@testsprite/testsprite-cli 0.1.2 → 0.2.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/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import { createTestCommand } from './commands/test.js';
8
8
  import { createUsageCommand } from './commands/usage.js';
9
9
  import { ApiError, CLIError, RequestTimeoutError } from './lib/errors.js';
10
10
  import { Output, isOutputMode } from './lib/output.js';
11
- import { rephraseUnknownOption } from './lib/render-error.js';
11
+ import { renderCommanderError, rephraseUnknownOption } from './lib/render-error.js';
12
12
  import { maybeEmitSkillNudge } from './lib/skill-nudge.js';
13
13
  import { VERSION } from './version.js';
14
14
  const program = new Command();
@@ -51,25 +51,30 @@ program.addCommand(createProjectCommand({}));
51
51
  program.addCommand(createTestCommand());
52
52
  program.addCommand(createAgentCommand({}));
53
53
  program.addCommand(createUsageCommand());
54
- // Propagate exitOverride to every subcommand in the tree.
55
- // Commander's addCommand() does NOT inherit exitOverride from the parent,
56
- // so commands built externally (createTestCommand, createProjectCommand, …)
57
- // and attached via addCommand() still have _exitCallback = null and call
58
- // process.exit directly. Recursively set exitOverride so CommanderError
59
- // bubbles up to our catch block for every leaf subcommand.
54
+ // Buffer Commander error messages instead of writing immediately. The catch
55
+ // block re-emits in the correct format (JSON or text) once the requested
56
+ // output mode is known. Safe because applyExitOverrideDeep ensures every
57
+ // command throws CommanderError rather than calling process.exit directly.
58
+ let pendingCommanderErrorMsg = null;
59
+ // Propagate exitOverride AND the buffered outputError config to every
60
+ // subcommand in the tree. Commander's addCommand() does NOT inherit either
61
+ // from the parent, so commands built externally (createTestCommand, etc.) and
62
+ // attached via addCommand() still have _exitCallback = null and a default
63
+ // outputError that writes immediately. Both must be applied after the full
64
+ // command tree is assembled so every leaf subcommand behaves consistently.
60
65
  function applyExitOverrideDeep(cmd) {
61
66
  cmd.exitOverride();
67
+ cmd.configureOutput({
68
+ outputError(str, _write) {
69
+ const rephrased = rephraseUnknownOption(str);
70
+ pendingCommanderErrorMsg = rephrased !== null ? `${rephrased}\n` : str;
71
+ },
72
+ });
62
73
  for (const child of cmd.commands) {
63
74
  applyExitOverrideDeep(child);
64
75
  }
65
76
  }
66
77
  applyExitOverrideDeep(program);
