arco-workbench 0.1.8 → 0.1.9
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/CONTRIBUTING.md +11 -0
- package/README.md +7 -5
- package/client/dist/assets/{PhosphorBackdrop-D7jdAV_G.js → PhosphorBackdrop-DRu16-Is.js} +1 -1
- package/client/dist/assets/{ThemedBackgroundShaderImpl-DrDm60h8.js → ThemedBackgroundShaderImpl-BLdwwQ4D.js} +1 -1
- package/client/dist/assets/{XtermView-BGFujb1e.js → XtermView-Xk7_9JaH.js} +1 -1
- package/client/dist/assets/{galleryEditor-D951A2sE.js → galleryEditor-CI8ClzBa.js} +1 -1
- package/client/dist/assets/{index-DD9kFGsF.css → index-BEFgrUJJ.css} +1 -1
- package/client/dist/assets/{index-CsVy3eZm.js → index-C7WzZfsr.js} +246 -244
- package/client/dist/index.html +2 -2
- package/client/src/App.tsx +2 -0
- package/client/src/components/ChatMessage.tsx +33 -8
- package/client/src/components/ChatModeView.tsx +2 -0
- package/client/src/components/ClusterRightPanel/SkillsControl.tsx +25 -8
- package/client/src/components/CodexLateCommand.tsx +34 -0
- package/client/src/components/DialogShell.tsx +2 -0
- package/client/src/components/MemberCard.tsx +4 -1
- package/client/src/components/MemberPane.tsx +3 -1
- package/client/src/components/PhoneUpload.tsx +288 -0
- package/client/src/components/PrimaryStatus.tsx +14 -6
- package/client/src/components/RuntimeStateBanner.tsx +5 -0
- package/client/src/components/SkillEditorDialog.tsx +2 -2
- package/client/src/components/SkillsSettings.tsx +17 -5
- package/client/src/components/TerminalInput.tsx +3 -1
- package/client/src/components/WorkflowView.tsx +2 -0
- package/client/src/explorer/ArtifactsLens.tsx +37 -28
- package/client/src/explorer/ExplorerApp.tsx +5 -4
- package/client/src/explorer/types.ts +8 -3
- package/client/src/help/content/cluster.tsx +11 -1
- package/client/src/help/content/composer.tsx +18 -1
- package/client/src/help/content/header.tsx +2 -1
- package/client/src/help/content/misc.tsx +1 -1
- package/client/src/help/content/settings.tsx +1 -1
- package/client/src/help/manualSections/clusters.tsx +3 -0
- package/client/src/help/manualSections/configuration.tsx +3 -1
- package/client/src/help/manualSections/gettingStarted.tsx +4 -4
- package/client/src/help/manualSections/maintenance.tsx +7 -6
- package/client/src/help/manualSections/powerFeatures.tsx +3 -2
- package/client/src/help/manualSections/workspace.tsx +30 -0
- package/client/src/stores/appStore.ts +7 -0
- package/client/src/stores/appStore.types.ts +4 -0
- package/client/src/styles/global.css +109 -0
- package/client/src/utils/phoneTheme.ts +38 -0
- package/client/src/utils/phoneUploadApi.ts +10 -0
- package/client/src/ws/handleServerMessage.ts +23 -6
- package/docs/CLIENT.md +7 -1
- package/docs/FEATURES.md +6 -3
- package/docs/GETTING_STARTED.md +8 -3
- package/docs/INDEX.md +1 -1
- package/docs/OPERATIONS.md +199 -48
- package/docs/PROTOCOL_CLUSTER.md +9 -1
- package/docs/PROVIDERS.md +34 -0
- package/docs/SETTINGS.md +5 -3
- package/native/darwin-arm64/manifest.json +1 -1
- package/native/linux-x64/manifest.json +1 -1
- package/native/win32-x64/manifest.json +1 -1
- package/node_modules/@arco/shared/dist/protocol/chat.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/clusters.d.ts +2 -0
- package/node_modules/@arco/shared/dist/protocol/serverMessages.d.ts +11 -0
- package/node_modules/@arco/shared/dist/protocol/workflows.d.ts +1 -0
- package/node_modules/@arco/shared/package.json +1 -1
- package/package.json +2 -2
- package/server/dist/clusterDirector.js +1 -0
- package/server/dist/clusterPeerOps.js +4 -1
- package/server/dist/clusterRehydrate.js +2 -0
- package/server/dist/explorerDocs.d.ts +10 -6
- package/server/dist/explorerDocs.js +75 -34
- package/server/dist/http/attachmentUpload.d.ts +13 -0
- package/server/dist/http/attachmentUpload.js +38 -0
- package/server/dist/http/browserWorktrees.d.ts +23 -0
- package/server/dist/http/browserWorktrees.js +120 -0
- package/server/dist/http/phoneUploadDrafts.d.ts +13 -0
- package/server/dist/http/phoneUploadDrafts.js +125 -0
- package/server/dist/http/phoneUploadListener.d.ts +17 -0
- package/server/dist/http/phoneUploadListener.js +81 -0
- package/server/dist/http/phoneUploadNetwork.d.ts +9 -0
- package/server/dist/http/phoneUploadNetwork.js +106 -0
- package/server/dist/http/phoneUploadPage.d.ts +2 -0
- package/server/dist/http/phoneUploadPage.js +136 -0
- package/server/dist/http/phoneUploadRouteHistory.d.ts +4 -0
- package/server/dist/http/phoneUploadRouteHistory.js +72 -0
- package/server/dist/http/phoneUploadRoutes.d.ts +4 -0
- package/server/dist/http/phoneUploadRoutes.js +419 -0
- package/server/dist/http/phoneUploadTheme.d.ts +17 -0
- package/server/dist/http/phoneUploadTheme.js +96 -0
- package/server/dist/http/projectBinding.d.ts +1 -0
- package/server/dist/http/projectBinding.js +3 -2
- package/server/dist/http/readConfinement.js +5 -1
- package/server/dist/http/router.js +13 -24
- package/server/dist/http/writeConfinement.js +19 -2
- package/server/dist/primitives/seedWorker.d.ts +1 -0
- package/server/dist/primitives/seedWorker.js +2 -1
- package/server/dist/providers/codex-appserver/heldCommands.d.ts +14 -0
- package/server/dist/providers/codex-appserver/heldCommands.js +54 -0
- package/server/dist/providers/codex-appserver/index.d.ts +52 -2
- package/server/dist/providers/codex-appserver/index.js +239 -21
- package/server/dist/providers/codex-appserver/lateCommands.d.ts +62 -0
- package/server/dist/providers/codex-appserver/lateCommands.js +195 -0
- package/server/dist/providers/codex-appserver/worker.d.ts +23 -1
- package/server/dist/providers/codex-appserver/worker.js +89 -20
- package/server/dist/providers/codex.js +2 -2
- package/server/dist/providers/codexCodeMode.d.ts +2 -1
- package/server/dist/providers/codexCodeMode.js +7 -3
- package/server/dist/workers/WorkerManager.d.ts +1 -0
- package/server/dist/workers/WorkerManager.js +1 -0
- package/server/dist/workers/processKill.d.ts +9 -1
- package/server/dist/workers/processKill.js +26 -10
- package/server/dist/ws/handoffHandlers.js +2 -0
- package/server/dist/ws/turnEngine.js +17 -0
- package/server/package.json +1 -1
- package/server/src/clusterDirector.ts +1 -0
- package/server/src/clusterPeerOps.ts +4 -1
- package/server/src/clusterRehydrate.ts +2 -0
- package/server/src/explorerDocs.ts +75 -34
- package/server/src/http/attachmentUpload.ts +49 -0
- package/server/src/http/browserWorktrees.ts +124 -0
- package/server/src/http/phoneUploadDrafts.ts +118 -0
- package/server/src/http/phoneUploadListener.ts +96 -0
- package/server/src/http/phoneUploadNetwork.ts +117 -0
- package/server/src/http/phoneUploadPage.ts +137 -0
- package/server/src/http/phoneUploadRouteHistory.ts +73 -0
- package/server/src/http/phoneUploadRoutes.ts +398 -0
- package/server/src/http/phoneUploadTheme.ts +97 -0
- package/server/src/http/projectBinding.ts +3 -2
- package/server/src/http/readConfinement.ts +5 -1
- package/server/src/http/router.ts +11 -25
- package/server/src/http/writeConfinement.ts +13 -2
- package/server/src/primitives/seedWorker.ts +3 -1
- package/server/src/providers/codex-appserver/heldCommands.ts +58 -0
- package/server/src/providers/codex-appserver/index.ts +222 -20
- package/server/src/providers/codex-appserver/lateCommands.ts +225 -0
- package/server/src/providers/codex-appserver/worker.ts +85 -21
- package/server/src/providers/codex.ts +2 -2
- package/server/src/providers/codexCodeMode.ts +8 -3
- package/server/src/workers/WorkerManager.ts +2 -0
- package/server/src/workers/processKill.ts +35 -7
- package/server/src/ws/handoffHandlers.ts +2 -0
- package/server/src/ws/turnEngine.ts +15 -0
- package/shared/dist/protocol/chat.d.ts +1 -0
- package/shared/dist/protocol/clusters.d.ts +2 -0
- package/shared/dist/protocol/serverMessages.d.ts +11 -0
- package/shared/dist/protocol/workflows.d.ts +1 -0
- package/shared/src/protocol/chat.ts +1 -0
- package/shared/src/protocol/clusters.ts +4 -5
- package/shared/src/protocol/serverMessages.ts +11 -0
- package/shared/src/protocol/workflows.ts +4 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { scanBeforeDeadline } from './scanDeadline.js';
|
|
2
2
|
import { projectFiles, scanBudget, exhausted } from './projectScan.js';
|
|
3
|
-
import { confinedPath } from './fileAccessPolicy.js';
|
|
3
|
+
import { confinedPath, createReadAccessContext } from './fileAccessPolicy.js';
|
|
4
|
+
import { resolveBoundCwd } from './http/writeConfinement.js';
|
|
5
|
+
import { browserWorktreeFile, browserWorktreeRegistry, confirmBrowserWorktree } from './http/browserWorktrees.js';
|
|
4
6
|
// ARCHIVE (docs/CLIENT.md) - project-DOCUMENT scan. The ARTIFACTS
|
|
5
7
|
// lens is a project-artifact tool, and the documents an operator most wants to
|
|
6
8
|
// find live in the PROJECT TREE (e.g. `Codex/Reports/2026-07-10_*.md`, top-level
|
|
@@ -9,14 +11,13 @@ import { confinedPath } from './fileAccessPolicy.js';
|
|
|
9
11
|
// scan is the other half: readable documents in the real tree, so drilling into
|
|
10
12
|
// a project shows the docs written FOR it, not just agent workflow spill.
|
|
11
13
|
//
|
|
12
|
-
// Portable pruned walk (no `fd`),
|
|
14
|
+
// Portable pruned walk (no `fd`), depth/count-capped. The global scan stays
|
|
15
|
+
// inside HOME; a scoped project can include Git-confirmed siblings. `.arco` is
|
|
13
16
|
// pruned wholesale here (the artifacts join owns it — merging both client-side
|
|
14
17
|
// gives the full picture without double-counting).
|
|
15
|
-
import { stat } from 'fs/promises';
|
|
16
|
-
import { basename,
|
|
17
|
-
import {
|
|
18
|
-
import { realpathWithinHome } from './explorerArtifacts.js';
|
|
19
|
-
import { arcoHome } from './arcoHome.js';
|
|
18
|
+
import { stat } from 'node:fs/promises';
|
|
19
|
+
import { basename, relative } from 'node:path';
|
|
20
|
+
import { readKnownCwds, realpathWithinHome } from './explorerArtifacts.js';
|
|
20
21
|
const PRUNE_DIRS = new Set([
|
|
21
22
|
'node_modules', '.git', 'dist', 'build', '.venv', '__pycache__',
|
|
22
23
|
'.next', 'target', '.cache', 'coverage', '.turbo', '.arco',
|
|
@@ -29,6 +30,27 @@ function isDoc(name) {
|
|
|
29
30
|
const ext = name.includes('.') ? name.split('.').pop().toLowerCase() : '';
|
|
30
31
|
return DOC_EXT.has(ext);
|
|
31
32
|
}
|
|
33
|
+
async function scanDocuments(root, owner, budget, out, authorize, branch) {
|
|
34
|
+
for await (const file of projectFiles(root, { budget, skip: PRUNE_DIRS, hidden: true, maxDepth: MAX_DEPTH })) {
|
|
35
|
+
if (!isDoc(file.name))
|
|
36
|
+
continue;
|
|
37
|
+
try {
|
|
38
|
+
const authorized = await scanBeforeDeadline(Promise.resolve(authorize(file.path)), budget);
|
|
39
|
+
if (!authorized)
|
|
40
|
+
break;
|
|
41
|
+
const st = await scanBeforeDeadline(stat(authorized), budget);
|
|
42
|
+
if (!st)
|
|
43
|
+
break;
|
|
44
|
+
out.push({ path: file.path, name: file.name, size: st.size, mtime: st.mtimeMs, project: basename(owner), cwd: owner,
|
|
45
|
+
rel: relative(root, file.path), ...(branch ? { branch } : {}) });
|
|
46
|
+
}
|
|
47
|
+
catch { /* unreadable or outside the project */ }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function finishPage(out, limit, budget) {
|
|
51
|
+
out.sort((a, b) => b.mtime - a.mtime);
|
|
52
|
+
return { entries: out.slice(0, limit), partial: budget.partial || out.length > limit };
|
|
53
|
+
}
|
|
32
54
|
// Walk one project tree for document files, newest-first, capped.
|
|
33
55
|
export async function collectProjectDocsPage(project, limit = 1000, global) {
|
|
34
56
|
const budget = scanBudget();
|
|
@@ -41,62 +63,81 @@ export async function collectProjectDocsPage(project, limit = 1000, global) {
|
|
|
41
63
|
budget.entries = Math.min(budget.entries, global.entries);
|
|
42
64
|
const starting = budget.entries;
|
|
43
65
|
const out = [];
|
|
44
|
-
|
|
45
|
-
if (!isDoc(file.name))
|
|
46
|
-
continue;
|
|
47
|
-
try {
|
|
48
|
-
confinedPath(file.path, [root], 'file');
|
|
49
|
-
const st = await scanBeforeDeadline(stat(file.path), budget);
|
|
50
|
-
if (!st)
|
|
51
|
-
break;
|
|
52
|
-
out.push({ path: file.path, name: file.name, size: st.size, mtime: st.mtimeMs, project: basename(root), cwd: root, rel: relative(root, file.path) });
|
|
53
|
-
}
|
|
54
|
-
catch { /* unreadable or outside the project */ }
|
|
55
|
-
}
|
|
66
|
+
await scanDocuments(root, root, budget, out, file => confinedPath(file, [root], 'file'));
|
|
56
67
|
if (global)
|
|
57
68
|
global.entries -= starting - budget.entries;
|
|
58
|
-
out
|
|
59
|
-
return { entries: out.slice(0, limit), partial: budget.partial || out.length > limit };
|
|
69
|
+
return finishPage(out, limit, budget);
|
|
60
70
|
}
|
|
61
71
|
export async function collectProjectDocs(project, limit = 1000) {
|
|
62
72
|
return (await collectProjectDocsPage(project, limit)).entries;
|
|
63
73
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return
|
|
74
|
+
async function collectScopedDocs(project) {
|
|
75
|
+
const budget = scanBudget();
|
|
76
|
+
const out = [];
|
|
77
|
+
const root = await scanBeforeDeadline(realpathWithinHome(project), budget);
|
|
78
|
+
if (root)
|
|
79
|
+
await scanDocuments(root, root, budget, out, file => confinedPath(file, [root], 'file'));
|
|
80
|
+
if (exhausted(budget))
|
|
81
|
+
return finishPage(out, 1000, budget);
|
|
82
|
+
const bound = await scanBeforeDeadline(resolveBoundCwd(project, undefined), budget);
|
|
83
|
+
if (!bound?.ok)
|
|
84
|
+
return finishPage(out, 1000, budget);
|
|
85
|
+
const access = await scanBeforeDeadline(createReadAccessContext(), budget);
|
|
86
|
+
if (!access)
|
|
87
|
+
return finishPage(out, 1000, budget);
|
|
88
|
+
const owner = root ?? await scanBeforeDeadline(access.safeDirectory(bound.cwd), budget);
|
|
89
|
+
if (!owner)
|
|
90
|
+
return finishPage(out, 1000, budget);
|
|
91
|
+
const signal = AbortSignal.timeout(Math.max(1, Math.ceil(budget.deadline - performance.now())));
|
|
92
|
+
const registry = await scanBeforeDeadline(browserWorktreeRegistry(owner, signal), budget);
|
|
93
|
+
if (!registry) {
|
|
94
|
+
if (signal.aborted)
|
|
95
|
+
budget.partial = true;
|
|
96
|
+
return finishPage(out, 1000, budget);
|
|
72
97
|
}
|
|
73
|
-
|
|
74
|
-
|
|
98
|
+
for (const entry of registry.entries) {
|
|
99
|
+
if (exhausted(budget))
|
|
100
|
+
break;
|
|
101
|
+
const tree = await scanBeforeDeadline(confirmBrowserWorktree(registry, entry, access, signal), budget);
|
|
102
|
+
if (!tree)
|
|
103
|
+
continue;
|
|
104
|
+
await scanDocuments(tree.canonical, owner, budget, out, file => browserWorktreeFile(file, tree, access), tree.branch);
|
|
75
105
|
}
|
|
106
|
+
if (signal.aborted)
|
|
107
|
+
budget.partial = true;
|
|
108
|
+
return finishPage(out, 1000, budget);
|
|
76
109
|
}
|
|
77
110
|
// Global doc scan across known projects, bounded per-project so a home load over
|
|
78
111
|
// dozens of projects stays responsive. `project` scopes to one (full limit).
|
|
79
112
|
export async function collectDocsPage(opts = {}) {
|
|
80
113
|
if (opts.project)
|
|
81
|
-
return
|
|
114
|
+
return collectScopedDocs(opts.project);
|
|
82
115
|
const global = scanBudget(50_000, 650);
|
|
83
116
|
const known = await scanBeforeDeadline(readKnownCwds(), global);
|
|
84
117
|
if (!known)
|
|
85
118
|
return { entries: [], partial: true };
|
|
86
119
|
const cwds = [...new Set(known)];
|
|
87
120
|
const all = [];
|
|
121
|
+
const projects = new Map();
|
|
122
|
+
const access = await scanBeforeDeadline(createReadAccessContext(), global);
|
|
123
|
+
if (!access)
|
|
124
|
+
return { entries: [], partial: true };
|
|
88
125
|
let partial = false;
|
|
89
126
|
for (const cwd of cwds) {
|
|
90
127
|
if (exhausted(global)) {
|
|
91
128
|
partial = true;
|
|
92
129
|
break;
|
|
93
130
|
}
|
|
94
|
-
const
|
|
131
|
+
const root = await scanBeforeDeadline(access.safeDirectory(cwd).catch(() => null), global);
|
|
132
|
+
if (!root)
|
|
133
|
+
continue;
|
|
134
|
+
projects.set(root, { cwd: root, project: basename(root) });
|
|
135
|
+
const page = await collectProjectDocsPage(root, 150, global).catch(() => ({ entries: [], partial: true }));
|
|
95
136
|
all.push(...page.entries);
|
|
96
137
|
partial ||= page.partial;
|
|
97
138
|
}
|
|
98
139
|
all.sort((a, b) => b.mtime - a.mtime);
|
|
99
|
-
return { entries: all.slice(0, 600), partial: partial || all.length > 600 };
|
|
140
|
+
return { entries: all.slice(0, 600), partial: partial || global.partial || all.length > 600, projects: [...projects.values()] };
|
|
100
141
|
}
|
|
101
142
|
export async function collectDocs(opts = {}) {
|
|
102
143
|
return (await collectDocsPage(opts)).entries;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
export interface StoredAttachment {
|
|
3
|
+
fileId: string;
|
|
4
|
+
filename: string;
|
|
5
|
+
path: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class UploadTooLarge extends Error {
|
|
8
|
+
}
|
|
9
|
+
export declare function readAttachmentBody(req: IncomingMessage, limit?: number): Promise<Buffer>;
|
|
10
|
+
export declare function storeAttachment(body: Buffer, rawFilename: string, contentType: string, reservation?: {
|
|
11
|
+
fileId: string;
|
|
12
|
+
beforeWrite: (file: StoredAttachment) => Promise<void>;
|
|
13
|
+
}): Promise<StoredAttachment>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { basename, extname, join } from 'node:path';
|
|
4
|
+
import { shrinkUploadedImage } from '../uploadImages.js';
|
|
5
|
+
import { queueModelImage } from '../providers/attachments.js';
|
|
6
|
+
import { UPLOADS_DIR, UPLOAD_IMAGE_EXT } from '../server/constants.js';
|
|
7
|
+
import { ensureStorageRoot } from '../storageRoot.js';
|
|
8
|
+
export class UploadTooLarge extends Error {
|
|
9
|
+
}
|
|
10
|
+
export async function readAttachmentBody(req, limit) {
|
|
11
|
+
const chunks = [];
|
|
12
|
+
let size = 0;
|
|
13
|
+
for await (const chunk of req.iterator({ destroyOnReturn: false })) {
|
|
14
|
+
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
15
|
+
size += bytes.length;
|
|
16
|
+
if (limit !== undefined && size > limit)
|
|
17
|
+
throw new UploadTooLarge();
|
|
18
|
+
chunks.push(bytes);
|
|
19
|
+
}
|
|
20
|
+
return Buffer.concat(chunks, size);
|
|
21
|
+
}
|
|
22
|
+
export async function storeAttachment(body, rawFilename, contentType, reservation) {
|
|
23
|
+
const inferredExt = !extname(rawFilename) ? UPLOAD_IMAGE_EXT[contentType] : undefined;
|
|
24
|
+
const filename = basename(rawFilename) + (inferredExt ?? '');
|
|
25
|
+
const fileId = reservation?.fileId ?? randomUUID().slice(0, 8);
|
|
26
|
+
const root = await ensureStorageRoot(UPLOADS_DIR);
|
|
27
|
+
const path = join(root, `${fileId}-${filename}`);
|
|
28
|
+
const stored = { fileId, filename, path };
|
|
29
|
+
await reservation?.beforeWrite(stored);
|
|
30
|
+
await writeFile(path, body, { flag: 'wx', mode: 0o600 });
|
|
31
|
+
if (!reservation)
|
|
32
|
+
console.log(`[arco] File uploaded: ${filename} -> ${path}`);
|
|
33
|
+
// Finish any replacement before publishing the stable path.
|
|
34
|
+
await shrinkUploadedImage(path);
|
|
35
|
+
queueModelImage(path);
|
|
36
|
+
return stored;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=attachmentUpload.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ReadAccessContext } from '../fileAccessPolicy.js';
|
|
2
|
+
interface RegisteredWorktree {
|
|
3
|
+
directory: string;
|
|
4
|
+
branch: string;
|
|
5
|
+
}
|
|
6
|
+
interface WorktreeRegistry {
|
|
7
|
+
checkout: string;
|
|
8
|
+
common: string;
|
|
9
|
+
entries: RegisteredWorktree[];
|
|
10
|
+
}
|
|
11
|
+
interface BrowserWorktree {
|
|
12
|
+
directory: string;
|
|
13
|
+
canonical: string;
|
|
14
|
+
native: string;
|
|
15
|
+
branch: string;
|
|
16
|
+
device: number;
|
|
17
|
+
inode: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function browserWorktreeRegistry(boundCwd: string, signal?: AbortSignal): Promise<WorktreeRegistry | null>;
|
|
20
|
+
export declare function confirmBrowserWorktree(registry: WorktreeRegistry, entry: RegisteredWorktree, access: ReadAccessContext, signal?: AbortSignal): Promise<BrowserWorktree | null>;
|
|
21
|
+
export declare function browserWorktreeFile(target: string, tree: BrowserWorktree, access: ReadAccessContext): Promise<string>;
|
|
22
|
+
export declare function resolveWorktreeFile(target: string, boundCwd: string, access: ReadAccessContext): Promise<string>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// A read grant for a single Git-confirmed checkout. This does not register the
|
|
2
|
+
// checkout with the global project roots or use the managed-task write grant.
|
|
3
|
+
import { realpath } from 'node:fs';
|
|
4
|
+
import { lstat } from 'node:fs/promises';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { promisify } from 'node:util';
|
|
8
|
+
import { FileAccessError, isPathWithin } from '../fileAccessPolicy.js';
|
|
9
|
+
import { gitOutput } from './projectBinding.js';
|
|
10
|
+
const nativePath = promisify(realpath.native);
|
|
11
|
+
const samePath = (a, b) => path.relative(a, b) === '';
|
|
12
|
+
function refuseArcoState(target) {
|
|
13
|
+
if (path.resolve(target).split(path.sep).some(part => part.toLowerCase() === '.arco'))
|
|
14
|
+
throw new FileAccessError();
|
|
15
|
+
}
|
|
16
|
+
async function gitDirectory(cwd, arg, signal) {
|
|
17
|
+
const stdout = await gitOutput(cwd, ['rev-parse', '--path-format=absolute', arg], signal);
|
|
18
|
+
return nativePath(stdout.replace(process.platform === 'win32' ? /\r?\n$/ : /\n$/, ''));
|
|
19
|
+
}
|
|
20
|
+
export async function browserWorktreeRegistry(boundCwd, signal) {
|
|
21
|
+
try {
|
|
22
|
+
const output = await gitOutput(boundCwd, ['worktree', 'list', '--porcelain', '-z'], signal);
|
|
23
|
+
const entries = output.split('\0\0').flatMap(record => {
|
|
24
|
+
const [worktree, ...fields] = record.split('\0');
|
|
25
|
+
if (!worktree.startsWith('worktree ') || fields.some(field => /^(bare|prunable)( |$)/.test(field)))
|
|
26
|
+
return [];
|
|
27
|
+
const directory = path.normalize(worktree.slice('worktree '.length));
|
|
28
|
+
const branch = fields.find(field => field.startsWith('branch refs/heads/'))?.slice('branch refs/heads/'.length);
|
|
29
|
+
const head = fields.find(field => /^HEAD [0-9a-f]{7,64}$/.test(field))?.slice(5, 12);
|
|
30
|
+
return path.isAbsolute(directory) && (branch || head)
|
|
31
|
+
? [{ directory, branch: branch || ('Detached HEAD ' + head) }] : [];
|
|
32
|
+
});
|
|
33
|
+
if (entries.length < 2)
|
|
34
|
+
return null;
|
|
35
|
+
const [checkout, common] = await Promise.all([
|
|
36
|
+
gitDirectory(boundCwd, '--show-toplevel', signal),
|
|
37
|
+
gitDirectory(boundCwd, '--git-common-dir', signal),
|
|
38
|
+
]);
|
|
39
|
+
return { checkout, common, entries: entries.filter(entry => !samePath(entry.directory, checkout)) };
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export async function confirmBrowserWorktree(registry, entry, access, signal) {
|
|
46
|
+
try {
|
|
47
|
+
refuseArcoState(entry.directory);
|
|
48
|
+
const root = await lstat(entry.directory);
|
|
49
|
+
if (!root.isDirectory())
|
|
50
|
+
return null;
|
|
51
|
+
const canonical = await access.safeDirectory(entry.directory);
|
|
52
|
+
refuseArcoState(canonical);
|
|
53
|
+
const real = await nativePath(canonical);
|
|
54
|
+
access.assertSafePath(real);
|
|
55
|
+
const home = await nativePath(homedir()).catch(() => homedir());
|
|
56
|
+
if (samePath(real, registry.checkout) || samePath(real, path.parse(real).root) || isPathWithin(real, home))
|
|
57
|
+
return null;
|
|
58
|
+
const [top, common] = await Promise.all([
|
|
59
|
+
gitDirectory(real, '--show-toplevel', signal),
|
|
60
|
+
gitDirectory(real, '--git-common-dir', signal),
|
|
61
|
+
]);
|
|
62
|
+
if (!samePath(real, top) || !samePath(common, registry.common))
|
|
63
|
+
return null;
|
|
64
|
+
return { ...entry, canonical, native: real, device: root.dev, inode: root.ino };
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export async function browserWorktreeFile(target, tree, access) {
|
|
71
|
+
refuseArcoState(target);
|
|
72
|
+
if (!isPathWithin(tree.directory, target) && !isPathWithin(tree.canonical, target))
|
|
73
|
+
throw new FileAccessError();
|
|
74
|
+
const { real } = await access.inspect(target, undefined, 'file');
|
|
75
|
+
// Git for Windows and Node may spell the same directory differently when
|
|
76
|
+
// a parent has an 8.3 name. Compare both resolved paths in native spelling.
|
|
77
|
+
const expanded = await nativePath(real);
|
|
78
|
+
access.assertSafePath(expanded);
|
|
79
|
+
refuseArcoState(real);
|
|
80
|
+
refuseArcoState(expanded);
|
|
81
|
+
if (!isPathWithin(tree.native, expanded))
|
|
82
|
+
throw new FileAccessError();
|
|
83
|
+
const root = await lstat(tree.directory);
|
|
84
|
+
if (!root.isDirectory() || root.dev !== tree.device || root.ino !== tree.inode)
|
|
85
|
+
throw new FileAccessError();
|
|
86
|
+
return real;
|
|
87
|
+
}
|
|
88
|
+
export async function resolveWorktreeFile(target, boundCwd, access) {
|
|
89
|
+
const registry = await browserWorktreeRegistry(boundCwd);
|
|
90
|
+
if (!registry)
|
|
91
|
+
throw new FileAccessError();
|
|
92
|
+
let alias;
|
|
93
|
+
let entry = registry.entries.filter(candidate => isPathWithin(candidate.directory, target))
|
|
94
|
+
.sort((a, b) => b.directory.length - a.directory.length)[0];
|
|
95
|
+
if (!entry) {
|
|
96
|
+
// Parent aliases occur on macOS and Windows. Match the root's expanded
|
|
97
|
+
// spelling but keep the request's spelling for read confinement below.
|
|
98
|
+
const spellings = await Promise.all(registry.entries.map(async (candidate) => ({
|
|
99
|
+
candidate,
|
|
100
|
+
real: await nativePath(candidate.directory).catch(() => null),
|
|
101
|
+
})));
|
|
102
|
+
for (let dir = path.dirname(target); dir !== path.dirname(dir); dir = path.dirname(dir)) {
|
|
103
|
+
const stat = await lstat(dir).catch(() => null);
|
|
104
|
+
if (!stat?.isDirectory())
|
|
105
|
+
continue;
|
|
106
|
+
const real = await nativePath(dir);
|
|
107
|
+
const registered = spellings.find(candidate => candidate.real && samePath(candidate.real, real))?.candidate;
|
|
108
|
+
if (registered) {
|
|
109
|
+
entry = registered;
|
|
110
|
+
alias = dir;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const verified = entry && await confirmBrowserWorktree(registry, entry, access);
|
|
116
|
+
if (!verified)
|
|
117
|
+
throw new FileAccessError();
|
|
118
|
+
return browserWorktreeFile(target, alias ? { ...verified, directory: alias } : verified, access);
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=browserWorktrees.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StoredAttachment } from './attachmentUpload.js';
|
|
2
|
+
export declare const PHONE_DRAFT_TTL_MS: number;
|
|
3
|
+
export interface PhoneDraft extends StoredAttachment {
|
|
4
|
+
workflowId: string;
|
|
5
|
+
owner: string;
|
|
6
|
+
expiresAt: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function phoneFilename(name: string): string;
|
|
9
|
+
export declare function rememberPhoneDraft(entry: PhoneDraft): Promise<void>;
|
|
10
|
+
export declare function phoneDraftForOwner(id: string, owner: string): PhoneDraft | null;
|
|
11
|
+
export declare function discardPhoneDraft(entry: PhoneDraft): Promise<void>;
|
|
12
|
+
export declare function adoptPhoneDrafts(workflowId: string, attachments: readonly string[] | undefined): boolean;
|
|
13
|
+
export declare function sweepPhoneDrafts(): Promise<void>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { lstatSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { basename, join } from 'node:path';
|
|
3
|
+
import { arcoHome } from '../arcoHome.js';
|
|
4
|
+
import { UPLOADS_DIR, UUID_PATTERN } from '../server/constants.js';
|
|
5
|
+
import { ensureStorageRoot } from '../storageRoot.js';
|
|
6
|
+
export const PHONE_DRAFT_TTL_MS = 30 * 60_000;
|
|
7
|
+
const ROOT_NAME = '.phone-upload-drafts';
|
|
8
|
+
function recordsDirectory() {
|
|
9
|
+
return join(arcoHome(), ROOT_NAME);
|
|
10
|
+
}
|
|
11
|
+
function recordPath(fileId) {
|
|
12
|
+
if (!UUID_PATTERN.test(fileId))
|
|
13
|
+
throw new Error('Invalid phone upload ID');
|
|
14
|
+
return join(recordsDirectory(), fileId + '.json');
|
|
15
|
+
}
|
|
16
|
+
function safeName(filename) {
|
|
17
|
+
return typeof filename === 'string' && /^[\p{L}\p{N}_()-][\p{L}\p{N} ._()-]{0,119}$/u.test(filename);
|
|
18
|
+
}
|
|
19
|
+
export function phoneFilename(name) {
|
|
20
|
+
const cleaned = name.normalize('NFC').replace(/[^\p{L}\p{N} ._()-]/gu, '_').replace(/^[. ]+|[. ]+$/g, '');
|
|
21
|
+
// A Windows file system also observes the extension after Unicode sanitizing.
|
|
22
|
+
return safeName(cleaned) ? cleaned : '';
|
|
23
|
+
}
|
|
24
|
+
function readRecord(id) {
|
|
25
|
+
try {
|
|
26
|
+
const directory = lstatSync(recordsDirectory());
|
|
27
|
+
if (!directory.isDirectory() || directory.isSymbolicLink())
|
|
28
|
+
return null;
|
|
29
|
+
const target = recordPath(id);
|
|
30
|
+
const stat = lstatSync(target);
|
|
31
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 4096)
|
|
32
|
+
return null;
|
|
33
|
+
const entry = JSON.parse(readFileSync(target, 'utf8'));
|
|
34
|
+
if (entry.fileId !== id || !safeName(entry.filename) || typeof entry.path !== 'string'
|
|
35
|
+
|| basename(entry.path) !== `${id}-${entry.filename}` || typeof entry.owner !== 'string'
|
|
36
|
+
|| typeof entry.workflowId !== 'string' || typeof entry.expiresAt !== 'number'
|
|
37
|
+
|| !Number.isSafeInteger(entry.expiresAt))
|
|
38
|
+
return null;
|
|
39
|
+
return entry;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export async function rememberPhoneDraft(entry) {
|
|
46
|
+
const directory = await ensureStorageRoot(recordsDirectory());
|
|
47
|
+
writeFileSync(join(directory, entry.fileId + '.json'), JSON.stringify(entry), { flag: 'wx', mode: 0o600 });
|
|
48
|
+
}
|
|
49
|
+
export function phoneDraftForOwner(id, owner) {
|
|
50
|
+
const entry = readRecord(id);
|
|
51
|
+
return entry && entry.owner === owner && entry.expiresAt > Date.now() ? entry : null;
|
|
52
|
+
}
|
|
53
|
+
export async function discardPhoneDraft(entry) {
|
|
54
|
+
const directory = await ensureStorageRoot(UPLOADS_DIR, false);
|
|
55
|
+
// Send may take ownership while the directory check is in flight.
|
|
56
|
+
if (readRecord(entry.fileId)?.path !== entry.path)
|
|
57
|
+
return;
|
|
58
|
+
const path = join(directory, `${entry.fileId}-${entry.filename}`);
|
|
59
|
+
// Delete only a filename generated for this phone receipt, never a path
|
|
60
|
+
// supplied by the phone or stored in the receipt.
|
|
61
|
+
for (const name of [path, path + '.model.png', path + '.model.jpg']) {
|
|
62
|
+
try {
|
|
63
|
+
unlinkSync(name);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (error.code !== 'ENOENT')
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
forgetRecord(entry.fileId);
|
|
71
|
+
}
|
|
72
|
+
function forgetRecord(fileId) {
|
|
73
|
+
try {
|
|
74
|
+
unlinkSync(recordPath(fileId));
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error.code !== 'ENOENT')
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Called only at the send acceptance points. Removing the cleanup receipt
|
|
82
|
+
// before queuing or starting the turn keeps sent attachments in history.
|
|
83
|
+
export function adoptPhoneDrafts(workflowId, attachments) {
|
|
84
|
+
const entries = [];
|
|
85
|
+
for (const path of attachments ?? []) {
|
|
86
|
+
const id = basename(path).slice(0, 36);
|
|
87
|
+
if (!UUID_PATTERN.test(id))
|
|
88
|
+
continue;
|
|
89
|
+
const entry = readRecord(id);
|
|
90
|
+
if (!entry)
|
|
91
|
+
continue;
|
|
92
|
+
if (entry.workflowId !== workflowId || entry.path !== path || entry.expiresAt <= Date.now())
|
|
93
|
+
return false;
|
|
94
|
+
entries.push(entry);
|
|
95
|
+
}
|
|
96
|
+
for (const entry of entries)
|
|
97
|
+
forgetRecord(entry.fileId);
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
let sweeping = false;
|
|
101
|
+
export async function sweepPhoneDrafts() {
|
|
102
|
+
if (sweeping)
|
|
103
|
+
return;
|
|
104
|
+
sweeping = true;
|
|
105
|
+
try {
|
|
106
|
+
const directory = lstatSync(recordsDirectory());
|
|
107
|
+
if (!directory.isDirectory() || directory.isSymbolicLink())
|
|
108
|
+
return;
|
|
109
|
+
for (const file of readdirSync(recordsDirectory())) {
|
|
110
|
+
if (!file.endsWith('.json'))
|
|
111
|
+
continue;
|
|
112
|
+
const entry = readRecord(file.slice(0, -5));
|
|
113
|
+
if (entry && entry.expiresAt <= Date.now())
|
|
114
|
+
await discardPhoneDraft(entry).catch(() => { });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// No phone uploads yet, or managed storage is unavailable.
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
sweeping = false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
setInterval(() => { void sweepPhoneDrafts(); }, 30_000).unref();
|
|
125
|
+
//# sourceMappingURL=phoneUploadDrafts.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type IncomingMessage, type Server, type ServerResponse } from 'node:http';
|
|
2
|
+
export interface PhoneListener {
|
|
3
|
+
origins: string[];
|
|
4
|
+
close(): void;
|
|
5
|
+
}
|
|
6
|
+
type Handler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
7
|
+
/** An HTTP server that answers only the phone upload path and refuses everything else. */
|
|
8
|
+
export declare function createPhoneServer(handler: Handler): Server;
|
|
9
|
+
export declare function _bindPhoneListenerForTest(map: ((address: string) => string) | null): void;
|
|
10
|
+
/**
|
|
11
|
+
* Bind one phone server per address. Arco's own port is tried first, so a
|
|
12
|
+
* firewall rule for that port also covers phones; when it is taken on an
|
|
13
|
+
* address, the system picks a free port there. Addresses that cannot be
|
|
14
|
+
* bound are left out.
|
|
15
|
+
*/
|
|
16
|
+
export declare function startPhoneListener(addresses: string[], preferredPort: number, handler: Handler): Promise<PhoneListener>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
const PHONE_PATH = '/phone-upload';
|
|
3
|
+
function notFound(res) {
|
|
4
|
+
res.writeHead(404, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Connection: 'close' });
|
|
5
|
+
res.end(JSON.stringify({ error: 'Not found.' }));
|
|
6
|
+
}
|
|
7
|
+
/** An HTTP server that answers only the phone upload path and refuses everything else. */
|
|
8
|
+
export function createPhoneServer(handler) {
|
|
9
|
+
const server = http.createServer((req, res) => {
|
|
10
|
+
if (req.url !== PHONE_PATH || req.headers.upgrade)
|
|
11
|
+
return notFound(res);
|
|
12
|
+
handler(req, res).catch(() => {
|
|
13
|
+
if (!res.headersSent)
|
|
14
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
15
|
+
res.end();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
server.on('upgrade', (_req, socket) => { socket.destroy(); });
|
|
19
|
+
server.headersTimeout = 15_000;
|
|
20
|
+
server.requestTimeout = 5 * 60_000;
|
|
21
|
+
server.keepAliveTimeout = 5_000;
|
|
22
|
+
server.maxConnections = 32;
|
|
23
|
+
return server;
|
|
24
|
+
}
|
|
25
|
+
// Tests bind the listener to loopback while it reports a fixture private
|
|
26
|
+
// address, so the operator route can be exercised without that interface.
|
|
27
|
+
let bindAddressForTest = null;
|
|
28
|
+
export function _bindPhoneListenerForTest(map) {
|
|
29
|
+
bindAddressForTest = map;
|
|
30
|
+
}
|
|
31
|
+
function listen(server, address, port) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
server.once('error', reject);
|
|
34
|
+
server.listen(port, address, () => {
|
|
35
|
+
server.off('error', reject);
|
|
36
|
+
const bound = server.address();
|
|
37
|
+
resolve(typeof bound === 'object' && bound ? bound.port : port);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Bind one phone server per address. Arco's own port is tried first, so a
|
|
43
|
+
* firewall rule for that port also covers phones; when it is taken on an
|
|
44
|
+
* address, the system picks a free port there. Addresses that cannot be
|
|
45
|
+
* bound are left out.
|
|
46
|
+
*/
|
|
47
|
+
export async function startPhoneListener(addresses, preferredPort, handler) {
|
|
48
|
+
const servers = [];
|
|
49
|
+
const origins = [];
|
|
50
|
+
for (const address of addresses) {
|
|
51
|
+
let reason = '';
|
|
52
|
+
for (const port of preferredPort ? [preferredPort, 0] : [0]) {
|
|
53
|
+
const server = createPhoneServer(handler);
|
|
54
|
+
try {
|
|
55
|
+
const bound = await listen(server, bindAddressForTest?.(address) ?? address, port);
|
|
56
|
+
server.on('error', error => console.warn(`[arco] phone upload listener: ${error.message}`));
|
|
57
|
+
servers.push(server);
|
|
58
|
+
origins.push(new URL(`http://${address}:${bound}`).origin);
|
|
59
|
+
reason = '';
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
reason = e.code ?? 'unknown error';
|
|
64
|
+
server.close();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// The error code only: the address itself stays out of the log.
|
|
68
|
+
if (reason)
|
|
69
|
+
console.warn(`[arco] phone upload listener could not bind a private address: ${reason}`);
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
origins,
|
|
73
|
+
close() {
|
|
74
|
+
for (const server of servers) {
|
|
75
|
+
server.close();
|
|
76
|
+
server.closeIdleConnections();
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=phoneUploadListener.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
/**
|
|
3
|
+
* The IPv4 private network and tailnet addresses of this machine that a
|
|
4
|
+
* phone could reach, container bridges excluded. The temporary phone
|
|
5
|
+
* listener binds each one separately, never a wildcard.
|
|
6
|
+
*/
|
|
7
|
+
export declare function phoneListenerAddresses(): string[];
|
|
8
|
+
export declare function phoneUploadOrigins(req: IncomingMessage): string[];
|
|
9
|
+
export declare function privatePhoneOrigin(req: IncomingMessage): string | undefined;
|