@promptbook/cli 0.113.0-5 → 0.113.0-8

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 (123) hide show
  1. package/apps/agents-server/src/app/admin/update/AdvancedOriginRepositoryPanel.tsx +76 -0
  2. package/apps/agents-server/src/app/admin/update/CurrentDeploymentCard.tsx +160 -0
  3. package/apps/agents-server/src/app/admin/update/PendingCommitsCard.tsx +86 -0
  4. package/apps/agents-server/src/app/admin/update/TargetEnvironmentCard.tsx +331 -0
  5. package/apps/agents-server/src/app/admin/update/UpdateClient.tsx +20 -873
  6. package/apps/agents-server/src/app/admin/update/UpdateJobCard.tsx +329 -0
  7. package/apps/agents-server/src/app/admin/update/UpdateOverview.ts +74 -0
  8. package/apps/agents-server/src/app/admin/update/buildDeploymentTimeBehindLabel.ts +29 -0
  9. package/apps/agents-server/src/app/admin/update/formatHumanReadableTimestamp.ts +18 -0
  10. package/apps/agents-server/src/app/admin/update/getUpdateJobFailureMessage.ts +13 -0
  11. package/apps/agents-server/src/app/admin/update/getUpdateJobSuccessMessage.ts +13 -0
  12. package/apps/agents-server/src/app/admin/update/useUpdateClientState.ts +441 -0
  13. package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +13 -1
  14. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/AgentCodePageClient.tsx +14 -559
  15. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/AgentCodePageHeader.tsx +84 -0
  16. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/AgentCodePageSection.tsx +52 -0
  17. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/GeneratedCodePreview.tsx +138 -0
  18. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/GeneratedHarnessSection.tsx +98 -0
  19. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/SourceBookSection.tsx +66 -0
  20. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/TranspiledCodeErrorBanner.tsx +30 -0
  21. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/TranspiledCodeExportWarningBanner.tsx +62 -0
  22. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/Transpiler.ts +9 -0
  23. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/useAgentCodeExportState.ts +478 -0
  24. package/apps/agents-server/src/app/system/utilities/mocked-chats/cloneMockedChatPreset.ts +17 -0
  25. package/apps/agents-server/src/app/system/utilities/mocked-chats/confirmDeleteMockedChat.ts +16 -0
  26. package/apps/agents-server/src/app/system/utilities/mocked-chats/createDraftWithUpdatedMessage.ts +81 -0
  27. package/apps/agents-server/src/app/system/utilities/mocked-chats/createDraftWithUpdatedParticipant.ts +146 -0
  28. package/apps/agents-server/src/app/system/utilities/mocked-chats/createDraftWithUpdatedSettings.ts +19 -0
  29. package/apps/agents-server/src/app/system/utilities/mocked-chats/createDuplicatedDraft.ts +66 -0
  30. package/apps/agents-server/src/app/system/utilities/mocked-chats/findMockedChatById.ts +51 -0
  31. package/apps/agents-server/src/app/system/utilities/mocked-chats/persistMockedChats.ts +51 -0
  32. package/apps/agents-server/src/app/system/utilities/mocked-chats/useMockedChatsEditorState.ts +16 -426
  33. package/apps/agents-server/src/components/Homepage/buildFreeGraphBoxLayout.ts +446 -0
  34. package/apps/agents-server/src/components/Homepage/buildGraphLayoutNodes.ts +415 -157
  35. package/apps/agents-server/src/components/Homepage/useAgentsGraphCanvasState.ts +2 -1
  36. package/apps/agents-server/src/database/sqlite/$provideLocalSqliteSupabase.ts +3 -1541
  37. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/LocalSqliteQueryBuilder.ts +623 -0
  38. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/LocalSqliteSupabaseClient.ts +64 -0
  39. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/ensureTable.ts +93 -0
  40. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteFilters.ts +202 -0
  41. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteMutationPayload.ts +131 -0
  42. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteRowOperations.ts +102 -0
  43. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteSql.ts +59 -0
  44. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteTableSchema.ts +329 -0
  45. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteTypes.ts +84 -0
  46. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteValueCodec.ts +63 -0
  47. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/normalizeSqliteError.ts +22 -0
  48. package/apps/agents-server/src/search/createDefaultServerSearchProviders/loadLocalOrganizationSearchDataset.ts +12 -1
  49. package/apps/agents-server/src/tools/send_email.ts +1 -2
  50. package/apps/agents-server/src/utils/agentOrganization/loadAgentOrganizationState.ts +13 -1
  51. package/apps/agents-server/src/utils/backup/createServerBackupZipStream.ts +7 -1382
  52. package/apps/agents-server/src/utils/backup/serverBackup/appendAgentBackupEntriesToZip.ts +27 -0
  53. package/apps/agents-server/src/utils/backup/serverBackup/appendConversationBackupEntriesToZip.ts +140 -0
  54. package/apps/agents-server/src/utils/backup/serverBackup/appendFileBackupEntriesToZip.ts +147 -0
  55. package/apps/agents-server/src/utils/backup/serverBackup/appendMessageBackupEntriesToZip.ts +65 -0
  56. package/apps/agents-server/src/utils/backup/serverBackup/appendMetadataBackupEntriesToZip.ts +39 -0
  57. package/apps/agents-server/src/utils/backup/serverBackup/appendSectionEntriesToZip.ts +92 -0
  58. package/apps/agents-server/src/utils/backup/serverBackup/appendUserBackupEntriesToZip.ts +80 -0
  59. package/apps/agents-server/src/utils/backup/serverBackup/createRedactedWalletBackupRecord.ts +34 -0
  60. package/apps/agents-server/src/utils/backup/serverBackup/createServerBackupManifest.ts +82 -0
  61. package/apps/agents-server/src/utils/backup/serverBackup/downloadBackupBinaryContent.ts +39 -0
  62. package/apps/agents-server/src/utils/backup/serverBackup/resolveFeedbackThreadMessages.ts +53 -0
  63. package/apps/agents-server/src/utils/backup/serverBackup/serverBackupAttachments.ts +151 -0
  64. package/apps/agents-server/src/utils/backup/serverBackup/serverBackupContext.ts +167 -0
  65. package/apps/agents-server/src/utils/backup/serverBackup/serverBackupFilenames.ts +161 -0
  66. package/apps/agents-server/src/utils/backup/serverBackup/serverBackupPreviews.ts +97 -0
  67. package/apps/agents-server/src/utils/backup/serverBackup/serverBackupRowUtilities.ts +158 -0
  68. package/apps/agents-server/src/utils/backup/serverBackup/serverBackupTypes.ts +59 -0
  69. package/apps/agents-server/src/utils/createLocalAgentSourceImporter.ts +159 -0
  70. package/apps/agents-server/src/utils/createMissingImportedAgentFallback.ts +60 -0
  71. package/apps/agents-server/src/utils/customDomainRouting.ts +157 -12
  72. package/apps/agents-server/src/utils/externalChatRunner/processExternalUserChatJob.ts +1 -1
  73. package/apps/agents-server/src/utils/importAgentWithFallback.ts +1 -58
  74. package/apps/agents-server/src/utils/localAgentRouteReferences.ts +167 -0
  75. package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +1 -1
  76. package/apps/agents-server/src/utils/managementApi/managementApiAgents.ts +17 -3
  77. package/apps/agents-server/src/utils/messages/sendMessage.ts +5 -3
  78. package/apps/agents-server/src/utils/resolveAgentStateFromSource.ts +7 -1
  79. package/apps/agents-server/src/utils/resolveInheritedAgentSource.ts +54 -5
  80. package/apps/agents-server/src/utils/resolveServerAgentContext.ts +12 -1
  81. package/apps/agents-server/src/utils/resolveStoredAgentState.ts +2 -1
  82. package/apps/agents-server/src/utils/speech-to-text/SpeechToTextFailoverRecognition/SpeechToTextFailoverRecognitionProviderRuntime.ts +0 -1
  83. package/apps/agents-server/src/utils/speech-to-text/SpeechToTextFailoverRecognition.ts +34 -2
  84. package/apps/agents-server/src/utils/userChat/userChatMessageLifecycle.ts +39 -9
  85. package/apps/agents-server/tests/e2e/support/ChatHistoryNavigationSupport.ts +5 -0
  86. package/esm/index.es.js +96 -57
  87. package/esm/index.es.js.map +1 -1
  88. package/esm/scripts/find-refactor-candidates/find-refactor-candidates.d.ts +7 -0
  89. package/esm/scripts/find-refactor-candidates/selectMostImportantRefactorCandidates.d.ts +12 -0
  90. package/esm/src/book-components/Chat/Chat/insertDictationChunk.d.ts +1 -1
  91. package/esm/src/book-components/Chat/Chat/insertDictationChunk.test.d.ts +1 -0
  92. package/esm/src/book-components/Chat/Chat/learnDictationDictionary.test.d.ts +1 -0
  93. package/esm/src/book-components/Chat/Chat/refineFinalDictationChunk.test.d.ts +1 -0
  94. package/esm/src/cli/cli-commands/common/createPositiveIntegerOptionParser.d.ts +10 -0
  95. package/esm/src/version.d.ts +1 -1
  96. package/package.json +1 -1
  97. package/src/avatars/avatarAnimationScheduler.ts +2 -1
  98. package/src/avatars/visuals/octopus3d3AvatarVisual.ts +6 -2
  99. package/src/avatars/visuals/octopus3d4AvatarVisual.ts +14 -18
  100. package/src/book-components/Chat/Chat/insertDictationChunk.ts +3 -3
  101. package/src/book-components/Chat/Chat/learnDictationDictionary.ts +1 -1
  102. package/src/book-components/Chat/Chat/useChatInputAreaDictation.ts +133 -26
  103. package/src/cli/cli-commands/agents-server/buildAgentsServer.ts +3 -1
  104. package/src/cli/cli-commands/coder/boilerplateTemplates.ts +14 -21
  105. package/src/cli/cli-commands/coder/find-refactor-candidates.ts +9 -2
  106. package/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.ts +1 -4
  107. package/src/cli/cli-commands/coder/run.ts +3 -27
  108. package/src/cli/cli-commands/common/createPositiveIntegerOptionParser.ts +31 -0
  109. package/src/commitments/TEAM/TEAM.ts +5 -5
  110. package/src/other/templates/getTemplatesPipelineCollection.ts +727 -781
  111. package/src/utils/ascii-art/convertImageDataToAsciiArt.ts +1 -4
  112. package/src/version.ts +2 -2
  113. package/src/versions.txt +1 -0
  114. package/umd/index.umd.js +96 -57
  115. package/umd/index.umd.js.map +1 -1
  116. package/umd/scripts/find-refactor-candidates/find-refactor-candidates.d.ts +7 -0
  117. package/umd/scripts/find-refactor-candidates/selectMostImportantRefactorCandidates.d.ts +12 -0
  118. package/umd/src/book-components/Chat/Chat/insertDictationChunk.d.ts +1 -1
  119. package/umd/src/book-components/Chat/Chat/insertDictationChunk.test.d.ts +1 -0
  120. package/umd/src/book-components/Chat/Chat/learnDictationDictionary.test.d.ts +1 -0
  121. package/umd/src/book-components/Chat/Chat/refineFinalDictationChunk.test.d.ts +1 -0
  122. package/umd/src/cli/cli-commands/common/createPositiveIntegerOptionParser.d.ts +10 -0
  123. package/umd/src/version.d.ts +1 -1
