@principles/workbuddy-adapter 0.6.4 → 0.6.6

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/pd-hook.js CHANGED
@@ -71,15 +71,31 @@ function redactStringFields(data) {
71
71
  * core writer, so the WorkBuddy host path carries the host's natural ids
72
72
  * (generation_id → runId/turnId, call_id → toolCallId).
73
73
  */
74
- function workbuddyEventEmitter(stateDir, evidence) {
74
+ function workbuddyEventEmitter(stateDir, evidence, readAdaptiveFact) {
75
75
  return {
76
76
  recordRuntimeActivationsInjected(data) {
77
+ // PRI-1127: attach the Adaptive turn fact to the SAME injection event the
78
+ // Console already reads. Flag-off / Native turns produce NO fact at all,
79
+ // so `adaptive` stays absent (never a fabricated "no append" record).
80
+ // `appendedActivationId` is the FINAL ASSEMBLY basis: a selected id that
81
+ // did not reach activationIds (budget, dropped, failed packing) is not
82
+ // reported as appended.
83
+ const fact = readAdaptiveFact?.() ?? null;
84
+ const adaptive = fact === null
85
+ ? undefined
86
+ : {
87
+ resultCode: `${fact.status}:${fact.reason}`.slice(0, 240),
88
+ scored: fact.sends > 0,
89
+ ...(fact.targetActivationId !== null && data.activationIds.includes(fact.targetActivationId)
90
+ ? { appendedActivationId: fact.targetActivationId }
91
+ : {}),
92
+ };
77
93
  appendEventLogLine(stateDir, {
78
94
  ts: new Date().toISOString(),
79
95
  type: 'runtime_v2_prompt_activations_injected',
80
96
  category: 'injected',
81
97
  sessionId: data.sessionId,
82
- data,
98
+ data: adaptive === undefined ? data : { ...data, adaptive },
83
99
  });
84
100
  // Delivery evidence AFTER the durable source line exists; degrades to a
85
101
  // bounded diagnostic and never affects the hook result.
@@ -434,6 +450,10 @@ export async function processWorkbuddyHookInvocation(rawStdin, channelEventName,
434
450
  // defaults) and must be visible on stderr (rc-9).
435
451
  ? toolSemanticsResolution.warnings.map((warning) => diagnostic('degraded', warning, 're-run this host so it refreshes its persisted tool declaration'))
436
452
  : [diagnostic('degraded', toolSemanticsResolution.reason, toolSemanticsResolution.nextAction)];
453
+ // PRI-1127: capture the real selection outcome for THIS turn so the same
454
+ // injection event can carry the Adaptive fact the Console reads. Absent
455
+ // (flag off / Native) stays absent — no fabricated record.
456
+ let adaptiveTurnFact = null;
437
457
  const adaptive = event.kind === 'before_prompt_build' && flags['host.workbuddy.adaptive_activation']?.enabled === true
438
458
  ? createAdaptivePriorityProviderForConfig(config.effective.config, resolution.workspaceDir, {
439
459
  flag: 'host.workbuddy.adaptive_activation',
@@ -442,12 +462,26 @@ export async function processWorkbuddyHookInvocation(rawStdin, channelEventName,
442
462
  // work well inside that budget, including this process's startup.
443
463
  outerDeadlineAt: Date.now() + Math.max(0, 5000 - Math.round(process.uptime() * 1000)),
444
464
  onDiagnostic: (line) => {
465
+ adaptiveTurnFact = {
466
+ status: line.status,
467
+ reason: line.reason,
468
+ sends: line.sends,
469
+ targetActivationId: line.targetActivationId,
470
+ };
445
471
  if (line.status !== 'selected')
446
472
  evidenceDiagnostics.push(diagnostic(line.status === 'unavailable' ? 'degraded' : 'skipped', `adaptive_selection_${line.status}:${line.reason}`, 'Check Adaptive configuration or use Native assembly.'));
447
473
  },
448
474
  })
449
475
  : undefined;
450
476
  if (adaptive && !adaptive.ok) {
477
+ // `sends: 0` is a fact, not an assumption: no request can leave when the
478
+ // effective configuration cannot build a model (Codex precedent).
479
+ adaptiveTurnFact = {
480
+ status: 'needs_setup',
481
+ reason: adaptive.reason,
482
+ sends: 0,
483
+ targetActivationId: null,
484
+ };
451
485
  evidenceDiagnostics.push(diagnostic('degraded', `adaptive_activation_${adaptive.readiness}:${adaptive.reason}`, adaptive.nextAction));
452
486
  }
453
487
  const result = await createProductionHostRuntime({
@@ -455,7 +489,7 @@ export async function processWorkbuddyHookInvocation(rawStdin, channelEventName,
455
489
  ...(projectDir !== undefined ? { projectDir } : {}),
456
490
  hostKind: 'workbuddy',
457
491
  toolSemantics,
458
- events: workbuddyEventEmitter(stateDir, evidenceContext),
492
+ events: workbuddyEventEmitter(stateDir, evidenceContext, () => adaptiveTurnFact),
459
493
  // SPEC-RULECODE-HOST-PROMOTION-001 C: the V2 rule context provider over
460
494
  // WorkBuddy's own observable trajectory (same-session tool_calls rows
461
495
  // the shared afterToolCall path records). No designGate fact is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/workbuddy-adapter",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "WorkBuddy host adapter for Principles Disciple — implements the HostAdapter interface for WorkBuddy's Git Bash command-hook model (ADR-0020 third host, SPEC workbuddy-host-adapter v0.3.0).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -42,8 +42,8 @@
42
42
  "lint": "eslint \"src/**/*.ts\""
43
43
  },
44
44
  "dependencies": {
45
- "@principles/core": "^7.6.2",
46
- "@principles/host-runtime": "^4.1.2",
45
+ "@principles/core": "^7.9.0",
46
+ "@principles/host-runtime": "^4.3.0",
47
47
  "@principles/install-layout": "^0.8.1"
48
48
  },
49
49
  "devDependencies": {
@@ -61,5 +61,5 @@
61
61
  "publishConfig": {
62
62
  "access": "public"
63
63
  },
64
- "gitHead": "80b43dd1b98d261b580215cff8b815594606178c"
64
+ "gitHead": "97cac4b30eb64ad4b369d2f86f5c57a8053897eb"
65
65
  }
@@ -56,7 +56,7 @@ Owner 说过 —— 本次对话、Owner 文档或已批准的决定。`anchorRe
56
56
 
57
57
  ### `established_principle`(既有原则)
58
58
 
59
- `anchorRef` 必须是 `<principleId>@<version>`(例如 `P-42@1`)。两者都从 `pd principle list` 取,禁止猜测或推断版本号。
59
+ `anchorRef` 必须是 `<principleId>@<version>`(例如 `P-42@1`)。两者都从工作区账本 `.state/principle_training_state.json` 的 `_tree.principles` 读取,禁止猜测或推断版本号。
60
60
 
61
61
  服务端会校验存在性、版本与状态:
62
62