@promptbook/cli 0.114.0-13 → 0.114.0-14

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/esm/index.es.js CHANGED
@@ -48,7 +48,7 @@ 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-13';
51
+ const PROMPTBOOK_ENGINE_VERSION = '0.114.0-14';
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
@@ -42447,6 +42447,52 @@ function listDefaultCoderProjectPromptTemplateDisplayPaths() {
42447
42447
  // Note: [🟡] Code for CLI command [init](src/cli/cli-commands/coder/init.ts) should never be published outside of `@promptbook/cli`
42448
42448
  // Note: [💞] Ignore a discrepancy between file name and entity name
42449
42449
 
42450
+ /**
42451
+ * Default wait duration applied before retrying a prompt round after an error (10 minutes).
42452
+ *
42453
+ * @private internal constant of `ptbk coder` wait handling
42454
+ */
42455
+ const DEFAULT_WAIT_AFTER_ERROR_MS$1 = 10 * 60 * 1000;
42456
+ /**
42457
+ * Parses an optional Commander duration string and returns the resolved milliseconds.
42458
+ *
42459
+ * Returns `defaultMs` when the flag was not provided or was provided without a non-empty value.
42460
+ *
42461
+ * @private internal utility of `ptbk coder` wait handling
42462
+ */
42463
+ function parseOptionalWaitDuration(value, defaultMs) {
42464
+ if (typeof value !== 'string' || value === '') {
42465
+ return defaultMs;
42466
+ }
42467
+ return parseDuration(value);
42468
+ }
42469
+ /**
42470
+ * Parses an optional Commander period duration string and returns the resolved milliseconds.
42471
+ *
42472
+ * Returns `undefined` when the flag was not provided or was provided without a non-empty value,
42473
+ * which means the command runs only once instead of repeating itself.
42474
+ *
42475
+ * @throws {NotAllowed} When the duration is not a positive one, because a non-positive period
42476
+ * would repeat the command without ever pausing between two rounds
42477
+ *
42478
+ * @private internal utility of `ptbk coder` wait handling
42479
+ */
42480
+ function parseOptionalPeriodDuration(optionName, value) {
42481
+ if (typeof value !== 'string' || value === '') {
42482
+ return undefined;
42483
+ }
42484
+ const periodMs = parseDuration(value);
42485
+ if (periodMs <= 0) {
42486
+ throw new NotAllowed(spaceTrim$1(`
42487
+ Invalid value for \`${optionName}\`: \`${value}\`.
42488
+
42489
+ Use a **positive** duration like \`5h\`, \`30m\` or \`1h30m\`.
42490
+ `));
42491
+ }
42492
+ return periodMs;
42493
+ }
42494
+ // Note: [💞] Ignore a discrepancy between file name and entity name
42495
+
42450
42496
  /**
42451
42497
  * Initializes `coder ping` command for Promptbook CLI utilities
42452
42498
  *
@@ -42465,6 +42511,7 @@ function $initializeCoderPingCommand(program) {
42465
42511
  - Verifies that the selected harness, model, thinking level and authentication really work
42466
42512
  - Reports the answer of the harness, the response time and the reported usage
42467
42513
  - Starts the hourly/weekly quota window before you need it, so it is already refreshing when you do
42514
+ - Optional --period keeps the quota window refreshing by pinging once per period until stopped
42468
42515
  - Leaves the project exactly as it was — nothing is read, written, changed or committed
42469
42516
  - Checks that the selected harness is installed globally and up to date unless --no-harness-update is used
42470
42517
  - Use --no-ui to stream the raw harness output instead of only the compact result
@@ -42472,21 +42519,34 @@ function $initializeCoderPingCommand(program) {
42472
42519
  addPromptRunnerSelectionOptions(command);
42473
42520
  addHarnessUpdateOption(command);
42474
42521
  addPromptRunnerRuntimeOptions(command);
42522
+ command.option('--period <duration>', spaceTrim$1(`
42523
+ Keep pinging once per period instead of pinging only once.
42524
+ Accepts durations like 5h, 30m, 1h30m and repeats until it is stopped with CTRL+C.
42525
+ `));
42475
42526
  command.action(handleActionErrors(async (cliOptions) => {
42527
+ const { period: periodValue } = cliOptions;
42476
42528
  const runnerOptions = normalizePromptRunnerSelectionCliOptions(cliOptions, { isAgentRequired: true });
42477
42529
  const { isHarnessUpdateCheckEnabled } = normalizeHarnessUpdateCliOptions(cliOptions);
42530
+ // Note: The period is validated before the harness installation check, so a mistyped duration fails fast
42531
+ const periodMs = parseOptionalPeriodDuration('--period', periodValue);
42478
42532
  await $ensureHarnessInstallations([runnerOptions.agentName], isHarnessUpdateCheckEnabled);
42479
- // Note: Import the ping dynamically to avoid loading heavy dependencies until needed
42480
- const { pingCoderHarness } = await Promise.resolve().then(function () { return pingCoderHarness$1; });
42481
- const { printCoderPingResult } = await Promise.resolve().then(function () { return printCoderPingResult$1; });
42482
- const result = await pingCoderHarness({
42533
+ const pingOptions = {
42483
42534
  agentName: runnerOptions.agentName,
42484
42535
  model: runnerOptions.model,
42485
42536
  thinkingLevel: runnerOptions.thinkingLevel,
42486
42537
  allowCredits: runnerOptions.allowCredits,
42487
42538
  shouldPrintLiveOutput: runnerOptions.noUi,
42488
- });
42489
- printCoderPingResult(result);
42539
+ };
42540
+ // Note: Import the ping dynamically to avoid loading heavy dependencies until needed
42541
+ if (periodMs !== undefined) {
42542
+ const { pingCoderHarnessPeriodically } = await Promise.resolve().then(function () { return pingCoderHarnessPeriodically$1; });
42543
+ // Note: This never returns - it keeps pinging until the user stops the process
42544
+ await pingCoderHarnessPeriodically({ ...pingOptions, periodMs });
42545
+ return;
42546
+ }
42547
+ const { pingCoderHarness } = await Promise.resolve().then(function () { return pingCoderHarness$1; });
42548
+ const { printCoderPingResult } = await Promise.resolve().then(function () { return printCoderPingResult$1; });
42549
+ printCoderPingResult(await pingCoderHarness(pingOptions));
42490
42550
  }));
42491
42551
  }
42492
42552
  // Note: [🟡] Code for CLI command [ping](src/cli/cli-commands/coder/ping.ts) should never be published outside of `@promptbook/cli`
@@ -42923,27 +42983,6 @@ function isTestBeforeMode(value) {
42923
42983
  return TEST_BEFORE_MODE_VALUES.includes(value);
42924
42984
  }
42925
42985
 
42926
- /**
42927
- * Default wait duration applied before retrying a prompt round after an error (10 minutes).
42928
- *
42929
- * @private internal constant of `ptbk coder` wait handling
42930
- */
42931
- const DEFAULT_WAIT_AFTER_ERROR_MS$1 = 10 * 60 * 1000;
42932
- /**
42933
- * Parses an optional Commander duration string and returns the resolved milliseconds.
42934
- *
42935
- * Returns `defaultMs` when the flag was not provided or was provided without a non-empty value.
42936
- *
42937
- * @private internal utility of `ptbk coder` wait handling
42938
- */
42939
- function parseOptionalWaitDuration(value, defaultMs) {
42940
- if (typeof value !== 'string' || value === '') {
42941
- return defaultMs;
42942
- }
42943
- return parseDuration(value);
42944
- }
42945
- // Note: [💞] Ignore a discrepancy between file name and entity name
42946
-
42947
42986
  /**
42948
42987
  * Initializes `coder run` command for Promptbook CLI utilities
42949
42988
  *
@@ -72682,6 +72721,23 @@ var findUnwrittenPrompts$1 = /*#__PURE__*/Object.freeze({
72682
72721
  findUnwrittenPrompts: findUnwrittenPrompts
72683
72722
  });
72684
72723
 
72724
+ /**
72725
+ * Formats one unknown error-like value into its readable message without the stack trace.
72726
+ *
72727
+ * Use this instead of `formatUnknownErrorDetails` whenever the text is shown to the user, for example
72728
+ * inside a branded error, where the stack of the wrapped error would only bury the actual cause.
72729
+ */
72730
+ function formatUnknownErrorMessage(error) {
72731
+ if (error instanceof Error) {
72732
+ return error.message;
72733
+ }
72734
+ if (typeof error === 'string') {
72735
+ return error;
72736
+ }
72737
+ const serializedError = JSON.stringify(error, null, 2);
72738
+ return serializedError !== null && serializedError !== void 0 ? serializedError : String(error);
72739
+ }
72740
+
72685
72741
  /**
72686
72742
  * Builds a normalized temporary shell script path for prompt runners.
72687
72743
  */
@@ -72919,6 +72975,60 @@ var printCoderPingResult$1 = /*#__PURE__*/Object.freeze({
72919
72975
  printCoderPingResult: printCoderPingResult
72920
72976
  });
72921
72977
 
72978
+ /**
72979
+ * How often the countdown to the next periodic ping is reported to the console (30 minutes).
72980
+ *
72981
+ * A period like `5h` is meant to be left running unattended, so the countdown is deliberately
72982
+ * coarse — it is a sign of life, not a progress bar.
72983
+ */
72984
+ const CODER_PING_COUNTDOWN_UPDATE_INTERVAL_MS = 30 * 60 * 1000;
72985
+ /**
72986
+ * Pings the selected harness and model once per period until the process is stopped.
72987
+ *
72988
+ * This keeps the quota window of the harness refreshing without any real work, so the window is
72989
+ * always open by the time you need it. The loop never ends on its own — it is stopped with `CTRL+C`
72990
+ * or by killing the process — therefore a failing ping is reported and the next period is started
72991
+ * instead of tearing the whole loop down.
72992
+ */
72993
+ async function pingCoderHarnessPeriodically(options) {
72994
+ const { periodMs, ...pingOptions } = options;
72995
+ console.info(colors.gray(`🏓 Pinging every ${formatDurationMs(periodMs)} until stopped with CTRL+C`));
72996
+ // Note: The loop is intentionally endless - only `CTRL+C` or killing the process ends it
72997
+ for (;;) {
72998
+ const nextPingTimeMs = Date.now() + periodMs;
72999
+ await reportOneCoderPing(pingOptions);
73000
+ await waitUntilNextCoderPing(nextPingTimeMs);
73001
+ }
73002
+ }
73003
+ /**
73004
+ * Sends and reports one ping of the endless loop, keeping the loop alive when the harness fails.
73005
+ */
73006
+ async function reportOneCoderPing(options) {
73007
+ try {
73008
+ printCoderPingResult(await pingCoderHarness(options));
73009
+ }
73010
+ catch (error) {
73011
+ console.error(colors.red(`🏓 Ping failed: ${formatUnknownErrorMessage(error)}`));
73012
+ }
73013
+ }
73014
+ /**
73015
+ * Waits until the wall-clock time of the next ping, reporting how much of the period is left.
73016
+ */
73017
+ async function waitUntilNextCoderPing(nextPingTimeMs) {
73018
+ await waitUntilWorldTimeDeadline({
73019
+ deadlineTimeMs: nextPingTimeMs,
73020
+ pollIntervalMs: CODER_PING_COUNTDOWN_UPDATE_INTERVAL_MS,
73021
+ onTick(remainingDurationMs) {
73022
+ console.info(colors.gray(` Next ping in ${formatDurationMs(remainingDurationMs)}`));
73023
+ },
73024
+ });
73025
+ }
73026
+
73027
+ var pingCoderHarnessPeriodically$1 = /*#__PURE__*/Object.freeze({
73028
+ __proto__: null,
73029
+ pingCoderHarnessPeriodically: pingCoderHarnessPeriodically
73030
+ });
73031
+
72922
73032
  /**
72923
73033
  * Default wait duration applied before retrying a failed prompt round.
72924
73034
  */
@@ -75752,23 +75862,6 @@ function buildCoderIsolationWorktreeDisplayPath(taskName) {
75752
75862
  return getPromptbookTemporaryPath(CODER_ISOLATION_WORKTREES_DIRECTORY_NAME, taskName);
75753
75863
  }
75754
75864
 
75755
- /**
75756
- * Formats one unknown error-like value into its readable message without the stack trace.
75757
- *
75758
- * Use this instead of `formatUnknownErrorDetails` whenever the text is shown to the user, for example
75759
- * inside a branded error, where the stack of the wrapped error would only bury the actual cause.
75760
- */
75761
- function formatUnknownErrorMessage(error) {
75762
- if (error instanceof Error) {
75763
- return error.message;
75764
- }
75765
- if (typeof error === 'string') {
75766
- return error;
75767
- }
75768
- const serializedError = JSON.stringify(error, null, 2);
75769
- return serializedError !== null && serializedError !== void 0 ? serializedError : String(error);
75770
- }
75771
-
75772
75865
  /**
75773
75866
  * Git configuration key which lets Git read, write and delete files whose absolute path is longer than
75774
75867
  * the Windows `MAX_PATH` limit of 260 characters.