kaizen-agent 1.80.0 → 1.81.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/task-service.ts +6 -7
- package/cli/web.ts +2 -2
- package/package.json +1 -1
- package/web/board/cards.ts +8 -2
- package/web/board/task-page.ts +87 -169
- package/web/board/task-results.ts +18 -21
- package/web/board/tasks.ts +8 -6
- package/web/board/workspace.ts +3 -2
- package/web/board/zoom.ts +90 -0
- package/web/board.html +84 -7
- package/web/board.js +169 -216
- package/web/notebook.js +167 -188
- package/web/term.js +1 -1
- package/web/video.js +206 -227
package/cli/task-service.ts
CHANGED
|
@@ -8,7 +8,7 @@ import * as R from './task-results.ts';
|
|
|
8
8
|
import { read as scalar } from './config-values.ts';
|
|
9
9
|
import { detectDefaultAgent, home, readInbox, readRuns, readText, saveAttachment, acceptance, gateOf } from './state.ts';
|
|
10
10
|
|
|
11
|
-
type Hooks = { launch: (state:string, run:string, text:string, task:T.Task) => {ok:boolean; pty?:string; why?:string}; alive:(pty:string)=>boolean; stop:(pty:string)=>boolean };
|
|
11
|
+
type Hooks = { launch: (state:string, run:string, text:string, task:T.Task, pick?:any) => {ok:boolean; pty?:string; why?:string}; alive:(pty:string)=>boolean; stop:(pty:string)=>boolean };
|
|
12
12
|
const runtimeLaunches = new Set<string>();
|
|
13
13
|
const parse = (file:string) => { try { return JSON.parse(readFileSync(file,'utf8')); } catch { return null; } };
|
|
14
14
|
const put = (file:string,value:unknown) => { const temp = file + `.${process.pid}.${randomUUID()}.tmp`; writeFileSync(temp,JSON.stringify(value,null,2)+'\n'); renameSync(temp,file); };
|
|
@@ -32,7 +32,7 @@ export function taskList(states:string[],hooks?:Hooks) {
|
|
|
32
32
|
for(const run of readRuns(state)) {
|
|
33
33
|
if(adopted.has(`run:${run.id}`)||tasks.some(t=>t.dir===state&&t.runIds.includes(run.id)))continue;
|
|
34
34
|
const goal=readTextSafe(join(state,'runs',run.id,'00-request.md'))?.split('\n').find(l=>l.trim()&&!l.startsWith('#'))??run.id;
|
|
35
|
-
tasks.push({id:`legacy-run-${run.id}`,dir:state,title:goal.slice(0,160),goal,revision:0,updatedAt:run.moved,status:run.stage==='done'?'ready':'working',attention:{category:run.awaiting?'needs-you':'in-progress',reason:run.awaiting?'This existing task needs your decision.':`Existing work: ${run.stage}`,action:'Open task'},legacy:{kind:'run',id:run.id},runIds:[run.id]} as any);
|
|
35
|
+
tasks.push({id:`legacy-run-${run.id}`,dir:state,title:goal.slice(0,160),goal,revision:0,updatedAt:run.moved,status:run.stage==='done'?'ready':'working',attention:{category:run.awaiting?'needs-you':['done','abandoned'].includes(run.stage)?'completed':'in-progress',reason:run.awaiting?'This existing task needs your decision.':`Existing work: ${run.stage}`,action:'Open task'},legacy:{kind:'run',id:run.id},runIds:[run.id]} as any);
|
|
36
36
|
}
|
|
37
37
|
readInbox(state).forEach((line:any,index:number)=>{const key=`inbox:${line.added??'legacy'}:${index}`;if(line.status!=='open'||adopted.has(key))return;tasks.push({id:`legacy-inbox-${index}`,dir:state,title:line.text,goal:line.text,revision:0,updatedAt:line.added??0,status:'draft',attention:{category:'needs-you',reason:'Ready to start',action:'Open task'},legacy:{kind:'inbox',index,added:line.added},runIds:[]} as any);});
|
|
38
38
|
}
|
|
@@ -49,7 +49,7 @@ export function reconcile(state:string,task:T.Task,hooks?:Hooks):T.Task {
|
|
|
49
49
|
return task;
|
|
50
50
|
}
|
|
51
51
|
function runState(state:string,task:T.Task) { return task.activeRun?parse(join(state,'runs',task.activeRun,'state.json')):null; }
|
|
52
|
-
export function dispatchReady(state:string,id:string,hooks:Hooks,initial=false):T.Task {
|
|
52
|
+
export function dispatchReady(state:string,id:string,hooks:Hooks,initial=false,pick?:any):T.Task {
|
|
53
53
|
let task=T.readTask(state,id)!;
|
|
54
54
|
if(task.pendingDecision||task.queuePaused||!task.safe||task.status==='accepted')return task;
|
|
55
55
|
const previous=runState(state,task);
|
|
@@ -65,7 +65,7 @@ export function dispatchReady(state:string,id:string,hooks:Hooks,initial=false):
|
|
|
65
65
|
if(!task.launch||task.launch.phase!=='intent')return task;
|
|
66
66
|
if(finished){
|
|
67
67
|
const folder=join(state,'runs',run);mkdirSync(folder,{recursive:true});
|
|
68
|
-
put(join(folder,'state.json'),{id:run,mode:config(state,'mode','auto'),runner:config(state,'runner','full'),agent:detectDefaultAgent(dirname(state)).cmd,track:'code',stage:'plan',awaiting:null,iteration:0,updated:new Date().toISOString(),task_id:id,task_policy:{requirePlanConfirmation:!task.initialConfirmed},...(task.initialConfirmed?{task_confirmed:{direction:'routine revision',at:Date.now()}}:{})});
|
|
68
|
+
put(join(folder,'state.json'),{id:run,mode:config(state,'mode','auto'),runner:pick?.kind==='lite'||pick?.kind==='full'?pick.kind:config(state,'runner','full'),agent:pick?.agent||detectDefaultAgent(dirname(state)).cmd,track:'code',stage:'plan',awaiting:null,iteration:0,updated:new Date().toISOString(),task_id:id,task_policy:{requirePlanConfirmation:!task.initialConfirmed},...(task.initialConfirmed?{task_confirmed:{direction:'routine revision',at:Date.now()}}:{})});
|
|
69
69
|
writeFileSync(join(folder,'00-request.md'),(ids.length?task.inputs.filter(i=>ids.includes(i.id)).map(i=>i.text).join('\n\n'):task.goal)+`\n\nTask: ${id}\n`+(previous?`Follow-up of: ${previous.id}\n`:'')+task.files.map(f=>`Reference: ${f.name} (${f.path})`).join('\n'));
|
|
70
70
|
}
|
|
71
71
|
const context=JSON.stringify({task:id,launch:task.launch.id,inputIds:ids,currentResult:task.currentResult,initialConfirmed:task.initialConfirmed});
|
|
@@ -75,7 +75,7 @@ export function dispatchReady(state:string,id:string,hooks:Hooks,initial=false):
|
|
|
75
75
|
runtimeLaunches.add(task.launch.id);
|
|
76
76
|
let outcome;try{
|
|
77
77
|
const selected=detectDefaultAgent(dirname(state)), requested=config(state,'agent.default','auto');
|
|
78
|
-
outcome
|
|
78
|
+
outcome=!pick?.agent && requested!=='auto' && ![selected.cmd,selected.name].includes(requested) ? {ok:false,why:`Configured agent ${requested} is unavailable. Enable/install it or choose an available default in Settings, then retry. Your goal is saved.`} : hooks.launch(state,run,text,task,pick);
|
|
79
79
|
}catch(e){outcome={ok:false,why:String(e)};}
|
|
80
80
|
task=T.readTask(state,id)!;
|
|
81
81
|
return T.mutateTask(state,id,{revision:task.revision,opId:`launched:${task.launch!.id}`},t=>{if(outcome.ok){if(t.launch!.phase==='intent')t.launch!.phase='started';if(outcome.pty)t.launch!.pty=outcome.pty;}else{t.status='failed';t.error=outcome.why||'Agent could not start. Your goal is saved.';t.launch!.phase='interrupted';t.queuePaused=true;} });
|
|
@@ -117,13 +117,12 @@ export function taskAction(state:string,body:any,hooks:Hooks):{state:string;task
|
|
|
117
117
|
const found=T.resolveTask(state,String(body.id??''));if(!found)throw new T.TaskError('Unknown task',404);state=found.state;let task=reconcile(state,found.task,hooks);
|
|
118
118
|
const mutation={revision:Number(body.revision),opId:operationId};
|
|
119
119
|
if(task.operations.includes(operationId))return {state,task};
|
|
120
|
-
if(op==='start'){task=T.mutateTask(state,task.id,mutation,t=>{if(t.status!=='draft')throw new T.TaskError('Task already started');});return {state,task:dispatchReady(state,task.id,hooks,true)};}
|
|
120
|
+
if(op==='start'){task=T.mutateTask(state,task.id,mutation,t=>{if(t.status!=='draft')throw new T.TaskError('Task already started');});return {state,task:dispatchReady(state,task.id,hooks,true,body.pick&&typeof body.pick==='object'?body.pick:undefined)};}
|
|
121
121
|
task=T.mutateTask(state,task.id,mutation,t=>{
|
|
122
122
|
if(op==='message'){
|
|
123
123
|
const text=String(body.text??'').trim();const status=body.intent==='question'||/^\s*(status\??|what(?:'s| is) (?:the )?(?:status|progress)\??|how (?:is|are) (?:it|things|the task) (?:going|doing)\??)\s*$/i.test(text);
|
|
124
124
|
if(status){T.receiveInput(t,{id:operationId,text,intent:'status',baseResult:body.baseResultId??null});return;}
|
|
125
125
|
const answer=t.pendingDecision?.kind==='question';
|
|
126
|
-
if(body.intent==='auto'&&!answer&&!/^(please |can you |could you |i want |change|add|remove|make|update|fix|replace|create|build|use|set|move|delete|show|hide|increase|reduce|rewrite)/i.test(text)){T.addEvent(t,'user','message',text);t.pendingDecision={id:randomUUID(),kind:'question',text:'Should I treat that as a change request? Send the change with Request change, or ask for status.',run:t.activeRun,iteration:0,result:t.currentResult,options:['Request change','Status']};t.status='waiting';return;}
|
|
127
126
|
T.receiveInput(t,{id:operationId,text,intent:answer?'answer':'change',baseResult:body.baseResultId??null});
|
|
128
127
|
if(answer||t.pendingDecision?.kind==='proposal'){t.pendingDecision=null;t.safe=true;t.status='draft';}
|
|
129
128
|
}else if(op==='stop'){T.requestStop(t);}
|
package/cli/web.ts
CHANGED
|
@@ -280,10 +280,10 @@ export async function web(repoDir: string, opts: Opts = {}) {
|
|
|
280
280
|
).filter((d, i, arr) => arr.indexOf(d) === i && existsSync(d));
|
|
281
281
|
|
|
282
282
|
const taskHooks = {
|
|
283
|
-
launch: (dir: string, id: string, text: string, task: tasks.Task) => {
|
|
283
|
+
launch: (dir: string, id: string, text: string, task: tasks.Task, pick?: any) => {
|
|
284
284
|
const live = liveAgent(dir, id);
|
|
285
285
|
if (live) { submitPty(live.key, text); return { ok: true, pty: live.key }; }
|
|
286
|
-
return launchRun({ severity: null, where: null, text, raw: text }, dir, id, { ...inCard(dir), task: { id: task.id, requirePlanConfirmation: !task.initialConfirmed } });
|
|
286
|
+
return launchRun({ severity: null, where: null, text, raw: text }, dir, id, { ...inCard(dir), ...(pick ? { agent: KNOWN_AGENTS.some((a) => a.cmd === pick.agent) ? pick.agent : undefined, account: typeof pick.account === "string" ? pick.account : undefined, explore: typeof pick.explore === "boolean" ? pick.explore : undefined, yolo: pick.yolo === true } : {}), task: { id: task.id, requirePlanConfirmation: !task.initialConfirmed } });
|
|
287
287
|
},
|
|
288
288
|
alive: (key: string) => ptyState(key)?.alive === true,
|
|
289
289
|
stop: (key: string) => killPty(key),
|
package/package.json
CHANGED
package/web/board/cards.ts
CHANGED
|
@@ -457,11 +457,17 @@ function inlineForm(c) {
|
|
|
457
457
|
const runHtml = (c) =>
|
|
458
458
|
html`<div class="q">Run "${c.text}"</div><div class="q dim">Opens your agent with this request in a terminal.</div><div class="q dim">Full plans, builds, and checks with a separate reviewer. Lite does it in one session.</div><div id="run-pick" style="display:grid;gap:6px"><div id="run-agent" class="agents" role="radiogroup" aria-label="Agent"></div></div><label class="yolo"><input type="checkbox" id="run-explore"> Explore first</label><div class="run-actions"><label class="yolo" id="run-yolo" title="Yolo: the agent runs every command and edit without asking" hidden>${toggleSwitch(false)}Yolo</label><div class="row"><button type="button" class="btn ghost" data-a="c">Cancel</button><button type="button" class="btn" data-a="l">Lite</button><button type="button" class="btn pri" data-a="s">Full run</button></div></div>`;
|
|
459
459
|
// The run form as a popup over any page: Start in the new-task form and on Tasks.
|
|
460
|
-
export function runPopup(c) {
|
|
460
|
+
export function runPopup(c, onStart?: (p: { kind: string; agent?: string; account?: string; yolo: boolean; explore?: boolean }) => void) {
|
|
461
461
|
const dl = modal(runHtml(c)),
|
|
462
462
|
f = dl.querySelector("form");
|
|
463
463
|
dl.classList.toggle("sheet", isPhone());
|
|
464
464
|
const go = (kind) => {
|
|
465
|
+
if (onStart) {
|
|
466
|
+
const p = runPick && runPick.k === key(c) ? runPick : null;
|
|
467
|
+
onStart({ kind, agent: p?.agent, account: p?.account, yolo: !!(p?.yolo && !$("run-yolo")?.hidden), explore: p?.exploreOverride });
|
|
468
|
+
runPick = null;
|
|
469
|
+
return dl.close();
|
|
470
|
+
}
|
|
465
471
|
// startRun reads the Yolo switch, so the dialog closes after it has.
|
|
466
472
|
void startRun(c, kind);
|
|
467
473
|
dl.close();
|
|
@@ -587,7 +593,7 @@ function taskForm(f, shut) {
|
|
|
587
593
|
newFiles = [];
|
|
588
594
|
shut();
|
|
589
595
|
};
|
|
590
|
-
f.innerHTML = html
|
|
596
|
+
f.innerHTML = html`<div class="nt-head"><h2>New task</h2>${picking ? html`<div class="combo" id="ndc"><button type="button" class="sel" id="newdir" aria-label="Project for this task" aria-haspopup="listbox" aria-expanded="false"></button><div class="menu-pop" hidden><input class="sel" aria-label="Search projects" placeholder="Search projects…" spellcheck="false" autocomplete="off"><div id="nds" role="listbox"></div></div></div>` : ""}</div><input id="newidea" placeholder="What do you want to build?"><label for="newnotes">Anything the planner should know <span class="dim">(optional)</span></label><textarea id="newnotes" placeholder="Context, constraints, examples, and what a good result looks like"></textarea><div class="att" id="newatt"></div><input type="file" id="newfile" multiple hidden><div class="row"><button type="button" class="ib" id="newpick" aria-label="Attach files" title="Attach files">${ico("clip")}</button><button type="button" class="btn ghost" id="nc">Cancel</button><div class="split"><button type="button" class="btn pri" id="ns">Add</button><button type="button" class="btn pri" id="nm" aria-label="More ways to add" aria-haspopup="menu" aria-expanded="false">${ico("chev")}</button><div class="menu-pop" role="menu" hidden><button type="button" role="menuitem" id="nr" title="Add the task and run it now">${ico("play")}Start run</button></div></div></div>`;
|
|
591
597
|
const inp = f.querySelector("#newidea"),
|
|
592
598
|
files = newFiles;
|
|
593
599
|
draft(inp, "f:new:0");
|
package/web/board/task-page.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// One durable task page across clarification, production, saved outputs and revisions.
|
|
2
2
|
// Polling patches the changing sections, leaving the composer and focused controls intact.
|
|
3
|
-
import { $, html, modal, dataUrls, type Safe } from "./dom.ts";
|
|
3
|
+
import { $, html, ico, modal, dataUrls, type Safe } from "./dom.ts";
|
|
4
4
|
import { store } from "./store.ts";
|
|
5
|
+
import { runPopup } from "./cards.ts";
|
|
5
6
|
import { toast } from "./toast.ts";
|
|
7
|
+
import { wireZoom } from "./zoom.ts";
|
|
6
8
|
import { attentionTasks, setTaskAttention } from "./badge.ts";
|
|
7
|
-
import { resultView, loadTextArtifacts, loadLiveArtifacts, type TaskResult } from "./task-results.ts";
|
|
9
|
+
import { checksView, savedLine, resultView, loadTextArtifacts, loadLiveArtifacts, type TaskResult } from "./task-results.ts";
|
|
8
10
|
|
|
9
11
|
export type TaskAttention = { category: "needs-you" | "in-progress" | "completed"; reason: string; action: string };
|
|
10
12
|
export type TaskDecision = {
|
|
@@ -200,44 +202,42 @@ function conversationView(t: TaskView): Safe {
|
|
|
200
202
|
: ""
|
|
201
203
|
}
|
|
202
204
|
<div class="tp-messages" role="log" aria-label="Task conversation" aria-live="polite" aria-relevant="additions">
|
|
203
|
-
${(t.messages ?? []).map(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
<
|
|
211
|
-
|
|
212
|
-
|
|
205
|
+
${(t.messages ?? []).map((m) => {
|
|
206
|
+
const long = m.text.length > 320;
|
|
207
|
+
const body = long
|
|
208
|
+
? html`<details class="tp-long"><summary>${m.text.slice(0, 280).trimEnd()}… <span>Show more</span></summary>${m.text}</details>`
|
|
209
|
+
: html`${m.text}`;
|
|
210
|
+
return html`<article class="tp-message ${m.role === "user" ? "from-user" : "from-agent"}">
|
|
211
|
+
<div>
|
|
212
|
+
<strong>${m.role === "user" ? "You" : m.role === "system" ? "kaizen" : "Assistant"}</strong
|
|
213
|
+
>${m.at ? html`<time>${new Date(m.at).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}</time>` : ""}
|
|
214
|
+
</div>
|
|
215
|
+
<p>${body}</p>
|
|
216
|
+
</article>`;
|
|
217
|
+
})}
|
|
213
218
|
</div>
|
|
214
219
|
${
|
|
215
220
|
queued(t).length
|
|
216
|
-
? html`<
|
|
217
|
-
<h3>Requests</h3>
|
|
221
|
+
? html`<div class="tp-queue" aria-label="Requests awaiting completion">
|
|
218
222
|
${queued(t).map(
|
|
219
223
|
(i) =>
|
|
220
|
-
html`<
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
>
|
|
224
|
-
<p>${i.text}</p>
|
|
225
|
-
<small>Receipt ${i.id.slice(0, 8)}</small>
|
|
226
|
-
</div>`,
|
|
224
|
+
html`<span class="tp-receipt" title="Receipt ${i.id.slice(0, 8)}"
|
|
225
|
+
>${i.state === "dispatched" ? "Processing" : i.state === "received" ? "Received" : "Queued for next pass"}</span
|
|
226
|
+
>`,
|
|
227
227
|
)}
|
|
228
|
-
</
|
|
228
|
+
</div>`
|
|
229
229
|
: ""
|
|
230
230
|
}`;
|
|
231
231
|
}
|
|
232
|
-
function technicalView(t: TaskView): Safe {
|
|
232
|
+
function technicalView(t: TaskView, current?: TaskResult): Safe {
|
|
233
233
|
const runs = [
|
|
234
234
|
...new Set([
|
|
235
235
|
...(t.runs ?? []).map((r) => (typeof r === "string" ? r : r.id)),
|
|
236
236
|
...(t.activeRun ? [t.activeRun] : []),
|
|
237
237
|
]),
|
|
238
238
|
];
|
|
239
|
-
return html`<
|
|
240
|
-
|
|
239
|
+
return html`<div class="tp-technical" id="tp-technical-details">
|
|
240
|
+
${checksView(current)}
|
|
241
241
|
<p>
|
|
242
242
|
${data?.defaults?.agent ? "Agent: " + data.defaults.agent + ". " : "Configured project agent and workflow. "}${data?.defaults?.workflow ? "Workflow: " + data.defaults.workflow + ". " : ""}${data?.defaults?.permissions || "Tool permissions follow the existing project settings."}
|
|
243
243
|
</p>
|
|
@@ -248,7 +248,7 @@ function technicalView(t: TaskView): Safe {
|
|
|
248
248
|
${runs.length ? html`<nav aria-label="Linked runs">${runs.map((id) => html`<a class="btn" href="?view=run&id=${id}&dir=${encodeURIComponent(t.dir)}">Open workspace · ${id}</a>`)}</nav>` : html`<p>No run has started yet.</p>`}<small
|
|
249
249
|
>Task ${t.id} · revision ${t.revision}</small
|
|
250
250
|
>
|
|
251
|
-
</
|
|
251
|
+
</div>`;
|
|
252
252
|
}
|
|
253
253
|
function updateActions() {
|
|
254
254
|
if (!data) return;
|
|
@@ -285,6 +285,18 @@ function preservePatch(id: string, markup: Safe | string) {
|
|
|
285
285
|
});
|
|
286
286
|
return true;
|
|
287
287
|
}
|
|
288
|
+
// The conversation is a drawer: open by itself only while a decision waits for you, closed otherwise.
|
|
289
|
+
let drawer: boolean | null = null,
|
|
290
|
+
threadCount = -1;
|
|
291
|
+
const drawerOpen = () =>
|
|
292
|
+
drawer ?? !!data?.task.pendingDecision;
|
|
293
|
+
function applyDrawer() {
|
|
294
|
+
const on = drawerOpen();
|
|
295
|
+
$("tp-drawer").classList.toggle("on", on);
|
|
296
|
+
$("tp-chat").setAttribute("aria-expanded", String(on));
|
|
297
|
+
const t = data?.task;
|
|
298
|
+
$("tp-chat").querySelector<HTMLElement>(".tp-dot")!.hidden = on || !(t?.pendingDecision || t?.inputs?.some?.((i: any) => i.state === "queued"));
|
|
299
|
+
}
|
|
288
300
|
function draw() {
|
|
289
301
|
if (!data || !document.body.classList.contains("taskpagev")) return;
|
|
290
302
|
const t = data.task,
|
|
@@ -292,47 +304,37 @@ function draw() {
|
|
|
292
304
|
if (!box.querySelector("#tp-composer")) {
|
|
293
305
|
box.innerHTML = String(
|
|
294
306
|
html`<header class="tp-head">
|
|
295
|
-
<a class="
|
|
296
|
-
<
|
|
297
|
-
|
|
298
|
-
<p id="tp-project-label"></p>
|
|
299
|
-
</div>
|
|
307
|
+
<a class="ib" href="?view=tasks" id="tp-back" aria-label="Back to tasks" title="Tasks">${ico("arrow")}</a>
|
|
308
|
+
<h1 id="tp-title"></h1>
|
|
309
|
+
<span id="tp-project-label" class="dim"></span>
|
|
300
310
|
<button class="btn" type="button" id="tp-stop" hidden>Stop</button
|
|
301
311
|
><button class="btn" type="button" id="tp-resume" hidden>Resume</button
|
|
302
|
-
><button class="btn pri" type="button" id="tp-start" hidden>Start planning</button
|
|
312
|
+
><button class="btn pri" type="button" id="tp-start" hidden>Start planning</button
|
|
313
|
+
><button type="button" class="btn pri" id="tp-accept" title="Accepting a result does not publish it. A preview alone does not prove that a backend works." hidden>Looks good</button
|
|
314
|
+
><button type="button" class="ib" id="tp-chat" aria-label="Conversation" aria-expanded="false" title="Conversation">${ico("note")}<i class="tp-dot" hidden></i></button
|
|
315
|
+
><details class="ice-filt" id="tp-info"><summary class="ib" aria-label="Task details" title="Details">${ico("more")}</summary><div class="ice-fpop tp-info-pop"><div id="tp-technical"></div></div></details>
|
|
303
316
|
</header>
|
|
304
|
-
<div class="tp-status" role="status"><span id="tp-status"></span><span id="tp-next"></span></div>
|
|
317
|
+
<div class="tp-status" role="status"><span id="tp-status"></span><span id="tp-next"></span><span id="tp-saved" class="dim"></span></div>
|
|
305
318
|
<div class="tp-layout">
|
|
306
319
|
<section class="tp-results" aria-label="Task results">
|
|
307
320
|
<div id="tp-history"></div>
|
|
308
321
|
<div id="tp-result"></div>
|
|
309
|
-
<button type="button" class="btn pri" id="tp-accept" hidden>Looks good</button>
|
|
310
322
|
<div id="tp-accepted"></div>
|
|
311
|
-
<div id="tp-technical"></div>
|
|
312
|
-
</section>
|
|
313
|
-
<section class="tp-conversation" aria-label="Conversation and requests">
|
|
314
|
-
<h2>Conversation</h2>
|
|
315
|
-
<div id="tp-thread"></div>
|
|
316
|
-
<form id="tp-composer">
|
|
317
|
-
<label for="tp-message">Your message</label
|
|
318
|
-
><textarea
|
|
319
|
-
id="tp-message"
|
|
320
|
-
placeholder="Ask a question or describe what you would like changed"
|
|
321
|
-
rows="4"
|
|
322
|
-
></textarea>
|
|
323
|
-
<p id="tp-composer-help" class="dim"></p>
|
|
324
|
-
<div class="tp-compose-row">
|
|
325
|
-
<label for="tp-intent">Send as</label
|
|
326
|
-
><select id="tp-intent" class="sel">
|
|
327
|
-
<option value="auto">Message</option>
|
|
328
|
-
<option value="change">Change request</option>
|
|
329
|
-
<option value="question">Question</option></select
|
|
330
|
-
><button type="submit" class="btn pri" id="tp-submit">Send</button>
|
|
331
|
-
</div>
|
|
332
|
-
<p id="tp-receipt" role="status"></p>
|
|
333
|
-
</form>
|
|
334
323
|
</section>
|
|
335
|
-
|
|
324
|
+
<div class="tp-conversation" id="tp-drawer" role="complementary" aria-label="Conversation and requests">
|
|
325
|
+
<header><h2>Conversation</h2><button type="button" class="ib" id="tp-drawer-x" aria-label="Close conversation">${ico("x")}</button></header>
|
|
326
|
+
<div id="tp-thread"></div>
|
|
327
|
+
</div>
|
|
328
|
+
</div>
|
|
329
|
+
<form id="tp-composer" class="tp-bar">
|
|
330
|
+
<div class="tp-compose">
|
|
331
|
+
<textarea id="tp-message" rows="1" aria-label="Your message" placeholder="Message the agent" title="Enter to send, Shift+Enter for a new line"></textarea>
|
|
332
|
+
<button type="submit" class="btn pri" id="tp-submit">Send</button>
|
|
333
|
+
</div>
|
|
334
|
+
<p id="tp-composer-help" class="dim" hidden></p>
|
|
335
|
+
<p id="tp-receipt" role="status"></p>
|
|
336
|
+
</form>
|
|
337
|
+
`,
|
|
336
338
|
);
|
|
337
339
|
$("tp-message").value = readDraft(t.id);
|
|
338
340
|
$("tp-message").oninput = () => saveDraft(t.id, $("tp-message").value);
|
|
@@ -345,14 +347,23 @@ function draw() {
|
|
|
345
347
|
void sendMessage();
|
|
346
348
|
};
|
|
347
349
|
$("tp-message").onkeydown = (e) => {
|
|
348
|
-
|
|
350
|
+
// Enter sends, Shift+Enter adds a line. A phone keyboard keeps Enter as a new line.
|
|
351
|
+
if (e.key === "Enter" && !e.shiftKey && !e.isComposing && !matchMedia("(pointer:coarse)").matches) {
|
|
349
352
|
e.preventDefault();
|
|
350
353
|
void sendMessage();
|
|
351
354
|
}
|
|
352
355
|
};
|
|
356
|
+
$("tp-chat").onclick = () => {
|
|
357
|
+
drawer = !drawerOpen();
|
|
358
|
+
applyDrawer();
|
|
359
|
+
};
|
|
360
|
+
$("tp-drawer-x").onclick = () => {
|
|
361
|
+
drawer = false;
|
|
362
|
+
applyDrawer();
|
|
363
|
+
};
|
|
353
364
|
$("tp-stop").onclick = () => void action("stop");
|
|
354
365
|
$("tp-resume").onclick = () => void action("resume");
|
|
355
|
-
$("tp-start").onclick = () => void action("start");
|
|
366
|
+
$("tp-start").onclick = () => runPopup({ _k: "task:" + t.id, kind: "task", state: t.dir, text: t.title }, (pick) => void action("start", { pick }));
|
|
356
367
|
$("tp-accept").onclick = () => void action("accept", { resultId: data?.task.currentResultId });
|
|
357
368
|
}
|
|
358
369
|
$("tp-title").textContent = t.title;
|
|
@@ -372,14 +383,13 @@ function draw() {
|
|
|
372
383
|
else selectedResult = selected?.id ?? "";
|
|
373
384
|
preservePatch(
|
|
374
385
|
"tp-history",
|
|
375
|
-
results.length
|
|
376
|
-
? html`<
|
|
377
|
-
><select class="sel" id="tp-version">
|
|
386
|
+
results.length > 1
|
|
387
|
+
? html`<select class="sel" id="tp-version" aria-label="Saved results" title="Files are retained without automatic expiry. Live links remain mutable.">
|
|
378
388
|
${[...results].reverse().map((r, i) => html`<option value="${r.id}" ${r.id === selectedResult ? html` selected` : ""}>${r.title || "Version " + (results.length - i)}${r.id === t.currentResultId ? " · current" : " · earlier saved output"}</option>`)}
|
|
379
|
-
</select
|
|
380
|
-
<p class="dim">Files are retained without automatic expiry. Live links remain mutable.</p>`
|
|
389
|
+
</select>`
|
|
381
390
|
: "",
|
|
382
391
|
);
|
|
392
|
+
$("tp-saved").textContent = savedLine(results.find((r) => r.id === selectedResult) ?? selected);
|
|
383
393
|
const resultMarkup = String(resultView(results.find((r) => r.id === selectedResult) ?? selected, selectedArtifact));
|
|
384
394
|
if (signature !== resultMarkup) {
|
|
385
395
|
if (preservePatch("tp-result", resultMarkup)) {
|
|
@@ -410,8 +420,13 @@ function draw() {
|
|
|
410
420
|
?.focus({ preventScroll: true });
|
|
411
421
|
}),
|
|
412
422
|
);
|
|
413
|
-
|
|
414
|
-
|
|
423
|
+
wireZoom($("tp-result"));
|
|
424
|
+
const count = (t.messages ?? []).length;
|
|
425
|
+
const grew = preservePatch("tp-thread", conversationView(t)) && count !== threadCount;
|
|
426
|
+
threadCount = count;
|
|
427
|
+
if (grew) requestAnimationFrame(() => ($("tp-thread").scrollTop = $("tp-thread").scrollHeight));
|
|
428
|
+
applyDrawer();
|
|
429
|
+
preservePatch("tp-technical", technicalView(t, results.find((r) => r.id === selectedResult) ?? selected));
|
|
415
430
|
$("tp-accepted").textContent =
|
|
416
431
|
t.acceptedResultId && t.attention.category === "completed" ? "Accepted. Publishing is a separate action." : "";
|
|
417
432
|
$("tp-confirm") &&
|
|
@@ -479,7 +494,7 @@ async function sendMessage() {
|
|
|
479
494
|
if (!text || pending || !data) return;
|
|
480
495
|
const original = input.value;
|
|
481
496
|
const baseResultId = selectedResult || data.task.currentResultId || null;
|
|
482
|
-
const identity = JSON.stringify([text, baseResultId, data.task.decision?.id,
|
|
497
|
+
const identity = JSON.stringify([text, baseResultId, data.task.decision?.id, "auto"]);
|
|
483
498
|
let saved;
|
|
484
499
|
try {
|
|
485
500
|
saved = JSON.parse(readDraft(currentId + ":operation"));
|
|
@@ -489,7 +504,7 @@ async function sendMessage() {
|
|
|
489
504
|
const r = await action("message", {
|
|
490
505
|
operationId: messageOperation,
|
|
491
506
|
text,
|
|
492
|
-
intent:
|
|
507
|
+
intent: "auto",
|
|
493
508
|
baseResultId,
|
|
494
509
|
decisionId: data.task.decision?.id,
|
|
495
510
|
});
|
|
@@ -499,6 +514,8 @@ async function sendMessage() {
|
|
|
499
514
|
saveDraft(currentId, "");
|
|
500
515
|
saveDraft(currentId + ":operation", "");
|
|
501
516
|
$("tp-receipt").textContent = "Message received. Follow its receipt in the conversation.";
|
|
517
|
+
drawer = true;
|
|
518
|
+
applyDrawer();
|
|
502
519
|
}
|
|
503
520
|
input.focus();
|
|
504
521
|
}
|
|
@@ -542,6 +559,7 @@ export function openTaskPage() {
|
|
|
542
559
|
currentDir = dir;
|
|
543
560
|
data = null;
|
|
544
561
|
followCurrent = true;
|
|
562
|
+
drawer = null;
|
|
545
563
|
selectedResult = "";
|
|
546
564
|
selectedArtifact = "";
|
|
547
565
|
signature = "";
|
|
@@ -556,102 +574,6 @@ export function openTaskPage() {
|
|
|
556
574
|
};
|
|
557
575
|
timer = setTimeout(poll, 4000);
|
|
558
576
|
}
|
|
559
|
-
export function newTaskDialog(dir?: string | null) {
|
|
560
|
-
const dl = modal(
|
|
561
|
-
html`<h2>What would you like to make?</h2>
|
|
562
|
-
<label for="task-goal">Describe your goal</label
|
|
563
|
-
><textarea
|
|
564
|
-
id="task-goal"
|
|
565
|
-
rows="5"
|
|
566
|
-
placeholder="Make a registration website for our community workshop"
|
|
567
|
-
required
|
|
568
|
-
></textarea>
|
|
569
|
-
<p class="dim">
|
|
570
|
-
Start with your goal. We will ask about the project and any missing details, then show a proposal to confirm.
|
|
571
|
-
</p>
|
|
572
|
-
<input type="file" id="task-files" multiple hidden />
|
|
573
|
-
<div class="att" id="task-picked"></div>
|
|
574
|
-
<details>
|
|
575
|
-
<summary>Project and technical details</summary>
|
|
576
|
-
<p>
|
|
577
|
-
${dir ? "Use the current project. " : "Choose or create a named project after saving your goal. "}The
|
|
578
|
-
configured agent, workflow and tool permissions apply.
|
|
579
|
-
</p>
|
|
580
|
-
<p id="task-new-defaults" class="dim">Loading defaults…</p>
|
|
581
|
-
</details>
|
|
582
|
-
<p id="task-new-error" role="status"></p>
|
|
583
|
-
<div class="row">
|
|
584
|
-
<button type="button" class="btn" id="task-attach">Attach files</button
|
|
585
|
-
><button type="button" class="btn ghost" id="task-cancel">Cancel</button
|
|
586
|
-
><button type="submit" class="btn pri" id="task-start">Start</button>
|
|
587
|
-
</div>`,
|
|
588
|
-
);
|
|
589
|
-
const input = dl.querySelector<HTMLTextAreaElement>("#task-goal")!,
|
|
590
|
-
fileInput = dl.querySelector<HTMLInputElement>("#task-files")!,
|
|
591
|
-
files: File[] = [];
|
|
592
|
-
const op = operationId();
|
|
593
|
-
input.value = readDraft("new");
|
|
594
|
-
input.oninput = () => saveDraft("new", input.value);
|
|
595
|
-
const shown = () => (dl.querySelector("#task-picked")!.textContent = files.map((f) => f.name).join(" · "));
|
|
596
|
-
dl.querySelector<HTMLElement>("#task-attach")!.onclick = () => fileInput.click();
|
|
597
|
-
fileInput.onchange = () => {
|
|
598
|
-
files.push(...Array.from(fileInput.files ?? []));
|
|
599
|
-
fileInput.value = "";
|
|
600
|
-
shown();
|
|
601
|
-
};
|
|
602
|
-
input.onpaste = (e) => {
|
|
603
|
-
for (const it of Array.from(e.clipboardData?.items ?? []))
|
|
604
|
-
if (it.kind === "file") {
|
|
605
|
-
const f = it.getAsFile();
|
|
606
|
-
if (f) {
|
|
607
|
-
files.push(f);
|
|
608
|
-
e.preventDefault();
|
|
609
|
-
shown();
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
};
|
|
613
|
-
dl.querySelector<HTMLElement>("#task-cancel")!.onclick = () => dl.close();
|
|
614
|
-
dl.querySelector("form")!.onsubmit = async (e) => {
|
|
615
|
-
e.preventDefault();
|
|
616
|
-
const goal = input.value.trim();
|
|
617
|
-
if (!goal) return input.focus();
|
|
618
|
-
const button = dl.querySelector<HTMLButtonElement>("#task-start")!;
|
|
619
|
-
if (button.disabled) return;
|
|
620
|
-
button.disabled = true;
|
|
621
|
-
button.textContent = "Saving…";
|
|
622
|
-
const r = await taskRequest({
|
|
623
|
-
op: "create",
|
|
624
|
-
goal,
|
|
625
|
-
dir: dir ?? null,
|
|
626
|
-
files: await dataUrls(files),
|
|
627
|
-
operationId: op,
|
|
628
|
-
});
|
|
629
|
-
button.disabled = false;
|
|
630
|
-
button.textContent = "Start";
|
|
631
|
-
if (r.ok && r.task) {
|
|
632
|
-
saveDraft("new", "");
|
|
633
|
-
dl.close();
|
|
634
|
-
navigateTask(r.task);
|
|
635
|
-
} else
|
|
636
|
-
dl.querySelector("#task-new-error")!.textContent =
|
|
637
|
-
r.why || r.error || "Your goal is still here. Try saving again.";
|
|
638
|
-
};
|
|
639
|
-
void fetch("/tasks" + (dir ? "?dir=" + encodeURIComponent(dir) : ""))
|
|
640
|
-
.then((r) => r.json())
|
|
641
|
-
.then((r) => {
|
|
642
|
-
const d = r.defaults;
|
|
643
|
-
dl.querySelector("#task-new-defaults")!.textContent = d
|
|
644
|
-
? [d.agent && "Agent: " + d.agent, d.workflow && "Workflow: " + d.workflow, d.permissions]
|
|
645
|
-
.filter(Boolean)
|
|
646
|
-
.join(" · ")
|
|
647
|
-
: "Project settings will be shown before work starts.";
|
|
648
|
-
})
|
|
649
|
-
.catch(() => {
|
|
650
|
-
dl.querySelector("#task-new-defaults")!.textContent =
|
|
651
|
-
"Defaults unavailable. The configured settings will be retained.";
|
|
652
|
-
});
|
|
653
|
-
input.focus();
|
|
654
|
-
}
|
|
655
577
|
export function initTaskPage(goTo: typeof go) {
|
|
656
578
|
go = goTo;
|
|
657
579
|
addEventListener("kz-state", () => {
|
|
@@ -661,10 +583,6 @@ export function initTaskPage(goTo: typeof go) {
|
|
|
661
583
|
generation++;
|
|
662
584
|
clearTimeout(timer);
|
|
663
585
|
});
|
|
664
|
-
addEventListener("kz-new-task", (e: CustomEvent) => {
|
|
665
|
-
e.preventDefault();
|
|
666
|
-
newTaskDialog(e.detail?.dir ?? (!store.all ? store.S.dir : null));
|
|
667
|
-
});
|
|
668
586
|
addEventListener("kz-open-task", (e: CustomEvent) => {
|
|
669
587
|
e.preventDefault();
|
|
670
588
|
navigateTask(e.detail);
|
|
@@ -45,6 +45,7 @@ export const sizeLabel = (n?: number) =>
|
|
|
45
45
|
: n < 1024 * 1024
|
|
46
46
|
? `${(n / 1024).toFixed(1)} KB`
|
|
47
47
|
: `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
48
|
+
const isImage = (a: TaskArtifact) => /^image\//.test(a.mediaType ?? "") || a.kind === "image" || a.kind === "screenshot";
|
|
48
49
|
export function artifactView(a: TaskArtifact, selected = false): Safe {
|
|
49
50
|
const url = storedUrl(a.url),
|
|
50
51
|
live = a.kind === "website" || a.kind === "app" || a.kind === "link" || a.kind === "live";
|
|
@@ -71,7 +72,10 @@ export function artifactView(a: TaskArtifact, selected = false): Safe {
|
|
|
71
72
|
<p class="dim" data-live-status>Checking preview availability… You can also use Open link.</p>`;
|
|
72
73
|
else if (selected && !active && a.preview !== false && a.preview !== "download" && a.preview !== "none") {
|
|
73
74
|
if (/^image\//.test(a.mediaType ?? "") || a.kind === "image" || a.kind === "screenshot")
|
|
74
|
-
view = html`<
|
|
75
|
+
view = html`<div class="tp-zoom" aria-label="${a.name}. Pinch, scroll or double-click to zoom.">
|
|
76
|
+
<img class="tp-image" src="${href}" alt="${a.name}" loading="lazy" draggable="false" />
|
|
77
|
+
<div class="tp-zoom-ctl"><button type="button" class="ib" data-zoom-out aria-label="Zoom out">−</button><button type="button" class="ib" data-zoom-reset aria-label="Reset zoom">100%</button><button type="button" class="ib" data-zoom-in aria-label="Zoom in">+</button></div>
|
|
78
|
+
</div>`;
|
|
75
79
|
else if (/^video\//.test(a.mediaType ?? "") || a.kind === "video")
|
|
76
80
|
view = html`<video class="tp-media" controls preload="metadata" src="${href}">
|
|
77
81
|
Download this video to watch it.
|
|
@@ -109,29 +113,22 @@ export function resultView(result: TaskResult | undefined, artifactId?: string):
|
|
|
109
113
|
</div>`;
|
|
110
114
|
const artifacts = result.artifacts ?? [],
|
|
111
115
|
selected = artifacts.find((a) => a.id === artifactId) ?? artifacts[0];
|
|
116
|
+
const legacy = !result.title || result.title === "Existing result";
|
|
112
117
|
return html`<header class="tp-result-heading">
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
${result.createdAt ? html`<small class="dim">Saved ${new Date(result.createdAt).toLocaleString()}${(result.storedSize ?? result.size) != null ? " · " + sizeLabel(result.storedSize ?? result.size) + " preserved" : ""}</small>` : ""}
|
|
118
|
+
${legacy ? "" : html`<h2>${result.title}</h2>`}
|
|
119
|
+
${result.summary && !legacy ? html`<p>${result.summary}</p>` : ""}
|
|
116
120
|
</header>
|
|
117
|
-
${artifacts.length > 1 ? html`<
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}${
|
|
127
|
-
result.limitations?.length
|
|
128
|
-
? html`<ul>
|
|
129
|
-
${result.limitations.map((l) => html`<li>${l}</li>`)}
|
|
130
|
-
</ul>`
|
|
131
|
-
: ""
|
|
132
|
-
}
|
|
121
|
+
<div class="tp-split${artifacts.length > 1 ? " has-rail" : ""}">${artifacts.length > 1 ? html`<nav class="tp-rail" role="group" aria-label="Outputs">${artifacts.map((a) => html`<button class="tp-file" type="button" data-artifact="${a.id}" aria-pressed="${String(a.id === selected?.id)}">${isImage(a) ? html`<img src="${storedUrl(a.url)}" alt="" loading="lazy" draggable="false" />` : html`<i>${(a.name.split(".").pop() || "file").slice(0, 4)}</i>`}<span>${a.name}</span></button>`)}</nav>` : ""}<div class="tp-stage">${selected ? artifactView(selected, true) : html`<p class="tp-limit">No saved file was published for this result.</p>`}${result.liveUrl && !artifacts.some((a) => a.url === result.liveUrl) && webUrl(result.liveUrl) ? artifactView({ id: "live", name: "Live website", kind: "website", url: result.liveUrl }, true) : ""}</div></div>`;
|
|
122
|
+
}
|
|
123
|
+
export const savedLine = (r?: TaskResult) =>
|
|
124
|
+
r?.createdAt ? `Saved ${new Date(r.createdAt).toLocaleString()}${(r.storedSize ?? r.size) != null ? " · " + sizeLabel(r.storedSize ?? r.size) + " preserved" : ""}` : "";
|
|
125
|
+
export function checksView(result: TaskResult | undefined): Safe {
|
|
126
|
+
if (!result) return html``;
|
|
127
|
+
return html`<details class="tp-checks"><summary>Checks and limits</summary>
|
|
128
|
+
${result.checks?.length ? html`<ul>${result.checks.map((c) => html`<li>${typeof c === "string" ? c : [c.label, c.outcome, c.evidence].filter(Boolean).join(" — ")}</li>`)}</ul>` : ""}
|
|
129
|
+
${result.limitations?.length ? html`<ul>${result.limitations.map((l) => html`<li>${l}</li>`)}</ul>` : ""}
|
|
133
130
|
<p class="dim">Accepting a result does not publish it. A preview alone does not prove that a backend works.</p>
|
|
134
|
-
</
|
|
131
|
+
</details>`;
|
|
135
132
|
}
|
|
136
133
|
export async function loadTextArtifacts(box: HTMLElement) {
|
|
137
134
|
await Promise.all(
|