@principles/host-runtime 5.2.0 → 5.3.0
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/advisory-delivery.d.ts +34 -0
- package/dist/advisory-delivery.js +69 -0
- package/dist/behavior-history.js +1 -1
- package/dist/cli-recovery-probe.d.ts +23 -2
- package/dist/cli-recovery-probe.js +98 -9
- package/dist/codex-ingestion-consent.d.ts +5 -6
- package/dist/codex-ingestion-consent.js +5 -6
- package/dist/codex-rule-context-provider.js +30 -7
- package/dist/conversation-ingestion/consent.d.ts +14 -31
- package/dist/conversation-ingestion/consent.js +14 -223
- package/dist/fact-assembler.d.ts +91 -0
- package/dist/fact-assembler.js +318 -0
- package/dist/forward-observation.d.ts +6 -0
- package/dist/forward-observation.js +2 -1
- package/dist/host-liveness-contract.js +12 -0
- package/dist/index.d.ts +11 -1
- package/dist/index.js +13 -32
- package/dist/mode-state-facts.d.ts +41 -0
- package/dist/mode-state-facts.js +224 -0
- package/dist/product-telemetry/consent-store.d.ts +9 -47
- package/dist/product-telemetry/consent-store.js +18 -131
- package/dist/production-pain-evidence.d.ts +9 -0
- package/dist/production-pain-evidence.js +22 -2
- package/dist/production-policy-gate.d.ts +104 -0
- package/dist/production-policy-gate.js +379 -0
- package/dist/production-rulehost-gate.d.ts +6 -0
- package/dist/production-rulehost-gate.js +160 -31
- package/dist/prompt-activation-event.d.ts +29 -0
- package/dist/prompt-activation-event.js +80 -0
- package/dist/prompt-injection-budget-observation.d.ts +0 -11
- package/dist/prompt-injection-budget-observation.js +0 -11
- package/dist/rule-policy-active.d.ts +80 -0
- package/dist/rule-policy-active.js +197 -0
- package/dist/rule-policy-host-defaults.d.ts +19 -0
- package/dist/rule-policy-host-defaults.js +12 -0
- package/dist/rule-policy-paths-fs.d.ts +20 -0
- package/dist/rule-policy-paths-fs.js +58 -0
- package/dist/rule-policy-replay-evidence.d.ts +52 -0
- package/dist/rule-policy-replay-evidence.js +259 -0
- package/dist/session-write-targets.d.ts +86 -0
- package/dist/session-write-targets.js +216 -0
- package/dist/signal-classifier.d.ts +1 -0
- package/dist/signal-classifier.js +1 -1
- package/dist/signal-rate-limiter.d.ts +34 -0
- package/dist/signal-rate-limiter.js +83 -0
- package/dist/trajectory-retention.d.ts +8 -0
- package/dist/trajectory-retention.js +29 -0
- package/dist/trusted-pd-binary.d.ts +10 -0
- package/dist/trusted-pd-binary.js +38 -0
- package/dist/workbuddy-rule-context-provider.js +31 -10
- package/dist/workspace-behavior-evidence.d.ts +55 -0
- package/dist/workspace-behavior-evidence.js +93 -0
- package/package.json +24 -4
|
@@ -1,24 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Conversation-ingestion consent ledger v3 (PRI-1171; SPEC v0.2 §8.1).
|
|
3
3
|
*
|
|
4
|
-
* Host-neutral
|
|
5
|
-
* workspace, keyed by host kind, at
|
|
4
|
+
* Host-neutral consent store: ONE file per workspace, keyed by host kind, at
|
|
6
5
|
* `<workspace>/.state/conversation-ingestion-consent.json`.
|
|
7
6
|
*
|
|
8
|
-
* Authority model (P4
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* v2 → v3 migration (one-way, audit-preserving): when no v3 file exists but a
|
|
16
|
-
* legacy `<workspace>/.pd/codex-ingestion-consent.json` (schema v2) does, the
|
|
17
|
-
* first read migrates it — the v3 file is written FIRST (atomic), then the
|
|
18
|
-
* legacy file is RENAMED with a `.superseded` suffix (never deleted). A crash
|
|
19
|
-
* between the two steps is safe: v3 existing means the legacy file is ignored;
|
|
20
|
-
* no v3 means the migration simply retries. Health and the pipeline read ONLY
|
|
21
|
-
* v3 (single authority — no dual-file ambiguity).
|
|
7
|
+
* Authority model (P4): the FEATURE FLAGS stay the runtime authority for
|
|
8
|
+
* whether ingestion runs; this ledger is the GOVERNANCE RECORD that the
|
|
9
|
+
* conversation-ingestion flags may only be enabled THROUGH the disclosed
|
|
10
|
+
* consent flow (or an explicit Owner directive). The unified ingestion
|
|
11
|
+
* pipeline additionally consults the recorded decision as its consent gate
|
|
12
|
+
* (SPEC §8.2: host AND ingestion-flag AND consent=granted).
|
|
22
13
|
*
|
|
23
14
|
* Records carry `disclosureVersion`: consent binds to the disclosure text it
|
|
24
15
|
* was granted against. The full-text tier additionally requires the record's
|
|
@@ -30,28 +21,20 @@
|
|
|
30
21
|
* setup flows (e.g. SPEC approval), with `evidenceRef` pointing at the
|
|
31
22
|
* decision record.
|
|
32
23
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
24
|
+
* Missing file is the normal never-asked case; malformed files fail loud
|
|
25
|
+
* (rc-3/rc-9) because silently treating them as "never asked" could
|
|
26
|
+
* re-enable against a recorded Owner decision; writes are atomic (temp +
|
|
27
|
+
* rename); unknown/malformed fields are rejected via guards, never `as`
|
|
28
|
+
* (rc-1/rc-2/rc-5). This file is consent control state — it never contains
|
|
29
|
+
* captured conversation text.
|
|
39
30
|
*/
|
|
40
31
|
import fs from 'node:fs';
|
|
41
32
|
import path from 'node:path';
|
|
42
33
|
export const CONVERSATION_INGESTION_CONSENT_FILENAME = 'conversation-ingestion-consent.json';
|
|
43
34
|
export const CONVERSATION_INGESTION_CONSENT_SCHEMA_VERSION = '3';
|
|
44
|
-
/** Suffix applied to the superseded v2 file (kept on disk for audit; never read again). */
|
|
45
|
-
export const CONVERSATION_INGESTION_CONSENT_SUPERSEDED_SUFFIX = '.superseded';
|
|
46
|
-
/** Legacy v2 authority location (Codex-only era); migrated on first read. */
|
|
47
|
-
export const LEGACY_CODEX_CONSENT_FILENAME = 'codex-ingestion-consent.json';
|
|
48
|
-
export const LEGACY_CODEX_CONSENT_SCHEMA_VERSION = '2';
|
|
49
35
|
export function getConversationIngestionConsentPath(workspaceDir) {
|
|
50
36
|
return path.join(path.resolve(workspaceDir), '.state', CONVERSATION_INGESTION_CONSENT_FILENAME);
|
|
51
37
|
}
|
|
52
|
-
function getLegacyCodexConsentPath(workspaceDir) {
|
|
53
|
-
return path.join(path.resolve(workspaceDir), '.pd', LEGACY_CODEX_CONSENT_FILENAME);
|
|
54
|
-
}
|
|
55
38
|
function isDecision(value) {
|
|
56
39
|
return value === 'granted' || value === 'pending' || value === 'revoked' || value === 'failed';
|
|
57
40
|
}
|
|
@@ -199,189 +182,9 @@ function writeLedgerAtomically(filePath, ledger) {
|
|
|
199
182
|
};
|
|
200
183
|
}
|
|
201
184
|
}
|
|
202
|
-
/**
|
|
203
|
-
* Parse the legacy Codex v2 record (strict — the same posture as the v2 store:
|
|
204
|
-
* garbage is never silently treated as "never asked").
|
|
205
|
-
*/
|
|
206
|
-
function parseLegacyCodexRecord(raw, filePath) {
|
|
207
|
-
let parsed;
|
|
208
|
-
try {
|
|
209
|
-
parsed = JSON.parse(raw);
|
|
210
|
-
}
|
|
211
|
-
catch {
|
|
212
|
-
return { record: null, read: { ok: false, reason: 'legacy_codex_consent_malformed_json', nextAction: `Fix or delete the legacy file ${filePath}; it blocks the v3 migration until readable.` } };
|
|
213
|
-
}
|
|
214
|
-
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
215
|
-
return { record: null, read: { ok: false, reason: 'legacy_codex_consent_malformed_shape', nextAction: `Fix or delete the legacy file ${filePath}; it blocks the v3 migration until readable.` } };
|
|
216
|
-
}
|
|
217
|
-
const obj = parsed;
|
|
218
|
-
const allowed = ['decision', 'disclosureVersion', 'decidedAt', 'decidedVia', 'failureReason', 'schemaVersion'];
|
|
219
|
-
const errors = [];
|
|
220
|
-
for (const key of Object.keys(obj)) {
|
|
221
|
-
if (!allowed.includes(key))
|
|
222
|
-
errors.push(`unknown field '${key}'`);
|
|
223
|
-
}
|
|
224
|
-
if (!isDecision(obj.decision))
|
|
225
|
-
errors.push('decision must be pending|granted|revoked|failed');
|
|
226
|
-
if (!isNonShortString(obj.disclosureVersion, 40))
|
|
227
|
-
errors.push('disclosureVersion must be a short non-empty string');
|
|
228
|
-
if (!isIsoTimestamp(obj.decidedAt))
|
|
229
|
-
errors.push('decidedAt must be a parseable ISO-8601 string');
|
|
230
|
-
if (!isDecidedVia(obj.decidedVia))
|
|
231
|
-
errors.push('decidedVia must be pd_codex_setup|codex_plugin_setup|owner_directive');
|
|
232
|
-
if (obj.failureReason !== undefined && !isNonShortString(obj.failureReason, 200))
|
|
233
|
-
errors.push('failureReason must be a non-empty string (≤200 chars) when present');
|
|
234
|
-
if (obj.schemaVersion !== LEGACY_CODEX_CONSENT_SCHEMA_VERSION)
|
|
235
|
-
errors.push(`schemaVersion must be '${LEGACY_CODEX_CONSENT_SCHEMA_VERSION}'`);
|
|
236
|
-
if (errors.length > 0) {
|
|
237
|
-
return { record: null, read: { ok: false, reason: `legacy_codex_consent_malformed: ${errors.join('; ').slice(0, 400)}`, nextAction: `Fix or delete the legacy file ${filePath}; it blocks the v3 migration until readable.` } };
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
record: {
|
|
241
|
-
decision: isDecision(obj.decision) ? obj.decision : 'failed',
|
|
242
|
-
disclosureVersion: isNonShortString(obj.disclosureVersion, 40) ? obj.disclosureVersion : '',
|
|
243
|
-
decidedAt: isIsoTimestamp(obj.decidedAt) ? obj.decidedAt : '',
|
|
244
|
-
decidedVia: isDecidedVia(obj.decidedVia) ? obj.decidedVia : 'pd_codex_setup',
|
|
245
|
-
...(isNonShortString(obj.failureReason, 200) && obj.failureReason !== undefined ? { failureReason: obj.failureReason } : {}),
|
|
246
|
-
schemaVersion: CONVERSATION_INGESTION_CONSENT_SCHEMA_VERSION,
|
|
247
|
-
},
|
|
248
|
-
read: null,
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Create the v3 ledger ONLY when it does not exist yet (exclusive create).
|
|
253
|
-
* Content lands via a uniquely-named temp file + atomic hard link, so a
|
|
254
|
-
* concurrent creator can never observe a half-written ledger and this writer
|
|
255
|
-
* can never clobber one: `EEXIST` on the link means someone else created the
|
|
256
|
-
* authority first (possibly carrying a NEWER decision — e.g. a revoke), which
|
|
257
|
-
* must be adopted, not overwritten.
|
|
258
|
-
*/
|
|
259
|
-
function createLedgerIfAbsent(filePath, hosts) {
|
|
260
|
-
const dir = path.dirname(filePath);
|
|
261
|
-
const tmpPath = `${filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
262
|
-
const body = `${JSON.stringify({ schemaVersion: CONVERSATION_INGESTION_CONSENT_SCHEMA_VERSION, hosts }, null, 2)}\n`;
|
|
263
|
-
try {
|
|
264
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
265
|
-
fs.writeFileSync(tmpPath, body, { encoding: 'utf8', mode: 0o600 });
|
|
266
|
-
try {
|
|
267
|
-
fs.linkSync(tmpPath, filePath); // atomic create-or-EEXIST
|
|
268
|
-
return { ok: true, created: true };
|
|
269
|
-
}
|
|
270
|
-
catch (linkError) {
|
|
271
|
-
const codeValue = typeof linkError === 'object' && linkError !== null && Object.hasOwn(linkError, 'code')
|
|
272
|
-
? linkError.code
|
|
273
|
-
: undefined;
|
|
274
|
-
if (codeValue === 'EEXIST')
|
|
275
|
-
return { ok: true, created: false };
|
|
276
|
-
throw linkError;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
catch (error) {
|
|
280
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
281
|
-
return {
|
|
282
|
-
ok: false,
|
|
283
|
-
reason: `conversation_ingestion_consent_write_failed: ${message.slice(0, 200)}`,
|
|
284
|
-
nextAction: `Check permissions on ${dir}`,
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
finally {
|
|
288
|
-
try {
|
|
289
|
-
fs.rmSync(tmpPath, { force: true });
|
|
290
|
-
}
|
|
291
|
-
catch {
|
|
292
|
-
// best-effort temp cleanup; never masks the primary outcome
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
/** Read and validate the existing v3 ledger directly (no recursion back into migration). */
|
|
297
|
-
function adoptExistingLedger(v3Path) {
|
|
298
|
-
let raw;
|
|
299
|
-
try {
|
|
300
|
-
raw = fs.readFileSync(v3Path, 'utf8');
|
|
301
|
-
}
|
|
302
|
-
catch (error) {
|
|
303
|
-
const codeValue = typeof error === 'object' && error !== null && Object.hasOwn(error, 'code')
|
|
304
|
-
? error.code
|
|
305
|
-
: undefined;
|
|
306
|
-
const code = typeof codeValue === 'string' ? codeValue : String(error);
|
|
307
|
-
return unreadable(code, v3Path);
|
|
308
|
-
}
|
|
309
|
-
const { ledger, errors } = parseLedgerFile(raw);
|
|
310
|
-
if (ledger === null)
|
|
311
|
-
return malformed(errors, v3Path);
|
|
312
|
-
const codexRecord = ledger.hosts.codex ?? null;
|
|
313
|
-
return { ok: true, existed: codexRecord !== null, record: codexRecord };
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Migrate a legacy v2 Codex consent file to the v3 ledger: create v3 only if
|
|
317
|
-
* absent (a concurrent writer's newer decisions win), then rename the legacy
|
|
318
|
-
* file with the superseded suffix. Returns the authoritative record, or a
|
|
319
|
-
* loud failure — never a silent "never asked".
|
|
320
|
-
*/
|
|
321
|
-
function migrateLegacyCodexConsent(workspaceDir) {
|
|
322
|
-
const legacyPath = getLegacyCodexConsentPath(workspaceDir);
|
|
323
|
-
let raw;
|
|
324
|
-
try {
|
|
325
|
-
raw = fs.readFileSync(legacyPath, 'utf8');
|
|
326
|
-
}
|
|
327
|
-
catch (error) {
|
|
328
|
-
const codeValue = typeof error === 'object' && error !== null && Object.hasOwn(error, 'code')
|
|
329
|
-
? error.code
|
|
330
|
-
: undefined;
|
|
331
|
-
if (codeValue === 'ENOENT')
|
|
332
|
-
return { ok: true, existed: false, record: null };
|
|
333
|
-
const code = typeof codeValue === 'string' ? codeValue : String(error);
|
|
334
|
-
return unreadable(`legacy read ${code}`, legacyPath);
|
|
335
|
-
}
|
|
336
|
-
const { record, read } = parseLegacyCodexRecord(raw, legacyPath);
|
|
337
|
-
if (read !== null)
|
|
338
|
-
return read;
|
|
339
|
-
if (record === null) {
|
|
340
|
-
// Unreachable in practice (parse either returns a record or a read
|
|
341
|
-
// failure); fail loud rather than assert (rc-2 posture).
|
|
342
|
-
return { ok: false, reason: 'legacy_codex_consent_invalid', nextAction: `Fix or delete the legacy file ${legacyPath}; it blocks the v3 migration until readable.` };
|
|
343
|
-
}
|
|
344
|
-
const v3Path = getConversationIngestionConsentPath(workspaceDir);
|
|
345
|
-
const created = createLedgerIfAbsent(v3Path, { codex: record });
|
|
346
|
-
if (!created.ok)
|
|
347
|
-
return { ok: false, reason: created.reason, nextAction: created.nextAction };
|
|
348
|
-
try {
|
|
349
|
-
fs.renameSync(legacyPath, `${legacyPath}${CONVERSATION_INGESTION_CONSENT_SUPERSEDED_SUFFIX}`);
|
|
350
|
-
}
|
|
351
|
-
catch (error) {
|
|
352
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
353
|
-
if (created.created) {
|
|
354
|
-
// v3 is already authoritative on disk; the un-renamed legacy file is
|
|
355
|
-
// inert (reads consult v3 first) but surface the residue loudly (rc-9).
|
|
356
|
-
return {
|
|
357
|
-
ok: true,
|
|
358
|
-
existed: true,
|
|
359
|
-
record,
|
|
360
|
-
migratedFromLegacy: true,
|
|
361
|
-
warnings: [`legacy_consent_rename_failed: ${message.slice(0, 120)}`],
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
// Someone else created v3 AND we could not supersede the legacy file —
|
|
365
|
-
// inert residue; the existing v3 is adopted below (warning surfaces it).
|
|
366
|
-
const adopted = adoptExistingLedger(v3Path);
|
|
367
|
-
if (!adopted.ok)
|
|
368
|
-
return adopted;
|
|
369
|
-
return { ...adopted, migratedFromLegacy: true, warnings: [...(adopted.warnings ?? []), `legacy_consent_rename_failed: ${message.slice(0, 120)}`] };
|
|
370
|
-
}
|
|
371
|
-
if (created.created) {
|
|
372
|
-
return { ok: true, existed: true, record, migratedFromLegacy: true };
|
|
373
|
-
}
|
|
374
|
-
// v3 already existed (concurrent writer completed the migration or landed a
|
|
375
|
-
// NEWER decision): adopt the existing authority — never overwrite it.
|
|
376
|
-
const adopted = adoptExistingLedger(v3Path);
|
|
377
|
-
if (!adopted.ok)
|
|
378
|
-
return adopted;
|
|
379
|
-
return { ...adopted, migratedFromLegacy: true };
|
|
380
|
-
}
|
|
381
185
|
/**
|
|
382
186
|
* Read one host's consent record from the v3 ledger (the ONLY authority).
|
|
383
|
-
*
|
|
384
|
-
* migration. ENOENT on both is the normal never-asked case.
|
|
187
|
+
* ENOENT is the normal never-asked case.
|
|
385
188
|
*/
|
|
386
189
|
export function readConversationIngestionConsent(workspaceDir, hostKind) {
|
|
387
190
|
const filePath = getConversationIngestionConsentPath(workspaceDir);
|
|
@@ -394,8 +197,6 @@ export function readConversationIngestionConsent(workspaceDir, hostKind) {
|
|
|
394
197
|
? error.code
|
|
395
198
|
: undefined;
|
|
396
199
|
if (codeValue === 'ENOENT') {
|
|
397
|
-
if (hostKind === 'codex')
|
|
398
|
-
return migrateLegacyCodexConsent(workspaceDir);
|
|
399
200
|
return { ok: true, existed: false, record: null };
|
|
400
201
|
}
|
|
401
202
|
const code = typeof codeValue === 'string' ? codeValue : String(error);
|
|
@@ -576,11 +377,6 @@ export function recordConversationIngestionConsent(workspaceDir, hostKind, input
|
|
|
576
377
|
const code = typeof codeValue === 'string' ? codeValue : String(error);
|
|
577
378
|
return { ok: false, reason: `conversation_ingestion_consent_write_failed: ${code.slice(0, 120)}`, nextAction: `Check permissions on ${filePath}` };
|
|
578
379
|
}
|
|
579
|
-
const migrated = migrateLegacyCodexConsent(workspaceDir);
|
|
580
|
-
if (!migrated.ok)
|
|
581
|
-
return { ok: false, reason: migrated.reason, nextAction: migrated.nextAction };
|
|
582
|
-
if (migrated.record !== null)
|
|
583
|
-
hosts = { codex: migrated.record };
|
|
584
380
|
}
|
|
585
381
|
const nextHosts = { ...hosts };
|
|
586
382
|
if (hostKind === 'codex')
|
|
@@ -665,11 +461,6 @@ export function grantConsentIfAbsent(workspaceDir, hostKind, input) {
|
|
|
665
461
|
const code = typeof codeValue === 'string' ? codeValue : String(error);
|
|
666
462
|
return { ok: false, reason: `conversation_ingestion_consent_write_failed: ${code.slice(0, 120)}`, nextAction: `Check permissions on ${filePath}` };
|
|
667
463
|
}
|
|
668
|
-
const migrated = migrateLegacyCodexConsent(workspaceDir);
|
|
669
|
-
if (!migrated.ok)
|
|
670
|
-
return { ok: false, reason: migrated.reason, nextAction: migrated.nextAction };
|
|
671
|
-
if (migrated.record !== null)
|
|
672
|
-
hosts = { codex: migrated.record };
|
|
673
464
|
}
|
|
674
465
|
const existing = hosts[hostKind];
|
|
675
466
|
if (existing !== undefined) {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fact_Assembler (SPEC-PD-RULE-POLICY-001 Requirement 7.3-7.6; design.md §7).
|
|
3
|
+
*
|
|
4
|
+
* `assembleFacts` is a pure function over injected inputs: it holds no database
|
|
5
|
+
* connection. It computes ONLY the facts in `needed`; every other key is absent.
|
|
6
|
+
* Session-activity facts share one read of the session rows, and that reader is
|
|
7
|
+
* not called at all when no activity fact is needed.
|
|
8
|
+
*
|
|
9
|
+
* Unknown is never a default (Requirement 7.6): a fact whose data is missing,
|
|
10
|
+
* unreadable, cut by the scan limit or not provided by the host is
|
|
11
|
+
* `{ unknown: true, reason }`. "Nothing there" is also reported as unknown with a
|
|
12
|
+
* dedicated reason (`no_write_in_session`, `no_failure_streak`,
|
|
13
|
+
* `no_previous_high_impact`) because the fact has no value to hold.
|
|
14
|
+
*/
|
|
15
|
+
import { type BashRiskLevel } from '@principles/core/runtime/internalization/bash-risk';
|
|
16
|
+
import { type CommandClass, type FactId, type FactValue, type HistoryRow } from '@principles/core/runtime/internalization/rule-policy-facts';
|
|
17
|
+
import type { CanonicalKind, ModeStateFact, RuleHistoryWindow, SessionWriteTargets } from '@principles/core/runtime/internalization/rule-context-v2';
|
|
18
|
+
import type { DesignGateFact, ToolSemanticRegistry } from '@principles/core/runtime';
|
|
19
|
+
import { type WorkspaceSessionWriteRowReaderOptions } from './session-write-targets.js';
|
|
20
|
+
export declare const DEFAULT_SCAN_LIMIT = 2000;
|
|
21
|
+
/** `action.targets` above this many entries is unknown, never truncated (bounds anyUnder/allUnder cost). */
|
|
22
|
+
export declare const MAX_ACTION_TARGETS = 500;
|
|
23
|
+
export interface SessionActivityRow {
|
|
24
|
+
id: number;
|
|
25
|
+
toolName: string;
|
|
26
|
+
outcome: string;
|
|
27
|
+
paramsJson: string;
|
|
28
|
+
createdAt: string | number;
|
|
29
|
+
}
|
|
30
|
+
export interface SessionActivityRows {
|
|
31
|
+
/** Newest first. */
|
|
32
|
+
rows: readonly SessionActivityRow[];
|
|
33
|
+
/** True when older rows exist beyond the `limit` that was asked for. */
|
|
34
|
+
truncated: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Injected read-only reader: at most `limit` rows of `sessionId` strictly before
|
|
38
|
+
* `beforeKey`, newest first, and whether older rows were cut. Host scoping
|
|
39
|
+
* (project_dir, host attribution, excluding the current call) lives inside the
|
|
40
|
+
* reader. `beforeKey` is host-defined (ISO created_at cutoff, or an id bound).
|
|
41
|
+
*/
|
|
42
|
+
export type ReadSessionActivityRows = (sessionId: string, beforeKey: string | number, limit: number) => SessionActivityRows;
|
|
43
|
+
/** Facts of the call being decided (from RuleHostInput.action and derived values). Absent field = unknown. */
|
|
44
|
+
export interface CurrentActionFacts {
|
|
45
|
+
kind: CanonicalKind;
|
|
46
|
+
toolName: string;
|
|
47
|
+
targetPaths?: readonly string[];
|
|
48
|
+
/** Single structured target of legacy/host inputs that do not carry targetPaths. */
|
|
49
|
+
normalizedPath?: string | null;
|
|
50
|
+
targetEvidence?: string;
|
|
51
|
+
commandClasses?: readonly CommandClass[];
|
|
52
|
+
bashRisk?: BashRiskLevel;
|
|
53
|
+
isSensitivePath?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* design.md ?11 fallback: `action.targetPaths ?? [normalizedPath-derived key]`.
|
|
57
|
+
* `normalizedPath` is already project-relative when it is provably inside the
|
|
58
|
+
* project. Reject absolute, escaping, synthetic and non-structured labels; never
|
|
59
|
+
* turn an unproven or outside target into a policy key.
|
|
60
|
+
*/
|
|
61
|
+
export declare function normalizedPathTargetKeys(normalizedPath: string | null | undefined, targetEvidence: string | undefined, platform: string): readonly string[] | undefined;
|
|
62
|
+
export interface FactQuery {
|
|
63
|
+
needed: ReadonlySet<FactId>;
|
|
64
|
+
current: CurrentActionFacts;
|
|
65
|
+
sessionWriteTargets: SessionWriteTargets;
|
|
66
|
+
readActivity: ReadSessionActivityRows;
|
|
67
|
+
history: RuleHistoryWindow | undefined;
|
|
68
|
+
/** undefined = the host did not provide mode state. */
|
|
69
|
+
modeState: ModeStateFact | undefined;
|
|
70
|
+
designGate: DesignGateFact | undefined;
|
|
71
|
+
toolSemantics: ToolSemanticRegistry;
|
|
72
|
+
sessionId: string;
|
|
73
|
+
beforeKey: string | number;
|
|
74
|
+
/** Absolute project root that history target keys are relative to. */
|
|
75
|
+
projectRoot: string;
|
|
76
|
+
/** Path key platform; defaults to `process.platform`. */
|
|
77
|
+
platform?: string;
|
|
78
|
+
scanLimit?: number;
|
|
79
|
+
}
|
|
80
|
+
export type UnknownFact = {
|
|
81
|
+
readonly unknown: true;
|
|
82
|
+
readonly reason: string;
|
|
83
|
+
};
|
|
84
|
+
/** What the expression evaluator reads: `FactAssignment` plus the `history` rows (newest first). */
|
|
85
|
+
export type AssembledFacts = Readonly<Partial<Record<FactId, FactValue | readonly HistoryRow[]>>>;
|
|
86
|
+
export declare function assembleFacts(q: FactQuery): AssembledFacts;
|
|
87
|
+
/**
|
|
88
|
+
* Reader for Codex / WorkBuddy over the governance workspace's trajectory
|
|
89
|
+
* database. `beforeKey` must be the ISO created_at cutoff captured at PreToolUse.
|
|
90
|
+
*/
|
|
91
|
+
export declare function createWorkspaceSessionActivityRowReader(workspaceDir: string, options: WorkspaceSessionWriteRowReaderOptions): ReadSessionActivityRows;
|