zidane 5.1.22 → 5.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.
@@ -1,4 +1,4 @@
1
- import { a as multiEdit, i as readFile, n as createSpawnTool, o as listFiles, r as shell, t as writeFile, u as edit } from "./tools-CMVruxF0.js";
1
+ import { a as multiEdit, i as readFile, n as createSpawnTool, o as listFiles, r as shell, t as writeFile, u as edit } from "./tools-BRbbfdJh.js";
2
2
  //#region src/presets/basic.ts
3
3
  /**
4
4
  * Core tools available in every basic preset (without spawn).
@@ -38,10 +38,11 @@ function definePreset(config) {
38
38
  * objects shallow-merge; arrays and hook handler lists concatenate. Designed so
39
39
  * stacking presets does the obvious thing without the spread-collision footgun:
40
40
  *
41
- * - `name`, `system`, `eager`, `skills` → last-defined wins
42
- * - `tools`, `toolAliases`, `behavior` → shallow-merge (later keys override)
43
- * - `mcpServers` concat with last-wins on `name` collision
44
- * - `hooks` per-event concat; every handler fires
41
+ * - `name`, `system`, `eager`, `skills` → last-defined wins
42
+ * - `tools`, `toolAliases`, `behavior` → shallow-merge (later keys override)
43
+ * - `behavior.dedupTools`, `behavior.toolBudgets` **deep-merge** (per-tool-name; later wins on collision)
44
+ * - `mcpServers` concat with last-wins on `name` collision
45
+ * - `hooks` → per-event concat; every handler fires
45
46
  *
46
47
  * `hooks` always emerges as `event → handler[]` so downstream registration
47
48
  * (in `createAgent`) sees a uniform shape. Order of handlers within an event
@@ -50,6 +51,13 @@ function definePreset(config) {
50
51
  * `mcpServers` is deduped by `name` because shipping two servers with the same
51
52
  * name would trip the connector at runtime — a later preset overriding an
52
53
  * earlier preset's `github` server is the practical intent.
54
+ *
55
+ * `behavior.dedupTools` and `behavior.toolBudgets` get the same per-key deep-merge
56
+ * because they are tool-name-keyed records — a preset that ships a dedup hasher
57
+ * for one tool should not erase a hasher another preset ships for a different
58
+ * tool. Last-wins still applies on a per-tool collision so a downstream preset
59
+ * can override an upstream preset's policy for one specific tool. Other
60
+ * `behavior` fields keep last-wins semantics.
53
61
  */
