takomi 2.1.2 → 2.1.3

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 (49) hide show
  1. package/.pi/README.md +124 -124
  2. package/.pi/agents/architect.md +15 -15
  3. package/.pi/agents/coder.md +14 -14
  4. package/.pi/agents/designer.md +17 -17
  5. package/.pi/agents/orchestrator.md +22 -22
  6. package/.pi/agents/reviewer.md +16 -16
  7. package/.pi/extensions/oauth-router/README.md +125 -125
  8. package/.pi/extensions/oauth-router/commands.ts +380 -380
  9. package/.pi/extensions/oauth-router/config.ts +200 -200
  10. package/.pi/extensions/oauth-router/index.ts +41 -41
  11. package/.pi/extensions/oauth-router/oauth-flow.ts +154 -154
  12. package/.pi/extensions/oauth-router/oauth-store.ts +121 -121
  13. package/.pi/extensions/oauth-router/package.json +14 -14
  14. package/.pi/extensions/oauth-router/policies.ts +27 -27
  15. package/.pi/extensions/oauth-router/provider.ts +492 -492
  16. package/.pi/extensions/oauth-router/scripts/vibe-verify.py +98 -98
  17. package/.pi/extensions/oauth-router/state.ts +174 -174
  18. package/.pi/extensions/oauth-router/types.ts +153 -153
  19. package/.pi/extensions/takomi-runtime/command-text.ts +130 -130
  20. package/.pi/extensions/takomi-runtime/commands.ts +179 -179
  21. package/.pi/extensions/takomi-runtime/context-panel.ts +282 -282
  22. package/.pi/extensions/takomi-runtime/index.ts +1288 -1288
  23. package/.pi/extensions/takomi-runtime/profile.ts +114 -114
  24. package/.pi/extensions/takomi-runtime/routing-policy.ts +105 -105
  25. package/.pi/extensions/takomi-runtime/shared.ts +492 -492
  26. package/.pi/extensions/takomi-runtime/subagent-controller.ts +364 -364
  27. package/.pi/extensions/takomi-runtime/subagent-render.ts +501 -501
  28. package/.pi/extensions/takomi-runtime/subagent-types.ts +83 -83
  29. package/.pi/extensions/takomi-runtime/ui.ts +133 -133
  30. package/.pi/extensions/takomi-subagents/agent-aliases.ts +18 -18
  31. package/.pi/extensions/takomi-subagents/agents.ts +113 -113
  32. package/.pi/extensions/takomi-subagents/delegation-plan.ts +95 -95
  33. package/.pi/extensions/takomi-subagents/dispatch-helpers.ts +26 -26
  34. package/.pi/extensions/takomi-subagents/dispatch.ts +215 -215
  35. package/.pi/extensions/takomi-subagents/index.ts +75 -75
  36. package/.pi/extensions/takomi-subagents/live-updates.ts +83 -83
  37. package/.pi/extensions/takomi-subagents/native-render.ts +174 -174
  38. package/.pi/extensions/takomi-subagents/tool-runner.ts +209 -209
  39. package/.pi/themes/takomi-noir.json +81 -81
  40. package/package.json +59 -59
  41. package/src/doctor.js +87 -84
  42. package/src/pi-harness.js +355 -351
  43. package/src/pi-installer.js +193 -171
  44. package/src/pi-takomi-core/index.ts +4 -4
  45. package/src/pi-takomi-core/orchestration.ts +402 -402
  46. package/src/pi-takomi-core/routing.ts +93 -93
  47. package/src/pi-takomi-core/types.ts +173 -173
  48. package/src/pi-takomi-core/workflows.ts +299 -299
  49. package/src/skills-installer.js +101 -101
