cowork-flow 2.4.2 → 2.5.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 (41) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/README.en.md +2 -1
  3. package/README.md +2 -1
  4. package/docs/architecture.en.md +2 -0
  5. package/docs/architecture.md +2 -0
  6. package/docs/hosts.en.md +15 -0
  7. package/docs/hosts.md +15 -0
  8. package/package.json +2 -2
  9. package/presets/claude-code/.claude-plugin/plugin.json +1 -1
  10. package/presets/codex/.codex-plugin/plugin.json +1 -1
  11. package/presets/kimi-code/.kimi-plugin/plugin.json +1 -1
  12. package/presets/qoder/.qoder-plugin/plugin.json +1 -1
  13. package/presets/zcode/.zcode-plugin/plugin.json +1 -1
  14. package/src/commands/host-inspect.js +86 -0
  15. package/src/commands/host.js +42 -18
  16. package/src/commands/init.js +100 -3
  17. package/src/commands/install-claude-code-plugin.js +53 -2
  18. package/src/commands/install-codex-plugin.js +114 -4
  19. package/src/commands/install-dsh-hook.js +51 -0
  20. package/src/commands/install-dsh-preset.js +46 -4
  21. package/src/commands/install-kimi-code-plugin.js +61 -2
  22. package/src/commands/install-kimi-hook.js +84 -2
  23. package/src/commands/install-opencode-plugin.js +58 -2
  24. package/src/commands/install-qoder-plugin.js +67 -3
  25. package/src/commands/install-zcode-plugin.js +77 -2
  26. package/src/commands/registry.js +20 -5
  27. package/src/lib/dsh-home.js +2 -2
  28. package/template/.cowork-flow/.version +1 -1
  29. package/template/.cowork-flow/scripts/adapters/host/host_manifest.py +4 -0
  30. package/template/.cowork-flow/scripts/adapters/host/workflow_state_hook.py +1 -3
  31. package/template/.cowork-flow/scripts/infra/files.py +0 -13
  32. package/template/.cowork-flow/scripts/services/ac_evidence.py +1 -1
  33. package/template/.cowork-flow/scripts/services/decision_anchor_schema.py +65 -0
  34. package/template/.cowork-flow/scripts/services/fact_view.py +2 -75
  35. package/template/.cowork-flow/scripts/services/lifecycle_checks.py +1 -1
  36. package/template/.cowork-flow/scripts/services/plan_readiness.py +139 -67
  37. package/template/.cowork-flow/spec/contracts/host-install-inspection.md +174 -0
  38. package/template/.cowork-flow/spec/contracts/index.md +1 -0
  39. package/template/.cowork-flow/spec/runtime/contract-registry.json +15 -0
  40. package/template/skills/runtime-health/scripts/doctor.py +538 -489
  41. package/template/skills/task-review/scripts/review_check.py +33 -6
@@ -1,10 +1,10 @@
1
1
  import { spawnSync } from 'node:child_process';
2
2
  import { existsSync } from 'node:fs';
