@aui.io/apollo 0.1.7 → 0.1.10
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/node_modules/@aui.io/apollo-cli/bin/apollo.js +8 -5
- package/node_modules/@aui.io/apollo-cli/dist/src/commands/operate.js +3 -10
- package/node_modules/@aui.io/apollo-cli/dist/src/commands/operate.js.map +1 -1
- package/node_modules/@aui.io/apollo-cli/package.json +3 -3
- package/node_modules/@aui.io/apollo-core/dist/src/api/runtime-api.d.ts +13 -0
- package/node_modules/@aui.io/apollo-core/dist/src/api/runtime-api.js +17 -0
- package/node_modules/@aui.io/apollo-core/dist/src/api/runtime-api.js.map +1 -1
- package/node_modules/@aui.io/apollo-core/dist/src/services/hierarchy.js +7 -1
- package/node_modules/@aui.io/apollo-core/dist/src/services/hierarchy.js.map +1 -1
- package/node_modules/@aui.io/apollo-core/dist/src/services/messaging.d.ts +17 -0
- package/node_modules/@aui.io/apollo-core/dist/src/services/messaging.js +27 -0
- package/node_modules/@aui.io/apollo-core/dist/src/services/messaging.js.map +1 -1
- package/node_modules/@aui.io/apollo-core/package.json +1 -1
- package/node_modules/@aui.io/apollo-tui/dist/src/actions/ActionPalette.d.ts +13 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/actions/ActionPalette.js +47 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/actions/ActionPalette.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/actions/registry.d.ts +28 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/actions/registry.js +219 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/actions/registry.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/activity/ActivityDrawer.d.ts +8 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/activity/ActivityDrawer.js +43 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/activity/ActivityDrawer.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/activity/ActivitySummary.d.ts +5 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/activity/ActivitySummary.js +26 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/activity/ActivitySummary.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/activity/operationStore.d.ts +67 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/activity/operationStore.js +138 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/activity/operationStore.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/AuthorHome.d.ts +27 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/AuthorHome.js +92 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/AuthorHome.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/DiffView.d.ts +46 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/DiffView.js +87 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/DiffView.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/SessionPane.d.ts +15 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/SessionPane.js +38 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/SessionPane.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/ValidationView.d.ts +11 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/ValidationView.js +34 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/ValidationView.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/VersionsView.d.ts +9 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/VersionsView.js +31 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/VersionsView.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/backend/claudeCode.d.ts +23 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/backend/claudeCode.js +293 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/backend/claudeCode.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/backend/index.d.ts +4 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/backend/index.js +13 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/backend/index.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/backend/sessions.d.ts +3 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/backend/sessions.js +36 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/backend/sessions.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/backend/types.d.ts +85 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/backend/types.js +11 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/backend/types.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/data.d.ts +78 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/data.js +279 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/data.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/session.d.ts +64 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/session.js +319 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/session.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/tree.d.ts +25 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/tree.js +69 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/author/tree.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/context/ContextSwitcher.d.ts +23 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/context/ContextSwitcher.js +60 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/context/ContextSwitcher.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/index.d.ts +19 -2
- package/node_modules/@aui.io/apollo-tui/dist/src/index.js +24 -2
- package/node_modules/@aui.io/apollo-tui/dist/src/index.js.map +1 -1
- package/node_modules/@aui.io/apollo-tui/dist/src/keyprobe.d.ts +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/keyprobe.js +51 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/keyprobe.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/actions.d.ts +56 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/actions.js +1019 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/actions.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/clipboard.d.ts +7 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/clipboard.js +33 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/clipboard.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/commands.d.ts +10 -4
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/commands.js +444 -23
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/commands.js.map +1 -1
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/confirm.d.ts +10 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/confirm.js +12 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/confirm.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/ide.d.ts +16 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/ide.js +39 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/ide.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/keydiag.d.ts +17 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/keydiag.js +76 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/keydiag.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/keys.d.ts +64 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/keys.js +105 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/keys.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/modes.d.ts +18 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/modes.js +24 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/modes.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/picker.d.ts +28 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/picker.js +72 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/picker.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/place.d.ts +26 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/place.js +32 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/place.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/scope.d.ts +29 -6
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/scope.js +112 -13
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/scope.js.map +1 -1
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/sheet.d.ts +5 -10
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/sheet.js +2 -1
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/sheet.js.map +1 -1
- package/node_modules/@aui.io/apollo-tui/dist/src/opentui-app.js +2106 -273
- package/node_modules/@aui.io/apollo-tui/dist/src/opentui-app.js.map +1 -1
- package/node_modules/@aui.io/apollo-tui/dist/src/shell/Breadcrumb.d.ts +15 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/shell/Breadcrumb.js +22 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/shell/Breadcrumb.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/shell/FooterHints.d.ts +8 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/shell/FooterHints.js +23 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/shell/FooterHints.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/shell/ModeNav.d.ts +4 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/shell/ModeNav.js +7 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/shell/ModeNav.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/Composer.d.ts +20 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/Composer.js +29 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/Composer.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/InspectorPane.d.ts +15 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/InspectorPane.js +27 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/InspectorPane.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/TalkView.d.ts +30 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/TalkView.js +60 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/TalkView.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/ThreadsPane.d.ts +17 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/ThreadsPane.js +61 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/ThreadsPane.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/data.d.ts +107 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/data.js +235 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/talk/data.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/theme/tokens.d.ts +8 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/theme/tokens.js +9 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/theme/tokens.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/ui/ConfirmPane.d.ts +4 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/ui/ConfirmPane.js +15 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/ui/ConfirmPane.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/ui/OutputPane.d.ts +5 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/ui/OutputPane.js +16 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/ui/OutputPane.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/ui/PickerPane.d.ts +10 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/ui/PickerPane.js +29 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/ui/PickerPane.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/ui/SheetPane.d.ts +4 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/ui/SheetPane.js +22 -0
- package/node_modules/@aui.io/apollo-tui/dist/src/ui/SheetPane.js.map +1 -0
- package/node_modules/@aui.io/apollo-tui/package.json +2 -2
- package/package.json +4 -4
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/tabs.d.ts +0 -10
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/tabs.js +0 -19
- package/node_modules/@aui.io/apollo-tui/dist/src/lib/tabs.js.map +0 -1
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code adapter, Level 1 (TODO Phase 5) — headless CLI integration:
|
|
3
|
+
* `claude -p --output-format stream-json`, cwd pinned to the checkout,
|
|
4
|
+
* `--resume <id>` for per-checkout session continuity. Permission policy:
|
|
5
|
+
* `acceptEdits` + an explicit tool allowlist scoped to file work inside the
|
|
6
|
+
* checkout — no Bash, no network tools; in headless mode disallowed tools
|
|
7
|
+
* are simply unavailable to the agent (nothing can prompt).
|
|
8
|
+
*
|
|
9
|
+
* Everything the UI learns about file changes still comes from Apollo's own
|
|
10
|
+
* watcher/diff — backend-reported edits are rendered as activity, not truth.
|
|
11
|
+
*/
|
|
12
|
+
import { spawn } from "node:child_process";
|
|
13
|
+
import { createInterface } from "node:readline";
|
|
14
|
+
/** File-work tools only — documented policy, revisit with Level 2 prompts. */
|
|
15
|
+
export const CLAUDE_ALLOWED_TOOLS = [
|
|
16
|
+
"Read",
|
|
17
|
+
"Glob",
|
|
18
|
+
"Grep",
|
|
19
|
+
"LS",
|
|
20
|
+
"Edit",
|
|
21
|
+
"Write",
|
|
22
|
+
"MultiEdit",
|
|
23
|
+
"TodoWrite",
|
|
24
|
+
];
|
|
25
|
+
export function claudeArgs(text, sessionId) {
|
|
26
|
+
return [
|
|
27
|
+
"-p",
|
|
28
|
+
text,
|
|
29
|
+
"--output-format",
|
|
30
|
+
"stream-json",
|
|
31
|
+
"--verbose", // the CLI requires it for stream-json with -p
|
|
32
|
+
"--include-partial-messages", // token-level streaming (stream_event lines)
|
|
33
|
+
"--permission-mode",
|
|
34
|
+
"acceptEdits",
|
|
35
|
+
"--allowedTools",
|
|
36
|
+
CLAUDE_ALLOWED_TOOLS.join(","),
|
|
37
|
+
...(sessionId ? ["--resume", sessionId] : []),
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
const INPUT_BODY_CAP = 30;
|
|
41
|
+
const RESULT_BODY_CAP = 60;
|
|
42
|
+
function capLines(lines, cap) {
|
|
43
|
+
if (lines.length <= cap)
|
|
44
|
+
return lines;
|
|
45
|
+
return [...lines.slice(0, cap), `… (${lines.length - cap} more lines)`];
|
|
46
|
+
}
|
|
47
|
+
/** Pretty tool input for the expandable unit body. */
|
|
48
|
+
function inputBody(input) {
|
|
49
|
+
if (!input || Object.keys(input).length === 0)
|
|
50
|
+
return [];
|
|
51
|
+
return capLines(JSON.stringify(input, null, 2).split("\n"), INPUT_BODY_CAP);
|
|
52
|
+
}
|
|
53
|
+
/** tool_result content arrives as a string or a list of text blocks. */
|
|
54
|
+
function resultBody(content) {
|
|
55
|
+
if (typeof content === "string") {
|
|
56
|
+
return capLines(content.split("\n"), RESULT_BODY_CAP);
|
|
57
|
+
}
|
|
58
|
+
if (Array.isArray(content)) {
|
|
59
|
+
const lines = [];
|
|
60
|
+
for (const block of content) {
|
|
61
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
62
|
+
lines.push(...block.text.split("\n"));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return capLines(lines, RESULT_BODY_CAP);
|
|
66
|
+
}
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
/** Short human label for a tool call: "Edit — bundle/src/program.yaml". */
|
|
70
|
+
export function summarizeToolUse(name, input) {
|
|
71
|
+
const pick = (key) => {
|
|
72
|
+
const value = input?.[key];
|
|
73
|
+
return typeof value === "string" ? value : undefined;
|
|
74
|
+
};
|
|
75
|
+
const detail = pick("file_path") ??
|
|
76
|
+
pick("command") ??
|
|
77
|
+
pick("pattern") ??
|
|
78
|
+
pick("path") ??
|
|
79
|
+
pick("skill");
|
|
80
|
+
const short = detail && detail.length > 80 ? `${detail.slice(0, 77)}…` : detail;
|
|
81
|
+
return { label: name, ...(short ? { detail: short } : {}) };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Map one stream-json line to normalized events. Tolerant: unknown or
|
|
85
|
+
* malformed lines yield nothing (vendor formats evolve).
|
|
86
|
+
*/
|
|
87
|
+
export function parseClaudeLine(line, state) {
|
|
88
|
+
const trimmed = line.trim();
|
|
89
|
+
if (!trimmed.startsWith("{"))
|
|
90
|
+
return [];
|
|
91
|
+
let data;
|
|
92
|
+
try {
|
|
93
|
+
data = JSON.parse(trimmed);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
if (typeof data.session_id === "string")
|
|
99
|
+
state.sessionId = data.session_id;
|
|
100
|
+
// Partial-message stream (--include-partial-messages): Anthropic streaming
|
|
101
|
+
// events wrapped in stream_event lines. Deltas render live; the complete
|
|
102
|
+
// assistant message that follows is authoritative and replaces them.
|
|
103
|
+
if (data.type === "stream_event") {
|
|
104
|
+
const event = data.event;
|
|
105
|
+
if (event?.type === "content_block_start") {
|
|
106
|
+
const block = event.content_block;
|
|
107
|
+
if (block?.type === "tool_use" && block.name && block.id) {
|
|
108
|
+
return [{ type: "action-start", id: block.id, label: block.name }];
|
|
109
|
+
}
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
if (event?.type === "content_block_delta") {
|
|
113
|
+
const delta = event.delta;
|
|
114
|
+
if (delta?.type === "text_delta" && typeof delta.text === "string") {
|
|
115
|
+
return [{ type: "text-delta", text: delta.text }];
|
|
116
|
+
}
|
|
117
|
+
if (delta?.type === "thinking_delta" &&
|
|
118
|
+
typeof delta.thinking === "string") {
|
|
119
|
+
return [{ type: "thinking-delta", text: delta.thinking }];
|
|
120
|
+
}
|
|
121
|
+
return []; // input_json_delta etc. — the complete action carries the input
|
|
122
|
+
}
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
if (data.type === "assistant") {
|
|
126
|
+
const message = data.message;
|
|
127
|
+
const events = [];
|
|
128
|
+
for (const block of message?.content ?? []) {
|
|
129
|
+
if (block.type === "text" && block.text?.trim()) {
|
|
130
|
+
events.push({ type: "text", text: block.text });
|
|
131
|
+
}
|
|
132
|
+
else if (block.type === "tool_use" && block.name) {
|
|
133
|
+
const { label, detail } = summarizeToolUse(block.name, block.input);
|
|
134
|
+
const body = inputBody(block.input);
|
|
135
|
+
events.push({
|
|
136
|
+
type: "action",
|
|
137
|
+
label,
|
|
138
|
+
...(block.id ? { id: block.id } : {}),
|
|
139
|
+
...(detail ? { detail } : {}),
|
|
140
|
+
...(body.length > 0 ? { body } : {}),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return events;
|
|
145
|
+
}
|
|
146
|
+
// Tool results ride on user messages; they complete the matching action.
|
|
147
|
+
if (data.type === "user") {
|
|
148
|
+
const message = data.message;
|
|
149
|
+
const events = [];
|
|
150
|
+
for (const block of message?.content ?? []) {
|
|
151
|
+
if (block.type === "tool_result" && typeof block.tool_use_id === "string") {
|
|
152
|
+
events.push({
|
|
153
|
+
type: "action-result",
|
|
154
|
+
id: block.tool_use_id,
|
|
155
|
+
body: resultBody(block.content),
|
|
156
|
+
ok: block.is_error !== true,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return events;
|
|
161
|
+
}
|
|
162
|
+
if (data.type === "result") {
|
|
163
|
+
const isError = data.is_error === true ||
|
|
164
|
+
(typeof data.subtype === "string" && data.subtype !== "success");
|
|
165
|
+
if (isError) {
|
|
166
|
+
const message = (typeof data.result === "string" && data.result) ||
|
|
167
|
+
(typeof data.error === "string" && data.error) ||
|
|
168
|
+
`claude result: ${typeof data.subtype === "string" ? data.subtype : "error"}`;
|
|
169
|
+
return [{ type: "error", message }];
|
|
170
|
+
}
|
|
171
|
+
const parts = [];
|
|
172
|
+
if (typeof data.num_turns === "number")
|
|
173
|
+
parts.push(`${data.num_turns} turns`);
|
|
174
|
+
if (typeof data.duration_ms === "number") {
|
|
175
|
+
parts.push(`${Math.round(data.duration_ms / 1000)}s`);
|
|
176
|
+
}
|
|
177
|
+
if (typeof data.total_cost_usd === "number") {
|
|
178
|
+
parts.push(`$${data.total_cost_usd.toFixed(2)}`);
|
|
179
|
+
}
|
|
180
|
+
return [
|
|
181
|
+
{
|
|
182
|
+
type: "done",
|
|
183
|
+
...(state.sessionId ? { sessionId: state.sessionId } : {}),
|
|
184
|
+
...(parts.length > 0 ? { summary: parts.join(" · ") } : {}),
|
|
185
|
+
},
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
// system/init (session capture above), user/tool_result — no UI event.
|
|
189
|
+
return [];
|
|
190
|
+
}
|
|
191
|
+
const DETECT_TIMEOUT_MS = 4000;
|
|
192
|
+
/**
|
|
193
|
+
* `claude --version` prints "2.1.220 (Claude Code)" — the UI already labels
|
|
194
|
+
* the backend, so the parenthetical would just repeat it.
|
|
195
|
+
*/
|
|
196
|
+
export function cleanVersionOutput(out) {
|
|
197
|
+
const version = out.trim().replace(/\s*\(claude code\)\s*$/i, "");
|
|
198
|
+
return version || undefined;
|
|
199
|
+
}
|
|
200
|
+
export const claudeCodeBackend = {
|
|
201
|
+
id: "claude-code",
|
|
202
|
+
label: "Claude Code",
|
|
203
|
+
capabilities: {
|
|
204
|
+
streaming: true, // coarse (per message/tool event) but real
|
|
205
|
+
cancel: true, // SIGTERM the headless process
|
|
206
|
+
permissionPrompts: false, // Level 2 (agent SDK canUseTool)
|
|
207
|
+
sessionResume: true,
|
|
208
|
+
},
|
|
209
|
+
detect() {
|
|
210
|
+
return new Promise((resolve) => {
|
|
211
|
+
const child = spawn("claude", ["--version"], {
|
|
212
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
213
|
+
});
|
|
214
|
+
let out = "";
|
|
215
|
+
const timer = setTimeout(() => {
|
|
216
|
+
child.kill("SIGKILL");
|
|
217
|
+
resolve({ available: false, reason: "claude --version timed out" });
|
|
218
|
+
}, DETECT_TIMEOUT_MS);
|
|
219
|
+
child.stdout.on("data", (chunk) => (out += chunk.toString()));
|
|
220
|
+
child.on("error", (error) => {
|
|
221
|
+
clearTimeout(timer);
|
|
222
|
+
resolve({
|
|
223
|
+
available: false,
|
|
224
|
+
reason: error.code === "ENOENT"
|
|
225
|
+
? "claude CLI not found on PATH — install Claude Code (https://claude.com/claude-code)"
|
|
226
|
+
: error.message,
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
child.on("close", (code) => {
|
|
230
|
+
clearTimeout(timer);
|
|
231
|
+
if (code === 0) {
|
|
232
|
+
resolve({ available: true, version: cleanVersionOutput(out) });
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
resolve({ available: false, reason: `claude --version exited ${code ?? "?"}` });
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
},
|
|
240
|
+
startTurn({ checkoutDir, text, sessionId, onEvent }) {
|
|
241
|
+
const child = spawn("claude", claudeArgs(text, sessionId), {
|
|
242
|
+
cwd: checkoutDir,
|
|
243
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
244
|
+
});
|
|
245
|
+
const state = {};
|
|
246
|
+
let terminal = false;
|
|
247
|
+
let stderrTail = "";
|
|
248
|
+
const emit = (event) => {
|
|
249
|
+
if (terminal)
|
|
250
|
+
return;
|
|
251
|
+
if (event.type === "done" || event.type === "error")
|
|
252
|
+
terminal = true;
|
|
253
|
+
onEvent(event);
|
|
254
|
+
};
|
|
255
|
+
const lines = createInterface({ input: child.stdout });
|
|
256
|
+
lines.on("line", (line) => {
|
|
257
|
+
for (const event of parseClaudeLine(line, state))
|
|
258
|
+
emit(event);
|
|
259
|
+
});
|
|
260
|
+
child.stderr.on("data", (chunk) => {
|
|
261
|
+
stderrTail = (stderrTail + chunk.toString()).slice(-500);
|
|
262
|
+
});
|
|
263
|
+
child.on("error", (error) => {
|
|
264
|
+
emit({
|
|
265
|
+
type: "error",
|
|
266
|
+
message: error.code === "ENOENT"
|
|
267
|
+
? "claude CLI not found on PATH — install Claude Code (https://claude.com/claude-code)"
|
|
268
|
+
: error.message,
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
child.on("close", (code) => {
|
|
272
|
+
// If stream-json already delivered the terminal event this is a no-op.
|
|
273
|
+
if (code === 0) {
|
|
274
|
+
emit({
|
|
275
|
+
type: "done",
|
|
276
|
+
...(state.sessionId ? { sessionId: state.sessionId } : {}),
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
emit({
|
|
281
|
+
type: "error",
|
|
282
|
+
message: `claude exited ${code ?? "by signal"}${stderrTail.trim() ? ` — ${stderrTail.trim()}` : ""}`,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
return {
|
|
287
|
+
cancel: () => {
|
|
288
|
+
child.kill("SIGTERM");
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
//# sourceMappingURL=claudeCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claudeCode.js","sourceRoot":"","sources":["../../../../src/author/backend/claudeCode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAShD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,oB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AC,EAAE,CAAC;iBAC3D,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC;oBACH,IAAI,EAAE,OAAO;oBACb,OAAO,EAAE,iBAAiB,IAAI,IAAI,WAAW,GAC3C,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAClD,EAAE;iBACH,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,MAAM,EAAE,GAAG,EAAE;gBACX,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACxB,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AuthorBackend } from "./types.js";
|
|
2
|
+
export declare const AUTHOR_BACKENDS: AuthorBackend[];
|
|
3
|
+
export declare function resolveAuthorBackend(id?: string | undefined): AuthorBackend;
|
|
4
|
+
export type { AuthorBackend, BackendCapabilities, BackendDetection, BackendEvent, TurnHandle, TurnOptions, } from "./types.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Author backend registry. One entry today (Claude Code); the seam and the
|
|
3
|
+
* env override exist so adding Codex / Apollo Author API is additive.
|
|
4
|
+
* Config-file selection (`author.backend`) + a palette switch action are
|
|
5
|
+
* deferred until a second backend exists — a switcher over one option is
|
|
6
|
+
* noise.
|
|
7
|
+
*/
|
|
8
|
+
import { claudeCodeBackend } from "./claudeCode.js";
|
|
9
|
+
export const AUTHOR_BACKENDS = [claudeCodeBackend];
|
|
10
|
+
export function resolveAuthorBackend(id = process.env.APOLLO_AUTHOR_BACKEND) {
|
|
11
|
+
return AUTHOR_BACKENDS.find((b) => b.id === id) ?? claudeCodeBackend;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/author/backend/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGpD,MAAM,CAAC,MAAM,eAAe,GAAoB,CAAC,iBAAiB,CAAC,CAAC;AAEpE,MAAM,UAAU,oBAAoB,CAClC,KAAyB,OAAO,CAAC,GAAG,CAAC,qBAAqB;IAE1D,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,iBAAiB,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-checkout author session identity (TODO Phase 5): checkout dir →
|
|
3
|
+
* backend session id, persisted under ~/.apollo so a TUI restart resumes
|
|
4
|
+
* the same conversation for the same checkout.
|
|
5
|
+
*/
|
|
6
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
export function defaultSessionsFile() {
|
|
10
|
+
return path.join(homedir(), ".apollo", "author-sessions.json");
|
|
11
|
+
}
|
|
12
|
+
export async function loadSessions(file = defaultSessionsFile()) {
|
|
13
|
+
try {
|
|
14
|
+
const raw = await readFile(file, "utf8");
|
|
15
|
+
const data = JSON.parse(raw);
|
|
16
|
+
if (data && typeof data === "object" && !Array.isArray(data)) {
|
|
17
|
+
const out = {};
|
|
18
|
+
for (const [key, value] of Object.entries(data)) {
|
|
19
|
+
if (typeof value === "string")
|
|
20
|
+
out[key] = value;
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// Missing or corrupt file — start clean.
|
|
27
|
+
}
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
export async function saveSession(checkoutDir, sessionId, file = defaultSessionsFile()) {
|
|
31
|
+
const sessions = await loadSessions(file);
|
|
32
|
+
sessions[checkoutDir] = sessionId;
|
|
33
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
34
|
+
await writeFile(file, `${JSON.stringify(sessions, null, 2)}\n`, "utf8");
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=sessions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessions.js","sourceRoot":"","sources":["../../../../src/author/backend/sessions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,UAAU,mBAAmB;IACjC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,sBAAsB,CAAC,CAAC;AACjE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAI,GAAG,mBAAmB,EAAE;IAE5B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACzC,MAAM,IAAI,GAAY,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACtC,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7D,MAAM,GAAG,GAA2B,EAAE,CAAC;YACvC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBAChD,IAAI,OAAO,KAAK,KAAK,QAAQ;oBAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YAClD,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,yCAAyC;IAC3C,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,WAAmB,EACnB,SAAiB,EACjB,IAAI,GAAG,mBAAmB,EAAE;IAE5B,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;IAC1C,QAAQ,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC;IAClC,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACrD,MAAM,SAAS,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The AuthorBackend seam (TUI_DESIGN §9, TODO Phase 5).
|
|
3
|
+
*
|
|
4
|
+
* The TUI talks only to this interface — never to a vendor CLI/SDK
|
|
5
|
+
* directly. Backends are replaceable by design (Claude Code today; Codex,
|
|
6
|
+
* Apollo Author API later): the UI renders only the normalized event
|
|
7
|
+
* vocabulary below, and capability gaps degrade honestly — a backend
|
|
8
|
+
* without streaming shows a pending state, never fake streaming.
|
|
9
|
+
*/
|
|
10
|
+
export interface BackendDetection {
|
|
11
|
+
available: boolean;
|
|
12
|
+
version?: string;
|
|
13
|
+
/** When unavailable: why, plus an install hint. */
|
|
14
|
+
reason?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface BackendCapabilities {
|
|
17
|
+
/** Emits incremental events during a turn (may be coarse-grained). */
|
|
18
|
+
streaming: boolean;
|
|
19
|
+
cancel: boolean;
|
|
20
|
+
/** Can surface interactive permission prompts (Level 2). */
|
|
21
|
+
permissionPrompts: boolean;
|
|
22
|
+
sessionResume: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Normalized event vocabulary — everything the UI knows how to render.
|
|
26
|
+
* Adapters guarantee exactly one terminal event (`done` or `error`).
|
|
27
|
+
*
|
|
28
|
+
* `action` is one unit of backend work (a tool call: Bash, Edit, Skill, …);
|
|
29
|
+
* `id` correlates `action-start`/`action-result` to it, and `body` carries
|
|
30
|
+
* the expandable payload (tool input). Streaming backends additionally emit
|
|
31
|
+
* `text-delta`/`thinking-delta` fragments and `action-start` notices; the
|
|
32
|
+
* later complete `text`/`action` events are authoritative and replace the
|
|
33
|
+
* accumulated fragments (no duplicates). Backends without streaming or
|
|
34
|
+
* correlation ids degrade to complete-block, non-expandable units.
|
|
35
|
+
*/
|
|
36
|
+
export type BackendEvent = {
|
|
37
|
+
type: "text";
|
|
38
|
+
text: string;
|
|
39
|
+
} | {
|
|
40
|
+
type: "text-delta";
|
|
41
|
+
text: string;
|
|
42
|
+
} | {
|
|
43
|
+
type: "thinking-delta";
|
|
44
|
+
text: string;
|
|
45
|
+
} | {
|
|
46
|
+
type: "action-start";
|
|
47
|
+
id: string;
|
|
48
|
+
label: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: "action";
|
|
51
|
+
id?: string;
|
|
52
|
+
label: string;
|
|
53
|
+
detail?: string;
|
|
54
|
+
body?: string[];
|
|
55
|
+
} | {
|
|
56
|
+
type: "action-result";
|
|
57
|
+
id: string;
|
|
58
|
+
body: string[];
|
|
59
|
+
ok: boolean;
|
|
60
|
+
} | {
|
|
61
|
+
type: "error";
|
|
62
|
+
message: string;
|
|
63
|
+
} | {
|
|
64
|
+
type: "done";
|
|
65
|
+
sessionId?: string;
|
|
66
|
+
summary?: string;
|
|
67
|
+
};
|
|
68
|
+
export interface TurnOptions {
|
|
69
|
+
/** Agent checkout the backend may read and edit (its cwd). */
|
|
70
|
+
checkoutDir: string;
|
|
71
|
+
text: string;
|
|
72
|
+
/** Resume a previous per-checkout conversation when supported. */
|
|
73
|
+
sessionId?: string;
|
|
74
|
+
onEvent: (event: BackendEvent) => void;
|
|
75
|
+
}
|
|
76
|
+
export interface TurnHandle {
|
|
77
|
+
cancel(): void;
|
|
78
|
+
}
|
|
79
|
+
export interface AuthorBackend {
|
|
80
|
+
id: string;
|
|
81
|
+
label: string;
|
|
82
|
+
capabilities: BackendCapabilities;
|
|
83
|
+
detect(): Promise<BackendDetection>;
|
|
84
|
+
startTurn(options: TurnOptions): TurnHandle;
|
|
85
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The AuthorBackend seam (TUI_DESIGN §9, TODO Phase 5).
|
|
3
|
+
*
|
|
4
|
+
* The TUI talks only to this interface — never to a vendor CLI/SDK
|
|
5
|
+
* directly. Backends are replaceable by design (Claude Code today; Codex,
|
|
6
|
+
* Apollo Author API later): the UI renders only the normalized event
|
|
7
|
+
* vocabulary below, and capability gaps degrade honestly — a backend
|
|
8
|
+
* without streaming shows a pending state, never fake streaming.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/author/backend/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type FileDiff } from "@aui.io/apollo-core/bundle/baseline.js";
|
|
2
|
+
import type { Context } from "@aui.io/apollo-core/config/types.js";
|
|
3
|
+
import type { AgentVersion, ManagementClient } from "@aui.io/apollo-core/api/management.js";
|
|
4
|
+
import type { RuntimeApiClient } from "@aui.io/apollo-core/api/runtime-api.js";
|
|
5
|
+
import type { ValidationResult } from "@aui.io/apollo-core/bundle/validate.js";
|
|
6
|
+
export interface AuthorSnapshot {
|
|
7
|
+
diff?: FileDiff;
|
|
8
|
+
baselineTag?: string;
|
|
9
|
+
baselineAt?: string;
|
|
10
|
+
/** Why the snapshot is unavailable (no agent, no baseline, read error). */
|
|
11
|
+
unavailable?: string;
|
|
12
|
+
loadedAt: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ValidationRecord {
|
|
15
|
+
result: ValidationResult;
|
|
16
|
+
at: number;
|
|
17
|
+
/** Files changed since this run — results may no longer hold. */
|
|
18
|
+
stale: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface ChangeEntry {
|
|
21
|
+
status: "A" | "M" | "D";
|
|
22
|
+
path: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function agentRootOf(context: Context): string | undefined;
|
|
25
|
+
export declare function bundleSrcRoot(context: Context): string | undefined;
|
|
26
|
+
export declare function loadAuthorSnapshot(context: Context): Promise<AuthorSnapshot>;
|
|
27
|
+
export declare function runValidationRecord(context: Context, runtime: RuntimeApiClient): Promise<ValidationRecord>;
|
|
28
|
+
export declare function changeEntries(diff: FileDiff | undefined): ChangeEntry[];
|
|
29
|
+
export declare function changesSummary(diff: FileDiff | undefined): string;
|
|
30
|
+
export declare function relativeTime(atMs: number, nowMs?: number): string;
|
|
31
|
+
export declare function validationSummary(record: ValidationRecord | undefined): string;
|
|
32
|
+
/** Local program files (path → content) for content diffs. */
|
|
33
|
+
export declare function readLocalFiles(context: Context): Promise<Record<string, string>>;
|
|
34
|
+
/** Remote files at the bound tag (path → content). One fetch, caller caches. */
|
|
35
|
+
export declare function fetchRemoteFiles(context: Context, management: ManagementClient): Promise<Record<string, string>>;
|
|
36
|
+
export interface DiffLine {
|
|
37
|
+
tag: " " | "+" | "-";
|
|
38
|
+
text: string;
|
|
39
|
+
}
|
|
40
|
+
/** Content-diff rendering style, like GitHub/Bitbucket's view options. */
|
|
41
|
+
export type DiffStyle = "split" | "unified";
|
|
42
|
+
export declare function defaultDiffStyle(width: number): DiffStyle;
|
|
43
|
+
/** Local + remote file contents backing the diff subview's content panes. */
|
|
44
|
+
export type DiffFilesState = {
|
|
45
|
+
status: "loading";
|
|
46
|
+
} | {
|
|
47
|
+
status: "ready";
|
|
48
|
+
local: Record<string, string>;
|
|
49
|
+
remote: Record<string, string>;
|
|
50
|
+
tag: string;
|
|
51
|
+
/** Remote fetch failed; tree + plain previews still work locally. */
|
|
52
|
+
remoteError?: string;
|
|
53
|
+
} | {
|
|
54
|
+
status: "error";
|
|
55
|
+
message: string;
|
|
56
|
+
};
|
|
57
|
+
/** One side-by-side row: removal on the left, addition on the right. */
|
|
58
|
+
export interface SplitRow {
|
|
59
|
+
left?: DiffLine | undefined;
|
|
60
|
+
right?: DiffLine | undefined;
|
|
61
|
+
}
|
|
62
|
+
/** Pair unified diff lines into aligned split rows (Git style). */
|
|
63
|
+
export declare function splitRows(lines: DiffLine[]): SplitRow[];
|
|
64
|
+
/**
|
|
65
|
+
* Line diff (common prefix/suffix trim + LCS middle). Good enough for program
|
|
66
|
+
* files; oversized inputs degrade to a truncation notice.
|
|
67
|
+
*/
|
|
68
|
+
export declare function diffLines(before: string, after: string): DiffLine[];
|
|
69
|
+
/** Content diff for one changed file: remote (bound tag) → local. */
|
|
70
|
+
export declare function fileContentDiff(filePath: string, localFiles: Record<string, string>, remoteFiles: Record<string, string>): DiffLine[];
|
|
71
|
+
export declare function formatVersionRow(version: AgentVersion): string;
|
|
72
|
+
/**
|
|
73
|
+
* Relative file paths under `root` for the browse tree (workspace level or
|
|
74
|
+
* clean checkouts). Skips vendored/system dirs; capped for sanity.
|
|
75
|
+
*/
|
|
76
|
+
export declare function listPlaceFiles(root: string, cap?: number): Promise<string[]>;
|
|
77
|
+
/** Read one file for the browse preview (size-capped, line-capped). */
|
|
78
|
+
export declare function readPlaceFile(root: string, rel: string): Promise<string[]>;
|