create-principles-disciple 1.147.16 → 1.147.18

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.
Files changed (72) hide show
  1. package/_release/product-identity.json +2 -2
  2. package/codex-adapter/package.json +1 -1
  3. package/core/dist/host/host-installer.d.ts +11 -0
  4. package/core/dist/host/host-installer.d.ts.map +1 -1
  5. package/core/dist/host/host-installer.js.map +1 -1
  6. package/core/dist/runtime/index.d.ts +2 -2
  7. package/core/dist/runtime/index.d.ts.map +1 -1
  8. package/core/dist/runtime/index.js +1 -1
  9. package/core/dist/runtime/index.js.map +1 -1
  10. package/core/dist/runtime/types/event-types.d.ts +62 -3
  11. package/core/dist/runtime/types/event-types.d.ts.map +1 -1
  12. package/core/dist/runtime/types/event-types.js +43 -0
  13. package/core/dist/runtime/types/event-types.js.map +1 -1
  14. package/core/package.json +1 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +23 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/installer.d.ts +20 -0
  19. package/dist/installer.d.ts.map +1 -1
  20. package/dist/installer.js +75 -12
  21. package/dist/installer.js.map +1 -1
  22. package/dist/installers/codex-host-installer.d.ts +21 -0
  23. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  24. package/dist/installers/codex-host-installer.js +105 -4
  25. package/dist/installers/codex-host-installer.js.map +1 -1
  26. package/dist/installers/workbuddy-host-installer.d.ts +2 -2
  27. package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
  28. package/dist/installers/workbuddy-host-installer.js +23 -7
  29. package/dist/installers/workbuddy-host-installer.js.map +1 -1
  30. package/host-runtime/dist/active-principle-prompt.d.ts +24 -0
  31. package/host-runtime/dist/active-principle-prompt.js +36 -0
  32. package/host-runtime/dist/product-telemetry/consent-store.d.ts +112 -14
  33. package/host-runtime/dist/product-telemetry/consent-store.js +343 -132
  34. package/host-runtime/dist/product-telemetry/control-state-lock.d.ts +99 -0
  35. package/host-runtime/dist/product-telemetry/control-state-lock.js +320 -0
  36. package/host-runtime/dist/product-telemetry/service.d.ts +26 -9
  37. package/host-runtime/dist/product-telemetry/service.js +90 -150
  38. package/host-runtime/dist/signal-stage2-cycle.js +8 -1
  39. package/host-runtime/package.json +1 -1
  40. package/install-layout/dist/index.d.ts +49 -0
  41. package/install-layout/dist/index.js +59 -0
  42. package/install-layout/package.json +1 -1
  43. package/package.json +4 -4
  44. package/pd-cli/dist/commands/health-workbuddy.d.ts +31 -0
  45. package/pd-cli/dist/commands/health-workbuddy.d.ts.map +1 -0
  46. package/pd-cli/dist/commands/health-workbuddy.js +192 -0
  47. package/pd-cli/dist/commands/health-workbuddy.js.map +1 -0
  48. package/pd-cli/dist/commands/health.d.ts.map +1 -1
  49. package/pd-cli/dist/commands/health.js +12 -0
  50. package/pd-cli/dist/commands/health.js.map +1 -1
  51. package/pd-cli/dist/commands/telemetry.d.ts.map +1 -1
  52. package/pd-cli/dist/commands/telemetry.js +3 -1
  53. package/pd-cli/dist/commands/telemetry.js.map +1 -1
  54. package/pd-cli/package.json +1 -1
  55. package/plugin/dist/bundle.js +429 -428
  56. package/plugin/dist/core/event-log.d.ts +8 -1
  57. package/plugin/dist/governance-audit.js +2 -2
  58. package/plugin/dist/hooks/llm-input-presence.d.ts +42 -0
  59. package/plugin/dist/hooks/prompt-presence-expectations.d.ts +6 -1
  60. package/plugin/dist/hooks/prompt-presence-lite.d.ts +53 -0
  61. package/plugin/dist/hooks/prompt-presence-measure.d.mts +1 -0
  62. package/plugin/dist/hooks/prompt-presence-registry.d.ts +150 -0
  63. package/plugin/dist/openclaw-sdk.d.ts +17 -0
  64. package/plugin/dist/openclaw.plugin.json +1 -1
  65. package/plugin/dist/types/event-types.d.ts +1 -1
  66. package/plugin/openclaw.plugin.json +1 -1
  67. package/plugin/package.json +1 -1
  68. package/release-manager/dist/installer.js +75 -12
  69. package/release-manager/dist/installers/codex-host-installer.js +105 -4
  70. package/release-manager/dist/installers/workbuddy-host-installer.js +23 -7
  71. package/release-manager/package.json +1 -1
  72. package/workbuddy-adapter/package.json +1 -1
