@code-yeongyu/senpi 2026.7.2 → 2026.7.4

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 (165) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/cli/config-selector.d.ts.map +1 -1
  3. package/dist/cli/config-selector.js +2 -1
  4. package/dist/cli/config-selector.js.map +1 -1
  5. package/dist/cli/startup-ui.d.ts.map +1 -1
  6. package/dist/cli/startup-ui.js +2 -1
  7. package/dist/cli/startup-ui.js.map +1 -1
  8. package/dist/core/dynamic-prompt/build.d.ts +13 -0
  9. package/dist/core/dynamic-prompt/build.d.ts.map +1 -1
  10. package/dist/core/dynamic-prompt/build.js +24 -21
  11. package/dist/core/dynamic-prompt/build.js.map +1 -1
  12. package/dist/core/dynamic-prompt/exploration.d.ts.map +1 -1
  13. package/dist/core/dynamic-prompt/exploration.js +1 -3
  14. package/dist/core/dynamic-prompt/exploration.js.map +1 -1
  15. package/dist/core/dynamic-prompt/index.d.ts +1 -1
  16. package/dist/core/dynamic-prompt/index.d.ts.map +1 -1
  17. package/dist/core/dynamic-prompt/index.js.map +1 -1
  18. package/dist/core/dynamic-prompt/intent-gate.d.ts.map +1 -1
  19. package/dist/core/dynamic-prompt/intent-gate.js +20 -35
  20. package/dist/core/dynamic-prompt/intent-gate.js.map +1 -1
  21. package/dist/core/dynamic-prompt/parallel-tools.d.ts.map +1 -1
  22. package/dist/core/dynamic-prompt/parallel-tools.js +2 -4
  23. package/dist/core/dynamic-prompt/parallel-tools.js.map +1 -1
  24. package/dist/core/dynamic-prompt/style.d.ts.map +1 -1
  25. package/dist/core/dynamic-prompt/style.js +7 -26
  26. package/dist/core/dynamic-prompt/style.js.map +1 -1
  27. package/dist/core/extensions/builtin/hooks/dispatcher.d.ts +2 -0
  28. package/dist/core/extensions/builtin/hooks/dispatcher.d.ts.map +1 -1
  29. package/dist/core/extensions/builtin/hooks/dispatcher.js +50 -17
  30. package/dist/core/extensions/builtin/hooks/dispatcher.js.map +1 -1
  31. package/dist/core/extensions/builtin/hooks/index.d.ts.map +1 -1
  32. package/dist/core/extensions/builtin/hooks/index.js +11 -1
  33. package/dist/core/extensions/builtin/hooks/index.js.map +1 -1
  34. package/dist/core/extensions/builtin/hooks/output-bounds.d.ts.map +1 -1
  35. package/dist/core/extensions/builtin/hooks/output-bounds.js +3 -7
  36. package/dist/core/extensions/builtin/hooks/output-bounds.js.map +1 -1
  37. package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.d.ts +3 -0
  38. package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.d.ts.map +1 -0
  39. package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js +16 -0
  40. package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js.map +1 -0
  41. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.d.ts.map +1 -1
  42. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js +3 -1
  43. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js.map +1 -1
  44. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.d.ts.map +1 -1
  45. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js +3 -1
  46. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js.map +1 -1
  47. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.d.ts.map +1 -1
  48. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js +6 -2
  49. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js.map +1 -1
  50. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.d.ts.map +1 -1
  51. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.js +5 -3
  52. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.js.map +1 -1
  53. package/dist/core/extensions/builtin/prompt-preset/gpt-5.5.d.ts.map +1 -1
  54. package/dist/core/extensions/builtin/prompt-preset/gpt-5.5.js +68 -8
  55. package/dist/core/extensions/builtin/prompt-preset/gpt-5.5.js.map +1 -1
  56. package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
  57. package/dist/core/extensions/builtin/prompt-preset/presets.js +9 -0
  58. package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
  59. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts +1 -1
  60. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts.map +1 -1
  61. package/dist/core/extensions/builtin/prompt-preset/settings.js +1 -0
  62. package/dist/core/extensions/builtin/prompt-preset/settings.js.map +1 -1
  63. package/dist/core/extensions/runner.d.ts +3 -0
  64. package/dist/core/extensions/runner.d.ts.map +1 -1
  65. package/dist/core/extensions/runner.js +89 -58
  66. package/dist/core/extensions/runner.js.map +1 -1
  67. package/dist/core/extensions/types.d.ts +7 -0
  68. package/dist/core/extensions/types.d.ts.map +1 -1
  69. package/dist/core/extensions/types.js.map +1 -1
  70. package/dist/core/hidden-stdout-log.d.ts +2 -0
  71. package/dist/core/hidden-stdout-log.d.ts.map +1 -0
  72. package/dist/core/hidden-stdout-log.js +17 -0
  73. package/dist/core/hidden-stdout-log.js.map +1 -0
  74. package/dist/core/model-resolver.js +5 -5
  75. package/dist/core/model-resolver.js.map +1 -1
  76. package/dist/core/output-guard.d.ts +2 -0
  77. package/dist/core/output-guard.d.ts.map +1 -1
  78. package/dist/core/output-guard.js +63 -0
  79. package/dist/core/output-guard.js.map +1 -1
  80. package/dist/core/provider-attribution.d.ts.map +1 -1
  81. package/dist/core/provider-attribution.js +0 -10
  82. package/dist/core/provider-attribution.js.map +1 -1
  83. package/dist/core/sensitive-output.d.ts +3 -0
  84. package/dist/core/sensitive-output.d.ts.map +1 -0
  85. package/dist/core/sensitive-output.js +12 -0
  86. package/dist/core/sensitive-output.js.map +1 -0
  87. package/dist/core/tools/edit.js +2 -2
  88. package/dist/core/tools/edit.js.map +1 -1
  89. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  90. package/dist/modes/interactive/interactive-mode.js +41 -4
  91. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  92. package/dist/modes/interactive/interactive-stderr-guard.d.ts +3 -0
  93. package/dist/modes/interactive/interactive-stderr-guard.d.ts.map +1 -0
  94. package/dist/modes/interactive/interactive-stderr-guard.js +24 -0
  95. package/dist/modes/interactive/interactive-stderr-guard.js.map +1 -0
  96. package/dist/package-manager-cli.d.ts.map +1 -1
  97. package/dist/package-manager-cli.js +7 -0
  98. package/dist/package-manager-cli.js.map +1 -1
  99. package/docs/extensions.md +14 -1
  100. package/docs/settings.md +1 -1
  101. package/examples/extensions/question.ts +1 -0
  102. package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
  103. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
  104. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +6 -0
  105. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
  106. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +4 -1
  107. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js.map +1 -1
  108. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts.map +1 -1
  109. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +10 -2
  110. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js.map +1 -1
  111. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +126 -0
  112. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts.map +1 -1
  113. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.d.ts +56 -0
  114. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.d.ts.map +1 -1
  115. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.js +38 -0
  116. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.js.map +1 -1
  117. package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.d.ts +28 -0
  118. package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.d.ts.map +1 -1
  119. package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.js +19 -0
  120. package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.js.map +1 -1
  121. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts +42 -0
  122. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts.map +1 -1
  123. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js +56 -20
  124. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js.map +1 -1
  125. package/node_modules/@earendil-works/pi-ai/dist/providers/together.models.js +2 -2
  126. package/node_modules/@earendil-works/pi-ai/dist/providers/together.models.js.map +1 -1
  127. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js +4 -4
  128. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js.map +1 -1
  129. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.d.ts +1 -0
  130. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.d.ts.map +1 -1
  131. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.js +9 -2
  132. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.js.map +1 -1
  133. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.d.ts.map +1 -1
  134. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.js +2 -2
  135. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.js.map +1 -1
  136. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts +1 -0
  137. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -1
  138. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +3 -0
  139. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
  140. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
  141. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -0
  142. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
  143. package/node_modules/@earendil-works/pi-ai/package.json +1 -1
  144. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts +1 -1
  145. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts.map +1 -1
  146. package/node_modules/@earendil-works/pi-tui/dist/index.js.map +1 -1
  147. package/node_modules/@earendil-works/pi-tui/dist/mux.d.ts +4 -0
  148. package/node_modules/@earendil-works/pi-tui/dist/mux.d.ts.map +1 -0
  149. package/node_modules/@earendil-works/pi-tui/dist/mux.js +10 -0
  150. package/node_modules/@earendil-works/pi-tui/dist/mux.js.map +1 -0
  151. package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts +17 -0
  152. package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts.map +1 -1
  153. package/node_modules/@earendil-works/pi-tui/dist/terminal.js +75 -22
  154. package/node_modules/@earendil-works/pi-tui/dist/terminal.js.map +1 -1
  155. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +29 -1
  156. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +1 -1
  157. package/node_modules/@earendil-works/pi-tui/dist/tui.js +401 -89
  158. package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
  159. package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts +10 -0
  160. package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts.map +1 -1
  161. package/node_modules/@earendil-works/pi-tui/dist/utils.js +53 -13
  162. package/node_modules/@earendil-works/pi-tui/dist/utils.js.map +1 -1
  163. package/node_modules/@earendil-works/pi-tui/package.json +2 -1
  164. package/npm-shrinkwrap.json +9 -9
  165. package/package.json +4 -4
