@phnx-labs/agents-cli 1.23.42 → 1.23.43
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 +6 -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/exec.d.ts +1 -1
- package/dist/lib/exec.js +2 -1
- package/dist/lib/session/presentation.d.ts +3 -0
- package/dist/lib/session/presentation.js +4 -1
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.23.43
|
|
4
|
+
|
|
5
|
+
- **`agents cloud --provider rush` uses a Rush API key, not the deprecated `rush login` (PHNX-4381).** The provider and `agents cloud transcripts` now call the Rush developer API (`/o/{org}/sessions`: start, read, list, `…/events`, `…/messages`, `…/cancel`) with `RUSH_API_KEY` and `RUSH_ORG`, read from the secrets bundle named in `cloud.providers.rush.secretsBundle` or from the environment (`secrets exec getrush.ai -- agents cloud run …`). Nothing reads `~/.rush/user.yaml` any more. A run no longer needs `--repo`; it takes one repository (sent with `--branch` as a `tree/<branch>` resource), and two `--repo` flags are refused. `--skill` takes a public skill URL. `agents cloud run` loses `--mode`, `-b/--balanced` and `--strategy`, which only the old Rush path read: a key run uses the key creator's own model accounts, and `agents run --cloud --mode …` to Rush is refused. Source: `cli/src/lib/cloud/rush.ts`, `cli/src/commands/cloud-transcripts.ts`.
|
|
6
|
+
|
|
7
|
+
- **`--mode auto` on Grok runs Grok's own auto mode instead of a flagless run that dies headless.** Grok's spec listed no `auto` mode, so `resolveMode` turned `auto` into `edit`, which passes Grok no permission flag. A headless `grok -p` run then asked before most shell commands, had nobody to answer, and got "User cancelled" on the first one, cancelling every later tool and exiting 0 about a minute in. Every Finder "Variations · Soft" run since the action moved to `grok#socials` ended this way. `auto` now passes Grok's native `--permission-mode auto` (the flag string Claude's `auto` also gets), which runs ordinary shell commands headless, and a headless `plan` request for Grok downgrades to that `auto` rather than to `edit`. Source: `cli/src/lib/agent-spec/agents.ts`, `cli/src/lib/exec.ts`.
|
|
8
|
+
|
|
3
9
|
## 1.23.42
|
|
4
10
|
|
|
5
11
|
- **A session that reconnects after an ssh drop keeps its editor tab.** `agents run --device` exports `AGENT_TERMINAL_ID`, `AGENTS_ORIGIN_TERMINAL_ID` and `AGENTS_ORIGIN_DEVICE` so the remote session's row links back to the tab it was launched from. The automatic reattach after a dropped connection (`agents ps focus --reconnect-reattach`) ran without them, so the reattached session had no tab. The extension then saw a running session with no tab here, resumed it, and started a second Claude on the same conversation (owner video, 2026-10-19). The reattach now runs behind the same `remoteRunShellPrelude` as the launch. Source: `cli/src/lib/hosts/reconnect.ts`, `cli/src/commands/exec.ts`.
|
package/README.md
CHANGED
|
@@ -243,7 +243,7 @@ Supports plan (read-only), edit, auto, and skip modes, effort levels, JSON outpu
|
|
|
243
243
|
Treat `skip` as a last-resort escape hatch. In direct-exec runs (without `--acp`),
|
|
244
244
|
agi-cli forwards the harness's native no-prompt flag; it does not add another
|
|
245
245
|
safety layer. Prefer `auto` where it adds a safer automatic policy (smart classifier
|
|
246
|
-
on Claude/Copilot, never-prompt over a sandbox on Codex, native high-auto mode on
|
|
246
|
+
on Claude/Copilot, Grok's native auto mode, never-prompt over a sandbox on Codex, native high-auto mode on
|
|
247
247
|
Droid, or interactive Kimi), or `edit` everywhere else. For headless Kimi, `edit`, `auto`, and `skip` all use the same
|
|
248
248
|
already-auto-approved `-p` behavior, so prefer `edit` rather than signaling a blanket
|
|
249
249
|
bypass. Harnesses without a native bypass flag reject direct-exec `skip`.
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { setHelpSections } from '../lib/help.js';
|
|
3
3
|
import { interruptibleSpinner } from '../lib/spinner.js';
|
|
4
|
+
import { deriveShortId } from '../lib/text/short-id.js';
|
|
4
5
|
const DEFAULT_LIMIT = '50';
|
|
6
|
+
function cloudTaskSessionMeta(task) {
|
|
7
|
+
if (task.agent !== 'claude' && task.agent !== 'codex' && task.agent !== 'opencode')
|
|
8
|
+
return null;
|
|
9
|
+
return {
|
|
10
|
+
id: task.id,
|
|
11
|
+
shortId: deriveShortId(task.id),
|
|
12
|
+
agent: task.agent,
|
|
13
|
+
timestamp: task.createdAt,
|
|
14
|
+
project: task.repo,
|
|
15
|
+
filePath: '',
|
|
16
|
+
topic: task.prompt.split('\n')[0]?.slice(0, 120) || undefined,
|
|
17
|
+
label: `[cloud/${task.status}]${task.branch ? ` ${task.branch}` : ''}`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
5
20
|
async function runCloudTranscripts(query, options) {
|
|
6
|
-
const {
|
|
7
|
-
const { buildFilterOptions, printSessionTable, resolveViewMode,
|
|
21
|
+
const { getRushProvider } = await import('../lib/cloud/registry.js');
|
|
22
|
+
const { buildFilterOptions, printSessionTable, resolveViewMode, renderSessionEvents } = await import('../lib/session/presentation.js');
|
|
23
|
+
const rush = getRushProvider();
|
|
8
24
|
let filterOpts;
|
|
9
25
|
try {
|
|
10
26
|
filterOpts = buildFilterOptions(options);
|
|
@@ -17,7 +33,10 @@ async function runCloudTranscripts(query, options) {
|
|
|
17
33
|
const spinner = options.json ? null : interruptibleSpinner('Loading cloud sessions...').start();
|
|
18
34
|
let sessions;
|
|
19
35
|
try {
|
|
20
|
-
sessions = await
|
|
36
|
+
sessions = (await rush.list())
|
|
37
|
+
.map(cloudTaskSessionMeta)
|
|
38
|
+
.filter((s) => s !== null)
|
|
39
|
+
.slice(0, parseInt(options.limit || DEFAULT_LIMIT, 10));
|
|
21
40
|
}
|
|
22
41
|
catch (err) {
|
|
23
42
|
spinner?.stop();
|
|
@@ -31,7 +50,7 @@ async function runCloudTranscripts(query, options) {
|
|
|
31
50
|
return;
|
|
32
51
|
}
|
|
33
52
|
if (sessions.length === 0) {
|
|
34
|
-
console.log(chalk.gray('No cloud sessions
|
|
53
|
+
console.log(chalk.gray('No cloud sessions yet.'));
|
|
35
54
|
return;
|
|
36
55
|
}
|
|
37
56
|
printSessionTable(sessions);
|
|
@@ -50,18 +69,18 @@ async function runCloudTranscripts(query, options) {
|
|
|
50
69
|
process.exit(1);
|
|
51
70
|
}
|
|
52
71
|
const meta = matches[0];
|
|
53
|
-
const
|
|
54
|
-
let
|
|
72
|
+
const fetchSpinner = options.json ? null : interruptibleSpinner('Fetching session...').start();
|
|
73
|
+
let events;
|
|
55
74
|
try {
|
|
56
|
-
|
|
75
|
+
events = await rush.transcript({ id: meta.id, createdAt: meta.timestamp }, meta.agent);
|
|
57
76
|
}
|
|
58
77
|
catch (err) {
|
|
59
|
-
|
|
78
|
+
fetchSpinner?.stop();
|
|
60
79
|
console.error(chalk.red(`Failed to fetch session: ${err?.message || err}`));
|
|
61
80
|
process.exit(1);
|
|
62
81
|
}
|
|
63
|
-
|
|
64
|
-
|
|
82
|
+
fetchSpinner?.stop();
|
|
83
|
+
renderSessionEvents(meta, events, mode, filterOpts, options);
|
|
65
84
|
}
|
|
66
85
|
export function registerCloudTranscriptsCommand(cloud) {
|
|
67
86
|
const cmd = cloud
|
|
@@ -91,8 +110,8 @@ export function registerCloudTranscriptsCommand(cloud) {
|
|
|
91
110
|
agents cloud transcripts 3f2a9c1e --include tools --last 2 --json
|
|
92
111
|
`,
|
|
93
112
|
notes: `
|
|
94
|
-
- Reads Rush Cloud runs
|
|
95
|
-
- Every render fetches the run's transcript again
|
|
113
|
+
- Reads Rush Cloud runs with your Rush API key (RUSH_API_KEY and RUSH_ORG, from the bundle named in cloud.providers.rush.secretsBundle or the environment). A missing or rejected key, or an unmatched or ambiguous selector, exits 1; it never falls back to local sessions.
|
|
114
|
+
- Every render fetches the run's transcript again from the developer API (\`GET /o/{org}/sessions/{id}/messages\`).
|
|
96
115
|
- \`agents cloud list/status/logs\` cover the run jobs, not their transcripts.
|
|
97
116
|
`,
|
|
98
117
|
});
|
package/dist/commands/cloud.js
CHANGED
|
@@ -29,7 +29,7 @@ Each agent runs in its own cloud. Pass --agent and the provider is auto-selected
|
|
|
29
29
|
(claude→rush, codex→codex, cursor→cursor, droid→factory, antigravity→antigravity); --provider overrides.
|
|
30
30
|
|
|
31
31
|
Providers:
|
|
32
|
-
rush Rush Cloud — Claude
|
|
32
|
+
rush Rush Cloud — Claude, Codex or OpenCode via the developer API (API key), optional repo → PR
|
|
33
33
|
codex Codex Cloud — runs in a pre-built Codex environment (--env)
|
|
34
34
|
cursor Cursor Cloud Agents — v1 REST API, with optional GitHub repos
|
|
35
35
|
factory Factory Droid Computer — droid exec on a cloud VM (--computer)
|
|
@@ -42,9 +42,6 @@ Examples:
|
|
|
42
42
|
# Fire-and-forget (returns the task id, no streaming)
|
|
43
43
|
agents cloud run "bump tailwind to v4 and fix the breaks" --provider rush --repo acme/example --no-follow
|
|
44
44
|
|
|
45
|
-
# Multi-repo dispatch: touch both rush and rush-extension in one task
|
|
46
|
-
agents cloud run "rename POST /v1/charge -> /v2/charge across server + extension" --provider rush --repo acme/example --repo acme/example-extension
|
|
47
|
-
|
|
48
45
|
# Codex Cloud against a saved environment
|
|
49
46
|
agents cloud run "add pytest fixtures for the new billing module" --provider codex --env env_a1b2c3 --agent codex --timeout 30m
|
|
50
47
|
|
|
@@ -80,7 +77,7 @@ Examples:
|
|
|
80
77
|
.description('Dispatch a task to a cloud agent.')
|
|
81
78
|
.option('--provider <id>', 'Cloud backend: rush, codex, cursor, factory, antigravity, host (overrides agent auto-routing)')
|
|
82
79
|
.option('--agent <name>', 'Agent to run: claude, codex, cursor, droid, antigravity (auto-routes to its native cloud)')
|
|
83
|
-
.option('--repo <owner/repo>', 'GitHub repository. Repeatable for multi-repo dispatch (Rush
|
|
80
|
+
.option('--repo <owner/repo>', 'GitHub repository. Repeatable for multi-repo dispatch (Cursor Cloud); Rush Cloud takes one.', (value, previous) => {
|
|
84
81
|
const acc = Array.isArray(previous) ? previous : [];
|
|
85
82
|
acc.push(value);
|
|
86
83
|
return acc;
|
|
@@ -95,19 +92,16 @@ Examples:
|
|
|
95
92
|
.option('--remote-cwd <dir>', 'Working directory on the device (--provider host only)')
|
|
96
93
|
.option('--any', 'With --device <cap> (a capability tag), pick any matching device instead of erroring when several match')
|
|
97
94
|
.option('--autonomy <level>', 'Factory/Droid autonomy: low, medium, high (default high)')
|
|
98
|
-
.option('--mode <mode>', 'Execution mode (e.g., plan, edit, full)')
|
|
99
95
|
.option('--image <path>', `Attach an image (.png/.jpg/.webp) for vision dispatch. Repeatable, up to ${MAX_IMAGES_PER_DISPATCH} (Rush Cloud only).`, (value, previous) => {
|
|
100
96
|
const acc = Array.isArray(previous) ? previous : [];
|
|
101
97
|
acc.push(value);
|
|
102
98
|
return acc;
|
|
103
99
|
})
|
|
104
|
-
.option('--skill <
|
|
100
|
+
.option('--skill <url>', 'Skill by public URL: a GitHub tree URL to a directory with SKILL.md, a SKILL.md file, or a .zip. Repeatable (Rush Cloud only).', (value, previous) => {
|
|
105
101
|
const acc = Array.isArray(previous) ? previous : [];
|
|
106
102
|
acc.push(value);
|
|
107
103
|
return acc;
|
|
108
104
|
})
|
|
109
|
-
.option('-b, --balanced', 'Shortcut for --strategy balanced. Route the factory run across all healthy accounts.')
|
|
110
|
-
.option('--strategy <strategy>', 'Account selection strategy for the factory: balanced. Sends all healthy accounts so the factory pod rotates between them on rate-limit.')
|
|
111
105
|
.option('--json', 'Structured JSON output')
|
|
112
106
|
.option('--no-follow', 'Dispatch and exit without streaming output')
|
|
113
107
|
.addHelpText('after', `
|
|
@@ -116,8 +110,8 @@ Examples:
|
|
|
116
110
|
agents cloud run "fix the flaky test" --provider rush --repo user/repo
|
|
117
111
|
agents cloud run task.md --provider rush --repo org/project --agent codex
|
|
118
112
|
|
|
119
|
-
# Rush Cloud
|
|
120
|
-
agents cloud run "
|
|
113
|
+
# Rush Cloud with no repository
|
|
114
|
+
agents cloud run "summarize the attached screenshot" --provider rush --image shot.png
|
|
121
115
|
|
|
122
116
|
# Codex Cloud
|
|
123
117
|
agents cloud run "add auth tests" --provider codex --env env_abc123
|
|
@@ -169,16 +163,11 @@ Examples:
|
|
|
169
163
|
dispatchOptions.providerOptions.any = true;
|
|
170
164
|
if (options.autonomy)
|
|
171
165
|
dispatchOptions.providerOptions.autonomy = options.autonomy;
|
|
172
|
-
if (options.mode)
|
|
173
|
-
dispatchOptions.providerOptions.mode = options.mode;
|
|
174
|
-
if (options.balanced || options.strategy === 'balanced') {
|
|
175
|
-
dispatchOptions.providerOptions.strategy = 'balanced';
|
|
176
|
-
}
|
|
177
166
|
await executeCloudDispatch({
|
|
178
167
|
provider,
|
|
179
168
|
dispatchOptions,
|
|
180
169
|
imagePaths: Array.isArray(options.image) ? options.image : [],
|
|
181
|
-
|
|
170
|
+
skillUrls: Array.isArray(options.skill) ? options.skill : [],
|
|
182
171
|
follow: options.follow !== false,
|
|
183
172
|
json,
|
|
184
173
|
});
|
package/dist/commands/exec.js
CHANGED
|
@@ -406,7 +406,7 @@ export function registerRunCommand(program) {
|
|
|
406
406
|
const runCmd = program
|
|
407
407
|
.command('run [agent] [prompt]')
|
|
408
408
|
.description('Execute an agent. Pass a prompt for headless runs; omit it to launch the agent interactively. With --broadcast, run the same prompt/task across an agent × model matrix.')
|
|
409
|
-
.option('-m, --mode <mode>', 'How much the agent can do: plan (read-only), edit (can write files), auto (more autonomous than edit, mechanism per-harness: smart classifier auto-approves safe ops and still prompts for risky ones on Claude/Copilot; approval_policy=never over the edit sandbox on Codex, which never prompts), skip (bypass all permission prompts). Omitted, no permission flag is passed and the harness\'s own settings decide (Codex\'s launcher applies its edit policy); set a default with agents config set run.<agent>@*.mode <mode>. \'full\' accepted as alias for skip.', 'plan')
|
|
409
|
+
.option('-m, --mode <mode>', 'How much the agent can do: plan (read-only), edit (can write files), auto (more autonomous than edit, mechanism per-harness: smart classifier auto-approves safe ops and still prompts for risky ones on Claude/Copilot; approval_policy=never over the edit sandbox on Codex, which never prompts; Grok\'s native --permission-mode auto), skip (bypass all permission prompts). Omitted, no permission flag is passed and the harness\'s own settings decide (Codex\'s launcher applies its edit policy); set a default with agents config set run.<agent>@*.mode <mode>. \'full\' accepted as alias for skip.', 'plan')
|
|
410
410
|
.option('-e, --effort <effort>', 'Reasoning effort: low | medium | high | xhigh | max | auto (claude and codex only)', 'auto')
|
|
411
411
|
.option('--model <model>', 'Cost tier (cheap|default|best|ultra) or a concrete model id; tiers resolve per harness+version to a supported model')
|
|
412
412
|
.option('--env <key=value>', 'Pass environment variable to the agent (repeatable, e.g., --env DEBUG=1 --env API_KEY=xyz)', (val, prev) => [...prev, val], [])
|
|
@@ -559,6 +559,7 @@ agents run auto --device yosemite-s0 "fix the flaky test" # pin the device
|
|
|
559
559
|
STILL PROMPTS for risky ones
|
|
560
560
|
codex: approval_policy=never over the edit sandbox; never
|
|
561
561
|
prompts at all, and a denied command fails instead
|
|
562
|
+
grok: grok's native --permission-mode auto
|
|
562
563
|
skip bypass every permission prompt (dangerously-skip-permissions)
|
|
563
564
|
Legacy 'full' is silently rewritten to 'skip'.
|
|
564
565
|
Unsupported requests degrade: auto falls back to edit, plan to the
|
package/dist/lib/agent-modes.js
CHANGED
|
@@ -15,6 +15,7 @@ const AUTO_SEMANTICS = {
|
|
|
15
15
|
muse: 'runs --disable-approval, which turns approvals off while keeping the sandbox — like codex, it never prompts and a denied command fails.',
|
|
16
16
|
droid: 'runs --auto high, droid\'s full-autonomy setting.',
|
|
17
17
|
kimi: "runs kimi's native --auto.",
|
|
18
|
+
grok: "runs grok's native --permission-mode auto.",
|
|
18
19
|
};
|
|
19
20
|
export function getAgentModesCatalog(agent, version, cwd = process.cwd()) {
|
|
20
21
|
const supported = AGENTS[agent].capabilities.modes;
|
|
@@ -484,7 +484,7 @@ export const AGENTS = {
|
|
|
484
484
|
rules: { file: 'AGENTS.md' },
|
|
485
485
|
workflows: { since: '0.2.111' },
|
|
486
486
|
memory: true,
|
|
487
|
-
modes: ['plan', 'edit', 'skip'],
|
|
487
|
+
modes: ['plan', 'edit', 'auto', 'skip'],
|
|
488
488
|
headlessPlan: false,
|
|
489
489
|
rulesImports: true,
|
|
490
490
|
interactiveRepl: true,
|
|
@@ -25,13 +25,6 @@ function readImageAttachment(file) {
|
|
|
25
25
|
const mimeType = imageMimeFromPath(file);
|
|
26
26
|
return { data: fs.readFileSync(file).toString('base64'), mimeType };
|
|
27
27
|
}
|
|
28
|
-
function parseSkillRef(raw) {
|
|
29
|
-
const at = raw.lastIndexOf('@');
|
|
30
|
-
if (at > 0) {
|
|
31
|
-
return { id: raw.slice(0, at), version: raw.slice(at + 1) };
|
|
32
|
-
}
|
|
33
|
-
return { id: raw };
|
|
34
|
-
}
|
|
35
28
|
export function resolveCloudPrompt(raw, opts) {
|
|
36
29
|
let prompt = raw;
|
|
37
30
|
if (!prompt)
|
|
@@ -79,7 +72,7 @@ async function pickMissingTarget(provider, err, json) {
|
|
|
79
72
|
export async function executeCloudDispatch(params) {
|
|
80
73
|
const { provider, dispatchOptions, follow, json } = params;
|
|
81
74
|
const imagePaths = params.imagePaths ?? [];
|
|
82
|
-
const
|
|
75
|
+
const skillUrls = params.skillUrls ?? [];
|
|
83
76
|
const shareEnv = shareRuntimeEnv();
|
|
84
77
|
if (shareEnv)
|
|
85
78
|
dispatchOptions.env = shareEnv;
|
|
@@ -92,10 +85,10 @@ export async function executeCloudDispatch(params) {
|
|
|
92
85
|
}
|
|
93
86
|
dispatchOptions.images = imagePaths.map(readImageAttachment);
|
|
94
87
|
}
|
|
95
|
-
if (
|
|
88
|
+
if (skillUrls.length > 0) {
|
|
96
89
|
if (!caps.skills)
|
|
97
90
|
die(`${provider.name} does not support ride-along skills.`, 1, { json });
|
|
98
|
-
dispatchOptions.skills =
|
|
91
|
+
dispatchOptions.skills = skillUrls;
|
|
99
92
|
}
|
|
100
93
|
const dispatchOnce = async () => {
|
|
101
94
|
const spinner = ora({ text: `Dispatching to ${provider.name}...`, stream: process.stderr }).start();
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { CloudProvider, CloudProviderId } from './types.js';
|
|
2
|
+
import { RushCloudProvider } from './rush.js';
|
|
2
3
|
export declare function nativeProviderForAgent(agentId: string): CloudProviderId | undefined;
|
|
3
4
|
export declare function getProvider(id: CloudProviderId): CloudProvider;
|
|
5
|
+
export declare function getRushProvider(): RushCloudProvider;
|
|
4
6
|
export declare function getDefaultProviderId(): CloudProviderId;
|
|
5
7
|
export declare function getAllProviders(): CloudProvider[];
|
|
6
8
|
export declare function resolveProvider(explicit?: string, agentId?: string): CloudProvider;
|
|
@@ -29,11 +29,13 @@ function loadCloudConfig() {
|
|
|
29
29
|
return _config;
|
|
30
30
|
}
|
|
31
31
|
const providers = new Map();
|
|
32
|
+
let rush = null;
|
|
32
33
|
function initProviders() {
|
|
33
34
|
if (providers.size > 0)
|
|
34
35
|
return;
|
|
35
36
|
const config = loadCloudConfig();
|
|
36
|
-
|
|
37
|
+
rush = new RushCloudProvider(config.providers?.rush);
|
|
38
|
+
providers.set('rush', rush);
|
|
37
39
|
providers.set('codex', new CodexCloudProvider(config.providers?.codex));
|
|
38
40
|
providers.set('factory', new FactoryCloudProvider(config.providers?.factory));
|
|
39
41
|
providers.set('antigravity', new AntigravityCloudProvider(config.providers?.antigravity));
|
|
@@ -52,6 +54,10 @@ export function getProvider(id) {
|
|
|
52
54
|
}
|
|
53
55
|
return provider;
|
|
54
56
|
}
|
|
57
|
+
export function getRushProvider() {
|
|
58
|
+
initProviders();
|
|
59
|
+
return rush;
|
|
60
|
+
}
|
|
55
61
|
export function getDefaultProviderId() {
|
|
56
62
|
const config = loadCloudConfig();
|
|
57
63
|
return config.default_provider ?? 'rush';
|
package/dist/lib/cloud/rush.d.ts
CHANGED
|
@@ -1,38 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export interface RushOrg {
|
|
5
|
-
slug?: string;
|
|
6
|
-
kind?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function rushOrgHandle(token: string, yamlPath?: string): Promise<string>;
|
|
9
|
-
export declare function personalOrgHandle(orgs: RushOrg[]): string | undefined;
|
|
10
|
-
interface AccountManifestEntry {
|
|
11
|
-
version: string;
|
|
12
|
-
email: string;
|
|
13
|
-
}
|
|
14
|
-
interface AccountManifest {
|
|
15
|
-
fp: string;
|
|
16
|
-
versions: AccountManifestEntry[];
|
|
17
|
-
}
|
|
18
|
-
export declare function buildDispatchBody(input: {
|
|
19
|
-
agent?: string;
|
|
20
|
-
prompt: string;
|
|
21
|
-
mode?: string;
|
|
22
|
-
strategy?: string;
|
|
23
|
-
resolvedRepos: Array<{
|
|
24
|
-
installation_id: number;
|
|
25
|
-
repo_owner: string;
|
|
26
|
-
repo_name: string;
|
|
27
|
-
}>;
|
|
28
|
-
accountManifest?: AccountManifest | null;
|
|
29
|
-
skills?: SkillRef[] | null;
|
|
30
|
-
images?: ImageAttachment[] | null;
|
|
31
|
-
env?: Record<string, string> | null;
|
|
32
|
-
}): Record<string, unknown>;
|
|
1
|
+
import type { SessionAgentId, SessionEvent } from '@phnx-labs/sessions-cli/reader';
|
|
2
|
+
import type { CloudProvider, CloudTask, CloudTaskStatus, CloudEvent, DispatchOptions, ProviderCapabilities } from './types.js';
|
|
3
|
+
export declare function buildSessionCreateBody(options: DispatchOptions): Record<string, unknown>;
|
|
33
4
|
export declare class RushCloudProvider implements CloudProvider {
|
|
34
5
|
id: "rush";
|
|
35
6
|
name: string;
|
|
7
|
+
private secretsBundle?;
|
|
8
|
+
constructor(config?: {
|
|
9
|
+
secretsBundle?: string;
|
|
10
|
+
});
|
|
11
|
+
private credential;
|
|
12
|
+
private request;
|
|
36
13
|
capabilities(): ProviderCapabilities;
|
|
37
14
|
dispatch(options: DispatchOptions): Promise<CloudTask>;
|
|
38
15
|
status(taskId: string): Promise<CloudTask>;
|
|
@@ -42,5 +19,5 @@ export declare class RushCloudProvider implements CloudProvider {
|
|
|
42
19
|
stream(taskId: string): AsyncIterable<CloudEvent>;
|
|
43
20
|
cancel(taskId: string): Promise<void>;
|
|
44
21
|
message(taskId: string, content: string): Promise<void>;
|
|
22
|
+
transcript(task: Pick<CloudTask, 'id' | 'createdAt'>, agent: SessionAgentId): Promise<SessionEvent[]>;
|
|
45
23
|
}
|
|
46
|
-
export {};
|
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
|
}
|
package/dist/lib/exec.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare function resolveMode(agent: AgentId, requested: Mode): Mode;
|
|
|
19
19
|
* because plan is broken in a headless `--prompt`/`-p` run — kimi refuses
|
|
20
20
|
* `--prompt` + `--plan`, and grok's `--permission-mode plan` silently stalls at
|
|
21
21
|
* its ExitPlanMode gate. For those agents, a headless plan request degrades to
|
|
22
|
-
* `auto` (kimi -p auto-runs; grok
|
|
22
|
+
* `auto` (kimi -p auto-runs; grok runs `--permission-mode auto`) with a visible
|
|
23
23
|
* one-line stderr warning, mirroring the graceful plan→edit degrade antigravity
|
|
24
24
|
* get for having no plan flag at all. Interactive runs are never
|
|
25
25
|
* downgraded. This is the single source of truth shared by buildExecCommand
|
package/dist/lib/exec.js
CHANGED
|
@@ -103,7 +103,7 @@ export function resolveMode(agent, requested) {
|
|
|
103
103
|
* because plan is broken in a headless `--prompt`/`-p` run — kimi refuses
|
|
104
104
|
* `--prompt` + `--plan`, and grok's `--permission-mode plan` silently stalls at
|
|
105
105
|
* its ExitPlanMode gate. For those agents, a headless plan request degrades to
|
|
106
|
-
* `auto` (kimi -p auto-runs; grok
|
|
106
|
+
* `auto` (kimi -p auto-runs; grok runs `--permission-mode auto`) with a visible
|
|
107
107
|
* one-line stderr warning, mirroring the graceful plan→edit degrade antigravity
|
|
108
108
|
* get for having no plan flag at all. Interactive runs are never
|
|
109
109
|
* downgraded. This is the single source of truth shared by buildExecCommand
|
|
@@ -441,6 +441,7 @@ export const AGENT_COMMANDS = {
|
|
|
441
441
|
modeFlags: {
|
|
442
442
|
plan: ['--permission-mode', 'plan'],
|
|
443
443
|
edit: [],
|
|
444
|
+
auto: ['--permission-mode', 'auto'],
|
|
444
445
|
skip: ['--always-approve'],
|
|
445
446
|
},
|
|
446
447
|
jsonFlags: ['--output-format', 'streaming-json'],
|
|
@@ -19,6 +19,9 @@ export declare function renderSessionLogJson(session: SessionMeta): Promise<void
|
|
|
19
19
|
export declare function renderSession(session: SessionMeta, mode: ViewMode, filters: FilterOptions, options?: {
|
|
20
20
|
redact?: boolean;
|
|
21
21
|
}): Promise<void>;
|
|
22
|
+
export declare function renderSessionEvents(session: SessionMeta, parsedEvents: SessionEvent[], mode: ViewMode, filters: FilterOptions, options?: {
|
|
23
|
+
redact?: boolean;
|
|
24
|
+
}): void;
|
|
22
25
|
export declare function formatTodoCompact(todos?: Pick<TodoProgress, 'done' | 'total' | 'activeForm'> | null): string;
|
|
23
26
|
export declare function statusColor(status: ActiveSession['status']): (s: string) => string;
|
|
24
27
|
export declare function cleanPreview(text: string): string;
|
|
@@ -152,7 +152,10 @@ export async function renderSession(session, mode, filters, options = {}) {
|
|
|
152
152
|
const spinner = ora(`Parsing ${sessionDisplayAgent(session)} session...`).start();
|
|
153
153
|
const parsedEvents = parseSession(session.filePath, session.agent);
|
|
154
154
|
spinner.stop();
|
|
155
|
-
|
|
155
|
+
renderSessionEvents(session, parsedEvents, mode, filters, options);
|
|
156
|
+
}
|
|
157
|
+
export function renderSessionEvents(session, parsedEvents, mode, filters, options = {}) {
|
|
158
|
+
const events = filterEvents(parsedEvents, filters);
|
|
156
159
|
const shown = sessionDisplayAgent(session);
|
|
157
160
|
const agentColor = colorAgent(shown);
|
|
158
161
|
console.log('');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phnx-labs/agents-cli",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.43",
|
|
4
4
|
"description": "One CLI for all your AI coding agents - versions, config, cloud dispatch, sessions, and teams (now with first-class Grok Build CLI support)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isRushSessionExpired(expiresAt: number | undefined): boolean;
|
package/dist/lib/rush-session.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { SessionMeta } from '@phnx-labs/sessions-cli/reader';
|
|
2
|
-
export declare function discoverCloudSessions(options?: {
|
|
3
|
-
limit?: number;
|
|
4
|
-
}): Promise<SessionMeta[]>;
|
|
5
|
-
export declare function ensureCloudSessionCached(executionId: string, destPath?: string): Promise<string>;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import { deriveShortId } from '../text/short-id.js';
|
|
4
|
-
import { getCacheDir } from '../state.js';
|
|
5
|
-
import { readToken, rushOrgHandle } from '../cloud/rush.js';
|
|
6
|
-
import { RUSH_API_BASE } from '../rush-api.js';
|
|
7
|
-
const CLOUD_CACHE_DIR = path.join(getCacheDir(), 'cloud-runs');
|
|
8
|
-
const CLOUD_EXECUTION_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
9
|
-
async function api(endpoint, token, accept) {
|
|
10
|
-
return fetch(`${RUSH_API_BASE}${endpoint}`, {
|
|
11
|
-
headers: { Authorization: `Bearer ${token}`, ...(accept ? { Accept: accept } : {}) },
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
function harnessToFormat(harness) {
|
|
15
|
-
if (harness === 'claude' || harness === 'codex' || harness === 'opencode')
|
|
16
|
-
return harness;
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
function assertContained(candidate, rootDir) {
|
|
20
|
-
const root = path.resolve(rootDir);
|
|
21
|
-
const resolved = path.resolve(root, candidate);
|
|
22
|
-
if (!resolved.startsWith(root + path.sep)) {
|
|
23
|
-
throw new Error(`Path escapes cloud session cache: ${candidate}`);
|
|
24
|
-
}
|
|
25
|
-
return resolved;
|
|
26
|
-
}
|
|
27
|
-
function validateCloudExecutionId(executionId) {
|
|
28
|
-
if (!CLOUD_EXECUTION_ID_RE.test(executionId)) {
|
|
29
|
-
throw new Error(`Invalid cloud execution_id: ${JSON.stringify(executionId)}`);
|
|
30
|
-
}
|
|
31
|
-
return executionId;
|
|
32
|
-
}
|
|
33
|
-
function cachePathForExecution(executionId, agent) {
|
|
34
|
-
const id = validateCloudExecutionId(executionId);
|
|
35
|
-
return assertContained(path.join(id, `session.${agent}.jsonl`), CLOUD_CACHE_DIR);
|
|
36
|
-
}
|
|
37
|
-
export async function discoverCloudSessions(options) {
|
|
38
|
-
const token = readToken();
|
|
39
|
-
const org = await rushOrgHandle(token);
|
|
40
|
-
const limit = options?.limit ?? 50;
|
|
41
|
-
const res = await api(`/o/${encodeURIComponent(org)}/sessions?limit=${limit}`, token);
|
|
42
|
-
if (!res.ok) {
|
|
43
|
-
throw new Error(`cloud sessions list failed (${res.status})`);
|
|
44
|
-
}
|
|
45
|
-
const data = (await res.json());
|
|
46
|
-
const rows = data.sessions ?? [];
|
|
47
|
-
const out = [];
|
|
48
|
-
for (const row of rows) {
|
|
49
|
-
const agent = harnessToFormat(row.harness);
|
|
50
|
-
if (!agent)
|
|
51
|
-
continue;
|
|
52
|
-
const id = validateCloudExecutionId(row.id);
|
|
53
|
-
const timestamp = row.updated_at || row.created_at || new Date().toISOString();
|
|
54
|
-
const project = row.project ?? undefined;
|
|
55
|
-
const filePath = cachePathForExecution(id, agent);
|
|
56
|
-
out.push({
|
|
57
|
-
id,
|
|
58
|
-
shortId: deriveShortId(id),
|
|
59
|
-
agent,
|
|
60
|
-
timestamp,
|
|
61
|
-
project,
|
|
62
|
-
filePath,
|
|
63
|
-
topic: (row.title || row.prompt)?.split('\n')[0]?.slice(0, 120),
|
|
64
|
-
label: `[cloud/${row.status}]${row.branch ? ` ${row.branch}` : ''}`,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
out.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
|
68
|
-
return out;
|
|
69
|
-
}
|
|
70
|
-
export async function ensureCloudSessionCached(executionId, destPath) {
|
|
71
|
-
const id = validateCloudExecutionId(executionId);
|
|
72
|
-
const callerPath = destPath ? assertContained(destPath, CLOUD_CACHE_DIR) : undefined;
|
|
73
|
-
const token = readToken();
|
|
74
|
-
const org = await rushOrgHandle(token);
|
|
75
|
-
const res = await api(`/o/${encodeURIComponent(org)}/p/_/sessions/${encodeURIComponent(id)}/trajectory`, token, 'application/x-ndjson');
|
|
76
|
-
if (!res.ok) {
|
|
77
|
-
const body = await res.text().catch(() => '');
|
|
78
|
-
throw new Error(`session.jsonl fetch ${res.status}: ${body.slice(0, 200)}`);
|
|
79
|
-
}
|
|
80
|
-
const format = (res.headers.get('X-Session-Format') || '').toLowerCase();
|
|
81
|
-
if (!['claude', 'codex', 'rush', 'opencode'].includes(format)) {
|
|
82
|
-
throw new Error(`Unknown X-Session-Format on cloud response: "${format}"`);
|
|
83
|
-
}
|
|
84
|
-
const finalPath = callerPath ?? cachePathForExecution(id, format);
|
|
85
|
-
fs.mkdirSync(path.dirname(finalPath), { recursive: true });
|
|
86
|
-
const body = Buffer.from(await res.arrayBuffer());
|
|
87
|
-
fs.writeFileSync(finalPath, body);
|
|
88
|
-
return finalPath;
|
|
89
|
-
}
|