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
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { Worker } from 'node:worker_threads';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
// Every byte under a scanned root lands in exactly one bucket. Extra hard links
|
|
5
|
+
// to an already counted file are reported once in `hardLinkBytes` and are not
|
|
6
|
+
// added to any bucket. A nested state folder (another project's state, such as
|
|
7
|
+
// a chat or Genesis project inside the home folder) is skipped and counted in
|
|
8
|
+
// `nestedFolders`; it is measured as its own project.
|
|
9
|
+
export const STORAGE_BUCKETS = [
|
|
10
|
+
'events', 'artifacts', 'handoffs', 'checkpoints', 'scratch', 'conversationFiles',
|
|
11
|
+
'plans', 'boards', 'worktrees', 'savedClusters', 'voiceAndModels', 'caches',
|
|
12
|
+
'providerData', 'logs', 'archives', 'other',
|
|
13
|
+
];
|
|
14
|
+
export const LARGE_FILE_BYTES = 500 * 1024 * 1024;
|
|
15
|
+
// Parsing and directory traversal run in a worker: even one oversized JSONL
|
|
16
|
+
// record cannot stall the HTTP server. Symlinks are never followed.
|
|
17
|
+
const workerSource = String.raw `
|
|
18
|
+
const { parentPort, workerData } = require('node:worker_threads');
|
|
19
|
+
const fs = require('node:fs/promises');
|
|
20
|
+
const { createReadStream } = require('node:fs');
|
|
21
|
+
const { createBrotliDecompress } = require('node:zlib');
|
|
22
|
+
const path = require('node:path');
|
|
23
|
+
const LIMIT = 10, LARGE = workerData.large, NAMES = workerData.names;
|
|
24
|
+
function emptyBuckets() { const b = {}; for (const n of NAMES) b[n] = { bytes: 0, allocatedBytes: 0, files: 0 }; return b; }
|
|
25
|
+
function pushLargest(list, item) { list.push(item); list.sort((a, b) => b.bytes - a.bytes); if (list.length > LIMIT) list.pop(); }
|
|
26
|
+
function isEventLog(name) { return name === 'events.jsonl' || /^events\.[0-9]+-[0-9]+\.jsonl\.br$/.test(name); }
|
|
27
|
+
// rel: path segments below the scanned root.
|
|
28
|
+
function classifyProject(rel) {
|
|
29
|
+
if (rel[0] === 'workflows' && rel.length >= 3) {
|
|
30
|
+
const part = rel[2];
|
|
31
|
+
if (rel.length === 3 && isEventLog(part)) return 'events';
|
|
32
|
+
if (part === 'artifacts') return 'artifacts';
|
|
33
|
+
if (part === 'handoffs') return 'handoffs';
|
|
34
|
+
if (part === 'checkpoints') return 'checkpoints';
|
|
35
|
+
if (part === 'scratch') return 'scratch';
|
|
36
|
+
return 'conversationFiles';
|
|
37
|
+
}
|
|
38
|
+
if (rel[0] === 'plans') return 'plans';
|
|
39
|
+
if (rel[0] === 'project') return 'boards';
|
|
40
|
+
if (rel[0] === 'worktrees') return 'worktrees';
|
|
41
|
+
if (rel[0] === 'scratch') return 'scratch';
|
|
42
|
+
if (rel[0] === 'archive') return 'archives';
|
|
43
|
+
if (rel.length === 1 && /\.log$/.test(rel[0])) return 'logs';
|
|
44
|
+
return 'other';
|
|
45
|
+
}
|
|
46
|
+
function classifyHome(rel) {
|
|
47
|
+
const top = rel[0];
|
|
48
|
+
if (top === 'checkpoints') return 'checkpoints';
|
|
49
|
+
if (top === 'worktrees' || top === 'bakeoffs') return 'worktrees';
|
|
50
|
+
if (top === 'clusters' && rel[2] === 'isolates') return 'worktrees';
|
|
51
|
+
if (top === 'cluster-snapshots') return 'savedClusters';
|
|
52
|
+
if (top === 'voice' || top === 'models') return 'voiceAndModels';
|
|
53
|
+
if (top === 'media-scratch') return 'scratch';
|
|
54
|
+
if (top === 'cache' || top === 'browser-profile' || top === 'cli-snapshots' || /^camoufox-/.test(top)) return 'caches';
|
|
55
|
+
if (top === 'provider-accounts') return 'providerData';
|
|
56
|
+
if (top === 'logs' || (rel.length === 1 && /\.log$/.test(top))) return 'logs';
|
|
57
|
+
return 'other';
|
|
58
|
+
}
|
|
59
|
+
async function eventTypes(file, counts) {
|
|
60
|
+
try {
|
|
61
|
+
const st = await fs.lstat(file); if (!st.isFile()) return 0;
|
|
62
|
+
let stream = createReadStream(file);
|
|
63
|
+
if (file.endsWith('.br')) stream = stream.pipe(createBrotliDecompress());
|
|
64
|
+
let parts = [], length = 0;
|
|
65
|
+
const type = () => {
|
|
66
|
+
let t = '(unreadable)';
|
|
67
|
+
try { const e = JSON.parse(Buffer.concat(parts, length).toString('utf8')); if (typeof e.type === 'string') t = e.type; } catch {}
|
|
68
|
+
return t;
|
|
69
|
+
};
|
|
70
|
+
for await (const chunk of stream) {
|
|
71
|
+
let start = 0;
|
|
72
|
+
for (let i = 0; i < chunk.length; i++) if (chunk[i] === 10) {
|
|
73
|
+
const part = chunk.subarray(start, i); parts.push(part); length += part.length;
|
|
74
|
+
const t = type(); counts[t] = (counts[t] || 0) + length + 1; parts = []; length = 0; start = i + 1;
|
|
75
|
+
}
|
|
76
|
+
if (start < chunk.length) { const part = chunk.subarray(start); parts.push(part); length += part.length; }
|
|
77
|
+
}
|
|
78
|
+
if (length) { const t = type(); counts[t] = (counts[t] || 0) + length; }
|
|
79
|
+
return 0;
|
|
80
|
+
} catch (e) { return e.code === 'ENOENT' ? 0 : 1; }
|
|
81
|
+
}
|
|
82
|
+
async function walk(root, scope, stateName, open) {
|
|
83
|
+
const buckets = emptyBuckets(); const seen = new Set(); const workflows = new Map();
|
|
84
|
+
let total = 0, allocated = 0, hardLinkBytes = 0, nestedFolders = 0, errors = 0;
|
|
85
|
+
const largest = [], largeFiles = [];
|
|
86
|
+
const classify = scope === 'home' ? classifyHome : classifyProject;
|
|
87
|
+
const stack = [[root, []]];
|
|
88
|
+
while (stack.length) {
|
|
89
|
+
const [dir, rel] = stack.pop(); let entries;
|
|
90
|
+
try { if (!(await fs.lstat(dir)).isDirectory()) continue; entries = await fs.readdir(dir, { withFileTypes: true }); }
|
|
91
|
+
catch (e) { if (e.code !== 'ENOENT') errors++; continue; }
|
|
92
|
+
for (const entry of entries) {
|
|
93
|
+
const p = path.join(dir, entry.name), r = rel.concat(entry.name);
|
|
94
|
+
if (entry.isDirectory()) {
|
|
95
|
+
if (entry.name === stateName) { nestedFolders++; continue; }
|
|
96
|
+
stack.push([p, r]); continue;
|
|
97
|
+
}
|
|
98
|
+
if (!entry.isFile()) continue;
|
|
99
|
+
let st;
|
|
100
|
+
try { st = await fs.lstat(p); if (!st.isFile()) continue; } catch { errors++; continue; }
|
|
101
|
+
if (st.nlink > 1) {
|
|
102
|
+
const key = st.dev + ':' + st.ino;
|
|
103
|
+
if (seen.has(key)) { hardLinkBytes += st.size; continue; }
|
|
104
|
+
seen.add(key);
|
|
105
|
+
}
|
|
106
|
+
const bucket = classify(r); const alloc = (st.blocks || 0) * 512;
|
|
107
|
+
buckets[bucket].bytes += st.size; buckets[bucket].allocatedBytes += alloc; buckets[bucket].files++;
|
|
108
|
+
total += st.size; allocated += alloc;
|
|
109
|
+
if (st.size >= LARGE) largeFiles.push({ path: p, bytes: st.size });
|
|
110
|
+
pushLargest(largest, { path: p, bytes: st.size });
|
|
111
|
+
if (scope === 'project' && r[0] === 'workflows' && r.length >= 3 && /^[a-zA-Z0-9-]{1,64}$/.test(r[1])) {
|
|
112
|
+
let w = workflows.get(r[1]);
|
|
113
|
+
if (!w) {
|
|
114
|
+
w = { id: r[1], open: open.includes(r[1]), lastActive: 0, eventBytes: 0, eventTypes: Object.create(null),
|
|
115
|
+
artifactBytes: 0, handoffBytes: 0, checkpointBytes: 0, scratchBytes: 0, otherBytes: 0,
|
|
116
|
+
largestFiles: [], largeFiles: [], errors: 0, logs: [] };
|
|
117
|
+
workflows.set(r[1], w);
|
|
118
|
+
}
|
|
119
|
+
w.lastActive = Math.max(w.lastActive, st.mtimeMs);
|
|
120
|
+
if (bucket === 'events') { w.eventBytes += st.size; w.logs.push(p); }
|
|
121
|
+
else if (bucket === 'artifacts') w.artifactBytes += st.size;
|
|
122
|
+
else if (bucket === 'handoffs') w.handoffBytes += st.size;
|
|
123
|
+
else if (bucket === 'checkpoints') w.checkpointBytes += st.size;
|
|
124
|
+
else if (bucket === 'scratch') w.scratchBytes += st.size;
|
|
125
|
+
else w.otherBytes += st.size;
|
|
126
|
+
if (st.size >= LARGE) w.largeFiles.push({ path: p, bytes: st.size });
|
|
127
|
+
pushLargest(w.largestFiles, { path: p, bytes: st.size });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const list = [];
|
|
132
|
+
for (const w of workflows.values()) {
|
|
133
|
+
for (const log of w.logs.sort()) w.errors += await eventTypes(log, w.eventTypes);
|
|
134
|
+
delete w.logs; list.push(w);
|
|
135
|
+
}
|
|
136
|
+
const size = (w) => w.eventBytes + w.artifactBytes + w.handoffBytes + w.checkpointBytes + w.scratchBytes + w.otherBytes;
|
|
137
|
+
list.sort((a, b) => size(b) - size(a));
|
|
138
|
+
return { buckets, total, allocated, hardLinkBytes, nestedFolders, errors, largest, largeFiles, workflows: list };
|
|
139
|
+
}
|
|
140
|
+
async function sizeOf(root) {
|
|
141
|
+
let bytes = 0, errors = 0; const stack = [root];
|
|
142
|
+
while (stack.length) {
|
|
143
|
+
const dir = stack.pop(); let entries;
|
|
144
|
+
try { if (!(await fs.lstat(dir)).isDirectory()) continue; entries = await fs.readdir(dir, { withFileTypes: true }); }
|
|
145
|
+
catch (e) { if (e.code !== 'ENOENT') errors++; continue; }
|
|
146
|
+
for (const entry of entries) {
|
|
147
|
+
const p = path.join(dir, entry.name);
|
|
148
|
+
if (entry.isDirectory()) { stack.push(p); continue; }
|
|
149
|
+
if (!entry.isFile()) continue;
|
|
150
|
+
try { const st = await fs.lstat(p); if (st.isFile()) bytes += st.size; } catch { errors++; }
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return { bytes, errors };
|
|
154
|
+
}
|
|
155
|
+
(async () => {
|
|
156
|
+
const { root, scope, stateName, open, checkpointRoot } = workerData;
|
|
157
|
+
const result = await walk(root, scope, stateName, open);
|
|
158
|
+
const shared = checkpointRoot ? await sizeOf(checkpointRoot) : { bytes: 0, errors: 0 };
|
|
159
|
+
parentPort.postMessage({ measuredAt: Date.now(), scope, stateBytes: result.total, allocatedBytes: result.allocated,
|
|
160
|
+
hardLinkBytes: result.hardLinkBytes, nestedFolders: result.nestedFolders, checkpointBytes: shared.bytes,
|
|
161
|
+
buckets: result.buckets, workflows: result.workflows, largestFiles: result.largest, largeFiles: result.largeFiles,
|
|
162
|
+
errors: result.errors + shared.errors });
|
|
163
|
+
})().catch(e => { throw e; });
|
|
164
|
+
`;
|
|
165
|
+
export function scanStorage(stateRoot, checkpointRoot, opts = {}) {
|
|
166
|
+
const o = Array.isArray(opts) ? { open: opts } : opts;
|
|
167
|
+
return new Promise((resolve, reject) => {
|
|
168
|
+
const worker = new Worker(workerSource, {
|
|
169
|
+
eval: true,
|
|
170
|
+
workerData: {
|
|
171
|
+
root: stateRoot, checkpointRoot, scope: o.scope ?? 'project', names: [...STORAGE_BUCKETS],
|
|
172
|
+
stateName: o.stateName ?? '.arco', open: o.open ?? [], large: LARGE_FILE_BYTES,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
worker.once('message', resolve);
|
|
176
|
+
worker.once('error', reject);
|
|
177
|
+
worker.once('exit', (code) => { if (code !== 0)
|
|
178
|
+
reject(new Error(`Storage scan failed (${code})`)); });
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
export function projectCheckpointRoot(home, cwd) {
|
|
182
|
+
const hash = createHash('sha256').update(path.resolve(cwd)).digest('hex').slice(0, 16);
|
|
183
|
+
return path.join(home, 'checkpoints', hash);
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=storageReport.js.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { atomicWriteFile, withFileLock } from './atomicFile.js';
|
|
4
|
+
import { isKept, readKeep } from './keepStore.js';
|
|
5
|
+
// Artifact size warnings (P7.4, docs/STORAGE_PLAN.md). Checked when a turn
|
|
6
|
+
// ends: an artifact file at or above the file threshold, or a conversation's
|
|
7
|
+
// artifacts at or above the conversation threshold, warns once. Thresholds are
|
|
8
|
+
// high on purpose (in the measured state 7 files and 2 conversations out of
|
|
9
|
+
// 1,895 would have warned). Kept items never warn.
|
|
10
|
+
const GiB = 1024 * 1024 * 1024;
|
|
11
|
+
function envBytes(name, fallback) {
|
|
12
|
+
const n = Number(process.env[name]);
|
|
13
|
+
return Number.isFinite(n) && n > 0 ? Math.floor(n) : fallback;
|
|
14
|
+
}
|
|
15
|
+
export function fileWarnBytes() { return envBytes('ARCO_ARTIFACT_WARN_FILE_BYTES', GiB); }
|
|
16
|
+
export function conversationWarnBytes() { return envBytes('ARCO_ARTIFACT_WARN_CONVERSATION_BYTES', 5 * GiB); }
|
|
17
|
+
const STATE_FILE = 'storage-warnings.json';
|
|
18
|
+
const MAX_ENTRIES = 50_000;
|
|
19
|
+
async function readState(dir) {
|
|
20
|
+
try {
|
|
21
|
+
const v = JSON.parse(await fs.readFile(path.join(dir, STATE_FILE), 'utf8'));
|
|
22
|
+
if (v.version === 1 && v.files && typeof v.files === 'object' && typeof v.conversationBytes === 'number')
|
|
23
|
+
return v;
|
|
24
|
+
}
|
|
25
|
+
catch { /* missing or unreadable: start fresh */ }
|
|
26
|
+
return { version: 1, files: {}, conversationBytes: 0 };
|
|
27
|
+
}
|
|
28
|
+
// Sizes under artifacts/, links never followed, bounded.
|
|
29
|
+
async function artifactSizes(dir) {
|
|
30
|
+
const root = path.join(dir, 'artifacts');
|
|
31
|
+
const limit = fileWarnBytes();
|
|
32
|
+
let total = 0, seen = 0;
|
|
33
|
+
const large = [];
|
|
34
|
+
const stack = [root];
|
|
35
|
+
while (stack.length && seen < MAX_ENTRIES) {
|
|
36
|
+
const folder = stack.pop();
|
|
37
|
+
let entries;
|
|
38
|
+
try {
|
|
39
|
+
entries = await fs.readdir(folder, { withFileTypes: true });
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
for (const entry of entries) {
|
|
45
|
+
if (++seen > MAX_ENTRIES)
|
|
46
|
+
break;
|
|
47
|
+
const p = path.join(folder, entry.name);
|
|
48
|
+
if (entry.isDirectory()) {
|
|
49
|
+
stack.push(p);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (!entry.isFile())
|
|
53
|
+
continue;
|
|
54
|
+
try {
|
|
55
|
+
const st = await fs.lstat(p);
|
|
56
|
+
if (!st.isFile())
|
|
57
|
+
continue;
|
|
58
|
+
total += st.size;
|
|
59
|
+
if (st.size >= limit)
|
|
60
|
+
large.push({ rel: path.relative(dir, p).split(path.sep).join('/'), bytes: st.size });
|
|
61
|
+
}
|
|
62
|
+
catch { /* vanished */ }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { total, large };
|
|
66
|
+
}
|
|
67
|
+
// Returns the items that newly cross a threshold and records them, so each
|
|
68
|
+
// warns once. A conversation total warns again only after it grows by
|
|
69
|
+
// another conversation threshold.
|
|
70
|
+
export async function checkArtifactSizes(conversationDir) {
|
|
71
|
+
return withFileLock(path.join(conversationDir, STATE_FILE), async () => {
|
|
72
|
+
const { total, large } = await artifactSizes(conversationDir);
|
|
73
|
+
const convLimit = conversationWarnBytes();
|
|
74
|
+
if (!large.length && total < convLimit)
|
|
75
|
+
return [];
|
|
76
|
+
const keep = await readKeep(conversationDir);
|
|
77
|
+
const kept = keep.ok ? keep.items : [];
|
|
78
|
+
const state = await readState(conversationDir);
|
|
79
|
+
const items = [];
|
|
80
|
+
for (const file of large) {
|
|
81
|
+
if (isKept(kept, file.rel) || state.files[file.rel] !== undefined)
|
|
82
|
+
continue;
|
|
83
|
+
state.files[file.rel] = file.bytes;
|
|
84
|
+
items.push({ path: file.rel, bytes: file.bytes, kind: 'file' });
|
|
85
|
+
}
|
|
86
|
+
const next = state.conversationBytes ? state.conversationBytes + convLimit : convLimit;
|
|
87
|
+
if (total >= next && !isKept(kept, 'artifacts')) {
|
|
88
|
+
state.conversationBytes = total;
|
|
89
|
+
items.push({ path: 'artifacts', bytes: total, kind: 'conversation' });
|
|
90
|
+
}
|
|
91
|
+
if (items.length)
|
|
92
|
+
await atomicWriteFile(path.join(conversationDir, STATE_FILE), JSON.stringify(state) + '\n');
|
|
93
|
+
return items;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=storageWarnings.js.map
|
|
@@ -61,6 +61,9 @@ export function buildWorkerSafetyFooter(cwd, wfid) {
|
|
|
61
61
|
const bigOutputLine = dir
|
|
62
62
|
? `- For report-shaped outputs (deep dives, inventories, audits, multi-section findings), write a markdown file into \`${dir}/\` (this directory already exists) and return a brief summary that names the file in backticks (for example \`audit-spawns.md\`) so it is clickable in chat. Do NOT write report files at the project root — Arco tracks artifacts per-workflow and surfaces them inline in chat. For ordinary prose responses — even detailed ones — return the full text inline; the operator reads it in chat.`
|
|
63
63
|
: `- For report-shaped outputs (deep dives, inventories, audits, multi-section findings), write a markdown file in the cwd and return a brief summary + absolute path. For ordinary prose responses — even detailed ones — return the full text inline; the operator reads it in chat.`;
|
|
64
|
+
const scratchLine = dir
|
|
65
|
+
? `\n- Put large intermediate files (builds, disk images, downloads, datasets) in \`${path.join(path.dirname(dir), 'scratch')}/\` (create it if missing), not in artifacts. Keep only finished deliverables in artifacts. The operator empties scratch with EMPTY SCRATCH; nothing there is deleted automatically.`
|
|
66
|
+
: '';
|
|
64
67
|
return `
|
|
65
68
|
|
|
66
69
|
---
|
|
@@ -69,7 +72,7 @@ export function buildWorkerSafetyFooter(cwd, wfid) {
|
|
|
69
72
|
- No \`find /\` / \`du -sh /\` without \`-maxdepth\` and exclusions for \`/proc /sys /dev /run\`. Skip \`~/.cache\`, \`node_modules\`, \`.git/objects\`, \`/var/cache\`, \`/snap\`.
|
|
70
73
|
- No reads of \`/proc/kcore\`, \`/proc/*/mem\`, \`/dev/{kmem,mem,zero,urandom}\` past first KB. No unbounded \`journalctl\` or \`while true\` loops.
|
|
71
74
|
- No \`cat\` of files >10MB; use \`head -c 100K\` instead. \`xargs\` always with explicit limits.
|
|
72
|
-
${bigOutputLine}
|
|
75
|
+
${bigOutputLine}${scratchLine}
|
|
73
76
|
- Arco will hard-kill your process tree at 32GB RSS or ${formatCapMb(MAX_WORKER_OUTPUT_BYTES)} returned output. These are the floor, not the budget.
|
|
74
77
|
`;
|
|
75
78
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { type SealResult } from './eventLog.js';
|
|
1
2
|
import type { ServerMessage } from '@arco/shared';
|
|
2
3
|
export declare function initWorkflowStore(cwd: string, wfid: string): Promise<void>;
|
|
3
4
|
export declare function currentSeq(cwd: string, wfid: string): number;
|
|
4
5
|
export declare function persistAndStampSeq(cwd: string, wfid: string, message: ServerMessage): ServerMessage;
|
|
6
|
+
export declare function sealWorkflowLogNow(cwd: string, wfid: string): Promise<SealResult | null>;
|
|
5
7
|
export declare function flushWorkflowBuffer(cwd: string, wfid: string): Promise<void>;
|
|
6
8
|
export declare function forgetWorkflowBuffer(cwd: string, wfid: string): void;
|
|
7
9
|
export declare function flushAll(): Promise<void>;
|
|
@@ -19,9 +19,9 @@ import { ensureProjectStateIgnore } from './projectStateIgnore.js';
|
|
|
19
19
|
// but loops until the buffer is drained so late arrivals during a flush
|
|
20
20
|
// don't get stranded.
|
|
21
21
|
// - wfid must match a UUID-ish shape (path-scope defense).
|
|
22
|
-
import { promises as fs
|
|
23
|
-
import { createInterface } from 'readline';
|
|
22
|
+
import { promises as fs } from 'fs';
|
|
24
23
|
import path from 'path';
|
|
24
|
+
import { LOG_FORMAT, firstSealedSeq, readLogFormat, readLogLines, readLogTail, sealLiveLog, sealThresholdBytes, highestNamedSeq, } from './eventLog.js';
|
|
25
25
|
const FLUSH_DEBOUNCE_MS = 100;
|
|
26
26
|
const FLUSH_BYTES_THRESHOLD = 64 * 1024;
|
|
27
27
|
// Read at most 1 MB from the tail of events.jsonl on init to find the latest
|
|
@@ -105,6 +105,9 @@ export async function initWorkflowStore(cwd, wfid) {
|
|
|
105
105
|
flushTimer: null,
|
|
106
106
|
flushInFlight: null,
|
|
107
107
|
initPromise: null,
|
|
108
|
+
liveBytes: 0,
|
|
109
|
+
sealRetryAt: 0,
|
|
110
|
+
readOnly: false,
|
|
108
111
|
};
|
|
109
112
|
buffers.set(key, buf);
|
|
110
113
|
}
|
|
@@ -121,12 +124,25 @@ export async function initWorkflowStore(cwd, wfid) {
|
|
|
121
124
|
async function primeBuffer(buf) {
|
|
122
125
|
const { cwd, wfid } = buf;
|
|
123
126
|
try {
|
|
124
|
-
|
|
127
|
+
// A live file that holds no record (all of it sealed) falls back to the
|
|
128
|
+
// highest sequence number any segment name has claimed, damaged ones moved
|
|
129
|
+
// aside included, so no number is ever reused.
|
|
130
|
+
buf.seq = Math.max(await readLatestSeq(eventsPath(cwd, wfid)), await highestNamedSeq(workflowDir(cwd, wfid)));
|
|
125
131
|
}
|
|
126
132
|
catch (err) {
|
|
127
133
|
console.error(`[arco] workflowStore init failed for ${wfid.slice(0, 8)}:`, err);
|
|
128
134
|
buf.seq = 0;
|
|
129
135
|
}
|
|
136
|
+
try {
|
|
137
|
+
buf.liveBytes = (await fs.stat(eventsPath(cwd, wfid))).size;
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
buf.liveBytes = 0;
|
|
141
|
+
}
|
|
142
|
+
if (await readLogFormat(workflowDir(cwd, wfid)) > LOG_FORMAT) {
|
|
143
|
+
buf.readOnly = true;
|
|
144
|
+
console.error(`[arco] workflow ${wfid.slice(0, 8)}: its log was written by a newer Arco release; new events are shown but not saved. Update Arco to continue saving this conversation.`);
|
|
145
|
+
}
|
|
130
146
|
// Protect all project state before creating the first workflow directory.
|
|
131
147
|
ensureProjectStateIgnore(cwd);
|
|
132
148
|
await fs.mkdir(path.join(workflowDir(cwd, wfid), 'artifacts'), { recursive: true });
|
|
@@ -150,7 +166,7 @@ export function persistAndStampSeq(cwd, wfid, message) {
|
|
|
150
166
|
if (!cwd)
|
|
151
167
|
return message;
|
|
152
168
|
const buf = buffers.get(bufferKey(cwd, wfid));
|
|
153
|
-
if (!buf || !buf.initialized)
|
|
169
|
+
if (!buf || !buf.initialized || buf.readOnly)
|
|
154
170
|
return message;
|
|
155
171
|
// Phase 0 — link each event back to its predecessor for HISTORY (Phase 8)
|
|
156
172
|
// and forks (Phase 9). Linear workflows: parent = previous seq. The very
|
|
@@ -220,6 +236,25 @@ async function flushBuffer(buf) {
|
|
|
220
236
|
// sees on next reconnect triggers the snapshot-only fallback.
|
|
221
237
|
return;
|
|
222
238
|
}
|
|
239
|
+
buf.liveBytes += Buffer.byteLength(chunk);
|
|
240
|
+
// P7.3: seal the live file into compressed segments once it is large.
|
|
241
|
+
// Runs inside this flush chain, so nothing appends meanwhile; new events
|
|
242
|
+
// wait in `pending` and land in the fresh live file.
|
|
243
|
+
const threshold = sealThresholdBytes();
|
|
244
|
+
if (buf.liveBytes >= Math.max(threshold, buf.sealRetryAt)) {
|
|
245
|
+
try {
|
|
246
|
+
const sealed = await sealLiveLog(path.dirname(filePath), threshold);
|
|
247
|
+
if (sealed)
|
|
248
|
+
buf.liveBytes = sealed.liveBytes;
|
|
249
|
+
// A live file that could not be replaced yet (held open on Windows)
|
|
250
|
+
// is tried again after a little more growth, not on every flush.
|
|
251
|
+
buf.sealRetryAt = sealed && !sealed.liveReplaced ? buf.liveBytes + Math.max(1024, Math.floor(threshold / 4)) : 0;
|
|
252
|
+
}
|
|
253
|
+
catch (err) {
|
|
254
|
+
console.error(`[arco] sealing the log of ${buf.wfid.slice(0, 8)} failed; it stays a plain file:`, err);
|
|
255
|
+
buf.sealRetryAt = buf.liveBytes + threshold;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
223
258
|
}
|
|
224
259
|
})();
|
|
225
260
|
try {
|
|
@@ -229,6 +264,43 @@ async function flushBuffer(buf) {
|
|
|
229
264
|
buf.flushInFlight = null;
|
|
230
265
|
}
|
|
231
266
|
}
|
|
267
|
+
// COMPRESS OLD LOGS (P7.3/P7.5): seal a conversation's live log now, inside
|
|
268
|
+
// its flush chain so no append can land between reading and replacing the
|
|
269
|
+
// live file. Pending events are written first; events arriving meanwhile
|
|
270
|
+
// wait and land in the new live file. Returns null when nothing was sealed.
|
|
271
|
+
export async function sealWorkflowLogNow(cwd, wfid) {
|
|
272
|
+
validateWfid(wfid);
|
|
273
|
+
await initWorkflowStore(cwd, wfid);
|
|
274
|
+
const buf = buffers.get(bufferKey(cwd, wfid));
|
|
275
|
+
if (!buf)
|
|
276
|
+
return null;
|
|
277
|
+
if (buf.readOnly)
|
|
278
|
+
throw new Error('This conversation log uses a newer storage format.');
|
|
279
|
+
if (buf.flushTimer) {
|
|
280
|
+
clearTimeout(buf.flushTimer);
|
|
281
|
+
buf.flushTimer = null;
|
|
282
|
+
}
|
|
283
|
+
await flushBuffer(buf);
|
|
284
|
+
while (buf.flushInFlight)
|
|
285
|
+
await buf.flushInFlight;
|
|
286
|
+
let result = null;
|
|
287
|
+
const run = (async () => {
|
|
288
|
+
result = await sealLiveLog(workflowDir(cwd, wfid), sealThresholdBytes());
|
|
289
|
+
if (result)
|
|
290
|
+
buf.liveBytes = result.liveBytes;
|
|
291
|
+
})();
|
|
292
|
+
buf.flushInFlight = run;
|
|
293
|
+
try {
|
|
294
|
+
await run;
|
|
295
|
+
}
|
|
296
|
+
finally {
|
|
297
|
+
if (buf.flushInFlight === run)
|
|
298
|
+
buf.flushInFlight = null;
|
|
299
|
+
}
|
|
300
|
+
if (buf.pending.length)
|
|
301
|
+
await flushBuffer(buf);
|
|
302
|
+
return result;
|
|
303
|
+
}
|
|
232
304
|
// Flush a single workflow's pending events to disk now (clearing its debounce
|
|
233
305
|
// timer). Used by the Genesis rebind (M2) before moving a workflow's on-disk
|
|
234
306
|
// store from the scratch ideation dir to the real project dir — every queued
|
|
@@ -292,6 +364,9 @@ export async function readFirstSeq(cwd, wfid) {
|
|
|
292
364
|
if (!cwd)
|
|
293
365
|
return null;
|
|
294
366
|
validateWfid(wfid);
|
|
367
|
+
const sealedFirst = await firstSealedSeq(workflowDir(cwd, wfid)).catch(() => null);
|
|
368
|
+
if (sealedFirst !== null)
|
|
369
|
+
return sealedFirst;
|
|
295
370
|
const filePath = eventsPath(cwd, wfid);
|
|
296
371
|
let fh;
|
|
297
372
|
try {
|
|
@@ -339,18 +414,8 @@ export async function replayEventsWithTs(cwd, wfid, fromSeq) {
|
|
|
339
414
|
}
|
|
340
415
|
await flushBuffer(buf);
|
|
341
416
|
}
|
|
342
|
-
const filePath = eventsPath(cwd, wfid);
|
|
343
|
-
let text;
|
|
344
|
-
try {
|
|
345
|
-
text = await fs.readFile(filePath, 'utf8');
|
|
346
|
-
}
|
|
347
|
-
catch (err) {
|
|
348
|
-
if (err.code === 'ENOENT')
|
|
349
|
-
return [];
|
|
350
|
-
throw err;
|
|
351
|
-
}
|
|
352
417
|
const out = [];
|
|
353
|
-
for (const line of
|
|
418
|
+
for await (const line of readLogLines(workflowDir(cwd, wfid), { fromSeq })) {
|
|
354
419
|
if (!line.trim())
|
|
355
420
|
continue;
|
|
356
421
|
let entry;
|
|
@@ -384,18 +449,8 @@ export async function replayEvents(cwd, wfid, fromSeq) {
|
|
|
384
449
|
}
|
|
385
450
|
await flushBuffer(buf);
|
|
386
451
|
}
|
|
387
|
-
const filePath = eventsPath(cwd, wfid);
|
|
388
|
-
let text;
|
|
389
|
-
try {
|
|
390
|
-
text = await fs.readFile(filePath, 'utf8');
|
|
391
|
-
}
|
|
392
|
-
catch (err) {
|
|
393
|
-
if (err.code === 'ENOENT')
|
|
394
|
-
return [];
|
|
395
|
-
throw err;
|
|
396
|
-
}
|
|
397
452
|
const out = [];
|
|
398
|
-
for (const line of
|
|
453
|
+
for await (const line of readLogLines(workflowDir(cwd, wfid), { fromSeq })) {
|
|
399
454
|
if (!line.trim())
|
|
400
455
|
continue;
|
|
401
456
|
let entry;
|
|
@@ -430,31 +485,13 @@ export async function replayTailEvents(cwd, wfid, maxBytes) {
|
|
|
430
485
|
}
|
|
431
486
|
await flushBuffer(buf);
|
|
432
487
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
size = (await fs.stat(filePath)).size;
|
|
437
|
-
}
|
|
438
|
-
catch (err) {
|
|
439
|
-
if (err.code === 'ENOENT')
|
|
440
|
-
return { events: [], truncated: false };
|
|
441
|
-
throw err;
|
|
442
|
-
}
|
|
443
|
-
if (size <= maxBytes)
|
|
488
|
+
// Live tail, plus the newest sealed segments when the live file is short.
|
|
489
|
+
const tail = await readLogTail(workflowDir(cwd, wfid), maxBytes);
|
|
490
|
+
if (!tail.truncated)
|
|
444
491
|
return { events: await replayEvents(cwd, wfid, 0), truncated: false };
|
|
445
|
-
const fh = await fs.open(filePath, 'r');
|
|
446
|
-
let text;
|
|
447
|
-
try {
|
|
448
|
-
const chunk = Buffer.alloc(maxBytes);
|
|
449
|
-
const { bytesRead } = await fh.read(chunk, 0, maxBytes, size - maxBytes);
|
|
450
|
-
text = chunk.subarray(0, bytesRead).toString('utf8');
|
|
451
|
-
}
|
|
452
|
-
finally {
|
|
453
|
-
await fh.close();
|
|
454
|
-
}
|
|
455
492
|
// The first line is almost certainly cut mid-record (and may start mid
|
|
456
493
|
// UTF-8 sequence) — drop it.
|
|
457
|
-
const lines = text.split('\n').slice(1);
|
|
494
|
+
const lines = tail.text.split('\n').slice(1);
|
|
458
495
|
const parsed = [];
|
|
459
496
|
for (const line of lines) {
|
|
460
497
|
if (!line.trim())
|
|
@@ -492,10 +529,8 @@ export async function scanEventsOfTypes(cwd, wfid, types, visit) {
|
|
|
492
529
|
}
|
|
493
530
|
const needles = types.map((t) => `"${t}"`);
|
|
494
531
|
const out = [];
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
const rl = createInterface({ input: stream, crlfDelay: Infinity });
|
|
498
|
-
for await (const line of rl) {
|
|
532
|
+
{
|
|
533
|
+
for await (const line of readLogLines(workflowDir(cwd, wfid))) {
|
|
499
534
|
if (!needles.some((n) => line.includes(n)))
|
|
500
535
|
continue;
|
|
501
536
|
let entry;
|
|
@@ -516,14 +551,6 @@ export async function scanEventsOfTypes(cwd, wfid, types, visit) {
|
|
|
516
551
|
out.push(event);
|
|
517
552
|
}
|
|
518
553
|
}
|
|
519
|
-
catch (err) {
|
|
520
|
-
if (err.code === 'ENOENT')
|
|
521
|
-
return [];
|
|
522
|
-
throw err;
|
|
523
|
-
}
|
|
524
|
-
finally {
|
|
525
|
-
stream.destroy();
|
|
526
|
-
}
|
|
527
554
|
return out;
|
|
528
555
|
}
|
|
529
556
|
export async function readEventsPageBefore(cwd, wfid, beforeSeq, limit) {
|
|
@@ -538,19 +565,8 @@ export async function readEventsPageBefore(cwd, wfid, beforeSeq, limit) {
|
|
|
538
565
|
}
|
|
539
566
|
await flushBuffer(buf);
|
|
540
567
|
}
|
|
541
|
-
const filePath = eventsPath(cwd, wfid);
|
|
542
|
-
let text;
|
|
543
|
-
try {
|
|
544
|
-
text = await fs.readFile(filePath, 'utf8');
|
|
545
|
-
}
|
|
546
|
-
catch (err) {
|
|
547
|
-
if (err.code === 'ENOENT') {
|
|
548
|
-
return { events: [], hasEarlier: false, total: 0 };
|
|
549
|
-
}
|
|
550
|
-
throw err;
|
|
551
|
-
}
|
|
552
568
|
const parsed = [];
|
|
553
|
-
for (const line of
|
|
569
|
+
for await (const line of readLogLines(workflowDir(cwd, wfid))) {
|
|
554
570
|
if (!line.trim())
|
|
555
571
|
continue;
|
|
556
572
|
let entry;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// is best-effort and isolated — one failing path never blocks the rest; the
|
|
14
14
|
// caller logs what was removed. There is no undo; the type-to-confirm gate on the
|
|
15
15
|
// nuclear tier is the only guard (enforced at the route).
|
|
16
|
-
import { rm, readdir, unlink } from 'node:fs/promises';
|
|
16
|
+
import { lstat, rm, readdir, unlink } from 'node:fs/promises';
|
|
17
17
|
import { homedir } from 'node:os';
|
|
18
18
|
import { join } from 'node:path';
|
|
19
19
|
import { execFile } from 'node:child_process';
|
|
@@ -97,6 +97,15 @@ async function deleteProviderSessions(cwd, sessions, removed) {
|
|
|
97
97
|
}
|
|
98
98
|
export async function purgeWorkflow(cwd, wfid, opts) {
|
|
99
99
|
const removed = [];
|
|
100
|
+
// A link in the way (the project's .arco, .arco/workflows or the workflow
|
|
101
|
+
// folder) is never followed: refuse before anything is torn down.
|
|
102
|
+
for (const rel of ['.arco', join('.arco', 'workflows'), join('.arco', 'workflows', wfid)]) {
|
|
103
|
+
try {
|
|
104
|
+
if ((await lstat(join(cwd, rel))).isSymbolicLink())
|
|
105
|
+
return { ok: false, removed, error: `${rel.split('\\').join('/')} is a link, so nothing was deleted` };
|
|
106
|
+
}
|
|
107
|
+
catch { /* missing: nothing to follow */ }
|
|
108
|
+
}
|
|
100
109
|
try {
|
|
101
110
|
// For nuclear, capture the provider sessions BEFORE the dir (holding
|
|
102
111
|
// meta.json) is deleted.
|
|
@@ -131,7 +140,11 @@ export async function purgeWorkflow(cwd, wfid, opts) {
|
|
|
131
140
|
}
|
|
132
141
|
// 2. The workflow directory tree (events.jsonl, meta.json, artifacts,
|
|
133
142
|
// handoffs, sandbox.db, mcp-config, attachments, …).
|
|
134
|
-
|
|
143
|
+
// The storage DELETE action passes `removeDir` to leave KEEP items in place.
|
|
144
|
+
if (opts.removeDir)
|
|
145
|
+
await opts.removeDir(workflowDir(cwd, wfid));
|
|
146
|
+
else
|
|
147
|
+
await rm(workflowDir(cwd, wfid), { recursive: true, force: true });
|
|
135
148
|
removed.push('workflow dir');
|
|
136
149
|
// 3. Checkpoints (git refs + tar files).
|
|
137
150
|
await deleteCheckpoints(cwd, wfid, removed);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { open, readdir, stat } from 'fs/promises';
|
|
2
|
-
import { openSync, fstatSync, readSync, closeSync } from 'node:fs';
|
|
3
2
|
import { join, resolve } from 'path';
|
|
4
3
|
import { homedir } from 'os';
|
|
5
4
|
import { UUID_PATTERN, CODEX_SCAN_DAYS } from '../server/constants.js';
|
|
@@ -9,6 +8,7 @@ import { backfillSessionIndex } from './sessionIndex.js';
|
|
|
9
8
|
import { getRecallIndex } from '../recall/index.js';
|
|
10
9
|
import { encodeProjectDir } from '../http/fileRead.js';
|
|
11
10
|
import { extractUserText } from './transcripts.js';
|
|
11
|
+
import { readLogHeadSync } from '../eventLog.js';
|
|
12
12
|
export async function extractSessionName(path) {
|
|
13
13
|
// Claude's ai-title is written at most once per session — many sessions
|
|
14
14
|
// never get one (observed: heavy tool-use sessions >1MB with zero ai-title
|
|
@@ -270,16 +270,12 @@ export async function extractCodexSessionInfo(path, wantCwd) {
|
|
|
270
270
|
// Arco-internal sessions that have no provider .jsonl and may not yet be in
|
|
271
271
|
// the recall index. Bounded head read, best-effort, never throws.
|
|
272
272
|
function readFirstUserText(cwd, wfid) {
|
|
273
|
-
let fd;
|
|
274
273
|
try {
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
if (
|
|
274
|
+
// The oldest records, from the first sealed segment when there is one (P7.3).
|
|
275
|
+
const head = readLogHeadSync(join(cwd, '.arco', 'workflows', wfid), 256 * 1024);
|
|
276
|
+
if (!head)
|
|
278
277
|
return undefined;
|
|
279
|
-
const
|
|
280
|
-
const buf = Buffer.allocUnsafe(len);
|
|
281
|
-
readSync(fd, buf, 0, len, 0);
|
|
282
|
-
for (const line of buf.toString('utf8').split('\n')) {
|
|
278
|
+
for (const line of head.split('\n')) {
|
|
283
279
|
if (!line || !line.includes('"user_message_echo"'))
|
|
284
280
|
continue;
|
|
285
281
|
try {
|
|
@@ -298,14 +294,6 @@ function readFirstUserText(cwd, wfid) {
|
|
|
298
294
|
catch {
|
|
299
295
|
return undefined;
|
|
300
296
|
}
|
|
301
|
-
finally {
|
|
302
|
-
if (fd !== undefined) {
|
|
303
|
-
try {
|
|
304
|
-
closeSync(fd);
|
|
305
|
-
}
|
|
306
|
-
catch { /* ignore */ }
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
297
|
}
|
|
310
298
|
export async function discoverSessions(targetDir) {
|
|
311
299
|
if (!targetDir)
|