@pi-chamber/web 0.9.4 → 0.9.6
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 +15 -0
- package/dist/assets/DiagramView-0Iq1ak1I.js +1 -0
- package/dist/assets/{DiffView-CBOrV4hS.js → DiffView-DD1AFRi3.js} +2 -2
- package/dist/assets/FileSaveConflictDialog-CoKwDovb.js +3 -0
- package/dist/assets/FilesView-B_BF39ef.js +6 -0
- package/dist/assets/GitView-LFEpCasf.js +8 -0
- package/dist/assets/{JsonTreeView-CKWGm5MS.js → JsonTreeView-Cwjgvh4g.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-_7kV1yNw.js +12 -0
- package/dist/assets/PatchDiff-DG43C1HW.js +1 -0
- package/dist/assets/{SessionSwitcherContent-z9VYCXrT.js → SessionSwitcherContent-DCFXPY3d.js} +1 -1
- package/dist/assets/SessionSwitcherDropdown-QY7FKuEQ.js +2 -0
- package/dist/assets/SessionUnreadDot-DGT31A3z.js +1 -0
- package/dist/assets/SettingsView-eG-wN-yY.js +2 -0
- package/dist/assets/SettingsWindow-Dvnp8YrA.js +1 -0
- package/dist/assets/ToolOutputDialog-IlCrS6BR.js +8 -0
- package/dist/assets/ToolPartDiffPreview-D68JV0rR.js +1 -0
- package/dist/assets/{VirtualizedFileDiff-DfaXovGB.js → VirtualizedFileDiff-Bl-rAYeh.js} +3 -3
- package/dist/assets/collapsible-BjniCdZ5.js +1 -0
- package/dist/assets/computeVirtualFileMetrics-FSOm2VrW.js +3 -0
- package/dist/assets/contextFileOpenGuard-Bxb6AIPa.js +1 -0
- package/dist/assets/gitStatusPredicates-DxolDpMd.js +134 -0
- package/dist/assets/index-BpmGBboM.css +1 -0
- package/dist/assets/index-DZnzXhTs.js +8 -0
- package/dist/assets/index-Dh58uD3I.js +1 -0
- package/dist/assets/isDiffPlainText-D3_04XCh.js +1 -0
- package/dist/assets/isFilePlainText-CHouYQhH.js +1 -0
- package/dist/assets/{main-DG1oZ0Wj.js → main-CH3EqGJI.js} +2 -2
- package/dist/assets/main-HzTrVvbB.js +135 -0
- package/dist/assets/{markdownCore-DUjQU2i0.js → markdownCore-DJU4KvHP.js} +2 -2
- package/dist/assets/{miniChat-BEAtOkr9.js → miniChat-Ca3TpaaA.js} +2 -2
- package/dist/assets/{mobile-DOFBBQg2.js → mobile-lj4gpGsO.js} +2 -2
- package/dist/assets/renderElectronMiniChatApp-rUFfaD-T.js +2 -0
- package/dist/assets/renderMobileApp-CcWQ1sCf.js +11 -0
- package/dist/assets/runtimeEndpointReset-D2MmSbDk.js +53 -0
- package/dist/assets/{runtimeSurface-CySRuLbN.js → runtimeSurface-CE_VNjdH.js} +1 -1
- package/dist/assets/{useAppFontEffects-C4JL1x7k.js → useAppFontEffects-BvFAP9zG.js} +102 -103
- package/dist/assets/useFilesViewSearch-BD79p3A2.js +7 -0
- package/dist/assets/usePushVisibilityBeacon-CWg0j-Wg.js +10 -0
- package/dist/assets/useSwitcherItems-CazJ6Yox.js +1 -0
- package/dist/assets/{vendor-base-ui-vkqQ2P9o.js → vendor-base-ui-CdaWtC7e.js} +1 -1
- package/dist/assets/vendor-beautiful-mermaid-D3YCkKz7.js +111 -0
- package/dist/assets/{vendor-codemirror-commands-DYppkHEk.js → vendor-codemirror-commands-CNlncqrr.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-C493X_9w.js → vendor-codemirror-language-data-CP3j3-xu.js} +2 -2
- package/dist/assets/{vendor-replit-codemirror-vim-CGHHNQxC.js → vendor-replit-codemirror-vim-DaSwPsXt.js} +1 -1
- package/dist/assets/{web-components-B2Rw__yK.js → web-components-DWuadqra.js} +3 -3
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +2 -2
- package/server/lib/fs/DOCUMENTATION.md +15 -3
- package/server/lib/fs/routes.js +369 -51
- package/server/lib/fs/routes.test.js +565 -3
- package/server/lib/fs/search.js +74 -29
- package/server/lib/pi/routes.js +56 -3
- package/server/lib/pi/routes.test.js +165 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +19 -6
- package/server/lib/pi/session-daemon/prompt-operations.test.js +151 -3
- package/server/lib/pi/session-daemon/prompt-preflight.test.js +556 -0
- package/server/lib/pi/session-daemon/sdk-upgrade.test.js +157 -0
- package/server/lib/pi/session-daemon/send-operation-dedup.test.js +331 -0
- package/server/lib/pi/session-daemon/send-operation-registry.js +264 -0
- package/server/lib/pi/session-daemon/send-operation-registry.test.js +205 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.e2e.test.js +16 -5
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +3 -1
- package/server/lib/pi/session-daemon/session-daemon.js +514 -107
- package/server/lib/pi/session-daemon/session-daemon.test.js +37 -13
- package/server/lib/pi/session-daemon/session-idle-residency.test.js +749 -0
- package/server/lib/pi/session-daemon/session-replay.js +98 -0
- package/server/lib/pi/session-daemon/session-replay.test.js +628 -0
- package/server/lib/pi/ui-settings-store.js +16 -10
- package/server/lib/pi/ui-settings-store.test.js +91 -0
- package/server/lib/server/cors.js +6 -0
- package/server/lib/server/cors.test.js +3 -0
- package/server/lib/stt/DOCUMENTATION.md +1 -1
- package/server/lib/stt/local/worker-client.js +11 -3
- package/server/lib/stt/local/worker-client.test.js +255 -0
- package/server/lib/workspace/host.js +6 -2
- package/server/lib/workspace/host.test.js +15 -0
- package/dist/assets/DiagramEditor-DuGmiPZ5.js +0 -1
- package/dist/assets/DiagramView-CHy1Glsl.js +0 -1
- package/dist/assets/FilesView-CK2YVs_W.js +0 -6
- package/dist/assets/GitView-BEFLOv_7.js +0 -8
- package/dist/assets/MarkdownRendererImpl-hE_nmSqe.js +0 -12
- package/dist/assets/PatchDiff-BagRxMON.js +0 -1
- package/dist/assets/SessionSwitcherDropdown-icxJk_lT.js +0 -2
- package/dist/assets/SessionUnreadDot-Bv-5KguB.js +0 -1
- package/dist/assets/SettingsView-Ck0qxtKP.js +0 -2
- package/dist/assets/SettingsWindow-GQRL2CdD.js +0 -1
- package/dist/assets/ToolOutputDialog-CxJUXVZW.js +0 -8
- package/dist/assets/ToolPartDiffPreview-BXuLRWHT.js +0 -1
- package/dist/assets/collapsible-szfZ0Syc.js +0 -1
- package/dist/assets/computeVirtualFileMetrics-DG_E6iaN.js +0 -3
- package/dist/assets/contextFileOpenGuard-DPBE3ELv.js +0 -1
- package/dist/assets/gitStatusPredicates-OljV4Bb2.js +0 -134
- package/dist/assets/index-DNoEeZ2U.css +0 -1
- package/dist/assets/index-DmexVlTQ.js +0 -1
- package/dist/assets/index-KIdiBFJs.js +0 -8
- package/dist/assets/isDiffPlainText-aikgiqLb.js +0 -1
- package/dist/assets/isFilePlainText-D-Dl6LqX.js +0 -1
- package/dist/assets/main-BXdraZTZ.js +0 -135
- package/dist/assets/renderElectronMiniChatApp-B0K72YnS.js +0 -2
- package/dist/assets/renderMobileApp-Ca_BO_s4.js +0 -11
- package/dist/assets/runtimeEndpointReset-Cx2tsgTo.js +0 -54
- package/dist/assets/useFilesViewSearch-Du0DnmKs.js +0 -7
- package/dist/assets/usePushVisibilityBeacon-BnHxIv4r.js +0 -10
- package/dist/assets/useSwitcherItems-C91mwPJD.js +0 -1
- package/dist/assets/vendor-beautiful-mermaid-DneUawHp.js +0 -119
package/dist/mini-chat.html
CHANGED
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
}
|
|
90
90
|
</style>
|
|
91
91
|
|
|
92
|
-
<script type="module" crossorigin src="/assets/miniChat-
|
|
92
|
+
<script type="module" crossorigin src="/assets/miniChat-Ca3TpaaA.js"></script>
|
|
93
93
|
<link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
|
|
94
94
|
<link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
|
|
95
95
|
<link rel="modulepreload" crossorigin href="/assets/vendor-react-B5Z1Mdn3.js">
|
|
@@ -97,9 +97,9 @@
|
|
|
97
97
|
<link rel="modulepreload" crossorigin href="/assets/vendor-clsx-B-dksMZM.js">
|
|
98
98
|
<link rel="modulepreload" crossorigin href="/assets/vendor-tailwind-merge-CPcsbTWB.js">
|
|
99
99
|
<link rel="modulepreload" crossorigin href="/assets/vendor-fuse.js-Dw8P0qyA.js">
|
|
100
|
-
<link rel="modulepreload" crossorigin href="/assets/index-
|
|
100
|
+
<link rel="modulepreload" crossorigin href="/assets/index-DZnzXhTs.js">
|
|
101
101
|
<link rel="modulepreload" crossorigin href="/assets/vendor-katex-CNckGUMB.js">
|
|
102
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
102
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BpmGBboM.css">
|
|
103
103
|
<link rel="stylesheet" crossorigin href="/assets/vendor-katex-Cp579UoJ.css">
|
|
104
104
|
</head>
|
|
105
105
|
<body class="h-full bg-background text-foreground">
|
package/dist/mobile.html
CHANGED
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
})();
|
|
64
64
|
</script>
|
|
65
65
|
|
|
66
|
-
<script type="module" crossorigin src="/assets/mobile-
|
|
66
|
+
<script type="module" crossorigin src="/assets/mobile-lj4gpGsO.js"></script>
|
|
67
67
|
<link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
|
|
68
68
|
<link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
|
|
69
69
|
<link rel="modulepreload" crossorigin href="/assets/vendor-react-B5Z1Mdn3.js">
|
|
@@ -71,9 +71,9 @@
|
|
|
71
71
|
<link rel="modulepreload" crossorigin href="/assets/vendor-clsx-B-dksMZM.js">
|
|
72
72
|
<link rel="modulepreload" crossorigin href="/assets/vendor-tailwind-merge-CPcsbTWB.js">
|
|
73
73
|
<link rel="modulepreload" crossorigin href="/assets/vendor-fuse.js-Dw8P0qyA.js">
|
|
74
|
-
<link rel="modulepreload" crossorigin href="/assets/index-
|
|
74
|
+
<link rel="modulepreload" crossorigin href="/assets/index-DZnzXhTs.js">
|
|
75
75
|
<link rel="modulepreload" crossorigin href="/assets/vendor-katex-CNckGUMB.js">
|
|
76
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
76
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BpmGBboM.css">
|
|
77
77
|
<link rel="stylesheet" crossorigin href="/assets/vendor-katex-Cp579UoJ.css">
|
|
78
78
|
</head>
|
|
79
79
|
<body class="h-full bg-background text-foreground">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-chamber/web",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@clack/prompts": "^1.1.0",
|
|
31
|
-
"@earendil-works/pi-coding-agent": "0.
|
|
31
|
+
"@earendil-works/pi-coding-agent": "0.85.1",
|
|
32
32
|
"@octokit/rest": "^22.0.1",
|
|
33
33
|
"@simplewebauthn/server": "13.3.1",
|
|
34
34
|
"adm-zip": "^0.6.0",
|
|
@@ -5,7 +5,7 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
|
|
|
5
5
|
|
|
6
6
|
## Entrypoints and structure
|
|
7
7
|
- `packages/web/server/lib/fs/routes.js`: route registration and runtime-owned state for `/api/fs/*` endpoints.
|
|
8
|
-
- `packages/web/server/lib/fs/search.js`: fuzzy filesystem search runtime used by
|
|
8
|
+
- `packages/web/server/lib/fs/search.js`: bounded-concurrency fuzzy filesystem search runtime used by `GET /api/fs/find`.
|
|
9
9
|
|
|
10
10
|
## Public exports
|
|
11
11
|
- `registerFsRoutes(app, dependencies)` from `routes.js`
|
|
@@ -14,6 +14,7 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
|
|
|
14
14
|
- `POST /api/fs/mkdir`
|
|
15
15
|
- `POST /api/fs/clone`
|
|
16
16
|
- `GET /api/fs/read`
|
|
17
|
+
- `GET /api/fs/stat`
|
|
17
18
|
- `GET /api/fs/raw`
|
|
18
19
|
- `GET /api/fs/serve/:path(*)`
|
|
19
20
|
- `POST /api/fs/write`
|
|
@@ -23,11 +24,22 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
|
|
|
23
24
|
- `POST /api/fs/exec`
|
|
24
25
|
- `GET /api/fs/exec/:jobId`
|
|
25
26
|
- `GET /api/fs/list`
|
|
27
|
+
- `GET /api/fs/find`
|
|
26
28
|
- Owns exec job queue state (`execJobs`) and lifecycle/TTL pruning.
|
|
27
29
|
- Enforces workspace boundary checks with active project + worktree fallback support. An explicit `directory` query is authoritative over a stale runtime directory header, which lets user-confirmed directory-browser operations and project-local optional configuration probes scope themselves to the selected directory. `optional=true` converts only a missing file to an empty success; it never bypasses workspace policy.
|
|
28
|
-
- `createFsSearchRuntime({ fsPromises, path, spawn, resolveGitBinaryForSpawn })` from `search.js`
|
|
30
|
+
- `createFsSearchRuntime({ fsPromises, path, spawn, resolveGitBinaryForSpawn, gitCheckIgnoreTimeoutMs })` from `search.js`
|
|
29
31
|
- Returns `{ searchFilesystemFiles(rootPath, options) }`.
|
|
30
|
-
- Supports fuzzy matching, hidden-file handling, and optional `git check-ignore` filtering.
|
|
32
|
+
- Supports fuzzy file and directory matching, hidden-file handling, fixed build-output exclusions, and optional `git check-ignore` filtering.
|
|
33
|
+
- Git-ignore checks use bounded directory concurrency and a positive configurable timeout (`PICHAMBER_GIT_CHECK_IGNORE_TIMEOUT_MS`, default 2500 ms). Concurrent searches share identical in-flight checks. A failed or timed-out check fails the search instead of returning files that may be ignored.
|
|
34
|
+
- Search reads through canonical paths for boundary enforcement, but result paths stay in the caller's requested path space so symlinked workspaces remain navigable.
|
|
35
|
+
|
|
36
|
+
## File-save revisions (finding #8)
|
|
37
|
+
- Revisions are opaque exact strings (`v1:<size>:<mtimeMs>[:<sha256>]`, 5 MiB hash ceiling). `null` means missing at read time; `undefined` means legacy/unknown and never guards a save.
|
|
38
|
+
- `GET /api/fs/read` returns `x-pichamber-file-revision` plus `Cache-Control: no-store`; optional missing reads also return `x-pichamber-file-exists: false`. The server CORS policy exposes both headers so HMR, packaged desktop, and Capacitor clients retain revision authority across origins.
|
|
39
|
+
- `GET /api/fs/stat` returns `{ revision, exists }` and accepts `?knownRevision=` to echo the client revision when size+mtime (and hash-ceiling category) match, skipping read+hash.
|
|
40
|
+
- `POST /api/fs/write` accepts `{ expectedRevision, overwrite }`. Omitting `expectedRevision` keeps legacy unconditional writes. `expectedRevision: null` (or `'missing'`) is create-only. `overwrite: true` is the explicit force path. Mismatches return HTTP 409 `{ reason: 'file-revision-conflict', currentRevision, exists, path }`. Identical content is an idempotent `{ noop: true }` success without rewrite. Writes serialize per canonical (realpath) file with re-keying for create/re-point races, preserve mode across atomic temp+rename, and never normalize line endings.
|
|
41
|
+
- External writers that bypass the protocol are non-cooperating: last writer wins on disk, and the next cooperating save conflicts instead of silently overwriting.
|
|
42
|
+
- The exact `~` global-session sentinel resolves to the server user's home directory before workspace validation. Other relative paths keep normal server-cwd resolution.
|
|
31
43
|
|
|
32
44
|
## Composition contract with `index.js`
|
|
33
45
|
- `index.js` provides composition-time dependencies only (platform primitives + callbacks such as `resolveProjectDirectory`, `normalizeDirectoryPath`, and `buildAugmentedPath`).
|
package/server/lib/fs/routes.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createRealpathCache } from '../path-realpath-cache.js';
|
|
2
2
|
import nodeFsPromises from 'node:fs/promises';
|
|
3
3
|
import nodePath from 'node:path';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
4
5
|
import { resolvePiChamberDataDir } from '../pichamber-data-dir.js';
|
|
5
6
|
import { createFsSearchRuntime } from './search.js';
|
|
6
7
|
import { pickHostDirectory } from './pick-directory.js';
|
|
@@ -29,6 +30,155 @@ const sendOsPermissionDenied = (res, message) => (
|
|
|
29
30
|
res.status(403).json({ error: message, reason: 'os-permission' })
|
|
30
31
|
);
|
|
31
32
|
|
|
33
|
+
// File-save revision protocol (finding #8).
|
|
34
|
+
//
|
|
35
|
+
// Cooperating PiChamber writers attach the opaque `expectedRevision` they read
|
|
36
|
+
// to every save. The server serializes compare+atomic-replace per canonical
|
|
37
|
+
// file so two writers with the same base revision cannot both win: the first
|
|
38
|
+
// commits, the second receives a typed 409 `file-revision-conflict` with the
|
|
39
|
+
// current revision and re-reads before retrying.
|
|
40
|
+
//
|
|
41
|
+
// Revision format is opaque to clients (exact string compare only):
|
|
42
|
+
// `v1:<size>:<mtimeMs>:<sha256hex>` for hashed text, or
|
|
43
|
+
// `v1:<size>:<mtimeMs>` when content exceeds the hash ceiling.
|
|
44
|
+
// A missing file has revision `null` on the wire; `expectedRevision: null`
|
|
45
|
+
// (or the literal `'missing'`) means "create only". `overwrite: true` is
|
|
46
|
+
// the explicit force path that bypasses the check. Omitting
|
|
47
|
+
// `expectedRevision` preserves legacy unconditional writes for older clients
|
|
48
|
+
// and non-editor callers.
|
|
49
|
+
//
|
|
50
|
+
// External processes that write without this protocol are non-cooperating:
|
|
51
|
+
// check and replace cannot be atomic against them. Last writer still wins on
|
|
52
|
+
// disk; the next cooperating save observes a revision mismatch and conflicts
|
|
53
|
+
// instead of silently overwriting. See DOCUMENTATION.md.
|
|
54
|
+
const FILE_REVISION_PREFIX = 'v1';
|
|
55
|
+
const FILE_REVISION_MISSING_LITERAL = 'missing';
|
|
56
|
+
const FILE_REVISION_HASH_MAX_BYTES = 5 * 1024 * 1024;
|
|
57
|
+
const FILE_REVISION_HEADER = 'x-pichamber-file-revision';
|
|
58
|
+
|
|
59
|
+
const fileWriteLocks = new Map();
|
|
60
|
+
|
|
61
|
+
// Canonical write-lock key. Locking on the pre-realpath workspace path would
|
|
62
|
+
// let symlink aliases of the same file bypass serialization, so key on the
|
|
63
|
+
// realpath target instead. For a missing target (create-only writes) walk up
|
|
64
|
+
// to the deepest existing ancestor so aliases of the same missing file still
|
|
65
|
+
// share one key; the write body re-keys inside the lock when the target
|
|
66
|
+
// appears or is re-pointed between key resolution and lock acquisition.
|
|
67
|
+
const canonicalFileWriteLockKey = async (fsPromises, path, target) => {
|
|
68
|
+
try {
|
|
69
|
+
return await fsPromises.realpath(target);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (!error || typeof error !== 'object' || error.code !== 'ENOENT') {
|
|
72
|
+
return path.resolve(target);
|
|
73
|
+
}
|
|
74
|
+
let current = target;
|
|
75
|
+
const segments = [];
|
|
76
|
+
for (;;) {
|
|
77
|
+
const parent = path.dirname(current);
|
|
78
|
+
if (parent === current) return path.resolve(target);
|
|
79
|
+
segments.unshift(path.basename(current));
|
|
80
|
+
try {
|
|
81
|
+
const realParent = await fsPromises.realpath(parent);
|
|
82
|
+
return path.join(realParent, ...segments);
|
|
83
|
+
} catch (parentError) {
|
|
84
|
+
if (parentError && typeof parentError === 'object' && parentError.code === 'ENOENT') {
|
|
85
|
+
current = parent;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
return path.resolve(target);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const withFileWriteLock = (key, fn) => {
|
|
95
|
+
const previous = fileWriteLocks.get(key) || Promise.resolve();
|
|
96
|
+
const next = previous.then(fn, fn);
|
|
97
|
+
const tracked = next.catch(() => {});
|
|
98
|
+
fileWriteLocks.set(key, tracked);
|
|
99
|
+
void tracked.finally(() => {
|
|
100
|
+
if (fileWriteLocks.get(key) === tracked) {
|
|
101
|
+
fileWriteLocks.delete(key);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return next;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const hashBytes = (buffer) => {
|
|
108
|
+
try {
|
|
109
|
+
return createHash('sha256').update(buffer).digest('hex');
|
|
110
|
+
} catch {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const buildFileRevision = ({ size, mtimeMs, hash }) => {
|
|
116
|
+
const safeSize = Number.isFinite(Number(size)) ? Number(size) : 0;
|
|
117
|
+
const safeMtime = Number.isFinite(Number(mtimeMs)) ? Number(mtimeMs) : 0;
|
|
118
|
+
if (typeof hash === 'string' && hash.length > 0) {
|
|
119
|
+
return `${FILE_REVISION_PREFIX}:${safeSize}:${safeMtime}:${hash}`;
|
|
120
|
+
}
|
|
121
|
+
return `${FILE_REVISION_PREFIX}:${safeSize}:${safeMtime}`;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const revisionForContentAndStat = (content, stats) => {
|
|
125
|
+
const size = typeof stats?.size === 'number' ? stats.size : Buffer.byteLength(typeof content === 'string' ? content : String(content ?? ''), 'utf8');
|
|
126
|
+
const mtimeMs = typeof stats?.mtimeMs === 'number' ? stats.mtimeMs : 0;
|
|
127
|
+
if (size > FILE_REVISION_HASH_MAX_BYTES) {
|
|
128
|
+
return buildFileRevision({ size, mtimeMs, hash: null });
|
|
129
|
+
}
|
|
130
|
+
const hash = hashBytes(Buffer.from(typeof content === 'string' ? content : String(content ?? ''), 'utf8'));
|
|
131
|
+
return buildFileRevision({ size, mtimeMs, hash });
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const revisionForBufferAndStat = (buffer, stats) => {
|
|
135
|
+
const size = typeof stats?.size === 'number' ? stats.size : buffer.length;
|
|
136
|
+
const mtimeMs = typeof stats?.mtimeMs === 'number' ? stats.mtimeMs : 0;
|
|
137
|
+
if (size > FILE_REVISION_HASH_MAX_BYTES) {
|
|
138
|
+
return buildFileRevision({ size, mtimeMs, hash: null });
|
|
139
|
+
}
|
|
140
|
+
return buildFileRevision({ size, mtimeMs, hash: hashBytes(buffer) });
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const normalizeExpectedRevision = (value) => {
|
|
144
|
+
if (value === undefined) return { mode: 'legacy' };
|
|
145
|
+
if (value === null) return { mode: 'missing' };
|
|
146
|
+
if (typeof value === 'string') {
|
|
147
|
+
if (value === FILE_REVISION_MISSING_LITERAL) return { mode: 'missing' };
|
|
148
|
+
// Opaque: retain exact, compare exact. Empty string is invalid.
|
|
149
|
+
if (value.length === 0) return { mode: 'invalid' };
|
|
150
|
+
return { mode: 'revision', revision: value };
|
|
151
|
+
}
|
|
152
|
+
return { mode: 'invalid' };
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// Parses a client-supplied `knownRevision` for the stat cheap-path. Opaque
|
|
156
|
+
// contract: a v1 revision is only ever compared for size/mtime equality, and
|
|
157
|
+
// the exact client string is echoed back; anything else returns null and the
|
|
158
|
+
// route computes a fresh revision the normal way.
|
|
159
|
+
const parseKnownStatRevision = (value) => {
|
|
160
|
+
if (typeof value !== 'string' || !value.startsWith(`${FILE_REVISION_PREFIX}:`)) return null;
|
|
161
|
+
const parts = value.split(':');
|
|
162
|
+
if (parts.length !== 3 && parts.length !== 4) return null;
|
|
163
|
+
const size = Number(parts[1]);
|
|
164
|
+
const mtimeMs = Number(parts[2]);
|
|
165
|
+
if (!Number.isFinite(size) || !Number.isFinite(mtimeMs)) return null;
|
|
166
|
+
if (parts.length === 3) return { size, mtimeMs, hash: null };
|
|
167
|
+
const hash = parts[3];
|
|
168
|
+
if (!/^[0-9a-f]{64}$/.test(hash)) return null;
|
|
169
|
+
return { size, mtimeMs, hash };
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const sendFileRevisionConflict = (res, { path: conflictPath, currentRevision, exists }) => (
|
|
173
|
+
res.status(409).json({
|
|
174
|
+
error: 'File has changed on disk',
|
|
175
|
+
reason: 'file-revision-conflict',
|
|
176
|
+
path: conflictPath,
|
|
177
|
+
exists: Boolean(exists),
|
|
178
|
+
currentRevision: exists ? currentRevision : null,
|
|
179
|
+
})
|
|
180
|
+
);
|
|
181
|
+
|
|
32
182
|
export const mintOutsideFileGrant = async (targetPath, {
|
|
33
183
|
scopes = ['stat', 'read', 'raw'],
|
|
34
184
|
fsPromises = nodeFsPromises,
|
|
@@ -433,6 +583,13 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
433
583
|
const commandTimeoutMs = createCommandTimeoutMs();
|
|
434
584
|
const gitReadCacheTtlMs = createGitReadCacheTtlMs();
|
|
435
585
|
const gitCheckIgnoreTimeoutMs = createGitCheckIgnoreTimeoutMs();
|
|
586
|
+
const fsSearchRuntime = createFsSearchRuntime({
|
|
587
|
+
fsPromises,
|
|
588
|
+
path,
|
|
589
|
+
spawn,
|
|
590
|
+
resolveGitBinaryForSpawn,
|
|
591
|
+
gitCheckIgnoreTimeoutMs,
|
|
592
|
+
});
|
|
436
593
|
const gitReadCache = new Map();
|
|
437
594
|
const inFlightGitReadCache = new Map();
|
|
438
595
|
|
|
@@ -779,7 +936,44 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
779
936
|
return res.status(400).json({ error: 'Specified path is not a file' });
|
|
780
937
|
}
|
|
781
938
|
|
|
782
|
-
|
|
939
|
+
// Cheap-path for change polling: when the client sends the exact
|
|
940
|
+
// revision it already holds and size+mtime are unchanged, skip the
|
|
941
|
+
// full read+hash a fresh revision would require. A same-size,
|
|
942
|
+
// same-mtime external write is already undetectable to metadata
|
|
943
|
+
// polling, so this preserves the polling contract while removing the
|
|
944
|
+
// per-poll read+hash of large files. The hash-ceiling category must
|
|
945
|
+
// match too; a size that crossed the ceiling means the content
|
|
946
|
+
// changed and the real revision must be computed.
|
|
947
|
+
const known = parseKnownStatRevision(req.query?.knownRevision);
|
|
948
|
+
if (known
|
|
949
|
+
&& known.size === stats.size
|
|
950
|
+
&& known.mtimeMs === stats.mtimeMs
|
|
951
|
+
&& (known.hash !== null) === (stats.size <= FILE_REVISION_HASH_MAX_BYTES)) {
|
|
952
|
+
return res.json({
|
|
953
|
+
path: canonicalPath,
|
|
954
|
+
isFile: true,
|
|
955
|
+
size: stats.size,
|
|
956
|
+
mtimeMs: stats.mtimeMs,
|
|
957
|
+
revision: req.query.knownRevision,
|
|
958
|
+
exists: true,
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
let revision = null;
|
|
963
|
+
try {
|
|
964
|
+
const size = typeof stats.size === 'number' ? stats.size : 0;
|
|
965
|
+
if (size <= FILE_REVISION_HASH_MAX_BYTES && typeof fsPromises.readFile === 'function') {
|
|
966
|
+
const buffer = await fsPromises.readFile(canonicalPath);
|
|
967
|
+
const bytes = Buffer.isBuffer(buffer) ? buffer : Buffer.from(typeof buffer === 'string' ? buffer : String(buffer ?? ''), 'utf8');
|
|
968
|
+
revision = revisionForBufferAndStat(bytes, stats);
|
|
969
|
+
} else {
|
|
970
|
+
revision = buildFileRevision({ size, mtimeMs: stats.mtimeMs, hash: null });
|
|
971
|
+
}
|
|
972
|
+
} catch {
|
|
973
|
+
revision = buildFileRevision({ size: stats.size, mtimeMs: stats.mtimeMs, hash: null });
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
return res.json({ path: canonicalPath, isFile: true, size: stats.size, mtimeMs: stats.mtimeMs, revision, exists: true });
|
|
783
977
|
} catch (error) {
|
|
784
978
|
const err = error;
|
|
785
979
|
if (err && typeof err === 'object' && err.code === 'ENOENT') {
|
|
@@ -851,11 +1045,16 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
851
1045
|
console.warn(`Read retry exhausted for ${canonicalPath}: stat reported ${stats.size} bytes but content is empty`);
|
|
852
1046
|
}
|
|
853
1047
|
}
|
|
1048
|
+
const revision = revisionForContentAndStat(content, stats);
|
|
1049
|
+
res.setHeader(FILE_REVISION_HEADER, revision);
|
|
1050
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
854
1051
|
return res.type('text/plain').send(content);
|
|
855
1052
|
} catch (error) {
|
|
856
1053
|
const err = error;
|
|
857
1054
|
if (err && typeof err === 'object' && err.code === 'ENOENT') {
|
|
858
1055
|
if (optional) {
|
|
1056
|
+
res.setHeader('x-pichamber-file-exists', 'false');
|
|
1057
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
859
1058
|
return res.type('text/plain').send('');
|
|
860
1059
|
}
|
|
861
1060
|
return res.status(404).json({ error: 'File not found' });
|
|
@@ -1015,13 +1214,18 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1015
1214
|
});
|
|
1016
1215
|
|
|
1017
1216
|
app.post('/api/fs/write', async (req, res) => {
|
|
1018
|
-
const { path: filePath, content } = req.body || {};
|
|
1217
|
+
const { path: filePath, content, expectedRevision, overwrite } = req.body || {};
|
|
1019
1218
|
if (!filePath || typeof filePath !== 'string') {
|
|
1020
1219
|
return res.status(400).json({ error: 'Path is required' });
|
|
1021
1220
|
}
|
|
1022
1221
|
if (typeof content !== 'string') {
|
|
1023
1222
|
return res.status(400).json({ error: 'Content is required' });
|
|
1024
1223
|
}
|
|
1224
|
+
const expectation = normalizeExpectedRevision(expectedRevision);
|
|
1225
|
+
if (expectation.mode === 'invalid') {
|
|
1226
|
+
return res.status(400).json({ error: 'Invalid expectedRevision' });
|
|
1227
|
+
}
|
|
1228
|
+
const forceOverwrite = overwrite === true;
|
|
1025
1229
|
|
|
1026
1230
|
try {
|
|
1027
1231
|
const resolved = await resolveWorkspacePathFromContext({
|
|
@@ -1037,35 +1241,131 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1037
1241
|
return res.status(400).json({ error: resolved.error });
|
|
1038
1242
|
}
|
|
1039
1243
|
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1244
|
+
// Serialize cooperating writers by canonical (realpath-resolved) path
|
|
1245
|
+
// so two saves with the same base revision cannot interleave
|
|
1246
|
+
// check+replace, including writes that arrive through different
|
|
1247
|
+
// symlink spellings of the same file.
|
|
1248
|
+
let lockKey = await canonicalFileWriteLockKey(fsPromises, path, resolved.resolved);
|
|
1249
|
+
let outcome = null;
|
|
1250
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
1251
|
+
outcome = await withFileWriteLock(lockKey, async () => {
|
|
1252
|
+
const writePath = await fsPromises.realpath(resolved.resolved).catch((error) => {
|
|
1253
|
+
if (error && typeof error === 'object' && error.code === 'ENOENT') {
|
|
1254
|
+
return resolved.resolved;
|
|
1255
|
+
}
|
|
1256
|
+
throw error;
|
|
1257
|
+
});
|
|
1258
|
+
// The target may have been created or re-pointed between lock-key
|
|
1259
|
+
// resolution and lock acquisition (delete/recreate races). Re-key
|
|
1260
|
+
// onto the canonical path so the compare+replace below still runs
|
|
1261
|
+
// under the lock other writers of the same file will observe.
|
|
1262
|
+
if (writePath !== lockKey && attempt < 2) {
|
|
1263
|
+
return { __rekey: writePath };
|
|
1264
|
+
}
|
|
1265
|
+
const canonicalBase = await fsPromises.realpath(resolved.base).catch(() => path.resolve(resolved.base));
|
|
1266
|
+
if (!isPathWithinRoot(writePath, canonicalBase, path, os)) {
|
|
1267
|
+
return res.status(403).json({ error: 'Access denied' });
|
|
1043
1268
|
}
|
|
1044
|
-
throw error;
|
|
1045
|
-
});
|
|
1046
|
-
const canonicalBase = await fsPromises.realpath(resolved.base).catch(() => path.resolve(resolved.base));
|
|
1047
|
-
if (!isPathWithinRoot(writePath, canonicalBase, path, os)) {
|
|
1048
|
-
return res.status(403).json({ error: 'Access denied' });
|
|
1049
|
-
}
|
|
1050
1269
|
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1270
|
+
let existing = null;
|
|
1271
|
+
let existingStats = null;
|
|
1272
|
+
let exists = false;
|
|
1273
|
+
try {
|
|
1274
|
+
const stats = await fsPromises.stat(writePath);
|
|
1275
|
+
if (!stats.isFile()) {
|
|
1276
|
+
// Preserve existing behavior for directory targets: read as text
|
|
1277
|
+
// fails, so treat as missing content for comparison. Stat
|
|
1278
|
+
// already proved the path exists but is not a file; writing
|
|
1279
|
+
// through rename would replace it, which must stay an error.
|
|
1280
|
+
// Fall through to the write attempt so the filesystem reports
|
|
1281
|
+
// the real failure instead of inventing a revision.
|
|
1282
|
+
exists = true;
|
|
1283
|
+
existingStats = stats;
|
|
1284
|
+
existing = null;
|
|
1285
|
+
} else {
|
|
1286
|
+
exists = true;
|
|
1287
|
+
existingStats = stats;
|
|
1288
|
+
existing = await fsPromises.readFile(writePath, 'utf8').catch(() => null);
|
|
1289
|
+
}
|
|
1290
|
+
} catch (error) {
|
|
1291
|
+
if (error && typeof error === 'object' && error.code === 'ENOENT') {
|
|
1292
|
+
exists = false;
|
|
1293
|
+
} else {
|
|
1294
|
+
throw error;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1055
1297
|
|
|
1056
|
-
|
|
1298
|
+
let currentRevision = null;
|
|
1299
|
+
if (exists && existing !== null && existingStats) {
|
|
1300
|
+
currentRevision = revisionForContentAndStat(existing, existingStats);
|
|
1301
|
+
} else if (exists && existingStats) {
|
|
1302
|
+
currentRevision = buildFileRevision({ size: existingStats.size, mtimeMs: existingStats.mtimeMs, hash: null });
|
|
1303
|
+
}
|
|
1057
1304
|
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1305
|
+
// Idempotent no-op: identical content never conflicts and never
|
|
1306
|
+
// rewrites, preserving mtime/mode and avoiding spurious 409s when
|
|
1307
|
+
// two writers converge on the same bytes.
|
|
1308
|
+
if (exists && existing === content) {
|
|
1309
|
+
return res.json({ success: true, path: resolved.resolved, revision: currentRevision, noop: true });
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
if (!forceOverwrite && expectation.mode !== 'legacy') {
|
|
1313
|
+
if (expectation.mode === 'missing') {
|
|
1314
|
+
if (exists) {
|
|
1315
|
+
return sendFileRevisionConflict(res, { path: resolved.resolved, currentRevision, exists: true });
|
|
1316
|
+
}
|
|
1317
|
+
} else if (expectation.mode === 'revision') {
|
|
1318
|
+
if (!exists) {
|
|
1319
|
+
return sendFileRevisionConflict(res, { path: resolved.resolved, currentRevision: null, exists: false });
|
|
1320
|
+
}
|
|
1321
|
+
if (currentRevision !== expectation.revision) {
|
|
1322
|
+
return sendFileRevisionConflict(res, { path: resolved.resolved, currentRevision, exists: true });
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
await fsPromises.mkdir(path.dirname(writePath), { recursive: true });
|
|
1328
|
+
|
|
1329
|
+
// Preserve access mode across atomic replace; rename creates a new
|
|
1330
|
+
// inode with default permissions, so copy the existing mode onto the
|
|
1331
|
+
// temp file first. New files keep the process default.
|
|
1332
|
+
const existingMode = exists && existingStats && typeof existingStats.mode === 'number'
|
|
1333
|
+
? existingStats.mode & 0o777
|
|
1334
|
+
: null;
|
|
1335
|
+
|
|
1336
|
+
// Atomic write: write to temp then rename to avoid concurrent readers
|
|
1337
|
+
// seeing an empty file during the O_TRUNC window of direct writeFile.
|
|
1338
|
+
// Bytes are written exactly as received; line-ending normalization
|
|
1339
|
+
// stays in the editor serializer, symlinks stay intact because
|
|
1340
|
+
// writePath is the realpath target, and binary content is never
|
|
1341
|
+
// decoded here.
|
|
1342
|
+
const tmp = `${writePath}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
1343
|
+
try {
|
|
1344
|
+
await fsPromises.writeFile(tmp, content, 'utf8');
|
|
1345
|
+
if (existingMode !== null && typeof fsPromises.chmod === 'function') {
|
|
1346
|
+
await fsPromises.chmod(tmp, existingMode).catch(() => {});
|
|
1347
|
+
}
|
|
1348
|
+
await fsPromises.rename(tmp, writePath);
|
|
1349
|
+
} catch (error) {
|
|
1350
|
+
await fsPromises.unlink(tmp).catch(() => {});
|
|
1351
|
+
throw error;
|
|
1352
|
+
}
|
|
1353
|
+
let newRevision = null;
|
|
1354
|
+
try {
|
|
1355
|
+
const nextStats = await fsPromises.stat(writePath);
|
|
1356
|
+
newRevision = revisionForContentAndStat(content, nextStats);
|
|
1357
|
+
} catch {
|
|
1358
|
+
newRevision = revisionForContentAndStat(content, { size: Buffer.byteLength(content, 'utf8'), mtimeMs: Date.now() });
|
|
1359
|
+
}
|
|
1360
|
+
return res.json({ success: true, path: resolved.resolved, revision: newRevision });
|
|
1361
|
+
});
|
|
1362
|
+
if (outcome && typeof outcome === 'object' && outcome.__rekey) {
|
|
1363
|
+
lockKey = outcome.__rekey;
|
|
1364
|
+
continue;
|
|
1365
|
+
}
|
|
1366
|
+
return outcome;
|
|
1067
1367
|
}
|
|
1068
|
-
return
|
|
1368
|
+
return outcome;
|
|
1069
1369
|
} catch (error) {
|
|
1070
1370
|
const err = error;
|
|
1071
1371
|
if (isOsPermissionError(err)) {
|
|
@@ -1475,46 +1775,64 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1475
1775
|
if (!rawPath.trim()) return res.status(400).json({ error: 'Directory path is required' });
|
|
1476
1776
|
|
|
1477
1777
|
try {
|
|
1478
|
-
const
|
|
1778
|
+
const resolved = await resolveWorkspacePathFromContext({
|
|
1779
|
+
req,
|
|
1780
|
+
targetPath: rawPath,
|
|
1781
|
+
resolveProjectDirectory,
|
|
1782
|
+
path,
|
|
1783
|
+
os,
|
|
1784
|
+
normalizeDirectoryPath,
|
|
1785
|
+
pichamberUserConfigRoot,
|
|
1786
|
+
});
|
|
1787
|
+
if (!resolved.ok) {
|
|
1788
|
+
return res.status(400).json({ error: resolved.error });
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
const [canonicalPath, canonicalBase] = await Promise.all([
|
|
1792
|
+
realpathCache.resolve(resolved.resolved),
|
|
1793
|
+
realpathCache.resolve(resolved.base).catch(() => path.resolve(resolved.base)),
|
|
1794
|
+
]);
|
|
1795
|
+
if (!isPathWithinRoot(canonicalPath, canonicalBase, path, os)) {
|
|
1796
|
+
return res.status(403).json({ error: 'Access to directory denied' });
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
const stats = await fsPromises.stat(canonicalPath);
|
|
1800
|
+
if (!stats.isDirectory()) {
|
|
1801
|
+
return res.status(400).json({ error: 'Specified path is not a directory', reason: 'not-directory' });
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1479
1804
|
const query = typeof req.query.query === 'string' ? req.query.query : '';
|
|
1480
|
-
const
|
|
1805
|
+
const requestedLimit = Number(req.query.limit);
|
|
1806
|
+
const limit = Number.isSafeInteger(requestedLimit) ? Math.max(1, Math.min(requestedLimit, 500)) : 60;
|
|
1481
1807
|
const includeHidden = req.query.includeHidden === 'true';
|
|
1482
1808
|
const respectGitignore = req.query.respectGitignore !== 'false';
|
|
1483
1809
|
const type = req.query.type === 'directory' ? 'directory' : req.query.type === 'file' ? 'file' : undefined;
|
|
1484
1810
|
|
|
1485
|
-
const fsSearchRuntime = createFsSearchRuntime({ fsPromises, path, spawn, resolveGitBinaryForSpawn });
|
|
1486
1811
|
const rawHits = await fsSearchRuntime.searchFilesystemFiles(canonicalPath, {
|
|
1487
1812
|
query,
|
|
1488
1813
|
limit,
|
|
1489
1814
|
includeHidden,
|
|
1490
1815
|
respectGitignore,
|
|
1816
|
+
type,
|
|
1491
1817
|
});
|
|
1492
1818
|
|
|
1493
|
-
const
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
const name = path.basename(hitPath);
|
|
1506
|
-
return {
|
|
1507
|
-
name,
|
|
1508
|
-
path: hitPath,
|
|
1509
|
-
relativePath,
|
|
1510
|
-
...(name.includes('.') ? { extension: name.split('.').pop().toLowerCase() } : {}),
|
|
1511
|
-
};
|
|
1512
|
-
});
|
|
1819
|
+
const logicalRoot = path.resolve(resolved.resolved);
|
|
1820
|
+
const files = rawHits.map((hit) => {
|
|
1821
|
+
const relativePath = hit.relativePath.replace(/\\/g, '/');
|
|
1822
|
+
const hitPath = path.join(logicalRoot, hit.relativePath).replace(/\\/g, '/');
|
|
1823
|
+
const name = hit.name;
|
|
1824
|
+
return {
|
|
1825
|
+
name,
|
|
1826
|
+
path: hitPath,
|
|
1827
|
+
relativePath,
|
|
1828
|
+
...(hit.extension ? { extension: hit.extension } : {}),
|
|
1829
|
+
};
|
|
1830
|
+
});
|
|
1513
1831
|
|
|
1514
1832
|
return res.json({ files });
|
|
1515
1833
|
} catch (error) {
|
|
1516
|
-
if (error
|
|
1517
|
-
return
|
|
1834
|
+
if (isOsPermissionError(error)) {
|
|
1835
|
+
return sendOsPermissionDenied(res, 'Access to directory denied');
|
|
1518
1836
|
}
|
|
1519
1837
|
return res.status(500).json({ error: (error && error.message) || 'Failed to search files' });
|
|
1520
1838
|
}
|