@principles/host-runtime 2.2.0 → 2.2.1

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.
@@ -46,7 +46,7 @@ export interface LinkAdaptiveBehaviorEvidenceInput {
46
46
  }
47
47
  export type BehaviorAssociation = 'strong_run' | 'weak' | 'ambiguous' | 'unknown' | 'conflict';
48
48
  export type BehaviorAssociationReason = 'run_identity_proven' | 'run_identity_missing' | 'workspace_identity_unknown' | 'journal_range_incomplete' | 'run_has_multiple_invocations' | 'duplicate_records' | 'target_identity_unproven' | 'terminal_conflicted' | 'config_changed' | 'open_not_visible_in_range' | 'terminal_not_visible_in_range' | 'action_before_open';
49
- export type BehaviorUnknownReason = 'delivery_time_unavailable' | 'task_success_not_observable' | 'model_completion_only' | 'artifact_effect_not_observable' | 'principle_ids_not_comparable' | 'journal_range_incomplete' | 'run_has_multiple_invocations' | 'duplicate_records' | 'terminal_not_visible_in_range' | 'open_not_visible_in_range' | 'config_changed' | 'trajectory_db_unavailable' | 'trajectory_schema_incomplete' | 'trajectory_query_failed' | 'event_log_unavailable' | 'event_log_parse_limit_reached' | 'event_log_files_omitted' | 'event_log_parse_errors' | 'event_log_read_error' | 'action_limit_reached' | 'correction_limit_reached' | 'outcome_limit_reached' | 'weak_candidate_limit_reached' | 'trajectory_row_limit_reached' | 'session_query_limit_reached';
49
+ export type BehaviorUnknownReason = 'delivery_time_unavailable' | 'task_success_not_observable' | 'model_completion_only' | 'artifact_effect_not_observable' | 'principle_ids_not_comparable' | 'journal_range_incomplete' | 'run_has_multiple_invocations' | 'duplicate_records' | 'terminal_not_visible_in_range' | 'open_not_visible_in_range' | 'config_changed' | 'trajectory_db_unavailable' | 'trajectory_schema_incomplete' | 'trajectory_query_failed' | 'event_log_unavailable' | 'event_log_parse_limit_reached' | 'event_log_files_omitted' | 'event_log_parse_errors' | 'event_log_read_error' | 'action_limit_reached' | 'correction_limit_reached' | 'outcome_limit_reached' | 'weak_candidate_limit_reached' | 'trajectory_row_limit_reached' | 'session_query_limit_reached' | 'session_rows_truncated';
50
50
  export interface BehaviorLinkageActionFact {
51
51
  source: 'event_log.tool_call';
52
52
  toolName: string;
@@ -410,6 +410,14 @@ function readTrajectory(input) {
410
410
  });
411
411
  row.weakToolCalls = weakToolCalls.rows;
412
412
  row.weakTruncated = weakToolCalls.truncated;
413
+ // A truncated per-session read means rows may exist past the cap; the
414
+ // targeted run's row can be among them, so the whole read is incomplete.
415
+ if (corrections.truncated || outcomes.truncated || weakToolCalls.truncated) {
416
+ result.truncated = true;
417
+ if (!result.reasons.includes('session_rows_truncated')) {
418
+ result.reasons.push('session_rows_truncated');
419
+ }
420
+ }
413
421
  }
