agentera 3.0.0-dev.8 → 3.0.0-dev.80
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 +252 -22
- package/bundle/.agentera-build-source.json +8 -0
- package/bundle/CHANGELOG.md +1387 -0
- package/bundle/DESIGN.md +229 -0
- package/bundle/LICENSE +201 -0
- package/bundle/README.md +143 -0
- package/bundle/UPGRADE.md +271 -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 +484 -0
- package/bundle/references/adapters/package-registry.yaml +443 -188
- package/bundle/references/adapters/package-surface-characterization.md +68 -34
- package/bundle/references/adapters/product-v1-reset.yaml +101 -0
- 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 +559 -0
- package/bundle/references/analysis/personal-glossary-evaluation-authority.yaml +175 -0
- package/bundle/references/analysis/personal-glossary-evaluation-corpus.yaml +291 -0
- package/bundle/references/analysis/personal-glossary-holdout.yaml +192 -0
- package/bundle/references/analysis/verification-policy.yaml +261 -0
- package/bundle/references/artifacts/artifact-registry-interface-model.yaml +17 -8
- package/bundle/references/artifacts/glossary-entry-contract.yaml +2906 -0
- package/bundle/references/artifacts/state-storage-authority.yaml +3065 -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 +7 -5
- package/bundle/references/cli/vocabulary-index.yaml +7 -9
- package/bundle/references/cli/vocabulary.md +54 -97
- package/bundle/references/meta/retained-reference-authority.yaml +171 -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 +13 -4
- package/bundle/skills/agentera/capabilities/profile/schemas/exit.yaml +8 -5
- package/bundle/skills/agentera/capabilities/profile/schemas/triggers.yaml +8 -37
- package/bundle/skills/agentera/capabilities/profile/schemas/validation.yaml +67 -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 +29 -30
- package/bundle/skills/agentera/schemas/artifacts/design.yaml +1 -0
- package/bundle/skills/agentera/schemas/artifacts/docs.yaml +7 -43
- package/bundle/skills/agentera/schemas/artifacts/experiments.yaml +140 -34
- package/bundle/skills/agentera/schemas/artifacts/glossary.yaml +87 -0
- package/bundle/skills/agentera/schemas/artifacts/health.yaml +53 -51
- package/bundle/skills/agentera/schemas/artifacts/objective.yaml +18 -35
- package/bundle/skills/agentera/schemas/artifacts/plan.yaml +453 -55
- package/bundle/skills/agentera/schemas/artifacts/progress.yaml +128 -39
- package/bundle/skills/agentera/schemas/artifacts/todo.yaml +305 -7
- package/bundle/skills/agentera/schemas/artifacts/vision.yaml +0 -19
- package/dist/.agentera-build-source.json +8 -0
- package/dist/analytics/extractCorpus/cli.js +52 -11
- package/dist/analytics/extractCorpus/copilotSessions.js +19 -8
- package/dist/analytics/extractCorpus/core.js +262 -14
- package/dist/analytics/extractCorpus/corpus.js +57 -18
- package/dist/analytics/extractCorpus/coverageAudit.js +44 -45
- package/dist/analytics/extractCorpus/cursorSessions.js +28 -8
- package/dist/analytics/extractCorpus/evidenceTiers.js +709 -0
- package/dist/analytics/extractCorpus/extractCorpusParity.js +4 -4
- package/dist/analytics/extractCorpus/filesystemSources.js +5 -5
- package/dist/analytics/extractCorpus/index.js +4 -2
- package/dist/analytics/extractCorpus/jsonlSessions.js +76 -8
- package/dist/analytics/extractCorpus/sqliteCaps.js +0 -1
- package/dist/analytics/extractCorpus/sqliteSessions.js +12 -4
- 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 +113 -0
- package/dist/analytics/personalGlossaryCandidateProjection.js +788 -0
- package/dist/analytics/personalGlossaryCandidateProjectionExcerpts.js +144 -0
- package/dist/analytics/personalGlossaryCandidateProjectionModel.js +1 -0
- package/dist/analytics/personalGlossaryCandidateReadView.js +23 -0
- package/dist/analytics/personalGlossaryCurrentGeneration.js +25 -0
- package/dist/analytics/personalGlossaryDecision.js +203 -0
- package/dist/analytics/personalGlossaryExplicit.js +788 -0
- package/dist/analytics/personalGlossaryExplicitMining.js +285 -0
- package/dist/analytics/personalGlossaryExplicitScope.js +41 -0
- package/dist/analytics/personalGlossaryExplicitSegments.js +418 -0
- package/dist/analytics/personalGlossaryExplicitTypes.js +26 -0
- package/dist/analytics/personalGlossaryLexicalClassifier.js +175 -0
- package/dist/analytics/personalGlossaryProfile.js +229 -0
- package/dist/analytics/personalGlossaryRecurrence.js +618 -0
- package/dist/analytics/personalGlossaryRefreshProjection.js +351 -0
- package/dist/analytics/personalGlossaryReviewRecordStorage.js +428 -0
- package/dist/analytics/personalGlossaryReviewRecords.js +332 -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 +20 -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 +104 -5
- 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 +52 -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 +118 -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/personalGlossaryCandidateReads.js +755 -0
- package/dist/cli/commands/personalGlossaryDecision.js +349 -0
- package/dist/cli/commands/personalGlossaryPublish.js +484 -0
- package/dist/cli/commands/personalGlossaryReviewRecordReads.js +209 -0
- package/dist/cli/commands/personalGlossaryReviewRecords.js +623 -0
- package/dist/cli/commands/prime/briefOrientation.js +845 -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 +338 -0
- package/dist/cli/commands/prime/collectOrientationState.js +124 -68
- package/dist/cli/commands/prime/orientationOutput.js +271 -59
- package/dist/cli/commands/prime/types.js +0 -1
- package/dist/cli/commands/prime.js +89 -11
- package/dist/cli/commands/profileGrounding.js +55 -0
- package/dist/cli/commands/query.js +74 -52
- package/dist/cli/commands/report.js +187 -27
- package/dist/cli/commands/route.js +142 -0
- package/dist/cli/commands/schema.js +436 -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 +459 -0
- package/dist/cli/commands/upgrade.js +176 -5
- package/dist/cli/commands/upgradeVerify.js +118 -0
- package/dist/cli/commands/validate.js +235 -136
- package/dist/cli/commands/verify.js +73 -16
- 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 +84 -52
- package/dist/cli/dispatch/lifecycle.js +182 -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 +419 -41
- package/dist/cli/migrationRequired.js +125 -0
- package/dist/cli/orientation/attention.js +19 -22
- 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/productV1Eol.js +55 -0
- package/dist/cli/profileAcquisition.js +167 -0
- package/dist/cli/startupCompletenessContract.js +11 -9
- 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 +23 -0
- package/dist/core/developmentChannel.js +1 -0
- package/dist/core/developmentInvocation.js +377 -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 +61 -2
- package/dist/eval/evalSkills.js +13 -14
- package/dist/eval/glossaryEvaluation.js +751 -0
- package/dist/eval/glossaryEvaluationProcess.js +29 -0
- package/dist/eval/glossaryEvaluationRunner.js +571 -0
- package/dist/eval/glossaryEvaluationSuccessReport.js +297 -0
- 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 +145 -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 +375 -0
- package/dist/registries/explicitSegmentGrammarContract.js +619 -0
- package/dist/registries/glossaryAdviceContract.js +79 -0
- package/dist/registries/glossaryCandidateContractPaths.js +6 -0
- package/dist/registries/glossaryCandidateContracts.js +820 -0
- package/dist/registries/glossaryCandidateDecisionAuthority.js +119 -0
- package/dist/registries/glossaryCandidateDecisionContract.js +62 -0
- package/dist/registries/glossaryCandidateProjectionAuthority.js +345 -0
- package/dist/registries/glossaryCandidateProjectionContract.js +108 -0
- package/dist/registries/glossaryCaveatContract.js +67 -0
- package/dist/registries/glossaryConsumerContractValidation.js +787 -0
- package/dist/registries/glossaryEntryContract.js +759 -0
- package/dist/registries/glossaryEntryTemporal.js +12 -0
- package/dist/registries/glossaryMiningAuthority.js +764 -0
- package/dist/registries/glossaryProfileFullContract.js +24 -0
- package/dist/registries/glossaryReviewRecordsAuthority.js +426 -0
- package/dist/registries/glossaryReviewRecordsContract.js +129 -0
- package/dist/registries/glossaryTermIdentity.js +139 -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/personalGlossaryContracts.js +1 -0
- 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 +168 -11
- 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 +503 -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/todoCreateBatch.js +69 -0
- package/dist/state/todoDocsEntities.js +1339 -0
- package/dist/state/todoDocsEntityValidation.js +158 -0
- package/dist/state/todoMarkdownProjection.js +63 -0
- package/dist/state/todoReconciliationActivation.js +182 -0
- package/dist/state/todoReconciliationInspection.js +184 -0
- package/dist/state/todoReconciliationRepair.js +320 -0
- package/dist/state/todoReconciliationTransaction.js +628 -0
- package/dist/state/todoSeverityHeadings.js +71 -0
- package/dist/state/todoTransitionBatch.js +65 -0
- package/dist/state/todoUpdateBatch.js +50 -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 +380 -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 +133 -34
- package/dist/upgrade/lifecycleUpgrade.js +113 -0
- package/dist/upgrade/migrateArtifactsV2ToV3.js +325 -82
- package/dist/upgrade/migrationPublication.js +122 -0
- package/dist/upgrade/nextMajorDoctor.js +0 -22
- package/dist/upgrade/npxPlatformStatus.js +2 -2
- package/dist/upgrade/productV1Reset.js +515 -0
- package/dist/upgrade/productV1ResetAuthority.js +139 -0
- package/dist/upgrade/projectIntegration.js +126 -134
- package/dist/upgrade/projectIntegrationDecision.js +21 -13
- package/dist/upgrade/retiredResourceDiagnostics.js +117 -0
- package/dist/upgrade/runtimeMigration.js +210 -430
- package/dist/upgrade/upgradeCommands.js +14 -1
- package/dist/upgrade/upgradeLock.js +85 -0
- package/dist/upgrade/upgradeOrchestrator.js +253 -48
- package/dist/upgrade/v3CapabilitySurface.js +2 -3
- package/dist/upgrade/versionResolution.js +0 -1
- package/dist/validate/activationArtifactEvidence.js +866 -0
- package/dist/validate/activationArtifactEvidenceTypes.js +12 -0
- package/dist/validate/activationConjunction.js +816 -0
- package/dist/validate/activationEvidenceManifest.js +610 -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/glossaryVariantGuard.js +96 -0
- package/dist/validate/retainedReferenceAuthority.js +879 -0
- package/dist/validate/selfAudit.js +39 -45
- package/dist/validate/vocabularyAuthority.js +8 -8
- package/package.json +39 -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/index.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/plan/instructions.js.map +0 -1
- package/dist/capabilities/profile/instructions.js.map +0 -1
- package/dist/capabilities/research/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/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/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/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/types.js.map +0 -1
- package/dist/cli/commands/prime/v1Migration.js +0 -39
- 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/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/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/types.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/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/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/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/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/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,788 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { personalGlossaryCandidateProjectionContract } from "../registries/glossaryCandidateProjectionContract.js";
|
|
4
|
+
import { validateGlossaryEvidenceCapsule, } from "../registries/glossaryCandidateContracts.js";
|
|
5
|
+
import { canonicalGlossaryJson, compareGlossaryUnicodeStrings, glossaryCanonicalSha256, } from "../registries/glossaryTermIdentity.js";
|
|
6
|
+
import { defaultProfileDir } from "./extractCorpus/core.js";
|
|
7
|
+
import { EXCERPT_OMISSION_REASONS, containsPersonalGlossarySensitiveContent, personalGlossaryCandidateProjectionExcerptExpiry, selectPersonalGlossarySafeExcerpt, validPersonalGlossarySafeExcerpt, } from "./personalGlossaryCandidateProjectionExcerpts.js";
|
|
8
|
+
const PROJECTION_SCHEMA_VERSION = "agentera.personalGlossaryCandidateProjection.v1";
|
|
9
|
+
const PROJECTION_REPORT_SCHEMA_VERSION = "agentera.personalGlossaryCandidateProjectionReport.v1";
|
|
10
|
+
const MINING_SUMMARY_SCHEMA_VERSION = "agentera.personalGlossaryMiningSummary.v1";
|
|
11
|
+
const PROJECT_IDENTITY_SCHEMA_VERSION = "agentera.personalGlossaryProjectionProjectIdentity.v1";
|
|
12
|
+
const PROJECTION_OWNER = "deterministic_discovery_projection";
|
|
13
|
+
const SHA256_RE = /^[a-f0-9]{64}$/u;
|
|
14
|
+
const TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/u;
|
|
15
|
+
function mapping(value) {
|
|
16
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
17
|
+
? value
|
|
18
|
+
: null;
|
|
19
|
+
}
|
|
20
|
+
function compareText(left, right) {
|
|
21
|
+
return compareGlossaryUnicodeStrings(left, right);
|
|
22
|
+
}
|
|
23
|
+
function exactKeys(value, expected) {
|
|
24
|
+
const actual = Object.keys(value).sort(compareText);
|
|
25
|
+
return JSON.stringify(actual) === JSON.stringify([...expected].sort(compareText));
|
|
26
|
+
}
|
|
27
|
+
function validTimestamp(value) {
|
|
28
|
+
return typeof value === "string" && TIMESTAMP_RE.test(value) && !Number.isNaN(Date.parse(value));
|
|
29
|
+
}
|
|
30
|
+
function requireBoundedText(value, maximum, label) {
|
|
31
|
+
if (typeof value !== "string" ||
|
|
32
|
+
value.length === 0 ||
|
|
33
|
+
Buffer.byteLength(value, "utf8") > maximum) {
|
|
34
|
+
throw new TypeError(`${label} is outside its bound`);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function projectionContract() {
|
|
39
|
+
const contract = personalGlossaryCandidateProjectionContract();
|
|
40
|
+
const families = contract.sourceFamilies;
|
|
41
|
+
if (contract.schemaVersion !== PROJECTION_SCHEMA_VERSION ||
|
|
42
|
+
contract.owner !== PROJECTION_OWNER ||
|
|
43
|
+
contract.candidatesMax !== 50 ||
|
|
44
|
+
contract.projectIdsMaxPerCandidate !== 100 ||
|
|
45
|
+
contract.sourceExcerptMaxUtf8Bytes !== 4096 ||
|
|
46
|
+
contract.pendingExcerptDays !== 30 ||
|
|
47
|
+
contract.selectionAlgorithm !==
|
|
48
|
+
"least_retained_source_family_then_project_then_canonical_candidate" ||
|
|
49
|
+
contract.tieBreak !== "candidate_id_then_candidate_revision_then_capsule_sha256" ||
|
|
50
|
+
contract.projectIdentitySchemaVersion !== PROJECT_IDENTITY_SCHEMA_VERSION ||
|
|
51
|
+
contract.storageFile !== "candidate-projection.json" ||
|
|
52
|
+
contract.candidateSecretReason !== "secret_content" ||
|
|
53
|
+
contract.excerptSensitiveContentAction !== "omit_complete_excerpt_before_projection" ||
|
|
54
|
+
contract.miningSummarySchemaVersion !== MINING_SUMMARY_SCHEMA_VERSION ||
|
|
55
|
+
contract.explicitAbstentionKeys.length !== 24 ||
|
|
56
|
+
contract.recurringAbstentionKeys.length !== 12 ||
|
|
57
|
+
JSON.stringify(Object.keys(families)) !== JSON.stringify(["explicit", "recurring"]) ||
|
|
58
|
+
JSON.stringify(families.explicit) !== JSON.stringify(["personal_explicit_definition"]) ||
|
|
59
|
+
JSON.stringify(families.recurring) !==
|
|
60
|
+
JSON.stringify(["personal_inferred_usage", "personal_inferred_conversation"])) {
|
|
61
|
+
throw new TypeError("personal glossary candidate projection contract is invalid");
|
|
62
|
+
}
|
|
63
|
+
return contract;
|
|
64
|
+
}
|
|
65
|
+
function zeroReasons(keys) {
|
|
66
|
+
return Object.fromEntries(keys.map((key) => [key, 0]));
|
|
67
|
+
}
|
|
68
|
+
function projectionMiningSummary(input, contract) {
|
|
69
|
+
if (input.mining_summary)
|
|
70
|
+
return input.mining_summary;
|
|
71
|
+
let explicit = 0;
|
|
72
|
+
let recurring = 0;
|
|
73
|
+
for (const candidate of input.candidates) {
|
|
74
|
+
if (candidate.capsule.provenance_kind === "personal_explicit_definition")
|
|
75
|
+
explicit += 1;
|
|
76
|
+
else
|
|
77
|
+
recurring += 1;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
schema_version: MINING_SUMMARY_SCHEMA_VERSION,
|
|
81
|
+
explicit: {
|
|
82
|
+
candidate_count: explicit,
|
|
83
|
+
abstention_count: 0,
|
|
84
|
+
abstentions_by_reason: zeroReasons(contract.explicitAbstentionKeys),
|
|
85
|
+
},
|
|
86
|
+
recurring: {
|
|
87
|
+
candidate_count: recurring,
|
|
88
|
+
abstention_count: 0,
|
|
89
|
+
abstentions_by_reason: zeroReasons(contract.recurringAbstentionKeys),
|
|
90
|
+
},
|
|
91
|
+
total_candidate_count: explicit + recurring,
|
|
92
|
+
total_abstention_count: 0,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function validMiningFamily(value, keys) {
|
|
96
|
+
const family = mapping(value);
|
|
97
|
+
const reasons = mapping(family?.abstentions_by_reason);
|
|
98
|
+
return family !== null && reasons !== null &&
|
|
99
|
+
exactKeys(family, ["candidate_count", "abstention_count", "abstentions_by_reason"]) &&
|
|
100
|
+
nonNegativeInteger(family.candidate_count) && nonNegativeInteger(family.abstention_count) &&
|
|
101
|
+
exactKeys(reasons, keys) && Object.values(reasons).every(nonNegativeInteger) &&
|
|
102
|
+
family.abstention_count === Object.values(reasons).reduce((sum, count) => sum + Number(count), 0);
|
|
103
|
+
}
|
|
104
|
+
function validMiningSummary(value, inputCount, contract) {
|
|
105
|
+
const summary = mapping(value);
|
|
106
|
+
if (summary === null || !exactKeys(summary, [
|
|
107
|
+
"schema_version", "explicit", "recurring", "total_candidate_count", "total_abstention_count",
|
|
108
|
+
]) || summary.schema_version !== MINING_SUMMARY_SCHEMA_VERSION ||
|
|
109
|
+
!validMiningFamily(summary.explicit, contract.explicitAbstentionKeys) ||
|
|
110
|
+
!validMiningFamily(summary.recurring, contract.recurringAbstentionKeys) ||
|
|
111
|
+
!nonNegativeInteger(summary.total_candidate_count) ||
|
|
112
|
+
!nonNegativeInteger(summary.total_abstention_count))
|
|
113
|
+
return false;
|
|
114
|
+
const explicit = summary.explicit;
|
|
115
|
+
const recurring = summary.recurring;
|
|
116
|
+
return summary.total_candidate_count === explicit.candidate_count + recurring.candidate_count &&
|
|
117
|
+
summary.total_candidate_count === inputCount &&
|
|
118
|
+
summary.total_abstention_count === explicit.abstention_count + recurring.abstention_count;
|
|
119
|
+
}
|
|
120
|
+
function sourceFamily(capsule, contract) {
|
|
121
|
+
const matches = Object.entries(contract.sourceFamilies)
|
|
122
|
+
.filter(([, kinds]) => kinds.includes(capsule.provenance_kind))
|
|
123
|
+
.map(([family]) => family);
|
|
124
|
+
if (matches.length !== 1)
|
|
125
|
+
throw new TypeError("candidate provenance has no projection source family");
|
|
126
|
+
return matches[0];
|
|
127
|
+
}
|
|
128
|
+
/** Hash the exact transient diversity label before it enters projection metadata or reports. */
|
|
129
|
+
export function personalGlossaryProjectionProjectIdentity(projectId) {
|
|
130
|
+
if (typeof projectId !== "string" || projectId.length === 0) {
|
|
131
|
+
throw new TypeError("candidate project identity must be non-empty");
|
|
132
|
+
}
|
|
133
|
+
return glossaryCanonicalSha256({
|
|
134
|
+
schema_version: PROJECT_IDENTITY_SCHEMA_VERSION,
|
|
135
|
+
project_id: projectId,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function candidateOrder(left, right) {
|
|
139
|
+
return (compareText(left.capsule.candidate_id, right.capsule.candidate_id) ||
|
|
140
|
+
compareText(left.capsule.candidate_revision, right.capsule.candidate_revision) ||
|
|
141
|
+
compareText(left.capsule.capsule_sha256, right.capsule.capsule_sha256));
|
|
142
|
+
}
|
|
143
|
+
function candidateKey(capsule) {
|
|
144
|
+
return `${capsule.candidate_id}\u0000${capsule.candidate_revision}`;
|
|
145
|
+
}
|
|
146
|
+
function projectCandidate(candidate, input, contract) {
|
|
147
|
+
const errors = validateGlossaryEvidenceCapsule(candidate.capsule);
|
|
148
|
+
if (errors.length > 0)
|
|
149
|
+
throw new TypeError("candidate capsule is invalid");
|
|
150
|
+
if (containsPersonalGlossarySensitiveContent(candidate.capsule.term) ||
|
|
151
|
+
containsPersonalGlossarySensitiveContent(candidate.capsule.meaning)) {
|
|
152
|
+
throw new TypeError(`candidate content is ineligible: ${contract.candidateSecretReason}`);
|
|
153
|
+
}
|
|
154
|
+
if (candidate.capsule.generation !== input.generation ||
|
|
155
|
+
candidate.capsule.policy_version !== input.policy_version) {
|
|
156
|
+
throw new TypeError("candidate capsule bindings do not match projection input");
|
|
157
|
+
}
|
|
158
|
+
if (!Array.isArray(candidate.project_ids) ||
|
|
159
|
+
candidate.project_ids.length === 0 ||
|
|
160
|
+
candidate.project_ids.length > contract.projectIdsMaxPerCandidate) {
|
|
161
|
+
throw new TypeError("candidate project identities are outside their bound");
|
|
162
|
+
}
|
|
163
|
+
const projectKeys = new Set();
|
|
164
|
+
for (const projectId of candidate.project_ids) {
|
|
165
|
+
const bounded = requireBoundedText(projectId, 256, "candidate project identity");
|
|
166
|
+
projectKeys.add(personalGlossaryProjectionProjectIdentity(bounded));
|
|
167
|
+
}
|
|
168
|
+
if (projectKeys.size > contract.projectIdsMaxPerCandidate) {
|
|
169
|
+
throw new TypeError("candidate project identities are outside their bound");
|
|
170
|
+
}
|
|
171
|
+
const excerpts = candidate.excerpts ?? [];
|
|
172
|
+
if (!Array.isArray(excerpts) || excerpts.some((excerpt) => typeof excerpt !== "string")) {
|
|
173
|
+
throw new TypeError("candidate excerpts must be strings");
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
capsule: candidate.capsule,
|
|
177
|
+
sourceFamily: sourceFamily(candidate.capsule, contract),
|
|
178
|
+
projectKeys,
|
|
179
|
+
excerpts: new Set(excerpts),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function mergeCandidates(input, contract) {
|
|
183
|
+
const merged = new Map();
|
|
184
|
+
let duplicates = 0;
|
|
185
|
+
for (const rawCandidate of input.candidates) {
|
|
186
|
+
const candidate = projectCandidate(rawCandidate, input, contract);
|
|
187
|
+
const key = candidateKey(candidate.capsule);
|
|
188
|
+
const existing = merged.get(key);
|
|
189
|
+
if (!existing) {
|
|
190
|
+
merged.set(key, candidate);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (existing.capsule.capsule_sha256 !== candidate.capsule.capsule_sha256 ||
|
|
194
|
+
canonicalGlossaryJson(existing.capsule) !== canonicalGlossaryJson(candidate.capsule)) {
|
|
195
|
+
throw new TypeError("candidate revision collision has non-identical capsule bytes");
|
|
196
|
+
}
|
|
197
|
+
duplicates += 1;
|
|
198
|
+
for (const projectKey of candidate.projectKeys)
|
|
199
|
+
existing.projectKeys.add(projectKey);
|
|
200
|
+
if (existing.projectKeys.size > contract.projectIdsMaxPerCandidate) {
|
|
201
|
+
throw new TypeError("candidate project identities are outside their bound");
|
|
202
|
+
}
|
|
203
|
+
for (const excerpt of candidate.excerpts)
|
|
204
|
+
existing.excerpts.add(excerpt);
|
|
205
|
+
}
|
|
206
|
+
return { candidates: [...merged.values()].sort(candidateOrder), duplicates };
|
|
207
|
+
}
|
|
208
|
+
function countByFamily(candidates) {
|
|
209
|
+
const counts = new Map([
|
|
210
|
+
["explicit", 0],
|
|
211
|
+
["recurring", 0],
|
|
212
|
+
]);
|
|
213
|
+
for (const candidate of candidates) {
|
|
214
|
+
counts.set(candidate.sourceFamily, (counts.get(candidate.sourceFamily) ?? 0) + 1);
|
|
215
|
+
}
|
|
216
|
+
return counts;
|
|
217
|
+
}
|
|
218
|
+
function countByProject(candidates) {
|
|
219
|
+
const counts = new Map();
|
|
220
|
+
for (const candidate of candidates) {
|
|
221
|
+
for (const projectKey of candidate.projectKeys) {
|
|
222
|
+
counts.set(projectKey, (counts.get(projectKey) ?? 0) + 1);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return counts;
|
|
226
|
+
}
|
|
227
|
+
function selectCandidates(candidates, contract) {
|
|
228
|
+
const remaining = [...candidates];
|
|
229
|
+
const familyRetained = new Map([
|
|
230
|
+
["explicit", 0],
|
|
231
|
+
["recurring", 0],
|
|
232
|
+
]);
|
|
233
|
+
const projectRetained = new Map([...countByProject(candidates).keys()].map((projectKey) => [projectKey, 0]));
|
|
234
|
+
const retained = [];
|
|
235
|
+
let ties = 0;
|
|
236
|
+
const rank = (candidate) => [
|
|
237
|
+
familyRetained.get(candidate.sourceFamily) ?? 0,
|
|
238
|
+
Math.min(...[...candidate.projectKeys].map((projectKey) => projectRetained.get(projectKey) ?? 0)),
|
|
239
|
+
];
|
|
240
|
+
while (remaining.length > 0 && retained.length < contract.candidatesMax) {
|
|
241
|
+
remaining.sort((left, right) => {
|
|
242
|
+
const leftRank = rank(left);
|
|
243
|
+
const rightRank = rank(right);
|
|
244
|
+
return (leftRank[0] - rightRank[0] || leftRank[1] - rightRank[1] || candidateOrder(left, right));
|
|
245
|
+
});
|
|
246
|
+
const next = remaining.shift();
|
|
247
|
+
const nextRank = rank(next);
|
|
248
|
+
if (remaining.some((candidate) => {
|
|
249
|
+
const candidateRank = rank(candidate);
|
|
250
|
+
return candidateRank[0] === nextRank[0] && candidateRank[1] === nextRank[1];
|
|
251
|
+
})) {
|
|
252
|
+
ties += 1;
|
|
253
|
+
}
|
|
254
|
+
retained.push(next);
|
|
255
|
+
familyRetained.set(next.sourceFamily, (familyRetained.get(next.sourceFamily) ?? 0) + 1);
|
|
256
|
+
for (const projectKey of next.projectKeys) {
|
|
257
|
+
projectRetained.set(projectKey, (projectRetained.get(projectKey) ?? 0) + 1);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return { retained: retained.sort(candidateOrder), ties };
|
|
261
|
+
}
|
|
262
|
+
function emptyOmissions() {
|
|
263
|
+
return Object.fromEntries(EXCERPT_OMISSION_REASONS.map((reason) => [reason, 0]));
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Build the bounded, user-local candidate projection. This is an internal
|
|
267
|
+
* producer seam only. It deliberately exposes no list, exact-read, review, or
|
|
268
|
+
* publication CLI behavior.
|
|
269
|
+
*/
|
|
270
|
+
export function projectPersonalGlossaryCandidates(input) {
|
|
271
|
+
const contract = projectionContract();
|
|
272
|
+
requireBoundedText(input.generation, 256, "projection generation");
|
|
273
|
+
requireBoundedText(input.policy_version, 256, "projection policy version");
|
|
274
|
+
if (!validTimestamp(input.retained_at)) {
|
|
275
|
+
throw new TypeError("projection retained_at must be an ISO timestamp");
|
|
276
|
+
}
|
|
277
|
+
if (!Array.isArray(input.candidates)) {
|
|
278
|
+
throw new TypeError("projection candidates must be a list");
|
|
279
|
+
}
|
|
280
|
+
const miningSummary = projectionMiningSummary(input, contract);
|
|
281
|
+
if (!validMiningSummary(miningSummary, input.candidates.length, contract)) {
|
|
282
|
+
throw new TypeError("candidate mining summary is invalid");
|
|
283
|
+
}
|
|
284
|
+
const merged = mergeCandidates(input, contract);
|
|
285
|
+
const selected = selectCandidates(merged.candidates, contract);
|
|
286
|
+
const availableByFamily = countByFamily(merged.candidates);
|
|
287
|
+
const availableByProject = countByProject(merged.candidates);
|
|
288
|
+
const retainedByFamily = countByFamily(selected.retained);
|
|
289
|
+
const retainedByProject = countByProject(selected.retained);
|
|
290
|
+
const omissions = emptyOmissions();
|
|
291
|
+
let provided = 0;
|
|
292
|
+
let safeRetained = 0;
|
|
293
|
+
let redacted = 0;
|
|
294
|
+
let truncated = 0;
|
|
295
|
+
const candidates = selected.retained.map((candidate) => {
|
|
296
|
+
const excerpt = selectPersonalGlossarySafeExcerpt(candidate.excerpts, candidate.capsule.term, input.retained_at, contract);
|
|
297
|
+
provided += excerpt.provided;
|
|
298
|
+
if (excerpt.excerpt !== null) {
|
|
299
|
+
safeRetained += 1;
|
|
300
|
+
if (excerpt.excerpt.redacted)
|
|
301
|
+
redacted += 1;
|
|
302
|
+
}
|
|
303
|
+
else if (excerpt.omission !== null) {
|
|
304
|
+
omissions[excerpt.omission] += 1;
|
|
305
|
+
}
|
|
306
|
+
if (excerpt.truncated)
|
|
307
|
+
truncated += 1;
|
|
308
|
+
return {
|
|
309
|
+
capsule: candidate.capsule,
|
|
310
|
+
source_family: candidate.sourceFamily,
|
|
311
|
+
project_keys: [...candidate.projectKeys].sort(compareText),
|
|
312
|
+
safe_excerpt: excerpt.excerpt,
|
|
313
|
+
};
|
|
314
|
+
});
|
|
315
|
+
const capApplied = merged.candidates.length > contract.candidatesMax;
|
|
316
|
+
const uncoveredSourceFamilies = ["explicit", "recurring"].filter((family) => (availableByFamily.get(family) ?? 0) > 0 && (retainedByFamily.get(family) ?? 0) === 0);
|
|
317
|
+
const uncoveredProjects = [...availableByProject.keys()].filter((projectKey) => (retainedByProject.get(projectKey) ?? 0) === 0).length;
|
|
318
|
+
const coverageReasons = [
|
|
319
|
+
...(capApplied ? ["candidate_cap"] : []),
|
|
320
|
+
...(uncoveredSourceFamilies.length > 0 ? ["source_family_uncovered"] : []),
|
|
321
|
+
...(uncoveredProjects > 0 ? ["project_uncovered"] : []),
|
|
322
|
+
];
|
|
323
|
+
const report = {
|
|
324
|
+
schema_version: PROJECTION_REPORT_SCHEMA_VERSION,
|
|
325
|
+
input_count: input.candidates.length,
|
|
326
|
+
duplicate_count: merged.duplicates,
|
|
327
|
+
unique_count: merged.candidates.length,
|
|
328
|
+
retained_count: candidates.length,
|
|
329
|
+
dropped_count: merged.candidates.length - candidates.length,
|
|
330
|
+
cap: { maximum: contract.candidatesMax, applied: capApplied },
|
|
331
|
+
allocation: {
|
|
332
|
+
algorithm: contract.selectionAlgorithm,
|
|
333
|
+
tie_break: contract.tieBreak,
|
|
334
|
+
tie_breaks_resolved: selected.ties,
|
|
335
|
+
},
|
|
336
|
+
source_families: ["explicit", "recurring"].map((family) => ({
|
|
337
|
+
family,
|
|
338
|
+
available: availableByFamily.get(family) ?? 0,
|
|
339
|
+
retained: retainedByFamily.get(family) ?? 0,
|
|
340
|
+
dropped: (availableByFamily.get(family) ?? 0) - (retainedByFamily.get(family) ?? 0),
|
|
341
|
+
})),
|
|
342
|
+
projects: {
|
|
343
|
+
available: availableByProject.size,
|
|
344
|
+
retained: [...retainedByProject.values()].filter((count) => count > 0).length,
|
|
345
|
+
dropped: uncoveredProjects,
|
|
346
|
+
},
|
|
347
|
+
coverage: {
|
|
348
|
+
status: coverageReasons.length === 0 ? "complete" : "degraded",
|
|
349
|
+
reasons: coverageReasons,
|
|
350
|
+
uncovered_source_families: [...uncoveredSourceFamilies],
|
|
351
|
+
uncovered_projects: uncoveredProjects,
|
|
352
|
+
},
|
|
353
|
+
excerpts: {
|
|
354
|
+
provided,
|
|
355
|
+
retained: safeRetained,
|
|
356
|
+
redacted,
|
|
357
|
+
truncated,
|
|
358
|
+
expired: 0,
|
|
359
|
+
omissions,
|
|
360
|
+
},
|
|
361
|
+
mining_summary: miningSummary,
|
|
362
|
+
};
|
|
363
|
+
const projection = {
|
|
364
|
+
schema_version: PROJECTION_SCHEMA_VERSION,
|
|
365
|
+
owner: PROJECTION_OWNER,
|
|
366
|
+
generation: input.generation,
|
|
367
|
+
policy_version: input.policy_version,
|
|
368
|
+
retained_at: input.retained_at,
|
|
369
|
+
candidates,
|
|
370
|
+
report,
|
|
371
|
+
};
|
|
372
|
+
return {
|
|
373
|
+
...projection,
|
|
374
|
+
projection_sha256: glossaryCanonicalSha256(projection),
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
export function personalGlossaryCandidateProjectionPath(options = {}) {
|
|
378
|
+
const contract = projectionContract();
|
|
379
|
+
return path.join(defaultProfileDir(options.env ?? process.env, options.platform ?? process.platform), "intermediate", "personal-glossary", contract.storageFile);
|
|
380
|
+
}
|
|
381
|
+
function privateWrite(pathname, text) {
|
|
382
|
+
const directory = path.dirname(pathname);
|
|
383
|
+
fs.mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
384
|
+
fs.chmodSync(directory, 0o700);
|
|
385
|
+
const temporary = `${pathname}.tmp.${process.pid}.${Date.now()}`;
|
|
386
|
+
let descriptor = null;
|
|
387
|
+
try {
|
|
388
|
+
descriptor = fs.openSync(temporary, "w", 0o600);
|
|
389
|
+
fs.writeFileSync(descriptor, text, "utf8");
|
|
390
|
+
fs.fsyncSync(descriptor);
|
|
391
|
+
fs.closeSync(descriptor);
|
|
392
|
+
descriptor = null;
|
|
393
|
+
fs.renameSync(temporary, pathname);
|
|
394
|
+
fs.chmodSync(pathname, 0o600);
|
|
395
|
+
}
|
|
396
|
+
catch (error) {
|
|
397
|
+
if (descriptor !== null)
|
|
398
|
+
fs.closeSync(descriptor);
|
|
399
|
+
try {
|
|
400
|
+
fs.rmSync(temporary, { force: true });
|
|
401
|
+
}
|
|
402
|
+
catch {
|
|
403
|
+
// The temporary file may not have been created or may already be renamed.
|
|
404
|
+
}
|
|
405
|
+
throw error;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function ensurePrivateProjectionMode(pathname) {
|
|
409
|
+
const metadata = fs.statSync(pathname);
|
|
410
|
+
if (!metadata.isFile()) {
|
|
411
|
+
throw new TypeError("stored candidate projection is not a private file");
|
|
412
|
+
}
|
|
413
|
+
if ((metadata.mode & 0o777) === 0o600)
|
|
414
|
+
return;
|
|
415
|
+
fs.chmodSync(pathname, 0o600);
|
|
416
|
+
if ((fs.statSync(pathname).mode & 0o777) !== 0o600) {
|
|
417
|
+
throw new TypeError("stored candidate projection could not be made private");
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
function nonNegativeInteger(value) {
|
|
421
|
+
return Number.isInteger(value) && Number(value) >= 0;
|
|
422
|
+
}
|
|
423
|
+
function validProjectionReport(value) {
|
|
424
|
+
const report = mapping(value);
|
|
425
|
+
const cap = mapping(report?.cap);
|
|
426
|
+
const allocation = mapping(report?.allocation);
|
|
427
|
+
const projects = mapping(report?.projects);
|
|
428
|
+
const coverage = mapping(report?.coverage);
|
|
429
|
+
const excerpts = mapping(report?.excerpts);
|
|
430
|
+
const omissions = mapping(excerpts?.omissions);
|
|
431
|
+
if (report === null ||
|
|
432
|
+
!exactKeys(report, [
|
|
433
|
+
"schema_version",
|
|
434
|
+
"input_count",
|
|
435
|
+
"duplicate_count",
|
|
436
|
+
"unique_count",
|
|
437
|
+
"retained_count",
|
|
438
|
+
"dropped_count",
|
|
439
|
+
"cap",
|
|
440
|
+
"allocation",
|
|
441
|
+
"source_families",
|
|
442
|
+
"projects",
|
|
443
|
+
"coverage",
|
|
444
|
+
"excerpts",
|
|
445
|
+
"mining_summary",
|
|
446
|
+
]) ||
|
|
447
|
+
report.schema_version !== PROJECTION_REPORT_SCHEMA_VERSION ||
|
|
448
|
+
![
|
|
449
|
+
report.input_count,
|
|
450
|
+
report.duplicate_count,
|
|
451
|
+
report.unique_count,
|
|
452
|
+
report.retained_count,
|
|
453
|
+
report.dropped_count,
|
|
454
|
+
].every(nonNegativeInteger) ||
|
|
455
|
+
cap === null ||
|
|
456
|
+
!exactKeys(cap, ["maximum", "applied"]) ||
|
|
457
|
+
cap.maximum !== projectionContract().candidatesMax ||
|
|
458
|
+
typeof cap.applied !== "boolean" ||
|
|
459
|
+
allocation === null ||
|
|
460
|
+
!exactKeys(allocation, ["algorithm", "tie_break", "tie_breaks_resolved"]) ||
|
|
461
|
+
allocation.algorithm !== projectionContract().selectionAlgorithm ||
|
|
462
|
+
allocation.tie_break !== projectionContract().tieBreak ||
|
|
463
|
+
!nonNegativeInteger(allocation.tie_breaks_resolved) ||
|
|
464
|
+
!Array.isArray(report.source_families) ||
|
|
465
|
+
report.source_families.length !== 2 ||
|
|
466
|
+
projects === null ||
|
|
467
|
+
!exactKeys(projects, ["available", "retained", "dropped"]) ||
|
|
468
|
+
!Object.values(projects).every(nonNegativeInteger) ||
|
|
469
|
+
coverage === null ||
|
|
470
|
+
!exactKeys(coverage, [
|
|
471
|
+
"status",
|
|
472
|
+
"reasons",
|
|
473
|
+
"uncovered_source_families",
|
|
474
|
+
"uncovered_projects",
|
|
475
|
+
]) ||
|
|
476
|
+
!["complete", "degraded"].includes(String(coverage.status)) ||
|
|
477
|
+
!Array.isArray(coverage.reasons) ||
|
|
478
|
+
coverage.reasons.some((reason) => typeof reason !== "string" ||
|
|
479
|
+
!["candidate_cap", "source_family_uncovered", "project_uncovered"].includes(reason)) ||
|
|
480
|
+
!Array.isArray(coverage.uncovered_source_families) ||
|
|
481
|
+
coverage.uncovered_source_families.some((family) => family !== "explicit" && family !== "recurring") ||
|
|
482
|
+
!nonNegativeInteger(coverage.uncovered_projects) ||
|
|
483
|
+
!validMiningSummary(report.mining_summary, Number(report.input_count), projectionContract()) ||
|
|
484
|
+
excerpts === null ||
|
|
485
|
+
!exactKeys(excerpts, [
|
|
486
|
+
"provided",
|
|
487
|
+
"retained",
|
|
488
|
+
"redacted",
|
|
489
|
+
"truncated",
|
|
490
|
+
"expired",
|
|
491
|
+
"omissions",
|
|
492
|
+
]) ||
|
|
493
|
+
![
|
|
494
|
+
excerpts.provided,
|
|
495
|
+
excerpts.retained,
|
|
496
|
+
excerpts.redacted,
|
|
497
|
+
excerpts.truncated,
|
|
498
|
+
excerpts.expired,
|
|
499
|
+
].every(nonNegativeInteger) ||
|
|
500
|
+
omissions === null ||
|
|
501
|
+
!exactKeys(omissions, EXCERPT_OMISSION_REASONS) ||
|
|
502
|
+
!Object.values(omissions).every(nonNegativeInteger)) {
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
|
+
return report.source_families.every((family) => {
|
|
506
|
+
const item = mapping(family);
|
|
507
|
+
return (item !== null &&
|
|
508
|
+
exactKeys(item, ["family", "available", "retained", "dropped"]) &&
|
|
509
|
+
(item.family === "explicit" || item.family === "recurring") &&
|
|
510
|
+
[item.available, item.retained, item.dropped].every(nonNegativeInteger));
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
function projectedCandidateOrder(left, right) {
|
|
514
|
+
return (compareText(left.capsule.candidate_id, right.capsule.candidate_id) ||
|
|
515
|
+
compareText(left.capsule.candidate_revision, right.capsule.candidate_revision) ||
|
|
516
|
+
compareText(left.capsule.capsule_sha256, right.capsule.capsule_sha256));
|
|
517
|
+
}
|
|
518
|
+
function sameTextArray(left, right) {
|
|
519
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
520
|
+
}
|
|
521
|
+
function validProjectedCandidate(value, projection, contract) {
|
|
522
|
+
const item = mapping(value);
|
|
523
|
+
if (item === null ||
|
|
524
|
+
!exactKeys(item, ["capsule", "source_family", "project_keys", "safe_excerpt"]) ||
|
|
525
|
+
!Array.isArray(item.project_keys) ||
|
|
526
|
+
item.project_keys.length === 0 ||
|
|
527
|
+
item.project_keys.length > contract.projectIdsMaxPerCandidate ||
|
|
528
|
+
item.project_keys.some((projectKey) => typeof projectKey !== "string" || !SHA256_RE.test(projectKey)) ||
|
|
529
|
+
new Set(item.project_keys).size !== item.project_keys.length ||
|
|
530
|
+
!sameTextArray(item.project_keys, [...item.project_keys].sort((left, right) => compareText(String(left), String(right)))) ||
|
|
531
|
+
(item.safe_excerpt !== null && !validPersonalGlossarySafeExcerpt(item.safe_excerpt))) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
const capsule = item.capsule;
|
|
535
|
+
if (validateGlossaryEvidenceCapsule(capsule).length > 0)
|
|
536
|
+
return false;
|
|
537
|
+
if (containsPersonalGlossarySensitiveContent(capsule.term) ||
|
|
538
|
+
containsPersonalGlossarySensitiveContent(capsule.meaning)) {
|
|
539
|
+
return false;
|
|
540
|
+
}
|
|
541
|
+
try {
|
|
542
|
+
return ((item.source_family === "explicit" || item.source_family === "recurring") &&
|
|
543
|
+
capsule.generation === projection.generation &&
|
|
544
|
+
capsule.policy_version === projection.policy_version &&
|
|
545
|
+
sourceFamily(capsule, contract) === item.source_family &&
|
|
546
|
+
(item.safe_excerpt === null ||
|
|
547
|
+
item.safe_excerpt.expires_at ===
|
|
548
|
+
personalGlossaryCandidateProjectionExcerptExpiry(projection.retained_at, contract.pendingExcerptDays)));
|
|
549
|
+
}
|
|
550
|
+
catch {
|
|
551
|
+
return false;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
function validProjectionBindings(projection, contract) {
|
|
555
|
+
const { candidates, report } = projection;
|
|
556
|
+
const families = ["explicit", "recurring"];
|
|
557
|
+
if (report.retained_count !== candidates.length ||
|
|
558
|
+
report.unique_count !== report.retained_count + report.dropped_count ||
|
|
559
|
+
report.input_count !== report.unique_count + report.duplicate_count ||
|
|
560
|
+
report.cap.applied !== report.unique_count > contract.candidatesMax ||
|
|
561
|
+
report.dropped_count !== Math.max(0, report.unique_count - contract.candidatesMax) ||
|
|
562
|
+
report.retained_count !== Math.min(report.unique_count, contract.candidatesMax) ||
|
|
563
|
+
report.allocation.tie_breaks_resolved > report.retained_count) {
|
|
564
|
+
return false;
|
|
565
|
+
}
|
|
566
|
+
const candidateKeys = new Set();
|
|
567
|
+
for (let index = 0; index < candidates.length; index += 1) {
|
|
568
|
+
const candidate = candidates[index];
|
|
569
|
+
const key = candidateKey(candidate.capsule);
|
|
570
|
+
if (candidateKeys.has(key))
|
|
571
|
+
return false;
|
|
572
|
+
candidateKeys.add(key);
|
|
573
|
+
if (index > 0 && projectedCandidateOrder(candidates[index - 1], candidate) >= 0)
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
const retainedByFamily = new Map(families.map((family) => [family, 0]));
|
|
577
|
+
const retainedProjectKeys = new Set();
|
|
578
|
+
for (const candidate of candidates) {
|
|
579
|
+
retainedByFamily.set(candidate.source_family, (retainedByFamily.get(candidate.source_family) ?? 0) + 1);
|
|
580
|
+
for (const projectKey of candidate.project_keys)
|
|
581
|
+
retainedProjectKeys.add(projectKey);
|
|
582
|
+
}
|
|
583
|
+
if (!sameTextArray(report.source_families.map((item) => item.family), families))
|
|
584
|
+
return false;
|
|
585
|
+
let availableCandidates = 0;
|
|
586
|
+
let droppedCandidates = 0;
|
|
587
|
+
for (const family of families) {
|
|
588
|
+
const item = report.source_families.find((entry) => entry.family === family);
|
|
589
|
+
const retained = retainedByFamily.get(family) ?? 0;
|
|
590
|
+
if (item.retained !== retained ||
|
|
591
|
+
item.available < item.retained ||
|
|
592
|
+
item.dropped !== item.available - item.retained) {
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
availableCandidates += item.available;
|
|
596
|
+
droppedCandidates += item.dropped;
|
|
597
|
+
}
|
|
598
|
+
if (availableCandidates !== report.unique_count || droppedCandidates !== report.dropped_count) {
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
if (report.projects.retained !== retainedProjectKeys.size ||
|
|
602
|
+
report.projects.available < report.projects.retained ||
|
|
603
|
+
report.projects.dropped !== report.projects.available - report.projects.retained) {
|
|
604
|
+
return false;
|
|
605
|
+
}
|
|
606
|
+
const uncoveredSourceFamilies = families.filter((family) => {
|
|
607
|
+
const item = report.source_families.find((entry) => entry.family === family);
|
|
608
|
+
return item.available > 0 && item.retained === 0;
|
|
609
|
+
});
|
|
610
|
+
const coverageReasons = [
|
|
611
|
+
...(report.cap.applied ? ["candidate_cap"] : []),
|
|
612
|
+
...(uncoveredSourceFamilies.length > 0 ? ["source_family_uncovered"] : []),
|
|
613
|
+
...(report.projects.dropped > 0 ? ["project_uncovered"] : []),
|
|
614
|
+
];
|
|
615
|
+
if (report.coverage.uncovered_projects !== report.projects.dropped ||
|
|
616
|
+
!sameTextArray(report.coverage.uncovered_source_families, uncoveredSourceFamilies) ||
|
|
617
|
+
!sameTextArray(report.coverage.reasons, coverageReasons) ||
|
|
618
|
+
report.coverage.status !== (coverageReasons.length === 0 ? "complete" : "degraded")) {
|
|
619
|
+
return false;
|
|
620
|
+
}
|
|
621
|
+
const activeExcerpts = candidates.flatMap((candidate) => candidate.safe_excerpt === null ? [] : [candidate.safe_excerpt]);
|
|
622
|
+
const omissionCount = Object.values(report.excerpts.omissions).reduce((total, count) => total + count, 0);
|
|
623
|
+
if (report.excerpts.retained !== activeExcerpts.length ||
|
|
624
|
+
report.excerpts.provided !== candidates.length - report.excerpts.omissions.no_excerpt ||
|
|
625
|
+
report.excerpts.retained + report.excerpts.expired + omissionCount !== candidates.length ||
|
|
626
|
+
report.excerpts.redacted < activeExcerpts.filter((excerpt) => excerpt.redacted).length ||
|
|
627
|
+
report.excerpts.redacted > report.excerpts.retained + report.excerpts.expired ||
|
|
628
|
+
report.excerpts.truncated > report.excerpts.provided ||
|
|
629
|
+
report.excerpts.expired > report.excerpts.provided) {
|
|
630
|
+
return false;
|
|
631
|
+
}
|
|
632
|
+
return true;
|
|
633
|
+
}
|
|
634
|
+
function validProjection(value) {
|
|
635
|
+
const projection = mapping(value);
|
|
636
|
+
const contract = projectionContract();
|
|
637
|
+
if (projection === null ||
|
|
638
|
+
!exactKeys(projection, [
|
|
639
|
+
"schema_version",
|
|
640
|
+
"owner",
|
|
641
|
+
"generation",
|
|
642
|
+
"policy_version",
|
|
643
|
+
"retained_at",
|
|
644
|
+
"candidates",
|
|
645
|
+
"report",
|
|
646
|
+
"projection_sha256",
|
|
647
|
+
]) ||
|
|
648
|
+
projection.schema_version !== PROJECTION_SCHEMA_VERSION ||
|
|
649
|
+
projection.owner !== PROJECTION_OWNER ||
|
|
650
|
+
typeof projection.generation !== "string" ||
|
|
651
|
+
projection.generation.length === 0 ||
|
|
652
|
+
Buffer.byteLength(projection.generation, "utf8") > 256 ||
|
|
653
|
+
typeof projection.policy_version !== "string" ||
|
|
654
|
+
projection.policy_version.length === 0 ||
|
|
655
|
+
Buffer.byteLength(projection.policy_version, "utf8") > 256 ||
|
|
656
|
+
!validTimestamp(projection.retained_at) ||
|
|
657
|
+
!Array.isArray(projection.candidates) ||
|
|
658
|
+
projection.candidates.length > contract.candidatesMax ||
|
|
659
|
+
!validProjectionReport(projection.report) ||
|
|
660
|
+
typeof projection.projection_sha256 !== "string" ||
|
|
661
|
+
!SHA256_RE.test(projection.projection_sha256)) {
|
|
662
|
+
return false;
|
|
663
|
+
}
|
|
664
|
+
const body = { ...projection };
|
|
665
|
+
delete body.projection_sha256;
|
|
666
|
+
if (projection.projection_sha256 !== glossaryCanonicalSha256(body))
|
|
667
|
+
return false;
|
|
668
|
+
const typed = projection;
|
|
669
|
+
return (typed.candidates.every((candidate) => validProjectedCandidate(candidate, typed, contract)) &&
|
|
670
|
+
validProjectionBindings(typed, contract));
|
|
671
|
+
}
|
|
672
|
+
export function readPersonalGlossaryCandidateProjection(options = {}) {
|
|
673
|
+
const pathname = personalGlossaryCandidateProjectionPath(options);
|
|
674
|
+
let text;
|
|
675
|
+
try {
|
|
676
|
+
text = fs.readFileSync(pathname, "utf8");
|
|
677
|
+
}
|
|
678
|
+
catch (error) {
|
|
679
|
+
return error.code === "ENOENT"
|
|
680
|
+
? { status: "missing", projection: null }
|
|
681
|
+
: { status: "corrupt", projection: null };
|
|
682
|
+
}
|
|
683
|
+
try {
|
|
684
|
+
const parsed = JSON.parse(text);
|
|
685
|
+
if (!validProjection(parsed) || text !== `${canonicalGlossaryJson(parsed)}\n`) {
|
|
686
|
+
return { status: "corrupt", projection: null };
|
|
687
|
+
}
|
|
688
|
+
return { status: "current", projection: parsed };
|
|
689
|
+
}
|
|
690
|
+
catch {
|
|
691
|
+
return { status: "corrupt", projection: null };
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
export function persistPersonalGlossaryCandidateProjection(projection, options = {}) {
|
|
695
|
+
if (!validProjection(projection))
|
|
696
|
+
throw new TypeError("candidate projection is invalid");
|
|
697
|
+
const pathname = personalGlossaryCandidateProjectionPath(options);
|
|
698
|
+
const text = `${canonicalGlossaryJson(projection)}\n`;
|
|
699
|
+
if (fs.existsSync(pathname)) {
|
|
700
|
+
const current = readPersonalGlossaryCandidateProjection(options);
|
|
701
|
+
if (current.status === "corrupt")
|
|
702
|
+
throw new TypeError("stored candidate projection is corrupt");
|
|
703
|
+
if (current.status === "current") {
|
|
704
|
+
const existing = fs.readFileSync(pathname, "utf8");
|
|
705
|
+
if (existing === text) {
|
|
706
|
+
ensurePrivateProjectionMode(pathname);
|
|
707
|
+
return { status: "unchanged_replay", path: pathname };
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
privateWrite(pathname, text);
|
|
712
|
+
return { status: "changed", path: pathname };
|
|
713
|
+
}
|
|
714
|
+
/** Persist after explicit refresh consent, replacing only a malformed owned regular file. */
|
|
715
|
+
export function persistPersonalGlossaryCandidateProjectionAfterRefresh(projection, options = {}) {
|
|
716
|
+
if (!validProjection(projection))
|
|
717
|
+
throw new TypeError("candidate projection is invalid");
|
|
718
|
+
const pathname = personalGlossaryCandidateProjectionPath(options);
|
|
719
|
+
const root = path.resolve(defaultProfileDir(options.env ?? process.env, options.platform ?? process.platform), "intermediate", "personal-glossary");
|
|
720
|
+
if (path.resolve(pathname) !== path.join(root, projectionContract().storageFile)) {
|
|
721
|
+
throw new TypeError("candidate projection path escapes its configured storage root");
|
|
722
|
+
}
|
|
723
|
+
try {
|
|
724
|
+
const metadata = fs.lstatSync(pathname);
|
|
725
|
+
if (metadata.isSymbolicLink() || !metadata.isFile()) {
|
|
726
|
+
throw new TypeError("candidate projection replacement requires the exact regular file");
|
|
727
|
+
}
|
|
728
|
+
const text = `${canonicalGlossaryJson(projection)}\n`;
|
|
729
|
+
const current = readPersonalGlossaryCandidateProjection(options);
|
|
730
|
+
if (current.status === "current" && fs.readFileSync(pathname, "utf8") === text) {
|
|
731
|
+
ensurePrivateProjectionMode(pathname);
|
|
732
|
+
return { status: "unchanged_replay", path: pathname };
|
|
733
|
+
}
|
|
734
|
+
privateWrite(pathname, text);
|
|
735
|
+
return { status: "changed", path: pathname };
|
|
736
|
+
}
|
|
737
|
+
catch (error) {
|
|
738
|
+
if (error.code !== "ENOENT")
|
|
739
|
+
throw error;
|
|
740
|
+
}
|
|
741
|
+
privateWrite(pathname, `${canonicalGlossaryJson(projection)}\n`);
|
|
742
|
+
return { status: "changed", path: pathname };
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Apply only expiry or a local-host-authorized purge to the private projection.
|
|
746
|
+
* No CLI command exposes this primitive. The later review lifecycle owns the
|
|
747
|
+
* authentication ceremony and any review-disposition storage.
|
|
748
|
+
*/
|
|
749
|
+
export function maintainPersonalGlossaryCandidateProjection(input) {
|
|
750
|
+
if (!validTimestamp(input.now))
|
|
751
|
+
throw new TypeError("maintenance now must be an ISO timestamp");
|
|
752
|
+
const options = { env: input.env, platform: input.platform };
|
|
753
|
+
const current = readPersonalGlossaryCandidateProjection(options);
|
|
754
|
+
if (current.status === "missing" || current.status === "corrupt") {
|
|
755
|
+
return { status: current.status, expired_excerpts: 0 };
|
|
756
|
+
}
|
|
757
|
+
const pathname = personalGlossaryCandidateProjectionPath(options);
|
|
758
|
+
if (input.current_user_purge_authorized === true) {
|
|
759
|
+
fs.rmSync(pathname, { force: true });
|
|
760
|
+
return { status: "purged", expired_excerpts: 0 };
|
|
761
|
+
}
|
|
762
|
+
let expired = 0;
|
|
763
|
+
const candidates = current.projection.candidates.map((candidate) => {
|
|
764
|
+
if (candidate.safe_excerpt !== null &&
|
|
765
|
+
Date.parse(candidate.safe_excerpt.expires_at) <= Date.parse(input.now)) {
|
|
766
|
+
expired += 1;
|
|
767
|
+
return { ...candidate, safe_excerpt: null };
|
|
768
|
+
}
|
|
769
|
+
return candidate;
|
|
770
|
+
});
|
|
771
|
+
if (expired === 0)
|
|
772
|
+
return { status: "unchanged", expired_excerpts: 0 };
|
|
773
|
+
const report = structuredClone(current.projection.report);
|
|
774
|
+
report.excerpts.retained -= expired;
|
|
775
|
+
report.excerpts.expired += expired;
|
|
776
|
+
const { projection_sha256: _previousDigest, ...previous } = current.projection;
|
|
777
|
+
const body = {
|
|
778
|
+
...previous,
|
|
779
|
+
candidates,
|
|
780
|
+
report,
|
|
781
|
+
};
|
|
782
|
+
const next = {
|
|
783
|
+
...body,
|
|
784
|
+
projection_sha256: glossaryCanonicalSha256(body),
|
|
785
|
+
};
|
|
786
|
+
privateWrite(pathname, `${canonicalGlossaryJson(next)}\n`);
|
|
787
|
+
return { status: "changed", expired_excerpts: expired };
|
|
788
|
+
}
|