@namzu/sdk 62.15.0 → 63.0.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 (47) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/plugin/hook-context.d.ts +30 -0
  3. package/dist/plugin/hook-context.d.ts.map +1 -0
  4. package/dist/plugin/hook-context.js +51 -0
  5. package/dist/plugin/hook-context.js.map +1 -0
  6. package/dist/plugin/index.d.ts +2 -1
  7. package/dist/plugin/index.d.ts.map +1 -1
  8. package/dist/plugin/index.js +1 -0
  9. package/dist/plugin/index.js.map +1 -1
  10. package/dist/plugin/lifecycle.d.ts +9 -0
  11. package/dist/plugin/lifecycle.d.ts.map +1 -1
  12. package/dist/plugin/lifecycle.js +13 -0
  13. package/dist/plugin/lifecycle.js.map +1 -1
  14. package/dist/plugin/shell-hook.d.ts +87 -12
  15. package/dist/plugin/shell-hook.d.ts.map +1 -1
  16. package/dist/plugin/shell-hook.js +222 -31
  17. package/dist/plugin/shell-hook.js.map +1 -1
  18. package/dist/public-runtime.d.ts +1 -1
  19. package/dist/public-runtime.d.ts.map +1 -1
  20. package/dist/public-runtime.js +1 -1
  21. package/dist/public-runtime.js.map +1 -1
  22. package/dist/public-types.d.ts +1 -1
  23. package/dist/public-types.d.ts.map +1 -1
  24. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  25. package/dist/runtime/query/executor/tool-call-admission.js +2 -3
  26. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  27. package/dist/runtime/query/executor.d.ts +2 -0
  28. package/dist/runtime/query/executor.d.ts.map +1 -1
  29. package/dist/runtime/query/executor.js +13 -1
  30. package/dist/runtime/query/executor.js.map +1 -1
  31. package/dist/runtime/query/index.d.ts.map +1 -1
  32. package/dist/runtime/query/index.js +3 -2
  33. package/dist/runtime/query/index.js.map +1 -1
  34. package/dist/types/plugin/index.d.ts +37 -10
  35. package/dist/types/plugin/index.d.ts.map +1 -1
  36. package/dist/types/plugin/index.js.map +1 -1
  37. package/package.json +1 -1
  38. package/src/plugin/hook-context.ts +58 -0
  39. package/src/plugin/index.ts +9 -0
  40. package/src/plugin/lifecycle.ts +13 -0
  41. package/src/plugin/shell-hook.ts +288 -42
  42. package/src/public-runtime.ts +6 -0
  43. package/src/public-types.ts +1 -0
  44. package/src/runtime/query/executor/tool-call-admission.ts +2 -4
  45. package/src/runtime/query/executor.ts +15 -3
  46. package/src/runtime/query/index.ts +3 -3
  47. package/src/types/plugin/index.ts +48 -16
@@ -18,6 +18,7 @@ import { restoreWorkingState, snapshotWorkingState } from '../../compaction/wire
18
18
  import { type CompactionConfig, CompactionConfigSchema } from '../../config/runtime.js'
19
19
  import { childSessionLog } from '../../manager/agent/child-session.js'
20
20
  import { type TurnRecorder, recordedTurnStart } from '../../manager/session/turn-recorder.js'
21
+ import { frameOperatorHookContext } from '../../plugin/hook-context.js'
21
22
  import { PromptContributionRegistry } from '../../prompt/contributions.js'
22
23
  import { resolveProviderCapabilities } from '../../provider/capabilities.js'
23
24
  import type { ProviderChainMember } from '../../provider/fallback.js'
@@ -2199,8 +2200,7 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
2199
2200
  promptContributions.replace({
2200
2201
  id: 'hooks:subagent_start',
2201
2202
  placement: 'context',
2202
- render: () =>
2203
- `Context from the operator's hooks:\n\n${startAnnotations.join('\n\n')}`,
2203
+ render: () => frameOperatorHookContext(startAnnotations),
2204
2204
  })
2205
2205
  }
2206
2206
  yield* eventTranslator.drainPending()
@@ -2226,7 +2226,7 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
2226
2226
  promptContributions.replace({
2227
2227
  id: 'hooks:user_prompt_submit',
2228
2228
  placement: 'context',
2229
- render: () => `Context from the operator's hooks:\n\n${annotations.join('\n\n')}`,
2229
+ render: () => frameOperatorHookContext(annotations),
2230
2230
  })
2231
2231
  }
2232
2232
  yield* eventTranslator.drainPending()
@@ -96,7 +96,13 @@ export type PluginHookEvent =
96
96
  * to what the model is told (`annotate`).
97
97
  */
98
98
  | 'user_prompt_submit'
