opensip-cli 0.1.2 → 0.1.3

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/dist/bootstrap/bind-tool-context.d.ts +16 -0
  2. package/dist/bootstrap/bind-tool-context.d.ts.map +1 -0
  3. package/dist/bootstrap/bind-tool-context.js +160 -0
  4. package/dist/bootstrap/bind-tool-context.js.map +1 -0
  5. package/dist/bootstrap/build-per-run-scope.d.ts.map +1 -1
  6. package/dist/bootstrap/build-per-run-scope.js +35 -2
  7. package/dist/bootstrap/build-per-run-scope.js.map +1 -1
  8. package/dist/bootstrap/execute-post-bailout-bootstrap.d.ts +45 -0
  9. package/dist/bootstrap/execute-post-bailout-bootstrap.d.ts.map +1 -0
  10. package/dist/bootstrap/execute-post-bailout-bootstrap.js +108 -0
  11. package/dist/bootstrap/execute-post-bailout-bootstrap.js.map +1 -0
  12. package/dist/bootstrap/plan-pre-action-bootstrap.d.ts +45 -0
  13. package/dist/bootstrap/plan-pre-action-bootstrap.d.ts.map +1 -0
  14. package/dist/bootstrap/plan-pre-action-bootstrap.js +86 -0
  15. package/dist/bootstrap/plan-pre-action-bootstrap.js.map +1 -0
  16. package/dist/bootstrap/pre-action-bootstrap-phases.d.ts +20 -0
  17. package/dist/bootstrap/pre-action-bootstrap-phases.d.ts.map +1 -0
  18. package/dist/bootstrap/pre-action-bootstrap-phases.js +25 -0
  19. package/dist/bootstrap/pre-action-bootstrap-phases.js.map +1 -0
  20. package/dist/bootstrap/pre-action-hook.d.ts +6 -66
  21. package/dist/bootstrap/pre-action-hook.d.ts.map +1 -1
  22. package/dist/bootstrap/pre-action-hook.js +22 -266
  23. package/dist/bootstrap/pre-action-hook.js.map +1 -1
  24. package/dist/bootstrap/pre-action-runtime.d.ts +9 -0
  25. package/dist/bootstrap/pre-action-runtime.d.ts.map +1 -0
  26. package/dist/bootstrap/pre-action-runtime.js +2 -0
  27. package/dist/bootstrap/pre-action-runtime.js.map +1 -0
  28. package/dist/bootstrap/register-tools-bundled.d.ts +28 -0
  29. package/dist/bootstrap/register-tools-bundled.d.ts.map +1 -0
  30. package/dist/bootstrap/register-tools-bundled.js +107 -0
  31. package/dist/bootstrap/register-tools-bundled.js.map +1 -0
  32. package/dist/bootstrap/register-tools-discovery.d.ts +154 -0
  33. package/dist/bootstrap/register-tools-discovery.d.ts.map +1 -0
  34. package/dist/bootstrap/register-tools-discovery.js +385 -0
  35. package/dist/bootstrap/register-tools-discovery.js.map +1 -0
  36. package/dist/bootstrap/register-tools-mount.d.ts +25 -0
  37. package/dist/bootstrap/register-tools-mount.d.ts.map +1 -0
  38. package/dist/bootstrap/register-tools-mount.js +91 -0
  39. package/dist/bootstrap/register-tools-mount.js.map +1 -0
  40. package/dist/bootstrap/register-tools-shared.d.ts +40 -0
  41. package/dist/bootstrap/register-tools-shared.d.ts.map +1 -0
  42. package/dist/bootstrap/register-tools-shared.js +98 -0
  43. package/dist/bootstrap/register-tools-shared.js.map +1 -0
  44. package/dist/bootstrap/register-tools.d.ts +4 -196
  45. package/dist/bootstrap/register-tools.d.ts.map +1 -1
  46. package/dist/bootstrap/register-tools.js +4 -668
  47. package/dist/bootstrap/register-tools.js.map +1 -1
  48. package/dist/commands/mount-command-spec.d.ts +2 -1
  49. package/dist/commands/mount-command-spec.d.ts.map +1 -1
  50. package/dist/commands/mount-command-spec.js +3 -6
  51. package/dist/commands/mount-command-spec.js.map +1 -1
  52. package/dist/env/host-env-specs.d.ts +4 -3
  53. package/dist/env/host-env-specs.d.ts.map +1 -1
  54. package/dist/env/host-env-specs.js +8 -3
  55. package/dist/env/host-env-specs.js.map +1 -1
  56. package/package.json +32 -32
