@promptbook/cli 0.114.0-48 → 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 +1074 -1210
  96. package/src/version.ts +2 -2
  97. package/src/versions.txt +1 -0
  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
@@ -5,6 +5,7 @@ import { spaceTrim } from 'spacetrim';
5
5
  import type { $side_effect } from '../../../utils/organization/$side_effect';
6
6
  import { $preflightWorkspaceRepository } from '../common/workspaceRepository';
7
7
  import { addWorkspaceRepositoryOptions } from '../common/workspaceRepositoryCliOptions';
8
+ import { normalizeProjectCliOptions } from '../common/projectCliOptions';
8
9
  import { handleActionErrors } from '../common/handleActionErrors';
9
10
  import { $ensureHarnessInstallations } from '../common/harness/$ensureHarnessInstallations';
10
11
  import {
@@ -68,6 +69,7 @@ export function $initializeCoderPingCommand(program: Program): $side_effect {
68
69
 
69
70
  command.action(
70
71
  handleActionErrors(async (cliOptions) => {
72
+ const projectOptions = normalizeProjectCliOptions(cliOptions);
71
73
  const { period: periodValue } = cliOptions as {
72
74
  readonly period?: string;
73
75
  } & PromptRunnerSelectionCliOptions;
@@ -81,7 +83,11 @@ export function $initializeCoderPingCommand(program: Program): $side_effect {
81
83
  // Note: The period is validated before the harness installation check, so a mistyped duration fails fast
82
84
  const periodMs = parseOptionalPeriodDuration('--period', periodValue);
83
85
 
84
- const workspace = await $preflightWorkspaceRepository({ policy: 'mutate', ...questionsOptions });
86
+ const workspace = await $preflightWorkspaceRepository({
87
+ ...projectOptions,
88
+ policy: 'mutate',
89
+ ...questionsOptions,
90
+ });
85
91
 
86
92
  await $ensureHarnessInstallations([runnerOptions.agentName], questionsOptions);
87
93
  await $ensureCoderHarnessGitignoreRules(workspace.projectPath, runnerOptions.agentName, questionsOptions);
@@ -7,13 +7,14 @@ import { spaceTrim } from '../../../utils/organization/spaceTrim';
7
7
  import { addCoderGitSyncOptions, normalizeCoderGitSyncCliOptions } from '../common/coderGitSyncCliOptions';
8
8
  import { $preflightWorkspaceRepository } from '../common/workspaceRepository';
9
9
  import { addWorkspaceRepositoryOptions } from '../common/workspaceRepositoryCliOptions';
10
+ import { normalizeProjectCliOptions } from '../common/projectCliOptions';
10
11
  import { handleActionErrors } from '../common/handleActionErrors';
11
12
  import {
12
13
  addPromptRunnerRuntimeOptions,
13
14
  addPromptRunnerSelectionOptions,
14
15
  normalizePromptRunnerSelectionCliOptions,
15
16
  } from '../common/promptRunnerCliOptions';
16
- import { addCoderAgentOption } from './agentCliOptions';
17
+ import { addCoderExecutionOptions } from './agentCliOptions';
17
18
 
18
19
  /**
19
20
  * Registers the repository-aware, planning-only conversation under the existing coder command group.
@@ -22,10 +23,10 @@ import { addCoderAgentOption } from './agentCliOptions';
22
23
  export function $initializeCoderPlanCommand(program: Program): $side_effect {
23
24
  const command = program.command('plan').description(
24
25
  spaceTrim(`
25
- Discuss features with the project's Planner and review PRDs before saving them.
26
+ Discuss features with the project's Developer Book and review PRDs before saving them.
26
27
 
27
- Run ptbk coder init first. Default Book: agents/planner.book; --agent overrides the Book,
28
- independently of --harness and --model. Currently supports openai-codex with restricted tools.
28
+ Run ptbk coder init first. Default Book: agents/developer.book; --agent overrides the Book,
29
+ independently of --harness and --model. Use --agent ./agents/planner.book for Planner. Currently supports openai-codex with restricted tools.
29
30
  Requires an interactive terminal and a Codex version supporting --ignore-user-config and --ignore-rules.
30
31
  Codex configuration, plugins, hooks and native tools are isolated; --model default uses Codex's built-in default.
31
32
  /save applies reviewed proposals, /draft saves [-] drafts, /discard drops proposals, /exit ends.
@@ -35,7 +36,7 @@ export function $initializeCoderPlanCommand(program: Program): $side_effect {
35
36
  );
36
37
  addPromptRunnerSelectionOptions(command);
37
38
  addPromptRunnerRuntimeOptions(command);
38
- addCoderAgentOption(command, 'planner');
39
+ addCoderExecutionOptions(command);
39
40
  addCoderGitSyncOptions(command);
40
41
  command.option(
41
42
  '--template <path>',
@@ -45,6 +46,7 @@ export function $initializeCoderPlanCommand(program: Program): $side_effect {
45
46
 
46
47
  command.action(
47
48
  handleActionErrors(async (cliOptions) => {
49
+ const projectOptions = normalizeProjectCliOptions(cliOptions);
48
50
  const { createPlanningTerminal } = await import('./planning/createPlanningTerminal');
49
51
  const { runPlanningSession } = await import('./planning/runPlanningSession');
50
52
  const { resolvePlanningPath } = await import('./planning/resolvePlanningPath');
@@ -57,6 +59,7 @@ export function $initializeCoderPlanCommand(program: Program): $side_effect {
57
59
  assertPlanningHarnessSupported(options.agentName);
58
60
  const gitSync = normalizeCoderGitSyncCliOptions(cliOptions);
59
61
  const workspace = await $preflightWorkspaceRepository({
62
+ ...projectOptions,
60
63
  policy: 'mutate',
61
64
  isAskingQuestionsEnabled: cliOptions.questions,
62
65
  });
@@ -67,6 +70,13 @@ export function $initializeCoderPlanCommand(program: Program): $side_effect {
67
70
  ),
68
71
  );
69
72
  }
73
+ const { resolveCoderProjectContext } = await import(
74
+ '../../../../scripts/run-codex-prompts/common/resolveCoderProjectContext'
75
+ );
76
+ const projectContext = await resolveCoderProjectContext({
77
+ ...cliOptions,
78
+ projectPath: workspace.projectPath,
79
+ });
70
80
  const terminal = createPlanningTerminal();
71
81
  try {
72
82
  const { projectPath } = workspace;
@@ -80,6 +90,8 @@ export function $initializeCoderPlanCommand(program: Program): $side_effect {
80
90
  ...options,
81
91
  projectPath,
82
92
  agent: cliOptions.agent,
93
+ context: cliOptions.context,
94
+ projectContext,
83
95
  template: cliOptions.template,
84
96
  preexistingChangedPaths: gitSync.isCommitEnabled
85
97
  ? new Set(
@@ -1,10 +1,12 @@
1
1
  # Coder planning
2
2
 
3
3
  Run `ptbk coder init`, then `ptbk coder plan --harness openai-codex` in an interactive terminal.
4
- The editable `agents/planner.book` uses the same implicit Adam inheritance as Developer. An explicit `--agent`
5
- overrides the Book through the shared resolver; planning resolves Books without initializing missing ancestors.
4
+ The default primary Book is `agents/developer.book`; use `--agent ./agents/planner.book` to select Planner.
5
+ Both use the same implicit Adam inheritance. `--path` defaults to invocation cwd, and additional context defaults
6
+ to that project's AGENTS.md. An explicit `--context` replaces it with inline text or a project-relative file;
7
+ `--context ""` disables it. Planning resolves Books without initializing missing ancestors.
6
8
 
7
- The discussion retains messages, read results and saved paths across topics. Planner proposes changes as data.
9
+ The discussion retains messages, read results and saved paths across topics. The selected Book proposes changes as data.
8
10
  The CLI shows exact paths and changed text, then accepts `/save`, `/draft`, `/discard`, or another discussion turn.
9
11
  EOF and `/exit` discard unsaved proposals. Ctrl+C aborts inference. Saved files remain intact after failures.
10
12
 
@@ -0,0 +1,22 @@
1
+ // Offline coding harness. Capture exactly what the installed CLI supplied, including the shell's -C argument.
2
+ const FILESYSTEM = require('fs');
3
+ const PATH = require('path');
4
+ const ARGUMENTS = process.argv.slice(2);
5
+ if (ARGUMENTS[0] === 'login') {
6
+ process.stdout.write('Logged in using ChatGPT\n');
7
+ process.exit(0);
8
+ }
9
+ if (!ARGUMENTS.includes('exec')) process.exit(2);
10
+ let prompt = '';
11
+ process.stdin.on('data', (chunk) => { prompt += chunk; });
12
+ process.stdin.on('end', () => {
13
+ const projectPath = ARGUMENTS[ARGUMENTS.indexOf('-C') + 1];
14
+ if (PATH.resolve(projectPath) !== process.cwd()) {
15
+ process.stderr.write(`Wrong project argument: ${projectPath}; cwd: ${process.cwd()}\n`);
16
+ process.exitCode = 2;
17
+ return;
18
+ }
19
+ FILESYSTEM.mkdirSync('.promptbook', { recursive: true });
20
+ FILESYSTEM.writeFileSync('.promptbook/mock-call.json', JSON.stringify({ projectPath, cwd: process.cwd(), prompt }));
21
+ process.stdout.write('Offline fixture completed.\ntokens used\n0\n');
22
+ });
@@ -2,6 +2,11 @@ import { existsSync, readFileSync } from 'fs';
2
2
  import { realpath } from 'fs/promises';
3
3
  import { join } from 'path';
4
4
  import { resolveCoderAgent } from '../../../../../scripts/run-codex-prompts/common/resolveCoderAgent';
5
+ import {
6
+ resolveCoderProjectContext,
7
+ type ResolvedCoderProjectContext,
8
+ } from '../../../../../scripts/run-codex-prompts/common/resolveCoderProjectContext';
9
+ import { DEFAULT_CODER_AGENT_ROLE } from '../coderAgentRole';
5
10
  import { CoderTeamRuntime } from '../../../../../scripts/run-codex-prompts/team/CoderTeamRuntime';
6
11
  import { appendCoderTeamEvent } from '../../../../../scripts/run-codex-prompts/team/createCoderTeamPromptRunner';
7
12
  import type { Usage } from '../../../../execution/Usage';
@@ -38,6 +43,8 @@ export async function runPlanningSession(
38
43
  options: NormalizedPromptRunnerSelectionCliOptions & {
39
44
  readonly projectPath: string;
40
45
  readonly agent?: string;
46
+ readonly context?: string;
47
+ readonly projectContext?: ResolvedCoderProjectContext;
41
48
  readonly template?: string;
42
49
  readonly preexistingChangedPaths?: ReadonlySet<string>;
43
50
  },
@@ -46,15 +53,16 @@ export async function runPlanningSession(
46
53
  ): Promise<ReadonlyMap<string, string>> {
47
54
  const projectPath = await realpath(options.projectPath);
48
55
  assertPlanningHarnessSupported(options.agentName);
56
+ const projectContext = options.projectContext ?? (await resolveCoderProjectContext({ ...options, projectPath }));
49
57
  const agent = await resolveCoderAgent(options.agent, projectPath, {
50
- defaultRole: 'planner',
58
+ defaultRole: DEFAULT_CODER_AGENT_ROLE,
51
59
  isInitializationAllowed: false,
52
60
  signal: io.signal,
53
61
  });
54
62
  if (!existsSync(join(projectPath, 'prompts'))) {
55
63
  throw new NotFoundError(spaceTrim('Planning requires `prompts/`. Run `ptbk coder init` first.'));
56
64
  }
57
- if (!agent) throw new NotFoundError(spaceTrim('Planner Book is missing. Run `ptbk coder init`.'));
65
+ if (!agent) throw new NotFoundError(spaceTrim('Primary Book is missing. Run `ptbk coder init`.'));
58
66
  resolvePlanningPath(projectPath, 'prompts');
59
67
  const templateOption =
60
68
  options.template ??
@@ -111,7 +119,10 @@ export async function runPlanningSession(
111
119
  },
112
120
  { role: 'context', content: await readPlanningContext(projectPath, { kind: 'list', path: '.' }) },
113
121
  ];
114
- for (const path of ['README.md', 'AGENTS.md']) {
122
+ if (projectContext.context !== undefined) {
123
+ history.push({ role: 'context', content: projectContext.context });
124
+ }
125
+ for (const path of ['README.md']) {
115
126
  if (existsSync(join(projectPath, path))) {
116
127
  history.push({
117
128
  role: 'context',
@@ -63,9 +63,7 @@ export function savePlanningChanges(
63
63
  const current = existsSync(change.path) ? readFileSync(change.path, 'utf-8') : null;
64
64
  if (current !== change.before) {
65
65
  throw new NotAllowed(
66
- spaceTrim(
67
- `\`${change.planningPath}\` changed while saving. Review a fresh preview.`,
68
- ),
66
+ spaceTrim(`\`${change.planningPath}\` changed while saving. Review a fresh preview.`),
69
67
  );
70
68
  }
71
69
  if (change.before === null) {
@@ -0,0 +1,304 @@
1
+ import {
2
+ assertProjectCheckScriptsAreConfigured,
3
+ CHECK_SETUP_PLACEHOLDER_COMMAND,
4
+ CoderCheckSetupError,
5
+ isCheckSetupRequired,
6
+ } from '../../../../scripts/run-codex-prompts/checks/projectCheck';
7
+ import { getDefaultCoderPackageJsonScripts } from './getDefaultCoderPackageJsonScripts';
8
+ import { projectScriptReferences } from '../../../../scripts/run-codex-prompts/checks/projectScriptReferences';
9
+
10
+ /** Old initialized aggregate entries, used only at this migration boundary. */
11
+ const LEGACY_CHECK_SCRIPT_NAMES = ['test-for-ptbk-coder', 'check-for-ptbk-coder'] as const;
12
+
13
+ /** Conventional project validation scripts, ordered from lightweight checks to tests. */
14
+ const VALIDATION_SCRIPT_GROUPS = [
15
+ ['lint', 'test-lint'],
16
+ ['typecheck', 'type-check', 'type-checking', 'check-types', 'test-types'],
17
+ ['build', 'test-build'],
18
+ ] as const;
19
+
20
+ /** Conventional leaf test families used when the project has no usable test aggregate. */
21
+ const TEST_SCRIPT_GROUPS = [
22
+ ['test-unit', 'test:unit'],
23
+ ['test-integration', 'test:integration'],
24
+ ['test-e2e', 'test:e2e'],
25
+ ] as const;
26
+
27
+ /** Script names that must never be reached by a generated aggregate. */
28
+ const NON_VALIDATION_SCRIPT_PATTERN =
29
+ /^(?:check$|coder:|(?:dev|start|serve|watch|deploy|publish|install|preinstall|postinstall|prepare|reset|clean)(?:$|[:-]))/iu;
30
+
31
+ /** Clearly unsuitable shell bodies are excluded even under a conventional validation name. */
32
+ const UNSUITABLE_VALIDATION_BODY_PATTERN =
33
+ /(?:\b(?:ptbk|promptbook)\s+coder\s+(?:run|fix)|\bcoder:(?:run|fix)\b|--watch(?:All)?(?:\b|=)|\b(?:watch|nodemon|concurrently|serve|deploy|publish|install|reset|rm|rmdir|del|remove-item)\b|--if-present|\|\||(?:^|[^&])&(?:$|[^&])|;|\bexit\s+0\b)/iu;
34
+
35
+ /** Npm lifecycle hooks that run implicitly before and after a selected project script. */
36
+ const SCRIPT_LIFECYCLE_PREFIXES = ['pre', 'post'] as const;
37
+
38
+ /** Result of preparing project-owned checks and migrating recognized generated callers. @private internal initializer result */
39
+ export type PreparedCoderPackageJsonScripts = {
40
+ readonly scripts: Readonly<Record<string, string>>;
41
+ readonly checkScriptSummary: string;
42
+ readonly migrationInstructions: ReadonlyArray<string>;
43
+ readonly isCheckConfigured: boolean;
44
+ };
45
+
46
+ /**
47
+ * Preserves project scripts, creates one canonical check, and migrates only exact generated caller forms.
48
+ * @private shared package-script preparation for Coder initialization
49
+ */
50
+ export function prepareCoderPackageJsonScripts(
51
+ existing: Readonly<Record<string, string>>,
52
+ externalCallers: Readonly<Record<string, ReadonlyArray<string>>> = {},
53
+ ): PreparedCoderPackageJsonScripts {
54
+ const scripts = { ...existing };
55
+ const migrationInstructions: string[] = [];
56
+ const legacyNames = LEGACY_CHECK_SCRIPT_NAMES.filter((name) =>
57
+ Object.prototype.hasOwnProperty.call(existing, name),
58
+ );
59
+ let checkScriptSummary: string;
60
+
61
+ if (Object.prototype.hasOwnProperty.call(existing, 'check')) {
62
+ checkScriptSummary = 'Preserved project scripts.check exactly; Coder executes npm run check.';
63
+ } else if (legacyNames.length > 0) {
64
+ const sourceName = legacyNames[0]!;
65
+ const isRecursive =
66
+ scriptReaches(sourceName, 'check', existing, new Set()) ||
67
+ scriptReaches(sourceName, sourceName, existing, new Set()) ||
68
+ scriptReaches(sourceName, 'coder:run', existing, new Set()) ||
69
+ scriptReaches(sourceName, 'coder:fix', existing, new Set());
70
+ const conflictingLifecycleNames = SCRIPT_LIFECYCLE_PREFIXES.filter(
71
+ (prefix) =>
72
+ existing[`${prefix}check`] !== undefined &&
73
+ existing[`${prefix}${sourceName}`] !== existing[`${prefix}check`],
74
+ ).map((prefix) => `${prefix}check`);
75
+ scripts.check =
76
+ isRecursive || conflictingLifecycleNames.length > 0
77
+ ? CHECK_SETUP_PLACEHOLDER_COMMAND
78
+ : existing[sourceName]!;
79
+ if (!isRecursive && conflictingLifecycleNames.length === 0) {
80
+ // npm runs these hooks implicitly. Preserve their bodies as well as the main script's scope.
81
+ for (const prefix of SCRIPT_LIFECYCLE_PREFIXES) {
82
+ const legacyHook = existing[`${prefix}${sourceName}`];
83
+ if (legacyHook !== undefined) scripts[`${prefix}check`] = legacyHook;
84
+ }
85
+ }
86
+ checkScriptSummary = isRecursive
87
+ ? `Kept recursive scripts.${sourceName} unchanged; configure scripts.check with validation that does not call check or Coder recursively.`
88
+ : conflictingLifecycleNames.length > 0
89
+ ? `Kept scripts.${sourceName} and conflicting ${conflictingLifecycleNames.join(
90
+ ', ',
91
+ )} hooks unchanged; configure scripts.check and its lifecycle hooks to preserve the required validation.`
92
+ : `Preserved scripts.${sourceName}'s validation command and npm lifecycle hooks in scripts.check: ${scripts.check}`;
93
+ } else {
94
+ const selectedScripts = selectValidationScripts(existing);
95
+ scripts.check =
96
+ selectedScripts.length > 0
97
+ ? selectedScripts.map((name) => (name === 'test' ? 'npm test' : `npm run ${name}`)).join(' && ')
98
+ : CHECK_SETUP_PLACEHOLDER_COMMAND;
99
+ checkScriptSummary =
100
+ selectedScripts.length > 0
101
+ ? `Generated scripts.check from the available validation scripts (${selectedScripts.join(', ')}): ${
102
+ scripts.check
103
+ }`
104
+ : 'No usable validation scripts found. scripts.check contains a failing setup placeholder; configure it before running Coder.';
105
+ }
106
+
107
+ for (const [name, command] of Object.entries(existing)) {
108
+ if (
109
+ ['check', ...legacyNames].some(
110
+ (verificationName) =>
111
+ name === verificationName ||
112
+ SCRIPT_LIFECYCLE_PREFIXES.some((prefix) => name === `${prefix}${verificationName}`),
113
+ )
114
+ )
115
+ continue;
116
+ const migratedCaller = migrateGeneratedCoderRunScript(command);
117
+ if (migratedCaller !== undefined) {
118
+ // A different existing check is authoritative, but changing a custom legacy caller's scope is not safe.
119
+ const referencedLegacyName = legacyNames.find((legacyName) => command.includes(legacyName));
120
+ const isConflictingCustomCheck =
121
+ referencedLegacyName !== undefined &&
122
+ !isLegacyCheckScopePreserved(referencedLegacyName, scripts) &&
123
+ !isUnchangedLegacyCheckDefault(referencedLegacyName, scripts);
124
+ if (!isConflictingCustomCheck) scripts[name] = migratedCaller;
125
+ }
126
+ }
127
+
128
+ for (const legacyName of legacyNames) {
129
+ const callers = Object.entries(scripts)
130
+ .filter(([name, command]) => name !== legacyName && command.includes(legacyName))
131
+ .map(([name]) => name);
132
+ const isPreservedScope = isLegacyCheckScopePreserved(legacyName, scripts);
133
+ const isObsoleteGeneratedDefault =
134
+ isUnchangedLegacyCheckDefault(legacyName, scripts) && !isCheckSetupRequired(scripts.check!);
135
+ const files = externalCallers[legacyName] ?? [];
136
+ if (callers.length === 0 && files.length === 0 && (isPreservedScope || isObsoleteGeneratedDefault)) {
137
+ delete scripts[legacyName];
138
+ for (const prefix of SCRIPT_LIFECYCLE_PREFIXES) delete scripts[`${prefix}${legacyName}`];
139
+ } else {
140
+ migrationInstructions.push(
141
+ `Kept scripts.${legacyName}${
142
+ callers.length ? `; referenced by scripts.${callers.join(', scripts.')}` : ''
143
+ }${files.length ? `; referenced by ${files.join(', ')}` : ''}${
144
+ !isPreservedScope && !isObsoleteGeneratedDefault
145
+ ? '; its custom command or npm lifecycle hooks differ from scripts.check'
146
+ : ''
147
+ }. Preserve its required validation and pre/post hooks in scripts.check, update those callers to npm run check, then remove scripts.${legacyName} and its unused lifecycle hooks.`,
148
+ );
149
+ }
150
+ }
151
+ for (const [name, command] of Object.entries(scripts)) {
152
+ if (
153
+ /\b(?:ptbk|promptbook)\s+coder\s+(?:run|server)\b|\brun-codex-prompts\b/u.test(command) &&
154
+ /--test(?:-before)?(?:\s|=|$)/u.test(command)
155
+ ) {
156
+ migrationInstructions.push(
157
+ `Update scripts.${name}: replace --test with --check and --test-before with --check-before; review its shell expression manually. Existing command was preserved: ${command}`,
158
+ );
159
+ }
160
+ }
161
+
162
+ let isCheckConfigured = true;
163
+ try {
164
+ assertProjectCheckScriptsAreConfigured(scripts);
165
+ } catch (error) {
166
+ if (!(error instanceof CoderCheckSetupError)) throw error;
167
+ isCheckConfigured = false;
168
+ checkScriptSummary += ` Additional setup required: ${error.message}`;
169
+ }
170
+
171
+ return {
172
+ scripts,
173
+ checkScriptSummary,
174
+ migrationInstructions,
175
+ isCheckConfigured,
176
+ };
177
+ }
178
+
179
+ /** Determines whether both the legacy command and its implicit npm validation hooks have been preserved. */
180
+ function isLegacyCheckScopePreserved(name: string, scripts: Readonly<Record<string, string>>): boolean {
181
+ return (
182
+ scripts[name] === scripts.check &&
183
+ SCRIPT_LIFECYCLE_PREFIXES.every((prefix) => scripts[`${prefix}${name}`] === scripts[`${prefix}check`])
184
+ );
185
+ }
186
+
187
+ /** Recognizes the generated default only when no custom lifecycle hooks extend its validation scope. */
188
+ function isUnchangedLegacyCheckDefault(name: string, scripts: Readonly<Record<string, string>>): boolean {
189
+ return (
190
+ scripts[name] === 'npm test' &&
191
+ SCRIPT_LIFECYCLE_PREFIXES.every((prefix) => scripts[`${prefix}${name}`] === undefined)
192
+ );
193
+ }
194
+
195
+ /**
196
+ * Recognizes unchanged generated run scripts, including the previous explicit Developer/context defaults.
197
+ * Unknown shell expressions and custom harness configuration are preserved for manual migration.
198
+ */
199
+ function migrateGeneratedCoderRunScript(command: string): string | undefined {
200
+ const prefix = 'npx ptbk coder run --harness openai-codex --thinking-level max';
201
+ const defaultArguments = ['', ' --agent agents/developer.book --context AGENTS.md'];
202
+ const verificationArguments = [
203
+ ' --test-before yes-and-fix',
204
+ ...LEGACY_CHECK_SCRIPT_NAMES.map((name) => ` --test "npm run ${name}" --test-before yes-and-fix`),
205
+ ...LEGACY_CHECK_SCRIPT_NAMES.map((name) => ` --check "npm run ${name}" --check-before yes-and-fix`),
206
+ ];
207
+ const isGenerated = defaultArguments.some((defaults) =>
208
+ verificationArguments.some((verification) => command === prefix + defaults + verification),
209
+ );
210
+ return isGenerated ? getDefaultCoderPackageJsonScripts()['coder:run'] : undefined;
211
+ }
212
+
213
+ /** Selects safe conventional scripts, avoiding duplicates already reached by another selected aggregate. */
214
+ function selectValidationScripts(scripts: Readonly<Record<string, string>>): string[] {
215
+ if (
216
+ SCRIPT_LIFECYCLE_PREFIXES.some(
217
+ (prefix) =>
218
+ scripts[`${prefix}check`] !== undefined &&
219
+ !isUsableValidationScript(`${prefix}check`, scripts, new Set()),
220
+ )
221
+ )
222
+ return [];
223
+ const selected: string[] = [];
224
+ for (const group of VALIDATION_SCRIPT_GROUPS) {
225
+ const name = group.find((candidate) => isUsableValidationScript(candidate, scripts, new Set()));
226
+ if (name !== undefined) selected.push(name);
227
+ }
228
+ if (isUsableValidationScript('test', scripts, new Set())) selected.push('test');
229
+ else
230
+ for (const group of TEST_SCRIPT_GROUPS) {
231
+ const name = group.find((candidate) => isUsableValidationScript(candidate, scripts, new Set()));
232
+ if (name !== undefined) selected.push(name);
233
+ }
234
+ return selected.filter(
235
+ (name) => !selected.some((other) => other !== name && scriptReaches(other, name, scripts, new Set())),
236
+ );
237
+ }
238
+
239
+ /** Inspects each body, referenced script, and implicit lifecycle hook before including it in an aggregate. */
240
+ function isUsableValidationScript(
241
+ name: string,
242
+ scripts: Readonly<Record<string, string>>,
243
+ visited: ReadonlySet<string>,
244
+ ): boolean {
245
+ const command = scripts[name];
246
+ if (
247
+ !command ||
248
+ visited.has(name) ||
249
+ NON_VALIDATION_SCRIPT_PATTERN.test(name) ||
250
+ isCheckSetupRequired(command) ||
251
+ UNSUITABLE_VALIDATION_BODY_PATTERN.test(command)
252
+ )
253
+ return false;
254
+ if (
255
+ command.split('&&').every((part) => /^\s*(?:echo|printf|true|:)(?:\s|$)/iu.test(part)) ||
256
+ /\bprocess\.exit\(\s*0\s*\)/u.test(command)
257
+ )
258
+ return false;
259
+ if (
260
+ /\b(?:vite|next|astro|webpack-dev-server)\s+(?:dev|start|serve)\b/iu.test(command) ||
261
+ /(?:^|&&)\s*(?:vite|webpack-dev-server)(?:\s*$|\s+--)/iu.test(command) ||
262
+ (/\bvitest\b/iu.test(command) && !/\bvitest\s+run\b/iu.test(command))
263
+ )
264
+ return false;
265
+ const nextVisited = new Set([...visited, name]);
266
+ const references = projectScriptReferences(command);
267
+ // Ambiguous package-manager flags and cwd switches cannot be composed confidently as root validation.
268
+ if (
269
+ /\b(?:npm|pnpm|yarn)\s+(?:--|run(?:-script)?\s+--)/u.test(command) ||
270
+ (/\b(?:npm|pnpm|yarn)\b/u.test(command) && references.length === 0)
271
+ )
272
+ return false;
273
+ if (references.some((reference) => !isUsableValidationScript(reference, scripts, nextVisited))) return false;
274
+ return SCRIPT_LIFECYCLE_PREFIXES.every((prefix) => {
275
+ const lifecycleName = `${prefix}${name}`;
276
+ return scripts[lifecycleName] === undefined || isUsableValidationScript(lifecycleName, scripts, nextVisited);
277
+ });
278
+ }
279
+
280
+ /** Checks whether a selected aggregate already reaches another selected script. */
281
+ function scriptReaches(
282
+ name: string,
283
+ target: string,
284
+ scripts: Readonly<Record<string, string>>,
285
+ visited: ReadonlySet<string>,
286
+ ): boolean {
287
+ if (visited.has(name)) return false;
288
+ const nextVisited = new Set([...visited, name]);
289
+ const command = scripts[name] ?? '';
290
+ if (
291
+ (target === 'coder:run' && /\b(?:ptbk|promptbook)\s+coder\s+run\b/u.test(command)) ||
292
+ (target === 'coder:fix' && /\b(?:ptbk|promptbook)\s+coder\s+fix\b/u.test(command))
293
+ )
294
+ return true;
295
+ const references = [
296
+ ...projectScriptReferences(command),
297
+ ...SCRIPT_LIFECYCLE_PREFIXES.map((prefix) => `${prefix}${name}`).filter(
298
+ (lifecycleName) => scripts[lifecycleName] !== undefined,
299
+ ),
300
+ ];
301
+ return references.some(
302
+ (reference) => reference === target || scriptReaches(reference, target, scripts, nextVisited),
303
+ );
304
+ }
@@ -18,10 +18,12 @@ export function printInitializationSummary(
18
18
  ): void {
19
19
  const isUnresolved =
20
20
  summary.adamAgentFileStatus === 'unresolved' ||
21
+ !summary.isCheckConfigured ||
22
+ summary.migrationInstructions.length > 0 ||
21
23
  summary.referencedArtifactStatuses.some(({ status }) => status === 'unresolved');
22
24
  console.info(
23
25
  isUnresolved
24
- ? colors.yellow('Promptbook coder initialization has unresolved artifacts.')
26
+ ? colors.yellow('Promptbook coder configuration setup: additional setup is required.')
25
27
  : colors.green('Promptbook coder configuration setup:'),
26
28
  );
27
29
  if (workspace)
@@ -60,6 +62,8 @@ export function printInitializationSummary(
60
62
  } else {
61
63
  printInitializationNote('Required coder env variables are already present.', colors.gray);
62
64
  }
65
+ console.info((summary.isCheckConfigured ? colors.cyan : colors.yellow)(summary.checkScriptSummary));
66
+ for (const instruction of summary.migrationInstructions) console.info(colors.yellow(`! ${instruction}`));
63
67
  }
64
68
 
65
69
  /**
@@ -225,9 +225,9 @@ export const PROMPTS_README_TEMPLATE = spaceTrim(`
225
225
 
226
226
  Runner-written completion lines may attribute implementation to a harness and model, include
227
227
  reasoning/authentication labels, attempts or interrupted/continued history, and report implementation,
228
- testing, fixing, or total cost/time information. Those are observed run metadata, not instructions, budgets,
229
- or a frozen list of supported models. A completed status alone does not prove tests ran: direct runs only
230
- execute an automated verification command when configured. Preserve actual measurements and record unknown
228
+ checking, fixing, or total cost/time information. Those are observed run metadata, not instructions, budgets,
229
+ or a frozen list of supported models. A completed status alone does not prove checks ran: direct runs only
230
+ execute the project check command when configured. Preserve actual measurements and record unknown
231
231
  results or checks that were not run honestly. Manual users must not invent cost/time figures, copy another
232
232
  run's attribution, or mark unverified work as verified. The textual metadata rows above demonstrate syntax
233
233
  only; use them only when the described events actually happened.
@@ -278,9 +278,9 @@ export const PROMPTS_README_TEMPLATE = spaceTrim(`
278
278
  | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
279
279
  | \`ptbk init\` / \`ptbk coder init\` | Initializes missing Git, then creates missing configuration, local Books, this guide, and fresh-directory boilerplates; preserves project-owned content. \`--no-questions\` skips installation questions/checks. |
280
280
  | \`ptbk coder add "Describe the reviewed change"\` | Creates one numbered, tagged pending PRD. Accepts a description argument, stdin, or interactive input; \`--priority\` and \`--template\` are available. It does not discuss or implement the task. Review the generated requirements before running. |
281
- | \`ptbk coder plan --harness openai-codex\` | Interactive planning with the local Planner. Review proposals; \`/save\` writes pending PRDs, \`/draft\` writes not-ready drafts, \`/discard\` drops proposals, \`/exit\` ends. It changes PRD Markdown only and never implements or starts the queue. Currently this planning command supports the Codex harness in a compatible interactive terminal. |
281
+ | \`ptbk coder plan --harness openai-codex\` | Interactive planning with the local Developer. Review proposals; \`/save\` writes pending PRDs, \`/draft\` writes not-ready drafts, \`/discard\` drops proposals, \`/exit\` ends. It changes PRD Markdown only and never implements or starts the queue. Currently this planning command supports the Codex harness in a compatible interactive terminal. |
282
282
  | \`ptbk coder list\` | Displays fully authored pending tasks grouped by descending priority without execution or file changes. Optional harness/model/agent and priority filters narrow the list. |
283
- | \`ptbk coder run --harness openai-codex --limit 1 --no-commit --no-auto --test "npm test"\` | Confirms and implements one selected task, then runs the specified project check. Replace the test command as needed. Without \`--limit\`, execution proceeds through the eligible queue; without \`--no-commit\`, run stages and commits its changes. |
283
+ | \`ptbk coder run --harness openai-codex --limit 1 --no-commit --no-auto --check "npm run check"\` | Confirms and implements one selected task, then runs the specified project check. Replace the check command as needed. Without \`--limit\`, execution proceeds through the eligible queue; without \`--no-commit\`, run stages and commits its changes. |
284
284
  | \`ptbk coder verify\` | Human review helper: shows completion claims, offers archival or a repair section, and can also ask about pending tasks. It does not run acceptance tests itself. Archival moves the whole file to \`done/\`, so inspect every section before agreeing. There is no separate archive command. |
285
285
  | \`ptbk coder find-unwritten\` | Lists pending sections still containing authoring placeholders; not-ready drafts are not included. |
286
286
  | \`ptbk coder generate-boilerplates\` | Adds not-ready starter sections using reusable templates; author and review them before making them pending. |
@@ -292,11 +292,18 @@ export const PROMPTS_README_TEMPLATE = spaceTrim(`
292
292
  pulling require the corresponding explicit options. Consult \`ptbk coder --help\` and the relevant subcommand's
293
293
  \`--help\` for the installed version's full options.
294
294
 
295
- The initialized \`npm run coder:run\` script supplies \`AGENTS.md\` as context, selects the Codex harness, and
296
- uses \`npm run test-for-ptbk-coder\` for checks (including pre-run repair mode). The new check script delegates
297
- to \`npm test\`; configure real tests for your project before running it. Existing npm scripts are preserved, so
298
- read your \`package.json\` to see your actual commands. Direct \`ptbk coder run\` does not inherit npm-script
299
- flags.
295
+ The initialized \`npm run coder:run\` script selects the Codex harness and uses
296
+ \`--check "npm run check" --check-before yes-and-fix\`. Developer, the current project directory, and its
297
+ \`AGENTS.md\` are shared CLI defaults. A **check** covers the project's chosen tests, linting, typechecking,
298
+ builds, generated-code consistency, and other validation. Tests remain one kind of check.
299
+ Init preserves an existing \`scripts.check\` exactly, or composes applicable existing validation scripts and
300
+ reports the selected scope. If none are usable, it creates a failing setup placeholder: configure real
301
+ validation before running Coder. Missing checks or setup placeholders stop with setup guidance, without model repairs.
302
+ Direct \`ptbk coder run\` defaults to \`--check-before no\`; checks after prompts remain opt-in. Enabled
303
+ preflight without an explicit command uses \`npm run check\`, including during repair verification.
304
+ Replace retired \`--test\` / \`--test-before\` with \`--check\` / \`--check-before\`. Init migrates recognized
305
+ generated scripts and preserves custom legacy validation in \`check\`. Conflicting definitions or custom callers
306
+ are preserved with manual migration instructions; review them before removing a legacy script.
300
307
 
301
308
  ### Book agent, harness, and model
302
309
 
@@ -308,9 +315,20 @@ export const PROMPTS_README_TEMPLATE = spaceTrim(`
308
315
  Init creates local Developer and Planner Books in \`agents/developer.book\` and \`agents/planner.book\`, their
309
316
  Lawyer and Copywriter TEAM advisers, and shared \`agents/.core/adam.book\` instructions. Books can
310
317
  inherit/import instructions; TEAM entries expose advisers for relevant consultations, not an obligation to
311
- invoke everyone. \`run\` and \`server\` default to Developer; \`plan\` defaults to Planner.
312
- \`--agent agents/my-developer.book\` overrides the Book only. \`list\` has no default Book filter. Selecting
313
- Developer for \`plan\` still permits planning only.
318
+ invoke everyone. \`run\`, \`server\` and \`plan\` default to Developer.
319
+ \`--agent ./agents/planner.book\` selects Planner explicitly; another Book path also works. \`list\` has no
320
+ default Book filter. Every Book used in \`plan\`, including Developer, still permits planning only.
321
+
322
+ Project commands default to the current directory captured when invoked. \`--path\` selects another existing
323
+ directory, relative to that invocation or absolute; an enclosing Git repository never relocates the project's
324
+ Books, PRDs or context. Additional context defaults to the actual UTF-8 contents of that project's \`AGENTS.md\`.
325
+ A missing implicit file warns and continues; an unreadable file fails. \`--context\` replaces the default with
326
+ inline instructions or a file resolved relative to the selected project; \`--context ""\` disables it.
327
+ Invalid explicit Books and missing/unreadable explicit context files fail without falling back.
328
+ Thus \`ptbk coder run --harness openai-codex\` and
329
+ \`ptbk coder run --harness openai-codex --agent ./agents/developer.book --path . --context ./AGENTS.md\` select
330
+ the same inputs. New npm scripts rely on these defaults; init still creates missing Books and AGENTS.md even
331
+ when every script already exists, preserving existing custom scripts, settings and context.
314
332
 
315
333
  Edit local Books to reflect this project's rules; repeat init preserves customizations and adds missing
316
334
  defaults/helper references. An invalid explicit Book selection fails rather than silently changing roles.