agentera 3.0.0-dev.2 → 3.0.0-dev.20
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/README.md +65 -6
- package/bundle/.agentera-npx-bundle.json +1 -1
- package/bundle/.codex-plugin/plugin.json +92 -0
- package/bundle/.cursor/agents/agentera.md +7 -0
- package/bundle/.cursor/hooks.json +32 -0
- package/bundle/.cursor-plugin/plugin.json +34 -0
- package/bundle/.github/hooks/postToolUse.json +9 -0
- package/bundle/.github/hooks/preToolUse.json +8 -0
- package/bundle/.github/hooks/sessionEnd.json +8 -0
- package/bundle/.github/hooks/sessionStart.json +8 -0
- package/bundle/.github/plugin/plugin.json +7 -0
- package/bundle/.opencode/agents/agentera.md +12 -0
- package/bundle/.opencode/commands/agentera.md +5 -0
- package/bundle/.opencode/package.json +31 -0
- package/bundle/.opencode/plugins/agentera.js +820 -0
- package/bundle/CHANGELOG.md +1108 -0
- package/bundle/DESIGN.md +233 -0
- package/bundle/LICENSE +201 -0
- package/bundle/README.md +141 -0
- package/bundle/UPGRADE.md +227 -0
- package/bundle/agents/openai.yaml +87 -0
- package/bundle/extract-corpus-parity.json +21 -0
- package/bundle/hooks/codex-hooks.json +31 -0
- package/bundle/hooks/codex-plugin-hooks.json +31 -0
- package/bundle/plugin.json +13 -0
- package/bundle/references/adapters/cursor.md +53 -42
- package/bundle/references/adapters/opencode.md +46 -47
- package/bundle/references/adapters/package-manifest-interface-model.yaml +32 -43
- package/bundle/references/adapters/package-registry.yaml +19 -53
- package/bundle/references/adapters/package-surface-characterization.md +61 -48
- package/bundle/references/adapters/runtime-adapter-characterization.md +44 -79
- package/bundle/references/adapters/runtime-adapter-registry.yaml +21 -182
- package/bundle/references/adapters/runtime-feature-parity.md +114 -174
- package/bundle/references/adapters/runtime-lifecycle-adapters.yaml +288 -0
- package/bundle/references/adapters/runtime-lifecycle-authority.yaml +90 -0
- package/bundle/references/adapters/runtime-lifecycle-operation-contract.yaml +84 -0
- package/bundle/references/adapters/runtime-retired-resources.yaml +33 -0
- package/bundle/references/analysis/benchmark.md +6 -6
- package/bundle/references/analysis/startup-measurement-contract.yaml +37 -26
- package/bundle/references/artifacts/artifact-registry-interface-model.yaml +6 -5
- package/bundle/references/cli/agent-ready-state-contract.yaml +26 -23
- package/bundle/references/cli/app-lifecycle-vocabulary.yaml +4 -4
- package/bundle/references/cli/audience-namespace-cli-migration.yaml +40 -26
- package/bundle/references/cli/bundle-skill-vocabulary.yaml +4 -32
- package/bundle/references/cli/capability-instruction-contract.yaml +98 -57
- package/bundle/references/cli/capability-instruction-structure.md +144 -0
- package/bundle/references/cli/capability-tool-classification.yaml +12 -12
- package/bundle/references/cli/coexistence-probe.yaml +13 -0
- package/bundle/references/cli/parity-expected-actual-template.md +30 -0
- package/bundle/references/cli/routing-execution-vocabulary.yaml +12 -12
- package/bundle/references/cli/routing-model.md +94 -0
- package/bundle/references/cli/single-name-protocol.yaml +42 -0
- package/bundle/references/cli/trigger-schema-enrichment.md +136 -0
- package/bundle/references/cli/update-channels.yaml +43 -7
- package/bundle/references/cli/upgrade-repair-wording.md +45 -0
- package/bundle/references/cli/v3-handoff-manifest.schema.yaml +98 -0
- package/bundle/references/cli/vocabulary-index.yaml +20 -15
- package/bundle/references/cli/vocabulary.md +342 -326
- package/bundle/references/meta/documentation-inventory.md +9 -3
- package/bundle/registry.json +14 -14
- package/bundle/skills/agentera/SKILL.md +136 -408
- package/bundle/skills/agentera/agents/audit.toml +6 -0
- package/bundle/skills/agentera/agents/build.toml +6 -0
- package/bundle/skills/agentera/agents/design.toml +6 -0
- package/bundle/skills/agentera/agents/discuss.toml +6 -0
- package/bundle/skills/agentera/agents/document.toml +6 -0
- package/bundle/skills/agentera/agents/optimize.toml +6 -0
- package/bundle/skills/agentera/agents/orchestrate.toml +6 -0
- package/bundle/skills/agentera/agents/plan.toml +6 -0
- package/bundle/skills/agentera/agents/profile.toml +6 -0
- package/bundle/skills/agentera/agents/research.toml +6 -0
- package/bundle/skills/agentera/agents/status.toml +6 -0
- package/bundle/skills/agentera/agents/vision.toml +6 -0
- package/bundle/skills/agentera/capabilities/{inspektera → audit}/schemas/artifacts.yaml +10 -10
- package/bundle/skills/agentera/capabilities/{inspektera → audit}/schemas/exit.yaml +2 -2
- package/bundle/skills/agentera/capabilities/{inspektera → audit}/schemas/triggers.yaml +15 -6
- package/bundle/skills/agentera/capabilities/{inspektera → audit}/schemas/validation.yaml +13 -12
- package/bundle/skills/agentera/capabilities/{realisera → build}/schemas/artifacts.yaml +12 -12
- package/bundle/skills/agentera/capabilities/{realisera → build}/schemas/exit.yaml +3 -3
- package/bundle/skills/agentera/capabilities/{realisera → build}/schemas/triggers.yaml +13 -3
- package/bundle/skills/agentera/capabilities/{realisera → build}/schemas/validation.yaml +11 -11
- package/bundle/skills/agentera/capabilities/{visualisera → design}/schemas/artifacts.yaml +6 -6
- package/bundle/skills/agentera/capabilities/{visualisera → design}/schemas/exit.yaml +5 -5
- package/bundle/skills/agentera/capabilities/{visualisera → design}/schemas/triggers.yaml +15 -3
- package/bundle/skills/agentera/capabilities/{visualisera → design}/schemas/validation.yaml +7 -7
- package/bundle/skills/agentera/capabilities/{resonera → discuss}/schemas/artifacts.yaml +12 -11
- package/bundle/skills/agentera/capabilities/{resonera → discuss}/schemas/exit.yaml +2 -2
- package/bundle/skills/agentera/capabilities/{resonera → discuss}/schemas/triggers.yaml +11 -3
- package/bundle/skills/agentera/capabilities/{resonera → discuss}/schemas/validation.yaml +9 -8
- package/bundle/skills/agentera/capabilities/{dokumentera → document}/schemas/artifacts.yaml +10 -10
- package/bundle/skills/agentera/capabilities/{dokumentera → document}/schemas/triggers.yaml +14 -4
- package/bundle/skills/agentera/capabilities/{dokumentera → document}/schemas/validation.yaml +8 -8
- package/bundle/skills/agentera/capabilities/{optimera → optimize}/schemas/artifacts.yaml +9 -9
- package/bundle/skills/agentera/capabilities/{optimera → optimize}/schemas/exit.yaml +2 -2
- package/bundle/skills/agentera/capabilities/{optimera → optimize}/schemas/triggers.yaml +11 -3
- package/bundle/skills/agentera/capabilities/{optimera → optimize}/schemas/validation.yaml +9 -9
- package/bundle/skills/agentera/capabilities/{orkestrera → orchestrate}/schemas/artifacts.yaml +12 -11
- package/bundle/skills/agentera/capabilities/{orkestrera → orchestrate}/schemas/exit.yaml +7 -6
- package/bundle/skills/agentera/capabilities/{orkestrera → orchestrate}/schemas/triggers.yaml +16 -3
- package/bundle/skills/agentera/capabilities/orchestrate/schemas/validation.yaml +120 -0
- package/bundle/skills/agentera/capabilities/plan/schemas/artifacts.yaml +63 -0
- package/bundle/skills/agentera/capabilities/{planera → plan}/schemas/exit.yaml +2 -2
- package/bundle/skills/agentera/capabilities/{planera → plan}/schemas/triggers.yaml +15 -3
- package/bundle/skills/agentera/capabilities/plan/schemas/validation.yaml +89 -0
- package/bundle/skills/agentera/capabilities/{profilera → profile}/schemas/artifacts.yaml +2 -2
- package/bundle/skills/agentera/capabilities/{profilera → profile}/schemas/exit.yaml +3 -3
- package/bundle/skills/agentera/capabilities/{profilera → profile}/schemas/triggers.yaml +7 -3
- package/bundle/skills/agentera/capabilities/{profilera → profile}/schemas/validation.yaml +2 -2
- package/bundle/skills/agentera/capabilities/research/schemas/artifacts.yaml +24 -0
- package/bundle/skills/agentera/capabilities/{inspirera → research}/schemas/triggers.yaml +9 -3
- package/bundle/skills/agentera/capabilities/{inspirera → research}/schemas/validation.yaml +2 -2
- package/bundle/skills/agentera/capabilities/{hej → status}/schemas/artifacts.yaml +14 -11
- package/bundle/skills/agentera/capabilities/{hej → status}/schemas/triggers.yaml +12 -8
- package/bundle/skills/agentera/capabilities/{hej → status}/schemas/validation.yaml +5 -5
- package/bundle/skills/agentera/capabilities/{visionera → vision}/schemas/artifacts.yaml +8 -8
- package/bundle/skills/agentera/capabilities/{visionera → vision}/schemas/exit.yaml +7 -6
- package/bundle/skills/agentera/capabilities/{visionera → vision}/schemas/triggers.yaml +19 -5
- package/bundle/skills/agentera/capabilities/{visionera → vision}/schemas/validation.yaml +18 -20
- package/bundle/skills/agentera/capability_schema_contract.yaml +201 -38
- package/bundle/skills/agentera/protocol.yaml +29 -29
- package/bundle/skills/agentera/references/contract.md +338 -322
- package/bundle/skills/agentera/schemas/artifacts/changelog.yaml +4 -4
- package/bundle/skills/agentera/schemas/artifacts/decisions.yaml +10 -10
- package/bundle/skills/agentera/schemas/artifacts/design.yaml +4 -4
- package/bundle/skills/agentera/schemas/artifacts/docs.yaml +8 -7
- package/bundle/skills/agentera/schemas/artifacts/experiments.yaml +5 -5
- package/bundle/skills/agentera/schemas/artifacts/health.yaml +5 -5
- package/bundle/skills/agentera/schemas/artifacts/objective.yaml +4 -4
- package/bundle/skills/agentera/schemas/artifacts/plan.yaml +263 -11
- package/bundle/skills/agentera/schemas/artifacts/progress.yaml +20 -41
- package/bundle/skills/agentera/schemas/artifacts/todo.yaml +43 -24
- package/bundle/skills/agentera/schemas/artifacts/vision.yaml +3 -3
- package/dist/analytics/extractCorpus/cli.js +163 -0
- package/dist/analytics/extractCorpus/cli.js.map +1 -0
- package/dist/analytics/extractCorpus/copilotSessions.js +276 -0
- package/dist/analytics/extractCorpus/copilotSessions.js.map +1 -0
- package/dist/analytics/extractCorpus/core.js +393 -0
- package/dist/analytics/extractCorpus/core.js.map +1 -0
- package/dist/analytics/extractCorpus/corpus.js +168 -0
- package/dist/analytics/extractCorpus/corpus.js.map +1 -0
- package/dist/analytics/extractCorpus/coverageAudit.js +261 -0
- package/dist/analytics/extractCorpus/coverageAudit.js.map +1 -0
- package/dist/analytics/extractCorpus/cursorSessions.js +426 -0
- package/dist/analytics/extractCorpus/cursorSessions.js.map +1 -0
- package/dist/analytics/extractCorpus/extractCorpusParity.js +105 -0
- package/dist/analytics/extractCorpus/extractCorpusParity.js.map +1 -0
- package/dist/analytics/extractCorpus/filesystemSources.js +119 -0
- package/dist/analytics/extractCorpus/filesystemSources.js.map +1 -0
- package/dist/analytics/extractCorpus/index.js +12 -0
- package/dist/analytics/extractCorpus/index.js.map +1 -0
- package/dist/analytics/extractCorpus/jsonlSessions.js +205 -0
- package/dist/analytics/extractCorpus/jsonlSessions.js.map +1 -0
- package/dist/analytics/extractCorpus/sqliteCaps.js +44 -0
- package/dist/analytics/extractCorpus/sqliteCaps.js.map +1 -0
- package/dist/analytics/extractCorpus/sqliteSessions.js +368 -0
- package/dist/analytics/extractCorpus/sqliteSessions.js.map +1 -0
- package/dist/analytics/extractCorpus.js +2 -1790
- package/dist/analytics/extractCorpus.js.map +1 -1
- package/dist/analytics/usageStats.js +93 -27
- package/dist/analytics/usageStats.js.map +1 -1
- package/dist/bin/agentera.js +3 -1
- package/dist/bin/agentera.js.map +1 -1
- package/dist/capabilities/audit/instructions.js +4 -0
- package/dist/capabilities/audit/instructions.js.map +1 -0
- package/dist/capabilities/build/instructions.js +5 -0
- package/dist/capabilities/build/instructions.js.map +1 -0
- package/dist/capabilities/design/instructions.js +5 -0
- package/dist/capabilities/design/instructions.js.map +1 -0
- package/dist/capabilities/discuss/instructions.js +6 -0
- package/dist/capabilities/discuss/instructions.js.map +1 -0
- package/dist/capabilities/document/instructions.js +4 -0
- package/dist/capabilities/document/instructions.js.map +1 -0
- package/dist/capabilities/index.js +38 -0
- package/dist/capabilities/index.js.map +1 -0
- package/dist/capabilities/optimize/instructions.js +5 -0
- package/dist/capabilities/optimize/instructions.js.map +1 -0
- package/dist/capabilities/orchestrate/instructions.js +10 -0
- package/dist/capabilities/orchestrate/instructions.js.map +1 -0
- package/dist/capabilities/plan/instructions.js +6 -0
- package/dist/capabilities/plan/instructions.js.map +1 -0
- package/dist/capabilities/profile/instructions.js +5 -0
- package/dist/capabilities/profile/instructions.js.map +1 -0
- package/dist/capabilities/research/instructions.js +6 -0
- package/dist/capabilities/research/instructions.js.map +1 -0
- package/dist/capabilities/status/instructions.js +5 -0
- package/dist/capabilities/status/instructions.js.map +1 -0
- package/dist/capabilities/vision/instructions.js +5 -0
- package/dist/capabilities/vision/instructions.js.map +1 -0
- package/dist/cli/appContext.js +16 -17
- package/dist/cli/appContext.js.map +1 -1
- package/dist/cli/capabilityContext/benchmark.js +564 -0
- package/dist/cli/capabilityContext/benchmark.js.map +1 -0
- package/dist/cli/capabilityContext/bespoke.js +36 -0
- package/dist/cli/capabilityContext/bespoke.js.map +1 -0
- package/dist/cli/capabilityContext/build.js +190 -0
- package/dist/cli/capabilityContext/build.js.map +1 -0
- package/dist/cli/capabilityContext/closeout.js +230 -0
- package/dist/cli/capabilityContext/closeout.js.map +1 -0
- package/dist/cli/capabilityContext/contract.js +190 -0
- package/dist/cli/capabilityContext/contract.js.map +1 -0
- package/dist/cli/capabilityContext/evidence.js +456 -0
- package/dist/cli/capabilityContext/evidence.js.map +1 -0
- package/dist/cli/capabilityContext/index.js +4 -0
- package/dist/cli/capabilityContext/index.js.map +1 -0
- package/dist/cli/capabilityContext/orchestration.js +117 -0
- package/dist/cli/capabilityContext/orchestration.js.map +1 -0
- package/dist/cli/capabilityContext/planState.js +279 -0
- package/dist/cli/capabilityContext/planState.js.map +1 -0
- package/dist/cli/capabilityContext/progress.js +138 -0
- package/dist/cli/capabilityContext/progress.js.map +1 -0
- package/dist/cli/capabilityContext/shared.js +94 -0
- package/dist/cli/capabilityContext/shared.js.map +1 -0
- package/dist/cli/capabilityContext/slim.js +108 -0
- package/dist/cli/capabilityContext/slim.js.map +1 -0
- package/dist/cli/capabilityContext/startup.js +217 -0
- package/dist/cli/capabilityContext/startup.js.map +1 -0
- package/dist/cli/capabilityContext/types.js +41 -0
- package/dist/cli/capabilityContext/types.js.map +1 -0
- package/dist/cli/capabilityContext.js +1 -2420
- package/dist/cli/capabilityContext.js.map +1 -1
- package/dist/cli/commands/appHome.js +23 -0
- package/dist/cli/commands/appHome.js.map +1 -0
- package/dist/cli/commands/capability.js +3 -10
- package/dist/cli/commands/capability.js.map +1 -1
- package/dist/cli/commands/compact.js +1 -1
- package/dist/cli/commands/compact.js.map +1 -1
- package/dist/cli/commands/doctor.js +116 -96
- package/dist/cli/commands/doctor.js.map +1 -1
- package/dist/cli/commands/lint.js +16 -41
- package/dist/cli/commands/lint.js.map +1 -1
- package/dist/cli/commands/prime/bundleStatus.js +185 -0
- package/dist/cli/commands/prime/bundleStatus.js.map +1 -0
- package/dist/cli/commands/prime/collectOrientationState.js +179 -0
- package/dist/cli/commands/prime/collectOrientationState.js.map +1 -0
- package/dist/cli/commands/prime/orientationOutput.js +233 -0
- package/dist/cli/commands/prime/orientationOutput.js.map +1 -0
- package/dist/cli/commands/prime/types.js +2 -0
- package/dist/cli/commands/prime/types.js.map +1 -0
- package/dist/cli/commands/prime/v1Migration.js +39 -0
- package/dist/cli/commands/prime/v1Migration.js.map +1 -0
- package/dist/cli/commands/prime.js +11 -519
- package/dist/cli/commands/prime.js.map +1 -1
- package/dist/cli/commands/query.js +5 -2
- package/dist/cli/commands/query.js.map +1 -1
- package/dist/cli/commands/report.js +50 -14
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/schema.js +113 -24
- package/dist/cli/commands/schema.js.map +1 -1
- package/dist/cli/commands/state/decisions.js +403 -0
- package/dist/cli/commands/state/decisions.js.map +1 -0
- package/dist/cli/commands/state/docs.js +97 -0
- package/dist/cli/commands/state/docs.js.map +1 -0
- package/dist/cli/commands/state/experiments.js +68 -0
- package/dist/cli/commands/state/experiments.js.map +1 -0
- package/dist/cli/commands/state/health.js +116 -0
- package/dist/cli/commands/state/health.js.map +1 -0
- package/dist/cli/commands/state/index.js +51 -0
- package/dist/cli/commands/state/index.js.map +1 -0
- package/dist/cli/commands/state/objective.js +69 -0
- package/dist/cli/commands/state/objective.js.map +1 -0
- package/dist/cli/commands/state/plan.js +274 -0
- package/dist/cli/commands/state/plan.js.map +1 -0
- package/dist/cli/commands/state/progress.js +47 -0
- package/dist/cli/commands/state/progress.js.map +1 -0
- package/dist/cli/commands/state/shared.js +15 -0
- package/dist/cli/commands/state/shared.js.map +1 -0
- package/dist/cli/commands/state/todo.js +121 -0
- package/dist/cli/commands/state/todo.js.map +1 -0
- package/dist/cli/commands/state/write.js +341 -0
- package/dist/cli/commands/state/write.js.map +1 -0
- package/dist/cli/commands/upgrade.js +79 -1
- package/dist/cli/commands/upgrade.js.map +1 -1
- package/dist/cli/commands/upgradeVerify.js +81 -0
- package/dist/cli/commands/upgradeVerify.js.map +1 -0
- package/dist/cli/commands/validate.js +56 -96
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/cli/commands/verify.js +13 -7
- package/dist/cli/commands/verify.js.map +1 -1
- package/dist/cli/contracts/bundleStatus.js +2 -0
- package/dist/cli/contracts/bundleStatus.js.map +1 -0
- package/dist/cli/contracts/orientationState.js +2 -0
- package/dist/cli/contracts/orientationState.js.map +1 -0
- package/dist/cli/dispatch/argvParser.js +33 -0
- package/dist/cli/dispatch/argvParser.js.map +1 -0
- package/dist/cli/dispatch/check.js +328 -0
- package/dist/cli/dispatch/check.js.map +1 -0
- package/dist/cli/dispatch/commands.js +27 -0
- package/dist/cli/dispatch/commands.js.map +1 -0
- package/dist/cli/dispatch/index.js +183 -0
- package/dist/cli/dispatch/index.js.map +1 -0
- package/dist/cli/dispatch/lifecycle.js +671 -0
- package/dist/cli/dispatch/lifecycle.js.map +1 -0
- package/dist/cli/dispatch/prime.js +104 -0
- package/dist/cli/dispatch/prime.js.map +1 -0
- package/dist/cli/dispatch/shared.js +64 -0
- package/dist/cli/dispatch/shared.js.map +1 -0
- package/dist/cli/dispatch/state.js +148 -0
- package/dist/cli/dispatch/state.js.map +1 -0
- package/dist/cli/dispatch.js +1 -957
- package/dist/cli/dispatch.js.map +1 -1
- package/dist/cli/errors.js +54 -0
- package/dist/cli/errors.js.map +1 -0
- package/dist/cli/help.js +262 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/orientation/attention.js +163 -0
- package/dist/cli/orientation/attention.js.map +1 -0
- package/dist/cli/orientation/corpusCoverage.js +71 -0
- package/dist/cli/orientation/corpusCoverage.js.map +1 -0
- package/dist/cli/orientation.js +194 -114
- package/dist/cli/orientation.js.map +1 -1
- package/dist/cli/planArtifacts.js +172 -0
- package/dist/cli/planArtifacts.js.map +1 -0
- package/dist/cli/planEvidence.js +158 -0
- package/dist/cli/planEvidence.js.map +1 -0
- package/dist/cli/planLifecycleState.js +34 -0
- package/dist/cli/planLifecycleState.js.map +1 -0
- package/dist/cli/prime-blob.js +68 -2
- package/dist/cli/prime-blob.js.map +1 -1
- package/dist/cli/startupCompletenessContract.js +56 -0
- package/dist/cli/startupCompletenessContract.js.map +1 -0
- package/dist/cli/stateQuery.js +17 -2
- package/dist/cli/stateQuery.js.map +1 -1
- package/dist/cli/todoMarkdown.js +33 -0
- package/dist/cli/todoMarkdown.js.map +1 -0
- package/dist/cli/todoSeverity.js +19 -0
- package/dist/cli/todoSeverity.js.map +1 -0
- package/dist/core/atomicWriter.js +21 -0
- package/dist/core/atomicWriter.js.map +1 -0
- package/dist/core/envPaths.js +21 -0
- package/dist/core/envPaths.js.map +1 -0
- package/dist/core/jsonValue.js +6 -0
- package/dist/core/jsonValue.js.map +1 -0
- package/dist/core/pyjson.js +67 -2
- package/dist/core/pyjson.js.map +1 -1
- package/dist/core/yaml.js +8 -0
- package/dist/core/yaml.js.map +1 -1
- package/dist/eval/evalSkills.js +30 -25
- package/dist/eval/evalSkills.js.map +1 -1
- package/dist/eval/semanticEval.js +43 -19
- package/dist/eval/semanticEval.js.map +1 -1
- package/dist/eval/semanticFixtures.js +16 -4
- package/dist/eval/semanticFixtures.js.map +1 -1
- package/dist/hooks/common.js +9 -26
- package/dist/hooks/common.js.map +1 -1
- package/dist/hooks/compaction/apply.js +269 -0
- package/dist/hooks/compaction/apply.js.map +1 -0
- package/dist/hooks/compaction/dryRun.js +183 -0
- package/dist/hooks/compaction/dryRun.js.map +1 -0
- package/dist/hooks/compaction/index.js +23 -0
- package/dist/hooks/compaction/index.js.map +1 -0
- package/dist/hooks/compaction/parse.js +258 -0
- package/dist/hooks/compaction/parse.js.map +1 -0
- package/dist/hooks/compaction/retention.js +202 -0
- package/dist/hooks/compaction/retention.js.map +1 -0
- package/dist/hooks/compaction/status.js +243 -0
- package/dist/hooks/compaction/status.js.map +1 -0
- package/dist/hooks/compaction/types.js +6 -0
- package/dist/hooks/compaction/types.js.map +1 -0
- package/dist/hooks/cursorPreToolUse.js +1 -1
- package/dist/hooks/cursorPreToolUse.js.map +1 -1
- package/dist/hooks/cursorSessionStart.js +10 -2
- package/dist/hooks/cursorSessionStart.js.map +1 -1
- package/dist/hooks/sessionStart.js +18 -11
- package/dist/hooks/sessionStart.js.map +1 -1
- package/dist/hooks/sessionStop.js +8 -14
- package/dist/hooks/sessionStop.js.map +1 -1
- package/dist/hooks/validateArtifact/agentFacing.js +10 -0
- package/dist/hooks/validateArtifact/agentFacing.js.map +1 -0
- package/dist/hooks/validateArtifact/index.js +151 -0
- package/dist/hooks/validateArtifact/index.js.map +1 -0
- package/dist/hooks/validateArtifact/markdown.js +146 -0
- package/dist/hooks/validateArtifact/markdown.js.map +1 -0
- package/dist/hooks/validateArtifact/runtime.js +86 -0
- package/dist/hooks/validateArtifact/runtime.js.map +1 -0
- package/dist/hooks/validateArtifact/schema.js +541 -0
- package/dist/hooks/validateArtifact/schema.js.map +1 -0
- package/dist/hooks/validateArtifact/traversal.js +106 -0
- package/dist/hooks/validateArtifact/traversal.js.map +1 -0
- package/dist/hooks/validateArtifact/violations.js +108 -0
- package/dist/hooks/validateArtifact/violations.js.map +1 -0
- package/dist/migrate/v2HandoffManifest.js +455 -0
- package/dist/migrate/v2HandoffManifest.js.map +1 -0
- package/dist/registries/artifactProtocolIds.js +77 -0
- package/dist/registries/artifactProtocolIds.js.map +1 -0
- package/dist/registries/artifactRegistry.js +62 -15
- package/dist/registries/artifactRegistry.js.map +1 -1
- package/dist/registries/capabilityContract.js +156 -12
- package/dist/registries/capabilityContract.js.map +1 -1
- package/dist/registries/evaluatorHandoffContract.js +171 -0
- package/dist/registries/evaluatorHandoffContract.js.map +1 -0
- package/dist/registries/packageRegistry.js +40 -6
- package/dist/registries/packageRegistry.js.map +1 -1
- package/dist/registries/runtimeAdapterRegistry.js +30 -21
- package/dist/registries/runtimeAdapterRegistry.js.map +1 -1
- package/dist/registries/triggerLoader.js +211 -0
- package/dist/registries/triggerLoader.js.map +1 -0
- package/dist/release/releaseMetadata.js +235 -0
- package/dist/release/releaseMetadata.js.map +1 -0
- package/dist/runtime/lifecycleAdapterContract.js +458 -0
- package/dist/runtime/lifecycleAdapterContract.js.map +1 -0
- package/dist/runtime/lifecycleAdapters.js +766 -0
- package/dist/runtime/lifecycleAdapters.js.map +1 -0
- package/dist/runtime/lifecycleAuthority.js +493 -0
- package/dist/runtime/lifecycleAuthority.js.map +1 -0
- package/dist/runtime/lifecycleOperationContract.js +113 -0
- package/dist/runtime/lifecycleOperationContract.js.map +1 -0
- package/dist/runtime/lifecycleOperations.js +635 -0
- package/dist/runtime/lifecycleOperations.js.map +1 -0
- package/dist/runtime/lifecycleOwnershipJournal.js +623 -0
- package/dist/runtime/lifecycleOwnershipJournal.js.map +1 -0
- package/dist/runtime/lifecyclePublication.js +395 -0
- package/dist/runtime/lifecyclePublication.js.map +1 -0
- package/dist/runtime/lifecycleSnapshot.js +439 -0
- package/dist/runtime/lifecycleSnapshot.js.map +1 -0
- package/dist/runtime/retiredRuntimeCleanup.js +238 -0
- package/dist/runtime/retiredRuntimeCleanup.js.map +1 -0
- package/dist/setup/codex/agents.js +96 -0
- package/dist/setup/codex/agents.js.map +1 -0
- package/dist/setup/codex/cli.js +161 -0
- package/dist/setup/codex/cli.js.map +1 -0
- package/dist/setup/codex/configToml.js +639 -0
- package/dist/setup/codex/configToml.js.map +1 -0
- package/dist/setup/codex/constants.js +29 -0
- package/dist/setup/codex/constants.js.map +1 -0
- package/dist/setup/codex/installRoot.js +64 -0
- package/dist/setup/codex/installRoot.js.map +1 -0
- package/dist/setup/codex/state.js +270 -0
- package/dist/setup/codex/state.js.map +1 -0
- package/dist/setup/codex.js +11 -1055
- package/dist/setup/codex.js.map +1 -1
- package/dist/setup/copilot.js +1 -1
- package/dist/setup/copilot.js.map +1 -1
- package/dist/setup/cursor.js +7 -5
- package/dist/setup/cursor.js.map +1 -1
- package/dist/setup/cursorSurfaces.js +67 -0
- package/dist/setup/cursorSurfaces.js.map +1 -0
- package/dist/setup/doctor/core.js +296 -0
- package/dist/setup/doctor/core.js.map +1 -0
- package/dist/setup/doctor/diagnostics.js +201 -0
- package/dist/setup/doctor/diagnostics.js.map +1 -0
- package/dist/setup/doctor/opencode.js +301 -0
- package/dist/setup/doctor/opencode.js.map +1 -0
- package/dist/setup/doctor/report.js +425 -0
- package/dist/setup/doctor/report.js.map +1 -0
- package/dist/setup/doctor.js +9 -1275
- package/dist/setup/doctor.js.map +1 -1
- package/dist/setup/opencode.js +13 -0
- package/dist/setup/opencode.js.map +1 -0
- package/dist/setup/opencodeConstants.js +2 -0
- package/dist/setup/opencodeConstants.js.map +1 -0
- package/dist/setup/smokeChecks.js +109 -0
- package/dist/setup/smokeChecks.js.map +1 -0
- package/dist/state/installRoot.js +64 -24
- package/dist/state/installRoot.js.map +1 -1
- package/dist/state/startupAnalysis/benchmark.js +371 -0
- package/dist/state/startupAnalysis/benchmark.js.map +1 -0
- package/dist/state/startupAnalysis/contract.js +126 -0
- package/dist/state/startupAnalysis/contract.js.map +1 -0
- package/dist/state/startupAnalysis/helpers.js +287 -0
- package/dist/state/startupAnalysis/helpers.js.map +1 -0
- package/dist/state/startupAnalysis/index.js +7 -0
- package/dist/state/startupAnalysis/index.js.map +1 -0
- package/dist/state/startupAnalysis/metrics.js +341 -0
- package/dist/state/startupAnalysis/metrics.js.map +1 -0
- package/dist/state/startupAnalysis/records.js +199 -0
- package/dist/state/startupAnalysis/records.js.map +1 -0
- package/dist/state/startupAnalysis/report.js +112 -0
- package/dist/state/startupAnalysis/report.js.map +1 -0
- package/dist/state/startupAnalysis/threshold.js +500 -0
- package/dist/state/startupAnalysis/threshold.js.map +1 -0
- package/dist/state/startupAnalysis.js +2 -1952
- package/dist/state/startupAnalysis.js.map +1 -1
- package/dist/state/write/assign.js +21 -0
- package/dist/state/write/assign.js.map +1 -0
- package/dist/state/write/errors.js +12 -0
- package/dist/state/write/errors.js.map +1 -0
- package/dist/state/write/explain.js +155 -0
- package/dist/state/write/explain.js.map +1 -0
- package/dist/state/write/fields.js +62 -0
- package/dist/state/write/fields.js.map +1 -0
- package/dist/state/write/index.js +11 -0
- package/dist/state/write/index.js.map +1 -0
- package/dist/state/write/input.js +22 -0
- package/dist/state/write/input.js.map +1 -0
- package/dist/state/write/lock.js +108 -0
- package/dist/state/write/lock.js.map +1 -0
- package/dist/state/write/operations.js +220 -0
- package/dist/state/write/operations.js.map +1 -0
- package/dist/state/write/serialize.js +2 -0
- package/dist/state/write/serialize.js.map +1 -0
- package/dist/state/write/transaction.js +787 -0
- package/dist/state/write/transaction.js.map +1 -0
- package/dist/state/write/validate.js +8 -0
- package/dist/state/write/validate.js.map +1 -0
- package/dist/upgrade/appContentRefresh.js +374 -0
- package/dist/upgrade/appContentRefresh.js.map +1 -0
- package/dist/upgrade/appModel.js +11 -6
- package/dist/upgrade/appModel.js.map +1 -1
- package/dist/upgrade/atomicWriter.js +2 -0
- package/dist/upgrade/atomicWriter.js.map +1 -0
- package/dist/upgrade/bundleEvidence.js +34 -0
- package/dist/upgrade/bundleEvidence.js.map +1 -0
- package/dist/upgrade/channels.js +27 -7
- package/dist/upgrade/channels.js.map +1 -1
- package/dist/upgrade/coexistenceProbe.js +105 -0
- package/dist/upgrade/coexistenceProbe.js.map +1 -0
- package/dist/upgrade/compatibility.js +52 -16
- package/dist/upgrade/compatibility.js.map +1 -1
- package/dist/upgrade/doctor.js +195 -193
- package/dist/upgrade/doctor.js.map +1 -1
- package/dist/upgrade/doctorClassifier.js +188 -0
- package/dist/upgrade/doctorClassifier.js.map +1 -0
- package/dist/upgrade/installedHooksRetirement.js +190 -0
- package/dist/upgrade/installedHooksRetirement.js.map +1 -0
- package/dist/upgrade/legacyAgentCleanup.js +183 -0
- package/dist/upgrade/legacyAgentCleanup.js.map +1 -0
- package/dist/upgrade/lifecycleUpgrade.js +427 -0
- package/dist/upgrade/lifecycleUpgrade.js.map +1 -0
- package/dist/upgrade/migrateArtifactsV1ToV2.js +568 -0
- package/dist/upgrade/migrateArtifactsV1ToV2.js.map +1 -0
- package/dist/upgrade/migrateArtifactsV2ToV3.js +273 -144
- package/dist/upgrade/migrateArtifactsV2ToV3.js.map +1 -1
- package/dist/upgrade/nextMajorDoctor.js +156 -0
- package/dist/upgrade/nextMajorDoctor.js.map +1 -0
- package/dist/upgrade/npxPlatformStatus.js +23 -0
- package/dist/upgrade/npxPlatformStatus.js.map +1 -0
- package/dist/upgrade/projectIntegration.js +259 -104
- package/dist/upgrade/projectIntegration.js.map +1 -1
- package/dist/upgrade/projectIntegrationDecision.js +141 -0
- package/dist/upgrade/projectIntegrationDecision.js.map +1 -0
- package/dist/upgrade/runtimeMigration.js +342 -89
- package/dist/upgrade/runtimeMigration.js.map +1 -1
- package/dist/upgrade/upgradeCommands.js +8 -0
- package/dist/upgrade/upgradeCommands.js.map +1 -1
- package/dist/upgrade/upgradeLock.js +54 -0
- package/dist/upgrade/upgradeLock.js.map +1 -0
- package/dist/upgrade/upgradeOrchestrator.js +170 -46
- package/dist/upgrade/upgradeOrchestrator.js.map +1 -1
- package/dist/upgrade/upgradeSnapshot.js +93 -0
- package/dist/upgrade/upgradeSnapshot.js.map +1 -0
- package/dist/upgrade/v3CapabilitySurface.js +15 -0
- package/dist/upgrade/v3CapabilitySurface.js.map +1 -0
- package/dist/upgrade/versionResolution.js +12 -4
- package/dist/upgrade/versionResolution.js.map +1 -1
- package/dist/validate/appHomeContract.js +5 -5
- package/dist/validate/appHomeContract.js.map +1 -1
- package/dist/validate/capability.js +135 -14
- package/dist/validate/capability.js.map +1 -1
- package/dist/validate/crossCapability.js +1 -1
- package/dist/validate/crossCapability.js.map +1 -1
- package/dist/validate/lifecycleAdapters/legacyPythonParity.js +93 -0
- package/dist/validate/lifecycleAdapters/legacyPythonParity.js.map +1 -0
- package/dist/validate/lifecycleAdapters/nodeFormChecks.js +481 -0
- package/dist/validate/lifecycleAdapters/nodeFormChecks.js.map +1 -0
- package/dist/validate/lifecycleAdapters/shared.js +198 -0
- package/dist/validate/lifecycleAdapters/shared.js.map +1 -0
- package/dist/validate/lifecycleAdapters.js +91 -702
- package/dist/validate/lifecycleAdapters.js.map +1 -1
- package/dist/validate/selfAudit.js +63 -21
- package/dist/validate/selfAudit.js.map +1 -1
- package/dist/validate/vocabularyAuthority.js +303 -0
- package/dist/validate/vocabularyAuthority.js.map +1 -0
- package/package.json +30 -27
- package/bundle/references/v1-section-mapping.md +0 -47
- package/bundle/skills/agentera/.claude-plugin/plugin.json +0 -27
- package/bundle/skills/agentera/agents/dokumentera.toml +0 -6
- package/bundle/skills/agentera/agents/hej.toml +0 -6
- package/bundle/skills/agentera/agents/inspektera.toml +0 -6
- package/bundle/skills/agentera/agents/inspirera.toml +0 -6
- package/bundle/skills/agentera/agents/optimera.toml +0 -6
- package/bundle/skills/agentera/agents/orkestrera.toml +0 -6
- package/bundle/skills/agentera/agents/planera.toml +0 -6
- package/bundle/skills/agentera/agents/profilera.toml +0 -6
- package/bundle/skills/agentera/agents/realisera.toml +0 -6
- package/bundle/skills/agentera/agents/resonera.toml +0 -6
- package/bundle/skills/agentera/agents/visionera.toml +0 -6
- package/bundle/skills/agentera/agents/visualisera.toml +0 -6
- package/bundle/skills/agentera/capabilities/dokumentera/instructions.md +0 -428
- package/bundle/skills/agentera/capabilities/hej/instructions.md +0 -331
- package/bundle/skills/agentera/capabilities/inspektera/instructions.md +0 -514
- package/bundle/skills/agentera/capabilities/inspirera/instructions.md +0 -280
- package/bundle/skills/agentera/capabilities/inspirera/schemas/artifacts.yaml +0 -24
- package/bundle/skills/agentera/capabilities/optimera/instructions.md +0 -437
- package/bundle/skills/agentera/capabilities/orkestrera/instructions.md +0 -433
- package/bundle/skills/agentera/capabilities/orkestrera/schemas/validation.yaml +0 -107
- package/bundle/skills/agentera/capabilities/planera/instructions.md +0 -368
- package/bundle/skills/agentera/capabilities/planera/schemas/artifacts.yaml +0 -62
- package/bundle/skills/agentera/capabilities/planera/schemas/validation.yaml +0 -61
- package/bundle/skills/agentera/capabilities/profilera/instructions.md +0 -419
- package/bundle/skills/agentera/capabilities/realisera/instructions.md +0 -403
- package/bundle/skills/agentera/capabilities/resonera/instructions.md +0 -329
- package/bundle/skills/agentera/capabilities/visionera/instructions.md +0 -309
- package/bundle/skills/agentera/capabilities/visualisera/instructions.md +0 -400
- package/bundle/skills/hej/.claude-plugin/plugin.json +0 -6
- package/bundle/skills/hej/SKILL.md +0 -69
- package/bundle/skills/hej/agents/hej.toml +0 -11
- package/bundle/skills/hej/agents/openai.yaml +0 -8
- package/dist/cli/commands/backfill.js +0 -84
- package/dist/cli/commands/backfill.js.map +0 -1
- package/dist/cli/commands/state.js +0 -1012
- package/dist/cli/commands/state.js.map +0 -1
- package/dist/core/git.js +0 -43
- package/dist/core/git.js.map +0 -1
- package/dist/hooks/compaction.js +0 -935
- package/dist/hooks/compaction.js.map +0 -1
- package/dist/hooks/validateArtifact.js +0 -933
- package/dist/hooks/validateArtifact.js.map +0 -1
- package/dist/state/progressCommit.js +0 -289
- package/dist/state/progressCommit.js.map +0 -1
- /package/bundle/skills/agentera/capabilities/{dokumentera → document}/schemas/exit.yaml +0 -0
- /package/bundle/skills/agentera/capabilities/{inspirera → research}/schemas/exit.yaml +0 -0
- /package/bundle/skills/agentera/capabilities/{hej → status}/schemas/exit.yaml +0 -0
|
@@ -0,0 +1,787 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { isDeepStrictEqual } from "node:util";
|
|
5
|
+
import { splitLinesKeepEnds, unifiedDiff } from "../../core/difflib.js";
|
|
6
|
+
import { dumpYamlMapping, loadYamlMapping } from "../../core/yaml.js";
|
|
7
|
+
import { lintFullArtifactPayload } from "../../cli/commands/lint.js";
|
|
8
|
+
import { compactYamlFile, decisionProtectedOverflowCount, } from "../../hooks/compaction/index.js";
|
|
9
|
+
import { assertRealpathBoundary, loadArtifactRegistry, resolveArtifactPath, } from "../../registries/artifactRegistry.js";
|
|
10
|
+
import { acquireWriterLock } from "./lock.js";
|
|
11
|
+
import { localDate, localTimestamp, nextEntryNumber, nextTaskNumber } from "./assign.js";
|
|
12
|
+
import { reject } from "./errors.js";
|
|
13
|
+
import { validateArtifactBytes } from "./validate.js";
|
|
14
|
+
import { dependencyReadyTasks } from "../../cli/capabilityContext/planState.js";
|
|
15
|
+
function mapping(value) {
|
|
16
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
17
|
+
? value
|
|
18
|
+
: {};
|
|
19
|
+
}
|
|
20
|
+
function array(doc, key) {
|
|
21
|
+
return Array.isArray(doc[key])
|
|
22
|
+
? doc[key].filter((v) => Boolean(v && typeof v === "object" && !Array.isArray(v)))
|
|
23
|
+
: [];
|
|
24
|
+
}
|
|
25
|
+
function setNested(target, field, value) {
|
|
26
|
+
const parts = field.split(".");
|
|
27
|
+
let cursor = target;
|
|
28
|
+
for (const part of parts.slice(0, -1)) {
|
|
29
|
+
if (!cursor[part] || typeof cursor[part] !== "object" || Array.isArray(cursor[part]))
|
|
30
|
+
cursor[part] = {};
|
|
31
|
+
cursor = cursor[part];
|
|
32
|
+
}
|
|
33
|
+
cursor[parts.at(-1)] = value;
|
|
34
|
+
}
|
|
35
|
+
function project(entry, payload) {
|
|
36
|
+
const result = {};
|
|
37
|
+
for (const [key, expected] of Object.entries(payload)) {
|
|
38
|
+
const actual = mappingPath(entry, key);
|
|
39
|
+
if (expected !== undefined)
|
|
40
|
+
setNested(result, key, actual);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
function mappingPath(entry, field) {
|
|
45
|
+
let value = entry;
|
|
46
|
+
for (const part of field.split(".")) {
|
|
47
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
48
|
+
return undefined;
|
|
49
|
+
value = value[part];
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
function exactReplay(entry, payload) {
|
|
54
|
+
return Boolean(entry && isDeepStrictEqual(project(entry, payload), payload));
|
|
55
|
+
}
|
|
56
|
+
function readExisting(target) {
|
|
57
|
+
if (!fs.existsSync(target))
|
|
58
|
+
return { doc: {}, bytes: "" };
|
|
59
|
+
const bytes = fs.readFileSync(target, "utf8");
|
|
60
|
+
try {
|
|
61
|
+
return { doc: loadYamlMapping(bytes), bytes };
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
throw new Error(`cannot parse existing artifact '${target}': ${error.message}; run agentera check validate artifact before retrying`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function buildProgress(doc, values) {
|
|
68
|
+
const entry = {
|
|
69
|
+
number: nextEntryNumber(doc, "cycles"),
|
|
70
|
+
timestamp: values.timestamp ?? localTimestamp(),
|
|
71
|
+
type: values.type,
|
|
72
|
+
phase: values.phase,
|
|
73
|
+
what: values.what,
|
|
74
|
+
};
|
|
75
|
+
for (const field of ["inspiration", "discovered", "verified", "next"])
|
|
76
|
+
if (values[field] !== undefined)
|
|
77
|
+
entry[field] = values[field];
|
|
78
|
+
const context = { intent: mappingPath(values, "context.intent") };
|
|
79
|
+
for (const field of ["constraints", "unknowns", "scope"]) {
|
|
80
|
+
const value = mappingPath(values, `context.${field}`);
|
|
81
|
+
if (value !== undefined)
|
|
82
|
+
context[field] = value;
|
|
83
|
+
}
|
|
84
|
+
entry.context = context;
|
|
85
|
+
return entry;
|
|
86
|
+
}
|
|
87
|
+
function buildDecision(doc, values) {
|
|
88
|
+
const alternatives = mapping(values.alternatives);
|
|
89
|
+
const rejected = Array.isArray(alternatives.rejected) ? alternatives.rejected : [];
|
|
90
|
+
const entry = {
|
|
91
|
+
number: nextEntryNumber(doc, "decisions"),
|
|
92
|
+
date: values.date ?? localDate(),
|
|
93
|
+
question: values.question,
|
|
94
|
+
context: values.context,
|
|
95
|
+
alternatives: [
|
|
96
|
+
{ name: alternatives.chosen, status: "chosen" },
|
|
97
|
+
...rejected.map((name) => ({ name, status: "rejected" })),
|
|
98
|
+
],
|
|
99
|
+
choice: values.choice,
|
|
100
|
+
reasoning: values.reasoning,
|
|
101
|
+
confidence: values.confidence,
|
|
102
|
+
};
|
|
103
|
+
if (values.feeds_into !== undefined)
|
|
104
|
+
entry.feeds_into = values.feeds_into;
|
|
105
|
+
return entry;
|
|
106
|
+
}
|
|
107
|
+
function normalizedDecisionPayload(values) {
|
|
108
|
+
const payload = { ...values };
|
|
109
|
+
const alternatives = mapping(values.alternatives);
|
|
110
|
+
payload.alternatives = [
|
|
111
|
+
{ name: alternatives.chosen, status: "chosen" },
|
|
112
|
+
...(Array.isArray(alternatives.rejected) ? alternatives.rejected : []).map((name) => ({
|
|
113
|
+
name,
|
|
114
|
+
status: "rejected",
|
|
115
|
+
})),
|
|
116
|
+
];
|
|
117
|
+
return payload;
|
|
118
|
+
}
|
|
119
|
+
function schemaViolation(violations) {
|
|
120
|
+
reject({ class: "schema_violation", message: violations[0], violations });
|
|
121
|
+
}
|
|
122
|
+
function validatePlanPublicationCandidate(bytes) {
|
|
123
|
+
const lint = lintFullArtifactPayload("plan", bytes);
|
|
124
|
+
const lintViolations = lint.checks
|
|
125
|
+
.filter((check) => check.status === "fail")
|
|
126
|
+
.map((check) => `strict prose lint ${check.name}: ${check.detail}; action: ${check.action}`);
|
|
127
|
+
const schemaViolations = validateArtifactBytes("plan", bytes).map((violation) => `schema validation: ${violation}`);
|
|
128
|
+
const violations = [...lintViolations, ...schemaViolations];
|
|
129
|
+
if (violations.length === 0)
|
|
130
|
+
return;
|
|
131
|
+
reject({
|
|
132
|
+
class: "schema_violation",
|
|
133
|
+
message: "plan publication candidate failed strict prose lint or schema validation; correct the reported violations and retry",
|
|
134
|
+
violations,
|
|
135
|
+
syntax: "agentera state plan create --input plan.yaml --format json",
|
|
136
|
+
example: "agentera state plan create --input plan.yaml --format json",
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function findByNumber(entries, number) {
|
|
140
|
+
return entries.find((entry) => Number(entry.number) === number);
|
|
141
|
+
}
|
|
142
|
+
function mutateCandidate(req, doc) {
|
|
143
|
+
const candidate = structuredClone(doc);
|
|
144
|
+
if (req.artifact === "progress") {
|
|
145
|
+
const payload = req.callerPayload;
|
|
146
|
+
const entries = array(candidate, "cycles");
|
|
147
|
+
if (exactReplay(entries[0], payload))
|
|
148
|
+
return {
|
|
149
|
+
candidate,
|
|
150
|
+
written: entries[0],
|
|
151
|
+
assigned: { number: entries[0].number, timestamp: entries[0].timestamp },
|
|
152
|
+
replay: true,
|
|
153
|
+
};
|
|
154
|
+
const entry = buildProgress(candidate, req.values);
|
|
155
|
+
candidate.cycles = [entry, ...entries];
|
|
156
|
+
return {
|
|
157
|
+
candidate,
|
|
158
|
+
written: entry,
|
|
159
|
+
assigned: { number: entry.number, timestamp: entry.timestamp },
|
|
160
|
+
replay: false,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
if (req.artifact === "decisions" && req.spec.verb === "append") {
|
|
164
|
+
const entries = array(candidate, "decisions");
|
|
165
|
+
const payload = normalizedDecisionPayload(req.callerPayload);
|
|
166
|
+
if (exactReplay(entries.at(-1), payload)) {
|
|
167
|
+
const entry = entries.at(-1);
|
|
168
|
+
return {
|
|
169
|
+
candidate,
|
|
170
|
+
written: entry,
|
|
171
|
+
assigned: { number: entry.number, date: entry.date },
|
|
172
|
+
replay: true,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const entry = buildDecision(candidate, req.values);
|
|
176
|
+
candidate.decisions = [...entries, entry];
|
|
177
|
+
if (decisionProtectedOverflowCount(candidate.decisions, Array.isArray(candidate.archive) ? candidate.archive : []) > 0) {
|
|
178
|
+
reject({
|
|
179
|
+
class: "conflict",
|
|
180
|
+
message: "decision append would exceed protected review capacity; review decision satisfaction first",
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
candidate,
|
|
185
|
+
written: entry,
|
|
186
|
+
assigned: { number: entry.number, date: entry.date },
|
|
187
|
+
replay: false,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
if (req.artifact === "decisions") {
|
|
191
|
+
const entries = array(candidate, "decisions");
|
|
192
|
+
const archived = array(candidate, "archive");
|
|
193
|
+
const number = Number(req.values.number);
|
|
194
|
+
const entry = findByNumber(entries, number) ?? findByNumber(archived, number);
|
|
195
|
+
if (!entry)
|
|
196
|
+
reject({
|
|
197
|
+
class: "unsupported_target",
|
|
198
|
+
message: `no decision with number ${number}; highest is ${Math.max(0, ...entries.map((e) => Number(e.number) || 0), ...archived.map((e) => Number(e.number) || 0))}`,
|
|
199
|
+
});
|
|
200
|
+
const satisfaction = mapping(req.values.satisfaction);
|
|
201
|
+
if (satisfaction.state === "provisionally_satisfied" &&
|
|
202
|
+
!String(satisfaction.evidence ?? "").trim()) {
|
|
203
|
+
reject({
|
|
204
|
+
class: "schema_violation",
|
|
205
|
+
message: "provisionally_satisfied requires non-empty --satisfaction-evidence",
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
if (satisfaction.state === "user_confirmed_satisfied") {
|
|
209
|
+
const confirmation = mapping(satisfaction.user_confirmation);
|
|
210
|
+
if (!String(confirmation.confirmed_by ?? "").trim() ||
|
|
211
|
+
!String(confirmation.confirmed_at ?? "").trim()) {
|
|
212
|
+
reject({
|
|
213
|
+
class: "schema_violation",
|
|
214
|
+
message: "user_confirmed_satisfied requires --confirmed-by and --confirmed-at",
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (isDeepStrictEqual(entry.satisfaction, satisfaction))
|
|
219
|
+
return { candidate, written: entry, assigned: { number }, replay: true };
|
|
220
|
+
entry.satisfaction = satisfaction;
|
|
221
|
+
return { candidate, written: entry, assigned: { number }, replay: false };
|
|
222
|
+
}
|
|
223
|
+
if (req.artifact === "health") {
|
|
224
|
+
if (req.input && ("audits" in req.input || "archive" in req.input)) {
|
|
225
|
+
reject({
|
|
226
|
+
class: "schema_violation",
|
|
227
|
+
message: "health append input must be one audit entry, not a whole health artifact",
|
|
228
|
+
violations: ["remove audits/archive wrapper fields"],
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
const entries = array(candidate, "audits");
|
|
232
|
+
const payload = req.callerPayload;
|
|
233
|
+
if (exactReplay(entries.at(-1), payload)) {
|
|
234
|
+
const entry = entries.at(-1);
|
|
235
|
+
return {
|
|
236
|
+
candidate,
|
|
237
|
+
written: entry,
|
|
238
|
+
assigned: { number: entry.number, date: entry.date },
|
|
239
|
+
replay: true,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
const entry = {
|
|
243
|
+
number: nextEntryNumber(candidate, "audits"),
|
|
244
|
+
date: req.input?.date ?? localDate(),
|
|
245
|
+
...req.input,
|
|
246
|
+
};
|
|
247
|
+
candidate.audits = [...entries, entry];
|
|
248
|
+
return {
|
|
249
|
+
candidate,
|
|
250
|
+
written: entry,
|
|
251
|
+
assigned: { number: entry.number, date: entry.date },
|
|
252
|
+
replay: false,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
const tasks = array(candidate, "tasks");
|
|
256
|
+
if (req.spec.verb === "append") {
|
|
257
|
+
const sameName = tasks.find((task) => task.name === req.values.name);
|
|
258
|
+
const payload = req.callerPayload;
|
|
259
|
+
if (sameName) {
|
|
260
|
+
if (exactReplay(sameName, payload))
|
|
261
|
+
return {
|
|
262
|
+
candidate,
|
|
263
|
+
written: sameName,
|
|
264
|
+
assigned: { number: sameName.number },
|
|
265
|
+
replay: true,
|
|
266
|
+
};
|
|
267
|
+
reject({
|
|
268
|
+
class: "conflict",
|
|
269
|
+
message: `plan task "${req.values.name}" exists with different fields; use 'state plan update --task ${sameName.number}' to modify it`,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
const entry = {
|
|
273
|
+
number: nextTaskNumber(candidate),
|
|
274
|
+
name: req.values.name,
|
|
275
|
+
status: req.values.status ?? "pending",
|
|
276
|
+
};
|
|
277
|
+
for (const field of ["depends_on", "acceptance"])
|
|
278
|
+
if (req.values[field] !== undefined)
|
|
279
|
+
entry[field] = req.values[field];
|
|
280
|
+
candidate.tasks = [...tasks, entry];
|
|
281
|
+
return { candidate, written: entry, assigned: { number: entry.number }, replay: false };
|
|
282
|
+
}
|
|
283
|
+
if (req.spec.verb === "update") {
|
|
284
|
+
const number = Number(req.values.task);
|
|
285
|
+
const entry = findByNumber(tasks, number);
|
|
286
|
+
if (!entry)
|
|
287
|
+
reject({ class: "unsupported_target", message: `no plan task with number ${number}` });
|
|
288
|
+
let changed = false;
|
|
289
|
+
for (const field of [
|
|
290
|
+
"name",
|
|
291
|
+
"depends_on",
|
|
292
|
+
"acceptance",
|
|
293
|
+
"status",
|
|
294
|
+
"evidence",
|
|
295
|
+
"blocked_reason",
|
|
296
|
+
]) {
|
|
297
|
+
if (req.values[field] !== undefined && !isDeepStrictEqual(entry[field], req.values[field])) {
|
|
298
|
+
entry[field] = req.values[field];
|
|
299
|
+
changed = true;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (req.values.surprise !== undefined) {
|
|
303
|
+
const current = String(candidate.surprises ?? "").trim();
|
|
304
|
+
const surprise = String(req.values.surprise);
|
|
305
|
+
if (!current.split("\n").includes(surprise)) {
|
|
306
|
+
candidate.surprises = current ? `${current}\n${surprise}` : surprise;
|
|
307
|
+
changed = true;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return { candidate, written: entry, assigned: { number }, replay: !changed };
|
|
311
|
+
}
|
|
312
|
+
if (req.spec.verb === "set-plan-status") {
|
|
313
|
+
const status = String(req.values.status);
|
|
314
|
+
if (status === "complete" && tasks.some((task) => task.status !== "complete")) {
|
|
315
|
+
reject({
|
|
316
|
+
class: "conflict",
|
|
317
|
+
message: "plan cannot be marked complete while incomplete tasks remain",
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
const header = mapping(candidate.header);
|
|
321
|
+
const replay = header.status === status;
|
|
322
|
+
header.status = status;
|
|
323
|
+
candidate.header = header;
|
|
324
|
+
return { candidate, written: header, assigned: {}, replay };
|
|
325
|
+
}
|
|
326
|
+
if (req.spec.verb === "set-status") {
|
|
327
|
+
const taskNumber = Number(req.values.task);
|
|
328
|
+
const status = String(req.values.status);
|
|
329
|
+
if (!["complete", "in_progress", "pending", "blocked"].includes(status))
|
|
330
|
+
reject({
|
|
331
|
+
class: "invalid_choice",
|
|
332
|
+
message: `argument --status: invalid choice: '${status}'`,
|
|
333
|
+
valid_values: ["complete", "in_progress", "pending", "blocked"],
|
|
334
|
+
});
|
|
335
|
+
const entry = findByNumber(tasks, taskNumber);
|
|
336
|
+
if (!entry)
|
|
337
|
+
reject({ class: "unsupported_target", message: `no plan task with number ${taskNumber}` });
|
|
338
|
+
const replay = entry.status === status;
|
|
339
|
+
entry.status = status;
|
|
340
|
+
return { candidate, written: entry, assigned: { number: taskNumber }, replay };
|
|
341
|
+
}
|
|
342
|
+
if (req.spec.verb === "record-evaluation") {
|
|
343
|
+
const taskNumber = Number(req.values.task);
|
|
344
|
+
const entry = findByNumber(tasks, taskNumber);
|
|
345
|
+
if (!entry)
|
|
346
|
+
reject({ class: "unsupported_target", message: `no plan task with number ${taskNumber}` });
|
|
347
|
+
const evaluationInput = mapping(req.values.evaluation);
|
|
348
|
+
const attemptId = String(evaluationInput.attempt_id ?? "").trim();
|
|
349
|
+
const verdict = String(evaluationInput.verdict ?? "");
|
|
350
|
+
const provenance = String(evaluationInput.provenance ?? "").trim();
|
|
351
|
+
const failureEvidence = String(evaluationInput.failure_evidence ?? "").trim();
|
|
352
|
+
if (!attemptId || !provenance)
|
|
353
|
+
reject({ class: "schema_violation", message: "evaluation requires non-empty --attempt-id and --provenance" });
|
|
354
|
+
if (verdict === "fail" && !failureEvidence)
|
|
355
|
+
reject({ class: "schema_violation", message: "a failed evaluation requires non-empty --failure-evidence" });
|
|
356
|
+
if (verdict === "pass" && failureEvidence)
|
|
357
|
+
reject({ class: "schema_violation", message: "--failure-evidence applies only to a failed evaluation" });
|
|
358
|
+
const prior = mapping(entry.evaluation);
|
|
359
|
+
const priorProvenance = mapping(prior.provenance);
|
|
360
|
+
if (priorProvenance.attempt_id === attemptId) {
|
|
361
|
+
const replay = prior.last_verdict === verdict &&
|
|
362
|
+
priorProvenance.source === provenance &&
|
|
363
|
+
(verdict !== "fail" || prior.last_failure_evidence === failureEvidence);
|
|
364
|
+
if (!replay)
|
|
365
|
+
reject({
|
|
366
|
+
class: "conflict",
|
|
367
|
+
message: `evaluation attempt '${attemptId}' already exists with different result data`,
|
|
368
|
+
});
|
|
369
|
+
return {
|
|
370
|
+
candidate,
|
|
371
|
+
written: entry,
|
|
372
|
+
assigned: { number: taskNumber, attempt_count: prior.attempt_count ?? 0 },
|
|
373
|
+
replay: true,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
if (["complete", "blocked"].includes(String(entry.status ?? "")))
|
|
377
|
+
reject({ class: "conflict", message: `plan task ${taskNumber} is ${entry.status} and cannot accept another evaluation` });
|
|
378
|
+
const attemptCount = Number(prior.attempt_count ?? 0);
|
|
379
|
+
const failureCount = Number(prior.failure_count ?? 0);
|
|
380
|
+
if (!Number.isInteger(attemptCount) || attemptCount < 0 || !Number.isInteger(failureCount) || failureCount < 0)
|
|
381
|
+
reject({ class: "schema_violation", message: `plan task ${taskNumber} has malformed evaluation state` });
|
|
382
|
+
if (verdict === "fail" && failureCount >= 2)
|
|
383
|
+
reject({ class: "conflict", message: `plan task ${taskNumber} has exhausted its evaluation retry budget` });
|
|
384
|
+
const nextFailureCount = failureCount + (verdict === "fail" ? 1 : 0);
|
|
385
|
+
entry.evaluation = {
|
|
386
|
+
attempt_count: attemptCount + 1,
|
|
387
|
+
failure_count: nextFailureCount,
|
|
388
|
+
last_verdict: verdict,
|
|
389
|
+
last_failure_evidence: verdict === "fail" ? failureEvidence : prior.last_failure_evidence ?? null,
|
|
390
|
+
provenance: {
|
|
391
|
+
attempt_id: attemptId,
|
|
392
|
+
source: provenance,
|
|
393
|
+
recorded_at: localTimestamp(),
|
|
394
|
+
writer_command: "agentera state plan record-evaluation",
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
if (nextFailureCount >= 2)
|
|
398
|
+
entry.status = "blocked";
|
|
399
|
+
return {
|
|
400
|
+
candidate,
|
|
401
|
+
written: entry,
|
|
402
|
+
assigned: {
|
|
403
|
+
number: taskNumber,
|
|
404
|
+
attempt_count: attemptCount + 1,
|
|
405
|
+
failure_count: nextFailureCount,
|
|
406
|
+
},
|
|
407
|
+
replay: false,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
throw new Error(`unsupported transaction ${req.artifact} ${req.spec.verb}`);
|
|
411
|
+
}
|
|
412
|
+
function activeKey(artifact) {
|
|
413
|
+
return artifact === "progress"
|
|
414
|
+
? "cycles"
|
|
415
|
+
: artifact === "decisions"
|
|
416
|
+
? "decisions"
|
|
417
|
+
: artifact === "health"
|
|
418
|
+
? "audits"
|
|
419
|
+
: "tasks";
|
|
420
|
+
}
|
|
421
|
+
function stateSlice(artifact, doc, archivePath) {
|
|
422
|
+
if (artifact === "plan") {
|
|
423
|
+
const tasks = array(doc, "tasks");
|
|
424
|
+
return {
|
|
425
|
+
title: mapping(doc.header).title ?? doc.title ?? null,
|
|
426
|
+
status: mapping(doc.header).status ?? doc.status ?? null,
|
|
427
|
+
task_count: tasks.length,
|
|
428
|
+
next_pending_task: dependencyReadyTasks(tasks).find((task) => task.status === "pending") ?? null,
|
|
429
|
+
...(archivePath ? { archive_path: archivePath } : {}),
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
const active = array(doc, activeKey(artifact));
|
|
433
|
+
const archive = Array.isArray(doc.archive) ? doc.archive : [];
|
|
434
|
+
return {
|
|
435
|
+
active_count: active.length,
|
|
436
|
+
archive_count: archive.length,
|
|
437
|
+
next_number: nextEntryNumber(doc, activeKey(artifact)),
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function diffText(before, after, target) {
|
|
441
|
+
return unifiedDiff(splitLinesKeepEnds(before), splitLinesKeepEnds(after), target, target).join("");
|
|
442
|
+
}
|
|
443
|
+
function slug(value) {
|
|
444
|
+
return (String(value ?? "plan")
|
|
445
|
+
.replace(/^Plan:\s*/i, "")
|
|
446
|
+
.toLowerCase()
|
|
447
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
448
|
+
.replace(/^-|-$/g, "") || "plan");
|
|
449
|
+
}
|
|
450
|
+
function assertWriterBoundary(projectRoot, candidate, artifactId) {
|
|
451
|
+
try {
|
|
452
|
+
assertRealpathBoundary(projectRoot, candidate, artifactId);
|
|
453
|
+
}
|
|
454
|
+
catch (error) {
|
|
455
|
+
const message = error.message;
|
|
456
|
+
if (message.startsWith("artifact '"))
|
|
457
|
+
reject({ class: "unsupported_target", message });
|
|
458
|
+
throw error;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function archivePathFor(projectRoot, target, doc, bytes) {
|
|
462
|
+
const header = mapping(doc.header);
|
|
463
|
+
const created = String(header.created ?? "undated").replace(/[^0-9-]/g, "") || "undated";
|
|
464
|
+
const title = header.title ?? doc.title;
|
|
465
|
+
// Archive identity must survive a retry that crosses a calendar boundary.
|
|
466
|
+
const identity = createHash("sha256").update(bytes).digest("hex").slice(0, 16);
|
|
467
|
+
const archivePath = path.join(path.dirname(target), "archive", `PLAN-${created}-${slug(title)}-${identity}.yaml`);
|
|
468
|
+
assertWriterBoundary(projectRoot, archivePath, "plan archive");
|
|
469
|
+
return archivePath;
|
|
470
|
+
}
|
|
471
|
+
function latestArchivePath(archiveDirectory) {
|
|
472
|
+
if (!fs.existsSync(archiveDirectory))
|
|
473
|
+
return null;
|
|
474
|
+
const latest = fs
|
|
475
|
+
.readdirSync(archiveDirectory)
|
|
476
|
+
.filter((name) => name.startsWith("PLAN-") && name.endsWith(".yaml"))
|
|
477
|
+
.sort()
|
|
478
|
+
.at(-1);
|
|
479
|
+
return latest ? path.join(archiveDirectory, latest) : null;
|
|
480
|
+
}
|
|
481
|
+
function validatePlanCreateInput(input) {
|
|
482
|
+
const tasks = array(input, "tasks");
|
|
483
|
+
const numbers = tasks.map((task) => Number(task.number));
|
|
484
|
+
const expected = tasks.map((_, index) => index + 1);
|
|
485
|
+
if (!isDeepStrictEqual(numbers, expected)) {
|
|
486
|
+
reject({
|
|
487
|
+
class: "schema_violation",
|
|
488
|
+
message: "plan create task numbers must be unique and sequential starting from 1",
|
|
489
|
+
violations: ["PV1: task numbers must equal 1..N"],
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
if (mapping(input.header).status === "complete" &&
|
|
493
|
+
tasks.some((task) => task.status !== "complete")) {
|
|
494
|
+
reject({
|
|
495
|
+
class: "schema_violation",
|
|
496
|
+
message: "a complete plan cannot contain incomplete tasks",
|
|
497
|
+
violations: ["header.status complete requires every task complete"],
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
function canonicalPlanDocumentForWrite(doc) {
|
|
502
|
+
const header = mapping(doc.header);
|
|
503
|
+
const status = String(header.status ?? "");
|
|
504
|
+
if (status !== "active" && status !== "completed")
|
|
505
|
+
return doc;
|
|
506
|
+
const canonicalStatus = status === "active" || array(doc, "tasks").some((task) => task.status !== "complete")
|
|
507
|
+
? "open"
|
|
508
|
+
: "complete";
|
|
509
|
+
return { ...doc, header: { ...header, status: canonicalStatus } };
|
|
510
|
+
}
|
|
511
|
+
function canonicalPlanDocumentForArchive(doc) {
|
|
512
|
+
const candidate = structuredClone(doc);
|
|
513
|
+
const tasks = array(candidate, "tasks");
|
|
514
|
+
const complete = tasks.length > 0 && tasks.every((task) => task.status === "complete");
|
|
515
|
+
candidate.header = { ...mapping(candidate.header), status: complete ? "complete" : "open" };
|
|
516
|
+
return candidate;
|
|
517
|
+
}
|
|
518
|
+
function fsyncDirectory(directory) {
|
|
519
|
+
const fd = fs.openSync(directory, "r");
|
|
520
|
+
try {
|
|
521
|
+
fs.fsyncSync(fd);
|
|
522
|
+
}
|
|
523
|
+
finally {
|
|
524
|
+
fs.closeSync(fd);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
function ensureArchive(archivePath, bytes) {
|
|
528
|
+
const directory = path.dirname(archivePath);
|
|
529
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
530
|
+
const stage = path.join(directory, `.${path.basename(archivePath)}.writer.${process.pid}.${Date.now()}.tmp`);
|
|
531
|
+
let stageCreated = false;
|
|
532
|
+
let fd;
|
|
533
|
+
try {
|
|
534
|
+
fd = fs.openSync(stage, "wx");
|
|
535
|
+
stageCreated = true;
|
|
536
|
+
fs.writeFileSync(fd, bytes, "utf8");
|
|
537
|
+
fs.fsyncSync(fd);
|
|
538
|
+
fs.closeSync(fd);
|
|
539
|
+
fd = undefined;
|
|
540
|
+
try {
|
|
541
|
+
fs.linkSync(stage, archivePath);
|
|
542
|
+
fsyncDirectory(directory);
|
|
543
|
+
return true;
|
|
544
|
+
}
|
|
545
|
+
catch (error) {
|
|
546
|
+
if (error.code !== "EEXIST")
|
|
547
|
+
throw error;
|
|
548
|
+
if (fs.readFileSync(archivePath, "utf8") !== bytes) {
|
|
549
|
+
reject({
|
|
550
|
+
class: "conflict",
|
|
551
|
+
message: `archive path '${archivePath}' already exists with different content; historical archives are immutable`,
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
return false;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
finally {
|
|
558
|
+
if (fd !== undefined)
|
|
559
|
+
fs.closeSync(fd);
|
|
560
|
+
if (stageCreated) {
|
|
561
|
+
try {
|
|
562
|
+
fs.unlinkSync(stage);
|
|
563
|
+
fsyncDirectory(directory);
|
|
564
|
+
}
|
|
565
|
+
catch {
|
|
566
|
+
// A published archive is authoritative; a leftover private stage is ignored on retry.
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
function publishStagedPlan(stage, target) {
|
|
572
|
+
fs.renameSync(stage, target);
|
|
573
|
+
fsyncDirectory(path.dirname(target));
|
|
574
|
+
}
|
|
575
|
+
function removeCurrentPlan(target) {
|
|
576
|
+
fs.unlinkSync(target);
|
|
577
|
+
fsyncDirectory(path.dirname(target));
|
|
578
|
+
}
|
|
579
|
+
function stagingPath(req, target) {
|
|
580
|
+
const dir = req.dryRun ? path.join(req.projectRoot, ".agentera") : path.dirname(target);
|
|
581
|
+
if (!req.dryRun)
|
|
582
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
583
|
+
return path.join(dir, `.${path.basename(target)}.writer.${process.pid}.${Date.now()}.tmp`);
|
|
584
|
+
}
|
|
585
|
+
function planLifecycle(req, target, existing, legacyLifecycle = false) {
|
|
586
|
+
if (req.spec.verb === "archive") {
|
|
587
|
+
const archiveDir = path.join(path.dirname(target), "archive");
|
|
588
|
+
assertWriterBoundary(req.projectRoot, archiveDir, "plan archive");
|
|
589
|
+
if (!existing.bytes) {
|
|
590
|
+
const archivePath = latestArchivePath(archiveDir);
|
|
591
|
+
if (!archivePath)
|
|
592
|
+
reject({ class: "unsupported_target", message: "no active plan exists to archive" });
|
|
593
|
+
const archived = readExisting(archivePath);
|
|
594
|
+
return envelope(req, target, {}, mapping(archived.doc.header), {}, true, null, {
|
|
595
|
+
archivePath,
|
|
596
|
+
...(req.dryRun ? { diff: "", before: {}, after: {} } : {}),
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
const status = String(mapping(existing.doc.header).status ?? existing.doc.status ?? "");
|
|
600
|
+
const incomplete = status !== "complete" ||
|
|
601
|
+
array(existing.doc, "tasks").some((task) => task.status !== "complete");
|
|
602
|
+
if (incomplete && !req.force)
|
|
603
|
+
reject({
|
|
604
|
+
class: "conflict",
|
|
605
|
+
message: `active plan "${mapping(existing.doc.header).title ?? existing.doc.title ?? "untitled"}" has status ${status || "unknown"} or incomplete tasks; archiving would discard incomplete work`,
|
|
606
|
+
syntax: "agentera state plan archive --force",
|
|
607
|
+
});
|
|
608
|
+
const archiveDoc = canonicalPlanDocumentForArchive(existing.doc);
|
|
609
|
+
const archiveBytes = dumpYamlMapping(archiveDoc);
|
|
610
|
+
const archivePath = archivePathFor(req.projectRoot, target, archiveDoc, archiveBytes);
|
|
611
|
+
validatePlanPublicationCandidate(archiveBytes);
|
|
612
|
+
if (!req.dryRun) {
|
|
613
|
+
// Archive creation and current-plan removal cannot be one filesystem transaction.
|
|
614
|
+
// The durable archive is published first; retries remove the current plan only after
|
|
615
|
+
// they observe that exact immutable archive.
|
|
616
|
+
ensureArchive(archivePath, archiveBytes);
|
|
617
|
+
removeCurrentPlan(target);
|
|
618
|
+
}
|
|
619
|
+
return envelope(req, target, {}, mapping(archiveDoc.header), {}, false, null, {
|
|
620
|
+
archivePath,
|
|
621
|
+
diff: diffText(existing.bytes, "", target),
|
|
622
|
+
before: existing.doc,
|
|
623
|
+
after: {},
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
const input = structuredClone(req.input ?? {});
|
|
627
|
+
validatePlanCreateInput(input);
|
|
628
|
+
const candidateStatus = String(mapping(input.header).status ?? input.status ?? "");
|
|
629
|
+
if (!candidateStatus)
|
|
630
|
+
reject({ class: "schema_violation", message: "plan create input requires header.status" });
|
|
631
|
+
let archivePath;
|
|
632
|
+
let predecessorBytes = null;
|
|
633
|
+
if (existing.bytes) {
|
|
634
|
+
const oldStatus = String(mapping(existing.doc.header).status ?? existing.doc.status ?? "");
|
|
635
|
+
const existingWithoutLineage = structuredClone(existing.doc);
|
|
636
|
+
delete existingWithoutLineage.previous_plan_archived;
|
|
637
|
+
const sameWithoutLineage = isDeepStrictEqual(existingWithoutLineage, input);
|
|
638
|
+
if (sameWithoutLineage && !legacyLifecycle) {
|
|
639
|
+
validatePlanPublicationCandidate(dumpYamlMapping(existing.doc));
|
|
640
|
+
return envelope(req, target, existing.doc, mapping(existing.doc.header), {}, true, null, req.dryRun ? { diff: "", before: existing.doc, after: existing.doc } : {});
|
|
641
|
+
}
|
|
642
|
+
if (!sameWithoutLineage) {
|
|
643
|
+
if (oldStatus !== "complete" && !req.force)
|
|
644
|
+
reject({
|
|
645
|
+
class: "conflict",
|
|
646
|
+
message: `active plan "${mapping(existing.doc.header).title ?? existing.doc.title ?? "untitled"}" has status ${oldStatus || "unknown"}; replacing it would discard incomplete work`,
|
|
647
|
+
});
|
|
648
|
+
predecessorBytes = dumpYamlMapping(existing.doc);
|
|
649
|
+
archivePath = archivePathFor(req.projectRoot, target, existing.doc, predecessorBytes);
|
|
650
|
+
input.previous_plan_archived = path.relative(req.projectRoot, archivePath);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
const bytes = dumpYamlMapping(input);
|
|
654
|
+
if (predecessorBytes)
|
|
655
|
+
validatePlanPublicationCandidate(predecessorBytes);
|
|
656
|
+
validatePlanPublicationCandidate(bytes);
|
|
657
|
+
const finalDoc = loadYamlMapping(bytes);
|
|
658
|
+
if (!req.dryRun) {
|
|
659
|
+
const stage = stagingPath(req, target);
|
|
660
|
+
try {
|
|
661
|
+
fs.writeFileSync(stage, bytes);
|
|
662
|
+
// Archive and current replacement are deliberately two durable operations. If the
|
|
663
|
+
// process stops between them, retry sees the exact archive and converges on this plan.
|
|
664
|
+
if (predecessorBytes && archivePath)
|
|
665
|
+
ensureArchive(archivePath, predecessorBytes);
|
|
666
|
+
publishStagedPlan(stage, target);
|
|
667
|
+
}
|
|
668
|
+
finally {
|
|
669
|
+
try {
|
|
670
|
+
fs.unlinkSync(stage);
|
|
671
|
+
}
|
|
672
|
+
catch {
|
|
673
|
+
/* published or already removed */
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
return envelope(req, target, finalDoc, mapping(finalDoc.header), {}, false, null, {
|
|
678
|
+
archivePath,
|
|
679
|
+
diff: diffText(existing.bytes, bytes, target),
|
|
680
|
+
before: existing.doc,
|
|
681
|
+
after: finalDoc,
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
function envelope(req, target, finalDoc, written, assigned, replay, compaction, extra = {}) {
|
|
685
|
+
const result = {
|
|
686
|
+
schemaVersion: "agentera.stateWrite.v1",
|
|
687
|
+
command: `state ${req.artifact} ${req.spec.verb}`,
|
|
688
|
+
status: "pass",
|
|
689
|
+
artifact: req.artifact,
|
|
690
|
+
path: target,
|
|
691
|
+
operation: {
|
|
692
|
+
verb: req.spec.verb,
|
|
693
|
+
dry_run: req.dryRun,
|
|
694
|
+
idempotent_replay: replay,
|
|
695
|
+
forced: req.force,
|
|
696
|
+
},
|
|
697
|
+
assigned,
|
|
698
|
+
written,
|
|
699
|
+
state: stateSlice(req.artifact, finalDoc, extra.archivePath),
|
|
700
|
+
validation: { status: "pass", violations: [] },
|
|
701
|
+
compaction: compaction && req.artifact === "decisions"
|
|
702
|
+
? { ...compaction, protected_overflow_count: 0 }
|
|
703
|
+
: compaction,
|
|
704
|
+
};
|
|
705
|
+
if (req.dryRun && extra.diff !== undefined) {
|
|
706
|
+
result.diff = extra.diff;
|
|
707
|
+
result.before = extra.before ?? {};
|
|
708
|
+
result.after = extra.after ?? finalDoc;
|
|
709
|
+
}
|
|
710
|
+
return result;
|
|
711
|
+
}
|
|
712
|
+
export function executeStateWrite(req) {
|
|
713
|
+
assertWriterBoundary(req.projectRoot, path.join(req.projectRoot, ".agentera"), "writer lock");
|
|
714
|
+
const planPublication = req.artifact === "plan" && ["archive", "create"].includes(req.spec.verb);
|
|
715
|
+
const lock = req.dryRun && planPublication ? null : acquireWriterLock(req.projectRoot);
|
|
716
|
+
try {
|
|
717
|
+
const record = loadArtifactRegistry().get(req.artifact);
|
|
718
|
+
if (!record)
|
|
719
|
+
throw new Error(`artifact '${req.artifact}' is not registered`);
|
|
720
|
+
let target;
|
|
721
|
+
try {
|
|
722
|
+
target = resolveArtifactPath(record, req.projectRoot, { strictWrite: true });
|
|
723
|
+
}
|
|
724
|
+
catch (error) {
|
|
725
|
+
const message = error.message;
|
|
726
|
+
if (message.startsWith("artifact '"))
|
|
727
|
+
reject({ class: "unsupported_target", message });
|
|
728
|
+
throw error;
|
|
729
|
+
}
|
|
730
|
+
const existing = readExisting(target);
|
|
731
|
+
const legacyLifecycle = req.artifact === "plan" && ["active", "completed"].includes(String(mapping(existing.doc.header).status ?? ""));
|
|
732
|
+
if (legacyLifecycle)
|
|
733
|
+
existing.doc = canonicalPlanDocumentForWrite(existing.doc);
|
|
734
|
+
if (existing.bytes) {
|
|
735
|
+
const validationBytes = req.artifact === "plan" ? dumpYamlMapping(existing.doc) : existing.bytes;
|
|
736
|
+
const violations = validateArtifactBytes(req.artifact, validationBytes);
|
|
737
|
+
if (violations.length) {
|
|
738
|
+
throw new Error(`existing artifact '${target}' is schema-invalid: ${violations.join("; ")}; repair it before retrying`);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
if (req.artifact === "plan" && ["archive", "create"].includes(req.spec.verb))
|
|
742
|
+
return planLifecycle(req, target, existing, legacyLifecycle);
|
|
743
|
+
if (!existing.bytes && req.artifact === "plan")
|
|
744
|
+
reject({
|
|
745
|
+
class: "unsupported_target",
|
|
746
|
+
message: "no active plan exists; create one before appending a task",
|
|
747
|
+
example: "agentera state plan create --input plan.yaml",
|
|
748
|
+
});
|
|
749
|
+
const mutated = mutateCandidate(req, existing.doc);
|
|
750
|
+
if (mutated.replay)
|
|
751
|
+
return envelope(req, target, mutated.candidate, mutated.written, mutated.assigned, true, null, req.dryRun ? { diff: "", before: existing.doc, after: mutated.candidate } : {});
|
|
752
|
+
const candidateBytes = dumpYamlMapping(mutated.candidate);
|
|
753
|
+
const candidateViolations = validateArtifactBytes(req.artifact, candidateBytes);
|
|
754
|
+
if (candidateViolations.length)
|
|
755
|
+
schemaViolation(candidateViolations);
|
|
756
|
+
const stage = stagingPath(req, target);
|
|
757
|
+
let compaction = null;
|
|
758
|
+
try {
|
|
759
|
+
fs.writeFileSync(stage, candidateBytes);
|
|
760
|
+
if (req.spec.compacts)
|
|
761
|
+
compaction = compactYamlFile(stage, req.artifact);
|
|
762
|
+
const finalBytes = fs.readFileSync(stage, "utf8");
|
|
763
|
+
const finalViolations = validateArtifactBytes(req.artifact, finalBytes);
|
|
764
|
+
if (finalViolations.length)
|
|
765
|
+
throw new Error(`writer/compactor invariant failure: ${finalViolations.join("; ")}`);
|
|
766
|
+
const finalDoc = loadYamlMapping(finalBytes);
|
|
767
|
+
const diff = diffText(existing.bytes, finalBytes, target);
|
|
768
|
+
if (req.dryRun) {
|
|
769
|
+
return envelope(req, target, finalDoc, mutated.written, mutated.assigned, false, compaction, { diff, before: existing.doc, after: finalDoc });
|
|
770
|
+
}
|
|
771
|
+
fs.renameSync(stage, target);
|
|
772
|
+
return envelope(req, target, finalDoc, mutated.written, mutated.assigned, false, compaction);
|
|
773
|
+
}
|
|
774
|
+
finally {
|
|
775
|
+
try {
|
|
776
|
+
fs.unlinkSync(stage);
|
|
777
|
+
}
|
|
778
|
+
catch {
|
|
779
|
+
/* stage published or absent */
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
finally {
|
|
784
|
+
lock?.release();
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
//# sourceMappingURL=transaction.js.map
|