54
62
  function composePresets(...presets) {
55
63
  const out = {};
@@ -68,10 +76,21 @@ function composePresets(...presets) {
68
76
  ...out.toolAliases,
69
77
  ...p.toolAliases
70
78
  };
71
- if (p.behavior) out.behavior = {
72
- ...out.behavior,
73
- ...p.behavior
74
- };
79
+ if (p.behavior) {
80
+ const merged = {
81
+ ...out.behavior,
82
+ ...p.behavior
83
+ };
84
+ if (out.behavior?.dedupTools || p.behavior.dedupTools) merged.dedupTools = {
85
+ ...out.behavior?.dedupTools,
86
+ ...p.behavior.dedupTools
87
+ };
88
+ if (out.behavior?.toolBudgets || p.behavior.toolBudgets) merged.toolBudgets = {
89
+ ...out.behavior?.toolBudgets,
90
+ ...p.behavior.toolBudgets
91
+ };
92
+ out.behavior = merged;
93
+ }
75
94
  if (p.mcpServers) for (const server of p.mcpServers) mcpByName.set(server.name, server);
76
95
  if (p.hooks) for (const [event, handler] of Object.entries(p.hooks)) {
77
96
  if (handler === void 0) continue;
@@ -87,4 +106,4 @@ function composePresets(...presets) {
87
106
  //#endregion
88
107
  export { basic_default as i, definePreset as n, basicTools as r, composePresets as t };
89
108
 
90
- //# sourceMappingURL=presets-tvD28pCu.js.map
109
+ //# sourceMappingURL=presets-AgF0RFx1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presets-AgF0RFx1.js","names":[],"sources":["../src/presets/basic.ts","../src/presets/index.ts"],"sourcesContent":["import { definePreset } from '.'\nimport { edit, listFiles, multiEdit, readFile, shell, writeFile } from '../tools'\nimport { createSpawnTool } from '../tools/spawn'\n\n/**\n * Core tools available in every basic preset (without spawn).\n *\n * `edit` and `multi_edit` ship in the basic set because surgical edits are the\n * default modality for production agents — `write_file` is for full overwrites.\n * `glob` and `grep` are exported but opt-in: not every agent needs codebase\n * search, and shipping them by default would force `tool:gate` work onto\n * consumers that prefer the model to use `shell` + classic Unix tools.\n */\nexport const basicTools = { shell, readFile, writeFile, listFiles, edit, multiEdit }\n\nexport default definePreset({\n name: 'basic',\n system: 'You are a helpful assistant with access to shell, file reading, file writing, surgical and multi-edit tools, directory listing, and sub-agent spawning. Prefer `edit` / `multi_edit` for in-place changes and `write_file` for full file overwrites. Use them to accomplish tasks in the project directory.',\n // `persist: true` shares the parent's session with every child agent — child\n // turns land in `session.turns` tagged with their own `runId`, and the run\n // itself is recorded in `session.runs` with `parentRunId` + `depth`. That's\n // what lets a reloaded TUI session reconstruct the full subagent tree (see\n // `eventsFromTurns` in `tui/store.ts`). Hosts that want children in-memory\n // only can construct their own preset with `createSpawnTool()`.\n tools: { ...basicTools, spawn: createSpawnTool({ persist: true }) },\n})\n","import type { AgentHooks, AgentOptions } from '../agent'\n\nexport type { AgentHookMap } from '../agent'\n\n/**\n * A preset is a reusable slice of `AgentOptions` — spread it into `createAgent()`\n * to configure tools, a default system prompt, aliases, behavior defaults, and\n * agent-lifetime hooks.\n *\n * `provider`, `execution`, `session`, and internal fields are excluded so presets\n * remain shareable and composable.\n *\n * ```ts\n * import { basic } from 'zidane/presets'\n * createAgent({ ...basic, provider })\n * ```\n *\n * ### Composing multiple presets\n *\n * Bare `...spread` is shallow — `{ ...a, ...b }` overwrites every key `b`\n * defines, including `hooks`. Use {@link composePresets} when you want\n * field-aware merging (per-event hook concat, tools shallow-merge, etc.):\n *\n * ```ts\n * createAgent({ ...composePresets(basic, telemetry, mine), provider })\n * ```\n */\nexport type Preset = Omit<Partial<AgentOptions>, 'provider' | 'execution' | 'session' | 'mcpConnector'>\n\n/**\n * Identity helper for type inference when defining a preset.\n */\nexport function definePreset(config: Preset): Preset {\n return config\n}\n\n/**\n * Field-aware composition of presets. Right-most preset wins for scalar fields;\n * objects shallow-merge; arrays and hook handler lists concatenate. Designed so\n * stacking presets does the obvious thing without the spread-collision footgun:\n *\n * - `name`, `system`, `eager`, `skills` → last-defined wins\n * - `tools`, `toolAliases`, `behavior` → shallow-merge (later keys override)\n * - `behavior.dedupTools`, `behavior.toolBudgets` → **deep-merge** (per-tool-name; later wins on collision)\n * - `mcpServers` → concat with last-wins on `name` collision\n * - `hooks` → per-event concat; every handler fires\n *\n * `hooks` always emerges as `event → handler[]` so downstream registration\n * (in `createAgent`) sees a uniform shape. Order of handlers within an event\n * follows preset order: earlier presets register first.\n *\n * `mcpServers` is deduped by `name` because shipping two servers with the same\n * name would trip the connector at runtime — a later preset overriding an\n * earlier preset's `github` server is the practical intent.\n *\n * `behavior.dedupTools` and `behavior.toolBudgets` get the same per-key deep-merge\n * because they are tool-name-keyed records — a preset that ships a dedup hasher\n * for one tool should not erase a hasher another preset ships for a different\n * tool. Last-wins still applies on a per-tool collision so a downstream preset\n * can override an upstream preset's policy for one specific tool. Other\n * `behavior` fields keep last-wins semantics.\n */\nexport function composePresets(...presets: Preset[]): Preset {\n const out: Preset = {}\n const hooksByEvent: { [K in keyof AgentHooks]?: AgentHooks[K][] } = {}\n // Keep mcpServers in source-order on first sight, but allow later\n // declarations to override earlier ones with the same `name`. A `Map`\n // keyed by name gives O(1) override + stable iteration.\n const mcpByName = new Map<string, NonNullable<Preset['mcpServers']>[number]>()\n\n for (const p of presets) {\n if (p.name !== undefined)\n out.name = p.name\n if (p.system !== undefined)\n out.system = p.system\n if (p.eager !== undefined)\n out.eager = p.eager\n if (p.skills !== undefined)\n out.skills = p.skills\n if (p.tools)\n out.tools = { ...out.tools, ...p.tools }\n if (p.toolAliases)\n out.toolAliases = { ...out.toolAliases, ...p.toolAliases }\n if (p.behavior) {\n // Top-level shallow-merge first; then deep-merge the two tool-name-keyed\n // sub-records so per-tool entries from earlier presets aren't clobbered.\n const merged: NonNullable<Preset['behavior']> = { ...out.behavior, ...p.behavior }\n if (out.behavior?.dedupTools || p.behavior.dedupTools) {\n merged.dedupTools = { ...out.behavior?.dedupTools, ...p.behavior.dedupTools }\n }\n if (out.behavior?.toolBudgets || p.behavior.toolBudgets) {\n merged.toolBudgets = { ...out.behavior?.toolBudgets, ...p.behavior.toolBudgets }\n }\n out.behavior = merged\n }\n if (p.mcpServers) {\n for (const server of p.mcpServers)\n mcpByName.set(server.name, server)\n }\n if (p.hooks) {\n for (const [event, handler] of Object.entries(p.hooks)) {\n if (handler === undefined)\n continue\n const list = Array.isArray(handler) ? handler : [handler]\n const key = event as keyof AgentHooks\n // Safe cast: we read the loose `AgentHookMap` shape (handler-or-array)\n // and re-emit only as arrays. Each `list` element matches the event's\n // handler signature by construction (the input was typed `AgentHookMap`).\n const bucket = (hooksByEvent[key] ??= []) as unknown[]\n bucket.push(...(list as unknown[]))\n }\n }\n }\n\n if (mcpByName.size > 0)\n out.mcpServers = [...mcpByName.values()]\n\n if (Object.keys(hooksByEvent).length > 0)\n out.hooks = hooksByEvent\n\n return out\n}\n\nexport { default as basic, basicTools } from './basic'\n"],"mappings":";;;;;;;;;;;AAaA,MAAa,aAAa;CAAE;CAAO;CAAU;CAAW;CAAW;CAAM;CAAW;AAEpF,IAAA,gBAAe,aAAa;CAC1B,MAAM;CACN,QAAQ;CAOR,OAAO;EAAE,GAAG;EAAY,OAAO,gBAAgB,EAAE,SAAS,MAAM,CAAC;EAAE;CACpE,CAAC;;;;;;ACOF,SAAgB,aAAa,QAAwB;CACnD,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BT,SAAgB,eAAe,GAAG,SAA2B;CAC3D,MAAM,MAAc,EAAE;CACtB,MAAM,eAA8D,EAAE;CAItE,MAAM,4BAAY,IAAI,KAAwD;CAE9E,KAAK,MAAM,KAAK,SAAS;EACvB,IAAI,EAAE,SAAS,KAAA,GACb,IAAI,OAAO,EAAE;EACf,IAAI,EAAE,WAAW,KAAA,GACf,IAAI,SAAS,EAAE;EACjB,IAAI,EAAE,UAAU,KAAA,GACd,IAAI,QAAQ,EAAE;EAChB,IAAI,EAAE,WAAW,KAAA,GACf,IAAI,SAAS,EAAE;EACjB,IAAI,EAAE,OACJ,IAAI,QAAQ;GAAE,GAAG,IAAI;GAAO,GAAG,EAAE;GAAO;EAC1C,IAAI,EAAE,aACJ,IAAI,cAAc;GAAE,GAAG,IAAI;GAAa,GAAG,EAAE;GAAa;EAC5D,IAAI,EAAE,UAAU;GAGd,MAAM,SAA0C;IAAE,GAAG,IAAI;IAAU,GAAG,EAAE;IAAU;GAClF,IAAI,IAAI,UAAU,cAAc,EAAE,SAAS,YACzC,OAAO,aAAa;IAAE,GAAG,IAAI,UAAU;IAAY,GAAG,EAAE,SAAS;IAAY;GAE/E,IAAI,IAAI,UAAU,eAAe,EAAE,SAAS,aAC1C,OAAO,cAAc;IAAE,GAAG,IAAI,UAAU;IAAa,GAAG,EAAE,SAAS;IAAa;GAElF,IAAI,WAAW;;EAEjB,IAAI,EAAE,YACJ,KAAK,MAAM,UAAU,EAAE,YACrB,UAAU,IAAI,OAAO,MAAM,OAAO;EAEtC,IAAI,EAAE,OACJ,KAAK,MAAM,CAAC,OAAO,YAAY,OAAO,QAAQ,EAAE,MAAM,EAAE;GACtD,IAAI,YAAY,KAAA,GACd;GACF,MAAM,OAAO,MAAM,QAAQ,QAAQ,GAAG,UAAU,CAAC,QAAQ;GACzD,MAAM,MAAM;GAKZ,CADgB,aAAa,SAAS,EAAE,EACjC,KAAK,GAAI,KAAmB;;;CAKzC,IAAI,UAAU,OAAO,GACnB,IAAI,aAAa,CAAC,GAAG,UAAU,QAAQ,CAAC;CAE1C,IAAI,OAAO,KAAK,aAAa,CAAC,SAAS,GACrC,IAAI,QAAQ;CAEd,OAAO"}
package/dist/presets.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { n as AgentHookMap } from "./agent-CYpPKn5Z.js";
2
- import { a as basicTools, i as _default, n as composePresets, r as definePreset, t as Preset } from "./index-D-cTScN3.js";
2
+ import { a as basicTools, i as _default, n as composePresets, r as definePreset, t as Preset } from "./index-BRTRan3z.js";
3
3
  export { AgentHookMap, Preset, _default as basic, basicTools, composePresets, definePreset };
package/dist/presets.js CHANGED
@@ -1,2 +1,2 @@
1
- import { i as basic_default, n as definePreset, r as basicTools, t as composePresets } from "./presets-tvD28pCu.js";
1
+ import { i as basic_default, n as definePreset, r as basicTools, t as composePresets } from "./presets-AgF0RFx1.js";
2
2
  export { basic_default as basic, basicTools, composePresets, definePreset };
@@ -480,6 +480,7 @@ function validateToolArgs(input, schema) {
480
480
  };
481
481
  let coerced;
482
482
  const coercions = [];
483
+ let droppedItems;
483
484
  for (const [key, value] of Object.entries(input)) {
484
485
  const propSchema = properties[key];
485
486
  if (!propSchema?.type) continue;
@@ -494,11 +495,138 @@ function validateToolArgs(input, schema) {
494
495
  coerced[key] = outcome.value;
495
496
  coercions.push(key);
496
497
  }
498
+ const arrayValue = outcome.changed ? outcome.value : value;
499
+ if (propSchema.type === "array" && propSchema.items && Array.isArray(arrayValue)) {
500
+ const itemOutcome = validateArrayItems(arrayValue, propSchema);
501
+ if (itemOutcome.error) return {
502
+ valid: false,
503
+ error: `Field "${key}": ${itemOutcome.error}`
504
+ };
505
+ if (itemOutcome.changed || itemOutcome.dropped.length > 0 || itemOutcome.truncated) {
506
+ if (!coerced) coerced = { ...input };
507
+ coerced[key] = itemOutcome.items;
508
+ if (!coercions.includes(key)) coercions.push(key);
509
+ }
510
+ if (itemOutcome.dropped.length > 0) {
511
+ if (!droppedItems) droppedItems = {};
512
+ droppedItems[key] = itemOutcome.dropped;
513
+ }
514
+ }
497
515
  }
498
516
  return {
499
517
  valid: true,
500
518
  coercedInput: coerced ?? input,
501
- coercions
519
+ coercions,
520
+ ...droppedItems ? { droppedItems } : {}
521
+ };
522
+ }
523
+ function validateArrayItems(items, schema) {
524
+ if (schema.minItems !== void 0 && items.length < schema.minItems) return {
525
+ items,
526
+ changed: false,
527
+ truncated: false,
528
+ dropped: [],
529
+ error: `expected at least ${schema.minItems} item${schema.minItems === 1 ? "" : "s"}, got ${items.length}`
530
+ };
531
+ const itemSchema = schema.items;
532
+ if (!itemSchema) return {
533
+ items,
534
+ changed: false,
535
+ truncated: false,
536
+ dropped: []
537
+ };
538
+ const out = [];
539
+ const outOriginalIdx = [];
540
+ const dropped = [];
541
+ let changed = false;
542
+ for (let i = 0; i < items.length; i++) {
543
+ const item = items[i];
544
+ const v = validateOneItem(item, itemSchema);
545
+ if (v.dropped) {
546
+ dropped.push(i);
547
+ changed = true;
548
+ continue;
549
+ }
550
+ if (v.changed) changed = true;
551
+ out.push(v.value);
552
+ outOriginalIdx.push(i);
553
+ }
554
+ let truncated = false;
555
+ if (schema.maxItems !== void 0 && out.length > schema.maxItems) {
556
+ for (let i = schema.maxItems; i < out.length; i++) dropped.push(outOriginalIdx[i]);
557
+ out.length = schema.maxItems;
558
+ truncated = true;
559
+ changed = true;
560
+ }
561
+ dropped.sort((a, b) => a - b);
562
+ return {
563
+ items: out,
564
+ changed,
565
+ truncated,
566
+ dropped
567
+ };
568
+ }
569
+ function validateOneItem(item, schema) {
570
+ if (schema.type === "object") {
571
+ if (!item || typeof item !== "object" || Array.isArray(item)) return {
572
+ value: item,
573
+ changed: false,
574
+ dropped: true
575
+ };
576
+ const obj = item;
577
+ const required = schema.required ?? [];
578
+ for (const field of required) {
579
+ const v = obj[field];
580
+ if (v === void 0 || v === null) return {
581
+ value: item,
582
+ changed: false,
583
+ dropped: true
584
+ };
585
+ }
586
+ const properties = schema.properties ?? {};
587
+ let coercedItem;
588
+ for (const [key, value] of Object.entries(obj)) {
589
+ const subSchema = properties[key];
590
+ if (!subSchema?.type) continue;
591
+ if (value === void 0 || value === null) continue;
592
+ const outcome = coerceValue(value, subSchema);
593
+ if (outcome.error) return {
594
+ value: item,
595
+ changed: false,
596
+ dropped: true
597
+ };
598
+ if (outcome.changed) {
599
+ if (!coercedItem) coercedItem = { ...obj };
600
+ coercedItem[key] = outcome.value;
601
+ }
602
+ }
603
+ return coercedItem ? {
604
+ value: coercedItem,
605
+ changed: true,
606
+ dropped: false
607
+ } : {
608
+ value: item,
609
+ changed: false,
610
+ dropped: false
611
+ };
612
+ }
613
+ if (schema.type) {
614
+ const outcome = coerceValue(item, schema);
615
+ if (outcome.error) return {
616
+ value: item,
617
+ changed: false,
618
+ dropped: true
619
+ };
620
+ return {
621
+ value: outcome.value,
622
+ changed: outcome.changed,
623
+ dropped: false
624
+ };
625
+ }
626
+ return {
627
+ value: item,
628
+ changed: false,
629
+ dropped: false
502
630
  };
503
631
  }
504
632
  function coerceValue(value, schema) {
@@ -4573,4 +4701,4 @@ const writeFile$1 = {
4573
4701
  //#endregion
4574
4702
  export { maybePersistToolResult as C, cleanupPersistedSession as S, getReadState as T, createSkillsReadTool as _, multiEdit as a, PERSISTENCE_PREVIEW_BYTES as b, grep as c, resolveOldString as d, styleReplacementForVia as f, createSkillsRunScriptTool as g, createSkillsUseTool as h, readFile$1 as i, glob as l, createToolSearchTool as m, createSpawnTool as n, listFiles as o, createAgent as p, shell as r, createInteractionTool as s, writeFile$1 as t, edit as u, validateToolArgs as v, resolvePersistDir as w, buildPersistedStub as x, PERSISTED_STUB_PREFIX as y };
4575
4703
 
4576
- //# sourceMappingURL=tools-CMVruxF0.js.map
4704
+ //# sourceMappingURL=tools-BRbbfdJh.js.map