opencode-agent-orchestration-kit 1.0.38 → 1.0.40

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.
Files changed (49) hide show
  1. package/README.md +12 -3
  2. package/docker/open-design/Dockerfile +3 -1
  3. package/docker/open-design/entrypoint.mjs +61 -0
  4. package/docs/docker-open-design.md +5 -0
  5. package/docs/models.md +1 -1
  6. package/docs/open-design.md +8 -0
  7. package/docs/performance/native-tools-benchmark.md +33 -0
  8. package/docs/releases/v1.0.39.md +44 -0
  9. package/docs/releases/v1.0.40.md +55 -0
  10. package/docs/sync-boundary.md +27 -0
  11. package/opencode/commands/loop-status.md +24 -0
  12. package/opencode/commands/loop.md +8 -0
  13. package/opencode/docs/ai/harness/agents.md +8 -0
  14. package/opencode/docs/ai/harness/checks.md +6 -0
  15. package/opencode/docs/ai/harness/commands.md +10 -0
  16. package/opencode/docs/ai/harness/orchestration-contracts.json +9 -1
  17. package/opencode/docs/ai/specs/mission-runtime.md +44 -0
  18. package/opencode/plugins/mission-runtime.test.mjs +46 -0
  19. package/opencode/plugins/mission-runtime.ts +41 -0
  20. package/opencode/scripts/check-harness.mjs +111 -0
  21. package/opencode/scripts/check-harness.test.mjs +37 -1
  22. package/opencode/scripts/loop-state.mjs +5 -0
  23. package/opencode/scripts/loop-state.test.mjs +13 -0
  24. package/opencode/scripts/mission-runtime-observer.d.mts +25 -0
  25. package/opencode/scripts/mission-runtime-observer.mjs +124 -0
  26. package/opencode/scripts/mission-runtime.test.mjs +97 -0
  27. package/opencode/scripts/mission-status.mjs +136 -0
  28. package/opencode/scripts/mission-status.test.mjs +196 -0
  29. package/opencode/scripts/project-capability-snapshot.mjs +2 -1
  30. package/opencode/scripts/project-capability-snapshot.test.mjs +17 -0
  31. package/opencode/scripts/runtime-permission-policy.mjs +72 -0
  32. package/opencode/scripts/runtime-permission-policy.test.mjs +89 -0
  33. package/opencode/tools/open-design-http.d.mts +45 -0
  34. package/opencode/tools/open-design-http.mjs +387 -0
  35. package/opencode/tools/open_design.ts +2 -103
  36. package/package.json +3 -3
  37. package/scripts/benchmark-tool-paths.mjs +226 -0
  38. package/scripts/benchmark-tool-paths.test.mjs +29 -0
  39. package/scripts/check-public-boundary.mjs +89 -0
  40. package/scripts/check-public-boundary.test.mjs +32 -0
  41. package/scripts/check.sh +17 -10
  42. package/scripts/install-smoke.sh +17 -0
  43. package/scripts/manage-installation.mjs +90 -7
  44. package/scripts/manage-installation.test.mjs +36 -0
  45. package/scripts/open-design-entrypoint.test.mjs +54 -0
  46. package/scripts/open-design-http.test.mjs +211 -0
  47. package/scripts/package-smoke.mjs +52 -3
  48. package/scripts/package-smoke.test.mjs +6 -6
  49. package/scripts/version.test.mjs +2 -2