@@ -23,7 +23,8 @@ import { fileURLToPath } from 'node:url';
23
23
  import { bucketDateFromTime, buildProductTelemetrySnapshot, deriveDailyTelemetryId, isValidTelemetrySecretHex, } from '@principles/core/runtime';
24
24
  import { getInstallLayoutPaths, parseInstallManifest, resolveInstallLayout } from '@principles/install-layout';
25
25
  import { loadFeatureFlagFromConfig, loadPdConfigForPlugin } from '../pd-config.js';
26
- import { deniedControlState, defaultProductTelemetryControlState, getProductTelemetryStatePath, grantedControlState, pruneWorkspaceExports, readProductTelemetryControlState, resetControlState, writeProductTelemetryControlState, } from './consent-store.js';
26
+ import { deniedControlState, defaultProductTelemetryControlState, getProductTelemetryStatePath, grantedControlState, pruneWorkspaceExports, readProductTelemetryControlState, resetControlState, withControlStateLock, } from './consent-store.js';
27
+ import { releaseExclusiveLock, tryAcquireExclusiveLockSync } from './control-state-lock.js';
27
28
  import { computeTelemetryEnvironment } from './eligibility.js';
28
29
  import { DEFAULT_PRODUCT_TELEMETRY_ENDPOINT, exportSnapshot, nextRetryDelayMs } from './exporter.js';
29
30
  import { readMilestoneFacts } from './milestone-readers.js';
@@ -35,132 +36,42 @@ export const PREVIEW_BANNER = 'Preview only. Nothing was sent.';
35
36
  export const MAX_DAILY_EXPORT_ATTEMPTS = 5;
36
37
  /** A lock older than this is treated as orphaned (holder crashed) and taken over. */
37
38
  const EXPORT_LOCK_STALE_MS = 5 * 60 * 1000;
38
- /**
39
- * The state-update critical section (fresh read → prune → merge → atomic
40
- * write) holds for a few ms, so the poll budget and stale threshold are
41
- * tiny compared to the export lock's — a crashed holder blocks bookkeeping
42
- * for seconds, not minutes, and live holders can never be evicted (the
43
- * hold is far shorter than the stale threshold).
44
- */
45
- const STATE_UPDATE_LOCK_STALE_MS = 5 * 1000;
46
- const STATE_UPDATE_LOCK_TIMEOUT_MS = 3 * 1000;
47
- const STATE_UPDATE_LOCK_POLL_MS = 15;
48
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
49
39
  /**
50
40
  * Per-workspace cross-process export lock: exclusive create ('wx') is atomic,
51
41
  * so exactly one of N simultaneous holders wins — and the lock name embeds
52
42
  * only the opaque scope key, so workspace A's in-flight export never blocks
53
- * workspace B's (review remediation P1-1). Stale takeover uses mtime — a
54
- * crashed holder can block that workspace for at most EXPORT_LOCK_STALE_MS.
43
+ * workspace B's (review remediation P1-1). Stale takeover and release use the
44
+ * SAME ownership-checked rename-claim protocol as the control-state lock
45
+ * (control-state-lock.ts, PRI-1151): a crashed holder blocks that workspace
46
+ * for at most EXPORT_LOCK_STALE_MS, a live holder's lock is never deleted by
47
+ * another process, and a late release cannot delete a successor's lock.
55
48
  * Never throws: any filesystem failure degrades to "not acquired"
56
49
  * (telemetry skips, PD unaffected).
57
50
  */
