@promptbook/cli 0.114.0-47 → 0.114.0-49

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 (153) hide show
  1. package/README.md +59 -25
  2. package/apps/agents-server/tests/e2e/mockSupabaseServer.cjs +79 -2
  3. package/apps/agents-server/tests/e2e/support/ChatHistoryNavigationSupport.ts +12 -2
  4. package/apps/agents-server/tests/e2e/support/auth.ts +6 -0
  5. package/esm/index.es.js +1327 -478
  6. package/esm/index.es.js.map +1 -1
  7. package/esm/scripts/run-codex-prompts/checks/CheckBeforeMode.d.ts +20 -0
  8. package/esm/scripts/run-codex-prompts/checks/checkRepairInstructions.d.ts +4 -0
  9. package/esm/scripts/run-codex-prompts/checks/createCheckBeforeRepairPrompt.d.ts +9 -0
  10. package/esm/scripts/run-codex-prompts/checks/limitCheckOutput.d.ts +4 -0
  11. package/esm/scripts/run-codex-prompts/checks/projectCheck.d.ts +26 -0
  12. package/esm/scripts/run-codex-prompts/checks/projectScriptReferences.d.ts +7 -0
  13. package/esm/scripts/run-codex-prompts/checks/runCheckBefore.d.ts +26 -0
  14. package/esm/scripts/run-codex-prompts/checks/runPromptCheckCommand.d.ts +16 -0
  15. package/esm/scripts/run-codex-prompts/{testing/runPromptWithTestFeedback.d.ts → checks/runPromptWithCheckFeedback.d.ts} +9 -9
  16. package/esm/scripts/run-codex-prompts/common/resolveCoderContext.d.ts +1 -1
  17. package/esm/scripts/run-codex-prompts/common/resolveCoderProjectContext.d.ts +17 -0
  18. package/esm/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +2 -0
  19. package/esm/scripts/run-codex-prompts/common/runGoScript/quoteBashArgument.d.ts +2 -0
  20. package/esm/scripts/run-codex-prompts/isolation/mapProjectReferenceToWorktree.d.ts +5 -0
  21. package/esm/scripts/run-codex-prompts/main/runPromptRound.d.ts +3 -1
  22. package/esm/scripts/run-codex-prompts/prompts/buildPromptLabel.d.ts +1 -1
  23. package/esm/scripts/run-codex-prompts/prompts/buildPromptLabelForDisplay.d.ts +1 -1
  24. package/esm/scripts/run-codex-prompts/prompts/buildPromptRunTraceContent.d.ts +3 -1
  25. package/esm/scripts/run-codex-prompts/prompts/formatCoderRunSteps.d.ts +2 -2
  26. package/esm/scripts/run-codex-prompts/prompts/listUpcomingTasks.d.ts +1 -1
  27. package/esm/scripts/run-codex-prompts/prompts/printPromptsToBeWritten.d.ts +1 -1
  28. package/esm/scripts/run-codex-prompts/server/buildCoderServerPromptResponse.d.ts +2 -0
  29. package/esm/scripts/run-codex-prompts/team/createCoderTeamPromptRunner.d.ts +1 -1
  30. package/esm/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +1 -1
  31. package/esm/src/cli/cli-commands/coder/agentCliOptions.d.ts +5 -0
  32. package/esm/src/cli/cli-commands/coder/coderAgentRole.d.ts +5 -0
  33. package/esm/src/cli/cli-commands/coder/coderReferencedArtifacts.d.ts +2 -2
  34. package/esm/src/cli/cli-commands/coder/ensureCoderPackageJsonFile.d.ts +3 -2
  35. package/esm/src/cli/cli-commands/coder/ensureCoderPackageJsonFile.test.d.ts +1 -0
  36. package/esm/src/cli/cli-commands/coder/findLegacyCoderCheckCallers.d.ts +5 -0
  37. package/esm/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +6 -0
  38. package/esm/src/cli/cli-commands/coder/mergeStringRecordJsonFile.d.ts +5 -3
  39. package/esm/src/cli/cli-commands/coder/planning/runPlanningSession.d.ts +3 -0
  40. package/esm/src/cli/cli-commands/coder/prepareCoderPackageJsonScripts.d.ts +12 -0
  41. package/esm/src/cli/cli-commands/coder.d.ts +1 -1
  42. package/esm/src/cli/cli-commands/common/coderCheckCliOptions.d.ts +21 -0
  43. package/esm/src/cli/cli-commands/common/coderCheckCliOptions.test.d.ts +1 -0
  44. package/esm/src/cli/cli-commands/common/projectCliOptions.d.ts +30 -0
  45. package/esm/src/cli/cli-commands/common/projectCliOptions.test.d.ts +1 -0
  46. package/esm/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.d.ts +1 -1
  47. package/esm/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.d.ts +1 -1
  48. package/esm/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.d.ts +1 -1
  49. package/esm/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.d.ts +1 -1
  50. package/esm/src/version.d.ts +1 -1
  51. package/package.json +1 -1
  52. package/src/_packages/cli.readme.md +15 -0
  53. package/src/cli/cli-commands/agent/chat.ts +11 -2
  54. package/src/cli/cli-commands/agent/exec.ts +11 -2
  55. package/src/cli/cli-commands/agent-folder/init.ts +6 -2
  56. package/src/cli/cli-commands/agent-folder/initializeAgentRunnerCommand.ts +9 -2
  57. package/src/cli/cli-commands/coder/add.ts +7 -1
  58. package/src/cli/cli-commands/coder/agentCliOptions.ts +11 -1
  59. package/src/cli/cli-commands/coder/coderAgentRole.ts +6 -0
  60. package/src/cli/cli-commands/coder/coderReferencedArtifacts.ts +3 -3
  61. package/src/cli/cli-commands/coder/ensureCoderPackageJsonFile.ts +22 -3
  62. package/src/cli/cli-commands/coder/find-fresh-emoji-tags.ts +3 -0
  63. package/src/cli/cli-commands/coder/find-refactor-candidates.ts +3 -0
  64. package/src/cli/cli-commands/coder/find-unwritten.ts +3 -0
  65. package/src/cli/cli-commands/coder/findLegacyCoderCheckCallers.ts +87 -0
  66. package/src/cli/cli-commands/coder/generate-boilerplates.ts +3 -0
  67. package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +6 -7
  68. package/src/cli/cli-commands/coder/init.ts +8 -2
  69. package/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.ts +16 -4
  70. package/src/cli/cli-commands/coder/list.ts +6 -1
  71. package/src/cli/cli-commands/coder/mergeStringRecordJsonFile.ts +14 -4
  72. package/src/cli/cli-commands/coder/ping.ts +7 -1
  73. package/src/cli/cli-commands/coder/plan.ts +17 -5
  74. package/src/cli/cli-commands/coder/planning/README.md +5 -3
  75. package/src/cli/cli-commands/coder/planning/fixtures/coding.cjs +22 -0
  76. package/src/cli/cli-commands/coder/planning/runPlanningSession.ts +14 -3
  77. package/src/cli/cli-commands/coder/planning/savePlanningChanges.ts +1 -3
  78. package/src/cli/cli-commands/coder/prepareCoderPackageJsonScripts.ts +304 -0
  79. package/src/cli/cli-commands/coder/printInitializationSummary.ts +5 -1
  80. package/src/cli/cli-commands/coder/promptsReadmeTemplate.ts +31 -13
  81. package/src/cli/cli-commands/coder/run.ts +31 -65
  82. package/src/cli/cli-commands/coder/server.ts +21 -39
  83. package/src/cli/cli-commands/coder/verify.ts +3 -0
  84. package/src/cli/cli-commands/coder.ts +2 -2
  85. package/src/cli/cli-commands/common/coderCheckCliOptions.ts +107 -0
  86. package/src/cli/cli-commands/common/projectCliOptions.ts +78 -0
  87. package/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.ts +4 -2
  88. package/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.ts +3 -2
  89. package/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.ts +8 -4
  90. package/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.ts +5 -2
  91. package/src/cli/cli-commands/common/validateCoderRunOptions.ts +12 -5
  92. package/src/cli/cli-commands/common/workspaceRepository.ts +7 -19
  93. package/src/cli/cli-commands/common/workspaceRepositoryCliOptions.ts +2 -0
  94. package/src/execution/translation/automatic-translate/translateMessages.ts +1 -3
  95. package/src/other/templates/getTemplatesPipelineCollection.ts +1060 -917
  96. package/src/version.ts +2 -2
  97. package/src/versions.txt +2 -1
  98. package/umd/index.umd.js +1324 -475
  99. package/umd/index.umd.js.map +1 -1
  100. package/umd/scripts/run-codex-prompts/checks/CheckBeforeMode.d.ts +20 -0
  101. package/umd/scripts/run-codex-prompts/checks/checkRepairInstructions.d.ts +4 -0
  102. package/umd/scripts/run-codex-prompts/checks/createCheckBeforeRepairPrompt.d.ts +9 -0
  103. package/umd/scripts/run-codex-prompts/checks/limitCheckOutput.d.ts +4 -0
  104. package/umd/scripts/run-codex-prompts/checks/projectCheck.d.ts +26 -0
  105. package/umd/scripts/run-codex-prompts/checks/projectScriptReferences.d.ts +7 -0
  106. package/umd/scripts/run-codex-prompts/checks/runCheckBefore.d.ts +26 -0
  107. package/umd/scripts/run-codex-prompts/checks/runPromptCheckCommand.d.ts +16 -0
  108. package/umd/scripts/run-codex-prompts/{testing/runPromptWithTestFeedback.d.ts → checks/runPromptWithCheckFeedback.d.ts} +9 -9
  109. package/umd/scripts/run-codex-prompts/common/resolveCoderContext.d.ts +1 -1
  110. package/umd/scripts/run-codex-prompts/common/resolveCoderProjectContext.d.ts +17 -0
  111. package/umd/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +2 -0
  112. package/umd/scripts/run-codex-prompts/common/runGoScript/quoteBashArgument.d.ts +2 -0
  113. package/umd/scripts/run-codex-prompts/isolation/mapProjectReferenceToWorktree.d.ts +5 -0
  114. package/umd/scripts/run-codex-prompts/main/runPromptRound.d.ts +3 -1
  115. package/umd/scripts/run-codex-prompts/prompts/buildPromptLabel.d.ts +1 -1
  116. package/umd/scripts/run-codex-prompts/prompts/buildPromptLabelForDisplay.d.ts +1 -1
  117. package/umd/scripts/run-codex-prompts/prompts/buildPromptRunTraceContent.d.ts +3 -1
  118. package/umd/scripts/run-codex-prompts/prompts/formatCoderRunSteps.d.ts +2 -2
  119. package/umd/scripts/run-codex-prompts/prompts/listUpcomingTasks.d.ts +1 -1
  120. package/umd/scripts/run-codex-prompts/prompts/printPromptsToBeWritten.d.ts +1 -1
  121. package/umd/scripts/run-codex-prompts/server/buildCoderServerPromptResponse.d.ts +2 -0
  122. package/umd/scripts/run-codex-prompts/team/createCoderTeamPromptRunner.d.ts +1 -1
  123. package/umd/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +1 -1
  124. package/umd/src/cli/cli-commands/coder/agentCliOptions.d.ts +5 -0
  125. package/umd/src/cli/cli-commands/coder/coderAgentRole.d.ts +5 -0
  126. package/umd/src/cli/cli-commands/coder/coderReferencedArtifacts.d.ts +2 -2
  127. package/umd/src/cli/cli-commands/coder/ensureCoderPackageJsonFile.d.ts +3 -2
  128. package/umd/src/cli/cli-commands/coder/ensureCoderPackageJsonFile.test.d.ts +1 -0
  129. package/umd/src/cli/cli-commands/coder/findLegacyCoderCheckCallers.d.ts +5 -0
  130. package/umd/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +6 -0
  131. package/umd/src/cli/cli-commands/coder/mergeStringRecordJsonFile.d.ts +5 -3
  132. package/umd/src/cli/cli-commands/coder/planning/runPlanningSession.d.ts +3 -0
  133. package/umd/src/cli/cli-commands/coder/prepareCoderPackageJsonScripts.d.ts +12 -0
  134. package/umd/src/cli/cli-commands/coder.d.ts +1 -1
  135. package/umd/src/cli/cli-commands/common/coderCheckCliOptions.d.ts +21 -0
  136. package/umd/src/cli/cli-commands/common/coderCheckCliOptions.test.d.ts +1 -0
  137. package/umd/src/cli/cli-commands/common/projectCliOptions.d.ts +30 -0
  138. package/umd/src/cli/cli-commands/common/projectCliOptions.test.d.ts +1 -0
  139. package/umd/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.d.ts +1 -1
  140. package/umd/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.d.ts +1 -1
  141. package/umd/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.d.ts +1 -1
  142. package/umd/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.d.ts +1 -1
  143. package/umd/src/version.d.ts +1 -1
  144. package/esm/scripts/run-codex-prompts/testing/TestBeforeMode.d.ts +0 -16
  145. package/esm/scripts/run-codex-prompts/testing/createTestBeforeRepairPrompt.d.ts +0 -9
  146. package/esm/scripts/run-codex-prompts/testing/limitTestOutput.d.ts +0 -4
  147. package/esm/scripts/run-codex-prompts/testing/runPromptTestCommand.d.ts +0 -14
  148. package/esm/scripts/run-codex-prompts/testing/runTestBefore.d.ts +0 -24
  149. package/umd/scripts/run-codex-prompts/testing/TestBeforeMode.d.ts +0 -16
  150. package/umd/scripts/run-codex-prompts/testing/createTestBeforeRepairPrompt.d.ts +0 -9
  151. package/umd/scripts/run-codex-prompts/testing/limitTestOutput.d.ts +0 -4
  152. package/umd/scripts/run-codex-prompts/testing/runPromptTestCommand.d.ts +0 -14
  153. package/umd/scripts/run-codex-prompts/testing/runTestBefore.d.ts +0 -24