67
- program.configureOutput({
68
- outputError(str, write) {
69
- const rephrased = rephraseUnknownOption(str);
70
- write(rephrased !== null ? `${rephrased}\n` : str);
71
- },
72
- });
73
78
  /**
74
79
  * Render a leaf command's full path (group + leaf), e.g. `test run` /
75
80
  * `auth whoami`, by walking parents up to (but not including) the root program.
@@ -161,9 +166,8 @@ catch (err) {
161
166
  process.exit(err.exitCode);
162
167
  }
163
168
  if (err instanceof CommanderError) {
164
- // Commander already wrote the error message (via configureOutput) or the
165
- // help/version text to stdout. Map exit codes per the CLI taxonomy:
166
- // help / version → 0 (user asked for it — no error)
169
+ // Map exit codes per the CLI taxonomy:
170
+ // help / version → 0 (user asked for it; Commander already wrote the text)
167
171
  // parse errors → 5 (VALIDATION_ERROR family: missing arg, invalid
168
172
  // option, unknown command, etc.)
169
173
  //
@@ -180,6 +184,24 @@ catch (err) {
180
184
  err.code === 'commander.version') {
181
185
  process.exit(0);
182
186
  }
187
+ // For parse errors, write the buffered message in the correct format.
188
+ // rawMode from program.opts() is reliable when --output was parsed before
189
+ // the error. When the error occurs first (e.g. `testsprite badcmd --output
190
+ // json`), rawMode is the default 'text'; scan argv as a best-effort
191
+ // fallback so machine consumers still receive a JSON envelope.
192
+ const commanderMode = (() => {
193
+ if (rawMode === 'json')
194
+ return 'json';
195
+ for (let i = 2; i < process.argv.length; i++) {
196
+ const arg = process.argv[i];
197
+ if (arg === '--output' && process.argv[i + 1] === 'json')
198
+ return 'json';
199
+ if (arg === '--output=json')
200
+ return 'json';
201
+ }
202
+ return mode;
203
+ })();
204
+ process.stderr.write(renderCommanderError(pendingCommanderErrorMsg, err.message, commanderMode));
183
205
  process.exit(5);
184
206
  }
185
207
  if (err instanceof CLIError) {
@@ -1,51 +1,132 @@
1
1
  export type AgentTarget = 'claude' | 'cursor' | 'cline' | 'antigravity' | 'codex';
2
2
  export interface TargetSpec {
3
3
  status: 'ga' | 'experimental';
4
- /** repo-relative landing path, POSIX separators */
4
+ /**
5
+ * Repo-relative landing path for the CANONICAL skill (`testsprite-verify`),
6
+ * POSIX separators. Kept for back-compat: `skill-nudge.ts` reads this to detect
7
+ * a verify install, and `agent list`/tests reference it. For any skill, derive
8
+ * the real path via {@link pathFor} — this field is `pathFor(target, SKILL_NAME)`.
9
+ */
5
10
  path: string;
6
11
  /**
7
- * 'own-file': the CLI owns the whole file (existing 4 targets).
12
+ * 'own-file': the CLI owns the whole file (claude/cursor/cline/antigravity).
8
13
  * 'managed-section': the CLI writes only a sentinel-delimited section inside
9
14
  * a potentially user-authored file (codex target, AGENTS.md).
10
15
  */
11
16
  mode: 'own-file' | 'managed-section';
12
- /** wrap the canonical body in this target's frontmatter/header */
13
- wrap(body: string): string;
17
+ /**
18
+ * Wrap a skill body in this target's frontmatter/header. Takes the skill's
19
+ * `name`+`description` (own-file targets emit them as frontmatter) and the body.
20
+ * No-op for cline (body verbatim) and codex (managed-section authors plain
21
+ * Markdown with no frontmatter).
22
+ */
23
+ wrap(name: string, description: string, body: string): string;
14
24
  }
25
+ /**
26
+ * How a skill contributes to the codex target's always-on `AGENTS.md` section.
27
+ *
28
+ * - 'full': inject the skill's trimmed codex body (a `*.codex.md` asset). Used by
29
+ * `testsprite-verify` (~6 KiB).
30
+ * - 'line': inject a single short line authored inline here. Used by
31
+ * `testsprite-onboard` — the full 6-step flow doesn't belong in an always-on,
32
+ * 32 KiB-budgeted file, but a one-line signal does.
33
+ * - 'none': skill is not represented in AGENTS.md at all (reserved).
34
+ */
35
+ export type CodexContribution = {
36
+ kind: 'full';
37
+ file: string;
38
+ } | {
39
+ kind: 'line';
40
+ text: string;
41
+ } | {
42
+ kind: 'none';
43
+ };
44
+ export interface SkillSpec {
45
+ /** Skill name — appears in own-file frontmatter and the landing path. */
46
+ name: string;
47
+ /** ≤1536 chars (claude description cap). Byte-identical to its template doc. */
48
+ description: string;
49
+ /** Own-file body asset basename under `skills/`, e.g. 'testsprite-verify.skill.md'. */
50
+ bodyFile: string;
51
+ /** How this skill contributes to the codex AGENTS.md managed section. */
52
+ codex: CodexContribution;
53
+ }
54
+ /**
55
+ * `testsprite-onboard` codex contribution — a single always-on line. Kept here
56
+ * (not in a `*.codex.md` asset) because it is one line; see {@link CodexContribution}.
57
+ */
58
+ export declare const ONBOARD_CODEX_LINE = "**First-time setup:** if this repo has no TestSprite tests yet, seed a *broad* first suite across its main user flows \u2014 not just one test \u2014 each with a concrete, observable assertion, before reporting setup as done.";
59
+ /**
60
+ * The skill registry. Each entry owns its name, description (drift-guarded by a
61
+ * byte-identity unit test against a template doc), own-file body asset, and codex
62
+ * contribution. `agent install` / `setup` install {@link DEFAULT_SKILLS}; the
63
+ * codex target aggregates every installed skill's codex contribution into ONE
64
+ * AGENTS.md section.
65
+ */
66
+ export declare const SKILLS: Record<string, SkillSpec>;
67
+ /**
68
+ * Skills installed by `setup` and by `agent install` when no `--skill` subset is
69
+ * given. Order is significant for the codex aggregate (verify first, then the
70
+ * onboard line as a short addendum).
71
+ */
72
+ export declare const DEFAULT_SKILLS: readonly ["testsprite-verify", "testsprite-onboard"];
73
+ /** @deprecated The canonical skill name. New code: iterate {@link SKILLS}. */
15
74
  export declare const SKILL_NAME = "testsprite-verify";
