@testsprite/testsprite-cli 0.1.2 → 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.
- package/README.md +34 -26
- package/dist/commands/agent.d.ts +52 -0
- package/dist/commands/agent.js +341 -93
- package/dist/commands/auth.js +29 -27
- package/dist/commands/doctor.d.ts +49 -0
- package/dist/commands/doctor.js +211 -0
- package/dist/commands/init.d.ts +7 -1
- package/dist/commands/init.js +66 -26
- package/dist/commands/project.d.ts +50 -1
- package/dist/commands/project.js +257 -43
- package/dist/commands/test.d.ts +214 -12
- package/dist/commands/test.js +1310 -174
- package/dist/commands/usage.js +13 -12
- package/dist/index.js +71 -18
- package/dist/lib/agent-targets.d.ts +169 -22
- package/dist/lib/agent-targets.js +335 -34
- package/dist/lib/bundle.d.ts +51 -1
- package/dist/lib/bundle.js +146 -55
- package/dist/lib/client-factory.d.ts +43 -0
- package/dist/lib/client-factory.js +89 -2
- package/dist/lib/config.d.ts +2 -0
- package/dist/lib/config.js +11 -2
- package/dist/lib/credentials.d.ts +7 -0
- package/dist/lib/credentials.js +40 -1
- package/dist/lib/dry-run/samples.d.ts +5 -0
- package/dist/lib/dry-run/samples.js +54 -9
- package/dist/lib/flaky.d.ts +80 -0
- package/dist/lib/flaky.js +76 -0
- package/dist/lib/http.d.ts +20 -0
- package/dist/lib/http.js +216 -132
- package/dist/lib/interrupt.d.ts +61 -0
- package/dist/lib/interrupt.js +97 -0
- package/dist/lib/junit-report.d.ts +58 -0
- package/dist/lib/junit-report.js +210 -0
- package/dist/lib/output.d.ts +16 -1
- package/dist/lib/output.js +24 -2
- package/dist/lib/pagination.d.ts +4 -3
- package/dist/lib/pagination.js +34 -6
- package/dist/lib/prompt.js +52 -8
- package/dist/lib/proxy.d.ts +29 -0
- package/dist/lib/proxy.js +30 -0
- package/dist/lib/render-error.d.ts +13 -0
- package/dist/lib/render-error.js +30 -7
- package/dist/lib/skill-nudge.d.ts +2 -2
- package/dist/lib/skill-nudge.js +13 -4
- package/dist/lib/target-url.js +8 -1
- package/dist/lib/ticker.d.ts +11 -1
- package/dist/lib/ticker.js +33 -1
- package/dist/lib/update-check.d.ts +67 -0
- package/dist/lib/update-check.js +246 -0
- package/dist/version-guard.d.ts +33 -0
- package/dist/version-guard.js +39 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -2
- package/skills/testsprite-onboard.skill.md +183 -0
- package/skills/testsprite-verify.codex.md +2 -0
- package/skills/testsprite-verify.skill.md +52 -1
|
@@ -1,40 +1,163 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { VERSION } from '../version.js';
|
|
4
|
+
/**
|
|
5
|
+
* `testsprite-onboard` codex contribution — a single always-on line. Kept here
|
|
6
|
+
* (not in a `*.codex.md` asset) because it is one line; see {@link CodexContribution}.
|
|
7
|
+
*/
|
|
8
|
+
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.';
|
|
9
|
+
/**
|
|
10
|
+
* The skill registry. Each entry owns its name, description (drift-guarded by a
|
|
11
|
+
* byte-identity unit test against a template doc), own-file body asset, and codex
|
|
12
|
+
* contribution. `agent install` / `setup` install {@link DEFAULT_SKILLS}; the
|
|
13
|
+
* codex target aggregates every installed skill's codex contribution into ONE
|
|
14
|
+
* AGENTS.md section.
|
|
15
|
+
*/
|
|
16
|
+
export const SKILLS = {
|
|
17
|
+
'testsprite-verify': {
|
|
18
|
+
name: 'testsprite-verify',
|
|
19
|
+
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.',
|
|
20
|
+
bodyFile: 'testsprite-verify.skill.md',
|
|
21
|
+
codex: { kind: 'full', file: 'testsprite-verify.codex.md' },
|
|
22
|
+
},
|
|
23
|
+
'testsprite-onboard': {
|
|
24
|
+
name: 'testsprite-onboard',
|
|
25
|
+
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.',
|
|
26
|
+
bodyFile: 'testsprite-onboard.skill.md',
|
|
27
|
+
codex: { kind: 'line', text: ONBOARD_CODEX_LINE },
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Skills installed by `setup` and by `agent install` when no `--skill` subset is
|
|
32
|
+
* given. Order is significant for the codex aggregate (verify first, then the
|
|
33
|
+
* onboard line as a short addendum).
|
|
34
|
+
*/
|
|
35
|
+
export const DEFAULT_SKILLS = ['testsprite-verify', 'testsprite-onboard'];
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
// Back-compat single-skill exports (= the canonical `testsprite-verify` skill)
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
/** @deprecated The canonical skill name. New code: iterate {@link SKILLS}. */
|
|
2
40
|
export const SKILL_NAME = 'testsprite-verify';
|
|
3
41
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
42
|
+
* @deprecated The canonical skill's description. New code:
|
|
43
|
+
* `SKILLS['testsprite-verify'].description`. Kept so existing importers and the
|
|
44
|
+
* byte-identity unit test keep working.
|
|
45
|
+
*/
|
|
46
|
+
export const SKILL_DESCRIPTION = SKILLS['testsprite-verify'].description;
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// Wrappers
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
function wrapSkill(name, description, body) {
|
|
51
|
+
return `---\nname: ${name}\ndescription: ${description}\n---\n\n${body}\n`;
|
|
52
|
+
}
|
|
53
|
+
function wrapMdc(_name, description, body) {
|
|
54
|
+
return `---\ndescription: ${description}\nalwaysApply: false\n---\n\n${body}\n`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Windsurf (Cascade) reads workspace rules from `.windsurf/rules/*.md` with YAML
|
|
58
|
+
* frontmatter. `trigger: model_decision` is the Cascade equivalent of the Cursor
|
|
59
|
+
* `.mdc` `alwaysApply: false` mode: only the `description` is surfaced up front,
|
|
60
|
+
* and Cascade pulls in the full rule body when the description shows it is
|
|
61
|
+
* relevant — exactly the on-demand activation these skills want. (The other
|
|
62
|
+
* triggers are `always_on`, `manual`, and `glob`.)
|
|
63
|
+
*/
|
|
64
|
+
function wrapWindsurf(_name, description, body) {
|
|
65
|
+
return `---\ntrigger: model_decision\ndescription: ${description}\n---\n\n${body}\n`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* GitHub Copilot reads path-specific custom instructions from
|
|
69
|
+
* `.github/instructions/*.instructions.md` (VS Code / Visual Studio / GitHub
|
|
70
|
+
* Copilot Chat). Each file carries YAML frontmatter with `applyTo` — a glob that
|
|
71
|
+
* scopes when the instructions attach. `applyTo: '**'` attaches the guidance to
|
|
72
|
+
* every request in the repo, which is what a persistent verification skill wants
|
|
73
|
+
* (there is no on-demand "model decides" mode for Copilot instruction files, so
|
|
74
|
+
* always-apply is the correct idiom). `description` is surfaced in Copilot's UI.
|
|
6
75
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return `---\nname: ${SKILL_NAME}\ndescription: ${SKILL_DESCRIPTION}\n---\n\n${body}\n`;
|
|
76
|
+
function wrapCopilot(_name, description, body) {
|
|
77
|
+
return `---\ndescription: ${description}\napplyTo: '**'\n---\n\n${body}\n`;
|
|
10
78
|
}
|
|
11
|
-
|
|
12
|
-
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// Landing paths
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
/**
|
|
83
|
+
* Repo-relative landing path for a given skill on a given target (POSIX
|
|
84
|
+
* separators). Own-file targets embed the skill name in the path so multiple
|
|
85
|
+
* skills coexist; the codex target always lands at the single shared `AGENTS.md`
|
|
86
|
+
* (every skill's codex contribution is merged into one managed section there).
|
|
87
|
+
*/
|
|
88
|
+
export function pathFor(target, skill) {
|
|
89
|
+
switch (target) {
|
|
90
|
+
case 'claude':
|
|
91
|
+
return `.claude/skills/${skill}/SKILL.md`;
|
|
92
|
+
case 'antigravity':
|
|
93
|
+
return `.agents/skills/${skill}/SKILL.md`;
|
|
94
|
+
case 'cursor':
|
|
95
|
+
return `.cursor/rules/${skill}.mdc`;
|
|
96
|
+
case 'cline':
|
|
97
|
+
return `.clinerules/${skill}.md`;
|
|
98
|
+
case 'kiro':
|
|
99
|
+
return `.kiro/skills/${skill}/SKILL.md`;
|
|
100
|
+
case 'windsurf':
|
|
101
|
+
return `.windsurf/rules/${skill}.md`;
|
|
102
|
+
case 'copilot':
|
|
103
|
+
return `.github/instructions/${skill}.instructions.md`;
|
|
104
|
+
case 'codex':
|
|
105
|
+
return 'AGENTS.md';
|
|
106
|
+
}
|
|
13
107
|
}
|
|
14
108
|
export const TARGETS = {
|
|
15
109
|
claude: {
|
|
16
110
|
status: 'ga',
|
|
17
|
-
path: '
|
|
111
|
+
path: pathFor('claude', SKILL_NAME),
|
|
18
112
|
mode: 'own-file',
|
|
19
113
|
wrap: wrapSkill,
|
|
20
114
|
},
|
|
21
115
|
antigravity: {
|
|
22
116
|
status: 'experimental',
|
|
23
|
-
path: '
|
|
117
|
+
path: pathFor('antigravity', SKILL_NAME),
|
|
24
118
|
mode: 'own-file',
|
|
25
119
|
wrap: wrapSkill,
|
|
26
120
|
},
|
|
27
121
|
cursor: {
|
|
28
122
|
status: 'experimental',
|
|
29
|
-
path: '
|
|
123
|
+
path: pathFor('cursor', SKILL_NAME),
|
|
30
124
|
mode: 'own-file',
|
|
31
125
|
wrap: wrapMdc,
|
|
32
126
|
},
|
|
33
127
|
cline: {
|
|
34
128
|
status: 'experimental',
|
|
35
|
-
path: '
|
|
129
|
+
path: pathFor('cline', SKILL_NAME),
|
|
130
|
+
mode: 'own-file',
|
|
131
|
+
wrap: (_name, _description, body) => body,
|
|
132
|
+
},
|
|
133
|
+
kiro: {
|
|
134
|
+
status: 'experimental',
|
|
135
|
+
path: pathFor('kiro', SKILL_NAME),
|
|
136
|
+
mode: 'own-file',
|
|
137
|
+
// kiro reads SKILL.md files with name/description frontmatter, same as
|
|
138
|
+
// claude/antigravity, so it shares the wrapSkill wrapper.
|
|
139
|
+
wrap: wrapSkill,
|
|
140
|
+
},
|
|
141
|
+
windsurf: {
|
|
142
|
+
status: 'experimental',
|
|
143
|
+
path: pathFor('windsurf', SKILL_NAME),
|
|
144
|
+
mode: 'own-file',
|
|
145
|
+
// Windsurf rules files are budget-capped (~12 K chars per `.windsurf/rules/*.md`),
|
|
146
|
+
// so render the compact body per skill (see compactBodyFor).
|
|
147
|
+
compactBody: true,
|
|
148
|
+
wrap: wrapWindsurf,
|
|
149
|
+
},
|
|
150
|
+
copilot: {
|
|
151
|
+
status: 'experimental',
|
|
152
|
+
path: pathFor('copilot', SKILL_NAME),
|
|
36
153
|
mode: 'own-file',
|
|
37
|
-
|
|
154
|
+
// GitHub Copilot path-specific instructions: frontmatter carries `applyTo`.
|
|
155
|
+
// `applyTo: '**'` means the file is ALWAYS injected into Copilot requests
|
|
156
|
+
// (there is no on-demand "model decides" mode like Cursor/Windsurf), so
|
|
157
|
+
// render the compact body to keep the always-on context cost small — the
|
|
158
|
+
// same reasoning that drives windsurf's compact render.
|
|
159
|
+
compactBody: true,
|
|
160
|
+
wrap: wrapCopilot,
|
|
38
161
|
},
|
|
39
162
|
/**
|
|
40
163
|
* codex target — managed-section mode.
|
|
@@ -43,7 +166,9 @@ export const TARGETS = {
|
|
|
43
166
|
* for the whole file). Unlike own-file targets, we must NOT clobber a user's
|
|
44
167
|
* existing AGENTS.md: we write only a sentinel-delimited section so other
|
|
45
168
|
* project instructions coexist. The sentinel pair is the canonical identity
|
|
46
|
-
* marker; the content between them is ours to replace.
|
|
169
|
+
* marker; the content between them is ours to replace. EVERY installed skill's
|
|
170
|
+
* codex contribution is aggregated into this one section (see
|
|
171
|
+
* {@link buildCodexAggregate}).
|
|
47
172
|
*
|
|
48
173
|
* --force with managed-section: replaces the section unconditionally but
|
|
49
174
|
* NEVER destroys content outside the sentinels. No whole-file .bak is written
|
|
@@ -52,50 +177,226 @@ export const TARGETS = {
|
|
|
52
177
|
*/
|
|
53
178
|
codex: {
|
|
54
179
|
status: 'experimental',
|
|
55
|
-
path: '
|
|
180
|
+
path: pathFor('codex', SKILL_NAME),
|
|
56
181
|
mode: 'managed-section',
|
|
57
182
|
// wrap is a no-op for managed-section — content is authored as plain Markdown
|
|
58
183
|
// with no frontmatter (AGENTS.md is plain prose, not a skill schema).
|
|
59
|
-
wrap: body => body,
|
|
184
|
+
wrap: (_name, _description, body) => body,
|
|
60
185
|
},
|
|
61
186
|
};
|
|
62
187
|
/** Sentinel pair that bounds our managed section in AGENTS.md. */
|
|
63
188
|
export const MANAGED_SECTION_BEGIN = '<!-- BEGIN TESTSPRITE AGENT SECTION (testsprite agent install codex) -->';
|
|
64
189
|
export const MANAGED_SECTION_END = '<!-- END TESTSPRITE AGENT SECTION -->';
|
|
190
|
+
// ---------------------------------------------------------------------------
|
|
191
|
+
// Install marker (stale-skill detection, issue #123)
|
|
192
|
+
// ---------------------------------------------------------------------------
|
|
193
|
+
/**
|
|
194
|
+
* Hex characters of the canonical body's SHA-256 kept in the install marker.
|
|
195
|
+
* 12 hex chars (48 bits) is ample for drift DETECTION (equality against bodies
|
|
196
|
+
* this CLI ships); the marker is provenance metadata, not a security boundary.
|
|
197
|
+
*/
|
|
198
|
+
const MARKER_HASH_HEX_LENGTH = 12;
|
|
199
|
+
/**
|
|
200
|
+
* When one marker covers several skills (the codex managed section aggregates
|
|
201
|
+
* every installed skill), their names are joined with this separator in the
|
|
202
|
+
* marker's skill field. Skill names never contain '+' (see {@link SKILLS} keys).
|
|
203
|
+
*/
|
|
204
|
+
export const MARKER_SKILL_SEPARATOR = '+';
|
|
205
|
+
/**
|
|
206
|
+
* Marker line shape: `<!-- testsprite-skill: <name> v<version> sha256:<hash> -->`.
|
|
207
|
+
* An HTML comment is inert in every target format (SKILL.md, .mdc, .clinerules
|
|
208
|
+
* markdown, AGENTS.md). Built via `new RegExp` so the hash length stays bound
|
|
209
|
+
* to {@link MARKER_HASH_HEX_LENGTH}.
|
|
210
|
+
*/
|
|
211
|
+
const SKILL_MARKER_LINE_RE = new RegExp(`^<!-- testsprite-skill: (\\S+) v(\\S+) sha256:([0-9a-f]{${MARKER_HASH_HEX_LENGTH}}) -->$`);
|
|
212
|
+
/**
|
|
213
|
+
* First {@link MARKER_HASH_HEX_LENGTH} hex chars of the SHA-256 of a canonical
|
|
214
|
+
* skill body. The hash covers the CANONICAL BODY ONLY (pre-wrap, pre-marker),
|
|
215
|
+
* so writing the marker into the rendered artifact never changes the hash the
|
|
216
|
+
* marker itself carries.
|
|
217
|
+
*/
|
|
218
|
+
export function bodyHash12(canonicalBody) {
|
|
219
|
+
return createHash('sha256')
|
|
220
|
+
.update(canonicalBody, 'utf8')
|
|
221
|
+
.digest('hex')
|
|
222
|
+
.slice(0, MARKER_HASH_HEX_LENGTH);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Build the provenance marker line for a skill (or a
|
|
226
|
+
* {@link MARKER_SKILL_SEPARATOR}-joined skill set) and its canonical body.
|
|
227
|
+
* `agent status` compares this fingerprint against the bodies the running CLI
|
|
228
|
+
* ships to detect silently stale installs.
|
|
229
|
+
*/
|
|
230
|
+
export function buildSkillMarker(skillName, canonicalBody) {
|
|
231
|
+
return `<!-- testsprite-skill: ${skillName} v${VERSION} sha256:${bodyHash12(canonicalBody)} -->`;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Find the first testsprite-skill marker line in `content`, or null when the
|
|
235
|
+
* content carries none (a pre-marker install). Lines are matched whole with
|
|
236
|
+
* trailing CR/whitespace stripped, so CRLF checkouts parse identically.
|
|
237
|
+
*/
|
|
238
|
+
export function parseSkillMarker(content) {
|
|
239
|
+
for (const rawLine of content.split('\n')) {
|
|
240
|
+
const line = rawLine.trimEnd();
|
|
241
|
+
const matched = SKILL_MARKER_LINE_RE.exec(line);
|
|
242
|
+
if (matched) {
|
|
243
|
+
return { skill: matched[1], version: matched[2], hash12: matched[3], line };
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
65
248
|
const defaultRead = (url) => readFileSync(url, 'utf8');
|
|
249
|
+
// ---------------------------------------------------------------------------
|
|
250
|
+
// Asset loaders
|
|
251
|
+
// ---------------------------------------------------------------------------
|
|
66
252
|
/**
|
|
67
|
-
*
|
|
253
|
+
* Resolve a `skills/<file>` asset. `../../skills/...` resolves to the repo-root
|
|
68
254
|
* `skills/` directory in BOTH source (vitest: `src/lib/` → `../../skills`) and
|
|
69
255
|
* the built/published package (`dist/lib/` → `../../skills` = package root). The
|
|
70
256
|
* directory ships verbatim via package.json `files`, so no build-time copy step
|
|
71
|
-
* is needed
|
|
72
|
-
|
|
73
|
-
|
|
257
|
+
* is needed. Injectable `read` keeps unit tests off disk.
|
|
258
|
+
*/
|
|
259
|
+
function readSkillAsset(file, read) {
|
|
260
|
+
return read(new URL(`../../skills/${file}`, import.meta.url));
|
|
261
|
+
}
|
|
262
|
+
/** Load a skill's own-file body by skill name (frontmatter is added by `wrap`). */
|
|
263
|
+
export function loadSkillBodyFor(skill, read = defaultRead) {
|
|
264
|
+
const spec = SKILLS[skill];
|
|
265
|
+
if (!spec)
|
|
266
|
+
throw new Error(`unknown skill: ${skill}`);
|
|
267
|
+
return readSkillAsset(spec.bodyFile, read);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Budget-friendly body for an own-file target whose rule files are size-capped
|
|
271
|
+
* (e.g. windsurf). For a skill that ships a trimmed codex asset (`codex.kind ===
|
|
272
|
+
* 'full'`, e.g. `testsprite-verify` — full body ~22 KB, codex ~5 KB) we render
|
|
273
|
+
* that compact asset so the wrapped file stays under the cap. For skills whose
|
|
274
|
+
* codex contribution is only a one-liner (`'line'`/`'none'`, e.g.
|
|
275
|
+
* `testsprite-onboard`), the one-liner is useless as a standalone rule and the
|
|
276
|
+
* full own-file body (~6.5 KB) already fits the budget — so the full body is
|
|
277
|
+
* used.
|
|
278
|
+
*/
|
|
279
|
+
export function compactBodyFor(skill, read = defaultRead) {
|
|
280
|
+
const spec = SKILLS[skill];
|
|
281
|
+
if (!spec)
|
|
282
|
+
throw new Error(`unknown skill: ${skill}`);
|
|
283
|
+
return spec.codex.kind === 'full'
|
|
284
|
+
? readSkillAsset(spec.codex.file, read)
|
|
285
|
+
: loadSkillBodyFor(skill, read);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Resolve a skill's codex (AGENTS.md) contribution as a Markdown string.
|
|
289
|
+
* 'full' → read the `*.codex.md` asset; 'line' → the inline one-liner; 'none' → ''.
|
|
290
|
+
*/
|
|
291
|
+
export function codexContentFor(skill, read = defaultRead) {
|
|
292
|
+
const spec = SKILLS[skill];
|
|
293
|
+
if (!spec)
|
|
294
|
+
throw new Error(`unknown skill: ${skill}`);
|
|
295
|
+
const c = spec.codex;
|
|
296
|
+
if (c.kind === 'full')
|
|
297
|
+
return readSkillAsset(c.file, read);
|
|
298
|
+
if (c.kind === 'line')
|
|
299
|
+
return c.text;
|
|
300
|
+
return '';
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Compose the codex managed-section BODY (sans sentinels) from several skills:
|
|
304
|
+
* each skill's codex contribution, trimmed, joined by a blank line, in the given
|
|
305
|
+
* order. A single `['testsprite-verify']` aggregate is byte-identical to the old
|
|
306
|
+
* single-skill codex body, so existing AGENTS.md installs round-trip unchanged.
|
|
307
|
+
*/
|
|
308
|
+
export function buildCodexAggregate(skills, read = defaultRead) {
|
|
309
|
+
return skills
|
|
310
|
+
.map(s => codexContentFor(s, read).trimEnd())
|
|
311
|
+
.filter(Boolean)
|
|
312
|
+
.join('\n\n');
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Back-compat: the canonical verify skill body (own-file). Kept so existing
|
|
316
|
+
* importers and the `loadSkillBody(read)` unit-test signature keep working.
|
|
317
|
+
* @deprecated Use {@link loadSkillBodyFor}.
|
|
74
318
|
*/
|
|
75
319
|
export function loadSkillBody(read = defaultRead) {
|
|
76
|
-
return
|
|
320
|
+
return loadSkillBodyFor(SKILL_NAME, read);
|
|
77
321
|
}
|
|
78
322
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
323
|
+
* Back-compat: the canonical verify skill's trimmed codex body. Kept so existing
|
|
324
|
+
* importers and the `loadCodexSkillBody(read)` unit-test signature keep working.
|
|
325
|
+
* @deprecated Use {@link codexContentFor}.
|
|
81
326
|
*/
|
|
82
327
|
export function loadCodexSkillBody(read = defaultRead) {
|
|
83
|
-
return
|
|
328
|
+
return codexContentFor(SKILL_NAME, read);
|
|
329
|
+
}
|
|
330
|
+
// ---------------------------------------------------------------------------
|
|
331
|
+
// renderForTarget
|
|
332
|
+
// ---------------------------------------------------------------------------
|
|
333
|
+
/**
|
|
334
|
+
* Place the marker line inside a wrapped own-file render.
|
|
335
|
+
*
|
|
336
|
+
* - Wraps that emit YAML frontmatter (claude/antigravity/cursor): the marker
|
|
337
|
+
* lands on the line right after the closing `---` fence, before the body.
|
|
338
|
+
* - Wrapless targets (cline, body verbatim): the marker is appended as the
|
|
339
|
+
* LAST line instead. Cline surfaces the file's first heading as the rule
|
|
340
|
+
* title, so a leading comment would displace the body's H1.
|
|
341
|
+
*/
|
|
342
|
+
function injectMarkerLine(wrapped, markerLine) {
|
|
343
|
+
if (wrapped.startsWith('---\n')) {
|
|
344
|
+
// The name/description frontmatter values are single-line, so the first
|
|
345
|
+
// `\n---\n` after the opening fence is always the closing fence.
|
|
346
|
+
const closingFence = '\n---\n';
|
|
347
|
+
const fenceIdx = wrapped.indexOf(closingFence);
|
|
348
|
+
if (fenceIdx !== -1) {
|
|
349
|
+
const insertAt = fenceIdx + closingFence.length;
|
|
350
|
+
return `${wrapped.slice(0, insertAt)}${markerLine}\n${wrapped.slice(insertAt)}`;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
const separator = wrapped.endsWith('\n') ? '' : '\n';
|
|
354
|
+
return `${wrapped}${separator}${markerLine}\n`;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Exact own-file bytes for a skill on a target, carrying the GIVEN marker line.
|
|
358
|
+
* `agent status` uses this to re-render the current canonical body with a
|
|
359
|
+
* file's own (possibly older-versioned) marker: when only the marker's version
|
|
360
|
+
* string lags but the body is unchanged, the artifact still compares pristine.
|
|
361
|
+
*/
|
|
362
|
+
export function renderOwnFileWithMarker(target, skill, markerLine, body) {
|
|
363
|
+
const spec = TARGETS[target];
|
|
364
|
+
if (spec.mode !== 'own-file') {
|
|
365
|
+
throw new Error(`renderOwnFileWithMarker: ${target} is not an own-file target`);
|
|
366
|
+
}
|
|
367
|
+
const skillSpec = SKILLS[skill];
|
|
368
|
+
if (!skillSpec)
|
|
369
|
+
throw new Error(`unknown skill: ${skill}`);
|
|
370
|
+
const resolvedBody = body !== undefined ? body : loadSkillBodyFor(skill);
|
|
371
|
+
return injectMarkerLine(spec.wrap(skillSpec.name, skillSpec.description, resolvedBody), markerLine);
|
|
84
372
|
}
|
|
85
373
|
/**
|
|
86
|
-
*
|
|
374
|
+
* The exact bytes to write for one skill on one target.
|
|
87
375
|
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
376
|
+
* - own-file targets: `body` defaults to the skill's own-file asset, wrapped in
|
|
377
|
+
* the target's frontmatter/header, and carrying a provenance marker line so
|
|
378
|
+
* `agent status` can tell fresh, stale, and hand-edited installs apart.
|
|
379
|
+
* - codex (managed-section): returns the skill's codex contribution unwrapped
|
|
380
|
+
* and marker-free (plain Markdown, no frontmatter). The real install does NOT
|
|
381
|
+
* call this for codex: it aggregates all skills via
|
|
382
|
+
* {@link buildCodexAggregate} and writes ONE marker just inside the BEGIN
|
|
383
|
+
* sentinel. It is kept single-skill here for tests and parity. Pass an
|
|
384
|
+
* explicit `body` to override.
|
|
91
385
|
*/
|
|
92
|
-
export function renderForTarget(t, body) {
|
|
386
|
+
export function renderForTarget(t, skill, body) {
|
|
93
387
|
const spec = TARGETS[t];
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
388
|
+
const skillSpec = SKILLS[skill];
|
|
389
|
+
if (!skillSpec)
|
|
390
|
+
throw new Error(`unknown skill: ${skill}`);
|
|
391
|
+
const path = pathFor(t, skill);
|
|
392
|
+
if (spec.mode === 'managed-section') {
|
|
393
|
+
const resolvedBody = body !== undefined ? body : codexContentFor(skill);
|
|
394
|
+
return { path, content: spec.wrap(skillSpec.name, skillSpec.description, resolvedBody) };
|
|
395
|
+
}
|
|
396
|
+
const resolvedBody = body !== undefined ? body : spec.compactBody ? compactBodyFor(skill) : loadSkillBodyFor(skill);
|
|
397
|
+
return {
|
|
398
|
+
path,
|
|
399
|
+
content: renderOwnFileWithMarker(t, skill, buildSkillMarker(skill, resolvedBody), resolvedBody),
|
|
400
|
+
};
|
|
100
401
|
}
|
|
101
402
|
//# sourceMappingURL=agent-targets.js.map
|
package/dist/lib/bundle.d.ts
CHANGED
|
@@ -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.
|
|
@@ -164,6 +174,40 @@ export declare function buildMeta(ctx: CliFailureContext, fetchedAt?: Date): Bun
|
|
|
164
174
|
* → 10 by default; the original ApiError is preserved when applicable).
|
|
165
175
|
*/
|
|
166
176
|
export declare function writeBundle(ctx: CliFailureContext, options: WriteBundleOptions): Promise<WriteBundleResult>;
|
|
177
|
+
/**
|
|
178
|
+
* Rename `<tmp>/<file>` → `<dir>/<file>` for every file in `files`.
|
|
179
|
+
*
|
|
180
|
+
* Critical ordering for atomicity (the §3 "agent-safe" contract):
|
|
181
|
+
*
|
|
182
|
+
* 1. **Remove the OLD `meta.json` first.** The bundle's completion
|
|
183
|
+
* signal is `meta.json`'s presence; an agent reading `<dir>` while
|
|
184
|
+
* we're mutating it must see "no meta → bundle absent or
|
|
185
|
+
* mid-write" rather than "meta points at a snapshot that's already
|
|
186
|
+
* been partially overwritten." Removing the old meta is what
|
|
187
|
+
* makes the rest of the swap safe to do in place.
|
|
188
|
+
* 2. Wipe stale top-level files (e.g. an old `video.mp4` when the new
|
|
189
|
+
* bundle has no video). Without this, a fresh bundle could ship
|
|
190
|
+
* with a stale video lingering at the top level.
|
|
191
|
+
* 3. Replace `<dir>/steps/` wholesale.
|
|
192
|
+
* 4. Rename top-level files into place.
|
|
193
|
+
* 5. **Rename `meta.json` LAST.** Its visible presence is the atomic
|
|
194
|
+
* completion signal; until step 5 lands, agents see "incomplete."
|
|
195
|
+
*
|
|
196
|
+
* The window between (1) and (5) is bounded by a handful of `rename`
|
|
197
|
+
* syscalls — small enough that a SIGKILL there is rare, and any agent
|
|
198
|
+
* caught reading the dir during it sees no meta and refuses to consume
|
|
199
|
+
* (per §7.3). That's what we want.
|
|
200
|
+
*/
|
|
201
|
+
/**
|
|
202
|
+
* Whether a top-level directory entry belongs to the bundle format —
|
|
203
|
+
* i.e. something a prior `writeBundle` could have produced and this
|
|
204
|
+
* commit is therefore allowed to clean up. `code.<ext>` is matched by
|
|
205
|
+
* pattern (not the current run's extension) so a stale `code.py` is
|
|
206
|
+
* still swept when the new bundle writes `code.ts`. Everything else in
|
|
207
|
+
* the directory is the user's and must never be deleted (`--out` can
|
|
208
|
+
* point at a pre-existing, populated directory).
|
|
209
|
+
*/
|
|
210
|
+
export declare function isBundleOwnedEntry(entry: string): boolean;
|
|
167
211
|
/**
|
|
168
212
|
* Stream a presigned URL into a file with bounded retry on transport
|
|
169
213
|
* failures. 4xx (presigned URL expired or unauthorized) is NOT
|
|
@@ -174,5 +218,11 @@ export declare function writeBundle(ctx: CliFailureContext, options: WriteBundle
|
|
|
174
218
|
* the upstream reader rather than buffering chunks in V8 heap. This
|
|
175
219
|
* matters for video files (multi-MB) and for very large HTML
|
|
176
220
|
* snapshots.
|
|
221
|
+
*
|
|
222
|
+
* Transport failures (network reset, DNS blip, mid-stream EOF) are
|
|
223
|
+
* retried up to STREAM_URL_MAX_RETRIES times with a fixed delay.
|
|
224
|
+
* Presigned URLs are valid for 15 minutes, so retries are safe.
|
|
177
225
|
*/
|
|
178
|
-
export declare function streamUrlToFile(url: string, filePath: string, fetchImpl: FetchImpl
|
|
226
|
+
export declare function streamUrlToFile(url: string, filePath: string, fetchImpl: FetchImpl, deps?: {
|
|
227
|
+
sleep?: (ms: number) => Promise<void>;
|
|
228
|
+
}): Promise<void>;
|