package/README.md CHANGED
@@ -67,6 +67,21 @@ npm install --global @promptbook/cli
67
67
 
68
68
  CLI utilities for Promptbook that provide command-line tools for building, prettifying, and managing promptbook collections. After installation, you can use the `ptbk` command in your terminal.
69
69
 
70
+ ## Project commands
71
+
72
+ `ptbk coder run --harness openai-codex` uses the invocation's current directory, its `agents/developer.book`, and
73
+ the UTF-8 contents of its `AGENTS.md`. The explicit equivalent is
74
+ `ptbk coder run --harness openai-codex --path . --agent ./agents/developer.book --context ./AGENTS.md`.
75
+ `--path` selects an existing project directory; relative Book/context files resolve inside it, even in a nested
76
+ Git project. Explicit context replaces the default; `--context ""` disables additional context. Missing implicit
77
+ AGENTS.md warns and continues, while unreadable files or invalid explicit Book/context references fail clearly.
78
+
79
+ `ptbk init` and `ptbk coder init` share initialization and preserve custom Books, context, scripts and settings.
80
+ `coder plan` also defaults to Developer, retaining PRD-only permissions; `--agent ./agents/planner.book` selects
81
+ Planner explicitly. `coder list` has no default Book filter. See the
82
+ [command inventory and precedence reference](https://github.com/webgptorg/promptbook/blob/main/scripts/run-codex-prompts/README.md#shared-project-selection-and-command-inventory)
83
+ for execution, authoring, listing, folder-runner, and legacy-command distinctions.
84
+
70
85
  ## 🎯 Purpose and Motivation
71
86
 
72
87
  The CLI package provides essential command-line tools for Promptbook development workflows. It enables developers to build optimized promptbook libraries, prettify promptbook files, and manage collections efficiently from the command line, making it easier to integrate Promptbook into development and deployment pipelines.
@@ -528,7 +543,7 @@ Promptbook Coder is **not another standalone coding model**. It is an orchestrat
528
543
 
529
544
  - prompt files with explicit statuses like `[ ]`, `[^]`, `[x]`, and `[-]`
530
545
  - automatic selection of the next runnable task, including priority support
531
- - optional shared repo context loaded from a file such as `AGENTS.md`
546
+ - shared project context loaded from `AGENTS.md` by default
532
547
  - automatic `git add`, commit, and push after each successful prompt
533
548
  - dedicated coding-agent Git identity and optional GPG signing
534
549
  - verification and repair flow for work that is done, partial, or broken
@@ -550,7 +565,7 @@ Prompts marked with `[-]` are not ready yet, prompts containing `@@@` are treate
550
565
  #### Features
551
566
 
552
567
  - **Multi-runner execution:** `openai-codex`, `github-copilot`, `cline`, `claude-code`, `opencode`, `gemini`, `qwen-code`
553
- - **Context injection:** `--agent agents/coding/developer.book --context AGENTS.md` or inline extra instructions
568
+ - **Project defaults:** Developer, invocation cwd, and project `AGENTS.md`; `--agent`, `--path`, and `--context` independently override them
554
569
  - **Reasoning control:** `--thinking-level low|medium|high|xhigh` for supported runners
555
570
  - **Unattended or interactive runs:** default auto mode, or `--no-auto` to wait for user confirmation before each prompt
556
571
  - **Git safety:** clean working tree check by default, or `--git-changes ignore` to keep the changes and `--git-changes continue` to resume an interrupted prompt
@@ -570,11 +585,11 @@ npx ts-node ./src/cli/test/ptbk.ts coder generate-boilerplates --template prompt
570
585
 
571
586
  npx ts-node ./src/cli/test/ptbk.ts coder generate-boilerplates --template prompts/templates/agents-server.md
572
587
 
573
- npx ts-node ./src/cli/test/ptbk.ts coder run --harness github-copilot --model gpt-5.4 --thinking-level xhigh --agent agents/coding/developer.book --context AGENTS.md
588
+ npx ts-node ./src/cli/test/ptbk.ts coder run --harness github-copilot --model gpt-5.4 --thinking-level xhigh --agent agents/coding/developer.book
574
589
 
575
- npx ts-node ./src/cli/test/ptbk.ts coder run --harness github-copilot --model gpt-5.4 --thinking-level xhigh --agent agents/coding/developer.book --context AGENTS.md --auto-push
590
+ npx ts-node ./src/cli/test/ptbk.ts coder run --harness github-copilot --model gpt-5.4 --thinking-level xhigh --agent agents/coding/developer.book --auto-push
576
591
 
577
- npx ts-node ./src/cli/test/ptbk.ts coder run --harness github-copilot --model gpt-5.4 --thinking-level xhigh --agent agents/coding/developer.book --context AGENTS.md --git-changes ignore
592
+ npx ts-node ./src/cli/test/ptbk.ts coder run --harness github-copilot --model gpt-5.4 --thinking-level xhigh --agent agents/coding/developer.book --git-changes ignore
578
593
 
579
594
  npx ts-node ./src/cli/test/ptbk.ts coder find-refactor-candidates
580
595
 
@@ -596,11 +611,11 @@ ptbk coder generate-boilerplates
596
611
 
597
612
  ptbk coder generate-boilerplates --template prompts/templates/common.md
598
613
 
599
- ptbk coder run --harness github-copilot --model gpt-5.4 --thinking-level xhigh --agent agents/coding/developer.book --context AGENTS.md --test npm run test
614
+ ptbk coder run --harness github-copilot --model gpt-5.4 --thinking-level xhigh --agent agents/coding/developer.book --check "npm run check"
600
615
 
601
- ptbk coder run --harness github-copilot --model gpt-5.4 --thinking-level xhigh --agent agents/coding/developer.book --context AGENTS.md --auto-push
616
+ ptbk coder run --harness github-copilot --model gpt-5.4 --thinking-level xhigh --agent agents/coding/developer.book --auto-push
602
617
 
603
- ptbk coder run --harness github-copilot --model gpt-5.4 --thinking-level xhigh --agent agents/coding/developer.book --context AGENTS.md --test npm run test --git-changes ignore
618
+ ptbk coder run --harness github-copilot --model gpt-5.4 --thinking-level xhigh --agent agents/coding/developer.book --check "npm run check" --git-changes ignore
604
619
 
605
620
  ptbk coder find-refactor-candidates
606
621
 
@@ -617,33 +632,52 @@ ptbk coder verify
617
632
  | ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- | ------ | ---- | ----- | ------------------------------------------------------------------------ |
618
633
  | `ptbk coder init` | Creates `prompts/`, `prompts/done/`, the project-generic template files materialized in `prompts/templates/` (currently `common.md`), and a starter `AGENTS.md`; ensures `.env` contains `CODING_AGENT_GIT_NAME`, `CODING_AGENT_GIT_EMAIL`, and `CODING_AGENT_GIT_SIGNING_KEY`; adds helper coder scripts to `package.json`; ensures `.gitignore` contains `/.promptbook`; and configures `.vscode/settings.json` to save pasted prompt images into `prompts/screenshots/`. |
619
634
  | `ptbk coder generate-boilerplates` | Creates new prompt markdown files with fresh emoji tags so you can quickly fill in coding tasks; `--template` accepts either a built-in alias or a markdown file path relative to the project root. |
620
- | `ptbk coder run` | Picks the next ready prompt, can run tests before coding to stop or repair pre-existing failures, appends optional context, runs it through the selected coding agent, can optionally verify each attempt with a shell test command and feed failing output back for retries, then marks success or failure, commits the result, and pushes only when `--auto-push` is enabled. |
635
+ | `ptbk coder run` | Picks the next ready prompt, can run project checks before coding to stop or repair pre-existing failures, appends optional context, runs it through the selected coding agent, can optionally check each attempt with the project command and feed failing output back for retries, then marks success or failure, commits the result, and pushes only when `--auto-push` is enabled. |
621
636
  | `ptbk coder find-refactor-candidates` | Scans the repository for oversized or overpacked files and writes prompt files for likely refactors; `--level <xlow | low | medium | high | xhigh | extreme>` ranges from a very benevolent scan to a very aggressive sweep. |
622
637
  | `ptbk coder verify` | Walks through completed prompts, archives truly finished work, and adds follow-up repair prompts for unfinished results. |
623
638
 
624
639
  #### Most useful `ptbk coder run` flags
625
640
 
626
- | Flag | Purpose |
627
- | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
628
- | `--harness <name>` | Selects the coding harness. |
629
- | `--model <model>` | Chooses the runner model; required for `openai-codex`, `gemini` and `qwen-code`, optional for `github-copilot`. |
630
- | `--context <text-or-file>` | Appends extra instructions inline or from a file like `AGENTS.md`. |
631
- | `--test <command>` | Runs a verification command after each prompt attempt and feeds failing output back for retries. |
632
- | `--test-before <mode>` | Runs tests before coding: `no` (default), `yes-and-fail` (stop with results), or `yes-and-fix` (create one repair prompt first); defaults to `npm test` when enabled without `--test`. |
633
- | `--thinking-level <level>` | Sets reasoning effort for supported runners. |
634
- | `--no-auto` | Waits for user confirmation before each prompt instead of running automatically through the queue. |
635
- | `--git-changes <mode>` | Decides what happens with a dirty working tree: `fail` (default), `ignore` to keep the changes, or `continue` to resume the single interrupted `[^]` prompt with them. |
636
- | `--priority <n>` | Runs only prompts at or above the given priority. |
637
- | `--dry-run` | Prints which prompts are ready instead of executing them. |
638
- | `--allow-credits` | Lets OpenAI Codex spend credits when required. |
639
- | `--auto-push` | Pushes each successful coding-agent commit to the configured remote. |
640
- | `--auto-migrate` | Runs testing-server database migrations after each successful prompt. |
641
+ A **check** is the project's aggregate validation: tests, linting, typechecking, builds, generated-code consistency,
642
+ and other quality checks. `ptbk init` and `ptbk coder init` preserve an existing `scripts.check`, or compose available
643
+ validation scripts and report their scope. Configure the failing setup placeholder if the project has none.
644
+
645
+ ```bash
646
+ ptbk coder run --harness openai-codex --check "npm run check" --check-before yes-and-fix
647
+ ptbk coder run --harness openai-codex --check "npm run lint && npm run build && npm test"
648
+ ```
649
+
650
+ The default preflight mode remains `no`. Enabled preflight uses `npm run check` when no command is supplied;
651
+ post-prompt verification remains opt-in. Initial checks and repairs use the same command and actual process result.
652
+ Replace retired `--test` and `--test-before` with `--check` and `--check-before`. Init migrates recognized generated
653
+ scripts while preserving custom validation. For conflicts or custom callers, it reports the exact entries/files to
654
+ review: preserve the required validation in `check`, update references, then remove the unused legacy entry.
655
+ Automation that invokes `npm run test-for-ptbk-coder` must switch to `npm run check`. Restart an already-running
656
+ Coder invocation with the new flags to release its captured legacy command; initialization creates no compatibility alias.
657
+
658
+ | Flag | Purpose |
659
+ | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
660
+ | `--harness <name>` | Selects the coding harness. |
661
+ | `--agent <book>` | Selects the primary Book; defaults to the selected project's `agents/developer.book`. |
662
+ | `--path <directory>` | Selects the project; defaults to invocation cwd. Relative paths start there, not at the CLI installation or enclosing Git root. |
663
+ | `--model <model>` | Chooses the runner model; required for `openai-codex`, `gemini` and `qwen-code`, optional for `github-copilot`. |
664
+ | `--context <text-or-file>` | Replaces the default project `AGENTS.md` with inline instructions or a project-relative file; an empty value disables context. |
665
+ | `--check <command>` | Runs a verification command after each prompt attempt and feeds failing output back for retries. |
666
+ | `--check-before <mode>` | Runs project checks before coding: `no` (default), `yes-and-fail` (stop with results), or `yes-and-fix` (create one repair prompt first); defaults to `npm run check` when enabled without `--check`. |
667
+ | `--thinking-level <level>` | Sets reasoning effort for supported runners. |
668
+ | `--no-auto` | Waits for user confirmation before each prompt instead of running automatically through the queue. |
669
+ | `--git-changes <mode>` | Decides what happens with a dirty working tree: `fail` (default), `ignore` to keep the changes, or `continue` to resume the single interrupted `[^]` prompt with them. |
670
+ | `--priority <n>` | Runs only prompts at or above the given priority. |
671
+ | `--dry-run` | Prints which prompts are ready instead of executing them. |
672
+ | `--allow-credits` | Lets OpenAI Codex spend credits when required. |
673
+ | `--auto-push` | Pushes each successful coding-agent commit to the configured remote. |
674
+ | `--auto-migrate` | Runs testing-server database migrations after each successful prompt. |
641
675
 
642
676
  #### Typical usage pattern
643
677
 
644
678
  1. Initialize once with `ptbk coder init`.
645
679
  2. Customize `prompts/templates/*.md` if needed, then create or write prompt files in `prompts/`.
646
- 3. Customize the starter `AGENTS.md` with repository-specific instructions, then pass `--agent agents/coding/developer.book --context AGENTS.md`.
680
+ 3. Customize `agents/developer.book` and `AGENTS.md`; the runner selects both automatically. Use `--path` for another project or `--agent` and `--context` for explicit overrides.
647
681
  4. Run unattended batches by default, or pass `--no-auto` to confirm each prompt interactively.
648
682
  5. Finish with `ptbk coder verify` so resolved prompts are archived and broken ones get explicit repair follow-ups.
649
683
 
@@ -21,6 +21,36 @@ const REST_PREFIX = '/rest/v1/';
21
21
  */
22
22
  const OBJECT_ACCEPT_HEADER = 'application/vnd.pgrst.object+json';
23
23
 
24
+ /**
25
+ * Matches PostgREST LIKE patterns, including escaped literals and the `*` alias for `%`.
26
+ *
27
+ * @param {unknown} value
28
+ * @param {string} pattern
29
+ * @param {boolean} ignoreCase
30
+ * @returns {boolean}
31
+ */
32
+ function matchesLikePattern(value, pattern, ignoreCase) {
33
+ if (value === null || value === undefined) {
34
+ return false;
35
+ }
36
+
37
+ let expression = '';
38
+ for (let index = 0; index < pattern.length; index++) {
39
+ const character = pattern[index];
40
+ if (character === '\\' && index + 1 < pattern.length) {
41
+ expression += pattern[++index].replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
42
+ } else if (character === '%' || character === '*') {
43
+ expression += '.*';
44
+ } else if (character === '_') {
45
+ expression += '.';
46
+ } else {
47
+ expression += character.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
48
+ }
49
+ }
50
+
51
+ return new RegExp(`^${expression}$`, ignoreCase ? 'is' : 's').test(String(value));
52
+ }
53
+
24
54
  /**
25
55
  * In-memory table store used by the mocked Supabase API.
26
56
  */
@@ -92,6 +122,20 @@ function getTableRows(tableName) {
92
122
  return tables.get(tableName);
93
123
  }
94
124
 
125
+ /**
126
+ * Decodes explicitly escaped filter values while preserving literal percent wildcards from URLSearchParams.
127
+ *
128
+ * @param {string} rawValue
129
+ * @returns {string}
130
+ */
131
+ function decodeFilterValue(rawValue) {
132
+ try {
133
+ return decodeURIComponent(rawValue);
134
+ } catch {
135
+ return rawValue;
136
+ }
137
+ }
138
+
95
139
  /**
96
140
  * Parses a PostgREST token into a primitive JavaScript value.
97
141
  *
@@ -99,7 +143,7 @@ function getTableRows(tableName) {
99
143
  * @returns {string | number | boolean | null}
100
144
  */
101
145
  function parseTokenValue(rawValue) {
102
- const decoded = decodeURIComponent(rawValue);
146
+ const decoded = decodeFilterValue(rawValue);
103
147
 
104
148
  if (decoded === 'null') {
105
149
  return null;
@@ -236,6 +280,15 @@ function matchesRowFilters(row, searchParams) {
236
280
  continue;
237
281
  }
238
282
 
283
+ if (rawClause.startsWith('like.') || rawClause.startsWith('ilike.')) {
284
+ const ignoreCase = rawClause.startsWith('ilike.');
285
+ const pattern = decodeFilterValue(rawClause.slice(ignoreCase ? 'ilike.'.length : 'like.'.length));
286
+ if (!matchesLikePattern(row[columnName], pattern, ignoreCase)) {
287
+ return false;
288
+ }
289
+ continue;
290
+ }
291
+
239
292
  if (rawClause.startsWith('is.')) {
240
293
  const expectedValue = parseTokenValue(rawClause.slice('is.'.length));
241
294
  if (expectedValue === null) {
@@ -378,6 +431,26 @@ async function handleRestRequest(request, response, requestUrl) {
378
431
  if (method === 'POST') {
379
432
  const body = await parseJsonBody(request);
380
433
  const payloadRows = Array.isArray(body) ? body : body ? [body] : [];
434
+ if (tableName === 'User' || tableName.endsWith('_User')) {
435
+ // Match the database constraint so concurrent identity creation can retry the existing user.
436
+ // Validate the whole batch before inserting any rows, as PostgreSQL does for one statement.
437
+ const usernames = new Set(tableRows.map((row) => row.username));
438
+ for (const payloadRow of payloadRows) {
439
+ if (payloadRow.username === undefined || payloadRow.username === null) {
440
+ continue;
441
+ }
442
+ if (usernames.has(payloadRow.username)) {
443
+ sendJson(response, 409, {
444
+ code: '23505',
445
+ details: `Key (username)=(${payloadRow.username}) already exists.`,
446
+ hint: null,
447
+ message: `duplicate key value violates unique constraint "${tableName}_username_idx"`,
448
+ });
449
+ return;
450
+ }
451
+ usernames.add(payloadRow.username);
452
+ }
453
+ }
381
454
  const insertedRows = payloadRows.map((payloadRow) => {
382
455
  const nextRow = { ...payloadRow };
383
456
 
@@ -506,4 +579,8 @@ function main() {
506
579
  process.on('SIGTERM', shutdown);
507
580
  }
508
581
 
509
- main();
582
+ module.exports = { createMockSupabaseServer };
583
+
584
+ if (require.main === module) {
585
+ main();
586
+ }
@@ -46,6 +46,10 @@ type DelayNextMatchingRequestOptions = {
46
46
  * @private internal utility of ChatHistoryNavigationSupport
47
47
  */
48
48
  readonly isMatchingUrl: (url: string) => boolean;
49
+ /**
50
+ * Buffers the response before pausing, so navigation can cancel the browser request without blocking release.
51
+ */
52
+ readonly delayResponse?: boolean;
49
53
  };
50
54
 
51
55
  /**
@@ -236,6 +240,7 @@ async function delayNextMatchingRequest(
236
240
  }
237
241
 
238
242
  hasInterceptedTargetRequest = true;
243
+ const bufferedResponse = options.delayResponse ? await route.fetch() : undefined;
239
244
  markStarted?.();
240
245
 
241
246
  await new Promise<void>((resolve) => {
@@ -246,8 +251,12 @@ async function delayNextMatchingRequest(
246
251
  });
247
252
 
248
253
  try {
249
- await route.continue();
250
- await request.response().catch(() => null);
254
+ if (bufferedResponse) {
255
+ await route.fulfill({ response: bufferedResponse });
256
+ } else {
257
+ await route.continue();
258
+ await request.response().catch(() => null);
259
+ }
251
260
  } finally {
252
261
  markFinished?.();
253
262
  }
@@ -294,6 +303,7 @@ async function delayNextUserChatSnapshotRequest(page: Page, agentName: string, c
294
303
  return delayNextMatchingRequest(page, {
295
304
  method: 'GET',
296
305
  isMatchingUrl: (url) => isMatchingUserChatSnapshotRequest(url, agentName, chatId),
306
+ delayResponse: true,
297
307
  });
298
308
  }
299
309
 
@@ -62,6 +62,12 @@ export async function loginAsAdmin(page: Page): Promise<void> {
62
62
  await page.getByLabel('Password').press('Enter');
63
63
  await expect(page.getByLabel('Username')).toBeHidden();
64
64
 
65
+ // Authentication is setup for these tests. Wait for the session and load it without racing the client refresh.
66
+ await expect
67
+ .poll(async () => (await page.context().cookies()).some((cookie) => cookie.name === 'sessionToken'))
68
+ .toBe(true);
69
+ await page.reload();
70
+
65
71
  const desktopAdminButton = page.getByRole('button', { name: /admin/i });
66
72
  if (await desktopAdminButton.isVisible().catch(() => false)) {
67
73
  return;