@promptbook/cli 0.114.0-35 → 0.114.0-39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/agents/default/.core/adam.book +33 -0
  2. package/apps/agents-server/package.json +1 -1
  3. package/apps/agents-server/scripts/build-agents-server.js +4 -0
  4. package/apps/agents-server/scripts/build-e2e.js +1 -1
  5. package/apps/agents-server/src/app/swagger/SwaggerPageClient.tsx +35 -19
  6. package/apps/agents-server/src/types/swagger-ui-dist.d.ts +5 -0
  7. package/apps/agents-server/src/utils/agentReferenceResolver/AgentReferenceResolutionIssue.ts +1 -69
  8. package/apps/agents-server/src/utils/agentReferenceResolver/extractAgentReferenceTokens.ts +1 -61
  9. package/apps/agents-server/src/utils/explicitFromCommitment.ts +1 -130
  10. package/apps/agents-server/src/utils/resolveInheritedAgentSource.ts +32 -817
  11. package/esm/index.es.js +1431 -128
  12. package/esm/index.es.js.map +1 -1
  13. package/esm/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +2 -1
  14. package/esm/scripts/run-codex-prompts/common/resolveCoderAgent.d.ts +11 -0
  15. package/esm/scripts/run-codex-prompts/git/commitInitializedAgentBooks.d.ts +5 -0
  16. package/esm/scripts/run-codex-prompts/main/resolvePromptRunner.d.ts +5 -8
  17. package/esm/scripts/run-codex-prompts/main/runPromptRound.d.ts +2 -4
  18. package/esm/scripts/run-codex-prompts/prompts/buildPromptRunTraceContent.d.ts +5 -17
  19. package/esm/scripts/run-codex-prompts/prompts/buildPromptStatusDetails.d.ts +3 -15
  20. package/esm/scripts/run-codex-prompts/prompts/formatRunnerSignature.d.ts +14 -1
  21. package/esm/scripts/run-codex-prompts/prompts/markPromptFailed.d.ts +2 -9
  22. package/esm/src/book-2.0/agent-source/AgentReferenceResolutionIssue.d.ts +45 -0
  23. package/esm/src/book-2.0/agent-source/createAgentModelRequirements.deduplication.test.d.ts +1 -0
  24. package/esm/src/book-2.0/agent-source/deduplicateSystemMessage.d.ts +14 -0
  25. package/esm/src/book-2.0/agent-source/deduplicateSystemMessage.test.d.ts +1 -0
  26. package/esm/src/book-2.0/agent-source/explicitFromCommitment.d.ts +62 -0
  27. package/esm/src/book-2.0/agent-source/extractAgentReferenceTokens.d.ts +32 -0
  28. package/esm/src/book-2.0/agent-source/resolveInheritedAgentSource.d.ts +73 -0
  29. package/esm/src/cli/$initializePromptbookCliProgram.d.ts +8 -0
  30. package/esm/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +1 -0
  31. package/esm/src/cli/cli-commands/common/LocalAgentBookCollection.d.ts +46 -0
  32. package/esm/src/cli/cli-commands/common/createLocalAgentReferenceResolver.d.ts +8 -0
  33. package/esm/src/cli/cli-commands/common/ensureAdamAgentBook.d.ts +12 -0
  34. package/esm/src/cli/cli-commands/common/resolveBundledAgentBookPath.d.ts +6 -0
  35. package/esm/src/cli/cli-commands/common/resolveLocalAgentSource.d.ts +19 -0
  36. package/esm/src/version.d.ts +1 -1
  37. package/package.json +2 -3
  38. package/src/book-2.0/agent-source/AgentReferenceResolutionIssue.ts +75 -0
  39. package/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.ts +3 -2
  40. package/src/book-2.0/agent-source/deduplicateSystemMessage.ts +327 -0
  41. package/src/book-2.0/agent-source/explicitFromCommitment.ts +132 -0
  42. package/src/book-2.0/agent-source/extractAgentReferenceTokens.ts +65 -0
  43. package/src/book-2.0/agent-source/resolveInheritedAgentSource.ts +841 -0
  44. package/src/cli/$initializePromptbookCliProgram.ts +87 -0
  45. package/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.ts +2 -28
  46. package/src/cli/cli-commands/coder/init.ts +3 -1
  47. package/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.ts +5 -0
  48. package/src/cli/cli-commands/coder/list.ts +5 -3
  49. package/src/cli/cli-commands/coder/printInitializationSummary.ts +6 -0
  50. package/src/cli/cli-commands/coder/run.ts +4 -1
  51. package/src/cli/cli-commands/coder/server.ts +2 -1
  52. package/src/cli/cli-commands/common/LocalAgentBookCollection.ts +220 -0
  53. package/src/cli/cli-commands/common/createLocalAgentReferenceResolver.ts +62 -0
  54. package/src/cli/cli-commands/common/ensureAdamAgentBook.ts +40 -0
  55. package/src/cli/cli-commands/common/resolveBundledAgentBookPath.ts +38 -0
  56. package/src/cli/cli-commands/common/resolveLocalAgentSource.ts +127 -0
  57. package/src/cli/promptbookCli.ts +2 -87
  58. package/src/other/templates/getTemplatesPipelineCollection.ts +612 -944
  59. package/src/version.ts +2 -2
  60. package/src/versions.txt +4 -0
  61. package/umd/index.umd.js +1431 -128
  62. package/umd/index.umd.js.map +1 -1
  63. package/umd/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +2 -1
  64. package/umd/scripts/run-codex-prompts/common/resolveCoderAgent.d.ts +11 -0
  65. package/umd/scripts/run-codex-prompts/git/commitInitializedAgentBooks.d.ts +5 -0
  66. package/umd/scripts/run-codex-prompts/main/resolvePromptRunner.d.ts +5 -8
  67. package/umd/scripts/run-codex-prompts/main/runPromptRound.d.ts +2 -4
  68. package/umd/scripts/run-codex-prompts/prompts/buildPromptRunTraceContent.d.ts +5 -17
  69. package/umd/scripts/run-codex-prompts/prompts/buildPromptStatusDetails.d.ts +3 -15
  70. package/umd/scripts/run-codex-prompts/prompts/formatRunnerSignature.d.ts +14 -1
  71. package/umd/scripts/run-codex-prompts/prompts/markPromptFailed.d.ts +2 -9
  72. package/umd/src/book-2.0/agent-source/AgentReferenceResolutionIssue.d.ts +45 -0
  73. package/umd/src/book-2.0/agent-source/createAgentModelRequirements.deduplication.test.d.ts +1 -0
  74. package/umd/src/book-2.0/agent-source/deduplicateSystemMessage.d.ts +14 -0
  75. package/umd/src/book-2.0/agent-source/deduplicateSystemMessage.test.d.ts +1 -0
  76. package/umd/src/book-2.0/agent-source/explicitFromCommitment.d.ts +62 -0
  77. package/umd/src/book-2.0/agent-source/extractAgentReferenceTokens.d.ts +32 -0
  78. package/umd/src/book-2.0/agent-source/resolveInheritedAgentSource.d.ts +73 -0
  79. package/umd/src/cli/$initializePromptbookCliProgram.d.ts +8 -0
  80. package/umd/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +1 -0
  81. package/umd/src/cli/cli-commands/common/LocalAgentBookCollection.d.ts +46 -0
  82. package/umd/src/cli/cli-commands/common/createLocalAgentReferenceResolver.d.ts +8 -0
  83. package/umd/src/cli/cli-commands/common/ensureAdamAgentBook.d.ts +12 -0
  84. package/umd/src/cli/cli-commands/common/resolveBundledAgentBookPath.d.ts +6 -0
  85. package/umd/src/cli/cli-commands/common/resolveLocalAgentSource.d.ts +19 -0
  86. package/umd/src/version.d.ts +1 -1
