opencode-agent-orchestration-kit 1.2.0 → 1.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 +11 -5
- package/docs/models.md +1 -1
- package/docs/releases/v1.2.1.md +75 -0
- package/docs/supply-chain.md +19 -14
- package/opencode/agents/lead.md +2 -1
- package/opencode/commands/loop-status.md +2 -2
- package/opencode/commands/loop.md +19 -5
- package/opencode/docs/ai/harness/agents.md +3 -1
- package/opencode/docs/ai/harness/commands.md +5 -1
- package/opencode/package-lock.json +46 -307
- package/opencode/package.json +4 -4
- package/opencode/scripts/check-harness.mjs +22 -3
- package/opencode/scripts/check-harness.test.mjs +82 -4
- package/package.json +1 -1
- package/scripts/benchmark-tool-paths.mjs +1 -1
- package/scripts/check-public-boundary.mjs +1 -1
- package/scripts/check-public-boundary.test.mjs +12 -0
- package/scripts/check-supply-chain.mjs +7 -7
- package/scripts/check-supply-chain.test.mjs +33 -25
- package/scripts/oc-switch.mjs +54 -7
- package/scripts/oc-switch.test.mjs +106 -0
- package/scripts/package-smoke.test.mjs +3 -3
- package/scripts/version.test.mjs +2 -2
- package/supply-chain.json +4 -4
|
@@ -550,6 +550,9 @@ test("orchestration catalog preserves approved behavior", async (t) => {
|
|
|
550
550
|
}
|
|
551
551
|
});
|
|
552
552
|
|
|
553
|
+
const kitScriptsDir = '"${OPENCODE_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/opencode}/scripts';
|
|
554
|
+
const loopStateCommand = `node ${kitScriptsDir}/loop-state.mjs"`;
|
|
555
|
+
|
|
553
556
|
const validLoopCommand = `---
|
|
554
557
|
description: Run a bounded and verifiable engineering loop.
|
|
555
558
|
agent: lead
|
|
@@ -563,16 +566,17 @@ history_path: .opencode/loops/<slug>.history.jsonl
|
|
|
563
566
|
lock_path: .opencode/loops/<slug>.lock
|
|
564
567
|
human_view_path: .opencode/loops/<slug>.md
|
|
565
568
|
worktree_mode: explicit_opt_in
|
|
569
|
+
state_runtime_missing: stop_and_report
|
|
566
570
|
|
|
567
571
|
developer -> reviewer -> developer (state sync)
|
|
568
572
|
|
|
569
573
|
## Phase 1
|
|
570
574
|
|
|
571
|
-
|
|
575
|
+
${loopStateCommand} inspect
|
|
572
576
|
|
|
573
577
|
## Phase 2
|
|
574
578
|
|
|
575
|
-
|
|
579
|
+
${loopStateCommand} resume
|
|
576
580
|
|
|
577
581
|
## Phase 3
|
|
578
582
|
`;
|
|
@@ -1021,8 +1025,8 @@ test("harness rejects loop resume writes before approval", () => {
|
|
|
1021
1025
|
writeLoopFixture(
|
|
1022
1026
|
cwd,
|
|
1023
1027
|
validLoopCommand.replace(
|
|
1024
|
-
|
|
1025
|
-
|
|
1028
|
+
`${loopStateCommand} inspect`,
|
|
1029
|
+
`${loopStateCommand} resume`,
|
|
1026
1030
|
),
|
|
1027
1031
|
);
|
|
1028
1032
|
|
|
@@ -1041,6 +1045,80 @@ test("harness rejects loop resume writes before approval", () => {
|
|
|
1041
1045
|
}
|
|
1042
1046
|
});
|
|
1043
1047
|
|
|
1048
|
+
test("harness rejects a project-relative loop-state call", () => {
|
|
1049
|
+
const cwd = makeFixture();
|
|
1050
|
+
try {
|
|
1051
|
+
writeLoopFixture(
|
|
1052
|
+
cwd,
|
|
1053
|
+
validLoopCommand.replace(`${loopStateCommand} resume`, "node scripts/loop-state.mjs resume"),
|
|
1054
|
+
);
|
|
1055
|
+
|
|
1056
|
+
const result = runHarness(cwd);
|
|
1057
|
+
assert.notEqual(result.status, 0, "checker accepted a project-relative loop-state call");
|
|
1058
|
+
assert.match(
|
|
1059
|
+
result.stderr,
|
|
1060
|
+
/commands\/loop\.md: loop-state must run from the config directory, not project-relative scripts\//,
|
|
1061
|
+
);
|
|
1062
|
+
} finally {
|
|
1063
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
|
|
1067
|
+
test("harness rejects a loop command without the fail-closed runtime rule", () => {
|
|
1068
|
+
const cwd = makeFixture();
|
|
1069
|
+
try {
|
|
1070
|
+
writeLoopFixture(cwd, validLoopCommand.replace("state_runtime_missing: stop_and_report\n", ""));
|
|
1071
|
+
|
|
1072
|
+
const result = runHarness(cwd);
|
|
1073
|
+
assert.notEqual(result.status, 0, "checker accepted a loop without the fail-closed rule");
|
|
1074
|
+
assert.match(result.stderr, /commands\/loop\.md: missing state_runtime_missing: stop_and_report/);
|
|
1075
|
+
} finally {
|
|
1076
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
1077
|
+
}
|
|
1078
|
+
});
|
|
1079
|
+
|
|
1080
|
+
test("harness rejects a project-relative mission-status call", () => {
|
|
1081
|
+
const cwd = makeFixture();
|
|
1082
|
+
try {
|
|
1083
|
+
const loopStatus = fs.readFileSync(path.join(cwd, "commands/loop-status.md"), "utf8");
|
|
1084
|
+
write(
|
|
1085
|
+
"commands/loop-status.md",
|
|
1086
|
+
loopStatus.replaceAll(`node ${kitScriptsDir}/mission-status.mjs"`, "node scripts/mission-status.mjs"),
|
|
1087
|
+
cwd,
|
|
1088
|
+
);
|
|
1089
|
+
|
|
1090
|
+
const result = runHarness(cwd);
|
|
1091
|
+
assert.notEqual(result.status, 0, "checker accepted a project-relative mission-status call");
|
|
1092
|
+
assert.match(
|
|
1093
|
+
result.stderr,
|
|
1094
|
+
/commands\/loop-status\.md: mission-status must run from the config directory/,
|
|
1095
|
+
);
|
|
1096
|
+
} finally {
|
|
1097
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
|
|
1101
|
+
test("harness rejects a lead allowlist that only matches project-relative loop-state", () => {
|
|
1102
|
+
const cwd = makeFixture();
|
|
1103
|
+
try {
|
|
1104
|
+
const lead = fs.readFileSync(path.join(cwd, "agents/lead.md"), "utf8");
|
|
1105
|
+
write(
|
|
1106
|
+
"agents/lead.md",
|
|
1107
|
+
lead.replace('"node *scripts/loop-state.mjs inspect*"', '"node scripts/loop-state.mjs inspect*"'),
|
|
1108
|
+
cwd,
|
|
1109
|
+
);
|
|
1110
|
+
|
|
1111
|
+
const result = runHarness(cwd);
|
|
1112
|
+
assert.notEqual(result.status, 0, "checker accepted a lead allowlist that denies the kit runtime");
|
|
1113
|
+
assert.match(
|
|
1114
|
+
result.stderr,
|
|
1115
|
+
/agents\/lead\.md: missing bash allow "node \*scripts\/loop-state\.mjs inspect\*": allow/,
|
|
1116
|
+
);
|
|
1117
|
+
} finally {
|
|
1118
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
1119
|
+
}
|
|
1120
|
+
});
|
|
1121
|
+
|
|
1044
1122
|
test("harness rejects evolve flow when evaluator/debugger/evolver order is inverted", () => {
|
|
1045
1123
|
const cwd = makeFixture();
|
|
1046
1124
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-agent-orchestration-kit",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Open-source multi-agent orchestration harness for OpenCode with specialized agents, durable workflows, review gates, and reproducible software-engineering processes.",
|
|
6
6
|
"keywords": [
|
|
@@ -143,7 +143,7 @@ async function benchmarkFixture(fixture, iterations, temporaryRoot) {
|
|
|
143
143
|
const result = await createInstallationManager({
|
|
144
144
|
sourceRoot: fixture.sourceRoot,
|
|
145
145
|
repositoryRoot: fixture.root,
|
|
146
|
-
versionProvider: () => "1.2.
|
|
146
|
+
versionProvider: () => "1.2.1",
|
|
147
147
|
}).run("install", { targetRoot });
|
|
148
148
|
if (result.exitCode !== 0) throw invalid(`installation benchmark failed for ${fixture.id}`);
|
|
149
149
|
} finally {
|
|
@@ -32,7 +32,7 @@ const PRIVATE_MARKERS = [
|
|
|
32
32
|
|
|
33
33
|
function walk(directory, root = directory, files = []) {
|
|
34
34
|
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
35
|
-
if ([".git", "node_modules"].includes(entry.name)) continue;
|
|
35
|
+
if ([".git", ".codegraph", "node_modules"].includes(entry.name)) continue;
|
|
36
36
|
if ([".gitignore", "check.sh"].includes(entry.name)) continue;
|
|
37
37
|
const full = path.join(directory, entry.name);
|
|
38
38
|
if (entry.isDirectory()) walk(full, root, files);
|
|
@@ -22,6 +22,18 @@ test("the boundary scan reports a private marker without echoing its value", ()
|
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
+
test("the boundary scan skips the local CodeGraph index", () => {
|
|
26
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "public-boundary-codegraph-"));
|
|
27
|
+
try {
|
|
28
|
+
const leaked = ["/", "Users", "example", "secret"].join("/");
|
|
29
|
+
fs.mkdirSync(path.join(root, ".codegraph"));
|
|
30
|
+
fs.writeFileSync(path.join(root, ".codegraph", "daemon.log"), leaked);
|
|
31
|
+
assert.deepEqual(scanPublicLeaks(root), []);
|
|
32
|
+
} finally {
|
|
33
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
25
37
|
test("missing boundary documentation fails closed", () => {
|
|
26
38
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "public-boundary-missing-"));
|
|
27
39
|
try {
|
|
@@ -22,7 +22,7 @@ const EXACT_KEYS = {
|
|
|
22
22
|
commit: ["commit"],
|
|
23
23
|
image: ["tag", "digest"],
|
|
24
24
|
version: ["version"],
|
|
25
|
-
overrides: ["@babel/core", "brace-expansion", "
|
|
25
|
+
overrides: ["@babel/core", "brace-expansion", "effect", "glob", "seroval", "seroval-plugins", "zod"],
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
const COMMIT = /^[0-9a-f]{40}$/;
|
|
@@ -106,10 +106,10 @@ export function validateSupplyChainData(data) {
|
|
|
106
106
|
data.npm_overrides["brace-expansion"],
|
|
107
107
|
"npm_overrides.brace-expansion",
|
|
108
108
|
);
|
|
109
|
+
assertStableVersion(data.npm_overrides.effect, "npm_overrides.effect");
|
|
110
|
+
assertStableVersion(data.npm_overrides.glob, "npm_overrides.glob");
|
|
109
111
|
assertStableVersion(data.npm_overrides.seroval, "npm_overrides.seroval");
|
|
110
112
|
assertStableVersion(data.npm_overrides["seroval-plugins"], "npm_overrides.seroval-plugins");
|
|
111
|
-
assertStableVersion(data.npm_overrides.toml, "npm_overrides.toml");
|
|
112
|
-
assertStableVersion(data.npm_overrides.uuid, "npm_overrides.uuid");
|
|
113
113
|
assertStableVersion(data.npm_overrides.zod, "npm_overrides.zod");
|
|
114
114
|
return data;
|
|
115
115
|
}
|
|
@@ -501,10 +501,10 @@ function canonicalDocumentationPinBlock(data) {
|
|
|
501
501
|
| opencode-ai | ${data.external_refs.opencode_ai.version} | exact version |
|
|
502
502
|
| @babel/core override | ${data.npm_overrides["@babel/core"]} | exact version |
|
|
503
503
|
| brace-expansion override | ${data.npm_overrides["brace-expansion"]} | exact version |
|
|
504
|
+
| effect override | ${data.npm_overrides.effect} | exact version |
|
|
505
|
+
| glob override | ${data.npm_overrides.glob} | exact version |
|
|
504
506
|
| seroval override | ${data.npm_overrides.seroval} | exact version |
|
|
505
507
|
| seroval-plugins override | ${data.npm_overrides["seroval-plugins"]} | exact version |
|
|
506
|
-
| toml override | ${data.npm_overrides.toml} | exact version |
|
|
507
|
-
| uuid override | ${data.npm_overrides.uuid} | exact version |
|
|
508
508
|
| zod override | ${data.npm_overrides.zod} | exact version |
|
|
509
509
|
<!-- supply-chain-pins:end -->`;
|
|
510
510
|
}
|
|
@@ -532,10 +532,10 @@ function validateDocumentation(root, data, fsOps) {
|
|
|
532
532
|
"| opencode-ai |",
|
|
533
533
|
"| @babel/core override |",
|
|
534
534
|
"| brace-expansion override |",
|
|
535
|
+
"| effect override |",
|
|
536
|
+
"| glob override |",
|
|
535
537
|
"| seroval override |",
|
|
536
538
|
"| seroval-plugins override |",
|
|
537
|
-
"| toml override |",
|
|
538
|
-
"| uuid override |",
|
|
539
539
|
"| zod override |",
|
|
540
540
|
].map((row) => actualBlock.indexOf(row));
|
|
541
541
|
const rowsAreOrdered = rowPositions.every(
|
|
@@ -44,10 +44,10 @@ const VALID = {
|
|
|
44
44
|
npm_overrides: {
|
|
45
45
|
"@babel/core": "7.29.7",
|
|
46
46
|
"brace-expansion": "5.0.12",
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
effect: "4.0.7",
|
|
48
|
+
glob: "14.0.2",
|
|
49
|
+
seroval: "1.6.12",
|
|
50
|
+
"seroval-plugins": "1.6.12",
|
|
51
51
|
zod: "4.6.7",
|
|
52
52
|
},
|
|
53
53
|
};
|
|
@@ -92,10 +92,10 @@ function canonicalPolicy() {
|
|
|
92
92
|
| opencode-ai | ${VALID.external_refs.opencode_ai.version} | exact version |
|
|
93
93
|
| @babel/core override | ${VALID.npm_overrides["@babel/core"]} | exact version |
|
|
94
94
|
| brace-expansion override | ${VALID.npm_overrides["brace-expansion"]} | exact version |
|
|
95
|
+
| effect override | ${VALID.npm_overrides.effect} | exact version |
|
|
96
|
+
| glob override | ${VALID.npm_overrides.glob} | exact version |
|
|
95
97
|
| seroval override | ${VALID.npm_overrides.seroval} | exact version |
|
|
96
98
|
| seroval-plugins override | ${VALID.npm_overrides["seroval-plugins"]} | exact version |
|
|
97
|
-
| toml override | ${VALID.npm_overrides.toml} | exact version |
|
|
98
|
-
| uuid override | ${VALID.npm_overrides.uuid} | exact version |
|
|
99
99
|
| zod override | ${VALID.npm_overrides.zod} | exact version |
|
|
100
100
|
<!-- supply-chain-pins:end -->
|
|
101
101
|
|
|
@@ -204,26 +204,26 @@ function withSurfaceFixture(callback) {
|
|
|
204
204
|
resolved: "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz",
|
|
205
205
|
integrity: "sha512-braceexpansion",
|
|
206
206
|
},
|
|
207
|
+
"node_modules/effect": {
|
|
208
|
+
version: VALID.npm_overrides.effect,
|
|
209
|
+
resolved: "https://registry.npmjs.org/effect/-/effect-4.0.7.tgz",
|
|
210
|
+
integrity: "sha512-effect",
|
|
211
|
+
},
|
|
212
|
+
"node_modules/glob": {
|
|
213
|
+
version: VALID.npm_overrides.glob,
|
|
214
|
+
resolved: "https://registry.npmjs.org/glob/-/glob-14.0.2.tgz",
|
|
215
|
+
integrity: "sha512-glob",
|
|
216
|
+
},
|
|
207
217
|
"node_modules/seroval": {
|
|
208
218
|
version: VALID.npm_overrides.seroval,
|
|
209
|
-
resolved: "https://registry.npmjs.org/seroval/-/seroval-1.6.
|
|
219
|
+
resolved: "https://registry.npmjs.org/seroval/-/seroval-1.6.12.tgz",
|
|
210
220
|
integrity: "sha512-seroval",
|
|
211
221
|
},
|
|
212
222
|
"node_modules/seroval-plugins": {
|
|
213
223
|
version: VALID.npm_overrides["seroval-plugins"],
|
|
214
|
-
resolved: "https://registry.npmjs.org/seroval-plugins/-/seroval-plugins-1.6.
|
|
224
|
+
resolved: "https://registry.npmjs.org/seroval-plugins/-/seroval-plugins-1.6.12.tgz",
|
|
215
225
|
integrity: "sha512-serovalplugins",
|
|
216
226
|
},
|
|
217
|
-
"node_modules/toml": {
|
|
218
|
-
version: VALID.npm_overrides.toml,
|
|
219
|
-
resolved: "https://registry.npmjs.org/toml/-/toml-5.0.1.tgz",
|
|
220
|
-
integrity: "sha512-toml",
|
|
221
|
-
},
|
|
222
|
-
"node_modules/uuid": {
|
|
223
|
-
version: VALID.npm_overrides.uuid,
|
|
224
|
-
resolved: "https://registry.npmjs.org/uuid/-/uuid-14.0.0.tgz",
|
|
225
|
-
integrity: "sha512-uuid",
|
|
226
|
-
},
|
|
227
227
|
"node_modules/zod": {
|
|
228
228
|
version: VALID.npm_overrides.zod,
|
|
229
229
|
resolved: "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz",
|
|
@@ -297,7 +297,7 @@ test("rejects missing and unknown keys at every schema level", () => {
|
|
|
297
297
|
expectInvalid((data) => { data.external_refs.unknown = {}; }, "external_refs keys");
|
|
298
298
|
expectInvalid((data) => delete data.external_refs.actions_checkout.commit, "external_refs.actions_checkout keys");
|
|
299
299
|
expectInvalid((data) => { data.external_refs.node_image.unknown = true; }, "external_refs.node_image keys");
|
|
300
|
-
expectInvalid((data) => delete data.npm_overrides.
|
|
300
|
+
expectInvalid((data) => delete data.npm_overrides.effect, "npm_overrides keys");
|
|
301
301
|
expectInvalid((data) => { data.npm_overrides.extra = "1.0.0"; }, "npm_overrides keys");
|
|
302
302
|
});
|
|
303
303
|
|
|
@@ -356,8 +356,12 @@ test("requires exact canonical versions without ranges", () => {
|
|
|
356
356
|
"npm_overrides.brace-expansion",
|
|
357
357
|
);
|
|
358
358
|
expectInvalid(
|
|
359
|
-
(data) => { data.npm_overrides.
|
|
360
|
-
"npm_overrides.
|
|
359
|
+
(data) => { data.npm_overrides.glob = "^14.0.2"; },
|
|
360
|
+
"npm_overrides.glob",
|
|
361
|
+
);
|
|
362
|
+
expectInvalid(
|
|
363
|
+
(data) => { data.npm_overrides.effect = "4.0"; },
|
|
364
|
+
"npm_overrides.effect",
|
|
361
365
|
);
|
|
362
366
|
});
|
|
363
367
|
|
|
@@ -614,7 +618,8 @@ for (const [label, current, replacement] of [
|
|
|
614
618
|
["opencode-ai", `| opencode-ai | ${VALID.external_refs.opencode_ai.version} |`, "| opencode-ai | DRIFTED |"],
|
|
615
619
|
["Babel override", `| @babel/core override | ${VALID.npm_overrides["@babel/core"]} |`, "| @babel/core override | DRIFTED |"],
|
|
616
620
|
["brace-expansion override", `| brace-expansion override | ${VALID.npm_overrides["brace-expansion"]} |`, "| brace-expansion override | DRIFTED |"],
|
|
617
|
-
["
|
|
621
|
+
["glob override", `| glob override | ${VALID.npm_overrides.glob} |`, "| glob override | DRIFTED |"],
|
|
622
|
+
["effect override", `| effect override | ${VALID.npm_overrides.effect} |`, "| effect override | DRIFTED |"],
|
|
618
623
|
]) {
|
|
619
624
|
test(`documentation validation rejects a drifted ${label} pin`, () => {
|
|
620
625
|
withSurfaceFixture((root) => {
|
|
@@ -702,9 +707,12 @@ for (const [dependency, mutation] of [
|
|
|
702
707
|
["brace-expansion", (packageData) => { delete packageData.overrides["brace-expansion"]; }],
|
|
703
708
|
["brace-expansion range", (packageData) => { packageData.overrides["brace-expansion"] = "^5.0.9"; }],
|
|
704
709
|
["brace-expansion wrong version", (packageData) => { packageData.overrides["brace-expansion"] = "5.0.7"; }],
|
|
705
|
-
["
|
|
706
|
-
["
|
|
707
|
-
["
|
|
710
|
+
["glob", (packageData) => { delete packageData.overrides.glob; }],
|
|
711
|
+
["glob range", (packageData) => { packageData.overrides.glob = "^14.0.2"; }],
|
|
712
|
+
["glob wrong version", (packageData) => { packageData.overrides.glob = "14.0.1"; }],
|
|
713
|
+
["effect", (packageData) => { delete packageData.overrides.effect; }],
|
|
714
|
+
["effect range", (packageData) => { packageData.overrides.effect = "^4.0.7"; }],
|
|
715
|
+
["effect wrong version", (packageData) => { packageData.overrides.effect = "4.0.6"; }],
|
|
708
716
|
]) {
|
|
709
717
|
test(`surface validation rejects absent, ranged, or wrong ${dependency} override`, () => {
|
|
710
718
|
withSurfaceFixture((root) => {
|
package/scripts/oc-switch.mjs
CHANGED
|
@@ -69,6 +69,11 @@ export function parseOpenCodeModelList(stdout) {
|
|
|
69
69
|
return grouped;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
export function parseOpenCodeMajorVersion(stdout) {
|
|
73
|
+
const match = String(stdout).match(/(\d+)\.\d+\.\d+/);
|
|
74
|
+
return match ? Number(match[1]) : undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
72
77
|
export function parseOpenCodeAuthProviders(stdout) {
|
|
73
78
|
if (typeof stdout !== "string") throw new Error("auth stdout must be a string");
|
|
74
79
|
const providers = [];
|
|
@@ -232,9 +237,17 @@ function shellRcPath({ homeDir, shell }) {
|
|
|
232
237
|
throw new Error("oc-switch supports zsh and bash startup files");
|
|
233
238
|
}
|
|
234
239
|
|
|
240
|
+
function modelEnvironment(state) {
|
|
241
|
+
return {
|
|
242
|
+
OPENCODE_MODEL: state.defaultModel,
|
|
243
|
+
OPENCODE_SMALL_MODEL: state.smallModel,
|
|
244
|
+
...Object.fromEntries(AGENT_IDS.map((agent) => [agentEnvKey(agent), state.agents[agent]])),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
235
248
|
function updateShellRc(contents, state) {
|
|
236
|
-
const managed = [SHELL_START,
|
|
237
|
-
...
|
|
249
|
+
const managed = [SHELL_START,
|
|
250
|
+
...Object.entries(modelEnvironment(state)).map(([key, value]) => `export ${key}=${shellQuote(value)}`), SHELL_END].join("\n");
|
|
238
251
|
const block = new RegExp(`${SHELL_START.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[\\s\\S]*?${SHELL_END.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\r?\\n?`, "g");
|
|
239
252
|
return `${contents.replace(block, "").trimEnd()}\n\n${managed}\n`;
|
|
240
253
|
}
|
|
@@ -280,9 +293,9 @@ function resolveBinary({ signal } = {}) {
|
|
|
280
293
|
});
|
|
281
294
|
}
|
|
282
295
|
|
|
283
|
-
function runCommand(args, { signal } = {}) {
|
|
296
|
+
function runCommand(args, { signal, env } = {}) {
|
|
284
297
|
return new Promise((resolve, reject) => {
|
|
285
|
-
const child = spawn(args[0], args.slice(1), { shell: false, stdio: ["ignore", "pipe", "pipe"] });
|
|
298
|
+
const child = spawn(args[0], args.slice(1), { shell: false, stdio: ["ignore", "pipe", "pipe"], env });
|
|
286
299
|
let stdout = "";
|
|
287
300
|
const abort = () => child.kill("SIGTERM");
|
|
288
301
|
signal?.addEventListener("abort", abort, { once: true });
|
|
@@ -306,17 +319,38 @@ function frame(screen, first, previousLineCount) {
|
|
|
306
319
|
export function createOcSwitcher({ homeDir = os.homedir(), env = process.env, shell = env.SHELL, now = () => new Date().toISOString(), resolve = resolveBinary, command = runCommand } = {}) {
|
|
307
320
|
const filePath = statePath({ homeDir, env });
|
|
308
321
|
const read = () => readState(filePath, env, now);
|
|
309
|
-
|
|
322
|
+
let majorVersion;
|
|
323
|
+
const openCodeMajor = async (binary, signal) => {
|
|
324
|
+
if (majorVersion === undefined) {
|
|
325
|
+
try { majorVersion = parseOpenCodeMajorVersion(await command([binary, "--version"], { signal })) ?? 1; } catch { majorVersion = 1; }
|
|
326
|
+
}
|
|
327
|
+
return majorVersion;
|
|
328
|
+
};
|
|
329
|
+
const save = async (state) => {
|
|
310
330
|
const normalized = { ...state, schemaVersion: STATE_VERSION, updatedAt: now() };
|
|
311
331
|
atomicWrite(filePath, `${JSON.stringify(normalized, null, 2)}\n`);
|
|
312
332
|
const rcPath = shellRcPath({ homeDir, shell });
|
|
313
333
|
let contents = "";
|
|
314
334
|
try { contents = fs.readFileSync(rcPath, "utf8"); } catch (cause) { if (cause?.code !== "ENOENT") throw cause; }
|
|
315
335
|
atomicWrite(rcPath, updateShellRc(contents, normalized));
|
|
336
|
+
const binary = await resolve();
|
|
337
|
+
// OpenCode 2 runs prompts through a background service that keeps the
|
|
338
|
+
// environment it started with, so new model variables need a restart.
|
|
339
|
+
if (await openCodeMajor(binary) >= 2) {
|
|
340
|
+
try {
|
|
341
|
+
await command([binary, "service", "restart"], { env: { ...env, ...modelEnvironment(normalized) } });
|
|
342
|
+
} catch {
|
|
343
|
+
throw Object.assign(new Error("Saved. Run `opencode service restart` to apply the new models."), { saved: true });
|
|
344
|
+
}
|
|
345
|
+
}
|
|
316
346
|
return normalized;
|
|
317
347
|
};
|
|
318
348
|
const refresh = async ({ signal, forceRefresh = false } = {}) => {
|
|
319
349
|
const binary = await resolve({ signal });
|
|
350
|
+
// OpenCode 2 removed --pure/--refresh and only lists providers with credentials.
|
|
351
|
+
if (await openCodeMajor(binary, signal) >= 2) {
|
|
352
|
+
return Object.values(parseOpenCodeModelList(await command([binary, "models"], { signal }))).flat();
|
|
353
|
+
}
|
|
320
354
|
const providers = configuredProviderIds({ homeDir, env });
|
|
321
355
|
try {
|
|
322
356
|
const auth = await command([binary, "auth", "list"], { signal });
|
|
@@ -360,7 +394,19 @@ export async function runTerminalOcSwitcher({ input = process.stdin, output = pr
|
|
|
360
394
|
previousLineCount = screenText.split("\n").length;
|
|
361
395
|
};
|
|
362
396
|
const finish = (nextResult) => { finished = true; result = nextResult; controller.abort(); };
|
|
363
|
-
|
|
397
|
+
let saveWarning;
|
|
398
|
+
const persist = async () => {
|
|
399
|
+
try {
|
|
400
|
+
state = await saveState(state);
|
|
401
|
+
saveWarning = undefined;
|
|
402
|
+
status = "Guardado.";
|
|
403
|
+
} catch (error) {
|
|
404
|
+
if (!error?.saved) throw error;
|
|
405
|
+
saveWarning = error.message;
|
|
406
|
+
status = error.message;
|
|
407
|
+
}
|
|
408
|
+
dirty = false;
|
|
409
|
+
};
|
|
364
410
|
const startRefresh = (first = false) => {
|
|
365
411
|
catalogFresh = false;
|
|
366
412
|
status = "Loading models...";
|
|
@@ -401,7 +447,7 @@ export async function runTerminalOcSwitcher({ input = process.stdin, output = pr
|
|
|
401
447
|
}
|
|
402
448
|
} else if (name === "r") startRefresh();
|
|
403
449
|
else if (name === "s") persist().catch(() => { status = "Save failed."; });
|
|
404
|
-
else if (name === "q") persist().then(() => finish({ status: "saved", state })).catch(() => finish({ status: "error", error: "Save failed." }));
|
|
450
|
+
else if (name === "q") persist().then(() => finish({ status: "saved", state, ...(saveWarning ? { warning: saveWarning } : {}) })).catch(() => finish({ status: "error", error: "Save failed." }));
|
|
405
451
|
else if (name === "escape") selectedAgents.clear();
|
|
406
452
|
} else {
|
|
407
453
|
const available = filtered();
|
|
@@ -470,4 +516,5 @@ export function isDirectExecution({
|
|
|
470
516
|
if (isDirectExecution()) {
|
|
471
517
|
const result = await runInteractive();
|
|
472
518
|
if (result.status === "error") { process.stderr.write(`${result.error}\n`); process.exitCode = 1; }
|
|
519
|
+
if (result.warning) process.stderr.write(`${result.warning}\n`);
|
|
473
520
|
}
|
|
@@ -139,6 +139,34 @@ test("OpenCode TUI changes the default model and persists on q", async () => {
|
|
|
139
139
|
assert.match(output.writes.join(""), /Loading models/);
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
+
test("OpenCode TUI reports a failed service restart as a saved warning on q", async () => {
|
|
143
|
+
const input = createTuiInput();
|
|
144
|
+
const output = { isTTY: true, rows: 30, writes: [], write(chunk) { this.writes.push(String(chunk)); } };
|
|
145
|
+
const state = {
|
|
146
|
+
schemaVersion: 1,
|
|
147
|
+
defaultModel: "nan/model-a",
|
|
148
|
+
smallModel: "nan/model-a",
|
|
149
|
+
agents: Object.fromEntries(AGENT_IDS.map((agent) => [agent, "nan/model-a"])),
|
|
150
|
+
};
|
|
151
|
+
const running = runTerminalOcSwitcher({
|
|
152
|
+
input,
|
|
153
|
+
output,
|
|
154
|
+
initialState: state,
|
|
155
|
+
initialModels: ["nan/model-a"],
|
|
156
|
+
refreshModels: async () => ["nan/model-a"],
|
|
157
|
+
saveState: async () => {
|
|
158
|
+
throw Object.assign(new Error("Saved. Run `opencode service restart` to apply the new models."), { saved: true });
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
await nextTick();
|
|
163
|
+
emitKey(input, "q");
|
|
164
|
+
const result = await running;
|
|
165
|
+
|
|
166
|
+
assert.equal(result.status, "saved");
|
|
167
|
+
assert.match(result.warning, /opencode service restart/);
|
|
168
|
+
});
|
|
169
|
+
|
|
142
170
|
test("OpenCode TUI changes the focused agent model", async () => {
|
|
143
171
|
const input = createTuiInput();
|
|
144
172
|
const output = { isTTY: true, rows: 30, writes: [], write(chunk) { this.writes.push(String(chunk)); } };
|
|
@@ -224,6 +252,7 @@ test("uses the local OpenCode model cache until an explicit refresh", async () =
|
|
|
224
252
|
await switcher.refreshModels({ forceRefresh: true });
|
|
225
253
|
|
|
226
254
|
assert.deepEqual(calls, [
|
|
255
|
+
["/opt/opencode/bin/opencode", "--version"],
|
|
227
256
|
["/opt/opencode/bin/opencode", "auth", "list"],
|
|
228
257
|
["/opt/opencode/bin/opencode", "models", "--pure"],
|
|
229
258
|
["/opt/opencode/bin/opencode", "auth", "list"],
|
|
@@ -231,6 +260,83 @@ test("uses the local OpenCode model cache until an explicit refresh", async () =
|
|
|
231
260
|
]);
|
|
232
261
|
});
|
|
233
262
|
|
|
263
|
+
test("reads the OpenCode 2 catalog without the removed --pure and --refresh flags", async () => {
|
|
264
|
+
const calls = [];
|
|
265
|
+
const switcher = createOcSwitcher({
|
|
266
|
+
homeDir: "/tmp/oc-switch-test-home",
|
|
267
|
+
env: { OPENCODE_MODEL: "openai/model-a" },
|
|
268
|
+
resolve: async () => "/opt/opencode/bin/opencode",
|
|
269
|
+
command: async (args) => {
|
|
270
|
+
calls.push(args);
|
|
271
|
+
if (args[1] === "--version") return "opencode v2.4.1\n";
|
|
272
|
+
return "openai/model-a\nopencode-go/model-b\nxai/model-c\n";
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
assert.deepEqual(await switcher.refreshModels(), ["openai/model-a", "opencode-go/model-b", "xai/model-c"]);
|
|
277
|
+
await switcher.refreshModels({ forceRefresh: true });
|
|
278
|
+
|
|
279
|
+
assert.deepEqual(calls, [
|
|
280
|
+
["/opt/opencode/bin/opencode", "--version"],
|
|
281
|
+
["/opt/opencode/bin/opencode", "models"],
|
|
282
|
+
["/opt/opencode/bin/opencode", "models"],
|
|
283
|
+
]);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
function saveWithVersion(version, { restartFails = false } = {}) {
|
|
287
|
+
const homeDir = fs.mkdtempSync(path.join(os.tmpdir(), "oc-switch-save-"));
|
|
288
|
+
const calls = [];
|
|
289
|
+
const switcher = createOcSwitcher({
|
|
290
|
+
homeDir,
|
|
291
|
+
env: { OPENCODE_MODEL: "openai/model-a", PATH: "/usr/bin" },
|
|
292
|
+
shell: "/bin/zsh",
|
|
293
|
+
resolve: async () => "/opt/opencode/bin/opencode",
|
|
294
|
+
command: async (args, options = {}) => {
|
|
295
|
+
calls.push({ args, env: options.env });
|
|
296
|
+
if (args[1] === "--version") return `${version}\n`;
|
|
297
|
+
if (args[1] === "service" && restartFails) throw new Error("OpenCode command unavailable");
|
|
298
|
+
return "";
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
const state = applyModelSelection(switcher.loadState(), { target: "defaultModel", modelRef: "opencode-go/model-b" });
|
|
302
|
+
return { homeDir, calls, saving: switcher.saveState(state) };
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
test("restarts the OpenCode 2 background service with the saved models", async () => {
|
|
306
|
+
const { homeDir, calls, saving } = saveWithVersion("opencode v2.4.1");
|
|
307
|
+
try {
|
|
308
|
+
await saving;
|
|
309
|
+
assert.match(fs.readFileSync(path.join(homeDir, ".zshrc"), "utf8"), /OPENCODE_MODEL='opencode-go\/model-b'/);
|
|
310
|
+
const restart = calls.find((call) => call.args[1] === "service");
|
|
311
|
+
assert.deepEqual(restart.args, ["/opt/opencode/bin/opencode", "service", "restart"]);
|
|
312
|
+
assert.equal(restart.env.OPENCODE_MODEL, "opencode-go/model-b");
|
|
313
|
+
assert.equal(restart.env.OPENCODE_LEAD_MODEL, "openai/model-a");
|
|
314
|
+
assert.equal(restart.env.PATH, "/usr/bin");
|
|
315
|
+
} finally {
|
|
316
|
+
fs.rmSync(homeDir, { recursive: true, force: true });
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
test("does not restart a service on OpenCode 1", async () => {
|
|
321
|
+
const { homeDir, calls, saving } = saveWithVersion("1.19.6");
|
|
322
|
+
try {
|
|
323
|
+
await saving;
|
|
324
|
+
assert.equal(calls.some((call) => call.args[1] === "service"), false);
|
|
325
|
+
} finally {
|
|
326
|
+
fs.rmSync(homeDir, { recursive: true, force: true });
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
test("keeps the saved models when the OpenCode 2 service restart fails", async () => {
|
|
331
|
+
const { homeDir, saving } = saveWithVersion("opencode v2.4.1", { restartFails: true });
|
|
332
|
+
try {
|
|
333
|
+
await assert.rejects(saving, (error) => error.saved === true && /opencode service restart/.test(error.message));
|
|
334
|
+
assert.match(fs.readFileSync(path.join(homeDir, ".zshrc"), "utf8"), /OPENCODE_MODEL='opencode-go\/model-b'/);
|
|
335
|
+
} finally {
|
|
336
|
+
fs.rmSync(homeDir, { recursive: true, force: true });
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
|
|
234
340
|
test("finds OpenCode directly on PATH without starting a login shell", () => {
|
|
235
341
|
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "oc-switch-path-"));
|
|
236
342
|
const binary = path.join(directory, "opencode");
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
|
|
19
19
|
const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
20
20
|
const HASH = "a".repeat(64);
|
|
21
|
-
const BASENAME = "opencode-agent-orchestration-kit-1.2.
|
|
21
|
+
const BASENAME = "opencode-agent-orchestration-kit-1.2.1.tgz";
|
|
22
22
|
const REQUIRED = [
|
|
23
23
|
"package/package.json",
|
|
24
24
|
"package/supply-chain.json",
|
|
@@ -228,7 +228,7 @@ test("smokeTarball checks the tracked set before extraction", async () => {
|
|
|
228
228
|
await assert.rejects(
|
|
229
229
|
smokeTarball({
|
|
230
230
|
repositoryRoot: ROOT,
|
|
231
|
-
tarball: "/public/opencode-agent-orchestration-kit-1.2.
|
|
231
|
+
tarball: "/public/opencode-agent-orchestration-kit-1.2.1.tgz",
|
|
232
232
|
captureTarball(_source, destination) {
|
|
233
233
|
fs.writeFileSync(destination, "fixture");
|
|
234
234
|
return { size: 1 };
|
|
@@ -253,7 +253,7 @@ test("smokeTarball validates both archive listings before extraction", async ()
|
|
|
253
253
|
await assert.rejects(
|
|
254
254
|
smokeTarball({
|
|
255
255
|
repositoryRoot: ROOT,
|
|
256
|
-
tarball: "/public/opencode-agent-orchestration-kit-1.2.
|
|
256
|
+
tarball: "/public/opencode-agent-orchestration-kit-1.2.1.tgz",
|
|
257
257
|
captureTarball(_source, destination) {
|
|
258
258
|
fs.writeFileSync(destination, "fixture");
|
|
259
259
|
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.2.
|
|
112
|
+
assert.equal(result.stdout, "opencode-agent-orchestration-kit 1.2.1\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.2.
|
|
121
|
+
assert.equal(result.stdout, "opencode-agent-orchestration-kit 1.2.1\n", wrapper);
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
124
|
|
package/supply-chain.json
CHANGED
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"npm_overrides": {
|
|
27
27
|
"@babel/core": "7.29.7",
|
|
28
28
|
"brace-expansion": "5.0.12",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
29
|
+
"effect": "4.0.7",
|
|
30
|
+
"glob": "14.0.2",
|
|
31
|
+
"seroval": "1.6.12",
|
|
32
|
+
"seroval-plugins": "1.6.12",
|
|
33
33
|
"zod": "4.6.7"
|
|
34
34
|
}
|
|
35
35
|
}
|