pal-code 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +3 -3
  2. package/SYSTEM.md +3 -3
  3. package/bin/pal-code.js +37 -11
  4. package/package.json +7 -14
  5. package/packages/cli/README.md +2 -2
  6. package/packages/cli/src/commands/ext.ts +1 -1
  7. package/packages/cli/src/commands.ts +1 -1
  8. package/packages/cli/src/components/render-history.ts +2 -2
  9. package/packages/cli/src/config.ts +2 -2
  10. package/packages/cli/src/index.ts +7 -7
  11. package/packages/cli/src/overlays/key-input.ts +1 -1
  12. package/packages/cli/src/overlays/model-picker.ts +2 -2
  13. package/packages/cli/src/overlays/session-picker.ts +1 -1
  14. package/packages/cli/src/overlays/wizard.ts +1 -1
  15. package/packages/cli/src/state.ts +2 -2
  16. package/packages/cli/src/turn.ts +16 -9
  17. package/packages/cli/src/utils/permissions.ts +3 -3
  18. package/packages/core/src/agent/events.ts +0 -36
  19. package/packages/core/src/agent/fallback.ts +0 -344
  20. package/packages/core/src/agent/index.ts +0 -35
  21. package/packages/core/src/agent/roles.ts +0 -188
  22. package/packages/core/src/agent/run.ts +0 -713
  23. package/packages/core/src/agent/scope.ts +0 -34
  24. package/packages/core/src/agent/todos.ts +0 -66
  25. package/packages/core/src/compaction.ts +0 -243
  26. package/packages/core/src/config.ts +0 -387
  27. package/packages/core/src/extensions.ts +0 -178
  28. package/packages/core/src/index.ts +0 -157
  29. package/packages/core/src/logger.ts +0 -54
  30. package/packages/core/src/provider/auth.ts +0 -153
  31. package/packages/core/src/provider/complete.ts +0 -63
  32. package/packages/core/src/provider/index.ts +0 -6
  33. package/packages/core/src/provider/openrouter.ts +0 -304
  34. package/packages/core/src/provider/pick-model.ts +0 -43
  35. package/packages/core/src/provider/registry.ts +0 -222
  36. package/packages/core/src/provider/types.ts +0 -61
  37. package/packages/core/src/repo-map.ts +0 -177
  38. package/packages/core/src/session/index.ts +0 -2
  39. package/packages/core/src/session/store.ts +0 -677
  40. package/packages/core/src/session/types.ts +0 -72
  41. package/packages/core/src/snapshots.ts +0 -107
  42. package/packages/core/src/tools/definitions.ts +0 -365
  43. package/packages/core/src/tools/executor.ts +0 -1363
  44. package/packages/core/src/tools/index.ts +0 -5
  45. package/packages/core/src/tools/search.ts +0 -201
  46. package/scripts/postinstall.js +0 -121
  47. package/scripts/preinstall.js +0 -51
