@ductape/cli 0.6.0 → 0.6.2
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 +8 -29
- package/dist/lib/api-client.js +2 -4
- package/dist/lib/cloud-connection.js +0 -3
- 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
package/dist/lib/api-client.js
CHANGED
|
@@ -15,10 +15,8 @@ export class ApiClient {
|
|
|
15
15
|
}
|
|
16
16
|
async request(method, path, body, extraHeaders) {
|
|
17
17
|
const url = `${this.apiUrl}${path.startsWith('/') ? path : `/${path}`}`;
|
|
18
|
-
// Bytes (a Worker bundle) are sent as they are; everything else is JSON.
|
|
19
|
-
const raw = body instanceof Uint8Array;
|
|
20
18
|
const headers = {
|
|
21
|
-
'Content-Type':
|
|
19
|
+
'Content-Type': 'application/json',
|
|
22
20
|
...extraHeaders,
|
|
23
21
|
};
|
|
24
22
|
if (this.token) {
|
|
@@ -30,7 +28,7 @@ export class ApiClient {
|
|
|
30
28
|
method,
|
|
31
29
|
headers,
|
|
32
30
|
...(this.timeoutMs ? { signal: AbortSignal.timeout(this.timeoutMs) } : {}),
|
|
33
|
-
body: body
|
|
31
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
34
32
|
});
|
|
35
33
|
}
|
|
36
34
|
catch (cause) {
|
|
@@ -309,9 +309,6 @@ export const GCP_DEPLOY_CREATES = [
|
|
|
309
309
|
];
|
|
310
310
|
export const GCP_DEPLOY_SAFETY = 'Ductape only adds resources it labels as its own (ductape_managed), never changes or reuses one it did not create, and never deletes anything, including what it created. Removing deployed resources is always your own action. Use a dedicated project if you can, so what Ductape adds is easy to see.';
|
|
311
311
|
export const GCP_DEPLOY_TROUBLESHOOTING = [
|
|
312
|
-
{ problem: 'Static egress creation fails with a Compute API or IAM error', fix: 'Enable compute.googleapis.com in the connected project. Grant the connection service account the Compute permissions named in the error, then retry the deployment. The journal records the outbound IPv4 once the network is ready.' },
|
|
313
|
-
{ problem: 'Cloud Run cannot attach the VPC subnet', fix: 'Check that the subnet belongs to the selected VPC and is in the deployment region and connected project. If Google Cloud reports an IAM denial, check the principal and permission named in the error.' },
|
|
314
|
-
{ problem: 'Cloud Run starts but Atlas connections time out or fail during TLS setup', fix: 'Check that Cloud NAT serves the selected subnet and uses a reserved IPv4. Verify the actual outbound IP from the revision and allowlist it as a /32 in Atlas. If the Ductape resolver returns 502, check the integrations logs for that request separately.' },
|
|
315
312
|
{ problem: '"<API> has not been used in project <PROJECT_ID> before or it is disabled"', fix: 'Enable that API (step 1), wait a minute or two for it to take effect, and try again.' },
|
|
316
313
|
{ problem: 'Validation lists missing permissions and the roles that grant them', fix: 'Grant exactly those roles to the Ductape service account on the project (step 3) and validate again. Role changes can take a minute to apply.' },
|
|
317
314
|
{ problem: '"caller does not have permission to act as service account ..." when a build or deploy starts', fix: 'Grant roles/iam.serviceAccountUser to the Ductape service account on the project. Cloud Build and Cloud Run run as a service account, and the Ductape account must be allowed to act as it.' },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Enum values aligned with @ductape/sdk — used for CLI dropdowns */
|
|
2
2
|
export declare const STORAGE_PROVIDERS: readonly ["aws", "gcp", "azure"];
|
|
3
|
-
export declare const DATABASE_TYPES: readonly ["postgresql", "mongodb", "mysql"
|
|
3
|
+
export declare const DATABASE_TYPES: readonly ["postgresql", "mongodb", "mysql"];
|
|
4
4
|
export declare const GRAPH_TYPES: readonly ["neo4j", "neptune", "arangodb", "memgraph"];
|
|
5
5
|
export declare const VECTOR_DB_TYPES: readonly ["pinecone", "qdrant", "weaviate", "chroma", "milvus", "pgvector", "memory"];
|
|
6
6
|
export declare const VECTOR_DISTANCE_METRICS: readonly ["cosine", "euclidean", "dotproduct"];
|
package/dist/lib/forms/enums.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Enum values aligned with @ductape/sdk — used for CLI dropdowns */
|
|
2
2
|
export const STORAGE_PROVIDERS = ['aws', 'gcp', 'azure'];
|
|
3
|
-
export const DATABASE_TYPES = ['postgresql', 'mongodb', 'mysql'
|
|
3
|
+
export const DATABASE_TYPES = ['postgresql', 'mongodb', 'mysql'];
|
|
4
4
|
export const GRAPH_TYPES = ['neo4j', 'neptune', 'arangodb', 'memgraph'];
|
|
5
5
|
export const VECTOR_DB_TYPES = [
|
|
6
6
|
'pinecone',
|
|
@@ -6,6 +6,7 @@ export type InteractiveOpts = {
|
|
|
6
6
|
export declare function isInteractive(opts?: InteractiveOpts): boolean;
|
|
7
7
|
export declare function promptForm(schema: FormSchema, opts?: {
|
|
8
8
|
patch?: boolean;
|
|
9
|
+
preset?: Record<string, unknown>;
|
|
9
10
|
}): Promise<Record<string, unknown>>;
|
|
10
11
|
export declare function promptTag(label?: string): Promise<string>;
|
|
11
12
|
export declare function promptKey(label?: string): Promise<string>;
|
package/dist/lib/forms/prompt.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import password from '@inquirer/password';
|
|
2
1
|
import input from '@inquirer/input';
|
|
2
|
+
import password from '@inquirer/password';
|
|
3
3
|
import select from '@inquirer/select';
|
|
4
4
|
import { MESSAGE_BROKER_TYPES, STORAGE_PROVIDERS } from './enums.js';
|
|
5
5
|
export function isInteractive(opts) {
|
|
@@ -67,26 +67,7 @@ async function promptEnvs(variant, context) {
|
|
|
67
67
|
message: `Environment slug #${envs.length + 1} (3 letters)`,
|
|
68
68
|
validate: (v) => (v.length >= 1 && v.length <= 3 ? true : 'Use 1–3 characters'),
|
|
69
69
|
});
|
|
70
|
-
if (variant === 'database'
|
|
71
|
-
const mode = await select({ message: 'Redis connection', choices: [
|
|
72
|
-
{ name: 'Redis URL', value: 'url' }, { name: 'Import cloud instance', value: 'import' }, { name: 'Provision cloud instance', value: 'provision' },
|
|
73
|
-
] });
|
|
74
|
-
if (mode === 'url')
|
|
75
|
-
envs.push({ slug, connection_url: await password({ message: 'Redis URL (redis:// or rediss://)' }) });
|
|
76
|
-
else {
|
|
77
|
-
const row = { slug, cloud: await input({ message: 'Cloud connection tag' }),
|
|
78
|
-
instance: await input({ message: 'Redis instance name or resource ID' }), region: await input({ message: 'Cloud region' }), importExisting: mode === 'import' };
|
|
79
|
-
if (mode === 'import') {
|
|
80
|
-
const token = await password({ message: 'AWS Redis AUTH token (leave empty for GCP/Azure or stored credentials)' });
|
|
81
|
-
if (token)
|
|
82
|
-
row.masterPassword = token;
|
|
83
|
-
}
|
|
84
|
-
else
|
|
85
|
-
row.redis = await promptJsonObject('Redis provider settings (GCP: authorizedNetwork, memorySizeGb; AWS: cacheSubnetGroupName, securityGroupIds, nodeType; Azure: resourceGroup, sku)');
|
|
86
|
-
envs.push(row);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else if (variant === 'database' || variant === 'graph') {
|
|
70
|
+
if (variant === 'database' || variant === 'graph') {
|
|
90
71
|
const connection_url = await input({
|
|
91
72
|
message: 'Connection URL',
|
|
92
73
|
});
|
|
@@ -165,6 +146,15 @@ async function promptField(field, patch) {
|
|
|
165
146
|
throw new Error('envs field missing envsVariant');
|
|
166
147
|
return promptEnvs(field.envsVariant);
|
|
167
148
|
}
|
|
149
|
+
if (field.kind === 'secret') {
|
|
150
|
+
// Masked and never trimmed: a secret is stored exactly as typed or pasted, apart from a trailing line break.
|
|
151
|
+
const value = (await password({ message: field.label, mask: '*' })).replace(/\r?\n$/, '');
|
|
152
|
+
if (!value && !required)
|
|
153
|
+
return undefined;
|
|
154
|
+
if (!value && required)
|
|
155
|
+
throw new Error(`${field.label} is required`);
|
|
156
|
+
return value;
|
|
157
|
+
}
|
|
168
158
|
const value = await input({
|
|
169
159
|
message: field.label,
|
|
170
160
|
default: field.default !== undefined ? String(field.default) : undefined,
|
|
@@ -178,9 +168,14 @@ async function promptField(field, patch) {
|
|
|
178
168
|
export async function promptForm(schema, opts) {
|
|
179
169
|
const patch = Boolean(opts?.patch);
|
|
180
170
|
const body = {};
|
|
171
|
+
const preset = opts?.preset ?? {};
|
|
181
172
|
let vectorType;
|
|
182
|
-
let databaseType;
|
|
183
173
|
for (const field of schema.fields) {
|
|
174
|
+
// A value already given on the command line (such as -k) is used, not asked for again.
|
|
175
|
+
if (preset[field.key] !== undefined && preset[field.key] !== '') {
|
|
176
|
+
body[field.key] = preset[field.key];
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
184
179
|
if (patch && !field.required) {
|
|
185
180
|
const set = await askYesNo(`Set ${field.label}?`, false);
|
|
186
181
|
if (!set)
|
|
@@ -191,14 +186,9 @@ export async function promptForm(schema, opts) {
|
|
|
191
186
|
if (value !== undefined) {
|
|
192
187
|
body.type = value;
|
|
193
188
|
vectorType = String(value);
|
|
194
|
-
databaseType = String(value);
|
|
195
189
|
}
|
|
196
190
|
continue;
|
|
197
191
|
}
|
|
198
|
-
if (field.kind === 'envs' && field.envsVariant === 'database' && databaseType === 'redis') {
|
|
199
|
-
body[field.key] = await promptEnvs('database', { databaseType });
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
192
|
if (field.kind === 'envs' && field.envsVariant === 'vector') {
|
|
203
193
|
const envs = await promptEnvs('vector', { vectorType });
|
|
204
194
|
if (envs.length)
|
|
@@ -198,13 +198,13 @@ const SCHEMAS = {
|
|
|
198
198
|
'secrets:create': {
|
|
199
199
|
fields: [
|
|
200
200
|
{ key: 'key', label: 'Secret key', kind: 'text', required: true },
|
|
201
|
-
{ key: 'value', label: 'Secret value', kind: '
|
|
201
|
+
{ key: 'value', label: 'Secret value (hidden as you type)', kind: 'secret', required: true },
|
|
202
202
|
DESC,
|
|
203
203
|
],
|
|
204
204
|
},
|
|
205
205
|
'secrets:update': {
|
|
206
206
|
fields: optional([
|
|
207
|
-
{ key: 'value', label: 'Secret value', kind: '
|
|
207
|
+
{ key: 'value', label: 'Secret value (hidden as you type)', kind: 'secret' },
|
|
208
208
|
DESC,
|
|
209
209
|
]),
|
|
210
210
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/** `secret` is typed without being shown on screen. */
|
|
2
|
+
export type FieldKind = 'text' | 'secret' | 'number' | 'enum' | 'envs';
|
|
2
3
|
export type EnvsVariant = 'database' | 'graph' | 'storage' | 'broker' | 'vector' | 'simple';
|
|
3
4
|
export interface FormField {
|
|
4
5
|
key: string;
|
|
@@ -24,7 +24,6 @@ export declare function getApp(ctx: WorkspaceContext, opts: {
|
|
|
24
24
|
tag?: string;
|
|
25
25
|
}): Promise<unknown>;
|
|
26
26
|
export declare function createApp(ctx: WorkspaceContext, body: Record<string, unknown>): Promise<unknown>;
|
|
27
|
-
export declare function getAppVersions(ctx: WorkspaceContext, appId: string): Promise<unknown>;
|
|
28
27
|
export declare function updateApp(ctx: WorkspaceContext, appId: string, body: Record<string, unknown>): Promise<unknown>;
|
|
29
28
|
export declare function updateAppViaProxy(ctx: WorkspaceContext, tag: string, body: Record<string, unknown>): Promise<unknown>;
|
|
30
29
|
export declare function deleteApp(ctx: WorkspaceContext, appId: string): Promise<unknown>;
|
package/dist/lib/platform-api.js
CHANGED
|
@@ -428,19 +428,22 @@ export async function createApp(ctx, body) {
|
|
|
428
428
|
const result = await client(ctx).post('/apps/v1/create', payload);
|
|
429
429
|
return unwrapOne(result);
|
|
430
430
|
}
|
|
431
|
-
export async function getAppVersions(ctx, appId) {
|
|
432
|
-
return unwrapOne(await client(ctx).getPath(`/apps/v1/${appId}/versions/metadata`, workspaceAuthQuery(ctx)));
|
|
433
|
-
}
|
|
434
431
|
export async function updateApp(ctx, appId, body) {
|
|
435
|
-
const q =
|
|
436
|
-
|
|
432
|
+
const q = {
|
|
433
|
+
user_id: ctx.credentials.user_id,
|
|
434
|
+
public_key: ctx.credentials.public_key,
|
|
435
|
+
};
|
|
436
|
+
const result = await client(ctx).put(`/apps/v1/${appId}?${new URLSearchParams(q).toString()}`, body);
|
|
437
437
|
return unwrapOne(result);
|
|
438
438
|
}
|
|
439
439
|
export async function updateAppViaProxy(ctx, tag, body) {
|
|
440
440
|
return proxy(ctx).execute('app', 'update', [tag, body]);
|
|
441
441
|
}
|
|
442
442
|
export async function deleteApp(ctx, appId) {
|
|
443
|
-
const q =
|
|
443
|
+
const q = {
|
|
444
|
+
user_id: ctx.credentials.user_id,
|
|
445
|
+
public_key: ctx.credentials.public_key,
|
|
446
|
+
};
|
|
444
447
|
return client(ctx).delete(`/apps/v1/${appId}?${new URLSearchParams(q).toString()}`);
|
|
445
448
|
}
|
|
446
449
|
// —— App actions (sdk-proxy — admin op, requires access key) ——
|
package/dist/lib/read-body.d.ts
CHANGED
|
@@ -7,5 +7,7 @@ export declare function resolveBody(opts: InteractiveOpts & {
|
|
|
7
7
|
schema?: FormSchema;
|
|
8
8
|
patch?: boolean;
|
|
9
9
|
requireBody?: boolean;
|
|
10
|
+
/** Fields already given as flags; the form does not ask for them. */
|
|
11
|
+
preset?: Record<string, unknown>;
|
|
10
12
|
}): Promise<Record<string, unknown> | undefined>;
|
|
11
13
|
export declare function bodyRequiredHint(schemaKey?: string): string;
|
package/dist/lib/read-body.js
CHANGED
|
@@ -20,7 +20,7 @@ export async function resolveBody(opts) {
|
|
|
20
20
|
}
|
|
21
21
|
const schema = opts.schema ?? (opts.schemaKey ? getFormSchema(opts.schemaKey) : undefined);
|
|
22
22
|
if (schema && isInteractive(opts)) {
|
|
23
|
-
return promptForm(schema, { patch: opts.patch ?? opts.schemaKey?.endsWith(':update') });
|
|
23
|
+
return promptForm(schema, { patch: opts.patch ?? opts.schemaKey?.endsWith(':update'), preset: opts.preset });
|
|
24
24
|
}
|
|
25
25
|
if (opts.requireBody && isInteractive(opts) === false) {
|
|
26
26
|
return undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the pass and fail counts from a test run's output, for the runners people use most. Only the summary lines
|
|
3
|
+
* are read, last one wins (a runner can print progress before its final tally). Nothing found means the counts are
|
|
4
|
+
* unknown; the exit code still says whether the run passed.
|
|
5
|
+
*/
|
|
6
|
+
export interface ITestCounts {
|
|
7
|
+
passed?: number;
|
|
8
|
+
failed?: number;
|
|
9
|
+
skipped?: number;
|
|
10
|
+
runner?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function readTestCounts(output: string): ITestCounts;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// eslint-disable-next-line no-control-regex
|
|
2
|
+
const ANSI = /\u001b\[[0-9;]*[A-Za-z]/g;
|
|
3
|
+
const num = (s) => (s === undefined ? undefined : Number(s));
|
|
4
|
+
const RULES = [
|
|
5
|
+
// Jest: "Tests: 1 failed, 2 skipped, 40 passed, 43 total"
|
|
6
|
+
{
|
|
7
|
+
runner: 'jest',
|
|
8
|
+
re: /^Tests:\s+(.*\btotal)\s*$/m,
|
|
9
|
+
read: (m) => ({ failed: num(/(\d+) failed/.exec(m[1])?.[1]) ?? 0, skipped: num(/(\d+) skipped/.exec(m[1])?.[1]), passed: num(/(\d+) passed/.exec(m[1])?.[1]) ?? 0 }),
|
|
10
|
+
},
|
|
11
|
+
// Vitest: " Tests 2 failed | 40 passed (42)"
|
|
12
|
+
{
|
|
13
|
+
runner: 'vitest',
|
|
14
|
+
re: /^\s*Tests\s+(.*\(\d+\))\s*$/m,
|
|
15
|
+
read: (m) => ({ failed: num(/(\d+) failed/.exec(m[1])?.[1]) ?? 0, skipped: num(/(\d+) skipped/.exec(m[1])?.[1]), passed: num(/(\d+) passed/.exec(m[1])?.[1]) ?? 0 }),
|
|
16
|
+
},
|
|
17
|
+
// node:test and TAP: "# pass 48" / "# fail 0" (node:test also prints "ℹ pass 48")
|
|
18
|
+
{
|
|
19
|
+
runner: 'node-test',
|
|
20
|
+
re: /^(?:#|ℹ) pass (\d+)\s*$[\s\S]*?^(?:#|ℹ) fail (\d+)\s*$/m,
|
|
21
|
+
read: (m) => ({ passed: Number(m[1]), failed: Number(m[2]) }),
|
|
22
|
+
},
|
|
23
|
+
// Mocha: " 40 passing (2s)" then optionally " 2 failing"
|
|
24
|
+
{
|
|
25
|
+
runner: 'mocha',
|
|
26
|
+
re: /^\s*(\d+) passing \([^)]*\)\s*$(?:\s*^\s*(\d+) pending\s*$)?(?:\s*^\s*(\d+) failing\s*$)?/m,
|
|
27
|
+
read: (m) => ({ passed: Number(m[1]), skipped: num(m[2]), failed: num(m[3]) ?? 0 }),
|
|
28
|
+
},
|
|
29
|
+
// pytest: "==== 2 failed, 40 passed, 1 skipped in 3.2s ===="
|
|
30
|
+
{
|
|
31
|
+
runner: 'pytest',
|
|
32
|
+
re: /^=+ (.*\b(?:passed|failed)\b.*) in [\d.]+s(?: \([^)]*\))? =+\s*$/m,
|
|
33
|
+
read: (m) => ({ failed: num(/(\d+) failed/.exec(m[1])?.[1]) ?? 0, skipped: num(/(\d+) skipped/.exec(m[1])?.[1]), passed: num(/(\d+) passed/.exec(m[1])?.[1]) ?? 0 }),
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
export function readTestCounts(output) {
|
|
37
|
+
const text = output.replace(ANSI, '');
|
|
38
|
+
let best;
|
|
39
|
+
for (const rule of RULES) {
|
|
40
|
+
const re = new RegExp(rule.re.source, rule.re.flags.includes('g') ? rule.re.flags : `${rule.re.flags}g`);
|
|
41
|
+
let m;
|
|
42
|
+
while ((m = re.exec(text))) {
|
|
43
|
+
if (!best || m.index >= best.at) {
|
|
44
|
+
const counts = Object.fromEntries(Object.entries(rule.read(m)).filter(([, v]) => v !== undefined && !Number.isNaN(v)));
|
|
45
|
+
best = { at: m.index, counts: { ...counts, runner: rule.runner } };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return best?.counts ?? {};
|
|
50
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type AgentClient } from './work.js';
|
|
2
|
+
/**
|
|
3
|
+
* Records what Ductape made or ran on the work it was made for: a Deploy release, deployment or build, or a test run
|
|
4
|
+
* through `ductape work test`. The work tracker finds the item (the one the agent session, or the person in this repo,
|
|
5
|
+
* holds) and checks releases, deployments and builds against Deploy's own records, so nothing here is taken on trust.
|
|
6
|
+
*
|
|
7
|
+
* It never fails the command it follows: the deploy or test has already happened, and a work tracker that cannot be
|
|
8
|
+
* reached is no reason to report it as failed. Set DUCTAPE_WORK_RECORD=off to skip it, or DUCTAPE_WORK_ITEM=W-12 to
|
|
9
|
+
* name the item.
|
|
10
|
+
*/
|
|
11
|
+
export interface IDeliveredArtifact {
|
|
12
|
+
kind: 'release' | 'deployment' | 'build' | 'test_report';
|
|
13
|
+
ref: string;
|
|
14
|
+
url?: string;
|
|
15
|
+
title?: string;
|
|
16
|
+
meta?: Record<string, string | number | boolean>;
|
|
17
|
+
source?: 'ductape_cli';
|
|
18
|
+
}
|
|
19
|
+
export interface IDeliveryResult {
|
|
20
|
+
recorded: string[];
|
|
21
|
+
candidates: string[];
|
|
22
|
+
reason?: string;
|
|
23
|
+
artifact?: {
|
|
24
|
+
kind: string;
|
|
25
|
+
ref: string;
|
|
26
|
+
title: string | null;
|
|
27
|
+
source: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** What to tell the person after recording. Silent when there was no work to record on. */
|
|
31
|
+
export declare function describeDelivery(result: IDeliveryResult, artifact: IDeliveredArtifact): string | undefined;
|
|
32
|
+
export declare function recordOnWork(artifact: IDeliveredArtifact, opts?: {
|
|
33
|
+
item?: string;
|
|
34
|
+
quiet?: boolean;
|
|
35
|
+
client?: AgentClient;
|
|
36
|
+
session?: string;
|
|
37
|
+
}): Promise<IDeliveryResult | undefined>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { WorkClient, resolveClient } from './work.js';
|
|
2
|
+
const FLAG = { release: '--release', deployment: '--deployment', build: '--build', test_report: '--test-report' };
|
|
3
|
+
const note = (message) => process.stderr.write(`${message}\n`);
|
|
4
|
+
/** The agent client this command runs under, when it can tell: DUCTAPE_AGENT_CLIENT, or Claude Code's own marker. */
|
|
5
|
+
function agentClient(env = process.env) {
|
|
6
|
+
try {
|
|
7
|
+
const flagged = resolveClient();
|
|
8
|
+
if (flagged)
|
|
9
|
+
return flagged;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
return env.CLAUDECODE === '1' ? 'claude-code' : undefined;
|
|
15
|
+
}
|
|
16
|
+
/** What to tell the person after recording. Silent when there was no work to record on. */
|
|
17
|
+
export function describeDelivery(result, artifact) {
|
|
18
|
+
const what = `${artifact.kind.replace('_', ' ')} ${result.artifact?.title ?? artifact.ref}`;
|
|
19
|
+
if (result.recorded.length) {
|
|
20
|
+
const how = result.artifact?.source === 'ductape' ? ', checked against Ductape Deploy' : result.artifact?.source === 'ductape_cli' ? ', run by the Ductape CLI' : '';
|
|
21
|
+
return `Recorded ${what} on ${result.recorded.join(', ')}${how}.`;
|
|
22
|
+
}
|
|
23
|
+
if (result.reason === 'ambiguous') {
|
|
24
|
+
const fix = artifact.kind === 'test_report' ? 'Run it again with --item <ref>' : `Record it on one with: ductape work update <ref> ${FLAG[artifact.kind]} ${artifact.ref}`;
|
|
25
|
+
return `Not recorded on any work item: you hold ${result.candidates.join(', ')}. ${fix}`;
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
export async function recordOnWork(artifact, opts = {}) {
|
|
30
|
+
if ((process.env.DUCTAPE_WORK_RECORD ?? '').toLowerCase() === 'off')
|
|
31
|
+
return undefined;
|
|
32
|
+
let work;
|
|
33
|
+
try {
|
|
34
|
+
work = new WorkClient({ client: opts.client ?? agentClient(), session: opts.session });
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return undefined; // not signed in, or no workspace: nothing to record on
|
|
38
|
+
}
|
|
39
|
+
const body = { artifact, repo: work.repo.repo || undefined, item: opts.item ?? process.env.DUCTAPE_WORK_ITEM ?? undefined };
|
|
40
|
+
try {
|
|
41
|
+
let result;
|
|
42
|
+
try {
|
|
43
|
+
result = await work.send('POST', '/deliveries', body);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
// A remembered session that has ended or lapsed: fall back to the repo, as a person would.
|
|
47
|
+
if (!/SESSION_/.test(error instanceof Error ? error.message : String(error)))
|
|
48
|
+
throw error;
|
|
49
|
+
result = await work.send('POST', '/deliveries', body, false);
|
|
50
|
+
}
|
|
51
|
+
const message = describeDelivery(result, artifact);
|
|
52
|
+
if (message && !opts.quiet)
|
|
53
|
+
note(message);
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (!opts.quiet)
|
|
58
|
+
note(`Could not record the ${artifact.kind.replace('_', ' ')} on work: ${error instanceof Error ? error.message : String(error)}`);
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether two path patterns can name the same file: the same conservative rule the work tracker service uses. Two
|
|
3
|
+
* patterns overlap when one fixed prefix (the part before any glob character) starts with the other.
|
|
4
|
+
*/
|
|
5
|
+
export declare function fixedPrefix(pattern: string): string;
|
|
6
|
+
export declare function pathsOverlap(a: string, b: string): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether two path patterns can name the same file: the same conservative rule the work tracker service uses. Two
|
|
3
|
+
* patterns overlap when one fixed prefix (the part before any glob character) starts with the other.
|
|
4
|
+
*/
|
|
5
|
+
export function fixedPrefix(pattern) {
|
|
6
|
+
const clean = pattern.trim().replace(/^\.\//, '').replace(/\\/g, '/');
|
|
7
|
+
const star = clean.search(/[*?[{]/);
|
|
8
|
+
return star === -1 ? clean : clean.slice(0, star);
|
|
9
|
+
}
|
|
10
|
+
export function pathsOverlap(a, b) {
|
|
11
|
+
const pa = fixedPrefix(a);
|
|
12
|
+
const pb = fixedPrefix(b);
|
|
13
|
+
if (!pa || !pb)
|
|
14
|
+
return true;
|
|
15
|
+
return pa.startsWith(pb) || pb.startsWith(pa);
|
|
16
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type WorkspaceContext } from './workspace-context.js';
|
|
2
|
+
/**
|
|
3
|
+
* Client for the work tracker (/tickets/v1/work). Every call carries the signed-in person's credentials and the
|
|
4
|
+
* active workspace. Agent calls also carry a session id: the agent's session is remembered per repo and client in
|
|
5
|
+
* ~/.ductape/work-sessions.json, so a later command in the same repo picks it up.
|
|
6
|
+
*/
|
|
7
|
+
export declare const AGENT_CLIENTS: readonly ["claude-code", "codex", "cursor", "other"];
|
|
8
|
+
export type AgentClient = (typeof AGENT_CLIENTS)[number];
|
|
9
|
+
export interface RepoInfo {
|
|
10
|
+
repo: string;
|
|
11
|
+
branch?: string;
|
|
12
|
+
root?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Normalises a git remote to host/owner/name, so SSH and HTTPS remotes of one repo match. */
|
|
15
|
+
export declare function normaliseRemote(remote: string): string;
|
|
16
|
+
/** The repo the command runs in: its origin remote (or folder name), branch and root. */
|
|
17
|
+
export declare function detectRepo(cwd?: string): RepoInfo;
|
|
18
|
+
/** The agent client this command speaks for: --client, then DUCTAPE_AGENT_CLIENT. None means a person. */
|
|
19
|
+
export declare function resolveClient(flag?: string): AgentClient | undefined;
|
|
20
|
+
export declare function rememberSession(workspaceId: string, repo: string, client: string, session: {
|
|
21
|
+
id: string;
|
|
22
|
+
agent_id: string;
|
|
23
|
+
started_at: string;
|
|
24
|
+
}, conversation?: string): void;
|
|
25
|
+
export declare function forgetSession(workspaceId: string, repo: string, client: string, conversation?: string): void;
|
|
26
|
+
/** The remembered session. With a conversation id, only that conversation's: never another window's. */
|
|
27
|
+
export declare function savedSession(workspaceId: string, repo: string, client: string, conversation?: string): string | undefined;
|
|
28
|
+
export interface WorkCallOptions {
|
|
29
|
+
/** An explicit session id (--session or DUCTAPE_WORK_SESSION). */
|
|
30
|
+
session?: string;
|
|
31
|
+
/** The agent client, when the caller is an agent. */
|
|
32
|
+
client?: AgentClient;
|
|
33
|
+
/** The agent's own conversation id (from its hook input), so each window keeps its own session. */
|
|
34
|
+
conversation?: string;
|
|
35
|
+
}
|
|
36
|
+
export declare class WorkClient {
|
|
37
|
+
readonly ctx: WorkspaceContext;
|
|
38
|
+
readonly repo: RepoInfo;
|
|
39
|
+
readonly client?: AgentClient;
|
|
40
|
+
private readonly api;
|
|
41
|
+
private readonly session?;
|
|
42
|
+
private readonly conversation?;
|
|
43
|
+
constructor(opts?: WorkCallOptions, ctx?: WorkspaceContext);
|
|
44
|
+
/** The product of the linked Ductape project (ductape/config.json), used when a command names none. */
|
|
45
|
+
get linkedProduct(): string | undefined;
|
|
46
|
+
/** The product a command is for: the one it names, or the linked project's. */
|
|
47
|
+
product(flag?: string): string | undefined;
|
|
48
|
+
get sessionId(): string | undefined;
|
|
49
|
+
private auth;
|
|
50
|
+
private headers;
|
|
51
|
+
get<T>(p: string, query?: Record<string, unknown>, withSession?: boolean): Promise<T>;
|
|
52
|
+
send<T>(method: 'POST' | 'PATCH' | 'PUT' | 'DELETE', p: string, body?: Record<string, unknown>, withSession?: boolean): Promise<T>;
|
|
53
|
+
private grant?;
|
|
54
|
+
private stepUp;
|
|
55
|
+
/** Starts an agent session for this repo and remembers it for later commands. */
|
|
56
|
+
startSession(input: {
|
|
57
|
+
client: AgentClient;
|
|
58
|
+
name?: string;
|
|
59
|
+
product?: string;
|
|
60
|
+
machine?: string;
|
|
61
|
+
via?: 'mcp' | 'hook' | 'cli';
|
|
62
|
+
}): Promise<any>;
|
|
63
|
+
endSession(summary?: string): Promise<unknown>;
|
|
64
|
+
}
|
|
65
|
+
/** Whether a refusal asks for a step-up code. */
|
|
66
|
+
export declare function isStepUpRequired(error: unknown): boolean;
|
|
67
|
+
/** Splits a comma-separated flag into a list; undefined stays undefined. */
|
|
68
|
+
export declare const list: (value?: string | string[]) => string[] | undefined;
|