@pi-chamber/web 1.0.6-rc.3 → 1.0.6-rc.5
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/assets/{DiagramView-Dq5w8TCG.js → DiagramView--XO16VPB.js} +1 -1
- package/dist/assets/DiffView-Duy2_7Gp.js +18 -0
- package/dist/assets/{FileSaveConflictDialog-dFqLbFzT.js → FileSaveConflictDialog-B1DvL9zy.js} +2 -2
- package/dist/assets/FilesView-CjjPpE4c.js +6 -0
- package/dist/assets/{GitHubDetailScaffold-B2HRjT8V.js → GitHubDetailScaffold-DqxAKqCT.js} +4 -4
- package/dist/assets/{GitHubLinkPicker-D7I3J9_O.js → GitHubLinkPicker-ELF_chia.js} +1 -1
- package/dist/assets/GitHubListPrimitives-C2nGTntk.js +1 -0
- package/dist/assets/GitView-5fIq2nzM.js +9 -0
- package/dist/assets/IssuesSurface-Dq5A_bWq.js +7 -0
- package/dist/assets/{JsonTreeView-BJr5kBg4.js → JsonTreeView-BjFFSUwi.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-B9Cu4TCh.js +12 -0
- package/dist/assets/{PatchDiff-B6RBZULC.js → PatchDiff-CTqTTcg7.js} +1 -1
- package/dist/assets/{PierreDiffViewer-YJJQkE7t.js → PierreDiffViewer-H2f4pJ1k.js} +15 -3
- package/dist/assets/PullRequestsSurface-DPpb2RW_.js +2 -0
- package/dist/assets/SessionSwitcherContent-B5DaBWZU.js +1 -0
- package/dist/assets/{SessionSwitcherDropdown-CEAid1Bd.js → SessionSwitcherDropdown-D86FaZg_.js} +2 -2
- package/dist/assets/SessionUnreadDot-CY9-1iV2.js +1 -0
- package/dist/assets/SettingsView-CiIuOi_E.js +6 -0
- package/dist/assets/{SettingsWindow-5dK-buUn.js → SettingsWindow-Bw1dUoJ1.js} +1 -1
- package/dist/assets/{StickyHorizontalScrollbar-p7EbL2-E.js → StickyHorizontalScrollbar-DNsbTLS7.js} +1 -1
- package/dist/assets/{ToolOutputDialog-gITobhpo.js → ToolOutputDialog-aR4kcgKL.js} +5 -5
- package/dist/assets/{ToolPartDiffPreview-nOJxBl-Y.js → ToolPartDiffPreview-B_wWmhtE.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-BmJk6XJm.js → VirtualizedFileDiff-BYby097w.js} +4 -4
- package/dist/assets/{Virtualizer-DNJrJKVb.js → Virtualizer-okhy9Aq3.js} +1 -1
- package/dist/assets/{collapsible-0yfy07W2.js → collapsible-Dz0bPrJ_.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-BCFpa-1q.js → computeVirtualFileMetrics-8MuwxSC6.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-BCi5nTZp.js → contextFileOpenGuard-fZ2NIQMQ.js} +1 -1
- package/dist/assets/fileTreeStatus-BzhMMLA9.js +7 -0
- package/dist/assets/gitStatusPredicates-Cyh9UhYX.js +1 -0
- package/dist/assets/{githubLink-CCmFsyTF.js → githubLink-D2PznPcI.js} +2 -2
- package/dist/assets/{index-BaeFf5Q8.js → index-BX5pAOQX.js} +1 -1
- package/dist/assets/index-Cs2nBW_t.js +11 -0
- package/dist/assets/index-tmO0fZa4.css +1 -0
- package/dist/assets/main-7vBNPBMb.js +137 -0
- package/dist/assets/{main-CgXs2e27.js → main-BI6qe8pz.js} +2 -2
- package/dist/assets/{markdownCore-DTNVLpYS.js → markdownCore-D5jiabKe.js} +1 -1
- package/dist/assets/{miniChat-CrAin_em.js → miniChat-B3up4Bnz.js} +2 -2
- package/dist/assets/{mobile-EK9oTupb.js → mobile-B4vLFgBc.js} +2 -2
- package/dist/assets/{nativeFileSave-Bhafll_7.js → nativeFileSave-DpBH1Sa3.js} +1 -1
- package/dist/assets/{pi-session-focus-preference-BoN1cyoG.js → pi-session-focus-preference-BrB72skF.js} +3 -3
- package/dist/assets/{renderDiffWithHighlighter-DixZh5Zd.js → renderDiffWithHighlighter-B6T04JGG.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-CX10w321.js +2 -0
- package/dist/assets/{renderFileWithHighlighter-s6fQq9eg.js → renderFileWithHighlighter-DtAcGyJr.js} +1 -1
- package/dist/assets/renderMobileApp-C9n-BhPZ.js +11 -0
- package/dist/assets/runtimeEndpointReset-aGyXPXPs.js +62 -0
- package/dist/assets/{runtimeSurface-CJN1oo_1.js → runtimeSurface-DiP2a57a.js} +1 -1
- package/dist/assets/useAppFontEffects-Oyin3dgQ.js +215 -0
- package/dist/assets/useGitHubRemoteSearch-CZ9Hauw0.js +1 -0
- package/dist/assets/useSwitcherItems-BSqDA1IF.js +1 -0
- package/dist/assets/{vendor-aparajita-capacitor-secure-storage-BLsm9T1Y.js → vendor-aparajita-capacitor-secure-storage-DVZvgYu4.js} +1 -1
- package/dist/assets/{vendor-base-ui-C7vVMZTg.js → vendor-base-ui-BCqPBzDj.js} +1 -1
- package/dist/assets/{vendor-boot-CoTxysn6.js → vendor-boot-3SaHYVb1.js} +18 -18
- package/dist/assets/{vendor-capacitor-app-NX6DULfp.js → vendor-capacitor-app-NbQ-WiPS.js} +1 -1
- package/dist/assets/{vendor-capacitor-keyboard-DJD81I9f.js → vendor-capacitor-keyboard-CgrHt8iN.js} +1 -1
- package/dist/assets/{vendor-capacitor-status-bar-DV24OoQV.js → vendor-capacitor-status-bar-CWt0OF5t.js} +1 -1
- package/dist/assets/{vendor-codemirror-autocomplete-qsuH4Dh-.js → vendor-codemirror-autocomplete-WThuuUAz.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-ZHWyBf7j.js → vendor-codemirror-lang-angular-BbLGCxF6.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-pCTOmv-k.js → vendor-codemirror-lang-cpp-Cceks-9O.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-2bFuyM70.js → vendor-codemirror-lang-css-D1wpUg3Z.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-DrG_c7D7.js → vendor-codemirror-lang-go-Cv0zXHHM.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-BV8lrR8v.js → vendor-codemirror-lang-html-DbL8oT9H.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-DrsvH6T2.js → vendor-codemirror-lang-java-CNugenuC.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-Dkzl3s07.js → vendor-codemirror-lang-javascript-Bx_FIyZF.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-jinja-8Nn3bnoP.js → vendor-codemirror-lang-jinja-DDGjB3Zq.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-CsdmtHhi.js → vendor-codemirror-lang-json-DIvqf9Pb.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-DJuZ4cZe.js → vendor-codemirror-lang-less-D8r9dGG1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-D2RO-Pzr.js → vendor-codemirror-lang-liquid-B24mguYi.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-C0Zu3b3n.js → vendor-codemirror-lang-markdown-v3yG2sbf.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-CuDtt2Zj.js → vendor-codemirror-lang-php-BcZGalqy.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-Cv2exx_M.js → vendor-codemirror-lang-python-b-JqEwQy.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-C4TxJ6Rg.js → vendor-codemirror-lang-rust-B1uZxDW-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-BmtPz8kf.js → vendor-codemirror-lang-sass-DqPrngKp.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-BF1ZaXqJ.js → vendor-codemirror-lang-sql-UyCnpt-k.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-DZgXrP2k.js → vendor-codemirror-lang-vue-xDwYkovV.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-DsnaGtL_.js → vendor-codemirror-lang-wast-CF3169p_.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-D8DzzFat.js → vendor-codemirror-lang-xml-FCtVhuOb.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-D5hBv7m6.js → vendor-codemirror-lang-yaml-g0sPmAnv.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-vn2RyN9T.js → vendor-codemirror-language-data-B03xgzP2.js} +2 -2
- package/dist/assets/{vendor-codemirror-search-BVCYIV0D.js → vendor-codemirror-search-Dw3Wpu15.js} +1 -1
- package/dist/assets/{vendor-lezer-cpp-vqXSn3lv.js → vendor-lezer-cpp-Cu3E-KUI.js} +1 -1
- package/dist/assets/{vendor-lezer-css-JnEzSyZR.js → vendor-lezer-css-Cb8vp67u.js} +1 -1
- package/dist/assets/{vendor-lezer-go-dD2gQMIL.js → vendor-lezer-go-BTsIaOm7.js} +1 -1
- package/dist/assets/{vendor-lezer-html-Cr3U-1pu.js → vendor-lezer-html-UQMsUwj-.js} +1 -1
- package/dist/assets/{vendor-lezer-java-CRM0IMCo.js → vendor-lezer-java-BIWrFrAx.js} +1 -1
- package/dist/assets/{vendor-lezer-javascript-B3s21DIS.js → vendor-lezer-javascript-BH2Etgoy.js} +1 -1
- package/dist/assets/{vendor-lezer-json-DPFM6EBV.js → vendor-lezer-json-CE-QUCwM.js} +1 -1
- package/dist/assets/{vendor-lezer-lr-Bllrq8hY.js → vendor-lezer-lr-HY6Yc0Vr.js} +1 -1
- package/dist/assets/{vendor-lezer-markdown-6-3PLvXG.js → vendor-lezer-markdown-xFL3Evwf.js} +1 -1
- package/dist/assets/{vendor-lezer-php-DOyzfHRl.js → vendor-lezer-php-Cr_mQGrG.js} +1 -1
- package/dist/assets/{vendor-lezer-python-CdHdN5qt.js → vendor-lezer-python-BNRFWCb0.js} +1 -1
- package/dist/assets/{vendor-lezer-rust-CqnW8EMH.js → vendor-lezer-rust-BvfOK5cU.js} +1 -1
- package/dist/assets/{vendor-lezer-sass-BbcF4y6A.js → vendor-lezer-sass-qoxiLisk.js} +1 -1
- package/dist/assets/{vendor-lezer-xml-C31AyWoo.js → vendor-lezer-xml--x8SSpqU.js} +1 -1
- package/dist/assets/{vendor-lezer-yaml-Cv908yC2.js → vendor-lezer-yaml-BDo1JaEr.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-Cwhyn_5f.js → vendor-replit-codemirror-vim-D1Fe7FiY.js} +1 -1
- package/dist/assets/{web-components-Bz5oGa3p.js → web-components-CkTNGkJ2.js} +4 -4
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/lib/git/DOCUMENTATION.md +1 -0
- package/server/lib/git/routes.js +14 -0
- package/server/lib/git/routes.test.js +37 -0
- package/server/lib/git/service.js +27 -0
- package/server/lib/git/service.test.js +32 -0
- package/server/lib/pi/archive-store.js +38 -10
- package/server/lib/pi/archive-store.test.js +10 -0
- package/server/lib/pi/routes.js +107 -2
- package/server/lib/pi/routes.test.js +255 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +5 -1
- package/server/lib/pi/session-daemon/session-daemon-engines.test.js +18 -0
- package/server/lib/pi/session-daemon/session-daemon.js +24 -1
- package/server/lib/pi/session-shelf-store.js +252 -0
- package/server/lib/pi/session-shelf-store.test.js +174 -0
- package/server/lib/pi/ui-settings-store.js +60 -0
- package/server/lib/pi/ui-settings-store.test.js +105 -6
- package/dist/assets/DiffView-CFIjN2zy.js +0 -18
- package/dist/assets/FilesView-D0b2mEKA.js +0 -6
- package/dist/assets/GitHubListPrimitives-Dw5LAmzm.js +0 -1
- package/dist/assets/GitView-Dhr7qVeI.js +0 -9
- package/dist/assets/IssuesSurface-Bya7OsRl.js +0 -7
- package/dist/assets/MarkdownRendererImpl-DadkFPCz.js +0 -12
- package/dist/assets/PullRequestsSurface-D8JpzP5l.js +0 -2
- package/dist/assets/SessionSwitcherContent-CJ6C2ZKG.js +0 -1
- package/dist/assets/SessionUnreadDot-I1_tmqY9.js +0 -1
- package/dist/assets/SettingsView-B-b76XDV.js +0 -6
- package/dist/assets/gitStatusPredicates-BQOqDJU1.js +0 -1
- package/dist/assets/index-C2ISrmRR.js +0 -11
- package/dist/assets/index-DgwThEwf.css +0 -1
- package/dist/assets/main-DoVzQV56.js +0 -137
- package/dist/assets/renderElectronMiniChatApp-0MqKeGfI.js +0 -2
- package/dist/assets/renderMobileApp-BLoXL_J8.js +0 -11
- package/dist/assets/runtimeEndpointReset-Bv2Y1fMm.js +0 -62
- package/dist/assets/useAppFontEffects-D2xXdmYC.js +0 -215
- package/dist/assets/useFilesViewSearch-BKotcAUN.js +0 -7
- package/dist/assets/useGitHubRemoteSearch-CZ92xKSw.js +0 -1
- package/dist/assets/useSwitcherItems-BfA4omGb.js +0 -1
package/dist/mini-chat.html
CHANGED
|
@@ -89,15 +89,15 @@
|
|
|
89
89
|
}
|
|
90
90
|
</style>
|
|
91
91
|
|
|
92
|
-
<script type="module" crossorigin src="/assets/miniChat-
|
|
92
|
+
<script type="module" crossorigin src="/assets/miniChat-B3up4Bnz.js"></script>
|
|
93
93
|
<link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
|
|
94
94
|
<link rel="modulepreload" crossorigin href="/assets/vendor-react-Bz1tRBxM.js">
|
|
95
95
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zustand-CXhN0IMY.js">
|
|
96
96
|
<link rel="modulepreload" crossorigin href="/assets/vendor-clsx-B-dksMZM.js">
|
|
97
97
|
<link rel="modulepreload" crossorigin href="/assets/vendor-tailwind-merge-BKkUfl9q.js">
|
|
98
98
|
<link rel="modulepreload" crossorigin href="/assets/vendor-fuse.js-t_7AcMTv.js">
|
|
99
|
-
<link rel="modulepreload" crossorigin href="/assets/index-
|
|
100
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
99
|
+
<link rel="modulepreload" crossorigin href="/assets/index-Cs2nBW_t.js">
|
|
100
|
+
<link rel="stylesheet" crossorigin href="/assets/index-tmO0fZa4.css">
|
|
101
101
|
<link rel="stylesheet" crossorigin href="/assets/vendor-katex-css-Cp579UoJ.css">
|
|
102
102
|
</head>
|
|
103
103
|
<body class="h-full bg-background text-foreground">
|
package/dist/mobile.html
CHANGED
|
@@ -63,15 +63,15 @@
|
|
|
63
63
|
})();
|
|
64
64
|
</script>
|
|
65
65
|
|
|
66
|
-
<script type="module" crossorigin src="/assets/mobile-
|
|
66
|
+
<script type="module" crossorigin src="/assets/mobile-B4vLFgBc.js"></script>
|
|
67
67
|
<link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
|
|
68
68
|
<link rel="modulepreload" crossorigin href="/assets/vendor-react-Bz1tRBxM.js">
|
|
69
69
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zustand-CXhN0IMY.js">
|
|
70
70
|
<link rel="modulepreload" crossorigin href="/assets/vendor-clsx-B-dksMZM.js">
|
|
71
71
|
<link rel="modulepreload" crossorigin href="/assets/vendor-tailwind-merge-BKkUfl9q.js">
|
|
72
72
|
<link rel="modulepreload" crossorigin href="/assets/vendor-fuse.js-t_7AcMTv.js">
|
|
73
|
-
<link rel="modulepreload" crossorigin href="/assets/index-
|
|
74
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
73
|
+
<link rel="modulepreload" crossorigin href="/assets/index-Cs2nBW_t.js">
|
|
74
|
+
<link rel="stylesheet" crossorigin href="/assets/index-tmO0fZa4.css">
|
|
75
75
|
<link rel="stylesheet" crossorigin href="/assets/vendor-katex-css-Cp579UoJ.css">
|
|
76
76
|
</head>
|
|
77
77
|
<body class="h-full bg-background text-foreground">
|
package/package.json
CHANGED
|
@@ -31,6 +31,7 @@ The following functions are exported and used by the web server:
|
|
|
31
31
|
### Repository Operations
|
|
32
32
|
- `isGitRepository(directory)`: Check if a directory is a Git repository.
|
|
33
33
|
- `getCurrentIdentity(directory)`: Read-only read of the local Git `user.name`/`user.email` (falling back to global when unset). Never writes config.
|
|
34
|
+
- `initRepository(directory)`: Run `git init` in an existing folder. Returns `{ created: true }`, or `{ created: false }` without running git when the folder already holds its own `.git` (a parent repository does not count). Throws for a missing path or a file. Exposed as `POST /api/git/init?directory=…`, which answers failures with 400; the Add folder dialog's new-project step calls it after creating the folder.
|
|
34
35
|
- `getRemoteUrl(directory, remoteName)`: Get URL for a specific remote.
|
|
35
36
|
|
|
36
37
|
### Status and Diff Operations
|
package/server/lib/git/routes.js
CHANGED
|
@@ -57,6 +57,20 @@ export function registerGitRoutes(app) {
|
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
+
app.post('/api/git/init', async (req, res) => {
|
|
61
|
+
const { initRepository } = await getGitLibraries();
|
|
62
|
+
try {
|
|
63
|
+
const directory = resolveDirectoryQuery(req.query.directory);
|
|
64
|
+
if (!directory) {
|
|
65
|
+
return res.status(400).json({ error: 'directory parameter is required' });
|
|
66
|
+
}
|
|
67
|
+
res.json(await initRepository(directory));
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error('Failed to initialize git repository:', error);
|
|
70
|
+
res.status(400).json({ error: error.message || 'Failed to initialize Git repository' });
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
60
74
|
app.get('/api/git/remote-url', async (req, res) => {
|
|
61
75
|
const { getRemoteUrl } = await getGitLibraries();
|
|
62
76
|
try {
|
|
@@ -13,6 +13,7 @@ const gitLibraries = {
|
|
|
13
13
|
getWorktreeBootstrapStatus: vi.fn(),
|
|
14
14
|
getDiff: vi.fn(),
|
|
15
15
|
resolveDiffSource: vi.fn(),
|
|
16
|
+
initRepository: vi.fn(),
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
vi.mock('./index.js', () => ({
|
|
@@ -28,6 +29,7 @@ vi.mock('./index.js', () => ({
|
|
|
28
29
|
getWorktreeBootstrapStatus: gitLibraries.getWorktreeBootstrapStatus,
|
|
29
30
|
getDiff: gitLibraries.getDiff,
|
|
30
31
|
resolveDiffSource: gitLibraries.resolveDiffSource,
|
|
32
|
+
initRepository: gitLibraries.initRepository,
|
|
31
33
|
}));
|
|
32
34
|
|
|
33
35
|
const { registerGitRoutes } = await import('./routes.js');
|
|
@@ -464,3 +466,38 @@ describe('git routes diff', () => {
|
|
|
464
466
|
expect(gitLibraries.getDiff).not.toHaveBeenCalled();
|
|
465
467
|
});
|
|
466
468
|
});
|
|
469
|
+
|
|
470
|
+
describe('git routes init', () => {
|
|
471
|
+
beforeEach(() => {
|
|
472
|
+
gitLibraries.initRepository.mockReset();
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it('initializes the folder named by the directory query', async () => {
|
|
476
|
+
const { app, getRoute } = createRouteRegistry();
|
|
477
|
+
registerGitRoutes(app);
|
|
478
|
+
gitLibraries.initRepository.mockResolvedValue({ created: true });
|
|
479
|
+
const response = createMockResponse();
|
|
480
|
+
|
|
481
|
+
await getRoute('POST', '/api/git/init')({ query: { directory: '/projects/demo' } }, response);
|
|
482
|
+
|
|
483
|
+
expect(gitLibraries.initRepository).toHaveBeenCalledWith('/projects/demo');
|
|
484
|
+
expect(response.statusCode).toBe(200);
|
|
485
|
+
expect(response.body).toEqual({ created: true });
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it('requires a directory and reports failures instead of success', async () => {
|
|
489
|
+
const { app, getRoute } = createRouteRegistry();
|
|
490
|
+
registerGitRoutes(app);
|
|
491
|
+
|
|
492
|
+
const missing = createMockResponse();
|
|
493
|
+
await getRoute('POST', '/api/git/init')({ query: {} }, missing);
|
|
494
|
+
expect(missing.statusCode).toBe(400);
|
|
495
|
+
expect(gitLibraries.initRepository).not.toHaveBeenCalled();
|
|
496
|
+
|
|
497
|
+
gitLibraries.initRepository.mockRejectedValueOnce(new Error('Folder does not exist'));
|
|
498
|
+
const failed = createMockResponse();
|
|
499
|
+
await getRoute('POST', '/api/git/init')({ query: { directory: '/nope' } }, failed);
|
|
500
|
+
expect(failed.statusCode).toBe(400);
|
|
501
|
+
expect(failed.body).toEqual({ error: 'Folder does not exist' });
|
|
502
|
+
});
|
|
503
|
+
});
|
|
@@ -1932,6 +1932,33 @@ export async function isGitRepository(directory) {
|
|
|
1932
1932
|
return result.success;
|
|
1933
1933
|
}
|
|
1934
1934
|
|
|
1935
|
+
/**
|
|
1936
|
+
* Makes an existing folder a Git repository. A folder that already holds its
|
|
1937
|
+
* own `.git` is left alone (`created: false`), so a retry after a partial
|
|
1938
|
+
* failure is safe. Only the folder's own `.git` counts: a new project inside
|
|
1939
|
+
* another repository's tree still gets a repository of its own.
|
|
1940
|
+
*/
|
|
1941
|
+
export async function initRepository(directory) {
|
|
1942
|
+
const directoryPath = normalizeDirectoryPath(directory);
|
|
1943
|
+
if (!directoryPath) {
|
|
1944
|
+
throw new Error('Folder path is required');
|
|
1945
|
+
}
|
|
1946
|
+
let stats;
|
|
1947
|
+
try {
|
|
1948
|
+
stats = await fs.promises.stat(directoryPath);
|
|
1949
|
+
} catch {
|
|
1950
|
+
throw new Error('Folder does not exist');
|
|
1951
|
+
}
|
|
1952
|
+
if (!stats.isDirectory()) {
|
|
1953
|
+
throw new Error('Path is not a folder');
|
|
1954
|
+
}
|
|
1955
|
+
if (fs.existsSync(path.join(directoryPath, '.git'))) {
|
|
1956
|
+
return { created: false };
|
|
1957
|
+
}
|
|
1958
|
+
await runGitCommandOrThrow(directoryPath, ['init'], 'Failed to initialize Git repository');
|
|
1959
|
+
return { created: true };
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1935
1962
|
export async function getRemoteUrl(directory, remoteName = 'origin') {
|
|
1936
1963
|
const git = await createGit(directory);
|
|
1937
1964
|
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
getDiff,
|
|
32
32
|
getFileDiff,
|
|
33
33
|
resolveDiffSource,
|
|
34
|
+
initRepository,
|
|
34
35
|
} from './service.js';
|
|
35
36
|
|
|
36
37
|
// ---------------------------------------------------------------------------
|
|
@@ -1500,3 +1501,34 @@ describe.runIf(canRunGit())('getRangeDiff', () => {
|
|
|
1500
1501
|
expect(diff).toContain('feature.txt');
|
|
1501
1502
|
});
|
|
1502
1503
|
});
|
|
1504
|
+
|
|
1505
|
+
describe.skipIf(!canRunGit())('initRepository', () => {
|
|
1506
|
+
it('makes a plain folder a repository and leaves an existing one alone', async () => {
|
|
1507
|
+
const folder = createTempDir();
|
|
1508
|
+
|
|
1509
|
+
expect(await initRepository(folder)).toEqual({ created: true });
|
|
1510
|
+
expect(fs.existsSync(path.join(folder, '.git'))).toBe(true);
|
|
1511
|
+
expect(await isGitRepository(folder)).toBe(true);
|
|
1512
|
+
|
|
1513
|
+
expect(await initRepository(folder)).toEqual({ created: false });
|
|
1514
|
+
});
|
|
1515
|
+
|
|
1516
|
+
it('gives a folder inside another repository its own repository', async () => {
|
|
1517
|
+
const parent = createTempDir();
|
|
1518
|
+
runGit(parent, ['init']);
|
|
1519
|
+
const child = path.join(parent, 'new-project');
|
|
1520
|
+
fs.mkdirSync(child);
|
|
1521
|
+
|
|
1522
|
+
expect(await initRepository(child)).toEqual({ created: true });
|
|
1523
|
+
expect(fs.existsSync(path.join(child, '.git'))).toBe(true);
|
|
1524
|
+
});
|
|
1525
|
+
|
|
1526
|
+
it('rejects a missing path and a file', async () => {
|
|
1527
|
+
const folder = createTempDir();
|
|
1528
|
+
const file = path.join(folder, 'notes.txt');
|
|
1529
|
+
fs.writeFileSync(file, 'x');
|
|
1530
|
+
|
|
1531
|
+
await expect(initRepository(path.join(folder, 'missing'))).rejects.toThrow('Folder does not exist');
|
|
1532
|
+
await expect(initRepository(file)).rejects.toThrow('Path is not a folder');
|
|
1533
|
+
});
|
|
1534
|
+
});
|
|
@@ -10,6 +10,12 @@ const invalidArchive = () => {
|
|
|
10
10
|
return error;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
const invalidArgument = () => {
|
|
14
|
+
const error = new Error('The archive request is invalid.');
|
|
15
|
+
error.code = 'INVALID_ARGUMENT';
|
|
16
|
+
return error;
|
|
17
|
+
};
|
|
18
|
+
|
|
13
19
|
/**
|
|
14
20
|
* PiChamber-owned archive metadata. Pi JSONL remains untouched: the sidecar is
|
|
15
21
|
* keyed only by opaque Pi session IDs and every write is atomic.
|
|
@@ -29,25 +35,47 @@ export const createPiArchiveStore = ({ file = join(resolvePiChamberDataDir(), 'p
|
|
|
29
35
|
}
|
|
30
36
|
};
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
error.code = 'INVALID_ARGUMENT';
|
|
36
|
-
throw error;
|
|
37
|
-
}
|
|
38
|
+
// Serializes writes in this process and across processes sharing the data
|
|
39
|
+
// directory. `change` edits the current map in place.
|
|
40
|
+
const mutate = (change) => {
|
|
38
41
|
const operation = writeChain.then(() => withCrossProcessLock(`${file}.lock`, async () => {
|
|
39
42
|
const current = await read();
|
|
40
|
-
|
|
41
|
-
else delete current[sessionId];
|
|
43
|
+
const result = change(current);
|
|
42
44
|
await mkdir(dirname(file), { recursive: true, mode: 0o700 });
|
|
43
45
|
const temporary = `${file}.tmp`;
|
|
44
46
|
await writeFile(temporary, JSON.stringify(current), { mode: 0o600 });
|
|
45
47
|
await rename(temporary, file);
|
|
46
|
-
return
|
|
48
|
+
return result;
|
|
47
49
|
}));
|
|
48
50
|
writeChain = operation.catch(() => {});
|
|
49
51
|
return operation;
|
|
50
52
|
};
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
const set = async (sessionId, archived) => {
|
|
55
|
+
if (typeof sessionId !== 'string' || sessionId.length === 0 || typeof archived !== 'boolean') throw invalidArgument();
|
|
56
|
+
return mutate((current) => {
|
|
57
|
+
if (archived) current[sessionId] = Date.now();
|
|
58
|
+
else delete current[sessionId];
|
|
59
|
+
return archived ? current[sessionId] : undefined;
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Archive each `{ sessionId: archivedAt }` that is not archived yet, at the
|
|
65
|
+
* given time. Sessions already archived keep their time. Used by the
|
|
66
|
+
* one-time settled-shelf migration.
|
|
67
|
+
*/
|
|
68
|
+
const archiveMissing = async (entries) => {
|
|
69
|
+
if (!entries || typeof entries !== 'object' || Array.isArray(entries)) throw invalidArgument();
|
|
70
|
+
const list = Object.entries(entries);
|
|
71
|
+
if (list.some(([sessionId, at]) => sessionId.length === 0 || !Number.isSafeInteger(at) || at <= 0)) throw invalidArgument();
|
|
72
|
+
if (list.length === 0) return;
|
|
73
|
+
await mutate((current) => {
|
|
74
|
+
for (const [sessionId, at] of list) {
|
|
75
|
+
if (!Object.hasOwn(current, sessionId)) current[sessionId] = at;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return { read, set, archiveMissing };
|
|
53
81
|
};
|
|
@@ -29,4 +29,14 @@ describe('Pi archive sidecar', () => {
|
|
|
29
29
|
await writeFile(file, 'not-json');
|
|
30
30
|
await expect(archive.read()).rejects.toMatchObject({ code: 'ARCHIVE_METADATA_INVALID' });
|
|
31
31
|
});
|
|
32
|
+
|
|
33
|
+
it('archives missing sessions at given times without moving existing archive times', async () => {
|
|
34
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-archive-'));
|
|
35
|
+
const archive = createPiArchiveStore({ file: join(root, 'pi', 'session-archive.json') });
|
|
36
|
+
await archive.set('kept', true);
|
|
37
|
+
const keptAt = (await archive.read()).kept;
|
|
38
|
+
await archive.archiveMissing({ kept: 5, added: 7 });
|
|
39
|
+
await expect(archive.read()).resolves.toEqual({ kept: keptAt, added: 7 });
|
|
40
|
+
await expect(archive.archiveMissing({ bad: -1 })).rejects.toMatchObject({ code: 'INVALID_ARGUMENT' });
|
|
41
|
+
});
|
|
32
42
|
});
|
package/server/lib/pi/routes.js
CHANGED
|
@@ -17,6 +17,7 @@ import { readUpdateJob } from '../update-job-store.js';
|
|
|
17
17
|
import { createPiSettingsStore } from './settings-store.js';
|
|
18
18
|
import { isPiThinkingLevel } from './thinking-levels.js';
|
|
19
19
|
import { createPiSessionFoldersStore } from './session-folders-store.js';
|
|
20
|
+
import { createPiSessionShelfStore } from './session-shelf-store.js';
|
|
20
21
|
import {
|
|
21
22
|
MAX_EXTENSION_APP_HTML_CHARS,
|
|
22
23
|
isValidCustomInputItems,
|
|
@@ -60,6 +61,7 @@ const UNAVAILABLE_CODES = new Set([
|
|
|
60
61
|
'MALFORMED_SESSION_JSONL',
|
|
61
62
|
'SESSION_JSONL_UNREADABLE',
|
|
62
63
|
'ARCHIVE_METADATA_INVALID',
|
|
64
|
+
'SESSION_SHELF_INVALID',
|
|
63
65
|
]);
|
|
64
66
|
|
|
65
67
|
const BAD_GATEWAY_CODES = new Set([
|
|
@@ -938,6 +940,11 @@ export const projectEventFrame = (frame) => {
|
|
|
938
940
|
const level = ['info', 'warning', 'error'].includes(frame.payload.level) ? frame.payload.level : 'info';
|
|
939
941
|
return { ...common, payload: { message: frame.payload.message.slice(0, 2000), level } };
|
|
940
942
|
}
|
|
943
|
+
case 'session.archive': {
|
|
944
|
+
// An archive mark changed on the server; devices re-list the folder.
|
|
945
|
+
if (typeof frame.payload.archived !== 'boolean') return null;
|
|
946
|
+
return { ...common, payload: { archived: frame.payload.archived } };
|
|
947
|
+
}
|
|
941
948
|
case 'session.openUrl': {
|
|
942
949
|
// An Open request (lib/open-url). `serverNow` is stamped at delivery so
|
|
943
950
|
// a device can tell a live request from a replayed one using only the
|
|
@@ -1119,6 +1126,7 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
1119
1126
|
attachmentStore = createPiAttachmentStore(),
|
|
1120
1127
|
settingsStore = createPiSettingsStore(),
|
|
1121
1128
|
sessionFoldersStore = createPiSessionFoldersStore(),
|
|
1129
|
+
sessionShelfStore = createPiSessionShelfStore({ archiveStore }),
|
|
1122
1130
|
uiSettingsStore = createPiUiSettingsStore(),
|
|
1123
1131
|
snippetsStore = createPiSnippetsStore(),
|
|
1124
1132
|
listCustomThemes = listPiCustomThemes,
|
|
@@ -1132,6 +1140,42 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
1132
1140
|
eventStreamMaxBufferedBytes = DEFAULT_EVENT_STREAM_MAX_BUFFERED_BYTES,
|
|
1133
1141
|
}) => {
|
|
1134
1142
|
const eventStreamRegistry = createPiEventStreamRegistry();
|
|
1143
|
+
// Tell every device an archive mark changed (a `session.archive` event on
|
|
1144
|
+
// the session's stream) so other clients re-list that folder. The change is
|
|
1145
|
+
// already saved, so this never delays or fails the request: an older
|
|
1146
|
+
// daemon without `archive.publish` only logs, and devices catch up on
|
|
1147
|
+
// their next list.
|
|
1148
|
+
const publishArchiveChange = (sessionId, archived, directory) => {
|
|
1149
|
+
void (async () => {
|
|
1150
|
+
try {
|
|
1151
|
+
await getDaemonRuntime(getPiSessionDaemonRuntime).request('archive.publish', {
|
|
1152
|
+
sessionId,
|
|
1153
|
+
archived,
|
|
1154
|
+
...(typeof directory === 'string' && directory.length > 0 ? { directory } : {}),
|
|
1155
|
+
});
|
|
1156
|
+
} catch (error) {
|
|
1157
|
+
console.warn('[pi] could not tell other devices about an archive change', error?.code ?? error);
|
|
1158
|
+
}
|
|
1159
|
+
})();
|
|
1160
|
+
};
|
|
1161
|
+
// A message or command the user sends ends a snooze and unarchives the
|
|
1162
|
+
// session. The send already succeeded, so a failed write only logs.
|
|
1163
|
+
const bringBackForActivity = async (sessionId) => {
|
|
1164
|
+
try {
|
|
1165
|
+
await sessionShelfStore.clearForActivity(sessionId);
|
|
1166
|
+
} catch (error) {
|
|
1167
|
+
console.warn('[pi] could not clear the session shelf after a send', error?.code ?? error);
|
|
1168
|
+
}
|
|
1169
|
+
try {
|
|
1170
|
+
const archived = await archiveStore.read();
|
|
1171
|
+
if (Object.hasOwn(archived, sessionId)) {
|
|
1172
|
+
await archiveStore.set(sessionId, false);
|
|
1173
|
+
publishArchiveChange(sessionId, false);
|
|
1174
|
+
}
|
|
1175
|
+
} catch (error) {
|
|
1176
|
+
console.warn('[pi] could not unarchive a session after a send', error?.code ?? error);
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1135
1179
|
app.get('/api/pi/ui-settings', async (_req, res) => {
|
|
1136
1180
|
try {
|
|
1137
1181
|
res.json(await uiSettingsStore.read());
|
|
@@ -2006,7 +2050,64 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
2006
2050
|
|
|
2007
2051
|
app.delete('/api/pi/sessions/:sessionId', async (req, res) => {
|
|
2008
2052
|
const result = await requestSessionOperation(req, res, getPiSessionDaemonRuntime, 'sessions.delete');
|
|
2009
|
-
if (result
|
|
2053
|
+
if (result === undefined) return;
|
|
2054
|
+
try {
|
|
2055
|
+
await sessionShelfStore.remove(req.params.sessionId);
|
|
2056
|
+
} catch (error) {
|
|
2057
|
+
console.warn('[pi] could not remove a deleted session from the shelf', error?.code ?? error);
|
|
2058
|
+
}
|
|
2059
|
+
res.status(204).end();
|
|
2060
|
+
});
|
|
2061
|
+
|
|
2062
|
+
app.get('/api/pi/session-shelf', async (_req, res) => {
|
|
2063
|
+
try {
|
|
2064
|
+
res.json({ sessions: await sessionShelfStore.read() });
|
|
2065
|
+
} catch (error) {
|
|
2066
|
+
writeDaemonError(res, error);
|
|
2067
|
+
}
|
|
2068
|
+
});
|
|
2069
|
+
|
|
2070
|
+
app.post('/api/pi/sessions/:sessionId/shelf', async (req, res) => {
|
|
2071
|
+
const { sessionId } = req.params;
|
|
2072
|
+
const body = req.body && typeof req.body === 'object' ? req.body : {};
|
|
2073
|
+
const directory = typeof body.directory === 'string' && body.directory.length > 0 ? body.directory : undefined;
|
|
2074
|
+
// Older clients (the Settle release candidate) may still send `settled`:
|
|
2075
|
+
// 'settled' archives the session; 'active' and null do nothing. Remove
|
|
2076
|
+
// this mapping one release after Archive replaced Settle.
|
|
2077
|
+
const hasSettled = Object.hasOwn(body, 'settled');
|
|
2078
|
+
const hasSnooze = Object.hasOwn(body, 'snoozedUntil');
|
|
2079
|
+
const settledValid = !hasSettled || body.settled === null || body.settled === 'settled' || body.settled === 'active';
|
|
2080
|
+
const snoozeValid = !hasSnooze || body.snoozedUntil === null
|
|
2081
|
+
|| (Number.isSafeInteger(body.snoozedUntil) && body.snoozedUntil > 0);
|
|
2082
|
+
if (!sessionId || (!hasSettled && !hasSnooze) || !settledValid || !snoozeValid) {
|
|
2083
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
try {
|
|
2087
|
+
// Same membership check as archive: shelf state is PiChamber metadata
|
|
2088
|
+
// for a session that exists, not a Pi session mutation.
|
|
2089
|
+
const result = await getDaemonRuntime(getPiSessionDaemonRuntime).request(
|
|
2090
|
+
'sessions.list',
|
|
2091
|
+
directory ? { directory } : undefined,
|
|
2092
|
+
);
|
|
2093
|
+
const items = projectSessionList(result?.sessions);
|
|
2094
|
+
const item = items.find((candidate) => candidate.session.id === sessionId);
|
|
2095
|
+
if (!item) {
|
|
2096
|
+
const error = new Error('The Pi session does not exist.');
|
|
2097
|
+
error.code = 'INVALID_SESSION';
|
|
2098
|
+
throw error;
|
|
2099
|
+
}
|
|
2100
|
+
if (hasSettled && body.settled === 'settled') {
|
|
2101
|
+
await archiveStore.set(sessionId, true);
|
|
2102
|
+
publishArchiveChange(sessionId, true, item.session.directory || directory);
|
|
2103
|
+
}
|
|
2104
|
+
const entry = hasSnooze
|
|
2105
|
+
? await sessionShelfStore.update(sessionId, { snoozedUntil: body.snoozedUntil })
|
|
2106
|
+
: (await sessionShelfStore.read())[sessionId] ?? null;
|
|
2107
|
+
res.json({ entry });
|
|
2108
|
+
} catch (error) {
|
|
2109
|
+
writeDaemonError(res, error);
|
|
2110
|
+
}
|
|
2010
2111
|
});
|
|
2011
2112
|
|
|
2012
2113
|
app.post('/api/pi/sessions/:sessionId/archive', async (req, res) => {
|
|
@@ -2025,12 +2126,14 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
2025
2126
|
directory ? { directory } : undefined,
|
|
2026
2127
|
);
|
|
2027
2128
|
const items = projectSessionList(result?.sessions);
|
|
2028
|
-
|
|
2129
|
+
const item = items.find((candidate) => candidate.session.id === sessionId);
|
|
2130
|
+
if (!item) {
|
|
2029
2131
|
const error = new Error('The Pi session does not exist.');
|
|
2030
2132
|
error.code = 'INVALID_SESSION';
|
|
2031
2133
|
throw error;
|
|
2032
2134
|
}
|
|
2033
2135
|
await archiveStore.set(sessionId, archived);
|
|
2136
|
+
publishArchiveChange(sessionId, archived, item.session.directory || directory);
|
|
2034
2137
|
res.status(204).end();
|
|
2035
2138
|
} catch (error) {
|
|
2036
2139
|
writeDaemonError(res, error);
|
|
@@ -2220,6 +2323,7 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
2220
2323
|
return;
|
|
2221
2324
|
}
|
|
2222
2325
|
await attachmentStore.consume?.(attachmentIds);
|
|
2326
|
+
await bringBackForActivity(req.params.sessionId);
|
|
2223
2327
|
res.status(202).json({
|
|
2224
2328
|
accepted: true,
|
|
2225
2329
|
messageId: result.messageId,
|
|
@@ -2294,6 +2398,7 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
2294
2398
|
writeDaemonError(res, protocolMismatch());
|
|
2295
2399
|
return;
|
|
2296
2400
|
}
|
|
2401
|
+
await bringBackForActivity(req.params.sessionId);
|
|
2297
2402
|
res.status(202).json({ accepted: true, id: result.id });
|
|
2298
2403
|
});
|
|
2299
2404
|
|