@coda-console/antigravity 1.3.0 → 1.3.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/agent/entry.mjs +18 -2
- package/agent/exit.mjs +12 -0
- package/package.json +1 -1
package/agent/entry.mjs
CHANGED
|
@@ -10,13 +10,20 @@
|
|
|
10
10
|
// `_meta.coda.probe: true` opens a session of this connection alone, answered from the catalog and never sent to agy; so
|
|
11
11
|
// does every request about a session of the `coda-probe:` namespace. What real sessions say of their options is held to
|
|
12
12
|
// the catalog, which one that differs marks to be collected again.
|
|
13
|
+
// 4. When agy ends on its own (not as Coda's input closing or a signal to this process stops it) with a non-zero exit code, a
|
|
14
|
+
// signal or a prompt unanswered, the log and the prompts still waiting say how (exit.mjs).
|
|
13
15
|
import { spawn } from 'node:child_process';
|
|
14
16
|
import { agyBinary } from '../scripts/agy.mjs';
|
|
15
17
|
import { createCatalog } from './catalog.mjs';
|
|
16
18
|
import { PREFIX, Probes, probeMark } from './probe.mjs';
|
|
19
|
+
import { describeExit, endedError } from './exit.mjs';
|
|
17
20
|
|
|
18
21
|
const binary = agyBinary() ?? 'agy';
|
|
19
|
-
const agy = spawn(binary, ['acp'], { stdio: ['pipe', 'pipe', '
|
|
22
|
+
const agy = spawn(binary, ['acp'], { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
23
|
+
let stderr = '';
|
|
24
|
+
agy.stderr.on('data', chunk => { process.stderr.write(chunk); stderr = (stderr + chunk).slice(-2048); });
|
|
25
|
+
// The ids of the prompts Coda has asked and agy has not answered yet.
|
|
26
|
+
const prompts = new Set();
|
|
20
27
|
const initializing = new Set();
|
|
21
28
|
const sessionRequests = new Set();
|
|
22
29
|
const configRequests = new Map(); // request id -> { sessionId, was }: a set_config_option, whose answer lists the options; `was` for a mode switch, undone if agy refuses it
|
|
@@ -76,6 +83,7 @@ relay(process.stdin, agy.stdin, message => {
|
|
|
76
83
|
if ('id' in message) answer(id, probes.handle(method, params));
|
|
77
84
|
return false;
|
|
78
85
|
}
|
|
86
|
+
if (method === 'session/prompt' && 'id' in message) prompts.add(id);
|
|
79
87
|
if (method === 'initialize' && 'id' in message) initializing.add(id);
|
|
80
88
|
if (['session/new', 'session/load', 'session/resume'].includes(method)) { delete params?.additionalDirectories; sessionRequests.add(id); }
|
|
81
89
|
if (method === 'session/set_mode' && typeof params?.sessionId === 'string') {
|
|
@@ -93,6 +101,7 @@ relay(process.stdin, agy.stdin, message => {
|
|
|
93
101
|
relay(agy.stdout, process.stdout, message => {
|
|
94
102
|
const { method, params, id } = message;
|
|
95
103
|
if (!method) {
|
|
104
|
+
prompts.delete(id);
|
|
96
105
|
if (initializing.delete(id) && message.result?.agentCapabilities) {
|
|
97
106
|
const capabilities = message.result.agentCapabilities;
|
|
98
107
|
for (const key of ['sessionCapabilities', 'session_capabilities']) delete capabilities[key]?.additionalDirectories;
|
|
@@ -133,6 +142,13 @@ const stop = () => {
|
|
|
133
142
|
};
|
|
134
143
|
agy.stdin.on('error', () => {});
|
|
135
144
|
agy.on('error', () => process.exit(1));
|
|
136
|
-
agy.on('close', code =>
|
|
145
|
+
agy.on('close', (code, signal) => {
|
|
146
|
+
if (!stopping && (code !== 0 || prompts.size)) {
|
|
147
|
+
const message = describeExit({ code, signal, stderr });
|
|
148
|
+
process.stderr.write(`${message}\n`);
|
|
149
|
+
for (const id of prompts) answer(id, { error: endedError(message) });
|
|
150
|
+
}
|
|
151
|
+
process.stdout.write('', () => process.exit(stopping ? 0 : code ?? 1));
|
|
152
|
+
});
|
|
137
153
|
process.stdin.on('end', stop);
|
|
138
154
|
for (const signal of ['SIGTERM', 'SIGINT', 'SIGHUP']) process.once(signal, stop);
|
package/agent/exit.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// How `agy acp` ended, as the plugin's log and the turns it leaves waiting say it: its exit code or the signal that killed it,
|
|
2
|
+
// and the last lines it wrote to stderr. Told when the process ends on its own with a prompt unanswered, or with a non-zero exit code or a signal.
|
|
3
|
+
export function describeExit({ code, signal, stderr }) {
|
|
4
|
+
const tail = stderr.trim().split('\n').slice(-5).join('\n').slice(-1000);
|
|
5
|
+
return `Antigravity 进程意外退出(${signal ? `被信号 ${signal} 终止` : `退出码 ${code}`})${tail ? `,stderr 末尾:\n${tail}` : ''}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// The error that ends a prompt as the process ends (docs/agent-protocol.md「原生会话已结束」): the category tells Coda the native
|
|
9
|
+
// session is over, not that the service failed. `input` is not written: nothing the
|
|
10
|
+
// process said proves this prompt was read, and Coda then resumes by checking first, with the whole original input.
|
|
11
|
+
export const endedError = message => ({ code: -32603, message,
|
|
12
|
+
data: { _meta: { coda: { failure: { kind: 'session_ended' } } } } });
|