@@ -1,344 +0,0 @@
1
- /**
2
- * Fallback / retry policy — the "keep the turn alive" wrapper around runAgent.
3
- *
4
- * This lives in core, not the CLI, because it *decides* what the agent does
5
- * (which model to try next, whether to back off, whether to give up). The CLI
6
- * only renders the events this yields.
7
- *
8
- * Strategy: same provider first (same rate-limit pool), then cross-provider.
9
- * - quota exhausted → switch immediately (retrying burns RPM for nothing)
10
- * - rate limited → exponential backoff, `maxRetries` attempts, then switch
11
- * - other retryable → backoff, `maxRetries` attempts, then switch
12
- * - anything else → rethrow
13
- */
14
-
15
- import {createOpenRouterProvider} from '../provider/openrouter.js';
16
- import {PROVIDERS, providerForModel} from '../provider/registry.js';
17
- import type {ProviderDef} from '../provider/registry.js';
18
- import type {ProviderKeys} from '../provider/auth.js';
19
- import type {Provider} from '../provider/types.js';
20
- import {
21
- runAgent,
22
- type AgentRunEvent,
23
- type ConversationMessage,
24
- type RunAgentOptions,
25
- } from './run.js';
26
-
27
- export function sleep(ms: number): Promise<void> {
28
- return new Promise((resolve) => setTimeout(resolve, ms));
29
- }
30
-
31
- export function isRetryableError(msg: string): boolean {
32
- // Transient transport failures. Bun says "Was there a typo in the url or
33
- // port?"; Node says "fetch failed". Neither is the model's fault and both
34
- // usually succeed on a retry — without this they killed the whole turn.
35
- if (
36
- /typo in the url|fetch failed|socket|network|ECONNRESET|ECONNREFUSED|ENOTFOUND|ETIMEDOUT|EAI_AGAIN|EPIPE|terminated/i.test(
37
- msg,
38
- )
39
- ) {
40
- return true;
41
- }
42
- return (
43
- msg.includes('429') ||
44
- msg.includes('Rate') ||
45
- msg.includes('FreeUsage') ||
46
- msg.includes('403') ||
47
- msg.includes('unavailable') ||
48
- msg.includes('UNAVAILABLE') ||
49
- msg.includes('503') ||
50
- msg.includes('timed out')
51
- );
52
- }
53
-
54
- /** Quota exhaustion = do NOT retry (burns RPM for nothing). Switch provider. */
55
- export function isQuotaExhausted(msg: string): boolean {
56
- return (
57
- msg.includes('FreeUsage') ||
58
- msg.includes('quota') ||
59
- msg.includes('Quota') ||
60
- msg.includes('insufficient_quota') ||
61
- msg.includes('billing')
62
- );
63
- }
64
-
65
- /** RPM rate limit = brief backoff + limited retries, then switch. */
66
- export function isRateLimited(msg: string): boolean {
67
- return msg.includes('429') || msg.includes('Rate limit') || msg.includes('rate-limit');
68
- }
69
-
70
- /** True when a provider is usable: it has a key, or is explicitly keyless. */
71
- export function providerAccessible(
72
- def: {id: string; keyOptional?: boolean},
73
- keys: ProviderKeys,
74
- ): boolean {
75
- return Boolean(keys[def.id]) || def.keyOptional === true;
76
- }
77
-
78
- /** Short display name for a `provider/model` spec. */
79
- export function shortModel(model: string): string {
80
- return model.split('/').pop()?.split(':')[0] ?? model;
81
- }
82
-
83
- /** Per-provider `/models` cache. `null` = the fetch failed. */
84
- const liveModels = new Map<string, string[] | null>();
85
-
86
- /**
87
- * Live model ids for a provider, cached. Returns `null` when the fetch fails so
88
- * callers can distinguish "unknown" from "empty".
89
- */
90
- export async function fetchProviderModels(
91
- def: ProviderDef,
92
- apiKey: string,
93
- ): Promise<string[] | null> {
94
- if (liveModels.has(def.id)) return liveModels.get(def.id) ?? null;
95
- try {
96
- const p = createOpenRouterProvider({
97
- id: def.id,
98
- baseUrl: def.baseUrl,
99
- apiKey: apiKey || (def.keyOptional ? 'public' : ''),
100
- headers: def.headers,
101
- modelPrefix: def.modelPrefix,
102
- });
103
- await p.init();
104
- const ids = (await p.models()).map((m) => m.id);
105
- liveModels.set(def.id, ids.length > 0 ? ids : null);
106
- return ids.length > 0 ? ids : null;
107
- } catch {
108
- liveModels.set(def.id, null);
109
- return null;
110
- }
111
- }
112
-
113
- /** Clear the `/models` cache (used after a key change). */
114
- export function clearModelCache(): void {
115
- liveModels.clear();
116
- }
117
-
118
- /** Live ids, falling back to the provider's curated list. */
119
- export async function resolveModelIds(def: ProviderDef, apiKey: string): Promise<string[]> {
120
- const ids = await fetchProviderModels(def, apiKey);
121
- // When keyOptional with no real key, filter to only free models to avoid
122
- // wasting fallback attempts on paid models that require billing.
123
- const isKeyless = def.keyOptional === true && !apiKey;
124
- if (ids && ids.length > 0) {
125
- if (isKeyless && def.freeModelPattern) {
126
- const re = new RegExp(def.freeModelPattern);
127
- const free = ids.filter((id) => re.test(id));
128
- return free.length > 0 ? free : def.fallbackModels;
129
- }
130
- return ids;
131
- }
132
- return def.fallbackModels;
133
- }
134
-
135
- /** Default provider factory: registry base URL + `PAL`-agnostic env override. */
136
- export function createProviderFor(modelSpec: string, keys: ProviderKeys): Provider {
137
- const {provider: def} = providerForModel(modelSpec, Object.keys(keys));
138
- const envOverride = process.env[`${def.id.toUpperCase()}_BASE_URL`];
139
- return createOpenRouterProvider({
140
- id: def.id,
141
- baseUrl: envOverride ?? def.baseUrl,
142
- apiKey: keys[def.id] ?? (def.keyOptional ? 'public' : ''),
143
- headers: def.headers,
144
- modelPrefix: def.modelPrefix,
145
- });
146
- }
147
-
148
- export interface RunWithFallbackOptions {
149
- /** Conversation history — MUTATED IN PLACE. */
150
- messages: ConversationMessage[];
151
- /** Tool definitions exposed to the model. */
152
- tools: RunAgentOptions['tools'];
153
- /** Requested `provider/model` spec. */
154
- model: string;
155
- systemPrompt: string;
156
- maxToolRounds?: number;
157
- contextLimit?: number;
158
- reasoningEffort?: 'low' | 'medium' | 'high';
159
- /**
160
- * 1-based store seq of genuinely-uncompacted history. Passed straight through
161
- * to `runAgent`, which seeded its own count-space mark from it.
162
- */
163
- compactedSeq?: number;
164
- /**
165
- * Pre-existing compaction summary from a resumed session. Threaded through
166
- * to `runAgent` so resumed sessions don't lose their compacted context.
167
- */
168
- compactionNote?: string;
169
- /** Retries per model before switching (default 1). */
170
- maxRetries?: number;
171
- /** Base backoff in ms; doubles each attempt (default 2000). */
172
- retryBaseMs?: number;
173
- keys: ProviderKeys;
174
- executeTool: RunAgentOptions['executeTool'];
175
- /**
176
- * Optional override for the tool executor in child agents. When provided,
177
- * delegated agents use this instead of the module-level `executeTool`.
178
- * Used by the CLI to inject permission gating into child agents.
179
- */
180
- childExecuteTool?: RunAgentOptions['executeTool'];
181
- signal?: AbortSignal;
182
- /** Read-only turn — `delegate` may not spawn anything that mutates state. */
183
- readOnly?: boolean;
184
- /**
185
- * Tool names this turn may dispatch. Enforced in `executeTool`, so a
186
- * hallucinated call for an unoffered tool is refused rather than run.
187
- */
188
- allowedTools?: string[];
189
- /** Injectable for tests. */
190
- createProvider?: (modelSpec: string, keys: ProviderKeys) => Provider;
191
- }
192
-
193
- /**
194
- * Drive `runAgent` with provider/model fallback.
195
- *
196
- * Yields the inner `AgentRunEvent`s, plus:
197
- * - `{type:'model-start'}` when it commits to a model (so the UI can relabel)
198
- * - `{type:'notice'}` for each fallback/backoff decision
199
- *
200
- * Returns normally when a model completes the turn (including a user abort).
201
- * Throws only when every candidate model failed.
202
- */
203
- export async function* runWithFallback(
204
- opts: RunWithFallbackOptions,
205
- ): AsyncGenerator<AgentRunEvent> {
206
- const {
207
- messages,
208
- tools,
209
- model,
210
- systemPrompt,
211
- maxToolRounds,
212
- contextLimit,
213
- reasoningEffort,
214
- compactedSeq,
215
- compactionNote,
216
- maxRetries = 1,
217
- retryBaseMs = 2000,
218
- keys,
219
- executeTool,
220
- childExecuteTool,
221
- signal,
222
- readOnly,
223
- allowedTools,
224
- createProvider = createProviderFor,
225
- } = opts;
226
-
227
- const {provider: baseDef, model: baseModel} = providerForModel(model, Object.keys(keys));
228
-
229
- // Same provider: other models from its live list. Never invented — if the
230
- // fetch failed there are simply no same-provider fallbacks.
231
- const sameProviderModels: string[] = [];
232
- if (providerAccessible(baseDef, keys)) {
233
- const ids = await resolveModelIds(baseDef, keys[baseDef.id] ?? '');
234
- for (const id of ids) {
235
- if (id !== baseModel) sameProviderModels.push(`${baseDef.id}/${id}`);
236
- }
237
- }
238
-
239
- // Cross provider: only accessible providers, at their default model.
240
- const crossProviderModels = PROVIDERS.filter(
241
- (p) => p.id !== baseDef.id && providerAccessible(p, keys),
242
- ).map((p) => `${p.id}/${p.defaultModel}`);
243
-
244
- const modelsToTry = [model, ...sameProviderModels, ...crossProviderModels];
245
-
246
- // Track consecutive quota exhaustion per provider. If ALL models from a
247
- // provider share the same quota pool (e.g. Zen free tier), short-circuit
248
- // after the first quota failure — retrying the remaining models wastes time.
249
- const quotaExhaustedProviders = new Set<string>();
250
-
251
- for (const modelSpec of modelsToTry) {
252
- const {provider: modelDef, model: bareModel} = providerForModel(modelSpec, Object.keys(keys));
253
- if (!providerAccessible(modelDef, keys)) continue;
254
-
255
- // Skip remaining models from a provider whose entire quota is exhausted.
256
- if (quotaExhaustedProviders.has(modelDef.id)) continue;
257
-
258
- // Handed to tools so `delegate` can spawn a working child agent.
259
- const providerConfig = {
260
- model: bareModel,
261
- apiKey: keys[modelDef.id] ?? (modelDef.keyOptional ? 'public' : ''),
262
- baseUrl: modelDef.baseUrl,
263
- keys: keys as Record<string, string>,
264
- // Carried through to `executeTool` so a read-only turn's `delegate` can
265
- // refuse to spawn anything that would mutate files.
266
- readOnly: readOnly ?? false,
267
- // Carried through so `executeTool` can refuse a tool the turn may not use.
268
- allowedTools,
269
- // CLI-injected permission-gated executor for child agents.
270
- childExecuteTool,
271
- };
272
-
273
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
274
- // Snapshot the message count so a mid-turn failure can be rolled back.
275
- // runAgent mutates `messages` in place; without rollback a retryable
276
- // transport error on round 3 leaves rounds 1–2's assistant + tool
277
- // messages in history, causing duplicate tool execution on retry.
278
- const snapshotLen = messages.length;
279
- try {
280
- const provider = createProvider(modelSpec, keys);
281
- await provider.init();
282
- yield {type: 'model-start', model: modelSpec};
283
-
284
- yield* runAgent({
285
- messages,
286
- tools,
287
- provider,
288
- model: bareModel,
289
- systemPrompt,
290
- maxRounds: maxToolRounds,
291
- contextLimit,
292
- reasoningEffort,
293
- compactedSeq,
294
- compactionNote,
295
- providerConfig,
296
- executeTool,
297
- signal,
298
- });
299
- return;
300
- } catch (err) {
301
- // Roll back any messages appended during the failed attempt so the
302
- // retry starts from a clean state — no orphaned assistant or tool rows.
303
- messages.length = snapshotLen;
304
- const msg = err instanceof Error ? err.message : String(err);
305
-
306
- if (isQuotaExhausted(msg)) {
307
- yield {
308
- type: 'notice',
309
- text: `${modelSpec} quota exhausted — skipping remaining ${modelDef.id} models`,
310
- };
311
- quotaExhaustedProviders.add(modelDef.id);
312
- break; // next model (from a different provider)
313
- }
314
-
315
- if (isRateLimited(msg)) {
316
- if (attempt < maxRetries) {
317
- const delay = retryBaseMs * 2 ** attempt;
318
- yield {
319
- type: 'notice',
320
- text: `${modelSpec} rate-limited, retry in ${delay / 1000}s…`,
321
- };
322
- await sleep(delay);
323
- continue;
324
- }
325
- yield {type: 'notice', text: `${modelSpec} exhausted, trying next…`};
326
- break;
327
- }
328
-
329
- if (isRetryableError(msg)) {
330
- if (attempt < maxRetries) {
331
- await sleep(retryBaseMs * 2 ** attempt);
332
- continue;
333
- }
334
- break;
335
- }
336
-
337
- throw err;
338
- }
339
- }
340
- }
341
-
342
- yield {type: 'notice', text: 'All models failed (rate limits). Try again in a few minutes.'};
343
- throw new Error('All models failed');
344
- }
@@ -1,35 +0,0 @@
1
- export {runAgent, summarizeArgs, getEffortParams, buildApiMessages, seqToCount} from './run.js';
2
- export {
3
- runWithFallback,
4
- resolveModelIds,
5
- fetchProviderModels,
6
- clearModelCache,
7
- createProviderFor,
8
- providerAccessible,
9
- shortModel,
10
- isRetryableError,
11
- isQuotaExhausted,
12
- isRateLimited,
13
- sleep,
14
- } from './fallback.js';
15
- export type {RunWithFallbackOptions} from './fallback.js';
16
- export type {
17
- AgentRunEvent,
18
- RunAgentOptions,
19
- RunAgentUsage,
20
- ConversationMessage,
21
- UserMsg,
22
- AssistantMsg,
23
- ToolResultMsg,
24
- } from './run.js';
25
- export {
26
- setTodos,
27
- getTodos,
28
- clearTodos,
29
- formatTodos,
30
- snapshotTodos,
31
- restoreTodos,
32
- } from './todos.js';
33
- export type {Todo, TodoStatus} from './todos.js';
34
- export {captureRunScope, restoreRunScope} from './scope.js';
35
- export type {RunScope} from './scope.js';
@@ -1,188 +0,0 @@
1
- /**
2
- * Role registry — the seam between core's `delegate` tool and the orchestration
3
- * extension (`@pal-code/agents`).
4
- *
5
- * Core must not import `.pal`-adjacent extension config, and extensions must not
6
- * be required for delegation to work. So core defines the *shape* of a role and
7
- * a registry; the extension populates it at load time. If no extension registers
8
- * one, `resolveRoleSpec` returns null and `delegate` falls back to its original
9
- * ad-hoc behaviour.
10
- *
11
- * Two axes, mirroring OMO:
12
- * - `agent` — curated read-only specialist (explore, librarian, …)
13
- * - `category` — implementation lane (build, deep, quick, architect, …)
14
- */
15
-
16
- export type RoleKind = 'agent' | 'category';
17
-
18
- /** A named specialist an agent turn can delegate to. */
19
- export interface RoleSpec {
20
- /** Role name, e.g. 'explore' or 'build'. */
21
- name: string;
22
- /** Which axis this role belongs to. */
23
- kind: RoleKind;
24
- /** One-line description shown to the model in the system prompt. */
25
- description: string;
26
- /** `provider/model` spec. When omitted, the parent's session model is used. */
27
- model?: string;
28
- /** Reasoning effort forwarded to the provider. Default: 'medium'. */
29
- reasoning?: 'low' | 'medium' | 'high';
30
- /** Tool names this role may use. Absent means "use the safe default". */
31
- tools?: string[];
32
- /** Max tool-call rounds for the child. */
33
- maxRounds: number;
34
- /** System prompt for the child agent. */
35
- systemPrompt: string;
36
- }
37
-
38
- export interface RoleProvider {
39
- /** Resolve one role by name, or null if unknown. */
40
- resolve: (name: string, kind: RoleKind) => RoleSpec | null;
41
- /** All roles currently available, for prompt injection + the /roles command. */
42
- list: () => RoleSpec[];
43
- /** Concurrency cap for `delegate_parallel`. Defaults to 3 when omitted. */
44
- maxParallel?: () => number;
45
- /** Primary agents the user can Tab between. Omitted → none. */
46
- listPrimary?: () => PrimarySpec[];
47
- /** Name of the primary agent selected on startup. Omitted → first primary. */
48
- defaultPrimary?: () => string;
49
- }
50
-
51
- /**
52
- * A **primary agent** — an agent the *user* talks to, selected with Tab.
53
- *
54
- * This is the OpenCode/OMO concept: the primary owns the conversation turn.
55
- * It is deliberately distinct from a `RoleSpec`, which is a *delegation target*
56
- * the main agent fans work out to. Confusing the two is the bug this module
57
- * exists to prevent.
58
- */
59
- export interface PrimarySpec {
60
- /** Stable id, e.g. 'pal' or 'plan'. */
61
- name: string;
62
- /** One-line description for the /help listing. */
63
- description: string;
64
- /** Short label shown in the input indicator. Defaults to `name`. */
65
- label?: string;
66
- /** Theme colour key (e.g. 'cyan', 'red'). Defaults to 'cyan'. */
67
- color?: string;
68
- /**
69
- * When set, the main agent is restricted to these tools for the turn —
70
- * this is how a read-only "plan" primary is enforced rather than merely
71
- * requested in the prompt.
72
- */
73
- tools?: string[];
74
- /** Extra system-prompt guidance prepended to the base prompt. */
75
- systemPrompt?: string;
76
- /**
77
- * Which side of the plan/execute handoff this primary serves.
78
- *
79
- * When set, it is authoritative — the front-end uses it instead of inferring
80
- * from `tools`, so a config typo can't silently swap the two roles.
81
- */
82
- role?: 'plan' | 'orchestrator';
83
- }
84
-
85
- /** Fallback concurrency when no extension registers one. */
86
- export const DEFAULT_MAX_PARALLEL = 3;
87
-
88
- let _provider: RoleProvider | null = null;
89
-
90
- /**
91
- * Register the role provider. Called by the orchestration extension's setup
92
- * hook. A later registration replaces the previous one (so `/reload` works).
93
- */
94
- export function registerRoleProvider(provider: RoleProvider): void {
95
- _provider = provider;
96
- }
97
-
98
- /** Unregister the role provider (used by `/reload` and tests). */
99
- export function clearRoleProvider(): void {
100
- _provider = null;
101
- }
102
-
103
- /** Resolve a role by name and axis. Returns null when no provider is registered. */
104
- export function resolveRoleSpec(name: string, kind: RoleKind): RoleSpec | null {
105
- return _provider?.resolve(name, kind) ?? null;
106
- }
107
-
108
- /** All roles, or an empty array when no provider is registered. */
109
- export function listRoleSpecs(): RoleSpec[] {
110
- return _provider?.list() ?? [];
111
- }
112
-
113
- /** Concurrency cap for `delegate_parallel`. */
114
- export function getMaxParallel(): number {
115
- try {
116
- return _provider?.maxParallel?.() ?? DEFAULT_MAX_PARALLEL;
117
- } catch {
118
- return DEFAULT_MAX_PARALLEL;
119
- }
120
- }
121
-
122
- /** Primary agents the user can Tab between (empty when none are registered). */
123
- export function listPrimaries(): PrimarySpec[] {
124
- try {
125
- return _provider?.listPrimary?.() ?? [];
126
- } catch {
127
- return [];
128
- }
129
- }
130
-
131
- /** Name of the primary agent to select on startup. */
132
- export function defaultPrimaryName(): string {
133
- const primaries = listPrimaries();
134
- if (primaries.length === 0) return 'pal';
135
- try {
136
- const name = _provider?.defaultPrimary?.();
137
- if (name && primaries.some((p) => p.name === name)) return name;
138
- } catch {
139
- /* fall through */
140
- }
141
- return primaries[0].name;
142
- }
143
-
144
- /** Resolve one primary agent by name, or null if unknown. */
145
- export function resolvePrimary(name: string): PrimarySpec | null {
146
- return listPrimaries().find((p) => p.name === name) ?? null;
147
- }
148
-
149
- /** Whether any orchestration extension has registered roles. */
150
- export function hasRoleProvider(): boolean {
151
- return _provider !== null;
152
- }
153
-
154
- /**
155
- * Build the system-prompt block describing available roles. Returns '' when no
156
- * roles are registered, so non-orchestration users pay nothing in tokens.
157
- */
158
- export function buildRolesPrompt(): string {
159
- const roles = listRoleSpecs();
160
- if (roles.length === 0) return '';
161
-
162
- const agents = roles.filter((r) => r.kind === 'agent');
163
- const categories = roles.filter((r) => r.kind === 'category');
164
-
165
- const lines: string[] = [
166
- 'You can delegate work to specialist sub-agents via the `delegate` tool.',
167
- 'Each role runs with its own model, tools, and system prompt — pick by role, not by model name.',
168
- '',
169
- ];
170
-
171
- if (agents.length > 0) {
172
- lines.push('Read-only agents (`delegate(task, agent="…")`):');
173
- for (const r of agents) lines.push(`- ${r.name}: ${r.description}`);
174
- lines.push('');
175
- }
176
-
177
- if (categories.length > 0) {
178
- lines.push('Implementation lanes (`delegate(task, category="…")`):');
179
- for (const r of categories) lines.push(`- ${r.name}: ${r.description}`);
180
- lines.push('');
181
- }
182
-
183
- lines.push(
184
- 'Use `delegate_parallel([...])` to run several delegates at once when the sub-tasks are independent.',
185
- );
186
-
187
- return lines.join('\n');
188
- }