project-tiny-context-harness 0.8.10 → 0.8.12
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 +21 -21
- package/README.md +490 -472
- package/assets/README.md +762 -749
- package/assets/README.zh-CN.md +446 -431
- package/assets/agents/.gitkeep +1 -1
- package/assets/agents/AGENTS_CORE.md +17 -23
- package/assets/agents/long-task-implementation.toml +15 -0
- package/assets/context_templates/architecture.md +18 -18
- package/assets/context_templates/area.md +30 -30
- package/assets/context_templates/context.toml +24 -24
- package/assets/context_templates/deployment.md +35 -35
- package/assets/context_templates/global.md +56 -56
- package/assets/context_templates/product-surface-contract.md +70 -70
- package/assets/context_templates/screen-contract.md +189 -189
- package/assets/context_templates/verification.md +25 -25
- package/assets/github/.gitkeep +1 -1
- package/assets/github/harness.yml +39 -39
- package/assets/make/.gitkeep +1 -1
- package/assets/make/ty-context.mk +48 -48
- package/assets/skills/context_development_engineer/SKILL.md +64 -185
- package/assets/skills/context_full_project_export/SKILL.md +28 -28
- package/assets/skills/context_harness_upgrade/SKILL.md +60 -60
- package/assets/skills/context_product_plan/SKILL.md +35 -101
- package/assets/skills/context_surface_contract/SKILL.md +194 -191
- package/assets/skills/context_uiux_design/SKILL.md +49 -172
- package/assets/skills/design-resource-authoring/SKILL.md +52 -88
- package/assets/skills/design-resource-authoring/references/downstream-handoff.md +51 -163
- package/assets/skills/design-resource-authoring/references/formal-selected-web-app-handoff.md +96 -0
- package/assets/skills/design-resource-authoring/references/open-design-provider.md +119 -119
- package/assets/skills/design-resource-authoring/references/resource-selection.md +158 -181
- package/assets/skills/design-system-authoring/SKILL.md +57 -57
- package/assets/skills/design-system-authoring/agents/openai.yaml +6 -6
- package/assets/skills/design-system-authoring/references/authority-adoption.md +48 -48
- package/assets/skills/design-system-authoring/references/open-design-design-system-provider.md +110 -110
- package/assets/skills/long-task-workflow/SKILL.md +71 -106
- package/assets/skills/long-task-workflow/agents/openai.yaml +1 -1
- package/assets/skills/long-task-workflow/references/authority-lifecycle.md +71 -69
- package/assets/skills/long-task-workflow/references/contract-authoring.md +98 -94
- package/assets/skills/long-task-workflow/references/evidence-design.md +67 -63
- package/assets/skills/long-task-workflow/references/source-authoring.md +90 -90
- package/assets/tools/validate_context.py +442 -442
- package/dist/commands/design-resource.js +9 -2
- package/dist/commands/enable.js +2 -0
- package/dist/commands/index.js +1 -1
- package/dist/commands/long-task-revision.js +8 -7
- package/dist/commands/sync.js +2 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.js +2 -1
- package/dist/lib/compact-authoring-support.d.ts +22 -0
- package/dist/lib/compact-authoring-support.js +143 -0
- package/dist/lib/compact-shared-structure-authoring.d.ts +5 -0
- package/dist/lib/compact-shared-structure-authoring.js +9 -0
- package/dist/lib/compact-shared-structure-types.d.ts +61 -0
- package/dist/lib/compact-shared-structure-types.js +1 -0
- package/dist/lib/compact-shared-structure-validation.d.ts +2 -0
- package/dist/lib/compact-shared-structure-validation.js +159 -0
- package/dist/lib/compact-shared-structures.d.ts +3 -0
- package/dist/lib/compact-shared-structures.js +204 -0
- package/dist/lib/design-resource-fact-enums.d.ts +4 -0
- package/dist/lib/design-resource-fact-enums.js +12 -0
- package/dist/lib/design-resource-fact-manifest-shape-evidence.js +2 -2
- package/dist/lib/design-resource-fact-manifest-validation.d.ts +2 -1
- package/dist/lib/design-resource-fact-policy.d.ts +2 -2
- package/dist/lib/design-resource-fact-types.d.ts +2 -2
- package/dist/lib/design-resource-handoff-bundle-draft.d.ts +11 -0
- package/dist/lib/design-resource-handoff-bundle-draft.js +40 -0
- package/dist/lib/design-resource-handoff-bundle.js +4 -28
- package/dist/lib/design-resource-handoff-input-types.d.ts +14 -0
- package/dist/lib/design-resource-handoff-input-types.js +1 -0
- package/dist/lib/design-resource-handoff-manifest-projection.d.ts +2 -1
- package/dist/lib/design-resource-handoff-parser.d.ts +2 -2
- package/dist/lib/design-resource-handoff-parser.js +2 -2
- package/dist/lib/design-resource-handoff-shape.d.ts +4 -1
- package/dist/lib/design-resource-handoff-shape.js +10 -0
- package/dist/lib/design-resource-handoff-snapshot.d.ts +1 -1
- package/dist/lib/design-resource-handoff-snapshot.js +4 -0
- package/dist/lib/design-resource-handoff-types.d.ts +0 -10
- package/dist/lib/design-resource-handoff-validation.d.ts +6 -2
- package/dist/lib/design-resource-handoff-validation.js +11 -0
- package/dist/lib/design-resource-handoff-web-dependency-validation.d.ts +4 -2
- package/dist/lib/design-resource-symbolic-applicability-authority.d.ts +7 -0
- package/dist/lib/design-resource-symbolic-applicability-authority.js +19 -0
- package/dist/lib/design-resource-symbolic-applicability-policy.d.ts +12 -0
- package/dist/lib/design-resource-symbolic-applicability-policy.js +79 -0
- package/dist/lib/design-resource-symbolic-applicability-profiles.d.ts +8 -0
- package/dist/lib/design-resource-symbolic-applicability-profiles.js +55 -0
- package/dist/lib/design-resource-symbolic-applicability-shape.d.ts +2 -0
- package/dist/lib/design-resource-symbolic-applicability-shape.js +76 -0
- package/dist/lib/design-resource-symbolic-applicability-validation.d.ts +7 -0
- package/dist/lib/design-resource-symbolic-applicability-validation.js +128 -0
- package/dist/lib/design-resource-symbolic-compilation.d.ts +3 -0
- package/dist/lib/design-resource-symbolic-compilation.js +13 -0
- package/dist/lib/design-resource-symbolic-denotation.d.ts +3 -0
- package/dist/lib/design-resource-symbolic-denotation.js +167 -0
- package/dist/lib/design-resource-symbolic-disposition-validation.d.ts +4 -0
- package/dist/lib/design-resource-symbolic-disposition-validation.js +28 -0
- package/dist/lib/design-resource-symbolic-fact-policy.d.ts +12 -0
- package/dist/lib/design-resource-symbolic-fact-policy.js +12 -0
- package/dist/lib/design-resource-symbolic-fact-shape.d.ts +3 -0
- package/dist/lib/design-resource-symbolic-fact-shape.js +138 -0
- package/dist/lib/design-resource-symbolic-fact-types.d.ts +213 -0
- package/dist/lib/design-resource-symbolic-fact-types.js +1 -0
- package/dist/lib/design-resource-symbolic-fact-validation.d.ts +3 -0
- package/dist/lib/design-resource-symbolic-fact-validation.js +86 -0
- package/dist/lib/design-resource-symbolic-indexes.d.ts +23 -0
- package/dist/lib/design-resource-symbolic-indexes.js +54 -0
- package/dist/lib/design-resource-symbolic-manifest-shape.d.ts +3 -0
- package/dist/lib/design-resource-symbolic-manifest-shape.js +155 -0
- package/dist/lib/design-resource-symbolic-manifest-validation.d.ts +6 -0
- package/dist/lib/design-resource-symbolic-manifest-validation.js +132 -0
- package/dist/lib/design-resource-symbolic-noninterference-artifact.d.ts +33 -0
- package/dist/lib/design-resource-symbolic-noninterference-artifact.js +110 -0
- package/dist/lib/design-resource-symbolic-noninterference-equivalence.d.ts +3 -0
- package/dist/lib/design-resource-symbolic-noninterference-equivalence.js +77 -0
- package/dist/lib/design-resource-symbolic-noninterference-recompute.d.ts +4 -0
- package/dist/lib/design-resource-symbolic-noninterference-recompute.js +146 -0
- package/dist/lib/design-resource-symbolic-noninterference-scope.d.ts +7 -0
- package/dist/lib/design-resource-symbolic-noninterference-scope.js +49 -0
- package/dist/lib/design-resource-symbolic-noninterference-shape.d.ts +2 -0
- package/dist/lib/design-resource-symbolic-noninterference-shape.js +152 -0
- package/dist/lib/design-resource-symbolic-noninterference-types.d.ts +103 -0
- package/dist/lib/design-resource-symbolic-noninterference-types.js +1 -0
- package/dist/lib/design-resource-symbolic-noninterference-validation.d.ts +5 -0
- package/dist/lib/design-resource-symbolic-noninterference-validation.js +62 -0
- package/dist/lib/design-resource-symbolic-oracle-fingerprint.d.ts +1 -0
- package/dist/lib/design-resource-symbolic-oracle-fingerprint.js +47 -0
- package/dist/lib/design-resource-symbolic-predicate-shape.d.ts +6 -0
- package/dist/lib/design-resource-symbolic-predicate-shape.js +123 -0
- package/dist/lib/design-resource-symbolic-production-closure.d.ts +4 -0
- package/dist/lib/design-resource-symbolic-production-closure.js +144 -0
- package/dist/lib/design-resource-symbolic-proof-authority-validation.d.ts +10 -0
- package/dist/lib/design-resource-symbolic-proof-authority-validation.js +68 -0
- package/dist/lib/design-resource-symbolic-proof-validation.d.ts +10 -0
- package/dist/lib/design-resource-symbolic-proof-validation.js +89 -0
- package/dist/lib/design-resource-symbolic-region-validation.d.ts +19 -0
- package/dist/lib/design-resource-symbolic-region-validation.js +146 -0
- package/dist/lib/design-resource-symbolic-resource-validation.d.ts +5 -0
- package/dist/lib/design-resource-symbolic-resource-validation.js +90 -0
- package/dist/lib/design-resource-symbolic-rule-shape.d.ts +27 -0
- package/dist/lib/design-resource-symbolic-rule-shape.js +158 -0
- package/dist/lib/design-resource-symbolic-safety-validation.d.ts +6 -0
- package/dist/lib/design-resource-symbolic-safety-validation.js +29 -0
- package/dist/lib/design-resource-symbolic-source-ir-evaluation.d.ts +19 -0
- package/dist/lib/design-resource-symbolic-source-ir-evaluation.js +74 -0
- package/dist/lib/design-resource-symbolic-source-ir-evidence.d.ts +44 -0
- package/dist/lib/design-resource-symbolic-source-ir-evidence.js +88 -0
- package/dist/lib/design-resource-symbolic-source-ir-oracle.d.ts +13 -0
- package/dist/lib/design-resource-symbolic-source-ir-oracle.js +96 -0
- package/dist/lib/design-resource-symbolic-source-ir-proof.d.ts +14 -0
- package/dist/lib/design-resource-symbolic-source-ir-proof.js +98 -0
- package/dist/lib/design-resource-symbolic-source-ir-shape.d.ts +2 -0
- package/dist/lib/design-resource-symbolic-source-ir-shape.js +38 -0
- package/dist/lib/design-resource-symbolic-source-ir-types.d.ts +17 -0
- package/dist/lib/design-resource-symbolic-source-ir-types.js +2 -0
- package/dist/lib/design-resource-symbolic-static-dependency-validation.d.ts +2 -0
- package/dist/lib/design-resource-symbolic-static-dependency-validation.js +83 -0
- package/dist/lib/design-resource-symbolic-structural-closure-validation.d.ts +6 -0
- package/dist/lib/design-resource-symbolic-structural-closure-validation.js +79 -0
- package/dist/lib/design-resource-symbolic-validation-support.d.ts +29 -0
- package/dist/lib/design-resource-symbolic-validation-support.js +111 -0
- package/dist/lib/design-resource-v1-capacity-header.d.ts +8 -0
- package/dist/lib/design-resource-v1-capacity-header.js +231 -0
- package/dist/lib/design-resource-v1-capacity.d.ts +5 -0
- package/dist/lib/design-resource-v1-capacity.js +45 -0
- package/dist/lib/init.js +1 -0
- package/dist/lib/long-task-activation-validation.js +2 -2
- package/dist/lib/long-task-authority-policy.d.ts +3 -0
- package/dist/lib/long-task-authority-policy.js +3 -0
- package/dist/lib/long-task-codex-agent-profile.d.ts +42 -0
- package/dist/lib/long-task-codex-agent-profile.js +276 -0
- package/dist/lib/long-task-compact-authoring-projections.d.ts +12 -0
- package/dist/lib/long-task-compact-authoring-projections.js +67 -0
- package/dist/lib/long-task-compact-authoring.d.ts +3 -0
- package/dist/lib/long-task-compact-authoring.js +173 -0
- package/dist/lib/long-task-compact-carrier.d.ts +7 -0
- package/dist/lib/long-task-compact-carrier.js +132 -0
- package/dist/lib/long-task-compact-parser.d.ts +14 -0
- package/dist/lib/long-task-compact-parser.js +123 -0
- package/dist/lib/long-task-compact-primitives.d.ts +22 -0
- package/dist/lib/long-task-compact-primitives.js +132 -0
- package/dist/lib/long-task-compact-projections.d.ts +4 -0
- package/dist/lib/long-task-compact-projections.js +153 -0
- package/dist/lib/long-task-compact-structure-targets.d.ts +2 -0
- package/dist/lib/long-task-compact-structure-targets.js +90 -0
- package/dist/lib/long-task-counterfactual-sandbox.d.ts +1 -1
- package/dist/lib/long-task-counterfactual-sandbox.js +7 -5
- package/dist/lib/long-task-delivery-parser.d.ts +1 -0
- package/dist/lib/long-task-delivery-parser.js +38 -6
- package/dist/lib/long-task-design-resource-handoff.d.ts +2 -1
- package/dist/lib/long-task-design-resource-handoff.js +71 -11
- package/dist/lib/long-task-design-resource-method-binding.d.ts +8 -1
- package/dist/lib/long-task-design-resource-method-binding.js +150 -0
- package/dist/lib/long-task-evidence-capability-codec.js +256 -34
- package/dist/lib/long-task-evidence-capability-policy.js +28 -0
- package/dist/lib/long-task-evidence-capability-runtime.js +271 -63
- package/dist/lib/long-task-evidence-capability-types.d.ts +70 -2
- package/dist/lib/long-task-evidence-v2.d.ts +1 -1
- package/dist/lib/long-task-evidence-v2.js +5 -5
- package/dist/lib/long-task-hook-install.d.ts +19 -2
- package/dist/lib/long-task-hook-install.js +288 -91
- package/dist/lib/long-task-playwright-capability-records.d.ts +2 -0
- package/dist/lib/long-task-playwright-capability-records.js +74 -2
- package/dist/lib/long-task-runner-freeze.d.ts +1 -1
- package/dist/lib/long-task-runner-freeze.js +4 -2
- package/dist/lib/long-task-semantic-contract-types.d.ts +1 -1
- package/dist/lib/long-task-semantic-fact-binding-types.d.ts +8 -0
- package/dist/lib/long-task-semantic-fact-closure.js +4 -1
- package/dist/lib/long-task-semantic-fact-contract-closure.d.ts +1 -1
- package/dist/lib/long-task-semantic-fact-contract-closure.js +15 -3
- package/dist/lib/long-task-semantic-fact-contract-facts.d.ts +1 -1
- package/dist/lib/long-task-semantic-fact-contract-facts.js +4 -1
- package/dist/lib/long-task-semantic-fact-contract-proofs.d.ts +1 -1
- package/dist/lib/long-task-semantic-fact-contract-proofs.js +12 -3
- package/dist/lib/long-task-semantic-fact-evidence.d.ts +5 -1
- package/dist/lib/long-task-semantic-fact-evidence.js +47 -4
- package/dist/lib/long-task-semantic-fact-shape.js +17 -6
- package/dist/lib/long-task-shape-primitives.d.ts +1 -1
- package/dist/lib/long-task-shape-primitives.js +1 -0
- package/dist/lib/long-task-source-item-parser.d.ts +2 -2
- package/dist/lib/long-task-source-item-parser.js +20 -11
- package/dist/lib/long-task-ui-design-policy.js +64 -4
- package/dist/lib/long-task-ui-surface-shape.js +195 -0
- package/dist/lib/long-task-ui-surface-types.d.ts +53 -0
- package/dist/lib/long-task-verifier-v2.js +1 -1
- package/dist/lib/long-task-worker-selection.d.ts +2 -0
- package/dist/lib/long-task-worker-selection.js +7 -0
- package/dist/lib/long-task-workspace-scope.js +3 -1
- package/dist/lib/long-task-workspace.js +11 -1
- package/dist/lib/migrations.js +58 -0
- package/dist/lib/profiles.js +0 -1
- package/dist/lib/semantic-fact-compact-authoring.d.ts +2 -0
- package/dist/lib/semantic-fact-compact-authoring.js +160 -0
- package/dist/lib/semantic-fact-compact-capacity.d.ts +9 -0
- package/dist/lib/semantic-fact-compact-capacity.js +40 -0
- package/dist/lib/semantic-fact-compact-carrier.d.ts +16 -0
- package/dist/lib/semantic-fact-compact-carrier.js +146 -0
- package/dist/lib/semantic-fact-compact-parser.d.ts +17 -0
- package/dist/lib/semantic-fact-compact-parser.js +168 -0
- package/dist/lib/semantic-fact-compact-revision.d.ts +11 -0
- package/dist/lib/semantic-fact-compact-revision.js +64 -0
- package/dist/lib/semantic-fact-compact-support.d.ts +23 -0
- package/dist/lib/semantic-fact-compact-support.js +159 -0
- package/dist/lib/semantic-fact-policy-census.d.ts +1 -0
- package/dist/lib/semantic-fact-policy-census.js +43 -0
- package/dist/lib/semantic-fact-proof-shape.d.ts +1 -1
- package/dist/lib/semantic-fact-property-shape.d.ts +1 -1
- package/dist/lib/semantic-fact-source-parser.d.ts +5 -0
- package/dist/lib/semantic-fact-source-parser.js +47 -6
- package/dist/lib/structural-closure-cost.d.ts +79 -0
- package/dist/lib/structural-closure-cost.js +91 -0
- package/dist/lib/symbolic-denotation-dag-builder.d.ts +25 -0
- package/dist/lib/symbolic-denotation-dag-builder.js +176 -0
- package/dist/lib/symbolic-denotation-domain-validation.d.ts +3 -0
- package/dist/lib/symbolic-denotation-domain-validation.js +56 -0
- package/dist/lib/symbolic-denotation-engine.d.ts +32 -0
- package/dist/lib/symbolic-denotation-engine.js +140 -0
- package/dist/lib/symbolic-denotation-public.d.ts +11 -0
- package/dist/lib/symbolic-denotation-public.js +12 -0
- package/dist/lib/symbolic-denotation-runtime.d.ts +20 -0
- package/dist/lib/symbolic-denotation-runtime.js +90 -0
- package/dist/lib/symbolic-denotation-support.d.ts +11 -0
- package/dist/lib/symbolic-denotation-support.js +49 -0
- package/dist/lib/symbolic-denotation-types.d.ts +133 -0
- package/dist/lib/symbolic-denotation-types.js +18 -0
- package/dist/lib/symbolic-denotation-validation.d.ts +6 -0
- package/dist/lib/symbolic-denotation-validation.js +126 -0
- package/dist/lib/sync-engine.d.ts +1 -0
- package/dist/lib/sync-engine.js +4 -1
- package/dist/lib/upgrade.js +1 -0
- package/dist/long-task-hook.js +40 -1
- package/dist/public-types.d.ts +8 -0
- package/dist/public-types.js +1 -0
- package/dist/schemas/design-resource-symbolic-noninterference-artifact-v2.schema.json +289 -0
- package/dist/schemas/design-resource-symbolic-source-ir-v1.schema.json +130 -0
- package/dist/schemas/long-task-delivery-v2/long-task-delivery-v2.schema.json +390 -5
- package/migrations/README.md +15 -15
- package/package.json +2 -2
- package/source-mappings.yaml +28 -25
- package/assets/skills/source-plan-authoring/SKILL.md +0 -14
|
@@ -27,8 +27,15 @@ export async function designResource(args) {
|
|
|
27
27
|
console.log(`Design resource handoff ready: ${result.handoff_path}`);
|
|
28
28
|
console.log(`Scope: ${result.handoff.scope.key}`);
|
|
29
29
|
console.log(`Targets: ${result.handoff.targets.map((item) => item.key).join(", ")}`);
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
if ("metrics" in result) {
|
|
31
|
+
console.log(`Coverage: ${result.manifest.subjects.length} subjects x ${result.manifest.properties.length} atomic properties (${result.rule_projections.length} symbolic Rules)`);
|
|
32
|
+
console.log(`Symbolic: ${result.metrics.semantic_obligations} semantic obligations, ${result.metrics.certificate_obligations} certificates, ${result.metrics.canonical_dag_nodes} DAG nodes, ${result.metrics.canonical_bytes} bytes`);
|
|
33
|
+
console.log(`Acceptance blockers: ${result.manifest.acceptance_blockers.length}`);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
console.log(`Coverage: ${result.counts.subjects} subjects x 8 dimensions (${result.counts.coverage} grouped rows)`);
|
|
37
|
+
console.log(`Acceptance blockers: ${result.counts.acceptance_blockers}`);
|
|
38
|
+
}
|
|
32
39
|
}
|
|
33
40
|
async function bundle(args) {
|
|
34
41
|
const positional = [];
|
package/dist/commands/enable.js
CHANGED
|
@@ -9,6 +9,8 @@ export async function enable(args) {
|
|
|
9
9
|
const sync = await runSync(root);
|
|
10
10
|
console.log(`${result.changed ? "enabled" : "kept enabled"} profile ${profile}`);
|
|
11
11
|
console.log(`sync changed=${sync.changed.length} skipped=${sync.skipped.length} blocked=${sync.blocked.length}`);
|
|
12
|
+
for (const notice of sync.notices ?? [])
|
|
13
|
+
console.log(notice);
|
|
12
14
|
if (sync.blocked.length)
|
|
13
15
|
throw new Error(sync.blocked.join("\n"));
|
|
14
16
|
}
|
package/dist/commands/index.js
CHANGED
|
@@ -39,7 +39,7 @@ export function help() {
|
|
|
39
39
|
console.log(`ty-context commands:
|
|
40
40
|
init [--adopt] [--harness-folder <path>]
|
|
41
41
|
Initialize/adopt a project; without --harness-folder, choose target agent first
|
|
42
|
-
enable long-task Install Long-Task Skill,
|
|
42
|
+
enable long-task Install Long-Task Skill, lifecycle Hooks, templates and optional Codex worker
|
|
43
43
|
disable long-task Remove only package-owned long-task profile assets
|
|
44
44
|
sync Refresh managed assets; does not run migrations
|
|
45
45
|
upgrade [--check] [--json]
|
|
@@ -90,7 +90,7 @@ function printCompileResult(compiled, previous, preserveProgress, revisionPropos
|
|
|
90
90
|
? projectAuthorityRevisionDecision(revisionProposal)
|
|
91
91
|
: null,
|
|
92
92
|
next_action: firstAuthorityLock
|
|
93
|
-
? "End this turn now
|
|
93
|
+
? "End this turn now. Do not implement, edit files, build, or test. After the user handles the model change in the host, wait for [continue]. Harness cannot observe or verify the model change."
|
|
94
94
|
: authorityChanged
|
|
95
95
|
? "Run status or resume, then continue rolling implementation or repair under the adopted Authority Revision."
|
|
96
96
|
: "Continue rolling implementation or repair under the active Authority.",
|
|
@@ -157,18 +157,19 @@ function executionModelCheckpoint(firstAuthorityLock) {
|
|
|
157
157
|
return {
|
|
158
158
|
required: true,
|
|
159
159
|
phase: "post_authority_lock_pre_implementation",
|
|
160
|
-
|
|
160
|
+
action: "change_model_in_host_then_continue",
|
|
161
|
+
resume_token: "continue",
|
|
161
162
|
turn_boundary: "end_current_turn",
|
|
162
|
-
|
|
163
|
+
blocked_until_resume: [
|
|
163
164
|
"product_implementation",
|
|
164
165
|
"file_edits",
|
|
165
166
|
"build",
|
|
166
167
|
"test_execution",
|
|
167
168
|
],
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
generic_continue_satisfies:
|
|
171
|
-
message: "Authority Lock created. End the current turn before product implementation, file edits, builds, or tests.
|
|
169
|
+
model_change_owner: "host_or_user",
|
|
170
|
+
model_change_observable_by_harness: false,
|
|
171
|
+
generic_continue_satisfies: true,
|
|
172
|
+
message: "Authority Lock created. End the current turn before product implementation, file edits, builds, or tests. After handling the model change, send [continue]. Harness cannot observe or verify the model change.",
|
|
172
173
|
};
|
|
173
174
|
}
|
|
174
175
|
function message(error) {
|
package/dist/commands/sync.js
CHANGED
|
@@ -5,6 +5,8 @@ export async function sync() {
|
|
|
5
5
|
for (const skipped of report.skipped.filter((line) => line.includes("customized"))) {
|
|
6
6
|
console.log(`skipped: ${skipped}`);
|
|
7
7
|
}
|
|
8
|
+
for (const notice of report.notices ?? [])
|
|
9
|
+
console.log(notice);
|
|
8
10
|
for (const blocked of report.blocked) {
|
|
9
11
|
console.error(`blocked: ${blocked}`);
|
|
10
12
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,12 @@ export { commands } from "./commands/index.js";
|
|
|
2
2
|
export { compileDeliveryContract, type CompileDeliveryOptionsV2, } from "./lib/long-task-delivery-compiler.js";
|
|
3
3
|
export { DELIVERY_CONTRACT_FILE, parseDeliveryContract, parseDeliveryContractBundle, } from "./lib/long-task-delivery-parser.js";
|
|
4
4
|
export { evaluateContractBoundary } from "./lib/long-task-boundary-check.js";
|
|
5
|
-
export { publishDesignResourceHandoffBundle
|
|
5
|
+
export { publishDesignResourceHandoffBundle } from "./lib/design-resource-handoff-bundle.js";
|
|
6
6
|
export { preflightDesignResourceHandoff } from "./lib/design-resource-handoff-validation.js";
|
|
7
|
+
export { symbolicDenotation } from "./lib/symbolic-denotation-public.js";
|
|
7
8
|
export { classifyLongTaskRisk, validateRiskProof, } from "./lib/long-task-risk.js";
|
|
8
9
|
export { verifyDeliveryContract } from "./lib/long-task-verifier-v2.js";
|
|
9
10
|
export { runDeliveryFinalGate } from "./lib/long-task-final-v2.js";
|
|
10
11
|
export { closeDeliveryTask, type DeliveryStatusV2, doctorDeliveryTask, readDeliveryStatus, resumeDeliveryTask, stopCheckDeliveryTask, } from "./lib/long-task-status-v2.js";
|
|
11
12
|
export { readActiveLongTaskBinding, readCompiledDeliveryContract, readFinalReceipt, } from "./lib/long-task-state.js";
|
|
12
|
-
export type { HarnessConfig, HarnessProfile, ManagedFile, SourceMapping, } from "./
|
|
13
|
-
export type { CheckExecutionResultV2, CompiledDeliveryContractV2, DeliveryAssertionV2, DeliveryCheckV2, DeliveryContractV2, DeliveryOutcomeV2, EffectiveRiskLevel, ExternalConfirmationV2, FinalReceiptV2, LongTaskFindingV2, LongTaskRiskFacts, ProofSurface, ProgressRecordV2, RequestedRiskLevel, RunnerType, SourceClaimV2, TargetedVerificationResultV2, } from "./lib/long-task-delivery-types.js";
|
|
14
|
-
export type { BoundaryCheckDecisionV2, BoundaryCheckInputV2, } from "./lib/long-task-boundary-check.js";
|
|
13
|
+
export type { BoundaryCheckDecisionV2, BoundaryCheckInputV2, CheckExecutionResultV2, CompiledDeliveryContractV2, DesignResourceHandoffBundleOptions, DesignResourceHandoffBundleResult, DesignResourceHandoffPreflightV1, DesignResourceHandoffPreflightV2, DesignResourceHandoffV1, DesignResourceHandoffV2, DesignResourceObservableRuleManifestV2, DesignResourceSymbolicFactRuleV2, DesignResourceSymbolicNoninterferenceArtifactV2, DesignResourceSymbolicNoninterferenceCertificateV2, DesignResourceSymbolicNoninterferenceDerivedResultV2, DesignResourceSymbolicNoninterferenceFailureWitnessV1, DesignResourceSymbolicNoninterferenceInputBindingV2, DesignResourceSymbolicNoninterferenceProofV2, DesignResourceSymbolicProofObligationV2, DesignResourceSymbolicSourceIrCertificateScopeV1, DesignResourceSymbolicSourceIrRegionV1, DesignResourceSymbolicSourceIrV1, CompiledSymbolicDenotationV1, SymbolicDenotationAxisDomain, SymbolicDenotationComplexityLimits, SymbolicDenotationPredicate, SymbolicExtensionalPointV1, SymbolicPointDenotationV1, DeliveryAssertionV2, DeliveryCheckV2, DeliveryContractV2, DeliveryOutcomeV2, EffectiveRiskLevel, ExternalConfirmationV2, FinalReceiptV2, LongTaskFindingV2, LongTaskRiskFacts, ProofSurface, ProgressRecordV2, RequestedRiskLevel, RunnerType, SourceClaimV2, TargetedVerificationResultV2, HarnessConfig, HarnessProfile, ManagedFile, SourceMapping, } from "./public-types.js";
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,9 @@ export { commands } from "./commands/index.js";
|
|
|
2
2
|
export { compileDeliveryContract, } from "./lib/long-task-delivery-compiler.js";
|
|
3
3
|
export { DELIVERY_CONTRACT_FILE, parseDeliveryContract, parseDeliveryContractBundle, } from "./lib/long-task-delivery-parser.js";
|
|
4
4
|
export { evaluateContractBoundary } from "./lib/long-task-boundary-check.js";
|
|
5
|
-
export { publishDesignResourceHandoffBundle
|
|
5
|
+
export { publishDesignResourceHandoffBundle } from "./lib/design-resource-handoff-bundle.js";
|
|
6
6
|
export { preflightDesignResourceHandoff } from "./lib/design-resource-handoff-validation.js";
|
|
7
|
+
export { symbolicDenotation } from "./lib/symbolic-denotation-public.js";
|
|
7
8
|
export { classifyLongTaskRisk, validateRiskProof, } from "./lib/long-task-risk.js";
|
|
8
9
|
export { verifyDeliveryContract } from "./lib/long-task-verifier-v2.js";
|
|
9
10
|
export { runDeliveryFinalGate } from "./lib/long-task-final-v2.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare function compactCommonFields<T extends Record<string, unknown>>(rows: T[], excluded: string[]): Record<string, unknown>;
|
|
2
|
+
export declare function compactWithoutFields<T extends Record<string, unknown>>(value: T, fields: string[]): Record<string, unknown>;
|
|
3
|
+
export declare function compactAuthoringTable<T extends object>(input: T[], excludedDefaults?: string[]): {
|
|
4
|
+
defaults: Record<string, unknown>;
|
|
5
|
+
columns: string[];
|
|
6
|
+
rows: unknown[][];
|
|
7
|
+
};
|
|
8
|
+
export declare function applyCompactAuthoringSelectors(base: Record<string, unknown>): {
|
|
9
|
+
value: Record<string, unknown>;
|
|
10
|
+
selectors: Array<{
|
|
11
|
+
key: string;
|
|
12
|
+
members: string[];
|
|
13
|
+
}>;
|
|
14
|
+
};
|
|
15
|
+
export declare function compactCapacityBudget(name: string, measured: number): number;
|
|
16
|
+
export declare function compactDeterministicTemplates(records: Record<string, unknown>[], excludedFields: string[], keyPrefix: string): {
|
|
17
|
+
templates: Array<{
|
|
18
|
+
key: string;
|
|
19
|
+
value: Record<string, unknown>;
|
|
20
|
+
}>;
|
|
21
|
+
template_refs: string[];
|
|
22
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { canonicalValueJson, sha256Hex } from "./strict-codec.js";
|
|
3
|
+
const STABLE_REF = /^[a-z0-9][a-z0-9._:-]*$/u;
|
|
4
|
+
export function compactCommonFields(rows, excluded) {
|
|
5
|
+
if (!rows.length)
|
|
6
|
+
return {};
|
|
7
|
+
const result = {};
|
|
8
|
+
for (const key of Object.keys(rows[0])) {
|
|
9
|
+
if (excluded.includes(key))
|
|
10
|
+
continue;
|
|
11
|
+
const identity = canonicalValueJson(rows[0][key]);
|
|
12
|
+
if (rows.every((row) => Object.hasOwn(row, key) && canonicalValueJson(row[key]) === identity))
|
|
13
|
+
result[key] = structuredClone(rows[0][key]);
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
export function compactWithoutFields(value, fields) {
|
|
18
|
+
const excluded = new Set(fields);
|
|
19
|
+
return Object.fromEntries(Object.entries(value)
|
|
20
|
+
.filter(([key]) => !excluded.has(key))
|
|
21
|
+
.map(([key, item]) => [key, structuredClone(item)]));
|
|
22
|
+
}
|
|
23
|
+
export function compactAuthoringTable(input, excludedDefaults = []) {
|
|
24
|
+
const records = input;
|
|
25
|
+
const defaults = compactCommonFields(records, excludedDefaults);
|
|
26
|
+
const columns = [
|
|
27
|
+
...new Set(records.flatMap((record) => Object.keys(record))),
|
|
28
|
+
].filter((key) => !Object.hasOwn(defaults, key));
|
|
29
|
+
return {
|
|
30
|
+
defaults,
|
|
31
|
+
columns,
|
|
32
|
+
rows: records.map((record, rowIndex) => columns.map((column) => {
|
|
33
|
+
if (!Object.hasOwn(record, column))
|
|
34
|
+
throw new Error(`compact_authoring_sparse_cell:${rowIndex}:${column}`);
|
|
35
|
+
return structuredClone(record[column]);
|
|
36
|
+
})),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function applyCompactAuthoringSelectors(base) {
|
|
40
|
+
const selectorCounts = countSelectorCandidates(base);
|
|
41
|
+
const selectorMap = new Map();
|
|
42
|
+
const value = replaceSharedSelectors(base, selectorCounts, selectorMap);
|
|
43
|
+
return {
|
|
44
|
+
value,
|
|
45
|
+
selectors: [...selectorMap.entries()]
|
|
46
|
+
.map(([key, members]) => ({ key, members }))
|
|
47
|
+
.sort((left, right) => left.key.localeCompare(right.key)),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function selectorCandidate(value) {
|
|
51
|
+
return Array.isArray(value) &&
|
|
52
|
+
value.length > 0 &&
|
|
53
|
+
value.every((item) => typeof item === "string" && STABLE_REF.test(item))
|
|
54
|
+
? value
|
|
55
|
+
: null;
|
|
56
|
+
}
|
|
57
|
+
function countSelectorCandidates(value) {
|
|
58
|
+
const counts = new Map();
|
|
59
|
+
const visit = (item, parentKey = "") => {
|
|
60
|
+
if (parentKey === "columns" || parentKey === "selectors")
|
|
61
|
+
return;
|
|
62
|
+
if (parentKey === "rows" && Array.isArray(item)) {
|
|
63
|
+
for (const row of item)
|
|
64
|
+
visit(row, "table_row");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (parentKey === "table_row" && Array.isArray(item)) {
|
|
68
|
+
for (const cell of item)
|
|
69
|
+
visit(cell);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const candidate = selectorCandidate(item);
|
|
73
|
+
if (candidate) {
|
|
74
|
+
const identity = canonicalValueJson(candidate);
|
|
75
|
+
counts.set(identity, (counts.get(identity) ?? 0) + 1);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (Array.isArray(item))
|
|
79
|
+
for (const child of item)
|
|
80
|
+
visit(child, parentKey);
|
|
81
|
+
else if (item && typeof item === "object")
|
|
82
|
+
for (const [key, child] of Object.entries(item))
|
|
83
|
+
visit(child, key);
|
|
84
|
+
};
|
|
85
|
+
visit(value);
|
|
86
|
+
return counts;
|
|
87
|
+
}
|
|
88
|
+
function replaceSharedSelectors(value, counts, selectors) {
|
|
89
|
+
const replace = (item, parentKey = "") => {
|
|
90
|
+
if (parentKey === "columns" || parentKey === "selectors")
|
|
91
|
+
return structuredClone(item);
|
|
92
|
+
if (parentKey === "rows" && Array.isArray(item))
|
|
93
|
+
return item.map((row) => replace(row, "table_row"));
|
|
94
|
+
if (parentKey === "table_row" && Array.isArray(item))
|
|
95
|
+
return item.map((cell) => replace(cell));
|
|
96
|
+
const candidate = selectorCandidate(item);
|
|
97
|
+
if (candidate) {
|
|
98
|
+
const identity = canonicalValueJson(candidate);
|
|
99
|
+
const count = counts.get(identity) ?? 0;
|
|
100
|
+
const selectorKey = `selector.refs.${sha256Hex(identity).slice(0, 16)}`;
|
|
101
|
+
const referenceBytes = Buffer.byteLength(canonicalValueJson({ selector_ref: selectorKey }), "utf8");
|
|
102
|
+
const listBytes = Buffer.byteLength(identity, "utf8");
|
|
103
|
+
if (count > 1 && (count - 1) * listBytes > count * referenceBytes) {
|
|
104
|
+
selectors.set(selectorKey, [...candidate]);
|
|
105
|
+
return { selector_ref: selectorKey };
|
|
106
|
+
}
|
|
107
|
+
return [...candidate];
|
|
108
|
+
}
|
|
109
|
+
if (Array.isArray(item))
|
|
110
|
+
return item.map((child) => replace(child, parentKey));
|
|
111
|
+
if (item && typeof item === "object")
|
|
112
|
+
return Object.fromEntries(Object.entries(item).map(([key, child]) => [key, replace(child, key)]));
|
|
113
|
+
return item;
|
|
114
|
+
};
|
|
115
|
+
return replace(value);
|
|
116
|
+
}
|
|
117
|
+
export function compactCapacityBudget(name, measured) {
|
|
118
|
+
if (name === "canonical_bytes")
|
|
119
|
+
return Math.max(1024 * 1024, roundPowerOfTwo(measured));
|
|
120
|
+
return Math.max(16, roundPowerOfTwo(measured));
|
|
121
|
+
}
|
|
122
|
+
export function compactDeterministicTemplates(records, excludedFields, keyPrefix) {
|
|
123
|
+
const templateByIdentity = new Map();
|
|
124
|
+
const templateRefs = records.map((record) => {
|
|
125
|
+
const value = compactWithoutFields(record, excludedFields);
|
|
126
|
+
const identity = canonicalValueJson(value);
|
|
127
|
+
const current = templateByIdentity.get(identity);
|
|
128
|
+
if (current)
|
|
129
|
+
return current.key;
|
|
130
|
+
const key = `${keyPrefix}.${sha256Hex(identity).slice(0, 20)}`;
|
|
131
|
+
templateByIdentity.set(identity, { key, value });
|
|
132
|
+
return key;
|
|
133
|
+
});
|
|
134
|
+
return {
|
|
135
|
+
templates: [...templateByIdentity.values()].sort((left, right) => left.key.localeCompare(right.key)),
|
|
136
|
+
template_refs: templateRefs,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function roundPowerOfTwo(value) {
|
|
140
|
+
if (value <= 1)
|
|
141
|
+
return 1;
|
|
142
|
+
return 2 ** Math.ceil(Math.log2(value));
|
|
143
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CompactSharedStructureStatistics, CompactSharedStructureTarget, CompactSharedStructureTemplate } from "./compact-shared-structure-types.js";
|
|
2
|
+
export declare function applyCompactSharedStructures(targets: CompactSharedStructureTarget[]): {
|
|
3
|
+
catalog: CompactSharedStructureTemplate[];
|
|
4
|
+
statistics: CompactSharedStructureStatistics;
|
|
5
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createCompactSharedStructures } from "./compact-shared-structures.js";
|
|
2
|
+
export function applyCompactSharedStructures(targets) {
|
|
3
|
+
const encoded = createCompactSharedStructures(targets.map((target) => ({
|
|
4
|
+
boundary: target.boundary,
|
|
5
|
+
value: target.read(),
|
|
6
|
+
})));
|
|
7
|
+
encoded.slots.forEach((slot, index) => targets[index].write(slot.value));
|
|
8
|
+
return { catalog: encoded.catalog, statistics: encoded.statistics };
|
|
9
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export interface CompactSharedStructureSlot {
|
|
2
|
+
boundary: string;
|
|
3
|
+
value: unknown;
|
|
4
|
+
}
|
|
5
|
+
export interface CompactSharedStructureTarget {
|
|
6
|
+
boundary: string;
|
|
7
|
+
read: () => unknown;
|
|
8
|
+
write: (value: unknown) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface CompactSharedStructureTemplate {
|
|
11
|
+
key: string;
|
|
12
|
+
digest: string;
|
|
13
|
+
boundary: string;
|
|
14
|
+
parameter_count: number;
|
|
15
|
+
template: unknown;
|
|
16
|
+
}
|
|
17
|
+
export interface CompactSharedStructureFamilyStatistic {
|
|
18
|
+
key: string;
|
|
19
|
+
boundary: string;
|
|
20
|
+
occurrences: number;
|
|
21
|
+
parameter_count: number;
|
|
22
|
+
original_bytes: number;
|
|
23
|
+
encoded_bytes: number;
|
|
24
|
+
saved_bytes: number;
|
|
25
|
+
}
|
|
26
|
+
export interface CompactSharedStructureStatistics {
|
|
27
|
+
slot_count: number;
|
|
28
|
+
composite_slot_count: number;
|
|
29
|
+
candidate_family_count: number;
|
|
30
|
+
emitted_family_count: number;
|
|
31
|
+
exact_family_count: number;
|
|
32
|
+
parameterized_family_count: number;
|
|
33
|
+
reference_count: number;
|
|
34
|
+
argument_count: number;
|
|
35
|
+
original_payload_bytes: number;
|
|
36
|
+
encoded_payload_bytes: number;
|
|
37
|
+
catalog_bytes: number;
|
|
38
|
+
saved_bytes: number;
|
|
39
|
+
remaining_beneficial_candidates: number;
|
|
40
|
+
families: CompactSharedStructureFamilyStatistic[];
|
|
41
|
+
}
|
|
42
|
+
export interface CompactSharedStructureEncoding {
|
|
43
|
+
slots: CompactSharedStructureSlot[];
|
|
44
|
+
catalog: CompactSharedStructureTemplate[];
|
|
45
|
+
statistics: CompactSharedStructureStatistics;
|
|
46
|
+
}
|
|
47
|
+
export interface CompactSharedStructureCandidateOccurrence {
|
|
48
|
+
slot_index: number;
|
|
49
|
+
value: unknown;
|
|
50
|
+
leaves: unknown[];
|
|
51
|
+
original_bytes: number;
|
|
52
|
+
}
|
|
53
|
+
export interface CompactSharedStructureCandidateFamily {
|
|
54
|
+
boundary: string;
|
|
55
|
+
occurrences: CompactSharedStructureCandidateOccurrence[];
|
|
56
|
+
parameter_positions: number[];
|
|
57
|
+
template: unknown;
|
|
58
|
+
row: CompactSharedStructureTemplate;
|
|
59
|
+
references: unknown[];
|
|
60
|
+
statistic: CompactSharedStructureFamilyStatistic;
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { CompactSharedStructureStatistics, CompactSharedStructureTarget } from "./compact-shared-structure-types.js";
|
|
2
|
+
export declare function materializeCanonicalCompactSharedStructures(targets: CompactSharedStructureTarget[], catalogInput: unknown, label: string): CompactSharedStructureStatistics;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { createCompactSharedStructures } from "./compact-shared-structures.js";
|
|
2
|
+
import { canonicalValueJson, sha256Hex } from "./strict-codec.js";
|
|
3
|
+
const STABLE_BOUNDARY = /^[a-z0-9][a-z0-9._:-]*$/u;
|
|
4
|
+
const STRUCTURE_KEY = /^structure\.[a-f0-9]{24}$/u;
|
|
5
|
+
export function materializeCanonicalCompactSharedStructures(targets, catalogInput, label) {
|
|
6
|
+
const catalog = parseCatalog(catalogInput, `${label}.shared_structures`);
|
|
7
|
+
const encodedSlots = targets.map((target, index) => ({
|
|
8
|
+
boundary: validBoundary(target.boundary, `${label}.slots[${index}]`),
|
|
9
|
+
value: structuredClone(target.read()),
|
|
10
|
+
}));
|
|
11
|
+
const catalogByKey = new Map(catalog.map((item) => [item.key, item]));
|
|
12
|
+
const materializedSlots = encodedSlots.map((slot, index) => ({
|
|
13
|
+
boundary: slot.boundary,
|
|
14
|
+
value: resolveReference(slot.value, slot.boundary, catalogByKey, `${label}.slots[${index}]`),
|
|
15
|
+
}));
|
|
16
|
+
const canonical = createCompactSharedStructures(materializedSlots);
|
|
17
|
+
if (canonicalValueJson(canonical.catalog) !== canonicalValueJson(catalog) ||
|
|
18
|
+
canonicalValueJson(canonical.slots) !== canonicalValueJson(encodedSlots))
|
|
19
|
+
fail(label, "shared structure catalog is not canonical");
|
|
20
|
+
materializedSlots.forEach((slot, index) => targets[index].write(slot.value));
|
|
21
|
+
return canonical.statistics;
|
|
22
|
+
}
|
|
23
|
+
function parseCatalog(value, label) {
|
|
24
|
+
if (!Array.isArray(value))
|
|
25
|
+
fail(label, "must be an array");
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
return value.map((item, index) => {
|
|
28
|
+
const itemLabel = `${label}[${index}]`;
|
|
29
|
+
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
30
|
+
fail(itemLabel, "must be an object");
|
|
31
|
+
const row = item;
|
|
32
|
+
const fields = ["key", "digest", "boundary", "parameter_count", "template"];
|
|
33
|
+
const unknown = Object.keys(row).filter((key) => !fields.includes(key));
|
|
34
|
+
const missing = fields.filter((key) => !Object.hasOwn(row, key));
|
|
35
|
+
if (unknown.length)
|
|
36
|
+
fail(itemLabel, `unknown keys: ${unknown.join(",")}`);
|
|
37
|
+
if (missing.length)
|
|
38
|
+
fail(itemLabel, `missing keys: ${missing.join(",")}`);
|
|
39
|
+
if (typeof row.key !== "string" || !STRUCTURE_KEY.test(row.key))
|
|
40
|
+
fail(`${itemLabel}.key`, "must be a canonical structure key");
|
|
41
|
+
if (seen.has(row.key))
|
|
42
|
+
fail(itemLabel, `duplicate key: ${row.key}`);
|
|
43
|
+
seen.add(row.key);
|
|
44
|
+
if (typeof row.digest !== "string" || !/^[a-f0-9]{64}$/u.test(row.digest))
|
|
45
|
+
fail(`${itemLabel}.digest`, "must be a lowercase SHA-256");
|
|
46
|
+
const boundary = validBoundary(row.boundary, `${itemLabel}.boundary`);
|
|
47
|
+
if (!Number.isInteger(row.parameter_count) ||
|
|
48
|
+
Number(row.parameter_count) < 0)
|
|
49
|
+
fail(`${itemLabel}.parameter_count`, "must be an integer >= 0");
|
|
50
|
+
const parameterCount = Number(row.parameter_count);
|
|
51
|
+
const used = validateTemplate(row.template, parameterCount, itemLabel);
|
|
52
|
+
for (let parameter = 0; parameter < parameterCount; parameter += 1)
|
|
53
|
+
if (!used.has(parameter))
|
|
54
|
+
fail(`${itemLabel}.template`, `unused parameter: ${parameter}`);
|
|
55
|
+
const digest = sha256Hex(canonicalValueJson({
|
|
56
|
+
boundary,
|
|
57
|
+
parameter_count: parameterCount,
|
|
58
|
+
template: row.template,
|
|
59
|
+
}));
|
|
60
|
+
if (row.digest !== digest)
|
|
61
|
+
fail(`${itemLabel}.digest`, `digest mismatch: ${row.digest}:${digest}`);
|
|
62
|
+
if (row.key !== `structure.${digest.slice(0, 24)}`)
|
|
63
|
+
fail(`${itemLabel}.key`, "key does not match digest");
|
|
64
|
+
return {
|
|
65
|
+
key: row.key,
|
|
66
|
+
digest,
|
|
67
|
+
boundary,
|
|
68
|
+
parameter_count: parameterCount,
|
|
69
|
+
template: structuredClone(row.template),
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function validateTemplate(value, parameterCount, label) {
|
|
74
|
+
const used = new Set();
|
|
75
|
+
const visit = (item, path) => {
|
|
76
|
+
if (Array.isArray(item)) {
|
|
77
|
+
item.forEach((child, index) => visit(child, `${path}[${index}]`));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (!item || typeof item !== "object") {
|
|
81
|
+
leafKind(item);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const row = item;
|
|
85
|
+
if (Object.hasOwn(row, "structure_ref"))
|
|
86
|
+
fail(path, "templates cannot contain structure references");
|
|
87
|
+
if (Object.hasOwn(row, "parameter_index")) {
|
|
88
|
+
if (Object.keys(row).length !== 1 ||
|
|
89
|
+
!Number.isInteger(row.parameter_index) ||
|
|
90
|
+
Number(row.parameter_index) < 0 ||
|
|
91
|
+
Number(row.parameter_index) >= parameterCount)
|
|
92
|
+
fail(path, "invalid parameter placeholder");
|
|
93
|
+
used.add(Number(row.parameter_index));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
for (const [key, child] of Object.entries(row))
|
|
97
|
+
visit(child, `${path}.${key}`);
|
|
98
|
+
};
|
|
99
|
+
visit(value, `${label}.template`);
|
|
100
|
+
return used;
|
|
101
|
+
}
|
|
102
|
+
function resolveReference(value, boundary, catalog, label) {
|
|
103
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
104
|
+
return structuredClone(value);
|
|
105
|
+
const row = value;
|
|
106
|
+
if (!Object.hasOwn(row, "structure_ref"))
|
|
107
|
+
return structuredClone(value);
|
|
108
|
+
if (Object.keys(row).length !== 2 ||
|
|
109
|
+
!Object.hasOwn(row, "arguments") ||
|
|
110
|
+
typeof row.structure_ref !== "string")
|
|
111
|
+
fail(label, "structure reference must contain only structure_ref/arguments");
|
|
112
|
+
const template = catalog.get(row.structure_ref);
|
|
113
|
+
if (!template)
|
|
114
|
+
fail(label, `unknown structure: ${String(row.structure_ref)}`);
|
|
115
|
+
if (template.boundary !== boundary)
|
|
116
|
+
fail(label, `structure boundary mismatch: ${template.boundary}:${boundary}`);
|
|
117
|
+
if (!Array.isArray(row.arguments))
|
|
118
|
+
fail(`${label}.arguments`, "must be an array");
|
|
119
|
+
if (row.arguments.length !== template.parameter_count)
|
|
120
|
+
fail(`${label}.arguments`, `parameter count mismatch: ${row.arguments.length}:${template.parameter_count}`);
|
|
121
|
+
row.arguments.forEach((argument, index) => {
|
|
122
|
+
if (argument && typeof argument === "object")
|
|
123
|
+
fail(`${label}.arguments[${index}]`, "arguments must be scalar");
|
|
124
|
+
leafKind(argument);
|
|
125
|
+
});
|
|
126
|
+
return instantiateTemplate(template.template, row.arguments);
|
|
127
|
+
}
|
|
128
|
+
function instantiateTemplate(template, arguments_) {
|
|
129
|
+
if (Array.isArray(template))
|
|
130
|
+
return template.map((item) => instantiateTemplate(item, arguments_));
|
|
131
|
+
if (!template || typeof template !== "object")
|
|
132
|
+
return structuredClone(template);
|
|
133
|
+
const row = template;
|
|
134
|
+
if (Object.keys(row).length === 1 && Object.hasOwn(row, "parameter_index"))
|
|
135
|
+
return structuredClone(arguments_[Number(row.parameter_index)]);
|
|
136
|
+
return Object.fromEntries(Object.entries(row).map(([key, value]) => [
|
|
137
|
+
key,
|
|
138
|
+
instantiateTemplate(value, arguments_),
|
|
139
|
+
]));
|
|
140
|
+
}
|
|
141
|
+
function leafKind(value) {
|
|
142
|
+
if (value === null)
|
|
143
|
+
return "null";
|
|
144
|
+
if (typeof value === "string")
|
|
145
|
+
return "string";
|
|
146
|
+
if (typeof value === "boolean")
|
|
147
|
+
return "boolean";
|
|
148
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
149
|
+
return "number";
|
|
150
|
+
fail("value", `unsupported scalar: ${typeof value}`);
|
|
151
|
+
}
|
|
152
|
+
function validBoundary(value, label) {
|
|
153
|
+
if (typeof value !== "string" || !STABLE_BOUNDARY.test(value))
|
|
154
|
+
fail(label, "must be a stable lowercase boundary");
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
function fail(label, message) {
|
|
158
|
+
throw new Error(`compact_shared_structure_invalid:${label}:${message}`);
|
|
159
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CompactSharedStructureEncoding, CompactSharedStructureSlot } from "./compact-shared-structure-types.js";
|
|
2
|
+
export type { CompactSharedStructureEncoding, CompactSharedStructureFamilyStatistic, CompactSharedStructureSlot, CompactSharedStructureStatistics, CompactSharedStructureTarget, CompactSharedStructureTemplate, } from "./compact-shared-structure-types.js";
|
|
3
|
+
export declare function createCompactSharedStructures(slotsInput: CompactSharedStructureSlot[]): CompactSharedStructureEncoding;
|