@@ -1,215 +1,215 @@
1
- import { mkdir } from "node:fs/promises";
2
- import path from "node:path";
3
- import type { ExtensionContext } from "@mariozechner/pi-coding-agent";
4
- import type { TakomiThinkingLevel } from "../../../src/pi-takomi-core";
5
- import {
6
- buildTaskPrompt,
7
- runModelPreflight,
8
- runPiAgentJson,
9
- writeTempPrompt,
10
- type ChecklistInput,
11
- } from "../takomi-runtime/shared";
12
- import type {
13
- TakomiSubagentRuntimeEvent,
14
- TakomiSubagentRunPatch,
15
- } from "../takomi-runtime/subagent-types";
16
- import type { TakomiAgentConfig } from "./agents";
17
- import {
18
- buildFallbackModels,
19
- buildSystemPrompt,
20
- hasThinkingSuffix,
21
- } from "./dispatch-helpers";
22
-
23
- export type TakomiDispatchInput = {
24
- agent: TakomiAgentConfig;
25
- task: string;
26
- rootCwd: string;
27
- cwd?: string;
28
- workflow?: string;
29
- skills?: string[];
30
- model?: string;
31
- fallbackModels?: string[];
32
- thinking?: TakomiThinkingLevel;
33
- conversationId?: string;
34
- checklist?: ChecklistInput;
35
- stage?: string;
36
- taskLabel?: string;
37
- parentTaskId?: string;
38
- parentRunKey?: string;
39
- boardTaskStatus?: "pending" | "in-progress" | "completed" | "blocked";
40
- source: "runtime-board" | "takomi-tool";
41
- rerunInstructions?: string;
42
- };
43
-
44
- export type TakomiDispatchResult = {
45
- agent: string;
46
- task: string;
47
- workflow?: string;
48
- model?: string;
49
- warning?: string;
50
- thinking?: TakomiThinkingLevel;
51
- conversationId: string;
52
- code: number;
53
- output: string;
54
- stderr: string;
55
- preflight: string;
56
- };
57
-
58
- export type TakomiDispatchHooks = {
59
- emit?: (event: TakomiSubagentRuntimeEvent) => void;
60
- onPatch?: (patch: TakomiSubagentRunPatch, runKey: string) => void | Promise<void>;
61
- };
62
-
63
- export async function dispatchTakomiSubagent(
64
- ctx: ExtensionContext,
65
- input: TakomiDispatchInput,
66
- signal?: AbortSignal,
67
- hooks?: TakomiDispatchHooks,
68
- ): Promise<TakomiDispatchResult> {
69
- const subagentCwd = input.cwd ? path.resolve(input.rootCwd, input.cwd) : input.rootCwd;
70
- const conversationId = input.conversationId || `${input.agent.name}-${Date.now()}`;
71
- const runKey = conversationId;
72
- const sessionDir = path.join(input.rootCwd, ".pi", "takomi", "subagents");
73
- const sessionPath = path.join(sessionDir, `${conversationId}.jsonl`);
74
- await mkdir(sessionDir, { recursive: true });
75
-
76
- hooks?.emit?.({
77
- type: "start",
78
- runKey,
79
- state: {
80
- agent: input.agent.name,
81
- taskLabel: input.taskLabel ?? input.task.split(/\r?\n/)[0]?.trim() ?? input.agent.name,
82
- workflow: input.workflow,
83
- stage: input.stage,
84
- conversationId,
85
- parentTaskId: input.parentTaskId,
86
- parentRunKey: input.parentRunKey,
87
- checklist: input.checklist,
88
- boardTaskStatus: input.boardTaskStatus,
89
- fallbackModels: input.fallbackModels,
90
- thinking: input.thinking ?? input.agent.thinking,
91
- summary: "Preparing delegated run.",
92
- source: input.source,
93
- },
94
- });
95
-
96
- const fallbackModels = buildFallbackModels(input);
97
- const preflight = await runModelPreflight(ctx, subagentCwd, input.model, fallbackModels, signal);
98
- const thinking = input.thinking ?? input.agent.thinking;
99
-
100
- if (preflight.model) {
101
- const patch = {
102
- model: preflight.model,
103
- fallbackModels,
104
- thinking,
105
- boardTaskStatus: input.boardTaskStatus,
106
- checklist: input.checklist,
107
- summary: `Model ready: ${preflight.model}${thinking ? ` (${thinking})` : ""}`,
108
- };
109
- hooks?.emit?.({ type: "update", runKey, patch });
110
- await hooks?.onPatch?.(patch, runKey);
111
- }
112
-
113
- if (!preflight.model) {
114
- const result = {
115
- agent: input.agent.name,
116
- task: input.task,
117
- workflow: input.workflow,
118
- model: "",
119
- warning: preflight.warning,
120
- thinking,
121
- conversationId,
122
- code: 1,
123
- output: "",
124
- stderr: preflight.report,
125
- preflight: preflight.report,
126
- };
127
- hooks?.emit?.({
128
- type: "block",
129
- runKey,
130
- patch: {
131
- summary: `Subagent ${input.agent.name} blocked before launch.`,
132
- boardTaskStatus: input.boardTaskStatus,
133
- checklist: input.checklist,
134
- fallbackModels,
135
- thinking,
136
- logs: [preflight.warning || "No model matched the requested run."],
137
- },
138
- });
139
- return result;
140
- }
141
-
142
- const promptPath = await writeTempPrompt(input.agent.name, buildSystemPrompt(input));
143
- const taskPrompt = buildTaskPrompt({
144
- task: input.rerunInstructions?.trim() || input.task,
145
- workflow: input.workflow,
146
- skills: input.skills,
147
- checklist: input.checklist,
148
- stage: input.stage,
149
- });
150
- const args = ["--mode", "json", "--append-system-prompt", promptPath, "--session", sessionPath, taskPrompt];
151
- args.unshift("--model", preflight.model);
152
- if (thinking && !hasThinkingSuffix(preflight.model)) args.unshift("--thinking", thinking);
153
- if (input.agent.tools?.length) args.unshift("--tools", input.agent.tools.join(","));
154
-
155
- const result = await runPiAgentJson(subagentCwd, args, signal, {
156
- onAssistantText: (text) => {
157
- hooks?.emit?.({ type: "update", runKey, patch: { outputText: text, boardTaskStatus: input.boardTaskStatus, checklist: input.checklist } });
158
- },
159
- onEventText: (line) => {
160
- hooks?.emit?.({ type: "appendLog", runKey, chunk: line });
161
- },
162
- onStderr: (chunk) => {
163
- hooks?.emit?.({ type: "appendLog", runKey, chunk });
164
- },
165
- });
166
-
167
- const output = result.stdout.trim();
168
- const dispatchResult: TakomiDispatchResult = {
169
- agent: input.agent.name,
170
- task: input.task,
171
- workflow: input.workflow,
172
- model: preflight.model,
173
- warning: preflight.warning,
174
- thinking,
175
- conversationId,
176
- code: result.code,
177
- output,
178
- stderr: result.stderr.trim(),
179
- preflight: preflight.report,
180
- };
181
-
182
- if (result.code !== 0) {
183
- hooks?.emit?.({
184
- type: "block",
185
- runKey,
186
- patch: {
187
- model: preflight.model,
188
- fallbackModels,
189
- thinking,
190
- boardTaskStatus: input.boardTaskStatus,
191
- checklist: input.checklist,
192
- summary: `Subagent ${input.agent.name} failed.`,
193
- outputText: output || undefined,
194
- logs: [result.stderr || result.stdout || "No output"],
195
- },
196
- });
197
- return dispatchResult;
198
- }
199
-
200
- hooks?.emit?.({
201
- type: "complete",
202
- runKey,
203
- patch: {
204
- model: preflight.model,
205
- fallbackModels,
206
- thinking,
207
- boardTaskStatus: input.boardTaskStatus,
208
- checklist: input.checklist,
209
- summary: output || `Subagent ${input.agent.name} run finished. Checklist-validated task completion is still a board action.`,
210
- outputText: output || undefined,
211
- },
212
- });
213
-
214
- return dispatchResult;
215
- }
1
+ import { mkdir } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import type { ExtensionContext } from "@mariozechner/pi-coding-agent";
4
+ import type { TakomiThinkingLevel } from "../../../src/pi-takomi-core";
5
+ import {
6
+ buildTaskPrompt,
7
+ runModelPreflight,
8
+ runPiAgentJson,
9
+ writeTempPrompt,
10
+ type ChecklistInput,
11
+ } from "../takomi-runtime/shared";
12
+ import type {
13
+ TakomiSubagentRuntimeEvent,
14
+ TakomiSubagentRunPatch,
15
+ } from "../takomi-runtime/subagent-types";
16
+ import type { TakomiAgentConfig } from "./agents";
17
+ import {
18
+ buildFallbackModels,
19
+ buildSystemPrompt,
20
+ hasThinkingSuffix,
21
+ } from "./dispatch-helpers";
22
+
23
+ export type TakomiDispatchInput = {
24
+ agent: TakomiAgentConfig;
25
+ task: string;
26
+ rootCwd: string;
27
+ cwd?: string;
28
+ workflow?: string;
29
+ skills?: string[];
30
+ model?: string;
31
+ fallbackModels?: string[];
32
+ thinking?: TakomiThinkingLevel;
33
+ conversationId?: string;
34
+ checklist?: ChecklistInput;
35
+ stage?: string;
36
+ taskLabel?: string;
37
+ parentTaskId?: string;
38
+ parentRunKey?: string;
39
+ boardTaskStatus?: "pending" | "in-progress" | "completed" | "blocked";
40
+ source: "runtime-board" | "takomi-tool";
41
+ rerunInstructions?: string;
42
+ };
43
+
44
+ export type TakomiDispatchResult = {
45
+ agent: string;
46
+ task: string;
47
+ workflow?: string;
48
+ model?: string;
49
+ warning?: string;
50
+ thinking?: TakomiThinkingLevel;
51
+ conversationId: string;
52
+ code: number;
53
+ output: string;
54
+ stderr: string;
55
+ preflight: string;
56
+ };
57
+
58
+ export type TakomiDispatchHooks = {
59
+ emit?: (event: TakomiSubagentRuntimeEvent) => void;
60
+ onPatch?: (patch: TakomiSubagentRunPatch, runKey: string) => void | Promise<void>;
61
+ };
62
+
63
+ export async function dispatchTakomiSubagent(
64
+ ctx: ExtensionContext,
65
+ input: TakomiDispatchInput,
66
+ signal?: AbortSignal,
67
+ hooks?: TakomiDispatchHooks,
68
+ ): Promise<TakomiDispatchResult> {
69
+ const subagentCwd = input.cwd ? path.resolve(input.rootCwd, input.cwd) : input.rootCwd;
70
+ const conversationId = input.conversationId || `${input.agent.name}-${Date.now()}`;
71
+ const runKey = conversationId;
72
+ const sessionDir = path.join(input.rootCwd, ".pi", "takomi", "subagents");
73
+ const sessionPath = path.join(sessionDir, `${conversationId}.jsonl`);
74
+ await mkdir(sessionDir, { recursive: true });
75
+
76
+ hooks?.emit?.({
77
+ type: "start",
78
+ runKey,
79
+ state: {
80
+ agent: input.agent.name,
81
+ taskLabel: input.taskLabel ?? input.task.split(/\r?\n/)[0]?.trim() ?? input.agent.name,
82
+ workflow: input.workflow,
83
+ stage: input.stage,
84
+ conversationId,
85
+ parentTaskId: input.parentTaskId,
86
+ parentRunKey: input.parentRunKey,
87
+ checklist: input.checklist,
88
+ boardTaskStatus: input.boardTaskStatus,
89
+ fallbackModels: input.fallbackModels,
90
+ thinking: input.thinking ?? input.agent.thinking,
91
+ summary: "Preparing delegated run.",
92
+ source: input.source,
93
+ },
94
+ });
95
+
96
+ const fallbackModels = buildFallbackModels(input);
97
+ const preflight = await runModelPreflight(ctx, subagentCwd, input.model, fallbackModels, signal);
98
+ const thinking = input.thinking ?? input.agent.thinking;
99
+
100
+ if (preflight.model) {
101
+ const patch = {
102
+ model: preflight.model,
103
+ fallbackModels,
104
+ thinking,
105
+ boardTaskStatus: input.boardTaskStatus,
106
+ checklist: input.checklist,
107
+ summary: `Model ready: ${preflight.model}${thinking ? ` (${thinking})` : ""}`,
108
+ };
109
+ hooks?.emit?.({ type: "update", runKey, patch });
110
+ await hooks?.onPatch?.(patch, runKey);
111
+ }
112
+
113
+ if (!preflight.model) {
114
+ const result = {
115
+ agent: input.agent.name,
116
+ task: input.task,
117
+ workflow: input.workflow,
118
+ model: "",
119
+ warning: preflight.warning,
120
+ thinking,
121
+ conversationId,
122
+ code: 1,
123
+ output: "",
124
+ stderr: preflight.report,
125
+ preflight: preflight.report,
126
+ };
127
+ hooks?.emit?.({
128
+ type: "block",
129
+ runKey,
130
+ patch: {
131
+ summary: `Subagent ${input.agent.name} blocked before launch.`,
132
+ boardTaskStatus: input.boardTaskStatus,
133
+ checklist: input.checklist,
134
+ fallbackModels,
135
+ thinking,
136
+ logs: [preflight.warning || "No model matched the requested run."],
137
+ },
138
+ });
139
+ return result;
140
+ }
141
+
142
+ const promptPath = await writeTempPrompt(input.agent.name, buildSystemPrompt(input));
143
+ const taskPrompt = buildTaskPrompt({
144
+ task: input.rerunInstructions?.trim() || input.task,
145
+ workflow: input.workflow,
146
+ skills: input.skills,
147
+ checklist: input.checklist,
148
+ stage: input.stage,
149
+ });
150
+ const args = ["--mode", "json", "--append-system-prompt", promptPath, "--session", sessionPath, taskPrompt];
151
+ args.unshift("--model", preflight.model);
152
+ if (thinking && !hasThinkingSuffix(preflight.model)) args.unshift("--thinking", thinking);
153
+ if (input.agent.tools?.length) args.unshift("--tools", input.agent.tools.join(","));
154
+
155
+ const result = await runPiAgentJson(subagentCwd, args, signal, {
156
+ onAssistantText: (text) => {
157
+ hooks?.emit?.({ type: "update", runKey, patch: { outputText: text, boardTaskStatus: input.boardTaskStatus, checklist: input.checklist } });
158
+ },
159
+ onEventText: (line) => {
160
+ hooks?.emit?.({ type: "appendLog", runKey, chunk: line });
161
+ },
162
+ onStderr: (chunk) => {
163
+ hooks?.emit?.({ type: "appendLog", runKey, chunk });
164
+ },
165
+ });
166
+
167
+ const output = result.stdout.trim();
168
+ const dispatchResult: TakomiDispatchResult = {
169
+ agent: input.agent.name,
170
+ task: input.task,
171
+ workflow: input.workflow,
172
+ model: preflight.model,
173
+ warning: preflight.warning,
174
+ thinking,
175
+ conversationId,
176
+ code: result.code,
177
+ output,
178
+ stderr: result.stderr.trim(),
179
+ preflight: preflight.report,
180
+ };
181
+
182
+ if (result.code !== 0) {
183
+ hooks?.emit?.({
184
+ type: "block",
185
+ runKey,
186
+ patch: {
187
+ model: preflight.model,
188
+ fallbackModels,
189
+ thinking,
190
+ boardTaskStatus: input.boardTaskStatus,
191
+ checklist: input.checklist,
192
+ summary: `Subagent ${input.agent.name} failed.`,
193
+ outputText: output || undefined,
194
+ logs: [result.stderr || result.stdout || "No output"],
195
+ },
196
+ });
197
+ return dispatchResult;
198
+ }
199
+
200
+ hooks?.emit?.({
201
+ type: "complete",
202
+ runKey,
203
+ patch: {
204
+ model: preflight.model,
205
+ fallbackModels,
206
+ thinking,
207
+ boardTaskStatus: input.boardTaskStatus,
208
+ checklist: input.checklist,
209
+ summary: output || `Subagent ${input.agent.name} run finished. Checklist-validated task completion is still a board action.`,
210
+ outputText: output || undefined,
211
+ },
212
+ });
213
+
214
+ return dispatchResult;
215
+ }
@@ -1,75 +1,75 @@
1
- import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
- import { Type } from "typebox";
3
- import { renderTakomiSubagentCall, renderTakomiSubagentResult } from "./native-render";
4
- import { executeTakomiSubagentTool } from "./tool-runner";
5
-
6
- const ChecklistItemSchema = Type.Object({
7
- text: Type.String(),
8
- done: Type.Optional(Type.Boolean()),
9
- });
10
-
11
- const ThinkingSchema = Type.Union([
12
- Type.Literal("off"),
13
- Type.Literal("minimal"),
14
- Type.Literal("low"),
15
- Type.Literal("medium"),
16
- Type.Literal("high"),
17
- Type.Literal("xhigh"),
18
- ]);
19
-
20
- const TaskSchema = Type.Object({
21
- agent: Type.String(),
22
- task: Type.String(),
23
- workflow: Type.Optional(Type.String()),
24
- skills: Type.Optional(Type.Array(Type.String())),
25
- model: Type.Optional(Type.String()),
26
- fallbackModels: Type.Optional(Type.Array(Type.String())),
27
- thinking: Type.Optional(ThinkingSchema),
28
- conversationId: Type.Optional(Type.String()),
29
- cwd: Type.Optional(Type.String()),
30
- checklist: Type.Optional(Type.Array(Type.Union([Type.String(), ChecklistItemSchema]))),
31
- });
32
-
33
- const SubagentParameters = Type.Object({
34
- agent: Type.Optional(Type.String({ description: "Agent name for single execution" })),
35
- task: Type.Optional(Type.String({ description: "Task for single execution" })),
36
- workflow: Type.Optional(Type.String({ description: "Workflow or playbook overlay for this task" })),
37
- skills: Type.Optional(Type.Array(Type.String(), { description: "Extra skills to apply during the task" })),
38
- model: Type.Optional(Type.String({ description: "Optional per-run model override" })),
39
- fallbackModels: Type.Optional(Type.Array(Type.String(), { description: "Optional ordered model fallback list" })),
40
- thinking: Type.Optional(ThinkingSchema),
41
- conversationId: Type.Optional(Type.String({ description: "Persistent conversation id to resume the same subagent session" })),
42
- cwd: Type.Optional(Type.String({ description: "Working directory override" })),
43
- checklist: Type.Optional(Type.Array(Type.Union([Type.String(), ChecklistItemSchema]), { description: "Optional checklist for the subagent" })),
44
- tasks: Type.Optional(Type.Array(TaskSchema, { description: "Parallel subagent tasks" })),
45
- confirmLaunch: Type.Optional(Type.Boolean({ description: "Required to launch immediately in manual Takomi launch mode" })),
46
- previewOnly: Type.Optional(Type.Boolean({ description: "Return the delegation plan without launching" })),
47
- chain: Type.Optional(Type.Array(TaskSchema, { description: "Sequential chain of subagent tasks" })),
48
- agentScope: Type.Optional(Type.Union([Type.Literal("user"), Type.Literal("project"), Type.Literal("both")])),
49
- confirmProjectAgents: Type.Optional(Type.Boolean({ description: "Prompt before running project-local agents. Default: true." })),
50
- });
51
-
52
- function registerSubagentTool(pi: ExtensionAPI): void {
53
- pi.registerTool({
54
- name: "takomi_subagent",
55
- label: "Takomi",
56
- description: "Run subagents with Pi-style single, parallel, or chain modes plus Takomi lifecycle metadata.",
57
- promptSnippet: "Delegate lifecycle-aware Takomi work to specialist subagents. Use single, tasks, or chain; reuse conversationId for review loops.",
58
- promptGuidelines: [
59
- "Use this tool during orchestration when a specialist should handle a task.",
60
- "Use tasks for independent parallel work and chain for dependent handoffs with {previous}.",
61
- "Use model, fallbackModels, and thinking only when deliberate; otherwise let the agent/profile defaults apply.",
62
- "If review sends work back to the same agent, reuse the same conversationId for continuity.",
63
- ],
64
- parameters: SubagentParameters,
65
- async execute(_toolCallId, params, signal, onUpdate, ctx) {
66
- return executeTakomiSubagentTool(pi, params, signal, onUpdate, ctx);
67
- },
68
- renderCall: renderTakomiSubagentCall,
69
- renderResult: renderTakomiSubagentResult,
70
- });
71
- }
72
-
73
- export default function takomiSubagents(pi: ExtensionAPI) {
74
- registerSubagentTool(pi);
75
- }
1
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
+ import { Type } from "typebox";
3
+ import { renderTakomiSubagentCall, renderTakomiSubagentResult } from "./native-render";
4
+ import { executeTakomiSubagentTool } from "./tool-runner";
5
+
6
+ const ChecklistItemSchema = Type.Object({
7
+ text: Type.String(),
8
+ done: Type.Optional(Type.Boolean()),
9
+ });
10
+
11
+ const ThinkingSchema = Type.Union([
12
+ Type.Literal("off"),
13
+ Type.Literal("minimal"),
14
+ Type.Literal("low"),
15
+ Type.Literal("medium"),
16
+ Type.Literal("high"),
17
+ Type.Literal("xhigh"),
18
+ ]);
19
+
20
+ const TaskSchema = Type.Object({
21
+ agent: Type.String(),
22
+ task: Type.String(),
23
+ workflow: Type.Optional(Type.String()),
24
+ skills: Type.Optional(Type.Array(Type.String())),
25
+ model: Type.Optional(Type.String()),
26
+ fallbackModels: Type.Optional(Type.Array(Type.String())),
27
+ thinking: Type.Optional(ThinkingSchema),
28
+ conversationId: Type.Optional(Type.String()),
29
+ cwd: Type.Optional(Type.String()),
30
+ checklist: Type.Optional(Type.Array(Type.Union([Type.String(), ChecklistItemSchema]))),
31
+ });
32
+
33
+ const SubagentParameters = Type.Object({
34
+ agent: Type.Optional(Type.String({ description: "Agent name for single execution" })),
35
+ task: Type.Optional(Type.String({ description: "Task for single execution" })),
36
+ workflow: Type.Optional(Type.String({ description: "Workflow or playbook overlay for this task" })),
37
+ skills: Type.Optional(Type.Array(Type.String(), { description: "Extra skills to apply during the task" })),
38
+ model: Type.Optional(Type.String({ description: "Optional per-run model override" })),
39
+ fallbackModels: Type.Optional(Type.Array(Type.String(), { description: "Optional ordered model fallback list" })),
40
+ thinking: Type.Optional(ThinkingSchema),
41
+ conversationId: Type.Optional(Type.String({ description: "Persistent conversation id to resume the same subagent session" })),
42
+ cwd: Type.Optional(Type.String({ description: "Working directory override" })),
43
+ checklist: Type.Optional(Type.Array(Type.Union([Type.String(), ChecklistItemSchema]), { description: "Optional checklist for the subagent" })),
44
+ tasks: Type.Optional(Type.Array(TaskSchema, { description: "Parallel subagent tasks" })),
45
+ confirmLaunch: Type.Optional(Type.Boolean({ description: "Required to launch immediately in manual Takomi launch mode" })),
46
+ previewOnly: Type.Optional(Type.Boolean({ description: "Return the delegation plan without launching" })),
47
+ chain: Type.Optional(Type.Array(TaskSchema, { description: "Sequential chain of subagent tasks" })),
48
+ agentScope: Type.Optional(Type.Union([Type.Literal("user"), Type.Literal("project"), Type.Literal("both")])),
49
+ confirmProjectAgents: Type.Optional(Type.Boolean({ description: "Prompt before running project-local agents. Default: true." })),
50
+ });
51
+
52
+ function registerSubagentTool(pi: ExtensionAPI): void {
53
+ pi.registerTool({
54
+ name: "takomi_subagent",
55
+ label: "Takomi",
56
+ description: "Run subagents with Pi-style single, parallel, or chain modes plus Takomi lifecycle metadata.",
57
+ promptSnippet: "Delegate lifecycle-aware Takomi work to specialist subagents. Use single, tasks, or chain; reuse conversationId for review loops.",
58
+ promptGuidelines: [
59
+ "Use this tool during orchestration when a specialist should handle a task.",
60
+ "Use tasks for independent parallel work and chain for dependent handoffs with {previous}.",
61
+ "Use model, fallbackModels, and thinking only when deliberate; otherwise let the agent/profile defaults apply.",
62
+ "If review sends work back to the same agent, reuse the same conversationId for continuity.",
63
+ ],
64
+ parameters: SubagentParameters,
65
+ async execute(_toolCallId, params, signal, onUpdate, ctx) {
66
+ return executeTakomiSubagentTool(pi, params, signal, onUpdate, ctx);
67
+ },
68
+ renderCall: renderTakomiSubagentCall,
69
+ renderResult: renderTakomiSubagentResult,
70
+ });
71
+ }
72
+
73
+ export default function takomiSubagents(pi: ExtensionAPI) {
74
+ registerSubagentTool(pi);
75
+ }