@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.
Files changed (56) hide show
  1. package/lib/assess.js +24 -4
  2. package/lib/contracts.d.ts +1 -1
  3. package/lib/dialects/claude-code/index.js +38 -41
  4. package/lib/dialects/claude-code/sessions/discover.js +31 -17
  5. package/lib/dialects/claude-code/sessions/parse.js +89 -83
  6. package/lib/dialects/claude-code/sessions/title.d.ts +23 -0
  7. package/lib/dialects/claude-code/sessions/title.js +74 -0
  8. package/lib/dialects/claude-code/statusline.d.ts +12 -0
  9. package/lib/dialects/claude-code/statusline.js +74 -0
  10. package/lib/dialects/claude-code/user-assets.d.ts +37 -6
  11. package/lib/dialects/claude-code/user-assets.js +155 -34
  12. package/lib/dialects/codex/index.js +8 -1
  13. package/lib/dialects/codex/mcp-server.d.ts +17 -0
  14. package/lib/dialects/codex/mcp-server.js +116 -0
  15. package/lib/dialects/codex/plugins.d.ts +16 -0
  16. package/lib/dialects/codex/plugins.js +120 -0
  17. package/lib/dialects/codex/user-assets.d.ts +10 -6
  18. package/lib/dialects/codex/user-assets.js +26 -42
  19. package/lib/dialects/opencode/index.js +43 -8
  20. package/lib/dialects/opencode/inventory.d.ts +100 -0
  21. package/lib/dialects/opencode/inventory.js +318 -0
  22. package/lib/dialects/opencode/plugin-id.d.ts +21 -0
  23. package/lib/dialects/opencode/plugin-id.js +296 -0
  24. package/lib/dialects/opencode/scan.d.ts +22 -0
  25. package/lib/dialects/opencode/scan.js +119 -121
  26. package/lib/dialects/types.d.ts +60 -6
  27. package/lib/discover.d.ts +32 -7
  28. package/lib/discover.js +58 -17
  29. package/lib/fingerprint.js +7 -0
  30. package/lib/harness-installs.d.ts +42 -0
  31. package/lib/harness-installs.js +59 -0
  32. package/lib/index.d.ts +6 -0
  33. package/lib/index.js +5 -0
  34. package/lib/instructions.d.ts +28 -2
  35. package/lib/instructions.js +202 -30
  36. package/lib/license.js +12 -11
  37. package/lib/manifest.d.ts +6 -0
  38. package/lib/manifest.js +41 -12
  39. package/lib/marketplace.d.ts +15 -1
  40. package/lib/marketplace.js +55 -38
  41. package/lib/paths.d.ts +65 -0
  42. package/lib/paths.js +152 -2
  43. package/lib/plan.js +3 -1
  44. package/lib/port-brief.d.ts +28 -5
  45. package/lib/port-brief.js +52 -10
  46. package/lib/remote.d.ts +121 -0
  47. package/lib/remote.js +352 -0
  48. package/lib/sessions/index.d.ts +1 -0
  49. package/lib/sessions/index.js +1 -0
  50. package/lib/sessions/lines.d.ts +57 -0
  51. package/lib/sessions/lines.js +122 -0
  52. package/lib/text.d.ts +9 -0
  53. package/lib/text.js +19 -0
  54. package/lib/trust.js +19 -6
  55. package/lib/types.d.ts +48 -1
  56. package/package.json +1 -1
