agentera 3.0.0-dev.7 → 3.0.0-dev.72
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 +118 -22
- package/bundle/CHANGELOG.md +1361 -0
- package/bundle/DESIGN.md +229 -0
- package/bundle/LICENSE +201 -0
- package/bundle/README.md +143 -0
- package/bundle/UPGRADE.md +252 -0
- package/bundle/extract-corpus-parity.json +2 -4
- package/bundle/fixtures/routing/hybrid-corpus.yaml +154 -0
- package/bundle/references/adapters/package-publication.json +488 -0
- package/bundle/references/adapters/package-registry.yaml +435 -188
- package/bundle/references/adapters/package-surface-characterization.md +66 -34
- 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 +266 -0
- package/bundle/references/artifacts/artifact-registry-interface-model.yaml +17 -8
- package/bundle/references/artifacts/glossary-entry-contract.yaml +1254 -0
- package/bundle/references/artifacts/state-storage-authority.yaml +3061 -0
- package/bundle/references/artifacts/verbosity-budget-authority.yaml +42 -0
- package/bundle/references/cli/app-lifecycle-vocabulary.yaml +3 -4
- package/bundle/references/cli/capability-instruction-contract.yaml +11 -14
- package/bundle/references/cli/hybrid-route-contract.yaml +438 -0
- package/bundle/references/cli/routing-model.md +152 -93
- package/bundle/references/cli/trigger-schema-enrichment.md +57 -46
- package/bundle/references/cli/update-channels.yaml +4 -2
- package/bundle/references/cli/vocabulary-index.yaml +5 -7
- package/bundle/references/cli/vocabulary.md +51 -93
- package/bundle/references/meta/retained-reference-authority.yaml +151 -0
- package/bundle/skills/agentera/SKILL.md +183 -63
- package/bundle/skills/agentera/capabilities/audit/schemas/artifacts.yaml +27 -19
- package/bundle/skills/agentera/capabilities/audit/schemas/exit.yaml +2 -2
- package/bundle/skills/agentera/capabilities/audit/schemas/triggers.yaml +13 -35
- package/bundle/skills/agentera/capabilities/audit/schemas/validation.yaml +30 -11
- package/bundle/skills/agentera/capabilities/build/schemas/artifacts.yaml +44 -21
- package/bundle/skills/agentera/capabilities/build/schemas/exit.yaml +8 -6
- package/bundle/skills/agentera/capabilities/build/schemas/triggers.yaml +14 -36
- package/bundle/skills/agentera/capabilities/build/schemas/validation.yaml +95 -21
- package/bundle/skills/agentera/capabilities/design/schemas/artifacts.yaml +6 -6
- package/bundle/skills/agentera/capabilities/design/schemas/exit.yaml +5 -5
- package/bundle/skills/agentera/capabilities/design/schemas/triggers.yaml +5 -34
- package/bundle/skills/agentera/capabilities/design/schemas/validation.yaml +2 -2
- package/bundle/skills/agentera/capabilities/discuss/schemas/artifacts.yaml +17 -13
- package/bundle/skills/agentera/capabilities/discuss/schemas/exit.yaml +2 -2
- package/bundle/skills/agentera/capabilities/discuss/schemas/triggers.yaml +6 -40
- package/bundle/skills/agentera/capabilities/discuss/schemas/validation.yaml +72 -5
- package/bundle/skills/agentera/capabilities/document/schemas/artifacts.yaml +24 -17
- package/bundle/skills/agentera/capabilities/document/schemas/triggers.yaml +5 -35
- package/bundle/skills/agentera/capabilities/document/schemas/validation.yaml +13 -13
- package/bundle/skills/agentera/capabilities/optimize/schemas/artifacts.yaml +10 -10
- package/bundle/skills/agentera/capabilities/optimize/schemas/exit.yaml +2 -2
- package/bundle/skills/agentera/capabilities/optimize/schemas/triggers.yaml +4 -35
- package/bundle/skills/agentera/capabilities/optimize/schemas/validation.yaml +3 -3
- package/bundle/skills/agentera/capabilities/orchestrate/schemas/artifacts.yaml +34 -22
- package/bundle/skills/agentera/capabilities/orchestrate/schemas/exit.yaml +9 -7
- package/bundle/skills/agentera/capabilities/orchestrate/schemas/triggers.yaml +5 -37
- package/bundle/skills/agentera/capabilities/orchestrate/schemas/validation.yaml +38 -37
- package/bundle/skills/agentera/capabilities/plan/schemas/artifacts.yaml +20 -16
- package/bundle/skills/agentera/capabilities/plan/schemas/triggers.yaml +8 -31
- package/bundle/skills/agentera/capabilities/plan/schemas/validation.yaml +66 -6
- package/bundle/skills/agentera/capabilities/profile/schemas/artifacts.yaml +9 -4
- package/bundle/skills/agentera/capabilities/profile/schemas/exit.yaml +4 -4
- package/bundle/skills/agentera/capabilities/profile/schemas/triggers.yaml +8 -37
- package/bundle/skills/agentera/capabilities/profile/schemas/validation.yaml +61 -3
- package/bundle/skills/agentera/capabilities/research/schemas/artifacts.yaml +6 -6
- package/bundle/skills/agentera/capabilities/research/schemas/triggers.yaml +5 -29
- package/bundle/skills/agentera/capabilities/status/schemas/artifacts.yaml +13 -12
- package/bundle/skills/agentera/capabilities/status/schemas/triggers.yaml +7 -49
- package/bundle/skills/agentera/capabilities/vision/schemas/artifacts.yaml +8 -8
- package/bundle/skills/agentera/capabilities/vision/schemas/exit.yaml +7 -6
- package/bundle/skills/agentera/capabilities/vision/schemas/triggers.yaml +7 -39
- package/bundle/skills/agentera/capabilities/vision/schemas/validation.yaml +14 -16
- package/bundle/skills/agentera/capability_schema_contract.yaml +32 -32
- package/bundle/skills/agentera/protocol.yaml +4 -4
- package/bundle/skills/agentera/route-phrases.yaml +81 -0
- package/bundle/skills/agentera/schemas/artifacts/changelog.yaml +1 -0
- package/bundle/skills/agentera/schemas/artifacts/decisions.yaml +30 -12
- package/bundle/skills/agentera/schemas/artifacts/design.yaml +1 -0
- package/bundle/skills/agentera/schemas/artifacts/docs.yaml +7 -12
- package/bundle/skills/agentera/schemas/artifacts/experiments.yaml +140 -9
- package/bundle/skills/agentera/schemas/artifacts/glossary.yaml +82 -0
- package/bundle/skills/agentera/schemas/artifacts/health.yaml +56 -19
- package/bundle/skills/agentera/schemas/artifacts/objective.yaml +18 -4
- package/bundle/skills/agentera/schemas/artifacts/plan.yaml +457 -32
- package/bundle/skills/agentera/schemas/artifacts/progress.yaml +131 -18
- package/bundle/skills/agentera/schemas/artifacts/todo.yaml +302 -7
- package/dist/analytics/extractCorpus/cli.js +52 -11
- package/dist/analytics/extractCorpus/copilotSessions.js +6 -4
- package/dist/analytics/extractCorpus/core.js +40 -12
- package/dist/analytics/extractCorpus/corpus.js +39 -17
- package/dist/analytics/extractCorpus/coverageAudit.js +44 -45
- package/dist/analytics/extractCorpus/cursorSessions.js +6 -4
- package/dist/analytics/extractCorpus/evidenceTiers.js +603 -0
- package/dist/analytics/extractCorpus/extractCorpusParity.js +4 -4
- package/dist/analytics/extractCorpus/filesystemSources.js +1 -5
- package/dist/analytics/extractCorpus/index.js +3 -1
- package/dist/analytics/extractCorpus/jsonlSessions.js +24 -5
- package/dist/analytics/extractCorpus/sqliteCaps.js +0 -1
- package/dist/analytics/extractCorpus/sqliteSessions.js +0 -1
- package/dist/analytics/extractCorpus/tierReader.js +108 -0
- package/dist/analytics/extractCorpus.js +0 -1
- 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 +150 -23
- package/dist/audit/terminologyDrift.js +281 -0
- package/dist/bin/agentera.js +3 -2
- package/dist/capabilities/audit/instructions.js +16 -6
- package/dist/capabilities/build/instructions.js +59 -6
- package/dist/capabilities/design/instructions.js +3 -4
- package/dist/capabilities/discuss/instructions.js +29 -6
- package/dist/capabilities/document/instructions.js +11 -6
- package/dist/capabilities/index.js +16 -14
- package/dist/capabilities/optimize/instructions.js +14 -6
- package/dist/capabilities/orchestrate/instructions.js +42 -6
- package/dist/capabilities/plan/instructions.js +30 -3
- package/dist/capabilities/profile/instructions.js +70 -6
- package/dist/capabilities/research/instructions.js +4 -5
- package/dist/capabilities/status/instructions.js +15 -6
- package/dist/capabilities/status/startupInstructions.js +34 -0
- package/dist/capabilities/vision/instructions.js +3 -5
- package/dist/cli/appContext.js +14 -7
- package/dist/cli/argvalidate.js +0 -1
- package/dist/cli/capabilityContext/benchmark.js +5 -4
- package/dist/cli/capabilityContext/bespoke.js +14 -6
- package/dist/cli/capabilityContext/build.js +116 -42
- package/dist/cli/capabilityContext/closeout.js +30 -27
- package/dist/cli/capabilityContext/contract.js +18 -27
- package/dist/cli/capabilityContext/evidence.js +84 -77
- package/dist/cli/capabilityContext/index.js +0 -1
- package/dist/cli/capabilityContext/orchestration.js +42 -18
- package/dist/cli/capabilityContext/planState.js +89 -96
- package/dist/cli/capabilityContext/progress.js +51 -12
- package/dist/cli/capabilityContext/projectVerification.js +409 -0
- package/dist/cli/capabilityContext/shared.js +9 -20
- package/dist/cli/capabilityContext/slim.js +52 -8
- package/dist/cli/capabilityContext/startup.js +51 -114
- package/dist/cli/capabilityContext/startupAggregation.js +68 -0
- package/dist/cli/capabilityContext/types.js +26 -10
- package/dist/cli/capabilityContext.js +0 -1
- package/dist/cli/commands/appHome.js +0 -1
- package/dist/cli/commands/capability.js +2 -2
- package/dist/cli/commands/compact.js +163 -13
- package/dist/cli/commands/doctor.js +117 -11
- package/dist/cli/commands/durability.js +81 -0
- package/dist/cli/commands/glossaryAdvice.js +138 -0
- package/dist/cli/commands/lint.js +22 -8
- package/dist/cli/commands/personalGlossary.js +176 -0
- package/dist/cli/commands/prime/briefOrientation.js +746 -0
- package/dist/cli/commands/prime/buildExecutionRequest.js +165 -0
- package/dist/cli/commands/prime/bundleStatus.js +54 -4
- package/dist/cli/commands/prime/collectEntityOrientation.js +326 -0
- package/dist/cli/commands/prime/collectOrientationState.js +126 -63
- package/dist/cli/commands/prime/orientationOutput.js +267 -56
- package/dist/cli/commands/prime/types.js +0 -1
- package/dist/cli/commands/prime/v1Migration.js +0 -1
- package/dist/cli/commands/prime.js +76 -11
- package/dist/cli/commands/profileGrounding.js +55 -0
- package/dist/cli/commands/query.js +74 -52
- package/dist/cli/commands/report.js +73 -19
- package/dist/cli/commands/route.js +142 -0
- package/dist/cli/commands/schema.js +257 -138
- package/dist/cli/commands/state/decisions.js +40 -56
- package/dist/cli/commands/state/docs.js +58 -85
- package/dist/cli/commands/state/experimentRecords.js +151 -0
- package/dist/cli/commands/state/experiments.js +11 -65
- package/dist/cli/commands/state/get.js +129 -0
- package/dist/cli/commands/state/health.js +11 -113
- package/dist/cli/commands/state/index.js +6 -41
- package/dist/cli/commands/state/list.js +194 -0
- package/dist/cli/commands/state/objective.js +21 -65
- package/dist/cli/commands/state/plan.js +11 -170
- 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 +11 -45
- package/dist/cli/commands/state/shared.js +0 -1
- package/dist/cli/commands/state/todo.js +28 -107
- package/dist/cli/commands/state/write.js +433 -0
- package/dist/cli/commands/upgrade.js +146 -5
- package/dist/cli/commands/upgradeVerify.js +118 -0
- package/dist/cli/commands/validate.js +235 -136
- package/dist/cli/commands/verify.js +23 -8
- package/dist/cli/contracts/bundleStatus.js +0 -1
- package/dist/cli/contracts/orientationState.js +0 -1
- package/dist/cli/dispatch/argvParser.js +0 -1
- package/dist/cli/dispatch/check.js +84 -40
- package/dist/cli/dispatch/commands.js +3 -3
- package/dist/cli/dispatch/index.js +77 -52
- package/dist/cli/dispatch/lifecycle.js +117 -62
- package/dist/cli/dispatch/prime.js +37 -2
- package/dist/cli/dispatch/projections.js +17 -0
- package/dist/cli/dispatch/shared.js +1 -2
- package/dist/cli/dispatch/state.js +62 -66
- package/dist/cli/dispatch.js +0 -1
- package/dist/cli/errors.js +16 -17
- package/dist/cli/help.js +358 -39
- package/dist/cli/migrationRequired.js +122 -0
- package/dist/cli/orientation/attention.js +19 -19
- package/dist/cli/orientation/corpusCoverage.js +32 -1
- package/dist/cli/orientation.js +346 -129
- 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 +11 -8
- package/dist/cli/stateQuery.js +47 -12
- package/dist/cli/structured.js +0 -1
- package/dist/cli/todoMarkdown.js +25 -12
- package/dist/cli/todoReadinessSelection.js +192 -0
- package/dist/cli/todoSeverity.js +0 -1
- 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 +0 -1
- package/dist/core/jsonValue.js +0 -1
- package/dist/core/paths.js +0 -1
- package/dist/core/pyjson.js +0 -1
- 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 +13 -14
- package/dist/eval/hybridRouteEvaluation.js +155 -0
- package/dist/eval/semanticEval.js +0 -1
- package/dist/eval/semanticFixtures.js +0 -1
- package/dist/hooks/common.js +3 -56
- package/dist/hooks/compaction/apply.js +224 -47
- package/dist/hooks/compaction/dryRun.js +2 -1
- package/dist/hooks/compaction/index.js +5 -6
- package/dist/hooks/compaction/parse.js +73 -6
- package/dist/hooks/compaction/retention.js +28 -25
- package/dist/hooks/compaction/status.js +145 -26
- package/dist/hooks/compaction/types.js +0 -1
- package/dist/hooks/validateArtifact/agentFacing.js +0 -1
- package/dist/hooks/validateArtifact/index.js +6 -65
- package/dist/hooks/validateArtifact/markdown.js +9 -10
- package/dist/hooks/validateArtifact/schema.js +96 -9
- package/dist/hooks/validateArtifact/traversal.js +12 -11
- package/dist/hooks/validateArtifact/violations.js +5 -3
- package/dist/migrate/v2HandoffManifest.js +8 -3
- package/dist/registries/activationContract.js +2 -0
- package/dist/registries/activationTuples.js +108 -0
- package/dist/registries/artifactProtocolIds.js +2 -1
- package/dist/registries/artifactRegistry.js +207 -60
- package/dist/registries/artifactSchemaProjection.js +45 -0
- package/dist/registries/capabilityContract.js +5 -21
- package/dist/registries/evaluatorHandoffContract.js +0 -1
- 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 +273 -0
- package/dist/registries/packageRegistry.js +184 -209
- package/dist/registries/todoReadinessContract.js +448 -0
- package/dist/registries/triggerLoader.js +7 -44
- package/dist/registries/verbosityBudgetContract.js +205 -0
- package/dist/release/releaseMetadata.js +155 -5
- 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 -13
- package/dist/setup/opencodeConstants.js +1 -0
- package/dist/setup/sharedSkill.js +45 -0
- package/dist/setup/smokeChecks.js +14 -75
- 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 +840 -0
- package/dist/state/entityMigrationTodo.js +133 -0
- package/dist/state/entityPublicationContext.js +859 -0
- package/dist/state/entityRetrievalHelp.js +506 -0
- package/dist/state/entityStorage.js +899 -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 +15 -7
- 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 +1027 -0
- package/dist/state/planIdentity.js +47 -0
- package/dist/state/planLineageValidation.js +52 -0
- package/dist/state/planReplacementTransaction.js +475 -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/progressWritePolicy.js +33 -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 +70 -9
- package/dist/state/startupAnalysis/contract.js +44 -10
- package/dist/state/startupAnalysis/helpers.js +1 -2
- package/dist/state/startupAnalysis/index.js +0 -1
- package/dist/state/startupAnalysis/metrics.js +0 -1
- package/dist/state/startupAnalysis/records.js +0 -1
- package/dist/state/startupAnalysis/report.js +0 -1
- package/dist/state/startupAnalysis/threshold.js +13 -1
- package/dist/state/startupAnalysis.js +0 -1
- package/dist/state/startupProjection.js +499 -0
- package/dist/state/stateMode.js +222 -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/todoActivationSafety.js +58 -0
- package/dist/state/todoDocsEntities.js +1124 -0
- package/dist/state/todoDocsEntityValidation.js +158 -0
- package/dist/state/todoMarkdownProjection.js +51 -0
- package/dist/state/todoReconciliationActivation.js +182 -0
- package/dist/state/todoReconciliationInspection.js +171 -0
- package/dist/state/todoReconciliationRepair.js +318 -0
- package/dist/state/todoReconciliationTransaction.js +595 -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 +377 -0
- package/dist/state/write/fields.js +61 -0
- package/dist/state/write/glossaryPublication.js +263 -0
- package/dist/state/write/grammar.js +285 -0
- package/dist/state/write/helpers.js +29 -0
- package/dist/state/write/index.js +12 -0
- package/dist/state/write/input.js +391 -0
- package/dist/state/write/lock.js +837 -0
- package/dist/state/write/mutation.js +234 -0
- package/dist/state/write/operations.js +170 -0
- package/dist/state/write/planEvaluation.js +128 -0
- package/dist/state/write/planPublication.js +179 -0
- package/dist/state/write/runtimeOperations.js +146 -0
- package/dist/state/write/serialize.js +1 -0
- package/dist/state/write/transaction.js +57 -0
- package/dist/state/write/validate.js +7 -0
- package/dist/upgrade/appContentRefresh.js +77 -36
- package/dist/upgrade/appModel.js +0 -1
- package/dist/upgrade/atomicWriter.js +1 -0
- package/dist/upgrade/bundleEvidence.js +0 -1
- package/dist/upgrade/channels.js +6 -9
- package/dist/upgrade/compatibility.js +43 -17
- package/dist/upgrade/doctor.js +55 -32
- package/dist/upgrade/doctorClassifier.js +11 -1
- package/dist/upgrade/installedHooksRetirement.js +46 -40
- package/dist/upgrade/legacyAgentCleanup.js +187 -21
- package/dist/upgrade/lifecycleUpgrade.js +113 -0
- package/dist/upgrade/migrateArtifactsV2ToV3.js +334 -64
- package/dist/upgrade/migrationPublication.js +122 -0
- package/dist/upgrade/nextMajorDoctor.js +0 -1
- package/dist/upgrade/npxPlatformStatus.js +0 -1
- package/dist/upgrade/projectIntegration.js +121 -159
- package/dist/upgrade/projectIntegrationDecision.js +42 -85
- package/dist/upgrade/retiredResourceDiagnostics.js +117 -0
- package/dist/upgrade/runtimeMigration.js +262 -453
- 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 +2 -3
- package/dist/upgrade/versionResolution.js +0 -1
- package/dist/validate/activationArtifactEvidence.js +852 -0
- package/dist/validate/activationArtifactEvidenceTypes.js +12 -0
- package/dist/validate/activationConjunction.js +816 -0
- package/dist/validate/activationEvidenceManifest.js +531 -0
- package/dist/validate/activationPackageSemantics.js +29 -0
- package/dist/validate/appHomeContract.js +1 -7
- package/dist/validate/bootstrapAuthority.js +44 -0
- package/dist/validate/capability.js +11 -3
- package/dist/validate/crossCapability.js +14 -9
- package/dist/validate/retainedReferenceAuthority.js +879 -0
- package/dist/validate/selfAudit.js +39 -45
- package/dist/validate/v1LegacyCruft.js +131 -0
- package/dist/validate/vocabularyAuthority.js +8 -8
- package/package.json +41 -13
- package/bundle/references/adapters/cursor.md +0 -214
- 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 -554
- 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 -369
- package/bundle/references/cli/bundle-skill-vocabulary.yaml +0 -250
- package/bundle/references/cli/capability-tool-classification.yaml +0 -53
- package/bundle/references/cli/coexistence-probe.yaml +0 -13
- package/bundle/references/cli/parity-expected-actual-template.md +0 -30
- package/bundle/references/cli/routing-execution-vocabulary.yaml +0 -281
- package/bundle/references/cli/single-name-protocol.yaml +0 -42
- package/bundle/references/cli/upgrade-repair-wording.md +0 -45
- package/bundle/references/cli/v3-handoff-manifest.schema.yaml +0 -98
- package/bundle/references/meta/documentation-inventory.md +0 -49
- package/bundle/skills/agentera/.claude-plugin/plugin.json +0 -27
- package/bundle/skills/agentera/agents/audit.toml +0 -6
- package/bundle/skills/agentera/agents/build.toml +0 -6
- package/bundle/skills/agentera/agents/design.toml +0 -6
- package/bundle/skills/agentera/agents/discuss.toml +0 -6
- package/bundle/skills/agentera/agents/document.toml +0 -6
- package/bundle/skills/agentera/agents/optimize.toml +0 -6
- package/bundle/skills/agentera/agents/orchestrate.toml +0 -6
- package/bundle/skills/agentera/agents/plan.toml +0 -6
- package/bundle/skills/agentera/agents/profile.toml +0 -6
- package/bundle/skills/agentera/agents/research.toml +0 -6
- package/bundle/skills/agentera/agents/status.toml +0 -6
- package/bundle/skills/agentera/agents/vision.toml +0 -6
- package/bundle/skills/agentera/references/contract.md +0 -1048
- package/dist/analytics/extractCorpus/cli.js.map +0 -1
- package/dist/analytics/extractCorpus/copilotSessions.js.map +0 -1
- package/dist/analytics/extractCorpus/core.js.map +0 -1
- package/dist/analytics/extractCorpus/corpus.js.map +0 -1
- package/dist/analytics/extractCorpus/coverageAudit.js.map +0 -1
- package/dist/analytics/extractCorpus/cursorSessions.js.map +0 -1
- package/dist/analytics/extractCorpus/extractCorpusParity.js.map +0 -1
- package/dist/analytics/extractCorpus/filesystemSources.js.map +0 -1
- package/dist/analytics/extractCorpus/index.js.map +0 -1
- package/dist/analytics/extractCorpus/jsonlSessions.js.map +0 -1
- package/dist/analytics/extractCorpus/sqliteCaps.js.map +0 -1
- package/dist/analytics/extractCorpus/sqliteSessions.js.map +0 -1
- 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/capabilities/audit/instructions.js.map +0 -1
- package/dist/capabilities/build/instructions.js.map +0 -1
- package/dist/capabilities/design/instructions.js.map +0 -1
- package/dist/capabilities/discuss/instructions.js.map +0 -1
- package/dist/capabilities/document/instructions.js.map +0 -1
- package/dist/capabilities/dokumentera/instructions.js +0 -6
- package/dist/capabilities/dokumentera/instructions.js.map +0 -1
- package/dist/capabilities/hej/instructions.js +0 -6
- package/dist/capabilities/hej/instructions.js.map +0 -1
- package/dist/capabilities/index.js.map +0 -1
- package/dist/capabilities/inspektera/instructions.js +0 -6
- package/dist/capabilities/inspektera/instructions.js.map +0 -1
- package/dist/capabilities/inspirera/instructions.js +0 -6
- package/dist/capabilities/inspirera/instructions.js.map +0 -1
- package/dist/capabilities/optimera/instructions.js +0 -6
- package/dist/capabilities/optimera/instructions.js.map +0 -1
- package/dist/capabilities/optimize/instructions.js.map +0 -1
- package/dist/capabilities/orchestrate/instructions.js.map +0 -1
- package/dist/capabilities/orkestrera/instructions.js +0 -6
- package/dist/capabilities/orkestrera/instructions.js.map +0 -1
- package/dist/capabilities/plan/instructions.js.map +0 -1
- package/dist/capabilities/planera/instructions.js +0 -6
- package/dist/capabilities/planera/instructions.js.map +0 -1
- package/dist/capabilities/profile/instructions.js.map +0 -1
- package/dist/capabilities/profilera/instructions.js +0 -6
- package/dist/capabilities/profilera/instructions.js.map +0 -1
- package/dist/capabilities/realisera/instructions.js +0 -6
- package/dist/capabilities/realisera/instructions.js.map +0 -1
- package/dist/capabilities/research/instructions.js.map +0 -1
- package/dist/capabilities/resonera/instructions.js +0 -6
- package/dist/capabilities/resonera/instructions.js.map +0 -1
- package/dist/capabilities/status/instructions.js.map +0 -1
- package/dist/capabilities/vision/instructions.js.map +0 -1
- package/dist/capabilities/visionera/instructions.js +0 -6
- package/dist/capabilities/visionera/instructions.js.map +0 -1
- package/dist/capabilities/visualisera/instructions.js +0 -5
- package/dist/capabilities/visualisera/instructions.js.map +0 -1
- package/dist/cli/appContext.js.map +0 -1
- package/dist/cli/argvalidate.js.map +0 -1
- package/dist/cli/capabilityContext/benchmark.js.map +0 -1
- package/dist/cli/capabilityContext/bespoke.js.map +0 -1
- package/dist/cli/capabilityContext/build.js.map +0 -1
- package/dist/cli/capabilityContext/closeout.js.map +0 -1
- package/dist/cli/capabilityContext/contract.js.map +0 -1
- package/dist/cli/capabilityContext/evidence.js.map +0 -1
- package/dist/cli/capabilityContext/index.js.map +0 -1
- package/dist/cli/capabilityContext/orchestration.js.map +0 -1
- package/dist/cli/capabilityContext/planState.js.map +0 -1
- package/dist/cli/capabilityContext/progress.js.map +0 -1
- package/dist/cli/capabilityContext/realisera.js +0 -174
- package/dist/cli/capabilityContext/realisera.js.map +0 -1
- package/dist/cli/capabilityContext/shared.js.map +0 -1
- package/dist/cli/capabilityContext/slim.js.map +0 -1
- package/dist/cli/capabilityContext/startup.js.map +0 -1
- package/dist/cli/capabilityContext/types.js.map +0 -1
- package/dist/cli/capabilityContext.js.map +0 -1
- package/dist/cli/commands/appHome.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/bundleStatus.js.map +0 -1
- package/dist/cli/commands/prime/collectOrientationState.js.map +0 -1
- package/dist/cli/commands/prime/orientationOutput.js.map +0 -1
- package/dist/cli/commands/prime/routeOutput.js +0 -50
- package/dist/cli/commands/prime/routeOutput.js.map +0 -1
- package/dist/cli/commands/prime/types.js.map +0 -1
- package/dist/cli/commands/prime/v1Migration.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/decisions.js.map +0 -1
- package/dist/cli/commands/state/docs.js.map +0 -1
- package/dist/cli/commands/state/experiments.js.map +0 -1
- package/dist/cli/commands/state/health.js.map +0 -1
- package/dist/cli/commands/state/index.js.map +0 -1
- package/dist/cli/commands/state/objective.js.map +0 -1
- package/dist/cli/commands/state/plan.js.map +0 -1
- package/dist/cli/commands/state/progress.js.map +0 -1
- package/dist/cli/commands/state/shared.js.map +0 -1
- package/dist/cli/commands/state/todo.js.map +0 -1
- package/dist/cli/commands/state.js +0 -1023
- 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/contracts/bundleStatus.js.map +0 -1
- package/dist/cli/contracts/orientationState.js.map +0 -1
- package/dist/cli/dispatch/argvParser.js.map +0 -1
- package/dist/cli/dispatch/check.js.map +0 -1
- package/dist/cli/dispatch/commands.js.map +0 -1
- package/dist/cli/dispatch/index.js.map +0 -1
- package/dist/cli/dispatch/lifecycle.js.map +0 -1
- package/dist/cli/dispatch/prime.js.map +0 -1
- package/dist/cli/dispatch/shared.js.map +0 -1
- package/dist/cli/dispatch/state.js.map +0 -1
- package/dist/cli/dispatch.js.map +0 -1
- package/dist/cli/errors.js.map +0 -1
- package/dist/cli/help.js.map +0 -1
- package/dist/cli/orientation/attention.js.map +0 -1
- package/dist/cli/orientation/corpusCoverage.js.map +0 -1
- package/dist/cli/orientation.js.map +0 -1
- package/dist/cli/prime-blob.js.map +0 -1
- package/dist/cli/startupCompletenessContract.js.map +0 -1
- package/dist/cli/stateQuery.js.map +0 -1
- package/dist/cli/structured.js.map +0 -1
- package/dist/cli/todoMarkdown.js.map +0 -1
- package/dist/cli/todoSeverity.js.map +0 -1
- package/dist/core/difflib.js.map +0 -1
- package/dist/core/envPaths.js.map +0 -1
- package/dist/core/git.js +0 -43
- package/dist/core/git.js.map +0 -1
- package/dist/core/jsonValue.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/apply.js.map +0 -1
- package/dist/hooks/compaction/dryRun.js.map +0 -1
- package/dist/hooks/compaction/index.js.map +0 -1
- package/dist/hooks/compaction/parse.js.map +0 -1
- package/dist/hooks/compaction/retention.js.map +0 -1
- package/dist/hooks/compaction/status.js.map +0 -1
- package/dist/hooks/compaction/todoResolved.js +0 -137
- package/dist/hooks/compaction/todoResolved.js.map +0 -1
- package/dist/hooks/compaction/types.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 -79
- package/dist/hooks/cursorSessionStart.js.map +0 -1
- package/dist/hooks/sessionStart.js +0 -216
- package/dist/hooks/sessionStart.js.map +0 -1
- package/dist/hooks/sessionStop.js +0 -206
- package/dist/hooks/sessionStop.js.map +0 -1
- package/dist/hooks/todoLayout.js +0 -177
- package/dist/hooks/todoLayout.js.map +0 -1
- package/dist/hooks/validateArtifact/agentFacing.js.map +0 -1
- package/dist/hooks/validateArtifact/index.js.map +0 -1
- package/dist/hooks/validateArtifact/markdown.js.map +0 -1
- package/dist/hooks/validateArtifact/runtime.js +0 -86
- package/dist/hooks/validateArtifact/runtime.js.map +0 -1
- package/dist/hooks/validateArtifact/schema.js.map +0 -1
- package/dist/hooks/validateArtifact/traversal.js.map +0 -1
- package/dist/hooks/validateArtifact/violations.js.map +0 -1
- package/dist/hooks/validateArtifact.js +0 -924
- package/dist/hooks/validateArtifact.js.map +0 -1
- package/dist/migrate/v2HandoffManifest.js.map +0 -1
- package/dist/registries/artifactProtocolIds.js.map +0 -1
- package/dist/registries/artifactRegistry.js.map +0 -1
- package/dist/registries/capabilityContract.js.map +0 -1
- package/dist/registries/evaluatorHandoffContract.js.map +0 -1
- package/dist/registries/packageRegistry.js.map +0 -1
- package/dist/registries/runtimeAdapterRegistry.js +0 -316
- package/dist/registries/runtimeAdapterRegistry.js.map +0 -1
- package/dist/registries/triggerLoader.js.map +0 -1
- package/dist/release/releaseMetadata.js.map +0 -1
- package/dist/routing/index.js +0 -2
- package/dist/routing/index.js.map +0 -1
- package/dist/routing/routeEngine.js +0 -189
- package/dist/routing/routeEngine.js.map +0 -1
- package/dist/setup/codex/agents.js +0 -96
- package/dist/setup/codex/agents.js.map +0 -1
- package/dist/setup/codex/cli.js +0 -161
- package/dist/setup/codex/cli.js.map +0 -1
- package/dist/setup/codex/configToml.js +0 -639
- package/dist/setup/codex/configToml.js.map +0 -1
- package/dist/setup/codex/constants.js +0 -29
- package/dist/setup/codex/constants.js.map +0 -1
- package/dist/setup/codex/installRoot.js +0 -64
- package/dist/setup/codex/installRoot.js.map +0 -1
- package/dist/setup/codex/state.js +0 -270
- package/dist/setup/codex/state.js.map +0 -1
- package/dist/setup/codex.js +0 -12
- 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 -129
- package/dist/setup/cursor.js.map +0 -1
- package/dist/setup/cursorSurfaces.js +0 -67
- package/dist/setup/cursorSurfaces.js.map +0 -1
- package/dist/setup/doctor/core.js +0 -300
- package/dist/setup/doctor/core.js.map +0 -1
- package/dist/setup/doctor/diagnostics.js +0 -240
- package/dist/setup/doctor/diagnostics.js.map +0 -1
- package/dist/setup/doctor/opencode.js +0 -313
- package/dist/setup/doctor/opencode.js.map +0 -1
- package/dist/setup/doctor/report.js +0 -425
- package/dist/setup/doctor/report.js.map +0 -1
- package/dist/setup/doctor.js +0 -10
- package/dist/setup/doctor.js.map +0 -1
- package/dist/setup/opencode.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/benchmark.js.map +0 -1
- package/dist/state/startupAnalysis/contract.js.map +0 -1
- package/dist/state/startupAnalysis/helpers.js.map +0 -1
- package/dist/state/startupAnalysis/index.js.map +0 -1
- package/dist/state/startupAnalysis/metrics.js.map +0 -1
- package/dist/state/startupAnalysis/records.js.map +0 -1
- package/dist/state/startupAnalysis/report.js.map +0 -1
- package/dist/state/startupAnalysis/threshold.js.map +0 -1
- package/dist/state/startupAnalysis.js.map +0 -1
- package/dist/upgrade/appContentRefresh.js.map +0 -1
- package/dist/upgrade/appModel.js.map +0 -1
- package/dist/upgrade/bundleEvidence.js.map +0 -1
- package/dist/upgrade/channels.js.map +0 -1
- package/dist/upgrade/cliProbe.js +0 -22
- package/dist/upgrade/cliProbe.js.map +0 -1
- package/dist/upgrade/coexistenceProbe.js +0 -107
- package/dist/upgrade/coexistenceProbe.js.map +0 -1
- package/dist/upgrade/compatibility.js.map +0 -1
- package/dist/upgrade/doctor.js.map +0 -1
- package/dist/upgrade/doctorClassifier.js.map +0 -1
- package/dist/upgrade/installedHooksRetirement.js.map +0 -1
- package/dist/upgrade/legacyAgentCleanup.js.map +0 -1
- package/dist/upgrade/migrateArtifactsV1ToV2.js +0 -570
- package/dist/upgrade/migrateArtifactsV1ToV2.js.map +0 -1
- package/dist/upgrade/migrateArtifactsV2ToV3.js.map +0 -1
- package/dist/upgrade/nextMajorDoctor.js.map +0 -1
- package/dist/upgrade/npxPlatformStatus.js.map +0 -1
- package/dist/upgrade/projectIntegration.js.map +0 -1
- package/dist/upgrade/projectIntegrationDecision.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/v3CapabilitySurface.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/legacyPythonParity.js +0 -93
- package/dist/validate/lifecycleAdapters/legacyPythonParity.js.map +0 -1
- package/dist/validate/lifecycleAdapters/nodeFormChecks.js +0 -488
- package/dist/validate/lifecycleAdapters/nodeFormChecks.js.map +0 -1
- package/dist/validate/lifecycleAdapters/shared.js +0 -198
- package/dist/validate/lifecycleAdapters/shared.js.map +0 -1
- package/dist/validate/lifecycleAdapters.js +0 -62
- package/dist/validate/lifecycleAdapters.js.map +0 -1
- package/dist/validate/selfAudit.js.map +0 -1
- package/dist/validate/vocabularyAuthority.js.map +0 -1
|
@@ -0,0 +1,840 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import YAML from "yaml";
|
|
5
|
+
import { fullEntityUpgradePreviewCommand } from "../upgrade/upgradeCommands.js";
|
|
6
|
+
import { loadYamlMapping } from "../core/yaml.js";
|
|
7
|
+
import { discoverPlanArtifacts, planDocumentParts } from "../cli/planArtifacts.js";
|
|
8
|
+
import { assertRealpathBoundary, docsPathOverridesFromBytes, loadArtifactRecord, resolveArtifactPath } from "../registries/artifactRegistry.js";
|
|
9
|
+
import { canonicalRecordJson, validateStateRecord } from "./archiveDiscovery.js";
|
|
10
|
+
import { canonicalEntityEnvelopeBytes, entityForbiddenCanonicalAliases, entityPreservedAggregateCollections, validateCanonicalEntityTargets } from "./entityStorage.js";
|
|
11
|
+
import { discoverObjectiveArtifacts, inspectExperimentIdentities } from "./experimentIdentity.js";
|
|
12
|
+
import { decisionRevisionContract, decisionRevisionViolations } from "./decisionRevision.js";
|
|
13
|
+
import { classifyCompleteDecisionConfidence, decisionLegacyCoexistence } from "./decisionLegacyValidation.js";
|
|
14
|
+
import { migrateDecisionRevisionEntries } from "./decisionRevisionMigration.js";
|
|
15
|
+
import { entityMigrationId } from "./entityMigrationIdentity.js";
|
|
16
|
+
import { assertValidatedProjectRoot, validateRealProjectRoot } from "./projectRoot.js";
|
|
17
|
+
import { todoDocsRecordViolations } from "./todoDocsEntityValidation.js";
|
|
18
|
+
import { yamlArchiveEntry } from "../hooks/compaction/retention.js";
|
|
19
|
+
import { truncateWords } from "../hooks/compaction/dryRun.js";
|
|
20
|
+
import { legacyIdentity } from "./legacyIdentity.js";
|
|
21
|
+
import { canonicalMigrationRecord } from "./canonicalMigrationRecord.js";
|
|
22
|
+
import { legacySummaryRecord } from "./legacySummaryRecord.js";
|
|
23
|
+
import { applyCausalBlockers } from "./entityMigrationCausality.js";
|
|
24
|
+
import { todoMigrationObservations, todoReconciliationMigrationPlan } from "./entityMigrationTodo.js";
|
|
25
|
+
import { classifyProjectState } from "./stateMode.js";
|
|
26
|
+
import { TODO_RECONCILIATION_ACTIVATION_PATH } from "./todoReconciliationActivation.js";
|
|
27
|
+
import { projectPathIsStable as migrationPathIsStable, readProjectFileSnapshot, resolveProjectDescriptorPath, snapshotProjectPath as snapshotMigrationPath, } from "./safeProjectFile.js";
|
|
28
|
+
export function classifyEntityCutoverProject(project, sourceRoot) {
|
|
29
|
+
const state = classifyProjectState(project, sourceRoot).state;
|
|
30
|
+
return state === "entities" ? "v3" : state;
|
|
31
|
+
}
|
|
32
|
+
export const ENTITY_MIGRATION_PREVIEW_MAX_OUTPUT_BYTES = 32_768;
|
|
33
|
+
const DEFAULT_LIMIT = 100;
|
|
34
|
+
const MAX_LIMIT = 1000;
|
|
35
|
+
const NUMBERED = {
|
|
36
|
+
progress: { file: ".agentera/progress.yaml", collection: "cycles", boundary: "progress_cycle" },
|
|
37
|
+
decisions: { file: ".agentera/decisions.yaml", collection: "decisions", boundary: "decision" },
|
|
38
|
+
health: { file: ".agentera/health.yaml", collection: "audits", boundary: "health_audit" },
|
|
39
|
+
};
|
|
40
|
+
const COMPACTED_SUMMARY_ARTIFACTS = new Set(["progress", "decisions", "health"]);
|
|
41
|
+
const BLOCKING = new Set(["duplicate", "conflict", "corrupt", "unsupported"]);
|
|
42
|
+
const INVENTORY_ORDER = "artifact_then_boundary_then_source_identity_then_source_path";
|
|
43
|
+
const INVENTORY_FILTER = "complete_declared_inventory";
|
|
44
|
+
const AUTHORITY_PATH = "references/artifacts/state-storage-authority.yaml";
|
|
45
|
+
const PLAN_ARCHIVE_SOURCE = /^\.agentera\/archive\/PLAN-[^/]+\.ya?ml$/i;
|
|
46
|
+
function mapping(value) {
|
|
47
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
48
|
+
}
|
|
49
|
+
function hash(value) {
|
|
50
|
+
return createHash("sha256").update(value).digest("hex");
|
|
51
|
+
}
|
|
52
|
+
function completeRecordAssessment(sourceRoot, artifact, record, source, sourcePath) {
|
|
53
|
+
if (artifact !== "decisions") {
|
|
54
|
+
const violations = validateStateRecord(sourceRoot, artifact, record);
|
|
55
|
+
return { valid: violations.length === 0, violations };
|
|
56
|
+
}
|
|
57
|
+
const assessment = classifyCompleteDecisionConfidence(record, decisionLegacyCoexistence(sourceRoot), (candidate) => validateStateRecord(sourceRoot, artifact, candidate), source);
|
|
58
|
+
return {
|
|
59
|
+
valid: assessment.status !== "invalid",
|
|
60
|
+
violations: assessment.violations,
|
|
61
|
+
...(assessment.status === "inherited" ? { inheritedConfidenceProvenance: {
|
|
62
|
+
kind: "inherited_decision_confidence",
|
|
63
|
+
source: source === "active" ? "current_projection" : "verified_archive",
|
|
64
|
+
source_path: sourcePath,
|
|
65
|
+
source_record_sha256: hash(canonicalRecordJson(record)),
|
|
66
|
+
confidence: record.confidence,
|
|
67
|
+
} } : {}),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function relative(root, target) {
|
|
71
|
+
return path.relative(root, target).replaceAll(path.sep, "/");
|
|
72
|
+
}
|
|
73
|
+
/** Migration-only source seam: pin one project file to a verified descriptor. */
|
|
74
|
+
function readMigrationSource(root, relativePath, descriptorPathResolver) {
|
|
75
|
+
return { relative: relativePath, ...readProjectFileSnapshot(root, relativePath, descriptorPathResolver) };
|
|
76
|
+
}
|
|
77
|
+
function directoryFiles(root, validatedRoot, relativeRoot, accept, descriptorPathResolver) {
|
|
78
|
+
const absoluteRoot = path.join(root, relativeRoot);
|
|
79
|
+
const inventoryPath = (directory) => `${relative(root, directory).replace(/\/$/, "")}/`;
|
|
80
|
+
const visit = (directory, isRoot = false) => {
|
|
81
|
+
assertValidatedProjectRoot(validatedRoot);
|
|
82
|
+
const directorySnapshot = snapshotMigrationPath(root, relative(root, directory), "directory");
|
|
83
|
+
if (directorySnapshot.kind !== "stable") {
|
|
84
|
+
if (directorySnapshot.kind === "missing")
|
|
85
|
+
return isRoot ? { files: [], changed: null } : { files: [], changed: inventoryPath(directory) };
|
|
86
|
+
if (path.resolve(directorySnapshot.absolute) !== path.resolve(directory))
|
|
87
|
+
return { files: [], changed: inventoryPath(directory) };
|
|
88
|
+
if (directorySnapshot.reason === "symlink")
|
|
89
|
+
throw new Error(`inventory root '${directory}' is a symbolic link; replace it with a real directory inside project '${root}' and retry`);
|
|
90
|
+
if (directorySnapshot.reason === "type")
|
|
91
|
+
throw new Error(`inventory root '${directory}' is not a directory; replace it with a real directory inside project '${root}' and retry`);
|
|
92
|
+
throw new Error(`inventory root '${directory}' cannot be inspected inside project '${root}'; replace it with a readable real directory and retry`);
|
|
93
|
+
}
|
|
94
|
+
let entries;
|
|
95
|
+
try {
|
|
96
|
+
entries = fs.readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
throw new Error(`inventory root '${directory}' cannot be read inside project '${root}'; replace it with a readable real directory and retry`);
|
|
100
|
+
}
|
|
101
|
+
if (!migrationPathIsStable(directorySnapshot))
|
|
102
|
+
return { files: [], changed: inventoryPath(directory) };
|
|
103
|
+
const files = [];
|
|
104
|
+
for (const entry of entries) {
|
|
105
|
+
const absolute = path.join(directory, entry.name);
|
|
106
|
+
const candidate = relative(root, absolute);
|
|
107
|
+
if (accept(candidate)) {
|
|
108
|
+
files.push(readMigrationSource(validatedRoot, candidate, descriptorPathResolver));
|
|
109
|
+
}
|
|
110
|
+
else if (entry.isSymbolicLink()) {
|
|
111
|
+
throw new Error(`inventory root '${absolute}' is a symbolic link; replace it with a real directory or file inside project '${root}' and retry`);
|
|
112
|
+
}
|
|
113
|
+
else if (entry.isDirectory()) {
|
|
114
|
+
const nested = visit(absolute);
|
|
115
|
+
if (nested.changed)
|
|
116
|
+
return nested;
|
|
117
|
+
files.push(...nested.files);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
assertValidatedProjectRoot(validatedRoot);
|
|
121
|
+
if (!migrationPathIsStable(directorySnapshot))
|
|
122
|
+
return { files: [], changed: inventoryPath(directory) };
|
|
123
|
+
return { files, changed: null };
|
|
124
|
+
};
|
|
125
|
+
const enumeration = visit(absoluteRoot, true);
|
|
126
|
+
return enumeration.changed ? [{ relative: enumeration.changed, bytes: null, kind: "unsafe" }] : enumeration.files;
|
|
127
|
+
}
|
|
128
|
+
function collectSources(root, validatedRoot, todoPath, docsSnapshot, descriptorPathResolver) {
|
|
129
|
+
const exact = [
|
|
130
|
+
todoPath, "CHANGELOG.md", "DESIGN.md", ".agentera/vision.yaml", ".agentera/docs.yaml", ".agentera/progress.yaml", ".agentera/decisions.yaml", ".agentera/health.yaml", ".agentera/plan.yaml",
|
|
131
|
+
".agentera/overlays/decisions.yaml", ".agentera/revisions/decisions.yaml", ".agentera/archive/recovery/projection-correlation.yaml",
|
|
132
|
+
].map((candidate) => candidate === docsSnapshot.relative ? docsSnapshot : readMigrationSource(validatedRoot, candidate, descriptorPathResolver));
|
|
133
|
+
const archives = directoryFiles(root, validatedRoot, ".agentera/archive", (candidate) => /^\.agentera\/archive\/(progress|decisions|health)\/.+/.test(candidate)
|
|
134
|
+
|| PLAN_ARCHIVE_SOURCE.test(candidate), descriptorPathResolver);
|
|
135
|
+
const objectives = [".agentera/optimize", ".agentera/optimera"].flatMap((directory) => directoryFiles(root, validatedRoot, directory, (candidate) => /\/(objective|experiments)\.yaml$/.test(candidate), descriptorPathResolver));
|
|
136
|
+
const todoEntities = directoryFiles(root, validatedRoot, ".agentera/entities/todo/todo_item", (candidate) => candidate.endsWith(".yaml"), descriptorPathResolver);
|
|
137
|
+
const activation = readMigrationSource(validatedRoot, TODO_RECONCILIATION_ACTIVATION_PATH, descriptorPathResolver);
|
|
138
|
+
const collected = [...exact, ...archives, ...objectives, ...todoEntities, activation];
|
|
139
|
+
const missingRoots = [".agentera/archive/", ".agentera/optimize/", ".agentera/optimera/", ".agentera/entities/todo/todo_item/"]
|
|
140
|
+
.filter((directory) => {
|
|
141
|
+
if (collected.some((source) => source.kind === "unsafe" && source.relative === directory))
|
|
142
|
+
return false;
|
|
143
|
+
try {
|
|
144
|
+
return !fs.lstatSync(path.join(root, directory)).isDirectory();
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
.map((directory) => ({ relative: directory, bytes: null, kind: "missing" }));
|
|
151
|
+
const byPath = new Map([...collected, ...missingRoots].map((source) => [source.relative, source]));
|
|
152
|
+
return [...byPath.values()].sort((a, b) => a.relative.localeCompare(b.relative));
|
|
153
|
+
}
|
|
154
|
+
function authorityBinding(sourceRoot) {
|
|
155
|
+
const authorityPath = path.join(sourceRoot, AUTHORITY_PATH);
|
|
156
|
+
const bytes = fs.readFileSync(authorityPath);
|
|
157
|
+
const authority = loadYamlMapping(bytes.toString("utf8"));
|
|
158
|
+
if (typeof authority.schema_version !== "string" || !mapping(authority.entity_migration)) {
|
|
159
|
+
throw new Error("active entity migration authority is missing its schema version or entity_migration contract");
|
|
160
|
+
}
|
|
161
|
+
return { authority_schema_version: authority.schema_version, authority_sha256: hash(bytes) };
|
|
162
|
+
}
|
|
163
|
+
function sourceFingerprint(files) {
|
|
164
|
+
return hash(canonicalRecordJson(files.map((file) => ({
|
|
165
|
+
path: file.relative,
|
|
166
|
+
presence: file.kind,
|
|
167
|
+
size: file.bytes?.byteLength ?? 0,
|
|
168
|
+
sha256: file.bytes ? hash(file.bytes) : null,
|
|
169
|
+
mode: file.kind === "file" ? file.mode : null,
|
|
170
|
+
dev: file.kind === "file" ? String(file.dev) : null,
|
|
171
|
+
ino: file.kind === "file" ? String(file.ino) : null,
|
|
172
|
+
type: file.kind === "file" ? file.type : null,
|
|
173
|
+
}))));
|
|
174
|
+
}
|
|
175
|
+
function parseYaml(source) {
|
|
176
|
+
if (source.kind !== "file" || !source.bytes)
|
|
177
|
+
throw new Error(source.kind === "unsafe" ? "source path is a symbolic link or non-file" : "source is missing");
|
|
178
|
+
return loadYamlMapping(source.bytes.toString("utf8"));
|
|
179
|
+
}
|
|
180
|
+
function recovery(project, pathName) {
|
|
181
|
+
return `Repair '${pathName}', then run ${fullEntityUpgradePreviewCommand(project)}.`;
|
|
182
|
+
}
|
|
183
|
+
function unsafeSourceMessage(pathName) {
|
|
184
|
+
return `source path '${pathName}' is a symbolic link, non-file, or unreadable; replace it with a readable regular file inside the project`;
|
|
185
|
+
}
|
|
186
|
+
function inventoryFailureObservations(files, observations) {
|
|
187
|
+
for (const source of files.filter((candidate) => candidate.kind === "unsafe" && candidate.relative.endsWith("/"))) {
|
|
188
|
+
observations.push({
|
|
189
|
+
key: `migration_inventory:${source.relative}`,
|
|
190
|
+
artifact: "state",
|
|
191
|
+
boundary: "migration_inventory",
|
|
192
|
+
path: source.relative,
|
|
193
|
+
provenance: "source_inventory",
|
|
194
|
+
record: null,
|
|
195
|
+
detail: "corrupt",
|
|
196
|
+
relationships: [],
|
|
197
|
+
message: `inventory directory '${source.relative}' changed while it was enumerated; no candidate names were accepted`,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function numberedObservations(root, sourceRoot, files, observations, aggregateCollections) {
|
|
202
|
+
const correlationSource = files.find((source) => source.relative === ".agentera/archive/recovery/projection-correlation.yaml");
|
|
203
|
+
let correlationManifest = null;
|
|
204
|
+
if (correlationSource?.kind === "file") {
|
|
205
|
+
try {
|
|
206
|
+
const manifest = parseYaml(correlationSource);
|
|
207
|
+
const entries = Array.isArray(manifest.entries) ? manifest.entries.map(mapping) : [];
|
|
208
|
+
const validEntries = entries.filter((entry) => Boolean(entry));
|
|
209
|
+
const digest = hash(canonicalRecordJson({ schemaVersion: "agentera.projectionCorrelationSet.v1", entries: validEntries }));
|
|
210
|
+
if (manifest.schemaVersion !== "agentera.projectionCorrelationManifest.v1" || manifest.recovery_set_digest !== digest || validEntries.length !== entries.length)
|
|
211
|
+
throw new Error("projection correlation manifest schema or digest is invalid");
|
|
212
|
+
correlationManifest = new Map(validEntries.map((entry) => [String(entry.identity), entry]));
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
observations.push({ key: "projection_correlation:manifest", artifact: "state", boundary: "migration_inventory", path: correlationSource.relative, provenance: "source_inventory", record: null, detail: "corrupt", relationships: [], message: error.message });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
else if (correlationSource?.kind === "unsafe") {
|
|
219
|
+
observations.push({ key: "projection_correlation:manifest", artifact: "state", boundary: "migration_inventory", path: correlationSource.relative, provenance: "source_inventory", record: null, detail: "corrupt", relationships: [], message: unsafeSourceMessage(correlationSource.relative) });
|
|
220
|
+
}
|
|
221
|
+
for (const [artifact, declaration] of Object.entries(NUMBERED)) {
|
|
222
|
+
const current = files.find((source) => source.relative === declaration.file);
|
|
223
|
+
if (current?.kind === "file") {
|
|
224
|
+
try {
|
|
225
|
+
const document = parseYaml(current);
|
|
226
|
+
const allowedCollections = new Set(aggregateCollections[declaration.file] ?? []);
|
|
227
|
+
for (const field of Object.keys(document).filter((field) => Array.isArray(document[field]) && !allowedCollections.has(field)).sort()) {
|
|
228
|
+
observations.push({ key: `${artifact}:undeclared_collection:${field}`, artifact, boundary: "migration_inventory", path: declaration.file, provenance: "source_inventory", record: null, detail: "corrupt", relationships: [], message: `aggregate collection '${field}' is not declared for '${declaration.file}' by the state storage authority` });
|
|
229
|
+
}
|
|
230
|
+
const currentValues = document[declaration.collection];
|
|
231
|
+
if (!Array.isArray(currentValues))
|
|
232
|
+
throw new Error(`field '${declaration.collection}' must be a list`);
|
|
233
|
+
const collections = [[declaration.collection, currentValues]];
|
|
234
|
+
if (Array.isArray(document.archive))
|
|
235
|
+
collections.push(["archive", document.archive]);
|
|
236
|
+
collections.flatMap(([collection, values]) => values.map((value, index) => ({ collection, value, index }))).forEach(({ collection, value, index }) => {
|
|
237
|
+
const record = legacySummaryRecord(value);
|
|
238
|
+
const identity = legacyIdentity(record, artifact, "number");
|
|
239
|
+
const number = identity.number;
|
|
240
|
+
const key = number ? `${artifact}:${number}` : `${artifact}:${collection}[${index}]`;
|
|
241
|
+
const assessment = record && typeof record.number === "number"
|
|
242
|
+
? completeRecordAssessment(sourceRoot, artifact, record, "active", declaration.file)
|
|
243
|
+
: { valid: false, violations: ["record number is required"] };
|
|
244
|
+
const valid = assessment.valid;
|
|
245
|
+
const summary = Boolean(record && (typeof record.summary === "string" || record.detail_availability === "summary_only"));
|
|
246
|
+
const text = typeof record?.summary === "string" ? record.summary : "";
|
|
247
|
+
const decisionRefs = artifact === "decisions" ? [...text.matchAll(/\bD([1-9][0-9]*)\b/g)] : [];
|
|
248
|
+
const residue = artifact === "decisions" && decisionRefs.length > 1 && !number;
|
|
249
|
+
observations.push({ key: residue ? `historical_projection_residue:${declaration.file}:${collection}[${index}]` : key, artifact, boundary: residue ? "historical_projection_residue" : declaration.boundary, path: declaration.file, provenance: residue ? "historical_projection_residue" : "current_projection", record, detail: valid ? "full" : summary ? "summary" : "corrupt", relationships: [], sourceRecordSha256: hash(canonicalRecordJson(value)), message: valid || summary ? undefined : "projection record does not satisfy the declared full-detail schema", ...(assessment.inheritedConfidenceProvenance ? { inheritedConfidenceProvenance: assessment.inheritedConfidenceProvenance } : {}), ...(residue ? { migrationProvenance: { classification: "historical_projection_residue", path: declaration.file, collection, index, content_sha256: hash(canonicalRecordJson(record)), text, inbound_structured_references: 0 } } : {}) });
|
|
250
|
+
if (artifact === "decisions" && valid && mapping(record?.satisfaction)) {
|
|
251
|
+
observations.push({ key: `decision_satisfaction:${key}`, artifact: "decisions", boundary: "decision_satisfaction", path: declaration.file, provenance: "current_projection", record: mapping(record?.satisfaction), detail: "full", relationships: [{ field: "decision", target: key }] });
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
observations.push({ key: `${artifact}:projection`, artifact, boundary: declaration.boundary, path: declaration.file, provenance: "current_projection", record: null, detail: "corrupt", relationships: [], message: error.message });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
else if (current?.kind === "unsafe") {
|
|
260
|
+
observations.push({ key: `${artifact}:projection`, artifact, boundary: declaration.boundary, path: declaration.file, provenance: "current_projection", record: null, detail: "corrupt", relationships: [], message: unsafeSourceMessage(declaration.file) });
|
|
261
|
+
}
|
|
262
|
+
for (const source of files.filter((candidate) => candidate.relative.startsWith(`.agentera/archive/${artifact}/`))) {
|
|
263
|
+
const match = new RegExp(`^\\.agentera/archive/${artifact}/([1-9][0-9]*)\\.yaml$`).exec(source.relative);
|
|
264
|
+
if (!match) {
|
|
265
|
+
observations.push({ key: `unsupported:${source.relative}`, artifact, boundary: declaration.boundary, path: source.relative, provenance: "archive", record: null, detail: "corrupt", relationships: [], message: "unsupported archive candidate name" });
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const key = `${artifact}:${match[1]}`;
|
|
269
|
+
try {
|
|
270
|
+
const envelope = parseYaml(source);
|
|
271
|
+
const record = mapping(envelope.record);
|
|
272
|
+
if (!record || envelope.artifact_id !== artifact || envelope.entry_number !== Number(match[1]))
|
|
273
|
+
throw new Error("archive envelope identity does not match its path");
|
|
274
|
+
const expected = hash(canonicalRecordJson(record));
|
|
275
|
+
if (envelope.record_sha256 !== expected)
|
|
276
|
+
throw new Error("archive record_sha256 does not match record bytes");
|
|
277
|
+
if (mapping(envelope.recovery_provenance)) {
|
|
278
|
+
const correlation = correlationManifest?.get(key);
|
|
279
|
+
if (!correlation)
|
|
280
|
+
throw new Error("recovered archive is absent from the immutable projection correlation manifest");
|
|
281
|
+
if (correlation.artifact !== artifact || correlation.identity !== key || correlation.archive_sha256 !== hash(source.bytes)
|
|
282
|
+
|| mapping(correlation.overlay)?.final_record_sha256 !== expected)
|
|
283
|
+
throw new Error("recovered archive does not match its immutable projection correlation manifest entry");
|
|
284
|
+
}
|
|
285
|
+
const assessment = completeRecordAssessment(sourceRoot, artifact, record, "archive", source.relative);
|
|
286
|
+
if (!assessment.valid)
|
|
287
|
+
throw new Error(`archive record is invalid: ${assessment.violations.join("; ")}`);
|
|
288
|
+
observations.push({ key, artifact, boundary: declaration.boundary, path: source.relative, provenance: "verified_archive", record, detail: "full", relationships: [], ...(assessment.inheritedConfidenceProvenance ? { inheritedConfidenceProvenance: assessment.inheritedConfidenceProvenance } : {}), ...(mapping(envelope.recovery_provenance) ? { migrationProvenance: mapping(envelope.recovery_provenance) } : {}) });
|
|
289
|
+
if (artifact === "decisions" && mapping(record.satisfaction)) {
|
|
290
|
+
observations.push({
|
|
291
|
+
key: `decision_satisfaction:${key}`,
|
|
292
|
+
artifact: "decisions",
|
|
293
|
+
boundary: "decision_satisfaction",
|
|
294
|
+
path: source.relative,
|
|
295
|
+
provenance: "verified_archive",
|
|
296
|
+
record: mapping(record.satisfaction),
|
|
297
|
+
detail: "full",
|
|
298
|
+
relationships: [{ field: "decision", target: key }],
|
|
299
|
+
...(mapping(envelope.recovery_provenance) ? { migrationProvenance: { kind: "nested_verified_archive_evidence", source: mapping(envelope.recovery_provenance) } } : {}),
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
observations.push({ key, artifact, boundary: declaration.boundary, path: source.relative, provenance: "archive", record: null, detail: "corrupt", relationships: [], message: error.message });
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function decisionEvidence(sourceRoot, files, observations) {
|
|
310
|
+
const overlay = files.find((source) => source.relative === ".agentera/overlays/decisions.yaml");
|
|
311
|
+
if (overlay?.kind === "file") {
|
|
312
|
+
try {
|
|
313
|
+
const document = parseYaml(overlay);
|
|
314
|
+
for (const [identity, value] of Object.entries(document).sort(([a], [b]) => a.localeCompare(b))) {
|
|
315
|
+
const record = mapping(value);
|
|
316
|
+
const match = /^decisions:([1-9][0-9]*)$/.exec(identity);
|
|
317
|
+
const satisfaction = mapping(record?.satisfaction);
|
|
318
|
+
observations.push({ key: `decision_satisfaction:${identity}`, artifact: "decisions", boundary: "decision_satisfaction", path: overlay.relative, provenance: "overlay", record: satisfaction, detail: match && satisfaction ? "full" : "corrupt", relationships: [{ field: "decision", target: match ? `decisions:${match[1]}` : null }], message: match && satisfaction ? undefined : "decision satisfaction overlay has an unsupported identity or shape" });
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
observations.push({ key: "decision_satisfaction:overlay", artifact: "decisions", boundary: "decision_satisfaction", path: overlay.relative, provenance: "overlay", record: null, detail: "corrupt", relationships: [{ field: "decision", target: null }], message: error.message });
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
else if (overlay?.kind === "unsafe") {
|
|
326
|
+
observations.push({ key: "decision_satisfaction:overlay", artifact: "decisions", boundary: "decision_satisfaction", path: overlay.relative, provenance: "overlay", record: null, detail: "corrupt", relationships: [], message: unsafeSourceMessage(overlay.relative) });
|
|
327
|
+
}
|
|
328
|
+
const revisions = files.find((source) => source.relative === ".agentera/revisions/decisions.yaml");
|
|
329
|
+
if (revisions?.kind === "file") {
|
|
330
|
+
try {
|
|
331
|
+
const document = parseYaml(revisions);
|
|
332
|
+
const contract = decisionRevisionContract(sourceRoot);
|
|
333
|
+
for (const [identity, value] of Object.entries(document).sort(([left], [right]) => left.localeCompare(right))) {
|
|
334
|
+
const target = new RegExp(`^${contract.identityPrefix}:[1-9][0-9]*$`).test(identity) ? identity : null;
|
|
335
|
+
if (!Array.isArray(value)) {
|
|
336
|
+
observations.push({ key: `decision_revision:${identity}`, artifact: "decisions", boundary: "decision_revision", path: revisions.relative, provenance: "revision", record: null, detail: "corrupt", relationships: [{ field: "decision", target }], message: `${identity} must be an ordered list of revision records` });
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
value.forEach((candidate, index) => {
|
|
340
|
+
const record = mapping(candidate);
|
|
341
|
+
const violations = decisionRevisionViolations({ [identity]: [candidate] }, contract);
|
|
342
|
+
observations.push({ key: `decision_revision:${identity}:${index}`, artifact: "decisions", boundary: "decision_revision", path: revisions.relative, provenance: "revision", record, detail: record && violations.length === 0 ? "full" : "corrupt", relationships: [{ field: "decision", target }], message: violations.length === 0 ? undefined : violations.join("; ") });
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
catch (error) {
|
|
347
|
+
observations.push({ key: "decision_revision:document", artifact: "decisions", boundary: "decision_revision", path: revisions.relative, provenance: "revision", record: null, detail: "corrupt", relationships: [{ field: "decision", target: null }], message: error.message });
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
else if (revisions?.kind === "unsafe") {
|
|
351
|
+
observations.push({ key: "decision_revision:document", artifact: "decisions", boundary: "decision_revision", path: revisions.relative, provenance: "revision", record: null, detail: "corrupt", relationships: [], message: unsafeSourceMessage(revisions.relative) });
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
function planObservations(root, files, observations) {
|
|
355
|
+
const active = path.join(root, ".agentera", "plan.yaml");
|
|
356
|
+
const activeSource = files.find((source) => source.relative === ".agentera/plan.yaml");
|
|
357
|
+
const archiveBytes = new Map(files.flatMap((source) => source.kind === "file" && PLAN_ARCHIVE_SOURCE.test(source.relative)
|
|
358
|
+
? [[path.join(root, source.relative), source.bytes]]
|
|
359
|
+
: []));
|
|
360
|
+
const discovery = discoverPlanArtifacts(active, {
|
|
361
|
+
activeBytes: activeSource?.kind === "file" ? activeSource.bytes : null,
|
|
362
|
+
archiveBytes,
|
|
363
|
+
});
|
|
364
|
+
const seen = new Set();
|
|
365
|
+
if (activeSource?.kind === "unsafe") {
|
|
366
|
+
observations.push({ key: "plan:document", artifact: "plan", boundary: "plan", path: activeSource.relative, provenance: "current_canonical", record: null, detail: "corrupt", relationships: [], message: unsafeSourceMessage(activeSource.relative) });
|
|
367
|
+
}
|
|
368
|
+
for (const identity of discovery.identities) {
|
|
369
|
+
const marker = `${identity.stableId}\0${identity.artifact.path}`;
|
|
370
|
+
if (seen.has(marker))
|
|
371
|
+
continue;
|
|
372
|
+
seen.add(marker);
|
|
373
|
+
const sourcePath = relative(root, identity.artifact.path);
|
|
374
|
+
const archived = identity.artifact.path !== active;
|
|
375
|
+
const source = files.find((candidate) => candidate.relative === sourcePath);
|
|
376
|
+
let sourceStatus = String((mapping(identity.artifact.data.header) ?? {}).status ?? "");
|
|
377
|
+
if (source?.kind === "file") {
|
|
378
|
+
const sourceDocument = parseYaml(source);
|
|
379
|
+
sourceStatus = String((mapping(sourceDocument.header) ?? {}).status ?? "");
|
|
380
|
+
}
|
|
381
|
+
const planRecord = structuredClone(identity.artifact.data);
|
|
382
|
+
const migratedHeader = mapping(planRecord.header);
|
|
383
|
+
if (archived && migratedHeader)
|
|
384
|
+
migratedHeader.status = "archived";
|
|
385
|
+
const migrationProvenance = archived ? {
|
|
386
|
+
...identity.artifact.migrationProvenance,
|
|
387
|
+
source_path: sourcePath,
|
|
388
|
+
source_lifecycle: "verified_plan_archive",
|
|
389
|
+
source_status: sourceStatus,
|
|
390
|
+
target_status: "archived",
|
|
391
|
+
} : identity.artifact.migrationProvenance ? { ...identity.artifact.migrationProvenance, source_path: sourcePath } : undefined;
|
|
392
|
+
const classificationDetail = identity.ambiguous ? "corrupt" : "full";
|
|
393
|
+
observations.push({ key: identity.stableId, artifact: "plan", boundary: "plan", path: sourcePath, provenance: archived ? "verified_plan_archive" : "current_canonical", record: planRecord, detail: classificationDetail, relationships: [], message: identity.ambiguous ? "plan identity resolves to conflicting documents" : undefined, ...(migrationProvenance ? { migrationProvenance } : {}) });
|
|
394
|
+
const parts = planDocumentParts(identity.artifact.data);
|
|
395
|
+
parts.tasks.forEach((task, index) => {
|
|
396
|
+
const number = task.number;
|
|
397
|
+
const taskKey = typeof number === "number" && Number.isSafeInteger(number) && number > 0 ? `${identity.stableId}/task:${number}` : `${identity.stableId}/task:index:${index}`;
|
|
398
|
+
const depends = Array.isArray(task.depends_on) ? task.depends_on : [];
|
|
399
|
+
observations.push({
|
|
400
|
+
key: taskKey,
|
|
401
|
+
artifact: "plan",
|
|
402
|
+
boundary: "plan_task",
|
|
403
|
+
path: sourcePath,
|
|
404
|
+
provenance: identity.artifact.path === active ? "current_canonical" : "verified_plan_archive",
|
|
405
|
+
record: task,
|
|
406
|
+
detail: typeof number === "number" ? classificationDetail : "corrupt",
|
|
407
|
+
relationships: [
|
|
408
|
+
{ field: "plan", target: identity.stableId },
|
|
409
|
+
...depends.map((dependency) => { const normalized = /^Task ([1-9][0-9]*)$/.exec(String(dependency))?.[1] ?? String(dependency); return { field: "depends_on", target: /^[1-9][0-9]*$/.test(normalized) ? `${identity.stableId}/task:${normalized}` : null }; }),
|
|
410
|
+
],
|
|
411
|
+
message: typeof number === "number" ? undefined : "plan task has no positive structured number",
|
|
412
|
+
...(identity.artifact.migrationProvenance ? { migrationProvenance: { ...identity.artifact.migrationProvenance, source_path: sourcePath, source_task_index: index } } : {}),
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
for (const diagnostic of discovery.diagnostics.filter((item) => !seen.has(`${item.path}\0diagnostic`))) {
|
|
417
|
+
if (discovery.identities.some((identity) => identity.artifact.path === diagnostic.path))
|
|
418
|
+
continue;
|
|
419
|
+
const sourcePath = relative(root, diagnostic.path);
|
|
420
|
+
observations.push({ key: `plan:corrupt:${sourcePath}`, artifact: "plan", boundary: "plan", path: sourcePath, provenance: "plan_candidate", record: null, detail: "corrupt", relationships: [], message: diagnostic.message });
|
|
421
|
+
}
|
|
422
|
+
for (const source of files.filter((candidate) => PLAN_ARCHIVE_SOURCE.test(candidate.relative))) {
|
|
423
|
+
if (!discovery.identities.some((identity) => relative(root, identity.artifact.path) === source.relative) && !observations.some((entry) => entry.path === source.relative)) {
|
|
424
|
+
observations.push({ key: `plan:corrupt:${source.relative}`, artifact: "plan", boundary: "plan", path: source.relative, provenance: "plan_candidate", record: null, detail: "corrupt", relationships: [], message: source.kind === "unsafe" ? unsafeSourceMessage(source.relative) : "plan archive could not be validated" });
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
function objectiveObservations(root, files, observations) {
|
|
429
|
+
const sourceBytes = new Map(files.flatMap((source) => source.kind === "file" && /^\.agentera\/(optimize|optimera)\/.+\/(objective|experiments)\.yaml$/.test(source.relative)
|
|
430
|
+
? [[path.join(root, source.relative), source.bytes]]
|
|
431
|
+
: []));
|
|
432
|
+
const discovery = discoverObjectiveArtifacts(root, sourceBytes);
|
|
433
|
+
for (const objective of discovery.objectives) {
|
|
434
|
+
for (const objectivePath of objective.paths) {
|
|
435
|
+
const sourcePath = relative(root, objectivePath);
|
|
436
|
+
const source = files.find((candidate) => candidate.relative === sourcePath);
|
|
437
|
+
let document = null;
|
|
438
|
+
try {
|
|
439
|
+
if (source?.kind === "file")
|
|
440
|
+
document = parseYaml(source);
|
|
441
|
+
}
|
|
442
|
+
catch { /* discovery diagnostic accounts for it */ }
|
|
443
|
+
observations.push({ key: objective.stableId, artifact: "objective", boundary: "objective", path: sourcePath, provenance: sourcePath.startsWith(".agentera/optimize/") ? "current_canonical" : "legacy_objective_root", record: document, detail: objective.ambiguous || !document ? "corrupt" : "full", relationships: [], message: objective.ambiguous ? "objective identity is ambiguous" : undefined });
|
|
444
|
+
}
|
|
445
|
+
if (objective.ambiguous)
|
|
446
|
+
continue;
|
|
447
|
+
const objectivePath = objective.paths[0];
|
|
448
|
+
const experimentsRelative = relative(root, path.join(path.dirname(objectivePath), "experiments.yaml"));
|
|
449
|
+
const experiments = files.find((source) => source.relative === experimentsRelative);
|
|
450
|
+
if (experiments?.kind === "file") {
|
|
451
|
+
try {
|
|
452
|
+
const document = parseYaml(experiments);
|
|
453
|
+
for (const experiment of inspectExperimentIdentities(objective.stableId, document).entries) {
|
|
454
|
+
const key = experiment.stableId ?? `${objective.stableId}/experiment:${experiment.provenance.collection}[${experiment.provenance.index}]`;
|
|
455
|
+
observations.push({ key, artifact: "experiments", boundary: "experiment", path: experiments.relative, provenance: "experiment_projection", record: experiment.data, detail: experiment.addressable ? "full" : experiment.compatibility === "legacy_missing_identity" ? "summary" : "corrupt", relationships: [{ field: "objective", target: objective.stableId }], message: experiment.caveats.join("; ") || undefined });
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
catch (error) {
|
|
459
|
+
observations.push({ key: `${objective.stableId}/experiments`, artifact: "experiments", boundary: "experiment", path: experiments.relative, provenance: "experiment_projection", record: null, detail: "corrupt", relationships: [{ field: "objective", target: objective.stableId }], message: error.message });
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
else if (experiments?.kind === "unsafe") {
|
|
463
|
+
observations.push({ key: `${objective.stableId}/experiments`, artifact: "experiments", boundary: "experiment", path: experiments.relative, provenance: "experiment_projection", record: null, detail: "corrupt", relationships: [{ field: "objective", target: objective.stableId }], message: unsafeSourceMessage(experiments.relative) });
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
for (const diagnostic of discovery.diagnostics) {
|
|
467
|
+
for (const candidate of diagnostic.candidate_paths) {
|
|
468
|
+
if (observations.some((entry) => entry.path === relative(root, candidate)))
|
|
469
|
+
continue;
|
|
470
|
+
observations.push({ key: `objective:corrupt:${relative(root, candidate)}`, artifact: "objective", boundary: "objective", path: relative(root, candidate), provenance: "objective_candidate", record: null, detail: "corrupt", relationships: [], message: diagnostic.message });
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
for (const source of files.filter((candidate) => candidate.kind === "unsafe" && /\/(objective|experiments)\.yaml$/.test(candidate.relative))) {
|
|
474
|
+
if (observations.some((entry) => entry.path === source.relative))
|
|
475
|
+
continue;
|
|
476
|
+
const artifact = source.relative.endsWith("/objective.yaml") ? "objective" : "experiments";
|
|
477
|
+
observations.push({ key: `${artifact}:corrupt:${source.relative}`, artifact, boundary: artifact === "objective" ? "objective" : "experiment", path: source.relative, provenance: artifact === "objective" ? "objective_candidate" : "experiment_projection", record: null, detail: "corrupt", relationships: [], message: unsafeSourceMessage(source.relative) });
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
function todoAndDocs(root, sourceRoot, todoPath, files, observations) {
|
|
481
|
+
observations.push(...todoMigrationObservations(root, sourceRoot, todoPath, files));
|
|
482
|
+
const docs = files.find((source) => source.relative === ".agentera/docs.yaml");
|
|
483
|
+
if (docs?.kind === "file") {
|
|
484
|
+
try {
|
|
485
|
+
const document = parseYaml(docs);
|
|
486
|
+
if (document.index !== undefined && !Array.isArray(document.index))
|
|
487
|
+
throw new Error("docs index must be a list");
|
|
488
|
+
(Array.isArray(document.index) ? document.index : []).forEach((value, index) => {
|
|
489
|
+
const sourceRecord = mapping(value);
|
|
490
|
+
const originalStatus = sourceRecord?.status;
|
|
491
|
+
const normalizedStatus = originalStatus === "draft" ? "intent" : originalStatus === "archived" ? "stale" : originalStatus;
|
|
492
|
+
const record = sourceRecord ? { ...structuredClone(sourceRecord), ...(normalizedStatus !== originalStatus ? { status: normalizedStatus } : {}) } : null;
|
|
493
|
+
const identity = typeof record?.path === "string" ? `docs:path:${record.path}` : `docs:index:${index}`;
|
|
494
|
+
const violations = record ? todoDocsRecordViolations("documentation_inventory_entry", record) : ["documentation inventory entry must be a mapping"];
|
|
495
|
+
observations.push({ key: identity, artifact: "docs", boundary: "documentation_inventory_entry", path: docs.relative, provenance: "current_canonical", record, detail: violations.length ? "corrupt" : "full", relationships: [], message: violations.length ? violations.join("; ") : undefined, ...(normalizedStatus !== originalStatus ? { migrationProvenance: { kind: "legacy_docs_status_normalization", source_path: docs.relative, index, ...(sourceRecord?.path !== undefined ? { original_path: sourceRecord.path } : {}), ...(originalStatus !== undefined ? { original_status: originalStatus } : {}), ...(normalizedStatus !== undefined ? { normalized_status: normalizedStatus } : {}) } } : {}) });
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
catch (error) {
|
|
499
|
+
observations.push({ key: "docs:document", artifact: "docs", boundary: "documentation_inventory_entry", path: docs.relative, provenance: "current_canonical", record: null, detail: "corrupt", relationships: [], message: error.message });
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
else if (docs?.kind === "unsafe") {
|
|
503
|
+
observations.push({ key: "docs:document", artifact: "docs", boundary: "documentation_inventory_entry", path: docs.relative, provenance: "current_canonical", record: null, detail: "corrupt", relationships: [], message: unsafeSourceMessage(docs.relative) });
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
function preservedSingletons(files) {
|
|
507
|
+
const declarations = [
|
|
508
|
+
{ boundary: "vision", source_path: ".agentera/vision.yaml" },
|
|
509
|
+
{ boundary: "design", source_path: "DESIGN.md" },
|
|
510
|
+
{ boundary: "changelog", source_path: "CHANGELOG.md" },
|
|
511
|
+
{ boundary: "docs_mapping", source_path: ".agentera/docs.yaml", preserved_sections: ["last_audit", "conventions", "mapping", "coverage", "audit_log"] },
|
|
512
|
+
{ boundary: "profile", source_path: "$AGENTERA_PROFILE_DIR/PROFILE.md" },
|
|
513
|
+
{ boundary: "runtime_local_session_state", source_path: "runtime-local" },
|
|
514
|
+
];
|
|
515
|
+
return declarations.map((declaration) => {
|
|
516
|
+
const source = files.find((candidate) => candidate.relative === declaration.source_path);
|
|
517
|
+
return { ...declaration, presence: source?.kind ?? "missing", content_sha256: source?.bytes ? hash(source.bytes) : null };
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
function summaryBoundary(artifact, fallback) {
|
|
521
|
+
return { progress: "progress_summary", decisions: "decision_summary", health: "health_summary" }[artifact] ?? fallback;
|
|
522
|
+
}
|
|
523
|
+
function canonicalSummaryBodies(group, forbiddenAliases) {
|
|
524
|
+
return new Set(group.flatMap((item) => item.record
|
|
525
|
+
? [canonicalRecordJson(canonicalMigrationRecord(summaryBoundary(item.artifact, item.boundary), item.record, forbiddenAliases))]
|
|
526
|
+
: []));
|
|
527
|
+
}
|
|
528
|
+
function classify(group, forbiddenAliases) {
|
|
529
|
+
if (group.some((item) => item.provenance === "historical_projection_residue"))
|
|
530
|
+
return "historical_projection_residue";
|
|
531
|
+
if (group.some((item) => item.key.startsWith("conflict:")))
|
|
532
|
+
return "conflict";
|
|
533
|
+
if (group.some((item) => item.key.startsWith("unsupported:")))
|
|
534
|
+
return "unsupported";
|
|
535
|
+
if (group.some((item) => item.detail === "corrupt"))
|
|
536
|
+
return "corrupt";
|
|
537
|
+
if (group.every((item) => item.detail === "summary")) {
|
|
538
|
+
if (!COMPACTED_SUMMARY_ARTIFACTS.has(group[0]?.artifact ?? ""))
|
|
539
|
+
return "corrupt";
|
|
540
|
+
return canonicalSummaryBodies(group, forbiddenAliases).size === 1 ? "valid_compacted_summary" : "conflict";
|
|
541
|
+
}
|
|
542
|
+
const full = group.filter((item) => item.detail === "full" && item.record);
|
|
543
|
+
const bodies = new Set(full.map((item) => canonicalRecordJson(item.record)));
|
|
544
|
+
if (bodies.size > 1)
|
|
545
|
+
return "duplicate";
|
|
546
|
+
const archive = group.find((item) => item.provenance === "verified_archive" && item.record);
|
|
547
|
+
const summaries = group.filter((item) => item.detail === "summary" && item.record);
|
|
548
|
+
if (full.length && summaries.length) {
|
|
549
|
+
const selected = archive ?? full[0];
|
|
550
|
+
const recovery = selected.migrationProvenance;
|
|
551
|
+
const recorded = mapping(recovery?.current_projection)?.record_sha256;
|
|
552
|
+
if (!summaries.every((item) => exactProjectionMirror(item.artifact, selected.record, item.record, recorded)))
|
|
553
|
+
return "conflict";
|
|
554
|
+
}
|
|
555
|
+
if (archive || group.some((item) => item.provenance === "verified_plan_archive"))
|
|
556
|
+
return "verified_full";
|
|
557
|
+
if (group.every((item) => item.provenance === "current_projection" || item.provenance === "experiment_projection"))
|
|
558
|
+
return "recoverable_degraded_full_projection";
|
|
559
|
+
return "verified_full";
|
|
560
|
+
}
|
|
561
|
+
function exactProjectionMirror(artifact, full, summary, recorded) {
|
|
562
|
+
if (recorded === hash(canonicalRecordJson(summary)))
|
|
563
|
+
return true;
|
|
564
|
+
if (artifact === "health" && typeof summary.summary === "string" && typeof full.number === "number" && typeof full.date === "string" && typeof full.trajectory === "string") {
|
|
565
|
+
if (summary.summary === `Audit ${full.number} · ${full.date} (${truncateWords(full.trajectory, 10)})`)
|
|
566
|
+
return true;
|
|
567
|
+
}
|
|
568
|
+
if (artifact !== "progress" && artifact !== "decisions" && artifact !== "health")
|
|
569
|
+
return false;
|
|
570
|
+
return canonicalRecordJson(yamlArchiveEntry(artifact, full)) === canonicalRecordJson(summary);
|
|
571
|
+
}
|
|
572
|
+
function buildEntries(project, sourceRoot, fingerprint, observations, forbiddenAliases) {
|
|
573
|
+
const groups = new Map();
|
|
574
|
+
for (const observation of observations)
|
|
575
|
+
groups.set(observation.key, [...(groups.get(observation.key) ?? []), observation]);
|
|
576
|
+
const ids = new Map();
|
|
577
|
+
for (const key of [...groups.keys()].sort()) {
|
|
578
|
+
const group = groups.get(key);
|
|
579
|
+
const canonicalSummaries = group.every((item) => item.detail === "summary") && COMPACTED_SUMMARY_ARTIFACTS.has(group[0]?.artifact ?? "")
|
|
580
|
+
? [...canonicalSummaryBodies(group, forbiddenAliases)].sort()
|
|
581
|
+
: [];
|
|
582
|
+
const identityBinding = canonicalSummaries.length === 1 ? hash(canonicalRecordJson(canonicalSummaries)) : fingerprint;
|
|
583
|
+
const explicitIds = [...new Set(group.map((item) => item.explicitId).filter((id) => id !== undefined))];
|
|
584
|
+
ids.set(key, explicitIds.length === 1 ? explicitIds[0] : entityMigrationId(identityBinding, key));
|
|
585
|
+
}
|
|
586
|
+
const collisions = new Set();
|
|
587
|
+
const idOwners = new Map();
|
|
588
|
+
for (const [key, id] of ids) {
|
|
589
|
+
const owner = idOwners.get(id);
|
|
590
|
+
if (owner) {
|
|
591
|
+
collisions.add(owner);
|
|
592
|
+
collisions.add(key);
|
|
593
|
+
}
|
|
594
|
+
else
|
|
595
|
+
idOwners.set(id, key);
|
|
596
|
+
}
|
|
597
|
+
const entries = [...groups.entries()].map(([key, unsortedGroup]) => {
|
|
598
|
+
const group = [...unsortedGroup].sort((left, right) => `${left.path}\0${left.provenance}\0${canonicalRecordJson(left.record)}\0${left.sourceRecordSha256 ?? ""}`.localeCompare(`${right.path}\0${right.provenance}\0${canonicalRecordJson(right.record)}\0${right.sourceRecordSha256 ?? ""}`));
|
|
599
|
+
let classification = classify(group, forbiddenAliases);
|
|
600
|
+
if (collisions.has(key))
|
|
601
|
+
classification = "conflict";
|
|
602
|
+
const primary = group[0];
|
|
603
|
+
const contentObservation = group.find((item) => item.provenance === "verified_archive" && item.detail === "full" && item.record)
|
|
604
|
+
?? group.find((item) => item.detail === "full" && item.record)
|
|
605
|
+
?? group.find((item) => item.detail === "summary" && item.record);
|
|
606
|
+
const content = contentObservation?.record ?? null;
|
|
607
|
+
const contentSha256s = [...new Set(group.flatMap((item) => item.record ? [hash(canonicalRecordJson(item.record))] : []))].sort();
|
|
608
|
+
const mirrored = contentSha256s.length === 1 && group.filter((item) => item.record).length > 1;
|
|
609
|
+
const id = ids.get(key);
|
|
610
|
+
const relationshipSources = new Map(group.flatMap((item) => item.relationships).map((relationship) => [`${relationship.field}\0${relationship.target ?? ""}`, relationship])).values();
|
|
611
|
+
const relationships = [...relationshipSources].map((relationship) => ({
|
|
612
|
+
field: relationship.field,
|
|
613
|
+
target_source_identity: relationship.target,
|
|
614
|
+
target_id: relationship.target ? ids.get(relationship.target) ?? null : null,
|
|
615
|
+
status: relationship.target && groups.has(relationship.target) ? "resolved" : "unresolved",
|
|
616
|
+
}));
|
|
617
|
+
const summary = classification === "valid_compacted_summary";
|
|
618
|
+
const boundary = summary ? summaryBoundary(primary.artifact, primary.boundary) : contentObservation?.boundary ?? primary.boundary;
|
|
619
|
+
const record = content ? canonicalMigrationRecord(boundary, content, forbiddenAliases, summary ? [] : relationships) : {};
|
|
620
|
+
if (summary && contentObservation && content) {
|
|
621
|
+
record.migration_provenance = {
|
|
622
|
+
source_path: contentObservation.path,
|
|
623
|
+
source_record_sha256: contentObservation.sourceRecordSha256 ?? hash(canonicalRecordJson(content)),
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
const residue = classification === "historical_projection_residue";
|
|
627
|
+
const blocked = BLOCKING.has(classification) || relationships.some((relationship) => relationship.status === "unresolved");
|
|
628
|
+
return {
|
|
629
|
+
source_identity: key,
|
|
630
|
+
source_paths: [...new Set(group.map((item) => item.path))].sort(),
|
|
631
|
+
artifact: primary.artifact,
|
|
632
|
+
boundary,
|
|
633
|
+
classification,
|
|
634
|
+
detail_availability: summary ? "summary" : content ? "full" : "unavailable",
|
|
635
|
+
compatibility: summary ? "degraded" : "current",
|
|
636
|
+
provenance: [...new Set([...group.map((item) => item.provenance), ...(mirrored ? ["mirrored"] : [])])].sort(),
|
|
637
|
+
content_sha256: contentSha256s.length === 1 ? contentSha256s[0] : null,
|
|
638
|
+
content_sha256s: contentSha256s,
|
|
639
|
+
physical_record_count: group.length,
|
|
640
|
+
proposed_target: blocked || residue ? null : { id, path: `.agentera/entities/${primary.artifact}/${boundary}/${id}.yaml` },
|
|
641
|
+
target_sha256: null,
|
|
642
|
+
relationships,
|
|
643
|
+
record,
|
|
644
|
+
recovery: blocked ? recovery(project, primary.path) : "none",
|
|
645
|
+
...(contentObservation?.inheritedConfidenceProvenance ? { canonical_migration_provenance: contentObservation.inheritedConfidenceProvenance } : {}),
|
|
646
|
+
...(group.some((item) => item.migrationProvenance) ? { migration_provenance: group.flatMap((item) => item.migrationProvenance ? [item.migrationProvenance] : []) } : {}),
|
|
647
|
+
};
|
|
648
|
+
}).sort((a, b) => `${a.artifact}\0${a.boundary}\0${a.source_identity}\0${a.source_paths[0]}`.localeCompare(`${b.artifact}\0${b.boundary}\0${b.source_identity}\0${b.source_paths[0]}`));
|
|
649
|
+
const decisions = new Map(entries.filter(({ boundary, proposed_target }) => boundary === "decision" && proposed_target).map((entry) => [entry.proposed_target.id, entry.record]));
|
|
650
|
+
const legacyDecisions = new Map(entries.filter(({ boundary, proposed_target }) => boundary === "decision" && proposed_target).flatMap((entry) => {
|
|
651
|
+
const group = groups.get(entry.source_identity) ?? [];
|
|
652
|
+
const source = group.find((item) => item.provenance === "verified_archive" && item.detail === "full" && item.record)
|
|
653
|
+
?? group.find((item) => item.detail === "full" && item.record);
|
|
654
|
+
return source?.record ? [[entry.proposed_target.id, source.record]] : [];
|
|
655
|
+
}));
|
|
656
|
+
migrateDecisionRevisionEntries(entries, decisions, legacyDecisions, sourceRoot, forbiddenAliases, fingerprint);
|
|
657
|
+
return entries;
|
|
658
|
+
}
|
|
659
|
+
export function validateEntityMigrationTargets(project, entries, sourceRoot) {
|
|
660
|
+
const targets = entries.flatMap((entry) => entry.proposed_target && entry.artifact && entry.boundary ? [{ sourceIdentity: entry.source_identity, path: entry.proposed_target.path, id: entry.proposed_target.id, artifact: entry.artifact, boundary: entry.boundary, record: entry.record, migrationProvenance: entry.canonical_migration_provenance }] : []);
|
|
661
|
+
const diagnostics = validateCanonicalEntityTargets(project, targets, sourceRoot);
|
|
662
|
+
for (const entry of entries) {
|
|
663
|
+
if (!entry.proposed_target || !entry.artifact)
|
|
664
|
+
continue;
|
|
665
|
+
const actual = hash(canonicalEntityEnvelopeBytes({ id: entry.proposed_target.id, artifact: entry.artifact, record: entry.record, migrationProvenance: entry.canonical_migration_provenance }));
|
|
666
|
+
if (entry.target_sha256 !== actual)
|
|
667
|
+
diagnostics.push({ sourceIdentity: entry.source_identity, path: entry.proposed_target.path, message: `canonical target bytes have SHA-256 '${actual}', not manifest binding '${entry.target_sha256 ?? "missing"}'` });
|
|
668
|
+
}
|
|
669
|
+
return diagnostics;
|
|
670
|
+
}
|
|
671
|
+
function migrationInventory(projectRoot, sourceRoot, resolveDescriptorPath) {
|
|
672
|
+
const project = path.resolve(projectRoot);
|
|
673
|
+
const validatedProject = validateRealProjectRoot(project);
|
|
674
|
+
const authority = authorityBinding(sourceRoot);
|
|
675
|
+
const todoRecord = loadArtifactRecord("todo");
|
|
676
|
+
if (!todoRecord)
|
|
677
|
+
throw new Error("artifact registry is missing the canonical 'todo' record");
|
|
678
|
+
const docsSnapshot = { relative: ".agentera/docs.yaml", ...readProjectFileSnapshot(validatedProject, ".agentera/docs.yaml", resolveDescriptorPath) };
|
|
679
|
+
const overrides = docsSnapshot.kind === "file" ? docsPathOverridesFromBytes(docsSnapshot.bytes) : {};
|
|
680
|
+
const todoAbsolute = todoRecord.displayName in overrides ? resolveArtifactPath(todoRecord, project, { docsPathOverrides: overrides }) : path.join(project, todoRecord.defaultPath);
|
|
681
|
+
const todoPath = relative(project, todoAbsolute);
|
|
682
|
+
if (todoPath !== todoRecord.defaultPath)
|
|
683
|
+
assertRealpathBoundary(project, todoAbsolute, todoRecord.artifactId);
|
|
684
|
+
const files = collectSources(project, validatedProject, todoPath, docsSnapshot, resolveDescriptorPath);
|
|
685
|
+
const fingerprint = sourceFingerprint(files);
|
|
686
|
+
const observations = [];
|
|
687
|
+
inventoryFailureObservations(files, observations);
|
|
688
|
+
numberedObservations(project, sourceRoot, files, observations, entityPreservedAggregateCollections(sourceRoot));
|
|
689
|
+
decisionEvidence(sourceRoot, files, observations);
|
|
690
|
+
planObservations(project, files, observations);
|
|
691
|
+
objectiveObservations(project, files, observations);
|
|
692
|
+
todoAndDocs(project, sourceRoot, todoPath, files, observations);
|
|
693
|
+
const preserved = preservedSingletons(files);
|
|
694
|
+
const completeInventory = buildEntries(project, sourceRoot, fingerprint, observations, entityForbiddenCanonicalAliases(sourceRoot));
|
|
695
|
+
const preservedResidues = completeInventory.filter((entry) => entry.classification === "historical_projection_residue");
|
|
696
|
+
const completeEntries = completeInventory.filter((entry) => entry.classification !== "historical_projection_residue");
|
|
697
|
+
const todoReconciliation = todoReconciliationMigrationPlan(todoPath, files, completeEntries);
|
|
698
|
+
for (const entry of completeEntries) {
|
|
699
|
+
if (entry.proposed_target && entry.artifact)
|
|
700
|
+
entry.target_sha256 = hash(canonicalEntityEnvelopeBytes({ id: entry.proposed_target.id, artifact: entry.artifact, record: entry.record, migrationProvenance: entry.canonical_migration_provenance }));
|
|
701
|
+
}
|
|
702
|
+
let causal = applyCausalBlockers(completeEntries, (sourcePath) => recovery(project, sourcePath));
|
|
703
|
+
const targetDiagnostics = validateEntityMigrationTargets(project, completeEntries, sourceRoot);
|
|
704
|
+
for (const diagnostic of targetDiagnostics) {
|
|
705
|
+
const entry = completeEntries.find((candidate) => candidate.source_identity === diagnostic.sourceIdentity);
|
|
706
|
+
if (!entry)
|
|
707
|
+
continue;
|
|
708
|
+
entry.classification = "corrupt";
|
|
709
|
+
entry.proposed_target = null;
|
|
710
|
+
entry.target_sha256 = null;
|
|
711
|
+
if (entry.recovery === "none")
|
|
712
|
+
entry.recovery = recovery(project, entry.source_paths[0]);
|
|
713
|
+
causal.rootReasons.set(entry.source_identity, `target_invalid: ${diagnostic.message}`);
|
|
714
|
+
}
|
|
715
|
+
causal = applyCausalBlockers(completeEntries, (sourcePath) => recovery(project, sourcePath), causal.rootReasons);
|
|
716
|
+
const classes = ["verified_full", "recoverable_degraded_full_projection", "valid_compacted_summary", "duplicate", "conflict", "corrupt", "unsupported", "historical_projection_residue"];
|
|
717
|
+
const counts = Object.fromEntries(classes.map((classification) => [classification, completeInventory.filter((entry) => entry.classification === classification).length]));
|
|
718
|
+
counts.total = completeInventory.length;
|
|
719
|
+
counts.publishable_entities = completeEntries.filter(({ proposed_target }) => proposed_target !== null).length;
|
|
720
|
+
counts.logical_identities = completeInventory.length;
|
|
721
|
+
counts.physical_records = observations.length;
|
|
722
|
+
counts.mirrors = completeInventory.reduce((total, entry) => total + (entry.provenance.includes("mirrored") ? entry.physical_record_count - 1 : 0), 0);
|
|
723
|
+
counts.duplicates = completeInventory.reduce((total, entry) => total + (entry.classification === "duplicate" ? entry.physical_record_count - 1 : 0), 0);
|
|
724
|
+
counts.conflicts = counts.duplicate + counts.conflict;
|
|
725
|
+
counts.relationships = completeEntries.reduce((total, entry) => total + entry.relationships.length, 0);
|
|
726
|
+
counts.unresolved_relationships = completeEntries.reduce((total, entry) => total + entry.relationships.filter((relationship) => relationship.status === "unresolved").length, 0);
|
|
727
|
+
const rootDiagnostics = completeEntries
|
|
728
|
+
.filter((entry) => causal.rootReasons.has(entry.source_identity))
|
|
729
|
+
.map((entry) => {
|
|
730
|
+
const unresolved = entry.relationships.find((relationship) => relationship.status === "unresolved");
|
|
731
|
+
const reason = causal.rootReasons.get(entry.source_identity) ?? `${entry.classification} source requires explicit recovery`;
|
|
732
|
+
const observationMessage = observations.find((item) => item.key === entry.source_identity)?.message;
|
|
733
|
+
return {
|
|
734
|
+
classification: entry.classification,
|
|
735
|
+
path: entry.source_paths[0],
|
|
736
|
+
source_identity: entry.source_identity,
|
|
737
|
+
...(unresolved ? { relationship_field: unresolved.field, target_source_identity: unresolved.target_source_identity } : {}),
|
|
738
|
+
message: reason === `${entry.classification} source requires explicit recovery` && observationMessage ? observationMessage : reason,
|
|
739
|
+
recovery: entry.recovery,
|
|
740
|
+
};
|
|
741
|
+
});
|
|
742
|
+
const dependentDiagnostics = completeEntries.flatMap((entry) => {
|
|
743
|
+
if (causal.rootReasons.has(entry.source_identity))
|
|
744
|
+
return [];
|
|
745
|
+
return entry.relationships.flatMap((relationship) => {
|
|
746
|
+
if (relationship.status !== "resolved" || !relationship.target_source_identity)
|
|
747
|
+
return [];
|
|
748
|
+
return causal.rootsFor(relationship.target_source_identity).map((rootSourceIdentity) => ({
|
|
749
|
+
classification: "dependent_blocker",
|
|
750
|
+
path: entry.source_paths[0],
|
|
751
|
+
source_identity: entry.source_identity,
|
|
752
|
+
relationship_field: relationship.field,
|
|
753
|
+
target_source_identity: relationship.target_source_identity,
|
|
754
|
+
root_source_identity: rootSourceIdentity,
|
|
755
|
+
message: `source '${entry.source_identity}' relationship '${relationship.field}' is blocked by root source '${rootSourceIdentity}'`,
|
|
756
|
+
recovery: recovery(project, entry.source_paths[0]),
|
|
757
|
+
}));
|
|
758
|
+
});
|
|
759
|
+
});
|
|
760
|
+
const diagnostics = [...rootDiagnostics, ...dependentDiagnostics].sort((left, right) => `${left.source_identity}\0${left.classification}\0${left.relationship_field ?? ""}\0${left.target_source_identity ?? ""}\0${left.root_source_identity ?? ""}`.localeCompare(`${right.source_identity}\0${right.classification}\0${right.relationship_field ?? ""}\0${right.target_source_identity ?? ""}\0${right.root_source_identity ?? ""}`));
|
|
761
|
+
counts.root_blockers = rootDiagnostics.length;
|
|
762
|
+
counts.dependent_blockers = dependentDiagnostics.length;
|
|
763
|
+
counts.blockers = counts.root_blockers + counts.dependent_blockers;
|
|
764
|
+
const digestEntries = completeEntries.map(({ record: _record, ...entry }) => entry);
|
|
765
|
+
const digestResidues = preservedResidues.map(({ record: _record, ...entry }) => entry);
|
|
766
|
+
const digestBody = { source_fingerprint: fingerprint, authority, selectors: { project, filter: INVENTORY_FILTER, order: INVENTORY_ORDER }, entries: digestEntries, preserved_residues: digestResidues, preserved_singletons: preserved, counts, diagnostics, todo_reconciliation: todoReconciliation ?? null };
|
|
767
|
+
const previewDigest = hash(canonicalRecordJson(digestBody));
|
|
768
|
+
const sources = files.map((file) => {
|
|
769
|
+
return { path: file.relative, presence: file.kind === "file" ? "file" : "missing", size: file.bytes?.byteLength ?? 0, sha256: file.bytes ? hash(file.bytes) : null, mode: file.kind === "file" ? file.mode : null, dev: file.kind === "file" ? String(file.dev) : null, ino: file.kind === "file" ? String(file.ino) : null, type: file.kind === "file" ? file.type : null, bytes_base64: file.bytes?.toString("base64") ?? null };
|
|
770
|
+
});
|
|
771
|
+
return { project, source_fingerprint: fingerprint, preview_digest: previewDigest, ...authority, preserved_singletons: preserved, entries: completeEntries, preserved_residues: preservedResidues, sources, counts, diagnostics, ...(todoReconciliation ? { todo_reconciliation: todoReconciliation } : {}) };
|
|
772
|
+
}
|
|
773
|
+
export function planEntityMigration(projectRoot, sourceRoot, options = {}) {
|
|
774
|
+
return migrationInventory(projectRoot, sourceRoot, options.resolveDescriptorPath ?? resolveProjectDescriptorPath);
|
|
775
|
+
}
|
|
776
|
+
export function previewEntityMigration(projectRoot, sourceRoot, options = {}) {
|
|
777
|
+
const inventory = migrationInventory(projectRoot, sourceRoot, options.resolveDescriptorPath ?? resolveProjectDescriptorPath);
|
|
778
|
+
const { project, source_fingerprint: fingerprint, preview_digest: previewDigest, preserved_singletons: preserved, counts, diagnostics } = inventory;
|
|
779
|
+
const authority = { authority_schema_version: inventory.authority_schema_version, authority_sha256: inventory.authority_sha256 };
|
|
780
|
+
const completeEntries = inventory.entries.map(({ record: _record, ...entry }) => entry);
|
|
781
|
+
const preservedResidues = inventory.preserved_residues.map(({ record: _record, ...entry }) => entry);
|
|
782
|
+
const requestedLimit = Math.max(1, Math.min(options.limit ?? DEFAULT_LIMIT, MAX_LIMIT));
|
|
783
|
+
const restartCommand = fullEntityUpgradePreviewCommand(project);
|
|
784
|
+
if (options.after !== undefined && (options.sourceFingerprint !== fingerprint || options.previewDigest !== previewDigest)) {
|
|
785
|
+
throw new EntityMigrationContinuationError(restartCommand);
|
|
786
|
+
}
|
|
787
|
+
const start = options.after === undefined ? 0 : completeEntries.findIndex((entry) => entry.source_identity === options.after) + 1;
|
|
788
|
+
if (options.after !== undefined && start === 0)
|
|
789
|
+
throw new Error(`pagination cursor '${options.after}' is not a source identity in the bound inventory; restart without --after`);
|
|
790
|
+
let entries = completeEntries.slice(start, start + requestedLimit);
|
|
791
|
+
const diagnosticsForEntries = () => {
|
|
792
|
+
const identities = new Set(entries.map((entry) => entry.source_identity));
|
|
793
|
+
return diagnostics.filter((diagnostic) => identities.has(diagnostic.source_identity));
|
|
794
|
+
};
|
|
795
|
+
let omissionReason = start > 0 || start + entries.length < completeEntries.length ? "result_limit" : null;
|
|
796
|
+
const base = { schemaVersion: "agentera.entityMigrationPreview.v1", command: "upgrade", status: counts.blockers > 0 ? "blocked" : "ready", mode: "preview", project, read_only: true, mutation_intent: false, mutation_performed: false, source_fingerprint: fingerprint, preview_digest: previewDigest, preserved_singletons: preserved, preserved_residues: preservedResidues, counts, source_contract: { authority: AUTHORITY_PATH, ...authority, zero_write: true, scalar_truncation: "forbidden", apply_owner: "full development-channel upgrade --yes" } };
|
|
797
|
+
const serializedBytes = () => {
|
|
798
|
+
const pageDiagnostics = diagnosticsForEntries();
|
|
799
|
+
const nextAfter = start + entries.length < completeEntries.length ? entries.at(-1)?.source_identity ?? null : null;
|
|
800
|
+
const command = restartCommand;
|
|
801
|
+
const body = { ...base, entries, diagnostics: pageDiagnostics, omitted: start > 0 || entries.length < completeEntries.length, omitted_count: completeEntries.length - entries.length, diagnostics_omitted_count: diagnostics.length - pageDiagnostics.length, omission_reason: omissionReason, page_after: options.after ?? null, next_after: nextAfter, retrieval: { command } };
|
|
802
|
+
return Math.max(Buffer.byteLength(JSON.stringify(body, null, 2), "utf8"), Buffer.byteLength(YAML.stringify(body), "utf8"));
|
|
803
|
+
};
|
|
804
|
+
while (entries.length > 0 && serializedBytes() > ENTITY_MIGRATION_PREVIEW_MAX_OUTPUT_BYTES) {
|
|
805
|
+
entries = entries.slice(0, -1);
|
|
806
|
+
omissionReason = "output_byte_budget";
|
|
807
|
+
}
|
|
808
|
+
if (entries.length === 0 && start < completeEntries.length)
|
|
809
|
+
throw new Error(`the next whole migration entry exceeds the ${ENTITY_MIGRATION_PREVIEW_MAX_OUTPUT_BYTES}-byte output budget; repair that source before retrying`);
|
|
810
|
+
const outputDiagnostics = diagnosticsForEntries();
|
|
811
|
+
const nextAfter = start + entries.length < completeEntries.length ? entries.at(-1)?.source_identity ?? null : null;
|
|
812
|
+
const retrieval = { command: restartCommand };
|
|
813
|
+
return { ...base, status: base.status, mode: "preview", entries, diagnostics: outputDiagnostics, omitted: start > 0 || entries.length < completeEntries.length, omitted_count: completeEntries.length - entries.length, diagnostics_omitted_count: diagnostics.length - outputDiagnostics.length, omission_reason: omissionReason, page_after: options.after ?? null, next_after: nextAfter, retrieval };
|
|
814
|
+
}
|
|
815
|
+
export class EntityMigrationContinuationError extends Error {
|
|
816
|
+
restartCommand;
|
|
817
|
+
classification = "continuation_changed";
|
|
818
|
+
constructor(restartCommand) {
|
|
819
|
+
super(`entity migration continuation no longer matches its source, migration authority, selectors, or order; restart with ${restartCommand}`);
|
|
820
|
+
this.restartCommand = restartCommand;
|
|
821
|
+
this.name = "EntityMigrationContinuationError";
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
export class EntityMigrationBindingError extends Error {
|
|
825
|
+
current;
|
|
826
|
+
classification = "source_changed";
|
|
827
|
+
restartCommand;
|
|
828
|
+
constructor(current) {
|
|
829
|
+
const restartCommand = fullEntityUpgradePreviewCommand(current.project);
|
|
830
|
+
super(`entity migration source or migration authority changed after preview; rerun ${restartCommand}`);
|
|
831
|
+
this.current = current;
|
|
832
|
+
this.restartCommand = restartCommand;
|
|
833
|
+
this.name = "EntityMigrationBindingError";
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
export function assertEntityMigrationBinding(expectedSourceFingerprint, expectedPreviewDigest, current, effect) {
|
|
837
|
+
if (current.source_fingerprint !== expectedSourceFingerprint || current.preview_digest !== expectedPreviewDigest)
|
|
838
|
+
throw new EntityMigrationBindingError(current);
|
|
839
|
+
return effect();
|
|
840
|
+
}
|