@kabmo-labs/kabmo 0.10.1 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +391 -391
- package/dist/client/static/js/{index-135sdc46.js → index-amss8pge.js} +660 -659
- package/dist/client/static/js/index-bq6qeayr.css +1 -0
- package/package.json +1 -1
- package/src/client/components/common/code-surface/theme.ts +11 -5
- package/src/client/components/workspace/chat-timeline/chat-input/access-levels.ts +11 -2
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/ApprovalBody.tsx +65 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/Header.tsx +21 -2
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/SelectBody.tsx +35 -19
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/approval-gate.test.tsx +145 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +32 -104
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/shortcuts.tsx +166 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +30 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.tsx +33 -27
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +51 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +6 -0
- package/src/client/components/workspace/diff-panel/folding.test.ts +252 -0
- package/src/client/components/workspace/diff-panel/folding.ts +134 -0
- package/src/client/components/workspace/diff-panel/merge.ts +5 -0
- package/src/client/components/workspace/git-panel/InitRepository.tsx +49 -0
- package/src/client/components/workspace/git-panel/commit-modal.test.ts +193 -0
- package/src/client/components/workspace/git-panel/index.test.ts +3 -125
- package/src/client/components/workspace/git-panel/index.tsx +7 -1
- package/src/client/components/workspace/git-panel/init-state.test.ts +145 -0
- package/src/client/data/samples/virtual-devices-session.ts +8 -2
- package/src/client/data/settings/omp-schema.json +25 -3
- package/src/client/hooks/chat/timeline/ask-frames.test.ts +33 -0
- package/src/client/hooks/chat/timeline/ask-frames.ts +9 -1
- package/src/client/hooks/chat/timeline/index.ts +1 -0
- package/src/client/hooks/chat/timeline/send-execute.test.ts +14 -207
- package/src/client/hooks/chat/timeline/send-refusal.test.ts +72 -0
- package/src/client/hooks/chat/timeline/send-steer.test.ts +1 -0
- package/src/client/hooks/chat/timeline/send.test-util.ts +245 -0
- package/src/client/hooks/chat/timeline/send.test.ts +1 -0
- package/src/client/hooks/chat/timeline/send.ts +10 -0
- package/src/server/lib/fs/git-actions-worktree.ts +25 -2
- package/src/server/lib/fs/git-actions.ts +3 -3
- package/src/server/lib/fs/git-status-read.test.ts +20 -0
- package/src/server/lib/fs/git-status-read.ts +43 -2
- package/src/server/lib/omp/rpc/constants.ts +15 -1
- package/src/server/lib/omp/rpc/manager.ts +1 -1
- package/src/server/lib/omp/rpc/prewarm-pool.ts +166 -0
- package/src/server/lib/omp/rpc/session-registry.ts +80 -164
- package/src/server/lib/omp/session/messages.test.ts +21 -0
- package/src/server/lib/omp/session/resumable-model.recovery.test.ts +194 -0
- package/src/server/lib/omp/session/resumable-model.server.test.ts +90 -0
- package/src/server/lib/omp/session/resumable-model.server.ts +181 -0
- package/src/server/lib/omp/session/standby.server.ts +1 -1
- package/src/server/routes/agent/command.ts +7 -1
- package/src/server/routes/agent/prewarm.ts +1 -1
- package/src/server/routes/fs/git-action.test.ts +4 -0
- package/src/server/routes/fs/git-init-action.test.ts +125 -0
- package/src/shared/lib/chat/notice-row.test.ts +25 -0
- package/src/shared/lib/chat/notice-row.ts +22 -1
- package/src/shared/lib/chat/omp/approval-gate.test.ts +99 -0
- package/src/shared/lib/chat/omp/approval-gate.ts +129 -0
- package/src/shared/lib/omp/config/schema.test.ts +12 -0
- package/src/shared/lib/omp/session/job-progress.test.ts +76 -0
- package/src/shared/lib/omp/session/job-progress.ts +84 -0
- package/src/shared/lib/omp/session/mapper.ts +3 -6
- package/src/shared/lib/omp/session/messages-map.test.ts +15 -6
- package/src/shared/lib/omp/session/messages-map.ts +19 -1
- package/src/shared/lib/omp/session/proc.test.ts +23 -0
- package/src/shared/lib/omp/session/proc.ts +17 -0
- package/src/shared/lib/omp/session/wait.test.ts +22 -0
- package/src/shared/lib/omp/session/wait.ts +14 -0
- package/src/test-support/fake-omp-restore.ts +153 -0
- package/src/test-support/file-explorer.test-util.ts +1 -1
- package/dist/client/static/js/index-snd9wk6w.css +0 -1
|
@@ -5,224 +5,31 @@
|
|
|
5
5
|
|
|
6
6
|
/** The send path's first half: composing and executing a send —
|
|
7
7
|
* optimistic bubble, generating flag, queue fallback, and follow-up delivery.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* The steer/interrupt cases live in `send.test.ts` and the refusal-report
|
|
9
|
+
* cases in `send-refusal.test.ts`; the harness all three share is
|
|
10
|
+
* `send.test-util.ts`. Every file stays under the repo's 350-line ceiling. */
|
|
10
11
|
|
|
11
|
-
import { afterEach, beforeAll,
|
|
12
|
-
import { Window } from 'happy-dom';
|
|
13
|
-
import { h, render } from 'preact';
|
|
14
|
-
import { act } from 'preact/test-utils';
|
|
15
|
-
import type { ChatMessageData, OmpAgentHandle } from '@/shared/types';
|
|
12
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
16
13
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
|
|
26
|
-
/** The runner's own globals, restored on teardown so later files still have them. */
|
|
27
|
-
const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
28
|
-
|
|
29
|
-
/** The runner's own fetch, reached through `Bun` so a stub leaked onto the global cannot be mistaken for it. */
|
|
30
|
-
const originalFetch = Bun.fetch;
|
|
31
|
-
let container: HTMLElement;
|
|
14
|
+
act,
|
|
15
|
+
installDomGlobals,
|
|
16
|
+
makeSendHarness,
|
|
17
|
+
originalFetch,
|
|
18
|
+
requests,
|
|
19
|
+
restoreDomGlobals,
|
|
20
|
+
stubComposerFetch,
|
|
21
|
+
} from '@/client/hooks/chat/timeline/send.test-util';
|
|
32
22
|
|
|
33
23
|
beforeAll(() => {
|
|
34
|
-
|
|
35
|
-
const target = globalThis as unknown as Record<string, unknown>;
|
|
36
|
-
for (const key of DOM_GLOBALS) {
|
|
37
|
-
if (!(key in native)) native[key] = target[key];
|
|
38
|
-
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
39
|
-
}
|
|
24
|
+
installDomGlobals();
|
|
40
25
|
});
|
|
41
26
|
afterAll(() => {
|
|
42
|
-
|
|
43
|
-
for (const key of DOM_GLOBALS) {
|
|
44
|
-
if (native[key] === undefined) delete target[key];
|
|
45
|
-
else target[key] = native[key];
|
|
46
|
-
}
|
|
27
|
+
restoreDomGlobals();
|
|
47
28
|
});
|
|
48
29
|
afterEach(() => {
|
|
49
|
-
if (container) render(null, container);
|
|
50
|
-
container?.remove();
|
|
51
30
|
globalThis.fetch = originalFetch;
|
|
52
31
|
});
|
|
53
32
|
|
|
54
|
-
/** Composer autocomplete reads; answer with "no agents" so prompts pass through. */
|
|
55
|
-
function stubComposerFetch() {
|
|
56
|
-
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
57
|
-
requests.push({ url: String(input), method: init?.method ?? 'GET', body: init?.body === undefined ? null : String(init.body) });
|
|
58
|
-
return new Response('{}', { status: 200, headers: { 'content-type': 'application/json' } });
|
|
59
|
-
}) as typeof fetch;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const requests: Array<{ url: string; method: string; body: string | null }> = [];
|
|
63
|
-
|
|
64
|
-
function makeMessages(): { messages: ChatMessageData[]; setLocalMessages: ChatTimelineSendDeps['setLocalMessages'] } {
|
|
65
|
-
const messages: ChatMessageData[] = [];
|
|
66
|
-
return {
|
|
67
|
-
messages,
|
|
68
|
-
setLocalMessages: (next) => {
|
|
69
|
-
const resolved = typeof next === 'function' ? next(messages) : next;
|
|
70
|
-
messages.splice(0, messages.length, ...resolved);
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Everything the send path pushed onto the agent, plus the canned outcomes. */
|
|
76
|
-
interface AgentCalls {
|
|
77
|
-
prompts: Array<{ text: string; images: unknown; options: unknown }>;
|
|
78
|
-
newPrompts: Array<{ text: string; cwd: string; options: unknown }>;
|
|
79
|
-
models: Array<[string, string]>;
|
|
80
|
-
levels: string[];
|
|
81
|
-
interrupts: Array<{ text: string; images: unknown }>;
|
|
82
|
-
sendPromptOk: boolean;
|
|
83
|
-
/** omp's typed mid-turn refusal (nothing delivered, safe to queue). */
|
|
84
|
-
sendPromptBusy: boolean;
|
|
85
|
-
spawnResult: { sessionId: string; model?: { provider: string; modelId: string } } | null;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
interface AgentRecorder {
|
|
89
|
-
calls: AgentCalls;
|
|
90
|
-
agent: OmpAgentHandle;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function makeAgent(overrides: Partial<AgentCalls> = {}): AgentRecorder {
|
|
94
|
-
const calls: AgentCalls = {
|
|
95
|
-
prompts: [],
|
|
96
|
-
newPrompts: [],
|
|
97
|
-
models: [],
|
|
98
|
-
levels: [],
|
|
99
|
-
interrupts: [],
|
|
100
|
-
sendPromptOk: true,
|
|
101
|
-
sendPromptBusy: false,
|
|
102
|
-
spawnResult: null,
|
|
103
|
-
...overrides,
|
|
104
|
-
};
|
|
105
|
-
const agent = {
|
|
106
|
-
sendPrompt: async (text: string, images: unknown, options: unknown) => {
|
|
107
|
-
calls.prompts.push({ text, images, options });
|
|
108
|
-
return { ok: calls.sendPromptOk, busy: calls.sendPromptBusy };
|
|
109
|
-
},
|
|
110
|
-
sendNewPrompt: async (text: string, cwd: string, _images: unknown, options: unknown) => {
|
|
111
|
-
calls.newPrompts.push({ text, cwd, options });
|
|
112
|
-
return calls.spawnResult;
|
|
113
|
-
},
|
|
114
|
-
steerOmpRun: async (text: string, images: unknown) => {
|
|
115
|
-
calls.interrupts.push({ text, images });
|
|
116
|
-
return { ok: calls.sendPromptOk, busy: false };
|
|
117
|
-
},
|
|
118
|
-
setModel: async (provider: string, modelId: string) => {
|
|
119
|
-
calls.models.push([provider, modelId]);
|
|
120
|
-
},
|
|
121
|
-
setThinkingLevel: async (level: string) => {
|
|
122
|
-
calls.levels.push(level);
|
|
123
|
-
},
|
|
124
|
-
} as unknown as OmpAgentHandle;
|
|
125
|
-
return { calls, agent };
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
interface SendHarness {
|
|
129
|
-
sends: ChatTimelineSendResult;
|
|
130
|
-
deps: ChatTimelineSendDeps;
|
|
131
|
-
agent: AgentRecorder;
|
|
132
|
-
state: { messages: ChatMessageData[] };
|
|
133
|
-
persisted: ChatMessageData[][];
|
|
134
|
-
generating: boolean[];
|
|
135
|
-
drafts: string[];
|
|
136
|
-
params: string[];
|
|
137
|
-
seeds: SessionSeed[];
|
|
138
|
-
spawnSelectionRef: { current: { plan: boolean; goal: boolean } | null };
|
|
139
|
-
adoptedSessionIdRef: { current: string | null };
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function makeSendHarness(options: {
|
|
143
|
-
isOmpSession?: boolean;
|
|
144
|
-
folders?: any[];
|
|
145
|
-
selectedFolderId?: number | null;
|
|
146
|
-
sessionId?: string | null;
|
|
147
|
-
agent?: Partial<AgentCalls> | AgentRecorder;
|
|
148
|
-
deferredPick?: { current: any };
|
|
149
|
-
} = {}): SendHarness {
|
|
150
|
-
const { messages, setLocalMessages } = makeMessages();
|
|
151
|
-
// `options.agent` is either overrides for the recorder's `AgentCalls` or
|
|
152
|
-
// the finished recorder itself; the two forms are told apart by shape.
|
|
153
|
-
const agent: AgentRecorder =
|
|
154
|
-
options.agent && 'calls' in options.agent
|
|
155
|
-
? options.agent
|
|
156
|
-
: makeAgent(options.agent);
|
|
157
|
-
const persisted: ChatMessageData[][] = [];
|
|
158
|
-
const generating: boolean[] = [];
|
|
159
|
-
const drafts: string[] = [];
|
|
160
|
-
const params: string[] = [];
|
|
161
|
-
const seeds: SessionSeed[] = [];
|
|
162
|
-
const spawnSelectionRef = { current: { plan: true, goal: false } };
|
|
163
|
-
const spawnWorktreeRef = { current: null as string | null };
|
|
164
|
-
const adoptedSessionIdRef = { current: null };
|
|
165
|
-
const deps: ChatTimelineSendDeps = {
|
|
166
|
-
folders: options.folders ?? [],
|
|
167
|
-
selectedFolderId: options.selectedFolderId ?? null,
|
|
168
|
-
sessionId: options.sessionId === undefined ? 'sess-1' : options.sessionId,
|
|
169
|
-
isOmpSession: options.isOmpSession ?? true,
|
|
170
|
-
appSettings: {},
|
|
171
|
-
ompAgent: agent.agent,
|
|
172
|
-
setLocalMessages,
|
|
173
|
-
persistMessages: (msgs) => {
|
|
174
|
-
persisted.push(msgs);
|
|
175
|
-
},
|
|
176
|
-
setGenerating: (v) => {
|
|
177
|
-
generating.push(v);
|
|
178
|
-
},
|
|
179
|
-
setGeneratingVerb: () => {},
|
|
180
|
-
scrollToBottom: () => {},
|
|
181
|
-
jumpToBottom: () => {},
|
|
182
|
-
aiPlaceholderIdRef: { current: null },
|
|
183
|
-
adoptedSessionIdRef,
|
|
184
|
-
optimisticUserIdRef: { current: null },
|
|
185
|
-
pendingUserDisplaysRef: { current: [] },
|
|
186
|
-
seedSession: (seed) => {
|
|
187
|
-
seeds.push(seed);
|
|
188
|
-
},
|
|
189
|
-
pendingComposerModelRef: { current: null },
|
|
190
|
-
pendingThinkingLevelRef: { current: null },
|
|
191
|
-
deferredComposerPickRef: options.deferredPick ?? { current: null },
|
|
192
|
-
accessModeRef: { current: 'always-ask' },
|
|
193
|
-
spawnSelectionRef,
|
|
194
|
-
spawnWorktreeRef,
|
|
195
|
-
abortControllerRef: { current: null },
|
|
196
|
-
setInputValue: (v) => {
|
|
197
|
-
drafts.push(v);
|
|
198
|
-
},
|
|
199
|
-
setSearchParams: (fn) => {
|
|
200
|
-
params.push(fn(new URLSearchParams('sessionId=new-1')).toString());
|
|
201
|
-
},
|
|
202
|
-
};
|
|
203
|
-
let sends: ChatTimelineSendResult | null = null;
|
|
204
|
-
const Probe = () => {
|
|
205
|
-
sends = useChatTimelineSend(deps);
|
|
206
|
-
return h('div', { id: 'send-probe' });
|
|
207
|
-
};
|
|
208
|
-
container ??= document.body.appendChild(document.createElement('div'));
|
|
209
|
-
render(h(Probe, {}), container as HTMLElement);
|
|
210
|
-
return {
|
|
211
|
-
sends: sends as unknown as ChatTimelineSendResult,
|
|
212
|
-
deps,
|
|
213
|
-
agent,
|
|
214
|
-
state: { messages },
|
|
215
|
-
persisted,
|
|
216
|
-
generating,
|
|
217
|
-
drafts,
|
|
218
|
-
params,
|
|
219
|
-
seeds,
|
|
220
|
-
spawnSelectionRef,
|
|
221
|
-
adoptedSessionIdRef,
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
33
|
describe('executeSend', () => {
|
|
227
34
|
beforeEach(() => {
|
|
228
35
|
requests.length = 0;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* How the send path REPORTS a refusal.
|
|
8
|
+
*
|
|
9
|
+
* The optimistic bubbles are rolled back either way, so without a report the
|
|
10
|
+
* operator's turn simply VANISHES — which is the reported "gagal kirim prompt":
|
|
11
|
+
* the send did not go out and nothing said why. The server's own reason (a
|
|
12
|
+
* child that could not start, a session another process owns) is what makes
|
|
13
|
+
* the difference between "it failed" and "here is what to do".
|
|
14
|
+
*
|
|
15
|
+
* Split from `send-execute.test.ts` (which owns composing and executing a
|
|
16
|
+
* send) so both files stay under the repo's 350-line ceiling; the harness is
|
|
17
|
+
* shared through `send.test-util.ts`.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
21
|
+
import { act, installDomGlobals, makeSendHarness, originalFetch, requests, restoreDomGlobals, stubComposerFetch } from '@/client/hooks/chat/timeline/send.test-util';
|
|
22
|
+
|
|
23
|
+
beforeAll(() => {
|
|
24
|
+
installDomGlobals();
|
|
25
|
+
});
|
|
26
|
+
afterAll(() => {
|
|
27
|
+
restoreDomGlobals();
|
|
28
|
+
});
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
globalThis.fetch = originalFetch;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('a refused send', () => {
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
requests.length = 0;
|
|
36
|
+
stubComposerFetch();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("reports the server's own reason", async () => {
|
|
40
|
+
const h1 = makeSendHarness({
|
|
41
|
+
agent: { sendPromptOk: false, sendPromptError: 'omp exited (code 1): Could not restore model a/b' },
|
|
42
|
+
});
|
|
43
|
+
await act(async () => {
|
|
44
|
+
await h1.sends.executeSend('hello', []);
|
|
45
|
+
});
|
|
46
|
+
expect(h1.reported).toEqual(['Prompt not sent: omp exited (code 1): Could not restore model a/b']);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('still reports a refusal that carries no reason', async () => {
|
|
50
|
+
const h1 = makeSendHarness({ agent: { sendPromptOk: false } });
|
|
51
|
+
await act(async () => {
|
|
52
|
+
await h1.sends.executeSend('hello', []);
|
|
53
|
+
});
|
|
54
|
+
expect(h1.reported).toEqual(['Prompt not sent: the session refused it']);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('is rolled back as well as reported', async () => {
|
|
58
|
+
const h1 = makeSendHarness({ agent: { sendPromptOk: false } });
|
|
59
|
+
await act(async () => {
|
|
60
|
+
await h1.sends.executeSend('hello', []);
|
|
61
|
+
});
|
|
62
|
+
expect(h1.state.messages).toEqual([]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('a DELIVERED send reports nothing', async () => {
|
|
66
|
+
const h1 = makeSendHarness();
|
|
67
|
+
await act(async () => {
|
|
68
|
+
await h1.sends.executeSend('hello', []);
|
|
69
|
+
});
|
|
70
|
+
expect(h1.reported).toEqual([]);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The shared harness behind the two halves of the send path's test suite
|
|
8
|
+
* (`send-execute.test.ts` for composing/executing, `send-refusal.test.ts` for
|
|
9
|
+
* how a REFUSAL is reported).
|
|
10
|
+
*
|
|
11
|
+
* Split out of the test files because both need the same recorder and the same
|
|
12
|
+
* mounted `useChatTimelineSend` probe, and because copying it into a second
|
|
13
|
+
* file is how the two ends drift — the recorder is what a case asserts on, so
|
|
14
|
+
* a copy that lost a field would make a test pass for the wrong reason.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Window } from 'happy-dom';
|
|
18
|
+
import { h, render } from 'preact';
|
|
19
|
+
import { act } from 'preact/test-utils';
|
|
20
|
+
import type { ChatMessageData, OmpAgentHandle } from '@/shared/types';
|
|
21
|
+
import {
|
|
22
|
+
useChatTimelineSend,
|
|
23
|
+
type ChatTimelineSendDeps,
|
|
24
|
+
type ChatTimelineSendResult,
|
|
25
|
+
} from '@/client/hooks/chat/timeline/send';
|
|
26
|
+
import type { SessionSeed } from '@/client/hooks/chat/timeline/session-load';
|
|
27
|
+
|
|
28
|
+
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
|
|
29
|
+
|
|
30
|
+
let installed: { restore: () => void } | null = null;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Give the file a DOM. Idempotent per process, and the restore puts the
|
|
34
|
+
* runner's own globals back so later files are unaffected.
|
|
35
|
+
*/
|
|
36
|
+
export function installDomGlobals(): void {
|
|
37
|
+
if (installed) return;
|
|
38
|
+
const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
39
|
+
const win = new Window({ url: 'http://localhost' });
|
|
40
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
41
|
+
for (const key of DOM_GLOBALS) {
|
|
42
|
+
native[key] = target[key];
|
|
43
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
44
|
+
}
|
|
45
|
+
installed = {
|
|
46
|
+
restore: () => {
|
|
47
|
+
for (const key of DOM_GLOBALS) {
|
|
48
|
+
if (native[key] === undefined) delete target[key];
|
|
49
|
+
else target[key] = native[key];
|
|
50
|
+
}
|
|
51
|
+
installed = null;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function restoreDomGlobals(): void {
|
|
57
|
+
installed?.restore();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The runner's own fetch, reached through `Bun` so a leaked stub cannot be mistaken for it. */
|
|
61
|
+
export const originalFetch = Bun.fetch;
|
|
62
|
+
|
|
63
|
+
export const requests: Array<{ url: string; method: string; body: string | null }> = [];
|
|
64
|
+
|
|
65
|
+
/** Composer autocomplete reads; answer with "no agents" so prompts pass through. */
|
|
66
|
+
export function stubComposerFetch(): void {
|
|
67
|
+
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
68
|
+
requests.push({ url: String(input), method: init?.method ?? 'GET', body: init?.body === undefined ? null : String(init.body) });
|
|
69
|
+
return new Response('{}', { status: 200, headers: { 'content-type': 'application/json' } });
|
|
70
|
+
}) as typeof fetch;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function makeMessages(): { messages: ChatMessageData[]; setLocalMessages: ChatTimelineSendDeps['setLocalMessages'] } {
|
|
74
|
+
const messages: ChatMessageData[] = [];
|
|
75
|
+
return {
|
|
76
|
+
messages,
|
|
77
|
+
setLocalMessages: (next) => {
|
|
78
|
+
const resolved = typeof next === 'function' ? next(messages) : next;
|
|
79
|
+
messages.splice(0, messages.length, ...resolved);
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Everything the send path pushed onto the agent, plus the canned outcomes. */
|
|
85
|
+
export interface AgentCalls {
|
|
86
|
+
prompts: Array<{ text: string; images: unknown; options: unknown }>;
|
|
87
|
+
newPrompts: Array<{ text: string; cwd: string; options: unknown }>;
|
|
88
|
+
models: Array<[string, string]>;
|
|
89
|
+
levels: string[];
|
|
90
|
+
interrupts: Array<{ text: string; images: unknown }>;
|
|
91
|
+
sendPromptOk: boolean;
|
|
92
|
+
/** omp's typed mid-turn refusal (nothing delivered, safe to queue). */
|
|
93
|
+
sendPromptBusy: boolean;
|
|
94
|
+
/** The server-supplied reason, when the send was refused. */
|
|
95
|
+
sendPromptError: string | undefined;
|
|
96
|
+
spawnResult: { sessionId: string; model?: { provider: string; modelId: string } } | null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface AgentRecorder {
|
|
100
|
+
calls: AgentCalls;
|
|
101
|
+
agent: OmpAgentHandle;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function makeAgent(overrides: Partial<AgentCalls> = {}): AgentRecorder {
|
|
105
|
+
const calls: AgentCalls = {
|
|
106
|
+
prompts: [],
|
|
107
|
+
newPrompts: [],
|
|
108
|
+
models: [],
|
|
109
|
+
levels: [],
|
|
110
|
+
interrupts: [],
|
|
111
|
+
sendPromptOk: true,
|
|
112
|
+
sendPromptBusy: false,
|
|
113
|
+
sendPromptError: undefined,
|
|
114
|
+
spawnResult: null,
|
|
115
|
+
...overrides,
|
|
116
|
+
};
|
|
117
|
+
const agent = {
|
|
118
|
+
sendPrompt: async (text: string, images: unknown, options: unknown) => {
|
|
119
|
+
calls.prompts.push({ text, images, options });
|
|
120
|
+
return { ok: calls.sendPromptOk, busy: calls.sendPromptBusy, error: calls.sendPromptError };
|
|
121
|
+
},
|
|
122
|
+
sendNewPrompt: async (text: string, cwd: string, _images: unknown, options: unknown) => {
|
|
123
|
+
calls.newPrompts.push({ text, cwd, options });
|
|
124
|
+
return calls.spawnResult;
|
|
125
|
+
},
|
|
126
|
+
steerOmpRun: async (text: string, images: unknown) => {
|
|
127
|
+
calls.interrupts.push({ text, images });
|
|
128
|
+
return { ok: calls.sendPromptOk, busy: false, error: calls.sendPromptError };
|
|
129
|
+
},
|
|
130
|
+
setModel: async (provider: string, modelId: string) => {
|
|
131
|
+
calls.models.push([provider, modelId]);
|
|
132
|
+
},
|
|
133
|
+
setThinkingLevel: async (level: string) => {
|
|
134
|
+
calls.levels.push(level);
|
|
135
|
+
},
|
|
136
|
+
} as unknown as OmpAgentHandle;
|
|
137
|
+
return { calls, agent };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface SendHarness {
|
|
141
|
+
sends: ChatTimelineSendResult;
|
|
142
|
+
deps: ChatTimelineSendDeps;
|
|
143
|
+
agent: AgentRecorder;
|
|
144
|
+
state: { messages: ChatMessageData[] };
|
|
145
|
+
persisted: ChatMessageData[][];
|
|
146
|
+
generating: boolean[];
|
|
147
|
+
drafts: string[];
|
|
148
|
+
/** Every message the send path REPORTED (the toast channel). */
|
|
149
|
+
reported: string[];
|
|
150
|
+
params: string[];
|
|
151
|
+
seeds: SessionSeed[];
|
|
152
|
+
spawnSelectionRef: { current: { plan: boolean; goal: boolean } | null };
|
|
153
|
+
adoptedSessionIdRef: { current: string | null };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function makeSendHarness(options: {
|
|
157
|
+
folders?: unknown[];
|
|
158
|
+
selectedFolderId?: number | null;
|
|
159
|
+
sessionId?: string | null;
|
|
160
|
+
isOmpSession?: boolean;
|
|
161
|
+
agent?: AgentRecorder | Partial<AgentCalls>;
|
|
162
|
+
deferredPick?: { current: unknown };
|
|
163
|
+
} = {}): SendHarness {
|
|
164
|
+
installDomGlobals();
|
|
165
|
+
const { messages, setLocalMessages } = makeMessages();
|
|
166
|
+
// `options.agent` is either overrides for the recorder's `AgentCalls` or
|
|
167
|
+
// the finished recorder itself; the two forms are told apart by shape.
|
|
168
|
+
const agent: AgentRecorder =
|
|
169
|
+
options.agent && 'calls' in options.agent
|
|
170
|
+
? options.agent
|
|
171
|
+
: makeAgent(options.agent);
|
|
172
|
+
const persisted: ChatMessageData[][] = [];
|
|
173
|
+
const generating: boolean[] = [];
|
|
174
|
+
const drafts: string[] = [];
|
|
175
|
+
const reported: string[] = [];
|
|
176
|
+
const params: string[] = [];
|
|
177
|
+
const seeds: SessionSeed[] = [];
|
|
178
|
+
const spawnSelectionRef = { current: { plan: true, goal: false } };
|
|
179
|
+
const spawnWorktreeRef = { current: null as string | null };
|
|
180
|
+
const adoptedSessionIdRef = { current: null };
|
|
181
|
+
const deps: ChatTimelineSendDeps = {
|
|
182
|
+
folders: (options.folders ?? []) as ChatTimelineSendDeps['folders'],
|
|
183
|
+
selectedFolderId: options.selectedFolderId ?? null,
|
|
184
|
+
sessionId: options.sessionId === undefined ? 'sess-1' : options.sessionId,
|
|
185
|
+
isOmpSession: options.isOmpSession ?? true,
|
|
186
|
+
appSettings: {},
|
|
187
|
+
ompAgent: agent.agent,
|
|
188
|
+
setLocalMessages,
|
|
189
|
+
persistMessages: (msgs) => {
|
|
190
|
+
persisted.push(msgs);
|
|
191
|
+
},
|
|
192
|
+
setGenerating: (v) => {
|
|
193
|
+
generating.push(v);
|
|
194
|
+
},
|
|
195
|
+
setGeneratingVerb: () => {},
|
|
196
|
+
scrollToBottom: () => {},
|
|
197
|
+
jumpToBottom: () => {},
|
|
198
|
+
aiPlaceholderIdRef: { current: null },
|
|
199
|
+
adoptedSessionIdRef,
|
|
200
|
+
optimisticUserIdRef: { current: null },
|
|
201
|
+
pendingUserDisplaysRef: { current: [] },
|
|
202
|
+
seedSession: (seed) => {
|
|
203
|
+
seeds.push(seed);
|
|
204
|
+
},
|
|
205
|
+
pendingComposerModelRef: { current: null },
|
|
206
|
+
pendingThinkingLevelRef: { current: null },
|
|
207
|
+
deferredComposerPickRef: (options.deferredPick ?? { current: null }) as ChatTimelineSendDeps['deferredComposerPickRef'],
|
|
208
|
+
accessModeRef: { current: 'always-ask' },
|
|
209
|
+
spawnSelectionRef,
|
|
210
|
+
spawnWorktreeRef,
|
|
211
|
+
abortControllerRef: { current: null },
|
|
212
|
+
setInputValue: (v) => {
|
|
213
|
+
drafts.push(v);
|
|
214
|
+
},
|
|
215
|
+
reportActionError: (message: string) => {
|
|
216
|
+
reported.push(message);
|
|
217
|
+
},
|
|
218
|
+
setSearchParams: (fn) => {
|
|
219
|
+
params.push(fn(new URLSearchParams('sessionId=new-1')).toString());
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
let sends: ChatTimelineSendResult | null = null;
|
|
223
|
+
const Probe = () => {
|
|
224
|
+
sends = useChatTimelineSend(deps);
|
|
225
|
+
return h('div', { id: 'send-probe' });
|
|
226
|
+
};
|
|
227
|
+
const container = document.body.appendChild(document.createElement('div'));
|
|
228
|
+
render(h(Probe, {}), container as HTMLElement);
|
|
229
|
+
return {
|
|
230
|
+
sends: sends as unknown as ChatTimelineSendResult,
|
|
231
|
+
deps,
|
|
232
|
+
agent,
|
|
233
|
+
state: { messages },
|
|
234
|
+
persisted,
|
|
235
|
+
generating,
|
|
236
|
+
drafts,
|
|
237
|
+
reported,
|
|
238
|
+
params,
|
|
239
|
+
seeds,
|
|
240
|
+
spawnSelectionRef,
|
|
241
|
+
adoptedSessionIdRef,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export { act };
|
|
@@ -70,6 +70,10 @@ export interface ChatTimelineSendDeps {
|
|
|
70
70
|
deferredComposerPickRef: DeferredModelStore;
|
|
71
71
|
abortControllerRef: { current: AbortController | null };
|
|
72
72
|
setInputValue: (v: string) => void;
|
|
73
|
+
/** Surface a refused send. The optimistic bubbles are rolled back either
|
|
74
|
+
* way; without this the operator's turn simply VANISHES, which is the
|
|
75
|
+
* "prompt failed to send" report this exists to answer. */
|
|
76
|
+
reportActionError: (message: string) => void;
|
|
73
77
|
setSearchParams: (fn: (prev: URLSearchParams) => URLSearchParams, opts?: { replace?: boolean }) => void;
|
|
74
78
|
}
|
|
75
79
|
|
|
@@ -114,6 +118,7 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
|
|
|
114
118
|
spawnWorktreeRef,
|
|
115
119
|
abortControllerRef,
|
|
116
120
|
setInputValue,
|
|
121
|
+
reportActionError,
|
|
117
122
|
setSearchParams,
|
|
118
123
|
} = deps;
|
|
119
124
|
|
|
@@ -233,6 +238,11 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
|
|
|
233
238
|
aiPlaceholderIdRef.current = null;
|
|
234
239
|
optimisticUserIdRef.current = null;
|
|
235
240
|
setGenerating(false);
|
|
241
|
+
// And SAY so. The rollback alone left the operator's turn vanishing
|
|
242
|
+
// with no explanation, which is the reported "gagal kirim prompt": the
|
|
243
|
+
// server's reason (a dead child, a session another process owns) was
|
|
244
|
+
// computed and then dropped on the floor.
|
|
245
|
+
reportActionError(`Prompt not sent: ${result.error ?? 'the session refused it'}`);
|
|
236
246
|
}
|
|
237
247
|
return result;
|
|
238
248
|
}
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The working-tree and history half of the Source Control panel's actions: the
|
|
8
|
-
* index, the commit, checkout, branch creation, and the two
|
|
9
|
-
* travel through the POST path (a page of commits, one file's
|
|
8
|
+
* repository init, the index, the commit, checkout, branch creation, and the two
|
|
9
|
+
* read actions that travel through the POST path (a page of commits, one file's
|
|
10
|
+
* patch).
|
|
10
11
|
*
|
|
11
12
|
* The branch/remote/conflict/stash half is `git-actions-branch.ts`; both are
|
|
12
13
|
* merged into one dispatch table by `git-actions.ts`. Split for the repo's
|
|
@@ -24,6 +25,7 @@
|
|
|
24
25
|
|
|
25
26
|
import { invalidateRemoteRefs } from '@/server/lib/fs/git-sync';
|
|
26
27
|
import { readGitState } from '@/server/lib/fs/git-state';
|
|
28
|
+
import { runGit } from '@/server/lib/fs/git-run';
|
|
27
29
|
import { revertAll, revertPath } from '@/server/lib/fs/git-revert';
|
|
28
30
|
import {
|
|
29
31
|
cherryPick,
|
|
@@ -76,6 +78,27 @@ async function checkoutRef(targetDir: string, ref: string): Promise<void> {
|
|
|
76
78
|
|
|
77
79
|
/** The working-tree and history actions. */
|
|
78
80
|
export const GIT_WORKTREE_ACTIONS: Record<string, GitActionHandler> = {
|
|
81
|
+
/**
|
|
82
|
+
* Create the repository, for a folder that has none.
|
|
83
|
+
*
|
|
84
|
+
* The Source Control panel offers this INSTEAD of its toolbar, commit box and
|
|
85
|
+
* change list when the status read answers `isRepo: false` (see
|
|
86
|
+
* `git-status-read.ts`), so it is the one action reachable on a tree where
|
|
87
|
+
* every other action would fail with "not a git repository".
|
|
88
|
+
*
|
|
89
|
+
* The guard is the probe, not the panel's render state: `git init` on an
|
|
90
|
+
* existing repository is a silent "Reinitialized existing Git repository", so a
|
|
91
|
+
* stale client would be told it created something it did not. `rev-parse
|
|
92
|
+
* --git-dir` is also what catches the folder-inside-another-repo case, where
|
|
93
|
+
* git answers with the ENCLOSING repository and `init` would nest a second one
|
|
94
|
+
* inside it.
|
|
95
|
+
*/
|
|
96
|
+
async init({ targetDir }) {
|
|
97
|
+
const existing = await runGit(['rev-parse', '--git-dir'], { cwd: targetDir });
|
|
98
|
+
if (existing.exitCode === 0) throw new Error('Already a Git repository.');
|
|
99
|
+
await expectOk(['init'], targetDir);
|
|
100
|
+
},
|
|
101
|
+
|
|
79
102
|
async commit({ formData, targetDir }) {
|
|
80
103
|
const message = (formData.get('message') as string) ?? '';
|
|
81
104
|
const amend = formData.get('amend') === '1';
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
* shape — root/repo resolution, the 400 envelope, the realtime signal — and
|
|
14
14
|
* adding an action is a row rather than another `else if`.
|
|
15
15
|
*
|
|
16
|
-
* - `git-actions-worktree.ts` — the index, the commit,
|
|
17
|
-
* creation, history/graph, and the commit-row actions
|
|
18
|
-
* reset, rebase).
|
|
16
|
+
* - `git-actions-worktree.ts` — repository init, the index, the commit,
|
|
17
|
+
* checkout, branch creation, history/graph, and the commit-row actions
|
|
18
|
+
* (cherry-pick, revert, reset, rebase).
|
|
19
19
|
* - `git-actions-branch.ts` — merge, the conflict trio, fetch/push/pull/sync,
|
|
20
20
|
* branch rename/delete, the stash.
|
|
21
21
|
*/
|