@@ -385,10 +385,7 @@ function mapColorToAnsi256(color: HalfCellColor): number {
385
385
  if (gray > ANSI_256_NEAR_WHITE_GRAY_LEVEL) {
386
386
  return ANSI_256_WHITE_INDEX; // <- Note: Pure white lives in the color cube
387
387
  }
388
- return (
389
- 232 +
390
- Math.round(((gray - 8) / ANSI_256_GRAYSCALE_RAMP_MAX_LEVEL) * ANSI_256_GRAYSCALE_RAMP_INDEX_SPAN)
391
- );
388
+ return 232 + Math.round(((gray - 8) / ANSI_256_GRAYSCALE_RAMP_MAX_LEVEL) * ANSI_256_GRAYSCALE_RAMP_INDEX_SPAN);
392
389
  }
393
390
 
394
391
  const redIndex = Math.round((red / 255) * 5);
package/src/version.ts CHANGED
@@ -16,11 +16,11 @@ export const BOOK_LANGUAGE_VERSION: string_semantic_version = '2.0.0';
16
16
  * @generated
17
17
  * @see https://github.com/webgptorg/promptbook
18
18
  */
19
- export const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version = '0.113.0-5';
19
+ export const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version = '0.113.0-8';
20
20
 
21
21
  /**
22
22
  * Represents the version string of the Promptbook engine.
23
- * It follows semantic versioning (e.g., `0.113.0-4`).
23
+ * It follows semantic versioning (e.g., `0.113.0-5`).
24
24
  *
25
25
  * @generated
26
26
  */
