@principles/host-runtime 3.0.2 → 3.0.3

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.
@@ -1,6 +1,20 @@
1
1
  import { type ActivatedPrinciple, type PromptBudgetResolution, type PromptSelectionPolicy } from '@principles/core/runtime';
2
2
  /** PRI-904 SPEC §10: bounded diagnostic id lists (mirrors the core selector's cap of 16). */
3
3
  export declare const MAX_SHARED_DIAGNOSTIC_IDS = 16;
4
+ /** PRI-1150: bounded per-assembly presence-expectation entries (design v2 §2.1). */
5
+ export declare const MAX_SHARED_PRESENCE_EXPECTATIONS = 64;
6
+ /** PRI-1150: one frozen per-principle expectation for prompt presence forensics. */
7
+ export interface SharedInjectedExpectation {
8
+ activationId: string;
9
+ /**
10
+ * The EXACT escaped `<directive>` slice this assembly embedded (renderer
11
+ * contract — already escaped once; consumers must not re-escape).
12
+ */
13
+ bodyText: string;
14
+ bodyChars: number;
15
+ /** False when the assembly truncated this directive (never yields a full_hit). */
16
+ bodyComplete: boolean;
17
+ }
4
18
  export interface ActivePrinciplePromptResult {
5
19
  additionalContext: string;
6
20
  principleIds: string[];
@@ -42,6 +56,16 @@ export interface ActivePrinciplePromptResult {
42
56
  budgetFallbackDetail?: string;
43
57
  /** Assembly-only status; it does not assert that the host delivered the prompt. */
44
58
  adaptivePacking?: AdaptivePackingReport;
59
+ /**
60
+ * PRI-1150: per-principle frozen expectation set, rendered SAME-SOURCE with
61
+ * `additionalContext` (one render pass, no second read). Revision is not
62
+ * available at this layer and is deliberately absent — consumers record
63
+ * unknown rather than inventing one. Memory-only forensics; PD-internal
64
+ * contract, never sent to the OpenClaw host.
65
+ */
66
+ injectedExpectations?: SharedInjectedExpectation[];
67
+ /** PRI-1150: injected directives dropped by the frozen-set cap (visibility fact). */
68
+ injectedExpectationsOverflow?: number;
45
69
  }
46
70
  export interface AdaptivePackingReport {
47
71
  status: 'target_present' | 'prioritized' | 'unavailable';
@@ -10,6 +10,8 @@ import { readPromptActivationAuthority } from './prompt-activation-authority.js'
10
10
  import { revalidateAdaptivePrinciple } from './adaptive-principle-revalidation.js';
11
11
  /** PRI-904 SPEC §10: bounded diagnostic id lists (mirrors the core selector's cap of 16). */
12
12
  export const MAX_SHARED_DIAGNOSTIC_IDS = 16;
13
+ /** PRI-1150: bounded per-assembly presence-expectation entries (design v2 §2.1). */
14
+ export const MAX_SHARED_PRESENCE_EXPECTATIONS = 64;
13
15
  /**
14
16
  * PR #1844 follow-up: the activation READ half of buildActivePrinciplePromptContext,
15
17
  * exported so the console budget projection can share the exact same input
@@ -248,6 +250,34 @@ export async function buildActivePrinciplePromptContext(input) {
248
250
  seenPrincipleIds.add(principle.principleId);
249
251
  return true;
250
252
  });
253
+ // PRI-1150: freeze per-principle presence expectations SAME-SOURCE with the
254
+ // additionalContext above — one render pass over the already-included
255
+ // principles, no second read. Each entry is the exact escaped `<directive>`
256
+ // slice this assembly embedded; `bodyComplete` is containment against the
257
+ // assembly, so a truncated directive can never yield a full_hit downstream.
258
+ // Bounded at MAX_SHARED_PRESENCE_EXPECTATIONS with an overflow fact.
259
+ const injectedExpectations = [];
260
+ let injectedExpectationsOverflow = 0;
261
+ for (const principle of injectedPrinciples) {
262
+ if (injectedExpectations.length >= MAX_SHARED_PRESENCE_EXPECTATIONS) {
263
+ injectedExpectationsOverflow += 1;
264
+ continue;
265
+ }
266
+ const rendered = renderPrinciplesToDirectives([principle], new Set([principle.principleId]), { escapeFn: escapeXml, selfReportInstruction: selfReportEnabled });
267
+ const start = rendered.indexOf('<directive ');
268
+ const end = rendered.indexOf('</directive>');
269
+ if (start === -1 || end === -1)
270
+ continue;
271
+ const bodyText = rendered.slice(start, end + '</directive>'.length);
272
+ if (!bodyText)
273
+ continue;
274
+ injectedExpectations.push({
275
+ activationId: principle.activationId,
276
+ bodyText,
277
+ bodyChars: bodyText.length,
278
+ bodyComplete: packing.additionalContext.includes(bodyText),
279
+ });
280
+ }
251
281
  return {
252
282
  additionalContext: packing.additionalContext,
253
283
  principleIds: injectedPrinciples.map((principle) => principle.principleId),
@@ -258,6 +288,12 @@ export async function buildActivePrinciplePromptContext(input) {
258
288
  truncated: packing.truncated,
259
289
  selectionPolicy,
260
290
  eligibleCount: eligiblePrinciples.length,
291
+ ...(injectedExpectations.length > 0 || injectedExpectationsOverflow > 0
292
+ ? {
293
+ injectedExpectations,
294
+ ...(injectedExpectationsOverflow > 0 ? { injectedExpectationsOverflow } : {}),
295
+ }
296
+ : {}),
261
297
  ...(rotationStartIndex !== undefined ? { rotationStartIndex } : {}),
262
298
  ...(selectionPolicy === 'fair_rotation_v1' && roundKey !== undefined ? { selectionRoundOrdinal: roundKey } : {}),
263
299
  ...(packing.dropped.length > 0 ? { droppedActivationIds: packing.dropped } : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/host-runtime",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
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": "^5.1.0",
34
+ "@principles/core": "^5.1.1",
35
35
  "@principles/install-layout": "^0.4.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": "c6f51874b108534807d539ca1e04fe079e3b992c"
52
+ "gitHead": "17c7d5c83b78aa03a040807fdfbdcf973371330c"
53
53
  }