@namzu/sdk 69.0.0 → 69.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 (316) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/dist/agents/QueryAgent.d.ts.map +1 -1
  3. package/dist/agents/QueryAgent.js +2 -0
  4. package/dist/agents/QueryAgent.js.map +1 -1
  5. package/dist/authorization/skill-grant.d.ts.map +1 -1
  6. package/dist/authorization/skill-grant.js +1 -0
  7. package/dist/authorization/skill-grant.js.map +1 -1
  8. package/dist/bridge/acp/permission.d.ts +10 -0
  9. package/dist/bridge/acp/permission.d.ts.map +1 -1
  10. package/dist/bridge/acp/permission.js.map +1 -1
  11. package/dist/bridge/acp/server.d.ts.map +1 -1
  12. package/dist/bridge/acp/server.js +1 -0
  13. package/dist/bridge/acp/server.js.map +1 -1
  14. package/dist/connector/index.d.ts +2 -2
  15. package/dist/connector/index.d.ts.map +1 -1
  16. package/dist/connector/index.js +1 -1
  17. package/dist/connector/index.js.map +1 -1
  18. package/dist/connector/mcp/client.d.ts +29 -0
  19. package/dist/connector/mcp/client.d.ts.map +1 -1
  20. package/dist/connector/mcp/client.js +59 -2
  21. package/dist/connector/mcp/client.js.map +1 -1
  22. package/dist/connector/mcp/errors.d.ts +7 -0
  23. package/dist/connector/mcp/errors.d.ts.map +1 -1
  24. package/dist/connector/mcp/errors.js +14 -0
  25. package/dist/connector/mcp/errors.js.map +1 -1
  26. package/dist/connector/mcp/index.d.ts +5 -1
  27. package/dist/connector/mcp/index.d.ts.map +1 -1
  28. package/dist/connector/mcp/index.js +3 -1
  29. package/dist/connector/mcp/index.js.map +1 -1
  30. package/dist/connector/mcp/skill-source.d.ts +144 -0
  31. package/dist/connector/mcp/skill-source.d.ts.map +1 -0
  32. package/dist/connector/mcp/skill-source.js +375 -0
  33. package/dist/connector/mcp/skill-source.js.map +1 -0
  34. package/dist/connector/mcp/skills.d.ts +137 -0
  35. package/dist/connector/mcp/skills.d.ts.map +1 -0
  36. package/dist/connector/mcp/skills.js +303 -0
  37. package/dist/connector/mcp/skills.js.map +1 -0
  38. package/dist/network/audit.d.ts +1 -1
  39. package/dist/network/audit.d.ts.map +1 -1
  40. package/dist/network/audit.js +2 -0
  41. package/dist/network/audit.js.map +1 -1
  42. package/dist/network/computer.d.ts +107 -0
  43. package/dist/network/computer.d.ts.map +1 -0
  44. package/dist/network/computer.js +250 -0
  45. package/dist/network/computer.js.map +1 -0
  46. package/dist/network/index.d.ts +2 -0
  47. package/dist/network/index.d.ts.map +1 -1
  48. package/dist/network/index.js +1 -0
  49. package/dist/network/index.js.map +1 -1
  50. package/dist/network/join.d.ts +3 -1
  51. package/dist/network/join.d.ts.map +1 -1
  52. package/dist/network/join.js +6 -3
  53. package/dist/network/join.js.map +1 -1
  54. package/dist/network/roster.d.ts +5 -0
  55. package/dist/network/roster.d.ts.map +1 -1
  56. package/dist/network/roster.js.map +1 -1
  57. package/dist/network/service.d.ts +12 -2
  58. package/dist/network/service.d.ts.map +1 -1
  59. package/dist/network/service.js +377 -52
  60. package/dist/network/service.js.map +1 -1
  61. package/dist/network/store.d.ts +10 -0
  62. package/dist/network/store.d.ts.map +1 -1
  63. package/dist/network/store.js +25 -3
  64. package/dist/network/store.js.map +1 -1
  65. package/dist/network/wire.d.ts +2 -0
  66. package/dist/network/wire.d.ts.map +1 -1
  67. package/dist/network/wire.js +5 -0
  68. package/dist/network/wire.js.map +1 -1
  69. package/dist/persona/assembler.d.ts.map +1 -1
  70. package/dist/persona/assembler.js +7 -1
  71. package/dist/persona/assembler.js.map +1 -1
  72. package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
  73. package/dist/plugin/shell-hook-tool-names.js +1 -0
  74. package/dist/plugin/shell-hook-tool-names.js.map +1 -1
  75. package/dist/plugin/shell-hook.d.ts +8 -3
  76. package/dist/plugin/shell-hook.d.ts.map +1 -1
  77. package/dist/plugin/shell-hook.js +132 -7
  78. package/dist/plugin/shell-hook.js.map +1 -1
  79. package/dist/provider/fallback.d.ts.map +1 -1
  80. package/dist/provider/fallback.js +4 -0
  81. package/dist/provider/fallback.js.map +1 -1
  82. package/dist/provider/idle-timeout.d.ts.map +1 -1
  83. package/dist/provider/idle-timeout.js +3 -0
  84. package/dist/provider/idle-timeout.js.map +1 -1
  85. package/dist/provider/model-window-suffix.d.ts.map +1 -1
  86. package/dist/provider/model-window-suffix.js +1 -0
  87. package/dist/provider/model-window-suffix.js.map +1 -1
  88. package/dist/provider/retry.d.ts.map +1 -1
  89. package/dist/provider/retry.js +3 -0
  90. package/dist/provider/retry.js.map +1 -1
  91. package/dist/public-runtime.d.ts +9 -6
  92. package/dist/public-runtime.d.ts.map +1 -1
  93. package/dist/public-runtime.js +11 -4
  94. package/dist/public-runtime.js.map +1 -1
  95. package/dist/public-tools.d.ts +7 -4
  96. package/dist/public-tools.d.ts.map +1 -1
  97. package/dist/public-tools.js +9 -3
  98. package/dist/public-tools.js.map +1 -1
  99. package/dist/public-types.d.ts +3 -1
  100. package/dist/public-types.d.ts.map +1 -1
  101. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  102. package/dist/runtime/query/executor/tool-call-admission.js +10 -1
  103. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  104. package/dist/runtime/query/executor.d.ts +12 -0
  105. package/dist/runtime/query/executor.d.ts.map +1 -1
  106. package/dist/runtime/query/executor.js +43 -9
  107. package/dist/runtime/query/executor.js.map +1 -1
  108. package/dist/runtime/query/index.d.ts +4 -0
  109. package/dist/runtime/query/index.d.ts.map +1 -1
  110. package/dist/runtime/query/index.js +32 -0
  111. package/dist/runtime/query/index.js.map +1 -1
  112. package/dist/runtime/query/review-policy.d.ts +2 -2
  113. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  114. package/dist/runtime/query/review-policy.js +2 -2
  115. package/dist/runtime/query/review-policy.js.map +1 -1
  116. package/dist/runtime/query/shell-line-escalation.d.ts +24 -0
  117. package/dist/runtime/query/shell-line-escalation.d.ts.map +1 -0
  118. package/dist/runtime/query/shell-line-escalation.js +38 -0
  119. package/dist/runtime/query/shell-line-escalation.js.map +1 -0
  120. package/dist/runtime/query/tooling.d.ts +7 -0
  121. package/dist/runtime/query/tooling.d.ts.map +1 -1
  122. package/dist/runtime/query/tooling.js +2 -0
  123. package/dist/runtime/query/tooling.js.map +1 -1
  124. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  125. package/dist/runtime/query/turn/outcome-ledger.js +11 -0
  126. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  127. package/dist/scheduler/local.d.ts.map +1 -1
  128. package/dist/scheduler/local.js +3 -1
  129. package/dist/scheduler/local.js.map +1 -1
  130. package/dist/skills/index.d.ts +4 -0
  131. package/dist/skills/index.d.ts.map +1 -1
  132. package/dist/skills/index.js +2 -0
  133. package/dist/skills/index.js.map +1 -1
  134. package/dist/skills/inline-shell-host.d.ts +103 -0
  135. package/dist/skills/inline-shell-host.d.ts.map +1 -0
  136. package/dist/skills/inline-shell-host.js +238 -0
  137. package/dist/skills/inline-shell-host.js.map +1 -0
  138. package/dist/skills/inline-shell.d.ts +176 -0
  139. package/dist/skills/inline-shell.d.ts.map +1 -0
  140. package/dist/skills/inline-shell.js +646 -0
  141. package/dist/skills/inline-shell.js.map +1 -0
  142. package/dist/store/index.d.ts +2 -0
  143. package/dist/store/index.d.ts.map +1 -1
  144. package/dist/store/index.js +1 -0
  145. package/dist/store/index.js.map +1 -1
  146. package/dist/store/task/file.d.ts +124 -0
  147. package/dist/store/task/file.d.ts.map +1 -0
  148. package/dist/store/task/file.js +498 -0
  149. package/dist/store/task/file.js.map +1 -0
  150. package/dist/teams/backend.d.ts +28 -0
  151. package/dist/teams/backend.d.ts.map +1 -0
  152. package/dist/teams/backend.js +2 -0
  153. package/dist/teams/backend.js.map +1 -0
  154. package/dist/teams/fs-sync.d.ts +19 -0
  155. package/dist/teams/fs-sync.d.ts.map +1 -0
  156. package/dist/teams/fs-sync.js +81 -0
  157. package/dist/teams/fs-sync.js.map +1 -0
  158. package/dist/teams/index.d.ts +14 -0
  159. package/dist/teams/index.d.ts.map +1 -0
  160. package/dist/teams/index.js +11 -0
  161. package/dist/teams/index.js.map +1 -0
  162. package/dist/teams/names.d.ts +15 -0
  163. package/dist/teams/names.d.ts.map +1 -0
  164. package/dist/teams/names.js +43 -0
  165. package/dist/teams/names.js.map +1 -0
  166. package/dist/teams/store.d.ts +133 -0
  167. package/dist/teams/store.d.ts.map +1 -0
  168. package/dist/teams/store.js +536 -0
  169. package/dist/teams/store.js.map +1 -0
  170. package/dist/teams/types.d.ts +97 -0
  171. package/dist/teams/types.d.ts.map +1 -0
  172. package/dist/teams/types.js +70 -0
  173. package/dist/teams/types.js.map +1 -0
  174. package/dist/tools/admit-facts.d.ts.map +1 -1
  175. package/dist/tools/admit-facts.js +9 -1
  176. package/dist/tools/admit-facts.js.map +1 -1
  177. package/dist/tools/builtins/atomic-write-file.d.ts +19 -3
  178. package/dist/tools/builtins/atomic-write-file.d.ts.map +1 -1
  179. package/dist/tools/builtins/atomic-write-file.js +56 -3
  180. package/dist/tools/builtins/atomic-write-file.js.map +1 -1
  181. package/dist/tools/builtins/computer-use.d.ts +56 -2
  182. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  183. package/dist/tools/builtins/computer-use.js +604 -90
  184. package/dist/tools/builtins/computer-use.js.map +1 -1
  185. package/dist/tools/builtins/index.d.ts +1 -1
  186. package/dist/tools/builtins/index.d.ts.map +1 -1
  187. package/dist/tools/builtins/index.js.map +1 -1
  188. package/dist/tools/builtins/skill.d.ts +31 -0
  189. package/dist/tools/builtins/skill.d.ts.map +1 -1
  190. package/dist/tools/builtins/skill.js +232 -88
  191. package/dist/tools/builtins/skill.js.map +1 -1
  192. package/dist/tools/task/create.d.ts.map +1 -1
  193. package/dist/tools/task/create.js +11 -2
  194. package/dist/tools/task/create.js.map +1 -1
  195. package/dist/tools/task/get.d.ts +8 -0
  196. package/dist/tools/task/get.d.ts.map +1 -0
  197. package/dist/tools/task/get.js +51 -0
  198. package/dist/tools/task/get.js.map +1 -0
  199. package/dist/tools/task/index.d.ts +7 -0
  200. package/dist/tools/task/index.d.ts.map +1 -1
  201. package/dist/tools/task/index.js +10 -2
  202. package/dist/tools/task/index.js.map +1 -1
  203. package/dist/tools/task/list.d.ts.map +1 -1
  204. package/dist/tools/task/list.js +10 -2
  205. package/dist/tools/task/list.js.map +1 -1
  206. package/dist/tools/task/number.d.ts +13 -0
  207. package/dist/tools/task/number.d.ts.map +1 -0
  208. package/dist/tools/task/number.js +30 -0
  209. package/dist/tools/task/number.js.map +1 -0
  210. package/dist/tools/task/present.d.ts.map +1 -1
  211. package/dist/tools/task/present.js +17 -3
  212. package/dist/tools/task/present.js.map +1 -1
  213. package/dist/tools/task/update.d.ts +2 -1
  214. package/dist/tools/task/update.d.ts.map +1 -1
  215. package/dist/tools/task/update.js +86 -19
  216. package/dist/tools/task/update.js.map +1 -1
  217. package/dist/types/acp/index.d.ts +10 -0
  218. package/dist/types/acp/index.d.ts.map +1 -1
  219. package/dist/types/agent/base.d.ts +4 -0
  220. package/dist/types/agent/base.d.ts.map +1 -1
  221. package/dist/types/agent/scheduler.d.ts +9 -0
  222. package/dist/types/agent/scheduler.d.ts.map +1 -1
  223. package/dist/types/computer-use/index.d.ts +7 -0
  224. package/dist/types/computer-use/index.d.ts.map +1 -1
  225. package/dist/types/computer-use/index.js.map +1 -1
  226. package/dist/types/connector/mcp.d.ts +10 -0
  227. package/dist/types/connector/mcp.d.ts.map +1 -1
  228. package/dist/types/permission/index.d.ts +20 -0
  229. package/dist/types/permission/index.d.ts.map +1 -1
  230. package/dist/types/permission/index.js +25 -0
  231. package/dist/types/permission/index.js.map +1 -1
  232. package/dist/types/plugin/index.d.ts +47 -3
  233. package/dist/types/plugin/index.d.ts.map +1 -1
  234. package/dist/types/plugin/index.js +4 -0
  235. package/dist/types/plugin/index.js.map +1 -1
  236. package/dist/types/provider/interface.d.ts +6 -0
  237. package/dist/types/provider/interface.d.ts.map +1 -1
  238. package/dist/types/skills/index.d.ts +7 -0
  239. package/dist/types/skills/index.d.ts.map +1 -1
  240. package/dist/types/skills/index.js.map +1 -1
  241. package/dist/types/tool/index.d.ts +28 -2
  242. package/dist/types/tool/index.d.ts.map +1 -1
  243. package/dist/types/tool/index.js.map +1 -1
  244. package/dist/types/tool/presentation.d.ts +4 -0
  245. package/dist/types/tool/presentation.d.ts.map +1 -1
  246. package/package.json +1 -1
  247. package/src/agents/QueryAgent.ts +2 -0
  248. package/src/authorization/skill-grant.ts +1 -0
  249. package/src/bridge/acp/permission.ts +11 -1
  250. package/src/bridge/acp/server.ts +1 -0
  251. package/src/connector/index.ts +27 -0
  252. package/src/connector/mcp/client.ts +71 -2
  253. package/src/connector/mcp/errors.ts +14 -0
  254. package/src/connector/mcp/index.ts +36 -0
  255. package/src/connector/mcp/skill-source.ts +499 -0
  256. package/src/connector/mcp/skills.ts +367 -0
  257. package/src/network/audit.ts +2 -0
  258. package/src/network/computer.ts +347 -0
  259. package/src/network/index.ts +20 -0
  260. package/src/network/join.ts +4 -2
  261. package/src/network/roster.ts +5 -0
  262. package/src/network/service.ts +492 -75
  263. package/src/network/store.ts +29 -3
  264. package/src/network/wire.ts +5 -0
  265. package/src/persona/assembler.ts +7 -1
  266. package/src/plugin/shell-hook-tool-names.ts +1 -0
  267. package/src/plugin/shell-hook.ts +144 -7
  268. package/src/provider/fallback.ts +4 -0
  269. package/src/provider/idle-timeout.ts +3 -0
  270. package/src/provider/model-window-suffix.ts +1 -0
  271. package/src/provider/retry.ts +3 -0
  272. package/src/public-runtime.ts +99 -0
  273. package/src/public-tools.ts +15 -0
  274. package/src/public-types.ts +28 -0
  275. package/src/runtime/query/executor/tool-call-admission.ts +10 -1
  276. package/src/runtime/query/executor.ts +57 -8
  277. package/src/runtime/query/index.ts +43 -0
  278. package/src/runtime/query/review-policy.ts +7 -1
  279. package/src/runtime/query/shell-line-escalation.ts +49 -0
  280. package/src/runtime/query/tooling.ts +6 -0
  281. package/src/runtime/query/turn/outcome-ledger.ts +11 -0
  282. package/src/scheduler/local.ts +3 -1
  283. package/src/skills/index.ts +43 -0
  284. package/src/skills/inline-shell-host.ts +303 -0
  285. package/src/skills/inline-shell.ts +765 -0
  286. package/src/store/index.ts +8 -0
  287. package/src/store/task/file.ts +641 -0
  288. package/src/teams/backend.ts +29 -0
  289. package/src/teams/fs-sync.ts +91 -0
  290. package/src/teams/index.ts +47 -0
  291. package/src/teams/names.ts +49 -0
  292. package/src/teams/store.ts +607 -0
  293. package/src/teams/types.ts +102 -0
  294. package/src/tools/admit-facts.ts +9 -1
  295. package/src/tools/builtins/atomic-write-file.ts +73 -5
  296. package/src/tools/builtins/computer-use.ts +689 -95
  297. package/src/tools/builtins/index.ts +1 -0
  298. package/src/tools/builtins/skill.ts +291 -95
  299. package/src/tools/task/create.ts +11 -2
  300. package/src/tools/task/get.ts +53 -0
  301. package/src/tools/task/index.ts +14 -2
  302. package/src/tools/task/list.ts +10 -2
  303. package/src/tools/task/number.ts +32 -0
  304. package/src/tools/task/present.ts +18 -3
  305. package/src/tools/task/update.ts +93 -19
  306. package/src/types/acp/index.ts +11 -1
  307. package/src/types/agent/base.ts +6 -0
  308. package/src/types/agent/scheduler.ts +9 -0
  309. package/src/types/computer-use/index.ts +7 -0
  310. package/src/types/connector/mcp.ts +10 -0
  311. package/src/types/permission/index.ts +29 -0
  312. package/src/types/plugin/index.ts +95 -39
  313. package/src/types/provider/interface.ts +7 -0
  314. package/src/types/skills/index.ts +8 -0
  315. package/src/types/tool/index.ts +23 -2
  316. package/src/types/tool/presentation.ts +2 -0