package/src/versions.txt CHANGED
@@ -1171,3 +1171,4 @@
1171
1171
  0.113.0-3
1172
1172
  0.113.0-4
1173
1173
  0.113.0-5
1174
+ 0.113.0-8
package/umd/index.umd.js CHANGED
@@ -63,7 +63,7 @@
63
63
  * @generated
64
64
  * @see https://github.com/webgptorg/promptbook
65
65
  */
66
- const PROMPTBOOK_ENGINE_VERSION = '0.113.0-5';
66
+ const PROMPTBOOK_ENGINE_VERSION = '0.113.0-8';
67
67
  /**
68
68
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
69
69
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -14668,7 +14668,7 @@
14668
14668
  isAnimated: true,
14669
14669
  supportsPointerTracking: true,
14670
14670
  render({ context, size, palette, createRandom, timeMs, interaction }) {
14671
- const { morphologyProfile, animationPhase, leftEyePhaseOffset, rightEyePhaseOffset, tentacleProfiles, skinSpots } = getOctopus3d4StableState(createRandom);
14671
+ const { morphologyProfile, animationPhase, leftEyePhaseOffset, rightEyePhaseOffset, tentacleProfiles, skinSpots, } = getOctopus3d4StableState(createRandom);
14672
14672
  const sceneCenterX = size * 0.5;
14673
14673
  const sceneCenterY = size * 0.535;
14674
14674
  const bob = Math.sin(timeMs / 980 + animationPhase) * size * 0.013;
@@ -15016,10 +15016,7 @@
15016
15016
  Math.max(0, Math.cos(effectiveLongitude)) * 0.12 +
15017
15017
  lowerBlend * tentacleInfluence.core * (0.12 + tentacleInfluence.depthScale * 0.07) -
15018
15018
  Math.max(0, -Math.cos(effectiveLongitude)) * 0.05;
15019
- const tentacleTubeRadius = lowerBlend *
15020
- tentacleInfluence.core *
15021
- (0.12 + tipBlend * 0.07 + tentacleInfluence.widthScale * 0.028) *
15022
- radiusX;
15019
+ const tentacleTubeRadius = lowerBlend * tentacleInfluence.core * (0.12 + tipBlend * 0.07 + tentacleInfluence.widthScale * 0.028) * radiusX;
15023
15020
  const planarRadiusX = cosineLatitude * radiusX * horizontalScale + tentacleTubeRadius;
15024
15021
  const planarRadiusZ = cosineLatitude * radiusZ * depthScale + tentacleTubeRadius * 0.74;
15025
15022
  const lowerDrop = lowerBlend *
@@ -15031,9 +15028,7 @@
15031
15028
  (morphologyProfile.tentacles.flowLengthScale - 1) * 0.1));
15032
15029
  const combinedTentacleSway = (primaryTentacleWave + secondaryTentacleWave) * radiusX * (0.06 + tipBlend * 0.06);
15033
15030
  return {
15034
- x: Math.sin(effectiveLongitude) * planarRadiusX +
15035
- combinedTentacleSway +
15036
- tentacleCurl * radiusX * 0.18,
15031
+ x: Math.sin(effectiveLongitude) * planarRadiusX + combinedTentacleSway + tentacleCurl * radiusX * 0.18,
15037
15032
  y: Math.sin(latitude) * radiusY * (1 + upperBlend * 0.14) -
15038
15033
  upperBlend * radiusY * 0.12 +
15039
15034
  lowerDrop +
@@ -18292,10 +18287,10 @@
18292
18287
  *
18293
18288
  * @private
18294
18289
  */
