opencode-completion-gate 1.0.0 → 1.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.1](https://github.com/PauloDevelo/opencode-completion-gate/compare/v1.1.0...v1.1.1) (2026-09-06)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * parse equals-form retry overrides ([7473ee7](https://github.com/PauloDevelo/opencode-completion-gate/commit/7473ee770af1e8cf21a00e54fd3fe7d7251dd66e))
9
+
10
+ ## [1.1.0](https://github.com/PauloDevelo/opencode-completion-gate/compare/v1.0.0...v1.1.0) (2026-09-06)
11
+
12
+
13
+ ### Features
14
+
15
+ * per-command max retries for /gate --only ([addc6ad](https://github.com/PauloDevelo/opencode-completion-gate/commit/addc6ad97f2ed154d448119ff63049683dd89b5c))
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * add AGENTS.md + /gate command ([0bfe0b7](https://github.com/PauloDevelo/opencode-completion-gate/commit/0bfe0b7bd1aadcc492524ee82940ff0cb4395e0f))
21
+ * normalize repository URL per npm pkg fix ([b3bef58](https://github.com/PauloDevelo/opencode-completion-gate/commit/b3bef58bf69672ff2070d1c07c447b7914a73b48))
22
+
3
23
  ## 1.0.0 (2026-09-06)
4
24
 
5
25
 
package/README.md CHANGED
@@ -34,8 +34,9 @@ Add the plugin to your OpenCode configuration:
34
34
 
35
35
  ```
36
36
  /gate # enable (same as /gate on)
37
- /gate status # e.g. "[completion-gate] status: ENABLED · retries=1 · lastOutcome=fail"
37
+ /gate status # e.g. "Completion gate: ENABLED · retries=1 · lastOutcome=fail · extraCommand=none · mode=combined · maxRetries=3 (config)"
38
38
  /gate off # disable for this session
39
+ /gate --only "npm run test-ci" --retries 5 # run only this command with its own retry cap
39
40
  ```
40
41
 
41
42
  ## Configuration
package/dist/core.d.ts CHANGED
@@ -50,6 +50,40 @@ export interface AssertionOutcome {
50
50
  evidence: string;
51
51
  }
52
52
  export declare function runCommandAssertion(a: CommandAssertion, cwd: string, isAborted?: () => boolean): Promise<AssertionOutcome>;
53
+ type GateMode = 'combined' | 'command-only';
54
+ interface GateSessionState {
55
+ sessionID: string;
56
+ directory: string;
57
+ gateEnabled: boolean;
58
+ extraCommand?: string;
59
+ gateMode: GateMode;
60
+ /** Per-session retry cap for command-only mode (`/gate --only ... --retries N`).
61
+ * Null/absent = fall back to the project config (or the default 3). */
62
+ sessionMaxRetries: number | null;
63
+ retries: number;
64
+ lastOutcome: 'pass' | 'fail' | null;
65
+ escalated: boolean;
66
+ busy: boolean;
67
+ deleted: boolean;
68
+ }
69
+ /**
70
+ * Splits a `--only` remainder into the session command plus an optional
71
+ * `--retries N` (alias `--max-retries N`) override. The flag is recognized
72
+ * only as a leading or trailing token sequence so a command that merely
73
+ * mentions `--retries` mid-line stays untouched; when both ends carry the
74
+ * flag the leading value wins.
75
+ */
76
+ export declare function parseOnlyCommand(remainder: string): {
77
+ command: string;
78
+ maxRetries?: number;
79
+ invalidRetry: boolean;
80
+ };
81
+ /** Effective retry cap for a session: session override wins in command-only
82
+ * mode, otherwise the project config (or the default 3). */
83
+ export declare function effectiveMaxRetries(state: Pick<GateSessionState, 'gateMode' | 'sessionMaxRetries'>, configMaxRetries: number): {
84
+ value: number;
85
+ source: 'session' | 'config';
86
+ };
53
87
  export type PickPrResult = {
54
88
  ok: true;
55
89
  prId: number;
package/dist/index.js CHANGED
@@ -169,6 +169,47 @@ async function runCommandAssertion(a, cwd, isAborted) {
169
169
  ${truncateTail([r.stderr, r.stdout].filter((s) => s.trim()).join("\n---\n"))}`
170
170
  );
171
171
  }
172
+ function parsePositiveIntToken(tok) {
173
+ const n = Number(tok);
174
+ return Number.isFinite(n) && n > 0 ? Math.floor(n) : null;
175
+ }
176
+ function parseOnlyCommand(remainder) {
177
+ if (!/^\s/.test(remainder)) return { command: "", invalidRetry: false };
178
+ let body = remainder.trim();
179
+ let leading = null;
180
+ let trailing = null;
181
+ let invalid = false;
182
+ const leadingMatch = /^--(?:retries|max-retries)(?:\s+|=)(\S+)\s*/i.exec(body);
183
+ if (leadingMatch) {
184
+ const parsed = parsePositiveIntToken(leadingMatch[1]);
185
+ if (parsed === null) invalid = true;
186
+ else leading = parsed;
187
+ body = body.slice(leadingMatch[0].length).trim();
188
+ } else if (/^--(?:retries|max-retries)(?:\s*=\s*)?$/i.test(body)) {
189
+ invalid = true;
190
+ }
191
+ const trailingMatch = /\s+--(?:retries|max-retries)(?:\s+|=)(\S+)\s*$/i.exec(body);
192
+ if (trailingMatch) {
193
+ const parsed = parsePositiveIntToken(trailingMatch[1]);
194
+ if (parsed === null) invalid = true;
195
+ else trailing = parsed;
196
+ body = body.slice(0, trailingMatch.index).trim();
197
+ } else if (/\s+--(?:retries|max-retries)(?:\s*=\s*)?$/i.test(body)) {
198
+ invalid = true;
199
+ }
200
+ const maxRetries = leading ?? trailing ?? void 0;
201
+ return {
202
+ command: body,
203
+ ...maxRetries !== void 0 ? { maxRetries } : {},
204
+ invalidRetry: invalid
205
+ };
206
+ }
207
+ function effectiveMaxRetries(state, configMaxRetries) {
208
+ if (state.gateMode === "command-only" && state.sessionMaxRetries !== null) {
209
+ return { value: state.sessionMaxRetries, source: "session" };
210
+ }
211
+ return { value: configMaxRetries, source: "config" };
212
+ }
172
213
  function pickActivePrDetails(prListJson) {
173
214
  let parsed;
174
215
  try {
@@ -676,6 +717,7 @@ export {
676
717
  buildShellInvocation,
677
718
  defaultBuildLogArtifact,
678
719
  downloadBuildLogs,
720
+ effectiveMaxRetries,
679
721
  evaluateAssertions,
680
722
  execFileOut,
681
723
  execShell,
@@ -683,6 +725,7 @@ export {
683
725
  findGateConfigPath,
684
726
  isHumanReviewPolicy,
685
727
  loadGateConfig,
728
+ parseOnlyCommand,
686
729
  parseVerdict,
687
730
  pickActivePr,
688
731
  pickActivePrDetails,
package/dist/plugin.js CHANGED
@@ -174,6 +174,11 @@ var INTERNAL_MARKER = "[completion-gate-internal]";
174
174
  var BOOTSTRAP_COMMAND_ENV = "OPENCODE_GATE_BOOTSTRAP_COMMAND";
175
175
  var BOOTSTRAP_COMMAND_B64_ENV = "OPENCODE_GATE_BOOTSTRAP_COMMAND_B64";
176
176
  var BOOTSTRAP_MODE_ENV = "OPENCODE_GATE_BOOTSTRAP_MODE";
177
+ var BOOTSTRAP_MAX_RETRIES_ENV = "OPENCODE_GATE_BOOTSTRAP_MAX_RETRIES";
178
+ function parsePositiveIntToken(tok) {
179
+ const n = Number(tok);
180
+ return Number.isFinite(n) && n > 0 ? Math.floor(n) : null;
181
+ }
177
182
  function readBootstrapGateCommand() {
178
183
  const b64 = process.env[BOOTSTRAP_COMMAND_B64_ENV];
179
184
  const plain = process.env[BOOTSTRAP_COMMAND_ENV];
@@ -193,16 +198,62 @@ function readBootstrapGateCommand() {
193
198
  command = command.trim();
194
199
  if (!command) return null;
195
200
  const mode = process.env[BOOTSTRAP_MODE_ENV]?.trim().toLowerCase() === "combined" ? "combined" : "command-only";
196
- return { command, mode };
201
+ let maxRetries;
202
+ if (mode === "command-only") {
203
+ const raw = process.env[BOOTSTRAP_MAX_RETRIES_ENV];
204
+ if (typeof raw === "string" && raw.trim() !== "") {
205
+ const parsed = parsePositiveIntToken(raw.trim());
206
+ if (parsed !== null) maxRetries = parsed;
207
+ }
208
+ }
209
+ return maxRetries !== void 0 ? { command, mode, maxRetries } : { command, mode };
197
210
  }
198
211
  function consumeBootstrapGateCommand() {
199
212
  delete process.env[BOOTSTRAP_COMMAND_B64_ENV];
200
213
  delete process.env[BOOTSTRAP_COMMAND_ENV];
201
214
  delete process.env[BOOTSTRAP_MODE_ENV];
215
+ delete process.env[BOOTSTRAP_MAX_RETRIES_ENV];
202
216
  }
203
217
  var TOGGLE_RE = /^\[completion-gate\](?:\s+(.*?))?\s*$/i;
204
218
  var INJECTED_FAILURE_RE = /^✖ Completion gate failed — "[^"]+"\. Fix these issues, then finish again\.\n\n```[\s\S]*\n```\n\n\(RETRY \d+\/\d+\)$/;
205
219
  var INJECTED_SUCCESS_RE = /^✅ Completion gate passed \([^\n]*\)\. You may report done\.$/;
220
+ function parseOnlyCommand(remainder) {
221
+ if (!/^\s/.test(remainder)) return { command: "", invalidRetry: false };
222
+ let body = remainder.trim();
223
+ let leading = null;
224
+ let trailing = null;
225
+ let invalid = false;
226
+ const leadingMatch = /^--(?:retries|max-retries)(?:\s+|=)(\S+)\s*/i.exec(body);
227
+ if (leadingMatch) {
228
+ const parsed = parsePositiveIntToken(leadingMatch[1]);
229
+ if (parsed === null) invalid = true;
230
+ else leading = parsed;
231
+ body = body.slice(leadingMatch[0].length).trim();
232
+ } else if (/^--(?:retries|max-retries)(?:\s*=\s*)?$/i.test(body)) {
233
+ invalid = true;
234
+ }
235
+ const trailingMatch = /\s+--(?:retries|max-retries)(?:\s+|=)(\S+)\s*$/i.exec(body);
236
+ if (trailingMatch) {
237
+ const parsed = parsePositiveIntToken(trailingMatch[1]);
238
+ if (parsed === null) invalid = true;
239
+ else trailing = parsed;
240
+ body = body.slice(0, trailingMatch.index).trim();
241
+ } else if (/\s+--(?:retries|max-retries)(?:\s*=\s*)?$/i.test(body)) {
242
+ invalid = true;
243
+ }
244
+ const maxRetries = leading ?? trailing ?? void 0;
245
+ return {
246
+ command: body,
247
+ ...maxRetries !== void 0 ? { maxRetries } : {},
248
+ invalidRetry: invalid
249
+ };
250
+ }
251
+ function effectiveMaxRetries(state, configMaxRetries) {
252
+ if (state.gateMode === "command-only" && state.sessionMaxRetries !== null) {
253
+ return { value: state.sessionMaxRetries, source: "session" };
254
+ }
255
+ return { value: configMaxRetries, source: "config" };
256
+ }
206
257
  var sessions = /* @__PURE__ */ new Map();
207
258
  var deletedSessionIDs = /* @__PURE__ */ new Set();
208
259
  var sessionGenerations = /* @__PURE__ */ new Map();
@@ -226,6 +277,7 @@ function createGateSessionState(sessionID, directory) {
226
277
  directory,
227
278
  gateEnabled: false,
228
279
  gateMode: "combined",
280
+ sessionMaxRetries: null,
229
281
  retries: 0,
230
282
  lastOutcome: null,
231
283
  escalated: false,
@@ -278,28 +330,33 @@ async function applyToggle(client, state, rawArgument) {
278
330
  const normalized = rawArgument.trim().toLowerCase();
279
331
  const arg = normalized || "on";
280
332
  if (arg === "status") {
281
- const notice2 = `Completion gate: ${state.gateEnabled ? "ENABLED" : "disabled"} \xB7 retries=${state.retries} \xB7 lastOutcome=${state.lastOutcome ?? "n/a"} \xB7 extraCommand=${state.extraCommand ? "configured" : "none"} \xB7 mode=${state.gateMode}`;
333
+ const loaded = loadGateConfig(state.directory);
334
+ const cap = state.gateMode === "command-only" && state.sessionMaxRetries !== null ? { value: state.sessionMaxRetries, source: "session" } : { value: loaded?.config.maxRetries ?? 3, source: "config" };
335
+ const notice2 = `Completion gate: ${state.gateEnabled ? "ENABLED" : "disabled"} \xB7 retries=${state.retries} \xB7 lastOutcome=${state.lastOutcome ?? "n/a"} \xB7 extraCommand=${state.extraCommand ? "configured" : "none"} \xB7 mode=${state.gateMode} \xB7 maxRetries=${cap.value} (${cap.source})`;
282
336
  await safeToast(client, notice2);
283
337
  return { notice: notice2, kind: "status" };
284
338
  }
285
339
  if (/^--only/i.test(rawArgument.trim())) {
286
340
  const onlyMatch = /^--only(.*)$/i.exec(rawArgument.trim());
287
341
  const remainder = onlyMatch?.[1] ?? "";
288
- const command = /^\s/.test(remainder) ? remainder.trim() : "";
289
- if (!command) {
290
- const notice3 = 'Usage: /gate --only "command"';
342
+ const parsed = parseOnlyCommand(remainder);
343
+ if (!parsed.command || parsed.invalidRetry) {
344
+ const notice3 = 'Usage: /gate --only "command" [--retries N]';
291
345
  await safeToast(client, notice3, "error");
292
346
  return { notice: notice3, kind: "usage" };
293
347
  }
294
- state.extraCommand = command;
348
+ state.extraCommand = parsed.command;
295
349
  state.gateMode = "command-only";
350
+ state.sessionMaxRetries = parsed.maxRetries ?? null;
296
351
  state.gateEnabled = true;
297
352
  state.retries = 0;
298
353
  state.escalated = false;
299
354
  state.lastOutcome = null;
300
- const notice2 = `Completion gate armed (command-only): ${command}`;
355
+ const notice2 = parsed.maxRetries !== void 0 ? `Completion gate armed (command-only): ${parsed.command} \xB7 maxRetries=${parsed.maxRetries}` : `Completion gate armed (command-only): ${parsed.command}`;
301
356
  await safeToast(client, notice2);
302
- logDiag(`gate command-only custom command registered on ${state.sessionID}`);
357
+ logDiag(
358
+ `gate command-only custom command registered on ${state.sessionID}` + (parsed.maxRetries !== void 0 ? ` (session maxRetries=${parsed.maxRetries})` : "")
359
+ );
303
360
  return { notice: notice2, kind: "enabled" };
304
361
  }
305
362
  if (arg !== "on" && arg !== "off") {
@@ -857,6 +914,7 @@ async function runGateTurnEnd(client, state) {
857
914
  }
858
915
  const projectRoot = loaded?.projectRoot ?? state.directory;
859
916
  const config = loaded?.config ?? { maxRetries: 3, assertions: [] };
917
+ const cap = effectiveMaxRetries(state, config.maxRetries);
860
918
  const sessionAssertion = {
861
919
  type: "command",
862
920
  name: "session-command",
@@ -865,7 +923,7 @@ async function runGateTurnEnd(client, state) {
865
923
  };
866
924
  const assertions = state.extraCommand ? state.gateMode === "command-only" ? [sessionAssertion] : [sessionAssertion, ...config.assertions] : config.assertions;
867
925
  logDiag(
868
- `gate turn-end on ${state.sessionID}: ${loaded ? `config ${loaded.path}` : "command-only without project config"} (${assertions.length} assertion(s), maxRetries=${config.maxRetries}, retries so far=${state.retries})`
926
+ `gate turn-end on ${state.sessionID}: ${loaded ? `config ${loaded.path}` : "command-only without project config"} (${assertions.length} assertion(s), maxRetries=${cap.value} (${cap.source}), retries so far=${state.retries})`
869
927
  );
870
928
  const results = await evaluateAssertions(assertions, projectRoot, client, isAborted);
871
929
  if (results === null) {
@@ -901,30 +959,30 @@ async function runGateTurnEnd(client, state) {
901
959
  return;
902
960
  }
903
961
  state.lastOutcome = "fail";
904
- if (state.retries >= config.maxRetries) {
962
+ if (state.retries >= cap.value) {
905
963
  if (!state.escalated) {
906
964
  state.escalated = true;
907
965
  await client.tui.showToast({
908
966
  body: {
909
967
  variant: "error",
910
- message: `\u2192 Completion gate "${last.name}" still failing after ${config.maxRetries} retries \u2014 manual attention needed`,
968
+ message: `\u2192 Completion gate "${last.name}" still failing after ${cap.value} retries \u2014 manual attention needed`,
911
969
  duration: 15e3
912
970
  }
913
971
  }).catch(() => {
914
972
  });
915
973
  logDiag(
916
- `gate ESCALATED on ${state.sessionID}: "${last.name}" still failing after ${config.maxRetries} retries \u2014 manual attention needed`
974
+ `gate ESCALATED on ${state.sessionID}: "${last.name}" still failing after ${cap.value} retries \u2014 manual attention needed`
917
975
  );
918
976
  }
919
977
  return;
920
978
  }
921
979
  state.retries += 1;
922
980
  logDiag(
923
- `gate FAILED on ${state.sessionID}: "${last.name}" \u2014 retry ${state.retries}/${config.maxRetries}, injecting fix request`
981
+ `gate FAILED on ${state.sessionID}: "${last.name}" \u2014 retry ${state.retries}/${cap.value}, injecting fix request`
924
982
  );
925
983
  await client.session.promptAsync({
926
984
  path: { id: state.sessionID },
927
- body: { parts: [{ type: "text", text: injectFailureText(state, last, config.maxRetries) }] }
985
+ body: { parts: [{ type: "text", text: injectFailureText(state, last, cap.value) }] }
928
986
  }).catch((err) => logDiag(`retry prompt error: ${err?.message ?? err}`));
929
987
  }
930
988
  var plugin = async ({ client }) => {
@@ -963,17 +1021,18 @@ var plugin = async ({ client }) => {
963
1021
  consumeBootstrapGateCommand();
964
1022
  created.extraCommand = bootstrap.command;
965
1023
  created.gateMode = bootstrap.mode;
1024
+ created.sessionMaxRetries = bootstrap.mode === "command-only" && bootstrap.maxRetries !== void 0 ? bootstrap.maxRetries : null;
966
1025
  created.gateEnabled = true;
967
1026
  created.retries = 0;
968
1027
  created.escalated = false;
969
1028
  created.lastOutcome = null;
970
1029
  logDiag(
971
- `gate bootstrap ${bootstrap.mode} custom command registered on ${created.sessionID}`
1030
+ `gate bootstrap ${bootstrap.mode} custom command registered on ${created.sessionID}` + (created.sessionMaxRetries !== null ? ` (session maxRetries=${created.sessionMaxRetries})` : "")
972
1031
  );
973
1032
  await client.tui.showToast({
974
1033
  body: {
975
1034
  variant: "info",
976
- message: `Completion gate armed (${bootstrap.mode}): ${bootstrap.command}`
1035
+ message: created.sessionMaxRetries !== null ? `Completion gate armed (${bootstrap.mode}): ${bootstrap.command} \xB7 maxRetries=${created.sessionMaxRetries}` : `Completion gate armed (${bootstrap.mode}): ${bootstrap.command}`
977
1036
  }
978
1037
  }).catch(() => {
979
1038
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-completion-gate",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "OpenCode plugin: per-session quality gate that blocks declaring done until configured assertions pass",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.js",
@@ -40,7 +40,7 @@
40
40
  "license": "MIT",
41
41
  "repository": {
42
42
  "type": "git",
43
- "url": "https://github.com/PauloDevelo/opencode-completion-gate.git"
43
+ "url": "git+https://github.com/PauloDevelo/opencode-completion-gate.git"
44
44
  },
45
45
  "bugs": {
46
46
  "url": "https://github.com/PauloDevelo/opencode-completion-gate/issues"