@promptbook/cli 0.114.0-25 → 0.114.0-27

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 (74) hide show
  1. package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimePm2.ts +56 -10
  2. package/apps/agents-server/src/utils/userChat/createImmediateUserChatAnswerModelRequirements.ts +1 -0
  3. package/esm/index.es.js +391 -68
  4. package/esm/index.es.js.map +1 -1
  5. package/esm/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.d.ts +1 -1
  6. package/esm/src/cli/cli-commands/common/harness/$resolveHarnessCommandPath.d.ts +14 -0
  7. package/esm/src/cli/cli-commands/common/harness/$resolveHarnessInstallationOrigin.d.ts +10 -0
  8. package/esm/src/cli/cli-commands/common/harness/$runHarnessInstallationCommand.d.ts +43 -0
  9. package/esm/src/cli/cli-commands/common/harness/HarnessDefinition.d.ts +26 -0
  10. package/esm/src/cli/cli-commands/common/harness/HarnessInstallationOrigin.d.ts +36 -0
  11. package/esm/src/cli/cli-commands/common/harness/HarnessInstallationStatus.d.ts +5 -0
  12. package/esm/src/cli/cli-commands/common/harness/HarnessUpdatePlan.d.ts +23 -0
  13. package/esm/src/cli/cli-commands/common/harness/buildHarnessInstallCommand.d.ts +4 -1
  14. package/esm/src/cli/cli-commands/common/harness/formatHarnessManualUpdateInstruction.d.ts +8 -0
  15. package/esm/src/cli/cli-commands/common/harness/formatHarnessManualUpdateInstruction.test.d.ts +1 -0
  16. package/esm/src/cli/cli-commands/common/harness/resolveHarnessInstallationMethodFromPaths.d.ts +31 -0
  17. package/esm/src/cli/cli-commands/common/harness/resolveHarnessInstallationMethodFromPaths.test.d.ts +1 -0
  18. package/esm/src/cli/cli-commands/common/harness/resolveHarnessUpdatePlan.d.ts +12 -0
  19. package/esm/src/cli/cli-commands/common/harness/resolveHarnessUpdatePlan.test.d.ts +1 -0
  20. package/esm/src/cli/cli-commands/common/npm/$resolveNpmGlobalPrefixPath.d.ts +9 -0
  21. package/esm/src/commitments/WRITING_RULES/WRITING_RULES.d.ts +14 -7
  22. package/esm/src/commitments/index.d.ts +1 -1
  23. package/esm/src/version.d.ts +1 -1
  24. package/package.json +1 -1
  25. package/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.ts +1 -0
  26. package/src/cli/cli-commands/coder/init.ts +1 -1
  27. package/src/cli/cli-commands/coder/ping.ts +1 -1
  28. package/src/cli/cli-commands/coder/run.ts +1 -1
  29. package/src/cli/cli-commands/coder/server.ts +1 -1
  30. package/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.ts +57 -8
  31. package/src/cli/cli-commands/common/harness/$checkHarnessInstallation.ts +8 -1
  32. package/src/cli/cli-commands/common/harness/$resolveHarnessCommandPath.ts +46 -0
  33. package/src/cli/cli-commands/common/harness/$resolveHarnessInstallationOrigin.ts +36 -0
  34. package/src/cli/cli-commands/common/harness/$runHarnessInstallationCommand.ts +100 -0
  35. package/src/cli/cli-commands/common/harness/HarnessDefinition.ts +34 -0
  36. package/src/cli/cli-commands/common/harness/HarnessInstallationOrigin.ts +44 -0
  37. package/src/cli/cli-commands/common/harness/HarnessInstallationStatus.ts +6 -0
  38. package/src/cli/cli-commands/common/harness/HarnessUpdatePlan.ts +27 -0
  39. package/src/cli/cli-commands/common/harness/buildHarnessInstallCommand.ts +4 -1
  40. package/src/cli/cli-commands/common/harness/formatHarnessInstallationWarning.ts +28 -6
  41. package/src/cli/cli-commands/common/harness/formatHarnessManualUpdateInstruction.ts +41 -0
  42. package/src/cli/cli-commands/common/harness/resolveHarnessInstallationMethodFromPaths.ts +111 -0
  43. package/src/cli/cli-commands/common/harness/resolveHarnessUpdatePlan.ts +47 -0
  44. package/src/cli/cli-commands/common/harnessUpdateCliOptions.ts +1 -1
  45. package/src/cli/cli-commands/common/npm/$resolveNpmGlobalPrefixPath.ts +51 -0
  46. package/src/commitments/WRITING_RULES/WRITING_RULES.ts +16 -8
  47. package/src/commitments/index.ts +2 -1
  48. package/src/other/templates/getTemplatesPipelineCollection.ts +823 -1016
  49. package/src/version.ts +2 -2
  50. package/src/versions.txt +2 -0
  51. package/umd/index.umd.js +391 -68
  52. package/umd/index.umd.js.map +1 -1
  53. package/umd/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.d.ts +1 -1
  54. package/umd/src/cli/cli-commands/common/harness/$resolveHarnessCommandPath.d.ts +14 -0
  55. package/umd/src/cli/cli-commands/common/harness/$resolveHarnessInstallationOrigin.d.ts +10 -0
  56. package/umd/src/cli/cli-commands/common/harness/$runHarnessInstallationCommand.d.ts +43 -0
  57. package/umd/src/cli/cli-commands/common/harness/HarnessDefinition.d.ts +26 -0
  58. package/umd/src/cli/cli-commands/common/harness/HarnessInstallationOrigin.d.ts +36 -0
  59. package/umd/src/cli/cli-commands/common/harness/HarnessInstallationStatus.d.ts +5 -0
  60. package/umd/src/cli/cli-commands/common/harness/HarnessUpdatePlan.d.ts +23 -0
  61. package/umd/src/cli/cli-commands/common/harness/buildHarnessInstallCommand.d.ts +4 -1
  62. package/umd/src/cli/cli-commands/common/harness/formatHarnessManualUpdateInstruction.d.ts +8 -0
  63. package/umd/src/cli/cli-commands/common/harness/formatHarnessManualUpdateInstruction.test.d.ts +1 -0
  64. package/umd/src/cli/cli-commands/common/harness/resolveHarnessInstallationMethodFromPaths.d.ts +31 -0
  65. package/umd/src/cli/cli-commands/common/harness/resolveHarnessInstallationMethodFromPaths.test.d.ts +1 -0
  66. package/umd/src/cli/cli-commands/common/harness/resolveHarnessUpdatePlan.d.ts +12 -0
  67. package/umd/src/cli/cli-commands/common/harness/resolveHarnessUpdatePlan.test.d.ts +1 -0
  68. package/umd/src/cli/cli-commands/common/npm/$resolveNpmGlobalPrefixPath.d.ts +9 -0
  69. package/umd/src/commitments/WRITING_RULES/WRITING_RULES.d.ts +14 -7
  70. package/umd/src/commitments/index.d.ts +1 -1
  71. package/umd/src/version.d.ts +1 -1
  72. package/esm/src/cli/cli-commands/common/harness/$installHarness.d.ts +0 -13
  73. package/src/cli/cli-commands/common/harness/$installHarness.ts +0 -56
  74. package/umd/src/cli/cli-commands/common/harness/$installHarness.d.ts +0 -13