@@ -24,6 +24,7 @@ export type {
24
24
  SkillDirectoryRequest,
25
25
  SkillDirectoryResolver,
26
26
  SkillToolOptions,
27
+ SkillToolShellOptions,
27
28
  } from './skill.js'
28
29
  export {
29
30
  WEB_FETCH_TOOL_NAME,
@@ -3,9 +3,23 @@ import { z } from 'zod'
3
3
 
4
4
  import { parseAllowedTools } from '../../authorization/skill-grant.js'
5
5
  import { forkedSkillReportNote } from '../../compaction/loaded-skills.js'
6
+ import {
7
+ type SkillShellHookOptions,
8
+ createSkillShellHook,
9
+ createToolSkillShellHost,
10
+ skillShellAllow,
11
+ } from '../../skills/inline-shell-host.js'
12
+ import {
13
+ type InlineShellBlock,
14
+ InlineShellError,
15
+ expandInlineShell,
16
+ findInlineShell,
17
+ substituteEscaped,
18
+ } from '../../skills/inline-shell.js'
19
+ import type { PluginSkillShellInvoker } from '../../types/plugin/index.js'
6
20
  import type { Sandbox } from '../../types/sandbox/index.js'
7
21
  import { isInvocableBy, skillInvocation } from '../../types/skills/index.js'
8
- import type { SkillHooksPlan, ToolContext } from '../../types/tool/index.js'
22
+ import type { SkillHooksPlan, ToolContext, ToolResult } from '../../types/tool/index.js'
9
23
  import { defineTool } from '../defineTool.js'
10
24
 
11
25
  export { parseAllowedTools }
@@ -80,6 +94,38 @@ export interface SkillToolOptions {
80
94
  * given. The skill is still LOADED from the registry's own path.
81
95
  */
82
96
  readonly resolveModelDirectory?: SkillDirectoryResolver
97
+ /**
98
+ * Run the shell commands a skill's text holds (`!`cmd`` and a fenced block
99
+ * opened with three backticks and a bang) while the skill loads. Absent, the
100
+ * text is handed over as written and nothing runs.
101
+ */
102
+ readonly shell?: SkillToolShellOptions
103
+ }
104
+
105
+ /** What the host says about the shell commands inside a skill's text. */
106
+ export interface SkillToolShellOptions {
107
+ /** True while commands in skill text must not run; read at each load. */
108
+ readonly disabled?: () => boolean
109
+ /**
110
+ * Where a skill came from, as the label a hook is told (`user`, `project`,
111
+ * `plugin`, `system`), and whether its commands may run at all: a skill from
112
+ * a tool server or other remote source, or a project's before its folder is
113
+ * trusted, gets `block` and its commands become a placeholder. A host that
114
+ * gives this function and answers `undefined` for a skill has not placed it,
115
+ * and that skill's commands do not run either.
116
+ */
117
+ readonly sourceOf?: (skill: string) =>
118
+ | {
119
+ readonly source?: string
120
+ readonly block?: InlineShellBlock
121
+ }
122
+ | undefined
123
+ /** The hook manager of the session; absent, no hook is asked. */
124
+ readonly hooks?: () => SkillShellHookOptions['manager']
125
+ /** The session's id, as a hook is told it. */
126
+ readonly sessionId?: () => string
127
+ /** A line for the person: a refused command, a hook's own message. */
128
+ readonly warn?: (line: string) => void
83
129
  }
84
130
 
85
131
  const inputSchema = z.object({
@@ -315,6 +361,17 @@ function pageSkillBody(input: {
315
361
 
316
362
  export const SKILL_TOOL_NAME = 'skill'
317
363
 
364
+ /**
365
+ * A skill that could not load because a command in it failed, was refused or
366
+ * was stopped, as the tool's own failure. `undefined` for anything else,
367
+ * including the turn's own cancellation, which belongs to the turn.
368
+ */
369
+ function shellLoadFailure(error: unknown, context: ToolContext): ToolResult | undefined {
370
+ if (context.abortSignal.aborted) return undefined
371
+ if (!(error instanceof InlineShellError)) return undefined
372
+ return { success: false, output: '', error: error.message }
373
+ }
374
+
318
375
  /** The tool a skill that sets `context: fork` is handed to. */
319
376
  const DELEGATION_TOOL_NAME = 'Agent'
320
377
 
@@ -324,6 +381,70 @@ const DELEGATION_TOOL_NAME = 'Agent'
324
381
  */
325
382
  export function createSkillTool(options: SkillToolOptions = {}) {
326
383
  const resolveModelDirectory = options.resolveModelDirectory
384
+ // A load that ran commands is read again for each page of a long skill, and
385
+ // must not run them again: the first load's text is kept for its pages.
386
+ const expanded = new Map<string, string>()
387
+ const expandShell = async (input: {
388
+ readonly name: string
389
+ readonly body: string
390
+ readonly args: string | undefined
391
+ readonly directory: string | undefined
392
+ readonly allowedTools: readonly string[] | undefined
393
+ readonly invokedBy: PluginSkillShellInvoker
394
+ readonly context: ToolContext
395
+ readonly reuse: boolean
396
+ }): Promise<string> => {
397
+ const shell = options.shell
398
+ if (shell === undefined || findInlineShell(input.body).length === 0) return input.body
399
+ const key = `${input.name}\u0000${input.body}`
400
+ const kept = input.reuse ? expanded.get(key) : undefined
401
+ if (kept !== undefined) return kept
402
+ const where = shell.sourceOf?.(input.name)
403
+ // A host that answers where skills come from, and has no answer for this one, has not
404
+ // placed it: its commands do not run.
405
+ const block: InlineShellBlock | undefined =
406
+ shell.disabled?.() === true
407
+ ? 'off'
408
+ : shell.sourceOf !== undefined && where === undefined
409
+ ? 'remote'
410
+ : where?.block
411
+ const values: Record<string, string> = { $ARGUMENTS: input.args?.trim() ?? '' }
412
+ if (input.directory !== undefined) {
413
+ values['${CLAUDE_SKILL_DIR}'] = input.directory
414
+ values['${NAMZU_SKILL_DIR}'] = input.directory
415
+ }
416
+ const text = substituteEscaped(input.body, values)
417
+ const hook = createSkillShellHook({
418
+ manager: shell.hooks?.(),
419
+ sessionId: shell.sessionId?.() ?? String(input.context.sessionId),
420
+ ...(input.context.turnId !== undefined ? { turnId: String(input.context.turnId) } : {}),
421
+ signal: input.context.abortSignal,
422
+ info: {
423
+ commandName: input.name,
424
+ ...(where?.source !== undefined ? { commandSource: where.source } : {}),
425
+ invokedBy: input.invokedBy,
426
+ },
427
+ })
428
+ const allow = skillShellAllow(input.allowedTools, {
429
+ ...(input.directory !== undefined ? { skillDirectory: input.directory } : {}),
430
+ })
431
+ const result = await expandInlineShell(text, {
432
+ host: createToolSkillShellHost({
433
+ context: input.context,
434
+ ...(allow ? { allow } : {}),
435
+ }),
436
+ commandName: input.name,
437
+ ...(block !== undefined ? { block } : {}),
438
+ ...(hook
439
+ ? { hook: (command: string) => hook(command, `skillshell_${crypto.randomUUID()}`) }
440
+ : {}),
441
+ ...(shell.warn ? { warn: shell.warn } : {}),
442
+ signal: input.context.abortSignal,
443
+ })
444
+ if (expanded.size >= 8) expanded.delete(expanded.keys().next().value as string)
445
+ expanded.set(key, result)
446
+ return result
447
+ }
327
448
  return defineTool({
328
449
  name: SKILL_TOOL_NAME,
329
450
  description:
@@ -511,17 +632,39 @@ export function createSkillTool(options: SkillToolOptions = {}) {
511
632
  ),
512
633
  )
513
634
  : ''
514
- // The delegated prompt is known before the agent starts: the host
515
- // recognises the agent that receives it, among any others that
516
- // start at the same time, and binds the skill's hooks to that one.
517
- const forkPrompt = forkedPrompt(forkHeader, argsLine, skill.body)
518
- const forkHooks = hooksPlanFor(skill, context, true, forkPrompt)
635
+ // The skill's hooks are read once, before any command runs: the same plan
636
+ // decides what its `allowed-tools` may pre-approve for its own commands as
637
+ // on an inline load. The delegated prompt is not known yet, so the host is
638
+ // told it when the hooks attach, and recognises the agent that receives it,
639
+ // among any others that start at the same time.
640
+ const forkHooks = hooksPlanFor(skill, context, true)
641
+ let forkBody = skill.body
642
+ if (forkBody !== undefined) {
643
+ try {
644
+ forkBody = await expandShell({
645
+ name: input.name,
646
+ body: forkBody,
647
+ args: input.args,
648
+ directory: skill.dirPath,
649
+ allowedTools: grantedTools(skill, forkHooks),
650
+ invokedBy: 'model',
651
+ context,
652
+ reuse: false,
653
+ })
654
+ } catch (error) {
655
+ const failed = shellLoadFailure(error, context)
656
+ if (failed) return failed
657
+ throw error
658
+ }
659
+ }
660
+ const forkPrompt = forkedPrompt(forkHeader, argsLine, forkBody)
519
661
  const forkResult = await runForkedSkill({
520
662
  name: input.name,
521
663
  skill,
522
664
  prompt: forkPrompt,
523
665
  dispatch: context.dispatchTool,
524
666
  hooks: forkHooks,
667
+ hooksPrompt: forkPrompt,
525
668
  })
526
669
  return forkHooks?.notice
527
670
  ? { ...forkResult, output: `[${forkHooks.notice}]\n\n${forkResult.output}` }
@@ -535,9 +678,7 @@ export function createSkillTool(options: SkillToolOptions = {}) {
535
678
  // that guards its work cannot be loaded, the skill's pre-approval is
536
679
  // withheld, whatever else it says.
537
680
  const hooksPlan = hooksPlanFor(skill, context, false)
538
- const allowed = hooksPlan?.withholdGrants
539
- ? undefined
540
- : parseAllowedTools(skill.metadata.allowedTools)
681
+ const allowed = grantedTools(skill, hooksPlan)
541
682
  // Asked on every call, first page or continuation: the digest binds
542
683
  // the answer, so a mount that changed between pages is a stale cursor
543
684
  // rather than a second half written for a different directory.
@@ -549,99 +690,137 @@ export function createSkillTool(options: SkillToolOptions = {}) {
549
690
  ),
550
691
  )
551
692
  : undefined
552
- const snapshot: SkillSnapshot = {
553
- name: input.name,
554
- body: skill.body ?? '(this skill has no body)',
555
- allowedTools: allowed,
556
- // The model's path when the host gave one: `${CLAUDE_SKILL_DIR}` in a
557
- // pattern is matched against a command line the model writes, and it
558
- // writes the path it was told.
559
- skillDirectory: resolveModelDirectory ? modelDirectory : skill.dirPath,
560
- header: forkUnavailable + (resolveModelDirectory ? directoryHeader(modelDirectory) : ''),
561
- invocation,
562
- }
563
- const digest = snapshotDigest(snapshot)
564
- let start = 0
565
- if (input.cursor !== undefined) {
566
- const parsed = parseCursor(input.cursor)
567
- if (
568
- !parsed ||
569
- parsed.digest !== digest ||
570
- parsed.offset >= snapshot.body.length ||
571
- !isCodePointBoundary(snapshot.body, parsed.offset)
572
- ) {
693
+ let loadedBody = skill.body ?? '(this skill has no body)'
694
+ // A skill's own hooks guard its own load-time commands, so a skill that holds
695
+ // commands attaches them first and takes them off again when the load fails.
696
+ // Any other skill keeps the rule that they go live once its instructions
697
+ // were delivered.
698
+ const attachedEarly =
699
+ skill.body !== undefined &&
700
+ options.shell !== undefined &&
701
+ findInlineShell(skill.body).length > 0
702
+ ? hooksPlan?.attach()
703
+ : undefined
704
+ let delivered = false
705
+ try {
706
+ if (skill.body !== undefined) {
707
+ try {
708
+ loadedBody = await expandShell({
709
+ name: input.name,
710
+ body: skill.body,
711
+ args: input.args,
712
+ directory: resolveModelDirectory ? modelDirectory : skill.dirPath,
713
+ allowedTools: allowed,
714
+ invokedBy: 'model',
715
+ context,
716
+ reuse: input.cursor !== undefined,
717
+ })
718
+ } catch (error) {
719
+ const failed = shellLoadFailure(error, context)
720
+ if (failed) return failed
721
+ throw error
722
+ }
723
+ }
724
+ const snapshot: SkillSnapshot = {
725
+ name: input.name,
726
+ body: loadedBody,
727
+ allowedTools: allowed,
728
+ // The model's path when the host gave one: `${CLAUDE_SKILL_DIR}` in a
729
+ // pattern is matched against a command line the model writes, and it
730
+ // writes the path it was told.
731
+ skillDirectory: resolveModelDirectory ? modelDirectory : skill.dirPath,
732
+ header: forkUnavailable + (resolveModelDirectory ? directoryHeader(modelDirectory) : ''),
733
+ invocation,
734
+ }
735
+ const digest = snapshotDigest(snapshot)
736
+ let start = 0
737
+ if (input.cursor !== undefined) {
738
+ const parsed = parseCursor(input.cursor)
739
+ if (
740
+ !parsed ||
741
+ parsed.digest !== digest ||
742
+ parsed.offset >= snapshot.body.length ||
743
+ !isCodePointBoundary(snapshot.body, parsed.offset)
744
+ ) {
745
+ return {
746
+ success: false,
747
+ output: '',
748
+ error: `The continuation cursor for "${input.name}" is stale or invalid. Call skill again without a cursor to read the current instructions.`,
749
+ }
750
+ }
751
+ start = parsed.offset
752
+ }
753
+
754
+ // Compiled before paging so the notice can say what the grant is, and
755
+ // committed only after paging succeeded: a load that fails here gave
756
+ // the model no instructions, so it must not have approved anything.
757
+ // Idempotent: a continuation call grants the same entries again, and
758
+ // the turn's set keeps one copy.
759
+ let grant: ReturnType<NonNullable<typeof context.grantSkillTools>> | undefined
760
+ if (allowed !== undefined && allowed.length > 0 && context.grantSkillTools) {
761
+ grant = context.grantSkillTools({
762
+ skill: skill.metadata.name,
763
+ allowedTools: allowed,
764
+ ...(snapshot.skillDirectory ? { skillDirectory: snapshot.skillDirectory } : {}),
765
+ })
766
+ }
767
+ const notice =
768
+ (hooksPlan?.notice ? `\n\n[${hooksPlan.notice}]` : '') +
769
+ grantNotice(allowed, grant, context.grantSkillTools !== undefined)
770
+ const page = pageSkillBody({
771
+ snapshot:
772
+ start === 0 && argsLine
773
+ ? { ...snapshot, header: argsLine + snapshot.header }
774
+ : snapshot,
775
+ digest,
776
+ start,
777
+ notice,
778
+ maxChars: context.maxToolOutputChars,
779
+ })
780
+ if (!page) {
573
781
  return {
574
782
  success: false,
575
783
  output: '',
576
- error: `The continuation cursor for "${input.name}" is stale or invalid. Call skill again without a cursor to read the current instructions.`,
784
+ error: `The model-visible tool-output budget is too small to read "${input.name}" safely. Increase maxToolOutputChars and retry.`,
785
+ }
786
+ }
787
+ grant?.commit()
788
+ // Live only now that the instructions were delivered, like the grant (a skill
789
+ // that holds commands attached them before it ran them).
790
+ delivered = true
791
+ if (attachedEarly === undefined) hooksPlan?.attach()
792
+ // Kept with the conversation, so a host that continues it later can
793
+ // attach the same hooks again. Once, on the first page of a load.
794
+ let output = page.output
795
+ if (hooksPlan?.resumable === true && start === 0 && skill.dirPath !== undefined) {
796
+ const kept = context.recordSkillHooks
797
+ ? await context
798
+ .recordSkillHooks({
799
+ skill: skill.metadata.name,
800
+ directory: skill.dirPath,
801
+ grantsWithheld: hooksPlan.withholdGrants,
802
+ ...(context.toolUseId !== undefined ? { toolCallId: context.toolUseId } : {}),
803
+ })
804
+ .catch(() => false)
805
+ : false
806
+ if (!kept) {
807
+ output += `\n\n[${SKILL_HOOKS_NOT_KEPT}]`
577
808
  }
578
809
  }
579
- start = parsed.offset
580
- }
581
810
 
582
- // Compiled before paging so the notice can say what the grant is, and
583
- // committed only after paging succeeded: a load that fails here gave
584
- // the model no instructions, so it must not have approved anything.
585
- // Idempotent: a continuation call grants the same entries again, and
586
- // the turn's set keeps one copy.
587
- let grant: ReturnType<NonNullable<typeof context.grantSkillTools>> | undefined
588
- if (allowed !== undefined && allowed.length > 0 && context.grantSkillTools) {
589
- grant = context.grantSkillTools({
590
- skill: skill.metadata.name,
591
- allowedTools: allowed,
592
- ...(snapshot.skillDirectory ? { skillDirectory: snapshot.skillDirectory } : {}),
593
- })
594
- }
595
- const notice =
596
- (hooksPlan?.notice ? `\n\n[${hooksPlan.notice}]` : '') +
597
- grantNotice(allowed, grant, context.grantSkillTools !== undefined)
598
- const page = pageSkillBody({
599
- snapshot:
600
- start === 0 && argsLine ? { ...snapshot, header: argsLine + snapshot.header } : snapshot,
601
- digest,
602
- start,
603
- notice,
604
- maxChars: context.maxToolOutputChars,
605
- })
606
- if (!page) {
607
811
  return {
608
- success: false,
609
- output: '',
610
- error: `The model-visible tool-output budget is too small to read "${input.name}" safely. Increase maxToolOutputChars and retry.`,
611
- }
612
- }
613
- grant?.commit()
614
- // Live only now that the instructions were delivered, like the grant.
615
- hooksPlan?.attach()
616
- // Kept with the conversation, so a host that continues it later can
617
- // attach the same hooks again. Once, on the first page of a load.
618
- let output = page.output
619
- if (hooksPlan?.resumable === true && start === 0 && skill.dirPath !== undefined) {
620
- const kept = context.recordSkillHooks
621
- ? await context
622
- .recordSkillHooks({
623
- skill: skill.metadata.name,
624
- directory: skill.dirPath,
625
- grantsWithheld: hooksPlan.withholdGrants,
626
- ...(context.toolUseId !== undefined ? { toolCallId: context.toolUseId } : {}),
627
- })
628
- .catch(() => false)
629
- : false
630
- if (!kept) {
631
- output += `\n\n[${SKILL_HOOKS_NOT_KEPT}]`
812
+ success: true,
813
+ output,
814
+ data: {
815
+ skill: skill.metadata.name,
816
+ ...(modelDirectory === undefined ? {} : { directory: modelDirectory }),
817
+ ...(allowed === undefined ? {} : { allowedTools: allowed }),
818
+ ...(grant ? { granted: grant.granted, ignored: grant.ignored } : {}),
819
+ ...(page.nextCursor === undefined ? {} : { nextCursor: page.nextCursor }),
820
+ },
632
821
  }
633
- }
634
-
635
- return {
636
- success: true,
637
- output,
638
- data: {
639
- skill: skill.metadata.name,
640
- ...(modelDirectory === undefined ? {} : { directory: modelDirectory }),
641
- ...(allowed === undefined ? {} : { allowedTools: allowed }),
642
- ...(grant ? { granted: grant.granted, ignored: grant.ignored } : {}),
643
- ...(page.nextCursor === undefined ? {} : { nextCursor: page.nextCursor }),
644
- },
822
+ } finally {
823
+ if (!delivered) attachedEarly?.remove()
645
824
  }
646
825
  },
647
826
  })
@@ -651,6 +830,19 @@ export function createSkillTool(options: SkillToolOptions = {}) {
651
830
  const SKILL_HOOKS_NOT_KEPT =
652
831
  "This conversation could not keep a record of this skill's hooks, so if it is continued later they will not be attached again: load the skill again then."
653
832
 
833
+ /**
834
+ * What a skill's `allowed-tools` may pre-approve, for its own commands and its
835
+ * grant alike: nothing when the host withheld the pre-approval (a hook that
836
+ * guards its work could not be loaded, or hooks cannot be attached here). One
837
+ * decision, for the inline load and the delegated one.
838
+ */
839
+ function grantedTools(
840
+ skill: { readonly metadata: { readonly allowedTools?: string } },
841
+ plan: SkillHooksPlan | undefined,
842
+ ): readonly string[] | undefined {
843
+ return plan?.withholdGrants ? undefined : parseAllowedTools(skill.metadata.allowedTools)
844
+ }
845
+
654
846
  /**
655
847
  * What the host says of the hooks a skill carries, or `undefined` for a skill
656
848
  * that carries none. A registry that cannot read hooks answers with a plan
@@ -785,9 +977,13 @@ async function runForkedSkill(input: {
785
977
  readonly dispatch: NonNullable<ToolContext['dispatchTool']>
786
978
  /** The skill's hooks, made live for the delegated agent's run only. */
787
979
  readonly hooks?: SkillHooksPlan
980
+ /** The prompt the hooks are bound to, told to the host when they attach. */
981
+ readonly hooksPrompt?: string
788
982
  }) {
789
983
  const { metadata } = input.skill
790
- const attached = input.hooks?.attach()
984
+ const attached = input.hooks?.attach(
985
+ input.hooksPrompt !== undefined ? { prompt: input.hooksPrompt } : undefined,
986
+ )
791
987
  let ended = false
792
988
  const end = (): void => {
793
989
  if (ended) return
@@ -4,6 +4,7 @@ import type { ToolDefinition } from '../../types/tool/index.js'
4
4
  import { asTaskId } from '../../utils/id.js'
5
5
  import { defineTool } from '../defineTool.js'
6
6
  import type { TaskToolScope } from './index.js'
7
+ import { taskNumbers } from './number.js'
7
8
  import { presentTaskCreateCall, presentTaskCreateResult } from './present.js'
8
9
 
9
10
  export function buildTaskCreateTool(
@@ -52,10 +53,18 @@ export function buildTaskCreateTool(
52
53
  metadata,
53
54
  })
54
55
 
56
+ const number = (await taskNumbers(taskStore)).get(task.id)
57
+ const named = number === undefined ? `${task.id}` : `#${number} (id ${task.id})`
55
58
  return {
56
59
  success: true,
57
- output: `Task created: ${task.id} — "${subject}"${owner ? ` [owner: ${owner}]` : ''}`,
58
- data: { id: task.id, subject: task.subject, status: task.status, owner: task.owner },
60
+ output: `Task created: ${named} — "${subject}"${owner ? ` [owner: ${owner}]` : ''}`,
61
+ data: {
62
+ id: task.id,
63
+ ...(number === undefined ? {} : { number }),
64
+ subject: task.subject,
65
+ status: task.status,
66
+ owner: task.owner,
67
+ },
59
68
  }
60
69
  },
61
70
  })
@@ -0,0 +1,53 @@
1
+ import { z } from 'zod'
2
+ import type { ClaimableTaskStore } from '../../store/task/file.js'
3
+ import type { ToolDefinition } from '../../types/tool/index.js'
4
+ import { asTaskId } from '../../utils/id.js'
5
+ import { defineTool } from '../defineTool.js'
6
+ import { taskNumbers } from './number.js'
7
+
8
+ /**
9
+ * Read one task in full: its description, owner and what it waits on. Only for a list several
10
+ * sessions share, where a teammate reads a task before it takes it.
11
+ */
12
+ export function buildTaskGetTool(taskStore: ClaimableTaskStore): ToolDefinition {
13
+ return defineTool({
14
+ name: 'task_get',
15
+ description:
16
+ 'Read one task in full: subject, description, status, owner, what it blocks and what blocks it. Read a task before you start it. A blocker only stops a task until that blocker is completed.',
17
+ inputSchema: z.object({
18
+ id: z.string().describe('Task ID'),
19
+ }),
20
+ category: 'custom',
21
+ permissions: [],
22
+ readOnly: true,
23
+ destructive: false,
24
+ concurrencySafe: true,
25
+ async execute({ id }) {
26
+ const task = await taskStore.get(asTaskId(id))
27
+ if (!task) return { success: false, output: `Task ${id} not found` }
28
+ const waiting = await taskStore.unresolvedBlockers(task)
29
+ const numbers = await taskNumbers(taskStore)
30
+ const number = numbers.get(task.id)
31
+ const data = {
32
+ id: task.id,
33
+ ...(number === undefined ? {} : { number }),
34
+ subject: task.subject,
35
+ description: task.description ?? null,
36
+ status: task.status,
37
+ owner: task.owner ?? null,
38
+ blocks: task.blocks,
39
+ blockedBy: task.blockedBy,
40
+ waitingOn: waiting,
41
+ activeForm: task.activeForm ?? null,
42
+ metadata: task.metadata ?? null,
43
+ }
44
+ const lines = [
45
+ `${number === undefined ? '' : `#${number} `}${task.subject} [${task.status}]${task.owner ? ` owner: ${task.owner}` : ''}`,
46
+ ...(task.description ? [task.description] : []),
47
+ ...(waiting.length > 0 ? [`Waiting on: ${waiting.join(', ')}`] : []),
48
+ ...(task.blocks.length > 0 ? [`Blocks: ${task.blocks.join(', ')}`] : []),
49
+ ]
50
+ return { success: true, output: lines.join('\n'), data }
51
+ },
52
+ })
53
+ }
@@ -1,7 +1,9 @@
1
+ import { isClaimableTaskStore } from '../../store/task/file.js'
1
2
  import type { SessionId, TurnId } from '../../types/ids/index.js'
2
3
  import type { TaskStore } from '../../types/task/index.js'
3
4
  import type { ToolDefinition } from '../../types/tool/index.js'
4
5
  import { buildTaskCreateTool } from './create.js'
6
+ import { buildTaskGetTool } from './get.js'
5
7
  import { buildTaskListTool } from './list.js'
6
8
  import { buildTaskUpdateTool } from './update.js'
7
9
 
@@ -18,17 +20,27 @@ export interface TaskToolScope {
18
20
  * time it first started. Absent: the time the tools were built.
19
21
  */
20
22
  readonly turnStartedAt?: number
23
+ /**
24
+ * The member the tools act for when the list is shared by a team: the name that moving a task to
25
+ * in_progress claims it under. Ignored for a store only this session uses.
26
+ */
27
+ readonly member?: string
21
28
  }
22
29
 
23
30
  export function buildTaskTools(taskStore: TaskStore, scope: TaskToolScope): ToolDefinition[] {
24
31
  const resolved = { ...scope, turnStartedAt: scope.turnStartedAt ?? Date.now() }
25
- return [
32
+ const tools = [
26
33
  buildTaskCreateTool(taskStore, resolved),
27
- buildTaskUpdateTool(taskStore),
34
+ buildTaskUpdateTool(taskStore, resolved),
28
35
  buildTaskListTool(taskStore, resolved),
29
36
  ]
37
+ // A list that several sessions share also lets a task be read in full.
38
+ if (isClaimableTaskStore(taskStore)) tools.push(buildTaskGetTool(taskStore))
39
+ return tools
30
40
  }
31
41
 
32
42
  export { buildTaskCreateTool } from './create.js'
43
+ export { buildTaskGetTool } from './get.js'
33
44
  export { buildTaskUpdateTool } from './update.js'
34
45
  export { buildTaskListTool } from './list.js'
46
+ export { plainTaskReceipt } from './number.js'
@@ -1,9 +1,11 @@
1
1
  import { z } from 'zod'
2
2
  import { selectTaskContext } from '../../store/task/context.js'
3
+ import { isClaimableTaskStore } from '../../store/task/file.js'
3
4
  import { type TaskStore, isTerminalTaskStatus } from '../../types/task/index.js'
4
5
  import type { ToolDefinition } from '../../types/tool/index.js'
5
6
  import { defineTool } from '../defineTool.js'
6
7
  import type { TaskToolScope } from './index.js'
8
+ import { taskNumbers } from './number.js'
7
9
  import { countTasks, presentTaskListCall, presentTaskListResult } from './present.js'
8
10
 
9
11
  export function buildTaskListTool(
@@ -26,16 +28,22 @@ export function buildTaskListTool(
26
28
  const all = await taskStore.list({ sessionId: scope.sessionId })
27
29
  // Blockers resolve against every task of the session, shown or not: a
28
30
  // blocker closed in an earlier turn is resolved, not unknown.
31
+ // A list several sessions share is shown whole, and a blocker only resolves by completing.
32
+ const shared = isClaimableTaskStore(taskStore)
29
33
  const terminalIds = new Set(
30
- all.filter((t) => isTerminalTaskStatus(t.status)).map((t) => t.id),
34
+ all
35
+ .filter((t) => (shared ? t.status === 'completed' : isTerminalTaskStatus(t.status)))
36
+ .map((t) => t.id),
31
37
  )
32
- const tasks = selectTaskContext(all, scope)
38
+ const tasks = shared ? all : selectTaskContext(all, scope)
33
39
 
40
+ const numbers = await taskNumbers(taskStore)
34
41
  const summary = tasks.map((task) => {
35
42
  const unresolvedBlockers = task.blockedBy.filter((bid) => !terminalIds.has(bid))
36
43
 
37
44
  return {
38
45
  id: task.id,
46
+ ...(numbers.has(task.id) ? { number: numbers.get(task.id) } : {}),
39
47
  subject: task.subject,
40
48
  status: task.status,
41
49
  owner: task.owner ?? null,
@@ -0,0 +1,32 @@
1
+ import { isClaimableTaskStore } from '../../store/task/file.js'
2
+ import type { TaskStore } from '../../types/task/index.js'
3
+
4
+ /**
5
+ * The number a task of a shared (team) list is shown under: its place in the list, lowest id first,
6
+ * from 1. A team's screens say `#2`, not a UUID, and this is the same count. A list only one session
7
+ * uses has no numbers; there the id stays the only handle.
8
+ */
9
+ export async function taskNumbers(store: TaskStore): Promise<ReadonlyMap<string, number>> {
10
+ if (!isClaimableTaskStore(store)) return new Map()
11
+ const tasks = await store.list()
12
+ const ids = tasks.map((task) => String(task.id)).sort(byId)
13
+ return new Map(ids.map((id, index) => [id, index + 1]))
14
+ }
15
+
16
+ function byId(a: string, b: string): number {
17
+ const left = Number(a)
18
+ const right = Number(b)
19
+ if (Number.isFinite(left) && Number.isFinite(right) && left !== right) return left - right
20
+ return a < b ? -1 : a > b ? 1 : 0
21
+ }
22
+
23
+ /** The id the model needs, set apart so a screen can leave it out. */
24
+ const ID_TAIL = /^(Task (?:created: )?#\d+) \(id [^)]*\)/
25
+
26
+ /**
27
+ * A task tool's receipt as a person reads it: the handle the model needs to call the next tool is
28
+ * dropped where the receipt already names the task by its number.
29
+ */
30
+ export function plainTaskReceipt(output: string): string {
31
+ return output.replace(ID_TAIL, '$1')
32
+ }