@namzu/sdk 64.0.0 → 64.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 (132) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/agents/file-definitions.d.ts +10 -0
  3. package/dist/agents/file-definitions.d.ts.map +1 -1
  4. package/dist/agents/file-definitions.js +10 -2
  5. package/dist/agents/file-definitions.js.map +1 -1
  6. package/dist/plugin/file-change-hooks.d.ts +53 -0
  7. package/dist/plugin/file-change-hooks.d.ts.map +1 -0
  8. package/dist/plugin/file-change-hooks.js +111 -0
  9. package/dist/plugin/file-change-hooks.js.map +1 -0
  10. package/dist/plugin/file-change-watch.d.ts +111 -0
  11. package/dist/plugin/file-change-watch.d.ts.map +1 -0
  12. package/dist/plugin/file-change-watch.js +324 -0
  13. package/dist/plugin/file-change-watch.js.map +1 -0
  14. package/dist/plugin/index.d.ts +10 -1
  15. package/dist/plugin/index.d.ts.map +1 -1
  16. package/dist/plugin/index.js +7 -1
  17. package/dist/plugin/index.js.map +1 -1
  18. package/dist/plugin/lifecycle.d.ts +60 -1
  19. package/dist/plugin/lifecycle.d.ts.map +1 -1
  20. package/dist/plugin/lifecycle.js +118 -7
  21. package/dist/plugin/lifecycle.js.map +1 -1
  22. package/dist/plugin/loader.d.ts.map +1 -1
  23. package/dist/plugin/loader.js +24 -1
  24. package/dist/plugin/loader.js.map +1 -1
  25. package/dist/plugin/session-hook-env.d.ts +140 -0
  26. package/dist/plugin/session-hook-env.d.ts.map +1 -0
  27. package/dist/plugin/session-hook-env.js +458 -0
  28. package/dist/plugin/session-hook-env.js.map +1 -0
  29. package/dist/plugin/shell-hook-env.d.ts +107 -0
  30. package/dist/plugin/shell-hook-env.d.ts.map +1 -0
  31. package/dist/plugin/shell-hook-env.js +272 -0
  32. package/dist/plugin/shell-hook-env.js.map +1 -0
  33. package/dist/plugin/shell-hook.d.ts +105 -2
  34. package/dist/plugin/shell-hook.d.ts.map +1 -1
  35. package/dist/plugin/shell-hook.js +282 -24
  36. package/dist/plugin/shell-hook.js.map +1 -1
  37. package/dist/plugin/worktree-hook-answer.d.ts +26 -0
  38. package/dist/plugin/worktree-hook-answer.d.ts.map +1 -0
  39. package/dist/plugin/worktree-hook-answer.js +132 -0
  40. package/dist/plugin/worktree-hook-answer.js.map +1 -0
  41. package/dist/public-runtime.d.ts +4 -4
  42. package/dist/public-runtime.d.ts.map +1 -1
  43. package/dist/public-runtime.js +4 -4
  44. package/dist/public-runtime.js.map +1 -1
  45. package/dist/public-types.d.ts +7 -1
  46. package/dist/public-types.d.ts.map +1 -1
  47. package/dist/runtime/query/executor.d.ts +8 -1
  48. package/dist/runtime/query/executor.d.ts.map +1 -1
  49. package/dist/runtime/query/executor.js +4 -0
  50. package/dist/runtime/query/executor.js.map +1 -1
  51. package/dist/runtime/query/index.d.ts +9 -0
  52. package/dist/runtime/query/index.d.ts.map +1 -1
  53. package/dist/runtime/query/index.js +20 -0
  54. package/dist/runtime/query/index.js.map +1 -1
  55. package/dist/runtime/query/tooling.d.ts +8 -1
  56. package/dist/runtime/query/tooling.d.ts.map +1 -1
  57. package/dist/runtime/query/tooling.js +6 -0
  58. package/dist/runtime/query/tooling.js.map +1 -1
  59. package/dist/session/workspace/hooked-driver.d.ts +72 -0
  60. package/dist/session/workspace/hooked-driver.d.ts.map +1 -0
  61. package/dist/session/workspace/hooked-driver.js +204 -0
  62. package/dist/session/workspace/hooked-driver.js.map +1 -0
  63. package/dist/session/workspace/index.d.ts +2 -0
  64. package/dist/session/workspace/index.d.ts.map +1 -1
  65. package/dist/session/workspace/index.js +1 -0
  66. package/dist/session/workspace/index.js.map +1 -1
  67. package/dist/skills/index.d.ts +1 -1
  68. package/dist/skills/index.d.ts.map +1 -1
  69. package/dist/skills/index.js +1 -1
  70. package/dist/skills/index.js.map +1 -1
  71. package/dist/skills/loader.d.ts +22 -0
  72. package/dist/skills/loader.d.ts.map +1 -1
  73. package/dist/skills/loader.js +41 -0
  74. package/dist/skills/loader.js.map +1 -1
  75. package/dist/tools/builtins/bash-cwd.d.ts +6 -1
  76. package/dist/tools/builtins/bash-cwd.d.ts.map +1 -1
  77. package/dist/tools/builtins/bash-cwd.js +27 -2
  78. package/dist/tools/builtins/bash-cwd.js.map +1 -1
  79. package/dist/tools/builtins/bash.js +1 -1
  80. package/dist/tools/builtins/bash.js.map +1 -1
  81. package/dist/tools/builtins/skill.d.ts.map +1 -1
  82. package/dist/tools/builtins/skill.js +114 -17
  83. package/dist/tools/builtins/skill.js.map +1 -1
  84. package/dist/types/plugin/index.d.ts +75 -2
  85. package/dist/types/plugin/index.d.ts.map +1 -1
  86. package/dist/types/plugin/index.js +5 -0
  87. package/dist/types/plugin/index.js.map +1 -1
  88. package/dist/types/session/records.d.ts +73 -1
  89. package/dist/types/session/records.d.ts.map +1 -1
  90. package/dist/types/session/records.js +25 -0
  91. package/dist/types/session/records.js.map +1 -1
  92. package/dist/types/skills/index.d.ts +8 -0
  93. package/dist/types/skills/index.d.ts.map +1 -1
  94. package/dist/types/skills/index.js.map +1 -1
  95. package/dist/types/tool/index.d.ts +97 -0
  96. package/dist/types/tool/index.d.ts.map +1 -1
  97. package/dist/types/tool/index.js.map +1 -1
  98. package/dist/types/workspace/ref.d.ts +6 -0
  99. package/dist/types/workspace/ref.d.ts.map +1 -1
  100. package/dist/utils/frontmatter.d.ts +16 -0
  101. package/dist/utils/frontmatter.d.ts.map +1 -1
  102. package/dist/utils/frontmatter.js +31 -1
  103. package/dist/utils/frontmatter.js.map +1 -1
  104. package/package.json +1 -1
  105. package/src/agents/file-definitions.ts +17 -2
  106. package/src/plugin/file-change-hooks.ts +131 -0
  107. package/src/plugin/file-change-watch.ts +367 -0
  108. package/src/plugin/index.ts +39 -1
  109. package/src/plugin/lifecycle.ts +162 -8
  110. package/src/plugin/loader.ts +22 -1
  111. package/src/plugin/session-hook-env.ts +475 -0
  112. package/src/plugin/shell-hook-env.ts +335 -0
  113. package/src/plugin/shell-hook.ts +416 -24
  114. package/src/plugin/worktree-hook-answer.ts +142 -0
  115. package/src/public-runtime.ts +33 -0
  116. package/src/public-types.ts +20 -1
  117. package/src/runtime/query/executor.ts +12 -0
  118. package/src/runtime/query/index.ts +28 -0
  119. package/src/runtime/query/tooling.ts +19 -1
  120. package/src/session/workspace/hooked-driver.ts +272 -0
  121. package/src/session/workspace/index.ts +7 -0
  122. package/src/skills/index.ts +3 -0
  123. package/src/skills/loader.ts +47 -0
  124. package/src/tools/builtins/bash-cwd.ts +25 -1
  125. package/src/tools/builtins/bash.ts +1 -1
  126. package/src/tools/builtins/skill.ts +138 -27
  127. package/src/types/plugin/index.ts +84 -1
  128. package/src/types/session/records.ts +28 -0
  129. package/src/types/skills/index.ts +9 -0
  130. package/src/types/tool/index.ts +105 -0
  131. package/src/types/workspace/ref.ts +6 -0
  132. package/src/utils/frontmatter.ts +52 -1
