@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,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safe-edit module: copy → modify → validate → swap pattern.
|
|
3
|
+
* Prevents bricking by never leaving core files in a broken state.
|
|
4
|
+
*/
|
|
5
|
+
import { copyFileSync, existsSync, mkdirSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { dirname, resolve } from "node:path";
|
|
8
|
+
import { spawnSync } from "node:child_process";
|
|
9
|
+
import { WORKSPACE_ROOT, safeRead, wsPath } from "./helpers.js";
|
|
10
|
+
import { isInside, isReadError, normalizeRelPath } from "./shared.js";
|
|
11
|
+
const STAGING_DIR = ".ace-staging";
|
|
12
|
+
// ────────────────────────────────────────────────────────────────────
|
|
13
|
+
// Helpers
|
|
14
|
+
// ────────────────────────────────────────────────────────────────────
|
|
15
|
+
function fileHash(content) {
|
|
16
|
+
return createHash("sha256").update(content).digest("hex").slice(0, 16);
|
|
17
|
+
}
|
|
18
|
+
function ensureDir(dirPath) {
|
|
19
|
+
if (!existsSync(dirPath))
|
|
20
|
+
mkdirSync(dirPath, { recursive: true });
|
|
21
|
+
}
|
|
22
|
+
function runValidation(validationCmd, testCmd) {
|
|
23
|
+
let validation_passed;
|
|
24
|
+
let validation_output;
|
|
25
|
+
let test_passed;
|
|
26
|
+
let test_output;
|
|
27
|
+
if (validationCmd) {
|
|
28
|
+
const res = spawnSync("sh", ["-c", validationCmd], {
|
|
29
|
+
cwd: WORKSPACE_ROOT,
|
|
30
|
+
encoding: "utf-8",
|
|
31
|
+
timeout: 60_000,
|
|
32
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
33
|
+
});
|
|
34
|
+
validation_passed = res.status === 0;
|
|
35
|
+
validation_output = ((res.stdout ?? "") + (res.stderr ?? "")).slice(0, 4000);
|
|
36
|
+
}
|
|
37
|
+
if (testCmd && (validation_passed === undefined || validation_passed)) {
|
|
38
|
+
const res = spawnSync("sh", ["-c", testCmd], {
|
|
39
|
+
cwd: WORKSPACE_ROOT,
|
|
40
|
+
encoding: "utf-8",
|
|
41
|
+
timeout: 120_000,
|
|
42
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
43
|
+
});
|
|
44
|
+
test_passed = res.status === 0;
|
|
45
|
+
test_output = ((res.stdout ?? "") + (res.stderr ?? "")).slice(0, 4000);
|
|
46
|
+
}
|
|
47
|
+
const passed = (validation_passed ?? true) && (test_passed ?? true);
|
|
48
|
+
return { passed, validation_passed, validation_output, test_passed, test_output };
|
|
49
|
+
}
|
|
50
|
+
// ────────────────────────────────────────────────────────────────────
|
|
51
|
+
// Safe edit (copy → modify → validate → swap)
|
|
52
|
+
// ────────────────────────────────────────────────────────────────────
|
|
53
|
+
export function safeEditFile(input) {
|
|
54
|
+
const absPath = resolve(WORKSPACE_ROOT, input.path);
|
|
55
|
+
// ── Workspace boundary guard ──────────────────────────────────────
|
|
56
|
+
if (!isInside(WORKSPACE_ROOT, absPath)) {
|
|
57
|
+
return {
|
|
58
|
+
ok: false,
|
|
59
|
+
original_path: absPath,
|
|
60
|
+
staging_path: "",
|
|
61
|
+
original_hash: "none",
|
|
62
|
+
new_hash: "none",
|
|
63
|
+
error: `Path escapes workspace root: ${input.path}`,
|
|
64
|
+
restored: false,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const relPath = normalizeRelPath(input.path);
|
|
68
|
+
const timestamp = Date.now();
|
|
69
|
+
const originalContent = safeRead(input.path);
|
|
70
|
+
const isNew = isReadError(originalContent);
|
|
71
|
+
const originalHash = isNew ? "none" : fileHash(originalContent);
|
|
72
|
+
const newHash = fileHash(input.content);
|
|
73
|
+
// Step 1: Create staging directory
|
|
74
|
+
const stagingDir = wsPath(STAGING_DIR, `${timestamp}-${isNew ? "new" : originalHash.slice(0, 8)}`);
|
|
75
|
+
ensureDir(stagingDir);
|
|
76
|
+
const flatName = relPath.replace(/\//g, "__");
|
|
77
|
+
const stagingNew = resolve(stagingDir, `new__${flatName}`);
|
|
78
|
+
writeFileSync(stagingNew, input.content, "utf-8");
|
|
79
|
+
// Step 2: If file exists, copy original to staging + backup
|
|
80
|
+
let backupPath;
|
|
81
|
+
if (!isNew) {
|
|
82
|
+
const stagingOriginal = resolve(stagingDir, `original__${flatName}`);
|
|
83
|
+
writeFileSync(stagingOriginal, originalContent, "utf-8");
|
|
84
|
+
if (input.backup !== false) {
|
|
85
|
+
backupPath = `${absPath}.ace-backup.${originalHash.slice(0, 8)}`;
|
|
86
|
+
copyFileSync(absPath, backupPath);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Step 3: Write new content
|
|
90
|
+
ensureDir(dirname(absPath));
|
|
91
|
+
writeFileSync(absPath, input.content, "utf-8");
|
|
92
|
+
// Step 4: Run validation/tests
|
|
93
|
+
if (input.validation_command || input.test_command) {
|
|
94
|
+
const check = runValidation(input.validation_command, input.test_command);
|
|
95
|
+
if (!check.passed) {
|
|
96
|
+
// ROLLBACK: restore original content
|
|
97
|
+
if (!isNew) {
|
|
98
|
+
writeFileSync(absPath, originalContent, "utf-8");
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
// Remove newly created file
|
|
102
|
+
try {
|
|
103
|
+
unlinkSync(absPath);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
/* best effort */
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
ok: false,
|
|
111
|
+
original_path: absPath,
|
|
112
|
+
staging_path: stagingDir,
|
|
113
|
+
backup_path: backupPath,
|
|
114
|
+
original_hash: originalHash,
|
|
115
|
+
new_hash: newHash,
|
|
116
|
+
validation_passed: check.validation_passed,
|
|
117
|
+
validation_output: check.validation_output,
|
|
118
|
+
test_passed: check.test_passed,
|
|
119
|
+
test_output: check.test_output,
|
|
120
|
+
error: "Validation/test failed — original restored",
|
|
121
|
+
restored: true,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
ok: true,
|
|
127
|
+
original_path: absPath,
|
|
128
|
+
staging_path: stagingDir,
|
|
129
|
+
backup_path: backupPath,
|
|
130
|
+
original_hash: originalHash,
|
|
131
|
+
new_hash: newHash,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
// ────────────────────────────────────────────────────────────────────
|
|
135
|
+
// Test runner
|
|
136
|
+
// ────────────────────────────────────────────────────────────────────
|
|
137
|
+
function detectTestCommand() {
|
|
138
|
+
const pkgJson = safeRead("package.json");
|
|
139
|
+
if (!isReadError(pkgJson)) {
|
|
140
|
+
try {
|
|
141
|
+
const pkg = JSON.parse(pkgJson);
|
|
142
|
+
if (pkg.scripts?.test)
|
|
143
|
+
return "npm test";
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
/* ignore */
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const acePkgJson = safeRead("ace-mcp-server/package.json");
|
|
150
|
+
if (!isReadError(acePkgJson)) {
|
|
151
|
+
try {
|
|
152
|
+
const pkg = JSON.parse(acePkgJson);
|
|
153
|
+
if (pkg.scripts?.test)
|
|
154
|
+
return "cd ace-mcp-server && npm test";
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
/* ignore */
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return "echo 'No test command detected' && exit 1";
|
|
161
|
+
}
|
|
162
|
+
export function runTestSuite(command) {
|
|
163
|
+
const cmd = command ?? detectTestCommand();
|
|
164
|
+
const start = Date.now();
|
|
165
|
+
const res = spawnSync("sh", ["-c", cmd], {
|
|
166
|
+
cwd: WORKSPACE_ROOT,
|
|
167
|
+
encoding: "utf-8",
|
|
168
|
+
timeout: 300_000,
|
|
169
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
ok: res.status === 0,
|
|
173
|
+
exit_code: res.status ?? -1,
|
|
174
|
+
output: ((res.stdout ?? "") + (res.stderr ?? "")).slice(0, 8000),
|
|
175
|
+
command: cmd,
|
|
176
|
+
duration_ms: Date.now() - start,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
// ────────────────────────────────────────────────────────────────────
|
|
180
|
+
// File diff
|
|
181
|
+
// ────────────────────────────────────────────────────────────────────
|
|
182
|
+
export function diffContents(original, updated) {
|
|
183
|
+
const origLines = original.split(/\r?\n/);
|
|
184
|
+
const newLines = updated.split(/\r?\n/);
|
|
185
|
+
// Simple line-based diff summary
|
|
186
|
+
const origSet = new Set(origLines);
|
|
187
|
+
const newSet = new Set(newLines);
|
|
188
|
+
let added = 0;
|
|
189
|
+
let removed = 0;
|
|
190
|
+
for (const line of newLines) {
|
|
191
|
+
if (!origSet.has(line))
|
|
192
|
+
added++;
|
|
193
|
+
}
|
|
194
|
+
for (const line of origLines) {
|
|
195
|
+
if (!newSet.has(line))
|
|
196
|
+
removed++;
|
|
197
|
+
}
|
|
198
|
+
const summaryLines = [];
|
|
199
|
+
summaryLines.push(`Lines: ${origLines.length} → ${newLines.length} (${added > 0 ? `+${added}` : "+0"}, ${removed > 0 ? `-${removed}` : "-0"})`);
|
|
200
|
+
// Show first 30 changed lines for context
|
|
201
|
+
const changes = [];
|
|
202
|
+
const maxContext = 30;
|
|
203
|
+
let shown = 0;
|
|
204
|
+
for (const line of origLines) {
|
|
205
|
+
if (!newSet.has(line) && shown < maxContext) {
|
|
206
|
+
changes.push(`- ${line}`);
|
|
207
|
+
shown++;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
for (const line of newLines) {
|
|
211
|
+
if (!origSet.has(line) && shown < maxContext) {
|
|
212
|
+
changes.push(`+ ${line}`);
|
|
213
|
+
shown++;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (changes.length > 0) {
|
|
217
|
+
summaryLines.push("", "Changes (sample):", ...changes);
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
has_diff: added > 0 || removed > 0,
|
|
221
|
+
original_lines: origLines.length,
|
|
222
|
+
new_lines: newLines.length,
|
|
223
|
+
added,
|
|
224
|
+
removed,
|
|
225
|
+
diff_summary: summaryLines.join("\n"),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
export function diffFiles(pathA, pathB) {
|
|
229
|
+
const contentA = safeRead(pathA);
|
|
230
|
+
const contentB = safeRead(pathB);
|
|
231
|
+
if (isReadError(contentA)) {
|
|
232
|
+
return {
|
|
233
|
+
has_diff: true,
|
|
234
|
+
original_lines: 0,
|
|
235
|
+
new_lines: 0,
|
|
236
|
+
added: 0,
|
|
237
|
+
removed: 0,
|
|
238
|
+
diff_summary: "",
|
|
239
|
+
error: `Cannot read file A: ${contentA}`,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
if (isReadError(contentB)) {
|
|
243
|
+
return {
|
|
244
|
+
has_diff: true,
|
|
245
|
+
original_lines: 0,
|
|
246
|
+
new_lines: 0,
|
|
247
|
+
added: 0,
|
|
248
|
+
removed: 0,
|
|
249
|
+
diff_summary: "",
|
|
250
|
+
error: `Cannot read file B: ${contentB}`,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
return diffContents(contentA, contentB);
|
|
254
|
+
}
|
|
255
|
+
//# sourceMappingURL=safe-edit.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type ValidationResult = {
|
|
2
|
+
ok: true;
|
|
3
|
+
schema: string;
|
|
4
|
+
} | {
|
|
5
|
+
ok: false;
|
|
6
|
+
schema: string;
|
|
7
|
+
errors: string[];
|
|
8
|
+
};
|
|
9
|
+
export type HandoffValidationMode = "auto" | "swarm" | "agent-state";
|
|
10
|
+
/**
|
|
11
|
+
* Event types that MUST carry provenance fields (autonomy gate – fail-closed).
|
|
12
|
+
* Exported so status-events.ts can use the same canonical set.
|
|
13
|
+
*/
|
|
14
|
+
export declare const PROVENANCE_CRITICAL_EVENT_TYPES: Set<string>;
|
|
15
|
+
export declare function validateSwarmHandoffPayload(payload: unknown): ValidationResult;
|
|
16
|
+
export declare function validateAgentStateHandoffPayload(payload: unknown): ValidationResult;
|
|
17
|
+
export declare function validateArtifactManifestPayload(payload: unknown): ValidationResult;
|
|
18
|
+
export declare function validateWorkspaceSessionRegistryPayload(payload: unknown): ValidationResult;
|
|
19
|
+
export declare function validateTrackerSnapshotPayload(payload: unknown): ValidationResult;
|
|
20
|
+
export declare function validateRuntimeToolSpecRegistryPayload(payload: unknown): ValidationResult;
|
|
21
|
+
export declare function validateRuntimeExecutorSessionRegistryPayload(payload: unknown): ValidationResult;
|
|
22
|
+
export declare function validateVericifyProcessPostLogPayload(payload: unknown): ValidationResult;
|
|
23
|
+
export declare function validateVericifyBridgeSnapshotPayload(payload: unknown): ValidationResult;
|
|
24
|
+
export declare function validateStatusEventPayload(payload: unknown, options?: {
|
|
25
|
+
provenanceCritical?: boolean;
|
|
26
|
+
}): ValidationResult;
|
|
27
|
+
export declare function validateStatusEventsNdjsonContent(content: string): ValidationResult;
|
|
28
|
+
export declare function validateTealConfigContent(content: string): ValidationResult;
|
|
29
|
+
export declare function validateProvenanceLogContent(content: string): ValidationResult;
|
|
30
|
+
export declare function validateHandoffPayload(payload: unknown, mode?: HandoffValidationMode): ValidationResult;
|
|
31
|
+
export interface HandoffLintResult {
|
|
32
|
+
ok: boolean;
|
|
33
|
+
warnings: string[];
|
|
34
|
+
errors: string[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Deep lint beyond schema validation:
|
|
38
|
+
* - Route legitimacy (from/to must be known roles)
|
|
39
|
+
* - Evidence freshness (context_pointers must reference existing files)
|
|
40
|
+
* - Acceptance criteria must be non-trivial
|
|
41
|
+
* - Required evidence array must be non-empty
|
|
42
|
+
*/
|
|
43
|
+
export declare function lintHandoffPayload(payload: unknown, workspaceRoot: string): HandoffLintResult;
|
|
44
|
+
//# sourceMappingURL=schemas.d.ts.map
|