@tiinex/core 0.1.1
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/NOTICE +31 -0
- package/README.md +45 -0
- package/package.json +176 -0
- package/src/actions/record.actions.js +312 -0
- package/src/adapters/adapter.contracts.js +143 -0
- package/src/adapters/archive/archive.adapter.js +502 -0
- package/src/adapters/archive/archive.portableChangeset.js +141 -0
- package/src/adapters/archive/archive.transport.js +124 -0
- package/src/artifacts/artifact.localDraft.js +27 -0
- package/src/artifacts/artifact.normalize.js +28 -0
- package/src/artifacts/artifact.parse.js +207 -0
- package/src/artifacts/artifact.record.js +83 -0
- package/src/audit/audit.run.js +103 -0
- package/src/audit/audit.summary.js +7 -0
- package/src/diagnostics/sourceBoundary.report.js +112 -0
- package/src/export/package.apply.js +349 -0
- package/src/export/package.builder.js +366 -0
- package/src/export/package.bytes.js +164 -0
- package/src/export/package.controlIntegrity.js +42 -0
- package/src/export/package.controlTopology.js +97 -0
- package/src/export/package.fileMap.js +174 -0
- package/src/export/package.manifest.js +401 -0
- package/src/export/package.preflight.js +204 -0
- package/src/export/package.sourceReference.js +81 -0
- package/src/export/package.workspaceContext.js +144 -0
- package/src/export/package.zip.js +128 -0
- package/src/export/tree.bundle.js +278 -0
- package/src/governance/governance.boundary.js +196 -0
- package/src/integrity/integrity.c14nV2.js +190 -0
- package/src/integrity/integrity.methodReference.js +73 -0
- package/src/integrity/integrity.validate.js +56 -0
- package/src/lineage/lineage.candidateResolution.js +46 -0
- package/src/lineage/lineage.githubIssueComment.js +106 -0
- package/src/lineage/lineage.githubIssueLocal.js +196 -0
- package/src/lineage/lineage.githubIssueTarget.js +89 -0
- package/src/lineage/lineage.integrity.js +133 -0
- package/src/lineage/lineage.materialPreference.js +26 -0
- package/src/lineage/lineage.model.js +63 -0
- package/src/lineage/lineage.parentAuthority.js +5 -0
- package/src/lineage/lineage.parentBinding.js +104 -0
- package/src/lineage/lineage.pathBasis.js +47 -0
- package/src/lineage/lineage.resolve.js +388 -0
- package/src/lineage/lineage.sourceScope.js +74 -0
- package/src/lineage/lineage.targetKeys.js +80 -0
- package/src/lineage/lineage.traverse.js +132 -0
- package/src/public/applicationProjection.js +236 -0
- package/src/public/companionResources.js +246 -0
- package/src/public/index.js +16 -0
- package/src/public/node.js +2 -0
- package/src/public/schemaAncestry.js +26 -0
- package/src/publication/publication.contract.js +196 -0
- package/src/publication/publication.preflight.js +159 -0
- package/src/publication/publication.targetContract.js +241 -0
- package/src/reingest/reingest.plan.js +162 -0
- package/src/release/plan.mjs +28 -0
- package/src/release/policy.mjs +100 -0
- package/src/release/run.mjs +74 -0
- package/src/schemas/capability.registry.js +226 -0
- package/src/schemas/companion.js +245 -0
- package/src/schemas/contracts.js +6 -0
- package/src/schemas/coordination/handoff/tiinex.handoff.v1.schema.js +14 -0
- package/src/schemas/coordination/handoff/tiinex.handoff.v1.schema.json +23 -0
- package/src/schemas/coordination/handoff/tiinex.handoff.v1.schema.runtime.json +4283 -0
- package/src/schemas/coordination/handoff/tiinex.handoff.v1.schema.source.js +9 -0
- package/src/schemas/coordination/project/tiinex.project.v1.schema.js +26 -0
- package/src/schemas/coordination/project/tiinex.project.v1.schema.json +23 -0
- package/src/schemas/coordination/project/tiinex.project.v1.schema.runtime.json +1985 -0
- package/src/schemas/coordination/project/tiinex.project.v1.schema.source.js +9 -0
- package/src/schemas/core/decision/tiinex.decision.v1.schema.js +14 -0
- package/src/schemas/core/decision/tiinex.decision.v1.schema.json +24 -0
- package/src/schemas/core/decision/tiinex.decision.v1.schema.runtime.json +1700 -0
- package/src/schemas/core/decision/tiinex.decision.v1.schema.source.js +9 -0
- package/src/schemas/core/evidence/tiinex.evidence.v1.capabilities.js +14 -0
- package/src/schemas/core/evidence/tiinex.evidence.v1.en.i18n.json +6 -0
- package/src/schemas/core/evidence/tiinex.evidence.v1.findings.js +9 -0
- package/src/schemas/core/evidence/tiinex.evidence.v1.presenter.js +1 -0
- package/src/schemas/core/evidence/tiinex.evidence.v1.schema.js +32 -0
- package/src/schemas/core/evidence/tiinex.evidence.v1.schema.json +24 -0
- package/src/schemas/core/evidence/tiinex.evidence.v1.schema.runtime.json +2184 -0
- package/src/schemas/core/evidence/tiinex.evidence.v1.schema.source.js +9 -0
- package/src/schemas/core/evidence/tiinex.evidence.v1.sv.i18n.json +6 -0
- package/src/schemas/core/evidence/tiinex.evidence.v1.transitions.js +1 -0
- package/src/schemas/core/evidence/tiinex.evidence.v1.validate.js +10 -0
- package/src/schemas/core/feedback/tiinex.feedback.v1.schema.js +14 -0
- package/src/schemas/core/feedback/tiinex.feedback.v1.schema.json +23 -0
- package/src/schemas/core/feedback/tiinex.feedback.v1.schema.runtime.json +1773 -0
- package/src/schemas/core/feedback/tiinex.feedback.v1.schema.source.js +9 -0
- package/src/schemas/core/interpretation/tiinex.interpretation.v1.capabilities.js +11 -0
- package/src/schemas/core/interpretation/tiinex.interpretation.v1.contract.js +40 -0
- package/src/schemas/core/interpretation/tiinex.interpretation.v1.en.i18n.json +9 -0
- package/src/schemas/core/interpretation/tiinex.interpretation.v1.findings.js +12 -0
- package/src/schemas/core/interpretation/tiinex.interpretation.v1.localMaterialization.js +89 -0
- package/src/schemas/core/interpretation/tiinex.interpretation.v1.presenter.js +8 -0
- package/src/schemas/core/interpretation/tiinex.interpretation.v1.schema.js +34 -0
- package/src/schemas/core/interpretation/tiinex.interpretation.v1.schema.json +23 -0
- package/src/schemas/core/interpretation/tiinex.interpretation.v1.schema.runtime.json +2029 -0
- package/src/schemas/core/interpretation/tiinex.interpretation.v1.schema.source.js +9 -0
- package/src/schemas/core/interpretation/tiinex.interpretation.v1.sv.i18n.json +9 -0
- package/src/schemas/core/interpretation/tiinex.interpretation.v1.transitions.js +1 -0
- package/src/schemas/core/interpretation/tiinex.interpretation.v1.validate.js +25 -0
- package/src/schemas/core/preservation/tiinex.preservation.v1.capabilities.js +14 -0
- package/src/schemas/core/preservation/tiinex.preservation.v1.en.i18n.json +6 -0
- package/src/schemas/core/preservation/tiinex.preservation.v1.findings.js +9 -0
- package/src/schemas/core/preservation/tiinex.preservation.v1.presenter.js +1 -0
- package/src/schemas/core/preservation/tiinex.preservation.v1.schema.js +31 -0
- package/src/schemas/core/preservation/tiinex.preservation.v1.schema.json +23 -0
- package/src/schemas/core/preservation/tiinex.preservation.v1.schema.runtime.json +2033 -0
- package/src/schemas/core/preservation/tiinex.preservation.v1.schema.source.js +9 -0
- package/src/schemas/core/preservation/tiinex.preservation.v1.sv.i18n.json +6 -0
- package/src/schemas/core/preservation/tiinex.preservation.v1.transitions.js +1 -0
- package/src/schemas/core/preservation/tiinex.preservation.v1.validate.js +10 -0
- package/src/schemas/core/relation/tiinex.relation.v1.capabilities.js +7 -0
- package/src/schemas/core/relation/tiinex.relation.v1.contract.js +3 -0
- package/src/schemas/core/relation/tiinex.relation.v1.en.i18n.json +4 -0
- package/src/schemas/core/relation/tiinex.relation.v1.findings.js +9 -0
- package/src/schemas/core/relation/tiinex.relation.v1.localMaterialization.js +153 -0
- package/src/schemas/core/relation/tiinex.relation.v1.presenter.js +3 -0
- package/src/schemas/core/relation/tiinex.relation.v1.schema.js +20 -0
- package/src/schemas/core/relation/tiinex.relation.v1.schema.json +23 -0
- package/src/schemas/core/relation/tiinex.relation.v1.schema.runtime.json +1668 -0
- package/src/schemas/core/relation/tiinex.relation.v1.schema.source.js +9 -0
- package/src/schemas/core/relation/tiinex.relation.v1.sv.i18n.json +4 -0
- package/src/schemas/core/relation/tiinex.relation.v1.transitions.js +1 -0
- package/src/schemas/core/relation/tiinex.relation.v1.validate.js +36 -0
- package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.capabilities.js +14 -0
- package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.contract.js +57 -0
- package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.en.i18n.json +4 -0
- package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.findings.js +13 -0
- package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.presenter.js +3 -0
- package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.schema.js +20 -0
- package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.schema.json +24 -0
- package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.schema.runtime.json +3315 -0
- package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.schema.source.js +9 -0
- package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.sv.i18n.json +4 -0
- package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.transitions.js +1 -0
- package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.validate.js +78 -0
- package/src/schemas/core/signal/tiinex.signal.v1.schema.js +14 -0
- package/src/schemas/core/signal/tiinex.signal.v1.schema.json +23 -0
- package/src/schemas/core/signal/tiinex.signal.v1.schema.runtime.json +1733 -0
- package/src/schemas/core/signal/tiinex.signal.v1.schema.source.js +9 -0
- package/src/schemas/core/task/tiinex.task.v1.capabilities.js +11 -0
- package/src/schemas/core/task/tiinex.task.v1.contract.js +3 -0
- package/src/schemas/core/task/tiinex.task.v1.en.i18n.json +15 -0
- package/src/schemas/core/task/tiinex.task.v1.findings.js +18 -0
- package/src/schemas/core/task/tiinex.task.v1.localMaterialization.js +148 -0
- package/src/schemas/core/task/tiinex.task.v1.presenter.js +8 -0
- package/src/schemas/core/task/tiinex.task.v1.schema.js +35 -0
- package/src/schemas/core/task/tiinex.task.v1.schema.json +23 -0
- package/src/schemas/core/task/tiinex.task.v1.schema.runtime.json +1708 -0
- package/src/schemas/core/task/tiinex.task.v1.schema.source.js +9 -0
- package/src/schemas/core/task/tiinex.task.v1.sv.i18n.json +15 -0
- package/src/schemas/core/task/tiinex.task.v1.transitions.js +3 -0
- package/src/schemas/core/task/tiinex.task.v1.validate.js +41 -0
- package/src/schemas/core/topic/tiinex.topic.v1.capabilities.js +14 -0
- package/src/schemas/core/topic/tiinex.topic.v1.creation.js +46 -0
- package/src/schemas/core/topic/tiinex.topic.v1.en.i18n.json +8 -0
- package/src/schemas/core/topic/tiinex.topic.v1.findings.js +11 -0
- package/src/schemas/core/topic/tiinex.topic.v1.localMaterialization.js +135 -0
- package/src/schemas/core/topic/tiinex.topic.v1.presenter.js +1 -0
- package/src/schemas/core/topic/tiinex.topic.v1.schema.js +34 -0
- package/src/schemas/core/topic/tiinex.topic.v1.schema.json +23 -0
- package/src/schemas/core/topic/tiinex.topic.v1.schema.runtime.json +1699 -0
- package/src/schemas/core/topic/tiinex.topic.v1.schema.source.js +9 -0
- package/src/schemas/core/topic/tiinex.topic.v1.sv.i18n.json +8 -0
- package/src/schemas/core/topic/tiinex.topic.v1.transitions.js +31 -0
- package/src/schemas/core/topic/tiinex.topic.v1.validate.js +11 -0
- package/src/schemas/creation.capability.js +289 -0
- package/src/schemas/creation.contracts.js +334 -0
- package/src/schemas/creation.executionSnapshot.js +79 -0
- package/src/schemas/creation.factoryQualification.js +73 -0
- package/src/schemas/creation.renderer.js +244 -0
- package/src/schemas/creation.representation.js +279 -0
- package/src/schemas/creation.rootMetadata.js +6 -0
- package/src/schemas/creation.schemaReferences.js +65 -0
- package/src/schemas/discovery/finding/tiinex.discovery.finding.v1.schema.js +14 -0
- package/src/schemas/discovery/finding/tiinex.discovery.finding.v1.schema.json +23 -0
- package/src/schemas/discovery/finding/tiinex.discovery.finding.v1.schema.runtime.json +1873 -0
- package/src/schemas/discovery/finding/tiinex.discovery.finding.v1.schema.source.js +9 -0
- package/src/schemas/discovery/tiinex.discovery.v1.schema.js +14 -0
- package/src/schemas/discovery/tiinex.discovery.v1.schema.json +23 -0
- package/src/schemas/discovery/tiinex.discovery.v1.schema.runtime.json +1839 -0
- package/src/schemas/discovery/tiinex.discovery.v1.schema.source.js +9 -0
- package/src/schemas/generic.artifact.module.js +25 -0
- package/src/schemas/party/organization/tiinex.party.organization.v1.schema.js +26 -0
- package/src/schemas/party/organization/tiinex.party.organization.v1.schema.json +23 -0
- package/src/schemas/party/organization/tiinex.party.organization.v1.schema.runtime.json +2249 -0
- package/src/schemas/party/organization/tiinex.party.organization.v1.schema.source.js +9 -0
- package/src/schemas/party/role/tiinex.party.role.v1.schema.js +26 -0
- package/src/schemas/party/role/tiinex.party.role.v1.schema.json +24 -0
- package/src/schemas/party/role/tiinex.party.role.v1.schema.runtime.json +2091 -0
- package/src/schemas/party/role/tiinex.party.role.v1.schema.source.js +9 -0
- package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.capabilities.js +14 -0
- package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.en.i18n.json +4 -0
- package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.findings.js +1 -0
- package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.presenter.js +1 -0
- package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.schema.js +29 -0
- package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.schema.json +21 -0
- package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.schema.runtime.json +2180 -0
- package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.schema.source.js +9 -0
- package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.sv.i18n.json +4 -0
- package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.transitions.js +1 -0
- package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.validate.js +1 -0
- package/src/schemas/reduction/tiinex.reduction.v1.schema.js +26 -0
- package/src/schemas/reduction/tiinex.reduction.v1.schema.json +23 -0
- package/src/schemas/reduction/tiinex.reduction.v1.schema.runtime.json +1733 -0
- package/src/schemas/reduction/tiinex.reduction.v1.schema.source.js +9 -0
- package/src/schemas/reference.shapes.js +33 -0
- package/src/schemas/registry.js +36 -0
- package/src/schemas/resolver.js +13 -0
- package/src/schemas/schema/module/tiinex.schema.module.v1.capabilities.js +14 -0
- package/src/schemas/schema/module/tiinex.schema.module.v1.en.i18n.json +4 -0
- package/src/schemas/schema/module/tiinex.schema.module.v1.findings.js +1 -0
- package/src/schemas/schema/module/tiinex.schema.module.v1.presenter.js +1 -0
- package/src/schemas/schema/module/tiinex.schema.module.v1.schema.js +29 -0
- package/src/schemas/schema/module/tiinex.schema.module.v1.schema.json +21 -0
- package/src/schemas/schema/module/tiinex.schema.module.v1.schema.runtime.json +2093 -0
- package/src/schemas/schema/module/tiinex.schema.module.v1.schema.source.js +9 -0
- package/src/schemas/schema/module/tiinex.schema.module.v1.sv.i18n.json +4 -0
- package/src/schemas/schema/module/tiinex.schema.module.v1.transitions.js +1 -0
- package/src/schemas/schema/module/tiinex.schema.module.v1.validate.js +1 -0
- package/src/schemas/schema.factory.descriptor.js +104 -0
- package/src/schemas/schema.githubSourceTarget.js +131 -0
- package/src/schemas/schema.identity.js +10 -0
- package/src/schemas/schema.reference.js +133 -0
- package/src/schemas/schema.source.js +239 -0
- package/src/schemas/tiinex.root.v1.capabilities.js +14 -0
- package/src/schemas/tiinex.root.v1.classify.js +55 -0
- package/src/schemas/tiinex.root.v1.en.i18n.json +24 -0
- package/src/schemas/tiinex.root.v1.fallback.js +84 -0
- package/src/schemas/tiinex.root.v1.findings.js +19 -0
- package/src/schemas/tiinex.root.v1.presenter.js +5 -0
- package/src/schemas/tiinex.root.v1.schema.js +29 -0
- package/src/schemas/tiinex.root.v1.schema.json +24 -0
- package/src/schemas/tiinex.root.v1.schema.runtime.json +1574 -0
- package/src/schemas/tiinex.root.v1.schema.source.js +9 -0
- package/src/schemas/tiinex.root.v1.sv.i18n.json +24 -0
- package/src/schemas/tiinex.root.v1.transitions.js +1 -0
- package/src/schemas/tiinex.root.v1.validate.js +36 -0
- package/src/schemas/validation/finding/tiinex.validation.finding.v1.schema.js +14 -0
- package/src/schemas/validation/finding/tiinex.validation.finding.v1.schema.json +23 -0
- package/src/schemas/validation/finding/tiinex.validation.finding.v1.schema.runtime.json +2027 -0
- package/src/schemas/validation/finding/tiinex.validation.finding.v1.schema.source.js +9 -0
- package/src/schemas/validation/method/tiinex.validation.method.v1.schema.js +14 -0
- package/src/schemas/validation/method/tiinex.validation.method.v1.schema.json +23 -0
- package/src/schemas/validation/method/tiinex.validation.method.v1.schema.runtime.json +1848 -0
- package/src/schemas/validation/method/tiinex.validation.method.v1.schema.source.js +9 -0
- package/src/schemas/validation/report/tiinex.validation.report.v1.schema.js +14 -0
- package/src/schemas/validation/report/tiinex.validation.report.v1.schema.json +23 -0
- package/src/schemas/validation/report/tiinex.validation.report.v1.schema.runtime.json +2015 -0
- package/src/schemas/validation/report/tiinex.validation.report.v1.schema.source.js +9 -0
- package/src/schemas/workspace/tiinex.workspace.v1.capabilities.js +12 -0
- package/src/schemas/workspace/tiinex.workspace.v1.en.i18n.json +7 -0
- package/src/schemas/workspace/tiinex.workspace.v1.findings.js +5 -0
- package/src/schemas/workspace/tiinex.workspace.v1.presenter.js +27 -0
- package/src/schemas/workspace/tiinex.workspace.v1.schema.js +30 -0
- package/src/schemas/workspace/tiinex.workspace.v1.schema.json +23 -0
- package/src/schemas/workspace/tiinex.workspace.v1.schema.runtime.json +1596 -0
- package/src/schemas/workspace/tiinex.workspace.v1.schema.source.js +9 -0
- package/src/schemas/workspace/tiinex.workspace.v1.sv.i18n.json +7 -0
- package/src/schemas/workspace/tiinex.workspace.v1.transitions.js +10 -0
- package/src/schemas/workspace/tiinex.workspace.v1.validate.js +10 -0
- package/src/sources/github/github.issueTarget.js +127 -0
- package/src/sources/origin.references.js +249 -0
- package/src/sources/source.explicitTargets.js +49 -0
- package/src/sources/transport.levels.js +107 -0
- package/src/tooling/portable/adapters/cli/cli.cold-start-input.js +34 -0
- package/src/tooling/portable/adapters/cli/cli.command-input.js +455 -0
- package/src/tooling/portable/adapters/cli/cli.common-author.js +249 -0
- package/src/tooling/portable/adapters/cli/cli.common-output.js +330 -0
- package/src/tooling/portable/adapters/cli/cli.editor-assistance.js +13 -0
- package/src/tooling/portable/adapters/cli/cli.ground-materialize.js +96 -0
- package/src/tooling/portable/adapters/cli/cli.ground-recovery.js +99 -0
- package/src/tooling/portable/adapters/cli/cli.handoff-manufacture.js +345 -0
- package/src/tooling/portable/adapters/cli/cli.handoff-sibling-allocation.js +31 -0
- package/src/tooling/portable/adapters/cli/cli.help.js +80 -0
- package/src/tooling/portable/adapters/cli/cli.land.js +13 -0
- package/src/tooling/portable/adapters/cli/cli.local-output.js +72 -0
- package/src/tooling/portable/adapters/cli/cli.material-policy.js +6 -0
- package/src/tooling/portable/adapters/cli/cli.operator-bridge.js +18 -0
- package/src/tooling/portable/adapters/cli/cli.reduction-input.js +14 -0
- package/src/tooling/portable/adapters/cli/cli.run.js +434 -0
- package/src/tooling/portable/adapters/llm/llm.entrypoint.js +34 -0
- package/src/tooling/portable/adapters/node/checkpoint.verify.js +267 -0
- package/src/tooling/portable/adapters/node/handoff.manufacture.bootstrap.js +109 -0
- package/src/tooling/portable/adapters/node/handoff.manufacture.enumeration.js +94 -0
- package/src/tooling/portable/adapters/node/handoff.manufacture.js +193 -0
- package/src/tooling/portable/adapters/node/handoff.manufacture.multiRoot.js +49 -0
- package/src/tooling/portable/adapters/node/handoff.manufacture.packageParent.js +130 -0
- package/src/tooling/portable/adapters/node/handoff.manufacture.requirements.js +353 -0
- package/src/tooling/portable/adapters/node/handoff.manufacture.scope.js +147 -0
- package/src/tooling/portable/adapters/node/workspaceCarrier.manufacture.js +62 -0
- package/src/tooling/portable/assets/asset.operations.js +170 -0
- package/src/tooling/portable/audit/audit.capability.js +119 -0
- package/src/tooling/portable/bootstrap/artifact.result.selfverify.mjs +109 -0
- package/src/tooling/portable/bootstrap/bootstrap.case.mjs +43 -0
- package/src/tooling/portable/bootstrap/tiinex.llm.bootstrap.md +814 -0
- package/src/tooling/portable/bootstrap/tiinex.llm.bootstrap.pointer.json +25 -0
- package/src/tooling/portable/checkpoint/portable.checkpoint.js +89 -0
- package/src/tooling/portable/conformance/checkpoint.qualification.js +271 -0
- package/src/tooling/portable/draft/draft.create.js +389 -0
- package/src/tooling/portable/draft/draft.crud.js +175 -0
- package/src/tooling/portable/draft/draft.exact.js +173 -0
- package/src/tooling/portable/draft/draft.operations.js +265 -0
- package/src/tooling/portable/draft/draft.qualification.js +45 -0
- package/src/tooling/portable/draft/draft.set.js +193 -0
- package/src/tooling/portable/draft/draft.validation-context.js +7 -0
- package/src/tooling/portable/editor/authoring.parent.js +37 -0
- package/src/tooling/portable/editor/editor.assistance.js +221 -0
- package/src/tooling/portable/editor/staged.validation.js +96 -0
- package/src/tooling/portable/engine.facade.js +468 -0
- package/src/tooling/portable/findings.js +92 -0
- package/src/tooling/portable/grounding/grounding.capsule.js +128 -0
- package/src/tooling/portable/grounding/grounding.continuity.js +283 -0
- package/src/tooling/portable/grounding/grounding.participantAuthority.js +20 -0
- package/src/tooling/portable/grounding/grounding.planningContext.js +34 -0
- package/src/tooling/portable/grounding/grounding.readiness.authority.js +17 -0
- package/src/tooling/portable/grounding/grounding.readiness.js +316 -0
- package/src/tooling/portable/grounding/grounding.readiness.support.js +245 -0
- package/src/tooling/portable/grounding/grounding.sourceEvidence.js +71 -0
- package/src/tooling/portable/grounding/grounding.workContext.js +72 -0
- package/src/tooling/portable/grounding/grounding.workProvenance.js +153 -0
- package/src/tooling/portable/handoff/carrierLineage.js +214 -0
- package/src/tooling/portable/handoff/carrierProfile.js +54 -0
- package/src/tooling/portable/handoff/carrierProjection.js +193 -0
- package/src/tooling/portable/handoff/carrierProjection.routeQualification.js +228 -0
- package/src/tooling/portable/handoff/carrierProjection.shared.js +7 -0
- package/src/tooling/portable/handoff/carrierProjection.workspaces.js +54 -0
- package/src/tooling/portable/handoff/coldConsumerEntrypoint.js +185 -0
- package/src/tooling/portable/handoff/coldStartQualification.contract.js +184 -0
- package/src/tooling/portable/handoff/coldStartQualification.grounding.js +392 -0
- package/src/tooling/portable/handoff/coldStartQualification.js +22 -0
- package/src/tooling/portable/handoff/coldStartQualification.materials.js +364 -0
- package/src/tooling/portable/handoff/coldStartQualification.observation.js +220 -0
- package/src/tooling/portable/handoff/coldStartQualification.run.js +81 -0
- package/src/tooling/portable/handoff/coldStartQualification.shared.js +57 -0
- package/src/tooling/portable/handoff/coldStartRolePointers.js +39 -0
- package/src/tooling/portable/handoff/contextAudit.js +247 -0
- package/src/tooling/portable/handoff/contracts/tiinex.handoff.package.v1.schema.md +409 -0
- package/src/tooling/portable/handoff/handoffAuthoringPlan.js +35 -0
- package/src/tooling/portable/handoff/handoffEndpointProjection.js +61 -0
- package/src/tooling/portable/handoff/handoffLeafProjection.js +91 -0
- package/src/tooling/portable/handoff/humanOutputPresentation.js +21 -0
- package/src/tooling/portable/handoff/manufacture.js +84 -0
- package/src/tooling/portable/handoff/materialClosure.archiveV2.binding.js +72 -0
- package/src/tooling/portable/handoff/materialClosure.archiveV2.direct.js +160 -0
- package/src/tooling/portable/handoff/materialClosure.archiveV2.indexes.js +36 -0
- package/src/tooling/portable/handoff/materialClosure.archiveV2.js +247 -0
- package/src/tooling/portable/handoff/materialClosure.archiveV2.projectionProvider.js +44 -0
- package/src/tooling/portable/handoff/materialClosure.archiveV2.workspace.js +226 -0
- package/src/tooling/portable/handoff/materialClosure.descriptor.js +169 -0
- package/src/tooling/portable/handoff/materialClosure.inputBinding.js +372 -0
- package/src/tooling/portable/handoff/materialClosure.inputBinding.support.js +62 -0
- package/src/tooling/portable/handoff/materialClosure.materialized.js +143 -0
- package/src/tooling/portable/handoff/materialClosure.materials.js +116 -0
- package/src/tooling/portable/handoff/materialClosure.package.js +181 -0
- package/src/tooling/portable/handoff/materialClosure.plan.js +204 -0
- package/src/tooling/portable/handoff/materialClosure.readiness.js +36 -0
- package/src/tooling/portable/handoff/materialClosure.requirements.js +137 -0
- package/src/tooling/portable/handoff/operatorContextProjection.js +105 -0
- package/src/tooling/portable/handoff/pointerEntrypoint.js +138 -0
- package/src/tooling/portable/handoff/qualifiedHandoffFixture.js +34 -0
- package/src/tooling/portable/handoff/recipientV2.artifactFirst.build.js +321 -0
- package/src/tooling/portable/handoff/recipientV2.artifactFirst.closure.js +126 -0
- package/src/tooling/portable/handoff/recipientV2.artifactFirst.inspect.js +194 -0
- package/src/tooling/portable/handoff/recipientV2.artifactFirst.materials.js +207 -0
- package/src/tooling/portable/handoff/recipientV2.artifactFirst.projection.js +69 -0
- package/src/tooling/portable/handoff/recipientV2.artifactFirst.roles.js +166 -0
- package/src/tooling/portable/handoff/recipientV2.artifactFirst.routes.js +113 -0
- package/src/tooling/portable/handoff/recipientV2.artifactFirst.shared.js +87 -0
- package/src/tooling/portable/handoff/recipientV2.artifactFirst.workspaces.js +160 -0
- package/src/tooling/portable/handoff/recipientV2.artifactFirstPhase1.js +44 -0
- package/src/tooling/portable/handoff/recipientV2.artifactInspection.js +55 -0
- package/src/tooling/portable/handoff/recipientV2.artifacts.js +174 -0
- package/src/tooling/portable/handoff/recipientV2.coldProjection.js +24 -0
- package/src/tooling/portable/handoff/recipientV2.delivery.js +48 -0
- package/src/tooling/portable/handoff/recipientV2.endpointRolePointers.js +179 -0
- package/src/tooling/portable/handoff/recipientV2.entryContract.js +28 -0
- package/src/tooling/portable/handoff/recipientV2.humanOutput.js +78 -0
- package/src/tooling/portable/handoff/recipientV2.inspect.helpers.js +218 -0
- package/src/tooling/portable/handoff/recipientV2.inspect.js +194 -0
- package/src/tooling/portable/handoff/recipientV2.inspect.pathToken.js +9 -0
- package/src/tooling/portable/handoff/recipientV2.inspect.projection.js +58 -0
- package/src/tooling/portable/handoff/recipientV2.inspect.workspaces.js +177 -0
- package/src/tooling/portable/handoff/recipientV2.lineage.js +142 -0
- package/src/tooling/portable/handoff/recipientV2.packageV1.build.js +147 -0
- package/src/tooling/portable/handoff/recipientV2.packageV1.constants.js +4 -0
- package/src/tooling/portable/handoff/recipientV2.packageV1.contract.js +101 -0
- package/src/tooling/portable/handoff/recipientV2.packageV1.inspect.helpers.js +126 -0
- package/src/tooling/portable/handoff/recipientV2.packageV1.inspect.js +185 -0
- package/src/tooling/portable/handoff/recipientV2.packageV1.js +12 -0
- package/src/tooling/portable/handoff/recipientV2.packageV1.shared.js +24 -0
- package/src/tooling/portable/handoff/recipientV2.packageV1.workspaceProjection.js +22 -0
- package/src/tooling/portable/handoff/recipientV2.pointer.js +40 -0
- package/src/tooling/portable/handoff/recipientV2.routeSelection.js +16 -0
- package/src/tooling/portable/handoff/recipientV2.topology.helpers.js +20 -0
- package/src/tooling/portable/handoff/recipientV2.topology.js +320 -0
- package/src/tooling/portable/handoff/recipientV2.topology.materials.js +70 -0
- package/src/tooling/portable/handoff/recipientV2.topology.workspaces.js +193 -0
- package/src/tooling/portable/handoff/recipientV2.transportManifest.js +123 -0
- package/src/tooling/portable/handoff/recipientV2.workspaceRepresentation.js +163 -0
- package/src/tooling/portable/handoff/routeArtifactConformance.js +130 -0
- package/src/tooling/portable/handoff/toolingBootstrap.js +67 -0
- package/src/tooling/portable/handoff/transportCompanion.js +175 -0
- package/src/tooling/portable/handoff/workspaceByteProvider.archive.js +95 -0
- package/src/tooling/portable/handoff/workspaceByteProvider.js +271 -0
- package/src/tooling/portable/handoff/workspaceCarrier.manufacture.js +93 -0
- package/src/tooling/portable/handoff/workspaceLandingPlan.js +142 -0
- package/src/tooling/portable/handoff/workspacePackageSources.js +105 -0
- package/src/tooling/portable/handoff/workspaceQualifiedReference.js +10 -0
- package/src/tooling/portable/handoff/workspaceSourceIdentity.js +52 -0
- package/src/tooling/portable/handoff/workspaceTargetConformance.js +134 -0
- package/src/tooling/portable/host/host.capabilities.js +181 -0
- package/src/tooling/portable/host/tool.bindings.js +357 -0
- package/src/tooling/portable/host/tool.receiptNormalization.js +141 -0
- package/src/tooling/portable/index.js +52 -0
- package/src/tooling/portable/input/node.input.js +184 -0
- package/src/tooling/portable/input/portable.input.js +249 -0
- package/src/tooling/portable/lifecycle/lifecycle.action.js +11 -0
- package/src/tooling/portable/lifecycle/lifecycle.material.js +173 -0
- package/src/tooling/portable/lifecycle/lifecycle.operations.js +34 -0
- package/src/tooling/portable/lifecycle/lifecycle.readiness.js +247 -0
- package/src/tooling/portable/lineage/lineage.integrity.apply.audit.js +22 -0
- package/src/tooling/portable/lineage/lineage.integrity.apply.evidence.js +36 -0
- package/src/tooling/portable/lineage/lineage.integrity.apply.js +306 -0
- package/src/tooling/portable/lineage/lineage.integrity.apply.structure.js +178 -0
- package/src/tooling/portable/lineage/lineage.integrity.plan.js +377 -0
- package/src/tooling/portable/lineage/lineage.integrity.projection.human.js +82 -0
- package/src/tooling/portable/lineage/lineage.integrity.projection.js +349 -0
- package/src/tooling/portable/lineage/lineage.operations.js +32 -0
- package/src/tooling/portable/lineage/lineage.print.js +398 -0
- package/src/tooling/portable/lineage/lineage.print.render.js +88 -0
- package/src/tooling/portable/lineage/lineage.print.utils.js +58 -0
- package/src/tooling/portable/lineage/lineage.publicationProviderReceipts.js +141 -0
- package/src/tooling/portable/lineage/lineage.publicationQualification.js +183 -0
- package/src/tooling/portable/lineage/lineage.search.js +301 -0
- package/src/tooling/portable/live/live.artifact.js +192 -0
- package/src/tooling/portable/live/live.export.js +107 -0
- package/src/tooling/portable/live/live.lineage.closure.js +71 -0
- package/src/tooling/portable/live/live.lineage.js +338 -0
- package/src/tooling/portable/live/live.protocol.js +181 -0
- package/src/tooling/portable/materialization/durable.materialize.js +162 -0
- package/src/tooling/portable/materialization/epistemic.plan.js +239 -0
- package/src/tooling/portable/materialization/loaded.parent.js +54 -0
- package/src/tooling/portable/materialization/materialization.facade.js +30 -0
- package/src/tooling/portable/operation.catalog.js +393 -0
- package/src/tooling/portable/operation.catalog.package.js +183 -0
- package/src/tooling/portable/operation.result.js +25 -0
- package/src/tooling/portable/orchestration/task.prepare.js +191 -0
- package/src/tooling/portable/output/artifact.result.package.js +308 -0
- package/src/tooling/portable/output/deterministic.zip.js +88 -0
- package/src/tooling/portable/output/node.artifact-set.js +223 -0
- package/src/tooling/portable/output/node.draft.js +41 -0
- package/src/tooling/portable/output/node.zip.js +39 -0
- package/src/tooling/portable/output/recipientV2.zip.js +59 -0
- package/src/tooling/portable/overview/blockingCue.js +16 -0
- package/src/tooling/portable/overview/operatingOverview.js +413 -0
- package/src/tooling/portable/package/generation.binding.js +314 -0
- package/src/tooling/portable/package/generation.binding.projection.js +128 -0
- package/src/tooling/portable/package/material.graph.js +236 -0
- package/src/tooling/portable/package/runtime.package.js +321 -0
- package/src/tooling/portable/package/schema.transition.companion.js +196 -0
- package/src/tooling/portable/package/semantic.package.graph.js +272 -0
- package/src/tooling/portable/package/semantic.package.js +203 -0
- package/src/tooling/portable/package/semantic.package.schema-resolution.js +158 -0
- package/src/tooling/portable/package/semantic.package.transition-registry.js +189 -0
- package/src/tooling/portable/package/semantic.package.types.js +18 -0
- package/src/tooling/portable/providers/schema.bootstrap.provenance.js +10 -0
- package/src/tooling/portable/providers/schema.provider.qualification.js +52 -0
- package/src/tooling/portable/providers/schema.providers.js +458 -0
- package/src/tooling/portable/publication/runtime.publication.js +53 -0
- package/src/tooling/portable/qualification.js +150 -0
- package/src/tooling/portable/reduction/reduction.composition.js +229 -0
- package/src/tooling/portable/reduction/reduction.eligibility.helpers.js +258 -0
- package/src/tooling/portable/reduction/reduction.eligibility.js +191 -0
- package/src/tooling/portable/reduction/reduction.operations.js +30 -0
- package/src/tooling/portable/reduction/reduction.preflight.js +85 -0
- package/src/tooling/portable/reduction/reduction.shared.js +173 -0
- package/src/tooling/portable/schema/bootstrap/canonical.pack.js +24 -0
- package/src/tooling/portable/schema/bootstrap/docs-3988951208eb9a8926e84ab42625d4b42fa00c2d/party/role/tiinex.party.role.v1.schema.md +289 -0
- package/src/tooling/portable/schema/bootstrap/docs-3988951208eb9a8926e84ab42625d4b42fa00c2d/validation/report/tiinex.validation.report.v1.schema.md +300 -0
- package/src/tooling/portable/schema/bootstrap/qualified-local-root/tiinex.root.v1.runtime-projection.json +48 -0
- package/src/tooling/portable/schema/bootstrap/qualified-local-root/tiinex.root.v1.schema.md +865 -0
- package/src/tooling/portable/schema/contract.compile.js +406 -0
- package/src/tooling/portable/schema/contract.compile.utils.js +9 -0
- package/src/tooling/portable/schema/contract.constraints.js +117 -0
- package/src/tooling/portable/schema/contract.envelope.validate.js +177 -0
- package/src/tooling/portable/schema/contract.field-domain.compile.js +399 -0
- package/src/tooling/portable/schema/contract.field-domain.js +247 -0
- package/src/tooling/portable/schema/contract.field-shape.compile.js +34 -0
- package/src/tooling/portable/schema/contract.inheritance.inline.js +103 -0
- package/src/tooling/portable/schema/contract.inheritance.js +210 -0
- package/src/tooling/portable/schema/contract.inheritance.record.js +76 -0
- package/src/tooling/portable/schema/contract.machine-shape.js +309 -0
- package/src/tooling/portable/schema/contract.project.js +81 -0
- package/src/tooling/portable/schema/contract.semantic-resolution.js +82 -0
- package/src/tooling/portable/schema/contract.validate.js +0 -0
- package/src/tooling/portable/schema/lexical.shape.v1.js +338 -0
- package/src/tooling/portable/schema/llm.companion.js +108 -0
- package/src/tooling/portable/schema/named.declarations.js +162 -0
- package/src/tooling/portable/schema/ordinary.contract.js +193 -0
- package/src/tooling/portable/schema/ordinary.fields.js +205 -0
- package/src/tooling/portable/schema/qualifiedLocalRoot.projection.js +70 -0
- package/src/tooling/portable/schema/qualifiedLocalRoot.runtime.js +170 -0
- package/src/tooling/portable/schema/schema.contract.js +465 -0
- package/src/tooling/portable/schema/schema.guide.js +326 -0
- package/src/tooling/portable/schema/schema.snapshot.js +119 -0
- package/src/tooling/portable/session/portable.session.js +145 -0
- package/src/tooling/portable/transfer/transfer.plan.js +102 -0
- package/src/transitions/record.transitions.js +484 -0
- package/src/transitions/transition.validate.js +129 -0
- package/src/validation/findings.js +76 -0
- package/src/validation/validateArtifact.js +216 -0
- package/src/workspaces/workspace.entrypointCapability.js +44 -0
- package/src/workspaces/workspace.materialRole.js +242 -0
- package/src/workspaces/workspace.recordPaths.js +426 -0
- package/tools/tiinex-portable.mjs +6 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { normalizePortableInput } from '../input/portable.input.js';
|
|
3
|
+
import { portableFinding, summarizePortableFindings } from '../findings.js';
|
|
4
|
+
import { appendLiveOperationReceipt, emptyLiveProtocol, normalizeLiveProtocol, verifyLiveOperationReceipts } from './live.protocol.js';
|
|
5
|
+
import { materializeLiveArtifact } from './live.artifact.js';
|
|
6
|
+
|
|
7
|
+
export const PORTABLE_LIVE_LINEAGE_SCHEMA_ID = 'tiinex.portable.live-lineage.v1';
|
|
8
|
+
export const PORTABLE_LIVE_LINEAGE_UPDATE_SCHEMA_ID = 'tiinex.portable.live-lineage.update.v1';
|
|
9
|
+
export const PORTABLE_LIVE_LINEAGE_READ_SCHEMA_ID = 'tiinex.portable.live-lineage.read.v1';
|
|
10
|
+
export const PORTABLE_LIVE_RESPONSE_PREPARE_SCHEMA_ID = 'tiinex.portable.live-response.prepare.v1';
|
|
11
|
+
export const PORTABLE_LIVE_TURN_PROCESS_SCHEMA_ID = 'tiinex.portable.live-turn.process.v1';
|
|
12
|
+
|
|
13
|
+
const CHANGE_ACTIONS = new Set(['upsert', 'withdraw']);
|
|
14
|
+
|
|
15
|
+
export function updatePortableLiveLineage(input = {}, options = {}) {
|
|
16
|
+
const findings = [];
|
|
17
|
+
const runtimeObservedAt = runtimeTimestamp(options);
|
|
18
|
+
const state = normalizePortableLiveLineageState(input.state || input.liveLineage || {}, findings, { sessionId: input.sessionId, clock: options.clock });
|
|
19
|
+
const material = normalizePortableInput(input.materials || input);
|
|
20
|
+
const turnInputPresent = Boolean(input.turn && typeof input.turn === 'object' && Object.keys(input.turn).length);
|
|
21
|
+
const turn = normalizeTurn(input.turn, findings, runtimeObservedAt);
|
|
22
|
+
const changes = normalizeChanges(input.changes || input.artifactChanges || input.change || [], findings);
|
|
23
|
+
if (!turn && !turnInputPresent) findings.push(portableFinding('error', 'live-lineage.turn.required', 'A substantive live-lineage transaction requires an explicit dialogue turn.'));
|
|
24
|
+
if (input.sessionId && clean(input.sessionId) !== state.protocol.sessionId) findings.push(portableFinding('error', 'live-lineage.session-id.drift', 'The dialogue session id must remain stable for the live lineage.', { expected: state.protocol.sessionId, actual: clean(input.sessionId) }));
|
|
25
|
+
if (turn && turn.sequence !== state.protocol.latestTurnSequence + 1) findings.push(portableFinding('error', 'live-lineage.turn.sequence-drift', 'Dialogue turn sequence must continue the persisted live session.', { expected: state.protocol.latestTurnSequence + 1, actual: turn.sequence, turnId: turn.id }));
|
|
26
|
+
if (turn && state.evidence.some((entry) => entry.id === turn.id)) findings.push(portableFinding('error', 'live-lineage.turn.duplicate', 'Dialogue turn id already exists in the live session.', { turnId: turn.id }));
|
|
27
|
+
if (changes.length && state.protocol.latestTurnSequence > state.protocol.preparedTurnSequence) {
|
|
28
|
+
findings.push(portableFinding('error', 'live-lineage.response-preflight.pending', 'Run prepare-live-response before another live artifact update.', {
|
|
29
|
+
latestTurnSequence: state.protocol.latestTurnSequence,
|
|
30
|
+
preparedTurnSequence: state.protocol.preparedTurnSequence
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
if (findings.some((finding) => finding.severity === 'error')) return blockedUpdate(state, findings);
|
|
34
|
+
|
|
35
|
+
const artifacts = new Map(state.artifacts.map((entry) => [entry.id, entry]));
|
|
36
|
+
const evidence = new Map(state.evidence.map((entry) => [entry.id, entry]));
|
|
37
|
+
const events = [...state.events];
|
|
38
|
+
if (turn) evidence.set(turn.id, turn);
|
|
39
|
+
|
|
40
|
+
for (const change of changes) {
|
|
41
|
+
if (change.action === 'withdraw') {
|
|
42
|
+
const current = artifacts.get(change.id);
|
|
43
|
+
if (!current) {
|
|
44
|
+
findings.push(portableFinding('error', 'live-lineage.withdraw.missing', 'Cannot withdraw a live artifact that does not exist.', { artifactId: change.id }));
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
artifacts.set(change.id, freezeArtifact({ ...current, status: 'withdrawn', revision: current.revision + 1, updatedAt: runtimeObservedAt, evidenceRefs: mergeStrings(current.evidenceRefs, change.evidenceRefs) }));
|
|
48
|
+
events.push(freezeEvent({ sequence: events.length + 1, kind: 'withdrawn', artifactId: change.id, evidenceRefs: change.evidenceRefs, reason: change.changeReason || 'Explicit live-artifact withdrawal.' }));
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const current = artifacts.get(change.id) || null;
|
|
53
|
+
const next = materializeLiveArtifact({ current, change, material, artifacts, findings, input: { ...input, state, runtimeObservedAt }, options });
|
|
54
|
+
if (!next) continue;
|
|
55
|
+
artifacts.set(change.id, next);
|
|
56
|
+
events.push(freezeEvent({
|
|
57
|
+
sequence: events.length + 1,
|
|
58
|
+
kind: current ? 'updated' : 'created',
|
|
59
|
+
artifactId: change.id,
|
|
60
|
+
revision: next.revision,
|
|
61
|
+
evidenceRefs: next.evidenceRefs,
|
|
62
|
+
changedFields: Object.freeze(changedFields(current, next)),
|
|
63
|
+
reason: change.changeReason || change.rationale || (current ? 'Dialogue changed the artifact.' : 'Dialogue warranted the artifact.')
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (findings.some((finding) => finding.severity === 'error')) return blockedUpdate(state, findings);
|
|
68
|
+
const normalizedArtifacts = [...artifacts.values()].sort((a, b) => a.id.localeCompare(b.id));
|
|
69
|
+
const normalizedEvidence = [...evidence.values()].sort((a, b) => a.id.localeCompare(b.id));
|
|
70
|
+
let protocol = state.protocol;
|
|
71
|
+
let receipts = state.receipts;
|
|
72
|
+
if (turn || events.length > state.events.length) {
|
|
73
|
+
const appended = appendLiveOperationReceipt({
|
|
74
|
+
protocol,
|
|
75
|
+
receipts,
|
|
76
|
+
operation: 'update-live-lineage',
|
|
77
|
+
eventSequence: events.length,
|
|
78
|
+
latestEventSequence: events.length,
|
|
79
|
+
preparedEventSequence: protocol.preparedEventSequence,
|
|
80
|
+
turnSequence: turn?.sequence || protocol.latestTurnSequence,
|
|
81
|
+
latestTurnSequence: turn?.sequence || protocol.latestTurnSequence,
|
|
82
|
+
preparedTurnSequence: protocol.preparedTurnSequence,
|
|
83
|
+
turnId: turn?.id || '',
|
|
84
|
+
turnMessageSha256: turn?.messageSha256 || '',
|
|
85
|
+
decision: events.length > state.events.length ? 'artifact-change' : 'no-artifact-change',
|
|
86
|
+
artifactIds: changes.map((entry) => entry.id),
|
|
87
|
+
evidenceRefs: turn ? [turn.id] : [],
|
|
88
|
+
clock: options.clock,
|
|
89
|
+
sessionId: input.sessionId,
|
|
90
|
+
details: { eventsAdded: events.length - state.events.length, changeCount: changes.length, boundedTurnSummary: turn?.summary || '' }
|
|
91
|
+
});
|
|
92
|
+
protocol = appended.protocol;
|
|
93
|
+
receipts = appended.receipts;
|
|
94
|
+
}
|
|
95
|
+
const nextState = Object.freeze({
|
|
96
|
+
schema: PORTABLE_LIVE_LINEAGE_SCHEMA_ID,
|
|
97
|
+
version: 3,
|
|
98
|
+
focusArtifactId: resolveFocus(input.focusArtifactId, state.focusArtifactId, normalizedArtifacts),
|
|
99
|
+
evidence: Object.freeze(normalizedEvidence),
|
|
100
|
+
artifacts: Object.freeze(normalizedArtifacts),
|
|
101
|
+
events: Object.freeze(events),
|
|
102
|
+
protocol,
|
|
103
|
+
receipts,
|
|
104
|
+
boundary: liveBoundary()
|
|
105
|
+
});
|
|
106
|
+
const read = readPortableLiveLineage({ state: nextState });
|
|
107
|
+
return Object.freeze({
|
|
108
|
+
schema: PORTABLE_LIVE_LINEAGE_UPDATE_SCHEMA_ID,
|
|
109
|
+
status: events.length > state.events.length ? 'updated' : turn ? 'observed-no-change' : 'unchanged',
|
|
110
|
+
state: nextState,
|
|
111
|
+
read,
|
|
112
|
+
operationReceipt: receipts.at(-1) || null,
|
|
113
|
+
findings: Object.freeze(findings),
|
|
114
|
+
findingSummary: summarizePortableFindings(findings)
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function blockedUpdate(state, findings) {
|
|
119
|
+
return Object.freeze({
|
|
120
|
+
schema: PORTABLE_LIVE_LINEAGE_UPDATE_SCHEMA_ID,
|
|
121
|
+
status: 'blocked',
|
|
122
|
+
state,
|
|
123
|
+
read: readPortableLiveLineage({ state }),
|
|
124
|
+
operationReceipt: null,
|
|
125
|
+
findings: Object.freeze(findings),
|
|
126
|
+
findingSummary: summarizePortableFindings(findings)
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function readPortableLiveLineage(input = {}) {
|
|
131
|
+
const findings = [];
|
|
132
|
+
const state = normalizePortableLiveLineageState(input.state || input.liveLineage || input, findings);
|
|
133
|
+
const active = state.artifacts.filter((entry) => entry.status !== 'withdrawn');
|
|
134
|
+
const focus = active.find((entry) => entry.id === state.focusArtifactId) || active.at(-1) || null;
|
|
135
|
+
const artifacts = active.map((entry) => Object.freeze({
|
|
136
|
+
id: entry.id,
|
|
137
|
+
schemaId: entry.schemaId,
|
|
138
|
+
path: entry.path,
|
|
139
|
+
title: entry.title,
|
|
140
|
+
summary: entry.summary,
|
|
141
|
+
parentRef: entry.parentRef,
|
|
142
|
+
revision: entry.revision,
|
|
143
|
+
status: entry.status,
|
|
144
|
+
exportReady: entry.exportReady,
|
|
145
|
+
evidenceRefs: entry.evidenceRefs,
|
|
146
|
+
blockingFindings: entry.validation?.findingSummary?.counts?.error || 0
|
|
147
|
+
}));
|
|
148
|
+
return Object.freeze({
|
|
149
|
+
schema: PORTABLE_LIVE_LINEAGE_READ_SCHEMA_ID,
|
|
150
|
+
status: findings.some((entry) => entry.severity === 'error') ? 'blocked' : 'ready',
|
|
151
|
+
focusArtifactId: focus?.id || '',
|
|
152
|
+
artifacts: Object.freeze(artifacts),
|
|
153
|
+
responseContext: Object.freeze({
|
|
154
|
+
current: focus ? `${focus.title}: ${focus.summary}` : 'No live artifact exists.',
|
|
155
|
+
continuity: focus?.parentRef ? `Continues ${focus.parentRef}.` : focus ? 'Current artifact is a local lineage root.' : 'No continuity edge is declared.',
|
|
156
|
+
openBoundary: focus?.exportReady ? 'Artifact is exportable.' : focus ? 'The live artifact remains incomplete or blocked and must not be exported as clean.' : 'Dialogue may continue without an artifact.',
|
|
157
|
+
instruction: 'Use this bounded state while answering. Do not expose internal state, JSON, Markdown, or operational boilerplate unless the user asks.'
|
|
158
|
+
}),
|
|
159
|
+
findings: Object.freeze(findings),
|
|
160
|
+
findingSummary: summarizePortableFindings(findings)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function preparePortableLiveResponse(input = {}, options = {}) {
|
|
165
|
+
const findings = [];
|
|
166
|
+
const state = normalizePortableLiveLineageState(input.state || input.liveLineage || input, findings);
|
|
167
|
+
const read = readPortableLiveLineage({ state });
|
|
168
|
+
if (findings.some((finding) => finding.severity === 'error')) return Object.freeze({
|
|
169
|
+
schema: PORTABLE_LIVE_RESPONSE_PREPARE_SCHEMA_ID,
|
|
170
|
+
status: 'blocked',
|
|
171
|
+
state,
|
|
172
|
+
read,
|
|
173
|
+
responseContext: read.responseContext,
|
|
174
|
+
responseToken: '',
|
|
175
|
+
findings: Object.freeze(findings),
|
|
176
|
+
findingSummary: summarizePortableFindings(findings)
|
|
177
|
+
});
|
|
178
|
+
const hadPendingUpdate = state.protocol.latestEventSequence > state.protocol.preparedEventSequence;
|
|
179
|
+
const hadPendingTurn = state.protocol.latestTurnSequence > state.protocol.preparedTurnSequence;
|
|
180
|
+
if (!hadPendingTurn) return Object.freeze({
|
|
181
|
+
schema: PORTABLE_LIVE_RESPONSE_PREPARE_SCHEMA_ID,
|
|
182
|
+
status: 'already-prepared',
|
|
183
|
+
state,
|
|
184
|
+
read,
|
|
185
|
+
responseContext: read.responseContext,
|
|
186
|
+
responseToken: state.protocol.receiptChainHead,
|
|
187
|
+
findings: Object.freeze(findings),
|
|
188
|
+
findingSummary: summarizePortableFindings(findings)
|
|
189
|
+
});
|
|
190
|
+
const appended = appendLiveOperationReceipt({
|
|
191
|
+
protocol: state.protocol,
|
|
192
|
+
receipts: state.receipts,
|
|
193
|
+
operation: 'prepare-live-response',
|
|
194
|
+
eventSequence: state.protocol.latestEventSequence,
|
|
195
|
+
coversThroughEventSequence: state.protocol.latestEventSequence,
|
|
196
|
+
latestEventSequence: state.protocol.latestEventSequence,
|
|
197
|
+
preparedEventSequence: state.protocol.latestEventSequence,
|
|
198
|
+
turnSequence: state.protocol.latestTurnSequence,
|
|
199
|
+
coversThroughTurnSequence: state.protocol.latestTurnSequence,
|
|
200
|
+
latestTurnSequence: state.protocol.latestTurnSequence,
|
|
201
|
+
preparedTurnSequence: state.protocol.latestTurnSequence,
|
|
202
|
+
artifactIds: state.artifacts.filter((entry) => entry.status !== 'withdrawn').map((entry) => entry.id),
|
|
203
|
+
clock: options.clock,
|
|
204
|
+
decision: state.artifacts.some((entry) => entry.status !== 'withdrawn') ? 'response-from-artifact-state' : 'response-without-artifact',
|
|
205
|
+
details: { responseContextDigestBasis: 'bounded-live-artifact-read', rawMarkdownExposed: false, hadPendingArtifactUpdate: hadPendingUpdate, hadPendingDialogueTurn: hadPendingTurn }
|
|
206
|
+
});
|
|
207
|
+
const nextState = Object.freeze({ ...state, protocol: appended.protocol, receipts: appended.receipts });
|
|
208
|
+
const nextRead = readPortableLiveLineage({ state: nextState });
|
|
209
|
+
return Object.freeze({
|
|
210
|
+
schema: PORTABLE_LIVE_RESPONSE_PREPARE_SCHEMA_ID,
|
|
211
|
+
status: hadPendingUpdate ? 'prepared-after-change' : 'prepared-no-change',
|
|
212
|
+
state: nextState,
|
|
213
|
+
read: nextRead,
|
|
214
|
+
responseContext: nextRead.responseContext,
|
|
215
|
+
responseToken: appended.receipt.receiptSha256,
|
|
216
|
+
operationReceipt: appended.receipt,
|
|
217
|
+
findings: Object.freeze(findings),
|
|
218
|
+
findingSummary: summarizePortableFindings(findings)
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
export function processPortableLiveTurn(input = {}, options = {}) {
|
|
224
|
+
const updated = updatePortableLiveLineage(input, options);
|
|
225
|
+
if (updated.status === 'blocked') return Object.freeze({
|
|
226
|
+
schema: PORTABLE_LIVE_TURN_PROCESS_SCHEMA_ID,
|
|
227
|
+
status: 'blocked',
|
|
228
|
+
state: updated.state,
|
|
229
|
+
read: updated.read,
|
|
230
|
+
responseContext: updated.read?.responseContext || {},
|
|
231
|
+
operationReceipts: Object.freeze([]),
|
|
232
|
+
findings: updated.findings,
|
|
233
|
+
findingSummary: updated.findingSummary
|
|
234
|
+
});
|
|
235
|
+
const prepared = preparePortableLiveResponse({ state: updated.state }, options);
|
|
236
|
+
const operationReceipts = [updated.operationReceipt, prepared.operationReceipt].filter(Boolean);
|
|
237
|
+
return Object.freeze({
|
|
238
|
+
schema: PORTABLE_LIVE_TURN_PROCESS_SCHEMA_ID,
|
|
239
|
+
status: prepared.status === 'blocked' ? 'blocked' : updated.status === 'updated' ? 'processed-with-artifact-change' : 'processed-without-artifact-change',
|
|
240
|
+
decision: updated.status === 'updated' ? 'artifact-change' : 'no-artifact-change',
|
|
241
|
+
state: prepared.state,
|
|
242
|
+
read: prepared.read,
|
|
243
|
+
responseContext: prepared.responseContext,
|
|
244
|
+
responseToken: prepared.responseToken,
|
|
245
|
+
operationReceipts: Object.freeze(operationReceipts),
|
|
246
|
+
boundary: Object.freeze({ oneCommandPerSubstantiveTurn: true, rawUserMessagePersisted: false, userMessageDigestPersisted: true, artifactChangeOptional: true, responseContextPreparedAtomically: true }),
|
|
247
|
+
findings: prepared.findings,
|
|
248
|
+
findingSummary: prepared.findingSummary
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
export function normalizePortableLiveLineageState(value, findings = [], defaults = {}) {
|
|
254
|
+
if (!value || !Object.keys(value).length) {
|
|
255
|
+
const protocol = emptyLiveProtocol(defaults);
|
|
256
|
+
return Object.freeze({ schema: PORTABLE_LIVE_LINEAGE_SCHEMA_ID, version: 3, focusArtifactId: '', evidence: Object.freeze([]), artifacts: Object.freeze([]), events: Object.freeze([]), protocol, receipts: Object.freeze([]), boundary: liveBoundary() });
|
|
257
|
+
}
|
|
258
|
+
if (value.schema !== PORTABLE_LIVE_LINEAGE_SCHEMA_ID) findings.push(portableFinding('error', 'live-lineage.schema.invalid', 'Live lineage state schema is unsupported.', { actual: value.schema || '' }));
|
|
259
|
+
const evidence = Object.freeze(normalizeArray(value.evidence).map(normalizeExistingEvidence).filter(Boolean));
|
|
260
|
+
const artifacts = Object.freeze(normalizeArray(value.artifacts).map((entry) => freezeArtifact(entry)).filter((entry) => entry.id));
|
|
261
|
+
const events = Object.freeze(normalizeArray(value.events).map(freezeEvent));
|
|
262
|
+
const receipts = verifyLiveOperationReceipts(value.receipts || [], value.protocol || {}, findings);
|
|
263
|
+
const protocol = normalizeLiveProtocol(value.protocol || {}, receipts, findings);
|
|
264
|
+
const latestEventSequence = events.at(-1)?.sequence || 0;
|
|
265
|
+
if (latestEventSequence !== protocol.latestEventSequence) findings.push(portableFinding('error', 'live-protocol.event-sequence.drift', 'Live protocol event sequence does not match the stored artifact events.', { expected: latestEventSequence, actual: protocol.latestEventSequence }));
|
|
266
|
+
const latestTurnSequence = evidence.reduce((max, entry) => Math.max(max, entry.sequence || 0), 0);
|
|
267
|
+
if (latestTurnSequence !== protocol.latestTurnSequence) findings.push(portableFinding('error', 'live-protocol.turn-sequence.state-drift', 'Live protocol turn sequence does not match stored dialogue evidence.', { expected: latestTurnSequence, actual: protocol.latestTurnSequence }));
|
|
268
|
+
if ((artifacts.length || events.length) && !receipts.length) findings.push(portableFinding('error', 'live-protocol.receipts.required', 'Operation receipts are required; legacy unreceipted state is blocked.'));
|
|
269
|
+
return Object.freeze({
|
|
270
|
+
schema: PORTABLE_LIVE_LINEAGE_SCHEMA_ID,
|
|
271
|
+
version: 3,
|
|
272
|
+
focusArtifactId: clean(value.focusArtifactId),
|
|
273
|
+
evidence,
|
|
274
|
+
artifacts,
|
|
275
|
+
events,
|
|
276
|
+
protocol,
|
|
277
|
+
receipts,
|
|
278
|
+
boundary: liveBoundary()
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function normalizeTurn(value, findings, observedAt = '') {
|
|
283
|
+
if (!value || !Object.keys(value).length) return null;
|
|
284
|
+
const id = clean(value.id || value.evidenceRef);
|
|
285
|
+
const summary = clean(value.summary);
|
|
286
|
+
const sequence = Math.max(0, Number(value.sequence || 0));
|
|
287
|
+
const rawMessage = String(value.userMessage ?? value.message ?? '');
|
|
288
|
+
const suppliedMessageSha256 = clean(value.messageSha256);
|
|
289
|
+
const messageSha256 = rawMessage ? createHash('sha256').update(rawMessage).digest('hex') : '';
|
|
290
|
+
if (!id) findings.push(portableFinding('error', 'live-lineage.turn.id-missing', 'Dialogue turn requires an explicit evidence id.'));
|
|
291
|
+
if (!summary) findings.push(portableFinding('error', 'live-lineage.turn.summary-missing', 'Dialogue turn requires a bounded observable summary.', { turnId: id }));
|
|
292
|
+
if (!sequence) findings.push(portableFinding('error', 'live-lineage.turn.sequence-missing', 'Dialogue turn requires a positive contiguous sequence.', { turnId: id }));
|
|
293
|
+
if (!rawMessage) findings.push(portableFinding('error', 'live-lineage.turn.user-message-required', 'Dialogue turn requires the exact current userMessage so the runtime can derive its digest.', { turnId: id }));
|
|
294
|
+
if (suppliedMessageSha256 && suppliedMessageSha256 !== messageSha256) findings.push(portableFinding('error', 'live-lineage.turn.message-digest-mismatch', 'Supplied messageSha256 does not match the exact current userMessage.', { turnId: id, supplied: suppliedMessageSha256, computed: messageSha256 }));
|
|
295
|
+
if (messageSha256 && !/^[a-f0-9]{64}$/.test(messageSha256)) findings.push(portableFinding('error', 'live-lineage.turn.message-digest-invalid', 'Runtime-derived dialogue digest is invalid.', { turnId: id }));
|
|
296
|
+
const blocked = findings.some((finding) => finding.severity === 'error');
|
|
297
|
+
return !blocked && id && summary && sequence && messageSha256
|
|
298
|
+
? Object.freeze({ id, sequence, summary, messageSha256, observedAt: observedAt || runtimeTimestamp() })
|
|
299
|
+
: null;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function normalizeExistingEvidence(value) {
|
|
303
|
+
const id = clean(value?.id);
|
|
304
|
+
const summary = clean(value?.summary);
|
|
305
|
+
const sequence = Math.max(0, Number(value?.sequence || 0));
|
|
306
|
+
const messageSha256 = clean(value?.messageSha256);
|
|
307
|
+
return id && summary && sequence && /^[a-f0-9]{64}$/.test(messageSha256) ? Object.freeze({ id, sequence, summary, messageSha256, observedAt: timestamp(value.observedAt) }) : null;
|
|
308
|
+
}
|
|
309
|
+
function normalizeChanges(value, findings) {
|
|
310
|
+
return Object.freeze(normalizeArray(value).map((entry) => {
|
|
311
|
+
const id = clean(entry?.id);
|
|
312
|
+
const action = clean(entry?.action || 'upsert').toLowerCase();
|
|
313
|
+
if (!id) findings.push(portableFinding('error', 'live-lineage.change.id-missing', 'Live artifact change requires an explicit id.'));
|
|
314
|
+
if (!CHANGE_ACTIONS.has(action)) findings.push(portableFinding('error', 'live-lineage.change.action-invalid', 'Live artifact change action must be upsert or withdraw.', { artifactId: id, action }));
|
|
315
|
+
return Object.freeze({ ...entry, id, action, evidenceRefs: Object.freeze(normalizeStrings(entry?.evidenceRefs)) });
|
|
316
|
+
}).filter((entry) => entry.id && CHANGE_ACTIONS.has(entry.action)));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function freezeArtifact(value = {}) {
|
|
320
|
+
return Object.freeze({
|
|
321
|
+
...value,
|
|
322
|
+
id: clean(value.id), schemaId: clean(value.schemaId), path: normalizeArtifactPath(value.path || ''), parentRef: clean(value.parentRef), title: clean(value.title), summary: clean(value.summary), why: clean(value.why),
|
|
323
|
+
values: Object.freeze(clone(value.values || {})), sections: Object.freeze(clone(value.sections || {})), evidenceRefs: Object.freeze(normalizeStrings(value.evidenceRefs)),
|
|
324
|
+
revision: Math.max(1, Number(value.revision || 1)), status: clean(value.status || 'live-incomplete'), exportReady: value.exportReady === true,
|
|
325
|
+
draft: value.draft ? Object.freeze({ ...value.draft }) : null, validation: value.validation ? Object.freeze({ ...value.validation }) : null, qualification: value.qualification ? Object.freeze({ ...value.qualification }) : null
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
function freezeEvent(value = {}) { return Object.freeze({ ...value, sequence: Math.max(1, Number(value.sequence || 1)), evidenceRefs: Object.freeze(normalizeStrings(value.evidenceRefs)), changedFields: Object.freeze(normalizeStrings(value.changedFields)) }); }
|
|
329
|
+
function liveBoundary() { return Object.freeze({ role: 'tool-owned live local artifact state', artifactStateIsPrimaryWorkingObject: true, dialogueIsInterface: true, turnTransactionRequiredBeforeSubstantiveResponse: true, responsePreflightRequiredBetweenUpdates: true, operationReceiptChainRequired: true, hiddenReasoning: false, sourceMutation: false, remoteWrite: false, genericFileFallback: false, exportRequiresSharedValidation: true }); }
|
|
330
|
+
function resolveFocus(requested, current, artifacts) { const wanted = clean(requested || current); if (artifacts.some((entry) => entry.id === wanted && entry.status !== 'withdrawn')) return wanted; return artifacts.filter((entry) => entry.status !== 'withdrawn').at(-1)?.id || ''; }
|
|
331
|
+
function normalizeArtifactPath(value) { const cleanPath = String(value || '').replace(/\\/g, '/').replace(/^\/+/, '').replace(/\.\.(?:\/|$)/g, '').trim(); if (!cleanPath) return ''; const withSuffix = cleanPath.toLowerCase().endsWith('.trace.md') ? cleanPath : cleanPath.replace(/\.md$/i, '') + '.trace.md'; return withSuffix.startsWith('.bootstrap/') || withSuffix === '.bootstrap' ? '' : withSuffix; }
|
|
332
|
+
function changedFields(before, after) { if (!before) return ['artifact']; const fields = ['title', 'summary', 'why', 'values', 'sections', 'evidenceRefs', 'status']; return fields.filter((field) => JSON.stringify(before[field]) !== JSON.stringify(after[field])); }
|
|
333
|
+
function normalizeStrings(value) { return [...new Set(normalizeArray(value).map(clean).filter(Boolean))].sort(); }
|
|
334
|
+
function normalizeArray(value) { return Array.isArray(value) ? value : value == null ? [] : [value]; }
|
|
335
|
+
function clean(value) { return String(value || '').replace(/\s+/g, ' ').trim(); }
|
|
336
|
+
function timestamp(value) { const text = String(value || '').trim(); if (text) return text; return new Date().toISOString(); }
|
|
337
|
+
function runtimeTimestamp(options = {}) { const value = typeof options.clock === 'function' ? options.clock() : new Date().toISOString(); const date = value instanceof Date ? value : new Date(value); return Number.isNaN(date.getTime()) ? new Date().toISOString() : date.toISOString(); }
|
|
338
|
+
function clone(value) { return value == null ? {} : JSON.parse(JSON.stringify(value)); }
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { portableFinding } from '../findings.js';
|
|
3
|
+
|
|
4
|
+
export const PORTABLE_LIVE_OPERATION_RECEIPT_SCHEMA_ID = 'tiinex.portable.live-operation-receipt.v1';
|
|
5
|
+
export const PORTABLE_LIVE_OPERATION_CHAIN_SCHEMA_ID = 'tiinex.portable.live-operation-chain.v1';
|
|
6
|
+
|
|
7
|
+
export function emptyLiveProtocol(input = {}) {
|
|
8
|
+
return Object.freeze({
|
|
9
|
+
schema: PORTABLE_LIVE_OPERATION_CHAIN_SCHEMA_ID,
|
|
10
|
+
version: 2,
|
|
11
|
+
sessionId: clean(input.sessionId || 'live-session'),
|
|
12
|
+
stateRevision: 0,
|
|
13
|
+
latestEventSequence: 0,
|
|
14
|
+
preparedEventSequence: 0,
|
|
15
|
+
latestTurnSequence: 0,
|
|
16
|
+
preparedTurnSequence: 0,
|
|
17
|
+
exportCount: 0,
|
|
18
|
+
receiptChainHead: '',
|
|
19
|
+
startedAt: runtimeTimestamp(input)
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function normalizeLiveProtocol(value = {}, receipts = [], findings = []) {
|
|
24
|
+
const protocol = Object.freeze({
|
|
25
|
+
schema: PORTABLE_LIVE_OPERATION_CHAIN_SCHEMA_ID,
|
|
26
|
+
version: 2,
|
|
27
|
+
sessionId: clean(value.sessionId || 'live-session'),
|
|
28
|
+
stateRevision: nonNegative(value.stateRevision),
|
|
29
|
+
latestEventSequence: nonNegative(value.latestEventSequence),
|
|
30
|
+
preparedEventSequence: nonNegative(value.preparedEventSequence),
|
|
31
|
+
latestTurnSequence: nonNegative(value.latestTurnSequence),
|
|
32
|
+
preparedTurnSequence: nonNegative(value.preparedTurnSequence),
|
|
33
|
+
exportCount: nonNegative(value.exportCount),
|
|
34
|
+
receiptChainHead: clean(value.receiptChainHead),
|
|
35
|
+
startedAt: timestamp(value.startedAt)
|
|
36
|
+
});
|
|
37
|
+
verifyLiveOperationReceipts(receipts, protocol, findings);
|
|
38
|
+
if (protocol.preparedEventSequence > protocol.latestEventSequence) findings.push(portableFinding('error', 'live-protocol.prepared-ahead', 'Prepared response event sequence cannot exceed the latest artifact event sequence.', { preparedEventSequence: protocol.preparedEventSequence, latestEventSequence: protocol.latestEventSequence }));
|
|
39
|
+
if (protocol.preparedTurnSequence > protocol.latestTurnSequence) findings.push(portableFinding('error', 'live-protocol.turn-prepared-ahead', 'Prepared response turn sequence cannot exceed the latest dialogue turn sequence.', { preparedTurnSequence: protocol.preparedTurnSequence, latestTurnSequence: protocol.latestTurnSequence }));
|
|
40
|
+
return protocol;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function appendLiveOperationReceipt(input = {}) {
|
|
44
|
+
const receipts = normalizeReceipts(input.receipts);
|
|
45
|
+
const protocol = input.protocol || emptyLiveProtocol(input);
|
|
46
|
+
const operation = clean(input.operation);
|
|
47
|
+
if (!operation) throw new Error('live-protocol.operation.required');
|
|
48
|
+
const sequence = receipts.length + 1;
|
|
49
|
+
const stateRevision = nonNegative(input.stateRevision ?? protocol.stateRevision + 1);
|
|
50
|
+
const receiptBase = {
|
|
51
|
+
schema: PORTABLE_LIVE_OPERATION_RECEIPT_SCHEMA_ID,
|
|
52
|
+
version: 2,
|
|
53
|
+
sequence,
|
|
54
|
+
operation,
|
|
55
|
+
sessionId: clean(input.sessionId || protocol.sessionId || 'live-session'),
|
|
56
|
+
stateRevision,
|
|
57
|
+
eventSequence: nonNegative(input.eventSequence ?? protocol.latestEventSequence),
|
|
58
|
+
coversThroughEventSequence: nonNegative(input.coversThroughEventSequence ?? 0),
|
|
59
|
+
turnSequence: nonNegative(input.turnSequence ?? protocol.latestTurnSequence),
|
|
60
|
+
coversThroughTurnSequence: nonNegative(input.coversThroughTurnSequence ?? 0),
|
|
61
|
+
turnId: clean(input.turnId),
|
|
62
|
+
turnMessageSha256: clean(input.turnMessageSha256),
|
|
63
|
+
decision: clean(input.decision),
|
|
64
|
+
artifactIds: Object.freeze(strings(input.artifactIds)),
|
|
65
|
+
evidenceRefs: Object.freeze(strings(input.evidenceRefs)),
|
|
66
|
+
status: clean(input.status || 'completed'),
|
|
67
|
+
previousReceiptSha256: clean(protocol.receiptChainHead),
|
|
68
|
+
observedAt: runtimeTimestamp(input),
|
|
69
|
+
details: Object.freeze(sortObject(input.details || {}))
|
|
70
|
+
};
|
|
71
|
+
const receiptSha256 = digest(receiptBase);
|
|
72
|
+
const receipt = Object.freeze({ ...receiptBase, receiptSha256 });
|
|
73
|
+
const nextProtocol = Object.freeze({
|
|
74
|
+
...protocol,
|
|
75
|
+
version: 2,
|
|
76
|
+
stateRevision,
|
|
77
|
+
latestEventSequence: nonNegative(input.latestEventSequence ?? protocol.latestEventSequence),
|
|
78
|
+
preparedEventSequence: nonNegative(input.preparedEventSequence ?? protocol.preparedEventSequence),
|
|
79
|
+
latestTurnSequence: nonNegative(input.latestTurnSequence ?? protocol.latestTurnSequence),
|
|
80
|
+
preparedTurnSequence: nonNegative(input.preparedTurnSequence ?? protocol.preparedTurnSequence),
|
|
81
|
+
exportCount: nonNegative(input.exportCount ?? protocol.exportCount),
|
|
82
|
+
receiptChainHead: receiptSha256
|
|
83
|
+
});
|
|
84
|
+
return Object.freeze({ receipt, receipts: Object.freeze([...receipts, receipt]), protocol: nextProtocol });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function verifyLiveOperationReceipts(value = [], protocol = {}, findings = []) {
|
|
88
|
+
const receipts = normalizeReceipts(value);
|
|
89
|
+
let previous = '';
|
|
90
|
+
let expectedTurnSequence = 1;
|
|
91
|
+
let latestTurnSequence = 0;
|
|
92
|
+
let preparedTurnSequence = 0;
|
|
93
|
+
for (let index = 0; index < receipts.length; index += 1) {
|
|
94
|
+
const receipt = receipts[index];
|
|
95
|
+
const expectedSequence = index + 1;
|
|
96
|
+
if (receipt.schema !== PORTABLE_LIVE_OPERATION_RECEIPT_SCHEMA_ID) findings.push(portableFinding('error', 'live-protocol.receipt.schema', 'Live operation receipt schema is invalid.', { sequence: receipt.sequence || expectedSequence }));
|
|
97
|
+
if (receipt.sequence !== expectedSequence) findings.push(portableFinding('error', 'live-protocol.receipt.sequence', 'Live operation receipt sequence is not contiguous.', { expected: expectedSequence, actual: receipt.sequence }));
|
|
98
|
+
if (clean(receipt.sessionId) !== clean(protocol.sessionId || receipt.sessionId)) findings.push(portableFinding('error', 'live-protocol.receipt.session-drift', 'Live operation receipt session id differs from the protocol session id.', { sequence: expectedSequence, expected: clean(protocol.sessionId), actual: clean(receipt.sessionId) }));
|
|
99
|
+
if (clean(receipt.previousReceiptSha256) !== previous) findings.push(portableFinding('error', 'live-protocol.receipt.previous-drift', 'Live operation receipt chain does not point to the previous receipt.', { sequence: expectedSequence }));
|
|
100
|
+
const { receiptSha256, ...base } = receipt;
|
|
101
|
+
const actual = digest(base);
|
|
102
|
+
if (receiptSha256 !== actual) findings.push(portableFinding('error', 'live-protocol.receipt.digest', 'Live operation receipt digest is invalid.', { sequence: expectedSequence, expected: receiptSha256, actual }));
|
|
103
|
+
if (receipt.operation === 'update-live-lineage') {
|
|
104
|
+
if (receipt.turnSequence !== expectedTurnSequence) findings.push(portableFinding('error', 'live-protocol.turn-sequence.drift', 'Dialogue turn receipts must be contiguous.', { expected: expectedTurnSequence, actual: receipt.turnSequence }));
|
|
105
|
+
expectedTurnSequence += 1;
|
|
106
|
+
latestTurnSequence = Math.max(latestTurnSequence, receipt.turnSequence);
|
|
107
|
+
if (!receipt.turnId) findings.push(portableFinding('error', 'live-protocol.turn-id.missing', 'Dialogue turn receipt requires a turn id.', { sequence: expectedSequence }));
|
|
108
|
+
if (!/^[a-f0-9]{64}$/.test(receipt.turnMessageSha256)) findings.push(portableFinding('error', 'live-protocol.turn-message-digest.invalid', 'Dialogue turn receipt requires a lowercase SHA-256 message digest.', { sequence: expectedSequence, turnId: receipt.turnId }));
|
|
109
|
+
}
|
|
110
|
+
if (receipt.operation === 'prepare-live-response') preparedTurnSequence = Math.max(preparedTurnSequence, receipt.coversThroughTurnSequence);
|
|
111
|
+
previous = receipt.receiptSha256;
|
|
112
|
+
}
|
|
113
|
+
if (receipts.length && clean(protocol.receiptChainHead) !== previous) findings.push(portableFinding('error', 'live-protocol.chain-head.drift', 'Live operation chain head does not match the final receipt.', { expected: previous, actual: clean(protocol.receiptChainHead) }));
|
|
114
|
+
if (!receipts.length && clean(protocol.receiptChainHead)) findings.push(portableFinding('error', 'live-protocol.chain-head.orphaned', 'Live operation chain head exists without receipts.'));
|
|
115
|
+
if (receipts.length && nonNegative(protocol.latestTurnSequence) !== latestTurnSequence) findings.push(portableFinding('error', 'live-protocol.latest-turn.drift', 'Protocol latest turn sequence does not match update receipts.', { expected: latestTurnSequence, actual: nonNegative(protocol.latestTurnSequence) }));
|
|
116
|
+
if (receipts.length && nonNegative(protocol.preparedTurnSequence) !== preparedTurnSequence) findings.push(portableFinding('error', 'live-protocol.prepared-turn.drift', 'Protocol prepared turn sequence does not match response-preflight receipts.', { expected: preparedTurnSequence, actual: nonNegative(protocol.preparedTurnSequence) }));
|
|
117
|
+
return Object.freeze(receipts);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function summarizeLiveOperationChain(input = {}) {
|
|
121
|
+
const receipts = normalizeReceipts(input.receipts);
|
|
122
|
+
const protocol = input.protocol || emptyLiveProtocol(input);
|
|
123
|
+
const counts = {};
|
|
124
|
+
for (const receipt of receipts) counts[receipt.operation] = (counts[receipt.operation] || 0) + 1;
|
|
125
|
+
return Object.freeze({
|
|
126
|
+
schema: PORTABLE_LIVE_OPERATION_CHAIN_SCHEMA_ID,
|
|
127
|
+
version: 2,
|
|
128
|
+
sessionId: protocol.sessionId,
|
|
129
|
+
stateRevision: protocol.stateRevision,
|
|
130
|
+
latestEventSequence: protocol.latestEventSequence,
|
|
131
|
+
preparedEventSequence: protocol.preparedEventSequence,
|
|
132
|
+
latestTurnSequence: protocol.latestTurnSequence,
|
|
133
|
+
preparedTurnSequence: protocol.preparedTurnSequence,
|
|
134
|
+
exportCount: protocol.exportCount,
|
|
135
|
+
receiptChainHead: protocol.receiptChainHead,
|
|
136
|
+
counts: Object.freeze(sortObject(counts)),
|
|
137
|
+
receipts: Object.freeze(receipts),
|
|
138
|
+
boundary: Object.freeze({ provesPortableOperationsRecorded: true, provesEveryProviderTurnObserved: false, doesNotProveUserVisibleQuality: true, hiddenReasoningIncluded: false })
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function normalizeReceipts(value) {
|
|
143
|
+
return (Array.isArray(value) ? value : []).map((receipt) => Object.freeze({
|
|
144
|
+
...receipt,
|
|
145
|
+
schema: clean(receipt?.schema),
|
|
146
|
+
version: nonNegative(receipt?.version || 1),
|
|
147
|
+
sequence: nonNegative(receipt?.sequence),
|
|
148
|
+
operation: clean(receipt?.operation),
|
|
149
|
+
sessionId: clean(receipt?.sessionId),
|
|
150
|
+
stateRevision: nonNegative(receipt?.stateRevision),
|
|
151
|
+
eventSequence: nonNegative(receipt?.eventSequence),
|
|
152
|
+
coversThroughEventSequence: nonNegative(receipt?.coversThroughEventSequence),
|
|
153
|
+
turnSequence: nonNegative(receipt?.turnSequence),
|
|
154
|
+
coversThroughTurnSequence: nonNegative(receipt?.coversThroughTurnSequence),
|
|
155
|
+
turnId: clean(receipt?.turnId),
|
|
156
|
+
turnMessageSha256: clean(receipt?.turnMessageSha256),
|
|
157
|
+
decision: clean(receipt?.decision),
|
|
158
|
+
artifactIds: Object.freeze(strings(receipt?.artifactIds)),
|
|
159
|
+
evidenceRefs: Object.freeze(strings(receipt?.evidenceRefs)),
|
|
160
|
+
status: clean(receipt?.status),
|
|
161
|
+
previousReceiptSha256: clean(receipt?.previousReceiptSha256),
|
|
162
|
+
observedAt: timestamp(receipt?.observedAt),
|
|
163
|
+
details: Object.freeze(sortObject(receipt?.details || {})),
|
|
164
|
+
receiptSha256: clean(receipt?.receiptSha256)
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function digest(value) { return createHash('sha256').update(stableJson(value)).digest('hex'); }
|
|
169
|
+
function stableJson(value) { return JSON.stringify(sortObject(value)); }
|
|
170
|
+
function sortObject(value) {
|
|
171
|
+
if (Array.isArray(value)) return value.map(sortObject);
|
|
172
|
+
if (!value || typeof value !== 'object') return value;
|
|
173
|
+
const output = {};
|
|
174
|
+
for (const key of Object.keys(value).sort()) output[key] = sortObject(value[key]);
|
|
175
|
+
return output;
|
|
176
|
+
}
|
|
177
|
+
function strings(value) { return [...new Set((Array.isArray(value) ? value : value == null ? [] : [value]).map(clean).filter(Boolean))].sort(); }
|
|
178
|
+
function clean(value) { return String(value || '').replace(/\s+/g, ' ').trim(); }
|
|
179
|
+
function nonNegative(value) { return Math.max(0, Number(value || 0)); }
|
|
180
|
+
function timestamp(value) { return String(value || '').trim() || new Date().toISOString(); }
|
|
181
|
+
function runtimeTimestamp(input = {}) { const value = typeof input.clock === 'function' ? input.clock() : new Date().toISOString(); const date = value instanceof Date ? value : new Date(value); return Number.isNaN(date.getTime()) ? new Date().toISOString() : date.toISOString(); }
|