synabun 2.4.1 → 2.4.2
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/CHANGELOG.md +30 -0
- package/README.md +1 -1
- package/browser-extension/content.js +56 -14
- package/browser-extension/engine.js +158 -8
- package/browser-extension/manifest.json +3 -1
- package/browser-extension/protocol.js +91 -6
- package/browser-extension/service-worker.js +13 -5
- package/browser-extension/tokens.css +1 -1
- package/docs/browser-extension-bridge.md +24 -4
- package/lib/data-home-files.js +4 -2
- package/lib/first-launch-protection.js +8 -2
- package/lib/update-snapshot.js +11 -4
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +25 -2
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +62 -17
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-bench.d.ts +22 -22
- package/mcp-server/dist/services/memory-maintenance.d.ts +1 -0
- package/mcp-server/dist/services/memory-maintenance.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-maintenance.js +34 -45
- package/mcp-server/dist/services/memory-maintenance.js.map +1 -1
- package/mcp-server/dist/services/memory-migration-copy.d.ts +144 -0
- package/mcp-server/dist/services/memory-migration-copy.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-copy.js +467 -0
- package/mcp-server/dist/services/memory-migration-copy.js.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts +2 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.js +60 -0
- package/mcp-server/dist/services/memory-migration-worker.js.map +1 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts +4 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-retrieval.js +188 -40
- package/mcp-server/dist/services/memory-retrieval.js.map +1 -1
- package/mcp-server/dist/services/memory-schema.d.ts +58 -2
- package/mcp-server/dist/services/memory-schema.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-schema.js +190 -13
- package/mcp-server/dist/services/memory-schema.js.map +1 -1
- package/mcp-server/dist/services/memory-sessions.d.ts +19 -1
- package/mcp-server/dist/services/memory-sessions.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-sessions.js +56 -20
- package/mcp-server/dist/services/memory-sessions.js.map +1 -1
- package/mcp-server/dist/services/memory-verification.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-verification.js +8 -5
- package/mcp-server/dist/services/memory-verification.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +5 -0
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +19 -2
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts +2 -0
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js +76 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts +38 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.js +145 -0
- package/mcp-server/dist/services/retrieval-reader.js.map +1 -0
- package/mcp-server/dist/services/sqlite-write.d.ts +14 -0
- package/mcp-server/dist/services/sqlite-write.d.ts.map +1 -0
- package/mcp-server/dist/services/sqlite-write.js +94 -0
- package/mcp-server/dist/services/sqlite-write.js.map +1 -0
- package/mcp-server/dist/services/sqlite.d.ts +39 -0
- package/mcp-server/dist/services/sqlite.d.ts.map +1 -1
- package/mcp-server/dist/services/sqlite.js +249 -8
- package/mcp-server/dist/services/sqlite.js.map +1 -1
- package/mcp-server/dist/services/tool-catalog.d.ts +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts +7 -1
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe-config.js +32 -10
- package/mcp-server/dist/services/typesafe-config.js.map +1 -1
- package/mcp-server/dist/services/typesafe.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe.js +9 -7
- package/mcp-server/dist/services/typesafe.js.map +1 -1
- package/mcp-server/dist/services/vector-cache.d.ts +32 -0
- package/mcp-server/dist/services/vector-cache.d.ts.map +1 -1
- package/mcp-server/dist/services/vector-cache.js +161 -8
- package/mcp-server/dist/services/vector-cache.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
- package/mcp-server/dist/tools/agents.d.ts +11 -7
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +27 -9
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +10 -3
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.d.ts +5 -0
- package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-extension-setup.js +23 -0
- package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -0
- package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-interact.js +6 -1
- package/mcp-server/dist/tools/browser-interact.js.map +1 -1
- package/mcp-server/dist/tools/fb-groups.d.ts +2 -2
- package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
- package/mcp-server/dist/tools/tool-groups.d.ts +1 -1
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +20 -2
- package/mcp-server/src/index.ts +59 -17
- package/mcp-server/src/services/memory-maintenance.ts +31 -28
- package/mcp-server/src/services/memory-migration-copy.ts +419 -0
- package/mcp-server/src/services/memory-migration-worker.ts +55 -0
- package/mcp-server/src/services/memory-retrieval.ts +173 -32
- package/mcp-server/src/services/memory-schema.ts +194 -12
- package/mcp-server/src/services/memory-sessions.ts +54 -21
- package/mcp-server/src/services/memory-verification.ts +7 -4
- package/mcp-server/src/services/neural-interface.ts +22 -2
- package/mcp-server/src/services/retrieval-reader-worker.ts +67 -0
- package/mcp-server/src/services/retrieval-reader.ts +131 -0
- package/mcp-server/src/services/sqlite-write.ts +60 -0
- package/mcp-server/src/services/sqlite.ts +246 -8
- package/mcp-server/src/services/typesafe-config.ts +25 -6
- package/mcp-server/src/services/typesafe.ts +9 -7
- package/mcp-server/src/services/vector-cache.ts +154 -9
- package/mcp-server/src/tools/agents.ts +26 -9
- package/mcp-server/src/tools/browser-advanced.ts +10 -3
- package/mcp-server/src/tools/browser-extension-setup.ts +30 -0
- package/mcp-server/src/tools/browser-interact.ts +5 -1
- package/neural-interface/i18n/en.json +263 -1
- package/neural-interface/i18n/pt-BR.json +264 -2
- package/neural-interface/lib/agents/split.js +32 -4
- package/neural-interface/lib/assistant-api.js +19 -8
- package/neural-interface/lib/assistant-brains/claude.js +2 -0
- package/neural-interface/lib/assistant-catalog.js +2 -2
- package/neural-interface/lib/assistant-config.js +0 -7
- package/neural-interface/lib/assistant-dispatch.js +257 -95
- package/neural-interface/lib/assistant-persona.js +16 -4
- package/neural-interface/lib/assistant-pricing.js +65 -14
- package/neural-interface/lib/assistant-router.js +131 -47
- package/neural-interface/lib/assistant-run-wait.js +45 -28
- package/neural-interface/lib/assistant-runtime.js +39 -33
- package/neural-interface/lib/backup-contents.js +158 -0
- package/neural-interface/lib/backup-crypto-io.js +330 -0
- package/neural-interface/lib/backup-crypto-worker.js +130 -0
- package/neural-interface/lib/backup-crypto.js +525 -0
- package/neural-interface/lib/backup-download.js +268 -0
- package/neural-interface/lib/backup-encryption.js +318 -0
- package/neural-interface/lib/backup-groups.js +287 -0
- package/neural-interface/lib/backup-restore-session.js +176 -0
- package/neural-interface/lib/backup-restore-stage.js +60 -0
- package/neural-interface/lib/backup-service.js +788 -233
- package/neural-interface/lib/backup-zip-reader.js +30 -18
- package/neural-interface/lib/backup-zip-writer.js +34 -10
- package/neural-interface/lib/browser-extension-adapter.js +89 -13
- package/neural-interface/lib/browser-extension-bridge.js +18 -7
- package/neural-interface/lib/claude-agent-bridge.js +1 -0
- package/neural-interface/lib/claude-session-cleanup.js +5 -1
- package/neural-interface/lib/cli-update-planner.js +105 -6
- package/neural-interface/lib/client-diagnostics.js +42 -0
- package/neural-interface/lib/confined-fs.js +7 -2
- package/neural-interface/lib/coordination/README.md +8 -2
- package/neural-interface/lib/coordination/contract.js +161 -0
- package/neural-interface/lib/coordination/database.js +999 -0
- package/neural-interface/lib/coordination/operations.js +436 -0
- package/neural-interface/lib/coordination/service.js +68 -537
- package/neural-interface/lib/coordination/storage-worker.js +101 -0
- package/neural-interface/lib/coordination/store.js +219 -1111
- package/neural-interface/lib/db.js +70 -32
- package/neural-interface/lib/health-count.js +37 -0
- package/neural-interface/lib/loop-stall.js +139 -0
- package/neural-interface/lib/maritaca/client.js +2 -2
- package/neural-interface/lib/maritaca/models.js +12 -17
- package/neural-interface/lib/maritaca/opencode.js +4 -2
- package/neural-interface/lib/memory-api.js +9 -1
- package/neural-interface/lib/memory-session-capture.js +42 -10
- package/neural-interface/lib/memory-store-gate.js +313 -0
- package/neural-interface/lib/memory-store-migrate.js +65 -0
- package/neural-interface/lib/memory-timers.js +7 -7
- package/neural-interface/lib/native-loop-providers.js +13 -16
- package/neural-interface/lib/native-loop-runtime.js +28 -7
- package/neural-interface/lib/opencode-build-preflight.js +18 -1
- package/neural-interface/lib/opencode-native-boundary.js +69 -8
- package/neural-interface/lib/opencode-provider-view.js +14 -3
- package/neural-interface/lib/opencode-v2-ws-requests.js +31 -1
- package/neural-interface/lib/opencode2-client.js +2 -1
- package/neural-interface/lib/recall-impact.js +122 -0
- package/neural-interface/lib/scratch-evidence.js +420 -0
- package/neural-interface/lib/scratch-process-guard.js +139 -0
- package/neural-interface/lib/scratch-references.js +279 -0
- package/neural-interface/lib/scratch-retention-core.js +385 -0
- package/neural-interface/lib/scratch-retention-worker.js +37 -0
- package/neural-interface/lib/scratch-retention.js +151 -0
- package/neural-interface/lib/session-cache-builder.js +31 -43
- package/neural-interface/lib/session-cache-worker.js +157 -0
- package/neural-interface/lib/session-indexer.js +28 -21
- package/neural-interface/lib/session-search-index.js +85 -0
- package/neural-interface/lib/skills/creation.js +1 -1
- package/neural-interface/lib/sqlite-integrity-worker.js +3 -1
- package/neural-interface/lib/style-guide/store.js +43 -3
- package/neural-interface/lib/system-restore.js +50 -0
- package/neural-interface/lib/teams/api.js +15 -6
- package/neural-interface/lib/teams/claims.js +67 -31
- package/neural-interface/lib/teams/index.js +7 -7
- package/neural-interface/lib/teams/integration.js +40 -40
- package/neural-interface/lib/teams/landing.js +6 -6
- package/neural-interface/lib/teams/recovery.js +24 -23
- package/neural-interface/lib/teams/scheduler.js +194 -95
- package/neural-interface/lib/teams/state.js +14 -14
- package/neural-interface/lib/teams/worktrees.js +27 -27
- package/neural-interface/lib/whatsapp/bridge.js +2 -1
- package/neural-interface/lib/worker-confinement.js +47 -2
- package/neural-interface/lib/worker-mcp-channel.js +2 -0
- package/neural-interface/lib/worker-resume.js +5 -0
- package/neural-interface/lib/worker-stop.js +86 -0
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/index.html +233 -24
- package/neural-interface/public/onboarding.html +259 -34
- package/neural-interface/public/shared/agents/studio/ax-library.js +0 -6
- package/neural-interface/public/shared/agents/studio/ax-main.js +14 -7
- package/neural-interface/public/shared/agy/agy-options.js +11 -0
- package/neural-interface/public/shared/agy/agy-panel.js +29 -10
- package/neural-interface/public/shared/agy/agy-styles.js +14 -12
- package/neural-interface/public/shared/agy/agy-tabs-logic.js +4 -1
- package/neural-interface/public/shared/api.js +1 -1
- package/neural-interface/public/shared/assistant/asst-api.js +3 -3
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +13 -6
- package/neural-interface/public/shared/assistant/asst-control.js +2 -0
- package/neural-interface/public/shared/assistant/asst-motion-gate.js +78 -4
- package/neural-interface/public/shared/assistant/asst-panel.js +18 -2
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +4 -0
- package/neural-interface/public/shared/assistant/asst-render.js +105 -38
- package/neural-interface/public/shared/assistant/asst-route.js +100 -21
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +1 -1
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +4 -2
- package/neural-interface/public/shared/assistant/asst-state.js +11 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +10 -23
- package/neural-interface/public/shared/assistant/route-identity.js +2 -1
- package/neural-interface/public/shared/cdx/cdx-render.js +9 -0
- package/neural-interface/public/shared/cdx/cdx-settings.js +3 -1
- package/neural-interface/public/shared/cdx/cdx-styles.js +6 -0
- package/neural-interface/public/shared/cdx/cdx-tabs.js +29 -9
- package/neural-interface/public/shared/client-diagnostics.js +94 -0
- package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
- package/neural-interface/public/shared/cp/cp-styles.js +1 -1
- package/neural-interface/public/shared/effort-i18n.js +118 -0
- package/neural-interface/public/shared/html-shell.js +4 -52
- package/neural-interface/public/shared/loading-diagnostic-entry.js +64 -0
- package/neural-interface/public/shared/memory-store-wait.js +52 -0
- package/neural-interface/public/shared/morelogin-profile-field.js +1 -1
- package/neural-interface/public/shared/mtc/mtc-logic.js +2 -1
- package/neural-interface/public/shared/mtc/mtc-panel.js +8 -1
- package/neural-interface/public/shared/mtc/mtc-styles.js +13 -12
- package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +7 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-location-logic.js +109 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-modelpicker.js +8 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +118 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +27 -3
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +13 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +2 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +27 -93
- package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +17 -6
- package/neural-interface/public/shared/output-format.js +294 -0
- package/neural-interface/public/shared/provider-icons.js +6 -0
- package/neural-interface/public/shared/schedules-view.js +2 -1
- package/neural-interface/public/shared/server-presence.js +77 -0
- package/neural-interface/public/shared/settings/settings-backup-contents.js +241 -0
- package/neural-interface/public/shared/settings/settings-backup-download.js +298 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption-pane.js +335 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption.js +545 -0
- package/neural-interface/public/shared/settings/settings-ia.js +1 -1
- package/neural-interface/public/shared/skills/studio/sx-geometry.js +12 -3
- package/neural-interface/public/shared/skills/studio/sx-main.js +14 -7
- package/neural-interface/public/shared/studio-attention.js +6 -0
- package/neural-interface/public/shared/styles.css +341 -437
- package/neural-interface/public/shared/transcript-rows.js +28 -3
- package/neural-interface/public/shared/tray-auto-close.js +18 -5
- package/neural-interface/public/shared/ui-agents.js +1 -2
- package/neural-interface/public/shared/ui-automation-studio.js +168 -108
- package/neural-interface/public/shared/ui-claude-panel.js +42 -65
- package/neural-interface/public/shared/ui-loading.js +124 -17
- package/neural-interface/public/shared/ui-native-loop-router.js +10 -0
- package/neural-interface/public/shared/ui-navbar.js +2 -1
- package/neural-interface/public/shared/ui-output.js +533 -0
- package/neural-interface/public/shared/ui-schedules-studio.js +165 -128
- package/neural-interface/public/shared/ui-scroll-follow.js +97 -6
- package/neural-interface/public/shared/ui-sessions.js +2 -2
- package/neural-interface/public/shared/ui-settings-entry.js +18 -0
- package/neural-interface/public/shared/ui-settings.js +224 -65
- package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
- package/neural-interface/public/shared/ui-tooltip.js +16 -0
- package/neural-interface/public/shared/ui-tutorial.js +5 -6
- package/neural-interface/public/shared/ui-worker-end.js +27 -8
- package/neural-interface/public/shared/worker-end.js +9 -4
- package/neural-interface/public/variant/2d/main.js +5 -0
- package/neural-interface/public/variant/3d/app.js +10 -0
- package/neural-interface/public/variant/3d/main.js +5 -1
- package/neural-interface/scripts/scratch-retention.mjs +20 -0
- package/neural-interface/server.js +477 -139
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/scripts/restore-data-home-from-backup.mjs +175 -8
- package/setup.js +18 -4
|
@@ -334,7 +334,7 @@ export function createSkillCreations({
|
|
|
334
334
|
await completeRun(d, runId);
|
|
335
335
|
throw new CreationError(422, `The draft has problems that stop it: ${read.problems.slice(0, 3).join(' ')}`, 'draft_invalid', { problems: read.problems.slice(0, 20).map((message) => ({ path: null, message })) });
|
|
336
336
|
}
|
|
337
|
-
try { d.sendTurn(runId, buildRepairPrompt({ errors: read.problems }), { origin: 'assistant' }); } catch (err) {
|
|
337
|
+
try { await d.sendTurn(runId, buildRepairPrompt({ errors: read.problems }), { origin: 'assistant' }); } catch (err) {
|
|
338
338
|
throw new CreationError(409, `The draft has problems and the worker could not be asked to fix them: ${err?.message || err}`, 'draft_invalid', { problems: read.problems.slice(0, 20).map((message) => ({ path: null, message })) });
|
|
339
339
|
}
|
|
340
340
|
update(job, { state: 'drafting' }, ['repair', `Asked the worker to fix ${read.problems.length} problem${read.problems.length === 1 ? '' : 's'}.`]);
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
// SQLite's PRAGMA integrity_check on each database copy of an upgrade snapshot, off the snapshot's main thread
|
|
2
2
|
// (backup-service.js checkSqliteIntegrity): the archive is written and read back meanwhile. workerData: { paths };
|
|
3
|
-
// posts [{ path, ok, lines, ms }] once, in the same order. A file that cannot be opened is not ok.
|
|
3
|
+
// posts progress before each file, then [{ path, ok, lines, ms }] once, in the same order. A file that cannot be opened is not ok.
|
|
4
4
|
import { parentPort, workerData } from 'node:worker_threads';
|
|
5
5
|
import { DatabaseSync } from 'node:sqlite';
|
|
6
|
+
import { statSync } from 'node:fs';
|
|
6
7
|
|
|
7
8
|
const results = [];
|
|
8
9
|
for (const path of workerData?.paths || []) {
|
|
9
10
|
const started = Date.now();
|
|
10
11
|
let db = null;
|
|
11
12
|
try {
|
|
13
|
+
parentPort.postMessage({ progress: true, inputBytes: statSync(path).size });
|
|
12
14
|
db = new DatabaseSync(path, { readOnly: true });
|
|
13
15
|
// The check `synabun restore-backup` runs (scripts/restore-data-home-from-backup.mjs); 20 findings are plenty to say why.
|
|
14
16
|
const lines = db.prepare('PRAGMA integrity_check(20)').all().map(row => String(Object.values(row)[0]));
|
|
@@ -21,8 +21,9 @@
|
|
|
21
21
|
// saved guide or the guide keeps that class of run out.
|
|
22
22
|
|
|
23
23
|
import { createHash, randomBytes } from 'node:crypto';
|
|
24
|
-
import { copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
24
|
+
import { copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
25
25
|
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
26
27
|
import { getDataHome } from '../../../lib/paths.js';
|
|
27
28
|
import { exportCss } from './export-css.js';
|
|
28
29
|
import { exportDtcgText } from './export-dtcg.js';
|
|
@@ -44,6 +45,25 @@ const PROPOSAL_FORBIDDEN_KEYS = Object.freeze(['schemaVersion', 'projectPath', '
|
|
|
44
45
|
const GENERATED_MARK = 'SynaBun Style Guide';
|
|
45
46
|
const DESIGN_FILE = 'DESIGN.md';
|
|
46
47
|
const DESIGN_BACKUP = 'DESIGN.before-synabun.md';
|
|
48
|
+
// The browser extension ships its own copy of SynaBun's tokens, byte for byte (browser-extension-contract.test.mjs).
|
|
49
|
+
const OWN_REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
|
|
50
|
+
const EXTENSION_TOKENS = 'browser-extension/tokens.css';
|
|
51
|
+
const EXTENSION_NAME = 'SynaBun Browser Bridge';
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Whether `root` is the SynaBun git checkout this code runs from: the same folder by device and inode, with a
|
|
55
|
+
* `.git`, the package name and the extension's manifest. A folder that only looks like it never qualifies, and
|
|
56
|
+
* neither does an installed copy (no `.git`).
|
|
57
|
+
*/
|
|
58
|
+
function isOwnCheckout(root, ownRoot) {
|
|
59
|
+
try {
|
|
60
|
+
const project = statSync(root);
|
|
61
|
+
const own = statSync(ownRoot);
|
|
62
|
+
if (project.dev !== own.dev || project.ino !== own.ino || !existsSync(join(root, '.git'))) return false;
|
|
63
|
+
if (JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')).name !== 'synabun') return false;
|
|
64
|
+
return JSON.parse(readFileSync(join(root, 'browser-extension', 'manifest.json'), 'utf8')).name === EXTENSION_NAME;
|
|
65
|
+
} catch { return false; }
|
|
66
|
+
}
|
|
47
67
|
|
|
48
68
|
export class StyleGuideError extends Error {
|
|
49
69
|
constructor(code, message, status = 400, extra = {}) {
|
|
@@ -127,9 +147,10 @@ export function renderFormat(config, format, { theme = null } = {}) {
|
|
|
127
147
|
|
|
128
148
|
/**
|
|
129
149
|
* The store over one data home. `projects()` returns the registered projects ([{ path, label }] or
|
|
130
|
-
* paths); without it the list is read from <dataDir>/claude-code-projects.json. `now()` is injectable
|
|
150
|
+
* paths); without it the list is read from <dataDir>/claude-code-projects.json. `now()` is injectable,
|
|
151
|
+
* and so is `ownRepoRoot`, the checkout whose extension copy of the tokens a save keeps in step.
|
|
131
152
|
*/
|
|
132
|
-
export function createStyleGuideStore({ dataHome = null, dataDir = null, projects = null, now = () => new Date(), log = () => {} } = {}) {
|
|
153
|
+
export function createStyleGuideStore({ dataHome = null, dataDir = null, projects = null, now = () => new Date(), log = () => {}, ownRepoRoot = OWN_REPO_ROOT } = {}) {
|
|
133
154
|
const dataFolder = resolve(dataDir || resolve(dataHome || getDataHome(), 'data'));
|
|
134
155
|
const dir = resolve(dataFolder, 'style-guides');
|
|
135
156
|
const assetsDir = resolve(dir, 'assets');
|
|
@@ -231,6 +252,24 @@ export function createStyleGuideStore({ dataHome = null, dataDir = null, project
|
|
|
231
252
|
}
|
|
232
253
|
}
|
|
233
254
|
|
|
255
|
+
/**
|
|
256
|
+
* In SynaBun's own checkout, bring the extension's tokens.css to the bytes of the file just written. It only
|
|
257
|
+
* replaces a regular file that is already there, and a failure is logged: the guide stays saved.
|
|
258
|
+
*/
|
|
259
|
+
function syncExtensionTokens(root, files) {
|
|
260
|
+
const css = files.find((file) => file.format === 'css');
|
|
261
|
+
if (!css || css.path !== resolve(root, STYLE_GUIDE_OUT_DIR, 'tokens.css') || !isOwnCheckout(root, ownRepoRoot)) return;
|
|
262
|
+
try {
|
|
263
|
+
const target = resolve(root, EXTENSION_TOKENS);
|
|
264
|
+
if (!containedPath(root, target, { noSymlinks: true })) throw new Error('its path goes through a link');
|
|
265
|
+
if (!lstatSync(target).isFile()) throw new Error('it is not a regular file');
|
|
266
|
+
const bytes = readFileSync(css.path);
|
|
267
|
+
if (!readFileSync(target).equals(bytes)) writeAtomic(target, bytes);
|
|
268
|
+
} catch (error) {
|
|
269
|
+
log('style-guide', `extension tokens copy failed: ${error.message}`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
234
273
|
/**
|
|
235
274
|
* Write the project's artifacts for `config`. Without `formats`: the enabled exports (and stale
|
|
236
275
|
* generated token files removed); with `formats`: the requested subset of enabled exports.
|
|
@@ -259,6 +298,7 @@ export function createStyleGuideStore({ dataHome = null, dataDir = null, project
|
|
|
259
298
|
}
|
|
260
299
|
if (!formats) dropStale(root, config, new Set(files.map((file) => file.path)));
|
|
261
300
|
mirrorLogos(root, config);
|
|
301
|
+
syncExtensionTokens(root, files);
|
|
262
302
|
return written;
|
|
263
303
|
}
|
|
264
304
|
|
|
@@ -3,6 +3,7 @@ import { randomBytes } from 'node:crypto';
|
|
|
3
3
|
import { basename, isAbsolute, join, relative, resolve } from 'node:path';
|
|
4
4
|
import { pipeline } from 'node:stream/promises';
|
|
5
5
|
import { isLockOnlyDataFile } from './backup-service.js';
|
|
6
|
+
import { isBackupEncryptionFile, isBackupLockFile } from './backup-groups.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Helpers for POST /api/system/restore{,/preview}.
|
|
@@ -41,6 +42,51 @@ export function removeRestoreUpload(upload) {
|
|
|
41
42
|
if (upload?.path && existsSync(upload.path)) rmSync(upload.path, { force: true });
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
// ── A stable code for each failure of the restore routes ──
|
|
46
|
+
// The routes keep answering the sentences they always did (the command line and older pages read them); the code is
|
|
47
|
+
// added beside it, and it is what a page shows, through its own strings (settings-backup-encryption.js RESTORE_KEYS).
|
|
48
|
+
// The ZIP reader and the checksum check are loaded fresh from disk by the backup worker threads, while the running
|
|
49
|
+
// server keeps its old copy, so they are not changed: what they throw is recognised here, by the start of the sentence.
|
|
50
|
+
const THROWN_FAILURES = [
|
|
51
|
+
[/^Invalid ZIP: /, 'RESTORE_ZIP_INVALID'],
|
|
52
|
+
[/^Unsupported ZIP: /, 'RESTORE_ZIP_UNSUPPORTED'],
|
|
53
|
+
[/^Invalid backup: checksum mismatch for /, 'RESTORE_CHECKSUM_MISMATCH'],
|
|
54
|
+
[/^Invalid backup: .+ is unreadable \(/s, 'RESTORE_ENTRY_UNREADABLE'],
|
|
55
|
+
[/^Invalid backup: .+ is missing$/s, 'RESTORE_ENTRY_MISSING'],
|
|
56
|
+
[/ is too large to read into memory$/, 'RESTORE_MANIFEST_UNREADABLE'],
|
|
57
|
+
];
|
|
58
|
+
// The sentences of `results.errors`: a restore that answered 200 and could not do all of it.
|
|
59
|
+
const PARTIAL_FAILURES = [
|
|
60
|
+
[/^Failed to restore database: /, 'RESTORE_DB_FAILED'],
|
|
61
|
+
[/^This backup contains Qdrant snapshots /, 'RESTORE_QDRANT_FORMAT'],
|
|
62
|
+
[/^Backup encryption could not be kept: /, 'RESTORE_KEY_NOT_KEPT'],
|
|
63
|
+
[/^MCP server auto-build failed: /, 'RESTORE_MCP_BUILD_FAILED'],
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
/** Every code these routes add. The page has words for each (tests/settings-backup-encryption.test.mjs). */
|
|
67
|
+
export const RESTORE_FAILURE_CODES = Object.freeze([...new Set([
|
|
68
|
+
'RESTORE_EMPTY_UPLOAD', 'RESTORE_MANIFEST_MISSING', 'RESTORE_MANIFEST_UNREADABLE', 'RESTORE_UNSUPPORTED_VERSION', 'RESTORE_UNSAFE_PATH',
|
|
69
|
+
'RESTORE_WRITE_FAILED', 'RESTORE_FAILED', ...THROWN_FAILURES.map(([, code]) => code), ...PARTIAL_FAILURES.map(([, code]) => code),
|
|
70
|
+
])]);
|
|
71
|
+
|
|
72
|
+
/** The `code` of a thrown failure: the one it carries (a system error's, the group check's), else what its sentence is. */
|
|
73
|
+
export function restoreFailureCode(error) {
|
|
74
|
+
if (error?.code) return error.code;
|
|
75
|
+
if (error instanceof SyntaxError) return 'RESTORE_MANIFEST_UNREADABLE'; // the only JSON a restore parses before it writes
|
|
76
|
+
const message = String(error?.message ?? '');
|
|
77
|
+
return THROWN_FAILURES.find(([pattern]) => pattern.test(message))?.[1] || 'RESTORE_FAILED';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** What a failed restore adds to its answer. Once it began writing, the answer says so: some files may be replaced. */
|
|
81
|
+
export function restoreFailureFields(error, res) {
|
|
82
|
+
return res?.locals?.restoreWriting ? { code: 'RESTORE_WRITE_FAILED', partial: true } : { code: restoreFailureCode(error) };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The code of one sentence of `results.errors`. */
|
|
86
|
+
export function restoreWarningCode(sentence) {
|
|
87
|
+
return PARTIAL_FAILURES.find(([pattern]) => pattern.test(String(sentence)))?.[1] || 'RESTORE_FAILED';
|
|
88
|
+
}
|
|
89
|
+
|
|
44
90
|
/**
|
|
45
91
|
* Map one archive-relative path (`data/x.json`, `skins/y/skin.css`, …) to the
|
|
46
92
|
* file it restores. Returns null for paths the mode does not restore and
|
|
@@ -74,6 +120,10 @@ export function restoreTargetFor(rel, roots) {
|
|
|
74
120
|
}
|
|
75
121
|
// By the name the write would land on, so `data/x/../rulesets-lock.db` and another letter case count too.
|
|
76
122
|
if (dataRoots.has(prefix) && isLockOnlyDataFile(basename(target))) return null;
|
|
123
|
+
// The hooks' state lock too (backup-groups.js): archives from before 2026-11-21 hold data/hook-state-lock.sqlite.
|
|
124
|
+
if (dataRoots.has(prefix) && isBackupLockFile(basename(target))) return null;
|
|
125
|
+
// The backup-encryption key file is this installation's own: no archive replaces it (backup-groups.js).
|
|
126
|
+
if (dataRoots.has(prefix) && isBackupEncryptionFile(basename(target))) return null;
|
|
77
127
|
return { target };
|
|
78
128
|
}
|
|
79
129
|
return null;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// callers:
|
|
7
7
|
//
|
|
8
8
|
// /api/assistant/teams/* the Assistant's `agent_team` tool (and the owner's page): plan, start, status,
|
|
9
|
-
// integrate, land, discard, list. Behind the Assistant API's orchestration guard:
|
|
9
|
+
// assign, set_test_command, integrate, land, cleanup, discard, list. Behind the Assistant API's orchestration guard:
|
|
10
10
|
// a brain by its launch credential, or the owner's page. Never a worker.
|
|
11
11
|
// /api/assistant/team/* a worker's `team` tool: context, post, read, wait, ack, claims, request. Only a
|
|
12
12
|
// run that proves its pin (its terminal token) AND works a team slice now. The
|
|
@@ -129,6 +129,15 @@ export function registerAssistantTeamRoutes(router, { scheduler, orchestrationGu
|
|
|
129
129
|
const body = req.body || {};
|
|
130
130
|
send(res, await teams.integrate(req.params.id, { sliceId: body.sliceId || body.slice_id || body.slice || null }));
|
|
131
131
|
}));
|
|
132
|
+
router.post('/teams/:id/assign', orchestrationGuard, run(async (req, res, teams) => {
|
|
133
|
+
if (refuseOthers(req, res, teams, req.params.id) || refusePlanning(req, res, 'assign paths to a slice')) return;
|
|
134
|
+
const body = req.body || {};
|
|
135
|
+
send(res, await teams.assign(req.params.id, { sliceId: body.sliceId ?? body.slice_id, paths: body.paths }));
|
|
136
|
+
}));
|
|
137
|
+
router.post('/teams/:id/set_test_command', orchestrationGuard, run(async (req, res, teams) => {
|
|
138
|
+
if (refuseOthers(req, res, teams, req.params.id) || refusePlanning(req, res, 'change the team test command')) return;
|
|
139
|
+
send(res, await teams.setTestCommand(req.params.id, req.body?.testCommand ?? req.body?.test_command));
|
|
140
|
+
}));
|
|
132
141
|
router.post('/teams/:id/land', orchestrationGuard, run(async (req, res, teams) => {
|
|
133
142
|
if (refuseOthers(req, res, teams, req.params.id)) return;
|
|
134
143
|
if (refusePlanning(req, res, 'land the team')) return;
|
|
@@ -178,11 +187,11 @@ export function registerAssistantTeamRoutes(router, { scheduler, orchestrationGu
|
|
|
178
187
|
}));
|
|
179
188
|
router.post('/team/post', worker(async (req, res, teams, who) => {
|
|
180
189
|
const body = req.body || {};
|
|
181
|
-
send(res, teams.post(who.runId, { to: body.to, kind: body.kind, text: body.text, path: body.path || null, id: body.id || body.idempotency_key || null }));
|
|
190
|
+
send(res, await teams.post(who.runId, { to: body.to, kind: body.kind, text: body.text, path: body.path || null, id: body.id || body.idempotency_key || null }));
|
|
182
191
|
}));
|
|
183
192
|
router.post('/team/read', worker(async (req, res, teams, who) => {
|
|
184
193
|
const body = req.body || {};
|
|
185
|
-
send(res, teams.read(who.runId, { afterSeq: body.afterSeq ?? body.after_seq ?? null, kinds: body.kinds || null, limit: body.limit ?? null }));
|
|
194
|
+
send(res, await teams.read(who.runId, { afterSeq: body.afterSeq ?? body.after_seq ?? null, kinds: body.kinds || null, limit: body.limit ?? null }));
|
|
186
195
|
}));
|
|
187
196
|
router.post('/team/wait', worker(async (req, res, teams, who) => {
|
|
188
197
|
const body = req.body || {};
|
|
@@ -190,14 +199,14 @@ export function registerAssistantTeamRoutes(router, { scheduler, orchestrationGu
|
|
|
190
199
|
}));
|
|
191
200
|
router.post('/team/ack', worker(async (req, res, teams, who) => {
|
|
192
201
|
const body = req.body || {};
|
|
193
|
-
send(res, teams.ack(who.runId, { ids: body.ids || body.eventIds || null, throughSeq: body.throughSeq ?? body.through_seq ?? null }));
|
|
202
|
+
send(res, await teams.ack(who.runId, { ids: body.ids || body.eventIds || null, throughSeq: body.throughSeq ?? body.through_seq ?? null }));
|
|
194
203
|
}));
|
|
195
204
|
router.post('/team/claims', worker(async (req, res, teams, who) => {
|
|
196
|
-
send(res, teams.claims(who.runId, { path: (req.body || {}).path ?? null }));
|
|
205
|
+
send(res, await teams.claims(who.runId, { path: (req.body || {}).path ?? null }));
|
|
197
206
|
}));
|
|
198
207
|
router.post('/team/request', worker(async (req, res, teams, who) => {
|
|
199
208
|
const body = req.body || {};
|
|
200
|
-
send(res, teams.request(who.runId, { path: body.path, text: body.text }));
|
|
209
|
+
send(res, await teams.request(who.runId, { path: body.path, text: body.text }));
|
|
201
210
|
}));
|
|
202
211
|
}
|
|
203
212
|
|
|
@@ -33,7 +33,7 @@ import { runGitReadSync } from '../git-read.js';
|
|
|
33
33
|
import { realPlace, registerTeamSlice, unregisterTeamSlice } from '../worker-confinement.js';
|
|
34
34
|
import {
|
|
35
35
|
RESERVED_PATH_ROOTS, claimablePaths, globsOverlap, integrationBranchName, isLockfilePath, isTeamSlug, normalizeRelPath, pathOwner,
|
|
36
|
-
branchName, worktreePath,
|
|
36
|
+
TEAM_LIMITS, branchName, normalizeOwnedPath, validateTeamPlan, worktreePath,
|
|
37
37
|
} from './schema.js';
|
|
38
38
|
import { parseNameStatus, parseStatus } from './git.js';
|
|
39
39
|
import { SETTLED_SLICE_STATES, TERMINAL_TEAM_STATES, planSlice, refuse, sliceState } from './state.js';
|
|
@@ -71,15 +71,18 @@ function gitIgnores(worktree, relPath) {
|
|
|
71
71
|
* @param {(tag: string, detail: any) => void} [deps.log]
|
|
72
72
|
*/
|
|
73
73
|
export function createTeamClaims({ store, state, git = null, isIgnored = gitIgnores, registry = { register: registerTeamSlice, unregister: unregisterTeamSlice }, log = () => {} } = {}) {
|
|
74
|
-
const plans = new Map(); //
|
|
74
|
+
const plans = new Map(); // latest committed ownership for the synchronous worker guard
|
|
75
75
|
const contexts = new Map(); // `${teamId}/${sliceId}` → the context registered with the worker guard
|
|
76
76
|
|
|
77
77
|
function planOf(teamId) {
|
|
78
|
+
return plans.get(teamId) || null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function loadPlan(teamId) {
|
|
78
82
|
if (plans.has(teamId)) return plans.get(teamId);
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
return record.plan;
|
|
83
|
+
const plan = isTeamSlug(teamId) ? (await state.record(teamId))?.plan : null;
|
|
84
|
+
if (plan) plans.set(teamId, plan);
|
|
85
|
+
return plan;
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
/** Does the slice own something inside this folder? (`mkdir -p src` on the way to `src/api/x.js`.) */
|
|
@@ -104,7 +107,7 @@ export function createTeamClaims({ store, state, git = null, isIgnored = gitIgno
|
|
|
104
107
|
if (owner === sliceId) {
|
|
105
108
|
if (isLockfilePath(path)) return { allow: true, owner, relPath: path, code: 'lockfile_owner', beneath };
|
|
106
109
|
// The claim is what says the slice is at work on it: a slice that finished gave its claims back.
|
|
107
|
-
const held = store.
|
|
110
|
+
const held = store.holdsClaim(teamId, sliceId, path);
|
|
108
111
|
return held ? { allow: true, owner, relPath: path, code: 'owned', beneath } : { allow: false, owner, relPath: path, code: 'claim_released', beneath };
|
|
109
112
|
}
|
|
110
113
|
if (plan.readOnly) return { allow: false, owner: null, relPath: path, code: 'unowned', beneath: false };
|
|
@@ -171,15 +174,15 @@ export function createTeamClaims({ store, state, git = null, isIgnored = gitIgno
|
|
|
171
174
|
return made;
|
|
172
175
|
}
|
|
173
176
|
|
|
174
|
-
function claimSlice(plan, sliceId, runId) {
|
|
177
|
+
async function claimSlice(plan, sliceId, runId) {
|
|
175
178
|
const globs = claimablePaths(plan, sliceId);
|
|
176
179
|
if (!globs.length) return { ok: true, claims: [] }; // a slice that owns lockfiles only: owned by rule
|
|
177
|
-
return store.claim({ teamId: plan.teamId, sliceId, runId: runId || null, globs });
|
|
180
|
+
return await store.claim({ teamId: plan.teamId, sliceId, runId: runId || null, globs });
|
|
178
181
|
}
|
|
179
182
|
|
|
180
|
-
function announceConflict(teamId, sliceId, conflicts) {
|
|
183
|
+
async function announceConflict(teamId, sliceId, conflicts) {
|
|
181
184
|
try {
|
|
182
|
-
store.append({
|
|
185
|
+
await store.append({
|
|
183
186
|
teamId, kind: EVENT_KINDS.CLAIM_CONFLICT,
|
|
184
187
|
payload: { teamId, sliceId, conflicts: conflicts.map((each) => ({ glob: each.glob, heldBy: each.heldBy?.sliceId || null })) },
|
|
185
188
|
});
|
|
@@ -192,17 +195,17 @@ export function createTeamClaims({ store, state, git = null, isIgnored = gitIgno
|
|
|
192
195
|
* @param {string} teamId
|
|
193
196
|
* @param {{ only?: (sliceId: string) => boolean }} [options] which slices (default: every slice)
|
|
194
197
|
*/
|
|
195
|
-
function start(teamId, { only = null } = {}) {
|
|
196
|
-
const plan =
|
|
198
|
+
async function start(teamId, { only = null } = {}) {
|
|
199
|
+
const plan = await loadPlan(teamId);
|
|
197
200
|
if (!plan) return refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is recorded.`);
|
|
198
201
|
const taken = [];
|
|
199
202
|
const claims = [];
|
|
200
203
|
for (const slice of plan.slices) {
|
|
201
204
|
if (only && !only(slice.id)) continue;
|
|
202
|
-
const result = claimSlice(plan, slice.id, null);
|
|
205
|
+
const result = await claimSlice(plan, slice.id, null);
|
|
203
206
|
if (!result.ok) {
|
|
204
|
-
for (const sliceId of taken) store.release({ teamId, sliceId });
|
|
205
|
-
announceConflict(teamId, slice.id, result.conflicts);
|
|
207
|
+
for (const sliceId of taken) await store.release({ teamId, sliceId });
|
|
208
|
+
await announceConflict(teamId, slice.id, result.conflicts);
|
|
206
209
|
return refuse('CLAIM_CONFLICT', `Slice "${slice.id}" could not take its files: ${result.conflicts.map((each) => `${each.glob} is held by slice "${each.heldBy.sliceId}"`).join('; ')}.`, { sliceId: slice.id, conflicts: result.conflicts });
|
|
207
210
|
}
|
|
208
211
|
taken.push(slice.id);
|
|
@@ -213,29 +216,62 @@ export function createTeamClaims({ store, state, git = null, isIgnored = gitIgno
|
|
|
213
216
|
}
|
|
214
217
|
|
|
215
218
|
/** A slice goes to a run: its claims are (re)taken in that run's name and its context registered. */
|
|
216
|
-
function assign(teamId, sliceId, runId = null) {
|
|
217
|
-
const plan =
|
|
219
|
+
async function assign(teamId, sliceId, runId = null) {
|
|
220
|
+
const plan = await loadPlan(teamId);
|
|
218
221
|
if (!plan || !plan.slices.some((slice) => slice.id === sliceId)) return refuse('SLICE_NOT_FOUND', `Team "${teamId}" has no slice "${sliceId}".`);
|
|
219
|
-
const result = claimSlice(plan, sliceId, runId);
|
|
222
|
+
const result = await claimSlice(plan, sliceId, runId);
|
|
220
223
|
if (!result.ok) {
|
|
221
|
-
announceConflict(teamId, sliceId, result.conflicts);
|
|
224
|
+
await announceConflict(teamId, sliceId, result.conflicts);
|
|
222
225
|
return refuse('CLAIM_CONFLICT', `Slice "${sliceId}" could not take its files: ${result.conflicts.map((each) => `${each.glob} is held by slice "${each.heldBy.sliceId}"`).join('; ')}.`, { sliceId, conflicts: result.conflicts });
|
|
223
226
|
}
|
|
224
227
|
register(teamId, sliceId);
|
|
225
228
|
return { ok: true, claims: result.claims };
|
|
226
229
|
}
|
|
227
230
|
|
|
231
|
+
/** Extend one slice's ownership under the scheduler's team and slice reservations. */
|
|
232
|
+
async function assignPaths(record, sliceId, paths) {
|
|
233
|
+
const own = planSlice(record, sliceId);
|
|
234
|
+
if (!own) return refuse('SLICE_NOT_FOUND', `Team "${record.teamId}" has no such slice.`);
|
|
235
|
+
const current = sliceState(record, sliceId);
|
|
236
|
+
if (current === 'integrated') return refuse('SLICE_ALREADY_INTEGRATED', `Slice "${sliceId}" has already joined.`);
|
|
237
|
+
const holdsClaims = CLAIMING_SLICE_STATES.has(current) || current === 'rejected';
|
|
238
|
+
if (!holdsClaims && !['conflict', 'tests-failed'].includes(current)) {
|
|
239
|
+
return refuse('SLICE_NOT_EDITABLE', `Slice "${sliceId}" is ${current}. Assign paths to a working, waiting or retryable slice.`);
|
|
240
|
+
}
|
|
241
|
+
if (!Array.isArray(paths) || !paths.length || paths.length > TEAM_LIMITS.ownedPaths || paths.some(path => !normalizeOwnedPath(path))) {
|
|
242
|
+
return refuse('INVALID_PLAN', `Give 1 to ${TEAM_LIMITS.ownedPaths} nonempty project-relative paths.`);
|
|
243
|
+
}
|
|
244
|
+
const requested = [...new Set(paths.map(normalizeOwnedPath))];
|
|
245
|
+
const slices = record.plan.slices.map(slice => slice === own ? { ...slice, ownedPaths: [...own.ownedPaths, ...requested] } : slice);
|
|
246
|
+
const checked = validateTeamPlan({ ...record.plan, slices }, { maxSlices: slices.length });
|
|
247
|
+
if (!checked.ok) return refuse('INVALID_PLAN', checked.errors[0].message, { errors: checked.errors });
|
|
248
|
+
const plan = checked.value;
|
|
249
|
+
const ownedPaths = plan.slices.find(slice => slice.id === sliceId).ownedPaths;
|
|
250
|
+
if (ownedPaths.length !== own.ownedPaths.length) {
|
|
251
|
+
const globs = holdsClaims ? claimablePaths(plan, sliceId) : [];
|
|
252
|
+
try {
|
|
253
|
+
await state.writeSlice(record.teamId, sliceId, current, { ownedPaths }, record.slices[sliceId].runId, globs);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
if (error.code === 'CLAIM_CONFLICT') return refuse(error.code, error.message, { conflicts: error.conflicts });
|
|
256
|
+
throw error;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
plans.set(record.teamId, plan);
|
|
260
|
+
register(record.teamId, sliceId);
|
|
261
|
+
return { ok: true, ownedPaths, requested };
|
|
262
|
+
}
|
|
263
|
+
|
|
228
264
|
/**
|
|
229
265
|
* Give claims back: a slice's when it finishes, the whole team's with no `sliceId`. The slice's context stays
|
|
230
266
|
* registered with the worker guard (a worker still running there is refused: its claims are gone) until `end`.
|
|
231
267
|
*/
|
|
232
|
-
function release(teamId, sliceId = null) {
|
|
233
|
-
return store.release(sliceId ? { teamId, sliceId } : { teamId });
|
|
268
|
+
async function release(teamId, sliceId = null) {
|
|
269
|
+
return await store.release(sliceId ? { teamId, sliceId } : { teamId });
|
|
234
270
|
}
|
|
235
271
|
|
|
236
272
|
/** The team is over (landed, discarded, removed): every claim back, every context off the worker guard. */
|
|
237
|
-
function end(teamId) {
|
|
238
|
-
const released = isTeamSlug(teamId) ? store.release({ teamId }).released : 0;
|
|
273
|
+
async function end(teamId) {
|
|
274
|
+
const released = isTeamSlug(teamId) ? (await store.release({ teamId })).released : 0;
|
|
239
275
|
for (const [key, made] of [...contexts]) {
|
|
240
276
|
if (!key.startsWith(`${teamId}/`)) continue;
|
|
241
277
|
try { registry.unregister(made); } catch { /* already gone */ }
|
|
@@ -250,12 +286,12 @@ export function createTeamClaims({ store, state, git = null, isIgnored = gitIgno
|
|
|
250
286
|
* is registered with the worker guard again (the registry is in memory). Claims of teams that are over are given
|
|
251
287
|
* back.
|
|
252
288
|
*/
|
|
253
|
-
function restore() {
|
|
289
|
+
async function restore() {
|
|
254
290
|
const out = [];
|
|
255
|
-
for (const entry of state.teams()) {
|
|
256
|
-
const record = state.record(entry.teamId);
|
|
291
|
+
for (const entry of await state.teams()) {
|
|
292
|
+
const record = await state.record(entry.teamId);
|
|
257
293
|
if (!record) continue;
|
|
258
|
-
if (TERMINAL_TEAM_STATES.includes(record.state) || record.removed) { out.push({ teamId: record.teamId, released: end(record.teamId).released }); continue; }
|
|
294
|
+
if (TERMINAL_TEAM_STATES.includes(record.state) || record.removed) { out.push({ teamId: record.teamId, released: (await end(record.teamId)).released }); continue; }
|
|
259
295
|
plans.set(record.teamId, record.plan);
|
|
260
296
|
const claimed = [];
|
|
261
297
|
const conflicts = [];
|
|
@@ -263,7 +299,7 @@ export function createTeamClaims({ store, state, git = null, isIgnored = gitIgno
|
|
|
263
299
|
const current = sliceState(record, slice.id);
|
|
264
300
|
if (!SETTLED_SLICE_STATES.includes(current)) register(record.teamId, slice.id);
|
|
265
301
|
if (!CLAIMING_SLICE_STATES.has(current)) continue;
|
|
266
|
-
const result = claimSlice(record.plan, slice.id, record.slices[slice.id]?.runId || null);
|
|
302
|
+
const result = await claimSlice(record.plan, slice.id, record.slices[slice.id]?.runId || null);
|
|
267
303
|
if (result.ok) claimed.push(slice.id); else conflicts.push({ sliceId: slice.id, conflicts: result.conflicts });
|
|
268
304
|
}
|
|
269
305
|
out.push({ teamId: record.teamId, claimed, conflicts });
|
|
@@ -283,7 +319,7 @@ export function createTeamClaims({ store, state, git = null, isIgnored = gitIgno
|
|
|
283
319
|
*/
|
|
284
320
|
async function verifyOwnership(teamId, sliceId) {
|
|
285
321
|
if (typeof git !== 'function') throw new Error('verifyOwnership needs a git runner.');
|
|
286
|
-
const record = isTeamSlug(teamId) ? state.record(teamId) : null;
|
|
322
|
+
const record = isTeamSlug(teamId) ? await state.record(teamId) : null;
|
|
287
323
|
if (!record) return refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is recorded.`);
|
|
288
324
|
const slice = planSlice(record, sliceId);
|
|
289
325
|
if (!slice) return refuse('SLICE_NOT_FOUND', `Team "${teamId}" has no slice "${sliceId}".`);
|
|
@@ -311,5 +347,5 @@ export function createTeamClaims({ store, state, git = null, isIgnored = gitIgno
|
|
|
311
347
|
return { ok: violations.length === 0, head, reference, changed, violations, uncommitted, stray, warnings };
|
|
312
348
|
}
|
|
313
349
|
|
|
314
|
-
return { start, assign, release, end, restore, checkWrite, checkRelative, context, verifyOwnership, planOf };
|
|
350
|
+
return { start, assign, assignPaths, release, end, restore, checkWrite, checkRelative, context, verifyOwnership, planOf };
|
|
315
351
|
}
|
|
@@ -54,11 +54,11 @@ export function createTeams({ store, git = createGitRunner(), runTests = createT
|
|
|
54
54
|
async function create(plan, options = {}) {
|
|
55
55
|
const made = await worktrees.create(plan, options);
|
|
56
56
|
if (!made.ok) return made;
|
|
57
|
-
const claimed = claims.start(made.team.teamId);
|
|
57
|
+
const claimed = await claims.start(made.team.teamId);
|
|
58
58
|
if (!claimed.ok) {
|
|
59
59
|
// A valid plan's claims never clash; should the store say otherwise, the team does not start.
|
|
60
60
|
await worktrees.remove(made.team.teamId, { discard: true, force: true });
|
|
61
|
-
claims.end(made.team.teamId);
|
|
61
|
+
await claims.end(made.team.teamId);
|
|
62
62
|
return claimed;
|
|
63
63
|
}
|
|
64
64
|
return { ...made, claims: claimed.claims };
|
|
@@ -68,7 +68,7 @@ export function createTeams({ store, git = createGitRunner(), runTests = createT
|
|
|
68
68
|
async function startSlice(teamId, sliceId, options = {}) {
|
|
69
69
|
const started = await worktrees.startSlice(teamId, sliceId, options);
|
|
70
70
|
if (!started.ok) return started;
|
|
71
|
-
const claimed = claims.assign(teamId, sliceId, options.runId || null);
|
|
71
|
+
const claimed = await claims.assign(teamId, sliceId, options.runId || null);
|
|
72
72
|
if (!claimed.ok) return claimed;
|
|
73
73
|
return { ...started, context: claims.context(teamId, sliceId) };
|
|
74
74
|
}
|
|
@@ -76,14 +76,14 @@ export function createTeams({ store, git = createGitRunner(), runTests = createT
|
|
|
76
76
|
/** Remove a team's worktrees and branches (after a landing, or `discard: true`); its claims go with it. */
|
|
77
77
|
async function remove(teamId, options = {}) {
|
|
78
78
|
const out = await worktrees.remove(teamId, options);
|
|
79
|
-
if (out.ok) claims.end(teamId);
|
|
79
|
+
if (out.ok) await claims.end(teamId);
|
|
80
80
|
return out;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
return {
|
|
84
84
|
create,
|
|
85
85
|
get: worktrees.get,
|
|
86
|
-
plan: (teamId) => worktrees.get(teamId)?.plan || null,
|
|
86
|
+
plan: async (teamId) => (await worktrees.get(teamId))?.plan || null,
|
|
87
87
|
list: worktrees.list,
|
|
88
88
|
inspect: worktrees.inspect,
|
|
89
89
|
startSlice,
|
|
@@ -91,8 +91,8 @@ export function createTeams({ store, git = createGitRunner(), runTests = createT
|
|
|
91
91
|
finishReadOnlySlice: async (teamId, sliceId, options) => {
|
|
92
92
|
const out = await worktrees.finishReadOnlySlice(teamId, sliceId, options);
|
|
93
93
|
if (out.ok) {
|
|
94
|
-
claims.release(teamId, sliceId);
|
|
95
|
-
if (worktrees.get(teamId)?.state === 'completed') claims.end(teamId);
|
|
94
|
+
await claims.release(teamId, sliceId);
|
|
95
|
+
if ((await worktrees.get(teamId))?.state === 'completed') await claims.end(teamId);
|
|
96
96
|
}
|
|
97
97
|
return out;
|
|
98
98
|
},
|