zidane 2.0.1 → 2.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.
Files changed (36) hide show
  1. package/README.md +40 -26
  2. package/dist/{agent-D-ZFMbSd.d.ts → agent-vPBFXnu-.d.ts} +389 -274
  3. package/dist/{chunk-SZA4FKW5.js → chunk-2EQT4EHD.js} +4 -3
  4. package/dist/{chunk-PJUUYBKF.js → chunk-37GD7NL3.js} +45 -16
  5. package/dist/{chunk-LVC7NQUZ.js → chunk-BW3WTFIR.js} +1 -1
  6. package/dist/{chunk-FRNFVKWW.js → chunk-CDRXC7A7.js} +64 -33
  7. package/dist/{chunk-PASFWG7S.js → chunk-F5UBXERT.js} +309 -77
  8. package/dist/{chunk-7JTBBZ2U.js → chunk-LNN5UTS2.js} +8 -0
  9. package/dist/{chunk-VG2E6YK3.js → chunk-PMCQOMV4.js} +4 -2
  10. package/dist/{chunk-LN4LLLHA.js → chunk-S3FCOMRI.js} +63 -20
  11. package/dist/{chunk-OVQ4N64O.js → chunk-SP5NA6WF.js} +6 -12
  12. package/dist/{chunk-BCXXXJ3G.js → chunk-TPXPVEH6.js} +99 -58
  13. package/dist/contexts.js +1 -1
  14. package/dist/index.d.ts +6 -5
  15. package/dist/index.js +16 -16
  16. package/dist/mcp.d.ts +1 -1
  17. package/dist/mcp.js +1 -1
  18. package/dist/presets.d.ts +33 -0
  19. package/dist/presets.js +15 -0
  20. package/dist/providers.d.ts +1 -1
  21. package/dist/providers.js +3 -3
  22. package/dist/session/sqlite.d.ts +1 -1
  23. package/dist/session.d.ts +1 -1
  24. package/dist/session.js +3 -3
  25. package/dist/{skills-use-C4KFVla0.d.ts → skills-use-39cCsA7_.d.ts} +4 -4
  26. package/dist/skills.d.ts +3 -9
  27. package/dist/skills.js +3 -5
  28. package/dist/spawn-Czx3owjX.d.ts +152 -0
  29. package/dist/tools.d.ts +6 -4
  30. package/dist/tools.js +5 -5
  31. package/dist/types.d.ts +3 -2
  32. package/dist/types.js +1 -1
  33. package/package.json +5 -5
  34. package/dist/harnesses.d.ts +0 -4
  35. package/dist/harnesses.js +0 -17
  36. package/dist/spawn-RoqpjYLZ.d.ts +0 -99
@@ -6,7 +6,7 @@ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
6
6
  * Typed error classes for agent runs.
7
7
  *
8
8
  * Providers classify native errors into one of these so downstream consumers
9
- * (e.g. harness adapters) can react without string-sniffing messages.
9
+ * can react without string-sniffing messages.
10
10
  *
11
11
  * Provider authors: implement `Provider.classifyError` to map native errors
12
12
  * (SDK exceptions, HTTP responses) to a `ClassifiedError`. The loop wraps
@@ -21,6 +21,13 @@ interface ClassifiedError {
21
21
  providerCode?: string;
22
22
  /** Optional human-readable message override. Falls back to the underlying error's message. */
23
23
  message?: string;
24
+ /**
25
+ * Hint that the error is transient and a retry with backoff is reasonable
26
+ * (e.g. 429, 5xx, truncated stream). Omitted when the provider can't decide;
27
+ * callers should default to "do not retry" when absent to avoid hammering
28
+ * terminal failures (auth, invalid request).
29
+ */
30
+ retryable?: boolean;
24
31
  }
25
32
  interface TypedErrorOptions {
26
33
  /** Provider name, always set (e.g. `anthropic`, `openrouter`) */
@@ -29,6 +36,8 @@ interface TypedErrorOptions {
29
36
  providerCode?: string;
30
37
  /** Original error from the provider SDK/HTTP layer */
31
38
  cause?: unknown;
39
+ /** See {@link ClassifiedError.retryable}. */
40
+ retryable?: boolean;
32
41
  }
33
42
  /**
34
43
  * Thrown when the model or provider signals that the context window was exceeded.
@@ -48,6 +57,12 @@ declare class AgentProviderError extends Error {
48
57
  readonly code: "provider_error";
49
58
  readonly provider: string;
50
59
  readonly providerCode?: string;
60
+ /**
61
+ * Whether a retry with backoff is likely to succeed. See
62
+ * {@link ClassifiedError.retryable}. Absent when the provider did not
63
+ * classify the error — callers should treat absent as "don't retry".
64
+ */
65
+ readonly retryable?: boolean;
51
66
  constructor(message: string, options: TypedErrorOptions);
52
67
  }
53
68
  /**
@@ -295,9 +310,9 @@ interface AgentRunOptions {
295
310
  images?: ImageContent[];
296
311
  /** Abort signal — when triggered, the agent stops after the current turn */
297
312
  signal?: AbortSignal;
298
- /** Behavior overrides for this run (overrides agent and harness defaults) */
313
+ /** Behavior overrides for this run (overrides agent defaults) */
299
314
  behavior?: AgentBehavior;
300
- /** Tool overrides for this run. Pass {} for no tools. Omit to use harness tools. */
315
+ /** Tool overrides for this run. Pass {} for no tools. Omit to use agent tools. */
301
316
  tools?: Record<string, ToolDef>;
302
317
  /**
303
318
  * Per-run hook registrations. Each hook is attached before the run starts and
@@ -306,6 +321,18 @@ interface AgentRunOptions {
306
321
  * Accepts either a single handler or an array (all handlers register).
307
322
  */
308
323
  hooks?: RunHookMap;