3
- import { cp, mkdir, rm, writeFile } from 'node:fs/promises';
3
+ import { cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
4
4
  import { homedir } from 'node:os';
5
5
  import { delimiter, dirname, join, resolve } from 'node:path';
6
6
 
7
- import { parseInstallArgs, pathExists } from '../lib/install-support.js';
7
+ import { parseInstallArgs, pathExists, readJsonFile } from '../lib/install-support.js';
8
8
  import { readPackageInfo } from '../lib/package-info.js';
9
9
  import { readPluginMetadata } from '../lib/plugin-metadata.js';
10
10
  import { pluginPayload, stampPayloadManifest } from '../lib/plugin-payload.js';
@@ -19,11 +19,70 @@ const MARKETPLACE_MANIFEST = join('.agents', 'plugins', 'marketplace.json');
19
19
  export const FLAGS = ['--dry-run', '--force', '--uninstall'];
20
20
 
21
21
 
22
- function codexHome() {
23
- const configured = (process.env.CODEX_HOME || '').trim();
22
+ function codexHome(env = process.env) {
23
+ const configured = (env.CODEX_HOME || '').trim();
24
24
  return configured || join(homedir(), '.codex');
25
25
  }
26
26
 
27
+
28
+ function stripTomlInlineComment(value) {
29
+ let quote = '';
30
+ let escaped = false;
31
+ for (let index = 0; index < value.length; index += 1) {
32
+ const char = value[index];
33
+ if (escaped) {
34
+ escaped = false;
35
+ } else if (quote === '"' && char === '\\') {
36
+ escaped = true;
37
+ } else if (quote) {
38
+ if (char === quote) {
39
+ quote = '';
40
+ }
41
+ } else if (index === 0 && (char === '"' || char === "'")) {
42
+ quote = char;
43
+ } else if (char === '#' && (index === 0 || value[index - 1] === ' ' || value[index - 1] === '\t')) {
44
+ return value.slice(0, index).trimEnd();
45
+ }
46
+ }
47
+ return value;
48
+ }
49
+
50
+
51
+ // The two flat sections cowork-flow owns in Codex's config.toml. Everything
52
+ // else in the file stays unread; this is registration state, not install layout.
53
+ async function readCodexConfig(home) {
54
+ const path = join(home, 'config.toml');
55
+ const sections = {};
56
+ let text;
57
+ try {
58
+ text = await readFile(path, 'utf8');
59
+ } catch {
60
+ return { path, sections };
61
+ }
62
+ let current = null;
63
+ for (const rawLine of text.split(/\r?\n/)) {
64
+ const line = rawLine.trim();
65
+ if (!line || line.startsWith('#')) {
66
+ continue;
67
+ }
68
+ if (line.startsWith('[') && line.endsWith(']')) {
69
+ const name = line.slice(1, -1).trim().replaceAll('"', '');
70
+ current = sections[name] = {};
71
+ continue;
72
+ }
73
+ if (!current || !line.includes('=')) {
74
+ continue;
75
+ }
76
+ const index = line.indexOf('=');
77
+ const key = line.slice(0, index).trim().replace(/^["']|["']$/g, '');
78
+ const value = stripTomlInlineComment(line.slice(index + 1).trim())
79
+ .trim()
80
+ .replace(/^["']|["']$/g, '');
81
+ current[key] = value;
82
+ }
83
+ return { path, sections };
84
+ }
85
+
27
86
  function marketplaceRoot(home) {
28
87
  return join(home, 'plugins', 'marketplaces', MARKETPLACE_NAME);
29
88
  }
@@ -310,3 +369,54 @@ export async function runInstallCodexPlugin(args = []) {
310
369
  );
311
370
  return 0;
312
371
  }
372
+
373
+
374
+ // Read-only installed-state facts for `host inspect`.
375
+ export async function inspectInstalledState({ env = process.env } = {}) {
376
+ const home = codexHome(env);
377
+ const root = marketplaceRoot(home);
378
+ const config = await readCodexConfig(home);
379
+ const marketplace = config.sections[`marketplaces.${MARKETPLACE_NAME}`];
380
+ const plugin = config.sections[`plugins.${PLUGIN_KEY}`];
381
+ // A registered source is where the marketplace actually lives; fall back to
382
+ // the installer's own root only when the source is absent or unusable.
383
+ const registeredSource = marketplace?.source || root;
384
+ const payload = marketplace?.source
385
+ ? join(marketplace.source, 'plugins', PLUGIN_NAME)
386
+ : pluginTarget(home);
387
+ const { manifest } = pluginPayload('codex');
388
+ const payloadManifest = await readJsonFile(join(payload, ...manifest.split('/')));
389
+ if (!marketplace) {
390
+ return {
391
+ status: 'missing',
392
+ version: null,
393
+ payloadPath: payloadManifest ? payload : null,
394
+ detailPath: config.path,
395
+ registeredSource: config.path,
396
+ enabled: null,
397
+ reason: 'marketplace is not registered'
398
+ };
399
+ }
400
+ if (!payloadManifest) {
401
+ return {
402
+ status: 'broken',
403
+ version: null,
404
+ payloadPath: payload,
405
+ detailPath: join(payload, ...manifest.split('/')),
406
+ registeredSource,
407
+ enabled: plugin?.enabled === 'true',
408
+ reason: `missing ${manifest}`
409
+ };
410
+ }
411
+ return {
412
+ status: 'installed',
413
+ version: typeof payloadManifest.version === 'string' ? payloadManifest.version : null,
414
+ payloadPath: payload,
415
+ detailPath: plugin?.enabled === 'true'
416
+ ? join(payload, ...manifest.split('/'))
417
+ : config.path,
418
+ registeredSource,
419
+ enabled: plugin?.enabled === 'true',
420
+ reason: null
421
+ };
422
+ }
@@ -205,3 +205,54 @@ export async function runInstallDshHook(args = []) {
205
205
  console.log(' Keep only one to avoid duplicate injection: remove the preset, or run "cwf host remove dsh --component hook".');
206
206
  }
207
207
  }
208
+
209
+
210
+ // Read-only installed-state facts for `host inspect`.
211
+ export async function inspectInstalledState({ env = process.env } = {}) {
212
+ const home = getDshHome(env);
213
+ const pluginDest = join(home, 'plugins', 'cowork-flow', 'workflow-state.js');
214
+ const patchFile = join(home, 'cordis.patch.yml');
215
+ const patch = await readIfExists(patchFile);
216
+ if (patch === null) {
217
+ return {
218
+ status: 'missing',
219
+ version: null,
220
+ payloadPath: pluginDest,
221
+ detailPath: patchFile,
222
+ registeredSource: patchFile,
223
+ enabled: null,
224
+ reason: 'no patch file'
225
+ };
226
+ }
227
+ if (!patch.includes(`- id: ${ROW_ID}`)) {
228
+ return {
229
+ status: 'missing',
230
+ version: null,
231
+ payloadPath: pluginDest,
232
+ detailPath: patchFile,
233
+ registeredSource: patchFile,
234
+ enabled: null,
235
+ reason: 'no managed hook row'
236
+ };
237
+ }
238
+ if (!(await pathExists(pluginDest))) {
239
+ return {
240
+ status: 'broken',
241
+ version: null,
242
+ payloadPath: pluginDest,
243
+ detailPath: pluginDest,
244
+ registeredSource: patchFile,
245
+ enabled: true,
246
+ reason: 'plugin file is missing'
247
+ };
248
+ }
249
+ return {
250
+ status: 'installed',
251
+ version: null,
252
+ payloadPath: pluginDest,
253
+ detailPath: pluginDest,
254
+ registeredSource: patchFile,
255
+ enabled: true,
256
+ reason: null
257
+ };
258
+ }
@@ -34,13 +34,13 @@ const DESKTOP_PERSONA_KEY = /(- id: persona\n(?:.*\n)*? {4})text: /;
34
34
  export const FLAGS = ['--dry-run', '--force', '--uninstall'];
35
35
 
36
36
 
37
- function getDshPresetRoot() {
38
- return join(getDshHome(), '.agent-presets');
37
+ function getDshPresetRoot(env = process.env) {
38
+ return join(getDshHome(env), '.agent-presets');
39
39
  }
40
40
 
41
41
 
42
- function getBundleRoot() {
43
- return join(getDshHome(), 'bundles');
42
+ function getBundleRoot(env = process.env) {
43
+ return join(getDshHome(env), 'bundles');
44
44
  }
45
45
 
46
46
 
@@ -277,3 +277,45 @@ export async function runInstallDshPreset(args = []) {
277
277
  console.log(' desktop - the Plugins page in the sidebar, entering that absolute path');
278
278
  console.log(' Then start a new session; running sessions keep the plugins they started with.');
279
279
  }
280
+
281
+
282
+ // Read-only installed-state facts for `host inspect`.
283
+ export async function inspectInstalledState({ env = process.env } = {}) {
284
+ const presetDir = join(getDshPresetRoot(env), PRESET_ID);
285
+ const bundleDir = join(getBundleRoot(env), PRESET_ID);
286
+ const legacyPresent = await pathExists(presetDir);
287
+ const bundlePresent = await pathExists(bundleDir);
288
+ if (!legacyPresent && !bundlePresent) {
289
+ return {
290
+ status: 'missing',
291
+ version: null,
292
+ payloadPath: null,
293
+ detailPath: null,
294
+ registeredSource: null,
295
+ enabled: null,
296
+ reason: 'no preset directory or bundle'
297
+ };
298
+ }
299
+ const payloadPath = legacyPresent ? presetDir : bundleDir;
300
+ const version = await readInstalledVersion(payloadPath);
301
+ if (version === null) {
302
+ return {
303
+ status: 'broken',
304
+ version: null,
305
+ payloadPath,
306
+ detailPath: join(payloadPath, MARKER_FILE),
307
+ registeredSource: payloadPath,
308
+ enabled: null,
309
+ reason: 'version marker is missing or unreadable'
310
+ };
311
+ }
312
+ return {
313
+ status: 'installed',
314
+ version,
315
+ payloadPath,
316
+ detailPath: join(payloadPath, MARKER_FILE),
317
+ registeredSource: payloadPath,
318
+ enabled: null,
319
+ reason: null
320
+ };
321
+ }
@@ -23,8 +23,8 @@ const LABEL = 'Kimi Code plugin';
23
23
  export const FLAGS = ['--dry-run', '--force', '--uninstall'];
24
24
 
25
25
 
26
- function kimiHome() {
27
- const configured = (process.env.KIMI_CODE_HOME || '').trim();
26
+ function kimiHome(env = process.env) {
27
+ const configured = (env.KIMI_CODE_HOME || '').trim();
28
28
  // The host rejects a relative plugin root; the resolved path is printed to paste.
29
29
  return configured ? resolve(configured) : join(homedir(), '.kimi-code');
30
30
  }
@@ -150,3 +150,62 @@ export async function runInstallKimiPlugin(args = []) {
150
150
  console.log(' Restart Kimi Code to load the plugin.');
151
151
  return 0;
152
152
  }
153
+
154
+
155
+ // Read-only installed-state facts for `host inspect`.
156
+ export async function inspectInstalledState({ env = process.env } = {}) {
157
+ const home = kimiHome(env);
158
+ const registry = installedRegistryPath(home);
159
+ const data = await readJsonFile(registry);
160
+ const entries = Array.isArray(data?.plugins) ? data.plugins : [];
161
+ const record = entries.find(
162
+ (entry) => entry && typeof entry === 'object' && entry.id === KIMI_PLUGIN_ID
163
+ );
164
+ if (!record) {
165
+ return {
166
+ status: 'missing',
167
+ version: null,
168
+ payloadPath: null,
169
+ detailPath: registry,
170
+ registeredSource: registry,
171
+ enabled: null,
172
+ reason: 'no registry record'
173
+ };
174
+ }
175
+ const root = typeof record.root === 'string' && record.root
176
+ ? record.root
177
+ : managedDir(home);
178
+ const enabled = record.enabled !== false;
179
+ const { manifest } = pluginPayload('kimi-code');
180
+ for (const relative of [manifest, 'skills/cowork-flow-bootstrap/SKILL.md']) {
181
+ if (!(await pathExists(join(root, ...relative.split('/'))))) {
182
+ return {
183
+ status: 'broken',
184
+ version: null,
185
+ payloadPath: root,
186
+ detailPath: join(root, ...relative.split('/')),
187
+ registeredSource: registry,
188
+ enabled,
189
+ reason: `missing ${relative}`
190
+ };
191
+ }
192
+ }
193
+ const payloadManifest = await readJsonFile(join(root, ...manifest.split('/')));
194
+ const version = typeof payloadManifest?.version === 'string'
195
+ ? payloadManifest.version
196
+ : null;
197
+ const sourceMissing = !(await pathExists(sourceDir(home)));
198
+ return {
199
+ status: 'installed',
200
+ version,
201
+ payloadPath: root,
202
+ detailPath: !enabled
203
+ ? registry
204
+ : (sourceMissing
205
+ ? sourceDir(home)
206
+ : join(root, ...manifest.split('/'))),
207
+ registeredSource: registry,
208
+ enabled,
209
+ reason: sourceMissing ? 'stable reinstall source directory is missing' : null
210
+ };
211
+ }
@@ -20,6 +20,7 @@ const HOOK_TIMEOUT = 30;
20
20
  // would append a second block.
21
21
  const MANAGED_START = '# cowork-flow: kimi hook start. Managed by "cowork-flow install-kimi-hook"; edits inside this block are replaced.';
22
22
  const MANAGED_END = '# cowork-flow: kimi hook end.';
23
+ const HOOK_START_MARK = '# cowork-flow: kimi hook start.';
23
24
 
24
25
  // Rendered by `host add`/`host remove`. No --force:
25
26
  // installing always rewrites the shim and its managed
@@ -28,8 +29,8 @@ const MANAGED_END = '# cowork-flow: kimi hook end.';
28
29
  export const FLAGS = ['--dry-run', '--uninstall'];
29
30
 
30
31
 
31
- function getKimiHome() {
32
- return process.env.KIMI_CODE_HOME || join(homedir(), '.kimi-code');
32
+ function getKimiHome(env = process.env) {
33
+ return env.KIMI_CODE_HOME || join(homedir(), '.kimi-code');
33
34
  }
34
35
 
35
36
 
@@ -369,3 +370,84 @@ export async function runInstallKimiHook(args = []) {
369
370
 
370
371
  await installHook({ config, home, shim, marker });
371
372
  }
373
+
374
+
375
+ // Read-only installed-state facts for `host inspect`.
376
+ export async function inspectInstalledState({ env = process.env } = {}) {
377
+ const home = getKimiHome(env);
378
+ const config = configFile(home);
379
+ const shim = shimDest(home);
380
+ const marker = markerDest(home);
381
+ const configText = await readIfExists(config);
382
+ if (configText === null) {
383
+ return {
384
+ status: 'missing',
385
+ version: null,
386
+ payloadPath: shim,
387
+ detailPath: config,
388
+ registeredSource: config,
389
+ enabled: null,
390
+ reason: 'config file is absent'
391
+ };
392
+ }
393
+ if (!configText.includes(HOOK_START_MARK)) {
394
+ return {
395
+ status: 'missing',
396
+ version: null,
397
+ payloadPath: shim,
398
+ detailPath: config,
399
+ registeredSource: config,
400
+ enabled: null,
401
+ reason: 'hook block is absent'
402
+ };
403
+ }
404
+ if (!(await pathExists(shim))) {
405
+ return {
406
+ status: 'broken',
407
+ version: null,
408
+ payloadPath: shim,
409
+ detailPath: shim,
410
+ registeredSource: config,
411
+ enabled: true,
412
+ reason: 'shim is missing'
413
+ };
414
+ }
415
+ const markerDocument = await readIfExists(marker);
416
+ if (markerDocument === null) {
417
+ return {
418
+ status: 'broken',
419
+ version: null,
420
+ payloadPath: shim,
421
+ detailPath: marker,
422
+ registeredSource: config,
423
+ enabled: true,
424
+ reason: 'version marker is missing'
425
+ };
426
+ }
427
+ let version = null;
428
+ try {
429
+ version = JSON.parse(markerDocument).version ?? null;
430
+ } catch {
431
+ version = null;
432
+ }
433
+ if (typeof version !== 'string' || version === '') {
434
+ return {
435
+ status: 'broken',
436
+ version: null,
437
+ payloadPath: shim,
438
+ detailPath: marker,
439
+ registeredSource: config,
440
+ enabled: true,
441
+ reason: 'version marker is unreadable'
442
+ };
443
+ }
444
+ return {
445
+ status: 'installed',
446
+ version,
447
+ payloadPath: shim,
448
+ detailPath: marker,
449
+ registeredSource: config,
450
+ enabled: true,
451
+ reason: null
452
+ };
453
+ }
@@ -19,8 +19,8 @@ export const FLAGS = ['--dry-run', '--force', '--uninstall'];
19
19
 
20
20
 
21
21
  // $XDG_CONFIG_HOME/opencode, falling back to ~/.config/opencode — on every platform.
22
- function opencodeHome() {
23
- const configured = (process.env.XDG_CONFIG_HOME || '').trim();
22
+ function opencodeHome(env = process.env) {
23
+ const configured = (env.XDG_CONFIG_HOME || '').trim();
24
24
  return configured ? join(configured, 'opencode') : join(homedir(), '.config', 'opencode');
25
25
  }
26
26
 
@@ -88,3 +88,59 @@ export async function runInstallOpenCodePlugin(args = []) {
88
88
  onDone: () => console.log(' Loads in the next OpenCode session; no marketplace, registry or enable step.')
89
89
  });
90
90
  }
91
+
92
+
93
+ // Read-only installed-state facts for `host inspect`. OpenCode has no version
94
+ // manifest, so version stays null; the doctor compares file contents.
95
+ export async function inspectInstalledState({ env = process.env } = {}) {
96
+ const home = opencodeHome(env);
97
+ const plugin = pluginPath(home);
98
+ const payload = payloadPath(home);
99
+ let installed;
100
+ try {
101
+ installed = await readFile(plugin, 'utf8');
102
+ } catch {
103
+ return {
104
+ status: 'missing',
105
+ version: null,
106
+ payloadPath: payload,
107
+ detailPath: plugin,
108
+ registeredSource: plugin,
109
+ enabled: null,
110
+ reason: 'no plugin file'
111
+ };
112
+ }
113
+ if (!installed.includes(PLUGIN_MARKER)) {
114
+ return {
115
+ status: 'missing',
116
+ version: null,
117
+ payloadPath: payload,
118
+ detailPath: plugin,
119
+ registeredSource: plugin,
120
+ enabled: null,
121
+ reason: 'a different plugin owns this file'
122
+ };
123
+ }
124
+ for (const relative of ['plugin-core.js', 'skills/cowork-flow-bootstrap/SKILL.md']) {
125
+ if (!(await pathExists(join(payload, ...relative.split('/'))))) {
126
+ return {
127
+ status: 'broken',
128
+ version: null,
129
+ payloadPath: payload,
130
+ detailPath: join(payload, ...relative.split('/')),
131
+ registeredSource: plugin,
132
+ enabled: true,
133
+ reason: `missing cowork-flow/${relative}`
134
+ };
135
+ }
136
+ }
137
+ return {
138
+ status: 'installed',
139
+ version: null,
140
+ payloadPath: payload,
141
+ detailPath: plugin,
142
+ registeredSource: plugin,
143
+ enabled: true,
144
+ reason: null
145
+ };
146
+ }
@@ -2,7 +2,7 @@ import { cp, mkdir, readFile, rm } from 'node:fs/promises';
2
2
  import { homedir } from 'node:os';
3
3
  import { join } from 'node:path';
4
4
 
5
- import { parseInstallArgs, pathExists, writeJsonAtomic } from '../lib/install-support.js';
5
+ import { parseInstallArgs, pathExists, readJsonFile, writeJsonAtomic } from '../lib/install-support.js';
6
6
  import { readPackageInfo } from '../lib/package-info.js';
7
7
  import { pluginPayload, stampPayloadManifest } from '../lib/plugin-payload.js';
8
8
 
@@ -16,8 +16,8 @@ const REGISTRY_FILE = 'installed_plugins_v2.json';
16
16
  export const FLAGS = ['--dry-run', '--force', '--uninstall'];
17
17
 
18
18
 
19
- function qoderHome() {
20
- const configured = (process.env.QODER_CONFIG_DIR || '').trim();
19
+ function qoderHome(env = process.env) {
20
+ const configured = (env.QODER_CONFIG_DIR || '').trim();
21
21
  return configured || join(homedir(), '.qoder');
22
22
  }
23
23
 
@@ -202,3 +202,67 @@ export async function runInstallQoderPlugin(args = []) {
202
202
  console.log(' Restart Qoder to load the plugin (the IDE has no hook hot reload).');
203
203
  return 0;
204
204
  }
205
+
206
+
207
+ // Read-only installed-state facts for `host inspect`. The registry and the
208
+ // settings flag are the host's records; the payload files are what a session
209
+ // actually loads.
210
+ export async function inspectInstalledState({ env = process.env } = {}) {
211
+ const home = qoderHome(env);
212
+ const paths = pluginPaths(home, null);
213
+ const registry = await readJsonFile(paths.registry);
214
+ const entries = registry?.plugins?.[PLUGIN_KEY];
215
+ const entry = Array.isArray(entries) ? entries[0] : null;
216
+ if (!entry || typeof entry !== 'object') {
217
+ return {
218
+ status: 'missing',
219
+ version: null,
220
+ payloadPath: null,
221
+ detailPath: paths.registry,
222
+ registeredSource: paths.registry,
223
+ enabled: null,
224
+ reason: 'no registry entry'
225
+ };
226
+ }
227
+ const version = typeof entry.version === 'string' ? entry.version : null;
228
+ const installPath = typeof entry.installPath === 'string' ? entry.installPath : '';
229
+ if (!installPath) {
230
+ return {
231
+ status: 'broken',
232
+ version,
233
+ payloadPath: null,
234
+ detailPath: paths.registry,
235
+ registeredSource: paths.registry,
236
+ enabled: null,
237
+ reason: 'registry entry has no installPath'
238
+ };
239
+ }
240
+ const { manifest } = pluginPayload('qoder');
241
+ for (const relative of [manifest, 'hooks/hooks.json', 'hooks/inject-context.mjs']) {
242
+ if (!(await pathExists(join(installPath, ...relative.split('/'))))) {
243
+ const role = relative === manifest ? 'payload manifest' : 'required file';
244
+ return {
245
+ status: 'broken',
246
+ version,
247
+ payloadPath: installPath,
248
+ detailPath: join(installPath, ...relative.split('/')),
249
+ registeredSource: paths.registry,
250
+ enabled: null,
251
+ reason: `missing ${relative} (${role})`
252
+ };
253
+ }
254
+ }
255
+ const settings = await readJsonFile(paths.settings);
256
+ const enabled = settings?.enabledPlugins?.[PLUGIN_KEY] === true;
257
+ return {
258
+ status: 'installed',
259
+ version,
260
+ payloadPath: installPath,
261
+ detailPath: enabled
262
+ ? join(installPath, ...manifest.split('/'))
263
+ : paths.settings,
264
+ registeredSource: paths.registry,
265
+ enabled,
266
+ reason: enabled ? null : 'enable flag is not true'
267
+ };
268
+ }
@@ -18,8 +18,8 @@ const LOCAL_MARKETPLACE_DESCRIPTION = 'Local marketplace registration for cowork
18
18
  export const FLAGS = ['--dry-run', '--force', '--prune-old', '--uninstall'];
19
19
 
20
20
 
21
- function getZCodePluginsRoot() {
22
- const base = process.env.ZCODE_HOME || join(homedir(), '.zcode');
21
+ function getZCodePluginsRoot(env = process.env) {
22
+ const base = env.ZCODE_HOME || join(homedir(), '.zcode');
23
23
  return join(base, 'cli', 'plugins');
24
24
  }
25
25
 
@@ -324,3 +324,78 @@ export async function runInstallZCodePlugin(args = []) {
324
324
  console.log(`✓ cowork-flow ZCode plugin installed to ${destDir}`);
325
325
  console.log(' Restart ZCode to load the plugin.');
326
326
  }
327
+
328
+
329
+ // Read-only installed-state facts for `host inspect`. The active marketplace
330
+ // record is the registration; the payload manifest carries the installed
331
+ // version.
332
+ export async function inspectInstalledState({ env = process.env } = {}) {
333
+ const pluginsRoot = getZCodePluginsRoot(env);
334
+ const { activeMarketplacePath } = marketplacePaths(pluginsRoot);
335
+ const market = await readJsonFile(activeMarketplacePath);
336
+ const plugins = Array.isArray(market?.plugins) ? market.plugins : [];
337
+ const entry = plugins.find((plugin) => plugin?.name === PLUGIN_NAME) ?? null;
338
+ if (!entry) {
339
+ return {
340
+ status: 'missing',
341
+ version: null,
342
+ payloadPath: null,
343
+ detailPath: activeMarketplacePath,
344
+ registeredSource: activeMarketplacePath,
345
+ enabled: null,
346
+ reason: 'no marketplace entry'
347
+ };
348
+ }
349
+ const source = entry.source;
350
+ const payloadPath = source && typeof source === 'object'
351
+ && typeof source.path === 'string'
352
+ ? source.path
353
+ : null;
354
+ if (!payloadPath) {
355
+ return {
356
+ status: 'broken',
357
+ version: null,
358
+ payloadPath: null,
359
+ detailPath: activeMarketplacePath,
360
+ registeredSource: activeMarketplacePath,
361
+ enabled: null,
362
+ reason: 'marketplace entry has no payload path'
363
+ };
364
+ }
365
+ if (!(await pathExists(payloadPath))) {
366
+ return {
367
+ status: 'broken',
368
+ version: null,
369
+ payloadPath,
370
+ detailPath: payloadPath,
371
+ registeredSource: activeMarketplacePath,
372
+ enabled: null,
373
+ reason: 'payload directory is missing'
374
+ };
375
+ }
376
+ const { manifest } = pluginPayload('zcode');
377
+ const payloadManifest = await readJsonFile(join(payloadPath, ...manifest.split('/')));
378
+ const version = typeof payloadManifest?.version === 'string'
379
+ ? payloadManifest.version
380
+ : null;
381
+ if (version === null) {
382
+ return {
383
+ status: 'broken',
384
+ version: null,
385
+ payloadPath,
386
+ detailPath: join(payloadPath, ...manifest.split('/')),
387
+ registeredSource: activeMarketplacePath,
388
+ enabled: null,
389
+ reason: 'payload manifest has no version'
390
+ };
391
+ }
392
+ return {
393
+ status: 'installed',
394
+ version,
395
+ payloadPath,
396
+ detailPath: join(payloadPath, ...manifest.split('/')),
397
+ registeredSource: activeMarketplacePath,
398
+ enabled: null,
399
+ reason: null
400
+ };
401
+ }