@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,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;
|
package/dist/lib/work.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import readline from 'node:readline';
|
|
6
|
+
import { ApiClient } from './api-client.js';
|
|
7
|
+
import { GLOBAL_DIR, findProjectConfig } from './config.js';
|
|
8
|
+
import { requireWorkspaceContext } from './workspace-context.js';
|
|
9
|
+
/**
|
|
10
|
+
* Client for the work tracker (/tickets/v1/work). Every call carries the signed-in person's credentials and the
|
|
11
|
+
* active workspace. Agent calls also carry a session id: the agent's session is remembered per repo and client in
|
|
12
|
+
* ~/.ductape/work-sessions.json, so a later command in the same repo picks it up.
|
|
13
|
+
*/
|
|
14
|
+
export const AGENT_CLIENTS = ['claude-code', 'codex', 'cursor', 'other'];
|
|
15
|
+
const SESSIONS_PATH = path.join(GLOBAL_DIR, 'work-sessions.json');
|
|
16
|
+
function git(args, cwd) {
|
|
17
|
+
try {
|
|
18
|
+
return execFileSync('git', args, { cwd, stdio: ['ignore', 'pipe', 'ignore'], encoding: 'utf8' }).trim() || undefined;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Normalises a git remote to host/owner/name, so SSH and HTTPS remotes of one repo match. */
|
|
25
|
+
export function normaliseRemote(remote) {
|
|
26
|
+
let r = remote.trim().replace(/\.git$/, '').replace(/\/$/, '');
|
|
27
|
+
const scp = /^[\w.-]+@([\w.-]+):(.+)$/.exec(r);
|
|
28
|
+
if (scp)
|
|
29
|
+
r = `${scp[1]}/${scp[2]}`;
|
|
30
|
+
r = r.replace(/^[a-z+]+:\/\//i, '').replace(/^[^@/]+@/, '');
|
|
31
|
+
return r.toLowerCase();
|
|
32
|
+
}
|
|
33
|
+
/** The repo the command runs in: its origin remote (or folder name), branch and root. */
|
|
34
|
+
export function detectRepo(cwd = process.cwd()) {
|
|
35
|
+
const root = git(['rev-parse', '--show-toplevel'], cwd);
|
|
36
|
+
if (!root)
|
|
37
|
+
return { repo: '' };
|
|
38
|
+
const remote = git(['config', '--get', 'remote.origin.url'], root);
|
|
39
|
+
const branch = git(['rev-parse', '--abbrev-ref', 'HEAD'], root);
|
|
40
|
+
return { repo: remote ? normaliseRemote(remote) : `local/${path.basename(root)}`, branch: branch === 'HEAD' ? undefined : branch, root };
|
|
41
|
+
}
|
|
42
|
+
/** The agent client this command speaks for: --client, then DUCTAPE_AGENT_CLIENT. None means a person. */
|
|
43
|
+
export function resolveClient(flag) {
|
|
44
|
+
const value = (flag ?? process.env.DUCTAPE_AGENT_CLIENT ?? '').trim().toLowerCase();
|
|
45
|
+
if (!value)
|
|
46
|
+
return undefined;
|
|
47
|
+
if (!AGENT_CLIENTS.includes(value)) {
|
|
48
|
+
throw new Error(`Unknown agent client "${value}". Use one of: ${AGENT_CLIENTS.join(', ')}.`);
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Sessions are remembered per workspace, repo and client, and, when the agent's own conversation id is known (hooks
|
|
54
|
+
* receive it), per conversation too: two windows of one agent in one repo then keep separate work sessions.
|
|
55
|
+
*/
|
|
56
|
+
const sessionKey = (workspaceId, repo, client, conversation) => `${workspaceId}|${repo}|${client}${conversation ? `|${conversation}` : ''}`;
|
|
57
|
+
const KEEP_MS = 14 * 24 * 60 * 60 * 1000;
|
|
58
|
+
function readSessions() {
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(fs.readFileSync(SESSIONS_PATH, 'utf8'));
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return {};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function writeSessions(map) {
|
|
67
|
+
// Conversations come and go; entries older than two weeks are dropped so the file does not grow forever.
|
|
68
|
+
const cutoff = Date.now() - KEEP_MS;
|
|
69
|
+
const kept = Object.fromEntries(Object.entries(map).filter(([, v]) => !(Date.parse(v.started_at) < cutoff)));
|
|
70
|
+
fs.mkdirSync(GLOBAL_DIR, { recursive: true });
|
|
71
|
+
fs.writeFileSync(SESSIONS_PATH, JSON.stringify(kept, null, 2), { mode: 0o600 });
|
|
72
|
+
}
|
|
73
|
+
export function rememberSession(workspaceId, repo, client, session, conversation) {
|
|
74
|
+
const map = readSessions();
|
|
75
|
+
const entry = { session_id: session.id, agent_id: session.agent_id, workspace_id: workspaceId, started_at: session.started_at };
|
|
76
|
+
map[sessionKey(workspaceId, repo, client)] = entry;
|
|
77
|
+
if (conversation)
|
|
78
|
+
map[sessionKey(workspaceId, repo, client, conversation)] = entry;
|
|
79
|
+
writeSessions(map);
|
|
80
|
+
}
|
|
81
|
+
export function forgetSession(workspaceId, repo, client, conversation) {
|
|
82
|
+
const map = readSessions();
|
|
83
|
+
const base = sessionKey(workspaceId, repo, client);
|
|
84
|
+
if (conversation) {
|
|
85
|
+
const own = map[sessionKey(workspaceId, repo, client, conversation)]?.session_id;
|
|
86
|
+
delete map[sessionKey(workspaceId, repo, client, conversation)];
|
|
87
|
+
// The repo-wide entry goes too only when it is this conversation's session.
|
|
88
|
+
if (own && map[base]?.session_id === own)
|
|
89
|
+
delete map[base];
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
delete map[base];
|
|
93
|
+
}
|
|
94
|
+
writeSessions(map);
|
|
95
|
+
}
|
|
96
|
+
/** The remembered session. With a conversation id, only that conversation's: never another window's. */
|
|
97
|
+
export function savedSession(workspaceId, repo, client, conversation) {
|
|
98
|
+
return readSessions()[sessionKey(workspaceId, repo, client, conversation)]?.session_id;
|
|
99
|
+
}
|
|
100
|
+
export class WorkClient {
|
|
101
|
+
ctx;
|
|
102
|
+
repo;
|
|
103
|
+
client;
|
|
104
|
+
api;
|
|
105
|
+
session;
|
|
106
|
+
conversation;
|
|
107
|
+
constructor(opts = {}, ctx = requireWorkspaceContext()) {
|
|
108
|
+
this.ctx = ctx;
|
|
109
|
+
this.repo = detectRepo();
|
|
110
|
+
this.client = opts.client;
|
|
111
|
+
this.api = new ApiClient(ctx.apiUrl, ctx.credentials.auth_token);
|
|
112
|
+
this.conversation = opts.conversation;
|
|
113
|
+
this.session = opts.session ?? process.env.DUCTAPE_WORK_SESSION ?? (opts.client ? savedSession(ctx.workspaceId, this.repo.repo, opts.client, opts.conversation) : undefined);
|
|
114
|
+
}
|
|
115
|
+
/** The product of the linked Ductape project (ductape/config.json), used when a command names none. */
|
|
116
|
+
get linkedProduct() {
|
|
117
|
+
try {
|
|
118
|
+
return findProjectConfig()?.config?.product_tag || undefined;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** The product a command is for: the one it names, or the linked project's. */
|
|
125
|
+
product(flag) {
|
|
126
|
+
return flag || this.linkedProduct;
|
|
127
|
+
}
|
|
128
|
+
get sessionId() {
|
|
129
|
+
return this.session;
|
|
130
|
+
}
|
|
131
|
+
auth() {
|
|
132
|
+
return { user_id: this.ctx.credentials.user_id, public_key: this.ctx.credentials.public_key, workspace_id: this.ctx.workspaceId };
|
|
133
|
+
}
|
|
134
|
+
headers(withSession) {
|
|
135
|
+
return withSession && this.session ? { 'x-ductape-session': this.session } : {};
|
|
136
|
+
}
|
|
137
|
+
async get(p, query = {}, withSession = true) {
|
|
138
|
+
const params = new URLSearchParams();
|
|
139
|
+
for (const [k, v] of Object.entries({ ...query, ...this.auth() }))
|
|
140
|
+
if (v !== undefined && v !== null && v !== '')
|
|
141
|
+
params.set(k, String(v));
|
|
142
|
+
return this.api.request('GET', `/tickets/v1/work${p}?${params}`, undefined, this.headers(withSession));
|
|
143
|
+
}
|
|
144
|
+
async send(method, p, body = {}, withSession = true) {
|
|
145
|
+
const call = () => this.api.request(method, `/tickets/v1/work${p}`, { ...body, ...this.auth() }, { ...this.headers(withSession), ...(this.grant ? { 'x-ductape-grant': this.grant } : {}) });
|
|
146
|
+
try {
|
|
147
|
+
return await call();
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
if (!isStepUpRequired(error) || this.grant)
|
|
151
|
+
throw error;
|
|
152
|
+
// A change only a person may make: prove it is the person with the code Ductape emails them, then try again.
|
|
153
|
+
// The grant lives only in this process. An agent's shell is not interactive and cannot read the email.
|
|
154
|
+
this.grant = await this.stepUp();
|
|
155
|
+
return call();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
grant;
|
|
159
|
+
async stepUp() {
|
|
160
|
+
if (!process.stdin.isTTY || !process.stderr.isTTY) {
|
|
161
|
+
throw new Error('This change needs a code from your email, so an agent using your sign-in cannot make it. Run the command yourself in your own terminal, or make the change in the Workbench.');
|
|
162
|
+
}
|
|
163
|
+
const started = await this.api.request('POST', '/tickets/v1/work/step-up/start', this.auth(), {});
|
|
164
|
+
if (started?.required === false)
|
|
165
|
+
throw new Error('The server did not ask for a code but refused the change; try again.');
|
|
166
|
+
const code = await promptHidden(`A code was sent to ${started.sent_to}. Enter it to confirm it is you: `);
|
|
167
|
+
const verified = await this.api.request('POST', '/tickets/v1/work/step-up/verify', { ...this.auth(), code: code.trim() }, {});
|
|
168
|
+
process.stderr.write('Confirmed for 15 minutes in this command.\n');
|
|
169
|
+
return verified.grant;
|
|
170
|
+
}
|
|
171
|
+
/** Starts an agent session for this repo and remembers it for later commands. */
|
|
172
|
+
async startSession(input) {
|
|
173
|
+
const res = await this.send('POST', '/sessions', {
|
|
174
|
+
client: input.client,
|
|
175
|
+
// How the agent reached Ductape, and the name its client gave (set by the MCP server from its handshake).
|
|
176
|
+
via: input.via ?? process.env.DUCTAPE_AGENT_VIA ?? 'cli',
|
|
177
|
+
client_name: process.env.DUCTAPE_AGENT_CLIENT_NAME || undefined,
|
|
178
|
+
name: input.name,
|
|
179
|
+
product: this.product(input.product),
|
|
180
|
+
machine: input.machine ?? os.hostname(),
|
|
181
|
+
repo: this.repo.repo,
|
|
182
|
+
branch: this.repo.branch,
|
|
183
|
+
}, false);
|
|
184
|
+
rememberSession(this.ctx.workspaceId, this.repo.repo, input.client, res.session, this.conversation);
|
|
185
|
+
return res;
|
|
186
|
+
}
|
|
187
|
+
async endSession(summary) {
|
|
188
|
+
if (!this.session)
|
|
189
|
+
throw new Error('No agent session to end. Pass --session, or --client for the session started in this repo.');
|
|
190
|
+
const res = await this.send('POST', '/sessions/end', { summary });
|
|
191
|
+
if (this.client)
|
|
192
|
+
forgetSession(this.ctx.workspaceId, this.repo.repo, this.client, this.conversation);
|
|
193
|
+
return res;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/** Whether a refusal asks for a step-up code. */
|
|
197
|
+
export function isStepUpRequired(error) {
|
|
198
|
+
const e = error;
|
|
199
|
+
return /STEP_UP_REQUIRED/.test(String(e?.message ?? '')) || e?.details?.code === 'STEP_UP_REQUIRED';
|
|
200
|
+
}
|
|
201
|
+
/** Reads one line from the terminal. */
|
|
202
|
+
function promptHidden(question) {
|
|
203
|
+
return new Promise((resolve) => {
|
|
204
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stderr, terminal: true });
|
|
205
|
+
rl.question(question, (answer) => {
|
|
206
|
+
rl.close();
|
|
207
|
+
resolve(answer);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/** Splits a comma-separated flag into a list; undefined stays undefined. */
|
|
212
|
+
export const list = (value) => {
|
|
213
|
+
if (value === undefined)
|
|
214
|
+
return undefined;
|
|
215
|
+
const parts = (Array.isArray(value) ? value : [value]).flatMap((v) => v.split(','));
|
|
216
|
+
return parts.map((s) => s.trim()).filter(Boolean);
|
|
217
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ductape/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Ductape CLI — local platform, login, link projects, and manage resources via the proxy (Workbench-compatible)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,8 +18,7 @@
|
|
|
18
18
|
"build": "tsc",
|
|
19
19
|
"dev": "tsx src/index.ts",
|
|
20
20
|
"test": "npm run build && node --import tsx --test test/**/*.test.ts",
|
|
21
|
-
"prepublishOnly": "npm run build"
|
|
22
|
-
"test:ui:e2e": "node --import tsx test/e2e/ui-slice.ts"
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
23
22
|
},
|
|
24
23
|
"keywords": [
|
|
25
24
|
"ductape",
|