@@ -0,0 +1,91 @@
1
+ import { logger } from '@opensip-cli/core';
2
+ import { mountCommandSpec } from '../commands/mount-command-spec.js';
3
+ import { bindToolCliContext } from './bind-tool-context.js';
4
+ import { BOOTSTRAP_MODULE } from './register-tools-shared.js';
5
+ /**
6
+ * Walk the registry and mount each tool's commands onto `program`. This is
7
+ * **step 8** of the tool lifecycle (launch, §5.4) — see
8
+ * {@link runToolLifecycle}.
9
+ *
10
+ * Public launch: there is ONE command surface — the tool's declared `commandSpecs`,
11
+ * mounted by `mountCommandSpec`. `register()` and the raw-Commander `program`
12
+ * handle on the tool context are gone, so the host owns `program` and passes it
13
+ * in here (the tool never touches Commander). A tool with no `commandSpecs` is a
14
+ * mis-declaration: it contributes no commands, surfaced loudly via
15
+ * `cli.tool.no_command_surface`.
16
+ *
17
+ * Failures are isolated per tool — one tool whose spec fails to mount must not
18
+ * take the whole CLI down. The failure is logged + stderr-warned, then we
19
+ * continue with the next tool.
20
+ *
21
+ * @param registry The per-invocation tool registry to walk.
22
+ * @param program The root Commander program (host-owned; the composition root
23
+ * passes it — it is no longer reachable through the tool context, §8).
24
+ * @param ctx The per-invocation handler context (render/emit/scope — no program).
25
+ */
26
+ export function mountAllToolCommands(registry, program, ctx) {
27
+ for (const tool of registry.list()) {
28
+ try {
29
+ mountOneTool(program, tool, ctx);
30
+ }
31
+ catch (error) {
32
+ const msg = error instanceof Error ? error.message : String(error);
33
+ const human = tool.metadata.name ?? tool.metadata.id;
34
+ process.stderr.write(`opensip: tool ${human} failed to mount: ${msg}\n`);
35
+ logger.warn({
36
+ evt: 'cli.tool.register_failed',
37
+ module: BOOTSTRAP_MODULE,
38
+ toolId: tool.metadata.id, // stable UUID
39
+ toolName: human,
40
+ error: msg,
41
+ });
42
+ }
43
+ }
44
+ // ADR-0021: one shared help shape across every mounted command — uniform
45
+ // option/subcommand ordering and a docs footer — applied here (the single
46
+ // place that has walked every tool's commands) rather than per tool.
47
+ applySharedHelpConfiguration(program);
48
+ }
49
+ /**
50
+ * Mount ONE tool's commands from its declared `commandSpecs` — the only command
51
+ * surface (public launch). Extracted so {@link mountAllToolCommands} keeps its
52
+ * per-tool failure isolation around a single call. A tool with no `commandSpecs`
53
+ * contributes nothing and is surfaced via `cli.tool.no_command_surface`.
54
+ */
55
+ function mountOneTool(program, tool, ctx) {
56
+ if (tool.commandSpecs !== undefined && tool.commandSpecs.length > 0) {
57
+ const toolCtx = bindToolCliContext(tool, ctx);
58
+ for (const spec of tool.commandSpecs) {
59
+ // `Tool.commandSpecs` is `CommandSpec<unknown, ToolCliContext>[]`, which
60
+ // is assignable to the mounter's `HostCommandSpec` (handler contravariance
61
+ // — an `unknown`-opts handler accepts a `Record`-opts call). No cast.
62
+ mountCommandSpec(program, spec, toolCtx);
63
+ }
64
+ return;
65
+ }
66
+ // No declarative command surface — a mis-declared tool contributes no commands.
67
+ // Surface it rather than silently mounting nothing.
68
+ logger.warn({
69
+ evt: 'cli.tool.no_command_surface',
70
+ module: BOOTSTRAP_MODULE,
71
+ toolId: tool.metadata.id, // stable
72
+ toolName: tool.metadata.name ?? tool.metadata.id,
73
+ detail: 'tool declares no commandSpecs; no commands mounted',
74
+ });
75
+ }
76
+ const DOCS_HELP_FOOTER = '\nDocs: https://opensip.ai/docs/opensip-cli';
77
+ /**
78
+ * Apply one help configuration to the root program and every (sub)command:
79
+ * options + subcommands sort alphabetically so the help reads the same across
80
+ * `fit`/`graph`/`sim`, and the root help ends with a docs pointer (ADR-0021).
81
+ */
82
+ function applySharedHelpConfiguration(program) {
83
+ const configure = (cmd) => {
84
+ cmd.configureHelp({ sortOptions: true, sortSubcommands: true });
85
+ for (const sub of cmd.commands)
86
+ configure(sub);
87
+ };
88
+ configure(program);
89
+ program.addHelpText('after', DOCS_HELP_FOOTER);
90
+ }
91
+ //# sourceMappingURL=register-tools-mount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-tools-mount.js","sourceRoot":"","sources":["../../src/bootstrap/register-tools-mount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAqD,MAAM,mBAAmB,CAAC;AAE9F,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,gBAAg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AI,IAAI,CAAC,YAAY,EAAE,CAAC;YACrC,yEAAyE;YACzE,2EAA2E;YAC3E,sEAAsE;YACtE,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO;IACT,CAAC;IACD,gFAAgF;IAChF,oDAAoD;IACpD,MAAM,CAAC,IAAI,CAAC;QACV,GAAG,EAAE,6BAA6B;QAClC,MAAM,EAAE,gBAAgB;QACxB,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS;QACnC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE;QAChD,MAAM,EAAE,oDAAoD;KAC7D,CAAC,CAAC;AACL,CAAC;AAED,MAAM,gBAAgB,GAAG,6CAA6C,CAAC;AAEvE;;;;GAIG;AACH,SAAS,4BAA4B,CAAC,OAAmB;IACvD,MAAM,SAAS,GAAG,CAAC,GAAe,EAAQ,EAAE;QAC1C,GAAG,CAAC,aAAa,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC;QAChE,KAAK,MAAM,GAAG,IAAI,GAAG,CAAC,QAAQ;YAAE,SAAS,CAAC,GAAG,CAAC,CAAC;IACjD,CAAC,CAAC;IACF,SAAS,CAAC,OAAO,CAAC,CAAC;IACnB,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,40 @@
1
+ /** `module` field on every structured log event emitted from this file. */
2
+ export declare const BOOTSTRAP_MODULE = "cli:bootstrap";
3
+ export declare const BUNDLED_TOOL_PACKAGES: readonly string[];
4
+ /**
5
+ * The ADR-0038 back-compat pin: the tool IDS whose `init` scaffold dirs the
6
+ * pre-registry-driven CLI ALWAYS created (fit/sim). The composition root warns
7
+ * (`cli.tool.expected_bundled_absent`) when one of these is missing from the
8
+ * populated registry, so a build whose {@link BUNDLED_TOOL_PACKAGES} drifted
9
+ * (a tool removed, a packaging variant) under-scaffolds LOUDLY instead of
10
+ * silently.
11
+ *
12
+ * Now derived from the same manifest as BUNDLED_TOOL_PACKAGES (Workstream A)
13
+ * so a single edit keeps them in sync. `graph` is correctly absent: it never
14
+ * scaffolded (`pluginLayout` undefined).
15
+ */
16
+ export declare const EXPECTED_SCAFFOLDING_TOOL_IDS: readonly string[];
17
+ /**
18
+ * Resolve a bundled tool's PACKAGE DIR — the directory whose `package.json`
19
+ * carries the `opensipTools` manifest.
20
+ *
21
+ * The `./package.json` subpath is not declared in each engine's `exports`,
22
+ * so `require.resolve('<pkg>/package.json')` throws. Instead we resolve the
23
+ * package's MAIN entry (a bare-name resolve, always permitted by `exports`)
24
+ * and walk up to the nearest ancestor directory that has a `package.json`
25
+ * whose `name` matches `packageName`. That ancestor IS the tool's own
26
+ * package dir under both the source layout and pnpm's workspace-injected
27
+ * `node_modules` layout (verified against fitness/simulation/graph here).
28
+ *
29
+ * @returns the resolved package directory, or `undefined` when the package
30
+ * cannot be resolved (should never happen for a bundled direct dep).
31
+ */
32
+ export declare function resolveBundledPackageDir(packageName: string): string | undefined;
33
+ /**
34
+ * Resolve a bundled tool package's on-disk directory, requiring success.
35
+ *
36
+ * @throws {PluginIncompatibleError} when the package directory cannot be
37
+ * resolved on disk (its manifest is unreadable).
38
+ */
39
+ export declare function resolveRequiredBundledPackageDir(packageName: string): string;
40
+ //# sourceMappingURL=register-tools-shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-tools-shared.d.ts","sourceRoot":"","sources":["../../src/bootstrap/register-tools-shared.ts"],"names":[],"mappings":"AAOA,2EAA2E;AAC3E,eAAO,MAAM,gBAAgB,kBAAkB,CAAC;AAmBhD,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAAoC,CAAC;AAExF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,6BAA6B,EAAE,SAAS,MAAM,EAAuC,CAAC;AAEnG;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAkChF;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAO5E"}
@@ -0,0 +1,98 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { createRequire } from 'node:module';
3
+ import { dirname, join } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { logger, PluginIncompatibleError } from '@opensip-cli/core';
6
+ /** `module` field on every structured log event emitted from this file. */
7
+ export const BOOTSTRAP_MODULE = 'cli:bootstrap';
8
+ /** Used to resolve the bundled engine package dirs from the CLI's own module graph. */
9
+ const requireFromHere = createRequire(import.meta.url);
10
+ /**
11
+ * Bundled first-party tools are now data-driven (platform-ergonomics Workstream A).
12
+ * The source of truth is the co-located JSON manifest (single edit site when
13
+ * adding a first-party tool). Loaded via fs + import.meta.url (works in both
14
+ * src dev and dist/ after tsc; the json is committed under src/ and must be
15
+ * present next to the .js in dist at runtime — ensured by package "files": ["dist"]
16
+ * + manual cp in build or future asset plugin; no resolveJsonModule dep).
17
+ */
18
+ const manifestUrl = new URL('bundled-tools.manifest.json', import.meta.url);
19
+ const bundledManifest = JSON.parse(readFileSync(fileURLToPath(manifestUrl), 'utf8'));
20
+ export const BUNDLED_TOOL_PACKAGES = bundledManifest.bundledPackages;
21
+ /**
22
+ * The ADR-0038 back-compat pin: the tool IDS whose `init` scaffold dirs the
23
+ * pre-registry-driven CLI ALWAYS created (fit/sim). The composition root warns
24
+ * (`cli.tool.expected_bundled_absent`) when one of these is missing from the
25
+ * populated registry, so a build whose {@link BUNDLED_TOOL_PACKAGES} drifted
26
+ * (a tool removed, a packaging variant) under-scaffolds LOUDLY instead of
27
+ * silently.
28
+ *
29
+ * Now derived from the same manifest as BUNDLED_TOOL_PACKAGES (Workstream A)
30
+ * so a single edit keeps them in sync. `graph` is correctly absent: it never
31
+ * scaffolded (`pluginLayout` undefined).
32
+ */
33
+ export const EXPECTED_SCAFFOLDING_TOOL_IDS = bundledManifest.scaffoldingToolIds;
34
+ /**
35
+ * Resolve a bundled tool's PACKAGE DIR — the directory whose `package.json`
36
+ * carries the `opensipTools` manifest.
37
+ *
38
+ * The `./package.json` subpath is not declared in each engine's `exports`,
39
+ * so `require.resolve('<pkg>/package.json')` throws. Instead we resolve the
40
+ * package's MAIN entry (a bare-name resolve, always permitted by `exports`)
41
+ * and walk up to the nearest ancestor directory that has a `package.json`
42
+ * whose `name` matches `packageName`. That ancestor IS the tool's own
43
+ * package dir under both the source layout and pnpm's workspace-injected
44
+ * `node_modules` layout (verified against fitness/simulation/graph here).
45
+ *
46
+ * @returns the resolved package directory, or `undefined` when the package
47
+ * cannot be resolved (should never happen for a bundled direct dep).
48
+ */
49
+ export function resolveBundledPackageDir(packageName) {
50
+ let resolvedEntry;
51
+ try {
52
+ resolvedEntry = requireFromHere.resolve(packageName);
53
+ }
54
+ catch (error) {
55
+ // A bundled direct dep failing to resolve is a packaging fault — log it
56
+ // so the subsequent fail-closed throw is diagnosable, then signal the
57
+ // unresolved state to the caller (which raises PluginIncompatibleError).
58
+ logger.debug({
59
+ evt: 'cli.tool.bundled_unresolved',
60
+ module: BOOTSTRAP_MODULE,
61
+ packageName,
62
+ error: error instanceof Error ? error.message : String(error),
63
+ });
64
+ return undefined;
65
+ }
66
+ let dir = dirname(resolvedEntry);
67
+ for (let i = 0; i < 50; i++) {
68
+ const pkgPath = join(dir, 'package.json');
69
+ if (existsSync(pkgPath)) {
70
+ try {
71
+ const json = JSON.parse(readFileSync(pkgPath, 'utf8'));
72
+ if (json.name === packageName)
73
+ return dir;
74
+ }
75
+ catch {
76
+ // @swallow-ok unreadable package.json on the walk-up — keep climbing.
77
+ }
78
+ }
79
+ const parent = dirname(dir);
80
+ if (parent === dir)
81
+ break;
82
+ dir = parent;
83
+ }
84
+ return undefined;
85
+ }
86
+ /**
87
+ * Resolve a bundled tool package's on-disk directory, requiring success.
88
+ *
89
+ * @throws {PluginIncompatibleError} when the package directory cannot be
90
+ * resolved on disk (its manifest is unreadable).
91
+ */
92
+ export function resolveRequiredBundledPackageDir(packageName) {
93
+ const dir = resolveBundledPackageDir(packageName);
94
+ if (dir !== undefined)
95
+ return dir;
96
+ throw new PluginIncompatibleError(`bundled tool '${packageName}' could not be resolved on disk; its manifest is unreadable`, { diagnostic: 'package directory not resolvable' });
97
+ }
98
+ //# sourceMappingURL=register-tools-shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-tools-shared.js","sourceRoot":"","sources":["../../src/bootstrap/register-tools-shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAEpE,2EAA2E;AAC3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC;AAEhD,uFAAuF;AACvF,MAAM,eAAe,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,6BAA6B,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5E,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,CAGlF,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAsB,eAAe,CAAC,eAAe,CAAC;AAExF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAs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AED;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAAC,WAAmB;IAClE,MAAM,GAAG,GAAG,wBAAwB,CAAC,WAAW,CAAC,CAAC;IAClD,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,GAAG,CAAC;IAClC,MAAM,IAAI,uBAAuB,CAC/B,iBAAiB,WAAW,6DAA6D,EACzF,EAAE,UAAU,EAAE,kCAAkC,EAAE,CACnD,CAAC;AACJ,CAAC"}
@@ -10,200 +10,8 @@
10
10
  * a noisy warning when a third-party package happens to ship under a
