create-principles-disciple 1.153.4 → 1.154.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_release/product-identity.json +2 -2
- package/codex-adapter/dist/ingestion/codex-home.d.ts +1 -0
- package/codex-adapter/dist/ingestion/codex-home.js +19 -7
- package/codex-adapter/dist/ingestion/ingestion.js +34 -7
- package/codex-adapter/dist/pd-hook.js +14 -6
- package/codex-adapter/dist/worker/workspace-worker.js +31 -1
- package/codex-adapter/package.json +1 -1
- package/console/dist/server/index.js +5 -16
- package/console/dist/server/utils/installed-layout.js +6 -4
- package/console/dist/server/utils/pd-backups.d.ts +1 -14
- package/console/dist/server/utils/pd-backups.js +12 -64
- package/console/dist/web/assets/app.css +67 -9
- package/console/dist/web/assets/app.js +37 -37
- package/console/dist/web/assets/providers/anthropic.png +0 -0
- package/console/dist/web/assets/providers/deepseek.png +0 -0
- package/console/dist/web/assets/providers/google.png +0 -0
- package/console/dist/web/assets/providers/groq.svg +1 -0
- package/console/dist/web/assets/providers/kimi.png +0 -0
- package/console/dist/web/assets/providers/minimax.png +0 -0
- package/console/dist/web/assets/providers/mistral.svg +28 -0
- package/console/dist/web/assets/providers/nvidia.png +0 -0
- package/console/dist/web/assets/providers/openai.svg +1 -0
- package/console/dist/web/assets/providers/openrouter.svg +3 -0
- package/console/dist/web/assets/providers/qwen.png +0 -0
- package/console/dist/web/assets/providers/together.svg +21 -0
- package/console/dist/web/assets/providers/xai.svg +1 -0
- package/console/dist/web/assets/providers/xiaomi.png +0 -0
- package/console/dist/web/assets/providers/zai.svg +219 -0
- package/core/dist/index.d.ts +1 -2
- package/core/dist/index.d.ts.map +1 -1
- package/core/dist/index.js +4 -2
- package/core/dist/index.js.map +1 -1
- package/core/dist/prompt-builder/focus-compression.d.ts +8 -60
- package/core/dist/prompt-builder/focus-compression.d.ts.map +1 -1
- package/core/dist/prompt-builder/focus-compression.js +8 -434
- package/core/dist/prompt-builder/focus-compression.js.map +1 -1
- package/core/dist/prompt-builder/index.d.ts +1 -2
- package/core/dist/prompt-builder/index.d.ts.map +1 -1
- package/core/dist/prompt-builder/index.js +3 -2
- package/core/dist/prompt-builder/index.js.map +1 -1
- package/core/dist/runtime/activation/production-gate-deps.d.ts +7 -3
- package/core/dist/runtime/activation/production-gate-deps.d.ts.map +1 -1
- package/core/dist/runtime/activation/production-gate-deps.js +15 -6
- package/core/dist/runtime/activation/production-gate-deps.js.map +1 -1
- package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts +2 -0
- package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js +9 -1
- package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js.map +1 -1
- package/core/dist/runtime/config/pd-config-types.d.ts +20 -1
- 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 +12 -1
- package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
- package/core/dist/runtime/internalization/bash-risk.d.ts.map +1 -1
- package/core/dist/runtime/internalization/bash-risk.js +6 -3
- package/core/dist/runtime/internalization/bash-risk.js.map +1 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +28 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.js +109 -13
- package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts +10 -0
- package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.js +6 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
- package/core/dist/runtime/pain-chain-read-model.d.ts +14 -0
- package/core/dist/runtime/pain-chain-read-model.d.ts.map +1 -1
- package/core/dist/runtime/pain-chain-read-model.js +91 -3
- package/core/dist/runtime/pain-chain-read-model.js.map +1 -1
- package/core/dist/runtime/pain-ingress-payload.d.ts +15 -0
- package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
- package/core/dist/runtime/pain-ingress-payload.js +32 -3
- package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
- package/core/dist/runtime/pain-signal-bridge.d.ts +8 -0
- package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-bridge.js +11 -0
- package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.js +3 -0
- package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
- package/core/dist/runtime/pain-submit-capability.d.ts +54 -0
- package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -1
- package/core/dist/runtime/pain-submit-capability.js +49 -1
- package/core/dist/runtime/pain-submit-capability.js.map +1 -1
- package/core/dist/runtime/storage-paths.d.ts +9 -10
- package/core/dist/runtime/storage-paths.d.ts.map +1 -1
- package/core/dist/runtime/storage-paths.js +9 -10
- package/core/dist/runtime/storage-paths.js.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.js +10 -2
- package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
- package/core/dist/runtime/store/storage-paths.d.ts +65 -12
- package/core/dist/runtime/store/storage-paths.d.ts.map +1 -1
- package/core/dist/runtime/store/storage-paths.js +92 -39
- package/core/dist/runtime/store/storage-paths.js.map +1 -1
- package/core/package.json +1 -1
- package/dist/installer.d.ts +113 -9
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +596 -100
- package/dist/installer.js.map +1 -1
- package/dist/installers/codex-host-installer.d.ts +23 -3
- package/dist/installers/codex-host-installer.d.ts.map +1 -1
- package/dist/installers/codex-host-installer.js +36 -20
- package/dist/installers/codex-host-installer.js.map +1 -1
- package/dist/installers/index.d.ts.map +1 -1
- package/dist/installers/index.js +24 -3
- package/dist/installers/index.js.map +1 -1
- package/dist/installers/mcp-registration-conflict.d.ts.map +1 -1
- package/dist/installers/mcp-registration-conflict.js +23 -16
- package/dist/installers/mcp-registration-conflict.js.map +1 -1
- package/dist/installers/openclaw-host-installer.d.ts.map +1 -1
- package/dist/installers/openclaw-host-installer.js +1 -8
- package/dist/installers/openclaw-host-installer.js.map +1 -1
- package/dist/installers/workbuddy-host-installer.js +7 -7
- package/dist/installers/workbuddy-host-installer.js.map +1 -1
- package/dist/mvp-config.d.ts +30 -5
- package/dist/mvp-config.d.ts.map +1 -1
- package/dist/mvp-config.js +49 -16
- package/dist/mvp-config.js.map +1 -1
- package/dist/prompts.js +1 -1
- package/dist/prompts.js.map +1 -1
- package/dist/uninstaller.d.ts.map +1 -1
- package/dist/uninstaller.js +142 -5
- package/dist/uninstaller.js.map +1 -1
- package/dist/update/release-manager.d.ts.map +1 -1
- package/dist/update/release-manager.js +5 -2
- package/dist/update/release-manager.js.map +1 -1
- package/dist/utils/env.d.ts +5 -10
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +91 -34
- package/dist/utils/env.js.map +1 -1
- package/dist/utils/host-workspace-ownership.d.ts +25 -0
- package/dist/utils/host-workspace-ownership.d.ts.map +1 -1
- package/dist/utils/host-workspace-ownership.js +153 -2
- package/dist/utils/host-workspace-ownership.js.map +1 -1
- package/host-runtime/dist/adaptive-background-append.d.ts +6 -0
- package/host-runtime/dist/adaptive-background-append.js +4 -1
- package/host-runtime/dist/adaptive-decision-protocol.d.ts +18 -2
- package/host-runtime/dist/adaptive-decision-protocol.js +39 -9
- package/host-runtime/dist/adaptive-principle-context-reader.d.ts +79 -0
- package/host-runtime/dist/adaptive-principle-context-reader.js +303 -0
- package/host-runtime/dist/adaptive-priority-provider.d.ts +33 -0
- package/host-runtime/dist/adaptive-priority-provider.js +68 -2
- package/host-runtime/dist/adaptive-selection.d.ts +16 -0
- package/host-runtime/dist/adaptive-selection.js +23 -1
- package/host-runtime/dist/codex-legacy-registration.js +10 -2
- package/host-runtime/dist/conversation-ingestion/pipeline.d.ts +8 -0
- package/host-runtime/dist/conversation-ingestion/pipeline.js +179 -7
- package/host-runtime/dist/degraded-enforcement-marker.js +16 -2
- package/host-runtime/dist/diagnostician-auto-run.js +4 -0
- package/host-runtime/dist/governance-observation-store.d.ts +44 -0
- package/host-runtime/dist/governance-observation-store.js +84 -1
- package/host-runtime/dist/governance-trajectory-turn-reader.d.ts +30 -0
- package/host-runtime/dist/governance-trajectory-turn-reader.js +47 -0
- package/host-runtime/dist/index.d.ts +2 -0
- package/host-runtime/dist/index.js +6 -0
- package/host-runtime/dist/product-telemetry/service.js +86 -20
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/index.d.ts +23 -9
- package/install-layout/dist/index.js +49 -24
- package/install-layout/dist/mcp-binding-contract.d.ts +62 -0
- package/install-layout/dist/mcp-binding-contract.js +175 -3
- package/install-layout/dist/pd-home.d.ts +35 -5
- package/install-layout/dist/pd-home.js +138 -23
- package/install-layout/package.json +1 -1
- package/package.json +4 -4
- package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
- package/pd-cli/dist/commands/candidate.js +134 -8
- package/pd-cli/dist/commands/candidate.js.map +1 -1
- package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
- package/pd-cli/dist/commands/codex-worker.js +36 -2
- package/pd-cli/dist/commands/codex-worker.js.map +1 -1
- package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
- package/pd-cli/dist/commands/diagnose.js +34 -8
- package/pd-cli/dist/commands/diagnose.js.map +1 -1
- package/pd-cli/dist/commands/health-codex-install.d.ts +1 -3
- package/pd-cli/dist/commands/health-codex-install.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-codex-install.js +19 -6
- package/pd-cli/dist/commands/health-codex-install.js.map +1 -1
- package/pd-cli/dist/commands/health-codex.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-codex.js +27 -9
- package/pd-cli/dist/commands/health-codex.js.map +1 -1
- package/pd-cli/dist/commands/health-console.d.ts +2 -1
- package/pd-cli/dist/commands/health-console.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-console.js +12 -3
- package/pd-cli/dist/commands/health-console.js.map +1 -1
- package/pd-cli/dist/commands/health-ingestion.d.ts +10 -2
- package/pd-cli/dist/commands/health-ingestion.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-ingestion.js +56 -14
- package/pd-cli/dist/commands/health-ingestion.js.map +1 -1
- package/pd-cli/dist/commands/health-mcp.d.ts +19 -7
- package/pd-cli/dist/commands/health-mcp.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-mcp.js +131 -45
- package/pd-cli/dist/commands/health-mcp.js.map +1 -1
- package/pd-cli/dist/commands/health-workbuddy.d.ts +2 -1
- package/pd-cli/dist/commands/health-workbuddy.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-workbuddy.js +17 -8
- package/pd-cli/dist/commands/health-workbuddy.js.map +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/mcp-probe.d.ts +6 -0
- package/pd-cli/dist/commands/mcp-probe.d.ts.map +1 -1
- package/pd-cli/dist/commands/mcp-probe.js +35 -7
- package/pd-cli/dist/commands/mcp-probe.js.map +1 -1
- package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-retry.js +10 -2
- package/pd-cli/dist/commands/pain-retry.js.map +1 -1
- package/pd-cli/dist/commands/trace.d.ts.map +1 -1
- package/pd-cli/dist/commands/trace.js +8 -0
- package/pd-cli/dist/commands/trace.js.map +1 -1
- package/pd-cli/dist/commands/workbuddy-setup.d.ts.map +1 -1
- package/pd-cli/dist/commands/workbuddy-setup.js +7 -3
- package/pd-cli/dist/commands/workbuddy-setup.js.map +1 -1
- package/pd-cli/dist/commands/workbuddy-worker.d.ts.map +1 -1
- package/pd-cli/dist/commands/workbuddy-worker.js +21 -6
- package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
- package/pd-cli/dist/services/admission-write-gate.d.ts +10 -1
- package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
- package/pd-cli/dist/services/admission-write-gate.js +12 -2
- package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
- package/pd-cli/dist/services/codex-plugin-install.d.ts +1 -3
- package/pd-cli/dist/services/codex-plugin-install.d.ts.map +1 -1
- package/pd-cli/dist/services/codex-plugin-install.js +10 -3
- package/pd-cli/dist/services/codex-plugin-install.js.map +1 -1
- package/pd-cli/dist/services/pain-flood-simulation-runner.d.ts.map +1 -1
- package/pd-cli/dist/services/pain-flood-simulation-runner.js +2 -0
- package/pd-cli/dist/services/pain-flood-simulation-runner.js.map +1 -1
- package/pd-cli/dist/services/pd-config-loader.d.ts +2 -2
- package/pd-cli/dist/services/pd-config-loader.d.ts.map +1 -1
- package/pd-cli/dist/services/pd-config-loader.js +28 -20
- package/pd-cli/dist/services/pd-config-loader.js.map +1 -1
- package/pd-cli/dist/services/synthetic-baseline-runner.d.ts.map +1 -1
- package/pd-cli/dist/services/synthetic-baseline-runner.js +2 -0
- package/pd-cli/dist/services/synthetic-baseline-runner.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/pd-mcp-server/dist/log-file.js +9 -2
- package/pd-mcp-server/dist/server.d.ts +52 -2
- package/pd-mcp-server/dist/server.js +40 -4
- package/pd-mcp-server/dist/submit-assembly.js +85 -12
- 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 +1 -1
- package/plugin/dist/bundle.js +761 -722
- package/plugin/dist/commands/focus.d.ts +10 -7
- package/plugin/dist/commands/strategy.d.ts +10 -0
- package/plugin/dist/core/focus-history.d.ts +9 -49
- package/plugin/dist/core/paths.d.ts +6 -53
- package/plugin/dist/governance-audit.js +2 -2
- package/plugin/dist/hooks/prompt-helpers.d.ts +6 -5
- package/plugin/dist/hooks/prompt-types.d.ts +6 -6
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/dist/rulehost-evidence.js +29 -29
- package/plugin/dist/templates/workspace/okr/RECOVERY_PROTOCOL.md +8 -7
- package/plugin/dist/utils/io.d.ts +1 -1
- package/plugin/dist/utils/workspace-resolver.d.ts +0 -20
- package/plugin/mcp/launcher.cjs +159 -35
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/plugin/templates/workspace/okr/RECOVERY_PROTOCOL.md +8 -7
- package/release-manager/dist/installer.js +596 -100
- package/release-manager/dist/installers/codex-host-installer.js +36 -20
- package/release-manager/dist/installers/index.js +24 -3
- package/release-manager/dist/installers/mcp-registration-conflict.js +23 -16
- package/release-manager/dist/installers/openclaw-host-installer.js +1 -8
- package/release-manager/dist/installers/workbuddy-host-installer.js +7 -7
- package/release-manager/dist/mvp-config.js +49 -16
- package/release-manager/dist/update/release-manager.js +5 -2
- package/release-manager/dist/utils/env.js +91 -34
- package/release-manager/dist/utils/host-workspace-ownership.js +153 -2
- package/release-manager/package.json +2 -2
- package/workbuddy-adapter/dist/index.d.ts +1 -1
- package/workbuddy-adapter/dist/index.js +1 -1
- package/workbuddy-adapter/dist/ingestion/catch-up.js +15 -3
- package/workbuddy-adapter/dist/ingestion/index.d.ts +1 -1
- package/workbuddy-adapter/dist/ingestion/index.js +1 -1
- package/workbuddy-adapter/dist/ingestion/ingestion.d.ts +18 -0
- package/workbuddy-adapter/dist/ingestion/ingestion.js +20 -2
- package/workbuddy-adapter/dist/ingestion/transcript-path.d.ts +13 -4
- package/workbuddy-adapter/dist/ingestion/transcript-path.js +102 -4
- package/workbuddy-adapter/dist/ingestion/transcript-source.js +76 -58
- package/workbuddy-adapter/dist/pd-hook.js +10 -3
- package/workbuddy-adapter/dist/worker/workspace-worker.js +4 -1
- package/workbuddy-adapter/dist/workspace-resolution.d.ts +9 -2
- package/workbuddy-adapter/dist/workspace-resolution.js +19 -3
- package/workbuddy-adapter/package.json +1 -1
- package/workbuddy-adapter/plugin/mcp/launcher.cjs +159 -35
- package/plugin/dist/templates/workspace/okr/CURRENT_FOCUS.md +0 -56
- package/plugin/dist/templates/workspace/okr/TASK_CHANGES.jsonl +0 -6
- package/plugin/dist/templates/workspace/okr/WEEK_TASKS.json +0 -6
- package/plugin/templates/workspace/okr/CURRENT_FOCUS.md +0 -56
- package/plugin/templates/workspace/okr/TASK_CHANGES.jsonl +0 -6
- package/plugin/templates/workspace/okr/WEEK_TASKS.json +0 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-workspace-ownership.js","sourceRoot":"","sources":["../../src/utils/host-workspace-ownership.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,aAAa,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"host-workspace-ownership.js","sourceRoot":"","sources":["../../src/utils/host-workspace-ownership.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,aAAa,MAAM,4BAA4B,CAAC;AAW5D,MAAM,aAAa,GAA8B,CAAC,UAAU,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AAEpF,SAAS,mBAAmB,CAC1B,IAAoB,EACpB,OAAsC;IAEtC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,KAAK,SAAS;QAC/C,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;QACjC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IA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GAAwC,IAAI,IAAI;SAC/D,CAAC;IACJ,CAAC;IACD,OAAO,iCAAiC,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC"}
|
|
@@ -28,6 +28,12 @@ export interface AdaptiveBackgroundDiagnostic {
|
|
|
28
28
|
readonly status: string;
|
|
29
29
|
readonly reason: string;
|
|
30
30
|
readonly sends: number;
|
|
31
|
+
/**
|
|
32
|
+
* Principle Context S-state (SPEC v1.1 sect 5.4.1) projected verbatim from
|
|
33
|
+
* the shared provider line; absent when the turn never reached selection.
|
|
34
|
+
* Bounded enum — never context text.
|
|
35
|
+
*/
|
|
36
|
+
readonly principleContext?: 'sent' | 'unauthorized' | 'unavailable' | 'dropped_budget';
|
|
31
37
|
}
|
|
32
38
|
export type AdaptiveBackgroundSelectionOutcome = {
|
|
33
39
|
readonly status: 'selected';
|
|
@@ -71,7 +71,10 @@ export async function runAdaptiveBackgroundSelection(input) {
|
|
|
71
71
|
// already rendered by the time the process exits.
|
|
72
72
|
outputReserveMs: 0,
|
|
73
73
|
onDiagnostic: (line) => {
|
|
74
|
-
diagnostic = {
|
|
74
|
+
diagnostic = {
|
|
75
|
+
status: line.status, reason: line.reason, sends: line.sends,
|
|
76
|
+
...(line.principleContext !== undefined ? { principleContext: line.principleContext } : {}),
|
|
77
|
+
};
|
|
75
78
|
},
|
|
76
79
|
});
|
|
77
80
|
if (!resolution.ok) {
|
|
@@ -28,9 +28,16 @@ export declare const ADAPTIVE_DECISION_INSUFFICIENT_QUESTION = "insufficient_con
|
|
|
28
28
|
* (incoming value, outgoing safety). The append path keeps the single
|
|
29
29
|
* condition of v2 unchanged, which is why the version bump is required to
|
|
30
30
|
* tell the two evidence generations apart.
|
|
31
|
+
*
|
|
32
|
+
* v4 (Principle Context, SPEC v1.1 sect 5.4): a NEW evidence generation. When
|
|
33
|
+
* the request state carries `principleContext`, every question's instructions
|
|
34
|
+
* gain the supplemental-background clause; without it the instructions stay
|
|
35
|
+
* byte-identical to v3 (S1-S3 keep v3 scoring semantics). Current Instruction
|
|
36
|
+
* remains the PRIMARY basis; the context is background data, never a command,
|
|
37
|
+
* and keyword matches in it never justify promotion or replacement.
|
|
31
38
|
*/
|
|
32
39
|
export declare const ADAPTIVE_DECISION_CRITERIA: {
|
|
33
|
-
readonly version: '
|
|
40
|
+
readonly version: 'v4-20261116';
|
|
34
41
|
/** A candidate (and, when it replaces something, its safety condition) must reach this score. */
|
|
35
42
|
readonly selectThreshold: 0.7;
|
|
36
43
|
/** Above this "information is insufficient" score, PD refuses to select. */
|
|
@@ -66,6 +73,13 @@ export interface BuildDecisionRequestInput {
|
|
|
66
73
|
readonly digest: string;
|
|
67
74
|
readonly replaces?: string;
|
|
68
75
|
}[];
|
|
76
|
+
/**
|
|
77
|
+
* Principle Context (SPEC v1.1 sect 5.2): normalized Owner background,
|
|
78
|
+
* present ONLY on an authorized, in-budget turn. Travels inside the `state`
|
|
79
|
+
* JSON string (layer 3 of the four-layer serialization contract) as an
|
|
80
|
+
* optional key — never as an envelope field.
|
|
81
|
+
*/
|
|
82
|
+
readonly principleContext?: string;
|
|
69
83
|
/** Bounded by the caller; a request larger than this is refused locally. */
|
|
70
84
|
readonly maxPayloadChars: number;
|
|
71
85
|
}
|
|
@@ -96,7 +110,9 @@ export declare function buildDecisionQuestions(candidates: readonly {
|
|
|
96
110
|
readonly ref: string;
|
|
97
111
|
readonly text: string;
|
|
98
112
|
readonly replaces?: string;
|
|
99
|
-
}[]
|
|
113
|
+
}[], options?: {
|
|
114
|
+
readonly withPrincipleContext?: boolean;
|
|
115
|
+
}): DecisionQuestions;
|
|
100
116
|
export declare function buildDecisionRequest(input: BuildDecisionRequestInput): BuildDecisionRequestResult;
|
|
101
117
|
/**
|
|
102
118
|
* Model identity is exact against an explicit allowlist when one is frozen
|
|
@@ -28,9 +28,16 @@ export const ADAPTIVE_DECISION_INSUFFICIENT_QUESTION = 'insufficient_context';
|
|
|
28
28
|
* (incoming value, outgoing safety). The append path keeps the single
|
|
29
29
|
* condition of v2 unchanged, which is why the version bump is required to
|
|
30
30
|
* tell the two evidence generations apart.
|
|
31
|
+
*
|
|
32
|
+
* v4 (Principle Context, SPEC v1.1 sect 5.4): a NEW evidence generation. When
|
|
33
|
+
* the request state carries `principleContext`, every question's instructions
|
|
34
|
+
* gain the supplemental-background clause; without it the instructions stay
|
|
35
|
+
* byte-identical to v3 (S1-S3 keep v3 scoring semantics). Current Instruction
|
|
36
|
+
* remains the PRIMARY basis; the context is background data, never a command,
|
|
37
|
+
* and keyword matches in it never justify promotion or replacement.
|
|
31
38
|
*/
|
|
32
39
|
export const ADAPTIVE_DECISION_CRITERIA = {
|
|
33
|
-
version: '
|
|
40
|
+
version: 'v4-20261116',
|
|
34
41
|
/** A candidate (and, when it replaces something, its safety condition) must reach this score. */
|
|
35
42
|
selectThreshold: 0.7,
|
|
36
43
|
/** Above this "information is insufficient" score, PD refuses to select. */
|
|
@@ -57,22 +64,36 @@ export function candidateSafetyQuestionId(ref) {
|
|
|
57
64
|
* next required step, and whether this turn can afford to drop the outgoing
|
|
58
65
|
* principle. Both must clear the same threshold. The append path is untouched.
|
|
59
66
|
*/
|
|
60
|
-
export function buildDecisionQuestions(candidates) {
|
|
67
|
+
export function buildDecisionQuestions(candidates, options) {
|
|
68
|
+
// Criteria v4 (SPEC v1.1 sect 5.4): the instructions branch on whether the
|
|
69
|
+
// request state carries principleContext. WITHOUT it the strings are
|
|
70
|
+
// byte-identical to v3 (S1-S3 keep v3 scoring semantics); WITH it each
|
|
71
|
+
// applicability/value question gains the supplemental-background clause and
|
|
72
|
+
// the anti-keyword guard. The question ID set itself never changes.
|
|
73
|
+
const withCtx = options?.withPrincipleContext === true;
|
|
61
74
|
const questions = {};
|
|
62
75
|
for (const candidate of candidates) {
|
|
63
76
|
if (candidate.replaces === undefined) {
|
|
64
77
|
questions[candidateQuestionId(candidate.ref)] = {
|
|
65
78
|
type: 'noul',
|
|
66
|
-
instructions:
|
|
67
|
-
|
|
79
|
+
instructions: (withCtx
|
|
80
|
+
? `依据 currentInstruction(并结合可用的 state.principleContext 作为补充背景)判断用户现在要做什么,并比较 state.candidates。候选 ${candidate.ref} 是否直接适用于这项任务,且最能改善下一步具体行动?`
|
|
81
|
+
: `依据 currentInstruction 判断用户现在要做什么,并比较 state.candidates。候选 ${candidate.ref} 是否直接适用于这项任务,且最能改善下一步具体行动?`)
|
|
82
|
+
+ (withCtx
|
|
83
|
+
? '能避免当前任务的具体失误或补上关键步骤时给高分。仅主题相近、重复用户已明确的要求、或对下一步没有实质帮助时给低分。principleContext 只是背景,不足以单独支撑适用性时不要给高分。没有合适候选时全部给低分。'
|
|
84
|
+
: '能避免当前任务的具体失误或补上关键步骤时给高分。仅主题相近、重复用户已明确的要求、或对下一步没有实质帮助时给低分。没有合适候选时全部给低分。'),
|
|
68
85
|
};
|
|
69
86
|
continue;
|
|
70
87
|
}
|
|
71
88
|
questions[candidateValueQuestionId(candidate.ref)] = {
|
|
72
89
|
type: 'noul',
|
|
73
|
-
instructions:
|
|
90
|
+
instructions: (withCtx
|
|
91
|
+
? `依据 currentInstruction(并结合可用的 state.principleContext 作为补充背景)判断用户现在要求完成的下一步,并比较 state.candidates。候选 ${candidate.ref} 是否直接帮助完成这一步?`
|
|
92
|
+
: `依据 currentInstruction 判断用户现在要求完成的下一步,并比较 state.candidates。候选 ${candidate.ref} 是否直接帮助完成这一步?`)
|
|
74
93
|
+ '为完成这一步所需的核对、验证和证据整理也算直接帮助,即使用户没有逐字说出这些动作。'
|
|
75
|
-
+
|
|
94
|
+
+ (withCtx
|
|
95
|
+
? '仅主题相近、重复用户已明确的要求、或对下一步没有实质帮助时给低分。principleContext 中出现该原则不等于它更适合本任务。没有合适候选时全部给低分。'
|
|
96
|
+
: '仅主题相近、重复用户已明确的要求、或对下一步没有实质帮助时给低分。没有合适候选时全部给低分。'),
|
|
76
97
|
};
|
|
77
98
|
questions[candidateSafetyQuestionId(candidate.ref)] = {
|
|
78
99
|
type: 'noul',
|
|
@@ -83,8 +104,12 @@ export function buildDecisionQuestions(candidates) {
|
|
|
83
104
|
}
|
|
84
105
|
questions[ADAPTIVE_DECISION_INSUFFICIENT_QUESTION] = {
|
|
85
106
|
type: 'noul',
|
|
86
|
-
instructions:
|
|
87
|
-
|
|
107
|
+
instructions: withCtx
|
|
108
|
+
? '信息不足:当前 currentInstruction(以及可用的 state.principleContext)是否缺少判断候选是否适用所需的信息'
|
|
109
|
+
+ '(例如只有确认词、指代不明、不知道在问哪一个任务)?信息不足时概率接近 1;能够明确判断时为 0。'
|
|
110
|
+
+ 'principleContext 缺失本身不是信息不足;只有输入确实无法可靠判断时才给高分。'
|
|
111
|
+
: '信息不足:当前输入是否缺少判断候选是否适用所需的信息(例如只有确认词、指代不明、'
|
|
112
|
+
+ '不知道在问哪一个任务)?信息不足时概率接近 1;能够明确判断时为 0。',
|
|
88
113
|
};
|
|
89
114
|
return questions;
|
|
90
115
|
}
|
|
@@ -92,7 +117,9 @@ export function buildDecisionRequest(input) {
|
|
|
92
117
|
if (input.candidates.length === 0) {
|
|
93
118
|
return { ok: false, reason: 'INPUT_REFUSED' };
|
|
94
119
|
}
|
|
95
|
-
const questions = buildDecisionQuestions(input.candidates
|
|
120
|
+
const questions = buildDecisionQuestions(input.candidates, {
|
|
121
|
+
withPrincipleContext: input.principleContext !== undefined,
|
|
122
|
+
});
|
|
96
123
|
const state = {
|
|
97
124
|
currentInstruction: input.currentInstruction,
|
|
98
125
|
priorMessages: input.priorMessages,
|
|
@@ -102,6 +129,9 @@ export function buildDecisionRequest(input) {
|
|
|
102
129
|
digest: candidate.digest,
|
|
103
130
|
...(candidate.replaces !== undefined ? { replaces: candidate.replaces } : {}),
|
|
104
131
|
})),
|
|
132
|
+
// Layer 3 (SPEC v1.1 sect 5.2): the context lives INSIDE the state JSON
|
|
133
|
+
// string as an optional key. No empty-string placeholder, no null.
|
|
134
|
+
...(input.principleContext !== undefined ? { principleContext: input.principleContext } : {}),
|
|
105
135
|
};
|
|
106
136
|
const body = {
|
|
107
137
|
model: input.model,
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** Fixed relative target (SPEC §4.7: never composed from Context content). */
|
|
2
|
+
export declare const PRINCIPLE_CONTEXT_SEGMENTS: readonly ['memory', 'okr', 'CURRENT_FOCUS.md'];
|
|
3
|
+
export declare const PRINCIPLE_CONTEXT_LIMITS: {
|
|
4
|
+
/** Raw file ceiling checked BEFORE reading (SPEC §4.4). */
|
|
5
|
+
readonly maxRawFileBytes: 65536;
|
|
6
|
+
/** Read buffer bound: one byte past the ceiling detects post-stat growth. */
|
|
7
|
+
readonly maxReadBytes: 65537;
|
|
8
|
+
/** Normalized context ceiling in JavaScript UTF-16 code units (no truncation). */
|
|
9
|
+
readonly maxContextChars: 4000;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The ONLY reason-code standard (SPEC §4.7 / TD §3.2). The four-value status
|
|
13
|
+
* below is a display grouping; `invalid` is a status, never a reason code.
|
|
14
|
+
*/
|
|
15
|
+
export type PrincipleContextReason = 'file_missing' | 'unreadable' | 'unsafe_path' | 'too_large' | 'read_failed' | 'empty_content' | 'normalize_failed';
|
|
16
|
+
export type PrincipleContextRead = {
|
|
17
|
+
readonly status: 'available';
|
|
18
|
+
readonly text: string;
|
|
19
|
+
} | {
|
|
20
|
+
readonly status: 'missing';
|
|
21
|
+
readonly reason: 'file_missing' | 'empty_content';
|
|
22
|
+
} | {
|
|
23
|
+
readonly status: 'invalid';
|
|
24
|
+
readonly reason: 'unsafe_path' | 'too_large' | 'normalize_failed';
|
|
25
|
+
} | {
|
|
26
|
+
readonly status: 'unreadable';
|
|
27
|
+
readonly reason: 'unreadable' | 'read_failed';
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Cross-platform containment via path.relative — NEVER a string-prefix test.
|
|
31
|
+
* `startsWith(root + sep)` misjudges drive/slash boundaries (e.g. `C:\\abc`
|
|
32
|
+
* vs `C:\\abc-def`, mixed separators) and POSIX root. path.relative returns:
|
|
33
|
+
* - `''` → candidate IS root (equal);
|
|
34
|
+
* - a relative path → candidate is inside root;
|
|
35
|
+
* - an absolute path or one starting with `..` → outside.
|
|
36
|
+
* Separator normalization keeps mixed-separator strings (Windows APIs may
|
|
37
|
+
* return either) from producing a false `..` escape.
|
|
38
|
+
*
|
|
39
|
+
* Exported for in-package test surface only (this module is deliberately not
|
|
40
|
+
* on the package barrel): the containment predicate's boundary behavior is
|
|
41
|
+
* part of the security contract and is asserted directly.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isWithin(root: string, candidate: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Deterministic in-memory normalization (SPEC §4.3): strict UTF-8 decode →
|
|
46
|
+
* strip BOM → CRLF to LF → trim outer whitespace. No truncation, no semantic
|
|
47
|
+
* rewriting, no folding of internal Markdown structure.
|
|
48
|
+
*/
|
|
49
|
+
export declare function normalizePrincipleContextText(raw: Buffer): {
|
|
50
|
+
readonly ok: true;
|
|
51
|
+
readonly text: string;
|
|
52
|
+
} | {
|
|
53
|
+
readonly ok: false;
|
|
54
|
+
readonly reason: 'normalize_failed' | 'empty_content';
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Execution-budget binding (SPEC §5.8 / TD §3.3): the Reader participates in
|
|
58
|
+
* the host's Adaptive window instead of running on an unbounded clock. The
|
|
59
|
+
* checks are COOPERATIVE stage gates placed before EVERY new I/O stage:
|
|
60
|
+
* before the root resolve, before each parent level, before open, and then
|
|
61
|
+
* open → gate → stat → gate → size validation → gate → read (plus a gate
|
|
62
|
+
* after the read, which discards an over-budget result) — Node's promise-based
|
|
63
|
+
* lstat/realpath/open and `FileHandle.read` accept NO AbortSignal, so an
|
|
64
|
+
* in-flight single I/O call cannot be truly cancelled by Node core APIs. What
|
|
65
|
+
* the deadline guarantees is therefore: once the budget is exhausted, no
|
|
66
|
+
* FURTHER I/O starts and the turn fails closed to "no context"; an
|
|
67
|
+
* already-started handle.read finishes bounded (≤65,537 bytes) and its result
|
|
68
|
+
* is discarded. This is disclosed as a residual limitation, not claimed as
|
|
69
|
+
* true cancellation.
|
|
70
|
+
*/
|
|
71
|
+
export interface PrincipleContextReaderBudget {
|
|
72
|
+
/** Absolute host deadline (epoch ms); the provider passes its host window. */
|
|
73
|
+
readonly deadlineAt?: number;
|
|
74
|
+
/** Cooperative abort signal (checked at every stage gate). */
|
|
75
|
+
readonly signal?: AbortSignal;
|
|
76
|
+
/** Test seam; production uses Date.now. */
|
|
77
|
+
readonly now?: () => number;
|
|
78
|
+
}
|
|
79
|
+
export declare function readPrincipleContext(workspaceDir: string, budget?: PrincipleContextReaderBudget): Promise<PrincipleContextRead>;
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Principle Context Reader (SPEC v1.1 §4/§4.7, Technical Design v0.3 §3).
|
|
3
|
+
*
|
|
4
|
+
* host-runtime PRIVATE implementation: this module is deliberately NOT
|
|
5
|
+
* re-exported from the package barrel and forms no public Context API. All
|
|
6
|
+
* three hosts reach it through the shared adaptive provider only.
|
|
7
|
+
*
|
|
8
|
+
* Contract summary (TD §3.2/§3.3 is the authority):
|
|
9
|
+
* - The single data source is `<workspaceDir>/memory/okr/CURRENT_FOCUS.md`,
|
|
10
|
+
* the Owner-maintained Principle Context file. The whole file is the
|
|
11
|
+
* context; no Markdown region parsing, no new PRINCIPLE_CONTEXT.md.
|
|
12
|
+
* - Read-only forever: no create, no repair, no backup, no mkdir. The Owner's
|
|
13
|
+
* bytes are never modified (normalization works on an in-memory copy).
|
|
14
|
+
* - Path safety: canonical workspace root (realpath), then a per-level lstat
|
|
15
|
+
* walk (memory → memory/okr → the file) rejecting symlinks / Windows
|
|
16
|
+
* junction-reparse entries, plus a realpath containment check at each level.
|
|
17
|
+
* Only after that is a FileHandle opened, and only that handle is read.
|
|
18
|
+
* `fstat` does NOT return a path — containment comes from the root + the
|
|
19
|
+
* lstat/realpath walk; the handle stat only proves "regular file + identity
|
|
20
|
+
* + size" (do not claim fstat proves path location).
|
|
21
|
+
* - Identity: the identity measured for the target during path validation is
|
|
22
|
+
* compared with the identity of the OBJECT the handle actually opened
|
|
23
|
+
* (`handle.stat()`). POSIX compares dev+ino (reliable same-object identity
|
|
24
|
+
* within a run). Windows has no usable inode semantics in Node's Stats, so
|
|
25
|
+
* only a best-effort WEAK fingerprint (birthtimeMs + size) is compared: a
|
|
26
|
+
* mismatch is a replacement signal (fail-closed), but a match does NOT prove
|
|
27
|
+
* the file was not replaced. The resolved path cannot participate in that
|
|
28
|
+
* comparison: `fstat` returns no path, and the path the handle was opened
|
|
29
|
+
* from is exactly the path validated in step 2. TOCTOU residual risk is NOT
|
|
30
|
+
* eliminated and is not claimed to be (no platform-native extensions).
|
|
31
|
+
* - All failures fail closed into the seven-value reason enum below; the
|
|
32
|
+
* reader never throws into the host prompt path and never returns raw OS
|
|
33
|
+
* errors, absolute paths, or context text in its diagnostics.
|
|
34
|
+
*/
|
|
35
|
+
import * as fs from 'node:fs';
|
|
36
|
+
import * as path from 'node:path';
|
|
37
|
+
/** Fixed relative target (SPEC §4.7: never composed from Context content). */
|
|
38
|
+
export const PRINCIPLE_CONTEXT_SEGMENTS = ['memory', 'okr', 'CURRENT_FOCUS.md'];
|
|
39
|
+
export const PRINCIPLE_CONTEXT_LIMITS = {
|
|
40
|
+
/** Raw file ceiling checked BEFORE reading (SPEC §4.4). */
|
|
41
|
+
maxRawFileBytes: 65_536,
|
|
42
|
+
/** Read buffer bound: one byte past the ceiling detects post-stat growth. */
|
|
43
|
+
maxReadBytes: 65_537,
|
|
44
|
+
/** Normalized context ceiling in JavaScript UTF-16 code units (no truncation). */
|
|
45
|
+
maxContextChars: 4_000,
|
|
46
|
+
};
|
|
47
|
+
function isErrnoException(value) {
|
|
48
|
+
return value instanceof Error && typeof value.code === 'string';
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Cross-platform containment via path.relative — NEVER a string-prefix test.
|
|
52
|
+
* `startsWith(root + sep)` misjudges drive/slash boundaries (e.g. `C:\\abc`
|
|
53
|
+
* vs `C:\\abc-def`, mixed separators) and POSIX root. path.relative returns:
|
|
54
|
+
* - `''` → candidate IS root (equal);
|
|
55
|
+
* - a relative path → candidate is inside root;
|
|
56
|
+
* - an absolute path or one starting with `..` → outside.
|
|
57
|
+
* Separator normalization keeps mixed-separator strings (Windows APIs may
|
|
58
|
+
* return either) from producing a false `..` escape.
|
|
59
|
+
*
|
|
60
|
+
* Exported for in-package test surface only (this module is deliberately not
|
|
61
|
+
* on the package barrel): the containment predicate's boundary behavior is
|
|
62
|
+
* part of the security contract and is asserted directly.
|
|
63
|
+
*/
|
|
64
|
+
export function isWithin(root, candidate) {
|
|
65
|
+
const rel = path.relative(root, candidate);
|
|
66
|
+
if (rel === '')
|
|
67
|
+
return true;
|
|
68
|
+
const normalized = rel.split(path.sep).join('/');
|
|
69
|
+
return !normalized.startsWith('../') && normalized !== '..' && !path.isAbsolute(normalized);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Windows junctions / reparse points surface through Node's lstat as symbolic
|
|
73
|
+
* links on modern Node, so one predicate covers both platforms. Anything that
|
|
74
|
+
* is not a plain directory/file (FIFO, device, socket) is rejected as well.
|
|
75
|
+
*/
|
|
76
|
+
function isForbiddenEntry(stats, expect) {
|
|
77
|
+
if (stats.isSymbolicLink())
|
|
78
|
+
return true;
|
|
79
|
+
return expect === 'directory' ? !stats.isDirectory() : !stats.isFile();
|
|
80
|
+
}
|
|
81
|
+
function identityOf(stats) {
|
|
82
|
+
return { dev: stats.dev, ino: stats.ino, birthtimeMs: stats.birthtimeMs, size: stats.size };
|
|
83
|
+
}
|
|
84
|
+
const IS_WINDOWS = process.platform === 'win32';
|
|
85
|
+
/**
|
|
86
|
+
* Same-object comparison, used both for "validated target vs opened handle"
|
|
87
|
+
* (the TOCTOU closure) and "opened vs post-read" (mid-read replacement).
|
|
88
|
+
* POSIX: dev+ino is a reliable identity within this run. Windows: best-effort
|
|
89
|
+
* weak fingerprint — a MISMATCH proves replacement (fail-closed), but a MATCH
|
|
90
|
+
* does NOT prove the file is unchanged (two different files can share size and
|
|
91
|
+
* birth time). Never present this as inode-equivalent proof.
|
|
92
|
+
*/
|
|
93
|
+
function identityMatches(opened, current) {
|
|
94
|
+
if (!IS_WINDOWS)
|
|
95
|
+
return opened.dev === current.dev && opened.ino === current.ino;
|
|
96
|
+
// Weak fingerprint only (documented best-effort, not an identity proof).
|
|
97
|
+
return opened.birthtimeMs === current.birthtimeMs && opened.size === current.size;
|
|
98
|
+
}
|
|
99
|
+
const UTF8_FATAL = new TextDecoder('utf-8', { fatal: true });
|
|
100
|
+
/**
|
|
101
|
+
* Deterministic in-memory normalization (SPEC §4.3): strict UTF-8 decode →
|
|
102
|
+
* strip BOM → CRLF to LF → trim outer whitespace. No truncation, no semantic
|
|
103
|
+
* rewriting, no folding of internal Markdown structure.
|
|
104
|
+
*/
|
|
105
|
+
export function normalizePrincipleContextText(raw) {
|
|
106
|
+
let text;
|
|
107
|
+
try {
|
|
108
|
+
text = UTF8_FATAL.decode(raw);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return { ok: false, reason: 'normalize_failed' };
|
|
112
|
+
}
|
|
113
|
+
if (text.charCodeAt(0) === 0xfeff)
|
|
114
|
+
text = text.slice(1);
|
|
115
|
+
text = text.replace(/\r\n/gu, '\n');
|
|
116
|
+
text = text.trim();
|
|
117
|
+
if (text.length === 0)
|
|
118
|
+
return { ok: false, reason: 'empty_content' };
|
|
119
|
+
if (text.length > PRINCIPLE_CONTEXT_LIMITS.maxContextChars) {
|
|
120
|
+
// Over the ceiling is invalid — never truncate to fit.
|
|
121
|
+
return { ok: false, reason: 'normalize_failed' };
|
|
122
|
+
}
|
|
123
|
+
return { ok: true, text };
|
|
124
|
+
}
|
|
125
|
+
function isAbsoluteRegularPath(value) {
|
|
126
|
+
return typeof value === 'string' && value.length > 0 && path.isAbsolute(value);
|
|
127
|
+
}
|
|
128
|
+
async function resolveCanonicalRoot(workspaceDir) {
|
|
129
|
+
try {
|
|
130
|
+
const root = await fs.promises.realpath(workspaceDir);
|
|
131
|
+
return isAbsoluteRegularPath(root) ? root : null;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
export async function readPrincipleContext(workspaceDir, budget = {}) {
|
|
138
|
+
const now = budget.now ?? Date.now;
|
|
139
|
+
// Stage gate: `pre-open` exhaustion maps to `unreadable` (nothing was
|
|
140
|
+
// opened); `post-open` exhaustion maps to `read_failed` (an open handle
|
|
141
|
+
// exists). Both are inside the seven-value reason enum.
|
|
142
|
+
const budgetExhausted = () => {
|
|
143
|
+
if (budget.signal?.aborted === true)
|
|
144
|
+
return true;
|
|
145
|
+
return budget.deadlineAt !== undefined && now() >= budget.deadlineAt;
|
|
146
|
+
};
|
|
147
|
+
const preOpenExhausted = () => ({ status: 'unreadable', reason: 'unreadable' });
|
|
148
|
+
const postOpenExhausted = () => ({ status: 'unreadable', reason: 'read_failed' });
|
|
149
|
+
if (!isAbsoluteRegularPath(workspaceDir)) {
|
|
150
|
+
return { status: 'invalid', reason: 'unsafe_path' };
|
|
151
|
+
}
|
|
152
|
+
if (budgetExhausted())
|
|
153
|
+
return preOpenExhausted();
|
|
154
|
+
// Step 1 — canonical workspace root. A root that cannot be resolved is
|
|
155
|
+
// unsafe to derive containment from (TD §3.3 step 1).
|
|
156
|
+
const root = await resolveCanonicalRoot(workspaceDir);
|
|
157
|
+
if (root === null)
|
|
158
|
+
return { status: 'invalid', reason: 'unsafe_path' };
|
|
159
|
+
// Step 2 — per-level validation of the fixed parent chain.
|
|
160
|
+
let current = root;
|
|
161
|
+
const segments = PRINCIPLE_CONTEXT_SEGMENTS;
|
|
162
|
+
let targetPath = root;
|
|
163
|
+
// The identity path validation measured for the target. The opened handle
|
|
164
|
+
// must describe THIS object, not merely a self-consistent one (TOCTOU).
|
|
165
|
+
let validatedTargetIdentity = null;
|
|
166
|
+
for (let index = 0; index < segments.length; index++) {
|
|
167
|
+
if (budgetExhausted())
|
|
168
|
+
return preOpenExhausted();
|
|
169
|
+
const segment = segments[index];
|
|
170
|
+
// noUncheckedIndexedAccess: an out-of-range read is impossible for this
|
|
171
|
+
// fixed tuple; fail closed rather than casting.
|
|
172
|
+
if (segment === undefined)
|
|
173
|
+
return { status: 'invalid', reason: 'unsafe_path' };
|
|
174
|
+
const isLast = index === segments.length - 1;
|
|
175
|
+
current = path.join(current, segment);
|
|
176
|
+
targetPath = current;
|
|
177
|
+
let stats;
|
|
178
|
+
try {
|
|
179
|
+
stats = await fs.promises.lstat(current);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
if (isErrnoException(error) && error.code === 'ENOENT')
|
|
183
|
+
return { status: 'missing', reason: 'file_missing' };
|
|
184
|
+
return { status: 'unreadable', reason: 'unreadable' };
|
|
185
|
+
}
|
|
186
|
+
if (isForbiddenEntry(stats, isLast ? 'file' : 'directory')) {
|
|
187
|
+
return { status: 'invalid', reason: 'unsafe_path' };
|
|
188
|
+
}
|
|
189
|
+
if (isLast)
|
|
190
|
+
validatedTargetIdentity = identityOf(stats);
|
|
191
|
+
if (budgetExhausted())
|
|
192
|
+
return preOpenExhausted();
|
|
193
|
+
let resolved;
|
|
194
|
+
try {
|
|
195
|
+
resolved = await fs.promises.realpath(current);
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return { status: 'invalid', reason: 'unsafe_path' };
|
|
199
|
+
}
|
|
200
|
+
if (!isWithin(root, resolved))
|
|
201
|
+
return { status: 'invalid', reason: 'unsafe_path' };
|
|
202
|
+
}
|
|
203
|
+
// Unreachable for the fixed tuple, but never open without a validated
|
|
204
|
+
// identity: the TOCTOU comparison below must have a left-hand side.
|
|
205
|
+
if (validatedTargetIdentity === null)
|
|
206
|
+
return { status: 'invalid', reason: 'unsafe_path' };
|
|
207
|
+
// Step 3 — handle-based bounded read. The path was validated level by level
|
|
208
|
+
// above; from here only the opened handle is trusted. O_NOFOLLOW where the
|
|
209
|
+
// platform provides it; elsewhere the lstat walk above is the guard.
|
|
210
|
+
if (budgetExhausted())
|
|
211
|
+
return preOpenExhausted();
|
|
212
|
+
const flags = fs.constants.O_RDONLY
|
|
213
|
+
| (fs.constants.O_NOFOLLOW !== undefined && !IS_WINDOWS ? fs.constants.O_NOFOLLOW : 0);
|
|
214
|
+
let handle;
|
|
215
|
+
try {
|
|
216
|
+
handle = await fs.promises.open(targetPath, flags);
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
if (isErrnoException(error) && error.code === 'ENOENT')
|
|
220
|
+
return { status: 'missing', reason: 'file_missing' };
|
|
221
|
+
if (isErrnoException(error) && error.code === 'ELOOP')
|
|
222
|
+
return { status: 'invalid', reason: 'unsafe_path' };
|
|
223
|
+
return { status: 'unreadable', reason: 'unreadable' };
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
if (budgetExhausted())
|
|
227
|
+
return postOpenExhausted();
|
|
228
|
+
let openedStats;
|
|
229
|
+
try {
|
|
230
|
+
openedStats = await handle.stat();
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return { status: 'unreadable', reason: 'read_failed' };
|
|
234
|
+
}
|
|
235
|
+
if (!openedStats.isFile())
|
|
236
|
+
return { status: 'invalid', reason: 'unsafe_path' };
|
|
237
|
+
// Stage gate: `handle.stat()` itself may have consumed the last budget.
|
|
238
|
+
// No new I/O (and no body read) may start after that.
|
|
239
|
+
if (budgetExhausted())
|
|
240
|
+
return postOpenExhausted();
|
|
241
|
+
// TOCTOU closure (TD §3.3 step 3): the handle must describe the SAME
|
|
242
|
+
// object path validation measured. Path validation proved the location;
|
|
243
|
+
// this proves the opened object, so a swap between validation and open
|
|
244
|
+
// (file or parent directory) fails closed before one byte is read.
|
|
245
|
+
if (!identityMatches(identityOf(openedStats), validatedTargetIdentity)) {
|
|
246
|
+
return { status: 'unreadable', reason: 'read_failed' };
|
|
247
|
+
}
|
|
248
|
+
// The hard raw-file ceiling applies BEFORE reading (SPEC §4.7 #5).
|
|
249
|
+
if (openedStats.size > PRINCIPLE_CONTEXT_LIMITS.maxRawFileBytes) {
|
|
250
|
+
return { status: 'invalid', reason: 'too_large' };
|
|
251
|
+
}
|
|
252
|
+
if (budgetExhausted())
|
|
253
|
+
return postOpenExhausted();
|
|
254
|
+
const buffer = Buffer.alloc(PRINCIPLE_CONTEXT_LIMITS.maxReadBytes);
|
|
255
|
+
let bytesRead;
|
|
256
|
+
try {
|
|
257
|
+
const { bytesRead: read } = await handle.read(buffer, 0, PRINCIPLE_CONTEXT_LIMITS.maxReadBytes, 0);
|
|
258
|
+
bytesRead = read;
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
return { status: 'unreadable', reason: 'read_failed' };
|
|
262
|
+
}
|
|
263
|
+
// The in-flight read could not be cancelled (Node API limitation — see
|
|
264
|
+
// the budget interface docs); if the budget ran out during it, discard
|
|
265
|
+
// the bytes instead of using them.
|
|
266
|
+
if (budgetExhausted())
|
|
267
|
+
return postOpenExhausted();
|
|
268
|
+
if (bytesRead > PRINCIPLE_CONTEXT_LIMITS.maxRawFileBytes) {
|
|
269
|
+
return { status: 'invalid', reason: 'too_large' };
|
|
270
|
+
}
|
|
271
|
+
// The read must describe the same object the stat measured.
|
|
272
|
+
if (bytesRead !== openedStats.size)
|
|
273
|
+
return { status: 'unreadable', reason: 'read_failed' };
|
|
274
|
+
// Best-effort replacement detection between open-time and post-read stat.
|
|
275
|
+
if (budgetExhausted())
|
|
276
|
+
return postOpenExhausted();
|
|
277
|
+
let postStats;
|
|
278
|
+
try {
|
|
279
|
+
postStats = await handle.stat();
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
return { status: 'unreadable', reason: 'read_failed' };
|
|
283
|
+
}
|
|
284
|
+
if (!postStats.isFile())
|
|
285
|
+
return { status: 'unreadable', reason: 'read_failed' };
|
|
286
|
+
if (!identityMatches(identityOf(openedStats), identityOf(postStats))) {
|
|
287
|
+
return { status: 'unreadable', reason: 'read_failed' };
|
|
288
|
+
}
|
|
289
|
+
if (postStats.size > PRINCIPLE_CONTEXT_LIMITS.maxRawFileBytes) {
|
|
290
|
+
return { status: 'invalid', reason: 'too_large' };
|
|
291
|
+
}
|
|
292
|
+
const normalized = normalizePrincipleContextText(buffer.subarray(0, bytesRead));
|
|
293
|
+
if (!normalized.ok) {
|
|
294
|
+
return normalized.reason === 'empty_content'
|
|
295
|
+
? { status: 'missing', reason: 'empty_content' }
|
|
296
|
+
: { status: 'invalid', reason: 'normalize_failed' };
|
|
297
|
+
}
|
|
298
|
+
return { status: 'available', text: normalized.text };
|
|
299
|
+
}
|
|
300
|
+
finally {
|
|
301
|
+
await handle.close().catch(() => undefined);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
@@ -12,6 +12,7 @@ import type { HostEvent } from '@principles/core/host';
|
|
|
12
12
|
import { type ActivatedPrinciple, type PdConfig } from '@principles/core/runtime';
|
|
13
13
|
import type { AdaptiveGapOptions } from './active-principle-prompt.js';
|
|
14
14
|
import { type AdaptiveSelectionModel } from './adaptive-selection.js';
|
|
15
|
+
import { readPrincipleContext } from './adaptive-principle-context-reader.js';
|
|
15
16
|
/** Independent switch. `features.host.codex.enabled` remains the whole-hook gate. */
|
|
16
17
|
export declare const ADAPTIVE_ACTIVATION_FLAG = "host.codex.adaptive_activation";
|
|
17
18
|
export type AdaptiveActivationFlag = typeof ADAPTIVE_ACTIVATION_FLAG | 'host.workbuddy.adaptive_activation' | 'host.openclaw.adaptive_activation';
|
|
@@ -72,6 +73,28 @@ export interface AdaptiveSelectionDiagnosticLine {
|
|
|
72
73
|
readonly reason: string;
|
|
73
74
|
readonly scores: Readonly<Record<string, number>>;
|
|
74
75
|
} | null;
|
|
76
|
+
/** S3 marker (SPEC v1.1 sect 5.3): the context was dropped for budget. */
|
|
77
|
+
readonly contextDropped: 'principle_context_dropped:budget' | null;
|
|
78
|
+
/**
|
|
79
|
+
* Principle Context participation for THIS turn (SPEC v1.1 sect 5.4.1
|
|
80
|
+
* S1–S4), a bounded enum so every host diagnostic surface can answer "did
|
|
81
|
+
* the context actually participate?" without any context text:
|
|
82
|
+
* - `unauthorized` — S1: not `=== true`; zero stat/read by construction.
|
|
83
|
+
* - `unavailable` — S2: authorized, the single bounded read attempt
|
|
84
|
+
* failed (the specific reason code rides in `failures`).
|
|
85
|
+
* - `dropped_budget` — S3: read completed; the field was removed for the
|
|
86
|
+
* 20K budget (`contextDropped` carries the marker).
|
|
87
|
+
* - `sent` — S4: a request that ACTUALLY CARRIED the context was
|
|
88
|
+
* really dispatched (`sends > 0`), i.e. `state` contained the field.
|
|
89
|
+
* A successful read whose turn never dispatched a request carrying it
|
|
90
|
+
* (input refused before send, deadline exhausted before send) is NOT
|
|
91
|
+
* `sent`; the field is then ABSENT and the line's status/reason/sends
|
|
92
|
+
* explain the turn — no fabricated fifth state.
|
|
93
|
+
* Absent on `skipped` lines: the turn never reached selection, so no
|
|
94
|
+
* S-state arose (and no reader I/O happened either way). Absent also when
|
|
95
|
+
* an authorized read produced text but no carrying request was sent.
|
|
96
|
+
*/
|
|
97
|
+
readonly principleContext?: 'sent' | 'unauthorized' | 'unavailable' | 'dropped_budget';
|
|
75
98
|
readonly failures: readonly string[];
|
|
76
99
|
}
|
|
77
100
|
export interface CreateAdaptivePriorityProviderOptions {
|
|
@@ -101,6 +124,16 @@ export interface CreateAdaptivePriorityProviderOptions {
|
|
|
101
124
|
readonly now?: () => number;
|
|
102
125
|
/** Test seam: production uses the global transport. */
|
|
103
126
|
readonly fetchImpl?: typeof fetch;
|
|
127
|
+
/**
|
|
128
|
+
* Principle Context egress consent (SPEC v1.1 §5.1/§6.2): evaluated ONCE by
|
|
129
|
+
* the config factory and held by this closure — never re-read per turn.
|
|
130
|
+
* Strict `=== true`; direct construction without the field is fail-closed
|
|
131
|
+
* (unauthorized: zero stat, zero read, zero Context field). `false` only
|
|
132
|
+
* disables the Context read/send — the Adaptive path itself keeps running.
|
|
133
|
+
*/
|
|
134
|
+
readonly sendPrincipleContext?: boolean;
|
|
135
|
+
/** Test seam: production reads via the shared private Reader. */
|
|
136
|
+
readonly readPrincipleContextImpl?: typeof readPrincipleContext;
|
|
104
137
|
/**
|
|
105
138
|
* Observability seam (rc-9): one bounded line per turn, no prompt text,
|
|
106
139
|
* no raw response, no credentials.
|