@amalgm/core 0.1.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 (87) hide show
  1. package/PURPOSE.md +94 -0
  2. package/README.md +30 -0
  3. package/dist/adapters/index.d.ts +13 -0
  4. package/dist/adapters/index.d.ts.map +1 -0
  5. package/dist/adapters/index.js +11 -0
  6. package/dist/adapters/index.js.map +1 -0
  7. package/dist/identity/auth-records.d.ts +147 -0
  8. package/dist/identity/auth-records.d.ts.map +1 -0
  9. package/dist/identity/auth-records.js +354 -0
  10. package/dist/identity/auth-records.js.map +1 -0
  11. package/dist/identity/ids.d.ts +57 -0
  12. package/dist/identity/ids.d.ts.map +1 -0
  13. package/dist/identity/ids.js +80 -0
  14. package/dist/identity/ids.js.map +1 -0
  15. package/dist/identity/index.d.ts +14 -0
  16. package/dist/identity/index.d.ts.map +1 -0
  17. package/dist/identity/index.js +14 -0
  18. package/dist/identity/index.js.map +1 -0
  19. package/dist/identity/labels.d.ts +115 -0
  20. package/dist/identity/labels.d.ts.map +1 -0
  21. package/dist/identity/labels.js +154 -0
  22. package/dist/identity/labels.js.map +1 -0
  23. package/dist/identity/layout.d.ts +188 -0
  24. package/dist/identity/layout.d.ts.map +1 -0
  25. package/dist/identity/layout.js +233 -0
  26. package/dist/identity/layout.js.map +1 -0
  27. package/dist/identity/ports.d.ts +31 -0
  28. package/dist/identity/ports.d.ts.map +1 -0
  29. package/dist/identity/ports.js +9 -0
  30. package/dist/identity/ports.js.map +1 -0
  31. package/dist/identity/product-state.d.ts +49 -0
  32. package/dist/identity/product-state.d.ts.map +1 -0
  33. package/dist/identity/product-state.js +55 -0
  34. package/dist/identity/product-state.js.map +1 -0
  35. package/dist/index.d.ts +19 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +19 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/supervision/app-health.d.ts +148 -0
  40. package/dist/supervision/app-health.d.ts.map +1 -0
  41. package/dist/supervision/app-health.js +165 -0
  42. package/dist/supervision/app-health.js.map +1 -0
  43. package/dist/supervision/app-restart.d.ts +105 -0
  44. package/dist/supervision/app-restart.d.ts.map +1 -0
  45. package/dist/supervision/app-restart.js +97 -0
  46. package/dist/supervision/app-restart.js.map +1 -0
  47. package/dist/supervision/health.d.ts +218 -0
  48. package/dist/supervision/health.d.ts.map +1 -0
  49. package/dist/supervision/health.js +227 -0
  50. package/dist/supervision/health.js.map +1 -0
  51. package/dist/supervision/index.d.ts +17 -0
  52. package/dist/supervision/index.d.ts.map +1 -0
  53. package/dist/supervision/index.js +17 -0
  54. package/dist/supervision/index.js.map +1 -0
  55. package/dist/supervision/service-registration.d.ts +343 -0
  56. package/dist/supervision/service-registration.d.ts.map +1 -0
  57. package/dist/supervision/service-registration.js +543 -0
  58. package/dist/supervision/service-registration.js.map +1 -0
  59. package/dist/supervision/update.d.ts +231 -0
  60. package/dist/supervision/update.d.ts.map +1 -0
  61. package/dist/supervision/update.js +336 -0
  62. package/dist/supervision/update.js.map +1 -0
  63. package/dist/transport/admission.d.ts +235 -0
  64. package/dist/transport/admission.d.ts.map +1 -0
  65. package/dist/transport/admission.js +313 -0
  66. package/dist/transport/admission.js.map +1 -0
  67. package/dist/transport/auth.d.ts +232 -0
  68. package/dist/transport/auth.d.ts.map +1 -0
  69. package/dist/transport/auth.js +266 -0
  70. package/dist/transport/auth.js.map +1 -0
  71. package/dist/transport/index.d.ts +21 -0
  72. package/dist/transport/index.d.ts.map +1 -0
  73. package/dist/transport/index.js +21 -0
  74. package/dist/transport/index.js.map +1 -0
  75. package/dist/transport/ingress.d.ts +94 -0
  76. package/dist/transport/ingress.d.ts.map +1 -0
  77. package/dist/transport/ingress.js +171 -0
  78. package/dist/transport/ingress.js.map +1 -0
  79. package/dist/transport/routing.d.ts +235 -0
  80. package/dist/transport/routing.d.ts.map +1 -0
  81. package/dist/transport/routing.js +288 -0
  82. package/dist/transport/routing.js.map +1 -0
  83. package/dist/transport/shipped-routes.d.ts +21 -0
  84. package/dist/transport/shipped-routes.d.ts.map +1 -0
  85. package/dist/transport/shipped-routes.js +53 -0
  86. package/dist/transport/shipped-routes.js.map +1 -0
  87. package/package.json +51 -0
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Updater laws — version comparison, npm install shape, and the
3
+ * auto-update manager's state vocabulary.
4
+ *
5
+ * The host runs npm, reads disks, and restarts processes; this module owns
6
+ * every decision and every contract string (axiom 8): the semver rules the
7
+ * updater lives by, the exact npm argv and environment, the error messages
8
+ * surfaces match on, and the idle-gating reasons the UI displays.
9
+ *
10
+ * Engine sources (production until cutover, axiom 9):
11
+ * `packages/amalgm/lib/updater.js` and `packages/amalgm/lib/supervisor.js`
12
+ * (auto-update manager), with the label→tag rule imported from
13
+ * `identity/labels.ts` — one definition (axiom 2).
14
+ */
15
+ export interface Semver {
16
+ readonly major: number;
17
+ readonly minor: number;
18
+ readonly patch: number;
19
+ readonly prerelease: string;
20
+ }
21
+ /**
22
+ * Engine `updater.js:21-31`. Notable exactness: a leading `v` is stripped;
23
+ * non-numeric components collapse to 0 (`Number(x) || 0`); the prerelease
24
+ * is whatever follows the FIRST hyphen up to the second — `split('-', 2)`
25
+ * truncates `1.0.0-alpha-beta` to prerelease `alpha`.
26
+ */
27
+ export declare function parseSemver(value: unknown): Semver;
28
+ /**
29
+ * Engine `updater.js:33-55`. The prerelease rules, each load-bearing:
30
+ *
31
+ * 1. Both absent → equal.
32
+ * 2. An ABSENT prerelease WINS: `1.0.0` > `1.0.0-rc.1` — a release
33
+ * outranks every prerelease of the same core version.
34
+ * 3. Dot-separated parts compare left to right; when one side runs out of
35
+ * parts, the SHORTER side is smaller (`1.0.0-rc` < `1.0.0-rc.1`).
36
+ * 4. Two numeric parts compare numerically (`rc.2` < `rc.10`).
37
+ * 5. A numeric part is smaller than an alphanumeric part:
38
+ * `1.0.0-2` < `1.0.0-alpha`.
39
+ * 6. Two alphanumeric parts compare lexically (`>` / `<` on strings).
40
+ */
41
+ export declare function comparePrerelease(left: string, right: string): number;
42
+ /** Engine `updater.js:57-64`: major/minor/patch first, prerelease last. */
43
+ export declare function compareVersions(left: unknown, right: unknown): number;
44
+ /**
45
+ * Engine `updater.js:106-110`: an explicit tag/channel wins with any
46
+ * leading `@` stripped (`@canary` → `canary`); otherwise the runtime
47
+ * label's tag. The label is injected — the engine's
48
+ * `AMALGM_RUNTIME_LABEL` fallback is the host's job.
49
+ */
50
+ export declare function npmInstallTag(options: {
51
+ tag?: string | true | undefined;
52
+ channel?: string | true | undefined;
53
+ runtimeLabel: string;
54
+ }): string;
55
+ /**
56
+ * Engine `updater.js:244-249`. `AMALGM_DISABLE_AUTO_UPDATE` disables on a
57
+ * truthy value (`'1' | 'true' | 'yes' | 'on'`), `AMALGM_AUTO_UPDATE`
58
+ * disables on a falsy value (`'0' | 'false' | 'no' | 'off'`); both are
59
+ * trimmed and lowercased first. The env map is injected (axiom 6).
60
+ */
61
+ export declare function envDisablesAutoUpdate(env: Readonly<Record<string, string | undefined>>): boolean;
62
+ /** Engine `updater.js:251-254`: the `local` label never auto-updates. */
63
+ export declare function autoUpdateSupported(runtimeLabel: string): boolean;
64
+ /** Engine `updater.js:256-259`. */
65
+ export declare function shouldAutoUpdate(options: {
66
+ runtimeLabel: string;
67
+ env: Readonly<Record<string, string | undefined>>;
68
+ }): boolean;
69
+ /**
70
+ * Engine `updater.js:77-83`. npm lays out global installs as
71
+ * `<prefix>/lib/node_modules/<name>` on POSIX and
72
+ * `<prefix>/node_modules/<name>` on Windows. Walking that layout backwards
73
+ * from the package root this process runs from recovers the prefix that
74
+ * owns the running install, so updates land in the tree the service
75
+ * actually boots — not whatever prefix the inherited environment points at.
76
+ * Returns null when the root is not a global-install layout (e.g. a repo
77
+ * checkout).
78
+ *
79
+ * Purity note: the engine calls `path.resolve`; this SDK takes an
80
+ * already-absolute root and normalizes `\` to `/` (the returned prefix uses
81
+ * forward slashes — a comparison key, not a filesystem call site).
82
+ */
83
+ export declare function globalPrefixForPackageRoot(packageRoot: string): string | null;
84
+ /**
85
+ * Engine `updater.js:94-104`: exactly `['install', '-g', 'amalgm@<tag>']`,
86
+ * plus `['--prefix', prefix]` when a prefix is known. The `--prefix` flag
87
+ * outranks every npm config layer, including an inherited
88
+ * `npm_config_prefix` pointing at a tree this process does not run from.
89
+ * npm runs through cmd.exe on Windows, where a bare path with spaces would
90
+ * split — hence the quoting there. Platform is injected (axiom 6).
91
+ */
92
+ export declare function npmInstallArgs(tag: string, options?: {
93
+ npmPrefix?: string | null | undefined;
94
+ packageRoot?: string | undefined;
95
+ platform?: string | undefined;
96
+ }): string[];
97
+ /** Engine `updater.js:19`: default cache dir name under the host's tmpdir. */
98
+ export declare const NPM_UPDATE_CACHE_DIRNAME = "amalgm-npm-cache";
99
+ /**
100
+ * Engine `updater.js:112-124`: the npm environment overlay —
101
+ * `npm_config_audit: 'false'`, `npm_config_fund: 'false'`,
102
+ * `npm_config_prefer_online: 'true'`, and a cache directory resolved as
103
+ * `npm_config_cache || NPM_CONFIG_CACHE || AMALGM_NPM_UPDATE_CACHE ||
104
+ * <tmpdir>/amalgm-npm-cache`. The tmpdir is injected (axiom 6).
105
+ */
106
+ export declare function npmEnv(env: Readonly<Record<string, string | undefined>>, options: {
107
+ tmpdir: string;
108
+ }): Record<string, string | undefined>;
109
+ /** Engine `updater.js:175-178`: the detail attached to a failed npm run. */
110
+ export declare function npmFailureDetail(result: {
111
+ timedOut?: boolean | undefined;
112
+ stdout?: string | undefined;
113
+ stderr?: string | undefined;
114
+ }): string;
115
+ /**
116
+ * Engine `updater.js:187`. Byte-exact, including the trailing space when
117
+ * the detail is empty — surfaces match on this string.
118
+ */
119
+ export declare function distTagCheckFailedMessage(tag: string, detail: string): string;
120
+ /** Engine `updater.js:207`. `status` is the exit status, signal, or `'unknown'`. */
121
+ export declare function installFailedMessage(tag: string, status: string | number, detail: string): string;
122
+ /** Engine `updater.js:216`: npm answered but produced no version. */
123
+ export declare function noVersionMessage(tag: string): string;
124
+ /** Engine `updater.js:16`: the error code surfaces and the manager match on. */
125
+ export declare const UPDATE_TARGET_MISMATCH = "AMALGM_UPDATE_TARGET_MISMATCH";
126
+ export interface UpdateTargetMismatchError extends Error {
127
+ code: typeof UPDATE_TARGET_MISMATCH;
128
+ targetVersion: string;
129
+ installedVersion: string | null;
130
+ packageRoot: string;
131
+ }
132
+ /**
133
+ * Engine `updater.js:232-239`: npm reported success but the tree this
134
+ * runtime boots from still carries the old version — the update landed in a
135
+ * different npm prefix and will never take effect here. Restarting cannot
136
+ * fix it, so the manager suppresses restarts for this target (see
137
+ * `restartSuppressedDetail`). Message and `code` are byte-exact.
138
+ */
139
+ export declare function updateTargetMismatchError(input: {
140
+ tag: string;
141
+ targetVersion: string;
142
+ packageRoot: string;
143
+ installedVersion: string | null;
144
+ }): UpdateTargetMismatchError;
145
+ /**
146
+ * Engine `supervisor.js:862`: the `restart_suppressed` state's
147
+ * `last_error` when a previously-mismatched target shows up again.
148
+ */
149
+ export declare function restartSuppressedDetail(targetVersion: string, packageRootDir: string): string;
150
+ /**
151
+ * The auto-update status vocabulary (axiom 8 — exactly these ten), written
152
+ * to the auto-update state file and read by every surface.
153
+ */
154
+ export declare const AUTO_UPDATE_STATUSES: readonly ["disabled", "checking", "current", "installing", "restart_required", "critical_restart_required", "critical_restart_pending", "restart_pending", "restart_suppressed", "error"];
155
+ export type AutoUpdateStatus = (typeof AUTO_UPDATE_STATUSES)[number];
156
+ /** Engine `supervisor.js:82-87`: 15-minute checks, 60s initial delay. */
157
+ export declare const AUTO_UPDATE_POLICY: {
158
+ readonly checkIntervalMs: 900000;
159
+ readonly initialDelayMs: 60000;
160
+ readonly idlePollMs: 10000;
161
+ readonly idleTimeoutMs: 2500;
162
+ };
163
+ /**
164
+ * Env overrides and their floors (engine `supervisor.js:679,722-736`). A
165
+ * non-numeric or non-positive value falls back to the policy default; a
166
+ * numeric value is clamped up to the floor — the knobs can slow the
167
+ * updater down, never turn it into a busy loop.
168
+ */
169
+ export declare const AUTO_UPDATE_ENV_OVERRIDES: {
170
+ readonly checkIntervalMs: {
171
+ readonly envName: "AMALGM_UPDATE_CHECK_INTERVAL_MS";
172
+ readonly minimum: 60000;
173
+ };
174
+ readonly initialDelayMs: {
175
+ readonly envName: "AMALGM_UPDATE_INITIAL_DELAY_MS";
176
+ readonly minimum: 5000;
177
+ };
178
+ readonly idlePollMs: {
179
+ readonly envName: "AMALGM_UPDATE_IDLE_POLL_MS";
180
+ readonly minimum: 1000;
181
+ };
182
+ readonly idleTimeoutMs: {
183
+ readonly envName: "AMALGM_UPDATE_IDLE_TIMEOUT_MS";
184
+ readonly minimum: 500;
185
+ };
186
+ };
187
+ /**
188
+ * Engine `supervisor.js:570-574` (`numberFromEnv`), over an injected raw
189
+ * value: `Number(value)`; non-finite or `<= 0` → fallback; otherwise
190
+ * `max(minimum, value)`.
191
+ */
192
+ export declare function numberFromEnvValue(value: unknown, fallback: number, minimum?: number): number;
193
+ /** Resolve the full auto-update timing policy from an injected env map. */
194
+ export declare function resolveAutoUpdateTimings(env: Readonly<Record<string, string | undefined>>): {
195
+ checkIntervalMs: number;
196
+ initialDelayMs: number;
197
+ idlePollMs: number;
198
+ idleTimeoutMs: number;
199
+ };
200
+ /**
201
+ * Engine `supervisor.js:696-699` (`envFlag`), over an injected raw value:
202
+ * trimmed, lowercased, truthy iff in `['1', 'true', 'yes', 'on']`. Used
203
+ * for `AMALGM_SERVICE_MANAGED`, `AMALGM_UPDATE_CRITICAL`, and
204
+ * `AMALGM_AUTO_UPDATE_CRITICAL`.
205
+ */
206
+ export declare function envFlag(value: string | undefined): boolean;
207
+ /** The idle report the manager polls while waiting to restart. */
208
+ export interface RuntimeIdleStatus {
209
+ readonly idle: boolean;
210
+ readonly reason?: string | undefined;
211
+ readonly active_turns?: number | null | undefined;
212
+ readonly tempstore_count?: number | null | undefined;
213
+ readonly mcp_active?: number | null | undefined;
214
+ }
215
+ /**
216
+ * Engine `supervisor.js:766`: the `idle_blocked_reason` written when the
217
+ * runtime is not under a service manager — a restart would not come back.
218
+ */
219
+ export declare const NOT_SERVICE_MANAGED_REASON = "runtime is not service-managed";
220
+ /**
221
+ * Engine `supervisor.js:660-675`: why a pending restart is blocked, in
222
+ * precedence order and byte-exact — the UI shows these verbatim:
223
+ *
224
+ * - null when idle;
225
+ * - a probe error's own message when present;
226
+ * - `tempstore has N active turn(s)`;
227
+ * - `mcp has N active agent conversation(s)`;
228
+ * - `runtime is busy` when not idle for any other reason.
229
+ */
230
+ export declare function autoUpdateIdleBlockedReason(idle: RuntimeIdleStatus): string | null;
231
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../src/supervision/update.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAUlD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAsBrE;AAED,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAOrE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE;IACrC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACpC,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,MAAM,CAIT;AAED;;;;;GAKG;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;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,SAAI,GAAG,MAAM,CAIxF;AAED,2EAA2E;AAC3E,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GAChD;IAAE,eAAe,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAuBhG;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAE1D;AAED,kEAAkE;AAClE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAClD,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACrD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACjD;AAED;;;GAGG;AACH,eAAO,MAAM,0BAA0B,mCAAmC,CAAC;AAE3E;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAelF"}
@@ -0,0 +1,336 @@
1
+ /**
2
+ * Updater laws — version comparison, npm install shape, and the
3
+ * auto-update manager's state vocabulary.
4
+ *
5
+ * The host runs npm, reads disks, and restarts processes; this module owns
6
+ * every decision and every contract string (axiom 8): the semver rules the
7
+ * updater lives by, the exact npm argv and environment, the error messages
8
+ * surfaces match on, and the idle-gating reasons the UI displays.
9
+ *
10
+ * Engine sources (production until cutover, axiom 9):
11
+ * `packages/amalgm/lib/updater.js` and `packages/amalgm/lib/supervisor.js`
12
+ * (auto-update manager), with the label→tag rule imported from
13
+ * `identity/labels.ts` — one definition (axiom 2).
14
+ */
15
+ import { npmTagForRuntimeLabel } from '../identity/labels.js';
16
+ /**
17
+ * Engine `updater.js:21-31`. Notable exactness: a leading `v` is stripped;
18
+ * non-numeric components collapse to 0 (`Number(x) || 0`); the prerelease
19
+ * is whatever follows the FIRST hyphen up to the second — `split('-', 2)`
20
+ * truncates `1.0.0-alpha-beta` to prerelease `alpha`.
21
+ */
22
+ export function parseSemver(value) {
23
+ const raw = String(value || '').trim().replace(/^v/, '');
24
+ const [core = '', prerelease = ''] = raw.split('-', 2);
25
+ const [major = '0', minor = '0', patch = '0'] = core.split('.');
26
+ return {
27
+ major: Number(major) || 0,
28
+ minor: Number(minor) || 0,
29
+ patch: Number(patch) || 0,
30
+ prerelease,
31
+ };
32
+ }
33
+ /**
34
+ * Engine `updater.js:33-55`. The prerelease rules, each load-bearing:
35
+ *
36
+ * 1. Both absent → equal.
37
+ * 2. An ABSENT prerelease WINS: `1.0.0` > `1.0.0-rc.1` — a release
38
+ * outranks every prerelease of the same core version.
39
+ * 3. Dot-separated parts compare left to right; when one side runs out of
40
+ * parts, the SHORTER side is smaller (`1.0.0-rc` < `1.0.0-rc.1`).
41
+ * 4. Two numeric parts compare numerically (`rc.2` < `rc.10`).
42
+ * 5. A numeric part is smaller than an alphanumeric part:
43
+ * `1.0.0-2` < `1.0.0-alpha`.
44
+ * 6. Two alphanumeric parts compare lexically (`>` / `<` on strings).
45
+ */
46
+ export function comparePrerelease(left, right) {
47
+ if (!left && !right)
48
+ return 0;
49
+ if (!left)
50
+ return 1;
51
+ if (!right)
52
+ return -1;
53
+ const aParts = left.split('.');
54
+ const bParts = right.split('.');
55
+ const count = Math.max(aParts.length, bParts.length);
56
+ for (let i = 0; i < count; i += 1) {
57
+ const a = aParts[i] || '';
58
+ const b = bParts[i] || '';
59
+ if (a === b)
60
+ continue;
61
+ if (!a)
62
+ return -1;
63
+ if (!b)
64
+ return 1;
65
+ const aNum = /^\d+$/.test(a) ? Number(a) : null;
66
+ const bNum = /^\d+$/.test(b) ? Number(b) : null;
67
+ if (aNum !== null && bNum !== null)
68
+ return aNum > bNum ? 1 : -1;
69
+ if (aNum !== null && bNum === null)
70
+ return -1;
71
+ if (aNum === null && bNum !== null)
72
+ return 1;
73
+ if (a !== b)
74
+ return a > b ? 1 : -1;
75
+ }
76
+ return 0;
77
+ }
78
+ /** Engine `updater.js:57-64`: major/minor/patch first, prerelease last. */
79
+ export function compareVersions(left, right) {
80
+ const a = parseSemver(left);
81
+ const b = parseSemver(right);
82
+ for (const key of ['major', 'minor', 'patch']) {
83
+ if (a[key] !== b[key])
84
+ return a[key] > b[key] ? 1 : -1;
85
+ }
86
+ return comparePrerelease(a.prerelease, b.prerelease);
87
+ }
88
+ /**
89
+ * Engine `updater.js:106-110`: an explicit tag/channel wins with any
90
+ * leading `@` stripped (`@canary` → `canary`); otherwise the runtime
91
+ * label's tag. The label is injected — the engine's
92
+ * `AMALGM_RUNTIME_LABEL` fallback is the host's job.
93
+ */
94
+ export function npmInstallTag(options) {
95
+ const explicit = options.tag || options.channel;
96
+ if (explicit && explicit !== true)
97
+ return String(explicit).replace(/^@/, '');
98
+ return npmTagForRuntimeLabel(options.runtimeLabel);
99
+ }
100
+ /**
101
+ * Engine `updater.js:244-249`. `AMALGM_DISABLE_AUTO_UPDATE` disables on a
102
+ * truthy value (`'1' | 'true' | 'yes' | 'on'`), `AMALGM_AUTO_UPDATE`
103
+ * disables on a falsy value (`'0' | 'false' | 'no' | 'off'`); both are
104
+ * trimmed and lowercased first. The env map is injected (axiom 6).
105
+ */
106
+ export function envDisablesAutoUpdate(env) {
107
+ const disable = String(env['AMALGM_DISABLE_AUTO_UPDATE'] || '').trim().toLowerCase();
108
+ if (['1', 'true', 'yes', 'on'].includes(disable))
109
+ return true;
110
+ const auto = String(env['AMALGM_AUTO_UPDATE'] || '').trim().toLowerCase();
111
+ return ['0', 'false', 'no', 'off'].includes(auto);
112
+ }
113
+ /** Engine `updater.js:251-254`: the `local` label never auto-updates. */
114
+ export function autoUpdateSupported(runtimeLabel) {
115
+ return runtimeLabel !== 'local';
116
+ }
117
+ /** Engine `updater.js:256-259`. */
118
+ export function shouldAutoUpdate(options) {
119
+ return autoUpdateSupported(options.runtimeLabel) && !envDisablesAutoUpdate(options.env);
120
+ }
121
+ /**
122
+ * Engine `updater.js:77-83`. npm lays out global installs as
123
+ * `<prefix>/lib/node_modules/<name>` on POSIX and
124
+ * `<prefix>/node_modules/<name>` on Windows. Walking that layout backwards
125
+ * from the package root this process runs from recovers the prefix that
126
+ * owns the running install, so updates land in the tree the service
127
+ * actually boots — not whatever prefix the inherited environment points at.
128
+ * Returns null when the root is not a global-install layout (e.g. a repo
129
+ * checkout).
130
+ *
131
+ * Purity note: the engine calls `path.resolve`; this SDK takes an
132
+ * already-absolute root and normalizes `\` to `/` (the returned prefix uses
133
+ * forward slashes — a comparison key, not a filesystem call site).
134
+ */
135
+ export function globalPrefixForPackageRoot(packageRoot) {
136
+ const root = String(packageRoot).replace(/\\/g, '/').replace(/\/+$/, '');
137
+ const nodeModules = dirnamePosix(root);
138
+ if (basenamePosix(nodeModules) !== 'node_modules')
139
+ return null;
140
+ const parent = dirnamePosix(nodeModules);
141
+ return basenamePosix(parent) === 'lib' ? dirnamePosix(parent) : parent;
142
+ }
143
+ function dirnamePosix(value) {
144
+ const index = value.lastIndexOf('/');
145
+ if (index < 0)
146
+ return '.';
147
+ if (index === 0)
148
+ return '/';
149
+ return value.slice(0, index);
150
+ }
151
+ function basenamePosix(value) {
152
+ const index = value.lastIndexOf('/');
153
+ return index < 0 ? value : value.slice(index + 1);
154
+ }
155
+ /**
156
+ * Engine `updater.js:94-104`: exactly `['install', '-g', 'amalgm@<tag>']`,
157
+ * plus `['--prefix', prefix]` when a prefix is known. The `--prefix` flag
158
+ * outranks every npm config layer, including an inherited
159
+ * `npm_config_prefix` pointing at a tree this process does not run from.
160
+ * npm runs through cmd.exe on Windows, where a bare path with spaces would
161
+ * split — hence the quoting there. Platform is injected (axiom 6).
162
+ */
163
+ export function npmInstallArgs(tag, options = {}) {
164
+ const args = ['install', '-g', `amalgm@${tag}`];
165
+ const prefix = options.npmPrefix !== undefined
166
+ ? options.npmPrefix
167
+ : (options.packageRoot !== undefined ? globalPrefixForPackageRoot(options.packageRoot) : null);
168
+ if (prefix)
169
+ args.push('--prefix', options.platform === 'win32' ? `"${prefix}"` : prefix);
170
+ return args;
171
+ }
172
+ /** Engine `updater.js:19`: default cache dir name under the host's tmpdir. */
173
+ export const NPM_UPDATE_CACHE_DIRNAME = 'amalgm-npm-cache';
174
+ /**
175
+ * Engine `updater.js:112-124`: the npm environment overlay —
176
+ * `npm_config_audit: 'false'`, `npm_config_fund: 'false'`,
177
+ * `npm_config_prefer_online: 'true'`, and a cache directory resolved as
178
+ * `npm_config_cache || NPM_CONFIG_CACHE || AMALGM_NPM_UPDATE_CACHE ||
179
+ * <tmpdir>/amalgm-npm-cache`. The tmpdir is injected (axiom 6).
180
+ */
181
+ export function npmEnv(env, options) {
182
+ const safeCache = env['npm_config_cache']
183
+ || env['NPM_CONFIG_CACHE']
184
+ || env['AMALGM_NPM_UPDATE_CACHE']
185
+ || `${options.tmpdir.replace(/[\\/]+$/, '')}/${NPM_UPDATE_CACHE_DIRNAME}`;
186
+ return {
187
+ ...env,
188
+ npm_config_audit: 'false',
189
+ npm_config_fund: 'false',
190
+ npm_config_cache: safeCache,
191
+ npm_config_prefer_online: 'true',
192
+ };
193
+ }
194
+ /** Engine `updater.js:175-178`: the detail attached to a failed npm run. */
195
+ export function npmFailureDetail(result) {
196
+ if (result.timedOut)
197
+ return 'npm command timed out';
198
+ return String(result.stderr || result.stdout || '').trim();
199
+ }
200
+ /**
201
+ * Engine `updater.js:187`. Byte-exact, including the trailing space when
202
+ * the detail is empty — surfaces match on this string.
203
+ */
204
+ export function distTagCheckFailedMessage(tag, detail) {
205
+ return `Could not check npm dist-tag "${tag}". ${detail}`;
206
+ }
207
+ /** Engine `updater.js:207`. `status` is the exit status, signal, or `'unknown'`. */
208
+ export function installFailedMessage(tag, status, detail) {
209
+ return `npm install -g amalgm@${tag} failed with status ${status}${detail ? `: ${detail}` : ''}`;
210
+ }
211
+ /** Engine `updater.js:216`: npm answered but produced no version. */
212
+ export function noVersionMessage(tag) {
213
+ return `npm did not return a version for amalgm@${tag}`;
214
+ }
215
+ /** Engine `updater.js:16`: the error code surfaces and the manager match on. */
216
+ export const UPDATE_TARGET_MISMATCH = 'AMALGM_UPDATE_TARGET_MISMATCH';
217
+ /**
218
+ * Engine `updater.js:232-239`: npm reported success but the tree this
219
+ * runtime boots from still carries the old version — the update landed in a
220
+ * different npm prefix and will never take effect here. Restarting cannot
221
+ * fix it, so the manager suppresses restarts for this target (see
222
+ * `restartSuppressedDetail`). Message and `code` are byte-exact.
223
+ */
224
+ export function updateTargetMismatchError(input) {
225
+ const error = new Error(`npm reported installing amalgm@${input.tag} (${input.targetVersion}), but the install this runtime boots from at ${input.packageRoot} still carries ${input.installedVersion || 'no readable version'}. The update landed in a different npm prefix and will never take effect here.`);
226
+ error.code = UPDATE_TARGET_MISMATCH;
227
+ error.targetVersion = input.targetVersion;
228
+ error.installedVersion = input.installedVersion;
229
+ error.packageRoot = input.packageRoot;
230
+ return error;
231
+ }
232
+ /**
233
+ * Engine `supervisor.js:862`: the `restart_suppressed` state's
234
+ * `last_error` when a previously-mismatched target shows up again.
235
+ */
236
+ export function restartSuppressedDetail(targetVersion, packageRootDir) {
237
+ return `update ${targetVersion} does not apply to this install (running from ${packageRootDir}); waiting for an install that includes it`;
238
+ }
239
+ /* ------------------------------------------------------------------ *
240
+ * Auto-update manager laws (engine supervisor.js:660-938).
241
+ * ------------------------------------------------------------------ */
242
+ /**
243
+ * The auto-update status vocabulary (axiom 8 — exactly these ten), written
244
+ * to the auto-update state file and read by every surface.
245
+ */
246
+ export const AUTO_UPDATE_STATUSES = [
247
+ 'disabled',
248
+ 'checking',
249
+ 'current',
250
+ 'installing',
251
+ 'restart_required',
252
+ 'critical_restart_required',
253
+ 'critical_restart_pending',
254
+ 'restart_pending',
255
+ 'restart_suppressed',
256
+ 'error',
257
+ ];
258
+ /** Engine `supervisor.js:82-87`: 15-minute checks, 60s initial delay. */
259
+ export const AUTO_UPDATE_POLICY = {
260
+ checkIntervalMs: 900_000, // 15 * 60_000 in the engine
261
+ initialDelayMs: 60_000,
262
+ idlePollMs: 10_000,
263
+ idleTimeoutMs: 2_500,
264
+ };
265
+ /**
266
+ * Env overrides and their floors (engine `supervisor.js:679,722-736`). A
267
+ * non-numeric or non-positive value falls back to the policy default; a
268
+ * numeric value is clamped up to the floor — the knobs can slow the
269
+ * updater down, never turn it into a busy loop.
270
+ */
271
+ export const AUTO_UPDATE_ENV_OVERRIDES = {
272
+ checkIntervalMs: { envName: 'AMALGM_UPDATE_CHECK_INTERVAL_MS', minimum: 60_000 },
273
+ initialDelayMs: { envName: 'AMALGM_UPDATE_INITIAL_DELAY_MS', minimum: 5_000 },
274
+ idlePollMs: { envName: 'AMALGM_UPDATE_IDLE_POLL_MS', minimum: 1_000 },
275
+ idleTimeoutMs: { envName: 'AMALGM_UPDATE_IDLE_TIMEOUT_MS', minimum: 500 },
276
+ };
277
+ /**
278
+ * Engine `supervisor.js:570-574` (`numberFromEnv`), over an injected raw
279
+ * value: `Number(value)`; non-finite or `<= 0` → fallback; otherwise
280
+ * `max(minimum, value)`.
281
+ */
282
+ export function numberFromEnvValue(value, fallback, minimum = 0) {
283
+ const parsed = Number(value);
284
+ if (!Number.isFinite(parsed) || parsed <= 0)
285
+ return fallback;
286
+ return Math.max(minimum, parsed);
287
+ }
288
+ /** Resolve the full auto-update timing policy from an injected env map. */
289
+ export function resolveAutoUpdateTimings(env) {
290
+ return {
291
+ checkIntervalMs: numberFromEnvValue(env[AUTO_UPDATE_ENV_OVERRIDES.checkIntervalMs.envName], AUTO_UPDATE_POLICY.checkIntervalMs, AUTO_UPDATE_ENV_OVERRIDES.checkIntervalMs.minimum),
292
+ initialDelayMs: numberFromEnvValue(env[AUTO_UPDATE_ENV_OVERRIDES.initialDelayMs.envName], AUTO_UPDATE_POLICY.initialDelayMs, AUTO_UPDATE_ENV_OVERRIDES.initialDelayMs.minimum),
293
+ idlePollMs: numberFromEnvValue(env[AUTO_UPDATE_ENV_OVERRIDES.idlePollMs.envName], AUTO_UPDATE_POLICY.idlePollMs, AUTO_UPDATE_ENV_OVERRIDES.idlePollMs.minimum),
294
+ idleTimeoutMs: numberFromEnvValue(env[AUTO_UPDATE_ENV_OVERRIDES.idleTimeoutMs.envName], AUTO_UPDATE_POLICY.idleTimeoutMs, AUTO_UPDATE_ENV_OVERRIDES.idleTimeoutMs.minimum),
295
+ };
296
+ }
297
+ /**
298
+ * Engine `supervisor.js:696-699` (`envFlag`), over an injected raw value:
299
+ * trimmed, lowercased, truthy iff in `['1', 'true', 'yes', 'on']`. Used
300
+ * for `AMALGM_SERVICE_MANAGED`, `AMALGM_UPDATE_CRITICAL`, and
301
+ * `AMALGM_AUTO_UPDATE_CRITICAL`.
302
+ */
303
+ export function envFlag(value) {
304
+ return ['1', 'true', 'yes', 'on'].includes(String(value || '').trim().toLowerCase());
305
+ }
306
+ /**
307
+ * Engine `supervisor.js:766`: the `idle_blocked_reason` written when the
308
+ * runtime is not under a service manager — a restart would not come back.
309
+ */
310
+ export const NOT_SERVICE_MANAGED_REASON = 'runtime is not service-managed';
311
+ /**
312
+ * Engine `supervisor.js:660-675`: why a pending restart is blocked, in
313
+ * precedence order and byte-exact — the UI shows these verbatim:
314
+ *
315
+ * - null when idle;
316
+ * - a probe error's own message when present;
317
+ * - `tempstore has N active turn(s)`;
318
+ * - `mcp has N active agent conversation(s)`;
319
+ * - `runtime is busy` when not idle for any other reason.
320
+ */
321
+ export function autoUpdateIdleBlockedReason(idle) {
322
+ if (idle.idle)
323
+ return null;
324
+ if (idle.reason)
325
+ return idle.reason;
326
+ const tempstoreCount = Number(idle.tempstore_count ?? idle.active_turns) || 0;
327
+ if (tempstoreCount > 0) {
328
+ return `tempstore has ${tempstoreCount} active turn${tempstoreCount === 1 ? '' : 's'}`;
329
+ }
330
+ const mcpActive = Number(idle.mcp_active) || 0;
331
+ if (mcpActive > 0) {
332
+ return `mcp has ${mcpActive} active agent conversation${mcpActive === 1 ? '' : 's'}`;
333
+ }
334
+ return 'runtime is busy';
335
+ }
336
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/supervision/update.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAS9D;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACzD,MAAM,CAAC,IAAI,GAAG,EAAE,EAAE,UAAU,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACvD,MAAM,CAAC,KAAK,GAAG,GAAG,EAAE,KAAK,GAAG,GAAG,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChE,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;QACzB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;QACzB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;QACzB,UAAU;KACX,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,KAAa;IAC3D,IAAI,CAA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