@@ -0,0 +1,120 @@
1
+ /**
2
+ * The plugins Codex has installed and the marketplaces it added, read the way
3
+ * Codex records them (https://developers.openai.com/plugins/build/plugins):
4
+ * an installed plugin has a `[plugins."<name>@<marketplace>"]` entry in
5
+ * `config.toml` (enabled or not) and its files in
6
+ * `plugins/cache/<marketplace>/<name>/<version>/`. The cache also holds
7
+ * plugins a marketplace offers that the person never installed; those are not
8
+ * listed.
9
+ * @module @kirkchinese/harness-forge-core
10
+ */
11
+ import { readdirSync, statSync } from 'node:fs';
12
+ import { homedir } from 'node:os';
13
+ import { basename, isAbsolute, join, relative, resolve, sep } from 'node:path';
14
+ import { isDirectory, isFile, isPlainObject, LEADS_TO_SHARE, leadsToShare } from '../../paths.js';
15
+ import { codexHome, readCodexConfig, readCodexConfigRecord } from './user-assets.js';
16
+ /**
17
+ * The plugins `config.toml` lists, each at the cached version Codex loads. A listed plugin with no cached version is
18
+ * `unresolved` (still installed); a `config.toml` that does not parse, or a cache folder that cannot be listed, is
19
+ * `unread`, never "nothing installed".
20
+ */
21
+ export function installedCodexPlugins(home = homedir()) {
22
+ const root = codexHome(home);
23
+ const config = readCodexConfigRecord(root);
24
+ const unread = config.problem === undefined ? [] : [config.problem];
25
+ const plugins = config.value?.['plugins'];
26
+ if (plugins !== undefined && !isPlainObject(plugins))
27
+ unread.push(`${join(root, 'config.toml')}: "plugins" is not a table`);
28
+ const listed = isPlainObject(plugins) ? plugins : {};
29
+ const entries = [];
30
+ const unresolved = [];
31
+ for (const [key, value] of Object.entries(listed)) {
32
+ const at = key.lastIndexOf('@');
33
+ if (at <= 0 || at === key.length - 1)
34
+ continue;
35
+ const name = key.slice(0, at);
36
+ const marketplace = key.slice(at + 1);
37
+ const dir = join(root, 'plugins', 'cache', marketplace, name);
38
+ const version = cachedVersion(dir);
39
+ if (typeof version !== 'string') {
40
+ if ('unread' in version)
41
+ unread.push(version.unread);
42
+ else
43
+ unresolved.push({ key, message: `Codex lists ${key}, but ${dir} holds no version of it` });
44
+ continue;
45
+ }
46
+ entries.push({ root: version, key, enabled: !(isPlainObject(value) && value['enabled'] === false), marketplace });
47
+ }
48
+ return { entries, unresolved, unread };
49
+ }
50
+ /**
51
+ * The `<name>@<marketplace>` a folder of Codex's cache (`plugins/cache/<marketplace>/<name>/<version>`) is a version
52
+ * of, listed or not.
53
+ */
54
+ export function codexInstallKey(root, home = homedir()) {
55
+ const parts = cachePath(join(codexHome(home), 'plugins', 'cache'), root);
56
+ return parts?.length === 3 ? `${parts[1]}@${parts[0]}` : undefined;
57
+ }
58
+ /** The folders from `cache` down to `root`, when `root` is below it. */
59
+ export function cachePath(cache, root) {
60
+ const path = relative(resolve(cache), resolve(root));
61
+ if (path.length === 0 || path.startsWith('..') || isAbsolute(path))
62
+ return undefined;
63
+ return path.split(sep);
64
+ }
65
+ /**
66
+ * The version folder Codex loads: `local` for a local plugin, else the newest
67
+ * one. A `latest` link to one of them is not a version of its own. `none` when
68
+ * the plugin's folder is missing or empty; `unread` when it cannot be listed.
69
+ */
70
+ function cachedVersion(dir) {
71
+ let entries;
72
+ if (leadsToShare(dir))
73
+ return { unread: `${dir} could not be listed (${LEADS_TO_SHARE})` };
74
+ try {
75
+ entries = readdirSync(dir, { withFileTypes: true });
76
+ }
77
+ catch (error) {
78
+ const code = error.code;
79
+ if (code === 'ENOENT' || code === 'ENOTDIR')
80
+ return { none: true };
81
+ return { unread: `${dir} could not be listed (${error instanceof Error ? error.message : String(error)})` };
82
+ }
83
+ const versions = entries.filter(entry => entry.isDirectory()).map(entry => join(dir, entry.name));
84
+ const local = versions.find(path => basename(path) === 'local');
85
+ if (local !== undefined)
86
+ return resolve(local);
87
+ const newest = versions
88
+ .map(path => ({ path, time: modified(path) }))
89
+ .sort((a, b) => b.time - a.time || b.path.localeCompare(a.path, 'en'))[0];
90
+ return newest === undefined ? { none: true } : resolve(newest.path);
91
+ }
92
+ function modified(path) {
93
+ if (leadsToShare(path))
94
+ return 0;
95
+ try {
96
+ return statSync(path).mtimeMs;
97
+ }
98
+ catch {
99
+ return 0;
100
+ }
101
+ }
102
+ /** The local marketplaces `config.toml` adds (`[marketplaces.<name>]` with a local `source`). */
103
+ export function codexMarketplaces(home = homedir()) {
104
+ const config = readCodexConfig(codexHome(home));
105
+ const listed = isPlainObject(config['marketplaces']) ? config['marketplaces'] : {};
106
+ const out = [];
107
+ for (const [name, value] of Object.entries(listed)) {
108
+ if (!isPlainObject(value) || typeof value['source'] !== 'string')
109
+ continue;
110
+ if (value['source_type'] !== undefined && value['source_type'] !== 'local')
111
+ continue;
112
+ const root = resolve(value['source']);
113
+ if (!isDirectory(root))
114
+ continue;
115
+ if (!isFile(join(root, '.agents', 'plugins', 'marketplace.json')) && !isFile(join(root, '.claude-plugin', 'marketplace.json')))
116
+ continue;
117
+ out.push({ name, root });
118
+ }
119
+ return out;
120
+ }
@@ -1,8 +1,14 @@
1
+ import { type RecordRead } from '../../paths.js';
1
2
  import type { AgentComponent, HookComponent, ForeignPlugin, McpComponent } from '../../types.js';