@@ -99,6 +99,8 @@ export interface SkillRegistryRef {
99
99
  model?: string
100
100
  effort?: import('../provider/chat.js').ReasoningEffort
101
101
  background?: boolean
102
+ /** The `hooks` block as the file wrote it; see `SkillMetadata.hooksSource`. */
103
+ hooksSource?: string
102
104
  }
103
105
  body?: string
104
106
  /** The skill's directory, which `${CLAUDE_SKILL_DIR}` in `allowed-tools` names. */
@@ -109,6 +111,85 @@ export interface SkillRegistryRef {
109
111
  >
110
112
  /** Every registered name, for a "did you mean" that names real options. */
111
113
  names(): readonly string[]
114
+ /**
115
+ * Read the hooks a skill carries, without attaching anything.
116
+ *
117
+ * Called by the `skill` tool for a skill whose front matter has a `hooks`
118
+ * block. Hooks are not a thing the kernel reads: the host that runs them
119
+ * answers. The answer says what to tell the model, whether the skill's
120
+ * `allowed-tools` may still be pre-approved, and, as `attach`, the one
121
+ * call that makes the hooks live. `attach` is called only once the skill's
122
+ * instructions have been delivered, like the tool grant's `commit`, and
123
+ * returns a handle that removes exactly what it attached.
124
+ *
125
+ * Absent, a skill that carries hooks loads without them, and without its
126
+ * `allowed-tools` pre-approval: a skill written to run its commands under
127
+ * its own guard must not run them unguarded and pre-approved.
128
+ */
129
+ prepareHooks?(
130
+ skill: {
131
+ readonly name: string
132
+ readonly dirPath?: string
133
+ readonly hooksSource: string
134
+ },
135
+ options: SkillHooksOptions,
136
+ ): SkillHooksPlan
137
+ }
138
+
139
+ /** What a conversation keeps of a skill whose hooks were attached to it; see {@link ToolContext.recordSkillHooks}. */
140
+ export interface SkillHooksRecordFact {
141
+ /** The skill's name. */
142
+ readonly skill: string
143
+ /** The skill's own folder. */
144
+ readonly directory: string
145
+ /** The skill's `allowed-tools` were left unapproved (a hook that guards its work could not be loaded). */
146
+ readonly grantsWithheld: boolean
147
+ /** The `skill` call that loaded it. */
148
+ readonly toolCallId?: string
149
+ }
150
+
151
+ /** What the `skill` tool tells a host's hook reader about the use it is making of a skill. */
152
+ export interface SkillHooksOptions {
153
+ /** The skill runs in a delegated agent: its hooks belong to that agent's run only. */
154
+ readonly forked: boolean
155
+ /**
156
+ * For a forked skill: the prompt the delegated agent is given, so the host
157
+ * can tell that agent from any other that starts at the same time.
158
+ */
159
+ readonly prompt?: string
160
+ /** The session the `skill` tool was called in. */
161
+ readonly sessionId?: string
162
+ }
163
+
164
+ /** What a host decided about the hooks a skill carries; see {@link SkillRegistryRef.prepareHooks}. */
165
+ export interface SkillHooksPlan {
166
+ /** One line for the model, and for the person, about the hooks. Empty when there is nothing to say. */
167
+ readonly notice?: string
168
+ /**
169
+ * The skill's `allowed-tools` must not be pre-approved: some hook that
170
+ * guards its work could not be loaded, or hooks cannot be attached here.
171
+ */
172
+ readonly withholdGrants: boolean
173
+ /**
174
+ * The hooks (or the refusal) belong to the conversation and should come
175
+ * back when it is continued: the `skill` tool keeps a record of the use
176
+ * ({@link ToolContext.recordSkillHooks}) once the instructions were
177
+ * delivered. Absent or false: nothing is kept (a forked skill, whose hooks
178
+ * belong to one run; a skill whose hooks are switched off).
179
+ */
180
+ readonly resumable?: boolean
181
+ /** Make the hooks live. Idempotent for a skill already attached to the conversation. */
182
+ attach(): SkillHooksHandle
183
+ }
184
+
185
+ /** What {@link SkillHooksPlan.attach} gives back. */
186
+ export interface SkillHooksHandle {
187
+ /**
188
+ * For a forked skill: bind the hooks to the delegated agent that is about
189
+ * to start, and end them when it ends. Absent for an inline skill, whose
190
+ * hooks last as long as the conversation.
191
+ */
192
+ readonly remove: () => void
112
193
  }
