@principles/host-runtime 4.9.1 → 4.9.3
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/dist/behavior-example-pack-assembler.js +1 -1
- package/dist/behavior-history.js +7 -16
- package/dist/codex-disclosure.d.ts +1 -1
- package/dist/codex-disclosure.js +1 -1
- package/dist/codex-rule-context-provider.js +6 -22
- package/dist/diagnostician-auto-run.js +1 -1
- package/dist/governance-signal-admission.js +7 -13
- package/dist/internalization-consumer-cycle.js +2 -2
- package/dist/internalization-consumer-governance.js +1 -1
- package/dist/intervention-evidence-ingress.js +1 -1
- package/dist/production-pain-evidence.d.ts +0 -7
- package/dist/production-pain-evidence.js +13 -75
- package/dist/source-revocation-sweep.js +59 -8
- package/package.json +4 -4
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* `evidence_source_error` (readTrajectoryStore) so the readiness contract
|
|
18
18
|
* preserves them as storage faults, not Owner evidence faults (§6.2).
|
|
19
19
|
*
|
|
20
|
-
* Spec: docs/superpowers/specs/2026-06-27-rulecode-context-vision-design.md §7.2
|
|
20
|
+
* Spec: docs/archive/superpowers/specs/2026-06-27-rulecode-context-vision-design.md §7.2
|
|
21
21
|
*
|
|
22
22
|
* Boundary: this module is I/O. Pure logic (type + validator) lives in
|
|
23
23
|
* `@principles/core/runtime` → `behavior-example-pack.ts`.
|
package/dist/behavior-history.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/** Shared validated history assembly; host vocabulary is supplied by its owner. */
|
|
2
2
|
import { buildRuleHostAction } from '@principles/core/runtime/internalization/rule-host-input-builder';
|
|
3
|
-
import {
|
|
3
|
+
import { computeConservativeBehaviorFacts as computeCoreConservativeBehaviorFacts } from '@principles/core/runtime/internalization/rule-context-v2';
|
|
4
|
+
export function computeConservativeBehaviorFacts(history, target, sameActionBlockCount) {
|
|
5
|
+
if (target !== null && typeof target === 'object') {
|
|
6
|
+
return computeCoreConservativeBehaviorFacts(history, target, sameActionBlockCount);
|
|
7
|
+
}
|
|
8
|
+
return computeCoreConservativeBehaviorFacts(history, target, sameActionBlockCount);
|
|
9
|
+
}
|
|
4
10
|
const VALID_OUTCOMES = new Set(['success', 'failure', 'blocked']);
|
|
5
11
|
function isPlainObject(value) {
|
|
6
12
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
@@ -16,21 +22,6 @@ function unavailable(reason) {
|
|
|
16
22
|
calls: [],
|
|
17
23
|
};
|
|
18
24
|
}
|
|
19
|
-
export function computeConservativeBehaviorFacts(history, target, sameActionBlockCount) {
|
|
20
|
-
const incomplete = history.truncated || history.calls.some((call) => call.canonicalKind === 'execute' || call.canonicalKind === 'other');
|
|
21
|
-
if (incomplete) {
|
|
22
|
-
return {
|
|
23
|
-
priorReadOfTarget: 'unknown',
|
|
24
|
-
readCount: null,
|
|
25
|
-
writeCount: null,
|
|
26
|
-
uniqueWritePathCount: null,
|
|
27
|
-
sameActionBlockCount: null,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return target !== null && typeof target === 'object'
|
|
31
|
-
? computeBehaviorFacts(history, target, sameActionBlockCount)
|
|
32
|
-
: computeBehaviorFacts(history, target, sameActionBlockCount);
|
|
33
|
-
}
|
|
34
25
|
export function assembleBehaviorHistory(rows, truncated, options) {
|
|
35
26
|
const { projectDir, toolSemantics, currentToolUseId } = options;
|
|
36
27
|
const records = [];
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Codex conversation-ingestion consent disclosure — G2A frozen text (Slice D),
|
|
3
3
|
* amended by the Owner decision recorded as "Amendment 2 — disclosure v2"
|
|
4
4
|
* (2026-11-12) in:
|
|
5
|
-
* docs/superpowers/specs/2026-08-28-codex-governance-closure-g0-g2a-decision.md
|
|
5
|
+
* docs/archive/superpowers/specs/2026-08-28-codex-governance-closure-g0-g2a-decision.md
|
|
6
6
|
* § "Frozen consent disclosure text (setup will show this verbatim)"
|
|
7
7
|
*
|
|
8
8
|
* That document is the language SSoT. The frozen text "must not be weakened
|
package/dist/codex-disclosure.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Codex conversation-ingestion consent disclosure — G2A frozen text (Slice D),
|
|
3
3
|
* amended by the Owner decision recorded as "Amendment 2 — disclosure v2"
|
|
4
4
|
* (2026-11-12) in:
|
|
5
|
-
* docs/superpowers/specs/2026-08-28-codex-governance-closure-g0-g2a-decision.md
|
|
5
|
+
* docs/archive/superpowers/specs/2026-08-28-codex-governance-closure-g0-g2a-decision.md
|
|
6
6
|
* § "Frozen consent disclosure text (setup will show this verbatim)"
|
|
7
7
|
*
|
|
8
8
|
* That document is the language SSoT. The frozen text "must not be weakened
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { computeBehaviorFacts, } from '@principles/core/runtime';
|
|
3
|
+
import { extractFileHeaderPatchTargets } from '@principles/core/runtime/internalization/rule-host-input-builder';
|
|
3
4
|
import { assembleBehaviorHistory, computeConservativeBehaviorFacts } from './behavior-history.js';
|
|
4
5
|
import { readWorkspaceRuleContextRowsBefore } from './workspace-behavior-evidence.js';
|
|
5
6
|
import { readLatestCodexDesignGateDeclaration, resolveCodexDesignGateFact } from './design-gate-facts.js';
|
|
6
7
|
const HISTORY_LIMIT = 100;
|
|
7
8
|
const MAX_REASON_LENGTH = 240;
|
|
8
|
-
const MAX_PATCH_BYTES = 1024 * 1024;
|
|
9
9
|
const APPROVED_READONLY_COMMANDS = new Set([
|
|
10
10
|
'git status',
|
|
11
11
|
'git status --short',
|
|
@@ -18,27 +18,11 @@ function isRecord(value) {
|
|
|
18
18
|
function patchTargets(params, projectDir) {
|
|
19
19
|
if (params === null)
|
|
20
20
|
return undefined;
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
: typeof params.input === 'string'
|
|
27
|
-
? params.input
|
|
28
|
-
: typeof params.command === 'string' ? params.command : null;
|
|
29
|
-
if (patch === null || Buffer.byteLength(patch, 'utf8') > MAX_PATCH_BYTES)
|
|
30
|
-
return undefined;
|
|
31
|
-
const targets = [];
|
|
32
|
-
for (const line of patch.split(/\r?\n/)) {
|
|
33
|
-
const match = /^\*\*\* (?:Add|Update|Delete) File: (.+)$|^\*\*\* Move (?:from|to): (.+)$/.exec(line);
|
|
34
|
-
if (!match)
|
|
35
|
-
continue;
|
|
36
|
-
const value = (match[1] ?? match[2] ?? '').trim();
|
|
37
|
-
if (value.length === 0 || value.includes('\0'))
|
|
38
|
-
return undefined;
|
|
39
|
-
targets.push(path.resolve(projectDir, value));
|
|
40
|
-
}
|
|
41
|
-
return targets.length > 0 ? targets : undefined;
|
|
21
|
+
// The core input builder owns the payload parser/carrier precedence so the
|
|
22
|
+
// design-gate projection and evaluator replay cannot drift into two parsers.
|
|
23
|
+
// This host-layer caller retains only workspace resolution (an I/O-boundary
|
|
24
|
+
// concern) of the lexical header paths.
|
|
25
|
+
return extractFileHeaderPatchTargets(params)?.map((target) => path.resolve(projectDir, target));
|
|
42
26
|
}
|
|
43
27
|
function safeReadonlyCommand(params) {
|
|
44
28
|
if (params === null)
|
|
@@ -76,7 +76,7 @@ export async function runPendingDiagnosticianOnce(options) {
|
|
|
76
76
|
nextAction: capability.nextAction,
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
-
const handle = await createRuntimeStateHandle({ workspaceDir: options.workspaceDir, readonly: false });
|
|
79
|
+
const handle = await createRuntimeStateHandle({ workspaceDir: options.workspaceDir, readonly: false, bootstrapIfMissing: false });
|
|
80
80
|
try {
|
|
81
81
|
const now = options.now ?? new Date().toISOString();
|
|
82
82
|
const candidate = await pickDiagnosticianCandidate(handle.stateManager, options.limit ?? DEFAULT_CANDIDATE_LIMIT, now);
|
|
@@ -35,8 +35,9 @@ import fs from 'node:fs';
|
|
|
35
35
|
import path from 'node:path';
|
|
36
36
|
import { randomUUID } from 'node:crypto';
|
|
37
37
|
import Database from 'better-sqlite3';
|
|
38
|
-
import { collectSync, computeFeatureFlagsFromConfig, CORRECTION_SEED_KEYWORDS, PainToPrincipleService, PrincipleTreeLedgerAdapter, RuntimeStateManager, createDiagnosticianTaskId, sanitizeString, boundCorrectionEvidenceText, fingerprintStatement, isOwnerManualCorrectionEvidence, MAX_EVIDENCE_VALUE_CHARS, evaluateStage2ConfidenceGate, evaluatePainIngress,
|
|
39
|
-
import { deriveProductionCorrectionPainIdentity, hasProductionPainSchema,
|
|
38
|
+
import { collectSync, computeFeatureFlagsFromConfig, CORRECTION_SEED_KEYWORDS, PainToPrincipleService, PrincipleTreeLedgerAdapter, RuntimeStateManager, createDiagnosticianTaskId, sanitizeString, boundCorrectionEvidenceText, fingerprintStatement, isOwnerManualCorrectionEvidence, MAX_EVIDENCE_VALUE_CHARS, evaluateStage2ConfidenceGate, evaluatePainIngress, STAGE2_MAX_ATTEMPTS, PENDING_CANDIDATE_TTL_MS, } from '@principles/core/runtime';
|
|
39
|
+
import { deriveProductionCorrectionPainIdentity, hasProductionPainSchema, } from './production-pain-evidence.js';
|
|
40
|
+
import { convergeTrajectorySchemaVersion } from '@principles/core/runtime/trajectory-schema';
|
|
40
41
|
import { promoteGovernanceEvidence, ensureGovernanceSchema } from './governance-observation-store.js';
|
|
41
42
|
import { readSourceMaterialAuthorization } from './source-material-authorization.js';
|
|
42
43
|
import { readConversationIngestionConsent } from './conversation-ingestion/consent.js';
|
|
@@ -360,18 +361,11 @@ function openAdmissionStore(workspaceDir, factory) {
|
|
|
360
361
|
let db;
|
|
361
362
|
try {
|
|
362
363
|
db = factory ? factory(dbPath) : new Database(dbPath);
|
|
364
|
+
// Clean-Slate: prove the baseline before WAL/DDL can mutate the file.
|
|
365
|
+
convergeTrajectorySchemaVersion(db);
|
|
363
366
|
db.pragma('busy_timeout = 5000');
|
|
364
367
|
db.pragma('journal_mode = WAL');
|
|
365
368
|
ensureGovernanceAdmissionSchema(db);
|
|
366
|
-
// GFI-COMPLETE-REMOVAL-001: the additive governance open does not retire
|
|
367
|
-
// the GFI columns, so a v1 workspace would be judged non-canonical by
|
|
368
|
-
// hasProductionPainSchema and refused. Converge it here with the SAME
|
|
369
|
-
// migration the other raw open paths use (idempotent, no-op on v2).
|
|
370
|
-
migrateLegacyGfiSchema(db);
|
|
371
|
-
// PD Phase 1.5: the canonical readiness probe now also proves the
|
|
372
|
-
// forward-evidence schema (tool_calls.turn_id + environment_snapshots);
|
|
373
|
-
// converge it here like every other raw open path.
|
|
374
|
-
ensureForwardEvidenceSchema(db);
|
|
375
369
|
// The reconciliation pass reads observation-owned tables (promotion
|
|
376
370
|
// tails): one open makes the whole governance schema ready.
|
|
377
371
|
ensureGovernanceSchema(db);
|
|
@@ -1934,7 +1928,7 @@ export async function ensureGovernanceDiagnosticianTask(input) {
|
|
|
1934
1928
|
if (!ownerManual && sourceAuthorization?.status === 'blocked'
|
|
1935
1929
|
&& (sourceAuthorization.reason !== 'consent_missing' || agentAssistedExplicit)) {
|
|
1936
1930
|
const taskId = createDiagnosticianTaskId(input.canonicalPainId);
|
|
1937
|
-
const stateManager = new RuntimeStateManager({ workspaceDir });
|
|
1931
|
+
const stateManager = new RuntimeStateManager({ bootstrapIfMissing: false, workspaceDir });
|
|
1938
1932
|
try {
|
|
1939
1933
|
await stateManager.initialize();
|
|
1940
1934
|
const existing = await stateManager.getTask(taskId);
|
|
@@ -2078,7 +2072,7 @@ export async function ensureGovernanceDiagnosticianTask(input) {
|
|
|
2078
2072
|
// PRI-624: the state manager MUST be closed on every exit — the Slice C
|
|
2079
2073
|
// worker calls this seam every cycle, and a leaked handle would pin the
|
|
2080
2074
|
// workspace state.db for the life of the worker process.
|
|
2081
|
-
const stateManager = new RuntimeStateManager({ workspaceDir });
|
|
2075
|
+
const stateManager = new RuntimeStateManager({ bootstrapIfMissing: false, workspaceDir });
|
|
2082
2076
|
try {
|
|
2083
2077
|
await stateManager.initialize();
|
|
2084
2078
|
let existing = await stateManager.getTask(taskId);
|
|
@@ -151,7 +151,7 @@ export function oldestReadyAgeMs(readyTasks, nowMs) {
|
|
|
151
151
|
async function runReconciliationBudget(workspaceDir, orchestrator, ports) {
|
|
152
152
|
const { logger, emitEvent, logLabel } = ports;
|
|
153
153
|
try {
|
|
154
|
-
const conn = new SqliteConnection(workspaceDir);
|
|
154
|
+
const conn = new SqliteConnection({ workspaceDir, bootstrapIfMissing: false });
|
|
155
155
|
try {
|
|
156
156
|
const cursorStore = new SqliteReconciliationCursorStore(conn);
|
|
157
157
|
const stored = cursorStore.get(SUCCEEDED_TRANSITIONS_SCOPE);
|
|
@@ -298,7 +298,7 @@ async function executeConsumerCycle(workspaceDir, ports, signals) {
|
|
|
298
298
|
}
|
|
299
299
|
let handle = null;
|
|
300
300
|
try {
|
|
301
|
-
handle = await createRuntimeStateHandle({ workspaceDir, readonly: false });
|
|
301
|
+
handle = await createRuntimeStateHandle({ workspaceDir, readonly: false, bootstrapIfMissing: false });
|
|
302
302
|
const { stateManager } = handle;
|
|
303
303
|
// A (最终复核): orchestrator 必须在所有队列状态相关的早退之前创建 —
|
|
304
304
|
// 纯 orphan 场景 (succeeded 后 crash、队列全空 → readyTaskCount=0) 恰恰
|
|
@@ -39,7 +39,7 @@ function makeFlagProbe(workspaceDir) {
|
|
|
39
39
|
}
|
|
40
40
|
/** rollout → ActivationDispatcher 的生产接线 (per dispatch 打开短连接, 与 Console 模式一致) */
|
|
41
41
|
export async function dispatchRolloutActivation(workspaceDir, input, options = {}) {
|
|
42
|
-
const connection = new SqliteConnection(workspaceDir);
|
|
42
|
+
const connection = new SqliteConnection({ workspaceDir, bootstrapIfMissing: false });
|
|
43
43
|
try {
|
|
44
44
|
const piArtifactStore = new SqlitePIArtifactStore(connection);
|
|
45
45
|
const artifactReadModel = {
|
|
@@ -107,7 +107,7 @@ export function createInterventionEvidenceIngress() {
|
|
|
107
107
|
}
|
|
108
108
|
let connection = null;
|
|
109
109
|
try {
|
|
110
|
-
connection = new SqliteConnection({ workspaceDir: input.workspaceDir, busyTimeoutMs: 0 });
|
|
110
|
+
connection = new SqliteConnection({ bootstrapIfMissing: false, workspaceDir: input.workspaceDir, busyTimeoutMs: 0 });
|
|
111
111
|
const store = new SqliteInterventionEvidenceStore(connection);
|
|
112
112
|
const expectedScope = store.getEvidenceScope()?.scopeId ?? scopeIdCandidateFor(input.workspaceDir);
|
|
113
113
|
if (input.batch.evidenceScopeId !== expectedScope) {
|
|
@@ -31,13 +31,6 @@ export declare function deriveProductionCorrectionPainIdentity(fields: {
|
|
|
31
31
|
painId: string;
|
|
32
32
|
};
|
|
33
33
|
declare function hasCanonicalSchema(db: Database.Database): boolean;
|
|
34
|
-
/**
|
|
35
|
-
* PD Phase 1.5 (review round 2 — single migration authority): the local
|
|
36
|
-
* turn_id / environment_snapshots ensures were REMOVED — the migration lives
|
|
37
|
-
* only in @principles/core/runtime/trajectory-schema. Re-exported here so
|
|
38
|
-
* the governance admission store's existing import keeps working.
|
|
39
|
-
*/
|
|
40
|
-
export { ensureForwardEvidenceSchema } from '@principles/core/runtime/trajectory-schema';
|
|
41
34
|
/** One host-verified tool outcome (SPEC-CODEX-PAIN-CLOSURE-001 CR-01). */
|
|
42
35
|
export interface VerifiedToolOutcomeInput {
|
|
43
36
|
/** Host tool-call id — the join key written by the live PostToolUse path. */
|
|
@@ -2,11 +2,11 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import Database from 'better-sqlite3';
|
|
5
|
-
import { applyTrajectorySchemaBase,
|
|
5
|
+
import { applyTrajectorySchemaBase, sanitizeToolParams, sanitizeValue, } from '@principles/core/runtime';
|
|
6
6
|
// PRI-1135: the canonical column declaration lives with the DDL owner. Import
|
|
7
7
|
// the subpath directly so the public runtime barrel surface stays unchanged.
|
|
8
|
-
import { TRAJECTORY_REQUIRED_COLUMNS } from '@principles/core/runtime/trajectory-schema';
|
|
9
|
-
import {
|
|
8
|
+
import { TRAJECTORY_REQUIRED_COLUMNS, convergeTrajectorySchemaVersion } from '@principles/core/runtime/trajectory-schema';
|
|
9
|
+
import { recordEnvironmentSnapshot } from '@principles/core/runtime/trajectory-schema';
|
|
10
10
|
import { resolveTrajectoryDbPath } from '@principles/core/runtime/storage-paths';
|
|
11
11
|
const MAX_PREVIEW = 500;
|
|
12
12
|
function isRecord(value) {
|
|
@@ -221,7 +221,7 @@ function hasCanonicalSchema(db) {
|
|
|
221
221
|
// snapshot analysis, golden fixtures) legitimately read pre-Phase-1.5
|
|
222
222
|
// databases whose rows carry NULL turn_id, and demanding the new columns
|
|
223
223
|
// there would degrade every honest read-only analysis path. Writable opens
|
|
224
|
-
// converge the schema first (
|
|
224
|
+
// converge the schema first (convergeTrajectorySchemaVersion), so a failure
|
|
225
225
|
// here still means the column is truly absent.
|
|
226
226
|
if (!db.readonly) {
|
|
227
227
|
db.prepare('SELECT 1 FROM tool_calls WHERE session_id = ? AND turn_id = ?');
|
|
@@ -230,62 +230,6 @@ function hasCanonicalSchema(db) {
|
|
|
230
230
|
}
|
|
231
231
|
return true;
|
|
232
232
|
}
|
|
233
|
-
/**
|
|
234
|
-
* SPEC-CODEX-PAIN-CLOSURE-001 CR-01: additive migration for the host
|
|
235
|
-
* tool-call id join column. The schema-owning modules (trajectory-schema.ts
|
|
236
|
-
* applyTrajectorySchemaBase) add it for every fresh/managed open; this local
|
|
237
|
-
* ensure covers the raw production-handler open, which historically opens
|
|
238
|
-
* trajectory.db without running the schema apply.
|
|
239
|
-
*/
|
|
240
|
-
function ensureToolCallsToolUseIdColumn(db) {
|
|
241
|
-
const columns = db.prepare('PRAGMA table_info(tool_calls)').all();
|
|
242
|
-
if (columns.some((row) => pragmaField(row, 'name') === 'tool_use_id'))
|
|
243
|
-
return;
|
|
244
|
-
try {
|
|
245
|
-
db.exec('ALTER TABLE tool_calls ADD COLUMN tool_use_id TEXT');
|
|
246
|
-
db.exec('CREATE INDEX IF NOT EXISTS idx_tool_calls_session_tool_use_id ON tool_calls(session_id, tool_use_id)');
|
|
247
|
-
}
|
|
248
|
-
catch {
|
|
249
|
-
// A concurrent writer may have added it between the check and the ALTER;
|
|
250
|
-
// the prepared-statement readiness check below fails loud if it is truly absent.
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
/** Additive migration for verified host cwd binding; legacy rows stay NULL. */
|
|
254
|
-
function ensureToolCallsProjectDirColumn(db) {
|
|
255
|
-
const columns = db.prepare('PRAGMA table_info(tool_calls)').all();
|
|
256
|
-
if (columns.some((row) => pragmaField(row, 'name') === 'project_dir'))
|
|
257
|
-
return;
|
|
258
|
-
try {
|
|
259
|
-
db.exec('ALTER TABLE tool_calls ADD COLUMN project_dir TEXT');
|
|
260
|
-
}
|
|
261
|
-
catch {
|
|
262
|
-
// A concurrent writer may have added it between the check and the ALTER;
|
|
263
|
-
// the prepared-statement readiness check below fails loud if absent.
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* SPEC-RULECODE-HOST-PROMOTION-001 R2: additive migration for producer host
|
|
268
|
-
* attribution. Legacy rows stay NULL — the WorkBuddy rule-context reader
|
|
269
|
-
* treats a NULL stamp as unprovable (never guessed), so no backfill exists.
|
|
270
|
-
*/
|
|
271
|
-
function ensureToolCallsHostKindColumn(db) {
|
|
272
|
-
const columns = db.prepare('PRAGMA table_info(tool_calls)').all();
|
|
273
|
-
if (columns.some((row) => pragmaField(row, 'name') === 'host_kind'))
|
|
274
|
-
return;
|
|
275
|
-
try {
|
|
276
|
-
db.exec('ALTER TABLE tool_calls ADD COLUMN host_kind TEXT');
|
|
277
|
-
}
|
|
278
|
-
catch {
|
|
279
|
-
// Same concurrent-writer contract as the sibling migrations above.
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* PD Phase 1.5 (review round 2 — single migration authority): the local
|
|
284
|
-
* turn_id / environment_snapshots ensures were REMOVED — the migration lives
|
|
285
|
-
* only in @principles/core/runtime/trajectory-schema. Re-exported here so
|
|
286
|
-
* the governance admission store's existing import keeps working.
|
|
287
|
-
*/
|
|
288
|
-
export { ensureForwardEvidenceSchema } from '@principles/core/runtime/trajectory-schema';
|
|
289
233
|
/**
|
|
290
234
|
* SPEC-CODEX-PAIN-CLOSURE-001 CR-01: upgrade the live-hook observation of a
|
|
291
235
|
* tool call with the host-verified final result (exit code) read through the
|
|
@@ -318,15 +262,13 @@ export function recordVerifiedToolOutcomes(args) {
|
|
|
318
262
|
// returning statuses that look successful while the legacy GFI columns
|
|
319
263
|
// survive would hide the bug (rc-9).
|
|
320
264
|
try {
|
|
321
|
-
|
|
265
|
+
convergeTrajectorySchemaVersion(db);
|
|
322
266
|
}
|
|
323
267
|
catch (error) {
|
|
324
268
|
const detail = error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200);
|
|
325
269
|
const reason = `trajectory_migration_failed:${detail}`;
|
|
326
270
|
return args.outcomes.map(() => ({ status: 'unavailable', reason }));
|
|
327
271
|
}
|
|
328
|
-
ensureToolCallsToolUseIdColumn(db);
|
|
329
|
-
ensureToolCallsHostKindColumn(db);
|
|
330
272
|
// Review R3/P2: a KNOWN host's call identity includes its attribution.
|
|
331
273
|
// The lookup matches ONLY rows of the same host — a colliding row from
|
|
332
274
|
// another host (or an unattributed legacy row) is a DIFFERENT record: the
|
|
@@ -434,24 +376,20 @@ export function createProductionPainEvidenceHandler(options = {}) {
|
|
|
434
376
|
try {
|
|
435
377
|
db = options.painDatabaseFactory ? options.painDatabaseFactory(dbPath) : new Database(dbPath);
|
|
436
378
|
db.pragma('busy_timeout = 5000');
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
// PD Phase 1.5 (review round 2 — single migration authority): the
|
|
441
|
-
// turn_id column + environment_snapshots table come from the ONE core
|
|
442
|
-
// ensure (re-exported below).
|
|
443
|
-
ensureForwardEvidenceSchema(db);
|
|
444
|
-
// GFI-COMPLETE-REMOVAL-001: v1 databases are migrated before the canonical
|
|
445
|
-
// verdict; a failed migration is reported by name and never downgraded
|
|
446
|
-
// into "canonical" (rc-9 — no silent fallback).
|
|
379
|
+
// Clean-Slate: pre-baseline databases fail closed before any write.
|
|
380
|
+
// Corruption remains a database-availability failure rather than a
|
|
381
|
+
// schema-version refusal.
|
|
447
382
|
try {
|
|
448
|
-
|
|
383
|
+
convergeTrajectorySchemaVersion(db);
|
|
449
384
|
}
|
|
450
385
|
catch (error) {
|
|
451
386
|
const detail = error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200);
|
|
452
387
|
db.close();
|
|
453
388
|
db = undefined;
|
|
454
|
-
|
|
389
|
+
if (!detail.includes('schema_version_incompatible')) {
|
|
390
|
+
return { decision: 'observe', source: event.source, warnings: [...(emissionWarning ? [emissionWarning] : []), `trajectory_database_unavailable:${detail}`], metadata: { outcome: 'unavailable', duplicate: false, nextAction: 'inspect or repair the selected PD trajectory database' } };
|
|
391
|
+
}
|
|
392
|
+
return { decision: 'observe', source: event.source, warnings: [...(emissionWarning ? [emissionWarning] : []), `trajectory_schema_incompatible:${detail}`], metadata: { outcome: 'unavailable', duplicate: false, nextAction: 'back up the workspace if needed, then run pd runtime init --confirm to initialize a new baseline database' } };
|
|
455
393
|
}
|
|
456
394
|
if (!hasCanonicalSchema(db)) {
|
|
457
395
|
db.close();
|
|
@@ -289,6 +289,9 @@ function sweepTrajectoryDb(args) {
|
|
|
289
289
|
const counts = emptyCounts();
|
|
290
290
|
const failures = [];
|
|
291
291
|
const notApplicable = [];
|
|
292
|
+
if (apply && !fs.existsSync(dbPath)) {
|
|
293
|
+
return { error: 'trajectory_db_not_found: apply sweep will not create the database implicitly' };
|
|
294
|
+
}
|
|
292
295
|
let db;
|
|
293
296
|
try {
|
|
294
297
|
// Directive E2: a dry run opens trajectory.db READ-ONLY (fileMustExist —
|
|
@@ -593,16 +596,25 @@ async function sweepStateDb(args) {
|
|
|
593
596
|
// (schema init / migrations / WAL pragmas are writes). Open state.db with a
|
|
594
597
|
// plain readonly connection instead — the dry run only SELECTs. Applying
|
|
595
598
|
// keeps the manager so task rows go through its CAS authority.
|
|
596
|
-
const stateManager = apply ? new RuntimeStateManager({ workspaceDir }) : null;
|
|
599
|
+
const stateManager = apply ? new RuntimeStateManager({ bootstrapIfMissing: false, workspaceDir }) : null;
|
|
597
600
|
let db;
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
+
try {
|
|
602
|
+
if (stateManager !== null) {
|
|
603
|
+
await stateManager.initialize();
|
|
604
|
+
db = stateManager.connection.getDb();
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
db = new Database(stateDbPath, { readonly: true, fileMustExist: true });
|
|
608
|
+
db.pragma('busy_timeout = 5000');
|
|
609
|
+
db.pragma('query_only = ON');
|
|
610
|
+
}
|
|
601
611
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
612
|
+
catch (error) {
|
|
613
|
+
if (stateManager !== null) {
|
|
614
|
+
await stateManager.close().catch(() => undefined);
|
|
615
|
+
}
|
|
616
|
+
failures.push(`state_db_open_failed: ${(error instanceof Error ? error.message : String(error)).slice(0, 160)}`);
|
|
617
|
+
return { counts, failures, notApplicable };
|
|
606
618
|
}
|
|
607
619
|
try {
|
|
608
620
|
const likePattern = `%${GOVERNANCE_OBSERVATION_SOURCE_REF_PREFIX}${logicalKeyPrefix}%`;
|
|
@@ -922,6 +934,30 @@ function mergeCounts(target, source) {
|
|
|
922
934
|
target[key] += value;
|
|
923
935
|
}
|
|
924
936
|
}
|
|
937
|
+
async function validateApplyStateDbBaseline(workspaceDir) {
|
|
938
|
+
const stateDbPath = resolveStateDbPath(workspaceDir);
|
|
939
|
+
if (!fs.existsSync(stateDbPath))
|
|
940
|
+
return { ok: true };
|
|
941
|
+
const manager = new RuntimeStateManager({ workspaceDir, bootstrapIfMissing: false });
|
|
942
|
+
try {
|
|
943
|
+
await manager.initialize();
|
|
944
|
+
manager.connection.getDb();
|
|
945
|
+
return { ok: true };
|
|
946
|
+
}
|
|
947
|
+
catch (error) {
|
|
948
|
+
const details = typeof error === 'object' && error !== null && 'details' in error
|
|
949
|
+
? error.details
|
|
950
|
+
: undefined;
|
|
951
|
+
return {
|
|
952
|
+
ok: false,
|
|
953
|
+
message: (error instanceof Error ? error.message : String(error)).slice(0, 240),
|
|
954
|
+
...(typeof details?.nextAction === 'string' ? { nextAction: details.nextAction } : {}),
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
finally {
|
|
958
|
+
await manager.close().catch(() => undefined);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
925
961
|
export async function runSourceRevocationSweep(options) {
|
|
926
962
|
const workspaceDir = path.resolve(options.workspaceDir);
|
|
927
963
|
const apply = options.apply === true;
|
|
@@ -977,6 +1013,21 @@ export async function runSourceRevocationSweep(options) {
|
|
|
977
1013
|
checkedOnly: CHECKED_ONLY_LOCATIONS,
|
|
978
1014
|
};
|
|
979
1015
|
}
|
|
1016
|
+
if (apply) {
|
|
1017
|
+
const stateBaseline = await validateApplyStateDbBaseline(workspaceDir);
|
|
1018
|
+
if (!stateBaseline.ok) {
|
|
1019
|
+
return {
|
|
1020
|
+
outcome: 'failed',
|
|
1021
|
+
workspaceDir,
|
|
1022
|
+
ranAt,
|
|
1023
|
+
apply,
|
|
1024
|
+
hosts: [],
|
|
1025
|
+
reason: `state_db_baseline_incompatible: ${stateBaseline.message}`,
|
|
1026
|
+
nextAction: stateBaseline.nextAction ?? 'Inspect or repair the selected PD state database, then rerun the sweep. No revocation cleanup was started.',
|
|
1027
|
+
checkedOnly: CHECKED_ONLY_LOCATIONS,
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
980
1031
|
const trajectoryDbPath = path.join(stateDir, 'trajectory.db');
|
|
981
1032
|
let outcome = 'completed';
|
|
982
1033
|
for (const target of toSweep) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/host-runtime",
|
|
3
|
-
"version": "4.9.
|
|
3
|
+
"version": "4.9.3",
|
|
4
4
|
"description": "Shared host-neutral orchestration for Principles Disciple MVP-Core hook paths.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"lint": "eslint \"src/**/*.ts\""
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@principles/core": "^8.5.
|
|
42
|
+
"@principles/core": "^8.5.3",
|
|
43
43
|
"@principles/install-layout": "^0.12.0",
|
|
44
44
|
"better-sqlite3": "^13.0.3",
|
|
45
45
|
"js-yaml": "^5.4.3"
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@types/node": "^26.6.6",
|
|
50
50
|
"@types/js-yaml": "^4.0.9",
|
|
51
51
|
"typescript": "^7.0.2",
|
|
52
|
-
"vite": "^8.
|
|
52
|
+
"vite": "^8.4.0",
|
|
53
53
|
"vitest": "^5.1.0"
|
|
54
54
|
},
|
|
55
55
|
"repository": {
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"url": "git+https://github.com/csuzngjh/principles.git"
|
|
58
58
|
},
|
|
59
59
|
"license": "Apache-2.0",
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "5443721f3d166ffef0817c53c59d88e38431825e"
|
|
61
61
|
}
|