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
|
@@ -3,64 +3,75 @@ import { ADAPTIVE_SELECTION_LIMITS, runAdaptiveSelection, } from './adaptive-sel
|
|
|
3
3
|
import { decideAdaptiveSkip } from './adaptive-skip-decision.js';
|
|
4
4
|
/** Independent switch. `features.host.codex.enabled` remains the whole-hook gate. */
|
|
5
5
|
export const ADAPTIVE_ACTIVATION_FLAG = 'host.codex.adaptive_activation';
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* PRI-1182 §2: time kept back from the host window for the principle assembly
|
|
8
|
+
* and the hook's own output. Selection never spends the reserve.
|
|
9
|
+
*/
|
|
10
|
+
export const ADAPTIVE_OUTPUT_RESERVE_MS = 200;
|
|
11
|
+
export function resolveAdaptiveSelectionModel(config, env, flag = ADAPTIVE_ACTIVATION_FLAG) {
|
|
12
|
+
const feature = config.features[flag];
|
|
8
13
|
if (feature?.enabled !== true) {
|
|
9
14
|
return {
|
|
10
15
|
ok: false,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
const profileId = config.internalAgents.defaultRuntime;
|
|
16
|
-
const profile = config.runtimeProfiles[profileId];
|
|
17
|
-
if (!profile) {
|
|
18
|
-
return {
|
|
19
|
-
ok: false,
|
|
20
|
-
reason: `Runtime profile '${profileId}' not found`,
|
|
21
|
-
nextAction: `Add runtime profile '${profileId}' to runtimeProfiles`,
|
|
16
|
+
readiness: 'disabled',
|
|
17
|
+
reason: `${flag} is disabled in .pd/config.yaml`,
|
|
18
|
+
nextAction: `Enable it explicitly with ${flag}: {enabled: true}`,
|
|
22
19
|
};
|
|
23
20
|
}
|
|
24
|
-
|
|
21
|
+
// PRI-1182: the Adaptive path has its OWN endpoint + model + credential
|
|
22
|
+
// reference. It no longer borrows a pi-ai runtime profile, because the
|
|
23
|
+
// Decisions protocol is a single scoring endpoint, not a chat completion.
|
|
24
|
+
const section = config.adaptiveActivation;
|
|
25
|
+
if (!section) {
|
|
25
26
|
return {
|
|
26
27
|
ok: false,
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
readiness: 'needs_setup',
|
|
29
|
+
reason: 'adaptiveActivation is not configured in .pd/config.yaml',
|
|
30
|
+
nextAction: 'Add adaptiveActivation: {endpoint, model, apiKeyEnv} to .pd/config.yaml',
|
|
29
31
|
};
|
|
30
32
|
}
|
|
31
|
-
if (!
|
|
33
|
+
if (!section.endpoint || !section.model || !section.apiKeyEnv) {
|
|
32
34
|
return {
|
|
33
35
|
ok: false,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
readiness: 'needs_setup',
|
|
37
|
+
reason: 'adaptiveActivation is missing endpoint/model/apiKeyEnv',
|
|
38
|
+
nextAction: 'Set endpoint (https URL), model and apiKeyEnv on adaptiveActivation',
|
|
36
39
|
};
|
|
37
40
|
}
|
|
38
|
-
if (!Object.hasOwn(env,
|
|
41
|
+
if (!Object.hasOwn(env, section.apiKeyEnv) || !env[section.apiKeyEnv]) {
|
|
39
42
|
return {
|
|
40
43
|
ok: false,
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
readiness: 'needs_setup',
|
|
45
|
+
reason: `Environment variable '${section.apiKeyEnv}' is not set or empty`,
|
|
46
|
+
nextAction: `Set the environment variable '${section.apiKeyEnv}' with a valid API key`,
|
|
43
47
|
};
|
|
44
48
|
}
|
|
45
49
|
return {
|
|
46
50
|
ok: true,
|
|
47
|
-
profileId,
|
|
48
51
|
model: {
|
|
49
|
-
|
|
50
|
-
model:
|
|
51
|
-
apiKeyEnv:
|
|
52
|
-
...(
|
|
52
|
+
endpoint: section.endpoint,
|
|
53
|
+
model: section.model,
|
|
54
|
+
apiKeyEnv: section.apiKeyEnv,
|
|
55
|
+
...(section.provider ? { provider: section.provider } : {}),
|
|
56
|
+
...(section.responseModels && section.responseModels.length > 0
|
|
57
|
+
? { allowedResponseModels: section.responseModels }
|
|
58
|
+
: {}),
|
|
53
59
|
},
|
|
54
60
|
};
|
|
55
61
|
}
|
|
56
62
|
export function createAdaptivePriorityProvider(options) {
|
|
57
63
|
const now = options.now ?? Date.now;
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
return async (event) => {
|
|
64
|
+
const requestTimeoutMs = options.requestTimeoutMs ?? ADAPTIVE_SELECTION_LIMITS.requestTimeoutMs;
|
|
65
|
+
const outputReserveMs = options.outputReserveMs ?? ADAPTIVE_OUTPUT_RESERVE_MS;
|
|
66
|
+
return async (event, candidates) => {
|
|
61
67
|
if (event.kind !== 'before_prompt_build')
|
|
62
68
|
return undefined;
|
|
63
69
|
const { sessionId, turnId, promptContent, workspaceDir } = event.context;
|
|
70
|
+
// The host budget starts before selection; the request budget starts at send.
|
|
71
|
+
const nowMs = now();
|
|
72
|
+
const hostDeadlineAt = options.outerDeadlineAt === undefined
|
|
73
|
+
? undefined
|
|
74
|
+
: options.outerDeadlineAt - outputReserveMs;
|
|
64
75
|
// PRI-1181: deterministic gate BEFORE the candidate read. A skipped turn
|
|
65
76
|
// costs zero reads and zero sends; the Native body is untouched.
|
|
66
77
|
const skip = decideAdaptiveSkip({
|
|
@@ -68,11 +79,9 @@ export function createAdaptivePriorityProvider(options) {
|
|
|
68
79
|
sessionId,
|
|
69
80
|
turnId,
|
|
70
81
|
prompt: promptContent ?? '',
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
...(options.minRemainingBudgetMs !== undefined
|
|
75
|
-
? { minRemainingBudgetMs: options.minRemainingBudgetMs }
|
|
82
|
+
remainingBudgetMs: Math.max(0, Math.min(requestTimeoutMs, (hostDeadlineAt ?? Infinity) - nowMs)),
|
|
83
|
+
...(options.minExecutableBudgetMs !== undefined
|
|
84
|
+
? { minExecutableBudgetMs: options.minExecutableBudgetMs }
|
|
76
85
|
: {}),
|
|
77
86
|
});
|
|
78
87
|
if (skip.skip) {
|
|
@@ -81,11 +90,16 @@ export function createAdaptivePriorityProvider(options) {
|
|
|
81
90
|
reason: skip.reason,
|
|
82
91
|
stage: 'gate',
|
|
83
92
|
sends: 0,
|
|
93
|
+
requestSentAt: null,
|
|
84
94
|
firstByteAt: null,
|
|
85
95
|
generationEndedAt: null,
|
|
96
|
+
validatedAt: null,
|
|
86
97
|
cancelledAt: null,
|
|
87
98
|
httpStatus: null,
|
|
88
99
|
finishReason: 'skipped',
|
|
100
|
+
modelObserved: null,
|
|
101
|
+
providerObserved: null,
|
|
102
|
+
decision: null,
|
|
89
103
|
failures: [],
|
|
90
104
|
});
|
|
91
105
|
return undefined;
|
|
@@ -93,27 +107,14 @@ export function createAdaptivePriorityProvider(options) {
|
|
|
93
107
|
// The gate already proved identity and a non-blank prompt (rc-3); the
|
|
94
108
|
// selector only needs the prompt body from here on.
|
|
95
109
|
const prompt = promptContent ?? '';
|
|
96
|
-
const
|
|
97
|
-
? now() + firstByteTimeoutMs
|
|
98
|
-
: Math.min(now() + firstByteTimeoutMs, options.outerDeadlineAt);
|
|
99
|
-
const remainingBudgetMs = options.outerDeadlineAt === undefined
|
|
100
|
-
? firstByteTimeoutMs
|
|
101
|
-
: Math.max(1, options.outerDeadlineAt - now());
|
|
102
|
-
const effectiveGenerationTimeoutMs = options.outerDeadlineAt === undefined
|
|
103
|
-
? generationTimeoutMs
|
|
104
|
-
: Math.min(generationTimeoutMs, remainingBudgetMs);
|
|
105
|
-
// Reuse the selector's AbortSignal seam instead of a second timer: it is
|
|
106
|
-
// combined with the first-byte and request signals inside the transport.
|
|
107
|
-
const signal = options.outerDeadlineAt === undefined ? undefined : AbortSignal.timeout(remainingBudgetMs);
|
|
110
|
+
const signal = hostDeadlineAt === undefined ? undefined : AbortSignal.timeout(Math.max(1, hostDeadlineAt - now()));
|
|
108
111
|
const outcome = await runAdaptiveSelection({
|
|
109
112
|
workspaceDir: workspaceDir || options.workspaceDir,
|
|
110
113
|
currentPrompt: prompt,
|
|
111
|
-
|
|
114
|
+
candidates,
|
|
112
115
|
model: options.model,
|
|
113
|
-
|
|
114
|
-
...(
|
|
115
|
-
...(signal ? { signal } : {}),
|
|
116
|
-
...(options.maxTokens !== undefined ? { maxTokens: options.maxTokens } : {}),
|
|
116
|
+
requestTimeoutMs,
|
|
117
|
+
...(hostDeadlineAt !== undefined ? { outerDeadlineAt: hostDeadlineAt, signal } : {}),
|
|
117
118
|
...(options.now ? { now: options.now } : {}),
|
|
118
119
|
...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
|
|
119
120
|
});
|
|
@@ -122,11 +123,16 @@ export function createAdaptivePriorityProvider(options) {
|
|
|
122
123
|
reason: outcome.reason,
|
|
123
124
|
stage: outcome.diagnostics.stage,
|
|
124
125
|
sends: outcome.sends,
|
|
126
|
+
requestSentAt: outcome.diagnostics.requestSentAt,
|
|
125
127
|
firstByteAt: outcome.diagnostics.firstByteAt,
|
|
126
128
|
generationEndedAt: outcome.diagnostics.generationEndedAt,
|
|
129
|
+
validatedAt: outcome.diagnostics.validatedAt,
|
|
127
130
|
cancelledAt: outcome.diagnostics.cancelledAt,
|
|
128
131
|
httpStatus: outcome.diagnostics.httpStatus,
|
|
129
132
|
finishReason: outcome.diagnostics.finishReason,
|
|
133
|
+
modelObserved: outcome.diagnostics.modelObserved,
|
|
134
|
+
providerObserved: outcome.diagnostics.providerObserved,
|
|
135
|
+
decision: outcome.diagnostics.decision,
|
|
130
136
|
failures: [...outcome.diagnostics.failures],
|
|
131
137
|
});
|
|
132
138
|
if (outcome.status !== 'selected' || !outcome.target)
|
|
@@ -135,8 +141,7 @@ export function createAdaptivePriorityProvider(options) {
|
|
|
135
141
|
artifactId: outcome.target.artifactId,
|
|
136
142
|
activationId: outcome.target.activationId,
|
|
137
143
|
additiveOnly: true,
|
|
138
|
-
deadlineAt:
|
|
139
|
-
...(signal ? { signal } : {}),
|
|
144
|
+
...(hostDeadlineAt !== undefined ? { deadlineAt: hostDeadlineAt, signal } : {}),
|
|
140
145
|
};
|
|
141
146
|
};
|
|
142
147
|
}
|
|
@@ -145,11 +150,11 @@ export function createAdaptivePriorityProvider(options) {
|
|
|
145
150
|
* workspace config for the current turn.
|
|
146
151
|
*/
|
|
147
152
|
export function createAdaptivePriorityProviderForConfig(config, workspaceDir, options = {}) {
|
|
148
|
-
const resolved = resolveAdaptiveSelectionModel(config, options.env ?? process.env);
|
|
153
|
+
const resolved = resolveAdaptiveSelectionModel(config, options.env ?? process.env, options.flag);
|
|
149
154
|
if (!resolved.ok) {
|
|
150
155
|
return {
|
|
151
156
|
ok: false,
|
|
152
|
-
readiness:
|
|
157
|
+
readiness: resolved.readiness,
|
|
153
158
|
reason: resolved.reason,
|
|
154
159
|
nextAction: resolved.nextAction,
|
|
155
160
|
};
|
|
@@ -157,11 +162,10 @@ export function createAdaptivePriorityProviderForConfig(config, workspaceDir, op
|
|
|
157
162
|
const provider = createAdaptivePriorityProvider({
|
|
158
163
|
workspaceDir,
|
|
159
164
|
model: resolved.model,
|
|
160
|
-
...(options.
|
|
161
|
-
...(options.generationTimeoutMs !== undefined ? { generationTimeoutMs: options.generationTimeoutMs } : {}),
|
|
165
|
+
...(options.requestTimeoutMs !== undefined ? { requestTimeoutMs: options.requestTimeoutMs } : {}),
|
|
162
166
|
...(options.outerDeadlineAt !== undefined ? { outerDeadlineAt: options.outerDeadlineAt } : {}),
|
|
163
|
-
...(options.
|
|
164
|
-
...(options.
|
|
167
|
+
...(options.outputReserveMs !== undefined ? { outputReserveMs: options.outputReserveMs } : {}),
|
|
168
|
+
...(options.minExecutableBudgetMs !== undefined ? { minExecutableBudgetMs: options.minExecutableBudgetMs } : {}),
|
|
165
169
|
...(options.now ? { now: options.now } : {}),
|
|
166
170
|
...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
|
|
167
171
|
...(options.onDiagnostic ? { onDiagnostic: options.onDiagnostic } : {}),
|
|
@@ -169,10 +173,9 @@ export function createAdaptivePriorityProviderForConfig(config, workspaceDir, op
|
|
|
169
173
|
return {
|
|
170
174
|
ok: true,
|
|
171
175
|
readiness: 'ready',
|
|
172
|
-
reason: `adaptive
|
|
176
|
+
reason: `adaptive decision ready at '${resolved.model.endpoint}' (model '${resolved.model.model}')`,
|
|
173
177
|
nextAction: 'none',
|
|
174
178
|
provider,
|
|
175
|
-
profileId: resolved.profileId,
|
|
176
179
|
};
|
|
177
180
|
}
|
|
178
181
|
/**
|
|
@@ -1,24 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ActivatedPrinciple } from '@principles/core/runtime';
|
|
2
|
+
import { type DecisionOutcome, type DecisionProtocolError, type DecisionRequestEnvelope } from './adaptive-decision-protocol.js';
|
|
2
3
|
export declare const ADAPTIVE_SELECTION_LIMITS: {
|
|
3
4
|
readonly maxCandidates: 12;
|
|
4
5
|
readonly maxCandidateChars: 600;
|
|
5
6
|
readonly maxPriorMessages: 4;
|
|
6
7
|
readonly maxPriorMessageChars: 1200;
|
|
7
8
|
readonly maxInputChars: 6000;
|
|
8
|
-
/**
|
|
9
|
-
readonly
|
|
10
|
-
/** Bounded
|
|
11
|
-
readonly
|
|
12
|
-
|
|
9
|
+
/** Total time from sending a decision request to validating the full response. */
|
|
10
|
+
readonly requestTimeoutMs: 2000;
|
|
11
|
+
/** Bounded outbound payload (current instruction + candidate snapshot + conditions). */
|
|
12
|
+
readonly maxPayloadChars: 20000;
|
|
13
|
+
/** Bounded response body; a Decisions answer table is a few KB at most. */
|
|
14
|
+
readonly maxResponseBytes: 65536;
|
|
13
15
|
};
|
|
14
16
|
export type AdaptiveSelectionModel = {
|
|
15
|
-
|
|
17
|
+
/** Exact Decisions endpoint (for example https://openrouter.ai/api/alpha/decisions). */
|
|
18
|
+
readonly endpoint: string;
|
|
16
19
|
readonly model: string;
|
|
17
20
|
readonly apiKeyEnv: string;
|
|
18
|
-
/**
|
|
19
|
-
readonly
|
|
20
|
-
/**
|
|
21
|
-
|
|
21
|
+
/** Optional provider allowlist label (for example Respan). */
|
|
22
|
+
readonly provider?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Frozen exact response-model allowlist for the acceptance batch. When set,
|
|
25
|
+
* a response whose `model` is not one of these strings is rejected — a
|
|
26
|
+
* same-prefix slug with an unregistered date does not pass.
|
|
27
|
+
*/
|
|
28
|
+
readonly allowedResponseModels?: readonly string[];
|
|
22
29
|
};
|
|
23
30
|
export type AdaptiveCandidateSource = ActivatedPrinciple;
|
|
24
31
|
export interface AdaptiveCandidate {
|
|
@@ -35,7 +42,6 @@ export interface BoundedSelectionInput {
|
|
|
35
42
|
readonly source: string;
|
|
36
43
|
readonly index: number;
|
|
37
44
|
}[];
|
|
38
|
-
/** `digest` is precomputed locally and only copied by the model. */
|
|
39
45
|
readonly candidates: readonly {
|
|
40
46
|
readonly ref: string;
|
|
41
47
|
readonly text: string;
|
|
@@ -52,47 +58,53 @@ export type BuildBoundedInputResult = {
|
|
|
52
58
|
readonly ok: false;
|
|
53
59
|
readonly reason: string;
|
|
54
60
|
};
|
|
55
|
-
export type
|
|
56
|
-
readonly status: 'selected';
|
|
57
|
-
readonly id: string;
|
|
58
|
-
readonly digest: string;
|
|
59
|
-
} | {
|
|
60
|
-
readonly status: 'none_applicable' | 'uncertain';
|
|
61
|
-
readonly id: null;
|
|
62
|
-
readonly digest: null;
|
|
63
|
-
};
|
|
64
|
-
export type ValidateSelectionResult = {
|
|
65
|
-
readonly ok: true;
|
|
66
|
-
readonly selected: AdaptiveCandidate | null;
|
|
67
|
-
readonly outcome: 'selected' | 'no_increment' | 'uncertain';
|
|
68
|
-
} | {
|
|
69
|
-
readonly ok: false;
|
|
70
|
-
readonly reason: string;
|
|
71
|
-
readonly refValid: boolean | null;
|
|
72
|
-
readonly digestValid: boolean | null;
|
|
73
|
-
};
|
|
74
|
-
export type AdaptiveFailureCode = 'SELECTION_REFERENCE_INVALID' | 'SELECTION_DIGEST_INVALID' | 'SELECTION_OUTPUT_INVALID' | 'SELECTION_AMBIGUOUS' | 'SELECTION_EXPIRED'
|
|
61
|
+
export type AdaptiveFailureCode = 'SELECTION_OUTPUT_INVALID' | DecisionProtocolError
|
|
75
62
|
/** The host's outer hook window ended Adaptive; distinct from the model's own timeout. */
|
|
76
|
-
| 'TURN_DEADLINE_EXCEEDED'
|
|
63
|
+
| 'TURN_DEADLINE_EXCEEDED'
|
|
64
|
+
/** The request's own short admission/completion window ended. */
|
|
65
|
+
| 'SELECTION_EXPIRED'
|
|
66
|
+
/**
|
|
67
|
+
* Configuration fault: the credential named by `apiKeyEnv` is absent at send
|
|
68
|
+
* time. Deliberately NOT in the TRANSPORT_* family — an operator must be able
|
|
69
|
+
* to tell "we never had a key" apart from "the network broke".
|
|
70
|
+
*/
|
|
71
|
+
| 'DECISION_CREDENTIAL_MISSING' | 'TRANSPORT_NOT_SENT' | 'TRANSPORT_FAILED' | 'TRANSPORT_HTTP_ERROR';
|
|
77
72
|
export type AdaptiveSelectionStage = 'idle' | 'admission' | 'generation' | 'validate' | 'revalidate' | 'done';
|
|
78
73
|
export interface AdaptiveSelectionDiagnostics {
|
|
79
74
|
stage: AdaptiveSelectionStage;
|
|
80
|
-
readonly
|
|
75
|
+
readonly requestDeadlineAt: number | null;
|
|
76
|
+
/** Epoch ms at which the single POST was actually issued (null = never sent). */
|
|
77
|
+
requestSentAt: number | null;
|
|
81
78
|
completionDeadlineAt: number | null;
|
|
82
79
|
firstByteAt: number | null;
|
|
83
80
|
generationEndedAt: number | null;
|
|
81
|
+
/** Epoch ms at which the WHOLE answer table passed validation (null = never). */
|
|
82
|
+
validatedAt: number | null;
|
|
84
83
|
cancelledAt: number | null;
|
|
85
84
|
httpStatus: number | null;
|
|
86
|
-
/**
|
|
85
|
+
/** `decisions` once a valid answer table was read; `unknown` otherwise. */
|
|
87
86
|
finishReason: string;
|
|
87
|
+
/** Exact response model observed (null until a body was parsed). */
|
|
88
|
+
modelObserved: string | null;
|
|
89
|
+
/** Response provider label observed; null both before parsing and when absent. */
|
|
90
|
+
providerObserved: string | null;
|
|
88
91
|
usage: {
|
|
89
92
|
inputTokens: number | null;
|
|
90
93
|
outputTokens: number | null;
|
|
91
94
|
} | null;
|
|
95
|
+
/**
|
|
96
|
+
* Local adjudication of the independent condition scores. Bounded: question
|
|
97
|
+
* ids are `c1..cN` plus `insufficient_context`, never prompt text.
|
|
98
|
+
*/
|
|
99
|
+
decision: {
|
|
100
|
+
status: string;
|
|
101
|
+
ref: string | null;
|
|
102
|
+
reason: string;
|
|
103
|
+
scores: Readonly<Record<string, number>>;
|
|
104
|
+
} | null;
|
|
92
105
|
failures: AdaptiveFailureCode[];
|
|
93
106
|
}
|
|
94
107
|
export declare function hash(value: string): string;
|
|
95
|
-
export declare const ADAPTIVE_SELECTOR_SYSTEM: string;
|
|
96
108
|
export declare function buildBoundedSelectionInput(input: {
|
|
97
109
|
readonly currentInput: string;
|
|
98
110
|
readonly priorMessages?: readonly {
|
|
@@ -101,30 +113,22 @@ export declare function buildBoundedSelectionInput(input: {
|
|
|
101
113
|
}[];
|
|
102
114
|
readonly candidates: readonly AdaptiveCandidateSource[];
|
|
103
115
|
}): BuildBoundedInputResult;
|
|
104
|
-
export
|
|
105
|
-
readonly ok: true;
|
|
106
|
-
readonly selection: SelectionShape;
|
|
107
|
-
} | {
|
|
108
|
-
readonly ok: false;
|
|
109
|
-
readonly reason: string;
|
|
110
|
-
};
|
|
111
|
-
export declare function validateSelectionResult(value: unknown, entries: readonly AdaptiveCandidate[]): ValidateSelectionResult;
|
|
112
|
-
export declare function localFailureCode(reason: string): AdaptiveFailureCode;
|
|
113
|
-
export interface SingleModelSelectorOptions {
|
|
114
|
-
readonly PiAiRuntimeAdapterImpl?: typeof PiAiRuntimeAdapter;
|
|
116
|
+
export interface DecisionSelectorOptions {
|
|
115
117
|
readonly fetchImpl?: typeof fetch;
|
|
116
118
|
readonly now?: () => number;
|
|
117
|
-
|
|
118
|
-
readonly admissionDeadlineAt: number;
|
|
119
|
-
readonly generationTimeoutMs?: number;
|
|
119
|
+
readonly requestTimeoutMs?: number;
|
|
120
120
|
readonly model: AdaptiveSelectionModel;
|
|
121
|
-
readonly maxTokens?: number;
|
|
122
121
|
readonly signal?: AbortSignal;
|
|
123
122
|
/** Absolute host deadline. Reaching it is NOT the model's generation timeout. */
|
|
124
123
|
readonly outerDeadlineAt?: number;
|
|
125
124
|
}
|
|
126
|
-
export interface
|
|
127
|
-
readonly
|
|
125
|
+
export interface DecisionSelectorInput {
|
|
126
|
+
readonly body: DecisionRequestEnvelope;
|
|
127
|
+
readonly questionIds: readonly string[];
|
|
128
|
+
readonly candidates: readonly AdaptiveCandidate[];
|
|
129
|
+
}
|
|
130
|
+
export interface DecisionSelector {
|
|
131
|
+
readonly select: (input: DecisionSelectorInput) => Promise<DecisionOutcome>;
|
|
128
132
|
readonly report: () => {
|
|
129
133
|
readonly sends: number;
|
|
130
134
|
readonly status: 'not_sent' | 'sent' | 'failed';
|
|
@@ -132,21 +136,22 @@ export interface SingleModelSelector {
|
|
|
132
136
|
readonly diagnostics: AdaptiveSelectionDiagnostics;
|
|
133
137
|
};
|
|
134
138
|
}
|
|
135
|
-
|
|
139
|
+
/**
|
|
140
|
+
* One Decisions POST per turn. Every failure is classified at the transport
|
|
141
|
+
* edge; the caller never sees provider text, headers or credentials.
|
|
142
|
+
*/
|
|
143
|
+
export declare function createDecisionSelector(options: DecisionSelectorOptions): DecisionSelector;
|
|
136
144
|
export interface RunAdaptiveSelectionOptions {
|
|
137
145
|
readonly workspaceDir: string;
|
|
138
146
|
readonly currentPrompt: string;
|
|
139
|
-
|
|
140
|
-
readonly admissionDeadlineAt: number;
|
|
147
|
+
readonly candidates: readonly ActivatedPrinciple[];
|
|
141
148
|
readonly model: AdaptiveSelectionModel;
|
|
142
|
-
readonly
|
|
143
|
-
readonly maxTokens?: number;
|
|
149
|
+
readonly requestTimeoutMs?: number;
|
|
144
150
|
readonly signal?: AbortSignal;
|
|
145
151
|
/** Absolute host deadline shared by selection, revalidation and packing. */
|
|
146
152
|
readonly outerDeadlineAt?: number;
|
|
147
153
|
readonly now?: () => number;
|
|
148
154
|
readonly fetchImpl?: typeof fetch;
|
|
149
|
-
readonly PiAiRuntimeAdapterImpl?: typeof PiAiRuntimeAdapter;
|
|
150
155
|
}
|
|
151
156
|
export interface AdaptiveSelectionOutcome {
|
|
152
157
|
readonly status: 'selected' | 'none' | 'unavailable';
|
|
@@ -157,8 +162,8 @@ export interface AdaptiveSelectionOutcome {
|
|
|
157
162
|
readonly diagnostics: AdaptiveSelectionDiagnostics;
|
|
158
163
|
}
|
|
159
164
|
/**
|
|
160
|
-
* Minimal host-facing selection step:
|
|
161
|
-
* make at most one bounded
|
|
162
|
-
* revalidate the chosen principle's content/revision/authorization.
|
|
165
|
+
* Minimal host-facing selection step: use the current frozen Native gap,
|
|
166
|
+
* make at most one bounded Decisions request, adjudicate locally, then
|
|
167
|
+
* independently revalidate the chosen principle's content/revision/authorization.
|
|
163
168
|
*/
|
|
164
169
|
export declare function runAdaptiveSelection(options: RunAdaptiveSelectionOptions): Promise<AdaptiveSelectionOutcome>;
|