@principles/workbuddy-adapter 0.10.2 → 0.11.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.
package/dist/pd-hook.js CHANGED
@@ -36,7 +36,7 @@ import path from 'node:path';
36
36
  import process from 'node:process';
37
37
  import { pathToFileURL, fileURLToPath } from 'node:url';
38
38
  import { appendEventLogLine, redactTelemetryString, isRuleHostEvaluatedEventData } from '@principles/core/runtime';
39
- import { createAdaptivePriorityProviderForConfig, createProductionHostRuntime, createWorkbuddyRuleContextProvider, environmentFactDigestOrNull, loadPdConfigForPlugin, parseOwnerStatementPrefix, assessWorkbuddyCorrectionCandidate, resolveSharedCorrectionKeywordStoreForDetection, admitTrustedWorkbuddyLiveCorrection, ensureGovernanceDiagnosticianTask, resolveHostToolSemanticsForHook } from '@principles/host-runtime';
39
+ import { createAdaptivePriorityProviderForConfig, createProductionHostRuntime, observeForwardTurnClose, createWorkbuddyRuleContextProvider, environmentFactDigestOrNull, loadPdConfigForPlugin, parseOwnerStatementPrefix, assessWorkbuddyCorrectionCandidate, resolveSharedCorrectionKeywordStoreForDetection, admitTrustedWorkbuddyLiveCorrection, ensureGovernanceDiagnosticianTask, resolveHostToolSemanticsForHook, recordIdleAuditTurnCompleted } from '@principles/host-runtime';
40
40
  import { computeFeatureFlagsFromConfig } from '@principles/core/runtime';
41
41
  import { WorkBuddyHooksHostAdapter } from './host-adapter.js';
42
42
  import { WORKBUDDY_TOOL_SEMANTIC_MAPPINGS, WORKBUDDY_TOOL_SEMANTICS } from './tool-semantics.js';
