@promptbook/cli 0.114.0-33 → 0.114.0-34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +1254 -318
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-codex-prompts/common/createFreeDiskSpaceGuard.d.ts +25 -0
- package/esm/scripts/run-codex-prompts/common/formatUnknownErrorDetails.d.ts +4 -0
- package/esm/scripts/run-codex-prompts/common/resolveCoderAgent.d.ts +21 -3
- package/esm/scripts/run-codex-prompts/main/listCoderPrompts.d.ts +1 -1
- package/esm/scripts/run-codex-prompts/prompts/buildPromptRunTraceContent.d.ts +77 -0
- package/esm/scripts/run-codex-prompts/prompts/buildPromptRunTracePath.d.ts +10 -0
- package/esm/scripts/run-codex-prompts/prompts/isPromptCompatibleWithRunner.d.ts +11 -6
- package/esm/scripts/run-codex-prompts/prompts/loadPromptFiles.d.ts +1 -1
- package/esm/scripts/run-codex-prompts/prompts/writePromptRunTrace.d.ts +19 -0
- package/esm/scripts/run-codex-prompts/runners/common/buildHarnessAuthenticationError.d.ts +20 -0
- package/esm/scripts/run-codex-prompts/runners/common/createAuthenticationAwarePromptRunner.d.ts +11 -0
- package/esm/scripts/run-codex-prompts/runners/common/extractHarnessAuthenticationFailureReason.d.ts +9 -0
- package/esm/scripts/run-codex-prompts/ui/buildCoderRunUiFrame.d.ts +3 -0
- package/esm/src/book-2.0/book-language-documentation/getSafeCodeBlock.d.ts +1 -1
- package/esm/src/book-components/Chat/MockedChat/MockedChat.test.d.ts +2 -0
- package/esm/src/cli/cli-commands/coder/$ensureCoderHarnessGitignoreRules.d.ts +2 -1
- package/esm/src/cli/cli-commands/coder/agentCliOptions.d.ts +21 -0
- package/esm/src/cli/cli-commands/coder/boilerplateTemplates.d.ts +8 -21
- package/esm/src/cli/cli-commands/coder/coderReferencedArtifacts.d.ts +33 -0
- package/esm/src/cli/cli-commands/coder/ensureCoderPackageJsonFile.d.ts +4 -2
- package/esm/src/cli/cli-commands/coder/ensureCoderVscodeSettingsFile.d.ts +2 -0
- package/esm/src/cli/cli-commands/coder/ensureDirectory.d.ts +6 -0
- package/esm/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.d.ts +6 -0
- package/esm/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +7 -5
- package/esm/src/cli/cli-commands/coder/mergeStringRecordJsonFile.d.ts +19 -1
- package/esm/src/cli/cli-commands/coder/printCoderRunFailure.d.ts +6 -0
- package/esm/src/cli/cli-commands/common/$askForConfirmation.d.ts +4 -2
- package/esm/src/cli/cli-commands/common/disk-space/$assertSufficientFreeDiskSpace.d.ts +12 -0
- package/esm/src/cli/cli-commands/common/disk-space/$assertSufficientFreeDiskSpace.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/common/disk-space/$readFreeDiskSpaceStatus.d.ts +11 -0
- package/esm/src/cli/cli-commands/common/disk-space/$readFreeDiskSpaceStatus.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/common/disk-space/FreeDiskSpaceStatus.d.ts +33 -0
- package/esm/src/cli/cli-commands/common/disk-space/formatFreeDiskSpaceBytes.d.ts +6 -0
- package/esm/src/cli/cli-commands/common/disk-space/formatFreeDiskSpaceBytes.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/common/disk-space/formatLowFreeDiskSpaceWarning.d.ts +10 -0
- package/esm/src/cli/cli-commands/common/disk-space/freeDiskSpaceConstants.d.ts +28 -0
- package/esm/src/cli/cli-commands/common/disk-space/resolveFreeDiskSpaceLevel.d.ts +7 -0
- package/esm/src/cli/cli-commands/common/disk-space/resolveFreeDiskSpaceLevel.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.d.ts +2 -1
- package/esm/src/cli/cli-commands/common/harness/$ensureHarnessInstallations.d.ts +3 -2
- package/esm/src/cli/cli-commands/common/harness/HarnessDefinition.d.ts +26 -0
- package/esm/src/cli/cli-commands/common/npm/$askForNpmPackageInstallationApproval.d.ts +4 -2
- package/esm/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.d.ts +2 -1
- package/esm/src/cli/cli-commands/common/questionsCliOptions.d.ts +45 -0
- package/esm/src/cli/cli-commands/common/questionsCliOptions.test.d.ts +1 -0
- package/esm/src/cli/common/$deprecateCliCommand.d.ts +3 -0
- package/esm/src/cli/common/$hideCliCommandFromHelp.d.ts +11 -0
- package/esm/src/cli/common/$hideCliCommandFromHelp.test.d.ts +1 -0
- package/esm/src/cli/common/$requireCliSubcommand.d.ts +18 -0
- package/esm/src/cli/common/$requireCliSubcommand.test.d.ts +1 -0
- package/esm/src/llm-providers/vercel/VercelExecutionToolsOptions.d.ts +5 -2
- package/esm/src/version.d.ts +1 -1
- package/package.json +8 -11
- package/src/book-2.0/book-language-documentation/getSafeCodeBlock.ts +1 -1
- package/src/book-components/Chat/MockedChat/MockedChat.tsx +25 -1
- package/src/cli/cli-commands/agent-folder.ts +2 -6
- package/src/cli/cli-commands/agent.ts +2 -6
- package/src/cli/cli-commands/agents-server.ts +2 -6
- package/src/cli/cli-commands/coder/$ensureCoderHarnessGitignoreRules.ts +3 -0
- package/src/cli/cli-commands/coder/add.ts +27 -2
- package/src/cli/cli-commands/coder/agentCliOptions.ts +32 -0
- package/src/cli/cli-commands/coder/boilerplateTemplates.ts +17 -44
- package/src/cli/cli-commands/coder/coderReferencedArtifacts.ts +106 -0
- package/src/cli/cli-commands/coder/ensureCoderPackageJsonFile.ts +4 -2
- package/src/cli/cli-commands/coder/ensureCoderVscodeSettingsFile.ts +5 -1
- package/src/cli/cli-commands/coder/ensureDirectory.ts +27 -1
- package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +99 -10
- package/src/cli/cli-commands/coder/init.ts +23 -14
- package/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.ts +18 -27
- package/src/cli/cli-commands/coder/list.ts +15 -3
- package/src/cli/cli-commands/coder/mergeStringRecordJsonFile.ts +31 -7
- package/src/cli/cli-commands/coder/ping.ts +25 -22
- package/src/cli/cli-commands/coder/printCoderRunFailure.ts +14 -0
- package/src/cli/cli-commands/coder/printInitializationSummary.ts +23 -16
- package/src/cli/cli-commands/coder/run.ts +34 -23
- package/src/cli/cli-commands/coder/server.ts +43 -32
- package/src/cli/cli-commands/coder.ts +2 -6
- package/src/cli/cli-commands/common/$askForConfirmation.ts +12 -2
- package/src/cli/cli-commands/common/disk-space/$assertSufficientFreeDiskSpace.ts +35 -0
- package/src/cli/cli-commands/common/disk-space/$readFreeDiskSpaceStatus.ts +37 -0
- package/src/cli/cli-commands/common/disk-space/FreeDiskSpaceStatus.ts +39 -0
- package/src/cli/cli-commands/common/disk-space/formatFreeDiskSpaceBytes.ts +26 -0
- package/src/cli/cli-commands/common/disk-space/formatLowFreeDiskSpaceWarning.ts +33 -0
- package/src/cli/cli-commands/common/disk-space/freeDiskSpaceConstants.ts +33 -0
- package/src/cli/cli-commands/common/disk-space/resolveFreeDiskSpaceLevel.ts +21 -0
- package/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.ts +17 -5
- package/src/cli/cli-commands/common/harness/$ensureHarnessInstallations.ts +8 -3
- package/src/cli/cli-commands/common/harness/HarnessDefinition.ts +36 -0
- package/src/cli/cli-commands/common/npm/$askForNpmPackageInstallationApproval.ts +8 -3
- package/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.ts +13 -2
- package/src/cli/cli-commands/common/questionsCliOptions.ts +89 -0
- package/src/cli/cli-commands/run.ts +3 -1
- package/src/cli/common/$deprecateCliCommand.ts +5 -0
- package/src/cli/common/$hideCliCommandFromHelp.ts +27 -0
- package/src/cli/common/$requireCliSubcommand.ts +35 -0
- package/src/cli/promptbookCli.ts +13 -9
- package/src/llm-providers/vercel/VercelExecutionToolsOptions.ts +7 -2
- package/src/llm-providers/vercel/createExecutionToolsFromVercelProvider.ts +18 -17
- package/src/other/templates/getTemplatesPipelineCollection.ts +677 -881
- package/src/version.ts +2 -2
- package/src/versions.txt +1 -0
- package/umd/index.umd.js +1253 -317
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-codex-prompts/common/createFreeDiskSpaceGuard.d.ts +25 -0
- package/umd/scripts/run-codex-prompts/common/formatUnknownErrorDetails.d.ts +4 -0
- package/umd/scripts/run-codex-prompts/common/resolveCoderAgent.d.ts +21 -3
- package/umd/scripts/run-codex-prompts/main/listCoderPrompts.d.ts +1 -1
- package/umd/scripts/run-codex-prompts/prompts/buildPromptRunTraceContent.d.ts +77 -0
- package/umd/scripts/run-codex-prompts/prompts/buildPromptRunTracePath.d.ts +10 -0
- package/umd/scripts/run-codex-prompts/prompts/isPromptCompatibleWithRunner.d.ts +11 -6
- package/umd/scripts/run-codex-prompts/prompts/loadPromptFiles.d.ts +1 -1
- package/umd/scripts/run-codex-prompts/prompts/writePromptRunTrace.d.ts +19 -0
- package/umd/scripts/run-codex-prompts/runners/common/buildHarnessAuthenticationError.d.ts +20 -0
- package/umd/scripts/run-codex-prompts/runners/common/createAuthenticationAwarePromptRunner.d.ts +11 -0
- package/umd/scripts/run-codex-prompts/runners/common/extractHarnessAuthenticationFailureReason.d.ts +9 -0
- package/umd/scripts/run-codex-prompts/ui/buildCoderRunUiFrame.d.ts +3 -0
- package/umd/src/book-2.0/book-language-documentation/getSafeCodeBlock.d.ts +1 -1
- package/umd/src/book-components/Chat/MockedChat/MockedChat.test.d.ts +2 -0
- package/umd/src/cli/cli-commands/coder/$ensureCoderHarnessGitignoreRules.d.ts +2 -1
- package/umd/src/cli/cli-commands/coder/agentCliOptions.d.ts +21 -0
- package/umd/src/cli/cli-commands/coder/boilerplateTemplates.d.ts +8 -21
- package/umd/src/cli/cli-commands/coder/coderReferencedArtifacts.d.ts +33 -0
- package/umd/src/cli/cli-commands/coder/ensureCoderPackageJsonFile.d.ts +4 -2
- package/umd/src/cli/cli-commands/coder/ensureCoderVscodeSettingsFile.d.ts +2 -0
- package/umd/src/cli/cli-commands/coder/ensureDirectory.d.ts +6 -0
- package/umd/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.d.ts +6 -0
- package/umd/src/cli/cli-commands/coder/init.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +7 -5
- package/umd/src/cli/cli-commands/coder/mergeStringRecordJsonFile.d.ts +19 -1
- package/umd/src/cli/cli-commands/coder/printCoderRunFailure.d.ts +6 -0
- package/umd/src/cli/cli-commands/common/$askForConfirmation.d.ts +4 -2
- package/umd/src/cli/cli-commands/common/$askForConfirmation.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/disk-space/$assertSufficientFreeDiskSpace.d.ts +12 -0
- package/umd/src/cli/cli-commands/common/disk-space/$assertSufficientFreeDiskSpace.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/disk-space/$readFreeDiskSpaceStatus.d.ts +11 -0
- package/umd/src/cli/cli-commands/common/disk-space/$readFreeDiskSpaceStatus.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/disk-space/FreeDiskSpaceStatus.d.ts +33 -0
- package/umd/src/cli/cli-commands/common/disk-space/formatFreeDiskSpaceBytes.d.ts +6 -0
- package/umd/src/cli/cli-commands/common/disk-space/formatFreeDiskSpaceBytes.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/disk-space/formatLowFreeDiskSpaceWarning.d.ts +10 -0
- package/umd/src/cli/cli-commands/common/disk-space/freeDiskSpaceConstants.d.ts +28 -0
- package/umd/src/cli/cli-commands/common/disk-space/resolveFreeDiskSpaceLevel.d.ts +7 -0
- package/umd/src/cli/cli-commands/common/disk-space/resolveFreeDiskSpaceLevel.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.d.ts +2 -1
- package/umd/src/cli/cli-commands/common/harness/$ensureHarnessInstallations.d.ts +3 -2
- package/umd/src/cli/cli-commands/common/harness/HarnessDefinition.d.ts +26 -0
- package/umd/src/cli/cli-commands/common/npm/$askForNpmPackageInstallationApproval.d.ts +4 -2
- package/umd/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.d.ts +2 -1
- package/umd/src/cli/cli-commands/common/questionsCliOptions.d.ts +45 -0
- package/umd/src/cli/cli-commands/common/questionsCliOptions.test.d.ts +1 -0
- package/umd/src/cli/common/$deprecateCliCommand.d.ts +3 -0
- package/umd/src/cli/common/$hideCliCommandFromHelp.d.ts +11 -0
- package/umd/src/cli/common/$hideCliCommandFromHelp.test.d.ts +1 -0
- package/umd/src/cli/common/$requireCliSubcommand.d.ts +18 -0
- package/umd/src/cli/common/$requireCliSubcommand.test.d.ts +1 -0
- package/umd/src/llm-providers/vercel/VercelExecutionToolsOptions.d.ts +5 -2
- package/umd/src/version.d.ts +1 -1
- package/esm/src/cli/cli-commands/coder/agentCodingFile.d.ts +0 -13
- package/esm/src/cli/cli-commands/common/harnessUpdateCliOptions.d.ts +0 -29
- package/src/cli/cli-commands/coder/agentCodingFile.ts +0 -25
- package/src/cli/cli-commands/common/harnessUpdateCliOptions.ts +0 -46
- package/umd/src/cli/cli-commands/coder/agentCodingFile.d.ts +0 -13
- package/umd/src/cli/cli-commands/common/harnessUpdateCliOptions.d.ts +0 -29
- /package/esm/src/cli/cli-commands/{common/harnessUpdateCliOptions.test.d.ts → coder/init.test.d.ts} +0 -0
- /package/{umd/src/cli/cli-commands/common/harnessUpdateCliOptions.test.d.ts → esm/src/cli/cli-commands/common/$askForConfirmation.test.d.ts} +0 -0
|
@@ -24,6 +24,13 @@ export const PROMPTS_DONE_DIRECTORY_PATH = join(PROMPTS_DIRECTORY_PATH, 'done');
|
|
|
24
24
|
*/
|
|
25
25
|
export const PROMPTS_TEMPLATES_DIRECTORY_PATH = join(PROMPTS_DIRECTORY_PATH, 'templates');
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Relative path to the project-agnostic `common` boilerplate template referenced by the default coder scripts.
|
|
29
|
+
*
|
|
30
|
+
* @private internal utility of `ptbk coder`
|
|
31
|
+
*/
|
|
32
|
+
export const COMMON_PROMPT_TEMPLATE_FILE_PATH = join(PROMPTS_TEMPLATES_DIRECTORY_PATH, 'common.md');
|
|
33
|
+
|
|
27
34
|
/**
|
|
28
35
|
* Initialization statuses used when creating or updating coder configuration artifacts.
|
|
29
36
|
*
|
|
@@ -66,26 +73,6 @@ export type CoderPromptTemplateDefinition = {
|
|
|
66
73
|
readonly isDefaultProjectTemplate: boolean;
|
|
67
74
|
};
|
|
68
75
|
|
|
69
|
-
/**
|
|
70
|
-
* Result of ensuring one default coder template file exists inside a project.
|
|
71
|
-
*
|
|
72
|
-
* @private internal utility of `ptbk coder`
|
|
73
|
-
*/
|
|
74
|
-
export type EnsuredCoderPromptTemplateFile = {
|
|
75
|
-
/**
|
|
76
|
-
* Stable built-in identifier of the template.
|
|
77
|
-
*/
|
|
78
|
-
readonly id: BuiltInCoderPromptTemplate;
|
|
79
|
-
/**
|
|
80
|
-
* Project-relative path of the materialized template file.
|
|
81
|
-
*/
|
|
82
|
-
readonly relativeFilePath: string;
|
|
83
|
-
/**
|
|
84
|
-
* Status describing whether the file had to be created.
|
|
85
|
-
*/
|
|
86
|
-
readonly status: InitializationStatus;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
76
|
/**
|
|
90
77
|
* Fully resolved boilerplate template used by `coder generate-boilerplates`.
|
|
91
78
|
*
|
|
@@ -118,7 +105,7 @@ export type ResolvedCoderPromptTemplate = {
|
|
|
118
105
|
const DEFAULT_CODER_PROMPT_TEMPLATE_DEFINITIONS = [
|
|
119
106
|
{
|
|
120
107
|
id: 'common',
|
|
121
|
-
relativeFilePath:
|
|
108
|
+
relativeFilePath: COMMON_PROMPT_TEMPLATE_FILE_PATH,
|
|
122
109
|
slugPrefix: null,
|
|
123
110
|
content: spaceTrim(`
|
|
124
111
|
- @@@
|
|
@@ -172,35 +159,21 @@ export function getDefaultCoderPromptTemplateDefinition(
|
|
|
172
159
|
}
|
|
173
160
|
|
|
174
161
|
/**
|
|
175
|
-
* Ensures
|
|
162
|
+
* Ensures one project-owned coder template file exists without overwriting user customizations.
|
|
176
163
|
*
|
|
177
164
|
* @private internal utility of `ptbk coder`
|
|
178
165
|
*/
|
|
179
|
-
export async function
|
|
166
|
+
export async function ensureDefaultCoderPromptTemplateFile(
|
|
180
167
|
projectPath: string,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (await isExistingFile(absoluteTemplatePath)) {
|
|
187
|
-
ensuredTemplateFiles.push({
|
|
188
|
-
id: definition.id,
|
|
189
|
-
relativeFilePath: definition.relativeFilePath,
|
|
190
|
-
status: 'unchanged',
|
|
191
|
-
});
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
await writeFile(absoluteTemplatePath, `${definition.content}\n`, 'utf-8');
|
|
196
|
-
ensuredTemplateFiles.push({
|
|
197
|
-
id: definition.id,
|
|
198
|
-
relativeFilePath: definition.relativeFilePath,
|
|
199
|
-
status: 'created',
|
|
200
|
-
});
|
|
168
|
+
definition: CoderPromptTemplateDefinition,
|
|
169
|
+
): Promise<InitializationStatus> {
|
|
170
|
+
const absoluteTemplatePath = join(projectPath, definition.relativeFilePath);
|
|
171
|
+
if (await isExistingFile(absoluteTemplatePath)) {
|
|
172
|
+
return 'unchanged';
|
|
201
173
|
}
|
|
202
174
|
|
|
203
|
-
|
|
175
|
+
await writeFile(absoluteTemplatePath, `${definition.content}\n`, 'utf-8');
|
|
176
|
+
return 'created';
|
|
204
177
|
}
|
|
205
178
|
|
|
206
179
|
/**
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { AGENTS_FILE_PATH, getDefaultCoderAgentsFileContent } from './agentsFile';
|
|
2
|
+
import type { CoderPromptTemplateDefinition, InitializationStatus } from './boilerplateTemplates';
|
|
3
|
+
import {
|
|
4
|
+
ensureDefaultCoderPromptTemplateFile,
|
|
5
|
+
getDefaultCoderProjectPromptTemplateDefinitions,
|
|
6
|
+
} from './boilerplateTemplates';
|
|
7
|
+
import { CODER_DEVELOPER_AGENT_FILE_PATH, ensureCoderDeveloperAgentFile } from './ensureCoderDeveloperAgentFile';
|
|
8
|
+
import { ensureCoderMarkdownFile } from './ensureCoderMarkdownFile';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Status of one artifact referenced by the default coder scripts.
|
|
12
|
+
*
|
|
13
|
+
* `not-referenced` means that no newly added script points at the artifact, so `ptbk coder init` left it alone.
|
|
14
|
+
*
|
|
15
|
+
* @private internal utility of `coder init` command
|
|
16
|
+
*/
|
|
17
|
+
export type CoderReferencedArtifactStatus = InitializationStatus | 'not-referenced';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Result of ensuring one artifact referenced by the default coder scripts.
|
|
21
|
+
*
|
|
22
|
+
* @private internal utility of `coder init` command
|
|
23
|
+
*/
|
|
24
|
+
export type EnsuredCoderReferencedArtifact = {
|
|
25
|
+
/**
|
|
26
|
+
* Project-relative path of the referenced artifact.
|
|
27
|
+
*/
|
|
28
|
+
readonly relativeFilePath: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Status describing whether the artifact had to be created.
|
|
32
|
+
*/
|
|
33
|
+
readonly status: CoderReferencedArtifactStatus;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* One project artifact which the default coder scripts point at.
|
|
38
|
+
*/
|
|
39
|
+
type CoderReferencedArtifactDefinition = {
|
|
40
|
+
/**
|
|
41
|
+
* Project-relative path which both identifies the artifact and locates it inside the project.
|
|
42
|
+
*/
|
|
43
|
+
readonly relativeFilePath: string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Creates the artifact when it is missing, never overwriting an existing one.
|
|
47
|
+
*/
|
|
48
|
+
readonly ensureArtifactFile: (projectPath: string) => Promise<InitializationStatus>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates the artifact definition of one project-owned coder prompt template.
|
|
53
|
+
*/
|
|
54
|
+
function createCoderPromptTemplateArtifactDefinition(
|
|
55
|
+
definition: CoderPromptTemplateDefinition,
|
|
56
|
+
): CoderReferencedArtifactDefinition {
|
|
57
|
+
return {
|
|
58
|
+
relativeFilePath: definition.relativeFilePath,
|
|
59
|
+
ensureArtifactFile: (projectPath) => ensureDefaultCoderPromptTemplateFile(projectPath, definition),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Every artifact which the default coder scripts can reference.
|
|
65
|
+
*/
|
|
66
|
+
const CODER_REFERENCED_ARTIFACT_DEFINITIONS: ReadonlyArray<CoderReferencedArtifactDefinition> = [
|
|
67
|
+
{
|
|
68
|
+
relativeFilePath: CODER_DEVELOPER_AGENT_FILE_PATH,
|
|
69
|
+
ensureArtifactFile: ensureCoderDeveloperAgentFile,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
relativeFilePath: AGENTS_FILE_PATH,
|
|
73
|
+
ensureArtifactFile: (projectPath) =>
|
|
74
|
+
ensureCoderMarkdownFile(projectPath, AGENTS_FILE_PATH, getDefaultCoderAgentsFileContent()),
|
|
75
|
+
},
|
|
76
|
+
...getDefaultCoderProjectPromptTemplateDefinitions().map(createCoderPromptTemplateArtifactDefinition),
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Creates only those referenced artifacts which the freshly added coder scripts point at.
|
|
81
|
+
*
|
|
82
|
+
* An artifact of a script which the project already defines is intentionally **not** created - the project-owned
|
|
83
|
+
* script is kept as is, so it does not reference the default artifact in the first place.
|
|
84
|
+
*
|
|
85
|
+
* @private function of `initializeCoderProjectConfiguration`
|
|
86
|
+
*/
|
|
87
|
+
export async function ensureCoderReferencedArtifacts(
|
|
88
|
+
projectPath: string,
|
|
89
|
+
referencedArtifactPaths: ReadonlySet<string>,
|
|
90
|
+
): Promise<ReadonlyArray<EnsuredCoderReferencedArtifact>> {
|
|
91
|
+
const ensuredArtifacts: Array<EnsuredCoderReferencedArtifact> = [];
|
|
92
|
+
|
|
93
|
+
for (const { relativeFilePath, ensureArtifactFile } of CODER_REFERENCED_ARTIFACT_DEFINITIONS) {
|
|
94
|
+
if (!referencedArtifactPaths.has(relativeFilePath)) {
|
|
95
|
+
ensuredArtifacts.push({ relativeFilePath, status: 'not-referenced' });
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
ensuredArtifacts.push({ relativeFilePath, status: await ensureArtifactFile(projectPath) });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return ensuredArtifacts;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Note: [🟡] Code for coder init referenced artifacts [coderReferencedArtifacts](src/cli/cli-commands/coder/coderReferencedArtifacts.ts) should never be published outside of `@promptbook/cli`
|
|
106
|
+
// Note: [💞] Ignore a discrepancy between file name and exported helper names
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { InitializationStatus } from './boilerplateTemplates';
|
|
2
1
|
import { getDefaultCoderPackageJsonScripts } from './getDefaultCoderPackageJsonScripts';
|
|
2
|
+
import type { MergedStringRecordJsonFile } from './mergeStringRecordJsonFile';
|
|
3
3
|
import { mergeStringRecordJsonFile } from './mergeStringRecordJsonFile';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -10,9 +10,11 @@ const PACKAGE_JSON_FILE_PATH = 'package.json';
|
|
|
10
10
|
/**
|
|
11
11
|
* Ensures `package.json` contains the standalone Promptbook coder helper scripts.
|
|
12
12
|
*
|
|
13
|
+
* Scripts which the project already defines are kept as they are, only missing ones are added.
|
|
14
|
+
*
|
|
13
15
|
* @private function of `initializeCoderProjectConfiguration`
|
|
14
16
|
*/
|
|
15
|
-
export async function ensureCoderPackageJsonFile(projectPath: string): Promise<
|
|
17
|
+
export async function ensureCoderPackageJsonFile(projectPath: string): Promise<MergedStringRecordJsonFile> {
|
|
16
18
|
return mergeStringRecordJsonFile({
|
|
17
19
|
projectPath,
|
|
18
20
|
relativeFilePath: PACKAGE_JSON_FILE_PATH,
|
|
@@ -15,18 +15,22 @@ const VSCODE_DIRECTORY_PATH = '.vscode';
|
|
|
15
15
|
/**
|
|
16
16
|
* Ensures VS Code routes pasted prompt images into `prompts/screenshots`.
|
|
17
17
|
*
|
|
18
|
+
* Settings which the project already defines are kept as they are, only missing ones are added.
|
|
19
|
+
*
|
|
18
20
|
* @private function of `initializeCoderProjectConfiguration`
|
|
19
21
|
*/
|
|
20
22
|
export async function ensureCoderVscodeSettingsFile(projectPath: string): Promise<InitializationStatus> {
|
|
21
23
|
const [fieldPath, nextEntries] = resolveDefaultCoderVscodeSettingsEntry();
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
const { status } = await mergeStringRecordJsonFile({
|
|
24
26
|
projectPath,
|
|
25
27
|
relativeFilePath: VSCODE_SETTINGS_FILE_PATH,
|
|
26
28
|
fieldPath,
|
|
27
29
|
nextEntries,
|
|
28
30
|
ensureParentDirectoryPath: VSCODE_DIRECTORY_PATH,
|
|
29
31
|
});
|
|
32
|
+
|
|
33
|
+
return status;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mkdir, stat } from 'fs/promises';
|
|
1
|
+
import { mkdir, readdir, stat } from 'fs/promises';
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import type { InitializationStatus } from './boilerplateTemplates';
|
|
4
4
|
|
|
@@ -22,6 +22,25 @@ export async function ensureDirectory(
|
|
|
22
22
|
return 'unchanged';
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Checks whether a project-relative directory is missing or contains no entries.
|
|
27
|
+
*
|
|
28
|
+
* @private internal utility of `coder init` command
|
|
29
|
+
*/
|
|
30
|
+
export async function isDirectoryEmpty(projectPath: string, relativeDirectoryPath: string): Promise<boolean> {
|
|
31
|
+
const directoryPath = join(projectPath, relativeDirectoryPath);
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
return (await readdir(directoryPath)).length === 0;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (isNodeJsErrorWithCode(error, 'ENOENT')) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
25
44
|
/**
|
|
26
45
|
* Checks whether a path exists and is a directory.
|
|
27
46
|
*/
|
|
@@ -33,4 +52,11 @@ async function isExistingDirectory(path: string): Promise<boolean> {
|
|
|
33
52
|
}
|
|
34
53
|
}
|
|
35
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Checks whether a caught value is a Node.js error with the given error code.
|
|
57
|
+
*/
|
|
58
|
+
function isNodeJsErrorWithCode(error: unknown, code: string): error is NodeJS.ErrnoException {
|
|
59
|
+
return typeof error === 'object' && error !== null && 'code' in error && error.code === code;
|
|
60
|
+
}
|
|
61
|
+
|
|
36
62
|
// Note: [🟡] Code for coder init directory creation [ensureDirectory](src/cli/cli-commands/coder/ensureDirectory.ts) should never be published outside of `@promptbook/cli`
|
|
@@ -1,17 +1,78 @@
|
|
|
1
|
+
import { AGENTS_FILE_PATH } from './agentsFile';
|
|
1
2
|
import { DEFAULT_BOILERPLATE_COUNT_OPTION_VALUE } from './boilerplateCount';
|
|
3
|
+
import { COMMON_PROMPT_TEMPLATE_FILE_PATH } from './boilerplateTemplates';
|
|
4
|
+
import { CODER_DEVELOPER_AGENT_FILE_PATH } from './ensureCoderDeveloperAgentFile';
|
|
5
|
+
import { formatDisplayPath } from './formatDisplayPath';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Name of the npm script which `ptbk coder run` uses to verify the project.
|
|
9
|
+
*/
|
|
10
|
+
const CODER_TEST_SCRIPT_NAME = 'test-for-ptbk-coder';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* One npm script initialized by `ptbk coder init`.
|
|
14
|
+
*/
|
|
15
|
+
type CoderPackageJsonScriptDefinition = {
|
|
16
|
+
/**
|
|
17
|
+
* Name of the npm script.
|
|
18
|
+
*/
|
|
19
|
+
readonly scriptName: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Shell command of the npm script.
|
|
23
|
+
*/
|
|
24
|
+
readonly scriptCommand: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Project-relative paths of the artifacts the command points at.
|
|
28
|
+
*
|
|
29
|
+
* They are created only together with the script itself, never for a script the project already defines.
|
|
30
|
+
*/
|
|
31
|
+
readonly referencedArtifactPaths: ReadonlyArray<string>;
|
|
32
|
+
};
|
|
2
33
|
|
|
3
34
|
/**
|
|
4
35
|
* Default npm scripts initialized by `ptbk coder init`.
|
|
36
|
+
*
|
|
37
|
+
* Note: Using NPX because `ptbk` can be installed globally or locally, and NPX will resolve it correctly in either case.
|
|
5
38
|
*/
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
39
|
+
const DEFAULT_CODER_PACKAGE_JSON_SCRIPT_DEFINITIONS: ReadonlyArray<CoderPackageJsonScriptDefinition> = [
|
|
40
|
+
{
|
|
41
|
+
scriptName: 'coder:generate-boilerplates',
|
|
42
|
+
scriptCommand: `npx ptbk coder generate-boilerplates --count ${DEFAULT_BOILERPLATE_COUNT_OPTION_VALUE} --template ${formatCoderScriptFilePath(
|
|
43
|
+
COMMON_PROMPT_TEMPLATE_FILE_PATH,
|
|
44
|
+
)}`,
|
|
45
|
+
referencedArtifactPaths: [COMMON_PROMPT_TEMPLATE_FILE_PATH],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
scriptName: 'coder:add',
|
|
49
|
+
scriptCommand: `npx ptbk coder add --template ${formatCoderScriptFilePath(COMMON_PROMPT_TEMPLATE_FILE_PATH)}`,
|
|
50
|
+
referencedArtifactPaths: [COMMON_PROMPT_TEMPLATE_FILE_PATH],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
scriptName: 'coder:run',
|
|
54
|
+
scriptCommand: [
|
|
55
|
+
'npx ptbk coder run --harness openai-codex --model gpt-5.6-terra --thinking-level max',
|
|
56
|
+
`--agent ${formatDisplayPath(CODER_DEVELOPER_AGENT_FILE_PATH)}`,
|
|
57
|
+
`--context ${formatDisplayPath(AGENTS_FILE_PATH)}`,
|
|
58
|
+
`--test "npm run ${CODER_TEST_SCRIPT_NAME}" --test-before yes-and-fix`,
|
|
59
|
+
].join(' '),
|
|
60
|
+
referencedArtifactPaths: [CODER_DEVELOPER_AGENT_FILE_PATH, AGENTS_FILE_PATH],
|
|
61
|
+
},
|
|
62
|
+
// { scriptName: 'coder:find-refactor-candidates', scriptCommand: 'npx ptbk coder find-refactor-candidates', referencedArtifactPaths: [] },
|
|
63
|
+
{
|
|
64
|
+
scriptName: 'coder:verify',
|
|
65
|
+
scriptCommand: 'npx ptbk coder verify',
|
|
66
|
+
referencedArtifactPaths: [],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
// Note: The verification command of `coder:run` is a project-owned script, so every project can decide
|
|
70
|
+
// what "verified" means without touching the `coder:run` script itself
|
|
71
|
+
scriptName: CODER_TEST_SCRIPT_NAME,
|
|
72
|
+
scriptCommand: 'npm test',
|
|
73
|
+
referencedArtifactPaths: [],
|
|
74
|
+
},
|
|
75
|
+
];
|
|
15
76
|
|
|
16
77
|
/**
|
|
17
78
|
* Lists the default npm scripts initialized by `ptbk coder init`.
|
|
@@ -19,7 +80,35 @@ const DEFAULT_CODER_PACKAGE_JSON_SCRIPTS = {
|
|
|
19
80
|
* @private internal utility of `coder init` command
|
|
20
81
|
*/
|
|
21
82
|
export function getDefaultCoderPackageJsonScripts(): Readonly<Record<string, string>> {
|
|
22
|
-
return
|
|
83
|
+
return Object.fromEntries(
|
|
84
|
+
DEFAULT_CODER_PACKAGE_JSON_SCRIPT_DEFINITIONS.map(({ scriptName, scriptCommand }) => [
|
|
85
|
+
scriptName,
|
|
86
|
+
scriptCommand,
|
|
87
|
+
]),
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Collects the project-relative artifact paths referenced by the given default coder scripts.
|
|
93
|
+
*
|
|
94
|
+
* @private internal utility of `coder init` command
|
|
95
|
+
*/
|
|
96
|
+
export function resolveCoderPackageJsonScriptReferencedArtifactPaths(
|
|
97
|
+
scriptNames: ReadonlyArray<string>,
|
|
98
|
+
): ReadonlySet<string> {
|
|
99
|
+
return new Set(
|
|
100
|
+
DEFAULT_CODER_PACKAGE_JSON_SCRIPT_DEFINITIONS.filter(({ scriptName }) => scriptNames.includes(scriptName))
|
|
101
|
+
.map(({ referencedArtifactPaths }) => referencedArtifactPaths)
|
|
102
|
+
.flat(),
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Formats one project-relative path as an explicitly project-rooted path usable inside a shell command.
|
|
108
|
+
*/
|
|
109
|
+
function formatCoderScriptFilePath(relativeFilePath: string): string {
|
|
110
|
+
return `./${formatDisplayPath(relativeFilePath)}`;
|
|
23
111
|
}
|
|
24
112
|
|
|
25
113
|
// Note: [🟡] Code for coder init package scripts [getDefaultCoderPackageJsonScripts](src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts) should never be published outside of `@promptbook/cli`
|
|
114
|
+
// Note: [💞] Ignore a discrepancy between file name and exported helper names
|
|
@@ -13,16 +13,17 @@ import { handleActionErrors } from '../common/handleActionErrors';
|
|
|
13
13
|
import { $ensureHarnessInstallations } from '../common/harness/$ensureHarnessInstallations';
|
|
14
14
|
import { getHarnessDefinition } from '../common/harness/HarnessDefinition';
|
|
15
15
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
addQuestionsOption,
|
|
17
|
+
normalizeQuestionsCliOptions,
|
|
18
|
+
QUESTIONS_DESCRIPTION,
|
|
19
|
+
type QuestionsCliOptions,
|
|
20
|
+
} from '../common/questionsCliOptions';
|
|
20
21
|
import type { PromptRunnerHarnessName } from '../common/promptRunnerCliOptions';
|
|
21
|
-
import { AGENT_CODING_FILE_PATH } from './agentCodingFile';
|
|
22
22
|
import { AGENTS_FILE_PATH } from './agentsFile';
|
|
23
23
|
import { DEFAULT_BOILERPLATE_COUNT } from './boilerplateCount';
|
|
24
|
-
import { getDefaultCoderProjectPromptTemplateDefinitions } from './boilerplateTemplates';
|
|
24
|
+
import { getDefaultCoderProjectPromptTemplateDefinitions, PROMPTS_DIRECTORY_PATH } from './boilerplateTemplates';
|
|
25
25
|
import { CODER_DEVELOPER_AGENT_FILE_PATH } from './ensureCoderDeveloperAgentFile';
|
|
26
|
+
import { isDirectoryEmpty } from './ensureDirectory';
|
|
26
27
|
import { formatDisplayPath } from './formatDisplayPath';
|
|
27
28
|
import { generatePromptBoilerplate } from './generate-boilerplates';
|
|
28
29
|
import { initializeCoderProjectConfiguration } from './initializeCoderProjectConfiguration';
|
|
@@ -61,33 +62,37 @@ export function $initializeCoderInitCommand(program: Program): $side_effect {
|
|
|
61
62
|
${block(listDefaultCoderProjectPromptTemplateDisplayPaths())}
|
|
62
63
|
- ${CODER_DEVELOPER_AGENT_FILE_PATH}
|
|
63
64
|
- ${AGENTS_FILE_PATH}
|
|
64
|
-
- ${AGENT_CODING_FILE_PATH}
|
|
65
65
|
- .gitignore with local artifacts from every supported harness
|
|
66
66
|
- package.json
|
|
67
67
|
- .vscode/settings.json
|
|
68
68
|
|
|
69
|
+
Never overwrites what the project already owns:
|
|
70
|
+
- Existing package.json scripts and .vscode/settings.json settings are kept, only missing ones are added
|
|
71
|
+
- Files referenced by a script, like the agent and context of coder:run, are created only together
|
|
72
|
+
with the script which references them
|
|
73
|
+
|
|
69
74
|
Ensures required coding-agent environment variables in .env:
|
|
70
75
|
- CODING_AGENT_GIT_NAME
|
|
71
76
|
- CODING_AGENT_GIT_EMAIL
|
|
72
77
|
- CODING_AGENT_GIT_SIGNING_KEY
|
|
73
78
|
|
|
74
|
-
Checks that the coding harnesses are installed and up to date unless \`--no-
|
|
79
|
+
Checks that the coding harnesses are installed and up to date unless \`--no-questions\` is used:
|
|
75
80
|
${block(listCheckedHarnessLabels())}
|
|
76
81
|
|
|
77
82
|
${block(CODER_GIT_SYNC_DESCRIPTION)}
|
|
83
|
+
|
|
84
|
+
${block(QUESTIONS_DESCRIPTION)}
|
|
78
85
|
`,
|
|
79
86
|
),
|
|
80
87
|
);
|
|
81
88
|
|
|
82
89
|
addCoderGitSyncOptions(command);
|
|
83
|
-
|
|
90
|
+
addQuestionsOption(command);
|
|
84
91
|
|
|
85
92
|
command.action(
|
|
86
93
|
handleActionErrors(async (cliOptions) => {
|
|
87
94
|
const gitSync = normalizeCoderGitSyncCliOptions(cliOptions as CoderGitSyncCliOptions);
|
|
88
|
-
const
|
|
89
|
-
cliOptions as HarnessUpdateCliOptions,
|
|
90
|
-
);
|
|
95
|
+
const questionsOptions = normalizeQuestionsCliOptions(cliOptions as QuestionsCliOptions);
|
|
91
96
|
const projectPath = process.cwd();
|
|
92
97
|
|
|
93
98
|
// Note: Import the git synchronization dynamically to keep the CLI fast for runs without `--commit`
|
|
@@ -96,10 +101,14 @@ export function $initializeCoderInitCommand(program: Program): $side_effect {
|
|
|
96
101
|
);
|
|
97
102
|
|
|
98
103
|
const commitScope = await $startCoderGitSync({ gitSync, projectPath });
|
|
104
|
+
const isPromptsDirectoryEmpty = await isDirectoryEmpty(projectPath, PROMPTS_DIRECTORY_PATH);
|
|
99
105
|
|
|
100
106
|
const summary = await initializeCoderProjectConfiguration(projectPath);
|
|
101
107
|
printInitializationSummary(summary);
|
|
102
|
-
|
|
108
|
+
|
|
109
|
+
if (isPromptsDirectoryEmpty) {
|
|
110
|
+
await generatePromptBoilerplate({ projectPath, boilerplateCount: DEFAULT_BOILERPLATE_COUNT });
|
|
111
|
+
}
|
|
103
112
|
|
|
104
113
|
await $commitCoderChanges({
|
|
105
114
|
gitSync,
|
|
@@ -107,7 +116,7 @@ export function $initializeCoderInitCommand(program: Program): $side_effect {
|
|
|
107
116
|
commitMessage: 'Initialize Promptbook Coder',
|
|
108
117
|
});
|
|
109
118
|
|
|
110
|
-
await $ensureHarnessInstallations(CODER_INIT_CHECKED_HARNESS_NAMES,
|
|
119
|
+
await $ensureHarnessInstallations(CODER_INIT_CHECKED_HARNESS_NAMES, questionsOptions);
|
|
111
120
|
}),
|
|
112
121
|
);
|
|
113
122
|
}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AGENTS_FILE_PATH, getDefaultCoderAgentsFileContent } from './agentsFile';
|
|
3
|
-
import type { EnsuredCoderPromptTemplateFile, InitializationStatus } from './boilerplateTemplates';
|
|
1
|
+
import type { InitializationStatus } from './boilerplateTemplates';
|
|
4
2
|
import {
|
|
5
|
-
ensureDefaultCoderPromptTemplateFiles,
|
|
6
3
|
PROMPTS_DIRECTORY_PATH,
|
|
7
4
|
PROMPTS_DONE_DIRECTORY_PATH,
|
|
8
5
|
PROMPTS_TEMPLATES_DIRECTORY_PATH,
|
|
9
6
|
} from './boilerplateTemplates';
|
|
10
|
-
import {
|
|
7
|
+
import type { EnsuredCoderReferencedArtifact } from './coderReferencedArtifacts';
|
|
8
|
+
import { ensureCoderReferencedArtifacts } from './coderReferencedArtifacts';
|
|
9
|
+
import { CODER_AGENTS_DIRECTORY_PATH } from './ensureCoderDeveloperAgentFile';
|
|
11
10
|
import { ensureCoderEnvFile } from './ensureCoderEnvFile';
|
|
12
11
|
import { ensureCoderGitignoreFile } from './ensureCoderGitignoreFile';
|
|
13
|
-
import { ensureCoderMarkdownFile } from './ensureCoderMarkdownFile';
|
|
14
12
|
import { ensureCoderPackageJsonFile } from './ensureCoderPackageJsonFile';
|
|
15
13
|
import { ensureCoderVscodeSettingsFile } from './ensureCoderVscodeSettingsFile';
|
|
16
14
|
import { ensureDirectory } from './ensureDirectory';
|
|
15
|
+
import { resolveCoderPackageJsonScriptReferencedArtifactPaths } from './getDefaultCoderPackageJsonScripts';
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
* Result summary returned after coder configuration initialization.
|
|
@@ -24,58 +23,50 @@ export type CoderInitializationSummary = {
|
|
|
24
23
|
readonly promptsDirectoryStatus: InitializationStatus;
|
|
25
24
|
readonly promptsDoneDirectoryStatus: InitializationStatus;
|
|
26
25
|
readonly promptsTemplatesDirectoryStatus: InitializationStatus;
|
|
27
|
-
readonly promptTemplateFileStatuses: ReadonlyArray<EnsuredCoderPromptTemplateFile>;
|
|
28
26
|
readonly agentsDirectoryStatus: InitializationStatus;
|
|
29
|
-
readonly developerAgentFileStatus: InitializationStatus;
|
|
30
|
-
readonly agentsFileStatus: InitializationStatus;
|
|
31
|
-
readonly agentCodingFileStatus: InitializationStatus;
|
|
32
27
|
readonly envFileStatus: InitializationStatus;
|
|
33
28
|
readonly gitignoreFileStatus: InitializationStatus;
|
|
34
29
|
readonly packageJsonFileStatus: InitializationStatus;
|
|
35
30
|
readonly vscodeSettingsFileStatus: InitializationStatus;
|
|
31
|
+
readonly addedPackageJsonScriptNames: ReadonlyArray<string>;
|
|
32
|
+
readonly referencedArtifactStatuses: ReadonlyArray<EnsuredCoderReferencedArtifact>;
|
|
36
33
|
readonly initializedEnvVariableNames: ReadonlyArray<string>;
|
|
37
34
|
};
|
|
38
35
|
|
|
39
36
|
/**
|
|
40
37
|
* Creates or updates all coder configuration artifacts required in the current project.
|
|
41
38
|
*
|
|
39
|
+
* Nothing the project already owns is ever overwritten - existing scripts, settings and files are kept as they are,
|
|
40
|
+
* and the artifacts they would reference are created only together with the scripts which actually reference them.
|
|
41
|
+
*
|
|
42
42
|
* @private internal utility of `coder init` command
|
|
43
43
|
*/
|
|
44
44
|
export async function initializeCoderProjectConfiguration(projectPath: string): Promise<CoderInitializationSummary> {
|
|
45
45
|
const promptsDirectoryStatus = await ensureDirectory(projectPath, PROMPTS_DIRECTORY_PATH);
|
|
46
46
|
const promptsDoneDirectoryStatus = await ensureDirectory(projectPath, PROMPTS_DONE_DIRECTORY_PATH);
|
|
47
47
|
const promptsTemplatesDirectoryStatus = await ensureDirectory(projectPath, PROMPTS_TEMPLATES_DIRECTORY_PATH);
|
|
48
|
-
const promptTemplateFileStatuses = await ensureDefaultCoderPromptTemplateFiles(projectPath);
|
|
49
48
|
const agentsDirectoryStatus = await ensureDirectory(projectPath, CODER_AGENTS_DIRECTORY_PATH);
|
|
50
|
-
const developerAgentFileStatus = await ensureCoderDeveloperAgentFile(projectPath);
|
|
51
|
-
const agentsFileStatus = await ensureCoderMarkdownFile(
|
|
52
|
-
projectPath,
|
|
53
|
-
AGENTS_FILE_PATH,
|
|
54
|
-
getDefaultCoderAgentsFileContent(),
|
|
55
|
-
);
|
|
56
|
-
const agentCodingFileStatus = await ensureCoderMarkdownFile(
|
|
57
|
-
projectPath,
|
|
58
|
-
AGENT_CODING_FILE_PATH,
|
|
59
|
-
getDefaultCoderAgentCodingFileContent(),
|
|
60
|
-
);
|
|
61
49
|
const { envFileStatus, initializedEnvVariableNames } = await ensureCoderEnvFile(projectPath);
|
|
62
50
|
const gitignoreFileStatus = await ensureCoderGitignoreFile(projectPath);
|
|
63
|
-
const packageJsonFileStatus
|
|
51
|
+
const { status: packageJsonFileStatus, addedEntryKeys: addedPackageJsonScriptNames } =
|
|
52
|
+
await ensureCoderPackageJsonFile(projectPath);
|
|
64
53
|
const vscodeSettingsFileStatus = await ensureCoderVscodeSettingsFile(projectPath);
|
|
54
|
+
const referencedArtifactStatuses = await ensureCoderReferencedArtifacts(
|
|
55
|
+
projectPath,
|
|
56
|
+
resolveCoderPackageJsonScriptReferencedArtifactPaths(addedPackageJsonScriptNames),
|
|
57
|
+
);
|
|
65
58
|
|
|
66
59
|
return {
|
|
67
60
|
promptsDirectoryStatus,
|
|
68
61
|
promptsDoneDirectoryStatus,
|
|
69
62
|
promptsTemplatesDirectoryStatus,
|
|
70
|
-
promptTemplateFileStatuses,
|
|
71
63
|
agentsDirectoryStatus,
|
|
72
|
-
developerAgentFileStatus,
|
|
73
|
-
agentsFileStatus,
|
|
74
|
-
agentCodingFileStatus,
|
|
75
64
|
envFileStatus,
|
|
76
65
|
gitignoreFileStatus,
|
|
77
66
|
packageJsonFileStatus,
|
|
78
67
|
vscodeSettingsFileStatus,
|
|
68
|
+
addedPackageJsonScriptNames,
|
|
69
|
+
referencedArtifactStatuses,
|
|
79
70
|
initializedEnvVariableNames,
|
|
80
71
|
};
|
|
81
72
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
normalizePromptRunnerSelectionCliOptions,
|
|
12
12
|
PROMPT_RUNNER_DESCRIPTION,
|
|
13
13
|
} from '../common/promptRunnerCliOptions';
|
|
14
|
+
import { addCoderAgentOption, type CoderAgentCliOptions } from './agentCliOptions';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Initializes `coder list` command for Promptbook CLI utilities.
|
|
@@ -30,35 +31,46 @@ export function $initializeCoderListCommand(program: Program): $side_effect {
|
|
|
30
31
|
Features:
|
|
31
32
|
- Lists only ready, fully authored prompts
|
|
32
33
|
- Groups prompts from highest to lowest priority
|
|
33
|
-
- Optional --harness and --
|
|
34
|
+
- Optional --harness, --model and --agent filters show only prompts compatible with that selection
|
|
34
35
|
- Does not start a coding harness or modify prompt files
|
|
35
36
|
`),
|
|
36
37
|
);
|
|
37
38
|
|
|
38
39
|
addPromptRunnerSelectionOptions(command);
|
|
40
|
+
addCoderAgentOption(command);
|
|
39
41
|
addPromptPriorityOptions(command);
|
|
40
42
|
|
|
41
43
|
command.action(
|
|
42
44
|
handleActionErrors(async (cliOptions) => {
|
|
43
45
|
const {
|
|
46
|
+
agent,
|
|
44
47
|
priority,
|
|
45
48
|
minPriority: minimumPriority,
|
|
46
49
|
maxPriority: maximumPriority,
|
|
47
50
|
} = cliOptions as {
|
|
51
|
+
readonly agent?: string;
|
|
48
52
|
readonly priority?: number;
|
|
49
53
|
readonly minPriority?: number;
|
|
50
54
|
readonly maxPriority?: number;
|
|
51
|
-
} & PromptRunnerSelectionCliOptions;
|
|
55
|
+
} & PromptRunnerSelectionCliOptions & CoderAgentCliOptions;
|
|
52
56
|
const runnerOptions = normalizePromptRunnerSelectionCliOptions(
|
|
53
57
|
cliOptions as PromptRunnerSelectionCliOptions,
|
|
54
58
|
{ isAgentRequired: false },
|
|
55
59
|
);
|
|
60
|
+
const resolvedCoderAgentBook =
|
|
61
|
+
agent === undefined
|
|
62
|
+
? undefined
|
|
63
|
+
: await (await import('../../../../scripts/run-codex-prompts/common/resolveCoderAgent'))
|
|
64
|
+
.resolveCoderAgentBook(agent, process.cwd());
|
|
56
65
|
const promptRunnerIdentity =
|
|
57
|
-
runnerOptions.agentName === undefined &&
|
|
66
|
+
runnerOptions.agentName === undefined &&
|
|
67
|
+
runnerOptions.model === undefined &&
|
|
68
|
+
resolvedCoderAgentBook === undefined
|
|
58
69
|
? undefined
|
|
59
70
|
: {
|
|
60
71
|
harnessName: runnerOptions.agentName,
|
|
61
72
|
modelName: runnerOptions.model,
|
|
73
|
+
agentReferences: resolvedCoderAgentBook?.agentReferences,
|
|
62
74
|
};
|
|
63
75
|
|
|
64
76
|
// Note: Import dynamically to avoid loading prompt parsing dependencies until this command is used.
|