58
51
  function tryAcquireExportLock(stateFilePath, workspaceScopeId) {
59
- const lockPath = workspaceExportLockPath(stateFilePath, workspaceScopeId);
60
- const create = () => {
61
- try {
62
- const fd = fs.openSync(lockPath, 'wx');
63
- try {
64
- fs.writeSync(fd, `${process.pid} ${new Date().toISOString()}`);
65
- }
66
- finally {
67
- fs.closeSync(fd);
68
- }
69
- return true;
70
- }
71
- catch {
72
- return false;
73
- }
74
- };
75
- if (create())
76
- return { acquired: true, lockPath };
77
- try {
78
- const stat = fs.statSync(lockPath);
79
- if (Date.now() - stat.mtimeMs > EXPORT_LOCK_STALE_MS) {
80
- fs.rmSync(lockPath, { force: true });
81
- if (create())
82
- return { acquired: true, lockPath };
83
- }
84
- }
85
- catch {
86
- // stat/rm failure → treat as busy; never throw for telemetry
87
- }
88
- return { acquired: false };
89
- }
90
- function releaseExportLock(lockPath) {
91
- try {
92
- fs.rmSync(lockPath, { force: true });
93
- }
94
- catch {
95
- // best effort; a leaked lock is reclaimed after EXPORT_LOCK_STALE_MS
96
- }
52
+ return tryAcquireExclusiveLockSync(stateFilePath, {
53
+ lockPath: workspaceExportLockPath(stateFilePath, workspaceScopeId),
54
+ staleMs: EXPORT_LOCK_STALE_MS,
55
+ });
97
56
  }
98
57
  /**
99
- * Machine-scope state-update lock: serializes ONLY the control-state file
100
- * read→merge→write across workspaces (a few ms each) — the network export
101
- * itself stays fully concurrent. Review round 4: without it, two
102
- * concurrently-completing exports built their writes from the same stale
103
- * base and the later write silently dropped the earlier workspace's entry
104
- * (lost update), defeating once/day dedup, backoff, and the attempt cap.
105
- *
106
- * Lock acquisition polls asynchronously (never blocks the event loop) and
107
- * takes over a stale (crashed-holder) lock after STATE_UPDATE_LOCK_STALE_MS.
108
- */
109
- async function acquireStateUpdateLock(stateFilePath) {
110
- const lockPath = `${stateFilePath}.state-lock`;
111
- const deadline = Date.now() + STATE_UPDATE_LOCK_TIMEOUT_MS;
112
- const create = () => {
113
- try {
114
- const fd = fs.openSync(lockPath, 'wx');
115
- try {
116
- fs.writeSync(fd, `${process.pid} ${new Date().toISOString()}`);
117
- }
118
- finally {
119
- fs.closeSync(fd);
120
- }
121
- return true;
122
- }
123
- catch {
124
- return false;
125
- }
126
- };
127
- for (;;) {
128
- if (create())
129
- return { acquired: true, lockPath };
130
- try {
131
- const stat = fs.statSync(lockPath);
132
- if (Date.now() - stat.mtimeMs > STATE_UPDATE_LOCK_STALE_MS) {
133
- fs.rmSync(lockPath, { force: true });
134
- if (create())
135
- return { acquired: true, lockPath };
136
- }
137
- }
138
- catch {
139
- // disappeared between poll attempts → next loop's create decides
140
- }
141
- if (Date.now() >= deadline)
142
- return { acquired: false };
143
- await sleep(STATE_UPDATE_LOCK_POLL_MS);
144
- }
145
- }
146
- /**
147
- * Merge ONE workspace's export entry into the control state inside the
148
- * state-update critical section. The entry itself is built by the caller
149
- * (its inputs are stable for this workspace under the per-workspace export
150
- * lock); the OTHER workspaces' entries come from a FRESH read under the
151
- * lock, so concurrent completions compose instead of overwrite. Identity
152
- * transitions that raced the export (reset/disable/secret rotation mid-
153
- * flight) are detected and win — an in-flight result is never merged into
154
- * a rotated/denied identity. Best-effort by contract: every non-written
155
- * outcome is observable at the call site via structured logs (rc-9).
58
+ * Merge ONE workspace's export entry into the control state inside the ONE
59
+ * cross-process control-state transaction (withControlStateLock, PRI-1151)
60
+ * — the same lock that serializes enable/disable/reset and the legacy v1→v2
61
+ * migration write-back. The entry itself is built by the caller (its inputs
62
+ * are stable for this workspace under the per-workspace export lock); the
63
+ * OTHER workspaces' entries and the consent identity come from a FRESH read
64
+ * under the lock, so concurrent completions compose instead of overwrite,
65
+ * and identity transitions that raced the export (reset/disable/secret
66
+ * rotation mid-flight) are detected and win — an in-flight result is never
67
+ * merged into a rotated/denied identity. Best-effort by contract: every
68
+ * non-written outcome is observable at the call site via structured logs
69
+ * (rc-9). A legacy v1 file is migrated to the current format by this same
70
+ * transaction (migration + merge are one atomic write).
156
71
  */
