@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.
- package/agents/default/.core/adam.book +33 -0
- package/apps/agents-server/package.json +1 -1
- package/apps/agents-server/scripts/build-agents-server.js +4 -0
- package/apps/agents-server/scripts/build-e2e.js +1 -1
- package/apps/agents-server/src/app/swagger/SwaggerPageClient.tsx +35 -19
- package/apps/agents-server/src/types/swagger-ui-dist.d.ts +5 -0
- package/apps/agents-server/src/utils/agentReferenceResolver/AgentReferenceResolutionIssue.ts +1 -69
- package/apps/agents-server/src/utils/agentReferenceResolver/extractAgentReferenceTokens.ts +1 -61
- package/apps/agents-server/src/utils/explicitFromCommitment.ts +1 -130
- package/apps/agents-server/src/utils/resolveInheritedAgentSource.ts +32 -817
- package/esm/index.es.js +1431 -128
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +2 -1
- package/esm/scripts/run-codex-prompts/common/resolveCoderAgent.d.ts +11 -0
- package/esm/scripts/run-codex-prompts/git/commitInitializedAgentBooks.d.ts +5 -0
- package/esm/scripts/run-codex-prompts/main/resolvePromptRunner.d.ts +5 -8
- package/esm/scripts/run-codex-prompts/main/runPromptRound.d.ts +2 -4
- package/esm/scripts/run-codex-prompts/prompts/buildPromptRunTraceContent.d.ts +5 -17
- package/esm/scripts/run-codex-prompts/prompts/buildPromptStatusDetails.d.ts +3 -15
- package/esm/scripts/run-codex-prompts/prompts/formatRunnerSignature.d.ts +14 -1
- package/esm/scripts/run-codex-prompts/prompts/markPromptFailed.d.ts +2 -9
- 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 +2 -3
- package/src/book-2.0/agent-source/AgentReferenceResolutionIssue.ts +75 -0
- package/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.ts +3 -2
- package/src/book-2.0/agent-source/deduplicateSystemMessage.ts +327 -0
- package/src/book-2.0/agent-source/explicitFromCommitment.ts +132 -0
- package/src/book-2.0/agent-source/extractAgentReferenceTokens.ts +65 -0
- package/src/book-2.0/agent-source/resolveInheritedAgentSource.ts +841 -0
- package/src/cli/$initializePromptbookCliProgram.ts +87 -0
- package/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.ts +2 -28
- package/src/cli/cli-commands/coder/init.ts +3 -1
- package/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.ts +5 -0
- package/src/cli/cli-commands/coder/list.ts +5 -3
- package/src/cli/cli-commands/coder/printInitializationSummary.ts +6 -0
- package/src/cli/cli-commands/coder/run.ts +4 -1
- package/src/cli/cli-commands/coder/server.ts +2 -1
- package/src/cli/cli-commands/common/LocalAgentBookCollection.ts +220 -0
- package/src/cli/cli-commands/common/createLocalAgentReferenceResolver.ts +62 -0
- package/src/cli/cli-commands/common/ensureAdamAgentBook.ts +40 -0
- package/src/cli/cli-commands/common/resolveBundledAgentBookPath.ts +38 -0
- package/src/cli/cli-commands/common/resolveLocalAgentSource.ts +127 -0
- package/src/cli/promptbookCli.ts +2 -87
- package/src/other/templates/getTemplatesPipelineCollection.ts +612 -944
- package/src/version.ts +2 -2
- package/src/versions.txt +4 -0
- package/umd/index.umd.js +1431 -128
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +2 -1
- package/umd/scripts/run-codex-prompts/common/resolveCoderAgent.d.ts +11 -0
- package/umd/scripts/run-codex-prompts/git/commitInitializedAgentBooks.d.ts +5 -0
- package/umd/scripts/run-codex-prompts/main/resolvePromptRunner.d.ts +5 -8
- package/umd/scripts/run-codex-prompts/main/runPromptRound.d.ts +2 -4
- package/umd/scripts/run-codex-prompts/prompts/buildPromptRunTraceContent.d.ts +5 -17
- package/umd/scripts/run-codex-prompts/prompts/buildPromptStatusDetails.d.ts +3 -15
- package/umd/scripts/run-codex-prompts/prompts/formatRunnerSignature.d.ts +14 -1
- package/umd/scripts/run-codex-prompts/prompts/markPromptFailed.d.ts +2 -9
- 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,33 @@
|
|
|
1
|
+
Adam
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
META VISIBILITY PRIVATE
|
|
5
|
+
|
|
6
|
+
FROM @Void
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
META COLOR #ff0b0bff
|
|
10
|
+
META FONT Playfair Display, sans-serif
|
|
11
|
+
PERSONA You are a helpful, honest, and intelligent AI assistant. Your goal is to provide accurate, clear, and concise responses while being friendly and engaging. Think step-by-step before answering complex questions.
|
|
12
|
+
RULE If you're unsure about something, say so and offer to look it up or clarify.
|
|
13
|
+
RULE You can use Markdown formatting in the messages like **bold** or *italic*
|
|
14
|
+
RULE You can use Markdown code blocks if needed
|
|
15
|
+
|
|
16
|
+
For example:
|
|
17
|
+
|
|
18
|
+
```javascript
|
|
19
|
+
console.log('Hello');
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
CLOSED
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"test": "npm run test-e2e",
|
|
9
9
|
"test-e2e": "node ./scripts/run-e2e-tests.js",
|
|
10
10
|
"pretest-build": "node ./scripts/kill-port.js 4021 4440",
|
|
11
|
-
"test-build": "npm run build",
|
|
11
|
+
"test-build": "npm run build -- --no-sentry-upload",
|
|
12
12
|
"pretest-e2e": "node ./scripts/kill-port.js 4021 4440",
|
|
13
13
|
"build": "node ./scripts/build-agents-server.js",
|
|
14
14
|
"build-e2e": "node ./scripts/build-e2e.js",
|
|
@@ -25,6 +25,8 @@ const AGENTS_SERVER_BUILD_MAX_OLD_SPACE_MIB = 8192;
|
|
|
25
25
|
* lint command has already completed successfully. The optional `--no-homepage-prerender`
|
|
26
26
|
* argument is used by builds whose caller starts the very same production server right
|
|
27
27
|
* afterwards, which makes the extra prerender server a repetition of that work.
|
|
28
|
+
* Test builds pass `--no-sentry-upload` to avoid publishing source maps and creating
|
|
29
|
+
* temporary upload bundles with credentials from the local `.env` file.
|
|
28
30
|
*/
|
|
29
31
|
function buildAgentsServer() {
|
|
30
32
|
const nextBuildArguments = [
|
|
@@ -44,6 +46,8 @@ function buildAgentsServer() {
|
|
|
44
46
|
// the build process which spawned it. The same merge is done for the CLI-owned
|
|
45
47
|
// production build in `src/cli/cli-commands/agents-server/buildAgentsServer/runNextBuild.ts`.
|
|
46
48
|
NODE_OPTIONS: mergeNodeOptionsWithHeapSize(process.env.NODE_OPTIONS, AGENTS_SERVER_BUILD_MAX_OLD_SPACE_MIB),
|
|
49
|
+
// An empty value also prevents Next.js from loading an upload token from `.env`.
|
|
50
|
+
...(process.argv.includes('--no-sentry-upload') ? { SENTRY_AUTH_TOKEN: '' } : {}),
|
|
47
51
|
});
|
|
48
52
|
|
|
49
53
|
if (!process.argv.includes('--no-homepage-prerender')) {
|
|
@@ -17,7 +17,7 @@ const APP_ROOT = path.resolve(__dirname, '..');
|
|
|
17
17
|
* is compiled, and the tests open the homepage against that very same server, so the snapshot would
|
|
18
18
|
* only repeat work the tests already do.
|
|
19
19
|
*/
|
|
20
|
-
const E2E_BUILD_ARGUMENTS = ['--no-homepage-prerender'];
|
|
20
|
+
const E2E_BUILD_ARGUMENTS = ['--no-homepage-prerender', '--no-sentry-upload'];
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Builds the production bundle used by the Agents Server E2E tests.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import 'swagger-ui-
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import 'swagger-ui-dist/swagger-ui.css';
|
|
5
5
|
import { SwaggerApiKeysPanel } from './SwaggerApiKeysPanel';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -18,26 +18,43 @@ type SwaggerPageClientProps = {
|
|
|
18
18
|
* Renders the runtime-generated Swagger UI and the compact API-key helper panel.
|
|
19
19
|
*/
|
|
20
20
|
export function SwaggerPageClient({ isAdmin }: SwaggerPageClientProps) {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
defaultModelsExpandDepth?: number;
|
|
25
|
-
docExpansion?: 'list' | 'full' | 'none';
|
|
26
|
-
}> | null>(null);
|
|
21
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
22
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
23
|
+
const [hasLoadError, setHasLoadError] = useState(false);
|
|
27
24
|
|
|
28
25
|
useEffect(() => {
|
|
29
26
|
let isMounted = true;
|
|
27
|
+
const container = containerRef.current;
|
|
30
28
|
|
|
31
29
|
void (async () => {
|
|
32
|
-
|
|
30
|
+
try {
|
|
31
|
+
// Import the browser bundle directly; the package entry point also imports Node.js helpers.
|
|
32
|
+
const { default: SwaggerUIBundle } = await import('swagger-ui-dist/swagger-ui-bundle.js');
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
if (!isMounted || !container) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
SwaggerUIBundle({
|
|
39
|
+
domNode: container,
|
|
40
|
+
url: '/openapi.json',
|
|
41
|
+
persistAuthorization: true,
|
|
42
|
+
defaultModelsExpandDepth: -1,
|
|
43
|
+
docExpansion: 'list',
|
|
44
|
+
});
|
|
45
|
+
setIsLoading(false);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (isMounted) {
|
|
48
|
+
console.error('Failed to load Swagger UI:', error);
|
|
49
|
+
setHasLoadError(true);
|
|
50
|
+
setIsLoading(false);
|
|
51
|
+
}
|
|
36
52
|
}
|
|
37
53
|
})();
|
|
38
54
|
|
|
39
55
|
return () => {
|
|
40
56
|
isMounted = false;
|
|
57
|
+
container?.replaceChildren();
|
|
41
58
|
};
|
|
42
59
|
}, []);
|
|
43
60
|
|
|
@@ -47,16 +64,15 @@ export function SwaggerPageClient({ isAdmin }: SwaggerPageClientProps) {
|
|
|
47
64
|
<SwaggerApiKeysPanel isAdmin={isAdmin} />
|
|
48
65
|
</div>
|
|
49
66
|
<div className="swagger-container bg-white min-h-screen">
|
|
50
|
-
{
|
|
51
|
-
<SwaggerUI
|
|
52
|
-
url="/openapi.json"
|
|
53
|
-
persistAuthorization
|
|
54
|
-
defaultModelsExpandDepth={-1}
|
|
55
|
-
docExpansion="list"
|
|
56
|
-
/>
|
|
57
|
-
) : (
|
|
67
|
+
{isLoading && (
|
|
58
68
|
<div className="mx-auto max-w-7xl px-4 py-10 text-sm text-slate-500">Loading Swagger UI...</div>
|
|
59
69
|
)}
|
|
70
|
+
{hasLoadError && (
|
|
71
|
+
<div role="alert" className="mx-auto max-w-7xl px-4 py-10 text-sm text-red-600">
|
|
72
|
+
Failed to load Swagger UI. Please reload the page.
|
|
73
|
+
</div>
|
|
74
|
+
)}
|
|
75
|
+
<div ref={containerRef} />
|
|
60
76
|
</div>
|
|
61
77
|
</div>
|
|
62
78
|
);
|
package/apps/agents-server/src/utils/agentReferenceResolver/AgentReferenceResolutionIssue.ts
CHANGED
|
@@ -1,69 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { AgentReferenceResolver } from '../../../../../src/book-2.0/agent-source/AgentReferenceResolver';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Structured issue captured when compact agent reference resolution fails.
|
|
6
|
-
*/
|
|
7
|
-
export type AgentReferenceResolutionIssue = {
|
|
8
|
-
/**
|
|
9
|
-
* Commitment where the unresolved token appeared.
|
|
10
|
-
*/
|
|
11
|
-
readonly commitmentType: BookCommitment;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Original token text (for example `{Unknown Agent}` or `@UnknownAgent`).
|
|
15
|
-
*/
|
|
16
|
-
readonly token: string;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Normalized token payload used for lookup.
|
|
20
|
-
*/
|
|
21
|
-
readonly reference: string;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Human-readable explanation of why the token could not be resolved.
|
|
25
|
-
*/
|
|
26
|
-
readonly message: string;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Extension implemented by resolvers that can expose accumulated resolution issues.
|
|
31
|
-
*/
|
|
32
|
-
export type IssueTrackingAgentReferenceResolver = AgentReferenceResolver & {
|
|
33
|
-
/**
|
|
34
|
-
* Returns tracked issues and clears the internal queue.
|
|
35
|
-
*/
|
|
36
|
-
consumeResolutionIssues(): Array<AgentReferenceResolutionIssue>;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Type guard for issue-tracking resolver implementations.
|
|
41
|
-
*
|
|
42
|
-
* @param resolver - Resolver instance to check.
|
|
43
|
-
* @returns True when the resolver provides `consumeResolutionIssues`.
|
|
44
|
-
*/
|
|
45
|
-
function isIssueTrackingAgentReferenceResolver(
|
|
46
|
-
resolver: AgentReferenceResolver,
|
|
47
|
-
): resolver is IssueTrackingAgentReferenceResolver {
|
|
48
|
-
return typeof (resolver as Partial<IssueTrackingAgentReferenceResolver>).consumeResolutionIssues === 'function';
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Drains unresolved compact-reference issues from a resolver when supported.
|
|
53
|
-
*
|
|
54
|
-
* @param resolver - Resolver instance that may implement issue tracking.
|
|
55
|
-
* @returns Collected issues or an empty list.
|
|
56
|
-
*/
|
|
57
|
-
export function consumeAgentReferenceResolutionIssues(
|
|
58
|
-
resolver?: AgentReferenceResolver,
|
|
59
|
-
): Array<AgentReferenceResolutionIssue> {
|
|
60
|
-
if (!resolver) {
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!isIssueTrackingAgentReferenceResolver(resolver)) {
|
|
65
|
-
return [];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return resolver.consumeResolutionIssues();
|
|
69
|
-
}
|
|
1
|
+
export * from '../../../../../src/book-2.0/agent-source/AgentReferenceResolutionIssue';
|
|
@@ -1,61 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Matched compact agent reference token inside commitment content.
|
|
3
|
-
*/
|
|
4
|
-
export type AgentReferenceTokenMatch = {
|
|
5
|
-
/**
|
|
6
|
-
* Original token text, for example `{Agent Name}` or `@AgentId`.
|
|
7
|
-
*/
|
|
8
|
-
readonly token: string;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Token payload used for lookup.
|
|
12
|
-
*/
|
|
13
|
-
readonly reference: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Zero-based character offset of `token` in the scanned content.
|
|
17
|
-
*/
|
|
18
|
-
readonly index: number;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Length of `token` in characters.
|
|
22
|
-
*/
|
|
23
|
-
readonly length: number;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Matches supported compact reference token syntaxes in commitment content.
|
|
28
|
-
*/
|
|
29
|
-
const AGENT_REFERENCE_TOKEN_REGEX = /(\{([^}]+)\}|@([A-Za-z0-9_-]+))/g;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Extracts compact agent-reference tokens from commitment content.
|
|
33
|
-
*
|
|
34
|
-
* @param content - Commitment content to inspect.
|
|
35
|
-
* @returns Matched compact reference tokens.
|
|
36
|
-
*/
|
|
37
|
-
export function extractAgentReferenceTokens(content: string): Array<AgentReferenceTokenMatch> {
|
|
38
|
-
const matches: Array<AgentReferenceTokenMatch> = [];
|
|
39
|
-
let match: RegExpExecArray | null;
|
|
40
|
-
|
|
41
|
-
AGENT_REFERENCE_TOKEN_REGEX.lastIndex = 0;
|
|
42
|
-
|
|
43
|
-
while ((match = AGENT_REFERENCE_TOKEN_REGEX.exec(content)) !== null) {
|
|
44
|
-
const token = match[1];
|
|
45
|
-
const reference = (match[2] ?? match[3] ?? '').trim();
|
|
46
|
-
const index = match.index;
|
|
47
|
-
|
|
48
|
-
if (!token || index === undefined) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
matches.push({
|
|
53
|
-
token,
|
|
54
|
-
reference,
|
|
55
|
-
index,
|
|
56
|
-
length: token.length,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return matches;
|
|
61
|
-
}
|
|
1
|
+
export * from '../../../../../src/book-2.0/agent-source/extractAgentReferenceTokens';
|
|
@@ -1,130 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Commitment keyword that declares the parent agent of one book.
|
|
5
|
-
*
|
|
6
|
-
* @private utility of Agents Server inheritance resolution
|
|
7
|
-
*/
|
|
8
|
-
const FROM_COMMITMENT_TYPE = 'FROM';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Matches one standalone `FROM` commitment line and captures its inline content.
|
|
12
|
-
*
|
|
13
|
-
* The Book parser accepts horizontal whitespace between a commitment keyword and its value, so inheritance resolution
|
|
14
|
-
* must do the same. Keeping this pattern here makes every server-side consumer agree on which `FROM` lines are real.
|
|
15
|
-
*
|
|
16
|
-
* @private utility of Agents Server inheritance resolution
|
|
17
|
-
*/
|
|
18
|
-
const FROM_COMMITMENT_LINE_PATTERN = new RegExp(`^${FROM_COMMITMENT_TYPE}(?:\\s+(.*))?$`);
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* One explicit `FROM` commitment written in a book.
|
|
22
|
-
*
|
|
23
|
-
* @private utility of Agents Server inheritance resolution
|
|
24
|
-
*/
|
|
25
|
-
export type ExplicitFromCommitment = {
|
|
26
|
-
/**
|
|
27
|
-
* Zero-based index of the line the commitment was found on, within the scanned lines.
|
|
28
|
-
*/
|
|
29
|
-
readonly lineIndex: number;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Trimmed commitment content, empty string for a blank `FROM`.
|
|
33
|
-
*/
|
|
34
|
-
readonly content: string;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Collects every explicit single-line `FROM` commitment of one book.
|
|
39
|
-
*
|
|
40
|
-
* This lightweight parser is intentionally limited to the subset needed by inheritance
|
|
41
|
-
* resolution so it stays safe to bundle into the Next.js proxy path.
|
|
42
|
-
*
|
|
43
|
-
* @param sourceLines - Book source already split into lines.
|
|
44
|
-
* @returns Found `FROM` commitments in source order, empty when the book declares no parent.
|
|
45
|
-
*
|
|
46
|
-
* @private utility of Agents Server inheritance resolution
|
|
47
|
-
*/
|
|
48
|
-
export function collectExplicitFromCommitments(
|
|
49
|
-
sourceLines: ReadonlyArray<string>,
|
|
50
|
-
): ReadonlyArray<ExplicitFromCommitment> {
|
|
51
|
-
const explicitFromCommitments: Array<ExplicitFromCommitment> = [];
|
|
52
|
-
let hasSeenTitle = false;
|
|
53
|
-
let isInsideCodeBlock = false;
|
|
54
|
-
|
|
55
|
-
for (let lineIndex = 0; lineIndex < sourceLines.length; lineIndex++) {
|
|
56
|
-
const trimmedLine = (sourceLines[lineIndex] || '').trim();
|
|
57
|
-
|
|
58
|
-
if (!hasSeenTitle) {
|
|
59
|
-
if (!trimmedLine) {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
hasSeenTitle = true;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (trimmedLine.startsWith('```')) {
|
|
68
|
-
isInsideCodeBlock = !isInsideCodeBlock;
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (isInsideCodeBlock) {
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const fromCommitmentMatch = FROM_COMMITMENT_LINE_PATTERN.exec(trimmedLine);
|
|
77
|
-
if (fromCommitmentMatch) {
|
|
78
|
-
explicitFromCommitments.push({
|
|
79
|
-
lineIndex,
|
|
80
|
-
content: (fromCommitmentMatch[1] || '').trim(),
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return explicitFromCommitments;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Returns the effective explicit `FROM` commitment of one book.
|
|
90
|
-
*
|
|
91
|
-
* A book may repeat `FROM`, in which case the last one wins and overrides every earlier one.
|
|
92
|
-
*
|
|
93
|
-
* @param agentSource - Raw book source.
|
|
94
|
-
* @returns The last explicit `FROM` commitment, or `undefined` when the book declares no parent.
|
|
95
|
-
*
|
|
96
|
-
* @private utility of Agents Server inheritance resolution
|
|
97
|
-
*/
|
|
98
|
-
export function getEffectiveExplicitFromCommitment(agentSource: string_book): ExplicitFromCommitment | undefined {
|
|
99
|
-
const explicitFromCommitments = collectExplicitFromCommitments(agentSource.split(/\r?\n/));
|
|
100
|
-
return explicitFromCommitments[explicitFromCommitments.length - 1];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Returns the effective explicit `FROM` commitment content of one book.
|
|
105
|
-
*
|
|
106
|
-
* A book may repeat `FROM`, in which case the last one wins and overrides every earlier one.
|
|
107
|
-
*
|
|
108
|
-
* @param agentSource - Raw book source.
|
|
109
|
-
* @returns Trimmed commitment content, empty string for a blank explicit `FROM`, or `undefined` when `FROM` is absent.
|
|
110
|
-
*
|
|
111
|
-
* @private utility of Agents Server inheritance resolution
|
|
112
|
-
*/
|
|
113
|
-
export function getExplicitFromCommitmentContent(agentSource: string_book): string | undefined {
|
|
114
|
-
return getEffectiveExplicitFromCommitment(agentSource)?.content;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Returns true when one book declares no parent at all and therefore implicitly inherits from `@Adam`.
|
|
119
|
-
*
|
|
120
|
-
* Writing no `FROM` commitment is equivalent to writing `FROM @Adam`, so only an explicit
|
|
121
|
-
* `FROM @Null` / `FROM {Void}` turns the inheritance off.
|
|
122
|
-
*
|
|
123
|
-
* @param agentSource - Raw book source.
|
|
124
|
-
* @returns True when the implicit `@Adam` ancestor applies to this book.
|
|
125
|
-
*
|
|
126
|
-
* @private utility of Agents Server inheritance resolution
|
|
127
|
-
*/
|
|
128
|
-
export function isImplicitAdamInheritance(agentSource: string_book): boolean {
|
|
129
|
-
return getExplicitFromCommitmentContent(agentSource) === undefined;
|
|
130
|
-
}
|
|
1
|
+
export * from '../../../../src/book-2.0/agent-source/explicitFromCommitment';
|