@principles/pd-cli 2.9.0 → 2.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.
Files changed (51) hide show
  1. package/dist/commands/health-ingestion.d.ts.map +1 -1
  2. package/dist/commands/health-ingestion.js +6 -2
  3. package/dist/commands/health-ingestion.js.map +1 -1
  4. package/dist/commands/pain-record.d.ts.map +1 -1
  5. package/dist/commands/pain-record.js +4 -1
  6. package/dist/commands/pain-record.js.map +1 -1
  7. package/dist/commands/pain-retry.d.ts.map +1 -1
  8. package/dist/commands/pain-retry.js +19 -1
  9. package/dist/commands/pain-retry.js.map +1 -1
  10. package/dist/commands/service-run-once.d.ts +6 -0
  11. package/dist/commands/service-run-once.d.ts.map +1 -0
  12. package/dist/commands/service-run-once.js +139 -0
  13. package/dist/commands/service-run-once.js.map +1 -0
  14. package/dist/program.d.ts.map +1 -1
  15. package/dist/program.js +21 -0
  16. package/dist/program.js.map +1 -1
  17. package/dist/services/pain-flood-simulation-runner.d.ts.map +1 -1
  18. package/dist/services/pain-flood-simulation-runner.js +4 -0
  19. package/dist/services/pain-flood-simulation-runner.js.map +1 -1
  20. package/dist/services/service-host/index.d.ts +15 -0
  21. package/dist/services/service-host/index.d.ts.map +1 -0
  22. package/dist/services/service-host/index.js +15 -0
  23. package/dist/services/service-host/index.js.map +1 -0
  24. package/dist/services/service-host/install-identity.d.ts +79 -0
  25. package/dist/services/service-host/install-identity.d.ts.map +1 -0
  26. package/dist/services/service-host/install-identity.js +166 -0
  27. package/dist/services/service-host/install-identity.js.map +1 -0
  28. package/dist/services/service-host/locking/service-run-lock.d.ts +134 -0
  29. package/dist/services/service-host/locking/service-run-lock.d.ts.map +1 -0
  30. package/dist/services/service-host/locking/service-run-lock.js +659 -0
  31. package/dist/services/service-host/locking/service-run-lock.js.map +1 -0
  32. package/dist/services/service-host/owner-projection.d.ts +47 -0
  33. package/dist/services/service-host/owner-projection.d.ts.map +1 -0
  34. package/dist/services/service-host/owner-projection.js +121 -0
  35. package/dist/services/service-host/owner-projection.js.map +1 -0
  36. package/dist/services/service-host/run-once.d.ts +96 -0
  37. package/dist/services/service-host/run-once.d.ts.map +1 -0
  38. package/dist/services/service-host/run-once.js +440 -0
  39. package/dist/services/service-host/run-once.js.map +1 -0
  40. package/dist/services/service-host/status/service-run-status.d.ts +117 -0
  41. package/dist/services/service-host/status/service-run-status.d.ts.map +1 -0
  42. package/dist/services/service-host/status/service-run-status.js +150 -0
  43. package/dist/services/service-host/status/service-run-status.js.map +1 -0
  44. package/dist/services/service-host/workspace-discovery.d.ts +71 -0
  45. package/dist/services/service-host/workspace-discovery.d.ts.map +1 -0
  46. package/dist/services/service-host/workspace-discovery.js +288 -0
  47. package/dist/services/service-host/workspace-discovery.js.map +1 -0
  48. package/dist/services/synthetic-baseline-runner.d.ts.map +1 -1
  49. package/dist/services/synthetic-baseline-runner.js +4 -0
  50. package/dist/services/synthetic-baseline-runner.js.map +1 -1
  51. package/package.json +8 -8
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Coordinator install identity (SPEC-PD-SERVICE-HOST-001 §8.2 step 1, TD §5.2).
3
+ *
4
+ * The run-once coordinator must act on ONE explicit production install
5
+ * identity, and TD §5.2 names every env variable that must NOT be able to
6
+ * relocate it: `PD_EXPERIMENT_ROOT`, `HOME`/`USERPROFILE`,
7
+ * `OPENCLAW_STATE_DIR`/`OPENCLAW_HOME`, `WORKBUDDY_CONFIG_DIR`,
8
+ * `CODEX_HOME`.
9
+ *
10
+ * Two different questions get two different authorities:
11
+ *
12
+ * - WHO this install is (pdHome identity): derived ONLY from the OS account
13
+ * record — `os.userInfo().homedir`, which reads getpwuid /
14
+ * GetUserProfileDirectoryW and cannot be overridden by inherited env vars.
15
+ * `PD_EXPERIMENT_ROOT` is stripped before resolution and `HOME` /
16
+ * `USERPROFILE` are ignored for identity entirely; each fact is RECORDED
17
+ * in the returned environment view (rc-9), never silently dropped. When no
18
+ * trusted home can be determined (no OS record, non-absolute result) the
19
+ * coordinator REFUSES — it never falls back to an env-derived guess.
20
+ * - WHICH host roots the same install serves (discovery context): the host
21
+ * overrides ARE honored, exactly like every other PD component resolves
22
+ * them. They decide where workspace claims are collected; they can never
23
+ * move `pdHome` itself (P1-2 contract).
24
+ *
25
+ * The registration-pinned identity (TD §5.2 "由注册时解析出的绝对路径决定")
26
+ * arrives with `pd service install` in Phase 3; until then the OS record is
27
+ * the single identity authority. `trustedHomeDir` exists so callers with an
28
+ * already-verified home (tests, the future registration handoff) can pin the
29
+ * same authority without going through the OS lookup again.
30
+ */
31
+ import * as os from 'node:os';
32
+ import * as path from 'node:path';
33
+ import { resolvePdHome } from '@principles/install-layout';
34
+ /** The one identity-switching experiment variable (pd-home.ts). */
35
+ const PD_EXPERIMENT_ROOT = 'PD_EXPERIMENT_ROOT';
36
+ /**
37
+ * Env variables that may steer host discovery but must never steer the
38
+ * coordinator's own identity. Recorded so the status output shows exactly
39
+ * which inherited inputs were consulted vs. ignored (rc-9).
40
+ */
41
+ const IDENTITY_IGNORED_ENV_VARS = ['HOME', 'USERPROFILE'];
42
+ const HOST_ROOT_ENV_VARS = [
43
+ 'OPENCLAW_STATE_DIR',
44
+ 'OPENCLAW_HOME',
45
+ 'CODEX_HOME',
46
+ 'WORKBUDDY_CONFIG_DIR',
47
+ ];
48
+ /** Strip the experiment-root switch, keeping every other variable intact. */
49
+ export function stripExperimentRoot(env) {
50
+ const isSet = (name) => {
51
+ const value = env[name];
52
+ return value !== undefined && value.trim().length > 0;
53
+ };
54
+ const ignoredIdentityEnvVars = IDENTITY_IGNORED_ENV_VARS.filter(isSet);
55
+ const inheritedHostRootEnvVars = HOST_ROOT_ENV_VARS.filter(isSet);
56
+ const base = {
57
+ ignoredIdentityEnvVars,
58
+ inheritedHostRootEnvVars,
59
+ };
60
+ const raw = env[PD_EXPERIMENT_ROOT];
61
+ if (raw === undefined) {
62
+ return {
63
+ env: { ...env },
64
+ view: { inheritedExperimentRoot: false, experimentRootStripped: false, ...base },
65
+ };
66
+ }
67
+ const next = {};
68
+ for (const [key, value] of Object.entries(env)) {
69
+ if (key !== PD_EXPERIMENT_ROOT)
70
+ next[key] = value;
71
+ }
72
+ const bounded = raw.length > 120 ? `${raw.slice(0, 120)}…` : raw;
73
+ return {
74
+ env: next,
75
+ view: {
76
+ inheritedExperimentRoot: true,
77
+ experimentRootStripped: true,
78
+ ...(bounded.length > 0 ? { inheritedExperimentRootValue: bounded } : {}),
79
+ ...base,
80
+ },
81
+ };
82
+ }
83
+ /**
84
+ * The OS account record's home. `os.userInfo()` resolves via getpwuid /
85
+ * GetUserProfileDirectoryW — it never consults `HOME` or `USERPROFILE`,
86
+ * which is exactly why it is the only env-independent authority available
87
+ * in-process.
88
+ */
89
+ function resolveOsAccountHome() {
90
+ try {
91
+ const homeDir = os.userInfo().homedir;
92
+ if (typeof homeDir !== 'string' || homeDir.length === 0) {
93
+ return { ok: false, detail: 'os_user_home_unavailable' };
94
+ }
95
+ return { ok: true, homeDir };
96
+ }
97
+ catch {
98
+ return { ok: false, detail: 'os_user_home_unavailable' };
99
+ }
100
+ }
101
+ /**
102
+ * Resolve the coordinator's install identity. The home comes ONLY from the
103
+ * OS account record (or an explicitly pinned trusted home) — never from
104
+ * `HOME`/`USERPROFILE` — and `PD_EXPERIMENT_ROOT` is stripped before
105
+ * resolution. Every honored/ignored inherited input is recorded in the
106
+ * environment view. Any inability to determine a trusted identity is a
107
+ * structured refusal, never a downgrade to an env-derived or experimental
108
+ * directory.
109
+ */
110
+ export function resolveCoordinatorInstallIdentity(env = process.env, options = {}) {
111
+ const { env: stripped, view } = stripExperimentRoot(env);
112
+ const homeSource = options.trustedHomeDir !== undefined ? 'injected' : 'os.userInfo()';
113
+ let homeDir;
114
+ if (options.trustedHomeDir !== undefined) {
115
+ homeDir = options.trustedHomeDir;
116
+ }
117
+ else {
118
+ const osHome = resolveOsAccountHome();
119
+ if (!osHome.ok) {
120
+ return {
121
+ ok: false,
122
+ reason: `install_identity_refused:${osHome.detail}`,
123
+ nextAction: 'Cannot determine the production install identity: the OS account record has no home directory. ' +
124
+ 'Run the coordinator as a real OS user with a valid home, or reinstall PD with `npx create-principles-disciple`.',
125
+ };
126
+ }
127
+ ({ homeDir } = osHome);
128
+ }
129
+ if (!path.isAbsolute(homeDir)) {
130
+ return {
131
+ ok: false,
132
+ reason: 'install_identity_refused:home_not_absolute',
133
+ nextAction: 'Cannot determine the production install identity: the trusted home is not an absolute path. ' +
134
+ 'Fix the OS account home directory, or reinstall PD with `npx create-principles-disciple`.',
135
+ };
136
+ }
137
+ // HOME/USERPROFILE are deliberately NOT removed from `stripped`: the env is
138
+ // also consulted for host-root overrides (P1-2), and the trusted home is
139
+ // passed explicitly so the vars can never steer identity.
140
+ const resolution = resolvePdHome({ env: stripped, homeDir });
141
+ if (!resolution.ok) {
142
+ return {
143
+ ok: false,
144
+ reason: `install_identity_refused:${resolution.reason}`,
145
+ nextAction: resolution.nextAction,
146
+ };
147
+ }
148
+ return {
149
+ ok: true,
150
+ identity: {
151
+ pdHome: resolution.pdHome,
152
+ homeDir: resolution.homeDir,
153
+ homeSource,
154
+ manifestPath: path.join(resolution.pdHome, 'install.json'),
155
+ activeRecordPath: path.join(resolution.pdHome, 'active.json'),
156
+ hostRoots: {
157
+ openclawHome: resolution.openclawHome,
158
+ codexHome: resolution.codexHome,
159
+ workbuddyConfigDir: resolution.workbuddyConfigDir,
160
+ },
161
+ mode: 'production',
162
+ environment: view,
163
+ },
164
+ };
165
+ }
166
+ //# sourceMappingURL=install-identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-identity.js","sourceRoot":"","sources":["../../../src/services/service-host/install-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AA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AAC;YAC7D,SAAS,EAAE;gBACT,YAAY,EAAE,UAAU,CAAC,YAAY;gBACrC,SAAS,EAAE,UAAU,CAAC,SAAS;gBAC/B,kBAAkB,EAAE,UAAU,CAAC,kBAAkB;aAClD;YACD,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,IAAI;SAClB;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * A lock older than this is treated as a crashed holder. A legitimate
3
+ * run-once (bounded cycles, Phase 2 per-workspace timeouts) must stay well
4
+ * below this window; the dry-run of Phase 1 finishes in seconds.
5
+ */
6
+ export declare const SERVICE_RUN_LOCK_STALE_MS: number;
7
+ /** The one lock file per install: `<pdHome>/service/service-run.lock`. */
8
+ export declare function serviceRunLockPath(pdHome: string): string;
9
+ export interface ServiceRunLockHandle {
10
+ readonly lockPath: string;
11
+ /** Random per-acquisition token; identifies THIS holder inside the body. */
12
+ readonly token: string;
13
+ /** The exact body we wrote; release and re-verification check it. */
14
+ readonly body: string;
15
+ }
16
+ export type AcquireServiceRunLockResult = {
17
+ ok: true;
18
+ handle: ServiceRunLockHandle;
19
+ staleTakenOver: boolean;
20
+ } | {
21
+ ok: false;
22
+ kind: 'held';
23
+ holderBodyHash: string;
24
+ } | {
25
+ ok: false;
26
+ kind: 'corrupt';
27
+ detail: string;
28
+ } | {
29
+ ok: false;
30
+ kind: 'unwritable';
31
+ detail: string;
32
+ };
33
+ /**
34
+ * Holder-liveness verdict. 'alive' includes EPERM-observable processes
35
+ * (exists, we just can't signal it). 'unknown' means the platform could not
36
+ * produce a reliable verdict — takeover must fail CLOSED on it.
37
+ */
38
+ export type HolderLiveness = 'alive' | 'dead' | 'unknown';
39
+ /**
40
+ * Deterministic injection points inside the arbitrated takeover section so
41
+ * multi-process tests can interleave contenders without random sleeps.
42
+ * Called synchronously INSIDE the arbitration transaction — a contender
43
+ * parked here still holds the gate, which is exactly what the tests need to
44
+ * prove: nobody else can even evaluate the lock meanwhile.
45
+ * A thrown error aborts the takeover fail-closed (transaction rolled back).
46
+ */
47
+ export type ServiceRunLockTakeoverPhase = 'mutex-acquired' | 'stale-verified' | 'lock-removed';
48
+ export interface ServiceRunLockProbes {
49
+ /**
50
+ * Liveness probe for the PID recorded in a stale lock body. Default:
51
+ * `process.kill(pid, 0)` semantics (alive / ESRCH→dead / EPERM→alive /
52
+ * anything else→unknown). Tests inject fakes; the contract is that an
53
+ * inconclusive answer MUST yield 'unknown' (fail-closed), never 'dead'.
54
+ */
55
+ readonly processAlive?: (pid: number) => HolderLiveness;
56
+ /**
57
+ * Synchronization hook for deterministic takeover-interleaving tests.
58
+ * Invoked once per phase inside the arbitration transaction; production
59
+ * passes nothing.
60
+ */
61
+ readonly takeoverSync?: (phase: ServiceRunLockTakeoverPhase) => void;
62
+ /**
63
+ * Deterministic test seam: force the gate transaction's END to fail after
64
+ * the acquire body ran — exercises the orphan-lock compensation path
65
+ * (§P0). Production never sets it.
66
+ */
67
+ readonly gateEndFailure?: boolean;
68
+ }
69
+ /**
70
+ * Structured lock-file read outcome (P0 round 6): a missing file and an
71
+ * existing-but-unreadable file are different facts and the release path
72
+ * MUST distinguish them — EACCES/EPERM/EIO/EISDIR are degraded evidence,
73
+ * never `not_owned`.
74
+ */
75
+ export type LockBodyRead = {
76
+ readonly kind: 'readable';
77
+ readonly body: string;
78
+ } | {
79
+ readonly kind: 'absent';
80
+ } | {
81
+ readonly kind: 'unreadable';
82
+ readonly detail: string;
83
+ };
84
+ export declare function readLockBodyStatus(lockPath: string): LockBodyRead;
85
+ /** True when the lock file still carries OUR body (mid-run ownership re-check). */
86
+ export declare function holdsServiceRunLock(handle: ServiceRunLockHandle): boolean;
87
+ /**
88
+ * Acquire the install-level single-instance run lock. Every decision —
89
+ * evaluate, stale takeover, create — runs inside the arbitration gate
90
+ * (§P1-4 round 4), immediate verdicts, no wait loop (`already_running`
91
+ * semantics, §8.2). A stale takeover additionally requires the recorded
92
+ * holder PID to be demonstrably DEAD; a live, unknown or unverifiable
93
+ * holder is NEVER taken over, and the verify→delete→create sequence is
94
+ * serialized by the same transaction that a second contender's BEGIN
95
+ * cannot enter.
96
+ */
97
+ export declare function acquireServiceRunLock(pdHome: string, options?: {
98
+ staleMs?: number;
99
+ probes?: ServiceRunLockProbes;
100
+ }): AcquireServiceRunLockResult;
101
+ /**
102
+ * Structured release outcome (§三): a release can never be silent.
103
+ * - `released` — our lock was verified and unlinked under the gate;
104
+ * - `not_owned` — the lock is gone or already another holder's;
105
+ * never an error, and never deletes a foreign body;
106
+ * - `failed_busy` — the arbiter stayed busy through the bounded retry;
107
+ * - `failed_unwritable` — the gate/transaction itself failed.
108
+ */
109
+ export type ReleaseServiceRunLockResult = 'released' | 'not_owned' | 'failed_busy' | 'failed_unwritable';
110
+ export interface ReleaseServiceRunLockOptions {
111
+ /** Deterministic test seam: force the release transaction's end to fail. */
112
+ readonly injectEndFailure?: boolean;
113
+ /** Hook invoked once inside the release transaction (deterministic tests). */
114
+ readonly insideTxn?: () => void;
115
+ /**
116
+ * Deterministic test seam: replace the lock-file read inside the
117
+ * release transaction (default: the real classified read). Lets tests
118
+ * reproduce EACCES/EPERM/EIO on every platform without depending on OS
119
+ * permission behavior — production never sets it.
120
+ */
121
+ readonly readBody?: (lockPath: string) => LockBodyRead;
122
+ }
123
+ /**
124
+ * Ownership-checked release under the SAME arbitration gate: verify the
125
+ * lock body is OURS and unlink it inside one transaction — a true
126
+ * compare-and-delete, so the file a foreign holder just created can never
127
+ * be removed by our late release (P1-4). The release gets its own bounded
128
+ * retry (`RELEASE_BUSY_TIMEOUT_MS` × `RELEASE_MAX_ATTEMPTS`) independent of
129
+ * acquire's zero-wait policy, but NEVER bypasses the gate to unlink: a gate
130
+ * failure leaves the lock in place and reports it — the leftover carries
131
+ * our own PID, which the next contender recovers on death evidence.
132
+ */
133
+ export declare function releaseServiceRunLock(handle: ServiceRunLockHandle, options?: ReleaseServiceRunLockOptions): ReleaseServiceRunLockResult;
134
+ //# sourceMappingURL=service-run-lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-run-lock.d.ts","sourceRoot":"","sources":["../../../../src/services/service-host/locking/service-run-lock.ts"],"names":[],"mappings":"AA2FA;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,QAAiB,CAAC;AAcxD,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEzD;AAWD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,qEAAqE;IACrE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,2BAA2B,GACnC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,oBAAoB,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAAE,GACnE;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtD;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,MAAM,2BAA2B,GACnC,gBAAgB,GAChB,gBAAgB,GAChB,cAAc,CAAC;AAEnB,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,cAAc,CAAC;IACxD;;;;OAIG;IACH,QAAQ,CAAC,YAAY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