11
11
  * built-in id.
12
12
  */
13
- import { type CliProgram } from '@opensip-cli/contracts';
14
- import { type ToolCliContext, type ToolDiscoverySource, type ToolPluginManifest, type ToolProvenance, type ToolRegistry } from '@opensip-cli/core';
15
- export declare const BUNDLED_TOOL_PACKAGES: readonly string[];
16
- /**
17
- * The ADR-0038 back-compat pin: the tool IDS whose `init` scaffold dirs the
18
- * pre-registry-driven CLI ALWAYS created (fit/sim). The composition root warns
19
- * (`cli.tool.expected_bundled_absent`) when one of these is missing from the
20
- * populated registry, so a build whose {@link BUNDLED_TOOL_PACKAGES} drifted
21
- * (a tool removed, a packaging variant) under-scaffolds LOUDLY instead of
22
- * silently.
23
- *
24
- * Now derived from the same manifest as BUNDLED_TOOL_PACKAGES (Workstream A)
25
- * so a single edit keeps them in sync. `graph` is correctly absent: it never
26
- * scaffolded (`pluginLayout` undefined).
27
- */
28
- export declare const EXPECTED_SCAFFOLDING_TOOL_IDS: readonly string[];
29
- /**
30
- * Register the bundled first-party tools into the supplied registry, each one
31
- * flowing through the SAME admit → dynamic-import → register path the external
32
- * path uses (launch cutover — replaces the static-import + gate path).
33
- *
34
- * Per package name: `resolveBundledPackageDir` → `loadToolManifest('bundled')`
35
- * → `admitTool({ source: 'bundled', explicitlyRequested: true })` →
36
- * `importToolRuntime` (dynamic import + shape validation) → drift guard →
37
- * `registry.register`. A bundled tool ships with the CLI, so it is always
38
- * explicitly present: a missing/incompatible manifest or a runtime that fails
39
- * to load is FAIL-CLOSED (never a silent skip). The recorded `ToolProvenance`
40
- * (source `'bundled'`, trusted-by-shipping) and manifest are pushed onto the
41
- * optional collectors so the composition root can surface provenance
42
- * (`plugin list`) and seed the per-run capability registry (§5.3).
43
- *
44
- * @param registry The per-invocation tool registry to populate.
45
- * @param provenance Optional sink for the admitted tools' provenance records.
46
- * @param manifests Optional sink for the admitted tools' manifests (§5.3).
47
- * @param packages The bundled package names to load (defaults to
48
- * {@link BUNDLED_TOOL_PACKAGES}; injectable so the fail-closed paths are
49
- * testable with fixture packages).
50
- * @throws {PluginIncompatibleError} when a bundled tool cannot be resolved,
51
- * has no conformant manifest, is out of range, or its runtime fails to load
52
- * — mapped to `EXIT_CODES.PLUGIN_INCOMPATIBLE` (exit 5) by the CLI boundary.
53
- */
54
- export declare function registerFirstPartyTools(registry: ToolRegistry, provenance?: ToolProvenance[], manifests?: ToolPluginManifest[], packages?: readonly string[]): Promise<void>;
55
- export interface DiscoveryOptions {
56
- /**
57
- * Ordered tool-discovery sources (precedence: first wins on duplicate
58
- * name). Built by {@link buildToolDiscoverySources} at the composition
59
- * root; passed in here so this function reads no ambient HOME/cwd state
60
- * and stays unit-testable with explicit anchors.
61
- */
62
- readonly sources: readonly ToolDiscoverySource[];
63
- }
64
- /**
65
- * Build the ordered tool-discovery sources. Order is precedence
66
- * (first-occurrence-wins on duplicate name):
67
- *
68
- * 1. project-local `.runtime/plugins/tool` — `plugin add --project`
69
- * 2. project tree (walk up from cwd) — plain `npm install @tool`
70
- * 3. user-global `~/.opensip-cli/plugins/tool` — `plugin add` (default)
71
- * 4. CLI install dir (walk up) — `npm i -g @tool`
72
- *
73
- * A project-local pin therefore shadows a user-global install of the same
74
- * tool. Project-root resolution is best-effort: an unresolvable context
75
- * (e.g. running outside any project) simply contributes no `.runtime`
76
- * source.
77
- */
78
- export declare function buildToolDiscoverySources(cwd: string, cliInstallDir: string): ToolDiscoverySource[];
79
- export declare function discoverAndRegisterToolPackages(registry: ToolRegistry, opts: DiscoveryOptions, builtInIds: ReadonlySet<string>, provenance?: ToolProvenance[], manifests?: ToolPluginManifest[]): Promise<void>;
80
- /**
81
- * The outcome of admitting a tool — the recorded `ToolProvenance` plus the
82
- * loaded `ToolPluginManifest`. Returned by the authored legs
83
- * ({@link admitUserGlobalTool} / {@link admitProjectLocalTool}) and the
84
- * installed leg ({@link admitInstalledTool}) alike. The manifest is returned
85
- * (not re-read) so the register step can run the drift guard
86
- * (`assertManifestMatchesTool`) against the imported runtime and seed the
87
- * per-run capability registry, without a second filesystem read.
88
- */
89
- export interface AuthoredAdmission {
90
- readonly provenance: ToolProvenance;
91
- readonly manifest: ToolPluginManifest;
92
- }
93
- /**
94
- * Admit (or reject) a single PROJECT-LOCAL authored tool under the
95
- * deny-by-default trust policy (launch, Phase 3 Task 3.2; wired into
96
- * production discovery in the launch contract).
97
- *
98
- * A project-local tool is authored code under
99
- * `<project>/opensip-cli/tools/<name>/` declaring its identity via a JSON
100
- * sidecar (`opensip-tool.manifest.json`). It is read + gated WITHOUT importing
101
- * its module:
102
- *
103
- * 1. `loadToolManifest('project-local', dir)` — identity only, no code run.
104
- * 2. Trust check — {@link isProjectLocalToolTrusted}. Not allowlisted ⇒
105
- * throw {@link PluginIncompatibleError} (fail-closed, exit 5) before any
106
- * import. Allowlisted ⇒ run the shared compatibility tail; an incompatible
107
- * explicitly-trusted tool is likewise fail-closed.
108
- *
109
- * Returns the admitted tool's `{ provenance, manifest }` on success. The trust
110
- * decision always precedes import (it is the FIRST statement here, ahead of the
111
- * shared {@link admitAuthoredTool} tail).
112
- *
113
- * @throws {PluginIncompatibleError} when the tool has no conformant sidecar
114
- * manifest, is not allowlisted, or is compatibility-incompatible.
115
- */
116
- export declare function admitProjectLocalTool(args: {
117
- readonly dir: string;
118
- readonly env?: NodeJS.ProcessEnv;
119
- }): AuthoredAdmission;
120
- /**
121
- * Admit a single USER-GLOBAL authored tool — the trusted-by-default sibling of
122
- * {@link admitProjectLocalTool}.
123
- *
124
- * A user-global tool is an authored sidecar under
125
- * `~/.opensip-cli/tools/<name>/`. The user deliberately placed it in their
126
- * own home dir (the `npm i -g` analogue for authored code), so there is **no
127
- * allowlist gate** — it is trusted-by-default. It still reads the static
128
- * sidecar and runs `admitTool` BEFORE the module could be imported (the shared
129
- * {@link admitAuthoredTool} tail), so trust-before-import holds for this leg
130
- * too: a global tool the user explicitly authored is fail-closed on a
131
- * missing/incompatible manifest, never a silent skip.
132
- *
133
- * @throws {PluginIncompatibleError} when the tool has no conformant sidecar
134
- * manifest or is compatibility-incompatible.
135
- */
136
- export declare function admitUserGlobalTool(args: {
137
- readonly dir: string;
138
- }): AuthoredAdmission;
139
- /**
140
- * Discover + admit + register AUTHORED Tool sidecars from the two authored
141
- * roots, then dynamic-import each admitted runtime through the shared
142
- * `importToolRuntime` seam — the same admit → import → register path the
143
- * bundled and installed legs travel (ADR-0027; this is the leg that makes the
144
- * dormant {@link admitProjectLocalTool} live).
145
- *
146
- * Two roots, two trust postures:
147
- * - **global** (`~/.opensip-cli/tools/`) → {@link admitUserGlobalTool},
148
- * trusted-by-default.
149
- * - **project** (`<project>/opensip-cli/tools/`) → {@link admitProjectLocalTool},
150
- * deny-by-default (allowlist via `OPENSIP_CLI_ALLOW_PROJECT_TOOLS`).
151
- *
152
- * Global is processed FIRST so a project-authored tool cannot shadow a same-id
153
- * global one — matching the `~/.opensip-cli/plugins` precedence note in
154
- * {@link buildToolDiscoverySources} (first-writer-wins via the registry).
155
- * `builtInIds` are skipped so an authored tool never shadows a bundled one.
156
- *
157
- * **Trust-before-import.** For each candidate, the admit step (which EMBEDS the
158
- * trust decision — deny-by-default inside `admitProjectLocalTool`) runs to
159
- * completion BEFORE `importToolRuntime`. A non-allowlisted project tool THROWS
160
- * `PluginIncompatibleError` (exit 5) here, propagated out of the walk: it must
161
- * fail the run loudly — that is the clone-protection contract.
162
- *
163
- * **Error-posture asymmetry (deliberate).** An un-allowlisted *project* tool is
164
- * fail-closed by policy (clone-risk; the user must opt in). A *global* tool that
165
- * fails to load is also fail-closed (the user explicitly authored it into
166
- * `$HOME`). This differs from the *installed* npm leg, where a stray bad plugin
167
- * skips-with-diagnostic so it can't take fit/graph/sim down — authored tools are
168
- * first-party-intent, installed tools are ambient.
169
- *
170
- * @param registry The per-invocation tool registry to populate.
171
- * @param opts.projectAuthoredDir `resolveProjectPaths(root).authoredToolsDir`,
172
- * or `undefined` when there is no resolvable project context.
173
- * @param opts.globalAuthoredDir `resolveUserPaths().authoredToolsDir`.
174
- * @param opts.env Environment carrying the project allowlist (default
175
- * `process.env`); injectable for tests.
176
- * @param builtInIds Bundled-tool ids to skip on a name collision.
177
- * @param provenance Sink for admitted authored tools' provenance records.
178
- * @param manifests Sink for admitted authored tools' manifests (§5.3).
179
- * @throws {PluginIncompatibleError} for an un-allowlisted project tool, or any
180
- * authored tool whose sidecar/runtime is missing/incompatible (fail-closed).
181
- */
182
- export declare function discoverAndRegisterAuthoredTools(registry: ToolRegistry, opts: {
183
- readonly projectAuthoredDir?: string;
184
- readonly globalAuthoredDir: string;
185
- readonly env?: NodeJS.ProcessEnv;
186
- }, builtInIds: ReadonlySet<string>, provenance?: ToolProvenance[], manifests?: ToolPluginManifest[]): Promise<void>;
187
- /**
188
- * Walk the registry and mount each tool's commands onto `program`. This is
189
- * **step 8** of the tool lifecycle (launch, §5.4) — see
190
- * {@link runToolLifecycle}.
191
- *
192
- * Public launch: there is ONE command surface — the tool's declared `commandSpecs`,
193
- * mounted by `mountCommandSpec`. `register()` and the raw-Commander `program`
194
- * handle on the tool context are gone, so the host owns `program` and passes it
195
- * in here (the tool never touches Commander). A tool with no `commandSpecs` is a
196
- * mis-declaration: it contributes no commands, surfaced loudly via
197
- * `cli.tool.no_command_surface`.
198
- *
199
- * Failures are isolated per tool — one tool whose spec fails to mount must not
200
- * take the whole CLI down. The failure is logged + stderr-warned, then we
201
- * continue with the next tool.
202
- *
203
- * @param registry The per-invocation tool registry to walk.
204
- * @param program The root Commander program (host-owned; the composition root
205
- * passes it — it is no longer reachable through the tool context, §8).
206
- * @param ctx The per-invocation handler context (render/emit/scope — no program).
207
- */
208
- export declare function mountAllToolCommands(registry: ToolRegistry, program: CliProgram, ctx: ToolCliContext): void;
13
+ export { BUNDLED_TOOL_PACKAGES, EXPECTED_SCAFFOLDING_TOOL_IDS } from './register-tools-shared.js';
14
+ export { registerFirstPartyTools } from './register-tools-bundled.js';
15
+ export { type DiscoveryOptions, buildToolDiscoverySources, discoverAndRegisterToolPackages, type AuthoredAdmission, admitProjectLocalTool, admitUserGlobalTool, discoverAndRegisterAuthoredTools, } from './register-tools-discovery.js';
16
+ export { mountAllToolCommands } from './register-tools-mount.js';
209
17
  //# sourceMappingURL=register-tools.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"register-tools.d.ts","sourceRoot":"","sources":["../../src/bootstrap/register-tools.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAOH,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAaL,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,YAAY,EAElB,MAAM,mBAAmB,CAAC;AAgC3B,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAAoC,CAAC;AAExF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,6BAA6B,EAAE,SAAS,MAAM,EAAuC,CAAC;AA0EnG;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,YAAY,EACtB,UAAU,GAAE,cAAc,EAAO,EACjC,SAAS,GAAE,kBAAkB,EAAO,EACpC,QAAQ,GAAE,SAAS,MAAM,EAA0B,GAClD,OAAO,CAAC,IAAI,CAAC,CAwCf;AA8DD,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,SAAS,mBAAmB,EAAE,CAAC;C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