18295
- const TEAM_SYSTEM_MESSAGE_GUIDANCE_LINES = [
18296
- '- If a teammate is relevant to the request, consult that teammate using the matching tool.',
18297
- '- Do not ask the user for information that a listed teammate can provide directly.',
18298
- ];
18290
+ const TEAM_SYSTEM_MESSAGE_GUIDANCE = _spaceTrim.spaceTrim(`
18291
+ - If a teammate is relevant to the request, consult that teammate using the matching tool.
18292
+ - Do not ask the user for information that a listed teammate can provide directly.
18293
+ `);
18299
18294
  /**
18300
18295
  * Constant for remote agents by Url.
18301
18296
  */
@@ -18477,7 +18472,7 @@
18477
18472
  `);
18478
18473
  });
18479
18474
  return _spaceTrim.spaceTrim((block) => `
18480
- ${block(TEAM_SYSTEM_MESSAGE_GUIDANCE_LINES.join('\n'))}
18475
+ ${block(TEAM_SYSTEM_MESSAGE_GUIDANCE)}
18481
18476
 
18482
18477
  ${block(teammateSections.join('\n\n'))}
18483
18478
  `);
@@ -40295,6 +40290,30 @@
40295
40290
  }
40296
40291
  // Note: [🟡] Code for repository script [RefactorCandidateLevel](scripts/find-refactor-candidates/RefactorCandidateLevel.ts) should never be published outside of `@promptbook/cli`
40297
40292
 
40293
+ /**
40294
+ * Creates a Commander argument parser that accepts only positive integers.
40295
+ *
40296
+ * The returned parser is meant to be passed as the coercion callback of `command.option(...)`.
40297
+ * It throws a branded `NotAllowed` error with a clear message referencing the given option name
40298
+ * when the provided value is not a positive integer.
40299
+ *
40300
+ * @private internal utility of `promptbookCli`
40301
+ */
40302
+ function createPositiveIntegerOptionParser(optionName) {
40303
+ return (value) => {
40304
+ const parsedValue = Number(value);
40305
+ if (!Number.isInteger(parsedValue) || parsedValue <= 0) {
40306
+ throw new NotAllowed(_spaceTrim.spaceTrim(`
40307
+ Invalid value for \`${optionName}\`: \`${value}\`.
40308
+
40309
+ Use a positive integer.
40310
+ `));
40311
+ }
40312
+ return parsedValue;
40313
+ };
40314
+ }
40315
+ // Note: [🟡] Code for CLI option parser [createPositiveIntegerOptionParser](src/cli/cli-commands/common/createPositiveIntegerOptionParser.ts) should never be published outside of `@promptbook/cli`
40316
+
40298
40317
  /**
40299
40318
  * Initializes `coder find-refactor-candidates` command for Promptbook CLI utilities
40300
40319
  *
@@ -40315,12 +40334,13 @@
40315
40334
  command.addOption(new commander.Option('--level <level>', `Set scan aggressiveness (${REFACTOR_CANDIDATE_LEVEL_VALUES.join(', ')})`)
40316
40335
  .choices([...REFACTOR_CANDIDATE_LEVEL_VALUES])
40317
40336
  .default(DEFAULT_REFACTOR_CANDIDATE_LEVEL));
40337
+ command.option('--limit <candidate-count>', 'Create at most this many refactor prompts, keeping the most important candidates', createPositiveIntegerOptionParser('--limit'));
40318
40338
  command.action(handleActionErrors(async (cliOptions) => {
40319
- const { level = DEFAULT_REFACTOR_CANDIDATE_LEVEL } = cliOptions;
40339
+ const { level = DEFAULT_REFACTOR_CANDIDATE_LEVEL, limit } = cliOptions;
40320
40340
  // Note: Import the function dynamically to avoid loading heavy dependencies until needed
40321
40341
  const { findRefactorCandidates } = await Promise.resolve().then(function () { return findRefactorCandidates$1; });
40322
40342
  try {
40323
- await findRefactorCandidates({ level });
40343
+ await findRefactorCandidates({ level, limit });
40324
40344
  }
40325
40345
  catch (error) {
40326
40346
  assertsError(error);
@@ -40404,26 +40424,26 @@
40404
40424
  id: 'common',
40405
40425
  relativeFilePath: path.join(PROMPTS_TEMPLATES_DIRECTORY_PATH, 'common.md'),
40406
40426
  slugPrefix: null,
40407
- content: buildCoderPromptTemplateContent([
40408
- '- @@@',
40409
- "- Keep in mind the DRY _(don't repeat yourself)_ principle.",
40410
- '- Do a proper analysis of the current functionality before you start implementing.',
40411
- '- Add the changes into the [changelog](changelog/_current-preversion.md)',
40412
- ]),
40427
+ content: _spaceTrim.spaceTrim(`
40428
+ - @@@
40429
+ - Keep in mind the DRY _(don't repeat yourself)_ principle.
40430
+ - Do a proper analysis of the current functionality before you start implementing.
40431
+ - Add the changes into the [changelog](changelog/_current-preversion.md)
40432
+ `),
40413
40433
  isDefaultProjectTemplate: true,
40414
40434
  },
40415
40435
  {
40416
40436
  id: 'agents-server',
40417
40437
  relativeFilePath: path.join(PROMPTS_TEMPLATES_DIRECTORY_PATH, 'agents-server.md'),
40418
40438
  slugPrefix: 'agents-server',
40419
- content: buildCoderPromptTemplateContent([
40420
- '- @@@',
40421
- "- Keep in mind the DRY _(don't repeat yourself)_ principle.",
40422
- '- Do a proper analysis of the current functionality before you start implementing.',
40423
- '- You are working with the [Agents Server](apps/agents-server)',
40424
- '- If you need to do the database migration, do it',
40425
- '- Add the changes into the [changelog](changelog/_current-preversion.md)',
40426
- ]),
40439
+ content: _spaceTrim.spaceTrim(`
40440
+ - @@@
40441
+ - Keep in mind the DRY _(don't repeat yourself)_ principle.
40442
+ - Do a proper analysis of the current functionality before you start implementing.
40443
+ - You are working with the [Agents Server](apps/agents-server)
40444
+ - If you need to do the database migration, do it
40445
+ - Add the changes into the [changelog](changelog/_current-preversion.md)
40446
+ `),
40427
40447
  isDefaultProjectTemplate: false,
40428
40448
  },
40429
40449
  ];
@@ -40543,12 +40563,6 @@
40543
40563
  function getDefaultCoderPromptTemplateDefinitionOrUndefined(template) {
40544
40564
  return DEFAULT_CODER_PROMPT_TEMPLATE_DEFINITIONS.find((definition) => definition.id === template);
40545
40565
  }
40546
- /**
40547
- * Builds stable markdown content for one coder prompt template without indentation drift.
40548
- */
40549
- function buildCoderPromptTemplateContent(lines) {
40550
- return lines.join('\n');
40551
- }
40552
40566
  /**
40553
40567
  * Creates a fully resolved template payload from one built-in definition.
40554
40568
  */
