@promptbook/cli 0.114.0-39 → 0.114.0-40

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.
@@ -0,0 +1,46 @@
1
+ import { glob, type GlobOptionsWithFileTypesUnset } from 'glob';
2
+ import type { string_filename } from '../../types/string_filename';
3
+
4
+ /**
5
+ * Options of `findFilesByGlob`
6
+ *
7
+ * Note: These are the options of `glob` itself, only `ignore` also accepts a readonly array
8
+ * @see https://www.npmjs.com/package/glob#options
9
+ *
10
+ * @private internal type of `findFilesByGlob`
11
+ */
12
+ export type FindFilesByGlobOptions = Omit<GlobOptionsWithFileTypesUnset, 'ignore'> & {
13
+ /**
14
+ * Glob patterns which are excluded from the result
15
+ */
16
+ readonly ignore?: string | ReadonlyArray<string>;
17
+ };
18
+
19
+ /**
20
+ * Finds all filenames matching a glob pattern
21
+ *
22
+ * Note: This is the single place where `glob` is used, so that every caller gets the same shape of results
23
+ * on every operating system - POSIX separators and a stable order - which `glob` itself does not guarantee
24
+ *
25
+ * @param pattern Glob pattern to match, for example `./src/**\/*.ts`
26
+ * @param options Options passed to `glob`
27
+ * @returns Matching filenames with `/` separators, sorted alphabetically
28
+ * @private within the repository
29
+ */
30
+ export async function findFilesByGlob(
31
+ pattern: string,
32
+ options: FindFilesByGlobOptions = {},
33
+ ): Promise<Array<string_filename>> {
34
+ const { ignore, ...restOptions } = options;
35
+
36
+ const matchedFilenames = await glob(pattern, {
37
+ ...restOptions,
38
+ ignore: typeof ignore === 'string' || ignore === undefined ? ignore : [...ignore],
39
+ });
40
+
41
+ return matchedFilenames
42
+ .map((matchedFilename) => matchedFilename.split('\\').join('/'))
43
+ .sort((filenameA, filenameB) => filenameA.localeCompare(filenameB, 'en'));
44
+ }
45
+
46
+ // Note: Not [~🟢~] because it is not directly dependent on `fs`, same as `listAllFiles`
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.114.0-39';
19
+ export const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version = '0.114.0-40';
20
20
 
21
21
  /**
22
22
  * Represents the version string of the Promptbook engine.
23
- * It follows semantic versioning (e.g., `0.114.0-38`).
23
+ * It follows semantic versioning (e.g., `0.114.0-39`).
24
24
  *
25
25
  * @generated
26
26
  */
package/src/versions.txt CHANGED
@@ -1215,3 +1215,4 @@
1215
1215
  0.114.0-37
1216
1216
  0.114.0-38
1217
1217
  0.114.0-39