157
72
  async function mergeWorkspaceExportEntry(args) {
158
- const stateFilePath = getProductTelemetryStatePath(args.homeDir);
159
- const lock = await acquireStateUpdateLock(stateFilePath);
160
- if (!lock.acquired)
161
- return 'skipped_contention';
162
- try {
163
- const read = readProductTelemetryControlState(args.homeDir);
73
+ const outcome = await withControlStateLock(args.homeDir, (tx) => {
74
+ const read = tx.readLatest();
164
75
  if (!read.ok)
165
76
  return 'skipped_unreadable';
166
77
  if (read.state.consent !== 'granted' || read.state.telemetrySecret !== args.secret)
@@ -170,11 +81,11 @@ async function mergeWorkspaceExportEntry(args) {
170
81
  ...pruned,
171
82
  workspaceExports: { ...(pruned.workspaceExports ?? {}), [args.scopeKey]: args.nextEntry },
172
83
  };
173
- return writeProductTelemetryControlState(args.homeDir, nextState).ok ? 'written' : 'skipped_unreadable';
174
- }
175
- finally {
176
- releaseExportLock(lock.lockPath);
177
- }
84
+ return tx.write(nextState).ok ? 'written' : 'skipped_unreadable';
85
+ });
86
+ if (!outcome.ok)
87
+ return 'skipped_contention';
88
+ return outcome.value;
178
89
  }
179
90
  const DEFAULT_MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
