@promptbook/cli 0.112.0 → 0.113.0-0
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 +45 -29
- package/agents/default/developer.book +2 -1
- package/apps/agents-server/next.config.ts +21 -0
- package/apps/agents-server/src/app/admin/limits/LimitsClient.tsx +1 -1
- package/apps/agents-server/src/app/admin/update/UpdateClient.tsx +52 -33
- package/apps/agents-server/src/app/api/agent-folders/[folderId]/visibility/route.ts +19 -7
- package/apps/agents-server/src/app/api/agents/[agentName]/route.ts +8 -18
- package/apps/agents-server/src/app/api/internal/agent-runner-limits/route.ts +1 -1
- package/apps/agents-server/src/app/api/v1/agents/[agentId]/route.ts +13 -8
- package/apps/agents-server/src/components/AgentProfile/AgentCapabilityChips.tsx +39 -5
- package/apps/agents-server/src/components/Homepage/AgentCard.tsx +7 -1
- package/apps/agents-server/src/components/Homepage/AgentsList.tsx +3 -0
- package/apps/agents-server/src/components/Homepage/AgentsListHeader.tsx +41 -0
- package/apps/agents-server/src/components/Homepage/hiddenFolders.ts +104 -0
- package/apps/agents-server/src/components/Homepage/useAgentsListQueryState.ts +35 -0
- package/apps/agents-server/src/components/Homepage/useAgentsListState.ts +24 -4
- package/apps/agents-server/src/constants/serverLimits.ts +19 -0
- package/apps/agents-server/src/database/seedCoreAgents.ts +0 -2
- package/apps/agents-server/src/database/seedDefaultAgents.ts +0 -2
- package/apps/agents-server/src/tools/agent_progress.ts +4 -10
- package/apps/agents-server/src/utils/agentVisibility.ts +25 -62
- package/apps/agents-server/src/utils/createAgentWithDefaultVisibility.ts +3 -1
- package/apps/agents-server/src/utils/externalChatRunner/processExternalUserChatJob.ts +9 -17
- package/apps/agents-server/src/utils/localChatRunner/LocalUserChatJobMetadata.ts +15 -5
- package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +17 -26
- package/apps/agents-server/src/utils/serverLimits.ts +2 -0
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerCoreAgents.ts +2 -2
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerDefaultAgents.ts +1 -1
- package/apps/agents-server/src/utils/userChat/createUserChatHarnessProgressCard.ts +0 -6
- package/apps/agents-server/src/utils/userChat/createUserChatRunnerProgressCard.ts +0 -6
- package/apps/agents-server/src/utils/userChat/userChatMessageLifecycle.ts +69 -0
- package/apps/agents-server/src/utils/userChat/userChatProgressCard.ts +0 -6
- package/apps/agents-server/src/utils/vpsSelfUpdate.ts +138 -24
- package/esm/apps/agents-server/src/constants/serverLimits.d.ts +17 -0
- package/esm/index.es.js +581 -93
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-agent-messages/main/runMultipleAgentMessages.d.ts +1 -0
- package/esm/scripts/run-agent-messages/main/tickAgentMessages.d.ts +1 -0
- package/esm/src/_packages/core.index.d.ts +22 -0
- package/esm/src/_packages/types.index.d.ts +2 -0
- package/esm/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -0
- package/esm/src/book-2.0/agent-source/agentSourceVisibility.d.ts +97 -0
- package/esm/src/book-2.0/agent-source/agentSourceVisibility.test.d.ts +1 -0
- package/esm/src/book-components/BookEditor/BookEditorMonacoTokenization.d.ts +1 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +6 -0
- package/esm/src/collection/agent-collection/CreateAgentInput.d.ts +2 -1
- package/esm/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.d.ts +21 -1
- package/esm/src/commitments/META_VISIBILITY/META_VISIBILITY.d.ts +27 -0
- package/esm/src/commitments/index.d.ts +2 -1
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/_packages/core.index.ts +22 -0
- package/src/_packages/types.index.ts +2 -0
- package/src/book-2.0/agent-source/AgentBasicInformation.ts +2 -0
- package/src/book-2.0/agent-source/agentSourceVisibility.ts +214 -0
- package/src/book-2.0/agent-source/parseAgentSource/applyMetaCommitment.ts +17 -0
- package/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.ts +1 -0
- package/src/book-components/BookEditor/BookEditorMonacoTokenization.ts +11 -0
- package/src/book-components/BookEditor/useBookEditorMonacoLanguage.ts +7 -3
- package/src/cli/cli-commands/agents-server/buildAgentsServer.ts +144 -16
- package/src/cli/cli-commands/agents-server/startAgentsServer.ts +22 -2
- package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +1 -1
- package/src/cli/cli-commands/coder/run.ts +30 -0
- package/src/collection/agent-collection/CreateAgentInput.ts +10 -5
- package/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.ts +7 -3
- package/src/collection/agent-collection/constructors/agent-collection-in-supabase/createAgentPersistenceRecords.ts +7 -4
- package/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.ts +44 -8
- package/src/commitments/META_VISIBILITY/META_VISIBILITY.ts +78 -0
- package/src/commitments/index.ts +2 -0
- package/src/other/templates/getTemplatesPipelineCollection.ts +854 -692
- package/src/version.ts +2 -2
- package/src/versions.txt +1 -0
- package/umd/apps/agents-server/src/constants/serverLimits.d.ts +17 -0
- package/umd/index.umd.js +581 -93
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-agent-messages/main/runMultipleAgentMessages.d.ts +1 -0
- package/umd/scripts/run-agent-messages/main/tickAgentMessages.d.ts +1 -0
- package/umd/src/_packages/core.index.d.ts +22 -0
- package/umd/src/_packages/types.index.d.ts +2 -0
- package/umd/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -0
- package/umd/src/book-2.0/agent-source/agentSourceVisibility.d.ts +97 -0
- package/umd/src/book-2.0/agent-source/agentSourceVisibility.test.d.ts +1 -0
- package/umd/src/book-components/BookEditor/BookEditorMonacoTokenization.d.ts +1 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +6 -0
- package/umd/src/collection/agent-collection/CreateAgentInput.d.ts +2 -1
- package/umd/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.d.ts +21 -1
- package/umd/src/commitments/META_VISIBILITY/META_VISIBILITY.d.ts +27 -0
- package/umd/src/commitments/index.d.ts +2 -1
- package/umd/src/version.d.ts +1 -1
|
@@ -21,6 +21,16 @@ const AGENT_REFERENCE_AT_PATTERN = '(?<!\\S)@[A-Za-z0-9_-]+';
|
|
|
21
21
|
*/
|
|
22
22
|
const AGENT_REFERENCE_BRACED_PATTERN = '\\{[^{}\\r\\n]+\\}';
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Pattern matching plain inline `@` tokens, for example email addresses.
|
|
26
|
+
*
|
|
27
|
+
* Monaco tokenizes from the current offset, so `team@foo.bar` can otherwise reach
|
|
28
|
+
* the `@foo` suffix and look like a standalone compact reference.
|
|
29
|
+
*
|
|
30
|
+
* @private function of BookEditorMonaco
|
|
31
|
+
*/
|
|
32
|
+
const NON_AGENT_REFERENCE_INLINE_AT_TOKEN_REGEX = /[^\s{}]*[^\s@{}]@[^\s{}]+/;
|
|
33
|
+
|
|
24
34
|
/**
|
|
25
35
|
* Commitment types where compact agent references are supported.
|
|
26
36
|
*
|
|
@@ -334,6 +344,7 @@ export const BookEditorMonacoTokenization = {
|
|
|
334
344
|
AGENT_URL_REFERENCE_REGEX,
|
|
335
345
|
AGENT_REFERENCE_TOKEN_REGEX,
|
|
336
346
|
AGENT_REFERENCE_BRACED_REGEX,
|
|
347
|
+
NON_AGENT_REFERENCE_INLINE_AT_TOKEN_REGEX,
|
|
337
348
|
AGENT_REFERENCE_HIGHLIGHT_REGEXES,
|
|
338
349
|
extractAgentReferenceValue,
|
|
339
350
|
resolveAgentReferenceToUrl,
|
|
@@ -312,14 +312,17 @@ export function ensureBookEditorMonacoLanguage(
|
|
|
312
312
|
commitmentRegex,
|
|
313
313
|
);
|
|
314
314
|
|
|
315
|
-
const
|
|
315
|
+
const PARAMETER_REGEX = /@([a-zA-Z0-9_á-žÁ-Žč-řČ-Řš-žŠ-Žа-яА-ЯёЁ]+)/;
|
|
316
|
+
const NON_AGENT_REFERENCE_INLINE_AT_TOKEN_REGEX =
|
|
317
|
+
BookEditorMonacoTokenization.NON_AGENT_REFERENCE_INLINE_AT_TOKEN_REGEX;
|
|
316
318
|
|
|
317
319
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
318
320
|
const defaultBodyRules: any = [
|
|
319
321
|
[/^---[-]*$/, ''],
|
|
320
322
|
[CODE_BLOCK_FENCE_REGEX, 'code-block', '@codeblock'],
|
|
321
323
|
...commitmentTransitionRules,
|
|
322
|
-
[
|
|
324
|
+
[NON_AGENT_REFERENCE_INLINE_AT_TOKEN_REGEX, ''],
|
|
325
|
+
[PARAMETER_REGEX, 'parameter'],
|
|
323
326
|
[/\{[^}]+\}/, 'parameter'],
|
|
324
327
|
];
|
|
325
328
|
|
|
@@ -329,7 +332,8 @@ export function ensureBookEditorMonacoLanguage(
|
|
|
329
332
|
[CODE_BLOCK_FENCE_REGEX, 'code-block', '@codeblock'],
|
|
330
333
|
...commitmentTransitionRules,
|
|
331
334
|
...BookEditorMonacoTokenization.AGENT_REFERENCE_HIGHLIGHT_REGEXES.map((regex) => [regex, 'agent-reference']),
|
|
332
|
-
[
|
|
335
|
+
[NON_AGENT_REFERENCE_INLINE_AT_TOKEN_REGEX, ''],
|
|
336
|
+
[PARAMETER_REGEX, 'parameter'],
|
|
333
337
|
[/\{[^}]+\}/, 'parameter'],
|
|
334
338
|
];
|
|
335
339
|
|
|
@@ -45,6 +45,31 @@ const DEFAULT_AGENTS_SERVER_NEXT_DIST_DIRECTORY_NAME = '.next';
|
|
|
45
45
|
*/
|
|
46
46
|
const AGENTS_SERVER_BUILD_MAX_OLD_SPACE_MIB = 4096;
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Conservative Next.js build worker count used by CLI-owned Agents Server production builds.
|
|
50
|
+
*
|
|
51
|
+
* Standalone VPS self-updates build the replacement server while the current pm2 process is
|
|
52
|
+
* still serving traffic. Keeping Next's static workers serial avoids CPU-count-based memory
|
|
53
|
+
* spikes that can make the OS kill the build child with no normal exit code.
|
|
54
|
+
*
|
|
55
|
+
* @private internal constant of `ptbk agents-server`
|
|
56
|
+
*/
|
|
57
|
+
const AGENTS_SERVER_BUILD_WORKER_COUNT = 1;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Maximum attempts for a Next.js build that was killed by the operating system.
|
|
61
|
+
*
|
|
62
|
+
* @private internal constant of `ptbk agents-server`
|
|
63
|
+
*/
|
|
64
|
+
const AGENTS_SERVER_BUILD_MAX_ATTEMPTS = 2;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Signals that indicate the Next.js build may have been terminated by resource pressure.
|
|
68
|
+
*
|
|
69
|
+
* @private internal constant of `ptbk agents-server`
|
|
70
|
+
*/
|
|
71
|
+
const RETRYABLE_NEXT_BUILD_SIGNALS = new Set<NodeJS.Signals | null>(['SIGKILL', null]);
|
|
72
|
+
|
|
48
73
|
/**
|
|
49
74
|
* Environment variable passed to the bundled Next app so webpack can resolve dependencies
|
|
50
75
|
* installed beside `ptbk` even when the app sources are materialized into a project cache.
|
|
@@ -53,6 +78,13 @@ const AGENTS_SERVER_BUILD_MAX_OLD_SPACE_MIB = 4096;
|
|
|
53
78
|
*/
|
|
54
79
|
export const PTBK_AGENTS_SERVER_NODE_MODULES_PATH_ENV = 'PTBK_AGENTS_SERVER_NODE_MODULES_PATH';
|
|
55
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Environment variable consumed by `apps/agents-server/next.config.ts` to throttle build workers.
|
|
83
|
+
*
|
|
84
|
+
* @private internal constant of `ptbk agents-server`
|
|
85
|
+
*/
|
|
86
|
+
export const PTBK_AGENTS_SERVER_BUILD_WORKER_COUNT_ENV = 'PTBK_AGENTS_SERVER_BUILD_WORKER_COUNT';
|
|
87
|
+
|
|
56
88
|
/**
|
|
57
89
|
* Environment variable used only by the CLI-owned production build.
|
|
58
90
|
*
|
|
@@ -206,6 +238,16 @@ type AgentsServerBuildCacheOptions = {
|
|
|
206
238
|
readonly environment?: NodeJS.ProcessEnv;
|
|
207
239
|
};
|
|
208
240
|
|
|
241
|
+
/**
|
|
242
|
+
* Exit status reported by one spawned Next.js build child process.
|
|
243
|
+
*
|
|
244
|
+
* @private internal type of `ptbk agents-server`
|
|
245
|
+
*/
|
|
246
|
+
type NextBuildExitStatus = {
|
|
247
|
+
readonly code: number | null;
|
|
248
|
+
readonly signal: NodeJS.Signals | null;
|
|
249
|
+
};
|
|
250
|
+
|
|
209
251
|
/**
|
|
210
252
|
* Ensures that the local Agents Server production build exists and matches its source fingerprint.
|
|
211
253
|
*
|
|
@@ -358,6 +400,8 @@ export function createAgentsServerRuntimeEnvironment(
|
|
|
358
400
|
...environment,
|
|
359
401
|
NODE_PATH: mergeNodePath(nodeModulesPath, environment.NODE_PATH),
|
|
360
402
|
[PTBK_AGENTS_SERVER_NODE_MODULES_PATH_ENV]: nodeModulesPath,
|
|
403
|
+
[PTBK_AGENTS_SERVER_BUILD_WORKER_COUNT_ENV]:
|
|
404
|
+
environment[PTBK_AGENTS_SERVER_BUILD_WORKER_COUNT_ENV] || String(AGENTS_SERVER_BUILD_WORKER_COUNT),
|
|
361
405
|
...(options.isNextValidationIgnored
|
|
362
406
|
? {
|
|
363
407
|
[PTBK_AGENTS_SERVER_IGNORE_NEXT_VALIDATION_ENV]: 'true',
|
|
@@ -626,16 +670,35 @@ async function runNextBuild(options: {
|
|
|
626
670
|
readonly nextCliPath: string;
|
|
627
671
|
readonly onBuildOutput?: (chunk: string) => void;
|
|
628
672
|
}): Promise<void> {
|
|
629
|
-
|
|
673
|
+
for (let attempt = 1; attempt <= AGENTS_SERVER_BUILD_MAX_ATTEMPTS; attempt++) {
|
|
674
|
+
const exitStatus = await runNextBuildAttempt(options);
|
|
675
|
+
|
|
676
|
+
if (exitStatus.code === 0) {
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
if (attempt < AGENTS_SERVER_BUILD_MAX_ATTEMPTS && isNextBuildTerminationRetryable(exitStatus)) {
|
|
681
|
+
forwardBuildOutput(createNextBuildRetryMessage(exitStatus, attempt + 1), options.onBuildOutput);
|
|
682
|
+
continue;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
throw createNextBuildExitError(exitStatus, attempt);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Runs one Next.js production build attempt and returns its exit status.
|
|
691
|
+
*/
|
|
692
|
+
async function runNextBuildAttempt(options: {
|
|
693
|
+
readonly appPath: string;
|
|
694
|
+
readonly environment: NodeJS.ProcessEnv;
|
|
695
|
+
readonly nextCliPath: string;
|
|
696
|
+
readonly onBuildOutput?: (chunk: string) => void;
|
|
697
|
+
}): Promise<NextBuildExitStatus> {
|
|
698
|
+
return await new Promise<NextBuildExitStatus>((resolveBuild, rejectBuild) => {
|
|
630
699
|
const buildProcess = spawn(process.execPath, [options.nextCliPath, 'build'], {
|
|
631
700
|
cwd: options.appPath,
|
|
632
|
-
env:
|
|
633
|
-
...options.environment,
|
|
634
|
-
NODE_OPTIONS: mergeNodeOptionsWithHeapSize(
|
|
635
|
-
options.environment.NODE_OPTIONS,
|
|
636
|
-
AGENTS_SERVER_BUILD_MAX_OLD_SPACE_MIB,
|
|
637
|
-
),
|
|
638
|
-
},
|
|
701
|
+
env: createNextBuildProcessEnvironment(options.environment),
|
|
639
702
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
640
703
|
});
|
|
641
704
|
|
|
@@ -646,18 +709,83 @@ async function runNextBuild(options: {
|
|
|
646
709
|
forwardBuildOutput(chunk.toString(), options.onBuildOutput);
|
|
647
710
|
});
|
|
648
711
|
|
|
649
|
-
buildProcess.once('error',
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
rejectBuild(new Error(`next-build exited with code ${String(code)}.`));
|
|
712
|
+
buildProcess.once('error', (error) => {
|
|
713
|
+
rejectBuild(createNextBuildSpawnError(error));
|
|
714
|
+
});
|
|
715
|
+
buildProcess.once('close', (code, signal) => {
|
|
716
|
+
resolveBuild({ code, signal });
|
|
657
717
|
});
|
|
658
718
|
});
|
|
659
719
|
}
|
|
660
720
|
|
|
721
|
+
/**
|
|
722
|
+
* Creates the environment passed to the spawned Next.js build process.
|
|
723
|
+
*/
|
|
724
|
+
function createNextBuildProcessEnvironment(environment: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
|
|
725
|
+
return {
|
|
726
|
+
...environment,
|
|
727
|
+
NODE_OPTIONS: mergeNodeOptionsWithHeapSize(environment.NODE_OPTIONS, AGENTS_SERVER_BUILD_MAX_OLD_SPACE_MIB),
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* Returns true when one failed build attempt is worth retrying.
|
|
733
|
+
*/
|
|
734
|
+
function isNextBuildTerminationRetryable(exitStatus: NextBuildExitStatus): boolean {
|
|
735
|
+
return exitStatus.code === null && RETRYABLE_NEXT_BUILD_SIGNALS.has(exitStatus.signal);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Creates one visible retry message for a killed Next.js build attempt.
|
|
740
|
+
*/
|
|
741
|
+
function createNextBuildRetryMessage(exitStatus: NextBuildExitStatus, nextAttempt: number): string {
|
|
742
|
+
return `\nAgents Server Next build was terminated by ${describeNextBuildExitStatus(exitStatus)}. Retrying attempt ${nextAttempt}/${AGENTS_SERVER_BUILD_MAX_ATTEMPTS}.\n`;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* Creates a branded error for a failed Next.js build child process.
|
|
747
|
+
*/
|
|
748
|
+
function createNextBuildExitError(exitStatus: NextBuildExitStatus, attemptCount: number): NotAllowed {
|
|
749
|
+
const lowMemoryHint = isNextBuildTerminationRetryable(exitStatus)
|
|
750
|
+
? '\n\nThe build process was terminated by the operating system. On standalone VPS self-updates this usually means the host ran out of memory while Next.js was compiling or prerendering the app.'
|
|
751
|
+
: '';
|
|
752
|
+
|
|
753
|
+
return new NotAllowed(
|
|
754
|
+
spaceTrim(`
|
|
755
|
+
Agents Server Next production build failed.
|
|
756
|
+
|
|
757
|
+
- Exit code: \`${String(exitStatus.code)}\`
|
|
758
|
+
- Signal: \`${String(exitStatus.signal)}\`
|
|
759
|
+
- Attempts: \`${String(attemptCount)}\`
|
|
760
|
+
${lowMemoryHint}
|
|
761
|
+
`),
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Creates a branded error for failures to start the Next.js build child process.
|
|
767
|
+
*/
|
|
768
|
+
function createNextBuildSpawnError(error: Error): NotAllowed {
|
|
769
|
+
return new NotAllowed(
|
|
770
|
+
spaceTrim(`
|
|
771
|
+
Cannot start the Agents Server Next production build.
|
|
772
|
+
|
|
773
|
+
${error.message}
|
|
774
|
+
`),
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Formats one Next.js build exit status for foreground logs.
|
|
780
|
+
*/
|
|
781
|
+
function describeNextBuildExitStatus(exitStatus: NextBuildExitStatus): string {
|
|
782
|
+
if (exitStatus.signal) {
|
|
783
|
+
return `signal \`${exitStatus.signal}\``;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
return `exit code \`${String(exitStatus.code)}\``;
|
|
787
|
+
}
|
|
788
|
+
|
|
661
789
|
/**
|
|
662
790
|
* Prepends `--max-old-space-size=<mib>` to `NODE_OPTIONS` unless the caller already set one.
|
|
663
791
|
*/
|
|
@@ -21,7 +21,10 @@ import {
|
|
|
21
21
|
type PreparedAgentsServerRuntime,
|
|
22
22
|
resolveAgentsServerAppPath,
|
|
23
23
|
} from './buildAgentsServer';
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
DEFAULT_LOCAL_AGENT_RUNNER_MAX_FAILED_ATTEMPTS,
|
|
26
|
+
DEFAULT_LOCAL_AGENT_RUNNER_MAX_PARALLEL_MESSAGES,
|
|
27
|
+
} from '../../../../apps/agents-server/src/constants/serverLimits';
|
|
25
28
|
|
|
26
29
|
/**
|
|
27
30
|
* Local worker-pump delay while the Agents Server foreground process stays active.
|
|
@@ -206,6 +209,7 @@ type PreparedAgentsServerLaunch = {
|
|
|
206
209
|
*/
|
|
207
210
|
type LocalAgentRunnerLimits = {
|
|
208
211
|
readonly maxFailedAttempts: number;
|
|
212
|
+
readonly maxParallelMessages: number;
|
|
209
213
|
};
|
|
210
214
|
|
|
211
215
|
/**
|
|
@@ -537,6 +541,7 @@ function createLocalAgentRunOptions(
|
|
|
537
541
|
autoPull: false,
|
|
538
542
|
autoClone: false,
|
|
539
543
|
maxMessageProcessingFailures: localAgentRunnerLimits.maxFailedAttempts,
|
|
544
|
+
maxParallelMessages: localAgentRunnerLimits.maxParallelMessages,
|
|
540
545
|
};
|
|
541
546
|
}
|
|
542
547
|
|
|
@@ -557,7 +562,7 @@ async function waitForLocalAgentRunnerLimits(options: {
|
|
|
557
562
|
const limits = await fetchLocalAgentRunnerLimits(options);
|
|
558
563
|
logRunnerEvent(
|
|
559
564
|
options.logStreams.runner,
|
|
560
|
-
`Local agent runner
|
|
565
|
+
`Local agent runner limits: ${limits.maxFailedAttempts} failed attempt(s), ${limits.maxParallelMessages} parallel message(s).`,
|
|
561
566
|
);
|
|
562
567
|
return limits;
|
|
563
568
|
} catch (error) {
|
|
@@ -569,6 +574,7 @@ async function waitForLocalAgentRunnerLimits(options: {
|
|
|
569
574
|
if (!options.state.isContinuing) {
|
|
570
575
|
return {
|
|
571
576
|
maxFailedAttempts: DEFAULT_LOCAL_AGENT_RUNNER_MAX_FAILED_ATTEMPTS,
|
|
577
|
+
maxParallelMessages: DEFAULT_LOCAL_AGENT_RUNNER_MAX_PARALLEL_MESSAGES,
|
|
572
578
|
};
|
|
573
579
|
}
|
|
574
580
|
|
|
@@ -604,6 +610,7 @@ async function fetchLocalAgentRunnerLimits(options: {
|
|
|
604
610
|
const payload = (await response.json()) as Partial<LocalAgentRunnerLimits>;
|
|
605
611
|
return {
|
|
606
612
|
maxFailedAttempts: normalizeLocalAgentRunnerMaxFailedAttempts(payload.maxFailedAttempts),
|
|
613
|
+
maxParallelMessages: normalizeLocalAgentRunnerMaxParallelMessages(payload.maxParallelMessages),
|
|
607
614
|
};
|
|
608
615
|
}
|
|
609
616
|
|
|
@@ -620,6 +627,19 @@ function normalizeLocalAgentRunnerMaxFailedAttempts(rawValue: unknown): number {
|
|
|
620
627
|
return Math.floor(parsedValue);
|
|
621
628
|
}
|
|
622
629
|
|
|
630
|
+
/**
|
|
631
|
+
* Normalizes the local runner parallel message cap returned by the internal server route.
|
|
632
|
+
*/
|
|
633
|
+
function normalizeLocalAgentRunnerMaxParallelMessages(rawValue: unknown): number {
|
|
634
|
+
const parsedValue = Number(rawValue);
|
|
635
|
+
|
|
636
|
+
if (!Number.isFinite(parsedValue) || parsedValue <= 0) {
|
|
637
|
+
return DEFAULT_LOCAL_AGENT_RUNNER_MAX_PARALLEL_MESSAGES;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
return Math.floor(parsedValue);
|
|
641
|
+
}
|
|
642
|
+
|
|
623
643
|
/**
|
|
624
644
|
* Starts periodic internal worker calls that queue and reconcile local message-folder jobs.
|
|
625
645
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
const DEFAULT_CODER_PACKAGE_JSON_SCRIPTS = {
|
|
5
5
|
'coder:generate-boilerplates': 'ptbk coder generate-boilerplates --template ./prompts/templates/common.md',
|
|
6
6
|
'coder:run':
|
|
7
|
-
'ptbk coder run --harness openai-codex --model gpt-5.
|
|
7
|
+
'ptbk coder run --harness openai-codex --model gpt-5.5 --thinking-level xhigh --agent agents/developer.book --context AGENTS.md',
|
|
8
8
|
// 'coder:find-refactor-candidates': 'ptbk coder find-refactor-candidates',
|
|
9
9
|
'coder:verify': 'ptbk coder verify',
|
|
10
10
|
} as const satisfies Readonly<Record<string, string>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import colors from 'colors';
|
|
2
2
|
import { Command as Program /* <- Note: [🔸] Using Program because Command is misleading name */ } from 'commander';
|
|
3
3
|
import { spaceTrim } from 'spacetrim';
|
|
4
|
+
import { NotAllowed } from '../../../errors/NotAllowed';
|
|
4
5
|
import { assertsError } from '../../../errors/assertsError';
|
|
5
6
|
import type { $side_effect } from '../../../utils/organization/$side_effect';
|
|
6
7
|
import { handleActionErrors } from '../common/handleActionErrors';
|
|
@@ -65,6 +66,11 @@ export function $initializeCoderRunCommand(program: Program): $side_effect {
|
|
|
65
66
|
);
|
|
66
67
|
addPromptRunnerExecutionOptions(command);
|
|
67
68
|
command.option('--priority <minimum-priority>', 'Filter prompts by minimum priority level', parseIntOption, 0);
|
|
69
|
+
command.option(
|
|
70
|
+
'--limit <run-count>',
|
|
71
|
+
'Stop after processing this many prompt runs',
|
|
72
|
+
parsePositiveIntegerOption,
|
|
73
|
+
);
|
|
68
74
|
command.option(
|
|
69
75
|
'--wait-after-prompt <duration>',
|
|
70
76
|
spaceTrim(`
|
|
@@ -110,6 +116,7 @@ export function $initializeCoderRunCommand(program: Program): $side_effect {
|
|
|
110
116
|
test,
|
|
111
117
|
preserveLogs,
|
|
112
118
|
priority,
|
|
119
|
+
limit,
|
|
113
120
|
waitAfterPrompt: waitAfterPromptValue,
|
|
114
121
|
waitBetweenPrompts: waitBetweenPromptsValue,
|
|
115
122
|
waitAfterError: waitAfterErrorValue,
|
|
@@ -123,6 +130,7 @@ export function $initializeCoderRunCommand(program: Program): $side_effect {
|
|
|
123
130
|
readonly test?: string | string[];
|
|
124
131
|
readonly preserveLogs: boolean;
|
|
125
132
|
readonly priority: number;
|
|
133
|
+
readonly limit?: number;
|
|
126
134
|
readonly waitAfterPrompt?: string;
|
|
127
135
|
readonly waitBetweenPrompts?: string;
|
|
128
136
|
readonly waitAfterError?: string;
|
|
@@ -165,6 +173,7 @@ export function $initializeCoderRunCommand(program: Program): $side_effect {
|
|
|
165
173
|
noUi: runnerOptions.noUi,
|
|
166
174
|
thinkingLevel: runnerOptions.thinkingLevel,
|
|
167
175
|
priority,
|
|
176
|
+
limit,
|
|
168
177
|
normalizeLineEndings: runnerOptions.normalizeLineEndings,
|
|
169
178
|
allowCredits: runnerOptions.allowCredits,
|
|
170
179
|
autoMigrate,
|
|
@@ -204,6 +213,27 @@ function parseIntOption(value: string): number {
|
|
|
204
213
|
return parsed;
|
|
205
214
|
}
|
|
206
215
|
|
|
216
|
+
/**
|
|
217
|
+
* Parses a positive integer option value.
|
|
218
|
+
*
|
|
219
|
+
* @private internal utility of `coder run` command
|
|
220
|
+
*/
|
|
221
|
+
function parsePositiveIntegerOption(value: string): number {
|
|
222
|
+
const parsed = Number(value);
|
|
223
|
+
|
|
224
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
225
|
+
throw new NotAllowed(
|
|
226
|
+
spaceTrim(`
|
|
227
|
+
Invalid value for \`--limit\`: \`${value}\`.
|
|
228
|
+
|
|
229
|
+
Use a positive integer.
|
|
230
|
+
`),
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return parsed;
|
|
235
|
+
}
|
|
236
|
+
|
|
207
237
|
/**
|
|
208
238
|
* Joins one Commander option that may be parsed either as a single string or a variadic token array.
|
|
209
239
|
*
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { string_book } from '../../book-2.0/agent-source/string_book';
|
|
2
|
+
import {
|
|
3
|
+
AGENT_VISIBILITY_VALUES,
|
|
4
|
+
normalizeAgentVisibility,
|
|
5
|
+
type AgentVisibility,
|
|
6
|
+
} from '../../book-2.0/agent-source/agentSourceVisibility';
|
|
2
7
|
import { LimitReachedError } from '../../errors/LimitReachedError';
|
|
3
8
|
import { ParseError } from '../../errors/ParseError';
|
|
4
9
|
import type { LlmToolDefinition } from '../../types/LlmToolDefinition';
|
|
@@ -9,14 +14,14 @@ import { spaceTrim } from '../../utils/organization/spaceTrim';
|
|
|
9
14
|
*
|
|
10
15
|
* @private shared create-agent contract
|
|
11
16
|
*/
|
|
12
|
-
export const CREATE_AGENT_VISIBILITY_VALUES =
|
|
17
|
+
export const CREATE_AGENT_VISIBILITY_VALUES = AGENT_VISIBILITY_VALUES;
|
|
13
18
|
|
|
14
19
|
/**
|
|
15
20
|
* Supported visibility options for agent creation.
|
|
16
21
|
*
|
|
17
22
|
* @private shared create-agent contract
|
|
18
23
|
*/
|
|
19
|
-
export type CreateAgentVisibility =
|
|
24
|
+
export type CreateAgentVisibility = AgentVisibility;
|
|
20
25
|
|
|
21
26
|
/**
|
|
22
27
|
* Canonical input payload for creating one persisted agent entity.
|
|
@@ -244,8 +249,8 @@ function parseOptionalVisibility(rawValue: unknown): CreateAgentVisibility | und
|
|
|
244
249
|
);
|
|
245
250
|
}
|
|
246
251
|
|
|
247
|
-
const
|
|
248
|
-
if (!
|
|
252
|
+
const visibility = normalizeAgentVisibility(rawValue);
|
|
253
|
+
if (!visibility) {
|
|
249
254
|
throw new ParseError(
|
|
250
255
|
spaceTrim(`
|
|
251
256
|
Invalid create-agent payload.
|
|
@@ -255,5 +260,5 @@ function parseOptionalVisibility(rawValue: unknown): CreateAgentVisibility | und
|
|
|
255
260
|
);
|
|
256
261
|
}
|
|
257
262
|
|
|
258
|
-
return
|
|
263
|
+
return visibility;
|
|
259
264
|
}
|
|
@@ -322,7 +322,7 @@ export class AgentCollectionInSupabase /* TODO: [🌈][🐱🚀] implements A
|
|
|
322
322
|
): Promise<void> {
|
|
323
323
|
const selectPreviousAgentResult = await this.supabaseClient
|
|
324
324
|
.from(this.getTableName('Agent'))
|
|
325
|
-
.select('agentHash,agentName,permanentId')
|
|
325
|
+
.select('agentHash,agentName,permanentId,visibility')
|
|
326
326
|
.eq('permanentId', permanentId)
|
|
327
327
|
.single();
|
|
328
328
|
|
|
@@ -343,9 +343,12 @@ export class AgentCollectionInSupabase /* TODO: [🌈][🐱🚀] implements A
|
|
|
343
343
|
const previousAgentName = selectPreviousAgentResult.data.agentName;
|
|
344
344
|
const previousAgentHash = selectPreviousAgentResult.data.agentHash;
|
|
345
345
|
const previousPermanentId = selectPreviousAgentResult.data.permanentId;
|
|
346
|
+
const previousVisibility = selectPreviousAgentResult.data.visibility;
|
|
346
347
|
|
|
347
|
-
const preparedAgentSource = prepareAgentSourceForPersistence(agentSource
|
|
348
|
-
|
|
348
|
+
const preparedAgentSource = prepareAgentSourceForPersistence(agentSource, {
|
|
349
|
+
visibility: previousVisibility,
|
|
350
|
+
});
|
|
351
|
+
const { agentProfile, agentSource: normalizedAgentSource, visibility } = preparedAgentSource;
|
|
349
352
|
let { permanentId: newPermanentId } = preparedAgentSource;
|
|
350
353
|
|
|
351
354
|
const { agentHash, agentName } = agentProfile;
|
|
@@ -380,6 +383,7 @@ export class AgentCollectionInSupabase /* TODO: [🌈][🐱🚀] implements A
|
|
|
380
383
|
updatedAt: new Date().toISOString(),
|
|
381
384
|
agentHash: agentProfile.agentHash,
|
|
382
385
|
agentSource: normalizedAgentSource,
|
|
386
|
+
visibility: visibility ?? previousVisibility,
|
|
383
387
|
promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
|
|
384
388
|
})
|
|
385
389
|
.eq('permanentId', permanentId);
|
|
@@ -51,8 +51,11 @@ export function createAgentPersistenceRecords(
|
|
|
51
51
|
options: CreateAgentPersistenceRecordsOptions = {},
|
|
52
52
|
createdAt: string = new Date().toISOString(),
|
|
53
53
|
): CreateAgentPersistenceRecordsResult {
|
|
54
|
-
const preparedAgentSource = prepareAgentSourceForPersistence(agentSource
|
|
55
|
-
|
|
54
|
+
const preparedAgentSource = prepareAgentSourceForPersistence(agentSource, {
|
|
55
|
+
visibility: options.visibility,
|
|
56
|
+
isVisibilityOverride: options.visibility !== undefined,
|
|
57
|
+
});
|
|
58
|
+
const { agentProfile, agentSource: normalizedAgentSource, visibility } = preparedAgentSource;
|
|
56
59
|
const permanentId = preparedAgentSource.permanentId || $randomBase58(14);
|
|
57
60
|
const { agentName, agentHash } = agentProfile;
|
|
58
61
|
|
|
@@ -74,8 +77,8 @@ export function createAgentPersistenceRecords(
|
|
|
74
77
|
if (options.sortOrder !== undefined) {
|
|
75
78
|
agentInsertRecord.sortOrder = options.sortOrder;
|
|
76
79
|
}
|
|
77
|
-
if (
|
|
78
|
-
agentInsertRecord.visibility =
|
|
80
|
+
if (visibility !== undefined) {
|
|
81
|
+
agentInsertRecord.visibility = visibility;
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
return {
|
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
import type { AgentBasicInformation } from '../../../../book-2.0/agent-source/AgentBasicInformation';
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_AGENT_VISIBILITY,
|
|
4
|
+
parseAgentSourceVisibility,
|
|
5
|
+
setAgentSourceVisibility,
|
|
6
|
+
type AgentVisibility,
|
|
7
|
+
} from '../../../../book-2.0/agent-source/agentSourceVisibility';
|
|
2
8
|
import { parseAgentSource } from '../../../../book-2.0/agent-source/parseAgentSource';
|
|
3
9
|
import type { string_book } from '../../../../book-2.0/agent-source/string_book';
|
|
4
10
|
import type { string_agent_permanent_id } from '../../../../types/string_agent_name';
|
|
5
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Options used while preparing a source for persistence.
|
|
14
|
+
*
|
|
15
|
+
* @private shared persistence helper for `AgentCollectionInSupabase`
|
|
16
|
+
*/
|
|
17
|
+
export type PrepareAgentSourceForPersistenceOptions = {
|
|
18
|
+
/**
|
|
19
|
+
* Visibility value that should be written into the book when present.
|
|
20
|
+
*/
|
|
21
|
+
readonly visibility?: AgentVisibility | null;
|
|
22
|
+
/**
|
|
23
|
+
* Whether `visibility` should replace an existing `META VISIBILITY` commitment.
|
|
24
|
+
*/
|
|
25
|
+
readonly isVisibilityOverride?: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
6
28
|
/**
|
|
7
29
|
* Prepared agent source payload ready for database persistence.
|
|
8
30
|
*
|
|
@@ -24,6 +46,10 @@ export type PreparedAgentSourceForPersistence = {
|
|
|
24
46
|
* Permanent id extracted from the original source before stripping `META ID`.
|
|
25
47
|
*/
|
|
26
48
|
readonly permanentId: string_agent_permanent_id | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Visibility parsed from the normalized source.
|
|
51
|
+
*/
|
|
52
|
+
readonly visibility: AgentVisibility | undefined;
|
|
27
53
|
};
|
|
28
54
|
|
|
29
55
|
/**
|
|
@@ -36,20 +62,30 @@ export type PreparedAgentSourceForPersistence = {
|
|
|
36
62
|
*
|
|
37
63
|
* @private shared persistence helper for `AgentCollectionInSupabase`
|
|
38
64
|
*/
|
|
39
|
-
export function prepareAgentSourceForPersistence(
|
|
40
|
-
|
|
41
|
-
|
|
65
|
+
export function prepareAgentSourceForPersistence(
|
|
66
|
+
agentSource: string_book,
|
|
67
|
+
options: PrepareAgentSourceForPersistenceOptions = {},
|
|
68
|
+
): PreparedAgentSourceForPersistence {
|
|
69
|
+
const originalAgentProfile = parseAgentSource(agentSource);
|
|
70
|
+
const permanentId = originalAgentProfile.permanentId;
|
|
42
71
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
agentSource = stripMetaIdLines(agentSource);
|
|
73
|
+
const sourceVisibility = parseAgentSourceVisibility(agentSource, { isStrict: true });
|
|
74
|
+
const resolvedVisibility =
|
|
75
|
+
options.isVisibilityOverride || !sourceVisibility
|
|
76
|
+
? options.visibility ?? sourceVisibility ?? DEFAULT_AGENT_VISIBILITY
|
|
77
|
+
: sourceVisibility;
|
|
78
|
+
|
|
79
|
+
agentSource = setAgentSourceVisibility(agentSource, resolvedVisibility);
|
|
80
|
+
|
|
81
|
+
const agentProfile = parseAgentSource(agentSource);
|
|
82
|
+
const visibility = parseAgentSourceVisibility(agentSource, { isStrict: true }) ?? undefined;
|
|
48
83
|
|
|
49
84
|
return {
|
|
50
85
|
agentProfile,
|
|
51
86
|
agentSource,
|
|
52
87
|
permanentId,
|
|
88
|
+
visibility,
|
|
53
89
|
};
|
|
54
90
|
}
|
|
55
91
|
|