dsh-subagent-agy 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +401 -3
- package/cordis.patch.yml +15 -0
- package/icon.svg +1 -0
- package/lib/classify.js +40 -0
- package/lib/client.js +397 -0
- package/lib/gemini-web.js +400 -0
- package/lib/index.js +183 -0
- package/lib/parallel.js +226 -0
- package/lib/run.js +314 -0
- package/lib/types/index.d.ts +71 -0
- package/lib/wire.js +178 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +81 -6
- package/scripts/gemini_research/browser.py +35 -0
- package/scripts/gemini_research/init_login.py +91 -0
- package/scripts/gemini_research/run_research.py +312 -0
package/lib/parallel.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel agy subagent tool.
|
|
3
|
+
*
|
|
4
|
+
* One tool call can start several independent Antigravity activations in the
|
|
5
|
+
* same assistant turn. `startActivation` publishes each child immediately, so
|
|
6
|
+
* this tool returns their ids without waiting for reports; DSH delivers each
|
|
7
|
+
* result through the normal parent notification path.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-subagent-agy/parallel
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** Default model-facing tool name. */
|
|
13
|
+
export const DEFAULT_PARALLEL_TOOL_NAME = 'subagent_agy_parallel';
|
|
14
|
+
|
|
15
|
+
/** Default maximum number of tasks in one call. */
|
|
16
|
+
export const DEFAULT_MAX_PARALLEL_TASKS = 8;
|
|
17
|
+
|
|
18
|
+
/** Maximum fallback description length, in characters. */
|
|
19
|
+
const DESCRIPTION_FALLBACK_LENGTH = 40;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Require a non-empty string and return its trimmed value.
|
|
23
|
+
* @param {unknown} value raw value
|
|
24
|
+
* @param {string} label field label for diagnostics
|
|
25
|
+
* @returns {string}
|
|
26
|
+
*/
|
|
27
|
+
function requireNonEmptyString(value, label) {
|
|
28
|
+
if (typeof value !== 'string') throw new Error(`${label} must be a string`);
|
|
29
|
+
const trimmed = value.trim();
|
|
30
|
+
if (trimmed.length === 0) throw new Error(`${label} must not be empty`);
|
|
31
|
+
return trimmed;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Validate and normalize the tasks accepted by the parallel tool.
|
|
36
|
+
* @param {unknown} tasks raw `tasks` array
|
|
37
|
+
* @param {number} [maxTasks] maximum number of tasks
|
|
38
|
+
* @returns {{description: string, prompt: string, cwd?: string}[]}
|
|
39
|
+
*/
|
|
40
|
+
export function normalizeParallelTasks(tasks, maxTasks = DEFAULT_MAX_PARALLEL_TASKS) {
|
|
41
|
+
if (!Number.isInteger(maxTasks) || maxTasks < 1) throw new Error('maxTasks must be a positive integer');
|
|
42
|
+
if (!Array.isArray(tasks)) throw new Error('tasks must be an array');
|
|
43
|
+
if (tasks.length === 0) throw new Error('tasks must contain at least one task');
|
|
44
|
+
if (tasks.length > maxTasks) throw new Error(`tasks must contain at most ${maxTasks} tasks`);
|
|
45
|
+
|
|
46
|
+
return tasks.map((task, index) => {
|
|
47
|
+
const label = `tasks[${index}]`;
|
|
48
|
+
if (task === null || typeof task !== 'object' || Array.isArray(task)) throw new Error(`${label} must be an object`);
|
|
49
|
+
|
|
50
|
+
const prompt = requireNonEmptyString(task.prompt, `${label}.prompt`);
|
|
51
|
+
let description;
|
|
52
|
+
if (task.description === undefined || task.description === null) {
|
|
53
|
+
description = prompt.slice(0, DESCRIPTION_FALLBACK_LENGTH);
|
|
54
|
+
} else if (typeof task.description === 'string') {
|
|
55
|
+
const trimmed = task.description.trim();
|
|
56
|
+
description = trimmed.length > 0 ? trimmed : prompt.slice(0, DESCRIPTION_FALLBACK_LENGTH);
|
|
57
|
+
} else {
|
|
58
|
+
throw new Error(`${label}.description must be a string`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const normalized = { description, prompt };
|
|
62
|
+
if (task.cwd !== undefined) normalized.cwd = requireNonEmptyString(task.cwd, `${label}.cwd`);
|
|
63
|
+
return normalized;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Render one concise start/failure line for the model.
|
|
69
|
+
* @param {{started?: {description: string, subagentId: string}[], failed?: {description: string, error: string}[]}} result
|
|
70
|
+
* @returns {string}
|
|
71
|
+
*/
|
|
72
|
+
export function renderParallelStart(result) {
|
|
73
|
+
const started = Array.isArray(result?.started) ? result.started.length : 0;
|
|
74
|
+
const failed = Array.isArray(result?.failed) ? result.failed.length : 0;
|
|
75
|
+
const parts = [`已启动 ${started} 个 agy 子智能体`];
|
|
76
|
+
if (failed > 0) {
|
|
77
|
+
const details = result.failed.map((item) => `${item.description}: ${item.error}`).join(';');
|
|
78
|
+
parts.push(`${failed} 个启动失败:${details}`);
|
|
79
|
+
}
|
|
80
|
+
return parts.join(',');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Build the tool's parameter JSON Schema. */
|
|
84
|
+
function toolParameters(maxTasks) {
|
|
85
|
+
return {
|
|
86
|
+
type: 'object',
|
|
87
|
+
properties: {
|
|
88
|
+
tasks: {
|
|
89
|
+
type: 'array',
|
|
90
|
+
description: `Independent agy subagent tasks to start concurrently (1-${maxTasks}).`,
|
|
91
|
+
items: {
|
|
92
|
+
type: 'object',
|
|
93
|
+
properties: {
|
|
94
|
+
description: {
|
|
95
|
+
type: 'string',
|
|
96
|
+
description: 'A short (3-5 word) display label; defaults to the first 40 characters of prompt.',
|
|
97
|
+
},
|
|
98
|
+
prompt: {
|
|
99
|
+
type: 'string',
|
|
100
|
+
description: 'A fully self-contained task prompt for one subagent.',
|
|
101
|
+
},
|
|
102
|
+
cwd: {
|
|
103
|
+
type: 'string',
|
|
104
|
+
description: 'Optional initial working directory; omitted inherits the parent directory.',
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
required: ['prompt'],
|
|
108
|
+
additionalProperties: false,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
required: ['tasks'],
|
|
113
|
+
additionalProperties: false,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Build the tool's result JSON Schema. */
|
|
118
|
+
function toolOutputSchema() {
|
|
119
|
+
return {
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
started: {
|
|
123
|
+
type: 'array',
|
|
124
|
+
items: {
|
|
125
|
+
type: 'object',
|
|
126
|
+
properties: {
|
|
127
|
+
description: { type: 'string' },
|
|
128
|
+
subagentId: { type: 'string' },
|
|
129
|
+
},
|
|
130
|
+
required: ['description', 'subagentId'],
|
|
131
|
+
additionalProperties: false,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
failed: {
|
|
135
|
+
type: 'array',
|
|
136
|
+
items: {
|
|
137
|
+
type: 'object',
|
|
138
|
+
properties: {
|
|
139
|
+
description: { type: 'string' },
|
|
140
|
+
error: { type: 'string' },
|
|
141
|
+
},
|
|
142
|
+
required: ['description', 'error'],
|
|
143
|
+
additionalProperties: false,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
required: ['started', 'failed'],
|
|
148
|
+
additionalProperties: false,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Turn an unknown rejection reason into a stable message. */
|
|
153
|
+
function errorText(error) {
|
|
154
|
+
return error instanceof Error ? error.message : String(error);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Register the `subagent_agy_parallel` tool on a DSH context.
|
|
159
|
+
*
|
|
160
|
+
* @param {object} ctx Cordis context carrying `inject`.
|
|
161
|
+
* @param {{provider: string, toolName?: string, maxTasks?: number}} options
|
|
162
|
+
* @returns {unknown} the disposer returned by `ctx.inject`, when any
|
|
163
|
+
*/
|
|
164
|
+
export function setupParallelTool(ctx, options = {}) {
|
|
165
|
+
if (ctx === null || typeof ctx !== 'object' || typeof ctx.inject !== 'function') {
|
|
166
|
+
throw new Error('setupParallelTool requires a Cordis context with inject()');
|
|
167
|
+
}
|
|
168
|
+
const provider = requireNonEmptyString(options.provider, 'provider');
|
|
169
|
+
const toolName = requireNonEmptyString(options.toolName ?? DEFAULT_PARALLEL_TOOL_NAME, 'toolName');
|
|
170
|
+
const maxTasks = options.maxTasks ?? DEFAULT_MAX_PARALLEL_TASKS;
|
|
171
|
+
if (!Number.isInteger(maxTasks) || maxTasks < 1) throw new Error('maxTasks must be a positive integer');
|
|
172
|
+
|
|
173
|
+
const parameters = toolParameters(maxTasks);
|
|
174
|
+
const outputSchema = toolOutputSchema();
|
|
175
|
+
|
|
176
|
+
return ctx.inject(['tools', 'subagents'], (tctx) => {
|
|
177
|
+
tctx.effect(() => tctx.tools.register({
|
|
178
|
+
name: toolName,
|
|
179
|
+
description: 'Start multiple independent agy subagents concurrently in one assistant turn and return their ids immediately. Use this when the user asks for several independent research, implementation, or analysis tasks to run in parallel. Results arrive asynchronously through the normal parent notification path.',
|
|
180
|
+
parameters,
|
|
181
|
+
output: {
|
|
182
|
+
schema: outputSchema,
|
|
183
|
+
render: (_args, value) => [{ type: 'text', text: renderParallelStart(value) }],
|
|
184
|
+
},
|
|
185
|
+
isConcurrencySafe: () => true,
|
|
186
|
+
async execute(args, exec) {
|
|
187
|
+
if (exec === undefined || exec === null || exec.agent === undefined || exec.agent === null) {
|
|
188
|
+
throw new Error('subagent_agy_parallel requires a calling agent (exec.agent was undefined)');
|
|
189
|
+
}
|
|
190
|
+
const tasks = normalizeParallelTasks(args?.tasks, maxTasks);
|
|
191
|
+
const settled = await Promise.allSettled(tasks.map(async (task) => await tctx.subagents.startActivation({
|
|
192
|
+
provider,
|
|
193
|
+
label: task.description,
|
|
194
|
+
request: {
|
|
195
|
+
prompt: [{ type: 'text', text: task.prompt }],
|
|
196
|
+
parent: exec.agent,
|
|
197
|
+
...(task.cwd === undefined ? {} : { cwd: task.cwd }),
|
|
198
|
+
},
|
|
199
|
+
signal: exec.signal,
|
|
200
|
+
delivery: 'parent',
|
|
201
|
+
})));
|
|
202
|
+
|
|
203
|
+
const started = [];
|
|
204
|
+
const failed = [];
|
|
205
|
+
settled.forEach((outcome, index) => {
|
|
206
|
+
const task = tasks[index];
|
|
207
|
+
if (outcome.status === 'fulfilled') {
|
|
208
|
+
const subagentId = outcome.value !== null && typeof outcome.value === 'object' ? outcome.value.childId : undefined;
|
|
209
|
+
if (typeof subagentId !== 'string' || subagentId.length === 0) {
|
|
210
|
+
failed.push({ description: task.description, error: 'startActivation returned no childId' });
|
|
211
|
+
} else {
|
|
212
|
+
started.push({ description: task.description, subagentId });
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
failed.push({ description: task.description, error: errorText(outcome.reason) });
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
if (started.length === 0) {
|
|
220
|
+
throw new Error(`all parallel agy subagents failed: ${failed.map((item) => `${item.description}: ${item.error}`).join('; ')}`);
|
|
221
|
+
}
|
|
222
|
+
return { started, failed };
|
|
223
|
+
},
|
|
224
|
+
}), 'subagent-antigravity: parallel tool');
|
|
225
|
+
});
|
|
226
|
+
}
|
package/lib/run.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-shot Antigravity child lifecycle: spawn the real `agy` CLI through the
|
|
3
|
+
* shared subprocess seam, publish only after the process is controllable,
|
|
4
|
+
* flatten post-publication failures, and dispose to whole-range quiescence.
|
|
5
|
+
*
|
|
6
|
+
* @module dsh-subagent-agy/run
|
|
7
|
+
*/
|
|
8
|
+
import { randomUUID } from 'node:crypto';
|
|
9
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
10
|
+
import { brandString } from '@deepseek-ai/dsh-brand';
|
|
11
|
+
import { settleRunResult, subprocessRunHandle } from '@deepseek-ai/dsh-subagent';
|
|
12
|
+
import { AntigravityStream } from './wire.js';
|
|
13
|
+
import { classifyFailure } from './classify.js';
|
|
14
|
+
|
|
15
|
+
/** Default grace between subprocess termination tiers. */
|
|
16
|
+
export const DEFAULT_DISPOSE_GRACE_MS = 3000;
|
|
17
|
+
|
|
18
|
+
/** ANSI/VT100 escape sequences (CSI, OSC, single-char escapes). */
|
|
19
|
+
const ANSI_ESCAPE = /\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Strip terminal escape sequences so child stderr does not pollute logs.
|
|
23
|
+
* @param {string} text
|
|
24
|
+
* @returns {string}
|
|
25
|
+
*/
|
|
26
|
+
export function stripAnsi(text) {
|
|
27
|
+
return text.replace(ANSI_ESCAPE, '');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Native non-interactive permission modes this provider can enforce. */
|
|
31
|
+
export const ANTIGRAVITY_PERMISSION_MODES = Object.freeze(['auto', 'dangerously-skip-permissions']);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Print mode soft-denies every tool confirmation unless permissions are skipped,
|
|
35
|
+
* so a child that cannot skip permissions can never read the workspace.
|
|
36
|
+
* `dangerously-skip-permissions` is therefore the only working default;
|
|
37
|
+
* `auto` remains selectable for prompts that need no tools at all.
|
|
38
|
+
*/
|
|
39
|
+
export const DEFAULT_ANTIGRAVITY_PERMISSION_MODE = 'dangerously-skip-permissions';
|
|
40
|
+
|
|
41
|
+
/** Fixed facts for one failed run. */
|
|
42
|
+
export class AntigravityRunFailure extends Error {
|
|
43
|
+
/** @param {{stage: string, category: string, outcome?: unknown}} facts */
|
|
44
|
+
constructor(facts, cause) {
|
|
45
|
+
super(`subagent-antigravity: Product subagent failure (${['product: Antigravity', `stage: ${facts.stage}`, `category: ${facts.category}`].join('; ')})`, cause === undefined ? undefined : { cause });
|
|
46
|
+
this.facts = facts;
|
|
47
|
+
this.name = 'AntigravityRunFailure';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function thrown(value) {
|
|
52
|
+
return value instanceof Error ? value : new Error(String(value));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Build the CLI argv for one run.
|
|
57
|
+
* @param {{executable: string, model?: string, effort?: string, permissionMode: string, printTimeout?: string, jsonSchema?: string, addDirs?: readonly string[], extraArgs: readonly string[], prompt: string, promptPrefix?: string}} spec
|
|
58
|
+
* @returns {string[]}
|
|
59
|
+
*/
|
|
60
|
+
export function antigravityArgv(spec) {
|
|
61
|
+
const prompt = spec.promptPrefix === undefined || spec.promptPrefix.length === 0
|
|
62
|
+
? spec.prompt
|
|
63
|
+
: `${spec.promptPrefix}\n\n${spec.prompt}`;
|
|
64
|
+
return [
|
|
65
|
+
spec.executable,
|
|
66
|
+
'--print',
|
|
67
|
+
prompt,
|
|
68
|
+
'--output-format',
|
|
69
|
+
'stream-json',
|
|
70
|
+
'--new-project',
|
|
71
|
+
...(spec.model === undefined ? [] : ['--model', spec.model]),
|
|
72
|
+
...(spec.effort === undefined ? [] : ['--effort', spec.effort]),
|
|
73
|
+
...(spec.permissionMode === 'dangerously-skip-permissions' ? ['--dangerously-skip-permissions'] : ['--mode', 'auto']),
|
|
74
|
+
...(spec.printTimeout === undefined ? [] : ['--print-timeout', spec.printTimeout]),
|
|
75
|
+
...(spec.jsonSchema === undefined ? [] : ['--json-schema', spec.jsonSchema]),
|
|
76
|
+
...(spec.addDirs === undefined ? [] : spec.addDirs.flatMap((dir) => ['--add-dir', dir])),
|
|
77
|
+
...spec.extraArgs,
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Validate and join the one-shot task before crossing the process boundary.
|
|
83
|
+
* @param {readonly {type: string, text?: string}[]} prompt
|
|
84
|
+
* @returns {string}
|
|
85
|
+
*/
|
|
86
|
+
export function textTask(prompt) {
|
|
87
|
+
if (prompt.length === 0) throw new Error('subagent-antigravity: the one-shot task must contain only text blocks');
|
|
88
|
+
const texts = [];
|
|
89
|
+
for (const block of prompt) {
|
|
90
|
+
if (block.type !== 'text') throw new Error('subagent-antigravity: the one-shot task must contain only text blocks');
|
|
91
|
+
texts.push(typeof block.text === 'string' ? block.text : '');
|
|
92
|
+
}
|
|
93
|
+
const joined = texts.join('');
|
|
94
|
+
if (joined.trim().length === 0) throw new Error('subagent-antigravity: the one-shot task must not be empty');
|
|
95
|
+
return joined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Wait for the CLI to reach its terminal envelope.
|
|
100
|
+
* @param {AntigravityStream} stream
|
|
101
|
+
* @param {{promise: Promise<void>, resolve: () => void}} terminal
|
|
102
|
+
* @returns {Promise<void>}
|
|
103
|
+
*/
|
|
104
|
+
async function awaitTerminal(stream, terminal) {
|
|
105
|
+
await terminal.promise;
|
|
106
|
+
stream.end();
|
|
107
|
+
if (stream.malformed !== undefined && !stream.terminalObserved) throw new AntigravityRunFailure({ stage: 'turn', category: 'protocol' }, new Error(stream.malformed));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Start the real `agy` child and publish its one-shot run.
|
|
112
|
+
* @param {{prompt: readonly {type: string}[], signal: AbortSignal, cwd?: string}} request
|
|
113
|
+
* @param {object} spec
|
|
114
|
+
* @returns {Promise<object>}
|
|
115
|
+
*/
|
|
116
|
+
export async function startAntigravityRun(request, spec) {
|
|
117
|
+
const prompt = textTask(request.prompt);
|
|
118
|
+
if (request.signal.aborted) throw new Error('subagent-antigravity: request was aborted before CLI startup');
|
|
119
|
+
let child;
|
|
120
|
+
try {
|
|
121
|
+
child = spec.spawn({
|
|
122
|
+
argv: antigravityArgv({ ...spec, prompt }),
|
|
123
|
+
cwd: spec.cwd,
|
|
124
|
+
stdio: { stdin: 'ignore', stdout: 'pipe', stderr: 'pipe' },
|
|
125
|
+
graceMs: spec.disposeGraceMs,
|
|
126
|
+
env: spec.env,
|
|
127
|
+
});
|
|
128
|
+
} catch (error) {
|
|
129
|
+
throw new AntigravityRunFailure({ stage: 'spawn', category: 'unknown' }, thrown(error));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const stream = new AntigravityStream('subagent-antigravity');
|
|
133
|
+
let stderrText = '';
|
|
134
|
+
const collectErrorText = () => [stream.errorText, stderrText].filter((value) => typeof value === 'string' && value.length > 0).join('\n');
|
|
135
|
+
let lastFailure = { kind: 'ok' };
|
|
136
|
+
const recordFailure = (failure) => {
|
|
137
|
+
lastFailure = failure;
|
|
138
|
+
if (spec.report !== undefined) spec.report.classification = failure;
|
|
139
|
+
};
|
|
140
|
+
const terminal = Promise.withResolvers();
|
|
141
|
+
const onStdout = (chunk) => {
|
|
142
|
+
stream.push(chunk);
|
|
143
|
+
if (stream.terminalObserved) terminal.resolve();
|
|
144
|
+
};
|
|
145
|
+
const onStderr = (chunk) => {
|
|
146
|
+
const bytes = typeof chunk === 'string' ? Buffer.from(chunk) : chunk;
|
|
147
|
+
try {
|
|
148
|
+
stderrText += bytes.toString('utf8');
|
|
149
|
+
if (stderrText.length > 16000) stderrText = stderrText.slice(-16000);
|
|
150
|
+
} catch {}
|
|
151
|
+
try {
|
|
152
|
+
spec.writeStderr(bytes);
|
|
153
|
+
} catch {}
|
|
154
|
+
};
|
|
155
|
+
child.stdout?.on('data', onStdout);
|
|
156
|
+
child.stderr?.on('data', onStderr);
|
|
157
|
+
|
|
158
|
+
const detachPipes = () => {
|
|
159
|
+
child.stdout?.off('data', onStdout);
|
|
160
|
+
child.stderr?.off('data', onStderr);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
let processFailureFacts;
|
|
164
|
+
/**
|
|
165
|
+
* A normally exited child is not a failure: `agy` prints its terminal
|
|
166
|
+
* envelope and exits, and the exit notification can win a race against the
|
|
167
|
+
* final `stdout` chunk. Only a non-zero exit rejects; a clean exit resolves
|
|
168
|
+
* so the caller can flush the remaining frames and read the envelope.
|
|
169
|
+
*/
|
|
170
|
+
const processSettled = child.done.then(
|
|
171
|
+
(outcome) => {
|
|
172
|
+
if (outcome?.exitCode === 0) return outcome;
|
|
173
|
+
processFailureFacts = { stage: 'process', category: 'process', outcome };
|
|
174
|
+
throw new AntigravityRunFailure(processFailureFacts);
|
|
175
|
+
},
|
|
176
|
+
(error) => {
|
|
177
|
+
processFailureFacts = { stage: 'process', category: 'unknown' };
|
|
178
|
+
throw new AntigravityRunFailure(processFailureFacts, thrown(error));
|
|
179
|
+
},
|
|
180
|
+
);
|
|
181
|
+
processSettled.catch(() => {});
|
|
182
|
+
|
|
183
|
+
const runAbort = new AbortController();
|
|
184
|
+
const requestCancel = () => {
|
|
185
|
+
if (runAbort.signal.aborted) return;
|
|
186
|
+
runAbort.abort(new Error('subagent-antigravity: run cancelled locally'));
|
|
187
|
+
};
|
|
188
|
+
const onAbort = () => {
|
|
189
|
+
requestCancel();
|
|
190
|
+
};
|
|
191
|
+
request.signal.addEventListener('abort', onAbort, { once: true });
|
|
192
|
+
|
|
193
|
+
const disposeProcess = async () => {
|
|
194
|
+
detachPipes();
|
|
195
|
+
try {
|
|
196
|
+
child.stdin?.end();
|
|
197
|
+
} catch {}
|
|
198
|
+
child.terminate();
|
|
199
|
+
await child.waitForExit();
|
|
200
|
+
await child.done.catch(() => {});
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
request.signal.throwIfAborted();
|
|
205
|
+
} catch {
|
|
206
|
+
detachPipes();
|
|
207
|
+
request.signal.removeEventListener('abort', onAbort);
|
|
208
|
+
await disposeProcess().catch(() => {});
|
|
209
|
+
throw new Error('subagent-antigravity: request was aborted before run publication');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
let diagnostic;
|
|
213
|
+
const result = settleRunResult({
|
|
214
|
+
attempt: async () => {
|
|
215
|
+
try {
|
|
216
|
+
await Promise.race([awaitTerminal(stream, terminal), processSettled]);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
const facts = error instanceof AntigravityRunFailure ? error.facts : {
|
|
219
|
+
stage: 'turn',
|
|
220
|
+
category: stream.malformed === undefined ? 'unknown' : 'protocol',
|
|
221
|
+
...(processFailureFacts === undefined ? {} : { outcome: processFailureFacts.outcome }),
|
|
222
|
+
};
|
|
223
|
+
const failure = error instanceof AntigravityRunFailure ? error : new AntigravityRunFailure(facts, thrown(error));
|
|
224
|
+
diagnostic = failure.message;
|
|
225
|
+
recordFailure(classifyFailure(collectErrorText(), processFailureFacts?.outcome));
|
|
226
|
+
throw failure;
|
|
227
|
+
}
|
|
228
|
+
stream.end();
|
|
229
|
+
const settled = stream.result();
|
|
230
|
+
if (settled.stopReason === 'error') {
|
|
231
|
+
const failureClass = classifyFailure(collectErrorText(), processFailureFacts?.outcome);
|
|
232
|
+
recordFailure(failureClass);
|
|
233
|
+
diagnostic ??= new AntigravityRunFailure({ stage: 'turn', category: 'product-error' }).message;
|
|
234
|
+
diagnostic += ` [${failureClass.kind}]`;
|
|
235
|
+
if (stream.conversationId !== undefined) diagnostic += ` (conversation: ${stream.conversationId})`;
|
|
236
|
+
} else {
|
|
237
|
+
recordFailure({ kind: 'ok' });
|
|
238
|
+
}
|
|
239
|
+
return settled;
|
|
240
|
+
},
|
|
241
|
+
collectOutput: () => stream.result().output,
|
|
242
|
+
collectDiagnostic: () => diagnostic,
|
|
243
|
+
cancelled: () => runAbort.signal.aborted,
|
|
244
|
+
onError: spec.onError,
|
|
245
|
+
signal: request.signal,
|
|
246
|
+
onAbort,
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
return subprocessRunHandle({
|
|
250
|
+
id: brandString(randomUUID()),
|
|
251
|
+
result,
|
|
252
|
+
signal: request.signal,
|
|
253
|
+
onAbort,
|
|
254
|
+
requestCancel,
|
|
255
|
+
teardown: disposeProcess,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Run the CLI once, optionally retrying a rate-limited / quota-exhausted
|
|
261
|
+
* attempt with a configured fallback model or a single rate-limit backoff.
|
|
262
|
+
* Retries only when explicitly configured; defaults to a single attempt.
|
|
263
|
+
* @param {{prompt: readonly {type: string}[], signal: AbortSignal, cwd?: string}} request
|
|
264
|
+
* @param {object} spec
|
|
265
|
+
* @returns {Promise<object>}
|
|
266
|
+
*/
|
|
267
|
+
export async function startAntigravityRunWithRetry(request, spec) {
|
|
268
|
+
const wantFallback = typeof spec.fallbackModel === 'string' && spec.fallbackModel.length > 0;
|
|
269
|
+
const wantRateRetry = spec.retryOnRateLimit === true;
|
|
270
|
+
if (!wantFallback && !wantRateRetry) return startAntigravityRun(request, spec);
|
|
271
|
+
const firstReport = {};
|
|
272
|
+
const first = await startAntigravityRun(request, { ...spec, report: firstReport });
|
|
273
|
+
let active = first;
|
|
274
|
+
const result = (async () => {
|
|
275
|
+
let current = first;
|
|
276
|
+
let currentReport = firstReport;
|
|
277
|
+
let attempt = 0;
|
|
278
|
+
for (;;) {
|
|
279
|
+
const settled = await current.result;
|
|
280
|
+
if (settled.stopReason !== 'error') return settled;
|
|
281
|
+
const info = currentReport.classification ?? { kind: 'unknown' };
|
|
282
|
+
const canFallback = attempt === 0 && wantFallback && (info.kind === 'quota_exhausted' || info.kind === 'rate_limited');
|
|
283
|
+
const canRateRetry = attempt === 0 && wantRateRetry && info.kind === 'rate_limited';
|
|
284
|
+
if (!canFallback && !canRateRetry) return settled;
|
|
285
|
+
await current.teardown().catch(() => {});
|
|
286
|
+
currentReport = {};
|
|
287
|
+
if (canFallback) {
|
|
288
|
+
current = await startAntigravityRun(request, { ...spec, model: spec.fallbackModel, report: currentReport });
|
|
289
|
+
} else {
|
|
290
|
+
await delay(Math.min(info.retryAfterMs ?? 2000, 15000), undefined, { signal: request.signal });
|
|
291
|
+
current = await startAntigravityRun(request, { ...spec, report: currentReport });
|
|
292
|
+
}
|
|
293
|
+
active = current;
|
|
294
|
+
attempt += 1;
|
|
295
|
+
}
|
|
296
|
+
})();
|
|
297
|
+
result.catch(() => {});
|
|
298
|
+
return subprocessRunHandle({
|
|
299
|
+
id: brandString(randomUUID()),
|
|
300
|
+
result,
|
|
301
|
+
signal: request.signal,
|
|
302
|
+
onAbort: () => {},
|
|
303
|
+
requestCancel: () => {
|
|
304
|
+
try {
|
|
305
|
+
active.requestCancel?.();
|
|
306
|
+
} catch {}
|
|
307
|
+
},
|
|
308
|
+
teardown: async () => {
|
|
309
|
+
try {
|
|
310
|
+
await active.teardown();
|
|
311
|
+
} catch {}
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profile-named Antigravity one-shot subagent provider.
|
|
3
|
+
*
|
|
4
|
+
* @module dsh-subagent-agy
|
|
5
|
+
*/
|
|
6
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
7
|
+
import z from '@deepseek-ai/schemastery';
|
|
8
|
+
|
|
9
|
+
export declare const name = 'subagent-antigravity';
|
|
10
|
+
export declare const inject: string[];
|
|
11
|
+
|
|
12
|
+
/** Native non-interactive permission modes this provider can enforce. */
|
|
13
|
+
export type AntigravityPermissionMode = 'auto' | 'dangerously-skip-permissions';
|
|
14
|
+
|
|
15
|
+
/** Reasoning effort accepted by the Antigravity CLI. */
|
|
16
|
+
export type AntigravityEffort = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
17
|
+
|
|
18
|
+
/** Deployment-owned CLI path, model, permission, environment, and process-release settings. */
|
|
19
|
+
export interface Config {
|
|
20
|
+
/** Provider name on `ctx.subagents` (default `antigravity`). */
|
|
21
|
+
providerName?: string;
|
|
22
|
+
/** Absolute path to the `agy` executable (default `%USERPROFILE%/.gemini/bin/agy.exe`). */
|
|
23
|
+
executable?: string;
|
|
24
|
+
/** Native Antigravity model fixed for this instance; omitted to inherit CLI settings. */
|
|
25
|
+
model?: string;
|
|
26
|
+
/** Native reasoning effort fixed for this instance. */
|
|
27
|
+
effort?: AntigravityEffort;
|
|
28
|
+
/** Explicit environment entries layered over the scrubbed parent environment. */
|
|
29
|
+
env?: Record<string, string>;
|
|
30
|
+
/** Native non-interactive permission mode fixed for this Provider instance. */
|
|
31
|
+
permissionMode?: AntigravityPermissionMode;
|
|
32
|
+
/** Extra CLI arguments appended verbatim. */
|
|
33
|
+
extraArgs?: string[];
|
|
34
|
+
/** Go-style duration for `--print-timeout` (e.g. "180s", "10m"); omitted to wait until the turn completes. */
|
|
35
|
+
printTimeout?: string;
|
|
36
|
+
/** JSON schema (inline or file path) for `--json-schema`, constraining the final structured result. */
|
|
37
|
+
jsonSchema?: string;
|
|
38
|
+
/** Extra workspace directories passed as repeatable `--add-dir`. */
|
|
39
|
+
addDirs?: string[];
|
|
40
|
+
/** Fallback native model to retry once when the primary attempt is rate-limited or out of quota; omitted to disable fallback. */
|
|
41
|
+
fallbackModel?: string;
|
|
42
|
+
/** Retry once with a short backoff when the attempt is rate-limited (HTTP 429). */
|
|
43
|
+
retryOnRateLimit?: boolean;
|
|
44
|
+
/** Grace in milliseconds between managed-range termination tiers. */
|
|
45
|
+
disposeGraceMs?: number;
|
|
46
|
+
/** Directory of the persistent browser profile used by the Gemini web Deep Research panel (default `~/.dsh/gemini-web-research/chrome-profile`). */
|
|
47
|
+
geminiProfileDir?: string;
|
|
48
|
+
/** Python executable used to launch the Playwright scripts (default `python`). */
|
|
49
|
+
geminiPython?: string;
|
|
50
|
+
/** Run the research browser headless; login initialization is always headed (default true). */
|
|
51
|
+
geminiHeadless?: boolean;
|
|
52
|
+
/** Hard timeout in milliseconds for one research job (default 900000). */
|
|
53
|
+
geminiTimeoutMs?: number;
|
|
54
|
+
/** Provider name for the native Antigravity parallel-team variant (default `antigravity-team`). */
|
|
55
|
+
teamProviderName?: string;
|
|
56
|
+
/** Register the `antigravity-team` provider in addition to the default provider (default true). */
|
|
57
|
+
teamEnabled?: boolean;
|
|
58
|
+
/** Model-facing tool name for the DSH-side batch delegation tool (default `subagent_agy_parallel`). */
|
|
59
|
+
parallelToolName?: string;
|
|
60
|
+
/** Maximum tasks accepted by the batch delegation tool (default 8). */
|
|
61
|
+
parallelMaxTasks?: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export declare const Config: z<Config>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Register one Profile-named Antigravity provider.
|
|
68
|
+
* @param ctx context carrying shared subagent and subprocess services.
|
|
69
|
+
* @param config registry name, CLI path, model, permission mode, environment, and disposal grace.
|
|
70
|
+
*/
|
|
71
|
+
export declare function apply(ctx: Context, config: Config): void;
|