2
3
  /** Where Codex keeps its configuration: `$CODEX_HOME`, else `~/.codex`. */
3
4
  export declare function codexHome(home?: string): string;
4
- /** `config.toml`, parsed; empty when absent or unreadable. */
5
+ /** `config.toml`, parsed; empty when absent or unreadable (see {@link readCodexConfigRecord} for which). */
5
6
  export declare function readCodexConfig(root: string): Record<string, unknown>;
7
+ /**
8
+ * `config.toml` as read: absent (a complete read of nothing), parsed, or why it could not be (malformed, or cut off
9
+ * while Codex or the ChatGPT app writes it).
10
+ */
11
+ export declare function readCodexConfigRecord(root: string): RecordRead<Record<string, unknown>>;
6
12
  /**
7
13
  * The user's own Codex assets as one plugin.
8
14
  * @returns undefined when `$CODEX_HOME` holds nothing to bring over.
@@ -29,11 +35,9 @@ export declare function codexHooks(pluginIdValue: string, file: string): HookCom
29
35
  */
30
36
  export declare function codexAgentRoles(pluginIdValue: string, root: string, config: Record<string, unknown>): AgentComponent[];
31
37
  /**
32
- * Codex's MCP servers (`[mcp_servers.<name>]`): `command`/`args`/`env`/
33
- * `env_vars`/`cwd` run a stdio server, `url` (with `bearer_token_env_var`,
34
- * `http_headers`, `env_http_headers`) a streamable-HTTP one; `enabled = false`
35
- * leaves a server out. Variables Codex passes through are referenced as
36
- * `${NAME}`, expanded when the server starts.
38
+ * Codex's MCP servers (`[mcp_servers.<name>]`), translated by
39
+ * {@link codexMcpServer}; a server with `enabled = false` is kept, marked as
40
+ * not started, so its part says why it does not run.
37
41
  */
38
42
  export declare function codexMcpComponents(pluginIdValue: string, servers: Record<string, unknown>): McpComponent[];
39
43
  /**
@@ -23,22 +23,31 @@ import { childId, pluginId, shortHash, uniqueName } from '../../naming.js';
23
23
  import { fingerprintPlugin } from '../../fingerprint.js';
24
24
  import { parseSkillFrontmatter, readMarkdownAsset } from '../../frontmatter.js';
25
25
  import { codexSkillPolicy } from './skill-policy.js';
26
- import { isDirectory, isFile, isPlainObject, readText, stem, toPosix } from '../../paths.js';
26
+ import { codexMcpServer } from './mcp-server.js';
27
+ import { contentPath, isDirectory, isFile, isPlainObject, leadsToShare, readRecordText, readText, stem, toPosix } from '../../paths.js';
27
28
  import { settingsHooksComponent } from '../claude-code/user-assets.js';
28
29
  /** Where Codex keeps its configuration: `$CODEX_HOME`, else `~/.codex`. */