@@ -0,0 +1,196 @@
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 {
10
+ LoopStateError,
11
+ acquireLoop,
12
+ initLoopState,
13
+ recordLoopAction,
14
+ releaseLoop,
15
+ } from "./loop-state.mjs";
16
+ import {
17
+ parseArguments,
18
+ readMissionStatus,
19
+ renderHuman,
20
+ } from "./mission-status.mjs";
21
+
22
+ const scriptPath = fileURLToPath(new URL("./mission-status.mjs", import.meta.url));
23
+
24
+ function withRepo(callback, plannedIterations = 3) {
25
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "opencode-mission-status-"));
26
+ const loopsDir = path.join(root, ".opencode", "loops");
27
+ fs.mkdirSync(loopsDir, { recursive: true });
28
+ const contractPath = path.join(loopsDir, "example.md");
29
+ fs.writeFileSync(contractPath, "# Approved loop\n\nObjective: ship safely.\n");
30
+ initLoopState({
31
+ root,
32
+ slug: "example",
33
+ contractPath,
34
+ gitBaseline: "abc123",
35
+ sessionId: "session-1",
36
+ actionId: "approve-1",
37
+ plannedIterations,
38
+ });
39
+ try {
40
+ return callback({
41
+ root,
42
+ contractPath,
43
+ statePath: path.join(loopsDir, "example.json"),
44
+ historyPath: path.join(loopsDir, "example.history.jsonl"),
45
+ });
46
+ } finally {
47
+ fs.rmSync(root, { recursive: true, force: true });
48
+ }
49
+ }
50
+
51
+ function runStatus(root, args) {
52
+ return spawnSync(process.execPath, [scriptPath, "--root", root, ...args], {
53
+ encoding: "utf8",
54
+ timeout: 10000,
55
+ });
56
+ }
57
+
58
+ test("projects approved state without writing canonical files", () => {
59
+ withRepo(({ root, statePath, historyPath }) => {
60
+ const before = [fs.readFileSync(statePath), fs.readFileSync(historyPath)];
61
+ const mission = readMissionStatus({ root, slug: "example" });
62
+
63
+ assert.equal(mission.schema_version, 1);
64
+ assert.equal(mission.slug, "example");
65
+ assert.equal(mission.status, "approved");
66
+ assert.equal(mission.current_iteration, 0);
67
+ assert.equal(mission.planned_iterations, 3);
68
+ assert.equal(mission.last_completed_step, null);
69
+ assert.equal(mission.blocking_cause, null);
70
+ assert.equal(mission.session_id, "session-1");
71
+ assert.equal(typeof mission.updated_at, "string");
72
+ assert.equal(mission.next_action, "resume after confirming the approved contract");
73
+ assert.deepEqual([fs.readFileSync(statePath), fs.readFileSync(historyPath)], before);
74
+ });
75
+ });
76
+
77
+ test("projects running, blocked, paused, and completed transitions", () => {
78
+ withRepo(({ root, contractPath }) => {
79
+ acquireLoop({
80
+ root,
81
+ slug: "example",
82
+ contractPath,
83
+ sessionId: "session-1",
84
+ actionId: "resume-1",
85
+ });
86
+ assert.equal(readMissionStatus({ root, slug: "example" }).status, "running");
87
+
88
+ recordLoopAction({
89
+ root,
90
+ slug: "example",
91
+ sessionId: "session-1",
92
+ actionId: "blocked-1",
93
+ iteration: 1,
94
+ completedStep: "developer_change",
95
+ blockingCause: "reviewer requested a focused fix",
96
+ status: "blocked",
97
+ });
98
+ let mission = readMissionStatus({ root, slug: "example" });
99
+ assert.equal(mission.status, "blocked");
100
+ assert.equal(mission.blocking_cause, "reviewer requested a focused fix");
101
+ assert.match(mission.next_action, /blocking cause/);
102
+
103
+ recordLoopAction({
104
+ root,
105
+ slug: "example",
106
+ sessionId: "session-1",
107
+ actionId: "paused-1",
108
+ iteration: 1,
109
+ completedStep: "developer_change",
110
+ blockingCause: null,
111
+ status: "paused",
112
+ });
113
+ mission = readMissionStatus({ root, slug: "example" });
114
+ assert.equal(mission.status, "paused");
115
+ assert.match(mission.next_action, /resume explicitly/);
116
+
117
+ recordLoopAction({
118
+ root,
119
+ slug: "example",
120
+ sessionId: "session-1",
121
+ actionId: "completed-1",
122
+ iteration: 3,
123
+ completedStep: "review_passed",
124
+ blockingCause: null,
125
+ status: "completed",
126
+ });
127
+ releaseLoop({ root, slug: "example", sessionId: "session-1", actionId: "release-1" });
128
+ mission = readMissionStatus({ root, slug: "example" });
129
+ assert.equal(mission.status, "completed");
130
+ assert.equal(mission.current_iteration, 3);
131
+ assert.match(mission.next_action, /no further action/);
132
+ });
133
+ });
134
+
135
+ test("JSON and human CLI output expose the same projection", () => {
136
+ withRepo(({ root }) => {
137
+ const jsonResult = runStatus(root, ["--slug", "example", "--json"]);
138
+ assert.equal(jsonResult.status, 0, jsonResult.stderr);
139
+ const json = JSON.parse(jsonResult.stdout);
140
+ assert.equal(json.status, "approved");
141
+ assert.equal(json.current_iteration, 0);
142
+
143
+ const humanResult = runStatus(root, ["--slug", "example"]);
144
+ assert.equal(humanResult.status, 0, humanResult.stderr);
145
+ assert.match(humanResult.stdout, /Mission: example/);
146
+ assert.match(humanResult.stdout, /Iteration: 0\/3/);
147
+ assert.match(humanResult.stdout, /Next action:/);
148
+ assert.equal(renderHuman(json), humanResult.stdout.trim());
149
+ });
150
+ });
151
+
152
+ test("corrupt history and stale snapshots remain visible errors", () => {
153
+ withRepo(({ root, statePath, historyPath }) => {
154
+ fs.appendFileSync(historyPath, "not-json\n");
155
+ assert.throws(
156
+ () => readMissionStatus({ root, slug: "example" }),
157
+ (error) => error instanceof LoopStateError && error.code === "history_corrupt",
158
+ );
159
+ });
160
+
161
+ withRepo(({ root, contractPath, statePath }) => {
162
+ const initial = JSON.parse(fs.readFileSync(statePath, "utf8"));
163
+ acquireLoop({
164
+ root,
165
+ slug: "example",
166
+ contractPath,
167
+ sessionId: "session-1",
168
+ actionId: "resume-1",
169
+ });
170
+ fs.writeFileSync(statePath, `${JSON.stringify(initial, null, 2)}\n`);
171
+ assert.throws(
172
+ () => readMissionStatus({ root, slug: "example" }),
173
+ (error) => error instanceof LoopStateError && error.code === "snapshot_stale",
174
+ );
175
+ });
176
+ });
177
+
178
+ test("CLI rejects missing loops, invalid slugs, and relative roots", () => {
179
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "opencode-mission-cli-"));
180
+ try {
181
+ const missing = runStatus(root, ["--slug", "example"]);
182
+ assert.equal(missing.status, 1);
183
+ assert.match(missing.stderr, /^state_missing:/);
184
+
185
+ assert.throws(
186
+ () => parseArguments(["--slug", "../unsafe"]),
187
+ (error) => error instanceof LoopStateError && error.code === "invalid_argument",
188
+ );
189
+ assert.throws(
190
+ () => parseArguments(["--root", ".", "--slug", "example"]),
191
+ (error) => error instanceof LoopStateError && error.code === "invalid_argument",
192
+ );
193
+ } finally {
194
+ fs.rmSync(root, { recursive: true, force: true });
195
+ }
196
+ });
@@ -37,6 +37,7 @@ const SKIP_DIRS = new Set([
37
37
 
38
38
  const STACK_RULES = [
39
39
  { file: "package.json", id: "node", confidence: "high" },
40
+ { glob: "scripts/*.mjs", id: "node", confidence: "medium" },
40
41
  { file: "tsconfig.json", id: "typescript", confidence: "high" },
41
42
  { file: "next.config.mjs", id: "nextjs", confidence: "high" },
42
43
  { file: "next.config.js", id: "nextjs", confidence: "high" },
@@ -241,7 +242,7 @@ export function detectStacks(repoRoot) {
241
242
  const seen = new Map();
242
243
 
243
244
  for (const rule of STACK_RULES) {
244
- const matches = matchGlobs(files, [rule.file]);
245
+ const matches = matchGlobs(files, [rule.file ?? rule.glob]);
245
246
  if (matches.length > 0) {
246
247
  const existing = seen.get(rule.id);
247
248
  if (!existing) {
@@ -224,6 +224,23 @@ test("repo with go.mod detects go stack", () => {
224
224
  }
225
225
  });
226
226
 
227
+ test("repo with Node scripts detects node stack without a package manifest", () => {
228
+ const tmp = makeRepoWith({
229
+ "scripts/tool.mjs": "#!/usr/bin/env node\nconsole.log('ok');\n",
230
+ });
231
+ try {
232
+ const result = runSnapshot(tmp);
233
+ const snapshot = parseOutput(result);
234
+
235
+ const node = snapshot.stacks_detected.find((stack) => stack.id === "node");
236
+ assert.ok(node, "should detect node stack");
237
+ assert.equal(node.confidence, "medium");
238
+ assert.ok(node.evidence.includes("scripts/tool.mjs"));
239
+ } finally {
240
+ fs.rmSync(tmp, { recursive: true, force: true });
241
+ }
242
+ });
243
+
227
244
  // ── Test 11: Custom repo with test files detects testing domain ─────────
228
245
 
229
246
  test("repo with test files detects testing domain", () => {
@@ -0,0 +1,72 @@
1
+ const DECISIONS = Object.freeze(["allow", "ask", "deny"]);
2
+
3
+ export const AGENT_IDS = Object.freeze([
4
+ "debugger",
5
+ "designer",
6
+ "developer",
7
+ "evaluator",
8
+ "evolver",
9
+ "lead",
10
+ "researcher",
11
+ "review_api",
12
+ "review_coordinator",
13
+ "review_quality",
14
+ "review_security",
15
+ "review_tests",
16
+ "reviewer",
17
+ "scoper",
18
+ "specifier",
19
+ ]);
20
+
21
+ export const POLICY_OPERATIONS = Object.freeze([
22
+ "read",
23
+ "write",
24
+ "shell",
25
+ "network",
26
+ "commit",
27
+ "push",
28
+ "deploy",
29
+ "delegate",
30
+ ]);
31
+
32
+ const common = {
33
+ read: "allow",
34
+ shell: "ask",
35
+ commit: "deny",
36
+ push: "deny",
37
+ deploy: "deny",
38
+ };
39
+
40
+ export const AGENT_POLICIES = Object.freeze({
41
+ debugger: Object.freeze({ ...common, repository_write: "unspecified", task_default: "unspecified", write: "ask", network: "allow", delegate_to: [] }),
42
+ designer: Object.freeze({ ...common, repository_write: "ask", task_default: "unspecified", write: "ask", network: "allow", delegate_to: [] }),
43
+ developer: Object.freeze({ ...common, repository_write: "allow", task_default: "unspecified", write: "allow", network: "ask", commit: "ask", delegate_to: [] }),
44
+ evaluator: Object.freeze({ ...common, repository_write: "unspecified", task_default: "unspecified", write: "ask", network: "ask", delegate_to: [] }),
45
+ evolver: Object.freeze({ ...common, repository_write: "unspecified", task_default: "unspecified", write: "ask", network: "ask", delegate_to: [] }),
46
+ lead: Object.freeze({ ...common, repository_write: "deny", task_default: "deny", write: "deny", network: "allow", delegate_to: ["debugger", "designer", "developer", "evaluator", "evolver", "researcher", "reviewer", "specifier"] }),
47
+ researcher: Object.freeze({ ...common, repository_write: "ask", task_default: "unspecified", write: "ask", network: "allow", delegate_to: [] }),
48
+ review_api: Object.freeze({ ...common, repository_write: "deny", task_default: "unspecified", write: "deny", network: "deny", delegate_to: [] }),
49
+ review_coordinator: Object.freeze({ ...common, repository_write: "deny", task_default: "deny", write: "deny", network: "deny", delegate_to: ["review_api", "review_quality", "review_security", "review_tests"] }),
50
+ review_quality: Object.freeze({ ...common, repository_write: "deny", task_default: "unspecified", write: "deny", network: "deny", delegate_to: [] }),
51
+ review_security: Object.freeze({ ...common, repository_write: "deny", task_default: "unspecified", write: "deny", network: "deny", delegate_to: [] }),
52
+ review_tests: Object.freeze({ ...common, repository_write: "deny", task_default: "unspecified", write: "deny", network: "deny", delegate_to: [] }),
53
+ reviewer: Object.freeze({ ...common, repository_write: "deny", task_default: "unspecified", write: "deny", network: "ask", delegate_to: [] }),
54
+ scoper: Object.freeze({ ...common, repository_write: "unspecified", task_default: "deny", write: "ask", network: "allow", delegate_to: ["debugger", "researcher", "specifier"] }),
55
+ specifier: Object.freeze({ ...common, repository_write: "ask", task_default: "unspecified", write: "ask", network: "allow", delegate_to: [] }),
56
+ });
57
+
58
+ function isDecision(value) {
59
+ return DECISIONS.includes(value);
60
+ }
61
+
62
+ export function decideToolAccess({ agentId, operation, target } = {}) {
63
+ const policy = AGENT_POLICIES[agentId];
64
+ if (!policy || !POLICY_OPERATIONS.includes(operation)) return "deny";
65
+
66
+ if (operation === "delegate") {
67
+ return policy.delegate_to.includes(target) ? "allow" : "deny";
68
+ }
69
+
70
+ const decision = policy[operation];
71
+ return isDecision(decision) ? decision : "deny";
72
+ }
@@ -0,0 +1,89 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+
4
+ import {
5
+ AGENT_IDS,
6
+ POLICY_OPERATIONS,
7
+ decideToolAccess,
8
+ } from "./runtime-permission-policy.mjs";
9
+
10
+ test("policy covers every configured agent and operation", () => {
11
+ assert.deepEqual(AGENT_IDS, [
12
+ "debugger",
13
+ "designer",
14
+ "developer",
15
+ "evaluator",
16
+ "evolver",
17
+ "lead",
18
+ "researcher",
19
+ "review_api",
20
+ "review_coordinator",
21
+ "review_quality",
22
+ "review_security",
23
+ "review_tests",
24
+ "reviewer",
25
+ "scoper",
26
+ "specifier",
27
+ ]);
28
+ assert.deepEqual(POLICY_OPERATIONS, [
29
+ "read",
30
+ "write",
31
+ "shell",
32
+ "network",
33
+ "commit",
34
+ "push",
35
+ "deploy",
36
+ "delegate",
37
+ ]);
38
+ });
39
+
40
+ test("role policy denies lead and reviewer implementation writes", () => {
41
+ assert.equal(decideToolAccess({ agentId: "lead", operation: "write" }), "deny");
42
+ assert.equal(decideToolAccess({ agentId: "reviewer", operation: "write" }), "deny");
43
+ assert.equal(decideToolAccess({ agentId: "developer", operation: "write" }), "allow");
44
+ assert.equal(decideToolAccess({ agentId: "designer", operation: "write" }), "ask");
45
+ });
46
+
47
+ test("delegation is restricted to the declared task allowlist", () => {
48
+ assert.equal(
49
+ decideToolAccess({ agentId: "lead", operation: "delegate", target: "developer" }),
50
+ "allow",
51
+ );
52
+ assert.equal(
53
+ decideToolAccess({ agentId: "lead", operation: "delegate", target: "unknown" }),
54
+ "deny",
55
+ );
56
+ assert.equal(
57
+ decideToolAccess({ agentId: "scoper", operation: "delegate", target: "researcher" }),
58
+ "allow",
59
+ );
60
+ assert.equal(
61
+ decideToolAccess({ agentId: "reviewer", operation: "delegate", target: "developer" }),
62
+ "deny",
63
+ );
64
+ assert.equal(
65
+ decideToolAccess({ agentId: "review_coordinator", operation: "delegate", target: "review_security" }),
66
+ "allow",
67
+ );
68
+ });
69
+
70
+ test("publication and deployment operations are denied for every role", () => {
71
+ for (const agentId of AGENT_IDS) {
72
+ assert.equal(decideToolAccess({ agentId, operation: "push" }), "deny", agentId);
73
+ assert.equal(decideToolAccess({ agentId, operation: "deploy" }), "deny", agentId);
74
+ }
75
+ });
76
+
77
+ test("unknown identities and operations never receive implicit allow", () => {
78
+ assert.equal(decideToolAccess({ agentId: "not-an-agent", operation: "write" }), "deny");
79
+ assert.equal(decideToolAccess({ agentId: "developer", operation: "not-an-operation" }), "deny");
80
+ assert.equal(decideToolAccess({ agentId: "developer", operation: "delegate", target: "reviewer" }), "deny");
81
+ });
82
+
83
+ test("specialist reviewers cannot write, delegate, or use network tools", () => {
84
+ for (const agentId of ["review_api", "review_quality", "review_security", "review_tests"]) {
85
+ assert.equal(decideToolAccess({ agentId, operation: "write" }), "deny", agentId);
86
+ assert.equal(decideToolAccess({ agentId, operation: "delegate", target: "developer" }), "deny", agentId);
87
+ assert.equal(decideToolAccess({ agentId, operation: "network" }), "deny", agentId);
88
+ }
89
+ });
@@ -0,0 +1,45 @@
1
+ export type OpenDesignHttpOptions = {
2
+ fetchImpl?: typeof fetch
3
+ connectTimeoutMs?: number
4
+ totalTimeoutMs?: number
5
+ idleTimeoutMs?: number
6
+ maxJsonBytes?: number
7
+ maxSseBytes?: number
8
+ maxOutputBytes?: number
9
+ maxEvents?: number
10
+ maxDiagnosticBytes?: number
11
+ }
12
+
13
+ export const OPEN_DESIGN_HTTP_LIMITS: Readonly<{
14
+ connectTimeoutMs: number
15
+ totalTimeoutMs: number
16
+ idleTimeoutMs: number
17
+ maxJsonBytes: number
18
+ maxSseBytes: number
19
+ maxOutputBytes: number
20
+ maxEvents: number
21
+ maxDiagnosticBytes: number
22
+ }>
23
+
24
+ export function requestJson(
25
+ base: string,
26
+ path: string,
27
+ init?: RequestInit,
28
+ options?: OpenDesignHttpOptions,
29
+ ): Promise<unknown>
30
+
31
+ export function parseSseFrames(buffer: string): {
32
+ frames: Array<{ event: string; data: unknown }>
33
+ rest: string
34
+ }
35
+
36
+ export function streamOpenDesignChat(
37
+ base: string,
38
+ body: unknown,
39
+ options?: OpenDesignHttpOptions,
40
+ ): Promise<{
41
+ stdout: string
42
+ stderr: string
43
+ end: unknown
44
+ eventsCount: number
45
+ }>