@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
package/dist/commands/agent.js
CHANGED
|
@@ -2,9 +2,9 @@ import path from 'node:path';
|
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import { CLIError, localValidationError } from '../lib/errors.js';
|
|
5
|
-
import { GLOBAL_OPTS_HINT, Output } from '../lib/output.js';
|
|
5
|
+
import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
6
6
|
import { promptText } from '../lib/prompt.js';
|
|
7
|
-
import { TARGETS,
|
|
7
|
+
import { TARGETS, SKILLS, DEFAULT_SKILLS, MARKER_SKILL_SEPARATOR, pathFor, loadSkillBodyFor, bodyHash12, compactBodyFor, buildCodexAggregate, buildSkillMarker, parseSkillMarker, renderForTarget, renderOwnFileWithMarker, MANAGED_SECTION_BEGIN, MANAGED_SECTION_END, } from '../lib/agent-targets.js';
|
|
8
8
|
// ---------------------------------------------------------------------------
|
|
9
9
|
// Constants
|
|
10
10
|
// ---------------------------------------------------------------------------
|
|
@@ -105,11 +105,15 @@ async function writeBackup(agentFs, abs, existing) {
|
|
|
105
105
|
// Managed-section helpers (codex target)
|
|
106
106
|
// ---------------------------------------------------------------------------
|
|
107
107
|
/**
|
|
108
|
-
* Build the section block to inject (sentinels + body + trailing
|
|
108
|
+
* Build the section block to inject (sentinels + marker + body + trailing
|
|
109
|
+
* newline). The provenance marker line sits just inside the BEGIN sentinel so
|
|
110
|
+
* `agent status` can fingerprint the section. The same skill set + CLI version
|
|
111
|
+
* + body always produce byte-identical output, so the classifySection
|
|
112
|
+
* 'unchanged' fast-path keeps working across re-installs.
|
|
109
113
|
* Uses \n throughout; the caller handles CRLF normalisation.
|
|
110
114
|
*/
|
|
111
|
-
function buildSection(body) {
|
|
112
|
-
return `${MANAGED_SECTION_BEGIN}\n${body.trimEnd()}\n${MANAGED_SECTION_END}\n`;
|
|
115
|
+
function buildSection(body, markerLine) {
|
|
116
|
+
return `${MANAGED_SECTION_BEGIN}\n${markerLine}\n${body.trimEnd()}\n${MANAGED_SECTION_END}\n`;
|
|
113
117
|
}
|
|
114
118
|
/**
|
|
115
119
|
* Inspect an existing AGENTS.md and classify the managed-section state.
|
|
@@ -224,15 +228,18 @@ export async function runInstall(opts, deps = {}) {
|
|
|
224
228
|
if (rawTargets.length === 0) {
|
|
225
229
|
const isTTY = deps.isTTY ?? Boolean(process.stdin.isTTY);
|
|
226
230
|
if (!isTTY) {
|
|
227
|
-
|
|
231
|
+
stderrFn('[info] --target not specified; defaulting to claude. Pass --target=<target> to select a different agent.');
|
|
232
|
+
resolvedTargetStrings = ['claude'];
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
const promptFn = deps.prompt ?? ((q) => promptText(q));
|
|
236
|
+
const answer = (await promptFn('Targets to install (comma-separated) [claude]: ')).trim();
|
|
237
|
+
const defaulted = answer || 'claude';
|
|
238
|
+
resolvedTargetStrings = defaulted
|
|
239
|
+
.split(',')
|
|
240
|
+
.map(s => s.trim())
|
|
241
|
+
.filter(Boolean);
|
|
228
242
|
}
|
|
229
|
-
const promptFn = deps.prompt ?? ((q) => promptText(q));
|
|
230
|
-
const answer = (await promptFn('Targets to install (comma-separated) [claude]: ')).trim();
|
|
231
|
-
const defaulted = answer || 'claude';
|
|
232
|
-
resolvedTargetStrings = defaulted
|
|
233
|
-
.split(',')
|
|
234
|
-
.map(s => s.trim())
|
|
235
|
-
.filter(Boolean);
|
|
236
243
|
}
|
|
237
244
|
else {
|
|
238
245
|
resolvedTargetStrings = rawTargets;
|
|
@@ -252,31 +259,82 @@ export async function runInstall(opts, deps = {}) {
|
|
|
252
259
|
seen.add(t);
|
|
253
260
|
return true;
|
|
254
261
|
});
|
|
262
|
+
// 2b. Resolve + validate the skill set (empty/absent → DEFAULT_SKILLS).
|
|
263
|
+
// Accepts comma-separated or repeated --skill values, same shape as --target.
|
|
264
|
+
const rawSkills = (opts.skills ?? [])
|
|
265
|
+
.flatMap(s => s.split(','))
|
|
266
|
+
.map(s => s.trim())
|
|
267
|
+
.filter(Boolean);
|
|
268
|
+
const validSkills = Object.keys(SKILLS);
|
|
269
|
+
for (const s of rawSkills) {
|
|
270
|
+
if (!validSkills.includes(s)) {
|
|
271
|
+
throw localValidationError('skill', `unknown skill "${s}"; supported: ${validSkills.join(', ')}`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const seenSkill = new Set();
|
|
275
|
+
const skills = (rawSkills.length > 0 ? rawSkills : [...DEFAULT_SKILLS]).filter(s => {
|
|
276
|
+
if (seenSkill.has(s))
|
|
277
|
+
return false;
|
|
278
|
+
seenSkill.add(s);
|
|
279
|
+
return true;
|
|
280
|
+
});
|
|
255
281
|
// 3. Resolve dir
|
|
256
282
|
const dir = opts.dir ?? deps.cwd ?? process.cwd();
|
|
257
283
|
const root = path.resolve(dir);
|
|
258
|
-
// 4.
|
|
259
|
-
|
|
260
|
-
|
|
284
|
+
// 4. Lazy asset loaders — only touch disk if a target actually needs it.
|
|
285
|
+
// own-file bodies are per-skill (cached); the codex section aggregates EVERY
|
|
286
|
+
// installed skill's contribution into ONE managed section.
|
|
287
|
+
const skillBodyCache = new Map();
|
|
288
|
+
const bodyForSkill = (skill) => {
|
|
289
|
+
let b = skillBodyCache.get(skill);
|
|
290
|
+
if (b === undefined) {
|
|
291
|
+
b = loadSkillBodyFor(skill);
|
|
292
|
+
skillBodyCache.set(skill, b);
|
|
293
|
+
}
|
|
294
|
+
return b;
|
|
295
|
+
};
|
|
296
|
+
// Budget-capped own-file targets (e.g. windsurf) render the compact per-skill
|
|
297
|
+
// body so the rule file isn't truncated by the agent. Cached separately; must
|
|
298
|
+
// match renderForTarget's default selection so written bytes equal the asserted
|
|
299
|
+
// render.
|
|
300
|
+
const compactBodyCache = new Map();
|
|
301
|
+
const compactBodyForSkill = (skill) => {
|
|
302
|
+
let b = compactBodyCache.get(skill);
|
|
303
|
+
if (b === undefined) {
|
|
304
|
+
b = compactBodyFor(skill);
|
|
305
|
+
compactBodyCache.set(skill, b);
|
|
306
|
+
}
|
|
307
|
+
return b;
|
|
308
|
+
};
|
|
309
|
+
const ownFileBodyFor = (t, skill) => TARGETS[t].compactBody ? compactBodyForSkill(skill) : bodyForSkill(skill);
|
|
310
|
+
let codexSectionCache;
|
|
311
|
+
const getCodexSection = () => {
|
|
312
|
+
if (codexSectionCache === undefined) {
|
|
313
|
+
const aggregate = buildCodexAggregate(skills);
|
|
314
|
+
// ONE marker for the whole managed section: it names every aggregated
|
|
315
|
+
// skill ('+'-joined) and hashes the canonical aggregate body, so
|
|
316
|
+
// `agent status` can attribute and fingerprint the section per skill.
|
|
317
|
+
codexSectionCache = buildSection(aggregate, buildSkillMarker(skills.join(MARKER_SKILL_SEPARATOR), aggregate));
|
|
318
|
+
}
|
|
319
|
+
return codexSectionCache;
|
|
320
|
+
};
|
|
261
321
|
const results = [];
|
|
262
322
|
// Track bytes for dry-run output
|
|
263
323
|
const dryRunLines = [];
|
|
264
324
|
// 5. Process each target
|
|
265
325
|
for (const t of targets) {
|
|
266
326
|
const spec = TARGETS[t];
|
|
267
|
-
const relPath = spec.path;
|
|
268
|
-
const abs = path.resolve(root, relPath);
|
|
269
|
-
// Path safety: ensure abs is inside root (defense against .. in relPath or dir)
|
|
270
|
-
if (abs !== root && !abs.startsWith(root + path.sep)) {
|
|
271
|
-
throw new CLIError(`refusing to write outside --dir: ${relPath}`, 5);
|
|
272
|
-
}
|
|
273
327
|
// -----------------------------------------------------------------------
|
|
274
|
-
// managed-section mode (codex target)
|
|
328
|
+
// managed-section mode (codex target) — ONE section aggregating all skills
|
|
275
329
|
// -----------------------------------------------------------------------
|
|
276
330
|
if (spec.mode === 'managed-section') {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
331
|
+
const relPath = spec.path; // 'AGENTS.md' — skill-independent (all skills merge here)
|
|
332
|
+
const abs = path.resolve(root, relPath);
|
|
333
|
+
// Path safety: ensure abs is inside root (defense against .. in relPath or dir)
|
|
334
|
+
if (abs !== root && !abs.startsWith(root + path.sep)) {
|
|
335
|
+
throw new CLIError(`refusing to write outside --dir: ${relPath}`, 5);
|
|
336
|
+
}
|
|
337
|
+
const section = getCodexSection();
|
|
280
338
|
if (opts.dryRun) {
|
|
281
339
|
// Dry-run: report what would happen without writing disk.
|
|
282
340
|
//
|
|
@@ -334,7 +392,7 @@ export async function runInstall(opts, deps = {}) {
|
|
|
334
392
|
stderrFn(`[warn] ${relPath} will be ${wouldBeBytes} bytes after this write — Codex may not load content beyond its 32 KiB (${AGENTS_MD_CODEX_BUDGET_BYTES} byte) budget. Trim AGENTS.md to stay within the limit.`);
|
|
335
393
|
}
|
|
336
394
|
dryRunLines.push({ abs, bytes, note: 'managed section' });
|
|
337
|
-
results.push({ target: t, path: relPath, action: 'dry-run' });
|
|
395
|
+
results.push({ target: t, path: relPath, action: 'dry-run', skills: [...skills] });
|
|
338
396
|
continue;
|
|
339
397
|
}
|
|
340
398
|
// Inspect the target path via lstat walk (symlink-safe, same as own-file).
|
|
@@ -366,7 +424,12 @@ export async function runInstall(opts, deps = {}) {
|
|
|
366
424
|
}
|
|
367
425
|
throw err;
|
|
368
426
|
}
|
|
369
|
-
results.push({
|
|
427
|
+
results.push({
|
|
428
|
+
target: t,
|
|
429
|
+
path: relPath,
|
|
430
|
+
action: 'section-installed',
|
|
431
|
+
skills: [...skills],
|
|
432
|
+
});
|
|
370
433
|
}
|
|
371
434
|
else {
|
|
372
435
|
const existing = await agentFs.readFile(abs);
|
|
@@ -377,13 +440,23 @@ export async function runInstall(opts, deps = {}) {
|
|
|
377
440
|
`Manually remove the partial sentinel block and re-run.`, 5);
|
|
378
441
|
}
|
|
379
442
|
if (state.kind === 'unchanged') {
|
|
380
|
-
results.push({
|
|
443
|
+
results.push({
|
|
444
|
+
target: t,
|
|
445
|
+
path: relPath,
|
|
446
|
+
action: 'section-unchanged',
|
|
447
|
+
skills: [...skills],
|
|
448
|
+
});
|
|
381
449
|
}
|
|
382
450
|
else if (state.kind === 'create') {
|
|
383
451
|
// Shouldn't happen (st !== null means file exists), but guard anyway.
|
|
384
452
|
warnIfOverBudget(section);
|
|
385
453
|
await agentFs.writeFile(abs, section);
|
|
386
|
-
results.push({
|
|
454
|
+
results.push({
|
|
455
|
+
target: t,
|
|
456
|
+
path: relPath,
|
|
457
|
+
action: 'section-installed',
|
|
458
|
+
skills: [...skills],
|
|
459
|
+
});
|
|
387
460
|
}
|
|
388
461
|
else {
|
|
389
462
|
// 'append' or 'replace' — write the new content.
|
|
@@ -394,69 +467,83 @@ export async function runInstall(opts, deps = {}) {
|
|
|
394
467
|
warnIfOverBudget(newContent);
|
|
395
468
|
await agentFs.writeFile(abs, newContent);
|
|
396
469
|
const action = state.kind === 'append' ? 'section-installed' : 'section-updated';
|
|
397
|
-
results.push({ target: t, path: relPath, action });
|
|
470
|
+
results.push({ target: t, path: relPath, action, skills: [...skills] });
|
|
398
471
|
}
|
|
399
472
|
}
|
|
400
473
|
continue;
|
|
401
474
|
}
|
|
402
475
|
// -----------------------------------------------------------------------
|
|
403
|
-
// own-file mode (all other targets)
|
|
476
|
+
// own-file mode (all other targets) — one file per skill
|
|
404
477
|
// -----------------------------------------------------------------------
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
results.push({ target: t, path: relPath, action: 'dry-run' });
|
|
412
|
-
continue;
|
|
413
|
-
}
|
|
414
|
-
// Inspect the target path: refuse to traverse or write through a symlink
|
|
415
|
-
// (fs writes follow symlinks, which would let a planted symlink escape
|
|
416
|
-
// --dir), and reject a non-regular-file landing path. The lexical guard
|
|
417
|
-
// above is necessary but not sufficient — it cannot see symlinks.
|
|
418
|
-
const st = await inspectTargetPath(agentFs, root, relPath);
|
|
419
|
-
if (st !== null && !st.isFile) {
|
|
420
|
-
throw new CLIError(`${relPath} exists but is not a regular file — remove it and re-run.`, 5);
|
|
421
|
-
}
|
|
422
|
-
if (st === null) {
|
|
423
|
-
// Path does not exist — create it. inspectTargetPath verified every
|
|
424
|
-
// existing ancestor is a real directory; exclusive create (wx) then
|
|
425
|
-
// ensures a file or symlink that races in after the check is not followed
|
|
426
|
-
// or silently overwritten.
|
|
427
|
-
await agentFs.mkdir(path.dirname(abs));
|
|
428
|
-
try {
|
|
429
|
-
await agentFs.writeFile(abs, content, { exclusive: true });
|
|
478
|
+
for (const skill of skills) {
|
|
479
|
+
const relPath = pathFor(t, skill);
|
|
480
|
+
const abs = path.resolve(root, relPath);
|
|
481
|
+
// Path safety: ensure abs is inside root (defense against .. in relPath or dir)
|
|
482
|
+
if (abs !== root && !abs.startsWith(root + path.sep)) {
|
|
483
|
+
throw new CLIError(`refusing to write outside --dir: ${relPath}`, 5);
|
|
430
484
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
485
|
+
const content = renderForTarget(t, skill, ownFileBodyFor(t, skill)).content;
|
|
486
|
+
if (opts.dryRun) {
|
|
487
|
+
// Apply the SAME symlink fail-close guard as the real install path
|
|
488
|
+
// below (the codex managed-section branch already does this). Without
|
|
489
|
+
// it, dry-run reports success for a planted symlink that the real
|
|
490
|
+
// install would refuse with exit 5.
|
|
491
|
+
const dryRunSt = await inspectTargetPath(agentFs, root, relPath);
|
|
492
|
+
if (dryRunSt !== null && !dryRunSt.isFile) {
|
|
493
|
+
throw new CLIError(`${relPath} exists but is not a regular file — remove it and re-run.`, 5);
|
|
434
494
|
}
|
|
435
|
-
|
|
495
|
+
const bytes = Buffer.byteLength(content, 'utf8');
|
|
496
|
+
dryRunLines.push({ abs, bytes, note: '' });
|
|
497
|
+
results.push({ target: t, path: relPath, action: 'dry-run', skills: [skill] });
|
|
498
|
+
continue;
|
|
436
499
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
500
|
+
// Inspect the target path: refuse to traverse or write through a symlink
|
|
501
|
+
// (fs writes follow symlinks, which would let a planted symlink escape
|
|
502
|
+
// --dir), and reject a non-regular-file landing path. The lexical guard
|
|
503
|
+
// above is necessary but not sufficient — it cannot see symlinks.
|
|
504
|
+
const st = await inspectTargetPath(agentFs, root, relPath);
|
|
505
|
+
if (st !== null && !st.isFile) {
|
|
506
|
+
throw new CLIError(`${relPath} exists but is not a regular file — remove it and re-run.`, 5);
|
|
444
507
|
}
|
|
445
|
-
|
|
446
|
-
//
|
|
447
|
-
|
|
508
|
+
if (st === null) {
|
|
509
|
+
// Path does not exist — create it. inspectTargetPath verified every
|
|
510
|
+
// existing ancestor is a real directory; exclusive create (wx) then
|
|
511
|
+
// ensures a file or symlink that races in after the check is not followed
|
|
512
|
+
// or silently overwritten.
|
|
513
|
+
await agentFs.mkdir(path.dirname(abs));
|
|
514
|
+
try {
|
|
515
|
+
await agentFs.writeFile(abs, content, { exclusive: true });
|
|
516
|
+
}
|
|
517
|
+
catch (err) {
|
|
518
|
+
if (err instanceof Error && err.code === 'EEXIST') {
|
|
519
|
+
throw new CLIError(`${relPath} appeared after the path check — re-run, or pass --force to overwrite.`, 6);
|
|
520
|
+
}
|
|
521
|
+
throw err;
|
|
522
|
+
}
|
|
523
|
+
results.push({ target: t, path: relPath, action: 'written', skills: [skill] });
|
|
448
524
|
}
|
|
449
525
|
else {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
526
|
+
const existing = await agentFs.readFile(abs);
|
|
527
|
+
if (existing === content) {
|
|
528
|
+
// Byte-identical — skip
|
|
529
|
+
results.push({ target: t, path: relPath, action: 'skipped', skills: [skill] });
|
|
530
|
+
}
|
|
531
|
+
else if (!opts.force) {
|
|
532
|
+
// Differs and no --force → blocked
|
|
533
|
+
results.push({ target: t, path: relPath, action: 'blocked', skills: [skill] });
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
// Differs and --force → back up the current bytes to a fresh slot
|
|
537
|
+
// (never clobbering an existing backup or following a symlink), then
|
|
538
|
+
// overwrite. The overwrite itself can follow a symlink swapped in after
|
|
539
|
+
// the check — an accepted TOCTOU residual for a local, single-user CLI.
|
|
540
|
+
const backupPath = await writeBackup(agentFs, abs, existing);
|
|
541
|
+
await agentFs.writeFile(abs, content);
|
|
542
|
+
if (opts.output === 'text') {
|
|
543
|
+
stderrFn(`backed up ${relPath} to ${path.relative(root, backupPath)}`);
|
|
544
|
+
}
|
|
545
|
+
results.push({ target: t, path: relPath, action: 'updated', skills: [skill] });
|
|
458
546
|
}
|
|
459
|
-
results.push({ target: t, path: relPath, action: 'updated' });
|
|
460
547
|
}
|
|
461
548
|
}
|
|
462
549
|
}
|
|
@@ -486,18 +573,169 @@ export async function runInstall(opts, deps = {}) {
|
|
|
486
573
|
}
|
|
487
574
|
export async function runList(opts, deps = {}) {
|
|
488
575
|
const out = makeOutput(opts.output, deps);
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
576
|
+
// One row per (target × default skill). Own-file targets land each skill at a
|
|
577
|
+
// distinct path; the codex managed-section target merges all skills into the
|
|
578
|
+
// single AGENTS.md (so every codex row shares that path — truthful, since both
|
|
579
|
+
// skills' content lands there).
|
|
580
|
+
const results = [];
|
|
581
|
+
for (const [t, spec] of Object.entries(TARGETS)) {
|
|
582
|
+
for (const skill of DEFAULT_SKILLS) {
|
|
583
|
+
results.push({
|
|
584
|
+
target: t,
|
|
585
|
+
skill,
|
|
586
|
+
status: spec.status,
|
|
587
|
+
mode: spec.mode,
|
|
588
|
+
path: pathFor(t, skill),
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
out.print(results, data => {
|
|
593
|
+
const items = data;
|
|
594
|
+
const header = `${'TARGET'.padEnd(14)} ${'SKILL'.padEnd(20)} ${'STATUS'.padEnd(12)} ${'MODE'.padEnd(18)} PATH`;
|
|
595
|
+
const rows = items.map(r => `${r.target.padEnd(14)} ${r.skill.padEnd(20)} ${r.status.padEnd(12)} ${r.mode.padEnd(18)} ${r.path}`);
|
|
596
|
+
return [header, ...rows].join('\n');
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Classify one own-file artifact per the {@link SkillArtifactState} contract.
|
|
601
|
+
* Comparisons are byte-exact, matching the installer's own skipped/blocked
|
|
602
|
+
* comparison for own-file targets.
|
|
603
|
+
*/
|
|
604
|
+
async function classifyOwnFileState(agentFs, abs, target, skill, bodyForSkill) {
|
|
605
|
+
const stat = await agentFs.lstat(abs);
|
|
606
|
+
if (stat === null)
|
|
607
|
+
return 'absent';
|
|
608
|
+
// Occupied by a directory or symlink: not something our installer wrote, and
|
|
609
|
+
// never followed (mirrors the installer's fail-closed stance on symlinks).
|
|
610
|
+
if (!stat.isFile)
|
|
611
|
+
return 'unmarked';
|
|
612
|
+
const existing = await agentFs.readFile(abs);
|
|
613
|
+
const marker = parseSkillMarker(existing);
|
|
614
|
+
if (marker === null)
|
|
615
|
+
return 'unmarked';
|
|
616
|
+
const canonicalBody = bodyForSkill(skill);
|
|
617
|
+
if (marker.hash12 !== bodyHash12(canonicalBody))
|
|
618
|
+
return 'stale';
|
|
619
|
+
// Hash matches the current body: pristine iff the file equals the canonical
|
|
620
|
+
// render carrying its own marker line, so a marker whose version string lags
|
|
621
|
+
// behind an unchanged body still reads ok.
|
|
622
|
+
const reRender = renderOwnFileWithMarker(target, skill, marker.line, canonicalBody);
|
|
623
|
+
return existing === reRender ? 'ok' : 'modified';
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Classify the codex managed section per skill. The section is ONE artifact
|
|
627
|
+
* carrying ONE marker that names every aggregated skill, so a single
|
|
628
|
+
* inspection answers all skill rows; the returned function maps a skill name
|
|
629
|
+
* to its state. Comparisons are CRLF-insensitive on the section bytes.
|
|
630
|
+
*/
|
|
631
|
+
async function classifyManagedSectionStates(agentFs, abs) {
|
|
632
|
+
const constantState = (state) => () => state;
|
|
633
|
+
const stat = await agentFs.lstat(abs);
|
|
634
|
+
if (stat === null)
|
|
635
|
+
return constantState('absent');
|
|
636
|
+
// Occupied by a directory or symlink: never followed (fail-closed).
|
|
637
|
+
if (!stat.isFile)
|
|
638
|
+
return constantState('unmarked');
|
|
639
|
+
const existing = await agentFs.readFile(abs);
|
|
640
|
+
// Current canonical section for the default skill set. classifySection's
|
|
641
|
+
// 'unchanged' answers the common all-defaults-fresh case; its
|
|
642
|
+
// corrupt/append classification is reused verbatim for status verdicts.
|
|
643
|
+
const defaultAggregate = buildCodexAggregate(DEFAULT_SKILLS);
|
|
644
|
+
const defaultSection = buildSection(defaultAggregate, buildSkillMarker(DEFAULT_SKILLS.join(MARKER_SKILL_SEPARATOR), defaultAggregate));
|
|
645
|
+
const sectionState = classifySection(existing, defaultSection);
|
|
646
|
+
if (sectionState.kind === 'corrupt')
|
|
647
|
+
return constantState('corrupt');
|
|
648
|
+
// No standalone sentinels anywhere: the managed section is not installed.
|
|
649
|
+
if (sectionState.kind === 'append')
|
|
650
|
+
return constantState('absent');
|
|
651
|
+
if (sectionState.kind === 'unchanged') {
|
|
652
|
+
// Byte-identical to today's default install.
|
|
653
|
+
return skill => (DEFAULT_SKILLS.includes(skill) ? 'ok' : 'absent');
|
|
654
|
+
}
|
|
655
|
+
if (sectionState.kind !== 'replace') {
|
|
656
|
+
// 'create' is unreachable when the file exists; treat defensively as absent.
|
|
657
|
+
return constantState('absent');
|
|
658
|
+
}
|
|
659
|
+
// Sentinels are present but the section differs from today's default
|
|
660
|
+
// canonical: slice the live section bytes out of the file and inspect its
|
|
661
|
+
// own marker (before/after are exact byte prefix/suffix around the section).
|
|
662
|
+
const sectionContent = existing.slice(sectionState.before.length, existing.length - sectionState.after.length);
|
|
663
|
+
const marker = parseSkillMarker(sectionContent);
|
|
664
|
+
if (marker === null)
|
|
665
|
+
return constantState('unmarked');
|
|
666
|
+
const installedSkills = marker.skill.split(MARKER_SKILL_SEPARATOR);
|
|
667
|
+
const coversSkill = (skill) => installedSkills.includes(skill);
|
|
668
|
+
// A marker naming a skill this CLI does not ship cannot be re-rendered;
|
|
669
|
+
// report the named skills stale (a re-install refreshes the section).
|
|
670
|
+
if (installedSkills.some(name => SKILLS[name] === undefined)) {
|
|
671
|
+
return skill => (coversSkill(skill) ? 'stale' : 'absent');
|
|
672
|
+
}
|
|
673
|
+
const canonicalAggregate = buildCodexAggregate(installedSkills);
|
|
674
|
+
if (marker.hash12 !== bodyHash12(canonicalAggregate)) {
|
|
675
|
+
return skill => (coversSkill(skill) ? 'stale' : 'absent');
|
|
676
|
+
}
|
|
677
|
+
// Hash matches the current aggregate: the section is pristine iff its bytes
|
|
678
|
+
// equal a re-render carrying its own marker line (version-string-only lag
|
|
679
|
+
// with an unchanged body still reads ok).
|
|
680
|
+
const pristine = sectionContent.replace(/\r\n/g, '\n') === buildSection(canonicalAggregate, marker.line);
|
|
681
|
+
return skill => (coversSkill(skill) ? (pristine ? 'ok' : 'modified') : 'absent');
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* `agent status`: one row per (target × default skill), each classified per
|
|
685
|
+
* the {@link SkillArtifactState} contract. Exit contract: returns normally
|
|
686
|
+
* (exit 0) when every row is 'ok' or 'absent'; throws CLIError exit 1 when any
|
|
687
|
+
* row is stale/modified/unmarked/corrupt, so the command can gate CI.
|
|
688
|
+
*/
|
|
689
|
+
export async function runStatus(opts, deps = {}) {
|
|
690
|
+
const agentFs = deps.fs ?? defaultAgentFs;
|
|
691
|
+
const out = makeOutput(opts.output, deps);
|
|
692
|
+
// An explicit but empty --dir must not silently resolve to cwd
|
|
693
|
+
// (path.resolve('') === cwd).
|
|
694
|
+
if (opts.dir !== undefined && opts.dir.trim() === '') {
|
|
695
|
+
throw localValidationError('dir', 'must not be empty');
|
|
696
|
+
}
|
|
697
|
+
const dir = opts.dir !== undefined ? opts.dir.trim() : (deps.cwd ?? process.cwd());
|
|
698
|
+
const root = path.resolve(dir);
|
|
699
|
+
// Canonical own-file bodies, read once per skill (same lazy caching pattern
|
|
700
|
+
// as runInstall's bodyForSkill).
|
|
701
|
+
const skillBodyCache = new Map();
|
|
702
|
+
const bodyForSkill = (skill) => {
|
|
703
|
+
let cachedBody = skillBodyCache.get(skill);
|
|
704
|
+
if (cachedBody === undefined) {
|
|
705
|
+
cachedBody = loadSkillBodyFor(skill);
|
|
706
|
+
skillBodyCache.set(skill, cachedBody);
|
|
707
|
+
}
|
|
708
|
+
return cachedBody;
|
|
709
|
+
};
|
|
710
|
+
const results = [];
|
|
711
|
+
for (const [target, spec] of Object.entries(TARGETS)) {
|
|
712
|
+
if (spec.mode === 'managed-section') {
|
|
713
|
+
const stateFor = await classifyManagedSectionStates(agentFs, path.resolve(root, spec.path));
|
|
714
|
+
for (const skill of DEFAULT_SKILLS) {
|
|
715
|
+
results.push({ target, skill, path: spec.path, state: stateFor(skill) });
|
|
716
|
+
}
|
|
717
|
+
continue;
|
|
718
|
+
}
|
|
719
|
+
for (const skill of DEFAULT_SKILLS) {
|
|
720
|
+
const relPath = pathFor(target, skill);
|
|
721
|
+
results.push({
|
|
722
|
+
target,
|
|
723
|
+
skill,
|
|
724
|
+
path: relPath,
|
|
725
|
+
state: await classifyOwnFileState(agentFs, path.resolve(root, relPath), target, skill, bodyForSkill),
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
}
|
|
495
729
|
out.print(results, data => {
|
|
496
730
|
const items = data;
|
|
497
|
-
const header = `${'TARGET'.padEnd(14)} ${'
|
|
498
|
-
const rows = items.map(
|
|
731
|
+
const header = `${'TARGET'.padEnd(14)} ${'SKILL'.padEnd(20)} ${'STATE'.padEnd(10)} PATH`;
|
|
732
|
+
const rows = items.map(row => `${row.target.padEnd(14)} ${row.skill.padEnd(20)} ${row.state.padEnd(10)} ${row.path}`);
|
|
499
733
|
return [header, ...rows].join('\n');
|
|
500
734
|
});
|
|
735
|
+
const needingAttention = results.filter(result => result.state !== 'ok' && result.state !== 'absent');
|
|
736
|
+
if (needingAttention.length > 0) {
|
|
737
|
+
throw new CLIError(`${needingAttention.length} skill artifact(s) need attention (stale/modified/unmarked/corrupt); re-run \`testsprite agent install\` (add --force for own-file targets) to refresh them.`, 1);
|
|
738
|
+
}
|
|
501
739
|
}
|
|
502
740
|
// ---------------------------------------------------------------------------
|
|
503
741
|
// Command factory
|
|
@@ -506,11 +744,12 @@ function collect(v, prev) {
|
|
|
506
744
|
return prev.concat(v);
|
|
507
745
|
}
|
|
508
746
|
export function createAgentCommand(deps = {}) {
|
|
509
|
-
const agent = new Command('agent').description('Install TestSprite guidance into coding-agent config (Claude Code, Cursor, Cline, Antigravity, Codex)');
|
|
747
|
+
const agent = new Command('agent').description('Install TestSprite guidance into coding-agent config (Claude Code, Cursor, Cline, Antigravity, Kiro, Windsurf, Copilot, Codex)');
|
|
510
748
|
agent
|
|
511
749
|
.command('install')
|
|
512
|
-
.description('Write the TestSprite verification
|
|
513
|
-
.option('--target <t>', 'Agent target(s): claude, cursor, cline, antigravity, codex (comma-separated or repeated)', collect, [])
|
|
750
|
+
.description('Write the TestSprite agent skills (verification loop + first-run onboarding) into a project for a coding agent')
|
|
751
|
+
.option('--target <t>', 'Agent target(s): claude, cursor, cline, antigravity, kiro, windsurf, copilot, codex (comma-separated or repeated)', collect, [])
|
|
752
|
+
.option('--skill <name>', `Skill(s) to install: ${Object.keys(SKILLS).join(', ')} (comma-separated or repeated; default: all)`, collect, [])
|
|
514
753
|
.option('--dir <path>', 'Project root to write into (default: cwd)')
|
|
515
754
|
.option('--force', 'For own-file targets: overwrite existing file (a .bak backup is kept). ' +
|
|
516
755
|
'For codex (managed-section): replaces the section unconditionally; user content outside the section is never destroyed.')
|
|
@@ -519,17 +758,26 @@ export function createAgentCommand(deps = {}) {
|
|
|
519
758
|
await runInstall({
|
|
520
759
|
...resolveCommonOptions(command),
|
|
521
760
|
target: cmdOpts.target,
|
|
761
|
+
skills: cmdOpts.skill,
|
|
522
762
|
dir: cmdOpts.dir,
|
|
523
763
|
force: Boolean(cmdOpts.force),
|
|
524
764
|
}, deps);
|
|
525
765
|
});
|
|
526
766
|
agent
|
|
527
767
|
.command('list')
|
|
528
|
-
.description('List supported agent targets, their status, and landing paths')
|
|
768
|
+
.description('List supported agent targets and skills, their status, and landing paths')
|
|
529
769
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
530
770
|
.action(async (_o, command) => {
|
|
531
771
|
await runList(resolveCommonOptions(command), deps);
|
|
532
772
|
});
|
|
773
|
+
agent
|
|
774
|
+
.command('status')
|
|
775
|
+
.description('Check installed TestSprite skill files against this CLI version: ok, stale, modified, unmarked, absent, or corrupt (exits 1 when anything needs attention, so it can gate CI)')
|
|
776
|
+
.option('--dir <path>', 'Project root to inspect (default: cwd)')
|
|
777
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
778
|
+
.action(async (cmdOpts, command) => {
|
|
779
|
+
await runStatus({ ...resolveCommonOptions(command), dir: cmdOpts.dir }, deps);
|
|
780
|
+
});
|
|
533
781
|
return agent;
|
|
534
782
|
}
|
|
535
783
|
// ---------------------------------------------------------------------------
|
|
@@ -539,7 +787,7 @@ function resolveCommonOptions(command) {
|
|
|
539
787
|
const globals = command.optsWithGlobals();
|
|
540
788
|
return {
|
|
541
789
|
profile: globals.profile ?? 'default',
|
|
542
|
-
output: globals.output
|
|
790
|
+
output: resolveOutputMode(globals.output),
|
|
543
791
|
endpointUrl: globals.endpointUrl,
|
|
544
792
|
debug: globals.debug ?? false,
|
|
545
793
|
verbose: globals.verbose ?? false,
|