@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.
- package/apps/agents-server/src/utils/agentProjects/agentProjectRuntimePm2.ts +56 -10
- package/apps/agents-server/src/utils/userChat/createImmediateUserChatAnswerModelRequirements.ts +1 -0
- package/esm/index.es.js +391 -68
- package/esm/index.es.js.map +1 -1
- package/esm/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.d.ts +1 -1
- package/esm/src/cli/cli-commands/common/harness/$resolveHarnessCommandPath.d.ts +14 -0
- package/esm/src/cli/cli-commands/common/harness/$resolveHarnessInstallationOrigin.d.ts +10 -0
- package/esm/src/cli/cli-commands/common/harness/$runHarnessInstallationCommand.d.ts +43 -0
- package/esm/src/cli/cli-commands/common/harness/HarnessDefinition.d.ts +26 -0
- package/esm/src/cli/cli-commands/common/harness/HarnessInstallationOrigin.d.ts +36 -0
- package/esm/src/cli/cli-commands/common/harness/HarnessInstallationStatus.d.ts +5 -0
- package/esm/src/cli/cli-commands/common/harness/HarnessUpdatePlan.d.ts +23 -0
- package/esm/src/cli/cli-commands/common/harness/buildHarnessInstallCommand.d.ts +4 -1
- package/esm/src/cli/cli-commands/common/harness/formatHarnessManualUpdateInstruction.d.ts +8 -0
- package/esm/src/cli/cli-commands/common/harness/formatHarnessManualUpdateInstruction.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/common/harness/resolveHarnessInstallationMethodFromPaths.d.ts +31 -0
- package/esm/src/cli/cli-commands/common/harness/resolveHarnessInstallationMethodFromPaths.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/common/harness/resolveHarnessUpdatePlan.d.ts +12 -0
- package/esm/src/cli/cli-commands/common/harness/resolveHarnessUpdatePlan.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/common/npm/$resolveNpmGlobalPrefixPath.d.ts +9 -0
- package/esm/src/commitments/WRITING_RULES/WRITING_RULES.d.ts +14 -7
- package/esm/src/commitments/index.d.ts +1 -1
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.ts +1 -0
- package/src/cli/cli-commands/coder/init.ts +1 -1
- package/src/cli/cli-commands/coder/ping.ts +1 -1
- package/src/cli/cli-commands/coder/run.ts +1 -1
- package/src/cli/cli-commands/coder/server.ts +1 -1
- package/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.ts +57 -8
- package/src/cli/cli-commands/common/harness/$checkHarnessInstallation.ts +8 -1
- package/src/cli/cli-commands/common/harness/$resolveHarnessCommandPath.ts +46 -0
- package/src/cli/cli-commands/common/harness/$resolveHarnessInstallationOrigin.ts +36 -0
- package/src/cli/cli-commands/common/harness/$runHarnessInstallationCommand.ts +100 -0
- package/src/cli/cli-commands/common/harness/HarnessDefinition.ts +34 -0
- package/src/cli/cli-commands/common/harness/HarnessInstallationOrigin.ts +44 -0
- package/src/cli/cli-commands/common/harness/HarnessInstallationStatus.ts +6 -0
- package/src/cli/cli-commands/common/harness/HarnessUpdatePlan.ts +27 -0
- package/src/cli/cli-commands/common/harness/buildHarnessInstallCommand.ts +4 -1
- package/src/cli/cli-commands/common/harness/formatHarnessInstallationWarning.ts +28 -6
- package/src/cli/cli-commands/common/harness/formatHarnessManualUpdateInstruction.ts +41 -0
- package/src/cli/cli-commands/common/harness/resolveHarnessInstallationMethodFromPaths.ts +111 -0
- package/src/cli/cli-commands/common/harness/resolveHarnessUpdatePlan.ts +47 -0
- package/src/cli/cli-commands/common/harnessUpdateCliOptions.ts +1 -1
- package/src/cli/cli-commands/common/npm/$resolveNpmGlobalPrefixPath.ts +51 -0
- package/src/commitments/WRITING_RULES/WRITING_RULES.ts +16 -8
- package/src/commitments/index.ts +2 -1
- package/src/other/templates/getTemplatesPipelineCollection.ts +823 -1016
- package/src/version.ts +2 -2
- package/src/versions.txt +2 -0
- package/umd/index.umd.js +391 -68
- package/umd/index.umd.js.map +1 -1
- package/umd/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.d.ts +1 -1
- package/umd/src/cli/cli-commands/common/harness/$resolveHarnessCommandPath.d.ts +14 -0
- package/umd/src/cli/cli-commands/common/harness/$resolveHarnessInstallationOrigin.d.ts +10 -0
- package/umd/src/cli/cli-commands/common/harness/$runHarnessInstallationCommand.d.ts +43 -0
- package/umd/src/cli/cli-commands/common/harness/HarnessDefinition.d.ts +26 -0
- package/umd/src/cli/cli-commands/common/harness/HarnessInstallationOrigin.d.ts +36 -0
- package/umd/src/cli/cli-commands/common/harness/HarnessInstallationStatus.d.ts +5 -0
- package/umd/src/cli/cli-commands/common/harness/HarnessUpdatePlan.d.ts +23 -0
- package/umd/src/cli/cli-commands/common/harness/buildHarnessInstallCommand.d.ts +4 -1
- package/umd/src/cli/cli-commands/common/harness/formatHarnessManualUpdateInstruction.d.ts +8 -0
- package/umd/src/cli/cli-commands/common/harness/formatHarnessManualUpdateInstruction.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/harness/resolveHarnessInstallationMethodFromPaths.d.ts +31 -0
- package/umd/src/cli/cli-commands/common/harness/resolveHarnessInstallationMethodFromPaths.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/harness/resolveHarnessUpdatePlan.d.ts +12 -0
- package/umd/src/cli/cli-commands/common/harness/resolveHarnessUpdatePlan.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/npm/$resolveNpmGlobalPrefixPath.d.ts +9 -0
- package/umd/src/commitments/WRITING_RULES/WRITING_RULES.d.ts +14 -7
- package/umd/src/commitments/index.d.ts +1 -1
- package/umd/src/version.d.ts +1 -1
- package/esm/src/cli/cli-commands/common/harness/$installHarness.d.ts +0 -13
- package/src/cli/cli-commands/common/harness/$installHarness.ts +0 -56
- 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
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
204
|
-
|
|
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
|
*/
|