@phnx-labs/agents-cli 1.23.42 → 1.23.44
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/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/dist/commands/cloud-transcripts.js +31 -12
- package/dist/commands/cloud.js +6 -17
- package/dist/commands/exec.js +2 -1
- package/dist/lib/agent-modes.js +1 -0
- package/dist/lib/agent-spec/agents.js +1 -1
- package/dist/lib/cloud/dispatch.d.ts +1 -1
- package/dist/lib/cloud/dispatch.js +3 -10
- package/dist/lib/cloud/registry.d.ts +2 -0
- package/dist/lib/cloud/registry.js +7 -1
- package/dist/lib/cloud/rush.d.ts +10 -33
- package/dist/lib/cloud/rush.js +151 -300
- package/dist/lib/cloud/stream.js +8 -6
- package/dist/lib/cloud/types.d.ts +4 -6
- package/dist/lib/cloud/types.js +4 -1
- package/dist/lib/daemon/session-state-service.d.ts +6 -1
- package/dist/lib/daemon/session-state-service.js +38 -1
- package/dist/lib/devices/connect.d.ts +1 -0
- package/dist/lib/devices/connect.js +3 -1
- package/dist/lib/devices/health.d.ts +3 -0
- package/dist/lib/devices/health.js +14 -2
- package/dist/lib/exec.d.ts +1 -1
- package/dist/lib/exec.js +2 -1
- package/dist/lib/github/project-prs.d.ts +1 -0
- package/dist/lib/github/project-prs.js +44 -8
- package/dist/lib/identity/client.d.ts +1 -1
- package/dist/lib/identity/client.js +1 -1
- package/dist/lib/session/discover.d.ts +4 -0
- package/dist/lib/session/discover.js +39 -1
- package/dist/lib/session/presentation.d.ts +3 -0
- package/dist/lib/session/presentation.js +4 -1
- package/dist/lib/ssh-exec.d.ts +2 -0
- package/dist/lib/ssh-exec.js +12 -2
- package/package.json +1 -1
- package/dist/lib/rush-session.d.ts +0 -1
- package/dist/lib/rush-session.js +0 -5
- package/dist/lib/session/cloud.d.ts +0 -5
- package/dist/lib/session/cloud.js +0 -89
package/dist/lib/cloud/rush.js
CHANGED
|
@@ -1,358 +1,209 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import * as os from 'os';
|
|
4
|
-
import * as crypto from 'crypto';
|
|
5
|
-
import * as yaml from 'yaml';
|
|
6
1
|
import { resolveDispatchRepos, normalizeProviderStatus, MAX_IMAGES_PER_DISPATCH } from './types.js';
|
|
7
|
-
import { isRushSessionExpired } from '../rush-session.js';
|
|
8
2
|
import { parseSSE } from './stream.js';
|
|
9
|
-
import {
|
|
10
|
-
import { getAccountInfo } from '../agents.js';
|
|
11
|
-
import { selectBalancedVersion } from '../accounting/rotate.js';
|
|
3
|
+
import { getTaskById } from './store.js';
|
|
12
4
|
import { RUSH_API_BASE } from '../rush-api.js';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
5
|
+
import { readAndResolveBundleEnv } from '../secrets-client.js';
|
|
6
|
+
const KEY_NAME = 'RUSH_API_KEY';
|
|
7
|
+
const ORG_NAME = 'RUSH_ORG';
|
|
8
|
+
const SETUP_HINT = `Create an API key on the Developers page of https://cloud.getrush.ai, store it with ` +
|
|
9
|
+
`\`secrets add getrush.ai ${KEY_NAME}\` and your org with \`secrets add getrush.ai ${ORG_NAME} --value <org>\`, ` +
|
|
10
|
+
`then set cloud.providers.rush.secretsBundle: getrush.ai in ~/.agents/agents.yaml ` +
|
|
11
|
+
`(or run under \`secrets exec getrush.ai --\`).`;
|
|
12
|
+
function credentialFrom(env, source) {
|
|
13
|
+
const apiKey = env[KEY_NAME];
|
|
14
|
+
const org = env[ORG_NAME];
|
|
15
|
+
if (!apiKey || !org) {
|
|
16
|
+
const missing = [!apiKey && KEY_NAME, !org && ORG_NAME].filter(Boolean).join(' and ');
|
|
17
|
+
throw new Error(`Rush Cloud needs ${missing} (${source} has none). ${SETUP_HINT}`);
|
|
18
|
+
}
|
|
19
|
+
return { apiKey, org };
|
|
29
20
|
}
|
|
30
|
-
export function
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
export function buildSessionCreateBody(options) {
|
|
22
|
+
const repos = resolveDispatchRepos(options);
|
|
23
|
+
if (repos.length > 1) {
|
|
24
|
+
throw new Error(`Rush Cloud runs one repository per session; got ${repos.length} (${repos.join(', ')}). Dispatch one per repository.`);
|
|
33
25
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const token = data?.session?.access_token;
|
|
37
|
-
if (!token) {
|
|
38
|
-
throw new Error('No session token in ~/.rush/user.yaml. Run `rush login` first.');
|
|
26
|
+
if (options.branch && repos.length === 0) {
|
|
27
|
+
throw new Error('--branch needs --repo: Rush Cloud starts a branch only inside a repository.');
|
|
39
28
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const expiredAt = new Date(expiresAt).toISOString();
|
|
43
|
-
throw new Error(`Rush session expired at ${expiredAt}. Run \`rush login\` to refresh.`);
|
|
29
|
+
if (options.providerOptions?.mode !== undefined) {
|
|
30
|
+
throw new Error('Rush Cloud has no execution mode; drop --mode and say what you want in the prompt.');
|
|
44
31
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
throw new Error('No Rush organization found for your account. Run `rush login` again.');
|
|
57
|
-
return handle;
|
|
32
|
+
const body = {
|
|
33
|
+
agent: options.agent ?? 'claude',
|
|
34
|
+
input: buildInput(options.prompt, options.images),
|
|
35
|
+
};
|
|
36
|
+
if (options.model)
|
|
37
|
+
body.model = options.model;
|
|
38
|
+
if (options.skills && options.skills.length > 0)
|
|
39
|
+
body.skills = options.skills;
|
|
40
|
+
if (repos.length === 1)
|
|
41
|
+
body.resources = [{ url: repoResourceUrl(repos[0], options.branch) }];
|
|
42
|
+
return body;
|
|
58
43
|
}
|
|
59
|
-
|
|
60
|
-
|
|
44
|
+
function buildInput(prompt, images) {
|
|
45
|
+
if (!images || images.length === 0)
|
|
46
|
+
return prompt;
|
|
47
|
+
return [
|
|
48
|
+
{ type: 'text', text: prompt },
|
|
49
|
+
...images.slice(0, MAX_IMAGES_PER_DISPATCH).map((img) => ({
|
|
50
|
+
type: 'image',
|
|
51
|
+
source: { type: 'base64', media_type: img.mimeType, data: img.data },
|
|
52
|
+
})),
|
|
53
|
+
];
|
|
61
54
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return data?.session?.email;
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
return undefined;
|
|
55
|
+
function repoResourceUrl(full, branch) {
|
|
56
|
+
const parts = full.split('/');
|
|
57
|
+
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
58
|
+
throw new Error(`Invalid repo format: ${JSON.stringify(full)}. Use owner/repo.`);
|
|
70
59
|
}
|
|
60
|
+
const base = `https://github.com/${encodeURIComponent(parts[0])}/${encodeURIComponent(parts[1])}`;
|
|
61
|
+
return branch ? `${base}/tree/${branch.split('/').map(encodeURIComponent).join('/')}` : base;
|
|
71
62
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
'
|
|
76
|
-
|
|
63
|
+
function sessionToTask(s) {
|
|
64
|
+
return {
|
|
65
|
+
id: s.execution_id,
|
|
66
|
+
provider: 'rush',
|
|
67
|
+
status: normalizeProviderStatus('rush', s.status),
|
|
68
|
+
agent: s.harness,
|
|
69
|
+
prompt: getTaskById(s.execution_id)?.prompt ?? '',
|
|
70
|
+
repo: s.repo_owner && s.repo_name ? `${s.repo_owner}/${s.repo_name}` : undefined,
|
|
71
|
+
branch: s.branch,
|
|
72
|
+
prUrl: s.pr_url,
|
|
73
|
+
summary: s.result ?? s.error?.message,
|
|
74
|
+
createdAt: s.created_at,
|
|
75
|
+
updatedAt: s.completed_at ?? s.created_at,
|
|
77
76
|
};
|
|
78
|
-
return fetch(url, {
|
|
79
|
-
method,
|
|
80
|
-
headers,
|
|
81
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
82
|
-
});
|
|
83
77
|
}
|
|
84
|
-
async function
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
throw new Error(`Failed to fetch GitHub installations (${res.status}). Is the Rush GitHub App installed?`);
|
|
88
|
-
}
|
|
89
|
-
const data = await res.json();
|
|
90
|
-
for (const inst of data.installations ?? []) {
|
|
91
|
-
if (inst.account_login?.toLowerCase() === owner.toLowerCase()) {
|
|
92
|
-
if (inst.repository_selection === 'all')
|
|
93
|
-
return inst.id;
|
|
94
|
-
if (inst.repositories?.some(r => r.name.toLowerCase() === repo.toLowerCase())) {
|
|
95
|
-
return inst.id;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
throw new Error(`No GitHub App installation found for ${owner}/${repo}. Install the Rush GitHub App at https://github.com/apps/cloud-bot.`);
|
|
100
|
-
}
|
|
101
|
-
function sha256(input) {
|
|
102
|
-
return crypto.createHash('sha256').update(input).digest('hex');
|
|
103
|
-
}
|
|
104
|
-
function sanitizeErrorBody(body) {
|
|
105
|
-
const MAX_LEN = 300;
|
|
78
|
+
async function rushApiError(action, res) {
|
|
79
|
+
const text = await res.text();
|
|
80
|
+
let detail;
|
|
106
81
|
try {
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
return msg.slice(0, MAX_LEN);
|
|
111
|
-
}
|
|
112
|
-
catch { }
|
|
113
|
-
let safe = body.slice(0, MAX_LEN);
|
|
114
|
-
safe = safe.replace(/eyJ[A-Za-z0-9_-]{20,}/g, '[REDACTED_TOKEN]');
|
|
115
|
-
safe = safe.replace(/Bearer\s+\S+/gi, 'Bearer [REDACTED]');
|
|
116
|
-
safe = safe.replace(/"(access_token|refresh_token|credentials_json)"\s*:\s*"[^"]*"/g, '"$1":"[REDACTED]"');
|
|
117
|
-
if (body.length > MAX_LEN)
|
|
118
|
-
safe += '...';
|
|
119
|
-
return safe;
|
|
120
|
-
}
|
|
121
|
-
function parsePromptCode(body) {
|
|
122
|
-
try {
|
|
123
|
-
const parsed = JSON.parse(body);
|
|
124
|
-
return typeof parsed.prompt_code === 'string' ? parsed.prompt_code : null;
|
|
82
|
+
const body = JSON.parse(text);
|
|
83
|
+
const code = body.code ?? body.error_code;
|
|
84
|
+
detail = `${code ? `${code}: ` : ''}${body.error ?? body.message ?? ''}`;
|
|
125
85
|
}
|
|
126
86
|
catch {
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
async function buildAccountManifest(strategy) {
|
|
131
|
-
let candidateVersions;
|
|
132
|
-
if (strategy === 'balanced') {
|
|
133
|
-
const result = await selectBalancedVersion('claude');
|
|
134
|
-
if (!result || result.healthy.length === 0)
|
|
135
|
-
return null;
|
|
136
|
-
candidateVersions = result.healthy
|
|
137
|
-
.filter((c) => !!c.email)
|
|
138
|
-
.map((c) => ({ version: c.version, email: c.email }));
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
const versions = listInstalledVersions('claude');
|
|
142
|
-
if (versions.length === 0)
|
|
143
|
-
return null;
|
|
144
|
-
const rows = await Promise.all(versions.map(async (version) => {
|
|
145
|
-
const home = getVersionHomePath('claude', version);
|
|
146
|
-
const info = await getAccountInfo('claude', home);
|
|
147
|
-
return info.email ? { version, email: info.email } : null;
|
|
148
|
-
}));
|
|
149
|
-
candidateVersions = rows.filter((r) => r !== null);
|
|
150
|
-
}
|
|
151
|
-
const entries = candidateVersions
|
|
152
|
-
.map(({ version, email }) => ({ version, email }))
|
|
153
|
-
.sort((a, b) => a.version.localeCompare(b.version));
|
|
154
|
-
if (entries.length === 0)
|
|
155
|
-
return null;
|
|
156
|
-
const fp = sha256(JSON.stringify(entries));
|
|
157
|
-
return { fp, versions: entries };
|
|
158
|
-
}
|
|
159
|
-
export function buildDispatchBody(input) {
|
|
160
|
-
if (input.resolvedRepos.length === 0) {
|
|
161
|
-
throw new Error('buildDispatchBody: resolvedRepos must have at least one entry');
|
|
162
|
-
}
|
|
163
|
-
const primary = input.resolvedRepos[0];
|
|
164
|
-
const body = {
|
|
165
|
-
agent: input.agent ?? 'claude',
|
|
166
|
-
prompt: input.prompt,
|
|
167
|
-
repos: input.resolvedRepos,
|
|
168
|
-
mode: input.mode,
|
|
169
|
-
...(input.strategy ? { strategy: input.strategy } : {}),
|
|
170
|
-
};
|
|
171
|
-
if (input.resolvedRepos.length === 1) {
|
|
172
|
-
body.installation_id = primary.installation_id;
|
|
173
|
-
body.repo_owner = primary.repo_owner;
|
|
174
|
-
body.repo_name = primary.repo_name;
|
|
175
|
-
}
|
|
176
|
-
if (input.accountManifest) {
|
|
177
|
-
body.account_manifest = input.accountManifest;
|
|
178
|
-
}
|
|
179
|
-
if (input.skills && input.skills.length > 0) {
|
|
180
|
-
body.skills = input.skills;
|
|
181
|
-
}
|
|
182
|
-
if (input.images && input.images.length > 0) {
|
|
183
|
-
body.images = input.images.slice(0, MAX_IMAGES_PER_DISPATCH);
|
|
87
|
+
detail = text.slice(0, 300).replace(/rk_live_[A-Za-z0-9_-]+/g, '[REDACTED]');
|
|
184
88
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
return body;
|
|
89
|
+
const hint = res.status === 401 ? ` Check ${KEY_NAME}: it may be revoked or expired.` : '';
|
|
90
|
+
return new Error(`Rush Cloud ${action} failed (${res.status}) ${detail}.${hint}`);
|
|
189
91
|
}
|
|
190
92
|
export class RushCloudProvider {
|
|
191
93
|
id = 'rush';
|
|
192
94
|
name = 'Rush Cloud';
|
|
95
|
+
secretsBundle;
|
|
96
|
+
constructor(config) {
|
|
97
|
+
this.secretsBundle = config?.secretsBundle;
|
|
98
|
+
}
|
|
99
|
+
async credential() {
|
|
100
|
+
if (!this.secretsBundle)
|
|
101
|
+
return credentialFrom(process.env, 'the environment');
|
|
102
|
+
let env;
|
|
103
|
+
try {
|
|
104
|
+
({ env } = await readAndResolveBundleEnv(this.secretsBundle, { caller: 'cloud:rush', agentOnly: true }));
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
throw new Error(`Could not read Rush Cloud credentials from bundle '${this.secretsBundle}': ${err.message}`);
|
|
108
|
+
}
|
|
109
|
+
return credentialFrom(env, `bundle '${this.secretsBundle}'`);
|
|
110
|
+
}
|
|
111
|
+
async request(action, path, init = {}) {
|
|
112
|
+
const { apiKey, org } = await this.credential();
|
|
113
|
+
let res;
|
|
114
|
+
try {
|
|
115
|
+
res = await fetch(`${RUSH_API_BASE}/o/${encodeURIComponent(org)}${path}`, {
|
|
116
|
+
...init,
|
|
117
|
+
headers: {
|
|
118
|
+
Authorization: `Bearer ${apiKey}`,
|
|
119
|
+
...(init.body ? { 'Content-Type': 'application/json' } : {}),
|
|
120
|
+
...init.headers,
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
throw new Error(`Rush Cloud ${action} failed (network): ${err.message}`);
|
|
126
|
+
}
|
|
127
|
+
if (!res.ok)
|
|
128
|
+
throw await rushApiError(action, res);
|
|
129
|
+
return res;
|
|
130
|
+
}
|
|
193
131
|
capabilities() {
|
|
194
132
|
return {
|
|
195
|
-
available:
|
|
133
|
+
available: Boolean(this.secretsBundle || process.env[KEY_NAME]),
|
|
196
134
|
dispatch: true,
|
|
197
135
|
status: true,
|
|
198
136
|
list: true,
|
|
199
137
|
stream: true,
|
|
200
138
|
cancel: true,
|
|
201
139
|
message: true,
|
|
202
|
-
multiRepo:
|
|
140
|
+
multiRepo: false,
|
|
203
141
|
skills: true,
|
|
204
142
|
images: true,
|
|
205
143
|
};
|
|
206
144
|
}
|
|
207
145
|
async dispatch(options) {
|
|
146
|
+
const body = buildSessionCreateBody(options);
|
|
208
147
|
const repos = resolveDispatchRepos(options);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const projectKey = repos[0] ?? process.cwd();
|
|
215
|
-
const gate = runPreflightGate({
|
|
216
|
-
agent: options.agent ?? 'cloud',
|
|
217
|
-
model: options.model ?? `${options.agent ?? 'cloud'}-default`,
|
|
218
|
-
prompt: options.prompt,
|
|
219
|
-
project: projectKey,
|
|
220
|
-
});
|
|
221
|
-
if (!gate.dormant && !gate.decision.allow) {
|
|
222
|
-
throw new Error(`[budget] BLOCKED cloud dispatch (${projectKey}): ${gate.decision.reason}`);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
const token = readToken();
|
|
226
|
-
const parsed = repos.map((full) => {
|
|
227
|
-
const parts = full.split('/');
|
|
228
|
-
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
229
|
-
throw new Error(`Invalid repo format: ${JSON.stringify(full)}. Use owner/repo.`);
|
|
230
|
-
}
|
|
231
|
-
return { full, owner: parts[0], name: parts[1] };
|
|
232
|
-
});
|
|
233
|
-
const resolvedRepos = await Promise.all(parsed.map(async (r) => ({
|
|
234
|
-
installation_id: await findInstallation(token, r.owner, r.name),
|
|
235
|
-
repo_owner: r.owner,
|
|
236
|
-
repo_name: r.name,
|
|
237
|
-
})));
|
|
238
|
-
const strategy = options.providerOptions?.strategy;
|
|
239
|
-
const accountManifest = strategy === 'balanced' ? null : await buildAccountManifest();
|
|
240
|
-
const body = buildDispatchBody({
|
|
241
|
-
agent: options.agent,
|
|
148
|
+
const { runPreflightGate } = await import('../budget/preflight.js');
|
|
149
|
+
const projectKey = repos[0] ?? process.cwd();
|
|
150
|
+
const gate = runPreflightGate({
|
|
151
|
+
agent: options.agent ?? 'cloud',
|
|
152
|
+
model: options.model ?? `${options.agent ?? 'cloud'}-default`,
|
|
242
153
|
prompt: options.prompt,
|
|
243
|
-
|
|
244
|
-
resolvedRepos,
|
|
245
|
-
accountManifest,
|
|
246
|
-
strategy,
|
|
247
|
-
skills: options.skills,
|
|
248
|
-
images: options.images,
|
|
249
|
-
env: options.env,
|
|
154
|
+
project: projectKey,
|
|
250
155
|
});
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const errBody = await res.clone().text();
|
|
254
|
-
const promptCode = parsePromptCode(errBody);
|
|
255
|
-
if (promptCode === 'NEW_ACCOUNT' || promptCode === 'TOKEN_ROTATED') {
|
|
256
|
-
throw new Error([
|
|
257
|
-
`Rush Cloud asked to sync your Claude login (reason: ${promptCode.toLowerCase()}), but`,
|
|
258
|
-
`agents-cli never copies a native OAuth / session login off this machine (SING-1b) —`,
|
|
259
|
-
`a rotating token uploaded to the cloud is invalidated on its next refresh.`,
|
|
260
|
-
``,
|
|
261
|
-
`Portable provider accounts can run locally or on a pinned fleet device, but cloud`,
|
|
262
|
-
`placement does not securely inject them yet. Create and sync one with:`,
|
|
263
|
-
` agents accounts add <name> --provider anthropic --auth api-key # or: --auth setup-token`,
|
|
264
|
-
` agents accounts sync <name> <device>`,
|
|
265
|
-
`then run locally or on that device with --account <name>. See docs/secrets.md (SING-1b).`,
|
|
266
|
-
].join('\n'));
|
|
267
|
-
}
|
|
156
|
+
if (!gate.dormant && !gate.decision.allow) {
|
|
157
|
+
throw new Error(`[budget] BLOCKED cloud dispatch (${projectKey}): ${gate.decision.reason}`);
|
|
268
158
|
}
|
|
269
|
-
if (
|
|
270
|
-
|
|
271
|
-
|
|
159
|
+
if (options.env && Object.keys(options.env).length > 0) {
|
|
160
|
+
process.stderr.write(`Rush Cloud takes no per-run environment; not sending ${Object.keys(options.env).join(', ')}. ` +
|
|
161
|
+
`Save it as a Project secret instead (POST /o/{org}/secrets).\n`);
|
|
272
162
|
}
|
|
273
|
-
const
|
|
274
|
-
const
|
|
163
|
+
const res = await this.request('dispatch', '/sessions', { method: 'POST', body: JSON.stringify(body) });
|
|
164
|
+
const session = (await res.json());
|
|
275
165
|
return {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
status: 'queued',
|
|
279
|
-
agent: options.agent ?? 'claude',
|
|
166
|
+
...sessionToTask(session),
|
|
167
|
+
agent: session.harness ?? body.agent,
|
|
280
168
|
prompt: options.prompt,
|
|
281
169
|
repo: repos[0],
|
|
282
|
-
repos: repos,
|
|
170
|
+
repos: repos.length > 0 ? repos : undefined,
|
|
283
171
|
branch: options.branch,
|
|
284
|
-
createdAt: now,
|
|
285
|
-
updatedAt: now,
|
|
286
172
|
};
|
|
287
173
|
}
|
|
288
174
|
async status(taskId) {
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
if (!res.ok) {
|
|
292
|
-
throw new Error(`Failed to get task status (${res.status}).`);
|
|
293
|
-
}
|
|
294
|
-
const data = await res.json();
|
|
295
|
-
return {
|
|
296
|
-
id: taskId,
|
|
297
|
-
provider: 'rush',
|
|
298
|
-
status: normalizeProviderStatus('rush', data.status),
|
|
299
|
-
agent: data.agent || undefined,
|
|
300
|
-
prompt: data.prompt || '',
|
|
301
|
-
repo: data.repo_owner && data.repo_name ? `${data.repo_owner}/${data.repo_name}` : undefined,
|
|
302
|
-
branch: data.branch || undefined,
|
|
303
|
-
prUrl: data.pr_url || undefined,
|
|
304
|
-
summary: data.summary || undefined,
|
|
305
|
-
createdAt: data.created_at || new Date().toISOString(),
|
|
306
|
-
updatedAt: data.updated_at || new Date().toISOString(),
|
|
307
|
-
};
|
|
175
|
+
const res = await this.request('status', `/sessions/${encodeURIComponent(taskId)}`);
|
|
176
|
+
return sessionToTask((await res.json()));
|
|
308
177
|
}
|
|
309
178
|
async list(filter) {
|
|
310
|
-
const
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const qs = params.toString() ? `?${params.toString()}` : '';
|
|
315
|
-
const res = await api('GET', `/api/v1/cloud-runs${qs}`, token);
|
|
316
|
-
if (!res.ok) {
|
|
317
|
-
throw new Error(`Failed to list tasks (${res.status}).`);
|
|
318
|
-
}
|
|
319
|
-
const data = await res.json();
|
|
320
|
-
return (data.executions ?? []).map((e) => ({
|
|
321
|
-
id: e.execution_id,
|
|
322
|
-
provider: 'rush',
|
|
323
|
-
status: normalizeProviderStatus('rush', e.status),
|
|
324
|
-
agent: e.agent || undefined,
|
|
325
|
-
prompt: e.prompt || '',
|
|
326
|
-
repo: e.repo_owner && e.repo_name ? `${e.repo_owner}/${e.repo_name}` : undefined,
|
|
327
|
-
branch: e.branch || undefined,
|
|
328
|
-
prUrl: e.pr_url || undefined,
|
|
329
|
-
summary: e.summary || undefined,
|
|
330
|
-
createdAt: e.created_at || '',
|
|
331
|
-
updatedAt: e.updated_at || '',
|
|
332
|
-
}));
|
|
179
|
+
const res = await this.request('list', '/sessions?limit=100');
|
|
180
|
+
const data = (await res.json());
|
|
181
|
+
const tasks = (data.sessions ?? []).map(sessionToTask);
|
|
182
|
+
return filter?.status ? tasks.filter((t) => t.status === filter.status) : tasks;
|
|
333
183
|
}
|
|
334
184
|
async *stream(taskId) {
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
headers: { 'Authorization': `Bearer ${token}` },
|
|
185
|
+
const res = await this.request('stream', `/sessions/${encodeURIComponent(taskId)}/events`, {
|
|
186
|
+
headers: { Accept: 'text/event-stream' },
|
|
338
187
|
});
|
|
339
|
-
if (!res.ok) {
|
|
340
|
-
throw new Error(`Failed to connect to stream (${res.status}).`);
|
|
341
|
-
}
|
|
342
188
|
yield* parseSSE(res);
|
|
343
189
|
}
|
|
344
190
|
async cancel(taskId) {
|
|
345
|
-
|
|
346
|
-
const res = await api('POST', `/api/v1/cloud-runs/${encodeURIComponent(taskId)}/cancel`, token);
|
|
347
|
-
if (!res.ok) {
|
|
348
|
-
throw new Error(`Failed to cancel task (${res.status}).`);
|
|
349
|
-
}
|
|
191
|
+
await this.request('cancel', `/sessions/${encodeURIComponent(taskId)}/cancel`, { method: 'POST' });
|
|
350
192
|
}
|
|
351
193
|
async message(taskId, content) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
194
|
+
await this.request('message', `/sessions/${encodeURIComponent(taskId)}/messages`, {
|
|
195
|
+
method: 'POST',
|
|
196
|
+
body: JSON.stringify({ input: content }),
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
async transcript(task, agent) {
|
|
200
|
+
const res = await this.request('transcript', `/sessions/${encodeURIComponent(task.id)}/messages`);
|
|
201
|
+
const data = (await res.json());
|
|
202
|
+
return (data.events ?? []).map(({ call_id, ...e }) => ({
|
|
203
|
+
...e,
|
|
204
|
+
...(call_id ? { callId: call_id } : {}),
|
|
205
|
+
agent,
|
|
206
|
+
timestamp: task.createdAt,
|
|
207
|
+
}));
|
|
357
208
|
}
|
|
358
209
|
}
|
package/dist/lib/cloud/stream.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
+
import { normalizeProviderStatus } from './types.js';
|
|
2
3
|
function decodeSSEFrame(name, data, timestamp) {
|
|
3
4
|
let parsed = {};
|
|
4
5
|
try {
|
|
@@ -8,7 +9,7 @@ function decodeSSEFrame(name, data, timestamp) {
|
|
|
8
9
|
}
|
|
9
10
|
switch (name) {
|
|
10
11
|
case 'status':
|
|
11
|
-
return { type: 'status', status: parsed.status
|
|
12
|
+
return { type: 'status', status: normalizeProviderStatus('rush', parsed.status), timestamp };
|
|
12
13
|
case 'text':
|
|
13
14
|
case 'output':
|
|
14
15
|
case 'message':
|
|
@@ -16,7 +17,7 @@ function decodeSSEFrame(name, data, timestamp) {
|
|
|
16
17
|
case 'thinking':
|
|
17
18
|
return { type: 'thinking', content: parsed.content ?? data, timestamp };
|
|
18
19
|
case 'tool_use':
|
|
19
|
-
return { type: 'tool_use', tool: parsed.tool ?? '', input: parsed.
|
|
20
|
+
return { type: 'tool_use', tool: parsed.tool ?? '', input: parsed.args, timestamp };
|
|
20
21
|
case 'tool_result':
|
|
21
22
|
return { type: 'tool_result', tool: parsed.tool ?? '', output: parsed.output, timestamp };
|
|
22
23
|
case 'usage':
|
|
@@ -27,14 +28,15 @@ function decodeSSEFrame(name, data, timestamp) {
|
|
|
27
28
|
outputTokens: parsed.outputTokens,
|
|
28
29
|
timestamp,
|
|
29
30
|
};
|
|
30
|
-
case 'done':
|
|
31
|
+
case 'done': {
|
|
32
|
+
const answer = parsed.result?.text;
|
|
31
33
|
return {
|
|
32
34
|
type: 'done',
|
|
33
|
-
status: parsed.status,
|
|
34
|
-
|
|
35
|
-
summary: typeof parsed.output === 'string' ? parsed.output.slice(0, 2000) : parsed.summary,
|
|
35
|
+
status: typeof parsed.status === 'string' ? normalizeProviderStatus('rush', parsed.status) : undefined,
|
|
36
|
+
summary: typeof answer === 'string' ? answer.slice(0, 2000) : undefined,
|
|
36
37
|
timestamp,
|
|
37
38
|
};
|
|
39
|
+
}
|
|
38
40
|
case 'error':
|
|
39
41
|
return { type: 'error', message: parsed.message ?? data, timestamp };
|
|
40
42
|
default:
|
|
@@ -60,10 +60,6 @@ export type CloudEvent = {
|
|
|
60
60
|
data: string;
|
|
61
61
|
timestamp?: string;
|
|
62
62
|
};
|
|
63
|
-
export interface SkillRef {
|
|
64
|
-
id: string;
|
|
65
|
-
version?: string;
|
|
66
|
-
}
|
|
67
63
|
export interface ImageAttachment {
|
|
68
64
|
data: string;
|
|
69
65
|
mimeType: 'image/png' | 'image/jpeg' | 'image/webp';
|
|
@@ -77,7 +73,7 @@ export interface DispatchOptions {
|
|
|
77
73
|
branch?: string;
|
|
78
74
|
timeout?: string;
|
|
79
75
|
model?: string;
|
|
80
|
-
skills?:
|
|
76
|
+
skills?: string[];
|
|
81
77
|
images?: ImageAttachment[];
|
|
82
78
|
providerOptions?: Record<string, unknown>;
|
|
83
79
|
env?: Record<string, string>;
|
|
@@ -123,7 +119,9 @@ export interface CloudProvider {
|
|
|
123
119
|
}
|
|
124
120
|
export type DroidAutonomy = 'low' | 'medium' | 'high';
|
|
125
121
|
export interface CloudProviderConfig {
|
|
126
|
-
rush?:
|
|
122
|
+
rush?: {
|
|
123
|
+
secretsBundle?: string;
|
|
124
|
+
};
|
|
127
125
|
codex?: {
|
|
128
126
|
env?: string;
|
|
129
127
|
};
|
package/dist/lib/cloud/types.js
CHANGED
|
@@ -23,6 +23,7 @@ function normalizeCursorStatus(s) {
|
|
|
23
23
|
}
|
|
24
24
|
function normalizeRushStatus(s) {
|
|
25
25
|
switch (s) {
|
|
26
|
+
case 'queued': return 'queued';
|
|
26
27
|
case 'allocating': return 'allocating';
|
|
27
28
|
case 'running': return 'running';
|
|
28
29
|
case 'idle':
|
|
@@ -30,7 +31,9 @@ function normalizeRushStatus(s) {
|
|
|
30
31
|
case 'needs_review': return 'idle';
|
|
31
32
|
case 'input_required': return 'input_required';
|
|
32
33
|
case 'completed': return 'completed';
|
|
33
|
-
case 'failed':
|
|
34
|
+
case 'failed':
|
|
35
|
+
case 'expired': return 'failed';
|
|
36
|
+
case 'cancelling':
|
|
34
37
|
case 'cancelled': return 'cancelled';
|
|
35
38
|
default: return 'running';
|
|
36
39
|
}
|
|
@@ -6,8 +6,13 @@ export declare class SessionStateService extends BasePeriodicService {
|
|
|
6
6
|
readonly intervalMs = 15000;
|
|
7
7
|
readonly deadlineMs = 30000;
|
|
8
8
|
private stopReaderWatch;
|
|
9
|
+
private liveFiles;
|
|
10
|
+
private wakeTimer;
|
|
11
|
+
private lastWakeMs;
|
|
12
|
+
private lastChangeMs;
|
|
9
13
|
constructor(wake: () => void);
|
|
10
|
-
protected onStart(
|
|
14
|
+
protected onStart(ctx: DaemonContext): Promise<void>;
|
|
11
15
|
protected onStop(): Promise<void>;
|
|
12
16
|
protected onTick(ctx: DaemonContext): Promise<void>;
|
|
17
|
+
private scheduleWake;
|
|
13
18
|
}
|