opencode-agent-orchestration-kit 1.0.32 → 1.0.37

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 (88) hide show
  1. package/README.md +73 -4
  2. package/SECURITY.md +7 -0
  3. package/docs/cli.md +100 -0
  4. package/docs/installation.md +25 -5
  5. package/docs/quickstart.md +1 -1
  6. package/docs/releases/v1.0.33.md +72 -0
  7. package/docs/releases/v1.0.34.md +59 -0
  8. package/docs/releases/v1.0.35.md +62 -0
  9. package/docs/releases/v1.0.36.md +58 -0
  10. package/docs/releases/v1.0.37.md +53 -0
  11. package/docs/security.md +4 -0
  12. package/docs/supply-chain.md +9 -5
  13. package/docs/threat-model.md +244 -0
  14. package/docs/use-cases/README.md +31 -0
  15. package/docs/use-cases/direct-label-change/README.md +76 -0
  16. package/docs/use-cases/direct-label-change/before/package.json +8 -0
  17. package/docs/use-cases/direct-label-change/before/src/settings-label.mjs +1 -0
  18. package/docs/use-cases/direct-label-change/before/test/settings-label.test.mjs +8 -0
  19. package/docs/use-cases/direct-label-change/case.json +118 -0
  20. package/docs/use-cases/direct-label-change/expected/package.json +8 -0
  21. package/docs/use-cases/direct-label-change/expected/src/settings-label.mjs +1 -0
  22. package/docs/use-cases/direct-label-change/expected/test/settings-label.test.mjs +8 -0
  23. package/docs/use-cases/feature-tag-normalizer/README.md +78 -0
  24. package/docs/use-cases/feature-tag-normalizer/before/package.json +8 -0
  25. package/docs/use-cases/feature-tag-normalizer/before/src/normalize-tags.mjs +3 -0
  26. package/docs/use-cases/feature-tag-normalizer/before/test/normalize-tags.test.mjs +13 -0
  27. package/docs/use-cases/feature-tag-normalizer/case.json +119 -0
  28. package/docs/use-cases/feature-tag-normalizer/expected/package.json +8 -0
  29. package/docs/use-cases/feature-tag-normalizer/expected/src/normalize-tags.mjs +14 -0
  30. package/docs/use-cases/feature-tag-normalizer/expected/test/normalize-tags.test.mjs +18 -0
  31. package/docs/workflows.md +6 -0
  32. package/opencode/agents/lead.md +11 -2
  33. package/opencode/agents/review_api.md +26 -9
  34. package/opencode/agents/review_coordinator.md +60 -68
  35. package/opencode/agents/review_quality.md +27 -11
  36. package/opencode/agents/review_security.md +26 -10
  37. package/opencode/agents/review_tests.md +26 -9
  38. package/opencode/agents/reviewer.md +95 -80
  39. package/opencode/commands/autonomous.md +75 -0
  40. package/opencode/commands/evolve.md +3 -1
  41. package/opencode/commands/feature.md +6 -2
  42. package/opencode/commands/loop.md +12 -8
  43. package/opencode/commands/review-orchestrated.md +26 -24
  44. package/opencode/commands/review-preflight.md +8 -7
  45. package/opencode/commands/review.md +27 -10
  46. package/opencode/docs/ai/harness/README.md +5 -0
  47. package/opencode/docs/ai/harness/agents.md +27 -3
  48. package/opencode/docs/ai/harness/checks.md +18 -0
  49. package/opencode/docs/ai/harness/commands.md +44 -0
  50. package/opencode/docs/ai/harness/orchestrated-review.md +8 -1
  51. package/opencode/docs/ai/harness/orchestration-contracts.json +924 -0
  52. package/opencode/package-lock.json +14 -8
  53. package/opencode/package.json +1 -0
  54. package/opencode/plugins/shell-export-guard.ts +23 -0
  55. package/opencode/scripts/adversarial-harness.test.mjs +5 -2
  56. package/opencode/scripts/check-harness.mjs +873 -18
  57. package/opencode/scripts/check-harness.test.mjs +562 -0
  58. package/opencode/scripts/loop-state.mjs +88 -14
  59. package/opencode/scripts/loop-state.test.mjs +82 -5
  60. package/opencode/scripts/review-orchestrated-prepare.mjs +18 -1
  61. package/opencode/scripts/review-orchestrated-prepare.test.mjs +49 -0
  62. package/opencode/scripts/shell-export-policy.d.mts +4 -0
  63. package/opencode/scripts/shell-export-policy.mjs +272 -0
  64. package/opencode/scripts/shell-export-policy.test.mjs +96 -0
  65. package/opencode/skills/code-review-and-quality/SKILL.md +63 -321
  66. package/opencode/skills/code-review-and-quality/references/profiles/backend-clean-ddd-cqrs.md +60 -0
  67. package/opencode/skills/code-review-and-quality/references/profiles/backend.md +54 -0
  68. package/opencode/skills/code-review-and-quality/references/profiles/frontend-clean-layered.md +60 -0
  69. package/opencode/skills/code-review-and-quality/references/profiles/frontend.md +62 -0
  70. package/opencode/skills/code-review-and-quality/references/review-policy.md +258 -0
  71. package/package.json +5 -2
  72. package/scripts/check-supply-chain.mjs +16 -2
  73. package/scripts/check-supply-chain.test.mjs +52 -1
  74. package/scripts/check-threat-model.mjs +421 -0
  75. package/scripts/check-threat-model.test.mjs +304 -0
  76. package/scripts/check-use-cases.mjs +501 -0
  77. package/scripts/check-use-cases.test.mjs +225 -0
  78. package/scripts/check.sh +55 -1
  79. package/scripts/install-smoke.sh +24 -1
  80. package/scripts/manage-installation.mjs +567 -25
  81. package/scripts/manage-installation.test.mjs +418 -0
  82. package/scripts/oak.mjs +246 -0
  83. package/scripts/oak.test.mjs +329 -0
  84. package/scripts/package-smoke.mjs +57 -0
  85. package/scripts/package-smoke.test.mjs +75 -2
  86. package/scripts/version.mjs +1 -0
  87. package/scripts/version.test.mjs +3 -2
  88. package/supply-chain.json +1 -0