99
- /** A host's session opened or closed. Carries `sessionId` and no `turnId`: these hooks run outside any turn. */
99
+ /**
100
+ * A host's session opened or closed. Carries `sessionId` and no `turnId`:
101
+ * these hooks run outside any turn. `session_start` carries `source`;
102
+ * `session_end` carries `endReason`. A `session_start` hook may answer with
103
+ * `context` (on `continue`) or `annotate`: text the model reads, from the
104
+ * first turn of the session on.
105
+ */
100
106
  | 'session_start'
101
107
  | 'session_end'
102
108
  /** A compaction pass is about to run / has run. Carries `compaction`. */
@@ -110,11 +116,6 @@ export type PluginHookEvent =
110
116
  | 'subagent_start'
111
117
  /** A child session's turn ended. Fired after its own `turn_end`; carries `parentSessionId`, `parentTurnId` and `agentType`. */
112
118
  | 'subagent_stop'
113
- /**
114
- * A child session's turn is starting. Fired right after its own
115
- * `turn_start`; carries `parentSessionId` and `parentTurnId`. Observational.
116
- */
117
- | 'subagent_start'
118
119
  | 'turn_start'
119
120
  | 'turn_end'
120
121
  /**
@@ -273,6 +274,21 @@ export interface PluginNotificationInfo {
273
274
  readonly message: string
274
275
  }
275
276
 
277
+ /**
278
+ * Why a session started, on `session_start`: `startup` for a conversation
279
+ * with no earlier turn, `resume` for one that already had turns (a resumed
280
+ * conversation, a `--continue`, or a session rebuilt under a running one).
281
+ */
282
+ export type PluginSessionSource = 'startup' | 'resume'
283
+
284
+ /**
285
+ * Why a session closed, on `session_end`: `exit` when the host is finishing
286
+ * with it (the process ends, the person quits), `replaced` when the host
287
+ * builds another session in its place (a model or account switch, another
288
+ * conversation opened).
289
+ */
290
+ export type PluginSessionEndReason = 'exit' | 'replaced'
291
+
276
292
  export interface PluginHookContext {
277
293
  /** The turn the hook fired in. Absent on `session_start` and `session_end`. */
278
294
  readonly turnId?: TurnId
@@ -286,6 +302,10 @@ export interface PluginHookContext {
286
302
  readonly parentTurnId?: TurnId
287
303
  /** The name of the agent the child runs, on `subagent_start` and `subagent_stop`. */
288
304
  readonly agentType?: string
305
+ /** Why the session started, on `session_start`. */
306
+ readonly source?: PluginSessionSource
307
+ /** Why the session closed, on `session_end`. */
308
+ readonly endReason?: PluginSessionEndReason
289
309
  /** The operator's prompt, on `user_prompt_submit`. */
290
310
  readonly prompt?: string
291
311
  /** The pass, on `pre_compact` and `post_compact`. */
@@ -437,7 +457,18 @@ export type PluginHookResult =
437
457
  * hook redacting a secret that also appears in an image must — this variant
438
458
  * cannot inspect what it is preserving.
439
459
  */
440
- | { action: 'replace'; output: string; content?: ToolResultContent }
460
+ | ({
461
+ action: 'replace'
462
+ output: string
463
+ content?: ToolResultContent
464
+ /**
465
+ * Say, beside the result the model and the record carry, that a hook
466
+ * replaced it, so rewritten text is not passed off as the tool's own
467
+ * words. Off by default: a plugin that redacts quietly keeps doing so.
468
+ * A shell hook's replacement always sets it.
469
+ */
470
+ disclose?: boolean
471
+ } & PluginHookNotes)
441
472
 
442
473
  export function assertPluginHookResult(result: PluginHookResult): asserts result {
443
474
  const action = result.action
@@ -472,15 +503,16 @@ export type PluginHookResultFor<E extends PluginHookEvent> = E extends 'user_pro
472
503
  ? Extract<PluginHookResult, { action: 'continue' | 'skip' }>
473
504
  : E extends 'turn_end' | 'subagent_stop' | 'pre_compact'
474
505
  ? Extract<PluginHookResult, { action: 'continue' | 'skip' | 'error' }>
475
- : E extends
476
- | 'turn_interrupt'
477
- | 'session_start'
478
- | 'session_end'
479
- | 'notification'
480
- | 'turn_failure'
481
- | 'permission_denied'
482
- ? Extract<PluginHookResult, { action: 'continue' }>
483
- : Extract<PluginHookResult, { action: 'continue' | 'error' }>
506
+ : E extends 'session_start'
507
+ ? Extract<PluginHookResult, { action: 'continue' | 'annotate' }>
508
+ : E extends
509
+ | 'turn_interrupt'
510
+ | 'session_end'
511
+ | 'notification'
512
+ | 'turn_failure'
513
+ | 'permission_denied'
514
+ ? Extract<PluginHookResult, { action: 'continue' }>
515
+ : Extract<PluginHookResult, { action: 'continue' | 'error' }>
484
516
 
485
517
  /** The event and its handler verdict stay correlated, including in hook arrays. */
486
518
  export type PluginHookDefinition<E extends PluginHookEvent = PluginHookEvent> =