@@ -49,6 +49,7 @@ export type HookDispatchOptions = {
49
49
  readonly envPassthrough?: readonly string[];
50
50
  readonly handlers: readonly ExecutableHookHandler[];
51
51
  readonly input: HookInputWire;
52
+ readonly onRunningHandlersChange?: (running: readonly ExecutableHookHandler[]) => void;
52
53
  readonly outputPolicy?: HookOutputPolicy;
53
54
  readonly runCommand?: HookCommandRunner;
54
55
  readonly signal?: AbortSignal;
@@ -57,4 +58,5 @@ export type HookDispatchOptions = {
57
58
  readonly trustState: HookTrustState;
58
59
  };
59
60
  export declare function dispatchHookEvent(options: HookDispatchOptions): Promise<HookDispatchResult>;
61
+ export declare function runningHookHandlersStatusLabel(handlers: readonly ExecutableHookHandler[], platform?: NodeJS.Platform): string;
60
62
  //# sourceMappingURL=dispatcher.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/hooks/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,oBAAoB,EAAkB,MAAM,qBAAqB,CAAC;AAE5G,OAAO,EAAE,KAAK,gBAAgB,EAAmB,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,KAAK,gBAAgB,EAA6B,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAwB,MAAM,YAAY,CAAC;AAC/F,OAAO,KAAK,EACX,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,iBAAiB,GAAG,CAC/B,OAAO,EAAE,qBAAqB,EAC9B,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,qBAAqB,KAC1B,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEnC,MAAM,MAAM,oBAAoB,GAC7B;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB;IACA,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;IACjC,QAAQ,CAAC,MAAM,CAAC,E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CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACvC,QAAQ,CAAC,YAAY,CAAC,EAAE,gBAAgB,CAAC;IACzC,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;CACpC,CAAC;AAWF,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAiEjG;AAED,wBAAgB,8BAA8B,CAC7C,QAAQ,EAAE,SAAS,qBAAqB,EAAE,EAC1C,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC1C,MAAM,CAGR"}
@@ -1,3 +1,4 @@
1
+ import { stripAnsi } from "../../../../utils/ansi.js";
1
2
  import { runCommandHook } from "./command-runner.js";
2
3
  import { matchingHookHandlers } from "./matcher.js";
3
4
  import { parseHookOutput } from "./output-parser.js";
@@ -9,24 +10,41 @@ export async function dispatchHookEvent(options) {
9
10
  const selected = selectExecutableHandlers(ordered, options.trustState, options.trustOptions);
10
11
  let nextCompletionIndex = 0;
11
12
  const runner = options.runCommand ?? runCommandHook;
13
+ const notifyRunningChange = options.onRunningHandlersChange;
14
+ const runningHandlers = [];
12
15
  const completed = await Promise.all(selected.runnable.map(async ({ handler, declarationIndex }) => {
13
- const run = await runner(handler, options.input, {
14
- cwd: options.cwd,
15
- ...(options.envPassthrough === undefined ? {} : { envPassthrough: options.envPassthrough }),
16
- ...(options.outputPolicy === undefined ? {} : { outputPolicy: options.outputPolicy }),
17
- ...(options.signal === undefined ? {} : { signal: options.signal }),
18
- ...(options.sourceEnv === undefined ? {} : { sourceEnv: options.sourceEnv }),
19
- });
20
- const parsed = parseHookOutput({
21
- event: options.input.event,
22
- exitCode: run.exitCode ?? 1,
23
- source: handler.source,
24
- stderr: run.stderr,
25
- stdout: run.stdout,
26
- });
27
- const completionIndex = nextCompletionIndex;
28
- nextCompletionIndex += 1;
29
- return { completionIndex, declarationIndex, handler, parsed, run };
16
+ if (notifyRunningChange !== undefined) {
17
+ runningHandlers.push(handler);
18
+ notifyRunningChange([...runningHandlers]);
19
+ }
20
+ try {
21
+ const run = await runner(handler, options.input, {
22
+ cwd: options.cwd,
23
+ ...(options.envPassthrough === undefined ? {} : { envPassthrough: options.envPassthrough }),
24
+ ...(options.outputPolicy === undefined ? {} : { outputPolicy: options.outputPolicy }),
25
+ ...(options.signal === undefined ? {} : { signal: options.signal }),
26
+ ...(options.sourceEnv === undefined ? {} : { sourceEnv: options.sourceEnv }),
27
+ });
28
+ const parsed = parseHookOutput({
29
+ event: options.input.event,
30
+ exitCode: run.exitCode ?? 1,
31
+ source: handler.source,
32
+ stderr: run.stderr,
33
+ stdout: run.stdout,
34
+ });
35
+ const completionIndex = nextCompletionIndex;
36
+ nextCompletionIndex += 1;
37
+ return { completionIndex, declarationIndex, handler, parsed, run };
38
+ }
39
+ finally {
40
+ if (notifyRunningChange !== undefined) {
41
+ const runningIndex = runningHandlers.indexOf(handler);
42
+ if (runningIndex !== -1) {
43
+ runningHandlers.splice(runningIndex, 1);
44
+ }
45
+ notifyRunningChange([...runningHandlers]);
46
+ }
47
+ }
30
48
  }));
31
49
  const declarationSummaries = completed
32
50
  .toSorted((left, right) => left.declarationIndex - right.declarationIndex)
@@ -51,6 +69,21 @@ export async function dispatchHookEvent(options) {
51
69
  summaries: declarationSummaries,
52
70
  };
53
71
  }
72
+ export function runningHookHandlersStatusLabel(handlers, platform = process.platform) {
73
+ const label = handlers.map((handler) => hookHandlerStatusLabel(handler, platform)).join(" · ");
74
+ return label.length <= 79 ? label : `${label.slice(0, 76)}...`;
75
+ }
76
+ function hookHandlerStatusLabel(handler, platform) {
77
+ const raw = handler.config.statusMessage ??
78
+ (platform === "win32" && handler.config.commandWindows !== undefined
79
+ ? handler.config.commandWindows
80
+ : handler.config.command);
81
+ return stripAnsi(raw)
82
+ .replace(/[\r\n\t]+/g, " ")
83
+ .replace(/[\u0000-\u001f\u007f]+/g, "")
84
+ .replace(/\s+/g, " ")
85
+ .trim();
86
+ }
54
87
  function declarationOrdered(handlers) {
55
88
  return handlers
56
89
  .map((handler, index) => ({ declarationIndex: index, handler }))
@@ -1 +1 @@
1
- {"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/hooks/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC5G,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAyB,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAyB,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAA+C,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA+E/F,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAA4B;IACnE,MAAM,KAAK,GAAG,oBAAoB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpE,MAAM,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC7F,IAAI,mBAAmB,GAAG,CAAC,CAAC;IAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,IAAI,cAAc,CAAC;IACpD,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CAClC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,EAAE;QAC7D,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE;YAChD,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,GAAG,CAAC,OAAO,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,OAAO,CA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;AAClF,CAAC;AAED,SAAS,kBAAkB,CAC1B,IAAuB,EACvB,OAA4B,EAC5B,MAA0B,EAC1B,YAAsB;IAEtB,OAAO;QACN,IAAI;QACJ,GAAG,WAAW,CAAC,MAAM,CAAC;QACtB,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM;QAC9B,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO;QAC7C,GAAG,iBAAiB,CAAC,YAAY,CAAC;KAClC,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,MAA0B;IAC9C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,EAAE,CAAC;IACX,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,CAAC;AACnB,CAAC;AAED,SAAS,iBAAiB,CAAC,YAAqB;IAC/C,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAChC,OAAO,EAAE,CAAC;IACX,CAAC;IACD,OAAO,EAAE,YAAY,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import { type CommandHookRunOptions, type CommandHookRunResult, runCommandHook } from \"./command-runner.ts\";\nimport { matchingHookHandlers } from \"./matcher.ts\";\nimport { type ParsedHookOutput, parseHookOutput } from \"./output-parser.ts\";\nimport { type HookOutputPolicy, validateHookHandlerSafety } from \"./safety.ts\";\nimport { type HookTrustOptions, type HookTrustRecord, listHookTrustRecords } from \"./trust.ts\";\nimport type {\n\tExecutableHookHandler,\n\tHookDiagnostic,\n\tHookInputWire,\n\tHookSourceMetadata,\n\tHookTrustState,\n} from \"./types.ts\";\n\nexport type HookCommandRunner = (\n\thandler: ExecutableHookHandler,\n\tinput: HookInputWire,\n\toptions: CommandHookRunOptions,\n) => Promise<CommandHookRunResult>;\n\nexport type HookDispatchDecision =\n\t| { readonly kind: \"none\" }\n\t| {\n\t\t\treadonly kind: \"allow\" | \"block\";\n\t\t\treadonly reason?: string;\n\t\t\treadonly source: HookSourceMetadata;\n\t\t\treadonly sourceCommand: string;\n\t\t\treadonly updatedInput?: unknown;\n\t }\n\t| {\n\t\t\treadonly fallback: { readonly kind: \"block\"; readonly reason: string };\n\t\t\treadonly kind: \"ask\";\n\t\t\treadonly nativeRepresentable: false;\n\t\t\treadonly reason?: string;\n\t\t\treadonly source: HookSourceMetadata;\n\t\t\treadonly sourceCommand: string;\n\t };\n\nexport type HookDispatchSkipped = {\n\treadonly diagnostics: readonly HookDiagnostic[];\n\treadonly handler: ExecutableHookHandler;\n\treadonly reason: \"disabled\" | \"untrusted\" | \"unsafe\";\n\treadonly record: HookTrustRecord;\n};\n\nexport type HookDispatchSummary = {\n\treadonly completionIndex: number;\n\treadonly diagnostics: readonly HookDiagnostic[];\n\treadonly handler: ExecutableHookHandler;\n\treadonly output: ParsedHookOutput[\"output\"];\n\treadonly run: CommandHookRunResult;\n};\n\nexport type HookDispatchResult = {\n\treadonly decision: HookDispatchDecision;\n\treadonly diagnostics: readonly HookDiagnostic[];\n\treadonly executableHandlers: readonly ExecutableHookHandler[];\n\treadonly matchedHandlers: readonly ExecutableHookHandler[];\n\treadonly skipped: readonly HookDispatchSkipped[];\n\treadonly summaries: readonly HookDispatchSummary[];\n};\n\nexport type HookDispatchOptions = {\n\treadonly cwd: string;\n\treadonly envPassthrough?: readonly string[];\n\treadonly handlers: readonly ExecutableHookHandler[];\n\treadonly input: HookInputWire;\n\treadonly outputPolicy?: HookOutputPolicy;\n\treadonly runCommand?: HookCommandRunner;\n\treadonly signal?: AbortSignal;\n\treadonly sourceEnv?: NodeJS.ProcessEnv;\n\treadonly trustOptions?: HookTrustOptions;\n\treadonly trustState: HookTrustState;\n};\n\ntype OrderedHandler = {\n\treadonly declarationIndex: number;\n\treadonly handler: ExecutableHookHandler;\n};\n\ntype RunnableHandler = OrderedHandler & {\n\treadonly record: HookTrustRecord;\n};\n\nexport async function dispatchHookEvent(options: HookDispatchOptions): Promise<HookDispatchResult> {\n\tconst match = matchingHookHandlers(options.input, options.handlers);\n\tconst ordered = declarationOrdered(match.handlers);\n\tconst selected = selectExecutableHandlers(ordered, options.trustState, options.trustOptions);\n\tlet nextCompletionIndex = 0;\n\tconst runner = options.runCommand ?? runCommandHook;\n\tconst completed = await Promise.all(\n\t\tselected.runnable.map(async ({ handler, declarationIndex }) => {\n\t\t\tconst run = await runner(handler, options.input, {\n\t\t\t\tcwd: options.cwd,\n\t\t\t\t...(options.envPassthrough === undefined ? {} : { envPassthrough: options.envPassthrough }),\n\t\t\t\t...(options.outputPolicy === undefined ? {} : { outputPolicy: options.outputPolicy }),\n\t\t\t\t...(options.signal === undefined ? {} : { signal: options.signal }),\n\t\t\t\t...(options.sourceEnv === undefined ? {} : { sourceEnv: options.sourceEnv }),\n\t\t\t});\n\t\t\tconst parsed = parseHookOutput({\n\t\t\t\tevent: options.input.event,\n\t\t\t\texitCode: run.exitCode ?? 1,\n\t\t\t\tsource: handler.source,\n\t\t\t\tstderr: run.stderr,\n\t\t\t\tstdout: run.stdout,\n\t\t\t});\n\t\t\tconst completionIndex = nextCompletionIndex;\n\t\t\tnextCompletionIndex += 1;\n\t\t\treturn { completionIndex, declarationIndex, handler, parsed, run };\n\t\t}),\n\t);\n\tconst declarationSummaries = completed\n\t\t.toSorted((left, right) => left.declarationIndex - right.declarationIndex)\n\t\t.map((run) => ({\n\t\t\tcompletionIndex: run.completionIndex,\n\t\t\tdiagnostics: run.parsed.diagnostics,\n\t\t\thandler: run.handler,\n\t\t\toutput: run.parsed.output,\n\t\t\trun: run.run,\n\t\t}));\n\tconst diagnostics = [\n\t\t...match.diagnostics,\n\t\t...selected.skipped.flatMap((skip) => skip.diagnostics),\n\t\t...declarationSummaries.flatMap((summary) => summary.diagnostics),\n\t];\n\treturn {\n\t\tdecision: aggregateDecision(options.input.event, declarationSummaries),\n\t\tdiagnostics,\n\t\texecutableHandlers: selected.runnable.map((item) => item.handler),\n\t\tmatchedHandlers: ordered.map((item) => item.handler),\n\t\tskipped: selected.skipped,\n\t\tsummaries: declarationSummaries,\n\t};\n}\n\nfunction declarationOrdered(handlers: readonly ExecutableHookHandler[]): readonly OrderedHandler[] {\n\treturn handlers\n\t\t.map((handler, index) => ({ declarationIndex: index, handler }))\n\t\t.toSorted(\n\t\t\t(left, right) =>\n\t\t\t\tcompareHandlers(left.handler, right.handler) || left.declarationIndex - right.declarationIndex,\n\t\t);\n}\n\nfunction compareHandlers(left: ExecutableHookHandler, right: ExecutableHookHandler): number {\n\treturn (\n\t\tleft.source.displayOrder - right.source.displayOrder ||\n\t\tleft.groupIndex - right.groupIndex ||\n\t\tleft.handlerIndex - right.handlerIndex\n\t);\n}\n\nfunction selectExecutableHandlers(\n\thandlers: readonly OrderedHandler[],\n\ttrustState: HookTrustState,\n\ttrustOptions: HookTrustOptions | undefined,\n): { readonly runnable: readonly RunnableHandler[]; readonly skipped: readonly HookDispatchSkipped[] } {\n\tconst records = listHookTrustRecords(\n\t\thandlers.map((item) => item.handler),\n\t\ttrustState,\n\t\ttrustOptions,\n\t);\n\tconst runnable: RunnableHandler[] = [];\n\tconst skipped: HookDispatchSkipped[] = [];\n\tfor (const [index, item] of handlers.entries()) {\n\t\tconst record = records[index];\n\t\tif (record === undefined) continue;\n\t\tconst safetyDiagnostics = validateHookHandlerSafety(item.handler);\n\t\tconst unsafe = safetyDiagnostics.some((diagnostic) => diagnostic.severity === \"error\");\n\t\tif (unsafe) {\n\t\t\tskipped.push({ diagnostics: safetyDiagnostics, handler: item.handler, reason: \"unsafe\", record });\n\t\t\tcontinue;\n\t\t}\n\t\tif (!record.enabled) {\n\t\t\tskipped.push({ diagnostics: [], handler: item.handler, reason: \"disabled\", record });\n\t\t\tcontinue;\n\t\t}\n\t\tif (!record.trusted) {\n\t\t\tskipped.push({ diagnostics: [], handler: item.handler, reason: \"untrusted\", record });\n\t\t\tcontinue;\n\t\t}\n\t\trunnable.push({ ...item, record });\n\t}\n\treturn { runnable, skipped };\n}\n\nfunction aggregateDecision(\n\tevent: HookInputWire[\"event\"],\n\tsummaries: readonly HookDispatchSummary[],\n): HookDispatchDecision {\n\tswitch (event) {\n\t\tcase \"PreToolUse\":\n\t\t\treturn aggregatePreToolUseDecision(summaries);\n\t\tcase \"PostToolUse\":\n\t\tcase \"UserPromptSubmit\":\n\t\tcase \"SessionStart\":\n\t\tcase \"PreCompact\":\n\t\tcase \"PostCompact\":\n\t\tcase \"Stop\":\n\t\t\treturn aggregateBlockingDecision(summaries);\n\t}\n}\n\nfunction aggregatePreToolUseDecision(summaries: readonly HookDispatchSummary[]): HookDispatchDecision {\n\tconst blocker = summaries.find(hasBlockingDecision);\n\tif (blocker !== undefined) {\n\t\treturn decisionWithSource(\"block\", blocker, blocker.output.reason);\n\t}\n\tconst ask = summaries.find((summary) => summary.output.decision === \"ask\");\n\tif (ask !== undefined) {\n\t\tconst reason = ask.output.reason ?? \"Hook requested manual approval.\";\n\t\treturn {\n\t\t\tfallback: { kind: \"block\", reason },\n\t\t\tkind: \"ask\",\n\t\t\tnativeRepresentable: false,\n\t\t\t...reasonField(ask.output.reason),\n\t\t\tsource: ask.handler.source,\n\t\t\tsourceCommand: ask.handler.config.command,\n\t\t};\n\t}\n\tlet allowSummary: HookDispatchSummary | undefined;\n\tfor (const summary of summaries) {\n\t\tif (summary.output.decision === \"allow\" || summary.output.decision === \"approve\") allowSummary = summary;\n\t}\n\tif (allowSummary !== undefined) {\n\t\treturn decisionWithSource(\"allow\", allowSummary, undefined, allowSummary.output.updatedInput);\n\t}\n\treturn { kind: \"none\" };\n}\n\nfunction aggregateBlockingDecision(summaries: readonly HookDispatchSummary[]): HookDispatchDecision {\n\tconst blocker = summaries.find(hasBlockingDecision);\n\tif (blocker !== undefined) {\n\t\treturn decisionWithSource(\"block\", blocker, blocker.output.reason ?? blocker.output.stopReason);\n\t}\n\treturn { kind: \"none\" };\n}\n\nfunction hasBlockingDecision(summary: HookDispatchSummary): boolean {\n\treturn summary.output.decision === \"block\" || summary.output.decision === \"deny\";\n}\n\nfunction decisionWithSource(\n\tkind: \"allow\" | \"block\",\n\tsummary: HookDispatchSummary,\n\treason: string | undefined,\n\tupdatedInput?: unknown,\n): HookDispatchDecision {\n\treturn {\n\t\tkind,\n\t\t...reasonField(reason),\n\t\tsource: summary.handler.source,\n\t\tsourceCommand: summary.handler.config.command,\n\t\t...updatedInputField(updatedInput),\n\t};\n}\n\nfunction reasonField(reason: string | undefined): { readonly reason?: string } {\n\tif (reason === undefined) {\n\t\treturn {};\n\t}\n\treturn { reason };\n}\n\nfunction updatedInputField(updatedInput: unknown): { readonly updatedInput?: unknown } {\n\tif (updatedInput === undefined) {\n\t\treturn {};\n\t}\n\treturn { updatedInput };\n}\n"]}
1
+ {"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/hooks/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAyD,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC5G,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAyB,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAyB,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAA+C,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAgF/F,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAA4B;IACnE,MAAM,KAAK,GAAG,oBAAoB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpE,MAAM,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC7F,IAAI,mBAAmB,GAAG,CAAC,CAAC;IAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,IAAI,cAAc,CAAC;IACpD,MAAM,mBAAmB,GAAG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;IACD,OAAO,EAAE,YAAY,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import { stripAnsi } from \"../../../../utils/ansi.ts\";\nimport { type CommandHookRunOptions, type CommandHookRunResult, runCommandHook } from \"./command-runner.ts\";\nimport { matchingHookHandlers } from \"./matcher.ts\";\nimport { type ParsedHookOutput, parseHookOutput } from \"./output-parser.ts\";\nimport { type HookOutputPolicy, validateHookHandlerSafety } from \"./safety.ts\";\nimport { type HookTrustOptions, type HookTrustRecord, listHookTrustRecords } from \"./trust.ts\";\nimport type {\n\tExecutableHookHandler,\n\tHookDiagnostic,\n\tHookInputWire,\n\tHookSourceMetadata,\n\tHookTrustState,\n} from \"./types.ts\";\n\nexport type HookCommandRunner = (\n\thandler: ExecutableHookHandler,\n\tinput: HookInputWire,\n\toptions: CommandHookRunOptions,\n) => Promise<CommandHookRunResult>;\n\nexport type HookDispatchDecision =\n\t| { readonly kind: \"none\" }\n\t| {\n\t\t\treadonly kind: \"allow\" | \"block\";\n\t\t\treadonly reason?: string;\n\t\t\treadonly source: HookSourceMetadata;\n\t\t\treadonly sourceCommand: string;\n\t\t\treadonly updatedInput?: unknown;\n\t }\n\t| {\n\t\t\treadonly fallback: { readonly kind: \"block\"; readonly reason: string };\n\t\t\treadonly kind: \"ask\";\n\t\t\treadonly nativeRepresentable: false;\n\t\t\treadonly reason?: string;\n\t\t\treadonly source: HookSourceMetadata;\n\t\t\treadonly sourceCommand: string;\n\t };\n\nexport type HookDispatchSkipped = {\n\treadonly diagnostics: readonly HookDiagnostic[];\n\treadonly handler: ExecutableHookHandler;\n\treadonly reason: \"disabled\" | \"untrusted\" | \"unsafe\";\n\treadonly record: HookTrustRecord;\n};\n\nexport type HookDispatchSummary = {\n\treadonly completionIndex: number;\n\treadonly diagnostics: readonly HookDiagnostic[];\n\treadonly handler: ExecutableHookHandler;\n\treadonly output: ParsedHookOutput[\"output\"];\n\treadonly run: CommandHookRunResult;\n};\n\nexport type HookDispatchResult = {\n\treadonly decision: HookDispatchDecision;\n\treadonly diagnostics: readonly HookDiagnostic[];\n\treadonly executableHandlers: readonly ExecutableHookHandler[];\n\treadonly matchedHandlers: readonly ExecutableHookHandler[];\n\treadonly skipped: readonly HookDispatchSkipped[];\n\treadonly summaries: readonly HookDispatchSummary[];\n};\n\nexport type HookDispatchOptions = {\n\treadonly cwd: string;\n\treadonly envPassthrough?: readonly string[];\n\treadonly handlers: readonly ExecutableHookHandler[];\n\treadonly input: HookInputWire;\n\treadonly onRunningHandlersChange?: (running: readonly ExecutableHookHandler[]) => void;\n\treadonly outputPolicy?: HookOutputPolicy;\n\treadonly runCommand?: HookCommandRunner;\n\treadonly signal?: AbortSignal;\n\treadonly sourceEnv?: NodeJS.ProcessEnv;\n\treadonly trustOptions?: HookTrustOptions;\n\treadonly trustState: HookTrustState;\n};\n\ntype OrderedHandler = {\n\treadonly declarationIndex: number;\n\treadonly handler: ExecutableHookHandler;\n};\n\ntype RunnableHandler = OrderedHandler & {\n\treadonly record: HookTrustRecord;\n};\n\nexport async function dispatchHookEvent(options: HookDispatchOptions): Promise<HookDispatchResult> {\n\tconst match = matchingHookHandlers(options.input, options.handlers);\n\tconst ordered = declarationOrdered(match.handlers);\n\tconst selected = selectExecutableHandlers(ordered, options.trustState, options.trustOptions);\n\tlet nextCompletionIndex = 0;\n\tconst runner = options.runCommand ?? runCommandHook;\n\tconst notifyRunningChange = options.onRunningHandlersChange;\n\tconst runningHandlers: ExecutableHookHandler[] = [];\n\tconst completed = await Promise.all(\n\t\tselected.runnable.map(async ({ handler, declarationIndex }) => {\n\t\t\tif (notifyRunningChange !== undefined) {\n\t\t\t\trunningHandlers.push(handler);\n\t\t\t\tnotifyRunningChange([...runningHandlers]);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst run = await runner(handler, options.input, {\n\t\t\t\t\tcwd: options.cwd,\n\t\t\t\t\t...(options.envPassthrough === undefined ? {} : { envPassthrough: options.envPassthrough }),\n\t\t\t\t\t...(options.outputPolicy === undefined ? {} : { outputPolicy: options.outputPolicy }),\n\t\t\t\t\t...(options.signal === undefined ? {} : { signal: options.signal }),\n\t\t\t\t\t...(options.sourceEnv === undefined ? {} : { sourceEnv: options.sourceEnv }),\n\t\t\t\t});\n\t\t\t\tconst parsed = parseHookOutput({\n\t\t\t\t\tevent: options.input.event,\n\t\t\t\t\texitCode: run.exitCode ?? 1,\n\t\t\t\t\tsource: handler.source,\n\t\t\t\t\tstderr: run.stderr,\n\t\t\t\t\tstdout: run.stdout,\n\t\t\t\t});\n\t\t\t\tconst completionIndex = nextCompletionIndex;\n\t\t\t\tnextCompletionIndex += 1;\n\t\t\t\treturn { completionIndex, declarationIndex, handler, parsed, run };\n\t\t\t} finally {\n\t\t\t\tif (notifyRunningChange !== undefined) {\n\t\t\t\t\tconst runningIndex = runningHandlers.indexOf(handler);\n\t\t\t\t\tif (runningIndex !== -1) {\n\t\t\t\t\t\trunningHandlers.splice(runningIndex, 1);\n\t\t\t\t\t}\n\t\t\t\t\tnotifyRunningChange([...runningHandlers]);\n\t\t\t\t}\n\t\t\t}\n\t\t}),\n\t);\n\tconst declarationSummaries = completed\n\t\t.toSorted((left, right) => left.declarationIndex - right.declarationIndex)\n\t\t.map((run) => ({\n\t\t\tcompletionIndex: run.completionIndex,\n\t\t\tdiagnostics: run.parsed.diagnostics,\n\t\t\thandler: run.handler,\n\t\t\toutput: run.parsed.output,\n\t\t\trun: run.run,\n\t\t}));\n\tconst diagnostics = [\n\t\t...match.diagnostics,\n\t\t...selected.skipped.flatMap((skip) => skip.diagnostics),\n\t\t...declarationSummaries.flatMap((summary) => summary.diagnostics),\n\t];\n\treturn {\n\t\tdecision: aggregateDecision(options.input.event, declarationSummaries),\n\t\tdiagnostics,\n\t\texecutableHandlers: selected.runnable.map((item) => item.handler),\n\t\tmatchedHandlers: ordered.map((item) => item.handler),\n\t\tskipped: selected.skipped,\n\t\tsummaries: declarationSummaries,\n\t};\n}\n\nexport function runningHookHandlersStatusLabel(\n\thandlers: readonly ExecutableHookHandler[],\n\tplatform: NodeJS.Platform = process.platform,\n): string {\n\tconst label = handlers.map((handler) => hookHandlerStatusLabel(handler, platform)).join(\" · \");\n\treturn label.length <= 79 ? label : `${label.slice(0, 76)}...`;\n}\n\nfunction hookHandlerStatusLabel(handler: ExecutableHookHandler, platform: NodeJS.Platform): string {\n\tconst raw =\n\t\thandler.config.statusMessage ??\n\t\t(platform === \"win32\" && handler.config.commandWindows !== undefined\n\t\t\t? handler.config.commandWindows\n\t\t\t: handler.config.command);\n\treturn stripAnsi(raw)\n\t\t.replace(/[\\r\\n\\t]+/g, \" \")\n\t\t.replace(/[\\u0000-\\u001f\\u007f]+/g, \"\")\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim();\n}\n\nfunction declarationOrdered(handlers: readonly ExecutableHookHandler[]): readonly OrderedHandler[] {\n\treturn handlers\n\t\t.map((handler, index) => ({ declarationIndex: index, handler }))\n\t\t.toSorted(\n\t\t\t(left, right) =>\n\t\t\t\tcompareHandlers(left.handler, right.handler) || left.declarationIndex - right.declarationIndex,\n\t\t);\n}\n\nfunction compareHandlers(left: ExecutableHookHandler, right: ExecutableHookHandler): number {\n\treturn (\n\t\tleft.source.displayOrder - right.source.displayOrder ||\n\t\tleft.groupIndex - right.groupIndex ||\n\t\tleft.handlerIndex - right.handlerIndex\n\t);\n}\n\nfunction selectExecutableHandlers(\n\thandlers: readonly OrderedHandler[],\n\ttrustState: HookTrustState,\n\ttrustOptions: HookTrustOptions | undefined,\n): { readonly runnable: readonly RunnableHandler[]; readonly skipped: readonly HookDispatchSkipped[] } {\n\tconst records = listHookTrustRecords(\n\t\thandlers.map((item) => item.handler),\n\t\ttrustState,\n\t\ttrustOptions,\n\t);\n\tconst runnable: RunnableHandler[] = [];\n\tconst skipped: HookDispatchSkipped[] = [];\n\tfor (const [index, item] of handlers.entries()) {\n\t\tconst record = records[index];\n\t\tif (record === undefined) continue;\n\t\tconst safetyDiagnostics = validateHookHandlerSafety(item.handler);\n\t\tconst unsafe = safetyDiagnostics.some((diagnostic) => diagnostic.severity === \"error\");\n\t\tif (unsafe) {\n\t\t\tskipped.push({ diagnostics: safetyDiagnostics, handler: item.handler, reason: \"unsafe\", record });\n\t\t\tcontinue;\n\t\t}\n\t\tif (!record.enabled) {\n\t\t\tskipped.push({ diagnostics: [], handler: item.handler, reason: \"disabled\", record });\n\t\t\tcontinue;\n\t\t}\n\t\tif (!record.trusted) {\n\t\t\tskipped.push({ diagnostics: [], handler: item.handler, reason: \"untrusted\", record });\n\t\t\tcontinue;\n\t\t}\n\t\trunnable.push({ ...item, record });\n\t}\n\treturn { runnable, skipped };\n}\n\nfunction aggregateDecision(\n\tevent: HookInputWire[\"event\"],\n\tsummaries: readonly HookDispatchSummary[],\n): HookDispatchDecision {\n\tswitch (event) {\n\t\tcase \"PreToolUse\":\n\t\t\treturn aggregatePreToolUseDecision(summaries);\n\t\tcase \"PostToolUse\":\n\t\tcase \"UserPromptSubmit\":\n\t\tcase \"SessionStart\":\n\t\tcase \"PreCompact\":\n\t\tcase \"PostCompact\":\n\t\tcase \"Stop\":\n\t\t\treturn aggregateBlockingDecision(summaries);\n\t}\n}\n\nfunction aggregatePreToolUseDecision(summaries: readonly HookDispatchSummary[]): HookDispatchDecision {\n\tconst blocker = summaries.find(hasBlockingDecision);\n\tif (blocker !== undefined) {\n\t\treturn decisionWithSource(\"block\", blocker, blocker.output.reason);\n\t}\n\tconst ask = summaries.find((summary) => summary.output.decision === \"ask\");\n\tif (ask !== undefined) {\n\t\tconst reason = ask.output.reason ?? \"Hook requested manual approval.\";\n\t\treturn {\n\t\t\tfallback: { kind: \"block\", reason },\n\t\t\tkind: \"ask\",\n\t\t\tnativeRepresentable: false,\n\t\t\t...reasonField(ask.output.reason),\n\t\t\tsource: ask.handler.source,\n\t\t\tsourceCommand: ask.handler.config.command,\n\t\t};\n\t}\n\tlet allowSummary: HookDispatchSummary | undefined;\n\tfor (const summary of summaries) {\n\t\tif (summary.output.decision === \"allow\" || summary.output.decision === \"approve\") allowSummary = summary;\n\t}\n\tif (allowSummary !== undefined) {\n\t\treturn decisionWithSource(\"allow\", allowSummary, undefined, allowSummary.output.updatedInput);\n\t}\n\treturn { kind: \"none\" };\n}\n\nfunction aggregateBlockingDecision(summaries: readonly HookDispatchSummary[]): HookDispatchDecision {\n\tconst blocker = summaries.find(hasBlockingDecision);\n\tif (blocker !== undefined) {\n\t\treturn decisionWithSource(\"block\", blocker, blocker.output.reason ?? blocker.output.stopReason);\n\t}\n\treturn { kind: \"none\" };\n}\n\nfunction hasBlockingDecision(summary: HookDispatchSummary): boolean {\n\treturn summary.output.decision === \"block\" || summary.output.decision === \"deny\";\n}\n\nfunction decisionWithSource(\n\tkind: \"allow\" | \"block\",\n\tsummary: HookDispatchSummary,\n\treason: string | undefined,\n\tupdatedInput?: unknown,\n): HookDispatchDecision {\n\treturn {\n\t\tkind,\n\t\t...reasonField(reason),\n\t\tsource: summary.handler.source,\n\t\tsourceCommand: summary.handler.config.command,\n\t\t...updatedInputField(updatedInput),\n\t};\n}\n\nfunction reasonField(reason: string | undefined): { readonly reason?: string } {\n\tif (reason === undefined) {\n\t\treturn {};\n\t}\n\treturn { reason };\n}\n\nfunction updatedInputField(updatedInput: unknown): { readonly updatedInput?: unknown } {\n\tif (updatedInput === undefined) {\n\t\treturn {};\n\t}\n\treturn { updatedInput };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA+B,YAAY,EAAuC,MAAM,gBAAgB,CAAC;AAqCrH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EACX,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,GACzB,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAyM7D;AAmBD,OAAO,EACN,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,GAC7B,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA+B,YAAY,EAAuC,MAAM,gBAAgB,CAAC;AAqCrH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EACX,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,GACzB,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAiN7D;AAmBD,OAAO,EACN,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,GAC7B,MAAM,YAAY,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { registerHooksCommand } from "./command.js";
3
3
  import { loadHookConfigSources } from "./config-loader.js";
4
- import { dispatchHookEvent } from "./dispatcher.js";
4
+ import { dispatchHookEvent, runningHookHandlersStatusLabel } from "./dispatcher.js";
5
5
  import { buildPostCompactHookInput, buildPreCompactHookInput, buildSessionStartHookInput, dispatchLifecycleHookEvent, postCompactResultDetails, preCompactResultDetails, recordLifecycleHookResult, sessionBeforeCompactResult, sessionStartResultDetails, } from "./lifecycle-adapter.js";
6
6
  import { appendSystemMessages, buildUserPromptHookInput, formatPromptContextMessage, HOOK_CUSTOM_MESSAGE_TYPE, promptBlockReasonFromResult, promptContextFromResult, safeDiagnosticDetails, } from "./prompt-adapter.js";
7
7
  import { applyStopHookResult, buildStopHookInput, createStopTurnTracker } from "./stop-adapter.js";
@@ -125,6 +125,11 @@ export default function hooksExtension(pi) {
125
125
  cwd: ctx.cwd,
126
126
  handlers: state.parsed.executableHandlers,
127
127
  input: buildPreToolUseHookInput(event, ctx),
128
+ onRunningHandlersChange: (running) => {
129
+ if (running.length === 0)
130
+ return;
131
+ ctx.updateToolHookStatus?.(runningHookHandlersStatusLabel(running));
132
+ },
128
133
  signal: ctx.signal,
129
134
  trustOptions: { platform: process.platform },
130
135
  trustState: state.trust,
@@ -148,6 +153,11 @@ export default function hooksExtension(pi) {
148
153
  cwd: ctx.cwd,
149
154
  handlers: state.parsed.executableHandlers,
150
155
  input: buildPostToolUseHookInput(event, ctx),
156
+ onRunningHandlersChange: (running) => {
157
+ if (running.length === 0)
158
+ return;
159
+ ctx.updateToolHookStatus?.(runningHookHandlersStatusLabel(running));
160
+ },
151
161
  signal: ctx.signal,
152
162
  trustOptions: { platform: process.platform },
153
163
  trustState: state.trust,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EACN,yBAAyB,EACzB,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,EACzB,0BAA0B,EAC1B,yBAAyB,GACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,oBAAoB,EACpB,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EAExB,2BAA2B,EAC3B,uBAAuB,EACvB,qBAAq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rC,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,YAAY,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE;YAC5C,UAAU,EAAE,KAAK,CAAC,KAAK;SACvB,CAAC,CAAC;QACH,MAAM,mBAAmB,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;IAEH,oBAAoB,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,gBAAgB,CAAC,WAA2B,EAAE,YAA4B;IAClF,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,WAAW,CAAC,KAAK,EAAE,GAAG,YAAY,CAAC,KAAK,EAAE,EAAE,CAAC;AAC/E,CAAC;AAED,SAAS,mBAAmB,CAAC,GAAW;IACvC,OAAO;QACN,QAAQ,EAAE,GAAG;QACb,GAAG;QACH,qBAAqB,EAAE,EAAE;QACzB,eAAe,EAAE,GAAG,GAAG,aAAa;QACpC,yBAAyB,EAAE,EAAE;QAC7B,sBAAsB,EAAE,EAAE;QAC1B,gBAAgB,EAAE,GAAG,GAAG,oBAAoB;QAC5C,sBAAsB,EAAE,EAAE;KAC1B,CAAC;AACH,CAAC;AAED,OAAO,EACN,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,GAC7B,MAAM,YAAY,CAAC","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport type { BeforeAgentStartEventResult, ExtensionAPI, ExtensionContext, LoadedHookSources } from \"../../types.ts\";\nimport { registerHooksCommand } from \"./command.ts\";\nimport { loadHookConfigSources } from \"./config-loader.ts\";\nimport { dispatchHookEvent } from \"./dispatcher.ts\";\nimport {\n\tbuildPostCompactHookInput,\n\tbuildPreCompactHookInput,\n\tbuildSessionStartHookInput,\n\tdispatchLifecycleHookEvent,\n\tpostCompactResultDetails,\n\tpreCompactResultDetails,\n\trecordLifecycleHookResult,\n\tsessionBeforeCompactResult,\n\tsessionStartResultDetails,\n} from \"./lifecycle-adapter.ts\";\nimport {\n\tappendSystemMessages,\n\tbuildUserPromptHookInput,\n\tformatPromptContextMessage,\n\tHOOK_CUSTOM_MESSAGE_TYPE,\n\ttype PendingPromptHookContext,\n\tpromptBlockReasonFromResult,\n\tpromptContextFromResult,\n\tsafeDiagnosticDetails,\n} from \"./prompt-adapter.ts\";\nimport { applyStopHookResult, buildStopHookInput, createStopTurnTracker } from \"./stop-adapter.ts\";\nimport {\n\tapplyPostToolUseResult,\n\tapplyPreToolUseResult,\n\tbuildPostToolUseHookInput,\n\tbuildPreToolUseHookInput,\n\ttoolContextsFromResult,\n} from \"./tool-adapter.ts\";\nimport { emptyHookTrustState } from \"./trust.ts\";\nimport { FileHookStateStorage } from \"./trust-storage.ts\";\nimport type { HookTrustState } from \"./types.ts\";\n\nexport { parseHookConfig } from \"./schema.ts\";\nexport type {\n\tCommandHookConfig,\n\tExecutableHookHandler,\n\tHookDiagnostic,\n\tHookDiagnosticCode,\n\tHookInputWire,\n\tHookOutputWire,\n\tHookRuntimeState,\n\tHookSourceMetadata,\n\tHookTrustEntry,\n\tHookTrustState,\n\tParsedHookConfig,\n\tSupportedHookEvent,\n\tUnsupportedKnownHookEvent,\n} from \"./types.ts\";\n\nexport default function hooksExtension(pi: ExtensionAPI): void {\n\tconst pendingPromptContexts: PendingPromptHookContext[] = [];\n\tconst pendingPreToolContexts = new Map<string, readonly string[]>();\n\tconst stopTurnTracker = createStopTurnTracker();\n\n\tconst refreshState = (ctx: ExtensionContext) => {\n\t\tconst sources = ctx.getLoadedHookSources?.() ?? fallbackHookSources(ctx.cwd);\n\t\tconst parsed = loadHookConfigSources({\n\t\t\tagentDir: sources.agentDir,\n\t\t\tcwd: sources.cwd,\n\t\t\tfileSystem: {\n\t\t\t\treadTextFile(path) {\n\t\t\t\t\treturn existsSync(path) ? readFileSync(path, \"utf-8\") : undefined;\n\t\t\t\t},\n\t\t\t},\n\t\t\tglobalHookSourcePaths: sources.globalHookSourcePaths,\n\t\t\tglobalHooksPath: sources.globalHooksPath,\n\t\t\tglobalSettingsHooks: sources.globalSettingsHooks,\n\t\t\tpreSessionHookSourcePaths: sources.preSessionHookSourcePaths,\n\t\t\tprojectHookSourcePaths: sources.projectHookSourcePaths,\n\t\t\tprojectHooksPath: sources.projectHooksPath,\n\t\t\tprojectSettingsHooks: sources.projectSettingsHooks,\n\t\t\truntimeHookSourcePaths: sources.runtimeHookSourcePaths,\n\t\t});\n\t\tconst storage = new FileHookStateStorage({ agentDir: sources.agentDir, cwd: sources.cwd });\n\t\tconst trust = mergeTrustStates(\n\t\t\tstorage.read(\"global\"),\n\t\t\tctx.isProjectTrusted() ? storage.read(\"project\") : emptyHookTrustState(),\n\t\t);\n\t\treturn { parsed, trust, storage };\n\t};\n\n\tpi.on(\"session_start\", async (event, ctx) => {\n\t\tconst state = refreshState(ctx);\n\t\tconst input = buildSessionStartHookInput(event, ctx);\n\t\tconst result = await dispatchLifecycleHookEvent({\n\t\t\tcwd: ctx.cwd,\n\t\t\thandlers: state.parsed.executableHandlers,\n\t\t\tinput,\n\t\t\tmatcherInputs: [\"SessionStart\", event.reason],\n\t\t\t...(ctx.signal === undefined ? {} : { signal: ctx.signal }),\n\t\t\ttrustState: state.trust,\n\t\t});\n\t\trecordLifecycleHookResult(pi, \"SessionStart\", sessionStartResultDetails(result));\n\t});\n\n\tpi.on(\"input\", async (event, ctx) => {\n\t\tif (event.source === \"extension\") return undefined;\n\t\tstopTurnTracker.reset();\n\t\tpendingPromptContexts.splice(0);\n\t\tconst state = refreshState(ctx);\n\t\tconst input = buildUserPromptHookInput({\n\t\t\tcwd: ctx.cwd,\n\t\t\tpermissionMode: \"default\",\n\t\t\tprompt: event.text,\n\t\t\tsessionId: ctx.sessionManager.getSessionId(),\n\t\t\ttranscriptPath: ctx.sessionManager.getSessionFile(),\n\t\t});\n\t\tconst result = await dispatchHookEvent({\n\t\t\tcwd: ctx.cwd,\n\t\t\thandlers: state.parsed.executableHandlers,\n\t\t\tinput,\n\t\t\tsignal: ctx.signal,\n\t\t\ttrustOptions: { platform: process.platform },\n\t\t\ttrustState: state.trust,\n\t\t});\n\t\tif (result.decision.kind === \"block\") {\n\t\t\tconst reason = promptBlockReasonFromResult(result);\n\t\t\tctx.ui.notify(reason, \"warning\");\n\t\t\tpi.sendMessage(\n\t\t\t\t{\n\t\t\t\t\tcustomType: HOOK_CUSTOM_MESSAGE_TYPE,\n\t\t\t\t\tcontent: reason,\n\t\t\t\t\tdisplay: false,\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tdecision: \"block\",\n\t\t\t\t\t\tevent: \"UserPromptSubmit\",\n\t\t\t\t\t\tsourcePath: result.decision.source.sourcePath,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{ triggerTurn: false },\n\t\t\t);\n\t\t\treturn { action: \"handled\" };\n\t\t}\n\t\tif (ctx.isIdle()) {\n\t\t\tconst pending = promptContextFromResult(result);\n\t\t\tif (pending !== undefined) {\n\t\t\t\tpendingPromptContexts.push(pending);\n\t\t\t}\n\t\t}\n\t\treturn { action: \"continue\" };\n\t});\n\n\tpi.on(\"before_agent_start\", async (event) => {\n\t\tconst pending = pendingPromptContexts.shift();\n\t\tif (pending === undefined) return undefined;\n\n\t\tconst messageContent = formatPromptContextMessage(pending);\n\t\tconst systemPrompt = appendSystemMessages(event.systemPrompt, pending.systemMessages);\n\t\tif (messageContent === undefined && systemPrompt === event.systemPrompt) return undefined;\n\n\t\tconst result: BeforeAgentStartEventResult = {};\n\t\tif (messageContent !== undefined) {\n\t\t\tresult.message = {\n\t\t\t\tcustomType: HOOK_CUSTOM_MESSAGE_TYPE,\n\t\t\t\tcontent: messageContent,\n\t\t\t\tdisplay: false,\n\t\t\t\tdetails: {\n\t\t\t\t\tevent: \"UserPromptSubmit\",\n\t\t\t\t\tdiagnostics: pending.diagnostics.map(safeDiagnosticDetails),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tif (systemPrompt !== event.systemPrompt) {\n\t\t\tresult.systemPrompt = systemPrompt;\n\t\t}\n\t\treturn result;\n\t});\n\n\tpi.on(\"tool_call\", async (event, ctx) => {\n\t\tpendingPreToolContexts.delete(event.toolCallId);\n\t\tconst state = refreshState(ctx);\n\t\tconst result = await dispatchHookEvent({\n\t\t\tcwd: ctx.cwd,\n\t\t\thandlers: state.parsed.executableHandlers,\n\t\t\tinput: buildPreToolUseHookInput(event, ctx),\n\t\t\tsignal: ctx.signal,\n\t\t\ttrustOptions: { platform: process.platform },\n\t\t\ttrustState: state.trust,\n\t\t});\n\t\tconst toolResult = applyPreToolUseResult(event, result);\n\t\tif (toolResult?.block) {\n\t\t\tpendingPreToolContexts.delete(event.toolCallId);\n\t\t\treturn toolResult;\n\t\t}\n\t\tconst contexts = toolContextsFromResult(result);\n\t\tif (contexts.length > 0) {\n\t\t\tpendingPreToolContexts.set(event.toolCallId, contexts);\n\t\t}\n\t\treturn toolResult;\n\t});\n\n\tpi.on(\"tool_result\", async (event, ctx) => {\n\t\tconst preToolContexts = pendingPreToolContexts.get(event.toolCallId) ?? [];\n\t\tpendingPreToolContexts.delete(event.toolCallId);\n\t\tconst state = refreshState(ctx);\n\t\tconst result = await dispatchHookEvent({\n\t\t\tcwd: ctx.cwd,\n\t\t\thandlers: state.parsed.executableHandlers,\n\t\t\tinput: buildPostToolUseHookInput(event, ctx),\n\t\t\tsignal: ctx.signal,\n\t\t\ttrustOptions: { platform: process.platform },\n\t\t\ttrustState: state.trust,\n\t\t});\n\t\treturn applyPostToolUseResult(event, result, preToolContexts);\n\t});\n\n\tpi.on(\"session_before_compact\", async (event, ctx) => {\n\t\tconst state = refreshState(ctx);\n\t\tconst result = await dispatchLifecycleHookEvent({\n\t\t\tcwd: ctx.cwd,\n\t\t\thandlers: state.parsed.executableHandlers,\n\t\t\tinput: buildPreCompactHookInput(event, ctx),\n\t\t\tmatcherInputs: [\"PreCompact\", event.reason],\n\t\t\tsignal: event.signal,\n\t\t\ttrustState: state.trust,\n\t\t});\n\t\tconst details = preCompactResultDetails(result);\n\t\trecordLifecycleHookResult(pi, \"PreCompact\", details);\n\t\treturn sessionBeforeCompactResult(details);\n\t});\n\n\tpi.on(\"session_compact\", async (event, ctx) => {\n\t\tif (!event.accepted) return undefined;\n\t\tconst state = refreshState(ctx);\n\t\tconst result = await dispatchLifecycleHookEvent({\n\t\t\tcwd: ctx.cwd,\n\t\t\thandlers: state.parsed.executableHandlers,\n\t\t\tinput: buildPostCompactHookInput(event, ctx),\n\t\t\tmatcherInputs: [\"PostCompact\", event.reason],\n\t\t\t...(ctx.signal === undefined ? {} : { signal: ctx.signal }),\n\t\t\ttrustState: state.trust,\n\t\t});\n\t\trecordLifecycleHookResult(pi, \"PostCompact\", postCompactResultDetails(result));\n\t\treturn undefined;\n\t});\n\n\tpi.on(\"agent_end\", async (event, ctx) => {\n\t\tconst state = refreshState(ctx);\n\t\tconst result = await dispatchHookEvent({\n\t\t\tcwd: ctx.cwd,\n\t\t\thandlers: state.parsed.executableHandlers,\n\t\t\tinput: buildStopHookInput(event, ctx),\n\t\t\tsignal: ctx.signal,\n\t\t\ttrustOptions: { platform: process.platform },\n\t\t\ttrustState: state.trust,\n\t\t});\n\t\tawait applyStopHookResult(pi, ctx, result, stopTurnTracker.turnKey(ctx));\n\t});\n\n\tregisterHooksCommand(pi, refreshState);\n}\n\nfunction mergeTrustStates(globalState: HookTrustState, projectState: HookTrustState): HookTrustState {\n\treturn { version: 1, hooks: { ...globalState.hooks, ...projectState.hooks } };\n}\n\nfunction fallbackHookSources(cwd: string): LoadedHookSources {\n\treturn {\n\t\tagentDir: cwd,\n\t\tcwd,\n\t\tglobalHookSourcePaths: [],\n\t\tglobalHooksPath: `${cwd}/hooks.json`,\n\t\tpreSessionHookSourcePaths: [],\n\t\tprojectHookSourcePaths: [],\n\t\tprojectHooksPath: `${cwd}/.senpi/hooks.json`,\n\t\truntimeHookSourcePaths: [],\n\t};\n}\n\nexport {\n\tSUPPORTED_HOOK_EVENTS,\n\tUNSUPPORTED_HANDLER_TYPES,\n\tUNSUPPORTED_KNOWN_HOOK_EVENTS,\n} from \"./types.ts\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AACpF,OAAO,EACN,yBAAyB,EACzB,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,EACzB,0BAA0B,EAC1B,yBAAyB,GACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,oBAAoB,EACpB,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EAExB,2BAA2B,EAC3B,uBAAuB,EACvB,qBAAqB,GACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACnG,OAAO,EACN,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,wBAAwB,EACxB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAiB9C,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EAAgB;IACtD,MAAM,qBAAqB,GAA+B,EAAE,CAAC;IAC7D,MAAM,sBAAsB,GAAG,IAAI,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,CAAC,KAAK;SACvB,CAAC,CAAC;QACH,MAAM,mBAAmB,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;IAEH,oBAAoB,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,gBAAgB,CAAC,WAA2B,EAAE,YAA4B;IAClF,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,WAAW,CAAC,KAAK,EAAE,GAAG,YAAY,CAAC,KAAK,EAAE,EAAE,CAAC;AAC/E,CAAC;AAED,SAAS,mBAAmB,CAAC,GAAW;IACvC,OAAO;QACN,QAAQ,EAAE,GAAG;QACb,GAAG;QACH,qBAAqB,EAAE,EAAE;QACzB,eAAe,EAAE,GAAG,GAAG,aAAa;QACpC,yBAAyB,EAAE,EAAE;QAC7B,sBAAsB,EAAE,EAAE;QAC1B,gBAAgB,EAAE,GAAG,GAAG,oBAAoB;QAC5C,sBAAsB,EAAE,EAAE;KAC1B,CAAC;AACH,CAAC;AAED,OAAO,EACN,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,GAC7B,MAAM,YAAY,CAAC","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport type { BeforeAgentStartEventResult, ExtensionAPI, ExtensionContext, LoadedHookSources } from \"../../types.ts\";\nimport { registerHooksCommand } from \"./command.ts\";\nimport { loadHookConfigSources } from \"./config-loader.ts\";\nimport { dispatchHookEvent, runningHookHandlersStatusLabel } from \"./dispatcher.ts\";\nimport {\n\tbuildPostCompactHookInput,\n\tbuildPreCompactHookInput,\n\tbuildSessionStartHookInput,\n\tdispatchLifecycleHookEvent,\n\tpostCompactResultDetails,\n\tpreCompactResultDetails,\n\trecordLifecycleHookResult,\n\tsessionBeforeCompactResult,\n\tsessionStartResultDetails,\n} from \"./lifecycle-adapter.ts\";\nimport {\n\tappendSystemMessages,\n\tbuildUserPromptHookInput,\n\tformatPromptContextMessage,\n\tHOOK_CUSTOM_MESSAGE_TYPE,\n\ttype PendingPromptHookContext,\n\tpromptBlockReasonFromResult,\n\tpromptContextFromResult,\n\tsafeDiagnosticDetails,\n} from \"./prompt-adapter.ts\";\nimport { applyStopHookResult, buildStopHookInput, createStopTurnTracker } from \"./stop-adapter.ts\";\nimport {\n\tapplyPostToolUseResult,\n\tapplyPreToolUseResult,\n\tbuildPostToolUseHookInput,\n\tbuildPreToolUseHookInput,\n\ttoolContextsFromResult,\n} from \"./tool-adapter.ts\";\nimport { emptyHookTrustState } from \"./trust.ts\";\nimport { FileHookStateStorage } from \"./trust-storage.ts\";\nimport type { HookTrustState } from \"./types.ts\";\n\nexport { parseHookConfig } from \"./schema.ts\";\nexport type {\n\tCommandHookConfig,\n\tExecutableHookHandler,\n\tHookDiagnostic,\n\tHookDiagnosticCode,\n\tHookInputWire,\n\tHookOutputWire,\n\tHookRuntimeState,\n\tHookSourceMetadata,\n\tHookTrustEntry,\n\tHookTrustState,\n\tParsedHookConfig,\n\tSupportedHookEvent,\n\tUnsupportedKnownHookEvent,\n} from \"./types.ts\";\n\nexport default function hooksExtension(pi: ExtensionAPI): void {\n\tconst pendingPromptContexts: PendingPromptHookContext[] = [];\n\tconst pendingPreToolContexts = new Map<string, readonly string[]>();\n\tconst stopTurnTracker = createStopTurnTracker();\n\n\tconst refreshState = (ctx: ExtensionContext) => {\n\t\tconst sources = ctx.getLoadedHookSources?.() ?? fallbackHookSources(ctx.cwd);\n\t\tconst parsed = loadHookConfigSources({\n\t\t\tagentDir: sources.agentDir,\n\t\t\tcwd: sources.cwd,\n\t\t\tfileSystem: {\n\t\t\t\treadTextFile(path) {\n\t\t\t\t\treturn existsSync(path) ? readFileSync(path, \"utf-8\") : undefined;\n\t\t\t\t},\n\t\t\t},\n\t\t\tglobalHookSourcePaths: sources.globalHookSourcePaths,\n\t\t\tglobalHooksPath: sources.globalHooksPath,\n\t\t\tglobalSettingsHooks: sources.globalSettingsHooks,\n\t\t\tpreSessionHookSourcePaths: sources.preSessionHookSourcePaths,\n\t\t\tprojectHookSourcePaths: sources.projectHookSourcePaths,\n\t\t\tprojectHooksPath: sources.projectHooksPath,\n\t\t\tprojectSettingsHooks: sources.projectSettingsHooks,\n\t\t\truntimeHookSourcePaths: sources.runtimeHookSourcePaths,\n\t\t});\n\t\tconst storage = new FileHookStateStorage({ agentDir: sources.agentDir, cwd: sources.cwd });\n\t\tconst trust = mergeTrustStates(\n\t\t\tstorage.read(\"global\"),\n\t\t\tctx.isProjectTrusted() ? storage.read(\"project\") : emptyHookTrustState(),\n\t\t);\n\t\treturn { parsed, trust, storage };\n\t};\n\n\tpi.on(\"session_start\", async (event, ctx) => {\n\t\tconst state = refreshState(ctx);\n\t\tconst input = buildSessionStartHookInput(event, ctx);\n\t\tconst result = await dispatchLifecycleHookEvent({\n\t\t\tcwd: ctx.cwd,\n\t\t\thandlers: state.parsed.executableHandlers,\n\t\t\tinput,\n\t\t\tmatcherInputs: [\"SessionStart\", event.reason],\n\t\t\t...(ctx.signal === undefined ? {} : { signal: ctx.signal }),\n\t\t\ttrustState: state.trust,\n\t\t});\n\t\trecordLifecycleHookResult(pi, \"SessionStart\", sessionStartResultDetails(result));\n\t});\n\n\tpi.on(\"input\", async (event, ctx) => {\n\t\tif (event.source === \"extension\") return undefined;\n\t\tstopTurnTracker.reset();\n\t\tpendingPromptContexts.splice(0);\n\t\tconst state = refreshState(ctx);\n\t\tconst input = buildUserPromptHookInput({\n\t\t\tcwd: ctx.cwd,\n\t\t\tpermissionMode: \"default\",\n\t\t\tprompt: event.text,\n\t\t\tsessionId: ctx.sessionManager.getSessionId(),\n\t\t\ttranscriptPath: ctx.sessionManager.getSessionFile(),\n\t\t});\n\t\tconst result = await dispatchHookEvent({\n\t\t\tcwd: ctx.cwd,\n\t\t\thandlers: state.parsed.executableHandlers,\n\t\t\tinput,\n\t\t\tsignal: ctx.signal,\n\t\t\ttrustOptions: { platform: process.platform },\n\t\t\ttrustState: state.trust,\n\t\t});\n\t\tif (result.decision.kind === \"block\") {\n\t\t\tconst reason = promptBlockReasonFromResult(result);\n\t\t\tctx.ui.notify(reason, \"warning\");\n\t\t\tpi.sendMessage(\n\t\t\t\t{\n\t\t\t\t\tcustomType: HOOK_CUSTOM_MESSAGE_TYPE,\n\t\t\t\t\tcontent: reason,\n\t\t\t\t\tdisplay: false,\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tdecision: \"block\",\n\t\t\t\t\t\tevent: \"UserPromptSubmit\",\n\t\t\t\t\t\tsourcePath: result.decision.source.sourcePath,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{ triggerTurn: false },\n\t\t\t);\n\t\t\treturn { action: \"handled\" };\n\t\t}\n\t\tif (ctx.isIdle()) {\n\t\t\tconst pending = promptContextFromResult(result);\n\t\t\tif (pending !== undefined) {\n\t\t\t\tpendingPromptContexts.push(pending);\n\t\t\t}\n\t\t}\n\t\treturn { action: \"continue\" };\n\t});\n\n\tpi.on(\"before_agent_start\", async (event) => {\n\t\tconst pending = pendingPromptContexts.shift();\n\t\tif (pending === undefined) return undefined;\n\n\t\tconst messageContent = formatPromptContextMessage(pending);\n\t\tconst systemPrompt = appendSystemMessages(event.systemPrompt, pending.systemMessages);\n\t\tif (messageContent === undefined && systemPrompt === event.systemPrompt) return undefined;\n\n\t\tconst result: BeforeAgentStartEventResult = {};\n\t\tif (messageContent !== undefined) {\n\t\t\tresult.message = {\n\t\t\t\tcustomType: HOOK_CUSTOM_MESSAGE_TYPE,\n\t\t\t\tcontent: messageContent,\n\t\t\t\tdisplay: false,\n\t\t\t\tdetails: {\n\t\t\t\t\tevent: \"UserPromptSubmit\",\n\t\t\t\t\tdiagnostics: pending.diagnostics.map(safeDiagnosticDetails),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tif (systemPrompt !== event.systemPrompt) {\n\t\t\tresult.systemPrompt = systemPrompt;\n\t\t}\n\t\treturn result;\n\t});\n\n\tpi.on(\"tool_call\", async (event, ctx) => {\n\t\tpendingPreToolContexts.delete(event.toolCallId);\n\t\tconst state = refreshState(ctx);\n\t\tconst result = await dispatchHookEvent({\n\t\t\tcwd: ctx.cwd,\n\t\t\thandlers: state.parsed.executableHandlers,\n\t\t\tinput: buildPreToolUseHookInput(event, ctx),\n\t\t\tonRunningHandlersChange: (running) => {\n\t\t\t\tif (running.length === 0) return;\n\t\t\t\tctx.updateToolHookStatus?.(runningHookHandlersStatusLabel(running));\n\t\t\t},\n\t\t\tsignal: ctx.signal,\n\t\t\ttrustOptions: { platform: process.platform },\n\t\t\ttrustState: state.trust,\n\t\t});\n\t\tconst toolResult = applyPreToolUseResult(event, result);\n\t\tif (toolResult?.block) {\n\t\t\tpendingPreToolContexts.delete(event.toolCallId);\n\t\t\treturn toolResult;\n\t\t}\n\t\tconst contexts = toolContextsFromResult(result);\n\t\tif (contexts.length > 0) {\n\t\t\tpendingPreToolContexts.set(event.toolCallId, contexts);\n\t\t}\n\t\treturn toolResult;\n\t});\n\n\tpi.on(\"tool_result\", async (event, ctx) => {\n\t\tconst preToolContexts = pendingPreToolContexts.get(event.toolCallId) ?? [];\n\t\tpendingPreToolContexts.delete(event.toolCallId);\n\t\tconst state = refreshState(ctx);\n\t\tconst result = await dispatchHookEvent({\n\t\t\tcwd: ctx.cwd,\n\t\t\thandlers: state.parsed.executableHandlers,\n\t\t\tinput: buildPostToolUseHookInput(event, ctx),\n\t\t\tonRunningHandlersChange: (running) => {\n\t\t\t\tif (running.length === 0) return;\n\t\t\t\tctx.updateToolHookStatus?.(runningHookHandlersStatusLabel(running));\n\t\t\t},\n\t\t\tsignal: ctx.signal,\n\t\t\ttrustOptions: { platform: process.platform },\n\t\t\ttrustState: state.trust,\n\t\t});\n\t\treturn applyPostToolUseResult(event, result, preToolContexts);\n\t});\n\n\tpi.on(\"session_before_compact\", async (event, ctx) => {\n\t\tconst state = refreshState(ctx);\n\t\tconst result = await dispatchLifecycleHookEvent({\n\t\t\tcwd: ctx.cwd,\n\t\t\thandlers: state.parsed.executableHandlers,\n\t\t\tinput: buildPreCompactHookInput(event, ctx),\n\t\t\tmatcherInputs: [\"PreCompact\", event.reason],\n\t\t\tsignal: event.signal,\n\t\t\ttrustState: state.trust,\n\t\t});\n\t\tconst details = preCompactResultDetails(result);\n\t\trecordLifecycleHookResult(pi, \"PreCompact\", details);\n\t\treturn sessionBeforeCompactResult(details);\n\t});\n\n\tpi.on(\"session_compact\", async (event, ctx) => {\n\t\tif (!event.accepted) return undefined;\n\t\tconst state = refreshState(ctx);\n\t\tconst result = await dispatchLifecycleHookEvent({\n\t\t\tcwd: ctx.cwd,\n\t\t\thandlers: state.parsed.executableHandlers,\n\t\t\tinput: buildPostCompactHookInput(event, ctx),\n\t\t\tmatcherInputs: [\"PostCompact\", event.reason],\n\t\t\t...(ctx.signal === undefined ? {} : { signal: ctx.signal }),\n\t\t\ttrustState: state.trust,\n\t\t});\n\t\trecordLifecycleHookResult(pi, \"PostCompact\", postCompactResultDetails(result));\n\t\treturn undefined;\n\t});\n\n\tpi.on(\"agent_end\", async (event, ctx) => {\n\t\tconst state = refreshState(ctx);\n\t\tconst result = await dispatchHookEvent({\n\t\t\tcwd: ctx.cwd,\n\t\t\thandlers: state.parsed.executableHandlers,\n\t\t\tinput: buildStopHookInput(event, ctx),\n\t\t\tsignal: ctx.signal,\n\t\t\ttrustOptions: { platform: process.platform },\n\t\t\ttrustState: state.trust,\n\t\t});\n\t\tawait applyStopHookResult(pi, ctx, result, stopTurnTracker.turnKey(ctx));\n\t});\n\n\tregisterHooksCommand(pi, refreshState);\n}\n\nfunction mergeTrustStates(globalState: HookTrustState, projectState: HookTrustState): HookTrustState {\n\treturn { version: 1, hooks: { ...globalState.hooks, ...projectState.hooks } };\n}\n\nfunction fallbackHookSources(cwd: string): LoadedHookSources {\n\treturn {\n\t\tagentDir: cwd,\n\t\tcwd,\n\t\tglobalHookSourcePaths: [],\n\t\tglobalHooksPath: `${cwd}/hooks.json`,\n\t\tpreSessionHookSourcePaths: [],\n\t\tprojectHookSourcePaths: [],\n\t\tprojectHooksPath: `${cwd}/.senpi/hooks.json`,\n\t\truntimeHookSourcePaths: [],\n\t};\n}\n\nexport {\n\tSUPPORTED_HOOK_EVENTS,\n\tUNSUPPORTED_HANDLER_TYPES,\n\tUNSUPPORTED_KNOWN_HOOK_EVENTS,\n} from \"./types.ts\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"output-bounds.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/hooks/output-bounds.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,0BAA0B,QAAY,CAAC;AACpD,eAAO,MAAM,0BAA0B,QAAY,CAAC;AAEpD,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACtC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACtC,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;CAC1C,CA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AI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;CAC1C,CAAC;AAEF,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,QAAQ,GAAG,QAAQ,EAC3B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,gBAAgB,GAAG,SAAS,EACpC,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAAE,GACvE,cAAc,CAqBhB;AAMD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,SAAe,GAAG,MAAM,CAEtF"}
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
2
2
  import { mkdirSync, writeFileSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
+ import { redactSensitiveOutput, redactSensitiveTokenValues } from "../../../sensitive-output.js";
5
6
  export const DEFAULT_STDOUT_LIMIT_BYTES = 64 * 1024;
6
7
  export const DEFAULT_STDERR_LIMIT_BYTES = 64 * 1024;
7
8
  export function applyHookOutputSafety(stream, text, policy, capture) {
@@ -27,15 +28,10 @@ export function applyHookOutputSafety(stream, text, policy, capture) {
27
28
  };
28
29
  }
29
30
  function redactHookOutput(text) {
30
- return redactHookTokenValues(text
31
- .replace(/\b([A-Z][A-Z0-9_]*(?:API_KEY|SECRET|TOKEN|PASSWORD|AUTH)[A-Z0-9_]*)=([^\s'"]+)/g, "$1=[REDACTED]")
32
- .replace(/\b(Authorization:\s*Bearer\s+)([^\s'"]+)/gi, "$1[REDACTED]")
33
- .replace(/\b(Bearer\s+)(sk-[A-Za-z0-9._-]+)/g, "$1[REDACTED]"));
31
+ return redactSensitiveOutput(text);
34
32
  }
35
33
  export function redactHookTokenValues(text, replacement = "[REDACTED]") {
36
- return text
37
- .replace(/\bghp_[A-Za-z0-9]{20,}\b/g, replacement)
38
- .replace(/\bgithub_pat_[A-Za-z0-9_]{20,}\b/g, replacement);
34
+ return redactSensitiveTokenValues(text, replacement);
39
35
  }
40
36
  function spillRedactedOutput(stream, text, policy) {
41
37
  const spillDir = policy?.spillDir ?? join(tmpdir(), "senpi-hook-output");
@@ -1 +1 @@
1
- {"version":3,"file":"output-bounds.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/hooks/output-bounds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,GAAG,IAAI,CAAC;AACpD,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,GAAG,IAAI,CAAC;AA2BpD,MAAM,UAAU,qBAAqB,CACpC,MAA2B,EAC3B,IAAY,EACZ,MAAoC,EACpC,OAAyE;IAEzE,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACxE,MAAM,YAAY,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,QAAQ,GAAG,YAAY,KAAK,IAAI,CAAC;IACvC,MAAM,KAAK,GAAG,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,MAAM,EAAE,cAAc,CAAC;IACpF,MAAM,QAAQ,GAAG,KAAK,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC;IAC1G,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IACtD,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,KAAK,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AC;IACzE,SAAS,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,QAAQ,MAAM,IAAI,OAAO,CAAC,GAAG,IAAI,UAAU,EAAE,MAAM,CAAC,CAAC;IACjF,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC1B,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { mkdirSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\n\nexport const DEFAULT_STDOUT_LIMIT_BYTES = 64 * 1024;\nexport const DEFAULT_STDERR_LIMIT_BYTES = 64 * 1024;\n\nexport type HookOutputPolicy = {\n\treadonly maxStdoutBytes?: number;\n\treadonly maxStderrBytes?: number;\n\treadonly spillDir?: string;\n};\n\nexport type HookStreamSafetyMetadata = {\n\treadonly originalBytes: number;\n\treadonly returnedBytes: number;\n\treadonly redacted: boolean;\n\treadonly spilled: boolean;\n\treadonly truncated: boolean;\n\treadonly spillPath?: string;\n};\n\nexport type HookOutputSafetyMetadata = {\n\treadonly stdout: HookStreamSafetyMetadata;\n\treadonly stderr: HookStreamSafetyMetadata;\n};\n\nexport type HookSafeOutput = {\n\treadonly text: string;\n\treadonly safety: HookStreamSafetyMetadata;\n};\n\nexport function applyHookOutputSafety(\n\tstream: \"stderr\" | \"stdout\",\n\ttext: string,\n\tpolicy: HookOutputPolicy | undefined,\n\tcapture?: { readonly originalBytes: number; readonly truncated: boolean },\n): HookSafeOutput {\n\tconst originalBytes = capture?.originalBytes ?? Buffer.byteLength(text);\n\tconst redactedText = redactHookOutput(text);\n\tconst redacted = redactedText !== text;\n\tconst limit = stream === \"stdout\" ? policy?.maxStdoutBytes : policy?.maxStderrBytes;\n\tconst maxBytes = limit ?? (stream === \"stdout\" ? DEFAULT_STDOUT_LIMIT_BYTES : DEFAULT_STDERR_LIMIT_BYTES);\n\tconst redactedBytes = Buffer.byteLength(redactedText);\n\tconst truncated = capture?.truncated === true || redactedBytes > maxBytes;\n\tconst spillPath = truncated ? spillRedactedOutput(stream, redactedText, policy) : undefined;\n\tconst returnedText = truncated ? Buffer.from(redactedText).subarray(0, maxBytes).toString(\"utf8\") : redactedText;\n\treturn {\n\t\tsafety: {\n\t\t\toriginalBytes,\n\t\t\tredacted,\n\t\t\treturnedBytes: Buffer.byteLength(returnedText),\n\t\t\tspilled: spillPath !== undefined,\n\t\t\t...(spillPath === undefined ? {} : { spillPath }),\n\t\t\ttruncated,\n\t\t},\n\t\ttext: returnedText,\n\t};\n}\n\nfunction redactHookOutput(text: string): string {\n\treturn redactHookTokenValues(\n\t\ttext\n\t\t\t.replace(/\\b([A-Z][A-Z0-9_]*(?:API_KEY|SECRET|TOKEN|PASSWORD|AUTH)[A-Z0-9_]*)=([^\\s'\"]+)/g, \"$1=[REDACTED]\")\n\t\t\t.replace(/\\b(Authorization:\\s*Bearer\\s+)([^\\s'\"]+)/gi, \"$1[REDACTED]\")\n\t\t\t.replace(/\\b(Bearer\\s+)(sk-[A-Za-z0-9._-]+)/g, \"$1[REDACTED]\"),\n\t);\n}\n\nexport function redactHookTokenValues(text: string, replacement = \"[REDACTED]\"): string {\n\treturn text\n\t\t.replace(/\\bghp_[A-Za-z0-9]{20,}\\b/g, replacement)\n\t\t.replace(/\\bgithub_pat_[A-Za-z0-9_]{20,}\\b/g, replacement);\n}\n\nfunction spillRedactedOutput(stream: \"stderr\" | \"stdout\", text: string, policy: HookOutputPolicy | undefined): string {\n\tconst spillDir = policy?.spillDir ?? join(tmpdir(), \"senpi-hook-output\");\n\tmkdirSync(spillDir, { recursive: true });\n\tconst path = join(spillDir, `hook-${stream}-${process.pid}-${randomUUID()}.txt`);\n\twriteFileSync(path, text);\n\treturn path;\n}\n"]}
1
+ {"version":3,"file":"output-bounds.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/hooks/output-bounds.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\"node:os\";\nimport { join } from \"node:path\";\nimport { redactSensitiveOutput, redactSensitiveTokenValues } from \"../../../sensitive-output.ts\";\n\nexport const DEFAULT_STDOUT_LIMIT_BYTES = 64 * 1024;\nexport const DEFAULT_STDERR_LIMIT_BYTES = 64 * 1024;\n\nexport type HookOutputPolicy = {\n\treadonly maxStdoutBytes?: number;\n\treadonly maxStderrBytes?: number;\n\treadonly spillDir?: string;\n};\n\nexport type HookStreamSafetyMetadata = {\n\treadonly originalBytes: number;\n\treadonly returnedBytes: number;\n\treadonly redacted: boolean;\n\treadonly spilled: boolean;\n\treadonly truncated: boolean;\n\treadonly spillPath?: string;\n};\n\nexport type HookOutputSafetyMetadata = {\n\treadonly stdout: HookStreamSafetyMetadata;\n\treadonly stderr: HookStreamSafetyMetadata;\n};\n\nexport type HookSafeOutput = {\n\treadonly text: string;\n\treadonly safety: HookStreamSafetyMetadata;\n};\n\nexport function applyHookOutputSafety(\n\tstream: \"stderr\" | \"stdout\",\n\ttext: string,\n\tpolicy: HookOutputPolicy | undefined,\n\tcapture?: { readonly originalBytes: number; readonly truncated: boolean },\n): HookSafeOutput {\n\tconst originalBytes = capture?.originalBytes ?? Buffer.byteLength(text);\n\tconst redactedText = redactHookOutput(text);\n\tconst redacted = redactedText !== text;\n\tconst limit = stream === \"stdout\" ? policy?.maxStdoutBytes : policy?.maxStderrBytes;\n\tconst maxBytes = limit ?? (stream === \"stdout\" ? DEFAULT_STDOUT_LIMIT_BYTES : DEFAULT_STDERR_LIMIT_BYTES);\n\tconst redactedBytes = Buffer.byteLength(redactedText);\n\tconst truncated = capture?.truncated === true || redactedBytes > maxBytes;\n\tconst spillPath = truncated ? spillRedactedOutput(stream, redactedText, policy) : undefined;\n\tconst returnedText = truncated ? Buffer.from(redactedText).subarray(0, maxBytes).toString(\"utf8\") : redactedText;\n\treturn {\n\t\tsafety: {\n\t\t\toriginalBytes,\n\t\t\tredacted,\n\t\t\treturnedBytes: Buffer.byteLength(returnedText),\n\t\t\tspilled: spillPath !== undefined,\n\t\t\t...(spillPath === undefined ? {} : { spillPath }),\n\t\t\ttruncated,\n\t\t},\n\t\ttext: returnedText,\n\t};\n}\n\nfunction redactHookOutput(text: string): string {\n\treturn redactSensitiveOutput(text);\n}\n\nexport function redactHookTokenValues(text: string, replacement = \"[REDACTED]\"): string {\n\treturn redactSensitiveTokenValues(text, replacement);\n}\n\nfunction spillRedactedOutput(stream: \"stderr\" | \"stdout\", text: string, policy: HookOutputPolicy | undefined): string {\n\tconst spillDir = policy?.spillDir ?? join(tmpdir(), \"senpi-hook-output\");\n\tmkdirSync(spillDir, { recursive: true });\n\tconst path = join(spillDir, `hook-${stream}-${process.pid}-${randomUUID()}.txt`);\n\twriteFileSync(path, text);\n\treturn path;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import { type BuildDynamicSystemPromptOptions } from "../../../dynamic-prompt/build.ts";
2
+ export declare function buildClaudeFable5Prompt(options: BuildDynamicSystemPromptOptions): string;
3
+ //# sourceMappingURL=claude-fable-5.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude-fable-5.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-fable-5.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;AAclH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAExF"}
@@ -0,0 +1,16 @@
1
+ import { buildDynamicSystemPrompt } from "../../../dynamic-prompt/build.js";
2
+ function buildClaudeFable5Tuning() {
3
+ return `When you have enough information to act, act. Do not re-derive facts already established in the conversation, re-litigate a decision the user has already made, or narrate options you will not pursue. When weighing a choice, give a recommendation, not a survey.
4
+
5
+ Before reporting progress, audit each claim against a tool result from this session. Only report work you can point to evidence for; if something is not yet verified, say so explicitly. If tests fail, say so with the output.
6
+
7
+ Pause for the user only when the work genuinely requires them: a destructive or irreversible action, a real scope change, or input only they can provide. If you hit one of these, ask and end the turn rather than ending on a promise. Before ending your turn, check your last paragraph: if it is a plan, a question, or a promise about work you have not done, do that work now with tool calls.
8
+
9
+ Terse shorthand between tool calls is fine; your final summary is for a reader who did not see it. Lead with the outcome in complete sentences, then supporting detail. Keep output short by dropping detail that does not change what the reader does next, not by compressing into fragments, arrow chains, or labels you made up mid-task.
10
+
11
+ Do not stop, summarize, or suggest a new session on account of context limits. Continue the work.`;
12
+ }
13
+ export function buildClaudeFable5Prompt(options) {
14
+ return buildDynamicSystemPrompt({ ...options, tuningSection: buildClaudeFable5Tuning() });
15
+ }
16
+ //# sourceMappingURL=claude-fable-5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude-fable-5.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-fable-5.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAElH,SAAS,uBAAuB;IAC/B,OAAO;;;;;;;;kGAQ0F,CAAC;AACnG,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAwC;IAC/E,OAAO,wBAAwB,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import { type BuildDynamicSystemPromptOptions, buildDynamicSystemPrompt } from \"../../../dynamic-prompt/build.ts\";\n\nfunction buildClaudeFable5Tuning(): string {\n\treturn `When you have enough information to act, act. Do not re-derive facts already established in the conversation, re-litigate a decision the user has already made, or narrate options you will not pursue. When weighing a choice, give a recommendation, not a survey.\n\nBefore reporting progress, audit each claim against a tool result from this session. Only report work you can point to evidence for; if something is not yet verified, say so explicitly. If tests fail, say so with the output.\n\nPause for the user only when the work genuinely requires them: a destructive or irreversible action, a real scope change, or input only they can provide. If you hit one of these, ask and end the turn rather than ending on a promise. Before ending your turn, check your last paragraph: if it is a plan, a question, or a promise about work you have not done, do that work now with tool calls.\n\nTerse shorthand between tool calls is fine; your final summary is for a reader who did not see it. Lead with the outcome in complete sentences, then supporting detail. Keep output short by dropping detail that does not change what the reader does next, not by compressing into fragments, arrow chains, or labels you made up mid-task.\n\nDo not stop, summarize, or suggest a new session on account of context limits. Continue the work.`;\n}\n\nexport function buildClaudeFable5Prompt(options: BuildDynamicSystemPromptOptions): string {\n\treturn buildDynamicSystemPrompt({ ...options, tuningSection: buildClaudeFable5Tuning() });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"claude-opus-4-5.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-5.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;AAMlH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAExF"}
1
+ {"version":3,"file":"claude-opus-4-5.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-5.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;AAQlH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAExF"}
@@ -1,6 +1,8 @@
1
1
  import { buildDynamicSystemPrompt } from "../../../dynamic-prompt/build.js";
2
2
  function buildClaudeOpus45Tuning() {
3
- return `Break complex tasks into ordered steps with clear dependencies rather than stating only the outcome. When a task must apply to ALL items in a set, state "apply to every item" explicitly. Do not add caveats, qualifications, or "let me know if..." closers.`;
3
+ return `Break complex tasks into ordered steps with clear dependencies before executing. When a request covers a set of items, apply it to every item rather than only the first, and state the scope you applied.
4
+
5
+ Do not wrap up early because the context window is running low; the harness auto-compacts context. Keep working until the task is complete.`;
4
6
  }
5
7
  export function buildClaudeOpus45Prompt(options) {
6
8
  return buildDynamicSystemPrompt({ ...options, tuningSection: buildClaudeOpus45Tuning() });
@@ -1 +1 @@
1
- {"version":3,"file":"claude-opus-4-5.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-5.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAElH,SAAS,uBAAuB;IAC/B,OAAO,gQAAgQ,CAAC;AACzQ,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAwC;IAC/E,OAAO,wBAAwB,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import { type BuildDynamicSystemPromptOptions, buildDynamicSystemPrompt } from \"../../../dynamic-prompt/build.ts\";\n\nfunction buildClaudeOpus45Tuning(): string {\n\treturn `Break complex tasks into ordered steps with clear dependencies rather than stating only the outcome. When a task must apply to ALL items in a set, state \"apply to every item\" explicitly. Do not add caveats, qualifications, or \"let me know if...\" closers.`;\n}\n\nexport function buildClaudeOpus45Prompt(options: BuildDynamicSystemPromptOptions): string {\n\treturn buildDynamicSystemPrompt({ ...options, tuningSection: buildClaudeOpus45Tuning() });\n}\n"]}
1
+ {"version":3,"file":"claude-opus-4-5.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-5.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAElH,SAAS,uBAAuB;IAC/B,OAAO;;4IAEoI,CAAC;AAC7I,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAwC;IAC/E,OAAO,wBAAwB,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import { type BuildDynamicSystemPromptOptions, buildDynamicSystemPrompt } from \"../../../dynamic-prompt/build.ts\";\n\nfunction buildClaudeOpus45Tuning(): string {\n\treturn `Break complex tasks into ordered steps with clear dependencies before executing. When a request covers a set of items, apply it to every item rather than only the first, and state the scope you applied.\n\nDo not wrap up early because the context window is running low; the harness auto-compacts context. Keep working until the task is complete.`;\n}\n\nexport function buildClaudeOpus45Prompt(options: BuildDynamicSystemPromptOptions): string {\n\treturn buildDynamicSystemPrompt({ ...options, tuningSection: buildClaudeOpus45Tuning() });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"claude-opus-4-6.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-6.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;AAMlH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAExF"}
1
+ {"version":3,"file":"claude-opus-4-6.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-6.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;AAQlH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAExF"}
@@ -1,6 +1,8 @@
1
1
  import { buildDynamicSystemPrompt } from "../../../dynamic-prompt/build.js";
2
2
  function buildClaudeOpus46Tuning() {
3
- return `When a task applies to multiple items, state the full scope explicitly rather than relying on implication. Default output is thorough constrain with "one sentence", "bullets only", "no preamble" when concise output is needed.`;
3
+ return `Choose an approach and commit to it; revisit only when new information directly contradicts your reasoning. When a request covers a set of items, apply it to every item and state the scope you applied.
4
+
5
+ Do not wrap up early because the context window is running low; the harness auto-compacts context. Keep working until the task is complete.`;
4
6
  }
5
7
  export function buildClaudeOpus46Prompt(options) {
6
8
  return buildDynamicSystemPrompt({ ...options, tuningSection: buildClaudeOpus46Tuning() });
@@ -1 +1 @@
1
- {"version":3,"file":"claude-opus-4-6.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-6.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAElH,SAAS,uBAAuB;IAC/B,OAAO,qOAAqO,CAAC;AAC9O,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAwC;IAC/E,OAAO,wBAAwB,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import { type BuildDynamicSystemPromptOptions, buildDynamicSystemPrompt } from \"../../../dynamic-prompt/build.ts\";\n\nfunction buildClaudeOpus46Tuning(): string {\n\treturn `When a task applies to multiple items, state the full scope explicitly rather than relying on implication. Default output is thorough constrain with \"one sentence\", \"bullets only\", \"no preamble\" when concise output is needed.`;\n}\n\nexport function buildClaudeOpus46Prompt(options: BuildDynamicSystemPromptOptions): string {\n\treturn buildDynamicSystemPrompt({ ...options, tuningSection: buildClaudeOpus46Tuning() });\n}\n"]}
1
+ {"version":3,"file":"claude-opus-4-6.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-6.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAElH,SAAS,uBAAuB;IAC/B,OAAO;;4IAEoI,CAAC;AAC7I,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAwC;IAC/E,OAAO,wBAAwB,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import { type BuildDynamicSystemPromptOptions, buildDynamicSystemPrompt } from \"../../../dynamic-prompt/build.ts\";\n\nfunction buildClaudeOpus46Tuning(): string {\n\treturn `Choose an approach and commit to it; revisit only when new information directly contradicts your reasoning. When a request covers a set of items, apply it to every item and state the scope you applied.\n\nDo not wrap up early because the context window is running low; the harness auto-compacts context. Keep working until the task is complete.`;\n}\n\nexport function buildClaudeOpus46Prompt(options: BuildDynamicSystemPromptOptions): string {\n\treturn buildDynamicSystemPrompt({ ...options, tuningSection: buildClaudeOpus46Tuning() });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"claude-opus-4-7.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-7.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;AAQlH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAExF"}
1
+ {"version":3,"file":"claude-opus-4-7.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-7.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;AAYlH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAExF"}
@@ -1,8 +1,12 @@
1
1
  import { buildDynamicSystemPrompt } from "../../../dynamic-prompt/build.js";
2
2
  function buildClaudeOpus47Tuning() {
3
- return `When an instruction names a scope like "every", "all", or "for each", apply it to the full set rather than the first item. When told "do X then Y", follow that exact sequence.
3
+ return `Apply instructions at the scope the user evidently intends: "every", "all", and "each" mean the full set rather than the first item, and a fix that plainly recurs covers every occurrence. State the scope you applied.
4
4
 
5
- Maintain coherent state across extended multi-tool workflows without drifting from the original goal. Do not re-anchor with reminder paragraphs mid-task.`;
5
+ Prefer tool calls over reasoning when a tool can resolve the question directly; do not reason past a fact you can look up.
6
+
7
+ For frontend design with no specified visual direction, derive one from the project's context or propose distinct options before building; do not fall back to your default cream/serif/terracotta house style or generic AI aesthetics.
8
+
9
+ Do not wrap up early because the context window is running low; the harness auto-compacts context. Keep working until the task is complete.`;
6
10
  }
7
11
  export function buildClaudeOpus47Prompt(options) {
8
12
  return buildDynamicSystemPrompt({ ...options, tuningSection: buildClaudeOpus47Tuning() });
@@ -1 +1 @@
1
- {"version":3,"file":"claude-opus-4-7.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-7.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAElH,SAAS,uBAAuB;IAC/B,OAAO;;0JAEkJ,CAAC;AAC3J,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAwC;IAC/E,OAAO,wBAAwB,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import { type BuildDynamicSystemPromptOptions, buildDynamicSystemPrompt } from \"../../../dynamic-prompt/build.ts\";\n\nfunction buildClaudeOpus47Tuning(): string {\n\treturn `When an instruction names a scope like \"every\", \"all\", or \"for each\", apply it to the full set rather than the first item. When told \"do X then Y\", follow that exact sequence.\n\nMaintain coherent state across extended multi-tool workflows without drifting from the original goal. Do not re-anchor with reminder paragraphs mid-task.`;\n}\n\nexport function buildClaudeOpus47Prompt(options: BuildDynamicSystemPromptOptions): string {\n\treturn buildDynamicSystemPrompt({ ...options, tuningSection: buildClaudeOpus47Tuning() });\n}\n"]}
1
+ {"version":3,"file":"claude-opus-4-7.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-7.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAElH,SAAS,uBAAuB;IAC/B,OAAO;;;;;;4IAMoI,CAAC;AAC7I,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAwC;IAC/E,OAAO,wBAAwB,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import { type BuildDynamicSystemPromptOptions, buildDynamicSystemPrompt } from \"../../../dynamic-prompt/build.ts\";\n\nfunction buildClaudeOpus47Tuning(): string {\n\treturn `Apply instructions at the scope the user evidently intends: \"every\", \"all\", and \"each\" mean the full set rather than the first item, and a fix that plainly recurs covers every occurrence. State the scope you applied.\n\nPrefer tool calls over reasoning when a tool can resolve the question directly; do not reason past a fact you can look up.\n\nFor frontend design with no specified visual direction, derive one from the project's context or propose distinct options before building; do not fall back to your default cream/serif/terracotta house style or generic AI aesthetics.\n\nDo not wrap up early because the context window is running low; the harness auto-compacts context. Keep working until the task is complete.`;\n}\n\nexport function buildClaudeOpus47Prompt(options: BuildDynamicSystemPromptOptions): string {\n\treturn buildDynamicSystemPrompt({ ...options, tuningSection: buildClaudeOpus47Tuning() });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"claude-opus-4-8.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-8.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;AAUlH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAExF"}
1
+ {"version":3,"file":"claude-opus-4-8.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-8.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;AAYlH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAExF"}
@@ -1,10 +1,12 @@
1
1
  import { buildDynamicSystemPrompt } from "../../../dynamic-prompt/build.js";
2
2
  function buildClaudeOpus48Tuning() {
3
- return `When an instruction names a scope like "every", "all", or "for each", apply it to the full set rather than the first item. When told "do X then Y", follow that exact sequence. State the scope explicitly when applying a rule broadly.
3
+ return `Apply instructions at the scope the user evidently intends: "every", "all", and "each" mean the full set rather than the first item, and a fix that plainly recurs covers every occurrence. State the scope you applied.
4
4
 
5
- Maintain coherent state across extended multi-tool workflows without drifting from the original goal. Do not re-anchor with reminder paragraphs mid-task.
5
+ Prefer tool calls over reasoning when a tool can resolve the question directly; do not reason past a fact you can look up. After a user turn, reason over what changed; do not re-derive facts already established in the conversation.
6
6
 
7
- Prefer tool calls over reasoning when a tool can resolve the question directly. Do not reason past a fact you can look up.`;
7
+ For frontend design with no specified visual direction, derive one from the project's context or propose distinct options before building; do not fall back to your default cream/serif/terracotta house style or generic AI aesthetics.
8
+
9
+ Do not wrap up early because the context window is running low; the harness auto-compacts context. Keep working until the task is complete.`;
8
10
  }
9
11
  export function buildClaudeOpus48Prompt(options) {
10
12
  return buildDynamicSystemPrompt({ ...options, tuningSection: buildClaudeOpus48Tuning() });
@@ -1 +1 @@
1
- {"version":3,"file":"claude-opus-4-8.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-8.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAElH,SAAS,uBAAuB;IAC/B,OAAO;;;;2HAImH,CAAC;AAC5H,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAwC;IAC/E,OAAO,wBAAwB,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import { type BuildDynamicSystemPromptOptions, buildDynamicSystemPrompt } from \"../../../dynamic-prompt/build.ts\";\n\nfunction buildClaudeOpus48Tuning(): string {\n\treturn `When an instruction names a scope like \"every\", \"all\", or \"for each\", apply it to the full set rather than the first item. When told \"do X then Y\", follow that exact sequence. State the scope explicitly when applying a rule broadly.\n\nMaintain coherent state across extended multi-tool workflows without drifting from the original goal. Do not re-anchor with reminder paragraphs mid-task.\n\nPrefer tool calls over reasoning when a tool can resolve the question directly. Do not reason past a fact you can look up.`;\n}\n\nexport function buildClaudeOpus48Prompt(options: BuildDynamicSystemPromptOptions): string {\n\treturn buildDynamicSystemPrompt({ ...options, tuningSection: buildClaudeOpus48Tuning() });\n}\n"]}
1
+ {"version":3,"file":"claude-opus-4-8.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-opus-4-8.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAElH,SAAS,uBAAuB;IAC/B,OAAO;;;;;;4IAMoI,CAAC;AAC7I,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAwC;IAC/E,OAAO,wBAAwB,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import { type BuildDynamicSystemPromptOptions, buildDynamicSystemPrompt } from \"../../../dynamic-prompt/build.ts\";\n\nfunction buildClaudeOpus48Tuning(): string {\n\treturn `Apply instructions at the scope the user evidently intends: \"every\", \"all\", and \"each\" mean the full set rather than the first item, and a fix that plainly recurs covers every occurrence. State the scope you applied.\n\nPrefer tool calls over reasoning when a tool can resolve the question directly; do not reason past a fact you can look up. After a user turn, reason over what changed; do not re-derive facts already established in the conversation.\n\nFor frontend design with no specified visual direction, derive one from the project's context or propose distinct options before building; do not fall back to your default cream/serif/terracotta house style or generic AI aesthetics.\n\nDo not wrap up early because the context window is running low; the harness auto-compacts context. Keep working until the task is complete.`;\n}\n\nexport function buildClaudeOpus48Prompt(options: BuildDynamicSystemPromptOptions): string {\n\treturn buildDynamicSystemPrompt({ ...options, tuningSection: buildClaudeOpus48Tuning() });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"gpt-5.5.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/gpt-5.5.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;AAmBlH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAEjF"}
1
+ {"version":3,"file":"gpt-5.5.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/gpt-5.5.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;AA+DlH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAEjF"}