create-principles-disciple 1.150.2 → 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/adaptive-selection-output.d.ts +35 -0
- package/core/dist/runtime/activation/adaptive-selection-output.d.ts.map +1 -0
- package/core/dist/runtime/activation/adaptive-selection-output.js +38 -0
- package/core/dist/runtime/activation/adaptive-selection-output.js.map +1 -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/artificer-l2-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/artificer-l2-adapter.js +89 -27
- package/core/dist/runtime/adapter/artificer-l2-adapter.js.map +1 -1
- package/core/dist/runtime/adapter/context-budget.d.ts +49 -0
- package/core/dist/runtime/adapter/context-budget.d.ts.map +1 -0
- package/core/dist/runtime/adapter/context-budget.js +127 -0
- package/core/dist/runtime/adapter/context-budget.js.map +1 -0
- package/core/dist/runtime/adapter/output-schema-registry.d.ts.map +1 -1
- package/core/dist/runtime/adapter/output-schema-registry.js +7 -0
- package/core/dist/runtime/adapter/output-schema-registry.js.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts +30 -7
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js +559 -211
- 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/telemetry-event.d.ts +2 -2
- package/core/dist/telemetry-event.d.ts.map +1 -1
- package/core/dist/telemetry-event.js +5 -0
- package/core/dist/telemetry-event.js.map +1 -1
- 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 -62
- package/host-runtime/dist/adaptive-selection.js +218 -301
- 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 +36 -4
- 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 +477 -471
- 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 +7 -2
- 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
|
@@ -20,7 +20,16 @@ import { readFileSync, writeFileSync, mkdirSync, mkdtempSync, renameSync, rmSync
|
|
|
20
20
|
import path from 'node:path';
|
|
21
21
|
import { validateToolSemanticMappings, } from '@principles/core/runtime';
|
|
22
22
|
export const HOST_TOOL_DECLARATION_DIRNAME = 'host-tool-semantics';
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* ADR-0030: version 2 adds `writePayloadFormat` to the mapping contract.
|
|
25
|
+
*
|
|
26
|
+
* The read path is deliberately FORWARD-COMPATIBLE with version 1: an older
|
|
27
|
+
* persisted file must never block host loading. A legacy declaration is read
|
|
28
|
+
* with v1 semantics (`writePayloadFormat` treated as unset) and reported as a
|
|
29
|
+
* structured warning, so the degradation is observable (rc-9). Only a
|
|
30
|
+
* genuinely malformed file still fails loud (rc-3).
|
|
31
|
+
*/
|
|
32
|
+
export const HOST_TOOL_DECLARATION_VERSION = 2;
|
|
24
33
|
const MAX_DECLARATION_BYTES = 256 * 1024;
|
|
25
34
|
/** hostKind doubles as a filename — code-controlled but validated anyway. */
|
|
26
35
|
const HOST_KIND_PATTERN = /^[a-z][a-z0-9_-]*$/;
|
|
@@ -33,6 +42,30 @@ function declarationPath(workspaceDir, hostKind) {
|
|
|
33
42
|
function isRecord(value) {
|
|
34
43
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
35
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* v1 never carried `writePayloadFormat`: applying v1 semantics means reading
|
|
47
|
+
* the mapping exactly as v1 did (rawToolName + canonicalKind only). An
|
|
48
|
+
* unexpected field in a legacy file is ignored, never interpreted — the same
|
|
49
|
+
* bytes read by the old loader would have produced this projection.
|
|
50
|
+
*/
|
|
51
|
+
function stripWritePayloadFormat(mappings) {
|
|
52
|
+
if (!Array.isArray(mappings))
|
|
53
|
+
return mappings;
|
|
54
|
+
return mappings.map((entry) => {
|
|
55
|
+
if (!isRecord(entry) || !Object.hasOwn(entry, 'writePayloadFormat'))
|
|
56
|
+
return entry;
|
|
57
|
+
const projected = {};
|
|
58
|
+
for (const [key, value] of Object.entries(entry)) {
|
|
59
|
+
if (key === 'writePayloadFormat')
|
|
60
|
+
continue;
|
|
61
|
+
projected[key] = value;
|
|
62
|
+
}
|
|
63
|
+
return projected;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function legacyVersionWarning(hostKind, declaredVersion) {
|
|
67
|
+
return `host_tool_declaration_version_legacy (${hostKind}: declared version ${declaredVersion}, supported ${HOST_TOOL_DECLARATION_VERSION}) — writePayloadFormat is treated as unset (default) for this legacy declaration; re-run host '${hostKind}' to refresh .pd/${HOST_TOOL_DECLARATION_DIRNAME}/${hostKind}.json`;
|
|
68
|
+
}
|
|
36
69
|
function parseDeclaration(hostKind, raw) {
|
|
37
70
|
if (Buffer.byteLength(raw, 'utf8') > MAX_DECLARATION_BYTES) {
|
|
38
71
|
return { invalidReason: `declaration exceeds ${MAX_DECLARATION_BYTES} bytes` };
|
|
@@ -44,25 +77,43 @@ function parseDeclaration(hostKind, raw) {
|
|
|
44
77
|
catch {
|
|
45
78
|
return { invalidReason: 'not valid JSON' };
|
|
46
79
|
}
|
|
47
|
-
if (!isRecord(parsed)
|
|
48
|
-
return { invalidReason:
|
|
80
|
+
if (!isRecord(parsed)) {
|
|
81
|
+
return { invalidReason: 'declaration must be a JSON object' };
|
|
82
|
+
}
|
|
83
|
+
const declaredVersion = parsed.version;
|
|
84
|
+
if (typeof declaredVersion !== 'number' || !Number.isInteger(declaredVersion) || declaredVersion < 1) {
|
|
85
|
+
return { invalidReason: `version must be a positive integer, got ${String(declaredVersion)}` };
|
|
86
|
+
}
|
|
87
|
+
// A file from a NEWER runtime carries fields this build cannot interpret —
|
|
88
|
+
// refuse rather than guess (the forward direction is not the compatibility
|
|
89
|
+
// promise; ADR-0030 only blesses reading OLDER declarations).
|
|
90
|
+
if (declaredVersion > HOST_TOOL_DECLARATION_VERSION) {
|
|
91
|
+
return {
|
|
92
|
+
invalidReason: `version ${declaredVersion} is newer than supported version ${HOST_TOOL_DECLARATION_VERSION}`,
|
|
93
|
+
};
|
|
49
94
|
}
|
|
95
|
+
const legacy = declaredVersion < HOST_TOOL_DECLARATION_VERSION;
|
|
50
96
|
const { mappings, declaredAt } = parsed;
|
|
51
97
|
if (typeof declaredAt !== 'string' || declaredAt.trim() === '') {
|
|
52
98
|
return { invalidReason: 'declaredAt must be a non-empty string' };
|
|
53
99
|
}
|
|
54
|
-
const
|
|
100
|
+
const effectiveMappings = legacy ? stripWritePayloadFormat(mappings) : mappings;
|
|
101
|
+
const validation = validateToolSemanticMappings(effectiveMappings);
|
|
55
102
|
if (!validation.valid) {
|
|
56
103
|
return { invalidReason: `mappings invalid: ${validation.errors.slice(0, 3).join('; ')}` };
|
|
57
104
|
}
|
|
58
|
-
if (!Array.isArray(
|
|
105
|
+
if (!Array.isArray(effectiveMappings) || effectiveMappings.length === 0) {
|
|
59
106
|
return { invalidReason: 'declaration must contain at least one mapping' };
|
|
60
107
|
}
|
|
108
|
+
const normalizedVersion = declaredVersion === 1 ? 1 : HOST_TOOL_DECLARATION_VERSION;
|
|
61
109
|
return {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
110
|
+
declaration: {
|
|
111
|
+
version: normalizedVersion,
|
|
112
|
+
hostKind,
|
|
113
|
+
mappings: effectiveMappings,
|
|
114
|
+
declaredAt,
|
|
115
|
+
},
|
|
116
|
+
warnings: legacy ? [legacyVersionWarning(hostKind, declaredVersion)] : [],
|
|
66
117
|
};
|
|
67
118
|
}
|
|
68
119
|
/**
|
|
@@ -105,6 +156,9 @@ export function saveHostToolDeclaration(workspaceDir, declaration) {
|
|
|
105
156
|
}
|
|
106
157
|
/**
|
|
107
158
|
* Load ALL host declarations for the workspace. Typed result —
|
|
159
|
+
* ok:true warnings=[...] : an OLDER (legacy) declaration was read with the
|
|
160
|
+
* current semantics minus the fields that version never had
|
|
161
|
+
* (`writePayloadFormat` treated as unset). Loading is not blocked (rc-9).
|
|
108
162
|
* ok:false reason=host_tool_declaration_missing : no declarations persisted
|
|
109
163
|
* ok:false reason=host_tool_declaration_invalid : at least one persisted
|
|
110
164
|
* file is malformed (named by hostKind — a broken host declaration is a
|
|
@@ -125,6 +179,7 @@ export function loadHostToolDeclarations(workspaceDir) {
|
|
|
125
179
|
};
|
|
126
180
|
}
|
|
127
181
|
const declarations = [];
|
|
182
|
+
const warnings = [];
|
|
128
183
|
for (const entry of entries.sort()) {
|
|
129
184
|
if (!entry.endsWith('.json'))
|
|
130
185
|
continue;
|
|
@@ -148,7 +203,8 @@ export function loadHostToolDeclarations(workspaceDir) {
|
|
|
148
203
|
nextAction: `re-run host '${hostKind}' to refresh ${declarationsDir(workspaceDir)}/${entry}`,
|
|
149
204
|
};
|
|
150
205
|
}
|
|
151
|
-
declarations.push(parsed);
|
|
206
|
+
declarations.push(parsed.declaration);
|
|
207
|
+
warnings.push(...parsed.warnings);
|
|
152
208
|
}
|
|
153
209
|
if (declarations.length === 0) {
|
|
154
210
|
return {
|
|
@@ -157,5 +213,5 @@ export function loadHostToolDeclarations(workspaceDir) {
|
|
|
157
213
|
nextAction: 'start each workspace host once (OpenClaw plugin / Codex worker) so it persists its tool declaration',
|
|
158
214
|
};
|
|
159
215
|
}
|
|
160
|
-
return { ok: true, declarations };
|
|
216
|
+
return { ok: true, declarations, warnings };
|
|
161
217
|
}
|
|
@@ -34,6 +34,8 @@ export type HostToolSemanticResolution = {
|
|
|
34
34
|
readonly ok: true;
|
|
35
35
|
readonly registry: ToolSemanticRegistry;
|
|
36
36
|
readonly hostKinds: readonly string[];
|
|
37
|
+
/** Non-blocking load diagnostics (legacy declaration version). */
|
|
38
|
+
readonly warnings: readonly string[];
|
|
37
39
|
} | {
|
|
38
40
|
readonly ok: false;
|
|
39
41
|
readonly reason: string;
|
|
@@ -52,6 +54,8 @@ export type HookToolSemanticsResolution = {
|
|
|
52
54
|
readonly ok: true;
|
|
53
55
|
readonly registry: ToolSemanticRegistry;
|
|
54
56
|
readonly source: HookToolSemanticsSource;
|
|
57
|
+
/** Non-blocking diagnostics the host must surface (legacy version). */
|
|
58
|
+
readonly warnings: readonly string[];
|
|
55
59
|
} | {
|
|
56
60
|
readonly ok: false;
|
|
57
61
|
readonly reason: string;
|
|
@@ -82,6 +86,9 @@ export interface HookToolSemanticsOptions {
|
|
|
82
86
|
* - malformed / conflicting declaration → typed refusal, never a silent
|
|
83
87
|
* static fallback and never an empty registry. Consumers must surface the
|
|
84
88
|
* reason (rc-9) and may fall back to their static registry for availability.
|
|
89
|
+
* - legacy declaration version (v1 read by a v2 build) → NOT a refusal: the
|
|
90
|
+
* file is read with v1 semantics (`writePayloadFormat` unset) and the
|
|
91
|
+
* result carries `warnings`, which consumers must surface (rc-9).
|
|
85
92
|
*/
|
|
86
93
|
export declare function resolveHostToolSemanticsForHook(options: HookToolSemanticsOptions): HookToolSemanticsResolution;
|
|
87
94
|
export { saveHostToolDeclaration };
|
|
@@ -49,6 +49,22 @@ function mergeDeclarations(declarations) {
|
|
|
49
49
|
nextAction: 'each raw tool name must resolve to one canonical kind across all co-installed hosts — fix the conflicting host declaration',
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
+
// ADR-0030: the payload encoding is part of the same identity. Two hosts
|
|
53
|
+
// claiming the same write tool with different encodings cannot both be
|
|
54
|
+
// right, and picking by startup order would make parsing order-dependent.
|
|
55
|
+
//
|
|
56
|
+
// An ABSENT format is a claim of plain content, not "no opinion": with a
|
|
57
|
+
// single-value enum this is the only reading under which the guard can
|
|
58
|
+
// fire, so "host A omits / host B declares the patch envelope" is a real
|
|
59
|
+
// disagreement (fail loud) rather than silently resolved drift. The fix
|
|
60
|
+
// belongs in the host declaration, never here.
|
|
61
|
+
if (existing && existing.writePayloadFormat !== mapping.writePayloadFormat) {
|
|
62
|
+
return {
|
|
63
|
+
ok: false,
|
|
64
|
+
reason: `host_tool_declaration_invalid (conflicting writePayloadFormat for '${mapping.rawToolName}': ${existing.writePayloadFormat ?? 'unset'} vs ${mapping.writePayloadFormat ?? 'unset'})`,
|
|
65
|
+
nextAction: 'each raw tool name must resolve to one write payload format across all co-installed hosts — fix the conflicting host declaration',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
52
68
|
if (!existing)
|
|
53
69
|
mappings.push(mapping);
|
|
54
70
|
}
|
|
@@ -81,6 +97,7 @@ export function resolveWorkspaceHostToolSemantics(workspaceDir) {
|
|
|
81
97
|
ok: true,
|
|
82
98
|
registry: built.registry,
|
|
83
99
|
hostKinds: loaded.declarations.map((d) => d.hostKind).sort(),
|
|
100
|
+
warnings: loaded.warnings,
|
|
84
101
|
};
|
|
85
102
|
}
|
|
86
103
|
/**
|
|
@@ -101,6 +118,9 @@ export function resolveWorkspaceHostToolSemantics(workspaceDir) {
|
|
|
101
118
|
* - malformed / conflicting declaration → typed refusal, never a silent
|
|
102
119
|
* static fallback and never an empty registry. Consumers must surface the
|
|
103
120
|
* reason (rc-9) and may fall back to their static registry for availability.
|
|
121
|
+
* - legacy declaration version (v1 read by a v2 build) → NOT a refusal: the
|
|
122
|
+
* file is read with v1 semantics (`writePayloadFormat` unset) and the
|
|
123
|
+
* result carries `warnings`, which consumers must surface (rc-9).
|
|
104
124
|
*/
|
|
105
125
|
export function resolveHostToolSemanticsForHook(options) {
|
|
106
126
|
const builtStatic = buildToolSemanticRegistry(options.staticMappings);
|
|
@@ -114,7 +134,7 @@ export function resolveHostToolSemanticsForHook(options) {
|
|
|
114
134
|
const loaded = loadHostToolDeclarations(options.workspaceDir);
|
|
115
135
|
if (!loaded.ok) {
|
|
116
136
|
if (loaded.reason === 'host_tool_declaration_missing') {
|
|
117
|
-
return { ok: true, registry: builtStatic.registry, source: 'host-static' };
|
|
137
|
+
return { ok: true, registry: builtStatic.registry, source: 'host-static', warnings: [] };
|
|
118
138
|
}
|
|
119
139
|
return { ok: false, reason: loaded.reason, nextAction: loaded.nextAction };
|
|
120
140
|
}
|
|
@@ -134,6 +154,6 @@ export function resolveHostToolSemanticsForHook(options) {
|
|
|
134
154
|
nextAction: `merged tool mappings invalid: ${built.errors.slice(0, 3).join('; ')}`,
|
|
135
155
|
};
|
|
136
156
|
}
|
|
137
|
-
return { ok: true, registry: built.registry, source: 'workspace-declaration' };
|
|
157
|
+
return { ok: true, registry: built.registry, source: 'workspace-declaration', warnings: loaded.warnings };
|
|
138
158
|
}
|
|
139
159
|
export { saveHostToolDeclaration };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type HostEvent, type HostEventResult, type HostEventEmitter } from '@principles/core/host';
|
|
2
|
+
import type { AdaptivePriorityProvider } from './adaptive-priority-provider.js';
|
|
2
3
|
import { buildActivePrinciplePromptContext } from './active-principle-prompt.js';
|
|
3
4
|
import { type RuleContextProvider, type RuleInputEnrichmentProvider } from './production-rulehost-gate.js';
|
|
4
5
|
import type { RuleImplementationRuntime } from './rule-implementation-runtime.js';
|
|
@@ -17,6 +18,7 @@ export * from './production-rulehost-gate.js';
|
|
|
17
18
|
export * from './rule-implementation-runtime.js';
|
|
18
19
|
export * from './production-pain-evidence.js';
|
|
19
20
|
export * from './governance-observation-store.js';
|
|
21
|
+
export * from './trajectory-retention.js';
|
|
20
22
|
export * from './conversation-ingestion/index.js';
|
|
21
23
|
export * from './governance-signal-admission.js';
|
|
22
24
|
export * from './signal-classifier.js';
|
|
@@ -92,6 +94,7 @@ export declare function createProductionHostRuntime(options?: Partial<Pick<HostR
|
|
|
92
94
|
* before this convergence. Must be a positive integer when present.
|
|
93
95
|
*/
|
|
94
96
|
roundKeyProvider?: (event: HostEvent) => number | undefined | Promise<number | undefined>;
|
|
97
|
+
adaptiveGapProvider?: AdaptivePriorityProvider;
|
|
95
98
|
/** Optional, already-scoped single prompt target from the host adapter. Errors fail closed to Native. */
|
|
96
99
|
adaptivePriorityProvider?: (event: HostEvent) => {
|
|
97
100
|
artifactId: string;
|
|
@@ -29,6 +29,10 @@ export * from './production-rulehost-gate.js';
|
|
|
29
29
|
export * from './rule-implementation-runtime.js';
|
|
30
30
|
export * from './production-pain-evidence.js';
|
|
31
31
|
export * from './governance-observation-store.js';
|
|
32
|
+
// SPEC-PD-TR-001: trajectory retention I/O boundary (lock + marker + export
|
|
33
|
+
// list + explicit VACUUM). The policy/batch engine is pure and lives in
|
|
34
|
+
// `@principles/core/runtime`.
|
|
35
|
+
export * from './trajectory-retention.js';
|
|
32
36
|
// PRI-1171: unified conversation-ingestion seam — the ONE host-neutral entry
|
|
33
37
|
// for transcript trajectory ingestion (source contract + shared pipeline +
|
|
34
38
|
// consent ledger v3 + text policy). Host decoders stay in their adapter
|
|
@@ -279,6 +283,16 @@ export function createProductionHostRuntime(options = {}) {
|
|
|
279
283
|
const prompt = await buildActivePrinciplePromptContext({
|
|
280
284
|
workspaceDir: event.context.workspaceDir,
|
|
281
285
|
...(roundKey !== undefined ? { roundKey } : {}),
|
|
286
|
+
...(options.adaptiveGapProvider ? {
|
|
287
|
+
async selectNativeGap(candidates) {
|
|
288
|
+
try {
|
|
289
|
+
return await options.adaptiveGapProvider?.(event, candidates);
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
} : {}),
|
|
282
296
|
...(adaptivePriority ? {
|
|
283
297
|
adaptivePriority: { artifactId: adaptivePriority.artifactId, activationId: adaptivePriority.activationId },
|
|
284
298
|
...(adaptivePriority.additiveOnly === true ? { additiveOnly: true } : {}),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { buildRuleHostAction, buildToolSemanticRegistry, deriveToolHintsFromCanonicalKind, estimateLineChanges, mergeDecisions, normalizeRuleHostResult, SqliteConnection, UNAVAILABLE_RULE_CONTEXT, validateRuleContextV2, verifyPiArtifactRowDigest, RECOVERY_CONTROL_SURFACES, } from '@principles/core/runtime';
|
|
4
|
-
import { isSensitiveSystemPath } from '@principles/core/runtime/internalization/rule-host-input-builder';
|
|
4
|
+
import { isRuleHostEvaluableKind, isSensitiveSystemPath } from '@principles/core/runtime/internalization/rule-host-input-builder';
|
|
5
5
|
import { classifyBashRisk } from '@principles/core/runtime/internalization/bash-risk';
|
|
6
6
|
import { scanRetiredContractSymbols } from './legacy-rule-contract-symbols.js';
|
|
7
7
|
import { recordDegradedEnforcement } from './degraded-enforcement-marker.js';
|
|
@@ -93,9 +93,21 @@ export function createProductionRuleHostGate(options = {}) {
|
|
|
93
93
|
return { decision: 'allow', source: event.source, warnings: [boundedWarning('tool_input_invalid', 'decode and validate toolName and params before dispatch')] };
|
|
94
94
|
}
|
|
95
95
|
const canonicalKind = toolSemantics.resolve(input.toolName);
|
|
96
|
+
// PRI-1184 / F3': restore the RuleHost routing contract. Only the write,
|
|
97
|
+
// execute and agent families enter rule evaluation; read/search and every
|
|
98
|
+
// other canonical kind are allowed without touching the RuleCode engine.
|
|
99
|
+
// The kind comes from the same ToolSemanticRegistry that supplies the
|
|
100
|
+
// extraction hints below — never a tool-name allowlist.
|
|
101
|
+
if (!isRuleHostEvaluableKind(canonicalKind)) {
|
|
102
|
+
return { decision: 'allow', source: event.source, metadata: { evaluatedLiveRules: 0 } };
|
|
103
|
+
}
|
|
96
104
|
const { isBashTool: isBash, isWriteTool: isWrite } = deriveToolHintsFromCanonicalKind(canonicalKind);
|
|
97
105
|
const action = buildRuleHostAction(input.toolName, input.params, options.projectDir ?? event.context.workspaceDir, { isBashTool: isBash, isWriteTool: isWrite, canonicalKind });
|
|
98
|
-
|
|
106
|
+
// F3': normalizePathPure returns '' when no path could be extracted, so the
|
|
107
|
+
// old `=== null` guard never fired. Both null and '' mean "no action
|
|
108
|
+
// target": a pathless tool is not evaluated rather than treating an empty
|
|
109
|
+
// string as a path.
|
|
110
|
+
if (action.normalizedPath === null || action.normalizedPath === '')
|
|
99
111
|
return { decision: 'allow', source: event.source, metadata: { evaluatedLiveRules: 0 } };
|
|
100
112
|
let context;
|
|
101
113
|
/**
|
|
@@ -521,7 +533,7 @@ export function createProductionRuleHostGate(options = {}) {
|
|
|
521
533
|
workspace: { isRiskPath: isSensitiveSystemPath(action.normalizedPath) },
|
|
522
534
|
session: { sessionId: event.context.sessionId },
|
|
523
535
|
evolution: { epTier: enrichment.epTier },
|
|
524
|
-
derived: { estimatedLineChanges: estimateLineChanges({ toolName: input.toolName, params: input.params }), bashRisk: enrichment.bashRisk },
|
|
536
|
+
derived: { estimatedLineChanges: estimateLineChanges({ toolName: input.toolName, params: input.params }, toolSemantics), bashRisk: enrichment.bashRisk },
|
|
525
537
|
...(context ? { context } : {}),
|
|
526
538
|
};
|
|
527
539
|
// CodeRabbit CR-3: live and shadow evaluate in SEPARATE batches so a
|
|
@@ -673,7 +685,27 @@ export function createProductionRuleHostGate(options = {}) {
|
|
|
673
685
|
}
|
|
674
686
|
return { decision: 'deny', reason: result.reason, source: event.source, ...(warnings.length ? { warnings } : {}), metadata: { evaluatedLiveRules: implementations.length, ruleId: result.ruleId, principleId: result.principleId, evaluations } };
|
|
675
687
|
}
|
|
676
|
-
|
|
688
|
+
// Task 1 (legacy fallback convergence): a non-block verdict now carries
|
|
689
|
+
// the facts the OpenClaw adapter needs to record/apply it WITHOUT a
|
|
690
|
+
// second evaluation: winner identity, matched flag, rule reason and the
|
|
691
|
+
// already-merged (validated) correction proposal. `metadata` is
|
|
692
|
+
// host-neutral; adapters that do not consume these keys ignore them and
|
|
693
|
+
// never forward them into a host schema.
|
|
694
|
+
return {
|
|
695
|
+
decision: 'allow',
|
|
696
|
+
source: event.source,
|
|
697
|
+
...(warnings.length ? { warnings } : {}),
|
|
698
|
+
metadata: {
|
|
699
|
+
evaluatedLiveRules: implementations.length,
|
|
700
|
+
ruleDecision: result?.decision ?? 'allow',
|
|
701
|
+
matched: result?.matched ?? false,
|
|
702
|
+
...(result?.ruleId !== undefined ? { ruleId: result.ruleId } : {}),
|
|
703
|
+
...(result?.principleId !== undefined ? { principleId: result.principleId } : {}),
|
|
704
|
+
...(result?.reason !== undefined ? { ruleReason: result.reason } : {}),
|
|
705
|
+
...(result !== undefined && result.correctionProposal !== undefined ? { correctionProposal: result.correctionProposal } : {}),
|
|
706
|
+
evaluations,
|
|
707
|
+
},
|
|
708
|
+
};
|
|
677
709
|
}
|
|
678
710
|
catch (error) {
|
|
679
711
|
addWarning(warnings, `activation_read_failed: ${error instanceof Error ? error.message : String(error)}`, 'inspect state.db schema and integrity');
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { type RetentionIndexReport, type TrajectoryRetentionMarker, type TrajectoryRetentionPolicy } from '@principles/core/runtime';
|
|
2
|
+
export declare const TRAJECTORY_RETENTION_MARKER_FILENAME = "trajectory-retention.json";
|
|
3
|
+
export declare const TRAJECTORY_RETENTION_LOCK_FILENAME = "trajectory-retention.lock";
|
|
4
|
+
/** 10 minutes: far above the 3 s run budget, so a live run is never taken over. */
|
|
5
|
+
export declare const TRAJECTORY_RETENTION_LOCK_STALE_MS: number;
|
|
6
|
+
/**
|
|
7
|
+
* The maintenance connection waits at most this long for the write lock.
|
|
8
|
+
*
|
|
9
|
+
* SPEC §4.2 says `busy_timeout = 5000`; acceptance criterion A8 requires the
|
|
10
|
+
* maintenance run to yield within 300 ms when another writer holds the lock.
|
|
11
|
+
* Those two cannot both hold, and A8 is the measurable one, so the write lock
|
|
12
|
+
* wait wins: a sweeper that queues behind the user's writer turns a background
|
|
13
|
+
* chore into user-visible latency. Reads in WAL mode do not need this wait.
|
|
14
|
+
*
|
|
15
|
+
* 100 ms (not 250) because SQLite's busy handler overshoots its timeout by up
|
|
16
|
+
* to one sleep step (~100 ms): a 250 ms timeout was measured at ~355 ms
|
|
17
|
+
* wall-clock, which breaks A8. Ordinary host writes hold the lock for
|
|
18
|
+
* milliseconds, so 100 ms is still enough to ride out normal contention.
|
|
19
|
+
*/
|
|
20
|
+
export declare const TRAJECTORY_RETENTION_WRITE_LOCK_WAIT_MS = 100;
|
|
21
|
+
/**
|
|
22
|
+
* Index DDL is NOT the hot path and is NEVER attempted by a regular sweep
|
|
23
|
+
* (F2: a 5 s wait at the start of every run stalled the host). Creation only
|
|
24
|
+
* happens in the explicit maintenance entry, which may use this longer wait.
|
|
25
|
+
*/
|
|
26
|
+
export declare const TRAJECTORY_RETENTION_DDL_BUSY_TIMEOUT_MS = 5000;
|
|
27
|
+
/** VACUUM is a foreground, explicit action; it may wait properly. */
|
|
28
|
+
export declare const TRAJECTORY_RETENTION_VACUUM_BUSY_TIMEOUT_MS = 5000;
|
|
29
|
+
export type TrajectoryRetentionTrigger = 'worker' | 'manual';
|
|
30
|
+
export type TrajectoryRetentionReportOutcome = 'completed' | 'partial' | 'deadline' | 'invariant_violation' | 'deferred:busy' | 'skipped';
|
|
31
|
+
export interface TrajectoryRetentionReport {
|
|
32
|
+
outcome: TrajectoryRetentionReportOutcome;
|
|
33
|
+
reason: string | null;
|
|
34
|
+
workspaceDir: string;
|
|
35
|
+
cutoff: string | null;
|
|
36
|
+
deletedByTable: Record<string, number>;
|
|
37
|
+
batches: number;
|
|
38
|
+
/** Batch-engine wall clock only. */
|
|
39
|
+
durationMs: number;
|
|
40
|
+
/** Whole run, including DB open, WAL check, index DDL and marker write (A1). */
|
|
41
|
+
totalDurationMs: number;
|
|
42
|
+
maxBatchDurationMs: number;
|
|
43
|
+
partial: boolean;
|
|
44
|
+
backoffUntil: string | null;
|
|
45
|
+
policy: TrajectoryRetentionPolicy;
|
|
46
|
+
indexes: RetentionIndexReport | null;
|
|
47
|
+
/** Non-null when index creation failed but the sweep continued anyway. */
|
|
48
|
+
indexesError: string | null;
|
|
49
|
+
/** Present on refused/failed outcomes (cli-6). */
|
|
50
|
+
nextAction?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface RunTrajectoryRetentionOptions {
|
|
53
|
+
workspaceDir: string;
|
|
54
|
+
trigger?: TrajectoryRetentionTrigger;
|
|
55
|
+
/** Injectable clock (tests, deterministic marker/cutoff assertions). */
|
|
56
|
+
now?: () => number;
|
|
57
|
+
}
|
|
58
|
+
export declare function trajectoryRetentionPaths(workspaceDir: string): {
|
|
59
|
+
stateDir: string;
|
|
60
|
+
dbPath: string;
|
|
61
|
+
markerPath: string;
|
|
62
|
+
lockPath: string;
|
|
63
|
+
exportsDir: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* One retention attempt for one workspace.
|
|
67
|
+
*
|
|
68
|
+
* Synchronous on purpose: callers are a worker cycle and a CLI command, both
|
|
69
|
+
* of which already own their concurrency, and a fire-and-forget promise in a
|
|
70
|
+
* worker loop is a crash risk with no upside.
|
|
71
|
+
*/
|
|
72
|
+
export declare function runTrajectoryRetention(options: RunTrajectoryRetentionOptions): TrajectoryRetentionReport;
|
|
73
|
+
export interface TrajectoryRetentionLogger {
|
|
74
|
+
info?: (message: string) => void;
|
|
75
|
+
warn?: (message: string) => void;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Long-lived failure reasons repeat on every worker cycle. Return a message
|
|
79
|
+
* only when the reason for THIS workspace changed, so a permanently wrong
|
|
80
|
+
* `journal_mode` or a failing index DDL is visible once, not every 120 s
|
|
81
|
+
* (review finding 7).
|
|
82
|
+
*/
|
|
83
|
+
export declare function retentionWarning(report: TrajectoryRetentionReport): string | null;
|
|
84
|
+
/**
|
|
85
|
+
* Schedule the periodic retention run for a long-lived host process.
|
|
86
|
+
*
|
|
87
|
+
* SPEC §4.1: an unref'd interval in the gateway process. Deliberately does NOT
|
|
88
|
+
* run at scheduling time — that call happens inside `before_prompt_build`, and
|
|
89
|
+
* a 3 s sweep there would be exactly the hook latency A3 forbids. The first
|
|
90
|
+
* attempt happens one minute later, off the hook path.
|
|
91
|
+
*
|
|
92
|
+
* Idempotent per workspace: repeated plugin initialisation cannot stack timers.
|
|
93
|
+
* Config is read once here (interval); the runner re-reads it every cycle, so
|
|
94
|
+
* `enabled`/range changes still take effect.
|
|
95
|
+
*/
|
|
96
|
+
export declare function scheduleTrajectoryRetention(workspaceDirInput: string, logger?: TrajectoryRetentionLogger): void;
|
|
97
|
+
export interface TrajectoryRetentionStatus {
|
|
98
|
+
workspaceDir: string;
|
|
99
|
+
dbPath: string;
|
|
100
|
+
dbExists: boolean;
|
|
101
|
+
marker: TrajectoryRetentionMarker;
|
|
102
|
+
markerError: string | null;
|
|
103
|
+
policy: TrajectoryRetentionPolicy;
|
|
104
|
+
/** Cutoff the NEXT run will use; null when no sweep can run. */
|
|
105
|
+
nextCutoff: string | null;
|
|
106
|
+
/** Rows the NEXT run's cutoff would select (same rule, same predicate). */
|
|
107
|
+
expiredByTable: Record<string, number> | null;
|
|
108
|
+
/** Retention indexes absent from the database (created by `vacuum --yes`). */
|
|
109
|
+
indexesMissing: string[];
|
|
110
|
+
dbError: string | null;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Read-only status: never creates the marker, never opens the database for
|
|
114
|
+
* writing, never creates an index.
|
|
115
|
+
*
|
|
116
|
+
* `now` is injectable so the projected next cutoff can be asserted exactly
|
|
117
|
+
* against the run that follows it (F4: one definition of "expired").
|
|
118
|
+
*/
|
|
119
|
+
export declare function readTrajectoryRetentionStatus(workspaceDirInput: string, now?: () => number): TrajectoryRetentionStatus;
|
|
120
|
+
export interface TrajectoryVacuumReport {
|
|
121
|
+
workspaceDir: string;
|
|
122
|
+
dbPath: string;
|
|
123
|
+
applied: boolean;
|
|
124
|
+
refusedReason: string | null;
|
|
125
|
+
nextAction?: string;
|
|
126
|
+
sizeBeforeBytes: number;
|
|
127
|
+
sizeAfterBytes: number | null;
|
|
128
|
+
freeBytes: number | null;
|
|
129
|
+
requiredBytes: number | null;
|
|
130
|
+
freelistBefore: number | null;
|
|
131
|
+
freelistAfter: number | null;
|
|
132
|
+
/** Retention indexes created here — the ONLY place DDL may run (F2). */
|
|
133
|
+
indexes: RetentionIndexReport | null;
|
|
134
|
+
durationMs: number;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* `pd trajectory vacuum` — the ONLY place VACUUM may run (SPEC §6).
|
|
138
|
+
*
|
|
139
|
+
* VACUUM takes an exclusive lock and cannot be interrupted, which is why it is
|
|
140
|
+
* never scheduled. Default is a dry run: it reports the space requirement and
|
|
141
|
+
* refuses to start when the filesystem cannot hold `2 × size + 10%`.
|
|
142
|
+
*/
|
|
143
|
+
export declare function vacuumTrajectoryDatabase(args: {
|
|
144
|
+
workspaceDir: string;
|
|
145
|
+
apply: boolean;
|
|
146
|
+
now?: () => number;
|
|
147
|
+
}): TrajectoryVacuumReport;
|