@voybio/ace-swarm 0.1.0
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 +109 -0
- package/LICENSE +186 -0
- package/README.md +229 -0
- package/assets/.agents/ACE/ACE-Init/AGENTS.md +210 -0
- package/assets/.agents/ACE/ACE-Init/instructions.md +118 -0
- package/assets/.agents/ACE/ACE_coders/AGENTS.md +154 -0
- package/assets/.agents/ACE/ACE_coders/INSTRUCTIONS.md +216 -0
- package/assets/.agents/ACE/AGENT_REGISTRY.md +70 -0
- package/assets/.agents/ACE/AGENT_REGISTRY_7.md +9 -0
- package/assets/.agents/ACE/DIRECTIVE_KERNEL.md +234 -0
- package/assets/.agents/ACE/UI/AGENTS.md +115 -0
- package/assets/.agents/ACE/UI/instructions.md +178 -0
- package/assets/.agents/ACE/VOS/ACE_VOS_MISSING_INFO_MATRIX.md +42 -0
- package/assets/.agents/ACE/VOS/AGENTS.md +72 -0
- package/assets/.agents/ACE/VOS/instructions.md +211 -0
- package/assets/.agents/ACE/agent-astgrep/AGENTS.md +123 -0
- package/assets/.agents/ACE/agent-astgrep/instructions.md +91 -0
- package/assets/.agents/ACE/agent-builder/AGENTS.md +172 -0
- package/assets/.agents/ACE/agent-builder/instructions.md +137 -0
- package/assets/.agents/ACE/agent-docs/AGENTS.md +159 -0
- package/assets/.agents/ACE/agent-docs/instructions.md +133 -0
- package/assets/.agents/ACE/agent-eval/AGENTS.md +46 -0
- package/assets/.agents/ACE/agent-eval/instructions.md +56 -0
- package/assets/.agents/ACE/agent-memory/AGENTS.md +49 -0
- package/assets/.agents/ACE/agent-memory/instructions.md +50 -0
- package/assets/.agents/ACE/agent-observability/AGENTS.md +46 -0
- package/assets/.agents/ACE/agent-observability/instructions.md +50 -0
- package/assets/.agents/ACE/agent-ops/AGENTS.md +201 -0
- package/assets/.agents/ACE/agent-ops/instructions.md +136 -0
- package/assets/.agents/ACE/agent-qa/AGENTS.md +189 -0
- package/assets/.agents/ACE/agent-qa/instructions.md +121 -0
- package/assets/.agents/ACE/agent-release/AGENTS.md +48 -0
- package/assets/.agents/ACE/agent-release/instructions.md +49 -0
- package/assets/.agents/ACE/agent-research/AGENTS.md +160 -0
- package/assets/.agents/ACE/agent-research/instructions.md +118 -0
- package/assets/.agents/ACE/agent-security/AGENTS.md +48 -0
- package/assets/.agents/ACE/agent-security/instructions.md +50 -0
- package/assets/.agents/ACE/agent-skeptic/AGENTS.md +178 -0
- package/assets/.agents/ACE/agent-skeptic/instructions.md +196 -0
- package/assets/.agents/ACE/agent-spec/AGENTS.md +169 -0
- package/assets/.agents/ACE/agent-spec/instructions.md +116 -0
- package/assets/.agents/ACE/orchestrator/AGENTS.md +365 -0
- package/assets/.agents/ACE/orchestrator/instructions.md +231 -0
- package/assets/.agents/skills/ace-orchestrator/SKILL.md +63 -0
- package/assets/.agents/skills/ace-orchestrator/references/engineering-bootstrap-playbook.md +360 -0
- package/assets/.agents/skills/astgrep-index/SKILL.md +58 -0
- package/assets/.agents/skills/codemunch/SKILL.md +65 -0
- package/assets/.agents/skills/codemunch/references/ast-driven-protocol.md +543 -0
- package/assets/.agents/skills/codesnipe/SKILL.md +64 -0
- package/assets/.agents/skills/codesnipe/references/dual-codebase-playbook.md +671 -0
- package/assets/.agents/skills/eval-harness/SKILL.md +203 -0
- package/assets/.agents/skills/handoff-lint/SKILL.md +164 -0
- package/assets/.agents/skills/incident-commander/SKILL.md +174 -0
- package/assets/.agents/skills/landing-review-watcher/SKILL.md +68 -0
- package/assets/.agents/skills/memory-curator/SKILL.md +179 -0
- package/assets/.agents/skills/problem-triage/SKILL.md +57 -0
- package/assets/.agents/skills/problem-triage/agents/openai.yaml +3 -0
- package/assets/.agents/skills/release-sentry/SKILL.md +189 -0
- package/assets/.agents/skills/risk-quant/SKILL.md +190 -0
- package/assets/.agents/skills/schema-forge/SKILL.md +174 -0
- package/assets/.agents/skills/skill-auditor/SKILL.md +52 -0
- package/assets/.agents/skills/state-auditor/SKILL.md +182 -0
- package/assets/.github/hooks/ace-copilot.json +68 -0
- package/assets/agent-state/ACE_WORKFLOW.md +131 -0
- package/assets/agent-state/ARTIFACT_MANIFEST.json +5 -0
- package/assets/agent-state/AST_GREP_COMMANDS.md +121 -0
- package/assets/agent-state/AST_GREP_INDEX.json +13 -0
- package/assets/agent-state/AST_GREP_INDEX.md +15 -0
- package/assets/agent-state/DECISIONS.md +7 -0
- package/assets/agent-state/EVIDENCE_LOG.md +7 -0
- package/assets/agent-state/HANDOFF.json +24 -0
- package/assets/agent-state/INTERFACE_REGISTRY.md +75 -0
- package/assets/agent-state/MODULES/gates/gate-autonomy.json +7 -0
- package/assets/agent-state/MODULES/gates/gate-completeness.json +7 -0
- package/assets/agent-state/MODULES/gates/gate-correctness.json +7 -0
- package/assets/agent-state/MODULES/gates/gate-evaluation.json +7 -0
- package/assets/agent-state/MODULES/gates/gate-operability.json +7 -0
- package/assets/agent-state/MODULES/gates/gate-security.json +7 -0
- package/assets/agent-state/MODULES/gates/gate-typescript-public-surface.json +7 -0
- package/assets/agent-state/MODULES/registry.json +41 -0
- package/assets/agent-state/MODULES/roles/capability-astgrep.json +49 -0
- package/assets/agent-state/MODULES/roles/capability-build.json +39 -0
- package/assets/agent-state/MODULES/roles/capability-docs.json +38 -0
- package/assets/agent-state/MODULES/roles/capability-eval.json +20 -0
- package/assets/agent-state/MODULES/roles/capability-memory.json +20 -0
- package/assets/agent-state/MODULES/roles/capability-observability.json +20 -0
- package/assets/agent-state/MODULES/roles/capability-ops.json +45 -0
- package/assets/agent-state/MODULES/roles/capability-qa.json +40 -0
- package/assets/agent-state/MODULES/roles/capability-release.json +21 -0
- package/assets/agent-state/MODULES/roles/capability-research.json +44 -0
- package/assets/agent-state/MODULES/roles/capability-security.json +21 -0
- package/assets/agent-state/MODULES/roles/capability-skeptic.json +48 -0
- package/assets/agent-state/MODULES/roles/capability-spec.json +42 -0
- package/assets/agent-state/MODULES/schemas/ACE_RUNTIME_PROFILE.schema.json +289 -0
- package/assets/agent-state/MODULES/schemas/ARTIFACT_MANIFEST.schema.json +185 -0
- package/assets/agent-state/MODULES/schemas/HANDOFF.agent-state.schema.json +124 -0
- package/assets/agent-state/MODULES/schemas/HANDOFF.schema.json +55 -0
- package/assets/agent-state/MODULES/schemas/RUNTIME_EXECUTOR_SESSION_REGISTRY.schema.json +290 -0
- package/assets/agent-state/MODULES/schemas/RUNTIME_TOOL_SPEC_REGISTRY.schema.json +144 -0
- package/assets/agent-state/MODULES/schemas/STATUS_EVENT.schema.json +84 -0
- package/assets/agent-state/MODULES/schemas/SWARM_HANDOFF.schema.json +138 -0
- package/assets/agent-state/MODULES/schemas/TRACKER_SNAPSHOT.schema.json +134 -0
- package/assets/agent-state/MODULES/schemas/VERICIFY_BRIDGE_SNAPSHOT.schema.json +157 -0
- package/assets/agent-state/MODULES/schemas/VERICIFY_PROCESS_POST_LOG.schema.json +93 -0
- package/assets/agent-state/MODULES/schemas/WORKSPACE_SESSION_REGISTRY.schema.json +133 -0
- package/assets/agent-state/PROVENANCE_LOG.md +28 -0
- package/assets/agent-state/QUALITY_GATES.md +15 -0
- package/assets/agent-state/RISKS.md +8 -0
- package/assets/agent-state/SCOPE.md +20 -0
- package/assets/agent-state/SKILL_CATALOG.md +48 -0
- package/assets/agent-state/STATUS.md +8 -0
- package/assets/agent-state/STATUS_EVENTS.ndjson +1 -0
- package/assets/agent-state/TASK.md +18 -0
- package/assets/agent-state/TEAL_CONFIG.md +117 -0
- package/assets/agent-state/handoff-registry.json +5 -0
- package/assets/agent-state/index-fingerprints.json +7 -0
- package/assets/agent-state/index.json +32 -0
- package/assets/agent-state/run-ledger.json +5 -0
- package/assets/agent-state/runtime-executor-sessions.json +5 -0
- package/assets/agent-state/runtime-tool-specs.json +5 -0
- package/assets/agent-state/runtime-workspaces.json +5 -0
- package/assets/agent-state/todo-state.json +7 -0
- package/assets/agent-state/tracker-snapshot.json +7 -0
- package/assets/agent-state/vericify/ace-bridge.json +60 -0
- package/assets/agent-state/vericify/process-posts.json +5 -0
- package/assets/instructions/ACE.instructions.md +187 -0
- package/assets/instructions/ACE_Coder.instructions.md +146 -0
- package/assets/instructions/ACE_UI.instructions.md +178 -0
- package/assets/instructions/ACE_VOS.instructions.md +211 -0
- package/assets/scripts/ace-hook-dispatch.mjs +538 -0
- package/assets/scripts/bootstrap-workspace.sh +27 -0
- package/assets/scripts/copilot-hook-dispatch.mjs +3 -0
- package/assets/scripts/eval-harness.sh +68 -0
- package/assets/scripts/render-mcp-configs.sh +396 -0
- package/assets/tasks/README.md +48 -0
- package/assets/tasks/SWARM_HANDOFF.example.json +53 -0
- package/assets/tasks/SWARM_HANDOFF.example_ui_to_coders.json +55 -0
- package/assets/tasks/SWARM_HANDOFF.example_vos_to_ui.json +55 -0
- package/assets/tasks/SWARM_HANDOFF.template.json +52 -0
- package/assets/tasks/cli_work_split.md +22 -0
- package/assets/tasks/lessons.md +17 -0
- package/assets/tasks/role_tasks.md +206 -0
- package/assets/tasks/todo.md +23 -0
- package/dist/ace-autonomy.d.ts +137 -0
- package/dist/ace-autonomy.js +472 -0
- package/dist/ace-context.d.ts +29 -0
- package/dist/ace-context.js +240 -0
- package/dist/ace-internal-tools.d.ts +8 -0
- package/dist/ace-internal-tools.js +76 -0
- package/dist/ace-server-instructions.d.ts +12 -0
- package/dist/ace-server-instructions.js +324 -0
- package/dist/agent-runtime/role-adapters.d.ts +29 -0
- package/dist/agent-runtime/role-adapters.js +573 -0
- package/dist/astgrep-index.d.ts +24 -0
- package/dist/astgrep-index.js +476 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +591 -0
- package/dist/git-ops.d.ts +53 -0
- package/dist/git-ops.js +238 -0
- package/dist/handoff-registry.d.ts +71 -0
- package/dist/handoff-registry.js +422 -0
- package/dist/helpers.d.ts +126 -0
- package/dist/helpers.js +1687 -0
- package/dist/index-store.d.ts +51 -0
- package/dist/index-store.js +328 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/internal-tool-runtime.d.ts +21 -0
- package/dist/internal-tool-runtime.js +136 -0
- package/dist/job-scheduler.d.ts +175 -0
- package/dist/job-scheduler.js +1217 -0
- package/dist/kanban.d.ts +27 -0
- package/dist/kanban.js +339 -0
- package/dist/local-model-runtime.d.ts +40 -0
- package/dist/local-model-runtime.js +174 -0
- package/dist/model-bridge.d.ts +54 -0
- package/dist/model-bridge.js +587 -0
- package/dist/orchestrator-supervisor.d.ts +100 -0
- package/dist/orchestrator-supervisor.js +399 -0
- package/dist/problem-triage.d.ts +23 -0
- package/dist/problem-triage.js +448 -0
- package/dist/prompts.d.ts +7 -0
- package/dist/prompts.js +628 -0
- package/dist/public-surface.d.ts +30 -0
- package/dist/public-surface.js +316 -0
- package/dist/resources.d.ts +7 -0
- package/dist/resources.js +545 -0
- package/dist/run-ledger.d.ts +36 -0
- package/dist/run-ledger.js +257 -0
- package/dist/runtime-command.d.ts +18 -0
- package/dist/runtime-command.js +76 -0
- package/dist/runtime-executor.d.ts +104 -0
- package/dist/runtime-executor.js +985 -0
- package/dist/runtime-profile.d.ts +116 -0
- package/dist/runtime-profile.js +532 -0
- package/dist/runtime-tool-specs.d.ts +68 -0
- package/dist/runtime-tool-specs.js +527 -0
- package/dist/safe-edit.d.ts +52 -0
- package/dist/safe-edit.js +255 -0
- package/dist/schemas.d.ts +44 -0
- package/dist/schemas.js +830 -0
- package/dist/semantic-cache.d.ts +147 -0
- package/dist/semantic-cache.js +552 -0
- package/dist/semantic-hash.d.ts +83 -0
- package/dist/semantic-hash.js +346 -0
- package/dist/server.d.ts +10 -0
- package/dist/server.js +46 -0
- package/dist/shared.d.ts +136 -0
- package/dist/shared.js +269 -0
- package/dist/skill-auditor.d.ts +26 -0
- package/dist/skill-auditor.js +184 -0
- package/dist/skill-catalog.d.ts +60 -0
- package/dist/skill-catalog.js +305 -0
- package/dist/status-events.d.ts +40 -0
- package/dist/status-events.js +269 -0
- package/dist/store/ace-packed-store.d.ts +69 -0
- package/dist/store/ace-packed-store.js +434 -0
- package/dist/store/bootstrap-store.d.ts +46 -0
- package/dist/store/bootstrap-store.js +242 -0
- package/dist/store/catalog-builder.d.ts +21 -0
- package/dist/store/catalog-builder.js +68 -0
- package/dist/store/importer.d.ts +19 -0
- package/dist/store/importer.js +157 -0
- package/dist/store/knowledge-bake.d.ts +59 -0
- package/dist/store/knowledge-bake.js +339 -0
- package/dist/store/materializers/hook-context-materializer.d.ts +25 -0
- package/dist/store/materializers/hook-context-materializer.js +100 -0
- package/dist/store/materializers/host-file-materializer.d.ts +37 -0
- package/dist/store/materializers/host-file-materializer.js +271 -0
- package/dist/store/materializers/todo-syncer.d.ts +30 -0
- package/dist/store/materializers/todo-syncer.js +140 -0
- package/dist/store/materializers/vericify-projector.d.ts +38 -0
- package/dist/store/materializers/vericify-projector.js +239 -0
- package/dist/store/repositories/discovery-repository.d.ts +24 -0
- package/dist/store/repositories/discovery-repository.js +58 -0
- package/dist/store/repositories/handoff-repository.d.ts +31 -0
- package/dist/store/repositories/handoff-repository.js +67 -0
- package/dist/store/repositories/ledger-repository.d.ts +26 -0
- package/dist/store/repositories/ledger-repository.js +49 -0
- package/dist/store/repositories/runtime-kv-repository.d.ts +16 -0
- package/dist/store/repositories/runtime-kv-repository.js +36 -0
- package/dist/store/repositories/scheduler-repository.d.ts +50 -0
- package/dist/store/repositories/scheduler-repository.js +123 -0
- package/dist/store/repositories/session-repository.d.ts +33 -0
- package/dist/store/repositories/session-repository.js +82 -0
- package/dist/store/repositories/todo-repository.d.ts +31 -0
- package/dist/store/repositories/todo-repository.js +77 -0
- package/dist/store/repositories/tracker-repository.d.ts +25 -0
- package/dist/store/repositories/tracker-repository.js +43 -0
- package/dist/store/repositories/vericify-repository.d.ts +32 -0
- package/dist/store/repositories/vericify-repository.js +58 -0
- package/dist/store/skills-install.d.ts +28 -0
- package/dist/store/skills-install.js +86 -0
- package/dist/store/state-reader.d.ts +49 -0
- package/dist/store/state-reader.js +111 -0
- package/dist/store/store-artifacts.d.ts +12 -0
- package/dist/store/store-artifacts.js +138 -0
- package/dist/store/store-snapshot.d.ts +19 -0
- package/dist/store/store-snapshot.js +140 -0
- package/dist/store/topology-bake.d.ts +15 -0
- package/dist/store/topology-bake.js +215 -0
- package/dist/store/types.d.ts +155 -0
- package/dist/store/types.js +35 -0
- package/dist/store/workspace-snapshot.d.ts +26 -0
- package/dist/store/workspace-snapshot.js +107 -0
- package/dist/store/write-queue.d.ts +7 -0
- package/dist/store/write-queue.js +26 -0
- package/dist/todo-state.d.ts +41 -0
- package/dist/todo-state.js +399 -0
- package/dist/tools-agent.d.ts +7 -0
- package/dist/tools-agent.js +1542 -0
- package/dist/tools-discovery.d.ts +6 -0
- package/dist/tools-discovery.js +178 -0
- package/dist/tools-drift.d.ts +13 -0
- package/dist/tools-drift.js +357 -0
- package/dist/tools-files.d.ts +6 -0
- package/dist/tools-files.js +679 -0
- package/dist/tools-framework.d.ts +7 -0
- package/dist/tools-framework.js +1414 -0
- package/dist/tools-git.d.ts +6 -0
- package/dist/tools-git.js +183 -0
- package/dist/tools-handoff.d.ts +32 -0
- package/dist/tools-handoff.js +489 -0
- package/dist/tools-lifecycle.d.ts +6 -0
- package/dist/tools-lifecycle.js +205 -0
- package/dist/tools-memory.d.ts +6 -0
- package/dist/tools-memory.js +260 -0
- package/dist/tools-scheduler.d.ts +6 -0
- package/dist/tools-scheduler.js +228 -0
- package/dist/tools-skills.d.ts +3 -0
- package/dist/tools-skills.js +104 -0
- package/dist/tools-todo.d.ts +6 -0
- package/dist/tools-todo.js +154 -0
- package/dist/tools.d.ts +9 -0
- package/dist/tools.js +33 -0
- package/dist/tracker-adapters.d.ts +74 -0
- package/dist/tracker-adapters.js +776 -0
- package/dist/tracker-sync.d.ts +10 -0
- package/dist/tracker-sync.js +84 -0
- package/dist/tui/agent-runner.d.ts +137 -0
- package/dist/tui/agent-runner.js +466 -0
- package/dist/tui/agent-worker.d.ts +10 -0
- package/dist/tui/agent-worker.js +347 -0
- package/dist/tui/chat.d.ts +84 -0
- package/dist/tui/chat.js +368 -0
- package/dist/tui/commands.d.ts +57 -0
- package/dist/tui/commands.js +432 -0
- package/dist/tui/dashboard.d.ts +24 -0
- package/dist/tui/dashboard.js +110 -0
- package/dist/tui/index.d.ts +114 -0
- package/dist/tui/index.js +1059 -0
- package/dist/tui/input.d.ts +49 -0
- package/dist/tui/input.js +336 -0
- package/dist/tui/layout.d.ts +116 -0
- package/dist/tui/layout.js +367 -0
- package/dist/tui/ollama.d.ts +116 -0
- package/dist/tui/ollama.js +192 -0
- package/dist/tui/openai-compatible.d.ts +63 -0
- package/dist/tui/openai-compatible.js +370 -0
- package/dist/tui/provider-discovery.d.ts +59 -0
- package/dist/tui/provider-discovery.js +530 -0
- package/dist/tui/renderer.d.ts +166 -0
- package/dist/tui/renderer.js +304 -0
- package/dist/tui/tabs.d.ts +70 -0
- package/dist/tui/tabs.js +208 -0
- package/dist/tui/telemetry.d.ts +56 -0
- package/dist/tui/telemetry.js +106 -0
- package/dist/vericify-bridge.d.ts +146 -0
- package/dist/vericify-bridge.js +571 -0
- package/dist/vericify-context.d.ts +10 -0
- package/dist/vericify-context.js +72 -0
- package/dist/workspace-manager.d.ts +107 -0
- package/dist/workspace-manager.js +636 -0
- package/package.json +83 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AcePackedStore
|
|
3
|
+
*
|
|
4
|
+
* Custom single-file store that implements Zarrita's AsyncReadable + AsyncWritable
|
|
5
|
+
* interfaces over a packed binary file at `.agents/ACE/ace-state.zarr`.
|
|
6
|
+
*
|
|
7
|
+
* File format:
|
|
8
|
+
* [ Header 64 bytes ] magic(8) version(4) flags(4) index_offset(8) index_length(8) reserved(32)
|
|
9
|
+
* [ Chunk region ] chunk_0: [uint32 length][bytes] ... chunk_N: [uint32 length][bytes]
|
|
10
|
+
* [ Index region ] UTF-8 JSON: { key → { offset, length } }
|
|
11
|
+
*
|
|
12
|
+
* Write protocol:
|
|
13
|
+
* 1. Append new chunk to end of chunk region.
|
|
14
|
+
* 2. Update in-memory index.
|
|
15
|
+
* 3. On commit(): rewrite index region → update header → fsync.
|
|
16
|
+
*
|
|
17
|
+
* Compaction:
|
|
18
|
+
* Write live chunks to temp file → validate → atomic rename.
|
|
19
|
+
*
|
|
20
|
+
* Locking:
|
|
21
|
+
* Advisory flock-style via a `.lock` sidecar file (PID + timestamp).
|
|
22
|
+
* Stale detection: lock held >30s and PID not alive → break lock.
|
|
23
|
+
*/
|
|
24
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, renameSync, unlinkSync } from "fs";
|
|
25
|
+
import { open as fsOpen } from "fs/promises";
|
|
26
|
+
import { dirname } from "path";
|
|
27
|
+
import { MAGIC, STORE_VERSION, HEADER_SIZE, ContentSource, EntityKind, } from "./types.js";
|
|
28
|
+
const LOCK_TIMEOUT_MS = 30_000;
|
|
29
|
+
const TEXT = new TextEncoder();
|
|
30
|
+
const DECODE = new TextDecoder();
|
|
31
|
+
function fnv1a(s) {
|
|
32
|
+
let h = 2166136261;
|
|
33
|
+
for (let i = 0; i < s.length; i++) {
|
|
34
|
+
h ^= s.charCodeAt(i);
|
|
35
|
+
h = Math.imul(h, 16777619) >>> 0;
|
|
36
|
+
}
|
|
37
|
+
return h >>> 0;
|
|
38
|
+
}
|
|
39
|
+
function uint32ToBytes(n) {
|
|
40
|
+
const b = new Uint8Array(4);
|
|
41
|
+
new DataView(b.buffer).setUint32(0, n, false);
|
|
42
|
+
return b;
|
|
43
|
+
}
|
|
44
|
+
function bytesToUint32(b, offset = 0) {
|
|
45
|
+
return new DataView(b.buffer, b.byteOffset).getUint32(offset, false);
|
|
46
|
+
}
|
|
47
|
+
function uint64ToBytes(n) {
|
|
48
|
+
// JS numbers are safe up to 2^53 — sufficient for file offsets
|
|
49
|
+
const b = new Uint8Array(8);
|
|
50
|
+
const dv = new DataView(b.buffer);
|
|
51
|
+
dv.setUint32(0, Math.floor(n / 2 ** 32), false);
|
|
52
|
+
dv.setUint32(4, n >>> 0, false);
|
|
53
|
+
return b;
|
|
54
|
+
}
|
|
55
|
+
function bytesToUint64(b, offset = 0) {
|
|
56
|
+
const dv = new DataView(b.buffer, b.byteOffset);
|
|
57
|
+
return dv.getUint32(offset, false) * 2 ** 32 + dv.getUint32(offset + 4, false);
|
|
58
|
+
}
|
|
59
|
+
async function readExact(handle, buffer, position) {
|
|
60
|
+
let offset = 0;
|
|
61
|
+
while (offset < buffer.length) {
|
|
62
|
+
const { bytesRead } = await handle.read(buffer, offset, buffer.length - offset, position + offset);
|
|
63
|
+
if (bytesRead <= 0) {
|
|
64
|
+
throw new Error("AcePackedStore: unexpected EOF while reading chunk");
|
|
65
|
+
}
|
|
66
|
+
offset += bytesRead;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function writeExact(handle, buffer, position) {
|
|
70
|
+
const source = Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer);
|
|
71
|
+
let offset = 0;
|
|
72
|
+
while (offset < source.length) {
|
|
73
|
+
const { bytesWritten } = await handle.write(source, offset, source.length - offset, position + offset);
|
|
74
|
+
if (bytesWritten <= 0) {
|
|
75
|
+
throw new Error("AcePackedStore: failed to write chunk");
|
|
76
|
+
}
|
|
77
|
+
offset += bytesWritten;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function acquireLock(lockPath) {
|
|
81
|
+
if (existsSync(lockPath)) {
|
|
82
|
+
const raw = readFileSync(lockPath, "utf8");
|
|
83
|
+
try {
|
|
84
|
+
const rec = JSON.parse(raw);
|
|
85
|
+
const age = Date.now() - rec.ts;
|
|
86
|
+
if (age < LOCK_TIMEOUT_MS) {
|
|
87
|
+
// Check if PID is alive
|
|
88
|
+
try {
|
|
89
|
+
process.kill(rec.pid, 0);
|
|
90
|
+
throw new Error(`AcePackedStore: locked by PID ${rec.pid} (${age}ms ago)`);
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
// PID not alive — stale lock, fall through to break it
|
|
94
|
+
if (e.code !== "ESRCH")
|
|
95
|
+
throw e;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Unparseable lock — break it
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
writeFileSync(lockPath, JSON.stringify({ pid: process.pid, ts: Date.now() }), "utf8");
|
|
104
|
+
}
|
|
105
|
+
function releaseLock(lockPath) {
|
|
106
|
+
if (existsSync(lockPath)) {
|
|
107
|
+
try {
|
|
108
|
+
unlinkSync(lockPath);
|
|
109
|
+
}
|
|
110
|
+
catch { /* ignore */ }
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// ── Header serialisation ──────────────────────────────────────────────────────
|
|
114
|
+
function writeHeader(buf, indexOffset, indexLength) {
|
|
115
|
+
// magic
|
|
116
|
+
for (let i = 0; i < 8; i++)
|
|
117
|
+
buf[i] = MAGIC.charCodeAt(i);
|
|
118
|
+
// version
|
|
119
|
+
buf.set(uint32ToBytes(STORE_VERSION), 8);
|
|
120
|
+
// flags
|
|
121
|
+
buf.set(uint32ToBytes(0), 12);
|
|
122
|
+
// index_offset
|
|
123
|
+
buf.set(uint64ToBytes(indexOffset), 16);
|
|
124
|
+
// index_length
|
|
125
|
+
buf.set(uint64ToBytes(indexLength), 24);
|
|
126
|
+
// reserved: zero-filled (already 0 on new Uint8Array)
|
|
127
|
+
}
|
|
128
|
+
function readHeader(buf) {
|
|
129
|
+
const magic = DECODE.decode(buf.slice(0, 8));
|
|
130
|
+
if (magic !== MAGIC)
|
|
131
|
+
throw new Error("AcePackedStore: invalid magic bytes — not an ACEPACK file");
|
|
132
|
+
return {
|
|
133
|
+
version: bytesToUint32(buf, 8),
|
|
134
|
+
indexOffset: bytesToUint64(buf, 16),
|
|
135
|
+
indexLength: bytesToUint64(buf, 24),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
// ── AcePackedStore ────────────────────────────────────────────────────────────
|
|
139
|
+
export class AcePackedStore {
|
|
140
|
+
storePath = "";
|
|
141
|
+
lockPath = "";
|
|
142
|
+
readOnly = false;
|
|
143
|
+
index = new Map();
|
|
144
|
+
chunkEnd = HEADER_SIZE; // byte offset immediately after last chunk
|
|
145
|
+
fh = null;
|
|
146
|
+
dirty = false;
|
|
147
|
+
entryCounter = 0;
|
|
148
|
+
// ── Lifecycle ─────────────────────────────────────────────────────────────
|
|
149
|
+
async open(path, opts = {}) {
|
|
150
|
+
this.storePath = path;
|
|
151
|
+
this.lockPath = path + ".lock";
|
|
152
|
+
this.readOnly = opts.readOnly ?? false;
|
|
153
|
+
if (!this.readOnly) {
|
|
154
|
+
acquireLock(this.lockPath);
|
|
155
|
+
}
|
|
156
|
+
if (!existsSync(path)) {
|
|
157
|
+
if (this.readOnly)
|
|
158
|
+
throw new Error(`AcePackedStore: store not found at ${path}`);
|
|
159
|
+
await this._initNewStore(path);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
await this._loadExistingStore(path);
|
|
163
|
+
}
|
|
164
|
+
this.fh = await fsOpen(path, this.readOnly ? "r" : "r+");
|
|
165
|
+
}
|
|
166
|
+
async _initNewStore(path) {
|
|
167
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
168
|
+
const header = new Uint8Array(HEADER_SIZE);
|
|
169
|
+
// Index starts immediately after header (empty at init)
|
|
170
|
+
const emptyIndex = TEXT.encode("{}");
|
|
171
|
+
writeHeader(header, HEADER_SIZE, emptyIndex.length);
|
|
172
|
+
const buf = new Uint8Array(HEADER_SIZE + emptyIndex.length);
|
|
173
|
+
buf.set(header);
|
|
174
|
+
buf.set(emptyIndex, HEADER_SIZE);
|
|
175
|
+
writeFileSync(path, buf);
|
|
176
|
+
this.chunkEnd = HEADER_SIZE;
|
|
177
|
+
this.index = new Map();
|
|
178
|
+
}
|
|
179
|
+
async _loadExistingStore(path) {
|
|
180
|
+
const file = readFileSync(path);
|
|
181
|
+
if (file.length < HEADER_SIZE)
|
|
182
|
+
throw new Error("AcePackedStore: file too short");
|
|
183
|
+
const { indexOffset, indexLength } = readHeader(file.slice(0, HEADER_SIZE));
|
|
184
|
+
const idxBytes = file.slice(indexOffset, indexOffset + indexLength);
|
|
185
|
+
const idxJson = JSON.parse(DECODE.decode(idxBytes));
|
|
186
|
+
this.index = new Map(Object.entries(idxJson));
|
|
187
|
+
// chunkEnd = start of index region (chunks live between header and index)
|
|
188
|
+
this.chunkEnd = indexOffset;
|
|
189
|
+
// Re-derive entry counter from unified log entries
|
|
190
|
+
const logKeys = [...this.index.keys()].filter(k => k.startsWith("core/log/"));
|
|
191
|
+
this.entryCounter = logKeys.length;
|
|
192
|
+
}
|
|
193
|
+
async commit() {
|
|
194
|
+
if (this.readOnly || !this.fh || !this.dirty)
|
|
195
|
+
return;
|
|
196
|
+
const idxJson = JSON.stringify(Object.fromEntries(this.index));
|
|
197
|
+
const idxBytes = TEXT.encode(idxJson);
|
|
198
|
+
// Write index at current chunkEnd
|
|
199
|
+
await writeExact(this.fh, idxBytes, this.chunkEnd);
|
|
200
|
+
// Update header
|
|
201
|
+
const header = new Uint8Array(HEADER_SIZE);
|
|
202
|
+
writeHeader(header, this.chunkEnd, idxBytes.length);
|
|
203
|
+
await writeExact(this.fh, header, 0);
|
|
204
|
+
// Truncate any stale trailing bytes
|
|
205
|
+
await this.fh.truncate(this.chunkEnd + idxBytes.length);
|
|
206
|
+
await this.fh.datasync();
|
|
207
|
+
this.dirty = false;
|
|
208
|
+
}
|
|
209
|
+
async compact() {
|
|
210
|
+
if (!this.storePath)
|
|
211
|
+
return;
|
|
212
|
+
const lockPath = this.lockPath;
|
|
213
|
+
const tmpPath = this.storePath + ".tmp";
|
|
214
|
+
// Write live chunks to temp file
|
|
215
|
+
const liveIndex = new Map();
|
|
216
|
+
let writeOffset = HEADER_SIZE;
|
|
217
|
+
const srcFile = readFileSync(this.storePath);
|
|
218
|
+
const chunks = [];
|
|
219
|
+
for (const [key, { offset, length }] of this.index) {
|
|
220
|
+
// offset points to the uint32 length prefix; skip 4 bytes to get pure data
|
|
221
|
+
const chunk = srcFile.slice(offset + 4, offset + 4 + length);
|
|
222
|
+
chunks.push(chunk);
|
|
223
|
+
liveIndex.set(key, { offset: writeOffset, length });
|
|
224
|
+
writeOffset += 4 + length; // uint32 length prefix + data
|
|
225
|
+
}
|
|
226
|
+
const idxJson = JSON.stringify(Object.fromEntries(liveIndex));
|
|
227
|
+
const idxBytes = TEXT.encode(idxJson);
|
|
228
|
+
const totalSize = HEADER_SIZE + chunks.reduce((s, c) => s + 4 + c.length, 0) + idxBytes.length;
|
|
229
|
+
const out = new Uint8Array(totalSize);
|
|
230
|
+
const header = new Uint8Array(HEADER_SIZE);
|
|
231
|
+
writeHeader(header, writeOffset, idxBytes.length);
|
|
232
|
+
out.set(header);
|
|
233
|
+
let pos = HEADER_SIZE;
|
|
234
|
+
for (const chunk of chunks) {
|
|
235
|
+
out.set(uint32ToBytes(chunk.length), pos);
|
|
236
|
+
out.set(chunk, pos + 4);
|
|
237
|
+
pos += 4 + chunk.length;
|
|
238
|
+
}
|
|
239
|
+
out.set(idxBytes, pos);
|
|
240
|
+
writeFileSync(tmpPath, out);
|
|
241
|
+
// Validate temp file magic
|
|
242
|
+
const tmpBuf = readFileSync(tmpPath);
|
|
243
|
+
readHeader(tmpBuf.slice(0, HEADER_SIZE)); // throws if invalid
|
|
244
|
+
// Atomic rename
|
|
245
|
+
if (this.fh) {
|
|
246
|
+
await this.fh.close();
|
|
247
|
+
this.fh = null;
|
|
248
|
+
}
|
|
249
|
+
renameSync(tmpPath, this.storePath);
|
|
250
|
+
releaseLock(lockPath);
|
|
251
|
+
acquireLock(lockPath);
|
|
252
|
+
this.fh = await fsOpen(this.storePath, "r+");
|
|
253
|
+
this.index = liveIndex;
|
|
254
|
+
this.chunkEnd = writeOffset;
|
|
255
|
+
this.dirty = false;
|
|
256
|
+
}
|
|
257
|
+
async close() {
|
|
258
|
+
await this.commit();
|
|
259
|
+
if (this.fh) {
|
|
260
|
+
await this.fh.close();
|
|
261
|
+
this.fh = null;
|
|
262
|
+
}
|
|
263
|
+
if (!this.readOnly)
|
|
264
|
+
releaseLock(this.lockPath);
|
|
265
|
+
}
|
|
266
|
+
// ── Zarrita protocol ──────────────────────────────────────────────────────
|
|
267
|
+
async get(key) {
|
|
268
|
+
const entry = this.index.get(key);
|
|
269
|
+
if (!entry)
|
|
270
|
+
return undefined;
|
|
271
|
+
if (!this.fh)
|
|
272
|
+
throw new Error("AcePackedStore: store not open");
|
|
273
|
+
const dataBuf = Buffer.alloc(entry.length);
|
|
274
|
+
await readExact(this.fh, dataBuf, entry.offset + 4);
|
|
275
|
+
return dataBuf;
|
|
276
|
+
}
|
|
277
|
+
async set(key, value) {
|
|
278
|
+
if (this.readOnly)
|
|
279
|
+
throw new Error("AcePackedStore: cannot write — store opened read-only");
|
|
280
|
+
if (!this.fh)
|
|
281
|
+
throw new Error("AcePackedStore: store not open");
|
|
282
|
+
const lenPrefix = uint32ToBytes(value.length);
|
|
283
|
+
const chunkOffset = this.chunkEnd;
|
|
284
|
+
await writeExact(this.fh, lenPrefix, chunkOffset);
|
|
285
|
+
await writeExact(this.fh, value, chunkOffset + 4);
|
|
286
|
+
this.index.set(key, { offset: chunkOffset, length: value.length });
|
|
287
|
+
this.chunkEnd += 4 + value.length;
|
|
288
|
+
this.dirty = true;
|
|
289
|
+
}
|
|
290
|
+
async delete(key) {
|
|
291
|
+
const existed = this.index.has(key);
|
|
292
|
+
this.index.delete(key);
|
|
293
|
+
if (existed)
|
|
294
|
+
this.dirty = true;
|
|
295
|
+
return existed;
|
|
296
|
+
}
|
|
297
|
+
async *list() {
|
|
298
|
+
for (const key of this.index.keys())
|
|
299
|
+
yield key;
|
|
300
|
+
}
|
|
301
|
+
// ── JSON / Blob convenience ───────────────────────────────────────────────
|
|
302
|
+
async getJSON(key) {
|
|
303
|
+
const raw = await this.get(key);
|
|
304
|
+
if (!raw)
|
|
305
|
+
return undefined;
|
|
306
|
+
return JSON.parse(DECODE.decode(raw));
|
|
307
|
+
}
|
|
308
|
+
async setJSON(key, value) {
|
|
309
|
+
await this.set(key, TEXT.encode(JSON.stringify(value)));
|
|
310
|
+
}
|
|
311
|
+
async getBlob(key) {
|
|
312
|
+
const raw = await this.get(key);
|
|
313
|
+
if (!raw)
|
|
314
|
+
return undefined;
|
|
315
|
+
return DECODE.decode(raw);
|
|
316
|
+
}
|
|
317
|
+
async setBlob(key, content) {
|
|
318
|
+
await this.set(key, TEXT.encode(content));
|
|
319
|
+
}
|
|
320
|
+
// ── Unified entry log ─────────────────────────────────────────────────────
|
|
321
|
+
async appendEntry(entry) {
|
|
322
|
+
const seqKey = "meta/log_entry_seq";
|
|
323
|
+
const current = (await this.getJSON(seqKey)) ?? this.entryCounter;
|
|
324
|
+
const id = current + 1;
|
|
325
|
+
this.entryCounter = id;
|
|
326
|
+
await this.setJSON(seqKey, id);
|
|
327
|
+
const full = { ...entry, id, ts: Date.now() };
|
|
328
|
+
const logKey = `core/log/${String(id).padStart(12, "0")}`;
|
|
329
|
+
await this.setJSON(logKey, full);
|
|
330
|
+
return full;
|
|
331
|
+
}
|
|
332
|
+
async getEntries(filter) {
|
|
333
|
+
const results = [];
|
|
334
|
+
for (const key of this.index.keys()) {
|
|
335
|
+
if (!key.startsWith("core/log/") || key === "core/log/__seq")
|
|
336
|
+
continue;
|
|
337
|
+
const entry = await this.getJSON(key);
|
|
338
|
+
if (!entry)
|
|
339
|
+
continue;
|
|
340
|
+
if (filter?.kind !== undefined && entry.kind !== filter.kind)
|
|
341
|
+
continue;
|
|
342
|
+
if (filter?.content_source !== undefined && entry.content_source !== filter.content_source)
|
|
343
|
+
continue;
|
|
344
|
+
if (filter?.keyPrefix && !entry.key.startsWith(filter.keyPrefix))
|
|
345
|
+
continue;
|
|
346
|
+
if (filter?.since !== undefined && entry.ts < filter.since)
|
|
347
|
+
continue;
|
|
348
|
+
if (!filter?.includeDeleted && (entry.flags ?? 0) & 0x01)
|
|
349
|
+
continue;
|
|
350
|
+
results.push(entry);
|
|
351
|
+
}
|
|
352
|
+
return results.sort((a, b) => a.id - b.id);
|
|
353
|
+
}
|
|
354
|
+
async getEntry(key) {
|
|
355
|
+
return this.getJSON(key);
|
|
356
|
+
}
|
|
357
|
+
// ── Topology ──────────────────────────────────────────────────────────────
|
|
358
|
+
async getTopology(kind) {
|
|
359
|
+
return (await this.getJSON(`topology/${kind}`)) ?? [];
|
|
360
|
+
}
|
|
361
|
+
async setTopology(kind, entries) {
|
|
362
|
+
await this.setJSON(`topology/${kind}`, entries);
|
|
363
|
+
}
|
|
364
|
+
// ── Knowledge: agents ─────────────────────────────────────────────────────
|
|
365
|
+
async getAgentInstruction(agent, file) {
|
|
366
|
+
return this.getBlob(`knowledge/agents/${agent}/${file}`);
|
|
367
|
+
}
|
|
368
|
+
async setAgentInstruction(agent, file, content, source = ContentSource.Package) {
|
|
369
|
+
const key = `knowledge/agents/${agent}/${file}`;
|
|
370
|
+
await this.setBlob(key, content);
|
|
371
|
+
await this.appendEntry({
|
|
372
|
+
kind: EntityKind.AgentInstruction,
|
|
373
|
+
content_source: source,
|
|
374
|
+
key,
|
|
375
|
+
payload: { agent, file, length: content.length },
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
async listAgents() {
|
|
379
|
+
const agents = new Set();
|
|
380
|
+
for (const key of this.index.keys()) {
|
|
381
|
+
if (key.startsWith("knowledge/agents/")) {
|
|
382
|
+
const parts = key.split("/");
|
|
383
|
+
if (parts[2])
|
|
384
|
+
agents.add(parts[2]);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return [...agents].sort();
|
|
388
|
+
}
|
|
389
|
+
// ── Knowledge: skills ─────────────────────────────────────────────────────
|
|
390
|
+
async getSkillContent(skill, file) {
|
|
391
|
+
return this.getBlob(`knowledge/skills/${skill}/${file}`);
|
|
392
|
+
}
|
|
393
|
+
async setSkillContent(skill, file, content, source = ContentSource.Package) {
|
|
394
|
+
const key = `knowledge/skills/${skill}/${file}`;
|
|
395
|
+
await this.setBlob(key, content);
|
|
396
|
+
await this.appendEntry({
|
|
397
|
+
kind: EntityKind.SkillDefinition,
|
|
398
|
+
content_source: source,
|
|
399
|
+
key,
|
|
400
|
+
payload: { skill, file, length: content.length },
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
async listSkills() {
|
|
404
|
+
const skills = new Set();
|
|
405
|
+
for (const key of this.index.keys()) {
|
|
406
|
+
if (key.startsWith("knowledge/skills/")) {
|
|
407
|
+
const parts = key.split("/");
|
|
408
|
+
if (parts[2])
|
|
409
|
+
skills.add(parts[2]);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return [...skills].sort();
|
|
413
|
+
}
|
|
414
|
+
// ── Internal helpers ──────────────────────────────────────────────────────
|
|
415
|
+
/** Dead space ratio — used to decide if compaction is needed */
|
|
416
|
+
get deadSpaceRatio() {
|
|
417
|
+
if (!existsSync(this.storePath))
|
|
418
|
+
return 0;
|
|
419
|
+
const totalSize = this.chunkEnd;
|
|
420
|
+
const liveSize = HEADER_SIZE + [...this.index.values()].reduce((s, e) => s + 4 + e.length, 0);
|
|
421
|
+
return totalSize > 0 ? 1 - liveSize / totalSize : 0;
|
|
422
|
+
}
|
|
423
|
+
/** Number of entries in the unified log */
|
|
424
|
+
get entryCount() {
|
|
425
|
+
return this.entryCounter;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
// ── Factory ────────────────────────────────────────────────────────────────────
|
|
429
|
+
export async function openStore(storePath, opts = {}) {
|
|
430
|
+
const store = new AcePackedStore();
|
|
431
|
+
await store.open(storePath, opts);
|
|
432
|
+
return store;
|
|
433
|
+
}
|
|
434
|
+
//# sourceMappingURL=ace-packed-store.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bootstrap-store.ts — Phase 8
|
|
3
|
+
*
|
|
4
|
+
* New bootstrapAceWorkspace() using the Zarrita-backed store.
|
|
5
|
+
*
|
|
6
|
+
* Replaces the old copyTree()-based bootstrap with:
|
|
7
|
+
* 1. Create minimal directories
|
|
8
|
+
* 2. Initialize AcePackedStore at .agents/ACE/ace-state.zarr
|
|
9
|
+
* 3. Bake core knowledge (agents, modules, kernel)
|
|
10
|
+
* 4. Write topology records
|
|
11
|
+
* 5. Write initial runtime state seeds
|
|
12
|
+
* 6. Write meta (codebooks, schema version)
|
|
13
|
+
* 7. Compact the store
|
|
14
|
+
* 8. Optionally materialize host integration files
|
|
15
|
+
* 9. Materialize hook context snapshot
|
|
16
|
+
* 10. Write tasks/todo.md starter
|
|
17
|
+
*/
|
|
18
|
+
export interface BootstrapOptions {
|
|
19
|
+
workspaceRoot: string;
|
|
20
|
+
projectName?: string;
|
|
21
|
+
force?: boolean;
|
|
22
|
+
includeMcpConfig?: boolean;
|
|
23
|
+
includeClientConfigBundle?: boolean;
|
|
24
|
+
mcpServerPath?: string;
|
|
25
|
+
llm?: string;
|
|
26
|
+
model?: string;
|
|
27
|
+
ollamaUrl?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface BootstrapResult {
|
|
30
|
+
storePath: string;
|
|
31
|
+
agents: number;
|
|
32
|
+
modules: {
|
|
33
|
+
gates: number;
|
|
34
|
+
roles: number;
|
|
35
|
+
schemas: number;
|
|
36
|
+
};
|
|
37
|
+
materialized: string[];
|
|
38
|
+
warnings: string[];
|
|
39
|
+
}
|
|
40
|
+
export declare function bootstrapStoreWorkspace(opts: BootstrapOptions): Promise<BootstrapResult>;
|
|
41
|
+
export declare function repairWorkspace(workspaceRoot: string): Promise<string[]>;
|
|
42
|
+
export declare function compactWorkspace(workspaceRoot: string): Promise<{
|
|
43
|
+
before: number;
|
|
44
|
+
after: number;
|
|
45
|
+
}>;
|
|
46
|
+
//# sourceMappingURL=bootstrap-store.d.ts.map
|