autodev-cli 1.4.190 → 1.4.192
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/out/pendingSteers.d.ts +28 -0
- package/out/pendingSteers.js +145 -0
- package/out/pendingSteers.js.map +1 -0
- package/out/providers/acp/AcpSession.d.ts +197 -0
- package/out/providers/acp/AcpSession.js +701 -0
- package/out/providers/acp/AcpSession.js.map +1 -0
- package/out/providers/grok/GrokAcpSession.d.ts +11 -112
- package/out/providers/grok/GrokAcpSession.js +40 -493
- package/out/providers/grok/GrokAcpSession.js.map +1 -1
- package/out/providers/grok/tui.d.ts +18 -0
- package/out/providers/grok/tui.js +62 -1
- package/out/providers/grok/tui.js.map +1 -1
- package/out/providers/opencode/acp.d.ts +52 -0
- package/out/providers/opencode/acp.js +427 -0
- package/out/providers/opencode/acp.js.map +1 -0
- package/out/providers/opencode/sdk.d.ts +10 -8
- package/out/providers/opencode/sdk.js +38 -5
- package/out/providers/opencode/sdk.js.map +1 -1
- package/out/taskLoop.d.ts +21 -0
- package/out/taskLoop.js +137 -2
- package/out/taskLoop.js.map +1 -1
- package/out/webSocketPoller.d.ts +6 -2
- package/out/webSocketPoller.js +8 -2
- package/out/webSocketPoller.js.map +1 -1
- package/out/webhookPoller.d.ts +4 -1
- package/out/webhookPoller.js +7 -0
- package/out/webhookPoller.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// opencode ACP — native `opencode acp` driven through the shared AcpSession.
|
|
4
|
+
//
|
|
5
|
+
// opencode ships FIRST-PARTY ACP (`opencode acp`, verified live on opencode
|
|
6
|
+
// 1.14.22): the same line-delimited JSON-RPC 2.0 protocol grok speaks, so we
|
|
7
|
+
// reuse the exact AcpSession client. One long-lived `opencode acp` process per
|
|
8
|
+
// workspace root, fed each turn, kept alive; resume only at (re)start via
|
|
9
|
+
// session/load (never minting a new session per turn — the opencode-session-
|
|
10
|
+
// explosion guard).
|
|
11
|
+
//
|
|
12
|
+
// This layer is the opencode BINDING of AcpSession:
|
|
13
|
+
// - the launch spec: `opencode [-m MODEL] acp` (global -m BEFORE the acp
|
|
14
|
+
// subcommand; the acp subcommand itself rejects -m). The MODEL comes from the
|
|
15
|
+
// agent's settings (settings.opencodeModel) — a real, usable model. NB the
|
|
16
|
+
// free `opencode/*` zen models return empty over raw ACP ("only usable from
|
|
17
|
+
// within OpenCode"), so an empty clean turn is surfaced as a clear log.
|
|
18
|
+
// - host hooks that emit the SAME canonical hook events (provider
|
|
19
|
+
// 'opencode-sdk') + live narration + secret redaction the SDK path emits, so
|
|
20
|
+
// pixel-office sees an identical event stream whether opencode runs via ACP
|
|
21
|
+
// or the createOpencode server.
|
|
22
|
+
// - gate `AUTODEV_OPENCODE_ACP` (default ON when `opencode acp` is available)
|
|
23
|
+
// with the createOpencode-server path as automatic fallback (wired in sdk.ts).
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
28
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
29
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
30
|
+
}
|
|
31
|
+
Object.defineProperty(o, k2, desc);
|
|
32
|
+
}) : (function(o, m, k, k2) {
|
|
33
|
+
if (k2 === undefined) k2 = k;
|
|
34
|
+
o[k2] = m[k];
|
|
35
|
+
}));
|
|
36
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
37
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
38
|
+
}) : function(o, v) {
|
|
39
|
+
o["default"] = v;
|
|
40
|
+
});
|
|
41
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
42
|
+
var ownKeys = function(o) {
|
|
43
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
44
|
+
var ar = [];
|
|
45
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
46
|
+
return ar;
|
|
47
|
+
};
|
|
48
|
+
return ownKeys(o);
|
|
49
|
+
};
|
|
50
|
+
return function (mod) {
|
|
51
|
+
if (mod && mod.__esModule) return mod;
|
|
52
|
+
var result = {};
|
|
53
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
54
|
+
__setModuleDefault(result, mod);
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
})();
|
|
58
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
+
exports.OPENCODE_ACP_SPEC = void 0;
|
|
60
|
+
exports.opencodeAcpSupported = opencodeAcpSupported;
|
|
61
|
+
exports.__setOpencodeAcpEnabledForTest = __setOpencodeAcpEnabledForTest;
|
|
62
|
+
exports.opencodeAcpEnabled = opencodeAcpEnabled;
|
|
63
|
+
exports.isOpencodeAcpBusy = isOpencodeAcpBusy;
|
|
64
|
+
exports.getOpencodeAcpActivity = getOpencodeAcpActivity;
|
|
65
|
+
exports.getOpencodeAcpLatestSessionId = getOpencodeAcpLatestSessionId;
|
|
66
|
+
exports.hasOpencodeAcpSession = hasOpencodeAcpSession;
|
|
67
|
+
exports.sendOpencodeAcpPrompt = sendOpencodeAcpPrompt;
|
|
68
|
+
exports.steerOpencodeAcp = steerOpencodeAcp;
|
|
69
|
+
exports.steerOpencodeAcpTracked = steerOpencodeAcpTracked;
|
|
70
|
+
exports.ensureOpencodeAcpSteer = ensureOpencodeAcpSteer;
|
|
71
|
+
exports.compactOpencodeAcp = compactOpencodeAcp;
|
|
72
|
+
exports.forceIdleOpencodeAcp = forceIdleOpencodeAcp;
|
|
73
|
+
exports.closeOpencodeAcp = closeOpencodeAcp;
|
|
74
|
+
exports.closeAllOpencodeAcp = closeAllOpencodeAcp;
|
|
75
|
+
const fs = __importStar(require("fs"));
|
|
76
|
+
const path = __importStar(require("path"));
|
|
77
|
+
const child_process = __importStar(require("child_process"));
|
|
78
|
+
const AcpSession_1 = require("../acp/AcpSession");
|
|
79
|
+
const ProviderNormalizer_1 = require("../base/ProviderNormalizer");
|
|
80
|
+
const redactSecrets_1 = require("../../core/redactSecrets");
|
|
81
|
+
const OPENCODE_BIN = 'opencode';
|
|
82
|
+
/** opencode's ACP launch spec. NB the model is NOT a CLI arg — `opencode acp`
|
|
83
|
+
* rejects `-m` (and the global `-m … acp` form exits 1). The model is injected
|
|
84
|
+
* via a merged OPENCODE_CONFIG file instead (see _writeAcpConfig). */
|
|
85
|
+
exports.OPENCODE_ACP_SPEC = {
|
|
86
|
+
buildArgs(_model, extraArgs) {
|
|
87
|
+
return [...extraArgs, 'acp'];
|
|
88
|
+
},
|
|
89
|
+
decodeUpdate: AcpSession_1.decodeAcpUpdateStandard,
|
|
90
|
+
narrationTitle: 'opencode',
|
|
91
|
+
narrateReasoning: false, // keep opencode's agent_thought_chunk out of the feed
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Write a MERGED opencode config to `<root>/.autodev/opencode-acp.json` and return
|
|
95
|
+
* its path — the workspace `opencode.json` (which carries autodev's office/operate
|
|
96
|
+
* MCP) with the agent's model layered in (and permission:allow ensured). Pointed
|
|
97
|
+
* at via OPENCODE_CONFIG so `opencode acp` runs the right model WITHOUT the CLI
|
|
98
|
+
* -m flag and WITHOUT mutating the workspace file. Returns undefined on failure
|
|
99
|
+
* (the session then just runs with opencode's own resolved config/model).
|
|
100
|
+
*/
|
|
101
|
+
function _writeAcpConfig(root, model) {
|
|
102
|
+
try {
|
|
103
|
+
let cfg = {};
|
|
104
|
+
const wsFile = path.join(root, 'opencode.json');
|
|
105
|
+
if (fs.existsSync(wsFile)) {
|
|
106
|
+
try {
|
|
107
|
+
cfg = JSON.parse(fs.readFileSync(wsFile, 'utf8'));
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
cfg = {};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!cfg['$schema']) {
|
|
114
|
+
cfg['$schema'] = 'https://opencode.ai/config.json';
|
|
115
|
+
}
|
|
116
|
+
if (model) {
|
|
117
|
+
cfg['model'] = model;
|
|
118
|
+
}
|
|
119
|
+
if (!cfg['permission']) {
|
|
120
|
+
cfg['permission'] = { '*': 'allow' };
|
|
121
|
+
} // empty client caps → opencode does its own I/O
|
|
122
|
+
const dir = path.join(root, '.autodev');
|
|
123
|
+
if (!fs.existsSync(dir)) {
|
|
124
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
125
|
+
}
|
|
126
|
+
const out = path.join(dir, 'opencode-acp.json');
|
|
127
|
+
fs.writeFileSync(out, JSON.stringify(cfg, null, 2), 'utf8');
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// --- persistent state (one AcpSession per root) ---------------------------
|
|
135
|
+
const _acpSessions = new Map();
|
|
136
|
+
/** Roots with an opencode ACP turn dispatched (busy synchronously from dispatch
|
|
137
|
+
* through full drain — covers the window before AcpSession.runTurn sets busy). */
|
|
138
|
+
const _acpBusyRoots = new Set();
|
|
139
|
+
const _latestSessionIds = new Map();
|
|
140
|
+
// --- availability gate ----------------------------------------------------
|
|
141
|
+
let _opencodeAcpSupported = null;
|
|
142
|
+
/** Cached probe: is `opencode acp` a real subcommand? (opencode prints its help
|
|
143
|
+
* to STDERR, so we merge 2>&1 and look for the ACP banner.) */
|
|
144
|
+
function opencodeAcpSupported() {
|
|
145
|
+
if (_opencodeAcpSupported !== null) {
|
|
146
|
+
return _opencodeAcpSupported;
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
const out = child_process.execSync(`${OPENCODE_BIN} acp --help 2>&1`, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: 10000 });
|
|
150
|
+
_opencodeAcpSupported = /Agent Client Protocol|\bACP\b/i.test(out);
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
_opencodeAcpSupported = false;
|
|
154
|
+
}
|
|
155
|
+
return _opencodeAcpSupported;
|
|
156
|
+
}
|
|
157
|
+
let _opencodeAcpTestOverride = null;
|
|
158
|
+
/** Test-only: force the ACP enablement decision. */
|
|
159
|
+
function __setOpencodeAcpEnabledForTest(v) { _opencodeAcpTestOverride = v; }
|
|
160
|
+
/**
|
|
161
|
+
* Whether opencode should run over native ACP instead of the createOpencode
|
|
162
|
+
* server. Gated by AUTODEV_OPENCODE_ACP (false/0/off/no forces the server path)
|
|
163
|
+
* AND `opencode acp` being available. Default ON when available.
|
|
164
|
+
*/
|
|
165
|
+
function opencodeAcpEnabled(env = process.env) {
|
|
166
|
+
if (_opencodeAcpTestOverride !== null) {
|
|
167
|
+
return _opencodeAcpTestOverride;
|
|
168
|
+
}
|
|
169
|
+
const raw = String(env['AUTODEV_OPENCODE_ACP'] ?? '').toLowerCase();
|
|
170
|
+
if (raw === 'false' || raw === '0' || raw === 'off' || raw === 'no') {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
return opencodeAcpSupported();
|
|
174
|
+
}
|
|
175
|
+
// --- canonical hook emission (parity with grok ACP + the opencode-sdk sink) --
|
|
176
|
+
function _emitOpencodeHook(root, hookEventName, extra = {}) {
|
|
177
|
+
try {
|
|
178
|
+
const dir = path.join(root, '.autodev');
|
|
179
|
+
if (!fs.existsSync(dir)) {
|
|
180
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
181
|
+
}
|
|
182
|
+
const ev = { hook_event_name: hookEventName, event_type: (0, ProviderNormalizer_1.eventTypeFor)(hookEventName), provider: 'opencode-sdk', cwd: root, timestamp: new Date().toISOString(), ...extra };
|
|
183
|
+
fs.appendFileSync(path.join(dir, 'hooks-events.jsonl'), JSON.stringify(ev) + '\n', 'utf8');
|
|
184
|
+
}
|
|
185
|
+
catch { /* non-critical */ }
|
|
186
|
+
}
|
|
187
|
+
/** Get (or lazily create) the persistent opencode ACP session for a root. */
|
|
188
|
+
function _getOrCreate(root, model, log, resumeSessionId) {
|
|
189
|
+
let sess = _acpSessions.get(root);
|
|
190
|
+
if (sess) {
|
|
191
|
+
return sess;
|
|
192
|
+
}
|
|
193
|
+
const seedId = resumeSessionId || _latestSessionIds.get(root) || undefined;
|
|
194
|
+
const hooks = {
|
|
195
|
+
emitHook: (name, e) => {
|
|
196
|
+
if (name === 'Notification' && typeof e['message'] === 'string') {
|
|
197
|
+
const msg = (0, redactSecrets_1.redactSecrets)(String(e['message'])).slice(0, 1200);
|
|
198
|
+
if (!msg.trim()) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
_emitOpencodeHook(root, 'Notification', { ...e, message: msg });
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
_emitOpencodeHook(root, name, (0, redactSecrets_1.redactDeep)(e));
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
log,
|
|
208
|
+
};
|
|
209
|
+
const cfgPath = _writeAcpConfig(root, model);
|
|
210
|
+
const extraEnv = cfgPath ? { OPENCODE_CONFIG: cfgPath } : {};
|
|
211
|
+
sess = new AcpSession_1.AcpSession({ root, model, bin: OPENCODE_BIN, hooks, spec: exports.OPENCODE_ACP_SPEC, initialSessionId: seedId, extraEnv });
|
|
212
|
+
_acpSessions.set(root, sess);
|
|
213
|
+
return sess;
|
|
214
|
+
}
|
|
215
|
+
/** True while an opencode ACP turn (incl. steered continuations) is running. */
|
|
216
|
+
function isOpencodeAcpBusy(root) {
|
|
217
|
+
if (_acpBusyRoots.has(root)) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
const s = _acpSessions.get(root);
|
|
221
|
+
return !!s && s.isBusy();
|
|
222
|
+
}
|
|
223
|
+
/** Current tool activity label for the root (undefined = idle). */
|
|
224
|
+
function getOpencodeAcpActivity(root) {
|
|
225
|
+
return _acpSessions.get(root)?.activity;
|
|
226
|
+
}
|
|
227
|
+
/** Latest opencode ACP session id (for resume-on-restart / session save). */
|
|
228
|
+
function getOpencodeAcpLatestSessionId(root) {
|
|
229
|
+
return _acpSessions.get(root)?.sessionId ?? _latestSessionIds.get(root);
|
|
230
|
+
}
|
|
231
|
+
/** Is an opencode ACP session currently held for this root? */
|
|
232
|
+
function hasOpencodeAcpSession(root) {
|
|
233
|
+
return _acpSessions.has(root);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Run ONE turn through the persistent opencode ACP session. Mirrors the SDK
|
|
237
|
+
* path's stdout/exit contract. On ACP startup failure, calls `onAcpUnavailable`
|
|
238
|
+
* (the createOpencode-server fallback) and does NOT write the exit file itself.
|
|
239
|
+
*/
|
|
240
|
+
function sendOpencodeAcpPrompt(root, promptFilePath, resumeSessionId, stdoutFile, exitFile, log, model, showOutput, onAcpUnavailable) {
|
|
241
|
+
try {
|
|
242
|
+
fs.writeFileSync(stdoutFile, '', 'utf8');
|
|
243
|
+
}
|
|
244
|
+
catch { /* ignore */ }
|
|
245
|
+
try {
|
|
246
|
+
fs.writeFileSync(exitFile, '', 'utf8');
|
|
247
|
+
}
|
|
248
|
+
catch { /* ignore */ }
|
|
249
|
+
let promptText = '';
|
|
250
|
+
try {
|
|
251
|
+
promptText = fs.readFileSync(promptFilePath, 'utf8');
|
|
252
|
+
}
|
|
253
|
+
catch (err) {
|
|
254
|
+
try {
|
|
255
|
+
fs.appendFileSync(stdoutFile, `\n[OpenCode ACP: cannot read prompt file: ${err?.message ?? err}]\n`, 'utf8');
|
|
256
|
+
}
|
|
257
|
+
catch { /* ignore */ }
|
|
258
|
+
try {
|
|
259
|
+
fs.writeFileSync(exitFile, '1\n', 'utf8');
|
|
260
|
+
}
|
|
261
|
+
catch { /* ignore */ }
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const sess = _getOrCreate(root, model, log, resumeSessionId);
|
|
265
|
+
_acpBusyRoots.add(root); // synchronous busy (before runTurn flips its own flag)
|
|
266
|
+
if (showOutput) {
|
|
267
|
+
try {
|
|
268
|
+
showOutput();
|
|
269
|
+
}
|
|
270
|
+
catch { /* ignore */ }
|
|
271
|
+
}
|
|
272
|
+
const sink = (text) => { try {
|
|
273
|
+
fs.appendFileSync(stdoutFile, text, 'utf8');
|
|
274
|
+
}
|
|
275
|
+
catch { /* ignore */ } };
|
|
276
|
+
void (async () => {
|
|
277
|
+
try {
|
|
278
|
+
await sess.ensureReady();
|
|
279
|
+
}
|
|
280
|
+
catch (err) {
|
|
281
|
+
log(`OpenCode ACP: startup failed (${err?.message ?? err}); stderr="${sess.stderrSnapshot.slice(0, 200)}" — falling back to createOpencode server`);
|
|
282
|
+
try {
|
|
283
|
+
sess.close();
|
|
284
|
+
}
|
|
285
|
+
catch { /* ignore */ }
|
|
286
|
+
_acpSessions.delete(root);
|
|
287
|
+
_acpBusyRoots.delete(root); // hand the busy flag over to the server path
|
|
288
|
+
onAcpUnavailable();
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (sess.sessionId) {
|
|
292
|
+
_latestSessionIds.set(root, sess.sessionId);
|
|
293
|
+
}
|
|
294
|
+
let res;
|
|
295
|
+
try {
|
|
296
|
+
res = await sess.runTurn(promptText, sink);
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
res = { clean: false, stopReason: 'exception', error: err?.message ?? String(err) };
|
|
300
|
+
}
|
|
301
|
+
if (res.emptyOutput) {
|
|
302
|
+
log(`OpenCode ACP: turn produced NO output (stopReason=${res.stopReason}). The model "${model ?? '(default)'}" may be an unusable free zen model or misconfigured — set a real model (e.g. ollama-cloud/gpt-oss:20b or a configured provider) in the agent settings.`);
|
|
303
|
+
try {
|
|
304
|
+
fs.appendFileSync(stdoutFile, `\n[OpenCode ACP: empty turn — check the configured model "${model ?? '(default)'}"]\n`, 'utf8');
|
|
305
|
+
}
|
|
306
|
+
catch { /* ignore */ }
|
|
307
|
+
}
|
|
308
|
+
if (!res.clean && res.error) {
|
|
309
|
+
try {
|
|
310
|
+
fs.appendFileSync(stdoutFile, `\n[OpenCode ACP: turn ended ${res.stopReason} — ${res.error}]\n`, 'utf8');
|
|
311
|
+
}
|
|
312
|
+
catch { /* ignore */ }
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
fs.writeFileSync(exitFile, `${res.clean ? 0 : 1}\n`, 'utf8');
|
|
316
|
+
}
|
|
317
|
+
catch { /* ignore */ }
|
|
318
|
+
_acpBusyRoots.delete(root);
|
|
319
|
+
})();
|
|
320
|
+
}
|
|
321
|
+
/** Steer the live opencode ACP process mid-turn (a queued session/prompt). */
|
|
322
|
+
function steerOpencodeAcp(root, text, log) {
|
|
323
|
+
const sess = _acpSessions.get(root);
|
|
324
|
+
if (!sess || !sess.isAlive()) {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
const ok = sess.steer(text);
|
|
328
|
+
if (ok) {
|
|
329
|
+
log(`OpenCode ACP: steered live process (${text.length} chars) — queued to the running session`);
|
|
330
|
+
}
|
|
331
|
+
return ok;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Durable-steer delivery to an EXISTING live opencode ACP session. Resolves when
|
|
335
|
+
* the steered turn COMPLETES; null when no live session exists (caller keeps the
|
|
336
|
+
* steer queued and retries via {@link ensureOpencodeAcpSteer}).
|
|
337
|
+
*/
|
|
338
|
+
function steerOpencodeAcpTracked(root, text, log) {
|
|
339
|
+
const sess = _acpSessions.get(root);
|
|
340
|
+
if (!sess || !sess.isAlive()) {
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
const p = sess.steerTracked(text);
|
|
344
|
+
if (p) {
|
|
345
|
+
log(`OpenCode ACP: durable steer delivered to live session (${text.length} chars) — awaiting completion`);
|
|
346
|
+
}
|
|
347
|
+
return p;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Restart-drain delivery: ENSURE a live opencode ACP session (spawn + session/load
|
|
351
|
+
* if none is held), then deliver the steer and await completion. Returns the turn
|
|
352
|
+
* result, or null when the session could not be brought up.
|
|
353
|
+
*/
|
|
354
|
+
async function ensureOpencodeAcpSteer(root, model, text, log) {
|
|
355
|
+
if (!opencodeAcpEnabled()) {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
const sess = _getOrCreate(root, model, log, undefined);
|
|
359
|
+
try {
|
|
360
|
+
await sess.ensureReady();
|
|
361
|
+
}
|
|
362
|
+
catch (err) {
|
|
363
|
+
log(`OpenCode ACP: durable-steer ensureReady failed (${err?.message ?? err})`);
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
if (sess.sessionId) {
|
|
367
|
+
_latestSessionIds.set(root, sess.sessionId);
|
|
368
|
+
}
|
|
369
|
+
const p = sess.steerTracked(text);
|
|
370
|
+
if (!p) {
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
log(`OpenCode ACP: durable steer (re)delivered on restart-drain (${text.length} chars) — awaiting completion`);
|
|
374
|
+
return p;
|
|
375
|
+
}
|
|
376
|
+
/** Best-effort /compact on the live opencode ACP session (quiet, no Stop hook). */
|
|
377
|
+
async function compactOpencodeAcp(root, log) {
|
|
378
|
+
const sess = _acpSessions.get(root);
|
|
379
|
+
if (!sess) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
log('OpenCode ACP: requesting /compact');
|
|
383
|
+
await sess.sendQuiet('/compact');
|
|
384
|
+
}
|
|
385
|
+
/** Force-clear busy + evict the ACP session for a root. */
|
|
386
|
+
function forceIdleOpencodeAcp(root) {
|
|
387
|
+
_acpBusyRoots.delete(root);
|
|
388
|
+
const sess = _acpSessions.get(root);
|
|
389
|
+
if (sess) {
|
|
390
|
+
if (sess.pid) {
|
|
391
|
+
try {
|
|
392
|
+
child_process.spawn('kill', ['-9', String(sess.pid)]);
|
|
393
|
+
}
|
|
394
|
+
catch { /* ignore */ }
|
|
395
|
+
}
|
|
396
|
+
try {
|
|
397
|
+
sess.close();
|
|
398
|
+
}
|
|
399
|
+
catch { /* ignore */ }
|
|
400
|
+
_acpSessions.delete(root);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/** Close + evict the opencode ACP session for a root (preserves session id). */
|
|
404
|
+
function closeOpencodeAcp(root, log) {
|
|
405
|
+
const sess = _acpSessions.get(root);
|
|
406
|
+
if (sess) {
|
|
407
|
+
log('OpenCode ACP: closing persistent session');
|
|
408
|
+
try {
|
|
409
|
+
sess.close();
|
|
410
|
+
}
|
|
411
|
+
catch { /* ignore */ }
|
|
412
|
+
_acpSessions.delete(root);
|
|
413
|
+
}
|
|
414
|
+
_acpBusyRoots.delete(root);
|
|
415
|
+
}
|
|
416
|
+
/** Close all opencode ACP sessions — extension deactivate. */
|
|
417
|
+
function closeAllOpencodeAcp() {
|
|
418
|
+
for (const [, sess] of _acpSessions) {
|
|
419
|
+
try {
|
|
420
|
+
sess.close();
|
|
421
|
+
}
|
|
422
|
+
catch { /* ignore */ }
|
|
423
|
+
}
|
|
424
|
+
_acpSessions.clear();
|
|
425
|
+
_acpBusyRoots.clear();
|
|
426
|
+
}
|
|
427
|
+
//# sourceMappingURL=acp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp.js","sourceRoot":"","sources":["../../../src/providers/opencode/acp.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,+EAA+E;AAC/E,0EAA0E;AAC1E,6EAA6E;AAC7E,oBAAoB;AACpB,EAAE;AACF,oDAAoD;AACpD,2EAA2E;AAC3E,kFAAkF;AAClF,+EAA+E;AAC/E,gFAAgF;AAChF,4EAA4E;AAC5E,oEAAoE;AACpE,iFAAiF;AACjF,gFAAgF;AAChF,oCAAoC;AACpC,gFAAgF;AAChF,mFAAmF;AACnF,8EAA8E;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5B,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,SAAgB,gBAAgB,CAAC,IAAY,EAAE,GAA0B;IACvE,MAAM,IAAI,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,IAAI,EAAE,CAAC;QACT,GAAG,CAAC,0CAA0C,CAAC,CAAC;QAChD,IAAI,CAAC;YAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;QAC5C,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IACD,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED,8DAA8D;AAC9D,SAAgB,mBAAmB;IACjC,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,IAAI,YAAY,EAAE,CAAC;QAAC,IAAI,CAAC;YAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;IAAC,CAAC;IACrF,YAAY,CAAC,KAAK,EAAE,CAAC;IACrB,aAAa,CAAC,KAAK,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export { opencodeAcpEnabled, hasOpencodeAcpSession, steerOpencodeAcpTracked, ensureOpencodeAcpSteer } from './acp';
|
|
2
|
+
/** True while an opencode turn is running (ACP session OR createOpencode server). */
|
|
2
3
|
export declare function isOpencodeSdkBusy(root: string): boolean;
|
|
3
4
|
/** Current tool activity label for the given root (undefined = idle). */
|
|
4
5
|
export declare function getOpencodeSdkActivity(root: string): string | undefined;
|
|
@@ -17,13 +18,14 @@ export declare function opencodeSdkTransportAvailable(): boolean;
|
|
|
17
18
|
/** Test-only: force the persistence decision regardless of env/transport. */
|
|
18
19
|
export declare function __setOpencodeCliPersistentForTest(v: boolean | null): void;
|
|
19
20
|
export declare function opencodeCliPersistentEnabled(env?: NodeJS.ProcessEnv): boolean;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Router: prefer native `opencode acp` (persistent AcpSession) when enabled;
|
|
23
|
+
* otherwise use the createOpencode in-process server. On ACP startup failure the
|
|
24
|
+
* ACP layer transparently falls back to the server path (onAcpUnavailable), so
|
|
25
|
+
* nothing regresses. Both paths are "SDK-like" to the task loop (persistent,
|
|
26
|
+
* turn-end via isOpencodeSdkBusy) so no loop change is needed.
|
|
27
|
+
*/
|
|
28
|
+
export declare function sendOpencodeSdkPrompt(root: string, promptFilePath: string, resumeSessionId: string | undefined, stdoutFile: string, exitFile: string, log: (msg: string) => void, model?: string, showOutput?: () => void): void;
|
|
27
29
|
export declare function runOpencodeSdkCompact(root: string, log: (msg: string) => void): Promise<void>;
|
|
28
30
|
export declare function closeOpencodeSdkClient(root: string, log: (msg: string) => void): void;
|
|
29
31
|
/**
|
|
@@ -44,6 +44,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
44
44
|
};
|
|
45
45
|
})();
|
|
46
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
exports.ensureOpencodeAcpSteer = exports.steerOpencodeAcpTracked = exports.hasOpencodeAcpSession = exports.opencodeAcpEnabled = void 0;
|
|
47
48
|
exports.isOpencodeSdkBusy = isOpencodeSdkBusy;
|
|
48
49
|
exports.getOpencodeSdkActivity = getOpencodeSdkActivity;
|
|
49
50
|
exports.getOpencodeSdkLatestSessionId = getOpencodeSdkLatestSessionId;
|
|
@@ -62,6 +63,14 @@ const net = __importStar(require("net"));
|
|
|
62
63
|
const url_1 = require("url");
|
|
63
64
|
const hookEventNormalizer_1 = require("../../hookEventNormalizer");
|
|
64
65
|
const liveNarration_1 = require("../../core/liveNarration");
|
|
66
|
+
const acp_1 = require("./acp");
|
|
67
|
+
// Re-export the durable-steer primitives so the task loop can reach them through
|
|
68
|
+
// the same opencodeSdkProvider barrel it already uses.
|
|
69
|
+
var acp_2 = require("./acp");
|
|
70
|
+
Object.defineProperty(exports, "opencodeAcpEnabled", { enumerable: true, get: function () { return acp_2.opencodeAcpEnabled; } });
|
|
71
|
+
Object.defineProperty(exports, "hasOpencodeAcpSession", { enumerable: true, get: function () { return acp_2.hasOpencodeAcpSession; } });
|
|
72
|
+
Object.defineProperty(exports, "steerOpencodeAcpTracked", { enumerable: true, get: function () { return acp_2.steerOpencodeAcpTracked; } });
|
|
73
|
+
Object.defineProperty(exports, "ensureOpencodeAcpSteer", { enumerable: true, get: function () { return acp_2.ensureOpencodeAcpSteer; } });
|
|
65
74
|
const _state = new Map();
|
|
66
75
|
const _latestSessionIds = new Map();
|
|
67
76
|
/** Latest log function per root — updated every dispatch so the background logger always writes to the active channel. */
|
|
@@ -70,16 +79,16 @@ const _loggers = new Map();
|
|
|
70
79
|
const _activity = new Map();
|
|
71
80
|
/** Roots that currently have an opencode-sdk turn actively running. */
|
|
72
81
|
const _busyRoots = new Set();
|
|
73
|
-
/** True while an opencode
|
|
82
|
+
/** True while an opencode turn is running (ACP session OR createOpencode server). */
|
|
74
83
|
function isOpencodeSdkBusy(root) {
|
|
75
|
-
return _busyRoots.has(root);
|
|
84
|
+
return _busyRoots.has(root) || (0, acp_1.isOpencodeAcpBusy)(root);
|
|
76
85
|
}
|
|
77
86
|
/** Current tool activity label for the given root (undefined = idle). */
|
|
78
87
|
function getOpencodeSdkActivity(root) {
|
|
79
|
-
return _activity.get(root);
|
|
88
|
+
return (0, acp_1.getOpencodeAcpActivity)(root) ?? _activity.get(root);
|
|
80
89
|
}
|
|
81
90
|
function getOpencodeSdkLatestSessionId(root) {
|
|
82
|
-
return _latestSessionIds.get(root) ?? _state.get(root)?.sessionId;
|
|
91
|
+
return (0, acp_1.getOpencodeAcpLatestSessionId)(root) ?? _latestSessionIds.get(root) ?? _state.get(root)?.sessionId;
|
|
83
92
|
}
|
|
84
93
|
/**
|
|
85
94
|
* Steer the live OpenCode SDK session MID-TURN. Unlike opencode-cli / grok /
|
|
@@ -91,6 +100,10 @@ function getOpencodeSdkLatestSessionId(root) {
|
|
|
91
100
|
* the durable TODO queue (at-least-once delivery preserved).
|
|
92
101
|
*/
|
|
93
102
|
async function steerOpencodeSdk(root, text, log) {
|
|
103
|
+
// Native-ACP path: a queued session/prompt to the live opencode acp process.
|
|
104
|
+
if ((0, acp_1.hasOpencodeAcpSession)(root)) {
|
|
105
|
+
return (0, acp_1.steerOpencodeAcp)(root, text, log);
|
|
106
|
+
}
|
|
94
107
|
const st = _state.get(root);
|
|
95
108
|
if (!st || !_busyRoots.has(root)) {
|
|
96
109
|
return false;
|
|
@@ -449,7 +462,21 @@ function _evictClient(root) {
|
|
|
449
462
|
// persistent SDK session, streams output to stdoutFile + log(), writes the
|
|
450
463
|
// exit code to exitFile once session.idle fires.
|
|
451
464
|
// ---------------------------------------------------------------------------
|
|
452
|
-
|
|
465
|
+
/**
|
|
466
|
+
* Router: prefer native `opencode acp` (persistent AcpSession) when enabled;
|
|
467
|
+
* otherwise use the createOpencode in-process server. On ACP startup failure the
|
|
468
|
+
* ACP layer transparently falls back to the server path (onAcpUnavailable), so
|
|
469
|
+
* nothing regresses. Both paths are "SDK-like" to the task loop (persistent,
|
|
470
|
+
* turn-end via isOpencodeSdkBusy) so no loop change is needed.
|
|
471
|
+
*/
|
|
472
|
+
function sendOpencodeSdkPrompt(root, promptFilePath, resumeSessionId, stdoutFile, exitFile, log, model, showOutput) {
|
|
473
|
+
if ((0, acp_1.opencodeAcpEnabled)()) {
|
|
474
|
+
(0, acp_1.sendOpencodeAcpPrompt)(root, promptFilePath, resumeSessionId, stdoutFile, exitFile, log, model, showOutput, () => _sendOpencodeSdkServerPrompt(root, promptFilePath, resumeSessionId, stdoutFile, exitFile, log, model, showOutput));
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
_sendOpencodeSdkServerPrompt(root, promptFilePath, resumeSessionId, stdoutFile, exitFile, log, model, showOutput);
|
|
478
|
+
}
|
|
479
|
+
function _sendOpencodeSdkServerPrompt(root,
|
|
453
480
|
/** Absolute path to the combined agent-profile + message file. */
|
|
454
481
|
promptFilePath, resumeSessionId, stdoutFile, exitFile, log,
|
|
455
482
|
/** Optional model string "providerID/modelID" */
|
|
@@ -598,6 +625,9 @@ showOutput) {
|
|
|
598
625
|
// Compact (summarise) the active session to free context window space.
|
|
599
626
|
// ---------------------------------------------------------------------------
|
|
600
627
|
function runOpencodeSdkCompact(root, log) {
|
|
628
|
+
if ((0, acp_1.hasOpencodeAcpSession)(root)) {
|
|
629
|
+
return (0, acp_1.compactOpencodeAcp)(root, log);
|
|
630
|
+
}
|
|
601
631
|
return new Promise((resolve) => {
|
|
602
632
|
const s = _state.get(root);
|
|
603
633
|
if (!s) {
|
|
@@ -616,6 +646,7 @@ function runOpencodeSdkCompact(root, log) {
|
|
|
616
646
|
// Shutdown — cleanly close the server when the task loop stops.
|
|
617
647
|
// ---------------------------------------------------------------------------
|
|
618
648
|
function closeOpencodeSdkClient(root, log) {
|
|
649
|
+
(0, acp_1.closeOpencodeAcp)(root, log);
|
|
619
650
|
const s = _state.get(root);
|
|
620
651
|
if (s) {
|
|
621
652
|
log('OpenCode SDK: closing persistent session + server');
|
|
@@ -639,10 +670,12 @@ function closeOpencodeSdkClient(root, log) {
|
|
|
639
670
|
function forceIdleOpencodeSdk(root) {
|
|
640
671
|
_busyRoots.delete(root);
|
|
641
672
|
_activity.delete(root);
|
|
673
|
+
(0, acp_1.forceIdleOpencodeAcp)(root);
|
|
642
674
|
_evictClient(root);
|
|
643
675
|
}
|
|
644
676
|
/** Close all open SDK servers — called on extension deactivate to avoid orphaned processes. */
|
|
645
677
|
function closeAllOpencodeSdkClients() {
|
|
678
|
+
(0, acp_1.closeAllOpencodeAcp)();
|
|
646
679
|
for (const [root, s] of _state) {
|
|
647
680
|
try {
|
|
648
681
|
s.server.close();
|