agentera 3.0.0-dev.4 → 3.0.0-dev.46
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/LICENSE +201 -0
- package/README.md +108 -22
- package/bundle/.agentera-npx-bundle.json +1 -1
- package/bundle/CHANGELOG.md +1351 -0
- package/bundle/DESIGN.md +229 -0
- package/bundle/LICENSE +201 -0
- package/bundle/README.md +143 -0
- package/bundle/UPGRADE.md +236 -0
- package/bundle/extract-corpus-parity.json +21 -0
- package/bundle/fixtures/routing/hybrid-corpus.yaml +154 -0
- package/bundle/references/adapters/package-publication.json +437 -0
- package/bundle/references/adapters/package-registry.yaml +434 -189
- package/bundle/references/adapters/package-surface-characterization.md +66 -35
- package/bundle/references/adapters/runtime-lifecycle-adapters.yaml +74 -0
- package/bundle/references/adapters/runtime-lifecycle-authority.yaml +62 -0
- package/bundle/references/adapters/runtime-lifecycle-operation-contract.yaml +84 -0
- package/bundle/references/adapters/runtime-retired-resources.yaml +333 -0
- package/bundle/references/analysis/evidence-tier-authority.yaml +518 -0
- package/bundle/references/analysis/verification-policy.yaml +191 -0
- package/bundle/references/artifacts/artifact-registry-interface-model.yaml +20 -10
- package/bundle/references/artifacts/glossary-entry-contract.yaml +1254 -0
- package/bundle/references/artifacts/state-storage-authority.yaml +2982 -0
- package/bundle/references/artifacts/verbosity-budget-authority.yaml +42 -0
- package/bundle/references/cli/app-lifecycle-vocabulary.yaml +7 -8
- package/bundle/references/cli/capability-instruction-contract.yaml +97 -59
- package/bundle/references/cli/hybrid-route-contract.yaml +438 -0
- package/bundle/references/cli/routing-model.md +155 -0
- package/bundle/references/cli/trigger-schema-enrichment.md +147 -0
- package/bundle/references/cli/update-channels.yaml +35 -2
- package/bundle/references/cli/vocabulary-index.yaml +23 -20
- package/bundle/references/cli/vocabulary.md +337 -366
- package/bundle/references/meta/retained-reference-authority.yaml +151 -0
- package/bundle/registry.json +14 -14
- package/bundle/skills/agentera/SKILL.md +218 -408
- package/bundle/skills/agentera/capabilities/audit/schemas/artifacts.yaml +84 -0
- package/bundle/skills/agentera/capabilities/{inspektera → audit}/schemas/exit.yaml +2 -2
- package/bundle/skills/agentera/capabilities/audit/schemas/triggers.yaml +25 -0
- package/bundle/skills/agentera/capabilities/{inspektera → audit}/schemas/validation.yaml +37 -18
- package/bundle/skills/agentera/capabilities/build/schemas/artifacts.yaml +102 -0
- package/bundle/skills/agentera/capabilities/{realisera → build}/schemas/exit.yaml +6 -5
- package/bundle/skills/agentera/capabilities/build/schemas/triggers.yaml +27 -0
- package/bundle/skills/agentera/capabilities/build/schemas/validation.yaml +176 -0
- package/bundle/skills/agentera/capabilities/{visualisera → design}/schemas/artifacts.yaml +12 -12
- package/bundle/skills/agentera/capabilities/{visualisera → design}/schemas/exit.yaml +5 -5
- package/bundle/skills/agentera/capabilities/design/schemas/triggers.yaml +16 -0
- package/bundle/skills/agentera/capabilities/{visualisera → design}/schemas/validation.yaml +7 -7
- package/bundle/skills/agentera/capabilities/discuss/schemas/artifacts.yaml +51 -0
- package/bundle/skills/agentera/capabilities/{resonera → discuss}/schemas/exit.yaml +2 -2
- package/bundle/skills/agentera/capabilities/discuss/schemas/triggers.yaml +20 -0
- package/bundle/skills/agentera/capabilities/discuss/schemas/validation.yaml +144 -0
- package/bundle/skills/agentera/capabilities/document/schemas/artifacts.yaml +80 -0
- package/bundle/skills/agentera/capabilities/document/schemas/triggers.yaml +16 -0
- package/bundle/skills/agentera/capabilities/{dokumentera → document}/schemas/validation.yaml +18 -18
- package/bundle/skills/agentera/capabilities/{optimera → optimize}/schemas/artifacts.yaml +18 -18
- package/bundle/skills/agentera/capabilities/{optimera → optimize}/schemas/exit.yaml +2 -2
- package/bundle/skills/agentera/capabilities/optimize/schemas/triggers.yaml +16 -0
- package/bundle/skills/agentera/capabilities/{optimera → optimize}/schemas/validation.yaml +9 -9
- package/bundle/skills/agentera/capabilities/orchestrate/schemas/artifacts.yaml +76 -0
- package/bundle/skills/agentera/capabilities/{orkestrera → orchestrate}/schemas/exit.yaml +9 -7
- package/bundle/skills/agentera/capabilities/orchestrate/schemas/triggers.yaml +23 -0
- package/bundle/skills/agentera/capabilities/orchestrate/schemas/validation.yaml +121 -0
- package/bundle/skills/agentera/capabilities/plan/schemas/artifacts.yaml +66 -0
- package/bundle/skills/agentera/capabilities/{planera → plan}/schemas/exit.yaml +2 -2
- package/bundle/skills/agentera/capabilities/plan/schemas/triggers.yaml +23 -0
- package/bundle/skills/agentera/capabilities/plan/schemas/validation.yaml +121 -0
- package/bundle/skills/agentera/capabilities/profile/schemas/artifacts.yaml +23 -0
- package/bundle/skills/agentera/capabilities/{profilera → profile}/schemas/exit.yaml +6 -5
- package/bundle/skills/agentera/capabilities/profile/schemas/triggers.yaml +20 -0
- package/bundle/skills/agentera/capabilities/profile/schemas/validation.yaml +115 -0
- package/bundle/skills/agentera/capabilities/research/schemas/artifacts.yaml +24 -0
- package/bundle/skills/agentera/capabilities/research/schemas/triggers.yaml +16 -0
- package/bundle/skills/agentera/capabilities/{inspirera → research}/schemas/validation.yaml +2 -2
- package/bundle/skills/agentera/capabilities/status/schemas/artifacts.yaml +73 -0
- package/bundle/skills/agentera/capabilities/status/schemas/triggers.yaml +22 -0
- package/bundle/skills/agentera/capabilities/{hej → status}/schemas/validation.yaml +5 -5
- package/bundle/skills/agentera/capabilities/{visionera → vision}/schemas/artifacts.yaml +16 -16
- package/bundle/skills/agentera/capabilities/{visionera → vision}/schemas/exit.yaml +7 -6
- package/bundle/skills/agentera/capabilities/vision/schemas/triggers.yaml +23 -0
- package/bundle/skills/agentera/capabilities/{visionera → vision}/schemas/validation.yaml +18 -20
- package/bundle/skills/agentera/capability_schema_contract.yaml +200 -37
- package/bundle/skills/agentera/protocol.yaml +31 -31
- package/bundle/skills/agentera/route-phrases.yaml +81 -0
- package/bundle/skills/agentera/schemas/artifacts/changelog.yaml +5 -4
- package/bundle/skills/agentera/schemas/artifacts/decisions.yaml +40 -22
- package/bundle/skills/agentera/schemas/artifacts/design.yaml +5 -4
- package/bundle/skills/agentera/schemas/artifacts/docs.yaml +15 -19
- package/bundle/skills/agentera/schemas/artifacts/experiments.yaml +145 -14
- package/bundle/skills/agentera/schemas/artifacts/glossary.yaml +82 -0
- package/bundle/skills/agentera/schemas/artifacts/health.yaml +58 -21
- package/bundle/skills/agentera/schemas/artifacts/objective.yaml +22 -8
- package/bundle/skills/agentera/schemas/artifacts/plan.yaml +421 -33
- package/bundle/skills/agentera/schemas/artifacts/progress.yaml +143 -53
- package/bundle/skills/agentera/schemas/artifacts/todo.yaml +345 -31
- package/bundle/skills/agentera/schemas/artifacts/vision.yaml +3 -3
- package/dist/analytics/extractCorpus/cli.js +190 -0
- package/dist/analytics/extractCorpus/copilotSessions.js +275 -0
- package/dist/analytics/extractCorpus/core.js +392 -0
- package/dist/analytics/extractCorpus/corpus.js +167 -0
- package/dist/analytics/extractCorpus/coverageAudit.js +260 -0
- package/dist/analytics/extractCorpus/cursorSessions.js +425 -0
- package/dist/analytics/extractCorpus/evidenceTiers.js +603 -0
- package/dist/analytics/extractCorpus/extractCorpusParity.js +105 -0
- package/dist/analytics/extractCorpus/filesystemSources.js +118 -0
- package/dist/analytics/extractCorpus/index.js +14 -0
- package/dist/analytics/extractCorpus/jsonlSessions.js +204 -0
- package/dist/analytics/extractCorpus/sqliteCaps.js +43 -0
- package/dist/analytics/extractCorpus/sqliteSessions.js +367 -0
- package/dist/analytics/extractCorpus/tierReader.js +108 -0
- package/dist/analytics/extractCorpus.js +2 -1791
- package/dist/analytics/glossaryAdviceResolution.js +166 -0
- package/dist/analytics/glossaryInputAcquisition.js +319 -0
- package/dist/analytics/personalGlossaryAdmission.js +133 -0
- package/dist/analytics/personalGlossaryProfile.js +219 -0
- package/dist/analytics/profileSignals.js +211 -0
- package/dist/analytics/usageStats.js +169 -42
- package/dist/audit/terminologyDrift.js +281 -0
- package/dist/bin/agentera.js +3 -2
- package/dist/capabilities/audit/instructions.js +16 -0
- package/dist/capabilities/build/instructions.js +56 -0
- package/dist/capabilities/design/instructions.js +4 -0
- package/dist/capabilities/discuss/instructions.js +29 -0
- package/dist/capabilities/document/instructions.js +11 -0
- package/dist/capabilities/index.js +40 -0
- package/dist/capabilities/optimize/instructions.js +14 -0
- package/dist/capabilities/orchestrate/instructions.js +40 -0
- package/dist/capabilities/plan/instructions.js +32 -0
- package/dist/capabilities/profile/instructions.js +70 -0
- package/dist/capabilities/research/instructions.js +5 -0
- package/dist/capabilities/status/instructions.js +11 -0
- package/dist/capabilities/status/startupInstructions.js +34 -0
- package/dist/capabilities/vision/instructions.js +4 -0
- package/dist/cli/appContext.js +30 -24
- package/dist/cli/argvalidate.js +0 -1
- package/dist/cli/capabilityContext/benchmark.js +565 -0
- package/dist/cli/capabilityContext/bespoke.js +44 -0
- package/dist/cli/capabilityContext/build.js +242 -0
- package/dist/cli/capabilityContext/closeout.js +233 -0
- package/dist/cli/capabilityContext/contract.js +179 -0
- package/dist/cli/capabilityContext/evidence.js +463 -0
- package/dist/cli/capabilityContext/index.js +3 -0
- package/dist/cli/capabilityContext/orchestration.js +131 -0
- package/dist/cli/capabilityContext/planState.js +260 -0
- package/dist/cli/capabilityContext/progress.js +142 -0
- package/dist/cli/capabilityContext/projectVerification.js +409 -0
- package/dist/cli/capabilityContext/shared.js +83 -0
- package/dist/cli/capabilityContext/slim.js +152 -0
- package/dist/cli/capabilityContext/startup.js +150 -0
- package/dist/cli/capabilityContext/startupAggregation.js +68 -0
- package/dist/cli/capabilityContext/types.js +56 -0
- package/dist/cli/capabilityContext.js +1 -2421
- package/dist/cli/commands/appHome.js +22 -0
- package/dist/cli/commands/capability.js +5 -12
- package/dist/cli/commands/compact.js +41 -13
- package/dist/cli/commands/doctor.js +127 -97
- package/dist/cli/commands/durability.js +81 -0
- package/dist/cli/commands/glossaryAdvice.js +138 -0
- package/dist/cli/commands/lint.js +26 -44
- package/dist/cli/commands/personalGlossary.js +176 -0
- package/dist/cli/commands/prime/briefOrientation.js +747 -0
- package/dist/cli/commands/prime/buildExecutionRequest.js +165 -0
- package/dist/cli/commands/prime/bundleStatus.js +190 -0
- package/dist/cli/commands/prime/collectEntityOrientation.js +311 -0
- package/dist/cli/commands/prime/collectOrientationState.js +212 -0
- package/dist/cli/commands/prime/orientationOutput.js +397 -0
- package/dist/cli/commands/prime/types.js +1 -0
- package/dist/cli/commands/prime/v1Migration.js +38 -0
- package/dist/cli/commands/prime.js +80 -558
- package/dist/cli/commands/profileGrounding.js +55 -0
- package/dist/cli/commands/query.js +78 -53
- package/dist/cli/commands/report.js +96 -25
- package/dist/cli/commands/route.js +142 -0
- package/dist/cli/commands/schema.js +266 -143
- package/dist/cli/commands/state/decisions.js +387 -0
- package/dist/cli/commands/state/docs.js +70 -0
- package/dist/cli/commands/state/experimentRecords.js +151 -0
- package/dist/cli/commands/state/experiments.js +14 -0
- package/dist/cli/commands/state/get.js +129 -0
- package/dist/cli/commands/state/health.js +14 -0
- package/dist/cli/commands/state/index.js +16 -0
- package/dist/cli/commands/state/list.js +194 -0
- package/dist/cli/commands/state/objective.js +25 -0
- package/dist/cli/commands/state/plan.js +14 -0
- package/dist/cli/commands/state/planTasks.js +154 -0
- package/dist/cli/commands/state/plans.js +154 -0
- package/dist/cli/commands/state/progress.js +13 -0
- package/dist/cli/commands/state/shared.js +14 -0
- package/dist/cli/commands/state/todo.js +42 -0
- package/dist/cli/commands/state/write.js +434 -0
- package/dist/cli/commands/upgrade.js +146 -5
- package/dist/cli/commands/upgradeVerify.js +118 -0
- package/dist/cli/commands/validate.js +272 -213
- package/dist/cli/commands/verify.js +24 -9
- package/dist/cli/contracts/bundleStatus.js +1 -0
- package/dist/cli/contracts/orientationState.js +1 -0
- package/dist/cli/dispatch/argvParser.js +32 -0
- package/dist/cli/dispatch/check.js +372 -0
- package/dist/cli/dispatch/commands.js +27 -0
- package/dist/cli/dispatch/index.js +207 -0
- package/dist/cli/dispatch/lifecycle.js +652 -0
- package/dist/cli/dispatch/prime.js +139 -0
- package/dist/cli/dispatch/projections.js +17 -0
- package/dist/cli/dispatch/shared.js +63 -0
- package/dist/cli/dispatch/state.js +140 -0
- package/dist/cli/dispatch.js +1 -996
- package/dist/cli/errors.js +52 -0
- package/dist/cli/help.js +390 -43
- package/dist/cli/migrationRequired.js +87 -0
- package/dist/cli/orientation/attention.js +59 -0
- package/dist/cli/orientation/corpusCoverage.js +102 -0
- package/dist/cli/orientation.js +444 -173
- package/dist/cli/planArtifacts.js +350 -0
- package/dist/cli/planEvidence.js +157 -0
- package/dist/cli/planLifecycleState.js +36 -0
- package/dist/cli/planTaskIndex.js +11 -0
- package/dist/cli/preCutoverCommand.js +32 -0
- package/dist/cli/prime-blob.js +71 -3
- package/dist/cli/profileAcquisition.js +167 -0
- package/dist/cli/startupCompletenessContract.js +59 -0
- package/dist/cli/stateQuery.js +63 -14
- package/dist/cli/structured.js +0 -1
- package/dist/cli/todoMarkdown.js +46 -0
- package/dist/cli/todoReadinessSelection.js +192 -0
- package/dist/cli/todoSeverity.js +18 -0
- package/dist/core/atomicWriter.js +20 -0
- package/dist/core/developmentChannel.js +1 -0
- package/dist/core/developmentInvocation.js +374 -0
- package/dist/core/difflib.js +0 -1
- package/dist/core/envPaths.js +20 -0
- package/dist/core/jsonValue.js +5 -0
- package/dist/core/paths.js +0 -1
- package/dist/core/pyjson.js +67 -3
- package/dist/core/shell.js +4 -0
- package/dist/core/skillIdentity.js +23 -0
- package/dist/core/sourceRoot.js +9 -12
- package/dist/core/text.js +10 -0
- package/dist/core/toml.js +0 -1
- package/dist/core/yaml.js +8 -1
- package/dist/eval/evalSkills.js +30 -26
- package/dist/eval/hybridRouteEvaluation.js +155 -0
- package/dist/eval/semanticEval.js +43 -20
- package/dist/eval/semanticFixtures.js +16 -5
- package/dist/hooks/common.js +11 -81
- package/dist/hooks/compaction/apply.js +446 -0
- package/dist/hooks/compaction/dryRun.js +184 -0
- package/dist/hooks/compaction/index.js +22 -0
- package/dist/hooks/compaction/parse.js +325 -0
- package/dist/hooks/compaction/retention.js +202 -0
- package/dist/hooks/compaction/status.js +360 -0
- package/dist/hooks/compaction/types.js +5 -0
- package/dist/hooks/validateArtifact/agentFacing.js +9 -0
- package/dist/hooks/validateArtifact/index.js +92 -0
- package/dist/hooks/validateArtifact/markdown.js +145 -0
- package/dist/hooks/validateArtifact/schema.js +546 -0
- package/dist/hooks/validateArtifact/traversal.js +107 -0
- package/dist/hooks/validateArtifact/violations.js +107 -0
- package/dist/migrate/v2HandoffManifest.js +452 -0
- package/dist/registries/activationContract.js +2 -0
- package/dist/registries/activationTuples.js +106 -0
- package/dist/registries/artifactProtocolIds.js +78 -0
- package/dist/registries/artifactRegistry.js +224 -63
- package/dist/registries/artifactSchemaProjection.js +45 -0
- package/dist/registries/capabilityContract.js +141 -13
- package/dist/registries/evaluatorHandoffContract.js +170 -0
- package/dist/registries/evidenceTierContract.js +371 -0
- package/dist/registries/glossaryAdviceContract.js +79 -0
- package/dist/registries/glossaryCaveatContract.js +67 -0
- package/dist/registries/glossaryConsumerContractValidation.js +787 -0
- package/dist/registries/glossaryEntryContract.js +757 -0
- package/dist/registries/glossaryTermIdentity.js +17 -0
- package/dist/registries/glossaryTermOccurrence.js +20 -0
- package/dist/registries/hybridRoute.js +274 -0
- package/dist/registries/hybridRouteReceipt.js +221 -0
- package/dist/registries/packagePublication.js +229 -0
- package/dist/registries/packageRegistry.js +187 -211
- package/dist/registries/todoReadinessContract.js +448 -0
- package/dist/registries/triggerLoader.js +174 -0
- package/dist/registries/verbosityBudgetContract.js +205 -0
- package/dist/release/releaseMetadata.js +385 -0
- package/dist/runtime/lifecycleAdapterContract.js +457 -0
- package/dist/runtime/lifecycleAdapters.js +777 -0
- package/dist/runtime/lifecycleAuthority.js +453 -0
- package/dist/runtime/lifecycleOperationContract.js +123 -0
- package/dist/runtime/lifecycleOperations.js +634 -0
- package/dist/runtime/lifecycleOwnershipJournal.js +622 -0
- package/dist/runtime/lifecyclePublication.js +415 -0
- package/dist/runtime/lifecycleSnapshot.js +438 -0
- package/dist/runtime/nativeResourceCleanup.js +502 -0
- package/dist/setup/opencode.js +20 -0
- package/dist/setup/opencodeConstants.js +1 -0
- package/dist/setup/sharedSkill.js +45 -0
- package/dist/setup/smokeChecks.js +21 -82
- package/dist/state/archiveDiscovery.js +580 -0
- package/dist/state/archivePublication.js +225 -0
- package/dist/state/archiveRecovery.js +237 -0
- package/dist/state/archiveReplay.js +53 -0
- package/dist/state/canonicalMigrationRecord.js +36 -0
- package/dist/state/changelog.js +221 -0
- package/dist/state/decisionEntities.js +367 -0
- package/dist/state/decisionLegacyValidation.js +215 -0
- package/dist/state/decisionMigrationProvenance.js +199 -0
- package/dist/state/decisionOverlay.js +254 -0
- package/dist/state/decisionRevision.js +256 -0
- package/dist/state/decisionRevisionMigration.js +89 -0
- package/dist/state/directRetrieval.js +323 -0
- package/dist/state/durability.js +324 -0
- package/dist/state/entityCutover.js +459 -0
- package/dist/state/entityCutoverGit.js +127 -0
- package/dist/state/entityGlossaryAuthority.js +13 -0
- package/dist/state/entityListProjection.js +187 -0
- package/dist/state/entityListRuntimeRegistry.js +85 -0
- package/dist/state/entityMigrationCausality.js +97 -0
- package/dist/state/entityMigrationIdentity.js +5 -0
- package/dist/state/entityMigrationPreview.js +846 -0
- package/dist/state/entityMigrationTodo.js +133 -0
- package/dist/state/entityPublicationContext.js +806 -0
- package/dist/state/entityRetrievalHelp.js +506 -0
- package/dist/state/entityStorage.js +896 -0
- package/dist/state/exactReplacementRecovery.js +18 -0
- package/dist/state/experimentArchive.js +63 -0
- package/dist/state/experimentIdentity.js +202 -0
- package/dist/state/healthEntities.js +262 -0
- package/dist/state/healthEntityValidation.js +18 -0
- package/dist/state/healthRepair.js +69 -0
- package/dist/state/installRoot.js +64 -25
- package/dist/state/legacyEntityCutoverEvidence.js +65 -0
- package/dist/state/legacyIdentity.js +47 -0
- package/dist/state/legacySummaryRecord.js +6 -0
- package/dist/state/listAccounting.js +54 -0
- package/dist/state/listClassification.js +17 -0
- package/dist/state/listCursor.js +42 -0
- package/dist/state/listRetrieval.js +781 -0
- package/dist/state/migrationSourceBinding.js +30 -0
- package/dist/state/objectiveExperimentEntities.js +322 -0
- package/dist/state/planEntities.js +530 -0
- package/dist/state/planIdentity.js +47 -0
- package/dist/state/planRetrieval.js +313 -0
- package/dist/state/planTaskRetrieval.js +294 -0
- package/dist/state/progressEntities.js +512 -0
- package/dist/state/progressGlossaryCaveat.js +168 -0
- package/dist/state/progressPublicationOrder.js +19 -0
- package/dist/state/projectRoot.js +62 -0
- package/dist/state/projectionPolicy.js +190 -0
- package/dist/state/retrievalAuthority.js +156 -0
- package/dist/state/safeProjectFile.js +155 -0
- package/dist/state/startupAnalysis/benchmark.js +432 -0
- package/dist/state/startupAnalysis/contract.js +160 -0
- package/dist/state/startupAnalysis/helpers.js +286 -0
- package/dist/state/startupAnalysis/index.js +6 -0
- package/dist/state/startupAnalysis/metrics.js +340 -0
- package/dist/state/startupAnalysis/records.js +198 -0
- package/dist/state/startupAnalysis/report.js +111 -0
- package/dist/state/startupAnalysis/threshold.js +512 -0
- package/dist/state/startupAnalysis.js +2 -1953
- package/dist/state/startupProjection.js +499 -0
- package/dist/state/stateMode.js +85 -0
- package/dist/state/stateStorageAuthority.js +47 -0
- package/dist/state/summaryEntityRead.js +25 -0
- package/dist/state/summaryMigrationProvenance.js +66 -0
- package/dist/state/summarySourceRowAuthority.js +36 -0
- package/dist/state/todoDocsEntities.js +1064 -0
- package/dist/state/todoDocsEntityValidation.js +158 -0
- package/dist/state/todoMarkdownProjection.js +51 -0
- package/dist/state/todoReconciliationActivation.js +132 -0
- package/dist/state/todoReconciliationInspection.js +173 -0
- package/dist/state/todoReconciliationRepair.js +170 -0
- package/dist/state/todoReconciliationTransaction.js +582 -0
- package/dist/state/write/assign.js +20 -0
- package/dist/state/write/candidateMutation.js +269 -0
- package/dist/state/write/errors.js +11 -0
- package/dist/state/write/experimentPublication.js +192 -0
- package/dist/state/write/explain.js +332 -0
- package/dist/state/write/fields.js +61 -0
- package/dist/state/write/glossaryPublication.js +263 -0
- package/dist/state/write/grammar.js +280 -0
- package/dist/state/write/helpers.js +29 -0
- package/dist/state/write/index.js +12 -0
- package/dist/state/write/input.js +367 -0
- package/dist/state/write/lock.js +837 -0
- package/dist/state/write/mutation.js +234 -0
- package/dist/state/write/operations.js +169 -0
- package/dist/state/write/planEvaluation.js +128 -0
- package/dist/state/write/planPublication.js +179 -0
- package/dist/state/write/runtimeOperations.js +142 -0
- package/dist/state/write/serialize.js +1 -0
- package/dist/state/write/transaction.js +52 -0
- package/dist/state/write/validate.js +7 -0
- package/dist/upgrade/appContentRefresh.js +383 -0
- package/dist/upgrade/appModel.js +8 -7
- package/dist/upgrade/atomicWriter.js +1 -0
- package/dist/upgrade/bundleEvidence.js +33 -0
- package/dist/upgrade/channels.js +12 -8
- package/dist/upgrade/compatibility.js +56 -21
- package/dist/upgrade/doctor.js +197 -192
- package/dist/upgrade/doctorClassifier.js +187 -0
- package/dist/upgrade/installedHooksRetirement.js +196 -0
- package/dist/upgrade/legacyAgentCleanup.js +282 -0
- package/dist/upgrade/lifecycleUpgrade.js +113 -0
- package/dist/upgrade/migrateArtifactsV2ToV3.js +367 -149
- package/dist/upgrade/migrationPublication.js +122 -0
- package/dist/upgrade/nextMajorDoctor.js +155 -0
- package/dist/upgrade/npxPlatformStatus.js +22 -0
- package/dist/upgrade/projectIntegration.js +145 -187
- package/dist/upgrade/projectIntegrationDecision.js +50 -0
- package/dist/upgrade/retiredResourceDiagnostics.js +117 -0
- package/dist/upgrade/runtimeMigration.js +278 -352
- package/dist/upgrade/upgradeCommands.js +14 -1
- package/dist/upgrade/upgradeLock.js +85 -0
- package/dist/upgrade/upgradeOrchestrator.js +263 -59
- package/dist/upgrade/v3CapabilitySurface.js +14 -0
- package/dist/upgrade/versionResolution.js +12 -5
- package/dist/validate/activationArtifactEvidence.js +844 -0
- package/dist/validate/activationConjunction.js +816 -0
- package/dist/validate/activationEvidenceManifest.js +515 -0
- package/dist/validate/activationPackageSemantics.js +29 -0
- package/dist/validate/appHomeContract.js +5 -11
- package/dist/validate/bootstrapAuthority.js +44 -0
- package/dist/validate/capability.js +144 -15
- package/dist/validate/crossCapability.js +15 -10
- package/dist/validate/retainedReferenceAuthority.js +879 -0
- package/dist/validate/selfAudit.js +73 -37
- package/dist/validate/v1LegacyCruft.js +131 -0
- package/dist/validate/vocabularyAuthority.js +303 -0
- package/package.json +53 -27
- package/bundle/references/adapters/cursor.md +0 -213
- package/bundle/references/adapters/opencode.md +0 -530
- package/bundle/references/adapters/package-manifest-interface-model.yaml +0 -337
- package/bundle/references/adapters/runtime-adapter-characterization.md +0 -79
- package/bundle/references/adapters/runtime-adapter-interface-model.yaml +0 -200
- package/bundle/references/adapters/runtime-adapter-registry.yaml +0 -548
- package/bundle/references/adapters/runtime-feature-parity.md +0 -189
- package/bundle/references/analysis/benchmark.md +0 -267
- package/bundle/references/analysis/startup-measurement-contract.yaml +0 -424
- package/bundle/references/cli/agent-ready-state-contract.yaml +0 -953
- package/bundle/references/cli/audience-namespace-cli-migration.yaml +0 -355
- package/bundle/references/cli/bundle-skill-vocabulary.yaml +0 -278
- package/bundle/references/cli/capability-tool-classification.yaml +0 -53
- package/bundle/references/cli/routing-execution-vocabulary.yaml +0 -281
- package/bundle/references/meta/documentation-inventory.md +0 -43
- 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/dokumentera/schemas/artifacts.yaml +0 -73
- package/bundle/skills/agentera/capabilities/dokumentera/schemas/triggers.yaml +0 -35
- package/bundle/skills/agentera/capabilities/hej/instructions.md +0 -331
- package/bundle/skills/agentera/capabilities/hej/schemas/artifacts.yaml +0 -69
- package/bundle/skills/agentera/capabilities/hej/schemas/triggers.yaml +0 -58
- package/bundle/skills/agentera/capabilities/inspektera/instructions.md +0 -514
- package/bundle/skills/agentera/capabilities/inspektera/schemas/artifacts.yaml +0 -76
- package/bundle/skills/agentera/capabilities/inspektera/schemas/triggers.yaml +0 -38
- 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/inspirera/schemas/triggers.yaml +0 -34
- package/bundle/skills/agentera/capabilities/optimera/instructions.md +0 -437
- package/bundle/skills/agentera/capabilities/optimera/schemas/triggers.yaml +0 -39
- package/bundle/skills/agentera/capabilities/orkestrera/instructions.md +0 -433
- package/bundle/skills/agentera/capabilities/orkestrera/schemas/artifacts.yaml +0 -64
- package/bundle/skills/agentera/capabilities/orkestrera/schemas/triggers.yaml +0 -42
- 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/triggers.yaml +0 -34
- 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/profilera/schemas/artifacts.yaml +0 -18
- package/bundle/skills/agentera/capabilities/profilera/schemas/triggers.yaml +0 -45
- package/bundle/skills/agentera/capabilities/profilera/schemas/validation.yaml +0 -57
- package/bundle/skills/agentera/capabilities/realisera/instructions.md +0 -403
- package/bundle/skills/agentera/capabilities/realisera/schemas/artifacts.yaml +0 -80
- package/bundle/skills/agentera/capabilities/realisera/schemas/triggers.yaml +0 -39
- package/bundle/skills/agentera/capabilities/realisera/schemas/validation.yaml +0 -110
- package/bundle/skills/agentera/capabilities/resonera/instructions.md +0 -329
- package/bundle/skills/agentera/capabilities/resonera/schemas/artifacts.yaml +0 -47
- package/bundle/skills/agentera/capabilities/resonera/schemas/triggers.yaml +0 -46
- package/bundle/skills/agentera/capabilities/resonera/schemas/validation.yaml +0 -77
- package/bundle/skills/agentera/capabilities/visionera/instructions.md +0 -309
- package/bundle/skills/agentera/capabilities/visionera/schemas/triggers.yaml +0 -41
- package/bundle/skills/agentera/capabilities/visualisera/instructions.md +0 -400
- package/bundle/skills/agentera/capabilities/visualisera/schemas/triggers.yaml +0 -33
- package/bundle/skills/agentera/references/contract.md +0 -1039
- 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/analytics/extractCorpus.js.map +0 -1
- package/dist/analytics/usageStats.js.map +0 -1
- package/dist/bin/agentera.js.map +0 -1
- package/dist/cli/appContext.js.map +0 -1
- package/dist/cli/argvalidate.js.map +0 -1
- package/dist/cli/capabilityContext.js.map +0 -1
- package/dist/cli/commands/backfill.js +0 -84
- package/dist/cli/commands/backfill.js.map +0 -1
- package/dist/cli/commands/capability.js.map +0 -1
- package/dist/cli/commands/compact.js.map +0 -1
- package/dist/cli/commands/doctor.js.map +0 -1
- package/dist/cli/commands/lint.js.map +0 -1
- package/dist/cli/commands/prime.js.map +0 -1
- package/dist/cli/commands/query.js.map +0 -1
- package/dist/cli/commands/report.js.map +0 -1
- package/dist/cli/commands/schema.js.map +0 -1
- package/dist/cli/commands/state.js +0 -1012
- package/dist/cli/commands/state.js.map +0 -1
- package/dist/cli/commands/upgrade.js.map +0 -1
- package/dist/cli/commands/validate.js.map +0 -1
- package/dist/cli/commands/verify.js.map +0 -1
- package/dist/cli/dispatch.js.map +0 -1
- package/dist/cli/help.js.map +0 -1
- package/dist/cli/orientation.js.map +0 -1
- package/dist/cli/prime-blob.js.map +0 -1
- package/dist/cli/stateQuery.js.map +0 -1
- package/dist/cli/structured.js.map +0 -1
- package/dist/core/difflib.js.map +0 -1
- package/dist/core/git.js +0 -43
- package/dist/core/git.js.map +0 -1
- package/dist/core/paths.js.map +0 -1
- package/dist/core/pyjson.js.map +0 -1
- package/dist/core/sourceRoot.js.map +0 -1
- package/dist/core/toml.js.map +0 -1
- package/dist/core/yaml.js.map +0 -1
- package/dist/eval/evalSkills.js.map +0 -1
- package/dist/eval/semanticEval.js.map +0 -1
- package/dist/eval/semanticFixtures.js.map +0 -1
- package/dist/hooks/common.js.map +0 -1
- package/dist/hooks/compaction.js +0 -935
- package/dist/hooks/compaction.js.map +0 -1
- package/dist/hooks/cursorPreToolUse.js +0 -19
- package/dist/hooks/cursorPreToolUse.js.map +0 -1
- package/dist/hooks/cursorSessionStart.js +0 -71
- package/dist/hooks/cursorSessionStart.js.map +0 -1
- package/dist/hooks/sessionStart.js +0 -209
- package/dist/hooks/sessionStart.js.map +0 -1
- package/dist/hooks/sessionStop.js +0 -212
- package/dist/hooks/sessionStop.js.map +0 -1
- package/dist/hooks/validateArtifact.js +0 -933
- package/dist/hooks/validateArtifact.js.map +0 -1
- package/dist/registries/artifactRegistry.js.map +0 -1
- package/dist/registries/capabilityContract.js.map +0 -1
- package/dist/registries/packageRegistry.js.map +0 -1
- package/dist/registries/runtimeAdapterRegistry.js +0 -315
- package/dist/registries/runtimeAdapterRegistry.js.map +0 -1
- package/dist/setup/codex.js +0 -1056
- package/dist/setup/codex.js.map +0 -1
- package/dist/setup/copilot.js +0 -227
- package/dist/setup/copilot.js.map +0 -1
- package/dist/setup/cursor.js +0 -127
- package/dist/setup/cursor.js.map +0 -1
- package/dist/setup/doctor.js +0 -1297
- package/dist/setup/doctor.js.map +0 -1
- package/dist/setup/smokeChecks.js.map +0 -1
- package/dist/state/installRoot.js.map +0 -1
- package/dist/state/progressCommit.js +0 -289
- package/dist/state/progressCommit.js.map +0 -1
- package/dist/state/startupAnalysis.js.map +0 -1
- package/dist/upgrade/appModel.js.map +0 -1
- package/dist/upgrade/channels.js.map +0 -1
- package/dist/upgrade/compatibility.js.map +0 -1
- package/dist/upgrade/doctor.js.map +0 -1
- package/dist/upgrade/migrateArtifactsV1ToV2.js +0 -571
- package/dist/upgrade/migrateArtifactsV1ToV2.js.map +0 -1
- package/dist/upgrade/migrateArtifactsV2ToV3.js.map +0 -1
- package/dist/upgrade/projectIntegration.js.map +0 -1
- package/dist/upgrade/runtimeMigration.js.map +0 -1
- package/dist/upgrade/upgradeCommands.js.map +0 -1
- package/dist/upgrade/upgradeOrchestrator.js.map +0 -1
- package/dist/upgrade/versionResolution.js.map +0 -1
- package/dist/validate/appHomeContract.js.map +0 -1
- package/dist/validate/capability.js.map +0 -1
- package/dist/validate/crossCapability.js.map +0 -1
- package/dist/validate/lifecycleAdapters.js +0 -772
- package/dist/validate/lifecycleAdapters.js.map +0 -1
- package/dist/validate/selfAudit.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,154 @@
|
|
|
1
|
+
import YAML from "yaml";
|
|
2
|
+
import { StateRetrievalFailure } from "../../../state/directRetrieval.js";
|
|
3
|
+
import { getPlanEntity, listPlanEntities } from "../../../state/planEntities.js";
|
|
4
|
+
import { emitStructured } from "../../structured.js";
|
|
5
|
+
import { entityListFamily, entityListValidValues } from "../../../state/entityRetrievalHelp.js";
|
|
6
|
+
function requestedFormat(argv) {
|
|
7
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
8
|
+
const token = argv[index];
|
|
9
|
+
const value = token === "--format" ? argv[index + 1] : token.startsWith("--format=") ? token.slice(9) : undefined;
|
|
10
|
+
if (value === "json" || value === "yaml")
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
return "text";
|
|
14
|
+
}
|
|
15
|
+
function failure(message, verb) {
|
|
16
|
+
const list = verb === "list";
|
|
17
|
+
const family = entityListFamily("plans");
|
|
18
|
+
return new StateRetrievalFailure({
|
|
19
|
+
schemaVersion: "agentera.stateFailure.v1",
|
|
20
|
+
status: "fail",
|
|
21
|
+
error: {
|
|
22
|
+
class: "invalid_request",
|
|
23
|
+
message,
|
|
24
|
+
syntax: list
|
|
25
|
+
? family.syntax
|
|
26
|
+
: family.get,
|
|
27
|
+
example: list
|
|
28
|
+
? family.example
|
|
29
|
+
: "agentera state plan get --id qjtrmnpvka --format json",
|
|
30
|
+
recovery: list ? `Run \`${family.example}\`; no state was changed.` : "Correct the command using one of the valid forms and retry; no state was changed.",
|
|
31
|
+
valid_values: list
|
|
32
|
+
? entityListValidValues(family)
|
|
33
|
+
: ["get", "--id ID", "--format text|json|yaml"],
|
|
34
|
+
},
|
|
35
|
+
}, 2);
|
|
36
|
+
}
|
|
37
|
+
function readValue(argv, index, name) {
|
|
38
|
+
const token = argv[index];
|
|
39
|
+
if (token.startsWith(`${name}=`))
|
|
40
|
+
return { value: token.slice(name.length + 1), next: index + 1 };
|
|
41
|
+
const value = argv[index + 1];
|
|
42
|
+
if (!value || value.startsWith("--"))
|
|
43
|
+
throw new Error(`${name} requires a value`);
|
|
44
|
+
return { value, next: index + 2 };
|
|
45
|
+
}
|
|
46
|
+
function parse(argv, verb) {
|
|
47
|
+
const family = entityListFamily("plans");
|
|
48
|
+
let format = "text";
|
|
49
|
+
let limit = family.bounds.default;
|
|
50
|
+
let cursor;
|
|
51
|
+
let id;
|
|
52
|
+
let status;
|
|
53
|
+
const selector = {};
|
|
54
|
+
const seen = new Set();
|
|
55
|
+
for (let index = 0; index < argv.length;) {
|
|
56
|
+
const token = argv[index];
|
|
57
|
+
if (verb === "list" && token === "--ids-only") {
|
|
58
|
+
if (selector.idsOnly)
|
|
59
|
+
throw failure("--ids-only may only be supplied once", verb);
|
|
60
|
+
selector.idsOnly = true;
|
|
61
|
+
index += 1;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const allowed = verb === "list" ? ["--format", "--limit", "--cursor", "--status", "--fields"] : ["--format", "--id"];
|
|
65
|
+
const name = allowed.find((flag) => token === flag || token.startsWith(`${flag}=`));
|
|
66
|
+
if (!name) {
|
|
67
|
+
throw failure(`unrecognized argument '${token}'`, verb);
|
|
68
|
+
}
|
|
69
|
+
if (seen.has(name))
|
|
70
|
+
throw failure(`${name} may only be supplied once`, verb);
|
|
71
|
+
seen.add(name);
|
|
72
|
+
let parsed;
|
|
73
|
+
try {
|
|
74
|
+
parsed = readValue(argv, index, name);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
throw failure(error.message, verb);
|
|
78
|
+
}
|
|
79
|
+
index = parsed.next;
|
|
80
|
+
if (name === "--format") {
|
|
81
|
+
if (!family.formats.includes(parsed.value))
|
|
82
|
+
throw failure(`invalid --format '${parsed.value}'`, verb);
|
|
83
|
+
format = parsed.value;
|
|
84
|
+
}
|
|
85
|
+
else if (name === "--limit") {
|
|
86
|
+
if (!/^[1-9][0-9]*$/.test(parsed.value) || Number(parsed.value) < family.bounds.minimum || Number(parsed.value) > family.bounds.maximum)
|
|
87
|
+
throw failure(`--limit must be an integer from ${family.bounds.minimum} through ${family.bounds.maximum}`, verb);
|
|
88
|
+
limit = Number(parsed.value);
|
|
89
|
+
}
|
|
90
|
+
else if (name === "--cursor")
|
|
91
|
+
cursor = parsed.value;
|
|
92
|
+
else if (name === "--fields")
|
|
93
|
+
selector.fields = parsed.value;
|
|
94
|
+
else if (name === "--status") {
|
|
95
|
+
const validStatuses = family.filters.find(({ name }) => name === "status")?.values;
|
|
96
|
+
if (!Array.isArray(validStatuses) || !validStatuses.includes(parsed.value))
|
|
97
|
+
throw failure(`invalid --status '${parsed.value}'`, verb);
|
|
98
|
+
status = parsed.value;
|
|
99
|
+
}
|
|
100
|
+
else
|
|
101
|
+
id = parsed.value;
|
|
102
|
+
}
|
|
103
|
+
return { format, limit, ...(cursor ? { cursor } : {}), ...(id ? { id } : {}), ...(status ? { status } : {}), selector };
|
|
104
|
+
}
|
|
105
|
+
function emitFailure(error, format, io) {
|
|
106
|
+
if (format === "json" || format === "yaml")
|
|
107
|
+
emitStructured(error.body, format, io.out ?? ((text) => process.stdout.write(text)));
|
|
108
|
+
else {
|
|
109
|
+
const detail = error.body.error;
|
|
110
|
+
(io.err ?? ((text) => process.stderr.write(text)))([
|
|
111
|
+
`Error: ${detail.message}`,
|
|
112
|
+
`Class: ${detail.class}`,
|
|
113
|
+
`Valid forms: ${(detail.valid_values ?? [detail.syntax]).join("; ")}`,
|
|
114
|
+
`Example: ${detail.example}`,
|
|
115
|
+
`Recovery: ${detail.recovery}`,
|
|
116
|
+
].join("\n") + "\n");
|
|
117
|
+
}
|
|
118
|
+
return error.exitCode;
|
|
119
|
+
}
|
|
120
|
+
export function runPlans(argv, io) {
|
|
121
|
+
const format = requestedFormat(argv);
|
|
122
|
+
const verb = argv[0];
|
|
123
|
+
if (verb !== "list" && verb !== "get")
|
|
124
|
+
return emitFailure(failure(`expected 'list' or 'get', received '${verb ?? "nothing"}'`, "list"), format, io);
|
|
125
|
+
try {
|
|
126
|
+
const args = parse(argv.slice(1), verb);
|
|
127
|
+
if (verb === "get" && !args.id)
|
|
128
|
+
throw failure("entity mode requires --id ID", verb);
|
|
129
|
+
const response = verb === "list"
|
|
130
|
+
? listPlanEntities(process.cwd(), args.limit, args.cursor, { format: args.format, selector: args.selector, ...(args.status ? { statuses: [args.status] } : {}) })
|
|
131
|
+
: getPlanEntity(process.cwd(), args.id);
|
|
132
|
+
const output = io.out ?? ((text) => process.stdout.write(text));
|
|
133
|
+
if (args.format === "json" || args.format === "yaml")
|
|
134
|
+
emitStructured(response, args.format, output);
|
|
135
|
+
else
|
|
136
|
+
output(YAML.stringify(response));
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
if (error instanceof StateRetrievalFailure)
|
|
141
|
+
return emitFailure(error, format, io);
|
|
142
|
+
return emitFailure(new StateRetrievalFailure({
|
|
143
|
+
schemaVersion: "agentera.stateFailure.v1",
|
|
144
|
+
status: "fail",
|
|
145
|
+
error: {
|
|
146
|
+
class: "unsupported_state",
|
|
147
|
+
message: error.message,
|
|
148
|
+
syntax: "agentera state plan {list|get} [options]",
|
|
149
|
+
example: "agentera state plan list --format json",
|
|
150
|
+
recovery: "Use supported plan state and retry; no state was changed.",
|
|
151
|
+
},
|
|
152
|
+
}, 1), format, io);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { emitStructured } from "../../structured.js";
|
|
2
|
+
import { listProgressEntities, renderProgressEntityListText } from "../../../state/progressEntities.js";
|
|
3
|
+
import { out } from "./shared.js";
|
|
4
|
+
export function queryProgress(args, _schemas, io) {
|
|
5
|
+
const format = (args.format ?? "text");
|
|
6
|
+
const response = listProgressEntities(process.cwd(), args.limit ?? undefined, { topic: args.topic, status: args.status }, args.cursor ?? undefined, { format });
|
|
7
|
+
const output = out(io);
|
|
8
|
+
if (format === "text")
|
|
9
|
+
output(renderProgressEntityListText(response));
|
|
10
|
+
else
|
|
11
|
+
emitStructured(response, format, output);
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types and helpers for the per-state-family query modules.
|
|
3
|
+
*
|
|
4
|
+
* The state command family is split into one module per state
|
|
5
|
+
* artifact (plan, progress, health, docs, objective, experiments,
|
|
6
|
+
* todo, decisions). They all share the StateArgs/Io shape and the
|
|
7
|
+
* stdout/stderr write helpers.
|
|
8
|
+
*/
|
|
9
|
+
export function out(io) {
|
|
10
|
+
return io.out ?? ((t) => process.stdout.write(t));
|
|
11
|
+
}
|
|
12
|
+
export function err(io) {
|
|
13
|
+
return io.err ?? ((t) => process.stderr.write(t));
|
|
14
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { emitStructured } from "../../structured.js";
|
|
2
|
+
import { TODO_SEVERITY_ORDER_KEYS } from "../../todoSeverity.js";
|
|
3
|
+
import { renderTodoPublicRecord } from "../../todoMarkdown.js";
|
|
4
|
+
import { StateRetrievalFailure } from "../../../state/directRetrieval.js";
|
|
5
|
+
import { listTodoDocsEntities } from "../../../state/todoDocsEntities.js";
|
|
6
|
+
import YAML from "yaml";
|
|
7
|
+
import { err, out } from "./shared.js";
|
|
8
|
+
export function normalizeSeverity(value, deflt = "normal") {
|
|
9
|
+
const text = String(value || deflt).toLowerCase();
|
|
10
|
+
for (const key of TODO_SEVERITY_ORDER_KEYS) {
|
|
11
|
+
if (text.includes(key))
|
|
12
|
+
return key;
|
|
13
|
+
}
|
|
14
|
+
return deflt;
|
|
15
|
+
}
|
|
16
|
+
export function queryTodo(args, _schemas, io, openOnly = false) {
|
|
17
|
+
const output = out(io);
|
|
18
|
+
const format = args.format ?? "text";
|
|
19
|
+
try {
|
|
20
|
+
const response = listTodoDocsEntities(process.cwd(), "todo", args.limit ?? undefined, undefined, {
|
|
21
|
+
...(args.severity ? { severity: args.severity } : {}),
|
|
22
|
+
...(args.status ? { status: args.status } : {}),
|
|
23
|
+
...(openOnly ? { status: "open" } : {}),
|
|
24
|
+
}, { format });
|
|
25
|
+
if (format === "json" || format === "yaml")
|
|
26
|
+
emitStructured(response, format, output);
|
|
27
|
+
else
|
|
28
|
+
for (const entry of response.entries) {
|
|
29
|
+
output(`[${entry.record.severity}] ${entry.id} ${entry.record.status}: ${renderTodoPublicRecord(entry.record)}\n`);
|
|
30
|
+
}
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (!(error instanceof StateRetrievalFailure))
|
|
35
|
+
throw error;
|
|
36
|
+
if (format === "json" || format === "yaml")
|
|
37
|
+
emitStructured(error.body, format, output);
|
|
38
|
+
else
|
|
39
|
+
err(io)(YAML.stringify(error.body));
|
|
40
|
+
return error.exitCode;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { emitInvalidInput } from "../../errors.js";
|
|
4
|
+
import { emitStructured } from "../../structured.js";
|
|
5
|
+
import { StateRetrievalFailure } from "../../../state/directRetrieval.js";
|
|
6
|
+
import { normalizeArtifactProtocolId, VALIDATE_ARTIFACT_PROTOCOL_IDS, } from "../../../registries/artifactProtocolIds.js";
|
|
7
|
+
import { buildExplain, buildExplainAll, assertMutationGrammarParity, exampleFor, executeStateWrite, isWritableArtifact, loadStructuredInput, operationSpec, projectedFields, renderExplainText, StateWriteInputError, verbsForArtifact, WRITABLE_ARTIFACTS, } from "../../../state/write/index.js";
|
|
8
|
+
function formatFromArgv(argv) {
|
|
9
|
+
for (let i = 0; i < argv.length; i++) {
|
|
10
|
+
if (argv[i] === "--format" && argv[i + 1] === "json")
|
|
11
|
+
return "json";
|
|
12
|
+
if (argv[i] === "--format=json")
|
|
13
|
+
return "json";
|
|
14
|
+
}
|
|
15
|
+
return "text";
|
|
16
|
+
}
|
|
17
|
+
function invalid(body) {
|
|
18
|
+
throw new StateWriteInputError(body);
|
|
19
|
+
}
|
|
20
|
+
function emitRetrievalFailure(error, format, io) {
|
|
21
|
+
if (format === "json") {
|
|
22
|
+
emitStructured(error.body, "json", io.out ?? ((text) => process.stdout.write(text)));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const detail = error.body.error;
|
|
26
|
+
(io.err ?? ((text) => process.stderr.write(text)))([
|
|
27
|
+
`Error: ${detail.message}`,
|
|
28
|
+
`Syntax: ${detail.syntax}`,
|
|
29
|
+
`Example: ${detail.example}`,
|
|
30
|
+
`Recovery: ${detail.recovery}`,
|
|
31
|
+
].join("\n") + "\n");
|
|
32
|
+
}
|
|
33
|
+
return error.exitCode;
|
|
34
|
+
}
|
|
35
|
+
function setNested(target, field, value) {
|
|
36
|
+
const parts = field.split(".");
|
|
37
|
+
let cursor = target;
|
|
38
|
+
for (const part of parts.slice(0, -1)) {
|
|
39
|
+
if (!cursor[part] || typeof cursor[part] !== "object" || Array.isArray(cursor[part]))
|
|
40
|
+
cursor[part] = {};
|
|
41
|
+
cursor = cursor[part];
|
|
42
|
+
}
|
|
43
|
+
cursor[parts.at(-1)] = value;
|
|
44
|
+
}
|
|
45
|
+
function hasNested(target, field) {
|
|
46
|
+
let value = target;
|
|
47
|
+
for (const part of field.split(".")) {
|
|
48
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
49
|
+
return false;
|
|
50
|
+
if (!(part in value))
|
|
51
|
+
return false;
|
|
52
|
+
value = value[part];
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
function readFlag(argv, index) {
|
|
57
|
+
const token = argv[index];
|
|
58
|
+
const equals = token.indexOf("=");
|
|
59
|
+
if (equals > 0)
|
|
60
|
+
return { name: token.slice(0, equals), value: token.slice(equals + 1), consumed: 1 };
|
|
61
|
+
return { name: token, value: argv[index + 1] ?? null, consumed: 2 };
|
|
62
|
+
}
|
|
63
|
+
function converted(field, raw) {
|
|
64
|
+
if (field.kind === "boolean") {
|
|
65
|
+
if (raw !== "true" && raw !== "false")
|
|
66
|
+
invalid({
|
|
67
|
+
class: "invalid_choice",
|
|
68
|
+
message: `argument ${field.flag}: expected true or false, got '${raw}'`,
|
|
69
|
+
valid_values: ["true", "false"],
|
|
70
|
+
});
|
|
71
|
+
return raw === "true";
|
|
72
|
+
}
|
|
73
|
+
if (field.kind === "integer") {
|
|
74
|
+
const number = Number(raw);
|
|
75
|
+
if (!Number.isInteger(number))
|
|
76
|
+
invalid({
|
|
77
|
+
class: "invalid_int",
|
|
78
|
+
message: `argument ${field.flag}: invalid int value: '${raw}'`,
|
|
79
|
+
syntax: `${field.flag} N`,
|
|
80
|
+
});
|
|
81
|
+
return number;
|
|
82
|
+
}
|
|
83
|
+
if (field.kind === "date" && !/^\d{4}-\d{2}-\d{2}$/.test(raw)) {
|
|
84
|
+
invalid({
|
|
85
|
+
class: "invalid_format",
|
|
86
|
+
message: `argument ${field.flag}: expected YYYY-MM-DD, got '${raw}'`,
|
|
87
|
+
syntax: `${field.flag} YYYY-MM-DD`,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (field.kind === "datetime" && !/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/.test(raw)) {
|
|
91
|
+
invalid({
|
|
92
|
+
class: "invalid_format",
|
|
93
|
+
message: `argument ${field.flag}: expected YYYY-MM-DD HH:MM, got '${raw}'`,
|
|
94
|
+
syntax: `${field.flag} "YYYY-MM-DD HH:MM"`,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (field.validValues && !field.validValues.includes(raw)) {
|
|
98
|
+
const privacySafe = field.field.startsWith("glossary_caveat.");
|
|
99
|
+
invalid({
|
|
100
|
+
class: "invalid_choice",
|
|
101
|
+
message: privacySafe
|
|
102
|
+
? `argument ${field.flag}: invalid bounded glossary caveat value`
|
|
103
|
+
: `argument ${field.flag}: invalid choice: '${raw}' (choose from ${field.validValues.map((v) => `'${v}'`).join(", ")})`,
|
|
104
|
+
valid_values: field.validValues,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return raw;
|
|
108
|
+
}
|
|
109
|
+
function artifactOrReject(raw) {
|
|
110
|
+
const normalized = normalizeArtifactProtocolId(raw);
|
|
111
|
+
if (normalized === null) {
|
|
112
|
+
invalid({
|
|
113
|
+
class: "unsupported_target",
|
|
114
|
+
message: `unsupported artifact "${raw}"; valid artifact_id values: ${VALIDATE_ARTIFACT_PROTOCOL_IDS.join(", ")}`,
|
|
115
|
+
valid_values: [...WRITABLE_ARTIFACTS],
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (!isWritableArtifact(normalized)) {
|
|
119
|
+
invalid({
|
|
120
|
+
class: "unsupported_target",
|
|
121
|
+
message: `artifact "${normalized}" is read-only through the state writer`,
|
|
122
|
+
valid_values: [...WRITABLE_ARTIFACTS],
|
|
123
|
+
example: "agentera state progress append --input progress.yaml --format json",
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return normalized;
|
|
127
|
+
}
|
|
128
|
+
function specOrReject(artifact, verb) {
|
|
129
|
+
const spec = operationSpec(artifact, verb);
|
|
130
|
+
if (!spec) {
|
|
131
|
+
const retrievalVerbs = artifact === "plan" ? ["list", "get", "tasks"] : artifact === "experiments" ? ["list", "get"] : [];
|
|
132
|
+
invalid({
|
|
133
|
+
class: "invalid_choice",
|
|
134
|
+
message: `verb "${verb}" does not apply to ${artifact}`,
|
|
135
|
+
valid_values: [...retrievalVerbs, ...verbsForArtifact(artifact)],
|
|
136
|
+
example: artifact === "experiments"
|
|
137
|
+
? "agentera state experiments list --objective OBJECTIVE_ID --format json"
|
|
138
|
+
: `agentera state ${artifact} ${artifact === "plan" ? "list --format json" : "explain --format json"}`,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return spec;
|
|
142
|
+
}
|
|
143
|
+
function parseWrite(artifactRaw, argv) {
|
|
144
|
+
const artifact = artifactOrReject(artifactRaw);
|
|
145
|
+
const verb = argv[0];
|
|
146
|
+
if (!verb)
|
|
147
|
+
invalid({
|
|
148
|
+
class: "missing_argument",
|
|
149
|
+
message: `write verb is required for ${artifact}`,
|
|
150
|
+
valid_values: verbsForArtifact(artifact),
|
|
151
|
+
});
|
|
152
|
+
const spec = specOrReject(artifact, verb);
|
|
153
|
+
let initialProjectRoot = process.cwd();
|
|
154
|
+
for (let index = 1; index < argv.length; index += 1) {
|
|
155
|
+
const token = argv[index];
|
|
156
|
+
if (token === "--project" && argv[index + 1])
|
|
157
|
+
initialProjectRoot = path.resolve(argv[index + 1]);
|
|
158
|
+
else if (token.startsWith("--project="))
|
|
159
|
+
initialProjectRoot = path.resolve(token.slice("--project=".length));
|
|
160
|
+
}
|
|
161
|
+
const fields = projectedFields(spec);
|
|
162
|
+
const byFlag = new Map(fields.map((field) => [field.flag, field]));
|
|
163
|
+
const values = {};
|
|
164
|
+
const callerPayload = {};
|
|
165
|
+
const occurrences = new Map();
|
|
166
|
+
let format = "text";
|
|
167
|
+
let projectRoot = initialProjectRoot;
|
|
168
|
+
let dryRun = false;
|
|
169
|
+
let force = false;
|
|
170
|
+
let inputSource = null;
|
|
171
|
+
for (let i = 1; i < argv.length;) {
|
|
172
|
+
const token = argv[i];
|
|
173
|
+
if (!token.startsWith("--"))
|
|
174
|
+
invalid({ class: "unrecognized_argument", message: `unrecognized arguments: ${token}` });
|
|
175
|
+
if (token === "--dry-run") {
|
|
176
|
+
dryRun = true;
|
|
177
|
+
i += 1;
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (token === "--force") {
|
|
181
|
+
force = true;
|
|
182
|
+
i += 1;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const bareBoolean = byFlag.get(token);
|
|
186
|
+
if (bareBoolean?.kind === "boolean") {
|
|
187
|
+
if ((occurrences.get(token) ?? 0) > 0)
|
|
188
|
+
invalid({ class: "mutually_exclusive", message: `${token} may only be supplied once` });
|
|
189
|
+
occurrences.set(token, 1);
|
|
190
|
+
setNested(values, bareBoolean.field, true);
|
|
191
|
+
setNested(callerPayload, bareBoolean.field, true);
|
|
192
|
+
i += 1;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
const parsed = readFlag(argv, i);
|
|
196
|
+
if (parsed.value === null || parsed.value.startsWith("--"))
|
|
197
|
+
invalid({
|
|
198
|
+
class: "missing_argument",
|
|
199
|
+
message: `${parsed.name} requires a value`,
|
|
200
|
+
syntax: `${parsed.name} VALUE`,
|
|
201
|
+
});
|
|
202
|
+
i += parsed.consumed;
|
|
203
|
+
if (parsed.name === "--format") {
|
|
204
|
+
if (parsed.value !== "text" && parsed.value !== "json")
|
|
205
|
+
invalid({
|
|
206
|
+
class: "invalid_choice",
|
|
207
|
+
message: `argument --format: invalid choice: '${parsed.value}' (choose from 'text', 'json')`,
|
|
208
|
+
valid_values: ["text", "json"],
|
|
209
|
+
});
|
|
210
|
+
format = parsed.value;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (parsed.name === "--project") {
|
|
214
|
+
projectRoot = path.resolve(parsed.value);
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (parsed.name === "--input") {
|
|
218
|
+
if (inputSource !== null)
|
|
219
|
+
invalid({ class: "mutually_exclusive", message: "--input may only be supplied once" });
|
|
220
|
+
inputSource = parsed.value;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (artifact === "decisions" && verb === "append" && parsed.name === "--number") {
|
|
224
|
+
invalid({
|
|
225
|
+
class: "unrecognized_argument",
|
|
226
|
+
message: "--number is assigned by the CLI on append and cannot be supplied",
|
|
227
|
+
example: exampleFor(artifact, verb),
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
const field = byFlag.get(parsed.name);
|
|
231
|
+
if (!field) {
|
|
232
|
+
if (spec.inputRoot && inputSource)
|
|
233
|
+
invalid({
|
|
234
|
+
class: "mutually_exclusive",
|
|
235
|
+
message: `--input cannot be combined with ${parsed.name}`,
|
|
236
|
+
syntax: "--input PATH",
|
|
237
|
+
example: exampleFor(artifact, verb),
|
|
238
|
+
});
|
|
239
|
+
invalid({
|
|
240
|
+
class: "unrecognized_argument",
|
|
241
|
+
message: `unrecognized arguments: ${parsed.name}`,
|
|
242
|
+
example: exampleFor(artifact, verb),
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
const count = (occurrences.get(parsed.name) ?? 0) + 1;
|
|
246
|
+
occurrences.set(parsed.name, count);
|
|
247
|
+
if (!field.repeatable && count > 1) {
|
|
248
|
+
const message = parsed.name === "--alternative-chosen"
|
|
249
|
+
? `exactly one alternative must be chosen (DV3); received ${count} --alternative-chosen flags`
|
|
250
|
+
: `${parsed.name} may only be supplied once`;
|
|
251
|
+
invalid({ class: "mutually_exclusive", message });
|
|
252
|
+
}
|
|
253
|
+
const value = converted(field, parsed.value);
|
|
254
|
+
if (field.repeatable) {
|
|
255
|
+
const current = mappingPath(values, field.field) ?? [];
|
|
256
|
+
setNested(values, field.field, [...current, value]);
|
|
257
|
+
setNested(callerPayload, field.field, [...current, value]);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
setNested(values, field.field, value);
|
|
261
|
+
setNested(callerPayload, field.field, value);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (force && !spec.allowForce)
|
|
265
|
+
invalid({
|
|
266
|
+
class: "unrecognized_argument",
|
|
267
|
+
message: `--force does not apply to ${artifact} ${verb}`,
|
|
268
|
+
});
|
|
269
|
+
if (inputSource && !spec.inputRoot)
|
|
270
|
+
invalid({
|
|
271
|
+
class: "mutually_exclusive",
|
|
272
|
+
message: `${artifact} ${verb} accepts field flags, not --input`,
|
|
273
|
+
example: exampleFor(artifact, verb),
|
|
274
|
+
});
|
|
275
|
+
if (spec.inputRoot && !inputSource)
|
|
276
|
+
invalid({
|
|
277
|
+
class: "missing_argument",
|
|
278
|
+
message: `--input is required for ${artifact} ${verb}`,
|
|
279
|
+
syntax: "--input PATH",
|
|
280
|
+
example: exampleFor(artifact, verb),
|
|
281
|
+
});
|
|
282
|
+
const selectorFields = new Set(spec.fields.filter((field) => spec.selectors.includes(field.flag)).map((field) => field.field));
|
|
283
|
+
if (spec.inputRoot && Object.keys(values).some((field) => !selectorFields.has(field)))
|
|
284
|
+
invalid({
|
|
285
|
+
class: "mutually_exclusive",
|
|
286
|
+
message: `--input cannot be combined with field flags for ${artifact} ${verb}`,
|
|
287
|
+
});
|
|
288
|
+
for (const field of fields.filter((candidate) => candidate.required)) {
|
|
289
|
+
if (mappingPath(values, field.field) === undefined) {
|
|
290
|
+
invalid({
|
|
291
|
+
class: "missing_argument",
|
|
292
|
+
message: `${field.flag} is required for ${artifact} ${verb}`,
|
|
293
|
+
valid_values: field.validValues,
|
|
294
|
+
syntax: `${field.flag} VALUE`,
|
|
295
|
+
example: exampleFor(artifact, verb),
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (artifact === "decisions" && (verb === "update" || verb === "amend")) {
|
|
300
|
+
const id = mappingPath(values, "id");
|
|
301
|
+
const number = mappingPath(values, "number");
|
|
302
|
+
if (number !== undefined)
|
|
303
|
+
invalid({ class: "unrecognized_argument", message: "numeric decision selectors are unavailable in entity mode; use --id ID" });
|
|
304
|
+
if (id === undefined)
|
|
305
|
+
invalid({ class: "missing_argument", message: `--id is required for decisions ${verb} in entity mode` });
|
|
306
|
+
if (verb === "amend" && mappingPath(values, "base_sha256") === undefined)
|
|
307
|
+
invalid({ class: "missing_argument", message: "--base-sha256 is required for decisions amend in entity mode" });
|
|
308
|
+
}
|
|
309
|
+
if (artifact === "plan" && verb !== "create") {
|
|
310
|
+
const taskVerb = ["update", "set-status", "supersede", "record-evaluation"].includes(verb);
|
|
311
|
+
const id = mappingPath(values, "id");
|
|
312
|
+
if (taskVerb && id === undefined)
|
|
313
|
+
invalid({ class: "missing_argument", message: `--id is required for plan ${verb} in entity mode` });
|
|
314
|
+
if (force)
|
|
315
|
+
invalid({ class: "unrecognized_argument", message: "--force is unavailable for entity plans; incomplete plans remain canonical history" });
|
|
316
|
+
}
|
|
317
|
+
if (artifact === "plan" && verb === "create" && force)
|
|
318
|
+
invalid({ class: "unrecognized_argument", message: "--force is unavailable for entity plan create because multiple open plans coexist" });
|
|
319
|
+
return { artifact, spec, format, projectRoot, dryRun, force, values, callerPayload, inputSource };
|
|
320
|
+
}
|
|
321
|
+
function mappingPath(entry, field) {
|
|
322
|
+
let value = entry;
|
|
323
|
+
for (const part of field.split(".")) {
|
|
324
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
325
|
+
return undefined;
|
|
326
|
+
value = value[part];
|
|
327
|
+
}
|
|
328
|
+
return value;
|
|
329
|
+
}
|
|
330
|
+
function explainArgs(argv) {
|
|
331
|
+
let format = "text";
|
|
332
|
+
let project = process.cwd();
|
|
333
|
+
let verb = null;
|
|
334
|
+
let all = false;
|
|
335
|
+
for (let i = 1; i < argv.length;) {
|
|
336
|
+
if (argv[i] === "--all") {
|
|
337
|
+
all = true;
|
|
338
|
+
i += 1;
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
const parsed = readFlag(argv, i);
|
|
342
|
+
if (parsed.value === null || parsed.value.startsWith("--"))
|
|
343
|
+
invalid({ class: "missing_argument", message: `${parsed.name} requires a value` });
|
|
344
|
+
i += parsed.consumed;
|
|
345
|
+
if (parsed.name === "--format") {
|
|
346
|
+
if (parsed.value !== "text" && parsed.value !== "json")
|
|
347
|
+
invalid({
|
|
348
|
+
class: "invalid_choice",
|
|
349
|
+
message: `argument --format: invalid choice: '${parsed.value}' (choose from 'text', 'json')`,
|
|
350
|
+
valid_values: ["text", "json"],
|
|
351
|
+
});
|
|
352
|
+
format = parsed.value;
|
|
353
|
+
}
|
|
354
|
+
else if (parsed.name === "--project")
|
|
355
|
+
project = path.resolve(parsed.value);
|
|
356
|
+
else if (parsed.name === "--verb")
|
|
357
|
+
verb = parsed.value;
|
|
358
|
+
else
|
|
359
|
+
invalid({
|
|
360
|
+
class: "unrecognized_argument",
|
|
361
|
+
message: `unrecognized arguments: ${parsed.name}`,
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
if (all && verb)
|
|
365
|
+
invalid({ class: "mutually_exclusive", message: "--all cannot be combined with --verb" });
|
|
366
|
+
return { format, project, verb, all };
|
|
367
|
+
}
|
|
368
|
+
export function runStateWrite(artifactRaw, argv, io) {
|
|
369
|
+
const out = io.out ?? ((text) => process.stdout.write(text));
|
|
370
|
+
const err = io.err ?? ((text) => process.stderr.write(text));
|
|
371
|
+
const detectedFormat = formatFromArgv(argv);
|
|
372
|
+
try {
|
|
373
|
+
const artifact = artifactOrReject(artifactRaw);
|
|
374
|
+
assertMutationGrammarParity();
|
|
375
|
+
if (argv[0] === "explain") {
|
|
376
|
+
const args = explainArgs(argv);
|
|
377
|
+
const explanation = args.all
|
|
378
|
+
? buildExplainAll(artifact, args.project)
|
|
379
|
+
: buildExplain(artifact, args.project, args.verb);
|
|
380
|
+
if (args.format === "json")
|
|
381
|
+
out(JSON.stringify(explanation, null, 2) + "\n");
|
|
382
|
+
else
|
|
383
|
+
out(renderExplainText(explanation));
|
|
384
|
+
return 0;
|
|
385
|
+
}
|
|
386
|
+
const parsed = parseWrite(artifactRaw, argv);
|
|
387
|
+
let input = null;
|
|
388
|
+
if (parsed.inputSource) {
|
|
389
|
+
try {
|
|
390
|
+
input = loadStructuredInput(parsed.inputSource, io.stdin ?? (() => fsStdin()), parsed.spec.inputMaxBytes);
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
const message = error.message;
|
|
394
|
+
invalid({
|
|
395
|
+
class: message.startsWith("input file") ? "unsupported_target" : message.includes("UTF-8 limit") ? "schema_violation" : "invalid_format",
|
|
396
|
+
message,
|
|
397
|
+
syntax: "--input PATH",
|
|
398
|
+
example: exampleFor(parsed.artifact, parsed.spec.verb),
|
|
399
|
+
...(message.includes("UTF-8 limit") ? { violations: [message] } : {}),
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
for (const owned of parsed.spec.cliOwnedFields ?? []) {
|
|
403
|
+
if (hasNested(input, owned))
|
|
404
|
+
invalid({
|
|
405
|
+
class: "schema_violation",
|
|
406
|
+
message: `${parsed.artifact} ${parsed.spec.verb} assigns ${owned}; remove '${owned}' from the input document`,
|
|
407
|
+
violations: [`CLI-owned field: ${owned}`],
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
parsed.callerPayload = structuredClone(input);
|
|
411
|
+
}
|
|
412
|
+
const envelope = executeStateWrite({ ...parsed, input });
|
|
413
|
+
if (parsed.format === "json")
|
|
414
|
+
out(JSON.stringify(envelope, null, 2) + "\n");
|
|
415
|
+
else if (parsed.dryRun)
|
|
416
|
+
out(String(envelope.diff ?? "No changes.\n"));
|
|
417
|
+
else {
|
|
418
|
+
const operation = envelope.operation;
|
|
419
|
+
out(`${envelope.command}: ${operation.idempotent_replay ? "idempotent replay" : "wrote"} ${envelope.path}\n`);
|
|
420
|
+
}
|
|
421
|
+
return 0;
|
|
422
|
+
}
|
|
423
|
+
catch (error) {
|
|
424
|
+
if (error instanceof StateWriteInputError)
|
|
425
|
+
return emitInvalidInput(io, { format: detectedFormat, body: error.body });
|
|
426
|
+
if (error instanceof StateRetrievalFailure)
|
|
427
|
+
return emitRetrievalFailure(error, detectedFormat, io);
|
|
428
|
+
err(`Error: ${error.message}\n`);
|
|
429
|
+
return 1;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
function fsStdin() {
|
|
433
|
+
return process.stdin.isTTY ? Buffer.alloc(0) : fs.readFileSync(0);
|
|
434
|
+
}
|