16
75
  /**
17
- * Mirrors skill-template.md frontmatter `description`. ≤1536 chars (claude cap).
18
- * A unit test asserts byte-identity with the template file.
76
+ * @deprecated The canonical skill's description. New code:
77
+ * `SKILLS['testsprite-verify'].description`. Kept so existing importers and the
78
+ * byte-identity unit test keep working.
79
+ */
80
+ export declare const SKILL_DESCRIPTION: string;
81
+ /**
82
+ * Repo-relative landing path for a given skill on a given target (POSIX
83
+ * separators). Own-file targets embed the skill name in the path so multiple
84
+ * skills coexist; the codex target always lands at the single shared `AGENTS.md`
85
+ * (every skill's codex contribution is merged into one managed section there).
19
86
  */
20
- export declare const SKILL_DESCRIPTION = "TestSprite verification loop \u2014 after finishing a feature or fix in a TestSprite-tested repo, use the `testsprite` CLI to run the relevant TestSprite tests against the change and inspect any failure artifacts before reporting the work as done. Use whenever code has changed outside docs/config and is about to be reported complete \u2014 by running an existing test that covers the change, or by creating a new TestSprite test (a frontend plan, or a backend Python assertion) and running it to a terminal verdict.";
87
+ export declare function pathFor(target: AgentTarget, skill: string): string;
21
88
  export declare const TARGETS: Record<AgentTarget, TargetSpec>;
22
89
  /** Sentinel pair that bounds our managed section in AGENTS.md. */
23
90
  export declare const MANAGED_SECTION_BEGIN = "<!-- BEGIN TESTSPRITE AGENT SECTION (testsprite agent install codex) -->";
24
91
  export declare const MANAGED_SECTION_END = "<!-- END TESTSPRITE AGENT SECTION -->";
25
92
  type ReadFn = (url: URL) => string;
