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
|
@@ -33,6 +33,13 @@ import { ensureLiveTokens } from './providers/claude-native/oauth.js';
|
|
|
33
33
|
import { loadTokens } from './providers/claude-native/auth.js';
|
|
34
34
|
import { CLAUDE_CLI_USER_AGENT } from './providers/claude-native/wireFingerprint.js';
|
|
35
35
|
import { resolveClaudeAliasFromCatalog } from './providers/claude-native/catalog.js';
|
|
36
|
+
import { getLmstudioBase, probeLmstudio } from './providers/lmstudio.js';
|
|
37
|
+
import { getStrataBase, probeStrata } from './providers/strata.js';
|
|
38
|
+
import { getDeepSeekBase, probeDeepSeek } from './providers/deepseek.js';
|
|
39
|
+
import { llamacppManager } from './providers/llamacppManager.js';
|
|
40
|
+
import { probeLlamacppLive } from './providers/llamacpp.js';
|
|
41
|
+
import { queueLocalProvider } from './providers/localProviderQueue.js';
|
|
42
|
+
import { localModelsUnloading } from './providers/localModelControl.js';
|
|
36
43
|
// Cursor start-up measured about 2 to 2.5 s warm on Linux (spawn and
|
|
37
44
|
// initialize about 0.25 s, session/new about 2 s); the allowance covers a cold
|
|
38
45
|
// agent start (update, sign-in refresh) without touching the answer limit.
|
|
@@ -143,13 +150,26 @@ export function claudeAdapter(opts = {}) {
|
|
|
143
150
|
system: [{ type: 'text', text: CLAUDE_IDENTITY }, { type: 'text', text: req.instructions }],
|
|
144
151
|
messages: [{ role: 'user', content: req.prompt }],
|
|
145
152
|
}, { signal });
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
+
const blocks = resp.content;
|
|
154
|
+
const types = Array.isArray(blocks) ? blocks.map((block) => {
|
|
155
|
+
const type = block && typeof block === 'object' && 'type' in block ? block.type : undefined;
|
|
156
|
+
return typeof type === 'string' && ['text', 'thinking', 'redacted_thinking', 'tool_use'].includes(type) ? type : 'other';
|
|
157
|
+
}) : [];
|
|
158
|
+
const refuse = (reason) => {
|
|
159
|
+
console.warn(`[arco] Claude evaluator refused: ${reason}; block types: ${types.slice(0, 20).join(',') || 'none'}`);
|
|
160
|
+
throw new EvaluatorRefused(reason);
|
|
161
|
+
};
|
|
162
|
+
if (!Array.isArray(blocks))
|
|
163
|
+
return refuse('unreadable_answer');
|
|
164
|
+
if (resp.stop_reason === 'tool_use' || types.includes('tool_use') || types.includes('other'))
|
|
165
|
+
return refuse('non_text_answer');
|
|
166
|
+
if (blocks.some((b) => b && typeof b === 'object' && 'type' in b && b.type === 'text' && (!('text' in b) || typeof b.text !== 'string')))
|
|
167
|
+
return refuse('unreadable_answer');
|
|
168
|
+
const text = blocks.filter((b) => b?.type === 'text').map((b) => b.text).join('');
|
|
169
|
+
if (resp.stop_reason === 'max_tokens' || text.length > outputCharCap(req.maxOutputTokens))
|
|
170
|
+
return refuse('output_too_long');
|
|
171
|
+
if (!text.trim())
|
|
172
|
+
return refuse('empty_answer');
|
|
153
173
|
return text;
|
|
154
174
|
}
|
|
155
175
|
catch (error) {
|
|
@@ -157,8 +177,10 @@ export function claudeAdapter(opts = {}) {
|
|
|
157
177
|
throw signal.reason;
|
|
158
178
|
if (error instanceof EvaluatorRefused)
|
|
159
179
|
throw error;
|
|
160
|
-
if (error instanceof SyntaxError)
|
|
180
|
+
if (error instanceof SyntaxError) {
|
|
181
|
+
console.warn('[arco] Claude evaluator refused: unreadable_answer; block types: none');
|
|
161
182
|
throw new EvaluatorRefused('unreadable_answer');
|
|
183
|
+
}
|
|
162
184
|
if (error instanceof Anthropic.APIError) {
|
|
163
185
|
if (error.status === 401)
|
|
164
186
|
throw new EvaluatorRefused('not_signed_in');
|
|
@@ -451,11 +473,153 @@ export function codexAdapter(opts = {}) {
|
|
|
451
473
|
},
|
|
452
474
|
};
|
|
453
475
|
}
|
|
476
|
+
async function boundedLocalResponse(response, maxBytes) {
|
|
477
|
+
const declared = Number(response.headers.get('content-length'));
|
|
478
|
+
if (Number.isFinite(declared) && declared > maxBytes)
|
|
479
|
+
throw new EvaluatorRefused('output_too_long');
|
|
480
|
+
if (!response.body)
|
|
481
|
+
throw new EvaluatorRefused('unreadable_answer');
|
|
482
|
+
const reader = response.body.getReader();
|
|
483
|
+
const chunks = [];
|
|
484
|
+
let size = 0;
|
|
485
|
+
try {
|
|
486
|
+
for (;;) {
|
|
487
|
+
const { value, done } = await reader.read();
|
|
488
|
+
if (done)
|
|
489
|
+
break;
|
|
490
|
+
size += value.byteLength;
|
|
491
|
+
if (size > maxBytes) {
|
|
492
|
+
await reader.cancel();
|
|
493
|
+
throw new EvaluatorRefused('output_too_long');
|
|
494
|
+
}
|
|
495
|
+
chunks.push(value);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
finally {
|
|
499
|
+
reader.releaseLock();
|
|
500
|
+
}
|
|
501
|
+
const data = new Uint8Array(size);
|
|
502
|
+
let offset = 0;
|
|
503
|
+
for (const chunk of chunks) {
|
|
504
|
+
data.set(chunk, offset);
|
|
505
|
+
offset += chunk.byteLength;
|
|
506
|
+
}
|
|
507
|
+
try {
|
|
508
|
+
return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(data));
|
|
509
|
+
}
|
|
510
|
+
catch {
|
|
511
|
+
throw new EvaluatorRefused('unreadable_answer');
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
// A single bounded, non-streaming OpenAI-compatible request for local models.
|
|
515
|
+
export function openAiCompatibleAdapter(provider, opts) {
|
|
516
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
517
|
+
return {
|
|
518
|
+
provider,
|
|
519
|
+
async capability() { try {
|
|
520
|
+
return { provider, available: await opts.available() };
|
|
521
|
+
}
|
|
522
|
+
catch {
|
|
523
|
+
return { provider, available: false, reason: 'Local provider is unavailable.' };
|
|
524
|
+
} },
|
|
525
|
+
async evaluate(req) {
|
|
526
|
+
const { signal, done } = deadline(req);
|
|
527
|
+
let onAbort;
|
|
528
|
+
try {
|
|
529
|
+
const perform = async () => {
|
|
530
|
+
signal.throwIfAborted();
|
|
531
|
+
const base = (await opts.base(req.model, signal)).replace(/\/$/, '');
|
|
532
|
+
signal.throwIfAborted();
|
|
533
|
+
const response = await fetchImpl(`${base}/chat/completions`, {
|
|
534
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' }, signal,
|
|
535
|
+
body: JSON.stringify({ model: req.model, stream: false, max_tokens: req.maxOutputTokens, temperature: 0,
|
|
536
|
+
messages: [{ role: 'system', content: req.instructions }, { role: 'user', content: req.prompt }] }),
|
|
537
|
+
});
|
|
538
|
+
if (!response.ok)
|
|
539
|
+
throw new EvaluatorRefused(response.status === 401 || response.status === 403 ? 'not_signed_in' : `provider_http_${response.status}`);
|
|
540
|
+
const result = await boundedLocalResponse(response, outputCharCap(req.maxOutputTokens) * 4 + 16_384);
|
|
541
|
+
const choice = result && Array.isArray(result.choices) ? result.choices[0] : undefined;
|
|
542
|
+
if ((choice?.message?.tool_calls != null && (!Array.isArray(choice.message.tool_calls) || choice.message.tool_calls.length > 0)) || choice?.message?.function_call || (choice?.finish_reason === 'tool_calls' || choice?.finish_reason === 'function_call'))
|
|
543
|
+
throw new EvaluatorRefused('tool_attempted');
|
|
544
|
+
if (!choice?.message || !('content' in choice.message))
|
|
545
|
+
throw new EvaluatorRefused('unreadable_answer');
|
|
546
|
+
if (typeof choice.message.content !== 'string')
|
|
547
|
+
throw new EvaluatorRefused('non_text_answer');
|
|
548
|
+
const answer = choice.message.content;
|
|
549
|
+
if (choice.finish_reason === 'length' || answer.length > outputCharCap(req.maxOutputTokens))
|
|
550
|
+
throw new EvaluatorRefused('output_too_long');
|
|
551
|
+
if (!answer.trim())
|
|
552
|
+
throw new EvaluatorRefused('empty_answer');
|
|
553
|
+
return answer;
|
|
554
|
+
};
|
|
555
|
+
const work = opts.run ? opts.run(perform) : perform();
|
|
556
|
+
const aborted = new Promise((_, reject) => {
|
|
557
|
+
onAbort = () => reject(signal.reason);
|
|
558
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
559
|
+
if (signal.aborted)
|
|
560
|
+
onAbort();
|
|
561
|
+
});
|
|
562
|
+
return await Promise.race([work, aborted]);
|
|
563
|
+
}
|
|
564
|
+
catch (error) {
|
|
565
|
+
if (signal.aborted)
|
|
566
|
+
throw signal.reason;
|
|
567
|
+
if (error instanceof EvaluatorRefused)
|
|
568
|
+
throw error;
|
|
569
|
+
if (error instanceof SyntaxError)
|
|
570
|
+
throw new EvaluatorRefused('unreadable_answer');
|
|
571
|
+
throw new EvaluatorRefused('unavailable');
|
|
572
|
+
}
|
|
573
|
+
finally {
|
|
574
|
+
if (onAbort)
|
|
575
|
+
signal.removeEventListener('abort', onAbort);
|
|
576
|
+
done();
|
|
577
|
+
}
|
|
578
|
+
},
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function localRun(provider, work) {
|
|
582
|
+
return queueLocalProvider(provider, async () => {
|
|
583
|
+
if (localModelsUnloading())
|
|
584
|
+
throw new EvaluatorRefused('unavailable');
|
|
585
|
+
return work();
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
export async function requireLoadedLocalModel(provider, base, model, signal) {
|
|
589
|
+
const url = provider === 'lmstudio' ? `${base.replace(/\/v\d+$/, '')}/api/v1/models` : `${base}/status`;
|
|
590
|
+
const response = await fetch(url, { signal });
|
|
591
|
+
if (!response.ok)
|
|
592
|
+
throw new EvaluatorRefused('unavailable');
|
|
593
|
+
const body = await boundedLocalResponse(response, 128_000);
|
|
594
|
+
const loaded = provider === 'lmstudio'
|
|
595
|
+
? body.models?.some((entry) => (entry.key === model && !!entry.loaded_instances?.length) || entry.loaded_instances?.some((instance) => instance.id === model))
|
|
596
|
+
: body.model === model && body.loaded === true;
|
|
597
|
+
if (!loaded)
|
|
598
|
+
throw new EvaluatorRefused(`model_not_loaded_${provider}`);
|
|
599
|
+
return base;
|
|
600
|
+
}
|
|
454
601
|
let adapters = {
|
|
455
602
|
ollama: ollamaAdapter(),
|
|
456
603
|
claude: claudeAdapter(),
|
|
457
604
|
cursor: cursorAdapter(),
|
|
458
605
|
codex: codexAdapter(),
|
|
606
|
+
lmstudio: openAiCompatibleAdapter('lmstudio', { base: async (model, signal) => requireLoadedLocalModel('lmstudio', await getLmstudioBase(), model, signal), available: async () => (await probeLmstudio()).up, run: (work) => localRun('lmstudio', work) }),
|
|
607
|
+
strata: openAiCompatibleAdapter('strata', { base: async (model, signal) => requireLoadedLocalModel('strata', await getStrataBase(), model, signal), available: async () => (await probeStrata()).up, run: (work) => localRun('strata', work) }),
|
|
608
|
+
deepseek: openAiCompatibleAdapter('deepseek', { base: async (model, signal) => requireLoadedLocalModel('deepseek', await getDeepSeekBase(), model, signal), available: async () => (await probeDeepSeek()).up, run: (work) => localRun('deepseek', work) }),
|
|
609
|
+
llamacpp: openAiCompatibleAdapter('llamacpp', { base: async (model) => {
|
|
610
|
+
const status = llamacppManager.getStatus();
|
|
611
|
+
if (status.state !== 'ready' || status.alias !== model || !status.port)
|
|
612
|
+
throw new EvaluatorRefused('model_not_loaded_llamacpp');
|
|
613
|
+
return `http://${llamacppManager.getEndpoint().host}:${status.port}/v1`;
|
|
614
|
+
}, available: async () => (await probeLlamacppLive()).up, run: (work) => localRun('llamacpp', async () => {
|
|
615
|
+
const release = llamacppManager.acquire();
|
|
616
|
+
try {
|
|
617
|
+
return await work();
|
|
618
|
+
}
|
|
619
|
+
finally {
|
|
620
|
+
release();
|
|
621
|
+
}
|
|
622
|
+
}) }),
|
|
459
623
|
};
|
|
460
624
|
export function evaluatorAdapter(provider) {
|
|
461
625
|
return adapters[provider];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare class StorageActionError extends Error {
|
|
2
|
+
readonly code: 'keep_unreadable' | 'busy' | 'open' | 'not_found' | 'kept' | 'exists' | 'invalid' | 'unsafe';
|
|
3
|
+
constructor(code: 'keep_unreadable' | 'busy' | 'open' | 'not_found' | 'kept' | 'exists' | 'invalid' | 'unsafe', message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare function conversationDir(cwd: string, workflowId: string): string;
|
|
6
|
+
export declare function checkedConversationDir(cwd: string, workflowId: string, opts?: {
|
|
7
|
+
mayBeMissing?: boolean;
|
|
8
|
+
}): Promise<string>;
|
|
9
|
+
export declare function unsafe(rel: string): StorageActionError;
|
|
10
|
+
export declare function checkedArchiveFolder(cwd: string): Promise<void>;
|
|
11
|
+
export declare function checkedEntry(dir: string, rel: string): Promise<boolean>;
|
|
12
|
+
export declare function recordStorageAction(cwd: string, entry: Record<string, unknown>): Promise<void>;
|
|
13
|
+
export interface RemovalResult {
|
|
14
|
+
removedBytes: number;
|
|
15
|
+
removedFiles: number;
|
|
16
|
+
keptItems: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function treeSize(p: string): Promise<{
|
|
19
|
+
bytes: number;
|
|
20
|
+
files: number;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function emptyScratch(cwd: string, workflowId: string, opts: {
|
|
23
|
+
busy: boolean;
|
|
24
|
+
}): Promise<RemovalResult>;
|
|
25
|
+
export declare function deleteConversation(cwd: string, workflowId: string, opts: {
|
|
26
|
+
open: boolean;
|
|
27
|
+
busy: boolean;
|
|
28
|
+
purge: (cwd: string, id: string, o: {
|
|
29
|
+
nuclear: boolean;
|
|
30
|
+
removeDir?: (dir: string) => Promise<void>;
|
|
31
|
+
}) => Promise<{
|
|
32
|
+
ok: boolean;
|
|
33
|
+
error?: string;
|
|
34
|
+
}>;
|
|
35
|
+
archiveFile?: string;
|
|
36
|
+
}): Promise<RemovalResult>;
|
|
37
|
+
export declare const COMPRESS_MIN_BYTES: number;
|
|
38
|
+
export interface CompressResult {
|
|
39
|
+
sealed: number;
|
|
40
|
+
skippedOpen: string[];
|
|
41
|
+
failed: number;
|
|
42
|
+
deferred: number;
|
|
43
|
+
beforeBytes: number;
|
|
44
|
+
afterBytes: number;
|
|
45
|
+
}
|
|
46
|
+
export declare function compressOldLogs(cwd: string, opts: {
|
|
47
|
+
isOpen: (id: string) => boolean;
|
|
48
|
+
isBusy: (id: string) => boolean;
|
|
49
|
+
seal: (cwd: string, id: string) => Promise<unknown>;
|
|
50
|
+
}): Promise<CompressResult>;
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { STAYING_FILES, holdsKept, isKept, readKeep, withKeepLock } from './keepStore.js';
|
|
4
|
+
import { ensureProjectStateIgnore } from './projectStateIgnore.js';
|
|
5
|
+
// Operator storage actions (P7.4/P7.5, docs/STORAGE_PLAN.md). Every action is
|
|
6
|
+
// an explicit operator request, never touches plans, skips KEEP items, stops
|
|
7
|
+
// when the KEEP file cannot be read, and is recorded in
|
|
8
|
+
// <project>/.arco/storage-actions.jsonl.
|
|
9
|
+
export class StorageActionError extends Error {
|
|
10
|
+
code;
|
|
11
|
+
constructor(code, message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const WFID = /^[a-zA-Z0-9-]{1,64}$/;
|
|
17
|
+
export function conversationDir(cwd, workflowId) {
|
|
18
|
+
if (!WFID.test(workflowId))
|
|
19
|
+
throw new StorageActionError('invalid', 'Invalid conversation id.');
|
|
20
|
+
return path.join(cwd, '.arco', 'workflows', workflowId);
|
|
21
|
+
}
|
|
22
|
+
// Links are never followed by a storage action. The project's `.arco`,
|
|
23
|
+
// `.arco/workflows` and the conversation folder must be real folders (not
|
|
24
|
+
// links), and the folder must resolve to where its path says; otherwise the
|
|
25
|
+
// action is refused before anything is read, written or removed.
|
|
26
|
+
// `mayBeMissing`: a conversation folder that does not exist is fine (restore).
|
|
27
|
+
export async function checkedConversationDir(cwd, workflowId, opts = {}) {
|
|
28
|
+
const dir = conversationDir(cwd, workflowId);
|
|
29
|
+
for (const p of [path.join(cwd, '.arco'), path.join(cwd, '.arco', 'workflows'), dir]) {
|
|
30
|
+
let st;
|
|
31
|
+
try {
|
|
32
|
+
st = await fs.lstat(p);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
if (err.code !== 'ENOENT')
|
|
36
|
+
throw err;
|
|
37
|
+
if (opts.mayBeMissing && p === dir)
|
|
38
|
+
return dir;
|
|
39
|
+
throw new StorageActionError('not_found', 'The conversation folder was not found.');
|
|
40
|
+
}
|
|
41
|
+
if (st.isSymbolicLink() || !st.isDirectory())
|
|
42
|
+
throw unsafe(path.relative(cwd, p));
|
|
43
|
+
}
|
|
44
|
+
const expected = path.join(await fs.realpath(cwd), '.arco', 'workflows', workflowId);
|
|
45
|
+
if (await fs.realpath(dir) !== expected)
|
|
46
|
+
throw unsafe(path.relative(cwd, dir));
|
|
47
|
+
return dir;
|
|
48
|
+
}
|
|
49
|
+
export function unsafe(rel) {
|
|
50
|
+
return new StorageActionError('unsafe', `${rel.split(path.sep).join('/')} is a link or not a folder, so nothing was changed.`);
|
|
51
|
+
}
|
|
52
|
+
// The project's archive folder: a real folder or missing, never a link.
|
|
53
|
+
export async function checkedArchiveFolder(cwd) {
|
|
54
|
+
const p = path.join(cwd, '.arco', 'archive');
|
|
55
|
+
try {
|
|
56
|
+
const st = await fs.lstat(p);
|
|
57
|
+
if (st.isSymbolicLink() || !st.isDirectory())
|
|
58
|
+
throw unsafe(path.join('.arco', 'archive'));
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
if (err.code !== 'ENOENT')
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// A folder or file inside a checked conversation folder: false when missing,
|
|
66
|
+
// refused when it is a link.
|
|
67
|
+
export async function checkedEntry(dir, rel) {
|
|
68
|
+
try {
|
|
69
|
+
if ((await fs.lstat(path.join(dir, ...rel.split('/')))).isSymbolicLink())
|
|
70
|
+
throw unsafe(rel);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
if (err.code === 'ENOENT')
|
|
75
|
+
return false;
|
|
76
|
+
throw err;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export async function recordStorageAction(cwd, entry) {
|
|
80
|
+
const line = JSON.stringify({ at: Date.now(), ...entry }) + '\n';
|
|
81
|
+
try {
|
|
82
|
+
ensureProjectStateIgnore(cwd);
|
|
83
|
+
await fs.mkdir(path.join(cwd, '.arco'), { recursive: true });
|
|
84
|
+
await fs.appendFile(path.join(cwd, '.arco', 'storage-actions.jsonl'), line, { encoding: 'utf8', mode: 0o600 });
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
console.error('[arco] storage action not recorded:', err);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Remove everything under `root` (relative `rel` inside the conversation)
|
|
91
|
+
// except kept items. Links are removed as links, never followed.
|
|
92
|
+
async function removeExceptKept(dir, rel, kept, out) {
|
|
93
|
+
const abs = rel ? path.join(dir, ...rel.split('/')) : dir;
|
|
94
|
+
// The start folder itself is never a link (a link inside is removed as one).
|
|
95
|
+
try {
|
|
96
|
+
if ((await fs.lstat(abs)).isSymbolicLink())
|
|
97
|
+
throw unsafe(rel || '.');
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
if (err.code === 'ENOENT')
|
|
101
|
+
return;
|
|
102
|
+
throw err;
|
|
103
|
+
}
|
|
104
|
+
let entries;
|
|
105
|
+
try {
|
|
106
|
+
entries = await fs.readdir(abs, { withFileTypes: true });
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
if (err.code === 'ENOENT')
|
|
110
|
+
return;
|
|
111
|
+
throw err;
|
|
112
|
+
}
|
|
113
|
+
for (const entry of entries) {
|
|
114
|
+
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
115
|
+
const child = path.join(abs, entry.name);
|
|
116
|
+
if (!rel && STAYING_FILES.has(entry.name))
|
|
117
|
+
continue;
|
|
118
|
+
if (isKept(kept, childRel)) {
|
|
119
|
+
out.keptItems++;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (entry.isDirectory() && holdsKept(kept, childRel)) {
|
|
123
|
+
await removeExceptKept(dir, childRel, kept, out);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const size = await treeSize(child);
|
|
127
|
+
await fs.rm(child, { recursive: true, force: true });
|
|
128
|
+
out.removedBytes += size.bytes;
|
|
129
|
+
out.removedFiles += size.files;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export async function treeSize(p) {
|
|
133
|
+
let bytes = 0, files = 0;
|
|
134
|
+
const stack = [p];
|
|
135
|
+
while (stack.length) {
|
|
136
|
+
const cur = stack.pop();
|
|
137
|
+
let st;
|
|
138
|
+
try {
|
|
139
|
+
st = await fs.lstat(cur);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (st.isDirectory()) {
|
|
145
|
+
try {
|
|
146
|
+
for (const name of await fs.readdir(cur))
|
|
147
|
+
stack.push(path.join(cur, name));
|
|
148
|
+
}
|
|
149
|
+
catch { /* unreadable */ }
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
bytes += st.size;
|
|
153
|
+
files++;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return { bytes, files };
|
|
157
|
+
}
|
|
158
|
+
// EMPTY SCRATCH: delete the conversation's scratch/ contents except kept
|
|
159
|
+
// items. Refused while the conversation is working and when the KEEP file
|
|
160
|
+
// cannot be read.
|
|
161
|
+
export async function emptyScratch(cwd, workflowId, opts) {
|
|
162
|
+
if (opts.busy)
|
|
163
|
+
throw new StorageActionError('busy', 'The conversation is working; empty its scratch folder when it is idle.');
|
|
164
|
+
const dir = await checkedConversationDir(cwd, workflowId, { mayBeMissing: true });
|
|
165
|
+
await checkedEntry(dir, 'scratch');
|
|
166
|
+
return withKeepLock(dir, async () => {
|
|
167
|
+
const keep = await readKeep(dir);
|
|
168
|
+
if (!keep.ok)
|
|
169
|
+
throw new StorageActionError('keep_unreadable', 'The KEEP list of this conversation cannot be read, so nothing was deleted.');
|
|
170
|
+
const out = { removedBytes: 0, removedFiles: 0, keptItems: 0 };
|
|
171
|
+
if (isKept(keep.items, 'scratch')) {
|
|
172
|
+
out.keptItems++;
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
await removeExceptKept(dir, 'scratch', keep.items, out);
|
|
176
|
+
await recordStorageAction(cwd, { action: 'empty_scratch', workflowId, removedBytes: out.removedBytes, removedFiles: out.removedFiles, keptItems: out.keptItems });
|
|
177
|
+
return out;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
// DELETE a closed conversation (P7.5): the existing purge (folder, checkpoints,
|
|
181
|
+
// Recall row, mailbox), plus its archive if it has one. Kept items stay in
|
|
182
|
+
// the conversation folder. Refused for an open or working conversation, a
|
|
183
|
+
// wholly kept one, or an unreadable KEEP list.
|
|
184
|
+
export async function deleteConversation(cwd, workflowId, opts) {
|
|
185
|
+
if (opts.open || opts.busy)
|
|
186
|
+
throw new StorageActionError('open', 'Close the conversation before deleting it.');
|
|
187
|
+
const dir = await checkedConversationDir(cwd, workflowId, { mayBeMissing: true });
|
|
188
|
+
if (opts.archiveFile) {
|
|
189
|
+
await checkedArchiveFolder(cwd);
|
|
190
|
+
try {
|
|
191
|
+
if (!(await fs.lstat(opts.archiveFile)).isFile())
|
|
192
|
+
throw unsafe(path.relative(cwd, opts.archiveFile));
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
if (err.code !== 'ENOENT')
|
|
196
|
+
throw err;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return withKeepLock(dir, async () => {
|
|
200
|
+
const keep = await readKeep(dir);
|
|
201
|
+
if (!keep.ok)
|
|
202
|
+
throw new StorageActionError('keep_unreadable', 'The KEEP list of this conversation cannot be read, so nothing was deleted.');
|
|
203
|
+
if (isKept(keep.items, '.'))
|
|
204
|
+
throw new StorageActionError('kept', 'The whole conversation is kept.');
|
|
205
|
+
let exists = true;
|
|
206
|
+
try {
|
|
207
|
+
await fs.lstat(dir);
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
exists = false;
|
|
211
|
+
}
|
|
212
|
+
let archived = false;
|
|
213
|
+
if (opts.archiveFile) {
|
|
214
|
+
try {
|
|
215
|
+
await fs.lstat(opts.archiveFile);
|
|
216
|
+
archived = true;
|
|
217
|
+
}
|
|
218
|
+
catch { /* none */ }
|
|
219
|
+
}
|
|
220
|
+
if (!exists && !archived)
|
|
221
|
+
throw new StorageActionError('not_found', 'The conversation was not found.');
|
|
222
|
+
const out = { removedBytes: 0, removedFiles: 0, keptItems: 0 };
|
|
223
|
+
if (exists && !keep.items.length) {
|
|
224
|
+
const size = await treeSize(dir);
|
|
225
|
+
out.removedBytes += size.bytes;
|
|
226
|
+
out.removedFiles += size.files;
|
|
227
|
+
}
|
|
228
|
+
const result = await opts.purge(cwd, workflowId, {
|
|
229
|
+
nuclear: false,
|
|
230
|
+
...(keep.items.length ? { removeDir: async () => { await removeExceptKept(dir, '', keep.items, out); } } : {}),
|
|
231
|
+
});
|
|
232
|
+
if (!result.ok)
|
|
233
|
+
throw new Error(result.error || 'The conversation could not be deleted.');
|
|
234
|
+
if (archived && opts.archiveFile) {
|
|
235
|
+
out.removedBytes += (await fs.stat(opts.archiveFile)).size;
|
|
236
|
+
out.removedFiles++;
|
|
237
|
+
// Checked again right before the removal.
|
|
238
|
+
await checkedArchiveFolder(cwd);
|
|
239
|
+
if (!(await fs.lstat(opts.archiveFile)).isFile())
|
|
240
|
+
throw unsafe(path.relative(cwd, opts.archiveFile));
|
|
241
|
+
await fs.rm(opts.archiveFile, { force: true });
|
|
242
|
+
}
|
|
243
|
+
await recordStorageAction(cwd, { action: 'delete', workflowId, removedBytes: out.removedBytes, removedFiles: out.removedFiles, keptItems: out.keptItems });
|
|
244
|
+
return out;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
// COMPRESS OLD LOGS (operator click, per project): seal the live logs of
|
|
248
|
+
// closed conversations into compressed segments. Open or working
|
|
249
|
+
// conversations are skipped and listed; logs under 1 MiB are not worth it.
|
|
250
|
+
// Lossless: the same sealing as during writes, inside each conversation's
|
|
251
|
+
// flush chain. Nothing is deleted.
|
|
252
|
+
export const COMPRESS_MIN_BYTES = 1024 * 1024;
|
|
253
|
+
export async function compressOldLogs(cwd, opts) {
|
|
254
|
+
const root = path.join(cwd, '.arco', 'workflows');
|
|
255
|
+
const out = { sealed: 0, skippedOpen: [], failed: 0, deferred: 0, beforeBytes: 0, afterBytes: 0 };
|
|
256
|
+
let names = [];
|
|
257
|
+
try {
|
|
258
|
+
names = await fs.readdir(root);
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
names = [];
|
|
262
|
+
}
|
|
263
|
+
for (const id of names.sort()) {
|
|
264
|
+
if (!WFID.test(id))
|
|
265
|
+
continue;
|
|
266
|
+
// Linked folders are never sealed into (checkedConversationDir refuses them).
|
|
267
|
+
try {
|
|
268
|
+
await checkedConversationDir(cwd, id);
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const live = path.join(root, id, 'events.jsonl');
|
|
274
|
+
let size = 0;
|
|
275
|
+
try {
|
|
276
|
+
const st = await fs.lstat(live);
|
|
277
|
+
if (!st.isFile())
|
|
278
|
+
continue;
|
|
279
|
+
size = st.size;
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (size < COMPRESS_MIN_BYTES)
|
|
285
|
+
continue;
|
|
286
|
+
if (opts.isOpen(id) || opts.isBusy(id)) {
|
|
287
|
+
out.skippedOpen.push(id);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
const before = await logBytes(path.join(root, id));
|
|
291
|
+
let result;
|
|
292
|
+
try {
|
|
293
|
+
result = await opts.seal(cwd, id);
|
|
294
|
+
}
|
|
295
|
+
catch (err) {
|
|
296
|
+
out.failed++;
|
|
297
|
+
console.error(`[arco] compress logs: ${id.slice(0, 8)} not sealed:`, err);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (result && typeof result === 'object' && result.liveReplaced === false) {
|
|
301
|
+
out.deferred++;
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
const after = await logBytes(path.join(root, id));
|
|
305
|
+
if (after < before) {
|
|
306
|
+
out.sealed++;
|
|
307
|
+
out.beforeBytes += before;
|
|
308
|
+
out.afterBytes += after;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
await recordStorageAction(cwd, { action: 'compress_logs', sealed: out.sealed, skippedOpen: out.skippedOpen.length, failed: out.failed, deferred: out.deferred, beforeBytes: out.beforeBytes, afterBytes: out.afterBytes });
|
|
312
|
+
return out;
|
|
313
|
+
}
|
|
314
|
+
async function logBytes(dir) {
|
|
315
|
+
let total = 0;
|
|
316
|
+
try {
|
|
317
|
+
for (const name of await fs.readdir(dir)) {
|
|
318
|
+
if (name !== 'events.jsonl' && !/^events\.\d{12}-\d{12}\.jsonl\.br$/.test(name))
|
|
319
|
+
continue;
|
|
320
|
+
total += (await fs.lstat(path.join(dir, name))).size;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
catch { /* unreadable */ }
|
|
324
|
+
return total;
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=storageActions.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const ARCHIVE_SUFFIX = ".arcoarchive";
|
|
2
|
+
export declare function archiveDir(cwd: string): string;
|
|
3
|
+
export declare function archivePath(cwd: string, workflowId: string): string;
|
|
4
|
+
export interface ArchiveResult {
|
|
5
|
+
files: number;
|
|
6
|
+
originalBytes: number;
|
|
7
|
+
archiveBytes: number;
|
|
8
|
+
keptItems: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function archiveConversation(cwd: string, workflowId: string, opts: {
|
|
11
|
+
open: boolean;
|
|
12
|
+
busy: boolean;
|
|
13
|
+
by: 'operator' | 'policy';
|
|
14
|
+
}): Promise<ArchiveResult>;
|
|
15
|
+
export interface RestoreResult {
|
|
16
|
+
files: number;
|
|
17
|
+
restoredBytes: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function restoreConversation(cwd: string, workflowId: string): Promise<RestoreResult>;
|
|
20
|
+
export declare function listArchives(cwd: string): Promise<Array<{
|
|
21
|
+
workflowId: string;
|
|
22
|
+
bytes: number;
|
|
23
|
+
archivedAt: number;
|
|
24
|
+
}>>;
|