takomi 2.0.7 → 2.1.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.
Files changed (66) hide show
  1. package/.pi/README.md +124 -0
  2. package/.pi/agents/architect.md +16 -0
  3. package/.pi/agents/coder.md +15 -0
  4. package/.pi/agents/designer.md +18 -0
  5. package/.pi/agents/orchestrator.md +23 -0
  6. package/.pi/agents/reviewer.md +17 -0
  7. package/.pi/extensions/oauth-router/README.md +125 -0
  8. package/.pi/extensions/oauth-router/commands.ts +380 -0
  9. package/.pi/extensions/oauth-router/config.ts +200 -0
  10. package/.pi/extensions/oauth-router/index.ts +41 -0
  11. package/.pi/extensions/oauth-router/oauth-flow.ts +154 -0
  12. package/.pi/extensions/oauth-router/oauth-store.ts +121 -0
  13. package/.pi/extensions/oauth-router/package.json +14 -0
  14. package/.pi/extensions/oauth-router/policies.ts +27 -0
  15. package/.pi/extensions/oauth-router/provider.ts +492 -0
  16. package/.pi/extensions/oauth-router/scripts/vibe-verify.py +98 -0
  17. package/.pi/extensions/oauth-router/state.ts +174 -0
  18. package/.pi/extensions/oauth-router/types.ts +153 -0
  19. package/.pi/extensions/takomi-runtime/command-text.ts +130 -0
  20. package/.pi/extensions/takomi-runtime/commands.ts +179 -0
  21. package/.pi/extensions/takomi-runtime/context-panel.ts +282 -0
  22. package/.pi/extensions/takomi-runtime/index.ts +1288 -0
  23. package/.pi/extensions/takomi-runtime/profile.ts +114 -0
  24. package/.pi/extensions/takomi-runtime/routing-policy.ts +105 -0
  25. package/.pi/extensions/takomi-runtime/shared.ts +492 -0
  26. package/.pi/extensions/takomi-runtime/subagent-controller.ts +364 -0
  27. package/.pi/extensions/takomi-runtime/subagent-render.ts +501 -0
  28. package/.pi/extensions/takomi-runtime/subagent-types.ts +83 -0
  29. package/.pi/extensions/takomi-runtime/ui.ts +133 -0
  30. package/.pi/extensions/takomi-subagents/agent-aliases.ts +18 -0
  31. package/.pi/extensions/takomi-subagents/agents.ts +113 -0
  32. package/.pi/extensions/takomi-subagents/delegation-plan.ts +95 -0
  33. package/.pi/extensions/takomi-subagents/dispatch-helpers.ts +26 -0
  34. package/.pi/extensions/takomi-subagents/dispatch.ts +215 -0
  35. package/.pi/extensions/takomi-subagents/index.ts +75 -0
  36. package/.pi/extensions/takomi-subagents/live-updates.ts +83 -0
  37. package/.pi/extensions/takomi-subagents/native-render.ts +174 -0
  38. package/.pi/extensions/takomi-subagents/tool-runner.ts +209 -0
  39. package/.pi/prompts/build-prompt.md +199 -0
  40. package/.pi/prompts/design-prompt.md +134 -0
  41. package/.pi/prompts/genesis-prompt.md +133 -0
  42. package/.pi/prompts/orch-prompt.md +144 -0
  43. package/.pi/prompts/prime-prompt.md +80 -0
  44. package/.pi/prompts/takomi-prompt.md +96 -0
  45. package/.pi/prompts/vibe-primeAgent.md +97 -0
  46. package/.pi/prompts/vibe-spawnTask.md +133 -0
  47. package/.pi/prompts/vibe-syncDocs.md +100 -0
  48. package/.pi/themes/takomi-noir.json +81 -0
  49. package/README.md +28 -2
  50. package/assets/.agent/skills/pr-comment-fix/SKILL.md +182 -0
  51. package/assets/.agent/skills/takomi/SKILL.md +59 -59
  52. package/package.json +58 -45
  53. package/src/cli.js +158 -8
  54. package/src/doctor.js +84 -0
  55. package/src/pi-harness.js +351 -0
  56. package/src/pi-installer.js +171 -0
  57. package/src/pi-takomi-core/index.ts +4 -0
  58. package/src/pi-takomi-core/orchestration.ts +402 -0
  59. package/src/pi-takomi-core/routing.ts +93 -0
  60. package/src/pi-takomi-core/types.ts +173 -0
  61. package/src/pi-takomi-core/workflows.ts +299 -0
  62. package/src/skills-installer.js +101 -0
  63. package/src/utils.js +479 -447
  64. package/assets/.agent/skills/skill-creator/scripts/__pycache__/quick_validate.cpython-311.pyc +0 -0
  65. package/assets/.agent/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-311.pyc +0 -0
  66. package/assets/.agent/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-311.pyc +0 -0
