@principles/workbuddy-adapter 0.9.0 → 0.10.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.
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* look-alike strings (SPEC TD §1.3).
|
|
32
32
|
*/
|
|
33
33
|
import * as path from 'node:path';
|
|
34
|
-
import { readSourceMaterialAuthorization } from '@principles/host-runtime';
|
|
34
|
+
import { createConsentLedgerSourceMaterialAuthorization, readSourceMaterialAuthorization } from '@principles/host-runtime';
|
|
35
35
|
import { isSentinelSessionId } from '@principles/core/runtime';
|
|
36
36
|
import { listGovernanceConversationTextsForHostTurn } from '@principles/host-runtime';
|
|
37
37
|
import { recoverTaskIdentityFromReceipt, validatePainSubmitReceipt, } from '@principles/core/runtime';
|
|
@@ -201,7 +201,8 @@ export async function attemptPainReceiptFallback(input) {
|
|
|
201
201
|
// turn pinned to an unproven id would wedge the task's evidence wait.
|
|
202
202
|
identity: { sessionId, toolCallId },
|
|
203
203
|
authorization: { minimalMetadataGranted: input.minimalMetadataGranted },
|
|
204
|
-
|
|
204
|
+
readTargetTurnEvidence: (hostSessionId, targetTurnId) => readWorkbuddyTargetTurnEvidence(normalizedWorkspace, hostSessionId, targetTurnId),
|
|
205
|
+
sourceMaterialAuthorization: createConsentLedgerSourceMaterialAuthorization(normalizedWorkspace),
|
|
205
206
|
...(input.now !== undefined ? { now: input.now } : {}),
|
|
206
207
|
});
|
|
207
208
|
return { status: 'attempted', outcome };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type TargetEvidenceReconcileReport } from '@principles/core/runtime';
|
|
1
2
|
import { type InternalizationConsumerCycleOutcome, type ConsumerCycleLogger, type ReconcileGovernanceContinuationResult, type SignalLlmClassifier, type Stage2CorrectionCycleReport } from '@principles/host-runtime';
|
|
2
3
|
import { type WorkbuddyCatchUpResult } from '../ingestion/catch-up.js';
|
|
3
4
|
export type WorkbuddyWorkerMode = 'ready' | 'manual_action_required' | 'paused' | 'degraded';
|
|
@@ -14,6 +15,8 @@ export interface WorkbuddyWorkerCycleStepReport {
|
|
|
14
15
|
readonly nextAction?: string;
|
|
15
16
|
} | null;
|
|
16
17
|
readonly downstream: InternalizationConsumerCycleOutcome | null;
|
|
18
|
+
/** PRI-1296: bounded exact-target evidence reconcile, before candidate picking. */
|
|
19
|
+
readonly targetEvidenceReconcile?: TargetEvidenceReconcileReport;
|
|
17
20
|
/** Phase B Stage-2 review step (always last, ≤2 candidates / ≤60s aggregate). */
|
|
18
21
|
readonly stage2?: Stage2CorrectionCycleReport;
|
|
19
22
|
}
|
|
@@ -44,8 +47,16 @@ export interface WorkbuddyWorkerCycleOptions {
|
|
|
44
47
|
/**
|
|
45
48
|
* WHO drove this cycle — same attribution contract as the Codex worker
|
|
46
49
|
* (PRI-1264 + Phase 2 `service_host` driver identity, TD §5.2).
|
|
50
|
+
*
|
|
51
|
+
* PRI-1278 Phase 5 (Companion-runtime removal): the companion worker driver
|
|
52
|
+
* is retired — there is no Companion runtime left that could legitimately
|
|
53
|
+
* produce it. A process still self-declaring `PD_INVOCATION_SOURCE=companion`
|
|
54
|
+
* (a legacy env leftover) is not authoritative: no resident supervisor backs
|
|
55
|
+
* it, so it is attributed as what it factually is — manual. Historical
|
|
56
|
+
* liveness records already persisted with `lastCycleDriver: 'companion'`
|
|
57
|
+
* stay readable as-is; they are durable facts and are never rewritten.
|
|
47
58
|
*/
|
|
48
|
-
export declare function workbuddyWorkerCycleDriver(): '
|
|
59
|
+
export declare function workbuddyWorkerCycleDriver(): 'service_host' | 'manual';
|
|
49
60
|
/** Read the persisted liveness record, or null when absent/unreadable. */
|
|
50
61
|
export declare function readWorkbuddyWorkerLiveness(workspaceDir: string): Record<string, unknown> | null;
|
|
51
62
|
/**
|
|
@@ -22,20 +22,27 @@
|
|
|
22
22
|
* scheduler state — and no Codex flag, path or transcript semantics are
|
|
23
23
|
* borrowed (SPEC §5: 不借用 Codex flag/日志伪装归因).
|
|
24
24
|
*
|
|
25
|
-
* Correctness under concurrent consumers (
|
|
26
|
-
* worker` + manual `pd runtime internalization
|
|
27
|
-
* durable Runtime task lease — never by
|
|
25
|
+
* Correctness under concurrent consumers (Service-Host-spawned bounded
|
|
26
|
+
* `pd workbuddy worker --once` + manual `pd runtime internalization
|
|
27
|
+
* run-once`) is owned by the durable Runtime task lease — never by
|
|
28
|
+
* process-local state. The
|
|
28
29
|
* governance workspace is the single canonical directory
|
|
29
30
|
* (`~/.workbuddy/pd-workspace`), so two projects never double-schedule:
|
|
30
31
|
* they share one workspace and the lease serialises consumption.
|
|
31
32
|
*/
|
|
32
33
|
import fs from 'node:fs';
|
|
33
34
|
import path from 'node:path';
|
|
34
|
-
import { computeFeatureFlagsFromConfig, createRuntimeStateHandle, createPainSignalBridge, isRetryWaitBackoffElapsed, pickDiagnosticianCandidate, PrincipleTreeLedgerAdapter, resolveDiagnosticianCapability, } from '@principles/core/runtime';
|
|
35
|
-
import { loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, runInternalizationConsumerCycle, runStage2CorrectionCycle, createSignalClassifierForWorkspace,
|
|
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
37
|
import { WORKBUDDY_TOOL_SEMANTICS, WORKBUDDY_TOOL_SEMANTIC_MAPPINGS } from '../tool-semantics.js';
|
|
37
38
|
import { catchUpWorkbuddyIngestion } from '../ingestion/catch-up.js';
|
|
38
|
-
|
|
39
|
+
import { readWorkbuddyTargetTurnEvidence } from '../ingestion/pain-receipt-fallback.js';
|
|
40
|
+
// PRI-1278 Phase 5 (Companion-runtime removal): the lease/consumer owner
|
|
41
|
+
// label for NEW writes is the Service Host worker identity — the PD Service
|
|
42
|
+
// Host is the only background runtime and spawns these bounded worker cycles.
|
|
43
|
+
// Historical lease records keep the retired 'companion-worker' string; they
|
|
44
|
+
// are durable facts and are deliberately NOT migrated.
|
|
45
|
+
const WORKER_OWNER = 'service-host-worker';
|
|
39
46
|
const DEFAULT_DIAG_CANDIDATE_LIMIT = 5;
|
|
40
47
|
// ── Cycle liveness (Phase 2, SPEC §11 / TD §2.3: WorkBuddy had NO liveness
|
|
41
48
|
// record — FR-10 health was undecidable). Same shape and atomic-write
|
|
@@ -55,11 +62,17 @@ function isPlainRecord(value) {
|
|
|
55
62
|
/**
|
|
56
63
|
* WHO drove this cycle — same attribution contract as the Codex worker
|
|
57
64
|
* (PRI-1264 + Phase 2 `service_host` driver identity, TD §5.2).
|
|
65
|
+
*
|
|
66
|
+
* PRI-1278 Phase 5 (Companion-runtime removal): the companion worker driver
|
|
67
|
+
* is retired — there is no Companion runtime left that could legitimately
|
|
68
|
+
* produce it. A process still self-declaring `PD_INVOCATION_SOURCE=companion`
|
|
69
|
+
* (a legacy env leftover) is not authoritative: no resident supervisor backs
|
|
70
|
+
* it, so it is attributed as what it factually is — manual. Historical
|
|
71
|
+
* liveness records already persisted with `lastCycleDriver: 'companion'`
|
|
72
|
+
* stay readable as-is; they are durable facts and are never rewritten.
|
|
58
73
|
*/
|
|
59
74
|
export function workbuddyWorkerCycleDriver() {
|
|
60
75
|
const source = process.env.PD_INVOCATION_SOURCE;
|
|
61
|
-
if (source === 'companion')
|
|
62
|
-
return 'companion';
|
|
63
76
|
if (source === 'service_host')
|
|
64
77
|
return 'service_host';
|
|
65
78
|
return 'manual';
|
|
@@ -68,9 +81,9 @@ export function workbuddyWorkerCycleDriver() {
|
|
|
68
81
|
* F13 (TD §5.2): the coordinator passes a unique invocation id; when
|
|
69
82
|
* present it lands in the liveness record so the shared per-workspace file
|
|
70
83
|
* can be correlated back to the exact Service Host invocation.
|
|
71
|
-
* R5 review fix: a manual
|
|
72
|
-
* patch must CLEAR the field — otherwise a completed manual run
|
|
73
|
-
* masquerading under the previous shadow run's id.
|
|
84
|
+
* R5 review fix: a manual (non-Service-Host) cycle carries NO invocation
|
|
85
|
+
* id, so the patch must CLEAR the field — otherwise a completed manual run
|
|
86
|
+
* would keep masquerading under the previous shadow run's id.
|
|
74
87
|
*/
|
|
75
88
|
function invocationIdLivenessPatch() {
|
|
76
89
|
const invocationId = process.env.PD_INVOCATION_ID;
|
|
@@ -241,6 +254,8 @@ export async function runWorkbuddyWorkspaceWorkerCycle(options) {
|
|
|
241
254
|
});
|
|
242
255
|
// Steps 3–5 — execution authority: internalization_auto_consumer.
|
|
243
256
|
let diagnostician = null;
|
|
257
|
+
// PRI-1296: filled by the exact-target evidence reconcile below.
|
|
258
|
+
let targetEvidenceReconcile = null;
|
|
244
259
|
if (diagnosticianDisabled) {
|
|
245
260
|
diagnostician = {
|
|
246
261
|
taskId: '',
|
|
@@ -297,15 +312,48 @@ export async function runWorkbuddyWorkspaceWorkerCycle(options) {
|
|
|
297
312
|
try {
|
|
298
313
|
const handle = await createRuntimeStateHandle({ workspaceDir, readonly: false });
|
|
299
314
|
try {
|
|
315
|
+
// SPEC-PD-PIPELINE-SPINE-001 §4.2 (PRI-1292 Phase 2A): ONE assembly
|
|
316
|
+
// point for the five host collaborators. The target-evidence reconcile
|
|
317
|
+
// and any diagnostician bridge in this cycle share the SAME consent
|
|
318
|
+
// authorization instance.
|
|
319
|
+
const hostDeps = resolveWorkspacePipelineHostDeps({
|
|
320
|
+
workspaceDir,
|
|
321
|
+
effectiveConfig: config.effective,
|
|
322
|
+
telemetryPersistenceFailureHandler: (detail) => {
|
|
323
|
+
try {
|
|
324
|
+
emitEvent('WORKBUDDY_WORKER_CRITICAL_TELEMETRY_PERSIST_FAILED', detail);
|
|
325
|
+
}
|
|
326
|
+
catch {
|
|
327
|
+
// Telemetry persistence warnings must never fail the worker cycle.
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
});
|
|
300
331
|
const sweep = await handle.stateManager.runRecoverySweep();
|
|
301
332
|
if (sweep.recovered > 0 || sweep.errors.length > 0) {
|
|
302
333
|
emitEvent('WORKBUDDY_WORKER_RECOVERY_SWEEP', JSON.stringify({ recovered: sweep.recovered, failed: sweep.errors.length }));
|
|
303
334
|
}
|
|
335
|
+
// PRI-1296: reconcile waiting target evidence BEFORE the candidate
|
|
336
|
+
// picker. Catch-up may have just delivered the exact target turn, and
|
|
337
|
+
// the picker SQL excludes waiting tasks; doing this after picking
|
|
338
|
+
// would let diagnosis consume a task before its evidence exists.
|
|
339
|
+
targetEvidenceReconcile = await reconcileWaitingTargetEvidenceTasks({
|
|
340
|
+
stateManager: handle.stateManager,
|
|
341
|
+
readTargetTurnEvidence: (sessionId, turnId) => readWorkbuddyTargetTurnEvidence(workspaceDir, sessionId, turnId),
|
|
342
|
+
sourceMaterialAuthorization: hostDeps.sourceMaterialAuthorization,
|
|
343
|
+
hostKind: 'workbuddy',
|
|
344
|
+
nowIso: new Date().toISOString(),
|
|
345
|
+
});
|
|
346
|
+
if (targetEvidenceReconcile.flipped > 0 || targetEvidenceReconcile.blocked > 0 || targetEvidenceReconcile.errors.length > 0) {
|
|
347
|
+
emitEvent('WORKBUDDY_WORKER_TARGET_EVIDENCE_RECONCILE', JSON.stringify(targetEvidenceReconcile));
|
|
348
|
+
}
|
|
304
349
|
const candidate = await pickNextDiagnosticianCandidate(handle.stateManager, options.diagnosticianCandidateLimit ?? DEFAULT_DIAG_CANDIDATE_LIMIT);
|
|
305
350
|
if (candidate !== null) {
|
|
306
351
|
const stateDir = path.join(workspaceDir, '.state');
|
|
307
352
|
let releaseBridge;
|
|
308
353
|
try {
|
|
354
|
+
// PRI-1233 / SPEC §9.2: this worker is where Stage A actually runs
|
|
355
|
+
// for governance-admitted WorkBuddy pains; PRI-1265: the Stage A gets
|
|
356
|
+
// the bound session's ORIGINAL turns through the shared host deps.
|
|
309
357
|
const bridge = await createPainSignalBridge({
|
|
310
358
|
workspaceDir,
|
|
311
359
|
stateDir,
|
|
@@ -313,18 +361,15 @@ export async function runWorkbuddyWorkspaceWorkerCycle(options) {
|
|
|
313
361
|
owner: WORKER_OWNER,
|
|
314
362
|
effectiveConfig: config.effective,
|
|
315
363
|
getEnvVar: (name) => process.env[name],
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
//
|
|
321
|
-
|
|
322
|
-
trajectoryTurnReader: createGovernanceTrajectoryTurnReader({ workspaceDir, sourceMaterialAuthorization: createConsentLedgerSourceMaterialAuthorization(workspaceDir) }),
|
|
323
|
-
// PRI-1283 R2: latest-consent gate consulted per assembly / model call.
|
|
324
|
-
sourceMaterialAuthorization: createConsentLedgerSourceMaterialAuthorization(workspaceDir),
|
|
364
|
+
intentDocReader: hostDeps.intentDocReader,
|
|
365
|
+
trajectoryTurnReader: hostDeps.trajectoryTurnReader,
|
|
366
|
+
sourceMaterialAuthorization: hostDeps.sourceMaterialAuthorization,
|
|
367
|
+
// PRI-939 Option A: allowlisted runner/bridge events persist to
|
|
368
|
+
// the workspace sink instead of the unsubscribed singleton.
|
|
369
|
+
telemetrySink: hostDeps.telemetrySink,
|
|
325
370
|
// SPEC §9.6: lazy probe — a revoked flag stops persisted
|
|
326
371
|
// automatic_hook tasks at the bridge's execution boundary.
|
|
327
|
-
isAutoPainSubmissionAuthorized:
|
|
372
|
+
isAutoPainSubmissionAuthorized: hostDeps.isAutoPainSubmissionAuthorized,
|
|
328
373
|
}, (release) => { releaseBridge = release; });
|
|
329
374
|
const executed = await bridge.executePendingDiagnosis({ taskId: candidate.taskId });
|
|
330
375
|
diagnostician = {
|
|
@@ -360,7 +405,7 @@ export async function runWorkbuddyWorkspaceWorkerCycle(options) {
|
|
|
360
405
|
mode: 'degraded',
|
|
361
406
|
reason,
|
|
362
407
|
nextAction: 'Inspect the governance workspace runtime profile and provider configuration; the task keeps its pending/retry state and no evidence was mutated.',
|
|
363
|
-
report: { catchUp, reconcile, diagnostician: null, downstream: null },
|
|
408
|
+
report: { catchUp, reconcile, diagnostician: null, downstream: null, ...(targetEvidenceReconcile !== null ? { targetEvidenceReconcile } : {}) },
|
|
364
409
|
};
|
|
365
410
|
}
|
|
366
411
|
}
|
|
@@ -383,7 +428,7 @@ export async function runWorkbuddyWorkspaceWorkerCycle(options) {
|
|
|
383
428
|
mode: 'degraded',
|
|
384
429
|
reason,
|
|
385
430
|
nextAction: 'Repair WorkBuddy host declaration persistence (.pd/host-tool-semantics/workbuddy.json) before running the downstream internalization cycle; the worker retries automatically on the next cycle.',
|
|
386
|
-
report: { catchUp, reconcile, diagnostician, downstream: null },
|
|
431
|
+
report: { catchUp, reconcile, diagnostician, downstream: null, ...(targetEvidenceReconcile !== null ? { targetEvidenceReconcile } : {}) },
|
|
387
432
|
};
|
|
388
433
|
}
|
|
389
434
|
writeLiveness(workspaceDir, { runningStage: 'downstream_cycle', stageDeadline: new Date(Date.now() + LIVENESS_STAGE_DEADLINE_MS.downstream_cycle).toISOString() });
|
|
@@ -436,6 +481,6 @@ export async function runWorkbuddyWorkspaceWorkerCycle(options) {
|
|
|
436
481
|
...base,
|
|
437
482
|
mode: degradedReason !== undefined ? 'degraded' : 'ready',
|
|
438
483
|
...(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.' } : {}),
|
|
439
|
-
report: { catchUp, reconcile, diagnostician, downstream, stage2 },
|
|
484
|
+
report: { catchUp, reconcile, diagnostician, downstream, ...(targetEvidenceReconcile !== null ? { targetEvidenceReconcile } : {}), stage2 },
|
|
440
485
|
};
|
|
441
486
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/workbuddy-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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,9 +42,9 @@
|
|
|
42
42
|
"lint": "eslint \"src/**/*.ts\""
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@principles/core": "^8.
|
|
46
|
-
"@principles/host-runtime": "^4.
|
|
47
|
-
"@principles/install-layout": "^0.
|
|
45
|
+
"@principles/core": "^8.4.0",
|
|
46
|
+
"@principles/host-runtime": "^4.8.0",
|
|
47
|
+
"@principles/install-layout": "^0.12.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/node": "^26.6.6",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"publishConfig": {
|
|
62
62
|
"access": "public"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "ff62137821c993773cc7df104a01625310776c51"
|
|
65
65
|
}
|