@plainconceptsplatform/workflows 0.4.28 → 0.4.32

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.
@@ -21,6 +21,8 @@ export declare function catalogSourcePath(modulePath?: string): string;
21
21
  export declare function installCatalog(repositoryPath: string, options?: CatalogInstallOptions): Promise<CatalogInstallResult>;
22
22
  export declare function installTemplate(repositoryPath: string, template: TemplateName, options?: CatalogInstallOptions): Promise<CatalogInstallResult>;
23
23
  export declare function installMandatoryFiles(repositoryPath: string, options?: CatalogInstallOptions): Promise<CatalogInstallResult>;
24
+ export declare function installedRoutes(repositoryPath: string): Promise<RouteName[]>;
25
+ export declare function removeRouteFiles(repositoryPath: string, routes: readonly RouteName[]): Promise<string[]>;
24
26
  export declare function isTemplateName(value: string): value is TemplateName;
25
27
  export declare function ensurePreCommitHook(repositoryPath: string): Promise<void>;
26
28
  export declare function runCompileIfAvailable(repositoryPath: string): Promise<void>;
@@ -4,7 +4,7 @@ import { constants } from "node:fs";
4
4
  import { dirname, join, relative, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { promisify } from "node:util";
7
- import { catalogTemplates, mandatoryFiles, routeNames, templateNames } from "./workflow-catalog.js";
7
+ import { catalogTemplates, mandatoryFiles, routeNames, templateNames, workflowRoutes } from "./workflow-catalog.js";
8
8
  import { processRoutes, excludedWorkerFiles } from "./route-processing.js";
9
9
  import { generateOpencodeCi, generateOpencodeConfig, generateStackDefaults, injectStackEnv } from "./stack-defaults.js";
10
10
  const execFileAsync = promisify(execFile);
@@ -149,6 +149,28 @@ export async function installMandatoryFiles(repositoryPath, options = {}) {
149
149
  await applyTransaction(repositoryPath, [...updates, await preCommitHookUpdate(repositoryPath)]);
150
150
  return { installed: files.map((file) => file.target), conflicts };
151
151
  }
152
+ export async function installedRoutes(repositoryPath) {
153
+ const found = await Promise.all(workflowRoutes.map(async (route) => (await exists(join(repositoryPath, ".github", "workflows", route.worker))) ? route.name : undefined));
154
+ return found.filter((name) => name !== undefined);
155
+ }
156
+ export async function removeRouteFiles(repositoryPath, routes) {
157
+ const workerByRoute = new Map(workflowRoutes.map((route) => [route.name, route.worker]));
158
+ const removed = [];
159
+ for (const route of routes) {
160
+ const worker = workerByRoute.get(route);
161
+ if (worker === undefined)
162
+ continue;
163
+ const lock = worker.replace(/\.md$/, ".lock.yml");
164
+ for (const file of [worker, lock]) {
165
+ const destination = join(repositoryPath, ".github", "workflows", file);
166
+ if (await exists(destination)) {
167
+ await rm(destination, { force: true });
168
+ removed.push(`.github/workflows/${file}`);
169
+ }
170
+ }
171
+ }
172
+ return removed.sort();
173
+ }
152
174
  export function isTemplateName(value) {
153
175
  return templateNames.includes(value);
154
176
  }
@@ -3,7 +3,7 @@ import { constants } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { dirname, join } from "node:path";
5
5
  import { afterEach, describe, expect, it } from "vitest";
6
- import { catalogSourcePath, ensurePreCommitHook, installCatalog, installMandatoryFiles, installTemplate } from "./catalog-installation.js";
6
+ import { catalogSourcePath, ensurePreCommitHook, installCatalog, installedRoutes, installMandatoryFiles, installTemplate, removeRouteFiles } from "./catalog-installation.js";
7
7
  const temporaryDirectories = [];
8
8
  afterEach(async () => {
9
9
  await Promise.all(temporaryDirectories.splice(0).map((directory) => rm(directory, { force: true, recursive: true })));
@@ -385,6 +385,36 @@ describe("catalog installation", () => {
385
385
  });
386
386
  });
387
387
  });
