@crouton-kit/crouter 0.3.70 → 0.3.79

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 (193) hide show
  1. package/README.md +1 -1
  2. package/dist/build-root.d.ts +12 -4
  3. package/dist/build-root.js +25 -6
  4. package/dist/builtin-memory/00-runtime-base.md +3 -10
  5. package/dist/builtin-memory/04-base-worker.md +18 -0
  6. package/dist/builtin-memory/04-orchestration-kernel.md +1 -1
  7. package/dist/builtin-memory/crouter-development/plugins.md +82 -5
  8. package/dist/builtin-pi-packages/pi-crtr-extensions/README.md +13 -34
  9. package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/__tests__/provider-rotation.test.ts +1115 -1
  10. package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/provider-rotation.ts +234 -71
  11. package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/statusline.ts +2 -9
  12. package/dist/builtin-pi-packages/pi-crtr-extensions/lib/subscription-state.ts +2 -516
  13. package/dist/builtin-pi-packages/pi-crtr-extensions/package-lock.json +2 -2
  14. package/dist/builtin-pi-packages/pi-mode-switch/README.md +11 -39
  15. package/dist/builtin-pi-packages/pi-mode-switch/extensions/index.ts +20 -15
  16. package/dist/builtin-pi-packages/pi-mode-switch/package.json +1 -1
  17. package/dist/builtin-views/canvas/tui.mjs +8 -9
  18. package/dist/builtin-views/chat/tui.mjs +12 -12
  19. package/dist/builtin-views/git-pr/tui.mjs +7 -8
  20. package/dist/builtin-views/inbox/tui.mjs +27 -41
  21. package/dist/builtin-views/linkedin/tui.mjs +23 -37
  22. package/dist/builtin-views/prompt-review/tui.mjs +11 -11
  23. package/dist/builtin-views/settings/tui.mjs +11 -11
  24. package/dist/builtin-views/workspace-sidebar/tui.mjs +8 -9
  25. package/dist/clients/attach/__tests__/attach-chrome-remote.test.js +11 -6
  26. package/dist/clients/attach/__tests__/attach-keybindings.test.d.ts +1 -0
  27. package/dist/clients/attach/__tests__/attach-keybindings.test.js +113 -0
  28. package/dist/clients/attach/__tests__/crtr-output-render.test.js +1 -1
  29. package/dist/clients/attach/__tests__/mermaid-render.test.d.ts +1 -0
  30. package/dist/clients/attach/__tests__/mermaid-render.test.js +28 -0
  31. package/dist/clients/attach/__tests__/oauth-dialog-lifecycle.test.d.ts +1 -0
  32. package/dist/clients/attach/__tests__/oauth-dialog-lifecycle.test.js +110 -0
  33. package/dist/clients/attach/attach-cmd.d.ts +9 -1
  34. package/dist/clients/attach/attach-cmd.js +841 -792
  35. package/dist/clients/attach/auth-pickers.d.ts +0 -12
  36. package/dist/clients/attach/auth-pickers.js +64 -15
  37. package/dist/clients/attach/canvas-panels.js +2 -3
  38. package/dist/clients/attach/chat-view.d.ts +7 -8
  39. package/dist/clients/attach/chat-view.js +119 -79
  40. package/dist/clients/attach/edit-diff-render.d.ts +6 -0
  41. package/dist/clients/attach/edit-diff-render.js +263 -0
  42. package/dist/clients/attach/graph-overlay.d.ts +12 -2
  43. package/dist/clients/attach/graph-overlay.js +83 -33
  44. package/dist/clients/attach/input-controller.d.ts +28 -2
  45. package/dist/clients/attach/input-controller.js +38 -5
  46. package/dist/clients/attach/mermaid-render.js +5 -2
  47. package/dist/clients/attach/pickers.d.ts +8 -7
  48. package/dist/clients/attach/pickers.js +11 -17
  49. package/dist/clients/attach/slash-commands.d.ts +9 -0
  50. package/dist/clients/attach/slash-commands.js +127 -7
  51. package/dist/clients/attach/titled-editor.d.ts +12 -1
  52. package/dist/clients/attach/titled-editor.js +103 -8
  53. package/dist/commands/canvas-browse.js +2 -2
  54. package/dist/commands/human/queue.js +3 -4
  55. package/dist/commands/memory/lint.js +39 -5
  56. package/dist/commands/memory/write.js +1 -0
  57. package/dist/commands/node.js +9 -2
  58. package/dist/commands/pkg/plugin-inspect.js +22 -1
  59. package/dist/commands/pkg/plugin-manage.js +31 -9
  60. package/dist/commands/surface-tmux-spread.js +1 -3
  61. package/dist/commands/sys/__tests__/config-keybindings.test.d.ts +1 -0
  62. package/dist/commands/sys/__tests__/config-keybindings.test.js +55 -0
  63. package/dist/commands/sys/__tests__/config-model-ladders.test.d.ts +1 -0
  64. package/dist/commands/sys/__tests__/config-model-ladders.test.js +121 -0
  65. package/dist/commands/sys/__tests__/setup-core.test.js +158 -1
  66. package/dist/commands/sys/config.js +18 -21
  67. package/dist/commands/sys/doctor.js +42 -4
  68. package/dist/commands/sys/setup-core.d.ts +49 -1
  69. package/dist/commands/sys/setup-core.js +161 -4
  70. package/dist/commands/sys/setup.d.ts +88 -0
  71. package/dist/commands/sys/setup.js +943 -169
  72. package/dist/commands/view-pick.d.ts +4 -0
  73. package/dist/commands/view-pick.js +17 -7
  74. package/dist/core/__tests__/base-worker-prompt.test.d.ts +1 -0
  75. package/dist/core/__tests__/base-worker-prompt.test.js +24 -0
  76. package/dist/core/__tests__/canvas-inbox-watcher-hold.test.js +232 -1
  77. package/dist/core/__tests__/canvas-inbox-watcher.test.js +34 -9
  78. package/dist/core/__tests__/command-plugins-surfaces.test.d.ts +1 -0
  79. package/dist/core/__tests__/command-plugins-surfaces.test.js +298 -0
  80. package/dist/core/__tests__/command-plugins.test.d.ts +1 -0
  81. package/dist/core/__tests__/command-plugins.test.js +444 -0
  82. package/dist/core/__tests__/fault-classifier.test.js +15 -0
  83. package/dist/core/__tests__/fixtures/fake-engine.d.ts +6 -0
  84. package/dist/core/__tests__/fixtures/fake-engine.js +9 -1
  85. package/dist/core/__tests__/full/broker-dialogs.test.js +7 -2
  86. package/dist/core/__tests__/host-teardown-process-group.test.js +15 -4
  87. package/dist/core/__tests__/preview-registry-sync.test.js +30 -1
  88. package/dist/core/__tests__/scope-crouter-home-fence.test.d.ts +1 -0
  89. package/dist/core/__tests__/scope-crouter-home-fence.test.js +55 -0
  90. package/dist/core/__tests__/stream-watchdog.test.d.ts +1 -0
  91. package/dist/core/__tests__/stream-watchdog.test.js +70 -0
  92. package/dist/core/__tests__/tmux-surface.test.js +72 -0
  93. package/dist/core/canvas/browse/__tests__/model.test.js +23 -5
  94. package/dist/core/canvas/browse/__tests__/render.test.js +1 -0
  95. package/dist/core/canvas/browse/app.d.ts +6 -0
  96. package/dist/core/canvas/browse/app.js +230 -41
  97. package/dist/core/canvas/browse/model.d.ts +10 -6
  98. package/dist/core/canvas/browse/model.js +20 -12
  99. package/dist/core/canvas/browse/pins.d.ts +4 -0
  100. package/dist/core/canvas/browse/pins.js +29 -0
  101. package/dist/core/canvas/browse/render.d.ts +13 -1
  102. package/dist/core/canvas/browse/render.js +72 -15
  103. package/dist/core/canvas/nav-model.js +5 -11
  104. package/dist/core/canvas/paths.d.ts +5 -0
  105. package/dist/core/canvas/paths.js +7 -0
  106. package/dist/core/command-plugins/adapter.d.ts +15 -0
  107. package/dist/core/command-plugins/adapter.js +145 -0
  108. package/dist/core/command-plugins/compose.d.ts +5 -0
  109. package/dist/core/command-plugins/compose.js +56 -0
  110. package/dist/core/command-plugins/discovery.d.ts +104 -0
  111. package/dist/core/command-plugins/discovery.js +565 -0
  112. package/dist/core/config.d.ts +48 -0
  113. package/dist/core/config.js +228 -110
  114. package/dist/core/fault-classifier.js +1 -1
  115. package/dist/core/fs-utils.d.ts +1 -0
  116. package/dist/core/fs-utils.js +15 -1
  117. package/dist/core/keybindings/__tests__/bespoke-consumers.test.d.ts +1 -0
  118. package/dist/core/keybindings/__tests__/bespoke-consumers.test.js +40 -0
  119. package/dist/core/keybindings/__tests__/resolve.test.d.ts +1 -0
  120. package/dist/core/keybindings/__tests__/resolve.test.js +224 -0
  121. package/dist/core/keybindings/catalog.d.ts +14 -0
  122. package/dist/core/keybindings/catalog.js +257 -0
  123. package/dist/core/keybindings/index.d.ts +5 -0
  124. package/dist/core/keybindings/index.js +4 -0
  125. package/dist/core/keybindings/match.d.ts +29 -0
  126. package/dist/core/keybindings/match.js +99 -0
  127. package/dist/core/keybindings/persistence.d.ts +14 -0
  128. package/dist/core/keybindings/persistence.js +31 -0
  129. package/dist/core/keybindings/resolve.d.ts +14 -0
  130. package/dist/core/keybindings/resolve.js +305 -0
  131. package/dist/core/keybindings/types.d.ts +37 -0
  132. package/dist/core/keybindings/types.js +1 -0
  133. package/dist/core/memory-resolver.d.ts +1 -1
  134. package/dist/core/memory-resolver.js +10 -3
  135. package/dist/core/predicate.d.ts +5 -3
  136. package/dist/core/predicate.js +5 -3
  137. package/dist/core/profiles/select.d.ts +6 -0
  138. package/dist/core/profiles/select.js +86 -52
  139. package/dist/core/provider-management.d.ts +12 -0
  140. package/dist/core/provider-management.js +24 -0
  141. package/dist/core/runtime/broker-protocol.d.ts +33 -5
  142. package/dist/core/runtime/broker.js +164 -14
  143. package/dist/core/runtime/launch.d.ts +39 -6
  144. package/dist/core/runtime/launch.js +78 -20
  145. package/dist/core/runtime/naming.js +3 -3
  146. package/dist/core/runtime/pi-cli.d.ts +6 -0
  147. package/dist/core/runtime/pi-cli.js +16 -2
  148. package/dist/core/runtime/pi-vendored.d.ts +8 -0
  149. package/dist/core/runtime/pi-vendored.js +14 -0
  150. package/dist/core/runtime/placement.d.ts +2 -2
  151. package/dist/core/runtime/placement.js +4 -1
  152. package/dist/core/runtime/promote.js +4 -0
  153. package/dist/core/runtime/recap.d.ts +3 -3
  154. package/dist/core/runtime/recap.js +75 -47
  155. package/dist/core/runtime/recycle.js +6 -1
  156. package/dist/core/runtime/reset.js +5 -0
  157. package/dist/core/runtime/session-list-cache.d.ts +33 -0
  158. package/dist/core/runtime/session-list-cache.js +338 -0
  159. package/dist/core/runtime/spawn.js +52 -45
  160. package/dist/core/runtime/stream-watchdog.d.ts +26 -0
  161. package/dist/core/runtime/stream-watchdog.js +75 -0
  162. package/dist/core/runtime/tmux-chrome.d.ts +1 -1
  163. package/dist/core/runtime/tmux-chrome.js +2 -2
  164. package/dist/core/runtime/tmux.d.ts +18 -15
  165. package/dist/core/runtime/tmux.js +217 -110
  166. package/dist/core/scope.js +27 -4
  167. package/dist/core/subscription-state.d.ts +90 -0
  168. package/dist/core/subscription-state.js +762 -0
  169. package/dist/core/tui/__tests__/host-keybindings.test.d.ts +1 -0
  170. package/dist/core/tui/__tests__/host-keybindings.test.js +112 -0
  171. package/dist/core/tui/host.d.ts +30 -1
  172. package/dist/core/tui/host.js +148 -34
  173. package/dist/core/view/contract.d.ts +17 -3
  174. package/dist/daemon/crtrd.js +253 -12
  175. package/dist/pi-extensions/__tests__/canvas-stophook-agentend.test.js +41 -0
  176. package/dist/pi-extensions/__tests__/canvas-stophook-context-nudge.test.d.ts +1 -0
  177. package/dist/pi-extensions/__tests__/canvas-stophook-context-nudge.test.js +121 -0
  178. package/dist/pi-extensions/canvas-inbox-watcher.d.ts +1 -1
  179. package/dist/pi-extensions/canvas-inbox-watcher.js +203 -25
  180. package/dist/pi-extensions/canvas-recap.d.ts +4 -0
  181. package/dist/pi-extensions/canvas-recap.js +73 -46
  182. package/dist/pi-extensions/canvas-stophook.d.ts +11 -0
  183. package/dist/pi-extensions/canvas-stophook.js +33 -4
  184. package/dist/types.d.ts +9 -26
  185. package/dist/types.js +1 -28
  186. package/dist/web-client/assets/{index-DiFuLcp6.js → index--md2ylfi.js} +1 -1
  187. package/dist/web-client/index.html +1 -1
  188. package/dist/web-client/sw.js +1 -1
  189. package/package.json +8 -4
  190. package/dist/pi-extensions/canvas-nav.d.ts +0 -43
  191. package/dist/pi-extensions/canvas-nav.js +0 -640
  192. package/dist/pi-extensions/widget-order-bus.d.ts +0 -6
  193. package/dist/pi-extensions/widget-order-bus.js +0 -34
