@abelxiaoxing/cadence 2.0.21 → 2.0.22
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/README.de.md +1 -1
- package/README.es.md +1 -1
- package/README.fr.md +1 -1
- package/README.ja.md +1 -1
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/README.pt-BR.md +1 -1
- package/README.ru.md +1 -1
- package/README.zh-CN.md +1 -1
- package/docs/conversation-mode.md +17 -7
- package/package.json +1 -1
- package/src/agent-panel-cadence.ts +302 -10
- package/src/cadence-instructions.ts +1 -1
- package/src/cadence-mode.ts +681 -225
- package/src/cadence-preferences.ts +43 -8
- package/src/native-build.ts +1 -1
- package/src/native-client.ts +44 -1
- package/src/service/contracts/workbench.ts +39 -3
- package/src/service/contracts/workflow.ts +38 -12
- package/src/service-host.mjs +2452 -1271
- package/src/task-shell.ts +1 -1
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +15 -15
- package/web/dist/manifest.json +7 -7
package/README.de.md
CHANGED
|
@@ -45,7 +45,7 @@ Port und Token liegen in `~/.pi/agent/cadence/.env`; wer das Token hat, kann dei
|
|
|
45
45
|
Dieses Gespräch bleibt im Cadence-Modus; kläre Anforderungen mit normalen Nachrichten.
|
|
46
46
|
4. Prüfe den vollständigen Plan und klicke **Implement this plan**.
|
|
47
47
|
Implementierung, Checks, begrenzte Reparaturen und die vereinbarte lokale Lieferung laufen automatisch.
|
|
48
|
-
5. Verfolge Fortschritt
|
|
48
|
+
5. Verfolge den Fortschritt im Gespräch; die Protokolle der Subagenten öffnest du über das Dock **Subagents** unten links.
|
|
49
49
|
Aktualisieren und Abschluss beenden den Modus nicht.
|
|
50
50
|
**Exit Cadence** beendet nur den Modus; **Cancel workflow — request stop** fordert den Abbruch an.
|
|
51
51
|
|
package/README.es.md
CHANGED
|
@@ -45,7 +45,7 @@ El puerto y el token están en `~/.pi/agent/cadence/.env`; cualquiera con el tok
|
|
|
45
45
|
Esta conversación permanece en modo Cadence; aclara los requisitos con mensajes normales.
|
|
46
46
|
4. Revisa el plan completo y pulsa **Implement this plan**.
|
|
47
47
|
La implementación, comprobaciones, reparaciones limitadas y entrega local acordada son automáticas.
|
|
48
|
-
5. Sigue el progreso
|
|
48
|
+
5. Sigue el progreso en la conversación; abre los registros de los subagentes desde el panel **Subagents** abajo a la izquierda.
|
|
49
49
|
Recargar o terminar un objetivo no desactiva el modo.
|
|
50
50
|
**Exit Cadence** sale del modo; **Cancel workflow — request stop** solicita cancelar el trabajo.
|
|
51
51
|
|
package/README.fr.md
CHANGED
|
@@ -45,7 +45,7 @@ Le port et le jeton se trouvent dans `~/.pi/agent/cadence/.env` ; quiconque poss
|
|
|
45
45
|
Cette conversation reste en mode Cadence ; précisez les besoins par des messages ordinaires.
|
|
46
46
|
4. Lisez le plan complet et cliquez sur **Implement this plan**.
|
|
47
47
|
L’implémentation, les vérifications, les réparations bornées et la livraison locale convenue sont automatiques.
|
|
48
|
-
5. Suivez la progression
|
|
48
|
+
5. Suivez la progression dans la conversation ; ouvrez les traces des sous-agents depuis le panneau **Subagents** en bas à gauche.
|
|
49
49
|
Actualiser ou terminer un objectif ne quitte pas le mode.
|
|
50
50
|
**Exit Cadence** quitte le mode ; **Cancel workflow — request stop** demande l’annulation.
|
|
51
51
|
|
package/README.ja.md
CHANGED
|
@@ -56,7 +56,7 @@ pi install "$(npm root -g)/@abelxiaoxing/cadence"
|
|
|
56
56
|
この会話は Cadence モードを維持し、その後は通常のメッセージで要件を明確にできます。
|
|
57
57
|
4. 完全な計画を確認し、**Implement this plan** を押します。
|
|
58
58
|
実装、検証、回数制限付きの修正、合意したローカル納品が自動で進みます。
|
|
59
|
-
5.
|
|
59
|
+
5. 同じ会話で進捗を確認し、サブエージェントの記録は左下の **Subagents** パネルから開きます。
|
|
60
60
|
再読み込みや目標完了でもモードは維持されます。
|
|
61
61
|
**Exit Cadence** はモード終了のみ、**Cancel workflow — request stop** は作業のキャンセル要求です。
|
|
62
62
|
|
package/README.ko.md
CHANGED
|
@@ -54,7 +54,7 @@ pi install "$(npm root -g)/@abelxiaoxing/cadence"
|
|
|
54
54
|
이 대화는 Cadence 모드를 유지하며 이후에는 일반 메시지로 요구사항을 구체화합니다.
|
|
55
55
|
4. 전체 계획을 확인하고 **Implement this plan**을 누르세요.
|
|
56
56
|
구현, 검사, 제한된 수정 및 합의한 로컬 전달을 자동으로 진행합니다.
|
|
57
|
-
5. 같은 대화에서 진행
|
|
57
|
+
5. 같은 대화에서 진행 상황을 확인하고, 서브에이전트 기록은 왼쪽 아래 **Subagents** 패널에서 여세요.
|
|
58
58
|
새로고침이나 목표 완료로 모드가 꺼지지 않습니다.
|
|
59
59
|
**Exit Cadence**는 모드만 종료하고, **Cancel workflow — request stop**은 작업 취소를 요청합니다.
|
|
60
60
|
|
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ The port and token live in `~/.pi/agent/cadence/.env`; anyone with the token can
|
|
|
46
46
|
3. Send `/cadence [goal]` once to enter Cadence in this conversation; continue with normal messages to investigate and clarify requirements.
|
|
47
47
|
4. Review the complete inline plan and click **Implement this plan** (or send `按计划实施`).
|
|
48
48
|
The owner implements, verifies, repairs within budget and delivers as approved.
|
|
49
|
-
5. Follow actual progress
|
|
49
|
+
5. Follow actual progress and local merge results in the conversation; open any subagent's full context from the lower-left **Subagents** dock.
|
|
50
50
|
Refresh and completion keep Cadence on; **Exit Cadence** only exits the mode, while **Cancel workflow — request stop** requests cancellation.
|
|
51
51
|
|
|
52
52
|
**Legacy task** retains the old create/plan/Save/Start/check/human-Review route explicitly.
|
package/README.pt-BR.md
CHANGED
|
@@ -45,7 +45,7 @@ A porta e o token ficam em `~/.pi/agent/cadence/.env`; qualquer pessoa com o tok
|
|
|
45
45
|
Esta conversa permanece no modo Cadence; esclareça os requisitos com mensagens normais.
|
|
46
46
|
4. Revise o plano completo e clique em **Implement this plan**.
|
|
47
47
|
Implementação, verificações, reparos limitados e entrega local acordada são automáticos.
|
|
48
|
-
5. Acompanhe o progresso
|
|
48
|
+
5. Acompanhe o progresso na conversa; abra os registros dos subagentes no painel **Subagents**, no canto inferior esquerdo.
|
|
49
49
|
Atualizar a página ou concluir um objetivo não desativa o modo.
|
|
50
50
|
**Exit Cadence** sai do modo; **Cancel workflow — request stop** solicita o cancelamento.
|
|
51
51
|
|
package/README.ru.md
CHANGED
|
@@ -45,7 +45,7 @@ pi install "$(npm root -g)/@abelxiaoxing/cadence"
|
|
|
45
45
|
Разговор остаётся в режиме Cadence; уточняйте требования обычными сообщениями.
|
|
46
46
|
4. Проверьте полный план и нажмите **Implement this plan**.
|
|
47
47
|
Реализация, проверки, ограниченные исправления и согласованная локальная интеграция выполняются автоматически.
|
|
48
|
-
5. Следите за ходом работы
|
|
48
|
+
5. Следите за ходом работы в разговоре; записи субагентов открываются из панели **Subagents** слева внизу.
|
|
49
49
|
Обновление страницы и завершение цели не выключают режим.
|
|
50
50
|
**Exit Cadence** выходит из режима; **Cancel workflow — request stop** запрашивает отмену работы.
|
|
51
51
|
|
package/README.zh-CN.md
CHANGED
|
@@ -44,7 +44,7 @@ pi install "$(npm root -g)/@abelxiaoxing/cadence"
|
|
|
44
44
|
3. 输入一次 `/cadence [目标]`,当前对话进入持续 Cadence 模式;之后正常对话,调查项目并反复澄清需求。
|
|
45
45
|
4. 查看完整计划,点击**按此计划实施**或发送 `按计划实施`。
|
|
46
46
|
后台自动实施、检查、有限修复,并按计划完成本地交付。
|
|
47
|
-
5.
|
|
47
|
+
5. 在同一对话查看真实进度和合并结果;子代理的完整上下文从左下角**子代理**面板打开。
|
|
48
48
|
刷新、完成目标后仍保持 Cadence;**退出 Cadence**不取消后台工作,**取消工作流 — 请求停止**才请求取消。
|
|
49
49
|
|
|
50
50
|
“旧版任务”入口明确保留原有创建任务、Save/Start、独立检查和人工 Review 路径。
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
In a trusted Pi terminal or a WebUI conversation in an explicitly selected project, enter `/cadence <goal>` once (or `/cadence` to discuss the goal).
|
|
4
4
|
Cadence stays enabled for the entire conversation, including after a goal finishes.
|
|
5
5
|
Continue using normal messages; do not repeat the command for clarification or another goal.
|
|
6
|
-
Type `退出 Cadence` or `exit cadence` to leave the mode explicitly.
|
|
6
|
+
Type `退出 Cadence` or `exit cadence` (in Pi also `/cadence exit`) to leave the mode explicitly.
|
|
7
7
|
Leaving, closing Pi/browser and switching conversations detach; they do not cancel accepted work.
|
|
8
8
|
Browser conversation mode is retained by the project owner, not by a browser-only toggle, and works without a live Pi terminal.
|
|
9
9
|
|
|
@@ -23,6 +23,8 @@ Browser conversation mode is retained by the project owner, not by a browser-onl
|
|
|
23
23
|
Ask for status, more detail, cancellation, or the next goal normally.
|
|
24
24
|
|
|
25
25
|
Native mode is branch-aware; browser mode follows its server-owned conversation identity.
|
|
26
|
+
A saved native mode is active only in a trusted interactive terminal; print/RPC sessions keep ordinary tools and can still exit with `/cadence exit`.
|
|
27
|
+
In Pi, the agent panel lists workflow subagents and opens their transcripts; `cadence_status` can read one step's transcript.
|
|
26
28
|
Resume and compaction retain the mode/context, not execution grants.
|
|
27
29
|
Opening a different conversation does not enable Cadence there.
|
|
28
30
|
Restore never replays a command or automatically resumes an interrupted queue.
|
|
@@ -34,7 +36,7 @@ The first native use defaults to the current Pi provider/model/API/thinking sele
|
|
|
34
36
|
The selected preference is remembered in `<agent-dir>/cadence/settings.json` (normally `~/.pi/agent/cadence/settings.json`) and reused across projects.
|
|
35
37
|
Ask Cadence to change its model in Pi, or use **Model** in the browser.
|
|
36
38
|
The browser restores an available saved preference on explicit Send; reads/login do not install a choice.
|
|
37
|
-
If no usable preference exists, choose once.
|
|
39
|
+
If no usable preference exists, choose once; an unreadable preference file falls back to the current Pi model, and choosing a model rewrites it.
|
|
38
40
|
An accepted run keeps its original exact model.
|
|
39
41
|
An unavailable remembered model is not silently substituted.
|
|
40
42
|
Pi's original model and authentication sources remain authoritative; Cadence does not copy credentials.
|
|
@@ -63,11 +65,17 @@ The plan chooses one delivery policy:
|
|
|
63
65
|
Failed or canceled work leaves actual edits in place; this is not transactional application or a sandbox.
|
|
64
66
|
|
|
65
67
|
A local-merge plan does not adopt existing dirty inputs into its committed baseline.
|
|
66
|
-
Dirty declared targets refuse before implementation; unrelated user changes are preserved and
|
|
68
|
+
Dirty declared targets refuse before implementation; unrelated user changes made during a run are preserved and do not block integration (Git refuses a genuine overlap).
|
|
69
|
+
A write path naming a directory covers the files below it; in Git, working-copy edits outside the declared writes fail the run (the edits stay).
|
|
67
70
|
Unresolved conflicts or a changed target stop integration.
|
|
68
71
|
Cadence never resets, stashes, force-pushes or silently cleans uncertain worktrees.
|
|
69
72
|
Ignored generated Markdown remains ignored and is published without forcing it into Git.
|
|
70
|
-
|
|
73
|
+
Clean worktrees are removed after a successful merge (plain `git worktree remove`, which also deletes their ignored setup output such as `node_modules`); dirty or moved ones and all results are retained.
|
|
74
|
+
Only one approved implementation runs at a time; approving a second while one is active is refused with `conflict`.
|
|
75
|
+
The 90-minute budget starts when the run acquires the checkout; Cancel/Stop never interrupt the final fast-forward (a hung `git merge` therefore delays Stop until Git exits).
|
|
76
|
+
Local-merge plans cannot declare files that Git ignores; use working-copy delivery for those.
|
|
77
|
+
After an owner restart, an unfinished run is shown as `unknown` with its retained worktrees; it is never resumed.
|
|
78
|
+
Credential-looking text in plans and research questions is shown and approved redacted.
|
|
71
79
|
|
|
72
80
|
An isolated worktree does **not** inherit ignored `node_modules`, build output, credentials or profiles.
|
|
73
81
|
Investigate prerequisites during planning.
|
|
@@ -80,7 +88,7 @@ Final candidate checks must pass before merge.
|
|
|
80
88
|
Post-merge failures remain failures and report the actual merge commit; no rollback is fabricated.
|
|
81
89
|
Automatic review is never recorded as human review.
|
|
82
90
|
|
|
83
|
-
|
|
91
|
+
To request orderly closure, ask Cadence to cancel in Pi, or use **Cancel workflow — request stop** in the browser (the browser coordinator cannot cancel).
|
|
84
92
|
A pending or unknown cancellation is not reported as stopped.
|
|
85
93
|
Failures, timeouts and unknown process/auth/storage outcomes remain distinct; unknown resources retain fences for explicit informed recovery.
|
|
86
94
|
|
|
@@ -88,13 +96,15 @@ Failures, timeouts and unknown process/auth/storage outcomes remain distinct; un
|
|
|
88
96
|
|
|
89
97
|
An explicit native mode entry/current user Send may start or reuse its local project owner on demand.
|
|
90
98
|
It does not install a system service, enable boot startup, select another account's credentials or expose a public listener.
|
|
99
|
+
Pi says once which command stops an owner it started; when Pi runs on Bun, Node must be on `PATH`.
|
|
91
100
|
An existing owner/configuration is reused, not silently replaced after a connection failure.
|
|
92
101
|
System-service installation and remote access remain separate explicit operations described in [Service management](service-management.md) and [Remote access](remote-access.md).
|
|
93
102
|
|
|
94
103
|
`/cadence-inspect` retains the previous advanced task/history UI for diagnostics and legacy workflows; it is not needed for conversation mode.
|
|
95
104
|
The WebUI uses the same execution engine with a separate, context-bound browser confirmation path.
|
|
96
|
-
Its main composer stays in the same conversation; plan, workflow progress
|
|
97
|
-
|
|
105
|
+
Its main composer stays in the same conversation; the plan card, workflow progress and actual merge outcomes appear inline.
|
|
106
|
+
Research, implementation and review subagents are listed in the lower-left **Subagents** dock, together with legacy task children; selecting one (or **Open subagent context** on a step) opens its full transcript and retained result in the main area, and **Back to conversation** returns.
|
|
107
|
+
Active workflows are listed under **Running conversations** with **Cancel workflow — request stop**; this includes native-started workflows, and an unavailable observation is not proof of no work.
|
|
98
108
|
**Legacy task** retains the old create/plan/Save/Start/check/human-Review route explicitly, rather than making `/cadence` create a legacy task.
|
|
99
109
|
Existing browser conversations enter the new mode only on explicit Send/activation; old tasks and Pi transcripts are not converted or imported.
|
|
100
110
|
Approval grants are neither stored in the browser nor restored after restart.
|
package/package.json
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
/** Cadence service children on the background-agent panel. Observation only:
|
|
2
2
|
* a Pi TUI session attaches to the owner already running for its workspace
|
|
3
|
-
* (never starting one), polls the active roster and task snapshots
|
|
4
|
-
*
|
|
3
|
+
* (never starting one), polls the active task roster and task snapshots plus
|
|
4
|
+
* the conversation-workflow roster and runs, and announces each child run
|
|
5
|
+
* (task children and workflow research/implementation/review subagents) on
|
|
6
|
+
* Pi's `subagent:*` bus. Reads go through the
|
|
5
7
|
* typed ServiceClient; nothing here starts, cancels, retries or keeps work
|
|
6
8
|
* alive, and leaving the session only detaches. */
|
|
7
9
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
8
10
|
import { SUBAGENT_EVENTS, SUBAGENT_VIEW } from "./agent-panel-model.ts";
|
|
9
11
|
import { departure, NativeConnection } from "./native-client.ts";
|
|
12
|
+
import type { ChatTurn } from "./service/contracts/workbench.ts";
|
|
13
|
+
import type {
|
|
14
|
+
WorkflowRun,
|
|
15
|
+
WorkflowStep,
|
|
16
|
+
} from "./service/contracts/workflow.ts";
|
|
10
17
|
import type { ServiceClient } from "./service-client.ts";
|
|
11
18
|
import {
|
|
12
19
|
type ContentRef,
|
|
@@ -25,6 +32,8 @@ export interface FeedConnection {
|
|
|
25
32
|
refresh(): Promise<unknown>;
|
|
26
33
|
compatible(): boolean;
|
|
27
34
|
detach(): Promise<void>;
|
|
35
|
+
/** Drop an attachment whose owner the registry proves gone or replaced. */
|
|
36
|
+
forgetSuperseded?(cwd: string): boolean;
|
|
28
37
|
}
|
|
29
38
|
/** Readonly ServiceClient reads only: no command, preflight or Cancel. */
|
|
30
39
|
export type FeedClient = Pick<
|
|
@@ -36,6 +45,7 @@ export type FeedClient = Pick<
|
|
|
36
45
|
| "tools"
|
|
37
46
|
| "contents"
|
|
38
47
|
| "detail"
|
|
48
|
+
| "workbenchRead"
|
|
39
49
|
>;
|
|
40
50
|
export interface CadenceFeedOptions {
|
|
41
51
|
connection?: () => FeedConnection;
|
|
@@ -56,7 +66,7 @@ export const FEED_TIMING: FeedTiming = {
|
|
|
56
66
|
idleMs: LIMITS.heartbeatMs,
|
|
57
67
|
retryMs: 15_000,
|
|
58
68
|
};
|
|
59
|
-
/** Retained reads are paged; a child larger than this stays in /cadence History. */
|
|
69
|
+
/** Retained reads are paged; a child larger than this stays in /cadence-inspect History. */
|
|
60
70
|
const MAX_PAGES = 50;
|
|
61
71
|
const MAX_DETAIL_STEPS = 8;
|
|
62
72
|
/** Characters of one field shown in the panel; the rest stays retained. */
|
|
@@ -64,6 +74,14 @@ const TEXT_CAP = 64 * 1024;
|
|
|
64
74
|
const CACHE_CHARS = 16 * 1024 * 1024;
|
|
65
75
|
/** Snapshots after an episode drained, while its children still look unsettled. */
|
|
66
76
|
const DRAIN_LOOKS = 5;
|
|
77
|
+
/** A running workflow subagent not shown in a view refreshes its activity at
|
|
78
|
+
* most this often; its retained transcript is one bounded owner file. */
|
|
79
|
+
const WORKFLOW_ACTIVITY_MS = 10_000;
|
|
80
|
+
const WORKFLOW_KINDS: Partial<Record<WorkflowStep["kind"], string>> = {
|
|
81
|
+
research: "Research",
|
|
82
|
+
implementation: "Implementation",
|
|
83
|
+
review: "Review",
|
|
84
|
+
};
|
|
67
85
|
|
|
68
86
|
type Child = {
|
|
69
87
|
id: string;
|
|
@@ -84,6 +102,14 @@ type Child = {
|
|
|
84
102
|
failedSeq?: string;
|
|
85
103
|
/** Final transcript messages already announced. */
|
|
86
104
|
sent: number;
|
|
105
|
+
/** A conversation-workflow subagent, read through workflow transcripts. */
|
|
106
|
+
workflow?: {
|
|
107
|
+
runId: string;
|
|
108
|
+
stepId: string;
|
|
109
|
+
/** The final transcript was announced after the step ended. */
|
|
110
|
+
done?: boolean;
|
|
111
|
+
readAt?: number;
|
|
112
|
+
};
|
|
87
113
|
};
|
|
88
114
|
type Tool = Extract<HistoryRecord, { kind: "tool" }>;
|
|
89
115
|
type Block = { index: number; ref: ContentRef };
|
|
@@ -176,6 +202,74 @@ function parseArgs(text: string | undefined): object {
|
|
|
176
202
|
return {};
|
|
177
203
|
}
|
|
178
204
|
}
|
|
205
|
+
const capped = (text: string) =>
|
|
206
|
+
text.length > TEXT_CAP
|
|
207
|
+
? `${text.slice(0, TEXT_CAP)}\n… (truncated; the project owner retains the full text)`
|
|
208
|
+
: text;
|
|
209
|
+
/** A workflow step transcript in Pi's message shapes. Each assistant message
|
|
210
|
+
* carries its tool calls, followed by their results; while the turn runs, its
|
|
211
|
+
* last group may still grow and is a streaming snapshot. */
|
|
212
|
+
export function turnMessages(
|
|
213
|
+
turn: ChatTurn,
|
|
214
|
+
finished: boolean,
|
|
215
|
+
): { messages: object[]; partial?: object } {
|
|
216
|
+
const messages: object[] = [];
|
|
217
|
+
let group:
|
|
218
|
+
| { assistant: { role: string; content: object[] }; results: object[] }
|
|
219
|
+
| undefined;
|
|
220
|
+
const close = () => {
|
|
221
|
+
if (group) messages.push(group.assistant, ...group.results);
|
|
222
|
+
group = undefined;
|
|
223
|
+
};
|
|
224
|
+
for (const item of turn.items) {
|
|
225
|
+
if (item.role === "user") {
|
|
226
|
+
close();
|
|
227
|
+
messages.push({
|
|
228
|
+
role: "user",
|
|
229
|
+
content: [{ type: "text", text: capped(item.text) }],
|
|
230
|
+
});
|
|
231
|
+
} else if (item.role === "assistant") {
|
|
232
|
+
close();
|
|
233
|
+
group = {
|
|
234
|
+
assistant: {
|
|
235
|
+
role: "assistant",
|
|
236
|
+
content: item.text ? [{ type: "text", text: capped(item.text) }] : [],
|
|
237
|
+
},
|
|
238
|
+
results: [],
|
|
239
|
+
};
|
|
240
|
+
} else {
|
|
241
|
+
group ??= { assistant: { role: "assistant", content: [] }, results: [] };
|
|
242
|
+
const name = item.name || "tool";
|
|
243
|
+
group.assistant.content.push({
|
|
244
|
+
type: "toolCall",
|
|
245
|
+
id: item.id,
|
|
246
|
+
name,
|
|
247
|
+
arguments: parseArgs(item.args),
|
|
248
|
+
});
|
|
249
|
+
group.results.push({
|
|
250
|
+
role: "toolResult",
|
|
251
|
+
toolCallId: item.id,
|
|
252
|
+
toolName: name,
|
|
253
|
+
content: [{ type: "text", text: capped(item.text) }],
|
|
254
|
+
isError: item.error,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (finished || !group) {
|
|
259
|
+
close();
|
|
260
|
+
return { messages };
|
|
261
|
+
}
|
|
262
|
+
return { messages, partial: group.assistant };
|
|
263
|
+
}
|
|
264
|
+
function turnWorking(turn: ChatTurn, finished: boolean): string {
|
|
265
|
+
const tools = turn.items.filter((i) => i.role === "tool");
|
|
266
|
+
const last = tools.at(-1);
|
|
267
|
+
if (!last) return "Working";
|
|
268
|
+
if (!finished && turn.items.at(-1) === last && !last.text && !last.error)
|
|
269
|
+
return `Running ${last.name || "tool"}`;
|
|
270
|
+
const n = tools.length;
|
|
271
|
+
return `Working · ${n} tool call${n === 1 ? "" : "s"} (last: ${last.name || "tool"})`;
|
|
272
|
+
}
|
|
179
273
|
|
|
180
274
|
class Feed {
|
|
181
275
|
private client: FeedClient | undefined;
|
|
@@ -192,6 +286,9 @@ class Feed {
|
|
|
192
286
|
string,
|
|
193
287
|
{ taskId: string; drained: number }
|
|
194
288
|
>();
|
|
289
|
+
/** Conversation workflow → consecutive unreadable looks, followed until
|
|
290
|
+
* its run is observed finished. */
|
|
291
|
+
private readonly workflows = new Map<string, number>();
|
|
195
292
|
constructor(
|
|
196
293
|
private readonly pi: ExtensionAPI,
|
|
197
294
|
private readonly cwd: string,
|
|
@@ -245,13 +342,19 @@ class Feed {
|
|
|
245
342
|
next = await this.observe(this.client);
|
|
246
343
|
} catch {
|
|
247
344
|
// Absent, stopped, restarted or incompatible owner: detach and look
|
|
248
|
-
// again later. Observation never starts one.
|
|
345
|
+
// again later. Observation never starts one. An owner the registry
|
|
346
|
+
// proves gone or replaced cannot accept a detach (a restarted one on the
|
|
347
|
+
// same port refuses the old capability), so its attachment is dropped.
|
|
249
348
|
this.client = undefined;
|
|
250
|
-
|
|
349
|
+
if (!this.connection.forgetSuperseded?.(this.cwd))
|
|
350
|
+
await this.connection.detach().catch(() => {});
|
|
251
351
|
// Still no compatible owner a whole retry after losing it: the children
|
|
252
352
|
// followed so far can no longer be observed from this session.
|
|
253
|
-
if (attaching)
|
|
353
|
+
if (attaching) {
|
|
254
354
|
this.abandon([...this.episodes.keys()], "owner unavailable");
|
|
355
|
+
for (const runId of [...this.workflows.keys()])
|
|
356
|
+
this.abandonWorkflow(runId, "owner unavailable");
|
|
357
|
+
}
|
|
255
358
|
} finally {
|
|
256
359
|
this.busy = false;
|
|
257
360
|
}
|
|
@@ -291,12 +394,183 @@ class Feed {
|
|
|
291
394
|
this.abandon([runId], "no settled row after the run ended");
|
|
292
395
|
}
|
|
293
396
|
}
|
|
397
|
+
await this.observeWorkflows(client, ends);
|
|
398
|
+
if (this.stopped) return this.timing.activeMs;
|
|
294
399
|
await this.refreshActivity(client);
|
|
295
400
|
await this.refreshTranscript(client);
|
|
296
401
|
// Ends follow the transcript so its last streaming snapshot is replaced
|
|
297
402
|
// by the final message rather than kept beside it.
|
|
298
403
|
for (const end of ends) this.emit("end", end);
|
|
299
|
-
return this.episodes.size
|
|
404
|
+
return this.episodes.size || this.workflows.size
|
|
405
|
+
? this.timing.activeMs
|
|
406
|
+
: this.timing.idleMs;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** Conversation-workflow subagents: the live roster names runs, each run
|
|
410
|
+
* read names its steps' child IDs. Readonly; an older owner without these
|
|
411
|
+
* reads leaves only task children. */
|
|
412
|
+
private async observeWorkflows(
|
|
413
|
+
client: FeedClient,
|
|
414
|
+
ends: object[],
|
|
415
|
+
): Promise<void> {
|
|
416
|
+
if (typeof client.workbenchRead !== "function") return;
|
|
417
|
+
const signal = this.abort.signal;
|
|
418
|
+
const roster = await client.workbenchRead(
|
|
419
|
+
{ kind: "workflow-active" },
|
|
420
|
+
signal,
|
|
421
|
+
);
|
|
422
|
+
if (this.stopped) return;
|
|
423
|
+
const live = new Set<string>();
|
|
424
|
+
if (roster.kind === "ok" && roster.value.kind === "workflow-active")
|
|
425
|
+
for (const run of roster.value.runs) {
|
|
426
|
+
live.add(run.id);
|
|
427
|
+
if (!this.workflows.has(run.id)) this.workflows.set(run.id, 0);
|
|
428
|
+
}
|
|
429
|
+
for (const [runId, misses] of [...this.workflows]) {
|
|
430
|
+
const reply = await client.workbenchRead(
|
|
431
|
+
{ kind: "workflow", id: runId },
|
|
432
|
+
signal,
|
|
433
|
+
);
|
|
434
|
+
if (this.stopped) return;
|
|
435
|
+
if (
|
|
436
|
+
reply.kind === "error" ||
|
|
437
|
+
reply.value.kind !== "workflow" ||
|
|
438
|
+
reply.value.response.type !== "run" ||
|
|
439
|
+
reply.value.response.run.id !== runId
|
|
440
|
+
) {
|
|
441
|
+
if (misses + 1 >= DRAIN_LOOKS)
|
|
442
|
+
this.abandonWorkflow(runId, "workflow not readable");
|
|
443
|
+
else this.workflows.set(runId, misses + 1);
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
this.workflows.set(runId, 0);
|
|
447
|
+
const run = reply.value.response.run;
|
|
448
|
+
const open =
|
|
449
|
+
live.has(runId) || ["queued", "running"].includes(run.status);
|
|
450
|
+
for (const step of run.steps) this.followStep(run, step, open, ends);
|
|
451
|
+
if (!open) this.workflows.delete(runId);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
private followStep(
|
|
455
|
+
run: WorkflowRun,
|
|
456
|
+
step: WorkflowStep,
|
|
457
|
+
open: boolean,
|
|
458
|
+
ends: object[],
|
|
459
|
+
): void {
|
|
460
|
+
const kind = WORKFLOW_KINDS[step.kind];
|
|
461
|
+
if (!step.childRunId || !kind) return;
|
|
462
|
+
const id = step.childRunId;
|
|
463
|
+
// A step still marked running in a finished run did not report its end.
|
|
464
|
+
const outcome =
|
|
465
|
+
step.status === "running" ? (open ? null : "unknown") : step.status;
|
|
466
|
+
let child = this.state.children.get(id);
|
|
467
|
+
if (!child) {
|
|
468
|
+
child = {
|
|
469
|
+
id,
|
|
470
|
+
label: step.id,
|
|
471
|
+
runId: `workflow:${run.id}`,
|
|
472
|
+
storeId: "",
|
|
473
|
+
seq: "",
|
|
474
|
+
lifecycle: outcome ? "settled" : "running",
|
|
475
|
+
ended: false,
|
|
476
|
+
activity: "",
|
|
477
|
+
sent: 0,
|
|
478
|
+
workflow: { runId: run.id, stepId: step.id },
|
|
479
|
+
};
|
|
480
|
+
this.state.children.set(id, child);
|
|
481
|
+
this.emit("start", {
|
|
482
|
+
id,
|
|
483
|
+
label: step.id,
|
|
484
|
+
kind,
|
|
485
|
+
// A subagent first seen settled ran before this session looked.
|
|
486
|
+
startedAt: outcome ? null : this.now(),
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
if (child.ended) return;
|
|
490
|
+
if (!outcome) {
|
|
491
|
+
this.activity(child, child.working ?? `Working · ${run.phase}`);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
child.lifecycle = "settled";
|
|
495
|
+
this.activity(child, outcome);
|
|
496
|
+
child.ended = true;
|
|
497
|
+
ends.push({
|
|
498
|
+
id,
|
|
499
|
+
status:
|
|
500
|
+
outcome === "completed"
|
|
501
|
+
? "done"
|
|
502
|
+
: outcome === "canceled"
|
|
503
|
+
? "cancelled"
|
|
504
|
+
: "error",
|
|
505
|
+
endedAt: this.now(),
|
|
506
|
+
...(outcome === "completed" || outcome === "canceled"
|
|
507
|
+
? {}
|
|
508
|
+
: { error: `${child.label} · ${outcome}` }),
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
private abandonWorkflow(runId: string, why: string): void {
|
|
512
|
+
this.workflows.delete(runId);
|
|
513
|
+
for (const child of this.state.children.values()) {
|
|
514
|
+
if (child.workflow?.runId !== runId || child.ended) continue;
|
|
515
|
+
this.activity(child, "outcome not observed");
|
|
516
|
+
child.ended = true;
|
|
517
|
+
this.emit("end", {
|
|
518
|
+
id: child.id,
|
|
519
|
+
status: "error",
|
|
520
|
+
endedAt: this.now(),
|
|
521
|
+
error: `${child.label} · outcome not observed here (${why}); ask cadence_status or open the WebUI`,
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
/** Reads one workflow step transcript; undefined when it is unreadable. */
|
|
526
|
+
private async workflowTurn(
|
|
527
|
+
client: FeedClient,
|
|
528
|
+
child: Child,
|
|
529
|
+
): Promise<ChatTurn | null | undefined> {
|
|
530
|
+
const w = child.workflow;
|
|
531
|
+
if (!w || typeof client.workbenchRead !== "function") return undefined;
|
|
532
|
+
w.readAt = this.now();
|
|
533
|
+
const reply = await client.workbenchRead(
|
|
534
|
+
{ kind: "workflow-transcript", id: w.runId, stepId: w.stepId },
|
|
535
|
+
this.abort.signal,
|
|
536
|
+
);
|
|
537
|
+
if (
|
|
538
|
+
reply.kind === "error" ||
|
|
539
|
+
reply.value.kind !== "workflow-transcript" ||
|
|
540
|
+
reply.value.runId !== w.runId ||
|
|
541
|
+
reply.value.stepId !== w.stepId
|
|
542
|
+
)
|
|
543
|
+
return undefined;
|
|
544
|
+
return reply.value.turn;
|
|
545
|
+
}
|
|
546
|
+
private async refreshWorkflowTranscript(
|
|
547
|
+
client: FeedClient,
|
|
548
|
+
child: Child,
|
|
549
|
+
): Promise<void> {
|
|
550
|
+
const w = child.workflow;
|
|
551
|
+
if (!w || w.done || child.failedSeq !== undefined) return;
|
|
552
|
+
const turn = await this.workflowTurn(client, child);
|
|
553
|
+
if (this.stopped) return;
|
|
554
|
+
if (turn === undefined) {
|
|
555
|
+
// Reopening the view retries, like a failed task transcript read.
|
|
556
|
+
child.failedSeq = "workflow";
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
if (!turn) return;
|
|
560
|
+
const finished = !["queued", "running"].includes(turn.status);
|
|
561
|
+
const built = turnMessages(turn, finished);
|
|
562
|
+
child.working = turnWorking(turn, finished);
|
|
563
|
+
if (!child.ended) this.activity(child, child.working);
|
|
564
|
+
for (let i = child.sent; i < built.messages.length; i++)
|
|
565
|
+
this.emit("message", { id: child.id, message: built.messages[i] });
|
|
566
|
+
child.sent = Math.max(child.sent, built.messages.length);
|
|
567
|
+
if (built.partial)
|
|
568
|
+
this.emit("message", {
|
|
569
|
+
id: child.id,
|
|
570
|
+
message: built.partial,
|
|
571
|
+
streaming: true,
|
|
572
|
+
});
|
|
573
|
+
if (finished && child.ended) w.done = true;
|
|
300
574
|
}
|
|
301
575
|
|
|
302
576
|
/** Announce this episode's children; true while any still looks unsettled. */
|
|
@@ -381,7 +655,7 @@ class Feed {
|
|
|
381
655
|
}
|
|
382
656
|
/** Stop following these episodes. Their unsettled children end as errors
|
|
383
657
|
* that say the outcome was not observed, instead of spinning as running for
|
|
384
|
-
* the rest of the session; /cadence History keeps the actual outcome. */
|
|
658
|
+
* the rest of the session; /cadence-inspect History keeps the actual outcome. */
|
|
385
659
|
private abandon(runIds: string[], why: string): void {
|
|
386
660
|
for (const runId of runIds) {
|
|
387
661
|
this.episodes.delete(runId);
|
|
@@ -393,7 +667,7 @@ class Feed {
|
|
|
393
667
|
id: child.id,
|
|
394
668
|
status: "error",
|
|
395
669
|
endedAt: this.now(),
|
|
396
|
-
error: `${child.label} · outcome not observed here (${why}); see /cadence History`,
|
|
670
|
+
error: `${child.label} · outcome not observed here (${why}); see /cadence-inspect History`,
|
|
397
671
|
});
|
|
398
672
|
}
|
|
399
673
|
}
|
|
@@ -440,6 +714,23 @@ class Feed {
|
|
|
440
714
|
/** Latest tool for running children not shown in a view (that read covers it). */
|
|
441
715
|
private async refreshActivity(client: FeedClient): Promise<void> {
|
|
442
716
|
for (const child of this.state.children.values()) {
|
|
717
|
+
if (child.workflow) {
|
|
718
|
+
if (
|
|
719
|
+
child.ended ||
|
|
720
|
+
child.id === this.state.viewing ||
|
|
721
|
+
!this.workflows.has(child.workflow.runId) ||
|
|
722
|
+
this.now() - (child.workflow.readAt ?? 0) < WORKFLOW_ACTIVITY_MS
|
|
723
|
+
)
|
|
724
|
+
continue;
|
|
725
|
+
const turn = await this.workflowTurn(client, child);
|
|
726
|
+
if (this.stopped || !turn) continue;
|
|
727
|
+
child.working = turnWorking(
|
|
728
|
+
turn,
|
|
729
|
+
!["queued", "running"].includes(turn.status),
|
|
730
|
+
);
|
|
731
|
+
this.activity(child, child.working);
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
443
734
|
if (
|
|
444
735
|
child.ended ||
|
|
445
736
|
child.lifecycle !== "running" ||
|
|
@@ -459,6 +750,7 @@ class Feed {
|
|
|
459
750
|
private async refreshTranscript(client: FeedClient): Promise<void> {
|
|
460
751
|
const id = this.state.viewing;
|
|
461
752
|
const child = id === undefined ? undefined : this.state.children.get(id);
|
|
753
|
+
if (child?.workflow) return this.refreshWorkflowTranscript(client, child);
|
|
462
754
|
if (
|
|
463
755
|
!child ||
|
|
464
756
|
child.transcriptSeq === child.seq ||
|
|
@@ -539,7 +831,7 @@ class Feed {
|
|
|
539
831
|
}
|
|
540
832
|
// One detail page can exceed the cap on its own, with no cursor left.
|
|
541
833
|
if (cursor || text.length > TEXT_CAP)
|
|
542
|
-
text = `${text.slice(0, TEXT_CAP)}\n… (truncated; the full text is in /cadence History)`;
|
|
834
|
+
text = `${text.slice(0, TEXT_CAP)}\n… (truncated; the full text is in /cadence-inspect History)`;
|
|
543
835
|
this.state.remember(key, text);
|
|
544
836
|
return text;
|
|
545
837
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Shared conversation policy; clients supply distinct human-consent adapters. */
|
|
2
|
-
export const CADENCE_INSTRUCTIONS = `CADENCE CONVERSATION MODE — stays enabled for this entire conversation, including after a goal completes, until the user explicitly exits.
|
|
2
|
+
export const CADENCE_INSTRUCTIONS = `CADENCE CONVERSATION MODE — stays enabled for this entire conversation, including after a goal completes, until the user explicitly exits by typing 退出 Cadence or exit cadence. Only the user can exit; leaving never cancels accepted work. When asked how to leave, say exactly this.
|
|
3
3
|
You are the sole user-facing coordinator. Continue normal conversation, not a task-manager UI. Do not ask the user to manage tasks, IDs, JSON, service ports, Save/Start/check menus or agent assignments.
|
|
4
4
|
For each new goal: inspect relevant project evidence through cadence_research (up to two independent readonly subagents); read existing AGENTS/docs/.cadence/project.md before proposing conventions. Reuse still-current findings; do not rescan the entire repository or spawn agents merely to fill slots. Aggregate questions yourself. Investigate discoverable facts and ask focused, frequent questions only for unresolved product/technical decisions. Preserve confirmed decisions across turns. Diagnosis/research alone never imply implementation.
|
|
5
5
|
Once material decisions and acceptance criteria are aligned, use cadence_plan with a readable design, explicit non-goals/decisions, exact file scopes, a finite dependency DAG, real verification commands, worktree prerequisites and a bounded repair budget. Independent writes may run concurrently; shared files need a single owner or dependency. Investigate local tool/dependency prerequisites BEFORE finalizing: isolated worktrees do not inherit ignored node_modules. Setup commands require inclusion in the final approval; never silently install/download/copy dependencies or credentials. local-merge needs an existing Git branch and commit identity; working-copy is explicit direct editing without Git mutation and is serialized.
|