@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
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The commit modal opens because the user ASKED for it — never because the
|
|
8
|
+
* panel re-rendered.
|
|
9
|
+
*
|
|
10
|
+
* `actionFetcher.data` is sticky (it holds the last response for the life of
|
|
11
|
+
* the mount) while the effect that turns a history payload into the modal also
|
|
12
|
+
* depends on `loadRepo`, whose identity changes whenever `rootPath` does. So
|
|
13
|
+
* switching to a session in another workspace re-ran that effect against the
|
|
14
|
+
* PREVIOUS history payload and reopened a modal the user had already dismissed
|
|
15
|
+
* (reported as "clicking a session item opens the commit modal").
|
|
16
|
+
*
|
|
17
|
+
* Split from `index.test.ts` when both files reached the repo's line ceiling;
|
|
18
|
+
* each owns its own harness.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
22
|
+
import { Window } from 'happy-dom';
|
|
23
|
+
import { h, render } from 'preact';
|
|
24
|
+
import { act } from 'preact/test-utils';
|
|
25
|
+
import { GitPanel } from '@/client/components/workspace/git-panel';
|
|
26
|
+
import { SessionStateProvider } from '@/client/components/common/session-state-provider/index';
|
|
27
|
+
import { resetRealtimeClient } from '@/shared/lib/realtime/client';
|
|
28
|
+
import { gitTopic, reposTopic } from '@/shared/lib/realtime/protocol';
|
|
29
|
+
import { startRealtimeTestServer, type RealtimeTestServer } from '@/test-support/realtime-server';
|
|
30
|
+
import { installDomGlobals, pristineWebSocket, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
31
|
+
import type { TopicResolver } from '@/server/lib/realtime/hub.server';
|
|
32
|
+
|
|
33
|
+
const ROOT = '/ws';
|
|
34
|
+
const SESSION = 'new-git-panel-modal';
|
|
35
|
+
const TOPIC = gitTopic(`${ROOT}\u0000.`);
|
|
36
|
+
|
|
37
|
+
/** The runner's own fetch, reached through `Bun` so a leaked stub cannot be mistaken for it. */
|
|
38
|
+
const nativeFetch = Bun.fetch;
|
|
39
|
+
|
|
40
|
+
let container: HTMLElement;
|
|
41
|
+
let server: RealtimeTestServer;
|
|
42
|
+
|
|
43
|
+
/** A payload the panel renders as `count` changed files — a repository. */
|
|
44
|
+
function statusOf(count: number): unknown {
|
|
45
|
+
return {
|
|
46
|
+
changes: Array.from({ length: count }, (_, i) => ({
|
|
47
|
+
status: '??',
|
|
48
|
+
file: `file-${i}.txt`,
|
|
49
|
+
staged: false,
|
|
50
|
+
additions: 1,
|
|
51
|
+
deletions: 0,
|
|
52
|
+
})),
|
|
53
|
+
branch: 'main',
|
|
54
|
+
branches: ['main'],
|
|
55
|
+
remoteBranches: [],
|
|
56
|
+
isRepo: true,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
beforeAll(() => {
|
|
61
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
afterEach(() => {
|
|
65
|
+
if (container) {
|
|
66
|
+
render(null, container);
|
|
67
|
+
container.remove();
|
|
68
|
+
}
|
|
69
|
+
resetRealtimeClient();
|
|
70
|
+
server?.stop();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
afterAll(() => {
|
|
74
|
+
(globalThis as unknown as Record<string, unknown>).fetch = nativeFetch;
|
|
75
|
+
restoreDomGlobals();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* happy-dom ships none of the three globals the modal's measurement layer
|
|
80
|
+
* needs (`useLayoutEffect`'s rAF, its own `ResizeObserver`, the paging
|
|
81
|
+
* `IntersectionObserver`). Stubbed rather than asserted on: the modal's
|
|
82
|
+
* geometry is not what this test is about.
|
|
83
|
+
*/
|
|
84
|
+
const OBSERVER_STUBS = ['ResizeObserver', 'IntersectionObserver'] as const;
|
|
85
|
+
const stubs: Partial<Record<(typeof OBSERVER_STUBS)[number], unknown>> = {};
|
|
86
|
+
|
|
87
|
+
beforeAll(() => {
|
|
88
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
89
|
+
for (const key of OBSERVER_STUBS) stubs[key] = target[key];
|
|
90
|
+
target.ResizeObserver = class { observe() {} unobserve() {} disconnect() {} };
|
|
91
|
+
target.IntersectionObserver = class { observe() {} unobserve() {} disconnect() {} };
|
|
92
|
+
// No-op rather than a timer: the geometry pass is not what this asserts, and
|
|
93
|
+
// a real delay would make the case's duration depend on the machine.
|
|
94
|
+
target.requestAnimationFrame = () => 0;
|
|
95
|
+
target.cancelAnimationFrame = () => {};
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
afterAll(() => {
|
|
99
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
100
|
+
for (const key of OBSERVER_STUBS) {
|
|
101
|
+
if (stubs[key] === undefined) delete target[key];
|
|
102
|
+
else target[key] = stubs[key];
|
|
103
|
+
}
|
|
104
|
+
delete target.requestAnimationFrame;
|
|
105
|
+
delete target.cancelAnimationFrame;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
/** Mount with an HTTP POST that answers a history page. */
|
|
109
|
+
async function mountHistory(): Promise<{ rerender: (props: { rootPath: string; enabled: boolean }) => Promise<void> }> {
|
|
110
|
+
server = await startRealtimeTestServer(new Map<string, TopicResolver>([
|
|
111
|
+
[TOPIC, async () => statusOf(1)],
|
|
112
|
+
[reposTopic(ROOT), async () => ({ repos: ['.'], reposPending: false })],
|
|
113
|
+
]));
|
|
114
|
+
const win = new Window({ url: `http://127.0.0.1:${server.port}` });
|
|
115
|
+
installDomGlobals(win);
|
|
116
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
117
|
+
target.WebSocket = pristineWebSocket;
|
|
118
|
+
target.fetch = async (input: unknown, init?: RequestInit) => {
|
|
119
|
+
const url = String(input);
|
|
120
|
+
const json = (body: unknown) => new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
|
|
121
|
+
if (url.includes('/state')) return json({ sessionId: SESSION, state: {} });
|
|
122
|
+
if (url.includes('reposOnly')) return json({ repos: ['.'], reposPending: false });
|
|
123
|
+
if (init?.method === 'POST') {
|
|
124
|
+
return json({ success: true, type: 'history', data: [{ hash: 'abc1234', message: 'first', author: 'a', time: 'now' }], hasMore: false, total: 1 });
|
|
125
|
+
}
|
|
126
|
+
return json(statusOf(0));
|
|
127
|
+
};
|
|
128
|
+
container = document.createElement('div');
|
|
129
|
+
document.body.appendChild(container);
|
|
130
|
+
const rerender = async (props: { rootPath: string; enabled: boolean }) => {
|
|
131
|
+
await act(async () => {
|
|
132
|
+
render(h(SessionStateProvider, { sessionId: SESSION, children: h(GitPanel, props) }), container);
|
|
133
|
+
});
|
|
134
|
+
for (let i = 0; i < 20; i += 1) await act(async () => {});
|
|
135
|
+
};
|
|
136
|
+
await rerender({ rootPath: ROOT, enabled: true });
|
|
137
|
+
await server.waitForTopic(TOPIC, (value) => value !== null);
|
|
138
|
+
for (let i = 0; i < 20; i += 1) await act(async () => {});
|
|
139
|
+
return { rerender };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const settle = async (rounds = 20) => { for (let i = 0; i < rounds; i += 1) await act(async () => {}); };
|
|
143
|
+
|
|
144
|
+
describe('GitPanel commit modal', () => {
|
|
145
|
+
test('a dismissed modal stays dismissed when the workspace root moves', async () => {
|
|
146
|
+
const { rerender } = await mountHistory();
|
|
147
|
+
|
|
148
|
+
const historyButton = container.querySelector('button[title="Commit History"]') as HTMLButtonElement | null;
|
|
149
|
+
expect(historyButton).toBeTruthy();
|
|
150
|
+
await act(async () => { historyButton?.click(); });
|
|
151
|
+
await settle();
|
|
152
|
+
expect(container.querySelector('[role="dialog"]')).toBeTruthy();
|
|
153
|
+
|
|
154
|
+
const close = container.querySelector('button[title="Close modal"]') as HTMLButtonElement | null;
|
|
155
|
+
expect(close).toBeTruthy();
|
|
156
|
+
await act(async () => { close?.click(); });
|
|
157
|
+
await settle(5);
|
|
158
|
+
expect(container.querySelector('[role="dialog"]')).toBeNull();
|
|
159
|
+
|
|
160
|
+
await rerender({ rootPath: '/ws-other', enabled: true });
|
|
161
|
+
expect(container.querySelector('[role="dialog"]')).toBeNull();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The same guard covers the ACTIVITY-BAR case: `enabled` is what the layout
|
|
166
|
+
* flips when another right-panel view is selected, and `loadRepo` depends on
|
|
167
|
+
* it too — so a panel-button click re-ran the effect exactly as a workspace
|
|
168
|
+
* switch did. Reported as the modal appearing "when clicking a panel button".
|
|
169
|
+
*/
|
|
170
|
+
test('a dismissed modal stays dismissed when the panel is toggled off and on', async () => {
|
|
171
|
+
const { rerender } = await mountHistory();
|
|
172
|
+
|
|
173
|
+
const historyButton = container.querySelector('button[title="Commit History"]') as HTMLButtonElement | null;
|
|
174
|
+
expect(historyButton).toBeTruthy();
|
|
175
|
+
await act(async () => { historyButton?.click(); });
|
|
176
|
+
await settle();
|
|
177
|
+
expect(container.querySelector('[role="dialog"]')).toBeTruthy();
|
|
178
|
+
|
|
179
|
+
const close = container.querySelector('button[title="Close modal"]') as HTMLButtonElement | null;
|
|
180
|
+
expect(close).toBeTruthy();
|
|
181
|
+
await act(async () => { close?.click(); });
|
|
182
|
+
await settle(5);
|
|
183
|
+
expect(container.querySelector('[role="dialog"]')).toBeNull();
|
|
184
|
+
|
|
185
|
+
// Selecting another view in the activity bar: the layout sets `enabled` false.
|
|
186
|
+
await rerender({ rootPath: ROOT, enabled: false });
|
|
187
|
+
expect(container.querySelector('[role="dialog"]')).toBeNull();
|
|
188
|
+
|
|
189
|
+
// And back to Source Control.
|
|
190
|
+
await rerender({ rootPath: ROOT, enabled: true });
|
|
191
|
+
expect(container.querySelector('[role="dialog"]')).toBeNull();
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -54,6 +54,7 @@ function statusOf(count: number, syncCount?: { ahead: number; behind: number }):
|
|
|
54
54
|
branch: 'main',
|
|
55
55
|
branches: ['main'],
|
|
56
56
|
remoteBranches: [],
|
|
57
|
+
isRepo: true,
|
|
57
58
|
...(syncCount ? { syncCount } : {}),
|
|
58
59
|
};
|
|
59
60
|
}
|
|
@@ -219,129 +220,6 @@ describe('GitPanel sync badge', () => {
|
|
|
219
220
|
});
|
|
220
221
|
|
|
221
222
|
/**
|
|
222
|
-
* The commit modal
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* `actionFetcher.data` is sticky (it holds the last response for the life of
|
|
226
|
-
* the mount) while the effect that turns a history payload into the modal also
|
|
227
|
-
* depends on `loadRepo`, whose identity changes whenever `rootPath` does. So
|
|
228
|
-
* switching to a session in another workspace re-ran that effect against the
|
|
229
|
-
* PREVIOUS history payload and reopened a modal the user had already dismissed
|
|
230
|
-
* (reported as "clicking a session item opens the commit modal").
|
|
223
|
+
* The commit modal's own cases live in `commit-modal.test.ts`: the two files
|
|
224
|
+
* together exceeded the repo's line ceiling, and each mounts its own harness.
|
|
231
225
|
*/
|
|
232
|
-
describe('GitPanel commit modal', () => {
|
|
233
|
-
/**
|
|
234
|
-
* happy-dom ships none of the three globals the modal's measurement layer
|
|
235
|
-
* needs (`useLayoutEffect`'s rAF, its own `ResizeObserver`, the paging
|
|
236
|
-
* `IntersectionObserver`). Stubbed rather than asserted on: the modal's
|
|
237
|
-
* geometry is not what this test is about.
|
|
238
|
-
*/
|
|
239
|
-
const OBSERVER_STUBS = ['ResizeObserver', 'IntersectionObserver'] as const;
|
|
240
|
-
const stubs: Partial<Record<(typeof OBSERVER_STUBS)[number], unknown>> = {};
|
|
241
|
-
|
|
242
|
-
beforeAll(() => {
|
|
243
|
-
const target = globalThis as unknown as Record<string, unknown>;
|
|
244
|
-
for (const key of OBSERVER_STUBS) stubs[key] = target[key];
|
|
245
|
-
target.ResizeObserver = class { observe() {} unobserve() {} disconnect() {} };
|
|
246
|
-
target.IntersectionObserver = class { observe() {} unobserve() {} disconnect() {} };
|
|
247
|
-
// No-op rather than a timer: the geometry pass is not what this asserts, and
|
|
248
|
-
// a real delay would make the case's duration depend on the machine.
|
|
249
|
-
target.requestAnimationFrame = () => 0;
|
|
250
|
-
target.cancelAnimationFrame = () => {};
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
afterAll(() => {
|
|
254
|
-
const target = globalThis as unknown as Record<string, unknown>;
|
|
255
|
-
for (const key of OBSERVER_STUBS) {
|
|
256
|
-
if (stubs[key] === undefined) delete target[key];
|
|
257
|
-
else target[key] = stubs[key];
|
|
258
|
-
}
|
|
259
|
-
delete target.requestAnimationFrame;
|
|
260
|
-
delete target.cancelAnimationFrame;
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
/** Mount with an HTTP POST that answers a history page. */
|
|
264
|
-
async function mountHistory(): Promise<{ rerender: (props: { rootPath: string; enabled: boolean }) => Promise<void> }> {
|
|
265
|
-
server = await startRealtimeTestServer(new Map<string, TopicResolver>([
|
|
266
|
-
[TOPIC, async () => statusOf(1)],
|
|
267
|
-
[reposTopic(ROOT), async () => ({ repos: ['.'], reposPending: false })],
|
|
268
|
-
]));
|
|
269
|
-
const win = new Window({ url: `http://127.0.0.1:${server.port}` });
|
|
270
|
-
installDomGlobals(win);
|
|
271
|
-
const target = globalThis as unknown as Record<string, unknown>;
|
|
272
|
-
target.WebSocket = pristineWebSocket;
|
|
273
|
-
target.fetch = async (input: unknown, init?: RequestInit) => {
|
|
274
|
-
const url = String(input);
|
|
275
|
-
const json = (body: unknown) => new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
|
|
276
|
-
if (url.includes('/state')) return json({ sessionId: SESSION, state: {} });
|
|
277
|
-
if (url.includes('reposOnly')) return json({ repos: ['.'], reposPending: false });
|
|
278
|
-
if (init?.method === 'POST') {
|
|
279
|
-
return json({ success: true, type: 'history', data: [{ hash: 'abc1234', message: 'first', author: 'a', time: 'now' }], hasMore: false, total: 1 });
|
|
280
|
-
}
|
|
281
|
-
return json(statusOf(0));
|
|
282
|
-
};
|
|
283
|
-
container = document.createElement('div');
|
|
284
|
-
document.body.appendChild(container);
|
|
285
|
-
const rerender = async (props: { rootPath: string; enabled: boolean }) => {
|
|
286
|
-
await act(async () => {
|
|
287
|
-
render(h(SessionStateProvider, { sessionId: SESSION, children: h(GitPanel, props) }), container);
|
|
288
|
-
});
|
|
289
|
-
for (let i = 0; i < 20; i += 1) await act(async () => {});
|
|
290
|
-
};
|
|
291
|
-
await rerender({ rootPath: ROOT, enabled: true });
|
|
292
|
-
await server.waitForTopic(TOPIC, (value) => value !== null);
|
|
293
|
-
for (let i = 0; i < 20; i += 1) await act(async () => {});
|
|
294
|
-
return { rerender };
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const settle = async (rounds = 20) => { for (let i = 0; i < rounds; i += 1) await act(async () => {}); };
|
|
298
|
-
|
|
299
|
-
test('a dismissed modal stays dismissed when the workspace root moves', async () => {
|
|
300
|
-
const { rerender } = await mountHistory();
|
|
301
|
-
|
|
302
|
-
const historyButton = container.querySelector('button[title="Commit History"]') as HTMLButtonElement | null;
|
|
303
|
-
expect(historyButton).toBeTruthy();
|
|
304
|
-
await act(async () => { historyButton?.click(); });
|
|
305
|
-
await settle();
|
|
306
|
-
expect(container.querySelector('[role="dialog"]')).toBeTruthy();
|
|
307
|
-
|
|
308
|
-
const close = container.querySelector('button[title="Close modal"]') as HTMLButtonElement | null;
|
|
309
|
-
expect(close).toBeTruthy();
|
|
310
|
-
await act(async () => { close?.click(); });
|
|
311
|
-
await settle(5);
|
|
312
|
-
expect(container.querySelector('[role="dialog"]')).toBeNull();
|
|
313
|
-
|
|
314
|
-
await rerender({ rootPath: '/ws-other', enabled: true });
|
|
315
|
-
expect(container.querySelector('[role="dialog"]')).toBeNull();
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* The same guard covers the ACTIVITY-BAR case: `enabled` is what the layout
|
|
320
|
-
* flips when another right-panel view is selected, and `loadRepo` depends on
|
|
321
|
-
* it too — so a panel-button click re-ran the effect exactly as a workspace
|
|
322
|
-
* switch did. Reported as the modal appearing "when clicking a panel button".
|
|
323
|
-
*/
|
|
324
|
-
test('a dismissed modal stays dismissed when the panel is toggled off and on', async () => {
|
|
325
|
-
const { rerender } = await mountHistory();
|
|
326
|
-
|
|
327
|
-
const historyButton = container.querySelector('button[title="Commit History"]') as HTMLButtonElement | null;
|
|
328
|
-
expect(historyButton).toBeTruthy();
|
|
329
|
-
await act(async () => { historyButton?.click(); });
|
|
330
|
-
await settle();
|
|
331
|
-
expect(container.querySelector('[role="dialog"]')).toBeTruthy();
|
|
332
|
-
|
|
333
|
-
const close = container.querySelector('button[title="Close modal"]') as HTMLButtonElement | null;
|
|
334
|
-
expect(close).toBeTruthy();
|
|
335
|
-
await act(async () => { close?.click(); });
|
|
336
|
-
await settle(5);
|
|
337
|
-
expect(container.querySelector('[role="dialog"]')).toBeNull();
|
|
338
|
-
|
|
339
|
-
// Selecting another view in the activity bar: the layout sets `enabled` false.
|
|
340
|
-
await rerender({ rootPath: ROOT, enabled: false });
|
|
341
|
-
expect(container.querySelector('[role="dialog"]')).toBeNull();
|
|
342
|
-
|
|
343
|
-
// And back to Source Control.
|
|
344
|
-
await rerender({ rootPath: ROOT, enabled: true });
|
|
345
|
-
expect(container.querySelector('[role="dialog"]')).toBeNull();
|
|
346
|
-
});
|
|
347
|
-
});
|
|
@@ -8,6 +8,7 @@ import { GitRepoHeader } from '@/client/components/workspace/git-panel/RepoHeade
|
|
|
8
8
|
import { GitChangesList } from '@/client/components/workspace/git-panel/ChangesList';
|
|
9
9
|
import { GitPanelModals } from '@/client/components/workspace/git-panel/PanelModals';
|
|
10
10
|
import { GitStashSection } from '@/client/components/workspace/git-panel/StashSection';
|
|
11
|
+
import { GitInitRepository } from '@/client/components/workspace/git-panel/InitRepository';
|
|
11
12
|
import { ToastStack } from '@/client/components/common/ToastStack';
|
|
12
13
|
import { useToasts } from '@/client/hooks/ui/toasts';
|
|
13
14
|
import { useSessionState } from '@/client/hooks/workspace/session-state';
|
|
@@ -264,7 +265,11 @@ export function GitPanel({ className = '', enabled = true, rootPath, refreshKey
|
|
|
264
265
|
}}
|
|
265
266
|
onRefreshRepos={refreshRepos}
|
|
266
267
|
/>
|
|
267
|
-
|
|
268
|
+
{/* A folder with no repository has no working tree to show, and the picker
|
|
269
|
+
above can still point at a nested one: everything below acts on a repo. */}
|
|
270
|
+
{data?.isRepo === false ? (
|
|
271
|
+
<GitInitRepository repo={activeRepo} isBusy={isBusy} onInit={() => executeAction('init')} />
|
|
272
|
+
) : (<>
|
|
268
273
|
{/* Branch & View Mode Toolbar */}
|
|
269
274
|
<GitBranchToolbar
|
|
270
275
|
branchRef={branchRef}
|
|
@@ -337,6 +342,7 @@ export function GitPanel({ className = '', enabled = true, rootPath, refreshKey
|
|
|
337
342
|
isBusy={isBusy}
|
|
338
343
|
onAction={(actionType, extra) => handleAction(actionType, undefined, extra)}
|
|
339
344
|
/>
|
|
345
|
+
</>)}
|
|
340
346
|
</div>
|
|
341
347
|
);
|
|
342
348
|
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A folder that is not a repository gets ONE control instead of the panel's
|
|
8
|
+
* chrome.
|
|
9
|
+
*
|
|
10
|
+
* The status read reports `isRepo: false` for it (it used to fold git's refusal
|
|
11
|
+
* into an empty change list on branch `main`), and the panel drew its branch
|
|
12
|
+
* toolbar, commit box and "No changes found." over a directory where every one of
|
|
13
|
+
* them fails with `fatal: not a git repository` — the reported "the git panel has
|
|
14
|
+
* no function here, only the dropdown works".
|
|
15
|
+
*
|
|
16
|
+
* Split from `index.test.ts`: the two files together exceeded the repo's line
|
|
17
|
+
* ceiling, and each mounts its own harness.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
21
|
+
import { Window } from 'happy-dom';
|
|
22
|
+
import { h, render } from 'preact';
|
|
23
|
+
import { act } from 'preact/test-utils';
|
|
24
|
+
import { GitPanel } from '@/client/components/workspace/git-panel';
|
|
25
|
+
import { SessionStateProvider } from '@/client/components/common/session-state-provider/index';
|
|
26
|
+
import { resetRealtimeClient } from '@/shared/lib/realtime/client';
|
|
27
|
+
import { gitTopic, reposTopic } from '@/shared/lib/realtime/protocol';
|
|
28
|
+
import { startRealtimeTestServer, type RealtimeTestServer } from '@/test-support/realtime-server';
|
|
29
|
+
import { installDomGlobals, pristineWebSocket, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
30
|
+
import type { TopicResolver } from '@/server/lib/realtime/hub.server';
|
|
31
|
+
|
|
32
|
+
const ROOT = '/ws';
|
|
33
|
+
const SESSION = 'new-git-panel-init';
|
|
34
|
+
const TOPIC = gitTopic(`${ROOT}\u0000.`);
|
|
35
|
+
|
|
36
|
+
/** The runner's own fetch, reached through `Bun` so a leaked stub cannot be mistaken for it. */
|
|
37
|
+
const nativeFetch = Bun.fetch;
|
|
38
|
+
|
|
39
|
+
let container: HTMLElement;
|
|
40
|
+
let server: RealtimeTestServer;
|
|
41
|
+
/** Every action the panel posted, as its form fields — reset per mount. */
|
|
42
|
+
let actionRequests: Array<Record<string, unknown>> = [];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A folder outside every repository, as `readGitStatus` reports it: an EMPTY
|
|
46
|
+
* change list carrying git's own refusal. The `isRepo` flag is what the panel
|
|
47
|
+
* reads — the empty list and `main` are the same fields a clean repository has.
|
|
48
|
+
*/
|
|
49
|
+
const NOT_A_REPO = {
|
|
50
|
+
changes: [],
|
|
51
|
+
branch: 'main',
|
|
52
|
+
branches: [],
|
|
53
|
+
remoteBranches: [],
|
|
54
|
+
isRepo: false,
|
|
55
|
+
error: 'fatal: not a git repository (or any of the parent directories): .git',
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
beforeAll(() => {
|
|
59
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
afterEach(() => {
|
|
63
|
+
if (container) {
|
|
64
|
+
render(null, container);
|
|
65
|
+
container.remove();
|
|
66
|
+
}
|
|
67
|
+
resetRealtimeClient();
|
|
68
|
+
server?.stop();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
afterAll(() => {
|
|
72
|
+
(globalThis as unknown as Record<string, unknown>).fetch = nativeFetch;
|
|
73
|
+
restoreDomGlobals();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/** Mount the panel over a server that answers the not-a-repository payload. */
|
|
77
|
+
async function mount(): Promise<void> {
|
|
78
|
+
actionRequests = [];
|
|
79
|
+
server = await startRealtimeTestServer(new Map<string, TopicResolver>([
|
|
80
|
+
[TOPIC, async () => NOT_A_REPO],
|
|
81
|
+
[reposTopic(ROOT), async () => ({ repos: ['.'], reposPending: false })],
|
|
82
|
+
]));
|
|
83
|
+
const win = new Window({ url: `http://127.0.0.1:${server.port}` });
|
|
84
|
+
installDomGlobals(win);
|
|
85
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
86
|
+
target.WebSocket = pristineWebSocket;
|
|
87
|
+
target.fetch = async (input: unknown, init?: RequestInit) => {
|
|
88
|
+
const url = String(input);
|
|
89
|
+
const json = (body: unknown) => new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
|
|
90
|
+
if (url.includes('/state')) return json({ sessionId: SESSION, state: {} });
|
|
91
|
+
if (url.includes('reposOnly')) return json({ repos: ['.'], reposPending: false });
|
|
92
|
+
if (init?.method === 'POST') {
|
|
93
|
+
// Duck-typed, not `instanceof FormData`: the body is built by the panel in
|
|
94
|
+
// the happy-dom realm, so an identity check would miss it.
|
|
95
|
+
const body = init.body as { forEach?: (fn: (value: unknown, key: string) => void) => void } | null;
|
|
96
|
+
const fields: Record<string, unknown> = {};
|
|
97
|
+
body?.forEach?.((value, key) => { fields[key] = value; });
|
|
98
|
+
actionRequests.push(fields);
|
|
99
|
+
return json({ success: true });
|
|
100
|
+
}
|
|
101
|
+
// The panel's own HTTP read answers the same state: both paths agree.
|
|
102
|
+
return json(NOT_A_REPO);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
container = document.createElement('div');
|
|
106
|
+
document.body.appendChild(container);
|
|
107
|
+
await act(async () => {
|
|
108
|
+
render(
|
|
109
|
+
h(SessionStateProvider, {
|
|
110
|
+
sessionId: SESSION,
|
|
111
|
+
children: h(GitPanel, { rootPath: ROOT, enabled: true }),
|
|
112
|
+
}),
|
|
113
|
+
container,
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
await server.waitForTopic(TOPIC, (value) => value !== null);
|
|
117
|
+
for (let i = 0; i < 20; i += 1) await act(async () => {});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
describe('GitPanel without a repository', () => {
|
|
121
|
+
test('offers Initialize instead of the toolbar, commit box and change list', async () => {
|
|
122
|
+
await mount();
|
|
123
|
+
|
|
124
|
+
expect(container.textContent).toContain('Not a Git repository');
|
|
125
|
+
expect(container.querySelector('button[aria-label="Initialize Git repository"]')).toBeTruthy();
|
|
126
|
+
// The chrome that cannot act on this folder is GONE, not merely empty.
|
|
127
|
+
expect(container.textContent).not.toContain('No changes found.');
|
|
128
|
+
expect(container.querySelector('textarea')).toBeNull();
|
|
129
|
+
expect(container.querySelector('button[aria-label="Sync with upstream"]')).toBeNull();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('the button posts the init action for the scoped folder', async () => {
|
|
133
|
+
await mount();
|
|
134
|
+
|
|
135
|
+
const button = container.querySelector('button[aria-label="Initialize Git repository"]') as HTMLButtonElement | null;
|
|
136
|
+
if (!button) throw new Error('no initialize control rendered');
|
|
137
|
+
await act(async () => { button.click(); });
|
|
138
|
+
for (let i = 0; i < 20; i += 1) await act(async () => {});
|
|
139
|
+
|
|
140
|
+
expect(actionRequests).toHaveLength(1);
|
|
141
|
+
expect(actionRequests[0]?.actionType).toBe('init');
|
|
142
|
+
expect(actionRequests[0]?.repo).toBe('.');
|
|
143
|
+
expect(actionRequests[0]?.root).toBe(ROOT);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -229,11 +229,17 @@ app/hooks/useSync.ts
|
|
|
229
229
|
label: 'Deep Typecheck & Regression Suite',
|
|
230
230
|
durationMs: 1820,
|
|
231
231
|
resolvedModel: 'claude-3-5-sonnet',
|
|
232
|
-
status: '
|
|
232
|
+
status: 'running',
|
|
233
|
+
completionPercent: 55,
|
|
234
|
+
requests: 90,
|
|
235
|
+
cost: 18.4,
|
|
236
|
+
contextTokens: 163_840,
|
|
237
|
+
contextWindow: 1_048_576,
|
|
238
|
+
stage: 'implementing',
|
|
233
239
|
},
|
|
234
240
|
],
|
|
235
241
|
},
|
|
236
|
-
output: '
|
|
242
|
+
output: 'Wait limit reached; 1 of 2 background jobs still running — read proc:// for status.',
|
|
237
243
|
},
|
|
238
244
|
...internalUrlCalls,
|
|
239
245
|
{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"source": "@oh-my-pi/pi-coding-agent 10 tabs /
|
|
2
|
+
"source": "@oh-my-pi/pi-coding-agent 10 tabs / 563 settings",
|
|
3
3
|
"tabs": [
|
|
4
4
|
{
|
|
5
5
|
"id": "appearance",
|
|
@@ -1524,7 +1524,7 @@
|
|
|
1524
1524
|
"tab": "interaction",
|
|
1525
1525
|
"group": "Power",
|
|
1526
1526
|
"label": "Sleep Prevention",
|
|
1527
|
-
"description": "Prevent the system sleeping
|
|
1527
|
+
"description": "Prevent the system sleeping while the agent is running a turn; an idle session, including one waiting on background jobs, does not hold it. Each level is cumulative — it adds the flags of all lower levels.",
|
|
1528
1528
|
"options": [
|
|
1529
1529
|
{
|
|
1530
1530
|
"value": "off",
|
|
@@ -1534,7 +1534,7 @@
|
|
|
1534
1534
|
{
|
|
1535
1535
|
"value": "idle",
|
|
1536
1536
|
"label": "Prevent Idle Sleep",
|
|
1537
|
-
"description": "Keep the system awake while
|
|
1537
|
+
"description": "Keep the system awake while the agent is running a turn (macOS `caffeinate -i`)"
|
|
1538
1538
|
},
|
|
1539
1539
|
{
|
|
1540
1540
|
"value": "display",
|
|
@@ -5887,6 +5887,18 @@
|
|
|
5887
5887
|
]
|
|
5888
5888
|
}
|
|
5889
5889
|
},
|
|
5890
|
+
"tools.restrictedFolders": {
|
|
5891
|
+
"type": "array",
|
|
5892
|
+
"default": [],
|
|
5893
|
+
"ui": {
|
|
5894
|
+
"tab": "interaction",
|
|
5895
|
+
"group": "Approvals",
|
|
5896
|
+
"label": "Restricted Folders",
|
|
5897
|
+
"editor": "json",
|
|
5898
|
+
"description": "Folders where every read, write, edit, search, or command needs an explicit approval, whatever the approval mode or a remembered grant. The folder and everything under it is restricted; commands are matched by the directory they run in. A JSON list of paths, e.g. [\"~/secrets\"].",
|
|
5899
|
+
"condition": "restrictedFoldersNotProject"
|
|
5900
|
+
}
|
|
5901
|
+
},
|
|
5890
5902
|
"todo.enabled": {
|
|
5891
5903
|
"type": "boolean",
|
|
5892
5904
|
"default": true,
|
|
@@ -6510,6 +6522,16 @@
|
|
|
6510
6522
|
"description": "Enable async bash commands and background task execution"
|
|
6511
6523
|
}
|
|
6512
6524
|
},
|
|
6525
|
+
"async.printWake": {
|
|
6526
|
+
"type": "boolean",
|
|
6527
|
+
"default": false,
|
|
6528
|
+
"ui": {
|
|
6529
|
+
"tab": "tools",
|
|
6530
|
+
"group": "Execution",
|
|
6531
|
+
"label": "Wake Print Mode on Job Results",
|
|
6532
|
+
"description": "In print mode (-p, --mode json), keep running after the last prompt while this run's background jobs are active, and start another turn in the same session with each job's result; exits once no job or result is pending. Off: print mode exits after its prompts and cancels running jobs"
|
|
6533
|
+
}
|
|
6534
|
+
},
|
|
6513
6535
|
"async.widgets": {
|
|
6514
6536
|
"type": "boolean",
|
|
6515
6537
|
"default": true,
|
|
@@ -47,6 +47,15 @@ function selectFrame(id: string, title: string): ExtensionUiDialogRequest {
|
|
|
47
47
|
return { type: 'extension_ui_request', id, method: 'select', title, options: ['A (Recommended)', 'B', 'Other (type your own)'] };
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* omp's TOOL-APPROVAL gate, exactly as it arrives over RPC: a `select` whose
|
|
52
|
+
* title is omp's whole prompt and whose choices are "Approve" / "Deny"
|
|
53
|
+
* (measured against 18.13.1).
|
|
54
|
+
*/
|
|
55
|
+
function approvalGateFrame(id: string, title: string): ExtensionUiDialogRequest {
|
|
56
|
+
return { type: 'extension_ui_request', id, method: 'select', title, options: ['Approve', 'Deny'] };
|
|
57
|
+
}
|
|
58
|
+
|
|
50
59
|
function confirmFrame(id: string, title: string): ExtensionUiDialogRequest {
|
|
51
60
|
return { type: 'extension_ui_request', id, method: 'confirm', title };
|
|
52
61
|
}
|
|
@@ -148,4 +157,28 @@ describe('splitAskFrames', () => {
|
|
|
148
157
|
expect(split.framesByTool.size).toBe(0);
|
|
149
158
|
expect(split.modalRequest).toBe(frame);
|
|
150
159
|
});
|
|
160
|
+
|
|
161
|
+
test('an approval gate is not claimed by an open question\'s card', () => {
|
|
162
|
+
// The gate arrives over RPC as a `select` whose title is omp's approval
|
|
163
|
+
// prompt (measured against 18.13.1) — the same method as a question's own
|
|
164
|
+
// dialog, and its title names no question, so the "last ask spoke"
|
|
165
|
+
// fallback used to hand it to that ask's card. There it rendered as
|
|
166
|
+
// "Approve"/"Deny" offered as the ANSWERS to "Which language?", and the
|
|
167
|
+
// answer was posted to the ask instead of the call being approved.
|
|
168
|
+
const question = selectFrame('f1', 'Which language?');
|
|
169
|
+
const gate = approvalGateFrame('g1', 'Allow tool: read\nReason: Restricted folder: /tmp/secret\nPath: /tmp/secret/creds.txt');
|
|
170
|
+
const split = splitAskFrames(askHistory(['Which language?']), [question, gate], true);
|
|
171
|
+
|
|
172
|
+
const held = split.framesByTool.get('call_ask')?.[0]?.map((frame) => frame.id) ?? [];
|
|
173
|
+
expect(held).toEqual(['f1']);
|
|
174
|
+
expect(split.modalRequest).toBe(gate);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('an approval gate beside no question at all keeps the modal', () => {
|
|
178
|
+
const gate = approvalGateFrame('g1', 'Allow tool: bash\nCommand: ls -la /tmp');
|
|
179
|
+
const split = splitAskFrames([], [gate], true);
|
|
180
|
+
|
|
181
|
+
expect(split.framesByTool.size).toBe(0);
|
|
182
|
+
expect(split.modalRequest).toBe(gate);
|
|
183
|
+
});
|
|
151
184
|
});
|
|
@@ -43,6 +43,7 @@ import { createContext, useContext } from 'preact/compat';
|
|
|
43
43
|
import type { ChatMessageData } from '@/shared/types';
|
|
44
44
|
import type { ExtensionUiDialogRequest } from '@/shared/types/omp/agent';
|
|
45
45
|
import { groupAskFrames, isAskSettled, isAskToolCall, normalizeAskText, parseAskQuestions, parseAskResult, type AskQuestion } from '@/shared/lib/chat/ask-questions';
|
|
46
|
+
import { isApprovalGateFrame } from '@/shared/lib/chat/omp/approval-gate';
|
|
46
47
|
import type { ExtensionDialogResponse } from '@/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/Lazy';
|
|
47
48
|
|
|
48
49
|
export interface AskFramesSplit {
|
|
@@ -181,7 +182,14 @@ export function splitAskFrames(
|
|
|
181
182
|
// The dialog omp opens after "Other (type your own)" names the question in
|
|
182
183
|
// its title only loosely; it continues whichever ask spoke last. An
|
|
183
184
|
// approval gate is never part of an ask, so it keeps its own modal.
|
|
184
|
-
|
|
185
|
+
//
|
|
186
|
+
// The gate arrives as a `select` over RPC (see `isApprovalGateFrame`), and
|
|
187
|
+
// its title names no question — so the walk above cannot place it, and the
|
|
188
|
+
// "last ask spoke" fallback used to hand it to that ask's card, where
|
|
189
|
+
// "Approve"/"Deny" rendered as the ANSWERS to an unrelated question and
|
|
190
|
+
// the answer went to the wrong tool call. A gate is excluded from the
|
|
191
|
+
// fallback exactly like a `confirm`, and reaches the modal instead.
|
|
192
|
+
if (!owner && request.method !== 'confirm' && !isApprovalGateFrame(request)) owner = lastOwner;
|
|
185
193
|
if (!owner) continue;
|
|
186
194
|
claimed.add(request);
|
|
187
195
|
lastOwner = owner;
|