388
+ describe("route lifecycle", () => {
389
+ it("detects installed route workers in workflowRoutes order", async () => {
390
+ const repositoryPath = await createDirectory({
391
+ ".github/workflows/agent-implement.md": "# Implement\n",
392
+ ".github/workflows/agent-refine.md": "# Refine\n",
393
+ });
394
+ await expect(installedRoutes(repositoryPath)).resolves.toEqual(["refine", "implement"]);
395
+ });
396
+ it("returns an empty list when no route workers are installed", async () => {
397
+ const repositoryPath = await createDirectory({});
398
+ await expect(installedRoutes(repositoryPath)).resolves.toEqual([]);
399
+ });
400
+ it("removes a route worker and its generated lock, leaving other workers", async () => {
401
+ const repositoryPath = await createDirectory({
402
+ ".github/workflows/agent-refine.md": "# Refine\n",
403
+ ".github/workflows/agent-refine.lock.yml": "generated\n",
404
+ ".github/workflows/agent-implement.md": "# Implement\n",
405
+ });
406
+ await expect(removeRouteFiles(repositoryPath, ["refine"])).resolves.toEqual([
407
+ ".github/workflows/agent-refine.lock.yml",
408
+ ".github/workflows/agent-refine.md",
409
+ ]);
410
+ await expect(readFile(join(repositoryPath, ".github/workflows/agent-refine.md"), "utf8")).rejects.toThrow();
411
+ await expect(readFile(join(repositoryPath, ".github/workflows/agent-implement.md"), "utf8")).resolves.toBe("# Implement\n");
412
+ });
413
+ it("ignores routes that are not installed", async () => {
414
+ const repositoryPath = await createDirectory({});
415
+ await expect(removeRouteFiles(repositoryPath, ["propose"])).resolves.toEqual([]);
416
+ });
417
+ });
388
418
  async function createDirectory(files) {
389
419
  const directory = await mkdtemp(join(tmpdir(), "workflows-"));
390
420
  temporaryDirectories.push(directory);
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { inspectRepository, parseVisibility, resolveVisibility } from "./repository-inspection.js";
3
- import { installCatalog, installTemplate, isTemplateName } from "./catalog-installation.js";
3
+ import { installCatalog, installedRoutes, installTemplate, isTemplateName, removeRouteFiles } from "./catalog-installation.js";
4
4
  import { formatCatalog, listCatalog, searchCatalog } from "./catalog-listing.js";
5
5
  import { routeNames, templateNames } from "./workflow-catalog.js";
6
6
  import { runInteractive } from "./tui.js";
@@ -21,6 +21,7 @@ Commands:
21
21
  (default) Launch the interactive TUI for selecting and installing items.
22
22
  init Inspect the repository and report its stack and visibility.
23
23
  add [routes] [--template <name>] [--force] Install route workers, a template, or mandatory files.
24
+ remove <routes> [--force] Uninstall route workers and regenerate the router without them.
24
25
  update Alias for add.
25
26
  status Print repository inspection as JSON.
26
27
  list List all available workflows and templates with install status.
@@ -35,6 +36,12 @@ Route names (positional arguments to add):
35
36
  add --template agentics-checks Installs the named template only (no mandatory files).
36
37
  add refine --template agentics-checks Installs routes + mandatory + the named template.
37
38
  add refine implement --force Forces re-install of routes plus mandatory, overwriting.
39
+ remove propose Uninstalls the propose worker and drops it from the router.
40
+
41
+ add and remove keep the router consistent with what is installed: add unions the requested
42
+ routes with the routes already present, and remove drops the requested routes from that set.
43
+ Both regenerate the router, classifier, and route matrix from the resulting set. Changing the
44
+ route set rewrites the package-owned router, so pass --force to overwrite it.
38
45
 
39
46
  Options:
40
47
  --visibility public|private Override repository visibility (init only).
@@ -95,7 +102,8 @@ export async function run(arguments_, repositoryPath = process.cwd()) {
95
102
  const allConflicts = [];
96
103
  const allInstalled = [];
97
104
  if (routes.length > 0) {
98
- const result = await installCatalog(repositoryPath, { force, selectedRoutes: routes, inspection });
105
+ const selectedRoutes = unionRoutes(routes, await installedRoutes(repositoryPath));
106
+ const result = await installCatalog(repositoryPath, { force, selectedRoutes, inspection });
99
107
  allConflicts.push(...result.conflicts);
100
108
  allInstalled.push(...result.installed);
101
109
  }
@@ -116,8 +124,36 @@ export async function run(arguments_, repositoryPath = process.cwd()) {
116
124
  console.log(JSON.stringify({ command, installed: allInstalled.sort(), conflicts: allConflicts }, null, 2));
117
125
  return 0;
118
126
  }
127
+ if (command === "remove") {
128
+ const parsed = parseAddOptions(options);
129
+ if (parsed.kind === "invalid")
130
+ return fail(parsed.message);
131
+ if (parsed.template !== undefined)
132
+ return fail("remove does not accept --template.");
133
+ if (parsed.routes.length === 0)
134
+ return fail("remove requires at least one route.");
135
+ const inspection = await inspectRepository(repositoryPath);
136
+ const installed = await installedRoutes(repositoryPath);
137
+ const desiredRoutes = installed.filter((route) => !parsed.routes.includes(route));
138
+ const result = await installCatalog(repositoryPath, { force: parsed.force, selectedRoutes: desiredRoutes, inspection });
139
+ if (result.conflicts.length > 0 && !parsed.force) {
140
+ console.error(`Catalog conflicts found. Re-run with --force to overwrite package-managed files:\n${result.conflicts.join("\n")}`);
141
+ return 1;
142
+ }
143
+ const removed = await removeRouteFiles(repositoryPath, parsed.routes);
144
+ console.log(JSON.stringify({ command, installed: [...result.installed].sort(), removed, conflicts: result.conflicts }, null, 2));
145
+ return 0;
146
+ }
119
147
  return fail(`Unknown command: ${command}`);
120
148
  }
149
+ function unionRoutes(requested, installed) {
150
+ const result = [...requested];
151
+ for (const route of installed) {
152
+ if (!result.includes(route))
153
+ result.push(route);
154
+ }
155
+ return result;
156
+ }
121
157
  function readVisibilityOption(options) {
122
158
  if (options.length === 0)
123
159
  return undefined;
@@ -219,6 +219,46 @@ describe("workflows CLI", () => {
219
219
  expect(error).toHaveBeenCalledWith("Unknown option: --unknown");
220
220
  error.mockRestore();
221
221
  });
222
+ it("add unions requested routes with already-installed routes", async () => {
223
+ const { installCatalog } = mockInstallers();
224
+ const repositoryPath = await createRepository({
225
+ ".github/workflows/agent-refine.md": "# Refine",
226
+ ".github/workflows/agent-implement.md": "# Implement",
227
+ });
228
+ const log = vi.spyOn(console, "log").mockImplementation(() => undefined);
229
+ await expect(run(["add", "direct"], repositoryPath)).resolves.toBe(0);
230
+ expect(installCatalog).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({ selectedRoutes: ["direct", "refine", "implement"] }));
231
+ log.mockRestore();
232
+ });
233
+ it("remove requires at least one route", async () => {
234
+ const error = vi.spyOn(console, "error").mockImplementation(() => undefined);
235
+ await expect(run(["remove"])).resolves.toBe(1);
236
+ expect(error).toHaveBeenCalledWith("remove requires at least one route.");
237
+ error.mockRestore();
238
+ });
239
+ it("remove rejects the --template flag", async () => {
240
+ const error = vi.spyOn(console, "error").mockImplementation(() => undefined);
241
+ await expect(run(["remove", "--template", "agentics-checks"])).resolves.toBe(1);
242
+ expect(error).toHaveBeenCalledWith("remove does not accept --template.");
243
+ error.mockRestore();
244
+ });
245
+ it("remove regenerates the router for the remaining routes and deletes the worker", async () => {
246
+ const { installCatalog } = mockInstallers();
247
+ const repositoryPath = await createRepository({
248
+ ".github/workflows/agent-refine.md": "# Refine",
249
+ ".github/workflows/agent-refine.lock.yml": "generated",
250
+ ".github/workflows/agent-implement.md": "# Implement",
251
+ });
252
+ const log = vi.spyOn(console, "log").mockImplementation(() => undefined);
253
+ await expect(run(["remove", "refine", "--force"], repositoryPath)).resolves.toBe(0);
254
+ expect(installCatalog).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({ force: true, selectedRoutes: ["implement"] }));
255
+ const { access } = await import("node:fs/promises");
256
+ const { constants } = await import("node:fs");
257
+ await expect(access(join(repositoryPath, ".github/workflows/agent-refine.md"), constants.F_OK)).rejects.toThrow();
258
+ await expect(access(join(repositoryPath, ".github/workflows/agent-refine.lock.yml"), constants.F_OK)).rejects.toThrow();
259
+ await expect(access(join(repositoryPath, ".github/workflows/agent-implement.md"), constants.F_OK)).resolves.toBeUndefined();
260
+ log.mockRestore();
261
+ });
222
262
  });