@@ -41475,7 +41489,7 @@
41475
41489
  command.option('--preserve-logs', 'Keep generated temp prompt/log artifacts after successful rounds for debugging and analytics', false);
41476
41490
  addPromptRunnerExecutionOptions(command);
41477
41491
  command.option('--priority <minimum-priority>', 'Filter prompts by minimum priority level', parseIntOption$1, 0);
41478
- command.option('--limit <run-count>', 'Stop after processing this many prompt runs', parsePositiveIntegerOption);
41492
+ command.option('--limit <run-count>', 'Stop after processing this many prompt runs', createPositiveIntegerOptionParser('--limit'));
41479
41493
  command.option('--wait-after-prompt <duration>', _spaceTrim.spaceTrim(`
41480
41494
  Wait this long after each prompt has been implemented, verified and committed before starting the next prompt.
41481
41495
  Accepts durations like 1h, 30m, 5s. Defaults to 0 (no wait).
@@ -41562,22 +41576,6 @@
41562
41576
  }
41563
41577
  return parsed;
41564
41578
  }
41565
- /**
41566
- * Parses a positive integer option value.
41567
- *
41568
- * @private internal utility of `coder run` command
41569
- */
41570
- function parsePositiveIntegerOption(value) {
41571
- const parsed = Number(value);
41572
- if (!Number.isInteger(parsed) || parsed <= 0) {
41573
- throw new NotAllowed(_spaceTrim.spaceTrim(`
41574
- Invalid value for \`--limit\`: \`${value}\`.
41575
-
41576
- Use a positive integer.
41577
- `));
41578
- }
41579
- return parsed;
41580
- }
41581
41579
  /**
41582
41580
  * Joins one Commander option that may be parsed either as a single string or a variadic token array.
41583
41581
  *
@@ -69850,23 +69848,28 @@
69850
69848
  const extension = path.extname(filePath).toLowerCase();
69851
69849
  const relativePath = normalizeRefactorCandidatePath(path.relative(rootDir, filePath));
69852
69850
  const reasons = [];
69851
+ let severityScore = 0;
69853
69852
  if (!lineCountExemptPaths.has(normalizedAbsolutePath)) {
69854
69853
  const lineCount = countLines(content);
69855
69854
  const maxLines = getMaxLinesForExtension(extension, heuristics);
69856
69855
  if (lineCount > maxLines) {
69857
69856
  reasons.push(`lines ${lineCount}/${maxLines}`);
69857
+ severityScore += lineCount / maxLines;
69858
69858
  }
69859
69859
  }
69860
69860
  if (STRUCTURAL_ANALYSIS_EXTENSIONS.includes(extension)) {
69861
69861
  const structureSummary = summarizeSourceFileStructure(content, extension, filePath);
69862
69862
  if (structureSummary.entityCount > heuristics.maxEntityCountPerFile) {
69863
69863
  reasons.push(`entities ${structureSummary.entityCount}/${heuristics.maxEntityCountPerFile}`);
69864
+ severityScore += structureSummary.entityCount / heuristics.maxEntityCountPerFile;
69864
69865
  }
69865
69866
  if (structureSummary.functionCount > heuristics.maxFunctionCountPerFile) {
69866
69867
  reasons.push(`functions ${structureSummary.functionCount}/${heuristics.maxFunctionCountPerFile}`);
69868
+ severityScore += structureSummary.functionCount / heuristics.maxFunctionCountPerFile;
69867
69869
  }
69868
69870
  if (structureSummary.maxFunctionComplexity > heuristics.maxFunctionComplexity) {
69869
69871
  reasons.push(buildComplexityReason(structureSummary, heuristics.maxFunctionComplexity));
69872
+ severityScore += structureSummary.maxFunctionComplexity / heuristics.maxFunctionComplexity;
69870
69873
  }
69871
69874
  }
69872
69875
  if (reasons.length === 0) {
@@ -69876,6 +69879,7 @@
69876
69879
  absolutePath: filePath,
69877
69880
  relativePath,
69878
69881
  reasons,
69882
+ severityScore,
69879
69883
  };
69880
69884
  }
69881
69885
  /**
@@ -70335,6 +70339,37 @@
70335
70339
  }
70336
70340
  // Note: [🟡] Code for repository script [resolveRefactorCandidateProject](scripts/find-refactor-candidates/resolveRefactorCandidateProject.ts) should never be published outside of `@promptbook/cli`
70337
70341
 
70342
+ /**
70343
+ * Keeps at most `limit` refactor candidates, preferring the most important ones.
70344
+ *
70345
+ * When there are more candidates than `limit`, only the highest-severity candidates are kept
70346
+ * (ties broken by relative path for determinism). When `limit` is `undefined` or there are fewer
70347
+ * candidates than the limit, every candidate is returned. The original input order is preserved
70348
+ * among the kept candidates, so `limit` acts purely as a filter and never reorders prompts.
70349
+ *
70350
+ * @private function of findRefactorCandidates
70351
+ */
70352
+ function selectMostImportantRefactorCandidates(candidates, limit) {
70353
+ if (limit === undefined || candidates.length <= limit) {
70354
+ return candidates;
70355
+ }
70356
+ const candidatesRankedByImportance = [...candidates].sort(compareRefactorCandidatesByImportance);
70357
+ const keptRelativePaths = new Set(candidatesRankedByImportance.slice(0, limit).map((candidate) => candidate.relativePath));
70358
+ return candidates.filter((candidate) => keptRelativePaths.has(candidate.relativePath));
70359
+ }
70360
+ /**
70361
+ * Orders refactor candidates from most to least important.
70362
+ *
70363
+ * @private function of selectMostImportantRefactorCandidates
70364
+ */
70365
+ function compareRefactorCandidatesByImportance(candidateA, candidateB) {
70366
+ if (candidateB.severityScore !== candidateA.severityScore) {
70367
+ return candidateB.severityScore - candidateA.severityScore;
70368
+ }
70369
+ return candidateA.relativePath.localeCompare(candidateB.relativePath);
70370
+ }
70371
+ // Note: [🟡] Code for repository script [selectMostImportantRefactorCandidates](scripts/find-refactor-candidates/selectMostImportantRefactorCandidates.ts) should never be published outside of `@promptbook/cli`
70372
+
70338
70373
  /**
70339
70374
  * Calculates the next available prompt numbering sequence for a month.
70340
70375
  */
