@principles/host-runtime 4.9.0 → 4.9.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/dist/behavior-example-pack-assembler.js +3 -4
- package/dist/behavior-history.d.ts +4 -1
- package/dist/behavior-history.js +19 -3
- package/dist/codex-disclosure.d.ts +1 -1
- package/dist/codex-disclosure.js +1 -1
- package/dist/codex-rule-context-provider.js +6 -12
- package/dist/production-rulehost-gate.d.ts +3 -0
- package/dist/production-rulehost-gate.js +1 -0
- package/dist/workbuddy-rule-context-provider.js +3 -12
- package/dist/workspace-behavior-evidence.js +9 -2
- package/package.json +4 -4
|
@@ -17,13 +17,12 @@
|
|
|
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`.
|
|
24
24
|
*/
|
|
25
25
|
import { buildRuleHostAction } from '@principles/core/runtime/internalization/rule-host-input-builder';
|
|
26
|
-
import { computeBehaviorFacts } from '@principles/core/runtime/internalization/rule-context-v2';
|
|
27
26
|
import { validateBehaviorExamplePack } from '@principles/core/runtime/internalization/behavior-example-pack';
|
|
28
27
|
// Factory lives in evidence-readiness.ts (the classification authority); it is
|
|
29
28
|
// consumed through its registered LEAF subpath. A VALUE import of the
|
|
@@ -31,7 +30,7 @@ import { validateBehaviorExamplePack } from '@principles/core/runtime/internaliz
|
|
|
31
30
|
// fails the satellite-purity guard (OPT-002, scripts/build/check-satellite-purity.mjs) —
|
|
32
31
|
// the leaf is on core's exports allowlist for exactly this consumer.
|
|
33
32
|
import { createOwnerEvidenceScopeError } from '@principles/core/runtime/internalization/evidence-readiness';
|
|
34
|
-
import { assembleBehaviorHistory } from './behavior-history.js';
|
|
33
|
+
import { assembleBehaviorHistory, computeConservativeBehaviorFacts } from './behavior-history.js';
|
|
35
34
|
// ── internal constants ─────────────────────────────────────────────────────
|
|
36
35
|
const MAX_POSITIVES = 3;
|
|
37
36
|
const MAX_EVIDENCE_REFS = 5;
|
|
@@ -237,7 +236,7 @@ export class BehaviorExamplePackAssembler {
|
|
|
237
236
|
const historyResult = readTrajectoryStore(`context history read for session=${row.sessionId} before id=${row.id}`, () => this.db.getRuleHostContextRowsBefore(row.sessionId, row.id, HISTORY_LIMIT));
|
|
238
237
|
const history = assembleBehaviorHistory(historyResult.rows, historyResult.truncated, { projectDir, toolSemantics: this.toolSemantics });
|
|
239
238
|
const action = buildRuleHostAction(row.toolName, redaction.redacted, projectDir, { canonicalKind: this.toolSemantics.resolve(row.toolName) });
|
|
240
|
-
const ruleContext = { version: 2, history, facts:
|
|
239
|
+
const ruleContext = { version: 2, history, facts: computeConservativeBehaviorFacts(history, { path: action.normalizedPath || null, evidence: action.targetEvidence }, null) };
|
|
241
240
|
return { ...base, params: redaction.redacted, ruleContext };
|
|
242
241
|
}
|
|
243
242
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type { RuleHistoryWindow, ToolSemanticRegistry } from '@principles/core/runtime';
|
|
1
|
+
import type { RuleBehaviorFacts, RuleHistoryWindow, ToolSemanticRegistry } from '@principles/core/runtime';
|
|
2
|
+
import type { RuleBehaviorFactsTarget } from '@principles/core/runtime/internalization/rule-context-v2';
|
|
2
3
|
import type { RuleHostContextRow } from '@principles/core/trajectory-types';
|
|
4
|
+
export declare function computeConservativeBehaviorFacts(history: RuleHistoryWindow, target: string | null | RuleBehaviorFactsTarget, sameActionBlockCount: number | null): RuleBehaviorFacts;
|
|
3
5
|
export declare function assembleBehaviorHistory(rows: readonly RuleHostContextRow[], truncated: boolean, options: {
|
|
4
6
|
projectDir: string;
|
|
5
7
|
toolSemantics: ToolSemanticRegistry;
|
|
8
|
+
currentToolUseId?: string;
|
|
6
9
|
}): RuleHistoryWindow;
|
package/dist/behavior-history.js
CHANGED
|
@@ -1,5 +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 { 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
|
+
}
|
|
3
10
|
const VALID_OUTCOMES = new Set(['success', 'failure', 'blocked']);
|
|
4
11
|
function isPlainObject(value) {
|
|
5
12
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
@@ -16,9 +23,11 @@ function unavailable(reason) {
|
|
|
16
23
|
};
|
|
17
24
|
}
|
|
18
25
|
export function assembleBehaviorHistory(rows, truncated, options) {
|
|
19
|
-
const { projectDir, toolSemantics } = options;
|
|
26
|
+
const { projectDir, toolSemantics, currentToolUseId } = options;
|
|
20
27
|
const records = [];
|
|
21
28
|
for (const row of rows) {
|
|
29
|
+
if (typeof currentToolUseId === 'string' && currentToolUseId.length > 0 && row.toolUseId === currentToolUseId)
|
|
30
|
+
continue;
|
|
22
31
|
// ── validate tool_name (ERR-001: unknown) ──
|
|
23
32
|
const { toolName } = row;
|
|
24
33
|
if (typeof toolName !== 'string' || toolName.length === 0) {
|
|
@@ -53,14 +62,21 @@ export function assembleBehaviorHistory(rows, truncated, options) {
|
|
|
53
62
|
const canonicalKind = toolSemantics.resolve(toolName);
|
|
54
63
|
// Use the shared action builder so history and live/replay preserve the
|
|
55
64
|
// same distinction between extracted paths and opaque shell commands.
|
|
56
|
-
const
|
|
65
|
+
const action = buildRuleHostAction(toolName, parsedParams, projectDir, { canonicalKind });
|
|
66
|
+
const callIdentityRelation = typeof currentToolUseId === 'string' && currentToolUseId.length > 0
|
|
67
|
+
&& typeof row.toolUseId === 'string' && row.toolUseId.length > 0
|
|
68
|
+
&& row.toolUseId !== currentToolUseId
|
|
69
|
+
? 'distinct_from_current'
|
|
70
|
+
: 'unproven';
|
|
57
71
|
records.push({
|
|
58
72
|
sequenceId: row.id,
|
|
59
73
|
toolName,
|
|
60
74
|
canonicalKind,
|
|
61
|
-
normalizedPath: normalizedPath === '' ? null : normalizedPath,
|
|
75
|
+
normalizedPath: action.normalizedPath === '' ? null : action.normalizedPath,
|
|
62
76
|
paramsSummary: parsedParams,
|
|
63
77
|
outcome,
|
|
78
|
+
callIdentityRelation,
|
|
79
|
+
targetEvidence: action.targetEvidence,
|
|
64
80
|
});
|
|
65
81
|
}
|
|
66
82
|
return {
|
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { computeBehaviorFacts, } from '@principles/core/runtime';
|
|
3
|
-
import { assembleBehaviorHistory } from './behavior-history.js';
|
|
3
|
+
import { assembleBehaviorHistory, computeConservativeBehaviorFacts } from './behavior-history.js';
|
|
4
4
|
import { readWorkspaceRuleContextRowsBefore } from './workspace-behavior-evidence.js';
|
|
5
5
|
import { readLatestCodexDesignGateDeclaration, resolveCodexDesignGateFact } from './design-gate-facts.js';
|
|
6
6
|
const HISTORY_LIMIT = 100;
|
|
@@ -134,6 +134,10 @@ export function createCodexRuleContextProvider(options) {
|
|
|
134
134
|
return unavailable('trajectory_project_scope_incomplete', designGate);
|
|
135
135
|
if (historyRows.rows.length === 0)
|
|
136
136
|
return unavailable('no_prior_session_history', designGate);
|
|
137
|
+
// Deliberately do not pass currentToolUseId here. Unlike WorkBuddy,
|
|
138
|
+
// this reader does not yet prove strict same-host attribution for every
|
|
139
|
+
// historical row, so Codex call identity conservatively remains
|
|
140
|
+
// `unproven` rather than borrowing WorkBuddy's stronger capability.
|
|
137
141
|
const history = assembleBehaviorHistory(historyRows.rows, historyRows.truncated, {
|
|
138
142
|
projectDir,
|
|
139
143
|
toolSemantics: options.toolSemantics,
|
|
@@ -142,17 +146,7 @@ export function createCodexRuleContextProvider(options) {
|
|
|
142
146
|
// absent from this host's semantic registry. Either may read or mutate
|
|
143
147
|
// files, so neither target-read absence nor exact action counts can be
|
|
144
148
|
// asserted from this partial semantic view.
|
|
145
|
-
const
|
|
146
|
-
const computedFacts = computeBehaviorFacts(history, factsIncomplete ? null : request.targetPath, null);
|
|
147
|
-
const facts = factsIncomplete
|
|
148
|
-
? {
|
|
149
|
-
priorReadOfTarget: 'unknown',
|
|
150
|
-
readCount: null,
|
|
151
|
-
writeCount: null,
|
|
152
|
-
uniqueWritePathCount: null,
|
|
153
|
-
sameActionBlockCount: null,
|
|
154
|
-
}
|
|
155
|
-
: computedFacts;
|
|
149
|
+
const facts = computeConservativeBehaviorFacts(history, { path: request.targetPath, evidence: request.targetEvidence }, null);
|
|
156
150
|
return {
|
|
157
151
|
version: 2,
|
|
158
152
|
history,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type RuleHostResult, type ToolSemanticRegistry, type GovernanceHostKind } from '@principles/core/runtime';
|
|
2
|
+
import type { RuleTargetEvidence } from '@principles/core/runtime/internalization/rule-context-v2';
|
|
2
3
|
import type { HostEvent, HostEventResult } from '@principles/core/host';
|
|
3
4
|
import { type RuleImplementationRuntime } from './rule-implementation-runtime.js';
|
|
4
5
|
/**
|
|
@@ -27,6 +28,8 @@ export interface ProductionRuleContextRequest {
|
|
|
27
28
|
targetPath: string;
|
|
28
29
|
toolName: string;
|
|
29
30
|
rawPayload: unknown;
|
|
31
|
+
/** Provenance of targetPath when produced by the shared action builder; absent only for legacy/test providers. */
|
|
32
|
+
targetEvidence?: RuleTargetEvidence;
|
|
30
33
|
}
|
|
31
34
|
export type RuleContextProvider = (request: ProductionRuleContextRequest) => unknown | Promise<unknown>;
|
|
32
35
|
export interface RuleInputEnrichment {
|
|
@@ -224,6 +224,7 @@ export function createProductionRuleHostGate(options = {}) {
|
|
|
224
224
|
const request = {
|
|
225
225
|
workspaceDir: event.context.workspaceDir, sessionId: event.context.sessionId,
|
|
226
226
|
targetPath: action.normalizedPath, toolName: input.toolName, rawPayload: event.rawPayload,
|
|
227
|
+
targetEvidence: action.targetEvidence,
|
|
227
228
|
};
|
|
228
229
|
if (options.ruleInputEnrichmentProvider) {
|
|
229
230
|
try {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { computeBehaviorFacts, } from '@principles/core/runtime';
|
|
3
|
-
import { assembleBehaviorHistory } from './behavior-history.js';
|
|
3
|
+
import { assembleBehaviorHistory, computeConservativeBehaviorFacts } from './behavior-history.js';
|
|
4
4
|
import { readWorkspaceRuleContextRowsBefore } from './workspace-behavior-evidence.js';
|
|
5
5
|
const HISTORY_LIMIT = 100;
|
|
6
6
|
const MAX_REASON_LENGTH = 240;
|
|
@@ -96,23 +96,14 @@ export function createWorkbuddyRuleContextProvider(options) {
|
|
|
96
96
|
const history = assembleBehaviorHistory(historyRows.rows, historyRows.truncated, {
|
|
97
97
|
projectDir,
|
|
98
98
|
toolSemantics: options.toolSemantics,
|
|
99
|
+
currentToolUseId: options.currentToolCallId,
|
|
99
100
|
});
|
|
100
101
|
// WorkBuddy exposes its shell as the Bash tool, and MCP-style tools may
|
|
101
102
|
// resolve to 'other' absent from this host's semantic registry. Either
|
|
102
103
|
// may read or mutate files, so target-read absence and exact action
|
|
103
104
|
// counts cannot be asserted from this partial semantic view (same
|
|
104
105
|
// conservative rule as the Codex provider).
|
|
105
|
-
const
|
|
106
|
-
const computedFacts = computeBehaviorFacts(history, factsIncomplete ? null : request.targetPath, null);
|
|
107
|
-
const facts = factsIncomplete
|
|
108
|
-
? {
|
|
109
|
-
priorReadOfTarget: 'unknown',
|
|
110
|
-
readCount: null,
|
|
111
|
-
writeCount: null,
|
|
112
|
-
uniqueWritePathCount: null,
|
|
113
|
-
sameActionBlockCount: null,
|
|
114
|
-
}
|
|
115
|
-
: computedFacts;
|
|
106
|
+
const facts = computeConservativeBehaviorFacts(history, { path: request.targetPath, evidence: request.targetEvidence }, null);
|
|
116
107
|
return {
|
|
117
108
|
version: 2,
|
|
118
109
|
history,
|
|
@@ -21,7 +21,14 @@ function contextRow(value) {
|
|
|
21
21
|
if (Object.keys(params).some((key) => key === '__proto__' || key === 'constructor' || key === 'prototype')) {
|
|
22
22
|
throw new Error('Unsafe keys in persisted trajectory params');
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
const toolUseId = typeof value.tool_use_id === 'string' && value.tool_use_id.length > 0 ? value.tool_use_id : undefined;
|
|
25
|
+
return {
|
|
26
|
+
id: value.id,
|
|
27
|
+
toolName: value.tool_name,
|
|
28
|
+
outcome: value.outcome,
|
|
29
|
+
paramsJson: value.params_json,
|
|
30
|
+
...(toolUseId !== undefined ? { toolUseId } : {}),
|
|
31
|
+
};
|
|
25
32
|
}
|
|
26
33
|
function source(db) {
|
|
27
34
|
return {
|
|
@@ -102,7 +109,7 @@ export function readWorkspaceRuleContextRowsBefore(workspaceDir, input) {
|
|
|
102
109
|
return db.transaction(() => {
|
|
103
110
|
// Attribution-aware read: fetch one extra slot beyond the limit so the
|
|
104
111
|
// partition counts stay truthful about a truncated window's tail.
|
|
105
|
-
const selectColumns = includeHostKind ? 'id, tool_name, outcome, params_json, host_kind' : 'id, tool_name, outcome, params_json';
|
|
112
|
+
const selectColumns = includeHostKind ? 'id, tool_name, outcome, params_json, host_kind, tool_use_id' : 'id, tool_name, outcome, params_json, tool_use_id';
|
|
106
113
|
const fetched = db.prepare(`
|
|
107
114
|
SELECT ${selectColumns}
|
|
108
115
|
FROM tool_calls
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/host-runtime",
|
|
3
|
-
"version": "4.9.
|
|
3
|
+
"version": "4.9.2",
|
|
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.2",
|
|
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": "6fd9c6576df0b5a891a5b6a25e7d8041dbf826b4"
|
|
61
61
|
}
|