1218
+ 0.114.0-40
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('commander'), require('spacetrim'), require('fs/promises'), require('path'), require('crypto'), require('child_process'), require('moment'), require('fs'), require('dotenv'), require('readline'), require('waitasecond'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('glob-promise'), require('http'), require('express'), require('socket.io'), require('express-openapi-validator'), require('swagger-ui-express'), require('react'), require('react-dom/server'), require('bottleneck'), require('showdown'), require('rxjs'), require('ignore'), require('events'), require('os'), require('mime-types'), require('url'), require('papaparse'), require('@supabase/supabase-js')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'commander', 'spacetrim', 'fs/promises', 'path', 'crypto', 'child_process', 'moment', 'fs', 'dotenv', 'readline', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'glob-promise', 'http', 'express', 'socket.io', 'express-openapi-validator', 'swagger-ui-express', 'react', 'react-dom/server', 'bottleneck', 'showdown', 'rxjs', 'ignore', 'events', 'os', 'mime-types', 'url', 'papaparse', '@supabase/supabase-js'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global._spaceTrim, global.promises, global.path, global.crypto, global.child_process, global.moment, global.fs, global.dotenv, global.readline, global.waitasecond, global.hexEncoder, global.sha256, global.CryptoJS, global.glob, global.http, global.express, global.socket_io, global.OpenApiValidator, global.swaggerUi, global.react, global.server, global.Bottleneck, global.showdown, global.rxjs, global.ignore, global.events, global.os, global.mimeTypes, global.url, global.papaparse));
5
- })(this, (function (exports, colors, commander, _spaceTrim, promises, path, crypto, child_process, moment, fs, dotenv, readline, waitasecond, hexEncoder, sha256, CryptoJS, glob, http, express, socket_io, OpenApiValidator, swaggerUi, react, server, Bottleneck, showdown, rxjs, ignore, events, os, mimeTypes, url, papaparse) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('commander'), require('spacetrim'), require('fs/promises'), require('path'), require('crypto'), require('child_process'), require('moment'), require('fs'), require('dotenv'), require('readline'), require('waitasecond'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('http'), require('express'), require('socket.io'), require('express-openapi-validator'), require('swagger-ui-express'), require('react'), require('react-dom/server'), require('bottleneck'), require('showdown'), require('rxjs'), require('glob'), require('ignore'), require('events'), require('os'), require('mime-types'), require('url'), require('papaparse'), require('@supabase/supabase-js')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'commander', 'spacetrim', 'fs/promises', 'path', 'crypto', 'child_process', 'moment', 'fs', 'dotenv', 'readline', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'http', 'express', 'socket.io', 'express-openapi-validator', 'swagger-ui-express', 'react', 'react-dom/server', 'bottleneck', 'showdown', 'rxjs', 'glob', 'ignore', 'events', 'os', 'mime-types', 'url', 'papaparse', '@supabase/supabase-js'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global._spaceTrim, global.promises, global.path, global.crypto, global.child_process, global.moment, global.fs, global.dotenv, global.readline, global.waitasecond, global.hexEncoder, global.sha256, global.CryptoJS, global.http, global.express, global.socket_io, global.OpenApiValidator, global.swaggerUi, global.react, global.server, global.Bottleneck, global.showdown, global.rxjs, global.glob, global.ignore, global.events, global.os, global.mimeTypes, global.url, global.papaparse));
5
+ })(this, (function (exports, colors, commander, _spaceTrim, promises, path, crypto, child_process, moment, fs, dotenv, readline, waitasecond, hexEncoder, sha256, CryptoJS, http, express, socket_io, OpenApiValidator, swaggerUi, react, server, Bottleneck, showdown, rxjs, glob, ignore, events, os, mimeTypes, url, papaparse) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -34,7 +34,6 @@
34
34
  var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
35
35
  var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
36
36
  var CryptoJS__default = /*#__PURE__*/_interopDefaultLegacy(CryptoJS);
37
- var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
38
37
  var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
39
38
  var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
40
39
  var OpenApiValidator__namespace = /*#__PURE__*/_interopNamespace(OpenApiValidator);
@@ -58,7 +57,7 @@
58
57
  * @generated
59
58
  * @see https://github.com/webgptorg/promptbook
60
59
  */
61
- const PROMPTBOOK_ENGINE_VERSION = '0.114.0-39';
60
+ const PROMPTBOOK_ENGINE_VERSION = '0.114.0-40';
62
61
  /**
63
62
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
64
63
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -25084,6 +25083,28 @@
25084
25083
  return parts.join(' ');
25085
25084
  }
25086
25085
 
25086
+ /**
25087
+ * Creates a line reader for one shell output stream.
25088
+ *
25089
+ * A chunk boundary can fall into the middle of a line, so the unterminated rest is remembered until the next chunk
25090
+ * completes it. Every observer of the live output therefore sees whole lines only, exactly as the finished output
25091
+ * would contain them. One reader belongs to one stream, because interleaving `stdout` and `stderr` into a single
25092
+ * buffer would splice two unrelated halves into one nonexistent line.
25093
+ *
25094
+ * @private internal utility of the script runners
25095
+ */
25096
+ function createScriptOutputLineReader() {
25097
+ let unterminatedLine = '';
25098
+ return {
25099
+ readCompletedLines(chunk) {
25100
+ var _a;
25101
+ const lines = `${unterminatedLine}${chunk}`.split(/\r?\n/);
25102
+ unterminatedLine = (_a = lines.pop()) !== null && _a !== void 0 ? _a : '';
25103
+ return lines;
25104
+ },
25105
+ };
25106
+ }
25107
+
25087
25108
  /**
25088
25109
  * Converts a file path to POSIX format.
25089
25110
  */
@@ -25308,6 +25329,10 @@
25308
25329
  scriptPath: options.scriptPath,
25309
25330
  logPath: options.logPath,
25310
25331
  });