113
194
 
114
195
  /**
@@ -547,6 +628,19 @@ export interface ToolContext {
547
628
  /** The turn this call belongs to. */
548
629
  turnId: TurnId
549
630
  workingDirectory: string
631
+ /**
632
+ * Called by the shell tool, after a command has finished, when the folder the
633
+ * session's next shell command starts in is a different folder from the one
634
+ * this command started in (it ran `cd`, or was put back at the working
635
+ * directory for leaving the allowed folders). Awaited before the result is
636
+ * returned, so what a host does here is done before the next command. Never
637
+ * called with the same folder twice in a row, and not at all for a command
638
+ * that did not move.
639
+ */
640
+ workingDirectoryChanged?: (change: {
641
+ readonly from: string
642
+ readonly to: string
643
+ }) => Promise<void> | void
550
644
  /**
551
645
  * Directories besides the working directory the file tools may reach,
552
646
  * absolute. A host adds one for a session (`/add-dir`); a sandboxed turn
@@ -791,6 +885,17 @@ export interface ToolContext {
791
885
  readonly commit: () => void
792
886
  }
793
887
 
888
+ /**
889
+ * Keep, in the conversation's own record, that a skill's hooks were attached
890
+ * (or refused) for it, so a host that continues the conversation later can
891
+ * attach them again. Called by the `skill` tool once the instructions were
892
+ * delivered, only for a skill the host's {@link SkillHooksPlan.resumable}
893
+ * names. Resolves `true` when the record was written; `false` (it does not
894
+ * throw) when it could not be, and the tool then says so in its result.
895
+ * Absent outside a turn that has a session log.
896
+ */
897
+ recordSkillHooks?: (fact: SkillHooksRecordFact) => Promise<boolean>
898
+
794
899
  /**
795
900
  * Effective model-visible character cap for this tool result.
796
901
  *
@@ -31,6 +31,12 @@ export interface GitWorktreeBackendMeta {
31
31
  worktreePath: string
32
32
  /** The commit the checkout started on; absent on refs made before it was recorded. */
