@promptbook/cli 0.112.0-121 → 0.112.0-123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/messages/route.ts +4 -11
- package/esm/index.es.js +1353 -277
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +6 -0
- package/esm/scripts/run-codex-prompts/main/findUnwrittenPrompts.d.ts +19 -0
- package/esm/scripts/run-codex-prompts/main/runCodexPromptsServer.d.ts +27 -0
- package/esm/scripts/run-codex-prompts/main/runPromptRound.d.ts +2 -1
- package/esm/scripts/run-codex-prompts/server/coderServerHtml.d.ts +9 -0
- package/esm/scripts/run-codex-prompts/server/runCoderHttpServer.d.ts +23 -0
- package/esm/scripts/run-codex-prompts/server/updatePromptSection.d.ts +9 -0
- package/esm/src/cli/cli-commands/coder/find-unwritten.d.ts +10 -0
- package/esm/src/cli/cli-commands/coder/server.d.ts +13 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/cli/cli-commands/coder/find-unwritten.ts +58 -0
- package/src/cli/cli-commands/coder/init.ts +4 -1
- package/src/cli/cli-commands/coder/run.ts +26 -11
- package/src/cli/cli-commands/coder/server.ts +239 -0
- package/src/cli/cli-commands/coder.ts +6 -0
- package/src/other/templates/getTemplatesPipelineCollection.ts +825 -1034
- package/src/version.ts +2 -2
- package/src/versions.txt +2 -1
- package/umd/index.umd.js +1355 -279
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +6 -0
- package/umd/scripts/run-codex-prompts/main/findUnwrittenPrompts.d.ts +19 -0
- package/umd/scripts/run-codex-prompts/main/runCodexPromptsServer.d.ts +27 -0
- package/umd/scripts/run-codex-prompts/main/runPromptRound.d.ts +2 -1
- package/umd/scripts/run-codex-prompts/server/coderServerHtml.d.ts +9 -0
- package/umd/scripts/run-codex-prompts/server/runCoderHttpServer.d.ts +23 -0
- package/umd/scripts/run-codex-prompts/server/updatePromptSection.d.ts +9 -0
- package/umd/src/cli/cli-commands/coder/find-unwritten.d.ts +10 -0
- package/umd/src/cli/cli-commands/coder/server.d.ts +13 -0
- package/umd/src/version.d.ts +1 -1
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('child_process'), require('crypto'), require('fs'), require('dotenv'), require('moment'), require('waitasecond'), require('prompts'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('socket.io-client'), require('jszip'), require('@mozilla/readability'), require('jsdom'), require('crypto-js'), require('showdown'), 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('@anthropic-ai/sdk'), require('bottleneck'), require('@azure/openai'), require('rxjs'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'colors', 'commander', 'spacetrim', 'fs/promises', 'path', 'child_process', 'crypto', 'fs', 'dotenv', 'moment', 'waitasecond', 'prompts', 'crypto-js/enc-hex', 'crypto-js/sha256', 'socket.io-client', 'jszip', '@mozilla/readability', 'jsdom', 'crypto-js', 'showdown', 'glob-promise', 'http', 'express', 'socket.io', 'express-openapi-validator', 'swagger-ui-express', 'react', 'react-dom/server', '@anthropic-ai/sdk', 'bottleneck', '@azure/openai', 'rxjs', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global._spaceTrim, global.promises, global.path, global.child_process, global.crypto, global.fs, global.dotenv, global.moment, global.waitasecond, global.prompts, global.hexEncoder, global.sha256, global.socket_ioClient, global.JSZip, global.readability, global.jsdom, global.CryptoJS, global.showdown, global.glob, global.http, global.express, global.socket_io, global.OpenApiValidator, global.swaggerUi, global.react, global.server, global.Anthropic, global.Bottleneck, global.openai, global.rxjs, global.
|
|
5
|
-
})(this, (function (exports, colors, commander, _spaceTrim, promises, path, child_process, crypto, fs, dotenv, moment, waitasecond, prompts, hexEncoder, sha256, socket_ioClient, JSZip, readability, jsdom, CryptoJS, showdown, glob, http, express, socket_io, OpenApiValidator, swaggerUi, react, server, Anthropic, Bottleneck, openai, rxjs,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('commander'), require('spacetrim'), require('fs/promises'), require('path'), require('child_process'), require('crypto'), require('fs'), require('dotenv'), require('moment'), require('waitasecond'), require('prompts'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('socket.io-client'), require('jszip'), require('@mozilla/readability'), require('jsdom'), require('crypto-js'), require('showdown'), 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('@anthropic-ai/sdk'), require('bottleneck'), require('@azure/openai'), require('rxjs'), require('@openai/agents'), require('openai'), require('typescript'), require('ignore'), require('readline'), require('mime-types'), require('papaparse'), require('url'), require('events'), require('pg'), require('@supabase/supabase-js')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'colors', 'commander', 'spacetrim', 'fs/promises', 'path', 'child_process', 'crypto', 'fs', 'dotenv', 'moment', 'waitasecond', 'prompts', 'crypto-js/enc-hex', 'crypto-js/sha256', 'socket.io-client', 'jszip', '@mozilla/readability', 'jsdom', 'crypto-js', 'showdown', 'glob-promise', 'http', 'express', 'socket.io', 'express-openapi-validator', 'swagger-ui-express', 'react', 'react-dom/server', '@anthropic-ai/sdk', 'bottleneck', '@azure/openai', 'rxjs', '@openai/agents', 'openai', 'typescript', 'ignore', 'readline', 'mime-types', 'papaparse', 'url', 'events', 'pg', '@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.child_process, global.crypto, global.fs, global.dotenv, global.moment, global.waitasecond, global.prompts, global.hexEncoder, global.sha256, global.socket_ioClient, global.JSZip, global.readability, global.jsdom, global.CryptoJS, global.showdown, global.glob, global.http, global.express, global.socket_io, global.OpenApiValidator, global.swaggerUi, global.react, global.server, global.Anthropic, global.Bottleneck, global.openai, global.rxjs, global.agents, global.OpenAI, global.ts, global.ignore, global.readline, global.mimeTypes, global.papaparse, global.url, global.events, global.pg));
|
|
5
|
+
})(this, (function (exports, colors, commander, _spaceTrim, promises, path, child_process, crypto, fs, dotenv, moment, waitasecond, prompts, hexEncoder, sha256, socket_ioClient, JSZip, readability, jsdom, CryptoJS, showdown, glob, http, express, socket_io, OpenApiValidator, swaggerUi, react, server, Anthropic, Bottleneck, openai, rxjs, agents, OpenAI, ts, ignore, readline, mimeTypes, papaparse, url, events, pg) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
var swaggerUi__default = /*#__PURE__*/_interopDefaultLegacy(swaggerUi);
|
|
44
44
|
var Anthropic__default = /*#__PURE__*/_interopDefaultLegacy(Anthropic);
|
|
45
45
|
var Bottleneck__default = /*#__PURE__*/_interopDefaultLegacy(Bottleneck);
|
|
46
|
-
var papaparse__default = /*#__PURE__*/_interopDefaultLegacy(papaparse);
|
|
47
46
|
var OpenAI__default = /*#__PURE__*/_interopDefaultLegacy(OpenAI);
|
|
48
47
|
var ts__namespace = /*#__PURE__*/_interopNamespace(ts);
|
|
49
48
|
var ignore__default = /*#__PURE__*/_interopDefaultLegacy(ignore);
|
|
50
49
|
var readline__namespace = /*#__PURE__*/_interopNamespace(readline);
|
|
50
|
+
var papaparse__default = /*#__PURE__*/_interopDefaultLegacy(papaparse);
|
|
51
51
|
|
|
52
52
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
53
53
|
/**
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
* @generated
|
|
64
64
|
* @see https://github.com/webgptorg/promptbook
|
|
65
65
|
*/
|
|
66
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
66
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-123';
|
|
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
|
|
@@ -4021,6 +4021,21 @@
|
|
|
4021
4021
|
function resetPauseTargetLabel() {
|
|
4022
4022
|
setPauseTargetLabel(DEFAULT_PAUSE_TARGET_LABEL);
|
|
4023
4023
|
}
|
|
4024
|
+
/**
|
|
4025
|
+
* Requests a pause from an external controller (e.g. the Ink UI).
|
|
4026
|
+
*/
|
|
4027
|
+
function requestPause() {
|
|
4028
|
+
if (pauseState === 'RUNNING') {
|
|
4029
|
+
setPauseState('PAUSING');
|
|
4030
|
+
}
|
|
4031
|
+
}
|
|
4032
|
+
/**
|
|
4033
|
+
* Resumes execution from an external controller after a pause.
|
|
4034
|
+
*/
|
|
4035
|
+
function requestResume() {
|
|
4036
|
+
setPauseState('RUNNING');
|
|
4037
|
+
resetPauseTargetLabel();
|
|
4038
|
+
}
|
|
4024
4039
|
|
|
4025
4040
|
/**
|
|
4026
4041
|
* Just says that the variable is not used but should be kept
|
|
@@ -38613,6 +38628,48 @@
|
|
|
38613
38628
|
// Note: [🟡] Code for CLI command [find-refactor-candidates](src/cli/cli-commands/coder/find-refactor-candidates.ts) should never be published outside of `@promptbook/cli`
|
|
38614
38629
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
38615
38630
|
|
|
38631
|
+
/**
|
|
38632
|
+
* Initializes `coder find-unwritten` command for Promptbook CLI utilities
|
|
38633
|
+
*
|
|
38634
|
+
* Note: `$` is used to indicate that this function is not a pure function - it registers a command in the CLI
|
|
38635
|
+
*
|
|
38636
|
+
* @private internal function of `promptbookCli`
|
|
38637
|
+
*/
|
|
38638
|
+
function $initializeCoderFindUnwrittenCommand(program) {
|
|
38639
|
+
const command = program.command('find-unwritten');
|
|
38640
|
+
command.description('List all prompt sections that still need to be authored (contain @@@ placeholder)');
|
|
38641
|
+
command.option('--priority <minimum-priority>', 'Filter prompts by minimum priority level', parseIntOption$2, 0);
|
|
38642
|
+
command.action(handleActionErrors(async (cliOptions) => {
|
|
38643
|
+
const { priority = 0 } = cliOptions;
|
|
38644
|
+
// Note: Import the function dynamically to avoid loading heavy dependencies until needed
|
|
38645
|
+
const { findUnwrittenPrompts } = await Promise.resolve().then(function () { return findUnwrittenPrompts$1; });
|
|
38646
|
+
try {
|
|
38647
|
+
await findUnwrittenPrompts({ priority });
|
|
38648
|
+
}
|
|
38649
|
+
catch (error) {
|
|
38650
|
+
assertsError(error);
|
|
38651
|
+
console.error(colors__default["default"].bgRed(`${error.name}`));
|
|
38652
|
+
console.error(colors__default["default"].red(error.stack || error.message));
|
|
38653
|
+
return process.exit(1);
|
|
38654
|
+
}
|
|
38655
|
+
return process.exit(0);
|
|
38656
|
+
}));
|
|
38657
|
+
}
|
|
38658
|
+
/**
|
|
38659
|
+
* Parses an integer option value
|
|
38660
|
+
*
|
|
38661
|
+
* @private internal utility of `coder find-unwritten` command
|
|
38662
|
+
*/
|
|
38663
|
+
function parseIntOption$2(value) {
|
|
38664
|
+
const parsed = parseInt(value, 10);
|
|
38665
|
+
if (isNaN(parsed)) {
|
|
38666
|
+
throw new Error(`Invalid number: ${value}`);
|
|
38667
|
+
}
|
|
38668
|
+
return parsed;
|
|
38669
|
+
}
|
|
38670
|
+
// Note: [🟡] Code for CLI command [find-unwritten](src/cli/cli-commands/coder/find-unwritten.ts) should never be published outside of `@promptbook/cli`
|
|
38671
|
+
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
38672
|
+
|
|
38616
38673
|
/**
|
|
38617
38674
|
* Relative path to the root prompts directory used by Promptbook coder utilities.
|
|
38618
38675
|
*
|
|
@@ -39519,8 +39576,10 @@
|
|
|
39519
39576
|
- CODING_AGENT_GIT_SIGNING_KEY
|
|
39520
39577
|
`));
|
|
39521
39578
|
command.action(handleActionErrors(async () => {
|
|
39522
|
-
const
|
|
39579
|
+
const projectPath = process.cwd();
|
|
39580
|
+
const summary = await initializeCoderProjectConfiguration(projectPath);
|
|
39523
39581
|
printInitializationSummary(summary);
|
|
39582
|
+
await generatePromptBoilerplate({ projectPath, filesCount: 5 });
|
|
39524
39583
|
}));
|
|
39525
39584
|
}
|
|
39526
39585
|
/**
|
|
@@ -39612,11 +39671,12 @@
|
|
|
39612
39671
|
`));
|
|
39613
39672
|
command.option('--dry-run', 'Print unwritten prompts without executing', false);
|
|
39614
39673
|
addPromptRunnerSelectionOptions(command);
|
|
39674
|
+
command.option('--agent <agent-book-path>', 'Path to a .book file whose compiled system message is prepended to each coding prompt');
|
|
39615
39675
|
command.option('--context <context-or-file>', 'Append extra instructions either inline or from a file path relative to the current project');
|
|
39616
39676
|
command.option('--test <test-command...>', 'Run a verification command after each prompt; quote it when the command itself contains top-level flags');
|
|
39617
39677
|
command.option('--preserve-logs', 'Keep generated temp prompt/log artifacts after successful rounds for debugging and analytics', false);
|
|
39618
39678
|
addPromptRunnerExecutionOptions(command);
|
|
39619
|
-
command.option('--priority <minimum-priority>', 'Filter prompts by minimum priority level', parseIntOption, 0);
|
|
39679
|
+
command.option('--priority <minimum-priority>', 'Filter prompts by minimum priority level', parseIntOption$1, 0);
|
|
39620
39680
|
command.option('--wait [duration]', _spaceTrim.spaceTrim(`
|
|
39621
39681
|
Wait between prompt rounds.
|
|
39622
39682
|
Without a value (default): waits for user confirmation before each prompt (interactive mode).
|
|
@@ -39627,8 +39687,8 @@
|
|
|
39627
39687
|
command.option('--auto-migrate', 'Run testing-server database migrations automatically after each successfully processed prompt');
|
|
39628
39688
|
command.option('--allow-destructive-auto-migrate', 'Allow auto-migrate even when heuristic SQL safety check flags destructive pending migrations');
|
|
39629
39689
|
command.action(handleActionErrors(async (cliOptions) => {
|
|
39630
|
-
const { dryRun, context, test, preserveLogs, priority, wait, autoMigrate, allowDestructiveAutoMigrate } = cliOptions;
|
|
39631
|
-
const testCommand = normalizeCommandOptionValue(test);
|
|
39690
|
+
const { dryRun, agent, context, test, preserveLogs, priority, wait, autoMigrate, allowDestructiveAutoMigrate, } = cliOptions;
|
|
39691
|
+
const testCommand = normalizeCommandOptionValue$1(test);
|
|
39632
39692
|
const runnerOptions = normalizePromptRunnerCliOptions(cliOptions, {
|
|
39633
39693
|
isAgentRequired: !dryRun,
|
|
39634
39694
|
});
|
|
@@ -39653,6 +39713,7 @@
|
|
|
39653
39713
|
ignoreGitChanges: runnerOptions.ignoreGitChanges,
|
|
39654
39714
|
agentName: runnerOptions.agentName,
|
|
39655
39715
|
model: runnerOptions.model,
|
|
39716
|
+
agent,
|
|
39656
39717
|
context,
|
|
39657
39718
|
testCommand,
|
|
39658
39719
|
preserveLogs,
|
|
@@ -39686,7 +39747,7 @@
|
|
|
39686
39747
|
*
|
|
39687
39748
|
* @private internal utility of `coder run` command
|
|
39688
39749
|
*/
|
|
39689
|
-
function parseIntOption(value) {
|
|
39750
|
+
function parseIntOption$1(value) {
|
|
39690
39751
|
const parsed = parseInt(value, 10);
|
|
39691
39752
|
if (isNaN(parsed)) {
|
|
39692
39753
|
throw new Error(`Invalid number: ${value}`);
|
|
@@ -39698,7 +39759,7 @@
|
|
|
39698
39759
|
*
|
|
39699
39760
|
* @private internal utility of `coder run` command
|
|
39700
39761
|
*/
|
|
39701
|
-
function normalizeCommandOptionValue(value) {
|
|
39762
|
+
function normalizeCommandOptionValue$1(value) {
|
|
39702
39763
|
if (value === undefined) {
|
|
39703
39764
|
return undefined;
|
|
39704
39765
|
}
|
|
@@ -39713,6 +39774,157 @@
|
|
|
39713
39774
|
// Note: [🟡] Code for CLI command [run](src/cli/cli-commands/coder/run.ts) should never be published outside of `@promptbook/cli`
|
|
39714
39775
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
39715
39776
|
|
|
39777
|
+
/**
|
|
39778
|
+
* Default port used by `ptbk coder server`.
|
|
39779
|
+
*
|
|
39780
|
+
* @private internal constant of `ptbk coder server`
|
|
39781
|
+
*/
|
|
39782
|
+
const DEFAULT_CODER_SERVER_PORT = '4441';
|
|
39783
|
+
/**
|
|
39784
|
+
* Initializes `coder server` command for Promptbook CLI utilities.
|
|
39785
|
+
*
|
|
39786
|
+
* Runs the same prompt processing logic as `ptbk coder run` but keeps the process alive
|
|
39787
|
+
* and serves a kanban web UI on the configured port.
|
|
39788
|
+
*
|
|
39789
|
+
* Note: `$` is used to indicate that this function is not a pure function - it registers a command in the CLI
|
|
39790
|
+
*
|
|
39791
|
+
* @private internal function of `promptbookCli`
|
|
39792
|
+
*/
|
|
39793
|
+
function $initializeCoderServerCommand(program) {
|
|
39794
|
+
const command = program.command('server');
|
|
39795
|
+
command.description(_spaceTrim.spaceTrim(`
|
|
39796
|
+
Start a coder server that watches for prompts and serves a kanban web UI
|
|
39797
|
+
|
|
39798
|
+
${PROMPT_RUNNER_DESCRIPTION}
|
|
39799
|
+
|
|
39800
|
+
Features:
|
|
39801
|
+
- Runs the same prompt processing as \`ptbk coder run\`
|
|
39802
|
+
- Does not exit when all prompts are done; polls for new prompt files instead
|
|
39803
|
+
- Serves a kanban board at http://localhost:<port> for visual progress tracking
|
|
39804
|
+
- Allows editing prompt files directly from the browser (Trello-style)
|
|
39805
|
+
- Play / pause button in the browser stays in sync with the CLI pause state
|
|
39806
|
+
- Press "p" in the terminal to pause / resume (same as \`ptbk coder run\`)
|
|
39807
|
+
`));
|
|
39808
|
+
command.addOption(new commander.Option('--port <port>', 'Port to start the coder server on')
|
|
39809
|
+
.env('PTBK_CODER_SERVER_PORT')
|
|
39810
|
+
.default(DEFAULT_CODER_SERVER_PORT));
|
|
39811
|
+
command.option('--dry-run', 'Print unwritten prompts without executing', false);
|
|
39812
|
+
addPromptRunnerSelectionOptions(command);
|
|
39813
|
+
command.option('--agent <agent-book-path>', 'Path to a .book file whose compiled system message is prepended to each coding prompt');
|
|
39814
|
+
command.option('--context <context-or-file>', 'Append extra instructions either inline or from a file path relative to the current project');
|
|
39815
|
+
command.option('--test <test-command...>', 'Run a verification command after each prompt; quote it when the command itself contains top-level flags');
|
|
39816
|
+
command.option('--preserve-logs', 'Keep generated temp prompt/log artifacts after successful rounds for debugging and analytics', false);
|
|
39817
|
+
addPromptRunnerExecutionOptions(command);
|
|
39818
|
+
command.option('--priority <minimum-priority>', 'Filter prompts by minimum priority level', parseIntOption, 0);
|
|
39819
|
+
command.option('--wait [duration]', _spaceTrim.spaceTrim(`
|
|
39820
|
+
Wait between prompt rounds.
|
|
39821
|
+
Without a value (default): waits for user confirmation before each prompt (interactive mode).
|
|
39822
|
+
With a duration like 1h, 30m, 5s: waits that long between prompts to avoid hitting rate limits of the harness.
|
|
39823
|
+
`), true);
|
|
39824
|
+
command.option('--no-wait', 'Skip all waiting between prompts and run non-interactively');
|
|
39825
|
+
command.option('--auto-migrate', 'Run testing-server database migrations automatically after each successfully processed prompt');
|
|
39826
|
+
command.option('--allow-destructive-auto-migrate', 'Allow auto-migrate even when heuristic SQL safety check flags destructive pending migrations');
|
|
39827
|
+
command.action(handleActionErrors(async (cliOptions) => {
|
|
39828
|
+
const { port: rawPort, dryRun, agent, context, test, preserveLogs, priority, wait, autoMigrate, allowDestructiveAutoMigrate, } = cliOptions;
|
|
39829
|
+
const port = parseCoderServerPort(rawPort);
|
|
39830
|
+
const testCommand = normalizeCommandOptionValue(test);
|
|
39831
|
+
const runnerOptions = normalizePromptRunnerCliOptions(cliOptions, {
|
|
39832
|
+
isAgentRequired: !dryRun,
|
|
39833
|
+
});
|
|
39834
|
+
// [1] Parse the --wait option (same logic as `coder run`)
|
|
39835
|
+
let waitForUser = false;
|
|
39836
|
+
let waitBetweenPrompts = 0;
|
|
39837
|
+
if (wait === true) {
|
|
39838
|
+
waitForUser = true;
|
|
39839
|
+
}
|
|
39840
|
+
else if (typeof wait === 'string' && wait !== '') {
|
|
39841
|
+
waitBetweenPrompts = parseDuration(wait);
|
|
39842
|
+
}
|
|
39843
|
+
const runOptions = {
|
|
39844
|
+
port,
|
|
39845
|
+
dryRun,
|
|
39846
|
+
waitForUser,
|
|
39847
|
+
waitBetweenPrompts,
|
|
39848
|
+
noCommit: runnerOptions.noCommit,
|
|
39849
|
+
ignoreGitChanges: runnerOptions.ignoreGitChanges,
|
|
39850
|
+
agentName: runnerOptions.agentName,
|
|
39851
|
+
model: runnerOptions.model,
|
|
39852
|
+
agent,
|
|
39853
|
+
context,
|
|
39854
|
+
testCommand,
|
|
39855
|
+
preserveLogs,
|
|
39856
|
+
noUi: runnerOptions.noUi,
|
|
39857
|
+
thinkingLevel: runnerOptions.thinkingLevel,
|
|
39858
|
+
priority,
|
|
39859
|
+
normalizeLineEndings: runnerOptions.normalizeLineEndings,
|
|
39860
|
+
allowCredits: runnerOptions.allowCredits,
|
|
39861
|
+
autoMigrate,
|
|
39862
|
+
allowDestructiveAutoMigrate,
|
|
39863
|
+
autoPush: runnerOptions.autoPush,
|
|
39864
|
+
autoPull: runnerOptions.autoPull,
|
|
39865
|
+
};
|
|
39866
|
+
// Note: Import dynamically to avoid loading heavy dependencies until needed
|
|
39867
|
+
const { runCodexPromptsServer } = await Promise.resolve().then(function () { return runCodexPromptsServer$1; });
|
|
39868
|
+
try {
|
|
39869
|
+
await runCodexPromptsServer(runOptions);
|
|
39870
|
+
}
|
|
39871
|
+
catch (error) {
|
|
39872
|
+
assertsError(error);
|
|
39873
|
+
console.error(colors__default["default"].bgRed(`${error.name}`));
|
|
39874
|
+
console.error(colors__default["default"].red(error.stack || error.message));
|
|
39875
|
+
return process.exit(1);
|
|
39876
|
+
}
|
|
39877
|
+
return process.exit(0);
|
|
39878
|
+
}));
|
|
39879
|
+
}
|
|
39880
|
+
/**
|
|
39881
|
+
* Parses and validates the coder server port number.
|
|
39882
|
+
*
|
|
39883
|
+
* @private internal utility of `coder server` command
|
|
39884
|
+
*/
|
|
39885
|
+
function parseCoderServerPort(rawPort) {
|
|
39886
|
+
const port = Number.parseInt(rawPort, 10);
|
|
39887
|
+
if (!Number.isInteger(port) || port <= 0 || port > NETWORK_LIMITS.MAX_PORT) {
|
|
39888
|
+
throw new NotAllowed(_spaceTrim.spaceTrim(`
|
|
39889
|
+
Invalid coder server port: \`${rawPort}\`.
|
|
39890
|
+
|
|
39891
|
+
Use \`--port\` or \`PTBK_CODER_SERVER_PORT\` with an integer between \`1\` and \`${NETWORK_LIMITS.MAX_PORT}\`.
|
|
39892
|
+
`));
|
|
39893
|
+
}
|
|
39894
|
+
return port;
|
|
39895
|
+
}
|
|
39896
|
+
/**
|
|
39897
|
+
* Parses an integer option value.
|
|
39898
|
+
*
|
|
39899
|
+
* @private internal utility of `coder server` command
|
|
39900
|
+
*/
|
|
39901
|
+
function parseIntOption(value) {
|
|
39902
|
+
const parsed = parseInt(value, 10);
|
|
39903
|
+
if (isNaN(parsed)) {
|
|
39904
|
+
throw new Error(`Invalid number: ${value}`);
|
|
39905
|
+
}
|
|
39906
|
+
return parsed;
|
|
39907
|
+
}
|
|
39908
|
+
/**
|
|
39909
|
+
* Joins one Commander option that may be parsed either as a single string or a variadic token array.
|
|
39910
|
+
*
|
|
39911
|
+
* @private internal utility of `coder server` command
|
|
39912
|
+
*/
|
|
39913
|
+
function normalizeCommandOptionValue(value) {
|
|
39914
|
+
if (value === undefined) {
|
|
39915
|
+
return undefined;
|
|
39916
|
+
}
|
|
39917
|
+
const parts = Array.isArray(value) ? value : [value];
|
|
39918
|
+
const normalizedValue = parts
|
|
39919
|
+
.map((part) => part.trim())
|
|
39920
|
+
.filter(Boolean)
|
|
39921
|
+
.join(' ')
|
|
39922
|
+
.trim();
|
|
39923
|
+
return normalizedValue === '' ? undefined : normalizedValue;
|
|
39924
|
+
}
|
|
39925
|
+
// Note: [🟡] Code for CLI command [server](src/cli/cli-commands/coder/server.ts) should never be published outside of `@promptbook/cli`
|
|
39926
|
+
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
39927
|
+
|
|
39716
39928
|
/**
|
|
39717
39929
|
* Initializes `coder verify` command for Promptbook CLI utilities
|
|
39718
39930
|
*
|
|
@@ -39784,7 +39996,9 @@
|
|
|
39784
39996
|
- init: Initialize coder configuration in current project
|
|
39785
39997
|
- generate-boilerplates: Generate prompt boilerplate files
|
|
39786
39998
|
- find-refactor-candidates: Find files that need refactoring
|
|
39999
|
+
- find-unwritten: List prompt sections that still need to be authored
|
|
39787
40000
|
- run: Run coding prompts with AI agents
|
|
40001
|
+
- server: Start a long-running coder server with a kanban web UI
|
|
39788
40002
|
- verify: Verify completed prompts
|
|
39789
40003
|
- find-fresh-emoji-tags: Find unused emoji tags
|
|
39790
40004
|
`));
|
|
@@ -39792,7 +40006,9 @@
|
|
|
39792
40006
|
$initializeCoderInitCommand(coderCommand);
|
|
39793
40007
|
$initializeCoderGenerateBoilerplatesCommand(coderCommand);
|
|
39794
40008
|
$initializeCoderFindRefactorCandidatesCommand(coderCommand);
|
|
40009
|
+
$initializeCoderFindUnwrittenCommand(coderCommand);
|
|
39795
40010
|
$initializeCoderRunCommand(coderCommand);
|
|
40011
|
+
$initializeCoderServerCommand(coderCommand);
|
|
39796
40012
|
$initializeCoderVerifyCommand(coderCommand);
|
|
39797
40013
|
$initializeCoderFindFreshEmojiTagCommand(coderCommand);
|
|
39798
40014
|
// If no subcommand is provided, show help
|
|
@@ -68628,6 +68844,303 @@
|
|
|
68628
68844
|
findRefactorCandidates: findRefactorCandidates
|
|
68629
68845
|
});
|
|
68630
68846
|
|
|
68847
|
+
/**
|
|
68848
|
+
* Checks whether a prompt section meets the minimum priority threshold.
|
|
68849
|
+
*/
|
|
68850
|
+
function hasSufficientPriority(section, minimumPriority) {
|
|
68851
|
+
return section.priority >= minimumPriority;
|
|
68852
|
+
}
|
|
68853
|
+
|
|
68854
|
+
/**
|
|
68855
|
+
* Trims leading and trailing empty lines.
|
|
68856
|
+
*/
|
|
68857
|
+
function trimEmptyEdges(lines) {
|
|
68858
|
+
let start = 0;
|
|
68859
|
+
while (start < lines.length) {
|
|
68860
|
+
const startLine = lines[start];
|
|
68861
|
+
if (startLine !== undefined && startLine.trim() !== '') {
|
|
68862
|
+
break;
|
|
68863
|
+
}
|
|
68864
|
+
start += 1;
|
|
68865
|
+
}
|
|
68866
|
+
let end = lines.length - 1;
|
|
68867
|
+
while (end >= start) {
|
|
68868
|
+
const endLine = lines[end];
|
|
68869
|
+
if (endLine !== undefined && endLine.trim() !== '') {
|
|
68870
|
+
break;
|
|
68871
|
+
}
|
|
68872
|
+
end -= 1;
|
|
68873
|
+
}
|
|
68874
|
+
return lines.slice(start, end + 1);
|
|
68875
|
+
}
|
|
68876
|
+
|
|
68877
|
+
/**
|
|
68878
|
+
* Extracts prompt lines without the status marker.
|
|
68879
|
+
*/
|
|
68880
|
+
function buildPromptLinesWithoutStatus(file, section) {
|
|
68881
|
+
const lines = file.lines.slice(section.startLine, section.endLine + 1);
|
|
68882
|
+
if (section.statusLineIndex !== undefined) {
|
|
68883
|
+
const relativeIndex = section.statusLineIndex - section.startLine;
|
|
68884
|
+
if (relativeIndex >= 0 && relativeIndex < lines.length) {
|
|
68885
|
+
lines.splice(relativeIndex, 1);
|
|
68886
|
+
}
|
|
68887
|
+
}
|
|
68888
|
+
return trimEmptyEdges(lines);
|
|
68889
|
+
}
|
|
68890
|
+
|
|
68891
|
+
/**
|
|
68892
|
+
* Builds the prompt text sent to the agent runner.
|
|
68893
|
+
*/
|
|
68894
|
+
function buildCodexPrompt(file, section) {
|
|
68895
|
+
const lines = buildPromptLinesWithoutStatus(file, section);
|
|
68896
|
+
for (let i = 0; i < lines.length; i++) {
|
|
68897
|
+
const line = lines[i];
|
|
68898
|
+
if (line === undefined || line.trim() === '') {
|
|
68899
|
+
continue;
|
|
68900
|
+
}
|
|
68901
|
+
lines[i] = line.replace(/^\[[^\]]+\]\s*/, '');
|
|
68902
|
+
break;
|
|
68903
|
+
}
|
|
68904
|
+
return lines.join(file.eol);
|
|
68905
|
+
}
|
|
68906
|
+
|
|
68907
|
+
/**
|
|
68908
|
+
* Checks whether a prompt section still needs authoring (contains "@@@").
|
|
68909
|
+
*/
|
|
68910
|
+
function isPromptToBeWritten(file, section) {
|
|
68911
|
+
return buildCodexPrompt(file, section).includes('@@@');
|
|
68912
|
+
}
|
|
68913
|
+
|
|
68914
|
+
/**
|
|
68915
|
+
* Lists todo prompts across all files.
|
|
68916
|
+
*/
|
|
68917
|
+
function listTodoPrompts(files) {
|
|
68918
|
+
const prompts = [];
|
|
68919
|
+
for (const file of files) {
|
|
68920
|
+
for (const section of file.sections) {
|
|
68921
|
+
if (section.status === 'todo') {
|
|
68922
|
+
prompts.push({ file, section });
|
|
68923
|
+
}
|
|
68924
|
+
}
|
|
68925
|
+
}
|
|
68926
|
+
return prompts;
|
|
68927
|
+
}
|
|
68928
|
+
|
|
68929
|
+
/**
|
|
68930
|
+
* Lists todo prompts that still contain authoring placeholders.
|
|
68931
|
+
*/
|
|
68932
|
+
function listPromptsToBeWritten(files, minimumPriority = 0) {
|
|
68933
|
+
return listTodoPrompts(files).filter((prompt) => isPromptToBeWritten(prompt.file, prompt.section) && hasSufficientPriority(prompt.section, minimumPriority));
|
|
68934
|
+
}
|
|
68935
|
+
|
|
68936
|
+
/**
|
|
68937
|
+
* Parses a prompt markdown file into sections and metadata.
|
|
68938
|
+
*/
|
|
68939
|
+
function parsePromptFile(filePath, content) {
|
|
68940
|
+
var _a, _b;
|
|
68941
|
+
const eol = content.includes('\r\n') ? '\r\n' : '\n';
|
|
68942
|
+
const hasFinalEol = content.endsWith('\n');
|
|
68943
|
+
const lines = content.split(/\r?\n/);
|
|
68944
|
+
const sections = [];
|
|
68945
|
+
let startLine = 0;
|
|
68946
|
+
let index = 0;
|
|
68947
|
+
for (let i = 0; i <= lines.length; i++) {
|
|
68948
|
+
const line = lines[i];
|
|
68949
|
+
const isSeparator = i < lines.length && line !== undefined && line.trim() === '---';
|
|
68950
|
+
const isEnd = i === lines.length;
|
|
68951
|
+
if (!isSeparator && !isEnd) {
|
|
68952
|
+
continue;
|
|
68953
|
+
}
|
|
68954
|
+
const endLine = i - 1;
|
|
68955
|
+
const firstNonEmptyLine = findFirstNonEmptyLine(lines, startLine, endLine);
|
|
68956
|
+
if (firstNonEmptyLine !== undefined) {
|
|
68957
|
+
const statusLine = (lines[firstNonEmptyLine] || '').trim();
|
|
68958
|
+
const parsedStatus = parseStatusLine(statusLine);
|
|
68959
|
+
const status = (_a = parsedStatus === null || parsedStatus === void 0 ? void 0 : parsedStatus.status) !== null && _a !== void 0 ? _a : 'not-ready';
|
|
68960
|
+
const priority = (_b = parsedStatus === null || parsedStatus === void 0 ? void 0 : parsedStatus.priority) !== null && _b !== void 0 ? _b : 0;
|
|
68961
|
+
sections.push({
|
|
68962
|
+
index,
|
|
68963
|
+
startLine,
|
|
68964
|
+
endLine,
|
|
68965
|
+
status,
|
|
68966
|
+
priority,
|
|
68967
|
+
statusLineIndex: parsedStatus ? firstNonEmptyLine : undefined,
|
|
68968
|
+
});
|
|
68969
|
+
index += 1;
|
|
68970
|
+
}
|
|
68971
|
+
startLine = i + 1;
|
|
68972
|
+
}
|
|
68973
|
+
return {
|
|
68974
|
+
path: filePath,
|
|
68975
|
+
name: path.basename(filePath),
|
|
68976
|
+
lines,
|
|
68977
|
+
eol,
|
|
68978
|
+
hasFinalEol,
|
|
68979
|
+
sections,
|
|
68980
|
+
};
|
|
68981
|
+
}
|
|
68982
|
+
/**
|
|
68983
|
+
* Parses a status line like "[ ] !!" or "[-]" or "[x] ~$0.65 21 minutes..." into status and priority.
|
|
68984
|
+
* For [x] done and [!] failed prompts, allow metadata after the status marker.
|
|
68985
|
+
*/
|
|
68986
|
+
function parseStatusLine(line) {
|
|
68987
|
+
var _a, _b, _c, _d, _e;
|
|
68988
|
+
// For done prompts [x], allow any content after (for cost/time metadata)
|
|
68989
|
+
const doneMatch = line.match(/^\[(?<status>[xX])\]/);
|
|
68990
|
+
if (doneMatch) {
|
|
68991
|
+
return { status: 'done', priority: 0 };
|
|
68992
|
+
}
|
|
68993
|
+
// For failed prompts [!], allow any content after (for failure metadata)
|
|
68994
|
+
const failedMatch = line.match(/^\[(?<status>!)\]/);
|
|
68995
|
+
if (failedMatch) {
|
|
68996
|
+
return { status: 'failed', priority: 0 };
|
|
68997
|
+
}
|
|
68998
|
+
// For todo [ ] and not-ready [-], require clean end with optional priority markers
|
|
68999
|
+
const match = line.match(/^\[(?<status>[ -])\]\s*(?<priority>!*)\s*$/);
|
|
69000
|
+
if (!match) {
|
|
69001
|
+
return undefined;
|
|
69002
|
+
}
|
|
69003
|
+
const statusChar = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a.status) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
69004
|
+
let status;
|
|
69005
|
+
if (statusChar === '-') {
|
|
69006
|
+
status = 'not-ready';
|
|
69007
|
+
}
|
|
69008
|
+
else {
|
|
69009
|
+
status = 'todo';
|
|
69010
|
+
}
|
|
69011
|
+
const priority = status === 'todo' ? (_e = (_d = (_c = match.groups) === null || _c === void 0 ? void 0 : _c.priority) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0 : 0;
|
|
69012
|
+
return { status, priority };
|
|
69013
|
+
}
|
|
69014
|
+
/**
|
|
69015
|
+
* Finds the first non-empty line index between two bounds.
|
|
69016
|
+
*/
|
|
69017
|
+
function findFirstNonEmptyLine(lines, startLine, endLine) {
|
|
69018
|
+
for (let i = startLine; i <= endLine; i++) {
|
|
69019
|
+
const line = lines[i];
|
|
69020
|
+
if (line !== undefined && line.trim() !== '') {
|
|
69021
|
+
return i;
|
|
69022
|
+
}
|
|
69023
|
+
}
|
|
69024
|
+
return undefined;
|
|
69025
|
+
}
|
|
69026
|
+
|
|
69027
|
+
/**
|
|
69028
|
+
* Loads and parses prompt files from the prompts directory.
|
|
69029
|
+
*/
|
|
69030
|
+
async function loadPromptFiles(promptsDir) {
|
|
69031
|
+
const entries = await promises.readdir(promptsDir, { withFileTypes: true });
|
|
69032
|
+
const files = entries
|
|
69033
|
+
.filter((entry) => entry.isFile() && entry.name.toLowerCase().endsWith('.md'))
|
|
69034
|
+
.map((entry) => path.join(promptsDir, entry.name))
|
|
69035
|
+
.sort((a, b) => a.localeCompare(b));
|
|
69036
|
+
const promptFiles = [];
|
|
69037
|
+
for (const filePath of files) {
|
|
69038
|
+
const content = await promises.readFile(filePath, 'utf-8');
|
|
69039
|
+
promptFiles.push(parsePromptFile(filePath, content));
|
|
69040
|
+
}
|
|
69041
|
+
return promptFiles;
|
|
69042
|
+
}
|
|
69043
|
+
|
|
69044
|
+
/**
|
|
69045
|
+
* Builds a display label using the prompt line number for easier navigation.
|
|
69046
|
+
*/
|
|
69047
|
+
function buildPromptLabelForDisplay(file, section) {
|
|
69048
|
+
return `${path.relative(process.cwd(), file.path).replace(/\\/g, '/')}#${section.startLine + 1}`;
|
|
69049
|
+
}
|
|
69050
|
+
|
|
69051
|
+
/**
|
|
69052
|
+
* Extracts a short summary line from a prompt section.
|
|
69053
|
+
*/
|
|
69054
|
+
function buildPromptSummary(file, section) {
|
|
69055
|
+
const lines = buildCodexPrompt(file, section).split(/\r?\n/);
|
|
69056
|
+
const firstLine = lines.find((line) => line.trim() !== '');
|
|
69057
|
+
return (firstLine === null || firstLine === void 0 ? void 0 : firstLine.trim()) || '(empty prompt)';
|
|
69058
|
+
}
|
|
69059
|
+
|
|
69060
|
+
/**
|
|
69061
|
+
* Prints the list of prompts that still need to be written.
|
|
69062
|
+
*/
|
|
69063
|
+
function printPromptsToBeWritten(files, minimumPriority = 0) {
|
|
69064
|
+
const promptsToWrite = listPromptsToBeWritten(files, minimumPriority);
|
|
69065
|
+
let i = 0;
|
|
69066
|
+
for (const { file, section } of promptsToWrite) {
|
|
69067
|
+
const label = buildPromptLabelForDisplay(file, section);
|
|
69068
|
+
const summary = buildPromptSummary(file, section);
|
|
69069
|
+
console.info(` ${++i}) ${label}: ${summary}`);
|
|
69070
|
+
}
|
|
69071
|
+
}
|
|
69072
|
+
|
|
69073
|
+
/**
|
|
69074
|
+
* Prints the summary stats line.
|
|
69075
|
+
*/
|
|
69076
|
+
function printStats(stats, minimumPriority = 0) {
|
|
69077
|
+
const priorityStats = minimumPriority > 0 ? ` | Priority <${minimumPriority}: ${stats.belowMinimumPriority}` : '';
|
|
69078
|
+
console.info(colors__default["default"].cyan(`Done: ${stats.done} | For agent: ${stats.forAgent}${priorityStats} | To be written: ${stats.toBeWritten}`));
|
|
69079
|
+
}
|
|
69080
|
+
|
|
69081
|
+
/**
|
|
69082
|
+
* Summarizes prompt stats for the runner output.
|
|
69083
|
+
*/
|
|
69084
|
+
function summarizePrompts(files, minimumPriority = 0) {
|
|
69085
|
+
const stats = { done: 0, forAgent: 0, belowMinimumPriority: 0, toBeWritten: 0 };
|
|
69086
|
+
for (const file of files) {
|
|
69087
|
+
for (const section of file.sections) {
|
|
69088
|
+
if (section.status === 'done') {
|
|
69089
|
+
stats.done += 1;
|
|
69090
|
+
}
|
|
69091
|
+
else if (section.status === 'todo') {
|
|
69092
|
+
const isAbovePriority = hasSufficientPriority(section, minimumPriority);
|
|
69093
|
+
if (isPromptToBeWritten(file, section)) {
|
|
69094
|
+
if (!isAbovePriority) {
|
|
69095
|
+
continue;
|
|
69096
|
+
}
|
|
69097
|
+
stats.toBeWritten += 1;
|
|
69098
|
+
}
|
|
69099
|
+
else if (isAbovePriority) {
|
|
69100
|
+
stats.forAgent += 1;
|
|
69101
|
+
}
|
|
69102
|
+
else {
|
|
69103
|
+
stats.belowMinimumPriority += 1;
|
|
69104
|
+
}
|
|
69105
|
+
}
|
|
69106
|
+
}
|
|
69107
|
+
}
|
|
69108
|
+
return stats;
|
|
69109
|
+
}
|
|
69110
|
+
|
|
69111
|
+
/**
|
|
69112
|
+
* Constant for prompts dir — mirrors the constant in `runCodexPrompts.ts`.
|
|
69113
|
+
*/
|
|
69114
|
+
const PROMPTS_DIR$2 = path.join(process.cwd(), 'prompts');
|
|
69115
|
+
/**
|
|
69116
|
+
* Lists and prints all prompt sections that still need to be authored (contain `@@@` placeholder).
|
|
69117
|
+
*
|
|
69118
|
+
* Reuses the same filtering logic as `ptbk coder run --dry-run`.
|
|
69119
|
+
*
|
|
69120
|
+
* @returns the number of unwritten prompts found
|
|
69121
|
+
* @public exported from `@promptbook/cli`
|
|
69122
|
+
*/
|
|
69123
|
+
async function findUnwrittenPrompts(options = {}) {
|
|
69124
|
+
const { priority = 0 } = options;
|
|
69125
|
+
const promptFiles = await loadPromptFiles(PROMPTS_DIR$2);
|
|
69126
|
+
const stats = summarizePrompts(promptFiles, priority);
|
|
69127
|
+
printStats(stats, priority);
|
|
69128
|
+
const unwrittenPrompts = listPromptsToBeWritten(promptFiles, priority);
|
|
69129
|
+
if (unwrittenPrompts.length === 0) {
|
|
69130
|
+
console.info(colors__default["default"].green('All prompts are written — nothing to do.'));
|
|
69131
|
+
}
|
|
69132
|
+
else {
|
|
69133
|
+
console.info(colors__default["default"].yellow(`Found ${unwrittenPrompts.length} prompt(s) that need to be written:`));
|
|
69134
|
+
printPromptsToBeWritten(promptFiles, priority);
|
|
69135
|
+
}
|
|
69136
|
+
return unwrittenPrompts.length;
|
|
69137
|
+
}
|
|
69138
|
+
|
|
69139
|
+
var findUnwrittenPrompts$1 = /*#__PURE__*/Object.freeze({
|
|
69140
|
+
__proto__: null,
|
|
69141
|
+
findUnwrittenPrompts: findUnwrittenPrompts
|
|
69142
|
+
});
|
|
69143
|
+
|
|
68631
69144
|
/**
|
|
68632
69145
|
* CLI usage text for this script.
|
|
68633
69146
|
*/
|
|
@@ -68971,6 +69484,29 @@
|
|
|
68971
69484
|
return `${count} prompt${count === 1 ? '' : 's'}`;
|
|
68972
69485
|
}
|
|
68973
69486
|
|
|
69487
|
+
/**
|
|
69488
|
+
* Reads an optional agent `.book` file and compiles its system message for injection into coder prompts.
|
|
69489
|
+
*
|
|
69490
|
+
* Returns `undefined` when no agent path is provided.
|
|
69491
|
+
*/
|
|
69492
|
+
async function resolveAgentSystemMessage(agentPath, currentWorkingDirectory) {
|
|
69493
|
+
if (!agentPath) {
|
|
69494
|
+
return undefined;
|
|
69495
|
+
}
|
|
69496
|
+
const resolvedAgentPath = path.resolve(currentWorkingDirectory, agentPath);
|
|
69497
|
+
const agentSource = await promises.readFile(resolvedAgentPath, 'utf-8').catch((error) => {
|
|
69498
|
+
if (error.code === 'ENOENT' || error.code === 'EISDIR') {
|
|
69499
|
+
throw new NotFoundError(spaceTrim(`
|
|
69500
|
+
Agent book \`${agentPath}\` was not found or is not a file.
|
|
69501
|
+
|
|
69502
|
+
Pass a path to a \`.book\` file in \`--agent\`.
|
|
69503
|
+
`));
|
|
69504
|
+
}
|
|
69505
|
+
throw error;
|
|
69506
|
+
});
|
|
69507
|
+
return createAgentRunnerSystemMessage(agentSource);
|
|
69508
|
+
}
|
|
69509
|
+
|
|
68974
69510
|
/**
|
|
68975
69511
|
* Resolves optional coding context provided inline or via a file path.
|
|
68976
69512
|
*/
|
|
@@ -69013,104 +69549,6 @@
|
|
|
69013
69549
|
}
|
|
69014
69550
|
}
|
|
69015
69551
|
|
|
69016
|
-
/**
|
|
69017
|
-
* Builds a display label using the prompt line number for easier navigation.
|
|
69018
|
-
*/
|
|
69019
|
-
function buildPromptLabelForDisplay(file, section) {
|
|
69020
|
-
return `${path.relative(process.cwd(), file.path).replace(/\\/g, '/')}#${section.startLine + 1}`;
|
|
69021
|
-
}
|
|
69022
|
-
|
|
69023
|
-
/**
|
|
69024
|
-
* Trims leading and trailing empty lines.
|
|
69025
|
-
*/
|
|
69026
|
-
function trimEmptyEdges(lines) {
|
|
69027
|
-
let start = 0;
|
|
69028
|
-
while (start < lines.length) {
|
|
69029
|
-
const startLine = lines[start];
|
|
69030
|
-
if (startLine !== undefined && startLine.trim() !== '') {
|
|
69031
|
-
break;
|
|
69032
|
-
}
|
|
69033
|
-
start += 1;
|
|
69034
|
-
}
|
|
69035
|
-
let end = lines.length - 1;
|
|
69036
|
-
while (end >= start) {
|
|
69037
|
-
const endLine = lines[end];
|
|
69038
|
-
if (endLine !== undefined && endLine.trim() !== '') {
|
|
69039
|
-
break;
|
|
69040
|
-
}
|
|
69041
|
-
end -= 1;
|
|
69042
|
-
}
|
|
69043
|
-
return lines.slice(start, end + 1);
|
|
69044
|
-
}
|
|
69045
|
-
|
|
69046
|
-
/**
|
|
69047
|
-
* Extracts prompt lines without the status marker.
|
|
69048
|
-
*/
|
|
69049
|
-
function buildPromptLinesWithoutStatus(file, section) {
|
|
69050
|
-
const lines = file.lines.slice(section.startLine, section.endLine + 1);
|
|
69051
|
-
if (section.statusLineIndex !== undefined) {
|
|
69052
|
-
const relativeIndex = section.statusLineIndex - section.startLine;
|
|
69053
|
-
if (relativeIndex >= 0 && relativeIndex < lines.length) {
|
|
69054
|
-
lines.splice(relativeIndex, 1);
|
|
69055
|
-
}
|
|
69056
|
-
}
|
|
69057
|
-
return trimEmptyEdges(lines);
|
|
69058
|
-
}
|
|
69059
|
-
|
|
69060
|
-
/**
|
|
69061
|
-
* Builds the prompt text sent to the agent runner.
|
|
69062
|
-
*/
|
|
69063
|
-
function buildCodexPrompt(file, section) {
|
|
69064
|
-
const lines = buildPromptLinesWithoutStatus(file, section);
|
|
69065
|
-
for (let i = 0; i < lines.length; i++) {
|
|
69066
|
-
const line = lines[i];
|
|
69067
|
-
if (line === undefined || line.trim() === '') {
|
|
69068
|
-
continue;
|
|
69069
|
-
}
|
|
69070
|
-
lines[i] = line.replace(/^\[[^\]]+\]\s*/, '');
|
|
69071
|
-
break;
|
|
69072
|
-
}
|
|
69073
|
-
return lines.join(file.eol);
|
|
69074
|
-
}
|
|
69075
|
-
|
|
69076
|
-
/**
|
|
69077
|
-
* Extracts a short summary line from a prompt section.
|
|
69078
|
-
*/
|
|
69079
|
-
function buildPromptSummary(file, section) {
|
|
69080
|
-
const lines = buildCodexPrompt(file, section).split(/\r?\n/);
|
|
69081
|
-
const firstLine = lines.find((line) => line.trim() !== '');
|
|
69082
|
-
return (firstLine === null || firstLine === void 0 ? void 0 : firstLine.trim()) || '(empty prompt)';
|
|
69083
|
-
}
|
|
69084
|
-
|
|
69085
|
-
/**
|
|
69086
|
-
* Checks whether a prompt section meets the minimum priority threshold.
|
|
69087
|
-
*/
|
|
69088
|
-
function hasSufficientPriority(section, minimumPriority) {
|
|
69089
|
-
return section.priority >= minimumPriority;
|
|
69090
|
-
}
|
|
69091
|
-
|
|
69092
|
-
/**
|
|
69093
|
-
* Checks whether a prompt section still needs authoring (contains "@@@").
|
|
69094
|
-
*/
|
|
69095
|
-
function isPromptToBeWritten(file, section) {
|
|
69096
|
-
return buildCodexPrompt(file, section).includes('@@@');
|
|
69097
|
-
}
|
|
69098
|
-
|
|
69099
|
-
/**
|
|
69100
|
-
* Lists todo prompts across all files.
|
|
69101
|
-
*/
|
|
69102
|
-
function listTodoPrompts(files) {
|
|
69103
|
-
const prompts = [];
|
|
69104
|
-
for (const file of files) {
|
|
69105
|
-
for (const section of file.sections) {
|
|
69106
|
-
if (section.status === 'todo') {
|
|
69107
|
-
prompts.push({ file, section });
|
|
69108
|
-
}
|
|
69109
|
-
}
|
|
69110
|
-
}
|
|
69111
|
-
return prompts;
|
|
69112
|
-
}
|
|
69113
|
-
|
|
69114
69552
|
/**
|
|
69115
69553
|
* Lists todo prompts that are ready to run (no authoring placeholders).
|
|
69116
69554
|
*/
|
|
@@ -69143,142 +69581,6 @@
|
|
|
69143
69581
|
}));
|
|
69144
69582
|
}
|
|
69145
69583
|
|
|
69146
|
-
/**
|
|
69147
|
-
* Parses a prompt markdown file into sections and metadata.
|
|
69148
|
-
*/
|
|
69149
|
-
function parsePromptFile(filePath, content) {
|
|
69150
|
-
var _a, _b;
|
|
69151
|
-
const eol = content.includes('\r\n') ? '\r\n' : '\n';
|
|
69152
|
-
const hasFinalEol = content.endsWith('\n');
|
|
69153
|
-
const lines = content.split(/\r?\n/);
|
|
69154
|
-
const sections = [];
|
|
69155
|
-
let startLine = 0;
|
|
69156
|
-
let index = 0;
|
|
69157
|
-
for (let i = 0; i <= lines.length; i++) {
|
|
69158
|
-
const line = lines[i];
|
|
69159
|
-
const isSeparator = i < lines.length && line !== undefined && line.trim() === '---';
|
|
69160
|
-
const isEnd = i === lines.length;
|
|
69161
|
-
if (!isSeparator && !isEnd) {
|
|
69162
|
-
continue;
|
|
69163
|
-
}
|
|
69164
|
-
const endLine = i - 1;
|
|
69165
|
-
const firstNonEmptyLine = findFirstNonEmptyLine(lines, startLine, endLine);
|
|
69166
|
-
if (firstNonEmptyLine !== undefined) {
|
|
69167
|
-
const statusLine = (lines[firstNonEmptyLine] || '').trim();
|
|
69168
|
-
const parsedStatus = parseStatusLine(statusLine);
|
|
69169
|
-
const status = (_a = parsedStatus === null || parsedStatus === void 0 ? void 0 : parsedStatus.status) !== null && _a !== void 0 ? _a : 'not-ready';
|
|
69170
|
-
const priority = (_b = parsedStatus === null || parsedStatus === void 0 ? void 0 : parsedStatus.priority) !== null && _b !== void 0 ? _b : 0;
|
|
69171
|
-
sections.push({
|
|
69172
|
-
index,
|
|
69173
|
-
startLine,
|
|
69174
|
-
endLine,
|
|
69175
|
-
status,
|
|
69176
|
-
priority,
|
|
69177
|
-
statusLineIndex: parsedStatus ? firstNonEmptyLine : undefined,
|
|
69178
|
-
});
|
|
69179
|
-
index += 1;
|
|
69180
|
-
}
|
|
69181
|
-
startLine = i + 1;
|
|
69182
|
-
}
|
|
69183
|
-
return {
|
|
69184
|
-
path: filePath,
|
|
69185
|
-
name: path.basename(filePath),
|
|
69186
|
-
lines,
|
|
69187
|
-
eol,
|
|
69188
|
-
hasFinalEol,
|
|
69189
|
-
sections,
|
|
69190
|
-
};
|
|
69191
|
-
}
|
|
69192
|
-
/**
|
|
69193
|
-
* Parses a status line like "[ ] !!" or "[-]" or "[x] ~$0.65 21 minutes..." into status and priority.
|
|
69194
|
-
* For [x] done and [!] failed prompts, allow metadata after the status marker.
|
|
69195
|
-
*/
|
|
69196
|
-
function parseStatusLine(line) {
|
|
69197
|
-
var _a, _b, _c, _d, _e;
|
|
69198
|
-
// For done prompts [x], allow any content after (for cost/time metadata)
|
|
69199
|
-
const doneMatch = line.match(/^\[(?<status>[xX])\]/);
|
|
69200
|
-
if (doneMatch) {
|
|
69201
|
-
return { status: 'done', priority: 0 };
|
|
69202
|
-
}
|
|
69203
|
-
// For failed prompts [!], allow any content after (for failure metadata)
|
|
69204
|
-
const failedMatch = line.match(/^\[(?<status>!)\]/);
|
|
69205
|
-
if (failedMatch) {
|
|
69206
|
-
return { status: 'failed', priority: 0 };
|
|
69207
|
-
}
|
|
69208
|
-
// For todo [ ] and not-ready [-], require clean end with optional priority markers
|
|
69209
|
-
const match = line.match(/^\[(?<status>[ -])\]\s*(?<priority>!*)\s*$/);
|
|
69210
|
-
if (!match) {
|
|
69211
|
-
return undefined;
|
|
69212
|
-
}
|
|
69213
|
-
const statusChar = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a.status) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
69214
|
-
let status;
|
|
69215
|
-
if (statusChar === '-') {
|
|
69216
|
-
status = 'not-ready';
|
|
69217
|
-
}
|
|
69218
|
-
else {
|
|
69219
|
-
status = 'todo';
|
|
69220
|
-
}
|
|
69221
|
-
const priority = status === 'todo' ? (_e = (_d = (_c = match.groups) === null || _c === void 0 ? void 0 : _c.priority) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0 : 0;
|
|
69222
|
-
return { status, priority };
|
|
69223
|
-
}
|
|
69224
|
-
/**
|
|
69225
|
-
* Finds the first non-empty line index between two bounds.
|
|
69226
|
-
*/
|
|
69227
|
-
function findFirstNonEmptyLine(lines, startLine, endLine) {
|
|
69228
|
-
for (let i = startLine; i <= endLine; i++) {
|
|
69229
|
-
const line = lines[i];
|
|
69230
|
-
if (line !== undefined && line.trim() !== '') {
|
|
69231
|
-
return i;
|
|
69232
|
-
}
|
|
69233
|
-
}
|
|
69234
|
-
return undefined;
|
|
69235
|
-
}
|
|
69236
|
-
|
|
69237
|
-
/**
|
|
69238
|
-
* Loads and parses prompt files from the prompts directory.
|
|
69239
|
-
*/
|
|
69240
|
-
async function loadPromptFiles(promptsDir) {
|
|
69241
|
-
const entries = await promises.readdir(promptsDir, { withFileTypes: true });
|
|
69242
|
-
const files = entries
|
|
69243
|
-
.filter((entry) => entry.isFile() && entry.name.toLowerCase().endsWith('.md'))
|
|
69244
|
-
.map((entry) => path.join(promptsDir, entry.name))
|
|
69245
|
-
.sort((a, b) => a.localeCompare(b));
|
|
69246
|
-
const promptFiles = [];
|
|
69247
|
-
for (const filePath of files) {
|
|
69248
|
-
const content = await promises.readFile(filePath, 'utf-8');
|
|
69249
|
-
promptFiles.push(parsePromptFile(filePath, content));
|
|
69250
|
-
}
|
|
69251
|
-
return promptFiles;
|
|
69252
|
-
}
|
|
69253
|
-
|
|
69254
|
-
/**
|
|
69255
|
-
* Lists todo prompts that still contain authoring placeholders.
|
|
69256
|
-
*/
|
|
69257
|
-
function listPromptsToBeWritten(files, minimumPriority = 0) {
|
|
69258
|
-
return listTodoPrompts(files).filter((prompt) => isPromptToBeWritten(prompt.file, prompt.section) && hasSufficientPriority(prompt.section, minimumPriority));
|
|
69259
|
-
}
|
|
69260
|
-
|
|
69261
|
-
/**
|
|
69262
|
-
* Prints the list of prompts that still need to be written.
|
|
69263
|
-
*/
|
|
69264
|
-
function printPromptsToBeWritten(files, minimumPriority = 0) {
|
|
69265
|
-
const promptsToWrite = listPromptsToBeWritten(files, minimumPriority);
|
|
69266
|
-
let i = 0;
|
|
69267
|
-
for (const { file, section } of promptsToWrite) {
|
|
69268
|
-
const label = buildPromptLabelForDisplay(file, section);
|
|
69269
|
-
const summary = buildPromptSummary(file, section);
|
|
69270
|
-
console.info(` ${++i}) ${label}: ${summary}`);
|
|
69271
|
-
}
|
|
69272
|
-
}
|
|
69273
|
-
|
|
69274
|
-
/**
|
|
69275
|
-
* Prints the summary stats line.
|
|
69276
|
-
*/
|
|
69277
|
-
function printStats(stats, minimumPriority = 0) {
|
|
69278
|
-
const priorityStats = minimumPriority > 0 ? ` | Priority <${minimumPriority}: ${stats.belowMinimumPriority}` : '';
|
|
69279
|
-
console.info(colors__default["default"].cyan(`Done: ${stats.done} | For agent: ${stats.forAgent}${priorityStats} | To be written: ${stats.toBeWritten}`));
|
|
69280
|
-
}
|
|
69281
|
-
|
|
69282
69584
|
/**
|
|
69283
69585
|
* Groups upcoming tasks by priority, high to low.
|
|
69284
69586
|
*/
|
|
@@ -69316,36 +69618,6 @@
|
|
|
69316
69618
|
}
|
|
69317
69619
|
}
|
|
69318
69620
|
|
|
69319
|
-
/**
|
|
69320
|
-
* Summarizes prompt stats for the runner output.
|
|
69321
|
-
*/
|
|
69322
|
-
function summarizePrompts(files, minimumPriority = 0) {
|
|
69323
|
-
const stats = { done: 0, forAgent: 0, belowMinimumPriority: 0, toBeWritten: 0 };
|
|
69324
|
-
for (const file of files) {
|
|
69325
|
-
for (const section of file.sections) {
|
|
69326
|
-
if (section.status === 'done') {
|
|
69327
|
-
stats.done += 1;
|
|
69328
|
-
}
|
|
69329
|
-
else if (section.status === 'todo') {
|
|
69330
|
-
const isAbovePriority = hasSufficientPriority(section, minimumPriority);
|
|
69331
|
-
if (isPromptToBeWritten(file, section)) {
|
|
69332
|
-
if (!isAbovePriority) {
|
|
69333
|
-
continue;
|
|
69334
|
-
}
|
|
69335
|
-
stats.toBeWritten += 1;
|
|
69336
|
-
}
|
|
69337
|
-
else if (isAbovePriority) {
|
|
69338
|
-
stats.forAgent += 1;
|
|
69339
|
-
}
|
|
69340
|
-
else {
|
|
69341
|
-
stats.belowMinimumPriority += 1;
|
|
69342
|
-
}
|
|
69343
|
-
}
|
|
69344
|
-
}
|
|
69345
|
-
}
|
|
69346
|
-
return stats;
|
|
69347
|
-
}
|
|
69348
|
-
|
|
69349
69621
|
/**
|
|
69350
69622
|
* Waits for the user to press Enter before continuing.
|
|
69351
69623
|
*/
|
|
@@ -70970,9 +71242,14 @@
|
|
|
70970
71242
|
*
|
|
70971
71243
|
* @private function of runCodexPrompts
|
|
70972
71244
|
*/
|
|
70973
|
-
async function runPromptRound({ options, runner, runnerMetadata, nextPrompt, promptLabel, resolvedCoderContext, isRichUiEnabled, progressDisplay, uiHandle, waitForRequestedPause, }) {
|
|
71245
|
+
async function runPromptRound({ options, runner, runnerMetadata, nextPrompt, promptLabel, resolvedCoderContext, resolvedAgentSystemMessage, isRichUiEnabled, progressDisplay, uiHandle, waitForRequestedPause, }) {
|
|
70974
71246
|
const commitMessage = buildCommitMessage(nextPrompt.file, nextPrompt.section);
|
|
70975
|
-
const
|
|
71247
|
+
const taskPrompt = buildCodexPrompt(nextPrompt.file, nextPrompt.section);
|
|
71248
|
+
// Prepend agent system message before the task so the harness sees agent instructions first
|
|
71249
|
+
const promptWithAgent = resolvedAgentSystemMessage
|
|
71250
|
+
? `${resolvedAgentSystemMessage.trim()}\n\n${taskPrompt}`
|
|
71251
|
+
: taskPrompt;
|
|
71252
|
+
const codexPrompt = appendCoderContext(promptWithAgent, resolvedCoderContext);
|
|
70976
71253
|
const scriptPath = buildScriptPath(nextPrompt.file, nextPrompt.section);
|
|
70977
71254
|
setPromptRoundRunningState({ isRichUiEnabled, promptLabel, scriptPath, uiHandle });
|
|
70978
71255
|
await waitForRequestedPause({
|
|
@@ -71205,6 +71482,7 @@
|
|
|
71205
71482
|
startPauseListenerIfNeeded(isRichUiEnabled);
|
|
71206
71483
|
try {
|
|
71207
71484
|
const resolvedCoderContext = await resolveCoderContext(options.context, process.cwd());
|
|
71485
|
+
const resolvedAgentSystemMessage = await resolveAgentSystemMessage(options.agent, process.cwd());
|
|
71208
71486
|
if (await runDryRunIfRequested(options)) {
|
|
71209
71487
|
return;
|
|
71210
71488
|
}
|
|
@@ -71244,7 +71522,13 @@
|
|
|
71244
71522
|
minimumPriority: options.priority,
|
|
71245
71523
|
isRichUiEnabled,
|
|
71246
71524
|
}));
|
|
71247
|
-
if (
|
|
71525
|
+
if (!promptQueueSnapshot.nextPrompt) {
|
|
71526
|
+
if (options.keepAlive) {
|
|
71527
|
+
announceKeepAliveStatus(promptQueueSnapshot, isRichUiEnabled, uiHandle);
|
|
71528
|
+
await new Promise((resolve) => setTimeout(resolve, KEEP_ALIVE_POLL_INTERVAL_MS));
|
|
71529
|
+
continue;
|
|
71530
|
+
}
|
|
71531
|
+
finishWhenNoPromptIsAvailable(promptQueueSnapshot, isRichUiEnabled, uiHandle);
|
|
71248
71532
|
return;
|
|
71249
71533
|
}
|
|
71250
71534
|
const nextPrompt = promptQueueSnapshot.nextPrompt;
|
|
@@ -71283,6 +71567,7 @@
|
|
|
71283
71567
|
nextPrompt,
|
|
71284
71568
|
promptLabel,
|
|
71285
71569
|
resolvedCoderContext,
|
|
71570
|
+
resolvedAgentSystemMessage,
|
|
71286
71571
|
isRichUiEnabled,
|
|
71287
71572
|
progressDisplay,
|
|
71288
71573
|
uiHandle,
|
|
@@ -71458,6 +71743,19 @@
|
|
|
71458
71743
|
}
|
|
71459
71744
|
return true;
|
|
71460
71745
|
}
|
|
71746
|
+
/**
|
|
71747
|
+
* Updates the UI status message while waiting for new prompts in keepAlive server mode.
|
|
71748
|
+
*/
|
|
71749
|
+
function announceKeepAliveStatus(promptQueueSnapshot, isRichUiEnabled, uiHandle) {
|
|
71750
|
+
const message = promptQueueSnapshot.stats.toBeWritten > 0
|
|
71751
|
+
? 'No prompts ready for agent. Watching for changes...'
|
|
71752
|
+
: 'All prompts are done. Watching for changes...';
|
|
71753
|
+
uiHandle === null || uiHandle === void 0 ? void 0 : uiHandle.state.setStatusMessage(message);
|
|
71754
|
+
uiHandle === null || uiHandle === void 0 ? void 0 : uiHandle.state.setPhase('waiting');
|
|
71755
|
+
if (!isRichUiEnabled) {
|
|
71756
|
+
console.info(colors__default["default"].gray(message));
|
|
71757
|
+
}
|
|
71758
|
+
}
|
|
71461
71759
|
/**
|
|
71462
71760
|
* Updates UI state and plain-console output for the terminal completion message.
|
|
71463
71761
|
*/
|
|
@@ -71498,6 +71796,10 @@
|
|
|
71498
71796
|
* Countdown update interval for the between-rounds wait display.
|
|
71499
71797
|
*/
|
|
71500
71798
|
const WAIT_COUNTDOWN_UPDATE_INTERVAL_MS = 30000;
|
|
71799
|
+
/**
|
|
71800
|
+
* Polling interval when in keepAlive server mode and no runnable prompts are available.
|
|
71801
|
+
*/
|
|
71802
|
+
const KEEP_ALIVE_POLL_INTERVAL_MS = 5000;
|
|
71501
71803
|
/**
|
|
71502
71804
|
* Waits the configured time between prompt rounds to avoid hitting harness rate limits.
|
|
71503
71805
|
* Does nothing when `waitBetweenPrompts` is zero.
|
|
@@ -71543,6 +71845,780 @@
|
|
|
71543
71845
|
runCodexPrompts: runCodexPrompts
|
|
71544
71846
|
});
|
|
71545
71847
|
|
|
71848
|
+
/**
|
|
71849
|
+
* Overwrites the body of one prompt section with new content, preserving the status line.
|
|
71850
|
+
*
|
|
71851
|
+
* The `newContent` string is the prompt text without the status marker.
|
|
71852
|
+
* The status line (`[ ]`, `[x]`, `[!]`, `[-]`) is kept intact.
|
|
71853
|
+
*
|
|
71854
|
+
* @private internal utility of `ptbk coder server`
|
|
71855
|
+
*/
|
|
71856
|
+
async function updatePromptSection(filePath, sectionIndex, newContent) {
|
|
71857
|
+
var _a;
|
|
71858
|
+
const rawContent = await promises.readFile(filePath, 'utf-8');
|
|
71859
|
+
const promptFile = parsePromptFile(filePath, rawContent);
|
|
71860
|
+
const section = promptFile.sections.find((s) => s.index === sectionIndex);
|
|
71861
|
+
if (!section) {
|
|
71862
|
+
throw new Error(`Section ${sectionIndex} not found in file: ${filePath}`);
|
|
71863
|
+
}
|
|
71864
|
+
// Lines before the status line (usually empty lines at section start)
|
|
71865
|
+
const linesBeforeStatus = section.statusLineIndex !== undefined
|
|
71866
|
+
? promptFile.lines.slice(section.startLine, section.statusLineIndex)
|
|
71867
|
+
: [];
|
|
71868
|
+
// The status line itself (preserved exactly)
|
|
71869
|
+
const statusLineContent = section.statusLineIndex !== undefined ? [promptFile.lines[section.statusLineIndex]] : [];
|
|
71870
|
+
// Split the new content and trim trailing blank lines
|
|
71871
|
+
const newContentLines = newContent.split(/\r?\n/);
|
|
71872
|
+
while (newContentLines.length > 0 && ((_a = newContentLines[newContentLines.length - 1]) === null || _a === void 0 ? void 0 : _a.trim()) === '') {
|
|
71873
|
+
newContentLines.pop();
|
|
71874
|
+
}
|
|
71875
|
+
// Build the reconstructed section lines
|
|
71876
|
+
const newSectionLines = [
|
|
71877
|
+
...linesBeforeStatus,
|
|
71878
|
+
...statusLineContent,
|
|
71879
|
+
...(statusLineContent.length > 0 ? [''] : []),
|
|
71880
|
+
...newContentLines,
|
|
71881
|
+
];
|
|
71882
|
+
// Splice the new section lines into the full file line array
|
|
71883
|
+
const updatedLines = [
|
|
71884
|
+
...promptFile.lines.slice(0, section.startLine),
|
|
71885
|
+
...newSectionLines,
|
|
71886
|
+
...promptFile.lines.slice(section.endLine + 1),
|
|
71887
|
+
];
|
|
71888
|
+
const updatedContent = updatedLines.join(promptFile.eol) + (promptFile.hasFinalEol ? promptFile.eol : '');
|
|
71889
|
+
await promises.writeFile(filePath, updatedContent, 'utf-8');
|
|
71890
|
+
}
|
|
71891
|
+
// Note: [🟡] Code for CLI command [coder server](scripts/run-codex-prompts/server/updatePromptSection.ts) should never be published outside of `@promptbook/cli`
|
|
71892
|
+
|
|
71893
|
+
/**
|
|
71894
|
+
* HTML source for the coder server kanban UI.
|
|
71895
|
+
*
|
|
71896
|
+
* The canonical source lives in `apps/coder-server/index.html`.
|
|
71897
|
+
* Keep both files in sync when updating the frontend.
|
|
71898
|
+
*
|
|
71899
|
+
* @private internal constant of `ptbk coder server`
|
|
71900
|
+
*/
|
|
71901
|
+
const CODER_SERVER_HTML = `<!DOCTYPE html>
|
|
71902
|
+
<html lang="en">
|
|
71903
|
+
<head>
|
|
71904
|
+
<meta charset="UTF-8">
|
|
71905
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
71906
|
+
<title>Ptbk Coder Server</title>
|
|
71907
|
+
<style>
|
|
71908
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
71909
|
+
body {
|
|
71910
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
71911
|
+
background: #f4f5f7;
|
|
71912
|
+
color: #172b4d;
|
|
71913
|
+
min-height: 100vh;
|
|
71914
|
+
}
|
|
71915
|
+
|
|
71916
|
+
header {
|
|
71917
|
+
background: #0052cc;
|
|
71918
|
+
color: white;
|
|
71919
|
+
padding: 12px 20px;
|
|
71920
|
+
display: flex;
|
|
71921
|
+
align-items: center;
|
|
71922
|
+
gap: 12px;
|
|
71923
|
+
position: sticky;
|
|
71924
|
+
top: 0;
|
|
71925
|
+
z-index: 10;
|
|
71926
|
+
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
|
|
71927
|
+
}
|
|
71928
|
+
header h1 { font-size: 17px; font-weight: 700; flex-shrink: 0; }
|
|
71929
|
+
|
|
71930
|
+
.status-badge {
|
|
71931
|
+
padding: 3px 10px;
|
|
71932
|
+
border-radius: 12px;
|
|
71933
|
+
font-size: 11px;
|
|
71934
|
+
font-weight: 700;
|
|
71935
|
+
letter-spacing: 0.5px;
|
|
71936
|
+
text-transform: uppercase;
|
|
71937
|
+
flex-shrink: 0;
|
|
71938
|
+
}
|
|
71939
|
+
.status-RUNNING { background: #00875a; color: white; }
|
|
71940
|
+
.status-PAUSING { background: #ff8b00; color: white; }
|
|
71941
|
+
.status-PAUSED { background: #bf2600; color: white; }
|
|
71942
|
+
|
|
71943
|
+
#pause-label {
|
|
71944
|
+
font-size: 12px;
|
|
71945
|
+
color: rgba(255,255,255,0.75);
|
|
71946
|
+
flex: 1;
|
|
71947
|
+
min-width: 0;
|
|
71948
|
+
overflow: hidden;
|
|
71949
|
+
text-overflow: ellipsis;
|
|
71950
|
+
white-space: nowrap;
|
|
71951
|
+
}
|
|
71952
|
+
|
|
71953
|
+
.btn {
|
|
71954
|
+
padding: 6px 14px;
|
|
71955
|
+
border: none;
|
|
71956
|
+
border-radius: 4px;
|
|
71957
|
+
cursor: pointer;
|
|
71958
|
+
font-size: 13px;
|
|
71959
|
+
font-weight: 600;
|
|
71960
|
+
transition: opacity 0.15s;
|
|
71961
|
+
flex-shrink: 0;
|
|
71962
|
+
}
|
|
71963
|
+
.btn:hover { opacity: 0.85; }
|
|
71964
|
+
.btn-pause { background: #ffc400; color: #172b4d; }
|
|
71965
|
+
.btn-resume { background: #00875a; color: white; }
|
|
71966
|
+
|
|
71967
|
+
.board {
|
|
71968
|
+
display: flex;
|
|
71969
|
+
gap: 14px;
|
|
71970
|
+
padding: 16px;
|
|
71971
|
+
overflow-x: auto;
|
|
71972
|
+
min-height: calc(100vh - 52px);
|
|
71973
|
+
align-items: flex-start;
|
|
71974
|
+
}
|
|
71975
|
+
|
|
71976
|
+
.column {
|
|
71977
|
+
background: #ebecf0;
|
|
71978
|
+
border-radius: 8px;
|
|
71979
|
+
padding: 10px;
|
|
71980
|
+
min-width: 250px;
|
|
71981
|
+
width: 270px;
|
|
71982
|
+
flex-shrink: 0;
|
|
71983
|
+
}
|
|
71984
|
+
|
|
71985
|
+
.column-header {
|
|
71986
|
+
font-size: 12px;
|
|
71987
|
+
font-weight: 700;
|
|
71988
|
+
text-transform: uppercase;
|
|
71989
|
+
letter-spacing: 0.6px;
|
|
71990
|
+
color: #5e6c84;
|
|
71991
|
+
margin-bottom: 10px;
|
|
71992
|
+
display: flex;
|
|
71993
|
+
align-items: center;
|
|
71994
|
+
justify-content: space-between;
|
|
71995
|
+
}
|
|
71996
|
+
|
|
71997
|
+
.column-count {
|
|
71998
|
+
background: #dfe1e6;
|
|
71999
|
+
border-radius: 10px;
|
|
72000
|
+
padding: 1px 7px;
|
|
72001
|
+
font-size: 11px;
|
|
72002
|
+
color: #5e6c84;
|
|
72003
|
+
}
|
|
72004
|
+
|
|
72005
|
+
.column-cards { min-height: 40px; }
|
|
72006
|
+
|
|
72007
|
+
.card {
|
|
72008
|
+
background: white;
|
|
72009
|
+
border-radius: 6px;
|
|
72010
|
+
padding: 10px 12px;
|
|
72011
|
+
margin-bottom: 8px;
|
|
72012
|
+
box-shadow: 0 1px 3px rgba(0,0,0,0.08);
|
|
72013
|
+
cursor: pointer;
|
|
72014
|
+
transition: box-shadow 0.15s, transform 0.1s;
|
|
72015
|
+
border-left: 3px solid transparent;
|
|
72016
|
+
}
|
|
72017
|
+
.card:hover {
|
|
72018
|
+
box-shadow: 0 4px 10px rgba(0,0,0,0.14);
|
|
72019
|
+
transform: translateY(-1px);
|
|
72020
|
+
}
|
|
72021
|
+
.card-todo { border-left-color: #0052cc; }
|
|
72022
|
+
.card-not-ready { border-left-color: #8993a4; }
|
|
72023
|
+
.card-done { border-left-color: #00875a; }
|
|
72024
|
+
.card-failed { border-left-color: #bf2600; }
|
|
72025
|
+
|
|
72026
|
+
.card-file {
|
|
72027
|
+
font-size: 10px;
|
|
72028
|
+
color: #8993a4;
|
|
72029
|
+
margin-bottom: 5px;
|
|
72030
|
+
font-weight: 500;
|
|
72031
|
+
}
|
|
72032
|
+
|
|
72033
|
+
.card-summary {
|
|
72034
|
+
font-size: 13px;
|
|
72035
|
+
line-height: 1.5;
|
|
72036
|
+
color: #172b4d;
|
|
72037
|
+
word-break: break-word;
|
|
72038
|
+
white-space: pre-wrap;
|
|
72039
|
+
max-height: 78px;
|
|
72040
|
+
overflow: hidden;
|
|
72041
|
+
display: -webkit-box;
|
|
72042
|
+
-webkit-line-clamp: 4;
|
|
72043
|
+
-webkit-box-orient: vertical;
|
|
72044
|
+
}
|
|
72045
|
+
|
|
72046
|
+
.card-priority {
|
|
72047
|
+
margin-top: 6px;
|
|
72048
|
+
color: #ff8b00;
|
|
72049
|
+
font-size: 11px;
|
|
72050
|
+
font-weight: 700;
|
|
72051
|
+
}
|
|
72052
|
+
|
|
72053
|
+
.card-edit-hint {
|
|
72054
|
+
font-size: 10px;
|
|
72055
|
+
color: #c1c7d0;
|
|
72056
|
+
margin-top: 6px;
|
|
72057
|
+
display: none;
|
|
72058
|
+
}
|
|
72059
|
+
.card:hover .card-edit-hint { display: block; }
|
|
72060
|
+
|
|
72061
|
+
.empty-column {
|
|
72062
|
+
color: #b3bac5;
|
|
72063
|
+
font-size: 12px;
|
|
72064
|
+
padding: 10px 4px;
|
|
72065
|
+
text-align: center;
|
|
72066
|
+
}
|
|
72067
|
+
|
|
72068
|
+
.modal-overlay {
|
|
72069
|
+
position: fixed;
|
|
72070
|
+
inset: 0;
|
|
72071
|
+
background: rgba(9,30,66,0.54);
|
|
72072
|
+
display: flex;
|
|
72073
|
+
align-items: flex-start;
|
|
72074
|
+
justify-content: center;
|
|
72075
|
+
padding: 60px 16px 16px;
|
|
72076
|
+
z-index: 100;
|
|
72077
|
+
animation: fadeIn 0.1s ease;
|
|
72078
|
+
}
|
|
72079
|
+
.modal-overlay.hidden { display: none; }
|
|
72080
|
+
|
|
72081
|
+
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
|
72082
|
+
|
|
72083
|
+
.modal {
|
|
72084
|
+
background: white;
|
|
72085
|
+
border-radius: 8px;
|
|
72086
|
+
width: 100%;
|
|
72087
|
+
max-width: 620px;
|
|
72088
|
+
padding: 20px;
|
|
72089
|
+
box-shadow: 0 8px 32px rgba(0,0,0,0.25);
|
|
72090
|
+
animation: slideIn 0.15s ease;
|
|
72091
|
+
}
|
|
72092
|
+
@keyframes slideIn { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
|
|
72093
|
+
|
|
72094
|
+
.modal-header {
|
|
72095
|
+
display: flex;
|
|
72096
|
+
align-items: flex-start;
|
|
72097
|
+
justify-content: space-between;
|
|
72098
|
+
margin-bottom: 14px;
|
|
72099
|
+
gap: 12px;
|
|
72100
|
+
}
|
|
72101
|
+
|
|
72102
|
+
.modal-meta { flex: 1; min-width: 0; }
|
|
72103
|
+
.modal-file { font-size: 11px; color: #8993a4; margin-bottom: 4px; }
|
|
72104
|
+
.modal-section-label { font-size: 13px; font-weight: 600; color: #172b4d; }
|
|
72105
|
+
|
|
72106
|
+
.modal-status {
|
|
72107
|
+
font-size: 11px;
|
|
72108
|
+
font-weight: 700;
|
|
72109
|
+
padding: 2px 8px;
|
|
72110
|
+
border-radius: 10px;
|
|
72111
|
+
text-transform: uppercase;
|
|
72112
|
+
letter-spacing: 0.4px;
|
|
72113
|
+
flex-shrink: 0;
|
|
72114
|
+
}
|
|
72115
|
+
.status-todo { background: #deebff; color: #0052cc; }
|
|
72116
|
+
.status-not-ready { background: #f4f5f7; color: #5e6c84; }
|
|
72117
|
+
.status-done { background: #e3fcef; color: #006644; }
|
|
72118
|
+
.status-failed { background: #ffebe6; color: #bf2600; }
|
|
72119
|
+
|
|
72120
|
+
.modal-close {
|
|
72121
|
+
background: none;
|
|
72122
|
+
border: none;
|
|
72123
|
+
color: #8993a4;
|
|
72124
|
+
cursor: pointer;
|
|
72125
|
+
font-size: 18px;
|
|
72126
|
+
padding: 0 4px;
|
|
72127
|
+
line-height: 1;
|
|
72128
|
+
flex-shrink: 0;
|
|
72129
|
+
}
|
|
72130
|
+
.modal-close:hover { color: #172b4d; }
|
|
72131
|
+
|
|
72132
|
+
textarea {
|
|
72133
|
+
width: 100%;
|
|
72134
|
+
min-height: 220px;
|
|
72135
|
+
font-family: 'SFMono-Regular', 'Consolas', 'Courier New', monospace;
|
|
72136
|
+
font-size: 13px;
|
|
72137
|
+
border: 2px solid #dfe1e6;
|
|
72138
|
+
border-radius: 4px;
|
|
72139
|
+
padding: 10px 12px;
|
|
72140
|
+
resize: vertical;
|
|
72141
|
+
line-height: 1.65;
|
|
72142
|
+
color: #172b4d;
|
|
72143
|
+
transition: border-color 0.15s;
|
|
72144
|
+
}
|
|
72145
|
+
textarea:focus {
|
|
72146
|
+
outline: none;
|
|
72147
|
+
border-color: #0052cc;
|
|
72148
|
+
box-shadow: 0 0 0 3px rgba(0,82,204,0.12);
|
|
72149
|
+
}
|
|
72150
|
+
|
|
72151
|
+
.modal-hint {
|
|
72152
|
+
font-size: 11px;
|
|
72153
|
+
color: #8993a4;
|
|
72154
|
+
margin-top: 6px;
|
|
72155
|
+
}
|
|
72156
|
+
|
|
72157
|
+
.modal-actions {
|
|
72158
|
+
display: flex;
|
|
72159
|
+
gap: 8px;
|
|
72160
|
+
margin-top: 14px;
|
|
72161
|
+
justify-content: flex-end;
|
|
72162
|
+
}
|
|
72163
|
+
|
|
72164
|
+
.btn-save { background: #0052cc; color: white; }
|
|
72165
|
+
.btn-cancel { background: #f4f5f7; color: #172b4d; }
|
|
72166
|
+
.btn-cancel:hover { background: #ebecf0; opacity: 1; }
|
|
72167
|
+
|
|
72168
|
+
.error-banner {
|
|
72169
|
+
background: #ffebe6;
|
|
72170
|
+
border-bottom: 2px solid #bf2600;
|
|
72171
|
+
color: #bf2600;
|
|
72172
|
+
padding: 8px 20px;
|
|
72173
|
+
font-size: 13px;
|
|
72174
|
+
font-weight: 500;
|
|
72175
|
+
}
|
|
72176
|
+
.error-banner.hidden { display: none; }
|
|
72177
|
+
</style>
|
|
72178
|
+
</head>
|
|
72179
|
+
<body>
|
|
72180
|
+
|
|
72181
|
+
<div id="error-banner" class="error-banner hidden"></div>
|
|
72182
|
+
|
|
72183
|
+
<header>
|
|
72184
|
+
<h1>🔧 Ptbk Coder Server</h1>
|
|
72185
|
+
<span id="status-badge" class="status-badge status-RUNNING">RUNNING</span>
|
|
72186
|
+
<span id="pause-label"></span>
|
|
72187
|
+
<button id="toggle-btn" class="btn btn-pause">▮▮ Pause</button>
|
|
72188
|
+
</header>
|
|
72189
|
+
|
|
72190
|
+
<div class="board">
|
|
72191
|
+
<div class="column">
|
|
72192
|
+
<div class="column-header">
|
|
72193
|
+
To Do
|
|
72194
|
+
<span class="column-count" id="count-todo">0</span>
|
|
72195
|
+
</div>
|
|
72196
|
+
<div class="column-cards" id="cards-todo">
|
|
72197
|
+
<div class="empty-column">Loading…</div>
|
|
72198
|
+
</div>
|
|
72199
|
+
</div>
|
|
72200
|
+
|
|
72201
|
+
<div class="column">
|
|
72202
|
+
<div class="column-header">
|
|
72203
|
+
Not Ready
|
|
72204
|
+
<span class="column-count" id="count-not-ready">0</span>
|
|
72205
|
+
</div>
|
|
72206
|
+
<div class="column-cards" id="cards-not-ready"></div>
|
|
72207
|
+
</div>
|
|
72208
|
+
|
|
72209
|
+
<div class="column">
|
|
72210
|
+
<div class="column-header">
|
|
72211
|
+
Done
|
|
72212
|
+
<span class="column-count" id="count-done">0</span>
|
|
72213
|
+
</div>
|
|
72214
|
+
<div class="column-cards" id="cards-done"></div>
|
|
72215
|
+
</div>
|
|
72216
|
+
|
|
72217
|
+
<div class="column">
|
|
72218
|
+
<div class="column-header">
|
|
72219
|
+
Failed
|
|
72220
|
+
<span class="column-count" id="count-failed">0</span>
|
|
72221
|
+
</div>
|
|
72222
|
+
<div class="column-cards" id="cards-failed"></div>
|
|
72223
|
+
</div>
|
|
72224
|
+
</div>
|
|
72225
|
+
|
|
72226
|
+
<div class="modal-overlay hidden" id="modal-overlay">
|
|
72227
|
+
<div class="modal">
|
|
72228
|
+
<div class="modal-header">
|
|
72229
|
+
<div class="modal-meta">
|
|
72230
|
+
<div class="modal-file" id="modal-file"></div>
|
|
72231
|
+
<div class="modal-section-label" id="modal-section-label"></div>
|
|
72232
|
+
</div>
|
|
72233
|
+
<span class="modal-status" id="modal-status-badge"></span>
|
|
72234
|
+
<button class="modal-close" onclick="closeModal()" title="Close (Esc)">✕</button>
|
|
72235
|
+
</div>
|
|
72236
|
+
|
|
72237
|
+
<textarea id="modal-content" placeholder="Prompt content…"></textarea>
|
|
72238
|
+
<div class="modal-hint">Tip: press Ctrl+Enter to save, Esc to cancel.</div>
|
|
72239
|
+
|
|
72240
|
+
<div class="modal-actions">
|
|
72241
|
+
<button class="btn btn-cancel" onclick="closeModal()">Cancel</button>
|
|
72242
|
+
<button class="btn btn-save" onclick="saveModal()">Save</button>
|
|
72243
|
+
</div>
|
|
72244
|
+
</div>
|
|
72245
|
+
</div>
|
|
72246
|
+
|
|
72247
|
+
<script>
|
|
72248
|
+
'use strict';
|
|
72249
|
+
|
|
72250
|
+
let modalState = null;
|
|
72251
|
+
let lastPauseState = 'RUNNING';
|
|
72252
|
+
|
|
72253
|
+
function showError(msg) {
|
|
72254
|
+
const banner = document.getElementById('error-banner');
|
|
72255
|
+
banner.textContent = '\\u26a0 ' + msg;
|
|
72256
|
+
banner.classList.remove('hidden');
|
|
72257
|
+
clearTimeout(banner._timer);
|
|
72258
|
+
banner._timer = setTimeout(() => banner.classList.add('hidden'), 6000);
|
|
72259
|
+
}
|
|
72260
|
+
|
|
72261
|
+
function escapeHtml(str) {
|
|
72262
|
+
const d = document.createElement('div');
|
|
72263
|
+
d.textContent = String(str);
|
|
72264
|
+
return d.innerHTML;
|
|
72265
|
+
}
|
|
72266
|
+
|
|
72267
|
+
async function fetchStatus() {
|
|
72268
|
+
try {
|
|
72269
|
+
const res = await fetch('/api/status');
|
|
72270
|
+
if (!res.ok) { showError('Status API error: ' + res.status); return; }
|
|
72271
|
+
const data = await res.json();
|
|
72272
|
+
|
|
72273
|
+
lastPauseState = data.pauseState;
|
|
72274
|
+
|
|
72275
|
+
const badge = document.getElementById('status-badge');
|
|
72276
|
+
badge.textContent = data.pauseState;
|
|
72277
|
+
badge.className = 'status-badge status-' + data.pauseState;
|
|
72278
|
+
|
|
72279
|
+
const btn = document.getElementById('toggle-btn');
|
|
72280
|
+
const label = document.getElementById('pause-label');
|
|
72281
|
+
|
|
72282
|
+
if (data.pauseState === 'RUNNING') {
|
|
72283
|
+
btn.textContent = '\\u23f8 Pause';
|
|
72284
|
+
btn.className = 'btn btn-pause';
|
|
72285
|
+
label.textContent = '';
|
|
72286
|
+
} else if (data.pauseState === 'PAUSING') {
|
|
72287
|
+
btn.textContent = '\\u23f5 Resume';
|
|
72288
|
+
btn.className = 'btn btn-resume';
|
|
72289
|
+
label.textContent = 'Pausing before: ' + (data.pauseTargetLabel || '\\u2026');
|
|
72290
|
+
} else {
|
|
72291
|
+
btn.textContent = '\\u23f5 Resume';
|
|
72292
|
+
btn.className = 'btn btn-resume';
|
|
72293
|
+
label.textContent = 'Paused before: ' + (data.pauseTargetLabel || '\\u2026');
|
|
72294
|
+
}
|
|
72295
|
+
} catch (e) {
|
|
72296
|
+
showError('Could not reach coder server: ' + e.message);
|
|
72297
|
+
}
|
|
72298
|
+
}
|
|
72299
|
+
|
|
72300
|
+
async function fetchPrompts() {
|
|
72301
|
+
try {
|
|
72302
|
+
const res = await fetch('/api/prompts');
|
|
72303
|
+
if (!res.ok) { showError('Prompts API error: ' + res.status); return; }
|
|
72304
|
+
renderBoard(await res.json());
|
|
72305
|
+
} catch (e) {
|
|
72306
|
+
showError('Could not load prompts: ' + e.message);
|
|
72307
|
+
}
|
|
72308
|
+
}
|
|
72309
|
+
|
|
72310
|
+
function renderBoard(promptFiles) {
|
|
72311
|
+
const columns = { 'todo': [], 'not-ready': [], 'done': [], 'failed': [] };
|
|
72312
|
+
|
|
72313
|
+
for (const file of promptFiles) {
|
|
72314
|
+
for (const section of file.sections) {
|
|
72315
|
+
const col = columns[section.status];
|
|
72316
|
+
if (col) col.push({ file, section });
|
|
72317
|
+
}
|
|
72318
|
+
}
|
|
72319
|
+
|
|
72320
|
+
for (const [status, cards] of Object.entries(columns)) {
|
|
72321
|
+
const container = document.getElementById('cards-' + status);
|
|
72322
|
+
const countEl = document.getElementById('count-' + status);
|
|
72323
|
+
if (!container) continue;
|
|
72324
|
+
|
|
72325
|
+
countEl.textContent = cards.length;
|
|
72326
|
+
container.innerHTML = '';
|
|
72327
|
+
|
|
72328
|
+
if (cards.length === 0) {
|
|
72329
|
+
container.innerHTML = '<div class="empty-column">Empty</div>';
|
|
72330
|
+
continue;
|
|
72331
|
+
}
|
|
72332
|
+
|
|
72333
|
+
for (const { file, section } of cards) {
|
|
72334
|
+
const card = document.createElement('div');
|
|
72335
|
+
card.className = 'card card-' + section.status;
|
|
72336
|
+
card.innerHTML =
|
|
72337
|
+
'<div class="card-file">' + escapeHtml(file.fileName) + ' • #' + (section.index + 1) + '</div>' +
|
|
72338
|
+
'<div class="card-summary">' + escapeHtml(section.summary) + '</div>' +
|
|
72339
|
+
(section.priority > 0
|
|
72340
|
+
? '<div class="card-priority">' + '!'.repeat(section.priority) + ' priority ' + section.priority + '</div>'
|
|
72341
|
+
: '') +
|
|
72342
|
+
'<div class="card-edit-hint">Click to edit</div>';
|
|
72343
|
+
card.onclick = () => openModal(file, section);
|
|
72344
|
+
container.appendChild(card);
|
|
72345
|
+
}
|
|
72346
|
+
}
|
|
72347
|
+
}
|
|
72348
|
+
|
|
72349
|
+
function openModal(file, section) {
|
|
72350
|
+
modalState = { filePath: file.filePath, sectionIndex: section.index };
|
|
72351
|
+
|
|
72352
|
+
document.getElementById('modal-file').textContent = file.fileName;
|
|
72353
|
+
document.getElementById('modal-section-label').textContent = 'Section ' + (section.index + 1);
|
|
72354
|
+
|
|
72355
|
+
const badge = document.getElementById('modal-status-badge');
|
|
72356
|
+
badge.textContent = section.status.replace('-', '\\u2011');
|
|
72357
|
+
badge.className = 'modal-status status-' + section.status;
|
|
72358
|
+
|
|
72359
|
+
document.getElementById('modal-content').value = section.content;
|
|
72360
|
+
document.getElementById('modal-overlay').classList.remove('hidden');
|
|
72361
|
+
setTimeout(() => document.getElementById('modal-content').focus(), 50);
|
|
72362
|
+
}
|
|
72363
|
+
|
|
72364
|
+
function closeModal() {
|
|
72365
|
+
document.getElementById('modal-overlay').classList.add('hidden');
|
|
72366
|
+
modalState = null;
|
|
72367
|
+
}
|
|
72368
|
+
|
|
72369
|
+
async function saveModal() {
|
|
72370
|
+
if (!modalState) return;
|
|
72371
|
+
|
|
72372
|
+
const content = document.getElementById('modal-content').value;
|
|
72373
|
+
const saveBtn = document.querySelector('.btn-save');
|
|
72374
|
+
saveBtn.disabled = true;
|
|
72375
|
+
saveBtn.textContent = 'Saving\\u2026';
|
|
72376
|
+
|
|
72377
|
+
try {
|
|
72378
|
+
const res = await fetch('/api/prompts/update', {
|
|
72379
|
+
method: 'PUT',
|
|
72380
|
+
headers: { 'Content-Type': 'application/json' },
|
|
72381
|
+
body: JSON.stringify({
|
|
72382
|
+
filePath: modalState.filePath,
|
|
72383
|
+
sectionIndex: modalState.sectionIndex,
|
|
72384
|
+
content,
|
|
72385
|
+
}),
|
|
72386
|
+
});
|
|
72387
|
+
if (!res.ok) throw new Error('HTTP ' + res.status);
|
|
72388
|
+
closeModal();
|
|
72389
|
+
fetchPrompts();
|
|
72390
|
+
} catch (e) {
|
|
72391
|
+
showError('Save failed: ' + e.message);
|
|
72392
|
+
} finally {
|
|
72393
|
+
saveBtn.disabled = false;
|
|
72394
|
+
saveBtn.textContent = 'Save';
|
|
72395
|
+
}
|
|
72396
|
+
}
|
|
72397
|
+
|
|
72398
|
+
document.getElementById('toggle-btn').onclick = async () => {
|
|
72399
|
+
try {
|
|
72400
|
+
const endpoint = lastPauseState === 'RUNNING' ? '/api/pause' : '/api/resume';
|
|
72401
|
+
await fetch(endpoint, { method: 'POST' });
|
|
72402
|
+
await fetchStatus();
|
|
72403
|
+
} catch (e) {
|
|
72404
|
+
showError('Toggle failed: ' + e.message);
|
|
72405
|
+
}
|
|
72406
|
+
};
|
|
72407
|
+
|
|
72408
|
+
document.addEventListener('keydown', (e) => {
|
|
72409
|
+
if (e.key === 'Escape') { closeModal(); return; }
|
|
72410
|
+
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') { saveModal(); return; }
|
|
72411
|
+
});
|
|
72412
|
+
|
|
72413
|
+
document.getElementById('modal-overlay').addEventListener('click', (e) => {
|
|
72414
|
+
if (e.target === document.getElementById('modal-overlay')) closeModal();
|
|
72415
|
+
});
|
|
72416
|
+
|
|
72417
|
+
fetchStatus();
|
|
72418
|
+
fetchPrompts();
|
|
72419
|
+
setInterval(fetchStatus, 2000);
|
|
72420
|
+
setInterval(fetchPrompts, 5000);
|
|
72421
|
+
</script>
|
|
72422
|
+
</body>
|
|
72423
|
+
</html>`;
|
|
72424
|
+
// Note: [🟡] Code for CLI command [coder server](scripts/run-codex-prompts/server/coderServerHtml.ts) should never be published outside of `@promptbook/cli`
|
|
72425
|
+
// Note: Keep in sync with apps/coder-server/index.html
|
|
72426
|
+
|
|
72427
|
+
/**
|
|
72428
|
+
* Directory from which prompt files are loaded, relative to the current working directory.
|
|
72429
|
+
*
|
|
72430
|
+
* @private internal constant of `ptbk coder server`
|
|
72431
|
+
*/
|
|
72432
|
+
const PROMPTS_DIRECTORY_NAME = 'prompts';
|
|
72433
|
+
/**
|
|
72434
|
+
* Starts the lightweight HTTP server that serves the coder kanban UI and REST API.
|
|
72435
|
+
*
|
|
72436
|
+
* API endpoints:
|
|
72437
|
+
* - `GET /` → HTML kanban page
|
|
72438
|
+
* - `GET /api/prompts` → JSON list of all prompt files and sections
|
|
72439
|
+
* - `GET /api/status` → JSON current pause state
|
|
72440
|
+
* - `POST /api/pause` → request pause
|
|
72441
|
+
* - `POST /api/resume` → request resume
|
|
72442
|
+
* - `PUT /api/prompts/update` → update prompt section content
|
|
72443
|
+
*
|
|
72444
|
+
* @private internal utility of `ptbk coder server`
|
|
72445
|
+
*/
|
|
72446
|
+
function startCoderHttpServer(port) {
|
|
72447
|
+
const promptsDir = path.join(process.cwd(), PROMPTS_DIRECTORY_NAME);
|
|
72448
|
+
const server = http.createServer(async (req, res) => {
|
|
72449
|
+
try {
|
|
72450
|
+
await handleRequest(req, res, promptsDir);
|
|
72451
|
+
}
|
|
72452
|
+
catch (error) {
|
|
72453
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
72454
|
+
console.error(colors__default["default"].red(`Coder server request error: ${message}`));
|
|
72455
|
+
if (!res.headersSent) {
|
|
72456
|
+
res.writeHead(500, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
72457
|
+
}
|
|
72458
|
+
res.end('Internal server error');
|
|
72459
|
+
}
|
|
72460
|
+
});
|
|
72461
|
+
server.listen(port, () => {
|
|
72462
|
+
console.info(_spaceTrim.spaceTrim(`
|
|
72463
|
+
Coder server running at ${colors__default["default"].cyan(`http://localhost:${port}`)}
|
|
72464
|
+
Open the URL above in your browser to see the kanban board.
|
|
72465
|
+
Press ${colors__default["default"].bold('p')} to pause / resume the agent runner.
|
|
72466
|
+
`));
|
|
72467
|
+
});
|
|
72468
|
+
return {
|
|
72469
|
+
close: () => {
|
|
72470
|
+
server.close();
|
|
72471
|
+
},
|
|
72472
|
+
};
|
|
72473
|
+
}
|
|
72474
|
+
/**
|
|
72475
|
+
* Routes one HTTP request to the appropriate handler.
|
|
72476
|
+
*/
|
|
72477
|
+
async function handleRequest(req, res, promptsDir) {
|
|
72478
|
+
const urlPath = new URL(req.url || '/', `http://localhost`).pathname;
|
|
72479
|
+
const method = (req.method || 'GET').toUpperCase();
|
|
72480
|
+
// Serve the kanban UI
|
|
72481
|
+
if (urlPath === '/' && method === 'GET') {
|
|
72482
|
+
res.writeHead(200, {
|
|
72483
|
+
'Content-Type': 'text/html; charset=utf-8',
|
|
72484
|
+
'Cache-Control': 'no-cache',
|
|
72485
|
+
});
|
|
72486
|
+
res.end(CODER_SERVER_HTML);
|
|
72487
|
+
return;
|
|
72488
|
+
}
|
|
72489
|
+
// GET /api/status
|
|
72490
|
+
if (urlPath === '/api/status' && method === 'GET') {
|
|
72491
|
+
res.writeHead(200, jsonHeaders());
|
|
72492
|
+
res.end(JSON.stringify({
|
|
72493
|
+
pauseState: getPauseState(),
|
|
72494
|
+
pauseTargetLabel: getPauseTargetLabel(),
|
|
72495
|
+
}));
|
|
72496
|
+
return;
|
|
72497
|
+
}
|
|
72498
|
+
// GET /api/prompts
|
|
72499
|
+
if (urlPath === '/api/prompts' && method === 'GET') {
|
|
72500
|
+
const promptData = await loadPromptsForApi(promptsDir);
|
|
72501
|
+
res.writeHead(200, jsonHeaders());
|
|
72502
|
+
res.end(JSON.stringify(promptData));
|
|
72503
|
+
return;
|
|
72504
|
+
}
|
|
72505
|
+
// POST /api/pause
|
|
72506
|
+
if (urlPath === '/api/pause' && method === 'POST') {
|
|
72507
|
+
requestPause();
|
|
72508
|
+
res.writeHead(200, jsonHeaders());
|
|
72509
|
+
res.end(JSON.stringify({ pauseState: getPauseState() }));
|
|
72510
|
+
return;
|
|
72511
|
+
}
|
|
72512
|
+
// POST /api/resume
|
|
72513
|
+
if (urlPath === '/api/resume' && method === 'POST') {
|
|
72514
|
+
requestResume();
|
|
72515
|
+
res.writeHead(200, jsonHeaders());
|
|
72516
|
+
res.end(JSON.stringify({ pauseState: getPauseState() }));
|
|
72517
|
+
return;
|
|
72518
|
+
}
|
|
72519
|
+
// PUT /api/prompts/update
|
|
72520
|
+
if (urlPath === '/api/prompts/update' && method === 'PUT') {
|
|
72521
|
+
const body = await readRequestBody(req);
|
|
72522
|
+
const parsed = JSON.parse(body);
|
|
72523
|
+
if (typeof parsed.filePath !== 'string' ||
|
|
72524
|
+
typeof parsed.sectionIndex !== 'number' ||
|
|
72525
|
+
typeof parsed.content !== 'string') {
|
|
72526
|
+
throw new NotAllowed(_spaceTrim.spaceTrim(`
|
|
72527
|
+
Invalid request body for \`PUT /api/prompts/update\`.
|
|
72528
|
+
|
|
72529
|
+
Expected: \`{ filePath: string, sectionIndex: number, content: string }\`
|
|
72530
|
+
`));
|
|
72531
|
+
}
|
|
72532
|
+
await updatePromptSection(parsed.filePath, parsed.sectionIndex, parsed.content);
|
|
72533
|
+
res.writeHead(200, jsonHeaders());
|
|
72534
|
+
res.end(JSON.stringify({ success: true }));
|
|
72535
|
+
return;
|
|
72536
|
+
}
|
|
72537
|
+
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
72538
|
+
res.end('Not found');
|
|
72539
|
+
}
|
|
72540
|
+
/**
|
|
72541
|
+
* Loads all prompt files and converts them to the API response shape.
|
|
72542
|
+
*/
|
|
72543
|
+
async function loadPromptsForApi(promptsDir) {
|
|
72544
|
+
try {
|
|
72545
|
+
const promptFiles = await loadPromptFiles(promptsDir);
|
|
72546
|
+
return promptFiles.map((file) => ({
|
|
72547
|
+
filePath: file.path,
|
|
72548
|
+
fileName: file.name,
|
|
72549
|
+
sections: file.sections.map((section) => ({
|
|
72550
|
+
index: section.index,
|
|
72551
|
+
status: section.status,
|
|
72552
|
+
priority: section.priority,
|
|
72553
|
+
summary: buildPromptSummary(file, section),
|
|
72554
|
+
content: buildCodexPrompt(file, section),
|
|
72555
|
+
})),
|
|
72556
|
+
}));
|
|
72557
|
+
}
|
|
72558
|
+
catch (error) {
|
|
72559
|
+
// Prompts directory may not exist yet; return empty list
|
|
72560
|
+
if (error.code === 'ENOENT') {
|
|
72561
|
+
return [];
|
|
72562
|
+
}
|
|
72563
|
+
throw error;
|
|
72564
|
+
}
|
|
72565
|
+
}
|
|
72566
|
+
/**
|
|
72567
|
+
* Reads the full request body as a UTF-8 string.
|
|
72568
|
+
*/
|
|
72569
|
+
function readRequestBody(req) {
|
|
72570
|
+
return new Promise((resolve, reject) => {
|
|
72571
|
+
const chunks = [];
|
|
72572
|
+
req.on('data', (chunk) => chunks.push(chunk));
|
|
72573
|
+
req.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')));
|
|
72574
|
+
req.on('error', reject);
|
|
72575
|
+
});
|
|
72576
|
+
}
|
|
72577
|
+
/**
|
|
72578
|
+
* Returns standard JSON response headers with no-cache directives.
|
|
72579
|
+
*/
|
|
72580
|
+
function jsonHeaders() {
|
|
72581
|
+
return {
|
|
72582
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
72583
|
+
'Cache-Control': 'no-cache',
|
|
72584
|
+
};
|
|
72585
|
+
}
|
|
72586
|
+
// Note: [🟡] Code for CLI command [coder server](scripts/run-codex-prompts/server/runCoderHttpServer.ts) should never be published outside of `@promptbook/cli`
|
|
72587
|
+
|
|
72588
|
+
/**
|
|
72589
|
+
* Starts the coder server: runs prompt processing in keepAlive mode while serving a
|
|
72590
|
+
* kanban web UI and REST API on the given port.
|
|
72591
|
+
*
|
|
72592
|
+
* Differences from `runCodexPrompts`:
|
|
72593
|
+
* - Does not exit when no runnable prompts are available; instead it polls every few seconds
|
|
72594
|
+
* and resumes processing as soon as a new prompt becomes ready.
|
|
72595
|
+
* - Starts a lightweight HTTP server that serves a kanban board at `http://localhost:<port>`
|
|
72596
|
+
* and exposes REST endpoints for reading prompts, controlling pause state, and editing
|
|
72597
|
+
* prompt files directly from the browser.
|
|
72598
|
+
*
|
|
72599
|
+
* @private internal function of `ptbk coder server`
|
|
72600
|
+
*/
|
|
72601
|
+
async function runCodexPromptsServer(options) {
|
|
72602
|
+
const { port, ...runOptions } = options;
|
|
72603
|
+
const serverHandle = startCoderHttpServer(port);
|
|
72604
|
+
console.info(colors__default["default"].gray('Starting prompt runner in server (keep-alive) mode…'));
|
|
72605
|
+
try {
|
|
72606
|
+
await runCodexPrompts({
|
|
72607
|
+
...runOptions,
|
|
72608
|
+
keepAlive: true,
|
|
72609
|
+
});
|
|
72610
|
+
}
|
|
72611
|
+
finally {
|
|
72612
|
+
serverHandle.close();
|
|
72613
|
+
}
|
|
72614
|
+
}
|
|
72615
|
+
// Note: [🟡] Code for CLI command [coder server](scripts/run-codex-prompts/main/runCodexPromptsServer.ts) should never be published outside of `@promptbook/cli`
|
|
72616
|
+
|
|
72617
|
+
var runCodexPromptsServer$1 = /*#__PURE__*/Object.freeze({
|
|
72618
|
+
__proto__: null,
|
|
72619
|
+
runCodexPromptsServer: runCodexPromptsServer
|
|
72620
|
+
});
|
|
72621
|
+
|
|
71546
72622
|
/**
|
|
71547
72623
|
* Path to the directory that holds the prompt markdown files.
|
|
71548
72624
|
*/
|