@narumitw/pi-subagents 2.1.4 → 3.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 +187 -1228
- package/dist/child-communication-bridge.ts +136 -0
- package/dist/child-communication-bridge.ts.map +7 -0
- package/dist/chunks/chunk-UKTWUQRM.js +667 -0
- package/dist/chunks/chunk-UKTWUQRM.js.map +7 -0
- package/dist/index.ts +1448 -1614
- package/dist/index.ts.map +4 -4
- package/docs/design-principles.md +31 -0
- package/docs/ipc-transport-idea.md +103 -0
- package/docs/tools.md +109 -0
- package/package.json +11 -19
- package/src/broker-credentials.ts +71 -0
- package/src/child-communication-bridge.ts +153 -0
- package/src/child-communication-tools.ts +147 -0
- package/src/completion-renderer.ts +60 -0
- package/src/index.ts +1 -1
- package/src/message-broker.ts +628 -0
- package/src/model-output.ts +42 -0
- package/src/process.ts +688 -0
- package/src/runtime.ts +538 -0
- package/src/subagents.ts +33 -34
- package/src/tools.ts +416 -0
- package/src/types.ts +85 -0
- package/src/widget.ts +130 -0
- package/dist/chunks/auto-transport-FUUKFDIG.ts +0 -109
- package/dist/chunks/auto-transport-FUUKFDIG.ts.map +0 -7
- package/dist/chunks/capability-grant-PR72SWWS.ts +0 -19
- package/dist/chunks/capability-grant-PR72SWWS.ts.map +0 -7
- package/dist/chunks/child-peer-bridge.ts +0 -108
- package/dist/chunks/child-peer-bridge.ts.map +0 -7
- package/dist/chunks/chunk-2LMJU25E.ts +0 -1641
- package/dist/chunks/chunk-2LMJU25E.ts.map +0 -7
- package/dist/chunks/chunk-47SK2QYC.ts +0 -56
- package/dist/chunks/chunk-47SK2QYC.ts.map +0 -7
- package/dist/chunks/chunk-4AQSF7AS.ts +0 -29
- package/dist/chunks/chunk-4AQSF7AS.ts.map +0 -7
- package/dist/chunks/chunk-5DGRMKNV.ts +0 -126
- package/dist/chunks/chunk-5DGRMKNV.ts.map +0 -7
- package/dist/chunks/chunk-6H6TBBED.ts +0 -108
- package/dist/chunks/chunk-6H6TBBED.ts.map +0 -7
- package/dist/chunks/chunk-6KJ34M6S.ts +0 -159
- package/dist/chunks/chunk-6KJ34M6S.ts.map +0 -7
- package/dist/chunks/chunk-6NSJVPXX.ts +0 -480
- package/dist/chunks/chunk-6NSJVPXX.ts.map +0 -7
- package/dist/chunks/chunk-7AAJEUSL.ts +0 -238
- package/dist/chunks/chunk-7AAJEUSL.ts.map +0 -7
- package/dist/chunks/chunk-BFK2Z4ZF.ts +0 -189
- package/dist/chunks/chunk-BFK2Z4ZF.ts.map +0 -7
- package/dist/chunks/chunk-BOAXY55Y.ts +0 -153
- package/dist/chunks/chunk-BOAXY55Y.ts.map +0 -7
- package/dist/chunks/chunk-D4CR7T73.ts +0 -353
- package/dist/chunks/chunk-D4CR7T73.ts.map +0 -7
- package/dist/chunks/chunk-FEVPWRMU.ts +0 -300
- package/dist/chunks/chunk-FEVPWRMU.ts.map +0 -7
- package/dist/chunks/chunk-G6VZTCFH.ts +0 -70
- package/dist/chunks/chunk-G6VZTCFH.ts.map +0 -7
- package/dist/chunks/chunk-H3FP6DLR.ts +0 -160
- package/dist/chunks/chunk-H3FP6DLR.ts.map +0 -7
- package/dist/chunks/chunk-HA36LPCO.ts +0 -130
- package/dist/chunks/chunk-HA36LPCO.ts.map +0 -7
- package/dist/chunks/chunk-HOP5FXDT.ts +0 -27
- package/dist/chunks/chunk-HOP5FXDT.ts.map +0 -7
- package/dist/chunks/chunk-IGAMVWFN.ts +0 -139
- package/dist/chunks/chunk-IGAMVWFN.ts.map +0 -7
- package/dist/chunks/chunk-ILEQ27AL.ts +0 -45
- package/dist/chunks/chunk-ILEQ27AL.ts.map +0 -7
- package/dist/chunks/chunk-ITVWPNU4.ts +0 -819
- package/dist/chunks/chunk-ITVWPNU4.ts.map +0 -7
- package/dist/chunks/chunk-IWC32VPY.ts +0 -172
- package/dist/chunks/chunk-IWC32VPY.ts.map +0 -7
- package/dist/chunks/chunk-JSZIP73U.ts +0 -362
- package/dist/chunks/chunk-JSZIP73U.ts.map +0 -7
- package/dist/chunks/chunk-JU6LUNLP.ts +0 -380
- package/dist/chunks/chunk-JU6LUNLP.ts.map +0 -7
- package/dist/chunks/chunk-KMGKCEO4.ts +0 -38
- package/dist/chunks/chunk-KMGKCEO4.ts.map +0 -7
- package/dist/chunks/chunk-LASD73CM.ts +0 -339
- package/dist/chunks/chunk-LASD73CM.ts.map +0 -7
- package/dist/chunks/chunk-LEOYDZI3.ts +0 -22
- package/dist/chunks/chunk-LEOYDZI3.ts.map +0 -7
- package/dist/chunks/chunk-LL4LP2T7.ts +0 -737
- package/dist/chunks/chunk-LL4LP2T7.ts.map +0 -7
- package/dist/chunks/chunk-N2T5IN4X.ts +0 -18
- package/dist/chunks/chunk-N2T5IN4X.ts.map +0 -7
- package/dist/chunks/chunk-N7BLVXKK.ts +0 -73
- package/dist/chunks/chunk-N7BLVXKK.ts.map +0 -7
- package/dist/chunks/chunk-NLT67IZS.ts +0 -322
- package/dist/chunks/chunk-NLT67IZS.ts.map +0 -7
- package/dist/chunks/chunk-NTRPLF46.ts +0 -63
- package/dist/chunks/chunk-NTRPLF46.ts.map +0 -7
- package/dist/chunks/chunk-ONDTY4EL.ts +0 -91
- package/dist/chunks/chunk-ONDTY4EL.ts.map +0 -7
- package/dist/chunks/chunk-OVPHFGKO.ts +0 -1769
- package/dist/chunks/chunk-OVPHFGKO.ts.map +0 -7
- package/dist/chunks/chunk-P7OH4XMF.ts +0 -60
- package/dist/chunks/chunk-P7OH4XMF.ts.map +0 -7
- package/dist/chunks/chunk-PBZMBTNJ.ts +0 -422
- package/dist/chunks/chunk-PBZMBTNJ.ts.map +0 -7
- package/dist/chunks/chunk-PGLSFLYW.ts +0 -52
- package/dist/chunks/chunk-PGLSFLYW.ts.map +0 -7
- package/dist/chunks/chunk-RRR66UWR.ts +0 -28
- package/dist/chunks/chunk-RRR66UWR.ts.map +0 -7
- package/dist/chunks/chunk-RSUXZD6S.ts +0 -275
- package/dist/chunks/chunk-RSUXZD6S.ts.map +0 -7
- package/dist/chunks/chunk-RTCVYIZA.ts +0 -221
- package/dist/chunks/chunk-RTCVYIZA.ts.map +0 -7
- package/dist/chunks/chunk-RY2AEGMZ.ts +0 -34
- package/dist/chunks/chunk-RY2AEGMZ.ts.map +0 -7
- package/dist/chunks/chunk-SWGQLFSD.ts +0 -60
- package/dist/chunks/chunk-SWGQLFSD.ts.map +0 -7
- package/dist/chunks/chunk-TM2R67J3.ts +0 -52
- package/dist/chunks/chunk-TM2R67J3.ts.map +0 -7
- package/dist/chunks/chunk-TMZRHIIK.ts +0 -497
- package/dist/chunks/chunk-TMZRHIIK.ts.map +0 -7
- package/dist/chunks/chunk-TZ34IQ3M.ts +0 -59
- package/dist/chunks/chunk-TZ34IQ3M.ts.map +0 -7
- package/dist/chunks/chunk-UMBPMVJW.ts +0 -22
- package/dist/chunks/chunk-UMBPMVJW.ts.map +0 -7
- package/dist/chunks/chunk-VDG7LTYE.ts +0 -80
- package/dist/chunks/chunk-VDG7LTYE.ts.map +0 -7
- package/dist/chunks/chunk-X4NMONPE.ts +0 -73
- package/dist/chunks/chunk-X4NMONPE.ts.map +0 -7
- package/dist/chunks/chunk-YPJEN6NU.ts +0 -65
- package/dist/chunks/chunk-YPJEN6NU.ts.map +0 -7
- package/dist/chunks/chunk-YU53SHA7.ts +0 -328
- package/dist/chunks/chunk-YU53SHA7.ts.map +0 -7
- package/dist/chunks/completion-delivery-RSJU6BXL.ts +0 -17
- package/dist/chunks/completion-delivery-RSJU6BXL.ts.map +0 -7
- package/dist/chunks/config-status-FKGDECZ3.ts +0 -35
- package/dist/chunks/config-status-FKGDECZ3.ts.map +0 -7
- package/dist/chunks/config-ui-ABHYNGQ7.ts +0 -1212
- package/dist/chunks/config-ui-ABHYNGQ7.ts.map +0 -7
- package/dist/chunks/consult-LJU3IQY5.ts +0 -519
- package/dist/chunks/consult-LJU3IQY5.ts.map +0 -7
- package/dist/chunks/context-QDKLVQXE.ts +0 -11
- package/dist/chunks/context-QDKLVQXE.ts.map +0 -7
- package/dist/chunks/create-stateful-transport-JWC2EFYL.ts +0 -130
- package/dist/chunks/create-stateful-transport-JWC2EFYL.ts.map +0 -7
- package/dist/chunks/cwd-policy-NB6XZ5GF.ts +0 -17
- package/dist/chunks/cwd-policy-NB6XZ5GF.ts.map +0 -7
- package/dist/chunks/delegation-contract-LA56I5DT.ts +0 -24
- package/dist/chunks/delegation-contract-LA56I5DT.ts.map +0 -7
- package/dist/chunks/discovery-MIFB2U4Y.ts +0 -12
- package/dist/chunks/discovery-MIFB2U4Y.ts.map +0 -7
- package/dist/chunks/execution-Q2JZLKJA.ts +0 -4037
- package/dist/chunks/execution-Q2JZLKJA.ts.map +0 -7
- package/dist/chunks/in-process-transport-HJ6TZXC3.ts +0 -39
- package/dist/chunks/in-process-transport-HJ6TZXC3.ts.map +0 -7
- package/dist/chunks/inspect-UH2TKH6E.ts +0 -634
- package/dist/chunks/inspect-UH2TKH6E.ts.map +0 -7
- package/dist/chunks/peer-communication-KL36Z6CO.ts +0 -294
- package/dist/chunks/peer-communication-KL36Z6CO.ts.map +0 -7
- package/dist/chunks/persistence-UY3PY6E5.ts +0 -348
- package/dist/chunks/persistence-UY3PY6E5.ts.map +0 -7
- package/dist/chunks/registry-BT54L6CY.ts +0 -1445
- package/dist/chunks/registry-BT54L6CY.ts.map +0 -7
- package/dist/chunks/retained-semantic-state-GM75FZGE.ts +0 -81
- package/dist/chunks/retained-semantic-state-GM75FZGE.ts.map +0 -7
- package/dist/chunks/rpc-transport-7R7DVCEB.ts +0 -1222
- package/dist/chunks/rpc-transport-7R7DVCEB.ts.map +0 -7
- package/dist/chunks/runtime-policy-5YELCOVC.ts +0 -15
- package/dist/chunks/runtime-policy-5YELCOVC.ts.map +0 -7
- package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts +0 -19
- package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts.map +0 -7
- package/dist/chunks/spawn-idempotency-BNHOSMZW.ts +0 -13
- package/dist/chunks/spawn-idempotency-BNHOSMZW.ts.map +0 -7
- package/dist/chunks/stateful-lifecycle-JAR6K55H.ts +0 -15
- package/dist/chunks/stateful-lifecycle-JAR6K55H.ts.map +0 -7
- package/dist/chunks/subprocess-transport-VHZJRBTW.ts +0 -160
- package/dist/chunks/subprocess-transport-VHZJRBTW.ts.map +0 -7
- package/dist/chunks/usage-recording-store-CW3EH2SZ.ts +0 -164
- package/dist/chunks/usage-recording-store-CW3EH2SZ.ts.map +0 -7
- package/dist/chunks/workspace-WDKLN72J.ts +0 -11
- package/dist/chunks/workspace-WDKLN72J.ts.map +0 -7
- package/docs/async-runtime-protocol.md +0 -84
- package/docs/implementation-notes/pi-subagents-capability-matrix.md +0 -62
- package/docs/implementation-notes/pi-subagents-current-direction.md +0 -99
- package/docs/implementation-notes/pi-subagents-rpc-v1.md +0 -139
- package/docs/pi-subagents-diagrams.md +0 -183
- package/src/adaptive-scheduler.ts +0 -224
- package/src/admission-policy.ts +0 -78
- package/src/agent-projection.ts +0 -53
- package/src/agents/built-ins.ts +0 -71
- package/src/agents/catalog.ts +0 -241
- package/src/agents/discovery.ts +0 -265
- package/src/agents/types.ts +0 -100
- package/src/agents.ts +0 -51
- package/src/auto-transport.ts +0 -121
- package/src/blocking-status.ts +0 -63
- package/src/cached-module-loader.ts +0 -18
- package/src/capabilities.ts +0 -145
- package/src/capability-grant.ts +0 -115
- package/src/capability-router.ts +0 -107
- package/src/child-peer-bridge.ts +0 -124
- package/src/child-peer-tools.ts +0 -132
- package/src/completion-delivery.ts +0 -409
- package/src/completion-render.ts +0 -190
- package/src/completion-requirement.ts +0 -479
- package/src/completion-routing.ts +0 -24
- package/src/config-registration.ts +0 -114
- package/src/config-status.ts +0 -217
- package/src/config-ui.ts +0 -983
- package/src/consult-policy.ts +0 -15
- package/src/consult-registration.ts +0 -125
- package/src/consult-render.ts +0 -194
- package/src/consult-resources.ts +0 -51
- package/src/consult-tool.ts +0 -95
- package/src/consult.ts +0 -566
- package/src/context.ts +0 -126
- package/src/create-stateful-transport.ts +0 -157
- package/src/cwd-policy.ts +0 -183
- package/src/delegation-contract.ts +0 -463
- package/src/execution/budget.ts +0 -56
- package/src/execution/runtime-policy.ts +0 -19
- package/src/execution-plan.ts +0 -322
- package/src/execution-ui.ts +0 -259
- package/src/execution.ts +0 -1679
- package/src/in-process-transport.ts +0 -941
- package/src/inspect-registration.ts +0 -64
- package/src/inspect-render.ts +0 -334
- package/src/inspect-tool.ts +0 -45
- package/src/inspect.ts +0 -769
- package/src/integration-controller.ts +0 -98
- package/src/limits.ts +0 -75
- package/src/orchestration-metrics.ts +0 -116
- package/src/outcome.ts +0 -61
- package/src/panel-child-group.ts +0 -35
- package/src/panel-contract.ts +0 -343
- package/src/panel-evidence.ts +0 -59
- package/src/panel-execution.ts +0 -769
- package/src/panel-failure.ts +0 -56
- package/src/panel-planning.ts +0 -175
- package/src/panel-presets.ts +0 -3
- package/src/panel-prompts.ts +0 -132
- package/src/panel-reconciliation.ts +0 -57
- package/src/panel-render.ts +0 -103
- package/src/parallel-limit-ui.ts +0 -113
- package/src/params.ts +0 -278
- package/src/peer-communication.ts +0 -352
- package/src/peer-transport.ts +0 -49
- package/src/persistence.ts +0 -522
- package/src/pi-args.ts +0 -43
- package/src/pi-invocation.ts +0 -168
- package/src/process-control.ts +0 -43
- package/src/prompt-resources.ts +0 -38
- package/src/prompt-source-safety.ts +0 -48
- package/src/protocol.ts +0 -76
- package/src/registry-types.ts +0 -204
- package/src/registry.ts +0 -1698
- package/src/render-common.ts +0 -252
- package/src/render.ts +0 -704
- package/src/result-contract.ts +0 -431
- package/src/retained-semantic-state.ts +0 -100
- package/src/rpc-timeout-finalization.ts +0 -207
- package/src/rpc-transport-metadata.ts +0 -65
- package/src/rpc-transport.ts +0 -1035
- package/src/rpc-turn-capture.ts +0 -217
- package/src/runner-outcome.ts +0 -31
- package/src/runner-result.ts +0 -55
- package/src/runner-types.ts +0 -102
- package/src/runner-usage.ts +0 -48
- package/src/runner.ts +0 -866
- package/src/safe-text.ts +0 -67
- package/src/semantic-snapshot.ts +0 -214
- package/src/session-guidance-contract.ts +0 -399
- package/src/settings/inspection.ts +0 -302
- package/src/settings/schema.ts +0 -195
- package/src/settings-reader.ts +0 -215
- package/src/settings.ts +0 -452
- package/src/spawn-idempotency.ts +0 -68
- package/src/stateful-agent-view.ts +0 -85
- package/src/stateful-config.ts +0 -13
- package/src/stateful-guidance.ts +0 -29
- package/src/stateful-lifecycle.ts +0 -74
- package/src/stateful-limit-ui.ts +0 -249
- package/src/stateful-limits.ts +0 -96
- package/src/stateful-prompt.ts +0 -49
- package/src/stateful-registration.ts +0 -1320
- package/src/stateful-render.ts +0 -318
- package/src/stateful-safety.ts +0 -47
- package/src/stateful-tool-params.ts +0 -215
- package/src/stateful.ts +0 -12
- package/src/subagent-details.ts +0 -43
- package/src/subagents-extension.ts +0 -372
- package/src/subprocess-transport.ts +0 -145
- package/src/supervision.ts +0 -104
- package/src/task-path.ts +0 -65
- package/src/timeout-checkpoint.ts +0 -305
- package/src/timeout-finalization.ts +0 -75
- package/src/tool-schema-compatibility.ts +0 -73
- package/src/transport-types.ts +0 -74
- package/src/transport-ui.ts +0 -135
- package/src/transport.ts +0 -43
- package/src/turn-budget.ts +0 -109
- package/src/usage-format.ts +0 -42
- package/src/usage-recording-config.ts +0 -13
- package/src/usage-recording-store.ts +0 -183
- package/src/usage-recording.ts +0 -478
- package/src/verification-harness.ts +0 -516
- package/src/verification-policy.ts +0 -67
- package/src/verification-receipt.ts +0 -275
- package/src/verified-execution-benchmark.ts +0 -86
- package/src/verified-execution-contract.ts +0 -191
- package/src/verified-execution-schema.ts +0 -32
- package/src/work-item-ledger.ts +0 -1404
- package/src/work-item-persistence.ts +0 -254
- package/src/workflow-completion-controller.ts +0 -397
- package/src/workflow-planning.ts +0 -172
- package/src/workflow-tree-identity.ts +0 -289
- package/src/workflow-ui.ts +0 -69
- package/src/workflow-verification.ts +0 -296
- package/src/workspace.ts +0 -174
package/src/agents/catalog.ts
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bounded, sanitized model-facing agent catalog formatting.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { BUILT_IN_AGENTS } from "./built-ins.js";
|
|
6
|
-
import {
|
|
7
|
-
type AgentDiscoveryOptions,
|
|
8
|
-
type AgentDiscoveryResult,
|
|
9
|
-
discoverAgents,
|
|
10
|
-
} from "./discovery.js";
|
|
11
|
-
import { type AgentConfig, resolveAgentToolNames, type SubagentSettings } from "./types.js";
|
|
12
|
-
|
|
13
|
-
export function formatAgentList(
|
|
14
|
-
agents: AgentConfig[],
|
|
15
|
-
maxItems: number,
|
|
16
|
-
): { text: string; remaining: number } {
|
|
17
|
-
if (agents.length === 0) return { text: "none", remaining: 0 };
|
|
18
|
-
const listed = agents.slice(0, maxItems);
|
|
19
|
-
const remaining = agents.length - listed.length;
|
|
20
|
-
return {
|
|
21
|
-
text: listed.map((a) => `${a.name} (${a.source}): ${a.description}`).join("; "),
|
|
22
|
-
remaining,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface AgentCatalog {
|
|
27
|
-
/** The effective catalog for the default invocation scope. */
|
|
28
|
-
user: AgentDiscoveryResult;
|
|
29
|
-
/** The project-scope catalog; custom project definitions are loaded only after project trust. */
|
|
30
|
-
project?: AgentDiscoveryResult;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface AgentCatalogFormatOptions {
|
|
34
|
-
maxItems?: number;
|
|
35
|
-
maxDescriptionLength?: number;
|
|
36
|
-
maxCharacters?: number;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface AgentCatalogFormatResult {
|
|
40
|
-
text: string;
|
|
41
|
-
omitted: number;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const DEFAULT_AGENT_CATALOG_MAX_ITEMS = 32;
|
|
45
|
-
export const DEFAULT_AGENT_CATALOG_MAX_DESCRIPTION_LENGTH = 240;
|
|
46
|
-
export const DEFAULT_AGENT_CATALOG_MAX_CHARACTERS = 6_000;
|
|
47
|
-
export const DEFAULT_AGENT_CATALOG_MAX_FILES_PER_SCOPE = 128;
|
|
48
|
-
export const DEFAULT_AGENT_CATALOG_MAX_FILE_BYTES = 64 * 1024;
|
|
49
|
-
export const DEFAULT_AGENT_CATALOG_MAX_TOTAL_BYTES_PER_SCOPE = 2 * 1024 * 1024;
|
|
50
|
-
|
|
51
|
-
const BUILT_IN_AGENT_ORDER = new Map(BUILT_IN_AGENTS.map((agent, index) => [agent.name, index]));
|
|
52
|
-
|
|
53
|
-
function compareCatalogAgents(left: AgentConfig, right: AgentConfig): number {
|
|
54
|
-
const leftBuiltInOrder = BUILT_IN_AGENT_ORDER.get(left.name);
|
|
55
|
-
const rightBuiltInOrder = BUILT_IN_AGENT_ORDER.get(right.name);
|
|
56
|
-
if (leftBuiltInOrder !== undefined || rightBuiltInOrder !== undefined) {
|
|
57
|
-
if (leftBuiltInOrder === undefined) return 1;
|
|
58
|
-
if (rightBuiltInOrder === undefined) return -1;
|
|
59
|
-
return leftBuiltInOrder - rightBuiltInOrder;
|
|
60
|
-
}
|
|
61
|
-
return left.name.localeCompare(right.name);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function normalizeCatalogDescription(description: string, maxLength: number): string {
|
|
65
|
-
const normalized = description.replace(/\s+/gu, " ").trim();
|
|
66
|
-
if (normalized.length <= maxLength) return normalized;
|
|
67
|
-
const suffix = "…";
|
|
68
|
-
return `${normalized.slice(0, Math.max(0, maxLength - suffix.length)).trimEnd()}${suffix}`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
type CatalogScope = "user" | "project" | "project-fallback";
|
|
72
|
-
|
|
73
|
-
function formatDeclaredItems(items: readonly string[] | undefined): string {
|
|
74
|
-
if (items === undefined) return "undeclared";
|
|
75
|
-
return items.length > 0 ? items.join(", ") : "none";
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function catalogAgentContractMetadata(agent: AgentConfig): string {
|
|
79
|
-
const manifest = agent.capabilityManifest;
|
|
80
|
-
return [
|
|
81
|
-
`capabilities: ${formatDeclaredItems(manifest?.capabilities)}`,
|
|
82
|
-
`tools: ${formatDeclaredItems(resolveAgentToolNames(agent.tools))}`,
|
|
83
|
-
`filesystem: ${manifest?.authority?.filesystem ?? "undeclared"}`,
|
|
84
|
-
`result formats: ${formatDeclaredItems(manifest?.resultFormats)}`,
|
|
85
|
-
].join("; ");
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function catalogAgentLine(
|
|
89
|
-
agent: AgentConfig,
|
|
90
|
-
scope: CatalogScope,
|
|
91
|
-
userNames: ReadonlySet<string>,
|
|
92
|
-
maxDescriptionLength: number,
|
|
93
|
-
): string {
|
|
94
|
-
const scopeLabel =
|
|
95
|
-
scope === "user"
|
|
96
|
-
? 'agentScope: "user"'
|
|
97
|
-
: scope === "project"
|
|
98
|
-
? 'requires agentScope: "project" or "both"'
|
|
99
|
-
: 'requires agentScope: "project" ("both" selects the user definition)';
|
|
100
|
-
const collision =
|
|
101
|
-
scope !== "user" && userNames.has(agent.name)
|
|
102
|
-
? scope === "project"
|
|
103
|
-
? "; overrides the default user definition for project/both"
|
|
104
|
-
: "; scope-specific fallback for the default user override"
|
|
105
|
-
: "";
|
|
106
|
-
return `- ${agent.name} [source: ${agent.source}; ${scopeLabel}${collision}] [${catalogAgentContractMetadata(agent)}] — ${normalizeCatalogDescription(agent.description, maxDescriptionLength)}`;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Format the effective agent variants that the parent model can invoke.
|
|
111
|
-
*
|
|
112
|
-
* User-authored descriptions are prompt text, so this formatter deliberately normalizes and bounds
|
|
113
|
-
* them. Project definitions are supplied separately by the caller so an untrusted project is never
|
|
114
|
-
* read merely to build model-facing metadata.
|
|
115
|
-
*/
|
|
116
|
-
export function formatAgentCatalog(
|
|
117
|
-
catalog: AgentCatalog,
|
|
118
|
-
options: AgentCatalogFormatOptions = {},
|
|
119
|
-
): AgentCatalogFormatResult {
|
|
120
|
-
const maxItems = Math.max(0, options.maxItems ?? DEFAULT_AGENT_CATALOG_MAX_ITEMS);
|
|
121
|
-
const maxDescriptionLength = Math.max(
|
|
122
|
-
1,
|
|
123
|
-
options.maxDescriptionLength ?? DEFAULT_AGENT_CATALOG_MAX_DESCRIPTION_LENGTH,
|
|
124
|
-
);
|
|
125
|
-
const maxCharacters = Math.max(1, options.maxCharacters ?? DEFAULT_AGENT_CATALOG_MAX_CHARACTERS);
|
|
126
|
-
const userDiscoveryIncomplete =
|
|
127
|
-
(catalog.user.omittedAgentDefinitions ?? 0) > 0 ||
|
|
128
|
-
catalog.user.metadataDiscoveryIncomplete === true;
|
|
129
|
-
const projectDiscoveryIncomplete =
|
|
130
|
-
(catalog.project?.omittedAgentDefinitions ?? 0) > 0 ||
|
|
131
|
-
catalog.project?.metadataDiscoveryIncomplete === true;
|
|
132
|
-
const discoveredUserAgents = [...catalog.user.agents].sort(compareCatalogAgents);
|
|
133
|
-
const discoveredProjectScopeAgents = [...(catalog.project?.agents ?? [])].sort(
|
|
134
|
-
compareCatalogAgents,
|
|
135
|
-
);
|
|
136
|
-
const userAgents = userDiscoveryIncomplete ? [] : discoveredUserAgents;
|
|
137
|
-
const projectScopeAgents = projectDiscoveryIncomplete ? [] : discoveredProjectScopeAgents;
|
|
138
|
-
const projectAgents = projectScopeAgents.filter((agent) => agent.source === "project");
|
|
139
|
-
const discoveredUserByName = new Map(discoveredUserAgents.map((agent) => [agent.name, agent]));
|
|
140
|
-
const userByName = new Map(userAgents.map((agent) => [agent.name, agent]));
|
|
141
|
-
const userNames = new Set(userByName.keys());
|
|
142
|
-
const potentialProjectFallbackAgents = discoveredProjectScopeAgents.filter(
|
|
143
|
-
(agent) =>
|
|
144
|
-
agent.source === "built-in" && discoveredUserByName.get(agent.name)?.source === "user",
|
|
145
|
-
);
|
|
146
|
-
const projectFallbackAgents =
|
|
147
|
-
userDiscoveryIncomplete || projectDiscoveryIncomplete ? [] : potentialProjectFallbackAgents;
|
|
148
|
-
const allEntries = [
|
|
149
|
-
...userAgents.map((agent) => ({ agent, scope: "user" as const })),
|
|
150
|
-
...projectAgents.map((agent) => ({ agent, scope: "project" as const })),
|
|
151
|
-
...projectFallbackAgents.map((agent) => ({ agent, scope: "project-fallback" as const })),
|
|
152
|
-
];
|
|
153
|
-
const boundedEntries = allEntries.slice(0, maxItems);
|
|
154
|
-
const suppressedMetadataEntries =
|
|
155
|
-
(userDiscoveryIncomplete ? discoveredUserAgents.length : 0) +
|
|
156
|
-
(projectDiscoveryIncomplete
|
|
157
|
-
? discoveredProjectScopeAgents.filter((agent) => agent.source === "project").length +
|
|
158
|
-
potentialProjectFallbackAgents.length
|
|
159
|
-
: 0);
|
|
160
|
-
const discoveryOmissions =
|
|
161
|
-
(catalog.user.omittedAgentDefinitions ?? 0) +
|
|
162
|
-
(catalog.project?.omittedAgentDefinitions ?? 0) +
|
|
163
|
-
suppressedMetadataEntries;
|
|
164
|
-
const discoveryIncomplete =
|
|
165
|
-
catalog.user.metadataDiscoveryIncomplete === true ||
|
|
166
|
-
catalog.project?.metadataDiscoveryIncomplete === true;
|
|
167
|
-
|
|
168
|
-
const render = (entries: typeof allEntries, omitted: number): string => {
|
|
169
|
-
const lines = [
|
|
170
|
-
"Available agent definitions (metadata only; runtime validation and trust remain authoritative).",
|
|
171
|
-
"Use capability and tool identifiers exactly as shown when authoring enforced contracts.",
|
|
172
|
-
"Enforced contract readPaths, writePaths, network, and secrets guarantees are unsupported.",
|
|
173
|
-
];
|
|
174
|
-
const userLines = entries
|
|
175
|
-
.filter((entry) => entry.scope === "user")
|
|
176
|
-
.map((entry) => catalogAgentLine(entry.agent, entry.scope, userNames, maxDescriptionLength));
|
|
177
|
-
if (userLines.length > 0) {
|
|
178
|
-
lines.push('Default scope (agentScope: "user"):');
|
|
179
|
-
lines.push(...userLines);
|
|
180
|
-
}
|
|
181
|
-
const projectLines = entries
|
|
182
|
-
.filter((entry) => entry.scope !== "user")
|
|
183
|
-
.map((entry) => catalogAgentLine(entry.agent, entry.scope, userNames, maxDescriptionLength));
|
|
184
|
-
if (projectLines.length > 0) {
|
|
185
|
-
lines.push("Trusted project/scope variants (use the required agentScope shown):");
|
|
186
|
-
lines.push(...projectLines);
|
|
187
|
-
}
|
|
188
|
-
const collisionNames = entries
|
|
189
|
-
.filter((entry) => entry.scope !== "user" && userNames.has(entry.agent.name))
|
|
190
|
-
.map((entry) => entry.agent.name);
|
|
191
|
-
if (collisionNames.length > 0 && projectLines.length > 0) {
|
|
192
|
-
const precedence = entries
|
|
193
|
-
.filter((entry) => entry.scope !== "user" && userNames.has(entry.agent.name))
|
|
194
|
-
.map((entry) =>
|
|
195
|
-
entry.scope === "project"
|
|
196
|
-
? `${entry.agent.name}: user with "user", project with "project"/"both"`
|
|
197
|
-
: `${entry.agent.name}: user with "user"/"both", built-in with "project"`,
|
|
198
|
-
);
|
|
199
|
-
lines.push(`Same-name precedence: ${precedence.join("; ")}.`);
|
|
200
|
-
}
|
|
201
|
-
if (omitted > 0) {
|
|
202
|
-
lines.push(
|
|
203
|
-
`[${omitted} additional agent definition${omitted === 1 ? "" : "s"} omitted due to metadata bounds or incomplete discovery.]`,
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
if (discoveryIncomplete) {
|
|
207
|
-
lines.push("[Agent metadata discovery was incomplete; some definitions may be unavailable.]");
|
|
208
|
-
}
|
|
209
|
-
return lines.join("\n");
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
let listedCount = boundedEntries.length;
|
|
213
|
-
let text = render(
|
|
214
|
-
boundedEntries.slice(0, listedCount),
|
|
215
|
-
allEntries.length - listedCount + discoveryOmissions,
|
|
216
|
-
);
|
|
217
|
-
while (text.length > maxCharacters && listedCount > 0) {
|
|
218
|
-
listedCount -= 1;
|
|
219
|
-
text = render(
|
|
220
|
-
boundedEntries.slice(0, listedCount),
|
|
221
|
-
allEntries.length - listedCount + discoveryOmissions,
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
return { text, omitted: allEntries.length - listedCount + discoveryOmissions };
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export function discoverAgentCatalog(
|
|
228
|
-
cwd: string,
|
|
229
|
-
projectTrusted: boolean,
|
|
230
|
-
config?: SubagentSettings,
|
|
231
|
-
): AgentCatalog {
|
|
232
|
-
const options: AgentDiscoveryOptions = {
|
|
233
|
-
maxFiles: DEFAULT_AGENT_CATALOG_MAX_FILES_PER_SCOPE,
|
|
234
|
-
maxFileBytes: DEFAULT_AGENT_CATALOG_MAX_FILE_BYTES,
|
|
235
|
-
maxTotalBytes: DEFAULT_AGENT_CATALOG_MAX_TOTAL_BYTES_PER_SCOPE,
|
|
236
|
-
};
|
|
237
|
-
return {
|
|
238
|
-
user: discoverAgents(cwd, "user", config, options),
|
|
239
|
-
project: projectTrusted ? discoverAgents(cwd, "project", config, options) : undefined,
|
|
240
|
-
};
|
|
241
|
-
}
|
package/src/agents/discovery.ts
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Filesystem and frontmatter discovery for user and trusted project agents.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as fs from "node:fs";
|
|
6
|
-
import * as path from "node:path";
|
|
7
|
-
import { CONFIG_DIR_NAME, getAgentDir, parseFrontmatter } from "@earendil-works/pi-coding-agent";
|
|
8
|
-
import { normalizeCapabilityManifest } from "../capabilities.js";
|
|
9
|
-
import { BUILT_IN_AGENTS } from "./built-ins.js";
|
|
10
|
-
import type { AgentConfig, AgentScope, SubagentSettings } from "./types.js";
|
|
11
|
-
import { isThinkingLevel } from "./types.js";
|
|
12
|
-
|
|
13
|
-
export interface AgentDiscoveryResult {
|
|
14
|
-
agents: AgentConfig[];
|
|
15
|
-
projectAgentsDir: string | null;
|
|
16
|
-
omittedAgentDefinitions?: number;
|
|
17
|
-
metadataDiscoveryIncomplete?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface AgentDiscoveryOptions {
|
|
21
|
-
maxFiles?: number;
|
|
22
|
-
maxFileBytes?: number;
|
|
23
|
-
maxTotalBytes?: number;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface LoadedAgents {
|
|
27
|
-
agents: AgentConfig[];
|
|
28
|
-
omittedAgentDefinitions: number;
|
|
29
|
-
metadataDiscoveryIncomplete: boolean;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function readFileBoundedSync(
|
|
33
|
-
filePath: string,
|
|
34
|
-
maxBytes: number | undefined,
|
|
35
|
-
): { content?: string; bytes: number; limited: boolean } {
|
|
36
|
-
if (maxBytes === undefined) {
|
|
37
|
-
try {
|
|
38
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
39
|
-
return { content, bytes: Buffer.byteLength(content), limited: false };
|
|
40
|
-
} catch {
|
|
41
|
-
return { bytes: 0, limited: false };
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const readLimit = Math.max(0, maxBytes);
|
|
46
|
-
let fd: number | undefined;
|
|
47
|
-
try {
|
|
48
|
-
fd = fs.openSync(filePath, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
|
|
49
|
-
if (!fs.fstatSync(fd).isFile()) return { bytes: 0, limited: false };
|
|
50
|
-
const buffer = Buffer.allocUnsafe(readLimit + 1);
|
|
51
|
-
let offset = 0;
|
|
52
|
-
while (offset < buffer.length) {
|
|
53
|
-
const bytesRead = fs.readSync(fd, buffer, offset, buffer.length - offset, null);
|
|
54
|
-
if (bytesRead === 0) break;
|
|
55
|
-
offset += bytesRead;
|
|
56
|
-
}
|
|
57
|
-
if (offset > readLimit) return { bytes: offset, limited: true };
|
|
58
|
-
return { content: buffer.subarray(0, offset).toString("utf-8"), bytes: offset, limited: false };
|
|
59
|
-
} catch {
|
|
60
|
-
return { bytes: 0, limited: false };
|
|
61
|
-
} finally {
|
|
62
|
-
if (fd !== undefined) fs.closeSync(fd);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function loadAgentsFromDir(
|
|
67
|
-
dir: string,
|
|
68
|
-
source: "user" | "project",
|
|
69
|
-
options: AgentDiscoveryOptions = {},
|
|
70
|
-
): LoadedAgents {
|
|
71
|
-
const agents: AgentConfig[] = [];
|
|
72
|
-
let omittedAgentDefinitions = 0;
|
|
73
|
-
|
|
74
|
-
let entries: fs.Dirent[];
|
|
75
|
-
try {
|
|
76
|
-
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
77
|
-
} catch (error) {
|
|
78
|
-
return {
|
|
79
|
-
agents,
|
|
80
|
-
omittedAgentDefinitions,
|
|
81
|
-
metadataDiscoveryIncomplete: (error as NodeJS.ErrnoException).code !== "ENOENT",
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const agentEntries = entries
|
|
86
|
-
.filter((entry) => entry.name.endsWith(".md"))
|
|
87
|
-
.filter((entry) => entry.isFile() || entry.isSymbolicLink());
|
|
88
|
-
let totalBytes = 0;
|
|
89
|
-
|
|
90
|
-
for (const [index, entry] of agentEntries.entries()) {
|
|
91
|
-
if (options.maxFiles !== undefined && index >= options.maxFiles) {
|
|
92
|
-
omittedAgentDefinitions += agentEntries.length - index;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
const filePath = path.join(dir, entry.name);
|
|
96
|
-
const remainingBytes =
|
|
97
|
-
options.maxTotalBytes === undefined ? undefined : options.maxTotalBytes - totalBytes;
|
|
98
|
-
if (remainingBytes !== undefined && remainingBytes <= 0) {
|
|
99
|
-
omittedAgentDefinitions++;
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
const maxBytes =
|
|
103
|
-
options.maxFileBytes === undefined
|
|
104
|
-
? remainingBytes
|
|
105
|
-
: remainingBytes === undefined
|
|
106
|
-
? options.maxFileBytes
|
|
107
|
-
: Math.min(options.maxFileBytes, remainingBytes);
|
|
108
|
-
const loaded = readFileBoundedSync(filePath, maxBytes);
|
|
109
|
-
totalBytes += Math.min(loaded.bytes, maxBytes ?? loaded.bytes);
|
|
110
|
-
if (loaded.limited || loaded.content === undefined) {
|
|
111
|
-
if (loaded.limited) omittedAgentDefinitions++;
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const { frontmatter, body } = parseFrontmatter<Record<string, unknown>>(loaded.content);
|
|
116
|
-
|
|
117
|
-
if (typeof frontmatter.name !== "string" || typeof frontmatter.description !== "string") {
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const hasTools = hasOwn(frontmatter, "tools");
|
|
122
|
-
const rawTools = frontmatter.tools;
|
|
123
|
-
let tools: string[] | undefined;
|
|
124
|
-
if (hasTools) {
|
|
125
|
-
if (rawTools === null) {
|
|
126
|
-
tools = [];
|
|
127
|
-
} else if (Array.isArray(rawTools)) {
|
|
128
|
-
if (!rawTools.every((tool): tool is string => typeof tool === "string")) continue;
|
|
129
|
-
tools = rawTools.map((tool) => tool.trim()).filter(Boolean);
|
|
130
|
-
} else if (typeof rawTools === "string") {
|
|
131
|
-
tools = rawTools
|
|
132
|
-
.split(",")
|
|
133
|
-
.map((tool) => tool.trim())
|
|
134
|
-
.filter(Boolean);
|
|
135
|
-
} else {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
agents.push({
|
|
141
|
-
name: frontmatter.name,
|
|
142
|
-
description: frontmatter.description,
|
|
143
|
-
...(hasTools ? { tools: tools ?? [] } : {}),
|
|
144
|
-
model: typeof frontmatter.model === "string" ? frontmatter.model : undefined,
|
|
145
|
-
thinkingLevel: isThinkingLevel(frontmatter.thinkingLevel)
|
|
146
|
-
? frontmatter.thinkingLevel
|
|
147
|
-
: undefined,
|
|
148
|
-
capabilityManifest: normalizeCapabilityManifest(frontmatter.capabilityManifest),
|
|
149
|
-
systemPrompt: body,
|
|
150
|
-
source,
|
|
151
|
-
filePath,
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return { agents, omittedAgentDefinitions, metadataDiscoveryIncomplete: false };
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function isDirectory(p: string): boolean {
|
|
159
|
-
try {
|
|
160
|
-
return fs.statSync(p).isDirectory();
|
|
161
|
-
} catch {
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function findNearestProjectAgentsDir(cwd: string): string | null {
|
|
167
|
-
let currentDir = cwd;
|
|
168
|
-
while (true) {
|
|
169
|
-
const candidate = path.join(currentDir, CONFIG_DIR_NAME, "agents");
|
|
170
|
-
if (isDirectory(candidate)) return candidate;
|
|
171
|
-
|
|
172
|
-
const parentDir = path.dirname(currentDir);
|
|
173
|
-
if (parentDir === currentDir) return null;
|
|
174
|
-
currentDir = parentDir;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function hasOwn(obj: object, key: PropertyKey): boolean {
|
|
179
|
-
return Object.hasOwn(obj, key);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function applyAgentOverride(
|
|
183
|
-
agent: AgentConfig,
|
|
184
|
-
override: NonNullable<SubagentSettings["agents"]>[string],
|
|
185
|
-
): AgentConfig {
|
|
186
|
-
const nextAgent: AgentConfig = { ...agent };
|
|
187
|
-
if (hasOwn(override, "tools")) nextAgent.tools = override.tools;
|
|
188
|
-
if (hasOwn(override, "model")) {
|
|
189
|
-
nextAgent.model = override.model === null ? undefined : override.model;
|
|
190
|
-
}
|
|
191
|
-
if (hasOwn(override, "thinkingLevel")) {
|
|
192
|
-
nextAgent.thinkingLevel = override.thinkingLevel === null ? undefined : override.thinkingLevel;
|
|
193
|
-
}
|
|
194
|
-
if (hasOwn(override, "timeoutMs")) {
|
|
195
|
-
nextAgent.timeoutMs = override.timeoutMs === null ? undefined : override.timeoutMs;
|
|
196
|
-
}
|
|
197
|
-
return nextAgent;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export function discoverAgents(
|
|
201
|
-
cwd: string,
|
|
202
|
-
scope: AgentScope,
|
|
203
|
-
config?: SubagentSettings,
|
|
204
|
-
options: AgentDiscoveryOptions = {},
|
|
205
|
-
): AgentDiscoveryResult {
|
|
206
|
-
const userDir = path.join(getAgentDir(), "agents");
|
|
207
|
-
const projectAgentsDir = findNearestProjectAgentsDir(cwd);
|
|
208
|
-
|
|
209
|
-
const userLoaded =
|
|
210
|
-
scope === "project"
|
|
211
|
-
? { agents: [], omittedAgentDefinitions: 0, metadataDiscoveryIncomplete: false }
|
|
212
|
-
: loadAgentsFromDir(userDir, "user", options);
|
|
213
|
-
const projectLoaded =
|
|
214
|
-
scope === "user" || !projectAgentsDir
|
|
215
|
-
? { agents: [], omittedAgentDefinitions: 0, metadataDiscoveryIncomplete: false }
|
|
216
|
-
: loadAgentsFromDir(projectAgentsDir, "project", options);
|
|
217
|
-
const userAgents = userLoaded.agents;
|
|
218
|
-
const projectAgents = projectLoaded.agents;
|
|
219
|
-
|
|
220
|
-
const agentMap = new Map<string, AgentConfig>();
|
|
221
|
-
|
|
222
|
-
// Lowest priority: built-ins are always available, then user agents, then
|
|
223
|
-
// trusted project agents if requested. This mirrors the subagent boundary
|
|
224
|
-
// pattern in ./src: stable built-ins plus overridable local definitions.
|
|
225
|
-
for (const agent of BUILT_IN_AGENTS) agentMap.set(agent.name, agent);
|
|
226
|
-
|
|
227
|
-
if (scope === "both") {
|
|
228
|
-
for (const agent of userAgents) agentMap.set(agent.name, agent);
|
|
229
|
-
for (const agent of projectAgents) agentMap.set(agent.name, agent);
|
|
230
|
-
} else if (scope === "user") {
|
|
231
|
-
for (const agent of userAgents) agentMap.set(agent.name, agent);
|
|
232
|
-
} else {
|
|
233
|
-
for (const agent of projectAgents) agentMap.set(agent.name, agent);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// Apply user-configured overrides (from /subagents → Agent tool settings) on top of
|
|
237
|
-
// the final resolved agent map, regardless of agent source.
|
|
238
|
-
const configuredAgents = config?.agents ?? {};
|
|
239
|
-
for (const [name, override] of Object.entries(configuredAgents)) {
|
|
240
|
-
const agent = agentMap.get(name);
|
|
241
|
-
if (!agent) continue;
|
|
242
|
-
agentMap.set(name, applyAgentOverride(agent, override));
|
|
243
|
-
}
|
|
244
|
-
const legacyScoutOverride = configuredAgents.scout;
|
|
245
|
-
const explorerAgent = agentMap.get("explorer");
|
|
246
|
-
if (
|
|
247
|
-
legacyScoutOverride &&
|
|
248
|
-
explorerAgent &&
|
|
249
|
-
!hasOwn(configuredAgents, "explorer") &&
|
|
250
|
-
!agentMap.has("scout")
|
|
251
|
-
) {
|
|
252
|
-
agentMap.set("explorer", applyAgentOverride(explorerAgent, legacyScoutOverride));
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const omittedAgentDefinitions =
|
|
256
|
-
userLoaded.omittedAgentDefinitions + projectLoaded.omittedAgentDefinitions;
|
|
257
|
-
const metadataDiscoveryIncomplete =
|
|
258
|
-
userLoaded.metadataDiscoveryIncomplete || projectLoaded.metadataDiscoveryIncomplete;
|
|
259
|
-
return {
|
|
260
|
-
agents: Array.from(agentMap.values()),
|
|
261
|
-
projectAgentsDir,
|
|
262
|
-
...(omittedAgentDefinitions > 0 ? { omittedAgentDefinitions } : {}),
|
|
263
|
-
...(metadataDiscoveryIncomplete ? { metadataDiscoveryIncomplete } : {}),
|
|
264
|
-
};
|
|
265
|
-
}
|
package/src/agents/types.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Foundational agent and settings types with dependency-light validation helpers.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { AgentCapabilityManifest } from "../capabilities.js";
|
|
6
|
-
import type { SubagentUsageRecordingSettings } from "../usage-recording-config.js";
|
|
7
|
-
|
|
8
|
-
export const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"] as const;
|
|
9
|
-
|
|
10
|
-
export type SubagentThinkingLevel = (typeof THINKING_LEVELS)[number];
|
|
11
|
-
|
|
12
|
-
export function isThinkingLevel(value: unknown): value is SubagentThinkingLevel {
|
|
13
|
-
return typeof value === "string" && THINKING_LEVELS.includes(value as SubagentThinkingLevel);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type AgentScope = "user" | "project" | "both";
|
|
17
|
-
|
|
18
|
-
export type AgentSource = "built-in" | "user" | "project";
|
|
19
|
-
|
|
20
|
-
export const DEFAULT_PI_TOOL_NAMES = ["read", "bash", "edit", "write"] as const;
|
|
21
|
-
|
|
22
|
-
export function resolveAgentToolNames(tools: readonly string[] | undefined): string[] {
|
|
23
|
-
return [...new Set(tools ?? DEFAULT_PI_TOOL_NAMES)];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface AgentConfig {
|
|
27
|
-
name: string;
|
|
28
|
-
description: string;
|
|
29
|
-
tools?: string[];
|
|
30
|
-
model?: string;
|
|
31
|
-
thinkingLevel?: SubagentThinkingLevel;
|
|
32
|
-
timeoutMs?: number;
|
|
33
|
-
capabilityManifest?: AgentCapabilityManifest;
|
|
34
|
-
systemPrompt: string;
|
|
35
|
-
source: AgentSource;
|
|
36
|
-
filePath: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface SubagentAgentConfig {
|
|
40
|
-
tools?: string[];
|
|
41
|
-
model?: string | null;
|
|
42
|
-
thinkingLevel?: SubagentThinkingLevel | null;
|
|
43
|
-
timeoutMs?: number | null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type SubagentTransportKind = "subprocess" | "in-process" | "rpc" | "auto";
|
|
47
|
-
|
|
48
|
-
export type CompletionDelivery = "next-turn" | "auto-resume";
|
|
49
|
-
|
|
50
|
-
export const CONSULT_RESOURCE_POLICIES = ["project-context", "none", "all"] as const;
|
|
51
|
-
|
|
52
|
-
export type ConsultResourcePolicy = (typeof CONSULT_RESOURCE_POLICIES)[number];
|
|
53
|
-
|
|
54
|
-
export interface SubagentConsultSettings {
|
|
55
|
-
resources?: ConsultResourcePolicy;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const CONSULTATION_CWD_POLICIES = ["anywhere", "current-workspace"] as const;
|
|
59
|
-
export type ConsultationCwdPolicy = (typeof CONSULTATION_CWD_POLICIES)[number];
|
|
60
|
-
|
|
61
|
-
export const DELEGATION_CWD_POLICIES = [
|
|
62
|
-
"trusted-targets",
|
|
63
|
-
"current-workspace",
|
|
64
|
-
"anywhere",
|
|
65
|
-
] as const;
|
|
66
|
-
export type DelegationCwdPolicy = (typeof DELEGATION_CWD_POLICIES)[number];
|
|
67
|
-
|
|
68
|
-
export interface SubagentCwdPolicySettings {
|
|
69
|
-
consultation?: ConsultationCwdPolicy;
|
|
70
|
-
delegation?: DelegationCwdPolicy;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface SubagentBlockingSettings {
|
|
74
|
-
enabled?: boolean;
|
|
75
|
-
maxParallelTasks?: number;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export interface SubagentRuntimeSettings {
|
|
79
|
-
enabled?: boolean;
|
|
80
|
-
transport?: SubagentTransportKind;
|
|
81
|
-
completionDelivery?: CompletionDelivery;
|
|
82
|
-
maxAgents?: number;
|
|
83
|
-
maxActiveTurns?: number;
|
|
84
|
-
maxDepth?: number;
|
|
85
|
-
maxChildrenPerAgent?: number;
|
|
86
|
-
maxMailboxMessages?: number;
|
|
87
|
-
maxMailboxMessageBytes?: number;
|
|
88
|
-
idleTtlMs?: number;
|
|
89
|
-
retentionDays?: number;
|
|
90
|
-
maxStoredAgents?: number;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface SubagentSettings {
|
|
94
|
-
agents?: Record<string, SubagentAgentConfig>;
|
|
95
|
-
blocking?: SubagentBlockingSettings;
|
|
96
|
-
stateful?: SubagentRuntimeSettings;
|
|
97
|
-
consult?: SubagentConsultSettings;
|
|
98
|
-
cwdPolicy?: SubagentCwdPolicySettings;
|
|
99
|
-
usageRecording?: SubagentUsageRecordingSettings;
|
|
100
|
-
}
|
package/src/agents.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compatibility facade for the former mixed agent module.
|
|
3
|
-
*
|
|
4
|
-
* New source modules should import from the cohesive agent boundaries directly.
|
|
5
|
-
* Keep this facade while tests and supported internal entrypoints still depend on the old path.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export { getBuiltInAgent } from "./agents/built-ins.js";
|
|
9
|
-
export {
|
|
10
|
-
type AgentCatalog,
|
|
11
|
-
type AgentCatalogFormatOptions,
|
|
12
|
-
type AgentCatalogFormatResult,
|
|
13
|
-
DEFAULT_AGENT_CATALOG_MAX_CHARACTERS,
|
|
14
|
-
DEFAULT_AGENT_CATALOG_MAX_DESCRIPTION_LENGTH,
|
|
15
|
-
DEFAULT_AGENT_CATALOG_MAX_FILE_BYTES,
|
|
16
|
-
DEFAULT_AGENT_CATALOG_MAX_FILES_PER_SCOPE,
|
|
17
|
-
DEFAULT_AGENT_CATALOG_MAX_ITEMS,
|
|
18
|
-
DEFAULT_AGENT_CATALOG_MAX_TOTAL_BYTES_PER_SCOPE,
|
|
19
|
-
discoverAgentCatalog,
|
|
20
|
-
formatAgentCatalog,
|
|
21
|
-
formatAgentList,
|
|
22
|
-
} from "./agents/catalog.js";
|
|
23
|
-
export {
|
|
24
|
-
type AgentDiscoveryOptions,
|
|
25
|
-
type AgentDiscoveryResult,
|
|
26
|
-
discoverAgents,
|
|
27
|
-
} from "./agents/discovery.js";
|
|
28
|
-
export {
|
|
29
|
-
type AgentConfig,
|
|
30
|
-
type AgentScope,
|
|
31
|
-
type AgentSource,
|
|
32
|
-
CONSULT_RESOURCE_POLICIES,
|
|
33
|
-
CONSULTATION_CWD_POLICIES,
|
|
34
|
-
type CompletionDelivery,
|
|
35
|
-
type ConsultationCwdPolicy,
|
|
36
|
-
type ConsultResourcePolicy,
|
|
37
|
-
DEFAULT_PI_TOOL_NAMES,
|
|
38
|
-
DELEGATION_CWD_POLICIES,
|
|
39
|
-
type DelegationCwdPolicy,
|
|
40
|
-
isThinkingLevel,
|
|
41
|
-
resolveAgentToolNames,
|
|
42
|
-
type SubagentAgentConfig,
|
|
43
|
-
type SubagentBlockingSettings,
|
|
44
|
-
type SubagentConsultSettings,
|
|
45
|
-
type SubagentCwdPolicySettings,
|
|
46
|
-
type SubagentRuntimeSettings,
|
|
47
|
-
type SubagentSettings,
|
|
48
|
-
type SubagentThinkingLevel,
|
|
49
|
-
type SubagentTransportKind,
|
|
50
|
-
THINKING_LEVELS,
|
|
51
|
-
} from "./agents/types.js";
|