@principles/workbuddy-adapter 0.10.2 → 0.11.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.
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, 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;
@@ -414,6 +414,13 @@ export async function processWorkbuddyHookInvocation(rawStdin, channelEventName,
414
414
  if (flags.workbuddy_conversation_ingestion?.enabled !== true) {
415
415
  return neutralWithDiagnostics([]);
416
416
  }
417
+ recordIdleAuditTurnCompleted({
418
+ workspaceDir: resolution.workspaceDir,
419
+ hostKind: 'workbuddy',
420
+ sessionId: event.context.sessionId,
421
+ turnEndSource: 'stop_hook',
422
+ hasActiveRun: false,
423
+ });
417
424
  const ingestion = ingestWorkbuddyConversation({
418
425
  workspaceDir: resolution.workspaceDir,
419
426
  rawPayload: event.rawPayload,
@@ -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.0",
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.0.0",
46
+ "@principles/host-runtime": "^4.11.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": "1e6fc5c3f3083d24dc50a65c420609e21307d9d5"
65
65
  }