@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,679 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File operation tool registrations + new safe-edit and diff tools.
|
|
3
|
+
*/
|
|
4
|
+
import { readdirSync } from "node:fs";
|
|
5
|
+
import { isAbsolute, relative } from "node:path";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { ACE_TASKS_ROOT_REL, normalizePathForValidation, safeRead, safeWrite, wsPath, WORKSPACE_ROOT, } from "./helpers.js";
|
|
8
|
+
import { looksLikeSwarmHandoffPath } from "./shared.js";
|
|
9
|
+
import { validateAgentStateHandoffPayload, validateArtifactManifestPayload, validateProvenanceLogContent, validateStatusEventsNdjsonContent, validateSwarmHandoffPayload, validateTealConfigContent, validateRuntimeExecutorSessionRegistryPayload, validateRuntimeToolSpecRegistryPayload, validateTrackerSnapshotPayload, validateVericifyBridgeSnapshotPayload, validateVericifyProcessPostLogPayload, validateWorkspaceSessionRegistryPayload, lintHandoffPayload, } from "./schemas.js";
|
|
10
|
+
import { syncTodoStateSafe } from "./todo-state.js";
|
|
11
|
+
import { validateRuntimeProfileContent } from "./runtime-profile.js";
|
|
12
|
+
import { shouldAutoRefreshKanbanForPath, refreshKanbanArtifacts, } from "./kanban.js";
|
|
13
|
+
import { appendRunLedgerEntrySafe } from "./run-ledger.js";
|
|
14
|
+
import { appendStatusEventSafe } from "./status-events.js";
|
|
15
|
+
import { safeEditFile, diffContents } from "./safe-edit.js";
|
|
16
|
+
export function registerFileTools(server) {
|
|
17
|
+
// ── Append-only artifact protection ───────────────────────────────
|
|
18
|
+
// These files must only grow; overwrites from the generic write tool
|
|
19
|
+
// would violate their immutable-log contract.
|
|
20
|
+
const APPEND_ONLY_PATHS = new Set([
|
|
21
|
+
"agent-state/EVIDENCE_LOG.md",
|
|
22
|
+
"agent-state/DECISIONS.md",
|
|
23
|
+
"agent-state/STATUS_EVENTS.ndjson",
|
|
24
|
+
"agent-state/run-ledger.json",
|
|
25
|
+
"agent-state/handoff-registry.json",
|
|
26
|
+
"agent-state/PROVENANCE_LOG.md",
|
|
27
|
+
]);
|
|
28
|
+
// ── Core file operations ──────────────────────────────────────────
|
|
29
|
+
server.tool("read_workspace_file", "Read any workspace file by relative path", {
|
|
30
|
+
path: z.string().describe("Relative path from workspace root"),
|
|
31
|
+
}, async ({ path }) => ({
|
|
32
|
+
content: [{ type: "text", text: safeRead(path) }],
|
|
33
|
+
}));
|
|
34
|
+
server.tool("write_workspace_file", "Write or update a workspace file", {
|
|
35
|
+
path: z.string().describe("Relative path from workspace root"),
|
|
36
|
+
content: z.string().describe("File content"),
|
|
37
|
+
}, async ({ path, content }) => {
|
|
38
|
+
const normalizedPath = normalizePathForValidation(path);
|
|
39
|
+
const validationNotes = [];
|
|
40
|
+
// ── Append-only guard ───────────────────────────────────────────
|
|
41
|
+
if (APPEND_ONLY_PATHS.has(normalizedPath)) {
|
|
42
|
+
const existing = safeRead(path);
|
|
43
|
+
const fileExists = !existing.startsWith("[FILE NOT FOUND]") && !existing.startsWith("[ACCESS DENIED]");
|
|
44
|
+
if (fileExists) {
|
|
45
|
+
// Only allow writes that are strict supersets (append).
|
|
46
|
+
const isAppend = content.startsWith(existing.trimEnd());
|
|
47
|
+
if (!isAppend) {
|
|
48
|
+
return {
|
|
49
|
+
content: [
|
|
50
|
+
{
|
|
51
|
+
type: "text",
|
|
52
|
+
text: `❌ ${normalizedPath} is append-only. Use the dedicated append API (appendStatusEvent, appendRunLedgerEntry, etc.) instead of overwriting via write_workspace_file.`,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Enforce schema contracts on key execution artifacts.
|
|
60
|
+
if (normalizedPath === "agent-state/HANDOFF.json") {
|
|
61
|
+
let parsed;
|
|
62
|
+
try {
|
|
63
|
+
parsed = JSON.parse(content);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return {
|
|
67
|
+
content: [
|
|
68
|
+
{
|
|
69
|
+
type: "text",
|
|
70
|
+
text: "❌ agent-state/HANDOFF.json must be valid JSON before write.",
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const validation = validateAgentStateHandoffPayload(parsed);
|
|
76
|
+
if (!validation.ok) {
|
|
77
|
+
return {
|
|
78
|
+
content: [
|
|
79
|
+
{
|
|
80
|
+
type: "text",
|
|
81
|
+
text: [
|
|
82
|
+
"❌ agent-state/HANDOFF.json failed schema validation.",
|
|
83
|
+
`Schema: ${validation.schema}`,
|
|
84
|
+
...validation.errors.map((error) => `- ${error}`),
|
|
85
|
+
].join("\n"),
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
validationNotes.push(`validated ${validation.schema}`);
|
|
91
|
+
}
|
|
92
|
+
else if (normalizedPath.startsWith("agent-state/HANDOFF_HISTORY/") &&
|
|
93
|
+
normalizedPath.endsWith(".json")) {
|
|
94
|
+
let parsed;
|
|
95
|
+
try {
|
|
96
|
+
parsed = JSON.parse(content);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return {
|
|
100
|
+
content: [
|
|
101
|
+
{
|
|
102
|
+
type: "text",
|
|
103
|
+
text: "❌ HANDOFF history entries must be valid JSON before write.",
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const validation = validateAgentStateHandoffPayload(parsed);
|
|
109
|
+
if (!validation.ok) {
|
|
110
|
+
return {
|
|
111
|
+
content: [
|
|
112
|
+
{
|
|
113
|
+
type: "text",
|
|
114
|
+
text: [
|
|
115
|
+
"❌ HANDOFF history payload failed schema validation.",
|
|
116
|
+
`Schema: ${validation.schema}`,
|
|
117
|
+
...validation.errors.map((error) => `- ${error}`),
|
|
118
|
+
].join("\n"),
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
validationNotes.push(`validated ${validation.schema}`);
|
|
124
|
+
}
|
|
125
|
+
else if (normalizedPath === "agent-state/STATUS_EVENTS.ndjson") {
|
|
126
|
+
const validation = validateStatusEventsNdjsonContent(content);
|
|
127
|
+
if (!validation.ok) {
|
|
128
|
+
return {
|
|
129
|
+
content: [
|
|
130
|
+
{
|
|
131
|
+
type: "text",
|
|
132
|
+
text: [
|
|
133
|
+
"❌ agent-state/STATUS_EVENTS.ndjson failed schema validation.",
|
|
134
|
+
`Schema: ${validation.schema}`,
|
|
135
|
+
...validation.errors.map((error) => `- ${error}`),
|
|
136
|
+
].join("\n"),
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
validationNotes.push(`validated ${validation.schema}`);
|
|
142
|
+
}
|
|
143
|
+
else if (normalizedPath === "agent-state/TEAL_CONFIG.md") {
|
|
144
|
+
const validation = validateTealConfigContent(content);
|
|
145
|
+
if (!validation.ok) {
|
|
146
|
+
return {
|
|
147
|
+
content: [
|
|
148
|
+
{
|
|
149
|
+
type: "text",
|
|
150
|
+
text: [
|
|
151
|
+
"❌ agent-state/TEAL_CONFIG.md failed validation.",
|
|
152
|
+
`Schema: ${validation.schema}`,
|
|
153
|
+
...validation.errors.map((error) => `- ${error}`),
|
|
154
|
+
].join("\n"),
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
validationNotes.push(`validated ${validation.schema}`);
|
|
160
|
+
}
|
|
161
|
+
else if (normalizedPath === "agent-state/PROVENANCE_LOG.md") {
|
|
162
|
+
const validation = validateProvenanceLogContent(content);
|
|
163
|
+
if (!validation.ok) {
|
|
164
|
+
return {
|
|
165
|
+
content: [
|
|
166
|
+
{
|
|
167
|
+
type: "text",
|
|
168
|
+
text: [
|
|
169
|
+
"❌ agent-state/PROVENANCE_LOG.md failed validation.",
|
|
170
|
+
`Schema: ${validation.schema}`,
|
|
171
|
+
...validation.errors.map((error) => `- ${error}`),
|
|
172
|
+
].join("\n"),
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
validationNotes.push(`validated ${validation.schema}`);
|
|
178
|
+
}
|
|
179
|
+
else if (normalizedPath === "agent-state/ACE_WORKFLOW.md") {
|
|
180
|
+
const validation = validateRuntimeProfileContent(content);
|
|
181
|
+
if (!validation.ok) {
|
|
182
|
+
return {
|
|
183
|
+
content: [
|
|
184
|
+
{
|
|
185
|
+
type: "text",
|
|
186
|
+
text: [
|
|
187
|
+
"❌ agent-state/ACE_WORKFLOW.md failed validation.",
|
|
188
|
+
`Schema: ${validation.schema}`,
|
|
189
|
+
...validation.errors.map((error) => `- ${error}`),
|
|
190
|
+
].join("\n"),
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
validationNotes.push(`validated ${validation.schema}`);
|
|
196
|
+
}
|
|
197
|
+
else if (normalizedPath === "agent-state/runtime-workspaces.json") {
|
|
198
|
+
let parsed;
|
|
199
|
+
try {
|
|
200
|
+
parsed = JSON.parse(content);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return {
|
|
204
|
+
content: [
|
|
205
|
+
{
|
|
206
|
+
type: "text",
|
|
207
|
+
text: "❌ agent-state/runtime-workspaces.json must be valid JSON before write.",
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const validation = validateWorkspaceSessionRegistryPayload(parsed);
|
|
213
|
+
if (!validation.ok) {
|
|
214
|
+
return {
|
|
215
|
+
content: [
|
|
216
|
+
{
|
|
217
|
+
type: "text",
|
|
218
|
+
text: [
|
|
219
|
+
"❌ agent-state/runtime-workspaces.json failed validation.",
|
|
220
|
+
`Schema: ${validation.schema}`,
|
|
221
|
+
...validation.errors.map((error) => `- ${error}`),
|
|
222
|
+
].join("\n"),
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
validationNotes.push(`validated ${validation.schema}`);
|
|
228
|
+
}
|
|
229
|
+
else if (normalizedPath === "agent-state/tracker-snapshot.json") {
|
|
230
|
+
let parsed;
|
|
231
|
+
try {
|
|
232
|
+
parsed = JSON.parse(content);
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
return {
|
|
236
|
+
content: [
|
|
237
|
+
{
|
|
238
|
+
type: "text",
|
|
239
|
+
text: "❌ agent-state/tracker-snapshot.json must be valid JSON before write.",
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
const validation = validateTrackerSnapshotPayload(parsed);
|
|
245
|
+
if (!validation.ok) {
|
|
246
|
+
return {
|
|
247
|
+
content: [
|
|
248
|
+
{
|
|
249
|
+
type: "text",
|
|
250
|
+
text: [
|
|
251
|
+
"❌ agent-state/tracker-snapshot.json failed validation.",
|
|
252
|
+
`Schema: ${validation.schema}`,
|
|
253
|
+
...validation.errors.map((error) => `- ${error}`),
|
|
254
|
+
].join("\n"),
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
validationNotes.push(`validated ${validation.schema}`);
|
|
260
|
+
}
|
|
261
|
+
else if (normalizedPath === "agent-state/runtime-tool-specs.json") {
|
|
262
|
+
let parsed;
|
|
263
|
+
try {
|
|
264
|
+
parsed = JSON.parse(content);
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return {
|
|
268
|
+
content: [
|
|
269
|
+
{
|
|
270
|
+
type: "text",
|
|
271
|
+
text: "❌ agent-state/runtime-tool-specs.json must be valid JSON before write.",
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const validation = validateRuntimeToolSpecRegistryPayload(parsed);
|
|
277
|
+
if (!validation.ok) {
|
|
278
|
+
return {
|
|
279
|
+
content: [
|
|
280
|
+
{
|
|
281
|
+
type: "text",
|
|
282
|
+
text: [
|
|
283
|
+
"❌ agent-state/runtime-tool-specs.json failed validation.",
|
|
284
|
+
`Schema: ${validation.schema}`,
|
|
285
|
+
...validation.errors.map((error) => `- ${error}`),
|
|
286
|
+
].join("\n"),
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
validationNotes.push(`validated ${validation.schema}`);
|
|
292
|
+
}
|
|
293
|
+
else if (normalizedPath === "agent-state/runtime-executor-sessions.json") {
|
|
294
|
+
let parsed;
|
|
295
|
+
try {
|
|
296
|
+
parsed = JSON.parse(content);
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
return {
|
|
300
|
+
content: [
|
|
301
|
+
{
|
|
302
|
+
type: "text",
|
|
303
|
+
text: "❌ agent-state/runtime-executor-sessions.json must be valid JSON before write.",
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
const validation = validateRuntimeExecutorSessionRegistryPayload(parsed);
|
|
309
|
+
if (!validation.ok) {
|
|
310
|
+
return {
|
|
311
|
+
content: [
|
|
312
|
+
{
|
|
313
|
+
type: "text",
|
|
314
|
+
text: [
|
|
315
|
+
"❌ agent-state/runtime-executor-sessions.json failed validation.",
|
|
316
|
+
`Schema: ${validation.schema}`,
|
|
317
|
+
...validation.errors.map((error) => `- ${error}`),
|
|
318
|
+
].join("\n"),
|
|
319
|
+
},
|
|
320
|
+
],
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
validationNotes.push(`validated ${validation.schema}`);
|
|
324
|
+
}
|
|
325
|
+
else if (normalizedPath === "agent-state/vericify/ace-bridge.json") {
|
|
326
|
+
let parsed;
|
|
327
|
+
try {
|
|
328
|
+
parsed = JSON.parse(content);
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
return {
|
|
332
|
+
content: [
|
|
333
|
+
{
|
|
334
|
+
type: "text",
|
|
335
|
+
text: "❌ agent-state/vericify/ace-bridge.json must be valid JSON before write.",
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
const validation = validateVericifyBridgeSnapshotPayload(parsed);
|
|
341
|
+
if (!validation.ok) {
|
|
342
|
+
return {
|
|
343
|
+
content: [
|
|
344
|
+
{
|
|
345
|
+
type: "text",
|
|
346
|
+
text: [
|
|
347
|
+
"❌ agent-state/vericify/ace-bridge.json failed validation.",
|
|
348
|
+
`Schema: ${validation.schema}`,
|
|
349
|
+
...validation.errors.map((error) => `- ${error}`),
|
|
350
|
+
].join("\n"),
|
|
351
|
+
},
|
|
352
|
+
],
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
validationNotes.push(`validated ${validation.schema}`);
|
|
356
|
+
}
|
|
357
|
+
else if (normalizedPath === "agent-state/vericify/process-posts.json") {
|
|
358
|
+
let parsed;
|
|
359
|
+
try {
|
|
360
|
+
parsed = JSON.parse(content);
|
|
361
|
+
}
|
|
362
|
+
catch {
|
|
363
|
+
return {
|
|
364
|
+
content: [
|
|
365
|
+
{
|
|
366
|
+
type: "text",
|
|
367
|
+
text: "❌ agent-state/vericify/process-posts.json must be valid JSON before write.",
|
|
368
|
+
},
|
|
369
|
+
],
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
const validation = validateVericifyProcessPostLogPayload(parsed);
|
|
373
|
+
if (!validation.ok) {
|
|
374
|
+
return {
|
|
375
|
+
content: [
|
|
376
|
+
{
|
|
377
|
+
type: "text",
|
|
378
|
+
text: [
|
|
379
|
+
"❌ agent-state/vericify/process-posts.json failed validation.",
|
|
380
|
+
`Schema: ${validation.schema}`,
|
|
381
|
+
...validation.errors.map((error) => `- ${error}`),
|
|
382
|
+
].join("\n"),
|
|
383
|
+
},
|
|
384
|
+
],
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
validationNotes.push(`validated ${validation.schema}`);
|
|
388
|
+
}
|
|
389
|
+
else if (normalizedPath.endsWith("/ARTIFACT_MANIFEST.json") ||
|
|
390
|
+
normalizedPath === "ARTIFACT_MANIFEST.json") {
|
|
391
|
+
let parsed;
|
|
392
|
+
try {
|
|
393
|
+
parsed = JSON.parse(content);
|
|
394
|
+
}
|
|
395
|
+
catch {
|
|
396
|
+
return {
|
|
397
|
+
content: [
|
|
398
|
+
{
|
|
399
|
+
type: "text",
|
|
400
|
+
text: "❌ ARTIFACT_MANIFEST.json must be valid JSON before write.",
|
|
401
|
+
},
|
|
402
|
+
],
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
const validation = validateArtifactManifestPayload(parsed);
|
|
406
|
+
if (!validation.ok) {
|
|
407
|
+
return {
|
|
408
|
+
content: [
|
|
409
|
+
{
|
|
410
|
+
type: "text",
|
|
411
|
+
text: [
|
|
412
|
+
"❌ ARTIFACT_MANIFEST.json failed schema validation.",
|
|
413
|
+
`Schema: ${validation.schema}`,
|
|
414
|
+
...validation.errors.map((error) => `- ${error}`),
|
|
415
|
+
].join("\n"),
|
|
416
|
+
},
|
|
417
|
+
],
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
validationNotes.push(`validated ${validation.schema}`);
|
|
421
|
+
}
|
|
422
|
+
else if (looksLikeSwarmHandoffPath(normalizedPath)) {
|
|
423
|
+
let parsed;
|
|
424
|
+
try {
|
|
425
|
+
parsed = JSON.parse(content);
|
|
426
|
+
}
|
|
427
|
+
catch {
|
|
428
|
+
return {
|
|
429
|
+
content: [
|
|
430
|
+
{
|
|
431
|
+
type: "text",
|
|
432
|
+
text: "❌ SWARM_HANDOFF payloads must be valid JSON before write.",
|
|
433
|
+
},
|
|
434
|
+
],
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
const validation = validateSwarmHandoffPayload(parsed);
|
|
438
|
+
if (!validation.ok) {
|
|
439
|
+
return {
|
|
440
|
+
content: [
|
|
441
|
+
{
|
|
442
|
+
type: "text",
|
|
443
|
+
text: [
|
|
444
|
+
"❌ SWARM_HANDOFF payload failed schema validation.",
|
|
445
|
+
`Schema: ${validation.schema}`,
|
|
446
|
+
...validation.errors.map((error) => `- ${error}`),
|
|
447
|
+
].join("\n"),
|
|
448
|
+
},
|
|
449
|
+
],
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
validationNotes.push(`validated ${validation.schema}`);
|
|
453
|
+
// Deep lint: route legitimacy + evidence existence
|
|
454
|
+
const lint = lintHandoffPayload(parsed, WORKSPACE_ROOT);
|
|
455
|
+
if (!lint.ok) {
|
|
456
|
+
return {
|
|
457
|
+
content: [
|
|
458
|
+
{
|
|
459
|
+
type: "text",
|
|
460
|
+
text: [
|
|
461
|
+
"❌ SWARM_HANDOFF payload failed deep lint checks.",
|
|
462
|
+
...lint.errors.map((e) => `- ERROR: ${e}`),
|
|
463
|
+
...lint.warnings.map((w) => `- WARN: ${w}`),
|
|
464
|
+
].join("\n"),
|
|
465
|
+
},
|
|
466
|
+
],
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
if (lint.warnings.length > 0) {
|
|
470
|
+
validationNotes.push(`lint warnings: ${lint.warnings.join("; ")}`);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
const abs = safeWrite(path, content);
|
|
474
|
+
let todoStateSuffix = "";
|
|
475
|
+
if (normalizedPath === `${ACE_TASKS_ROOT_REL}/todo.md`) {
|
|
476
|
+
const synced = await syncTodoStateSafe(content);
|
|
477
|
+
todoStateSuffix = `\nTODO state synced: ${synced.path}`;
|
|
478
|
+
}
|
|
479
|
+
let kanbanSuffix = "";
|
|
480
|
+
const shouldRefreshKanban = shouldAutoRefreshKanbanForPath(normalizedPath);
|
|
481
|
+
if (shouldRefreshKanban) {
|
|
482
|
+
const kanban = refreshKanbanArtifacts(`tool:write_workspace_file:${normalizedPath}`);
|
|
483
|
+
kanbanSuffix = `\nKanban updated: ${kanban.html_path}\nKanban counts: backlog=${kanban.counts.backlog}, blocked=${kanban.counts.blocked}, in_progress=${kanban.counts.in_progress}, gated=${kanban.counts.gated}, done=${kanban.counts.done}`;
|
|
484
|
+
}
|
|
485
|
+
const runLedger = await appendRunLedgerEntrySafe({
|
|
486
|
+
tool: "write_workspace_file",
|
|
487
|
+
category: shouldRefreshKanban ? "major_update" : "info",
|
|
488
|
+
message: `Wrote workspace file ${normalizedPath}`,
|
|
489
|
+
artifacts: [normalizedPath],
|
|
490
|
+
metadata: {
|
|
491
|
+
validation_notes: validationNotes,
|
|
492
|
+
auto_refreshed_kanban: shouldRefreshKanban,
|
|
493
|
+
bytes: content.length,
|
|
494
|
+
},
|
|
495
|
+
});
|
|
496
|
+
const suffix = validationNotes.length > 0
|
|
497
|
+
? `\nSchema checks: ${validationNotes.join(", ")}`
|
|
498
|
+
: "";
|
|
499
|
+
return {
|
|
500
|
+
content: [
|
|
501
|
+
{
|
|
502
|
+
type: "text",
|
|
503
|
+
text: `✅ Written: ${abs}${suffix}${todoStateSuffix}\nRun ledger: ${runLedger.path} (${runLedger.entry.id})${kanbanSuffix}`,
|
|
504
|
+
},
|
|
505
|
+
],
|
|
506
|
+
};
|
|
507
|
+
});
|
|
508
|
+
server.tool("list_workspace", "List files/directories in a workspace path", {
|
|
509
|
+
path: z
|
|
510
|
+
.string()
|
|
511
|
+
.optional()
|
|
512
|
+
.describe("Relative path (default: workspace root)"),
|
|
513
|
+
}, async ({ path }) => {
|
|
514
|
+
const dir = path ? wsPath(path) : WORKSPACE_ROOT;
|
|
515
|
+
const rel = relative(WORKSPACE_ROOT, dir);
|
|
516
|
+
if (rel.startsWith("..") || isAbsolute(rel)) {
|
|
517
|
+
return {
|
|
518
|
+
content: [
|
|
519
|
+
{
|
|
520
|
+
type: "text",
|
|
521
|
+
text: `❌ Access denied: path escapes workspace root (${dir})`,
|
|
522
|
+
},
|
|
523
|
+
],
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
try {
|
|
527
|
+
const entries = readdirSync(dir, { withFileTypes: true })
|
|
528
|
+
.map((entry) => `${entry.isDirectory() ? "[DIR]" : "[FILE]"} ${entry.name}`)
|
|
529
|
+
.join("\n");
|
|
530
|
+
return {
|
|
531
|
+
content: [{ type: "text", text: `# ${dir}\n\n${entries}` }],
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
catch (err) {
|
|
535
|
+
return {
|
|
536
|
+
content: [
|
|
537
|
+
{
|
|
538
|
+
type: "text",
|
|
539
|
+
text: `❌ Could not list ${dir}\n${String(err)}`,
|
|
540
|
+
},
|
|
541
|
+
],
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
// ── Safe-edit (new P0 tool) ───────────────────────────────────────
|
|
546
|
+
server.tool("safe_edit_file", "Edit a file using copy→validate→swap pattern. Automatically rolls back if validation or tests fail.", {
|
|
547
|
+
path: z.string().describe("Workspace-relative file path to edit"),
|
|
548
|
+
content: z.string().describe("New file content"),
|
|
549
|
+
validation_command: z
|
|
550
|
+
.string()
|
|
551
|
+
.optional()
|
|
552
|
+
.describe("Shell command to validate (e.g. 'npx tsc --noEmit')"),
|
|
553
|
+
test_command: z
|
|
554
|
+
.string()
|
|
555
|
+
.optional()
|
|
556
|
+
.describe("Shell command for tests (e.g. 'npm test')"),
|
|
557
|
+
backup: z
|
|
558
|
+
.boolean()
|
|
559
|
+
.optional()
|
|
560
|
+
.describe("Keep .ace-backup copy (default: true)"),
|
|
561
|
+
}, async ({ path, content, validation_command, test_command, backup }) => {
|
|
562
|
+
const result = safeEditFile({
|
|
563
|
+
path,
|
|
564
|
+
content,
|
|
565
|
+
validation_command,
|
|
566
|
+
test_command,
|
|
567
|
+
backup,
|
|
568
|
+
});
|
|
569
|
+
const ledger = await appendRunLedgerEntrySafe({
|
|
570
|
+
tool: "safe_edit_file",
|
|
571
|
+
category: result.ok ? "major_update" : "regression",
|
|
572
|
+
message: result.ok
|
|
573
|
+
? `Safe-edited ${path}`
|
|
574
|
+
: `Safe-edit FAILED for ${path} — restored original`,
|
|
575
|
+
artifacts: [path],
|
|
576
|
+
metadata: {
|
|
577
|
+
ok: result.ok,
|
|
578
|
+
original_hash: result.original_hash,
|
|
579
|
+
new_hash: result.new_hash,
|
|
580
|
+
restored: result.restored,
|
|
581
|
+
validation_passed: result.validation_passed,
|
|
582
|
+
test_passed: result.test_passed,
|
|
583
|
+
},
|
|
584
|
+
});
|
|
585
|
+
if (result.ok) {
|
|
586
|
+
await appendStatusEventSafe({
|
|
587
|
+
source_module: "capability-safety",
|
|
588
|
+
event_type: "SAFE_EDIT_COMPLETED",
|
|
589
|
+
status: "done",
|
|
590
|
+
summary: `Safe-edited ${path}`,
|
|
591
|
+
objective_id: "safe-edit",
|
|
592
|
+
payload: {
|
|
593
|
+
original_hash: result.original_hash,
|
|
594
|
+
new_hash: result.new_hash,
|
|
595
|
+
evidence_ref: path,
|
|
596
|
+
},
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
await appendStatusEventSafe({
|
|
601
|
+
source_module: "capability-safety",
|
|
602
|
+
event_type: "SAFE_EDIT_FAILED",
|
|
603
|
+
status: "fail",
|
|
604
|
+
summary: `Safe-edit rolled back for ${path}: ${result.error}`,
|
|
605
|
+
objective_id: "safe-edit",
|
|
606
|
+
payload: {
|
|
607
|
+
evidence_ref: path,
|
|
608
|
+
},
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
return {
|
|
612
|
+
content: [
|
|
613
|
+
{
|
|
614
|
+
type: "text",
|
|
615
|
+
text: [
|
|
616
|
+
result.ok ? "✅ Safe-edit succeeded" : "❌ Safe-edit FAILED — original restored",
|
|
617
|
+
`Path: ${result.original_path}`,
|
|
618
|
+
`Hash: ${result.original_hash} → ${result.new_hash}`,
|
|
619
|
+
result.backup_path ? `Backup: ${result.backup_path}` : "",
|
|
620
|
+
result.validation_passed !== undefined
|
|
621
|
+
? `Validation: ${result.validation_passed ? "passed" : "FAILED"}`
|
|
622
|
+
: "",
|
|
623
|
+
result.validation_output
|
|
624
|
+
? `Validation output:\n${result.validation_output.slice(0, 2000)}`
|
|
625
|
+
: "",
|
|
626
|
+
result.test_passed !== undefined
|
|
627
|
+
? `Tests: ${result.test_passed ? "passed" : "FAILED"}`
|
|
628
|
+
: "",
|
|
629
|
+
result.test_output
|
|
630
|
+
? `Test output:\n${result.test_output.slice(0, 2000)}`
|
|
631
|
+
: "",
|
|
632
|
+
result.error ? `Error: ${result.error}` : "",
|
|
633
|
+
`Run ledger: ${ledger.path} (${ledger.entry.id})`,
|
|
634
|
+
]
|
|
635
|
+
.filter(Boolean)
|
|
636
|
+
.join("\n"),
|
|
637
|
+
},
|
|
638
|
+
],
|
|
639
|
+
};
|
|
640
|
+
});
|
|
641
|
+
// ── Diff (new P2 tool) ────────────────────────────────────────────
|
|
642
|
+
server.tool("diff_files", "Compute a line-based diff between two file contents or file paths", {
|
|
643
|
+
original: z.string().describe("Original content or workspace-relative file path"),
|
|
644
|
+
modified: z.string().describe("Modified content or workspace-relative file path"),
|
|
645
|
+
is_path: z
|
|
646
|
+
.boolean()
|
|
647
|
+
.optional()
|
|
648
|
+
.describe("If true, treat original/modified as file paths and read their contents"),
|
|
649
|
+
}, async ({ original, modified, is_path }) => {
|
|
650
|
+
let origContent = original;
|
|
651
|
+
let modContent = modified;
|
|
652
|
+
if (is_path) {
|
|
653
|
+
origContent = safeRead(original);
|
|
654
|
+
modContent = safeRead(modified);
|
|
655
|
+
}
|
|
656
|
+
const diff = diffContents(origContent, modContent);
|
|
657
|
+
return {
|
|
658
|
+
content: [
|
|
659
|
+
{
|
|
660
|
+
type: "text",
|
|
661
|
+
text: [
|
|
662
|
+
"# Diff Result",
|
|
663
|
+
"",
|
|
664
|
+
`Has differences: ${diff.has_diff}`,
|
|
665
|
+
`Original lines: ${diff.original_lines}`,
|
|
666
|
+
`Modified lines: ${diff.new_lines}`,
|
|
667
|
+
`Added: +${diff.added}`,
|
|
668
|
+
`Removed: -${diff.removed}`,
|
|
669
|
+
"",
|
|
670
|
+
"```diff",
|
|
671
|
+
diff.diff_summary,
|
|
672
|
+
"```",
|
|
673
|
+
].join("\n"),
|
|
674
|
+
},
|
|
675
|
+
],
|
|
676
|
+
};
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
//# sourceMappingURL=tools-files.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework tool registrations: bootstrap, status, config, routing,
|
|
3
|
+
* plus new run_tests and validate_framework tools.
|
|
4
|
+
*/
|
|
5
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
|
+
export declare function registerFrameworkTools(server: McpServer): void;
|
|
7
|
+
//# sourceMappingURL=tools-framework.d.ts.map
|