25332
+ const outputLineReaders = {
25333
+ stdout: createScriptOutputLineReader(),
25334
+ stderr: createScriptOutputLineReader(),
25335
+ };
25311
25336
  let output = '';
25312
25337
  let settled = false;
25313
25338
  let isSettling = false;
@@ -25344,16 +25369,19 @@
25344
25369
  settleOnce(handler);
25345
25370
  });
25346
25371
  };
25347
- commandProcess.stdout.on('data', (stdout) => {
25348
- const chunk = stdout.toString();
25349
- output += chunk;
25350
- printLiveScriptChunk(chunk, 'stdout', shouldPrintLiveOutput);
25351
- });
25352
- commandProcess.stderr.on('data', (stderr) => {
25353
- const chunk = stderr.toString();
25372
+ /**
25373
+ * Accumulates one output chunk and reports the lines it completed.
25374
+ */
25375
+ const handleChunk = (chunk, source) => {
25376
+ var _a;
25354
25377
  output += chunk;
25355
- printLiveScriptChunk(chunk, 'stderr', shouldPrintLiveOutput);
25356
- });
25378
+ printLiveScriptChunk(chunk, source, shouldPrintLiveOutput);
25379
+ for (const line of outputLineReaders[source].readCompletedLines(chunk)) {
25380
+ (_a = options.onOutputLine) === null || _a === void 0 ? void 0 : _a.call(options, line);
25381
+ }
25382
+ };
25383
+ commandProcess.stdout.on('data', (stdout) => handleChunk(stdout.toString(), 'stdout'));
25384
+ commandProcess.stderr.on('data', (stderr) => handleChunk(stderr.toString(), 'stderr'));
25357
25385
  /**
25358
25386
  * Handles process exit and resolves or rejects accordingly.
25359
25387
  */
@@ -26219,6 +26247,10 @@
26219
26247
  * Polling interval used while waiting for Claude Code session limits to reset.
26220
26248
  */
26221
26249
  const CLAUDE_CODE_SESSION_RESURRECTION_POLL_MS = 30 * 1000;
26250
+ /**
26251
+ * Stream event type which carries a Claude Code subscription-limit update.
26252
+ */
26253
+ const CLAUDE_CODE_RATE_LIMIT_EVENT_TYPE = 'rate_limit_event';
26222
26254
  /**
26223
26255
  * Runs prompts via the Claude Code CLI.
26224
26256
  */
@@ -26233,7 +26265,9 @@
26233
26265
  /**
26234
26266
  * Returns the latest subscription-limit snapshot emitted by this Claude Code session.
26235
26267
  *
26236
- * Claude exposes these values in the normal stream after a response, so no separate quota-only model call is made.
26268
+ * Claude exposes these values in the normal stream, so no separate quota-only model call is made. The snapshot is
26269
+ * kept current while the prompt is still running, which is what lets the dashboard poll it instead of showing the
26270
+ * values of the previous prompt for the whole round.
26237
26271
  */
26238
26272
  async getSubscriptionUsage() {
26239
26273
  return this.subscriptionUsage;
@@ -26294,8 +26328,22 @@
26294
26328
  logPath: options.logPath,
26295
26329
  shouldPrintLiveOutput: options.shouldPrintLiveOutput,
26296
26330
  preserveArtifactsOnSuccess: options.preserveArtifactsOnSuccess,
26331
+ onOutputLine: (line) => this.updateSubscriptionUsageFromOutputLine(line),
26297
26332
  });
26298
26333
  }
