create-principles-disciple 1.152.3 → 1.152.5

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 (198) hide show
  1. package/_release/product-identity.json +2 -2
  2. package/console/dist/server/config/pd-config-store.js +9 -3
  3. package/console/dist/server/index.js +5 -1
  4. package/console/dist/server/models/AdaptiveActivationConsoleModel.js +3 -1
  5. package/console/dist/server/models/ApprovalsConsoleModel.d.ts +6 -0
  6. package/console/dist/server/models/ApprovalsConsoleModel.js +3 -0
  7. package/console/dist/server/models/ApprovalsGroupedConsoleModel.d.ts +21 -1
  8. package/console/dist/server/models/ApprovalsGroupedConsoleModel.js +28 -2
  9. package/console/dist/server/models/IntentDecisionModel.d.ts +6 -1
  10. package/console/dist/server/models/IntentDecisionModel.js +17 -9
  11. package/console/dist/server/routes/approvals.js +7 -0
  12. package/console/dist/server/routes/config.js +172 -0
  13. package/console/dist/server/routes/intent-decisions.js +19 -1
  14. package/console/dist/web/assets/app.css +65 -35
  15. package/console/dist/web/assets/app.js +32 -32
  16. package/core/dist/runtime/activation/activation-types.d.ts +6 -0
  17. package/core/dist/runtime/activation/activation-types.d.ts.map +1 -1
  18. package/core/dist/runtime/activation/activation-types.js.map +1 -1
  19. package/core/dist/runtime/activation/index.d.ts +2 -1
  20. package/core/dist/runtime/activation/index.d.ts.map +1 -1
  21. package/core/dist/runtime/activation/index.js +1 -1
  22. package/core/dist/runtime/activation/index.js.map +1 -1
  23. package/core/dist/runtime/activation/ledger-identity.d.ts +8 -0
  24. package/core/dist/runtime/activation/ledger-identity.d.ts.map +1 -1
  25. package/core/dist/runtime/activation/ledger-identity.js +20 -1
  26. package/core/dist/runtime/activation/ledger-identity.js.map +1 -1
  27. package/core/dist/runtime/activation/sqlite-approval-store.d.ts +18 -0
  28. package/core/dist/runtime/activation/sqlite-approval-store.d.ts.map +1 -1
  29. package/core/dist/runtime/activation/sqlite-approval-store.js +146 -20
  30. package/core/dist/runtime/activation/sqlite-approval-store.js.map +1 -1
  31. package/core/dist/runtime/adapter/artificer-l2-adapter.d.ts.map +1 -1
  32. package/core/dist/runtime/adapter/artificer-l2-adapter.js +11 -4
  33. package/core/dist/runtime/adapter/artificer-l2-adapter.js.map +1 -1
  34. package/core/dist/runtime/adapter/l2-agent-loop-adapter.d.ts.map +1 -1
  35. package/core/dist/runtime/adapter/l2-agent-loop-adapter.js +11 -4
  36. package/core/dist/runtime/adapter/l2-agent-loop-adapter.js.map +1 -1
  37. package/core/dist/runtime/adapter/pi-ai-catalog.d.ts +42 -0
  38. package/core/dist/runtime/adapter/pi-ai-catalog.d.ts.map +1 -1
  39. package/core/dist/runtime/adapter/pi-ai-catalog.js +68 -0
  40. package/core/dist/runtime/adapter/pi-ai-catalog.js.map +1 -1
  41. package/core/dist/runtime/adapter/pi-ai-connection-probe.d.ts +45 -0
  42. package/core/dist/runtime/adapter/pi-ai-connection-probe.d.ts.map +1 -0
  43. package/core/dist/runtime/adapter/pi-ai-connection-probe.js +321 -0
  44. package/core/dist/runtime/adapter/pi-ai-connection-probe.js.map +1 -0
  45. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts +18 -1
  46. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
  47. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js +14 -7
  48. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js.map +1 -1
  49. package/core/dist/runtime/config/index.d.ts +2 -0
  50. package/core/dist/runtime/config/index.d.ts.map +1 -1
  51. package/core/dist/runtime/config/index.js +1 -0
  52. package/core/dist/runtime/config/index.js.map +1 -1
  53. package/core/dist/runtime/config/pd-config-redaction.d.ts.map +1 -1
  54. package/core/dist/runtime/config/pd-config-redaction.js +4 -0
  55. package/core/dist/runtime/config/pd-config-redaction.js.map +1 -1
  56. package/core/dist/runtime/config/pd-config-types.d.ts +5 -0
  57. package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
  58. package/core/dist/runtime/config/pd-config-types.js.map +1 -1
  59. package/core/dist/runtime/config/pd-credentials.d.ts +105 -0
  60. package/core/dist/runtime/config/pd-credentials.d.ts.map +1 -0
  61. package/core/dist/runtime/config/pd-credentials.js +409 -0
  62. package/core/dist/runtime/config/pd-credentials.js.map +1 -0
  63. package/core/dist/runtime/diagnostician/diag-rootcause-output.d.ts +13 -2
  64. package/core/dist/runtime/diagnostician/diag-rootcause-output.d.ts.map +1 -1
  65. package/core/dist/runtime/diagnostician/diag-rootcause-output.js.map +1 -1
  66. package/core/dist/runtime/diagnostician-output.d.ts +1 -1
  67. package/core/dist/runtime/diagnostician-output.d.ts.map +1 -1
  68. package/core/dist/runtime/diagnostician-output.js +2 -2
  69. package/core/dist/runtime/diagnostician-output.js.map +1 -1
  70. package/core/dist/runtime/index.d.ts +5 -2
  71. package/core/dist/runtime/index.d.ts.map +1 -1
  72. package/core/dist/runtime/index.js +11 -1
  73. package/core/dist/runtime/index.js.map +1 -1
  74. package/core/dist/runtime/intent/index.d.ts +2 -0
  75. package/core/dist/runtime/intent/index.d.ts.map +1 -1
  76. package/core/dist/runtime/intent/index.js +2 -0
  77. package/core/dist/runtime/intent/index.js.map +1 -1
  78. package/core/dist/runtime/intent/intent-decision-record.d.ts +51 -3
  79. package/core/dist/runtime/intent/intent-decision-record.d.ts.map +1 -1
  80. package/core/dist/runtime/intent/intent-snapshot.d.ts +104 -0
  81. package/core/dist/runtime/intent/intent-snapshot.d.ts.map +1 -0
  82. package/core/dist/runtime/intent/intent-snapshot.js +164 -0
  83. package/core/dist/runtime/intent/intent-snapshot.js.map +1 -0
  84. package/core/dist/runtime/intent/strategic-conflict-gate.d.ts +70 -0
  85. package/core/dist/runtime/intent/strategic-conflict-gate.d.ts.map +1 -0
  86. package/core/dist/runtime/intent/strategic-conflict-gate.js +148 -0
  87. package/core/dist/runtime/intent/strategic-conflict-gate.js.map +1 -0
  88. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts +41 -1
  89. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
  90. package/core/dist/runtime/internalization/diag-rootcause-runner.js +189 -42
  91. package/core/dist/runtime/internalization/diag-rootcause-runner.js.map +1 -1
  92. package/core/dist/runtime/internalization/diag-router-runner.d.ts.map +1 -1
  93. package/core/dist/runtime/internalization/diag-router-runner.js +10 -0
  94. package/core/dist/runtime/internalization/diag-router-runner.js.map +1 -1
  95. package/core/dist/runtime/internalization/dreamer-prompt-builder.d.ts.map +1 -1
  96. package/core/dist/runtime/internalization/dreamer-prompt-builder.js +3 -0
  97. package/core/dist/runtime/internalization/dreamer-prompt-builder.js.map +1 -1
  98. package/core/dist/runtime/internalization/formation-context.d.ts +54 -0
  99. package/core/dist/runtime/internalization/formation-context.d.ts.map +1 -1
  100. package/core/dist/runtime/internalization/formation-context.js +135 -3
  101. package/core/dist/runtime/internalization/formation-context.js.map +1 -1
  102. package/core/dist/runtime/internalization/index.d.ts +2 -2
  103. package/core/dist/runtime/internalization/index.d.ts.map +1 -1
  104. package/core/dist/runtime/internalization/index.js +1 -1
  105. package/core/dist/runtime/internalization/index.js.map +1 -1
  106. package/core/dist/runtime/internalization/intent-contract.d.ts +107 -0
  107. package/core/dist/runtime/internalization/intent-contract.d.ts.map +1 -1
  108. package/core/dist/runtime/internalization/intent-contract.js +315 -4
  109. package/core/dist/runtime/internalization/intent-contract.js.map +1 -1
  110. package/core/dist/runtime/internalization/peer-runner-contracts.d.ts +8 -0
  111. package/core/dist/runtime/internalization/peer-runner-contracts.d.ts.map +1 -1
  112. package/core/dist/runtime/internalization/peer-runner-contracts.js.map +1 -1
  113. package/core/dist/runtime/internalization/philosopher-prompt-builder.d.ts +22 -1
  114. package/core/dist/runtime/internalization/philosopher-prompt-builder.d.ts.map +1 -1
  115. package/core/dist/runtime/internalization/philosopher-prompt-builder.js +22 -3
  116. package/core/dist/runtime/internalization/philosopher-prompt-builder.js.map +1 -1
  117. package/core/dist/runtime/internalization/philosopher-runner.d.ts +15 -0
  118. package/core/dist/runtime/internalization/philosopher-runner.d.ts.map +1 -1
  119. package/core/dist/runtime/internalization/philosopher-runner.js +73 -1
  120. package/core/dist/runtime/internalization/philosopher-runner.js.map +1 -1
  121. package/core/dist/runtime/internalization/pitask-metadata.d.ts +32 -0
  122. package/core/dist/runtime/internalization/pitask-metadata.d.ts.map +1 -1
  123. package/core/dist/runtime/internalization/pitask-metadata.js +44 -0
  124. package/core/dist/runtime/internalization/pitask-metadata.js.map +1 -1
  125. package/core/dist/runtime/internalization/scribe-output.d.ts +21 -0
  126. package/core/dist/runtime/internalization/scribe-output.d.ts.map +1 -1
  127. package/core/dist/runtime/internalization/scribe-output.js +125 -2
  128. package/core/dist/runtime/internalization/scribe-output.js.map +1 -1
  129. package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts +26 -1
  130. package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts.map +1 -1
  131. package/core/dist/runtime/internalization/scribe-prompt-builder.js +33 -3
  132. package/core/dist/runtime/internalization/scribe-prompt-builder.js.map +1 -1
  133. package/core/dist/runtime/internalization/scribe-runner.d.ts +32 -2
  134. package/core/dist/runtime/internalization/scribe-runner.d.ts.map +1 -1
  135. package/core/dist/runtime/internalization/scribe-runner.js +105 -7
  136. package/core/dist/runtime/internalization/scribe-runner.js.map +1 -1
  137. package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.d.ts +7 -0
  138. package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.d.ts.map +1 -1
  139. package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.js +7 -1
  140. package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.js.map +1 -1
  141. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.d.ts +2 -2
  142. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.d.ts.map +1 -1
  143. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.js +285 -35
  144. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.js.map +1 -1
  145. package/core/dist/runtime/store/sqlite-connection.d.ts.map +1 -1
  146. package/core/dist/runtime/store/sqlite-connection.js +38 -3
  147. package/core/dist/runtime/store/sqlite-connection.js.map +1 -1
  148. package/core/dist/telemetry-event.d.ts +2 -2
  149. package/core/dist/telemetry-event.d.ts.map +1 -1
  150. package/core/dist/telemetry-event.js +9 -0
  151. package/core/dist/telemetry-event.js.map +1 -1
  152. package/core/package.json +1 -1
  153. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  154. package/dist/installers/codex-host-installer.js +9 -12
  155. package/dist/installers/codex-host-installer.js.map +1 -1
  156. package/dist/update/release-metadata-publisher.d.ts +3 -1
  157. package/dist/update/release-metadata-publisher.d.ts.map +1 -1
  158. package/dist/update/release-metadata-publisher.js +33 -2
  159. package/dist/update/release-metadata-publisher.js.map +1 -1
  160. package/dist/update/trust-metadata.d.ts +21 -0
  161. package/dist/update/trust-metadata.d.ts.map +1 -1
  162. package/dist/update/trust-metadata.js +192 -4
  163. package/dist/update/trust-metadata.js.map +1 -1
  164. package/host-runtime/dist/adaptive-priority-provider.d.ts +1 -1
  165. package/host-runtime/dist/adaptive-priority-provider.js +4 -3
  166. package/host-runtime/dist/adaptive-selection.d.ts +1 -1
  167. package/host-runtime/dist/adaptive-selection.js +2 -1
  168. package/host-runtime/dist/signal-classifier.js +4 -4
  169. package/host-runtime/package.json +1 -1
  170. package/install-layout/dist/mcp-binding-contract.js +4 -15
  171. package/install-layout/package.json +1 -1
  172. package/package.json +3 -3
  173. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  174. package/pd-cli/dist/commands/pain-retry.js +6 -4
  175. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  176. package/pd-cli/dist/commands/runtime-internalization-run-once.js +1 -1
  177. package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
  178. package/pd-cli/dist/commands/runtime-internalization-run-rulehost.d.ts.map +1 -1
  179. package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js +5 -5
  180. package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js.map +1 -1
  181. package/pd-cli/dist/commands/runtime.js +6 -6
  182. package/pd-cli/dist/commands/runtime.js.map +1 -1
  183. package/pd-cli/dist/services/config-doctor.d.ts.map +1 -1
  184. package/pd-cli/dist/services/config-doctor.js +5 -4
  185. package/pd-cli/dist/services/config-doctor.js.map +1 -1
  186. package/pd-cli/dist/services/runtime-adapter-resolver.d.ts.map +1 -1
  187. package/pd-cli/dist/services/runtime-adapter-resolver.js +5 -5
  188. package/pd-cli/dist/services/runtime-adapter-resolver.js.map +1 -1
  189. package/pd-cli/package.json +1 -1
  190. package/plugin/dist/bundle.js +521 -497
  191. package/release-manager/dist/installers/codex-host-installer.js +9 -12
  192. package/release-manager/dist/update/trust-metadata.js +192 -4
  193. package/release-manager/package.json +1 -1
  194. package/dist/installers/mcp-binding-shape-mirror.d.ts +0 -27
  195. package/dist/installers/mcp-binding-shape-mirror.d.ts.map +0 -1
  196. package/dist/installers/mcp-binding-shape-mirror.js +0 -105
  197. package/dist/installers/mcp-binding-shape-mirror.js.map +0 -1
  198. package/release-manager/dist/installers/mcp-binding-shape-mirror.js +0 -105