93
+ /** Load a skill's own-file body by skill name (frontmatter is added by `wrap`). */
94
+ export declare function loadSkillBodyFor(skill: string, read?: ReadFn): string;
26
95
  /**
27
- * Load the canonical skill body. `../../skills/...` resolves to the repo-root
28
- * `skills/` directory in BOTH source (vitest: `src/lib/` → `../../skills`) and
29
- * the built/published package (`dist/lib/` → `../../skills` = package root). The
30
- * directory ships verbatim via package.json `files`, so no build-time copy step
31
- * is needed (unlike the old `src/assets` → `dist/assets` mirror).
32
- *
33
- * Injectable `read` fn keeps unit tests off disk.
96
+ * Resolve a skill's codex (AGENTS.md) contribution as a Markdown string.
97
+ * 'full' → read the `*.codex.md` asset; 'line' → the inline one-liner; 'none' → ''.
98
+ */
99
+ export declare function codexContentFor(skill: string, read?: ReadFn): string;
100
+ /**
101
+ * Compose the codex managed-section BODY (sans sentinels) from several skills:
102
+ * each skill's codex contribution, trimmed, joined by a blank line, in the given
103
+ * order. A single `['testsprite-verify']` aggregate is byte-identical to the old
104
+ * single-skill codex body, so existing AGENTS.md installs round-trip unchanged.
105
+ */
106
+ export declare function buildCodexAggregate(skills: readonly string[], read?: ReadFn): string;
107
+ /**
108
+ * Back-compat: the canonical verify skill body (own-file). Kept so existing
109
+ * importers and the `loadSkillBody(read)` unit-test signature keep working.
110
+ * @deprecated Use {@link loadSkillBodyFor}.
34
111
  */
35
112
  export declare function loadSkillBody(read?: ReadFn): string;
36
113
  /**
37
- * Load the trimmed codex skill body (plain Markdown, no frontmatter).
38
- * Designed for AGENTS.md managed-section injection.
114
+ * Back-compat: the canonical verify skill's trimmed codex body. Kept so existing
115
+ * importers and the `loadCodexSkillBody(read)` unit-test signature keep working.
116
+ * @deprecated Use {@link codexContentFor}.
39
117
  */
40
118
  export declare function loadCodexSkillBody(read?: ReadFn): string;
41
119
  /**
42
- * Convenience for piece-2: returns the exact bytes to write for a target.
120
+ * The exact bytes to write for one skill on one target.
43
121
  *
44
- * For own-file targets, `body` defaults to the full skill body.
45
- * For the codex managed-section target, the trimmed codex body is used instead —
46
- * pass an explicit `body` to override in tests.
122
+ * - own-file targets: `body` defaults to the skill's own-file asset, wrapped in
123
+ * the target's frontmatter/header.
124
+ * - codex (managed-section): returns the skill's codex contribution unwrapped
125
+ * (plain Markdown, no frontmatter). The real install does NOT call this for
126
+ * codex — it aggregates all skills via {@link buildCodexAggregate} — but it is
127
+ * kept single-skill here for tests and parity. Pass an explicit `body` to override.
47
128
  */
