@pi-chamber/web 0.3.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/bin/lib/cli-startup.js +1 -0
- package/dist/assets/CommitSection-Cz-ACBaD.js +1 -0
- package/dist/assets/DiagramEditor-BNUOrd9m.js +1 -0
- package/dist/assets/DiagramView-D4YR9YRt.js +1 -0
- package/dist/assets/{DiffView-DGD9DMS7.js → DiffView-DPW8dcg_.js} +3 -3
- package/dist/assets/FilesView-BFGIdY6b.js +14 -0
- package/dist/assets/GitView-CKtiKOfJ.js +6 -0
- package/dist/assets/JsonTreeView-c-UJUw3D.js +1 -0
- package/dist/assets/{MarkdownRendererImpl-V1HMFCjr.js → MarkdownRendererImpl-CvC9eXoa.js} +2 -2
- package/dist/assets/PatchDiff-YGHsZUIR.js +1 -0
- package/dist/assets/PierreDiffViewer-CoXa-JJK.js +136 -0
- package/dist/assets/SessionSwitcherContent-B7eep3dO.js +1 -0
- package/dist/assets/SessionSwitcherDropdown-CZOFeJHH.js +2 -0
- package/dist/assets/SessionUnreadDot-ClpeYFPz.js +1 -0
- package/dist/assets/SettingsView-CPmHHDbQ.js +4 -0
- package/dist/assets/SettingsWindow-2CBpoJ8H.js +1 -0
- package/dist/assets/{ToolOutputDialog-2zKUdGYL.js → ToolOutputDialog-HMW-Kh19.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-C3nbNbxk.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-UMgLcO4Q.js → VirtualizedFileDiff-DEX83nQ0.js} +3 -3
- package/dist/assets/{SessionSwitcherDropdown-o1RjhCfF.js → WindowsWindowControls-PPk5H89-.js} +172 -118
- package/dist/assets/collapsible-Dux-9hAC.js +1 -0
- package/dist/assets/computeVirtualFileMetrics-Cy0nxMJB.js +3 -0
- package/dist/assets/contextFileOpenGuard-Dn_38hd9.js +1 -0
- package/dist/assets/index--zDkVFU6.css +1 -0
- package/dist/assets/index-DU2OBBy5.js +8 -0
- package/dist/assets/index-EN7MioVf.js +1 -0
- package/dist/assets/isDiffPlainText-DSWRVq-W.js +1 -0
- package/dist/assets/isFilePlainText-7RAjjrQ5.js +1 -0
- package/dist/assets/{main-CmkRaMOR.js → main-BGKjg-qW.js} +8 -8
- package/dist/assets/main-DGHrBx_u.js +2 -0
- package/dist/assets/markdownCore-BYPqQtbE.js +3 -0
- package/dist/assets/miniChat-DW2PVX49.js +2 -0
- package/dist/assets/mobile-0Gxc02iO.js +2 -0
- package/dist/assets/renderElectronMiniChatApp-C-qpqp1i.js +2 -0
- package/dist/assets/renderMobileApp-UB9bhC1x.js +14 -0
- package/dist/assets/{runtimeSurface-CkHYYg0E.js → runtimeSurface-DefD-2Iv.js} +1 -1
- package/dist/assets/{useInlineCommentController-DD31jQNC.js → useInlineCommentController-B8p2XwXA.js} +2 -2
- package/dist/assets/usePanelSlide-CbqVf-y8.js +56 -0
- package/dist/assets/usePushVisibilityBeacon-CvjN-47R.js +10 -0
- package/dist/assets/useSwitcherItems-B6_F-J-z.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-Dp_Z-0GD.js → vendor-codemirror-language-data-BhBdEPsJ.js} +2 -2
- package/dist/assets/{vendor-katex-CHD9BdDO.js → vendor-katex-CNckGUMB.js} +1 -1
- package/dist/assets/{vendor-marked-i_gIkIP3.js → vendor-marked-CX41MkDF.js} +1 -1
- package/dist/assets/{web-components-Cct1r-wn.js → web-components-C9yVPsWN.js} +2 -2
- package/dist/index.html +8 -5
- package/dist/mini-chat.html +7 -4
- package/dist/mobile.html +7 -4
- package/dist/sw.js +1 -1
- package/package.json +1 -1
- package/server/index.js +27 -5
- package/server/lib/fs/routes.js +0 -21
- package/server/lib/git/DOCUMENTATION.md +15 -5
- package/server/lib/git/issue-2746-longpaths.test.js +11 -11
- package/server/lib/git/routes.js +80 -4
- package/server/lib/git/routes.test.js +135 -0
- package/server/lib/git/service.js +144 -82
- package/server/lib/git/service.test.js +182 -36
- package/server/lib/pi/extension-protocol.js +62 -0
- package/server/lib/pi/extension-protocol.test.js +34 -0
- package/server/lib/pi/fixtures/pichamber-gui-demo.ts +251 -0
- package/server/lib/pi/routes-extension-events.test.js +152 -0
- package/server/lib/pi/routes.js +345 -7
- package/server/lib/pi/routes.test.js +43 -28
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +8 -5
- package/server/lib/pi/session-daemon/extension-bridge.js +488 -0
- package/server/lib/pi/session-daemon/message-entry-aliases.js +53 -13
- package/server/lib/pi/session-daemon/message-entry-aliases.test.js +110 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.e2e.test.js +215 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +559 -0
- package/server/lib/pi/session-daemon/session-daemon.js +483 -54
- package/server/lib/pi/session-daemon/session-daemon.test.js +212 -4
- package/server/lib/pi/session-daemon/session-retry-limits.js +55 -0
- package/server/lib/pi/session-daemon/session-retry-limits.test.js +53 -0
- package/server/lib/pi/session-daemon/skill-read-classifier.js +39 -0
- package/server/lib/pi/session-daemon/skill-read-classifier.test.js +41 -0
- package/server/lib/pi/session-daemon/supervisor.js +3 -0
- package/server/lib/pi/small-model-generation.js +104 -0
- package/server/lib/pi/small-model-generation.test.js +66 -0
- package/server/lib/preview/proxy-runtime.js +11 -1
- package/server/lib/preview/proxy-runtime.test.js +3 -0
- package/server/lib/relay/tunnel-host.js +1 -0
- package/server/lib/server/cors.js +0 -2
- package/server/lib/server/cors.test.js +4 -4
- package/server/lib/stt/DOCUMENTATION.md +38 -0
- package/server/lib/stt/audio.js +47 -0
- package/server/lib/stt/config-store.js +81 -0
- package/server/lib/stt/config-store.test.js +36 -0
- package/server/lib/stt/local/model-catalog.js +57 -0
- package/server/lib/stt/local/model-downloader.js +127 -0
- package/server/lib/stt/local/recognizer.js +64 -0
- package/server/lib/stt/local/sherpa-loader.js +43 -0
- package/server/lib/stt/local/worker-client.js +115 -0
- package/server/lib/stt/local/worker-process.js +64 -0
- package/server/lib/stt/protocol.js +38 -0
- package/server/lib/stt/protocol.test.js +17 -0
- package/server/lib/stt/providers/local-worker-provider.js +11 -0
- package/server/lib/stt/providers/openai-compatible-provider.js +31 -0
- package/server/lib/stt/providers/openai-compatible-provider.test.js +31 -0
- package/server/lib/stt/runtime.js +111 -0
- package/server/lib/stt/service.js +106 -0
- package/server/lib/stt/stream-manager.js +188 -0
- package/server/lib/stt/stream-manager.test.js +64 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +1 -1
- package/server/lib/ui-auth/ui-auth.js +8 -3
- package/server/lib/ui-auth/ui-auth.test.js +8 -0
- package/server/lib/workspace/host.js +19 -3
- package/dist/assets/CommitSection-BAYzLtBf.js +0 -1
- package/dist/assets/DiagramEditor-D1yc4joK.js +0 -1
- package/dist/assets/DiagramView-CAlJiG11.js +0 -1
- package/dist/assets/FilesView-DB5VI7EN.js +0 -14
- package/dist/assets/GitView-CFlPcSn9.js +0 -6
- package/dist/assets/JsonTreeView-CoX1ZscV.js +0 -1
- package/dist/assets/PatchDiff-D6Gs7K5B.js +0 -1
- package/dist/assets/PierreDiffViewer-COYd5Qr-.js +0 -136
- package/dist/assets/SettingsView-BYqvfMTS.js +0 -4
- package/dist/assets/SettingsWindow-CtNS0tQn.js +0 -1
- package/dist/assets/ToolPartDiffPreview-CBFC9min.js +0 -8
- package/dist/assets/collapsible-Kx4bmsQM.js +0 -1
- package/dist/assets/computeVirtualFileMetrics-DdOCbMyK.js +0 -3
- package/dist/assets/contextFileOpenGuard-BRldMp0d.js +0 -1
- package/dist/assets/index-BAqpUCjs.js +0 -8
- package/dist/assets/index-CuSNEV7s.js +0 -1
- package/dist/assets/index-riABQmQ_.css +0 -1
- package/dist/assets/isDiffPlainText-CGIf0q8p.js +0 -1
- package/dist/assets/isFilePlainText-D4hgTRxT.js +0 -1
- package/dist/assets/main-By_pvk90.js +0 -2
- package/dist/assets/markdownCore-CAVCyFnI.js +0 -2
- package/dist/assets/miniChat-_XK2gGZE.js +0 -2
- package/dist/assets/mobile-B4E4JqAf.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-Ca4hZgIz.js +0 -1
- package/dist/assets/renderMobileApp-ClA5Cnmw.js +0 -14
- package/dist/assets/usePanelSlide-a4c67FIY.js +0 -56
- package/dist/assets/useWindowTitle-DoHrUC5r.js +0 -10
- package/server/lib/pi/legacy-ui-model-defaults.js +0 -57
- package/server/lib/pi/legacy-ui-model-defaults.test.js +0 -65
package/server/lib/git/routes.js
CHANGED
|
@@ -248,6 +248,62 @@ export function registerGitRoutes(app) {
|
|
|
248
248
|
}
|
|
249
249
|
});
|
|
250
250
|
|
|
251
|
+
app.get('/api/git/worktrees', async (req, res) => {
|
|
252
|
+
const { getWorktrees } = await getGitLibraries();
|
|
253
|
+
try {
|
|
254
|
+
const directory = resolveDirectoryQuery(req.query.directory);
|
|
255
|
+
if (!directory) {
|
|
256
|
+
return res.status(400).json({ error: 'directory parameter is required' });
|
|
257
|
+
}
|
|
258
|
+
res.json({ worktrees: await getWorktrees(directory) });
|
|
259
|
+
} catch (error) {
|
|
260
|
+
console.error('Failed to list git worktrees:', error);
|
|
261
|
+
res.status(500).json({ error: error.message || 'Failed to list git worktrees' });
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
app.post('/api/git/worktrees/validate', async (req, res) => {
|
|
266
|
+
const { validateWorktreeCreate } = await getGitLibraries();
|
|
267
|
+
try {
|
|
268
|
+
const directory = resolveDirectoryQuery(req.query.directory);
|
|
269
|
+
if (!directory) {
|
|
270
|
+
return res.status(400).json({ error: 'directory parameter is required' });
|
|
271
|
+
}
|
|
272
|
+
res.json(await validateWorktreeCreate(directory, req.body ?? {}));
|
|
273
|
+
} catch (error) {
|
|
274
|
+
console.error('Failed to validate git worktree:', error);
|
|
275
|
+
res.status(400).json({ error: error.message || 'Failed to validate git worktree' });
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
app.post('/api/git/worktrees', async (req, res) => {
|
|
280
|
+
const { createWorktree } = await getGitLibraries();
|
|
281
|
+
try {
|
|
282
|
+
const directory = resolveDirectoryQuery(req.query.directory);
|
|
283
|
+
if (!directory) {
|
|
284
|
+
return res.status(400).json({ error: 'directory parameter is required' });
|
|
285
|
+
}
|
|
286
|
+
res.status(201).json(await createWorktree(directory, req.body ?? {}));
|
|
287
|
+
} catch (error) {
|
|
288
|
+
console.error('Failed to create git worktree:', error);
|
|
289
|
+
res.status(400).json({ error: error.message || 'Failed to create git worktree' });
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
app.get('/api/git/worktrees/bootstrap-status', async (req, res) => {
|
|
294
|
+
const { getWorktreeBootstrapStatus } = await getGitLibraries();
|
|
295
|
+
try {
|
|
296
|
+
const directory = resolveDirectoryQuery(req.query.directory);
|
|
297
|
+
if (!directory) {
|
|
298
|
+
return res.status(400).json({ error: 'directory parameter is required' });
|
|
299
|
+
}
|
|
300
|
+
res.json(await getWorktreeBootstrapStatus(directory));
|
|
301
|
+
} catch (error) {
|
|
302
|
+
console.error('Failed to get git worktree bootstrap status:', error);
|
|
303
|
+
res.status(500).json({ error: error.message || 'Failed to get git worktree bootstrap status' });
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
|
|
251
307
|
app.get('/api/git/primary-root', async (req, res) => {
|
|
252
308
|
const { resolvePrimaryWorktreeRoot } = await getGitLibraries();
|
|
253
309
|
try {
|
|
@@ -925,16 +981,36 @@ export function registerGitRoutes(app) {
|
|
|
925
981
|
return res.status(400).json({ error: 'directory parameter is required' });
|
|
926
982
|
}
|
|
927
983
|
|
|
928
|
-
const { branch } = req.body;
|
|
929
|
-
if (!branch) {
|
|
984
|
+
const { branch, expectedCurrent, localOnly } = req.body;
|
|
985
|
+
if (typeof branch !== 'string' || !branch.trim()) {
|
|
930
986
|
return res.status(400).json({ error: 'branch is required' });
|
|
931
987
|
}
|
|
988
|
+
if (
|
|
989
|
+
Object.prototype.hasOwnProperty.call(req.body, 'expectedCurrent')
|
|
990
|
+
&& expectedCurrent !== null
|
|
991
|
+
&& typeof expectedCurrent !== 'string'
|
|
992
|
+
) {
|
|
993
|
+
return res.status(400).json({ error: 'expectedCurrent must be a branch name or null' });
|
|
994
|
+
}
|
|
995
|
+
if (localOnly !== undefined && typeof localOnly !== 'boolean') {
|
|
996
|
+
return res.status(400).json({ error: 'localOnly must be a boolean' });
|
|
997
|
+
}
|
|
932
998
|
|
|
933
|
-
const
|
|
999
|
+
const options = {
|
|
1000
|
+
...(Object.prototype.hasOwnProperty.call(req.body, 'expectedCurrent') ? { expectedCurrent } : {}),
|
|
1001
|
+
...(localOnly === true ? { localOnly: true } : {}),
|
|
1002
|
+
};
|
|
1003
|
+
const result = await checkoutBranch(directory, branch, options);
|
|
934
1004
|
res.json(result);
|
|
935
1005
|
} catch (error) {
|
|
936
1006
|
console.error('Failed to checkout branch:', error);
|
|
937
|
-
res.status(500).json({
|
|
1007
|
+
res.status(error.statusCode || 500).json({
|
|
1008
|
+
error: error.message || 'Failed to checkout branch',
|
|
1009
|
+
...(typeof error.code === 'string' ? { code: error.code } : {}),
|
|
1010
|
+
...(typeof error.currentBranch === 'string' || error.currentBranch === null
|
|
1011
|
+
? { currentBranch: error.currentBranch }
|
|
1012
|
+
: {}),
|
|
1013
|
+
});
|
|
938
1014
|
}
|
|
939
1015
|
});
|
|
940
1016
|
|
|
@@ -5,6 +5,11 @@ const gitLibraries = {
|
|
|
5
5
|
unstageFiles: vi.fn(),
|
|
6
6
|
isGitRepository: vi.fn(),
|
|
7
7
|
getStatus: vi.fn(),
|
|
8
|
+
checkoutBranch: vi.fn(),
|
|
9
|
+
getWorktrees: vi.fn(),
|
|
10
|
+
validateWorktreeCreate: vi.fn(),
|
|
11
|
+
createWorktree: vi.fn(),
|
|
12
|
+
getWorktreeBootstrapStatus: vi.fn(),
|
|
8
13
|
};
|
|
9
14
|
|
|
10
15
|
vi.mock('./index.js', () => ({
|
|
@@ -12,6 +17,11 @@ vi.mock('./index.js', () => ({
|
|
|
12
17
|
unstageFiles: gitLibraries.unstageFiles,
|
|
13
18
|
isGitRepository: gitLibraries.isGitRepository,
|
|
14
19
|
getStatus: gitLibraries.getStatus,
|
|
20
|
+
checkoutBranch: gitLibraries.checkoutBranch,
|
|
21
|
+
getWorktrees: gitLibraries.getWorktrees,
|
|
22
|
+
validateWorktreeCreate: gitLibraries.validateWorktreeCreate,
|
|
23
|
+
createWorktree: gitLibraries.createWorktree,
|
|
24
|
+
getWorktreeBootstrapStatus: gitLibraries.getWorktreeBootstrapStatus,
|
|
15
25
|
}));
|
|
16
26
|
|
|
17
27
|
const { registerGitRoutes } = await import('./routes.js');
|
|
@@ -67,6 +77,63 @@ describe('git routes index mutations', () => {
|
|
|
67
77
|
gitLibraries.unstageFiles.mockReset();
|
|
68
78
|
gitLibraries.isGitRepository.mockReset();
|
|
69
79
|
gitLibraries.getStatus.mockReset();
|
|
80
|
+
gitLibraries.checkoutBranch.mockReset();
|
|
81
|
+
gitLibraries.getWorktrees.mockReset();
|
|
82
|
+
gitLibraries.validateWorktreeCreate.mockReset();
|
|
83
|
+
gitLibraries.createWorktree.mockReset();
|
|
84
|
+
gitLibraries.getWorktreeBootstrapStatus.mockReset();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('lists worktrees without converting failures into an empty result', async () => {
|
|
88
|
+
const { app, getRoute } = createRouteRegistry();
|
|
89
|
+
registerGitRoutes(app);
|
|
90
|
+
const response = createMockResponse();
|
|
91
|
+
gitLibraries.getWorktrees.mockResolvedValue([{ path: '/repo-task', branch: 'task' }]);
|
|
92
|
+
|
|
93
|
+
await getRoute('GET', '/api/git/worktrees')(
|
|
94
|
+
{ query: { directory: '/repo' } },
|
|
95
|
+
response,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
expect(response.statusCode).toBe(200);
|
|
99
|
+
expect(response.body).toEqual({ worktrees: [{ path: '/repo-task', branch: 'task' }] });
|
|
100
|
+
expect(gitLibraries.getWorktrees).toHaveBeenCalledWith('/repo');
|
|
101
|
+
|
|
102
|
+
const failed = createMockResponse();
|
|
103
|
+
gitLibraries.getWorktrees.mockRejectedValueOnce(new Error('registry unavailable'));
|
|
104
|
+
await getRoute('GET', '/api/git/worktrees')(
|
|
105
|
+
{ query: { directory: '/repo' } },
|
|
106
|
+
failed,
|
|
107
|
+
);
|
|
108
|
+
expect(failed.statusCode).toBe(500);
|
|
109
|
+
expect(failed.body).toEqual({ error: 'registry unavailable' });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('creates and polls a worktree through explicit routes', async () => {
|
|
113
|
+
const { app, getRoute } = createRouteRegistry();
|
|
114
|
+
registerGitRoutes(app);
|
|
115
|
+
const created = {
|
|
116
|
+
path: '/repo-task',
|
|
117
|
+
branch: 'pichamber/task',
|
|
118
|
+
bootstrapStatus: { status: 'pending', phase: 'directory-created' },
|
|
119
|
+
};
|
|
120
|
+
gitLibraries.createWorktree.mockResolvedValue(created);
|
|
121
|
+
gitLibraries.getWorktreeBootstrapStatus.mockResolvedValue({ status: 'ready', phase: 'setup-ready' });
|
|
122
|
+
|
|
123
|
+
const createResponse = createMockResponse();
|
|
124
|
+
await getRoute('POST', '/api/git/worktrees')(
|
|
125
|
+
{ query: { directory: '/repo' }, body: { mode: 'new', startRef: 'main' } },
|
|
126
|
+
createResponse,
|
|
127
|
+
);
|
|
128
|
+
expect(createResponse.statusCode).toBe(201);
|
|
129
|
+
expect(createResponse.body).toEqual(created);
|
|
130
|
+
|
|
131
|
+
const statusResponse = createMockResponse();
|
|
132
|
+
await getRoute('GET', '/api/git/worktrees/bootstrap-status')(
|
|
133
|
+
{ query: { directory: '/repo-task' } },
|
|
134
|
+
statusResponse,
|
|
135
|
+
);
|
|
136
|
+
expect(statusResponse.body).toEqual({ status: 'ready', phase: 'setup-ready' });
|
|
70
137
|
});
|
|
71
138
|
|
|
72
139
|
it('accepts legacy stage path payloads', async () => {
|
|
@@ -125,6 +192,74 @@ describe('git routes index mutations', () => {
|
|
|
125
192
|
expect(gitLibraries.unstageFiles).toHaveBeenCalledWith('/repo', ['a.ts', 'b.ts']);
|
|
126
193
|
});
|
|
127
194
|
|
|
195
|
+
it('forwards conditional local-only checkout options', async () => {
|
|
196
|
+
gitLibraries.checkoutBranch.mockResolvedValue({
|
|
197
|
+
success: true,
|
|
198
|
+
branch: 'feature',
|
|
199
|
+
previousBranch: 'main',
|
|
200
|
+
currentBranch: 'feature',
|
|
201
|
+
});
|
|
202
|
+
const { app, getRoute } = createRouteRegistry();
|
|
203
|
+
registerGitRoutes(app);
|
|
204
|
+
const response = createMockResponse();
|
|
205
|
+
|
|
206
|
+
await getRoute('POST', '/api/git/checkout')(
|
|
207
|
+
{
|
|
208
|
+
query: { directory: '/repo' },
|
|
209
|
+
body: { branch: 'feature', expectedCurrent: 'main', localOnly: true },
|
|
210
|
+
},
|
|
211
|
+
response,
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
expect(response.statusCode).toBe(200);
|
|
215
|
+
expect(gitLibraries.checkoutBranch).toHaveBeenCalledWith('/repo', 'feature', {
|
|
216
|
+
expectedCurrent: 'main',
|
|
217
|
+
localOnly: true,
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('rejects malformed checkout preconditions before calling git', async () => {
|
|
222
|
+
const { app, getRoute } = createRouteRegistry();
|
|
223
|
+
registerGitRoutes(app);
|
|
224
|
+
const response = createMockResponse();
|
|
225
|
+
|
|
226
|
+
await getRoute('POST', '/api/git/checkout')(
|
|
227
|
+
{
|
|
228
|
+
query: { directory: '/repo' },
|
|
229
|
+
body: { branch: 'feature', expectedCurrent: 42, localOnly: 'true' },
|
|
230
|
+
},
|
|
231
|
+
response,
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
expect(response.statusCode).toBe(400);
|
|
235
|
+
expect(gitLibraries.checkoutBranch).not.toHaveBeenCalled();
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('returns structured checkout conflicts', async () => {
|
|
239
|
+
gitLibraries.checkoutBranch.mockRejectedValue(Object.assign(
|
|
240
|
+
new Error('The current branch changed.'),
|
|
241
|
+
{ statusCode: 409, code: 'BRANCH_CHANGED', currentBranch: 'release' },
|
|
242
|
+
));
|
|
243
|
+
const { app, getRoute } = createRouteRegistry();
|
|
244
|
+
registerGitRoutes(app);
|
|
245
|
+
const response = createMockResponse();
|
|
246
|
+
|
|
247
|
+
await getRoute('POST', '/api/git/checkout')(
|
|
248
|
+
{
|
|
249
|
+
query: { directory: '/repo' },
|
|
250
|
+
body: { branch: 'feature', expectedCurrent: 'main', localOnly: true },
|
|
251
|
+
},
|
|
252
|
+
response,
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
expect(response.statusCode).toBe(409);
|
|
256
|
+
expect(response.body).toEqual({
|
|
257
|
+
error: 'The current branch changed.',
|
|
258
|
+
code: 'BRANCH_CHANGED',
|
|
259
|
+
currentBranch: 'release',
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
128
263
|
it('rejects invalid path payloads before calling git', async () => {
|
|
129
264
|
const { app, getRoute } = createRouteRegistry();
|
|
130
265
|
registerGitRoutes(app);
|
|
@@ -554,7 +554,7 @@ const cleanBranchName = (branch) => {
|
|
|
554
554
|
return branch;
|
|
555
555
|
};
|
|
556
556
|
|
|
557
|
-
const
|
|
557
|
+
const PICHAMBER_ADJECTIVES = [
|
|
558
558
|
'brave',
|
|
559
559
|
'calm',
|
|
560
560
|
'clever',
|
|
@@ -586,7 +586,7 @@ const OPENCODE_ADJECTIVES = [
|
|
|
586
586
|
'witty',
|
|
587
587
|
];
|
|
588
588
|
|
|
589
|
-
const
|
|
589
|
+
const PICHAMBER_NOUNS = [
|
|
590
590
|
'cabin',
|
|
591
591
|
'cactus',
|
|
592
592
|
'canyon',
|
|
@@ -620,16 +620,11 @@ const OPENCODE_NOUNS = [
|
|
|
620
620
|
'wolf',
|
|
621
621
|
];
|
|
622
622
|
|
|
623
|
-
const
|
|
624
|
-
|
|
625
|
-
const getOpenCodeDataPath = () => {
|
|
626
|
-
const xdgDataHome = process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local', 'share');
|
|
627
|
-
return path.join(xdgDataHome, 'opencode');
|
|
628
|
-
};
|
|
623
|
+
const PICHAMBER_WORKTREE_ATTEMPTS = 26;
|
|
629
624
|
|
|
630
625
|
const pickRandom = (values) => values[Math.floor(Math.random() * values.length)];
|
|
631
626
|
|
|
632
|
-
const
|
|
627
|
+
const generatePiChamberRandomName = () => `${pickRandom(PICHAMBER_ADJECTIVES)}-${pickRandom(PICHAMBER_NOUNS)}`;
|
|
633
628
|
|
|
634
629
|
const slugWorktreeName = (value) => {
|
|
635
630
|
return String(value || '')
|
|
@@ -681,6 +676,21 @@ const parseWorktreePorcelain = (raw) => {
|
|
|
681
676
|
const branchRef = line.substring('branch '.length).trim();
|
|
682
677
|
current.branchRef = branchRef;
|
|
683
678
|
current.branch = cleanBranchName(branchRef);
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
if (line === 'detached') {
|
|
683
|
+
current.detached = true;
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
if (line === 'locked' || line.startsWith('locked ')) {
|
|
688
|
+
current.locked = true;
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
if (line === 'prunable' || line.startsWith('prunable ')) {
|
|
693
|
+
current.prunable = true;
|
|
684
694
|
}
|
|
685
695
|
}
|
|
686
696
|
|
|
@@ -988,8 +998,8 @@ const getFileIdentity = async (filePath) => {
|
|
|
988
998
|
}
|
|
989
999
|
};
|
|
990
1000
|
|
|
991
|
-
// PiChamber places managed worktrees under
|
|
992
|
-
// (`<
|
|
1001
|
+
// PiChamber places managed worktrees under its application data path
|
|
1002
|
+
// (`<PICHAMBER_DATA_DIR>/worktree/<40-char project id>/<name>/`). On
|
|
993
1003
|
// Windows that prefix plus a deeply nested repo file routinely exceeds
|
|
994
1004
|
// MAX_PATH (260). Git can check those paths out when core.longpaths is
|
|
995
1005
|
// enabled; without it, `git reset --hard` during bootstrap fails with
|
|
@@ -1522,9 +1532,9 @@ export async function continueIntegrate(stateInput = {}) {
|
|
|
1522
1532
|
return { kind: 'success', moved: state.remainingCommits.length };
|
|
1523
1533
|
}
|
|
1524
1534
|
|
|
1525
|
-
const
|
|
1535
|
+
const ensurePiChamberProjectId = async (primaryWorktree) => {
|
|
1526
1536
|
const gitDir = path.join(primaryWorktree, '.git');
|
|
1527
|
-
const idFile = path.join(gitDir, '
|
|
1537
|
+
const idFile = path.join(gitDir, 'pichamber');
|
|
1528
1538
|
const existing = await fsp.readFile(idFile, 'utf8').then((value) => value.trim()).catch(() => '');
|
|
1529
1539
|
if (existing) {
|
|
1530
1540
|
return existing;
|
|
@@ -1544,7 +1554,7 @@ const ensureOpenCodeProjectId = async (primaryWorktree) => {
|
|
|
1544
1554
|
|
|
1545
1555
|
const projectId = roots[0] || '';
|
|
1546
1556
|
if (!projectId) {
|
|
1547
|
-
throw new Error('Failed to derive
|
|
1557
|
+
throw new Error('Failed to derive PiChamber project ID');
|
|
1548
1558
|
}
|
|
1549
1559
|
|
|
1550
1560
|
await fsp.mkdir(gitDir, { recursive: true }).catch(() => undefined);
|
|
@@ -1573,11 +1583,10 @@ const resolveWorktreeProjectContext = async (directory) => {
|
|
|
1573
1583
|
);
|
|
1574
1584
|
const commonDir = path.resolve(sandbox, commonResult.stdout.trim());
|
|
1575
1585
|
const primaryWorktree = path.dirname(commonDir);
|
|
1576
|
-
const projectID = await
|
|
1577
|
-
const worktreeRoot =
|
|
1586
|
+
const projectID = await ensurePiChamberProjectId(primaryWorktree);
|
|
1587
|
+
const worktreeRoot = resolvePiChamberDataPath(['worktree', projectID]);
|
|
1578
1588
|
|
|
1579
1589
|
return {
|
|
1580
|
-
projectID,
|
|
1581
1590
|
sandbox,
|
|
1582
1591
|
primaryWorktree,
|
|
1583
1592
|
worktreeRoot,
|
|
@@ -1596,13 +1605,13 @@ const listWorktreeEntries = async (directory) => {
|
|
|
1596
1605
|
const resolveWorktreeNameCandidates = (baseName) => {
|
|
1597
1606
|
const normalizedBase = slugWorktreeName(baseName || '');
|
|
1598
1607
|
if (!normalizedBase) {
|
|
1599
|
-
return Array.from({ length:
|
|
1608
|
+
return Array.from({ length: PICHAMBER_WORKTREE_ATTEMPTS }, () => generatePiChamberRandomName());
|
|
1600
1609
|
}
|
|
1601
|
-
return Array.from({ length:
|
|
1610
|
+
return Array.from({ length: PICHAMBER_WORKTREE_ATTEMPTS }, (_, index) => {
|
|
1602
1611
|
if (index === 0) {
|
|
1603
1612
|
return normalizedBase;
|
|
1604
1613
|
}
|
|
1605
|
-
return `${normalizedBase}-${
|
|
1614
|
+
return `${normalizedBase}-${generatePiChamberRandomName()}`;
|
|
1606
1615
|
});
|
|
1607
1616
|
};
|
|
1608
1617
|
|
|
@@ -1725,26 +1734,6 @@ const runWorktreeStartCommand = async (directory, command) => {
|
|
|
1725
1734
|
return result;
|
|
1726
1735
|
};
|
|
1727
1736
|
|
|
1728
|
-
const loadProjectStartCommand = async (projectID) => {
|
|
1729
|
-
const storagePath = path.join(getOpenCodeDataPath(), 'storage', 'project', `${projectID}.json`);
|
|
1730
|
-
try {
|
|
1731
|
-
const raw = await fsp.readFile(storagePath, 'utf8');
|
|
1732
|
-
const parsed = JSON.parse(raw);
|
|
1733
|
-
const start = typeof parsed?.commands?.start === 'string' ? parsed.commands.start.trim() : '';
|
|
1734
|
-
return start || '';
|
|
1735
|
-
} catch {
|
|
1736
|
-
return '';
|
|
1737
|
-
}
|
|
1738
|
-
};
|
|
1739
|
-
|
|
1740
|
-
// OpenCode owns its own project/sandbox registry. It records a worktree as a
|
|
1741
|
-
// sandbox itself when an instance boots for that directory, and filters entries
|
|
1742
|
-
// whose directory no longer exists when reading them back. PiChamber used to
|
|
1743
|
-
// write that state directly into OpenCode's storage JSON and SQLite database,
|
|
1744
|
-
// behind the back of the running process: the row changed but the server was
|
|
1745
|
-
// never told, so a worktree created while OpenCode was running stayed unknown
|
|
1746
|
-
// to it until a restart. Registration is not ours to perform.
|
|
1747
|
-
|
|
1748
1737
|
const isAttachedGitWorktreeDirectory = async (directory) => {
|
|
1749
1738
|
try {
|
|
1750
1739
|
const result = await runGitCommand(directory, ['rev-parse', '--is-inside-work-tree']);
|
|
@@ -1776,16 +1765,7 @@ const cleanupFailedFastWorktreeCreate = async (context, candidate) => {
|
|
|
1776
1765
|
}
|
|
1777
1766
|
};
|
|
1778
1767
|
|
|
1779
|
-
const runWorktreeStartScripts = async (directory,
|
|
1780
|
-
const projectStart = await loadProjectStartCommand(projectID);
|
|
1781
|
-
if (projectStart) {
|
|
1782
|
-
const projectResult = await runWorktreeStartCommand(directory, projectStart);
|
|
1783
|
-
if (!projectResult.success) {
|
|
1784
|
-
console.warn('Worktree project start command failed:', projectResult.message || projectResult.stderr || projectResult.stdout);
|
|
1785
|
-
return;
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1768
|
+
const runWorktreeStartScripts = async (directory, startCommand) => {
|
|
1789
1769
|
const extraCommand = String(startCommand || '').trim();
|
|
1790
1770
|
if (!extraCommand) {
|
|
1791
1771
|
return;
|
|
@@ -1793,13 +1773,13 @@ const runWorktreeStartScripts = async (directory, projectID, startCommand) => {
|
|
|
1793
1773
|
const extraResult = await runWorktreeStartCommand(directory, extraCommand);
|
|
1794
1774
|
if (!extraResult.success) {
|
|
1795
1775
|
console.warn('Worktree start command failed:', extraResult.message || extraResult.stderr || extraResult.stdout);
|
|
1776
|
+
throw new Error('Worktree setup command failed');
|
|
1796
1777
|
}
|
|
1797
1778
|
};
|
|
1798
1779
|
|
|
1799
1780
|
const queueWorktreeBootstrap = (args) => {
|
|
1800
1781
|
const {
|
|
1801
1782
|
directory,
|
|
1802
|
-
projectID,
|
|
1803
1783
|
primaryWorktree,
|
|
1804
1784
|
localBranch,
|
|
1805
1785
|
setUpstream,
|
|
@@ -1832,9 +1812,7 @@ const queueWorktreeBootstrap = (args) => {
|
|
|
1832
1812
|
WORKTREE_BOOTSTRAP_PENDING,
|
|
1833
1813
|
WORKTREE_BOOTSTRAP_PHASE_GIT_READY
|
|
1834
1814
|
);
|
|
1835
|
-
await runWorktreeStartScripts(directory,
|
|
1836
|
-
console.warn('Worktree start script task failed:', error instanceof Error ? error.message : String(error));
|
|
1837
|
-
});
|
|
1815
|
+
await runWorktreeStartScripts(directory, startCommand);
|
|
1838
1816
|
setWorktreeBootstrapState(
|
|
1839
1817
|
directory,
|
|
1840
1818
|
WORKTREE_BOOTSTRAP_READY,
|
|
@@ -1842,10 +1820,12 @@ const queueWorktreeBootstrap = (args) => {
|
|
|
1842
1820
|
);
|
|
1843
1821
|
})
|
|
1844
1822
|
.catch((error) => {
|
|
1823
|
+
const currentPhase = worktreeBootstrapState.get(toBootstrapStateKey(directory))?.phase
|
|
1824
|
+
?? WORKTREE_BOOTSTRAP_PHASE_DIRECTORY_CREATED;
|
|
1845
1825
|
setWorktreeBootstrapState(
|
|
1846
1826
|
directory,
|
|
1847
1827
|
WORKTREE_BOOTSTRAP_FAILED,
|
|
1848
|
-
|
|
1828
|
+
currentPhase,
|
|
1849
1829
|
error instanceof Error ? error.message : String(error)
|
|
1850
1830
|
);
|
|
1851
1831
|
console.warn('Worktree bootstrap task failed:', error instanceof Error ? error.message : String(error));
|
|
@@ -3522,16 +3502,97 @@ export async function createBranch(directory, branchName, options = {}) {
|
|
|
3522
3502
|
}
|
|
3523
3503
|
}
|
|
3524
3504
|
|
|
3525
|
-
|
|
3526
|
-
|
|
3505
|
+
const branchCheckoutLocks = new Map();
|
|
3506
|
+
|
|
3507
|
+
const readCurrentLocalBranch = async (git) => {
|
|
3508
|
+
const output = await git.raw(['symbolic-ref', '--quiet', '--short', 'HEAD']).catch(() => '');
|
|
3509
|
+
return output.trim() || null;
|
|
3510
|
+
};
|
|
3511
|
+
|
|
3512
|
+
const withBranchCheckoutLock = async (directory, operation) => {
|
|
3513
|
+
const normalized = normalizeDirectoryPath(directory);
|
|
3514
|
+
const key = await canonicalPath(normalized).catch(() => normalized);
|
|
3515
|
+
const previous = branchCheckoutLocks.get(key) ?? Promise.resolve();
|
|
3516
|
+
let release;
|
|
3517
|
+
const current = new Promise((resolve) => { release = resolve; });
|
|
3518
|
+
branchCheckoutLocks.set(key, current);
|
|
3527
3519
|
|
|
3520
|
+
await previous.catch(() => undefined);
|
|
3528
3521
|
try {
|
|
3529
|
-
await
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3522
|
+
return await operation();
|
|
3523
|
+
} finally {
|
|
3524
|
+
release();
|
|
3525
|
+
if (branchCheckoutLocks.get(key) === current) {
|
|
3526
|
+
branchCheckoutLocks.delete(key);
|
|
3527
|
+
}
|
|
3534
3528
|
}
|
|
3529
|
+
};
|
|
3530
|
+
|
|
3531
|
+
const checkoutBranchError = (message, code, statusCode, currentBranch) => Object.assign(
|
|
3532
|
+
new Error(message),
|
|
3533
|
+
{ code, statusCode, currentBranch },
|
|
3534
|
+
);
|
|
3535
|
+
|
|
3536
|
+
export async function checkoutBranch(directory, branchName, options = {}) {
|
|
3537
|
+
const repositoryContext = await createRepositoryGitContext(directory);
|
|
3538
|
+
return withBranchCheckoutLock(repositoryContext.repoRoot, async () => {
|
|
3539
|
+
const { git } = repositoryContext;
|
|
3540
|
+
const previousBranch = await readCurrentLocalBranch(git);
|
|
3541
|
+
const hasExpectedCurrent = Object.prototype.hasOwnProperty.call(options, 'expectedCurrent');
|
|
3542
|
+
|
|
3543
|
+
if (hasExpectedCurrent && previousBranch !== (options.expectedCurrent ?? null)) {
|
|
3544
|
+
throw checkoutBranchError(
|
|
3545
|
+
`The current branch changed from ${options.expectedCurrent ?? 'detached HEAD'} to ${previousBranch ?? 'detached HEAD'}.`,
|
|
3546
|
+
'BRANCH_CHANGED',
|
|
3547
|
+
409,
|
|
3548
|
+
previousBranch,
|
|
3549
|
+
);
|
|
3550
|
+
}
|
|
3551
|
+
|
|
3552
|
+
if (options.localOnly === true) {
|
|
3553
|
+
const localRef = `refs/heads/${branchName}`;
|
|
3554
|
+
const matchingRef = await git.raw(['for-each-ref', '--format=%(refname)', localRef]).catch(() => '');
|
|
3555
|
+
const exists = matchingRef.trim().split('\n').includes(localRef);
|
|
3556
|
+
if (!exists) {
|
|
3557
|
+
throw checkoutBranchError(
|
|
3558
|
+
`Local branch ${branchName} no longer exists.`,
|
|
3559
|
+
'BRANCH_NOT_FOUND',
|
|
3560
|
+
409,
|
|
3561
|
+
previousBranch,
|
|
3562
|
+
);
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
|
|
3566
|
+
try {
|
|
3567
|
+
await git.checkout(branchName);
|
|
3568
|
+
} catch (error) {
|
|
3569
|
+
const currentBranch = await readCurrentLocalBranch(git).catch(() => null);
|
|
3570
|
+
console.error('Failed to checkout branch:', error);
|
|
3571
|
+
if (error && typeof error === 'object') {
|
|
3572
|
+
error.currentBranch = currentBranch;
|
|
3573
|
+
error.code = error.code || 'CHECKOUT_FAILED';
|
|
3574
|
+
error.statusCode = error.statusCode || 409;
|
|
3575
|
+
}
|
|
3576
|
+
throw error;
|
|
3577
|
+
}
|
|
3578
|
+
|
|
3579
|
+
const currentBranch = await readCurrentLocalBranch(git);
|
|
3580
|
+
if (options.localOnly === true && currentBranch !== branchName) {
|
|
3581
|
+
throw checkoutBranchError(
|
|
3582
|
+
`Git did not finish checking out ${branchName}.`,
|
|
3583
|
+
'CHECKOUT_NOT_CONFIRMED',
|
|
3584
|
+
409,
|
|
3585
|
+
currentBranch,
|
|
3586
|
+
);
|
|
3587
|
+
}
|
|
3588
|
+
|
|
3589
|
+
return {
|
|
3590
|
+
success: true,
|
|
3591
|
+
branch: branchName,
|
|
3592
|
+
previousBranch,
|
|
3593
|
+
currentBranch,
|
|
3594
|
+
};
|
|
3595
|
+
});
|
|
3535
3596
|
}
|
|
3536
3597
|
|
|
3537
3598
|
export async function checkoutCommit(directory, hash) {
|
|
@@ -3630,26 +3691,28 @@ export async function resetToCommit(directory, hash, mode, force = false) {
|
|
|
3630
3691
|
export async function getWorktrees(directory) {
|
|
3631
3692
|
const directoryPath = normalizeDirectoryPath(directory);
|
|
3632
3693
|
if (!directoryPath || !fs.existsSync(directoryPath)) {
|
|
3633
|
-
|
|
3634
|
-
}
|
|
3635
|
-
try {
|
|
3636
|
-
const directoryGit = await createGit(directoryPath);
|
|
3637
|
-
const repoRoot = await resolveGitRepositoryRoot(directoryPath, directoryGit);
|
|
3638
|
-
const result = await runGitCommandOrThrow(
|
|
3639
|
-
repoRoot,
|
|
3640
|
-
['worktree', 'list', '--porcelain'],
|
|
3641
|
-
'Failed to list git worktrees'
|
|
3642
|
-
);
|
|
3643
|
-
return parseWorktreePorcelain(result.stdout).map((entry) => ({
|
|
3644
|
-
head: entry.head || '',
|
|
3645
|
-
name: path.basename(entry.worktree || ''),
|
|
3646
|
-
branch: entry.branch || '',
|
|
3647
|
-
path: entry.worktree,
|
|
3648
|
-
}));
|
|
3649
|
-
} catch (error) {
|
|
3650
|
-
console.warn('Failed to list worktrees, returning empty list:', error?.message || error);
|
|
3651
|
-
return [];
|
|
3694
|
+
throw new Error('Git worktree directory does not exist');
|
|
3652
3695
|
}
|
|
3696
|
+
|
|
3697
|
+
const directoryGit = await createGit(directoryPath);
|
|
3698
|
+
const repoRoot = await resolveGitRepositoryRoot(directoryPath, directoryGit);
|
|
3699
|
+
const { root: primaryRoot } = await resolvePrimaryWorktreeRoot(directoryPath);
|
|
3700
|
+
const primaryCanonical = await canonicalPath(primaryRoot);
|
|
3701
|
+
const result = await runGitCommandOrThrow(
|
|
3702
|
+
repoRoot,
|
|
3703
|
+
['worktree', 'list', '--porcelain'],
|
|
3704
|
+
'Failed to list git worktrees'
|
|
3705
|
+
);
|
|
3706
|
+
return Promise.all(parseWorktreePorcelain(result.stdout).map(async (entry) => ({
|
|
3707
|
+
head: entry.head || '',
|
|
3708
|
+
name: path.basename(entry.worktree || ''),
|
|
3709
|
+
branch: entry.detached ? null : (entry.branch || null),
|
|
3710
|
+
path: entry.worktree,
|
|
3711
|
+
isPrimary: await canonicalPath(entry.worktree) === primaryCanonical,
|
|
3712
|
+
detached: entry.detached === true || !entry.branch,
|
|
3713
|
+
locked: entry.locked === true,
|
|
3714
|
+
prunable: entry.prunable === true,
|
|
3715
|
+
})));
|
|
3653
3716
|
}
|
|
3654
3717
|
|
|
3655
3718
|
export async function validateWorktreeCreate(directory, input = {}) {
|
|
@@ -3933,7 +3996,6 @@ async function attachGitWorktreeToCandidate(context, candidate, input = {}) {
|
|
|
3933
3996
|
|
|
3934
3997
|
queueWorktreeBootstrap({
|
|
3935
3998
|
directory: candidate.directory,
|
|
3936
|
-
projectID: context.projectID,
|
|
3937
3999
|
primaryWorktree: context.primaryWorktree,
|
|
3938
4000
|
localBranch,
|
|
3939
4001
|
setUpstream: shouldSetUpstream,
|