arco-workbench 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +63 -12
- package/README.md +21 -17
- package/client/dist/assets/{PhosphorBackdrop-DVQdBrTw.js → PhosphorBackdrop-DRu16-Is.js} +1 -1
- package/client/dist/assets/{ThemedBackgroundShaderImpl-BfSs2tB4.js → ThemedBackgroundShaderImpl-BLdwwQ4D.js} +1 -1
- package/client/dist/assets/{XtermView-DaMjC8Ny.js → XtermView-Xk7_9JaH.js} +1 -1
- package/client/dist/assets/{galleryEditor-BCQnXj7R.js → galleryEditor-CI8ClzBa.js} +1 -1
- package/client/dist/assets/{index-DD9kFGsF.css → index-BEFgrUJJ.css} +1 -1
- package/client/dist/assets/{index-COfbHCYv.js → index-C7WzZfsr.js} +257 -255
- package/client/dist/index.html +2 -2
- package/client/src/App.tsx +2 -0
- package/client/src/components/ChatMessage.tsx +33 -8
- package/client/src/components/ChatModeView.tsx +2 -0
- package/client/src/components/ClusterRightPanel/ReplaceMemberDialog.tsx +65 -15
- package/client/src/components/ClusterRightPanel/SkillsControl.tsx +124 -0
- package/client/src/components/ClusterRightPanel/index.tsx +4 -0
- package/client/src/components/ClusterTaskBoardTab.tsx +9 -22
- package/client/src/components/CodexLateCommand.tsx +34 -0
- package/client/src/components/DialogShell.tsx +2 -0
- package/client/src/components/MemberCard.tsx +4 -1
- package/client/src/components/MemberPane.tsx +3 -1
- package/client/src/components/NeedsYouBadge.tsx +3 -3
- package/client/src/components/PhoneUpload.tsx +288 -0
- package/client/src/components/PrimaryStatus.tsx +14 -6
- package/client/src/components/ProviderReleasesModal.tsx +8 -4
- package/client/src/components/ProvidersPopover.tsx +28 -23
- package/client/src/components/RuntimeStateBanner.tsx +5 -0
- package/client/src/components/SettingsPanel.tsx +2 -2
- package/client/src/components/SkillEditorDialog.tsx +2 -2
- package/client/src/components/SkillsSettings.tsx +21 -4
- package/client/src/components/TabBar.tsx +91 -9
- package/client/src/components/TerminalInput.tsx +15 -11
- package/client/src/components/TranscriptSendDialog.tsx +12 -8
- package/client/src/components/TranscriptWorkerDialog.tsx +119 -0
- package/client/src/components/WorkflowView.tsx +2 -0
- package/client/src/components/clusterNeedsYou.ts +11 -18
- package/client/src/explorer/ArtifactsLens.tsx +37 -28
- package/client/src/explorer/ExplorerApp.tsx +5 -4
- package/client/src/explorer/types.ts +8 -3
- package/client/src/help/content/cluster.tsx +48 -17
- package/client/src/help/content/composer.tsx +40 -1
- package/client/src/help/content/header.tsx +18 -1
- package/client/src/help/content/misc.tsx +9 -1
- package/client/src/help/content/settings.tsx +18 -4
- package/client/src/help/content/tabbar.tsx +5 -0
- package/client/src/help/manualSections/actions.tsx +31 -0
- package/client/src/help/manualSections/clusters.tsx +44 -20
- package/client/src/help/manualSections/configuration.tsx +20 -0
- package/client/src/help/manualSections/gettingStarted.tsx +4 -4
- package/client/src/help/manualSections/maintenance.tsx +25 -6
- package/client/src/help/manualSections/powerFeatures.tsx +3 -2
- package/client/src/help/manualSections/providers.tsx +32 -8
- package/client/src/help/manualSections/troubleshooting.tsx +2 -1
- package/client/src/help/manualSections/workflows.tsx +12 -0
- package/client/src/help/manualSections/workspace.tsx +36 -0
- package/client/src/stores/appStore.ts +7 -0
- package/client/src/stores/appStore.types.ts +4 -0
- package/client/src/styles/global.css +109 -0
- package/client/src/utils/phoneTheme.ts +38 -0
- package/client/src/utils/phoneUploadApi.ts +10 -0
- package/client/src/utils/transcriptWorkerRequest.ts +24 -0
- package/client/src/ws/handleServerMessage.ts +31 -8
- package/docs/ARCHITECTURE.md +1 -1
- package/docs/CLIENT.md +16 -9
- package/docs/FEATURES.md +13 -7
- package/docs/GETTING_STARTED.md +12 -6
- package/docs/GOTCHAS.md +2 -1
- package/docs/INDEX.md +1 -1
- package/docs/OPERATIONS.md +213 -52
- package/docs/PERSISTENCE.md +7 -2
- package/docs/PRIMITIVES.md +42 -0
- package/docs/PROTOCOL_CLUSTER.md +51 -4
- package/docs/PROTOCOL_PRIMITIVES.md +39 -0
- package/docs/PROVIDERS.md +84 -13
- package/docs/SETTINGS.md +29 -3
- package/docs/TASK_LEDGER.md +7 -15
- package/native/linux-x64/manifest.json +1 -1
- package/native/win32-x64/manifest.json +1 -1
- package/node_modules/@arco/shared/dist/clusterCoordination.d.ts +2 -0
- package/node_modules/@arco/shared/dist/clusterCoordination.js +5 -1
- package/node_modules/@arco/shared/dist/protocol/chat.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/clientMessages.d.ts +3 -2
- package/node_modules/@arco/shared/dist/protocol/clusters.d.ts +15 -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/models.d.ts +4 -3
- package/node_modules/@arco/shared/dist/protocol/models.js +26 -2
- package/node_modules/@arco/shared/dist/protocol/serverMessages.d.ts +13 -1
- package/node_modules/@arco/shared/dist/protocol/tasks.d.ts +4 -0
- package/node_modules/@arco/shared/dist/protocol/transcriptWorker.d.ts +47 -0
- package/node_modules/@arco/shared/dist/protocol/transcriptWorker.js +2 -0
- package/node_modules/@arco/shared/dist/protocol/workflows.d.ts +1 -0
- package/node_modules/@arco/shared/dist/runtimeVersions.d.ts +1 -0
- package/node_modules/@arco/shared/dist/runtimeVersions.js +14 -0
- package/node_modules/@arco/shared/package.json +1 -1
- package/package.json +2 -2
- package/scripts/packaging/arco.mjs +1 -1
- package/scripts/packaging/native-repair.mjs +32 -4
- package/server/dist/atomicFile.js +1 -2
- package/server/dist/capabilities.d.ts +5 -2
- package/server/dist/capabilities.js +59 -9
- package/server/dist/cliUpdateDecision.d.ts +1 -1
- package/server/dist/cliUpdateDecision.js +5 -3
- package/server/dist/clusterDirector.js +2 -1
- package/server/dist/clusterPeerOps.js +14 -8
- package/server/dist/clusterProgress.js +1 -1
- package/server/dist/clusterRehydrate.js +2 -0
- package/server/dist/clusterSkills.d.ts +13 -0
- package/server/dist/clusterSkills.js +81 -0
- package/server/dist/clusterSnapshots.js +2 -0
- package/server/dist/clusterStore.d.ts +7 -2
- package/server/dist/clusterStore.js +42 -1
- package/server/dist/diagnostics/codeSkew.js +1 -0
- package/server/dist/eventLog.d.ts +7 -0
- package/server/dist/eventLog.js +70 -13
- package/server/dist/explorerDocs.d.ts +10 -6
- package/server/dist/explorerDocs.js +75 -34
- package/server/dist/historyLimits.d.ts +1 -0
- package/server/dist/historyLimits.js +3 -0
- package/server/dist/http/attachmentUpload.d.ts +13 -0
- package/server/dist/http/attachmentUpload.js +38 -0
- package/server/dist/http/browserWorktrees.d.ts +23 -0
- package/server/dist/http/browserWorktrees.js +120 -0
- package/server/dist/http/phoneUploadDrafts.d.ts +13 -0
- package/server/dist/http/phoneUploadDrafts.js +125 -0
- package/server/dist/http/phoneUploadListener.d.ts +17 -0
- package/server/dist/http/phoneUploadListener.js +81 -0
- package/server/dist/http/phoneUploadNetwork.d.ts +9 -0
- package/server/dist/http/phoneUploadNetwork.js +106 -0
- package/server/dist/http/phoneUploadPage.d.ts +2 -0
- package/server/dist/http/phoneUploadPage.js +136 -0
- package/server/dist/http/phoneUploadRouteHistory.d.ts +4 -0
- package/server/dist/http/phoneUploadRouteHistory.js +72 -0
- package/server/dist/http/phoneUploadRoutes.d.ts +4 -0
- package/server/dist/http/phoneUploadRoutes.js +419 -0
- package/server/dist/http/phoneUploadTheme.d.ts +17 -0
- package/server/dist/http/phoneUploadTheme.js +96 -0
- package/server/dist/http/projectBinding.d.ts +1 -0
- package/server/dist/http/projectBinding.js +3 -2
- package/server/dist/http/readConfinement.js +5 -1
- package/server/dist/http/router.js +14 -25
- package/server/dist/http/writeConfinement.js +19 -2
- package/server/dist/index.js +24 -1
- package/server/dist/jsonlLines.d.ts +4 -0
- package/server/dist/jsonlLines.js +53 -0
- package/server/dist/management/identity.js +1 -0
- package/server/dist/mcp/clusterMcpTools.js +4 -4
- package/server/dist/primitives/seedWorker.d.ts +1 -0
- package/server/dist/primitives/seedWorker.js +2 -1
- package/server/dist/project/taskLedger.d.ts +4 -0
- package/server/dist/project/taskLedger.js +7 -4
- package/server/dist/providerConversation.d.ts +1 -0
- package/server/dist/providerConversation.js +17 -0
- package/server/dist/providers/claude-native/resumeSummary.d.ts +9 -0
- package/server/dist/providers/claude-native/resumeSummary.js +102 -49
- package/server/dist/providers/claude-native/worker.js +8 -4
- package/server/dist/providers/claude.js +2 -1
- package/server/dist/providers/clusterTaskToolDefinitions.js +4 -4
- package/server/dist/providers/codex-appserver/catalog.js +16 -1
- package/server/dist/providers/codex-appserver/heldCommands.d.ts +14 -0
- package/server/dist/providers/codex-appserver/heldCommands.js +54 -0
- package/server/dist/providers/codex-appserver/index.d.ts +52 -2
- package/server/dist/providers/codex-appserver/index.js +239 -21
- package/server/dist/providers/codex-appserver/lateCommands.d.ts +62 -0
- package/server/dist/providers/codex-appserver/lateCommands.js +195 -0
- package/server/dist/providers/codex-appserver/worker.d.ts +23 -1
- package/server/dist/providers/codex-appserver/worker.js +89 -20
- package/server/dist/providers/codex.js +2 -1
- package/server/dist/providers/codexCodeMode.d.ts +2 -1
- package/server/dist/providers/codexCodeMode.js +8 -3
- package/server/dist/providers/cursor/print.js +2 -1
- package/server/dist/providers/cursor/worker.js +2 -1
- package/server/dist/providers/llamacpp.js +17 -8
- package/server/dist/providers/ollamaRecovery.js +6 -6
- package/server/dist/providers/ollamaResilience.js +3 -3
- package/server/dist/providers/ollamaTokens.js +1 -1
- package/server/dist/quota.d.ts +0 -18
- package/server/dist/quota.js +0 -44
- package/server/dist/replacementHistory.d.ts +19 -0
- package/server/dist/replacementHistory.js +49 -0
- package/server/dist/server/broadcast.d.ts +2 -1
- package/server/dist/server/broadcast.js +1 -0
- package/server/dist/server/prompts.d.ts +1 -0
- package/server/dist/server/prompts.js +6 -1
- package/server/dist/sessionJsonl.d.ts +1 -1
- package/server/dist/sessionJsonl.js +115 -40
- package/server/dist/smartPickupAdapters.js +15 -2
- package/server/dist/transcriptWorker.d.ts +34 -0
- package/server/dist/transcriptWorker.js +201 -0
- package/server/dist/workers/WorkerManager.d.ts +1 -0
- package/server/dist/workers/WorkerManager.js +1 -0
- package/server/dist/workers/processKill.d.ts +9 -1
- package/server/dist/workers/processKill.js +26 -10
- package/server/dist/workflowStore.d.ts +1 -0
- package/server/dist/workflowStore.js +31 -0
- package/server/dist/ws/clusterHandlers.d.ts +1 -0
- package/server/dist/ws/clusterHandlers.js +62 -26
- package/server/dist/ws/handoffHandlers.js +7 -2
- package/server/dist/ws/transcriptWorkerHandlers.d.ts +25 -0
- package/server/dist/ws/transcriptWorkerHandlers.js +139 -0
- package/server/dist/ws/turnEngine.js +40 -9
- package/server/dist/ws/updatePrimaryConfig.js +27 -8
- package/server/dist/ws/workflowHandlers.d.ts +4 -1
- package/server/dist/ws/workflowHandlers.js +3 -1
- package/server/package.json +1 -1
- package/server/src/atomicFile.ts +1 -2
- package/server/src/capabilities.ts +58 -17
- package/server/src/cliUpdateDecision.ts +5 -4
- package/server/src/clusterDirector.ts +2 -1
- package/server/src/clusterPeerOps.ts +15 -9
- package/server/src/clusterProgress.ts +1 -1
- package/server/src/clusterRehydrate.ts +2 -0
- package/server/src/clusterSkills.ts +79 -0
- package/server/src/clusterSnapshots.ts +1 -0
- package/server/src/clusterStore.ts +38 -0
- package/server/src/diagnostics/codeSkew.ts +1 -0
- package/server/src/eventLog.ts +73 -13
- package/server/src/explorerDocs.ts +75 -34
- package/server/src/historyLimits.ts +2 -0
- package/server/src/http/attachmentUpload.ts +49 -0
- package/server/src/http/browserWorktrees.ts +124 -0
- package/server/src/http/phoneUploadDrafts.ts +118 -0
- package/server/src/http/phoneUploadListener.ts +96 -0
- package/server/src/http/phoneUploadNetwork.ts +117 -0
- package/server/src/http/phoneUploadPage.ts +137 -0
- package/server/src/http/phoneUploadRouteHistory.ts +73 -0
- package/server/src/http/phoneUploadRoutes.ts +398 -0
- package/server/src/http/phoneUploadTheme.ts +97 -0
- package/server/src/http/projectBinding.ts +3 -2
- package/server/src/http/readConfinement.ts +5 -1
- package/server/src/http/router.ts +12 -26
- package/server/src/http/writeConfinement.ts +13 -2
- package/server/src/index.ts +23 -0
- package/server/src/jsonlLines.ts +52 -0
- package/server/src/management/identity.ts +1 -0
- package/server/src/mcp/clusterMcpTools.ts +4 -4
- package/server/src/primitives/seedWorker.ts +3 -1
- package/server/src/project/taskLedger.ts +7 -5
- package/server/src/providerConversation.ts +15 -0
- package/server/src/providers/claude-native/resumeSummary.ts +98 -50
- package/server/src/providers/claude-native/worker.ts +8 -4
- package/server/src/providers/claude.ts +2 -1
- package/server/src/providers/clusterTaskToolDefinitions.ts +4 -4
- package/server/src/providers/codex-appserver/catalog.ts +14 -1
- package/server/src/providers/codex-appserver/heldCommands.ts +58 -0
- package/server/src/providers/codex-appserver/index.ts +222 -20
- package/server/src/providers/codex-appserver/lateCommands.ts +225 -0
- package/server/src/providers/codex-appserver/worker.ts +85 -21
- package/server/src/providers/codex.ts +2 -1
- package/server/src/providers/codexCodeMode.ts +9 -4
- package/server/src/providers/cursor/print.ts +2 -1
- package/server/src/providers/cursor/worker.ts +2 -1
- package/server/src/providers/llamacpp.ts +18 -7
- package/server/src/providers/llamacppRecovery.ts +2 -0
- package/server/src/providers/ollamaRecovery.ts +6 -6
- package/server/src/providers/ollamaResilience.ts +3 -3
- package/server/src/providers/ollamaTokens.ts +1 -1
- package/server/src/providers/ollamaToolSubset.ts +3 -3
- package/server/src/quota.ts +0 -50
- package/server/src/replacementHistory.ts +44 -0
- package/server/src/server/broadcast.ts +2 -0
- package/server/src/server/prompts.ts +8 -1
- package/server/src/sessionJsonl.ts +92 -32
- package/server/src/smartPickupAdapters.ts +17 -3
- package/server/src/transcriptWorker.ts +182 -0
- package/server/src/workers/WorkerManager.ts +2 -0
- package/server/src/workers/processKill.ts +35 -7
- package/server/src/workflowStore.ts +21 -0
- package/server/src/ws/clusterHandlers.ts +43 -25
- package/server/src/ws/handoffHandlers.ts +7 -1
- package/server/src/ws/transcriptWorkerHandlers.ts +126 -0
- package/server/src/ws/turnEngine.ts +35 -8
- package/server/src/ws/updatePrimaryConfig.ts +25 -6
- package/server/src/ws/workflowHandlers.ts +3 -1
- package/shared/dist/clusterCoordination.d.ts +2 -0
- package/shared/dist/clusterCoordination.js +5 -1
- package/shared/dist/protocol/chat.d.ts +1 -0
- package/shared/dist/protocol/clientMessages.d.ts +3 -2
- package/shared/dist/protocol/clusters.d.ts +15 -1
- package/shared/dist/protocol/index.d.ts +1 -0
- package/shared/dist/protocol/index.js +1 -0
- package/shared/dist/protocol/models.d.ts +4 -3
- package/shared/dist/protocol/models.js +26 -2
- package/shared/dist/protocol/serverMessages.d.ts +13 -1
- package/shared/dist/protocol/tasks.d.ts +4 -0
- package/shared/dist/protocol/transcriptWorker.d.ts +47 -0
- package/shared/dist/protocol/transcriptWorker.js +2 -0
- package/shared/dist/protocol/workflows.d.ts +1 -0
- package/shared/dist/runtimeVersions.d.ts +1 -0
- package/shared/dist/runtimeVersions.js +14 -0
- package/shared/src/clusterCoordination.ts +7 -1
- package/shared/src/protocol/chat.ts +1 -0
- package/shared/src/protocol/clientMessages.ts +5 -0
- package/shared/src/protocol/clusters.ts +20 -6
- package/shared/src/protocol/index.ts +1 -0
- package/shared/src/protocol/models.ts +31 -5
- package/shared/src/protocol/serverMessages.ts +13 -0
- package/shared/src/protocol/settings.ts +2 -3
- package/shared/src/protocol/tasks.ts +4 -7
- package/shared/src/protocol/transcriptWorker.ts +49 -0
- package/shared/src/protocol/workflows.ts +4 -0
- package/shared/src/runtimeVersions.ts +14 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { normalizeClusterRoleText } from '@arco/shared';
|
|
2
|
+
import { ClusterValidationError, MEMBER_ROLE_MAX, getClusterIdForWorkflow, readCluster } from './clusterStore.js';
|
|
3
|
+
import { MAX_PINNED_SKILLS, isValidSlug, resolvePinnedSkills } from './skills.js';
|
|
4
|
+
import { workflows } from './server/state.js';
|
|
5
|
+
import { readMeta } from './workflowMeta.js';
|
|
6
|
+
const key = (ref) => `${ref.scope}:${ref.slug}`;
|
|
7
|
+
const pinKey = (pin) => JSON.stringify([pin.scope, pin.slug, pin.role ?? null]);
|
|
8
|
+
export function uniqueSkillRefs(refs) {
|
|
9
|
+
return [...new Map(refs.map(ref => [key(ref), { scope: ref.scope, slug: ref.slug }])).values()];
|
|
10
|
+
}
|
|
11
|
+
export function parseClusterSkillPins(value) {
|
|
12
|
+
if (!Array.isArray(value))
|
|
13
|
+
throw new ClusterValidationError('skill_pins', 'Skills must be a list.');
|
|
14
|
+
const pins = value.map(pin => {
|
|
15
|
+
if (!pin || (pin.scope !== 'project' && pin.scope !== 'global') || !isValidSlug(pin.slug)
|
|
16
|
+
|| (pin.role !== undefined && (typeof pin.role !== 'string' || !pin.role.trim() || pin.role.trim().length > MEMBER_ROLE_MAX))) {
|
|
17
|
+
throw new ClusterValidationError('skill_pins', 'Choose an installed project/global skill and a saved role of at most 120 characters.');
|
|
18
|
+
}
|
|
19
|
+
return { scope: pin.scope, slug: pin.slug, ...(pin.role !== undefined ? { role: pin.role.trim() } : {}) };
|
|
20
|
+
});
|
|
21
|
+
return [...new Map(pins.map(pin => [pinKey(pin), pin])).values()];
|
|
22
|
+
}
|
|
23
|
+
export function skillRefsForRole(state, role, own = []) {
|
|
24
|
+
const savedRole = role ? normalizeClusterRoleText(role) : undefined;
|
|
25
|
+
return uniqueSkillRefs([
|
|
26
|
+
...(state.skillPins ?? []).filter(pin => pin.role === undefined),
|
|
27
|
+
...(state.skillPins ?? []).filter(pin => pin.role !== undefined && pin.role === savedRole),
|
|
28
|
+
...own,
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
export async function assertSkillUnion(state, role, own, label) {
|
|
32
|
+
const refs = skillRefsForRole(state, role, own);
|
|
33
|
+
if (refs.length > MAX_PINNED_SKILLS)
|
|
34
|
+
throw new ClusterValidationError('skill_limit', `${label}: tab, cluster and role pins together exceed 12 unique skills.`);
|
|
35
|
+
const resolved = await resolvePinnedSkills(refs, state.cwd);
|
|
36
|
+
if (resolved.truncated.length)
|
|
37
|
+
throw new ClusterValidationError('skill_limit', `${label}: tab, cluster and role pins together exceed 64 KiB of skill text.`);
|
|
38
|
+
}
|
|
39
|
+
export async function assertClusterSkillLimits(state) {
|
|
40
|
+
// Check role targets even when no current member has that role. New workers
|
|
41
|
+
// must inherit a usable set rather than discovering an over-limit role later.
|
|
42
|
+
const roles = new Set([undefined, ...(state.skillPins ?? []).map(pin => pin.role)]);
|
|
43
|
+
for (const role of roles)
|
|
44
|
+
await assertSkillUnion(state, role, [], role ? `Role ${role}` : 'All members');
|
|
45
|
+
for (const id of state.members) {
|
|
46
|
+
const wf = workflows.get(id);
|
|
47
|
+
const own = wf?.config.pinnedSkills ?? (await readMeta(state.cwd, id).catch(() => null))?.pinnedSkills ?? [];
|
|
48
|
+
await assertSkillUnion(state, state.memberRoles?.[id], own, wf?.config.name ?? `Member ${id.slice(0, 8)}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export async function validateNewClusterPins(state, pins) {
|
|
52
|
+
const previous = new Set((state.skillPins ?? []).map(pinKey));
|
|
53
|
+
// Removing a pin must stay possible after an edited skill grows over budget.
|
|
54
|
+
if (pins.every(pin => previous.has(pinKey(pin))))
|
|
55
|
+
return;
|
|
56
|
+
for (const pin of pins) {
|
|
57
|
+
if (previous.has(pinKey(pin)))
|
|
58
|
+
continue;
|
|
59
|
+
const resolved = await resolvePinnedSkills([pin], state.cwd);
|
|
60
|
+
if (resolved.missing.length)
|
|
61
|
+
throw new ClusterValidationError('skill_pins', `Skill ${pin.slug} is missing, off or unreadable. Choose an available skill.`);
|
|
62
|
+
if (resolved.truncated.length)
|
|
63
|
+
throw new ClusterValidationError('skill_limit', `Skill ${pin.slug} exceeds 64 KiB of text.`);
|
|
64
|
+
}
|
|
65
|
+
await assertClusterSkillLimits({ ...state, skillPins: pins });
|
|
66
|
+
}
|
|
67
|
+
export async function resolveWorkflowSkillPins(workflowId, cwd, own) {
|
|
68
|
+
const clusterId = getClusterIdForWorkflow(workflowId);
|
|
69
|
+
const cluster = clusterId ? await readCluster(clusterId) : null;
|
|
70
|
+
const refs = cluster ? skillRefsForRole(cluster, cluster.memberRoles?.[workflowId], own) : uniqueSkillRefs(own);
|
|
71
|
+
return { refs, resolved: await resolvePinnedSkills(refs, cluster?.cwd ?? cwd) };
|
|
72
|
+
}
|
|
73
|
+
export async function assertWorkflowSkillPins(workflowId, cwd, refs) {
|
|
74
|
+
const previous = new Set((workflows.get(workflowId)?.config.pinnedSkills ?? []).map(key));
|
|
75
|
+
if (refs.every(ref => previous.has(key(ref))))
|
|
76
|
+
return;
|
|
77
|
+
const clusterId = getClusterIdForWorkflow(workflowId);
|
|
78
|
+
const cluster = clusterId ? await readCluster(clusterId) : null;
|
|
79
|
+
await assertSkillUnion(cluster ?? { cwd }, cluster?.memberRoles?.[workflowId], refs, 'This tab');
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=clusterSkills.js.map
|
|
@@ -793,6 +793,8 @@ export async function restoreSnapshot(snapshotId, targetCwdInput, turnsPerMember
|
|
|
793
793
|
// Passive cluster configuration is portable. Runtime arming is not:
|
|
794
794
|
// idle-nudger, auto-turn, dispatcher enabled, REMOTE, and remote gates stay
|
|
795
795
|
// OFF on every restore so importing a cluster cannot start work or expose it.
|
|
796
|
+
if (src.skillPins?.length)
|
|
797
|
+
await clusterStore.setSkillPins(cluster.clusterId, src.skillPins, { restoringSnapshot: true });
|
|
796
798
|
if (src.autoCompaction)
|
|
797
799
|
await clusterStore.setAutoCompaction(cluster.clusterId, src.autoCompaction);
|
|
798
800
|
await clusterStore.setEfficiency(cluster.clusterId, src.efficiencyLevel ?? 'thorough', src.efficiencyAddendum ?? '', resolveClusterMessageGuard(src)).catch(() => { });
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { type AutoCompactionPolicy, MEMBER_TIERS, type ClusterMessageGuard, type ClusterCreationSettings, type ClusterDispatcherSettingsPatch, type ClusterDispatcherState, type ClusterEfficiencyLevel, type ClusterMemberAccessMode, type ClusterProgressMode, type ClusterTaskBoardMode, type MemberTier, isMemberTier, type RulePickupLimits, type AutoPickupMode, type SmartPickupEvaluator, type SmartPickupLimits, type SmartPickupSession } from '@arco/shared';
|
|
1
|
+
import { type AutoCompactionPolicy, MEMBER_TIERS, type ClusterMessageGuard, type ClusterCreationSettings, type ClusterSkillPin, type ClusterDispatcherSettingsPatch, type ClusterDispatcherState, type ClusterEfficiencyLevel, type ClusterMemberAccessMode, type ClusterProgressMode, type ClusterTaskBoardMode, type MemberTier, isMemberTier, type RulePickupLimits, type AutoPickupMode, type SmartPickupEvaluator, type SmartPickupLimits, type SmartPickupSession } from '@arco/shared';
|
|
2
2
|
export interface ClusterState {
|
|
3
|
+
skillPins?: ClusterSkillPin[];
|
|
3
4
|
autoCompaction?: AutoCompactionPolicy;
|
|
4
5
|
clusterId: string;
|
|
5
6
|
cwd: string;
|
|
@@ -48,6 +49,10 @@ export declare function createCluster(opts: {
|
|
|
48
49
|
cwd: string;
|
|
49
50
|
memberWorkflowIds: string[];
|
|
50
51
|
} & ClusterCreationSettings): Promise<ClusterState>;
|
|
52
|
+
export declare function withClusterSkillLock<T>(workflowId: string, fn: () => Promise<T>): Promise<T>;
|
|
53
|
+
export declare function setSkillPins(clusterId: string, value: unknown, options?: {
|
|
54
|
+
restoringSnapshot?: boolean;
|
|
55
|
+
}): Promise<ClusterState | null>;
|
|
51
56
|
export declare function readCluster(clusterId: string): Promise<ClusterState | null>;
|
|
52
57
|
export declare function loadAllClustersFromDisk(): Promise<ClusterState[]>;
|
|
53
58
|
export declare function deleteCluster(clusterId: string): Promise<void>;
|
|
@@ -60,7 +65,7 @@ export declare function removeMember(clusterId: string, workflowId: string): Pro
|
|
|
60
65
|
export declare function addMember(clusterId: string, workflowId: string): Promise<ClusterState | null>;
|
|
61
66
|
export declare function getMemberAccessMode(clusterId: string, workflowId: string): ClusterMemberAccessMode;
|
|
62
67
|
export declare function setMemberAccessMode(clusterId: string, workflowId: string, mode: ClusterMemberAccessMode): Promise<ClusterState | null>;
|
|
63
|
-
export declare function replaceMember(clusterId: string, oldWorkflowId: string, newWorkflowId: string, accessMode?: ClusterMemberAccessMode): Promise<ClusterState | null>;
|
|
68
|
+
export declare function replaceMember(clusterId: string, oldWorkflowId: string, newWorkflowId: string, accessMode?: ClusterMemberAccessMode, role?: string): Promise<ClusterState | null>;
|
|
64
69
|
export declare function getMembers(clusterId: string): string[] | undefined;
|
|
65
70
|
export declare function getPlanId(clusterId: string): string | undefined;
|
|
66
71
|
export declare function setPlanId(clusterId: string, planId: string): Promise<ClusterState | null>;
|
|
@@ -117,6 +117,29 @@ export async function createCluster(opts) {
|
|
|
117
117
|
function withClusterMetaLock(clusterId, fn) {
|
|
118
118
|
return withFileLock(clusterMetaPath(clusterId), fn);
|
|
119
119
|
}
|
|
120
|
+
// Direct tab-pin edits share the cluster lock with role and cluster-pin edits,
|
|
121
|
+
// so concurrent edits cannot each pass against an outdated effective union.
|
|
122
|
+
export function withClusterSkillLock(workflowId, fn) {
|
|
123
|
+
const clusterId = getClusterIdForWorkflow(workflowId);
|
|
124
|
+
return clusterId ? withClusterMetaLock(clusterId, fn) : fn();
|
|
125
|
+
}
|
|
126
|
+
export async function setSkillPins(clusterId, value, options = {}) {
|
|
127
|
+
return withClusterMetaLock(clusterId, async () => {
|
|
128
|
+
const state = await readCluster(clusterId);
|
|
129
|
+
if (!state)
|
|
130
|
+
return null;
|
|
131
|
+
const { parseClusterSkillPins, validateNewClusterPins } = await import('./clusterSkills.js');
|
|
132
|
+
const pins = parseClusterSkillPins(value);
|
|
133
|
+
// A saved snapshot has the same missing/off/grown-file behavior as restart.
|
|
134
|
+
// Current turn resolution still enforces the standing prompt limits.
|
|
135
|
+
if (!options.restoringSnapshot)
|
|
136
|
+
await validateNewClusterPins(state, pins);
|
|
137
|
+
const next = { ...state, skillPins: pins.length ? pins : undefined };
|
|
138
|
+
await writeMetaAtomic(next);
|
|
139
|
+
rebuildIndexFor(next);
|
|
140
|
+
return next;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
120
143
|
async function writeMetaAtomic(state) {
|
|
121
144
|
const path = clusterMetaPath(state.clusterId);
|
|
122
145
|
// proper-lockfile needs the file to exist before lock(); seed an empty
|
|
@@ -290,6 +313,8 @@ export async function addMember(clusterId, workflowId) {
|
|
|
290
313
|
throw new ClusterValidationError('member_already_in_cluster', `workflow ${workflowId} is already a member of cluster ${existing}; cross-cluster membership is rejected`);
|
|
291
314
|
}
|
|
292
315
|
const next = { ...state, members: [...state.members, workflowId] };
|
|
316
|
+
if (next.skillPins?.length)
|
|
317
|
+
await (await import('./clusterSkills.js')).assertClusterSkillLimits(next);
|
|
293
318
|
await writeMetaAtomic(next);
|
|
294
319
|
rebuildIndexFor(next);
|
|
295
320
|
memberJoined?.(clusterId, workflowId);
|
|
@@ -367,7 +392,7 @@ async function reassignPendingMailbox(clusterId, oldWorkflowId, newWorkflowId) {
|
|
|
367
392
|
// validates its config first; the meta write preserves member order and remaps
|
|
368
393
|
// every member-scoped setting without ever collapsing a 2-member cluster.
|
|
369
394
|
// Pending inbound mail follows the slot to the replacement workflow.
|
|
370
|
-
export async function replaceMember(clusterId, oldWorkflowId, newWorkflowId, accessMode) {
|
|
395
|
+
export async function replaceMember(clusterId, oldWorkflowId, newWorkflowId, accessMode, role) {
|
|
371
396
|
return withClusterMetaLock(clusterId, async () => {
|
|
372
397
|
const state = await readCluster(clusterId);
|
|
373
398
|
if (!state || !state.members.includes(oldWorkflowId))
|
|
@@ -398,6 +423,20 @@ export async function replaceMember(clusterId, oldWorkflowId, newWorkflowId, acc
|
|
|
398
423
|
memberFocuses: remapSparse(state.memberFocuses, oldWorkflowId, newWorkflowId),
|
|
399
424
|
memberAccessModes: Object.keys(nextModes).length > 0 ? nextModes : undefined,
|
|
400
425
|
};
|
|
426
|
+
if (role !== undefined) {
|
|
427
|
+
const roles = { ...next.memberRoles };
|
|
428
|
+
const savedRole = normalizeClusterRoleText(role).slice(0, MEMBER_ROLE_MAX);
|
|
429
|
+
if (savedRole)
|
|
430
|
+
roles[newWorkflowId] = savedRole;
|
|
431
|
+
else
|
|
432
|
+
delete roles[newWorkflowId];
|
|
433
|
+
const problem = clusterDirectorProblem(next.members.map(id => roles[id]));
|
|
434
|
+
if (problem)
|
|
435
|
+
throw new ClusterValidationError('multiple_directors', problem);
|
|
436
|
+
next.memberRoles = Object.keys(roles).length ? roles : undefined;
|
|
437
|
+
}
|
|
438
|
+
if (next.skillPins?.length)
|
|
439
|
+
await (await import('./clusterSkills.js')).assertClusterSkillLimits(next);
|
|
401
440
|
if (nextMode === 'isolated') {
|
|
402
441
|
await fs.mkdir(isolatedWorkspaceFor(clusterId, newWorkflowId), { recursive: true, mode: 0o700 });
|
|
403
442
|
}
|
|
@@ -517,6 +556,8 @@ export async function setMemberRole(clusterId, workflowId, role, options = {}) {
|
|
|
517
556
|
const next = Object.keys(nextRoles).length === 0
|
|
518
557
|
? { ...state, memberRoles: undefined }
|
|
519
558
|
: { ...state, memberRoles: nextRoles };
|
|
559
|
+
if (!options.restoringSnapshot && next.skillPins?.length)
|
|
560
|
+
await (await import('./clusterSkills.js')).assertClusterSkillLimits(next);
|
|
520
561
|
await writeMetaAtomic(next);
|
|
521
562
|
rebuildIndexFor(next);
|
|
522
563
|
return next;
|
|
@@ -43,6 +43,13 @@ export declare function readLogLines(dir: string, opts?: {
|
|
|
43
43
|
fromSeq?: number;
|
|
44
44
|
}): AsyncGenerator<string>;
|
|
45
45
|
export declare function readLogText(dir: string): Promise<string>;
|
|
46
|
+
export interface LogByteSource {
|
|
47
|
+
size: number;
|
|
48
|
+
chunks(start: number, length: number): AsyncGenerator<Buffer>;
|
|
49
|
+
read(start: number, length: number): Promise<string>;
|
|
50
|
+
close(): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
export declare function openLogByteSource(dir: string): Promise<LogByteSource | null>;
|
|
46
53
|
export declare function readLogTextSync(dir: string): string;
|
|
47
54
|
export declare function readLogTail(dir: string, maxBytes: number): Promise<{
|
|
48
55
|
text: string;
|
package/server/dist/eventLog.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// live records only up to the newest sequence number they actually read from
|
|
20
20
|
// a segment, or that a checked segment holds.
|
|
21
21
|
import { promises as fs, createReadStream, closeSync, fstatSync, openSync, readFileSync, readSync, readdirSync, statSync, constants as fsConstants } from 'node:fs';
|
|
22
|
-
import {
|
|
22
|
+
import { jsonlLines } from './jsonlLines.js';
|
|
23
23
|
import { brotliCompress, brotliDecompress, brotliDecompressSync, createBrotliDecompress, constants as zc } from 'node:zlib';
|
|
24
24
|
import { promisify } from 'node:util';
|
|
25
25
|
import { randomUUID } from 'node:crypto';
|
|
@@ -287,7 +287,7 @@ async function firstLiveSeq(file) {
|
|
|
287
287
|
if (!fh)
|
|
288
288
|
return null;
|
|
289
289
|
try {
|
|
290
|
-
for await (const line of handleLines(fh)) {
|
|
290
|
+
for await (const line of handleLines(fh, file)) {
|
|
291
291
|
const seq = lineSeq(line);
|
|
292
292
|
if (seq !== null)
|
|
293
293
|
return seq;
|
|
@@ -310,14 +310,13 @@ function reportUnreadable(err) {
|
|
|
310
310
|
console.error(`[arco] ${err instanceof Error ? err.message : String(err)}; skipping it, the rest of the history stays readable`);
|
|
311
311
|
}
|
|
312
312
|
async function* segmentLines(seg) {
|
|
313
|
-
const input = createReadStream(seg.file);
|
|
313
|
+
const input = createReadStream(seg.file, { highWaterMark: 64 * 1024 });
|
|
314
314
|
const decompressed = createBrotliDecompress();
|
|
315
315
|
// An error opening or reading the file (a segment removed or replaced since
|
|
316
316
|
// it was listed) reaches the reader below instead of going unhandled.
|
|
317
317
|
input.on('error', (err) => decompressed.destroy(err));
|
|
318
|
-
const rl = createInterface({ input: input.pipe(decompressed), crlfDelay: Infinity });
|
|
319
318
|
try {
|
|
320
|
-
for await (const line of
|
|
319
|
+
for await (const line of jsonlLines(input.pipe(decompressed), seg.file))
|
|
321
320
|
if (line)
|
|
322
321
|
yield line;
|
|
323
322
|
}
|
|
@@ -325,8 +324,8 @@ async function* segmentLines(seg) {
|
|
|
325
324
|
throw new SegmentReadError(seg.file, err);
|
|
326
325
|
}
|
|
327
326
|
finally {
|
|
328
|
-
rl.close();
|
|
329
327
|
input.destroy();
|
|
328
|
+
decompressed.destroy();
|
|
330
329
|
}
|
|
331
330
|
}
|
|
332
331
|
async function openLive(file) {
|
|
@@ -339,16 +338,14 @@ async function openLive(file) {
|
|
|
339
338
|
throw err;
|
|
340
339
|
}
|
|
341
340
|
}
|
|
342
|
-
async function* handleLines(fh) {
|
|
343
|
-
const input = fh.createReadStream({ autoClose: false });
|
|
344
|
-
const rl = createInterface({ input, crlfDelay: Infinity });
|
|
341
|
+
async function* handleLines(fh, source) {
|
|
342
|
+
const input = fh.createReadStream({ autoClose: false, highWaterMark: 64 * 1024 });
|
|
345
343
|
try {
|
|
346
|
-
for await (const line of
|
|
344
|
+
for await (const line of jsonlLines(input, source))
|
|
347
345
|
if (line)
|
|
348
346
|
yield line;
|
|
349
347
|
}
|
|
350
348
|
finally {
|
|
351
|
-
rl.close();
|
|
352
349
|
input.destroy();
|
|
353
350
|
}
|
|
354
351
|
}
|
|
@@ -357,7 +354,7 @@ async function* liveLines(file) {
|
|
|
357
354
|
if (!fh)
|
|
358
355
|
return;
|
|
359
356
|
try {
|
|
360
|
-
yield* handleLines(fh);
|
|
357
|
+
yield* handleLines(fh, file);
|
|
361
358
|
}
|
|
362
359
|
finally {
|
|
363
360
|
await fh.close();
|
|
@@ -416,7 +413,7 @@ export async function* readLogLines(dir, opts = {}) {
|
|
|
416
413
|
yield* drainSegments();
|
|
417
414
|
if (!fh)
|
|
418
415
|
return;
|
|
419
|
-
for await (const line of handleLines(fh))
|
|
416
|
+
for await (const line of handleLines(fh, path.join(dir, LIVE_LOG)))
|
|
420
417
|
if (!copies.drop(line))
|
|
421
418
|
yield line;
|
|
422
419
|
}
|
|
@@ -432,6 +429,66 @@ export async function readLogText(dir) {
|
|
|
432
429
|
parts.push(line);
|
|
433
430
|
return parts.length ? parts.join('\n') + '\n' : '';
|
|
434
431
|
}
|
|
432
|
+
export async function openLogByteSource(dir) {
|
|
433
|
+
let size = 0;
|
|
434
|
+
let chunks;
|
|
435
|
+
let close = async () => { };
|
|
436
|
+
if ((await listSegments(dir)).length) {
|
|
437
|
+
for await (const line of readLogLines(dir))
|
|
438
|
+
size += Buffer.byteLength(line, 'utf8') + 1;
|
|
439
|
+
chunks = async function* (start, length) {
|
|
440
|
+
const end = Math.min(size, start + length);
|
|
441
|
+
let position = 0;
|
|
442
|
+
for await (const line of readLogLines(dir)) {
|
|
443
|
+
const next = position + Buffer.byteLength(line, 'utf8') + 1;
|
|
444
|
+
if (next > start && position < end) {
|
|
445
|
+
const buffer = Buffer.from(line + '\n', 'utf8');
|
|
446
|
+
const from = Math.max(0, start - position), through = Math.min(buffer.length, end - position);
|
|
447
|
+
for (let offset = from; offset < through; offset += 64 * 1024) {
|
|
448
|
+
yield buffer.subarray(offset, Math.min(through, offset + 64 * 1024));
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
position = next;
|
|
452
|
+
if (position >= end)
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
const file = path.join(dir, LIVE_LOG);
|
|
459
|
+
const fh = await openLive(file);
|
|
460
|
+
if (!fh)
|
|
461
|
+
return null;
|
|
462
|
+
try {
|
|
463
|
+
const stat = await fh.stat();
|
|
464
|
+
if (!stat.isFile())
|
|
465
|
+
throw new Error(`Expected a history file at ${file}`);
|
|
466
|
+
size = stat.size;
|
|
467
|
+
}
|
|
468
|
+
catch (err) {
|
|
469
|
+
await fh.close();
|
|
470
|
+
throw err;
|
|
471
|
+
}
|
|
472
|
+
close = () => fh.close();
|
|
473
|
+
chunks = async function* (start, length) {
|
|
474
|
+
const end = Math.min(size, start + length);
|
|
475
|
+
for (let position = start; position < end;) {
|
|
476
|
+
const buffer = Buffer.alloc(Math.min(64 * 1024, end - position));
|
|
477
|
+
const { bytesRead } = await fh.read(buffer, 0, buffer.length, position);
|
|
478
|
+
if (!bytesRead)
|
|
479
|
+
break;
|
|
480
|
+
position += bytesRead;
|
|
481
|
+
yield buffer.subarray(0, bytesRead);
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
return { size, chunks, close, read: async (start, length) => {
|
|
486
|
+
const parts = [];
|
|
487
|
+
for await (const chunk of chunks(start, length))
|
|
488
|
+
parts.push(chunk);
|
|
489
|
+
return Buffer.concat(parts).toString('utf8');
|
|
490
|
+
} };
|
|
491
|
+
}
|
|
435
492
|
function decompressSegmentSync(seg) {
|
|
436
493
|
try {
|
|
437
494
|
return brotliDecompressSync(readFileSync(seg.file)).toString('utf8');
|
|
@@ -7,18 +7,22 @@ export interface DocEntry {
|
|
|
7
7
|
project: string;
|
|
8
8
|
cwd: string;
|
|
9
9
|
rel: string;
|
|
10
|
+
branch?: string;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
+
interface DocsPage {
|
|
12
13
|
entries: DocEntry[];
|
|
13
14
|
partial: boolean;
|
|
14
|
-
|
|
15
|
+
projects?: Array<{
|
|
16
|
+
cwd: string;
|
|
17
|
+
project: string;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
export declare function collectProjectDocsPage(project: string, limit?: number, global?: ScanBudget): Promise<DocsPage>;
|
|
15
21
|
export declare function collectProjectDocs(project: string, limit?: number): Promise<DocEntry[]>;
|
|
16
22
|
export declare function collectDocsPage(opts?: {
|
|
17
23
|
project?: string;
|
|
18
|
-
}): Promise<
|
|
19
|
-
entries: DocEntry[];
|
|
20
|
-
partial: boolean;
|
|
21
|
-
}>;
|
|
24
|
+
}): Promise<DocsPage>;
|
|
22
25
|
export declare function collectDocs(opts?: {
|
|
23
26
|
project?: string;
|
|
24
27
|
}): Promise<DocEntry[]>;
|
|
28
|
+
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { scanBeforeDeadline } from './scanDeadline.js';
|
|
2
2
|
import { projectFiles, scanBudget, exhausted } from './projectScan.js';
|
|
3
|
-
import { confinedPath } from './fileAccessPolicy.js';
|
|
3
|
+
import { confinedPath, createReadAccessContext } from './fileAccessPolicy.js';
|
|
4
|
+
import { resolveBoundCwd } from './http/writeConfinement.js';
|
|
5
|
+
import { browserWorktreeFile, browserWorktreeRegistry, confirmBrowserWorktree } from './http/browserWorktrees.js';
|
|
4
6
|
// ARCHIVE (docs/CLIENT.md) - project-DOCUMENT scan. The ARTIFACTS
|
|
5
7
|
// lens is a project-artifact tool, and the documents an operator most wants to
|
|
6
8
|
// find live in the PROJECT TREE (e.g. `Codex/Reports/2026-07-10_*.md`, top-level
|
|
@@ -9,14 +11,13 @@ import { confinedPath } from './fileAccessPolicy.js';
|
|
|
9
11
|
// scan is the other half: readable documents in the real tree, so drilling into
|
|
10
12
|
// a project shows the docs written FOR it, not just agent workflow spill.
|
|
11
13
|
//
|
|
12
|
-
// Portable pruned walk (no `fd`),
|
|
14
|
+
// Portable pruned walk (no `fd`), depth/count-capped. The global scan stays
|
|
15
|
+
// inside HOME; a scoped project can include Git-confirmed siblings. `.arco` is
|
|
13
16
|
// pruned wholesale here (the artifacts join owns it — merging both client-side
|
|
14
17
|
// gives the full picture without double-counting).
|
|
15
|
-
import { stat } from 'fs/promises';
|
|
16
|
-
import { basename,
|
|
17
|
-
import {
|
|
18
|
-
import { realpathWithinHome } from './explorerArtifacts.js';
|
|
19
|
-
import { arcoHome } from './arcoHome.js';
|
|
18
|
+
import { stat } from 'node:fs/promises';
|
|
19
|
+
import { basename, relative } from 'node:path';
|
|
20
|
+
import { readKnownCwds, realpathWithinHome } from './explorerArtifacts.js';
|
|
20
21
|
const PRUNE_DIRS = new Set([
|
|
21
22
|
'node_modules', '.git', 'dist', 'build', '.venv', '__pycache__',
|
|
22
23
|
'.next', 'target', '.cache', 'coverage', '.turbo', '.arco',
|
|
@@ -29,6 +30,27 @@ function isDoc(name) {
|
|
|
29
30
|
const ext = name.includes('.') ? name.split('.').pop().toLowerCase() : '';
|
|
30
31
|
return DOC_EXT.has(ext);
|
|
31
32
|
}
|
|
33
|
+
async function scanDocuments(root, owner, budget, out, authorize, branch) {
|
|
34
|
+
for await (const file of projectFiles(root, { budget, skip: PRUNE_DIRS, hidden: true, maxDepth: MAX_DEPTH })) {
|
|
35
|
+
if (!isDoc(file.name))
|
|
36
|
+
continue;
|
|
37
|
+
try {
|
|
38
|
+
const authorized = await scanBeforeDeadline(Promise.resolve(authorize(file.path)), budget);
|
|
39
|
+
if (!authorized)
|
|
40
|
+
break;
|
|
41
|
+
const st = await scanBeforeDeadline(stat(authorized), budget);
|
|
42
|
+
if (!st)
|
|
43
|
+
break;
|
|
44
|
+
out.push({ path: file.path, name: file.name, size: st.size, mtime: st.mtimeMs, project: basename(owner), cwd: owner,
|
|
45
|
+
rel: relative(root, file.path), ...(branch ? { branch } : {}) });
|
|
46
|
+
}
|
|
47
|
+
catch { /* unreadable or outside the project */ }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function finishPage(out, limit, budget) {
|
|
51
|
+
out.sort((a, b) => b.mtime - a.mtime);
|
|
52
|
+
return { entries: out.slice(0, limit), partial: budget.partial || out.length > limit };
|
|
53
|
+
}
|
|
32
54
|
// Walk one project tree for document files, newest-first, capped.
|
|
33
55
|
export async function collectProjectDocsPage(project, limit = 1000, global) {
|
|
34
56
|
const budget = scanBudget();
|
|
@@ -41,62 +63,81 @@ export async function collectProjectDocsPage(project, limit = 1000, global) {
|
|
|
41
63
|
budget.entries = Math.min(budget.entries, global.entries);
|
|
42
64
|
const starting = budget.entries;
|
|
43
65
|
const out = [];
|
|
44
|
-
|
|
45
|
-
if (!isDoc(file.name))
|
|
46
|
-
continue;
|
|
47
|
-
try {
|
|
48
|
-
confinedPath(file.path, [root], 'file');
|
|
49
|
-
const st = await scanBeforeDeadline(stat(file.path), budget);
|
|
50
|
-
if (!st)
|
|
51
|
-
break;
|
|
52
|
-
out.push({ path: file.path, name: file.name, size: st.size, mtime: st.mtimeMs, project: basename(root), cwd: root, rel: relative(root, file.path) });
|
|
53
|
-
}
|
|
54
|
-
catch { /* unreadable or outside the project */ }
|
|
55
|
-
}
|
|
66
|
+
await scanDocuments(root, root, budget, out, file => confinedPath(file, [root], 'file'));
|
|
56
67
|
if (global)
|
|
57
68
|
global.entries -= starting - budget.entries;
|
|
58
|
-
out
|
|
59
|
-
return { entries: out.slice(0, limit), partial: budget.partial || out.length > limit };
|
|
69
|
+
return finishPage(out, limit, budget);
|
|
60
70
|
}
|
|
61
71
|
export async function collectProjectDocs(project, limit = 1000) {
|
|
62
72
|
return (await collectProjectDocsPage(project, limit)).entries;
|
|
63
73
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return
|
|
74
|
+
async function collectScopedDocs(project) {
|
|
75
|
+
const budget = scanBudget();
|
|
76
|
+
const out = [];
|
|
77
|
+
const root = await scanBeforeDeadline(realpathWithinHome(project), budget);
|
|
78
|
+
if (root)
|
|
79
|
+
await scanDocuments(root, root, budget, out, file => confinedPath(file, [root], 'file'));
|
|
80
|
+
if (exhausted(budget))
|
|
81
|
+
return finishPage(out, 1000, budget);
|
|
82
|
+
const bound = await scanBeforeDeadline(resolveBoundCwd(project, undefined), budget);
|
|
83
|
+
if (!bound?.ok)
|
|
84
|
+
return finishPage(out, 1000, budget);
|
|
85
|
+
const access = await scanBeforeDeadline(createReadAccessContext(), budget);
|
|
86
|
+
if (!access)
|
|
87
|
+
return finishPage(out, 1000, budget);
|
|
88
|
+
const owner = root ?? await scanBeforeDeadline(access.safeDirectory(bound.cwd), budget);
|
|
89
|
+
if (!owner)
|
|
90
|
+
return finishPage(out, 1000, budget);
|
|
91
|
+
const signal = AbortSignal.timeout(Math.max(1, Math.ceil(budget.deadline - performance.now())));
|
|
92
|
+
const registry = await scanBeforeDeadline(browserWorktreeRegistry(owner, signal), budget);
|
|
93
|
+
if (!registry) {
|
|
94
|
+
if (signal.aborted)
|
|
95
|
+
budget.partial = true;
|
|
96
|
+
return finishPage(out, 1000, budget);
|
|
72
97
|
}
|
|
73
|
-
|
|
74
|
-
|
|
98
|
+
for (const entry of registry.entries) {
|
|
99
|
+
if (exhausted(budget))
|
|
100
|
+
break;
|
|
101
|
+
const tree = await scanBeforeDeadline(confirmBrowserWorktree(registry, entry, access, signal), budget);
|
|
102
|
+
if (!tree)
|
|
103
|
+
continue;
|
|
104
|
+
await scanDocuments(tree.canonical, owner, budget, out, file => browserWorktreeFile(file, tree, access), tree.branch);
|
|
75
105
|
}
|
|
106
|
+
if (signal.aborted)
|
|
107
|
+
budget.partial = true;
|
|
108
|
+
return finishPage(out, 1000, budget);
|
|
76
109
|
}
|
|
77
110
|
// Global doc scan across known projects, bounded per-project so a home load over
|
|
78
111
|
// dozens of projects stays responsive. `project` scopes to one (full limit).
|
|
79
112
|
export async function collectDocsPage(opts = {}) {
|
|
80
113
|
if (opts.project)
|
|
81
|
-
return
|
|
114
|
+
return collectScopedDocs(opts.project);
|
|
82
115
|
const global = scanBudget(50_000, 650);
|
|
83
116
|
const known = await scanBeforeDeadline(readKnownCwds(), global);
|
|
84
117
|
if (!known)
|
|
85
118
|
return { entries: [], partial: true };
|
|
86
119
|
const cwds = [...new Set(known)];
|
|
87
120
|
const all = [];
|
|
121
|
+
const projects = new Map();
|
|
122
|
+
const access = await scanBeforeDeadline(createReadAccessContext(), global);
|
|
123
|
+
if (!access)
|
|
124
|
+
return { entries: [], partial: true };
|
|
88
125
|
let partial = false;
|
|
89
126
|
for (const cwd of cwds) {
|
|
90
127
|
if (exhausted(global)) {
|
|
91
128
|
partial = true;
|
|
92
129
|
break;
|
|
93
130
|
}
|
|
94
|
-
const
|
|
131
|
+
const root = await scanBeforeDeadline(access.safeDirectory(cwd).catch(() => null), global);
|
|
132
|
+
if (!root)
|
|
133
|
+
continue;
|
|
134
|
+
projects.set(root, { cwd: root, project: basename(root) });
|
|
135
|
+
const page = await collectProjectDocsPage(root, 150, global).catch(() => ({ entries: [], partial: true }));
|
|
95
136
|
all.push(...page.entries);
|
|
96
137
|
partial ||= page.partial;
|
|
97
138
|
}
|
|
98
139
|
all.sort((a, b) => b.mtime - a.mtime);
|
|
99
|
-
return { entries: all.slice(0, 600), partial: partial || all.length > 600 };
|
|
140
|
+
return { entries: all.slice(0, 600), partial: partial || global.partial || all.length > 600, projects: [...projects.values()] };
|
|
100
141
|
}
|
|
101
142
|
export async function collectDocs(opts = {}) {
|
|
102
143
|
return (await collectDocsPage(opts)).entries;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const RECENT_HISTORY_MAX_BYTES: number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
export interface StoredAttachment {
|
|
3
|
+
fileId: string;
|
|
4
|
+
filename: string;
|
|
5
|
+
path: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class UploadTooLarge extends Error {
|
|
8
|
+
}
|
|
9
|
+
export declare function readAttachmentBody(req: IncomingMessage, limit?: number): Promise<Buffer>;
|
|
10
|
+
export declare function storeAttachment(body: Buffer, rawFilename: string, contentType: string, reservation?: {
|
|
11
|
+
fileId: string;
|
|
12
|
+
beforeWrite: (file: StoredAttachment) => Promise<void>;
|
|
13
|
+
}): Promise<StoredAttachment>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { basename, extname, join } from 'node:path';
|
|
4
|
+
import { shrinkUploadedImage } from '../uploadImages.js';
|
|
5
|
+
import { queueModelImage } from '../providers/attachments.js';
|
|
6
|
+
import { UPLOADS_DIR, UPLOAD_IMAGE_EXT } from '../server/constants.js';
|
|
7
|
+
import { ensureStorageRoot } from '../storageRoot.js';
|
|
8
|
+
export class UploadTooLarge extends Error {
|
|
9
|
+
}
|
|
10
|
+
export async function readAttachmentBody(req, limit) {
|
|
11
|
+
const chunks = [];
|
|
12
|
+
let size = 0;
|
|
13
|
+
for await (const chunk of req.iterator({ destroyOnReturn: false })) {
|
|
14
|
+
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
15
|
+
size += bytes.length;
|
|
16
|
+
if (limit !== undefined && size > limit)
|
|
17
|
+
throw new UploadTooLarge();
|
|
18
|
+
chunks.push(bytes);
|
|
19
|
+
}
|
|
20
|
+
return Buffer.concat(chunks, size);
|
|
21
|
+
}
|
|
22
|
+
export async function storeAttachment(body, rawFilename, contentType, reservation) {
|
|
23
|
+
const inferredExt = !extname(rawFilename) ? UPLOAD_IMAGE_EXT[contentType] : undefined;
|
|
24
|
+
const filename = basename(rawFilename) + (inferredExt ?? '');
|
|
25
|
+
const fileId = reservation?.fileId ?? randomUUID().slice(0, 8);
|
|
26
|
+
const root = await ensureStorageRoot(UPLOADS_DIR);
|
|
27
|
+
const path = join(root, `${fileId}-${filename}`);
|
|
28
|
+
const stored = { fileId, filename, path };
|
|
29
|
+
await reservation?.beforeWrite(stored);
|
|
30
|
+
await writeFile(path, body, { flag: 'wx', mode: 0o600 });
|
|
31
|
+
if (!reservation)
|
|
32
|
+
console.log(`[arco] File uploaded: ${filename} -> ${path}`);
|
|
33
|
+
// Finish any replacement before publishing the stable path.
|
|
34
|
+
await shrinkUploadedImage(path);
|
|
35
|
+
queueModelImage(path);
|
|
36
|
+
return stored;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=attachmentUpload.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ReadAccessContext } from '../fileAccessPolicy.js';
|
|
2
|
+
interface RegisteredWorktree {
|
|
3
|
+
directory: string;
|
|
4
|
+
branch: string;
|
|
5
|
+
}
|
|
6
|
+
interface WorktreeRegistry {
|
|
7
|
+
checkout: string;
|
|
8
|
+
common: string;
|
|
9
|
+
entries: RegisteredWorktree[];
|
|
10
|
+
}
|
|
11
|
+
interface BrowserWorktree {
|
|
12
|
+
directory: string;
|
|
13
|
+
canonical: string;
|
|
14
|
+
native: string;
|
|
15
|
+
branch: string;
|
|
16
|
+
device: number;
|
|
17
|
+
inode: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function browserWorktreeRegistry(boundCwd: string, signal?: AbortSignal): Promise<WorktreeRegistry | null>;
|
|
20
|
+
export declare function confirmBrowserWorktree(registry: WorktreeRegistry, entry: RegisteredWorktree, access: ReadAccessContext, signal?: AbortSignal): Promise<BrowserWorktree | null>;
|
|
21
|
+
export declare function browserWorktreeFile(target: string, tree: BrowserWorktree, access: ReadAccessContext): Promise<string>;
|
|
22
|
+
export declare function resolveWorktreeFile(target: string, boundCwd: string, access: ReadAccessContext): Promise<string>;
|
|
23
|
+
export {};
|