223
263
  async function createRepository(files) {
224
264
  const repositoryPath = await mkdtemp(join(tmpdir(), "workflows-"));
package/dist/tui.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as readline from "node:readline";
2
2
  import { formatCatalog, listCatalog } from "./catalog-listing.js";
3
- import { installCatalog, installMandatoryFiles, installTemplate, isTemplateName } from "./catalog-installation.js";
3
+ import { installCatalog, installMandatoryFiles, installTemplate, isTemplateName, removeRouteFiles } from "./catalog-installation.js";
4
4
  import { inspectRepository } from "./repository-inspection.js";
5
5
  import { routeNames } from "./workflow-catalog.js";
6
6
  const ANSI = {
@@ -218,22 +218,37 @@ export async function runInteractive(repositoryPath, options = {}) {
218
218
  }
219
219
  async function installSelected(state, repositoryPath, force) {
220
220
  const items = getItemsToInstall(state, force);
221
- const routes = items.filter((entry) => entry.kind === "route");
221
+ const newRoutes = items.filter((entry) => entry.kind === "route");
222
222
  const templates = items.filter((entry) => entry.kind === "template");
223
+ const routeEntries = state.allItems.filter((entry) => entry.kind === "route");
224
+ const checkedRoutes = routeEntries
225
+ .filter((entry) => state.selected.has(entry.name))
226
+ .map((entry) => entry.name)
227
+ .filter((name) => routeNames.includes(name));
228
+ const installedRouteNames = routeEntries
229
+ .filter((entry) => entry.installed)
230
+ .map((entry) => entry.name)
231
+ .filter((name) => routeNames.includes(name));
232
+ const removedRoutes = installedRouteNames.filter((name) => !checkedRoutes.includes(name));
223
233
  const allConflicts = [];
224
234
  const allInstalled = [];
225
- const selectedRouteNames = routes.length > 0
226
- ? routes.map((entry) => entry.name).filter((name) => routeNames.includes(name))
227
- : [...routeNames];
235
+ const allRemoved = [];
228
236
  const inspection = await inspectRepository(repositoryPath);
229
- if (routes.length > 0) {
230
- const result = await installCatalog(repositoryPath, {
231
- force,
232
- selectedRoutes: selectedRouteNames,
233
- inspection,
234
- });
237
+ if (checkedRoutes.length > 0 && (newRoutes.length > 0 || removedRoutes.length > 0 || force)) {
238
+ const result = await installCatalog(repositoryPath, { force, selectedRoutes: checkedRoutes, inspection });
235
239
  allConflicts.push(...result.conflicts);
236
240
  allInstalled.push(...result.installed);
241
+ if (result.conflicts.length === 0 || force) {
242
+ allRemoved.push(...await removeRouteFiles(repositoryPath, removedRoutes));
243
+ }
244
+ }
245
+ else if (checkedRoutes.length === 0 && removedRoutes.length > 0) {
246
+ const result = await installCatalog(repositoryPath, { force, selectedRoutes: [], inspection });
247
+ allConflicts.push(...result.conflicts);
248
+ allInstalled.push(...result.installed);
249
+ if (result.conflicts.length === 0 || force) {
250
+ allRemoved.push(...await removeRouteFiles(repositoryPath, removedRoutes));
251
+ }
237
252
  }
238
253
  else {
239
254
  const result = await installMandatoryFiles(repositoryPath, { force });
@@ -251,10 +266,18 @@ async function installSelected(state, repositoryPath, force) {
251
266
  console.error(`Conflicts found. Re-run with --force to overwrite:\n${allConflicts.join("\n")}`);
252
267
  return 1;
253
268
  }
254
- if (allInstalled.length > 0) {
255
- console.log(`Installed ${allInstalled.length} item(s):`);
256
- for (const file of allInstalled) {
257
- console.log(` ${file}`);
269
+ if (allInstalled.length > 0 || allRemoved.length > 0) {
270
+ if (allInstalled.length > 0) {
271
+ console.log(`Installed ${allInstalled.length} item(s):`);
272
+ for (const file of allInstalled) {
273
+ console.log(` ${file}`);
274
+ }
275
+ }
276
+ if (allRemoved.length > 0) {
277
+ console.log(`Removed ${allRemoved.length} item(s):`);
278
+ for (const file of allRemoved) {
279
+ console.log(` ${file}`);
280
+ }
258
281
  }
259
282
  }
260
283
  else {
@@ -11,8 +11,7 @@ set -euo pipefail
11
11
  readonly AUDIT_CRON="17 1 * * 1"
12
12
  readonly AUDIT_CLOSE_CRON="43 3 * * *"
13
13
  readonly CLEANUP_ARTIFACTS_CRON="0 6 * * *"
14
- readonly RECONCILE_BOT_PR_RUNS_CRON="*/15 * * * *"
15
- readonly STALE_RECOVERY_CRON="0 */2 * * *"
14
+ readonly RECONCILE_BOT_PR_RUNS_CRON="*/30 * * * *"
16
15
  # Daily, but it proposes far less often than daily: the worker holds one open
17
16
  # proposal at a time and skips while that slot is filled. The cron is a heartbeat,
18
17
  # the queue is the pacing.
@@ -136,8 +135,6 @@ classify_route() {
136
135
  "$AUDIT_CLOSE_CRON") route="audit-close" ;;
137
136
  "$CLEANUP_ARTIFACTS_CRON") route="cleanup-artifacts" ;;
138
137
  "$RECONCILE_BOT_PR_RUNS_CRON") route="reconcile-bot-pr-runs" ;;
139
- "$STALE_RECOVERY_CRON") route="stale-recovery" ;;
140
- "$PROPOSE_CRON") route="propose" ;;
141
138
  *) error="no route for cron '${SCHEDULE:-}'" ;;
142
139
  esac
143
140
  ;;
@@ -180,7 +177,7 @@ classify_route() {
180
177
  route="${OPERATION}"
181
178
  trigger_kind="${INPUT_TRIGGER_KIND:-manual}"
182
179
  ;;
183
- audit-close | cleanup-artifacts | reconcile-bot-pr-runs | stale-recovery | validate)
180
+ audit-close | cleanup-artifacts | reconcile-bot-pr-runs | validate)
184
181
  route="${OPERATION}"
185
182
  ;;
186
183
  *)
@@ -277,14 +277,35 @@ timeout-minutes: 90
277
277
  If a check fails, fix the cause and rerun. Do not weaken a test, lower a threshold, or skip
278
278
  a check to make it pass.
279
279
 
280
- 5. Before creating the pull request, update `changelog.json` in the project's
281
- `src/shared/data/` folder (create `src/shared/data/changelog.json` if it does not
282
- exist; in a monorepo use `apps/web/src/shared/data/changelog.json`). The file
283
- has shape `{"version":1,"changes":[...]}`. Use `jq` to prepend a new entry
284
- with `"timestamp"` (ISO 8601), `"issue"` (number), `"title"` (issue title),
285
- `"summary"` (1-2 sentences of what you changed), and `"commit"` (short SHA).
286
- Keep at most 10 entries: if there are already 10, drop the oldest. Commit
287
- this file as part of the same branch before creating the PR.
280
+ 5. Before creating the pull request, check whether an open bot pull request already
281
+ exists that closes #${{ inputs.issue-number }}. Run:
282
+
283
+ ```
284
+ gh pr list --repo "$GITHUB_REPOSITORY" --state open --search "is:pr linked:issue ${{ inputs.issue-number }}" --json number,headRefName,author --jq '[.[] | select(.author.login | test("[bot]$"))] | if length > 0 then .[0] else empty end'
285
+ ```
286
+
287
+ If a PR already exists, do **not** create a new branch or PR. Push your changes to
288
+ the existing PR's branch (`headRefName`) instead, then call
289
+ `safeoutputs/push_to_pull_request_branch` rather than `safeoutputs/create_pull_request`.
290
+ This prevents duplicate PRs when a retry is triggered after a merge-gate failure.
291
+
292
+ If no existing PR is found, proceed to create a new one as described below.
293
+
294
+ Before creating the pull request, update `changelog.json` in the project's
295
+ `src/shared/data/` folder (create `src/shared/data/changelog.json` if it does not
296
+ exist; in a monorepo use `apps/web/src/shared/data/changelog.json`). The file
297
+ has shape `{"version":1,"changes":[...]}`. Use `jq` to prepend a new entry
298
+ with `"timestamp"` (ISO 8601), `"issue"` (number), `"title"` (issue title),
299
+ `"summary"` (1-2 sentences of what you changed), and `"commit"` (short SHA).
300
+ Keep at most 10 entries: if there are already 10, drop the oldest. Commit
301
+ this file as part of the same branch before creating the PR.
302
+
303
+ The changelog is user-facing. Write the summary for a non-technical reader. Never
304
+ expose security, auth, or admin internals: no token/session/JWT details, no
305
+ permission or authorization logic, no audit trail mechanics, no internal method
306
+ names, no database or migration details. If the work touches these areas, describe
307
+ the user-visible outcome only (e.g. "Improved session reliability" or "Fixed a data
308
+ display issue"), not how it was implemented.
288
309
 
289
310
  6. You **must** call exactly one safe-output tool before finishing, or the workflow
290
311
  reports a failure. All safe-output tools are on the `safeoutputs` MCP server. Call
@@ -296,11 +317,14 @@ timeout-minutes: 90
296
317
 
297
318
  Choose exactly one:
298
319
 
299
- - **`safeoutputs/create_pull_request`** , propose a pull request against `main` with
300
- the verified changes. Its `body` must close the issue
301
- (`Closes #${{ inputs.issue-number }}`) and summarise what changed and why.
302
- This is the normal path.
303
- - **`safeoutputs/report_incomplete`** , use only when infrastructure or tooling
320
+ - **`safeoutputs/create_pull_request`** , propose a pull request against `main` with
321
+ the verified changes. Its `body` must close the issue
322
+ (`Closes #${{ inputs.issue-number }}`) and summarise what changed and why.
323
+ Use this when no open bot PR exists for the issue.
324
+ This is the normal path.
325
+ - **`safeoutputs/push_to_pull_request_branch`** , push to an existing PR's branch
326
+ when step 5 found an open bot PR for this issue. Do not create a duplicate PR.
327
+ - **`safeoutputs/report_incomplete`** , use only when infrastructure or tooling
304
328
  prevents you from completing the task (e.g. the codebase cannot build due to a
305
329
  pre-existing error you cannot fix). Provide a specific `reason`.
306
330
  - **`safeoutputs/noop`** , use only when the issue context shows the work is already
@@ -270,7 +270,7 @@ jobs:
270
270
  with:
271
271
  token: ${{ steps.app-token.outputs.token }}
272
272
  issue-number: ${{ needs.subject.outputs.issue }}
273
- labels: ${{ env.WORKING_LABEL }}
273
+ labels: ${{ env.WORKING_LABEL }},${{ env.IMPLEMENT_LABEL }}
274
274
  - name: Flag for human review
275
275
  uses: ./.github/actions/add-issue-labels
276
276
  with:
@@ -442,8 +442,8 @@ timeout-minutes: 60
442
442
  stop looping: `remove_labels` (item_number: ${{ needs.subject.outputs.issue }}) to remove
443
443
  `implement` and `bot-working`, `add_labels` (item_number:
444
444
  ${{ needs.subject.outputs.issue }}) to add `review`, and `add_comment` (item_number:
445
- ${{ needs.subject.outputs.issue }}) with the failure and what you tried. Per #167
446
- decision 2, a human decides from there.
445
+ ${{ needs.subject.outputs.issue }}) with the failure and what you tried. The `implement`
446
+ label is removed so retries do not create duplicate PRs. A human decides from there.
447
447
 
448
448
  8. Never merge with administrator privileges and never bypass a required check. If the merge
449
449
  is refused, that refusal is the answer: `add_labels` to add `review`
@@ -10,6 +10,7 @@ env:
10
10
  REFINE_MARKER: "<!-- agent-refine -->"
11
11
  INITIAL_MODE: first
12
12
  RESPONSE_MODE: rerefine
13
+ MAX_SELF_QUESTIONS: "5"
13
14
  INCOMPLETE_COMMENT: "Automated refinement ended without an outcome. The refine label remains for a retry."
14
15
  SAFE_OUTPUT_COMMENT_PREFIX: "Refinement update"
15
16
  ISSUE_CONTEXT_PATH: /tmp/gh-aw/agent/issue-context.json
@@ -24,6 +25,10 @@ description: |
24
25
  Refines an issue into a user story, on a first pass or after the author has answered the
25
26
  bot's questions. Replaces .loops/recipes/refine-loop.yaml.
26
27
 
28
+ Before writing the story, the agent explores the codebase per work unit (each bullet in a
29
+ bullet-list issue is its own unit), answering its own questions where the code can and
30
+ escalating only genuine business decisions to the author.
31
+
27
32
  Each issue refines independently. `bot-working` prevents double-processing: the reserve
28
33
  job adds it, the agent or finalization removes it, and a crashed run's leftover marker
29
34
  still parks an issue for a person.
@@ -234,9 +239,9 @@ engine:
234
239
  - "plainconcepts/glm-5-2"
235
240
 
236
241
  model: openai/glm-5-2
237
- max-turns: 300
238
- max-turn-cache-misses: 3000
239
- max-ai-credits: 5000
242
+ max-turns: 500
243
+ max-turn-cache-misses: 4000
244
+ max-ai-credits: 8000
240
245
 
241
246
  permissions: read-all
242
247
 
@@ -256,7 +261,7 @@ safe-outputs:
256
261
  add-comment:
257
262
 
258
263
 
259
- timeout-minutes: 30
264
+ timeout-minutes: 40
260
265
  ---
261
266
 
262
267
  1. You are refining the triggering issue **#${{ inputs.issue-number }}**. Do not choose
@@ -270,31 +275,66 @@ timeout-minutes: 30
270
275
  - On a `${{ env.RESPONSE_MODE }}` pass, incorporate only the supplied answers from the issue author or an
271
276
  assignee. Do not use answers from other commenters.
272
277
 
273
- 3. Call skill("ob-plan-story"), then run `/plan-story` for the issue. Ground the story in the actual
274
- codebase by reading the relevant files. Never read outside this repository root. Write it as
275
- a user story in Mike Cohn's As a / I want to / so that form, with
276
- Given/When/Then acceptance criteria, the edge cases, and a Mermaid diagram where one
277
- genuinely helps.
278
+ 3. Explore before you write. Call skill("ob-plan-explore") and hold its stance for this step:
279
+ read-only, no plans, no files, no branches. You are only building understanding here, never
280
+ producing artifacts.
281
+
282
+ Split the issue into work units first. If the issue body is a bullet list of distinct tasks
283
+ (for example "- check the button component", "- then check the login", "- then suggest a
284
+ register page"), treat each bullet as its own work unit. Otherwise treat the whole issue as a
285
+ single work unit.
286
+
287
+ Create a todo entry for each work unit before you start exploring. Process them one at a
288
+ time, strictly sequentially: explore unit 1, self-answer its questions, mark the todo
289
+ complete, then move to unit 2. Do not explore multiple work units in the same pass. Do not
290
+ start unit N+1 until unit N is marked complete.
291
+
292
+ For the current work unit only:
293
+ - Explore the relevant code and repository documentation, and raise the concrete questions you
294
+ must answer to refine it well.
295
+ - Keep exploring to answer those questions yourself from the codebase and the docs.
296
+ - Only when a question is a genuine business or product decision that the code cannot answer,
297
+ set it aside as a question for the author.
298
+ - Mark the unit's todo complete only when your findings are concrete enough to write
299
+ acceptance criteria for this unit. If you explored a file but cannot describe what changes
300
+ for this unit, you are not done — keep exploring or set aside a question.
301
+
302
+ Explore more deeply than a single pass, but never without end. Ask yourself at most
303
+ ${{ env.MAX_SELF_QUESTIONS }} questions per work unit, and stop once further exploration no
304
+ longer changes your understanding. This exploration is internal working: never write your
305
+ self-asked questions or their answers to the issue.
306
+
307
+ 4. Before writing the story, verify coverage: list every work unit and confirm each one has
308
+ exploration findings concrete enough for acceptance criteria. If any unit is missing, go back
309
+ and explore it now. Then call skill("ob-plan-story") and run `/plan-story` for the issue,
310
+ passing everything you learned while exploring as the exploration findings. Ground the story
311
+ in the actual codebase by reading the relevant files. Never read outside this repository root.
312
+ When the issue held several work units, combine them into a single user story that covers all
313
+ of them. Write at least one Given/When/Then acceptance scenario per work unit. Write it as a
314
+ user story in Mike Cohn's As a / I want to / so that form, with Given/When/Then acceptance
315
+ criteria, the edge cases, and a Mermaid diagram where one genuinely helps.
278
316
 
279
317
  Apply repository documentation and established conventions before finalizing the story.
280
318
  Adhere to ${{ env.REPO_RULES }}.
281
319
 
282
- 4. Load `@humanizer` and prepare the complete replacement issue body as valid Markdown.
320
+ 5. Load `@humanizer` and prepare the complete replacement issue body as valid Markdown.
283
321
 
284
- 5. Decide exactly one outcome:
322
+ 6. Decide exactly one outcome:
285
323
 
286
324
  Labels are workflow-owned state. Do not call `add_labels` or `remove_labels`.
287
325
 
288
- **Questions remain.** Leave the body unchanged. Call `add_comment` once with:
326
+ **Questions remain.** You set aside one or more questions for the author that the codebase
327
+ could not answer. Leave the body unchanged. Call `add_comment` once with:
289
328
  1. `${{ env.REFINE_MARKER }}`
290
329
  2. `${{ env.SAFE_OUTPUT_COMMENT_PREFIX }}`
291
330
  3. `I have some questions about this issue. Please reply in one comment and I'll process your answers.`
292
- 4. Every clarification question immediately below it, each answerable in a sentence.
331
+ 4. Every set-aside question, gathered from all work units, immediately below it, each answerable in a sentence.
293
332
 
294
333
  Write the questions in **plain business language, not technical jargon**. The person reading
295
334
  them is a domain expert, not an engineer.
296
335
 
297
- **The story is complete.** Call `update_issue` with the replacement body and `add_comment`
336
+ **The story is complete.** You answered every exploration question yourself and none remain
337
+ for the author. Call `update_issue` with the replacement body and `add_comment`
298
338
  with `${{ env.REFINE_MARKER }}`, then `${{ env.SAFE_OUTPUT_COMMENT_PREFIX }}`,
299
339
  then exactly one of these messages, based only on the `labels` array in the supplied issue
300
340
  context:
@@ -310,7 +350,8 @@ flowchart TD
310
350
  refPick{"Issue eligible?"} -->|yes| refReserve
311
351
  refPick -.->|no| refIdle
312
352
  refReserve("Reserve<br/>bot-working") --> refFacts
313
- refFacts("Facts<br/>Issue and comments to disk") --> refStory
353
+ refFacts("Facts<br/>Issue and comments to disk") --> refExplore
354
+ refExplore("Explore<br/>ob-plan-explore per work unit,<br/>self-answer, bounded") --> refStory
314
355
  refStory("Story<br/>/plan-story, grounded in the code") -->|✓| refProse
315
356
  refStory -.->|✗| refFail
316
357
  refProse("Prose<br/>@humanizer over the final text") -->|✓| refOutcome
@@ -330,7 +371,7 @@ flowchart TD
330
371
  classDef success fill:#e8f8ec,stroke:#18883c,stroke-width:2px,color:#145a32
331
372
 
332
373
  class refStart start
333
- class refReserve,refFacts,refStory,refProse action
374
+ class refReserve,refFacts,refExplore,refStory,refProse action
334
375
  class refPick,refOutcome decision
335
376
  class refIdle idle
336
377
  class refFail failure
@@ -69,8 +69,7 @@ on:
69
69
  - cron: "17 1 * * 1"
70
70
  - cron: "43 3 * * *"
71
71
  - cron: "0 6 * * *"
72
- - cron: "*/15 * * * *"
73
- - cron: "0 */2 * * *"
72
+ - cron: "*/30 * * * *"
74
73
  - cron: "29 7 * * *"
75
74
 
76
75
  workflow_dispatch:
@@ -90,7 +89,6 @@ on:
90
89
  - audit-close
91
90
  - cleanup-artifacts
92
91
  - reconcile-bot-pr-runs
93
- - stale-recovery
94
92
  - validate
95
93
  issue-number:
96
94
  description: "Issue number (required for refine / implement / direct)"
@@ -229,9 +227,41 @@ jobs:
229
227
  BOT_APP_ID: ${{ secrets.BOT_APP_ID }}
230
228
  BOT_PRIVATE_KEY: ${{ secrets.BOT_PRIVATE_KEY }}
231
229
 
232
- call-implement:
230
+ # Checks whether an open bot PR already exists for the issue. If it does, implement is
231
+ # skipped — the merge-gate will handle fixing the existing PR. This prevents duplicate
232
+ # PRs when retries are triggered after a merge-gate failure.
233
+ check-implement-pr:
233
234
  needs: [classify, authorize]
234
235
  if: needs.classify.outputs.route == 'implement' && needs.authorize.outputs.trusted == 'true'
236
+ runs-on: RunnerLandingZone
237
+ timeout-minutes: 3
238
+ permissions:
239
+ contents: read
240
+ pull-requests: read
241
+ outputs:
242
+ has-open-pr: ${{ steps.check.outputs.has-open-pr }}
243
+ steps:
244
+ - name: Check for existing open bot PR
245
+ id: check
246
+ env:
247
+ GH_TOKEN: ${{ github.token }}
248
+ REPO: ${{ github.repository }}
249
+ ISSUE_NUMBER: ${{ needs.classify.outputs.issue-number }}
250
+ run: |
251
+ set -euo pipefail
252
+ existing=$(gh pr list --repo "$REPO" --state open \
253
+ --search "is:pr linked:issue $ISSUE_NUMBER" \
254
+ --json number,author --jq '[.[] | select(.author.login | test("[bot]$"))] | length')
255
+ if [ "$existing" -gt 0 ]; then
256
+ echo "has-open-pr=true" >> "$GITHUB_OUTPUT"
257
+ echo "::notice::Issue #$ISSUE_NUMBER already has an open bot PR. Skipping implement to prevent duplicates."
258
+ else
259
+ echo "has-open-pr=false" >> "$GITHUB_OUTPUT"
260
+ fi
261
+
262
+ call-implement:
263
+ needs: [classify, authorize, check-implement-pr]
264
+ if: needs.classify.outputs.route == 'implement' && needs.authorize.outputs.trusted == 'true' && needs.check-implement-pr.outputs.has-open-pr != 'true'
235
265
  uses: ./.github/workflows/agent-implement.lock.yml
236
266
  concurrency:
237
267
  group: write-pipeline-${{ needs.classify.outputs.issue-number }}
@@ -505,29 +535,6 @@ jobs:
505
535
  token: ${{ github.token }}
506
536
  artifact-retention-days: ${{ vars.ARTIFACT_RETENTION_DAYS }}
507
537
 
508
- stale-recovery:
509
- needs: classify
510
- if: needs.classify.outputs.route == 'stale-recovery'
511
- runs-on: RunnerLandingZone
512
- timeout-minutes: 15
513
- concurrency:
514
- group: stale-recovery
515
- cancel-in-progress: false
516
- permissions:
517
- contents: read
518
- issues: write
519
- pull-requests: read
520
- actions: write
521
- steps:
522
- - name: Checkout workflow actions
523
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
524
- with:
525
- persist-credentials: false
526
- - uses: ./.github/actions/stale-recovery
527
- with:
528
- token: ${{ github.token }}
529
- stale-threshold-hours: ${{ vars.STALE_THRESHOLD_HOURS }}
530
-
531
538
  validate:
532
539
  needs: classify
533
540
  if: needs.classify.outputs.route == 'validate'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plainconceptsplatform/workflows",
3
- "version": "0.4.28",
3
+ "version": "0.4.32",
4
4
  "description": "Install and update Platform GitHub agentic workflows.",
5
5
  "keywords": [
6
6
  "github-actions",
@@ -40,4 +40,4 @@
40
40
  "typescript": "^5.8.0",
41
41
  "vitest": "^3.0.0"
42
42
  }
43
- }
43
+ }