superpowers-manager 0.2.0 → 0.3.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 (64) hide show
  1. package/README.md +112 -47
  2. package/bin/superpowers-manager.js +9 -283
  3. package/dist/adapter-result.js +204 -0
  4. package/dist/adapter.js +649 -0
  5. package/dist/atomic.js +142 -0
  6. package/dist/cli-arguments.js +32 -0
  7. package/dist/cli.js +293 -0
  8. package/dist/codex-json.js +89 -0
  9. package/dist/codex-state.js +78 -0
  10. package/dist/commands/context.js +1 -0
  11. package/dist/commands/install.js +376 -0
  12. package/dist/commands/pin.js +79 -0
  13. package/dist/commands/prepare.js +527 -0
  14. package/dist/commands/probe.js +392 -0
  15. package/dist/commands/track-latest.js +44 -0
  16. package/dist/commands/uninstall.js +308 -0
  17. package/dist/commands/unpin.js +95 -0
  18. package/dist/commands/update.js +138 -0
  19. package/dist/domain/fingerprint.js +4 -0
  20. package/dist/domain/refs.js +37 -0
  21. package/dist/effective-selection.js +123 -0
  22. package/dist/generated-plugin.js +748 -0
  23. package/dist/git.js +38 -0
  24. package/dist/hooks.js +290 -0
  25. package/dist/lifecycle.js +220 -0
  26. package/dist/manifest-overlay.js +125 -0
  27. package/dist/provenance.js +111 -0
  28. package/dist/python-json-format.js +83 -0
  29. package/dist/python-json.js +29 -0
  30. package/dist/python-text.js +74 -0
  31. package/dist/safe-path.js +137 -0
  32. package/dist/safety-error.js +10 -0
  33. package/dist/selection-state-cli.js +85 -0
  34. package/dist/selection-store.js +172 -0
  35. package/dist/selection.js +200 -0
  36. package/dist/status.js +24 -0
  37. package/dist/strict-json.js +248 -0
  38. package/dist/upstream-cli.js +110 -0
  39. package/dist/upstream-version.js +40 -0
  40. package/dist/upstream.js +253 -0
  41. package/dist/validate-generated-plugin-cli.js +118 -0
  42. package/dist/validator.js +317 -0
  43. package/dist/workspace.js +139 -0
  44. package/package.json +25 -2
  45. package/scripts/adapters/codex/adapter +0 -603
  46. package/scripts/adapters/codex/lib.sh +0 -449
  47. package/scripts/adapters/codex/validate-generated-plugin.py +0 -314
  48. package/scripts/core/adapter.sh +0 -103
  49. package/scripts/core/common.sh +0 -59
  50. package/scripts/core/lifecycle.sh +0 -141
  51. package/scripts/core/provenance.sh +0 -135
  52. package/scripts/core/selection-state.py +0 -414
  53. package/scripts/core/selection.sh +0 -168
  54. package/scripts/core/status.sh +0 -27
  55. package/scripts/core/upstream.sh +0 -280
  56. package/scripts/core/validate-adapter-response.py +0 -284
  57. package/scripts/install +0 -59
  58. package/scripts/pin +0 -51
  59. package/scripts/prepare +0 -117
  60. package/scripts/probe +0 -82
  61. package/scripts/track-latest +0 -30
  62. package/scripts/uninstall +0 -35
  63. package/scripts/unpin +0 -41
  64. package/scripts/update +0 -34
package/README.md CHANGED
@@ -19,7 +19,7 @@ npx superpowers-manager update
19
19
  Use the official marketplace for the simplest native Codex installation. Use
20
20
  Superpowers Manager when you want immediate stable-upstream freshness after a
21
21
  user-triggered install/update, per-invocation release or commit selection,
22
- recorded upstream provenance, diagnostics, Codex-specific hook-free packaging,
22
+ recorded upstream provenance, diagnostics, upstream-owned Codex hook handling,
23
23
  and explicit install/update/probe/uninstall lifecycle control.
