create-principles-disciple 1.150.1 → 1.150.2
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/ingestion.d.ts +9 -7
- package/codex-adapter/dist/ingestion/ingestion.js +68 -144
- package/codex-adapter/dist/ingestion/transcript-decoder.d.ts +35 -44
- package/codex-adapter/dist/ingestion/transcript-decoder.js +23 -84
- package/codex-adapter/dist/ingestion/transcript-source.d.ts +29 -0
- package/codex-adapter/dist/ingestion/transcript-source.js +65 -0
- package/codex-adapter/dist/pd-hook.d.ts +5 -0
- package/codex-adapter/dist/pd-hook.js +8 -1
- package/console/dist/server/routes/examiner-eligibility.d.ts +73 -0
- package/console/dist/server/routes/examiner-eligibility.js +326 -0
- package/console/dist/server/routes/examiner.js +66 -8
- package/console/dist/web/assets/app.css +40 -0
- package/console/dist/web/assets/app.js +30 -30
- package/core/dist/runtime/config/pd-config-effective.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-effective.js +5 -2
- package/core/dist/runtime/config/pd-config-effective.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 +20 -0
- package/dist/installers/codex-host-installer.js.map +1 -1
- package/host-runtime/dist/adaptive-priority-provider.d.ts +7 -0
- package/host-runtime/dist/adaptive-priority-provider.js +34 -2
- package/host-runtime/dist/adaptive-skip-decision.d.ts +61 -0
- package/host-runtime/dist/adaptive-skip-decision.js +114 -0
- package/host-runtime/dist/codex-ingestion-consent.d.ts +32 -95
- package/host-runtime/dist/codex-ingestion-consent.js +33 -205
- package/host-runtime/dist/conversation-ingestion/consent.d.ts +124 -0
- package/host-runtime/dist/conversation-ingestion/consent.js +531 -0
- package/host-runtime/dist/conversation-ingestion/index.d.ts +12 -0
- package/host-runtime/dist/conversation-ingestion/index.js +12 -0
- package/host-runtime/dist/conversation-ingestion/pipeline.d.ts +101 -0
- package/host-runtime/dist/conversation-ingestion/pipeline.js +162 -0
- package/host-runtime/dist/conversation-ingestion/source.d.ts +172 -0
- package/host-runtime/dist/conversation-ingestion/source.js +111 -0
- package/host-runtime/dist/conversation-ingestion/text-policy.d.ts +51 -0
- package/host-runtime/dist/conversation-ingestion/text-policy.js +68 -0
- package/host-runtime/dist/governance-observation-store.d.ts +9 -7
- package/host-runtime/dist/governance-observation-store.js +20 -4
- package/host-runtime/dist/index.d.ts +1 -0
- package/host-runtime/dist/index.js +6 -0
- package/host-runtime/package.json +1 -1
- package/package.json +2 -2
- package/pd-cli/package.json +1 -1
- package/plugin/dist/bundle.js +213 -213
- package/release-manager/dist/installers/codex-host-installer.js +20 -0
- package/release-manager/package.json +1 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { resolveCodexHome } from './codex-home.js';
|
|
2
|
+
import { validateCodexTranscriptPath } from './transcript-path.js';
|
|
3
|
+
import { classifyCodexVersion, CODEX_VERSION_NEXT_ACTION } from './codex-version.js';
|
|
4
|
+
import { decodeTranscriptWindow } from './transcript-decoder.js';
|
|
5
|
+
export function createCodexTranscriptSource(context) {
|
|
6
|
+
return {
|
|
7
|
+
hostKind: 'codex',
|
|
8
|
+
locate(_session, hints) {
|
|
9
|
+
const home = resolveCodexHome(context.env);
|
|
10
|
+
if (!home.ok)
|
|
11
|
+
return { status: 'degraded', reason: home.reason, nextAction: home.nextAction };
|
|
12
|
+
if (typeof hints.transcriptPath !== 'string' || hints.transcriptPath.length === 0) {
|
|
13
|
+
// SPEC §9: never scan for another file; keep a neutral degraded result.
|
|
14
|
+
return { status: 'degraded', reason: 'transcript_unavailable', nextAction: 'Codex supplied no transcript for this event; nothing is read or fabricated.' };
|
|
15
|
+
}
|
|
16
|
+
const validated = validateCodexTranscriptPath(hints.transcriptPath, home.home);
|
|
17
|
+
if (!validated.ok)
|
|
18
|
+
return { status: 'degraded', reason: validated.reason, nextAction: validated.nextAction };
|
|
19
|
+
return {
|
|
20
|
+
status: 'ok',
|
|
21
|
+
filePath: validated.canonicalPath,
|
|
22
|
+
expectedIdentity: validated.identity,
|
|
23
|
+
sessionIdentity: validated.rolloutIdentity,
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
decodeWindow(locator, window, checkpoint) {
|
|
27
|
+
const decoded = decodeTranscriptWindow({
|
|
28
|
+
bytes: window.bytes,
|
|
29
|
+
fileOffset: window.fileOffset,
|
|
30
|
+
byteBoundReached: window.byteBoundReached,
|
|
31
|
+
rolloutIdentity: locator.sessionIdentity,
|
|
32
|
+
fallbackRootSessionId: checkpoint !== null ? checkpoint.rootSessionId : context.fallbackRootSessionId,
|
|
33
|
+
nowIso: context.now.toISOString(),
|
|
34
|
+
});
|
|
35
|
+
// Supported-version guard (SPEC §9): the version signal lives in the
|
|
36
|
+
// transcript session_meta (or the committed checkpoint after the first
|
|
37
|
+
// batch). Anything below the verified floor or above the verified
|
|
38
|
+
// ceiling refuses the delta — never guess record fields of an unknown
|
|
39
|
+
// contract.
|
|
40
|
+
const cliVersion = decoded.rolloutMeta.cliVersion ?? checkpoint?.cliVersion ?? null;
|
|
41
|
+
const version = classifyCodexVersion(cliVersion);
|
|
42
|
+
const guard = version.status === 'supported'
|
|
43
|
+
? null
|
|
44
|
+
: { reason: `${version.reason}:${cliVersion ?? 'unknown'}`, nextAction: CODEX_VERSION_NEXT_ACTION };
|
|
45
|
+
return {
|
|
46
|
+
observations: decoded.observations,
|
|
47
|
+
rollout: {
|
|
48
|
+
rootSessionId: decoded.rolloutMeta.rootSessionId ?? checkpoint?.rootSessionId ?? context.fallbackRootSessionId,
|
|
49
|
+
...(cliVersion !== null ? { cliVersion } : {}),
|
|
50
|
+
...(decoded.rolloutMeta.parentRolloutIdentity !== null ? { parentRolloutIdentity: decoded.rolloutMeta.parentRolloutIdentity } : {}),
|
|
51
|
+
...(decoded.rolloutMeta.agentIdentity !== null ? { agentIdentity: decoded.rolloutMeta.agentIdentity } : {}),
|
|
52
|
+
...(decoded.rolloutMeta.agentDepth !== null ? { agentDepth: decoded.rolloutMeta.agentDepth } : {}),
|
|
53
|
+
},
|
|
54
|
+
guard,
|
|
55
|
+
compactionTimestamp: decoded.compactionTimestamp,
|
|
56
|
+
rollbackTurns: decoded.rollbackTurns,
|
|
57
|
+
stop: decoded.stop,
|
|
58
|
+
nextByteOffset: decoded.nextByteOffset,
|
|
59
|
+
lastOrdinal: decoded.lastOrdinal,
|
|
60
|
+
warnings: decoded.warnings,
|
|
61
|
+
fileSize: window.fileSize,
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -31,6 +31,11 @@ export interface PdHookDeps {
|
|
|
31
31
|
readonly generationTimeoutMs?: number;
|
|
32
32
|
/** Test seam: effective adaptive budget inside the host hook window. */
|
|
33
33
|
readonly hookBudgetMs?: number;
|
|
34
|
+
/**
|
|
35
|
+
* PRI-1181: remaining-budget floor for the pre-selection skip gate. Defaults
|
|
36
|
+
* to the measured minimum; 0 keeps a cancellation scenario sending.
|
|
37
|
+
*/
|
|
38
|
+
readonly minRemainingBudgetMs?: number;
|
|
34
39
|
}
|
|
35
40
|
export declare function processHookInvocation(rawStdin: string, _env?: EnvMap, cwd?: string, deps?: PdHookDeps): Promise<PdHookResult>;
|
|
36
41
|
export {};
|
|
@@ -30,7 +30,13 @@ function errorMessage(error) {
|
|
|
30
30
|
* rejection apart — never the prompt, the raw response, or credentials.
|
|
31
31
|
*/
|
|
32
32
|
function adaptiveSelectionDiagnostic(line) {
|
|
33
|
-
|
|
33
|
+
// PRI-1181: a deterministic pre-selection skip is normal behaviour (zero
|
|
34
|
+
// reads, zero sends) — it must not be reported as a degraded selection.
|
|
35
|
+
const status = line.status === 'selected'
|
|
36
|
+
? 'adaptive'
|
|
37
|
+
: line.status === 'skipped'
|
|
38
|
+
? 'skipped'
|
|
39
|
+
: 'degraded';
|
|
34
40
|
const failures = line.failures.length > 0 ? line.failures.join('|') : 'none';
|
|
35
41
|
return `[PD] status=${status} reason=adaptive_selection_${line.status}:${line.reason} stage=${line.stage} sends=${line.sends} firstByteAt=${line.firstByteAt ?? 'unknown'} generationEndedAt=${line.generationEndedAt ?? 'unknown'} cancelledAt=${line.cancelledAt ?? 'unknown'} httpStatus=${line.httpStatus ?? 'unknown'} finishReason=${line.finishReason} failures=${failures}`
|
|
36
42
|
.replace(/\s+/g, ' ')
|
|
@@ -427,6 +433,7 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
|
|
|
427
433
|
...(deps.now ? { now: deps.now } : {}),
|
|
428
434
|
...(deps.firstByteTimeoutMs !== undefined ? { firstByteTimeoutMs: deps.firstByteTimeoutMs } : {}),
|
|
429
435
|
...(deps.generationTimeoutMs !== undefined ? { generationTimeoutMs: deps.generationTimeoutMs } : {}),
|
|
436
|
+
...(deps.minRemainingBudgetMs !== undefined ? { minRemainingBudgetMs: deps.minRemainingBudgetMs } : {}),
|
|
430
437
|
outerDeadlineAt: adaptiveDeadlineAt,
|
|
431
438
|
onDiagnostic: (line) => { adaptiveDiagnostics.push(adaptiveSelectionDiagnostic(line)); },
|
|
432
439
|
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { LabModules, StudyRoots } from './examiner-executor.js';
|
|
2
|
+
import { type ProductionSnapshot, type StudyRuleCodeFacts } from './examiner-study-inputs.js';
|
|
3
|
+
/**
|
|
4
|
+
* Phase C: Study eligibility pre-check.
|
|
5
|
+
*
|
|
6
|
+
* The verdict is computed from the SAME authorities the creation path uses:
|
|
7
|
+
* - the workspace ledger (target presence / status);
|
|
8
|
+
* - `buildHostEffectivePrincipleSet` (the lab's status eligibility rule);
|
|
9
|
+
* - `gatherProductionSnapshot` + `deriveStudyRuleCodeFacts` +
|
|
10
|
+
* `buildRuleCodePolicy` (the lab's RuleCode / identifiability rule);
|
|
11
|
+
* - `suiteCaseDefs` (the lab's suite compiler).
|
|
12
|
+
*
|
|
13
|
+
* Creation calls this same function BEFORE materializing, so a study that the
|
|
14
|
+
* pre-check calls BLOCKED is never created, and a study that is created was
|
|
15
|
+
* ELIGIBLE or DEGRADED under exactly these rules.
|
|
16
|
+
*
|
|
17
|
+
* Read-only by contract: no study directory, no state mutation.
|
|
18
|
+
*/
|
|
19
|
+
export type EligibilityCheckId = 'experiment_mode' | 'principle_exists' | 'principle_status' | 'production_snapshot' | 'activation_evidence' | 'rulecode_identifiability' | 'experiment_configuration' | 'suite_available' | 'study_root_writable';
|
|
20
|
+
export type EligibilityCheckStatus = 'PASS' | 'WARNING' | 'BLOCKED';
|
|
21
|
+
export interface EligibilityCheck {
|
|
22
|
+
id: EligibilityCheckId;
|
|
23
|
+
status: EligibilityCheckStatus;
|
|
24
|
+
/** Stable machine code the UI can translate. */
|
|
25
|
+
reasonCode: string;
|
|
26
|
+
/** Technical detail (English); null when there is nothing to add. */
|
|
27
|
+
detail: string | null;
|
|
28
|
+
/** Supporting evidence (ids, markers, counts). */
|
|
29
|
+
evidence: string[];
|
|
30
|
+
/** Owner-facing next step (English); the UI maps reasonCode to localized copy. */
|
|
31
|
+
nextAction: string | null;
|
|
32
|
+
}
|
|
33
|
+
export type EligibilityStatus = 'ELIGIBLE' | 'DEGRADED' | 'BLOCKED';
|
|
34
|
+
export interface StudyEligibilityVerdict {
|
|
35
|
+
status: EligibilityStatus;
|
|
36
|
+
principleId: string;
|
|
37
|
+
/** Owner-facing one-liner; the UI prefers its own localized copy. */
|
|
38
|
+
summary: string;
|
|
39
|
+
/** Stable machine code of the first blocking reason (null when not blocked). */
|
|
40
|
+
reasonCode: string | null;
|
|
41
|
+
/** Alias kept for callers that read "blockingReasonCode". */
|
|
42
|
+
blockingReasonCode: string | null;
|
|
43
|
+
/** First actionable next step, or null when the study is creatable. */
|
|
44
|
+
nextAction: string | null;
|
|
45
|
+
checks: EligibilityCheck[];
|
|
46
|
+
}
|
|
47
|
+
export interface StudyEligibilityInputs {
|
|
48
|
+
snapshot: ProductionSnapshot;
|
|
49
|
+
ruleCodeFacts: StudyRuleCodeFacts;
|
|
50
|
+
}
|
|
51
|
+
export interface StudyEligibilityResult {
|
|
52
|
+
verdict: StudyEligibilityVerdict;
|
|
53
|
+
/** Reusable creation inputs — present whenever the snapshot was gathered. */
|
|
54
|
+
inputs: StudyEligibilityInputs | null;
|
|
55
|
+
}
|
|
56
|
+
declare const EXPERIMENT_MODES: readonly ['isolated_principle', 'full_library_incremental'];
|
|
57
|
+
export type ExperimentMode = (typeof EXPERIMENT_MODES)[number];
|
|
58
|
+
/**
|
|
59
|
+
* Project a verdict into its operator-facing shape. Every HTTP response must
|
|
60
|
+
* use this; the raw verdict stays internal because it also carries the
|
|
61
|
+
* creation inputs (`snapshot` / `ruleCodeFacts`).
|
|
62
|
+
*/
|
|
63
|
+
export declare function toOperatorVerdict(result: StudyEligibilityResult): StudyEligibilityVerdict;
|
|
64
|
+
export declare function evaluateStudyEligibility(args: {
|
|
65
|
+
workspaceDir: string;
|
|
66
|
+
labRoot: string;
|
|
67
|
+
labModules: LabModules;
|
|
68
|
+
roots: StudyRoots;
|
|
69
|
+
principleId: string;
|
|
70
|
+
experimentMode: string;
|
|
71
|
+
suiteKey?: string;
|
|
72
|
+
}): Promise<StudyEligibilityResult>;
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { PrinciplesConsoleModel } from '../models/PrinciplesConsoleModel.js';
|
|
2
|
+
import { writableRootProblem } from './examiner-executor.js';
|
|
3
|
+
import { deriveStudyRuleCodeFacts, gatherProductionSnapshot, isSuiteKey, suiteCaseDefs, } from './examiner-study-inputs.js';
|
|
4
|
+
const EXPERIMENT_MODES = ['isolated_principle', 'full_library_incremental'];
|
|
5
|
+
/** rc-1/rc-2: read a boolean out of an untrusted lab record without `as`. */
|
|
6
|
+
function readBoolean(record, key) {
|
|
7
|
+
const value = record[key];
|
|
8
|
+
return typeof value === 'boolean' ? value : null;
|
|
9
|
+
}
|
|
10
|
+
function readString(record, key) {
|
|
11
|
+
const value = record[key];
|
|
12
|
+
return typeof value === 'string' ? value : null;
|
|
13
|
+
}
|
|
14
|
+
function readRecord(record, key) {
|
|
15
|
+
const value = record[key];
|
|
16
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
17
|
+
? value
|
|
18
|
+
: null;
|
|
19
|
+
}
|
|
20
|
+
function summarize(principleId, checks) {
|
|
21
|
+
const blocking = checks.find((check) => check.status === 'BLOCKED') ?? null;
|
|
22
|
+
const warnings = checks.filter((check) => check.status === 'WARNING');
|
|
23
|
+
const status = blocking !== null
|
|
24
|
+
? 'BLOCKED'
|
|
25
|
+
: warnings.length > 0 ? 'DEGRADED' : 'ELIGIBLE';
|
|
26
|
+
const reasonCode = blocking?.reasonCode ?? null;
|
|
27
|
+
const actionable = blocking ?? warnings[0] ?? null;
|
|
28
|
+
const summary = blocking !== null
|
|
29
|
+
? `This principle cannot be evaluated yet (${blocking.reasonCode}).`
|
|
30
|
+
: warnings.length > 0
|
|
31
|
+
? `The study can be created, but ${warnings.length} production condition(s) are degraded.`
|
|
32
|
+
: 'The study can be created.';
|
|
33
|
+
return {
|
|
34
|
+
status,
|
|
35
|
+
principleId,
|
|
36
|
+
summary,
|
|
37
|
+
reasonCode,
|
|
38
|
+
blockingReasonCode: reasonCode,
|
|
39
|
+
nextAction: status === 'ELIGIBLE' ? null : (actionable?.nextAction ?? null),
|
|
40
|
+
checks,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* An operator payload must never carry a server-side absolute path: it says
|
|
45
|
+
* nothing useful to the Owner, leaks the machine layout, and differs per
|
|
46
|
+
* environment (CI vs local workstation). The rule is enforced at the response
|
|
47
|
+
* boundary so every present and future field is covered — not only the fields
|
|
48
|
+
* that happen to be known today.
|
|
49
|
+
*/
|
|
50
|
+
const ABSOLUTE_PATH = /(?:[A-Za-z]:[\\/]|\\\\[^\s\\/]+[\\/]|\/(?:home|Users|root|tmp|var|private|opt|mnt|srv|workspace|github|\.pd-tmp|pd-tmp)\/)[^\s'",;:)\]]*/g;
|
|
51
|
+
function redactAbsolutePaths(value) {
|
|
52
|
+
return value.replace(ABSOLUTE_PATH, '<path>');
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Project a verdict into its operator-facing shape. Every HTTP response must
|
|
56
|
+
* use this; the raw verdict stays internal because it also carries the
|
|
57
|
+
* creation inputs (`snapshot` / `ruleCodeFacts`).
|
|
58
|
+
*/
|
|
59
|
+
export function toOperatorVerdict(result) {
|
|
60
|
+
const { verdict } = result;
|
|
61
|
+
return {
|
|
62
|
+
...verdict,
|
|
63
|
+
summary: redactAbsolutePaths(verdict.summary),
|
|
64
|
+
nextAction: verdict.nextAction === null ? null : redactAbsolutePaths(verdict.nextAction),
|
|
65
|
+
checks: verdict.checks.map((check) => ({
|
|
66
|
+
...check,
|
|
67
|
+
detail: check.detail === null ? null : redactAbsolutePaths(check.detail),
|
|
68
|
+
evidence: check.evidence.map(redactAbsolutePaths),
|
|
69
|
+
nextAction: check.nextAction === null ? null : redactAbsolutePaths(check.nextAction),
|
|
70
|
+
})),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** Compile one suite case set with a throwaway id. Returns null when usable. */
|
|
74
|
+
async function probeSuite(labRoot, suiteKey) {
|
|
75
|
+
if (!isSuiteKey(suiteKey))
|
|
76
|
+
return `unknown suite key '${suiteKey}'`;
|
|
77
|
+
try {
|
|
78
|
+
const cases = await suiteCaseDefs(labRoot, 'ELIGIBILITY-PROBE', suiteKey);
|
|
79
|
+
if (!Array.isArray(cases) || cases.length === 0)
|
|
80
|
+
return 'the suite compiled to zero cases';
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
return error instanceof Error ? error.message : String(error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export async function evaluateStudyEligibility(args) {
|
|
88
|
+
const checks = [];
|
|
89
|
+
// 1. Experiment mode — the two modes the creation path accepts.
|
|
90
|
+
const mode = EXPERIMENT_MODES.find((candidate) => candidate === args.experimentMode) ?? null;
|
|
91
|
+
checks.push(mode === null
|
|
92
|
+
? {
|
|
93
|
+
id: 'experiment_mode',
|
|
94
|
+
status: 'BLOCKED',
|
|
95
|
+
reasonCode: 'experiment_mode_unsupported',
|
|
96
|
+
detail: `unknown experiment mode '${args.experimentMode}'`,
|
|
97
|
+
evidence: [...EXPERIMENT_MODES],
|
|
98
|
+
nextAction: 'Choose isolated_principle or full_library_incremental.',
|
|
99
|
+
}
|
|
100
|
+
: {
|
|
101
|
+
id: 'experiment_mode',
|
|
102
|
+
status: 'PASS',
|
|
103
|
+
reasonCode: 'experiment_mode_supported',
|
|
104
|
+
detail: null,
|
|
105
|
+
evidence: [mode],
|
|
106
|
+
nextAction: null,
|
|
107
|
+
});
|
|
108
|
+
// 2. Target presence in the workspace ledger.
|
|
109
|
+
const model = new PrinciplesConsoleModel(args.workspaceDir);
|
|
110
|
+
const list = await model.listPrinciples();
|
|
111
|
+
const ledgerPrinciples = (list.principles ?? []).map((p) => ({
|
|
112
|
+
id: p.id,
|
|
113
|
+
version: 'ledger',
|
|
114
|
+
text: p.text,
|
|
115
|
+
status: p.status,
|
|
116
|
+
ruleCount: p.ruleCount ?? 0,
|
|
117
|
+
}));
|
|
118
|
+
const target = ledgerPrinciples.find((p) => p.id === args.principleId) ?? null;
|
|
119
|
+
checks.push(target === null
|
|
120
|
+
? {
|
|
121
|
+
id: 'principle_exists',
|
|
122
|
+
status: 'BLOCKED',
|
|
123
|
+
reasonCode: 'principle_not_found',
|
|
124
|
+
detail: `principle '${args.principleId}' is not in the workspace ledger`,
|
|
125
|
+
evidence: [],
|
|
126
|
+
nextAction: 'Return to Principle Governance and confirm the principle id.',
|
|
127
|
+
}
|
|
128
|
+
: {
|
|
129
|
+
id: 'principle_exists',
|
|
130
|
+
status: 'PASS',
|
|
131
|
+
reasonCode: 'principle_found',
|
|
132
|
+
detail: null,
|
|
133
|
+
evidence: [target.id, `status:${target.status}`],
|
|
134
|
+
nextAction: null,
|
|
135
|
+
});
|
|
136
|
+
if (target === null) {
|
|
137
|
+
return { verdict: summarize(args.principleId, checks), inputs: null };
|
|
138
|
+
}
|
|
139
|
+
// 3. Status eligibility — the lab's own rule (never re-implemented here).
|
|
140
|
+
const heps = args.labModules.study.buildHostEffectivePrincipleSet({
|
|
141
|
+
principles: ledgerPrinciples,
|
|
142
|
+
targetPrincipleId: args.principleId,
|
|
143
|
+
host: 'offline-stub',
|
|
144
|
+
});
|
|
145
|
+
const hepsTarget = readRecord(heps, 'target');
|
|
146
|
+
const qualifies = hepsTarget === null ? null : readBoolean(hepsTarget, 'qualifies');
|
|
147
|
+
const exclusionReason = hepsTarget === null ? null : readString(hepsTarget, 'exclusionReason');
|
|
148
|
+
checks.push(qualifies === true
|
|
149
|
+
? {
|
|
150
|
+
id: 'principle_status',
|
|
151
|
+
status: 'PASS',
|
|
152
|
+
reasonCode: 'principle_status_eligible',
|
|
153
|
+
detail: null,
|
|
154
|
+
evidence: [`status:${target.status}`],
|
|
155
|
+
nextAction: null,
|
|
156
|
+
}
|
|
157
|
+
: {
|
|
158
|
+
id: 'principle_status',
|
|
159
|
+
status: 'BLOCKED',
|
|
160
|
+
reasonCode: 'principle_not_active',
|
|
161
|
+
detail: exclusionReason === null
|
|
162
|
+
? 'the lab could not confirm that the target principle is eligible'
|
|
163
|
+
: `target eligibility refused: ${exclusionReason}`,
|
|
164
|
+
evidence: [`status:${target.status}`],
|
|
165
|
+
nextAction: 'Only active principles can be studied — complete the governance decision first.',
|
|
166
|
+
});
|
|
167
|
+
// 4. Production snapshot — read-only freeze facts (degraded is observable,
|
|
168
|
+
// never silently treated as "zero activations").
|
|
169
|
+
let snapshot = null;
|
|
170
|
+
try {
|
|
171
|
+
snapshot = await gatherProductionSnapshot(args.workspaceDir, args.principleId, 2000);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
checks.push({
|
|
175
|
+
id: 'production_snapshot',
|
|
176
|
+
status: 'BLOCKED',
|
|
177
|
+
reasonCode: 'snapshot_unreadable',
|
|
178
|
+
detail: error instanceof Error ? error.message : String(error),
|
|
179
|
+
evidence: [],
|
|
180
|
+
nextAction: 'Repair the workspace runtime state, then retry the pre-check.',
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (snapshot !== null) {
|
|
184
|
+
const degraded = snapshot.runtimeActivation.status !== 'ok';
|
|
185
|
+
checks.push({
|
|
186
|
+
id: 'production_snapshot',
|
|
187
|
+
status: 'PASS',
|
|
188
|
+
reasonCode: 'snapshot_readable',
|
|
189
|
+
detail: null,
|
|
190
|
+
evidence: [`ledger_active:${snapshot.ledgerActivePrincipleIds.length}`],
|
|
191
|
+
nextAction: null,
|
|
192
|
+
});
|
|
193
|
+
// One check per id, and never a PASS over unknown evidence: a degraded
|
|
194
|
+
// activation read model means the baseline cannot be confirmed.
|
|
195
|
+
const activationWarning = degraded
|
|
196
|
+
? {
|
|
197
|
+
id: 'activation_evidence',
|
|
198
|
+
status: 'WARNING',
|
|
199
|
+
reasonCode: 'activation_data_degraded',
|
|
200
|
+
detail: snapshot.runtimeActivation.reason ?? 'the runtime activation read model reported degraded',
|
|
201
|
+
evidence: ['ACTIVATION_DATA_DEGRADED'],
|
|
202
|
+
nextAction: snapshot.runtimeActivation.nextAction ?? 'Inspect the workspace runtime state.',
|
|
203
|
+
}
|
|
204
|
+
: snapshot.targetPrinciple.runtimePromptActive === false
|
|
205
|
+
? {
|
|
206
|
+
id: 'activation_evidence',
|
|
207
|
+
status: 'WARNING',
|
|
208
|
+
reasonCode: 'runtime_prompt_inactive',
|
|
209
|
+
detail: 'the target principle is ledger-active but has no active runtime prompt activation row',
|
|
210
|
+
evidence: [args.principleId],
|
|
211
|
+
nextAction: 'Activate the principle for the runtime, or treat the offline result as a baseline-only comparison.',
|
|
212
|
+
}
|
|
213
|
+
: null;
|
|
214
|
+
checks.push(activationWarning ?? {
|
|
215
|
+
id: 'activation_evidence',
|
|
216
|
+
status: 'PASS',
|
|
217
|
+
reasonCode: 'activation_evidence_present',
|
|
218
|
+
detail: null,
|
|
219
|
+
evidence: [`runtime_prompt_active:${snapshot.targetPrinciple.runtimePromptActive !== false}`],
|
|
220
|
+
nextAction: null,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
// 5. RuleCode identifiability — the lab's policy over runtime-derived facts.
|
|
224
|
+
let ruleCodeFacts = null;
|
|
225
|
+
if (snapshot !== null) {
|
|
226
|
+
ruleCodeFacts = deriveStudyRuleCodeFacts(snapshot);
|
|
227
|
+
if (mode === null) {
|
|
228
|
+
// Cannot evaluate the policy without a mode; the mode check already blocks.
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
const policy = args.labModules.study.buildRuleCodePolicy({
|
|
232
|
+
mode,
|
|
233
|
+
ruleCodes: ruleCodeFacts.ruleCodes,
|
|
234
|
+
targetPrincipleId: args.principleId,
|
|
235
|
+
principleRuleCodeIndependence: ruleCodeFacts.principleRuleCodeIndependence,
|
|
236
|
+
targetRuleCodeCount: ruleCodeFacts.targetRuleCodeCount,
|
|
237
|
+
});
|
|
238
|
+
const executable = readBoolean(policy, 'executable');
|
|
239
|
+
const identifiability = readString(policy, 'identifiability');
|
|
240
|
+
const couplingReason = readString(policy, 'couplingReason');
|
|
241
|
+
checks.push(executable === true
|
|
242
|
+
? {
|
|
243
|
+
id: 'rulecode_identifiability',
|
|
244
|
+
status: 'PASS',
|
|
245
|
+
reasonCode: 'intervention_identifiable',
|
|
246
|
+
detail: ruleCodeFacts.evidenceNote,
|
|
247
|
+
evidence: [`target_rulecodes:${ruleCodeFacts.targetRuleCodeCount}`],
|
|
248
|
+
nextAction: null,
|
|
249
|
+
}
|
|
250
|
+
: {
|
|
251
|
+
id: 'rulecode_identifiability',
|
|
252
|
+
status: 'BLOCKED',
|
|
253
|
+
reasonCode: 'intervention_not_identifiable',
|
|
254
|
+
detail: couplingReason ?? `the RuleCode policy is not executable (identifiability: ${identifiability ?? 'unknown'})`,
|
|
255
|
+
evidence: [`target_rulecodes:${ruleCodeFacts.targetRuleCodeCount}`],
|
|
256
|
+
nextAction: 'Resolve the target principle\u2019s RuleCode baseline (or its independence evidence) before evaluating it.',
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
// 6. Experiment vs production configuration — a stated difference, never a
|
|
261
|
+
// silent one: it limits what an offline result can be compared against.
|
|
262
|
+
if (snapshot !== null) {
|
|
263
|
+
const { markers } = snapshot.experimentVsProduction;
|
|
264
|
+
checks.push(markers.length > 0
|
|
265
|
+
? {
|
|
266
|
+
id: 'experiment_configuration',
|
|
267
|
+
status: 'WARNING',
|
|
268
|
+
reasonCode: 'experiment_config_differs',
|
|
269
|
+
detail: 'the experiment configuration differs from the production injection path',
|
|
270
|
+
evidence: markers,
|
|
271
|
+
nextAction: null,
|
|
272
|
+
}
|
|
273
|
+
: {
|
|
274
|
+
id: 'experiment_configuration',
|
|
275
|
+
status: 'PASS',
|
|
276
|
+
reasonCode: 'experiment_configuration_matches',
|
|
277
|
+
detail: null,
|
|
278
|
+
evidence: [],
|
|
279
|
+
nextAction: null,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
// 7. Research suite availability — compile the selected suite once.
|
|
283
|
+
if (args.suiteKey !== undefined) {
|
|
284
|
+
const suiteProblem = await probeSuite(args.labRoot, args.suiteKey);
|
|
285
|
+
checks.push(suiteProblem === null
|
|
286
|
+
? {
|
|
287
|
+
id: 'suite_available',
|
|
288
|
+
status: 'PASS',
|
|
289
|
+
reasonCode: 'suite_available',
|
|
290
|
+
detail: null,
|
|
291
|
+
evidence: [args.suiteKey],
|
|
292
|
+
nextAction: null,
|
|
293
|
+
}
|
|
294
|
+
: {
|
|
295
|
+
id: 'suite_available',
|
|
296
|
+
status: 'BLOCKED',
|
|
297
|
+
reasonCode: 'suite_unavailable',
|
|
298
|
+
detail: suiteProblem,
|
|
299
|
+
evidence: [args.suiteKey],
|
|
300
|
+
nextAction: 'Choose another research suite from the server-fixed catalog.',
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
// 8. Writable study root — creation would refuse here with 409/422.
|
|
304
|
+
const rootProblem = writableRootProblem(args.roots);
|
|
305
|
+
checks.push(rootProblem === null
|
|
306
|
+
? {
|
|
307
|
+
id: 'study_root_writable',
|
|
308
|
+
status: 'PASS',
|
|
309
|
+
reasonCode: 'study_root_writable',
|
|
310
|
+
detail: null,
|
|
311
|
+
evidence: ['root:isolated'],
|
|
312
|
+
nextAction: null,
|
|
313
|
+
}
|
|
314
|
+
: {
|
|
315
|
+
id: 'study_root_writable',
|
|
316
|
+
status: 'BLOCKED',
|
|
317
|
+
reasonCode: 'study_root_not_writable',
|
|
318
|
+
detail: rootProblem,
|
|
319
|
+
evidence: ['root:not_isolated'],
|
|
320
|
+
nextAction: 'Fix the workspace examiner root isolation before creating a study.',
|
|
321
|
+
});
|
|
322
|
+
return {
|
|
323
|
+
verdict: summarize(args.principleId, checks),
|
|
324
|
+
inputs: snapshot !== null && ruleCodeFacts !== null ? { snapshot, ruleCodeFacts } : null,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
@@ -5,7 +5,8 @@ import { sendSuccess, sendError, sendNotFound, sendJson } from '../utils/respons
|
|
|
5
5
|
import { PrinciplesConsoleModel } from '../models/PrinciplesConsoleModel.js';
|
|
6
6
|
import { ExaminerEvidenceModel } from '../models/ExaminerEvidenceModel.js';
|
|
7
7
|
import { loadLabModules, loadHostCapability, preflightCheck, offlineStudyPass, reportMaterialize, listStudyNames, resolveStudyAccess, resolveStudyRoots, studyReportPayload, materializeConsoleStudy, verifyConsoleOwnership, writableRootProblem, isJsonObject, ExaminerPreflightBlockedError, } from './examiner-executor.js';
|
|
8
|
-
import { listSuiteCatalog, isSuiteKey,
|
|
8
|
+
import { listSuiteCatalog, isSuiteKey, readProductionSnapshot, } from './examiner-study-inputs.js';
|
|
9
|
+
import { evaluateStudyEligibility, toOperatorVerdict } from './examiner-eligibility.js';
|
|
9
10
|
import { appendConsoleRunEventLocked, readConsoleRuns, currentConsoleRun, recoverUnfinishedConsoleRuns, acceptConsoleRun, hostDryRunPass, f2AuthorizationGate, CONSOLE_RUN_SCHEMA, CONSOLE_RUN_MODES, ConsoleRunInProgressError, ConsoleLedgerUnreadableError, studyStatusPayload, assertOfflineAdmissionAllowed, } from './examiner-runs.js';
|
|
10
11
|
/* eslint-disable @typescript-eslint/max-params -- node:http handler signature (req, res, workspaceDir, subPath) matches every other route */
|
|
11
12
|
const LAB_ENTRY = path.join('lib', 'examiner-study.mjs');
|
|
@@ -196,6 +197,39 @@ export async function handleExaminerRoute(req, res, workspaceDir, subPath) {
|
|
|
196
197
|
sendSuccess(res, { principles, note: 'study inputs are read from the workspace ledger (read-only); eligibility filtering happens inside the Examiner contract' });
|
|
197
198
|
return;
|
|
198
199
|
}
|
|
200
|
+
// ── Phase C: Study eligibility PRE-CHECK (read-only; creates nothing).
|
|
201
|
+
// Answers "would a study for this principle be creatable right now, and with
|
|
202
|
+
// which caveats" using the SAME functions POST /studies re-runs before it
|
|
203
|
+
// materializes anything. /principles/<id>/eligibility
|
|
204
|
+
const eligibilityPrincipleId = subPath.startsWith(evidencePrefix) && subPath.endsWith('/eligibility')
|
|
205
|
+
? subPath.slice(evidencePrefix.length, subPath.length - '/eligibility'.length)
|
|
206
|
+
: null;
|
|
207
|
+
if (eligibilityPrincipleId !== null && PRINCIPLE_ID_PATTERN.test(eligibilityPrincipleId) && method === 'GET') {
|
|
208
|
+
const requestUrl = new URL(req.url ?? '', 'http://localhost');
|
|
209
|
+
const requestedEligibilityMode = requestUrl.searchParams.get('mode');
|
|
210
|
+
const experimentMode = requestedEligibilityMode === 'isolated_principle' ? 'isolated_principle' : 'full_library_incremental';
|
|
211
|
+
const requestedSuite = requestUrl.searchParams.get('suite');
|
|
212
|
+
// Mirror the creation fallback: an unrecognized/absent suite becomes the
|
|
213
|
+
// v0.9 default, so the pre-check never disagrees with what creation uses.
|
|
214
|
+
const suiteKey = requestedSuite !== null && isSuiteKey(requestedSuite) ? requestedSuite : 'didactic-pair';
|
|
215
|
+
const eligibility = await evaluateStudyEligibility({
|
|
216
|
+
workspaceDir,
|
|
217
|
+
labRoot,
|
|
218
|
+
labModules,
|
|
219
|
+
roots,
|
|
220
|
+
principleId: eligibilityPrincipleId,
|
|
221
|
+
experimentMode,
|
|
222
|
+
suiteKey,
|
|
223
|
+
});
|
|
224
|
+
sendSuccess(res, {
|
|
225
|
+
...toOperatorVerdict(eligibility),
|
|
226
|
+
experimentMode,
|
|
227
|
+
suiteKey,
|
|
228
|
+
productionSnapshotMarkers: eligibility.inputs?.snapshot.experimentVsProduction.markers ?? [],
|
|
229
|
+
note: 'read-only pre-check: nothing was created; the same checks run again before any study is materialized',
|
|
230
|
+
});
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
199
233
|
// ── v0.10.1 §9: challenge-suite catalog (server-fixed keys, read-only).
|
|
200
234
|
if (subPath === '/suites' && method === 'GET') {
|
|
201
235
|
const suites = await listSuiteCatalog(labRoot);
|
|
@@ -249,14 +283,38 @@ export async function handleExaminerRoute(req, res, workspaceDir, subPath) {
|
|
|
249
283
|
return;
|
|
250
284
|
}
|
|
251
285
|
const isolatedMode = requestedMode === 'isolated_principle';
|
|
286
|
+
const experimentMode = isolatedMode ? 'isolated_principle' : 'full_library_incremental';
|
|
252
287
|
try {
|
|
288
|
+
// Phase C2: creation runs the SAME eligibility implementation the
|
|
289
|
+
// pre-check endpoint exposes, BEFORE any file is written. A study the
|
|
290
|
+
// pre-check calls BLOCKED is never created; a created study was ELIGIBLE
|
|
291
|
+
// or DEGRADED under exactly those rules.
|
|
292
|
+
const eligibility = await evaluateStudyEligibility({
|
|
293
|
+
workspaceDir,
|
|
294
|
+
labRoot,
|
|
295
|
+
labModules,
|
|
296
|
+
roots,
|
|
297
|
+
principleId: requestedTarget,
|
|
298
|
+
experimentMode,
|
|
299
|
+
suiteKey,
|
|
300
|
+
});
|
|
301
|
+
if (eligibility.verdict.status === 'BLOCKED' || eligibility.inputs === null) {
|
|
302
|
+
const operatorVerdict = toOperatorVerdict(eligibility);
|
|
303
|
+
sendError(res, 422, 'study_creation_refused', 'the eligibility pre-check refused creation (no file was written)', {
|
|
304
|
+
// `error` stays the stable family code; `reason` carries the
|
|
305
|
+
// specific refusal so a client never has to parse prose.
|
|
306
|
+
reason: operatorVerdict.reasonCode,
|
|
307
|
+
nextAction: operatorVerdict.nextAction,
|
|
308
|
+
blockingReasonCode: operatorVerdict.blockingReasonCode,
|
|
309
|
+
eligibility: operatorVerdict,
|
|
310
|
+
});
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
253
313
|
// v0.10.1 host-backed inputs (SPEC §4/§6/§7): freeze the production
|
|
254
|
-
// snapshot
|
|
255
|
-
// carry the real pain lineage and compile the
|
|
256
|
-
//
|
|
257
|
-
|
|
258
|
-
// (suiteCaseDefs is deterministic; the ids are re-minted below).
|
|
259
|
-
const snapshot = await gatherProductionSnapshot(workspaceDir, requestedTarget, 2000);
|
|
314
|
+
// snapshot and the RuleCode facts the pre-check already derived from
|
|
315
|
+
// RUNTIME activation truth, carry the real pain lineage and compile the
|
|
316
|
+
// selected suite's cases.
|
|
317
|
+
const { snapshot, ruleCodeFacts } = eligibility.inputs;
|
|
260
318
|
const detailOutput = await model.getPrincipleDetail(requestedTarget);
|
|
261
319
|
const painRefs = detailOutput?.principle.derivedFromPainIds ?? [];
|
|
262
320
|
const created = await materializeConsoleStudy(labModules, labRoot, roots, {
|
|
@@ -267,7 +325,7 @@ export async function handleExaminerRoute(req, res, workspaceDir, subPath) {
|
|
|
267
325
|
suiteKey,
|
|
268
326
|
hostBacked: {
|
|
269
327
|
productionSnapshot: { ...snapshot },
|
|
270
|
-
ruleCodeFacts
|
|
328
|
+
ruleCodeFacts,
|
|
271
329
|
painRefs,
|
|
272
330
|
},
|
|
273
331
|
});
|