@@ -30,7 +30,7 @@ import * as os from 'os';
30
30
  import { createRequire } from 'module';
31
31
  import { pathToFileURL } from 'url';
32
32
  import { isNpmDependencyResolutionEnabled } from '../installer.js';
33
- import { isSameMcpBindingPath, validateMcpBindingShape } from './mcp-binding-shape-mirror.js';
33
+ import { isSameMcpBindingPath, validateMcpBinding } from '@principles/install-layout';
34
34
  import { getPdRuntimeDir } from '../mvp-config.js';
35
35
  // NOTE (PRI-625 review round 3 / PRI-669 gate): this installer ships as the
36
36
  // self-contained npx package — @principles/core is NOT in its dependencies,
@@ -508,17 +508,14 @@ function isMcpBindingHealthy(pluginRoot, runtimeDir, pin) {
508
508
  catch {
509
509
  return false;
510
510
  }
511
- // Use the SAME shape gate as the launcher. The declaration lives in
512
- // @principles/install-layout, but the packaged installer must keep loading
513
- // against the PUBLISHED install-layout (registry-parity smoke, PRI-669/RF-02)
514
- // and a normal PR cannot raise the version floor — so this is the pinned
515
- // mirror, kept identical to the shared validator by
516
- // mcp-binding-shape-mirror-parity.test.ts. A binding the launcher would
517
- // refuse ON SHAPE — workspaceDir/serverEntry missing, a relative path, or a
518
- // non-canonical serverEntry — must never count as healthy, or setup is
519
- // skipped and the launcher stays dead on binding_workspace_invalid /
520
- // binding_server_entry_invalid / server_entry_not_canonical.
521
- const verdict = validateMcpBindingShape(binding, 'codex', process.platform);
511
+ // Use the launcher's own shape gate: the shared @principles/install-layout
512
+ // declaration, which the installer's published dependency floor now carries.
513
+ // A binding the launcher would refuse ON SHAPE — workspaceDir/serverEntry
514
+ // missing, a relative path, or a non-canonical serverEntry — must never count
515
+ // as healthy, or setup is skipped and the launcher stays dead on
516
+ // binding_workspace_invalid / binding_server_entry_invalid /
517
+ // server_entry_not_canonical.
518
+ const verdict = validateMcpBinding(binding, 'codex', process.platform);
522
519
  if (!verdict.ok)
523
520
  return false;
524
521
  // Installer-only context the shape contract cannot know: the binding must
@@ -1,4 +1,10 @@
1
1
  import { Updater } from 'tuf-js';
2
+ // tuf-js publishes no `exports` map, so these are the only reachable paths to
3
+ // the classes its own loader matches on: `Updater#loadRoot` treats a root
4
+ // probe as "absent" ONLY for a `DownloadHTTPError` whose statusCode is 403/404,
5
+ // and every other error is rethrown (PRI-1219).
6
+ import { DownloadHTTPError } from 'tuf-js/dist/error.js';
7
+ import { DefaultFetcher } from 'tuf-js/dist/fetcher.js';
2
8
  export class ReleaseTrustError extends Error {
3
9
  code;
4
10
  nextAction;
@@ -9,6 +15,165 @@ export class ReleaseTrustError extends Error {
9
15
  this.nextAction = options.nextAction;
10
16
  }
11
17
  }
18
+ /**
19
+ * TUF client workflow 5.3.3 makes every refresh probe `<current+1>.root.json`
20
+ * and defines ONLY 403/404 as "the trusted root is already the newest one".
21
+ * A carrier that answers a non-existent object with 5xx therefore fails the
22
+ * whole refresh even though the signed chain is intact (PRI-1219: GitHub Pages
23
+ * served `503 / Server: Varnish` for `2.root.json`, and every update check on
24
+ * a healthy 2.8.5 install reported a trust failure that never happened).
25
+ *
26
+ * A persistent 5xx on that OPTIONAL probe carries no information about whether
27
+ * a newer root exists, so it is read as "no newer root" here. The root that
28
+ * stays pinned is the one the install ALREADY trusts, so this never widens what
29
+ * is trusted — but it DEFERS a rotation instead of evaluating it, and the two
30
+ * rotation shapes behave differently:
31
+ * - rotation to a key the held root does not name still fails closed: tuf-js
32
+ * rejects the new timestamp/snapshot/targets signatures;
33
+ * - a version-only rotation, or one that revokes a key while keeping the
34
+ * signing key, is NOT detected here — the held root keeps accepting the
35
+ * signatures it names until the carrier answers the probe again.
36
+ * That gap is why every suppression is reported on the resolved target through
37
+ * `retainedTrustAnchor` instead of disappearing.
38
+ *
39
+ * A transient 5xx is not evidence of an outage either, so the default fetcher
40
+ * retries a bounded number of times before the probe is read as absent or the
41
+ * failure is reported.
42
+ */
43
+ const ROOT_ROTATION_PROBE_PATTERN = /\/\d+\.root\.json$/;
44
+ const TRUST_FETCH_RETRIES = 2;
45
+ const TRUST_FETCH_MIN_TIMEOUT_MS = 250;
46
+ const TRUST_FETCH_MAX_TIMEOUT_MS = 2_000;
47
+ function isServerErrorStatus(statusCode) {
48
+ return statusCode >= 500 && statusCode <= 599;
49
+ }
50
+ function isRootRotationProbe(url) {
51
+ return ROOT_ROTATION_PROBE_PATTERN.test(url);
52
+ }
53
+ function describeMetadataObject(url) {
54
+ const name = url.slice(url.lastIndexOf('/') + 1);
55
+ if (/^\d+\.root\.json$/.test(name))
56
+ return 'trusted-root rotation probe';
57
+ if (name === 'timestamp.json')
58
+ return 'timestamp document';
59
+ if (name === 'snapshot.json')
60
+ return 'snapshot document';
61
+ if (name === 'targets.json')
62
+ return 'targets document';
63
+ return `metadata object ${name}`;
64
+ }
65
+ /**
66
+ * Fetcher used by every TUF refresh in this module unless a caller injects
67
+ * its own. Wraps tuf-js's default fetcher (bounded retry for transient
68
+ * delivery faults) and applies the root-probe rule above.
69
+ */
70
+ class ResilientTrustFetcher {
71
+ inner;
72
+ failure;
73
+ // Deliberately NOT reset per download: it describes a policy decision that
74
+ // applies to the whole refresh, so it must survive to the success path.
75
+ suppressedRootProbe;
76
+ constructor(inner) {
77
+ // No timeout is configured on purpose: an existing install's check
78
+ // behaviour must not change beyond the retry/root-probe policy.
79
+ this.inner = inner ?? new DefaultFetcher({
80
+ retry: {
81
+ retries: TRUST_FETCH_RETRIES,
82
+ minTimeout: TRUST_FETCH_MIN_TIMEOUT_MS,
83
+ maxTimeout: TRUST_FETCH_MAX_TIMEOUT_MS,
84
+ },
85
+ });
86
+ }
87
+ get lastDownloadFailure() {
88
+ return this.failure;
89
+ }
90
+ get retainedRootProbe() {
91
+ return this.suppressedRootProbe;
92
+ }
93
+ async downloadBytes(url, maxLength) {
94
+ return this.guard(url, () => this.inner.downloadBytes(url, maxLength));
95
+ }
96
+ async downloadFile(url, maxLength, handler) {
97
+ return this.guard(url, () => this.inner.downloadFile(url, maxLength, handler));
98
+ }
99
+ async guard(url, download) {
100
+ this.failure = undefined;
101
+ try {
102
+ return await download();
103
+ }
104
+ catch (error) {
105
+ this.failure = {
106
+ url,
107
+ statusCode: error instanceof DownloadHTTPError ? error.statusCode : undefined,
108
+ };
109
+ if (error instanceof DownloadHTTPError
110
+ && isServerErrorStatus(error.statusCode)
111
+ && isRootRotationProbe(url)) {
112
+ this.suppressedRootProbe = this.failure;
113
+ // Rethrown as the "absent" status `loadRoot` breaks on. The message
114
+ // names the real status so a log never loses the cause.
115
+ throw new DownloadHTTPError(`HTTP ${error.statusCode} for ${url} — no newer trusted root could be confirmed, keeping the installed root`, 404);
116
+ }
117
+ throw error;
118
+ }
119
+ }
120
+ }
121
+ /**
122
+ * Not exported: a caller-built fetcher would be created OUTSIDE
123
+ * `resolveTrustedReleaseTarget`, whose success path is what reports a retained
124
+ * trust anchor, so its suppressions would silently vanish. Callers that need
125
+ * their own fetcher pass one through `options.fetcher` and accept the reduced
126
+ * diagnosis.
127
+ */
128
+ function createTrustMetadataFetcher() {
129
+ return new ResilientTrustFetcher();
130
+ }
131
+ /**
132
+ * Flattens an error and its `cause` chain. Node's `fetch` reports a transport
133
+ * fault as `TypeError: fetch failed` and puts the actionable text
134
+ * (`connect ECONNREFUSED …`, `getaddrinfo ENOTFOUND …`) one level down, so the
135
+ * top-level message alone is useless to an Owner.
136
+ */
137
+ function describeErrorChain(error) {
138
+ const messages = [];
139
+ let current = error;
140
+ for (let depth = 0; depth < 4; depth += 1) {
141
+ if (current === undefined || current === null)
142
+ break;
143
+ const message = current instanceof Error ? current.message : String(current);
144
+ if (message.length > 0 && !messages.includes(message))
145
+ messages.push(message);
146
+ current = current instanceof Error ? current.cause : undefined;
147
+ }
148
+ return messages.length > 0 ? messages.join(' → ') : String(error);
149
+ }
150
+ /**
151
+ * Turns a failed refresh into an Owner-facing diagnosis. A download fault must
152
+ * never be reported as "could not be verified against the trusted root": that
153
+ * wording sent the reporter of PRI-1219 chasing a trust-root problem (and a
154
+ * VPN) while the metadata carrier was returning 503.
155
+ */
156
+ function describeRefreshFailure(error, failure) {
157
+ const cause = describeErrorChain(error);
158
+ const detail = cause.length > 300 ? `${cause.slice(0, 297)}...` : cause;
159
+ if (failure !== undefined) {
160
+ const object = describeMetadataObject(failure.url);
161
+ // A transport failure has no status code. Say so AND keep the underlying
162
+ // message: "no HTTP response" alone would hide a DNS/TLS/socket error that
163
+ // the Owner needs to tell a dead network apart from a dead repository.
164
+ const status = failure.statusCode === undefined
165
+ ? `no HTTP response (${detail})`
166
+ : `HTTP ${failure.statusCode}`;
167
+ return {
168
+ message: `Release metadata refresh failed while downloading the ${object}: ${status} from ${failure.url}. The signed chain could not be fully evaluated — this is a delivery failure on the metadata carrier, not a signature or trust-root failure.`,
169
+ nextAction: `Retry the update check. If the metadata carrier keeps failing for ${failure.url}, the release repository is unhealthy and needs repair; re-pinning the trust root would not help.`,
170
+ };
171
+ }
172
+ return {
173
+ message: `Release metadata could not be verified against the trusted root: ${detail}`,
174
+ nextAction: 'Do not install this release. Check the signed release repository and retry after the metadata issue is resolved.',
175
+ };
176
+ }
12
177
  function isNonEmptyString(value) {
13
178
  return typeof value === 'string' && value.trim().length > 0;
14
179
  }
@@ -43,6 +208,25 @@ function readArtifactSha256(hashes) {
43
208
  }
44
209
  return sha256.toLowerCase();
45
210
  }
