arco-workbench 0.1.3 → 0.1.4
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 +1 -1
- package/README.md +5 -1
- package/client/dist/assets/{PhosphorBackdrop-CkVIGkeX.js → PhosphorBackdrop-CNumba2X.js} +1 -1
- package/client/dist/assets/{ThemedBackgroundShaderImpl-DHF7CnpE.js → ThemedBackgroundShaderImpl-DX5KyCt3.js} +1 -1
- package/client/dist/assets/{XtermView-SY0UcZUS.js → XtermView-DhS5g8Rt.js} +1 -1
- package/client/dist/assets/{galleryEditor-Ca4F8HiM.js → galleryEditor-fPb76Cjv.js} +1 -1
- package/client/dist/assets/index-CjkHb-_n.js +592 -0
- package/client/dist/assets/index-DIbh3ae5.css +1 -0
- package/client/dist/index.html +2 -2
- package/client/src/App.tsx +2 -0
- package/client/src/alerts/desktopAlerts.ts +13 -1
- package/client/src/brief/briefFacts.ts +22 -0
- package/client/src/brief/briefFromStore.ts +7 -2
- package/client/src/components/ArtifactMoveDialog.tsx +64 -0
- package/client/src/components/BriefControl.tsx +38 -47
- package/client/src/components/CatchMeUp.tsx +25 -25
- package/client/src/components/CheckpointActions.tsx +7 -4
- package/client/src/components/ClusterComposerButtons.tsx +6 -3
- package/client/src/components/ClusterPlanTab.tsx +15 -1
- package/client/src/components/ClusterRightPanel/AutoPickupControl.tsx +6 -2
- package/client/src/components/ClusterTab.tsx +33 -3
- package/client/src/components/ClusterTaskBoardTab.tsx +62 -8
- package/client/src/components/DialogShell.tsx +115 -0
- package/client/src/components/DocsUpdateDialog.tsx +16 -42
- package/client/src/components/ForwardMessages.tsx +28 -32
- package/client/src/components/GitDialog.tsx +52 -52
- package/client/src/components/GitOtherWork.tsx +4 -2
- package/client/src/components/HandoffDialog.tsx +19 -45
- package/client/src/components/Home/HomeView.tsx +36 -8
- package/client/src/components/Home/home.css +7 -0
- package/client/src/components/KeepButton.tsx +23 -0
- package/client/src/components/MdTuneupDialog.tsx +52 -51
- package/client/src/components/MemberCard.tsx +4 -1
- package/client/src/components/MemberPane.tsx +1 -1
- package/client/src/components/NotificationCenter.tsx +4 -3
- package/client/src/components/NotificationChannelsSettings.tsx +25 -7
- package/client/src/components/PlanCandidateBanner.tsx +111 -57
- package/client/src/components/PlanComposerDialog.tsx +55 -87
- package/client/src/components/ProjectStateNotice.tsx +60 -0
- package/client/src/components/PublicProjectBox.tsx +25 -0
- package/client/src/components/ResearchDialog.tsx +15 -24
- package/client/src/components/ReviewDialog.tsx +32 -57
- package/client/src/components/RightPanel/OutputsPanel.tsx +4 -0
- package/client/src/components/RightPanel/PlanTab.tsx +24 -2
- package/client/src/components/RightPanel/UsageTab.tsx +77 -1
- package/client/src/components/SkillEditorDialog.tsx +38 -73
- package/client/src/components/SpawnDialog.tsx +19 -41
- package/client/src/components/StorageWarnings.tsx +21 -0
- package/client/src/components/SystemHeader.tsx +2 -2
- package/client/src/components/TerminalInput.tsx +6 -2
- package/client/src/components/TidyComposer.tsx +24 -41
- package/client/src/components/TranscriptSendDialog.tsx +151 -202
- package/client/src/components/UtilityAgentPicker.tsx +4 -2
- package/client/src/components/WorkflowCreator/index.tsx +2 -0
- package/client/src/components/WorkflowView.tsx +4 -1
- package/client/src/components/clusterNeedsYou.ts +35 -3
- package/client/src/components/compare/CompareDialog.tsx +26 -2
- package/client/src/components/terminalInput/planDraft.ts +33 -4
- package/client/src/components/utilityResult.ts +5 -1
- package/client/src/explorer/ExplorerApp.tsx +5 -2
- package/client/src/explorer/PlansLens.tsx +60 -19
- package/client/src/explorer/StorageLens.tsx +275 -0
- package/client/src/explorer/launch.ts +3 -3
- package/client/src/explorer/plansGrouping.ts +15 -0
- package/client/src/help/content/cluster.tsx +42 -7
- package/client/src/help/content/composer.tsx +26 -6
- package/client/src/help/content/header.tsx +16 -14
- package/client/src/help/content/misc.tsx +141 -6
- package/client/src/help/content/rightPanel.tsx +16 -0
- package/client/src/help/content/settings.tsx +4 -4
- package/client/src/help/manualSections/actions.tsx +19 -4
- package/client/src/help/manualSections/clusters.tsx +29 -16
- package/client/src/help/manualSections/configuration.tsx +6 -4
- package/client/src/help/manualSections/maintenance.tsx +27 -5
- package/client/src/help/manualSections/plans.tsx +96 -2
- package/client/src/help/manualSections/powerFeatures.tsx +2 -2
- package/client/src/help/manualSections/reference.tsx +6 -0
- package/client/src/help/manualSections/workspace.tsx +9 -5
- package/client/src/stores/appStore.ts +10 -1
- package/client/src/stores/appStore.types.ts +2 -0
- package/client/src/stores/mdTuneupStore.ts +5 -4
- package/client/src/stores/memoryTrim.ts +18 -2
- package/client/src/stores/storageWarningStore.ts +18 -0
- package/client/src/utils/gitDialogMemory.ts +26 -0
- package/client/src/utils/historyEvents.ts +1 -0
- package/client/src/utils/homeModel.ts +19 -0
- package/client/src/utils/publicProject.ts +56 -0
- package/client/src/ws/handleServerMessage.ts +7 -2
- package/docs/ARCHITECTURE.md +1 -1
- package/docs/CHECKPOINTS.md +2 -0
- package/docs/CLIENT.md +29 -11
- package/docs/FEATURES.md +14 -11
- package/docs/GETTING_STARTED.md +7 -7
- package/docs/GLOSSARY.md +3 -3
- package/docs/GOTCHAS.md +3 -2
- package/docs/HTTP_API.md +31 -1
- package/docs/NOTIFICATIONS.md +13 -14
- package/docs/OPERATIONS.md +27 -1
- package/docs/OPERATOR_ACTIONS.md +1 -1
- package/docs/OUTPUTS.md +9 -0
- package/docs/PERSISTENCE.md +34 -4
- package/docs/PLAN_OR_BOARD.md +7 -0
- package/docs/PRIMITIVES.md +3 -3
- package/docs/PROTOCOL.md +14 -4
- package/docs/PROTOCOL_CLUSTER.md +3 -2
- package/docs/SERVICE_MODE.md +5 -1
- package/docs/SETTINGS.md +8 -6
- package/docs/STORAGE_PLAN.md +324 -0
- package/docs/TASK_LEDGER.md +5 -4
- package/native/linux-arm64/manifest.json +1 -1
- package/node_modules/@arco/shared/dist/index.d.ts +2 -0
- package/node_modules/@arco/shared/dist/index.js +2 -0
- package/node_modules/@arco/shared/dist/protocol/autoPickup.d.ts +1 -1
- package/node_modules/@arco/shared/dist/protocol/autoPickup.js +1 -1
- package/node_modules/@arco/shared/dist/protocol/checkpoints.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/clusters.d.ts +2 -1
- package/node_modules/@arco/shared/dist/protocol/index.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/index.js +1 -0
- package/node_modules/@arco/shared/dist/protocol/mdTuneup.d.ts +6 -0
- package/node_modules/@arco/shared/dist/protocol/notifications.d.ts +2 -1
- package/node_modules/@arco/shared/dist/protocol/notifications.js +3 -2
- package/node_modules/@arco/shared/dist/protocol/plans.d.ts +2 -0
- package/node_modules/@arco/shared/dist/protocol/serverMessages.d.ts +2 -1
- package/node_modules/@arco/shared/dist/protocol/storage.d.ts +21 -0
- package/node_modules/@arco/shared/dist/protocol/storage.js +3 -0
- package/node_modules/@arco/shared/dist/protocol/tasks.d.ts +3 -0
- package/node_modules/@arco/shared/dist/protocol/utilityAgent.d.ts +2 -2
- package/node_modules/@arco/shared/dist/protocol/utilityAgent.js +2 -2
- package/node_modules/@arco/shared/dist/publicGuardrails.d.ts +7 -0
- package/node_modules/@arco/shared/dist/publicGuardrails.js +47 -0
- package/node_modules/@arco/shared/dist/publicSafetyRules.d.ts +1 -0
- package/node_modules/@arco/shared/dist/publicSafetyRules.js +6 -0
- package/node_modules/@arco/shared/package.json +1 -1
- package/package.json +3 -2
- package/scripts/packaging/arco.mjs +17 -1
- package/scripts/packaging/services.mjs +35 -5
- package/scripts/packaging/storage.mjs +125 -0
- package/scripts/packaging/update.mjs +3 -3
- package/server/dist/artifactCopy.d.ts +26 -0
- package/server/dist/artifactCopy.js +398 -0
- package/server/dist/atomicFile.d.ts +1 -0
- package/server/dist/atomicFile.js +1 -1
- package/server/dist/attention.d.ts +1 -1
- package/server/dist/attention.js +10 -13
- package/server/dist/catchUp.d.ts +2 -0
- package/server/dist/catchUp.js +46 -23
- package/server/dist/clusterPeerOps.d.ts +2 -0
- package/server/dist/clusterPeerOps.js +2 -0
- package/server/dist/clusterSnapshots.js +22 -12
- package/server/dist/eventLog.d.ts +55 -0
- package/server/dist/eventLog.js +792 -0
- package/server/dist/explorerLaunch.d.ts +4 -1
- package/server/dist/explorerLaunch.js +3 -2
- package/server/dist/explorerPlans.d.ts +4 -0
- package/server/dist/explorerPlans.js +27 -2
- package/server/dist/http/clusterRoutes.js +2 -0
- package/server/dist/http/explorerRoutes.js +2 -1
- package/server/dist/http/publicProjectRoutes.d.ts +2 -0
- package/server/dist/http/publicProjectRoutes.js +68 -0
- package/server/dist/http/router.js +6 -0
- package/server/dist/http/storageRoutes.d.ts +2 -0
- package/server/dist/http/storageRoutes.js +254 -0
- package/server/dist/http/usageStatsRoutes.js +3 -12
- package/server/dist/index.js +4 -0
- package/server/dist/keepStore.d.ts +16 -0
- package/server/dist/keepStore.js +119 -0
- package/server/dist/management/clusterActivity.js +6 -20
- package/server/dist/management/initHubLink.js +10 -43
- package/server/dist/mcp/clusterMcpTools.js +8 -1
- package/server/dist/notifications.d.ts +3 -1
- package/server/dist/notifications.js +5 -4
- package/server/dist/outputStore.d.ts +1 -0
- package/server/dist/outputStore.js +1 -1
- package/server/dist/outputs.js +39 -8
- package/server/dist/planHistory.d.ts +3 -0
- package/server/dist/planHistory.js +60 -0
- package/server/dist/primitives/runMdTuneup.d.ts +5 -1
- package/server/dist/primitives/runMdTuneup.js +43 -2
- package/server/dist/project/taskLedger.d.ts +4 -0
- package/server/dist/project/taskLedger.js +19 -0
- package/server/dist/providers/claude-native/peerTools.js +4 -0
- package/server/dist/providers/claude-native/resumeSummary.js +30 -19
- package/server/dist/providers/index.js +8 -13
- package/server/dist/providers/localProviderQueue.d.ts +2 -0
- package/server/dist/providers/localProviderQueue.js +11 -0
- package/server/dist/publicProject.d.ts +54 -0
- package/server/dist/publicProject.js +135 -0
- package/server/dist/recall/index.js +22 -23
- package/server/dist/server/broadcast.d.ts +2 -1
- package/server/dist/server/broadcast.js +56 -1
- package/server/dist/smartPickupAdapters.d.ts +7 -0
- package/server/dist/smartPickupAdapters.js +172 -8
- package/server/dist/storageActions.d.ts +50 -0
- package/server/dist/storageActions.js +326 -0
- package/server/dist/storageArchive.d.ts +24 -0
- package/server/dist/storageArchive.js +358 -0
- package/server/dist/storageOverview.d.ts +47 -0
- package/server/dist/storageOverview.js +197 -0
- package/server/dist/storageReport.d.ts +48 -0
- package/server/dist/storageReport.js +185 -0
- package/server/dist/storageWarnings.d.ts +4 -0
- package/server/dist/storageWarnings.js +96 -0
- package/server/dist/workers/limits.js +4 -1
- package/server/dist/workflowStore.d.ts +2 -0
- package/server/dist/workflowStore.js +88 -72
- package/server/dist/workflows/purgeWorkflow.d.ts +1 -0
- package/server/dist/workflows/purgeWorkflow.js +15 -2
- package/server/dist/workflows/sessionDiscovery.js +5 -17
- package/server/dist/workflows/sessionIndex.js +22 -17
- package/server/dist/ws/taskLedgerHandlers.js +8 -3
- package/server/dist/ws/workflowHandlers.js +5 -4
- package/server/package.json +1 -1
- package/server/src/artifactCopy.ts +254 -0
- package/server/src/atomicFile.ts +1 -1
- package/server/src/attention.ts +9 -10
- package/server/src/catchUp.ts +37 -15
- package/server/src/clusterPeerOps.ts +5 -0
- package/server/src/clusterSnapshots.ts +20 -13
- package/server/src/eventLog.ts +571 -0
- package/server/src/explorerLaunch.ts +3 -2
- package/server/src/explorerPlans.ts +22 -2
- package/server/src/http/clusterRoutes.ts +4 -1
- package/server/src/http/explorerRoutes.ts +2 -1
- package/server/src/http/publicProjectRoutes.ts +54 -0
- package/server/src/http/router.ts +4 -0
- package/server/src/http/storageRoutes.ts +187 -0
- package/server/src/http/usageStatsRoutes.ts +3 -11
- package/server/src/index.ts +4 -0
- package/server/src/keepStore.ts +102 -0
- package/server/src/management/clusterActivity.ts +6 -16
- package/server/src/management/initHubLink.ts +10 -39
- package/server/src/mcp/clusterMcpTools.ts +8 -2
- package/server/src/notifications.ts +4 -3
- package/server/src/outputStore.ts +5 -2
- package/server/src/outputs.ts +30 -6
- package/server/src/planHistory.ts +48 -0
- package/server/src/primitives/runMdTuneup.ts +32 -2
- package/server/src/project/taskLedger.ts +20 -0
- package/server/src/providers/claude-native/peerTools.ts +4 -0
- package/server/src/providers/claude-native/resumeSummary.ts +32 -18
- package/server/src/providers/index.ts +2 -16
- package/server/src/providers/localProviderQueue.ts +13 -0
- package/server/src/publicProject.ts +142 -0
- package/server/src/recall/index.ts +4 -9
- package/server/src/server/broadcast.ts +53 -1
- package/server/src/smartPickupAdapters.ts +128 -5
- package/server/src/storageActions.ts +216 -0
- package/server/src/storageArchive.ts +277 -0
- package/server/src/storageOverview.ts +184 -0
- package/server/src/storageReport.ts +210 -0
- package/server/src/storageWarnings.ts +84 -0
- package/server/src/workers/limits.ts +4 -1
- package/server/src/workflowStore.ts +78 -61
- package/server/src/workflows/purgeWorkflow.ts +12 -3
- package/server/src/workflows/sessionDiscovery.ts +5 -13
- package/server/src/workflows/sessionIndex.ts +5 -9
- package/server/src/ws/taskLedgerHandlers.ts +8 -3
- package/server/src/ws/workflowHandlers.ts +5 -4
- package/shared/dist/index.d.ts +2 -0
- package/shared/dist/index.js +2 -0
- package/shared/dist/protocol/autoPickup.d.ts +1 -1
- package/shared/dist/protocol/autoPickup.js +1 -1
- package/shared/dist/protocol/checkpoints.d.ts +1 -0
- package/shared/dist/protocol/clusters.d.ts +2 -1
- package/shared/dist/protocol/index.d.ts +1 -0
- package/shared/dist/protocol/index.js +1 -0
- package/shared/dist/protocol/mdTuneup.d.ts +6 -0
- package/shared/dist/protocol/notifications.d.ts +2 -1
- package/shared/dist/protocol/notifications.js +3 -2
- package/shared/dist/protocol/plans.d.ts +2 -0
- package/shared/dist/protocol/serverMessages.d.ts +2 -1
- package/shared/dist/protocol/storage.d.ts +21 -0
- package/shared/dist/protocol/storage.js +3 -0
- package/shared/dist/protocol/tasks.d.ts +3 -0
- package/shared/dist/protocol/utilityAgent.d.ts +2 -2
- package/shared/dist/protocol/utilityAgent.js +2 -2
- package/shared/dist/publicGuardrails.d.ts +7 -0
- package/shared/dist/publicGuardrails.js +47 -0
- package/shared/dist/publicSafetyRules.d.ts +1 -0
- package/shared/dist/publicSafetyRules.js +6 -0
- package/shared/src/index.ts +3 -0
- package/shared/src/protocol/autoPickup.ts +1 -1
- package/shared/src/protocol/checkpoints.ts +4 -0
- package/shared/src/protocol/clusters.ts +6 -1
- package/shared/src/protocol/index.ts +1 -0
- package/shared/src/protocol/mdTuneup.ts +5 -0
- package/shared/src/protocol/notifications.ts +6 -2
- package/shared/src/protocol/plans.ts +2 -0
- package/shared/src/protocol/serverMessages.ts +2 -0
- package/shared/src/protocol/storage.ts +35 -0
- package/shared/src/protocol/tasks.ts +6 -0
- package/shared/src/protocol/utilityAgent.ts +2 -2
- package/shared/src/publicGuardrails.ts +50 -0
- package/shared/src/publicSafetyRules.ts +5 -0
- package/client/dist/assets/index-CcNtMA2y.js +0 -546
- package/client/dist/assets/index-Dl8tYsSp.css +0 -1
|
@@ -11,4 +11,7 @@ export type ExplorerLaunchResult = {
|
|
|
11
11
|
code: 'spawn-failed';
|
|
12
12
|
error: string;
|
|
13
13
|
};
|
|
14
|
-
export declare function launchExplorerWindow(origin: string
|
|
14
|
+
export declare function launchExplorerWindow(origin: string, options?: {
|
|
15
|
+
lens?: 'plans';
|
|
16
|
+
cwd?: string;
|
|
17
|
+
}): Promise<ExplorerLaunchResult>;
|
|
@@ -86,8 +86,9 @@ function spawnDetachedProbe(bin, args, env) {
|
|
|
86
86
|
// by the route from the request Host/Origin so dev (5173) and prod (3001)
|
|
87
87
|
// both resolve without config. Fail-soft: every non-launch path returns a
|
|
88
88
|
// structured result so the client engages its popup fallback (never a throw).
|
|
89
|
-
export async function launchExplorerWindow(origin) {
|
|
90
|
-
const
|
|
89
|
+
export async function launchExplorerWindow(origin, options = {}) {
|
|
90
|
+
const params = new URLSearchParams({ app: 'explorer', ...(options.lens ? { lens: options.lens } : {}), ...(options.cwd ? { cwd: options.cwd } : {}) });
|
|
91
|
+
const url = `${origin.replace(/\/$/, '')}/?${params}`;
|
|
91
92
|
// Prefer the service/desktop env so a systemd user unit inherits DISPLAY /
|
|
92
93
|
// WAYLAND_DISPLAY / DBUS; fall back to DISPLAY=:0 when the unit carries
|
|
93
94
|
// neither (§3 — the prod unit may not export a display).
|
|
@@ -6,10 +6,35 @@
|
|
|
6
6
|
// `cwd` is the known-cwds string as recorded (not its realpath): the plan
|
|
7
7
|
// routes and the attached-workflow broadcasts key on the workflow's own cwd
|
|
8
8
|
// string, so a symlinked project must round-trip the same spelling.
|
|
9
|
-
import { basename } from 'path';
|
|
9
|
+
import { basename, join } from 'path';
|
|
10
|
+
import { open } from 'node:fs/promises';
|
|
10
11
|
import { listPlans, listPlanRefs } from './planStore.js';
|
|
11
12
|
import { readKnownCwds, realpathWithinHome } from './explorerArtifacts.js';
|
|
12
13
|
import * as clusterStore from './clusterStore.js';
|
|
14
|
+
export function countPlanCheckboxes(body) {
|
|
15
|
+
const boxes = [...body.matchAll(/^\s*[-*+]\s+\[([ xX])\]/gm)];
|
|
16
|
+
return { checkboxTotal: boxes.length, checkboxDone: boxes.filter((m) => m[1].toLowerCase() === 'x').length };
|
|
17
|
+
}
|
|
18
|
+
async function checkboxCounts(cwd, id) {
|
|
19
|
+
if (!/^[a-zA-Z0-9-]{1,64}$/.test(id))
|
|
20
|
+
return { checkboxTotal: 0, checkboxDone: 0 };
|
|
21
|
+
let file;
|
|
22
|
+
try {
|
|
23
|
+
file = await open(join(cwd, '.arco', 'plans', `${id}.md`), 'r');
|
|
24
|
+
const buffer = Buffer.alloc(256 * 1024 + 1);
|
|
25
|
+
const { bytesRead } = await file.read(buffer, 0, buffer.length, 0);
|
|
26
|
+
// An incomplete body cannot safely establish that all boxes are checked.
|
|
27
|
+
if (bytesRead > 256 * 1024)
|
|
28
|
+
return { checkboxTotal: 0, checkboxDone: 0 };
|
|
29
|
+
return countPlanCheckboxes(buffer.subarray(0, bytesRead).toString('utf8'));
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return { checkboxTotal: 0, checkboxDone: 0 };
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
await file?.close();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
13
38
|
export async function collectPlanLibrary() {
|
|
14
39
|
const known = [...new Set(await readKnownCwds())];
|
|
15
40
|
const clusters = await clusterStore.loadAllClustersFromDisk().catch(() => []);
|
|
@@ -26,7 +51,7 @@ export async function collectPlanLibrary() {
|
|
|
26
51
|
.filter((c) => c.cwd === cwd && c.planId === p.id)
|
|
27
52
|
.map((c) => ({ clusterId: c.clusterId, name: c.name || `${c.clusterId.slice(0, 8)} cluster` }));
|
|
28
53
|
const openSpan = (p.attachments ?? []).some((a) => a.detachedAt === null);
|
|
29
|
-
return { ...p, refCount: refs.length, attached: openSpan || bound.length > 0, clusters: bound };
|
|
54
|
+
return { ...p, ...await checkboxCounts(cwd, p.id), refCount: refs.length, attached: openSpan || bound.length > 0, clusters: bound };
|
|
30
55
|
}));
|
|
31
56
|
out.push({ cwd, name: basename(cwd) || cwd, plans: entries });
|
|
32
57
|
}
|
|
@@ -385,6 +385,7 @@ export async function tryHandleClusterRoutes(req, res, deps) {
|
|
|
385
385
|
...(typeof body.reviewRequired === 'boolean' ? { reviewRequired: body.reviewRequired } : {}),
|
|
386
386
|
...(typeof body.goalMode === 'boolean' ? { goalMode: body.goalMode } : {}),
|
|
387
387
|
...(typeof body.goalMaxTurns === 'number' ? { goalMaxTurns: body.goalMaxTurns } : {}),
|
|
388
|
+
...(typeof body.release === 'string' ? { release: body.release } : {}),
|
|
388
389
|
...(typeof body.status === 'string' ? { status: body.status } : {}),
|
|
389
390
|
}, (msg) => broadcastCluster(clusterId, msg));
|
|
390
391
|
if (!result.ok) {
|
|
@@ -544,6 +545,7 @@ export async function tryHandleClusterRoutes(req, res, deps) {
|
|
|
544
545
|
id: typeof body.id === 'string' ? body.id : '',
|
|
545
546
|
...(typeof body.status === 'string' ? { status: body.status } : {}),
|
|
546
547
|
...(typeof body.notes === 'string' ? { notes: body.notes } : {}),
|
|
548
|
+
...(typeof body.release === 'string' ? { release: body.release } : {}),
|
|
547
549
|
// §D3 — advisory sign-off; peerTaskUpdate validates + stamps author.
|
|
548
550
|
...(body.signoff !== undefined ? { signoff: body.signoff } : {}),
|
|
549
551
|
}, (msg) => broadcastCluster(clusterId, msg));
|
|
@@ -39,7 +39,8 @@ export async function tryHandleExplorerRoutes(req, res) {
|
|
|
39
39
|
// window.open. A genuinely unexpected error still degrades to a soft result.
|
|
40
40
|
if (url.startsWith('/api/explorer/open') && req.method === 'POST') {
|
|
41
41
|
try {
|
|
42
|
-
const
|
|
42
|
+
const params = new URL(url, 'http://localhost').searchParams;
|
|
43
|
+
const result = await launchExplorerWindow(deriveOrigin(req), { lens: params.get('lens') === 'plans' ? 'plans' : undefined, cwd: params.get('cwd') || undefined });
|
|
43
44
|
return sendJson(res, 200, result);
|
|
44
45
|
}
|
|
45
46
|
catch (err) {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// /api/public-project -- guardrails for public projects (server/src/publicProject.ts).
|
|
2
|
+
// GET /api/public-project/remote?path=... -> { state: 'none' | 'hosted' | 'public', host? }
|
|
3
|
+
// GET /api/public-project/state?path=... -> project state report
|
|
4
|
+
// POST /api/public-project/restore-ignore { path } -> { ok, backup? }
|
|
5
|
+
// POST /api/public-project/stop-tracking { path } -> { ok, removed }
|
|
6
|
+
import { statSync } from 'node:fs';
|
|
7
|
+
import { isAbsolute } from 'node:path';
|
|
8
|
+
import { assertSafePath } from '../fileAccessPolicy.js';
|
|
9
|
+
import { checkProjectState, restoreIgnoreFile, stopTrackingState, suggestFromRemote } from '../publicProject.js';
|
|
10
|
+
function sendJson(res, code, body) {
|
|
11
|
+
res.writeHead(code, { 'Content-Type': 'application/json' });
|
|
12
|
+
res.end(JSON.stringify(body));
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
function validDir(value) {
|
|
16
|
+
if (typeof value !== 'string' || !isAbsolute(value))
|
|
17
|
+
return null;
|
|
18
|
+
try {
|
|
19
|
+
assertSafePath(value);
|
|
20
|
+
return statSync(value).isDirectory() ? value : null;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function readPath(req) {
|
|
27
|
+
const chunks = [];
|
|
28
|
+
let size = 0;
|
|
29
|
+
for await (const chunk of req) {
|
|
30
|
+
size += chunk.length;
|
|
31
|
+
if (size > 16 * 1024)
|
|
32
|
+
return null;
|
|
33
|
+
chunks.push(chunk);
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf-8')).path;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export async function tryHandlePublicProjectRoutes(req, res) {
|
|
43
|
+
const url = new URL(req.url || '/', 'http://localhost');
|
|
44
|
+
if (!url.pathname.startsWith('/api/public-project/'))
|
|
45
|
+
return false;
|
|
46
|
+
const action = url.pathname.slice('/api/public-project/'.length);
|
|
47
|
+
try {
|
|
48
|
+
if (req.method === 'GET' && (action === 'remote' || action === 'state')) {
|
|
49
|
+
const cwd = validDir(url.searchParams.get('path'));
|
|
50
|
+
if (!cwd)
|
|
51
|
+
return sendJson(res, 400, { error: 'Choose an existing project folder.' });
|
|
52
|
+
return sendJson(res, 200, action === 'remote' ? await suggestFromRemote(cwd) : await checkProjectState(cwd));
|
|
53
|
+
}
|
|
54
|
+
if (req.method === 'POST' && (action === 'restore-ignore' || action === 'stop-tracking')) {
|
|
55
|
+
const cwd = validDir(await readPath(req));
|
|
56
|
+
if (!cwd)
|
|
57
|
+
return sendJson(res, 400, { error: 'Choose an existing project folder.' });
|
|
58
|
+
if (action === 'restore-ignore')
|
|
59
|
+
return sendJson(res, 200, { ok: true, ...restoreIgnoreFile(cwd) });
|
|
60
|
+
return sendJson(res, 200, await stopTrackingState(cwd));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
return sendJson(res, 500, { error: err instanceof Error ? err.message : 'failed' });
|
|
65
|
+
}
|
|
66
|
+
return sendJson(res, 404, { error: 'not found' });
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=publicProjectRoutes.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { tryHandleStorageRoutes } from './storageRoutes.js';
|
|
1
2
|
import { removedProviderReason } from '@arco/shared';
|
|
2
3
|
import { tryHandleAppVersionRoutes } from './appVersionRoutes.js';
|
|
3
4
|
import { tryHandleSmartPickupRoutes } from './smartPickupRoutes.js';
|
|
@@ -76,6 +77,7 @@ import { tryHandleUsageStatsRoutes } from './usageStatsRoutes.js';
|
|
|
76
77
|
import { tryHandleEndpointDiscoveryRoutes } from './endpointDiscoveryRoutes.js';
|
|
77
78
|
import { tryHandleDiagnosticsRoutes } from './diagnosticsRoutes.js';
|
|
78
79
|
import { tryHandleProjectRoutes } from './projectRoutes.js';
|
|
80
|
+
import { tryHandlePublicProjectRoutes } from './publicProjectRoutes.js';
|
|
79
81
|
import { tryHandleProjectTrustRoutes } from './projectTrustRoutes.js';
|
|
80
82
|
import { tryHandleServicesRoutes } from './servicesRoutes.js';
|
|
81
83
|
import { tryHandleMediaOpsRoutes } from './mediaOpsRoutes.js';
|
|
@@ -375,6 +377,8 @@ export async function handleHttpRequest(req, res, deps) {
|
|
|
375
377
|
// /api/usage-stats prefix, so no collision with /api/usage or /api/recall.
|
|
376
378
|
if (await tryHandleUsageStatsRoutes(req, res))
|
|
377
379
|
return;
|
|
380
|
+
if (await tryHandleStorageRoutes(req, res))
|
|
381
|
+
return;
|
|
378
382
|
// D2 — Endpoint auto-discovery (tailscale peers + localhost, bounded ports).
|
|
379
383
|
if (await tryHandleEndpointDiscoveryRoutes(req, res))
|
|
380
384
|
return;
|
|
@@ -386,6 +390,8 @@ export async function handleHttpRequest(req, res, deps) {
|
|
|
386
390
|
// rides HTTP: the global SettingsPanel has no workflowId for the WS message.
|
|
387
391
|
if (await tryHandleProjectRoutes(req, res))
|
|
388
392
|
return;
|
|
393
|
+
if (await tryHandlePublicProjectRoutes(req, res))
|
|
394
|
+
return;
|
|
389
395
|
if (await tryHandleProjectTrustRoutes(req, res))
|
|
390
396
|
return;
|
|
391
397
|
// Ops L1/L2 — Local services. GET /api/services is read-only enumeration of
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { arcoHome } from '../arcoHome.js';
|
|
3
|
+
import { snapshot } from '../workspace.js';
|
|
4
|
+
import { realpathWithinProjects } from '../projects.js';
|
|
5
|
+
import { lstat, readFile } from 'node:fs/promises';
|
|
6
|
+
import { projectCheckpointRoot, scanStorage } from '../storageReport.js';
|
|
7
|
+
import { compressOldLogs, deleteConversation, emptyScratch, StorageActionError } from '../storageActions.js';
|
|
8
|
+
import { sealWorkflowLogNow } from '../workflowStore.js';
|
|
9
|
+
import { archiveConversation, archivePath, listArchives, restoreConversation } from '../storageArchive.js';
|
|
10
|
+
import { isKept, readKeep } from '../keepStore.js';
|
|
11
|
+
import { openWorkflowIds, readPolicy, storageOverview, writePolicy, cachedOverviewAge } from '../storageOverview.js';
|
|
12
|
+
import { purgeWorkflow } from '../workflows/purgeWorkflow.js';
|
|
13
|
+
import { workflows } from '../server/state.js';
|
|
14
|
+
import { addKeep } from '../keepStore.js';
|
|
15
|
+
import { outputDirectory } from '../outputStore.js';
|
|
16
|
+
import { inspectArtifactCopy, copyReviewedArtifact, ignoreCopyDestination } from '../artifactCopy.js';
|
|
17
|
+
const cache = new Map();
|
|
18
|
+
// Not a path, so it cannot collide with a project key.
|
|
19
|
+
const HOME_KEY = '\0home';
|
|
20
|
+
function json(res, status, body) {
|
|
21
|
+
res.writeHead(status, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
22
|
+
res.end(JSON.stringify(body));
|
|
23
|
+
}
|
|
24
|
+
async function readJson(req) {
|
|
25
|
+
let size = 0;
|
|
26
|
+
const chunks = [];
|
|
27
|
+
for await (const chunk of req) {
|
|
28
|
+
size += chunk.length;
|
|
29
|
+
if (size > 64 * 1024)
|
|
30
|
+
return null;
|
|
31
|
+
chunks.push(chunk);
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const v = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}');
|
|
35
|
+
return v && typeof v === 'object' && !Array.isArray(v) ? v : null;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// A registered project whose state folder is not a link; null otherwise.
|
|
42
|
+
async function projectFor(cwd) {
|
|
43
|
+
if (typeof cwd !== 'string' || !path.isAbsolute(cwd))
|
|
44
|
+
return null;
|
|
45
|
+
const key = await realpathWithinProjects(path.resolve(cwd));
|
|
46
|
+
if (!key)
|
|
47
|
+
return null;
|
|
48
|
+
try {
|
|
49
|
+
if ((await lstat(path.join(key, '.arco'))).isSymbolicLink())
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
if (err.code !== 'ENOENT')
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return key;
|
|
57
|
+
}
|
|
58
|
+
const ACTION_STATUS = { keep_unreadable: 409, busy: 409, open: 409, kept: 409, exists: 409, unsafe: 409, not_found: 404, invalid: 400 };
|
|
59
|
+
// Operator storage actions. Each needs `confirm: true`: the client asks first.
|
|
60
|
+
async function handleStorageAction(req, res, action) {
|
|
61
|
+
const body = await readJson(req);
|
|
62
|
+
if (!body)
|
|
63
|
+
return json(res, 400, { error: 'invalid_body' });
|
|
64
|
+
const project = await projectFor(body.path);
|
|
65
|
+
if (!project)
|
|
66
|
+
return json(res, 403, { error: 'Project is unavailable' });
|
|
67
|
+
if (body.confirm !== true)
|
|
68
|
+
return json(res, 400, { error: 'confirmation_required' });
|
|
69
|
+
const workflowId = typeof body.workflowId === 'string' ? body.workflowId : '';
|
|
70
|
+
try {
|
|
71
|
+
if (action === 'compress-logs') {
|
|
72
|
+
const open = openWorkflowIds();
|
|
73
|
+
const result = await compressOldLogs(project, { isOpen: (id) => open.has(id), isBusy: (id) => !!workflows.get(id)?.busy, seal: sealWorkflowLogNow });
|
|
74
|
+
return json(res, 200, { ok: true, ...result });
|
|
75
|
+
}
|
|
76
|
+
if (action === 'copy-review' || action === 'copy-confirm' || action === 'copy-ignore') {
|
|
77
|
+
if (typeof body.itemPath !== 'string' || typeof body.destinationFolder !== 'string')
|
|
78
|
+
return json(res, 400, { error: 'invalid' });
|
|
79
|
+
const declaredPublic = body.publicProject === true;
|
|
80
|
+
const review = await inspectArtifactCopy(project, workflowId, body.itemPath, body.destinationFolder, declaredPublic);
|
|
81
|
+
if (action === 'copy-review')
|
|
82
|
+
return json(res, 200, review);
|
|
83
|
+
if (typeof body.token !== 'string' || body.token !== review.token)
|
|
84
|
+
return json(res, 409, { error: 'The artifact or destination changed. Review it again.' });
|
|
85
|
+
if (action === 'copy-ignore') {
|
|
86
|
+
await ignoreCopyDestination(project, review.target);
|
|
87
|
+
return json(res, 200, { ok: true });
|
|
88
|
+
}
|
|
89
|
+
await copyReviewedArtifact(project, workflowId, body.itemPath, body.destinationFolder, declaredPublic, body.token, undefined, body.confirmUnscanned === true);
|
|
90
|
+
return json(res, 200, { ok: true });
|
|
91
|
+
}
|
|
92
|
+
if (action === 'keep') {
|
|
93
|
+
if (typeof body.itemPath !== 'string' || (body.reason !== 'operator' && body.reason !== 'size-warning'))
|
|
94
|
+
return json(res, 400, { error: 'invalid' });
|
|
95
|
+
const dir = await outputDirectory(project, workflowId);
|
|
96
|
+
const items = await addKeep(dir, body.itemPath, body.reason);
|
|
97
|
+
return json(res, 200, { ok: true, items });
|
|
98
|
+
}
|
|
99
|
+
const busy = !!workflows.get(workflowId)?.busy;
|
|
100
|
+
const open = openWorkflowIds().has(workflowId);
|
|
101
|
+
if (action === 'empty-scratch') {
|
|
102
|
+
const result = await emptyScratch(project, workflowId, { busy });
|
|
103
|
+
return json(res, 200, { ok: true, ...result });
|
|
104
|
+
}
|
|
105
|
+
if (action === 'archive')
|
|
106
|
+
return json(res, 200, { ok: true, ...(await archiveConversation(project, workflowId, { open, busy, by: 'operator' })) });
|
|
107
|
+
if (action === 'restore')
|
|
108
|
+
return json(res, 200, { ok: true, ...(await restoreConversation(project, workflowId)) });
|
|
109
|
+
if (action === 'delete') {
|
|
110
|
+
return json(res, 200, { ok: true, ...(await deleteConversation(project, workflowId, { open, busy, purge: purgeWorkflow, archiveFile: archivePath(project, workflowId) })) });
|
|
111
|
+
}
|
|
112
|
+
return json(res, 404, { error: 'unknown_action' });
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
if (err instanceof StorageActionError)
|
|
116
|
+
return json(res, ACTION_STATUS[err.code], { error: err.code, message: err.message });
|
|
117
|
+
if (action === 'keep' || action.startsWith('copy-'))
|
|
118
|
+
return json(res, 400, { error: err instanceof Error ? err.message : 'The request could not be completed.' });
|
|
119
|
+
console.error('[arco] storage action failed:', err);
|
|
120
|
+
return json(res, 500, { error: 'storage_action_failed' });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export async function tryHandleStorageRoutes(req, res) {
|
|
124
|
+
const url = new URL(req.url ?? '/', 'http://localhost');
|
|
125
|
+
if (url.pathname === '/api/storage/policy') {
|
|
126
|
+
if (req.method === 'GET') {
|
|
127
|
+
json(res, 200, await readPolicy());
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
if (req.method === 'POST') {
|
|
131
|
+
const body = await readJson(req);
|
|
132
|
+
if (!body) {
|
|
133
|
+
json(res, 400, { error: 'invalid_body' });
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
const patch = {};
|
|
137
|
+
for (const key of ['autoArchiveClosedDays', 'budgetGiB', 'budgetNotice'])
|
|
138
|
+
if (key in body)
|
|
139
|
+
patch[key] = body[key];
|
|
140
|
+
json(res, 200, await writePolicy(patch));
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (url.pathname === '/api/storage/budget' && req.method === 'GET') {
|
|
145
|
+
// The notice reads the last measurement; it never starts a scan itself.
|
|
146
|
+
const policy = await readPolicy();
|
|
147
|
+
const age = cachedOverviewAge();
|
|
148
|
+
const last = age === null ? null : await storageOverview().catch(() => null);
|
|
149
|
+
json(res, 200, { enabled: policy.budgetNotice, limitBytes: policy.budgetGiB * 1024 ** 3, totalBytes: last?.totalBytes ?? null, measuredAt: last?.measuredAt ?? null, over: !!(policy.budgetNotice && last && last.totalBytes > policy.budgetGiB * 1024 ** 3) });
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
const actionMatch = /^\/api\/storage\/([a-z-]+)$/.exec(url.pathname);
|
|
153
|
+
if (actionMatch && req.method === 'POST') {
|
|
154
|
+
await handleStorageAction(req, res, actionMatch[1]);
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
if (url.pathname !== '/api/storage-report' || req.method !== 'GET')
|
|
158
|
+
return false;
|
|
159
|
+
if (url.searchParams.get('scope') === 'all') {
|
|
160
|
+
try {
|
|
161
|
+
json(res, 200, await storageOverview(url.searchParams.get('refresh') === '1'));
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
json(res, 500, { error: 'Storage scan failed' });
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
if (url.searchParams.get('scope') === 'home') {
|
|
169
|
+
// Arco's own folder: voice and media models, caches, shared checkpoints,
|
|
170
|
+
// task worktrees, saved clusters. Chat and Genesis project state folders
|
|
171
|
+
// inside it are skipped here and measured as their own projects.
|
|
172
|
+
if (url.searchParams.get('refresh') === '1')
|
|
173
|
+
cache.delete(HOME_KEY);
|
|
174
|
+
let pending = cache.get(HOME_KEY);
|
|
175
|
+
if (!pending) {
|
|
176
|
+
pending = scanStorage(arcoHome(), null, { scope: 'home' });
|
|
177
|
+
cache.set(HOME_KEY, pending);
|
|
178
|
+
}
|
|
179
|
+
await respond(res, HOME_KEY, pending);
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
const cwd = url.searchParams.get('path');
|
|
183
|
+
if (!cwd || !path.isAbsolute(cwd)) {
|
|
184
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
185
|
+
res.end(JSON.stringify({ error: 'Absolute path required' }));
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
const key = await realpathWithinProjects(path.resolve(cwd));
|
|
189
|
+
if (!key) {
|
|
190
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
191
|
+
res.end(JSON.stringify({ error: 'Project is unavailable' }));
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
if ((await lstat(path.join(key, '.arco'))).isSymbolicLink()) {
|
|
196
|
+
res.writeHead(403);
|
|
197
|
+
res.end();
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
if (err.code !== 'ENOENT') {
|
|
203
|
+
res.writeHead(403);
|
|
204
|
+
res.end();
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (url.searchParams.get('refresh') === '1')
|
|
209
|
+
cache.delete(key);
|
|
210
|
+
let pending = cache.get(key);
|
|
211
|
+
if (!pending) {
|
|
212
|
+
const workspace = snapshot();
|
|
213
|
+
const open = [...workspace.workflows.map(w => w.workflowId), ...workspace.clusters.flatMap(c => c.memberIds)];
|
|
214
|
+
pending = scanStorage(path.join(key, '.arco'), projectCheckpointRoot(arcoHome(), path.resolve(cwd)), { open });
|
|
215
|
+
cache.set(key, pending);
|
|
216
|
+
}
|
|
217
|
+
await respond(res, key, pending, (report) => withConversationState(key, report));
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
// Fresh per response (the scan itself is cached): each conversation's name,
|
|
221
|
+
// KEEP state and working state, and the project's archives, for the STORAGE
|
|
222
|
+
// view. KEEP changes and archive actions show without measuring again.
|
|
223
|
+
async function withConversationState(cwd, report) {
|
|
224
|
+
const conversations = await Promise.all(report.workflows.map(async (w) => {
|
|
225
|
+
const dir = path.join(cwd, '.arco', 'workflows', w.id);
|
|
226
|
+
let name;
|
|
227
|
+
try {
|
|
228
|
+
const meta = JSON.parse(await readFile(path.join(dir, 'meta.json'), 'utf8'));
|
|
229
|
+
if (typeof meta.name === 'string')
|
|
230
|
+
name = meta.name;
|
|
231
|
+
}
|
|
232
|
+
catch { /* no meta: archived or partial folder */ }
|
|
233
|
+
const keep = await readKeep(dir);
|
|
234
|
+
return {
|
|
235
|
+
...w, ...(name ? { name } : {}), busy: !!workflows.get(w.id)?.busy,
|
|
236
|
+
keep: keep.ok ? { readable: true, whole: isKept(keep.items, '.'), items: keep.items.length } : { readable: false, whole: false, items: 0 },
|
|
237
|
+
};
|
|
238
|
+
}));
|
|
239
|
+
return { ...report, workflows: conversations, archives: await listArchives(cwd) };
|
|
240
|
+
}
|
|
241
|
+
async function respond(res, key, pending, shape) {
|
|
242
|
+
try {
|
|
243
|
+
const result = shape ? await shape(await pending) : await pending;
|
|
244
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
245
|
+
res.end(JSON.stringify(result));
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
if (cache.get(key) === pending)
|
|
249
|
+
cache.delete(key);
|
|
250
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
251
|
+
res.end(JSON.stringify({ error: 'Storage scan failed' }));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=storageRoutes.js.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readLogLines } from '../eventLog.js';
|
|
2
2
|
import { promises as fs } from 'fs';
|
|
3
|
-
import { createInterface } from 'readline';
|
|
4
3
|
import path from 'path';
|
|
5
4
|
import { PORT } from '../server/constants.js';
|
|
6
5
|
// Workbench Expansion §D3 — Usage analytics over time.
|
|
@@ -164,17 +163,9 @@ export function aggregateUsage(events, opts = {}) {
|
|
|
164
163
|
async function collectWorkflowUsage(cwd, wfid, out) {
|
|
165
164
|
if (!WFID_PATTERN.test(wfid))
|
|
166
165
|
return;
|
|
167
|
-
const eventsPath = path.join(cwd, '.arco', 'workflows', wfid, 'events.jsonl');
|
|
168
|
-
let stream;
|
|
169
166
|
try {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
catch {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
try {
|
|
176
|
-
const rl = createInterface({ input: stream, crlfDelay: Infinity });
|
|
177
|
-
for await (const line of rl) {
|
|
167
|
+
// Sealed segments, then the live file (P7.3).
|
|
168
|
+
for await (const line of readLogLines(path.join(cwd, '.arco', 'workflows', wfid))) {
|
|
178
169
|
// Cheap pre-filter before JSON.parse — most lines aren't usage events.
|
|
179
170
|
if (!line || !line.includes('"primary_turn_token_usage"'))
|
|
180
171
|
continue;
|
package/server/dist/index.js
CHANGED
|
@@ -86,6 +86,7 @@ import { handleHandoffRequest, handleRehydrateWorkflows, handleClusterMemberRehy
|
|
|
86
86
|
import { resolveOrphanedGate, handleGateRevoke } from './ws/gateHandlers.js';
|
|
87
87
|
import { checkRequestOrigin } from './http/originGuard.js';
|
|
88
88
|
import { checkUpgradeAuth, describePeer, wsAuthEnabled } from './http/wsAuth.js';
|
|
89
|
+
import { startStoragePolicy } from './storageOverview.js';
|
|
89
90
|
// Strict-incognito exception list, read by the protocol fence in the ws
|
|
90
91
|
// message handler below. That fence rejects every config
|
|
91
92
|
// surface because a config edit is how a stale client would make an incognito
|
|
@@ -2046,6 +2047,9 @@ function onListening() {
|
|
|
2046
2047
|
},
|
|
2047
2048
|
});
|
|
2048
2049
|
clusterIdleNudger.start();
|
|
2050
|
+
// P7.5: daily storage measurement for the disk-budget notice and the
|
|
2051
|
+
// opt-in auto-archive rule (off by default; never deletes).
|
|
2052
|
+
startStoragePolicy();
|
|
2049
2053
|
// docs/PROTOCOL_CLUSTER.md - configure the auto-turn detector. The
|
|
2050
2054
|
// detector itself has no timer (it runs inline off broadcastWorkflow's
|
|
2051
2055
|
// peer_message_sent branch), so configure() just wires the three
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { KeepItem } from '@arco/shared';
|
|
2
|
+
export declare const KEEP_FILE = "keep.json";
|
|
3
|
+
export declare function keepLockKey(conversationDir: string): string;
|
|
4
|
+
export declare function withKeepLock<T>(conversationDir: string, fn: () => Promise<T>): Promise<T>;
|
|
5
|
+
export declare const STAYING_FILES: Set<string>;
|
|
6
|
+
export type KeepRead = {
|
|
7
|
+
ok: true;
|
|
8
|
+
items: KeepItem[];
|
|
9
|
+
} | {
|
|
10
|
+
ok: false;
|
|
11
|
+
};
|
|
12
|
+
export declare function normalizeKeepPath(raw: string): string | null;
|
|
13
|
+
export declare function readKeep(conversationDir: string): Promise<KeepRead>;
|
|
14
|
+
export declare function isKept(items: KeepItem[], rel: string): boolean;
|
|
15
|
+
export declare function holdsKept(items: KeepItem[], rel: string): boolean;
|
|
16
|
+
export declare function addKeep(conversationDir: string, raw: string, reason: KeepItem['reason']): Promise<KeepItem[]>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { atomicWriteFile, withFileLock } from './atomicFile.js';
|
|
4
|
+
// Reader for the per-conversation KEEP file (docs/STORAGE_PLAN.md, "KEEP file
|
|
5
|
+
// format"): <project>/.arco/workflows/<id>/keep.json. Builder of the KEEP and
|
|
6
|
+
// MOVE TO PROJECT controls owns the writer; archive, delete, EMPTY SCRATCH and
|
|
7
|
+
// size warnings read it here.
|
|
8
|
+
export const KEEP_FILE = 'keep.json';
|
|
9
|
+
// One in-process lock per conversation KEEP list. The KEEP writer and every
|
|
10
|
+
// action that reads the list and then removes files (archive, delete, EMPTY
|
|
11
|
+
// SCRATCH) hold it from the read through the last removal, so a KEEP set
|
|
12
|
+
// meanwhile is never undone. Use exactly this key: withFileLock matches keys
|
|
13
|
+
// as strings.
|
|
14
|
+
export function keepLockKey(conversationDir) {
|
|
15
|
+
return path.join(path.resolve(conversationDir), KEEP_FILE);
|
|
16
|
+
}
|
|
17
|
+
export function withKeepLock(conversationDir, fn) {
|
|
18
|
+
return withFileLock(keepLockKey(conversationDir), fn);
|
|
19
|
+
}
|
|
20
|
+
// Files of the conversation folder itself that every storage action leaves
|
|
21
|
+
// in place: the KEEP list and the record of size warnings already shown.
|
|
22
|
+
export const STAYING_FILES = new Set([KEEP_FILE, 'storage-warnings.json']);
|
|
23
|
+
// Normalized relative path: '/' separators, no '.', '..' or empty parts.
|
|
24
|
+
// Returns null for anything that could leave the conversation folder.
|
|
25
|
+
export function normalizeKeepPath(raw) {
|
|
26
|
+
if (typeof raw !== 'string' || raw.length > 4096 || raw.includes('\0'))
|
|
27
|
+
return null;
|
|
28
|
+
if (raw === '.' || raw === '')
|
|
29
|
+
return '.';
|
|
30
|
+
const parts = raw.replace(/\\/g, '/').split('/').filter((p) => p !== '' && p !== '.');
|
|
31
|
+
if (!parts.length)
|
|
32
|
+
return '.';
|
|
33
|
+
if (parts.some((p) => p === '..') || path.isAbsolute(raw) || /^[a-zA-Z]:/.test(raw))
|
|
34
|
+
return null;
|
|
35
|
+
return parts.join('/');
|
|
36
|
+
}
|
|
37
|
+
// Missing file: nothing is kept. Unreadable or malformed file: { ok: false };
|
|
38
|
+
// archive and delete must stop and ask instead of acting.
|
|
39
|
+
export async function readKeep(conversationDir) {
|
|
40
|
+
let raw;
|
|
41
|
+
try {
|
|
42
|
+
raw = await fs.readFile(path.join(conversationDir, KEEP_FILE), 'utf8');
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
return err.code === 'ENOENT' ? { ok: true, items: [] } : { ok: false };
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const value = JSON.parse(raw);
|
|
49
|
+
if (value.version !== 1 || !Array.isArray(value.items))
|
|
50
|
+
return { ok: false };
|
|
51
|
+
const items = [];
|
|
52
|
+
for (const item of value.items) {
|
|
53
|
+
const p = normalizeKeepPath(item?.path);
|
|
54
|
+
if (p === null || (item.reason !== 'operator' && item.reason !== 'size-warning'))
|
|
55
|
+
return { ok: false };
|
|
56
|
+
items.push({ path: p, reason: item.reason, at: Number(item.at) || 0 });
|
|
57
|
+
}
|
|
58
|
+
return { ok: true, items };
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return { ok: false };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// True when `rel` (relative to the conversation folder) is kept: the path
|
|
65
|
+
// itself, or a folder above it, or the whole conversation.
|
|
66
|
+
export function isKept(items, rel) {
|
|
67
|
+
const p = normalizeKeepPath(rel);
|
|
68
|
+
if (p === null)
|
|
69
|
+
return false;
|
|
70
|
+
return items.some((k) => k.path === '.' || k.path === p || p.startsWith(`${k.path}/`));
|
|
71
|
+
}
|
|
72
|
+
// True when something below `rel` is kept (so `rel` itself cannot be removed
|
|
73
|
+
// as a whole).
|
|
74
|
+
export function holdsKept(items, rel) {
|
|
75
|
+
const p = normalizeKeepPath(rel);
|
|
76
|
+
if (p === null)
|
|
77
|
+
return true;
|
|
78
|
+
return items.some((k) => k.path.startsWith(`${p}/`));
|
|
79
|
+
}
|
|
80
|
+
// Add a protection atomically; malformed existing metadata is never overwritten.
|
|
81
|
+
export async function addKeep(conversationDir, raw, reason) {
|
|
82
|
+
const rel = normalizeKeepPath(raw);
|
|
83
|
+
if (rel === null || (rel !== '.' && !/^(artifacts|scratch)(?:\/|$)/.test(rel)))
|
|
84
|
+
throw new Error('Invalid KEEP path.');
|
|
85
|
+
if (reason !== 'operator' && reason !== 'size-warning')
|
|
86
|
+
throw new Error('Invalid KEEP reason.');
|
|
87
|
+
const file = path.join(conversationDir, KEEP_FILE);
|
|
88
|
+
return withKeepLock(conversationDir, async () => {
|
|
89
|
+
let current = conversationDir;
|
|
90
|
+
const root = await fs.lstat(current);
|
|
91
|
+
if (!root.isDirectory() || root.isSymbolicLink())
|
|
92
|
+
throw new Error('Conversation is unavailable.');
|
|
93
|
+
for (const part of rel === '.' ? [] : rel.split('/')) {
|
|
94
|
+
current = path.join(current, part);
|
|
95
|
+
const st = await fs.lstat(current);
|
|
96
|
+
if (st.isSymbolicLink() || (!st.isDirectory() && !st.isFile()))
|
|
97
|
+
throw new Error('KEEP does not follow links.');
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
if ((await fs.lstat(file)).isSymbolicLink())
|
|
101
|
+
throw new Error('KEEP file cannot be a link.');
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
if (err.code !== 'ENOENT')
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
const existing = await readKeep(conversationDir);
|
|
108
|
+
if (!existing.ok)
|
|
109
|
+
throw new Error('The KEEP list cannot be read; nothing was changed.');
|
|
110
|
+
if (!isKept(existing.items, rel)) {
|
|
111
|
+
if (existing.items.length >= 10000)
|
|
112
|
+
throw new Error('The KEEP list is full.');
|
|
113
|
+
existing.items.push({ path: rel, reason, at: Date.now() });
|
|
114
|
+
await atomicWriteFile(file, JSON.stringify({ version: 1, items: existing.items }) + '\n', { mode: 0o600, skipMkdir: true });
|
|
115
|
+
}
|
|
116
|
+
return existing.items;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=keepStore.js.map
|