26334
+ /**
26335
+ * Keeps the snapshot current from one line of the stream which is still being written.
26336
+ *
26337
+ * A coding prompt can run for hours, and a subscription window keeps moving during all of it. Only a rate-limit
26338
+ * event can change the snapshot, so the far more frequent tool and message lines are recognized by their type and
26339
+ * skipped before anything is parsed.
26340
+ */
26341
+ updateSubscriptionUsageFromOutputLine(line) {
26342
+ if (!line.includes(CLAUDE_CODE_RATE_LIMIT_EVENT_TYPE)) {
26343
+ return;
26344
+ }
26345
+ this.updateSubscriptionUsage(line);
26346
+ }
26299
26347
  /**
26300
26348
  * Keeps the newest usable Claude subscription-limit values reported by the stream.
26301
26349
  *
@@ -26956,8 +27004,10 @@
26956
27004
  scriptPath,
26957
27005
  logPath: options.logPath,
26958
27006
  });
26959
- let stdoutBuffer = '';
26960
- let stderrBuffer = '';
27007
+ const outputLineReaders = {
27008
+ stdout: createScriptOutputLineReader(),
27009
+ stderr: createScriptOutputLineReader(),
27010
+ };
26961
27011
  let fullOutput = '';
26962
27012
  let markerSeen = false;
26963
27013
  let isCompletedAfterIdleTimeout = false;
@@ -27027,7 +27077,9 @@
27027
27077
  * Processes completed output lines to detect completion markers.
27028
27078
  */
27029
27079
  const handleLines = (lines) => {
27080
+ var _a;
27030
27081
  for (const line of lines) {
27082
+ (_a = options.onOutputLine) === null || _a === void 0 ? void 0 : _a.call(options, line);
27031
27083
  if (completionLineMatcher.test(line)) {
27032
27084
  markerSeen = true;
27033
27085
  scheduleIdleExit();
@@ -27042,21 +27094,9 @@
27042
27094
  * Handles output chunks from stdout or stderr.
27043
27095
  */
27044
27096
  const handleChunk = (chunk, source) => {
27045
- var _a, _b;
27046
27097
  fullOutput += chunk;
27047
27098
  printLiveScriptChunk(chunk, source, shouldPrintLiveOutput);
27048
- if (source === 'stdout') {
27049
- stdoutBuffer += chunk;
27050
- const lines = stdoutBuffer.split(/\r?\n/);
27051
- stdoutBuffer = (_a = lines.pop()) !== null && _a !== void 0 ? _a : '';
27052
- handleLines(lines);
27053
- }
27054
- else {
27055
- stderrBuffer += chunk;
27056
- const lines = stderrBuffer.split(/\r?\n/);
27057
- stderrBuffer = (_b = lines.pop()) !== null && _b !== void 0 ? _b : '';
27058
- handleLines(lines);
27059
- }
27099
+ handleLines(outputLineReaders[source].readCompletedLines(chunk));
27060
27100
  if (markerSeen && chunk.length > 0) {
27061
27101
  scheduleIdleExit();
27062
27102
  }
@@ -27118,6 +27158,7 @@
27118
27158
  idleTimeoutMs: options.idleTimeoutMs,
27119
27159
  logPath: options.logPath,
27120
27160
  shouldPrintLiveOutput: options.shouldPrintLiveOutput,
27161
+ onOutputLine: options.onOutputLine,
27121
27162
  });
27122
27163
  });
27123
27164
  }
@@ -56069,6 +56110,29 @@
56069
56110
  // TODO: Maybe use some Mermaid package instead of string templating
56070
56111
  // TODO: [🕌] When more than 2 functionalities, split into separate functions
56071
56112
 