@@ -1,6 +1,8 @@
1
1
  import { execFile } from 'child_process';
2
2
  import { createHash } from 'crypto';
3
3
  import { promisify } from 'util';
4
+ import { UnexpectedError } from '../../../../../src/errors/UnexpectedError';
5
+ import { spaceTrim } from '../../../../../src/utils/organization/spaceTrim';
4
6
  import { AGENT_PROJECT_RUNTIME_HOST } from './agentProjectRuntimeConstants';
5
7
  import type { AgentProjectRuntimeMode } from './AgentProjectRuntimeInfo';
6
8
  import { resolveAgentProjectRuntimeEnvironmentFlag } from './resolveAgentProjectRuntimeEnvironmentFlag';
@@ -44,8 +46,18 @@ const AGENT_PROJECT_PM2_PROCESS_LABEL_LENGTH = 36;
44
46
 
45
47
  /**
46
48
  * Max output retained from pm2 commands.
49
+ *
50
+ * Note: `pm2 jlist` embeds a full environment snapshot into every listed process, so the list grows by tens of
51
+ * kilobytes with each started project. A budget of one megabyte was exhausted by roughly a dozen projects,
52
+ * after which `execFile` killed every `pm2 jlist` call with `ERR_CHILD_PROCESS_STDIO_MAXBUFFER` and pm2
53
+ * appeared to know no process at all.
54
+ */
55
+ const PM2_COMMAND_MAX_BUFFER_BYTES = 64 * 1024 * 1024;
56
+
57
+ /**
58
+ * pm2 error reported when no process of the requested name is registered.
47
59
  */