@@ -70658,7 +70693,7 @@
70658
70693
  * @public exported from `@promptbook/cli`
70659
70694
  */
70660
70695
  async function findRefactorCandidates(options = {}) {
70661
- const { level = DEFAULT_REFACTOR_CANDIDATE_LEVEL } = options;
70696
+ const { level = DEFAULT_REFACTOR_CANDIDATE_LEVEL, limit } = options;
70662
70697
  const heuristics = getRefactorCandidateLevelConfiguration(level);
70663
70698
  initializeFindRefactorCandidatesRun();
70664
70699
  console.info(colors__default["default"].cyan('⚡🏭 Find refactor candidates'));
@@ -70682,8 +70717,10 @@
70682
70717
  console.info(colors__default["default"].green('All candidates already have prompts.'));
70683
70718
  return;
70684
70719
  }
70720
+ const selectedCandidatesToWrite = selectMostImportantRefactorCandidates(candidatesToWrite, limit);
70721
+ const skippedByLimit = candidatesToWrite.length - selectedCandidatesToWrite.length;
70685
70722
  const createdPrompts = await writeRefactorCandidatePrompts({
70686
- candidates: candidatesToWrite,
70723
+ candidates: selectedCandidatesToWrite,
70687
70724
  rootDir,
70688
70725
  promptsDir,
70689
70726
  });