@@ -0,0 +1,298 @@
1
+ // Phase-2 surface tests: the lifecycle surfaces (pkg plugin install / show and
2
+ // sys doctor) must surface the Phase-1 validator's STABLE TYPED ISSUES to the
3
+ // caller, and must do so WITHOUT executing the plugin binary. Covers spec item
4
+ // 6 at the surface seam (the validator itself is tested in
5
+ // command-plugins.test.ts). Run with:
6
+ // node --import tsx/esm --test src/core/__tests__/command-plugins-surfaces.test.ts
7
+ //
8
+ // Every test runs against an ISOLATED home (HOME → temp) with cwd pinned to a
9
+ // dir that has no .crouter ancestor, so discovery is deterministic. Each fixture
10
+ // executable writes a sentinel file if it is ever spawned; every surface
11
+ // assertion also checks the sentinel is absent — proving validation stayed
12
+ // static.
13
+ import { test, describe, before, after, beforeEach } from 'node:test';
14
+ import assert from 'node:assert/strict';
15
+ import { mkdtempSync, mkdirSync, writeFileSync, rmSync, chmodSync, existsSync } from 'node:fs';
16
+ import { tmpdir } from 'node:os';
17
+ import { join } from 'node:path';
18
+ import { pluginInstall, pluginUpdate } from '../../commands/pkg/plugin-manage.js';
19
+ import { pluginShow } from '../../commands/pkg/plugin-inspect.js';
20
+ import { sysDoctorLeaf } from '../../commands/sys/doctor.js';
21
+ import { discoverCommandContributions } from '../command-plugins/discovery.js';
22
+ import { resetScopeCache } from '../scope.js';
23
+ // A real executable that records the fact it ran. No surface should ever spawn
24
+ // it — the sentinel must never appear.
25
+ const SENTINEL_EXEC = `#!/usr/bin/env node
26
+ const fs = require('fs');
27
+ if (process.env.CMDPLUGIN_SENTINEL) fs.writeFileSync(process.env.CMDPLUGIN_SENTINEL, 'executed');
28
+ process.stdout.write(JSON.stringify({ protocolVersion: 1, ok: true, result: { app_id: 'x', status: 'running' } }));
29
+ `;
30
+ function validManifest() {
31
+ return {
32
+ schemaVersion: 1,
33
+ executable: 'bin/cmd.js',
34
+ mounts: [
35
+ {
36
+ parent: [],
37
+ node: {
38
+ kind: 'branch',
39
+ name: 'app',
40
+ description: 'application lifecycle and inspection',
41
+ whenToUse: 'you need to create, deploy, inspect, or remove an application',
42
+ rootEntry: {
43
+ concept: 'applications hosted by a crouter home',
44
+ description: 'application lifecycle and inspection',
45
+ whenToUse: 'you need to create, deploy, inspect, or remove an application',
46
+ },
47
+ summary: 'application lifecycle and inspection',
48
+ children: [
49
+ {
50
+ kind: 'leaf',
51
+ name: 'show',
52
+ description: 'show one application',
53
+ whenToUse: 'inspect a single application by id',
54
+ summary: 'show one application details',
55
+ params: [{ kind: 'positional', name: 'app-id', required: true, constraint: 'the application id' }],
56
+ output: [{ name: 'app_id', type: 'string', required: true, constraint: 'the echoed application id' }],
57
+ outputKind: 'object',
58
+ effects: ['None. Read-only.'],
59
+ },
60
+ ],
61
+ },
62
+ },
63
+ ],
64
+ };
65
+ }
66
+ const CASES = [
67
+ (() => { const m = validManifest(); m['executable'] = '../../../../bin/sh'; return { name: 'escaping executable path', code: 'command_path_unsafe', manifest: m }; })(),
68
+ { name: 'non-executable file', code: 'command_not_executable', execBit: false },
69
+ (() => { const m = validManifest(); m['schemaVersion'] = 2; return { name: 'unknown schemaVersion', code: 'command_schema_version', manifest: m }; })(),
70
+ (() => { const m = validManifest(); m['requires'] = { crtr: '>=1' }; return { name: 'unknown top-level key', code: 'command_manifest_invalid', manifest: m }; })(),
71
+ (() => { const m = validManifest(); m['mounts'][0].parent = ['sys']; return { name: 'non-empty parent', code: 'command_parent_invalid', manifest: m }; })(),
72
+ ];
73
+ // ---------------------------------------------------------------------------
74
+ // Isolated home + cwd
75
+ // ---------------------------------------------------------------------------
76
+ let home;
77
+ let userRoot;
78
+ let emptyStart;
79
+ let sourceRoot; // holds source plugin dirs for install tests
80
+ let sentinel;
81
+ let realHome;
82
+ let realProfile;
83
+ let realCwd;
84
+ before(() => {
85
+ realHome = process.env['HOME'];
86
+ realProfile = process.env['CRTR_PROFILE_ID'];
87
+ realCwd = process.cwd();
88
+ delete process.env['CRTR_PROFILE_ID'];
89
+ });
90
+ after(() => {
91
+ process.chdir(realCwd);
92
+ if (realHome !== undefined)
93
+ process.env['HOME'] = realHome;
94
+ else
95
+ delete process.env['HOME'];
96
+ if (realProfile !== undefined)
97
+ process.env['CRTR_PROFILE_ID'] = realProfile;
98
+ delete process.env['CMDPLUGIN_SENTINEL'];
99
+ // Remove EVERY test's temp dirs, not just the last beforeEach's set.
100
+ for (const d of tempDirs) {
101
+ try {
102
+ rmSync(d, { recursive: true, force: true });
103
+ }
104
+ catch { /* ignore */ }
105
+ }
106
+ resetScopeCache();
107
+ });
108
+ const tempDirs = [];
109
+ function mintDir(prefix) {
110
+ const d = mkdtempSync(join(tmpdir(), prefix));
111
+ tempDirs.push(d);
112
+ return d;
113
+ }
114
+ beforeEach(() => {
115
+ home = mintDir('crtr-cmdsurf-home-');
116
+ process.env['HOME'] = home;
117
+ userRoot = join(home, '.crouter');
118
+ mkdirSync(join(userRoot, 'plugins'), { recursive: true });
119
+ emptyStart = mintDir('crtr-cmdsurf-empty-');
120
+ sourceRoot = mintDir('crtr-cmdsurf-src-');
121
+ sentinel = join(emptyStart, 'EXECUTED');
122
+ process.env['CMDPLUGIN_SENTINEL'] = sentinel;
123
+ process.chdir(emptyStart); // no .crouter ancestor → project scope is empty
124
+ resetScopeCache();
125
+ });
126
+ /** Write a plugin at `<dir>/<name>/` with a command manifest + executable. */
127
+ function writePlugin(dir, name, c) {
128
+ const root = join(dir, name);
129
+ mkdirSync(join(root, '.crouter-plugin'), { recursive: true });
130
+ mkdirSync(join(root, 'bin'), { recursive: true });
131
+ writeFileSync(join(root, '.crouter-plugin', 'plugin.json'), JSON.stringify({ name, version: '0.1.0', description: 'fixture', commands: 'commands.json' }));
132
+ writeFileSync(join(root, 'commands.json'), JSON.stringify(c.manifest ?? validManifest()));
133
+ const execPath = join(root, 'bin', 'cmd.js');
134
+ writeFileSync(execPath, SENTINEL_EXEC);
135
+ chmodSync(execPath, c.execBit === false ? 0o644 : 0o755);
136
+ return root;
137
+ }
138
+ function assertNotExecuted() {
139
+ assert.equal(existsSync(sentinel), false, 'the plugin binary must never be spawned by a validation surface');
140
+ }
141
+ // ---------------------------------------------------------------------------
142
+ // pkg plugin show
143
+ // ---------------------------------------------------------------------------
144
+ describe('pkg plugin show surfaces command validation', () => {
145
+ for (const c of CASES) {
146
+ test(`${c.name} → ${c.code} in commands.issues, no execution`, async () => {
147
+ writePlugin(join(userRoot, 'plugins'), 'p', c);
148
+ resetScopeCache();
149
+ const out = await pluginShow.run({ name: 'p' });
150
+ const commands = out['commands'];
151
+ assert.ok(commands, 'show must inventory commands for a plugin declaring a manifest');
152
+ assert.ok(commands.issues.some((i) => i.code === c.code), `expected ${c.code}, got ${JSON.stringify(commands.issues.map((i) => i.code))}`);
153
+ // Typed issues render with received/expected/next.
154
+ const issue = commands.issues.find((i) => i.code === c.code);
155
+ assert.ok(typeof issue.received === 'string' && typeof issue.expected === 'string' && typeof issue.next === 'string');
156
+ assert.equal(commands.mounts.length, 0, 'a rejected manifest contributes no mounts');
157
+ assertNotExecuted();
158
+ });
159
+ }
160
+ test('valid manifest → inventory with the accepted mount and zero issues', async () => {
161
+ writePlugin(join(userRoot, 'plugins'), 'p', { name: 'valid', code: '' });
162
+ resetScopeCache();
163
+ const out = await pluginShow.run({ name: 'p' });
164
+ const commands = out['commands'];
165
+ assert.deepEqual(commands.mounts, ['app']);
166
+ assert.equal(commands.issues.length, 0);
167
+ assert.ok(typeof commands.executable === 'string', 'executable path is resolved for a valid manifest');
168
+ assertNotExecuted();
169
+ });
170
+ });
171
+ // ---------------------------------------------------------------------------
172
+ // sys doctor
173
+ // ---------------------------------------------------------------------------
174
+ describe('sys doctor surfaces command validation', () => {
175
+ for (const c of CASES) {
176
+ test(`${c.name} → fail check with human_action remediation, no execution`, async () => {
177
+ writePlugin(join(userRoot, 'plugins'), 'p', c);
178
+ resetScopeCache();
179
+ const out = await sysDoctorLeaf.run({ scope: 'user', fix: false, remote: false });
180
+ const checks = out['checks'];
181
+ const cmdCheck = checks.find((k) => k.name.startsWith('plugin:p:commands') && k.status === 'fail');
182
+ assert.ok(cmdCheck, `expected a failing command check, got ${JSON.stringify(checks.map((k) => k.name + ':' + k.status))}`);
183
+ assert.match(cmdCheck.message, new RegExp(c.code));
184
+ assert.equal(cmdCheck.remediation?.kind, 'human_action', 'command remediation is never auto-applied');
185
+ assert.equal(out['ok'], false);
186
+ assertNotExecuted();
187
+ });
188
+ }
189
+ test('--fix never touches plugin content and leaves the command issue unresolved', async () => {
190
+ writePlugin(join(userRoot, 'plugins'), 'p', { name: 'non-executable file', code: 'command_not_executable', execBit: false });
191
+ resetScopeCache();
192
+ const out = await sysDoctorLeaf.run({ scope: 'user', fix: true, remote: false });
193
+ const checks = out['checks'];
194
+ const cmdCheck = checks.find((k) => k.name.startsWith('plugin:p:commands') && k.status === 'fail');
195
+ assert.ok(cmdCheck, 'the command issue is still reported under --fix');
196
+ assert.notEqual(cmdCheck.fixed, true, '--fix must not chmod the plugin executable');
197
+ assertNotExecuted();
198
+ });
199
+ test('valid manifest → a passing command check', async () => {
200
+ writePlugin(join(userRoot, 'plugins'), 'p', { name: 'valid', code: '' });
201
+ resetScopeCache();
202
+ const out = await sysDoctorLeaf.run({ scope: 'user', fix: false, remote: false });
203
+ const checks = out['checks'];
204
+ const cmdCheck = checks.find((k) => k.name === 'plugin:p:commands');
205
+ assert.ok(cmdCheck && cmdCheck.status === 'pass', 'a valid manifest yields a pass check');
206
+ assert.match(cmdCheck.message, /app/);
207
+ assertNotExecuted();
208
+ });
209
+ });
210
+ // ---------------------------------------------------------------------------
211
+ // Cross-plugin top-level collision (drop-both + issue, visible on surfaces)
212
+ // ---------------------------------------------------------------------------
213
+ describe('cross-plugin top-level collision surfaces on doctor and show', () => {
214
+ function installTwoClaimants() {
215
+ // Two distinct plugins, both valid in isolation, both claiming `app`.
216
+ writePlugin(join(userRoot, 'plugins'), 'p-one', { name: 'valid', code: '' });
217
+ writePlugin(join(userRoot, 'plugins'), 'p-two', { name: 'valid', code: '' });
218
+ resetScopeCache();
219
+ }
220
+ test('neither claimant mounts: discovery drops the collided command from the tree', () => {
221
+ installTwoClaimants();
222
+ const snapshot = discoverCommandContributions(new Set(['sys']));
223
+ assert.equal(snapshot.contributions.length, 0, 'a collided top-level command must not be mounted by ANY claimant');
224
+ const collisions = snapshot.issues.filter((i) => i.code === 'command_collision');
225
+ assert.deepEqual(collisions.map((i) => i.plugin).sort(), ['p-one', 'p-two'], 'both claimants are flagged');
226
+ });
227
+ test('sys doctor fails BOTH claimants with the collision (no false pass)', async () => {
228
+ installTwoClaimants();
229
+ const out = await sysDoctorLeaf.run({ scope: 'user', fix: false, remote: false });
230
+ const checks = out['checks'];
231
+ for (const name of ['p-one', 'p-two']) {
232
+ const passCheck = checks.find((k) => k.name === `plugin:${name}:commands` && k.status === 'pass');
233
+ assert.equal(passCheck, undefined, `${name} must not PASS while its command is dropped by a collision`);
234
+ const failCheck = checks.find((k) => k.name.startsWith(`plugin:${name}:commands`) && k.status === 'fail' && /command_collision/.test(k.message));
235
+ assert.ok(failCheck, `${name} must fail with command_collision, got ${JSON.stringify(checks.map((k) => k.name + ':' + k.status))}`);
236
+ assert.match(failCheck.message, /claimed by multiple plugins/);
237
+ assert.match(failCheck.message, /p-one/);
238
+ assert.match(failCheck.message, /p-two/);
239
+ assert.equal(failCheck.remediation?.kind, 'human_action');
240
+ }
241
+ assert.equal(out['ok'], false);
242
+ assertNotExecuted();
243
+ });
244
+ test('pkg plugin show reports the collision on each claimant and lists no mounts', async () => {
245
+ installTwoClaimants();
246
+ for (const name of ['p-one', 'p-two']) {
247
+ const out = await pluginShow.run({ name });
248
+ const commands = out['commands'];
249
+ assert.deepEqual(commands.mounts, [], `${name} must not list the collided command as an accepted mount`);
250
+ const issue = commands.issues.find((i) => i.code === 'command_collision');
251
+ assert.ok(issue, `${name} show must carry the command_collision issue`);
252
+ assert.deepEqual(issue.received.split(', ').sort(), ['p-one', 'p-two'], 'the issue names both claimants');
253
+ }
254
+ assertNotExecuted();
255
+ });
256
+ });
257
+ // ---------------------------------------------------------------------------
258
+ // pkg plugin install / update
259
+ // ---------------------------------------------------------------------------
260
+ describe('pkg plugin install/update surface command validation', () => {
261
+ for (const c of CASES) {
262
+ test(`install ${c.name} → ${c.code} in result.commands.issues, no execution`, async () => {
263
+ const src = writePlugin(sourceRoot, 'p', c);
264
+ resetScopeCache();
265
+ const out = await pluginInstall.run({ installRef: src, scope: 'user' });
266
+ const commands = out['commands'];
267
+ assert.ok(commands, 'install reports command validation for a plugin declaring a manifest');
268
+ assert.ok(commands.issues.some((i) => i.code === c.code), `expected ${c.code}, got ${JSON.stringify(commands.issues.map((i) => i.code))}`);
269
+ assert.equal(commands.mounts.length, 0);
270
+ assertNotExecuted();
271
+ });
272
+ }
273
+ test('install valid manifest → accepted contribution, zero issues, no execution', async () => {
274
+ const src = writePlugin(sourceRoot, 'p', { name: 'valid', code: '' });
275
+ resetScopeCache();
276
+ const out = await pluginInstall.run({ installRef: src, scope: 'user' });
277
+ const commands = out['commands'];
278
+ assert.deepEqual(commands.mounts, ['app']);
279
+ assert.equal(commands.issues.length, 0);
280
+ assertNotExecuted();
281
+ });
282
+ test('update re-reports the current command validation for an edited manifest', async () => {
283
+ // Install valid, then break the on-disk manifest, then update: the report
284
+ // must reflect the CURRENT (broken) state — validation is per-call.
285
+ const src = writePlugin(sourceRoot, 'p', { name: 'valid', code: '' });
286
+ resetScopeCache();
287
+ await pluginInstall.run({ installRef: src, scope: 'user' });
288
+ // Break the installed copy's manifest in place.
289
+ writeFileSync(join(userRoot, 'plugins', 'p', 'commands.json'), JSON.stringify((() => { const m = validManifest(); m['schemaVersion'] = 2; return m; })()));
290
+ resetScopeCache();
291
+ const out = await pluginUpdate.run({ name: 'p' });
292
+ const updated = out['updated'];
293
+ const entry = updated.find((u) => u.name === 'p');
294
+ assert.ok(entry.commands, 'update reports command validation');
295
+ assert.ok(entry.commands.issues.some((i) => i.code === 'command_schema_version'));
296
+ assertNotExecuted();
297
+ });
298
+ });
@@ -0,0 +1 @@
1
+ export {};