@promptbook/cli 0.114.0-34 → 0.114.0-38
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/package.json +1 -1
- package/apps/agents-server/scripts/build-agents-server.js +4 -0
- package/apps/agents-server/scripts/build-e2e.js +1 -1
- package/apps/agents-server/src/app/swagger/SwaggerPageClient.tsx +35 -19
- package/apps/agents-server/src/types/swagger-ui-dist.d.ts +5 -0
- package/esm/index.es.js +363 -98
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-codex-prompts/common/resolveCoderAgent.d.ts +7 -0
- package/esm/scripts/run-codex-prompts/main/resolvePromptRunner.d.ts +5 -8
- package/esm/scripts/run-codex-prompts/main/runPromptRound.d.ts +2 -4
- package/esm/scripts/run-codex-prompts/prompts/buildPromptRunTraceContent.d.ts +5 -17
- package/esm/scripts/run-codex-prompts/prompts/buildPromptStatusDetails.d.ts +3 -15
- package/esm/scripts/run-codex-prompts/prompts/formatRunnerSignature.d.ts +14 -1
- package/esm/scripts/run-codex-prompts/prompts/markPromptFailed.d.ts +2 -9
- package/esm/src/book-2.0/agent-source/createAgentModelRequirements.deduplication.test.d.ts +1 -0
- package/esm/src/book-2.0/agent-source/deduplicateSystemMessage.d.ts +14 -0
- package/esm/src/book-2.0/agent-source/deduplicateSystemMessage.test.d.ts +1 -0
- package/esm/src/cli/$initializePromptbookCliProgram.d.ts +8 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -3
- package/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.ts +3 -2
- package/src/book-2.0/agent-source/deduplicateSystemMessage.ts +327 -0
- package/src/cli/$initializePromptbookCliProgram.ts +87 -0
- package/src/cli/promptbookCli.ts +2 -87
- package/src/other/templates/getTemplatesPipelineCollection.ts +903 -663
- package/src/version.ts +2 -2
- package/src/versions.txt +4 -0
- package/umd/index.umd.js +363 -98
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-codex-prompts/common/resolveCoderAgent.d.ts +7 -0
- package/umd/scripts/run-codex-prompts/main/resolvePromptRunner.d.ts +5 -8
- package/umd/scripts/run-codex-prompts/main/runPromptRound.d.ts +2 -4
- package/umd/scripts/run-codex-prompts/prompts/buildPromptRunTraceContent.d.ts +5 -17
- package/umd/scripts/run-codex-prompts/prompts/buildPromptStatusDetails.d.ts +3 -15
- package/umd/scripts/run-codex-prompts/prompts/formatRunnerSignature.d.ts +14 -1
- package/umd/scripts/run-codex-prompts/prompts/markPromptFailed.d.ts +2 -9
- package/umd/src/book-2.0/agent-source/createAgentModelRequirements.deduplication.test.d.ts +1 -0
- package/umd/src/book-2.0/agent-source/deduplicateSystemMessage.d.ts +14 -0
- package/umd/src/book-2.0/agent-source/deduplicateSystemMessage.test.d.ts +1 -0
- package/umd/src/cli/$initializePromptbookCliProgram.d.ts +8 -0
- package/umd/src/version.d.ts +1 -1
package/esm/index.es.js
CHANGED
|
@@ -48,12 +48,42 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
48
48
|
* @generated
|
|
49
49
|
* @see https://github.com/webgptorg/promptbook
|
|
50
50
|
*/
|
|
51
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.114.0-
|
|
51
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.114.0-38';
|
|
52
52
|
/**
|
|
53
53
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
54
54
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
55
55
|
*/
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
59
|
+
*
|
|
60
|
+
* @public exported from `@promptbook/core`
|
|
61
|
+
*/
|
|
62
|
+
class EnvironmentMismatchError extends Error {
|
|
63
|
+
constructor(message) {
|
|
64
|
+
super(message);
|
|
65
|
+
this.name = 'EnvironmentMismatchError';
|
|
66
|
+
Object.setPrototypeOf(this, EnvironmentMismatchError.prototype);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Detects if the code is running in a Node.js environment
|
|
72
|
+
*
|
|
73
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
74
|
+
*
|
|
75
|
+
* @public exported from `@promptbook/utils`
|
|
76
|
+
*/
|
|
77
|
+
function $isRunningInNode() {
|
|
78
|
+
try {
|
|
79
|
+
return typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// TODO: [🎺]
|
|
86
|
+
|
|
57
87
|
/**
|
|
58
88
|
* Trims string from all 4 sides
|
|
59
89
|
*
|
|
@@ -1438,36 +1468,6 @@ true);
|
|
|
1438
1468
|
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
1439
1469
|
*/
|
|
1440
1470
|
|
|
1441
|
-
/**
|
|
1442
|
-
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
1443
|
-
*
|
|
1444
|
-
* @public exported from `@promptbook/core`
|
|
1445
|
-
*/
|
|
1446
|
-
class EnvironmentMismatchError extends Error {
|
|
1447
|
-
constructor(message) {
|
|
1448
|
-
super(message);
|
|
1449
|
-
this.name = 'EnvironmentMismatchError';
|
|
1450
|
-
Object.setPrototypeOf(this, EnvironmentMismatchError.prototype);
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1454
|
-
/**
|
|
1455
|
-
* Detects if the code is running in a Node.js environment
|
|
1456
|
-
*
|
|
1457
|
-
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
1458
|
-
*
|
|
1459
|
-
* @public exported from `@promptbook/utils`
|
|
1460
|
-
*/
|
|
1461
|
-
function $isRunningInNode() {
|
|
1462
|
-
try {
|
|
1463
|
-
return typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
1464
|
-
}
|
|
1465
|
-
catch (e) {
|
|
1466
|
-
return false;
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
// TODO: [🎺]
|
|
1470
|
-
|
|
1471
1471
|
/**
|
|
1472
1472
|
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
1473
1473
|
*
|
|
@@ -39274,6 +39274,245 @@ function stripInlineKnowledgeMetadata(metadata) {
|
|
|
39274
39274
|
return Object.keys(rest).length > 0 ? rest : undefined;
|
|
39275
39275
|
}
|
|
39276
39276
|
|
|
39277
|
+
/**
|
|
39278
|
+
* Pattern matching a markdown section heading (`## Title`) that separates system-message sections
|
|
39279
|
+
*
|
|
39280
|
+
* @private internal constant of `deduplicateSystemMessage`
|
|
39281
|
+
*/
|
|
39282
|
+
const SYSTEM_MESSAGE_SECTION_HEADING_PATTERN = /^##(?!#)\s*(.+?)\s*$/;
|
|
39283
|
+
/**
|
|
39284
|
+
* Pattern matching a fenced code block delimiter which suspends section and block splitting
|
|
39285
|
+
*
|
|
39286
|
+
* @private internal constant of `deduplicateSystemMessage`
|
|
39287
|
+
*/
|
|
39288
|
+
const CODE_FENCE_PATTERN = /^\s*(?:```|~~~)/;
|
|
39289
|
+
/**
|
|
39290
|
+
* Pattern matching a markdown list item which keeps merged bullet lists visually compact
|
|
39291
|
+
*
|
|
39292
|
+
* @private internal constant of `deduplicateSystemMessage`
|
|
39293
|
+
*/
|
|
39294
|
+
const LIST_ITEM_PATTERN = /^\s*(?:[-*+]|\d+[.)])\s/;
|
|
39295
|
+
/**
|
|
39296
|
+
* Removes duplicated instructions from a generated system message
|
|
39297
|
+
*
|
|
39298
|
+
* Commitments are applied one by one, so a commitment used multiple times in one book repeats its whole
|
|
39299
|
+
* section, including the shared guidance preamble. For example two `WRITING RULES` commitments emit the
|
|
39300
|
+
* `## Writing rules` heading and its guidance paragraph twice. This function merges all sections sharing
|
|
39301
|
+
* one heading into the position of their first occurrence and keeps every identical block only once.
|
|
39302
|
+
*
|
|
39303
|
+
* @param systemMessage The assembled system message which may contain repeated sections and blocks
|
|
39304
|
+
* @returns The system message where each section heading and each identical block appears exactly once
|
|
39305
|
+
*
|
|
39306
|
+
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
39307
|
+
*/
|
|
39308
|
+
function deduplicateSystemMessage(systemMessage) {
|
|
39309
|
+
if (!systemMessage.trim()) {
|
|
39310
|
+
return systemMessage;
|
|
39311
|
+
}
|
|
39312
|
+
return splitSystemMessageIntoRegions(systemMessage)
|
|
39313
|
+
.reduce(mergeRegionSharingHeading, [])
|
|
39314
|
+
.map(removeDuplicateBlocksFromRegion)
|
|
39315
|
+
.map(renderRegion)
|
|
39316
|
+
.filter((renderedRegion) => renderedRegion !== '')
|
|
39317
|
+
.join('\n\n');
|
|
39318
|
+
}
|
|
39319
|
+
/**
|
|
39320
|
+
* Splits the system message into the intro region and one region per `## Title` section
|
|
39321
|
+
*
|
|
39322
|
+
* @param systemMessage The system message to split
|
|
39323
|
+
* @returns Regions in their original order, without empty ones
|
|
39324
|
+
*
|
|
39325
|
+
* @private internal utility of `deduplicateSystemMessage`
|
|
39326
|
+
*/
|
|
39327
|
+
function splitSystemMessageIntoRegions(systemMessage) {
|
|
39328
|
+
const regions = [];
|
|
39329
|
+
let headingLine = null;
|
|
39330
|
+
let bodyLines = [];
|
|
39331
|
+
let isInsideCodeFence = false;
|
|
39332
|
+
for (const line of systemMessage.split(/\r?\n/)) {
|
|
39333
|
+
if (CODE_FENCE_PATTERN.test(line)) {
|
|
39334
|
+
isInsideCodeFence = !isInsideCodeFence;
|
|
39335
|
+
}
|
|
39336
|
+
if (isInsideCodeFence || !SYSTEM_MESSAGE_SECTION_HEADING_PATTERN.test(line)) {
|
|
39337
|
+
bodyLines.push(line);
|
|
39338
|
+
continue;
|
|
39339
|
+
}
|
|
39340
|
+
regions.push(createRegion(headingLine, bodyLines));
|
|
39341
|
+
headingLine = line;
|
|
39342
|
+
bodyLines = [];
|
|
39343
|
+
}
|
|
39344
|
+
regions.push(createRegion(headingLine, bodyLines));
|
|
39345
|
+
return regions.filter((region) => region.headingLine !== null || region.blocks.length > 0);
|
|
39346
|
+
}
|
|
39347
|
+
/**
|
|
39348
|
+
* Creates one region from its heading line and its raw body lines
|
|
39349
|
+
*
|
|
39350
|
+
* @param headingLine The original `## Title` line, or `null` for the intro before the first heading
|
|
39351
|
+
* @param bodyLines The raw lines following the heading line
|
|
39352
|
+
* @returns The region with its body already split into blocks
|
|
39353
|
+
*
|
|
39354
|
+
* @private internal utility of `splitSystemMessageIntoRegions`
|
|
39355
|
+
*/
|
|
39356
|
+
function createRegion(headingLine, bodyLines) {
|
|
39357
|
+
return {
|
|
39358
|
+
titleKey: headingLine === null ? null : normalizeSectionTitle(headingLine),
|
|
39359
|
+
headingLine,
|
|
39360
|
+
isBodySeparatedByBlankLine: bodyLines[0] !== undefined && bodyLines[0].trim() === '',
|
|
39361
|
+
blocks: splitBodyIntoBlocks(bodyLines),
|
|
39362
|
+
};
|
|
39363
|
+
}
|
|
39364
|
+
/**
|
|
39365
|
+
* Normalizes a heading line into a key usable for matching sections which belong together
|
|
39366
|
+
*
|
|
39367
|
+
* @param headingLine The original `## Title` line
|
|
39368
|
+
* @returns Lowercased title without the markdown heading prefix
|
|
39369
|
+
*
|
|
39370
|
+
* @private internal utility of `createRegion`
|
|
39371
|
+
*/
|
|
39372
|
+
function normalizeSectionTitle(headingLine) {
|
|
39373
|
+
var _a, _b;
|
|
39374
|
+
return ((_b = (_a = SYSTEM_MESSAGE_SECTION_HEADING_PATTERN.exec(headingLine)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : headingLine).toLowerCase();
|
|
39375
|
+
}
|
|
39376
|
+
/**
|
|
39377
|
+
* Splits raw body lines into blocks separated by blank lines while keeping fenced code blocks intact
|
|
39378
|
+
*
|
|
39379
|
+
* @param bodyLines The raw lines of one region body
|
|
39380
|
+
* @returns Non-empty blocks in their original order
|
|
39381
|
+
*
|
|
39382
|
+
* @private internal utility of `createRegion`
|
|
39383
|
+
*/
|
|
39384
|
+
function splitBodyIntoBlocks(bodyLines) {
|
|
39385
|
+
const blockTexts = [];
|
|
39386
|
+
let blockLines = [];
|
|
39387
|
+
let isInsideCodeFence = false;
|
|
39388
|
+
for (const line of bodyLines) {
|
|
39389
|
+
if (CODE_FENCE_PATTERN.test(line)) {
|
|
39390
|
+
isInsideCodeFence = !isInsideCodeFence;
|
|
39391
|
+
}
|
|
39392
|
+
if (!isInsideCodeFence && line.trim() === '') {
|
|
39393
|
+
blockTexts.push(blockLines.join('\n'));
|
|
39394
|
+
blockLines = [];
|
|
39395
|
+
continue;
|
|
39396
|
+
}
|
|
39397
|
+
blockLines.push(line);
|
|
39398
|
+
}
|
|
39399
|
+
blockTexts.push(blockLines.join('\n'));
|
|
39400
|
+
return blockTexts
|
|
39401
|
+
.filter((blockText) => blockText.trim() !== '')
|
|
39402
|
+
.map((blockText) => ({ text: blockText, isOpeningMergedSection: false }));
|
|
39403
|
+
}
|
|
39404
|
+
/**
|
|
39405
|
+
* Appends one region to the already merged regions, merging it into an earlier region with the same heading
|
|
39406
|
+
*
|
|
39407
|
+
* @param mergedRegions Regions merged so far, used as the reducer accumulator
|
|
39408
|
+
* @param region The next region in original order
|
|
39409
|
+
* @returns The accumulator with the region either appended or merged into its earlier twin
|
|
39410
|
+
*
|
|
39411
|
+
* @private internal utility of `deduplicateSystemMessage`
|
|
39412
|
+
*/
|
|
39413
|
+
function mergeRegionSharingHeading(mergedRegions, region) {
|
|
39414
|
+
const existingRegionIndex = mergedRegions.findIndex((mergedRegion) => region.titleKey !== null && mergedRegion.titleKey === region.titleKey);
|
|
39415
|
+
if (existingRegionIndex === -1) {
|
|
39416
|
+
return [...mergedRegions, region];
|
|
39417
|
+
}
|
|
39418
|
+
return mergedRegions.map((mergedRegion, index) => index !== existingRegionIndex
|
|
39419
|
+
? mergedRegion
|
|
39420
|
+
: {
|
|
39421
|
+
...mergedRegion,
|
|
39422
|
+
blocks: [...mergedRegion.blocks, ...markFirstBlockAsOpeningMergedSection(region.blocks)],
|
|
39423
|
+
});
|
|
39424
|
+
}
|
|
39425
|
+
/**
|
|
39426
|
+
* Marks the first block of a merged section occurrence so the merge seam can be rendered as one list
|
|
39427
|
+
*
|
|
39428
|
+
* @param blocks The blocks of the section occurrence being merged into an earlier section
|
|
39429
|
+
* @returns The same blocks with the first one marked as opening a merged section
|
|
39430
|
+
*
|
|
39431
|
+
* @private internal utility of `mergeRegionSharingHeading`
|
|
39432
|
+
*/
|
|
39433
|
+
function markFirstBlockAsOpeningMergedSection(blocks) {
|
|
39434
|
+
return blocks.map((block, index) => (index === 0 ? { ...block, isOpeningMergedSection: true } : block));
|
|
39435
|
+
}
|
|
39436
|
+
/**
|
|
39437
|
+
* Keeps only the first occurrence of every identical block inside one region
|
|
39438
|
+
*
|
|
39439
|
+
* @param region The region whose blocks may repeat
|
|
39440
|
+
* @returns The region without repeated blocks
|
|
39441
|
+
*
|
|
39442
|
+
* @private internal utility of `deduplicateSystemMessage`
|
|
39443
|
+
*/
|
|
39444
|
+
function removeDuplicateBlocksFromRegion(region) {
|
|
39445
|
+
const alreadyRenderedTexts = new Set();
|
|
39446
|
+
const uniqueBlocks = [];
|
|
39447
|
+
let isMergeSeamPending = false;
|
|
39448
|
+
for (const block of region.blocks) {
|
|
39449
|
+
if (alreadyRenderedTexts.has(block.text)) {
|
|
39450
|
+
// Note: A removed block must still hand its merge seam over to the next block which survives
|
|
39451
|
+
isMergeSeamPending = isMergeSeamPending || block.isOpeningMergedSection;
|
|
39452
|
+
continue;
|
|
39453
|
+
}
|
|
39454
|
+
alreadyRenderedTexts.add(block.text);
|
|
39455
|
+
uniqueBlocks.push({
|
|
39456
|
+
text: block.text,
|
|
39457
|
+
isOpeningMergedSection: block.isOpeningMergedSection || isMergeSeamPending,
|
|
39458
|
+
});
|
|
39459
|
+
isMergeSeamPending = false;
|
|
39460
|
+
}
|
|
39461
|
+
return { ...region, blocks: uniqueBlocks };
|
|
39462
|
+
}
|
|
39463
|
+
/**
|
|
39464
|
+
* Renders one region back into its markdown representation
|
|
39465
|
+
*
|
|
39466
|
+
* @param region The region to render
|
|
39467
|
+
* @returns The heading line together with its joined blocks
|
|
39468
|
+
*
|
|
39469
|
+
* @private internal utility of `deduplicateSystemMessage`
|
|
39470
|
+
*/
|
|
39471
|
+
function renderRegion(region) {
|
|
39472
|
+
const body = joinBlocks(region.blocks);
|
|
39473
|
+
if (region.headingLine === null) {
|
|
39474
|
+
return body;
|
|
39475
|
+
}
|
|
39476
|
+
if (body === '') {
|
|
39477
|
+
return region.headingLine;
|
|
39478
|
+
}
|
|
39479
|
+
return `${region.headingLine}${region.isBodySeparatedByBlankLine ? '\n\n' : '\n'}${body}`;
|
|
39480
|
+
}
|
|
39481
|
+
/**
|
|
39482
|
+
* Joins blocks of one region back together
|
|
39483
|
+
*
|
|
39484
|
+
* @param blocks The blocks to join in their original order
|
|
39485
|
+
* @returns The joined body of one region
|
|
39486
|
+
*
|
|
39487
|
+
* @private internal utility of `renderRegion`
|
|
39488
|
+
*/
|
|
39489
|
+
function joinBlocks(blocks) {
|
|
39490
|
+
return blocks
|
|
39491
|
+
.map((block, index) => index === 0 ? block.text : `${createBlockSeparator(blocks[index - 1], block)}${block.text}`)
|
|
39492
|
+
.join('');
|
|
39493
|
+
}
|
|
39494
|
+
/**
|
|
39495
|
+
* Chooses the separator between two neighboring blocks
|
|
39496
|
+
*
|
|
39497
|
+
* Blocks are normally separated by a blank line, exactly as they were written. Only where two sections were
|
|
39498
|
+
* merged together their lists are joined into one compact list instead of two separate ones.
|
|
39499
|
+
*
|
|
39500
|
+
* @param previousBlock The block rendered before the separator
|
|
39501
|
+
* @param nextBlock The block rendered after the separator
|
|
39502
|
+
* @returns Either a single or a double newline
|
|
39503
|
+
*
|
|
39504
|
+
* @private internal utility of `joinBlocks`
|
|
39505
|
+
*/
|
|
39506
|
+
function createBlockSeparator(previousBlock, nextBlock) {
|
|
39507
|
+
if (!nextBlock.isOpeningMergedSection) {
|
|
39508
|
+
return '\n\n';
|
|
39509
|
+
}
|
|
39510
|
+
const previousBlockLines = previousBlock.text.split('\n');
|
|
39511
|
+
const isListContinuing = LIST_ITEM_PATTERN.test(previousBlockLines[previousBlockLines.length - 1]) &&
|
|
39512
|
+
LIST_ITEM_PATTERN.test(nextBlock.text.split('\n')[0]);
|
|
39513
|
+
return isListContinuing ? '\n' : '\n\n';
|
|
39514
|
+
}
|
|
39515
|
+
|
|
39277
39516
|
/**
|
|
39278
39517
|
* Removes single-hash comment lines (`# Comment`) from a system message
|
|
39279
39518
|
* This is used to clean up the final system message before sending it to the AI model
|
|
@@ -39347,14 +39586,14 @@ function createInitialAgentModelRequirements(agentName, modelName) {
|
|
|
39347
39586
|
* Performs the final system-message cleanup pass after all other augmentation steps are complete.
|
|
39348
39587
|
*
|
|
39349
39588
|
* @param requirements - Fully built requirements before final cleanup.
|
|
39350
|
-
* @returns Requirements with comment lines removed
|
|
39589
|
+
* @returns Requirements with comment lines removed and repeated instructions deduplicated in the final system message.
|
|
39351
39590
|
*
|
|
39352
39591
|
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
39353
39592
|
*/
|
|
39354
39593
|
function finalizeRequirements(requirements) {
|
|
39355
39594
|
return {
|
|
39356
39595
|
...requirements,
|
|
39357
|
-
systemMessage: removeCommentsFromSystemMessage(requirements.systemMessage),
|
|
39596
|
+
systemMessage: deduplicateSystemMessage(removeCommentsFromSystemMessage(requirements.systemMessage)),
|
|
39358
39597
|
};
|
|
39359
39598
|
}
|
|
39360
39599
|
|
|
@@ -58701,6 +58940,43 @@ const DEPRECATED_TOP_LEVEL_COMMAND_MESSAGES = {
|
|
|
58701
58940
|
'start-agents-server': 'Use `ptbk agents-server start` instead.',
|
|
58702
58941
|
'start-pipelines-server': OLD_PIPELINE_SYSTEM_DEPRECATION_MESSAGE,
|
|
58703
58942
|
};
|
|
58943
|
+
/**
|
|
58944
|
+
* Registers the CLI commands on a fresh Commander program without parsing arguments or running an action.
|
|
58945
|
+
* Tests can configure output and exit handling before registration, so subcommands inherit those settings.
|
|
58946
|
+
*
|
|
58947
|
+
* @private internal utility of `promptbookCli`
|
|
58948
|
+
*/
|
|
58949
|
+
function $initializePromptbookCliProgram(program) {
|
|
58950
|
+
program.name('promptbook');
|
|
58951
|
+
program.alias('ptbk');
|
|
58952
|
+
program.version(PROMPTBOOK_ENGINE_VERSION);
|
|
58953
|
+
program.description(CLAIM);
|
|
58954
|
+
// Commands are listed in registration order. Keep `coder` first and hide deprecated commands below.
|
|
58955
|
+
$initializeCoderCommand(program);
|
|
58956
|
+
$initializeAgentCommand(program);
|
|
58957
|
+
$initializeAgentFolderCommand(program);
|
|
58958
|
+
$initializeAgentsServerCommand(program);
|
|
58959
|
+
$initializeAboutCommand(program);
|
|
58960
|
+
$initializeHelloCommand(program);
|
|
58961
|
+
$initializeRunCommand(program);
|
|
58962
|
+
$initializeLoginCommand(program);
|
|
58963
|
+
$initializeMakeCommand(program);
|
|
58964
|
+
$initializePrettifyCommand(program);
|
|
58965
|
+
$initializeTestCommand(program);
|
|
58966
|
+
$initializeListModelsCommand(program);
|
|
58967
|
+
$initializeListScrapersCommand(program);
|
|
58968
|
+
$initializeStartAgentsServerCommand(program);
|
|
58969
|
+
$initializeStartPipelinesServerCommand(program);
|
|
58970
|
+
for (const command of program.commands) {
|
|
58971
|
+
const deprecationMessage = DEPRECATED_TOP_LEVEL_COMMAND_MESSAGES[command.name()];
|
|
58972
|
+
if (deprecationMessage !== undefined) {
|
|
58973
|
+
$deprecateCliCommand(command, deprecationMessage);
|
|
58974
|
+
}
|
|
58975
|
+
}
|
|
58976
|
+
program.commands.forEach($addGlobalOptionsToCommand);
|
|
58977
|
+
}
|
|
58978
|
+
// Note: [🟡] Code for CLI command registration [$initializePromptbookCliProgram](src/cli/$initializePromptbookCliProgram.ts) should never be published outside of `@promptbook/cli`
|
|
58979
|
+
|
|
58704
58980
|
/**
|
|
58705
58981
|
* Raw top-level CLI arguments that print the Promptbook version.
|
|
58706
58982
|
*
|
|
@@ -58733,32 +59009,7 @@ async function promptbookCli() {
|
|
|
58733
59009
|
console.info(colors.gray(`Promptbook CLI version ${PROMPTBOOK_ENGINE_VERSION} in ${__filename.split('\\').join('/')}`));
|
|
58734
59010
|
}
|
|
58735
59011
|
const program = new commander.Command();
|
|
58736
|
-
program
|
|
58737
|
-
program.alias('ptbk');
|
|
58738
|
-
program.version(PROMPTBOOK_ENGINE_VERSION);
|
|
58739
|
-
program.description(CLAIM);
|
|
58740
|
-
// Note: These options are valid for all commands
|
|
58741
|
-
// Note: Commands are listed in the help in the order they are registered,
|
|
58742
|
-
// `coder` is the most used one so it goes first and the deprecated ones,
|
|
58743
|
-
// which `$deprecateTopLevelCommands` hides from the help entirely, go last
|
|
58744
|
-
$initializeCoderCommand(program);
|
|
58745
|
-
$initializeAgentCommand(program);
|
|
58746
|
-
$initializeAgentFolderCommand(program);
|
|
58747
|
-
$initializeAgentsServerCommand(program);
|
|
58748
|
-
$initializeAboutCommand(program);
|
|
58749
|
-
$initializeHelloCommand(program);
|
|
58750
|
-
$initializeRunCommand(program);
|
|
58751
|
-
$initializeLoginCommand(program);
|
|
58752
|
-
$initializeMakeCommand(program);
|
|
58753
|
-
$initializePrettifyCommand(program);
|
|
58754
|
-
$initializeTestCommand(program);
|
|
58755
|
-
$initializeListModelsCommand(program);
|
|
58756
|
-
$initializeListScrapersCommand(program);
|
|
58757
|
-
$initializeStartAgentsServerCommand(program);
|
|
58758
|
-
$initializeStartPipelinesServerCommand(program);
|
|
58759
|
-
$deprecateTopLevelCommands(program);
|
|
58760
|
-
// TODO: [🧠] Should it be here or not> $addGlobalOptionsToCommand(program);
|
|
58761
|
-
program.commands.forEach($addGlobalOptionsToCommand);
|
|
59012
|
+
$initializePromptbookCliProgram(program);
|
|
58762
59013
|
// Note: There is no default command, so `ptbk` without a subcommand asks for one
|
|
58763
59014
|
// instead of running the deprecated `ptbk run`
|
|
58764
59015
|
if (commandLineArguments.length === 0) {
|
|
@@ -58775,17 +59026,6 @@ function isTopLevelVersionRequested(commandLineArguments) {
|
|
|
58775
59026
|
const firstCommandLineArgument = commandLineArguments[0];
|
|
58776
59027
|
return firstCommandLineArgument !== undefined && VERSION_OPTION_ARGUMENTS.has(firstCommandLineArgument);
|
|
58777
59028
|
}
|
|
58778
|
-
/**
|
|
58779
|
-
* Marks each configured top-level legacy command as deprecated, which keeps it usable but takes it out of the help.
|
|
58780
|
-
*/
|
|
58781
|
-
function $deprecateTopLevelCommands(program) {
|
|
58782
|
-
for (const command of program.commands) {
|
|
58783
|
-
const deprecationMessage = DEPRECATED_TOP_LEVEL_COMMAND_MESSAGES[command.name()];
|
|
58784
|
-
if (deprecationMessage !== undefined) {
|
|
58785
|
-
$deprecateCliCommand(command, deprecationMessage);
|
|
58786
|
-
}
|
|
58787
|
-
}
|
|
58788
|
-
}
|
|
58789
59029
|
// Note: [🟡] Code for CLI program [promptbookCli](src/cli/promptbookCli.ts) should never be published outside of `@promptbook/cli`
|
|
58790
59030
|
// TODO: [🥠] Do not export, its just for CLI script
|
|
58791
59031
|
// TODO: [🕌] When more functionalities, rename
|
|
@@ -75610,13 +75850,16 @@ async function resolveCoderAgentBook(agentBookReference, currentWorkingDirectory
|
|
|
75610
75850
|
}
|
|
75611
75851
|
throw error;
|
|
75612
75852
|
}));
|
|
75853
|
+
// Note: Parsed once here, because both the display name of the agent and its routing references need it
|
|
75854
|
+
const parsedAgentSource = parseAgentSource(agentSource);
|
|
75613
75855
|
return {
|
|
75614
75856
|
agentSource,
|
|
75857
|
+
agentName: parsedAgentSource.meta.fullname || parsedAgentSource.agentName,
|
|
75615
75858
|
agentReferences: createCoderAgentReferences({
|
|
75616
75859
|
agentBookReference: normalizedAgentBookReference,
|
|
75617
75860
|
resolvedAgentBookPath,
|
|
75618
75861
|
currentWorkingDirectory,
|
|
75619
|
-
|
|
75862
|
+
normalizedAgentNameFromBook: parsedAgentSource.agentName,
|
|
75620
75863
|
}),
|
|
75621
75864
|
};
|
|
75622
75865
|
}
|
|
@@ -75644,13 +75887,12 @@ function createCoderAgentReferences(options) {
|
|
|
75644
75887
|
const relativeAgentBookPath = relative(options.currentWorkingDirectory, options.resolvedAgentBookPath).replaceAll('\\', '/');
|
|
75645
75888
|
const agentBookFileName = basename(options.resolvedAgentBookPath);
|
|
75646
75889
|
const agentBookName = basename(options.resolvedAgentBookPath, extname(options.resolvedAgentBookPath));
|
|
75647
|
-
const agentNameFromBook = parseAgentSource(options.agentSource).agentName;
|
|
75648
75890
|
return Array.from(new Set([
|
|
75649
75891
|
options.agentBookReference,
|
|
75650
75892
|
relativeAgentBookPath,
|
|
75651
75893
|
agentBookFileName,
|
|
75652
75894
|
agentBookName,
|
|
75653
|
-
|
|
75895
|
+
options.normalizedAgentNameFromBook,
|
|
75654
75896
|
].filter((agentReference) => agentReference.trim() !== '')));
|
|
75655
75897
|
}
|
|
75656
75898
|
|
|
@@ -75913,11 +76155,27 @@ function formatUsagePrice(usage) {
|
|
|
75913
76155
|
|
|
75914
76156
|
/**
|
|
75915
76157
|
* Formats runner details for prompt status lines.
|
|
76158
|
+
*
|
|
76159
|
+
* Produces `` OpenAI Codex `gpt-5.6-luna` thinking `max` `` for a plain run and
|
|
76160
|
+
* `` Developer on OpenAI Codex `gpt-5.6-luna` thinking `max` `` for a run personalized with `--agent`.
|
|
76161
|
+
*/
|
|
76162
|
+
function formatRunnerSignature(options) {
|
|
76163
|
+
var _a;
|
|
76164
|
+
const normalizedAgentName = (_a = options.agentName) === null || _a === void 0 ? void 0 : _a.trim();
|
|
76165
|
+
const harnessSignature = formatHarnessSignature(options);
|
|
76166
|
+
if (!normalizedAgentName) {
|
|
76167
|
+
return harnessSignature;
|
|
76168
|
+
}
|
|
76169
|
+
return `${normalizedAgentName} on ${harnessSignature}`;
|
|
76170
|
+
}
|
|
76171
|
+
/**
|
|
76172
|
+
* Formats the harness part of one runner signature, which names the harness, its model and its thinking level.
|
|
75916
76173
|
*/
|
|
75917
|
-
function
|
|
75918
|
-
|
|
75919
|
-
const
|
|
75920
|
-
const
|
|
76174
|
+
function formatHarnessSignature(options) {
|
|
76175
|
+
var _a, _b;
|
|
76176
|
+
const normalizedRunner = (_a = options.runnerName) === null || _a === void 0 ? void 0 : _a.trim();
|
|
76177
|
+
const normalizedModel = (_b = options.modelName) === null || _b === void 0 ? void 0 : _b.trim();
|
|
76178
|
+
const thinkingLevelSuffix = options.thinkingLevel ? ` thinking \`${options.thinkingLevel}\`` : '';
|
|
75921
76179
|
if (!normalizedRunner && !normalizedModel) {
|
|
75922
76180
|
return 'unknown';
|
|
75923
76181
|
}
|
|
@@ -75932,7 +76190,12 @@ function formatRunnerSignature(runnerName, modelName, thinkingLevel) {
|
|
|
75932
76190
|
* Prints the compact summary of one finished `ptbk coder ping`.
|
|
75933
76191
|
*/
|
|
75934
76192
|
function printCoderPingResult(result) {
|
|
75935
|
-
|
|
76193
|
+
// Note: `ptbk coder ping` measures one harness alone, it never runs the prompts of a Book agent
|
|
76194
|
+
const runnerSignature = formatRunnerSignature({
|
|
76195
|
+
runnerName: result.runnerName,
|
|
76196
|
+
modelName: result.modelName,
|
|
76197
|
+
thinkingLevel: result.thinkingLevel,
|
|
76198
|
+
});
|
|
75936
76199
|
const loginMethodLabel = formatCodexLoginMethod(result.loginMethod);
|
|
75937
76200
|
const loginMethodSuffix = loginMethodLabel === undefined ? '' : ` (${loginMethodLabel})`;
|
|
75938
76201
|
console.info(colors.green(`🏓 ${runnerSignature}${loginMethodSuffix} answered in ${formatCoderPingResponseTime(result.durationMs)}`));
|
|
@@ -78420,11 +78683,11 @@ function toPromptRunnerAttribution(runnerSignatures) {
|
|
|
78420
78683
|
* Builds the shared body of a prompt status line, used by both the in-progress `[^]` and the done `[x]` status.
|
|
78421
78684
|
*
|
|
78422
78685
|
* Produces details such as
|
|
78423
|
-
* ``by OpenAI Codex `gpt-5.6-luna` thinking `max` (ChatGPT account) - Implementation ~$0.2036 10 minutes``.
|
|
78686
|
+
* ``by Developer on OpenAI Codex `gpt-5.6-luna` thinking `max` (ChatGPT account) - Implementation ~$0.2036 10 minutes``.
|
|
78424
78687
|
*/
|
|
78425
78688
|
function buildPromptStatusDetails(options) {
|
|
78426
|
-
const { steps, inProgressStepKind,
|
|
78427
|
-
const runnerSignature = formatRunnerSignature(
|
|
78689
|
+
const { steps, inProgressStepKind, previousRunnerSignatures, attemptCount, loginMethod } = options;
|
|
78690
|
+
const runnerSignature = formatRunnerSignature(options);
|
|
78428
78691
|
const attemptMetadata = formatPromptAttemptMetadata('done', attemptCount);
|
|
78429
78692
|
const loginMethodLabel = formatCodexLoginMethod(loginMethod);
|
|
78430
78693
|
const loginMethodSuffix = loginMethodLabel ? ` (${loginMethodLabel})` : '';
|
|
@@ -78536,9 +78799,9 @@ function markPromptDone(options) {
|
|
|
78536
78799
|
* Marks a prompt section as failed and records runner details.
|
|
78537
78800
|
*/
|
|
78538
78801
|
function markPromptFailed(options) {
|
|
78539
|
-
const { file, section,
|
|
78802
|
+
const { file, section, previousRunnerSignatures, promptExecutionStartedDate, attemptCount } = options;
|
|
78540
78803
|
const attribution = formatPromptRunnerAttribution({
|
|
78541
|
-
currentRunnerSignature: formatRunnerSignature(
|
|
78804
|
+
currentRunnerSignature: formatRunnerSignature(options),
|
|
78542
78805
|
previousRunnerSignatures,
|
|
78543
78806
|
});
|
|
78544
78807
|
const attemptMetadata = formatPromptAttemptMetadata('failed', attemptCount);
|
|
@@ -78624,9 +78887,9 @@ function getSafeCodeBlock(content, language = 'markdown') {
|
|
|
78624
78887
|
/**
|
|
78625
78888
|
* Renders the markdown run trace of one finished or failed prompt round.
|
|
78626
78889
|
*
|
|
78627
|
-
* The trace pairs the metadata of the round - which harness, model and thinking level ran it, how long
|
|
78628
|
-
* its steps took and what it cost - with the untouched runtime log, so a finished round can still be
|
|
78629
|
-
* after its temporary artifacts are cleaned up.
|
|
78890
|
+
* The trace pairs the metadata of the round - which agent, harness, model and thinking level ran it, how long
|
|
78891
|
+
* each of its steps took and what it cost - with the untouched runtime log, so a finished round can still be
|
|
78892
|
+
* analyzed after its temporary artifacts are cleaned up.
|
|
78630
78893
|
*/
|
|
78631
78894
|
function buildPromptRunTraceContent(options) {
|
|
78632
78895
|
const sections = [
|
|
@@ -78641,7 +78904,7 @@ function buildPromptRunTraceContent(options) {
|
|
|
78641
78904
|
*/
|
|
78642
78905
|
function buildPromptRunTraceSummarySection(options) {
|
|
78643
78906
|
const { file, section, outcome } = options;
|
|
78644
|
-
const runnerSignature = formatRunnerSignature(options
|
|
78907
|
+
const runnerSignature = formatRunnerSignature(options);
|
|
78645
78908
|
const loginMethodLabel = outcome.kind === 'succeeded' ? formatCodexLoginMethod(outcome.loginMethod) : undefined;
|
|
78646
78909
|
const loginMethodSuffix = loginMethodLabel ? ` (${loginMethodLabel})` : '';
|
|
78647
78910
|
const detailLines = [
|
|
@@ -78951,8 +79214,7 @@ async function recordPromptRoundInProgress(options) {
|
|
|
78951
79214
|
section: nextPrompt.section,
|
|
78952
79215
|
steps: progress.finishedSteps,
|
|
78953
79216
|
inProgressStepKind: progress.startedStepKind,
|
|
78954
|
-
|
|
78955
|
-
modelName: runnerMetadata.modelName,
|
|
79217
|
+
...runnerMetadata,
|
|
78956
79218
|
previousRunnerSignatures,
|
|
78957
79219
|
attemptCount,
|
|
78958
79220
|
loginMethod: progress.loginMethod,
|
|
@@ -79022,8 +79284,7 @@ async function finalizeSuccessfulPromptRound(options) {
|
|
|
79022
79284
|
file: nextPrompt.file,
|
|
79023
79285
|
section: nextPrompt.section,
|
|
79024
79286
|
steps: result.steps,
|
|
79025
|
-
|
|
79026
|
-
modelName: runnerMetadata.modelName,
|
|
79287
|
+
...runnerMetadata,
|
|
79027
79288
|
previousRunnerSignatures,
|
|
79028
79289
|
attemptCount: result.attemptCount,
|
|
79029
79290
|
loginMethod: result.loginMethod,
|
|
@@ -79102,8 +79363,7 @@ async function finalizeFailedPromptRound(options) {
|
|
|
79102
79363
|
markPromptFailed({
|
|
79103
79364
|
file: nextPrompt.file,
|
|
79104
79365
|
section: nextPrompt.section,
|
|
79105
|
-
|
|
79106
|
-
modelName: runnerMetadata.modelName,
|
|
79366
|
+
...runnerMetadata,
|
|
79107
79367
|
previousRunnerSignatures,
|
|
79108
79368
|
promptExecutionStartedDate,
|
|
79109
79369
|
attemptCount,
|
|
@@ -79133,16 +79393,15 @@ async function finalizeFailedPromptRound(options) {
|
|
|
79133
79393
|
* Persists the run trace of one prompt round, so the round can still be analyzed after its temporary
|
|
79134
79394
|
* artifacts are gone.
|
|
79135
79395
|
*
|
|
79136
|
-
* This is the single place where both the successful and the failed round record what they did, which
|
|
79137
|
-
* model and thinking level did it and everything that harness has written while doing it.
|
|
79396
|
+
* This is the single place where both the successful and the failed round record what they did, which agent,
|
|
79397
|
+
* harness, model and thinking level did it and everything that harness has written while doing it.
|
|
79138
79398
|
*/
|
|
79139
79399
|
async function recordPromptRoundTrace(options) {
|
|
79140
79400
|
const { options: runOptions, nextPrompt, runnerMetadata, promptExecutionStartedDate, attemptCount, logPath, outcome, } = options;
|
|
79141
79401
|
await writePromptRunTrace({
|
|
79142
79402
|
file: nextPrompt.file,
|
|
79143
79403
|
section: nextPrompt.section,
|
|
79144
|
-
|
|
79145
|
-
modelName: runnerMetadata.modelName,
|
|
79404
|
+
...runnerMetadata,
|
|
79146
79405
|
thinkingLevel: runOptions.thinkingLevel,
|
|
79147
79406
|
testCommand: runOptions.testCommand,
|
|
79148
79407
|
attemptCount,
|
|
@@ -80106,7 +80365,13 @@ async function runCodexPrompts(providedOptions) {
|
|
|
80106
80365
|
if (await runDryRunIfRequested(options)) {
|
|
80107
80366
|
return;
|
|
80108
80367
|
}
|
|
80109
|
-
const { runner, actualRunnerModel, runnerMetadata } = resolvePromptRunner(options);
|
|
80368
|
+
const { runner, actualRunnerModel, runnerMetadata: harnessRunnerMetadata } = resolvePromptRunner(options);
|
|
80369
|
+
// Note: The harness only knows itself, so the Book agent it runs as is joined here - this is the single
|
|
80370
|
+
// place where the whole run report of prompt status lines and run traces is put together
|
|
80371
|
+
const runnerMetadata = {
|
|
80372
|
+
...harnessRunnerMetadata,
|
|
80373
|
+
agentName: resolvedCoderAgent === null || resolvedCoderAgent === void 0 ? void 0 : resolvedCoderAgent.agentName,
|
|
80374
|
+
};
|
|
80110
80375
|
const promptRunnerIdentity = {
|
|
80111
80376
|
harnessName: options.agentName,
|
|
80112
80377
|
modelName: actualRunnerModel,
|