opencode-agent-orchestration-kit 1.0.37 → 1.0.39
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 +61 -4
- package/docker/open-design/Dockerfile +3 -1
- package/docker/open-design/entrypoint.mjs +61 -0
- package/docs/docker-open-design.md +5 -0
- package/docs/models.md +30 -0
- package/docs/open-design.md +8 -0
- package/docs/releases/v1.0.38.md +44 -0
- package/docs/releases/v1.0.39.md +44 -0
- package/opencode/tools/open-design-http.d.mts +45 -0
- package/opencode/tools/open-design-http.mjs +387 -0
- package/opencode/tools/open_design.ts +1 -102
- package/package.json +5 -3
- package/scripts/check-supply-chain.mjs +4 -1
- package/scripts/check-supply-chain.test.mjs +6 -5
- package/scripts/check.sh +4 -2
- package/scripts/oak.test.mjs +9 -2
- package/scripts/oc-switch.mjs +472 -0
- package/scripts/oc-switch.test.mjs +217 -0
- package/scripts/open-design-entrypoint.test.mjs +54 -0
- package/scripts/open-design-http.test.mjs +211 -0
- package/scripts/package-smoke.mjs +16 -2
- package/scripts/package-smoke.test.mjs +7 -5
- package/scripts/version.test.mjs +2 -2
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
import test from "node:test";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
import { daemonArguments, parsePort } from "../docker/open-design/entrypoint.mjs";
|
|
10
|
+
|
|
11
|
+
const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
12
|
+
const ENTRYPOINT = path.join(ROOT, "docker/open-design/entrypoint.mjs");
|
|
13
|
+
const DOCKERFILE = path.join(ROOT, "docker/open-design/Dockerfile");
|
|
14
|
+
|
|
15
|
+
test("[OD001] parsePort accepts decimal ports in the valid range", () => {
|
|
16
|
+
for (const [raw, expected] of [["1", 1], ["7456", 7456], ["65535", 65535], ["07456", 7456]]) {
|
|
17
|
+
assert.equal(parsePort(raw), expected, raw);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
for (const raw of ["", "0", "65536", "7456 ", " 7456", "+7456", "7456; touch marker", "7456\n--help"]) {
|
|
22
|
+
test(`[OD002] parsePort rejects unsafe value ${JSON.stringify(raw)}`, () => {
|
|
23
|
+
assert.throws(() => parsePort(raw), /OD_PORT.*1 and 65535/);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
test("[OD003] daemon arguments keep the port as one argument", () => {
|
|
28
|
+
assert.deepEqual(daemonArguments(parsePort("7456")), [
|
|
29
|
+
"apps/daemon/dist/cli.js",
|
|
30
|
+
"--port",
|
|
31
|
+
"7456",
|
|
32
|
+
"--no-open",
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("[OD004] a shell metacharacter fails before any daemon can start", () => {
|
|
37
|
+
const marker = path.join(os.tmpdir(), `open-design-entrypoint-${process.pid}-marker`);
|
|
38
|
+
const result = spawnSync(process.execPath, [ENTRYPOINT], {
|
|
39
|
+
cwd: ROOT,
|
|
40
|
+
encoding: "utf8",
|
|
41
|
+
env: { ...process.env, OD_PORT: `7456; touch ${marker}` },
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
assert.equal(result.status, 1, result.stderr);
|
|
45
|
+
assert.match(result.stderr, /OD_PORT/);
|
|
46
|
+
assert.equal(fs.existsSync(marker), false);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("[OD005] Docker uses an exec-form Node entrypoint without shell interpolation", () => {
|
|
50
|
+
const dockerfile = fs.readFileSync(DOCKERFILE, "utf8");
|
|
51
|
+
assert.match(dockerfile, /COPY entrypoint\.mjs \/usr\/local\/bin\/open-design-entrypoint\.mjs/);
|
|
52
|
+
assert.match(dockerfile, /ENTRYPOINT \["node", "\/usr\/local\/bin\/open-design-entrypoint\.mjs"\]/);
|
|
53
|
+
assert.doesNotMatch(dockerfile, /sh\s+-lc|\$\{OD_PORT/);
|
|
54
|
+
});
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import test from "node:test";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const openDesign = await import("../opencode/tools/open-design-http.mjs");
|
|
8
|
+
const { requestJson, streamOpenDesignChat } = openDesign;
|
|
9
|
+
const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
10
|
+
|
|
11
|
+
function trackedStream(chunks, state = {}) {
|
|
12
|
+
let index = 0;
|
|
13
|
+
return new ReadableStream({
|
|
14
|
+
pull(controller) {
|
|
15
|
+
if (index < chunks.length) {
|
|
16
|
+
controller.enqueue(new TextEncoder().encode(chunks[index++]));
|
|
17
|
+
} else {
|
|
18
|
+
controller.close();
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
cancel() {
|
|
22
|
+
state.cancelled = true;
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function chatResponse(chunks, state = {}) {
|
|
28
|
+
return new Response(trackedStream(chunks, state), { status: 200 });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function options(fetchImpl, overrides = {}) {
|
|
32
|
+
return { fetchImpl, ...overrides };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
test("Open Design exposes bounded HTTP and SSE transport helpers", () => {
|
|
36
|
+
assert.equal(typeof requestJson, "function");
|
|
37
|
+
assert.equal(typeof streamOpenDesignChat, "function");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("the Open Design tool delegates network reads to the bounded transport", () => {
|
|
41
|
+
const source = fs.readFileSync(path.join(ROOT, "opencode/tools/open_design.ts"), "utf8");
|
|
42
|
+
assert.match(source, /from ["']\.\/open-design-http\.mjs["']/);
|
|
43
|
+
assert.doesNotMatch(source, /await fetch\(/);
|
|
44
|
+
assert.doesNotMatch(source, /await res\.text\(/);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("requestJson aborts a request that stalls before response headers", async () => {
|
|
48
|
+
await assert.rejects(
|
|
49
|
+
requestJson("http://open-design.test", "/api/health", {}, options(() => new Promise(() => {}), {
|
|
50
|
+
connectTimeoutMs: 100,
|
|
51
|
+
})),
|
|
52
|
+
/timed out while connecting/,
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("requestJson cancels an oversized response before parsing it", async () => {
|
|
57
|
+
const state = {};
|
|
58
|
+
const response = new Response(trackedStream(["x".repeat(2_048), "x"], state), {
|
|
59
|
+
status: 200,
|
|
60
|
+
headers: { "content-length": "2048" },
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await assert.rejects(
|
|
64
|
+
requestJson("http://open-design.test", "/api/health", {}, options(async () => response, {
|
|
65
|
+
maxJsonBytes: 1_024,
|
|
66
|
+
})),
|
|
67
|
+
/response exceeds 1024 bytes/,
|
|
68
|
+
);
|
|
69
|
+
assert.equal(state.cancelled, true);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("streamOpenDesignChat parses partial CRLF-framed SSE events", async () => {
|
|
73
|
+
const chunks = [
|
|
74
|
+
"event: stdout\r\ndata: {\"chunk\":\"hel",
|
|
75
|
+
"lo\"}\r\n\r\nevent: agent\r\ndata: {\"delta\":\" world\"}\r\n\r\nevent: end\r\ndata: {\"code\":0}\r\n\r\n",
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
const result = await streamOpenDesignChat(
|
|
79
|
+
"http://open-design.test",
|
|
80
|
+
{ prompt: "test" },
|
|
81
|
+
options(async () => chatResponse(chunks), { maxEvents: 10 }),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
assert.equal(result.stdout, "hello world");
|
|
85
|
+
assert.equal(result.stderr, "");
|
|
86
|
+
assert.equal(result.eventsCount, 3);
|
|
87
|
+
assert.deepEqual(result.end, { code: 0 });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("streamOpenDesignChat keeps the tail of bounded stderr on non-zero exit", async () => {
|
|
91
|
+
const stderr = `head-marker ${"x".repeat(1_500)} tail-marker`;
|
|
92
|
+
const frames = [
|
|
93
|
+
`event: stderr\ndata: ${JSON.stringify({ chunk: stderr })}\n\n`,
|
|
94
|
+
"event: end\ndata: {\"code\":2}\n\n",
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
await assert.rejects(
|
|
98
|
+
streamOpenDesignChat(
|
|
99
|
+
"http://open-design.test",
|
|
100
|
+
{ prompt: "test" },
|
|
101
|
+
options(async () => chatResponse(frames)),
|
|
102
|
+
),
|
|
103
|
+
/tail-marker/,
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("streamOpenDesignChat cancels the reader when output exceeds its cap", async () => {
|
|
108
|
+
const state = {};
|
|
109
|
+
const frame = `event: stdout\ndata: ${JSON.stringify({ chunk: "x".repeat(1_500) })}\n\n`;
|
|
110
|
+
|
|
111
|
+
await assert.rejects(
|
|
112
|
+
streamOpenDesignChat(
|
|
113
|
+
"http://open-design.test",
|
|
114
|
+
{ prompt: "test" },
|
|
115
|
+
options(async () => chatResponse([frame, frame], state), { maxOutputBytes: 1_024 }),
|
|
116
|
+
),
|
|
117
|
+
/stdout\/stderr output exceeds 1024 bytes/,
|
|
118
|
+
);
|
|
119
|
+
assert.equal(state.cancelled, true);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("streamOpenDesignChat rejects an oversized SSE body and cancels the reader", async () => {
|
|
123
|
+
const state = {};
|
|
124
|
+
const oversizedComment = `: ${"x".repeat(1_500)}\n\n`;
|
|
125
|
+
|
|
126
|
+
await assert.rejects(
|
|
127
|
+
streamOpenDesignChat(
|
|
128
|
+
"http://open-design.test",
|
|
129
|
+
{ prompt: "test" },
|
|
130
|
+
options(async () => chatResponse([oversizedComment, oversizedComment], state), {
|
|
131
|
+
maxSseBytes: 1_024,
|
|
132
|
+
}),
|
|
133
|
+
),
|
|
134
|
+
/SSE response exceeds 1024 bytes/,
|
|
135
|
+
);
|
|
136
|
+
assert.equal(state.cancelled, true);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("streamOpenDesignChat rejects an excessive event count and cancels the reader", async () => {
|
|
140
|
+
const state = {};
|
|
141
|
+
const frame = "event: stdout\ndata: {\"chunk\":\"x\"}\n\n";
|
|
142
|
+
|
|
143
|
+
await assert.rejects(
|
|
144
|
+
streamOpenDesignChat(
|
|
145
|
+
"http://open-design.test",
|
|
146
|
+
{ prompt: "test" },
|
|
147
|
+
options(async () => chatResponse([frame + frame + frame, frame], state), { maxEvents: 2 }),
|
|
148
|
+
),
|
|
149
|
+
/SSE event count exceeds 2/,
|
|
150
|
+
);
|
|
151
|
+
assert.equal(state.cancelled, true);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("streamOpenDesignChat cancels an idle stream deterministically", async () => {
|
|
155
|
+
const state = {};
|
|
156
|
+
const response = new Response(new ReadableStream({
|
|
157
|
+
pull() {
|
|
158
|
+
return new Promise(() => {});
|
|
159
|
+
},
|
|
160
|
+
cancel() {
|
|
161
|
+
state.cancelled = true;
|
|
162
|
+
},
|
|
163
|
+
}), { status: 200 });
|
|
164
|
+
|
|
165
|
+
await assert.rejects(
|
|
166
|
+
streamOpenDesignChat(
|
|
167
|
+
"http://open-design.test",
|
|
168
|
+
{ prompt: "test" },
|
|
169
|
+
options(async () => response, { idleTimeoutMs: 100, totalTimeoutMs: 2_000 }),
|
|
170
|
+
),
|
|
171
|
+
/timed out while reading/,
|
|
172
|
+
);
|
|
173
|
+
assert.equal(state.cancelled, true);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("streamOpenDesignChat enforces the total request timeout", async () => {
|
|
177
|
+
const state = {};
|
|
178
|
+
const response = new Response(new ReadableStream({
|
|
179
|
+
pull() {
|
|
180
|
+
return new Promise(() => {});
|
|
181
|
+
},
|
|
182
|
+
cancel() {
|
|
183
|
+
state.cancelled = true;
|
|
184
|
+
},
|
|
185
|
+
}), { status: 200 });
|
|
186
|
+
|
|
187
|
+
await assert.rejects(
|
|
188
|
+
streamOpenDesignChat(
|
|
189
|
+
"http://open-design.test",
|
|
190
|
+
{ prompt: "test" },
|
|
191
|
+
options(async () => response, { idleTimeoutMs: 2_000, totalTimeoutMs: 1_000 }),
|
|
192
|
+
),
|
|
193
|
+
/Open Design request timed out$/,
|
|
194
|
+
);
|
|
195
|
+
assert.equal(state.cancelled, true);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("streamOpenDesignChat cancels the reader on an agent error event", async () => {
|
|
199
|
+
const state = {};
|
|
200
|
+
const errorFrame = "event: error\ndata: {\"message\":\"upstream failed\"}\n\n";
|
|
201
|
+
|
|
202
|
+
await assert.rejects(
|
|
203
|
+
streamOpenDesignChat(
|
|
204
|
+
"http://open-design.test",
|
|
205
|
+
{ prompt: "test" },
|
|
206
|
+
options(async () => chatResponse([errorFrame, "event: stdout\ndata: {}\n\n"], state)),
|
|
207
|
+
),
|
|
208
|
+
/Open Design agent error: upstream failed/,
|
|
209
|
+
);
|
|
210
|
+
assert.equal(state.cancelled, true);
|
|
211
|
+
});
|
|
@@ -15,6 +15,7 @@ const REQUIRED_FILES = [
|
|
|
15
15
|
"package/install.sh",
|
|
16
16
|
"package/scripts/manage-installation.mjs",
|
|
17
17
|
"package/scripts/oak.mjs",
|
|
18
|
+
"package/scripts/oc-switch.mjs",
|
|
18
19
|
"package/scripts/package-smoke.sh",
|
|
19
20
|
"package/scripts/package-smoke.mjs",
|
|
20
21
|
"package/opencode/opencode.json",
|
|
@@ -123,10 +124,11 @@ export function validatePackedOak({ packed, packedRoot, fsOps = fs }) {
|
|
|
123
124
|
!packed?.bin
|
|
124
125
|
|| typeof packed.bin !== "object"
|
|
125
126
|
|| Array.isArray(packed.bin)
|
|
126
|
-
|| JSON.stringify(Object.keys(packed.bin).sort()) !== JSON.stringify(["oak"])
|
|
127
|
+
|| JSON.stringify(Object.keys(packed.bin).sort()) !== JSON.stringify(["oak", "oc-switch"])
|
|
127
128
|
|| packed.bin.oak !== "scripts/oak.mjs"
|
|
129
|
+
|| packed.bin["oc-switch"] !== "scripts/oc-switch.mjs"
|
|
128
130
|
) {
|
|
129
|
-
throw smokeError("packed package bin must expose
|
|
131
|
+
throw smokeError("packed package bin must expose oak and oc-switch at their scripts entrypoints");
|
|
130
132
|
}
|
|
131
133
|
let stat;
|
|
132
134
|
try {
|
|
@@ -140,6 +142,18 @@ export function validatePackedOak({ packed, packedRoot, fsOps = fs }) {
|
|
|
140
142
|
if ((stat.mode & 0o111) === 0) {
|
|
141
143
|
throw smokeError("packed oak entrypoint must be executable");
|
|
142
144
|
}
|
|
145
|
+
let switchStat;
|
|
146
|
+
try {
|
|
147
|
+
switchStat = fsOps.lstatSync(path.join(packedRoot, packed.bin["oc-switch"]));
|
|
148
|
+
} catch {
|
|
149
|
+
throw smokeError("packed oc-switch entrypoint is missing");
|
|
150
|
+
}
|
|
151
|
+
if (switchStat.isSymbolicLink() || !switchStat.isFile()) {
|
|
152
|
+
throw smokeError("packed oc-switch entrypoint must be a regular non-symlink file");
|
|
153
|
+
}
|
|
154
|
+
if ((switchStat.mode & 0o111) === 0) {
|
|
155
|
+
throw smokeError("packed oc-switch entrypoint must be executable");
|
|
156
|
+
}
|
|
143
157
|
}
|
|
144
158
|
|
|
145
159
|
function inspectRegularFile(file) {
|
|
@@ -17,13 +17,14 @@ import {
|
|
|
17
17
|
|
|
18
18
|
const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
19
19
|
const HASH = "a".repeat(64);
|
|
20
|
-
const BASENAME = "opencode-agent-orchestration-kit-1.0.
|
|
20
|
+
const BASENAME = "opencode-agent-orchestration-kit-1.0.39.tgz";
|
|
21
21
|
const REQUIRED = [
|
|
22
22
|
"package/package.json",
|
|
23
23
|
"package/supply-chain.json",
|
|
24
24
|
"package/install.sh",
|
|
25
25
|
"package/scripts/manage-installation.mjs",
|
|
26
26
|
"package/scripts/oak.mjs",
|
|
27
|
+
"package/scripts/oc-switch.mjs",
|
|
27
28
|
"package/scripts/package-smoke.sh",
|
|
28
29
|
"package/scripts/package-smoke.mjs",
|
|
29
30
|
"package/opencode/opencode.json",
|
|
@@ -157,20 +158,21 @@ test("validatePackedOak requires exact metadata and executable regular file", (t
|
|
|
157
158
|
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
158
159
|
fs.mkdirSync(path.join(root, "scripts"));
|
|
159
160
|
fs.writeFileSync(path.join(root, "scripts/oak.mjs"), "#!/usr/bin/env node\n", { mode: 0o755 });
|
|
161
|
+
fs.writeFileSync(path.join(root, "scripts/oc-switch.mjs"), "#!/usr/bin/env node\n", { mode: 0o755 });
|
|
160
162
|
assert.doesNotThrow(() => validatePackedOak({
|
|
161
|
-
packed: { bin: { oak: "scripts/oak.mjs" } },
|
|
163
|
+
packed: { bin: { oak: "scripts/oak.mjs", "oc-switch": "scripts/oc-switch.mjs" } },
|
|
162
164
|
packedRoot: root,
|
|
163
165
|
}));
|
|
164
166
|
for (const bin of [
|
|
165
167
|
undefined,
|
|
166
168
|
{ oak: "scripts/other.mjs" },
|
|
167
|
-
{ oak: "scripts/oak.mjs", other: "scripts/other.mjs" },
|
|
169
|
+
{ oak: "scripts/oak.mjs", "oc-switch": "scripts/oc-switch.mjs", other: "scripts/other.mjs" },
|
|
168
170
|
]) {
|
|
169
171
|
assert.throws(() => validatePackedOak({ packed: { bin }, packedRoot: root }), /bin/i);
|
|
170
172
|
}
|
|
171
173
|
fs.chmodSync(path.join(root, "scripts/oak.mjs"), 0o644);
|
|
172
174
|
assert.throws(() => validatePackedOak({
|
|
173
|
-
packed: { bin: { oak: "scripts/oak.mjs" } },
|
|
175
|
+
packed: { bin: { oak: "scripts/oak.mjs", "oc-switch": "scripts/oc-switch.mjs" } },
|
|
174
176
|
packedRoot: root,
|
|
175
177
|
}), /executable/i);
|
|
176
178
|
});
|
|
@@ -208,7 +210,7 @@ test("smokeTarball validates both archive listings before extraction", async ()
|
|
|
208
210
|
await assert.rejects(
|
|
209
211
|
smokeTarball({
|
|
210
212
|
repositoryRoot: ROOT,
|
|
211
|
-
tarball: "/public/opencode-agent-orchestration-kit-1.0.
|
|
213
|
+
tarball: "/public/opencode-agent-orchestration-kit-1.0.39.tgz",
|
|
212
214
|
captureTarball(_source, destination) {
|
|
213
215
|
fs.writeFileSync(destination, "fixture");
|
|
214
216
|
return { size: 1 };
|
package/scripts/version.test.mjs
CHANGED
|
@@ -109,7 +109,7 @@ test("[V004] direct version entrypoints are exact and mutation-free", (t) => {
|
|
|
109
109
|
for (const args of [["scripts/version.mjs"], ["scripts/manage-installation.mjs", "--version"]]) {
|
|
110
110
|
const result = run(process.execPath, args, { HOME: home });
|
|
111
111
|
assert.equal(result.status, 0, result.stderr);
|
|
112
|
-
assert.equal(result.stdout, "opencode-agent-orchestration-kit 1.0.
|
|
112
|
+
assert.equal(result.stdout, "opencode-agent-orchestration-kit 1.0.39\n");
|
|
113
113
|
assert.equal(fs.existsSync(target), false);
|
|
114
114
|
}
|
|
115
115
|
});
|
|
@@ -118,7 +118,7 @@ test("[V005] all lifecycle wrappers expose the canonical version", () => {
|
|
|
118
118
|
for (const wrapper of ["install.sh", "upgrade.sh", "doctor.sh", "uninstall.sh", "rollback.sh"]) {
|
|
119
119
|
const result = run(path.join(REPOSITORY_ROOT, wrapper), ["--version"]);
|
|
120
120
|
assert.equal(result.status, 0, `${wrapper}: ${result.stderr}`);
|
|
121
|
-
assert.equal(result.stdout, "opencode-agent-orchestration-kit 1.0.
|
|
121
|
+
assert.equal(result.stdout, "opencode-agent-orchestration-kit 1.0.39\n", wrapper);
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
124
|
|