@@ -70691,6 +70728,9 @@
70691
70728
  if (alreadyTracked > 0) {
70692
70729
  console.info(colors__default["default"].gray(`Skipped ${alreadyTracked} candidate(s) with existing prompts.`));
70693
70730
  }
70731
+ if (skippedByLimit > 0) {
70732
+ console.info(colors__default["default"].gray(`Skipped ${skippedByLimit} lower-priority candidate(s) because of \`--limit ${limit}\`.`));
70733
+ }
70694
70734
  }
70695
70735
  /**
70696
70736
  * Prints discovered refactor candidates with their reasons.
@@ -71942,8 +71982,7 @@
71942
71982
  if (gray > ANSI_256_NEAR_WHITE_GRAY_LEVEL) {
71943
71983
  return ANSI_256_WHITE_INDEX; // <- Note: Pure white lives in the color cube
71944
71984
  }
71945
- return (232 +
71946
- Math.round(((gray - 8) / ANSI_256_GRAYSCALE_RAMP_MAX_LEVEL) * ANSI_256_GRAYSCALE_RAMP_INDEX_SPAN));
71985
+ return 232 + Math.round(((gray - 8) / ANSI_256_GRAYSCALE_RAMP_MAX_LEVEL) * ANSI_256_GRAYSCALE_RAMP_INDEX_SPAN);
71947
71986
  }
71948
71987
  const redIndex = Math.round((red / 255) * 5);
71949
71988
  const greenIndex = Math.round((green / 255) * 5);