@testsprite/testsprite-cli 0.2.0 → 0.4.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 +35 -26
- package/dist/commands/agent.d.ts +43 -0
- package/dist/commands/agent.js +200 -18
- package/dist/commands/auth.d.ts +5 -0
- package/dist/commands/auth.js +38 -27
- package/dist/commands/doctor.d.ts +49 -0
- package/dist/commands/doctor.js +233 -0
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/init.js +24 -14
- package/dist/commands/project.d.ts +75 -2
- package/dist/commands/project.js +326 -47
- package/dist/commands/test.d.ts +281 -2
- package/dist/commands/test.js +1658 -177
- package/dist/commands/usage.js +13 -12
- package/dist/index.js +71 -3
- package/dist/lib/agent-targets.d.ts +72 -6
- package/dist/lib/agent-targets.js +188 -6
- package/dist/lib/bundle.d.ts +34 -0
- package/dist/lib/bundle.js +63 -11
- package/dist/lib/client-factory.d.ts +31 -0
- package/dist/lib/client-factory.js +63 -0
- package/dist/lib/config.d.ts +2 -0
- package/dist/lib/config.js +11 -2
- package/dist/lib/credentials.js +10 -1
- package/dist/lib/dry-run/samples.d.ts +5 -0
- package/dist/lib/dry-run/samples.js +64 -0
- package/dist/lib/errors.d.ts +28 -1
- package/dist/lib/errors.js +40 -0
- package/dist/lib/failing-fe-resolver.d.ts +15 -0
- package/dist/lib/failing-fe-resolver.js +49 -1
- package/dist/lib/flaky.d.ts +80 -0
- package/dist/lib/flaky.js +76 -0
- package/dist/lib/http.d.ts +73 -1
- package/dist/lib/http.js +327 -135
- package/dist/lib/interrupt.d.ts +116 -0
- package/dist/lib/interrupt.js +182 -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/poll.d.ts +11 -0
- package/dist/lib/poll.js +70 -5
- 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.js +3 -1
- package/dist/lib/runs.types.d.ts +9 -0
- 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/lib/v3-advisory.d.ts +13 -0
- package/dist/lib/v3-advisory.js +24 -0
- package/dist/lib/version-notice.d.ts +37 -0
- package/dist/lib/version-notice.js +87 -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 +21 -0
- package/skills/testsprite-verify.codex.md +6 -0
- package/skills/testsprite-verify.skill.md +48 -4
package/dist/commands/usage.js
CHANGED
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
* `GET /api/cli/v1/usage` endpoint returning `{ credits, subPlan, creditsPerRun }`.
|
|
14
14
|
*/
|
|
15
15
|
import { Command } from 'commander';
|
|
16
|
-
import { emitDryRunBanner, makeHttpClient, } from '../lib/client-factory.js';
|
|
16
|
+
import { emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, } from '../lib/client-factory.js';
|
|
17
17
|
import { loadConfig } from '../lib/config.js';
|
|
18
18
|
import { resolvePortalBase } from '../lib/facade.js';
|
|
19
|
-
import { GLOBAL_OPTS_HINT, Output } from '../lib/output.js';
|
|
19
|
+
import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
20
20
|
/** Dry-run canned response — matches what the real /me + User lookup would return. */
|
|
21
21
|
export const DRY_RUN_USAGE_SAMPLE = {
|
|
22
22
|
userId: '11111111-1111-4111-8111-111111111111',
|
|
@@ -91,7 +91,11 @@ function renderUsage(u, portalBase) {
|
|
|
91
91
|
}
|
|
92
92
|
if (u.creditsPerRun !== undefined) {
|
|
93
93
|
lines.push(`cost per frontend run: ${u.creditsPerRun} credit(s)`);
|
|
94
|
-
|
|
94
|
+
// Backend runs DO consume credits (confirmed by design 2026-06-30 / DEV-289).
|
|
95
|
+
// The API exposes no backend-specific per-run cost field, and it differs from
|
|
96
|
+
// the frontend rate, so state that it bills without asserting a possibly-wrong
|
|
97
|
+
// number — check your balance before/after, or see the billing page.
|
|
98
|
+
lines.push(`cost per backend run: also consumes credits (exact amount not reported by the API)`);
|
|
95
99
|
}
|
|
96
100
|
// Pre-flight hint: how many runs the current balance can fund
|
|
97
101
|
if (u.credits !== undefined && u.creditsPerRun !== undefined && u.creditsPerRun > 0) {
|
|
@@ -122,7 +126,12 @@ export function createUsageCommand(deps = {}) {
|
|
|
122
126
|
.addHelpText('after', '\nExamples:\n' +
|
|
123
127
|
' testsprite usage # show balance + plan\n' +
|
|
124
128
|
' testsprite usage --output json # machine-readable balance\n' +
|
|
129
|
+
' testsprite usage --debug # trace HTTP method/path, request id, latency\n' +
|
|
125
130
|
' testsprite credits # alias for usage\n' +
|
|
131
|
+
'\nExit codes:\n' +
|
|
132
|
+
' 0 success (or --dry-run)\n' +
|
|
133
|
+
' 3 auth error — run `testsprite setup` to configure credentials\n' +
|
|
134
|
+
' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
|
|
126
135
|
'\nNote: credit balance requires a backend update to /me. Until shipped,\n' +
|
|
127
136
|
" check your portal's Billing page (/dashboard/settings/billing) for your balance.")
|
|
128
137
|
.action(async (_cmdOpts, command) => {
|
|
@@ -134,7 +143,7 @@ function resolveCommonOptions(command) {
|
|
|
134
143
|
const globals = command.optsWithGlobals();
|
|
135
144
|
return {
|
|
136
145
|
profile: globals.profile ?? 'default',
|
|
137
|
-
output: globals.output
|
|
146
|
+
output: resolveOutputMode(globals.output),
|
|
138
147
|
endpointUrl: globals.endpointUrl,
|
|
139
148
|
debug: globals.debug ?? false,
|
|
140
149
|
verbose: globals.verbose ?? false,
|
|
@@ -142,14 +151,6 @@ function resolveCommonOptions(command) {
|
|
|
142
151
|
requestTimeoutMs: parseRequestTimeoutFlag(globals.requestTimeout),
|
|
143
152
|
};
|
|
144
153
|
}
|
|
145
|
-
function parseRequestTimeoutFlag(raw) {
|
|
146
|
-
if (raw === undefined)
|
|
147
|
-
return undefined;
|
|
148
|
-
const n = Number(raw);
|
|
149
|
-
if (!Number.isFinite(n) || n <= 0)
|
|
150
|
-
return undefined;
|
|
151
|
-
return Math.round(n * 1000);
|
|
152
|
-
}
|
|
153
154
|
function makeOutput(mode, deps) {
|
|
154
155
|
return new Output(mode, { stdout: deps.stdout, stderr: deps.stderr });
|
|
155
156
|
}
|
package/dist/index.js
CHANGED
|
@@ -2,15 +2,26 @@
|
|
|
2
2
|
import { Command, CommanderError } from 'commander';
|
|
3
3
|
import { createAgentCommand } from './commands/agent.js';
|
|
4
4
|
import { createAuthCommand } from './commands/auth.js';
|
|
5
|
+
import { createDoctorCommand } from './commands/doctor.js';
|
|
5
6
|
import { createDeprecatedInitCommand, createSetupCommand, runConfigureViaSetup, } from './commands/init.js';
|
|
6
7
|
import { createProjectCommand } from './commands/project.js';
|
|
7
8
|
import { createTestCommand } from './commands/test.js';
|
|
8
9
|
import { createUsageCommand } from './commands/usage.js';
|
|
9
|
-
import { ApiError, CLIError, RequestTimeoutError } from './lib/errors.js';
|
|
10
|
+
import { ApiError, CLIError, InterruptError, RequestTimeoutError } from './lib/errors.js';
|
|
11
|
+
import { installBrokenPipeGuard, installSignalHandlers } from './lib/interrupt.js';
|
|
10
12
|
import { Output, isOutputMode } from './lib/output.js';
|
|
13
|
+
import { maybeInstallProxyAgent } from './lib/proxy.js';
|
|
11
14
|
import { renderCommanderError, rephraseUnknownOption } from './lib/render-error.js';
|
|
12
15
|
import { maybeEmitSkillNudge } from './lib/skill-nudge.js';
|
|
16
|
+
import { maybeNotifyUpdate } from './lib/update-check.js';
|
|
13
17
|
import { VERSION } from './version.js';
|
|
18
|
+
import { shouldRejectNodeVersion } from './version-guard.js';
|
|
19
|
+
// Guard: exit early with a clear message on unsupported Node.js versions,
|
|
20
|
+
// rather than failing later with a cryptic ESM/runtime error.
|
|
21
|
+
if (shouldRejectNodeVersion(process.versions.node)) {
|
|
22
|
+
process.stderr.write(`Error: testsprite requires Node.js >= 20 (found ${process.versions.node}).\nInstall the latest LTS from https://nodejs.org\n`);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
14
25
|
const program = new Command();
|
|
15
26
|
// exitOverride() causes Commander to throw CommanderError instead of calling
|
|
16
27
|
// process.exit() directly, giving our catch block a chance to remap error
|
|
@@ -25,7 +36,7 @@ program
|
|
|
25
36
|
.option('--endpoint-url <url>', 'Override the API endpoint host')
|
|
26
37
|
.option('--verbose', 'Emit human-readable HTTP retry / backoff / polling-mode transitions to stderr. Less noisy than --debug; useful for diagnosing hangs without the full trace.')
|
|
27
38
|
.option('--debug', 'Print HTTP method/path, request id, latency, retry decisions to stderr')
|
|
28
|
-
.option('--dry-run', 'Skip the network
|
|
39
|
+
.option('--dry-run', 'Skip the network and credentials; emit a canned sample matching the OpenAPI contract. Useful for learning the CLI surface without an API key. Note: file inputs you pass (--plan-from/--plans/--steps) are still read and validated locally; only --code-file uses a placeholder.')
|
|
29
40
|
.option('--request-timeout <seconds>', 'Client-side per-request timeout in seconds (default: 120). Aborts any single fetch that does not complete within this deadline. ' +
|
|
30
41
|
'Override via TESTSPRITE_REQUEST_TIMEOUT_MS env var (milliseconds). ' +
|
|
31
42
|
'Range: 1–600. Does not affect the --timeout polling ceiling for `test run/wait`.');
|
|
@@ -51,6 +62,7 @@ program.addCommand(createProjectCommand({}));
|
|
|
51
62
|
program.addCommand(createTestCommand());
|
|
52
63
|
program.addCommand(createAgentCommand({}));
|
|
53
64
|
program.addCommand(createUsageCommand());
|
|
65
|
+
program.addCommand(createDoctorCommand());
|
|
54
66
|
// Buffer Commander error messages instead of writing immediately. The catch
|
|
55
67
|
// block re-emits in the correct format (JSON or text) once the requested
|
|
56
68
|
// output mode is known. Safe because applyExitOverrideDeep ensures every
|
|
@@ -95,15 +107,37 @@ function commandPathOf(cmd) {
|
|
|
95
107
|
// allowlist, opt-out via TESTSPRITE_NO_SKILL_WARNING) and never throws.
|
|
96
108
|
program.hook('preAction', (_thisCommand, actionCommand) => {
|
|
97
109
|
const globals = actionCommand.optsWithGlobals();
|
|
110
|
+
const commandPath = commandPathOf(actionCommand);
|
|
98
111
|
maybeEmitSkillNudge({
|
|
99
|
-
commandPath
|
|
112
|
+
commandPath,
|
|
100
113
|
output: isOutputMode(globals.output) ? globals.output : 'text',
|
|
101
114
|
dryRun: globals.dryRun ?? false,
|
|
102
115
|
profile: globals.profile ?? 'default',
|
|
103
116
|
cwd: process.cwd(),
|
|
104
117
|
env: process.env,
|
|
105
118
|
});
|
|
119
|
+
// Best-effort update notice (see lib/update-check.ts): self-gates on the
|
|
120
|
+
// opt-out env, CI, TTY, and a 24h cache; the wiring adds the flag-level
|
|
121
|
+
// gates the lib cannot see. Skipped for `completion` (its stdout is eval'd
|
|
122
|
+
// by shells), under --output json, and under --dry-run. Deliberately not
|
|
123
|
+
// awaited: an advisory must never delay the real command.
|
|
124
|
+
if (globals.output !== 'json' && globals.dryRun !== true && commandPath !== 'completion') {
|
|
125
|
+
void maybeNotifyUpdate();
|
|
126
|
+
}
|
|
106
127
|
});
|
|
128
|
+
// Clean process lifecycle (DEV-331 piece 1, errors.md §8.1): during a `--wait`
|
|
129
|
+
// poll the scope is armed — the first SIGINT/SIGTERM/SIGHUP aborts gracefully
|
|
130
|
+
// and the wait path prints an honest partial (the run KEEPS executing and
|
|
131
|
+
// billing server-side) + re-attach hint before exiting 128+signum; a second
|
|
132
|
+
// signal hard-exits. Outside an armed scope: a clear one-line message +
|
|
133
|
+
// immediate exit (instead of Node's silent abrupt kill). Plus an EPIPE guard
|
|
134
|
+
// so piping to a reader that closes early (`| head`) exits cleanly instead of
|
|
135
|
+
// dumping a raw `write EPIPE` stack.
|
|
136
|
+
installSignalHandlers();
|
|
137
|
+
installBrokenPipeGuard();
|
|
138
|
+
// Corporate/CI proxies: honor HTTPS_PROXY/HTTP_PROXY/NO_PROXY (Node's fetch
|
|
139
|
+
// ignores them by default). No-op when no proxy variable is set.
|
|
140
|
+
maybeInstallProxyAgent();
|
|
107
141
|
try {
|
|
108
142
|
await program.parseAsync(process.argv);
|
|
109
143
|
}
|
|
@@ -140,10 +174,44 @@ catch (err) {
|
|
|
140
174
|
process.stderr.write(` granted: ${granted.join(', ')}\n`);
|
|
141
175
|
}
|
|
142
176
|
}
|
|
177
|
+
// Surface the version gap on CLIENT_TOO_OLD so the user sees exactly what
|
|
178
|
+
// moved without parsing the message string. (No "latest" line — the npm
|
|
179
|
+
// update-notice is the single source of truth for the newest release.)
|
|
180
|
+
if (err.code === 'CLIENT_TOO_OLD') {
|
|
181
|
+
const your = err.getDetail('yourVersion');
|
|
182
|
+
const min = err.getDetail('minVersion');
|
|
183
|
+
if (typeof your === 'string' && typeof min === 'string') {
|
|
184
|
+
process.stderr.write(` your version: ${your}, minimum supported: ${min}\n`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
143
187
|
}
|
|
144
188
|
process.exit(err.exitCode);
|
|
145
189
|
}
|
|
146
190
|
const output = new Output(mode);
|
|
191
|
+
if (err instanceof InterruptError) {
|
|
192
|
+
// Graceful detach (DEV-331 piece 1, errors.md §8.1): the wait-path catch
|
|
193
|
+
// block already printed the honest partial + re-attach hint. Exit with
|
|
194
|
+
// the conventional 128+signum code; `INTERRUPTED` is deliberately outside
|
|
195
|
+
// the error catalog. Note: Ctrl-C does NOT cancel the server-side run.
|
|
196
|
+
if (mode === 'json') {
|
|
197
|
+
const envelope = {
|
|
198
|
+
error: {
|
|
199
|
+
code: 'INTERRUPTED',
|
|
200
|
+
message: err.message,
|
|
201
|
+
nextAction: 'The server-side run (if any) keeps executing and billing. ' +
|
|
202
|
+
'Re-attach with: testsprite test wait <runId>, or stop it with: testsprite test cancel <runId> ' +
|
|
203
|
+
'(runId is in the partial JSON on stdout).',
|
|
204
|
+
requestId: 'local',
|
|
205
|
+
details: { signal: err.signal },
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
process.stderr.write(`${JSON.stringify(envelope, null, 2)}\n`);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
process.stderr.write(`Error: ${err.message}\n`);
|
|
212
|
+
}
|
|
213
|
+
process.exit(err.exitCode);
|
|
214
|
+
}
|
|
147
215
|
if (err instanceof RequestTimeoutError) {
|
|
148
216
|
// Structured rendering for per-request timeouts: JSON mode emits a
|
|
149
217
|
// machine-readable envelope; text mode emits the message with a hint.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type AgentTarget = 'claude' | 'cursor' | 'cline' | 'antigravity' | 'codex';
|
|
1
|
+
export type AgentTarget = 'claude' | 'cursor' | 'cline' | 'antigravity' | 'codex' | 'kiro' | 'windsurf' | 'copilot';
|
|
2
2
|
export interface TargetSpec {
|
|
3
3
|
status: 'ga' | 'experimental';
|
|
4
4
|
/**
|
|
@@ -9,11 +9,19 @@ export interface TargetSpec {
|
|
|
9
9
|
*/
|
|
10
10
|
path: string;
|
|
11
11
|
/**
|
|
12
|
-
* 'own-file': the CLI owns the whole file (claude/cursor/cline/antigravity).
|
|
12
|
+
* 'own-file': the CLI owns the whole file (claude/cursor/cline/antigravity/windsurf).
|
|
13
13
|
* 'managed-section': the CLI writes only a sentinel-delimited section inside
|
|
14
14
|
* a potentially user-authored file (codex target, AGENTS.md).
|
|
15
15
|
*/
|
|
16
16
|
mode: 'own-file' | 'managed-section';
|
|
17
|
+
/**
|
|
18
|
+
* When true, render the budget-friendly body (see {@link compactBodyFor})
|
|
19
|
+
* instead of the full own-file skill body. Used for own-file targets whose
|
|
20
|
+
* rule files are size-capped — currently `windsurf` (`.windsurf/rules/*.md`
|
|
21
|
+
* files cap at ~12 K characters and Cascade silently truncates beyond that,
|
|
22
|
+
* which would cut the full ~22 KB verify skill in half).
|
|
23
|
+
*/
|
|
24
|
+
compactBody?: boolean;
|
|
17
25
|
/**
|
|
18
26
|
* Wrap a skill body in this target's frontmatter/header. Takes the skill's
|
|
19
27
|
* `name`+`description` (own-file targets emit them as frontmatter) and the body.
|
|
@@ -89,9 +97,57 @@ export declare const TARGETS: Record<AgentTarget, TargetSpec>;
|
|
|
89
97
|
/** Sentinel pair that bounds our managed section in AGENTS.md. */
|
|
90
98
|
export declare const MANAGED_SECTION_BEGIN = "<!-- BEGIN TESTSPRITE AGENT SECTION (testsprite agent install codex) -->";
|
|
91
99
|
export declare const MANAGED_SECTION_END = "<!-- END TESTSPRITE AGENT SECTION -->";
|
|
100
|
+
/**
|
|
101
|
+
* When one marker covers several skills (the codex managed section aggregates
|
|
102
|
+
* every installed skill), their names are joined with this separator in the
|
|
103
|
+
* marker's skill field. Skill names never contain '+' (see {@link SKILLS} keys).
|
|
104
|
+
*/
|
|
105
|
+
export declare const MARKER_SKILL_SEPARATOR = "+";
|
|
106
|
+
/**
|
|
107
|
+
* First {@link MARKER_HASH_HEX_LENGTH} hex chars of the SHA-256 of a canonical
|
|
108
|
+
* skill body. The hash covers the CANONICAL BODY ONLY (pre-wrap, pre-marker),
|
|
109
|
+
* so writing the marker into the rendered artifact never changes the hash the
|
|
110
|
+
* marker itself carries.
|
|
111
|
+
*/
|
|
112
|
+
export declare function bodyHash12(canonicalBody: string): string;
|
|
113
|
+
/**
|
|
114
|
+
* Build the provenance marker line for a skill (or a
|
|
115
|
+
* {@link MARKER_SKILL_SEPARATOR}-joined skill set) and its canonical body.
|
|
116
|
+
* `agent status` compares this fingerprint against the bodies the running CLI
|
|
117
|
+
* ships to detect silently stale installs.
|
|
118
|
+
*/
|
|
119
|
+
export declare function buildSkillMarker(skillName: string, canonicalBody: string): string;
|
|
120
|
+
/** A marker line parsed back into its fields. */
|
|
121
|
+
export interface ParsedSkillMarker {
|
|
122
|
+
/** Skill name, or several names joined with {@link MARKER_SKILL_SEPARATOR}. */
|
|
123
|
+
skill: string;
|
|
124
|
+
/** CLI version that wrote the artifact. */
|
|
125
|
+
version: string;
|
|
126
|
+
/** First 12 hex chars of the canonical body's SHA-256 at install time. */
|
|
127
|
+
hash12: string;
|
|
128
|
+
/** The exact marker line (trailing CR/whitespace stripped) as found. */
|
|
129
|
+
line: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Find the first testsprite-skill marker line in `content`, or null when the
|
|
133
|
+
* content carries none (a pre-marker install). Lines are matched whole with
|
|
134
|
+
* trailing CR/whitespace stripped, so CRLF checkouts parse identically.
|
|
135
|
+
*/
|
|
136
|
+
export declare function parseSkillMarker(content: string): ParsedSkillMarker | null;
|
|
92
137
|
type ReadFn = (url: URL) => string;
|
|
93
138
|
/** Load a skill's own-file body by skill name (frontmatter is added by `wrap`). */
|
|
94
139
|
export declare function loadSkillBodyFor(skill: string, read?: ReadFn): string;
|
|
140
|
+
/**
|
|
141
|
+
* Budget-friendly body for an own-file target whose rule files are size-capped
|
|
142
|
+
* (e.g. windsurf). For a skill that ships a trimmed codex asset (`codex.kind ===
|
|
143
|
+
* 'full'`, e.g. `testsprite-verify` — full body ~22 KB, codex ~5 KB) we render
|
|
144
|
+
* that compact asset so the wrapped file stays under the cap. For skills whose
|
|
145
|
+
* codex contribution is only a one-liner (`'line'`/`'none'`, e.g.
|
|
146
|
+
* `testsprite-onboard`), the one-liner is useless as a standalone rule and the
|
|
147
|
+
* full own-file body (~6.5 KB) already fits the budget — so the full body is
|
|
148
|
+
* used.
|
|
149
|
+
*/
|
|
150
|
+
export declare function compactBodyFor(skill: string, read?: ReadFn): string;
|
|
95
151
|
/**
|
|
96
152
|
* Resolve a skill's codex (AGENTS.md) contribution as a Markdown string.
|
|
97
153
|
* 'full' → read the `*.codex.md` asset; 'line' → the inline one-liner; 'none' → ''.
|
|
@@ -116,15 +172,25 @@ export declare function loadSkillBody(read?: ReadFn): string;
|
|
|
116
172
|
* @deprecated Use {@link codexContentFor}.
|
|
117
173
|
*/
|
|
118
174
|
export declare function loadCodexSkillBody(read?: ReadFn): string;
|
|
175
|
+
/**
|
|
176
|
+
* Exact own-file bytes for a skill on a target, carrying the GIVEN marker line.
|
|
177
|
+
* `agent status` uses this to re-render the current canonical body with a
|
|
178
|
+
* file's own (possibly older-versioned) marker: when only the marker's version
|
|
179
|
+
* string lags but the body is unchanged, the artifact still compares pristine.
|
|
180
|
+
*/
|
|
181
|
+
export declare function renderOwnFileWithMarker(target: AgentTarget, skill: string, markerLine: string, body?: string): string;
|
|
119
182
|
/**
|
|
120
183
|
* The exact bytes to write for one skill on one target.
|
|
121
184
|
*
|
|
122
185
|
* - own-file targets: `body` defaults to the skill's own-file asset, wrapped in
|
|
123
|
-
* the target's frontmatter/header
|
|
186
|
+
* the target's frontmatter/header, and carrying a provenance marker line so
|
|
187
|
+
* `agent status` can tell fresh, stale, and hand-edited installs apart.
|
|
124
188
|
* - codex (managed-section): returns the skill's codex contribution unwrapped
|
|
125
|
-
* (plain Markdown, no frontmatter). The real install does NOT
|
|
126
|
-
* codex
|
|
127
|
-
*
|
|
189
|
+
* and marker-free (plain Markdown, no frontmatter). The real install does NOT
|
|
190
|
+
* call this for codex: it aggregates all skills via
|
|
191
|
+
* {@link buildCodexAggregate} and writes ONE marker just inside the BEGIN
|
|
192
|
+
* sentinel. It is kept single-skill here for tests and parity. Pass an
|
|
193
|
+
* explicit `body` to override.
|
|
128
194
|
*/
|
|
129
195
|
export declare function renderForTarget(t: AgentTarget, skill: string, body?: string): {
|
|
130
196
|
path: string;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { VERSION } from '../version.js';
|
|
2
4
|
/**
|
|
3
5
|
* `testsprite-onboard` codex contribution — a single always-on line. Kept here
|
|
4
6
|
* (not in a `*.codex.md` asset) because it is one line; see {@link CodexContribution}.
|
|
@@ -51,6 +53,29 @@ function wrapSkill(name, description, body) {
|
|
|
51
53
|
function wrapMdc(_name, description, body) {
|
|
52
54
|
return `---\ndescription: ${description}\nalwaysApply: false\n---\n\n${body}\n`;
|
|
53
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.
|
|
75
|
+
*/
|
|
76
|
+
function wrapCopilot(_name, description, body) {
|
|
77
|
+
return `---\ndescription: ${description}\napplyTo: '**'\n---\n\n${body}\n`;
|
|
78
|
+
}
|
|
54
79
|
// ---------------------------------------------------------------------------
|
|
55
80
|
// Landing paths
|
|
56
81
|
// ---------------------------------------------------------------------------
|
|
@@ -70,6 +95,12 @@ export function pathFor(target, skill) {
|
|
|
70
95
|
return `.cursor/rules/${skill}.mdc`;
|
|
71
96
|
case 'cline':
|
|
72
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`;
|
|
73
104
|
case 'codex':
|
|
74
105
|
return 'AGENTS.md';
|
|
75
106
|
}
|
|
@@ -99,6 +130,35 @@ export const TARGETS = {
|
|
|
99
130
|
mode: 'own-file',
|
|
100
131
|
wrap: (_name, _description, body) => body,
|
|
101
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),
|
|
153
|
+
mode: 'own-file',
|
|
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,
|
|
161
|
+
},
|
|
102
162
|
/**
|
|
103
163
|
* codex target — managed-section mode.
|
|
104
164
|
*
|
|
@@ -127,6 +187,64 @@ export const TARGETS = {
|
|
|
127
187
|
/** Sentinel pair that bounds our managed section in AGENTS.md. */
|
|
128
188
|
export const MANAGED_SECTION_BEGIN = '<!-- BEGIN TESTSPRITE AGENT SECTION (testsprite agent install codex) -->';
|
|
129
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
|
+
}
|
|
130
248
|
const defaultRead = (url) => readFileSync(url, 'utf8');
|
|
131
249
|
// ---------------------------------------------------------------------------
|
|
132
250
|
// Asset loaders
|
|
@@ -148,6 +266,24 @@ export function loadSkillBodyFor(skill, read = defaultRead) {
|
|
|
148
266
|
throw new Error(`unknown skill: ${skill}`);
|
|
149
267
|
return readSkillAsset(spec.bodyFile, read);
|
|
150
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
|
+
}
|
|
151
287
|
/**
|
|
152
288
|
* Resolve a skill's codex (AGENTS.md) contribution as a Markdown string.
|
|
153
289
|
* 'full' → read the `*.codex.md` asset; 'line' → the inline one-liner; 'none' → ''.
|
|
@@ -194,15 +330,58 @@ export function loadCodexSkillBody(read = defaultRead) {
|
|
|
194
330
|
// ---------------------------------------------------------------------------
|
|
195
331
|
// renderForTarget
|
|
196
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);
|
|
372
|
+
}
|
|
197
373
|
/**
|
|
198
374
|
* The exact bytes to write for one skill on one target.
|
|
199
375
|
*
|
|
200
376
|
* - own-file targets: `body` defaults to the skill's own-file asset, wrapped in
|
|
201
|
-
* the target's frontmatter/header
|
|
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.
|
|
202
379
|
* - codex (managed-section): returns the skill's codex contribution unwrapped
|
|
203
|
-
* (plain Markdown, no frontmatter). The real install does NOT
|
|
204
|
-
* codex
|
|
205
|
-
*
|
|
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.
|
|
206
385
|
*/
|
|
207
386
|
export function renderForTarget(t, skill, body) {
|
|
208
387
|
const spec = TARGETS[t];
|
|
@@ -214,7 +393,10 @@ export function renderForTarget(t, skill, body) {
|
|
|
214
393
|
const resolvedBody = body !== undefined ? body : codexContentFor(skill);
|
|
215
394
|
return { path, content: spec.wrap(skillSpec.name, skillSpec.description, resolvedBody) };
|
|
216
395
|
}
|
|
217
|
-
const resolvedBody = body !== undefined ? body : loadSkillBodyFor(skill);
|
|
218
|
-
return {
|
|
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
|
+
};
|
|
219
401
|
}
|
|
220
402
|
//# sourceMappingURL=agent-targets.js.map
|
package/dist/lib/bundle.d.ts
CHANGED
|
@@ -174,6 +174,40 @@ export declare function buildMeta(ctx: CliFailureContext, fetchedAt?: Date): Bun
|
|
|
174
174
|
* → 10 by default; the original ApiError is preserved when applicable).
|
|
175
175
|
*/
|
|
176
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;
|
|
177
211
|
/**
|
|
178
212
|
* Stream a presigned URL into a file with bounded retry on transport
|
|
179
213
|
* failures. 4xx (presigned URL expired or unauthorized) is NOT
|