48
- export declare function renderForTarget(t: AgentTarget, body?: string): {
129
+ export declare function renderForTarget(t: AgentTarget, skill: string, body?: string): {
49
130
  path: string;
50
131
  content: string;
51
132
  };
@@ -1,40 +1,103 @@
1
1
  import { readFileSync } from 'node:fs';
2
+ /**
3
+ * `testsprite-onboard` codex contribution — a single always-on line. Kept here
4
+ * (not in a `*.codex.md` asset) because it is one line; see {@link CodexContribution}.
5
+ */
6
+ export const ONBOARD_CODEX_LINE = '**First-time setup:** if this repo has no TestSprite tests yet, seed a *broad* first suite across its main user flows — not just one test — each with a concrete, observable assertion, before reporting setup as done.';
7
+ /**
8
+ * The skill registry. Each entry owns its name, description (drift-guarded by a
9
+ * byte-identity unit test against a template doc), own-file body asset, and codex
10
+ * contribution. `agent install` / `setup` install {@link DEFAULT_SKILLS}; the
11
+ * codex target aggregates every installed skill's codex contribution into ONE
12
+ * AGENTS.md section.
13
+ */
14
+ export const SKILLS = {
15
+ 'testsprite-verify': {
16
+ name: 'testsprite-verify',
17
+ description: 'TestSprite verification loop — after finishing a feature or fix in a TestSprite-tested repo, use the `testsprite` CLI to run the relevant TestSprite tests against the change and inspect any failure artifacts before reporting the work as done. Use whenever code has changed outside docs/config and is about to be reported complete — by running an existing test that covers the change, or by creating a new TestSprite test (a frontend plan, or a backend Python assertion) and running it to a terminal verdict.',
18
+ bodyFile: 'testsprite-verify.skill.md',
19
+ codex: { kind: 'full', file: 'testsprite-verify.codex.md' },
20
+ },
21
+ 'testsprite-onboard': {
22
+ name: 'testsprite-onboard',
23
+ description: 'Stand up a complete, runnable TestSprite test suite for the current repo at first use — create a project (with a target URL and auth), derive a coherent set of tests from the codebase, batch-create them, and smoke-run a few to a green verdict so the user immediately has something worth running. Use ONLY when a repo has no TestSprite tests yet (a fresh project), right after `testsprite setup`, or when the user asks to "set up / bootstrap / seed tests". This is first-run setup, NOT change verification — once a project already has tests, use the testsprite-verify skill instead.',
24
+ bodyFile: 'testsprite-onboard.skill.md',
25
+ codex: { kind: 'line', text: ONBOARD_CODEX_LINE },
26
+ },
27
+ };
28
+ /**
29
+ * Skills installed by `setup` and by `agent install` when no `--skill` subset is
30
+ * given. Order is significant for the codex aggregate (verify first, then the
31
+ * onboard line as a short addendum).
32
+ */
33
+ export const DEFAULT_SKILLS = ['testsprite-verify', 'testsprite-onboard'];
34
+ // ---------------------------------------------------------------------------
35
+ // Back-compat single-skill exports (= the canonical `testsprite-verify` skill)
36
+ // ---------------------------------------------------------------------------
37
+ /** @deprecated The canonical skill name. New code: iterate {@link SKILLS}. */
2
38
  export const SKILL_NAME = 'testsprite-verify';
3
39
  /**
4
- * Mirrors skill-template.md frontmatter `description`. ≤1536 chars (claude cap).
5
- * A unit test asserts byte-identity with the template file.
40
+ * @deprecated The canonical skill's description. New code:
41
+ * `SKILLS['testsprite-verify'].description`. Kept so existing importers and the
42
+ * byte-identity unit test keep working.
6
43
  */
7
- export const SKILL_DESCRIPTION = 'TestSprite verification loop — after finishing a feature or fix in a TestSprite-tested repo, use the `testsprite` CLI to run the relevant TestSprite tests against the change and inspect any failure artifacts before reporting the work as done. Use whenever code has changed outside docs/config and is about to be reported complete — by running an existing test that covers the change, or by creating a new TestSprite test (a frontend plan, or a backend Python assertion) and running it to a terminal verdict.';
8
- function wrapSkill(body) {
9
- return `---\nname: ${SKILL_NAME}\ndescription: ${SKILL_DESCRIPTION}\n---\n\n${body}\n`;
44
+ export const SKILL_DESCRIPTION = SKILLS['testsprite-verify'].description;
45
+ // ---------------------------------------------------------------------------
46
+ // Wrappers
47
+ // ---------------------------------------------------------------------------
48
+ function wrapSkill(name, description, body) {
49
+ return `---\nname: ${name}\ndescription: ${description}\n---\n\n${body}\n`;
10
50
  }
11
- function wrapMdc(body) {
12
- return `---\ndescription: ${SKILL_DESCRIPTION}\nalwaysApply: false\n---\n\n${body}\n`;
51
+ function wrapMdc(_name, description, body) {
52
+ return `---\ndescription: ${description}\nalwaysApply: false\n---\n\n${body}\n`;
53
+ }
54
+ // ---------------------------------------------------------------------------
55
+ // Landing paths
56
+ // ---------------------------------------------------------------------------
57
+ /**
58
+ * Repo-relative landing path for a given skill on a given target (POSIX
59
+ * separators). Own-file targets embed the skill name in the path so multiple
60
+ * skills coexist; the codex target always lands at the single shared `AGENTS.md`
61
+ * (every skill's codex contribution is merged into one managed section there).
62
+ */
63
+ export function pathFor(target, skill) {
64
+ switch (target) {
65
+ case 'claude':
66
+ return `.claude/skills/${skill}/SKILL.md`;
67
+ case 'antigravity':
68
+ return `.agents/skills/${skill}/SKILL.md`;
69
+ case 'cursor':
70
+ return `.cursor/rules/${skill}.mdc`;
71
+ case 'cline':
72
+ return `.clinerules/${skill}.md`;
73
+ case 'codex':
74
+ return 'AGENTS.md';
75
+ }
13
76
  }
14
77
  export const TARGETS = {
15
78
  claude: {
16
79
  status: 'ga',
17
- path: '.claude/skills/testsprite-verify/SKILL.md',
80
+ path: pathFor('claude', SKILL_NAME),
18
81
  mode: 'own-file',
19
82
  wrap: wrapSkill,
20
83
  },
21
84
  antigravity: {
22
85
  status: 'experimental',
23
- path: '.agents/skills/testsprite-verify/SKILL.md',
86
+ path: pathFor('antigravity', SKILL_NAME),
24
87
  mode: 'own-file',
25
88
  wrap: wrapSkill,
26
89
  },
27
90
  cursor: {
28
91
  status: 'experimental',
29
- path: '.cursor/rules/testsprite-verify.mdc',
92
+ path: pathFor('cursor', SKILL_NAME),
30
93
  mode: 'own-file',
31
94
  wrap: wrapMdc,
32
95
  },
33
96
  cline: {
34
97
  status: 'experimental',
35
- path: '.clinerules/testsprite-verify.md',
98
+ path: pathFor('cline', SKILL_NAME),
36
99
  mode: 'own-file',
37
- wrap: body => body,
100
+ wrap: (_name, _description, body) => body,
38
101
  },
39
102
  /**
40
103
  * codex target — managed-section mode.
@@ -43,7 +106,9 @@ export const TARGETS = {
43
106
  * for the whole file). Unlike own-file targets, we must NOT clobber a user's
44
107
  * existing AGENTS.md: we write only a sentinel-delimited section so other
45
108
  * project instructions coexist. The sentinel pair is the canonical identity
46
- * marker; the content between them is ours to replace.
109
+ * marker; the content between them is ours to replace. EVERY installed skill's
110
+ * codex contribution is aggregated into this one section (see
111
+ * {@link buildCodexAggregate}).
47
112
  *
48
113
  * --force with managed-section: replaces the section unconditionally but
49
114
  * NEVER destroys content outside the sentinels. No whole-file .bak is written
@@ -52,50 +117,104 @@ export const TARGETS = {
52
117
  */
53
118
  codex: {
54
119
  status: 'experimental',
55
- path: 'AGENTS.md',
120
+ path: pathFor('codex', SKILL_NAME),
56
121
  mode: 'managed-section',
57
122
  // wrap is a no-op for managed-section — content is authored as plain Markdown
58
123
  // with no frontmatter (AGENTS.md is plain prose, not a skill schema).
59
- wrap: body => body,
124
+ wrap: (_name, _description, body) => body,
60
125
  },
61
126
  };
62
127
  /** Sentinel pair that bounds our managed section in AGENTS.md. */
63
128
  export const MANAGED_SECTION_BEGIN = '<!-- BEGIN TESTSPRITE AGENT SECTION (testsprite agent install codex) -->';
64
129
  export const MANAGED_SECTION_END = '<!-- END TESTSPRITE AGENT SECTION -->';
65
130
  const defaultRead = (url) => readFileSync(url, 'utf8');
131
+ // ---------------------------------------------------------------------------
132
+ // Asset loaders
133
+ // ---------------------------------------------------------------------------
66
134
  /**
67
- * Load the canonical skill body. `../../skills/...` resolves to the repo-root
135
+ * Resolve a `skills/<file>` asset. `../../skills/...` resolves to the repo-root
68
136
  * `skills/` directory in BOTH source (vitest: `src/lib/` → `../../skills`) and
69
137
  * the built/published package (`dist/lib/` → `../../skills` = package root). The
70
138
  * directory ships verbatim via package.json `files`, so no build-time copy step
71
- * is needed (unlike the old `src/assets` → `dist/assets` mirror).
72
- *
73
- * Injectable `read` fn keeps unit tests off disk.
139
+ * is needed. Injectable `read` keeps unit tests off disk.
140
+ */
141
+ function readSkillAsset(file, read) {
142
+ return read(new URL(`../../skills/${file}`, import.meta.url));
143
+ }
144
+ /** Load a skill's own-file body by skill name (frontmatter is added by `wrap`). */
145
+ export function loadSkillBodyFor(skill, read = defaultRead) {
146
+ const spec = SKILLS[skill];
147
+ if (!spec)
148
+ throw new Error(`unknown skill: ${skill}`);
149
+ return readSkillAsset(spec.bodyFile, read);
150
+ }
151
+ /**
152
+ * Resolve a skill's codex (AGENTS.md) contribution as a Markdown string.
153
+ * 'full' → read the `*.codex.md` asset; 'line' → the inline one-liner; 'none' → ''.
154
+ */
155
+ export function codexContentFor(skill, read = defaultRead) {
156
+ const spec = SKILLS[skill];
157
+ if (!spec)
158
+ throw new Error(`unknown skill: ${skill}`);
159
+ const c = spec.codex;
160
+ if (c.kind === 'full')
161
+ return readSkillAsset(c.file, read);
162
+ if (c.kind === 'line')
163
+ return c.text;
164
+ return '';
165
+ }
166
+ /**
167
+ * Compose the codex managed-section BODY (sans sentinels) from several skills:
168
+ * each skill's codex contribution, trimmed, joined by a blank line, in the given
169
+ * order. A single `['testsprite-verify']` aggregate is byte-identical to the old
170
+ * single-skill codex body, so existing AGENTS.md installs round-trip unchanged.
171
+ */
172
+ export function buildCodexAggregate(skills, read = defaultRead) {
173
+ return skills
174
+ .map(s => codexContentFor(s, read).trimEnd())
175
+ .filter(Boolean)
176
+ .join('\n\n');
177
+ }
178
+ /**
179
+ * Back-compat: the canonical verify skill body (own-file). Kept so existing
180
+ * importers and the `loadSkillBody(read)` unit-test signature keep working.
181
+ * @deprecated Use {@link loadSkillBodyFor}.
74
182
  */
75
183
  export function loadSkillBody(read = defaultRead) {
76
- return read(new URL('../../skills/testsprite-verify.skill.md', import.meta.url));
184
+ return loadSkillBodyFor(SKILL_NAME, read);
77
185
  }
78
186
  /**
79
- * Load the trimmed codex skill body (plain Markdown, no frontmatter).
80
- * Designed for AGENTS.md managed-section injection.
187
+ * Back-compat: the canonical verify skill's trimmed codex body. Kept so existing
188
+ * importers and the `loadCodexSkillBody(read)` unit-test signature keep working.
189
+ * @deprecated Use {@link codexContentFor}.
81
190
  */
82
191
  export function loadCodexSkillBody(read = defaultRead) {
83
- return read(new URL('../../skills/testsprite-verify.codex.md', import.meta.url));
192
+ return codexContentFor(SKILL_NAME, read);
84
193
  }
194
+ // ---------------------------------------------------------------------------
195
+ // renderForTarget
196
+ // ---------------------------------------------------------------------------
85
197
  /**
86
- * Convenience for piece-2: returns the exact bytes to write for a target.
198
+ * The exact bytes to write for one skill on one target.
87
199
  *
88
- * For own-file targets, `body` defaults to the full skill body.
89
- * For the codex managed-section target, the trimmed codex body is used instead —
90
- * pass an explicit `body` to override in tests.
200
+ * - own-file targets: `body` defaults to the skill's own-file asset, wrapped in
201
+ * the target's frontmatter/header.
202
+ * - codex (managed-section): returns the skill's codex contribution unwrapped
203
+ * (plain Markdown, no frontmatter). The real install does NOT call this for
204
+ * codex — it aggregates all skills via {@link buildCodexAggregate} — but it is
205
+ * kept single-skill here for tests and parity. Pass an explicit `body` to override.
91
206
  */
92
- export function renderForTarget(t, body) {
207
+ export function renderForTarget(t, skill, body) {
93
208
  const spec = TARGETS[t];
94
- const resolvedBody = body !== undefined
95
- ? body
96
- : spec.mode === 'managed-section'
97
- ? loadCodexSkillBody()
98
- : loadSkillBody();
99
- return { path: spec.path, content: spec.wrap(resolvedBody) };
209
+ const skillSpec = SKILLS[skill];
210
+ if (!skillSpec)
211
+ throw new Error(`unknown skill: ${skill}`);
212
+ const path = pathFor(t, skill);
213
+ if (spec.mode === 'managed-section') {
214
+ const resolvedBody = body !== undefined ? body : codexContentFor(skill);
215
+ return { path, content: spec.wrap(skillSpec.name, skillSpec.description, resolvedBody) };
216
+ }
217
+ const resolvedBody = body !== undefined ? body : loadSkillBodyFor(skill);
218
+ return { path, content: spec.wrap(skillSpec.name, skillSpec.description, resolvedBody) };
100
219
  }
101
220
  //# sourceMappingURL=agent-targets.js.map
@@ -36,6 +36,10 @@ import type { CliFailureContext } from '../commands/test.js';
36
36
  import type { FetchImpl } from './http.js';
37
37
  /** Schema version stamped into `meta.json`. Bumps with the contract. */
38
38
  export declare const BUNDLE_SCHEMA_VERSION: "cli-v1";
39
+ /** Max fetch attempts for each presigned URL (initial + retries). */
40
+ export declare const STREAM_URL_MAX_RETRIES = 3;
41
+ /** Delay between retries for transient transport failures (ms). */
42
+ export declare const STREAM_URL_RETRY_DELAY_MS = 1000;
39
43
  /** Default radius around the failed step when `--failed-only` is set. */
40
44
  export declare const FAILED_ONLY_RADIUS = 1;
41
45
  /**
@@ -141,6 +145,12 @@ export declare function pickCodeExtension(language: string, framework: string):
141
145
  * naturally without breaking existing fixtures.
142
146
  */
143
147
  export declare function stepFilenamePrefix(stepIndex: number): string;
148
+ /**
149
+ * Refuse a composed artifact path that escapes `baseDir`. Step filenames are
150
+ * built from response-controlled fields, so this is the final containment
151
+ * check before any write. Returns the validated absolute path.
152
+ */
153
+ export declare function assertNoEscape(baseDir: string, segment: string): string;
144
154
  /**
145
155
  * Build the §7.1 meta.json given a context. Pure function, no I/O —
146
156
  * lets specs assert the meta shape without touching disk.
@@ -174,5 +184,11 @@ export declare function writeBundle(ctx: CliFailureContext, options: WriteBundle
174
184
  * the upstream reader rather than buffering chunks in V8 heap. This
175
185
  * matters for video files (multi-MB) and for very large HTML
176
186
  * snapshots.
187
+ *
188
+ * Transport failures (network reset, DNS blip, mid-stream EOF) are
189
+ * retried up to STREAM_URL_MAX_RETRIES times with a fixed delay.
190
+ * Presigned URLs are valid for 15 minutes, so retries are safe.
177
191
  */
178
- export declare function streamUrlToFile(url: string, filePath: string, fetchImpl: FetchImpl): Promise<void>;
192
+ export declare function streamUrlToFile(url: string, filePath: string, fetchImpl: FetchImpl, deps?: {
193
+ sleep?: (ms: number) => Promise<void>;
194
+ }): Promise<void>;