56113
+ /**
56114
+ * Finds all filenames matching a glob pattern
56115
+ *
56116
+ * Note: This is the single place where `glob` is used, so that every caller gets the same shape of results
56117
+ * on every operating system - POSIX separators and a stable order - which `glob` itself does not guarantee
56118
+ *
56119
+ * @param pattern Glob pattern to match, for example `./src/**\/*.ts`
56120
+ * @param options Options passed to `glob`
56121
+ * @returns Matching filenames with `/` separators, sorted alphabetically
56122
+ * @private within the repository
56123
+ */
56124
+ async function findFilesByGlob(pattern, options = {}) {
56125
+ const { ignore, ...restOptions } = options;
56126
+ const matchedFilenames = await glob.glob(pattern, {
56127
+ ...restOptions,
56128
+ ignore: typeof ignore === 'string' || ignore === undefined ? ignore : [...ignore],
56129
+ });
56130
+ return matchedFilenames
56131
+ .map((matchedFilename) => matchedFilename.split('\\').join('/'))
56132
+ .sort((filenameA, filenameB) => filenameA.localeCompare(filenameB, 'en'));
56133
+ }
56134
+ // Note: Not [~🟢~] because it is not directly dependent on `fs`, same as `listAllFiles`
56135
+
56072
56136
  /**
56073
56137
  * Initializes `prettify` command for Promptbook CLI utilities
56074
56138
  *
@@ -56090,7 +56154,7 @@
56090
56154
  prettifyCommand.option('-i, --ignore <glob>', `Ignore as glob pattern`);
56091
56155
  prettifyCommand.action(handleActionErrors(async (filesGlob, cliOptions) => {
56092
56156
  const { ignore, verbose: isVerbose } = cliOptions;
56093
- const filenames = await glob__default["default"](filesGlob, { ignore });
56157
+ const filenames = await findFilesByGlob(filesGlob, { ignore });
56094
56158
  // <- TODO: [😶]
56095
56159
  for (const filename of filenames) {
56096
56160
  if (!filename.endsWith('.book') && isVerbose) {
@@ -58922,7 +58986,7 @@
58922
58986
  };
58923
58987
  }
58924
58988
  const ignore = ignoreRaw.split(',').map((pattern) => pattern.trim());
58925
- const filenames = await glob__default["default"](filesGlob, { ignore });
58989
+ const filenames = await findFilesByGlob(filesGlob, { ignore });
58926
58990
  // <- TODO: [😶]
58927
58991
  // console.log({ filesGlob, ignore, filenames });
58928
58992
  // await forTime(1000000);
@@ -74195,7 +74259,7 @@
74195
74259
  const month = (now.getMonth() + 1).toString().padStart(2, '0');
74196
74260
  const datePrefix = `${year}-${month}`;
74197
74261
  const step = (_b = options.step) !== null && _b !== void 0 ? _b : 10;
74198
- const promptFiles = await glob__default["default"]('**/*.md', {
74262
+ const promptFiles = await findFilesByGlob('**/*.md', {
74199
74263
  cwd: options.promptsDir,
74200
74264
  ignore: options.ignoreGlobs,
74201
74265
  nodir: true,
@@ -74341,7 +74405,7 @@
74341
74405
  async function findFilesToScan(rootDir, includeGlobs, ignoreGlobs) {
74342
74406
  const files = new Set();
74343
74407
  for (const pattern of includeGlobs) {
74344
- const matches = await glob__default["default"](pattern, {
74408
+ const matches = await findFilesByGlob(pattern, {
74345
74409
  cwd: rootDir,
74346
74410
  ignore: Array.from(new Set([...ignoreGlobs, ...DEFAULT_IGNORE_GLOBS])),
74347
74411
  nodir: true,
@@ -75091,7 +75155,7 @@
75091
75155
  const patterns = [...SOURCE_ROOTS.map((root) => `${root}/**/*.${extensionGlob}`), `*.${extensionGlob}`];
75092
75156
  const files = new Set();
75093
75157
  for (const pattern of patterns) {
75094
- const matches = await glob__default["default"](pattern, {
75158
+ const matches = await findFilesByGlob(pattern, {
75095
75159
  cwd: rootDir,
75096
75160
  ignore: SOURCE_FILE_IGNORE_GLOBS,
75097
75161
  nodir: true,
@@ -75114,7 +75178,7 @@
75114
75178
  async function buildExemptPathSet(rootDir, patterns, isIgnoredRelativePath) {
75115
75179
  const exemptPaths = new Set();
75116
75180
  for (const pattern of patterns) {
75117
- const matches = await glob__default["default"](pattern, {
75181
+ const matches = await findFilesByGlob(pattern, {
75118
75182
  cwd: rootDir,
75119
75183
  ignore: SOURCE_FILE_IGNORE_GLOBS,
75120
75184
  nodir: true,
@@ -75159,7 +75223,7 @@
75159
75223
  if (!fs.existsSync(promptsDir)) {
75160
75224
  return new Set();
75161
75225
  }
75162
- const promptFiles = await glob__default["default"]('**/*.md', {
75226
+ const promptFiles = await findFilesByGlob('**/*.md', {
75163
75227
  cwd: promptsDir,
75164
75228
  nodir: true,
75165
75229
  });
@@ -80077,30 +80141,6 @@
80077
80141
  }
80078
80142
  }
80079
80143
 
80080
- /**
80081
- * Refreshes optional harness subscription usage in the shared coder-run UI state.
80082
- *
80083
- * Subscription visibility is an enhancement, not a prerequisite for running prompts. A harness which cannot expose a
80084
- * snapshot, or whose account endpoint is temporarily unavailable, therefore leaves the existing dashboard unchanged.
80085
- *
80086
- * @private internal utility of coder run UI
80087
- */
80088
- async function refreshCoderRunUiSubscriptionUsage(options) {
80089
- const { runner, uiState } = options;
80090
- if (!uiState || !runner.getSubscriptionUsage) {
80091
- return;
80092
- }
80093
- try {
80094
- const subscriptionUsage = await runner.getSubscriptionUsage();
80095
- if (subscriptionUsage) {
80096
- uiState.setSubscriptionUsage(subscriptionUsage);
80097
- }
80098
- }
80099
- catch (_a) {
80100
- // A current subscription snapshot must never interrupt the coding queue.
80101
- }
80102
- }
80103
-
80104
80144
  /**
80105
80145
  * Maximum number of retry attempts performed after a prompt round throws an error.
80106
80146
  * After this many retries the round is finalized as failed.
@@ -80174,10 +80214,6 @@
80174
80214
  }),
80175
80215
  waitForPauseCheckpoint: waitForRequestedPause,
80176
80216
  });
80177
- await refreshCoderRunUiSubscriptionUsage({
80178
- runner,
80179
- uiState: uiHandle === null || uiHandle === void 0 ? void 0 : uiHandle.state,
80180
- });
80181
80217
  await finalizeSuccessfulPromptRound({
80182
80218
  options,
80183
80219
  nextPrompt,
@@ -81304,6 +81340,80 @@
81304
81340
  }
81305
81341
  }
81306
81342
 
81343
+ /**
81344
+ * Refreshes optional harness subscription usage in the shared coder-run UI state.
81345
+ *
81346
+ * Subscription visibility is an enhancement, not a prerequisite for running prompts. A harness which cannot expose a
81347
+ * snapshot, or whose account endpoint is temporarily unavailable, therefore leaves the existing dashboard unchanged.
81348
+ *
81349
+ * @private internal utility of coder run UI
81350
+ */
81351
+ async function refreshCoderRunUiSubscriptionUsage(options) {
81352
+ const { runner, uiState } = options;
81353
+ if (!uiState || !runner.getSubscriptionUsage) {
81354
+ return;
81355
+ }
81356
+ try {
81357
+ const subscriptionUsage = await runner.getSubscriptionUsage();
81358
+ if (subscriptionUsage) {
81359
+ uiState.setSubscriptionUsage(subscriptionUsage);
81360
+ }
81361
+ }
81362
+ catch (_a) {
81363
+ // A current subscription snapshot must never interrupt the coding queue.
81364
+ }
81365
+ }
81366
+
81367
+ /**
81368
+ * How often the harness subscription usage is re-read while `ptbk coder` is running.
81369
+ *
81370
+ * @private internal constant of coder run UI
81371
+ */
81372
+ const CODER_RUN_SUBSCRIPTION_USAGE_REFRESH_INTERVAL_MS = 5 * 1000;
81373
+ /**
81374
+ * Keeps the harness subscription usage of the coder-run dashboard current for the whole run.
81375
+ *
81376
+ * A single coding prompt can take hours, so reading the usage once per prompt leaves the dashboard showing values
81377
+ * which are long out of date. Reading it on its own clock instead means the percentages and reset countdowns always
81378
+ * describe the present moment, no matter how long the current prompt runs.
81379
+ *
81380
+ * Refreshes never overlap: a read which is still in flight when the next tick arrives simply skips that tick, so a
81381
+ * slow or hanging harness cannot pile up requests. The whole refresh is optional dashboard information, so a harness
81382
+ * without subscription limits and a run without a dashboard start no timer at all.
81383
+ *
81384
+ * @private internal utility of coder run UI
81385
+ */
81386
+ function startCoderRunUiSubscriptionUsageRefresh(options) {
81387
+ var _a;
81388
+ const { runner, uiState, refreshIntervalMs = CODER_RUN_SUBSCRIPTION_USAGE_REFRESH_INTERVAL_MS } = options;
81389
+ if (!uiState || !runner.getSubscriptionUsage) {
81390
+ return { stop: () => { } };
81391
+ }
81392
+ let isRefreshing = false;
81393
+ /**
81394
+ * Reads one fresh snapshot unless the previous read has not finished yet.
81395
+ */
81396
+ const refreshSubscriptionUsage = () => {
81397
+ if (isRefreshing) {
81398
+ return;
81399
+ }
81400
+ isRefreshing = true;
81401
+ void refreshCoderRunUiSubscriptionUsage({ runner, uiState }).finally(() => {
81402
+ isRefreshing = false;
81403
+ });
81404
+ };
81405
+ // Note: The dashboard shows the usage from its very first frames on instead of waiting out one whole interval
81406
+ refreshSubscriptionUsage();
81407
+ const refreshInterval = setInterval(refreshSubscriptionUsage, refreshIntervalMs);
81408
+ // Note: Optional dashboard information must never keep the `ptbk coder` process alive after the queue is done
81409
+ (_a = refreshInterval.unref) === null || _a === void 0 ? void 0 : _a.call(refreshInterval);
81410
+ return {
81411
+ stop() {
81412
+ clearInterval(refreshInterval);
81413
+ },
81414
+ };
81415
+ }
81416
+
81307
81417
  /**
81308
81418
  * Creates the one queue prompt used to repair a pre-existing test failure.
81309
81419
  */
@@ -81403,6 +81513,7 @@
81403
81513
  }),
81404
81514
  });
81405
81515
  startPauseListenerIfNeeded(isRichUiEnabled);
81516
+ let subscriptionUsageRefresh;
81406
81517
  try {
81407
81518
  const resolvedCoderContext = await resolveCoderContext(options.context, process.cwd());
81408
81519
  const resolvedCoderAgent = await resolveCoderAgent(options.agent, process.cwd());
@@ -81428,7 +81539,8 @@
81428
81539
  console.info(colors__default["default"].green(`Running prompts with ${runner.name}`));
81429
81540
  initializeRunUi(uiHandle, runner.name, actualRunnerModel, options);
81430
81541
  await initializeRunUiAgentVisual(uiHandle, resolvedCoderAgent === null || resolvedCoderAgent === void 0 ? void 0 : resolvedCoderAgent.agentSource);
81431
- await refreshCoderRunUiSubscriptionUsage({
81542
+ // Note: The usage keeps refreshing on its own clock from here on, so a long prompt no longer freezes it
81543
+ subscriptionUsageRefresh = startCoderRunUiSubscriptionUsageRefresh({
81432
81544
  runner,
81433
81545
  uiState: uiHandle === null || uiHandle === void 0 ? void 0 : uiHandle.state,
81434
81546
  });
@@ -81609,6 +81721,7 @@
81609
81721
  }
81610
81722
  }
81611
81723
  finally {
81724
+ subscriptionUsageRefresh === null || subscriptionUsageRefresh === void 0 ? void 0 : subscriptionUsageRefresh.stop();
81612
81725
  cleanupRunDisplays(progressDisplay, uiHandle, options);
81613
81726
  resetCoderRunControls();
81614
81727
  }