24
24
 
25
25
  | Choose | Best fit |
@@ -39,14 +39,32 @@ It never removes the legacy provider automatically.
39
39
 
40
40
  ## Requirements and platforms
41
41
 
42
- Superpowers Manager requires Node 24+, `git`, Python 3, and a POSIX `sh`.
43
- Codex CLI is required for `probe`, `install`, `update`, and `uninstall`;
44
- `prepare`, `pin`, `track-latest`, and `unpin` do not require it. Codex is the
45
- only supported integration today.
42
+ Superpowers Manager requires Node 24+, and Codex is the only supported
43
+ integration today. Every other requirement is per command, enforced by
44
+ preflight before any dispatch. This table is checked against production by
45
+ `tests/bin/readme-requirements.test.js`; edit it when a command's requirements
46
+ change, in the same pull request.
47
+
48
+ <!-- requirements:begin -->
49
+ | Command | git | Python 3 | Codex CLI |
50
+ |---|---|---|---|
51
+ | `pin` | yes | no | no |
52
+ | `track-latest` | no | no | no |
53
+ | `unpin` | no | no | no |
54
+ | `prepare` | yes | only with SUPERPOWERS_VALIDATOR | no |
55
+ | `probe` | yes | no | yes |
56
+ | `install` | yes | no | yes |
57
+ | `update` | yes | no | yes |
58
+ | `uninstall` | no | no | yes |
59
+ <!-- requirements:end -->
60
+
61
+ See `docs/baseline/behavioral-inventory.md`'s `CLI-PREFLIGHT-01` for the
62
+ behaviour this table describes.
46
63
 
47
64
  macOS and Linux are tested. WSL2 is supported. The native Windows path is
48
- untested; the launcher looks for Git Bash, `git`, and `python3`, but path
49
- handling between MSYS and Codex remains a known risk area.
65
+ untested; the launcher no longer looks for Git Bash at all — every command runs
66
+ in-process, so no POSIX shell is discovered or required — but path handling
67
+ between MSYS and Codex remains a known risk area.
50
68
 
51
69
  Network needs depend on the saved policy. `pin` verifies its target;
52
70
  `track-latest` and invocation overrides resolve from upstream when applied; and
@@ -60,30 +78,40 @@ updates.
60
78
  - Resolves an upstream ref, defaulting to the latest stable `vX.Y.Z` release
61
79
  tag.
62
80
  - Clones/fetches upstream at that commit and assembles a Codex plugin tree under
