@alisio/core 0.1.0-alpha.17 → 0.1.0-alpha.18

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.
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Pure logic for the ACTIVE (main-session) agent: the built-in catalog, user/plugin
3
+ * contributions, resolution and the per-run options an agent implies. No terminal or pi-tui
4
+ * imports here — the Picker and status-line rendering live in each surface (e.g. the TUI shell).
5
+ *
6
+ * The active agent drives the MAIN session (its `instructions` are appended per run and an
7
+ * agent-specific `model` is offered on selection). This is deliberately separate from the
8
+ * delegated child-session agents of the subagents plugin: a subagent definition becomes a main
9
+ * agent only when it is marked main-capable (`mode: primary|all`), which the subagents plugin
10
+ * publishes for the host to read.
11
+ */
12
+ export interface ActiveAgent {
13
+ /** Stable id, also the persisted `agents.active` value. */
14
+ id: string;
15
+ name: string;
16
+ description: string;
17
+ /** System prompt appended to the main session's instructions on every run. */
18
+ instructions?: string;
19
+ /** Optional default model selector (`provider/model` or an unambiguous model id). */
20
+ model?: string;
21
+ /** Read-only agents run with write/process/external tools disabled and approvals off. */
22
+ readOnly?: boolean;
23
+ /** Product built-ins are shown as built-in and never shadowed by contributed definitions. */
24
+ source: "builtin" | "user" | "plugin";
25
+ }
26
+ export declare const DEFAULT_AGENT_ID = "build";
27
+ /** Product built-ins. `build` keeps the CURRENT behavior exactly: no added persona, full power. */
28
+ export declare const BUILTIN_AGENTS: ActiveAgent[];
29
+ export interface MainCapableAgentRecord {
30
+ name: string;
31
+ description: string;
32
+ prompt: string;
33
+ model?: string;
34
+ readOnly?: boolean;
35
+ source: string;
36
+ path?: string;
37
+ }
38
+ /** Maps a main-capable definition published by the subagents plugin to an active agent. */
39
+ export declare function mainAgentFromRecord(record: MainCapableAgentRecord): ActiveAgent;
40
+ /** Builds the selectable catalog from the subagents plugin's published state (best-effort). */
41
+ export declare function agentCatalogFromState(untrusted: unknown): ActiveAgent[];
42
+ /**
43
+ * The full selectable catalog: built-ins first, then contributed main-capable definitions.
44
+ * A contributed definition may never shadow a built-in id; later duplicates of a contributed id
45
+ * are dropped (the subagents plugin already resolved precedence by its own discovery order).
46
+ */
47
+ export declare function activeAgentCatalog(contributions?: ActiveAgent[]): ActiveAgent[];
48
+ /** Resolves the persisted agent id; unknown ids fall back to the built-in default (`build`). */
49
+ export declare function resolveActiveAgent(agents: ActiveAgent[], id: string | undefined): ActiveAgent;
50
+ /** The run options an active agent implies. An undefined agent yields the current behavior. */
51
+ export declare function agentRunOptions(agent: ActiveAgent | undefined): {
52
+ instructions?: string;
53
+ policy?: {
54
+ write: false;
55
+ process: false;
56
+ external: false;
57
+ };
58
+ approvals?: false;
59
+ };
60
+ export interface AgentPickerItem {
61
+ value: string;
62
+ label: string;
63
+ description: string;
64
+ }
65
+ /** Picker rows for `/agents`: name with (current), built-in/default and read-only markers. */
66
+ export declare function agentPickerItems(agents: ActiveAgent[], activeId: string): AgentPickerItem[];
@@ -0,0 +1,113 @@
1
+ export const DEFAULT_AGENT_ID = "build";
2
+ const PLAN_INSTRUCTIONS = `You are the "plan" agent: a read-only planning assistant for this main session.
3
+
4
+ Your job is analysis and planning only. Investigate the repository with read-only tools
5
+ (list_files, search_text, read_file, git_status, git_diff) and return a concrete, ordered plan:
6
+ files to change, functions to touch, risks and verification steps. You may run context and
7
+ inspection tools that do not modify anything.
8
+
9
+ You never edit, write or delete files, and you never start processes that change the workspace
10
+ or the network. If a task requires changes, hand back a precise plan (and the exact commands)
11
+ instead of making them.`;
12
+ /** Product built-ins. `build` keeps the CURRENT behavior exactly: no added persona, full power. */
13
+ export const BUILTIN_AGENTS = [
14
+ {
15
+ id: DEFAULT_AGENT_ID,
16
+ name: "build",
17
+ description: "Default full-power agent: edits code and files, runs processes and verifies its work through the normal permission flow.",
18
+ source: "builtin",
19
+ },
20
+ {
21
+ id: "plan",
22
+ name: "plan",
23
+ description: "Read-only planning agent: analyzes the codebase and returns an implementation plan without modifying anything.",
24
+ instructions: PLAN_INSTRUCTIONS,
25
+ readOnly: true,
26
+ source: "builtin",
27
+ },
28
+ ];
29
+ /** Maps a main-capable definition published by the subagents plugin to an active agent. */
30
+ export function mainAgentFromRecord(record) {
31
+ const source = String(record.source ?? "");
32
+ return {
33
+ id: record.name,
34
+ name: record.name,
35
+ description: record.description,
36
+ ...(record.prompt ? { instructions: record.prompt } : {}),
37
+ ...(record.model ? { model: record.model } : {}),
38
+ ...(record.readOnly ? { readOnly: true } : {}),
39
+ ...(source.startsWith("plugin:")
40
+ ? { source: "plugin" }
41
+ : { source: "user" }),
42
+ };
43
+ }
44
+ /** Builds the selectable catalog from the subagents plugin's published state (best-effort). */
45
+ export function agentCatalogFromState(untrusted) {
46
+ if (!Array.isArray(untrusted))
47
+ return activeAgentCatalog([]);
48
+ const records = untrusted.filter((entry) => !!entry &&
49
+ typeof entry === "object" &&
50
+ typeof entry.name === "string" &&
51
+ typeof entry.description === "string" &&
52
+ entry.description.length > 0 &&
53
+ typeof entry.prompt === "string");
54
+ return activeAgentCatalog(records.map(mainAgentFromRecord));
55
+ }
56
+ /**
57
+ * The full selectable catalog: built-ins first, then contributed main-capable definitions.
58
+ * A contributed definition may never shadow a built-in id; later duplicates of a contributed id
59
+ * are dropped (the subagents plugin already resolved precedence by its own discovery order).
60
+ */
61
+ export function activeAgentCatalog(contributions = []) {
62
+ const seen = new Set();
63
+ const out = [];
64
+ for (const agent of [...BUILTIN_AGENTS, ...contributions]) {
65
+ if (seen.has(agent.id))
66
+ continue;
67
+ seen.add(agent.id);
68
+ out.push(agent);
69
+ }
70
+ return out;
71
+ }
72
+ /** Resolves the persisted agent id; unknown ids fall back to the built-in default (`build`). */
73
+ export function resolveActiveAgent(agents, id) {
74
+ const found = id ? agents.find((a) => a.id === id) : undefined;
75
+ if (found)
76
+ return found;
77
+ return agents.find((a) => a.id === DEFAULT_AGENT_ID) ?? agents[0] ?? BUILTIN_AGENTS[0];
78
+ }
79
+ /** The run options an active agent implies. An undefined agent yields the current behavior. */
80
+ export function agentRunOptions(agent) {
81
+ if (!agent)
82
+ return {};
83
+ return {
84
+ ...(agent.instructions ? { instructions: agent.instructions } : {}),
85
+ ...(agent.readOnly
86
+ ? {
87
+ policy: { write: false, process: false, external: false },
88
+ approvals: false,
89
+ }
90
+ : {}),
91
+ };
92
+ }
93
+ /** Picker rows for `/agents`: name with (current), built-in/default and read-only markers. */
94
+ export function agentPickerItems(agents, activeId) {
95
+ return agents.map((agent) => ({
96
+ value: agent.id,
97
+ label: [
98
+ agent.name,
99
+ agent.id === activeId ? "(current)" : undefined,
100
+ agent.id === DEFAULT_AGENT_ID ? "(default)" : undefined,
101
+ agent.readOnly ? "read-only" : undefined,
102
+ ]
103
+ .filter(Boolean)
104
+ .join(" · "),
105
+ description: [
106
+ agent.description,
107
+ agent.model ? `default model: ${agent.model}` : undefined,
108
+ agent.instructions ? "injects its system prompt from the next prompt" : undefined,
109
+ ]
110
+ .filter(Boolean)
111
+ .join(" · "),
112
+ }));
113
+ }
@@ -11,6 +11,7 @@ import { ProviderSettingsStore } from "./providers/settings.ts";
11
11
  import { ProjectContext } from "./resources/context.ts";
