@namzu/sdk 5.1.0 → 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.
Files changed (158) hide show
  1. package/CHANGELOG.md +361 -0
  2. package/dist/agents/__tests__/run-agent-forwarding.test.d.ts +2 -0
  3. package/dist/agents/__tests__/run-agent-forwarding.test.d.ts.map +1 -0
  4. package/dist/agents/__tests__/run-agent-forwarding.test.js +76 -0
  5. package/dist/agents/__tests__/run-agent-forwarding.test.js.map +1 -0
  6. package/dist/agents/__tests__/run-completed-stop-reason.test.d.ts +2 -0
  7. package/dist/agents/__tests__/run-completed-stop-reason.test.d.ts.map +1 -0
  8. package/dist/agents/__tests__/run-completed-stop-reason.test.js +50 -0
  9. package/dist/agents/__tests__/run-completed-stop-reason.test.js.map +1 -0
  10. package/dist/agents/index.d.ts +1 -0
  11. package/dist/agents/index.d.ts.map +1 -1
  12. package/dist/agents/index.js +4 -0
  13. package/dist/agents/index.js.map +1 -1
  14. package/dist/agents/runAgent.d.ts +34 -0
  15. package/dist/agents/runAgent.d.ts.map +1 -1
  16. package/dist/agents/runAgent.js +5 -3
  17. package/dist/agents/runAgent.js.map +1 -1
  18. package/dist/config/runtime.d.ts +30 -30
  19. package/dist/constants/tools/__tests__/dangerous-patterns.test.d.ts +2 -0
  20. package/dist/constants/tools/__tests__/dangerous-patterns.test.d.ts.map +1 -0
  21. package/dist/constants/tools/__tests__/dangerous-patterns.test.js +54 -0
  22. package/dist/constants/tools/__tests__/dangerous-patterns.test.js.map +1 -0
  23. package/dist/constants/tools/index.d.ts.map +1 -1
  24. package/dist/constants/tools/index.js +28 -1
  25. package/dist/constants/tools/index.js.map +1 -1
  26. package/dist/contracts/a2a.d.ts +44 -44
  27. package/dist/directory/__tests__/derive.test.d.ts +2 -0
  28. package/dist/directory/__tests__/derive.test.d.ts.map +1 -0
  29. package/dist/directory/__tests__/derive.test.js +111 -0
  30. package/dist/directory/__tests__/derive.test.js.map +1 -0
  31. package/dist/directory/__tests__/load-diagnostics.test.d.ts +2 -0
  32. package/dist/directory/__tests__/load-diagnostics.test.d.ts.map +1 -0
  33. package/dist/directory/__tests__/load-diagnostics.test.js +106 -0
  34. package/dist/directory/__tests__/load-diagnostics.test.js.map +1 -0
  35. package/dist/directory/__tests__/load-directory.test.d.ts +2 -0
  36. package/dist/directory/__tests__/load-directory.test.d.ts.map +1 -0
  37. package/dist/directory/__tests__/load-directory.test.js +196 -0
  38. package/dist/directory/__tests__/load-directory.test.js.map +1 -0
  39. package/dist/directory/__tests__/subagents.test.d.ts +2 -0
  40. package/dist/directory/__tests__/subagents.test.d.ts.map +1 -0
  41. package/dist/directory/__tests__/subagents.test.js +117 -0
  42. package/dist/directory/__tests__/subagents.test.js.map +1 -0
  43. package/dist/directory/__tests__/supervisor-budget.test.d.ts +2 -0
  44. package/dist/directory/__tests__/supervisor-budget.test.d.ts.map +1 -0
  45. package/dist/directory/__tests__/supervisor-budget.test.js +97 -0
  46. package/dist/directory/__tests__/supervisor-budget.test.js.map +1 -0
  47. package/dist/directory/derive-supervisor.d.ts +58 -0
  48. package/dist/directory/derive-supervisor.d.ts.map +1 -0
  49. package/dist/directory/derive-supervisor.js +88 -0
  50. package/dist/directory/derive-supervisor.js.map +1 -0
  51. package/dist/directory/derive.d.ts +12 -0
  52. package/dist/directory/derive.d.ts.map +1 -0
  53. package/dist/directory/derive.js +58 -0
  54. package/dist/directory/derive.js.map +1 -0
  55. package/dist/directory/index.d.ts +7 -0
  56. package/dist/directory/index.d.ts.map +1 -0
  57. package/dist/directory/index.js +5 -0
  58. package/dist/directory/index.js.map +1 -0
  59. package/dist/directory/load.d.ts +14 -0
  60. package/dist/directory/load.d.ts.map +1 -0
  61. package/dist/directory/load.js +488 -0
  62. package/dist/directory/load.js.map +1 -0
  63. package/dist/directory/scan.d.ts +36 -0
  64. package/dist/directory/scan.d.ts.map +1 -0
  65. package/dist/directory/scan.js +136 -0
  66. package/dist/directory/scan.js.map +1 -0
  67. package/dist/directory/types.d.ts +215 -0
  68. package/dist/directory/types.d.ts.map +1 -0
  69. package/dist/directory/types.js +8 -0
  70. package/dist/directory/types.js.map +1 -0
  71. package/dist/plugin/__tests__/path-containment.test.d.ts +2 -0
  72. package/dist/plugin/__tests__/path-containment.test.d.ts.map +1 -0
  73. package/dist/plugin/__tests__/path-containment.test.js +91 -0
  74. package/dist/plugin/__tests__/path-containment.test.js.map +1 -0
  75. package/dist/plugin/lifecycle.d.ts.map +1 -1
  76. package/dist/plugin/lifecycle.js +3 -3
  77. package/dist/plugin/lifecycle.js.map +1 -1
  78. package/dist/plugin/loader.d.ts.map +1 -1
  79. package/dist/plugin/loader.js +12 -2
  80. package/dist/plugin/loader.js.map +1 -1
  81. package/dist/provider/__tests__/model-version.test.d.ts +2 -0
  82. package/dist/provider/__tests__/model-version.test.d.ts.map +1 -0
  83. package/dist/provider/__tests__/model-version.test.js +80 -0
  84. package/dist/provider/__tests__/model-version.test.js.map +1 -0
  85. package/dist/provider/__tests__/strict-schema.test.d.ts +2 -0
  86. package/dist/provider/__tests__/strict-schema.test.d.ts.map +1 -0
  87. package/dist/provider/__tests__/strict-schema.test.js +109 -0
  88. package/dist/provider/__tests__/strict-schema.test.js.map +1 -0
  89. package/dist/provider/model-version.d.ts +60 -0
  90. package/dist/provider/model-version.d.ts.map +1 -0
  91. package/dist/provider/model-version.js +64 -0
  92. package/dist/provider/model-version.js.map +1 -0
  93. package/dist/provider/strict-schema.d.ts +49 -0
  94. package/dist/provider/strict-schema.d.ts.map +1 -0
  95. package/dist/provider/strict-schema.js +112 -0
  96. package/dist/provider/strict-schema.js.map +1 -0
  97. package/dist/public-runtime.d.ts +6 -1
  98. package/dist/public-runtime.d.ts.map +1 -1
  99. package/dist/public-runtime.js +21 -1
  100. package/dist/public-runtime.js.map +1 -1
  101. package/dist/public-types.d.ts +2 -0
  102. package/dist/public-types.d.ts.map +1 -1
  103. package/dist/registry/tool/__tests__/strict-registration.test.d.ts +2 -0
  104. package/dist/registry/tool/__tests__/strict-registration.test.d.ts.map +1 -0
  105. package/dist/registry/tool/__tests__/strict-registration.test.js +82 -0
  106. package/dist/registry/tool/__tests__/strict-registration.test.js.map +1 -0
  107. package/dist/registry/tool/execute.d.ts.map +1 -1
  108. package/dist/registry/tool/execute.js +16 -0
  109. package/dist/registry/tool/execute.js.map +1 -1
  110. package/dist/runtime/query/result.d.ts.map +1 -1
  111. package/dist/runtime/query/result.js +5 -0
  112. package/dist/runtime/query/result.js.map +1 -1
  113. package/dist/tools/builtins/__tests__/edit-insert-reachable.test.js +7 -1
  114. package/dist/tools/builtins/__tests__/edit-insert-reachable.test.js.map +1 -1
  115. package/dist/tools/builtins/__tests__/edit.test.js +1 -1
  116. package/dist/tools/builtins/__tests__/edit.test.js.map +1 -1
  117. package/dist/tools/builtins/edit.d.ts.map +1 -1
  118. package/dist/tools/builtins/edit.js +20 -2
  119. package/dist/tools/builtins/edit.js.map +1 -1
  120. package/dist/types/plugin/index.d.ts +4 -4
  121. package/dist/types/run/events.d.ts +17 -2
  122. package/dist/types/run/events.d.ts.map +1 -1
  123. package/dist/types/run/events.js.map +1 -1
  124. package/dist/types/verification/index.d.ts +6 -6
  125. package/package.json +1 -1
  126. package/src/agents/__tests__/run-agent-forwarding.test.ts +85 -0
  127. package/src/agents/__tests__/run-completed-stop-reason.test.ts +59 -0
  128. package/src/agents/index.ts +8 -0
  129. package/src/agents/runAgent.ts +30 -4
  130. package/src/constants/tools/__tests__/dangerous-patterns.test.ts +62 -0
  131. package/src/constants/tools/index.ts +28 -1
  132. package/src/directory/__tests__/derive.test.ts +135 -0
  133. package/src/directory/__tests__/load-diagnostics.test.ts +126 -0
  134. package/src/directory/__tests__/load-directory.test.ts +243 -0
  135. package/src/directory/__tests__/subagents.test.ts +155 -0
  136. package/src/directory/__tests__/supervisor-budget.test.ts +117 -0
  137. package/src/directory/derive-supervisor.ts +149 -0
  138. package/src/directory/derive.ts +70 -0
  139. package/src/directory/index.ts +27 -0
  140. package/src/directory/load.ts +556 -0
  141. package/src/directory/scan.ts +163 -0
  142. package/src/directory/types.ts +254 -0
  143. package/src/plugin/__tests__/path-containment.test.ts +107 -0
  144. package/src/plugin/lifecycle.ts +3 -3
  145. package/src/plugin/loader.ts +12 -2
  146. package/src/provider/__tests__/model-version.test.ts +93 -0
  147. package/src/provider/__tests__/strict-schema.test.ts +133 -0
  148. package/src/provider/model-version.ts +98 -0
  149. package/src/provider/strict-schema.ts +125 -0
  150. package/src/public-runtime.ts +31 -0
  151. package/src/public-types.ts +8 -0
  152. package/src/registry/tool/__tests__/strict-registration.test.ts +115 -0
  153. package/src/registry/tool/execute.ts +16 -0
  154. package/src/runtime/query/result.ts +5 -0
  155. package/src/tools/builtins/__tests__/edit-insert-reachable.test.ts +8 -2
  156. package/src/tools/builtins/__tests__/edit.test.ts +1 -1
  157. package/src/tools/builtins/edit.ts +20 -2
  158. package/src/types/run/events.ts +15 -2