@@ -0,0 +1,127 @@
1
+ import { dirname } from 'path';
2
+ import { spaceTrim } from 'spacetrim';
3
+ import type { AgentReferenceResolver } from '../../../book-2.0/agent-source/AgentReferenceResolver';
4
+ import { getEffectiveExplicitFromCommitment } from '../../../book-2.0/agent-source/explicitFromCommitment';
5
+ import { parseAgentSourceWithCommitments } from '../../../book-2.0/agent-source/parseAgentSourceWithCommitments';
6
+ import { parseAgentSource } from '../../../book-2.0/agent-source/parseAgentSource';
7
+ import { isPseudoAgentUrl } from '../../../book-2.0/agent-source/pseudoAgentReferences';
8
+ import { resolveInheritedAgentSource } from '../../../book-2.0/agent-source/resolveInheritedAgentSource';
9
+ import type { string_book } from '../../../book-2.0/agent-source/string_book';
10
+ import { DEFAULT_MAX_RECURSION } from '../../../config';
11
+ import { ParseError } from '../../../errors/ParseError';
12
+ import { createLocalAgentReferenceResolver } from './createLocalAgentReferenceResolver';
13
+ import { LocalAgentBookCollection, type LocalAgentBook } from './LocalAgentBookCollection';
14
+
15
+ /**
16
+ * Resolved source together with the profile resolver used when compiling TEAM commitments.
17
+ *
18
+ * @private internal type of CLI agent resolution
19
+ */
20
+ export type ResolvedLocalAgentSource = {
21
+ readonly agentSource: string_book;
22
+ readonly agentReferenceResolver: AgentReferenceResolver;
23
+ /** Newly created books which the coder may include in its initialization commit. */
24
+ readonly createdAgentBookPaths: ReadonlyArray<string>;
25
+ };
26
+
27
+ /**
28
+ * Applies the shared Agent Server inheritance rules to a repository's local and remote books.
29
+ *
30
+ * @private internal utility of CLI agent resolution
31
+ */
32
+ export async function resolveLocalAgentSource(
33
+ agentBookPath: string,
34
+ currentWorkingDirectory: string,
35
+ ): Promise<ResolvedLocalAgentSource> {
36
+ const collection = new LocalAgentBookCollection(dirname(agentBookPath), currentWorkingDirectory);
37
+ await collection.initialize();
38
+ const primaryBook = await collection.readBook(agentBookPath);
39
+ const adamAgentUrl = collection.getAdamAgentUrl();
40
+
41
+ /** Resolves each dependency with its own location and the current inheritance stack. */
42
+ async function resolveBook(
43
+ book: LocalAgentBook,
44
+ inheritancePath: ReadonlyArray<string> = [],
45
+ ): Promise<string_book> {
46
+ if (inheritancePath.length > DEFAULT_MAX_RECURSION) {
47
+ throw new ParseError(
48
+ spaceTrim(
49
+ `Agent inheritance exceeds **${DEFAULT_MAX_RECURSION}** levels at \`${
50
+ book.filePath || book.url
51
+ }\`.`,
52
+ ),
53
+ );
54
+ }
55
+ const agentReferenceResolver = createLocalAgentReferenceResolver(collection, book);
56
+ const source = await resolveBookCommitmentReferences(book.source, agentReferenceResolver);
57
+ return resolveInheritedAgentSource(source, {
58
+ adamAgentUrl,
59
+ currentAgentUrl: book.url,
60
+ inheritancePath,
61
+ agentSourceImporter: async (url, context) =>
62
+ resolveBook(await collection.getBook(url), context.importAgentOptions.inheritancePath),
63
+ });
64
+ }
65
+
66
+ return {
67
+ agentSource: await resolveBook(primaryBook),
68
+ agentReferenceResolver: {
69
+ ...createLocalAgentReferenceResolver(collection, primaryBook),
70
+ resolveTeammateProfile: async (url) => {
71
+ if (isPseudoAgentUrl(url)) {
72
+ return null;
73
+ }
74
+ const book = await collection.getBook(url);
75
+ const parsedSource = parseAgentSource(await resolveBook(book));
76
+ return {
77
+ agentName: book.profile.agentName,
78
+ personaDescription: parsedSource.personaDescription,
79
+ };
80
+ },
81
+ },
82
+ createdAgentBookPaths: collection.createdAgentBookPaths,
83
+ };
84
+ }
85
+
86
+ /**
87
+ * Resolves reference blocks before embedding dependencies so inherited TEAM paths keep their original directory.
88
+ * Parser-provided locations keep examples, unknown commitments and ordinary prose untouched.
89
+ */
90
+ async function resolveBookCommitmentReferences(
91
+ source: string_book,
92
+ resolver: AgentReferenceResolver,
93
+ ): Promise<string_book> {
94
+ const parsedSource = parseAgentSourceWithCommitments(source);
95
+ const lines = source.split(/\r?\n/);
96
+ const commitmentStartLines = [...parsedSource.commitments, ...(parsedSource.unknownCommitments || [])]
97
+ .map((commitment) => commitment.lineNumber - 1)
98
+ .sort((left, right) => left - right);
99
+ const effectiveFrom = getEffectiveExplicitFromCommitment(source);
100
+
101
+ for (const commitment of [...parsedSource.commitments].reverse()) {
102
+ if (!['FROM', 'IMPORT', 'IMPORTS', 'TEAM'].includes(commitment.type)) {
103
+ continue;
104
+ }
105
+ const startLine = commitment.lineNumber - 1;
106
+ if (commitment.type === 'FROM' && effectiveFrom?.lineIndex !== startLine) {
107
+ continue;
108
+ }
109
+ let endLine = commitmentStartLines.find((lineNumber) => lineNumber > startLine) ?? lines.length;
110
+ // A horizontal rule also terminates a commitment before the next registered keyword.
111
+ for (let lineIndex = startLine + 1; lineIndex < endLine; lineIndex++) {
112
+ if (/^\s*(?:-{3,}|\*{3,}|_{3,})\s*$/.test(lines[lineIndex] || '')) {
113
+ endLine = lineIndex;
114
+ break;
115
+ }
116
+ }
117
+ const content = await resolver.resolveCommitmentContent(commitment.type, commitment.content);
118
+ const commitmentType = commitment.type === 'IMPORTS' ? 'IMPORT' : commitment.type;
119
+ const replacement = content.trim()
120
+ ? `${commitmentType} ${content}\n`
121
+ : commitmentType === 'FROM'
122
+ ? 'FROM @Null\n'
123
+ : '';
124
+ lines.splice(startLine, endLine - startLine, ...replacement.split('\n'));
125
+ }
126
+ return lines.join('\n') as string_book;
127
+ }
@@ -1,54 +1,12 @@
1
1
  import colors from 'colors';