180
91
  function readJsonFile(filePath) {
@@ -337,40 +248,69 @@ export function createProductTelemetryService(deps = {}) {
337
248
  previewNotes.push(`control state unreadable (${read.reason}) — showing defaults`);
338
249
  return { banner: PREVIEW_BANNER, snapshot, gates, notes: previewNotes, secretEphemeral };
339
250
  },
340
- /** `pd telemetry enable --confirm`: explicit granted consent (+ secret). */
341
- enable() {
342
- const read = readProductTelemetryControlState(homeDir());
343
- if (!read.ok)
344
- return read;
345
- const next = grantedControlState(read.state);
346
- const written = writeProductTelemetryControlState(homeDir(), next);
347
- if (!written.ok)
348
- return written;
251
+ /**
252
+ * `pd telemetry enable --confirm`: explicit granted consent (+ secret).
253
+ * One locked transaction (PRI-1151): the latest disk state is read UNDER
254
+ * the same cross-process lock that serializes every other control-state
255
+ * writer, so the grant is computed from — and applied to — the current
256
+ * state; a concurrent disable/migration/reset cannot be overwritten by a
257
+ * stale one.
258
+ */
259
+ async enable() {
260
+ const outcome = await withControlStateLock(homeDir(), (tx) => {
261
+ const read = tx.readLatest();
262
+ if (!read.ok)
263
+ return read;
264
+ return tx.write(grantedControlState(read.state));
265
+ });
266
+ if (!outcome.ok)
267
+ return outcome;
268
+ if (!outcome.value.ok)
269
+ return outcome.value;
349
270
  logger.info?.(`[PD:Telemetry] Consent granted (control state: ${getProductTelemetryStatePath(homeDir())}).`);
350
271
  return { ok: true, consent: 'granted' };
351
272
  },
352
- /** `pd telemetry disable --confirm`: deny consent and delete export identity. */
353
- disable() {
354
- const read = readProductTelemetryControlState(homeDir());
355
- if (!read.ok)
356
- return read;
357
- const written = writeProductTelemetryControlState(homeDir(), deniedControlState());
358
- if (!written.ok)
359
- return written;
273
+ /**
274
+ * `pd telemetry disable --confirm`: deny consent and delete export
275
+ * identity — one locked transaction (PRI-1151). Once this returns ok,
276
+ * no concurrent migration, enable, reset, or bookkeeping merge can
277
+ * restore the previous granted consent or secret: they serialize on the
278
+ * same lock and re-read the denied state.
279
+ */
280
+ async disable() {
281
+ const outcome = await withControlStateLock(homeDir(), (tx) => {
282
+ const read = tx.readLatest();
283
+ if (!read.ok)
284
+ return read;
285
+ return tx.write(deniedControlState());
286
+ });
287
+ if (!outcome.ok)
288
+ return outcome;
289
+ if (!outcome.value.ok)
290
+ return outcome.value;
360
291
  logger.info?.('[PD:Telemetry] Consent denied; local telemetry secret and export status deleted. Future export requests: 0.');
361
292
  return { ok: true, consent: 'denied' };
362
293
  },
363
- /** `pd telemetry reset --confirm`: delete identity; fresh secret only if still enabled. */
364
- reset() {
365
- const read = readProductTelemetryControlState(homeDir());
366
- if (!read.ok)
367
- return read;
368
- const next = resetControlState(read.state);
369
- const written = writeProductTelemetryControlState(homeDir(), next);
370
- if (!written.ok)
371
- return written;
294
+ /**
295
+ * `pd telemetry reset --confirm`: delete identity; fresh secret only if
296
+ * still enabled — one locked transaction (PRI-1151) over the LATEST disk
297
+ * state (never a stale cached identity).
298
+ */
299
+ async reset() {
300
+ const outcome = await withControlStateLock(homeDir(), (tx) => {
301
+ const read = tx.readLatest();
302
+ if (!read.ok)
303
+ return read;
304
+ const next = resetControlState(read.state);
305
+ const written = tx.write(next);
306
+ return written.ok ? { ok: true, consent: next.consent } : written;
307
+ });
308
+ if (!outcome.ok)
309
+ return outcome;
310
+ if (!outcome.value.ok)
311
+ return outcome.value;
372
312
  logger.info?.('[PD:Telemetry] Telemetry identity reset; previous daily IDs are unlinkable going forward.');
373
- return { ok: true, consent: next.consent };
313
+ return { ok: true, consent: outcome.value.consent };
374
314
  },
375
315
  /**
376
316
  * One gate-checked export attempt for a normal-activity trigger.
@@ -422,7 +362,7 @@ export function createProductTelemetryService(deps = {}) {
422
362
  return { attempted: false, skipReason: 'daily_attempt_cap' };
423
363
  }
424
364
  const lock = tryAcquireExportLock(getProductTelemetryStatePath(homeDir()), scopeKey);
425
- if (!lock.acquired || lock.lockPath === undefined) {
365
+ if (lock === undefined) {
426
366
  // Another process is mid-export for THIS workspace; it will record
427
367
  // shared-day success and our next trigger will see
428
368
  // already_succeeded_today.
@@ -493,7 +433,7 @@ export function createProductTelemetryService(deps = {}) {
493
433
  nextEntry,
494
434
  });
495
435
  if (merged === 'skipped_contention') {
496
- logger.warn?.(`[PD:Telemetry] Export ${result.ok ? 'succeeded' : `failed (${result.code})`} but control state update was skipped after ${STATE_UPDATE_LOCK_TIMEOUT_MS / 1000}s of state-lock contention — this workspace may re-attempt today.`);
436
+ logger.warn?.(`[PD:Telemetry] Export ${result.ok ? 'succeeded' : `failed (${result.code})`} but control state update was skipped after 3s of state-lock contention — this workspace may re-attempt today.`);
497
437
  }
498
438
  else if (merged === 'skipped_unreadable') {
499
439
  logger.warn?.(`[PD:Telemetry] Export ${result.ok ? 'succeeded' : `failed (${result.code})`} but control state could not be read/updated — ${getProductTelemetryStatePath(homeDir())}`);
@@ -509,7 +449,7 @@ export function createProductTelemetryService(deps = {}) {
509
449
  return { attempted: true, ok: false, failureCode: result.code };
510
450
  }
511
451
  finally {
512
- releaseExportLock(lock.lockPath);
452
+ releaseExclusiveLock(lock);
513
453
  }
514
454
  },
515
455
  };
@@ -102,7 +102,14 @@ export async function runStage2CorrectionCycle(input) {
102
102
  skipped += 1;
103
103
  continue;
104
104
  }
105
- const timeoutMs = Math.max(1, Math.min(classificationTimeoutMs, remaining));
105
+ // AbortSignal.timeout (pi-ai-runtime-adapter startRun) rejects
106
+ // fractional delays with ERR_OUT_OF_RANGE, and `remaining` is a
107
+ // performance.now() float — under the default 60s budget it is
108
+ // virtually always fractional, which made every classification fail
109
+ // before any network I/O (PRI-1147 real-LLM BDD, ERR-PRI-1147-D1).
110
+ // Clamp to whole milliseconds so the remaining budget reaches the
111
+ // adapter request itself instead of throwing.
112
+ const timeoutMs = Math.max(1, Math.floor(Math.min(classificationTimeoutMs, remaining)));
106
113
  // The remaining budget goes INTO the adapter request as well as the
107
114
  // outer race (v0.3.1 §2.2); an outer timeout does not cancel a
108
115
  // provider request that the adapter does not support cancelling.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/host-runtime",
3
- "version": "3.0.0",
3
+ "version": "3.0.4",
4
4
  "description": "Shared host-neutral orchestration for Principles Disciple MVP-Core hook paths.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -136,6 +136,55 @@ export declare function getMcpServerEntry(paths: InstallLayoutPaths): string;
136
136
  * fallback to another host's database.
137
137
  */
138
138
  export declare function getWorkbuddyWorkspaceDir(homeDir: string): string;
139
+ /**
140
+ * The ONE registration/enablement state definition shared by the installer
141
+ * (install summary + `status`) and pd-cli (`pd health --host workbuddy`).
142
+ * Pure: no fs, no env — callers read the host files and hand the parsed
143
+ * values in. Neither fact may be inferred from the other (SPEC §6.4
144
+ * install ≠ enable); an unreadable source must never collapse into a
145
+ * definite value.
146
+ */
147
+ export declare const WORKBUDDY_PLUGIN_NAME = "principles-disciple";
148
+ export declare const WORKBUDDY_MARKETPLACE_NAME = "principles-disciple-market";
149
+ /** Registry/settings key: "principles-disciple@principles-disciple-market". */
150
+ export declare const WORKBUDDY_PLUGIN_KEY = "principles-disciple@principles-disciple-market";
151
+ export interface WorkbuddyPluginStateView {
152
+ /** The host registry (installed_plugins.json) carries the PD plugin entry. */
153
+ readonly registered: boolean;
154
+ /** False when the registry file could not be read/parsed — installed must NOT be claimed. */
155
+ readonly registryReadable: boolean;
156
+ /** `enabledPlugins[key]`: true/false, or null when absent/unreadable/non-boolean (activation unknown). */
157
+ readonly enabled: boolean | null;
158
+ }
159
+ export interface WorkbuddyHostConfigPaths {
160
+ /** Host config root (the engine honors WORKBUDDY_CONFIG_DIR when set). */
161
+ readonly configDir: string;
162
+ readonly settingsPath: string;
163
+ readonly registryPath: string;
164
+ }
165
+ /**
166
+ * Resolve the WorkBuddy HOST config paths from one authority. The frozen
167
+ * governance dir (~/.workbuddy/pd-workspace) defines the config root;
168
+ * WORKBUDDY_CONFIG_DIR is the isolation override (Phase 0 lab discipline).
169
+ * The WorkBuddyHostInstaller resolves its full path set by delegating here,
170
+ * so installer / status / health can never disagree about where the host
171
+ * files live.
172
+ */
173
+ export declare function getWorkbuddyHostConfigPaths(homeDir: string, configDirOverride?: string): WorkbuddyHostConfigPaths;
174
+ /**
175
+ * The shared plugin-state judgment (rc-2: no `as` bypass; rc-4/5). The exact
176
+ * semantics the installer has applied since PR #2355, extracted so pd-cli
177
+ * health reports the SAME three facts from the same rules:
178
+ * - registered: registry readable AND carried a plugins mapping with our key;
179
+ * - registryReadable: false only when the registry could not be read/parsed;
180
+ * - enabled: the boolean in settings.enabledPlugins[our key], or null when
181
+ * settings are unreadable, the key is absent, or the value is not boolean.
182
+ */
183
+ export declare function interpretWorkbuddyPluginState(input: {
184
+ registryParsed: unknown;
185
+ settingsParsed: unknown;
186
+ registryReadable: boolean;
187
+ }): WorkbuddyPluginStateView;
139
188
  export declare function resolveInstallLayout(options: ResolveInstallLayoutOptions): LayoutResolution;
140
189
  export declare function getConsoleServerEntry(paths: InstallLayoutPaths, mode: InstallLayoutMode): string;
141
190
  export declare function getConsoleWebIndex(paths: InstallLayoutPaths, mode: InstallLayoutMode): string;
@@ -164,6 +164,65 @@ export function getMcpServerEntry(paths) {
164
164
  export function getWorkbuddyWorkspaceDir(homeDir) {
165
165
  return path.join(path.resolve(homeDir), '.workbuddy', 'pd-workspace');
166
166
  }
167
+ // ─── WorkBuddy host state (2026-11-07, read-only state contract) ────────────
168
+ /**
169
+ * The ONE registration/enablement state definition shared by the installer
170
+ * (install summary + `status`) and pd-cli (`pd health --host workbuddy`).
171
+ * Pure: no fs, no env — callers read the host files and hand the parsed
172
+ * values in. Neither fact may be inferred from the other (SPEC §6.4
173
+ * install ≠ enable); an unreadable source must never collapse into a
174
+ * definite value.
175
+ */
176
+ export const WORKBUDDY_PLUGIN_NAME = 'principles-disciple';
177
+ export const WORKBUDDY_MARKETPLACE_NAME = 'principles-disciple-market';
178
+ /** Registry/settings key: "principles-disciple@principles-disciple-market". */
179
+ export const WORKBUDDY_PLUGIN_KEY = `${WORKBUDDY_PLUGIN_NAME}@${WORKBUDDY_MARKETPLACE_NAME}`;
180
+ /**
181
+ * Resolve the WorkBuddy HOST config paths from one authority. The frozen
182
+ * governance dir (~/.workbuddy/pd-workspace) defines the config root;
183
+ * WORKBUDDY_CONFIG_DIR is the isolation override (Phase 0 lab discipline).
184
+ * The WorkBuddyHostInstaller resolves its full path set by delegating here,
185
+ * so installer / status / health can never disagree about where the host
186
+ * files live.
187
+ */
188
+ export function getWorkbuddyHostConfigPaths(homeDir, configDirOverride) {
189
+ const configDir = configDirOverride !== undefined && configDirOverride.length > 0
190
+ ? path.resolve(configDirOverride)
191
+ : path.dirname(getWorkbuddyWorkspaceDir(homeDir));
192
+ return {
193
+ configDir,
194
+ settingsPath: path.join(configDir, 'settings.json'),
195
+ registryPath: path.join(configDir, 'plugins', 'installed_plugins.json'),
196
+ };
197
+ }
198
+ /** rc-1 minimal guard: a plain JSON object, not an array/null/primitive. */
199
+ function isPlainJsonObject(value) {
200
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
201
+ }
202
+ /**
203
+ * The shared plugin-state judgment (rc-2: no `as` bypass; rc-4/5). The exact
204
+ * semantics the installer has applied since PR #2355, extracted so pd-cli
205
+ * health reports the SAME three facts from the same rules:
206
+ * - registered: registry readable AND carried a plugins mapping with our key;
207
+ * - registryReadable: false only when the registry could not be read/parsed;
208
+ * - enabled: the boolean in settings.enabledPlugins[our key], or null when
209
+ * settings are unreadable, the key is absent, or the value is not boolean.
210
+ */
211
+ export function interpretWorkbuddyPluginState(input) {
212
+ const registry = isPlainJsonObject(input.registryParsed) ? input.registryParsed : undefined;
213
+ const plugins = registry !== undefined && isPlainJsonObject(registry.plugins) ? registry.plugins : undefined;
214
+ const registered = input.registryReadable && plugins !== undefined
215
+ ? Object.hasOwn(plugins, WORKBUDDY_PLUGIN_KEY)
216
+ : false;
217
+ const settings = isPlainJsonObject(input.settingsParsed) ? input.settingsParsed : undefined;
218
+ const enabledPlugins = settings !== undefined && isPlainJsonObject(settings.enabledPlugins) ? settings.enabledPlugins : undefined;
219
+ const raw = enabledPlugins === undefined ? undefined : enabledPlugins[WORKBUDDY_PLUGIN_KEY];
220
+ return {
221
+ registered,
222
+ registryReadable: input.registryReadable,
223
+ enabled: typeof raw === 'boolean' ? raw : null,
224
+ };
225
+ }
167
226
  export function resolveInstallLayout(options) {
168
227
  const paths = getInstallLayoutPaths(options.homeDir);
169
228
  const parsed = parseInstallManifest(options.manifest);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/install-layout",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-principles-disciple",
3
- "version": "1.147.16",
3
+ "version": "1.147.18",
4
4
  "description": "Interactive CLI installer for Principles Disciple OpenClaw plugin",
5
5
  "type": "module",
6
6
  "bin": {
@@ -63,7 +63,7 @@
63
63
  "dependencies": {
64
64
  "@earendil-works/pi-agent-core": "1.2.0",
65
65
  "@earendil-works/pi-ai": "1.4.0",
66
- "@principles/install-layout": "^0.4.1",
66
+ "@principles/install-layout": "^0.5.0",
67
67
  "@sinclair/typebox": "^0.34.52",
68
68
  "@tufjs/models": "3.0.1",
69
69
  "@inquirer/prompts": "^8.7.2",
@@ -99,7 +99,7 @@
99
99
  "directory": "packages/create-principles-disciple"
100
100
  },
101
101
  "pd": {
102
- "bundledPluginVersion": "3.0.1"
102
+ "bundledPluginVersion": "3.0.2"
103
103
  },
104
- "gitHead": "9656a64563e073c92aa8da0373ea96249de1a71b"
104
+ "gitHead": "d1b8ff89e487e11a242aa705ee562b75ebc8d209"
105
105
  }
@@ -0,0 +1,31 @@
1
+ import { type WorkbuddyPluginStateView } from '@principles/install-layout';
2
+ export type WorkbuddyGovernanceState = 'ENABLED' | 'EXPLICITLY_DISABLED' | 'DEFAULT_OFF' | 'UNKNOWN';
3
+ export interface WorkbuddyHostFacts {
4
+ /** Registry + enablement, interpreted by the shared install-layout judgment. */
5
+ plugin: WorkbuddyPluginStateView;
6
+ governance: {
7
+ state: WorkbuddyGovernanceState;
8
+ /** The governance config file the flag was read from (null when absent/unreadable). */
9
+ configPath: string | null;
10
+ /** Structured reason when state === 'UNKNOWN' (rc-9). */
11
+ reason?: string;
12
+ };
13
+ /** Honest runtime boundary: static health never implies a live host. */
14
+ runtime: {
15
+ /** Always false — pd health never spawns WorkBuddy or the MCP server. */
16
+ probePerformed: false;
17
+ reason: string;
18
+ modelToolCall: 'NOT_VERIFIED';
19
+ };
20
+ paths: {
21
+ registryPath: string;
22
+ settingsPath: string;
23
+ governanceDir: string;
24
+ };
25
+ }
26
+ export declare function assessWorkbuddyHostFacts(options?: {
27
+ homeDir?: string;
28
+ configDirOverride?: string;
29
+ }): WorkbuddyHostFacts;
30
+ export declare function formatWorkbuddyHostFactLines(facts: WorkbuddyHostFacts): string[];
31
+ //# sourceMappingURL=health-workbuddy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health-workbuddy.d.ts","sourceRoot":"","sources":["../../src/commands/health-workbuddy.ts"],"names":[],"mappings":"AAgCA,OAAO,EAIL,KAAK,wBAAwB,EAC9B,MAAM,4BAA4B,CAAC;AAIpC,MAAM,MAAM,wBAAwB,GAAG,SAAS,GAAG,qBAAqB,GAAG,aAAa,GAAG,SAAS,CAAC;AAErG,MAAM,WAAW,kBAAkB;IACjC,gFAAgF;IAChF,MAAM,EAAE,wBAAwB,CAAC;IACjC,UAAU,EAAE;QACV,KAAK,EAAE,wBAAwB,CAAC;QAChC,uFAAuF;QACvF,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,yDAAyD;QACzD,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,wEAAwE;IACxE,OAAO,EAAE;QACP,yEAAyE;QACzE,cAAc,EAAE,KAAK,CAAC;QACtB,MAAM,EAAE,MAAM,CAAC;QACf,aAAa,EAAE,cAAc,CAAC;KAC/B,CAAC;IACF,KAAK,EAAE;QACL,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAkDD,wBAAgB,wBAAwB,CAAC,OAAO,GAAE;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,kBAAkB,CA8E1B;AASD,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,kBAAkB,GAAG,MAAM,EAAE,CAehF"}