@@ -0,0 +1,149 @@
1
+ import { DEFAULT_TIMEOUT_MS, DEFAULT_TOKEN_BUDGET } from '../agents/runAgent.js'
2
+ import type { AgentIdentity } from '../agents/runAgent.js'
3
+ import { ToolRegistry } from '../registry/tool/execute.js'
4
+ import type { SupervisorAgentConfig } from '../types/agent/supervisor.js'
5
+ import type { LLMProvider } from '../types/provider/index.js'
6
+
7
+ import type { DirectoryManifest, SubAgentEntry } from './types.js'
8
+
9
+ export interface DeriveSupervisorInput {
10
+ readonly provider: LLMProvider
11
+ /** Wins over `agent.ts`. Required when `agent.ts` names no model. */
12
+ readonly model?: string
13
+ readonly identity?: Required<AgentIdentity>
14
+ /**
15
+ * The lifecycle object that actually spawns delegates.
16
+ *
17
+ * Supplied by the host and never built here. An `AgentManager` owns
18
+ * running processes, budgets and cancellation — it is a thing with a
19
+ * lifetime, not a description of one, and this package's whole boundary is
20
+ * that it describes and does not run. Handing back options that carry a
21
+ * manager we constructed would make it a runner wearing a loader's name.
22
+ */
23
+ readonly agentManager: SupervisorAgentConfig['agentManager']
24
+ readonly overrides?: Partial<SupervisorAgentConfig>
25
+ }
26
+
27
+ export interface SupervisorPlan {
28
+ /** Ready for `new SupervisorAgent(...).run(input, config)`. */
29
+ readonly config: SupervisorAgentConfig
30
+ /**
31
+ * What the host must register with its `AgentManager` before running,
32
+ * one per delegate, keyed by the id the supervisor will name.
33
+ *
34
+ * Returned rather than registered: registration is a mutation of the
35
+ * host's manager, and a function that quietly mutates an object it was
36
+ * handed for reference is the kind of surprise this package exists to
37
+ * avoid. The host does it, in one loop it can see.
38
+ */
39
+ readonly delegates: readonly DelegatePlan[]
40
+ }
41
+
42
+ export interface DelegatePlan {
43
+ readonly id: string
44
+ readonly manifest: DirectoryManifest
45
+ /** The delegate's own instructions, tools and model, already assembled. */
46
+ readonly systemPrompt: string
47
+ readonly tools: ToolRegistry
48
+ readonly model: string
49
+ }
50
+
51
+ function toolsOf(manifest: DirectoryManifest): ToolRegistry {
52
+ const tools = new ToolRegistry()
53
+ for (const entry of manifest.tools) tools.register(entry.definition)
54
+ return tools
55
+ }
56
+
57
+ function delegatePlan(entry: SubAgentEntry, fallbackModel: string): DelegatePlan {
58
+ return {
59
+ id: entry.id,
60
+ manifest: entry.manifest,
61
+ systemPrompt: entry.manifest.instructions,
62
+ tools: toolsOf(entry.manifest),
63
+ // A delegate may name its own model — a cheap one for a narrow job is
64
+ // the common case — and inherits the supervisor's only when it does
65
+ // not. Inheriting unconditionally would silently bill every specialist
66
+ // at the coordinator's rate.
67
+ model: entry.manifest.config.model ?? fallbackModel,
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Turn a project that declares delegates into a supervisor configuration.
73
+ *
74
+ * The counterpart to `deriveRunOptions` for the multi-agent shape, and the
75
+ * same contract: it converts, it does not run. `SupervisorAgent` needs an
76
+ * `agentIds` roster and a manager that can spawn them; this supplies the
77
+ * roster from the directory and leaves the manager to the host.
78
+ *
79
+ * The delegates come back as plans rather than registered agents because
80
+ * registration mutates the host's manager. Two lines in the host, and the host
81
+ * can see exactly what it just gained.
82
+ */
83
+ export function deriveSupervisorOptions(
84
+ manifest: DirectoryManifest,
85
+ input: DeriveSupervisorInput,
86
+ ): SupervisorPlan {
87
+ if (manifest.modules === 'skip') {
88
+ throw new Error(
89
+ 'This manifest was loaded with modules: "skip", so no tool was imported and no delegate was evaluated. Load with modules: "evaluate" before deriving supervisor options.',
90
+ )
91
+ }
92
+ if (manifest.agents.length === 0) {
93
+ // Not a warning that degrades into a supervisor with nobody to call.
94
+ // An empty roster makes `create_task` unmountable by design, so the
95
+ // result would be a coordinator that cannot coordinate — and the
96
+ // caller asked for a supervisor, which means they expected delegates.
97
+ throw new Error(
98
+ `${manifest.root} declares no delegates, so there is nothing for a supervisor to coordinate. Add directories under agents/, or use deriveRunOptions for a single agent.`,
99
+ )
100
+ }
101
+
102
+ const model = input.model ?? manifest.config.model
103
+ if (!model) {
104
+ throw new Error(
105
+ `No model. Declare one in ${manifest.root}/agent.ts as \`export default { model: "…" }\`, or pass \`model\` here.`,
106
+ )
107
+ }
108
+
109
+ const delegates = manifest.agents.map((entry) => delegatePlan(entry, model))
110
+
111
+ const config = {
112
+ provider: input.provider,
113
+ model,
114
+ agentManager: input.agentManager,
115
+ agentIds: delegates.map((d) => d.id),
116
+ systemPrompt: manifest.instructions,
117
+ tools: toolsOf(manifest),
118
+ // Skills were loaded and then dropped. The manifest reads a whole
119
+ // `skills/` directory and `SupervisorAgentConfig` takes them, and the
120
+ // cast that used to close this object meant nobody was told the field
121
+ // had never been supplied.
122
+ ...(manifest.skills.length > 0 ? { skills: manifest.skills.map((s) => s.skill) } : {}),
123
+ // `tokenBudget` and `timeoutMs` are REQUIRED by `BaseAgentConfig`, and
124
+ // this object supplied them only when `agent.ts` happened to declare
125
+ // them — which is the uncommon case. The `as SupervisorAgentConfig`
126
+ // below made that compile, so a directory that named no budget produced
127
+ // a config typed `tokenBudget: number` holding `undefined`, and
128
+ // `buildLimitConfig` then disabled BOTH hard stops: no token cap, no
129
+ // wall clock. Worse, the child-spawn refusal computes its allocation
130
+ // from the parent budget, so `undefined` became `NaN`, and `NaN <= 0`
131
+ // is false — the guard that exists to refuse an unfunded child let it
132
+ // through with a NaN budget.
133
+ //
134
+ // Defaulted to the same numbers `runAgent` uses rather than to a local
135
+ // guess, so the two front doors cannot drift.
136
+ tokenBudget: manifest.config.tokenBudget ?? DEFAULT_TOKEN_BUDGET,
137
+ timeoutMs: manifest.config.timeoutMs ?? DEFAULT_TIMEOUT_MS,
138
+ ...(manifest.config.temperature !== undefined
139
+ ? { temperature: manifest.config.temperature }
140
+ : {}),
141
+ ...(manifest.config.maxIterations !== undefined
142
+ ? { maxIterations: manifest.config.maxIterations }
143
+ : {}),
144
+ ...(input.identity ?? {}),
145
+ ...(input.overrides ?? {}),
146
+ } satisfies SupervisorAgentConfig
147
+
148
+ return { config, delegates }
149
+ }
@@ -0,0 +1,70 @@
1
+ import type { RunAgentOptions } from '../agents/runAgent.js'
2
+ import { ToolRegistry } from '../registry/tool/execute.js'
3
+
4
+ import type { DeriveRunOptionsInput, DirectoryManifest } from './types.js'
5
+
6
+ /**
7
+ * Turn a loaded project into the options `runAgent` takes.
8
+ *
9
+ * One direction, no second engine. Everything this produces is an ordinary
10
+ * `RunAgentOptions` field, so a caller who needs something this does not cover
11
+ * spreads `overrides` or stops using this function — there is no behaviour
12
+ * reachable only through the convention.
13
+ */
14
+ export function deriveRunOptions(
15
+ manifest: DirectoryManifest,
16
+ input: DeriveRunOptionsInput,
17
+ ): RunAgentOptions {
18
+ if (manifest.modules === 'skip') {
19
+ // The manifest is structurally complete and its tools were never
20
+ // imported, so `manifest.tools` is empty for a reason that has nothing
21
+ // to do with the project. Running it would produce an agent with no
22
+ // capabilities and no indication why.
23
+ throw new Error(
24
+ 'This manifest was loaded with modules: "skip", so no tool was imported and none can be registered. Load with modules: "evaluate" before deriving run options.',
25
+ )
26
+ }
27
+
28
+ const model = input.model ?? manifest.config.model
29
+ if (!model) {
30
+ throw new Error(
31
+ `No model. Declare one in ${manifest.root}/agent.ts as \`export default { model: "…" }\`, or pass \`model\` here.`,
32
+ )
33
+ }
34
+
35
+ const tools = new ToolRegistry()
36
+ for (const entry of manifest.tools) tools.register(entry.definition)
37
+
38
+ return {
39
+ provider: input.provider,
40
+ prompt: input.prompt,
41
+ model,
42
+ tools,
43
+ // The one value the project knows and `runAgent` cannot infer. Left
44
+ // unset it would default to the host's own cwd, pointing the file
45
+ // tools' containment at the host's source tree rather than at the
46
+ // project. The root is `agent/` itself, not its parent — narrower is
47
+ // the safe direction, and widening it is the caller's explicit call
48
+ // through `overrides`.
49
+ workingDirectory: manifest.root,
50
+ ...(manifest.instructions ? { instructions: manifest.instructions } : {}),
51
+ ...(manifest.skills.length > 0 ? { skills: manifest.skills.map((s) => s.skill) } : {}),
52
+ // Only when declared. A name guessed from a directory basename becomes
53
+ // the agent id in traces, where two sibling projects called `agent`
54
+ // would silently merge into one attribution bucket — worse than the
55
+ // SDK's own default, which at least does not pretend to be specific.
56
+ ...(manifest.config.name ? { name: manifest.config.name } : {}),
57
+ ...(manifest.config.temperature !== undefined
58
+ ? { temperature: manifest.config.temperature }
59
+ : {}),
60
+ ...(manifest.config.maxIterations !== undefined
61
+ ? { maxIterations: manifest.config.maxIterations }
62
+ : {}),
63
+ ...(manifest.config.tokenBudget !== undefined
64
+ ? { tokenBudget: manifest.config.tokenBudget }
65
+ : {}),
66
+ ...(manifest.config.timeoutMs !== undefined ? { timeoutMs: manifest.config.timeoutMs } : {}),
67
+ ...(input.identity ?? {}),
68
+ ...(input.overrides ?? {}),
69
+ }
70
+ }
@@ -0,0 +1,27 @@
1
+ export { loadDirectory } from './load.js'
2
+ export { deriveRunOptions } from './derive.js'
3
+ export { deriveSupervisorOptions } from './derive-supervisor.js'
4
+ export type {
5
+ DelegatePlan,
6
+ DeriveSupervisorInput,
7
+ SupervisorPlan,
8
+ } from './derive-supervisor.js'
9
+ export type {
10
+ DeriveRunOptionsInput,
11
+ DirectoryDiagnosticCode,
12
+ DirectoryDiagnosticSeverity,
13
+ LoadDirectoryOptions,
14
+ ModuleImporter,
15
+ ModuleMode,
16
+ DirectoryConfig,
17
+ DirectoryDiagnostic,
18
+ DirectoryLoadResult,
19
+ DirectoryManifest,
20
+ DirectorySlot,
21
+ SkillEntry,
22
+ SourceOutcome,
23
+ SourceRef,
24
+ SubAgentEntry,
25
+ ToolEntry,
26
+ } from './types.js'
27
+ export { ALL_SLOTS } from './types.js'