33
33
  baseCommit?: string
34
+ /**
35
+ * Set when a `worktree_create` hook made the folder. It is the hook's: the
36
+ * kernel never runs its own Git removal on it, it asks the `worktree_remove`
37
+ * hooks and, with none, leaves the folder where it is.
38
+ */
39
+ hookOwned?: true
34
40
  }
35
41
 
36
42
  /**
@@ -157,6 +157,16 @@ export interface FrontmatterOptions {
157
157
  * which is what it meant to everything before it was read.
158
158
  */
159
159
  readonly tolerates?: (key: string) => boolean
160
+ /**
161
+ * Keys whose value is handed back as the text the file wrote, not parsed
162
+ * here: the key's own line and every line under it, up to the next
163
+ * top-level key, in {@link ParsedFrontmatter.rawBlocks}. For a key whose
164
+ * structure this flat reader cannot hold (a `hooks` block is a list of
165
+ * mappings, a list in it) and whose reader is the caller's, which has a
166
+ * real YAML parser. The key is never refused for its shape and never
167
+ * appears in `values`; every other key is read exactly as before.
168
+ */
169
+ readonly raw?: readonly string[]
160
170
  }
161
171
 
162
172
  export interface ParsedFrontmatter {
@@ -174,6 +184,13 @@ export interface ParsedFrontmatter {
174
184
  */
175
185
  readonly values: Readonly<Record<string, FrontmatterValue>>
176
186
 
187
+ /**
188
+ * The text of each key named in {@link FrontmatterOptions.raw} that the
189
+ * file declared, from its key line to the line before the next top-level
190
+ * key. Absent keys are absent.
191
+ */
192
+ readonly rawBlocks: Readonly<Record<string, string>>
193
+
177
194
  /** Everything after the closing fence, trimmed. */
178
195
  readonly body: string
179
196
  }
@@ -230,10 +247,38 @@ export function parseFrontmatter(
230
247
  // The current top-level key is one the caller does not read: its value
231
248
  // and its indented lines are skipped rather than parsed or refused.
232
249
  let skipping = false
250
+ // The caller reads these keys itself: their lines are collected as written.
251
+ const rawKeys = new Set(options.raw ?? [])
252
+ const rawBlocks = new Map<string, string[]>()
253
+ let rawCurrent: string[] | undefined
233
254
 
234
255
  for (const line of frontmatterRaw.split(LINE_SPLIT)) {
256
+ // Blank lines and comments inside a raw block belong to it (a block
257
+ // scalar's blank line is part of its text); they end nothing.
258
+ if (rawCurrent && (!line.trim() || line.trimStart().startsWith('#'))) {
259
+ rawCurrent.push(line)
260
+ continue
261
+ }
235
262
  if (!line.trim() || line.trimStart().startsWith('#')) continue
236
263
 
264
+ if (rawCurrent && (/^\s/.test(line) || /^-(\s|$)/.test(line))) {
265
+ rawCurrent.push(line)
266
+ continue
267
+ }
268
+
269
+ if (!/^\s/.test(line)) {
270
+ rawCurrent = undefined
271
+ const rawColon = line.indexOf(':')
272
+ const rawKey = rawColon === -1 ? '' : line.slice(0, rawColon).trim()
273
+ if (rawKey && rawKeys.has(rawKey)) {
274
+ rawCurrent = [line]
275
+ rawBlocks.set(rawKey, rawCurrent)
276
+ currentKey = rawKey
277
+ skipping = true
278
+ continue
279
+ }
280
+ }
281
+
237
282
  if (/^\s/.test(line)) {
238
283
  if (!currentKey || skipping) continue
239
284
 
@@ -342,7 +387,13 @@ export function parseFrontmatter(
342
387
  values.set(key, { kind: 'mapping', entries: Object.fromEntries(entries) })
343
388
  }
344
389
 
345
- return { values: Object.fromEntries(values), body }
390
+ return {
391
+ values: Object.fromEntries(values),
392
+ rawBlocks: Object.fromEntries(
393
+ [...rawBlocks].map(([key, lines]) => [key, lines.join('\n').replace(/\s+$/, '')]),
394
+ ),
395
+ body,
396
+ }
346
397
  }
347
398
 
348
399
  function normalizeScalar(value: string): string {