| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <pstm-uri>/tasks/{task_id}</pstm-uri>
- <pstm-template>main</pstm-template>
- <script>
- // Live updates: the page subscribes to the global pulse (see the
- // entrypoint); whenever task or saddle state changes anywhere in
- // the app, the sealed refresh action rehydrates the task slot —
- // no fixed-interval polling. RFC bodies get the shared
- // text-highlight -> comment popover (see main.html). Design-task
- // plan reviews collect inline comments on the plan and submit them
- // as the block answer.
- if (window.statum) {
- (function () {
- 'use strict';
- statum.addStateListener('pulse', function () {
- var task = statum.read('task');
- if (task && task.refresh) {
- statum.act(task.refresh).catch(function () { });
- }
- });
- if (window.initQuoteComments) {
- window.initQuoteComments({
- matches: function (node) {
- return node.closest && node.closest('.rfc-body') != null
- && node.closest('[data-plan-body]') == null;
- },
- action: function () {
- var task = statum.read('task');
- return task && task.comment;
- }
- });
- }
- // Plan-review feedback: collected comments live in these maps
- // (keyed by block id) so statum re-renders never lose them;
- // the DOM list is rebuilt after every render cycle.
- var feedbackByBlock = {};
- var modeByBlock = {};
- var planPopover = null;
- statum.afterEvaluate(syncPlanFeedback);
- document.addEventListener('click', function (event) {
- if (!event.target.closest) return;
- var toggle = event.target.closest('[data-plan-toggle]');
- if (toggle) {
- hidePlanPopover();
- var review = toggle.closest('[data-plan-review]');
- var id = review && review.getAttribute('data-block-id');
- if (id) modeByBlock[id] = !modeByBlock[id];
- syncPlanFeedback();
- return;
- }
- var submit = event.target.closest('[data-plan-submit]');
- if (submit) {
- submitPlanFeedback(submit.closest('[data-plan-review]'));
- return;
- }
- var remove = event.target.closest('[data-plan-remove]');
- if (remove) {
- var entry = remove.closest('[data-plan-comment-id]');
- var blockId = remove.closest('[data-plan-review]').getAttribute('data-block-id');
- var list = feedbackByBlock[blockId] || [];
- var index = parseInt(entry.getAttribute('data-plan-comment-id'), 10);
- if (!isNaN(index) && list[index]) list.splice(index, 1);
- feedbackByBlock[blockId] = list;
- syncPlanFeedback();
- }
- });
- document.addEventListener('mouseup', function (event) {
- if (!event.target.closest) return;
- if (planPopover && planPopover.contains(event.target)) return;
- var body = event.target.closest('[data-plan-body]');
- if (!body) {
- hidePlanPopover();
- return;
- }
- var review = body.closest('[data-plan-review]');
- if (!review || review.getAttribute('data-plan-open') !== '1') return;
- var selection = window.getSelection();
- var text = selection ? String(selection.toString()).trim() : '';
- if (text.length === 0) {
- hidePlanPopover();
- return;
- }
- showPlanPopover(event.pageX, event.pageY, text, review);
- });
- document.addEventListener('mousedown', function (event) {
- if (planPopover && event.target.closest && event.target.closest('.plan-popover')) return;
- hidePlanPopover();
- });
- function showPlanPopover(x, y, quote, review) {
- hidePlanPopover();
- planPopover = document.createElement('div');
- planPopover.className = 'plan-popover';
- planPopover.style.left = Math.min(x, window.innerWidth - 140) + 'px';
- planPopover.style.top = y + 'px';
- var quoted = document.createElement('blockquote');
- quoted.textContent = quote;
- planPopover.appendChild(quoted);
- var body = document.createElement('textarea');
- body.placeholder = 'Your comment on the selected plan text';
- planPopover.appendChild(body);
- var actions = document.createElement('div');
- actions.className = 'actions';
- var add = document.createElement('button');
- add.type = 'button';
- add.className = 'primary';
- add.textContent = 'Add comment';
- add.addEventListener('click', function () {
- if (body.value.trim().length === 0) return;
- var id = review.getAttribute('data-block-id');
- var list = feedbackByBlock[id] || [];
- list.push({ quote: quote, body: body.value.trim() });
- feedbackByBlock[id] = list;
- hidePlanPopover();
- syncPlanFeedback();
- });
- var cancel = document.createElement('button');
- cancel.type = 'button';
- cancel.textContent = 'Cancel';
- cancel.addEventListener('click', hidePlanPopover);
- actions.appendChild(add);
- actions.appendChild(cancel);
- planPopover.appendChild(actions);
- document.body.appendChild(planPopover);
- body.focus();
- }
- function hidePlanPopover() {
- if (planPopover) {
- planPopover.remove();
- planPopover = null;
- }
- }
- function submitPlanFeedback(review) {
- if (!review) return;
- var id = review.getAttribute('data-block-id');
- var list = feedbackByBlock[id] || [];
- if (list.length === 0) {
- if (window.showToast) window.showToast('Highlight some plan text and add a comment first', 'error');
- return;
- }
- var task = statum.read('task');
- var block = null;
- (task && task.blocks || []).forEach(function (candidate) {
- if (String(candidate.id) === String(id)) block = candidate;
- });
- if (!block || !block.answer_action) return;
- var answer = list.map(function (item) {
- return item.quote
- ? '> ' + item.quote.replace(/\n/g, '\n> ') + '\n\n' + item.body
- : item.body;
- }).join('\n\n');
- feedbackByBlock[id] = [];
- modeByBlock[id] = false;
- statum.act(block.answer_action, { answer: answer }).catch(function () { });
- }
- function syncPlanFeedback() {
- document.querySelectorAll('[data-plan-review]').forEach(function (review) {
- var id = review.getAttribute('data-block-id');
- var open = modeByBlock[id] ? '1' : '0';
- review.setAttribute('data-plan-open', open);
- var feedback = review.querySelector('[data-plan-feedback]');
- if (feedback) {
- if (modeByBlock[id]) feedback.removeAttribute('hidden');
- else feedback.setAttribute('hidden', '');
- }
- var list = review.querySelector('[data-plan-comments]');
- if (!list) return;
- while (list.firstChild) list.removeChild(list.firstChild);
- (feedbackByBlock[id] || []).forEach(function (item, index) {
- var entry = document.createElement('li');
- entry.setAttribute('data-plan-comment-id', String(index));
- if (item.quote) {
- var quoted = document.createElement('blockquote');
- quoted.textContent = item.quote;
- entry.appendChild(quoted);
- }
- var body = document.createElement('div');
- body.textContent = item.body;
- entry.appendChild(body);
- var remove = document.createElement('button');
- remove.type = 'button';
- remove.className = 'inline';
- remove.setAttribute('data-plan-remove', '');
- remove.textContent = 'Remove';
- entry.appendChild(remove);
- list.appendChild(entry);
- });
- });
- }
- })();
- }
- </script>
- </head>
- <body>
- <section>
- <h2 stm-if="task != null && task.exists">#<span stm-text="task.id">id</span> —
- <span stm-text="task.title">title</span></h2>
- <p stm-if="task != null && !task.exists" class="muted">Task not found.</p>
- <div stm-if="task != null && task.exists">
- <p><a href="/tasks">All tasks</a> · project
- <a stm-attribute.href="'/projects/' + task.project_id" stm-text="task.project_name">project</a>
- <span stm-if="task.parent_task_id > 0"> · subtask of
- <a stm-attribute.href="'/tasks/' + task.parent_task_id" stm-text="'#' + task.parent_task_id">#parent</a></span></p>
- <div class="cards">
- <section class="card">
- <h3>Status</h3>
- <p><span stm-attribute.class="'badge badge-' + task.status" stm-text="task.status">status</span>
- · priority <strong stm-text="task.priority">5</strong>
- <span stm-if="task.is_design_task"> · <strong>plan review required</strong></span></p>
- <p class="muted">Created <span stm-text="task.created_display">when</span></p>
- <p class="muted" stm-if="task.started_display.length > 0">Started <span stm-text="task.started_display">when</span></p>
- <p class="muted" stm-if="task.completed_display.length > 0">Completed <span stm-text="task.completed_display">when</span></p>
- <p stm-if="task.task_branch.length > 0">Branch: <strong stm-text="task.task_branch">branch</strong>
- <span class="muted" stm-if="task.branch_from.length > 0"> from <span stm-text="task.branch_from">base</span></span></p>
- <p stm-if="task.working_branch.length > 0" class="muted">Working branch: <span stm-text="task.working_branch">branch</span></p>
- <form class="inline">
- <input type="hidden" name="task_id" stm-attribute.value="task.id">
- <button type="button" stm-action="task.cancel" stm-confirm="Cancel this task?">Cancel task</button>
- </form>
- </section>
- <section class="card">
- <h3>Description</h3>
- <div stm-if="task.description.length > 0" class="md" stm-markdown="task.description">description</div>
- <p class="muted" stm-if="task.description.length == 0">No description.</p>
- <p stm-if="task.summary.length > 0"><strong>Summary:</strong> <span stm-text="task.summary">summary</span></p>
- </section>
- <section class="card">
- <h3>Edit</h3>
- <form stm-action="task.update">
- <input type="hidden" name="task_id" stm-attribute.value="task.id">
- <div class="form-row"><label>Title</label>
- <input type="text" name="title" stm-attribute.value="task.title"></div>
- <div class="form-row"><label>Description</label>
- <textarea name="description" rows="4" stm-attribute.value="task.description"></textarea></div>
- <div class="form-row"><label>Priority (1–9)</label>
- <input type="number" name="priority" min="1" max="9" stm-attribute.value="task.priority"></div>
- <div class="form-row"><label>Task branch</label>
- <input type="text" name="task_branch" stm-attribute.value="task.task_branch" placeholder="task/<id>-<slug>"></div>
- <div class="form-row"><label>Branch from</label>
- <input type="text" name="branch_from" stm-attribute.value="task.branch_from"></div>
- <div class="form-row"><label>Status</label>
- <select name="status" stm-attribute.value="task.status">
- <option value="queued">queued</option>
- <option value="assigned">assigned</option>
- <option value="working">working</option>
- <option value="blocked">blocked</option>
- <option value="review_requested">review_requested</option>
- <option value="done">done</option>
- <option value="failed">failed</option>
- </select></div>
- <button type="submit">Save</button>
- </form>
- </section>
- </div>
- <h3>Plan</h3>
- <div stm-if="task.plan.length > 0" class="card md" stm-markdown="task.plan">plan</div>
- <details stm-if="task.plan.length > 0">
- <summary>Edit plan</summary>
- <form stm-action="task.save_plan">
- <input type="hidden" name="task_id" stm-attribute.value="task.id">
- <div class="form-row"><label for="plan-editor">Plan (markdown)</label>
- <textarea id="plan-editor" name="plan" rows="12" stm-attribute.value="task.plan"></textarea></div>
- <button type="submit" class="primary">Save plan</button>
- </form>
- </details>
- <details stm-if="task.plan.length == 0">
- <summary>Write a plan</summary>
- <form stm-action="task.save_plan">
- <input type="hidden" name="task_id" stm-attribute.value="task.id">
- <div class="form-row"><label for="plan-editor">Plan (markdown)</label>
- <textarea id="plan-editor" name="plan" rows="12" placeholder="The agent fills this in via `saddle plan` — or write it yourself."></textarea></div>
- <button type="submit" class="primary">Save plan</button>
- </form>
- </details>
- <h3>Progress</h3>
- <div stm-if="task.progress.length > 0">
- <p class="progress-latest" stm-text="task.progress[0].summary">latest</p>
- <p class="muted" stm-text="'reported ' + task.progress[0].when_display">when</p>
- <details stm-if="task.progress.length > 1">
- <summary>Show history (<span stm-text="task.progress.length">0</span> updates)</summary>
- <ul class="progress-history">
- <li stm-for-item-in="task.progress">
- <span class="muted" stm-text="item.when_display">when</span> —
- <span stm-text="item.summary">summary</span>
- </li>
- </ul>
- </details>
- </div>
- <p stm-if="task.progress.length == 0" class="muted">No progress reports yet — the agent reports via
- <code>saddle progress-update</code>.</p>
- <h3>Blocks <span class="muted" stm-if="task.blocks.length > 0">(<span stm-text="task.blocks.length">0</span>)</span></h3>
- <div stm-for-block-in="task.blocks" stm-key="block.id"
- stm-attribute.class="'block-card ' + block.block_type + (block.answered ? ' answered' : '')">
- <div stm-if="!block.answered && block.block_type == 'review'" class="review-banner">
- <h3>Review requested</h3>
- <div class="md" stm-markdown="block.body.length > 0 ? block.body : block.question">summary</div>
- <p>Branch <strong stm-text="task.task_branch">branch</strong>
- <a stm-if="task.review_diff_url.length > 0" stm-attribute.href="task.review_diff_url"
- target="_blank" rel="noopener">· compare changes</a></p>
- <div class="actions">
- <form stm-action="block.answer_action" class="inline">
- <input type="hidden" name="answer" value="Human approved the review">
- <button type="submit" class="approve">Approve</button>
- </form>
- <form stm-action="block.answer_action" class="inline">
- <textarea name="answer" rows="2" placeholder="What should change?"></textarea>
- <button type="submit" class="reject">Request changes</button>
- </form>
- </div>
- </div>
- <div stm-if="!block.answered && block.is_plan_review" class="plan-review"
- data-plan-review stm-attribute.data-block-id="block.id">
- <div class="md rfc-body" stm-markdown="task.plan" data-plan-body>plan</div>
- <div class="actions">
- <form stm-action="block.answer_action" class="inline">
- <input type="hidden" name="answer" value="Plan approved. Proceed with implementation.">
- <button type="submit" class="approve">Approve plan</button>
- </form>
- <button type="button" data-plan-toggle>Give feedback</button>
- </div>
- <div data-plan-feedback hidden>
- <p class="muted">Highlight plan text to attach a comment to it, then submit everything
- as feedback — the agent revises the plan and asks again.</p>
- <ul class="plan-comments" data-plan-comments></ul>
- <button type="button" class="primary" data-plan-submit>Submit feedback</button>
- </div>
- </div>
- <p><span stm-attribute.class="'badge badge-' + block.block_type" stm-text="block.block_type">type</span>
- <span class="muted" stm-text="block.created_display">when</span></p>
- <div stm-if="block.show_body && block.body.length > 0" class="md rfc-body"
- stm-markdown="block.body">body</div>
- <div stm-if="block.answered">
- <p>Answer: <strong stm-text="block.answer">answer</strong>
- <span class="muted" stm-text="block.answered_display">when</span></p>
- </div>
- <form stm-if="!block.answered && block.block_type == 'question'" stm-action="block.answer_action">
- <div class="options">
- <label stm-for-option-in="block.options" stm-key="option" class="option-card">
- <input type="radio" name="option" stm-attribute.value="option">
- <span stm-text="option">option</span>
- </label>
- <label>
- <input type="radio" name="option" value="__other__">
- <span>Other:</span>
- <textarea name="other" rows="2"></textarea>
- </label>
- </div>
- <button type="submit" class="primary">Answer</button>
- </form>
- <form stm-if="!block.answered && block.block_type != 'question' && block.block_type != 'review' && !block.is_plan_review"
- stm-action="block.answer_action" class="inline">
- <textarea name="answer" rows="3" placeholder="Your reply (delivered to the agent)"></textarea>
- <button type="submit" class="primary">Reply</button>
- </form>
- </div>
- <p stm-if="task.blocks.length == 0" class="muted">No blocks — the agent has no open questions.</p>
- <h3>Comments</h3>
- <div stm-for-comment-in="task.comments" stm-attribute.class="'comment' + (comment.from_bot ? ' bot' : '')">
- <strong stm-text="comment.author">author</strong>
- <span class="muted" stm-text="comment.when_display">when</span>
- <blockquote stm-if="comment.quote.length > 0" stm-text="comment.quote">quote</blockquote>
- <div stm-text="comment.body">body</div>
- </div>
- <p stm-if="task.comments.length == 0" class="muted">No comments yet.</p>
- <form stm-action="task.comment">
- <input type="hidden" name="task_id" stm-attribute.value="task.id">
- <div class="form-row"><label for="comment-body">Add comment</label>
- <textarea id="comment-body" name="body" rows="3" placeholder="A comment for the agent"></textarea></div>
- <button type="submit" class="primary">Comment</button>
- </form>
- <h3>Subtasks</h3>
- <table>
- <thead><tr><th>#</th><th>Title</th><th>Status</th></tr></thead>
- <tbody>
- <tr stm-for-subtask-in="task.subtasks">
- <td stm-text="subtask.id">id</td>
- <td><a stm-attribute.href="'/tasks/' + subtask.id" stm-text="subtask.title">title</a></td>
- <td><span stm-attribute.class="'badge badge-' + subtask.status" stm-text="subtask.status">status</span></td>
- </tr>
- <tr stm-if="task.subtasks.length == 0"><td colspan="3" class="muted">No subtasks.</td></tr>
- </tbody>
- </table>
- <details>
- <summary><strong>New subtask</strong></summary>
- <form stm-action="task.subtask">
- <div class="form-row"><label>Title</label>
- <input type="text" name="title" required></div>
- <div class="form-row"><label>Description</label>
- <textarea name="description" rows="3"></textarea></div>
- <button type="submit">Create subtask</button>
- </form>
- </details>
- <h3>Dependencies</h3>
- <p stm-if="task.dependencies.length > 0">Depends on:
- <span stm-for-dep-in="task.dependencies">
- <a stm-attribute.href="'/tasks/' + dep.id" stm-text="'#' + dep.id + ' ' + dep.title">dep</a>
- <span stm-attribute.class="'badge badge-' + dep.status" stm-text="dep.status">status</span>
- </span>
- </p>
- <p stm-if="task.dependencies.length == 0" class="muted">No dependencies.</p>
- <form class="inline" stm-action="task.dependency">
- <label for="dep-target">Depends on</label>
- <select id="dep-target" name="depends_on_task_id" required>
- <option stm-for-candidate-in="task.candidates" stm-attribute.value="candidate.id"
- stm-text="'#' + candidate.id + ' ' + candidate.title">candidate</option>
- </select>
- <button type="submit">Add dependency</button>
- </form>
- <h3>Sessions</h3>
- <table>
- <thead><tr><th>#</th><th>Saddle</th><th>Started</th><th>Ended</th><th>Outcome</th><th></th></tr></thead>
- <tbody>
- <tr stm-for-session-in="task.sessions">
- <td stm-text="session.id">id</td>
- <td stm-text="session.saddle_name">saddle</td>
- <td stm-text="session.started_display">started</td>
- <td stm-text="session.ended_display">ended</td>
- <td stm-if="session.open"><span class="badge badge-working">open</span></td>
- <td stm-if="!session.open" stm-text="session.outcome">outcome</td>
- <td><a stm-attribute.href="'/tasks/' + task.id + '/terminal?session_id=' + session.id">Terminal</a></td>
- </tr>
- <tr stm-if="task.sessions.length == 0"><td colspan="6" class="muted">No sessions yet.</td></tr>
- </tbody>
- </table>
- <h3>Complete</h3>
- <form stm-action="task.complete" class="inline">
- <input type="hidden" name="task_id" stm-attribute.value="task.id">
- <input type="text" name="summary" placeholder="Completion summary">
- <input type="text" name="working_branch" placeholder="Branch (optional)">
- <button type="submit">Mark done</button>
- </form>
- </div>
- </section>
- </body>
- </html>
|