12
12
  import { Skills } from "./resources/skills.ts";
13
13
  import { type ExternalDirectoryHandler, PathAccess } from "./runtime/access.ts";
14
+ import { BlobStore } from "./runtime/blobs.ts";
14
15
  import { SQLiteStore } from "./runtime/store.ts";
15
16
  export interface AppOptions {
16
17
  cwd?: string;
@@ -117,6 +118,8 @@ export declare function createApplication(options?: AppOptions): Promise<{
117
118
  template: import("./index.ts").PromptTemplate;
118
119
  } | undefined;
119
120
  store: SQLiteStore;
121
+ /** Uploaded attachment bytes; resolve a `BlobRef` with `blobs.attachment(ref)` before a run. */
122
+ blobs: BlobStore;
120
123
  registry: ToolRegistry;
121
124
  context: ProjectContext;
122
125
  skills: Skills;
@@ -159,13 +162,16 @@ export declare function createApplication(options?: AppOptions): Promise<{
159
162
  * (only when runtime permission was granted). Never includes credentials or command paths.
160
163
  */
161
164
  mcpStartupFailures(): string[];
162
- /** Host-owned interactive consent boundary. Headless callers remain blocked unless flagged. */
165
+ /**
166
+ * Host-owned interactive consent boundary: the TUI and the web UI (`alisio serve`, after an
167
+ * explicit confirmation dialog) may grant. Headless callers remain blocked unless flagged.
168
+ */
163
169
  grantMcpRuntimePermission(request: {
164
- source: "interactive-tui";
170
+ source: "interactive-tui" | "interactive-web";
165
171
  confirmed: boolean;
166
172
  }): "granted" | "not-granted" | "read-only";
167
173
  /** Persist global consent atomically, then grant runtime permission for this process. */
168
- rememberGlobalMcpConsent(): Promise<void>;
174
+ rememberGlobalMcpConsent(source?: "interactive-tui" | "interactive-web"): Promise<void>;
169
175
  /**
170
176
  * Clear the persisted global consent atomically and drop the runtime permission (disconnecting
171
177
  * servers as cleanup does). An explicit this-run `--allow-mcp` flag keeps the grant alive.
@@ -15,6 +15,7 @@ import { ProjectContext } from "./resources/context.js";
15
15
  import { expandSlashPrompt, loadPromptTemplates, promptSources } from "./resources/prompts.js";
16
16
  import { Skills, skillRoots } from "./resources/skills.js";
17
17
  import { PathAccess } from "./runtime/access.js";
18
+ import { BlobStore } from "./runtime/blobs.js";
18
19
  import { isPathSpec } from "./runtime/modules.js";
19
20
  import { findWorkspace } from "./runtime/paths.js";
20
21
  import { SQLiteStore } from "./runtime/store.js";
@@ -76,6 +77,13 @@ export async function createApplication(options = {}) {
76
77
  readOnly: !!options.readOnly,
77
78
  });
78
79
  const store = new SQLiteStore(options.db ?? join(stateHome(), "sessions.sqlite"));
80
+ // Content-addressed attachment bytes next to the session database (no I/O until `put`).
81
+ const blobs = new BlobStore({
82
+ root: options.db && options.db !== ":memory:"
83
+ ? join(dirname(options.db), "blobs")
84
+ : join(stateHome(), "blobs"),
85
+ db: store.db,
86
+ });
79
87
  const registry = new ToolRegistry(), skills = new Skills({ overrides: config.skillOverrides }), context = new ProjectContext(workspace, {
80
88
  globalDir: configHome(),
81
89
  cwd,
@@ -532,6 +540,10 @@ export async function createApplication(options = {}) {
532
540
  // Child sessions (generic delegation service for plugins). Contexts are cached per workspace
533
541
  // so a child in a git worktree reads that worktree's AGENTS.md files.
534
542
  const contexts = new Map([[workspace, context]]);
543
+ // Startup reconciliation: runs left queued/running by a dead process become `interrupted`
544
+ // (runs of this process, e.g. another Application in a server, are kept). Child sessions are
545
+ // reconciled by `interruptStale()` in the ChildSessions constructor right below.
546
+ store.interruptRuns();
535
547
  plugins.setSessions(new ChildSessions({
536
548
  store,
537
549
  runner,
@@ -605,6 +617,8 @@ export async function createApplication(options = {}) {
605
617
  prompts,
606
618
  expandPrompt,
607
619
  store,
620
+ /** Uploaded attachment bytes; resolve a `BlobRef` with `blobs.attachment(ref)` before a run. */
621
+ blobs,
608
622
  registry,
609
623
  context,
610
624
  skills,
@@ -697,12 +711,15 @@ export async function createApplication(options = {}) {
697
711
  mcpStartupFailures() {
698
712
  return [...mcpStartupFailures];
699
713
  },
700
- /** Host-owned interactive consent boundary. Headless callers remain blocked unless flagged. */
714
+ /**
715
+ * Host-owned interactive consent boundary: the TUI and the web UI (`alisio serve`, after an
716
+ * explicit confirmation dialog) may grant. Headless callers remain blocked unless flagged.
717
+ */
701
718
  grantMcpRuntimePermission(request) {
702
719
  if (!request.confirmed)
703
720
  return mcpRuntimePermission;
704
- if (request.source !== "interactive-tui")
705
- throw new Error("MCP runtime permission may only be granted by the interactive TUI");
721
+ if (request.source !== "interactive-tui" && request.source !== "interactive-web")
722
+ throw new Error("MCP runtime permission may only be granted by an interactive UI");
706
723
  if (options.readOnly)
707
724
  throw new Error("MCP is unavailable under --read-only");
708
725
  if (mcpRuntimePermission === "granted")
@@ -713,12 +730,12 @@ export async function createApplication(options = {}) {
713
730
  return mcpRuntimePermission;
714
731
  },
715
732
  /** Persist global consent atomically, then grant runtime permission for this process. */
716
- async rememberGlobalMcpConsent() {
733
+ async rememberGlobalMcpConsent(source = "interactive-tui") {
717
734
  if (options.readOnly)
718
735
  throw new Error("MCP is unavailable under --read-only");
719
736
  await setGlobalMcpAllow({ allow: true });
720
737
  persistedMcpAllow = true;
721
- this.grantMcpRuntimePermission({ source: "interactive-tui", confirmed: true });
738
+ this.grantMcpRuntimePermission({ source, confirmed: true });
722
739
  },
723
740
  /**
724
741
  * Clear the persisted global consent atomically and drop the runtime permission (disconnecting
@@ -0,0 +1,10 @@
1
+ import type { CommandDescriptor } from "@alisio/sdk";
2
+ /** A built-in slash command: a descriptor without `source`/`owner` (always `builtin`). */
3
+ export type BuiltinCommand = Omit<CommandDescriptor, "source" | "owner">;
4
+ /**
5
+ * Built-in slash commands, in the order the TUI lists them. Names, aliases, descriptions and
6
+ * argument hints are the TUI's `COMMANDS` moved here as data (the TUI re-exports them).
7
+ * `execution: "core"` commands have a handler in `CommandCatalog.execute`; `surface` commands
8
+ * (clipboard, exit, settings/connect wizards, help, `/ask`) are handled by each UI.
9
+ */
10
+ export declare const BUILTIN_COMMANDS: readonly BuiltinCommand[];
@@ -0,0 +1,115 @@
1
+ const ALL = ["tui", "web", "api"];
2
+ const TUI = ["tui"];
3
+ const INTERACTIVE = ["tui", "web"];
4
+ /**
5
+ * Built-in slash commands, in the order the TUI lists them. Names, aliases, descriptions and
6
+ * argument hints are the TUI's `COMMANDS` moved here as data (the TUI re-exports them).
7
+ * `execution: "core"` commands have a handler in `CommandCatalog.execute`; `surface` commands
8
+ * (clipboard, exit, settings/connect wizards, help, `/ask`) are handled by each UI.
9
+ */
10
+ export const BUILTIN_COMMANDS = [
11
+ {
12
+ name: "help",
13
+ description: "Show commands and keys",
14
+ surfaces: INTERACTIVE,
15
+ execution: "surface",
16
+ },
17
+ {
18
+ name: "connect",
19
+ description: "Configure a provider and choose its active model",
20
+ surfaces: TUI,
21
+ execution: "surface",
22
+ },
23
+ {
24
+ name: "model",
25
+ description: "Switch provider and model",
26
+ aliases: ["models"],
27
+ surfaces: ALL,
28
+ execution: "core",
29
+ },
30
+ {
31
+ name: "compact",
32
+ description: "Summarize older history",
33
+ argumentHint: "[focus]",
34
+ surfaces: ALL,
35
+ execution: "core",
36
+ },
37
+ { name: "stats", description: "Session statistics", surfaces: ALL, execution: "core" },
38
+ {
39
+ name: "clear",
40
+ description: "Start a new session",
41
+ aliases: ["new"],
42
+ surfaces: ALL,
43
+ execution: "core",
44
+ },
45
+ { name: "sessions", description: "List recent sessions", surfaces: ALL, execution: "core" },
46
+ {
47
+ name: "resume",
48
+ description: "Resume a session by ID or prefix",
49
+ argumentHint: "<id>",
50
+ surfaces: ALL,
51
+ execution: "core",
52
+ },
53
+ {
54
+ name: "tools",
55
+ description: "List tools and permission state",
56
+ surfaces: ALL,
57
+ execution: "core",
58
+ },
59
+ {
60
+ name: "plugins",
61
+ description: "Browse and manage project plugins",
62
+ aliases: ["plugin"],
63
+ surfaces: ALL,
64
+ execution: "core",
65
+ },
66
+ {
67
+ name: "skills",
68
+ description: "Browse and manage effective skills",
69
+ aliases: ["skill"],
70
+ surfaces: ALL,
71
+ execution: "core",
72
+ },
73
+ { name: "mcp", description: "Browse and manage MCP servers", surfaces: ALL, execution: "core" },
74
+ {
75
+ name: "settings",
76
+ description: "Open the settings menu",
77
+ aliases: ["prefs"],
78
+ surfaces: TUI,
79
+ execution: "surface",
80
+ },
81
+ {
82
+ name: "copy",
83
+ description: "Copy the last assistant response to the clipboard",
84
+ surfaces: TUI,
85
+ execution: "surface",
86
+ },
87
+ {
88
+ name: "agents",
89
+ description: "List and switch the active agent (applies from the next prompt)",
90
+ argumentHint: "[<verb>]",
91
+ surfaces: ALL,
92
+ execution: "core",
93
+ },
94
+ {
95
+ name: "effort",
96
+ description: "Set the reasoning effort level for the active model",
97
+ argumentHint: "[level]",
98
+ surfaces: ALL,
99
+ execution: "core",
100
+ },
101
+ {
102
+ name: "ask",
103
+ description: "Ask the agent to turn your question into a multiple-choice ask_user_question",
104
+ argumentHint: "<question>",
105
+ surfaces: INTERACTIVE,
106
+ execution: "surface",
107
+ },
108
+ {
109
+ name: "exit",
110
+ description: "Exit Alisio",
111
+ aliases: ["quit"],
112
+ surfaces: TUI,
113
+ execution: "surface",
114
+ },
115
+ ];
@@ -0,0 +1,83 @@
1
+ /**
2
+ * One catalog of slash commands for every surface (TUI, web, API): built-ins, plugin commands,
3
+ * prompt templates and skills, with the pure core handlers of `execution: "core"` commands.
4
+ * The catalog reads its sources live from the host on each call, so plugin/template/skill
5
+ * changes show up without rebuilding it.
6
+ */
7
+ import type { CommandDescriptor, ToolDefinition } from "@alisio/sdk";
8
+ import type { PluginCatalogEntry } from "../application.ts";
9
+ import type { SessionStore } from "../core/contracts.ts";
10
+ import type { AgentRunner } from "../core/runner.ts";
11
+ import type { McpServerInfo } from "../mcp/connector.ts";
12
+ import type { PromptTemplate } from "../resources/prompts.ts";
13
+ import type { SkillCatalogEntry } from "../resources/skills.ts";
14
+ import { BUILTIN_COMMANDS, type BuiltinCommand } from "./builtins.ts";
15
+ export { BUILTIN_COMMANDS, type BuiltinCommand };
16
+ export type CommandSurface = CommandDescriptor["surfaces"][number];
17
+ type PluginCommandHandler = (args: string, context?: {
18
+ sessionId?: string;
19
+ }) => Promise<string>;
20
+ /**
21
+ * What the catalog needs from an application. `createApplication()`'s result satisfies it; the
22
+ * optional members only enable the matching sources and handlers.
23
+ */
24
+ export interface CommandHost {
25
+ workspace: string;
26
+ store: SessionStore;
27
+ runner: Pick<AgentRunner, "policy" | "approvals" | "compact" | "setModel">;
28
+ registry: {
29
+ list(): ToolDefinition[];
30
+ };
31
+ provider: {
32
+ id: string;
33
+ };
34
+ plugins?: {
35
+ commands: ReadonlyMap<string, PluginCommandHandler>;
36
+ commandInfo: ReadonlyMap<string, {
37
+ plugin: string;
38
+ description?: string;
39
+ argumentHint?: string;
40
+ }>;
41
+ pluginState?(plugin: string, key: string): unknown;
42
+ };
43
+ prompts?: {
44
+ templates: ReadonlyMap<string, PromptTemplate>;
45
+ };
46
+ skillCatalog?(): SkillCatalogEntry[];
47
+ pluginCatalog?(): PluginCatalogEntry[];
48
+ mcp?: {
49
+ list(): McpServerInfo[];
50
+ };
51
+ config?: {
52
+ agents: {
53
+ active?: string;
54
+ effort?: string;
55
+ };
56
+ };
57
+ updateSetting?(key: "agents.effort", value: unknown): Promise<string>;
58
+ }
59
+ export interface CommandExecutionContext {
60
+ sessionId: string;
61
+ signal?: AbortSignal;
62
+ }
63
+ export interface CommandResult {
64
+ /** Markdown for the user. */
65
+ text?: string;
66
+ /** `notice` is a short status line; `info` (default) a report. */
67
+ tone?: "info" | "notice";
68
+ /** The session the surface should switch to (`clear`/`new`, `resume`). */
69
+ sessionId?: string;
70
+ /** Structured result for programmatic callers (e.g. a `CompactionResult`). */
71
+ data?: unknown;
72
+ }
73
+ export declare class CommandCatalog {
74
+ private readonly host?;
75
+ constructor(host?: CommandHost | undefined);
76
+ private builtins;
77
+ /** Every descriptor (optionally for one surface). Precedence: builtin > plugin > prompt > skill. */
78
+ list(surface?: CommandSurface): CommandDescriptor[];
79
+ /** A command by name or alias (built-in names and aliases are case-insensitive). */
80
+ resolve(name: string): CommandDescriptor | undefined;
81
+ /** Runs an `execution: "core"` command. Surface commands and unknown names throw. */
82
+ execute(name: string, args: string, ctx: CommandExecutionContext): Promise<CommandResult>;
83
+ }