@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,16 @@ export interface FrontmatterOptions {
99
99
  * which is what it meant to everything before it was read.
100
100
  */
101
101
  readonly tolerates?: (key: string) => boolean;
102
+ /**
103
+ * Keys whose value is handed back as the text the file wrote, not parsed
104
+ * here: the key's own line and every line under it, up to the next
105
+ * top-level key, in {@link ParsedFrontmatter.rawBlocks}. For a key whose
106
+ * structure this flat reader cannot hold (a `hooks` block is a list of
107
+ * mappings, a list in it) and whose reader is the caller's, which has a
108
+ * real YAML parser. The key is never refused for its shape and never
109
+ * appears in `values`; every other key is read exactly as before.
110
+ */
111
+ readonly raw?: readonly string[];
102
112
  }
103
113
  export interface ParsedFrontmatter {
104
114
  /**
@@ -114,6 +124,12 @@ export interface ParsedFrontmatter {
114
124
  * ```
115
125
  */
116
126
  readonly values: Readonly<Record<string, FrontmatterValue>>;
127
+ /**
128
+ * The text of each key named in {@link FrontmatterOptions.raw} that the
129
+ * file declared, from its key line to the line before the next top-level
130
+ * key. Absent keys are absent.
131
+ */
132
+ readonly rawBlocks: Readonly<Record<string, string>>;
117
133
  /** Everything after the closing fence, trimmed. */
118
134
  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AkB,CAAA;AAExD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,kBAAuB,GAC9B,iBAAiB,CAqLnB"}
@@ -137,9 +137,35 @@ export function parseFrontmatter(raw, source, options = {}) {
137
137
  // The current top-level key is one the caller does not read: its value
138
138
  // and its indented lines are skipped rather than parsed or refused.
139
139
  let skipping = false;
140
+ // The caller reads these keys itself: their lines are collected as written.
141
+ const rawKeys = new Set(options.raw ?? []);
142
+ const rawBlocks = new Map();
143
+ let rawCurrent;
140
144
  for (const line of frontmatterRaw.split(LINE_SPLIT)) {
145
+ // Blank lines and comments inside a raw block belong to it (a block
146
+ // scalar's blank line is part of its text); they end nothing.
147
+ if (rawCurrent && (!line.trim() || line.trimStart().startsWith('#'))) {
148
+ rawCurrent.push(line);
149
+ continue;
150
+ }
141
151
  if (!line.trim() || line.trimStart().startsWith('#'))
142
152
  continue;
153
+ if (rawCurrent && (/^\s/.test(line) || /^-(\s|$)/.test(line))) {
154
+ rawCurrent.push(line);
155
+ continue;
156
+ }
157
+ if (!/^\s/.test(line)) {
158
+ rawCurrent = undefined;
159
+ const rawColon = line.indexOf(':');
160
+ const rawKey = rawColon === -1 ? '' : line.slice(0, rawColon).trim();
161
+ if (rawKey && rawKeys.has(rawKey)) {
162
+ rawCurrent = [line];
163
+ rawBlocks.set(rawKey, rawCurrent);
164
+ currentKey = rawKey;
165
+ skipping = true;
166
+ continue;
167
+ }
168
+ }
143
169
  if (/^\s/.test(line)) {
144
170
  if (!currentKey || skipping)
145
171
  continue;
@@ -240,7 +266,11 @@ export function parseFrontmatter(raw, source, options = {}) {
240
266
  for (const [key, entries] of blocks) {
241
267
  values.set(key, { kind: 'mapping', entries: Object.fromEntries(entries) });
242
268
  }
243
- return { values: Object.fromEntries(values), body };
269
+ return {
270
+ values: Object.fromEntries(values),
271
+ rawBlocks: Object.fromEntries([...rawBlocks].map(([key, lines]) => [key, lines.join('\n').replace(/\s+$/, '')])),
272
+ body,
273
+ };
244
274
  }
245
275
  function normalizeScalar(value) {
246
276
  return value
@@ -1 +1 @@
1
- {"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../../src/utils/frontmatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,iBAAiB,GAAG,iBAAiB,CAAA;AAE3C,MAAM,qBAAqB,GAAG,KAAK,CAAA;AAEnC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,GAAG,YAAY,CAAA;AAE/B;;;;;;;;;;;;;GAaG;AACH,MAAM,gBAAgB,GAAG;IACxB,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,6BAA6B,EAAE;IAClE,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,4BAA4B,EAAE;IAC3D,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,2BAA2B,EAAE;CACjD,CAAA;AAkFV;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAC/B,GAAW,EACX,MAAc,EACd,UAA8B,EAAE;IAEhC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAA;IAC7C,MAAM,OAAO,GAAG,GAAG,CAAC,SAAS,EAAE,CAAA;IAE/B,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,qBAAqB,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,0BAA0B,CAAC,CAAA;IACrD,CAAC;IAED,MAAM,OAAO,GAAG,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAA;IACnF,IAAI,CAAC,OAAO,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,GAAG,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AAC,KAAa;IACrC,OAAO,KAAK;SACV,IAAI,EAAE;SACN,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;SAC3B,IAAI,EAAE,CAAA;AACT,CAAC;AAED,SAAS,oBAAoB,CAAC,GAAW,EAAE,KAAa,EAAE,MAAc;IACvE,KAAK,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,gBAAgB,EAAE,CAAC;QAClD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,SAAQ;QAClC,MAAM,IAAI,KAAK,CACd,GAAG,MAAM,MAAM,GAAG,UAAU,IAAI,oHAAoH,GAAG,wBAAwB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CACvM,CAAA;IACF,CAAC;AACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@namzu/sdk",
3
- "version": "64.0.0",
3
+ "version": "64.2.0",
4
4
  "description": "Open-source AI kernel for TypeScript: runs an agent the way an operating system runs a process, with an identity and a budget, scheduled tool calls and checkpointed turns.",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "engines": {
@@ -27,6 +27,10 @@
27
27
  * You review changes for this repository. Cite file:line for every finding …
28
28
  * ```
29
29
  *
30
+ * `hooks` is a block of hook entries in either shape a config file takes (see
31
+ * `AgentFileDefinition.hooksSource`); the kernel keeps its text and the host
32
+ * reads it.
33
+ *
30
34
  * `tools`, `disallowedTools` and `skills` are each one comma-separated line: this kernel's frontmatter reader
31
35
  * refuses block lists and flow sequences by design, so there is no other
32
36
  * form to accept.
@@ -92,6 +96,7 @@ export const AGENT_FILE_KEYS: readonly string[] = Object.freeze([
92
96
  'skills',
93
97
  'permissionMode',
94
98
  'readOnly',
99
+ 'hooks',
95
100
  ])
96
101
 
97
102
  export interface AgentFileDefinition {
@@ -121,6 +126,12 @@ export interface AgentFileDefinition {
121
126
  */
122
127
  readonly permissionMode?: string
123
128
  readonly readOnly: boolean
129
+ /**
130
+ * The text of the file's `hooks` key, as written (the key's own line and the
131
+ * lines under it), for the host to read with a YAML reader: the frontmatter
132
+ * reader here cannot hold a list of mappings. The kernel only keeps it.
133
+ */
134
+ readonly hooksSource?: string
124
135
  readonly path: string
125
136
  /** The host's label for the root this file came from (`user`, `project`, …). */
126
137
  readonly source: string
@@ -224,14 +235,14 @@ export function parseAgentMarkdown(
224
235
  }
225
236
  let parsed: ReturnType<typeof parseFrontmatter>
226
237
  try {
227
- parsed = parseFrontmatter(raw, path)
238
+ parsed = parseFrontmatter(raw, path, { raw: ['hooks'] })
228
239
  } catch (error) {
229
240
  return {
230
241
  path,
231
242
  reason: `frontmatter did not parse: ${error instanceof Error ? error.message : String(error)}`,
232
243
  }
233
244
  }
234
- const { values, body } = parsed
245
+ const { values, body, rawBlocks } = parsed
235
246
 
236
247
  const name = scalar(values.name)
237
248
  if (name === undefined) return { path, reason: 'has no `name:` in its frontmatter' }
@@ -331,6 +342,9 @@ export function parseAgentMarkdown(
331
342
  readOnly = flag === 'true'
332
343
  }
333
344
 
345
+ const hooksText = Object.hasOwn(rawBlocks, 'hooks') ? rawBlocks.hooks : undefined
346
+ const hooksSource = hooksText !== undefined && hooksText.trim() !== '' ? hooksText : undefined
347
+
334
348
  const trimmed = body.trim()
335
349
  if (trimmed.length === 0) {
336
350
  return { path, reason: "has an empty body; the body is the agent's system prompt" }
@@ -354,6 +368,7 @@ export function parseAgentMarkdown(
354
368
  ...(preloaded.list ? { skills: preloaded.list } : {}),
355
369
  ...(permissionMode ? { permissionMode } : {}),
356
370
  readOnly,
371
+ ...(hooksSource !== undefined ? { hooksSource } : {}),
357
372
  path,
358
373
  source,
359
374
  }
@@ -0,0 +1,131 @@
1
+ /**
2
+ * `file_changed` events for a session: the watcher and what it fires.
3
+ *
4
+ * The files watched are the ones named in the matchers of the `file_changed`
5
+ * hooks the host attached, plus the list hooks have handed back with
6
+ * `hookSpecificOutput.watchPaths`. A new list from any hook of `session_start`,
7
+ * `file_changed` or `cwd_changed` replaces the one handed back before; the
8
+ * matcher paths stay. With neither, no watcher exists.
9
+ *
10
+ * A hook of `file_changed` cannot refuse anything and gives the model nothing:
11
+ * what it may answer is a line for the person (`systemMessage`, passed to
12
+ * `onNotice`) and the next list of paths.
13
+ */
14
+
15
+ import type { SessionId } from '../types/ids/index.js'
16
+ import type { PluginHookResult } from '../types/plugin/index.js'
17
+ import { FileChangeWatcher, type FileChangeWatcherOptions } from './file-change-watch.js'
18
+ import type { PluginLifecycleManager } from './lifecycle.js'
19
+
20
+ export interface FileChangeHooksOptions {
21
+ readonly manager: Pick<PluginLifecycleManager, 'executeHooks'> &
22
+ Partial<Pick<PluginLifecycleManager, 'listHooks' | 'onHooksChanged'>>
23
+ /** Relative paths are under this folder. */
24
+ readonly cwd: string
25
+ /** The session now; asked at each event, because a host's session can change. */
26
+ readonly sessionId: () => string
27
+ /**
28
+ * Paths the `file_changed` matchers name, from the host's hook configuration.
29
+ * The matchers of hooks attached to the manager (a plugin's, a skill's, an
30
+ * agent file's) are read from it and added, now and whenever they change.
31
+ */
32
+ readonly matcherPaths: readonly string[]
33
+ /** A line a hook gave for the person. */
34
+ readonly onNotice?: (line: string) => void
35
+ /** A watch that failed or was cut short, once per distinct sentence. */
36
+ readonly onProblem?: (line: string) => void
37
+ /** Seams for tests. */
38
+ readonly watcher?: Pick<
39
+ FileChangeWatcherOptions,
40
+ 'settleMs' | 'maxPaths' | 'watchDirectory' | 'exists'
41
+ >
42
+ }
43
+
44
+ /** The paths a set of answers hand back: the union, or `undefined` when no answer carried the field. */
45
+ export function watchPathsOf(results: readonly PluginHookResult[]): readonly string[] | undefined {
46
+ let seen = false
47
+ const paths: string[] = []
48
+ for (const result of results) {
49
+ if (!('watchPaths' in result) || result.watchPaths === undefined) continue
50
+ seen = true
51
+ for (const path of result.watchPaths) if (!paths.includes(path)) paths.push(path)
52
+ }
53
+ return seen ? paths : undefined
54
+ }
55
+
56
+ export class FileChangeHooks {
57
+ private handedBack: readonly string[] = []
58
+ private readonly watcher: FileChangeWatcher
59
+ private closed = false
60
+ private readonly stopListening: (() => void) | undefined
61
+
62
+ constructor(private readonly options: FileChangeHooksOptions) {
63
+ this.watcher = new FileChangeWatcher({
64
+ ...options.watcher,
65
+ ...(options.onProblem ? { onProblem: options.onProblem } : {}),
66
+ onChange: (change) => {
67
+ void this.fire(change.path, change.change)
68
+ },
69
+ })
70
+ this.stopListening = options.manager.onHooksChanged?.(() => {
71
+ if (!this.closed) this.refresh()
72
+ })
73
+ this.refresh()
74
+ }
75
+
76
+ /** The files watched now, absolute. */
77
+ get watching(): readonly string[] {
78
+ return this.watcher.watching
79
+ }
80
+
81
+ /** What the answers of a `session_start`, `file_changed` or `cwd_changed` run said: notices and a new list. */
82
+ absorb(results: readonly PluginHookResult[]): void {
83
+ if (this.closed) return
84
+ for (const result of results) {
85
+ const notice = 'notice' in result ? result.notice : undefined
86
+ if (notice !== undefined && notice.trim() !== '') this.options.onNotice?.(notice.trim())
87
+ }
88
+ const next = watchPathsOf(results)
89
+ if (next === undefined) return
90
+ this.handedBack = next
91
+ this.refresh()
92
+ }
93
+
94
+ close(): void {
95
+ this.closed = true
96
+ this.stopListening?.()
97
+ this.watcher.close()
98
+ }
99
+
100
+ private refresh(): void {
101
+ const all = [...this.options.matcherPaths]
102
+ for (const hook of this.options.manager.listHooks?.() ?? []) {
103
+ if (hook.event !== 'file_changed') continue
104
+ for (const path of hook.watches ?? []) if (!all.includes(path)) all.push(path)
105
+ }
106
+ for (const path of this.handedBack) if (!all.includes(path)) all.push(path)
107
+ this.watcher.setPaths(all, this.options.cwd)
108
+ }
109
+
110
+ private async fire(path: string, change: 'change' | 'add' | 'unlink'): Promise<void> {
111
+ if (this.closed) return
112
+ // What the hook writes to this very file is not a new change: without
113
+ // this a hook that touches the file it watches would start itself again
114
+ // every half second for as long as the session lives.
115
+ this.watcher.hold(path)
116
+ try {
117
+ const results = await this.options.manager.executeHooks('file_changed', {
118
+ sessionId: this.options.sessionId() as SessionId,
119
+ filePath: path,
120
+ change,
121
+ })
122
+ this.absorb(results)
123
+ } catch (error) {
124
+ this.options.onProblem?.(
125
+ `A file_changed hook could not run for ${path}: ${error instanceof Error ? error.message : String(error)}.`,
126
+ )
127
+ } finally {
128
+ this.watcher.release(path)
129
+ }
130
+ }
131
+ }