414
422
  catch {
415
423
  row.queryFailed = true;
@@ -661,6 +669,14 @@ function buildInvocation(input) {
661
669
  addUnknown('outcomes', 'outcome_limit_reached');
662
670
  if (weakTruncated)
663
671
  addUnknown('weak_candidates', 'weak_candidate_limit_reached');
672
+ // Session-level truncation is not the per-opportunity cap: filtering by run
673
+ // can hide the missing rows, so it must degrade coverage on its own.
674
+ if (sessionRows?.correctionsTruncated)
675
+ addUnknown('corrections', 'session_rows_truncated');
676
+ if (sessionRows?.outcomesTruncated)
677
+ addUnknown('outcomes', 'session_rows_truncated');
678
+ if (sessionRows?.weakTruncated)
679
+ addUnknown('weak_candidates', 'session_rows_truncated');
664
680
  if (sessionRows?.queryFailed)
665
681
  addUnknown('trajectory', 'trajectory_row_limit_reached');
666
682
  if (trajectory.status === 'unavailable') {
@@ -672,6 +688,8 @@ function buildInvocation(input) {
672
688
  for (const reason of trajectory.reasons) {
673
689
  if (reason === 'session_query_limit_reached')
674
690
  addUnknown('trajectory', 'session_query_limit_reached');
691
+ if (reason === 'session_rows_truncated')
692
+ addUnknown('trajectory', 'session_rows_truncated');
675
693
  if (reason === 'trajectory_row_limit_reached')
676
694
  addUnknown('trajectory', 'trajectory_row_limit_reached');
677
695
  }
@@ -873,6 +891,8 @@ export function linkAdaptiveBehaviorEvidence(input) {
873
891
  incompleteReasons.push('trajectory_row_limit_reached');
874
892
  if (trajectory.reasons.includes('session_query_limit_reached'))
875
893
  incompleteReasons.push('session_query_limit_reached');
894
+ if (trajectory.reasons.includes('session_rows_truncated'))
895
+ incompleteReasons.push('session_rows_truncated');
876
896
  if (trajectory.reasons.includes('trajectory_query_failed'))
877
897
  incompleteReasons.push('trajectory_query_failed');
878
898
  }
@@ -882,6 +902,7 @@ export function linkAdaptiveBehaviorEvidence(input) {
882
902
  'correction_limit_reached',
883
903
  'outcome_limit_reached',
884
904
  'weak_candidate_limit_reached',
905
+ 'session_rows_truncated',
885
906
  ];
886
907
  for (const code of perInvocationCaps) {
887
908
  if (invocations.some((item) => item.unknowns.some((entry) => entry.reasonCode === code))) {
@@ -927,6 +948,9 @@ export function linkAdaptiveBehaviorEvidence(input) {
927
948
  if (incompleteReasons.includes('trajectory_row_limit_reached') || incompleteReasons.includes('session_query_limit_reached')) {
928
949
  nextAction.push('提高 --max-trajectory-rows/--max-session-queries,或缩小时间窗口。');
929
950
  }
951
+ if (incompleteReasons.includes('session_rows_truncated')) {
952
+ nextAction.push(`该会话的分类查询已达到固定的单会话 ${BEHAVIOR_LINKAGE_ROWS_PER_SESSION} 行上限;请缩小 --since/--until 时间窗口后重试(--max-trajectory-rows 不控制该上限)。空结果不代表“不存在”。`);
953
+ }
930
954
  if (eventLog.unattributedToolCalls > 0)
931
955
  nextAction.push('部分工具事件缺少 run/session 身份,已排除在关联之外;不要把它们当作未发生。');
932
956
  if (invocations.some((item) => item.association === 'ambiguous'))
@@ -2,6 +2,35 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { PROMPT_BUDGET_POLICY_VERSION, RUNTIME_V2_PRINCIPLE_BUDGET, isValidContextWindowTokens, promptBudgetCharsForContextWindow, resolvePromptBudget, operatorDeclaredContextWindow, } from '@principles/core/runtime-v2';
4
4
  import { isPromptInjectionTargetHost, } from './prompt-injection-projection.js';
5
+ /**
6
+ * PRI-1104 Stage 0 (expand): accepted budget policy provenance versions.
7
+ *
8
+ * Injection events written to the JSONL event log carry `budgetPolicyVersion`
9
+ * as a durable wire literal. PR-6 renames the CURRENT policy id from
10
+ * `model_aware_v2` to a version-neutral `model_aware`; without this read-side
11
+ * allowance, every historical event would suddenly be classified as
12
+ * "computed under a different policy" and silently skipped (and a revert of
13
+ * PR-6 would strand events written with the new id).
14
+ *
15
+ * These are FROZEN WIRE LITERALS, not a second policy definition: they exist
16
+ * only so events remain readable across the PR-6 rename AND its revert. The
17
+ * PR-6 target id `model_aware` is listed up front (PR #2367 CodeRabbit #2):
18
+ * if PR-6 is reverted after it wrote `model_aware` events, a reader accepting
19
+ * only `model_aware_v2` would silently skip those observations and the console
20
+ * would fall back to a stale budget.
21
+ *
22
+ * Today the writer emits only `model_aware_v2`, so listing the future and
23
+ * historical literals does not change any current read result.
24
+ */
25
+ const ACCEPTED_BUDGET_POLICY_VERSIONS = new Set([
26
+ PROMPT_BUDGET_POLICY_VERSION,
27
+ 'model_aware_v2',
28
+ 'model_aware',
29
+ ]);
30
+ /** Narrow an untrusted event field to an accepted policy provenance id. */
31
+ function isAcceptedBudgetPolicyVersion(value) {
32
+ return typeof value === 'string' && ACCEPTED_BUDGET_POLICY_VERSIONS.has(value);
33
+ }
5
34
  /**
6
35
  * PRI-1017: runtime budget OBSERVATION read model over the EXISTING
7
36
  * injection-event JSONL (`<workspaceDir>/{.pd,.state}/logs/events_<date>.jsonl`,
@@ -162,7 +191,7 @@ function narrowObservation(parsed, workspaceDir, nowMs) {
162
191
  // A budget computed under another policy version is not evidence about the
163
192
  // CURRENT formula. Absent provenance is pre-policy, not "current by
164
193
  // default": both are skipped, never reinterpreted.
165
- if (data.budgetPolicyVersion !== PROMPT_BUDGET_POLICY_VERSION)
194
+ if (!isAcceptedBudgetPolicyVersion(data.budgetPolicyVersion))
166
195
  return null;
167
196
  const rawSource = data.budgetCapacitySource;
168
197
  const rawStatus = data.budgetCapacityStatus;
@@ -335,7 +364,7 @@ export function readRuntimePromptBudgetObservations(input) {
335
364
  if (isRecord(parsed) && parsed.type === 'runtime_v2_prompt_activations_injected' && isRecord(parsed.data)) {
336
365
  const { data } = parsed;
337
366
  const rawPolicyVersion = data.budgetPolicyVersion;
338
- if (rawPolicyVersion !== undefined && rawPolicyVersion !== PROMPT_BUDGET_POLICY_VERSION) {
367
+ if (rawPolicyVersion !== undefined && !isAcceptedBudgetPolicyVersion(rawPolicyVersion)) {
339
368
  // A budget computed under a DIFFERENT policy version is not
340
369
  // evidence about the current formula — counted, not reinterpreted.
341
370
  foreignPolicyEventsSkipped.count += 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/host-runtime",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "Shared host-neutral orchestration for Principles Disciple MVP-Core hook paths.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -49,5 +49,5 @@
49
49
  "url": "git+https://github.com/csuzngjh/principles.git"
50
50
  },
51
51
  "license": "Apache-2.0",
52
- "gitHead": "53279ca6dd35e2c02321f9e3e0c317af6da7c2a3"
52
+ "gitHead": "e2f66fab6d7e1830c6552c73ad9b3292996c254f"
53
53
  }