@namzu/sdk 63.1.0 → 64.1.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 (200) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/dist/agents/QueryAgent.d.ts.map +1 -1
  3. package/dist/agents/QueryAgent.js +2 -1
  4. package/dist/agents/QueryAgent.js.map +1 -1
  5. package/dist/agents/file-definitions.d.ts +10 -0
  6. package/dist/agents/file-definitions.d.ts.map +1 -1
  7. package/dist/agents/file-definitions.js +10 -2
  8. package/dist/agents/file-definitions.js.map +1 -1
  9. package/dist/compaction/hooks.d.ts +57 -0
  10. package/dist/compaction/hooks.d.ts.map +1 -0
  11. package/dist/compaction/hooks.js +44 -0
  12. package/dist/compaction/hooks.js.map +1 -0
  13. package/dist/compaction/manual.d.ts +9 -0
  14. package/dist/compaction/manual.d.ts.map +1 -1
  15. package/dist/compaction/manual.js +74 -5
  16. package/dist/compaction/manual.js.map +1 -1
  17. package/dist/compaction/model-summary.d.ts +6 -0
  18. package/dist/compaction/model-summary.d.ts.map +1 -1
  19. package/dist/compaction/model-summary.js +13 -3
  20. package/dist/compaction/model-summary.js.map +1 -1
  21. package/dist/compaction/verifier.d.ts +8 -2
  22. package/dist/compaction/verifier.d.ts.map +1 -1
  23. package/dist/compaction/verifier.js +23 -7
  24. package/dist/compaction/verifier.js.map +1 -1
  25. package/dist/plugin/file-change-hooks.d.ts +53 -0
  26. package/dist/plugin/file-change-hooks.d.ts.map +1 -0
  27. package/dist/plugin/file-change-hooks.js +111 -0
  28. package/dist/plugin/file-change-hooks.js.map +1 -0
  29. package/dist/plugin/file-change-watch.d.ts +111 -0
  30. package/dist/plugin/file-change-watch.d.ts.map +1 -0
  31. package/dist/plugin/file-change-watch.js +324 -0
  32. package/dist/plugin/file-change-watch.js.map +1 -0
  33. package/dist/plugin/hook-context.d.ts +16 -0
  34. package/dist/plugin/hook-context.d.ts.map +1 -1
  35. package/dist/plugin/hook-context.js +40 -0
  36. package/dist/plugin/hook-context.js.map +1 -1
  37. package/dist/plugin/index.d.ts +14 -4
  38. package/dist/plugin/index.d.ts.map +1 -1
  39. package/dist/plugin/index.js +10 -3
  40. package/dist/plugin/index.js.map +1 -1
  41. package/dist/plugin/lifecycle.d.ts +60 -1
  42. package/dist/plugin/lifecycle.d.ts.map +1 -1
  43. package/dist/plugin/lifecycle.js +118 -7
  44. package/dist/plugin/lifecycle.js.map +1 -1
  45. package/dist/plugin/loader.d.ts.map +1 -1
  46. package/dist/plugin/loader.js +24 -1
  47. package/dist/plugin/loader.js.map +1 -1
  48. package/dist/plugin/session-hook-env.d.ts +140 -0
  49. package/dist/plugin/session-hook-env.d.ts.map +1 -0
  50. package/dist/plugin/session-hook-env.js +458 -0
  51. package/dist/plugin/session-hook-env.js.map +1 -0
  52. package/dist/plugin/shell-hook-command.d.ts +25 -0
  53. package/dist/plugin/shell-hook-command.d.ts.map +1 -0
  54. package/dist/plugin/shell-hook-command.js +218 -0
  55. package/dist/plugin/shell-hook-command.js.map +1 -0
  56. package/dist/plugin/shell-hook-env.d.ts +107 -0
  57. package/dist/plugin/shell-hook-env.d.ts.map +1 -0
  58. package/dist/plugin/shell-hook-env.js +272 -0
  59. package/dist/plugin/shell-hook-env.js.map +1 -0
  60. package/dist/plugin/shell-hook-tool-names.d.ts +20 -0
  61. package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -0
  62. package/dist/plugin/shell-hook-tool-names.js +43 -0
  63. package/dist/plugin/shell-hook-tool-names.js.map +1 -0
  64. package/dist/plugin/shell-hook.d.ts +167 -22
  65. package/dist/plugin/shell-hook.d.ts.map +1 -1
  66. package/dist/plugin/shell-hook.js +651 -106
  67. package/dist/plugin/shell-hook.js.map +1 -1
  68. package/dist/plugin/worktree-hook-answer.d.ts +26 -0
  69. package/dist/plugin/worktree-hook-answer.d.ts.map +1 -0
  70. package/dist/plugin/worktree-hook-answer.js +132 -0
  71. package/dist/plugin/worktree-hook-answer.js.map +1 -0
  72. package/dist/public-runtime.d.ts +5 -3
  73. package/dist/public-runtime.d.ts.map +1 -1
  74. package/dist/public-runtime.js +4 -3
  75. package/dist/public-runtime.js.map +1 -1
  76. package/dist/public-types.d.ts +9 -2
  77. package/dist/public-types.d.ts.map +1 -1
  78. package/dist/runtime/query/compact-session.d.ts +7 -1
  79. package/dist/runtime/query/compact-session.d.ts.map +1 -1
  80. package/dist/runtime/query/compact-session.js +8 -3
  81. package/dist/runtime/query/compact-session.js.map +1 -1
  82. package/dist/runtime/query/executor/tool-call-admission.d.ts +1 -1
  83. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  84. package/dist/runtime/query/executor/tool-call-admission.js +4 -3
  85. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  86. package/dist/runtime/query/executor.d.ts +5 -0
  87. package/dist/runtime/query/executor.d.ts.map +1 -1
  88. package/dist/runtime/query/executor.js +8 -3
  89. package/dist/runtime/query/executor.js.map +1 -1
  90. package/dist/runtime/query/finalize-turn.d.ts.map +1 -1
  91. package/dist/runtime/query/finalize-turn.js +9 -2
  92. package/dist/runtime/query/finalize-turn.js.map +1 -1
  93. package/dist/runtime/query/index.d.ts +9 -0
  94. package/dist/runtime/query/index.d.ts.map +1 -1
  95. package/dist/runtime/query/index.js +3 -0
  96. package/dist/runtime/query/index.js.map +1 -1
  97. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  98. package/dist/runtime/query/iteration/index.js +2 -1
  99. package/dist/runtime/query/iteration/index.js.map +1 -1
  100. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  101. package/dist/runtime/query/iteration/phases/compaction.js +24 -12
  102. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  103. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  104. package/dist/runtime/query/iteration/phases/tool-review.js +2 -0
  105. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  106. package/dist/runtime/query/plugin-hooks.d.ts +13 -0
  107. package/dist/runtime/query/plugin-hooks.d.ts.map +1 -1
  108. package/dist/runtime/query/plugin-hooks.js +29 -2
  109. package/dist/runtime/query/plugin-hooks.js.map +1 -1
  110. package/dist/runtime/query/tooling.d.ts +5 -0
  111. package/dist/runtime/query/tooling.d.ts.map +1 -1
  112. package/dist/runtime/query/tooling.js +3 -0
  113. package/dist/runtime/query/tooling.js.map +1 -1
  114. package/dist/session/workspace/hooked-driver.d.ts +72 -0
  115. package/dist/session/workspace/hooked-driver.d.ts.map +1 -0
  116. package/dist/session/workspace/hooked-driver.js +204 -0
  117. package/dist/session/workspace/hooked-driver.js.map +1 -0
  118. package/dist/session/workspace/index.d.ts +2 -0
  119. package/dist/session/workspace/index.d.ts.map +1 -1
  120. package/dist/session/workspace/index.js +1 -0
  121. package/dist/session/workspace/index.js.map +1 -1
  122. package/dist/skills/index.d.ts +1 -1
  123. package/dist/skills/index.d.ts.map +1 -1
  124. package/dist/skills/index.js +1 -1
  125. package/dist/skills/index.js.map +1 -1
  126. package/dist/skills/loader.d.ts +22 -0
  127. package/dist/skills/loader.d.ts.map +1 -1
  128. package/dist/skills/loader.js +41 -0
  129. package/dist/skills/loader.js.map +1 -1
  130. package/dist/tools/builtins/bash-cwd.d.ts +6 -1
  131. package/dist/tools/builtins/bash-cwd.d.ts.map +1 -1
  132. package/dist/tools/builtins/bash-cwd.js +27 -2
  133. package/dist/tools/builtins/bash-cwd.js.map +1 -1
  134. package/dist/tools/builtins/bash.js +1 -1
  135. package/dist/tools/builtins/bash.js.map +1 -1
  136. package/dist/tools/builtins/skill.d.ts.map +1 -1
  137. package/dist/tools/builtins/skill.js +93 -16
  138. package/dist/tools/builtins/skill.js.map +1 -1
  139. package/dist/types/agent/query.d.ts +8 -0
  140. package/dist/types/agent/query.d.ts.map +1 -1
  141. package/dist/types/plugin/index.d.ts +130 -13
  142. package/dist/types/plugin/index.d.ts.map +1 -1
  143. package/dist/types/plugin/index.js +5 -0
  144. package/dist/types/plugin/index.js.map +1 -1
  145. package/dist/types/skills/index.d.ts +8 -0
  146. package/dist/types/skills/index.d.ts.map +1 -1
  147. package/dist/types/skills/index.js.map +1 -1
  148. package/dist/types/tool/index.d.ts +68 -0
  149. package/dist/types/tool/index.d.ts.map +1 -1
  150. package/dist/types/tool/index.js.map +1 -1
  151. package/dist/types/workspace/ref.d.ts +6 -0
  152. package/dist/types/workspace/ref.d.ts.map +1 -1
  153. package/dist/utils/frontmatter.d.ts +16 -0
  154. package/dist/utils/frontmatter.d.ts.map +1 -1
  155. package/dist/utils/frontmatter.js +31 -1
  156. package/dist/utils/frontmatter.js.map +1 -1
  157. package/package.json +1 -1
  158. package/src/agents/QueryAgent.ts +2 -1
  159. package/src/agents/file-definitions.ts +17 -2
  160. package/src/compaction/hooks.ts +104 -0
  161. package/src/compaction/manual.ts +117 -4
  162. package/src/compaction/model-summary.ts +19 -3
  163. package/src/compaction/verifier.ts +33 -3
  164. package/src/plugin/file-change-hooks.ts +131 -0
  165. package/src/plugin/file-change-watch.ts +367 -0
  166. package/src/plugin/hook-context.ts +46 -0
  167. package/src/plugin/index.ts +53 -1
  168. package/src/plugin/lifecycle.ts +162 -8
  169. package/src/plugin/loader.ts +22 -1
  170. package/src/plugin/session-hook-env.ts +475 -0
  171. package/src/plugin/shell-hook-command.ts +215 -0
  172. package/src/plugin/shell-hook-env.ts +335 -0
  173. package/src/plugin/shell-hook-tool-names.ts +46 -0
  174. package/src/plugin/shell-hook.ts +818 -100
  175. package/src/plugin/worktree-hook-answer.ts +142 -0
  176. package/src/public-runtime.ts +44 -0
  177. package/src/public-types.ts +22 -1
  178. package/src/runtime/query/compact-session.ts +16 -4
  179. package/src/runtime/query/executor/tool-call-admission.ts +10 -2
  180. package/src/runtime/query/executor.ts +13 -2
  181. package/src/runtime/query/finalize-turn.ts +9 -2
  182. package/src/runtime/query/index.ts +12 -0
  183. package/src/runtime/query/iteration/index.ts +2 -1
  184. package/src/runtime/query/iteration/phases/compaction.ts +31 -12
  185. package/src/runtime/query/iteration/phases/tool-review.ts +2 -0
  186. package/src/runtime/query/plugin-hooks.ts +32 -2
  187. package/src/runtime/query/tooling.ts +8 -0
  188. package/src/session/workspace/hooked-driver.ts +272 -0
  189. package/src/session/workspace/index.ts +7 -0
  190. package/src/skills/index.ts +3 -0
  191. package/src/skills/loader.ts +47 -0
  192. package/src/tools/builtins/bash-cwd.ts +25 -1
  193. package/src/tools/builtins/bash.ts +1 -1
  194. package/src/tools/builtins/skill.ts +115 -26
  195. package/src/types/agent/query.ts +9 -0
  196. package/src/types/plugin/index.ts +150 -23
  197. package/src/types/skills/index.ts +9 -0
  198. package/src/types/tool/index.ts +74 -0
  199. package/src/types/workspace/ref.ts +6 -0
  200. package/src/utils/frontmatter.ts +52 -1
