@kirkchinese/harness-forge-core 0.4.0 → 0.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.
- package/lib/assess.js +24 -4
- package/lib/contracts.d.ts +1 -1
- package/lib/dialects/claude-code/index.js +38 -41
- package/lib/dialects/claude-code/sessions/discover.js +31 -17
- package/lib/dialects/claude-code/sessions/parse.js +89 -83
- package/lib/dialects/claude-code/sessions/title.d.ts +23 -0
- package/lib/dialects/claude-code/sessions/title.js +74 -0
- package/lib/dialects/claude-code/statusline.d.ts +12 -0
- package/lib/dialects/claude-code/statusline.js +74 -0
- package/lib/dialects/claude-code/user-assets.d.ts +37 -6
- package/lib/dialects/claude-code/user-assets.js +155 -34
- package/lib/dialects/codex/index.js +8 -1
- package/lib/dialects/codex/mcp-server.d.ts +17 -0
- package/lib/dialects/codex/mcp-server.js +116 -0
- package/lib/dialects/codex/plugins.d.ts +16 -0
- package/lib/dialects/codex/plugins.js +120 -0
- package/lib/dialects/codex/user-assets.d.ts +10 -6
- package/lib/dialects/codex/user-assets.js +26 -42
- package/lib/dialects/opencode/index.js +43 -8
- package/lib/dialects/opencode/inventory.d.ts +100 -0
- package/lib/dialects/opencode/inventory.js +318 -0
- package/lib/dialects/opencode/plugin-id.d.ts +21 -0
- package/lib/dialects/opencode/plugin-id.js +296 -0
- package/lib/dialects/opencode/scan.d.ts +22 -0
- package/lib/dialects/opencode/scan.js +119 -121
- package/lib/dialects/types.d.ts +60 -6
- package/lib/discover.d.ts +32 -7
- package/lib/discover.js +58 -17
- package/lib/fingerprint.js +7 -0
- package/lib/harness-installs.d.ts +42 -0
- package/lib/harness-installs.js +59 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +5 -0
- package/lib/instructions.d.ts +28 -2
- package/lib/instructions.js +202 -30
- package/lib/license.js +12 -11
- package/lib/manifest.d.ts +6 -0
- package/lib/manifest.js +41 -12
- package/lib/marketplace.d.ts +15 -1
- package/lib/marketplace.js +55 -38
- package/lib/paths.d.ts +65 -0
- package/lib/paths.js +152 -2
- package/lib/plan.js +3 -1
- package/lib/port-brief.d.ts +28 -5
- package/lib/port-brief.js +52 -10
- package/lib/remote.d.ts +121 -0
- package/lib/remote.js +352 -0
- package/lib/sessions/index.d.ts +1 -0
- package/lib/sessions/index.js +1 -0
- package/lib/sessions/lines.d.ts +57 -0
- package/lib/sessions/lines.js +122 -0
- package/lib/text.d.ts +9 -0
- package/lib/text.js +19 -0
- package/lib/trust.js +19 -6
- package/lib/types.d.ts +48 -1
- package/package.json +1 -1
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
* @module @kirkchinese/harness-forge-core
|
|
6
6
|
*/
|
|
7
7
|
import { readdirSync } from 'node:fs';
|
|
8
|
-
import { basename, dirname, join
|
|
8
|
+
import { basename, dirname, join } from 'node:path';
|
|
9
|
+
import { openCodeConfigFiles, openCodeInventory, pluginEntryOf } from './inventory.js';
|
|
9
10
|
import { childId, kebabCase, pluginId, uniqueName } from '../../naming.js';
|
|
10
11
|
import { fingerprintPlugin } from '../../fingerprint.js';
|
|
11
|
-
import { childDirectories, isDirectory, isFile, isInside, isPlainObject, readJsonObject, readText, stem, toPosix, } from '../../paths.js';
|
|
12
|
+
import { childDirectories, isDirectory, isFile, isInside, isPlainObject, leadsToShare, readJsonObject, readText, stem, toPosix, } from '../../paths.js';
|
|
12
13
|
import { parseSkillFrontmatter, readMarkdownAsset } from '../../frontmatter.js';
|
|
13
14
|
/** Strip JSONC comments and trailing commas without touching string literals. */
|
|
14
15
|
export function stripJsonc(text) {
|
|
@@ -184,6 +185,7 @@ export function scanOpenCodeProject(root, options = {}) {
|
|
|
184
185
|
id: childId(id, 'mcp', nameSafe),
|
|
185
186
|
kind: 'mcp',
|
|
186
187
|
name: nameSafe,
|
|
188
|
+
declaredName: serverName,
|
|
187
189
|
transport: type === 'remote' || url !== undefined ? 'streamable-http' : command !== undefined ? 'stdio' : 'unknown',
|
|
188
190
|
...(command !== undefined ? { command } : {}),
|
|
189
191
|
...(url !== undefined ? { url } : {}),
|
|
@@ -193,83 +195,46 @@ export function scanOpenCodeProject(root, options = {}) {
|
|
|
193
195
|
};
|
|
194
196
|
components.push(component);
|
|
195
197
|
}
|
|
196
|
-
//
|
|
197
|
-
//
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
198
|
+
// The plugins OpenCode loads for this project: configured entries and the `.opencode/plugin(s)/` folders.
|
|
199
|
+
// Only what lies inside the project is read as its code; a package from elsewhere is reported by its spec.
|
|
200
|
+
// A plugin the project's config switches off, or may switch off, is not surely OpenCode's to run here, and is left out.
|
|
201
|
+
const inventory = openCodeInventory({ configDir: join(root, '.opencode'), configFiles: [...openCodeConfigFiles(root), ...openCodeConfigFiles(join(root, '.opencode'))] });
|
|
202
|
+
warnings.push(...inventory.warnings);
|
|
203
|
+
for (const entry of inventory.entries) {
|
|
204
|
+
if (entry.enabled !== true) {
|
|
205
|
+
warnings.push(leftOut(entry));
|
|
202
206
|
continue;
|
|
203
|
-
const local = spec.startsWith('.') || spec.startsWith('/') || spec.startsWith('file:');
|
|
204
|
-
const path = local ? join(root, spec.replace(/^file:/u, '')) : undefined;
|
|
205
|
-
const entryPath = path !== undefined && isInside(root, path) && isDirectory(path) ? pluginEntryOf(path) : undefined;
|
|
206
|
-
if (path !== undefined && entryPath !== undefined) {
|
|
207
|
-
const codeName = uniqueName(stem(path), usedCodeNames, path);
|
|
208
|
-
usedCodeNames.add(codeName);
|
|
209
|
-
const component = {
|
|
210
|
-
id: childId(id, 'code', codeName),
|
|
211
|
-
kind: 'code',
|
|
212
|
-
name: codeName,
|
|
213
|
-
runtime: 'opencode-plugin',
|
|
214
|
-
entryPath,
|
|
215
|
-
path: toPosix(entryPath.slice(root.length + 1)),
|
|
216
|
-
};
|
|
217
|
-
components.push(component);
|
|
218
207
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
208
|
+
const entryPath = entry.kind === 'file' ? entry.path : entry.kind === 'package' ? entry.entryPath : undefined;
|
|
209
|
+
if (entryPath !== undefined && isInside(root, entryPath)) {
|
|
210
|
+
components.push(codeComponent(id, root, entry.kind === 'package' ? entry.root : entryPath, entryPath, usedCodeNames));
|
|
211
|
+
}
|
|
212
|
+
else if (entry.kind !== 'file' && entry.spec !== undefined) {
|
|
213
|
+
const local = entry.kind === 'package' && isInside(root, entry.root);
|
|
214
|
+
components.push({
|
|
215
|
+
id: childId(id, 'other', entry.spec),
|
|
222
216
|
kind: 'other',
|
|
223
217
|
originalKind: 'opencode-plugin-package',
|
|
224
|
-
name: spec,
|
|
225
|
-
description:
|
|
226
|
-
|
|
227
|
-
: 'OpenCode local plugin has no index/server entry',
|
|
228
|
-
};
|
|
229
|
-
components.push(component);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
// Plugins OpenCode discovers on its own: files and package directories under `.opencode/plugin(s)/`.
|
|
233
|
-
for (const dir of [join(root, '.opencode', 'plugins'), join(root, '.opencode', 'plugin')]) {
|
|
234
|
-
let entries = [];
|
|
235
|
-
try {
|
|
236
|
-
entries = readdirSync(dir);
|
|
237
|
-
}
|
|
238
|
-
catch {
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
for (const entry of entries.sort((a, b) => a.localeCompare(b, 'en'))) {
|
|
242
|
-
const path = join(dir, entry);
|
|
243
|
-
const entryPath = isFile(path) && /\.(ts|tsx|js|mjs)$/u.test(entry) ? path : isDirectory(path) ? pluginEntryOf(path) : undefined;
|
|
244
|
-
if (entryPath === undefined || !isInside(root, entryPath))
|
|
245
|
-
continue;
|
|
246
|
-
const codeName = uniqueName(stem(entry), usedCodeNames, entryPath);
|
|
247
|
-
usedCodeNames.add(codeName);
|
|
248
|
-
components.push({ id: childId(id, 'code', codeName), kind: 'code', name: codeName, runtime: 'opencode-plugin', entryPath, path: toPosix(entryPath.slice(root.length + 1)) });
|
|
218
|
+
name: entry.spec,
|
|
219
|
+
description: local ? 'OpenCode local plugin has no index/server entry' : 'OpenCode npm/git plugin package; not loaded by the preview shim',
|
|
220
|
+
});
|
|
249
221
|
}
|
|
250
222
|
}
|
|
251
|
-
// The directory is itself a plugin package: it depends on OpenCode's plugin SDK
|
|
223
|
+
// The directory is itself a plugin package: it depends on OpenCode's plugin SDK, or it is a bare package
|
|
224
|
+
// directory OpenCode loads from a plugins folder (no config of its own, no `.opencode/`).
|
|
252
225
|
const declared = {
|
|
253
226
|
...(packageJson !== undefined && isPlainObject(packageJson['dependencies']) ? packageJson['dependencies'] : {}),
|
|
254
227
|
...(packageJson !== undefined && isPlainObject(packageJson['peerDependencies']) ? packageJson['peerDependencies'] : {}),
|
|
255
228
|
};
|
|
256
|
-
const
|
|
229
|
+
const bare = openCodeConfigFiles(root).length === 0 && !isDirectory(join(root, '.opencode'));
|
|
230
|
+
const isCodePackage = bare || Object.keys(declared).some(name => name === '@opencode-ai/plugin' || name === '@opencode/plugin');
|
|
257
231
|
if (isCodePackage && !components.some(component => component.kind === 'code')) {
|
|
258
232
|
const entryPath = pluginEntryOf(root);
|
|
259
|
-
if (entryPath !== undefined && isInside(root, entryPath))
|
|
260
|
-
|
|
261
|
-
usedCodeNames.add(codeName);
|
|
262
|
-
components.push({
|
|
263
|
-
id: childId(id, 'code', codeName),
|
|
264
|
-
kind: 'code',
|
|
265
|
-
name: codeName,
|
|
266
|
-
runtime: 'opencode-plugin',
|
|
267
|
-
entryPath,
|
|
268
|
-
path: toPosix(entryPath.slice(root.length + 1)),
|
|
269
|
-
});
|
|
270
|
-
}
|
|
233
|
+
if (entryPath !== undefined && isInside(root, entryPath))
|
|
234
|
+
components.push(codeComponent(id, root, entryPath, entryPath, usedCodeNames));
|
|
271
235
|
}
|
|
272
236
|
const problems = components.length === 0 ? ['no OpenCode components found'] : [];
|
|
237
|
+
warnings.push(...problems);
|
|
273
238
|
const plugin = {
|
|
274
239
|
id,
|
|
275
240
|
source: 'opencode',
|
|
@@ -285,73 +250,106 @@ export function scanOpenCodeProject(root, options = {}) {
|
|
|
285
250
|
manifestKind: 'opencode',
|
|
286
251
|
},
|
|
287
252
|
components,
|
|
288
|
-
warnings:
|
|
253
|
+
warnings: [
|
|
254
|
+
...warnings.filter(message => !problems.includes(message)).map(message => ({ code: 'opencode-plugin', message })),
|
|
255
|
+
...problems.map(message => ({ code: 'opencode-empty', message })),
|
|
256
|
+
],
|
|
289
257
|
manifest: config,
|
|
290
258
|
};
|
|
291
|
-
return { plugin: { ...plugin, fingerprint: fingerprintPlugin(plugin) }, warnings
|
|
259
|
+
return { plugin: { ...plugin, fingerprint: fingerprintPlugin(plugin) }, warnings };
|
|
260
|
+
}
|
|
261
|
+
/** A code component OpenCode runs: `named` gives its name (a package directory, or the file itself). */
|
|
262
|
+
function codeComponent(id, root, named, entryPath, used) {
|
|
263
|
+
const name = uniqueName(stem(named), used, entryPath);
|
|
264
|
+
used.add(name);
|
|
265
|
+
return { id: childId(id, 'code', name), kind: 'code', name, runtime: 'opencode-plugin', entryPath, path: toPosix(entryPath.slice(root.length + 1)) };
|
|
266
|
+
}
|
|
267
|
+
/** OpenCode's global config directory (https://opencode.ai/docs/plugins/: "Global plugins use the same discovery layout under the OpenCode config directory"). */
|
|
268
|
+
export function openCodeConfigDir(home) {
|
|
269
|
+
return join(home, '.config', 'opencode');
|
|
270
|
+
}
|
|
271
|
+
/** OpenCode's package cache, where V1 installed npm plugins (https://opencode.ai/v1/docs/plugins.md: "cached in ~/.cache/opencode/node_modules/"). */
|
|
272
|
+
export function openCodeCacheDir(home) {
|
|
273
|
+
return join(home, '.cache', 'opencode');
|
|
274
|
+
}
|
|
275
|
+
/** Where OpenCode keeps a global config directory's plugins, its npm cache included. */
|
|
276
|
+
export function openCodeGlobalLocation(home) {
|
|
277
|
+
const configDir = openCodeConfigDir(home);
|
|
278
|
+
return { configDir, configFiles: openCodeConfigFiles(configDir), cacheDir: openCodeCacheDir(home) };
|
|
279
|
+
}
|
|
280
|
+
/** What a plugin of the inventory is called in a warning: its file, folder or spec. */
|
|
281
|
+
function pluginLabel(entry) {
|
|
282
|
+
return `OpenCode plugin ${entry.kind === 'file' ? entry.path : entry.kind === 'package' ? entry.root : entry.spec}`;
|
|
283
|
+
}
|
|
284
|
+
/** Why a plugin OpenCode may not run is left out: it is switched off, or its id does not tell whether it is. */
|
|
285
|
+
function leftOut(entry) {
|
|
286
|
+
return !('unknownBecause' in entry)
|
|
287
|
+
? `${pluginLabel(entry)} is switched off in OpenCode's config and is left out`
|
|
288
|
+
: `${pluginLabel(entry)} is left out: an entry in OpenCode's config switches plugins by id, and its id ${ID_PROBLEM_TEXT[entry.unknownBecause]}, so whether OpenCode runs it cannot be told`;
|
|
289
|
+
}
|
|
290
|
+
/** How a warning says why a plugin's id cannot be told. */
|
|
291
|
+
const ID_PROBLEM_TEXT = {
|
|
292
|
+
missing: 'is declared by no Plugin.define({ id }) Harness Forge can read',
|
|
293
|
+
ambiguous: 'is declared more than once',
|
|
294
|
+
dynamic: 'is computed, not a plain string',
|
|
295
|
+
escape: 'is written with an escape JavaScript refuses in a module',
|
|
296
|
+
};
|
|
297
|
+
/** The plugin files right in OpenCode's global plugins folder, with whether OpenCode runs each. */
|
|
298
|
+
function userPluginFiles(home) {
|
|
299
|
+
const inventory = openCodeInventory(openCodeGlobalLocation(home));
|
|
300
|
+
return { files: inventory.entries.filter((entry) => entry.kind === 'file'), warnings: inventory.warnings };
|
|
292
301
|
}
|
|
293
302
|
/**
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
* source checkout whose build output is absent runs from its TypeScript
|
|
297
|
-
* source (`dist/x.js` → `src/x.ts` or `x.ts`), as Bun runs it.
|
|
303
|
+
* Whether OpenCode runs the person's plugin files: on when it surely runs one; else not known when it may run one
|
|
304
|
+
* (why, from the first such file), else off when its config switches off every one.
|
|
298
305
|
*/
|
|
299
|
-
function
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const
|
|
304
|
-
if (
|
|
305
|
-
return
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
306
|
+
export function openCodeUserEnablement(home) {
|
|
307
|
+
const { files } = userPluginFiles(home);
|
|
308
|
+
if (files.length === 0 || files.some(file => file.enabled === true))
|
|
309
|
+
return { enabled: true };
|
|
310
|
+
for (const file of files)
|
|
311
|
+
if ('unknownBecause' in file)
|
|
312
|
+
return { enabledUnknown: file.unknownBecause };
|
|
313
|
+
return { enabled: false };
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* The plugin files a person keeps right in OpenCode's global plugins folder, as one plugin `opencode:user`
|
|
317
|
+
* rooted at the config directory (where OpenCode installs their dependencies). Package directories and
|
|
318
|
+
* configured packages are plugins of their own (`harnessPlugins`). When OpenCode surely runs some files, the others
|
|
319
|
+
* (switched off, or not known to run) are left out, with why; else the plugin holds them all, and is off or not
|
|
320
|
+
* known to run ({@link openCodeUserEnablement}).
|
|
321
|
+
* @returns undefined when there is no such file.
|
|
322
|
+
*/
|
|
323
|
+
export function scanOpenCodeUser(home) {
|
|
324
|
+
const root = openCodeConfigDir(home);
|
|
325
|
+
const id = pluginId('opencode', 'user');
|
|
326
|
+
const used = new Set();
|
|
327
|
+
const { files, warnings } = userPluginFiles(home);
|
|
328
|
+
const running = files.some(file => file.enabled === true);
|
|
329
|
+
const kept = running ? files.filter(file => file.enabled === true) : files;
|
|
330
|
+
const components = kept.map(file => codeComponent(id, root, file.path, file.path, used));
|
|
331
|
+
if (components.length === 0)
|
|
313
332
|
return undefined;
|
|
333
|
+
const manifest = { name: 'user', scope: 'user', description: 'OpenCode plugin files (~/.config/opencode/plugins)' };
|
|
334
|
+
const left = running ? files.filter(file => file.enabled !== true).map(leftOut) : [];
|
|
335
|
+
const plugin = {
|
|
336
|
+
id,
|
|
337
|
+
source: 'opencode',
|
|
338
|
+
name: 'user',
|
|
339
|
+
description: manifest.description,
|
|
340
|
+
root,
|
|
341
|
+
ref: { kind: 'opencode', root, manifestPath: join(root, 'opencode.json'), manifestKind: 'opencode' },
|
|
342
|
+
components,
|
|
343
|
+
warnings: [...warnings, ...left].map(message => ({ code: 'opencode-plugin', message })),
|
|
344
|
+
manifest,
|
|
314
345
|
};
|
|
315
|
-
|
|
316
|
-
targets.push(exportsField);
|
|
317
|
-
else if (isPlainObject(exportsField)) {
|
|
318
|
-
for (const key of ['./server', '.']) {
|
|
319
|
-
const target = conditional(exportsField[key]);
|
|
320
|
-
if (target !== undefined)
|
|
321
|
-
targets.push(target);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
for (const key of ['main', 'module'])
|
|
325
|
-
if (typeof packageJson?.[key] === 'string')
|
|
326
|
-
targets.push(packageJson[key]);
|
|
327
|
-
for (const target of targets) {
|
|
328
|
-
const resolved = resolve(directory, target);
|
|
329
|
-
if (isFile(resolved))
|
|
330
|
-
return resolved;
|
|
331
|
-
const source = sourceOf(directory, target);
|
|
332
|
-
if (source !== undefined)
|
|
333
|
-
return source;
|
|
334
|
-
}
|
|
335
|
-
for (const name of ['server.ts', 'server.tsx', 'server.js', 'index.ts', 'index.tsx', 'index.js', 'index.mjs']) {
|
|
336
|
-
const candidate = join(directory, name);
|
|
337
|
-
if (isFile(candidate))
|
|
338
|
-
return candidate;
|
|
339
|
-
}
|
|
340
|
-
return undefined;
|
|
341
|
-
}
|
|
342
|
-
/** The TypeScript source of a build output path, when the checkout has it. */
|
|
343
|
-
function sourceOf(directory, target) {
|
|
344
|
-
const relative = target.replace(/^\.\//u, '').replace(/^(dist|build|lib|out)\//u, '').replace(/\.(m|c)?js$/u, '');
|
|
345
|
-
for (const candidate of [`src/${relative}.ts`, `src/${relative}.tsx`, `${relative}.ts`, `${relative}.tsx`]) {
|
|
346
|
-
const path = join(directory, candidate);
|
|
347
|
-
if (isFile(path))
|
|
348
|
-
return path;
|
|
349
|
-
}
|
|
350
|
-
return undefined;
|
|
346
|
+
return { ...plugin, fingerprint: fingerprintPlugin(plugin) };
|
|
351
347
|
}
|
|
352
348
|
function walkMarkdown(root) {
|
|
353
349
|
const out = [];
|
|
354
350
|
const walk = (dir) => {
|
|
351
|
+
if (leadsToShare(dir))
|
|
352
|
+
return;
|
|
355
353
|
try {
|
|
356
354
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
357
355
|
const path = join(dir, entry.name);
|
package/lib/dialects/types.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { ForeignPlugin, SourceId } from '../types.js';
|
|
9
9
|
import type { SessionSourceAdapter } from '../sessions/adapter.js';
|
|
10
|
+
import type { PluginIdProblem } from './opencode/plugin-id.js';
|
|
10
11
|
/**
|
|
11
12
|
* Something at a directory that says which dialect it speaks. Detection takes
|
|
12
13
|
* the first match of the strongest tier, in registry order: a manifest beats
|
|
@@ -24,13 +25,46 @@ export interface DialectMarker {
|
|
|
24
25
|
readonly listedOnly?: boolean;
|
|
25
26
|
test(directory: string): boolean;
|
|
26
27
|
}
|
|
27
|
-
/** One plugin the harness itself has installed
|
|
28
|
+
/** One plugin the harness itself has installed. */
|
|
28
29
|
export interface HarnessPluginEntry {
|
|
29
30
|
readonly root: string;
|
|
30
|
-
|
|
31
|
+
/**
|
|
32
|
+
* What the harness knows the install by, stable across its updates: Claude Code and Codex `<name>@<marketplace>`
|
|
33
|
+
* (a new version goes into a folder of its own), OpenCode the package folder (an update rewrites it in place).
|
|
34
|
+
*/
|
|
35
|
+
readonly key: string;
|
|
31
36
|
readonly enabled?: boolean;
|
|
37
|
+
/** Set instead of `enabled` when whether the harness runs it cannot be told: why (an OpenCode plugin id its source does not settle). */
|
|
38
|
+
readonly enabledUnknown?: PluginIdProblem;
|
|
32
39
|
readonly marketplace?: string;
|
|
33
40
|
}
|
|
41
|
+
/** An install the harness records whose files are not where the record says: still installed, not readable now. */
|
|
42
|
+
export interface UnresolvedHarnessPlugin {
|
|
43
|
+
readonly key: string;
|
|
44
|
+
readonly message: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The plugins a harness records, and how much of its record could be read. A plugin missing from `entries` is not
|
|
48
|
+
* installed only when `unread` is empty (a complete read) and it is not `unresolved`.
|
|
49
|
+
*/
|
|
50
|
+
export interface HarnessPluginList {
|
|
51
|
+
readonly entries: readonly HarnessPluginEntry[];
|
|
52
|
+
readonly unresolved: readonly UnresolvedHarnessPlugin[];
|
|
53
|
+
/** What of the record could not be read (a malformed or cut-off file, a folder that could not be listed), each saying why. */
|
|
54
|
+
readonly unread: readonly string[];
|
|
55
|
+
}
|
|
56
|
+
/** Whether a harness runs the person's own assets, or why that cannot be told. */
|
|
57
|
+
export type UserEnablement = {
|
|
58
|
+
readonly enabled: boolean;
|
|
59
|
+
} | {
|
|
60
|
+
readonly enabledUnknown: PluginIdProblem;
|
|
61
|
+
};
|
|
62
|
+
/** A marketplace the harness added that has a local copy: what it offers can be installed one by one. */
|
|
63
|
+
export interface HarnessMarketplace {
|
|
64
|
+
readonly name: string;
|
|
65
|
+
/** The marketplace's root folder (it holds `.claude-plugin/marketplace.json` or `.agents/plugins/marketplace.json`). */
|
|
66
|
+
readonly root: string;
|
|
67
|
+
}
|
|
34
68
|
/** Options of {@link Dialect.scan}. */
|
|
35
69
|
export interface DialectScanOptions {
|
|
36
70
|
/** Plugin name to use instead of the manifest's (a second plugin of the same name). */
|
|
@@ -57,16 +91,36 @@ export interface Dialect {
|
|
|
57
91
|
/** The discovery root that lists them. */
|
|
58
92
|
anchor(home: string): string;
|
|
59
93
|
scan(home: string): ForeignPlugin | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Whether the harness runs them: off when it switches off every one (OpenCode's `-*`), or not known, with why.
|
|
96
|
+
* Absent: on. Discovery lists them either way.
|
|
97
|
+
*/
|
|
98
|
+
enablement?(home: string): UserEnablement;
|
|
60
99
|
/** What the directory lacks when `scan` finds nothing, for the error. */
|
|
61
100
|
readonly emptyMessage: string;
|
|
62
101
|
};
|
|
63
102
|
/**
|
|
64
|
-
*
|
|
65
|
-
* is read through
|
|
103
|
+
* The plugins the harness has installed, as it records them. A folder of
|
|
104
|
+
* `roots` that is a discovery root is read through `list` instead of being
|
|
105
|
+
* walked, so a cached version or a marketplace offer the person never
|
|
106
|
+
* installed is not listed (nor migrated). Each plugin is read through this
|
|
107
|
+
* dialect: the harness that installed it is the one it belongs to.
|
|
66
108
|
*/
|
|
67
109
|
readonly harnessPlugins?: {
|
|
68
|
-
|
|
69
|
-
|
|
110
|
+
roots(home: string): string[];
|
|
111
|
+
/**
|
|
112
|
+
* The plugins recorded for `root`. A record entry that cannot be read is skipped and reported in `unread`, naming
|
|
113
|
+
* it: it must not cost the others, nor the other harnesses' plugins.
|
|
114
|
+
*/
|
|
115
|
+
list(home: string, root: string): HarnessPluginList;
|
|
116
|
+
/** The marketplaces the harness added, with a local copy, to browse under "Get plugins". */
|
|
117
|
+
marketplaces?(home: string): HarnessMarketplace[];
|
|
118
|
+
/**
|
|
119
|
+
* The key ({@link HarnessPluginEntry.key}) a folder of the harness's own install layout stands for, whether or
|
|
120
|
+
* not the harness still lists it: how a ledger written before installs carried their key learns it.
|
|
121
|
+
* @param name - the plugin's own name, for a layout that does not spell it.
|
|
122
|
+
*/
|
|
123
|
+
identify?(home: string, root: string, name: string): string | undefined;
|
|
70
124
|
};
|
|
71
125
|
/** The project assets of a session starting in `cwd`, as one plugin. */
|
|
72
126
|
projectAssets?(cwd: string, home: string): ForeignPlugin | undefined;
|
package/lib/discover.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ComponentCounts, type SourceId } from './types.js';
|
|
2
|
+
import type { PluginIdProblem } from './dialects/opencode/plugin-id.js';
|
|
2
3
|
/** One discovered plugin root. */
|
|
3
4
|
export interface DiscoveredPlugin {
|
|
4
5
|
readonly root: string;
|
|
@@ -11,20 +12,42 @@ export interface DiscoveredPlugin {
|
|
|
11
12
|
readonly components: ComponentCounts;
|
|
12
13
|
/**
|
|
13
14
|
* Where it was found: the user's own assets, a plugin the harness has
|
|
14
|
-
* installed, a plugin a marketplace offers but the harness has not
|
|
15
15
|
* installed, or a plugin directory under a discovery root.
|
|
16
16
|
*/
|
|
17
|
-
readonly origin: 'user' | 'installed' | '
|
|
18
|
-
/**
|
|
17
|
+
readonly origin: 'user' | 'installed' | 'directory';
|
|
18
|
+
/** Whether the harness runs it: set for an installed plugin, and `false` for user assets it switches off. */
|
|
19
19
|
readonly enabled?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Set instead of `enabled` when whether the harness runs it cannot be told, saying why: an OpenCode plugin whose
|
|
22
|
+
* id its source does not settle (`missing`, `ambiguous`, `dynamic`), under an entry that switches plugins by id.
|
|
23
|
+
*/
|
|
24
|
+
readonly enabledUnknown?: PluginIdProblem;
|
|
20
25
|
/** The marketplace that offers it. */
|
|
21
26
|
readonly marketplace?: string;
|
|
27
|
+
/** What its harness knows an installed plugin by, across updates (see `HarnessPluginEntry.key`). */
|
|
28
|
+
readonly installKey?: string;
|
|
29
|
+
}
|
|
30
|
+
/** A marketplace a harness added, with a local copy: its plugins are offers, installed one by one, never discovered. */
|
|
31
|
+
export interface DiscoveredMarketplace {
|
|
32
|
+
readonly source: SourceId;
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly root: string;
|
|
35
|
+
}
|
|
36
|
+
/** Something discovery could not read: it was skipped, and the rest was found. */
|
|
37
|
+
export interface DiscoveryWarning {
|
|
38
|
+
/** The harness whose record or assets it is. */
|
|
39
|
+
readonly source: SourceId;
|
|
40
|
+
/** What was skipped, named, and why. */
|
|
41
|
+
readonly message: string;
|
|
22
42
|
}
|
|
23
|
-
/** Discovery output. Missing roots are reported, not treated as fatal. */
|
|
43
|
+
/** Discovery output. Missing roots and unreadable entries are reported, not treated as fatal. */
|
|
24
44
|
export interface DiscoveryResult {
|
|
25
45
|
readonly plugins: readonly DiscoveredPlugin[];
|
|
46
|
+
/** The local marketplaces of the harnesses whose plugin folder is a root. */
|
|
47
|
+
readonly marketplaces: readonly DiscoveredMarketplace[];
|
|
26
48
|
readonly roots: readonly string[];
|
|
27
49
|
readonly missingRoots: readonly string[];
|
|
50
|
+
readonly warnings: readonly DiscoveryWarning[];
|
|
28
51
|
}
|
|
29
52
|
/** Options for a filesystem walk. */
|
|
30
53
|
export interface DiscoverOptions {
|
|
@@ -38,9 +61,11 @@ export declare function defaultDiscoveryRoots(home?: string): string[];
|
|
|
38
61
|
/**
|
|
39
62
|
* Discover plugin roots under the given directories. A dialect's user assets
|
|
40
63
|
* are listed when its anchor folder is a root, even when that folder does not
|
|
41
|
-
* exist. A harness that records its plugins (Claude Code
|
|
42
|
-
* folder read through that record
|
|
43
|
-
*
|
|
64
|
+
* exist. A harness that records its plugins (Claude Code, Codex, OpenCode)
|
|
65
|
+
* has its plugin folder read through that record: the plugins it installed,
|
|
66
|
+
* one version each, read as that harness's plugins. Cached versions and
|
|
67
|
+
* marketplace offers are not plugins of the person's; the marketplaces that
|
|
68
|
+
* offer them are listed apart.
|
|
44
69
|
*/
|
|
45
70
|
export declare function discoverPlugins(roots: readonly string[], options?: DiscoverOptions): DiscoveryResult;
|
|
46
71
|
/**
|
package/lib/discover.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { readdirSync } from 'node:fs';
|
|
8
8
|
import { homedir } from 'node:os';
|
|
9
9
|
import { join, resolve } from 'node:path';
|
|
10
|
-
import { isDirectory } from './paths.js';
|
|
10
|
+
import { isDirectory, leadsToShare } from './paths.js';
|
|
11
11
|
import { countComponents } from './types.js';
|
|
12
12
|
import { detectDialect, dialects, FALLBACK_SOURCE, isPluginRoot } from './dialects/registry.js';
|
|
13
13
|
const DEFAULT_EXCLUDED = new Set(['node_modules', '.git', 'dist', 'lib', 'out', '.cache']);
|
|
@@ -18,9 +18,11 @@ export function defaultDiscoveryRoots(home = homedir()) {
|
|
|
18
18
|
/**
|
|
19
19
|
* Discover plugin roots under the given directories. A dialect's user assets
|
|
20
20
|
* are listed when its anchor folder is a root, even when that folder does not
|
|
21
|
-
* exist. A harness that records its plugins (Claude Code
|
|
22
|
-
* folder read through that record
|
|
23
|
-
*
|
|
21
|
+
* exist. A harness that records its plugins (Claude Code, Codex, OpenCode)
|
|
22
|
+
* has its plugin folder read through that record: the plugins it installed,
|
|
23
|
+
* one version each, read as that harness's plugins. Cached versions and
|
|
24
|
+
* marketplace offers are not plugins of the person's; the marketplaces that
|
|
25
|
+
* offer them are listed apart.
|
|
24
26
|
*/
|
|
25
27
|
export function discoverPlugins(roots, options = {}) {
|
|
26
28
|
const maxDepth = options.maxDepth ?? 6;
|
|
@@ -28,7 +30,19 @@ export function discoverPlugins(roots, options = {}) {
|
|
|
28
30
|
const plugins = [];
|
|
29
31
|
const seen = new Set();
|
|
30
32
|
const missing = [];
|
|
33
|
+
const marketplaces = [];
|
|
34
|
+
const warnings = [];
|
|
31
35
|
const home = options.home ?? homedir();
|
|
36
|
+
// One harness's record that cannot be read costs that harness's part only, not the others'.
|
|
37
|
+
const guarded = (dialect, what, read) => {
|
|
38
|
+
try {
|
|
39
|
+
return read();
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
warnings.push({ source: dialect.id, message: `${dialect.label} ${what} could not be read and is skipped: ${error instanceof Error ? error.message : String(error)}` });
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
32
46
|
const add = (plugin) => {
|
|
33
47
|
if (seen.has(plugin.root))
|
|
34
48
|
return;
|
|
@@ -40,35 +54,48 @@ export function discoverPlugins(roots, options = {}) {
|
|
|
40
54
|
for (const dialect of dialects()) {
|
|
41
55
|
if (dialect.user === undefined || resolve(dialect.user.anchor(home)) !== root)
|
|
42
56
|
continue;
|
|
43
|
-
const user = dialect.user.scan(home);
|
|
44
|
-
if (user
|
|
45
|
-
|
|
57
|
+
const user = guarded(dialect, 'user assets', () => dialect.user.scan(home));
|
|
58
|
+
if (user === undefined)
|
|
59
|
+
continue;
|
|
60
|
+
const enablement = guarded(dialect, 'user assets', () => dialect.user.enablement?.(home));
|
|
61
|
+
const state = enablement === undefined ? {} : 'enabledUnknown' in enablement ? { enabledUnknown: enablement.enabledUnknown } : enablement.enabled ? {} : { enabled: false };
|
|
62
|
+
add({ ...summarize(user, 'user'), ...state });
|
|
46
63
|
}
|
|
47
|
-
const recorded = dialects().find(dialect => dialect.harnessPlugins
|
|
48
|
-
|
|
64
|
+
const recorded = dialects().find(dialect => dialect.harnessPlugins?.roots(home).some(path => resolve(path) === root) === true);
|
|
65
|
+
// A harness's record can name plugins outside a folder that does not exist (OpenCode's configured packages).
|
|
66
|
+
if (!isDirectory(root))
|
|
49
67
|
missing.push(root);
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
68
|
if (recorded !== undefined) {
|
|
53
|
-
for (
|
|
54
|
-
|
|
69
|
+
const listed = guarded(recorded, `plugin record for ${root}`, () => recorded.harnessPlugins.list(home, root));
|
|
70
|
+
// What could not be read is said, not passed over: the plugins it would have listed are missing from this view.
|
|
71
|
+
for (const message of [...listed?.unread ?? [], ...(listed?.unresolved ?? []).map(item => item.message)])
|
|
72
|
+
warnings.push({ source: recorded.id, message });
|
|
73
|
+
for (const entry of listed?.entries ?? []) {
|
|
74
|
+
const discovered = scanned(recorded, entry.root);
|
|
55
75
|
if (discovered === undefined)
|
|
56
76
|
continue;
|
|
57
77
|
add({
|
|
58
78
|
...discovered,
|
|
59
|
-
origin:
|
|
79
|
+
origin: 'installed',
|
|
80
|
+
installKey: entry.key,
|
|
60
81
|
...(entry.enabled !== undefined ? { enabled: entry.enabled } : {}),
|
|
82
|
+
...(entry.enabledUnknown !== undefined ? { enabledUnknown: entry.enabledUnknown } : {}),
|
|
61
83
|
...(entry.marketplace !== undefined ? { marketplace: entry.marketplace } : {}),
|
|
62
84
|
});
|
|
63
85
|
}
|
|
86
|
+
for (const market of guarded(recorded, 'marketplaces', () => recorded.harnessPlugins.marketplaces?.(home)) ?? []) {
|
|
87
|
+
if (!marketplaces.some(known => known.root === market.root))
|
|
88
|
+
marketplaces.push({ source: recorded.id, ...market });
|
|
89
|
+
}
|
|
64
90
|
continue;
|
|
65
91
|
}
|
|
66
|
-
|
|
92
|
+
if (isDirectory(root))
|
|
93
|
+
walk(root, 0, maxDepth, excluded, seen, plugins);
|
|
67
94
|
}
|
|
68
95
|
plugins.sort((a, b) => ORIGIN_ORDER[a.origin] - ORIGIN_ORDER[b.origin] || a.name.localeCompare(b.name, 'en') || a.root.localeCompare(b.root, 'en'));
|
|
69
|
-
return { plugins, roots: roots.map(root => resolve(root)), missingRoots: missing };
|
|
96
|
+
return { plugins, marketplaces, roots: roots.map(root => resolve(root)), missingRoots: missing, warnings };
|
|
70
97
|
}
|
|
71
|
-
const ORIGIN_ORDER = { user: 0, installed: 1, directory: 2
|
|
98
|
+
const ORIGIN_ORDER = { user: 0, installed: 1, directory: 2 };
|
|
72
99
|
function summarize(plugin, origin) {
|
|
73
100
|
return {
|
|
74
101
|
root: plugin.root,
|
|
@@ -96,6 +123,9 @@ function walk(directory, depth, maxDepth, excluded, seen, out) {
|
|
|
96
123
|
return;
|
|
97
124
|
}
|
|
98
125
|
let entries;
|
|
126
|
+
// On a link to a network share the path is not on: as unreadable (see `leadsToShare`).
|
|
127
|
+
if (leadsToShare(directory))
|
|
128
|
+
return;
|
|
99
129
|
try {
|
|
100
130
|
entries = readdirSync(directory, { withFileTypes: true });
|
|
101
131
|
}
|
|
@@ -108,6 +138,17 @@ function walk(directory, depth, maxDepth, excluded, seen, out) {
|
|
|
108
138
|
walk(join(directory, entry.name), depth + 1, maxDepth, excluded, seen, out);
|
|
109
139
|
}
|
|
110
140
|
}
|
|
141
|
+
/** A plugin the harness installed, read as that harness's: Codex keeps a plugin with a Claude manifest too, say. */
|
|
142
|
+
function scanned(dialect, root) {
|
|
143
|
+
if (!isDirectory(root))
|
|
144
|
+
return undefined;
|
|
145
|
+
try {
|
|
146
|
+
return summarize(dialect.scan(root), 'directory');
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
111
152
|
function pluginAt(directory, listed) {
|
|
112
153
|
if (!isPluginRoot(directory, listed))
|
|
113
154
|
return undefined;
|
package/lib/fingerprint.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { createHash } from 'node:crypto';
|
|
8
8
|
import { readFileSync, statSync } from 'node:fs';
|
|
9
9
|
import { relative, resolve } from 'node:path';
|
|
10
|
+
import { LEADS_TO_SHARE, leadsToShare } from './paths.js';
|
|
10
11
|
const MAX_HASH_BYTES = 8 * 1024 * 1024;
|
|
11
12
|
/** Compute a deterministic fingerprint for the plugin's manifest and files. */
|
|
12
13
|
export function fingerprintPlugin(plugin) {
|
|
@@ -18,6 +19,9 @@ export function fingerprintPlugin(plugin) {
|
|
|
18
19
|
hash.update(relativePath);
|
|
19
20
|
hash.update('\0');
|
|
20
21
|
try {
|
|
22
|
+
// A file on a link to a network share the path is not on is hashed as unreadable (see `leadsToShare`).
|
|
23
|
+
if (leadsToShare(path))
|
|
24
|
+
throw new Error(LEADS_TO_SHARE);
|
|
21
25
|
const stat = statSync(path);
|
|
22
26
|
if (stat.size <= MAX_HASH_BYTES)
|
|
23
27
|
hash.update(readFileSync(path));
|
|
@@ -83,6 +87,9 @@ function sha256(value) {
|
|
|
83
87
|
return createHash('sha256').update(value).digest('hex');
|
|
84
88
|
}
|
|
85
89
|
function safeStat(path) {
|
|
90
|
+
// On a link to a network share the path is not on: as unreadable (see `leadsToShare`).
|
|
91
|
+
if (leadsToShare(path))
|
|
92
|
+
return undefined;
|
|
86
93
|
try {
|
|
87
94
|
return statSync(path);
|
|
88
95
|
}
|