@promptbook/cli 0.112.0-123 → 0.112.0-125
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/README.md +14 -14
- package/agents/default/developer.book +23 -0
- package/apps/agents-server/src/app/api/scrape/route.ts +18 -0
- package/apps/agents-server/src/tools/createAgentProgressTools.ts +6 -4
- package/apps/agents-server/src/utils/assertSafeUrl.ts +136 -0
- package/apps/agents-server/src/utils/authenticateUser.ts +2 -1
- package/apps/agents-server/src/utils/getCurrentUser.ts +2 -1
- package/apps/agents-server/src/utils/isAdminPasswordEqual.ts +28 -0
- package/apps/agents-server/src/utils/isUserGlobalAdmin.ts +3 -1
- package/apps/agents-server/src/utils/userChat/createRunUserChatJobPersistenceController.ts +21 -0
- package/apps/agents-server/src/utils/userChat/retryUserChatJob.ts +4 -0
- package/apps/agents-server/src/utils/userChat/userChatMessageLifecycle.ts +2 -0
- package/apps/agents-server/src/utils/userChat/userChatProgressCard.ts +288 -0
- package/esm/index.es.js +78 -7
- package/esm/index.es.js.map +1 -1
- package/esm/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.d.ts +25 -0
- package/esm/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +2 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.ts +79 -0
- package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +1 -1
- package/src/cli/cli-commands/coder/init.ts +2 -0
- package/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.ts +10 -0
- package/src/cli/cli-commands/coder/printInitializationSummary.ts +3 -0
- package/src/other/templates/getTemplatesPipelineCollection.ts +871 -790
- package/src/version.ts +2 -2
- package/src/versions.txt +1 -0
- package/umd/index.umd.js +77 -6
- package/umd/index.umd.js.map +1 -1
- package/umd/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.d.ts +25 -0
- package/umd/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +2 -0
- package/umd/src/version.d.ts +1 -1
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import type { ChatMessage, ToolCall } from '@promptbook-local/types';
|
|
2
|
+
import { ASSISTANT_PREPARATION_TOOL_CALL_NAME } from '../../../../../src/types/ToolCall';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Prefix used by automatic durable chat progress items.
|
|
6
|
+
*
|
|
7
|
+
* @private internal helper for Agents Server durable chat progress
|
|
8
|
+
*/
|
|
9
|
+
const AUTOMATIC_PROGRESS_ITEM_ID_PREFIX = 'user-chat-job-progress-';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Shared title for progress cards owned by the durable chat runner.
|
|
13
|
+
*
|
|
14
|
+
* @private internal helper for Agents Server durable chat progress
|
|
15
|
+
*/
|
|
16
|
+
const AUTOMATIC_PROGRESS_TITLE = 'Agent Progress';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Tool names that are already represented by the progress card itself.
|
|
20
|
+
*
|
|
21
|
+
* @private internal helper for Agents Server durable chat progress
|
|
22
|
+
*/
|
|
23
|
+
const HIDDEN_PROGRESS_TOOL_NAMES = new Set(['agent_progress']);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Options for building an automatic running progress card.
|
|
27
|
+
*
|
|
28
|
+
* @private internal helper for Agents Server durable chat progress
|
|
29
|
+
*/
|
|
30
|
+
type CreateRunningUserChatProgressCardOptions = {
|
|
31
|
+
readonly currentProgressCard?: ChatMessage['progressCard'];
|
|
32
|
+
readonly content: string;
|
|
33
|
+
readonly toolCalls?: ReadonlyArray<ToolCall>;
|
|
34
|
+
readonly updatedAt: NonNullable<ChatMessage['progressCard']>['updatedAt'];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates the initial real progress payload shown before an agent runner starts.
|
|
39
|
+
*
|
|
40
|
+
* @param updatedAt - Timestamp used for the progress-card update marker.
|
|
41
|
+
* @returns Structured progress card for a queued assistant placeholder.
|
|
42
|
+
*
|
|
43
|
+
* @private internal helper for Agents Server durable chat progress
|
|
44
|
+
*/
|
|
45
|
+
export function createQueuedUserChatProgressCard(
|
|
46
|
+
updatedAt: NonNullable<ChatMessage['progressCard']>['updatedAt'],
|
|
47
|
+
): NonNullable<ChatMessage['progressCard']> {
|
|
48
|
+
return {
|
|
49
|
+
title: AUTOMATIC_PROGRESS_TITLE,
|
|
50
|
+
now: 'Your message is queued for the agent runner.',
|
|
51
|
+
next: 'The runner will prepare the agent context and start generating the response.',
|
|
52
|
+
items: [
|
|
53
|
+
{
|
|
54
|
+
id: `${AUTOMATIC_PROGRESS_ITEM_ID_PREFIX}queued`,
|
|
55
|
+
text: 'Request added to the chat queue',
|
|
56
|
+
status: 'completed',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: `${AUTOMATIC_PROGRESS_ITEM_ID_PREFIX}waiting-for-runner`,
|
|
60
|
+
text: 'Waiting for an available agent runner',
|
|
61
|
+
status: 'pending',
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
updatedAt,
|
|
65
|
+
isVisible: true,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Creates or refreshes the automatic progress card for a running durable chat job.
|
|
71
|
+
*
|
|
72
|
+
* A model-authored `agent_progress` card is preserved once it takes over, so the
|
|
73
|
+
* durable runner does not overwrite more specific progress supplied by the agent.
|
|
74
|
+
*
|
|
75
|
+
* @param options - Current message state and streamed runtime details.
|
|
76
|
+
* @returns Progress card that should be stored on the assistant message.
|
|
77
|
+
*
|
|
78
|
+
* @private internal helper for Agents Server durable chat progress
|
|
79
|
+
*/
|
|
80
|
+
export function createRunningUserChatProgressCard(
|
|
81
|
+
options: CreateRunningUserChatProgressCardOptions,
|
|
82
|
+
): NonNullable<ChatMessage['progressCard']> {
|
|
83
|
+
if (shouldPreserveModelProgressCard(options.currentProgressCard)) {
|
|
84
|
+
return options.currentProgressCard;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const visibleToolCalls = (options.toolCalls || []).filter((toolCall) => !HIDDEN_PROGRESS_TOOL_NAMES.has(toolCall.name));
|
|
88
|
+
const hasVisibleToolCalls = visibleToolCalls.length > 0;
|
|
89
|
+
const hasStartedWriting = options.content.trim().length > 0;
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
title: AUTOMATIC_PROGRESS_TITLE,
|
|
93
|
+
now: resolveRunningProgressNowText({
|
|
94
|
+
hasStartedWriting,
|
|
95
|
+
visibleToolCalls,
|
|
96
|
+
}),
|
|
97
|
+
next: hasVisibleToolCalls
|
|
98
|
+
? 'Tool results will be incorporated into the final response.'
|
|
99
|
+
: 'The final answer will replace this progress view when generation finishes.',
|
|
100
|
+
items: [
|
|
101
|
+
{
|
|
102
|
+
id: `${AUTOMATIC_PROGRESS_ITEM_ID_PREFIX}queued`,
|
|
103
|
+
text: 'Request added to the chat queue',
|
|
104
|
+
status: 'completed',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: `${AUTOMATIC_PROGRESS_ITEM_ID_PREFIX}runtime-prepared`,
|
|
108
|
+
text: 'Agent context and runtime tools prepared',
|
|
109
|
+
status: 'completed',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: `${AUTOMATIC_PROGRESS_ITEM_ID_PREFIX}generating-response`,
|
|
113
|
+
text: hasStartedWriting ? 'Response text has started streaming' : 'Generating the assistant response',
|
|
114
|
+
status: hasStartedWriting ? 'completed' : 'pending',
|
|
115
|
+
},
|
|
116
|
+
...visibleToolCalls.map(createToolCallProgressItem),
|
|
117
|
+
],
|
|
118
|
+
updatedAt: options.updatedAt,
|
|
119
|
+
isVisible: true,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Returns true when the existing progress card should be treated as model-authored.
|
|
125
|
+
*
|
|
126
|
+
* @param progressCard - Existing progress-card payload on the assistant message.
|
|
127
|
+
* @returns Whether automatic runner progress should leave the card untouched.
|
|
128
|
+
*
|
|
129
|
+
* @private internal helper for Agents Server durable chat progress
|
|
130
|
+
*/
|
|
131
|
+
function shouldPreserveModelProgressCard(
|
|
132
|
+
progressCard: ChatMessage['progressCard'],
|
|
133
|
+
): progressCard is NonNullable<ChatMessage['progressCard']> {
|
|
134
|
+
if (!progressCard || progressCard.isVisible === false) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (progressCard.title !== AUTOMATIC_PROGRESS_TITLE) {
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return (progressCard.items || []).some((item) => !item.id.startsWith(AUTOMATIC_PROGRESS_ITEM_ID_PREFIX));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Resolves the current-work copy for a running progress card.
|
|
147
|
+
*
|
|
148
|
+
* @param options - Running output and tool-call state.
|
|
149
|
+
* @returns Concise progress-card text.
|
|
150
|
+
*
|
|
151
|
+
* @private internal helper for Agents Server durable chat progress
|
|
152
|
+
*/
|
|
153
|
+
function resolveRunningProgressNowText(options: {
|
|
154
|
+
readonly hasStartedWriting: boolean;
|
|
155
|
+
readonly visibleToolCalls: ReadonlyArray<ToolCall>;
|
|
156
|
+
}): string {
|
|
157
|
+
if (options.visibleToolCalls.length > 0) {
|
|
158
|
+
return `Using ${formatToolCallList(options.visibleToolCalls)}.`;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (options.hasStartedWriting) {
|
|
162
|
+
return 'The agent has started writing the response.';
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return 'The agent runtime is prepared and the model is generating the response.';
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Creates one checklist item from an observed tool-call snapshot.
|
|
170
|
+
*
|
|
171
|
+
* @param toolCall - Tool call observed while the model is running.
|
|
172
|
+
* @param index - Position of the tool call in the current snapshot.
|
|
173
|
+
* @returns Progress item for the tool action.
|
|
174
|
+
*
|
|
175
|
+
* @private internal helper for Agents Server durable chat progress
|
|
176
|
+
*/
|
|
177
|
+
function createToolCallProgressItem(toolCall: ToolCall, index: number): NonNullable<ChatMessage['progressCard']>['items'][number] {
|
|
178
|
+
return {
|
|
179
|
+
id: `${AUTOMATIC_PROGRESS_ITEM_ID_PREFIX}tool-${resolveToolCallProgressId(toolCall, index)}`,
|
|
180
|
+
text: resolveToolCallProgressText(toolCall),
|
|
181
|
+
status: isToolCallComplete(toolCall) ? 'completed' : 'pending',
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Creates a stable progress item id from one tool-call snapshot.
|
|
187
|
+
*
|
|
188
|
+
* @param toolCall - Tool call observed while the model is running.
|
|
189
|
+
* @param index - Position of the tool call in the current snapshot.
|
|
190
|
+
* @returns Stable id suffix for the rendered progress item.
|
|
191
|
+
*
|
|
192
|
+
* @private internal helper for Agents Server durable chat progress
|
|
193
|
+
*/
|
|
194
|
+
function resolveToolCallProgressId(toolCall: ToolCall, index: number): string {
|
|
195
|
+
const rawId = toolCall.idempotencyKey || `${toolCall.name}-${index}`;
|
|
196
|
+
return rawId
|
|
197
|
+
.toLowerCase()
|
|
198
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
199
|
+
.replace(/^-+|-+$/g, '')
|
|
200
|
+
.slice(0, 80);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Resolves user-facing progress text for one tool-call snapshot.
|
|
205
|
+
*
|
|
206
|
+
* @param toolCall - Tool call observed while the model is running.
|
|
207
|
+
* @returns Concise description of the action or result.
|
|
208
|
+
*
|
|
209
|
+
* @private internal helper for Agents Server durable chat progress
|
|
210
|
+
*/
|
|
211
|
+
function resolveToolCallProgressText(toolCall: ToolCall): string {
|
|
212
|
+
const toolTitle = formatToolName(toolCall.name);
|
|
213
|
+
const latestLog = [...(toolCall.logs || [])].reverse().find((log) => log.title || log.message);
|
|
214
|
+
|
|
215
|
+
if (toolCall.name === ASSISTANT_PREPARATION_TOOL_CALL_NAME) {
|
|
216
|
+
return 'Preparing assistant runtime';
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (Array.isArray(toolCall.errors) && toolCall.errors.length > 0) {
|
|
220
|
+
return `${toolTitle} reported an error`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (isToolCallComplete(toolCall)) {
|
|
224
|
+
return `${toolTitle} completed`;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (latestLog) {
|
|
228
|
+
const logText = latestLog.title || latestLog.message;
|
|
229
|
+
return `${toolTitle}: ${logText}`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return `${toolTitle} is running`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Formats a short comma-separated list of active tools.
|
|
237
|
+
*
|
|
238
|
+
* @param toolCalls - Visible tool calls in the current stream snapshot.
|
|
239
|
+
* @returns Human-readable tool list.
|
|
240
|
+
*
|
|
241
|
+
* @private internal helper for Agents Server durable chat progress
|
|
242
|
+
*/
|
|
243
|
+
function formatToolCallList(toolCalls: ReadonlyArray<ToolCall>): string {
|
|
244
|
+
const uniqueToolNames = [...new Set(toolCalls.map((toolCall) => formatToolName(toolCall.name)))];
|
|
245
|
+
|
|
246
|
+
if (uniqueToolNames.length === 1) {
|
|
247
|
+
return uniqueToolNames[0]!;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const finalToolName = uniqueToolNames[uniqueToolNames.length - 1]!;
|
|
251
|
+
return `${uniqueToolNames.slice(0, -1).join(', ')} and ${finalToolName}`;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Converts one technical tool name into compact user-facing copy.
|
|
256
|
+
*
|
|
257
|
+
* @param toolName - Tool function name.
|
|
258
|
+
* @returns Human-readable tool name.
|
|
259
|
+
*
|
|
260
|
+
* @private internal helper for Agents Server durable chat progress
|
|
261
|
+
*/
|
|
262
|
+
function formatToolName(toolName: string): string {
|
|
263
|
+
return toolName
|
|
264
|
+
.replace(/[_-]+/g, ' ')
|
|
265
|
+
.replace(/\s+/g, ' ')
|
|
266
|
+
.trim()
|
|
267
|
+
.replace(/^\w/, (character) => character.toUpperCase());
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Infers whether a tool-call snapshot has reached a terminal successful state.
|
|
272
|
+
*
|
|
273
|
+
* @param toolCall - Tool call observed while the model is running.
|
|
274
|
+
* @returns Whether the tool call has a completed result.
|
|
275
|
+
*
|
|
276
|
+
* @private internal helper for Agents Server durable chat progress
|
|
277
|
+
*/
|
|
278
|
+
function isToolCallComplete(toolCall: ToolCall): boolean {
|
|
279
|
+
if (toolCall.state === 'COMPLETE') {
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (toolCall.state === 'ERROR' || toolCall.state === 'PARTIAL' || toolCall.state === 'PENDING') {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return toolCall.result !== undefined && toolCall.result !== '';
|
|
288
|
+
}
|
package/esm/index.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import colors from 'colors';
|
|
2
2
|
import commander, { Option } from 'commander';
|
|
3
3
|
import _spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
4
|
-
import { writeFile, stat, mkdir, readFile, rm, cp, lstat, symlink, readdir, unlink, appendFile, rename, access, constants, watch, rmdir } from 'fs/promises';
|
|
4
|
+
import { writeFile, stat, mkdir, readFile, rm, cp, lstat, symlink, readdir, unlink, appendFile, rename, copyFile, access, constants, watch, rmdir } from 'fs/promises';
|
|
5
5
|
import { join, resolve, dirname, relative, basename, delimiter, isAbsolute, extname } from 'path';
|
|
6
6
|
import { spawn } from 'child_process';
|
|
7
7
|
import { createHash, randomBytes } from 'crypto';
|
|
@@ -58,7 +58,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
58
58
|
* @generated
|
|
59
59
|
* @see https://github.com/webgptorg/promptbook
|
|
60
60
|
*/
|
|
61
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
61
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-125';
|
|
62
62
|
/**
|
|
63
63
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
64
64
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -2176,7 +2176,7 @@ function getDefaultBookLanguageManualContent() {
|
|
|
2176
2176
|
*/
|
|
2177
2177
|
async function ensureCoderMarkdownFile(projectPath, relativeFilePath, fileContent) {
|
|
2178
2178
|
const absoluteFilePath = join(projectPath, relativeFilePath);
|
|
2179
|
-
if (await isExistingFile$
|
|
2179
|
+
if (await isExistingFile$3(absoluteFilePath)) {
|
|
2180
2180
|
return 'unchanged';
|
|
2181
2181
|
}
|
|
2182
2182
|
await writeFile(absoluteFilePath, `${fileContent}\n`, 'utf-8');
|
|
@@ -2185,7 +2185,7 @@ async function ensureCoderMarkdownFile(projectPath, relativeFilePath, fileConten
|
|
|
2185
2185
|
/**
|
|
2186
2186
|
* Checks whether a path exists and is a file.
|
|
2187
2187
|
*/
|
|
2188
|
-
async function isExistingFile$
|
|
2188
|
+
async function isExistingFile$3(path) {
|
|
2189
2189
|
try {
|
|
2190
2190
|
return (await stat(path)).isFile();
|
|
2191
2191
|
}
|
|
@@ -38757,7 +38757,7 @@ async function ensureDefaultCoderPromptTemplateFiles(projectPath) {
|
|
|
38757
38757
|
const ensuredTemplateFiles = [];
|
|
38758
38758
|
for (const definition of DEFAULT_CODER_PROJECT_PROMPT_TEMPLATE_DEFINITIONS) {
|
|
38759
38759
|
const absoluteTemplatePath = join(projectPath, definition.relativeFilePath);
|
|
38760
|
-
if (await isExistingFile$
|
|
38760
|
+
if (await isExistingFile$2(absoluteTemplatePath)) {
|
|
38761
38761
|
ensuredTemplateFiles.push({
|
|
38762
38762
|
id: definition.id,
|
|
38763
38763
|
relativeFilePath: definition.relativeFilePath,
|
|
@@ -38871,7 +38871,7 @@ function isNodeJsErrorWithCode(error, code) {
|
|
|
38871
38871
|
/**
|
|
38872
38872
|
* Checks whether a path exists and is a file.
|
|
38873
38873
|
*/
|
|
38874
|
-
async function isExistingFile$
|
|
38874
|
+
async function isExistingFile$2(path) {
|
|
38875
38875
|
try {
|
|
38876
38876
|
return (await stat(path)).isFile();
|
|
38877
38877
|
}
|
|
@@ -39144,6 +39144,70 @@ function formatInlineCodeList(values) {
|
|
|
39144
39144
|
// Note: [🟡] Code for coder AGENT_CODING file boilerplate [agentCodingFile](src/cli/cli-commands/coder/agentCodingFile.ts) should never be published outside of `@promptbook/cli`
|
|
39145
39145
|
// Note: [💞] Ignore a discrepancy between file name and exported helper names
|
|
39146
39146
|
|
|
39147
|
+
/**
|
|
39148
|
+
* Relative directory path for agents initialized by `ptbk coder init`.
|
|
39149
|
+
*
|
|
39150
|
+
* @private internal utility of `coder init` command
|
|
39151
|
+
*/
|
|
39152
|
+
const CODER_AGENTS_DIRECTORY_PATH = 'agents';
|
|
39153
|
+
/**
|
|
39154
|
+
* Relative file path to the default developer agent initialized by `ptbk coder init`.
|
|
39155
|
+
*
|
|
39156
|
+
* @private internal utility of `coder init` command
|
|
39157
|
+
*/
|
|
39158
|
+
const CODER_DEVELOPER_AGENT_FILE_PATH = 'agents/developer.book';
|
|
39159
|
+
/**
|
|
39160
|
+
* Source file path of the bundled developer agent inside the Promptbook repository.
|
|
39161
|
+
*
|
|
39162
|
+
* @private internal utility of `coder init` command
|
|
39163
|
+
*/
|
|
39164
|
+
const DEFAULT_CODER_DEVELOPER_AGENT_SOURCE_FILE_PATH = 'agents/default/developer.book';
|
|
39165
|
+
/**
|
|
39166
|
+
* Ensures the default developer agent exists in the initialized project.
|
|
39167
|
+
*
|
|
39168
|
+
* @private function of `initializeCoderProjectConfiguration`
|
|
39169
|
+
*/
|
|
39170
|
+
async function ensureCoderDeveloperAgentFile(projectPath) {
|
|
39171
|
+
const absoluteFilePath = join(projectPath, CODER_DEVELOPER_AGENT_FILE_PATH);
|
|
39172
|
+
if (await isExistingFile$1(absoluteFilePath)) {
|
|
39173
|
+
return 'unchanged';
|
|
39174
|
+
}
|
|
39175
|
+
await copyFile(await resolveDefaultCoderDeveloperAgentFilePath(), absoluteFilePath);
|
|
39176
|
+
return 'created';
|
|
39177
|
+
}
|
|
39178
|
+
/**
|
|
39179
|
+
* Resolves the bundled developer agent from a source checkout or generated CLI package.
|
|
39180
|
+
*/
|
|
39181
|
+
async function resolveDefaultCoderDeveloperAgentFilePath() {
|
|
39182
|
+
const candidates = [
|
|
39183
|
+
join(__dirname, '..', DEFAULT_CODER_DEVELOPER_AGENT_SOURCE_FILE_PATH),
|
|
39184
|
+
join(__dirname, '..', '..', '..', '..', DEFAULT_CODER_DEVELOPER_AGENT_SOURCE_FILE_PATH),
|
|
39185
|
+
];
|
|
39186
|
+
for (const candidate of candidates) {
|
|
39187
|
+
if (await isExistingFile$1(candidate)) {
|
|
39188
|
+
return candidate;
|
|
39189
|
+
}
|
|
39190
|
+
}
|
|
39191
|
+
throw new NotAllowed(spaceTrim$1(`
|
|
39192
|
+
Cannot find the bundled Promptbook developer agent.
|
|
39193
|
+
|
|
39194
|
+
Checked:
|
|
39195
|
+
${candidates.map((candidate) => `- \`${candidate}\``).join('\n')}
|
|
39196
|
+
`));
|
|
39197
|
+
}
|
|
39198
|
+
/**
|
|
39199
|
+
* Checks whether a path exists and is a file.
|
|
39200
|
+
*/
|
|
39201
|
+
async function isExistingFile$1(path) {
|
|
39202
|
+
try {
|
|
39203
|
+
return (await stat(path)).isFile();
|
|
39204
|
+
}
|
|
39205
|
+
catch (_a) {
|
|
39206
|
+
return false;
|
|
39207
|
+
}
|
|
39208
|
+
}
|
|
39209
|
+
// Note: [🟡] Code for coder init developer agent bootstrapping [ensureCoderDeveloperAgentFile](src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.ts) should never be published outside of `@promptbook/cli`
|
|
39210
|
+
|
|
39147
39211
|
/**
|
|
39148
39212
|
* Fallback `.env` content used when no required variables need to be appended.
|
|
39149
39213
|
*/
|
|
@@ -39220,7 +39284,7 @@ async function ensureCoderGitignoreFile(projectPath) {
|
|
|
39220
39284
|
*/
|
|
39221
39285
|
const DEFAULT_CODER_PACKAGE_JSON_SCRIPTS = {
|
|
39222
39286
|
'coder:generate-boilerplates': 'ptbk coder generate-boilerplates --template ./prompts/templates/common.md',
|
|
39223
|
-
'coder:run': 'ptbk coder run --harness openai-codex --model gpt-5.4 --thinking-level xhigh --context AGENTS.md --no-wait',
|
|
39287
|
+
'coder:run': 'ptbk coder run --harness openai-codex --model gpt-5.4 --thinking-level xhigh --agent agents/developer.book --context AGENTS.md --no-wait',
|
|
39224
39288
|
// 'coder:find-refactor-candidates': 'ptbk coder find-refactor-candidates',
|
|
39225
39289
|
'coder:verify': 'ptbk coder verify',
|
|
39226
39290
|
};
|
|
@@ -39466,6 +39530,8 @@ async function initializeCoderProjectConfiguration(projectPath) {
|
|
|
39466
39530
|
const promptsDoneDirectoryStatus = await ensureDirectory(projectPath, PROMPTS_DONE_DIRECTORY_PATH);
|
|
39467
39531
|
const promptsTemplatesDirectoryStatus = await ensureDirectory(projectPath, PROMPTS_TEMPLATES_DIRECTORY_PATH);
|
|
39468
39532
|
const promptTemplateFileStatuses = await ensureDefaultCoderPromptTemplateFiles(projectPath);
|
|
39533
|
+
const agentsDirectoryStatus = await ensureDirectory(projectPath, CODER_AGENTS_DIRECTORY_PATH);
|
|
39534
|
+
const developerAgentFileStatus = await ensureCoderDeveloperAgentFile(projectPath);
|
|
39469
39535
|
const agentsFileStatus = await ensureCoderMarkdownFile(projectPath, AGENTS_FILE_PATH, getDefaultCoderAgentsFileContent());
|
|
39470
39536
|
const agentCodingFileStatus = await ensureCoderMarkdownFile(projectPath, AGENT_CODING_FILE_PATH, getDefaultCoderAgentCodingFileContent({
|
|
39471
39537
|
packageJsonScripts: getDefaultCoderPackageJsonScripts(),
|
|
@@ -39479,6 +39545,8 @@ async function initializeCoderProjectConfiguration(projectPath) {
|
|
|
39479
39545
|
promptsDoneDirectoryStatus,
|
|
39480
39546
|
promptsTemplatesDirectoryStatus,
|
|
39481
39547
|
promptTemplateFileStatuses,
|
|
39548
|
+
agentsDirectoryStatus,
|
|
39549
|
+
developerAgentFileStatus,
|
|
39482
39550
|
agentsFileStatus,
|
|
39483
39551
|
agentCodingFileStatus,
|
|
39484
39552
|
envFileStatus,
|
|
@@ -39503,6 +39571,8 @@ function printInitializationSummary(summary) {
|
|
|
39503
39571
|
for (const templateFileStatus of summary.promptTemplateFileStatuses) {
|
|
39504
39572
|
printInitializationStatusLine(formatDisplayPath(templateFileStatus.relativeFilePath), templateFileStatus.status);
|
|
39505
39573
|
}
|
|
39574
|
+
printInitializationStatusLine('agents/', summary.agentsDirectoryStatus);
|
|
39575
|
+
printInitializationStatusLine(CODER_DEVELOPER_AGENT_FILE_PATH, summary.developerAgentFileStatus);
|
|
39506
39576
|
printInitializationStatusLine(AGENTS_FILE_PATH, summary.agentsFileStatus);
|
|
39507
39577
|
printInitializationStatusLine(AGENT_CODING_FILE_PATH, summary.agentCodingFileStatus);
|
|
39508
39578
|
printInitializationStatusLine('.env', summary.envFileStatus);
|
|
@@ -39559,6 +39629,7 @@ function $initializeCoderInitCommand(program) {
|
|
|
39559
39629
|
- prompts/
|
|
39560
39630
|
- prompts/done/
|
|
39561
39631
|
${listDefaultCoderProjectPromptTemplateDisplayPaths()}
|
|
39632
|
+
- ${CODER_DEVELOPER_AGENT_FILE_PATH}
|
|
39562
39633
|
- ${AGENTS_FILE_PATH}
|
|
39563
39634
|
- ${AGENT_CODING_FILE_PATH}
|
|
39564
39635
|
- .gitignore
|