@agentuity/cli 1.0.36 → 1.0.37
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/dist/cmd/cloud/sandbox/cp.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/cp.js +31 -0
- package/dist/cmd/cloud/sandbox/cp.js.map +1 -1
- package/dist/cmd/cloud/sandbox/exec.d.ts.map +1 -1
- package/dist/cmd/cloud/sandbox/exec.js +44 -11
- package/dist/cmd/cloud/sandbox/exec.js.map +1 -1
- package/dist/cmd/cloud/task/get.d.ts.map +1 -1
- package/dist/cmd/cloud/task/get.js +58 -4
- package/dist/cmd/cloud/task/get.js.map +1 -1
- package/dist/cmd/cloud/task/util.d.ts +1 -0
- package/dist/cmd/cloud/task/util.d.ts.map +1 -1
- package/dist/cmd/cloud/task/util.js +13 -0
- package/dist/cmd/cloud/task/util.js.map +1 -1
- package/dist/cmd/coder/hub-url.d.ts +35 -0
- package/dist/cmd/coder/hub-url.d.ts.map +1 -0
- package/dist/cmd/coder/hub-url.js +101 -0
- package/dist/cmd/coder/hub-url.js.map +1 -0
- package/dist/cmd/coder/index.d.ts +2 -0
- package/dist/cmd/coder/index.d.ts.map +1 -0
- package/dist/cmd/coder/index.js +27 -0
- package/dist/cmd/coder/index.js.map +1 -0
- package/dist/cmd/coder/inspect.d.ts +2 -0
- package/dist/cmd/coder/inspect.d.ts.map +1 -0
- package/dist/cmd/coder/inspect.js +145 -0
- package/dist/cmd/coder/inspect.js.map +1 -0
- package/dist/cmd/coder/list.d.ts +2 -0
- package/dist/cmd/coder/list.d.ts.map +1 -0
- package/dist/cmd/coder/list.js +109 -0
- package/dist/cmd/coder/list.js.map +1 -0
- package/dist/cmd/coder/start.d.ts +2 -0
- package/dist/cmd/coder/start.d.ts.map +1 -0
- package/dist/cmd/coder/start.js +384 -0
- package/dist/cmd/coder/start.js.map +1 -0
- package/dist/cmd/dev/index.d.ts.map +1 -1
- package/dist/cmd/dev/index.js +4 -0
- package/dist/cmd/dev/index.js.map +1 -1
- package/dist/cmd/index.d.ts.map +1 -1
- package/dist/cmd/index.js +1 -0
- package/dist/cmd/index.js.map +1 -1
- package/package.json +6 -6
- package/src/cmd/cloud/sandbox/cp.ts +32 -0
- package/src/cmd/cloud/sandbox/exec.ts +62 -13
- package/src/cmd/cloud/task/get.ts +68 -4
- package/src/cmd/cloud/task/util.ts +18 -0
- package/src/cmd/coder/hub-url.ts +105 -0
- package/src/cmd/coder/index.ts +27 -0
- package/src/cmd/coder/inspect.ts +200 -0
- package/src/cmd/coder/list.ts +143 -0
- package/src/cmd/coder/start.ts +419 -0
- package/src/cmd/dev/index.ts +5 -0
- package/src/cmd/index.ts +1 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createSubcommand } from '../../types';
|
|
3
|
+
import * as tui from '../../tui';
|
|
4
|
+
import { getCommand } from '../../command-prefix';
|
|
5
|
+
import { ErrorCode } from '../../errors';
|
|
6
|
+
import { resolveHubUrl, hubFetchHeaders } from './hub-url';
|
|
7
|
+
|
|
8
|
+
function formatRelativeTime(isoDate: string): string {
|
|
9
|
+
const diffMs = Date.now() - new Date(isoDate).getTime();
|
|
10
|
+
const seconds = Math.floor(diffMs / 1000);
|
|
11
|
+
if (seconds < 60) return `${seconds}s ago`;
|
|
12
|
+
const minutes = Math.floor(seconds / 60);
|
|
13
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
14
|
+
const hours = Math.floor(minutes / 60);
|
|
15
|
+
if (hours < 24) return `${hours}h ago`;
|
|
16
|
+
const days = Math.floor(hours / 24);
|
|
17
|
+
return `${days}d ago`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function formatDuration(ms: number): string {
|
|
21
|
+
const seconds = Math.floor(ms / 1000);
|
|
22
|
+
if (seconds < 60) return `${seconds}s`;
|
|
23
|
+
const minutes = Math.floor(seconds / 60);
|
|
24
|
+
const remainSec = seconds % 60;
|
|
25
|
+
if (minutes < 60) return `${minutes}m ${remainSec}s`;
|
|
26
|
+
const hours = Math.floor(minutes / 60);
|
|
27
|
+
const remainMin = minutes % 60;
|
|
28
|
+
return `${hours}h ${remainMin}m`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const inspectSubcommand = createSubcommand({
|
|
32
|
+
name: 'inspect',
|
|
33
|
+
description: 'Show detailed information about a Coder Hub session',
|
|
34
|
+
tags: ['read-only', 'fast', 'requires-auth'],
|
|
35
|
+
examples: [
|
|
36
|
+
{
|
|
37
|
+
command: getCommand('coder inspect codesess_abc123'),
|
|
38
|
+
description: 'Inspect a session by ID',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
command: getCommand('coder inspect codesess_abc123 --json'),
|
|
42
|
+
description: 'Get session details as JSON',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
idempotent: true,
|
|
46
|
+
schema: {
|
|
47
|
+
args: z.object({
|
|
48
|
+
session_id: z.string().describe('Coder session ID to inspect'),
|
|
49
|
+
}),
|
|
50
|
+
options: z.object({
|
|
51
|
+
hubUrl: z.string().optional().describe('Hub URL override'),
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
async handler(ctx) {
|
|
55
|
+
const { args, options, opts } = ctx;
|
|
56
|
+
const sessionId = args.session_id;
|
|
57
|
+
const hubUrl = await resolveHubUrl(opts?.hubUrl);
|
|
58
|
+
|
|
59
|
+
if (!hubUrl) {
|
|
60
|
+
tui.fatal(
|
|
61
|
+
'Could not find a running Coder Hub.\n\nEither:\n - Start the Hub with: bun run dev\n - Set AGENTUITY_CODER_HUB_URL environment variable\n - Pass --hub-url flag',
|
|
62
|
+
ErrorCode.NETWORK_ERROR
|
|
63
|
+
);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let data: {
|
|
68
|
+
sessionId: string;
|
|
69
|
+
label: string;
|
|
70
|
+
status: string;
|
|
71
|
+
createdAt: string;
|
|
72
|
+
mode: string;
|
|
73
|
+
context: {
|
|
74
|
+
branch?: string;
|
|
75
|
+
workingDirectory?: string;
|
|
76
|
+
};
|
|
77
|
+
participants: Array<{
|
|
78
|
+
id: string;
|
|
79
|
+
role: string;
|
|
80
|
+
transport: string;
|
|
81
|
+
connectedAt: string;
|
|
82
|
+
idle: boolean;
|
|
83
|
+
}>;
|
|
84
|
+
tasks: Array<{
|
|
85
|
+
taskId: string;
|
|
86
|
+
agent: string;
|
|
87
|
+
status: string;
|
|
88
|
+
prompt: string;
|
|
89
|
+
duration?: number;
|
|
90
|
+
startedAt: string;
|
|
91
|
+
completedAt?: string;
|
|
92
|
+
}>;
|
|
93
|
+
agentActivity: Record<
|
|
94
|
+
string,
|
|
95
|
+
{
|
|
96
|
+
name: string;
|
|
97
|
+
status: string;
|
|
98
|
+
currentTool?: string;
|
|
99
|
+
toolCallCount: number;
|
|
100
|
+
lastActivity: number;
|
|
101
|
+
}
|
|
102
|
+
>;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const resp = await fetch(`${hubUrl}/api/hub/session/${encodeURIComponent(sessionId)}`, {
|
|
107
|
+
headers: hubFetchHeaders(),
|
|
108
|
+
signal: AbortSignal.timeout(10_000),
|
|
109
|
+
});
|
|
110
|
+
if (resp.status === 404) {
|
|
111
|
+
tui.fatal(`Session not found: ${sessionId}`, ErrorCode.RESOURCE_NOT_FOUND);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (resp.status === 410) {
|
|
115
|
+
tui.fatal(`Session has shut down: ${sessionId}`, ErrorCode.RESOURCE_NOT_FOUND);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (!resp.ok) {
|
|
119
|
+
tui.fatal(
|
|
120
|
+
`Hub returned ${resp.status}: ${resp.statusText}. Is the Coder Hub running at ${hubUrl}?`,
|
|
121
|
+
ErrorCode.API_ERROR
|
|
122
|
+
);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
data = (await resp.json()) as typeof data;
|
|
126
|
+
} catch (err) {
|
|
127
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
128
|
+
tui.fatal(
|
|
129
|
+
`Could not connect to Coder Hub at ${hubUrl}: ${msg}\n\nSet AGENTUITY_CODER_HUB_URL or start the Hub with: bun run dev`,
|
|
130
|
+
ErrorCode.NETWORK_ERROR
|
|
131
|
+
);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (options.json) {
|
|
136
|
+
return data;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Header
|
|
140
|
+
const label = data.label || data.sessionId;
|
|
141
|
+
console.log();
|
|
142
|
+
console.log(` Session: ${label} (${data.sessionId})`);
|
|
143
|
+
const parts = [`Status: ${data.status}`, `Mode: ${data.mode}`];
|
|
144
|
+
if (data.context.branch) parts.push(`Branch: ${data.context.branch}`);
|
|
145
|
+
console.log(` ${parts.join(' | ')}`);
|
|
146
|
+
console.log(` Created: ${data.createdAt}`);
|
|
147
|
+
|
|
148
|
+
// Participants
|
|
149
|
+
console.log();
|
|
150
|
+
console.log(' Participants:');
|
|
151
|
+
if (data.participants.length === 0) {
|
|
152
|
+
console.log(' (none)');
|
|
153
|
+
} else {
|
|
154
|
+
for (const p of data.participants) {
|
|
155
|
+
const idle = p.idle ? ' (idle)' : '';
|
|
156
|
+
const connected = p.connectedAt
|
|
157
|
+
? ` connected ${formatRelativeTime(p.connectedAt)}`
|
|
158
|
+
: '';
|
|
159
|
+
console.log(
|
|
160
|
+
` ${p.id.padEnd(12)} ${p.role.padEnd(10)} ${p.transport}${connected}${idle}`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Tasks
|
|
166
|
+
if (data.tasks.length > 0) {
|
|
167
|
+
console.log();
|
|
168
|
+
console.log(' Tasks:');
|
|
169
|
+
for (const t of data.tasks) {
|
|
170
|
+
const dur = t.duration ? formatDuration(t.duration) : '-';
|
|
171
|
+
const prompt = t.prompt.length > 40 ? t.prompt.slice(0, 37) + '...' : t.prompt;
|
|
172
|
+
console.log(
|
|
173
|
+
` ${t.taskId.padEnd(10)} ${t.agent.padEnd(10)} ${t.status.padEnd(10)} ${prompt.padEnd(42)} ${dur}`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Agent Activity
|
|
179
|
+
const agents = Object.values(data.agentActivity);
|
|
180
|
+
if (agents.length > 0) {
|
|
181
|
+
console.log();
|
|
182
|
+
console.log(' Agent Activity:');
|
|
183
|
+
for (const a of agents) {
|
|
184
|
+
const tool = a.currentTool
|
|
185
|
+
? `${a.currentTool} (${a.toolCallCount} calls)`
|
|
186
|
+
: `${a.toolCallCount} calls`;
|
|
187
|
+
const lastAct = a.lastActivity
|
|
188
|
+
? formatRelativeTime(new Date(a.lastActivity).toISOString())
|
|
189
|
+
: '-';
|
|
190
|
+
console.log(
|
|
191
|
+
` ${a.name.padEnd(12)} ${a.status.padEnd(8)} ${tool.padEnd(28)} last: ${lastAct}`
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
console.log();
|
|
197
|
+
|
|
198
|
+
return data;
|
|
199
|
+
},
|
|
200
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createSubcommand } from '../../types';
|
|
3
|
+
import * as tui from '../../tui';
|
|
4
|
+
import { getCommand } from '../../command-prefix';
|
|
5
|
+
import { ErrorCode } from '../../errors';
|
|
6
|
+
import { resolveHubUrl, hubFetchHeaders } from './hub-url';
|
|
7
|
+
|
|
8
|
+
function formatRelativeTime(isoDate: string): string {
|
|
9
|
+
const diffMs = Date.now() - new Date(isoDate).getTime();
|
|
10
|
+
const seconds = Math.floor(diffMs / 1000);
|
|
11
|
+
if (seconds < 60) return `${seconds}s ago`;
|
|
12
|
+
const minutes = Math.floor(seconds / 60);
|
|
13
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
14
|
+
const hours = Math.floor(minutes / 60);
|
|
15
|
+
if (hours < 24) return `${hours}h ago`;
|
|
16
|
+
const days = Math.floor(hours / 24);
|
|
17
|
+
return `${days}d ago`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const SessionListResponseSchema = z.array(
|
|
21
|
+
z.object({
|
|
22
|
+
sessionId: z.string().describe('Session ID'),
|
|
23
|
+
label: z.string().describe('Human-readable session label'),
|
|
24
|
+
status: z.string().describe('Session status'),
|
|
25
|
+
mode: z.string().describe('Session mode (sandbox or tui)'),
|
|
26
|
+
createdAt: z.string().describe('Creation timestamp'),
|
|
27
|
+
taskCount: z.number().describe('Number of tasks'),
|
|
28
|
+
subAgentCount: z.number().describe('Number of sub-agents'),
|
|
29
|
+
observerCount: z.number().describe('Number of observers'),
|
|
30
|
+
participantCount: z.number().describe('Total participant count'),
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export const listSubcommand = createSubcommand({
|
|
35
|
+
name: 'list',
|
|
36
|
+
description: 'List active Coder Hub sessions',
|
|
37
|
+
tags: ['read-only', 'fast', 'requires-auth'],
|
|
38
|
+
examples: [
|
|
39
|
+
{
|
|
40
|
+
command: getCommand('coder ls'),
|
|
41
|
+
description: 'List all active sessions',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
command: getCommand('coder list --json'),
|
|
45
|
+
description: 'List sessions as JSON',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
aliases: ['ls'],
|
|
49
|
+
idempotent: true,
|
|
50
|
+
schema: {
|
|
51
|
+
options: z.object({
|
|
52
|
+
hubUrl: z.string().optional().describe('Hub URL override'),
|
|
53
|
+
}),
|
|
54
|
+
response: SessionListResponseSchema,
|
|
55
|
+
},
|
|
56
|
+
async handler(ctx) {
|
|
57
|
+
const { options, opts } = ctx;
|
|
58
|
+
const hubUrl = await resolveHubUrl(opts?.hubUrl);
|
|
59
|
+
|
|
60
|
+
if (!hubUrl) {
|
|
61
|
+
tui.fatal(
|
|
62
|
+
'Could not find a running Coder Hub.\n\nEither:\n - Start the Hub with: bun run dev\n - Set AGENTUITY_CODER_HUB_URL environment variable\n - Pass --hub-url flag',
|
|
63
|
+
ErrorCode.NETWORK_ERROR
|
|
64
|
+
);
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let data: {
|
|
69
|
+
sessions: {
|
|
70
|
+
websocket: Array<{
|
|
71
|
+
sessionId: string;
|
|
72
|
+
label: string;
|
|
73
|
+
status: string;
|
|
74
|
+
mode: string;
|
|
75
|
+
createdAt: string;
|
|
76
|
+
taskCount: number;
|
|
77
|
+
subAgentCount: number;
|
|
78
|
+
observerCount: number;
|
|
79
|
+
participantCount: number;
|
|
80
|
+
}>;
|
|
81
|
+
sandbox: Array<Record<string, unknown>>;
|
|
82
|
+
};
|
|
83
|
+
total: number;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const resp = await fetch(`${hubUrl}/api/hub/sessions`, {
|
|
88
|
+
headers: hubFetchHeaders(),
|
|
89
|
+
signal: AbortSignal.timeout(10_000),
|
|
90
|
+
});
|
|
91
|
+
if (!resp.ok) {
|
|
92
|
+
tui.fatal(
|
|
93
|
+
`Hub returned ${resp.status}: ${resp.statusText}. Is the Coder Hub running at ${hubUrl}?`,
|
|
94
|
+
ErrorCode.API_ERROR
|
|
95
|
+
);
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
data = (await resp.json()) as typeof data;
|
|
99
|
+
} catch (err) {
|
|
100
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
101
|
+
tui.fatal(
|
|
102
|
+
`Could not connect to Coder Hub at ${hubUrl}: ${msg}\n\nSet AGENTUITY_CODER_HUB_URL or start the Hub with: bun run dev`,
|
|
103
|
+
ErrorCode.NETWORK_ERROR
|
|
104
|
+
);
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const sessions = data.sessions.websocket;
|
|
109
|
+
|
|
110
|
+
if (options.json) {
|
|
111
|
+
return sessions;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (sessions.length === 0) {
|
|
115
|
+
tui.info('No active Coder Hub sessions.');
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const tableData = sessions.map((s) => ({
|
|
120
|
+
'Session ID': s.sessionId.length > 20 ? s.sessionId.slice(0, 17) + '...' : s.sessionId,
|
|
121
|
+
Label: s.label || '-',
|
|
122
|
+
Status: s.status,
|
|
123
|
+
Mode: s.mode,
|
|
124
|
+
Observers: String(s.observerCount),
|
|
125
|
+
Agents: String(s.subAgentCount),
|
|
126
|
+
Tasks: String(s.taskCount),
|
|
127
|
+
Created: formatRelativeTime(s.createdAt),
|
|
128
|
+
}));
|
|
129
|
+
|
|
130
|
+
tui.table(tableData, [
|
|
131
|
+
{ name: 'Session ID', alignment: 'left' },
|
|
132
|
+
{ name: 'Label', alignment: 'left' },
|
|
133
|
+
{ name: 'Status', alignment: 'center' },
|
|
134
|
+
{ name: 'Mode', alignment: 'center' },
|
|
135
|
+
{ name: 'Observers', alignment: 'right' },
|
|
136
|
+
{ name: 'Agents', alignment: 'right' },
|
|
137
|
+
{ name: 'Tasks', alignment: 'right' },
|
|
138
|
+
{ name: 'Created', alignment: 'right' },
|
|
139
|
+
]);
|
|
140
|
+
|
|
141
|
+
return sessions;
|
|
142
|
+
},
|
|
143
|
+
});
|