324
+ /**
325
+ * Parent run id. Populated automatically by the `spawn` tool when the child
326
+ * shares the parent's session; recorded on the resulting `SessionRun` so the
327
+ * parent↔child run tree can be reconstructed from a persisted session.
328
+ */
329
+ parentRunId?: string;
330
+ /**
331
+ * Zero-based subagent depth. 0 = top-level `agent.run()`, 1 = first-level
332
+ * child spawned by a parent agent, and so on. Used by the spawn tool to
333
+ * enforce `maxDepth` and to stamp `child:*` forwarded hook payloads.
334
+ */
335
+ depth?: number;
309
336
  }
310
337
  /** Reason the provider gave for stopping the turn */
311
338
  type TurnFinishReason = 'stop' | 'tool-calls' | 'length' | 'content-filter' | 'error' | 'other';
@@ -356,15 +383,33 @@ interface ChildRunStats {
356
383
  id: string;
357
384
  task: string;
358
385
  stats: AgentStats;
386
+ /**
387
+ * Subagent depth when this child ran. 1 = direct child of the top-level
388
+ * agent, 2 = grandchild, etc. Useful for telemetry that wants to group
389
+ * runs by depth.
390
+ */
391
+ depth?: number;
392
+ /**
393
+ * Terminal state of the child run. `'completed'` is the default. Exposed so
394
+ * a parent reading `stats.children` can distinguish aborted/timed-out
395
+ * children without re-parsing the returned string.
396
+ */
397
+ status?: 'completed' | 'aborted' | 'timeout' | 'error';
398
+ /**
399
+ * Final structured output when the child was run with `behavior.schema`.
400
+ * Mirrors `AgentStats.output` but is surfaced here so the parent can read
401
+ * it without peeking at the nested `stats` bag.
402
+ */
403
+ output?: Record<string, unknown>;
359
404
  }
360
405
  /**
361
406
  * Base context for tool execution hooks.
362
407
  *
363
- * `name` is the canonical tool identity — the spec name defined in the harness (or the
408
+ * `name` is the canonical tool identity — the spec name registered on the agent (or the
364
409
  * `mcp_{server}_{tool}` name for MCP tools). Hooks should policy-match against `name`.
365
410
  *
366
411
  * `displayName` is the outward-facing name — the alias surfaced to the LLM when
367
- * `HarnessConfig.toolAliases` maps the canonical name; otherwise equal to `name`.
412
+ * `AgentOptions.toolAliases` maps the canonical name; otherwise equal to `name`.
368
413
  * UI/telemetry adapters should emit `displayName`.
369
414
  *
370
415
  * Canonical vs. alias matters on session resume: `session.turns` persists canonical
@@ -373,7 +418,7 @@ interface ChildRunStats {
373
418
  interface ToolHookContext {
374
419
  turnId: string;
375
420
  callId: string;
376
- /** Canonical tool name (harness spec name). Stable across alias-map changes. */
421
+ /** Canonical tool name (spec name). Stable across alias-map changes. */
377
422
  name: string;
378
423
  /** Aliased (wire) name — equal to `name` when no alias is defined. */
379
424
  displayName: string;
