@wipcomputer/wip-ldm-os 0.4.85-alpha.3 → 0.4.85-alpha.30

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 (43) hide show
  1. package/README.md +22 -2
  2. package/SKILL.md +136 -14
  3. package/bin/ldm.js +422 -75
  4. package/docs/universal-installer/SPEC.md +16 -3
  5. package/docs/universal-installer/TECHNICAL.md +4 -4
  6. package/lib/deploy.mjs +104 -20
  7. package/lib/detect.mjs +35 -4
  8. package/lib/registry-migrations.mjs +296 -0
  9. package/package.json +17 -2
  10. package/scripts/test-crc-agentid-tenant-boundary.mjs +80 -0
  11. package/scripts/test-crc-e2ee-key-persistence.mjs +150 -0
  12. package/scripts/test-crc-e2ee-session-route.mjs +129 -0
  13. package/scripts/test-crc-pair-login-flow.mjs +40 -0
  14. package/scripts/test-crc-pair-relink-audit-and-rotation.mjs +164 -0
  15. package/scripts/test-crc-pair-status-poll-token.mjs +73 -0
  16. package/scripts/test-crc-websocket-abuse-limits.mjs +128 -0
  17. package/scripts/test-install-prompt-policy.mjs +84 -0
  18. package/scripts/test-installer-skill-directory.mjs +55 -0
  19. package/scripts/test-installer-skill-dry-run-destinations.mjs +100 -0
  20. package/scripts/test-installer-target-self-update.mjs +131 -0
  21. package/scripts/test-ldm-status-concurrency.mjs +118 -0
  22. package/scripts/test-ldm-status-timeout.mjs +96 -0
  23. package/scripts/test-legacy-npm-sources-migration.mjs +460 -0
  24. package/scripts/test-readme-install-prompt.mjs +66 -0
  25. package/shared/templates/install-prompt.md +20 -2
  26. package/src/hosted-mcp/README.md +37 -0
  27. package/src/hosted-mcp/app/footer.js +74 -0
  28. package/src/hosted-mcp/app/kaleidoscope-login.html +846 -0
  29. package/src/hosted-mcp/app/pair.html +165 -57
  30. package/src/hosted-mcp/app/sprites.png +0 -0
  31. package/src/hosted-mcp/codex-relay-e2ee-registry.mjs +208 -0
  32. package/src/hosted-mcp/codex-relay-ws-abuse-limits.mjs +140 -0
  33. package/src/hosted-mcp/demo/index.html +3 -7
  34. package/src/hosted-mcp/demo/login.html +318 -20
  35. package/src/hosted-mcp/deploy.sh +308 -56
  36. package/src/hosted-mcp/docs/self-host.md +268 -0
  37. package/src/hosted-mcp/nginx/codex-relay.conf +25 -0
  38. package/src/hosted-mcp/nginx/conf.d/redact-logs.conf +60 -0
  39. package/src/hosted-mcp/nginx/mcp-oauth.conf +58 -0
  40. package/src/hosted-mcp/nginx/wip.computer.conf +25 -1
  41. package/src/hosted-mcp/scripts/audit-logs.sh +205 -0
  42. package/src/hosted-mcp/scripts/verify-deploy.sh +102 -0
  43. package/src/hosted-mcp/server.mjs +1034 -146