211
+ /**
212
+ * Reports a suppressed root-rotation probe on the SUCCESS path. Absent when the
213
+ * caller injected its own fetcher (no suppression is observable there).
214
+ */
215
+ function retainedAnchorReport(fetcher) {
216
+ if (!(fetcher instanceof ResilientTrustFetcher))
217
+ return {};
218
+ const probe = fetcher.retainedRootProbe;
219
+ if (probe === undefined || probe.statusCode === undefined)
220
+ return {};
221
+ return {
222
+ retainedTrustAnchor: {
223
+ probeUrl: probe.url,
224
+ statusCode: probe.statusCode,
225
+ message: `The ${describeMetadataObject(probe.url)} answered HTTP ${probe.statusCode}, so the installed trusted root was kept without checking for a newer one. This release is still verified against that root, but a root rotation or key revocation published meanwhile has NOT been applied.`,
226
+ nextAction: `Repair the metadata carrier so ${probe.url} answers 403/404 when no newer root exists. Until then, keep publishing under the installed root and do not rely on root rotation reaching existing installs.`,
227
+ },
228
+ };
229
+ }
46
230
  /**
47
231
  * Resolves a release target only after the official TUF client verifies the
48
232
  * trusted-root → timestamp → snapshot → targets metadata chain.
@@ -60,20 +244,23 @@ export async function resolveTrustedReleaseTarget(options) {
60
244
  });
61
245
  }
62
246
  let target;
247
+ const fetcher = options.fetcher ?? createTrustMetadataFetcher();
63
248
  try {
64
249
  const updater = new Updater({
65
250
  metadataDir: options.metadataDir,
66
251
  metadataBaseUrl: options.metadataBaseUrl,
67
- fetcher: options.fetcher,
252
+ fetcher,
68
253
  });
69
254
  await updater.refresh();
70
255
  target = await updater.getTargetInfo(options.targetPath);
71
256
  }
72
257
  catch (error) {
258
+ const failure = fetcher instanceof ResilientTrustFetcher ? fetcher.lastDownloadFailure : undefined;
259
+ const diagnosis = describeRefreshFailure(error, failure);
73
260
  throw new ReleaseTrustError({
74
261
  code: 'metadata_refresh_failed',
75
- message: 'Release metadata could not be verified against the trusted root.',
76
- nextAction: 'Do not install this release. Check the signed release repository and retry after the metadata issue is resolved.',
262
+ message: diagnosis.message,
263
+ nextAction: diagnosis.nextAction,
77
264
  cause: error,
78
265
  });
79
266
  }
@@ -99,6 +286,7 @@ export async function resolveTrustedReleaseTarget(options) {
99
286
  platform: identity.platform,
100
287
  releaseId: identity.releaseId,
101
288
  targetPath: target.path,
289
+ ...retainedAnchorReport(fetcher),
102
290
  };
103
291
  }
104
292
  function destinationDirOf(destinationPath) {
@@ -128,7 +316,7 @@ export async function downloadTrustedReleasePayload(options) {
128
316
  metadataDir: options.metadataDir,
129
317
  metadataBaseUrl: options.metadataBaseUrl,
130
318
  targetBaseUrl: `${options.metadataBaseUrl.replace(/\/+$/, '')}/targets`,
131
- fetcher: options.fetcher,
319
+ fetcher: options.fetcher ?? createTrustMetadataFetcher(),
132
320
  });
133
321
  await updater.refresh();
134
322
  const target = await updater.getTargetInfo(options.targetPath);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-principles-disciple",
3
- "version": "1.152.3",
3
+ "version": "1.152.5",
4
4
  "description": "Interactive CLI installer for Principles Disciple OpenClaw plugin",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,27 +0,0 @@
1
- declare const MCP_BINDING_HOSTS: readonly ['codex', 'openclaw', 'workbuddy'];
2
- type McpBindingHost = (typeof MCP_BINDING_HOSTS)[number];
3
- /** The subset of the shared verdict the installer actually consumes. */
4
- export type PinnedMcpBindingVerdict = {
5
- readonly ok: true;
6
- readonly binding: {
7
- readonly workspaceDir: string;
8
- readonly runtimeDir: string;
9
- readonly serverEntry: string;
10
- readonly versions: {
11
- readonly mcpServer: string;
12
- readonly core?: string;
13
- };
14
- };
15
- } | {
16
- readonly ok: false;
17
- readonly reason: string;
18
- };
19
- /** Mirrors the shared `isSameMcpBindingPath` — see the SAME-SOURCE POINTER above. */
20
- export declare function isSameMcpBindingPath(left: string, right: string, platform: string): boolean;
21
- /**
22
- * Validate the binding SHAPE (and the canonical-entry rule) exactly as the
23
- * launcher and `validateMcpBinding` do. Filesystem facts stay outside.
24
- */
25
- export declare function validateMcpBindingShape(raw: unknown, expectedHost: McpBindingHost, platform: string): PinnedMcpBindingVerdict;
26
- export {};
27
- //# sourceMappingURL=mcp-binding-shape-mirror.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-binding-shape-mirror.d.ts","sourceRoot":"","sources":["../../src/installers/mcp-binding-shape-mirror.ts"],"names":[],"mappings":"AA8BA,QAAA,MAAM,iBAAiB,YAAI,OAAO,EAAE,UAAU,EAAE,WAAW,CAAU,CAAC;AACtE,KAAK,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAYzD,wEAAwE;AACxE,MAAM,MAAM,uBAAuB,GAC/B;IACE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,OAAO,EAAE;QAChB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;QAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,QAAQ,EAAE;YAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;KAC3E,CAAC;CACH,GACD;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAoBpD,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAI3F;AAMD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,uBAAuB,CAiC7H"}
@@ -1,105 +0,0 @@
1
- /**
2
- * PINNED MIRROR of `@principles/install-layout`'s `validateMcpBinding`.
3
- *
4
- * Why a mirror instead of a runtime import: the packaged installer dist is
5
- * installed from the npm registry, so it must keep loading against the
6
- * PUBLISHED @principles/install-layout (registry-parity smoke, PRI-669/RF-02).
7
- * A normal PR may not raise the dependency floor (release-intent guard
8
- * N-version), so a brand-new export cannot be imported here at runtime — the
9
- * published package does not carry it yet.
10
- *
11
- * This is NOT a second declaration and NOT a looser gate. The declaration
12
- * lives in `@principles/install-layout` (`mcp-binding-contract.ts`); this file
13
- * mirrors it verbatim, and `mcp-binding-shape-mirror-parity.test.ts` pins the
14
- * two to identical verdicts (ok + reason) over
15
- * `MCP_BINDING_HOSTS × MCP_BINDING_FIXTURES`. A new reason code, a reordered
16
- * check or a relaxed comparison on either side turns that test red.
17
- *
18
- * SAME-SOURCE POINTER — the authoritative declaration is
19
- * packages/install-layout/src/mcp-binding-contract.ts
20
- * The two files MUST change together, in the same commit. Retiring this mirror
21
- * (restoring the single implementation) is tracked by PRI-1191 and is blocked
22
- * until the export is published to the registry AND the installer's
23
- * install-layout dependency floor reaches that version.
24
- *
25
- * Same discipline as the WorkBuddy plugin-state mirror (2026-11-08).
26
- */
27
- import * as path from 'node:path';
28
- const MCP_BINDING_SCHEMA_VERSION = 'pd.mcp-binding.v1';
29
- const MCP_BINDING_HOSTS = ['codex', 'openclaw', 'workbuddy'];
30
- const MCP_BINDING_SERVER_ENTRY_SEGMENTS = {
31
- codex: ['node_modules', '@principles', 'pd-mcp-server', 'dist', 'index.js'],
32
- openclaw: ['pd-mcp-server', 'dist', 'index.js'],
33
- workbuddy: ['pd-mcp-server', 'dist', 'index.js'],
34
- };
35
- function getCanonicalMcpServerEntry(host, runtimeDir) {
36
- return path.join(runtimeDir, ...MCP_BINDING_SERVER_ENTRY_SEGMENTS[host]);
37
- }
38
- const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
39
- function isRecord(value) {
40
- return typeof value === 'object' && value !== null && !Array.isArray(value);
41
- }
42
- function isAbsolutePath(value) {
43
- return typeof value === 'string' && path.isAbsolute(value);
44
- }
45
- function isMcpBindingHost(value) {
46
- return typeof value === 'string' && MCP_BINDING_HOSTS.includes(value);
47
- }
48
- function isSemverVersion(value) {
49
- return typeof value === 'string' && SEMVER.test(value);
50
- }
51
- /** Mirrors the shared `isSameMcpBindingPath` — see the SAME-SOURCE POINTER above. */
52
- export function isSameMcpBindingPath(left, right, platform) {
53
- const a = path.resolve(left);
54
- const b = path.resolve(right);
55
- return platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b;
56
- }
57
- function reject(reason) {
58
- return { ok: false, reason };
59
- }
60
- /**
61
- * Validate the binding SHAPE (and the canonical-entry rule) exactly as the
62
- * launcher and `validateMcpBinding` do. Filesystem facts stay outside.
63
- */
64
- export function validateMcpBindingShape(raw, expectedHost, platform) {
65
- if (!isRecord(raw))
66
- return reject('binding_invalid');
67
- if (raw.schemaVersion !== MCP_BINDING_SCHEMA_VERSION) {
68
- // rc-8: untrusted value reaches host logs; keep the launcher's exact shape.
69
- const schemaKind = typeof raw.schemaVersion === 'string'
70
- ? raw.schemaVersion.replace(/[^A-Za-z0-9._-]/g, '').slice(0, 60)
71
- : 'non-string';
72
- return reject(`binding_schema_unsupported:${schemaKind}`);
73
- }
74
- if (!isMcpBindingHost(raw.host))
75
- return reject('binding_host_invalid');
76
- if (raw.host !== expectedHost)
77
- return reject(`binding_host_mismatch:${raw.host}!=${expectedHost}`);
78
- if (!isAbsolutePath(raw.workspaceDir))
79
- return reject('binding_workspace_invalid');
80
- if (!isAbsolutePath(raw.runtimeDir))
81
- return reject('binding_runtime_dir_invalid');
82
- if (!isAbsolutePath(raw.serverEntry))
83
- return reject('binding_server_entry_invalid');
84
- const { versions } = raw;
85
- if (!isRecord(versions) || !isSemverVersion(versions.mcpServer))
86
- return reject('binding_versions_invalid');
87
- const canonicalEntry = getCanonicalMcpServerEntry(expectedHost, raw.runtimeDir);
88
- if (!isSameMcpBindingPath(raw.serverEntry, canonicalEntry, platform)) {
89
- return reject(`server_entry_not_canonical:${expectedHost}`);
90
- }
91
- const { mcpServer } = versions;
92
- return {
93
- ok: true,
94
- binding: {
95
- workspaceDir: raw.workspaceDir,
96
- runtimeDir: raw.runtimeDir,
97
- serverEntry: raw.serverEntry,
98
- versions: {
99
- mcpServer,
100
- ...(typeof versions.core === 'string' ? { core: versions.core } : {}),
101
- },
102
- },
103
- };
104
- }
105
- //# sourceMappingURL=mcp-binding-shape-mirror.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-binding-shape-mirror.js","sourceRoot":"","sources":["../../src/installers/mcp-binding-shape-mirror.ts"],"names":[],"mappings":"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"}
@@ -1,105 +0,0 @@
1
- /**
2
- * PINNED MIRROR of `@principles/install-layout`'s `validateMcpBinding`.
3
- *
4
- * Why a mirror instead of a runtime import: the packaged installer dist is
5
- * installed from the npm registry, so it must keep loading against the
6
- * PUBLISHED @principles/install-layout (registry-parity smoke, PRI-669/RF-02).
7
- * A normal PR may not raise the dependency floor (release-intent guard
8
- * N-version), so a brand-new export cannot be imported here at runtime — the
9
- * published package does not carry it yet.
10
- *
11
- * This is NOT a second declaration and NOT a looser gate. The declaration
12
- * lives in `@principles/install-layout` (`mcp-binding-contract.ts`); this file
13
- * mirrors it verbatim, and `mcp-binding-shape-mirror-parity.test.ts` pins the
14
- * two to identical verdicts (ok + reason) over
15
- * `MCP_BINDING_HOSTS × MCP_BINDING_FIXTURES`. A new reason code, a reordered
16
- * check or a relaxed comparison on either side turns that test red.
17
- *
18
- * SAME-SOURCE POINTER — the authoritative declaration is
19
- * packages/install-layout/src/mcp-binding-contract.ts
20
- * The two files MUST change together, in the same commit. Retiring this mirror
21
- * (restoring the single implementation) is tracked by PRI-1191 and is blocked
22
- * until the export is published to the registry AND the installer's
23
- * install-layout dependency floor reaches that version.
24
- *
25
- * Same discipline as the WorkBuddy plugin-state mirror (2026-11-08).
26
- */
27
- import * as path from 'node:path';
28
- const MCP_BINDING_SCHEMA_VERSION = 'pd.mcp-binding.v1';
29
- const MCP_BINDING_HOSTS = ['codex', 'openclaw', 'workbuddy'];
30
- const MCP_BINDING_SERVER_ENTRY_SEGMENTS = {
31
- codex: ['node_modules', '@principles', 'pd-mcp-server', 'dist', 'index.js'],
32
- openclaw: ['pd-mcp-server', 'dist', 'index.js'],
33
- workbuddy: ['pd-mcp-server', 'dist', 'index.js'],
34
- };
35
- function getCanonicalMcpServerEntry(host, runtimeDir) {
36
- return path.join(runtimeDir, ...MCP_BINDING_SERVER_ENTRY_SEGMENTS[host]);
37
- }
38
- const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
39
- function isRecord(value) {
40
- return typeof value === 'object' && value !== null && !Array.isArray(value);
41
- }
42
- function isAbsolutePath(value) {
43
- return typeof value === 'string' && path.isAbsolute(value);
44
- }
45
- function isMcpBindingHost(value) {
46
- return typeof value === 'string' && MCP_BINDING_HOSTS.includes(value);
47
- }
48
- function isSemverVersion(value) {
49
- return typeof value === 'string' && SEMVER.test(value);
50
- }
51
- /** Mirrors the shared `isSameMcpBindingPath` — see the SAME-SOURCE POINTER above. */
52
- export function isSameMcpBindingPath(left, right, platform) {
53
- const a = path.resolve(left);
54
- const b = path.resolve(right);
55
- return platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b;
56
- }
57
- function reject(reason) {
58
- return { ok: false, reason };
59
- }
60
- /**
61
- * Validate the binding SHAPE (and the canonical-entry rule) exactly as the
62
- * launcher and `validateMcpBinding` do. Filesystem facts stay outside.
63
- */
64
- export function validateMcpBindingShape(raw, expectedHost, platform) {
65
- if (!isRecord(raw))
66
- return reject('binding_invalid');
67
- if (raw.schemaVersion !== MCP_BINDING_SCHEMA_VERSION) {
68
- // rc-8: untrusted value reaches host logs; keep the launcher's exact shape.
69
- const schemaKind = typeof raw.schemaVersion === 'string'
70
- ? raw.schemaVersion.replace(/[^A-Za-z0-9._-]/g, '').slice(0, 60)
71
- : 'non-string';
72
- return reject(`binding_schema_unsupported:${schemaKind}`);
73
- }
74
- if (!isMcpBindingHost(raw.host))
75
- return reject('binding_host_invalid');
76
- if (raw.host !== expectedHost)
77
- return reject(`binding_host_mismatch:${raw.host}!=${expectedHost}`);
78
- if (!isAbsolutePath(raw.workspaceDir))
79
- return reject('binding_workspace_invalid');
80
- if (!isAbsolutePath(raw.runtimeDir))
81
- return reject('binding_runtime_dir_invalid');
82
- if (!isAbsolutePath(raw.serverEntry))
83
- return reject('binding_server_entry_invalid');
84
- const { versions } = raw;
85
- if (!isRecord(versions) || !isSemverVersion(versions.mcpServer))
86
- return reject('binding_versions_invalid');
87
- const canonicalEntry = getCanonicalMcpServerEntry(expectedHost, raw.runtimeDir);
88
- if (!isSameMcpBindingPath(raw.serverEntry, canonicalEntry, platform)) {
89
- return reject(`server_entry_not_canonical:${expectedHost}`);
90
- }
91
- const { mcpServer } = versions;
92
- return {
93
- ok: true,
94
- binding: {
95
- workspaceDir: raw.workspaceDir,
96
- runtimeDir: raw.runtimeDir,
97
- serverEntry: raw.serverEntry,
98
- versions: {
99
- mcpServer,
100
- ...(typeof versions.core === 'string' ? { core: versions.core } : {}),
101
- },
102
- },
103
- };
104
- }
105
- //# sourceMappingURL=mcp-binding-shape-mirror.js.map