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.
- package/README.md +73 -4
- package/SECURITY.md +7 -0
- package/docs/cli.md +100 -0
- package/docs/installation.md +25 -5
- package/docs/quickstart.md +1 -1
- package/docs/releases/v1.0.33.md +72 -0
- package/docs/releases/v1.0.34.md +59 -0
- package/docs/releases/v1.0.35.md +62 -0
- package/docs/releases/v1.0.36.md +58 -0
- package/docs/releases/v1.0.37.md +53 -0
- package/docs/security.md +4 -0
- package/docs/supply-chain.md +9 -5
- package/docs/threat-model.md +244 -0
- package/docs/use-cases/README.md +31 -0
- package/docs/use-cases/direct-label-change/README.md +76 -0
- package/docs/use-cases/direct-label-change/before/package.json +8 -0
- package/docs/use-cases/direct-label-change/before/src/settings-label.mjs +1 -0
- package/docs/use-cases/direct-label-change/before/test/settings-label.test.mjs +8 -0
- package/docs/use-cases/direct-label-change/case.json +118 -0
- package/docs/use-cases/direct-label-change/expected/package.json +8 -0
- package/docs/use-cases/direct-label-change/expected/src/settings-label.mjs +1 -0
- package/docs/use-cases/direct-label-change/expected/test/settings-label.test.mjs +8 -0
- package/docs/use-cases/feature-tag-normalizer/README.md +78 -0
- package/docs/use-cases/feature-tag-normalizer/before/package.json +8 -0
- package/docs/use-cases/feature-tag-normalizer/before/src/normalize-tags.mjs +3 -0
- package/docs/use-cases/feature-tag-normalizer/before/test/normalize-tags.test.mjs +13 -0
- package/docs/use-cases/feature-tag-normalizer/case.json +119 -0
- package/docs/use-cases/feature-tag-normalizer/expected/package.json +8 -0
- package/docs/use-cases/feature-tag-normalizer/expected/src/normalize-tags.mjs +14 -0
- package/docs/use-cases/feature-tag-normalizer/expected/test/normalize-tags.test.mjs +18 -0
- package/docs/workflows.md +6 -0
- package/opencode/agents/lead.md +11 -2
- package/opencode/agents/review_api.md +26 -9
- package/opencode/agents/review_coordinator.md +60 -68
- package/opencode/agents/review_quality.md +27 -11
- package/opencode/agents/review_security.md +26 -10
- package/opencode/agents/review_tests.md +26 -9
- package/opencode/agents/reviewer.md +95 -80
- package/opencode/commands/autonomous.md +75 -0
- package/opencode/commands/evolve.md +3 -1
- package/opencode/commands/feature.md +6 -2
- package/opencode/commands/loop.md +12 -8
- package/opencode/commands/review-orchestrated.md +26 -24
- package/opencode/commands/review-preflight.md +8 -7
- package/opencode/commands/review.md +27 -10
- package/opencode/docs/ai/harness/README.md +5 -0
- package/opencode/docs/ai/harness/agents.md +27 -3
- package/opencode/docs/ai/harness/checks.md +18 -0
- package/opencode/docs/ai/harness/commands.md +44 -0
- package/opencode/docs/ai/harness/orchestrated-review.md +8 -1
- package/opencode/docs/ai/harness/orchestration-contracts.json +924 -0
- package/opencode/package-lock.json +14 -8
- package/opencode/package.json +1 -0
- package/opencode/plugins/shell-export-guard.ts +23 -0
- package/opencode/scripts/adversarial-harness.test.mjs +5 -2
- package/opencode/scripts/check-harness.mjs +873 -18
- package/opencode/scripts/check-harness.test.mjs +562 -0
- package/opencode/scripts/loop-state.mjs +88 -14
- package/opencode/scripts/loop-state.test.mjs +82 -5
- package/opencode/scripts/review-orchestrated-prepare.mjs +18 -1
- package/opencode/scripts/review-orchestrated-prepare.test.mjs +49 -0
- package/opencode/scripts/shell-export-policy.d.mts +4 -0
- package/opencode/scripts/shell-export-policy.mjs +272 -0
- package/opencode/scripts/shell-export-policy.test.mjs +96 -0
- package/opencode/skills/code-review-and-quality/SKILL.md +63 -321
- package/opencode/skills/code-review-and-quality/references/profiles/backend-clean-ddd-cqrs.md +60 -0
- package/opencode/skills/code-review-and-quality/references/profiles/backend.md +54 -0
- package/opencode/skills/code-review-and-quality/references/profiles/frontend-clean-layered.md +60 -0
- package/opencode/skills/code-review-and-quality/references/profiles/frontend.md +62 -0
- package/opencode/skills/code-review-and-quality/references/review-policy.md +258 -0
- package/package.json +5 -2
- package/scripts/check-supply-chain.mjs +16 -2
- package/scripts/check-supply-chain.test.mjs +52 -1
- package/scripts/check-threat-model.mjs +421 -0
- package/scripts/check-threat-model.test.mjs +304 -0
- package/scripts/check-use-cases.mjs +501 -0
- package/scripts/check-use-cases.test.mjs +225 -0
- package/scripts/check.sh +55 -1
- package/scripts/install-smoke.sh +24 -1
- package/scripts/manage-installation.mjs +567 -25
- package/scripts/manage-installation.test.mjs +418 -0
- package/scripts/oak.mjs +246 -0
- package/scripts/oak.test.mjs +329 -0
- package/scripts/package-smoke.mjs +57 -0
- package/scripts/package-smoke.test.mjs +75 -2
- package/scripts/version.mjs +1 -0
- package/scripts/version.test.mjs +3 -2
- package/supply-chain.json +1 -0
|
@@ -5,7 +5,8 @@ import fs from "node:fs";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
|
|
8
|
-
const SCHEMA_VERSION =
|
|
8
|
+
const SCHEMA_VERSION = 2;
|
|
9
|
+
const LEGACY_SCHEMA_VERSION = 1;
|
|
9
10
|
const slugPattern = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
10
11
|
const idPattern = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
11
12
|
const approvalStatuses = new Set(["approved"]);
|
|
@@ -48,7 +49,8 @@ function requireExactKeys(value, keys, label, corruptCode = "state_corrupt") {
|
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
function validateState(state) {
|
|
52
|
+
function validateState(state, { allowLegacy = false } = {}) {
|
|
53
|
+
const isLegacy = state?.schema_version === LEGACY_SCHEMA_VERSION;
|
|
52
54
|
requireExactKeys(
|
|
53
55
|
state,
|
|
54
56
|
[
|
|
@@ -61,13 +63,14 @@ function validateState(state) {
|
|
|
61
63
|
"lease",
|
|
62
64
|
"status",
|
|
63
65
|
"current_iteration",
|
|
66
|
+
...(isLegacy ? [] : ["planned_iterations"]),
|
|
64
67
|
"last_completed_step",
|
|
65
68
|
"blocking_cause",
|
|
66
69
|
"last_action_id",
|
|
67
70
|
],
|
|
68
71
|
"state",
|
|
69
72
|
);
|
|
70
|
-
if (state.schema_version !== SCHEMA_VERSION) {
|
|
73
|
+
if (state.schema_version !== SCHEMA_VERSION && !(allowLegacy && isLegacy)) {
|
|
71
74
|
fail("schema_unsupported", `unsupported schema_version ${state.schema_version}`);
|
|
72
75
|
}
|
|
73
76
|
requireString(state.slug, "state.slug", slugPattern);
|
|
@@ -99,6 +102,9 @@ function validateState(state) {
|
|
|
99
102
|
if (!Number.isInteger(state.current_iteration) || state.current_iteration < 0) {
|
|
100
103
|
fail("state_corrupt", "state.current_iteration must be a non-negative integer");
|
|
101
104
|
}
|
|
105
|
+
if (!isLegacy && (!Number.isInteger(state.planned_iterations) || state.planned_iterations < 1 || state.planned_iterations > 6)) {
|
|
106
|
+
fail("state_corrupt", "state.planned_iterations must be an integer from 1 through 6");
|
|
107
|
+
}
|
|
102
108
|
requireNullableString(state.last_completed_step, "state.last_completed_step");
|
|
103
109
|
requireNullableString(state.blocking_cause, "state.blocking_cause");
|
|
104
110
|
requireString(state.last_action_id, "state.last_action_id");
|
|
@@ -121,7 +127,7 @@ function validateEvent(event, expectedSequence) {
|
|
|
121
127
|
`history event ${expectedSequence}`,
|
|
122
128
|
"history_corrupt",
|
|
123
129
|
);
|
|
124
|
-
if (event.schema_version
|
|
130
|
+
if (![LEGACY_SCHEMA_VERSION, SCHEMA_VERSION].includes(event.schema_version) || event.sequence !== expectedSequence) {
|
|
125
131
|
fail("history_corrupt", `history event ${expectedSequence} has invalid sequence or schema`);
|
|
126
132
|
}
|
|
127
133
|
if (
|
|
@@ -138,7 +144,7 @@ function validateEvent(event, expectedSequence) {
|
|
|
138
144
|
fail("history_corrupt", `history event ${expectedSequence} is invalid`);
|
|
139
145
|
}
|
|
140
146
|
try {
|
|
141
|
-
validateState(event.state_after);
|
|
147
|
+
validateState(event.state_after, { allowLegacy: true });
|
|
142
148
|
} catch (error) {
|
|
143
149
|
if (error instanceof LoopStateError) {
|
|
144
150
|
fail("history_corrupt", `history event ${expectedSequence}: ${error.message}`);
|
|
@@ -148,6 +154,9 @@ function validateEvent(event, expectedSequence) {
|
|
|
148
154
|
if (event.state_after.last_action_id !== event.action_id) {
|
|
149
155
|
fail("history_corrupt", `history event ${expectedSequence} action mismatch`);
|
|
150
156
|
}
|
|
157
|
+
if (event.state_after.schema_version !== event.schema_version) {
|
|
158
|
+
fail("history_corrupt", `history event ${expectedSequence} state schema mismatch`);
|
|
159
|
+
}
|
|
151
160
|
return event;
|
|
152
161
|
}
|
|
153
162
|
|
|
@@ -181,10 +190,13 @@ function validateHistoryContinuity(events, expectedSlug) {
|
|
|
181
190
|
} else {
|
|
182
191
|
requireExactKeys(
|
|
183
192
|
first.payload,
|
|
184
|
-
["from_schema_version"],
|
|
193
|
+
["from_schema_version", "planned_iterations"],
|
|
185
194
|
"history event 1 payload",
|
|
186
195
|
"history_corrupt",
|
|
187
196
|
);
|
|
197
|
+
if (first.state_after.planned_iterations !== first.payload.planned_iterations) {
|
|
198
|
+
fail("history_corrupt", "initial migration iteration budget mismatch");
|
|
199
|
+
}
|
|
188
200
|
}
|
|
189
201
|
const immutable = {
|
|
190
202
|
slug: first.state_after.slug,
|
|
@@ -206,7 +218,31 @@ function validateHistoryContinuity(events, expectedSlug) {
|
|
|
206
218
|
if (index === 0) continue;
|
|
207
219
|
const previous = events[index - 1].state_after;
|
|
208
220
|
let expected;
|
|
209
|
-
if (event.type === "
|
|
221
|
+
if (event.type === "migrated") {
|
|
222
|
+
requireExactKeys(
|
|
223
|
+
event.payload,
|
|
224
|
+
["from_schema_version", "planned_iterations"],
|
|
225
|
+
`history event ${index + 1} payload`,
|
|
226
|
+
"history_corrupt",
|
|
227
|
+
);
|
|
228
|
+
if (
|
|
229
|
+
previous.schema_version !== LEGACY_SCHEMA_VERSION
|
|
230
|
+
|| event.payload.from_schema_version !== LEGACY_SCHEMA_VERSION
|
|
231
|
+
|| previous.lease !== null
|
|
232
|
+
|| event.state_after.planned_iterations !== event.payload.planned_iterations
|
|
233
|
+
) {
|
|
234
|
+
fail("history_corrupt", `invalid migration transition at event ${index + 1}`);
|
|
235
|
+
}
|
|
236
|
+
expected = {
|
|
237
|
+
...previous,
|
|
238
|
+
schema_version: SCHEMA_VERSION,
|
|
239
|
+
planned_iterations: event.payload.planned_iterations,
|
|
240
|
+
session_id: event.session_id,
|
|
241
|
+
lease: null,
|
|
242
|
+
status: "approved",
|
|
243
|
+
last_action_id: event.action_id,
|
|
244
|
+
};
|
|
245
|
+
} else if (event.type === "resumed") {
|
|
210
246
|
requireExactKeys(
|
|
211
247
|
event.payload,
|
|
212
248
|
["contract_hash"],
|
|
@@ -237,6 +273,7 @@ function validateHistoryContinuity(events, expectedSlug) {
|
|
|
237
273
|
if (
|
|
238
274
|
previous.lease?.session_id !== event.session_id
|
|
239
275
|
|| event.payload.iteration < previous.current_iteration
|
|
276
|
+
|| event.payload.iteration > previous.planned_iterations
|
|
240
277
|
) {
|
|
241
278
|
fail("history_corrupt", `invalid action transition at event ${index + 1}`);
|
|
242
279
|
}
|
|
@@ -281,7 +318,7 @@ function validateHistoryContinuity(events, expectedSlug) {
|
|
|
281
318
|
} else {
|
|
282
319
|
fail("history_corrupt", `unexpected event type at event ${index + 1}`);
|
|
283
320
|
}
|
|
284
|
-
if (JSON.stringify(event.state_after) !== JSON.stringify(expected)) {
|
|
321
|
+
if (JSON.stringify(stable(event.state_after)) !== JSON.stringify(stable(expected))) {
|
|
285
322
|
fail("history_corrupt", `state transition mismatch at event ${index + 1}`);
|
|
286
323
|
}
|
|
287
324
|
}
|
|
@@ -693,10 +730,14 @@ export function initLoopState({
|
|
|
693
730
|
gitBaseline,
|
|
694
731
|
sessionId,
|
|
695
732
|
actionId,
|
|
733
|
+
plannedIterations,
|
|
696
734
|
}) {
|
|
697
735
|
requireString(gitBaseline, "gitBaseline");
|
|
698
736
|
requireString(sessionId, "sessionId");
|
|
699
737
|
requireString(actionId, "actionId");
|
|
738
|
+
if (!Number.isInteger(plannedIterations) || plannedIterations < 1 || plannedIterations > 6) {
|
|
739
|
+
fail("invalid_argument", "plannedIterations must be an integer from 1 through 6");
|
|
740
|
+
}
|
|
700
741
|
const paths = pathsFor(root, slug);
|
|
701
742
|
ensureLoopsDir(paths);
|
|
702
743
|
const hash = contractHash(contractPath, paths.root);
|
|
@@ -717,6 +758,7 @@ export function initLoopState({
|
|
|
717
758
|
lease: null,
|
|
718
759
|
status: "approved",
|
|
719
760
|
current_iteration: 0,
|
|
761
|
+
planned_iterations: plannedIterations,
|
|
720
762
|
last_completed_step: null,
|
|
721
763
|
blocking_cause: null,
|
|
722
764
|
last_action_id: actionId,
|
|
@@ -870,6 +912,9 @@ export function recordLoopAction({
|
|
|
870
912
|
if (iteration < state.current_iteration) {
|
|
871
913
|
fail("iteration_regression", "iteration cannot move backwards");
|
|
872
914
|
}
|
|
915
|
+
if (iteration > state.planned_iterations) {
|
|
916
|
+
fail("iteration_budget_exceeded", "iteration exceeds the planned iteration budget");
|
|
917
|
+
}
|
|
873
918
|
try {
|
|
874
919
|
return commitTransition({
|
|
875
920
|
paths,
|
|
@@ -1012,27 +1057,49 @@ export function migrateLoopState({
|
|
|
1012
1057
|
sessionId,
|
|
1013
1058
|
actionId,
|
|
1014
1059
|
approvalStatus,
|
|
1060
|
+
plannedIterations,
|
|
1015
1061
|
}) {
|
|
1016
1062
|
if (approvalStatus !== "approved") {
|
|
1017
1063
|
fail("approval_required", "migration requires renewed explicit approval");
|
|
1018
1064
|
}
|
|
1019
1065
|
requireString(sessionId, "sessionId");
|
|
1020
1066
|
requireString(actionId, "actionId");
|
|
1067
|
+
if (!Number.isInteger(plannedIterations) || plannedIterations < 1 || plannedIterations > 6) {
|
|
1068
|
+
fail("invalid_argument", "plannedIterations must be an integer from 1 through 6");
|
|
1069
|
+
}
|
|
1021
1070
|
const paths = pathsFor(root, slug);
|
|
1022
1071
|
ensureLoopsDir(paths);
|
|
1023
1072
|
let legacy = null;
|
|
1024
1073
|
if (lstatIfPresent(paths.state) !== null) {
|
|
1025
1074
|
legacy = readJsonFile(paths.state, "state_corrupt");
|
|
1026
|
-
if (!isObject(legacy) || legacy.schema_version
|
|
1027
|
-
fail("schema_unsupported", "migrate accepts only schema_version 0 or markdown-only state");
|
|
1075
|
+
if (!isObject(legacy) || ![0, LEGACY_SCHEMA_VERSION].includes(legacy.schema_version)) {
|
|
1076
|
+
fail("schema_unsupported", "migrate accepts only schema_version 0, 1, or markdown-only state");
|
|
1028
1077
|
}
|
|
1029
1078
|
}
|
|
1030
1079
|
const baseline = legacy?.git_baseline ?? gitBaseline;
|
|
1031
1080
|
requireString(baseline, "gitBaseline");
|
|
1032
|
-
|
|
1081
|
+
const historyPresent = lstatIfPresent(paths.history) !== null;
|
|
1082
|
+
if (historyPresent && legacy?.schema_version !== LEGACY_SCHEMA_VERSION) {
|
|
1033
1083
|
fail("history_exists", "migration refuses to replace existing append-only history");
|
|
1034
1084
|
}
|
|
1085
|
+
let legacyHistory = null;
|
|
1086
|
+
if (legacy?.schema_version === LEGACY_SCHEMA_VERSION) {
|
|
1087
|
+
legacyHistory = readHistory(paths);
|
|
1088
|
+
if (JSON.stringify(stable(legacyHistory.events.at(-1).state_after)) !== JSON.stringify(stable(legacy))) {
|
|
1089
|
+
fail("snapshot_stale", "snapshot is behind append-only history; run repair before migration");
|
|
1090
|
+
}
|
|
1091
|
+
if (legacy.lease !== null || lstatIfPresent(paths.lock) !== null) {
|
|
1092
|
+
fail("loop_locked", "migration requires a released schema v1 loop");
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1035
1095
|
const hash = contractHash(contractPath, paths.root);
|
|
1096
|
+
if (legacy?.schema_version === LEGACY_SCHEMA_VERSION && hash !== legacy.contract_hash) {
|
|
1097
|
+
fail("contract_mismatch", "renewed approval contract hash must match schema v1 history");
|
|
1098
|
+
}
|
|
1099
|
+
const currentIteration = legacy?.current_iteration ?? 0;
|
|
1100
|
+
if (currentIteration > plannedIterations) {
|
|
1101
|
+
fail("invalid_argument", "plannedIterations cannot be below the current iteration");
|
|
1102
|
+
}
|
|
1036
1103
|
const state = validateState({
|
|
1037
1104
|
schema_version: SCHEMA_VERSION,
|
|
1038
1105
|
slug,
|
|
@@ -1042,18 +1109,22 @@ export function migrateLoopState({
|
|
|
1042
1109
|
approval: { status: "approved", contract_hash: hash },
|
|
1043
1110
|
lease: null,
|
|
1044
1111
|
status: legacy?.status ?? "approved",
|
|
1045
|
-
current_iteration:
|
|
1112
|
+
current_iteration: currentIteration,
|
|
1113
|
+
planned_iterations: plannedIterations,
|
|
1046
1114
|
last_completed_step: legacy?.last_completed_step ?? null,
|
|
1047
1115
|
blocking_cause: legacy?.blocking_cause ?? null,
|
|
1048
1116
|
last_action_id: actionId,
|
|
1049
1117
|
});
|
|
1050
1118
|
const event = {
|
|
1051
1119
|
schema_version: SCHEMA_VERSION,
|
|
1052
|
-
sequence: 1,
|
|
1120
|
+
sequence: legacyHistory ? legacyHistory.events.length + 1 : 1,
|
|
1053
1121
|
action_id: actionId,
|
|
1054
1122
|
type: "migrated",
|
|
1055
1123
|
session_id: sessionId,
|
|
1056
|
-
payload: {
|
|
1124
|
+
payload: {
|
|
1125
|
+
from_schema_version: legacy?.schema_version ?? "markdown",
|
|
1126
|
+
planned_iterations: plannedIterations,
|
|
1127
|
+
},
|
|
1057
1128
|
recorded_at: new Date().toISOString(),
|
|
1058
1129
|
state_after: state,
|
|
1059
1130
|
};
|
|
@@ -1092,6 +1163,9 @@ function cliOptions(options) {
|
|
|
1092
1163
|
sessionId: options.session_id,
|
|
1093
1164
|
actionId: options.action_id,
|
|
1094
1165
|
approvalStatus: options.approval_status,
|
|
1166
|
+
plannedIterations: options.planned_iterations === undefined
|
|
1167
|
+
? undefined
|
|
1168
|
+
: Number(options.planned_iterations),
|
|
1095
1169
|
};
|
|
1096
1170
|
}
|
|
1097
1171
|
|
|
@@ -31,7 +31,7 @@ function withRepo(callback) {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function initExample(root, contractPath) {
|
|
34
|
+
function initExample(root, contractPath, plannedIterations = 6) {
|
|
35
35
|
return initLoopState({
|
|
36
36
|
root,
|
|
37
37
|
slug: "example",
|
|
@@ -39,15 +39,16 @@ function initExample(root, contractPath) {
|
|
|
39
39
|
gitBaseline: "abc123",
|
|
40
40
|
sessionId: "session-1",
|
|
41
41
|
actionId: "approve-1",
|
|
42
|
+
plannedIterations,
|
|
42
43
|
});
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
test("initializes canonical state and append-only history without replacing markdown", () => {
|
|
46
47
|
withRepo(({ root, contractPath }) => {
|
|
47
48
|
const markdown = fs.readFileSync(contractPath, "utf8");
|
|
48
|
-
const state = initExample(root, contractPath);
|
|
49
|
+
const state = initExample(root, contractPath, 1);
|
|
49
50
|
|
|
50
|
-
assert.equal(state.schema_version,
|
|
51
|
+
assert.equal(state.schema_version, 2);
|
|
51
52
|
assert.equal(state.slug, "example");
|
|
52
53
|
assert.match(state.contract_hash, /^sha256:[a-f0-9]{64}$/);
|
|
53
54
|
assert.equal(state.approval.status, "approved");
|
|
@@ -57,6 +58,7 @@ test("initializes canonical state and append-only history without replacing mark
|
|
|
57
58
|
assert.equal(state.lease, null);
|
|
58
59
|
assert.equal(state.status, "approved");
|
|
59
60
|
assert.equal(state.current_iteration, 0);
|
|
61
|
+
assert.equal(state.planned_iterations, 1);
|
|
60
62
|
assert.equal(state.last_completed_step, null);
|
|
61
63
|
assert.equal(state.blocking_cause, null);
|
|
62
64
|
assert.equal(state.last_action_id, "approve-1");
|
|
@@ -98,6 +100,32 @@ test("acquires one durable lease and rejects a simultaneous resume", () => {
|
|
|
98
100
|
});
|
|
99
101
|
});
|
|
100
102
|
|
|
103
|
+
test("rejects action records above the persisted iteration budget", () => {
|
|
104
|
+
withRepo(({ root, contractPath }) => {
|
|
105
|
+
initExample(root, contractPath, 1);
|
|
106
|
+
acquireLoop({
|
|
107
|
+
root,
|
|
108
|
+
slug: "example",
|
|
109
|
+
contractPath,
|
|
110
|
+
sessionId: "session-1",
|
|
111
|
+
actionId: "resume-1",
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
assert.throws(
|
|
115
|
+
() => recordLoopAction({
|
|
116
|
+
root,
|
|
117
|
+
slug: "example",
|
|
118
|
+
sessionId: "session-1",
|
|
119
|
+
actionId: "iteration-2",
|
|
120
|
+
iteration: 2,
|
|
121
|
+
completedStep: "developer_change",
|
|
122
|
+
blockingCause: null,
|
|
123
|
+
}),
|
|
124
|
+
(error) => error instanceof LoopStateError && error.code === "iteration_budget_exceeded",
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
101
129
|
test("serializes transitions even when processes share the same session id", () => {
|
|
102
130
|
withRepo(({ root, contractPath }) => {
|
|
103
131
|
initExample(root, contractPath);
|
|
@@ -427,6 +455,7 @@ test("migrates a schema v0 snapshot only with explicit renewed approval", () =>
|
|
|
427
455
|
sessionId: "session-2",
|
|
428
456
|
actionId: "migrate-1",
|
|
429
457
|
approvalStatus: "pending",
|
|
458
|
+
plannedIterations: 3,
|
|
430
459
|
}),
|
|
431
460
|
(error) => error instanceof LoopStateError && error.code === "approval_required",
|
|
432
461
|
);
|
|
@@ -438,8 +467,10 @@ test("migrates a schema v0 snapshot only with explicit renewed approval", () =>
|
|
|
438
467
|
sessionId: "session-2",
|
|
439
468
|
actionId: "migrate-1",
|
|
440
469
|
approvalStatus: "approved",
|
|
470
|
+
plannedIterations: 3,
|
|
441
471
|
});
|
|
442
|
-
assert.equal(migrated.schema_version,
|
|
472
|
+
assert.equal(migrated.schema_version, 2);
|
|
473
|
+
assert.equal(migrated.planned_iterations, 3);
|
|
443
474
|
assert.equal(migrated.current_iteration, 2);
|
|
444
475
|
assert.equal(migrated.last_completed_step, "reviewer_rejected");
|
|
445
476
|
assert.equal(migrated.approval.status, "approved");
|
|
@@ -447,6 +478,47 @@ test("migrates a schema v0 snapshot only with explicit renewed approval", () =>
|
|
|
447
478
|
});
|
|
448
479
|
});
|
|
449
480
|
|
|
481
|
+
test("migrates schema v1 only with renewed approval and an explicit budget", () => {
|
|
482
|
+
withRepo(({ root, contractPath }) => {
|
|
483
|
+
initExample(root, contractPath);
|
|
484
|
+
const statePath = path.join(root, ".opencode/loops/example.json");
|
|
485
|
+
const historyPath = path.join(root, ".opencode/loops/example.history.jsonl");
|
|
486
|
+
const legacyState = JSON.parse(fs.readFileSync(statePath, "utf8"));
|
|
487
|
+
legacyState.schema_version = 1;
|
|
488
|
+
delete legacyState.planned_iterations;
|
|
489
|
+
fs.writeFileSync(statePath, `${JSON.stringify(legacyState)}\n`);
|
|
490
|
+
const [legacyEvent] = fs.readFileSync(historyPath, "utf8").trim().split("\n").map(JSON.parse);
|
|
491
|
+
legacyEvent.schema_version = 1;
|
|
492
|
+
legacyEvent.state_after = legacyState;
|
|
493
|
+
fs.writeFileSync(historyPath, `${JSON.stringify(legacyEvent)}\n`);
|
|
494
|
+
|
|
495
|
+
assert.throws(
|
|
496
|
+
() => migrateLoopState({
|
|
497
|
+
root,
|
|
498
|
+
slug: "example",
|
|
499
|
+
contractPath,
|
|
500
|
+
sessionId: "session-2",
|
|
501
|
+
actionId: "migrate-1",
|
|
502
|
+
approvalStatus: "approved",
|
|
503
|
+
}),
|
|
504
|
+
(error) => error instanceof LoopStateError && error.code === "invalid_argument",
|
|
505
|
+
);
|
|
506
|
+
|
|
507
|
+
const migrated = migrateLoopState({
|
|
508
|
+
root,
|
|
509
|
+
slug: "example",
|
|
510
|
+
contractPath,
|
|
511
|
+
sessionId: "session-2",
|
|
512
|
+
actionId: "migrate-1",
|
|
513
|
+
approvalStatus: "approved",
|
|
514
|
+
plannedIterations: 3,
|
|
515
|
+
});
|
|
516
|
+
assert.equal(migrated.schema_version, 2);
|
|
517
|
+
assert.equal(migrated.planned_iterations, 3);
|
|
518
|
+
assert.equal(inspectLoopState({ root, slug: "example" }).planned_iterations, 3);
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
|
|
450
522
|
test("releases only the owning session lease", () => {
|
|
451
523
|
withRepo(({ root, contractPath }) => {
|
|
452
524
|
initExample(root, contractPath);
|
|
@@ -497,11 +569,14 @@ test("exposes the durable operations through the portable CLI", () => {
|
|
|
497
569
|
"session-1",
|
|
498
570
|
"--action-id",
|
|
499
571
|
"approve-1",
|
|
572
|
+
"--planned-iterations",
|
|
573
|
+
"1",
|
|
500
574
|
],
|
|
501
575
|
{ encoding: "utf8" },
|
|
502
576
|
);
|
|
503
577
|
assert.equal(init.status, 0, init.stderr);
|
|
504
|
-
assert.equal(JSON.parse(init.stdout).schema_version,
|
|
578
|
+
assert.equal(JSON.parse(init.stdout).schema_version, 2);
|
|
579
|
+
assert.equal(JSON.parse(init.stdout).planned_iterations, 1);
|
|
505
580
|
|
|
506
581
|
const inspect = spawnSync(
|
|
507
582
|
process.execPath,
|
|
@@ -532,6 +607,7 @@ test("rejects a symlinked state ancestor that escapes the root", () => {
|
|
|
532
607
|
gitBaseline: "abc123",
|
|
533
608
|
sessionId: "session-1",
|
|
534
609
|
actionId: "approve-1",
|
|
610
|
+
plannedIterations: 1,
|
|
535
611
|
}),
|
|
536
612
|
(error) => error instanceof LoopStateError && error.code === "unsafe_path",
|
|
537
613
|
);
|
|
@@ -566,6 +642,7 @@ test("does not follow a broken history symlink during initialization", () => {
|
|
|
566
642
|
gitBaseline: "abc123",
|
|
567
643
|
sessionId: "session-1",
|
|
568
644
|
actionId: "approve-1",
|
|
645
|
+
plannedIterations: 1,
|
|
569
646
|
}),
|
|
570
647
|
(error) => error instanceof LoopStateError && error.code === "state_exists",
|
|
571
648
|
);
|
|
@@ -171,6 +171,13 @@ function isDocFile(file) {
|
|
|
171
171
|
return /\.(md|mdx|txt|rst|adoc)$/i.test(file) || /^docs\//.test(file);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
function isOperationalMarkdown(file) {
|
|
175
|
+
return file === "AGENTS.md"
|
|
176
|
+
|| /^agents\/[^/]+\.md$/i.test(file)
|
|
177
|
+
|| /^commands\/[^/]+\.md$/i.test(file)
|
|
178
|
+
|| /^skills\/.+\/SKILL\.md$/i.test(file);
|
|
179
|
+
}
|
|
180
|
+
|
|
174
181
|
function isLockfile(file) {
|
|
175
182
|
return /(^|\/)(package-lock\.json|pnpm-lock\.yaml|yarn\.lock|bun\.lockb|Cargo\.lock|Gemfile\.lock|Pipfile\.lock|poetry\.lock|pubspec\.lock|Podfile\.lock)$/i.test(file);
|
|
176
183
|
}
|
|
@@ -197,6 +204,7 @@ function isMigration(file) {
|
|
|
197
204
|
|
|
198
205
|
function riskFlagsForFile(file) {
|
|
199
206
|
const flags = [];
|
|
207
|
+
if (isOperationalMarkdown(file)) flags.push("harness_contract");
|
|
200
208
|
if (isLockfile(file)) flags.push("lockfiles", "deps");
|
|
201
209
|
if (isGenerated(file)) flags.push("generated");
|
|
202
210
|
if (isMigration(file)) flags.push("migrations");
|
|
@@ -245,7 +253,9 @@ function classify(files, stats, riskFlags, filteredFiles, budgets, totalPatchByt
|
|
|
245
253
|
const reviewed = files.reviewed;
|
|
246
254
|
const reviewable = reviewed.filter((file) => !shouldFilterPatch(file));
|
|
247
255
|
const changedLines = [...stats.values()].reduce((sum, item) => sum + item.added + item.deleted, 0);
|
|
248
|
-
const docOnly = reviewed.length > 0 && reviewed.every(
|
|
256
|
+
const docOnly = reviewed.length > 0 && reviewed.every(
|
|
257
|
+
(file) => (isDocFile(file) && !isOperationalMarkdown(file)) || shouldFilterPatch(file),
|
|
258
|
+
);
|
|
249
259
|
const highRiskFlags = ["security", "auth", "permissions", "secrets", "migrations", "infra", "deps", "lockfiles"];
|
|
250
260
|
const hasHighRisk = riskFlags.some((flag) => highRiskFlags.includes(flag));
|
|
251
261
|
const hasReviewRisk = riskFlags.some((flag) => !["generated", "bundles", "sourcemaps", "minified"].includes(flag));
|
|
@@ -288,6 +298,8 @@ function buildExecutionPlan(classification, recommendedReviewers, options) {
|
|
|
288
298
|
if (mode === "preflight") {
|
|
289
299
|
return {
|
|
290
300
|
mode,
|
|
301
|
+
review_stage: "preflight",
|
|
302
|
+
verdict: "not_run",
|
|
291
303
|
dry_run_alias: options.dryRun,
|
|
292
304
|
ai_review: "not_run",
|
|
293
305
|
strategy: "preflight_only",
|
|
@@ -304,6 +316,8 @@ function buildExecutionPlan(classification, recommendedReviewers, options) {
|
|
|
304
316
|
const planned = reviewer ? [reviewer] : [];
|
|
305
317
|
return {
|
|
306
318
|
mode,
|
|
319
|
+
review_stage: "partial",
|
|
320
|
+
verdict: "not_run",
|
|
307
321
|
dry_run_alias: false,
|
|
308
322
|
ai_review: planned.length > 0 ? "coordinator_focused" : "not_run",
|
|
309
323
|
strategy: planned.length > 0
|
|
@@ -321,6 +335,8 @@ function buildExecutionPlan(classification, recommendedReviewers, options) {
|
|
|
321
335
|
const planned = recommendedReviewers.slice(0, cap);
|
|
322
336
|
return {
|
|
323
337
|
mode,
|
|
338
|
+
review_stage: "partial",
|
|
339
|
+
verdict: "not_run",
|
|
324
340
|
dry_run_alias: false,
|
|
325
341
|
ai_review: planned.length > 0 ? "experimental_specialized_agents" : "not_run",
|
|
326
342
|
strategy: "Experimental costly mode; run selected specialized reviewers sequentially with timeout and partial-failure reporting.",
|
|
@@ -563,6 +579,7 @@ export {
|
|
|
563
579
|
buildExecutionPlan,
|
|
564
580
|
classify,
|
|
565
581
|
cleanupWorkspace,
|
|
582
|
+
isOperationalMarkdown,
|
|
566
583
|
parseArgs,
|
|
567
584
|
prepareReviewWorkspace,
|
|
568
585
|
recordReviewerResult,
|
|
@@ -77,6 +77,55 @@ test("doc-only changes are skipped without launching reviewers", () => {
|
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
+
test("operational Markdown is never skipped as doc-only", async (t) => {
|
|
81
|
+
for (const [rel, operational] of [
|
|
82
|
+
["AGENTS.md", true],
|
|
83
|
+
["agents/reviewer.md", true],
|
|
84
|
+
["commands/review.md", true],
|
|
85
|
+
["skills/code-review-and-quality/SKILL.md", true],
|
|
86
|
+
["docs/guide.md", false],
|
|
87
|
+
]) {
|
|
88
|
+
await t.test(rel, () => {
|
|
89
|
+
const cwd = makeRepo();
|
|
90
|
+
try {
|
|
91
|
+
writeFile(cwd, rel, "# Initial contract\n");
|
|
92
|
+
run(cwd, "git", ["add", rel]);
|
|
93
|
+
run(cwd, "git", ["commit", "-m", `add ${rel}`]);
|
|
94
|
+
writeFile(cwd, rel, "# Changed contract\n");
|
|
95
|
+
|
|
96
|
+
const manifest = prepare(cwd);
|
|
97
|
+
if (operational) {
|
|
98
|
+
assert.notEqual(manifest.classification, "skipped", `${rel} was skipped as docs`);
|
|
99
|
+
assert.ok(manifest.risk_flags.includes("harness_contract"));
|
|
100
|
+
} else {
|
|
101
|
+
assert.equal(manifest.classification, "skipped");
|
|
102
|
+
assert.ok(!manifest.risk_flags.includes("harness_contract"));
|
|
103
|
+
}
|
|
104
|
+
assert.equal(manifest.execution_plan.review_stage, "preflight");
|
|
105
|
+
assert.equal(manifest.execution_plan.verdict, "not_run");
|
|
106
|
+
} finally {
|
|
107
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("review stage stays non-final in every orchestrated execution mode", () => {
|
|
114
|
+
for (const [args, stage] of [
|
|
115
|
+
[[], "preflight"],
|
|
116
|
+
[["--agents"], "partial"],
|
|
117
|
+
[["--full-agents"], "partial"],
|
|
118
|
+
]) {
|
|
119
|
+
const plan = buildExecutionPlan(
|
|
120
|
+
"lite",
|
|
121
|
+
["review_quality", "review_tests"],
|
|
122
|
+
parseArgs(args),
|
|
123
|
+
);
|
|
124
|
+
assert.equal(plan.review_stage, stage);
|
|
125
|
+
assert.equal(plan.verdict, "not_run");
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
80
129
|
test("normal implementation change selects quality reviewer", () => {
|
|
81
130
|
const cwd = makeRepo();
|
|
82
131
|
try {
|