29
30
  export function codexHome(home = homedir()) {
30
31
  return process.env['CODEX_HOME'] ?? join(home, '.codex');
31
32
  }
32
- /** `config.toml`, parsed; empty when absent or unreadable. */
33
+ /** `config.toml`, parsed; empty when absent or unreadable (see {@link readCodexConfigRecord} for which). */
33
34
  export function readCodexConfig(root) {
34
- const text = readText(join(root, 'config.toml'));
35
- if (text === undefined)
36
- return {};
35
+ return readCodexConfigRecord(root).value ?? {};
36
+ }
37
+ /**
38
+ * `config.toml` as read: absent (a complete read of nothing), parsed, or why it could not be (malformed, or cut off
39
+ * while Codex or the ChatGPT app writes it).
40
+ */
41
+ export function readCodexConfigRecord(root) {
42
+ const path = join(root, 'config.toml');
43
+ const text = readRecordText(path);
44
+ if (text.value === undefined)
45
+ return text.problem === undefined ? {} : { problem: text.problem };
37
46
  try {
38
- return parseToml(text);
47
+ return { value: parseToml(text.value) };
39
48
  }
40
- catch {
41
- return {};
49
+ catch (error) {
50
+ return { problem: `${path} is not valid TOML (${error instanceof Error ? error.message : String(error)})` };
42
51
  }
43
52
  }
44
53
  /**
@@ -278,7 +287,8 @@ export function codexAgentRoles(pluginIdValue, root, config) {
278
287
  for (const [name, raw] of Object.entries(declared)) {
279
288
  if (!isPlainObject(raw))
280
289
  continue;
281
- const configFile = typeof raw['config_file'] === 'string' ? resolve(root, raw['config_file']) : undefined;
290
+ // A value of the config file: checked against its folder before it is read (see `contentPath`).
291
+ const configFile = typeof raw['config_file'] === 'string' ? contentPath(raw['config_file'], root) : undefined;
282
292
  const table = configFile === undefined ? {} : read(configFile) ?? {};
283
293
  roles.set(name, { file: configFile ?? join(root, 'config.toml'), table, ...(typeof raw['description'] === 'string' ? { description: raw['description'] } : {}) });
284
294
  }
@@ -306,44 +316,16 @@ export function codexAgentRoles(pluginIdValue, root, config) {
306
316
  return out;
307
317
  }
308
318
  /**
309
- * Codex's MCP servers (`[mcp_servers.<name>]`): `command`/`args`/`env`/
310
- * `env_vars`/`cwd` run a stdio server, `url` (with `bearer_token_env_var`,
311
- * `http_headers`, `env_http_headers`) a streamable-HTTP one; `enabled = false`
312
- * leaves a server out. Variables Codex passes through are referenced as
313
- * `${NAME}`, expanded when the server starts.
319
+ * Codex's MCP servers (`[mcp_servers.<name>]`), translated by
320
+ * {@link codexMcpServer}; a server with `enabled = false` is kept, marked as
321
+ * not started, so its part says why it does not run.
314
322
  */
315
323
  export function codexMcpComponents(pluginIdValue, servers) {
316
324
  const out = [];
317
325
  for (const [name, raw] of Object.entries(servers)) {
318
- if (!isPlainObject(raw) || raw['enabled'] === false)
326
+ if (!isPlainObject(raw))
319
327
  continue;
320
- const strings = (value) => (isPlainObject(value)
321
- ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === 'string'))
322
- : {});
323
- const command = typeof raw['command'] === 'string' ? raw['command'] : undefined;
324
- const url = typeof raw['url'] === 'string' ? raw['url'] : undefined;
325
- const args = Array.isArray(raw['args']) ? raw['args'].filter((arg) => typeof arg === 'string') : [];
326
- const passed = Array.isArray(raw['env_vars']) ? raw['env_vars'].filter((item) => typeof item === 'string') : [];
327
- const env = { ...Object.fromEntries(passed.map(variable => [variable, `\${${variable}}`])), ...strings(raw['env']) };
328
- const headers = {
329
- ...strings(raw['http_headers']),
330
- ...Object.fromEntries(Object.entries(strings(raw['env_http_headers'])).map(([header, variable]) => [header, `\${${variable}}`])),
331
- ...(typeof raw['bearer_token_env_var'] === 'string' ? { Authorization: `Bearer \${${raw['bearer_token_env_var']}}` } : {}),
332
- };
333
- const transport = command !== undefined ? 'stdio' : url !== undefined ? 'streamable-http' : 'unknown';
334
- out.push({
335
- id: childId(pluginIdValue, 'mcp', name),
336
- kind: 'mcp',
337
- name,
338
- description: `user-scope ${transport} MCP server`,
339
- transport,
340
- ...(command !== undefined ? { command } : {}),
341
- ...(args.length > 0 ? { args } : {}),
342
- ...(Object.keys(env).length > 0 ? { env } : {}),
343
- ...(typeof raw['cwd'] === 'string' ? { cwd: raw['cwd'] } : {}),
344
- ...(url !== undefined ? { url } : {}),
345
- ...(Object.keys(headers).length > 0 ? { headers } : {}),
346
- });
328
+ out.push(codexMcpServer(raw, { id: childId(pluginIdValue, 'mcp', name), name, declaredName: name, scope: 'user-scope', disabledCode: 'disabled-in-config' }));
347
329
  }
