create-principles-disciple 1.148.11 → 1.150.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 +1 -1
- package/codex-adapter/dist/pd-hook.d.ts +22 -1
- package/codex-adapter/dist/pd-hook.js +81 -7
- package/codex-adapter/dist/worker/workspace-worker.d.ts +15 -0
- package/codex-adapter/dist/worker/workspace-worker.js +7 -36
- package/codex-adapter/package.json +1 -1
- package/console/dist/server/index.js +21 -0
- package/console/dist/server/models/ActivationsConsoleModel.d.ts +3 -17
- package/console/dist/server/models/ActivationsConsoleModel.js +5 -44
- package/console/dist/server/routes/compatibility-scan.d.ts +18 -0
- package/console/dist/server/routes/compatibility-scan.js +33 -0
- package/console/dist/server/routes/diagnostician.d.ts +50 -0
- package/console/dist/server/routes/diagnostician.js +388 -0
- package/console/dist/shared/compatibility-scan-contract.d.ts +26 -0
- package/console/dist/shared/compatibility-scan-contract.js +1 -0
- package/console/dist/web/assets/app.js +31 -31
- package/core/dist/host/host-installer.d.ts +7 -0
- package/core/dist/host/host-installer.d.ts.map +1 -1
- package/core/dist/host/host-installer.js.map +1 -1
- package/core/dist/runtime/activation/index.d.ts +3 -3
- package/core/dist/runtime/activation/index.d.ts.map +1 -1
- package/core/dist/runtime/activation/index.js +1 -1
- package/core/dist/runtime/activation/index.js.map +1 -1
- package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts +25 -1
- package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts.map +1 -1
- package/core/dist/runtime/activation/promotion-readiness-evaluator.js +58 -1
- package/core/dist/runtime/activation/promotion-readiness-evaluator.js.map +1 -1
- package/core/dist/runtime/activation/promotion-readiness-reader.d.ts.map +1 -1
- package/core/dist/runtime/activation/promotion-readiness-reader.js +4 -2
- package/core/dist/runtime/activation/promotion-readiness-reader.js.map +1 -1
- package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts +28 -0
- package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts.map +1 -1
- package/core/dist/runtime/activation/rulecode-owner-decision-service.js +2 -0
- package/core/dist/runtime/activation/rulecode-owner-decision-service.js.map +1 -1
- package/core/dist/runtime/activation-compatibility-read-model.d.ts +20 -5
- package/core/dist/runtime/activation-compatibility-read-model.d.ts.map +1 -1
- package/core/dist/runtime/activation-compatibility-read-model.js +15 -3
- package/core/dist/runtime/activation-compatibility-read-model.js.map +1 -1
- package/core/dist/runtime/admission-gate.d.ts +8 -1
- package/core/dist/runtime/admission-gate.d.ts.map +1 -1
- package/core/dist/runtime/admission-gate.js +2 -1
- package/core/dist/runtime/admission-gate.js.map +1 -1
- package/core/dist/runtime/config/pd-config-defaults.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-defaults.js +20 -2
- package/core/dist/runtime/config/pd-config-defaults.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 +18 -0
- package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
- package/core/dist/runtime/context-payload.d.ts +48 -3
- package/core/dist/runtime/context-payload.d.ts.map +1 -1
- package/core/dist/runtime/context-payload.js +38 -0
- package/core/dist/runtime/context-payload.js.map +1 -1
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts +8 -2
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js +28 -2
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js.map +1 -1
- package/core/dist/runtime/diagnostician-candidate.d.ts +24 -0
- package/core/dist/runtime/diagnostician-candidate.d.ts.map +1 -0
- package/core/dist/runtime/diagnostician-candidate.js +55 -0
- package/core/dist/runtime/diagnostician-candidate.js.map +1 -0
- package/core/dist/runtime/evidence-guards.d.ts +10 -4
- package/core/dist/runtime/evidence-guards.d.ts.map +1 -1
- package/core/dist/runtime/evidence-guards.js +12 -5
- package/core/dist/runtime/evidence-guards.js.map +1 -1
- package/core/dist/runtime/evolution/evolution-types.d.ts +4 -4
- package/core/dist/runtime/evolution/evolution-types.d.ts.map +1 -1
- package/core/dist/runtime/evolution/evolution-types.js +1 -0
- package/core/dist/runtime/evolution/evolution-types.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 +14 -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 +16 -0
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
- package/core/dist/runtime/index.d.ts +5 -2
- package/core/dist/runtime/index.d.ts.map +1 -1
- package/core/dist/runtime/index.js +6 -1
- package/core/dist/runtime/index.js.map +1 -1
- package/core/dist/runtime/internalization/index.d.ts +1 -0
- package/core/dist/runtime/internalization/index.d.ts.map +1 -1
- package/core/dist/runtime/internalization/index.js +2 -0
- package/core/dist/runtime/internalization/index.js.map +1 -1
- package/core/dist/runtime/internalization/rule-host-contracts.d.ts +10 -0
- package/core/dist/runtime/internalization/rule-host-contracts.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rule-host-evaluator.js +10 -10
- package/core/dist/runtime/internalization/rule-host-evaluator.js.map +1 -1
- package/core/dist/runtime/internalization/rule-host-input-builder.d.ts +7 -6
- package/core/dist/runtime/internalization/rule-host-input-builder.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rule-host-input-builder.js +6 -2
- package/core/dist/runtime/internalization/rule-host-input-builder.js.map +1 -1
- package/core/dist/runtime/internalization/rule-host-result-normalizer.d.ts +33 -0
- package/core/dist/runtime/internalization/rule-host-result-normalizer.d.ts.map +1 -0
- package/core/dist/runtime/internalization/rule-host-result-normalizer.js +61 -0
- package/core/dist/runtime/internalization/rule-host-result-normalizer.js.map +1 -0
- package/core/dist/runtime/internalization/rule-host-validator.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rule-host-validator.js +17 -0
- package/core/dist/runtime/internalization/rule-host-validator.js.map +1 -1
- package/core/dist/runtime/pain-ingress-payload.d.ts +27 -2
- package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
- package/core/dist/runtime/pain-ingress-payload.js +45 -3
- package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
- package/core/dist/runtime/pain-ingress.d.ts +4 -2
- package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
- package/core/dist/runtime/pain-ingress.js +23 -3
- package/core/dist/runtime/pain-ingress.js.map +1 -1
- package/core/dist/runtime/pain-severity.d.ts +14 -0
- package/core/dist/runtime/pain-severity.d.ts.map +1 -0
- package/core/dist/runtime/pain-severity.js +14 -0
- package/core/dist/runtime/pain-severity.js.map +1 -0
- package/core/dist/runtime/pain-signal-bridge.d.ts +17 -3
- package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-bridge.js +6 -0
- package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
- package/core/dist/runtime/pain-signal-observability.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-observability.js +3 -2
- package/core/dist/runtime/pain-signal-observability.js.map +1 -1
- package/core/dist/runtime/pain-submit-capability.d.ts +164 -0
- package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -0
- package/core/dist/runtime/pain-submit-capability.js +442 -0
- package/core/dist/runtime/pain-submit-capability.js.map +1 -0
- package/core/dist/runtime/pain-to-principle-service.d.ts +4 -0
- package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
- package/core/dist/runtime/pain-to-principle-service.js +2 -0
- package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
- package/core/dist/runtime/stalled-diagnostician-task-read-model.d.ts +56 -10
- package/core/dist/runtime/stalled-diagnostician-task-read-model.d.ts.map +1 -1
- package/core/dist/runtime/stalled-diagnostician-task-read-model.js +80 -4
- package/core/dist/runtime/stalled-diagnostician-task-read-model.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 +11 -0
- package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
- package/core/dist/runtime/store/run/memory-run-store.d.ts +10 -0
- package/core/dist/runtime/store/run/memory-run-store.d.ts.map +1 -1
- package/core/dist/runtime/store/run/memory-run-store.js +21 -0
- package/core/dist/runtime/store/run/memory-run-store.js.map +1 -1
- package/core/dist/runtime/store/run/run-store.d.ts +12 -0
- package/core/dist/runtime/store/run/run-store.d.ts.map +1 -1
- package/core/dist/runtime/store/run/sqlite-run-store.d.ts +1 -0
- package/core/dist/runtime/store/run/sqlite-run-store.d.ts.map +1 -1
- package/core/dist/runtime/store/run/sqlite-run-store.js +14 -0
- package/core/dist/runtime/store/run/sqlite-run-store.js.map +1 -1
- package/core/dist/runtime/task-status.d.ts +9 -0
- package/core/dist/runtime/task-status.d.ts.map +1 -1
- package/core/dist/runtime/task-status.js +7 -1
- package/core/dist/runtime/task-status.js.map +1 -1
- package/core/dist/runtime/types/evidence-chain-contract.d.ts +18 -0
- package/core/dist/runtime/types/evidence-chain-contract.d.ts.map +1 -1
- package/core/dist/runtime/types/evidence-chain-contract.js +37 -7
- package/core/dist/runtime/types/evidence-chain-contract.js.map +1 -1
- package/core/package.json +5 -1
- package/dist/install-summary.d.ts +7 -0
- package/dist/install-summary.d.ts.map +1 -1
- package/dist/install-summary.js +4 -0
- package/dist/install-summary.js.map +1 -1
- package/dist/installer.d.ts +92 -8
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +215 -10
- package/dist/installer.js.map +1 -1
- package/dist/installers/codex-host-installer.d.ts +88 -1
- package/dist/installers/codex-host-installer.d.ts.map +1 -1
- package/dist/installers/codex-host-installer.js +350 -11
- package/dist/installers/codex-host-installer.js.map +1 -1
- package/dist/installers/index.d.ts +23 -0
- package/dist/installers/index.d.ts.map +1 -1
- package/dist/installers/index.js +38 -1
- package/dist/installers/index.js.map +1 -1
- package/dist/installers/legacy-workbuddy-skill.d.ts +59 -0
- package/dist/installers/legacy-workbuddy-skill.d.ts.map +1 -0
- package/dist/installers/legacy-workbuddy-skill.js +168 -0
- package/dist/installers/legacy-workbuddy-skill.js.map +1 -0
- package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
- package/dist/installers/workbuddy-host-installer.js +7 -0
- package/dist/installers/workbuddy-host-installer.js.map +1 -1
- package/host-runtime/dist/adaptive-priority-provider.d.ts +94 -0
- package/host-runtime/dist/adaptive-priority-provider.js +162 -0
- package/host-runtime/dist/adaptive-selection.d.ts +164 -0
- package/host-runtime/dist/adaptive-selection.js +506 -0
- package/host-runtime/dist/diagnostician-auto-run.d.ts +28 -0
- package/host-runtime/dist/diagnostician-auto-run.js +100 -0
- package/host-runtime/dist/host-tool-semantic-resolver.d.ts +42 -1
- package/host-runtime/dist/host-tool-semantic-resolver.js +80 -14
- package/host-runtime/dist/index.d.ts +4 -0
- package/host-runtime/dist/index.js +6 -0
- package/host-runtime/dist/production-rulehost-gate.js +17 -17
- package/host-runtime/dist/rulecode-event-collection.d.ts +31 -0
- package/host-runtime/dist/rulecode-event-collection.js +62 -0
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/index.d.ts +1 -1
- package/install-layout/dist/index.js +1 -1
- package/install-layout/dist/pd-home.d.ts +9 -2
- package/install-layout/dist/pd-home.js +77 -14
- package/install-layout/package.json +1 -1
- package/package.json +4 -4
- package/pd-cli/dist/commands/diagnose.d.ts +30 -0
- package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
- package/pd-cli/dist/commands/diagnose.js +75 -0
- package/pd-cli/dist/commands/diagnose.js.map +1 -1
- package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-record.js +5 -4
- package/pd-cli/dist/commands/pain-record.js.map +1 -1
- package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-retry.js +2 -1
- package/pd-cli/dist/commands/pain-retry.js.map +1 -1
- package/pd-cli/dist/commands/runtime-activation.d.ts +6 -17
- package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-activation.js +42 -48
- package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
- package/pd-cli/dist/commands/runtime-compatibility-scan.d.ts +5 -2
- package/pd-cli/dist/commands/runtime-compatibility-scan.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-compatibility-scan.js +22 -2
- package/pd-cli/dist/commands/runtime-compatibility-scan.js.map +1 -1
- package/pd-cli/dist/index.js +1 -0
- package/pd-cli/dist/index.js.map +1 -1
- package/pd-cli/dist/services/config-doctor.d.ts +9 -0
- package/pd-cli/dist/services/config-doctor.d.ts.map +1 -1
- package/pd-cli/dist/services/config-doctor.js +15 -0
- package/pd-cli/dist/services/config-doctor.js.map +1 -1
- package/pd-cli/dist/services/delivery-surfaces.js +1 -1
- package/pd-cli/dist/services/delivery-surfaces.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/pd-mcp-server/dist/budget.d.ts +1 -1
- package/pd-mcp-server/dist/budget.js +2 -2
- package/pd-mcp-server/dist/envelope.d.ts +15 -0
- package/pd-mcp-server/dist/envelope.js +49 -1
- package/pd-mcp-server/dist/index.d.ts +2 -0
- package/pd-mcp-server/dist/index.js +6 -0
- package/pd-mcp-server/dist/server.d.ts +83 -14
- package/pd-mcp-server/dist/server.js +251 -4
- package/pd-mcp-server/dist/version.d.ts +1 -1
- package/pd-mcp-server/dist/version.js +1 -1
- package/pd-mcp-server/dist/workspace.d.ts +4 -2
- package/pd-mcp-server/dist/workspace.js +5 -2
- package/pd-mcp-server/package.json +1 -1
- package/plugin/dist/bundle.js +443 -431
- package/plugin/dist/core/evolution-reducer.d.ts +2 -2
- package/plugin/dist/hooks/hook-tool-semantics.d.ts +25 -0
- package/plugin/dist/hooks/pain-ingress-adapter.d.ts +1 -1
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/dist/rulehost-evidence.js +1 -1
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/release-manager/dist/installer.js +215 -10
- package/release-manager/dist/installers/codex-host-installer.js +350 -11
- package/release-manager/dist/installers/index.js +38 -1
- package/release-manager/dist/installers/legacy-workbuddy-skill.js +168 -0
- package/release-manager/dist/installers/workbuddy-host-installer.js +7 -0
- package/release-manager/package.json +1 -1
- package/workbuddy-adapter/dist/pd-hook.js +20 -4
- package/workbuddy-adapter/package.json +1 -1
- package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +123 -20
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adaptive Activation — Codex host provider (default OFF).
|
|
3
|
+
*
|
|
4
|
+
* The provider is a thin, optional hook boundary:
|
|
5
|
+
* UserPromptSubmit → decoded HostEvent → this provider → shared assembly.
|
|
6
|
+
*
|
|
7
|
+
* It binds ONLY the host-supplied current-turn identity (`session_id`,
|
|
8
|
+
* `turn_id`) and prompt body. No markers, no manual principle ids, no scene
|
|
9
|
+
* mapping. Any missing identity/config/model keeps the Native path unchanged.
|
|
10
|
+
*/
|
|
11
|
+
import type { HostEvent } from '@principles/core/host';
|
|
12
|
+
import type { PdConfig } from '@principles/core/runtime';
|
|
13
|
+
import { type AdaptiveSelectionModel } from './adaptive-selection.js';
|
|
14
|
+
/** Independent switch. `features.host.codex.enabled` remains the whole-hook gate. */
|
|
15
|
+
export declare const ADAPTIVE_ACTIVATION_FLAG = "host.codex.adaptive_activation";
|
|
16
|
+
export interface AdaptivePrioritySelection {
|
|
17
|
+
readonly artifactId: string;
|
|
18
|
+
readonly activationId: string;
|
|
19
|
+
readonly additiveOnly: true;
|
|
20
|
+
readonly deadlineAt?: number;
|
|
21
|
+
readonly signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
export type AdaptivePriorityProvider = (event: HostEvent) => Promise<AdaptivePrioritySelection | undefined>;
|
|
24
|
+
export interface AdaptiveActivationReadiness {
|
|
25
|
+
readonly readiness: 'ready' | 'disabled' | 'needs_setup';
|
|
26
|
+
readonly reason: string;
|
|
27
|
+
readonly nextAction: string;
|
|
28
|
+
}
|
|
29
|
+
export type AdaptiveModelResolution = {
|
|
30
|
+
readonly ok: true;
|
|
31
|
+
readonly model: AdaptiveSelectionModel;
|
|
32
|
+
readonly profileId: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly ok: false;
|
|
35
|
+
readonly reason: string;
|
|
36
|
+
readonly nextAction: string;
|
|
37
|
+
};
|
|
38
|
+
export declare function resolveAdaptiveSelectionModel(config: PdConfig, env: Record<string, string | undefined>): AdaptiveModelResolution;
|
|
39
|
+
export interface AdaptiveSelectionDiagnosticLine {
|
|
40
|
+
readonly status: string;
|
|
41
|
+
readonly reason: string;
|
|
42
|
+
readonly stage: string;
|
|
43
|
+
readonly sends: number;
|
|
44
|
+
readonly firstByteAt: number | null;
|
|
45
|
+
readonly generationEndedAt: number | null;
|
|
46
|
+
readonly cancelledAt: number | null;
|
|
47
|
+
readonly httpStatus: number | null;
|
|
48
|
+
readonly finishReason: string;
|
|
49
|
+
readonly failures: readonly string[];
|
|
50
|
+
}
|
|
51
|
+
export interface CreateAdaptivePriorityProviderOptions {
|
|
52
|
+
readonly workspaceDir: string;
|
|
53
|
+
readonly model: AdaptiveSelectionModel;
|
|
54
|
+
readonly firstByteTimeoutMs?: number;
|
|
55
|
+
readonly generationTimeoutMs?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Absolute host deadline (Codex: the plugin hook window minus the Native
|
|
58
|
+
* reserve). Selection, revalidation and packing all share it: a selection
|
|
59
|
+
* that cannot finish inside the window is cancelled and never applied.
|
|
60
|
+
*/
|
|
61
|
+
readonly outerDeadlineAt?: number;
|
|
62
|
+
readonly maxTokens?: number;
|
|
63
|
+
readonly now?: () => number;
|
|
64
|
+
/** Test seam: production uses the global transport. */
|
|
65
|
+
readonly fetchImpl?: typeof fetch;
|
|
66
|
+
/**
|
|
67
|
+
* Observability seam (rc-9): one bounded line per turn, no prompt text,
|
|
68
|
+
* no raw response, no credentials.
|
|
69
|
+
*/
|
|
70
|
+
readonly onDiagnostic?: (line: AdaptiveSelectionDiagnosticLine) => void;
|
|
71
|
+
}
|
|
72
|
+
export declare function createAdaptivePriorityProvider(options: CreateAdaptivePriorityProviderOptions): AdaptivePriorityProvider;
|
|
73
|
+
export type AdaptivePriorityProviderResolution = (AdaptiveActivationReadiness & {
|
|
74
|
+
readonly ok: true;
|
|
75
|
+
readonly readiness: 'ready';
|
|
76
|
+
readonly provider: AdaptivePriorityProvider;
|
|
77
|
+
readonly profileId: string;
|
|
78
|
+
}) | (AdaptiveActivationReadiness & {
|
|
79
|
+
readonly ok: false;
|
|
80
|
+
});
|
|
81
|
+
export interface CreateAdaptiveProviderFromConfigOptions extends Omit<CreateAdaptivePriorityProviderOptions, 'workspaceDir' | 'model'> {
|
|
82
|
+
readonly env?: Record<string, string | undefined>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Config-first factory for hosts (Codex pd-hook) that already loaded the
|
|
86
|
+
* workspace config for the current turn.
|
|
87
|
+
*/
|
|
88
|
+
export declare function createAdaptivePriorityProviderForConfig(config: PdConfig, workspaceDir: string, options?: CreateAdaptiveProviderFromConfigOptions): AdaptivePriorityProviderResolution;
|
|
89
|
+
/**
|
|
90
|
+
* Workspace-facing variant: mirrors the existing signal-classifier readiness
|
|
91
|
+
* contract (flag → profile → api key) so a misconfigured workspace degrades to
|
|
92
|
+
* Native with one observable reason instead of a silent model attempt.
|
|
93
|
+
*/
|
|
94
|
+
export declare function createAdaptivePriorityProviderForWorkspace(workspaceDir: string, options?: CreateAdaptiveProviderFromConfigOptions): AdaptivePriorityProviderResolution;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { loadPdConfigForPlugin } from './pd-config.js';
|
|
2
|
+
import { ADAPTIVE_SELECTION_LIMITS, runAdaptiveSelection, } from './adaptive-selection.js';
|
|
3
|
+
/** Independent switch. `features.host.codex.enabled` remains the whole-hook gate. */
|
|
4
|
+
export const ADAPTIVE_ACTIVATION_FLAG = 'host.codex.adaptive_activation';
|
|
5
|
+
export function resolveAdaptiveSelectionModel(config, env) {
|
|
6
|
+
const feature = config.features[ADAPTIVE_ACTIVATION_FLAG];
|
|
7
|
+
if (feature?.enabled !== true) {
|
|
8
|
+
return {
|
|
9
|
+
ok: false,
|
|
10
|
+
reason: `${ADAPTIVE_ACTIVATION_FLAG} is disabled in .pd/config.yaml`,
|
|
11
|
+
nextAction: `Enable it explicitly with ${ADAPTIVE_ACTIVATION_FLAG}: {enabled: true}`,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const profileId = config.internalAgents.defaultRuntime;
|
|
15
|
+
const profile = config.runtimeProfiles[profileId];
|
|
16
|
+
if (!profile) {
|
|
17
|
+
return {
|
|
18
|
+
ok: false,
|
|
19
|
+
reason: `Runtime profile '${profileId}' not found`,
|
|
20
|
+
nextAction: `Add runtime profile '${profileId}' to runtimeProfiles`,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (profile.type !== 'pi-ai') {
|
|
24
|
+
return {
|
|
25
|
+
ok: false,
|
|
26
|
+
reason: `Runtime profile '${profileId}' is '${profile.type}', not pi-ai`,
|
|
27
|
+
nextAction: 'ADR-0029 requires a pi-ai runtime profile for adaptive selection',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (!profile.provider || !profile.model || !profile.apiKeyEnv) {
|
|
31
|
+
return {
|
|
32
|
+
ok: false,
|
|
33
|
+
reason: `pi-ai profile '${profileId}' missing provider/model/apiKeyEnv`,
|
|
34
|
+
nextAction: `Set provider, model and apiKeyEnv on runtime profile '${profileId}'`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (!Object.hasOwn(env, profile.apiKeyEnv) || !env[profile.apiKeyEnv]) {
|
|
38
|
+
return {
|
|
39
|
+
ok: false,
|
|
40
|
+
reason: `Environment variable '${profile.apiKeyEnv}' is not set or empty`,
|
|
41
|
+
nextAction: `Set the environment variable '${profile.apiKeyEnv}' with a valid API key`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
ok: true,
|
|
46
|
+
profileId,
|
|
47
|
+
model: {
|
|
48
|
+
provider: profile.provider,
|
|
49
|
+
model: profile.model,
|
|
50
|
+
apiKeyEnv: profile.apiKeyEnv,
|
|
51
|
+
...(profile.baseUrl ? { baseUrl: profile.baseUrl } : {}),
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export function createAdaptivePriorityProvider(options) {
|
|
56
|
+
const now = options.now ?? Date.now;
|
|
57
|
+
const firstByteTimeoutMs = options.firstByteTimeoutMs ?? ADAPTIVE_SELECTION_LIMITS.firstByteTimeoutMs;
|
|
58
|
+
const generationTimeoutMs = options.generationTimeoutMs ?? ADAPTIVE_SELECTION_LIMITS.generationTimeoutMs;
|
|
59
|
+
return async (event) => {
|
|
60
|
+
if (event.kind !== 'before_prompt_build')
|
|
61
|
+
return undefined;
|
|
62
|
+
const { sessionId, turnId, promptContent, workspaceDir } = event.context;
|
|
63
|
+
if (!sessionId || !turnId || !promptContent?.trim())
|
|
64
|
+
return undefined;
|
|
65
|
+
const admissionDeadlineAt = options.outerDeadlineAt === undefined
|
|
66
|
+
? now() + firstByteTimeoutMs
|
|
67
|
+
: Math.min(now() + firstByteTimeoutMs, options.outerDeadlineAt);
|
|
68
|
+
const remainingBudgetMs = options.outerDeadlineAt === undefined
|
|
69
|
+
? firstByteTimeoutMs
|
|
70
|
+
: Math.max(1, options.outerDeadlineAt - now());
|
|
71
|
+
const effectiveGenerationTimeoutMs = options.outerDeadlineAt === undefined
|
|
72
|
+
? generationTimeoutMs
|
|
73
|
+
: Math.min(generationTimeoutMs, remainingBudgetMs);
|
|
74
|
+
// Reuse the selector's AbortSignal seam instead of a second timer: it is
|
|
75
|
+
// combined with the first-byte and request signals inside the transport.
|
|
76
|
+
const signal = options.outerDeadlineAt === undefined ? undefined : AbortSignal.timeout(remainingBudgetMs);
|
|
77
|
+
const outcome = await runAdaptiveSelection({
|
|
78
|
+
workspaceDir: workspaceDir || options.workspaceDir,
|
|
79
|
+
currentPrompt: promptContent,
|
|
80
|
+
admissionDeadlineAt,
|
|
81
|
+
model: options.model,
|
|
82
|
+
generationTimeoutMs: effectiveGenerationTimeoutMs,
|
|
83
|
+
...(options.outerDeadlineAt !== undefined ? { outerDeadlineAt: options.outerDeadlineAt } : {}),
|
|
84
|
+
...(signal ? { signal } : {}),
|
|
85
|
+
...(options.maxTokens !== undefined ? { maxTokens: options.maxTokens } : {}),
|
|
86
|
+
...(options.now ? { now: options.now } : {}),
|
|
87
|
+
...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
|
|
88
|
+
});
|
|
89
|
+
options.onDiagnostic?.({
|
|
90
|
+
status: outcome.status,
|
|
91
|
+
reason: outcome.reason,
|
|
92
|
+
stage: outcome.diagnostics.stage,
|
|
93
|
+
sends: outcome.sends,
|
|
94
|
+
firstByteAt: outcome.diagnostics.firstByteAt,
|
|
95
|
+
generationEndedAt: outcome.diagnostics.generationEndedAt,
|
|
96
|
+
cancelledAt: outcome.diagnostics.cancelledAt,
|
|
97
|
+
httpStatus: outcome.diagnostics.httpStatus,
|
|
98
|
+
finishReason: outcome.diagnostics.finishReason,
|
|
99
|
+
failures: [...outcome.diagnostics.failures],
|
|
100
|
+
});
|
|
101
|
+
if (outcome.status !== 'selected' || !outcome.target)
|
|
102
|
+
return undefined;
|
|
103
|
+
return {
|
|
104
|
+
artifactId: outcome.target.artifactId,
|
|
105
|
+
activationId: outcome.target.activationId,
|
|
106
|
+
additiveOnly: true,
|
|
107
|
+
deadlineAt: options.outerDeadlineAt ?? admissionDeadlineAt + generationTimeoutMs,
|
|
108
|
+
...(signal ? { signal } : {}),
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Config-first factory for hosts (Codex pd-hook) that already loaded the
|
|
114
|
+
* workspace config for the current turn.
|
|
115
|
+
*/
|
|
116
|
+
export function createAdaptivePriorityProviderForConfig(config, workspaceDir, options = {}) {
|
|
117
|
+
const resolved = resolveAdaptiveSelectionModel(config, options.env ?? process.env);
|
|
118
|
+
if (!resolved.ok) {
|
|
119
|
+
return {
|
|
120
|
+
ok: false,
|
|
121
|
+
readiness: 'disabled',
|
|
122
|
+
reason: resolved.reason,
|
|
123
|
+
nextAction: resolved.nextAction,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const provider = createAdaptivePriorityProvider({
|
|
127
|
+
workspaceDir,
|
|
128
|
+
model: resolved.model,
|
|
129
|
+
...(options.firstByteTimeoutMs !== undefined ? { firstByteTimeoutMs: options.firstByteTimeoutMs } : {}),
|
|
130
|
+
...(options.generationTimeoutMs !== undefined ? { generationTimeoutMs: options.generationTimeoutMs } : {}),
|
|
131
|
+
...(options.outerDeadlineAt !== undefined ? { outerDeadlineAt: options.outerDeadlineAt } : {}),
|
|
132
|
+
...(options.maxTokens !== undefined ? { maxTokens: options.maxTokens } : {}),
|
|
133
|
+
...(options.now ? { now: options.now } : {}),
|
|
134
|
+
...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
|
|
135
|
+
...(options.onDiagnostic ? { onDiagnostic: options.onDiagnostic } : {}),
|
|
136
|
+
});
|
|
137
|
+
return {
|
|
138
|
+
ok: true,
|
|
139
|
+
readiness: 'ready',
|
|
140
|
+
reason: `adaptive selection ready via runtime profile '${resolved.profileId}'`,
|
|
141
|
+
nextAction: 'none',
|
|
142
|
+
provider,
|
|
143
|
+
profileId: resolved.profileId,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Workspace-facing variant: mirrors the existing signal-classifier readiness
|
|
148
|
+
* contract (flag → profile → api key) so a misconfigured workspace degrades to
|
|
149
|
+
* Native with one observable reason instead of a silent model attempt.
|
|
150
|
+
*/
|
|
151
|
+
export function createAdaptivePriorityProviderForWorkspace(workspaceDir, options = {}) {
|
|
152
|
+
const configResult = loadPdConfigForPlugin(workspaceDir);
|
|
153
|
+
if (!configResult.ok) {
|
|
154
|
+
return {
|
|
155
|
+
ok: false,
|
|
156
|
+
readiness: 'needs_setup',
|
|
157
|
+
reason: configResult.errors[0]?.reason ?? 'invalid .pd/config.yaml',
|
|
158
|
+
nextAction: configResult.errors[0]?.nextAction ?? 'Fix .pd/config.yaml and retry',
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return createAdaptivePriorityProviderForConfig(configResult.effective.config, workspaceDir, options);
|
|
162
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { PiAiRuntimeAdapter, type ActivatedPrinciple } from '@principles/core/runtime';
|
|
2
|
+
export declare const ADAPTIVE_SELECTION_LIMITS: {
|
|
3
|
+
readonly maxCandidates: 12;
|
|
4
|
+
readonly maxCandidateChars: 600;
|
|
5
|
+
readonly maxPriorMessages: 4;
|
|
6
|
+
readonly maxPriorMessageChars: 1200;
|
|
7
|
+
readonly maxInputChars: 6000;
|
|
8
|
+
/** Admission (time-to-first-byte) deadline for the incremental step. */
|
|
9
|
+
readonly firstByteTimeoutMs: 10000;
|
|
10
|
+
/** Bounded completion window once the endpoint has started answering. */
|
|
11
|
+
readonly generationTimeoutMs: 10000;
|
|
12
|
+
readonly maxOutputTokens: 512;
|
|
13
|
+
};
|
|
14
|
+
export type AdaptiveSelectionModel = {
|
|
15
|
+
readonly provider: string;
|
|
16
|
+
readonly model: string;
|
|
17
|
+
readonly apiKeyEnv: string;
|
|
18
|
+
/** Exact request URL when the caller already knows it (lab). */
|
|
19
|
+
readonly url?: string;
|
|
20
|
+
/** Outbound allowlist prefix when only a base URL is known (production). */
|
|
21
|
+
readonly baseUrl?: string;
|
|
22
|
+
};
|
|
23
|
+
export type AdaptiveCandidateSource = ActivatedPrinciple;
|
|
24
|
+
export interface AdaptiveCandidate {
|
|
25
|
+
readonly ref: string;
|
|
26
|
+
readonly text: string;
|
|
27
|
+
readonly digest: string;
|
|
28
|
+
readonly principle: AdaptiveCandidateSource;
|
|
29
|
+
}
|
|
30
|
+
export interface BoundedSelectionInput {
|
|
31
|
+
readonly payload: {
|
|
32
|
+
readonly currentInstruction: string;
|
|
33
|
+
readonly priorMessages: readonly {
|
|
34
|
+
readonly text: string;
|
|
35
|
+
readonly source: string;
|
|
36
|
+
readonly index: number;
|
|
37
|
+
}[];
|
|
38
|
+
/** `digest` is precomputed locally and only copied by the model. */
|
|
39
|
+
readonly candidates: readonly {
|
|
40
|
+
readonly ref: string;
|
|
41
|
+
readonly text: string;
|
|
42
|
+
readonly digest: string;
|
|
43
|
+
}[];
|
|
44
|
+
};
|
|
45
|
+
readonly entries: readonly AdaptiveCandidate[];
|
|
46
|
+
readonly priorDropped: number;
|
|
47
|
+
}
|
|
48
|
+
export type BuildBoundedInputResult = {
|
|
49
|
+
readonly ok: true;
|
|
50
|
+
readonly input: BoundedSelectionInput;
|
|
51
|
+
} | {
|
|
52
|
+
readonly ok: false;
|
|
53
|
+
readonly reason: string;
|
|
54
|
+
};
|
|
55
|
+
export type SelectionShape = {
|
|
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'
|
|
75
|
+
/** The host's outer hook window ended Adaptive; distinct from the model's own timeout. */
|
|
76
|
+
| 'TURN_DEADLINE_EXCEEDED' | 'TRANSPORT_NOT_SENT' | 'TRANSPORT_FAILED' | 'INPUT_REFUSED';
|
|
77
|
+
export type AdaptiveSelectionStage = 'idle' | 'admission' | 'generation' | 'validate' | 'revalidate' | 'done';
|
|
78
|
+
export interface AdaptiveSelectionDiagnostics {
|
|
79
|
+
stage: AdaptiveSelectionStage;
|
|
80
|
+
readonly admissionDeadlineAt: number;
|
|
81
|
+
completionDeadlineAt: number | null;
|
|
82
|
+
firstByteAt: number | null;
|
|
83
|
+
generationEndedAt: number | null;
|
|
84
|
+
cancelledAt: number | null;
|
|
85
|
+
httpStatus: number | null;
|
|
86
|
+
/** Server-reported finish reason, or 'unknown' when the transport does not expose one. */
|
|
87
|
+
finishReason: string;
|
|
88
|
+
usage: {
|
|
89
|
+
inputTokens: number | null;
|
|
90
|
+
outputTokens: number | null;
|
|
91
|
+
} | null;
|
|
92
|
+
failures: AdaptiveFailureCode[];
|
|
93
|
+
}
|
|
94
|
+
export declare function hash(value: string): string;
|
|
95
|
+
export declare const ADAPTIVE_SELECTOR_SYSTEM: string;
|
|
96
|
+
export declare function buildBoundedSelectionInput(input: {
|
|
97
|
+
readonly currentInput: string;
|
|
98
|
+
readonly priorMessages?: readonly {
|
|
99
|
+
readonly text: string;
|
|
100
|
+
readonly source?: string;
|
|
101
|
+
}[];
|
|
102
|
+
readonly candidates: readonly AdaptiveCandidateSource[];
|
|
103
|
+
}): BuildBoundedInputResult;
|
|
104
|
+
export declare function parseSelectionShape(value: unknown): {
|
|
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;
|
|
115
|
+
readonly fetchImpl?: typeof fetch;
|
|
116
|
+
readonly now?: () => number;
|
|
117
|
+
/** Absolute deadline for the first byte of the model response. */
|
|
118
|
+
readonly admissionDeadlineAt: number;
|
|
119
|
+
readonly generationTimeoutMs?: number;
|
|
120
|
+
readonly model: AdaptiveSelectionModel;
|
|
121
|
+
readonly maxTokens?: number;
|
|
122
|
+
readonly signal?: AbortSignal;
|
|
123
|
+
/** Absolute host deadline. Reaching it is NOT the model's generation timeout. */
|
|
124
|
+
readonly outerDeadlineAt?: number;
|
|
125
|
+
}
|
|
126
|
+
export interface SingleModelSelector {
|
|
127
|
+
readonly select: (input: BoundedSelectionInput) => Promise<unknown>;
|
|
128
|
+
readonly report: () => {
|
|
129
|
+
readonly sends: number;
|
|
130
|
+
readonly status: 'not_sent' | 'sent' | 'failed';
|
|
131
|
+
readonly failure: AdaptiveFailureCode | null;
|
|
132
|
+
readonly diagnostics: AdaptiveSelectionDiagnostics;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export declare function createSingleModelSelector(options: SingleModelSelectorOptions): SingleModelSelector;
|
|
136
|
+
export interface RunAdaptiveSelectionOptions {
|
|
137
|
+
readonly workspaceDir: string;
|
|
138
|
+
readonly currentPrompt: string;
|
|
139
|
+
/** Absolute first-byte deadline for the incremental step. */
|
|
140
|
+
readonly admissionDeadlineAt: number;
|
|
141
|
+
readonly model: AdaptiveSelectionModel;
|
|
142
|
+
readonly generationTimeoutMs?: number;
|
|
143
|
+
readonly maxTokens?: number;
|
|
144
|
+
readonly signal?: AbortSignal;
|
|
145
|
+
/** Absolute host deadline shared by selection, revalidation and packing. */
|
|
146
|
+
readonly outerDeadlineAt?: number;
|
|
147
|
+
readonly now?: () => number;
|
|
148
|
+
readonly fetchImpl?: typeof fetch;
|
|
149
|
+
readonly PiAiRuntimeAdapterImpl?: typeof PiAiRuntimeAdapter;
|
|
150
|
+
}
|
|
151
|
+
export interface AdaptiveSelectionOutcome {
|
|
152
|
+
readonly status: 'selected' | 'none' | 'unavailable';
|
|
153
|
+
readonly target: ActivatedPrinciple | null;
|
|
154
|
+
readonly reason: string;
|
|
155
|
+
/** Real transport sends for this turn (0 or 1). */
|
|
156
|
+
readonly sends: number;
|
|
157
|
+
readonly diagnostics: AdaptiveSelectionDiagnostics;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Minimal host-facing selection step: read the current frozen candidates,
|
|
161
|
+
* make at most one bounded model call, verify ref+digest, then independently
|
|
162
|
+
* revalidate the chosen principle's content/revision/authorization.
|
|
163
|
+
*/
|
|
164
|
+
export declare function runAdaptiveSelection(options: RunAdaptiveSelectionOptions): Promise<AdaptiveSelectionOutcome>;
|