@ductape/cli 0.5.9 → 0.6.1
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 +0 -43
- package/dist/commands/apps.d.ts +0 -10
- package/dist/commands/apps.js +5 -24
- package/dist/commands/deploy-builds.js +14 -1
- package/dist/commands/deploy-remote.js +13 -0
- package/dist/commands/deploy-worker.js +5 -0
- package/dist/commands/secrets.d.ts +1 -0
- package/dist/commands/secrets.js +9 -1
- package/dist/commands/work-hooks.d.ts +64 -0
- package/dist/commands/work-hooks.js +335 -0
- package/dist/commands/work-test.d.ts +37 -0
- package/dist/commands/work-test.js +71 -0
- package/dist/commands/work.d.ts +19 -0
- package/dist/commands/work.js +520 -0
- package/dist/index.js +7 -118
- package/dist/lib/api-client.js +2 -4
- package/dist/lib/cloud-connection.js +9 -7
- package/dist/lib/forms/enums.d.ts +1 -1
- package/dist/lib/forms/enums.js +1 -1
- package/dist/lib/forms/prompt.d.ts +1 -0
- package/dist/lib/forms/prompt.js +17 -27
- package/dist/lib/forms/schemas.js +2 -2
- package/dist/lib/forms/types.d.ts +2 -1
- package/dist/lib/platform-api.d.ts +0 -1
- package/dist/lib/platform-api.js +9 -6
- package/dist/lib/read-body.d.ts +2 -0
- package/dist/lib/read-body.js +1 -1
- package/dist/lib/test-summary.d.ts +12 -0
- package/dist/lib/test-summary.js +50 -0
- package/dist/lib/work-delivery.d.ts +37 -0
- package/dist/lib/work-delivery.js +61 -0
- package/dist/lib/work-paths.d.ts +6 -0
- package/dist/lib/work-paths.js +16 -0
- package/dist/lib/work.d.ts +68 -0
- package/dist/lib/work.js +217 -0
- package/package.json +2 -3
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AgentClient } from '../lib/work.js';
|
|
2
|
+
/** A test run as a work artifact: what ran, on which commit, and what came of it. */
|
|
3
|
+
export declare function testArtifact(input: {
|
|
4
|
+
command: string;
|
|
5
|
+
exitCode: number;
|
|
6
|
+
output: string;
|
|
7
|
+
durationMs: number;
|
|
8
|
+
commit?: string;
|
|
9
|
+
uncommitted?: boolean;
|
|
10
|
+
at?: Date;
|
|
11
|
+
}): {
|
|
12
|
+
kind: "test_report";
|
|
13
|
+
ref: string;
|
|
14
|
+
title: string;
|
|
15
|
+
source: "ductape_cli";
|
|
16
|
+
meta: {
|
|
17
|
+
uncommitted_changes?: boolean | undefined;
|
|
18
|
+
commit?: string | undefined;
|
|
19
|
+
runner?: string | undefined;
|
|
20
|
+
skipped?: number | undefined;
|
|
21
|
+
passed?: number | undefined;
|
|
22
|
+
failed?: number | undefined;
|
|
23
|
+
result: string;
|
|
24
|
+
exit_code: number;
|
|
25
|
+
duration_ms: number;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Runs a test command as given, showing its output as it comes, then records the run on the work held. The exit code
|
|
30
|
+
* is the command's own, so `ductape work test -- npm test` can stand in for `npm test` anywhere.
|
|
31
|
+
*/
|
|
32
|
+
export declare function runRecordedTests(command: string[], opts: {
|
|
33
|
+
item?: string;
|
|
34
|
+
client?: AgentClient;
|
|
35
|
+
session?: string;
|
|
36
|
+
json?: boolean;
|
|
37
|
+
}): Promise<number>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { execFileSync, spawn } from 'node:child_process';
|
|
2
|
+
import { readTestCounts } from '../lib/test-summary.js';
|
|
3
|
+
import { recordOnWork } from '../lib/work-delivery.js';
|
|
4
|
+
const KEEP = 256 * 1024;
|
|
5
|
+
function git(args) {
|
|
6
|
+
try {
|
|
7
|
+
return execFileSync('git', args, { stdio: ['ignore', 'pipe', 'ignore'], encoding: 'utf8' }).trim();
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** A test run as a work artifact: what ran, on which commit, and what came of it. */
|
|
14
|
+
export function testArtifact(input) {
|
|
15
|
+
const counts = readTestCounts(input.output);
|
|
16
|
+
const at = (input.at ?? new Date()).toISOString().replace(/\.\d+Z$/, 'Z');
|
|
17
|
+
const passed = input.exitCode === 0;
|
|
18
|
+
const tally = counts.passed !== undefined ? `${counts.passed} passed, ${counts.failed ?? 0} failed` : passed ? 'passed' : `failed (exit ${input.exitCode})`;
|
|
19
|
+
return {
|
|
20
|
+
kind: 'test_report',
|
|
21
|
+
ref: `${input.command.slice(0, 200)} @ ${input.commit ?? 'no commit'} ${at}`,
|
|
22
|
+
title: `${input.command.slice(0, 120)}: ${tally}`,
|
|
23
|
+
source: 'ductape_cli',
|
|
24
|
+
meta: {
|
|
25
|
+
result: passed ? 'passed' : 'failed',
|
|
26
|
+
exit_code: input.exitCode,
|
|
27
|
+
duration_ms: Math.round(input.durationMs),
|
|
28
|
+
...(counts.passed !== undefined ? { passed: counts.passed, failed: counts.failed ?? 0 } : {}),
|
|
29
|
+
...(counts.skipped !== undefined ? { skipped: counts.skipped } : {}),
|
|
30
|
+
...(counts.runner ? { runner: counts.runner } : {}),
|
|
31
|
+
...(input.commit ? { commit: input.commit } : {}),
|
|
32
|
+
...(input.uncommitted ? { uncommitted_changes: true } : {}),
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Runs a test command as given, showing its output as it comes, then records the run on the work held. The exit code
|
|
38
|
+
* is the command's own, so `ductape work test -- npm test` can stand in for `npm test` anywhere.
|
|
39
|
+
*/
|
|
40
|
+
export async function runRecordedTests(command, opts) {
|
|
41
|
+
if (!command.length)
|
|
42
|
+
throw new Error('Give the test command after --, e.g. ductape work test -- npm test');
|
|
43
|
+
// One argument with spaces is a shell line ("npm test && npm run lint"); several are run as given.
|
|
44
|
+
const line = command.join(' ');
|
|
45
|
+
const child = command.length === 1 && /\s/.test(command[0]) ? spawn(command[0], { shell: true, stdio: ['inherit', 'pipe', 'pipe'] }) : spawn(command[0], command.slice(1), { stdio: ['inherit', 'pipe', 'pipe'] });
|
|
46
|
+
let output = '';
|
|
47
|
+
const keep = (chunk) => {
|
|
48
|
+
output += chunk.toString('utf8');
|
|
49
|
+
if (output.length > KEEP * 2)
|
|
50
|
+
output = output.slice(-KEEP);
|
|
51
|
+
};
|
|
52
|
+
child.stdout?.on('data', (c) => { process.stdout.write(c); keep(c); });
|
|
53
|
+
child.stderr?.on('data', (c) => { process.stderr.write(c); keep(c); });
|
|
54
|
+
const started = Date.now();
|
|
55
|
+
const exitCode = await new Promise((resolve) => {
|
|
56
|
+
child.on('error', (e) => { process.stderr.write(`Could not run ${command[0]}: ${e.message}\n`); resolve(127); });
|
|
57
|
+
child.on('close', (code, signal) => resolve(code ?? (signal ? 128 : 1)));
|
|
58
|
+
});
|
|
59
|
+
const artifact = testArtifact({
|
|
60
|
+
command: line,
|
|
61
|
+
exitCode,
|
|
62
|
+
output,
|
|
63
|
+
durationMs: Date.now() - started,
|
|
64
|
+
commit: git(['rev-parse', '--short', 'HEAD']),
|
|
65
|
+
uncommitted: Boolean(git(['status', '--porcelain'])),
|
|
66
|
+
});
|
|
67
|
+
const result = await recordOnWork(artifact, { item: opts.item, client: opts.client, session: opts.session });
|
|
68
|
+
if (opts.json)
|
|
69
|
+
process.stdout.write(`${JSON.stringify({ exit_code: exitCode, artifact, recorded: result?.recorded ?? [], candidates: result?.candidates ?? [] })}\n`);
|
|
70
|
+
return exitCode;
|
|
71
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* `ductape work`: the agentic work tracker. People and coding agents plan work as a task tree, claim items with a
|
|
4
|
+
* lease, report progress, and finish or hand work back. Agents run these through the Ductape MCP tools or their
|
|
5
|
+
* hooks; people can run the same commands. A command speaks for an agent when --client (or DUCTAPE_AGENT_CLIENT)
|
|
6
|
+
* names one; otherwise it speaks for the signed-in person.
|
|
7
|
+
*/
|
|
8
|
+
type Wrap = (fn: (...args: any[]) => void | Promise<void>) => (...args: any[]) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Artifacts from flags: --doc, --test-report, --release, --deployment, --build, --link. Each takes "ref", "url", or
|
|
11
|
+
* "ref=url" (a document path and where to read it, a release hash and its page).
|
|
12
|
+
*/
|
|
13
|
+
export declare function artifactsFromFlags(opts: any): Array<{
|
|
14
|
+
kind: string;
|
|
15
|
+
ref?: string;
|
|
16
|
+
url?: string;
|
|
17
|
+
}> | undefined;
|
|
18
|
+
export declare function registerWork(program: Command, wrap: Wrap): void;
|
|
19
|
+
export {};
|