@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
|
@@ -36,6 +36,61 @@ export declare function readWorkspaceRuleContextRowsBefore(workspaceDir: string,
|
|
|
36
36
|
limit: number;
|
|
37
37
|
hostKind?: string;
|
|
38
38
|
}): WorkspaceRuleContextRowsResult;
|
|
39
|
+
/**
|
|
40
|
+
* Session-wide (no window, no LIMIT) write-tool rows before a pre-event cutoff.
|
|
41
|
+
*
|
|
42
|
+
* Unlike `readWorkspaceRuleContextRowsBefore` this never truncates: the caller
|
|
43
|
+
* counts distinct write targets over the whole session. Scope is the same
|
|
44
|
+
* proven scope as the window reader plus a mandatory host stamp: rows must
|
|
45
|
+
* carry `project_dir = projectDir` and `host_kind = hostKind`. Unscoped or
|
|
46
|
+
* unattributed rows are excluded, which can only lower a lower bound.
|
|
47
|
+
* Uses `idx_tool_calls_session_id`; the tool-name list is derived from the
|
|
48
|
+
* session's own distinct names, so no write-tool name table is duplicated here.
|
|
49
|
+
* Read-only; never creates or migrates trajectory state.
|
|
50
|
+
*/
|
|
51
|
+
export interface WorkspaceSessionWriteRowsInput {
|
|
52
|
+
sessionId: string;
|
|
53
|
+
projectDir: string;
|
|
54
|
+
hostKind: string;
|
|
55
|
+
beforeCreatedAt: string;
|
|
56
|
+
excludeToolUseId: string;
|
|
57
|
+
isWriteTool: (toolName: string) => boolean;
|
|
58
|
+
}
|
|
59
|
+
export declare function readWorkspaceSessionWriteRowsBefore(workspaceDir: string, input: WorkspaceSessionWriteRowsInput): readonly {
|
|
60
|
+
id: number;
|
|
61
|
+
toolName: string;
|
|
62
|
+
outcome: string;
|
|
63
|
+
paramsJson: string;
|
|
64
|
+
}[];
|
|
65
|
+
export interface WorkspaceSessionActivityRowsInput {
|
|
66
|
+
sessionId: string;
|
|
67
|
+
projectDir: string;
|
|
68
|
+
hostKind: string;
|
|
69
|
+
beforeCreatedAt: string;
|
|
70
|
+
excludeToolUseId: string;
|
|
71
|
+
/** Maximum rows returned; the reader fetches one more to learn whether the scan was cut. */
|
|
72
|
+
limit: number;
|
|
73
|
+
}
|
|
74
|
+
export interface WorkspaceSessionActivityRows {
|
|
75
|
+
/** Newest first (`created_at DESC, id DESC`). */
|
|
76
|
+
rows: readonly {
|
|
77
|
+
id: number;
|
|
78
|
+
toolName: string;
|
|
79
|
+
outcome: string;
|
|
80
|
+
paramsJson: string;
|
|
81
|
+
createdAt: string;
|
|
82
|
+
}[];
|
|
83
|
+
/** True when older rows exist beyond `limit`. */
|
|
84
|
+
truncated: boolean;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Session activity rows (every tool kind) before a pre-event cutoff, newest
|
|
88
|
+
* first, at most `limit`. Same proven scope as the write-row reader:
|
|
89
|
+
* `project_dir`, mandatory `host_kind`, the cutoff and the current tool_use_id;
|
|
90
|
+
* unscoped or unattributed rows are excluded. Uses `idx_tool_calls_session_id`.
|
|
91
|
+
* Read-only; never creates or migrates trajectory state.
|
|
92
|
+
*/
|
|
93
|
+
export declare function readWorkspaceSessionActivityRowsBefore(workspaceDir: string, input: WorkspaceSessionActivityRowsInput): WorkspaceSessionActivityRows;
|
|
39
94
|
/**
|
|
40
95
|
* List only Codex sessions proven by normalized host evidence and a matching
|
|
41
96
|
* project-scoped trajectory row. The trajectory schema has no host_kind on
|
|
@@ -159,6 +159,99 @@ export function readWorkspaceRuleContextRowsBefore(workspaceDir, input) {
|
|
|
159
159
|
db.close();
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
+
export function readWorkspaceSessionWriteRowsBefore(workspaceDir, input) {
|
|
163
|
+
const { sessionId, projectDir, hostKind, beforeCreatedAt, excludeToolUseId } = input;
|
|
164
|
+
if (sessionId.trim().length === 0)
|
|
165
|
+
throw new Error('history_session_id_invalid');
|
|
166
|
+
if (!path.isAbsolute(projectDir))
|
|
167
|
+
throw new Error('history_project_dir_invalid');
|
|
168
|
+
if (hostKind.trim().length === 0)
|
|
169
|
+
throw new Error('history_host_kind_invalid');
|
|
170
|
+
if (excludeToolUseId.trim().length === 0)
|
|
171
|
+
throw new Error('history_tool_use_id_invalid');
|
|
172
|
+
if (!Number.isFinite(Date.parse(beforeCreatedAt)))
|
|
173
|
+
throw new Error('history_cutoff_invalid');
|
|
174
|
+
const db = new Database(resolveTrajectoryDbPath(workspaceDir), { readonly: true, fileMustExist: true });
|
|
175
|
+
try {
|
|
176
|
+
db.pragma('busy_timeout = 100');
|
|
177
|
+
return db.transaction(() => {
|
|
178
|
+
const scope = `session_id = ? AND project_dir = ? AND host_kind = ? AND created_at < ?
|
|
179
|
+
AND (tool_use_id IS NULL OR tool_use_id <> ?)`;
|
|
180
|
+
const scopeArgs = [sessionId, projectDir, hostKind, beforeCreatedAt, excludeToolUseId];
|
|
181
|
+
const nameRows = db.prepare(`SELECT DISTINCT tool_name FROM tool_calls WHERE ${scope}`).all(...scopeArgs);
|
|
182
|
+
if (!Array.isArray(nameRows))
|
|
183
|
+
throw new Error('session_write_query_invalid');
|
|
184
|
+
const writeNames = [];
|
|
185
|
+
for (const row of nameRows) {
|
|
186
|
+
if (!record(row) || typeof row.tool_name !== 'string')
|
|
187
|
+
throw new Error('Malformed trajectory tool name row');
|
|
188
|
+
if (input.isWriteTool(row.tool_name))
|
|
189
|
+
writeNames.push(row.tool_name);
|
|
190
|
+
}
|
|
191
|
+
if (writeNames.length === 0)
|
|
192
|
+
return [];
|
|
193
|
+
const placeholders = writeNames.map(() => '?').join(', ');
|
|
194
|
+
const rows = db.prepare(`
|
|
195
|
+
SELECT id, tool_name, outcome, params_json FROM tool_calls
|
|
196
|
+
WHERE ${scope} AND tool_name IN (${placeholders})
|
|
197
|
+
ORDER BY created_at ASC, id ASC
|
|
198
|
+
`).all(...scopeArgs, ...writeNames);
|
|
199
|
+
if (!Array.isArray(rows))
|
|
200
|
+
throw new Error('session_write_query_invalid');
|
|
201
|
+
return rows.map(contextRow).map(({ id, toolName, outcome, paramsJson }) => ({ id, toolName, outcome, paramsJson }));
|
|
202
|
+
})();
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
db.close();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Session activity rows (every tool kind) before a pre-event cutoff, newest
|
|
210
|
+
* first, at most `limit`. Same proven scope as the write-row reader:
|
|
211
|
+
* `project_dir`, mandatory `host_kind`, the cutoff and the current tool_use_id;
|
|
212
|
+
* unscoped or unattributed rows are excluded. Uses `idx_tool_calls_session_id`.
|
|
213
|
+
* Read-only; never creates or migrates trajectory state.
|
|
214
|
+
*/
|
|
215
|
+
export function readWorkspaceSessionActivityRowsBefore(workspaceDir, input) {
|
|
216
|
+
const { sessionId, projectDir, hostKind, beforeCreatedAt, excludeToolUseId, limit } = input;
|
|
217
|
+
if (sessionId.trim().length === 0)
|
|
218
|
+
throw new Error('history_session_id_invalid');
|
|
219
|
+
if (!path.isAbsolute(projectDir))
|
|
220
|
+
throw new Error('history_project_dir_invalid');
|
|
221
|
+
if (hostKind.trim().length === 0)
|
|
222
|
+
throw new Error('history_host_kind_invalid');
|
|
223
|
+
if (excludeToolUseId.trim().length === 0)
|
|
224
|
+
throw new Error('history_tool_use_id_invalid');
|
|
225
|
+
if (!Number.isFinite(Date.parse(beforeCreatedAt)))
|
|
226
|
+
throw new Error('history_cutoff_invalid');
|
|
227
|
+
if (!Number.isSafeInteger(limit) || limit < 1)
|
|
228
|
+
throw new Error('history_limit_invalid');
|
|
229
|
+
const db = new Database(resolveTrajectoryDbPath(workspaceDir), { readonly: true, fileMustExist: true });
|
|
230
|
+
try {
|
|
231
|
+
db.pragma('busy_timeout = 100');
|
|
232
|
+
const fetched = db.prepare(`
|
|
233
|
+
SELECT id, tool_name, outcome, params_json, created_at FROM tool_calls
|
|
234
|
+
WHERE session_id = ? AND project_dir = ? AND host_kind = ? AND created_at < ?
|
|
235
|
+
AND (tool_use_id IS NULL OR tool_use_id <> ?)
|
|
236
|
+
ORDER BY created_at DESC, id DESC
|
|
237
|
+
LIMIT ?
|
|
238
|
+
`).all(sessionId, projectDir, hostKind, beforeCreatedAt, excludeToolUseId, limit + 1);
|
|
239
|
+
if (!Array.isArray(fetched))
|
|
240
|
+
throw new Error('session_activity_query_invalid');
|
|
241
|
+
const rows = fetched.slice(0, limit).map((value) => {
|
|
242
|
+
if (!record(value) || typeof value.id !== 'number' || typeof value.tool_name !== 'string'
|
|
243
|
+
|| typeof value.outcome !== 'string' || typeof value.params_json !== 'string'
|
|
244
|
+
|| typeof value.created_at !== 'string') {
|
|
245
|
+
throw new Error('Malformed trajectory activity row');
|
|
246
|
+
}
|
|
247
|
+
return { id: value.id, toolName: value.tool_name, outcome: value.outcome, paramsJson: value.params_json, createdAt: value.created_at };
|
|
248
|
+
});
|
|
249
|
+
return { rows, truncated: fetched.length > limit };
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
db.close();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
162
255
|
/**
|
|
163
256
|
* List only Codex sessions proven by normalized host evidence and a matching
|
|
164
257
|
* project-scoped trajectory row. The trajectory schema has no host_kind on
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/host-runtime",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Shared host-neutral orchestration for Principles Disciple MVP-Core hook paths.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,6 +23,26 @@
|
|
|
23
23
|
"types": "./dist/behavior-history.d.ts",
|
|
24
24
|
"default": "./dist/behavior-history.js"
|
|
25
25
|
},
|
|
26
|
+
"./rule-policy-active": {
|
|
27
|
+
"types": "./dist/rule-policy-active.d.ts",
|
|
28
|
+
"default": "./dist/rule-policy-active.js"
|
|
29
|
+
},
|
|
30
|
+
"./rule-policy-host-defaults": {
|
|
31
|
+
"types": "./dist/rule-policy-host-defaults.d.ts",
|
|
32
|
+
"default": "./dist/rule-policy-host-defaults.js"
|
|
33
|
+
},
|
|
34
|
+
"./rule-policy-paths-fs": {
|
|
35
|
+
"types": "./dist/rule-policy-paths-fs.d.ts",
|
|
36
|
+
"default": "./dist/rule-policy-paths-fs.js"
|
|
37
|
+
},
|
|
38
|
+
"./fact-assembler": {
|
|
39
|
+
"types": "./dist/fact-assembler.d.ts",
|
|
40
|
+
"default": "./dist/fact-assembler.js"
|
|
41
|
+
},
|
|
42
|
+
"./session-write-targets": {
|
|
43
|
+
"types": "./dist/session-write-targets.d.ts",
|
|
44
|
+
"default": "./dist/session-write-targets.js"
|
|
45
|
+
},
|
|
26
46
|
"./pd-config": {
|
|
27
47
|
"types": "./dist/pd-config.d.ts",
|
|
28
48
|
"default": "./dist/pd-config.js"
|
|
@@ -43,8 +63,8 @@
|
|
|
43
63
|
"lint": "eslint \"src/**/*.ts\""
|
|
44
64
|
},
|
|
45
65
|
"dependencies": {
|
|
46
|
-
"@principles/core": "^11.
|
|
47
|
-
"@principles/install-layout": "^0.12.
|
|
66
|
+
"@principles/core": "^11.1.0",
|
|
67
|
+
"@principles/install-layout": "^0.12.1",
|
|
48
68
|
"better-sqlite3": "^13.0.3",
|
|
49
69
|
"js-yaml": "^5.4.3"
|
|
50
70
|
},
|
|
@@ -61,5 +81,5 @@
|
|
|
61
81
|
"url": "git+https://github.com/csuzngjh/principles.git"
|
|
62
82
|
},
|
|
63
83
|
"license": "Apache-2.0",
|
|
64
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "ad56c831e90bbc63814b65cd33dd0c2496c3ab3f"
|
|
65
85
|
}
|