@principles/host-runtime 3.1.2 → 3.2.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.
@@ -18,9 +18,14 @@ function isRecord(value) {
18
18
  function patchTargets(params, projectDir) {
19
19
  if (params === null)
20
20
  return undefined;
21
+ // Native Codex sends the patch body under `tool_input.command`
22
+ // (`{"command":"*** Begin Patch..."}`); older/embedded callers use
23
+ // `patch` or `input`. All three carry the same `*** <op> File:` headers.
21
24
  const patch = typeof params.patch === 'string'
22
25
  ? params.patch
23
- : typeof params.input === 'string' ? params.input : null;
26
+ : typeof params.input === 'string'
27
+ ? params.input
28
+ : typeof params.command === 'string' ? params.command : null;
24
29
  if (patch === null || Buffer.byteLength(patch, 'utf8') > MAX_PATCH_BYTES)
25
30
  return undefined;
26
31
  const targets = [];
@@ -194,6 +194,39 @@ export function createProductionRuleHostGate(options = {}) {
194
194
  metadata: { evaluatedLiveRules: 0 },
195
195
  };
196
196
  }
197
+ // PRI-1044 step 3-1: an ACTIVE activation whose pi_artifacts row is gone
198
+ // is invisible to the candidate query below (INNER JOIN), so the gate
199
+ // reported `no_rules_armed` and enforced nothing with no trace at all
200
+ // (observed: 8+ hours of silent non-enforcement). Detect the dangling
201
+ // reference explicitly: the fail-open availability posture is unchanged,
202
+ // but the gap becomes Owner-visible (rc-9) through a structured warning
203
+ // that names the activation AND the durable out-of-workspace marker, so
204
+ // it survives the host's per-call log buffer.
205
+ const danglingArtifacts = connection.getDb().prepare(`
206
+ SELECT a.activation_id, a.artifact_id
207
+ FROM activations a
208
+ WHERE a.channel = 'code_tool_hook' AND a.deactivated_at IS NULL
209
+ AND NOT EXISTS (SELECT 1 FROM pi_artifacts p WHERE p.artifact_id = a.artifact_id)
210
+ ORDER BY a.activated_at ASC
211
+ `).all();
212
+ if (!Array.isArray(danglingArtifacts)) {
213
+ addWarning(warnings, 'activation_artifact_reference_query_invalid', 'inspect state.db schema and integrity');
214
+ }
215
+ else {
216
+ const missingArtifacts = [];
217
+ for (const dangling of danglingArtifacts) {
218
+ if (!isRecord(dangling) || typeof dangling.activation_id !== 'string') {
219
+ addWarning(warnings, 'activation_artifact_reference_invalid', 'inspect state.db activation rows and integrity');
220
+ continue;
221
+ }
222
+ const artifactLabel = typeof dangling.artifact_id === 'string' ? dangling.artifact_id : 'unknown';
223
+ missingArtifacts.push(`${dangling.activation_id}->${artifactLabel}`);
224
+ addWarning(warnings, `activation_artifact_missing: activation=${dangling.activation_id} artifact=${artifactLabel}`, 'restore the referenced pi_artifacts row or deactivate the stale activation; the rule did not run');
225
+ }
226
+ if (missingArtifacts.length > 0) {
227
+ recordDegradedEnforcement(event.context.workspaceDir, `activation_artifact_missing: ${missingArtifacts.join(', ')}`.slice(0, 300));
228
+ }
229
+ }
197
230
  const rows = connection.getDb().prepare(`
198
231
  SELECT a.activation_id, a.artifact_id, a.target_ref, a.action,
199
232
  c.enforcement, c.isolation_decision_id,
@@ -39,6 +39,10 @@ import { StoreEventEmitter } from '@principles/core/runtime';
39
39
  * Rule 4 降级放行 CREATE 时 Owner 必须能事后取证「复用保护为何没拦」。
40
40
  * 注意 reuse_evaluation_recommended 刻意不入列:recommended 已由
41
41
  * candidateOutcomes / reuseEvidence 持久承载,落盘会形成第二决策日志)
42
+ * - diag_router_trusted_context_unavailable / replay_review_source_invalid
43
+ * (PRI-1146 P1-01:低频 skip/degradation 取证 — 前者记录 ledger 不可证明
44
+ * 时 canonical association 为何保持 unresolved,后者是 replay review skip
45
+ * 的唯一持久记录;见 Set 内注释)
42
46
  *
43
47
  * 落点 `<workspaceDir>/.pd/telemetry/critical-events.jsonl`(JSONL,一行一
44
48
  * 事件,含完整 TelemetryEvent)。同步 append:事件量小(allowlist 限流),
@@ -59,6 +63,15 @@ const CRITICAL_EVENT_ALLOWLIST = new Set([
59
63
  'artificer_blocked_on_owner_evidence',
60
64
  'reuse_gate_triggered',
61
65
  'reuse_evaluation_unavailable',
66
+ // PRI-1146 (P1-01 / rc-9): typed-unavailable diagnosis runs and replay-review
67
+ // skips must be reconstructable after the fact. Both are low-frequency skip/
68
+ // degradation evidence: the router event records WHY canonical associations
69
+ // stayed unresolved when the ledger was unprovable (the receipt is the
70
+ // primary proof; this line survives even if the artifact write later fails),
71
+ // and the replay event records WHY a pending candidate was not reuse-reviewed
72
+ // (its only durable record — the candidate row itself carries no skip reason).
73
+ 'diag_router_trusted_context_unavailable',
74
+ 'replay_review_source_invalid',
62
75
  ]);
63
76
  export class WorkspaceTelemetryEmitter extends StoreEventEmitter {
64
77
  upstream;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/host-runtime",
3
- "version": "3.1.2",
3
+ "version": "3.2.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",
@@ -31,7 +31,7 @@
31
31
  "lint": "eslint \"src/**/*.ts\""
32
32
  },
33
33
  "dependencies": {
34
- "@principles/core": "^6.0.1",
34
+ "@principles/core": "^7.0.0",
35
35
  "@principles/install-layout": "^0.5.0",
36
36
  "better-sqlite3": "^13.0.3",
37
37
  "js-yaml": "^5.4.3"
@@ -49,5 +49,5 @@
49
49
  "url": "git+https://github.com/csuzngjh/principles.git"
50
50
  },
51
51
  "license": "Apache-2.0",
52
- "gitHead": "4000adc495a7c146f4d9282c114d0d936d8e196a"
52
+ "gitHead": "7d898b78cdcc789b8102129cfaeb5318d70d9153"
53
53
  }