2
2
  import commander from 'commander';
3
3
  import { spaceTrim } from 'spacetrim';
4
- import { CLAIM } from '../config';
5
4
  import { EnvironmentMismatchError } from '../errors/EnvironmentMismatchError';
6
5
  import { $isRunningInNode } from '../utils/environment/$isRunningInNode';
7
6
  import { PROMPTBOOK_ENGINE_VERSION } from '../version';
8
- import { $initializeAboutCommand } from './cli-commands/about';
9
- import { $initializeAgentCommand } from './cli-commands/agent';
10
- import { $initializeAgentFolderCommand } from './cli-commands/agent-folder';
11
- import { $initializeAgentsServerCommand } from './cli-commands/agents-server';
12
- import { $initializeCoderCommand } from './cli-commands/coder';
13
- import { $initializeHelloCommand } from './cli-commands/hello';
14
- import { $initializeListModelsCommand } from './cli-commands/list-models';
15
- import { $initializeListScrapersCommand } from './cli-commands/list-scrapers';
16
- import { $initializeLoginCommand } from './cli-commands/login';
17
- import { $initializeMakeCommand } from './cli-commands/make';
18
- import { $initializePrettifyCommand } from './cli-commands/prettify';
19
- import { $initializeRunCommand } from './cli-commands/run';
20
- import { $initializeStartAgentsServerCommand } from './cli-commands/start-agents-server';
21
- import { $initializeStartPipelinesServerCommand } from './cli-commands/start-pipelines-server';
22
- import { $initializeTestCommand } from './cli-commands/test-command';
23
- import { $addGlobalOptionsToCommand } from './common/$addGlobalOptionsToCommand';
24
- import { $deprecateCliCommand } from './common/$deprecateCliCommand';
7
+ import { $initializePromptbookCliProgram } from './$initializePromptbookCliProgram';
25
8
  import { $reportMissingCliSubcommand } from './common/$requireCliSubcommand';