@@ -0,0 +1,128 @@
1
+ import { readFileSync } from "node:fs";
2
+ import assert from "node:assert/strict";
3
+ import {
4
+ CODEX_WS_CLOSE_CODES,
5
+ codexWsFrameByteLength,
6
+ createCodexWsAbuseLimitConfig,
7
+ createCodexWsConnectionGuard,
8
+ formatCodexWsLimitLog,
9
+ isCodexWsAgentDisabled,
10
+ } from "../src/hosted-mcp/codex-relay-ws-abuse-limits.mjs";
11
+
12
+ const server = readFileSync("src/hosted-mcp/server.mjs", "utf8");
13
+ const deploy = readFileSync("src/hosted-mcp/deploy.sh", "utf8");
14
+
15
+ function assertContains(source, needle, label) {
16
+ if (!source.includes(needle)) {
17
+ throw new Error(`${label} missing expected text: ${needle}`);
18
+ }
19
+ }
20
+
21
+ function assertBefore(source, first, second, label) {
22
+ const firstIndex = source.indexOf(first);
23
+ const secondIndex = firstIndex === -1 ? -1 : source.indexOf(second, firstIndex + first.length);
24
+ if (firstIndex === -1 || secondIndex === -1 || firstIndex >= secondIndex) {
25
+ throw new Error(`${label} expected "${first}" before "${second}"`);
26
+ }
27
+ }
28
+
29
+ const config = createCodexWsAbuseLimitConfig({
30
+ LDM_CODEX_WS_MAX_FRAME_BYTES: "10",
31
+ LDM_CODEX_WS_RATE_WINDOW_MS: "100",
32
+ LDM_CODEX_WS_MAX_MESSAGES_PER_WINDOW: "2",
33
+ LDM_CODEX_WS_MAX_BYTES_PER_WINDOW: "15",
34
+ LDM_CODEX_WS_MAX_BROWSER_SOCKETS_PER_THREAD: "3",
35
+ LDM_CODEX_WS_IDLE_TTL_MS: "50",
36
+ LDM_CODEX_WS_MAX_MALFORMED_FRAMES: "1",
37
+ LDM_CODEX_WS_MAX_PENDING_BYTES: "20",
38
+ LDM_CODEX_WS_KILL_SWITCH_AGENTS: "acct:blocked, acct:other",
39
+ });
40
+
41
+ assert.equal(config.maxFrameBytes, 10);
42
+ assert.equal(config.maxBrowserSocketsPerThread, 3);
43
+ assert.equal(isCodexWsAgentDisabled(config, "acct:blocked"), true);
44
+ assert.equal(isCodexWsAgentDisabled(config, "acct:allowed"), false);
45
+
46
+ let nowMs = 1_000;
47
+ const guard = createCodexWsConnectionGuard({
48
+ config,
49
+ agentId: "acct:allowed",
50
+ now: () => nowMs,
51
+ });
52
+
53
+ assert.equal(guard.observeFrame(11).code, CODEX_WS_CLOSE_CODES.oversizedFrame);
54
+ assert.equal(guard.observeFrame(5).ok, true);
55
+ assert.equal(guard.observeFrame(5).ok, true);
56
+ assert.equal(guard.observeFrame(5).reason, "message rate limit");
57
+
58
+ nowMs += 101;
59
+ const byteGuard = createCodexWsConnectionGuard({ config, agentId: "acct:allowed", now: () => nowMs });
60
+ assert.equal(byteGuard.observeFrame(8).ok, true);
61
+ assert.equal(byteGuard.observeFrame(8).reason, "byte rate limit");
62
+
63
+ const malformedGuard = createCodexWsConnectionGuard({ config, agentId: "acct:allowed", now: () => nowMs });
64
+ assert.equal(malformedGuard.observeMalformed().ok, true);
65
+ assert.equal(malformedGuard.observeMalformed().code, CODEX_WS_CLOSE_CODES.malformedFrames);
66
+
67
+ const pendingGuard = createCodexWsConnectionGuard({ config, agentId: "acct:allowed", now: () => nowMs });
68
+ assert.equal(pendingGuard.observePendingBytes(21).code, CODEX_WS_CLOSE_CODES.pendingBytes);
69
+
70
+ const idleGuard = createCodexWsConnectionGuard({ config, agentId: "acct:allowed", now: () => nowMs });
71
+ assert.equal(idleGuard.observeFrame(1).ok, true);
72
+ assert.equal(idleGuard.observeIdle(nowMs + 51).code, CODEX_WS_CLOSE_CODES.idleTimeout);
73
+
74
+ const killedGuard = createCodexWsConnectionGuard({ config, agentId: "acct:blocked", now: () => nowMs });
75
+ assert.equal(killedGuard.observeFrame(1).code, CODEX_WS_CLOSE_CODES.operatorDisabled);
76
+ assert.equal(codexWsFrameByteLength(Buffer.from("hello")), 5);
77
+ assert.match(
78
+ formatCodexWsLimitLog({
79
+ agentId: "acct:blocked",
80
+ threadId: "thread-a",
81
+ connectionId: "conn-a",
82
+ reason: "message rate limit",
83
+ }),
84
+ /reason=message rate limit agent=acct:blocked thread=thread-a conn=conn-a/,
85
+ );
86
+
87
+ assertContains(server, "import {", "server imports abuse module");
88
+ assertContains(server, "createCodexWsAbuseLimitConfig", "server configures websocket limits");
89
+ assertContains(server, "isCodexWsAgentDisabled(CODEX_WS_ABUSE_LIMITS, identity.agentId)", "server checks operator kill switch");
90
+ assertContains(server, "openBrowserSockets >= CODEX_WS_ABUSE_LIMITS.maxBrowserSocketsPerThread", "server limits browser sockets per thread");
91
+ assertContains(server, "createCodexWsConnectionGuard({", "server creates per-socket guard");
92
+ assertContains(server, "guard.observeFrame(codexWsFrameByteLength(data))", "server observes browser frame size and rate");
93
+ assertContains(server, "guard.observeMalformed()", "server observes malformed browser frames");
94
+ assertContains(server, "guard.observePendingBytes(daemonWs.bufferedAmount || 0)", "server observes pending daemon bytes");
95
+ assertContains(server, "guard.observeIdle()", "server observes idle connections");
96
+ assertContains(server, "closeCodexWsForLimit(ws, guardContext, decision)", "server closes idle sockets by limit");
97
+ assertContains(server, "closeCodexWsForLimit(ws, guardContext, frameDecision)", "server closes frame abuse");
98
+ assertContains(server, "closeCodexWsForLimit(ws, guardContext, malformedDecision)", "server closes malformed abuse");
99
+ assertContains(server, "closeCodexWsForLimit(ws, guardContext, pendingDecision)", "server closes pending byte abuse");
100
+ assertContains(server, "codex-relay-ws-abuse-limits.mjs", "deploy inventory includes abuse module");
101
+ assertContains(deploy, "add_file \"codex-relay-ws-abuse-limits.mjs\"", "deploy copies abuse module");
102
+
103
+ assertBefore(
104
+ server,
105
+ "openBrowserSockets >= CODEX_WS_ABUSE_LIMITS.maxBrowserSocketsPerThread",
106
+ "codexRelayWss.handleUpgrade(req, socket, head, (ws) => {",
107
+ "socket cap should run before websocket upgrade is accepted",
108
+ );
109
+ assertBefore(
110
+ server,
111
+ "const frameDecision = guard.observeFrame(codexWsFrameByteLength(data));",
112
+ "let text = data.toString();",
113
+ "frame limit should run before parsing or forwarding browser data",
114
+ );
115
+ assertBefore(
116
+ server,
117
+ "if (!envelope || typeof envelope !== \"object\" || Array.isArray(envelope)) {",
118
+ "const daemonWs = codexDaemons.get(identity.agentId);",
119
+ "malformed browser frames should not be forwarded",
120
+ );
121
+ assertBefore(
122
+ server,
123
+ "const pendingDecision = guard.observePendingBytes(daemonWs.bufferedAmount || 0);",
124
+ "daemonWs.send(text);",
125
+ "pending byte check should run before forwarding to daemon",
126
+ );
127
+
128
+ console.log("crc websocket abuse limit checks passed");
@@ -0,0 +1,84 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const repoRoot = fileURLToPath(new URL("..", import.meta.url));
6
+
7
+ const files = [
8
+ "README.md",
9
+ "SKILL.md",
10
+ "shared/templates/install-prompt.md",
11
+ ];
12
+
13
+ const contents = Object.fromEntries(
14
+ files.map((file) => [file, readFileSync(join(repoRoot, file), "utf8")]),
15
+ );
16
+
17
+ const failures = [];
18
+
19
+ for (const file of ["README.md", "shared/templates/install-prompt.md"]) {
20
+ const text = contents[file];
21
+ for (const phrase of [
22
+ "Use the install document and live local checks as the source of truth.",
23
+ "Do not search memory or prior notes for this install. Do not pre-load context from `MEMORY.md`, `crystal_search`, local skill dev guides, or other local memory before fetching the install document.",
24
+ "Do not run GitHub commands during this install flow. Do not run or request approval for `gh release`, `gh api`, or `gh search`.",
25
+ "If release notes are not available from local or npm metadata, say that and do not fetch them from GitHub.",
26
+ "If installed: run `ldm status`",
27
+ "check available npm tracks from the install document",
28
+ "If yes to dry run, use the selected track's dry-run path from the install document.",
29
+ "If I say install, use the selected track's install path from the install document, then run `ldm doctor`.",
30
+ "install the CLI first using the selected track's bootstrap command from the install document",
31
+ "Then run:\n`ldm init --dry-run`",
32
+ "If I say install, run:\n`ldm init`",
33
+ ]) {
34
+ if (!text.includes(phrase)) {
35
+ failures.push(`${file} missing install prompt phrase: ${phrase}`);
36
+ }
37
+ }
38
+ if (text.includes("If it is, run ldm install --dry-run")) {
39
+ failures.push(`${file} still tells installed users to start with ldm install --dry-run`);
40
+ }
41
+ }
42
+
43
+ const skill = contents["SKILL.md"];
44
+ for (const phrase of [
45
+ "Memory policy for install flows: do not consult `MEMORY.md`, do not run `crystal_search`, and do not search prior notes when this skill is invoked, including in any parallel or batched exploration step.",
46
+ "The only context sources for this install flow are `https://wip.computer/install/wip-ldm-os.txt` and the live local commands that document prescribes.",
47
+ "Read that document and run those commands. Do not pre-load other context.",
48
+ "Do not run GitHub commands during the install-state flow.",
49
+ "Do not run or request approval for `gh release list`, `gh release view`, `gh api repos/*`, `gh search`, or any other GitHub query unless the user explicitly asks for release notes.",
50
+ "npm view @wipcomputer/wip-ldm-os dist-tags --json",
51
+ "The README prompt should stay short. This install document owns the detailed track rules.",
52
+ "stable/current/latest: `ldm install --dry-run`",
53
+ "beta/latest beta: `ldm install --beta --dry-run`",
54
+ "alpha/latest alpha: `ldm install --alpha --dry-run`",
55
+ "beta/latest beta: `npm install -g @wipcomputer/wip-ldm-os@beta`",
56
+ "alpha/latest alpha: `npm install -g @wipcomputer/wip-ldm-os@alpha`",
57
+ "Use the output of `ldm status`, installed package metadata, and npm metadata.",
58
+ "Do not use GitHub commands here.",
59
+ "If npm metadata for a package does not include release notes:",
60
+ "Say \"release notes not available from local metadata.\"",
61
+ "Do not infer release-note content from package descriptions, commit messages, or repo READMEs.",
62
+ "An approval dialog is not a user request.",
63
+ ]) {
64
+ if (!skill.includes(phrase)) {
65
+ failures.push(`SKILL.md missing install policy phrase: ${phrase}`);
66
+ }
67
+ }
68
+
69
+ if (/gh release (list|view) --repo/.test(skill)) {
70
+ failures.push("SKILL.md still includes concrete gh release commands in the install flow");
71
+ }
72
+
73
+ const temporalMemoryPolicyPhrase = "your first action is " + "to fetch";
74
+ if (skill.includes(temporalMemoryPolicyPhrase)) {
75
+ failures.push("SKILL.md still uses temporal first-action memory-policy phrasing");
76
+ }
77
+
78
+ if (failures.length > 0) {
79
+ console.error("install prompt policy checks failed:");
80
+ for (const failure of failures) console.error(` - ${failure}`);
81
+ process.exit(1);
82
+ }
83
+
84
+ console.log("install-prompt-policy: LDM OS prompt and install doc agree");
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { tmpdir } from 'node:os';
5
+
6
+ const home = mkdtempSync(join(tmpdir(), 'ldm-skill-dir-home-'));
7
+ const source = mkdtempSync(join(tmpdir(), 'ldm-skill-dir-source-'));
8
+
9
+ function assert(condition, message) {
10
+ if (!condition) throw new Error(message);
11
+ }
12
+
13
+ try {
14
+ process.env.HOME = home;
15
+
16
+ for (const dir of ['.claude', '.openclaw', '.codex', '.agents']) {
17
+ mkdirSync(join(home, dir), { recursive: true });
18
+ }
19
+
20
+ const skillDir = join(source, 'skills', 'wip-ai-chat-ui');
21
+ mkdirSync(join(skillDir, 'references'), { recursive: true });
22
+ mkdirSync(join(skillDir, 'agents'), { recursive: true });
23
+ writeFileSync(join(skillDir, 'SKILL.md'), '---\nname: wip-ai-chat-ui\ndescription: "test skill"\n---\n\n# Test Skill\n');
24
+ writeFileSync(join(skillDir, 'references', 'stack.md'), '# Stack\n');
25
+ writeFileSync(join(skillDir, 'agents', 'openai.yaml'), 'display_name: "WIP AI Chat UI"\n');
26
+
27
+ const { detectInterfacesJSON } = await import('../lib/detect.mjs');
28
+ const detected = detectInterfacesJSON(source);
29
+ assert(detected.interfaceCount === 1, 'skill directory repo should expose one interface');
30
+ assert(detected.interfaces.skill?.skills?.[0]?.name === 'wip-ai-chat-ui', 'skill directory name should be detected');
31
+
32
+ const { installFromPath } = await import('../lib/deploy.mjs');
33
+ const result = await installFromPath(source);
34
+ assert(result.interfaces === 1, 'skill directory install should process one interface');
35
+
36
+ for (const target of [
37
+ join(home, '.claude', 'skills', 'wip-ai-chat-ui'),
38
+ join(home, '.openclaw', 'skills', 'wip-ai-chat-ui'),
39
+ join(home, '.codex', 'skills', 'wip-ai-chat-ui'),
40
+ join(home, '.agents', 'skills', 'wip-ai-chat-ui'),
41
+ ]) {
42
+ assert(existsSync(join(target, 'SKILL.md')), `${target} should include SKILL.md`);
43
+ assert(existsSync(join(target, 'references', 'stack.md')), `${target} should include references`);
44
+ assert(existsSync(join(target, 'agents', 'openai.yaml')), `${target} should include agents metadata`);
45
+ assert(!lstatSync(target).isSymbolicLink(), `${target} should be a deployed directory, not a symlink`);
46
+ }
47
+
48
+ const codexSkill = readFileSync(join(home, '.codex', 'skills', 'wip-ai-chat-ui', 'SKILL.md'), 'utf8');
49
+ assert(codexSkill.includes('name: wip-ai-chat-ui'), 'Codex target should contain the expected skill');
50
+
51
+ console.log('installer skill directory regression passed');
52
+ } finally {
53
+ rmSync(home, { recursive: true, force: true });
54
+ rmSync(source, { recursive: true, force: true });
55
+ }
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env node
2
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { tmpdir } from 'node:os';
5
+
6
+ const home = mkdtempSync(join(tmpdir(), 'ldm-skill-dry-run-home-'));
7
+ const source = mkdtempSync(join(tmpdir(), 'ldm-skill-dry-run-source-'));
8
+
9
+ function assert(condition, message) {
10
+ if (!condition) throw new Error(message);
11
+ }
12
+
13
+ try {
14
+ process.env.HOME = home;
15
+
16
+ for (const dir of ['.claude', '.openclaw', '.codex', '.agents']) {
17
+ mkdirSync(join(home, dir), { recursive: true });
18
+ }
19
+
20
+ const workspace = join(home, 'workspace');
21
+ mkdirSync(workspace, { recursive: true });
22
+ mkdirSync(join(home, '.ldm'), { recursive: true });
23
+ writeFileSync(join(home, '.ldm', 'config.json'), JSON.stringify({
24
+ workspace,
25
+ harnesses: {
26
+ 'claude-code': {
27
+ detected: true,
28
+ home: join(home, '.claude'),
29
+ skills: join(home, '.claude', 'skills'),
30
+ },
31
+ openclaw: {
32
+ detected: true,
33
+ home: join(home, '.openclaw'),
34
+ skills: join(home, '.openclaw', 'skills'),
35
+ },
36
+ codex: {
37
+ detected: true,
38
+ home: join(home, '.codex'),
39
+ skills: join(home, '.codex', 'skills'),
40
+ },
41
+ 'wip-agents': {
42
+ detected: true,
43
+ home: join(home, '.agents'),
44
+ skills: join(home, '.agents', 'skills'),
45
+ },
46
+ },
47
+ }, null, 2));
48
+
49
+ mkdirSync(join(source, 'references'), { recursive: true });
50
+ mkdirSync(join(source, 'agents'), { recursive: true });
51
+ writeFileSync(join(source, 'package.json'), JSON.stringify({
52
+ name: '@wipcomputer/wip-ai-chat-ui',
53
+ version: '0.1.1',
54
+ }, null, 2));
55
+ writeFileSync(join(source, 'SKILL.md'), '---\nname: wip-ai-chat-ui\ndescription: "test skill"\n---\n\n# Test Skill\n');
56
+ writeFileSync(join(source, 'references', 'stack.md'), '# Stack\n');
57
+ writeFileSync(join(source, 'agents', 'openai.yaml'), 'display_name: "WIP AI Chat UI"\n');
58
+
59
+ const { setFlags, installFromPath } = await import('../lib/deploy.mjs');
60
+
61
+ const lines = [];
62
+ const originalLog = console.log;
63
+ console.log = (...args) => lines.push(args.join(' '));
64
+
65
+ try {
66
+ setFlags({ dryRun: true, jsonOutput: false });
67
+ const result = await installFromPath(source);
68
+ assert(result.interfaces === 1, 'dry run should process one skill interface');
69
+ } finally {
70
+ console.log = originalLog;
71
+ }
72
+
73
+ const output = lines.join('\n');
74
+
75
+ for (const expected of [
76
+ 'Would copy:',
77
+ '- SKILL.md',
78
+ '- references/',
79
+ '- agents/',
80
+ 'Permanent copy:',
81
+ join(home, '.ldm', 'extensions', 'wip-ai-chat-ui', 'SKILL.md'),
82
+ join(home, '.ldm', 'extensions', 'wip-ai-chat-ui', 'references/'),
83
+ 'Agent skill targets:',
84
+ `claude-code: ${join(home, '.claude', 'skills', 'wip-ai-chat-ui')}`,
85
+ join(home, '.claude', 'skills', 'wip-ai-chat-ui', 'SKILL.md'),
86
+ `openclaw: ${join(home, '.openclaw', 'skills', 'wip-ai-chat-ui')}`,
87
+ join(home, '.openclaw', 'skills', 'wip-ai-chat-ui', 'references/'),
88
+ `codex: ${join(home, '.codex', 'skills', 'wip-ai-chat-ui')}`,
89
+ `wip-agents: ${join(home, '.agents', 'skills', 'wip-ai-chat-ui')}`,
90
+ 'Workspace docs target:',
91
+ `${join(workspace, 'settings', 'docs', 'skills', 'wip-ai-chat-ui')} (references/ only)`,
92
+ ]) {
93
+ assert(output.includes(expected), `dry-run output should include ${expected}\n\n${output}`);
94
+ }
95
+
96
+ console.log('installer skill dry-run destinations regression passed');
97
+ } finally {
98
+ rmSync(home, { recursive: true, force: true });
99
+ rmSync(source, { recursive: true, force: true });
100
+ }
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env node
2
+ import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { dirname, join } from 'node:path';
5
+ import { spawnSync } from 'node:child_process';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ const root = dirname(dirname(fileURLToPath(import.meta.url)));
9
+ const cli = readFileSync(join(root, 'bin', 'ldm.js'), 'utf8');
10
+
11
+ const helperName = 'function maybeSelfUpdateLdmCliBeforeInstall()';
12
+ const helperIdx = cli.indexOf(helperName);
13
+ if (helperIdx === -1) {
14
+ throw new Error('Missing shared LDM OS self-update preflight helper');
15
+ }
16
+
17
+ const helperBlock = cli.slice(helperIdx, cli.indexOf('// ── Dead backup trigger cleanup', helperIdx));
18
+ if (!helperBlock.includes('Dry run only: continuing with v${PKG_VERSION}.')) {
19
+ throw new Error('Self-update helper must warn on dry run without updating');
20
+ }
21
+
22
+ if (!helperBlock.includes("execSync(`npm install -g @wipcomputer/wip-ldm-os@${latest}`")) {
23
+ throw new Error('Self-update helper must update LDM OS before real installs');
24
+ }
25
+
26
+ if (!helperBlock.includes("spawnSync('ldm'")) {
27
+ throw new Error('Self-update helper must re-run the original install command without shell joining args');
28
+ }
29
+
30
+ if (helperBlock.includes('process.argv.slice(2).join')) {
31
+ throw new Error('Self-update helper must preserve argv boundaries when re-running install');
32
+ }
33
+
34
+ const cmdInstallIdx = cli.indexOf('async function cmdInstall()');
35
+ const lockIdx = cli.indexOf('acquireInstallLock()', cmdInstallIdx);
36
+ const initIdx = cli.indexOf('LDM OS not initialized. Running init first', cmdInstallIdx);
37
+ const targetIdx = cli.indexOf('// Find the target (skip flags)', cmdInstallIdx);
38
+ const preflightCallIdx = cli.indexOf('maybeSelfUpdateLdmCliBeforeInstall();', cmdInstallIdx);
39
+ if (cmdInstallIdx === -1 || targetIdx === -1 || preflightCallIdx === -1) {
40
+ throw new Error('Could not find cmdInstall self-update placement');
41
+ }
42
+
43
+ if (preflightCallIdx > lockIdx || preflightCallIdx > initIdx) {
44
+ throw new Error('Self-update preflight must run before lock acquisition and init work');
45
+ }
46
+
47
+ if (preflightCallIdx > targetIdx) {
48
+ throw new Error('Self-update preflight must run before target resolution so app installs are covered');
49
+ }
50
+
51
+ const catalogIdx = cli.indexOf('async function cmdInstallCatalog()');
52
+ const oldCatalogBlock = cli.indexOf('Self-update: check if CLI itself is outdated', catalogIdx);
53
+ const autoDetectIdx = cli.indexOf('autoDetectExtensions();', catalogIdx);
54
+ if (oldCatalogBlock !== -1 && oldCatalogBlock < autoDetectIdx) {
55
+ throw new Error('Catalog install should not own the only self-update block');
56
+ }
57
+
58
+ const tempRoot = mkdtempSync(join(tmpdir(), 'ldm-target-self-update-'));
59
+ try {
60
+ const home = join(tempRoot, 'home');
61
+ const fakeBin = join(tempRoot, 'bin');
62
+ const target = join(tempRoot, 'target skill with spaces');
63
+
64
+ mkdirSync(join(home, '.ldm'), { recursive: true });
65
+ writeFileSync(join(home, '.ldm', 'version.json'), JSON.stringify({
66
+ version: '0.0.0',
67
+ installed: new Date().toISOString(),
68
+ updated: new Date().toISOString(),
69
+ }, null, 2) + '\n');
70
+
71
+ mkdirSync(fakeBin, { recursive: true });
72
+ const fakeNpm = join(fakeBin, 'npm');
73
+ writeFileSync(fakeNpm, `#!/usr/bin/env bash
74
+ if [ "$1" = "view" ] && [ "$2" = "@wipcomputer/wip-ldm-os" ] && [ "$3" = "dist-tags.alpha" ]; then
75
+ echo "99.0.0-alpha.1"
76
+ exit 0
77
+ fi
78
+ echo "unexpected npm command: $*" >&2
79
+ exit 64
80
+ `);
81
+ chmodSync(fakeNpm, 0o755);
82
+
83
+ mkdirSync(target, { recursive: true });
84
+ writeFileSync(join(target, 'SKILL.md'), `---
85
+ name: test-target-skill
86
+ description: Test target skill for installer self-update dry-run checks.
87
+ ---
88
+
89
+ # Test Target Skill
90
+ `);
91
+
92
+ const result = spawnSync(process.execPath, [
93
+ join(root, 'bin', 'ldm.js'),
94
+ 'install',
95
+ '--alpha',
96
+ '--dry-run',
97
+ target,
98
+ ], {
99
+ cwd: root,
100
+ encoding: 'utf8',
101
+ env: {
102
+ ...process.env,
103
+ HOME: home,
104
+ PATH: `${fakeBin}:${process.env.PATH || ''}`,
105
+ },
106
+ });
107
+
108
+ if (result.status !== 0) {
109
+ throw new Error(`Runtime dry-run exited ${result.status}\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`);
110
+ }
111
+
112
+ if (!result.stdout.includes('LDM OS CLI v')) {
113
+ throw new Error(`Runtime dry-run did not print the LDM OS skew warning\nstdout:\n${result.stdout}`);
114
+ }
115
+
116
+ if (!result.stdout.includes('-> v99.0.0-alpha.1 (alpha track) is available.')) {
117
+ throw new Error(`Runtime dry-run did not include the selected alpha track version\nstdout:\n${result.stdout}`);
118
+ }
119
+
120
+ if (!result.stdout.includes('Dry run only: continuing with v')) {
121
+ throw new Error(`Runtime dry-run did not say it would continue without updating\nstdout:\n${result.stdout}`);
122
+ }
123
+
124
+ if (!result.stdout.includes('Installing: target skill with spaces (dry run)')) {
125
+ throw new Error(`Runtime dry-run did not continue to the targeted install preview\nstdout:\n${result.stdout}`);
126
+ }
127
+ } finally {
128
+ rmSync(tempRoot, { recursive: true, force: true });
129
+ }
130
+
131
+ console.log('targeted install self-update regression checks passed');
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { createServer } from 'node:http';
4
+ import { tmpdir } from 'node:os';
5
+ import { dirname, join } from 'node:path';
6
+ import { spawn } from 'node:child_process';
7
+ import { fileURLToPath } from 'node:url';
8
+
9
+ const root = dirname(dirname(fileURLToPath(import.meta.url)));
10
+ const tempRoot = mkdtempSync(join(tmpdir(), 'ldm-status-concurrency-'));
11
+ const sourceVersion = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')).version;
12
+
13
+ function assert(condition, message) {
14
+ if (!condition) throw new Error(message);
15
+ }
16
+
17
+ function listen(server) {
18
+ return new Promise((resolve) => {
19
+ server.listen(0, '127.0.0.1', () => resolve(server.address()));
20
+ });
21
+ }
22
+
23
+ function createRegistryServer(delayMs) {
24
+ let active = 0;
25
+ let maxActive = 0;
26
+ const server = createServer((_req, res) => {
27
+ active += 1;
28
+ maxActive = Math.max(maxActive, active);
29
+ setTimeout(() => {
30
+ res.setHeader('content-type', 'application/json');
31
+ res.end(JSON.stringify({ 'dist-tags': { latest: '1.0.0' } }));
32
+ active -= 1;
33
+ }, delayMs);
34
+ });
35
+ return { server, getMaxActive: () => maxActive };
36
+ }
37
+
38
+ function writeFixture(home) {
39
+ const extensions = join(home, '.ldm', 'extensions');
40
+ mkdirSync(extensions, { recursive: true });
41
+ writeFileSync(join(home, '.ldm', 'version.json'), JSON.stringify({
42
+ version: '0.0.0-test',
43
+ installed: '2026-05-12T00:00:00.000Z',
44
+ updated: '2026-05-12T00:00:00.000Z',
45
+ }, null, 2) + '\n');
46
+
47
+ const registry = { extensions: {} };
48
+ for (let i = 1; i <= 8; i += 1) {
49
+ registry.extensions[`ext-${i}`] = {
50
+ source: { npm: `ext-${i}` },
51
+ installed: { version: '1.0.0' },
52
+ };
53
+ }
54
+ writeFileSync(join(extensions, 'registry.json'), JSON.stringify(registry, null, 2) + '\n');
55
+ }
56
+
57
+ function runStatus({ concurrency, registryUrl, home }) {
58
+ return new Promise((resolve) => {
59
+ const child = spawn(process.execPath, [join(root, 'bin', 'ldm.js'), 'status'], {
60
+ cwd: root,
61
+ env: {
62
+ ...process.env,
63
+ HOME: home,
64
+ LDM_STATUS_NPM_REGISTRY_URL: registryUrl,
65
+ LDM_STATUS_NPM_CONCURRENCY: String(concurrency),
66
+ LDM_STATUS_NPM_TIMEOUT_MS: '2000',
67
+ LDM_STATUS_TOTAL_BUDGET_MS: '10000',
68
+ },
69
+ stdio: ['ignore', 'pipe', 'pipe'],
70
+ });
71
+
72
+ let stdout = '';
73
+ let stderr = '';
74
+ child.stdout.setEncoding('utf8');
75
+ child.stderr.setEncoding('utf8');
76
+ child.stdout.on('data', chunk => { stdout += chunk; });
77
+ child.stderr.on('data', chunk => { stderr += chunk; });
78
+ child.on('close', status => resolve({ status, stdout, stderr }));
79
+ });
80
+ }
81
+
82
+ async function runFixture({ concurrency, delayMs }) {
83
+ const home = join(tempRoot, `home-${concurrency}-${delayMs}`);
84
+ writeFixture(home);
85
+ const registry = createRegistryServer(delayMs);
86
+ const address = await listen(registry.server);
87
+ const startedAt = Date.now();
88
+ const result = await runStatus({
89
+ concurrency,
90
+ home,
91
+ registryUrl: `http://${address.address}:${address.port}`,
92
+ });
93
+ const elapsedMs = Date.now() - startedAt;
94
+ registry.server.closeAllConnections();
95
+ registry.server.close();
96
+ return { result, elapsedMs, maxActive: registry.getMaxActive() };
97
+ }
98
+
99
+ try {
100
+ const concurrent = await runFixture({ concurrency: 4, delayMs: 500 });
101
+ assert(concurrent.result.status === 0, `concurrent ldm status exited ${concurrent.result.status}\nstdout:\n${concurrent.result.stdout}\nstderr:\n${concurrent.result.stderr}`);
102
+ assert(concurrent.elapsedMs < 3000, `concurrent ldm status should finish well before serial runtime; elapsed ${concurrent.elapsedMs}ms`);
103
+ assert(concurrent.maxActive >= 4, `registry server should see concurrent probes; max active ${concurrent.maxActive}`);
104
+ assert(concurrent.result.stdout.includes(`LDM OS v${sourceVersion}`), `status should print installed LDM OS version\n${concurrent.result.stdout}`);
105
+ assert(concurrent.result.stdout.includes('Extensions: 8'), `status should print extension count\n${concurrent.result.stdout}`);
106
+ assert(concurrent.result.stdout.includes('ext-8: checking npm'), `status should check every staged extension\n${concurrent.result.stdout}`);
107
+ assert(!concurrent.result.stdout.includes('Update checks skipped:'), `concurrent status should not skip checks in this fixture\n${concurrent.result.stdout}`);
108
+
109
+ const serialFallback = await runFixture({ concurrency: 1, delayMs: 10 });
110
+ assert(serialFallback.result.status === 0, `serial fallback ldm status exited ${serialFallback.result.status}\nstdout:\n${serialFallback.result.stdout}\nstderr:\n${serialFallback.result.stderr}`);
111
+ assert(serialFallback.maxActive === 1, `serial fallback should only run one probe at a time; max active ${serialFallback.maxActive}`);
112
+ assert(serialFallback.result.stdout.includes('ext-8: checking npm'), `serial fallback should still check every staged extension\n${serialFallback.result.stdout}`);
113
+ assert(!serialFallback.result.stdout.includes('Update checks skipped:'), `serial fallback should not skip checks in this fixture\n${serialFallback.result.stdout}`);
114
+ } finally {
115
+ rmSync(tempRoot, { recursive: true, force: true });
116
+ }
117
+
118
+ console.log('ldm status concurrency regression passed');