@ngockhoale/ckit 0.4.0 → 0.4.1
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/dist/src/team/engine.js +63 -13
- package/package.json +1 -1
package/dist/src/team/engine.js
CHANGED
|
@@ -699,46 +699,73 @@ export function startTeamRun(opts) {
|
|
|
699
699
|
setWait(agent.id, 'waiting-first-output');
|
|
700
700
|
const firstOut = () => { if (waits.get(agent.id) === 'waiting-first-output')
|
|
701
701
|
setWait(agent.id, 'generating'); };
|
|
702
|
+
// Stall watchdog: a provider stream can go silent mid-turn (seen on a real run: the stream abandoned a tool_use block and then sent only pings,
|
|
703
|
+
// so the CLI hung until agentTimeoutMs). No model output for stallMs while waiting for or generating output (never while a tool runs) aborts
|
|
704
|
+
// this attempt; the turn is retried once on a fresh process, then fails with a clear reason instead of hanging.
|
|
705
|
+
const stallMs = Math.min(Math.max(1000, Number(process.env['CKIT_STALL_MS']) || 240000), Math.max(1000, config.limits.agentTimeoutMs - 1000));
|
|
706
|
+
// Per-turn runners do not report tool calls, so a quiet long command looks like 'generating' there: only sessions (which report executing-tool) watch 'generating'.
|
|
707
|
+
let lastOut = Date.now(), stalled = false, att = new AbortController(), watch = null, inSession = false;
|
|
708
|
+
const bump = () => { lastOut = Date.now(); };
|
|
709
|
+
if (!own) {
|
|
710
|
+
watch = setInterval(() => { const w = waits.get(agent.id); if ((w === 'waiting-first-output' || (inSession && w === 'generating')) && Date.now() - lastOut > stallMs && !att.signal.aborted) {
|
|
711
|
+
stalled = true;
|
|
712
|
+
att.abort();
|
|
713
|
+
} }, Math.max(200, Math.min(5000, stallMs / 4)));
|
|
714
|
+
watch.unref?.();
|
|
715
|
+
}
|
|
702
716
|
try {
|
|
703
717
|
const raw = rawSink(agent);
|
|
704
|
-
const runOpts = {
|
|
705
|
-
cwd: opts.projectRoot, timeoutMs: config.limits.agentTimeoutMs, signal: ctl.signal, ...(atts.length ? { images: images() } : {}),
|
|
718
|
+
const runOpts = () => ({
|
|
719
|
+
cwd: opts.projectRoot, timeoutMs: config.limits.agentTimeoutMs, signal: AbortSignal.any([ctl.signal, att.signal]), ...(atts.length ? { images: images() } : {}),
|
|
706
720
|
onRaw: (stream, line) => raw(`[${stamp()}] ${stream}: ${line.endsWith('\n') ? line : `${line}\n`}`),
|
|
707
|
-
onActivity: text => { firstOut(); agentLog(agent, `[${stamp()}] activity: ${oneLine(text, 400)}\n`); emit({ type: 'agent.activity', agentId: agent.id, text: oneLine(text, 160) }); const l = own ? null : stepOf(text); if (l)
|
|
721
|
+
onActivity: text => { bump(); firstOut(); agentLog(agent, `[${stamp()}] activity: ${oneLine(text, 400)}\n`); emit({ type: 'agent.activity', agentId: agent.id, text: oneLine(text, 160) }); const l = own ? null : stepOf(text); if (l)
|
|
708
722
|
step(l); },
|
|
709
|
-
onStep: (label, k, total) => step(oneLine(label, 80), k, total),
|
|
723
|
+
onStep: (label, k, total) => { bump(); step(oneLine(label, 80), k, total); },
|
|
710
724
|
onSubagent: e => {
|
|
725
|
+
bump();
|
|
711
726
|
agentLog(agent, `[${stamp()}] subagent ${e.type} ${e.childId}: ${e.type === 'started' ? e.task : e.type === 'activity' ? e.text : e.summary}\n`);
|
|
712
727
|
emit(e.type === 'started' ? { type: 'subagent.started', agentId: agent.id, childId: e.childId, kind: e.kind, task: oneLine(e.task, 160) }
|
|
713
728
|
: e.type === 'activity' ? { type: 'subagent.activity', agentId: agent.id, childId: e.childId, text: oneLine(e.text, 160) }
|
|
714
729
|
: { type: 'subagent.finished', agentId: agent.id, childId: e.childId, ok: e.ok, summary: oneLine(e.summary, 200) });
|
|
715
730
|
},
|
|
716
|
-
};
|
|
731
|
+
});
|
|
732
|
+
const fresh = () => { stalled = false; att = new AbortController(); bump(); setWait(agent.id, 'waiting-first-output'); };
|
|
717
733
|
const sess = sessionFor(agent, scheduler !== null && agent.team !== 'director' ? true : false);
|
|
718
734
|
let res;
|
|
719
735
|
if (!sess)
|
|
720
|
-
res = await runner(agent, prompt, runOpts);
|
|
736
|
+
res = await runner(agent, prompt, runOpts());
|
|
721
737
|
else {
|
|
722
738
|
running.set(agent.id, sess);
|
|
723
739
|
const ent = myEntries.get(sessKey(agent));
|
|
724
740
|
if (ent)
|
|
725
741
|
ent.busy = true;
|
|
742
|
+
inSession = true;
|
|
726
743
|
try {
|
|
727
|
-
res = await sess.send(prompt, { ...runOpts, onDelta: t => { firstOut(); pushDelta(agent.id, t); }, onFirstOutput: firstOut,
|
|
728
|
-
onTool: (phase, name, text) => { firstOut(); setWait(agent.id, phase === 'call' ? 'executing-tool' : 'generating', phase === 'call' ? name : undefined); liveEmit({ type: 'agent.tool', agentId: agent.id, phase, name: oneLine(name, 80), text: oneLine(journal.redact(text), phase === 'call' ? 300 : 400) }); } }); // redact the whole text first, then shorten
|
|
744
|
+
res = await sess.send(prompt, { ...runOpts(), onDelta: t => { bump(); firstOut(); pushDelta(agent.id, t); }, onFirstOutput: () => { bump(); firstOut(); },
|
|
745
|
+
onTool: (phase, name, text) => { bump(); firstOut(); setWait(agent.id, phase === 'call' ? 'executing-tool' : 'generating', phase === 'call' ? name : undefined); liveEmit({ type: 'agent.tool', agentId: agent.id, phase, name: oneLine(name, 80), text: oneLine(journal.redact(text), phase === 'call' ? 300 : 400) }); } }); // redact the whole text first, then shorten
|
|
729
746
|
}
|
|
730
747
|
finally {
|
|
731
748
|
flushDelta(agent.id);
|
|
732
749
|
running.delete(agent.id);
|
|
733
750
|
if (ent)
|
|
734
751
|
ent.busy = false;
|
|
752
|
+
inSession = false;
|
|
735
753
|
}
|
|
736
|
-
if (!res.ok && res.transport && !abort.signal.aborted && !ctl.signal.aborted) {
|
|
754
|
+
if (!res.ok && (res.transport || stalled) && !abort.signal.aborted && !ctl.signal.aborted) {
|
|
737
755
|
dropSession(agent);
|
|
738
|
-
|
|
739
|
-
|
|
756
|
+
const why = stalled ? `no model output for ${Math.round(stallMs / 1000)} s (stalled stream)` : oneLine(res.reason, 100);
|
|
757
|
+
runOpts().onActivity?.(`Persistent session failed (${why}); retrying this turn with a fresh one-shot process`);
|
|
758
|
+
fresh(); // after the notice: the notice counts as output (firstOut) and must not mark the new attempt as already generating
|
|
759
|
+
res = await runner(agent, prompt, runOpts());
|
|
740
760
|
}
|
|
741
761
|
}
|
|
762
|
+
if (!res.ok && stalled && !sess && !abort.signal.aborted && !ctl.signal.aborted) {
|
|
763
|
+
runOpts().onActivity?.(`No model output for ${Math.round(stallMs / 1000)} s (stalled stream); retrying this turn with a fresh process`);
|
|
764
|
+
fresh();
|
|
765
|
+
res = await runner(agent, prompt, runOpts());
|
|
766
|
+
}
|
|
767
|
+
if (!res.ok && stalled && !abort.signal.aborted && !ctl.signal.aborted)
|
|
768
|
+
res = { ok: false, reason: `no model output for ${Math.round(stallMs / 1000)} s, twice (the provider stream stalled); check the CLI/provider connection` };
|
|
742
769
|
if (res.ok && !own)
|
|
743
770
|
step(last);
|
|
744
771
|
return done(res.ok ? res : { ok: false, reason: withArgsNote(agent, res.reason) });
|
|
@@ -747,6 +774,8 @@ export function startTeamRun(opts) {
|
|
|
747
774
|
return done({ ok: false, reason: withArgsNote(agent, e instanceof Error ? e.message : 'runner threw') });
|
|
748
775
|
}
|
|
749
776
|
finally {
|
|
777
|
+
if (watch)
|
|
778
|
+
clearInterval(watch);
|
|
750
779
|
abort.signal.removeEventListener('abort', onAbort);
|
|
751
780
|
signal?.removeEventListener('abort', onAbort);
|
|
752
781
|
if (turnCtl.get(agent.id) === ctl)
|
|
@@ -858,7 +887,7 @@ export function startTeamRun(opts) {
|
|
|
858
887
|
if (modelDirector()) {
|
|
859
888
|
const answered = qaRounds.length ? `\nYOUR EARLIER QUESTIONS AND THE OWNER'S ANSWERS:\n${qaRounds.map((q, i) => `Round ${i + 1} questions:\n${q.questions}\nOwner's answer:\n${q.answer}`).join('\n\n')}\n` : '';
|
|
860
889
|
const limitNote = forced ? '\nThe owner chose to proceed with your stated assumptions: answer "DECISION: PROCEED" now.' : needRounds >= 3 ? '\nYou already asked 3 times: you must not use NEED INFO again. Choose PROCEED with stated assumptions, or CANNOT DO.' : '';
|
|
861
|
-
const ask = () => directorAsk('intake brief', `${role(config.director, `You are the Director. First triage the owner request, then (only on PROCEED) split it between your teams.\nYour reply must contain exactly one decision line on its own line: "DECISION: PROCEED", "DECISION: NEED INFO" or "DECISION: CANNOT DO".\n- PROCEED: write a short overall summary (scope), an "ASSUMPTIONS:" list when you assumed anything, then one section per listed team, each starting with a line exactly "### TEAM <team id>" followed by: what this team must do for this goal, the expected deliverable, and what is out of scope for it. Assign every part of the goal to exactly one listed team and assign nothing to a team that is not listed.\n- NEED INFO: no team starts. Write a numbered list of at most 5 specific questions, each with why you need it; when sensible add a line "ASSUMPTIONS IF NO ANSWER:" followed by what you would assume.\n- CANNOT DO: write "REASON:" and then "WHAT WOULD WORK:" with 1 to 3 alternatives.\nRules: prefer PROCEED with stated assumptions when the gap is small and a wrong guess is cheap. Use NEED INFO only when a wrong guess wastes work or risks damage. Use CANNOT DO only when no reasonable reading of the request can be achieved with the configured teams, their access and this workspace. Never invent requirements. Never start teams on a request you do not understand. Answer in the owner's language. You may read project files (read only) to decide. Check the work is assignable: changing files needs a team with a write agent.\nOn PROCEED also add a line "MODE: <mode>" and a line "MODE REASON: <one sentence>". Modes: DIRECT = you answer it yourself right now (a question answerable from the request, the project files or a small lookup): put the complete answer for the owner in your reply and write no team sections; DELEGATE <agent id> = one best-fit agent does it alone (single-scope investigation or small fix); PARALLEL_MERGE = several agents give independent views at the same time and their team leads merge (options, reviews, risk); PARALLEL_EXECUTE = multi-part implementation through the teams. Never activate an agent just because it is configured; choose the cheapest mode that is good enough.\nWith DELEGATE, PARALLEL_MERGE, PARALLEL_EXECUTE or TARGETED_DISCUSSION also add a line "TEAMS: <team ids, comma separated>" naming ONLY the teams that must run (the pipeline order is kept); every other team is skipped. A read-only goal (a question, analysis or review where no file may change) activates no team with a write agent and no Test or QC team: those exist to change and verify files.\nWith PARALLEL_EXECUTE also add a line "DEPENDS: <team> <- <team>, <team>; <team> <- none; ..." saying which teams need which other teams' results first; teams with no dependency between them run at the same time (a team may only depend on teams earlier in the pipeline order; writes to the workspace are still serialized by CKit).${limitNote}`, true)}\n${accessFacts()}\n${lanes.length ? `LANES (choose exactly one; you may not invent lanes or teams):\n${laneRosterText()}\n${ownerLane ? `The owner FIXED the lane: "${ownerLane.id}". Brief only its teams. You may still answer NEED INFO or CANNOT DO.` : 'On PROCEED you MUST include a line "LANE: <lane id>" and a line "LANE REASON: <one sentence>", and write sections only for the teams of that lane. If no lane fits, answer DECISION: CANNOT DO with the reason "no lane fits" and say which lane would be needed; if the request is unclear between lanes, use NEED INFO.'}` : `TEAM ROSTER (pipeline order):\n${rosterText()}`}\n${common()}${answered}`);
|
|
890
|
+
const ask = () => directorAsk('intake brief', `${role(config.director, `You are the Director. First triage the owner request, then (only on PROCEED) split it between your teams.\nYour reply must contain exactly one decision line on its own line: "DECISION: PROCEED", "DECISION: NEED INFO" or "DECISION: CANNOT DO".\n- PROCEED: write a short overall summary (scope), an "ASSUMPTIONS:" list when you assumed anything, then one section per listed team, each starting with a line exactly "### TEAM <team id>" followed by: what this team must do for this goal, the expected deliverable, and what is out of scope for it. Assign every part of the goal to exactly one listed team and assign nothing to a team that is not listed.\n- NEED INFO: no team starts. Write a numbered list of at most 5 specific questions, each with why you need it; when sensible add a line "ASSUMPTIONS IF NO ANSWER:" followed by what you would assume.\n- CANNOT DO: write "REASON:" and then "WHAT WOULD WORK:" with 1 to 3 alternatives.\nRules: prefer PROCEED with stated assumptions when the gap is small and a wrong guess is cheap. Use NEED INFO only when a wrong guess wastes work or risks damage. Use CANNOT DO only when no reasonable reading of the request can be achieved with the configured teams, their access and this workspace. Never invent requirements. Never start teams on a request you do not understand. Answer in the owner's language. You may read project files (read only) to decide. Check the work is assignable: changing files needs a team with a write agent.\nOn PROCEED also add a line "MODE: <mode>" and a line "MODE REASON: <one sentence>". Modes: DIRECT = you answer it yourself right now (a question answerable from the request, the project files or a small lookup): put the complete answer for the owner in your reply and write no team sections; DELEGATE <agent id> = one best-fit agent does it alone (single-scope investigation or small fix); PARALLEL_MERGE = several agents give independent views at the same time and their team leads merge (options, reviews, risk); PARALLEL_EXECUTE = multi-part implementation through the teams. Never activate an agent just because it is configured; choose the cheapest mode that is good enough.\nWith DELEGATE, PARALLEL_MERGE, PARALLEL_EXECUTE or TARGETED_DISCUSSION also add a line "TEAMS: <team ids, comma separated>" naming ONLY the teams that must run (the pipeline order is kept); every other team is skipped. A read-only goal (a question, analysis or review where no file may change) activates no team with a write agent and no Test or QC team: those exist to change and verify files.\nWith PARALLEL_EXECUTE also add a line "DEPENDS: <team> <- <team>, <team>; <team> <- none; ..." saying which teams need which other teams' results first; teams with no dependency between them run at the same time. Do not chain every team after the previous one: list only real data dependencies (example for ba, implement, test, security, qc: "DEPENDS: implement <- ba; test <- implement; security <- implement; qc <- test, security" — Test and Security both only need the implementation, so they review it at the same time) (a team may only depend on teams earlier in the pipeline order; writes to the workspace are still serialized by CKit).${limitNote}`, true)}\n${accessFacts()}\n${lanes.length ? `LANES (choose exactly one; you may not invent lanes or teams):\n${laneRosterText()}\n${ownerLane ? `The owner FIXED the lane: "${ownerLane.id}". Brief only its teams. You may still answer NEED INFO or CANNOT DO.` : 'On PROCEED you MUST include a line "LANE: <lane id>" and a line "LANE REASON: <one sentence>", and write sections only for the teams of that lane. If no lane fits, answer DECISION: CANNOT DO with the reason "no lane fits" and say which lane would be needed; if the request is unclear between lanes, use NEED INFO.'}` : `TEAM ROSTER (pipeline order):\n${rosterText()}`}\n${common()}${answered}`);
|
|
862
891
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
863
892
|
const t = await ask();
|
|
864
893
|
if (t?.trim())
|
|
@@ -1109,11 +1138,23 @@ export function startTeamRun(opts) {
|
|
|
1109
1138
|
const earlyPlans = new Map();
|
|
1110
1139
|
/** PF-TEST: once the contract (the team right before Implement) is accepted, a later Tester team starts deriving test scenarios in parallel with Implement, read-only. It blocks nothing; only the Tester's own pass waits for it. */
|
|
1111
1140
|
const startEarlyTest = (k) => {
|
|
1112
|
-
if (earlyTest ||
|
|
1141
|
+
if (earlyTest || collabMode === 'DIRECT' || collabMode === 'DELEGATE' || process.env['CKIT_EARLY_TEST'] === '0')
|
|
1113
1142
|
return;
|
|
1114
1143
|
const impl = order.indexOf('implement'), tid = order.find((x, i) => i > impl && x !== 'qc' && /\btesters?\b/i.test(teamName(x))); // a team named "Tester" (the default Tester team)
|
|
1115
1144
|
if (impl < 0 || k !== impl - 1 || !tid)
|
|
1116
1145
|
return;
|
|
1146
|
+
if (graph) {
|
|
1147
|
+
const seen = new Set(), q = [...(graph.get(tid) ?? [])];
|
|
1148
|
+
while (q.length) {
|
|
1149
|
+
const d = q.pop();
|
|
1150
|
+
if (!seen.has(d)) {
|
|
1151
|
+
seen.add(d);
|
|
1152
|
+
q.push(...(graph.get(d) ?? []));
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
if (!seen.has('implement'))
|
|
1156
|
+
return;
|
|
1157
|
+
} // the Tester does not wait for Implement: its own pass starts now, no early plan needed
|
|
1117
1158
|
const agents = agentsOf(tid);
|
|
1118
1159
|
if (!agents.length)
|
|
1119
1160
|
return;
|
|
@@ -1619,6 +1660,13 @@ export function startTeamRun(opts) {
|
|
|
1619
1660
|
if (ctl.signal.aborted)
|
|
1620
1661
|
throw new NodeCancelled();
|
|
1621
1662
|
halted();
|
|
1663
|
+
if (earlyTest && earlyTest.id === id && !earlyPlans.has(id)) {
|
|
1664
|
+
setWait(agentsOf(id)[0]?.id ?? id, 'waiting-dependency', earlyTest.taskId);
|
|
1665
|
+
const plan = await earlyTest.p;
|
|
1666
|
+
halted();
|
|
1667
|
+
if (plan)
|
|
1668
|
+
earlyPlans.set(id, plan);
|
|
1669
|
+
}
|
|
1622
1670
|
const my = new AbortController();
|
|
1623
1671
|
nctl.set(id, my);
|
|
1624
1672
|
started.add(id);
|
|
@@ -1667,6 +1715,8 @@ export function startTeamRun(opts) {
|
|
|
1667
1715
|
continue;
|
|
1668
1716
|
}
|
|
1669
1717
|
}
|
|
1718
|
+
if (cp.decision !== 'return')
|
|
1719
|
+
startEarlyTest(k); // PF-TEST in the task graph too: the Tester designs tests from the contract while Implement works
|
|
1670
1720
|
for (const d of dependents(id)) {
|
|
1671
1721
|
if (cp.dispatch)
|
|
1672
1722
|
dispatches.set(d, cp.dispatch);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngockhoale/ckit",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "CKit — local Agent Company: a Director plus BA / Implement / QC teams running your own codex, claude and omp CLIs, with a web Mission Control (ckit gui).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|