348
330
  return out;
349
331
  }
@@ -423,6 +405,8 @@ function expand(pattern) {
423
405
  return prefixes.map(words => words.join(' '));
424
406
  }
425
407
  function entries(dir) {
408
+ if (leadsToShare(dir))
409
+ return [];
426
410
  try {
427
411
  return readdirSync(dir).sort((a, b) => a.localeCompare(b, 'en'));
428
412
  }
@@ -1,20 +1,55 @@
1
1
  /**
2
2
  * The OpenCode dialect: projects with `opencode.json(c)` and npm packages
3
- * built on OpenCode's plugin API.
3
+ * built on OpenCode's plugin API. What OpenCode itself loads globally is read
4
+ * through one inventory (`inventory.ts`): the plugin files of the global
5
+ * plugins folder are the person's own (`opencode:user`), and each plugin
6
+ * package (a directory in a plugins folder, a configured local directory, an
7
+ * npm package OpenCode installed) is a plugin of its own.
4
8
  * @module @kirkchinese/harness-forge-core
5
9
  */
6
- import { join } from 'node:path';
10
+ import { dirname, join, resolve } from 'node:path';
7
11
  import { isFile, readJsonObject } from '../../paths.js';
8
- import { scanOpenCodeProject } from './scan.js';
12
+ import { openCodeConfigFiles, openCodeInventory } from './inventory.js';
13
+ import { openCodeCacheDir, openCodeConfigDir, openCodeGlobalLocation, openCodeUserEnablement, scanOpenCodeProject, scanOpenCodeUser } from './scan.js';
14
+ const isOpenCodeRoot = (directory) => isFile(join(directory, 'opencode.json')) || isFile(join(directory, 'opencode.jsonc')) || isOpenCodePackage(directory);
15
+ /** The plugins folders discovery lists: the global one, and `~/.opencode/plugins` (the `.opencode` of a session in the home folder). */
16
+ const pluginFolders = (home) => [join(openCodeConfigDir(home), 'plugins'), join(home, '.opencode', 'plugins')];
9
17
  export const openCodeDialect = {
10
18
  id: 'opencode',
11
19
  label: 'OpenCode',
12
- markers: [{
13
- tier: 'manifest',
14
- test: directory => isFile(join(directory, 'opencode.json')) || isFile(join(directory, 'opencode.jsonc')) || isOpenCodePackage(directory),
15
- }],
20
+ markers: [{ tier: 'manifest', test: isOpenCodeRoot }],
16
21
  scan: (root, options) => scanOpenCodeProject(root, options).plugin,
17
- discoveryRoots: home => [join(home, '.config', 'opencode', 'plugins'), join(home, '.opencode', 'plugins')],
22
+ discoveryRoots: pluginFolders,
23
+ user: {
24
+ root: home => openCodeConfigDir(home),
25
+ anchor: home => join(openCodeConfigDir(home), 'plugins'),
26
+ scan: home => scanOpenCodeUser(home),
27
+ enablement: home => openCodeUserEnablement(home),
28
+ emptyMessage: 'holds no OpenCode plugin files in plugins/ or plugin/',
29
+ },
30
+ harnessPlugins: {
31
+ roots: pluginFolders,
32
+ // The packages a config directory loads (see `inventory.ts`); its plugin files are the person's own assets.
33
+ // Each with whether OpenCode runs it: `~/.opencode` is read after the global config, which can switch its plugins off.
34
+ list: (home, root) => {
35
+ const configDir = dirname(root);
36
+ const global = openCodeGlobalLocation(home);
37
+ const inventory = resolve(configDir) === resolve(global.configDir)
38
+ ? openCodeInventory(global)
39
+ : openCodeInventory({ configDir, configFiles: openCodeConfigFiles(configDir), cacheDir: openCodeCacheDir(home) }, [global]);
40
+ return {
41
+ entries: inventory.entries.flatMap(entry => entry.kind === 'package' && entry.entryPath !== undefined ? [{ root: entry.root, key: resolve(entry.root), ...(entry.enabled !== undefined ? { enabled: entry.enabled } : { enabledUnknown: entry.unknownBecause }) }] : []),
42
+ // A configured package not on disk is still configured: each folder it would be in stays installed. One no folder
43
+ // can be named for (a git spec) could be any installed folder, so the read is not complete.
44
+ unresolved: inventory.entries.flatMap(entry => entry.kind === 'unresolved' ? (entry.candidates ?? []).map(candidate => ({ key: resolve(candidate), message: `OpenCode configures ${entry.spec}, which is not installed at ${candidate}` })) : []),
45
+ unread: [
46
+ ...inventory.unread,
47
+ ...inventory.warnings.filter(warning => !inventory.unread.includes(warning)),
48
+ ...inventory.entries.flatMap(entry => entry.kind === 'unresolved' && entry.candidates === undefined ? [`OpenCode configures ${entry.spec}, which names no folder Harness Forge can find`] : []),
49
+ ],
50
+ };
51
+ },
52
+ },
18
53
  };
19
54
  function isOpenCodePackage(directory) {
20
55
  const packageJson = readJsonObject(join(directory, 'package.json'));
@@ -0,0 +1,100 @@
1
+ import { type PluginIdProblem } from './plugin-id.js';
2
+ /** One plugin OpenCode loads from a config directory, and where it is. */
3
+ export type OpenCodePlugin =
4
+ /** A plugin file right inside a plugins folder. */
5
+ {
6
+ readonly kind: 'file';
7
+ readonly path: string;
8
+ }
9
+ /**
10
+ * A plugin package directory: in a plugins folder, a configured local directory, or an installed npm package,
11
+ * with the server entry OpenCode runs (none for a configured directory without one; a folder's directory without
12
+ * one is no plugin and not listed).
13
+ */
14
+ | {
15
+ readonly kind: 'package';
16
+ readonly root: string;
17
+ readonly spec?: string;
18
+ readonly entryPath?: string;
19
+ }
20
+ /**
21
+ * A configured entry with nothing on disk to read: a package OpenCode has not installed, or a git spec. `candidates`
22
+ * are the folders it would be in (a local path, or `node_modules/<name>` of the config and cache folders); none for a
23
+ * spec no folder can be named for.
24
+ */
25
+ | {
26
+ readonly kind: 'unresolved';
27
+ readonly spec: string;
28
+ readonly candidates?: readonly string[];
29
+ };
30
+ /** Whether OpenCode runs a plugin, or, when that cannot be told, why. */
31
+ export type OpenCodeEnablement = {
32
+ readonly enabled: boolean;
33
+ }
34
+ /**
35
+ * An entry that switches plugins by id may or may not apply: the id of this plugin, or of one loaded after it
36
+ * that could share its id, cannot be told from the source ({@link declaredPluginId}).
37
+ */
38
+ | {
39
+ readonly enabled: undefined;
40
+ readonly unknownBecause: PluginIdProblem;
41
+ };
42
+ /** One plugin OpenCode loads from a config directory, with whether it runs. */
43
+ export type OpenCodePluginEntry = OpenCodePlugin & OpenCodeEnablement;
44
+ /** Where one OpenCode config directory keeps its plugins. */
45
+ export interface OpenCodeLocation {
46
+ /** `~/.config/opencode`, or a project's `.opencode`. */
47
+ readonly configDir: string;
48
+ /** The `opencode.json(c)` files whose plugin entries apply, lowest precedence first. */
49
+ readonly configFiles: readonly string[];
50
+ /** OpenCode's package cache (`~/.cache/opencode`), where V1 installed npm plugins. */
51
+ readonly cacheDir?: string;
52
+ }
53
+ /** The plugins of one config directory, and the entries that could not be read. */
54
+ export interface OpenCodeInventory {
55
+ readonly entries: readonly OpenCodePluginEntry[];
56
+ /** One per configured entry that could not be resolved, naming it; the entry is skipped. */
57
+ readonly warnings: readonly string[];
58
+ /**
59
+ * What of the chain's configuration could not be read (a config file that does not parse, a plugins folder that
60
+ * cannot be listed): while any, a plugin missing from `entries` may only be unreadable.
61
+ */
62
+ readonly unread: readonly string[];
63
+ }
64
+ /** The plugin folders of a config directory: V2's `plugins`, and V1's `plugin`, which V2 still reads. */
65
+ export declare const OPENCODE_PLUGIN_FOLDERS: readonly string[];
66
+ /** The config files of a directory, as OpenCode names them. */
67
+ export declare function openCodeConfigFiles(directory: string): string[];
68
+ /** Read one `opencode.json` or `opencode.jsonc`. */
69
+ export declare function readOpenCodeConfigFile(path: string): Record<string, unknown> | undefined;
70
+ /** The plugin specs a config loads: its entries that add, not those that switch plugins on or off by id. */
71
+ export declare function configuredPluginSpecs(config: Record<string, unknown>): string[];
72
+ /**
73
+ * Every plugin `location` loads, each with whether OpenCode runs it, resolved the way OpenCode resolves them
74
+ * (`scan` in `packages/core/src/config/plugin/source.ts` and `resolve` in `packages/core/src/plugin/supervisor.ts`
75
+ * of https://github.com/anomalyco/opencode; documented at https://opencode.ai/docs/plugins/#control):
76
+ *
77
+ * - OpenCode reads its config directories lowest precedence first: the global one, then a project's (`inherited`
78
+ * are those it reads before `location`). Their plugins folders come first, then the entries of their config
79
+ * files, in order ("Plugin arrays from applicable config files are applied from lowest to highest precedence").
80
+ * - Each entry is processed in order. `-<id>` switches off the plugins loaded so far whose id it matches; `*`
81
+ * matches every id, `<prefix>.*` the ids starting with `<prefix>.`. An entry that matches the id of a plugin
82
+ * loaded so far, or is a selector, switches the matching plugins on again ("A later ID re-enables a plugin");
83
+ * any other entry loads a plugin, on.
84
+ * - A plugin's id is what its server part declares ({@link declaredPluginId}). Whether an entry applies to a plugin
85
+ * whose id cannot be told is not guessed: `*` and `-*` apply to every plugin, but after any other entry that
86
+ * could switch it, by id or by loading a plugin that could share its id, its state is unknown, with why.
87
+ *
88
+ * Only `location`'s own plugins are returned. A configured entry that cannot be resolved is skipped, with a warning
89
+ * when it is `location`'s.
90
+ */
91
+ export declare function openCodeInventory(location: OpenCodeLocation, inherited?: readonly OpenCodeLocation[]): OpenCodeInventory;
92
+ /** The npm package name of a spec (`name`, `name@1.2.0`, `@scope/name@^1`); undefined for git and URL specs. */
93
+ export declare function packageName(spec: string): string | undefined;
94
+ /**
95
+ * A plugin package's server entry, as OpenCode loads it: `exports` `./server`
96
+ * or `.`, else `main`/`module`, else `server` or `index` at its root. A
97
+ * source checkout whose build output is absent runs from its TypeScript
98
+ * source (`dist/x.js` → `src/x.ts` or `x.ts`), as Bun runs it.
99
+ */
100
+ export declare function pluginEntryOf(directory: string): string | undefined;