@@ -385,8 +430,8 @@ interface ToolHookContext {
385
430
  * `tool` is the native tool name on the MCP server. `server` is the configured server
386
431
  * name. The canonical zidane-namespaced identity is `mcp_{server}_{tool}`.
387
432
  *
388
- * `displayName` equals the canonical namespaced name unless the harness has aliased
389
- * this MCP tool via `HarnessConfig.toolAliases`; in which case `displayName` is the
433
+ * `displayName` equals the canonical namespaced name unless the agent has aliased
434
+ * this MCP tool via `AgentOptions.toolAliases`; in which case `displayName` is the
390
435
  * alias that the LLM sees.
391
436
  */
392
437
  interface McpToolHookContext {
@@ -406,6 +451,12 @@ interface SessionHookContext {
406
451
  interface SpawnHookContext {
407
452
  id: string;
408
453
  task: string;
454
+ /**
455
+ * Subagent depth for the spawn. 1 = direct child of the top-level agent.
456
+ * Present on spawn:before/complete/error. Absent for grandchild spawns that
457
+ * bubble through `child:*` events (which carry their own `depth`).
458
+ */
459
+ depth?: number;
409
460
  }
410
461
  /** Context for stream hooks */
411
462
  interface StreamHookContext {
@@ -711,263 +762,6 @@ interface Provider {
711
762
  classifyError?: (err: unknown) => ClassifiedError | null;
712
763
  }
713
764
 
714
- /**
715
- * Types for the Agent Skills system.
716
- *
717
- * Follows the Agent Skills open standard (agentskills.io/specification).
718
- * Zidane-specific metadata conventionally uses the `zidane.` key prefix
719
- * (e.g. `metadata['zidane.paths']`) to stay spec-compliant.
720
- */
721
- interface SkillResource {
722
- /** Relative path from skill directory */
723
- path: string;
724
- /** Resource type inferred from directory */
725
- type: 'script' | 'reference' | 'asset' | 'other';
726
- }
727
- /**
728
- * Where the skill came from. Used for collision precedence (project beats user)
729
- * and for host SDKs to gate project-level skills on a trust check.
730
- */
731
- type SkillSource = 'project' | 'user' | 'inline' | 'builtin';
732
- /** Severity + code for lenient-load warnings surfaced to host UIs. */
733
- interface SkillDiagnostic {
734
- severity: 'warning' | 'error';
735
- /** Stable machine-readable code (e.g. `name-mismatch-directory`). */
736
- code: string;
737
- /** Human-readable description. */
738
- message: string;
739
- /** Optional frontmatter field name the diagnostic relates to. */
740
- field?: string;
741
- }
742
- interface SkillConfig {
743
- /** Skill name: 1-64 chars, lowercase alphanumeric + hyphens */
744
- name: string;
745
- /** What the skill does and when to use it (1-1024 chars) */
746
- description: string;
747
- /** The SKILL.md body content (after YAML frontmatter) */
748
- instructions: string;
749
- /**
750
- * Where this skill was loaded from. Drives collision precedence and the
751
- * `trustProjectSkills` gate. Optional — `parseSkillFile` stamps it; raw
752
- * fixtures that omit it are treated as `'project'` by downstream readers.
753
- */
754
- source?: SkillSource;
755
- /** Absolute path to SKILL.md (undefined for inline skills) */
756
- location?: string;
757
- /** Skill directory path for resolving relative references */
758
- baseDir?: string;
759
- /** License identifier or reference */
760
- license?: string;
761
- /** Environment requirements */
762
- compatibility?: string;
763
- /**
764
- * Flat key-value metadata bag per the spec. For Zidane-specific hints,
765
- * use the `zidane.` key prefix (e.g. `metadata['zidane.paths']`).
766
- */
767
- metadata?: Record<string, string>;
768
- /** Pre-approved tool names (experimental per spec) */
769
- allowedTools?: string[];
770
- /** Bundled resource files discovered in the skill directory */
771
- resources?: SkillResource[];
772
- /**
773
- * Lenient-load warnings recorded during parsing. Host SDKs can surface these
774
- * as inline UI hints. Absent when no issues were found.
775
- */
776
- diagnostics?: SkillDiagnostic[];
777
- }
778
- interface SkillsConfig {
779
- /**
780
- * Control which skills are active.
781
- * - `true` (default): all discovered skills are enabled
782
- * - `false` or `[]`: fully disable the skills system (no resolution, no catalog, no hooks)
783
- * - `string[]`: allowlist — only skills with matching names are enabled
784
- */
785
- enabled?: boolean | string[];
786
- /** Directories to scan for SKILL.md files */
787
- scan?: string[];
788
- /** Dynamic skills written to disk at agent start, then loaded normally */
789
- write?: SkillConfig[];
790
- /** Skill names to exclude from the catalog */
791
- exclude?: string[];
792
- /** Skip default scan paths (~/.agents/skills, .zidane/skills, etc.) */
793
- skipDefaultPaths?: boolean;
794
- /**
795
- * Auto-inject `skills_use` / `skills_read` / `skills_run_script` tools
796
- * when the catalog is non-empty. Default `true`. Set `false` to opt out
797
- * (the system prompt will then instruct the model to use its file-read
798
- * tool instead).
799
- */
800
- tool?: boolean;
801
- /**
802
- * Cap on concurrently active skills per run. Default `undefined` (unlimited).
803
- * Attempts to activate past the cap throw from `skills_use`.
804
- */
805
- maxActive?: number;
806
- /** Script timeout for `skills_run_script`, in milliseconds. Default `60000`. */
807
- scriptTimeoutMs?: number;
808
- /**
809
- * When `false`, skills with `source: 'project'` are skipped during
810
- * resolution with a diagnostic. Default `true` (preserves existing behavior).
811
- * Useful for host SDKs handling untrusted repositories.
812
- */
813
- trustProjectSkills?: boolean;
814
- }
815
-
816
- /** Core tools available in every basic harness (without spawn) */
817
- declare const basicTools: {
818
- shell: ToolDef;
819
- readFile: ToolDef;
820
- writeFile: ToolDef;
821
- listFiles: ToolDef;
822
- };
823
- declare const _default: HarnessConfig;
824
-
825
- /**
826
- * Runtime context passed to every tool execution.
827
- * Provides access to the agent's provider, abort signal, execution environment, and hooks.
828
- */
829
- interface ToolContext {
830
- /** The LLM provider for this agent run */
831
- provider: Provider;
832
- /** Abort signal — tools should check this for early termination */
833
- signal: AbortSignal;
834
- /** The execution context (shell, filesystem, etc.) */
835
- execution: ExecutionContext;
836
- /** The active execution handle for the current agent run */
837
- handle: ExecutionHandle;
838
- /** Agent hooks for emitting events (e.g. spawn:complete) */
839
- hooks: Hookable<AgentHooks>;
840
- /** The harness config for this agent (tools available to the agent) */
841
- harness: HarnessConfig;
842
- /** Turn ID that requested this tool call */
843
- turnId: string;
844
- /** Tool call ID from the model */
845
- callId: string;
846
- }
847
- interface ToolDef {
848
- spec: ToolSpec;
849
- /**
850
- * Execute the tool and return its output.
851
- *
852
- * Return a plain string for text-only tools (the common case). Return a
853
- * `ToolResultContent[]` when the tool produces non-text content (images, mixed
854
- * text+image) that the provider can route through natively (Anthropic
855
- * `tool_result.content` arrays, OpenAI Codex pi-ai) or through the
856
- * companion-user-message fallback (OpenAI Chat Completions).
857
- */
858
- execute: (input: Record<string, unknown>, ctx: ToolContext) => Promise<string | ToolResultContent[]>;
859
- }
860
- type ToolMap = Map<string, ToolDef>;
861
- interface HarnessConfig {
862
- /** Display name for this harness */
863
- name: string;
864
- /** Default system prompt injected when no system is provided at run time */
865
- system?: string;
866
- /** Tool definitions available to the agent */
867
- tools: Record<string, ToolDef>;
868
- /** MCP servers to connect and expose as tools */
869
- mcpServers?: McpServerConfig[];
870
- /** Skills configuration at the harness level */
871
- skills?: SkillsConfig;
872
- /** Default behavior for agents using this harness */
873
- behavior?: AgentBehavior;
874
- /**
875
- * Map canonical tool names to LLM-facing (aliased) names.
876
- *
877
- * Aliasing is **LLM-boundary-only**:
878
- * - The alias is what the provider's tool spec carries, what the model calls it, and
879
- * what appears in `ToolHookContext.displayName` / `McpToolHookContext.displayName`.
880
- * - The canonical name is what lives in `session.turns`, `ToolHookContext.name`, and
881
- * what the agent uses to look up the tool implementation. Alias changes never
882
- * desync persisted history.
883
- *
884
- * Keys are canonical names from `tools` (or `mcp_{server}_{tool}` for MCP tools).
885
- * Collisions between aliases are rejected by the loop.
886
- *
887
- * @example
888
- * ```ts
889
- * defineHarness({
890
- * tools: { ...basicTools },
891
- * toolAliases: { shell: 'Bash', read_file: 'Read', write_file: 'Write' },
892
- * })
893
- * ```
894
- *
895
- * @remarks Alias a tool only when the aliased name is semantically equivalent.
896
- * `list_files` → `Glob` is NOT a valid alias because Glob is pattern-based.
897
- */
898
- toolAliases?: Record<string, string>;
899
- }
900
- /**
901
- * Define a harness with a name, optional system prompt, and tools.
902
- */
903
- declare function defineHarness(config: HarnessConfig): HarnessConfig;
904
- type Harness = HarnessConfig;
905
- /**
906
- * A harness with no tools — for pure chat mode.
907
- * Pass `tools: {}` in agent.run() or use this harness directly.
908
- */
909
- declare const noTools: HarnessConfig;
910
-
911
- /**
912
- * MCP (Model Context Protocol) server support.
913
- *
914
- * Connects to one or more MCP servers, discovers their tools,
915
- * and wraps them as zidane ToolDefs for use in agent loops.
916
- */
917
-
918
- interface McpConnection {
919
- tools: Record<string, ToolDef>;
920
- close: () => Promise<void>;
921
- }
922
- /**
923
- * Normalize MCP server configs from any common shape to `McpServerConfig[]`.
924
- *
925
- * Accepts:
926
- * - `McpServerConfig[]` — zidane native (pass-through).
927
- * - `McpServerConfig` — a single config object (wrapped to a 1-element array).
928
- * - `Record<string, RawShape>` — name-keyed map (common in host-SDK configs), where the key is the server name.
929
- * - Mixed shapes with `type` vs `transport`, `httpUrl`/`sseUrl` vs `url`.
930
- *
931
- * Returns `[]` when `input` is nullish. Throws a descriptive error when the transport
932
- * cannot be inferred from a given entry, or when the input shape is unsupported.
933
- */
934
- declare function normalizeMcpServers(input: unknown): McpServerConfig[];
935
- /**
936
- * Lossy flattener — converts MCP `CallToolResult.content` blocks to a single string.
937
- * Text blocks are extracted; non-text blocks are JSON-stringified.
938
- *
939
- * Prefer {@link normalizeMcpBlocks} for new code — it preserves image blocks so the
940
- * provider can route them through to the model natively (Anthropic tool_result blocks,
941
- * OpenAI companion-user-message). This function is kept for back-compat and is useful
942
- * as a logging/display helper where a single string is required.
943
- */
944
- declare function resultToString(content: unknown[]): string;
945
- /**
946
- * Normalize MCP `CallToolResult.content` to zidane's {@link ToolResultContent[]} shape.
947
- *
948
- * Handles the four MCP content block types:
949
- * - `text` → preserved as `{type:'text', text}`
950
- * - `image` → preserved as `{type:'image', mediaType, data}` (MCP uses `mimeType`)
951
- * - `resource` with embedded text → flattened to a text block
952
- * - `resource` with embedded blob whose `mimeType` is `image/*` → flattened to an image block
953
- * - Any unrecognized block → JSON-stringified fallback text block (lossy but safe)
954
- *
955
- * Returns `null` when the input is not an array — callers should fall back to an empty
956
- * result in that case.
957
- */
958
- declare function normalizeMcpBlocks(content: unknown): ToolResultContent[] | null;
959
- /**
960
- * Connect to MCP servers and discover their tools.
961
- *
962
- * Each tool is namespaced as `mcp_{serverName}_{toolName}` to avoid
963
- * collisions with harness tools or tools from other servers.
964
- *
965
- * @param configs - Array of MCP server configurations
966
- * @param _clientFactory - Internal: override client construction for testing
967
- * @param hooks - Optional agent hooks for firing mcp:connect, mcp:error, mcp:close events
968
- */
969
- declare function connectMcpServers(configs: McpServerConfig[], _clientFactory?: () => Client, hooks?: Hookable<AgentHooks>): Promise<McpConnection>;
970
-
971
765
  /**
972
766
  * File-map session store.
973
767
  *
@@ -1108,6 +902,17 @@ interface SessionRun {
1108
902
  totalUsage?: TurnUsage;
1109
903
  /** Estimated cost in USD */
1110
904
  cost?: number;
905
+ /**
906
+ * The run that spawned this one, when the agent is a subagent sharing its
907
+ * parent's session. Undefined on top-level `agent.run()`. Consumers can walk
908
+ * `runs` by `parentRunId` to reconstruct the subagent tree.
909
+ */
910
+ parentRunId?: string;
911
+ /**
912
+ * Zero-based subagent depth. 0 = top-level run, 1 = direct child, …
913
+ * Recorded here so hosts can query/filter by level without walking the tree.
914
+ */
915
+ depth?: number;
1111
916
  }
1112
917
  interface SessionData {
1113
918
  id: string;
@@ -1164,8 +969,15 @@ interface Session {
1164
969
  readonly runs: SessionRun[];
1165
970
  /** Arbitrary metadata */
1166
971
  readonly metadata: Record<string, unknown>;
1167
- /** Start tracking a new run */
1168
- startRun: (runId: string, prompt?: string) => void;
972
+ /**
973
+ * Start tracking a new run. `extras.parentRunId` + `extras.depth` are
974
+ * populated by the spawn tool when a child agent shares its parent's
975
+ * session; regular top-level `agent.run()` calls omit them.
976
+ */
977
+ startRun: (runId: string, prompt?: string, extras?: {
978
+ parentRunId?: string;
979
+ depth?: number;
980
+ }) => void;
1169
981
  /** Mark a run as completed */
1170
982
  completeRun: (runId: string, stats: {
1171
983
  turns: number;
@@ -1216,6 +1028,250 @@ declare function createSession(options?: CreateSessionOptions): Promise<Session>
1216
1028
  */
1217
1029
  declare function loadSession(store: SessionStore, sessionId: string): Promise<Session | null>;
1218
1030
 
1031
+ /**
1032
+ * Types for the Agent Skills system.
1033
+ *
1034
+ * Follows the Agent Skills open standard (agentskills.io/specification).
1035
+ * Zidane-specific metadata conventionally uses the `zidane.` key prefix
1036
+ * (e.g. `metadata['zidane.paths']`) to stay spec-compliant.
1037
+ */
1038
+ interface SkillResource {
1039
+ /** Relative path from skill directory */
1040
+ path: string;
1041
+ /** Resource type inferred from directory */
1042
+ type: 'script' | 'reference' | 'asset' | 'other';
1043
+ }
1044
+ /**
1045
+ * Where the skill came from. Used for collision precedence (project beats user)
1046
+ * and for host SDKs to gate project-level skills on a trust check.
1047
+ */
1048
+ type SkillSource = 'project' | 'user' | 'inline' | 'builtin';
1049
+ /** Severity + code for lenient-load warnings surfaced to host UIs. */
1050
+ interface SkillDiagnostic {
1051
+ severity: 'warning' | 'error';
1052
+ /** Stable machine-readable code (e.g. `name-mismatch-directory`). */
1053
+ code: string;
1054
+ /** Human-readable description. */
1055
+ message: string;
1056
+ /** Optional frontmatter field name the diagnostic relates to. */
1057
+ field?: string;
1058
+ }
1059
+ interface SkillConfig {
1060
+ /** Skill name: 1-64 chars, lowercase alphanumeric + hyphens */
1061
+ name: string;
1062
+ /** What the skill does and when to use it (1-1024 chars) */
1063
+ description: string;
1064
+ /** The SKILL.md body content (after YAML frontmatter) */
1065
+ instructions: string;
1066
+ /**
1067
+ * Where this skill was loaded from. Drives collision precedence and the
1068
+ * `trustProjectSkills` gate. Optional — `parseSkillFile` stamps it; raw
1069
+ * fixtures that omit it are treated as `'project'` by downstream readers.
1070
+ */
1071
+ source?: SkillSource;
1072
+ /** Absolute path to SKILL.md (undefined for inline skills) */
1073
+ location?: string;
1074
+ /** Skill directory path for resolving relative references */
1075
+ baseDir?: string;
1076
+ /** License identifier or reference */
1077
+ license?: string;
1078
+ /** Environment requirements */
1079
+ compatibility?: string;
1080
+ /**
1081
+ * Flat key-value metadata bag per the spec. For Zidane-specific hints,
1082
+ * use the `zidane.` key prefix (e.g. `metadata['zidane.paths']`).
1083
+ */
1084
+ metadata?: Record<string, string>;
1085
+ /** Pre-approved tool names (experimental per spec) */
1086
+ allowedTools?: string[];
1087
+ /** Bundled resource files discovered in the skill directory */
1088
+ resources?: SkillResource[];
1089
+ /**
1090
+ * Lenient-load warnings recorded during parsing. Host SDKs can surface these
1091
+ * as inline UI hints. Absent when no issues were found.
1092
+ */
1093
+ diagnostics?: SkillDiagnostic[];
1094
+ }
1095
+ interface SkillsConfig {
1096
+ /**
1097
+ * Control which skills are active.
1098
+ * - `true` (default): all discovered skills are enabled
1099
+ * - `false` or `[]`: fully disable the skills system (no resolution, no catalog, no hooks)
1100
+ * - `string[]`: allowlist — only skills with matching names are enabled
1101
+ */
1102
+ enabled?: boolean | string[];
1103
+ /** Directories to scan for SKILL.md files */
1104
+ scan?: string[];
1105
+ /** Dynamic skills written to disk at agent start, then loaded normally */
1106
+ write?: SkillConfig[];
1107
+ /** Skill names to exclude from the catalog */
1108
+ exclude?: string[];
1109
+ /** Skip default scan paths (~/.agents/skills, .zidane/skills, etc.) */
1110
+ skipDefaultPaths?: boolean;
1111
+ /**
1112
+ * Auto-inject `skills_use` / `skills_read` / `skills_run_script` tools
1113
+ * when the catalog is non-empty. Default `true`. Set `false` to opt out
1114
+ * (the system prompt will then instruct the model to use its file-read
1115
+ * tool instead).
1116
+ */
1117
+ tool?: boolean;
1118
+ /**
1119
+ * Cap on concurrently active skills per run. Default `undefined` (unlimited).
1120
+ * Attempts to activate past the cap throw from `skills_use`.
1121
+ */
1122
+ maxActive?: number;
1123
+ /** Script timeout for `skills_run_script`, in milliseconds. Default `60000`. */
1124
+ scriptTimeoutMs?: number;
1125
+ /**
1126
+ * When `false`, skills with `source: 'project'` are skipped during
1127
+ * resolution with a diagnostic. Default `true` (preserves existing behavior).
1128
+ * Useful for host SDKs handling untrusted repositories.
1129
+ */
1130
+ trustProjectSkills?: boolean;
1131
+ }
1132
+
1133
+ /**
1134
+ * Runtime context passed to every tool execution.
1135
+ * Provides access to the agent's provider, abort signal, execution environment, and hooks.
1136
+ *
1137
+ * The preset-y fields (`name`, `system`, `tools`, `toolAliases`, `mcpServers`, `skills`,
1138
+ * `behavior`) mirror the agent's own options so child-spawning tools can inherit them.
1139
+ */
1140
+ interface ToolContext {
1141
+ /** The LLM provider for this agent run */
1142
+ provider: Provider;
1143
+ /** Abort signal — tools should check this for early termination */
1144
+ signal: AbortSignal;
1145
+ /** The execution context (shell, filesystem, etc.) */
1146
+ execution: ExecutionContext;
1147
+ /** The active execution handle for the current agent run */
1148
+ handle: ExecutionHandle;
1149
+ /** Agent hooks for emitting events (e.g. spawn:complete) */
1150
+ hooks: Hookable<AgentHooks>;
1151
+ /** Agent display name (preset or user-supplied) */
1152
+ name?: string;
1153
+ /** Agent default system prompt */
1154
+ system?: string;
1155
+ /** Source tool map the agent was created with (pre-MCP-merge, pre-skills-injection) */
1156
+ tools: Record<string, ToolDef>;
1157
+ /**
1158
+ * Map canonical tool names to LLM-facing (aliased) names.
1159
+ *
1160
+ * Aliasing is **LLM-boundary-only**:
1161
+ * - The alias is what the provider's tool spec carries, what the model calls it, and
1162
+ * what appears in `ToolHookContext.displayName` / `McpToolHookContext.displayName`.
1163
+ * - The canonical name is what lives in `session.turns`, `ToolHookContext.name`, and
1164
+ * what the agent uses to look up the tool implementation. Alias changes never
1165
+ * desync persisted history.
1166
+ */
1167
+ toolAliases?: Record<string, string>;
1168
+ /** MCP servers configured on the agent (for child inheritance) */
1169
+ mcpServers?: McpServerConfig[];
1170
+ /** Skills configuration (for child inheritance) */
1171
+ skills?: SkillsConfig;
1172
+ /** Behavior defaults (for child inheritance) */
1173
+ behavior?: AgentBehavior;
1174
+ /** Turn ID that requested this tool call */
1175
+ turnId: string;
1176
+ /** Tool call ID from the model */
1177
+ callId: string;
1178
+ /**
1179
+ * The run id this tool call is part of. Populated by the agent loop when
1180
+ * invoking tools. Optional on the type so host code constructing contexts
1181
+ * by hand (tests, direct tool invocations) doesn't have to synthesize one.
1182
+ *
1183
+ * Spawn-style tools rely on this to tag child runs with `parentRunId` so
1184
+ * the subagent tree can be reconstructed from a persisted session.
1185
+ */
1186
+ runId?: string;
1187
+ /**
1188
+ * The agent's session, when one was provided to `createAgent`. Tools that
1189
+ * want to persist their own state (or, in the case of `spawn`, inherit the
1190
+ * parent's session for child persistence) can read from here.
1191
+ */
1192
+ session?: Session;
1193
+ /**
1194
+ * Subagent depth for the agent owning this tool call. 0 = top-level,
1195
+ * 1 = first-level child, … Used by spawn to enforce a `maxDepth` cap.
1196
+ * Undefined is treated as 0 by spawn.
1197
+ */
1198
+ depth?: number;
1199
+ }
1200
+ interface ToolDef {
1201
+ spec: ToolSpec;
1202
+ /**
1203
+ * Execute the tool and return its output.
1204
+ *
1205
+ * Return a plain string for text-only tools (the common case). Return a
1206
+ * `ToolResultContent[]` when the tool produces non-text content (images, mixed
1207
+ * text+image) that the provider can route through natively (Anthropic
1208
+ * `tool_result.content` arrays, OpenAI Codex pi-ai) or through the
1209
+ * companion-user-message fallback (OpenAI Chat Completions).
1210
+ */
1211
+ execute: (input: Record<string, unknown>, ctx: ToolContext) => Promise<string | ToolResultContent[]>;
1212
+ }
1213
+ type ToolMap = Map<string, ToolDef>;
1214
+
1215
+ /**
1216
+ * MCP (Model Context Protocol) server support.
1217
+ *
1218
+ * Connects to one or more MCP servers, discovers their tools,
1219
+ * and wraps them as zidane ToolDefs for use in agent loops.
1220
+ */
1221
+
1222
+ interface McpConnection {
1223
+ tools: Record<string, ToolDef>;
1224
+ close: () => Promise<void>;
1225
+ }
1226
+ /**
1227
+ * Normalize MCP server configs from any common shape to `McpServerConfig[]`.
1228
+ *
1229
+ * Accepts:
1230
+ * - `McpServerConfig[]` — zidane native (pass-through).
1231
+ * - `McpServerConfig` — a single config object (wrapped to a 1-element array).
1232
+ * - `Record<string, RawShape>` — name-keyed map (common in host-SDK configs), where the key is the server name.
1233
+ * - Mixed shapes with `type` vs `transport`, `httpUrl`/`sseUrl` vs `url`.
1234
+ *
1235
+ * Returns `[]` when `input` is nullish. Throws a descriptive error when the transport
1236
+ * cannot be inferred from a given entry, or when the input shape is unsupported.
1237
+ */
1238
+ declare function normalizeMcpServers(input: unknown): McpServerConfig[];
1239
+ /**
1240
+ * Lossy flattener — converts MCP `CallToolResult.content` blocks to a single string.
1241
+ * Text blocks are extracted; non-text blocks are JSON-stringified.
1242
+ *
1243
+ * Prefer {@link normalizeMcpBlocks} for new code — it preserves image blocks so the
1244
+ * provider can route them through to the model natively (Anthropic tool_result blocks,
1245
+ * OpenAI companion-user-message). This function is kept for back-compat and is useful
1246
+ * as a logging/display helper where a single string is required.
1247
+ */
1248
+ declare function resultToString(content: unknown[]): string;
1249
+ /**
1250
+ * Normalize MCP `CallToolResult.content` to zidane's {@link ToolResultContent[]} shape.
1251
+ *
1252
+ * Handles the four MCP content block types:
1253
+ * - `text` → preserved as `{type:'text', text}`
1254
+ * - `image` → preserved as `{type:'image', mediaType, data}` (MCP uses `mimeType`)
1255
+ * - `resource` with embedded text → flattened to a text block
1256
+ * - `resource` with embedded blob whose `mimeType` is `image/*` → flattened to an image block
1257
+ * - Any unrecognized block → JSON-stringified fallback text block (lossy but safe)
1258
+ *
1259
+ * Returns `null` when the input is not an array — callers should fall back to an empty
1260
+ * result in that case.
1261
+ */
1262
+ declare function normalizeMcpBlocks(content: unknown): ToolResultContent[] | null;
1263
+ /**
1264
+ * Connect to MCP servers and discover their tools.
1265
+ *
1266
+ * Each tool is namespaced as `mcp_{serverName}_{toolName}` to avoid
1267
+ * collisions with agent tools or tools from other servers.
1268
+ *
1269
+ * @param configs - Array of MCP server configurations
1270
+ * @param _clientFactory - Internal: override client construction for testing
1271
+ * @param hooks - Optional agent hooks for firing mcp:connect, mcp:error, mcp:close events
1272
+ */
1273
+ declare function connectMcpServers(configs: McpServerConfig[], _clientFactory?: () => Client, hooks?: Hookable<AgentHooks>): Promise<McpConnection>;
1274
+
1219
1275
  /**
1220
1276
  * Per-agent skill activation state machine.
1221
1277
  *
@@ -1341,6 +1397,45 @@ interface AgentHooks {
1341
1397
  'spawn:error': (ctx: SpawnHookContext & {
1342
1398
  error: Error;
1343
1399
  }) => void;
1400
+ 'child:stream:text': (ctx: StreamHookContext & {
1401
+ delta: string;
1402
+ text: string;
1403
+ childId: string;
1404
+ depth: number;
1405
+ }) => void;
1406
+ 'child:stream:thinking': (ctx: StreamHookContext & {
1407
+ delta: string;
1408
+ thinking: string;
1409
+ childId: string;
1410
+ depth: number;
1411
+ }) => void;
1412
+ 'child:stream:end': (ctx: StreamHookContext & {
1413
+ text: string;
1414
+ childId: string;
1415
+ depth: number;
1416
+ }) => void;
1417
+ 'child:tool:before': (ctx: ToolHookContext & {
1418
+ childId: string;
1419
+ depth: number;
1420
+ }) => void;
1421
+ 'child:tool:after': (ctx: ToolHookContext & {
1422
+ result: string | ToolResultContent[];
1423
+ childId: string;
1424
+ depth: number;
1425
+ }) => void;
1426
+ 'child:tool:error': (ctx: ToolHookContext & {
1427
+ error: Error;
1428
+ childId: string;
1429
+ depth: number;
1430
+ }) => void;
1431
+ 'child:turn:after': (ctx: {
1432
+ turn: number;
1433
+ turnId: string;
1434
+ usage: TurnUsage;
1435
+ message: SessionTurn;
1436
+ childId: string;
1437
+ depth: number;
1438
+ }) => void;
1344
1439
  'mcp:connect': (ctx: {
1345
1440
  name: string;
1346
1441
  transport: string;
@@ -1415,9 +1510,21 @@ interface AgentHooks {
1415
1510
  'session:save': (ctx: SessionHookContext) => void;
1416
1511
  }
1417
1512
  interface AgentOptions {
1418
- /** Harness (tools + system prompt). Defaults to a no-tools harness if omitted. */
1419
- harness?: HarnessConfig;
1420
1513
  provider: Provider;
1514
+ /** Display name for the agent (used in traces/logs). */
1515
+ name?: string;
1516
+ /** Default system prompt injected when no system is provided at run time. */
1517
+ system?: string;
1518
+ /** Tool definitions available to the agent. Defaults to no tools. */
1519
+ tools?: Record<string, ToolDef>;
1520
+ /**
1521
+ * Map canonical tool names to LLM-facing (aliased) names.
1522
+ *
1523
+ * Aliasing is **LLM-boundary-only**: the alias is what the provider's tool spec
1524
+ * carries and what the model calls the tool; the canonical name is what lives in
1525
+ * `session.turns` and what the agent uses to look up the tool implementation.
1526
+ */
1527
+ toolAliases?: Record<string, string>;
1421
1528
  /** Agent-level behavior defaults (overridden by run-level behavior) */
1422
1529
  behavior?: AgentBehavior;
1423
1530
  /** Execution context: where tools run. Defaults to in-process. */
@@ -1426,7 +1533,7 @@ interface AgentOptions {
1426
1533
  mcpServers?: McpServerConfig[];
1427
1534
  /** Session for identity, turn persistence, and run tracking */
1428
1535
  session?: Session;
1429
- /** Skills configuration (merged with harness-level skills, agent takes precedence) */
1536
+ /** Skills configuration */
1430
1537
  skills?: SkillsConfig;
1431
1538
  /** @internal */
1432
1539
  _mcpConnector?: (configs: McpServerConfig[]) => Promise<McpConnection>;
@@ -1438,8 +1545,16 @@ interface Agent {
1438
1545
  steer: (message: string) => void;
1439
1546
  followUp: (message: string) => void;
1440
1547
  waitForIdle: () => Promise<void>;
1441
- reset: () => void;
1442
- /** Destroy the execution context and clean up resources */
1548
+ /**
1549
+ * Clear the agent's in-memory state (turns, queues, skill activations).
1550
+ * Fires `skills:deactivate` with `reason: 'reset'` for each previously active
1551
+ * skill. Awaiting lets host apps observe listener rejections.
1552
+ */
1553
+ reset: () => Promise<void>;
1554
+ /**
1555
+ * Destroy the execution context and clean up resources.
1556
+ * Idempotent — safe to call from both a `finally` block and a signal handler.
1557
+ */
1443
1558
  destroy: () => Promise<void>;
1444
1559
  /**
1445
1560
  * Explicitly activate a skill by name. Fires `skills:activate` with
@@ -1462,6 +1577,6 @@ interface Agent {
1462
1577
  readonly activeSkills: readonly ActiveSkill[];
1463
1578
  meta: Record<string, unknown>;
1464
1579
  }
1465
- declare function createAgent({ harness: harnessOption, provider, behavior: agentBehavior, execution, mcpServers, session, skills: agentSkills, _mcpConnector }: AgentOptions): Agent;
1580
+ declare function createAgent({ provider, name: agentName, system: agentSystem, tools: agentTools, toolAliases, behavior: agentBehavior, execution, mcpServers, session, skills: agentSkills, _mcpConnector }: AgentOptions): Agent;
1466
1581
 
1467
- export { type ToolDef as $, type Agent as A, type SessionContentBlock as B, CONTEXT_EXCEEDED_MESSAGE_PATTERNS as C, type SessionData as D, type SessionEndStatus as E, type SessionHookContext as F, type SessionMessage as G, type Harness as H, type ImageContent as I, type SessionRun as J, type SessionStore as K, type SessionTurn as L, type McpConnection as M, type SkillConfig as N, type OAuthRefreshHookContext as O, type PromptDocumentPart as P, type SkillResource as Q, type RemoteStoreOptions as R, type Session as S, type SkillsConfig as T, type SpawnHookContext as U, type StreamCallbacks as V, type StreamHookContext as W, type StreamOptions as X, type ThinkingLevel as Y, type ToolCall as Z, type ToolContext as _, AgentAbortedError as a, type ToolExecutionMode as a0, type ToolHookContext as a1, type ToolMap as a2, type ToolResult as a3, type ToolResultContent as a4, type ToolResultImageContent as a5, type ToolResultTextContent as a6, type ToolSpec as a7, type TurnFinishReason as a8, type TurnResult as a9, defineHarness as aA, fromAnthropic as aB, fromOpenAI as aC, loadSession as aD, mapOAIFinishReason as aE, noTools as aF, normalizeMcpBlocks as aG, normalizeMcpServers as aH, openai as aI, openaiCompat as aJ, openrouter as aK, resultToString as aL, toAnthropic as aM, toOpenAI as aN, toTypedError as aO, _default as aP, basicTools as aQ, type TurnUsage as aa, matchesContextExceeded as ab, toolResultToText as ac, type ActivationVia as ad, type ActiveSkill as ae, type DeactivationReason as af, type FileMapAdapter as ag, type FileMapStoreOptions as ah, type OpenAICompatAuthHeader as ai, OpenAICompatHttpError as aj, type OpenAICompatParams as ak, type SkillActivationState as al, type SkillActivationStateOptions as am, type SkillDiagnostic as an, type SkillSource as ao, anthropic as ap, autoDetectAndConvert as aq, cerebras as ar, classifyOpenAICompatError as as, connectMcpServers as at, createAgent as au, createFileMapStore as av, createMemoryStore as aw, createRemoteStore as ax, createSession as ay, createSkillActivationState as az, type AgentBehavior as b, AgentContextExceededError as c, type AgentHooks as d, type AgentOptions as e, AgentProviderError as f, type AgentRunOptions as g, type AgentStats as h, AgentToolNotAllowedError as i, type AnthropicParams as j, type CerebrasParams as k, type ChildRunStats as l, type ClassifiedError as m, type ClassifiedErrorKind as n, type CreateSessionOptions as o, type HarnessConfig as p, type McpServerConfig as q, type McpToolHookContext as r, type OpenAIParams as s, type OpenRouterParams as t, type PromptImagePart as u, type PromptPart as v, type PromptTextPart as w, type Provider as x, type ProviderCapabilities as y, type RunHookMap as z };
1582
+ export { type ToolHookContext as $, type Agent as A, type SessionData as B, CONTEXT_EXCEEDED_MESSAGE_PATTERNS as C, type SessionEndStatus as D, type SessionHookContext as E, type SessionMessage as F, type SessionRun as G, type SessionStore as H, type ImageContent as I, type SessionTurn as J, type SkillConfig as K, type SkillResource as L, type McpConnection as M, type SkillsConfig as N, type OAuthRefreshHookContext as O, type PromptDocumentPart as P, type SpawnHookContext as Q, type RemoteStoreOptions as R, type Session as S, type StreamCallbacks as T, type StreamHookContext as U, type StreamOptions as V, type ThinkingLevel as W, type ToolCall as X, type ToolContext as Y, type ToolDef as Z, type ToolExecutionMode as _, AgentAbortedError as a, type ToolMap as a0, type ToolResult as a1, type ToolResultContent as a2, type ToolResultImageContent as a3, type ToolResultTextContent as a4, type ToolSpec as a5, type TurnFinishReason as a6, type TurnResult as a7, type TurnUsage as a8, matchesContextExceeded as a9, loadSession as aA, mapOAIFinishReason as aB, normalizeMcpBlocks as aC, normalizeMcpServers as aD, openai as aE, openaiCompat as aF, openrouter as aG, resultToString as aH, toAnthropic as aI, toOpenAI as aJ, toTypedError as aK, toolResultToText as aa, type ActivationVia as ab, type ActiveSkill as ac, type DeactivationReason as ad, type FileMapAdapter as ae, type FileMapStoreOptions as af, type OpenAICompatAuthHeader as ag, OpenAICompatHttpError as ah, type OpenAICompatParams as ai, type SkillActivationState as aj, type SkillActivationStateOptions as ak, type SkillDiagnostic as al, type SkillSource as am, anthropic as an, autoDetectAndConvert as ao, cerebras as ap, classifyOpenAICompatError as aq, connectMcpServers as ar, createAgent as as, createFileMapStore as at, createMemoryStore as au, createRemoteStore as av, createSession as aw, createSkillActivationState as ax, fromAnthropic as ay, fromOpenAI as az, type AgentBehavior as b, AgentContextExceededError as c, type AgentHooks as d, type AgentOptions as e, AgentProviderError as f, type AgentRunOptions as g, type AgentStats as h, AgentToolNotAllowedError as i, type AnthropicParams as j, type CerebrasParams as k, type ChildRunStats as l, type ClassifiedError as m, type ClassifiedErrorKind as n, type CreateSessionOptions as o, type McpServerConfig as p, type McpToolHookContext as q, type OpenAIParams as r, type OpenRouterParams as s, type PromptImagePart as t, type PromptPart as u, type PromptTextPart as v, type Provider as w, type ProviderCapabilities as x, type RunHookMap as y, type SessionContentBlock as z };