63
- `plugins/superpowers/` (skills, assets, license/readme, and manifest;
64
- upstream's `hooks/` directory is deliberately excluded).
81
+ `plugins/superpowers/` (skills, assets, license/readme, manifest, and any
82
+ hook files that the upstream manifest allows).
65
83
  - Stamps the generated manifest with a ref-aware manager version ending in
66
84
  `+manager.<short-sha>` and writes the upstream provenance to
67
85
  `.superpowers-upstream.json`.
68
- - Validates the generated tree with the manager's shipped, Python-standard-library
69
- contract validator before swapping it into place (a failed run never destroys
70
- a previously generated tree).
86
+ - Validates the generated tree with the manager's shipped contract validator
87
+ before swapping it into place (a failed run never destroys a previously
88
+ generated tree).
71
89
  - Registers the `superpowers-manager` marketplace and installs or refreshes
72
90
  `superpowers@superpowers-manager` in Codex.
73
91
 
74
- The generated plugin carries upstream skills, assets, and documentation. The
75
- manager excludes upstream `hooks/`, removes the manifest `hooks` field, and
76
- validates that both stay absent. This is a Codex-specific adapter policy, not a
77
- claim about how Superpowers should be packaged for future or other harnesses.
78
- Changing the hook-free policy requires a separate design and current
79
- compatibility evidence.
92
+ The generated plugin carries upstream skills, assets, documentation, and the
93
+ upstream-owned hook policy. When upstream provides a Codex manifest, its
94
+ `hooks` declaration is preserved: exact `{}` suppresses the `hooks/` subtree;
95
+ active declarations conditionally materialize the upstream hook files; and a
96
+ missing `hooks` key or explicit empty array (`[]`) declaration uses Codex's
97
+ default discovery only when upstream ships `hooks/hooks.json`. Manifest-less
98
+ fallback refs use the committed minimal template and generate neither a manifest
99
+ `hooks` key nor a `hooks/` directory.
100
+ The manager never creates its own hooks or mutates Codex trust state.
101
+
102
+ Review upstream hook command definitions with Codex's `/hooks` flow. Codex
103
+ trust applies to a command definition, not to the contents of scripts that the
104
+ definition references. An explicit update of an older pin can therefore change
105
+ the contents of a trusted referenced script, or reveal a newly untrusted
106
+ upstream definition; review it before trusting or running it. This policy
107
+ eliminates latent hook-policy drift.
80
108
 
81
109
  ## Runtime architecture
82
110
 
83
- - `scripts/core/` owns the shared lifecycle, status, and protocol validation;
84
- see the [version-1 adapter response protocol](https://github.com/j7an/superpowers-manager/blob/main/docs/adapter-protocol.md).
85
- - `scripts/adapters/codex/` owns build, inspection, reconciliation, and Codex
86
- mutation.
111
+ - The in-process TypeScript runtime under `src/` owns lifecycle dispatch,
112
+ status, and adapter-result handling;
113
+ see the [in-process adapter result contract](https://github.com/j7an/superpowers-manager/blob/main/docs/adapter-result-contract.md).
114
+ - `src/adapter.ts` owns build, inspection, reconciliation, and Codex mutation.
87
115
  - Codex is the only supported adapter today; no public harness selector ships
88
116
  yet.
89
117
 
@@ -97,10 +125,33 @@ after the built-in check. It receives the candidate plugin root as its only
97
125
  argument. It cannot replace or bypass built-in validation, and either check
98
126
  failing prevents the tree swap and all Codex mutation.
99
127
 
100
- Direct `scripts/install` keeps harness-specific validation in the Codex adapter:
101
- phase 1 prepares the exact candidate first, then the adapter performs its Codex
102
- and refresh-mode preflight before any Codex mutation. The Node dispatcher keeps
103
- its existing Codex preflight before dispatching to the shell lifecycle.
128
+ `SUPERPOWERS_VALIDATOR_EXECUTABLE=/path/to/validator` adds an optional external
129
+ validator after the built-in check. It names an executable, receiving the
130
+ candidate plugin root as its only argument. The manager constructs no shell
131
+ command string and supplies argv directly. On Linux, `execvp` may hand that
132
+ same argv to `/bin/sh` after `ENOEXEC`, and the values are preserved rather
133
+ than re-parsed, so a candidate path containing spaces or shell metacharacters
134
+ is passed through intact and cannot inject a command — on either platform. A
135
+ file with the exec bit set but no valid executable format is handled by the
136
+ platform's own `execvp` fallback, not by the manager: on Linux, `/bin/sh` runs
137
+ it as shell source; on darwin, it is
138
+ rejected outright as not runnable. Give the validator a shebang line or make
139
+ it a real binary, or its behavior will differ by platform. Exit 0 accepts;
140
+ any nonzero exit rejects and prevents the tree swap. The manager stops
141
+ waiting after 30 seconds and keeps at most 64 KiB of each of its output
142
+ streams. It cannot replace or bypass built-in validation, and it is not a
143
+ security boundary: it runs with the manager's own privileges, by design.
144
+
145
+ `SUPERPOWERS_VALIDATOR` is deprecated in favor of `SUPERPOWERS_VALIDATOR_EXECUTABLE`
146
+ and continues to work unchanged. The legacy variable requires `python3`; the
147
+ executable hook does not. Setting both is rejected at preflight, before any
148
+ network or Codex access, rather than silently resolved. Removal of the legacy
149
+ variable is deferred to a future major release.
150
+
151
+ The in-process install command keeps harness-specific validation in the Codex
152
+ adapter: phase 1 prepares the exact candidate first, then the adapter performs
153
+ its Codex and refresh-mode preflight before any Codex mutation. The CLI runs
154
+ its Codex preflight before invoking the lifecycle handler.
104
155
 
105
156
  ## Provider ownership
106
157
 
@@ -218,15 +269,17 @@ updates the official provider or any other provider automatically.
218
269
 
219
270
  - **Upstream manifest first:** when upstream provides
220
271
  `.codex-plugin/plugin.json`, `prepare` uses it as the generated manifest base
221
- so future upstream metadata fields are preserved by default.
272
+ so future upstream metadata fields, including its hook declaration, are
273
+ preserved by default.
222
274
  - **Fallback template:** `plugins/superpowers/.codex-plugin/plugin.template.json`
223
275
  is committed as a minimal fallback for older upstream refs that do not ship a
224
276
  Codex manifest. It carries the placeholder version
225
- `0.0.0+manager.template`.
277
+ `0.0.0+manager.template`, declares no hooks, and produces no `hooks/`
278
+ directory.
226
279
  - **Manager overlay:** `prepare` replaces the version with a ref-aware manager
227
- version, forces `skills` to `./skills/`, and enforces the manager's current
228
- hook-free policy: no manifest `hooks` key and no copied `hooks/` directory.
229
- Unknown upstream manifest fields remain preserved.
280
+ version and forces `skills` to `./skills/`. Unknown upstream manifest fields,
281
+ including `hooks`, remain preserved; the adapter materializes hook files only
282
+ according to the upstream declaration.
230
283
  - Stable tags generate release-looking versions such as
231
284
  `6.0.3+manager.896224c`; explicit prerelease tags generate versions such as
232
285
  `6.1.0-beta.1+manager.abc1234`.
@@ -256,11 +309,16 @@ updates the official provider or any other provider automatically.
256
309
  ## Tests
257
310
 
258
311
  ```sh
312
+ pnpm install --frozen-lockfile
313
+ pnpm run build
259
314
  sh tests/run.sh # Layers 1-3: host-side hermetic checks while iterating
260
315
  sh tests/container.sh # Layers 1-4: blocking Docker acceptance command
261
316
  sh tests/manual/codex-behavior-probe.sh # optional native-only compatibility residue
262
317
  ```
263
318
 
319
+ `pnpm run build` deletes `dist/` before compiling, so every build is a clean
320
+ rebuild and stale artifacts of deleted or renamed modules cannot survive.
321
+
264
322
  Layers 1-3 stay offline and hermetic: they use a fake local upstream repo plus
265
323
  host-side fixtures, and they perform no mutation of the developer's or runner's
266
324
  real Codex state.
@@ -273,29 +331,36 @@ an isolated container home with networking disabled. That container run may
273
331
  mutate the throwaway container-local Codex state, but it still performs no
274
332
  mutation of the developer's or runner's real Codex state.
275
333
 
334
+ The container probe uses Codex's `hooks/list` only as compatibility evidence
335
+ for the tested Codex build. It is not a stable Superpowers Manager API.
336
+
276
337
  The manual probe is opt-in and covers native-only compatibility residue such as
277
- path/cache behavior against an intentionally real local Codex install. It is
278
- not part of acceptance. GitHub Actions runs the blocking container acceptance
279
- command on pull requests and pushes to `main`.
338
+ path/cache and version-precedence behavior against an intentionally real local
339
+ Codex install. It is not part of acceptance. GitHub Actions runs both the
340
+ toolchain check and the blocking container acceptance command on pull requests
341
+ and pushes to `main`.
280
342
 
281
343
  ## Repository layout
282
344
 
283
345
  ```
284
346
  .agents/plugins/marketplace.json # local marketplace definition (tracked)
285
- config/upstream-ref # which upstream ref to track (tracked)
347
+ .github/ # CI, security, dependency, and release workflows (tracked)
348
+ bin/superpowers-manager.js # public thin loader for dist/cli.js
349
+ config/upstream-ref # packaged upstream fallback policy (tracked)
350
+ docs/ # adapter result contract and baseline evidence (tracked)
351
+ package.json pnpm-lock.yaml tsconfig.json # package contract and locked toolchain (tracked)
286
352
  plugins/superpowers/
287
- .codex-plugin/plugin.template.json # fallback manifest template (tracked)
288
- .codex-plugin/plugin.json # generated manifest (gitignored)
289
- skills/ assets/ LICENSE ... # generated from upstream (gitignored)
290
- .superpowers-upstream.json # generated provenance (gitignored)
291
- scripts/
292
- adapters/codex/ # Codex adapter entrypoint + validator helpers
293
- core/ # shared lifecycle, selection, provenance, and status modules
294
- pin track-latest unpin # persistent-selection entrypoints
295
- prepare probe install update uninstall # lifecycle entrypoints
296
- tests/ # hermetic suite + manual Codex probe
297
- .cache/upstream/ # upstream clone cache (gitignored)
353
+ .codex-plugin/plugin.template.json # fallback manifest template (tracked)
354
+ generated plugin tree # prepared from upstream (gitignored)
355
+ src/ # in-process TypeScript runtime (tracked)
356
+ cli.ts # CLI parsing, preflight, and command dispatch
357
+ commands/ # lifecycle and selection command handlers
358
+ adapter.ts # Codex integration
359
+ tests/ # hermetic suite and manual Codex probe (tracked)
360
+ migration-inventory/ # frozen historical evidence
361
+ dist/ # generated ESM build tree (gitignored)
298
362
  ```
299
363
 
300
364
  Everything under `plugins/superpowers/` except the fallback manifest template is
301
- generated by `prepare` and ignored by Git; re-run `prepare` to regenerate it.
365
+ generated by `npx superpowers-manager prepare` and ignored by Git; re-run that
366
+ command to regenerate it.
@@ -1,290 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  // @ts-check
3
3
 
4
- import * as fs from 'node:fs';
5
- import * as path from 'node:path';
6
- import { spawnSync } from 'node:child_process';
4
+ import { existsSync } from "node:fs";
7
5
 
8
- /**
9
- * @typedef {'pin' | 'track-latest' | 'unpin' | 'prepare' | 'probe' | 'install' | 'update' | 'uninstall'} Subcommand
10
- */
6
+ const cliUrl = new URL("../dist/cli.js", import.meta.url);
11
7
 
12
- /**
13
- * @typedef {{ kind: 'run', cmd: Subcommand, args: string[] }} RunParseResult
14
- * @typedef {{ kind: 'help' }} HelpParseResult
15
- * @typedef {{ kind: 'version' }} VersionParseResult
16
- * @typedef {{ kind: 'usage-error', message: string }} UsageErrorParseResult
17
- * @typedef {RunParseResult | HelpParseResult | VersionParseResult | UsageErrorParseResult} ParseResult
18
- */
19
-
20
- /**
21
- * @typedef {{ ok: true, shell: string }} PreflightOk
22
- * @typedef {{ ok: false, errors: string[] }} PreflightError
23
- * @typedef {PreflightOk | PreflightError} PreflightResult
24
- */
25
-
26
- /**
27
- * @typedef {{ file: string, argv: string[] }} SpawnDescriptor
28
- */
29
-
30
- const SUBCOMMANDS = [
31
- 'pin', 'track-latest', 'unpin', 'prepare', 'probe', 'install', 'update', 'uninstall',
32
- ];
33
- const PIN_TAG_RE = /^v(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-(?:(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*))?$/;
34
- const PIN_COMMIT_RE = /^[0-9A-Fa-f]{40}$/;
35
- /** @type {Record<Subcommand, string[]>} */
36
- const COMMAND_REQUIREMENTS = {
37
- pin: ['git', 'python3'],
38
- 'track-latest': ['python3'],
39
- unpin: [],
40
- prepare: ['git', 'python3'],
41
- probe: ['git', 'python3', 'codex'],
42
- install: ['git', 'python3', 'codex'],
43
- update: ['git', 'python3', 'codex'],
44
- uninstall: ['python3', 'codex'],
45
- };
46
- // Mirrors upstream Superpowers' hooks/run-hook.cmd discovery order.
47
- const GIT_BASH_CANDIDATES = [
48
- 'C:\\Program Files\\Git\\bin\\bash.exe',
49
- 'C:\\Program Files (x86)\\Git\\bin\\bash.exe',
50
- ];
51
-
52
- // Walk upward from the bin's physical location to the directory containing
53
- // package.json. realpathSync first: npm/npx expose the bin through a symlink
54
- // or shim outside the package root.
55
- /**
56
- * @param {string} scriptPath
57
- * @returns {string | null}
58
- */
59
- function resolvePackageRoot(scriptPath) {
60
- let dir;
61
- try {
62
- dir = path.dirname(fs.realpathSync(scriptPath));
63
- } catch (err) {
64
- return null;
65
- }
66
- for (;;) {
67
- if (fs.existsSync(path.join(dir, 'package.json'))) return dir;
68
- const parent = path.dirname(dir);
69
- if (parent === dir) return null;
70
- dir = parent;
71
- }
72
- }
73
-
74
- /**
75
- * @param {string} moduleFilename
76
- * @param {string | undefined} argvPath
77
- * @returns {boolean}
78
- */
79
- function isMain(moduleFilename, argvPath) {
80
- if (!argvPath) return false;
81
- return moduleFilename === fs.realpathSync(argvPath);
82
- }
83
-
84
- /**
85
- * @param {string[]} argv
86
- * @returns {ParseResult}
87
- */
88
- function parseArgs(argv) {
89
- /** @type {string | undefined} */
90
- const first = argv[0];
91
- if (argv.length === 0) return { kind: 'run', cmd: 'update', args: [] };
92
- if (first === '--help' || first === '-h') return { kind: 'help' };
93
- if (first === '--version') return { kind: 'version' };
94
- if (first && SUBCOMMANDS.includes(first)) {
95
- const args = argv.slice(1);
96
- if (first === 'pin' && args.length !== 1) {
97
- return { kind: 'usage-error', message: 'usage: superpowers-manager pin REF' };
98
- }
99
- if (first === 'pin' && !PIN_TAG_RE.test(args[0]) && !PIN_COMMIT_RE.test(args[0])) {
100
- return {
101
- kind: 'usage-error',
102
- message: 'pin REF must be an exact v-prefixed SemVer tag or full 40-hex commit',
103
- };
104
- }
105
- if ((first === 'track-latest' || first === 'unpin') && args.length !== 0) {
106
- return { kind: 'usage-error', message: `usage: superpowers-manager ${first}` };
107
- }
108
- return { kind: 'run', cmd: /** @type {Subcommand} */ (first), args };
109
- }
110
- return { kind: 'usage-error', message: `unknown subcommand: ${first}` };
111
- }
112
-
113
- // Search env.PATH for an executable named `name`; on win32 also try PATHEXT
114
- // extensions. Returns the full path or null.
115
- /**
116
- * @param {string} name
117
- * @param {NodeJS.ProcessEnv} env
118
- * @param {NodeJS.Platform} platform
119
- * @returns {string | null}
120
- */
121
- function findTool(name, env, platform) {
122
- const pathVar = env.PATH || env.Path || '';
123
- const dirs = pathVar.split(path.delimiter).filter(Boolean);
124
- const exts = platform === 'win32'
125
- ? (env.PATHEXT || '.EXE;.CMD;.BAT;.COM').split(';')
126
- : [''];
127
- for (const dir of dirs) {
128
- for (const ext of exts) {
129
- const candidate = path.join(dir, name + ext.toLowerCase());
130
- try {
131
- fs.accessSync(candidate, fs.constants.X_OK);
132
- return candidate;
133
- } catch (err) { /* keep looking */ }
134
- }
135
- }
136
- return null;
137
- }
138
-
139
- // POSIX: `sh` on PATH. Windows: Git Bash at its standard install paths,
140
- // then `bash` on PATH.
141
- /**
142
- * @param {NodeJS.ProcessEnv} env
143
- * @param {NodeJS.Platform} platform
144
- * @returns {string | null}
145
- */
146
- function discoverShell(env, platform) {
147
- if (platform !== 'win32') return findTool('sh', env, platform);
148
- for (const candidate of GIT_BASH_CANDIDATES) {
149
- try {
150
- fs.accessSync(candidate, fs.constants.X_OK);
151
- return candidate;
152
- } catch (err) { /* keep looking */ }
153
- }
154
- return findTool('bash', env, platform);
8
+ if (!existsSync(cliUrl)) {
9
+ console.error(
10
+ "dist/ not built — run `pnpm install --frozen-lockfile && pnpm run build`",
11
+ );
12
+ process.exit(1);
155
13
  }
156
14
 
157
- /**
158
- * @returns {Record<Subcommand, string[]>}
159
- */
160
- function commandRequirements() {
161
- return COMMAND_REQUIREMENTS;
162
- }
163
-
164
- // Tool preflight; never touches Codex state. Requirements are specific to the
165
- // selected command, while a POSIX shell remains mandatory for every command.
166
- /**
167
- * @param {Subcommand} cmd
168
- * @param {NodeJS.ProcessEnv} env
169
- * @param {NodeJS.Platform} platform
170
- * @returns {PreflightResult}
171
- */
172
- function preflight(cmd, env, platform) {
173
- const errors = [];
174
- for (const tool of COMMAND_REQUIREMENTS[cmd]) {
175
- if (tool === 'codex') {
176
- const codexBin = env.SUPERPOWERS_CODEX || 'codex';
177
- // An explicit override may be a path rather than a PATH-resolvable name.
178
- const found = codexBin.includes(path.sep)
179
- ? fs.existsSync(codexBin)
180
- : Boolean(findTool(codexBin, env, platform));
181
- if (!found) {
182
- errors.push(`required command not found: ${codexBin} — install the Codex CLI or set SUPERPOWERS_CODEX`);
183
- }
184
- } else if (!findTool(tool, env, platform)) {
185
- errors.push(`required command not found: ${tool} — install ${tool} and re-run`);
186
- }
187
- }
188
- const shell = discoverShell(env, platform);
189
- if (!shell) {
190
- errors.push(platform === 'win32'
191
- ? 'no POSIX shell found — install Git for Windows (provides bash) or use WSL2'
192
- : 'required command not found: sh');
193
- }
194
- if (errors.length) return { ok: false, errors };
195
- return { ok: true, shell: /** @type {string} */ (shell) };
196
- }
197
-
198
- // POSIX executes the script directly (#!/bin/sh shebang); Windows cannot
199
- // spawn extensionless scripts, so the discovered shell runs the script as
200
- // its first argument.
201
- /**
202
- * @param {Subcommand} cmd
203
- * @param {string[]} args
204
- * @param {string} root
205
- * @param {string} shell
206
- * @param {NodeJS.Platform} platform
207
- * @returns {SpawnDescriptor}
208
- */
209
- function buildSpawn(cmd, args, root, shell, platform) {
210
- const script = path.join(root, 'scripts', cmd);
211
- if (platform === 'win32') {
212
- return { file: shell, argv: [script, ...args] };
213
- }
214
- return { file: script, argv: args };
215
- }
216
-
217
- function usage() {
218
- return [
219
- 'usage: superpowers-manager [command] [args...]',
220
- '',
221
- 'Selection commands (save intent only; they do not prepare or install it):',
222
- ' pin REF save an exact upstream release tag or commit',
223
- ' track-latest save selection of the latest stable upstream release',
224
- ' unpin remove the saved selection and return to the packaged fallback',
225
- '',
226
- 'Apply and lifecycle commands:',
227
- ' prepare fetch the pinned upstream ref and generate the plugin tree',
228
- ' probe report upstream/generated/installed status (accepts --porcelain)',
229
- ' install register this package root as a Codex marketplace and install the plugin',
230
- ' update probe, then prepare/install only if needed (default when no subcommand)',
231
- ' uninstall remove the manager plugin and marketplace from Codex',
232
- '',
233
- 'Environment overrides (passed through to the scripts): SUPERPOWERS_REF,',
234
- 'SUPERPOWERS_UPSTREAM_URL, SUPERPOWERS_CODEX, SUPERPOWERS_CACHE_DIR,',
235
- 'SUPERPOWERS_CONFIG_DIR, XDG_CONFIG_HOME,',
236
- 'SUPERPOWERS_PLUGIN_ROOT, SUPERPOWERS_MANIFEST_TEMPLATE,',
237
- 'SUPERPOWERS_VALIDATOR,',
238
- 'SUPERPOWERS_INSTALLED_SEARCH_ROOT, SUPERPOWERS_INSTALL_REFRESH_MODE',
239
- '',
240
- 'Selection state uses SUPERPOWERS_CONFIG_DIR when set; otherwise it uses',
241
- '$XDG_CONFIG_HOME/superpowers-manager, then $HOME/.config/superpowers-manager.',
242
- ].join('\n');
243
- }
244
-
245
- function main() {
246
- const parsed = parseArgs(process.argv.slice(2));
247
- if (parsed.kind === 'help') {
248
- console.log(usage());
249
- process.exit(0);
250
- }
251
- const root = resolvePackageRoot(import.meta.filename);
252
- if (!root) {
253
- console.error('error: cannot resolve the superpowers-manager package root');
254
- process.exit(1);
255
- }
256
- if (parsed.kind === 'version') {
257
- console.log(JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')).version);
258
- process.exit(0);
259
- }
260
- if (parsed.kind === 'usage-error') {
261
- console.error(`error: ${parsed.message}`);
262
- console.error(usage());
263
- process.exit(2);
264
- }
265
- const pf = preflight(parsed.cmd, process.env, process.platform);
266
- if (!pf.ok) {
267
- for (const e of pf.errors) console.error(`error: ${e}`);
268
- process.exit(1);
269
- }
270
- const script = path.join(root, 'scripts', parsed.cmd);
271
- if (!fs.existsSync(script)) {
272
- console.error(`error: missing script: ${script}`);
273
- process.exit(1);
274
- }
275
- const spawn = buildSpawn(parsed.cmd, parsed.args, root, pf.shell, process.platform);
276
- // env is inherited wholesale, so every SUPERPOWERS_* override passes through.
277
- const res = spawnSync(spawn.file, spawn.argv, { stdio: 'inherit', env: process.env });
278
- if (res.error) {
279
- console.error(`error: cannot run ${spawn.file}: ${res.error.message}`);
280
- process.exit(1);
281
- }
282
- process.exit(res.status === null ? 1 : res.status);
283
- }
284
-
285
- export {
286
- resolvePackageRoot, isMain, parseArgs, findTool, discoverShell,
287
- commandRequirements, preflight, buildSpawn, usage,
288
- };
289
-
290
- if (isMain(import.meta.filename, process.argv[1])) main();
15
+ const { main } = await import(cliUrl.href);
16
+ main();