@promptbook/components 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.
- package/esm/index.es.js +242 -3
- package/esm/index.es.js.map +1 -1
- package/esm/src/book-2.0/agent-source/AgentReferenceResolutionIssue.d.ts +45 -0
- package/esm/src/book-2.0/agent-source/createAgentModelRequirements.deduplication.test.d.ts +1 -0
- package/esm/src/book-2.0/agent-source/deduplicateSystemMessage.d.ts +14 -0
- package/esm/src/book-2.0/agent-source/deduplicateSystemMessage.test.d.ts +1 -0
- package/esm/src/book-2.0/agent-source/explicitFromCommitment.d.ts +62 -0
- package/esm/src/book-2.0/agent-source/extractAgentReferenceTokens.d.ts +32 -0
- package/esm/src/book-2.0/agent-source/resolveInheritedAgentSource.d.ts +73 -0
- package/esm/src/cli/$initializePromptbookCliProgram.d.ts +8 -0
- package/esm/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +1 -0
- package/esm/src/cli/cli-commands/common/LocalAgentBookCollection.d.ts +46 -0
- package/esm/src/cli/cli-commands/common/createLocalAgentReferenceResolver.d.ts +8 -0
- package/esm/src/cli/cli-commands/common/ensureAdamAgentBook.d.ts +12 -0
- package/esm/src/cli/cli-commands/common/resolveBundledAgentBookPath.d.ts +6 -0
- package/esm/src/cli/cli-commands/common/resolveLocalAgentSource.d.ts +19 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +242 -3
- package/umd/index.umd.js.map +1 -1
- package/umd/src/book-2.0/agent-source/AgentReferenceResolutionIssue.d.ts +45 -0
- package/umd/src/book-2.0/agent-source/createAgentModelRequirements.deduplication.test.d.ts +1 -0
- package/umd/src/book-2.0/agent-source/deduplicateSystemMessage.d.ts +14 -0
- package/umd/src/book-2.0/agent-source/deduplicateSystemMessage.test.d.ts +1 -0
- package/umd/src/book-2.0/agent-source/explicitFromCommitment.d.ts +62 -0
- package/umd/src/book-2.0/agent-source/extractAgentReferenceTokens.d.ts +32 -0
- package/umd/src/book-2.0/agent-source/resolveInheritedAgentSource.d.ts +73 -0
- package/umd/src/cli/$initializePromptbookCliProgram.d.ts +8 -0
- package/umd/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +1 -0
- package/umd/src/cli/cli-commands/common/LocalAgentBookCollection.d.ts +46 -0
- package/umd/src/cli/cli-commands/common/createLocalAgentReferenceResolver.d.ts +8 -0
- package/umd/src/cli/cli-commands/common/ensureAdamAgentBook.d.ts +12 -0
- package/umd/src/cli/cli-commands/common/resolveBundledAgentBookPath.d.ts +6 -0
- package/umd/src/cli/cli-commands/common/resolveLocalAgentSource.d.ts +19 -0
- package/umd/src/version.d.ts +1 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { BookCommitment } from '../../commitments/_base/BookCommitment';
|
|
2
|
+
import type { AgentReferenceResolver } from './AgentReferenceResolver';
|
|
3
|
+
/**
|
|
4
|
+
* Structured issue captured when compact agent reference resolution fails.
|
|
5
|
+
*
|
|
6
|
+
* @private internal utility of agent reference resolution
|
|
7
|
+
*/
|
|
8
|
+
export type AgentReferenceResolutionIssue = {
|
|
9
|
+
/**
|
|
10
|
+
* Commitment where the unresolved token appeared.
|
|
11
|
+
*/
|
|
12
|
+
readonly commitmentType: BookCommitment;
|
|
13
|
+
/**
|
|
14
|
+
* Original token text (for example `{Unknown Agent}` or `@UnknownAgent`).
|
|
15
|
+
*/
|
|
16
|
+
readonly token: string;
|
|
17
|
+
/**
|
|
18
|
+
* Normalized token payload used for lookup.
|
|
19
|
+
*/
|
|
20
|
+
readonly reference: string;
|
|
21
|
+
/**
|
|
22
|
+
* Human-readable explanation of why the token could not be resolved.
|
|
23
|
+
*/
|
|
24
|
+
readonly message: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Extension implemented by resolvers that can expose accumulated resolution issues.
|
|
28
|
+
*
|
|
29
|
+
* @private internal utility of agent reference resolution
|
|
30
|
+
*/
|
|
31
|
+
export type IssueTrackingAgentReferenceResolver = AgentReferenceResolver & {
|
|
32
|
+
/**
|
|
33
|
+
* Returns tracked issues and clears the internal queue.
|
|
34
|
+
*/
|
|
35
|
+
consumeResolutionIssues(): Array<AgentReferenceResolutionIssue>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Drains unresolved compact-reference issues from a resolver when supported.
|
|
39
|
+
*
|
|
40
|
+
* @param resolver - Resolver instance that may implement issue tracking.
|
|
41
|
+
* @returns Collected issues or an empty list.
|
|
42
|
+
*
|
|
43
|
+
* @private internal utility of agent reference resolution
|
|
44
|
+
*/
|
|
45
|
+
export declare function consumeAgentReferenceResolutionIssues(resolver?: AgentReferenceResolver): Array<AgentReferenceResolutionIssue>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes duplicated instructions from a generated system message
|
|
3
|
+
*
|
|
4
|
+
* Commitments are applied one by one, so a commitment used multiple times in one book repeats its whole
|
|
5
|
+
* section, including the shared guidance preamble. For example two `WRITING RULES` commitments emit the
|
|
6
|
+
* `## Writing rules` heading and its guidance paragraph twice. This function merges all sections sharing
|
|
7
|
+
* one heading into the position of their first occurrence and keeps every identical block only once.
|
|
8
|
+
*
|
|
9
|
+
* @param systemMessage The assembled system message which may contain repeated sections and blocks
|
|
10
|
+
* @returns The system message where each section heading and each identical block appears exactly once
|
|
11
|
+
*
|
|
12
|
+
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
13
|
+
*/
|
|
14
|
+
export declare function deduplicateSystemMessage(systemMessage: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { string_book } from './string_book';
|
|
2
|
+
/**
|
|
3
|
+
* One explicit `FROM` commitment written in a book.
|
|
4
|
+
*
|
|
5
|
+
* @private utility of Agents Server inheritance resolution
|
|
6
|
+
*/
|
|
7
|
+
export type ExplicitFromCommitment = {
|
|
8
|
+
/**
|
|
9
|
+
* Zero-based index of the line the commitment was found on, within the scanned lines.
|
|
10
|
+
*/
|
|
11
|
+
readonly lineIndex: number;
|
|
12
|
+
/**
|
|
13
|
+
* Trimmed commitment content, empty string for a blank `FROM`.
|
|
14
|
+
*/
|
|
15
|
+
readonly content: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Collects every explicit single-line `FROM` commitment of one book.
|
|
19
|
+
*
|
|
20
|
+
* This lightweight parser is intentionally limited to the subset needed by inheritance
|
|
21
|
+
* resolution so it stays safe to bundle into the Next.js proxy path.
|
|
22
|
+
*
|
|
23
|
+
* @param sourceLines - Book source already split into lines.
|
|
24
|
+
* @returns Found `FROM` commitments in source order, empty when the book declares no parent.
|
|
25
|
+
*
|
|
26
|
+
* @private utility of Agents Server inheritance resolution
|
|
27
|
+
*/
|
|
28
|
+
export declare function collectExplicitFromCommitments(sourceLines: ReadonlyArray<string>): ReadonlyArray<ExplicitFromCommitment>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the effective explicit `FROM` commitment of one book.
|
|
31
|
+
*
|
|
32
|
+
* A book may repeat `FROM`, in which case the last one wins and overrides every earlier one.
|
|
33
|
+
*
|
|
34
|
+
* @param agentSource - Raw book source.
|
|
35
|
+
* @returns The last explicit `FROM` commitment, or `undefined` when the book declares no parent.
|
|
36
|
+
*
|
|
37
|
+
* @private utility of Agents Server inheritance resolution
|
|
38
|
+
*/
|
|
39
|
+
export declare function getEffectiveExplicitFromCommitment(agentSource: string_book): ExplicitFromCommitment | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the effective explicit `FROM` commitment content of one book.
|
|
42
|
+
*
|
|
43
|
+
* A book may repeat `FROM`, in which case the last one wins and overrides every earlier one.
|
|
44
|
+
*
|
|
45
|
+
* @param agentSource - Raw book source.
|
|
46
|
+
* @returns Trimmed commitment content, empty string for a blank explicit `FROM`, or `undefined` when `FROM` is absent.
|
|
47
|
+
*
|
|
48
|
+
* @private utility of Agents Server inheritance resolution
|
|
49
|
+
*/
|
|
50
|
+
export declare function getExplicitFromCommitmentContent(agentSource: string_book): string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Returns true when one book declares no parent at all and therefore implicitly inherits from `@Adam`.
|
|
53
|
+
*
|
|
54
|
+
* Writing no `FROM` commitment is equivalent to writing `FROM @Adam`, so only an explicit
|
|
55
|
+
* `FROM @Null` / `FROM {Void}` turns the inheritance off.
|
|
56
|
+
*
|
|
57
|
+
* @param agentSource - Raw book source.
|
|
58
|
+
* @returns True when the implicit `@Adam` ancestor applies to this book.
|
|
59
|
+
*
|
|
60
|
+
* @private utility of Agents Server inheritance resolution
|
|
61
|
+
*/
|
|
62
|
+
export declare function isImplicitAdamInheritance(agentSource: string_book): boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matched compact agent reference token inside commitment content.
|
|
3
|
+
*
|
|
4
|
+
* @private internal utility of agent reference resolution
|
|
5
|
+
*/
|
|
6
|
+
export type AgentReferenceTokenMatch = {
|
|
7
|
+
/**
|
|
8
|
+
* Original token text, for example `{Agent Name}` or `@AgentId`.
|
|
9
|
+
*/
|
|
10
|
+
readonly token: string;
|
|
11
|
+
/**
|
|
12
|
+
* Token payload used for lookup.
|
|
13
|
+
*/
|
|
14
|
+
readonly reference: string;
|
|
15
|
+
/**
|
|
16
|
+
* Zero-based character offset of `token` in the scanned content.
|
|
17
|
+
*/
|
|
18
|
+
readonly index: number;
|
|
19
|
+
/**
|
|
20
|
+
* Length of `token` in characters.
|
|
21
|
+
*/
|
|
22
|
+
readonly length: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Extracts compact agent-reference tokens from commitment content.
|
|
26
|
+
*
|
|
27
|
+
* @param content - Commitment content to inspect.
|
|
28
|
+
* @returns Matched compact reference tokens.
|
|
29
|
+
*
|
|
30
|
+
* @private internal utility of agent reference resolution
|
|
31
|
+
*/
|
|
32
|
+
export declare function extractAgentReferenceTokens(content: string): Array<AgentReferenceTokenMatch>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { string_agent_url } from '../../types/string_agent_url';
|
|
2
|
+
import type { string_book } from './string_book';
|
|
3
|
+
import type { AgentReferenceResolver } from './AgentReferenceResolver';
|
|
4
|
+
/**
|
|
5
|
+
* Shared options for resolving one agent source with inheritance and imports applied.
|
|
6
|
+
*
|
|
7
|
+
* @private internal utility of agent source resolution
|
|
8
|
+
*/
|
|
9
|
+
export type ResolveInheritedAgentSourceOptions = {
|
|
10
|
+
/** Current recursion depth, forwarded to the source importer. */
|
|
11
|
+
readonly recursionLevel?: number;
|
|
12
|
+
/**
|
|
13
|
+
* The URL of the Adam agent to use as the default ancestor
|
|
14
|
+
*
|
|
15
|
+
* @default 'https://core.ptbk.io/agents/adam'
|
|
16
|
+
*/
|
|
17
|
+
readonly adamAgentUrl?: string_agent_url;
|
|
18
|
+
/**
|
|
19
|
+
* Custom resolver used to expand compact agent references.
|
|
20
|
+
*/
|
|
21
|
+
readonly agentReferenceResolver?: AgentReferenceResolver;
|
|
22
|
+
/**
|
|
23
|
+
* Canonical URL of the currently resolved agent.
|
|
24
|
+
*/
|
|
25
|
+
readonly currentAgentUrl?: string_agent_url;
|
|
26
|
+
/**
|
|
27
|
+
* Additional equivalent URLs that should be treated as the current agent while detecting cycles.
|
|
28
|
+
*/
|
|
29
|
+
readonly currentAgentAliases?: ReadonlyArray<string_agent_url>;
|
|
30
|
+
/**
|
|
31
|
+
* Already visited agent URLs in the current resolution stack.
|
|
32
|
+
*/
|
|
33
|
+
readonly inheritancePath?: ReadonlyArray<string_agent_url>;
|
|
34
|
+
/**
|
|
35
|
+
* Source importer supplied by the host application.
|
|
36
|
+
*/
|
|
37
|
+
readonly agentSourceImporter: AgentSourceImporter;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Context passed to a custom agent source importer.
|
|
41
|
+
*
|
|
42
|
+
* @private internal utility of agent source resolution
|
|
43
|
+
*/
|
|
44
|
+
export type AgentSourceImporterContext = {
|
|
45
|
+
/**
|
|
46
|
+
* Commitment that requested the imported source.
|
|
47
|
+
*/
|
|
48
|
+
readonly commitmentType: 'FROM' | 'IMPORT';
|
|
49
|
+
/**
|
|
50
|
+
* Import options propagated from the current resolution pass.
|
|
51
|
+
*/
|
|
52
|
+
readonly importAgentOptions: {
|
|
53
|
+
readonly recursionLevel?: number;
|
|
54
|
+
readonly inheritancePath?: ReadonlyArray<string_agent_url>;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Loads and recursively resolves one referenced agent using the caller's transport.
|
|
59
|
+
*
|
|
60
|
+
* @private internal utility of agent source resolution
|
|
61
|
+
*/
|
|
62
|
+
export type AgentSourceImporter = (agentUrl: string_agent_url, context: AgentSourceImporterContext) => Promise<string_book>;
|
|
63
|
+
/**
|
|
64
|
+
* Resolves agent source with inheritance (FROM commitment)
|
|
65
|
+
*
|
|
66
|
+
* It recursively fetches the parent agent source and merges it with the current source.
|
|
67
|
+
*
|
|
68
|
+
* @param agentSource The initial agent source
|
|
69
|
+
* @returns The resolved agent source with inheritance applied
|
|
70
|
+
*
|
|
71
|
+
* @private internal utility of agent source resolution
|
|
72
|
+
*/
|
|
73
|
+
export declare function resolveInheritedAgentSource(agentSource: string_book, options: ResolveInheritedAgentSourceOptions): Promise<string_book>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* Registers the CLI commands on a fresh Commander program without parsing arguments or running an action.
|
|
4
|
+
* Tests can configure output and exit handling before registration, so subcommands inherit those settings.
|
|
5
|
+
*
|
|
6
|
+
* @private internal utility of `promptbookCli`
|
|
7
|
+
*/
|
|
8
|
+
export declare function $initializePromptbookCliProgram(program: Command): void;
|
|
@@ -10,6 +10,7 @@ export type CoderInitializationSummary = {
|
|
|
10
10
|
readonly promptsDoneDirectoryStatus: InitializationStatus;
|
|
11
11
|
readonly promptsTemplatesDirectoryStatus: InitializationStatus;
|
|
12
12
|
readonly agentsDirectoryStatus: InitializationStatus;
|
|
13
|
+
readonly adamAgentFileStatus: InitializationStatus;
|
|
13
14
|
readonly envFileStatus: InitializationStatus;
|
|
14
15
|
readonly gitignoreFileStatus: InitializationStatus;
|
|
15
16
|
readonly packageJsonFileStatus: InitializationStatus;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { string_book } from '../../../book-2.0/agent-source/string_book';
|
|
2
|
+
import type { TeammateProfile } from '../../../book-2.0/agent-source/TeammateProfileResolver';
|
|
3
|
+
/**
|
|
4
|
+
* A book's source and identity, retaining its location for nested relative references.
|
|
5
|
+
*
|
|
6
|
+
* @private internal type of CLI agent resolution
|
|
7
|
+
*/
|
|
8
|
+
export type LocalAgentBook = {
|
|
9
|
+
readonly url: string;
|
|
10
|
+
readonly filePath?: string;
|
|
11
|
+
readonly source: string_book;
|
|
12
|
+
readonly profile: TeammateProfile;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Reads repository books and indexes their first-line names for CLI reference resolution.
|
|
16
|
+
*
|
|
17
|
+
* @private internal utility of CLI agent resolution
|
|
18
|
+
*/
|
|
19
|
+
export declare class LocalAgentBookCollection {
|
|
20
|
+
private readonly agentDirectoryPath;
|
|
21
|
+
private readonly currentWorkingDirectory;
|
|
22
|
+
private readonly booksByUrl;
|
|
23
|
+
private readonly booksByName;
|
|
24
|
+
/** Stable default ancestor selected from the initial repository scan. */
|
|
25
|
+
private adamAgentUrl;
|
|
26
|
+
/** Files initialized by this collection, for the coder's normal commit handling. */
|
|
27
|
+
readonly createdAgentBookPaths: string[];
|
|
28
|
+
/** Creates a collection rooted at the primary book's directory. */
|
|
29
|
+
constructor(agentDirectoryPath: string, currentWorkingDirectory: string);
|
|
30
|
+
/** Discovers nested books, including the hidden `.core` directory. */
|
|
31
|
+
initialize(): Promise<void>;
|
|
32
|
+
/** Identifies the default ancestor without creating an unused book for FROM null/void. */
|
|
33
|
+
getAdamAgentUrl(): string;
|
|
34
|
+
/** Resolves a unique first-line name, refusing ambiguous matches. */
|
|
35
|
+
findByName(name: string): LocalAgentBook;
|
|
36
|
+
/** Resolves a name, a path relative to its declaring book, or a path relative to the CLI cwd. */
|
|
37
|
+
resolveReference(reference: string, declaringBook: LocalAgentBook): Promise<string>;
|
|
38
|
+
/** Reads a local book once, canonicalizing symlinks so aliases cannot bypass cycle detection. */
|
|
39
|
+
readBook(filePath: string): Promise<LocalAgentBook>;
|
|
40
|
+
/** Loads a referenced remote book, while keeping local identifiers entirely inside the collection. */
|
|
41
|
+
getBook(url: string): Promise<LocalAgentBook>;
|
|
42
|
+
/** Adds a book under its normalized first-line name and preserves the display name for TEAM. */
|
|
43
|
+
private registerBook;
|
|
44
|
+
/** Walks real directories in deterministic order without following directory symlink loops. */
|
|
45
|
+
private readDirectory;
|
|
46
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AgentReferenceResolver } from '../../../book-2.0/agent-source/AgentReferenceResolver';
|
|
2
|
+
import type { LocalAgentBook, LocalAgentBookCollection } from './LocalAgentBookCollection';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a resolver scoped to the book which declares each reference.
|
|
5
|
+
*
|
|
6
|
+
* @private internal utility of CLI agent resolution
|
|
7
|
+
*/
|
|
8
|
+
export declare function createLocalAgentReferenceResolver(collection: LocalAgentBookCollection, declaringBook: LocalAgentBook): AgentReferenceResolver;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adam's location relative to a directory of local agents.
|
|
3
|
+
*
|
|
4
|
+
* @private internal constant of CLI agent initialization
|
|
5
|
+
*/
|
|
6
|
+
export declare const ADAM_AGENT_BOOK_RELATIVE_PATH = ".core/adam.book";
|
|
7
|
+
/**
|
|
8
|
+
* Creates the same Adam book used by the Agent Server without overwriting a project-owned book.
|
|
9
|
+
*
|
|
10
|
+
* @private internal utility of CLI agent initialization
|
|
11
|
+
*/
|
|
12
|
+
export declare function ensureAdamAgentBook(agentDirectoryPath: string): Promise<'created' | 'unchanged'>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AgentReferenceResolver } from '../../../book-2.0/agent-source/AgentReferenceResolver';
|
|
2
|
+
import type { string_book } from '../../../book-2.0/agent-source/string_book';
|
|
3
|
+
/**
|
|
4
|
+
* Resolved source together with the profile resolver used when compiling TEAM commitments.
|
|
5
|
+
*
|
|
6
|
+
* @private internal type of CLI agent resolution
|
|
7
|
+
*/
|
|
8
|
+
export type ResolvedLocalAgentSource = {
|
|
9
|
+
readonly agentSource: string_book;
|
|
10
|
+
readonly agentReferenceResolver: AgentReferenceResolver;
|
|
11
|
+
/** Newly created books which the coder may include in its initialization commit. */
|
|
12
|
+
readonly createdAgentBookPaths: ReadonlyArray<string>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Applies the shared Agent Server inheritance rules to a repository's local and remote books.
|
|
16
|
+
*
|
|
17
|
+
* @private internal utility of CLI agent resolution
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveLocalAgentSource(agentBookPath: string, currentWorkingDirectory: string): Promise<ResolvedLocalAgentSource>;
|
package/esm/src/version.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
|
|
|
15
15
|
export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
|
|
16
16
|
/**
|
|
17
17
|
* Represents the version string of the Promptbook engine.
|
|
18
|
-
* It follows semantic versioning (e.g., `0.114.0-
|
|
18
|
+
* It follows semantic versioning (e.g., `0.114.0-38`).
|
|
19
19
|
*
|
|
20
20
|
* @generated
|
|
21
21
|
*/
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* @generated
|
|
34
34
|
* @see https://github.com/webgptorg/promptbook
|
|
35
35
|
*/
|
|
36
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.114.0-
|
|
36
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.114.0-39';
|
|
37
37
|
/**
|
|
38
38
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
39
39
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -50484,6 +50484,245 @@
|
|
|
50484
50484
|
return Object.keys(rest).length > 0 ? rest : undefined;
|
|
50485
50485
|
}
|
|
50486
50486
|
|
|
50487
|
+
/**
|
|
50488
|
+
* Pattern matching a markdown section heading (`## Title`) that separates system-message sections
|
|
50489
|
+
*
|
|
50490
|
+
* @private internal constant of `deduplicateSystemMessage`
|
|
50491
|
+
*/
|
|
50492
|
+
const SYSTEM_MESSAGE_SECTION_HEADING_PATTERN = /^##(?!#)\s*(.+?)\s*$/;
|
|
50493
|
+
/**
|
|
50494
|
+
* Pattern matching a fenced code block delimiter which suspends section and block splitting
|
|
50495
|
+
*
|
|
50496
|
+
* @private internal constant of `deduplicateSystemMessage`
|
|
50497
|
+
*/
|
|
50498
|
+
const CODE_FENCE_PATTERN = /^\s*(?:```|~~~)/;
|
|
50499
|
+
/**
|
|
50500
|
+
* Pattern matching a markdown list item which keeps merged bullet lists visually compact
|
|
50501
|
+
*
|
|
50502
|
+
* @private internal constant of `deduplicateSystemMessage`
|
|
50503
|
+
*/
|
|
50504
|
+
const LIST_ITEM_PATTERN = /^\s*(?:[-*+]|\d+[.)])\s/;
|
|
50505
|
+
/**
|
|
50506
|
+
* Removes duplicated instructions from a generated system message
|
|
50507
|
+
*
|
|
50508
|
+
* Commitments are applied one by one, so a commitment used multiple times in one book repeats its whole
|
|
50509
|
+
* section, including the shared guidance preamble. For example two `WRITING RULES` commitments emit the
|
|
50510
|
+
* `## Writing rules` heading and its guidance paragraph twice. This function merges all sections sharing
|
|
50511
|
+
* one heading into the position of their first occurrence and keeps every identical block only once.
|
|
50512
|
+
*
|
|
50513
|
+
* @param systemMessage The assembled system message which may contain repeated sections and blocks
|
|
50514
|
+
* @returns The system message where each section heading and each identical block appears exactly once
|
|
50515
|
+
*
|
|
50516
|
+
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
50517
|
+
*/
|
|
50518
|
+
function deduplicateSystemMessage(systemMessage) {
|
|
50519
|
+
if (!systemMessage.trim()) {
|
|
50520
|
+
return systemMessage;
|
|
50521
|
+
}
|
|
50522
|
+
return splitSystemMessageIntoRegions(systemMessage)
|
|
50523
|
+
.reduce(mergeRegionSharingHeading, [])
|
|
50524
|
+
.map(removeDuplicateBlocksFromRegion)
|
|
50525
|
+
.map(renderRegion)
|
|
50526
|
+
.filter((renderedRegion) => renderedRegion !== '')
|
|
50527
|
+
.join('\n\n');
|
|
50528
|
+
}
|
|
50529
|
+
/**
|
|
50530
|
+
* Splits the system message into the intro region and one region per `## Title` section
|
|
50531
|
+
*
|
|
50532
|
+
* @param systemMessage The system message to split
|
|
50533
|
+
* @returns Regions in their original order, without empty ones
|
|
50534
|
+
*
|
|
50535
|
+
* @private internal utility of `deduplicateSystemMessage`
|
|
50536
|
+
*/
|
|
50537
|
+
function splitSystemMessageIntoRegions(systemMessage) {
|
|
50538
|
+
const regions = [];
|
|
50539
|
+
let headingLine = null;
|
|
50540
|
+
let bodyLines = [];
|
|
50541
|
+
let isInsideCodeFence = false;
|
|
50542
|
+
for (const line of systemMessage.split(/\r?\n/)) {
|
|
50543
|
+
if (CODE_FENCE_PATTERN.test(line)) {
|
|
50544
|
+
isInsideCodeFence = !isInsideCodeFence;
|
|
50545
|
+
}
|
|
50546
|
+
if (isInsideCodeFence || !SYSTEM_MESSAGE_SECTION_HEADING_PATTERN.test(line)) {
|
|
50547
|
+
bodyLines.push(line);
|
|
50548
|
+
continue;
|
|
50549
|
+
}
|
|
50550
|
+
regions.push(createRegion(headingLine, bodyLines));
|
|
50551
|
+
headingLine = line;
|
|
50552
|
+
bodyLines = [];
|
|
50553
|
+
}
|
|
50554
|
+
regions.push(createRegion(headingLine, bodyLines));
|
|
50555
|
+
return regions.filter((region) => region.headingLine !== null || region.blocks.length > 0);
|
|
50556
|
+
}
|
|
50557
|
+
/**
|
|
50558
|
+
* Creates one region from its heading line and its raw body lines
|
|
50559
|
+
*
|
|
50560
|
+
* @param headingLine The original `## Title` line, or `null` for the intro before the first heading
|
|
50561
|
+
* @param bodyLines The raw lines following the heading line
|
|
50562
|
+
* @returns The region with its body already split into blocks
|
|
50563
|
+
*
|
|
50564
|
+
* @private internal utility of `splitSystemMessageIntoRegions`
|
|
50565
|
+
*/
|
|
50566
|
+
function createRegion(headingLine, bodyLines) {
|
|
50567
|
+
return {
|
|
50568
|
+
titleKey: headingLine === null ? null : normalizeSectionTitle(headingLine),
|
|
50569
|
+
headingLine,
|
|
50570
|
+
isBodySeparatedByBlankLine: bodyLines[0] !== undefined && bodyLines[0].trim() === '',
|
|
50571
|
+
blocks: splitBodyIntoBlocks(bodyLines),
|
|
50572
|
+
};
|
|
50573
|
+
}
|
|
50574
|
+
/**
|
|
50575
|
+
* Normalizes a heading line into a key usable for matching sections which belong together
|
|
50576
|
+
*
|
|
50577
|
+
* @param headingLine The original `## Title` line
|
|
50578
|
+
* @returns Lowercased title without the markdown heading prefix
|
|
50579
|
+
*
|
|
50580
|
+
* @private internal utility of `createRegion`
|
|
50581
|
+
*/
|
|
50582
|
+
function normalizeSectionTitle(headingLine) {
|
|
50583
|
+
var _a, _b;
|
|
50584
|
+
return ((_b = (_a = SYSTEM_MESSAGE_SECTION_HEADING_PATTERN.exec(headingLine)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : headingLine).toLowerCase();
|
|
50585
|
+
}
|
|
50586
|
+
/**
|
|
50587
|
+
* Splits raw body lines into blocks separated by blank lines while keeping fenced code blocks intact
|
|
50588
|
+
*
|
|
50589
|
+
* @param bodyLines The raw lines of one region body
|
|
50590
|
+
* @returns Non-empty blocks in their original order
|
|
50591
|
+
*
|
|
50592
|
+
* @private internal utility of `createRegion`
|
|
50593
|
+
*/
|
|
50594
|
+
function splitBodyIntoBlocks(bodyLines) {
|
|
50595
|
+
const blockTexts = [];
|
|
50596
|
+
let blockLines = [];
|
|
50597
|
+
let isInsideCodeFence = false;
|
|
50598
|
+
for (const line of bodyLines) {
|
|
50599
|
+
if (CODE_FENCE_PATTERN.test(line)) {
|
|
50600
|
+
isInsideCodeFence = !isInsideCodeFence;
|
|
50601
|
+
}
|
|
50602
|
+
if (!isInsideCodeFence && line.trim() === '') {
|
|
50603
|
+
blockTexts.push(blockLines.join('\n'));
|
|
50604
|
+
blockLines = [];
|
|
50605
|
+
continue;
|
|
50606
|
+
}
|
|
50607
|
+
blockLines.push(line);
|
|
50608
|
+
}
|
|
50609
|
+
blockTexts.push(blockLines.join('\n'));
|
|
50610
|
+
return blockTexts
|
|
50611
|
+
.filter((blockText) => blockText.trim() !== '')
|
|
50612
|
+
.map((blockText) => ({ text: blockText, isOpeningMergedSection: false }));
|
|
50613
|
+
}
|
|
50614
|
+
/**
|
|
50615
|
+
* Appends one region to the already merged regions, merging it into an earlier region with the same heading
|
|
50616
|
+
*
|
|
50617
|
+
* @param mergedRegions Regions merged so far, used as the reducer accumulator
|
|
50618
|
+
* @param region The next region in original order
|
|
50619
|
+
* @returns The accumulator with the region either appended or merged into its earlier twin
|
|
50620
|
+
*
|
|
50621
|
+
* @private internal utility of `deduplicateSystemMessage`
|
|
50622
|
+
*/
|
|
50623
|
+
function mergeRegionSharingHeading(mergedRegions, region) {
|
|
50624
|
+
const existingRegionIndex = mergedRegions.findIndex((mergedRegion) => region.titleKey !== null && mergedRegion.titleKey === region.titleKey);
|
|
50625
|
+
if (existingRegionIndex === -1) {
|
|
50626
|
+
return [...mergedRegions, region];
|
|
50627
|
+
}
|
|
50628
|
+
return mergedRegions.map((mergedRegion, index) => index !== existingRegionIndex
|
|
50629
|
+
? mergedRegion
|
|
50630
|
+
: {
|
|
50631
|
+
...mergedRegion,
|
|
50632
|
+
blocks: [...mergedRegion.blocks, ...markFirstBlockAsOpeningMergedSection(region.blocks)],
|
|
50633
|
+
});
|
|
50634
|
+
}
|
|
50635
|
+
/**
|
|
50636
|
+
* Marks the first block of a merged section occurrence so the merge seam can be rendered as one list
|
|
50637
|
+
*
|
|
50638
|
+
* @param blocks The blocks of the section occurrence being merged into an earlier section
|
|
50639
|
+
* @returns The same blocks with the first one marked as opening a merged section
|
|
50640
|
+
*
|
|
50641
|
+
* @private internal utility of `mergeRegionSharingHeading`
|
|
50642
|
+
*/
|
|
50643
|
+
function markFirstBlockAsOpeningMergedSection(blocks) {
|
|
50644
|
+
return blocks.map((block, index) => (index === 0 ? { ...block, isOpeningMergedSection: true } : block));
|
|
50645
|
+
}
|
|
50646
|
+
/**
|
|
50647
|
+
* Keeps only the first occurrence of every identical block inside one region
|
|
50648
|
+
*
|
|
50649
|
+
* @param region The region whose blocks may repeat
|
|
50650
|
+
* @returns The region without repeated blocks
|
|
50651
|
+
*
|
|
50652
|
+
* @private internal utility of `deduplicateSystemMessage`
|
|
50653
|
+
*/
|
|
50654
|
+
function removeDuplicateBlocksFromRegion(region) {
|
|
50655
|
+
const alreadyRenderedTexts = new Set();
|
|
50656
|
+
const uniqueBlocks = [];
|
|
50657
|
+
let isMergeSeamPending = false;
|
|
50658
|
+
for (const block of region.blocks) {
|
|
50659
|
+
if (alreadyRenderedTexts.has(block.text)) {
|
|
50660
|
+
// Note: A removed block must still hand its merge seam over to the next block which survives
|
|
50661
|
+
isMergeSeamPending = isMergeSeamPending || block.isOpeningMergedSection;
|
|
50662
|
+
continue;
|
|
50663
|
+
}
|
|
50664
|
+
alreadyRenderedTexts.add(block.text);
|
|
50665
|
+
uniqueBlocks.push({
|
|
50666
|
+
text: block.text,
|
|
50667
|
+
isOpeningMergedSection: block.isOpeningMergedSection || isMergeSeamPending,
|
|
50668
|
+
});
|
|
50669
|
+
isMergeSeamPending = false;
|
|
50670
|
+
}
|
|
50671
|
+
return { ...region, blocks: uniqueBlocks };
|
|
50672
|
+
}
|
|
50673
|
+
/**
|
|
50674
|
+
* Renders one region back into its markdown representation
|
|
50675
|
+
*
|
|
50676
|
+
* @param region The region to render
|
|
50677
|
+
* @returns The heading line together with its joined blocks
|
|
50678
|
+
*
|
|
50679
|
+
* @private internal utility of `deduplicateSystemMessage`
|
|
50680
|
+
*/
|
|
50681
|
+
function renderRegion(region) {
|
|
50682
|
+
const body = joinBlocks(region.blocks);
|
|
50683
|
+
if (region.headingLine === null) {
|
|
50684
|
+
return body;
|
|
50685
|
+
}
|
|
50686
|
+
if (body === '') {
|
|
50687
|
+
return region.headingLine;
|
|
50688
|
+
}
|
|
50689
|
+
return `${region.headingLine}${region.isBodySeparatedByBlankLine ? '\n\n' : '\n'}${body}`;
|
|
50690
|
+
}
|
|
50691
|
+
/**
|
|
50692
|
+
* Joins blocks of one region back together
|
|
50693
|
+
*
|
|
50694
|
+
* @param blocks The blocks to join in their original order
|
|
50695
|
+
* @returns The joined body of one region
|
|
50696
|
+
*
|
|
50697
|
+
* @private internal utility of `renderRegion`
|
|
50698
|
+
*/
|
|
50699
|
+
function joinBlocks(blocks) {
|
|
50700
|
+
return blocks
|
|
50701
|
+
.map((block, index) => index === 0 ? block.text : `${createBlockSeparator(blocks[index - 1], block)}${block.text}`)
|
|
50702
|
+
.join('');
|
|
50703
|
+
}
|
|
50704
|
+
/**
|
|
50705
|
+
* Chooses the separator between two neighboring blocks
|
|
50706
|
+
*
|
|
50707
|
+
* Blocks are normally separated by a blank line, exactly as they were written. Only where two sections were
|
|
50708
|
+
* merged together their lists are joined into one compact list instead of two separate ones.
|
|
50709
|
+
*
|
|
50710
|
+
* @param previousBlock The block rendered before the separator
|
|
50711
|
+
* @param nextBlock The block rendered after the separator
|
|
50712
|
+
* @returns Either a single or a double newline
|
|
50713
|
+
*
|
|
50714
|
+
* @private internal utility of `joinBlocks`
|
|
50715
|
+
*/
|
|
50716
|
+
function createBlockSeparator(previousBlock, nextBlock) {
|
|
50717
|
+
if (!nextBlock.isOpeningMergedSection) {
|
|
50718
|
+
return '\n\n';
|
|
50719
|
+
}
|
|
50720
|
+
const previousBlockLines = previousBlock.text.split('\n');
|
|
50721
|
+
const isListContinuing = LIST_ITEM_PATTERN.test(previousBlockLines[previousBlockLines.length - 1]) &&
|
|
50722
|
+
LIST_ITEM_PATTERN.test(nextBlock.text.split('\n')[0]);
|
|
50723
|
+
return isListContinuing ? '\n' : '\n\n';
|
|
50724
|
+
}
|
|
50725
|
+
|
|
50487
50726
|
/**
|
|
50488
50727
|
* Removes single-hash comment lines (`# Comment`) from a system message
|
|
50489
50728
|
* This is used to clean up the final system message before sending it to the AI model
|
|
@@ -50557,14 +50796,14 @@
|
|
|
50557
50796
|
* Performs the final system-message cleanup pass after all other augmentation steps are complete.
|
|
50558
50797
|
*
|
|
50559
50798
|
* @param requirements - Fully built requirements before final cleanup.
|
|
50560
|
-
* @returns Requirements with comment lines removed
|
|
50799
|
+
* @returns Requirements with comment lines removed and repeated instructions deduplicated in the final system message.
|
|
50561
50800
|
*
|
|
50562
50801
|
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
50563
50802
|
*/
|
|
50564
50803
|
function finalizeRequirements(requirements) {
|
|
50565
50804
|
return {
|
|
50566
50805
|
...requirements,
|
|
50567
|
-
systemMessage: removeCommentsFromSystemMessage(requirements.systemMessage),
|
|
50806
|
+
systemMessage: deduplicateSystemMessage(removeCommentsFromSystemMessage(requirements.systemMessage)),
|
|
50568
50807
|
};
|
|
50569
50808
|
}
|
|
50570
50809
|
|