@promptbook/cli 0.112.0-121 → 0.112.0-124

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 (55) hide show
  1. package/README.md +14 -14
  2. package/agents/default/developer.book +23 -0
  3. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/messages/route.ts +4 -11
  4. package/apps/agents-server/src/app/api/scrape/route.ts +18 -0
  5. package/apps/agents-server/src/tools/createAgentProgressTools.ts +6 -4
  6. package/apps/agents-server/src/utils/assertSafeUrl.ts +136 -0
  7. package/apps/agents-server/src/utils/authenticateUser.ts +2 -1
  8. package/apps/agents-server/src/utils/getCurrentUser.ts +2 -1
  9. package/apps/agents-server/src/utils/isAdminPasswordEqual.ts +28 -0
  10. package/apps/agents-server/src/utils/isUserGlobalAdmin.ts +3 -1
  11. package/apps/agents-server/src/utils/userChat/createRunUserChatJobPersistenceController.ts +21 -0
  12. package/apps/agents-server/src/utils/userChat/retryUserChatJob.ts +4 -0
  13. package/apps/agents-server/src/utils/userChat/userChatMessageLifecycle.ts +2 -0
  14. package/apps/agents-server/src/utils/userChat/userChatProgressCard.ts +288 -0
  15. package/esm/index.es.js +1430 -283
  16. package/esm/index.es.js.map +1 -1
  17. package/esm/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +6 -0
  18. package/esm/scripts/run-codex-prompts/main/findUnwrittenPrompts.d.ts +19 -0
  19. package/esm/scripts/run-codex-prompts/main/runCodexPromptsServer.d.ts +27 -0
  20. package/esm/scripts/run-codex-prompts/main/runPromptRound.d.ts +2 -1
  21. package/esm/scripts/run-codex-prompts/server/coderServerHtml.d.ts +9 -0
  22. package/esm/scripts/run-codex-prompts/server/runCoderHttpServer.d.ts +23 -0
  23. package/esm/scripts/run-codex-prompts/server/updatePromptSection.d.ts +9 -0
  24. package/esm/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.d.ts +25 -0
  25. package/esm/src/cli/cli-commands/coder/find-unwritten.d.ts +10 -0
  26. package/esm/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +2 -0
  27. package/esm/src/cli/cli-commands/coder/server.d.ts +13 -0
  28. package/esm/src/version.d.ts +1 -1
  29. package/package.json +1 -1
  30. package/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.ts +79 -0
  31. package/src/cli/cli-commands/coder/find-unwritten.ts +58 -0
  32. package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +1 -1
  33. package/src/cli/cli-commands/coder/init.ts +6 -1
  34. package/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.ts +10 -0
  35. package/src/cli/cli-commands/coder/printInitializationSummary.ts +3 -0
  36. package/src/cli/cli-commands/coder/run.ts +26 -11
  37. package/src/cli/cli-commands/coder/server.ts +239 -0
  38. package/src/cli/cli-commands/coder.ts +6 -0
  39. package/src/other/templates/getTemplatesPipelineCollection.ts +727 -1105
  40. package/src/version.ts +2 -2
  41. package/src/versions.txt +3 -1
  42. package/umd/index.umd.js +1431 -284
  43. package/umd/index.umd.js.map +1 -1
  44. package/umd/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +6 -0
  45. package/umd/scripts/run-codex-prompts/main/findUnwrittenPrompts.d.ts +19 -0
  46. package/umd/scripts/run-codex-prompts/main/runCodexPromptsServer.d.ts +27 -0
  47. package/umd/scripts/run-codex-prompts/main/runPromptRound.d.ts +2 -1
  48. package/umd/scripts/run-codex-prompts/server/coderServerHtml.d.ts +9 -0
  49. package/umd/scripts/run-codex-prompts/server/runCoderHttpServer.d.ts +23 -0
  50. package/umd/scripts/run-codex-prompts/server/updatePromptSection.d.ts +9 -0
  51. package/umd/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.d.ts +25 -0
  52. package/umd/src/cli/cli-commands/coder/find-unwritten.d.ts +10 -0
  53. package/umd/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +2 -0
  54. package/umd/src/cli/cli-commands/coder/server.d.ts +13 -0
  55. 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
+ }