@abelxiaoxing/cadence 2.0.36 → 2.0.38
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 +4 -4
- package/README.es.md +4 -4
- package/README.fr.md +4 -4
- package/README.ja.md +4 -4
- package/README.ko.md +4 -4
- package/README.md +11 -9
- package/README.pt-BR.md +4 -4
- package/README.ru.md +4 -4
- package/README.zh-CN.md +12 -10
- package/THIRD_PARTY_NOTICES.md +9 -1
- 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 +46 -18
- package/docs/reuse-and-distribution.md +1 -1
- package/docs/service-management.md +35 -9
- package/package.json +16 -8
- package/src/agent-browser/labeled-rule.ts +74 -0
- package/src/agent-browser/session-navigator.ts +214 -0
- package/src/agent-browser/source.ts +174 -0
- package/src/agent-browser/transcript-content.ts +442 -0
- package/src/agent-browser/transcript-pane.ts +324 -0
- package/src/agent-panel-cadence.ts +147 -628
- package/src/agent-panel-model.ts +34 -267
- package/src/agent-panel.ts +139 -437
- 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 +44 -16
- package/src/git-environment.d.mts +2 -0
- package/src/git-environment.mjs +24 -0
- package/src/image-content.mjs +7 -28
- package/src/index.ts +1 -1
- package/src/native-build.ts +1 -1
- package/src/native-workflow-history.ts +20 -3
- package/src/operator-cli.mjs +18 -11
- package/src/research-scan.mjs +393 -0
- package/src/research-tools.mjs +406 -342
- package/src/sdk-worker.mjs +42 -55
- package/src/service/contracts/core.ts +0 -1
- package/src/service/contracts/workbench.ts +21 -19
- package/src/service/contracts/workflow.ts +283 -16
- package/src/service/coordination.ts +7 -0
- package/src/service-cli.mjs +652 -149
- package/src/service-host.mjs +2745 -1137
- package/src/worker-capture.mjs +24 -1
- package/src/worker-public.mjs +19 -2
- package/src/worker-redaction.mjs +11 -0
- package/src/worker-toolkit.mjs +157 -0
- package/src/worker-workspace.d.mts +13 -0
- package/src/worker-workspace.mjs +48 -0
- package/src/workspace.ts +4 -24
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +18 -17
- package/web/dist/manifest.json +7 -7
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/** Adapted from gotgenes/pi-packages @ 52854c12d590142e61a4f6a6947be9084035300d.
|
|
2
|
+
* MIT; see licenses/pi-subagents-MIT.txt and provenance/agent-browser-reuse.json. */
|
|
3
|
+
import type {
|
|
4
|
+
KeybindingsManager,
|
|
5
|
+
Theme,
|
|
6
|
+
} from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import {
|
|
8
|
+
type Component,
|
|
9
|
+
type Keybinding,
|
|
10
|
+
type KeyId,
|
|
11
|
+
type MarkdownTheme,
|
|
12
|
+
matchesKey,
|
|
13
|
+
type TUI,
|
|
14
|
+
type TuiMouseEvent,
|
|
15
|
+
type TuiMouseEventResult,
|
|
16
|
+
truncateToWidth,
|
|
17
|
+
} from "@earendil-works/pi-tui";
|
|
18
|
+
import { labeledRule } from "./labeled-rule.ts";
|
|
19
|
+
import type {
|
|
20
|
+
EntryHeading,
|
|
21
|
+
ModelIdentity,
|
|
22
|
+
TranscriptSource,
|
|
23
|
+
} from "./source.ts";
|
|
24
|
+
import { TranscriptContent } from "./transcript-content.ts";
|
|
25
|
+
|
|
26
|
+
const CHROME_LINES = 2;
|
|
27
|
+
export const VIEWPORT_HEIGHT_PCT = 70;
|
|
28
|
+
interface ScrollOptions {
|
|
29
|
+
follow?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface ReadingPosition {
|
|
32
|
+
offset: number;
|
|
33
|
+
follow: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface TranscriptPaneOptions {
|
|
36
|
+
tui: TUI;
|
|
37
|
+
theme: Theme;
|
|
38
|
+
keys: Pick<KeybindingsManager, "matches" | "getKeys">;
|
|
39
|
+
source: TranscriptSource;
|
|
40
|
+
heading: EntryHeading;
|
|
41
|
+
done: (result: undefined) => void;
|
|
42
|
+
cwd: string;
|
|
43
|
+
markdownTheme: MarkdownTheme;
|
|
44
|
+
position: ReadingPosition;
|
|
45
|
+
}
|
|
46
|
+
const formatModel = (model: ModelIdentity) => `${model.provider}/${model.id}`;
|
|
47
|
+
export class TranscriptPane implements Component {
|
|
48
|
+
readonly capturesViewportInput = true;
|
|
49
|
+
private readonly position: ReadingPosition;
|
|
50
|
+
private get scrollOffset() {
|
|
51
|
+
return this.position.offset;
|
|
52
|
+
}
|
|
53
|
+
private set scrollOffset(value: number) {
|
|
54
|
+
this.position.offset = value;
|
|
55
|
+
}
|
|
56
|
+
private get autoScroll() {
|
|
57
|
+
return this.position.follow;
|
|
58
|
+
}
|
|
59
|
+
private set autoScroll(value: boolean) {
|
|
60
|
+
this.position.follow = value;
|
|
61
|
+
}
|
|
62
|
+
private unsubscribe: (() => void) | undefined;
|
|
63
|
+
private closed = false;
|
|
64
|
+
|
|
65
|
+
private readonly tui: TUI;
|
|
66
|
+
private readonly theme: Theme;
|
|
67
|
+
private readonly keys: Pick<KeybindingsManager, "matches" | "getKeys">;
|
|
68
|
+
private readonly source: TranscriptSource;
|
|
69
|
+
private readonly heading: EntryHeading;
|
|
70
|
+
private readonly done: (result: undefined) => void;
|
|
71
|
+
private readonly content: TranscriptContent;
|
|
72
|
+
/** Width the host last rendered at; input must use the same layout. */
|
|
73
|
+
private renderedWidth: number | undefined;
|
|
74
|
+
|
|
75
|
+
constructor({
|
|
76
|
+
tui,
|
|
77
|
+
theme,
|
|
78
|
+
keys,
|
|
79
|
+
source,
|
|
80
|
+
heading,
|
|
81
|
+
done,
|
|
82
|
+
cwd,
|
|
83
|
+
markdownTheme,
|
|
84
|
+
position,
|
|
85
|
+
}: TranscriptPaneOptions) {
|
|
86
|
+
this.position = position;
|
|
87
|
+
this.tui = tui;
|
|
88
|
+
this.theme = theme;
|
|
89
|
+
this.keys = keys;
|
|
90
|
+
this.source = source;
|
|
91
|
+
this.heading = heading;
|
|
92
|
+
this.done = done;
|
|
93
|
+
this.content = new TranscriptContent({ tui, cwd, markdownTheme, source });
|
|
94
|
+
this.unsubscribe = source.subscribe(() => {
|
|
95
|
+
if (this.closed) return;
|
|
96
|
+
this.content.apply();
|
|
97
|
+
this.tui.requestRender();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
handleInput(data: string): void {
|
|
102
|
+
if (
|
|
103
|
+
matchesKey(data, "escape") ||
|
|
104
|
+
matchesKey(data, "q") ||
|
|
105
|
+
matchesKey(data, "ctrl+c")
|
|
106
|
+
) {
|
|
107
|
+
this.closed = true;
|
|
108
|
+
this.done(undefined);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const { viewportHeight } = this.scrollBounds(this.inputWidth());
|
|
113
|
+
|
|
114
|
+
if (matchesKey(data, "up") || matchesKey(data, "k")) {
|
|
115
|
+
this.scrollBy(-1);
|
|
116
|
+
} else if (matchesKey(data, "down") || matchesKey(data, "j")) {
|
|
117
|
+
this.scrollBy(1);
|
|
118
|
+
} else if (
|
|
119
|
+
this.keys.matches(data, "tui.altScreen.pageUp") ||
|
|
120
|
+
matchesKey(data, "shift+up")
|
|
121
|
+
) {
|
|
122
|
+
this.scrollBy(-viewportHeight, { follow: false });
|
|
123
|
+
} else if (
|
|
124
|
+
this.keys.matches(data, "tui.altScreen.pageDown") ||
|
|
125
|
+
matchesKey(data, "shift+down")
|
|
126
|
+
) {
|
|
127
|
+
this.scrollBy(viewportHeight);
|
|
128
|
+
} else if (
|
|
129
|
+
this.keys.matches(data, "tui.altScreen.top") ||
|
|
130
|
+
matchesKey(data, "home")
|
|
131
|
+
) {
|
|
132
|
+
this.scrollTo(0, { follow: false });
|
|
133
|
+
} else if (
|
|
134
|
+
this.keys.matches(data, "tui.altScreen.bottom") ||
|
|
135
|
+
matchesKey(data, "end")
|
|
136
|
+
) {
|
|
137
|
+
this.scrollTo(Number.POSITIVE_INFINITY);
|
|
138
|
+
} else if (this.keys.matches(data, "app.tools.expand")) {
|
|
139
|
+
this.content.toggleExpanded();
|
|
140
|
+
}
|
|
141
|
+
this.tui.requestRender();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** The wheel scrolls the transcript; every other mouse event is left to the host. */
|
|
145
|
+
handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined {
|
|
146
|
+
if (event.type !== "wheel") return undefined;
|
|
147
|
+
this.scrollBy(event.wheelDelta ?? 0);
|
|
148
|
+
this.tui.requestRender();
|
|
149
|
+
return { handled: true };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
render(width: number): string[] {
|
|
153
|
+
if (width < 6) return [];
|
|
154
|
+
const th = this.theme;
|
|
155
|
+
this.renderedWidth = width;
|
|
156
|
+
const lines: string[] = [];
|
|
157
|
+
|
|
158
|
+
// Rows span at most the width the host supplied: pi-tui rejects a wider one.
|
|
159
|
+
const fitLine = (content: string): string =>
|
|
160
|
+
truncateToWidth(content, width);
|
|
161
|
+
const { model, thinkingLevel } = this.source.sessionModel();
|
|
162
|
+
const paint = th.getThinkingBorderColor(thinkingLevel ?? "off");
|
|
163
|
+
|
|
164
|
+
lines.push(
|
|
165
|
+
labeledRule(width, paint, this.headerLabels(model, thinkingLevel)),
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const { totalLines, viewportHeight, maxScroll } = this.scrollBounds(width);
|
|
169
|
+
if (this.autoScroll) this.scrollOffset = maxScroll;
|
|
170
|
+
const visibleStart = Math.min(this.scrollOffset, maxScroll);
|
|
171
|
+
this.scrollOffset = visibleStart;
|
|
172
|
+
const visible = this.content.slice(width, visibleStart, viewportHeight);
|
|
173
|
+
for (let i = 0; i < viewportHeight; i++)
|
|
174
|
+
lines.push(fitLine(visible[i] ?? ""));
|
|
175
|
+
|
|
176
|
+
const scrollPct =
|
|
177
|
+
totalLines <= viewportHeight
|
|
178
|
+
? "100%"
|
|
179
|
+
: `${Math.round(((visibleStart + viewportHeight) / totalLines) * 100)}%`;
|
|
180
|
+
const position = th.fg(
|
|
181
|
+
"dim",
|
|
182
|
+
`${totalLines} lines · ${scrollPct} · ${this.autoScroll ? "following" : "paused"}`,
|
|
183
|
+
);
|
|
184
|
+
const hints = th.fg("dim", this.footerHint());
|
|
185
|
+
lines.push(labeledRule(width, paint, [position], [hints]));
|
|
186
|
+
|
|
187
|
+
return lines;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// fallow-ignore-next-line unused-class-member
|
|
191
|
+
invalidate(): void {
|
|
192
|
+
this.content.invalidate();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
dispose(): void {
|
|
196
|
+
this.closed = true;
|
|
197
|
+
if (this.unsubscribe) {
|
|
198
|
+
this.unsubscribe();
|
|
199
|
+
this.unsubscribe = undefined;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ---- Private ----
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The key hints the footer rule carries on its right, naming the keys the
|
|
207
|
+
* operator actually bound: the first key of each binding, and no segment
|
|
208
|
+
* for a pair left wholly unbound.
|
|
209
|
+
*/
|
|
210
|
+
private footerHint(): string {
|
|
211
|
+
const page = this.keyPair("tui.altScreen.pageUp", "tui.altScreen.pageDown");
|
|
212
|
+
const ends = this.keyPair("tui.altScreen.top", "tui.altScreen.bottom");
|
|
213
|
+
return ["↑↓ scroll", page, ends, "Esc list"]
|
|
214
|
+
.filter((segment) => segment !== "")
|
|
215
|
+
.join(" · ");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** `PageUp/PageDown` for a pair of bindings; the bound side alone when the other is unbound. */
|
|
219
|
+
private keyPair(first: Keybinding, second: Keybinding): string {
|
|
220
|
+
return [first, second]
|
|
221
|
+
.flatMap((keybinding) => this.keys.getKeys(keybinding).slice(0, 1))
|
|
222
|
+
.map(displayKey)
|
|
223
|
+
.join("/");
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Header labels, most to least informative: the rule drops the task first,
|
|
228
|
+
* then the model and thinking level, before it truncates the agent's name.
|
|
229
|
+
*/
|
|
230
|
+
private headerLabels(
|
|
231
|
+
model: ModelIdentity | undefined,
|
|
232
|
+
thinkingLevel: string | undefined,
|
|
233
|
+
): string[] {
|
|
234
|
+
const th = this.theme;
|
|
235
|
+
const { name, modeLabel, description } = this.heading;
|
|
236
|
+
const identity =
|
|
237
|
+
th.bold(name) + (modeLabel ? ` ${th.fg("muted", `(${modeLabel})`)}` : "");
|
|
238
|
+
const runtime = describeRuntime(model, thinkingLevel);
|
|
239
|
+
const runtimeTag = runtime ? th.fg("muted", ` · ${runtime}`) : "";
|
|
240
|
+
return [
|
|
241
|
+
`${identity} ${th.fg("muted", description)}${runtimeTag}`,
|
|
242
|
+
identity + runtimeTag,
|
|
243
|
+
identity,
|
|
244
|
+
];
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
private scrollBy(delta: number, options?: ScrollOptions): void {
|
|
248
|
+
this.scrollTo(this.scrollOffset + delta, options);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Move to `offset`, clamped to the transcript. The pane follows new output
|
|
253
|
+
* when it lands on the bottom, unless the move says otherwise: paging up or
|
|
254
|
+
* jumping to the top stops following even on a transcript that fits.
|
|
255
|
+
*/
|
|
256
|
+
private scrollTo(offset: number, { follow }: ScrollOptions = {}): void {
|
|
257
|
+
const { maxScroll } = this.scrollBounds(this.inputWidth());
|
|
258
|
+
this.scrollOffset = Math.min(maxScroll, Math.max(0, offset));
|
|
259
|
+
this.autoScroll = follow ?? this.scrollOffset >= maxScroll;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Scroll geometry at a given layout width.
|
|
264
|
+
*
|
|
265
|
+
* The single place a width becomes a viewport height, so `render` and
|
|
266
|
+
* `handleInput` cannot disagree about how far the transcript scrolls.
|
|
267
|
+
*/
|
|
268
|
+
private scrollBounds(width: number): {
|
|
269
|
+
totalLines: number;
|
|
270
|
+
viewportHeight: number;
|
|
271
|
+
maxScroll: number;
|
|
272
|
+
} {
|
|
273
|
+
const totalLines = this.content.lineCount(width);
|
|
274
|
+
const viewportHeight = this.viewportHeight(totalLines);
|
|
275
|
+
return {
|
|
276
|
+
totalLines,
|
|
277
|
+
viewportHeight,
|
|
278
|
+
maxScroll: Math.max(0, totalLines - viewportHeight),
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* The width `handleInput` must lay out at: the one the host actually supplied,
|
|
284
|
+
* so scroll bounds match the layout on screen. Before the first paint there is
|
|
285
|
+
* none, so fall back to the full terminal width.
|
|
286
|
+
*/
|
|
287
|
+
private inputWidth(): number {
|
|
288
|
+
return this.renderedWidth ?? this.tui.terminal.columns;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Rows the transcript gets: what it needs, capped at the pane's share of the
|
|
293
|
+
* terminal so a long or live transcript cannot crowd out the conversation, and
|
|
294
|
+
* floored so a short one still reads as a pane.
|
|
295
|
+
*/
|
|
296
|
+
private viewportHeight(totalLines: number): number {
|
|
297
|
+
const cap =
|
|
298
|
+
Math.floor((this.tui.terminal.rows * VIEWPORT_HEIGHT_PCT) / 100) -
|
|
299
|
+
CHROME_LINES;
|
|
300
|
+
return Math.max(0, Math.min(Math.max(1, totalLines), cap));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** A key id in Pi's display style: `ctrl+b` → `Ctrl+B`, `pageUp` → `PageUp`. */
|
|
305
|
+
function displayKey(key: KeyId): string {
|
|
306
|
+
return key
|
|
307
|
+
.split("+")
|
|
308
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
309
|
+
.join("+");
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* `anthropic/claude-sonnet-5 • high`, in Pi's footer wording: `thinking off` rather
|
|
314
|
+
* than a bare `off`, and `thinking <level>` when no model is named to attach it to.
|
|
315
|
+
*/
|
|
316
|
+
function describeRuntime(
|
|
317
|
+
model: ModelIdentity | undefined,
|
|
318
|
+
thinkingLevel: string | undefined,
|
|
319
|
+
): string {
|
|
320
|
+
if (!model) return thinkingLevel ? `thinking ${thinkingLevel}` : "";
|
|
321
|
+
if (!thinkingLevel) return formatModel(model);
|
|
322
|
+
const level = thinkingLevel === "off" ? "thinking off" : thinkingLevel;
|
|
323
|
+
return `${formatModel(model)} • ${level}`;
|
|
324
|
+
}
|