@@ -31,6 +31,7 @@ import type {
31
31
  PluginHookResult,
32
32
  PluginLifecycleEvent,
33
33
  PluginMCPServerConfig,
34
+ PluginManifest,
34
35
  PluginScope,
35
36
  } from '../types/plugin/index.js'
36
37
  import { assertPluginHookEvent } from '../types/plugin/index.js'
@@ -156,6 +157,11 @@ function assertPluginTool(
156
157
  }
157
158
  }
158
159
 
160
+ /** A manifest `hooks` path that names a file of hook entries (not a module). */
161
+ export function isHookEntriesPath(path: string): boolean {
162
+ return path.toLowerCase().endsWith('.json')
163
+ }
164
+
159
165
  function immutableManifest(manifest: PluginDefinition['manifest']): PluginDefinition['manifest'] {
160
166
  const mcpServers = manifest.mcpServers?.map((server) =>
161
167
  Object.freeze({
@@ -177,6 +183,9 @@ function immutableManifest(manifest: PluginDefinition['manifest']): PluginDefini
177
183
  ...(manifest.tools ? { tools: Object.freeze([...manifest.tools]) } : {}),
178
184
  ...(manifest.skills ? { skills: Object.freeze([...manifest.skills]) } : {}),
179
185
  ...(manifest.hooks ? { hooks: Object.freeze([...manifest.hooks]) } : {}),
186
+ ...(manifest.hookEntries
187
+ ? { hookEntries: Object.freeze(structuredClone(manifest.hookEntries)) }
188
+ : {}),
180
189
  ...(mcpServers ? { mcpServers: Object.freeze(mcpServers) } : {}),
181
190
  ...(manifest.connectors ? { connectors: Object.freeze([...manifest.connectors]) } : {}),
182
191
  ...(manifest.personas ? { personas: Object.freeze([...manifest.personas]) } : {}),
@@ -209,6 +218,20 @@ export interface PluginLifecycleManagerConfig {
209
218
  skillRegistry?: SkillRegistry
210
219
  log: Logger
211
220
  hookTimeoutMs?: number
221
+ /**
222
+ * Hooks a host reads for a plugin when it is enabled, beyond the JavaScript
223
+ * modules its manifest lists (shell, http and prompt entries a plugin ships,
224
+ * for one). They are attached under the plugin's id the moment it is
225
+ * enabled and removed with its other hooks when it is disabled, uninstalled
226
+ * or its enable is rolled back, so they live exactly as long as the plugin
227
+ * is on. Not called for a plugin defined in code. A throw fails the enable.
228
+ */
229
+ hooksFor?: (plugin: {
230
+ readonly id: PluginId
231
+ readonly manifest: PluginManifest
232
+ readonly rootDir: string
233
+ readonly scope: PluginScope
234
+ }) => readonly PluginHookDefinition[] | Promise<readonly PluginHookDefinition[]>
212
235
  /**
213
236
  * Where each MCP server's reconnect policy is registered, so an operator
214
237
  * can retune it while a turn is live.
@@ -247,6 +270,19 @@ export interface PluginLifecycleManagerConfig {
247
270
  onMCPToolDrift?: MCPToolDiscoveryOptions['onDrift']
248
271
  }
249
272
 
273
+ /**
274
+ * What {@link PluginLifecycleManager.attachHooks} gives back: a way to take
275
+ * off exactly the hooks that call attached.
276
+ */
277
+ export interface HookAttachment {
278
+ /** How many hooks the call attached. */
279
+ readonly size: number
280
+ /** Take every hook of this attachment off; returns how many were still attached. Safe to call again. */
281
+ readonly remove: () => number
282
+ /** Take off the hook at this position of the call's list; false when it is gone already or there is none. */
283
+ readonly removeAt: (index: number) => boolean
284
+ }
285
+
250
286
  export class PluginLifecycleManager {
251
287
  private pluginRegistry: PluginRegistry
252
288
  /** Each installed plugin owns its own file source and one source per MCP server. */
@@ -265,14 +301,21 @@ export class PluginLifecycleManager {
265
301
  priority: number
266
302
  seq: number
267
303
  statusMessage?: string
304
+ /** Read by the host from entries the plugin ships, not a module the plugin runs. */
305
+ shell?: true
306
+ /** On `file_changed`: the paths the hook's matcher names. */
307
+ watches?: readonly string[]
268
308
  }>
269
309
  > = new Map()
310
+ private hookSeq = 0
311
+ private readonly hooksChangedListeners = new Set<() => void>()
270
312
  private pluginContributions: Map<PluginId, PluginContributionRecord> = new Map()
271
313
  /** Reserve each id before async admission so lifecycle calls cannot overlap. */
272
314
  private readonly lifecycleTails = new Map<PluginId, Promise<void>>()
273
315
  /** Immutable executable admissions owned by this manager, never by the mutable registry. */
274
316
  private pluginAdmissions: Map<PluginId, PluginAdmission> = new Map()
275
317
  private hookTimeoutMs: number
318
+ private readonly hooksFor: PluginLifecycleManagerConfig['hooksFor']
276
319
  private readonly configRegistry: ConfigRegistry | undefined
277
320
  private readonly scopeRoots: Readonly<Record<PluginScope, string>>
278
321
  private log: Logger
@@ -299,6 +342,7 @@ export class PluginLifecycleManager {
299
342
  this.skillRegistry = config.skillRegistry
300
343
  this.scopeRoots = Object.freeze({ ...config.scopeRoots })
301
344
  this.hookTimeoutMs = config.hookTimeoutMs ?? HOOK_TIMEOUT_MS
345
+ this.hooksFor = config.hooksFor
302
346
  this.configRegistry = config.configRegistry
303
347
  this.mcpToolPolicies = config.mcpToolPolicies
304
348
  this.onMCPToolDrift = config.onMCPToolDrift
@@ -411,24 +455,98 @@ export class PluginLifecycleManager {
411
455
  * registration order.
412
456
  */
413
457
  registerHook(pluginId: PluginId, hook: PluginHookDefinition): void {
458
+ this.addHook(pluginId, hook, false)
459
+ }
460
+
461
+ /**
462
+ * Attach hooks that can be taken off again, and nothing else.
463
+ *
464
+ * Hooks left the manager only by plugin id: everything one id attached went
465
+ * together, and a hook attached for a while (a skill's, for as long as it is
466
+ * used) had no way to leave on its own. This returns a handle that removes
467
+ * exactly the hooks this call attached, whoever else registered under the
468
+ * same id, and a handle for one hook of them. A hook that is removed while
469
+ * an event is being answered still answers that event: the event started
470
+ * with the hooks it found.
471
+ *
472
+ * All or nothing: when one definition is refused (an event nothing emits),
473
+ * none of them is attached.
474
+ */
475
+ attachHooks(pluginId: PluginId, hooks: readonly PluginHookDefinition[]): HookAttachment {
476
+ for (const hook of hooks) assertPluginHookEvent(hook.event)
477
+ const records = hooks.map((hook) => this.addHook(pluginId, hook, false))
478
+ const removeRecords = (gone: ReadonlySet<object>): number => {
479
+ let removed = 0
480
+ for (const [event, handlers] of this.hookHandlers) {
481
+ const kept = handlers.filter((handler) => !gone.has(handler))
482
+ removed += handlers.length - kept.length
483
+ if (kept.length === handlers.length) continue
484
+ if (kept.length === 0) this.hookHandlers.delete(event)
485
+ else this.hookHandlers.set(event, kept)
486
+ }
487
+ if (removed > 0) this.notifyHooksChanged()
488
+ return removed
489
+ }
490
+ return {
491
+ size: records.length,
492
+ remove: () => removeRecords(new Set(records)),
493
+ removeAt: (index) => {
494
+ const record = records[index]
495
+ return record === undefined ? false : removeRecords(new Set([record])) > 0
496
+ },
497
+ }
498
+ }
499
+
500
+ private addHook(pluginId: PluginId, hook: PluginHookDefinition, shell: boolean): object {
414
501
  // Refused here rather than left to never fire: a hook module still
415
502
  // naming `run_start` would otherwise attach to an event nothing emits,
416
503
  // and the operator would learn of the rename only by its silence.
417
504
  assertPluginHookEvent(hook.event)
418
505
  const handlers = this.hookHandlers.get(hook.event) ?? []
419
- handlers.push({
506
+ const record = {
420
507
  pluginId,
421
508
  handler: hook.handler,
422
509
  priority: hook.priority ?? DEFAULT_HOOK_PRIORITY,
423
510
  ...(hook.statusMessage !== undefined ? { statusMessage: hook.statusMessage } : {}),
424
- // Registration index, so the sort has something stable to fall
425
- // back on when priorities are equal.
426
- seq: handlers.length,
427
- })
511
+ ...(shell ? { shell: true as const } : {}),
512
+ ...(hook.watches !== undefined ? { watches: hook.watches } : {}),
513
+ // Registration order, so the sort has something stable to fall back
514
+ // on when priorities are equal. A counter, not the list's length: a
515
+ // hook taken off again would otherwise hand its number to the next.
516
+ seq: this.hookSeq++,
517
+ }
518
+ handlers.push(record)
428
519
  // Sorted on insert rather than on dispatch: a chain runs on every
429
520
  // tool call, and the order only changes when a plugin comes or goes.
430
521
  handlers.sort((a, b) => a.priority - b.priority || a.seq - b.seq)
431
522
  this.hookHandlers.set(hook.event, handlers)
523
+ this.notifyHooksChanged()
524
+ return record
525
+ }
526
+
527
+ /**
528
+ * Called after a hook was attached or taken off, however it happened (a
529
+ * plugin enabled or disabled, a skill's hooks attached, a handle removed).
530
+ * For a host that keeps something in step with the hooks, such as the files
531
+ * `file_changed` hooks watch. Returns what ends the subscription.
532
+ */
533
+ onHooksChanged(listener: () => void): () => void {
534
+ this.hooksChangedListeners.add(listener)
535
+ return () => {
536
+ this.hooksChangedListeners.delete(listener)
537
+ }
538
+ }
539
+
540
+ private notifyHooksChanged(): void {
541
+ for (const listener of [...this.hooksChangedListeners]) {
542
+ try {
543
+ listener()
544
+ } catch (error) {
545
+ this.log.warn('A hooks-changed listener threw', {
546
+ 'exception.message': toErrorMessage(error),
547
+ })
548
+ }
549
+ }
432
550
  }
433
551
 
434
552
  /**
@@ -436,10 +554,29 @@ export class PluginLifecycleManager {
436
554
  * and its event, in the order answers are read. For a host that shows the
437
555
  * operator what is attached; it carries no handler.
438
556
  */
439
- listHooks(): readonly { readonly pluginId: PluginId; readonly event: PluginHookEvent }[] {
440
- const out: { pluginId: PluginId; event: PluginHookEvent }[] = []
557
+ listHooks(): readonly {
558
+ readonly pluginId: PluginId
559
+ readonly event: PluginHookEvent
560
+ /** Set when the hook was read from entries the plugin ships and not from a module it runs. */
561
+ readonly shell?: true
562
+ /** On `file_changed`: the paths the hook's matcher names. */
563
+ readonly watches?: readonly string[]
564
+ }[] {
565
+ const out: {
566
+ pluginId: PluginId
567
+ event: PluginHookEvent
568
+ shell?: true
569
+ watches?: readonly string[]
570
+ }[] = []
441
571
  for (const [event, handlers] of this.hookHandlers) {
442
- for (const handler of handlers) out.push({ pluginId: handler.pluginId, event })
572
+ for (const handler of handlers) {
573
+ out.push({
574
+ pluginId: handler.pluginId,
575
+ event,
576
+ ...(handler.shell === true ? { shell: true as const } : {}),
577
+ ...(handler.watches !== undefined ? { watches: handler.watches } : {}),
578
+ })
579
+ }
443
580
  }
444
581
  return out
445
582
  }
@@ -739,6 +876,9 @@ export class PluginLifecycleManager {
739
876
  for (const hook of admission.inCode.hooks) this.registerHook(pluginId, hook)
740
877
  } else if (manifest.hooks && manifest.hooks.length > 0) {
741
878
  for (const hookPath of manifest.hooks) {
879
+ // A `.json` path is a file of hook entries, read by the host through
880
+ // `hooksFor`; it is not a module.
881
+ if (isHookEntriesPath(hookPath)) continue
742
882
  const absolutePath = await resolveWithinReal(admission.rootDir, hookPath)
743
883
  const fileUrl = pathToFileURL(absolutePath).href
744
884
  const mod = (await import(fileUrl)) as {
@@ -757,6 +897,18 @@ export class PluginLifecycleManager {
757
897
  }
758
898
  }
759
899
 
900
+ // Entries the host reads from the plugin folder: attached now, removed
901
+ // with the rest of this plugin's hooks.
902
+ if (!admission.inCode && this.hooksFor) {
903
+ const shipped = await this.hooksFor({
904
+ id: pluginId,
905
+ manifest,
906
+ rootDir: admission.rootDir,
907
+ scope: admission.scope,
908
+ })
909
+ for (const hook of shipped) this.addHook(pluginId, hook, true)
910
+ }
911
+
760
912
  // Start MCP servers and adapt their tools
761
913
  if (manifest.mcpServers && manifest.mcpServers.length > 0) {
762
914
  for (const serverConfig of manifest.mcpServers) {
@@ -945,6 +1097,7 @@ export class PluginLifecycleManager {
945
1097
  this.hookHandlers.set(event, filtered)
946
1098
  }
947
1099
  }
1100
+ this.notifyHooksChanged()
948
1101
  }
949
1102
 
950
1103
  private async stopMcpContributions(
@@ -1028,6 +1181,7 @@ export class PluginLifecycleManager {
1028
1181
  this.hookHandlers.set(event, filtered)
1029
1182
  }
1030
1183
  }
1184
+ this.notifyHooksChanged()
1031
1185
 
1032
1186
  this.pluginContributions.delete(pluginId)
1033
1187
  this.instructions.unregister(
@@ -114,7 +114,28 @@ export async function loadPluginManifest(
114
114
  */
115
115
  export function parsePluginManifestText(raw: string): PluginManifest {
116
116
  const parsed: unknown = JSON.parse(raw)
117
- return PluginManifestSchema.parse(parsed)
117
+ return PluginManifestSchema.parse(normalizeManifestHooks(parsed))
118
+ }
119
+
120
+ /**
121
+ * The two ways a plugin written for the common hook contract names its hook
122
+ * entries, read as the keys this manifest has: `"hooks": "./hooks/hooks.json"`
123
+ * (one file, as a text) is a list of one path, and `"hooks": { <events> }`
124
+ * (the events object written inline) is `hookEntries`. A manifest that already
125
+ * has `hookEntries` next to an inline `hooks` object is left as written, so the
126
+ * schema says what is wrong rather than one of the two being dropped.
127
+ */
128
+ function normalizeManifestHooks(parsed: unknown): unknown {
129
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return parsed
130
+ const manifest = parsed as Record<string, unknown>
131
+ const hooks = manifest.hooks
132
+ if (typeof hooks === 'string') return { ...manifest, hooks: [hooks] }
133
+ if (hooks !== null && typeof hooks === 'object' && !Array.isArray(hooks)) {
134
+ if (manifest.hookEntries !== undefined) return parsed
135
+ const { hooks: inline, ...rest } = manifest
136
+ return { ...rest, hookEntries: inline }
137
+ }
138
+ return parsed
118
139
  }
119
140
 
120
141
  async function discoverScopedPlugins(