26
9
 
27
- /**
28
- * Shared deprecation text for top-level CLI commands backed by the old pipeline system.
29
- */
30
- const OLD_PIPELINE_SYSTEM_DEPRECATION_MESSAGE = 'This command is part of the old pipeline system.';
31
-
32
- /**
33
- * Shared deprecation text for top-level CLI commands backed by the old pre-agent system.
34
- */
35
- const OLD_SYSTEM_DEPRECATION_MESSAGE = 'This command is part of the old system.';
36
-
37
- /**
38
- * Deprecation guidance for top-level `ptbk` commands that remain for compatibility.
39
- */
40
- const DEPRECATED_TOP_LEVEL_COMMAND_MESSAGES: Readonly<Record<string, string>> = {
41
- run: OLD_PIPELINE_SYSTEM_DEPRECATION_MESSAGE,
42
- login: OLD_PIPELINE_SYSTEM_DEPRECATION_MESSAGE,
43
- make: OLD_PIPELINE_SYSTEM_DEPRECATION_MESSAGE,
44
- prettify: OLD_PIPELINE_SYSTEM_DEPRECATION_MESSAGE,
45
- test: OLD_PIPELINE_SYSTEM_DEPRECATION_MESSAGE,
46
- 'list-models': OLD_SYSTEM_DEPRECATION_MESSAGE,
47
- 'list-scrapers': OLD_SYSTEM_DEPRECATION_MESSAGE,
48
- 'start-agents-server': 'Use `ptbk agents-server start` instead.',
49
- 'start-pipelines-server': OLD_PIPELINE_SYSTEM_DEPRECATION_MESSAGE,
50
- };
51
-
52
10
  /**
53
11
  * Raw top-level CLI arguments that print the Promptbook version.
54
12
  *
@@ -90,37 +48,7 @@ export async function promptbookCli(): Promise<void> {
90
48
  }
91
49
 
92
50
  const program = new commander.Command();
93
- program.name('promptbook');
94
- program.alias('ptbk');
95
-
96
- program.version(PROMPTBOOK_ENGINE_VERSION);
97
- program.description(CLAIM);
98
-
99
- // Note: These options are valid for all commands
100
-
101
- // Note: Commands are listed in the help in the order they are registered,
102
- // `coder` is the most used one so it goes first and the deprecated ones,
103
- // which `$deprecateTopLevelCommands` hides from the help entirely, go last
104
- $initializeCoderCommand(program);
105
- $initializeAgentCommand(program);
106
- $initializeAgentFolderCommand(program);
107
- $initializeAgentsServerCommand(program);
108
- $initializeAboutCommand(program);
109
- $initializeHelloCommand(program);
110
- $initializeRunCommand(program);
111
- $initializeLoginCommand(program);
112
- $initializeMakeCommand(program);
113
- $initializePrettifyCommand(program);
114
- $initializeTestCommand(program);
115
- $initializeListModelsCommand(program);
116
- $initializeListScrapersCommand(program);
117
- $initializeStartAgentsServerCommand(program);
118
- $initializeStartPipelinesServerCommand(program);
119
-
120
- $deprecateTopLevelCommands(program);
121
-
122
- // TODO: [🧠] Should it be here or not> $addGlobalOptionsToCommand(program);
123
- program.commands.forEach($addGlobalOptionsToCommand);
51
+ $initializePromptbookCliProgram(program);
124
52
 
125
53
  // Note: There is no default command, so `ptbk` without a subcommand asks for one
126
54
  // instead of running the deprecated `ptbk run`
@@ -142,19 +70,6 @@ function isTopLevelVersionRequested(commandLineArguments: ReadonlyArray<string>)
142
70
  return firstCommandLineArgument !== undefined && VERSION_OPTION_ARGUMENTS.has(firstCommandLineArgument);
143
71
  }
144
72
 
145
- /**
146
- * Marks each configured top-level legacy command as deprecated, which keeps it usable but takes it out of the help.
147
- */
148
- function $deprecateTopLevelCommands(program: commander.Command): void {
149
- for (const command of program.commands) {
150
- const deprecationMessage = DEPRECATED_TOP_LEVEL_COMMAND_MESSAGES[command.name()];
151
-
152
- if (deprecationMessage !== undefined) {
153
- $deprecateCliCommand(command, deprecationMessage);
154
- }
155
- }
156
- }
157
-
158
73
  // Note: [🟡] Code for CLI program [promptbookCli](src/cli/promptbookCli.ts) should never be published outside of `@promptbook/cli`
159
74
  // TODO: [🥠] Do not export, its just for CLI script
160
75
  // TODO: [🕌] When more functionalities, rename