regent-code 3.0.3 → 3.0.5
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/.github/workflows/ci.yml +3 -0
- package/.opencode/INSTALL.md +3 -3
- package/AGENTS.md +6 -0
- package/README.md +9 -34
- package/mcp/cli.js +1 -0
- package/mcp/index.js +29 -7
- package/mcp/install.js +5 -20
- package/mcp/shared.js +109 -27
- package/package.json +4 -3
- package/regent-code-3.0.5.tgz +0 -0
- package/regent-code-3.0.3.tgz +0 -0
package/.github/workflows/ci.yml
CHANGED
|
@@ -36,3 +36,6 @@ jobs:
|
|
|
36
36
|
- name: Test
|
|
37
37
|
working-directory: .opencode
|
|
38
38
|
run: node --test tests/regent.test.js tests/regent.v2.test.js tests/regent.live-test.js tests/regent.hybrid.v2.6.1.test.js tests/regent.runtime.v2.6.1.test.js
|
|
39
|
+
|
|
40
|
+
- name: Test MCP suites (bin contract + installer + server)
|
|
41
|
+
run: node --test mcp/tests/bin.test.js mcp/tests/install.test.js mcp/tests/mcp.test.js
|
package/.opencode/INSTALL.md
CHANGED
|
@@ -6,7 +6,7 @@ If the package is published to npm, both the plugin and the MCP server install
|
|
|
6
6
|
with a single command against any existing `opencode.json` / `opencode.jsonc`:
|
|
7
7
|
|
|
8
8
|
```bash
|
|
9
|
-
npx -y regent-code@3.0.
|
|
9
|
+
npx -y regent-code@3.0.5 install
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
Patches the project config (or the global `~/.config/opencode/` config) to add
|
|
@@ -19,7 +19,7 @@ Patches the project config (or the global `~/.config/opencode/` config) to add
|
|
|
19
19
|
```jsonc
|
|
20
20
|
{
|
|
21
21
|
"$schema": "https://opencode.ai/config.json",
|
|
22
|
-
"plugins": ["regent-code@git+https://github.com/nathwn12/regent-code.git#v3.0.
|
|
22
|
+
"plugins": ["regent-code@git+https://github.com/nathwn12/regent-code.git#v3.0.5"],
|
|
23
23
|
}
|
|
24
24
|
```
|
|
25
25
|
|
|
@@ -32,7 +32,7 @@ Patches the project config (or the global `~/.config/opencode/` config) to add
|
|
|
32
32
|
}
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
The pinned version is recommended. Use the unpinned branch only when you intentionally want the latest changes. The `v3.0.
|
|
35
|
+
The pinned version is recommended. Use the unpinned branch only when you intentionally want the latest changes. The `v3.0.5` git tag must be pushed to GitHub before the pinned spec resolves.
|
|
36
36
|
|
|
37
37
|
## Single-source rule (duplicate plugin ID)
|
|
38
38
|
|
package/AGENTS.md
CHANGED
|
@@ -28,6 +28,12 @@ All 108 tests across the five suites must pass before committing.
|
|
|
28
28
|
- Error paths produce structured JSON, never throw
|
|
29
29
|
- `context.directory` → `process.cwd()` fallback
|
|
30
30
|
|
|
31
|
+
## Bin targets
|
|
32
|
+
|
|
33
|
+
- Every `package.json` `bin` file MUST start with `#!/usr/bin/env node`. Without it, npm generates a passthrough `.cmd` shim on Windows that ShellExecutes the file through its extension association (opens an editor) instead of running it under node. Enforced by `mcp/tests/bin.test.js`.
|
|
34
|
+
- The MCP launch contract is the single command `npx -y regent-code` - no absolute paths, no global installs, no hand-written `.cmd`/`.ps1` shims. Enforced by the same test.
|
|
35
|
+
- `npm run prepublishOnly` (wired to `npm run verify`) gates every `npm publish`; CI runs the MCP suites too.
|
|
36
|
+
|
|
31
37
|
## Verdict gates
|
|
32
38
|
|
|
33
39
|
Before committing:
|
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ Add Regent to your OpenCode configuration:
|
|
|
51
51
|
```jsonc
|
|
52
52
|
{
|
|
53
53
|
"$schema": "https://opencode.ai/config.json",
|
|
54
|
-
"plugins": ["regent-code@git+https://github.com/nathwn12/regent-code.git#v3.0.
|
|
54
|
+
"plugins": ["regent-code@git+https://github.com/nathwn12/regent-code.git#v3.0.5"],
|
|
55
55
|
}
|
|
56
56
|
```
|
|
57
57
|
|
|
@@ -69,7 +69,7 @@ are read from the persisted transcript when the service stores turns, otherwise
|
|
|
69
69
|
from the synchronous `session.generate` text; agent catalogs are queried with
|
|
70
70
|
and without an explicit location scope; and the caller-authorization guardrail
|
|
71
71
|
degrades OPEN when the runtime agent API is unresolvable (only recursion from
|
|
72
|
-
known worker sessions stays hard-blocked). The `v3.0.
|
|
72
|
+
known worker sessions stays hard-blocked). The `v3.0.5` git tag must be pushed
|
|
73
73
|
to GitHub before this pinned spec resolves.
|
|
74
74
|
|
|
75
75
|
> **Windows dev-machine warning (single-source rule):** when this repository is open as an OpenCode project, its own `.opencode/plugins/regent.js` is auto-loaded as a project plugin. Do NOT also pin regent in `opencode.jsonc` on the same machine — two active sources make host plugin reloads fail with `Duplicate plugin ID: regent`, leaving sessions with a torn tool surface and blocking live skill/plugin edits. Either develop unpinned (project plugin only) or pin the repo file directly: `"plugins": ["file:///Q:/PROJECTS/PERSONAL/regent-code/.opencode/plugins/regent.js"]`. One source of truth, always.
|
|
@@ -79,25 +79,23 @@ to GitHub before this pinned spec resolves.
|
|
|
79
79
|
The fastest way to get **both** the plugin and the MCP server on any machine — no cloning, no manual config edits, no local files:
|
|
80
80
|
|
|
81
81
|
```bash
|
|
82
|
-
npx -y regent-code@3.0.
|
|
82
|
+
npx -y regent-code@3.0.5 install
|
|
83
83
|
```
|
|
84
84
|
|
|
85
85
|
The installer finds an existing `opencode.json` / `opencode.jsonc` (project config in the current directory first, then the global `~/.config/opencode/` config) and adds both entries:
|
|
86
86
|
|
|
87
|
-
- **MCP server**: `mcp.servers.regent` → runs `
|
|
88
|
-
- **Plugin**: `plugins` → `regent-code@3.0.
|
|
87
|
+
- **MCP server**: `mcp.servers.regent` → runs `["npx", "-y", "regent-code"]`. That single command spawns the server through the package's `bin` — no absolute paths, no global install, no per-machine shims.
|
|
88
|
+
- **Plugin**: `plugins` → `regent-code@3.0.5`
|
|
89
89
|
|
|
90
90
|
It is **idempotent and non-destructive** — it only adds or updates regent entries, preserving comments, trailing commas, and every unrelated setting in the file. Re-run it to upgrade the pinned version. Flags: `--global` forces the user config, `--file <path>` targets an exact file, `--help` explains all options. Restart the OpenCode session afterwards — plugin load and MCP connection happen on config load.
|
|
91
91
|
|
|
92
|
-
> When the installer is invoked from npm's ephemeral npx cache, it prints a warning: the absolute path it wrote can be pruned by npm. Run `npm install -g regent-code@3.0.3` once and re-run the installer so the entry points at the persistent global install.
|
|
93
|
-
|
|
94
92
|
> On the machine that develops regent-code itself, respect the single-source rule above: do not add a second pin when the repo is open as a project.
|
|
95
93
|
|
|
96
94
|
## MCP Server
|
|
97
95
|
|
|
98
96
|
Since v3.0.0, regent-code ships a second distribution alongside the plugin: a Model Context Protocol (MCP) server that exposes the same six tools (`delegate`, `delegate_many`, `research`, `explore`, `changed-files`, `verify`) plus the Regent command and skill corpus as MCP prompts. It is out-of-process and works from any MCP client (Claude Desktop, Cursor, or OpenCode).
|
|
99
97
|
|
|
100
|
-
Configure it in OpenCode by adding a local MCP server:
|
|
98
|
+
Configure it in OpenCode by adding a local MCP server — the exact entry the installer writes:
|
|
101
99
|
|
|
102
100
|
```jsonc
|
|
103
101
|
{
|
|
@@ -106,7 +104,7 @@ Configure it in OpenCode by adding a local MCP server:
|
|
|
106
104
|
"servers": {
|
|
107
105
|
"regent": {
|
|
108
106
|
"type": "local",
|
|
109
|
-
"command": ["
|
|
107
|
+
"command": ["npx", "-y", "regent-code"],
|
|
110
108
|
"cwd": "."
|
|
111
109
|
}
|
|
112
110
|
}
|
|
@@ -114,32 +112,9 @@ Configure it in OpenCode by adding a local MCP server:
|
|
|
114
112
|
}
|
|
115
113
|
```
|
|
116
114
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
**Other machines / people — no local clone needed.** The package is published to npm. Recommended: install globally once, then let the installer write the entry (see "One-command install" above):
|
|
120
|
-
|
|
121
|
-
```bash
|
|
122
|
-
npm install -g regent-code@3.0.3
|
|
123
|
-
npx -y regent-code@3.0.3 install --global
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
Or add the server to `opencode.jsonc` manually with a direct node launch:
|
|
127
|
-
|
|
128
|
-
```jsonc
|
|
129
|
-
{
|
|
130
|
-
"$schema": "https://opencode.ai/config.json",
|
|
131
|
-
"mcp": {
|
|
132
|
-
"servers": {
|
|
133
|
-
"regent": {
|
|
134
|
-
"type": "local",
|
|
135
|
-
"command": ["node", "<NPM_GLOBAL>/regent-code/mcp/cli.js"]
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
```
|
|
115
|
+
`npx -y regent-code` is the single, canonical launch command — it runs on any machine with Node/npm installed, from the npm registry or the npx cache. No cloning, no global install, no absolute path, no shims. `cwd: "."` makes the server operate on the workspace directory, which is what the `explore` tool and subagent dispatch use as the working directory.
|
|
141
116
|
|
|
142
|
-
|
|
117
|
+
**Other machines / people — no local clone needed.** The package is published to npm. On any machine, either hand-write the entry above or run the one-command installer (see "One-command install" above).
|
|
143
118
|
|
|
144
119
|
Tool names surface in OpenCode as `<server>_<tool>`, so `regent_delegate`, `regent_delegate_many`, `regent_research`, `regent_explore`, `regent_changed-files`, `regent_verify`. Prompts surface as commands named `<server>:<prompt>`; the prompts are namespaced `command.<name>` (e.g. `/regent:command.orchestrate`, `/regent:command.tdd`) and `skill.<id>` (e.g. `/regent:skill.using-regent`).
|
|
145
120
|
|
package/mcp/cli.js
CHANGED
package/mcp/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
markEvidenceVerified,
|
|
27
27
|
evidenceForScope,
|
|
28
28
|
redactSecrets,
|
|
29
|
+
safeErrorMessage,
|
|
29
30
|
isSensitiveFocusPath,
|
|
30
31
|
parseSubagentTextResponse,
|
|
31
32
|
unwrapData,
|
|
@@ -285,9 +286,26 @@ async function dispatchSubagent(client, resolveWorker, args, taskId = '') {
|
|
|
285
286
|
);
|
|
286
287
|
const seed = extractGenerationText(unwrapData(result));
|
|
287
288
|
|
|
288
|
-
// Collect the final answer
|
|
289
|
-
//
|
|
290
|
-
const output = await collectWorkerAnswer(client, session.id, seed
|
|
289
|
+
// Collect the final answer once the turn has actually ended (generate
|
|
290
|
+
// resolves with the first chunk on current service semantics).
|
|
291
|
+
const output = await collectWorkerAnswer(client, session.id, seed, {
|
|
292
|
+
timeoutMs: Number(process.env.REGENT_TURN_TIMEOUT_MS) || 120000,
|
|
293
|
+
});
|
|
294
|
+
if (!output) {
|
|
295
|
+
try {
|
|
296
|
+
await client.session.interrupt({ sessionID: session.id });
|
|
297
|
+
} catch {
|
|
298
|
+
/* best effort */
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
status: 'blocked',
|
|
302
|
+
output:
|
|
303
|
+
'Subagent error: worker turn ended without producing an answer (stalled or timed out)',
|
|
304
|
+
concerns: [],
|
|
305
|
+
files_changed: [],
|
|
306
|
+
session_id: session.id,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
291
309
|
const parsed = parseSubagentTextResponse(output);
|
|
292
310
|
const { status, concerns, filesChanged } = parsed;
|
|
293
311
|
|
|
@@ -303,7 +321,7 @@ async function dispatchSubagent(client, resolveWorker, args, taskId = '') {
|
|
|
303
321
|
|
|
304
322
|
return { status, output, concerns, files_changed: filesChanged, session_id: session.id };
|
|
305
323
|
} catch (err) {
|
|
306
|
-
const message = redactSecrets(
|
|
324
|
+
const message = redactSecrets(safeErrorMessage(err)).slice(0, 500);
|
|
307
325
|
return {
|
|
308
326
|
status: 'blocked',
|
|
309
327
|
output: `Subagent error: ${message}`,
|
|
@@ -360,8 +378,11 @@ function runExplore(query, focus) {
|
|
|
360
378
|
if (focus) {
|
|
361
379
|
const worktreeRoot = path.resolve(worktree);
|
|
362
380
|
const focusPath = path.resolve(worktree, focus);
|
|
381
|
+
const absoluteFocus = path.isAbsolute(focus);
|
|
382
|
+
// Absolute focus paths may point outside the project (e.g. another repo);
|
|
383
|
+
// the sensitive-path guards still apply to every segment of the path.
|
|
363
384
|
const lexicalInside =
|
|
364
|
-
focusPath.startsWith(worktreeRoot + path.sep) || focusPath === worktreeRoot;
|
|
385
|
+
absoluteFocus || focusPath.startsWith(worktreeRoot + path.sep) || focusPath === worktreeRoot;
|
|
365
386
|
if (!lexicalInside) {
|
|
366
387
|
result += `\n## Focus: ${focus}\n(path outside project directory)\n`;
|
|
367
388
|
} else if (isSensitiveFocusPath(focusPath, worktreeRoot)) {
|
|
@@ -376,8 +397,9 @@ function runExplore(query, focus) {
|
|
|
376
397
|
/* fall back to lexical paths */
|
|
377
398
|
}
|
|
378
399
|
const inside =
|
|
379
|
-
|
|
380
|
-
(
|
|
400
|
+
absoluteFocus ||
|
|
401
|
+
((realFocus.startsWith(realRoot + path.sep) || realFocus === realRoot) &&
|
|
402
|
+
(focusPath.startsWith(worktreeRoot + path.sep) || focusPath === worktreeRoot));
|
|
381
403
|
if (!inside) {
|
|
382
404
|
result += `\n## Focus: ${focus}\n(path outside project directory)\n`;
|
|
383
405
|
} else if (isSensitiveFocusPath(realFocus, realRoot)) {
|
package/mcp/install.js
CHANGED
|
@@ -8,30 +8,22 @@
|
|
|
8
8
|
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
9
9
|
import { join, dirname, resolve } from 'node:path';
|
|
10
10
|
import { homedir } from 'node:os';
|
|
11
|
-
import { fileURLToPath } from 'node:url';
|
|
12
11
|
import { parseTree, findNodeAtLocation, getNodeValue, modify, applyEdits } from 'jsonc-parser';
|
|
13
12
|
import { version } from './version.js';
|
|
14
13
|
|
|
15
14
|
export const PLUGIN_SPEC = `regent-code@${version}`;
|
|
16
15
|
export const SERVER_NAME = 'regent';
|
|
17
16
|
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
// deterministic and offline.
|
|
23
|
-
const CLI_PATH = fileURLToPath(new URL('./cli.js', import.meta.url));
|
|
24
|
-
|
|
17
|
+
// The MCP server launches with a single portable command. `npx -y regent-code`
|
|
18
|
+
// runs the package's `bin` (mcp/cli.js) from the npm registry or npx cache —
|
|
19
|
+
// no absolute paths, no global install, no per-machine shims. This is the only
|
|
20
|
+
// supported launch path; the installer writes exactly this entry.
|
|
25
21
|
export const SERVER_CONFIG = Object.freeze({
|
|
26
22
|
type: 'local',
|
|
27
|
-
command: ['
|
|
23
|
+
command: ['npx', '-y', 'regent-code'],
|
|
28
24
|
cwd: '.',
|
|
29
25
|
});
|
|
30
26
|
|
|
31
|
-
// npm's ephemeral npx cache (`_npx/<hash>/...`) can be pruned by npm; warn the
|
|
32
|
-
// user to install globally so the config's absolute path keeps resolving.
|
|
33
|
-
const EPHEMERAL_NPX_CACHE = '_npx';
|
|
34
|
-
|
|
35
27
|
const CONFIG_NAMES = ['opencode.jsonc', 'opencode.json'];
|
|
36
28
|
|
|
37
29
|
export class InstallError extends Error {}
|
|
@@ -210,13 +202,6 @@ export function install(options = {}) {
|
|
|
210
202
|
const { text, report } = patchText(base);
|
|
211
203
|
const warnings = [...report.warnings];
|
|
212
204
|
|
|
213
|
-
if (CLI_PATH.includes(EPHEMERAL_NPX_CACHE)) {
|
|
214
|
-
warnings.push(
|
|
215
|
-
`MCP entry points into npm's ephemeral npx cache (${CLI_PATH}); npm can prune it. ` +
|
|
216
|
-
`Run "npm install -g ${PLUGIN_SPEC}" once, then re-run "npx -y ${PLUGIN_SPEC} install" ` +
|
|
217
|
-
`so the config points at the persistent global install.`,
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
205
|
if (text !== existingText) {
|
|
221
206
|
mkdirSync(dirname(target.path), { recursive: true });
|
|
222
207
|
writeFileSync(target.path, text);
|
package/mcp/shared.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
|
|
4
|
+
// ── Error helpers ──
|
|
5
|
+
/** @param {unknown} err @returns {string} */
|
|
6
|
+
export function safeErrorMessage(err) {
|
|
7
|
+
const value = err instanceof Error ? err.message : err;
|
|
8
|
+
if (typeof value === 'string' && value.trim()) return value;
|
|
9
|
+
try {
|
|
10
|
+
return JSON.stringify(value);
|
|
11
|
+
} catch {
|
|
12
|
+
return String(value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
4
16
|
// ── Dispatch safety limits ──
|
|
5
17
|
export const MAX_DISPATCH_ITEMS = 10;
|
|
6
18
|
export const MAX_STRING_LENGTH = 8000;
|
|
@@ -234,26 +246,46 @@ export function isSensitiveFocusPath(focusPath, worktreeRoot) {
|
|
|
234
246
|
}
|
|
235
247
|
|
|
236
248
|
// ── Subagent text-response parsing ──
|
|
249
|
+
const STATUS_WORDS = new Set(['done', 'blocked', 'needs_context', 'done_with_concerns']);
|
|
250
|
+
|
|
237
251
|
/**
|
|
252
|
+
* Parse a worker's final answer. A status line the worker was asked to emit
|
|
253
|
+
* (`- status: <word>`) wins; legacy ALL-CAPS tokens are fallbacks. `done` is
|
|
254
|
+
* only claimed when the answer has completion shape (`summary` or an explicit
|
|
255
|
+
* status line) — a bare fragment such as a mid-turn first chunk parses as
|
|
256
|
+
* needs_context, never as a false done. Empty output parses as blocked.
|
|
238
257
|
* @param {string} text
|
|
239
258
|
* @returns {{ status: string, concerns: string[], filesChanged: string[] }}
|
|
240
259
|
*/
|
|
241
260
|
export function parseSubagentTextResponse(text) {
|
|
242
|
-
|
|
243
|
-
|
|
261
|
+
const trimmed = String(text || '').trim();
|
|
262
|
+
if (!trimmed) {
|
|
263
|
+
return { status: 'blocked', concerns: ['worker returned no output'], filesChanged: [] };
|
|
264
|
+
}
|
|
244
265
|
|
|
245
|
-
|
|
266
|
+
const explicit = trimmed.match(/(?:^|\n)\s*-\s*status\s*[:=]\s*([a-z_]+)/i);
|
|
267
|
+
const statusWord = explicit ? explicit[1].toLowerCase() : '';
|
|
268
|
+
let status;
|
|
269
|
+
if (STATUS_WORDS.has(statusWord)) {
|
|
270
|
+
status = statusWord;
|
|
271
|
+
} else if (trimmed.includes('BLOCKED')) {
|
|
246
272
|
status = 'blocked';
|
|
247
|
-
} else if (
|
|
273
|
+
} else if (trimmed.includes('NEEDS_CONTEXT')) {
|
|
248
274
|
status = 'needs_context';
|
|
249
|
-
} else if (
|
|
275
|
+
} else if (trimmed.includes('CONCERN:')) {
|
|
250
276
|
status = 'done_with_concerns';
|
|
251
|
-
|
|
277
|
+
} else if (/\bsummary\s*[:=]/i.test(trimmed)) {
|
|
278
|
+
status = 'done';
|
|
279
|
+
} else {
|
|
280
|
+
status = 'needs_context';
|
|
252
281
|
}
|
|
253
282
|
|
|
283
|
+
const concerns =
|
|
284
|
+
trimmed.match(/CONCERN:.*$/gm)?.map((c) => c.replace('CONCERN:', '').trim()) || [];
|
|
285
|
+
|
|
254
286
|
const pathPattern =
|
|
255
287
|
/(?:^|\n)(?:[\w./\\-]+\.[a-zA-Z0-9]+|[\w.-]+(?:[\\/][\w.-]+)+(?:\.[a-zA-Z0-9]+)?|^[A-Za-z][\w-]+\.[\w-]+|^[A-Za-z][\w-]+(?:\.[\w-]+)*$(?!\.))/gm;
|
|
256
|
-
const matches =
|
|
288
|
+
const matches = trimmed.match(pathPattern);
|
|
257
289
|
const filesChanged = (matches || [])
|
|
258
290
|
.map((f) => f.trim())
|
|
259
291
|
.filter(
|
|
@@ -338,19 +370,33 @@ export function joinAssistantText(messages) {
|
|
|
338
370
|
|
|
339
371
|
/**
|
|
340
372
|
* Read the latest session transcript through whatever API the session handle
|
|
341
|
-
* exposes
|
|
342
|
-
*
|
|
373
|
+
* exposes, newest contract first: `session.context` (promised client) and
|
|
374
|
+
* `message.list` (returns { data: SessionMessageInfo[], cursor }), then the
|
|
375
|
+
* legacy `session.context` plugin domain.
|
|
343
376
|
* @param {any} sessionApi session or client handle
|
|
344
377
|
* @param {string} sessionID
|
|
345
378
|
* @returns {Promise<any[]>}
|
|
346
379
|
*/
|
|
347
380
|
export async function readTurnTranscript(sessionApi, sessionID) {
|
|
381
|
+
if (typeof sessionApi?.session?.context === 'function') {
|
|
382
|
+
try {
|
|
383
|
+
const response = await sessionApi.session.context({ sessionID });
|
|
384
|
+
const data = unwrapData(response);
|
|
385
|
+
if (Array.isArray(data)) return data;
|
|
386
|
+
if (Array.isArray(data?.data)) return data.data;
|
|
387
|
+
if (Array.isArray(data?.messages)) return data.messages;
|
|
388
|
+
return [];
|
|
389
|
+
} catch {
|
|
390
|
+
/* fall through to message.list */
|
|
391
|
+
}
|
|
392
|
+
}
|
|
348
393
|
if (typeof sessionApi?.message?.list === 'function') {
|
|
349
394
|
try {
|
|
350
395
|
const response = await sessionApi.message.list({ sessionID });
|
|
351
396
|
const data = unwrapData(response);
|
|
352
397
|
if (Array.isArray(data)) return data;
|
|
353
398
|
if (Array.isArray(data?.data)) return data.data;
|
|
399
|
+
if (Array.isArray(data?.messages)) return data.messages;
|
|
354
400
|
return [];
|
|
355
401
|
} catch {
|
|
356
402
|
/* fall through to context */
|
|
@@ -369,36 +415,72 @@ export async function readTurnTranscript(sessionApi, sessionID) {
|
|
|
369
415
|
}
|
|
370
416
|
|
|
371
417
|
/**
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
* 3. With neither available yet, wait briefly for async persistence, then
|
|
379
|
-
* give up with whatever exists (bounded, never hangs).
|
|
418
|
+
* Wait for a dispatched turn to end. The service resolves `session.generate`
|
|
419
|
+
* with the FIRST text chunk while the turn continues asynchronously, so the
|
|
420
|
+
* final answer only becomes read-consistent once the turn settles. Completion
|
|
421
|
+
* is signalled by `session.wait` (blocks until the session is idle) when the
|
|
422
|
+
* client exposes it; otherwise by transcript settlement (two consecutive
|
|
423
|
+
* identical non-empty reads). Bounded by timeoutMs; never hangs.
|
|
380
424
|
* @param {any} sessionApi session or client handle
|
|
381
425
|
* @param {string} sessionID
|
|
382
|
-
* @param {string} seed text returned by `session.generate`
|
|
383
426
|
* @param {{ timeoutMs?: number, intervalMs?: number }} [options]
|
|
384
|
-
* @returns {Promise<
|
|
427
|
+
* @returns {Promise<void>}
|
|
385
428
|
*/
|
|
386
|
-
export async function
|
|
429
|
+
export async function waitForTurnEnd(
|
|
387
430
|
sessionApi,
|
|
388
431
|
sessionID,
|
|
389
|
-
|
|
390
|
-
{ timeoutMs = 30000, intervalMs = 800 } = {},
|
|
432
|
+
{ timeoutMs = 120000, intervalMs = 1500 } = {},
|
|
391
433
|
) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
434
|
+
if (typeof sessionApi?.session?.wait === 'function') {
|
|
435
|
+
try {
|
|
436
|
+
await Promise.race([
|
|
437
|
+
sessionApi.session.wait({ sessionID }),
|
|
438
|
+
new Promise((resolve) => setTimeout(resolve, timeoutMs)),
|
|
439
|
+
]);
|
|
440
|
+
return;
|
|
441
|
+
} catch {
|
|
442
|
+
/* fall through to transcript settlement */
|
|
443
|
+
}
|
|
444
|
+
}
|
|
396
445
|
const deadline = Date.now() + timeoutMs;
|
|
446
|
+
let previous = '';
|
|
447
|
+
let stableReads = 0;
|
|
397
448
|
while (Date.now() < deadline) {
|
|
398
449
|
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
399
450
|
const text = joinAssistantText(await readTurnTranscript(sessionApi, sessionID));
|
|
400
|
-
if (text
|
|
451
|
+
if (text && text === previous) {
|
|
452
|
+
stableReads += 1;
|
|
453
|
+
if (stableReads >= 2) return;
|
|
454
|
+
} else {
|
|
455
|
+
stableReads = 0;
|
|
456
|
+
previous = text;
|
|
457
|
+
}
|
|
401
458
|
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Collect the final worker answer for a dispatched turn. Waits for the turn
|
|
463
|
+
* to end first: the seed from `session.generate` is only the first chunk on
|
|
464
|
+
* current service semantics, so the transcript after settlement wins. The
|
|
465
|
+
* seed is used only as a last resort when it already carries the completion
|
|
466
|
+
* block. Empty returns mean the turn produced nothing (caller reports a
|
|
467
|
+
* bounded failure instead of a false done).
|
|
468
|
+
* @param {any} sessionApi session or client handle
|
|
469
|
+
* @param {string} sessionID
|
|
470
|
+
* @param {string} seed text returned by `session.generate`
|
|
471
|
+
* @param {{ timeoutMs?: number, intervalMs?: number }} [options]
|
|
472
|
+
* @returns {Promise<string>}
|
|
473
|
+
*/
|
|
474
|
+
export async function collectWorkerAnswer(
|
|
475
|
+
sessionApi,
|
|
476
|
+
sessionID,
|
|
477
|
+
seed,
|
|
478
|
+
{ timeoutMs = 120000, intervalMs = 800 } = {},
|
|
479
|
+
) {
|
|
480
|
+
await waitForTurnEnd(sessionApi, sessionID, { timeoutMs, intervalMs });
|
|
481
|
+
const finalText = joinAssistantText(await readTurnTranscript(sessionApi, sessionID));
|
|
482
|
+
if (finalText) return finalText;
|
|
483
|
+
if (seed && /(?:^|\n)\s*-\s*status\s*[:=]|BLOCKED|NEEDS_CONTEXT/.test(seed)) return seed;
|
|
402
484
|
return '';
|
|
403
485
|
}
|
|
404
486
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "regent-code",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "Agent orchestration for OpenCode. From idea to shipped — zero ceremony. Plugin + MCP server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": ".opencode/plugins/regent.js",
|
|
@@ -30,8 +30,9 @@
|
|
|
30
30
|
"format": "prettier --write .opencode/plugins/ skills/ mcp/ --no-error-on-unmatched-pattern",
|
|
31
31
|
"format:check": "prettier --check .opencode/plugins/ skills/ mcp/ --no-error-on-unmatched-pattern",
|
|
32
32
|
"typecheck": "tsc --noEmit",
|
|
33
|
-
"test": "node --test .opencode/tests/regent.test.js .opencode/tests/regent.live-test.js .opencode/tests/regent.v2.test.js .opencode/tests/regent.hybrid.v2.6.1.test.js .opencode/tests/regent.runtime.v2.6.1.test.js mcp/tests/mcp.test.js mcp/tests/install.test.js",
|
|
34
|
-
"verify": "npm run format:check && npm run lint && npm run typecheck && npm test"
|
|
33
|
+
"test": "node --test .opencode/tests/regent.test.js .opencode/tests/regent.live-test.js .opencode/tests/regent.v2.test.js .opencode/tests/regent.hybrid.v2.6.1.test.js .opencode/tests/regent.runtime.v2.6.1.test.js mcp/tests/mcp.test.js mcp/tests/install.test.js mcp/tests/bin.test.js",
|
|
34
|
+
"verify": "npm run format:check && npm run lint && npm run typecheck && npm test",
|
|
35
|
+
"prepublishOnly": "npm run verify"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@eslint/js": "^10.0.1",
|
|
Binary file
|
package/regent-code-3.0.3.tgz
DELETED
|
Binary file
|