@@ -302,7 +302,7 @@ export async function processWorkbuddyHookInvocation(rawStdin, channelEventName,
302
302
  const autoDiagnostics = [];
303
303
  if (channelEventName === 'UserPromptSubmit' &&
304
304
  event.kind === 'before_prompt_build' &&
305
- flags.workbuddy_live_keyword_pain?.enabled === true) {
305
+ flags.workbuddy_live_keyword_pain?.enabled !== false) {
306
306
  try {
307
307
  const raw = parsed;
308
308
  const prompt = event.context.promptContent;
@@ -406,14 +406,27 @@ export async function processWorkbuddyHookInvocation(rawStdin, channelEventName,
406
406
  return neutralWithDiagnostics([]);
407
407
  }
408
408
  if (event.kind === 'turn_complete') {
409
+ const closeDiagnostics = observeForwardTurnClose({
410
+ workspaceDir: resolution.workspaceDir,
411
+ hostKind: 'workbuddy',
412
+ sessionId: event.context.sessionId,
413
+ ...(event.context.turnId !== undefined ? { turnId: event.context.turnId } : {}),
414
+ }).map((warning) => diagnostic('degraded', warning, 'Inspect trajectory.db forward evidence; Stop ingestion remains non-blocking.'));
409
415
  // PRI-1171 P2 ticket ⑤: the authenticated Stop hook is the ingestion
410
416
  // trigger. Neutral output is MANDATORY — WorkBuddy injects any stdout
411
417
  // into model-visible context (P04). Flag-off stays completely silent so
412
418
  // the pre-wiring behavior is unchanged; the consent gate and the
413
419
  // transcript port are both inside ingestWorkbuddyConversation.
414
420
  if (flags.workbuddy_conversation_ingestion?.enabled !== true) {
415
- return neutralWithDiagnostics([]);
421
+ return neutralWithDiagnostics(closeDiagnostics);
416
422
  }
423
+ recordIdleAuditTurnCompleted({
424
+ workspaceDir: resolution.workspaceDir,
425
+ hostKind: 'workbuddy',
426
+ sessionId: event.context.sessionId,
427
+ turnEndSource: 'stop_hook',
428
+ hasActiveRun: false,
429
+ });
417
430
  const ingestion = ingestWorkbuddyConversation({
418
431
  workspaceDir: resolution.workspaceDir,
419
432
  rawPayload: event.rawPayload,
@@ -431,7 +444,7 @@ export async function processWorkbuddyHookInvocation(rawStdin, channelEventName,
431
444
  return neutralWithDiagnostics(ingestion.warnings.slice(0, 2).map((warning) => diagnostic(warning.startsWith('wb_skipped') ? 'skipped' : 'degraded', warning, 'Inspect the WorkBuddy transcript and the governance trajectory checkpoint; ingestion warnings are bounded and non-blocking.')));
432
445
  }
433
446
  if (ingestion.status === 'skipped')
434
- return neutralWithDiagnostics([]);
447
+ return neutralWithDiagnostics(closeDiagnostics);
435
448
  return neutralWithDiagnostics([diagnostic('degraded', ingestion.reason, ingestion.nextAction)]);
436
449
  }
437
450
  const evidenceDiagnostics = [];
@@ -1,5 +1,5 @@
1
1
  import { type TargetEvidenceReconcileReport } from '@principles/core/runtime';
2
- import { type InternalizationConsumerCycleOutcome, type ConsumerCycleLogger, type ReconcileGovernanceContinuationResult, type SignalLlmClassifier, type Stage2CorrectionCycleReport } from '@principles/host-runtime';
2
+ import { type InternalizationConsumerCycleOutcome, type ConsumerCycleLogger, type ReconcileGovernanceContinuationResult, type SignalLlmClassifier, type Stage2CorrectionCycleReport, type RunIdleTurnAuditCycleReport, type IdleTurnAuditor } from '@principles/host-runtime';
3
3
  import { type WorkbuddyCatchUpResult } from '../ingestion/catch-up.js';
4
4
  export type WorkbuddyWorkerMode = 'ready' | 'manual_action_required' | 'paused' | 'degraded';
5
5
  export interface WorkbuddyWorkerCycleStepReport {
@@ -19,6 +19,7 @@ export interface WorkbuddyWorkerCycleStepReport {
19
19
  readonly targetEvidenceReconcile?: TargetEvidenceReconcileReport;
20
20
  /** Phase B Stage-2 review step (always last, ≤2 candidates / ≤60s aggregate). */
21
21
  readonly stage2?: Stage2CorrectionCycleReport;
22
+ readonly idleAudit?: RunIdleTurnAuditCycleReport;
22
23
  }
23
24
  export interface WorkbuddyWorkerCycleResult {
24
25
  readonly workspaceDir: string;
@@ -43,6 +44,8 @@ export interface WorkbuddyWorkerCycleOptions {
43
44
  /** Stage-2 classifier injection (tests); undefined = resolve from config. */
44
45
  readonly stage2Classifier?: SignalLlmClassifier | null;
45
46
  readonly stage2AggregateBudgetMs?: number;
47
+ /** Test seam: undefined = production auditor resolution; null = explicitly unavailable. */
48
+ readonly idleTurnAuditor?: IdleTurnAuditor | null;
46
49
  }
47
50
  /**
48
51
  * WHO drove this cycle — same attribution contract as the Codex worker
@@ -33,7 +33,7 @@
33
33
  import fs from 'node:fs';
34
34
  import path from 'node:path';
35
35
  import { computeFeatureFlagsFromConfig, createRuntimeStateHandle, createPainSignalBridge, isRetryWaitBackoffElapsed, pickDiagnosticianCandidate, reconcileWaitingTargetEvidenceTasks, PrincipleTreeLedgerAdapter, resolveDiagnosticianCapability, } from '@principles/core/runtime';
36
- import { loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, runInternalizationConsumerCycle, runStage2CorrectionCycle, createSignalClassifierForWorkspace, resolveWorkspacePipelineHostDeps, saveHostToolDeclaration, HOST_TOOL_DECLARATION_VERSION, } from '@principles/host-runtime';
36
+ import { loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, runInternalizationConsumerCycle, runStage2CorrectionCycle, runIdleTurnAuditCycle, createIdleTurnAuditorForWorkspace, createSignalClassifierForWorkspace, resolveWorkspacePipelineHostDeps, saveHostToolDeclaration, HOST_TOOL_DECLARATION_VERSION, } from '@principles/host-runtime';
37
37
  import { WORKBUDDY_TOOL_SEMANTICS, WORKBUDDY_TOOL_SEMANTIC_MAPPINGS } from '../tool-semantics.js';
38
38
  import { catchUpWorkbuddyIngestion } from '../ingestion/catch-up.js';
39
39
  import { readWorkbuddyTargetTurnEvidence } from '../ingestion/pain-receipt-fallback.js';
@@ -456,6 +456,24 @@ export async function runWorkbuddyWorkspaceWorkerCycle(options) {
456
456
  ...(options.now !== undefined ? { now: options.now } : {}),
457
457
  onEvent: emitEvent,
458
458
  });
459
+ // R5: one bounded idle-turn audit per worker cycle, after every
460
+ // higher-priority diagnosis/internalization step. Auditor unavailability is
461
+ // observable but does not degrade the whole worker cycle.
462
+ const idleResolution = options.idleTurnAuditor === undefined
463
+ ? createIdleTurnAuditorForWorkspace(workspaceDir, {
464
+ log: (event, detail) => emitEvent(event, detail),
465
+ })
466
+ : null;
467
+ const idleAuditor = options.idleTurnAuditor !== undefined
468
+ ? options.idleTurnAuditor
469
+ : (idleResolution?.ok === true ? idleResolution.auditor : null);
470
+ if (idleResolution !== null && !idleResolution.ok) {
471
+ emitEvent('IDLE_AUDIT_AUDITOR_UNAVAILABLE', JSON.stringify({ reason: idleResolution.reason, readiness: idleResolution.readiness }));
472
+ }
473
+ const idleAudit = await runIdleTurnAuditCycle({
474
+ workspaceDir,
475
+ auditor: idleAuditor,
476
+ });
459
477
  const degradedReason = !reconcile.ok ? `reconcile:${reconcile.reason ?? 'failed'}`
460
478
  : catchUp.status === 'degraded' ? `catch_up:${catchUp.reason ?? 'degraded'}`
461
479
  : diagnostician?.status === 'failed' && diagnostician.errorCategory !== 'lease_conflict' ? `diagnostician_failed:${diagnostician.message ?? 'max_attempts_exceeded'}`
@@ -477,6 +495,6 @@ export async function runWorkbuddyWorkspaceWorkerCycle(options) {
477
495
  ...base,
478
496
  mode: degradedReason !== undefined ? 'degraded' : 'ready',
479
497
  ...(degradedReason !== undefined ? { reason: degradedReason, nextAction: 'Inspect the governance workspace .pd/config.yaml runtime profile and the per-step report above; the worker retries automatically on the next cycle.' } : {}),
480
- report: { catchUp, reconcile, diagnostician, downstream, ...(targetEvidenceReconcile !== null ? { targetEvidenceReconcile } : {}), stage2 },
498
+ report: { catchUp, reconcile, diagnostician, downstream, ...(targetEvidenceReconcile !== null ? { targetEvidenceReconcile } : {}), stage2, idleAudit },
481
499
  };
482
500
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/workbuddy-adapter",
3
- "version": "0.10.2",
3
+ "version": "0.11.1",
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": "^8.7.0",
46
- "@principles/host-runtime": "^4.10.0",
45
+ "@principles/core": "^9.1.0",
46
+ "@principles/host-runtime": "^4.12.0",
47
47
  "@principles/install-layout": "^0.12.0"
48
48
  },
49
49
  "devDependencies": {
@@ -61,5 +61,5 @@
61
61
  "publishConfig": {
62
62
  "access": "public"
63
63
  },
64
- "gitHead": "1da1cdfe14b3c0a471e2b990a2aa376bbefe840b"
64
+ "gitHead": "e14270ad721ec3a3352d629bb8254be81842cc38"
65
65
  }