create-principles-disciple 1.150.3 → 1.150.4
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/_release/product-identity.json +1 -1
- package/codex-adapter/dist/ingestion/admission.js +2 -0
- package/codex-adapter/dist/pd-hook.d.ts +7 -5
- package/codex-adapter/dist/pd-hook.js +18 -7
- package/codex-adapter/dist/tool-semantics.js +5 -1
- package/codex-adapter/dist/worker/workspace-worker.js +4 -2
- package/codex-adapter/package.json +1 -1
- package/console/dist/lib/utils.js +16 -1
- package/console/dist/web/assets/app.css +147 -46
- package/console/dist/web/assets/app.js +35 -32
- package/console/package.json +2 -0
- package/core/dist/runtime/activation-compatibility-read-model.d.ts.map +1 -1
- package/core/dist/runtime/activation-compatibility-read-model.js +2 -1
- package/core/dist/runtime/activation-compatibility-read-model.js.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js +106 -19
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js.map +1 -1
- package/core/dist/runtime/candidate-audit.d.ts.map +1 -1
- package/core/dist/runtime/candidate-audit.js +2 -1
- package/core/dist/runtime/candidate-audit.js.map +1 -1
- package/core/dist/runtime/config/pd-config-effective.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-effective.js +2 -0
- package/core/dist/runtime/config/pd-config-effective.js.map +1 -1
- package/core/dist/runtime/config/pd-config-types.d.ts +52 -0
- package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-types.js.map +1 -1
- package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-validate.js +134 -0
- package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-contract.js +8 -0
- package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +24 -0
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
- package/core/dist/runtime/index.d.ts +2 -0
- package/core/dist/runtime/index.d.ts.map +1 -1
- package/core/dist/runtime/index.js +2 -0
- package/core/dist/runtime/index.js.map +1 -1
- package/core/dist/runtime/internalization/rule-host-input-builder.d.ts +16 -0
- package/core/dist/runtime/internalization/rule-host-input-builder.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rule-host-input-builder.js +18 -0
- package/core/dist/runtime/internalization/rule-host-input-builder.js.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts +8 -0
- package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.js +24 -2
- package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
- package/core/dist/runtime/internalization/tool-semantic-registry.d.ts +26 -0
- package/core/dist/runtime/internalization/tool-semantic-registry.d.ts.map +1 -1
- package/core/dist/runtime/internalization/tool-semantic-registry.js +55 -5
- package/core/dist/runtime/internalization/tool-semantic-registry.js.map +1 -1
- package/core/dist/runtime/internalization-chain-integrity-read-model.d.ts.map +1 -1
- package/core/dist/runtime/internalization-chain-integrity-read-model.js +2 -2
- package/core/dist/runtime/internalization-chain-integrity-read-model.js.map +1 -1
- package/core/dist/runtime/internalization-integrity-remediation.d.ts.map +1 -1
- package/core/dist/runtime/internalization-integrity-remediation.js +2 -2
- package/core/dist/runtime/internalization-integrity-remediation.js.map +1 -1
- package/core/dist/runtime/operator-health-read-model.d.ts.map +1 -1
- package/core/dist/runtime/operator-health-read-model.js +2 -2
- package/core/dist/runtime/operator-health-read-model.js.map +1 -1
- package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
- package/core/dist/runtime/pain-recall-read-model.js +4 -3
- package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
- package/core/dist/runtime/pruning-read-model.d.ts.map +1 -1
- package/core/dist/runtime/pruning-read-model.js +3 -2
- package/core/dist/runtime/pruning-read-model.js.map +1 -1
- package/core/dist/runtime/risk/risk-calculator-policy.d.ts +12 -2
- package/core/dist/runtime/risk/risk-calculator-policy.d.ts.map +1 -1
- package/core/dist/runtime/risk/risk-calculator-policy.js +33 -22
- package/core/dist/runtime/risk/risk-calculator-policy.js.map +1 -1
- package/core/dist/runtime/schema-conformance-read-model.js +2 -2
- package/core/dist/runtime/schema-conformance-read-model.js.map +1 -1
- package/core/dist/runtime/store/sqlite-connection.d.ts +0 -5
- package/core/dist/runtime/store/sqlite-connection.d.ts.map +1 -1
- package/core/dist/runtime/store/sqlite-connection.js +4 -12
- package/core/dist/runtime/store/sqlite-connection.js.map +1 -1
- package/core/dist/runtime/store/storage-paths.d.ts +17 -0
- package/core/dist/runtime/store/storage-paths.d.ts.map +1 -0
- package/core/dist/runtime/store/storage-paths.js +52 -0
- package/core/dist/runtime/store/storage-paths.js.map +1 -0
- package/core/dist/runtime/trajectory-retention.d.ts +257 -0
- package/core/dist/runtime/trajectory-retention.d.ts.map +1 -0
- package/core/dist/runtime/trajectory-retention.js +598 -0
- package/core/dist/runtime/trajectory-retention.js.map +1 -0
- package/core/dist/trajectory-store.d.ts +9 -9
- package/core/dist/trajectory-store.d.ts.map +1 -1
- package/core/dist/trajectory-store.js +9 -12
- package/core/dist/trajectory-store.js.map +1 -1
- package/core/package.json +1 -1
- package/dist/installers/codex-host-installer.d.ts.map +1 -1
- package/dist/installers/codex-host-installer.js +92 -5
- package/dist/installers/codex-host-installer.js.map +1 -1
- package/dist/installers/mcp-binding-shape-mirror.d.ts +27 -0
- package/dist/installers/mcp-binding-shape-mirror.d.ts.map +1 -0
- package/dist/installers/mcp-binding-shape-mirror.js +105 -0
- package/dist/installers/mcp-binding-shape-mirror.js.map +1 -0
- package/dist/skill-catalog.d.ts +35 -0
- package/dist/skill-catalog.d.ts.map +1 -0
- package/dist/skill-catalog.js +85 -0
- package/dist/skill-catalog.js.map +1 -0
- package/dist/skill-delivery-parity.d.ts +22 -0
- package/dist/skill-delivery-parity.d.ts.map +1 -0
- package/dist/skill-delivery-parity.js +31 -0
- package/dist/skill-delivery-parity.js.map +1 -0
- package/host-runtime/dist/active-principle-prompt.d.ts +8 -0
- package/host-runtime/dist/active-principle-prompt.js +15 -5
- package/host-runtime/dist/adaptive-decision-protocol.d.ts +142 -0
- package/host-runtime/dist/adaptive-decision-protocol.js +190 -0
- package/host-runtime/dist/adaptive-priority-provider.d.ts +37 -13
- package/host-runtime/dist/adaptive-priority-provider.js +65 -62
- package/host-runtime/dist/adaptive-selection.d.ts +67 -64
- package/host-runtime/dist/adaptive-selection.js +215 -327
- package/host-runtime/dist/adaptive-skip-decision.d.ts +26 -14
- package/host-runtime/dist/adaptive-skip-decision.js +33 -29
- package/host-runtime/dist/codex-rule-context-provider.js +4 -1
- package/host-runtime/dist/governance-observation-store.d.ts +40 -1
- package/host-runtime/dist/governance-observation-store.js +188 -9
- package/host-runtime/dist/governance-signal-admission.d.ts +19 -3
- package/host-runtime/dist/governance-signal-admission.js +12 -4
- package/host-runtime/dist/host-tool-declaration.d.ts +18 -2
- package/host-runtime/dist/host-tool-declaration.js +67 -11
- package/host-runtime/dist/host-tool-semantic-resolver.d.ts +7 -0
- package/host-runtime/dist/host-tool-semantic-resolver.js +22 -2
- package/host-runtime/dist/index.d.ts +3 -0
- package/host-runtime/dist/index.js +14 -0
- package/host-runtime/dist/production-rulehost-gate.js +15 -3
- package/host-runtime/dist/trajectory-retention.d.ts +147 -0
- package/host-runtime/dist/trajectory-retention.js +907 -0
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/index.d.ts +9 -2
- package/install-layout/dist/index.js +26 -9
- package/install-layout/dist/mcp-binding-contract.d.ts +91 -0
- package/install-layout/dist/mcp-binding-contract.js +230 -0
- package/install-layout/package.json +1 -1
- package/package.json +4 -4
- package/pd-cli/dist/commands/build-trajectory-evidence.d.ts.map +1 -1
- package/pd-cli/dist/commands/build-trajectory-evidence.js +17 -11
- package/pd-cli/dist/commands/build-trajectory-evidence.js.map +1 -1
- package/pd-cli/dist/commands/codex-reconcile.d.ts +7 -0
- package/pd-cli/dist/commands/codex-reconcile.d.ts.map +1 -1
- package/pd-cli/dist/commands/codex-reconcile.js +11 -2
- package/pd-cli/dist/commands/codex-reconcile.js.map +1 -1
- package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
- package/pd-cli/dist/commands/codex-worker.js +35 -0
- package/pd-cli/dist/commands/codex-worker.js.map +1 -1
- package/pd-cli/dist/commands/command-helpers.d.ts +1 -1
- package/pd-cli/dist/commands/command-helpers.js +1 -1
- package/pd-cli/dist/commands/errors-list.d.ts +1 -1
- package/pd-cli/dist/commands/errors-list.js +1 -1
- package/pd-cli/dist/commands/health-mcp.d.ts +23 -1
- package/pd-cli/dist/commands/health-mcp.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-mcp.js +81 -22
- package/pd-cli/dist/commands/health-mcp.js.map +1 -1
- package/pd-cli/dist/commands/health.d.ts +1 -1
- package/pd-cli/dist/commands/health.d.ts.map +1 -1
- package/pd-cli/dist/commands/health.js +12 -5
- package/pd-cli/dist/commands/health.js.map +1 -1
- package/pd-cli/dist/commands/principles-stats.d.ts +1 -1
- package/pd-cli/dist/commands/principles-stats.js +1 -1
- package/pd-cli/dist/commands/trajectory-retention.d.ts +23 -0
- package/pd-cli/dist/commands/trajectory-retention.d.ts.map +1 -0
- package/pd-cli/dist/commands/trajectory-retention.js +159 -0
- package/pd-cli/dist/commands/trajectory-retention.js.map +1 -0
- package/pd-cli/dist/commands/workbuddy-setup.d.ts +69 -0
- package/pd-cli/dist/commands/workbuddy-setup.d.ts.map +1 -0
- package/pd-cli/dist/commands/workbuddy-setup.js +379 -0
- package/pd-cli/dist/commands/workbuddy-setup.js.map +1 -0
- package/pd-cli/dist/commands/workbuddy-worker.d.ts.map +1 -1
- package/pd-cli/dist/commands/workbuddy-worker.js +42 -6
- package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
- package/pd-cli/dist/index.d.ts +1 -7
- package/pd-cli/dist/index.d.ts.map +1 -1
- package/pd-cli/dist/index.js +15 -1201
- package/pd-cli/dist/index.js.map +1 -1
- package/pd-cli/dist/program.d.ts +17 -0
- package/pd-cli/dist/program.d.ts.map +1 -0
- package/pd-cli/dist/program.js +1263 -0
- package/pd-cli/dist/program.js.map +1 -0
- package/pd-cli/dist/services/delivery-surfaces.d.ts.map +1 -1
- package/pd-cli/dist/services/delivery-surfaces.js +7 -5
- package/pd-cli/dist/services/delivery-surfaces.js.map +1 -1
- package/pd-cli/dist/services/version-report.d.ts.map +1 -1
- package/pd-cli/dist/services/version-report.js +30 -4
- package/pd-cli/dist/services/version-report.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/pd-mcp-server/dist/version.d.ts +1 -1
- package/pd-mcp-server/dist/version.js +1 -1
- package/pd-mcp-server/package.json +3 -1
- package/plugin/dist/bundle.js +544 -494
- package/plugin/dist/constants/tools.d.ts +8 -1
- package/plugin/dist/core/trajectory-retention-trigger.d.ts +13 -0
- package/plugin/dist/core/trajectory.d.ts +14 -0
- package/plugin/dist/hooks/gate-block-helper.d.ts +17 -0
- package/plugin/dist/hooks/gate.d.ts +6 -1
- package/plugin/dist/host-runtime/openclaw-host-runtime.d.ts +1 -0
- package/plugin/dist/index.d.ts +5 -0
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/dist/rulehost-evidence.js +29 -23
- package/plugin/dist/templates/langs/en/skills/pd-cli-operator/SKILL.md +16 -5
- package/plugin/dist/templates/langs/en/skills/pd-control/SKILL.md +7 -6
- package/plugin/dist/templates/langs/en/skills/pd-pain-signal/SKILL.md +141 -28
- package/plugin/dist/templates/langs/en/skills/pd-review/SKILL.md +15 -1
- package/plugin/dist/templates/langs/zh/skills/pd-cli-operator/SKILL.md +16 -5
- package/plugin/dist/templates/langs/zh/skills/pd-control/SKILL.md +7 -6
- package/plugin/dist/templates/langs/zh/skills/pd-pain-signal/SKILL.md +142 -29
- package/plugin/dist/templates/langs/zh/skills/pd-review/SKILL.md +15 -1
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/plugin/templates/langs/en/skills/pd-cli-operator/SKILL.md +16 -5
- package/plugin/templates/langs/en/skills/pd-control/SKILL.md +7 -6
- package/plugin/templates/langs/en/skills/pd-pain-signal/SKILL.md +141 -28
- package/plugin/templates/langs/en/skills/pd-review/SKILL.md +15 -1
- package/plugin/templates/langs/zh/skills/pd-cli-operator/SKILL.md +16 -5
- package/plugin/templates/langs/zh/skills/pd-control/SKILL.md +7 -6
- package/plugin/templates/langs/zh/skills/pd-pain-signal/SKILL.md +142 -29
- package/plugin/templates/langs/zh/skills/pd-review/SKILL.md +15 -1
- package/release-manager/dist/installers/codex-host-installer.js +92 -5
- package/release-manager/dist/installers/mcp-binding-shape-mirror.js +105 -0
- package/release-manager/package.json +1 -1
- package/workbuddy-adapter/dist/codec/input-decoder.d.ts +10 -0
- package/workbuddy-adapter/dist/codec/input-decoder.js +62 -5
- package/workbuddy-adapter/dist/host-adapter.js +1 -0
- package/workbuddy-adapter/dist/index.d.ts +1 -0
- package/workbuddy-adapter/dist/index.js +1 -0
- package/workbuddy-adapter/dist/ingestion/catch-up.d.ts +25 -0
- package/workbuddy-adapter/dist/ingestion/catch-up.js +161 -0
- package/workbuddy-adapter/dist/ingestion/encode-cwd.d.ts +6 -0
- package/workbuddy-adapter/dist/ingestion/encode-cwd.js +39 -0
- package/workbuddy-adapter/dist/ingestion/index.d.ts +13 -0
- package/workbuddy-adapter/dist/ingestion/index.js +13 -0
- package/workbuddy-adapter/dist/ingestion/ingestion.d.ts +46 -0
- package/workbuddy-adapter/dist/ingestion/ingestion.js +135 -0
- package/workbuddy-adapter/dist/ingestion/transcript-decoder.d.ts +70 -0
- package/workbuddy-adapter/dist/ingestion/transcript-decoder.js +554 -0
- package/workbuddy-adapter/dist/ingestion/transcript-path.d.ts +39 -0
- package/workbuddy-adapter/dist/ingestion/transcript-path.js +117 -0
- package/workbuddy-adapter/dist/ingestion/transcript-source.d.ts +15 -0
- package/workbuddy-adapter/dist/ingestion/transcript-source.js +152 -0
- package/workbuddy-adapter/dist/pd-hook.d.ts +8 -0
- package/workbuddy-adapter/dist/pd-hook.js +59 -2
- package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +9 -0
- package/workbuddy-adapter/dist/worker/workspace-worker.js +46 -17
- package/workbuddy-adapter/package.json +1 -1
- package/workbuddy-adapter/plugin/hooks/hooks.json +11 -0
- package/workbuddy-adapter/plugin/skills/pd-cli-operator/SKILL.md +57 -19
- package/workbuddy-adapter/plugin/skills/pd-control/SKILL.md +21 -9
- package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +72 -61
- package/workbuddy-adapter/plugin/skills/pd-review/SKILL.md +27 -12
|
@@ -11,24 +11,36 @@
|
|
|
11
11
|
* second check would be a second source of truth for the same switch);
|
|
12
12
|
* - the host did not bind the current turn (`sessionId`/`turnId`) or the
|
|
13
13
|
* prompt body is blank;
|
|
14
|
-
* - the remaining hook budget cannot cover
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* - the remaining hook budget cannot cover the request's own MINIMUM executable
|
|
15
|
+
* envelope (see `minExecutableBudgetMs`) — a fast Decisions request that can
|
|
16
|
+
* still finish is never skipped just because it is under an old slow-path
|
|
17
|
+
* line;
|
|
18
|
+
* - the prompt is a pure social acknowledgement ("谢谢", "收到", "ok").
|
|
17
19
|
*
|
|
18
|
-
* Everything else — including short instructions and task
|
|
19
|
-
* keeps the
|
|
20
|
-
* acknowledgement vocabulary below, never by length alone: "继续"
|
|
21
|
-
* "
|
|
20
|
+
* Everything else — including short instructions, approvals and task
|
|
21
|
+
* continuations — keeps the fast single-send selection. "Simple" is decided by
|
|
22
|
+
* the acknowledgement vocabulary below, never by length alone: "继续", "执行一下"
|
|
23
|
+
* and "确认" look short but can approve or advance a stage.
|
|
22
24
|
*/
|
|
23
25
|
export declare const ADAPTIVE_SKIP_LIMITS: {
|
|
24
26
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* Smallest remaining budget worth one Decisions send.
|
|
28
|
+
*
|
|
29
|
+
* PRI-1181 used the measured slow-path time-to-first-byte (789–1426 ms) as a
|
|
30
|
+
* 1500 ms admission line. That line skipped requests that were executable:
|
|
31
|
+
* the Decisions endpoint answers a small answer table well inside a
|
|
32
|
+
* sub-second window, and a skip is permanent for the turn.
|
|
33
|
+
*
|
|
34
|
+
* This is an ADMISSION line, not a wait allowance: it answers "may a fast
|
|
35
|
+
* request start at all with this much host budget left?" A request that is
|
|
36
|
+
* admitted is still bounded by the earlier of its own deadline and the host
|
|
37
|
+
* deadline minus the assembly/output reserve; both cancel the underlying
|
|
38
|
+
* request. So the number below must stay far below any selection wait.
|
|
39
|
+
*
|
|
40
|
+
* The gate is the request's own floor — the output reserve plus one
|
|
41
|
+
* bounded round trip — not the slow path's observed maximum.
|
|
30
42
|
*/
|
|
31
|
-
readonly
|
|
43
|
+
readonly minExecutableBudgetMs: 300;
|
|
32
44
|
/** Longest acknowledgement (after normalization) still treated as pure social. */
|
|
33
45
|
readonly maxConfirmationChars: 12;
|
|
34
46
|
};
|
|
@@ -46,7 +58,7 @@ export interface AdaptiveSkipInput {
|
|
|
46
58
|
readonly prompt: string;
|
|
47
59
|
/** Undefined = no outer host deadline (direct/lab calls): never budget-skip. */
|
|
48
60
|
readonly remainingBudgetMs?: number | undefined;
|
|
49
|
-
readonly
|
|
61
|
+
readonly minExecutableBudgetMs?: number | undefined;
|
|
50
62
|
}
|
|
51
63
|
export type AdaptiveSkipDecision = {
|
|
52
64
|
readonly skip: false;
|
|
@@ -11,62 +11,66 @@
|
|
|
11
11
|
* second check would be a second source of truth for the same switch);
|
|
12
12
|
* - the host did not bind the current turn (`sessionId`/`turnId`) or the
|
|
13
13
|
* prompt body is blank;
|
|
14
|
-
* - the remaining hook budget cannot cover
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* - the remaining hook budget cannot cover the request's own MINIMUM executable
|
|
15
|
+
* envelope (see `minExecutableBudgetMs`) — a fast Decisions request that can
|
|
16
|
+
* still finish is never skipped just because it is under an old slow-path
|
|
17
|
+
* line;
|
|
18
|
+
* - the prompt is a pure social acknowledgement ("谢谢", "收到", "ok").
|
|
17
19
|
*
|
|
18
|
-
* Everything else — including short instructions and task
|
|
19
|
-
* keeps the
|
|
20
|
-
* acknowledgement vocabulary below, never by length alone: "继续"
|
|
21
|
-
* "
|
|
20
|
+
* Everything else — including short instructions, approvals and task
|
|
21
|
+
* continuations — keeps the fast single-send selection. "Simple" is decided by
|
|
22
|
+
* the acknowledgement vocabulary below, never by length alone: "继续", "执行一下"
|
|
23
|
+
* and "确认" look short but can approve or advance a stage.
|
|
22
24
|
*/
|
|
23
25
|
export const ADAPTIVE_SKIP_LIMITS = {
|
|
24
26
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* Smallest remaining budget worth one Decisions send.
|
|
28
|
+
*
|
|
29
|
+
* PRI-1181 used the measured slow-path time-to-first-byte (789–1426 ms) as a
|
|
30
|
+
* 1500 ms admission line. That line skipped requests that were executable:
|
|
31
|
+
* the Decisions endpoint answers a small answer table well inside a
|
|
32
|
+
* sub-second window, and a skip is permanent for the turn.
|
|
33
|
+
*
|
|
34
|
+
* This is an ADMISSION line, not a wait allowance: it answers "may a fast
|
|
35
|
+
* request start at all with this much host budget left?" A request that is
|
|
36
|
+
* admitted is still bounded by the earlier of its own deadline and the host
|
|
37
|
+
* deadline minus the assembly/output reserve; both cancel the underlying
|
|
38
|
+
* request. So the number below must stay far below any selection wait.
|
|
39
|
+
*
|
|
40
|
+
* The gate is the request's own floor — the output reserve plus one
|
|
41
|
+
* bounded round trip — not the slow path's observed maximum.
|
|
30
42
|
*/
|
|
31
|
-
|
|
43
|
+
minExecutableBudgetMs: 300,
|
|
32
44
|
/** Longest acknowledgement (after normalization) still treated as pure social. */
|
|
33
45
|
maxConfirmationChars: 12,
|
|
34
46
|
};
|
|
35
47
|
/**
|
|
36
48
|
* Acknowledgements, longest first so the greedy removal below never leaves a
|
|
37
49
|
* fragment behind ("明白了" must be consumed before "明白").
|
|
38
|
-
*
|
|
50
|
+
*
|
|
51
|
+
* Scope is deliberately PURE SOCIAL: gratitude and receipt-of-message only.
|
|
52
|
+
* Approval words that can answer a pending question are excluded — "确认",
|
|
53
|
+
* "可以", "好的", "行", "ok", "yes" must all reach the decision endpoint,
|
|
54
|
+
* because "要不要提交最终版?→ 确认" is a real stage change, not social noise.
|
|
39
55
|
*/
|
|
40
56
|
const ACKNOWLEDGEMENTS = [
|
|
41
57
|
'thankyouverymuch',
|
|
42
58
|
'thanksalot',
|
|
43
|
-
'soundsgood',
|
|
44
59
|
'thankyou',
|
|
45
|
-
'gotit',
|
|
46
|
-
'好的好的',
|
|
47
60
|
'明白了',
|
|
48
61
|
'收到啦',
|
|
49
62
|
'辛苦了',
|
|
50
|
-
'没问题',
|
|
51
|
-
'好的',
|
|
52
|
-
'好嘞',
|
|
53
63
|
'谢谢',
|
|
54
64
|
'多谢',
|
|
65
|
+
'感谢',
|
|
55
66
|
'收到',
|
|
56
67
|
'明白',
|
|
57
|
-
'可以',
|
|
58
|
-
'确认',
|
|
59
68
|
'了解',
|
|
60
69
|
'嗯嗯',
|
|
61
|
-
'okay',
|
|
62
70
|
'thanks',
|
|
63
71
|
'thank',
|
|
64
|
-
'
|
|
65
|
-
'yes',
|
|
66
|
-
'ok',
|
|
72
|
+
'gotit',
|
|
67
73
|
'嗯',
|
|
68
|
-
'好',
|
|
69
|
-
'行',
|
|
70
74
|
];
|
|
71
75
|
/** Strip whitespace, punctuation and emoji-ish separators before matching. */
|
|
72
76
|
function normalize(prompt) {
|
|
@@ -104,7 +108,7 @@ export function decideAdaptiveSkip(input) {
|
|
|
104
108
|
return { skip: true, reason: 'missing_identity' };
|
|
105
109
|
if (!input.prompt.trim())
|
|
106
110
|
return { skip: true, reason: 'empty_prompt' };
|
|
107
|
-
const minimum = input.
|
|
111
|
+
const minimum = input.minExecutableBudgetMs ?? ADAPTIVE_SKIP_LIMITS.minExecutableBudgetMs;
|
|
108
112
|
if (input.remainingBudgetMs !== undefined && input.remainingBudgetMs < minimum) {
|
|
109
113
|
return { skip: true, reason: 'budget_insufficient' };
|
|
110
114
|
}
|
|
@@ -94,7 +94,10 @@ export function createCodexRuleContextProvider(options) {
|
|
|
94
94
|
projectWorkspacePath: projectDir,
|
|
95
95
|
hostSessionId: request.sessionId,
|
|
96
96
|
targetPath: targetKind === 'execute' ? projectDir : request.targetPath,
|
|
97
|
-
|
|
97
|
+
// ADR-0030: the payload parser is selected by the DECLARED encoding, not
|
|
98
|
+
// by a raw tool-name literal — an alias declared with the same format
|
|
99
|
+
// parses identically with no code change.
|
|
100
|
+
...(targetKind === 'write' && options.toolSemantics.resolveWritePayloadFormat(request.toolName) === 'file-header-patch'
|
|
98
101
|
? { targetPaths: patchTargets(rawParams, projectDir) ?? [] }
|
|
99
102
|
: {}),
|
|
100
103
|
...(targetKind === 'execute' ? { projectScopedExecution: true } : {}),
|
|
@@ -5,7 +5,14 @@ export declare const GOVERNANCE_PROMOTION_PRECEDING_TURNS = 12;
|
|
|
5
5
|
export declare const GOVERNANCE_PENDING_TAIL_STALE_MS: number;
|
|
6
6
|
/** Host taxonomy for governance observations (schema v4; PRI-1171 unification). */
|
|
7
7
|
export type GovernanceObservationHostKind = 'codex' | 'workbuddy' | 'openclaw';
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* PRI-1171 P2: `reasoning` joins the kind union with the WorkBuddy decoder
|
|
10
|
+
* (tech design §5.2) — the first producer. The Codex decoder keeps its
|
|
11
|
+
* explicit reasoning discard until P3 ticket ⑧ wires the new disclosure +
|
|
12
|
+
* consent records for the Codex full tier (tech design §11.8), so no
|
|
13
|
+
* existing Codex path starts emitting it.
|
|
14
|
+
*/
|
|
15
|
+
export type GovernanceObservationKind = 'user_turn' | 'assistant_turn' | 'tool_call' | 'reasoning';
|
|
9
16
|
export type GovernanceObservationSource = 'live_hook' | 'transcript';
|
|
10
17
|
export type GovernanceObservationCompleteness = 'complete' | 'partial';
|
|
11
18
|
/** `quarantined` (Slice D §15): audited, permanently-invalid row; bodies dropped, metadata kept. */
|
|
@@ -158,6 +165,15 @@ export interface IngestGovernanceObservationsInput {
|
|
|
158
165
|
readonly now?: Date;
|
|
159
166
|
readonly databaseFactory?: ObservationDatabaseFactory;
|
|
160
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Persist one decoded delta (observations + rollout lineage + checkpoint) in a
|
|
170
|
+
* single IMMEDIATE transaction.
|
|
171
|
+
*
|
|
172
|
+
* The up-front write lock is required: with a deferred BEGIN two concurrent
|
|
173
|
+
* hooks both read and then race the upgrade, and SQLite fails that upgrade
|
|
174
|
+
* with SQLITE_BUSY. A failure rolls everything back (checkpoint not advanced)
|
|
175
|
+
* and returns a structured reason/nextAction; warnings stay observable.
|
|
176
|
+
*/
|
|
161
177
|
export declare function ingestGovernanceObservations(input: IngestGovernanceObservationsInput): IngestGovernanceObservationsResult;
|
|
162
178
|
export interface ReadGovernanceCheckpointArgs {
|
|
163
179
|
readonly workspaceDir: string;
|
|
@@ -166,6 +182,29 @@ export interface ReadGovernanceCheckpointArgs {
|
|
|
166
182
|
readonly databaseFactory?: ObservationDatabaseFactory;
|
|
167
183
|
}
|
|
168
184
|
export declare function readGovernanceCheckpoint(args: ReadGovernanceCheckpointArgs): GovernanceCheckpointRecord | null | Degradation;
|
|
185
|
+
export interface DeferGovernanceCheckpointArgs {
|
|
186
|
+
readonly workspaceDir: string;
|
|
187
|
+
readonly hostKind: GovernanceObservationHostKind;
|
|
188
|
+
readonly rolloutIdentity: string;
|
|
189
|
+
readonly reason: string;
|
|
190
|
+
readonly now: string;
|
|
191
|
+
readonly databaseFactory?: ObservationDatabaseFactory;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Move a checkpoint to the BACK of the oldest-first retry queue without
|
|
195
|
+
* touching its water mark (P2 review).
|
|
196
|
+
*
|
|
197
|
+
* `listGovernanceCheckpoints` returns the oldest-updated rows first and the
|
|
198
|
+
* catch-up worker processes a bounded prefix. A rollout whose transcript is
|
|
199
|
+
* missing/unreadable never advances its checkpoint, so it would occupy the
|
|
200
|
+
* prefix forever and starve every rollout behind it. Bumping ONLY
|
|
201
|
+
* `updated_at` + the degradation reason lets the failed session yield its slot
|
|
202
|
+
* on the next cycle while keeping its byte offset, ordinal and retryability
|
|
203
|
+
* exactly as they were.
|
|
204
|
+
*/
|
|
205
|
+
export declare function deferGovernanceCheckpoint(args: DeferGovernanceCheckpointArgs): {
|
|
206
|
+
ok: true;
|
|
207
|
+
} | Degradation;
|
|
169
208
|
export interface ListGovernanceCheckpointsArgs {
|
|
170
209
|
readonly workspaceDir: string;
|
|
171
210
|
readonly hostKind: GovernanceObservationHostKind;
|
|
@@ -77,6 +77,38 @@ function safeJson(value) {
|
|
|
77
77
|
return null;
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Merge a LATER window's tool facts onto an already-committed PARTIAL tool_call
|
|
82
|
+
* row. A host may split one execution across windows (WorkBuddy keys call and
|
|
83
|
+
* result by callId, each decode window is byte-bounded), so the result arrives
|
|
84
|
+
* as a second observation with the same logical key. `fill` alone would drop
|
|
85
|
+
* the result preview because the call's facts column is already non-null.
|
|
86
|
+
* Only two well-formed `facts` envelopes are merged; anything else returns
|
|
87
|
+
* null so the caller can keep the existing `fill` behaviour.
|
|
88
|
+
*/
|
|
89
|
+
function mergeToolFactsJson(existingJson, incomingJson) {
|
|
90
|
+
if (typeof existingJson !== 'string' || incomingJson === null)
|
|
91
|
+
return null;
|
|
92
|
+
try {
|
|
93
|
+
const existing = JSON.parse(existingJson);
|
|
94
|
+
const incoming = JSON.parse(incomingJson);
|
|
95
|
+
if (!isRecord(existing) || !isRecord(incoming))
|
|
96
|
+
return null;
|
|
97
|
+
const existingFacts = existing.facts;
|
|
98
|
+
const incomingFacts = incoming.facts;
|
|
99
|
+
if (!isRecord(existingFacts) || !isRecord(incomingFacts))
|
|
100
|
+
return null;
|
|
101
|
+
const merged = { ...existingFacts };
|
|
102
|
+
for (const [key, value] of Object.entries(incomingFacts)) {
|
|
103
|
+
if (value !== null && value !== undefined)
|
|
104
|
+
merged[key] = value;
|
|
105
|
+
}
|
|
106
|
+
return safeJson({ facts: merged });
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
80
112
|
const CREATE_STATEMENTS = [
|
|
81
113
|
`CREATE TABLE IF NOT EXISTS governance_observation_schema_version (version INTEGER NOT NULL)`,
|
|
82
114
|
`CREATE TABLE IF NOT EXISTS governance_rollouts (
|
|
@@ -201,20 +233,50 @@ function ensureGovernanceObservationSchema(db) {
|
|
|
201
233
|
export function ensureGovernanceSchema(db) {
|
|
202
234
|
ensureGovernanceObservationSchema(db);
|
|
203
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Open the workspace trajectory database for governance observations.
|
|
238
|
+
*
|
|
239
|
+
* Returns a {@link Degradation} when the database file is absent or cannot be
|
|
240
|
+
* opened. Non-fatal degradations (journal_mode switch losing a race) are
|
|
241
|
+
* reported through `warnings` instead of failing the write (rc-9).
|
|
242
|
+
*/
|
|
204
243
|
function openStore(workspaceDir, factory) {
|
|
205
244
|
const dbPath = path.join(workspaceDir, '.state', 'trajectory.db');
|
|
206
245
|
if (!fs.existsSync(dbPath)) {
|
|
207
246
|
return { ok: false, reason: 'trajectory_db_not_found', nextAction: 'initialize the selected PD workspace (pd runtime init) before enabling conversation ingestion' };
|
|
208
247
|
}
|
|
248
|
+
const warnings = [];
|
|
209
249
|
try {
|
|
210
250
|
const db = factory ? factory(dbPath) : new Database(dbPath);
|
|
211
251
|
db.pragma('busy_timeout = 5000');
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
252
|
+
// Switching journal_mode takes an exclusive lock, and SQLITE_BUSY on this
|
|
253
|
+
// pragma is NOT covered by busy_timeout. Two hooks that start at the same
|
|
254
|
+
// moment can collide here; neither the mode nor the data is corrupted, and
|
|
255
|
+
// whoever wins performs the switch. Read the mode first (lock-free) and
|
|
256
|
+
// never fail ingestion just because this optimization lost the race.
|
|
257
|
+
//
|
|
258
|
+
// Deliberate choice: NO retry. The losing opener keeps the previous
|
|
259
|
+
// rollback-journal mode for THIS connection only. WAL is a concurrency
|
|
260
|
+
// optimization, not a correctness requirement — writes already run under
|
|
261
|
+
// BEGIN IMMEDIATE with busy_timeout, so isolation and durability are
|
|
262
|
+
// unchanged; the winner's switch is persisted for every later open. The
|
|
263
|
+
// fallback is reported (rc-9: never silent) through `warnings`.
|
|
264
|
+
try {
|
|
265
|
+
const journalMode = db.pragma('journal_mode', { simple: true });
|
|
266
|
+
if (typeof journalMode !== 'string' || journalMode.toLowerCase() !== 'wal') {
|
|
267
|
+
db.pragma('journal_mode = WAL');
|
|
216
268
|
}
|
|
217
|
-
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
warnings.push('journal_mode_switch_deferred');
|
|
272
|
+
}
|
|
273
|
+
ensureGovernanceObservationSchema(db);
|
|
274
|
+
/** Close the connection; a close failure must not mask the already-determined write result. */
|
|
275
|
+
const close = () => { try {
|
|
276
|
+
db.close();
|
|
277
|
+
}
|
|
278
|
+
catch { /* write result already determined */ } };
|
|
279
|
+
return { db, close, warnings };
|
|
218
280
|
}
|
|
219
281
|
catch (error) {
|
|
220
282
|
const detail = error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200);
|
|
@@ -236,8 +298,35 @@ function upsertRollout(db, input, now) {
|
|
|
236
298
|
.run(input.hostKind, input.rolloutIdentity, input.rootSessionId, input.parentRolloutIdentity ?? null, boundedString(input.agentIdentity, MAX_TEXT_BOUND), input.agentDepth ?? null, now, now);
|
|
237
299
|
return Number(result.lastInsertRowid);
|
|
238
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Apply one observation against its logical key and report what happened.
|
|
303
|
+
*
|
|
304
|
+
* - `inserted`: new key (a duplicate physical record is reported separately);
|
|
305
|
+
* - `enriched`: the existing row gained identity/ordering/completion facts;
|
|
306
|
+
* - `duplicate`: replay produced nothing new;
|
|
307
|
+
* - `conflict`: a user utterance disagrees for the same key — keep the first
|
|
308
|
+
* committed content, mark partial, and report where the checkpoint must stop.
|
|
309
|
+
* Never overwrites committed content silently (source precedence, SPEC §10).
|
|
310
|
+
*/
|
|
239
311
|
function applyObservation({ db, rolloutRowId, input, workspaceDir }) {
|
|
240
|
-
const
|
|
312
|
+
const byKey = db.prepare('SELECT * FROM governance_observations WHERE logical_key = ?').get(input.logicalObservationKey);
|
|
313
|
+
let existing = byKey;
|
|
314
|
+
// Cross-window tool completion by STABLE identity (P2 review): the call row
|
|
315
|
+
// is keyed by its transcript record, so a later window's result cannot derive
|
|
316
|
+
// the same logical key. Reconnect it to the single still-partial call row
|
|
317
|
+
// that carries the same `tool_use_id`. `LIMIT 2` makes ambiguity explicit:
|
|
318
|
+
// duplicate callIds across windows yield two candidates and are NOT merged.
|
|
319
|
+
if (!isRecord(byKey)
|
|
320
|
+
&& input.kind === 'tool_call'
|
|
321
|
+
&& input.completeness === 'complete'
|
|
322
|
+
&& typeof input.toolUseId === 'string'
|
|
323
|
+
&& input.toolUseId.length > 0) {
|
|
324
|
+
const partials = db.prepare(`SELECT * FROM governance_observations
|
|
325
|
+
WHERE rollout_row_id = ? AND kind = 'tool_call' AND completeness = 'partial' AND tool_use_id = ?
|
|
326
|
+
LIMIT 2`).all(rolloutRowId, input.toolUseId);
|
|
327
|
+
if (partials.length === 1)
|
|
328
|
+
[existing] = partials;
|
|
329
|
+
}
|
|
241
330
|
if (!isRecord(existing)) {
|
|
242
331
|
// Physical replay guard: the same transcript record decoded twice (crash
|
|
243
332
|
// before checkpoint, or a re-invoked hook) must not contribute twice.
|
|
@@ -270,8 +359,25 @@ function applyObservation({ db, rolloutRowId, input, workspaceDir }) {
|
|
|
270
359
|
db.prepare("UPDATE governance_observations SET completeness = 'partial' WHERE id = ?").run(existingId);
|
|
271
360
|
return { disposition: 'conflict', stopByteStart: input.recordByteStart };
|
|
272
361
|
}
|
|
362
|
+
// Two DISTINCT executions reusing one callId in DIFFERENT decode windows
|
|
363
|
+
// share the `call:<callId>` logical key. Without this guard the second
|
|
364
|
+
// call's partial observation is silently absorbed into the first (fill and
|
|
365
|
+
// fact-merge never overwrite committed fields), so an execution disappears.
|
|
366
|
+
// A different transcript record is a lineage conflict: keep the first, mark
|
|
367
|
+
// it partial, and stop at the offending record (P2 review).
|
|
368
|
+
const existingRecordKey = rowField(existing, 'transcript_record_key');
|
|
369
|
+
if (input.kind === 'tool_call'
|
|
370
|
+
&& input.completeness === 'partial'
|
|
371
|
+
&& typeof existingRecordKey === 'string'
|
|
372
|
+
&& existingRecordKey.length > 0
|
|
373
|
+
&& input.transcriptRecordKey !== undefined
|
|
374
|
+
&& existingRecordKey !== input.transcriptRecordKey) {
|
|
375
|
+
db.prepare("UPDATE governance_observations SET completeness = 'partial' WHERE id = ?").run(existingId);
|
|
376
|
+
return { disposition: 'conflict', stopByteStart: input.recordByteStart };
|
|
377
|
+
}
|
|
273
378
|
const updates = [];
|
|
274
379
|
const values = [];
|
|
380
|
+
/** Queue a column only when the stored value is still absent (never overwrite committed content). */
|
|
275
381
|
const fill = (column, value) => {
|
|
276
382
|
const current = rowField(existing, column);
|
|
277
383
|
if ((current === null || current === undefined) && value !== null && value !== undefined) {
|
|
@@ -290,7 +396,33 @@ function applyObservation({ db, rolloutRowId, input, workspaceDir }) {
|
|
|
290
396
|
fill('tool_use_id', boundedString(input.toolUseId, MAX_TEXT_BOUND));
|
|
291
397
|
fill('transcript_tool_call_id', boundedString(input.transcriptToolCallId, MAX_TEXT_BOUND));
|
|
292
398
|
fill('visible_text', input.visibleText !== undefined ? sanitizeString(input.visibleText, workspaceDir) : null);
|
|
293
|
-
|
|
399
|
+
const incomingFacts = input.toolFacts !== undefined ? safeJson({ facts: sanitizeValue(input.toolFacts, 0, workspaceDir) }) : null;
|
|
400
|
+
// Cross-window tool completion (P1): the call row is partial and the result
|
|
401
|
+
// arrives under the same logical key from a later decode window. Merge the
|
|
402
|
+
// result facts instead of dropping them through `fill`'s null-only rule.
|
|
403
|
+
const crossWindowToolCompletion = input.kind === 'tool_call'
|
|
404
|
+
&& input.completeness === 'complete'
|
|
405
|
+
&& rowField(existing, 'completeness') === 'partial';
|
|
406
|
+
if (crossWindowToolCompletion) {
|
|
407
|
+
const existingFactsJson = rowField(existing, 'sanitized_tool_facts_json');
|
|
408
|
+
const mergedFacts = mergeToolFactsJson(existingFactsJson, incomingFacts);
|
|
409
|
+
// Fall back to the incoming facts ONLY when the row has none AND is still
|
|
410
|
+
// active. An existing but unmergeable value is a bounded truncation
|
|
411
|
+
// preview that is still committed evidence; replacing it would destroy
|
|
412
|
+
// what the advanced checkpoint can no longer recover. A terminal retention
|
|
413
|
+
// class (expired / quarantined) must not regain a body either (P2 review).
|
|
414
|
+
const hasExistingFacts = typeof existingFactsJson === 'string' && existingFactsJson.length > 0;
|
|
415
|
+
const retentionClass = rowField(existing, 'retention_class');
|
|
416
|
+
const activeRow = retentionClass === 'operational' || retentionClass === 'promoted';
|
|
417
|
+
const nextFacts = mergedFacts ?? (hasExistingFacts || !activeRow ? null : incomingFacts);
|
|
418
|
+
if (nextFacts !== null && nextFacts !== rowField(existing, 'sanitized_tool_facts_json')) {
|
|
419
|
+
updates.push('sanitized_tool_facts_json = ?');
|
|
420
|
+
values.push(nextFacts);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
fill('sanitized_tool_facts_json', incomingFacts);
|
|
425
|
+
}
|
|
294
426
|
const existingCompleteness = rowField(existing, 'completeness');
|
|
295
427
|
if (existingCompleteness === 'partial' && input.completeness === 'complete') {
|
|
296
428
|
updates.push('completeness = ?');
|
|
@@ -384,19 +516,33 @@ function expireStalePendingTails(db, now) {
|
|
|
384
516
|
db.prepare("UPDATE governance_pending_promotion_tails SET state = 'stale', stale_at = ? WHERE state = 'pending' AND created_at < ?")
|
|
385
517
|
.run(now.toISOString(), new Date(now.getTime() - GOVERNANCE_PENDING_TAIL_STALE_MS).toISOString());
|
|
386
518
|
}
|
|
519
|
+
/**
|
|
520
|
+
* Persist one decoded delta (observations + rollout lineage + checkpoint) in a
|
|
521
|
+
* single IMMEDIATE transaction.
|
|
522
|
+
*
|
|
523
|
+
* The up-front write lock is required: with a deferred BEGIN two concurrent
|
|
524
|
+
* hooks both read and then race the upgrade, and SQLite fails that upgrade
|
|
525
|
+
* with SQLITE_BUSY. A failure rolls everything back (checkpoint not advanced)
|
|
526
|
+
* and returns a structured reason/nextAction; warnings stay observable.
|
|
527
|
+
*/
|
|
387
528
|
export function ingestGovernanceObservations(input) {
|
|
388
529
|
const opened = openStore(input.workspaceDir, input.databaseFactory);
|
|
389
530
|
if (!('db' in opened))
|
|
390
531
|
return { ok: false, reason: opened.reason, nextAction: opened.nextAction, inserted: 0, enriched: 0, duplicates: 0, checkpointCommitted: false, warnings: [] };
|
|
391
532
|
const { db, close } = opened;
|
|
392
533
|
const now = (input.now ?? new Date()).toISOString();
|
|
393
|
-
const warnings = [];
|
|
534
|
+
const warnings = [...opened.warnings];
|
|
394
535
|
try {
|
|
395
536
|
let inserted = 0;
|
|
396
537
|
let enriched = 0;
|
|
397
538
|
let duplicates = 0;
|
|
398
539
|
let conflictStop;
|
|
399
540
|
let conflictKey = '';
|
|
541
|
+
// `.immediate()` takes the write lock up front. With the default deferred
|
|
542
|
+
// BEGIN, two concurrent Stop hooks for the same session both read first
|
|
543
|
+
// and then try to upgrade; SQLite fails that upgrade with SQLITE_BUSY
|
|
544
|
+
// immediately (busy_timeout does not cover upgrade deadlocks), which the
|
|
545
|
+
// hook surfaces as `governance_write_failed:database is locked`.
|
|
400
546
|
const result = db.transaction(() => {
|
|
401
547
|
let rolloutRowId = null;
|
|
402
548
|
if (input.rollout !== undefined) {
|
|
@@ -482,7 +628,7 @@ export function ingestGovernanceObservations(input) {
|
|
|
482
628
|
expireStalePendingTails(db, new Date(now));
|
|
483
629
|
pruneRetention(db, rolloutRowId, new Date(now));
|
|
484
630
|
return 'committed';
|
|
485
|
-
})();
|
|
631
|
+
}).immediate();
|
|
486
632
|
if (result === 'conflict') {
|
|
487
633
|
return {
|
|
488
634
|
ok: false, reason: 'logical_key_content_conflict', nextAction: 'the first committed content was preserved and the observation is marked partial; run `pd codex ingest quarantine --workspace <path> --rollout <id> --record <id>` (audited, dry-run default) or re-ingest from a fresh rollout',
|
|
@@ -526,6 +672,39 @@ export function readGovernanceCheckpoint(args) {
|
|
|
526
672
|
close();
|
|
527
673
|
}
|
|
528
674
|
}
|
|
675
|
+
/**
|
|
676
|
+
* Move a checkpoint to the BACK of the oldest-first retry queue without
|
|
677
|
+
* touching its water mark (P2 review).
|
|
678
|
+
*
|
|
679
|
+
* `listGovernanceCheckpoints` returns the oldest-updated rows first and the
|
|
680
|
+
* catch-up worker processes a bounded prefix. A rollout whose transcript is
|
|
681
|
+
* missing/unreadable never advances its checkpoint, so it would occupy the
|
|
682
|
+
* prefix forever and starve every rollout behind it. Bumping ONLY
|
|
683
|
+
* `updated_at` + the degradation reason lets the failed session yield its slot
|
|
684
|
+
* on the next cycle while keeping its byte offset, ordinal and retryability
|
|
685
|
+
* exactly as they were.
|
|
686
|
+
*/
|
|
687
|
+
export function deferGovernanceCheckpoint(args) {
|
|
688
|
+
const { workspaceDir, hostKind, rolloutIdentity, reason, now, databaseFactory } = args;
|
|
689
|
+
const opened = openStore(workspaceDir, databaseFactory);
|
|
690
|
+
if (!('db' in opened))
|
|
691
|
+
return opened;
|
|
692
|
+
const { db, close } = opened;
|
|
693
|
+
try {
|
|
694
|
+
db.prepare(`UPDATE governance_transcript_checkpoints
|
|
695
|
+
SET updated_at = ?, last_degradation_reason = ?
|
|
696
|
+
WHERE host_kind = ? AND rollout_identity = ?`)
|
|
697
|
+
.run(now, reason.slice(0, 200), hostKind, rolloutIdentity);
|
|
698
|
+
return { ok: true };
|
|
699
|
+
}
|
|
700
|
+
catch (error) {
|
|
701
|
+
const detail = error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200);
|
|
702
|
+
return { ok: false, reason: `governance_write_failed:${detail}`, nextAction: 'inspect the workspace trajectory database and retry; nothing was partially committed' };
|
|
703
|
+
}
|
|
704
|
+
finally {
|
|
705
|
+
close();
|
|
706
|
+
}
|
|
707
|
+
}
|
|
529
708
|
/**
|
|
530
709
|
* List every checkpoint for a host kind, oldest-updated first (PRI-624).
|
|
531
710
|
* The Slice C worker/CLI catch-up uses this to find rollouts with pending
|
|
@@ -340,7 +340,16 @@ export interface EnsureGovernanceContinuationInput {
|
|
|
340
340
|
readonly logicalObservationKey: string;
|
|
341
341
|
readonly canonicalPainId: string;
|
|
342
342
|
/** Current Owner consent for Codex conversation evidence. Required to prevent reconciliation from promoting old observations after opt-out. */
|
|
343
|
-
readonly
|
|
343
|
+
readonly codexConversationIngestionEnabled: boolean;
|
|
344
|
+
/**
|
|
345
|
+
* Legacy alias from before the host-scoped rename. It means the SAME thing as
|
|
346
|
+
* the field above — Codex conversation-evidence consent only, never consent
|
|
347
|
+
* for WorkBuddy evidence. Kept so an older caller paired with this runtime
|
|
348
|
+
* still promotes, and callers pass both names so an older runtime still sees
|
|
349
|
+
* consent (P2 review). When the new field is present it wins: an explicit
|
|
350
|
+
* `false` must never be overridden by a stale `true` here.
|
|
351
|
+
*/
|
|
352
|
+
readonly conversationIngestionEnabled?: boolean;
|
|
344
353
|
readonly databaseFactory?: ObservationDatabaseFactory;
|
|
345
354
|
}
|
|
346
355
|
export type EnsureGovernanceContinuationResult = {
|
|
@@ -369,8 +378,15 @@ export type EnsureGovernanceContinuationResult = {
|
|
|
369
378
|
export declare function ensureGovernanceContinuation(input: EnsureGovernanceContinuationInput): Promise<EnsureGovernanceContinuationResult>;
|
|
370
379
|
export interface ReconcileGovernanceContinuationInput {
|
|
371
380
|
readonly workspaceDir: string;
|
|
372
|
-
/** Current Owner consent; false means reconcile may ensure tasks/links but must not read or promote Codex session evidence. */
|
|
373
|
-
readonly
|
|
381
|
+
/** Current Owner consent for CODEX conversation evidence; false means reconcile may ensure tasks/links but must not read or promote Codex session evidence. A WorkBuddy worker must pass false — its own flag is not consent for Codex evidence. */
|
|
382
|
+
readonly codexConversationIngestionEnabled: boolean;
|
|
383
|
+
/**
|
|
384
|
+
* Legacy alias (pre-rename) for the Codex-only consent above; never consent
|
|
385
|
+
* for WorkBuddy evidence. Kept for cross-version compatibility (P2 review);
|
|
386
|
+
* the new field wins when present, so an explicit `false` cannot be
|
|
387
|
+
* overridden by a stale `true`.
|
|
388
|
+
*/
|
|
389
|
+
readonly conversationIngestionEnabled?: boolean;
|
|
374
390
|
/** Bounded work per pass (default 50 admitted pains). */
|
|
375
391
|
readonly limit?: number;
|
|
376
392
|
readonly databaseFactory?: ObservationDatabaseFactory;
|
|
@@ -1954,7 +1954,10 @@ export async function ensureGovernanceContinuation(input) {
|
|
|
1954
1954
|
// continuation cannot begin diagnosis before the eligible evidence window
|
|
1955
1955
|
// has been promoted. A promotion failure is retained as a degradation,
|
|
1956
1956
|
// but never prevents the task from being durably ensured.
|
|
1957
|
-
const
|
|
1957
|
+
const codexConsent = typeof input.codexConversationIngestionEnabled === 'boolean'
|
|
1958
|
+
? input.codexConversationIngestionEnabled
|
|
1959
|
+
: input.conversationIngestionEnabled === true;
|
|
1960
|
+
const promoted = codexConsent
|
|
1958
1961
|
? promoteAdmittedGovernanceEvidence({
|
|
1959
1962
|
workspaceDir,
|
|
1960
1963
|
rolloutIdentity,
|
|
@@ -1991,6 +1994,11 @@ export async function ensureGovernanceContinuation(input) {
|
|
|
1991
1994
|
*/
|
|
1992
1995
|
export async function reconcileGovernanceContinuation(input) {
|
|
1993
1996
|
const workspaceDir = path.resolve(input.workspaceDir);
|
|
1997
|
+
// Accept the pre-rename field too: an older caller paired with this runtime
|
|
1998
|
+
// must not silently lose Codex evidence promotion (P2 review).
|
|
1999
|
+
const codexConsent = typeof input.codexConversationIngestionEnabled === 'boolean'
|
|
2000
|
+
? input.codexConversationIngestionEnabled
|
|
2001
|
+
: input.conversationIngestionEnabled === true;
|
|
1994
2002
|
const opened = openAdmissionStore(input.workspaceDir, input.databaseFactory);
|
|
1995
2003
|
if (!('db' in opened)) {
|
|
1996
2004
|
return { ok: false, reason: opened.reason, nextAction: opened.nextAction, tasksEnsured: 0, linksRepaired: 0, pendingTails: 0, completedTails: 0, staleTails: 0, degradations: [opened.reason] };
|
|
@@ -2029,7 +2037,7 @@ export async function reconcileGovernanceContinuation(input) {
|
|
|
2029
2037
|
// not retry pending tails, so pending-tail markers do not block later
|
|
2030
2038
|
// markers. Stale tails are NOT auto-recoverable (substrate refuses to
|
|
2031
2039
|
// re-arm them): they are counted separately below and reported.
|
|
2032
|
-
const promotionRecoveryClause =
|
|
2040
|
+
const promotionRecoveryClause = codexConsent
|
|
2033
2041
|
? `OR (a.host_kind = 'codex'
|
|
2034
2042
|
AND NOT EXISTS (SELECT 1 FROM governance_observations o
|
|
2035
2043
|
WHERE o.promotion_ref = a.canonical_pain_id))`
|
|
@@ -2064,7 +2072,7 @@ export async function reconcileGovernanceContinuation(input) {
|
|
|
2064
2072
|
}
|
|
2065
2073
|
continue;
|
|
2066
2074
|
}
|
|
2067
|
-
const cont = await ensureGovernanceContinuation({ workspaceDir, logicalObservationKey: key, canonicalPainId: painId,
|
|
2075
|
+
const cont = await ensureGovernanceContinuation({ workspaceDir, logicalObservationKey: key, canonicalPainId: painId, codexConversationIngestionEnabled: codexConsent });
|
|
2068
2076
|
if (cont.ok) {
|
|
2069
2077
|
// Only count REAL actions: a task actually created, a link actually
|
|
2070
2078
|
// repaired (task existed but the marker link was missing). Healthy
|
|
@@ -2088,7 +2096,7 @@ export async function reconcileGovernanceContinuation(input) {
|
|
|
2088
2096
|
}
|
|
2089
2097
|
}
|
|
2090
2098
|
// Also report stale tails scoped to governance admissions.
|
|
2091
|
-
const stale =
|
|
2099
|
+
const stale = codexConsent
|
|
2092
2100
|
? db.prepare(`SELECT COUNT(*) AS n FROM governance_pending_promotion_tails t
|
|
2093
2101
|
WHERE t.state = 'stale'
|
|
2094
2102
|
AND EXISTS (SELECT 1 FROM governance_signal_admissions a WHERE a.canonical_pain_id = t.pain_ref)`).get()
|
|
@@ -18,9 +18,20 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { type ToolSemanticMappingV1 } from '@principles/core/runtime';
|
|
20
20
|
export declare const HOST_TOOL_DECLARATION_DIRNAME = "host-tool-semantics";
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* ADR-0030: version 2 adds `writePayloadFormat` to the mapping contract.
|
|
23
|
+
*
|
|
24
|
+
* The read path is deliberately FORWARD-COMPATIBLE with version 1: an older
|
|
25
|
+
* persisted file must never block host loading. A legacy declaration is read
|
|
26
|
+
* with v1 semantics (`writePayloadFormat` treated as unset) and reported as a
|
|
27
|
+
* structured warning, so the degradation is observable (rc-9). Only a
|
|
28
|
+
* genuinely malformed file still fails loud (rc-3).
|
|
29
|
+
*/
|
|
30
|
+
export declare const HOST_TOOL_DECLARATION_VERSION: 2;
|
|
31
|
+
export type HostToolDeclarationVersion = 1 | typeof HOST_TOOL_DECLARATION_VERSION;
|
|
22
32
|
export interface HostToolDeclaration {
|
|
23
|
-
|
|
33
|
+
/** The version literally read from/written to the file. */
|
|
34
|
+
readonly version: HostToolDeclarationVersion;
|
|
24
35
|
/** Host identity label ('openclaw' | 'codex' | …). */
|
|
25
36
|
readonly hostKind: string;
|
|
26
37
|
readonly mappings: readonly ToolSemanticMappingV1[];
|
|
@@ -33,6 +44,8 @@ export type HostToolDeclarationSaveResult = {
|
|
|
33
44
|
export type HostToolDeclarationLoadResult = {
|
|
34
45
|
readonly ok: true;
|
|
35
46
|
readonly declarations: readonly HostToolDeclaration[];
|
|
47
|
+
/** Non-blocking diagnostics (legacy version degraded to defaults). */
|
|
48
|
+
readonly warnings: readonly string[];
|
|
36
49
|
} | {
|
|
37
50
|
readonly ok: false;
|
|
38
51
|
readonly reason: string;
|
|
@@ -47,6 +60,9 @@ export type HostToolDeclarationLoadResult = {
|
|
|
47
60
|
export declare function saveHostToolDeclaration(workspaceDir: string, declaration: HostToolDeclaration): HostToolDeclarationSaveResult;
|
|
48
61
|
/**
|
|
49
62
|
* Load ALL host declarations for the workspace. Typed result —
|
|
63
|
+
* ok:true warnings=[...] : an OLDER (legacy) declaration was read with the
|
|
64
|
+
* current semantics minus the fields that version never had
|
|
65
|
+
* (`writePayloadFormat` treated as unset). Loading is not blocked (rc-9).
|
|
50
66
|
* ok:false reason=host_tool_declaration_missing : no declarations persisted
|
|
51
67
|
* ok:false reason=host_tool_declaration_invalid : at least one persisted
|
|
52
68
|
* file is malformed (named by hostKind — a broken host declaration is a
|