@piagent/platform 1.5.5 → 1.6.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/CHANGELOG.md +166 -0
- package/README.md +25 -21
- package/README.vi.md +34 -5
- package/adapters/web-frontend/profile.json +2 -4
- package/architecture/layers.json +18 -3
- package/benchmarks/deep-logic-v1/SPECIALIST_PROTOCOL.vi.md +122 -0
- package/benchmarks/deep-logic-v1/grade.mjs +272 -10
- package/benchmarks/deep-logic-v1/project/apps/admin/src/billing-summary.js +3 -0
- package/benchmarks/deep-logic-v1/project/benchmark-contract/public-smoke.test.js +166 -0
- package/benchmarks/deep-logic-v1/project/package.json +1 -1
- package/benchmarks/deep-logic-v1/project/packages/billing/src/close-period.js +3 -0
- package/benchmarks/deep-logic-v1/project/packages/billing/src/plan-timeline.js +3 -0
- package/benchmarks/deep-logic-v1/project/test/smoke.test.js +7 -1
- package/benchmarks/deep-logic-v1/prompts/budgeted-context-graph.md +2 -0
- package/benchmarks/deep-logic-v1/prompts/fair-dependency-scheduler.md +2 -0
- package/benchmarks/deep-logic-v1/prompts/layered-policy-resolution.md +2 -0
- package/benchmarks/deep-logic-v1/prompts/resumable-stream-assembly.md +3 -1
- package/benchmarks/deep-logic-v1/prompts/revision-event-reconciliation.md +2 -0
- package/benchmarks/deep-logic-v1/prompts/temporal-usage-billing-close.md +123 -0
- package/benchmarks/deep-logic-v1/prompts/transactional-config-merge.md +2 -0
- package/benchmarks/deep-logic-v1/suite.json +51 -3
- package/benchmarks/deep-logic-v1/variant.mjs +22 -1
- package/benchmarks/production-v1/spend-control.v1.json +92 -0
- package/benchmarks/production-v1/suite.json +46 -3
- package/catalog/capabilities.json +18 -18
- package/docs/authority-manifest.md +1 -1
- package/docs/auto-delegation-policy.md +38 -73
- package/docs/command-reference-vietnamese.md +27 -35
- package/docs/context-engine.md +12 -4
- package/docs/context-window-policy.md +37 -1
- package/docs/distribution-standard.md +7 -7
- package/docs/en/architecture.md +27 -13
- package/docs/languages.json +4 -4
- package/docs/model-options.md +8 -5
- package/docs/operator-manual-vietnamese.md +27 -45
- package/docs/project-adapters.md +2 -2
- package/docs/publishing-for-teams.md +10 -0
- package/docs/quality-benchmark.md +427 -62
- package/docs/release-install-policy.md +10 -9
- package/docs/runtime-harness-standard.md +3 -3
- package/docs/runtime-policy-design.md +4 -4
- package/docs/runtime-quality-baseline.md +13 -6
- package/docs/security-threat-model.md +2 -2
- package/docs/subagent-orchestration-capabilities.md +19 -51
- package/docs/subagents-and-multiagent.md +21 -47
- package/docs/task-implementation-contract.md +3 -3
- package/docs/task-lifecycle-vietnamese.md +3 -3
- package/docs/team-onboarding.md +2 -2
- package/docs/usage-observability.md +7 -2
- package/docs/vi/architecture.md +27 -13
- package/docs-site/architecture.html +1 -1
- package/docs-site/benchmark.html +89 -95
- package/docs-site/commands.html +1 -1
- package/docs-site/content/benchmark.html +88 -94
- package/docs-site/content/en/benchmark.html +134 -90
- package/docs-site/content/en/index.html +19 -19
- package/docs-site/content/en/runtime.html +4 -4
- package/docs-site/content/en/whats-new.html +12 -1
- package/docs-site/content/en/workflows.html +2 -2
- package/docs-site/content/index.html +19 -19
- package/docs-site/content/runtime.html +4 -4
- package/docs-site/content/whats-new.html +12 -1
- package/docs-site/content/workflows.html +2 -2
- package/docs-site/context-engine.html +1 -1
- package/docs-site/en/architecture.html +1 -1
- package/docs-site/en/benchmark.html +135 -91
- package/docs-site/en/commands.html +1 -1
- package/docs-site/en/context-engine.html +1 -1
- package/docs-site/en/index.html +20 -20
- package/docs-site/en/mcp-approval.html +1 -1
- package/docs-site/en/mcp-auth.html +1 -1
- package/docs-site/en/mcp-servers.html +1 -1
- package/docs-site/en/mcp.html +1 -1
- package/docs-site/en/permissions.html +1 -1
- package/docs-site/en/profiles.html +1 -1
- package/docs-site/en/quickstart.html +1 -1
- package/docs-site/en/runtime.html +5 -5
- package/docs-site/en/scope.html +1 -1
- package/docs-site/en/security.html +1 -1
- package/docs-site/en/team.html +1 -1
- package/docs-site/en/whats-new.html +13 -2
- package/docs-site/en/workflows.html +3 -3
- package/docs-site/index.html +20 -20
- package/docs-site/mcp-approval.html +1 -1
- package/docs-site/mcp-auth.html +1 -1
- package/docs-site/mcp-servers.html +1 -1
- package/docs-site/mcp.html +1 -1
- package/docs-site/permissions.html +1 -1
- package/docs-site/profiles.html +1 -1
- package/docs-site/quickstart.html +1 -1
- package/docs-site/runtime.html +5 -5
- package/docs-site/scope.html +1 -1
- package/docs-site/security.html +1 -1
- package/docs-site/team.html +1 -1
- package/docs-site/whats-new.html +13 -2
- package/docs-site/workflows.html +3 -3
- package/evals/fixtures/benchmark-assurance-evidence.invalid.json +1 -1
- package/evals/fixtures/benchmark-assurance-evidence.valid.json +1 -1
- package/evals/fixtures/codex-relative-efficiency-v1.invalid.json +4 -0
- package/evals/fixtures/codex-relative-efficiency-v1.valid.json +94 -0
- package/evals/fixtures/helper-request.invalid.json +1 -1
- package/evals/fixtures/helper-request.valid.json +1 -1
- package/evals/fixtures/piagent-webui/session-live-state-v1.invalid.json +18 -0
- package/evals/fixtures/piagent-webui/session-live-state-v1.valid.json +27 -0
- package/evals/fixtures/piagent-webui/subagent-tree-v1.valid.json +7 -0
- package/evals/fixtures/task-authority-snapshot.valid.json +4 -4
- package/evals/fs4-readiness-matrix.v1.json +2 -2
- package/evals/fs5-causal-arm.v1.json +3 -3
- package/evals/fs5-pilot-protocol.v1.json +3 -3
- package/evals/fs5-pilot-protocol.v2.json +8 -8
- package/evals/fs5-pilot-protocol.v3.json +8 -8
- package/evals/fs5-pilot-protocol.v4.json +7 -6
- package/evals/fs5-pilot-protocol.v5.json +9 -7
- package/evals/private-holdout-v1/public-exposure.v1.json +1 -1
- package/evals/runtime-conformance-v1/README.md +43 -0
- package/evals/runtime-conformance-v1/evaluate-paid-canary.mjs +198 -0
- package/evals/runtime-conformance-v1/lane.json +57 -0
- package/evals/runtime-conformance-v1/paid-canary.json +31 -0
- package/evals/runtime-conformance-v1/runner.mjs +456 -0
- package/package.json +3 -1
- package/packages/piagent-core/README.md +13 -4
- package/packages/piagent-core/benchmark/benchmark-assurance.js +4 -1
- package/packages/piagent-core/benchmark/benchmark-bootstrap.js +91 -9
- package/packages/piagent-core/benchmark/benchmark-claim-restrictions.js +38 -7
- package/packages/piagent-core/benchmark/benchmark-cli.js +7 -7
- package/packages/piagent-core/benchmark/benchmark-codex-relative-efficiency.js +698 -0
- package/packages/piagent-core/benchmark/benchmark-codex.js +3 -1
- package/packages/piagent-core/benchmark/benchmark-comparison.js +271 -2
- package/packages/piagent-core/benchmark/benchmark-core.js +736 -664
- package/packages/piagent-core/benchmark/benchmark-execution-guard.js +7 -5
- package/packages/piagent-core/benchmark/benchmark-forensics.js +441 -4
- package/packages/piagent-core/benchmark/benchmark-host-readiness.js +639 -0
- package/packages/piagent-core/benchmark/benchmark-matrix.js +22 -4
- package/packages/piagent-core/benchmark/benchmark-normalized-cost.js +317 -0
- package/packages/piagent-core/benchmark/benchmark-preflight.js +5 -1
- package/packages/piagent-core/benchmark/benchmark-process.js +6 -5
- package/packages/piagent-core/benchmark/benchmark-provider-free-evidence.js +345 -0
- package/packages/piagent-core/benchmark/benchmark-provider-wire.js +126 -0
- package/packages/piagent-core/benchmark/benchmark-record-validation.js +252 -0
- package/packages/piagent-core/benchmark/benchmark-report.js +130 -12
- package/packages/piagent-core/benchmark/benchmark-resume-recovery.js +14 -0
- package/packages/piagent-core/benchmark/benchmark-runner-policy.js +26 -0
- package/packages/piagent-core/benchmark/benchmark-runtime-causal.js +244 -0
- package/packages/piagent-core/benchmark/benchmark-stage-diagnostic.js +979 -0
- package/packages/piagent-core/benchmark/benchmark-statistics.js +64 -0
- package/packages/piagent-core/benchmark/benchmark-stop-policy.js +8 -5
- package/packages/piagent-core/benchmark/benchmark-suite-identity.js +31 -0
- package/packages/piagent-core/benchmark/benchmark-suite-runtime.js +13 -9
- package/packages/piagent-core/benchmark/benchmark-suite.js +149 -2
- package/packages/piagent-core/benchmark/benchmark-summary-support.js +380 -0
- package/packages/piagent-core/benchmark/benchmark-timing-diagnostics.js +971 -0
- package/packages/piagent-core/benchmark/benchmark-usage.js +322 -0
- package/packages/piagent-core/benchmark/benchmark-workflow.js +166 -0
- package/packages/piagent-core/capabilities/runtime-integrity.js +3 -0
- package/packages/piagent-core/docs/context-efficiency-improvement-plan.md +1080 -0
- package/packages/piagent-core/extensions/acceptance-behavior-proof.js +806 -0
- package/packages/piagent-core/extensions/acceptance-contract-semantics.js +83 -69
- package/packages/piagent-core/extensions/acceptance-error-classes.js +160 -0
- package/packages/piagent-core/extensions/acceptance-executable-evidence.js +12 -9
- package/packages/piagent-core/extensions/acceptance-receipt.js +123 -59
- package/packages/piagent-core/extensions/acceptance-state-machine-evidence.js +518 -0
- package/packages/piagent-core/extensions/acceptance-test-binding-evidence.js +60 -0
- package/packages/piagent-core/extensions/context-efficiency-metrics.js +302 -0
- package/packages/piagent-core/extensions/context-efficiency-report.js +167 -0
- package/packages/piagent-core/extensions/context-engine.js +149 -156
- package/packages/piagent-core/extensions/context-evidence.js +48 -0
- package/packages/piagent-core/extensions/context-import-links.js +296 -0
- package/packages/piagent-core/extensions/context-index-policy.js +4 -0
- package/packages/piagent-core/extensions/context-query-paths.js +57 -0
- package/packages/piagent-core/extensions/context-telemetry-integrity.js +65 -0
- package/packages/piagent-core/extensions/criterion-context-pack.js +435 -7
- package/packages/piagent-core/extensions/criterion-graph.js +82 -9
- package/packages/piagent-core/extensions/fallback-base-policy.ts +101 -0
- package/packages/piagent-core/extensions/guard-types.ts +6 -0
- package/packages/piagent-core/extensions/javascript-regex-evidence.js +32 -0
- package/packages/piagent-core/extensions/piagent-guard.ts +420 -260
- package/packages/piagent-core/extensions/task-contract-view.js +17 -3
- package/packages/piagent-core/extensions/task-lifecycle.js +39 -2
- package/packages/piagent-core/extensions/task-state.js +109 -142
- package/packages/piagent-core/extensions/verification-intelligence.js +52 -13
- package/packages/piagent-core/extensions/workspace-evidence-roots.js +193 -0
- package/packages/piagent-core/package.json +1 -1
- package/packages/piagent-core/policies/base-policy.json +44 -2
- package/packages/piagent-core/policy/authority-manifest.v1.json +3 -3
- package/packages/piagent-core/prompts/be-to-fe.md +2 -8
- package/packages/piagent-core/prompts/plan.md +1 -1
- package/packages/piagent-core/prompts/platform-improve.md +2 -6
- package/packages/piagent-core/prompts/review.md +2 -7
- package/packages/piagent-core/prompts/scout.md +1 -1
- package/packages/piagent-core/prompts/task.md +4 -3
- package/packages/piagent-core/runtime/context/context-delivery.ts +103 -0
- package/packages/piagent-core/runtime/context/context-delta-shadow.ts +53 -0
- package/packages/piagent-core/runtime/context/context-efficiency-format.ts +47 -0
- package/packages/piagent-core/runtime/context/context-evidence-qualification.ts +32 -0
- package/packages/piagent-core/runtime/context/prefix-telemetry.ts +47 -0
- package/packages/piagent-core/runtime/context/repository-memory-hints.ts +27 -0
- package/packages/piagent-core/runtime/hooks/agent-prompt-telemetry.ts +56 -0
- package/packages/piagent-core/runtime/hooks/agent-start-hook.ts +162 -102
- package/packages/piagent-core/runtime/hooks/completion-hook.ts +12 -12
- package/packages/piagent-core/runtime/hooks/input-hook.ts +17 -1
- package/packages/piagent-core/runtime/hooks/session-hooks.ts +22 -2
- package/packages/piagent-core/runtime/hooks/session-start-hook.ts +107 -3
- package/packages/piagent-core/runtime/hooks/tool-result-content-guards.ts +95 -0
- package/packages/piagent-core/runtime/hooks/tool-result-hook.ts +134 -166
- package/packages/piagent-core/runtime/hooks/tool-result-value-helpers.ts +66 -0
- package/packages/piagent-core/runtime/inspection/activity-event-adapter.ts +4 -2
- package/packages/piagent-core/runtime/inspection/activity-recovery.ts +104 -0
- package/packages/piagent-core/runtime/inspection/bounded-emission-guard.ts +286 -0
- package/packages/piagent-core/runtime/inspection/runtime-event-store.ts +37 -7
- package/packages/piagent-core/runtime/inspection/task-compaction-history.ts +1 -1
- package/packages/piagent-core/runtime/inspection/task-handoff-history.ts +1 -1
- package/packages/piagent-core/runtime/inspection/task-subagent-tree.ts +27 -4
- package/packages/piagent-core/runtime/inspection/tool-failure-classification.ts +70 -0
- package/packages/piagent-core/runtime/inspection/webui-snapshot.ts +73 -9
- package/packages/piagent-core/runtime/model/authenticated-catalog.ts +17 -9
- package/packages/piagent-core/runtime/model/openai-codex-reasoning.ts +83 -0
- package/packages/piagent-core/runtime/model/provider-wire-fingerprint.ts +238 -0
- package/packages/piagent-core/runtime/orchestration/helper-lifecycle.ts +16 -12
- package/packages/piagent-core/runtime/orchestration/minimal-delegation-policy.ts +71 -0
- package/packages/piagent-core/runtime/orchestration/owned-work-budget.ts +28 -20
- package/packages/piagent-core/runtime/orchestration/role-policy.ts +27 -9
- package/packages/piagent-core/runtime/orchestration/subagent-tool-policy.ts +329 -0
- package/packages/piagent-core/runtime/policy/block-remedy.ts +0 -4
- package/packages/piagent-core/runtime/product/activity-inspector.ts +7 -2
- package/packages/piagent-core/runtime/product/efficiency-metrics.ts +7 -2
- package/packages/piagent-core/runtime/quality/edit-freshness-guard.ts +102 -0
- package/packages/piagent-core/runtime/quality/exact-output-contract.ts +22 -11
- package/packages/piagent-core/runtime/quality/performance-assurance-signals.ts +23 -0
- package/packages/piagent-core/runtime/quality/performance-assurance.ts +9 -5
- package/packages/piagent-core/runtime/recovery/continuation-budget.ts +1 -1
- package/packages/piagent-core/runtime/recovery/edit-recovery-context.ts +113 -0
- package/packages/piagent-core/runtime/recovery/edit-recovery-delivery.ts +42 -0
- package/packages/piagent-core/runtime/recovery/handoff-projection.ts +4 -1
- package/packages/piagent-core/runtime/recovery/pristine-task-policy-refresh.ts +91 -0
- package/packages/piagent-core/runtime/recovery/recovery-policy.ts +7 -4
- package/packages/piagent-core/runtime/recovery/resume-state.ts +112 -14
- package/packages/piagent-core/runtime/recovery/semantic-repair-handshake.ts +60 -13
- package/packages/piagent-core/runtime/recovery/semantic-repair-runtime.ts +55 -2
- package/packages/piagent-core/runtime/recovery/task-evidence-coverage-refresh.ts +217 -0
- package/packages/piagent-core/runtime/registration/context-commands.ts +82 -7
- package/packages/piagent-core/runtime/registration/knowledge-tools.ts +9 -5
- package/packages/piagent-core/runtime/registration/operator-request-intake.ts +49 -0
- package/packages/piagent-core/runtime/registration/policy-tools.ts +50 -15
- package/packages/piagent-core/runtime/registration/session-commands.ts +1 -1
- package/packages/piagent-core/runtime/registration/task-completion-tools.ts +61 -25
- package/packages/piagent-core/runtime/registration/task-evidence-tools.ts +21 -12
- package/packages/piagent-core/runtime/registration/task-start-guidance.ts +169 -0
- package/packages/piagent-core/runtime/registration/task-start-manifest.ts +54 -0
- package/packages/piagent-core/runtime/registration/task-start-retry-helpers.ts +37 -0
- package/packages/piagent-core/runtime/registration/task-start-tool.ts +108 -103
- package/packages/piagent-core/runtime/runtime-limits.ts +16 -2
- package/packages/piagent-core/runtime/session/adaptive-context-analysis.ts +461 -0
- package/packages/piagent-core/runtime/session/adaptive-context-governor.ts +464 -0
- package/packages/piagent-core/runtime/session/adaptive-context-ledger.ts +265 -0
- package/packages/piagent-core/runtime/session/message-signals.ts +7 -3
- package/packages/piagent-core/runtime/session/operator-request-carry.ts +44 -0
- package/packages/piagent-core/runtime/session/runtime-state.ts +161 -5
- package/packages/piagent-core/runtime/session/source-checkout-read-grants.ts +35 -0
- package/packages/piagent-core/runtime/session/system-prompt.ts +76 -14
- package/packages/piagent-core/runtime/session/task-contract-presentation.ts +39 -0
- package/packages/piagent-core/runtime/tools/apply-patch-tool.ts +500 -0
- package/packages/piagent-core/runtime/tools/phase-tools.ts +8 -8
- package/packages/piagent-core/runtime/tools/tool-groups.ts +12 -2
- package/packages/piagent-core/runtime/trajectory/trajectory-runtime.ts +2 -1
- package/packages/piagent-core/runtime/verification/exact-verifier-reuse.ts +101 -0
- package/packages/piagent-core/runtime/workflows/runtime-intake-compaction.ts +164 -0
- package/packages/piagent-core/runtime/workflows/task-intake.ts +207 -38
- package/packages/piagent-core/security/sensitive-data.js +13 -218
- package/packages/piagent-core/security/sensitive-project-file.js +42 -0
- package/packages/piagent-core/security/sensitive-source-expression.js +330 -0
- package/packages/piagent-core/security/sensitive-source-formats.js +394 -0
- package/packages/piagent-core/security/sensitive-text.js +234 -0
- package/packages/piagent-core/subagents/piagent-oracle.md +5 -3
- package/packages/piagent-core/subagents/piagent-planner.md +6 -4
- package/packages/piagent-core/subagents/piagent-reviewer.md +5 -3
- package/packages/piagent-core/subagents/piagent-scout.md +4 -2
- package/packages/piagent-core/subagents/piagent-worker.md +7 -5
- package/packages/piagent-webui/dist/client/assets/{MarkdownMessage-rD9WJKxs.js → MarkdownMessage-B4XehTCU.js} +1 -1
- package/packages/piagent-webui/dist/client/assets/index-CgOEyRPG.js +176 -0
- package/packages/piagent-webui/dist/client/index.html +1 -1
- package/packages/piagent-webui/extension/piagent-webui.ts +3 -1
- package/packages/piagent-webui/extension/same-session-bridge.ts +1 -1
- package/packages/piagent-webui/extension/session-stream-adapter.ts +33 -10
- package/packages/piagent-webui/gateway/gateway-events.ts +109 -5
- package/packages/piagent-webui/gateway/gateway-service.ts +3 -0
- package/packages/piagent-webui/gateway/gateway-session-stream.ts +122 -20
- package/packages/piagent-webui/gateway/session-command-controller.ts +18 -3
- package/packages/piagent-webui/gateway/session-effective-options.ts +47 -0
- package/packages/piagent-webui/gateway/session-live-state.ts +21 -0
- package/packages/piagent-webui/gateway/session-operation-lifecycle.ts +237 -0
- package/packages/piagent-webui/gateway/session-operation-retry-control.ts +38 -0
- package/packages/piagent-webui/gateway/session-operation-start.ts +5 -1
- package/packages/piagent-webui/gateway/session-operation-watchdog.ts +165 -0
- package/packages/piagent-webui/gateway/session-runtime-factory.ts +45 -0
- package/packages/piagent-webui/gateway/session-runtime-supervisor.ts +141 -125
- package/packages/piagent-webui/ownership/session-lease-store.ts +5 -2
- package/packages/piagent-webui/server/core-inspection-provider.ts +2 -1
- package/packages/piagent-webui/server/loopback-server.ts +8 -0
- package/packages/piagent-webui/server/transcript-projection.ts +113 -9
- package/packages/piagent-webui/shared/text-visibility.ts +10 -0
- package/schemas/codex-relative-efficiency-v1.schema.json +155 -0
- package/schemas/piagent-webui/catalog-v1.json +9 -0
- package/schemas/piagent-webui/gateway-protocol-v1.schema.json +53 -3
- package/schemas/piagent-webui/runtime-event-v2.schema.json +15 -5
- package/schemas/piagent-webui/session-live-state-v1.schema.json +76 -0
- package/schemas/piagent-webui/subagent-tree-v1.schema.json +11 -1
- package/schemas/project-profile.schema.json +1 -1
- package/schemas/task-contract.schema.json +27 -1
- package/scripts/benchmark-runner-core.mjs +367 -363
- package/scripts/benchmark-runner-finalization.mjs +313 -0
- package/scripts/benchmark-runner-host-readiness.mjs +94 -0
- package/scripts/benchmark-runner-support.mjs +200 -0
- package/scripts/benchmark-session.mjs +95 -41
- package/scripts/configure-model-scope.sh +4 -3
- package/scripts/configure-subagents.sh +42 -34
- package/scripts/helper-evaluation.mjs +2 -2
- package/scripts/install-global.sh +2 -2
- package/scripts/pi-usage-history.mjs +37 -10
- package/scripts/setup.sh +2 -2
- package/scripts/team-doctor.sh +1 -1
- package/scripts/verify-local.sh +10 -1
- package/templates/global/settings.json +2 -1
- package/packages/piagent-webui/dist/client/assets/index-BZRFw1u6.js +0 -174
|
@@ -0,0 +1,1080 @@
|
|
|
1
|
+
# Context Efficiency Improvement Plan
|
|
2
|
+
|
|
3
|
+
## Status
|
|
4
|
+
|
|
5
|
+
- **Scope:** `packages/piagent-core`
|
|
6
|
+
- **Purpose:** Improve prompt-prefix stability, context reuse, delta injection, verification feedback, and adaptive context budgeting.
|
|
7
|
+
- **Verified against:** repository state on 2026-08-23.
|
|
8
|
+
- **Review disposition:** Approved for sequential implementation only after the PR-0A evidence-semantics foundation and the release non-regression gates below.
|
|
9
|
+
- **Implementation order:** PR-0A → PR-0 → PR-1 → PR-2 → PR-3B. PR-3A may start after PR-0A in recommend-only mode.
|
|
10
|
+
- **Implementation progress (2026-08-23):** PR-0A and PR-0 are implemented locally and verified. The first behavior slice now composes one criterion-aware, source-sanitized initial snapshot; cleans volatile state at a terminal/missing-binding task boundary; and measures evidence coverage without rewarding missing telemetry. Redacted items retain only sanitized-text provenance, not a raw-content digest. Production execution is staged at S12/S36/S72/S108 with a ledger-bound durable resume gate. Only the complete S108 ledger may decide the 40% fresh-token claim; paired model intelligence, task continuity, and exact usage remain hard constraints at every paid boundary. Duration, host load, normalized API-equivalent cost, and intermediate token ratios are observations only. Every Piagent record carries a privacy-safe causal aggregate whose provenance, prompt/terminal order and offer/delivery/injection lifecycle fail closed. The runner consumes the frozen seed/execution/stage contract, cannot bypass it by explicitly selecting all scenarios, and finalizes an already complete ledger without another provider preflight. It does not implement residency/delta suppression, verifier batching, or semantic tool-result compaction, and makes no new provider-backed claim yet.
|
|
11
|
+
- **Primary safety rule:** Never trade verification coverage or context correctness for token savings.
|
|
12
|
+
|
|
13
|
+
The implementation scope is primarily `packages/piagent-core`, but policy-backed configuration also requires coordinated changes to root `schemas/`, `adapters/`, capability catalogs/locks, and their tests. These are part of the delivery scope when a phase introduces `contextDeltaShadow`, `contextRuntime`, or `fastVerify` settings.
|
|
14
|
+
|
|
15
|
+
## Release contract
|
|
16
|
+
|
|
17
|
+
Token reduction is the optimization target. Model intelligence and task
|
|
18
|
+
continuity are the non-regression constraints: correctness, safety, scope,
|
|
19
|
+
verification evidence, resolved outcomes, and operation finality may not be
|
|
20
|
+
weakened. Exact usage is required to make the token measurement auditable.
|
|
21
|
+
Duration, host load, and normalized API-equivalent cost remain observational;
|
|
22
|
+
Piagent may be slower than Codex CLI without invalidating the token claim. No
|
|
23
|
+
context phase may be promoted merely because it uses fewer tokens.
|
|
24
|
+
|
|
25
|
+
The release comparison must:
|
|
26
|
+
|
|
27
|
+
- compare Piagent with Codex CLI, never Raw Pi, using the same authenticated
|
|
28
|
+
Codex model, thinking level, prompt, repository tree, verifier, and repeat;
|
|
29
|
+
- run the complete declared suite on an exact clean candidate with seeded,
|
|
30
|
+
randomized pair order and at least three repeats;
|
|
31
|
+
- require the family-clustered upper 95% fresh-token ratio of the complete S108
|
|
32
|
+
ledger to be at most `0.60` for the production-v1 claim (at least 40%
|
|
33
|
+
fresh-token reduction). Category/profile/lifecycle/difficulty and individual
|
|
34
|
+
family ratios remain visible diagnostics, but they do not replace or veto
|
|
35
|
+
the predeclared full-suite estimand;
|
|
36
|
+
- reject a token claim when candidate quality, safety, reliability, workflow,
|
|
37
|
+
resolved outcomes, or evidence completeness is worse than the Codex CLI
|
|
38
|
+
baseline; in addition to aggregate gates, every declared scenario/repeat must
|
|
39
|
+
have exactly one finite paired grade and Piagent may not score below Codex CLI
|
|
40
|
+
on any pair;
|
|
41
|
+
- require every Piagent session to resolve with all required workflow checks,
|
|
42
|
+
exact accepted token buckets, no unknown provider-attempt usage, and no
|
|
43
|
+
timeout, orphaned operation, or unknown terminal state;
|
|
44
|
+
- continue to measure paired duration, normalized API-equivalent cost, and host
|
|
45
|
+
load when evidence is available, but assign those observations no stage,
|
|
46
|
+
verdict, or token-claim authority;
|
|
47
|
+
- require stable system/tool prefix telemetry, with no unexplained prefix drift,
|
|
48
|
+
while keeping model identity and reasoning effort outside the prefix hash;
|
|
49
|
+
- run the exact production efficiency comparison on
|
|
50
|
+
`openai-codex/gpt-5.6-luna:medium`. The product default
|
|
51
|
+
`openai-codex/gpt-5.6-sol:high` and the authenticated Codex catalog remain
|
|
52
|
+
separate compatibility smoke lanes; they are not mixed into the 108-session
|
|
53
|
+
Luna efficiency estimand.
|
|
54
|
+
|
|
55
|
+
Partial, dirty-tree, provider-free, subset, or retry-recovered runs may report
|
|
56
|
+
observations but may not produce a release token-saving claim. S0, S12, S36,
|
|
57
|
+
and S72 are spend-control boundaries, never early token verdicts. Web UI release
|
|
58
|
+
validation remains a separate product control rather than an input to the S108
|
|
59
|
+
benchmark verdict: every operation must reach one canonical terminal settlement;
|
|
60
|
+
only successful assistant output belongs in the chat; drafts, retries, commands,
|
|
61
|
+
and failures belong in Activity; reload/resync must not strand a running
|
|
62
|
+
indicator or remove Stop/recovery controls.
|
|
63
|
+
|
|
64
|
+
Codex OAuth usage currently exposes exact token categories but no authoritative
|
|
65
|
+
monetary charge. Production-v1 binds a versioned official pricing snapshot and
|
|
66
|
+
may report an API-equivalent text-token cost comparison for exact
|
|
67
|
+
model/input/cache/output buckets. The value is observational and non-blocking;
|
|
68
|
+
missing pricing applicability cannot invalidate an otherwise exact fresh-token
|
|
69
|
+
claim. It remains explicitly distinct from provider-billed, OAuth-plan, tool,
|
|
70
|
+
storage, or total currency spend.
|
|
71
|
+
|
|
72
|
+
## Historical paid-run evidence and current decision
|
|
73
|
+
|
|
74
|
+
The historical ledgers below remain immutable and must not be resumed or
|
|
75
|
+
relabelled under the new contract. The next authoritative result must come from
|
|
76
|
+
one fresh, frozen S0→S12→S36→S72→S108 run. The closest clean historical Luna
|
|
77
|
+
Medium production run had a fresh-token ratio of `0.3833` with upper-95%
|
|
78
|
+
`0.4832`, so the 40% target is plausible, but that run is not a valid claim: one
|
|
79
|
+
`cli-double-dash` pair regressed and closed the quality/category gates. A prior
|
|
80
|
+
deep-logic diagnostic at `0.817` was a smaller dirty subset; it is not the
|
|
81
|
+
current production estimate.
|
|
82
|
+
|
|
83
|
+
The latest closed S12 diagnostic used `openai-codex/gpt-5.6-luna:medium` and
|
|
84
|
+
measured `67,507` Piagent fresh tokens versus `106,109` for Codex CLI: ratio
|
|
85
|
+
`0.6362`, or `36.38%` reduction. API-equivalent text-token cost fell `32.88%`
|
|
86
|
+
and pooled Piagent duration was `4.93%` lower, with all six paired grades at
|
|
87
|
+
`10/10`. Under the superseded contract, the stage failed and was permanently
|
|
88
|
+
closed because the 40% token/cost contract was missed and the `quoted-csv`
|
|
89
|
+
family regressed to a `1.4314` token ratio and `1.4259` duration ratio. It also
|
|
90
|
+
misses the current final fresh-token target (`36.38%` rather than at least 40%),
|
|
91
|
+
but remains only a partial historical diagnostic. Its Piagent trajectory used
|
|
92
|
+
20 tool calls and recorded four edit/test errors, while the other five families
|
|
93
|
+
had a pooled fresh-token ratio of `0.4229`. This isolates recovery churn and
|
|
94
|
+
test-selection ambiguity as candidate causes rather than excess context-pack
|
|
95
|
+
payload (the affected pack injected only about 100 tokens).
|
|
96
|
+
|
|
97
|
+
A subsequent clean candidate at `9cc16de` completed a brand-new S12 with all six
|
|
98
|
+
pairs at `10/10`, exact Luna Medium provider parity, no retries, and complete
|
|
99
|
+
schema-v2 causal receipts. It measured `45,474` Piagent fresh tokens versus
|
|
100
|
+
`105,618` for Codex CLI (ratio `0.4306`, or `56.94%` reduction) and an
|
|
101
|
+
API-equivalent text-token cost ratio of `0.4527` (`54.73%` reduction). Aggregate
|
|
102
|
+
Piagent duration was `23.04%` lower. Under the superseded strict-duration
|
|
103
|
+
contract, the stage was permanently closed because `unicode-search:r1` took
|
|
104
|
+
`45.9048s` in Piagent versus `43.0316s` in Codex CLI, a `1.0668` ratio. The
|
|
105
|
+
current contract treats that timing as observational, but it does not
|
|
106
|
+
retroactively reopen, resume, or relabel the old S12 ledger. Recovery
|
|
107
|
+
correctness was covered offline, but the paid S12 observed no edit failures or
|
|
108
|
+
recovery injections and therefore cannot support a paid-run
|
|
109
|
+
recovery-effectiveness claim.
|
|
110
|
+
|
|
111
|
+
The `9cc16de` candidate implemented the planned direct-import, singleton-test,
|
|
112
|
+
bounded edit-recovery, and terminal-state evidence changes and removed the prior
|
|
113
|
+
`quoted-csv` regression. Work following that candidate remained deliberately
|
|
114
|
+
narrow and did not weaken verification: one guarded multi-file `apply_patch`
|
|
115
|
+
operation allows a legitimate source-plus-regression-test change in one
|
|
116
|
+
model/tool turn, while privacy-safe observational timing separates process
|
|
117
|
+
startup, model-turn wait, tool execution, and unattributed remainder.
|
|
118
|
+
Timing uses monotonic JSONL receipt boundaries, stores no prompt, command, path,
|
|
119
|
+
or identifier, leaves ambiguous boundaries unavailable, and has no gate impact.
|
|
120
|
+
These behaviors require offline verification and another clean commit before a
|
|
121
|
+
brand-new S0/S12 ledger; both closed S12 ledgers must never be resumed or
|
|
122
|
+
relabeled.
|
|
123
|
+
|
|
124
|
+
After the candidate passes complete offline verification and is bound to one
|
|
125
|
+
clean commit, start one new staged ledger. S12/S36/S72 may advance only when
|
|
126
|
+
paired quality and model intelligence do not regress, every Piagent task remains
|
|
127
|
+
resolved with complete workflow/causal evidence, and accepted usage is exact.
|
|
128
|
+
Intermediate fresh-token ratios are final-only diagnostics; normalized cost,
|
|
129
|
+
duration, and host load are observational. None of those observations may close
|
|
130
|
+
an otherwise valid stage before S108. Use their aggregates for later engineering
|
|
131
|
+
analysis without changing the frozen candidate mid-run:
|
|
132
|
+
|
|
133
|
+
- unexpected injected tokens or successful direct fallback rereads justify
|
|
134
|
+
residency/delta work;
|
|
135
|
+
- uncompacted managed prefixes justify prefix reduction;
|
|
136
|
+
- unexpected criterion zero-selection reasons justify retrieval repair;
|
|
137
|
+
- high shell-call exposure keeps reread attribution open and must not be
|
|
138
|
+
reported as proven zero waste.
|
|
139
|
+
|
|
140
|
+
If a stage fails a quality, intelligence, continuity, exact-usage, provenance,
|
|
141
|
+
or execution-integrity constraint, close that candidate and fix it without
|
|
142
|
+
spending the remaining sessions. Otherwise proceed through the predeclared
|
|
143
|
+
S36/S72 windows and let the final S108 fresh-token gate decide the claim, even
|
|
144
|
+
when an intermediate token ratio, duration, normalized cost, or host-load
|
|
145
|
+
observation is unfavorable.
|
|
146
|
+
|
|
147
|
+
## 1. Current-state findings
|
|
148
|
+
|
|
149
|
+
The implementation already contains most of the required primitives, but several proposal assumptions need correction before source changes begin.
|
|
150
|
+
|
|
151
|
+
### 1.1 Existing telemetry
|
|
152
|
+
|
|
153
|
+
- `agent_prompt` already records `systemPromptHash` in `runtime/hooks/agent-start-hook.ts`.
|
|
154
|
+
- `context_pack` events that select items already include `selectedPaths`; a new `paths[]` field is not required.
|
|
155
|
+
- `buildContextEfficiencyReport()` already reads bounded telemetry and reports duplicate reads, duplicate output, tool-schema share, low-confidence packs, and positive-only retrieval utilization in `extensions/context-engine.js`.
|
|
156
|
+
|
|
157
|
+
The current `context_pack` event is emitted before the confidence gate decides whether the pack is actually injected. It therefore represents a built candidate pack, not necessarily an injection.
|
|
158
|
+
|
|
159
|
+
### 1.2 Active-task context behavior
|
|
160
|
+
|
|
161
|
+
Context packing is currently disabled for a pending task in two places:
|
|
162
|
+
|
|
163
|
+
- `runtime/hooks/agent-start-hook.ts`: `autoPackUseful` requires the active task not to be pending.
|
|
164
|
+
- `runtime/context/adaptive-planner.ts`: `shouldInject` is false when `activePendingTask` is true.
|
|
165
|
+
|
|
166
|
+
Replacing only `hasAutoPackedPrompt(packKey)` will not activate task-time delta injection.
|
|
167
|
+
|
|
168
|
+
### 1.3 Context manifest semantics
|
|
169
|
+
|
|
170
|
+
The current task `contextManifest` is a mixed-semantics structure containing only `{path, reason}`. Task start may seed it from criterion targets before any file content is delivered, while runtime read and pack paths also append observed or injected entries later.
|
|
171
|
+
|
|
172
|
+
Several consumers currently treat any non-empty manifest as read-only evidence or lifecycle progress. Consequently, a criterion seed can be mistaken for observed context. This existing ambiguity must be corrected before manifest writes are tied to context injection.
|
|
173
|
+
|
|
174
|
+
`buildContextPack()` normally produces a navigation pack with symbols and bounded snippets. A selected path can therefore represent:
|
|
175
|
+
|
|
176
|
+
- a repository-map entry;
|
|
177
|
+
- one or more snippets;
|
|
178
|
+
- truncated content;
|
|
179
|
+
- or, in limited cases, a complete file.
|
|
180
|
+
|
|
181
|
+
Path-level presence alone is insufficient for a safe “already in context” decision.
|
|
182
|
+
|
|
183
|
+
### 1.3.1 Delivery acknowledgement
|
|
184
|
+
|
|
185
|
+
`before_agent_start` can return a hidden message, but returning a message object is not by itself proof that the host accepted it into the conversation. Tool results, slash-command runtime messages, criterion packs, and automatic hidden messages also have different delivery boundaries.
|
|
186
|
+
|
|
187
|
+
The design must therefore distinguish candidate construction, payload return, and confirmed delivery. If the Pi host exposes no confirmation event for a delivery surface, that surface may record only an offered/returned receipt and must not create durable acceptance evidence.
|
|
188
|
+
|
|
189
|
+
### 1.3.2 First-turn task attribution
|
|
190
|
+
|
|
191
|
+
`agent_prompt` is currently emitted before automatic intake creates a task. The first governed prompt can therefore have a session identity but no `taskRunId`. Metrics cannot safely partition that prompt by task without a turn/operation correlation identifier and a later task-binding event.
|
|
192
|
+
|
|
193
|
+
### 1.4 Schema compatibility
|
|
194
|
+
|
|
195
|
+
Task Contract schema v2 validates nested citation objects strictly. Unsupported citation fields are rejected and normalization strips unknown legacy fields.
|
|
196
|
+
|
|
197
|
+
A generic task schema mismatch is currently treated as legacy/untrusted working-tree evidence. A direct v2→v3 bump without an explicit compatible migration can invalidate proof state or force a new task attempt.
|
|
198
|
+
|
|
199
|
+
### 1.5 Compaction behavior
|
|
200
|
+
|
|
201
|
+
`session_compact` currently records only:
|
|
202
|
+
|
|
203
|
+
- reason;
|
|
204
|
+
- retry intent;
|
|
205
|
+
- whether compaction originated from an extension.
|
|
206
|
+
|
|
207
|
+
It does not identify which source excerpts remain in the compacted summary. Any path-level retention assumption after compaction would be unsafe.
|
|
208
|
+
|
|
209
|
+
### 1.6 Verification behavior
|
|
210
|
+
|
|
211
|
+
`buildTestImpact()` exists but is exposed only through diagnostic context tools and commands. It is not part of task verification planning.
|
|
212
|
+
|
|
213
|
+
The completion gate requires all exact commands persisted in `task.verifyCommands` to pass on the current proof-capable tree. Impact-based tests may be added as a fast feedback pass, but must not replace or satisfy the mandatory acceptance commands.
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## 2. Architecture decision
|
|
218
|
+
|
|
219
|
+
Do not use one structure for both durable task evidence and live model-context residency.
|
|
220
|
+
|
|
221
|
+
### 2.1 Planned context and durable evidence
|
|
222
|
+
|
|
223
|
+
Do not store planned criterion seeds in `contextManifest`. Keep planned selection in the criterion graph or a versioned planning receipt.
|
|
224
|
+
|
|
225
|
+
Keep the current task contract representation:
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
type ContextManifestEntry = {
|
|
229
|
+
path: string;
|
|
230
|
+
reason: string;
|
|
231
|
+
};
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
This remains bounded and schema-compatible, but entries may be appended only for:
|
|
235
|
+
|
|
236
|
+
- a successful observed read; or
|
|
237
|
+
- a context payload whose delivery was confirmed by the host.
|
|
238
|
+
|
|
239
|
+
Reason strings must use stable runtime-owned categories rather than being interpreted as free-form proof. Read-only lifecycle and acceptance consumers must reject criterion/planned reasons and require observed-read or confirmed-delivery evidence. Existing v2 tasks with criterion-seeded entries fail safely to “evidence unknown” until a real read or confirmed delivery occurs.
|
|
240
|
+
|
|
241
|
+
### 2.2 Live context residency
|
|
242
|
+
|
|
243
|
+
Add a versioned private sidecar:
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
type ContextResidencyReceipt = {
|
|
247
|
+
schemaVersion: 1;
|
|
248
|
+
taskRunId: string;
|
|
249
|
+
sessionId: string;
|
|
250
|
+
generation: number;
|
|
251
|
+
entries: Array<{
|
|
252
|
+
path: string;
|
|
253
|
+
source:
|
|
254
|
+
| "auto-pack"
|
|
255
|
+
| "criterion-seed"
|
|
256
|
+
| "observed-read"
|
|
257
|
+
| "model-recorded";
|
|
258
|
+
fileContentHash?: string;
|
|
259
|
+
payloadHash: string;
|
|
260
|
+
representation: "full" | "snippets" | "map" | "diff" | "marker";
|
|
261
|
+
ranges?: Array<{ start: number; end: number }>;
|
|
262
|
+
truncated: boolean;
|
|
263
|
+
offeredAt: string;
|
|
264
|
+
deliveredAt?: string;
|
|
265
|
+
injectedTurn?: number;
|
|
266
|
+
contentRef?: string;
|
|
267
|
+
pinned: boolean;
|
|
268
|
+
lastUsedAt?: string;
|
|
269
|
+
deliveryId: string;
|
|
270
|
+
deliveryState: "offered" | "delivered";
|
|
271
|
+
}>;
|
|
272
|
+
};
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Store it under private Piagent state with mode `0600`, atomic writes, bounded retention, protected-path filtering, and no raw prompts.
|
|
276
|
+
|
|
277
|
+
If a task has no valid residency receipt, treat its residency as unknown and reinject bounded context when required. This is safer than assuming old context remains available.
|
|
278
|
+
|
|
279
|
+
`fileContentHash` is the hash of the complete stable file read, when a complete-file hash can be obtained safely. `payloadHash` is the hash of the exact rendered payload delivered to the model. A snippet payload must never be compared directly with a complete current file as though the two hashes represented the same bytes.
|
|
280
|
+
|
|
281
|
+
### 2.3 Delivery receipt lifecycle
|
|
282
|
+
|
|
283
|
+
Use one state machine across every delivery surface:
|
|
284
|
+
|
|
285
|
+
```text
|
|
286
|
+
candidate → offered → delivered
|
|
287
|
+
↘ failed/unknown
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
- `candidate`: selection completed; no model-context claim.
|
|
291
|
+
- `offered`: the extension returned a payload to the host.
|
|
292
|
+
- `delivered`: a host lifecycle event confirms the custom message or tool result.
|
|
293
|
+
- `failed/unknown`: no durable evidence or residency claim is created.
|
|
294
|
+
|
|
295
|
+
Stage manifest/residency updates under `deliveryId`. Commit them idempotently only at `delivered`. If a host version cannot acknowledge a surface, keep the receipt offered and rehydrate conservatively on later turns.
|
|
296
|
+
|
|
297
|
+
The delivery matrix must cover automatic hidden messages, criterion snapshots, explicit task-start tool results, `/context pack`, and `piagent_context_engine pack`.
|
|
298
|
+
|
|
299
|
+
### 2.4 Why use a sidecar first
|
|
300
|
+
|
|
301
|
+
- Avoids a high-risk Task Contract v2→v3 migration in the first rollout.
|
|
302
|
+
- Allows compaction to invalidate residency without deleting durable task evidence.
|
|
303
|
+
- Supports bounded content references needed for incremental diffs.
|
|
304
|
+
- Makes deletion or corruption fail safely to reinjection/default behavior.
|
|
305
|
+
|
|
306
|
+
If product requirements later require residency metadata inside the Task Contract, implement a dedicated lossless v2→v3 migration as a separate change.
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
## 3. Delivery plan
|
|
311
|
+
|
|
312
|
+
| Pull request | Scope | Dependency | Estimated effort |
|
|
313
|
+
|---|---|---|---|
|
|
314
|
+
| PR-0A | Evidence semantics and delivery receipts | None | 2–4 engineering days |
|
|
315
|
+
| PR-0 | Metrics and telemetry semantics | PR-0A | 1–2 engineering days |
|
|
316
|
+
| PR-1 | Task-start baseline and residency sidecar | PR-0A + PR-0 | 3–5 engineering days |
|
|
317
|
+
| PR-2 | Delta injection, compaction recovery, and eviction | PR-1 | 5–7 engineering days |
|
|
318
|
+
| PR-3A | Fast test-impact verification | PR-0A | 2–3 engineering days |
|
|
319
|
+
| PR-3B | Adaptive context-budget learning | PR-2 | 3–5 engineering days |
|
|
320
|
+
|
|
321
|
+
Each PR must be independently revertible. Metrics may default on; behavior-changing features must roll out behind policy modes and emergency kill switches.
|
|
322
|
+
|
|
323
|
+
### 3.1 PR-0A — Correct evidence semantics before optimization
|
|
324
|
+
|
|
325
|
+
1. Stop writing criterion-planned paths into `contextManifest` at task creation.
|
|
326
|
+
2. Preserve criterion seeds in the criterion graph/planning receipt.
|
|
327
|
+
3. Add staged delivery receipts and host-confirmed commit where supported.
|
|
328
|
+
4. Update read-only lifecycle, acceptance, exact-output inputs, trajectory, efficiency metrics, task views, recovery projections, and tests that currently equate `contextManifest.length > 0` with observed evidence.
|
|
329
|
+
5. Treat legacy criterion-only v2 manifests as evidence-unknown; do not invalidate the task schema and do not auto-complete them.
|
|
330
|
+
6. Add explicit automatic and manual task-start tests proving that planned paths alone cannot satisfy completion.
|
|
331
|
+
|
|
332
|
+
PR-0A changes evidence interpretation, not Task Contract schema version. It must not weaken exact verification, working-tree, protected-path, or authority invariants.
|
|
333
|
+
|
|
334
|
+
Primary files/consumers include:
|
|
335
|
+
|
|
336
|
+
- `runtime/registration/task-start-tool.ts`
|
|
337
|
+
- `extensions/task-contract-view.js`
|
|
338
|
+
- `extensions/acceptance-receipt.js`
|
|
339
|
+
- `runtime/hooks/completion-hook.ts`
|
|
340
|
+
- `runtime/trajectory/trajectory-runtime.ts`
|
|
341
|
+
- `runtime/quality/exact-output-contract.ts`
|
|
342
|
+
- `runtime/product/efficiency-metrics.ts`
|
|
343
|
+
- the delivery staging/confirmation module and focused regression tests
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## 4. PR-0 — Measure before changing behavior
|
|
348
|
+
|
|
349
|
+
### 4.1 Prefix instrumentation
|
|
350
|
+
|
|
351
|
+
Extend `agent_prompt` with canonical hashes:
|
|
352
|
+
|
|
353
|
+
```ts
|
|
354
|
+
{
|
|
355
|
+
event: "agent_prompt",
|
|
356
|
+
systemPromptHash,
|
|
357
|
+
toolSchemaHash,
|
|
358
|
+
prefixSurfaceHash,
|
|
359
|
+
activeToolCount,
|
|
360
|
+
toolSchemaTokens,
|
|
361
|
+
taskRunId,
|
|
362
|
+
sessionId
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
Definitions:
|
|
367
|
+
|
|
368
|
+
```text
|
|
369
|
+
toolSchemaHash =
|
|
370
|
+
hash(deep-canonical active tool metadata exactly matching the provider surface)
|
|
371
|
+
|
|
372
|
+
prefixSurfaceHash =
|
|
373
|
+
hash(systemPromptHash + toolSchemaHash)
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
Tool names and all nested object keys must be sorted before hashing so object-order differences do not create false churn. Keep provider/model identity as a metric partition, not as bytes inside `prefixSurfaceHash`. Preserve the historical numeric `activeTools` field or version it explicitly; do not silently change its type.
|
|
377
|
+
|
|
378
|
+
Add `turnId` to `user_input`, `agent_prompt`, pack, delivery, and task-start telemetry. When automatic intake creates a task after `agent_prompt`, emit `turn_task_bound {turnId, taskRunId}` so the first prompt is attributable without rewriting append-only telemetry.
|
|
379
|
+
|
|
380
|
+
### 4.2 Separate pack construction from injection
|
|
381
|
+
|
|
382
|
+
Keep `context_pack` with the meaning “candidate pack was built.”
|
|
383
|
+
|
|
384
|
+
After confidence acceptance, emit an offered event. Emit the following only after host-confirmed delivery:
|
|
385
|
+
|
|
386
|
+
```ts
|
|
387
|
+
{
|
|
388
|
+
event: "context_pack_injected",
|
|
389
|
+
injectionId,
|
|
390
|
+
queryHash,
|
|
391
|
+
selectedPaths,
|
|
392
|
+
selectedItems: Array<{ path: string; estimatedTokens: number }>,
|
|
393
|
+
estimatedTokens,
|
|
394
|
+
confidence
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
Do not count a rejected or empty pack as an injection.
|
|
399
|
+
|
|
400
|
+
Update both `buildContextEfficiencyReport()` and positive retrieval feedback to consume confirmed delivery events. Historical `context_pack` records remain candidate-only and must not be silently reclassified as injections.
|
|
401
|
+
|
|
402
|
+
### 4.3 Metrics
|
|
403
|
+
|
|
404
|
+
Calculate within `sessionId + taskRunId` partitions:
|
|
405
|
+
|
|
406
|
+
```text
|
|
407
|
+
prefixChangeRate =
|
|
408
|
+
changed adjacent prefixSurfaceHash transitions
|
|
409
|
+
/ comparable prompt transitions
|
|
410
|
+
|
|
411
|
+
averageTurnsPerPrefixEpoch =
|
|
412
|
+
prompt count
|
|
413
|
+
/ (1 + prefix changes)
|
|
414
|
+
|
|
415
|
+
duplicateInjectionRate =
|
|
416
|
+
repeated equivalent payload occurrences in context_pack_injected
|
|
417
|
+
/ all injected path occurrences
|
|
418
|
+
|
|
419
|
+
duplicateInjectionTokenRate =
|
|
420
|
+
estimated tokens of duplicate (path + fileContentHash + payloadHash + representation + ranges + generation)
|
|
421
|
+
/ total injected path tokens
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
Required post-compaction rehydration is not a duplicate injection. Task boundaries, explicit refresh, changed hashes, and newly required coverage must be reported separately.
|
|
425
|
+
|
|
426
|
+
Report both micro-averages and macro-averages so a long session cannot dominate the project result.
|
|
427
|
+
|
|
428
|
+
### 4.4 Shadow candidate measurement
|
|
429
|
+
|
|
430
|
+
Actual duplicate injection may be structurally low because active pending tasks currently suppress packing. Add a bounded shadow mode:
|
|
431
|
+
|
|
432
|
+
```text
|
|
433
|
+
contextDeltaShadow: off | sample | on
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
A shadow pass performs selection but never injects content. It records:
|
|
437
|
+
|
|
438
|
+
```ts
|
|
439
|
+
{
|
|
440
|
+
event: "context_delta_shadow",
|
|
441
|
+
candidatePaths,
|
|
442
|
+
pathsAlreadyManifested,
|
|
443
|
+
candidateTokens,
|
|
444
|
+
duplicateCandidateTokens
|
|
445
|
+
}
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
Skip shadow work when the index is missing/stale, context pressure is high, or the task targets protected paths.
|
|
449
|
+
|
|
450
|
+
### 4.5 Report compatibility
|
|
451
|
+
|
|
452
|
+
Bump only the context-efficiency report schema to version 2. Existing event readers should continue to accept historical records with missing new fields.
|
|
453
|
+
|
|
454
|
+
### 4.6 Files
|
|
455
|
+
|
|
456
|
+
- `extensions/context-engine.js`
|
|
457
|
+
- `extensions/piagent-guard.ts`
|
|
458
|
+
- `runtime/hooks/input-hook.ts`
|
|
459
|
+
- `runtime/hooks/agent-start-hook.ts`
|
|
460
|
+
- `runtime/registration/task-start-tool.ts`
|
|
461
|
+
- `runtime/registration/context-commands.ts`
|
|
462
|
+
- `runtime/registration/policy-tools.ts`
|
|
463
|
+
- `tests/context-engine.test.mjs`
|
|
464
|
+
- `tests/piagent-guard-integration.test.mjs`
|
|
465
|
+
|
|
466
|
+
### 4.7 Acceptance tests
|
|
467
|
+
|
|
468
|
+
- Separate sessions and task runs do not share duplicate attribution.
|
|
469
|
+
- Tool-schema ordering does not change the canonical hash.
|
|
470
|
+
- Rejected packs do not increment injection metrics.
|
|
471
|
+
- Missing task IDs, hashes, or selected paths do not crash reporting.
|
|
472
|
+
- Zero denominators produce zero, not `NaN`.
|
|
473
|
+
- Protected paths never appear in telemetry.
|
|
474
|
+
|
|
475
|
+
### 4.8 Decision gate
|
|
476
|
+
|
|
477
|
+
For a smoke decision, collect at least:
|
|
478
|
+
|
|
479
|
+
- 20 task runs;
|
|
480
|
+
- 100 comparable prompt transitions;
|
|
481
|
+
- 5 task runs for every risk lane being evaluated.
|
|
482
|
+
|
|
483
|
+
These floors are not release proof for a 10% reduction claim. Canary decisions must use paired or matched control/treatment cohorts with the same model, thinking level, task class, repository state, and verifier; report variance/confidence intervals and minimum accepted-task counts per evaluated class.
|
|
484
|
+
|
|
485
|
+
Priority rules:
|
|
486
|
+
|
|
487
|
+
| Observation | Decision |
|
|
488
|
+
|---|---|
|
|
489
|
+
| `averageTurnsPerPrefixEpoch <= 1.2` | Freeze the prefix before delta work |
|
|
490
|
+
| Duplicate candidate/injection token rate ≥ 20% | Prioritize Phase 2 |
|
|
491
|
+
| High churn, low duplication | Stabilize system/tool prefix; postpone complex delta logic |
|
|
492
|
+
| Low churn, high duplication | Prioritize delta injection |
|
|
493
|
+
| Both low | Keep baseline work small and prioritize Phase 3A |
|
|
494
|
+
|
|
495
|
+
Hash churn is an invalidation proxy, not proof that cache reuse is zero. Correlate it with provider cache-read/cache-write usage when available.
|
|
496
|
+
|
|
497
|
+
---
|
|
498
|
+
|
|
499
|
+
## 5. PR-1 — Intentional task-start baseline
|
|
500
|
+
|
|
501
|
+
### 5.1 New residency modules
|
|
502
|
+
|
|
503
|
+
Add:
|
|
504
|
+
|
|
505
|
+
```text
|
|
506
|
+
runtime/context/context-residency-store.ts
|
|
507
|
+
runtime/context/context-residency-types.ts
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
Requirements:
|
|
511
|
+
|
|
512
|
+
- private local-state path resolution;
|
|
513
|
+
- symlink-safe access;
|
|
514
|
+
- mode `0600`;
|
|
515
|
+
- atomic writes;
|
|
516
|
+
- bounded entry and byte limits;
|
|
517
|
+
- no protected paths;
|
|
518
|
+
- corrupt/missing state falls back to unknown residency.
|
|
519
|
+
|
|
520
|
+
### 5.2 Extend context-pack results
|
|
521
|
+
|
|
522
|
+
For every selected item, return:
|
|
523
|
+
|
|
524
|
+
```ts
|
|
525
|
+
{
|
|
526
|
+
path,
|
|
527
|
+
fileContentHash: "context-file-v1:<sha256>",
|
|
528
|
+
payloadHash: "context-payload-v1:<sha256>",
|
|
529
|
+
representation,
|
|
530
|
+
ranges,
|
|
531
|
+
truncated,
|
|
532
|
+
estimatedTokens
|
|
533
|
+
}
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
Calculate `fileContentHash` from a complete, stable, symlink-safe file read, not from possibly stale index metadata. Calculate `payloadHash` from the exact rendered item bytes offered for delivery. If a complete stable read is unavailable, omit `fileContentHash` and force coverage-aware refresh behavior.
|
|
537
|
+
|
|
538
|
+
Do not label snippet or repository-map output as a complete file.
|
|
539
|
+
|
|
540
|
+
Line ranges are 1-based and inclusive. Normalize, sort, and merge them before hashing or comparing coverage.
|
|
541
|
+
|
|
542
|
+
### 5.3 Task-start planner
|
|
543
|
+
|
|
544
|
+
Add a planner that does not inherit the active-task suppression rule:
|
|
545
|
+
|
|
546
|
+
```ts
|
|
547
|
+
planTaskStartContext({
|
|
548
|
+
request,
|
|
549
|
+
summary,
|
|
550
|
+
acceptanceCriteria,
|
|
551
|
+
scope,
|
|
552
|
+
riskLane,
|
|
553
|
+
classifierSignal,
|
|
554
|
+
modelCapability
|
|
555
|
+
})
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
Use the stricter of the operator lane and classifier lane. Build a bounded retrieval query from task summary, criteria, canonical scope, criterion hints, and explicit paths. Do not persist the raw prompt.
|
|
559
|
+
|
|
560
|
+
### 5.4 Build once
|
|
561
|
+
|
|
562
|
+
Move baseline ownership to task start:
|
|
563
|
+
|
|
564
|
+
- Automatic intake creates the task and baseline pack once.
|
|
565
|
+
- `finishAgentStart()` receives and injects that result.
|
|
566
|
+
- Explicit `piagent_task_start` includes the baseline pack in its tool result.
|
|
567
|
+
- Remove or bypass the earlier duplicate auto-pack path when task start owns the baseline.
|
|
568
|
+
|
|
569
|
+
Persisting metadata without returning `pack.text` does not inject context and is insufficient.
|
|
570
|
+
|
|
571
|
+
### 5.5 Evidence and residency write order
|
|
572
|
+
|
|
573
|
+
After selection, stage a bounded receipt under `deliveryId`. Only after confirmed delivery:
|
|
574
|
+
|
|
575
|
+
1. append `{path, reason}` to the durable context manifest;
|
|
576
|
+
2. write source/hash/coverage metadata to residency state;
|
|
577
|
+
3. emit `context_pack_injected`.
|
|
578
|
+
|
|
579
|
+
A sidecar write failure must not block the model loop, but the runtime must then treat the path as nonresident on future turns. Manifest, sidecar, and telemetry are not one filesystem transaction, so all writes must be idempotent by `deliveryId`; partial state must fail safely to reinjection rather than claiming residency.
|
|
580
|
+
|
|
581
|
+
### 5.6 Prefix stability
|
|
582
|
+
|
|
583
|
+
Based on Phase 0 evidence:
|
|
584
|
+
|
|
585
|
+
- choose task tool groups once at task start;
|
|
586
|
+
- preserve canonical schema ordering;
|
|
587
|
+
- avoid adding/removing tool schemas within a task except explicit recovery transitions;
|
|
588
|
+
- emit a classified `prefix_transition` event when drift is intentional.
|
|
589
|
+
|
|
590
|
+
Do not hard-fail an agent turn solely because a prefix hash changed.
|
|
591
|
+
|
|
592
|
+
Recovery and explicit user-requested workflow changes may legitimately add a tool group. Preserve user control within a session; prefix stability must never freeze the task workflow or prevent a different request in the same session.
|
|
593
|
+
|
|
594
|
+
### 5.7 Fallbacks
|
|
595
|
+
|
|
596
|
+
| Condition | Behavior |
|
|
597
|
+
|---|---|
|
|
598
|
+
| Missing/stale index | Use criterion seeds; do not block task start |
|
|
599
|
+
| Low retrieval confidence | Do not claim full injected content |
|
|
600
|
+
| File read failure | Skip path and record degraded telemetry |
|
|
601
|
+
| Residency write failure | Allow current injection, force future refresh |
|
|
602
|
+
| Protected path | Do not read, hash, inject, or persist |
|
|
603
|
+
|
|
604
|
+
### 5.8 Tests
|
|
605
|
+
|
|
606
|
+
- Automatic and explicit task starts build exactly one baseline pack.
|
|
607
|
+
- Manifest paths correspond to content actually injected.
|
|
608
|
+
- Planned criterion paths alone never satisfy read-only completion.
|
|
609
|
+
- Offered-but-unconfirmed payloads never enter durable evidence.
|
|
610
|
+
- Every delivery surface produces the same staged/confirmed lifecycle.
|
|
611
|
+
- Snippets are not marked `full`.
|
|
612
|
+
- Content hashes change with file bytes.
|
|
613
|
+
- Missing/stale indexes degrade safely.
|
|
614
|
+
- Corrupt sidecars force reinjection.
|
|
615
|
+
- Protected paths never enter packs or sidecars.
|
|
616
|
+
- Prefix surface remains stable across normal turns in one task.
|
|
617
|
+
|
|
618
|
+
---
|
|
619
|
+
|
|
620
|
+
## 6. PR-2 — Delta-only task-time injection
|
|
621
|
+
|
|
622
|
+
### 6.1 Replace both active-task gates
|
|
623
|
+
|
|
624
|
+
Update both `agent-start-hook.ts` and `adaptive-planner.ts`. The new plan should support:
|
|
625
|
+
|
|
626
|
+
```ts
|
|
627
|
+
type ContextDeltaMode =
|
|
628
|
+
| "skip"
|
|
629
|
+
| "marker"
|
|
630
|
+
| "coverage-delta"
|
|
631
|
+
| "content-diff"
|
|
632
|
+
| "refresh";
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
### 6.2 Per-path algorithm
|
|
636
|
+
|
|
637
|
+
#### New path
|
|
638
|
+
|
|
639
|
+
Inject query-relevant snippets, or a complete file only when size and budget allow. Record coverage and residency.
|
|
640
|
+
|
|
641
|
+
#### Same hash, sufficient coverage
|
|
642
|
+
|
|
643
|
+
Emit only a truthful marker:
|
|
644
|
+
|
|
645
|
+
```text
|
|
646
|
+
foo.ts: the relevant ranges are resident from task turn 3,
|
|
647
|
+
context generation 2.
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
Never claim the complete file is resident when only snippets were injected.
|
|
651
|
+
|
|
652
|
+
#### Same hash, missing coverage
|
|
653
|
+
|
|
654
|
+
Inject only query-relevant ranges not already covered. Merge normalized ranges after confirmed delivery.
|
|
655
|
+
|
|
656
|
+
#### Changed hash
|
|
657
|
+
|
|
658
|
+
- Load prior comparable bytes from `contentRef`.
|
|
659
|
+
- Compare full→full or the same normalized coverage only.
|
|
660
|
+
- Use the low-level `diffTextBuffers` primitive.
|
|
661
|
+
- Inject a bounded incremental diff.
|
|
662
|
+
- Update hash/content reference only after confirmed delivery.
|
|
663
|
+
|
|
664
|
+
If the prior representation is a map, truncated payload, or snippets whose coverage cannot be compared with the current representation, use `refresh` or `coverage-delta`; do not manufacture a full-file diff.
|
|
665
|
+
|
|
666
|
+
The high-level WebUI diff projection should not be used as the delta engine because it is based on task/Git baseline semantics rather than the last injected revision.
|
|
667
|
+
|
|
668
|
+
#### Missing previous content
|
|
669
|
+
|
|
670
|
+
If the previous blob was removed, oversized, binary, or unreadable, inject a bounded current snapshot and reset residency. Never silently skip based only on a hash.
|
|
671
|
+
|
|
672
|
+
#### Delete or rename
|
|
673
|
+
|
|
674
|
+
Inject a structured delete marker and update residency accordingly. Record a rename only when exact Git/task-delta evidence identifies both endpoints; otherwise treat it as delete plus new path.
|
|
675
|
+
|
|
676
|
+
### 6.3 Content retention
|
|
677
|
+
|
|
678
|
+
Store bounded prior content under a private residency blob directory.
|
|
679
|
+
|
|
680
|
+
Suggested limits:
|
|
681
|
+
|
|
682
|
+
- 512 KiB per file;
|
|
683
|
+
- 8 MiB per task;
|
|
684
|
+
- LRU cleanup;
|
|
685
|
+
- mode `0600`;
|
|
686
|
+
- no protected, binary, or sensitive content.
|
|
687
|
+
|
|
688
|
+
A retained hash without a readable content blob is insufficient to generate an incremental diff.
|
|
689
|
+
|
|
690
|
+
Run the repository sensitive-data detector before hashing or persisting raw context. If redaction would change the content, do not persist the raw blob and do not store a guessable raw-content hash; retain only a safe degraded receipt and force later bounded refresh. Use private directories with mode `0700`, `O_NOFOLLOW` reads, strict pre-read byte limits, atomic `0600` publication, and bounded corruption handling.
|
|
691
|
+
|
|
692
|
+
### 6.4 Compaction recovery
|
|
693
|
+
|
|
694
|
+
For every `session_compact` event:
|
|
695
|
+
|
|
696
|
+
```text
|
|
697
|
+
generation += 1
|
|
698
|
+
mark all residency entries stale
|
|
699
|
+
clear in-memory injected-pack assumptions
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
Do not attempt path-specific invalidation because the event does not report retained paths.
|
|
703
|
+
|
|
704
|
+
Persist generation updates with a lock or compare-and-swap rule. A delayed pre-compaction delivery commit must not overwrite a newer generation or resurrect stale residency.
|
|
705
|
+
|
|
706
|
+
After compaction, the next relevant prompt performs bounded rehydration. Durable manifest entries remain intact.
|
|
707
|
+
|
|
708
|
+
On process restart or uncertain resume state, prefer stale residency and bounded reinjection over a false skip.
|
|
709
|
+
|
|
710
|
+
Close or expire residency on task completion/replacement and session shutdown. Retention cleanup must be task-bound and must not delete durable task evidence.
|
|
711
|
+
|
|
712
|
+
### 6.5 Capacity and eviction
|
|
713
|
+
|
|
714
|
+
Add a separate policy:
|
|
715
|
+
|
|
716
|
+
```json
|
|
717
|
+
{
|
|
718
|
+
"contextRuntime": {
|
|
719
|
+
"maxResidentFiles": 12,
|
|
720
|
+
"maxTrackedInjectedTokens": 6000,
|
|
721
|
+
"maxResidencyBlobBytes": 8388608
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
Do not reuse `maxManifestFiles=80` as the live-context LRU.
|
|
727
|
+
|
|
728
|
+
Treat the following as high-priority soft pins unless a security rule requires a hard pin:
|
|
729
|
+
|
|
730
|
+
- explicit user paths;
|
|
731
|
+
- required context;
|
|
732
|
+
- current changed files;
|
|
733
|
+
- criterion-critical targets.
|
|
734
|
+
|
|
735
|
+
Before adding a path:
|
|
736
|
+
|
|
737
|
+
1. choose an unpinned least-recently-used entry;
|
|
738
|
+
2. invalidate its residency and content blob;
|
|
739
|
+
3. emit `context_residency_evicted`;
|
|
740
|
+
4. preserve durable observed-read evidence.
|
|
741
|
+
|
|
742
|
+
Current explicit user paths outrank older soft-pinned entries. If every entry is hard-pinned, skip/degrade the new pack instead of allowing unbounded growth. `maxTrackedInjectedTokens` is an accounting estimate, not a claim about the provider's true resident-token state.
|
|
743
|
+
|
|
744
|
+
Add `contextRuntime` and `contextDeltaShadow` through the typed base policy and capability-lock path. Update the fallback policy copy, policy inspection, profile/schema/catalog ownership, and drift tests in the same PR; do not introduce an untracked environment-only behavior switch.
|
|
745
|
+
|
|
746
|
+
### 6.6 Tests
|
|
747
|
+
|
|
748
|
+
- Pending tasks enter the delta planner.
|
|
749
|
+
- Same hash and coverage emits a marker only.
|
|
750
|
+
- Missing coverage injects only new ranges.
|
|
751
|
+
- Changed content produces an incremental diff without repeated old hunks.
|
|
752
|
+
- Missing blobs cause refresh.
|
|
753
|
+
- Compaction invalidates all residency.
|
|
754
|
+
- Resume cannot cause false skips.
|
|
755
|
+
- LRU never removes pinned entries.
|
|
756
|
+
- File/token/blob limits are enforced.
|
|
757
|
+
- Delete, rename, symlink, binary, and oversized cases degrade safely.
|
|
758
|
+
- Protected paths are never diffed or persisted.
|
|
759
|
+
|
|
760
|
+
Phase 2 is not releasable without passing compaction, restart, generation-race, sensitive-content, and missing-blob tests.
|
|
761
|
+
|
|
762
|
+
---
|
|
763
|
+
|
|
764
|
+
## 7. PR-3A — Fast test-impact verification
|
|
765
|
+
|
|
766
|
+
This PR can proceed after PR-0A and must begin in recommend-only mode.
|
|
767
|
+
|
|
768
|
+
### 7.1 Keep fast and acceptance plans separate
|
|
769
|
+
|
|
770
|
+
Mandatory acceptance remains:
|
|
771
|
+
|
|
772
|
+
```ts
|
|
773
|
+
task.verifyCommands
|
|
774
|
+
```
|
|
775
|
+
|
|
776
|
+
Add a separate advisory representation:
|
|
777
|
+
|
|
778
|
+
```ts
|
|
779
|
+
{
|
|
780
|
+
impactedPaths,
|
|
781
|
+
tests,
|
|
782
|
+
commands,
|
|
783
|
+
generatedForTreeDigest,
|
|
784
|
+
advisory: true
|
|
785
|
+
}
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
It may live in a versioned sidecar or runtime receipt to avoid an immediate Task Contract schema bump.
|
|
789
|
+
|
|
790
|
+
### 7.2 Trigger
|
|
791
|
+
|
|
792
|
+
After the first successful mutation, or whenever the exact task delta changes:
|
|
793
|
+
|
|
794
|
+
1. calculate the current task delta;
|
|
795
|
+
2. call `buildTestImpact(changedFiles)`;
|
|
796
|
+
3. create a fast verification plan;
|
|
797
|
+
4. inject one short plan message on the next turn;
|
|
798
|
+
5. in recommend mode, present fast commands without executing them automatically;
|
|
799
|
+
6. in a separately authorized execution mode, run fast commands before the mandatory full verifier.
|
|
800
|
+
|
|
801
|
+
Do not recompute impact when the tree digest is unchanged.
|
|
802
|
+
|
|
803
|
+
### 7.3 Runner mapping
|
|
804
|
+
|
|
805
|
+
Do not infer shell commands only from filenames. Add explicit profile adapters using executable/argv templates rather than shell strings, for example:
|
|
806
|
+
|
|
807
|
+
```json
|
|
808
|
+
{
|
|
809
|
+
"fastVerify": {
|
|
810
|
+
"mode": "recommend",
|
|
811
|
+
"adapters": [
|
|
812
|
+
{
|
|
813
|
+
"patterns": ["tests/**/*.test.mjs"],
|
|
814
|
+
"executable": "node",
|
|
815
|
+
"args": ["--test", "{files}"]
|
|
816
|
+
}
|
|
817
|
+
]
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
```
|
|
821
|
+
|
|
822
|
+
Validate every project-relative path and expand `{files}` into individual argv elements. If no adapter applies, present impacted test paths without generating a command.
|
|
823
|
+
|
|
824
|
+
Every fast command must pass the normal execution policy, filesystem scope, protected-path checks, external/destructive confirmation policy, timeout/output limits, and current task authority. Record tree digests before and after execution; a fast command that mutates the tree invalidates its own evidence and is surfaced as a verifier-side effect.
|
|
825
|
+
|
|
826
|
+
### 7.4 Security invariants
|
|
827
|
+
|
|
828
|
+
Fast verification:
|
|
829
|
+
|
|
830
|
+
- never sets `matchedProfileCommand=true`;
|
|
831
|
+
- never satisfies completion;
|
|
832
|
+
- never changes `task.verifyCommands`;
|
|
833
|
+
- never bypasses stable-tree verification.
|
|
834
|
+
- never bypasses execution/approval policy.
|
|
835
|
+
|
|
836
|
+
After the final mutation, all exact acceptance commands must pass on the same final tree digest.
|
|
837
|
+
|
|
838
|
+
### 7.5 Tests
|
|
839
|
+
|
|
840
|
+
- Fast success does not complete a task.
|
|
841
|
+
- Full verifier remains mandatory.
|
|
842
|
+
- A later mutation invalidates fast and full evidence.
|
|
843
|
+
- Fast failure leads to repair guidance.
|
|
844
|
+
- Missing/stale indexes produce degraded recommendations.
|
|
845
|
+
- Traversal/test caps are visible in the receipt.
|
|
846
|
+
- Mixed frontend/backend impact never removes the general acceptance group.
|
|
847
|
+
|
|
848
|
+
---
|
|
849
|
+
|
|
850
|
+
## 8. PR-3B — Adaptive budget learning
|
|
851
|
+
|
|
852
|
+
### 8.1 Deterministic task classes
|
|
853
|
+
|
|
854
|
+
Do not key learning by raw prompt. Use a versioned class:
|
|
855
|
+
|
|
856
|
+
```text
|
|
857
|
+
context-task-class-v1:
|
|
858
|
+
workflow
|
|
859
|
+
effective risk lane
|
|
860
|
+
explicit-path yes/no
|
|
861
|
+
scope band: 1 | 2-5 | 6+
|
|
862
|
+
dominant language family
|
|
863
|
+
change mode
|
|
864
|
+
```
|
|
865
|
+
|
|
866
|
+
### 8.2 Completion metrics
|
|
867
|
+
|
|
868
|
+
Evaluate baseline sources separately (`auto-pack`, confirmed `criterion-seed`, and explicit task-start baseline). Do not combine them into one precision value until cohort-specific metrics are available.
|
|
869
|
+
|
|
870
|
+
```text
|
|
871
|
+
precision =
|
|
872
|
+
auto-pack paths used
|
|
873
|
+
/ auto-pack paths injected
|
|
874
|
+
|
|
875
|
+
coverage =
|
|
876
|
+
final structured-used paths present in baseline
|
|
877
|
+
/ final structured-used paths
|
|
878
|
+
|
|
879
|
+
tokenPrecision =
|
|
880
|
+
tokens of used injected items
|
|
881
|
+
/ total injected tokens
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
Strong positive usage evidence includes structured mutation, verification impact, and structured citation events bound to the same content revision. A read/grep after injection is ambiguous: it may indicate use, but it may also indicate missing coverage or lack of trust. Report it separately as fallback reread and do not automatically reward it as positive precision. Free-form final-response path parsing is advisory only.
|
|
885
|
+
|
|
886
|
+
### 8.3 Quality filter
|
|
887
|
+
|
|
888
|
+
Update learning state only when:
|
|
889
|
+
|
|
890
|
+
- task completion succeeded;
|
|
891
|
+
- acceptance passed;
|
|
892
|
+
- exact verifier passed on the final tree;
|
|
893
|
+
- no scope/protected-path violation occurred;
|
|
894
|
+
- telemetry and residency state are valid.
|
|
895
|
+
|
|
896
|
+
Failed, partial, blocked, or corrupt tasks may contribute diagnostics but must not adjust budgets.
|
|
897
|
+
|
|
898
|
+
### 8.4 Learning policy
|
|
899
|
+
|
|
900
|
+
| Valid samples | Behavior |
|
|
901
|
+
|---|---|
|
|
902
|
+
| 0–4 | Deterministic cold-start default |
|
|
903
|
+
| 5–19 | Shadow/recommend only |
|
|
904
|
+
| 20+ | Eligible for a canary evaluation only when the class is not sparse and quality confidence is sufficient |
|
|
905
|
+
|
|
906
|
+
Controls:
|
|
907
|
+
|
|
908
|
+
- EMA alpha around `0.2`;
|
|
909
|
+
- maximum 10–15% adjustment per update window;
|
|
910
|
+
- hard planner minimum and maximum remain authoritative;
|
|
911
|
+
- use p75 utilized tokens plus a safety margin, backed by a bounded deterministic histogram/reservoir or another explicitly mergeable quantile structure;
|
|
912
|
+
- low precision with high coverage may shrink slightly;
|
|
913
|
+
- low coverage must not shrink the budget;
|
|
914
|
+
- retain an exploration floor.
|
|
915
|
+
|
|
916
|
+
### 8.5 Persistence
|
|
917
|
+
|
|
918
|
+
Add:
|
|
919
|
+
|
|
920
|
+
```text
|
|
921
|
+
runtime/context/context-learning-store.ts
|
|
922
|
+
```
|
|
923
|
+
|
|
924
|
+
Store only versioned aggregates:
|
|
925
|
+
|
|
926
|
+
- classifier version;
|
|
927
|
+
- class key;
|
|
928
|
+
- valid sample count;
|
|
929
|
+
- EMA/p50/p75;
|
|
930
|
+
- quality counters;
|
|
931
|
+
- last update.
|
|
932
|
+
|
|
933
|
+
Define atomic concurrent updates, corruption recovery, and classifier-version migration. High-dimensional task classes require hierarchical fallback to a coarser class/global prior; a sparse exact class must not enforce a learned budget merely because a global sample count reached 20.
|
|
934
|
+
|
|
935
|
+
Corrupt or missing state falls back to deterministic defaults and never blocks the task.
|
|
936
|
+
|
|
937
|
+
### 8.6 Rollout
|
|
938
|
+
|
|
939
|
+
```text
|
|
940
|
+
off → shadow → recommend → 10% canary → 50% canary → default
|
|
941
|
+
```
|
|
942
|
+
|
|
943
|
+
An emergency kill switch must immediately restore deterministic budgets.
|
|
944
|
+
|
|
945
|
+
### 8.7 Tests
|
|
946
|
+
|
|
947
|
+
- No learning from failed or partial tasks.
|
|
948
|
+
- No cross-task attribution in one session.
|
|
949
|
+
- Sample floor and hysteresis work as specified.
|
|
950
|
+
- Hard budget bounds cannot be exceeded.
|
|
951
|
+
- Corrupt state falls back safely.
|
|
952
|
+
- Classifier-version changes do not reuse incompatible history.
|
|
953
|
+
- Low coverage cannot trigger shrinking.
|
|
954
|
+
- Same inputs and store state produce deterministic plans.
|
|
955
|
+
|
|
956
|
+
---
|
|
957
|
+
|
|
958
|
+
## 9. Verification matrix
|
|
959
|
+
|
|
960
|
+
### 9.1 Focused suites
|
|
961
|
+
|
|
962
|
+
```bash
|
|
963
|
+
node --test tests/context-engine.test.mjs
|
|
964
|
+
node --test tests/task-state.test.mjs
|
|
965
|
+
node --test tests/runtime-session-modules.test.mjs
|
|
966
|
+
node --test tests/adaptive-runtime-services.test.mjs
|
|
967
|
+
node --test tests/piagent-guard-integration.test.mjs
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
Suggested new suites:
|
|
971
|
+
|
|
972
|
+
```text
|
|
973
|
+
tests/context-residency.test.mjs
|
|
974
|
+
tests/context-delta-injection.test.mjs
|
|
975
|
+
tests/context-learning.test.mjs
|
|
976
|
+
tests/fast-verification-plan.test.mjs
|
|
977
|
+
```
|
|
978
|
+
|
|
979
|
+
PR-0A must also update/add focused coverage for:
|
|
980
|
+
|
|
981
|
+
```text
|
|
982
|
+
tests/context-evidence-semantics.test.mjs
|
|
983
|
+
tests/context-delivery-receipt.test.mjs
|
|
984
|
+
tests/acceptance-receipt.test.mjs
|
|
985
|
+
tests/exact-output-contract.test.mjs
|
|
986
|
+
```
|
|
987
|
+
|
|
988
|
+
### 9.2 Exact verifier
|
|
989
|
+
|
|
990
|
+
After every PR and after the latest mutation:
|
|
991
|
+
|
|
992
|
+
```bash
|
|
993
|
+
bash scripts/verify-local.sh
|
|
994
|
+
```
|
|
995
|
+
|
|
996
|
+
### 9.3 Security review
|
|
997
|
+
|
|
998
|
+
Every behavior-changing PR must verify:
|
|
999
|
+
|
|
1000
|
+
- protected-path filtering;
|
|
1001
|
+
- secret redaction;
|
|
1002
|
+
- sidecar permissions and symlink defense;
|
|
1003
|
+
- no acceptance-verifier bypass;
|
|
1004
|
+
- no cross-session/task attribution;
|
|
1005
|
+
- safe fallback for missing/corrupt state.
|
|
1006
|
+
- offered payloads are not acceptance evidence;
|
|
1007
|
+
- secret-bearing source bytes and hashes are not persisted;
|
|
1008
|
+
- generated verifier commands pass normal execution and approval policy.
|
|
1009
|
+
|
|
1010
|
+
---
|
|
1011
|
+
|
|
1012
|
+
## 10. Rollout gates
|
|
1013
|
+
|
|
1014
|
+
### Phase 1
|
|
1015
|
+
|
|
1016
|
+
- Baseline is injected exactly once.
|
|
1017
|
+
- Manifest and residency match actual injected content.
|
|
1018
|
+
- Criterion plans and offered-only payloads cannot satisfy completion.
|
|
1019
|
+
- Old task/session state degrades safely.
|
|
1020
|
+
- Prefix churn does not increase beyond intentional task-boundary transitions.
|
|
1021
|
+
|
|
1022
|
+
### Phase 2
|
|
1023
|
+
|
|
1024
|
+
- No silent context loss after compaction or restart.
|
|
1025
|
+
- Duplicate injected token rate falls by at least 50% in the canary cohort.
|
|
1026
|
+
- An internal canary may use 10% as a diagnostic milestone, but it cannot make a
|
|
1027
|
+
product claim. Promotion requires the complete release cohort to meet the
|
|
1028
|
+
family-clustered upper-95% ratio `<= 0.60` (at least 40% reduction) at S108.
|
|
1029
|
+
Workload-band and individual-family ratios remain diagnostics and do not
|
|
1030
|
+
override the full-suite estimand.
|
|
1031
|
+
- Verification retry/failure and partial/blocked rates do not regress.
|
|
1032
|
+
- End-to-end duration, normalized API-equivalent cost, and host load remain
|
|
1033
|
+
visible observations with no promotion-gate authority.
|
|
1034
|
+
|
|
1035
|
+
The reduction claim requires a matched control/treatment comparison with the same model, thinking level, task class, repository starting tree, and verifier. Report sample sizes and uncertainty; post-compaction rehydration is classified separately from avoidable duplicate injection.
|
|
1036
|
+
|
|
1037
|
+
### Phase 3A
|
|
1038
|
+
|
|
1039
|
+
- Time to first test feedback improves.
|
|
1040
|
+
- Exact verifier execution remains mandatory before completion.
|
|
1041
|
+
- Zero acceptance bypasses.
|
|
1042
|
+
|
|
1043
|
+
### Phase 3B
|
|
1044
|
+
|
|
1045
|
+
- Learned budgets remain within deterministic hard bounds.
|
|
1046
|
+
- No quality or security regression.
|
|
1047
|
+
- Failed/corrupt evidence never updates the learner.
|
|
1048
|
+
- Kill switch restores defaults immediately.
|
|
1049
|
+
|
|
1050
|
+
---
|
|
1051
|
+
|
|
1052
|
+
## 11. Final dependency order
|
|
1053
|
+
|
|
1054
|
+
```text
|
|
1055
|
+
PR-0A Evidence semantics + delivery receipts
|
|
1056
|
+
↓
|
|
1057
|
+
PR-0 Metrics
|
|
1058
|
+
↓
|
|
1059
|
+
PR-1 Baseline + residency sidecar
|
|
1060
|
+
↓
|
|
1061
|
+
PR-2 Delta + compaction + eviction
|
|
1062
|
+
↓
|
|
1063
|
+
PR-3B Learning shadow/recommend/enforce
|
|
1064
|
+
|
|
1065
|
+
PR-3A Fast verification can start after PR-0A and remains recommend-only until its execution-policy path is verified.
|
|
1066
|
+
```
|
|
1067
|
+
|
|
1068
|
+
Recommended execution sequence:
|
|
1069
|
+
|
|
1070
|
+
1. Implement PR-0A and prove planned context cannot satisfy completion.
|
|
1071
|
+
2. Implement PR-0; make the Codex CLI paired-intelligence, task-continuity,
|
|
1072
|
+
exact-usage, and final S108 fresh-token gates enforceable; keep duration,
|
|
1073
|
+
host load, and normalized cost observational. Start PR-3A in recommend-only
|
|
1074
|
+
mode after PR-0A.
|
|
1075
|
+
3. Collect Phase 0 telemetry while preparing PR-1, but do not enable PR-1
|
|
1076
|
+
behavior until those gates and canonical Web UI operation settlement pass.
|
|
1077
|
+
4. Decide prefix-freeze scope using measured churn.
|
|
1078
|
+
5. Release PR-1 behind a canary policy.
|
|
1079
|
+
6. Do not canary PR-2 until compaction, restart, race, secret-content, and missing-blob tests pass.
|
|
1080
|
+
7. Run PR-3B in shadow/recommend mode before any learned budget is enforced.
|