@promptbook/cli 0.112.0-112 → 0.112.0-114
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/README.md +7 -7
- package/apps/agents-server/README.md +1 -1
- package/apps/agents-server/next.config.ts +20 -1
- package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/stream/route.ts +85 -56
- package/apps/agents-server/src/app/agents/[agentName]/chat/useAgentChatHistorySyncEffects.ts +7 -13
- package/apps/agents-server/src/app/api/admin/code-runners/route.ts +1 -1
- package/apps/agents-server/src/app/api/internal/user-chat-jobs/run/route.ts +1 -1
- package/apps/agents-server/src/database/migrations/2026-06-1300-user-chat-active-read-indexes.sql +7 -0
- package/apps/agents-server/src/instrumentation-client.ts +28 -0
- package/apps/agents-server/src/instrumentation.ts +16 -0
- package/apps/agents-server/src/sentry.edge.config.ts +18 -0
- package/apps/agents-server/src/sentry.server.config.ts +19 -0
- package/apps/agents-server/src/utils/agentRouting/resolveAgentRouteTarget.ts +38 -0
- package/apps/agents-server/src/utils/codeRunnerConfiguration.ts +1 -1
- package/apps/agents-server/src/utils/errorReporting/agentsServerSentryContext.ts +203 -0
- package/apps/agents-server/src/utils/errorReporting/registerServerErrorSentryLogging.ts +59 -9
- package/apps/agents-server/src/utils/errorReporting/sendApplicationErrorReportToSentry.ts +39 -3
- package/apps/agents-server/src/utils/errorReporting/sentrySdkConfig.ts +237 -0
- package/apps/agents-server/src/utils/errorReporting/sentryStore.ts +10 -0
- package/apps/agents-server/src/utils/externalChatRunner/createExternalAgentRepositoryFiles.ts +2 -2
- package/apps/agents-server/src/utils/userChat/createImmediateUserChatAnswerModelRequirements.ts +15 -12
- package/apps/agents-server/src/utils/userChat/createUserChatDetailPayload.ts +33 -18
- package/apps/agents-server/src/utils/userChat/hasPotentiallyPendingAssistantMessages.ts +26 -0
- package/apps/agents-server/src/utils/userChat/runImmediateUserChatAnswer.ts +1 -1
- package/apps/agents-server/src/utils/userChat/triggerUserChatJobWorker.ts +54 -19
- package/apps/agents-server/src/utils/vpsConfiguration.ts +1 -1
- package/esm/index.es.js +9285 -8807
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-agent-chat/executeAgentChatTurn.d.ts +28 -0
- package/esm/scripts/run-agent-chat/runAgentChat.d.ts +5 -0
- package/esm/scripts/run-agent-chat/runAgentExec.d.ts +11 -0
- package/esm/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +10 -0
- package/esm/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +14 -0
- package/esm/scripts/run-codex-prompts/common/runGoScript/printLiveScriptChunk.d.ts +4 -0
- package/esm/src/_packages/node.index.d.ts +20 -0
- package/esm/src/_packages/types.index.d.ts +16 -0
- package/esm/src/book-3.0/BookNodeAgentSource.d.ts +38 -0
- package/esm/src/book-3.0/CliAgent.d.ts +68 -0
- package/esm/src/book-3.0/LiteAgent.d.ts +68 -0
- package/esm/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.d.ts +12 -0
- package/esm/src/cli/cli-commands/agent/agentCliOptions.d.ts +38 -0
- package/esm/src/cli/cli-commands/agent/chat.d.ts +10 -0
- package/esm/src/cli/cli-commands/agent/exec.d.ts +10 -0
- package/esm/src/cli/cli-commands/agent/run.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/agent.d.ts +14 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +3 -4
- package/esm/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +9 -9
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -1
- package/src/_packages/node.index.ts +20 -0
- package/src/_packages/types.index.ts +16 -0
- package/src/book-3.0/BookNodeAgentSource.ts +135 -0
- package/src/book-3.0/CliAgent.ts +236 -0
- package/src/book-3.0/LiteAgent.ts +468 -0
- package/src/book-components/BookEditor/BookEditor.module.css +61 -0
- package/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.tsx +74 -0
- package/src/book-components/BookEditor/BookEditorActionbar.tsx +3 -3
- package/src/cli/cli-commands/agent/agentCliOptions.ts +92 -0
- package/src/cli/cli-commands/agent/chat.ts +54 -0
- package/src/cli/cli-commands/agent/exec.ts +60 -0
- package/src/cli/cli-commands/agent.ts +44 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer.ts +3 -19
- package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +1 -1
- package/src/cli/cli-commands/common/promptRunnerCliOptions.ts +27 -23
- package/src/cli/promptbookCli.ts +2 -0
- package/src/other/templates/getTemplatesPipelineCollection.ts +747 -771
- package/src/version.ts +2 -2
- package/src/versions.txt +2 -0
- package/umd/index.umd.js +9285 -8807
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-agent-chat/executeAgentChatTurn.d.ts +28 -0
- package/umd/scripts/run-agent-chat/runAgentChat.d.ts +5 -0
- package/umd/scripts/run-agent-chat/runAgentExec.d.ts +11 -0
- package/umd/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +10 -0
- package/umd/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +14 -0
- package/umd/scripts/run-codex-prompts/common/runGoScript/printLiveScriptChunk.d.ts +4 -0
- package/umd/src/_packages/node.index.d.ts +20 -0
- package/umd/src/_packages/types.index.d.ts +16 -0
- package/umd/src/book-3.0/BookNodeAgentSource.d.ts +38 -0
- package/umd/src/book-3.0/CliAgent.d.ts +68 -0
- package/umd/src/book-3.0/CliAgent.test.d.ts +1 -0
- package/umd/src/book-3.0/LiteAgent.d.ts +68 -0
- package/umd/src/book-3.0/LiteAgent.test.d.ts +1 -0
- package/umd/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.d.ts +12 -0
- package/umd/src/cli/cli-commands/agent/agentCliOptions.d.ts +38 -0
- package/umd/src/cli/cli-commands/agent/chat.d.ts +10 -0
- package/umd/src/cli/cli-commands/agent/exec.d.ts +10 -0
- package/umd/src/cli/cli-commands/agent/run.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/agent.d.ts +14 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +3 -4
- package/umd/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +9 -9
- package/umd/src/version.d.ts +1 -1
- /package/esm/src/{cli/cli-commands/agents-server/startAgentsServer.test.d.ts → book-3.0/CliAgent.test.d.ts} +0 -0
- /package/{umd/src/cli/cli-commands/agents-server/startAgentsServer.test.d.ts → esm/src/book-3.0/LiteAgent.test.d.ts} +0 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
import { dirname, resolve } from 'path';
|
|
3
|
+
import type { string_book } from '../book-2.0/agent-source/string_book';
|
|
4
|
+
import { assertsError } from '../errors/assertsError';
|
|
5
|
+
import { NotAllowed } from '../errors/NotAllowed';
|
|
6
|
+
import { NotFoundError } from '../errors/NotFoundError';
|
|
7
|
+
import { spaceTrim } from '../utils/organization/spaceTrim';
|
|
8
|
+
import { Book } from './Book';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Book source value accepted by Node-backed Book agents.
|
|
12
|
+
*
|
|
13
|
+
* @public exported from `@promptbook/node`
|
|
14
|
+
*/
|
|
15
|
+
export type BookNodeAgentSource = Book | string_book;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Common source options shared by Node-backed Book agents.
|
|
19
|
+
*
|
|
20
|
+
* Provide either `agentPath` or `book`.
|
|
21
|
+
*
|
|
22
|
+
* @public exported from `@promptbook/node`
|
|
23
|
+
*/
|
|
24
|
+
export type BookNodeAgentSourceOptions = {
|
|
25
|
+
readonly agentPath?: string;
|
|
26
|
+
readonly book?: BookNodeAgentSource;
|
|
27
|
+
readonly currentWorkingDirectory?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Normalized source snapshot used internally by Node-backed Book agents.
|
|
32
|
+
*
|
|
33
|
+
* @private internal utility of `CliAgent` and `LiteAgent`
|
|
34
|
+
*/
|
|
35
|
+
export type ResolvedBookNodeAgentSource = {
|
|
36
|
+
readonly agentName: string;
|
|
37
|
+
readonly agentPath: string | null;
|
|
38
|
+
readonly agentSource: string_book;
|
|
39
|
+
readonly currentWorkingDirectory: string;
|
|
40
|
+
readonly sourceDirectoryPath: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Resolves shared Node-backed Book source options into one normalized source snapshot.
|
|
45
|
+
*
|
|
46
|
+
* @private internal utility of `CliAgent` and `LiteAgent`
|
|
47
|
+
*/
|
|
48
|
+
export async function resolveBookNodeAgentSource(
|
|
49
|
+
options: BookNodeAgentSourceOptions,
|
|
50
|
+
): Promise<ResolvedBookNodeAgentSource> {
|
|
51
|
+
const hasAgentPath = typeof options.agentPath === 'string' && options.agentPath.trim().length > 0;
|
|
52
|
+
const hasBook = options.book !== undefined;
|
|
53
|
+
|
|
54
|
+
if (hasAgentPath === hasBook) {
|
|
55
|
+
throw new NotAllowed(
|
|
56
|
+
spaceTrim(`
|
|
57
|
+
Provide exactly one of \`agentPath\` or \`book\`.
|
|
58
|
+
|
|
59
|
+
These options are mutually exclusive because they define different source-resolution strategies.
|
|
60
|
+
`),
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const currentWorkingDirectory = options.currentWorkingDirectory || process.cwd();
|
|
65
|
+
|
|
66
|
+
if (hasBook) {
|
|
67
|
+
const agentSource = normalizeBookNodeAgentSource(options.book!);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
agentName: resolveBookNodeAgentName(agentSource),
|
|
71
|
+
agentPath: null,
|
|
72
|
+
agentSource,
|
|
73
|
+
currentWorkingDirectory,
|
|
74
|
+
sourceDirectoryPath: currentWorkingDirectory,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const absoluteAgentPath = resolve(currentWorkingDirectory, options.agentPath!);
|
|
79
|
+
const agentSource = await readAgentSourceFile(absoluteAgentPath, options.agentPath!);
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
agentName: resolveBookNodeAgentName(agentSource),
|
|
83
|
+
agentPath: absoluteAgentPath,
|
|
84
|
+
agentSource,
|
|
85
|
+
currentWorkingDirectory,
|
|
86
|
+
sourceDirectoryPath: dirname(absoluteAgentPath),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Normalizes one in-memory Book source into a persisted string.
|
|
92
|
+
*
|
|
93
|
+
* @private internal utility of `resolveBookNodeAgentSource`
|
|
94
|
+
*/
|
|
95
|
+
function normalizeBookNodeAgentSource(book: BookNodeAgentSource): string_book {
|
|
96
|
+
if (book instanceof Book) {
|
|
97
|
+
return book.stringify();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return (book.endsWith('\n') ? book : `${book}\n`) as string_book;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Reads one agent source file and wraps missing-file errors into Promptbook-branded errors.
|
|
105
|
+
*
|
|
106
|
+
* @private internal utility of `resolveBookNodeAgentSource`
|
|
107
|
+
*/
|
|
108
|
+
async function readAgentSourceFile(absoluteAgentPath: string, agentPathReference: string): Promise<string_book> {
|
|
109
|
+
try {
|
|
110
|
+
return (await readFile(absoluteAgentPath, 'utf-8')) as string_book;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
assertsError(error);
|
|
113
|
+
|
|
114
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT' || (error as NodeJS.ErrnoException).code === 'EISDIR') {
|
|
115
|
+
throw new NotFoundError(
|
|
116
|
+
spaceTrim(`
|
|
117
|
+
Agent book \`${agentPathReference}\` was not found or is not a file.
|
|
118
|
+
|
|
119
|
+
Pass a path to an existing \`.book\` file.
|
|
120
|
+
`),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Resolves the display name used by Node-backed Book agents.
|
|
130
|
+
*
|
|
131
|
+
* @private internal utility of `resolveBookNodeAgentSource`
|
|
132
|
+
*/
|
|
133
|
+
function resolveBookNodeAgentName(agentSource: string_book): string {
|
|
134
|
+
return Book.parse(agentSource).agentName.trim() || 'Agent';
|
|
135
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { mkdir, writeFile } from 'fs/promises';
|
|
2
|
+
import { dirname } from 'path';
|
|
3
|
+
import { NotAllowed } from '../errors/NotAllowed';
|
|
4
|
+
import { resolvePromptbookTemporaryPath } from '../utils/filesystem/promptbookTemporaryPath';
|
|
5
|
+
import { $execCommand } from '../utils/execCommand/$execCommand';
|
|
6
|
+
import type { BookNodeAgentSourceOptions, ResolvedBookNodeAgentSource } from './BookNodeAgentSource';
|
|
7
|
+
import { resolveBookNodeAgentSource } from './BookNodeAgentSource';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* CLI harness names supported by `ptbk agent exec`.
|
|
11
|
+
*
|
|
12
|
+
* @public exported from `@promptbook/node`
|
|
13
|
+
*/
|
|
14
|
+
export type CliAgentHarness = 'openai-codex' | 'github-copilot' | 'cline' | 'claude-code' | 'opencode' | 'gemini';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Thinking levels supported by CLI coding harnesses.
|
|
18
|
+
*
|
|
19
|
+
* @public exported from `@promptbook/node`
|
|
20
|
+
*/
|
|
21
|
+
export type CliAgentThinkingLevel = 'low' | 'medium' | 'high' | 'xhigh';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Per-run CLI options exposed by `CliAgent`.
|
|
25
|
+
*
|
|
26
|
+
* `noUi` defaults to `true` so command output stays suitable for JavaScript callers.
|
|
27
|
+
*
|
|
28
|
+
* @public exported from `@promptbook/node`
|
|
29
|
+
*/
|
|
30
|
+
export type CliAgentRunOptions = {
|
|
31
|
+
readonly allowCredits?: boolean;
|
|
32
|
+
readonly context?: string;
|
|
33
|
+
readonly harness?: CliAgentHarness;
|
|
34
|
+
readonly model?: string;
|
|
35
|
+
readonly noUi?: boolean;
|
|
36
|
+
readonly thinkingLevel?: CliAgentThinkingLevel;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Constructor options for `CliAgent`.
|
|
41
|
+
*
|
|
42
|
+
* @public exported from `@promptbook/node`
|
|
43
|
+
*/
|
|
44
|
+
export type CliAgentOptions = BookNodeAgentSourceOptions &
|
|
45
|
+
CliAgentRunOptions & {
|
|
46
|
+
/**
|
|
47
|
+
* Executable used for the wrapper command.
|
|
48
|
+
*
|
|
49
|
+
* @default ptbk
|
|
50
|
+
*/
|
|
51
|
+
readonly command?: string;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Default executable used by `CliAgent`.
|
|
56
|
+
*
|
|
57
|
+
* @private internal constant of `CliAgent`
|
|
58
|
+
*/
|
|
59
|
+
const DEFAULT_CLI_AGENT_COMMAND = 'ptbk';
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Default non-interactive mode used by `CliAgent`.
|
|
63
|
+
*
|
|
64
|
+
* @private internal constant of `CliAgent`
|
|
65
|
+
*/
|
|
66
|
+
const DEFAULT_CLI_AGENT_IS_NO_UI = true;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Lightweight JavaScript wrapper around `ptbk agent exec`.
|
|
70
|
+
*
|
|
71
|
+
* It uses the same CLI harnesses as Promptbook's agent command, making it the most faithful
|
|
72
|
+
* way to run a local Book agent from Node.js when you want the CLI execution flow.
|
|
73
|
+
*
|
|
74
|
+
* @public exported from `@promptbook/node`
|
|
75
|
+
*/
|
|
76
|
+
export class CliAgent {
|
|
77
|
+
private temporaryAgentPath: string | null = null;
|
|
78
|
+
|
|
79
|
+
public constructor(private readonly options: CliAgentOptions) {}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Runs one non-interactive agent turn through `ptbk agent exec`.
|
|
83
|
+
*
|
|
84
|
+
* @param message - User message sent to the agent.
|
|
85
|
+
* @param options - Optional per-run CLI overrides.
|
|
86
|
+
* @returns Raw stdout emitted by the CLI command.
|
|
87
|
+
*/
|
|
88
|
+
public async run(message: string, options: CliAgentRunOptions = {}): Promise<string> {
|
|
89
|
+
const normalizedMessage = message.trim();
|
|
90
|
+
|
|
91
|
+
if (!normalizedMessage) {
|
|
92
|
+
throw new NotAllowed('Pass a non-empty message to `CliAgent.run(...)`.');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const resolvedSource = await resolveBookNodeAgentSource(this.options);
|
|
96
|
+
const agentPath = await this.resolveExecutableAgentPath(resolvedSource);
|
|
97
|
+
const mergedOptions = mergeCliAgentRunOptions(this.options, options);
|
|
98
|
+
|
|
99
|
+
return $execCommand({
|
|
100
|
+
command: this.options.command || DEFAULT_CLI_AGENT_COMMAND,
|
|
101
|
+
args: createCliAgentExecArguments({
|
|
102
|
+
agentPath,
|
|
103
|
+
allowCredits: mergedOptions.allowCredits ?? false,
|
|
104
|
+
context: mergedOptions.context,
|
|
105
|
+
harness: mergedOptions.harness,
|
|
106
|
+
message: normalizedMessage,
|
|
107
|
+
model: mergedOptions.model,
|
|
108
|
+
noUi: mergedOptions.noUi ?? DEFAULT_CLI_AGENT_IS_NO_UI,
|
|
109
|
+
thinkingLevel: mergedOptions.thinkingLevel,
|
|
110
|
+
}),
|
|
111
|
+
cwd: resolvedSource.currentWorkingDirectory,
|
|
112
|
+
crashOnError: true,
|
|
113
|
+
timeout: Infinity,
|
|
114
|
+
isVerbose: false,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Resolves the agent path passed to the CLI, materializing one temporary `.book` file when needed.
|
|
120
|
+
*
|
|
121
|
+
* @private internal utility of `CliAgent`
|
|
122
|
+
*/
|
|
123
|
+
private async resolveExecutableAgentPath(resolvedSource: ResolvedBookNodeAgentSource): Promise<string> {
|
|
124
|
+
if (resolvedSource.agentPath) {
|
|
125
|
+
return resolvedSource.agentPath;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!this.temporaryAgentPath) {
|
|
129
|
+
this.temporaryAgentPath = createCliAgentTemporaryBookPath(resolvedSource);
|
|
130
|
+
|
|
131
|
+
await mkdir(dirname(this.temporaryAgentPath), { recursive: true });
|
|
132
|
+
await writeFile(this.temporaryAgentPath, normalizeCliAgentBookSource(resolvedSource.agentSource), 'utf-8');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return this.temporaryAgentPath;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Merges constructor defaults with per-run CLI overrides.
|
|
141
|
+
*
|
|
142
|
+
* @private internal utility of `CliAgent`
|
|
143
|
+
*/
|
|
144
|
+
function mergeCliAgentRunOptions(defaults: CliAgentRunOptions, overrides: CliAgentRunOptions): CliAgentRunOptions {
|
|
145
|
+
return {
|
|
146
|
+
allowCredits: overrides.allowCredits ?? defaults.allowCredits,
|
|
147
|
+
context: overrides.context ?? defaults.context,
|
|
148
|
+
harness: overrides.harness ?? defaults.harness,
|
|
149
|
+
model: overrides.model ?? defaults.model,
|
|
150
|
+
noUi: overrides.noUi ?? defaults.noUi,
|
|
151
|
+
thinkingLevel: overrides.thinkingLevel ?? defaults.thinkingLevel,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Builds CLI arguments for `ptbk agent exec`.
|
|
157
|
+
*
|
|
158
|
+
* @private internal utility of `CliAgent`
|
|
159
|
+
*/
|
|
160
|
+
function createCliAgentExecArguments(options: {
|
|
161
|
+
readonly agentPath: string;
|
|
162
|
+
readonly allowCredits: boolean;
|
|
163
|
+
readonly context?: string;
|
|
164
|
+
readonly harness?: CliAgentHarness;
|
|
165
|
+
readonly message: string;
|
|
166
|
+
readonly model?: string;
|
|
167
|
+
readonly noUi: boolean;
|
|
168
|
+
readonly thinkingLevel?: CliAgentThinkingLevel;
|
|
169
|
+
}): Array<string> {
|
|
170
|
+
const argumentsList = ['agent', 'exec', '--agent', options.agentPath, '--message', options.message];
|
|
171
|
+
|
|
172
|
+
if (options.harness) {
|
|
173
|
+
argumentsList.push('--harness', options.harness);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (options.model) {
|
|
177
|
+
argumentsList.push('--model', options.model);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (options.noUi) {
|
|
181
|
+
argumentsList.push('--no-ui');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (options.thinkingLevel) {
|
|
185
|
+
argumentsList.push('--thinking-level', options.thinkingLevel);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (options.allowCredits) {
|
|
189
|
+
argumentsList.push('--allow-credits');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (options.context?.trim()) {
|
|
193
|
+
argumentsList.push('--context', options.context.trim());
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return argumentsList;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Creates the stable temporary path used when `CliAgent` is initialized from in-memory Book source.
|
|
201
|
+
*
|
|
202
|
+
* @private internal utility of `CliAgent`
|
|
203
|
+
*/
|
|
204
|
+
function createCliAgentTemporaryBookPath(resolvedSource: ResolvedBookNodeAgentSource): string {
|
|
205
|
+
const safeAgentName = normalizeCliAgentFileSegment(resolvedSource.agentName);
|
|
206
|
+
const uniqueSuffix = `${Date.now().toString(36)}-${process.pid.toString(36)}`;
|
|
207
|
+
|
|
208
|
+
return resolvePromptbookTemporaryPath(
|
|
209
|
+
resolvedSource.currentWorkingDirectory,
|
|
210
|
+
'book-3.0',
|
|
211
|
+
'cli-agent',
|
|
212
|
+
`${safeAgentName || 'agent'}-${uniqueSuffix}.book`,
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Keeps in-memory Book source readable when persisted for the CLI wrapper.
|
|
218
|
+
*
|
|
219
|
+
* @private internal utility of `CliAgent`
|
|
220
|
+
*/
|
|
221
|
+
function normalizeCliAgentBookSource(agentSource: string): string {
|
|
222
|
+
return agentSource.endsWith('\n') ? agentSource : `${agentSource}\n`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Normalizes one filename segment used in temporary agent-book paths.
|
|
227
|
+
*
|
|
228
|
+
* @private internal utility of `CliAgent`
|
|
229
|
+
*/
|
|
230
|
+
function normalizeCliAgentFileSegment(value: string): string {
|
|
231
|
+
return value
|
|
232
|
+
.trim()
|
|
233
|
+
.toLowerCase()
|
|
234
|
+
.replace(/[^a-z0-9._-]+/gu, '-')
|
|
235
|
+
.replace(/^[._-]+|[._-]+$/gu, '');
|
|
236
|
+
}
|