@abelxiaoxing/cadence 2.0.37 → 2.0.40
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 +2 -2
- package/README.es.md +2 -2
- package/README.fr.md +2 -2
- package/README.ja.md +2 -2
- package/README.ko.md +2 -2
- package/README.md +9 -7
- package/README.pt-BR.md +2 -2
- package/README.ru.md +2 -2
- package/README.zh-CN.md +10 -8
- package/agents/design-explorer.md +4 -2
- package/agents/diagnosis-worker.md +5 -2
- package/agents/implementation-worker.md +19 -12
- package/docs/conversation-mode.md +73 -16
- package/docs/reuse-and-distribution.md +78 -0
- package/package.json +7 -2
- package/src/activity.ts +147 -0
- package/src/agent-browser/session-navigator.ts +33 -6
- package/src/agent-browser/source.ts +23 -19
- package/src/agent-panel-cadence.ts +147 -628
- package/src/agent-panel-model.ts +30 -19
- package/src/agent-panel.ts +12 -16
- package/src/cadence-instructions.ts +8 -7
- package/src/cadence-mode.ts +30 -9
- package/src/change-tools.mjs +268 -0
- package/src/coordinator-tools.mjs +2 -2
- package/src/git-environment.d.mts +2 -0
- package/src/git-environment.mjs +24 -0
- package/src/index.ts +3 -1
- package/src/native-build.ts +1 -1
- package/src/native-workflow-history.ts +20 -3
- package/src/operator-cli.mjs +22 -12
- package/src/research-scan.mjs +111 -31
- package/src/research-tools.mjs +75 -16
- package/src/sdk-worker.mjs +6 -1
- package/src/service/activity-files.ts +190 -0
- package/src/service/contracts/workbench.ts +11 -3
- package/src/service/contracts/workflow.ts +283 -16
- package/src/service/coordination.ts +13 -3
- package/src/service-cli.mjs +392 -93
- package/src/service-host.mjs +7635 -5682
- package/src/worker-capture.mjs +24 -1
- package/src/worker-public.mjs +18 -0
- package/src/worker-redaction.mjs +11 -0
- package/src/worker-toolkit.mjs +55 -2
- package/src/workspace.ts +62 -25
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +19 -18
- package/web/dist/manifest.json +7 -7
package/src/activity.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/** Reports only an interactive Pi's real agent lifetime; no presence, owner or control. */
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import {
|
|
5
|
+
type ExtensionAPI,
|
|
6
|
+
getAgentDir,
|
|
7
|
+
} from "@earendil-works/pi-coding-agent";
|
|
8
|
+
import {
|
|
9
|
+
ACTIVITY_RENEW_MS,
|
|
10
|
+
ActivityFiles,
|
|
11
|
+
type NativeActivity,
|
|
12
|
+
} from "./service/activity-files.ts";
|
|
13
|
+
import { selfMark } from "./service/liveness.ts";
|
|
14
|
+
import { type FileSnapshot, hash } from "./service/private-files.ts";
|
|
15
|
+
import {
|
|
16
|
+
privateWorkspace,
|
|
17
|
+
resolveWorkspaceAsync,
|
|
18
|
+
stateHomeInside,
|
|
19
|
+
} from "./workspace.ts";
|
|
20
|
+
|
|
21
|
+
export interface ActivityPublisherOptions {
|
|
22
|
+
store?: () => Pick<
|
|
23
|
+
ActivityFiles,
|
|
24
|
+
"scope" | "publish" | "withdraw" | "retireDead"
|
|
25
|
+
>;
|
|
26
|
+
now?: () => number;
|
|
27
|
+
canonical?: (cwd: string, signal: AbortSignal) => string | Promise<string>;
|
|
28
|
+
}
|
|
29
|
+
export function registerActivity(
|
|
30
|
+
pi: ExtensionAPI,
|
|
31
|
+
options: ActivityPublisherOptions = {},
|
|
32
|
+
): void {
|
|
33
|
+
if (process.env.CADENCE_SUBAGENT_CHILD === "1") return;
|
|
34
|
+
const instance = randomUUID();
|
|
35
|
+
const now = options.now ?? Date.now;
|
|
36
|
+
let active:
|
|
37
|
+
| {
|
|
38
|
+
id: string;
|
|
39
|
+
sessionId: string;
|
|
40
|
+
abort: AbortController;
|
|
41
|
+
record?: NativeActivity;
|
|
42
|
+
saved?: FileSnapshot;
|
|
43
|
+
store?: ReturnType<NonNullable<ActivityPublisherOptions["store"]>>;
|
|
44
|
+
}
|
|
45
|
+
| undefined;
|
|
46
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
47
|
+
let retired = false;
|
|
48
|
+
const stop = () => {
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
timer = undefined;
|
|
51
|
+
const previous = active;
|
|
52
|
+
active = undefined; // Fence callbacks before any filesystem operation.
|
|
53
|
+
previous?.abort.abort();
|
|
54
|
+
try {
|
|
55
|
+
if (previous?.store && previous.saved)
|
|
56
|
+
previous.store.withdraw(instance, previous.saved);
|
|
57
|
+
} catch {
|
|
58
|
+
/* Retain uncertain bytes; discovery reports stale/unknown, not success. */
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
pi.on("agent_start", (_event, ctx) => {
|
|
62
|
+
if (retired || ctx.mode !== "tui" || !ctx.hasUI) return;
|
|
63
|
+
try {
|
|
64
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
65
|
+
if (active?.sessionId === sessionId) return; // retries/compaction/queued continuation
|
|
66
|
+
stop();
|
|
67
|
+
const cwdAtStart = ctx.cwd,
|
|
68
|
+
sessionScope = hash(ctx.sessionManager.getSessionDir()),
|
|
69
|
+
startedAt = now();
|
|
70
|
+
const current = {
|
|
71
|
+
id: randomUUID(),
|
|
72
|
+
sessionId,
|
|
73
|
+
abort: new AbortController(),
|
|
74
|
+
} as NonNullable<typeof active>;
|
|
75
|
+
active = current;
|
|
76
|
+
// Lifecycle hooks never await publication. One callback at a time; timers
|
|
77
|
+
// neither keep Pi alive nor run after settlement/session replacement.
|
|
78
|
+
const publish = async () => {
|
|
79
|
+
if (active !== current || retired) return;
|
|
80
|
+
try {
|
|
81
|
+
if (!current.store) {
|
|
82
|
+
current.store =
|
|
83
|
+
options.store?.() ?? new ActivityFiles(getAgentDir());
|
|
84
|
+
const resolving = options.canonical
|
|
85
|
+
? options.canonical(cwdAtStart, current.abort.signal)
|
|
86
|
+
: resolveWorkspaceAsync(cwdAtStart, current.abort.signal).then(
|
|
87
|
+
({ root, cwd }) => {
|
|
88
|
+
if (privateWorkspace(root) || stateHomeInside(root))
|
|
89
|
+
throw new Error("private-workspace");
|
|
90
|
+
return realpathSync(cwd);
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
const cwd =
|
|
94
|
+
typeof resolving === "string" ? resolving : await resolving;
|
|
95
|
+
if (active !== current || retired) return;
|
|
96
|
+
current.store.retireDead(now());
|
|
97
|
+
current.record = {
|
|
98
|
+
schema: "cadence-pi-activity/1",
|
|
99
|
+
instance,
|
|
100
|
+
activity: current.id,
|
|
101
|
+
scope: current.store.scope,
|
|
102
|
+
sessionScope,
|
|
103
|
+
process: selfMark(),
|
|
104
|
+
cwd,
|
|
105
|
+
sessionId,
|
|
106
|
+
leaf: null,
|
|
107
|
+
startedAt,
|
|
108
|
+
renewedAt: now(),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const record = current.record;
|
|
112
|
+
if (!record) return;
|
|
113
|
+
record.leaf = ctx.sessionManager.getLeafId();
|
|
114
|
+
record.renewedAt = now();
|
|
115
|
+
current.saved = current.store.publish(record, current.saved);
|
|
116
|
+
timer = setTimeout(publish, ACTIVITY_RENEW_MS);
|
|
117
|
+
timer.unref?.();
|
|
118
|
+
} catch {
|
|
119
|
+
/* Observation failures do not fail, cancel or retry Pi work. */
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
timer = setTimeout(publish, 0);
|
|
123
|
+
timer.unref?.();
|
|
124
|
+
} catch {
|
|
125
|
+
/* Metadata is optional; no error escapes into Pi. */
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
// agent_end is deliberately NOT a settlement signal.
|
|
129
|
+
pi.on("agent_settled", (_event, ctx) => {
|
|
130
|
+
if (!active || retired) return;
|
|
131
|
+
try {
|
|
132
|
+
if (active.sessionId === ctx.sessionManager.getSessionId()) stop();
|
|
133
|
+
} catch {
|
|
134
|
+
// An invalidated public context cannot fail Pi's final notification.
|
|
135
|
+
// Preserve uncertain metadata but never keep renewing an idle report.
|
|
136
|
+
clearTimeout(timer);
|
|
137
|
+
timer = undefined;
|
|
138
|
+
const previous = active;
|
|
139
|
+
active = undefined;
|
|
140
|
+
previous?.abort.abort();
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
pi.on("session_shutdown", () => {
|
|
144
|
+
retired = true;
|
|
145
|
+
stop();
|
|
146
|
+
});
|
|
147
|
+
}
|
|
@@ -69,11 +69,23 @@ export class SessionNavigator implements Component {
|
|
|
69
69
|
]);
|
|
70
70
|
if (this.signature === signature) return;
|
|
71
71
|
this.signature = signature;
|
|
72
|
+
const previousIndex = this.entries.findIndex(
|
|
73
|
+
(entry) => entry.id === this.selected,
|
|
74
|
+
);
|
|
75
|
+
// Keep an already-open transcript as a reading snapshot, but release the
|
|
76
|
+
// producer as soon as it leaves the live list. No historical rereads.
|
|
77
|
+
if (this.viewing && !entries.some((entry) => entry.id === this.viewing)) {
|
|
78
|
+
this.viewing = undefined;
|
|
79
|
+
this.source.view(null);
|
|
80
|
+
}
|
|
72
81
|
this.entries = entries;
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
entries.findIndex((entry) => entry.id === this.selected),
|
|
82
|
+
const selectedIndex = entries.findIndex(
|
|
83
|
+
(entry) => entry.id === this.selected,
|
|
76
84
|
);
|
|
85
|
+
const index =
|
|
86
|
+
selectedIndex >= 0
|
|
87
|
+
? selectedIndex
|
|
88
|
+
: Math.max(0, Math.min(previousIndex, entries.length - 1));
|
|
77
89
|
this.selected = entries[index]?.id;
|
|
78
90
|
this.list = new SelectList(
|
|
79
91
|
entries.map(({ id, label }) => ({ value: id, label })),
|
|
@@ -95,8 +107,14 @@ export class SessionNavigator implements Component {
|
|
|
95
107
|
}
|
|
96
108
|
|
|
97
109
|
private open(id: string): void {
|
|
110
|
+
// Mouse input can still name a row painted before its end. Recheck that
|
|
111
|
+
// exact id, rather than redirecting the click to a different live row.
|
|
112
|
+
this.refresh();
|
|
98
113
|
const entry = this.entries.find((candidate) => candidate.id === id);
|
|
99
|
-
if (!entry)
|
|
114
|
+
if (!entry) {
|
|
115
|
+
this.tui.requestRender();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
100
118
|
this.viewing = id;
|
|
101
119
|
let position = this.positions.get(id);
|
|
102
120
|
if (!position) {
|
|
@@ -144,10 +162,17 @@ export class SessionNavigator implements Component {
|
|
|
144
162
|
labeledRule(
|
|
145
163
|
width,
|
|
146
164
|
(text) => this.theme.fg("border", text),
|
|
147
|
-
["
|
|
165
|
+
["Running agents"],
|
|
148
166
|
[`${at + 1} / ${this.entries.length}`],
|
|
149
167
|
),
|
|
150
|
-
...(this.
|
|
168
|
+
...(this.entries.length
|
|
169
|
+
? (this.list?.render(width) ?? [])
|
|
170
|
+
: [
|
|
171
|
+
truncateToWidth(
|
|
172
|
+
this.theme.fg("dim", "No agents running in this session"),
|
|
173
|
+
width,
|
|
174
|
+
),
|
|
175
|
+
]),
|
|
151
176
|
truncateToWidth(
|
|
152
177
|
this.theme.fg("dim", "↑↓ select · Enter view · Esc return to input"),
|
|
153
178
|
width,
|
|
@@ -157,6 +182,8 @@ export class SessionNavigator implements Component {
|
|
|
157
182
|
|
|
158
183
|
handleInput(data: string): void {
|
|
159
184
|
if (isKeyRelease(data)) return;
|
|
185
|
+
// An end can arrive between the last paint and Enter: never open a stale row.
|
|
186
|
+
this.refresh();
|
|
160
187
|
if (this.pane) this.pane.handleInput(data);
|
|
161
188
|
else this.list?.handleInput(data);
|
|
162
189
|
this.tui.requestRender();
|
|
@@ -143,26 +143,30 @@ export function cadenceBrowserSource(
|
|
|
143
143
|
const sources = new Map<string, TranscriptSource>();
|
|
144
144
|
return {
|
|
145
145
|
entries: () => {
|
|
146
|
-
for (const id of sources.keys())
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
146
|
+
for (const id of sources.keys())
|
|
147
|
+
if (store.get(id)?.status !== "running") sources.delete(id);
|
|
148
|
+
return store
|
|
149
|
+
.ordered()
|
|
150
|
+
.filter((agent) => agent.status === "running")
|
|
151
|
+
.map((agent) => {
|
|
152
|
+
let source = sources.get(agent.id);
|
|
153
|
+
if (!source) {
|
|
154
|
+
source = transcriptSource(store, agent);
|
|
155
|
+
sources.set(agent.id, source);
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
id: agent.id,
|
|
159
|
+
label: `${described(agent)} · ${agent.status} · ${factsText(agent, now())}`,
|
|
160
|
+
heading: {
|
|
161
|
+
name: agent.label,
|
|
162
|
+
modeLabel: agent.kind,
|
|
163
|
+
get description() {
|
|
164
|
+
return agent.status;
|
|
165
|
+
},
|
|
161
166
|
},
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
};
|
|
165
|
-
});
|
|
167
|
+
source,
|
|
168
|
+
};
|
|
169
|
+
});
|
|
166
170
|
},
|
|
167
171
|
subscribe: (changed) => store.subscribe(changed),
|
|
168
172
|
view,
|