@@ -0,0 +1,402 @@
1
+ import path from "node:path";
2
+ import type {
3
+ LifecycleStageState,
4
+ OrchestratorSessionState,
5
+ OrchestratorTask,
6
+ OrchestratorTaskStatus,
7
+ SessionIntent,
8
+ TakomiRole,
9
+ TaskChecklistItem,
10
+ VibeLifecycleStage,
11
+ } from "./types";
12
+
13
+ export function createSessionId(now = new Date()): string {
14
+ const yyyy = now.getFullYear();
15
+ const mm = String(now.getMonth() + 1).padStart(2, "0");
16
+ const dd = String(now.getDate()).padStart(2, "0");
17
+ const hh = String(now.getHours()).padStart(2, "0");
18
+ const mi = String(now.getMinutes()).padStart(2, "0");
19
+ const ss = String(now.getSeconds()).padStart(2, "0");
20
+ return `orch-${yyyy}${mm}${dd}-${hh}${mi}${ss}`;
21
+ }
22
+
23
+ export function slugifyTaskTitle(title: string): string {
24
+ return title.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
25
+ }
26
+
27
+ export function getSessionPaths(cwd: string, sessionId: string) {
28
+ const docsRoot = path.join(cwd, "docs", "tasks", "orchestrator-sessions", sessionId);
29
+ const machineRoot = path.join(cwd, ".pi", "takomi", "orchestrator");
30
+ return {
31
+ root: docsRoot,
32
+ pending: path.join(docsRoot, "pending"),
33
+ inProgress: path.join(docsRoot, "in-progress"),
34
+ completed: path.join(docsRoot, "completed"),
35
+ blocked: path.join(docsRoot, "blocked"),
36
+ masterPlan: path.join(docsRoot, "master_plan.md"),
37
+ summary: path.join(docsRoot, "Orchestrator_Summary.md"),
38
+ stateDir: machineRoot,
39
+ stateFile: path.join(machineRoot, `${sessionId}.json`),
40
+ };
41
+ }
42
+
43
+ export function createConversationId(agent: string, taskId: string): string {
44
+ return `${agent}-${taskId}`;
45
+ }
46
+
47
+ export function workflowToStage(workflow?: OrchestratorTask["workflow"]): VibeLifecycleStage | undefined {
48
+ switch (workflow) {
49
+ case "vibe-genesis":
50
+ return "genesis";
51
+ case "vibe-design":
52
+ return "design";
53
+ case "vibe-build":
54
+ return "build";
55
+ default:
56
+ return undefined;
57
+ }
58
+ }
59
+
60
+ function defaultStageForRole(role: TakomiRole): VibeLifecycleStage | undefined {
61
+ switch (role) {
62
+ case "architect":
63
+ return "genesis";
64
+ case "design":
65
+ return "design";
66
+ case "code":
67
+ case "review":
68
+ case "orchestrator":
69
+ return "build";
70
+ default:
71
+ return undefined;
72
+ }
73
+ }
74
+
75
+ function emptyStageState(): LifecycleStageState {
76
+ return {
77
+ status: "pending",
78
+ taskIds: [],
79
+ canExpand: true,
80
+ };
81
+ }
82
+
83
+ export function createEmptyLifecycle(): Record<VibeLifecycleStage, LifecycleStageState> {
84
+ return {
85
+ genesis: emptyStageState(),
86
+ design: emptyStageState(),
87
+ build: emptyStageState(),
88
+ };
89
+ }
90
+
91
+ function stageStatusFromTasks(tasks: OrchestratorTask[]): OrchestratorTaskStatus {
92
+ if (!tasks.length) return "pending";
93
+ if (tasks.every((task) => task.status === "completed")) return "completed";
94
+ if (tasks.some((task) => task.status === "in-progress")) return "in-progress";
95
+ if (tasks.some((task) => task.status === "blocked") && !tasks.some((task) => task.status === "completed")) return "blocked";
96
+ if (tasks.some((task) => task.status === "completed")) return "in-progress";
97
+ return "pending";
98
+ }
99
+
100
+ export function deriveLifecycleFromTasks(
101
+ tasks: OrchestratorTask[],
102
+ previous?: Partial<Record<VibeLifecycleStage, LifecycleStageState>>,
103
+ ): Record<VibeLifecycleStage, LifecycleStageState> {
104
+ const lifecycle = createEmptyLifecycle();
105
+
106
+ for (const stage of Object.keys(lifecycle) as VibeLifecycleStage[]) {
107
+ const stageTasks = tasks.filter((task) => task.stage === stage || workflowToStage(task.workflow) === stage);
108
+ const prev = previous?.[stage];
109
+ lifecycle[stage] = {
110
+ status: stageStatusFromTasks(stageTasks),
111
+ taskIds: stageTasks.map((task) => task.id),
112
+ canExpand: prev?.canExpand ?? true,
113
+ expandedAt: prev?.expandedAt,
114
+ notes: prev?.notes,
115
+ };
116
+ }
117
+
118
+ return lifecycle;
119
+ }
120
+
121
+ export function normalizeChecklist(checklist?: Array<string | TaskChecklistItem>): TaskChecklistItem[] | undefined {
122
+ if (!checklist?.length) return undefined;
123
+ return checklist.map((item) => typeof item === "string" ? { text: item, done: false } : { text: item.text, done: item.done ?? false });
124
+ }
125
+
126
+ export function createTask(id: string, title: string, role: TakomiRole, extras?: Partial<OrchestratorTask>): OrchestratorTask {
127
+ const preferredAgent = extras?.preferredAgent ?? (role === "design" ? "designer" : role === "architect" ? "architect" : role === "review" ? "reviewer" : role === "code" ? "coder" : "orchestrator");
128
+ const stage = extras?.stage ?? workflowToStage(extras?.workflow) ?? defaultStageForRole(role);
129
+ return {
130
+ id,
131
+ title,
132
+ role,
133
+ status: "pending",
134
+ ...extras,
135
+ stage,
136
+ preferredAgent,
137
+ conversationId: extras?.conversationId ?? createConversationId(preferredAgent, id),
138
+ preferredModel: extras?.preferredModel,
139
+ preferredModelHint: extras?.preferredModelHint,
140
+ preferredThinking: extras?.preferredThinking,
141
+ fallbackModels: extras?.fallbackModels,
142
+ dispatchPolicy: extras?.dispatchPolicy,
143
+ skills: extras?.skills,
144
+ checklist: normalizeChecklist(extras?.checklist),
145
+ };
146
+ }
147
+
148
+ export function getNextTaskId(tasks: OrchestratorTask[]): string {
149
+ const max = tasks.reduce((current, task) => {
150
+ const parsed = Number.parseInt(task.id, 10);
151
+ return Number.isFinite(parsed) ? Math.max(current, parsed) : current;
152
+ }, 0);
153
+ return String(max + 1).padStart(2, "0");
154
+ }
155
+
156
+ export function moveTaskStatus(tasks: OrchestratorTask[], id: string, status: OrchestratorTaskStatus): OrchestratorTask[] {
157
+ return tasks.map((task) => (task.id === id ? { ...task, status } : task));
158
+ }
159
+
160
+ function renderChecklist(checklist?: TaskChecklistItem[]): string[] {
161
+ if (!checklist?.length) return ["- No checklist yet."];
162
+ return checklist.map((item) => `- [${item.done ? "x" : " "}] ${item.text}`);
163
+ }
164
+
165
+ function renderBullets(items?: string[], empty = "- None specified."): string[] {
166
+ if (!items?.length) return [empty];
167
+ return items.map((item) => `- ${item}`);
168
+ }
169
+
170
+ function renderLifecycleSummary(state: OrchestratorSessionState): string[] {
171
+ return (Object.keys(state.lifecycle) as VibeLifecycleStage[]).flatMap((stage) => {
172
+ const entry = state.lifecycle[stage];
173
+ const taskSummary = entry.taskIds.length ? entry.taskIds.join(", ") : "none yet";
174
+ return [
175
+ `### ${stage[0].toUpperCase()}${stage.slice(1)}`,
176
+ `- Status: ${entry.status}`,
177
+ `- Tasks: ${taskSummary}`,
178
+ `- Expandable: ${entry.canExpand === false ? "no" : "yes"}`,
179
+ entry.expandedAt ? `- Expanded At: ${entry.expandedAt}` : "",
180
+ entry.notes ? `- Notes: ${entry.notes}` : "",
181
+ "",
182
+ ].filter(Boolean);
183
+ });
184
+ }
185
+
186
+ export function renderMasterPlan(sessionOrId: OrchestratorSessionState | string, title?: string, tasks?: OrchestratorTask[]): string {
187
+ const state = typeof sessionOrId === "string"
188
+ ? buildSessionState(sessionOrId, title ?? "Takomi Session", tasks ?? [])
189
+ : normalizeSessionState(sessionOrId);
190
+
191
+ const rows = state.tasks
192
+ .map((task) => `| ${task.id} | ${task.stage ?? "-"} | ${task.title} | ${task.status} | ${task.role} | ${task.preferredAgent ?? "-"} | ${task.workflow ?? "-"} | ${task.preferredModel ?? task.preferredModelHint ?? "-"} | ${task.preferredThinking ?? "-"} | ${task.dispatchPolicy ?? "-"} | ${task.skills?.join(", ") ?? "-"} |`)
193
+ .join("\n");
194
+
195
+ return [
196
+ `# Master Plan: ${state.title}`,
197
+ "",
198
+ `**Session ID:** ${state.sessionId}`,
199
+ `**Runtime Mode:** ${state.mode}`,
200
+ `**Session Intent:** ${state.sessionIntent ?? "full-project"}`,
201
+ "",
202
+ "## Lifecycle",
203
+ "",
204
+ ...renderLifecycleSummary(state),
205
+ "## Tasks",
206
+ "",
207
+ "| ID | Stage | Title | Status | Role | Preferred Agent | Workflow | Model | Thinking | Dispatch | Skills |",
208
+ "|---|---|---|---|---|---|---|---|---|---|---|",
209
+ rows || "| - | - | No tasks yet | - | - | - | - | - | - | - | - |",
210
+ "",
211
+ "## Notes",
212
+ "",
213
+ "- Human-readable task docs live in this session folder.",
214
+ "- Machine state lives in `.pi/takomi/orchestrator/<sessionId>.json`.",
215
+ "- Sending a task back to the same agent should reuse its conversationId when continuity is helpful.",
216
+ "- Sessions follow the Genesis -> Design -> Build lifecycle, but each stage may stay compact or expand into more tasks.",
217
+ ].join("\n");
218
+ }
219
+
220
+ export function renderTaskFile(task: OrchestratorTask, context?: string): string {
221
+ return [
222
+ `# Task: ${task.title}`,
223
+ "",
224
+ `**Task ID:** ${task.id}`,
225
+ `**Stage:** ${task.stage ?? "-"}`,
226
+ `**Status:** ${task.status}`,
227
+ `**Role:** ${task.role}`,
228
+ task.parentTaskId ? `**Parent Task:** ${task.parentTaskId}` : "",
229
+ `**Preferred Agent:** ${task.preferredAgent ?? "-"}`,
230
+ `**Conversation ID:** ${task.conversationId ?? "-"}`,
231
+ `**Workflow:** ${task.workflow ?? "-"}`,
232
+ task.preferredModel ? `**Model Override:** ${task.preferredModel}` : "",
233
+ task.preferredModelHint ? `**Model Hint:** ${task.preferredModelHint}` : "",
234
+ task.fallbackModels?.length ? `**Fallback Models:** ${task.fallbackModels.join(", ")}` : "",
235
+ task.preferredThinking ? `**Thinking Level:** ${task.preferredThinking}` : "",
236
+ task.dispatchPolicy ? `**Dispatch Policy:** ${task.dispatchPolicy}` : "",
237
+ task.skills?.length ? `**Required Skills:** ${task.skills.join(", ")}` : "",
238
+ "",
239
+ "## Context",
240
+ "",
241
+ context ?? "Add task-specific context here.",
242
+ "",
243
+ "## Objective",
244
+ "",
245
+ task.objective ?? task.title,
246
+ "",
247
+ "## Scope",
248
+ "",
249
+ ...renderBullets(task.scope),
250
+ "",
251
+ "## Checklist",
252
+ "",
253
+ ...renderChecklist(task.checklist),
254
+ "",
255
+ "## Definition of Done",
256
+ "",
257
+ ...renderBullets(task.definitionOfDone),
258
+ "",
259
+ "## Expected Artifacts",
260
+ "",
261
+ ...renderBullets(task.expectedArtifacts),
262
+ "",
263
+ "## Dependencies",
264
+ "",
265
+ ...renderBullets(task.dependencies),
266
+ "",
267
+ "## Review Checkpoint",
268
+ "",
269
+ task.reviewCheckpoint ?? "Review before implementation handoff or final completion.",
270
+ "",
271
+ "## Instructions",
272
+ "",
273
+ ...renderBullets(task.instructions ?? [
274
+ "complete the task within scope",
275
+ "use the listed workflow and skills when they are provided",
276
+ "report blockers clearly",
277
+ "if review sends this back, continue using the same conversation id when possible",
278
+ "summarize what changed and what remains",
279
+ ]),
280
+ task.notes ? "" : "",
281
+ task.notes ? "## Notes" : "",
282
+ task.notes ? "" : "",
283
+ task.notes ?? "",
284
+ ].filter(Boolean).join("\n");
285
+ }
286
+
287
+ export function buildSessionState(
288
+ sessionId: string,
289
+ title: string,
290
+ tasks: OrchestratorTask[],
291
+ now = new Date(),
292
+ extras?: Partial<Pick<OrchestratorSessionState, "sessionIntent" | "lifecycle">>,
293
+ ): OrchestratorSessionState {
294
+ const stamp = now.toISOString();
295
+ const normalizedTasks = tasks.map((task) => ({ ...task, stage: task.stage ?? workflowToStage(task.workflow) ?? defaultStageForRole(task.role) }));
296
+ return {
297
+ sessionId,
298
+ title,
299
+ createdAt: stamp,
300
+ updatedAt: stamp,
301
+ mode: "hybrid",
302
+ lifecycle: deriveLifecycleFromTasks(normalizedTasks, extras?.lifecycle),
303
+ sessionIntent: extras?.sessionIntent ?? "full-project",
304
+ tasks: normalizedTasks,
305
+ };
306
+ }
307
+
308
+ export function normalizeSessionState(
309
+ session: Partial<OrchestratorSessionState> & Pick<OrchestratorSessionState, "sessionId" | "title">,
310
+ ): OrchestratorSessionState {
311
+ const tasks = (session.tasks ?? []).map((task) => ({ ...task, stage: task.stage ?? workflowToStage(task.workflow) ?? defaultStageForRole(task.role) }));
312
+ const normalized = buildSessionState(
313
+ session.sessionId,
314
+ session.title,
315
+ tasks,
316
+ session.updatedAt ? new Date(session.updatedAt) : new Date(),
317
+ {
318
+ sessionIntent: session.sessionIntent ?? "full-project",
319
+ lifecycle: session.lifecycle,
320
+ },
321
+ );
322
+
323
+ return {
324
+ ...normalized,
325
+ createdAt: session.createdAt ?? normalized.createdAt,
326
+ updatedAt: session.updatedAt ?? normalized.updatedAt,
327
+ mode: "hybrid",
328
+ };
329
+ }
330
+
331
+ export function markStageExpanded(
332
+ state: OrchestratorSessionState,
333
+ stage: VibeLifecycleStage,
334
+ notes?: string,
335
+ now = new Date(),
336
+ ): OrchestratorSessionState {
337
+ const lifecycle = {
338
+ ...state.lifecycle,
339
+ [stage]: {
340
+ ...state.lifecycle[stage],
341
+ expandedAt: now.toISOString(),
342
+ notes: notes ?? state.lifecycle[stage].notes,
343
+ },
344
+ };
345
+ return normalizeSessionState({
346
+ ...state,
347
+ updatedAt: now.toISOString(),
348
+ lifecycle,
349
+ });
350
+ }
351
+
352
+ export function createLifecycleStarterSession(
353
+ title: string,
354
+ options?: { sessionId?: string; now?: Date; sessionIntent?: SessionIntent },
355
+ ): OrchestratorSessionState {
356
+ const sessionId = options?.sessionId ?? createSessionId(options?.now);
357
+ const tasks = [
358
+ createTask("01", "Genesis foundation", "orchestrator", {
359
+ stage: "genesis",
360
+ workflow: "vibe-genesis",
361
+ preferredAgent: "orchestrator",
362
+ objective: "Establish the project foundation, produce the required planning docs, and decide what should split next.",
363
+ scope: [
364
+ "Clarify scope and mission",
365
+ "Create or update the core markdown artifacts",
366
+ "Lock acceptance criteria and boundaries",
367
+ "Recommend whether Design and Build should stay compact or expand",
368
+ ],
369
+ checklist: [
370
+ { text: "Create or update requirements docs" },
371
+ { text: "Capture acceptance criteria" },
372
+ { text: "Define boundaries and non-goals" },
373
+ { text: "Recommend next-stage task breakdown" },
374
+ ],
375
+ definitionOfDone: [
376
+ "Required planning markdown files exist or are updated",
377
+ "Minimum usable state is explicit",
378
+ "Genesis recommends the correct next Design and Build structure",
379
+ ],
380
+ expectedArtifacts: [
381
+ "Requirements and feature docs",
382
+ "Genesis brief",
383
+ "Recommended task breakdown for later stages",
384
+ ],
385
+ reviewCheckpoint: "User or orchestrator approves the foundation before expanding later stages.",
386
+ instructions: [
387
+ "treat this as the root task for the whole Genesis -> Design -> Build lifecycle",
388
+ "create the required markdown artifacts before implementation begins",
389
+ "split later-stage work only when the scope justifies it",
390
+ "leave a clear recommendation for how Design and Build should fan out",
391
+ ],
392
+ }),
393
+ ];
394
+
395
+ return buildSessionState(sessionId, title, tasks, options?.now, {
396
+ sessionIntent: options?.sessionIntent ?? "full-project",
397
+ });
398
+ }
399
+
400
+ export function serializeSessionState(state: OrchestratorSessionState): string {
401
+ return `${JSON.stringify(normalizeSessionState(state), null, 2)}\n`;
402
+ }
@@ -0,0 +1,93 @@
1
+ import { getWorkflowDefinition } from "./workflows";
2
+ import type { RouteDecision, TakomiRole, TakomiWorkflowId, VibeLifecycleStage } from "./types";
3
+
4
+ function stageToWorkflow(stage: VibeLifecycleStage): TakomiWorkflowId {
5
+ switch (stage) {
6
+ case "genesis":
7
+ return "vibe-genesis";
8
+ case "design":
9
+ return "vibe-design";
10
+ case "build":
11
+ default:
12
+ return "vibe-build";
13
+ }
14
+ }
15
+
16
+ export function detectLifecycleStage(text: string): VibeLifecycleStage | undefined {
17
+ const lowered = text.toLowerCase();
18
+ if (/(\bgenesis\b|\brequirements\b|\bprd\b|\bscope\b|\bplan first\b|\bblueprint\b)/.test(lowered)) return "genesis";
19
+ if (/(\bdesign\b|\bux\b|\bui\b|\bmockup\b|\bwireframe\b|\bvisual\b)/.test(lowered)) return "design";
20
+ if (/(\bbuild\b|\bimplement\b|\bcode\b|\bship\b|\bwire up\b|\bfeature\b)/.test(lowered)) return "build";
21
+ return undefined;
22
+ }
23
+
24
+ export function detectRole(text: string): TakomiRole | undefined {
25
+ const lowered = text.toLowerCase();
26
+ if (/(\borchestrate\b|\bcoordinate\b|\bbreak this down\b|\bmulti-step\b|\bmulti step\b|\borchestration session\b)/.test(lowered)) return "orchestrator";
27
+ if (/(\barchitect\b|\bdesign the system\b|\bplan\b|\bspec\b)/.test(lowered)) return "architect";
28
+ if (/(\bdesign\b|\bdesigner\b|\bmockup\b|\bvisual\b)/.test(lowered)) return "design";
29
+ if (/(\bcode\b|\bimplement\b|\bbuild\b|\bfix\b)/.test(lowered)) return "code";
30
+ if (/(\breview\b|\baudit\b|\bcheck\b|\bqa\b)/.test(lowered)) return "review";
31
+ return undefined;
32
+ }
33
+
34
+ function isFollowUpExpansionRequest(lowered: string): boolean {
35
+ return /(\bcontinue\b|\bexpand\b|\badd\b|\bnext\b|\bfollow[- ]?up\b|\bcome back\b|\bworking on\b)/.test(lowered);
36
+ }
37
+
38
+ export function decideRoute(text: string): RouteDecision {
39
+ const lowered = text.toLowerCase();
40
+ const explicitStage = detectLifecycleStage(text);
41
+ const explicitRole = detectRole(text);
42
+ const orchestrationSignal = /(\buse takomi\b|\borchestration session\b|\bbreak this down\b|\bcoordinate\b|\bmulti[- ]part\b|\bmulti[- ]step\b)/.test(lowered);
43
+ const connectors = (lowered.match(/\b(and|then|also|after|while|plus)\b/g) ?? []).length;
44
+ const broad = lowered.length > 220 || connectors >= 2;
45
+ const bigBuildSignal = /(\bminimum usable\b|\bmus\b|\bseveral features\b|\bmultiple features\b|\bwhole project\b|\bfull project\b|\bend to end\b)/.test(lowered);
46
+ const followUp = isFollowUpExpansionRequest(lowered);
47
+
48
+ if (explicitStage) {
49
+ const workflow = stageToWorkflow(explicitStage);
50
+ const def = getWorkflowDefinition(workflow);
51
+ const shouldOrchestrate = orchestrationSignal || broad || bigBuildSignal || (followUp && explicitStage === "build");
52
+ return {
53
+ role: explicitRole ?? def.preferredRole,
54
+ workflow,
55
+ stage: explicitStage,
56
+ executionMode: shouldOrchestrate ? "orchestrate" : "direct",
57
+ sessionRecommendation: shouldOrchestrate ? (broad || bigBuildSignal ? "create" : "consider") : "none",
58
+ reason: `Matched lifecycle stage ${explicitStage}.`,
59
+ };
60
+ }
61
+
62
+ if (explicitRole) {
63
+ const orchestrationRole = explicitRole === "orchestrator";
64
+ return {
65
+ role: explicitRole,
66
+ executionMode: orchestrationRole ? "orchestrate" : "direct",
67
+ sessionRecommendation: orchestrationRole ? "create" : "none",
68
+ reason: `Matched role ${explicitRole}.`,
69
+ };
70
+ }
71
+
72
+ if (orchestrationSignal || broad || bigBuildSignal) {
73
+ return {
74
+ role: "orchestrator",
75
+ workflow: "vibe-build",
76
+ stage: "build",
77
+ executionMode: "orchestrate",
78
+ sessionRecommendation: followUp || bigBuildSignal || broad ? "create" : "consider",
79
+ reason: followUp
80
+ ? "Follow-up request appears large enough to merit orchestration."
81
+ : "Broad request defaults to orchestrated Takomi lifecycle handling.",
82
+ };
83
+ }
84
+
85
+ return {
86
+ role: "general",
87
+ executionMode: "direct",
88
+ sessionRecommendation: followUp ? "consider" : "none",
89
+ reason: followUp
90
+ ? "Follow-up request may still fit direct execution; decide whether a new session is actually necessary."
91
+ : "No strong route detected; stay adaptive.",
92
+ };
93
+ }
@@ -0,0 +1,173 @@
1
+ export type TakomiRole = "general" | "orchestrator" | "architect" | "design" | "code" | "review";
2
+
3
+ export type TakomiWorkflowId = "vibe-genesis" | "vibe-design" | "vibe-build";
4
+
5
+ export type VibeLifecycleStage = "genesis" | "design" | "build";
6
+
7
+ export type TakomiThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh";
8
+
9
+ export type TakomiDispatchPolicy = "direct" | "subagent" | "review-first";
10
+
11
+ export type TakomiLaunchMode = "auto" | "manual";
12
+
13
+ export type TakomiRunPlacement = "foreground" | "background";
14
+
15
+ export type TakomiAgentScope = "user" | "project" | "both";
16
+
17
+ export type TakomiSubagentMode = "single" | "parallel" | "chain";
18
+
19
+ export type TakomiDispatchDefaults = {
20
+ agent?: string;
21
+ model?: string;
22
+ fallbackModels?: string[];
23
+ thinking?: TakomiThinkingLevel;
24
+ dispatchPolicy?: TakomiDispatchPolicy;
25
+ };
26
+
27
+ export type TakomiReviewProfile = {
28
+ enabled: boolean;
29
+ agent?: string;
30
+ maxIterations?: number;
31
+ sameConversation: boolean;
32
+ };
33
+
34
+ export type TakomiProfile = {
35
+ version: 1;
36
+ autoOrchestrate: boolean;
37
+ launchMode?: TakomiLaunchMode;
38
+ foreground?: boolean;
39
+ background?: boolean;
40
+ reviewAfterImplementation?: boolean;
41
+ roles?: Partial<Record<TakomiRole, TakomiDispatchDefaults>>;
42
+ stages?: Partial<Record<VibeLifecycleStage, TakomiDispatchDefaults>>;
43
+ review?: TakomiReviewProfile;
44
+ };
45
+
46
+ export type TakomiDelegationPlanTaskStatus = "planned" | "running" | "completed" | "blocked" | "cancelled";
47
+
48
+ export type TakomiDelegationPlanTask = {
49
+ id: string;
50
+ title: string;
51
+ agent: string;
52
+ task: string;
53
+ role?: TakomiRole;
54
+ stage?: VibeLifecycleStage;
55
+ workflow?: TakomiWorkflowId | string;
56
+ model?: string;
57
+ fallbackModels?: string[];
58
+ thinking?: TakomiThinkingLevel;
59
+ conversationId?: string;
60
+ checklist?: TaskChecklistItem[];
61
+ dispatchPolicy?: TakomiDispatchPolicy;
62
+ review: boolean;
63
+ status: TakomiDelegationPlanTaskStatus;
64
+ };
65
+
66
+ export type TakomiDelegationPlan = {
67
+ planId: string;
68
+ source: "runtime-board" | "takomi-tool";
69
+ launchMode: TakomiLaunchMode;
70
+ placement: TakomiRunPlacement;
71
+ reviewAfterImplementation: boolean;
72
+ createdAt: string;
73
+ sessionId?: string;
74
+ tasks: TakomiDelegationPlanTask[];
75
+ };
76
+
77
+ export type TakomiSubagentTask = {
78
+ agent: string;
79
+ task: string;
80
+ cwd?: string;
81
+ workflow?: string;
82
+ skills?: string[];
83
+ model?: string;
84
+ fallbackModels?: string[];
85
+ thinking?: TakomiThinkingLevel;
86
+ conversationId?: string;
87
+ checklist?: TaskChecklistItem[];
88
+ };
89
+
90
+ export type TakomiSubagentRunGroup = {
91
+ mode: TakomiSubagentMode;
92
+ agentScope: TakomiAgentScope;
93
+ tasks: TakomiSubagentTask[];
94
+ confirmProjectAgents: boolean;
95
+ launchMode: TakomiLaunchMode;
96
+ sessionId?: string;
97
+ };
98
+
99
+ export type WorkflowDefinition = {
100
+ id: TakomiWorkflowId;
101
+ stage: VibeLifecycleStage;
102
+ title: string;
103
+ purpose: string;
104
+ preferredRole: TakomiRole;
105
+ preferredAgent?: string;
106
+ preferredModelHint?: string;
107
+ nextStage?: VibeLifecycleStage;
108
+ playbook: string;
109
+ };
110
+
111
+ export type RouteDecision = {
112
+ role: TakomiRole;
113
+ workflow?: TakomiWorkflowId;
114
+ stage?: VibeLifecycleStage;
115
+ executionMode: "direct" | "orchestrate";
116
+ sessionRecommendation: "none" | "consider" | "create";
117
+ reason: string;
118
+ };
119
+
120
+ export type OrchestratorTaskStatus = "pending" | "in-progress" | "completed" | "blocked";
121
+
122
+ export type TaskChecklistItem = {
123
+ text: string;
124
+ done?: boolean;
125
+ };
126
+
127
+ export type OrchestratorTask = {
128
+ id: string;
129
+ title: string;
130
+ role: TakomiRole;
131
+ stage?: VibeLifecycleStage;
132
+ workflow?: TakomiWorkflowId;
133
+ parentTaskId?: string;
134
+ preferredAgent?: string;
135
+ preferredModelHint?: string;
136
+ preferredModel?: string;
137
+ preferredThinking?: TakomiThinkingLevel;
138
+ fallbackModels?: string[];
139
+ dispatchPolicy?: TakomiDispatchPolicy;
140
+ skills?: string[];
141
+ checklist?: TaskChecklistItem[];
142
+ objective?: string;
143
+ scope?: string[];
144
+ definitionOfDone?: string[];
145
+ expectedArtifacts?: string[];
146
+ dependencies?: string[];
147
+ reviewCheckpoint?: string;
148
+ instructions?: string[];
149
+ status: OrchestratorTaskStatus;
150
+ notes?: string;
151
+ conversationId?: string;
152
+ };
153
+
154
+ export type LifecycleStageState = {
155
+ status: OrchestratorTaskStatus;
156
+ taskIds: string[];
157
+ canExpand?: boolean;
158
+ expandedAt?: string;
159
+ notes?: string;
160
+ };
161
+
162
+ export type SessionIntent = "full-project" | "feature-scope" | "follow-up-task";
163
+
164
+ export type OrchestratorSessionState = {
165
+ sessionId: string;
166
+ title: string;
167
+ createdAt: string;
168
+ updatedAt: string;
169
+ mode: "hybrid";
170
+ lifecycle: Record<VibeLifecycleStage, LifecycleStageState>;
171
+ sessionIntent?: SessionIntent;
172
+ tasks: OrchestratorTask[];
173
+ };