@alisio/core 0.1.0 → 0.2.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.
@@ -30,6 +30,18 @@ export interface ActiveAgent {
30
30
  }
31
31
  export declare const DEFAULT_AGENT_ID = "build";
32
32
  export declare const PLAN_AGENT_ID = "plan";
33
+ export interface PlanInstructionSettings {
34
+ /** `plan.diagrams`. */
35
+ diagrams: boolean;
36
+ /** `plan.maxDiagrams`. */
37
+ maxDiagrams: number;
38
+ }
39
+ export declare const DEFAULT_PLAN_SETTINGS: PlanInstructionSettings;
40
+ /**
41
+ * The plan agent's system prompt. The diagram style guide is part of it only while diagrams are on
42
+ * (`plan.diagrams` with a `plan.maxDiagrams` above 0).
43
+ */
44
+ export declare function planInstructions(settings?: PlanInstructionSettings): string;
33
45
  /** Product built-ins. `build` keeps the CURRENT behavior exactly: no added persona, full power. */
34
46
  export declare const BUILTIN_AGENTS: ActiveAgent[];
35
47
  export interface MainCapableAgentRecord {
@@ -67,7 +79,9 @@ export declare function nextAgent(agents: ActiveAgent[], currentId: string | und
67
79
  /** Resolves the persisted agent id; unknown ids fall back to the built-in default (`build`). */
68
80
  export declare function resolveActiveAgent(agents: ActiveAgent[], id: string | undefined): ActiveAgent;
69
81
  /** The run options an active agent implies. An undefined agent yields the current behavior. */
70
- export declare function agentRunOptions(agent: ActiveAgent | undefined): {
82
+ export declare function agentRunOptions(agent: ActiveAgent | undefined, settings?: {
83
+ plan?: PlanInstructionSettings;
84
+ }): {
71
85
  instructions?: string;
72
86
  policy?: {
73
87
  write: false;
@@ -1,7 +1,8 @@
1
1
  import { EXIT_PLAN_TOOL } from "../core/opt-in.js";
2
2
  export const DEFAULT_AGENT_ID = "build";
3
3
  export const PLAN_AGENT_ID = "plan";
4
- const PLAN_INSTRUCTIONS = `You are the "plan" agent: a read-only planning assistant for this main session.
4
+ export const DEFAULT_PLAN_SETTINGS = { diagrams: true, maxDiagrams: 5 };
5
+ const PLAN_BASE = `You are the "plan" agent: a read-only planning assistant for this main session.
5
6
 
6
7
  Your job is analysis and planning only. Investigate the repository with read-only tools
7
8
  (list_files, search_text, read_file, git_status, git_diff) and return a concrete, ordered plan:
@@ -15,7 +16,8 @@ approval hands the plan to the build agent.
15
16
 
16
17
  When the plan is complete, finish by calling \`exit_plan\` exactly once with the whole plan in
17
18
  Markdown (and a short \`title\`). Do not paste the plan in your reply first: exit_plan shows it to
18
- the user and asks for a decision. Write the plan with these sections, in this order:
19
+ the user and asks for a decision. The plan must be fully understandable on its own, as text. Write
20
+ it with these sections, in this order:
19
21
 
20
22
  # <Title>
21
23
  ## Goal
@@ -24,15 +26,51 @@ What will be true when this is done, in one or two sentences.
24
26
  What you found in the repository that the plan relies on (files, functions, conventions).
25
27
  ## Steps
26
28
  A numbered, ordered list. Each step names the files and functions to change and what changes.
29
+ ## Decisions
30
+ Only when there were real choices: each decision and why, in one line.
27
31
  ## Risks
28
32
  What could go wrong, what is uncertain, and what you did not verify.
29
33
  ## Verification
30
- The exact commands and checks that prove the work is done.
34
+ The exact commands and checks that prove the work is done.`;
35
+ const PLAN_DIAGRAMS = (max) => `
36
+
37
+ Diagrams (optional). exit_plan can also carry Mermaid diagrams in its \`diagrams\` argument, as
38
+ {id, title, explanation, section, type, mermaid}. Add one only when it explains the plan better than
39
+ the text does: a flow, the parts of a system and how they relate, a sequence between components, or
40
+ how data moves. Use 0 to ${max} per plan: a simple plan gets none. Never repeat what the text
41
+ already says and never add information that is not in the plan.
42
+ - One idea per diagram, about 40 nodes at most, labels of one to four plain words.
43
+ - id: kebab-case and stable (for example "request-flow"). title: a few words. explanation: one short
44
+ sentence about what it shows. section: the plan heading it illustrates (for example "Steps").
45
+ type: overview, flow, components, architecture, sequence, data, state or other.
46
+ - Mermaid types: flowchart (preferred; LR for flows, TD for layers), sequenceDiagram,
47
+ stateDiagram-v2, erDiagram, classDiagram, gantt, mindmap, timeline, journey. No click, links, HTML
48
+ tags or %%{init} directives.
49
+ - Style flowcharts with these classes by adding :::name to a node; Alisio defines their colors for
50
+ light and dark, so do not set colors yourself: input (what comes in), process (a step or a part
51
+ that does work), data (stored or exchanged data), system (a main part of the product), external
52
+ (a third party or an outside system), decision (a choice or condition), risk (a risk or an
53
+ uncertain part).
54
+ - Shapes with meaning: [rectangle] for steps, ([rounded]) for start and end, [(cylinder)] for stored
55
+ data, {rhombus} for decisions. Group related nodes with: subgraph Name ... end.
56
+ Example: flowchart LR; user([Request]):::input --> api[API]:::system --> db[(Store)]:::data
57
+ - When you revise a plan, send EVERY diagram that still applies, updated to match it (same id), and
58
+ leave out the ones that no longer apply. The tool result lists the diagrams it accepted, dropped
59
+ (with the reason) and removed: fix a dropped one in the next revision.`;
60
+ const PLAN_TAIL = `
31
61
 
32
62
  Read the tool result: "approved" means the build agent will implement the plan, so reply with one
33
63
  short sentence and stop. "skipped" means stay in plan mode and do not call exit_plan again unless
34
64
  asked. "feedback" carries extra context from the user: revise the plan and call exit_plan again
35
65
  with the complete updated plan.`;
66
+ /**
67
+ * The plan agent's system prompt. The diagram style guide is part of it only while diagrams are on
68
+ * (`plan.diagrams` with a `plan.maxDiagrams` above 0).
69
+ */
70
+ export function planInstructions(settings = DEFAULT_PLAN_SETTINGS) {
71
+ const diagrams = settings.diagrams && settings.maxDiagrams > 0;
72
+ return `${PLAN_BASE}${diagrams ? PLAN_DIAGRAMS(settings.maxDiagrams) : ""}${PLAN_TAIL}`;
73
+ }
36
74
  /** Product built-ins. `build` keeps the CURRENT behavior exactly: no added persona, full power. */
37
75
  export const BUILTIN_AGENTS = [
38
76
  {
@@ -45,7 +83,7 @@ export const BUILTIN_AGENTS = [
45
83
  id: PLAN_AGENT_ID,
46
84
  name: "plan",
47
85
  description: "Read-only planning agent: analyzes the codebase and returns an implementation plan without modifying anything.",
48
- instructions: PLAN_INSTRUCTIONS,
86
+ instructions: planInstructions(),
49
87
  readOnly: true,
50
88
  source: "builtin",
51
89
  },
@@ -139,15 +177,16 @@ export function resolveActiveAgent(agents, id) {
139
177
  return agents.find((a) => a.id === DEFAULT_AGENT_ID) ?? agents[0] ?? BUILTIN_AGENTS[0];
140
178
  }
141
179
  /** The run options an active agent implies. An undefined agent yields the current behavior. */
142
- export function agentRunOptions(agent) {
180
+ export function agentRunOptions(agent, settings) {
143
181
  if (!agent)
144
182
  return {};
183
+ const builtinPlan = agent.id === PLAN_AGENT_ID && agent.source === "builtin";
184
+ // The built-in plan agent's prompt follows `plan.diagrams` / `plan.maxDiagrams` (read live).
185
+ const instructions = builtinPlan && settings?.plan ? planInstructions(settings.plan) : agent.instructions;
145
186
  return {
146
- ...(agent.instructions ? { instructions: agent.instructions } : {}),
187
+ ...(instructions ? { instructions } : {}),
147
188
  // `exit_plan` exists for the built-in plan agent only (it is hidden from every other run).
148
- ...(agent.id === PLAN_AGENT_ID && agent.source === "builtin"
149
- ? { optInTools: [EXIT_PLAN_TOOL] }
150
- : {}),
189
+ ...(builtinPlan ? { optInTools: [EXIT_PLAN_TOOL] } : {}),
151
190
  ...(agent.effort ? { reasoningEffort: agent.effort } : {}),
152
191
  ...(agent.readOnly
153
192
  ? {