@@ -0,0 +1,421 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ const SCRIPT_PATH = fileURLToPath(import.meta.url);
8
+ const ROOT = path.dirname(path.dirname(SCRIPT_PATH));
9
+ const MODEL_PATH = path.join(ROOT, "docs/threat-model.md");
10
+ const AGENTS_PATH = path.join(ROOT, "opencode/agents");
11
+ const SCENARIOS_PATH = path.join(
12
+ ROOT,
13
+ "opencode/docs/ai/evolution/benchmarks/adversarial-scenarios.jsonl",
14
+ );
15
+
16
+ const REQUIRED_SECTIONS = [
17
+ "Scope and security objectives",
18
+ "Actors",
19
+ "Assets",
20
+ "Trust boundaries",
21
+ "Agent capabilities",
22
+ "External surfaces",
23
+ "Persistence surfaces",
24
+ "Data flows",
25
+ "Risk register",
26
+ "Adversarial traceability",
27
+ "Residual risks and assumptions",
28
+ "Private and public boundary",
29
+ ];
30
+ const SEVERITIES = new Set(["high", "medium", "low"]);
31
+ const STATUSES = new Set([
32
+ "mitigated",
33
+ "partially-mitigated",
34
+ "accepted",
35
+ "out-of-scope",
36
+ ]);
37
+ const EVIDENCE_PREFIXES = ["test:", "check:", "limitation:"];
38
+ const PRIVATE_MARKERS = [
39
+ ["", "Users", ""].join("/"),
40
+ [".config", "opencode"].join("/"),
41
+ ["auth", "json"].join("."),
42
+ ["OPENAI", "API", "KEY"].join("_"),
43
+ ["synology", "me"].join("."),
44
+ ];
45
+
46
+ const TABLES = {
47
+ Actors: ["ID", "Actor", "Trust", "Capabilities"],
48
+ Assets: ["ID", "Asset", "Protection"],
49
+ "Trust boundaries": ["ID", "Boundary", "Flow"],
50
+ "Agent capabilities": [
51
+ "Agent",
52
+ "Edit",
53
+ "Shell",
54
+ "Network",
55
+ "External directory",
56
+ "Delegation",
57
+ "Role",
58
+ "Source",
59
+ ],
60
+ "External surfaces": ["Surface", "Boundary", "Controls or limitations"],
61
+ "Persistence surfaces": [
62
+ "Surface",
63
+ "Owner",
64
+ "Sensitivity",
65
+ "Lifecycle",
66
+ "Controls or limitations",
67
+ ],
68
+ "Risk register": [
69
+ "ID",
70
+ "Title",
71
+ "Actor or input",
72
+ "Assets",
73
+ "Boundaries",
74
+ "Abuse",
75
+ "Severity",
76
+ "Controls",
77
+ "Evidence",
78
+ "Status",
79
+ "Residual",
80
+ "Authority",
81
+ "Review trigger",
82
+ ],
83
+ "Adversarial traceability": ["Scenario ID", "Risk ID", "Evidence"],
84
+ };
85
+
86
+ function modelError(message) {
87
+ const error = new Error(message);
88
+ error.code = "INVALID_THREAT_MODEL";
89
+ return error;
90
+ }
91
+
92
+ function cleanCell(value) {
93
+ const trimmed = value.trim();
94
+ const match = trimmed.match(/^`([^`]+)`$/);
95
+ return match ? match[1] : trimmed;
96
+ }
97
+
98
+ function parseTableLine(line) {
99
+ const trimmed = line.trim();
100
+ if (!trimmed.startsWith("|") || !trimmed.endsWith("|")) {
101
+ throw modelError("Markdown table rows must start and end with |");
102
+ }
103
+ return trimmed
104
+ .slice(1, -1)
105
+ .split("|")
106
+ .map(cleanCell);
107
+ }
108
+
109
+ export function parseMarkdownTable(text, heading, expectedHeaders) {
110
+ if (typeof text !== "string") throw modelError("threat model must be text");
111
+ const lines = text.split(/\r?\n/);
112
+ const headingLine = `## ${heading}`;
113
+ const headingIndex = lines.findIndex((line) => line.trim() === headingLine);
114
+ if (headingIndex === -1) throw modelError(`missing section: ${heading}`);
115
+
116
+ let tableIndex = -1;
117
+ for (let index = headingIndex + 1; index < lines.length; index += 1) {
118
+ const line = lines[index].trim();
119
+ if (line.startsWith("## ")) break;
120
+ if (line.startsWith("|")) {
121
+ tableIndex = index;
122
+ break;
123
+ }
124
+ }
125
+ if (tableIndex === -1) throw modelError(`${heading}: missing Markdown table`);
126
+
127
+ const headers = parseTableLine(lines[tableIndex]);
128
+ if (JSON.stringify(headers) !== JSON.stringify(expectedHeaders)) {
129
+ throw modelError(
130
+ `${heading}: expected headers ${expectedHeaders.join(", ")}`,
131
+ );
132
+ }
133
+ const separator = parseTableLine(lines[tableIndex + 1] ?? "");
134
+ if (
135
+ separator.length !== headers.length
136
+ || separator.some((cell) => !/^:?-{3,}:?$/.test(cell))
137
+ ) {
138
+ throw modelError(`${heading}: invalid Markdown table separator`);
139
+ }
140
+
141
+ const rows = [];
142
+ for (let index = tableIndex + 2; index < lines.length; index += 1) {
143
+ if (!lines[index].trim().startsWith("|")) break;
144
+ const cells = parseTableLine(lines[index]);
145
+ if (cells.length !== headers.length) {
146
+ throw modelError(`${heading}: row ${rows.length + 1} has wrong column count`);
147
+ }
148
+ rows.push(Object.fromEntries(headers.map((header, cell) => [
149
+ header,
150
+ cells[cell],
151
+ ])));
152
+ }
153
+ if (rows.length === 0) throw modelError(`${heading}: table must not be empty`);
154
+ return rows;
155
+ }
156
+
157
+ function splitCell(value, label) {
158
+ const values = value.split("<br>").map(cleanCell);
159
+ if (values.some((item) => item === "")) {
160
+ throw modelError(`${label}: empty list item`);
161
+ }
162
+ return values;
163
+ }
164
+
165
+ function requireNonEmpty(row, fields, id) {
166
+ for (const field of fields) {
167
+ if (typeof row[field] !== "string" || row[field].trim() === "") {
168
+ throw modelError(`${id}: ${field} must not be empty`);
169
+ }
170
+ }
171
+ }
172
+
173
+ function requireExactSet(actual, expected, label) {
174
+ const duplicates = actual.filter((value, index) => actual.indexOf(value) !== index);
175
+ if (duplicates.length > 0) {
176
+ throw modelError(`${label}: duplicate ${duplicates[0]}`);
177
+ }
178
+ const actualSet = new Set(actual);
179
+ const expectedSet = new Set(expected);
180
+ const missing = [...expectedSet].filter((value) => !actualSet.has(value));
181
+ const extra = [...actualSet].filter((value) => !expectedSet.has(value));
182
+ if (missing.length > 0 || extra.length > 0) {
183
+ throw modelError(
184
+ `${label}: inventory mismatch; missing=${missing.join(",") || "none"}; extra=${extra.join(",") || "none"}`,
185
+ );
186
+ }
187
+ }
188
+
189
+ function requiredRange(prefix, count) {
190
+ return Array.from(
191
+ { length: count },
192
+ (_, index) => `${prefix}-${String(index + 1).padStart(3, "0")}`,
193
+ );
194
+ }
195
+
196
+ function requireIds(rows, pattern, required, label) {
197
+ const ids = rows.map((row) => row.ID);
198
+ for (const id of ids) {
199
+ if (!pattern.test(id)) throw modelError(`${label}: invalid ID ${id}`);
200
+ }
201
+ const duplicates = ids.filter((id, index) => ids.indexOf(id) !== index);
202
+ if (duplicates.length > 0) {
203
+ throw modelError(`${label}: duplicate ${duplicates[0]}`);
204
+ }
205
+ const missing = required.filter((id) => !ids.includes(id));
206
+ if (missing.length > 0) {
207
+ throw modelError(`${label}: missing required IDs ${missing.join(", ")}`);
208
+ }
209
+ return new Set(ids);
210
+ }
211
+
212
+ function requireKnownReferences(value, known, label) {
213
+ for (const reference of splitCell(value, label)) {
214
+ if (!known.has(reference)) {
215
+ throw modelError(`${label}: unknown reference ${reference}`);
216
+ }
217
+ }
218
+ }
219
+
220
+ function requireEvidence(value, label) {
221
+ for (const evidence of splitCell(value, label)) {
222
+ if (!EVIDENCE_PREFIXES.some((prefix) => evidence.startsWith(prefix))) {
223
+ throw modelError(
224
+ `${label}: evidence must start with test:, check:, or limitation:`,
225
+ );
226
+ }
227
+ }
228
+ }
229
+
230
+ export function validateThreatModel(text, { agentIds, scenarioIds }) {
231
+ if (!Array.isArray(agentIds) || !Array.isArray(scenarioIds)) {
232
+ throw modelError("agentIds and scenarioIds must be arrays");
233
+ }
234
+ for (const section of REQUIRED_SECTIONS) {
235
+ const matches = text
236
+ .split(/\r?\n/)
237
+ .filter((line) => line.trim() === `## ${section}`);
238
+ if (matches.length !== 1) {
239
+ throw modelError(
240
+ `${section}: required exactly once, found ${matches.length}`,
241
+ );
242
+ }
243
+ }
244
+ for (const marker of PRIVATE_MARKERS) {
245
+ if (text.includes(marker)) {
246
+ throw modelError(`private marker is forbidden in threat model: ${marker}`);
247
+ }
248
+ }
249
+
250
+ const tables = Object.fromEntries(
251
+ Object.entries(TABLES).map(([heading, headers]) => [
252
+ heading,
253
+ parseMarkdownTable(text, heading, headers),
254
+ ]),
255
+ );
256
+ const actorIds = requireIds(
257
+ tables.Actors,
258
+ /^AC-\d{3}$/,
259
+ requiredRange("AC", 6),
260
+ "actors",
261
+ );
262
+ const assetIds = requireIds(
263
+ tables.Assets,
264
+ /^A-\d{3}$/,
265
+ requiredRange("A", 10),
266
+ "assets",
267
+ );
268
+ const boundaryIds = requireIds(
269
+ tables["Trust boundaries"],
270
+ /^TB-\d{3}$/,
271
+ requiredRange("TB", 9),
272
+ "trust boundaries",
273
+ );
274
+ const riskIds = requireIds(
275
+ tables["Risk register"],
276
+ /^TM-\d{3}$/,
277
+ requiredRange("TM", 20),
278
+ "risks",
279
+ );
280
+
281
+ for (const row of tables.Actors) {
282
+ requireNonEmpty(row, TABLES.Actors, row.ID);
283
+ }
284
+ for (const row of tables.Assets) {
285
+ requireNonEmpty(row, TABLES.Assets, row.ID);
286
+ }
287
+ for (const row of tables["Trust boundaries"]) {
288
+ requireNonEmpty(row, TABLES["Trust boundaries"], row.ID);
289
+ }
290
+
291
+ const documentedAgents = tables["Agent capabilities"].map((row) => row.Agent);
292
+ requireExactSet(documentedAgents, agentIds, "agents");
293
+ for (const row of tables["Agent capabilities"]) {
294
+ requireNonEmpty(row, TABLES["Agent capabilities"], row.Agent);
295
+ if (row.Source !== `opencode/agents/${row.Agent}.md`) {
296
+ throw modelError(`${row.Agent}: source must point to its public agent file`);
297
+ }
298
+ }
299
+
300
+ for (const row of tables["External surfaces"]) {
301
+ requireNonEmpty(row, TABLES["External surfaces"], row.Surface);
302
+ requireKnownReferences(
303
+ row.Boundary,
304
+ boundaryIds,
305
+ `${row.Surface} boundary`,
306
+ );
307
+ }
308
+ for (const row of tables["Persistence surfaces"]) {
309
+ requireNonEmpty(row, TABLES["Persistence surfaces"], row.Surface);
310
+ }
311
+
312
+ for (const row of tables["Risk register"]) {
313
+ requireNonEmpty(row, TABLES["Risk register"], row.ID);
314
+ requireKnownReferences(
315
+ row["Actor or input"],
316
+ actorIds,
317
+ `${row.ID} actor or input`,
318
+ );
319
+ requireKnownReferences(row.Assets, assetIds, `${row.ID} assets`);
320
+ requireKnownReferences(row.Boundaries, boundaryIds, `${row.ID} boundaries`);
321
+ if (!SEVERITIES.has(row.Severity)) {
322
+ throw modelError(`${row.ID}: invalid severity ${row.Severity}`);
323
+ }
324
+ if (!STATUSES.has(row.Status)) {
325
+ throw modelError(`${row.ID}: invalid status ${row.Status}`);
326
+ }
327
+ requireEvidence(row.Evidence, `${row.ID} evidence`);
328
+ if (
329
+ row.Status === "accepted"
330
+ && (
331
+ row.Authority !== "maintainer"
332
+ || row["Review trigger"].toLowerCase() === "none"
333
+ )
334
+ ) {
335
+ throw modelError(
336
+ `${row.ID}: accepted risk requires maintainer authority and a review trigger`,
337
+ );
338
+ }
339
+ }
340
+
341
+ const traceRows = tables["Adversarial traceability"];
342
+ const documentedScenarios = traceRows.map((row) => row["Scenario ID"]);
343
+ requireExactSet(documentedScenarios, scenarioIds, "scenarios");
344
+ for (const row of traceRows) {
345
+ requireNonEmpty(row, TABLES["Adversarial traceability"], row["Scenario ID"]);
346
+ if (!riskIds.has(row["Risk ID"])) {
347
+ throw modelError(
348
+ `${row["Scenario ID"]}: unknown risk ${row["Risk ID"]}`,
349
+ );
350
+ }
351
+ requireEvidence(row.Evidence, `${row["Scenario ID"]} evidence`);
352
+ }
353
+
354
+ return {
355
+ actors: tables.Actors.length,
356
+ assets: tables.Assets.length,
357
+ boundaries: tables["Trust boundaries"].length,
358
+ agents: documentedAgents.length,
359
+ risks: tables["Risk register"].length,
360
+ scenarios: documentedScenarios.length,
361
+ };
362
+ }
363
+
364
+ function readRegularFile(file, label) {
365
+ let stat;
366
+ try {
367
+ stat = fs.lstatSync(file);
368
+ } catch {
369
+ throw modelError(`${label} is missing`);
370
+ }
371
+ if (stat.isSymbolicLink() || !stat.isFile()) {
372
+ throw modelError(`${label} must be a regular non-symlink file`);
373
+ }
374
+ return fs.readFileSync(file, "utf8");
375
+ }
376
+
377
+ function loadScenarioIds() {
378
+ const text = readRegularFile(SCENARIOS_PATH, "adversarial scenario corpus");
379
+ if (text.trim() === "") throw modelError("adversarial scenario corpus is empty");
380
+ return text.trim().split("\n").map((line, index) => {
381
+ let scenario;
382
+ try {
383
+ scenario = JSON.parse(line);
384
+ } catch {
385
+ throw modelError(`adversarial scenario line ${index + 1} is invalid JSON`);
386
+ }
387
+ if (typeof scenario.id !== "string" || scenario.id === "") {
388
+ throw modelError(`adversarial scenario line ${index + 1} is missing id`);
389
+ }
390
+ return scenario.id;
391
+ }).sort();
392
+ }
393
+
394
+ function loadAgentIds() {
395
+ return fs.readdirSync(AGENTS_PATH, { withFileTypes: true })
396
+ .filter((entry) => entry.isFile() && entry.name.endsWith(".md"))
397
+ .map((entry) => path.basename(entry.name, ".md"))
398
+ .sort();
399
+ }
400
+
401
+ function runCli() {
402
+ const summary = validateThreatModel(
403
+ readRegularFile(MODEL_PATH, "canonical threat model"),
404
+ {
405
+ agentIds: loadAgentIds(),
406
+ scenarioIds: loadScenarioIds(),
407
+ },
408
+ );
409
+ console.log(
410
+ `Threat model check passed: ${summary.actors} actors, ${summary.assets} assets, ${summary.boundaries} boundaries, ${summary.agents} agents, ${summary.risks} risks, ${summary.scenarios} adversarial scenarios.`,
411
+ );
412
+ }
413
+
414
+ if (process.argv[1] && path.resolve(process.argv[1]) === SCRIPT_PATH) {
415
+ try {
416
+ runCli();
417
+ } catch (error) {
418
+ console.error(error instanceof Error ? error.message : String(error));
419
+ process.exitCode = 1;
420
+ }
421
+ }