@pi-chamber/web 0.3.3 → 0.4.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-0zl1puqf.js +1 -0
- package/dist/assets/DiagramEditor-CFV_TjE2.js +1 -0
- package/dist/assets/DiagramView-0I4PZUpw.js +1 -0
- package/dist/assets/{DiffView-DGD9DMS7.js → DiffView-BoTz2Zqe.js} +2 -2
- package/dist/assets/{FilesView-DB5VI7EN.js → FilesView-CVMNE9Pr.js} +6 -6
- package/dist/assets/GitView-DnsbCAWl.js +6 -0
- package/dist/assets/JsonTreeView-Cn1Mk0Wf.js +1 -0
- package/dist/assets/{MarkdownRendererImpl-V1HMFCjr.js → MarkdownRendererImpl-DJKD8tNq.js} +2 -2
- package/dist/assets/PatchDiff-GdGq3IlM.js +1 -0
- package/dist/assets/PierreDiffViewer-CdkAUt-S.js +136 -0
- package/dist/assets/SessionSwitcherContent-BTzVmIop.js +1 -0
- package/dist/assets/SessionSwitcherDropdown-DuPmnk3k.js +2 -0
- package/dist/assets/SessionUnreadDot-ogHL0INY.js +1 -0
- package/dist/assets/SettingsView-SHhVrRdh.js +4 -0
- package/dist/assets/SettingsWindow-D_D1qqLF.js +1 -0
- package/dist/assets/{ToolOutputDialog-2zKUdGYL.js → ToolOutputDialog-BHaf293m.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-BTMXNcqG.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-UMgLcO4Q.js → VirtualizedFileDiff-CRVvv23V.js} +4 -4
- package/dist/assets/{SessionSwitcherDropdown-o1RjhCfF.js → WindowsWindowControls-CTtxXnD1.js} +172 -123
- package/dist/assets/collapsible-BO4qEdib.js +1 -0
- package/dist/assets/computeVirtualFileMetrics-D1I8YrPV.js +3 -0
- package/dist/assets/contextFileOpenGuard-w5xG9Qz2.js +1 -0
- package/dist/assets/index-3zee2IYy.css +1 -0
- package/dist/assets/{index-BAqpUCjs.js → index-CI-cd-mw.js} +6 -6
- package/dist/assets/index-DbghctxK.js +1 -0
- package/dist/assets/isDiffPlainText-BK9bF1l5.js +1 -0
- package/dist/assets/isFilePlainText-Cua0RCRz.js +1 -0
- package/dist/assets/main-BNJQ6mSF.js +2 -0
- package/dist/assets/{main-CmkRaMOR.js → main-CoA--JT-.js} +6 -6
- package/dist/assets/markdownCore-BGlLZrb8.js +3 -0
- package/dist/assets/miniChat-DU2jFhXq.js +2 -0
- package/dist/assets/mobile-B3lJ_CJR.js +2 -0
- package/dist/assets/renderElectronMiniChatApp-BfXYv3zl.js +2 -0
- package/dist/assets/renderMobileApp-Cd_F7yMe.js +14 -0
- package/dist/assets/{runtimeSurface-CkHYYg0E.js → runtimeSurface-UriLeO95.js} +1 -1
- package/dist/assets/{useInlineCommentController-DD31jQNC.js → useInlineCommentController-5XANmO1k.js} +2 -2
- package/dist/assets/usePanelSlide-CBZw2Cjo.js +56 -0
- package/dist/assets/useSwitcherItems-Cc6Tx-LO.js +1 -0
- package/dist/assets/{useWindowTitle-DoHrUC5r.js → useWindowTitle-Bf8ZNN_R.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-Dp_Z-0GD.js → vendor-codemirror-language-data-DxpwplIe.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-g7DKkne_.js} +4 -4
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -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 +13 -3
- package/server/lib/git/routes.js +80 -4
- package/server/lib/git/routes.test.js +135 -0
- package/server/lib/git/service.js +130 -31
- package/server/lib/git/service.test.js +146 -0
- package/server/lib/pi/routes.js +67 -2
- package/server/lib/pi/routes.test.js +43 -3
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +4 -4
- 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.js +181 -22
- package/server/lib/pi/session-daemon/session-daemon.test.js +123 -3
- 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/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 +18 -2
- 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/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-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
|
@@ -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);
|
|
@@ -681,6 +681,21 @@ const parseWorktreePorcelain = (raw) => {
|
|
|
681
681
|
const branchRef = line.substring('branch '.length).trim();
|
|
682
682
|
current.branchRef = branchRef;
|
|
683
683
|
current.branch = cleanBranchName(branchRef);
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
if (line === 'detached') {
|
|
688
|
+
current.detached = true;
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
if (line === 'locked' || line.startsWith('locked ')) {
|
|
693
|
+
current.locked = true;
|
|
694
|
+
continue;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
if (line === 'prunable' || line.startsWith('prunable ')) {
|
|
698
|
+
current.prunable = true;
|
|
684
699
|
}
|
|
685
700
|
}
|
|
686
701
|
|
|
@@ -1782,7 +1797,7 @@ const runWorktreeStartScripts = async (directory, projectID, startCommand) => {
|
|
|
1782
1797
|
const projectResult = await runWorktreeStartCommand(directory, projectStart);
|
|
1783
1798
|
if (!projectResult.success) {
|
|
1784
1799
|
console.warn('Worktree project start command failed:', projectResult.message || projectResult.stderr || projectResult.stdout);
|
|
1785
|
-
|
|
1800
|
+
throw new Error('Project setup command failed');
|
|
1786
1801
|
}
|
|
1787
1802
|
}
|
|
1788
1803
|
|
|
@@ -1793,6 +1808,7 @@ const runWorktreeStartScripts = async (directory, projectID, startCommand) => {
|
|
|
1793
1808
|
const extraResult = await runWorktreeStartCommand(directory, extraCommand);
|
|
1794
1809
|
if (!extraResult.success) {
|
|
1795
1810
|
console.warn('Worktree start command failed:', extraResult.message || extraResult.stderr || extraResult.stdout);
|
|
1811
|
+
throw new Error('Worktree setup command failed');
|
|
1796
1812
|
}
|
|
1797
1813
|
};
|
|
1798
1814
|
|
|
@@ -1832,9 +1848,7 @@ const queueWorktreeBootstrap = (args) => {
|
|
|
1832
1848
|
WORKTREE_BOOTSTRAP_PENDING,
|
|
1833
1849
|
WORKTREE_BOOTSTRAP_PHASE_GIT_READY
|
|
1834
1850
|
);
|
|
1835
|
-
await runWorktreeStartScripts(directory, projectID, startCommand)
|
|
1836
|
-
console.warn('Worktree start script task failed:', error instanceof Error ? error.message : String(error));
|
|
1837
|
-
});
|
|
1851
|
+
await runWorktreeStartScripts(directory, projectID, startCommand);
|
|
1838
1852
|
setWorktreeBootstrapState(
|
|
1839
1853
|
directory,
|
|
1840
1854
|
WORKTREE_BOOTSTRAP_READY,
|
|
@@ -1842,10 +1856,12 @@ const queueWorktreeBootstrap = (args) => {
|
|
|
1842
1856
|
);
|
|
1843
1857
|
})
|
|
1844
1858
|
.catch((error) => {
|
|
1859
|
+
const currentPhase = worktreeBootstrapState.get(toBootstrapStateKey(directory))?.phase
|
|
1860
|
+
?? WORKTREE_BOOTSTRAP_PHASE_DIRECTORY_CREATED;
|
|
1845
1861
|
setWorktreeBootstrapState(
|
|
1846
1862
|
directory,
|
|
1847
1863
|
WORKTREE_BOOTSTRAP_FAILED,
|
|
1848
|
-
|
|
1864
|
+
currentPhase,
|
|
1849
1865
|
error instanceof Error ? error.message : String(error)
|
|
1850
1866
|
);
|
|
1851
1867
|
console.warn('Worktree bootstrap task failed:', error instanceof Error ? error.message : String(error));
|
|
@@ -3522,16 +3538,97 @@ export async function createBranch(directory, branchName, options = {}) {
|
|
|
3522
3538
|
}
|
|
3523
3539
|
}
|
|
3524
3540
|
|
|
3525
|
-
|
|
3526
|
-
|
|
3541
|
+
const branchCheckoutLocks = new Map();
|
|
3542
|
+
|
|
3543
|
+
const readCurrentLocalBranch = async (git) => {
|
|
3544
|
+
const output = await git.raw(['symbolic-ref', '--quiet', '--short', 'HEAD']).catch(() => '');
|
|
3545
|
+
return output.trim() || null;
|
|
3546
|
+
};
|
|
3527
3547
|
|
|
3548
|
+
const withBranchCheckoutLock = async (directory, operation) => {
|
|
3549
|
+
const normalized = normalizeDirectoryPath(directory);
|
|
3550
|
+
const key = await canonicalPath(normalized).catch(() => normalized);
|
|
3551
|
+
const previous = branchCheckoutLocks.get(key) ?? Promise.resolve();
|
|
3552
|
+
let release;
|
|
3553
|
+
const current = new Promise((resolve) => { release = resolve; });
|
|
3554
|
+
branchCheckoutLocks.set(key, current);
|
|
3555
|
+
|
|
3556
|
+
await previous.catch(() => undefined);
|
|
3528
3557
|
try {
|
|
3529
|
-
await
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3558
|
+
return await operation();
|
|
3559
|
+
} finally {
|
|
3560
|
+
release();
|
|
3561
|
+
if (branchCheckoutLocks.get(key) === current) {
|
|
3562
|
+
branchCheckoutLocks.delete(key);
|
|
3563
|
+
}
|
|
3534
3564
|
}
|
|
3565
|
+
};
|
|
3566
|
+
|
|
3567
|
+
const checkoutBranchError = (message, code, statusCode, currentBranch) => Object.assign(
|
|
3568
|
+
new Error(message),
|
|
3569
|
+
{ code, statusCode, currentBranch },
|
|
3570
|
+
);
|
|
3571
|
+
|
|
3572
|
+
export async function checkoutBranch(directory, branchName, options = {}) {
|
|
3573
|
+
const repositoryContext = await createRepositoryGitContext(directory);
|
|
3574
|
+
return withBranchCheckoutLock(repositoryContext.repoRoot, async () => {
|
|
3575
|
+
const { git } = repositoryContext;
|
|
3576
|
+
const previousBranch = await readCurrentLocalBranch(git);
|
|
3577
|
+
const hasExpectedCurrent = Object.prototype.hasOwnProperty.call(options, 'expectedCurrent');
|
|
3578
|
+
|
|
3579
|
+
if (hasExpectedCurrent && previousBranch !== (options.expectedCurrent ?? null)) {
|
|
3580
|
+
throw checkoutBranchError(
|
|
3581
|
+
`The current branch changed from ${options.expectedCurrent ?? 'detached HEAD'} to ${previousBranch ?? 'detached HEAD'}.`,
|
|
3582
|
+
'BRANCH_CHANGED',
|
|
3583
|
+
409,
|
|
3584
|
+
previousBranch,
|
|
3585
|
+
);
|
|
3586
|
+
}
|
|
3587
|
+
|
|
3588
|
+
if (options.localOnly === true) {
|
|
3589
|
+
const localRef = `refs/heads/${branchName}`;
|
|
3590
|
+
const matchingRef = await git.raw(['for-each-ref', '--format=%(refname)', localRef]).catch(() => '');
|
|
3591
|
+
const exists = matchingRef.trim().split('\n').includes(localRef);
|
|
3592
|
+
if (!exists) {
|
|
3593
|
+
throw checkoutBranchError(
|
|
3594
|
+
`Local branch ${branchName} no longer exists.`,
|
|
3595
|
+
'BRANCH_NOT_FOUND',
|
|
3596
|
+
409,
|
|
3597
|
+
previousBranch,
|
|
3598
|
+
);
|
|
3599
|
+
}
|
|
3600
|
+
}
|
|
3601
|
+
|
|
3602
|
+
try {
|
|
3603
|
+
await git.checkout(branchName);
|
|
3604
|
+
} catch (error) {
|
|
3605
|
+
const currentBranch = await readCurrentLocalBranch(git).catch(() => null);
|
|
3606
|
+
console.error('Failed to checkout branch:', error);
|
|
3607
|
+
if (error && typeof error === 'object') {
|
|
3608
|
+
error.currentBranch = currentBranch;
|
|
3609
|
+
error.code = error.code || 'CHECKOUT_FAILED';
|
|
3610
|
+
error.statusCode = error.statusCode || 409;
|
|
3611
|
+
}
|
|
3612
|
+
throw error;
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3615
|
+
const currentBranch = await readCurrentLocalBranch(git);
|
|
3616
|
+
if (options.localOnly === true && currentBranch !== branchName) {
|
|
3617
|
+
throw checkoutBranchError(
|
|
3618
|
+
`Git did not finish checking out ${branchName}.`,
|
|
3619
|
+
'CHECKOUT_NOT_CONFIRMED',
|
|
3620
|
+
409,
|
|
3621
|
+
currentBranch,
|
|
3622
|
+
);
|
|
3623
|
+
}
|
|
3624
|
+
|
|
3625
|
+
return {
|
|
3626
|
+
success: true,
|
|
3627
|
+
branch: branchName,
|
|
3628
|
+
previousBranch,
|
|
3629
|
+
currentBranch,
|
|
3630
|
+
};
|
|
3631
|
+
});
|
|
3535
3632
|
}
|
|
3536
3633
|
|
|
3537
3634
|
export async function checkoutCommit(directory, hash) {
|
|
@@ -3630,26 +3727,28 @@ export async function resetToCommit(directory, hash, mode, force = false) {
|
|
|
3630
3727
|
export async function getWorktrees(directory) {
|
|
3631
3728
|
const directoryPath = normalizeDirectoryPath(directory);
|
|
3632
3729
|
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 [];
|
|
3730
|
+
throw new Error('Git worktree directory does not exist');
|
|
3652
3731
|
}
|
|
3732
|
+
|
|
3733
|
+
const directoryGit = await createGit(directoryPath);
|
|
3734
|
+
const repoRoot = await resolveGitRepositoryRoot(directoryPath, directoryGit);
|
|
3735
|
+
const { root: primaryRoot } = await resolvePrimaryWorktreeRoot(directoryPath);
|
|
3736
|
+
const primaryCanonical = await canonicalPath(primaryRoot);
|
|
3737
|
+
const result = await runGitCommandOrThrow(
|
|
3738
|
+
repoRoot,
|
|
3739
|
+
['worktree', 'list', '--porcelain'],
|
|
3740
|
+
'Failed to list git worktrees'
|
|
3741
|
+
);
|
|
3742
|
+
return Promise.all(parseWorktreePorcelain(result.stdout).map(async (entry) => ({
|
|
3743
|
+
head: entry.head || '',
|
|
3744
|
+
name: path.basename(entry.worktree || ''),
|
|
3745
|
+
branch: entry.detached ? null : (entry.branch || null),
|
|
3746
|
+
path: entry.worktree,
|
|
3747
|
+
isPrimary: await canonicalPath(entry.worktree) === primaryCanonical,
|
|
3748
|
+
detached: entry.detached === true || !entry.branch,
|
|
3749
|
+
locked: entry.locked === true,
|
|
3750
|
+
prunable: entry.prunable === true,
|
|
3751
|
+
})));
|
|
3653
3752
|
}
|
|
3654
3753
|
|
|
3655
3754
|
export async function validateWorktreeCreate(directory, input = {}) {
|
|
@@ -6,10 +6,12 @@ import { afterEach, describe, expect, it } from 'vitest';
|
|
|
6
6
|
import simpleGit from 'simple-git';
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
|
+
checkoutBranch,
|
|
9
10
|
checkoutCommit,
|
|
10
11
|
cherryPick,
|
|
11
12
|
createWorktree,
|
|
12
13
|
getWorktreeBootstrapStatus,
|
|
14
|
+
getWorktrees,
|
|
13
15
|
getBranches,
|
|
14
16
|
getRangeDiff,
|
|
15
17
|
getRemotes,
|
|
@@ -449,6 +451,36 @@ describe('worktree root resolution', () => {
|
|
|
449
451
|
await expect(resolveWorktreeTopLevel(subdirectory)).resolves.toEqual({ root: fs.realpathSync(repo) });
|
|
450
452
|
});
|
|
451
453
|
|
|
454
|
+
it('lists primary and linked worktrees from either checkout', async () => {
|
|
455
|
+
if (!canRunGit()) return;
|
|
456
|
+
|
|
457
|
+
const repo = createTempDir();
|
|
458
|
+
const worktree = createTempDir();
|
|
459
|
+
runGit(repo, ['init', '-b', 'main']);
|
|
460
|
+
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
|
461
|
+
runGit(repo, ['config', 'user.name', 'Test User']);
|
|
462
|
+
fs.writeFileSync(path.join(repo, 'README.md'), '# Test\n');
|
|
463
|
+
runGit(repo, ['add', 'README.md']);
|
|
464
|
+
runGit(repo, ['commit', '-m', 'Initial commit']);
|
|
465
|
+
fs.rmSync(worktree, { recursive: true, force: true });
|
|
466
|
+
runGit(repo, ['worktree', 'add', '-b', 'feature/test', worktree, 'HEAD']);
|
|
467
|
+
|
|
468
|
+
const listed = await getWorktrees(worktree);
|
|
469
|
+
expect(listed).toHaveLength(2);
|
|
470
|
+
expect(listed.find((entry) => entry.isPrimary)).toMatchObject({
|
|
471
|
+
path: fs.realpathSync(repo),
|
|
472
|
+
branch: 'main',
|
|
473
|
+
detached: false,
|
|
474
|
+
});
|
|
475
|
+
expect(listed.find((entry) => !entry.isPrimary)).toMatchObject({
|
|
476
|
+
path: fs.realpathSync(worktree),
|
|
477
|
+
branch: 'feature/test',
|
|
478
|
+
detached: false,
|
|
479
|
+
locked: false,
|
|
480
|
+
prunable: false,
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
|
|
452
484
|
it('resolves the primary worktree root from a linked worktree', async () => {
|
|
453
485
|
if (!canRunGit()) return;
|
|
454
486
|
|
|
@@ -544,6 +576,47 @@ describe('createWorktree', () => {
|
|
|
544
576
|
}
|
|
545
577
|
});
|
|
546
578
|
|
|
579
|
+
it('reports setup command failure after Git becomes ready', async () => {
|
|
580
|
+
if (!canRunGit()) return;
|
|
581
|
+
|
|
582
|
+
const previousXdgDataHome = process.env.XDG_DATA_HOME;
|
|
583
|
+
const dataHome = createTempDir();
|
|
584
|
+
const setupScript = path.join(dataHome, 'setup-failure.cjs');
|
|
585
|
+
process.env.XDG_DATA_HOME = dataHome;
|
|
586
|
+
fs.writeFileSync(setupScript, 'process.exitCode = 1;\n');
|
|
587
|
+
|
|
588
|
+
try {
|
|
589
|
+
const repo = createTempDir();
|
|
590
|
+
runGit(repo, ['init', '-b', 'main']);
|
|
591
|
+
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
|
592
|
+
runGit(repo, ['config', 'user.name', 'Test User']);
|
|
593
|
+
fs.writeFileSync(path.join(repo, 'README.md'), '# Test\n');
|
|
594
|
+
runGit(repo, ['add', 'README.md']);
|
|
595
|
+
runGit(repo, ['commit', '-m', 'Initial commit']);
|
|
596
|
+
|
|
597
|
+
const created = await createWorktree(repo, {
|
|
598
|
+
mode: 'new',
|
|
599
|
+
branchName: 'feature/setup-failure',
|
|
600
|
+
worktreeName: 'setup-failure',
|
|
601
|
+
returnAfterDirectoryCreated: true,
|
|
602
|
+
startCommand: `${JSON.stringify(process.execPath)} ${JSON.stringify(setupScript)}`,
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
await expect.poll(
|
|
606
|
+
async () => (await getWorktreeBootstrapStatus(created.path)).status,
|
|
607
|
+
{ timeout: 5_000 },
|
|
608
|
+
).toBe('failed');
|
|
609
|
+
await expect(getWorktreeBootstrapStatus(created.path)).resolves.toMatchObject({
|
|
610
|
+
status: 'failed',
|
|
611
|
+
phase: 'git-ready',
|
|
612
|
+
error: 'Worktree setup command failed',
|
|
613
|
+
});
|
|
614
|
+
} finally {
|
|
615
|
+
if (previousXdgDataHome === undefined) delete process.env.XDG_DATA_HOME;
|
|
616
|
+
else process.env.XDG_DATA_HOME = previousXdgDataHome;
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
|
|
547
620
|
const installPostCheckoutHook = (repo, script, executable = true) => {
|
|
548
621
|
const hookPath = path.join(repo, '.git', 'hooks', 'post-checkout');
|
|
549
622
|
fs.writeFileSync(hookPath, script);
|
|
@@ -1168,6 +1241,79 @@ describe('hash validation', () => {
|
|
|
1168
1241
|
});
|
|
1169
1242
|
});
|
|
1170
1243
|
|
|
1244
|
+
describe.runIf(canRunGit())('checkoutBranch', () => {
|
|
1245
|
+
const createBranchRepository = async () => {
|
|
1246
|
+
const { tmpDir, git } = await createTempRepo();
|
|
1247
|
+
fs.writeFileSync(path.join(tmpDir, 'tracked.txt'), 'main\n');
|
|
1248
|
+
await git.add('tracked.txt');
|
|
1249
|
+
await git.commit('main');
|
|
1250
|
+
await git.checkoutLocalBranch('feature');
|
|
1251
|
+
fs.writeFileSync(path.join(tmpDir, 'tracked.txt'), 'feature\n');
|
|
1252
|
+
await git.add('tracked.txt');
|
|
1253
|
+
await git.commit('feature');
|
|
1254
|
+
await git.checkout('main');
|
|
1255
|
+
return { repository: tmpDir, git };
|
|
1256
|
+
};
|
|
1257
|
+
|
|
1258
|
+
it('conditionally checks out an exact local branch and returns the observed branches', async () => {
|
|
1259
|
+
const { repository } = await createBranchRepository();
|
|
1260
|
+
|
|
1261
|
+
await expect(checkoutBranch(repository, 'feature', {
|
|
1262
|
+
expectedCurrent: 'main',
|
|
1263
|
+
localOnly: true,
|
|
1264
|
+
})).resolves.toMatchObject({
|
|
1265
|
+
success: true,
|
|
1266
|
+
branch: 'feature',
|
|
1267
|
+
previousBranch: 'main',
|
|
1268
|
+
currentBranch: 'feature',
|
|
1269
|
+
});
|
|
1270
|
+
expect(runGit(repository, ['branch', '--show-current']).trim()).toBe('feature');
|
|
1271
|
+
});
|
|
1272
|
+
|
|
1273
|
+
it('rejects a stale expected branch without changing the worktree', async () => {
|
|
1274
|
+
const { repository } = await createBranchRepository();
|
|
1275
|
+
|
|
1276
|
+
await expect(checkoutBranch(repository, 'feature', {
|
|
1277
|
+
expectedCurrent: 'release',
|
|
1278
|
+
localOnly: true,
|
|
1279
|
+
})).rejects.toMatchObject({
|
|
1280
|
+
code: 'BRANCH_CHANGED',
|
|
1281
|
+
statusCode: 409,
|
|
1282
|
+
currentBranch: 'main',
|
|
1283
|
+
});
|
|
1284
|
+
expect(runGit(repository, ['branch', '--show-current']).trim()).toBe('main');
|
|
1285
|
+
});
|
|
1286
|
+
|
|
1287
|
+
it('rejects a missing local branch before checkout', async () => {
|
|
1288
|
+
const { repository } = await createBranchRepository();
|
|
1289
|
+
|
|
1290
|
+
await expect(checkoutBranch(repository, 'origin/feature', {
|
|
1291
|
+
expectedCurrent: 'main',
|
|
1292
|
+
localOnly: true,
|
|
1293
|
+
})).rejects.toMatchObject({
|
|
1294
|
+
code: 'BRANCH_NOT_FOUND',
|
|
1295
|
+
statusCode: 409,
|
|
1296
|
+
currentBranch: 'main',
|
|
1297
|
+
});
|
|
1298
|
+
});
|
|
1299
|
+
|
|
1300
|
+
it('preserves the current branch when local changes conflict with checkout', async () => {
|
|
1301
|
+
const { repository } = await createBranchRepository();
|
|
1302
|
+
fs.writeFileSync(path.join(repository, 'tracked.txt'), 'uncommitted main change\n');
|
|
1303
|
+
|
|
1304
|
+
await expect(checkoutBranch(repository, 'feature', {
|
|
1305
|
+
expectedCurrent: 'main',
|
|
1306
|
+
localOnly: true,
|
|
1307
|
+
})).rejects.toMatchObject({
|
|
1308
|
+
code: 'CHECKOUT_FAILED',
|
|
1309
|
+
statusCode: 409,
|
|
1310
|
+
currentBranch: 'main',
|
|
1311
|
+
});
|
|
1312
|
+
expect(runGit(repository, ['branch', '--show-current']).trim()).toBe('main');
|
|
1313
|
+
expect(fs.readFileSync(path.join(repository, 'tracked.txt'), 'utf8')).toBe('uncommitted main change\n');
|
|
1314
|
+
});
|
|
1315
|
+
});
|
|
1316
|
+
|
|
1171
1317
|
describe.runIf(canRunGit())('getBranches', () => {
|
|
1172
1318
|
it('returns a remote default branch whose name is not a conventional fallback', async () => {
|
|
1173
1319
|
const { repository } = createRepositoryWithRemote({ remoteName: 'origin', defaultBranch: 'react' });
|
package/server/lib/pi/routes.js
CHANGED
|
@@ -144,6 +144,23 @@ const projectRetryInfo = (value) => {
|
|
|
144
144
|
};
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
+
const projectCompactionInfo = (value) => {
|
|
148
|
+
if (!value || typeof value !== 'object' || !['running', 'retrying', 'completed', 'failed', 'aborted'].includes(value.phase)) return null;
|
|
149
|
+
return {
|
|
150
|
+
phase: value.phase,
|
|
151
|
+
...(['manual', 'threshold', 'overflow'].includes(value.reason) ? { reason: value.reason } : {}),
|
|
152
|
+
...(Number.isFinite(value.startedAt) && value.startedAt >= 0 ? { startedAt: Math.floor(value.startedAt) } : {}),
|
|
153
|
+
...(Number.isFinite(value.completedAt) && value.completedAt >= 0 ? { completedAt: Math.floor(value.completedAt) } : {}),
|
|
154
|
+
...(Number.isSafeInteger(value.attempt) && value.attempt > 0 ? { attempt: value.attempt } : {}),
|
|
155
|
+
...(Number.isSafeInteger(value.maxAttempts) && value.maxAttempts > 0 ? { maxAttempts: value.maxAttempts } : {}),
|
|
156
|
+
...(Number.isFinite(value.next) && value.next >= 0 ? { next: Math.floor(value.next) } : {}),
|
|
157
|
+
...(Number.isFinite(value.tokensBefore) && value.tokensBefore >= 0 ? { tokensBefore: Math.floor(value.tokensBefore) } : {}),
|
|
158
|
+
...(Number.isFinite(value.estimatedTokensAfter) && value.estimatedTokensAfter >= 0 ? { estimatedTokensAfter: Math.floor(value.estimatedTokensAfter) } : {}),
|
|
159
|
+
...(typeof value.willRetry === 'boolean' ? { willRetry: value.willRetry } : {}),
|
|
160
|
+
...(typeof value.message === 'string' ? { message: value.message } : {}),
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
|
|
147
164
|
const sanitizeNavigation = (value) => {
|
|
148
165
|
if (!value || typeof value !== 'object' || typeof value.targetEntryId !== 'string' || value.targetEntryId.length === 0) return null;
|
|
149
166
|
const previousLeafId = value.previousLeafId === null ? null : (typeof value.previousLeafId === 'string' ? value.previousLeafId : null);
|
|
@@ -212,6 +229,7 @@ const projectSessionDetail = (value) => {
|
|
|
212
229
|
? value.lifecycle
|
|
213
230
|
: (isStreaming ? 'busy' : 'idle');
|
|
214
231
|
const retry = lifecycle === 'retry' ? projectRetryInfo(value.retry) : null;
|
|
232
|
+
const compaction = projectCompactionInfo(value.compaction);
|
|
215
233
|
return {
|
|
216
234
|
session: projectSession(value.session),
|
|
217
235
|
messages,
|
|
@@ -219,6 +237,7 @@ const projectSessionDetail = (value) => {
|
|
|
219
237
|
isStreaming,
|
|
220
238
|
lifecycle,
|
|
221
239
|
...(retry ? { retry } : {}),
|
|
240
|
+
...(compaction ? { compaction } : {}),
|
|
222
241
|
...(Number.isFinite(value.runStartedAt) ? { runStartedAt: Math.floor(value.runStartedAt) } : {}),
|
|
223
242
|
...(Number.isFinite(value.serverNow) ? { serverNow: Math.floor(value.serverNow) } : {}),
|
|
224
243
|
};
|
|
@@ -373,10 +392,12 @@ const projectEventFrame = (frame) => {
|
|
|
373
392
|
const snapshot = frame.payload;
|
|
374
393
|
const lifecycle = ['idle', 'busy', 'retry', 'error', 'interrupted'].includes(snapshot.lifecycle) ? snapshot.lifecycle : 'idle';
|
|
375
394
|
const retry = lifecycle === 'retry' ? projectRetryInfo(snapshot.retry) : null;
|
|
395
|
+
const compaction = projectCompactionInfo(snapshot.compaction);
|
|
376
396
|
return { ...common, payload: { snapshot: {
|
|
377
397
|
sessionId, directory, isStreaming: snapshot.isStreaming === true,
|
|
378
398
|
lifecycle,
|
|
379
399
|
...(retry ? { retry } : {}),
|
|
400
|
+
...(compaction ? { compaction } : {}),
|
|
380
401
|
queue: { steering: Number.isSafeInteger(snapshot.queue?.steering) ? snapshot.queue.steering : 0, followUp: Number.isSafeInteger(snapshot.queue?.followUp) ? snapshot.queue.followUp : 0 },
|
|
381
402
|
...(snapshot.model && typeof snapshot.model.providerId === 'string' && typeof snapshot.model.modelId === 'string' ? { model: { providerId: snapshot.model.providerId, modelId: snapshot.model.modelId } } : {}),
|
|
382
403
|
...(typeof snapshot.thinking === 'string' ? { thinking: snapshot.thinking } : {}),
|
|
@@ -422,7 +443,10 @@ const projectEventFrame = (frame) => {
|
|
|
422
443
|
case 'session.queue': return { ...common, payload: { steering: frame.payload.steering, followUp: frame.payload.followUp } };
|
|
423
444
|
case 'session.model': return { ...common, payload: { model: frame.payload.model } };
|
|
424
445
|
case 'session.thinking': return { ...common, payload: { thinking: frame.payload.thinking } };
|
|
425
|
-
case 'session.compaction':
|
|
446
|
+
case 'session.compaction': {
|
|
447
|
+
const compaction = projectCompactionInfo(frame.payload);
|
|
448
|
+
return compaction ? { ...common, payload: compaction } : null;
|
|
449
|
+
}
|
|
426
450
|
case 'session.error': return {
|
|
427
451
|
...common,
|
|
428
452
|
payload: {
|
|
@@ -487,6 +511,7 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
487
511
|
uiSettingsStore = createPiUiSettingsStore(),
|
|
488
512
|
listCustomThemes = listPiCustomThemes,
|
|
489
513
|
updateChecker = checkForUpdates,
|
|
514
|
+
smallModelGenerator = async (input) => (await import('./small-model-generation.js')).generateWithSmallModel(input),
|
|
490
515
|
}) => {
|
|
491
516
|
app.get('/api/pi/ui-settings', async (_req, res) => {
|
|
492
517
|
try {
|
|
@@ -722,6 +747,36 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
722
747
|
}
|
|
723
748
|
});
|
|
724
749
|
|
|
750
|
+
app.post('/api/pi/small-model/generate', async (req, res) => {
|
|
751
|
+
const source = typeof req.body?.prompt === 'string' ? req.body.prompt.trim() : '';
|
|
752
|
+
const directory = typeof req.body?.directory === 'string' ? req.body.directory.trim() : '';
|
|
753
|
+
if (!source || source.length > 20_000 || !directory) {
|
|
754
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
try {
|
|
758
|
+
const settings = await settingsStore.read();
|
|
759
|
+
const model = settings.smallModel ?? settings.defaultModel;
|
|
760
|
+
const result = await smallModelGenerator({
|
|
761
|
+
directory,
|
|
762
|
+
model,
|
|
763
|
+
prompt: [
|
|
764
|
+
'Create a short task name for a Git worktree and branch.',
|
|
765
|
+
'Return only lowercase ASCII words separated by hyphens.',
|
|
766
|
+
'Use at most 48 characters. Do not include quotes, punctuation, a prefix, or explanation.',
|
|
767
|
+
'',
|
|
768
|
+
source,
|
|
769
|
+
].join('\n'),
|
|
770
|
+
});
|
|
771
|
+
if (!result || typeof result.text !== 'string' || result.text.trim().length === 0) throw protocolMismatch();
|
|
772
|
+
res.json({ text: result.text.trim() });
|
|
773
|
+
} catch (error) {
|
|
774
|
+
const code = typeof error?.code === 'string' ? error.code : 'SMALL_MODEL_FAILED';
|
|
775
|
+
const status = code === 'SMALL_MODEL_UNCONFIGURED' ? 409 : 503;
|
|
776
|
+
res.status(status).json({ error: { code } });
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
|
|
725
780
|
app.get('/api/pi/settings', async (_req, res) => {
|
|
726
781
|
try {
|
|
727
782
|
const pi = projectPiSettings(await getDaemonRuntime(getPiSessionDaemonRuntime).request('settings.get'));
|
|
@@ -977,13 +1032,23 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
977
1032
|
});
|
|
978
1033
|
}
|
|
979
1034
|
|
|
980
|
-
for (const [suffix, command] of [['abort', 'sessions.abort'], ['model', 'sessions.setModel'], ['thinking', 'sessions.setThinking']
|
|
1035
|
+
for (const [suffix, command] of [['abort', 'sessions.abort'], ['model', 'sessions.setModel'], ['thinking', 'sessions.setThinking']]) {
|
|
981
1036
|
app.post(`/api/pi/sessions/:sessionId/${suffix}`, async (req, res) => {
|
|
982
1037
|
const result = await requestSessionOperation(req, res, getPiSessionDaemonRuntime, command, req.body && typeof req.body === 'object' ? req.body : {});
|
|
983
1038
|
if (result !== undefined) res.status(204).end();
|
|
984
1039
|
});
|
|
985
1040
|
}
|
|
986
1041
|
|
|
1042
|
+
app.post('/api/pi/sessions/:sessionId/compact', async (req, res) => {
|
|
1043
|
+
const result = await requestSessionOperation(req, res, getPiSessionDaemonRuntime, 'sessions.compact', req.body && typeof req.body === 'object' ? req.body : {});
|
|
1044
|
+
if (result === undefined) return;
|
|
1045
|
+
if (!result || result.accepted !== true) {
|
|
1046
|
+
writeDaemonError(res, protocolMismatch());
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
res.status(202).json({ accepted: true });
|
|
1050
|
+
});
|
|
1051
|
+
|
|
987
1052
|
app.post('/api/pi/attachments', async (req, res) => {
|
|
988
1053
|
try {
|
|
989
1054
|
const attachment = await attachmentStore.create(req.body ?? {});
|