48
- const PM2_COMMAND_MAX_BUFFER_BYTES = 1024 * 1024;
60
+ const PM2_MISSING_PROCESS_ERROR_PATTERN = /Process or Namespace .* not found/u;
49
61
 
50
62
  /**
51
63
  * Status snapshot for one pm2 process.
@@ -189,25 +201,46 @@ export async function startAgentProjectRuntimePm2Process(
189
201
  }
190
202
 
191
203
  /**
192
- * Stops one pm2 project process when it exists.
204
+ * Deletes every pm2 process registered under one name.
205
+ *
206
+ * Note: The delete is never skipped because pm2 could not be asked for its current process list. `pm2 start`
207
+ * appends another process instead of replacing the existing one when a process of the same name is already
208
+ * registered, so a delete which silently does nothing turns every later start of the same project into one
209
+ * more duplicate. Only pm2 itself reporting an unknown name counts as "already gone", every other failure
210
+ * is reported to the caller, which then must not start the project again.
193
211
  *
194
212
  * @param processName - pm2 process name.
195
213
  */
196
214
  export async function stopAgentProjectRuntimePm2Process(processName: string | null | undefined): Promise<void> {
197
- if (!processName) {
215
+ if (!processName || !isAgentProjectRuntimePm2Enabled()) {
198
216
  return;
199
217
  }
200
218
 
201
- const status = await resolveAgentProjectRuntimePm2Status(processName);
219
+ try {
220
+ await execFileAsync(PM2_COMMAND, ['delete', processName], {
221
+ maxBuffer: PM2_COMMAND_MAX_BUFFER_BYTES,
222
+ windowsHide: true,
223
+ });
224
+ } catch (error) {
225
+ if (isPm2MissingProcessError(error)) {
226
+ return;
227
+ }
202
228
 
203
- if (!status.isKnown) {
204
- return;
229
+ throw new UnexpectedError(
230
+ spaceTrim(
231
+ (block) => `
232
+ Failed to delete the pm2 process \`${processName}\` of an agent project.
233
+
234
+ Starting the project again would register one more pm2 process of the same name instead of
235
+ replacing the existing one, so the project was left alone.
236
+
237
+ **Cause:**
238
+ ${block(error instanceof Error ? error.message : String(error))}
239
+ `,
240
+ ),
241
+ );
205
242
  }
206
243
 
207
- await execFileAsync(PM2_COMMAND, ['delete', processName], {
208
- maxBuffer: PM2_COMMAND_MAX_BUFFER_BYTES,
209
- windowsHide: true,
210
- });
211
244
  await savePm2ProcessList();
212
245
  }
213
246
 
@@ -366,6 +399,19 @@ async function savePm2ProcessList(): Promise<void> {
366
399
  });
367
400
  }
368
401
 
402
+ /**
403
+ * Returns whether one failed pm2 command failed only because pm2 knows no process of the requested name.
404
+ */
405
+ function isPm2MissingProcessError(error: unknown): boolean {
406
+ if (!error || typeof error !== 'object') {
407
+ return false;
408
+ }
409
+
410
+ const { stderr } = error as { readonly stderr?: unknown };
411
+
412
+ return typeof stderr === 'string' && PM2_MISSING_PROCESS_ERROR_PATTERN.test(stderr);
413
+ }
414
+
369
415
  /**
370
416
  * Creates the fallback status for missing or unavailable pm2 processes.
371
417
  */
@@ -19,6 +19,7 @@ const IMMEDIATE_USER_CHAT_ANSWER_INSTRUCTION_COMMITMENTS = new Set<string>([
19
19
  'STYLE',
20
20
  'STYLES',
21
21
  'WRITING RULES',
22
+ 'WRITING RULE',
22
23
  'FORMAT',
23
24
  'FORMATS',
24
25
  'SCENARIO',