@namzu/sdk 69.2.0 → 69.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/authorization/readonly-commands.d.ts.map +1 -1
  3. package/dist/authorization/readonly-commands.js +30 -2
  4. package/dist/authorization/readonly-commands.js.map +1 -1
  5. package/dist/constants/plugin/index.d.ts +8 -0
  6. package/dist/constants/plugin/index.d.ts.map +1 -1
  7. package/dist/constants/plugin/index.js +8 -0
  8. package/dist/constants/plugin/index.js.map +1 -1
  9. package/dist/plugin/common-layout/index.d.ts +5 -0
  10. package/dist/plugin/common-layout/index.d.ts.map +1 -0
  11. package/dist/plugin/common-layout/index.js +3 -0
  12. package/dist/plugin/common-layout/index.js.map +1 -0
  13. package/dist/plugin/common-layout/mcp.d.ts +21 -0
  14. package/dist/plugin/common-layout/mcp.d.ts.map +1 -0
  15. package/dist/plugin/common-layout/mcp.js +305 -0
  16. package/dist/plugin/common-layout/mcp.js.map +1 -0
  17. package/dist/plugin/common-layout/paths.d.ts +27 -0
  18. package/dist/plugin/common-layout/paths.d.ts.map +1 -0
  19. package/dist/plugin/common-layout/paths.js +48 -0
  20. package/dist/plugin/common-layout/paths.js.map +1 -0
  21. package/dist/plugin/common-layout/read.d.ts +25 -0
  22. package/dist/plugin/common-layout/read.d.ts.map +1 -0
  23. package/dist/plugin/common-layout/read.js +1155 -0
  24. package/dist/plugin/common-layout/read.js.map +1 -0
  25. package/dist/plugin/common-layout/types.d.ts +66 -0
  26. package/dist/plugin/common-layout/types.d.ts.map +1 -0
  27. package/dist/plugin/common-layout/types.js +2 -0
  28. package/dist/plugin/common-layout/types.js.map +1 -0
  29. package/dist/plugin/common-layout-names.d.ts +65 -0
  30. package/dist/plugin/common-layout-names.d.ts.map +1 -0
  31. package/dist/plugin/common-layout-names.js +94 -0
  32. package/dist/plugin/common-layout-names.js.map +1 -0
  33. package/dist/plugin/hook-module/capabilities.d.ts +41 -0
  34. package/dist/plugin/hook-module/capabilities.d.ts.map +1 -0
  35. package/dist/plugin/hook-module/capabilities.js +438 -0
  36. package/dist/plugin/hook-module/capabilities.js.map +1 -0
  37. package/dist/plugin/hook-module/consent.d.ts +39 -0
  38. package/dist/plugin/hook-module/consent.d.ts.map +1 -0
  39. package/dist/plugin/hook-module/consent.js +59 -0
  40. package/dist/plugin/hook-module/consent.js.map +1 -0
  41. package/dist/plugin/hook-module/events.d.ts +33 -0
  42. package/dist/plugin/hook-module/events.d.ts.map +1 -0
  43. package/dist/plugin/hook-module/events.js +149 -0
  44. package/dist/plugin/hook-module/events.js.map +1 -0
  45. package/dist/plugin/hook-module/host.d.ts +79 -0
  46. package/dist/plugin/hook-module/host.d.ts.map +1 -0
  47. package/dist/plugin/hook-module/host.js +546 -0
  48. package/dist/plugin/hook-module/host.js.map +1 -0
  49. package/dist/plugin/hook-module/index.d.ts +11 -0
  50. package/dist/plugin/hook-module/index.d.ts.map +1 -0
  51. package/dist/plugin/hook-module/index.js +6 -0
  52. package/dist/plugin/hook-module/index.js.map +1 -0
  53. package/dist/plugin/hook-module/scan.d.ts +99 -0
  54. package/dist/plugin/hook-module/scan.d.ts.map +1 -0
  55. package/dist/plugin/hook-module/scan.js +789 -0
  56. package/dist/plugin/hook-module/scan.js.map +1 -0
  57. package/dist/plugin/hook-module/worker-source.d.ts +31 -0
  58. package/dist/plugin/hook-module/worker-source.d.ts.map +1 -0
  59. package/dist/plugin/hook-module/worker-source.js +498 -0
  60. package/dist/plugin/hook-module/worker-source.js.map +1 -0
  61. package/dist/plugin/index.d.ts +5 -2
  62. package/dist/plugin/index.d.ts.map +1 -1
  63. package/dist/plugin/index.js +4 -1
  64. package/dist/plugin/index.js.map +1 -1
  65. package/dist/plugin/lifecycle.d.ts +57 -0
  66. package/dist/plugin/lifecycle.d.ts.map +1 -1
  67. package/dist/plugin/lifecycle.js +92 -11
  68. package/dist/plugin/lifecycle.js.map +1 -1
  69. package/dist/plugin/loader.d.ts +30 -0
  70. package/dist/plugin/loader.d.ts.map +1 -1
  71. package/dist/plugin/loader.js +76 -19
  72. package/dist/plugin/loader.js.map +1 -1
  73. package/dist/plugin/shell-hook-env.d.ts +7 -0
  74. package/dist/plugin/shell-hook-env.d.ts.map +1 -1
  75. package/dist/plugin/shell-hook-env.js.map +1 -1
  76. package/dist/plugin/shell-hook.d.ts +10 -1
  77. package/dist/plugin/shell-hook.d.ts.map +1 -1
  78. package/dist/plugin/shell-hook.js +81 -70
  79. package/dist/plugin/shell-hook.js.map +1 -1
  80. package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
  81. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  82. package/dist/prompt/coding-agent-doctrine.js +1 -1
  83. package/dist/provider/side-request-reasoning.d.ts.map +1 -1
  84. package/dist/provider/side-request-reasoning.js +5 -1
  85. package/dist/provider/side-request-reasoning.js.map +1 -1
  86. package/dist/public-runtime.d.ts +3 -2
  87. package/dist/public-runtime.d.ts.map +1 -1
  88. package/dist/public-runtime.js +2 -2
  89. package/dist/public-runtime.js.map +1 -1
  90. package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
  91. package/dist/runtime/query/auto-review/classifier.js +13 -2
  92. package/dist/runtime/query/auto-review/classifier.js.map +1 -1
  93. package/dist/runtime/query/auto-review/failure.d.ts +12 -5
  94. package/dist/runtime/query/auto-review/failure.d.ts.map +1 -1
  95. package/dist/runtime/query/auto-review/failure.js +42 -7
  96. package/dist/runtime/query/auto-review/failure.js.map +1 -1
  97. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  98. package/dist/runtime/query/review-policy.js +22 -6
  99. package/dist/runtime/query/review-policy.js.map +1 -1
  100. package/dist/runtime/query/turn/check-scope.d.ts +18 -0
  101. package/dist/runtime/query/turn/check-scope.d.ts.map +1 -0
  102. package/dist/runtime/query/turn/check-scope.js +90 -0
  103. package/dist/runtime/query/turn/check-scope.js.map +1 -0
  104. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  105. package/dist/runtime/query/turn/outcome-ledger.js +13 -0
  106. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  107. package/dist/skills/loader.d.ts +8 -2
  108. package/dist/skills/loader.d.ts.map +1 -1
  109. package/dist/skills/loader.js +22 -11
  110. package/dist/skills/loader.js.map +1 -1
  111. package/dist/skills/registry.d.ts.map +1 -1
  112. package/dist/skills/registry.js +9 -1
  113. package/dist/skills/registry.js.map +1 -1
  114. package/dist/tools/builtins/job.d.ts.map +1 -1
  115. package/dist/tools/builtins/job.js +4 -1
  116. package/dist/tools/builtins/job.js.map +1 -1
  117. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
  118. package/dist/tools/builtins/wait-for-job.js +2 -1
  119. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  120. package/dist/types/plugin/index.d.ts +73 -0
  121. package/dist/types/plugin/index.d.ts.map +1 -1
  122. package/dist/types/plugin/index.js +28 -6
  123. package/dist/types/plugin/index.js.map +1 -1
  124. package/dist/types/skills/index.d.ts +6 -0
  125. package/dist/types/skills/index.d.ts.map +1 -1
  126. package/package.json +2 -1
  127. package/src/authorization/readonly-commands.ts +30 -2
  128. package/src/constants/plugin/index.ts +9 -0
  129. package/src/plugin/common-layout/index.ts +19 -0
  130. package/src/plugin/common-layout/mcp.ts +362 -0
  131. package/src/plugin/common-layout/paths.ts +70 -0
  132. package/src/plugin/common-layout/read.ts +1282 -0
  133. package/src/plugin/common-layout/types.ts +77 -0
  134. package/src/plugin/common-layout-names.ts +108 -0
  135. package/src/plugin/hook-module/capabilities.ts +500 -0
  136. package/src/plugin/hook-module/consent.ts +96 -0
  137. package/src/plugin/hook-module/events.ts +177 -0
  138. package/src/plugin/hook-module/host.ts +649 -0
  139. package/src/plugin/hook-module/index.ts +52 -0
  140. package/src/plugin/hook-module/scan.ts +1004 -0
  141. package/src/plugin/hook-module/worker-source.ts +500 -0
  142. package/src/plugin/index.ts +13 -1
  143. package/src/plugin/lifecycle.ts +179 -17
  144. package/src/plugin/loader.ts +97 -18
  145. package/src/plugin/shell-hook-env.ts +7 -0
  146. package/src/plugin/shell-hook.ts +91 -70
  147. package/src/prompt/coding-agent-doctrine.ts +1 -1
  148. package/src/provider/side-request-reasoning.ts +5 -1
  149. package/src/public-runtime.ts +35 -0
  150. package/src/runtime/query/auto-review/classifier.ts +14 -2
  151. package/src/runtime/query/auto-review/failure.ts +52 -7
  152. package/src/runtime/query/review-policy.ts +30 -6
  153. package/src/runtime/query/turn/check-scope.ts +90 -0
  154. package/src/runtime/query/turn/outcome-ledger.ts +11 -0
  155. package/src/skills/loader.ts +26 -9
  156. package/src/skills/registry.ts +9 -1
  157. package/src/tools/builtins/job.ts +4 -1
  158. package/src/tools/builtins/wait-for-job.ts +3 -1
  159. package/src/types/plugin/index.ts +81 -24
  160. package/src/types/skills/index.ts +7 -0
@@ -0,0 +1,96 @@
1
+ import { classicWrittenName } from './events.js'
2
+ import type { HookModuleScan } from './scan.js'
3
+
4
+ /** What a hooks module does, in the terms a person is asked about. */
5
+ export interface HookModuleSummary {
6
+ /** The module, relative to the plugin. */
7
+ readonly entry: string
8
+ /** The events it hooks and Namzu runs, as the module spells them (`PreToolUse`). */
9
+ readonly events: readonly string[]
10
+ /** It starts programs. */
11
+ readonly runsCommands: boolean
12
+ /** It reads files in the plugin's folder and the project. */
13
+ readonly readsFiles: boolean
14
+ /** It makes network requests. */
15
+ readonly usesNetwork: boolean
16
+ /** It keeps data between sessions in the plugin's data folder. */
17
+ readonly keepsData: boolean
18
+ /** The variables it reads, by name. */
19
+ readonly readsEnvironment: readonly string[]
20
+ /** What it hooks or calls that Namzu has no place for, one line each. */
21
+ readonly notUsed: readonly string[]
22
+ /** Why it is refused and does not load, one line each. */
23
+ readonly refused: readonly string[]
24
+ }
25
+
26
+ /** Read a scan as a summary of what the module does. */
27
+ export function summarizeHookModule(scan: HookModuleScan): HookModuleSummary {
28
+ const events = new Set<string>()
29
+ const notUsed: string[] = []
30
+ for (const hook of scan.hooks) {
31
+ for (const event of hook.runs) {
32
+ const written = classicWrittenName(event)
33
+ if (written !== undefined) events.add(written)
34
+ }
35
+ if (hook.notUsed !== undefined) notUsed.push(hook.notUsed)
36
+ }
37
+ const supportedCalls = scan.calls.filter((call) => call.supported).map((call) => call.call)
38
+ for (const call of scan.calls) {
39
+ if (call.supported) continue
40
+ notUsed.push(
41
+ call.neverRuns === true
42
+ ? `${call.call} is not available in Namzu; the hook that calls it is not run, so it is never called.`
43
+ : `${call.call} is not available in Namzu; calling it throws.`,
44
+ )
45
+ }
46
+ const uses = (prefix: string): boolean => supportedCalls.some((call) => call.startsWith(prefix))
47
+ return {
48
+ entry: scan.entry,
49
+ events: [...events].sort(),
50
+ runsCommands: uses('$.process.'),
51
+ readsFiles: uses('$.fs.'),
52
+ usesNetwork: uses('$.http.'),
53
+ keepsData: uses('$.store.'),
54
+ readsEnvironment: scan.envNames,
55
+ notUsed: [...new Set(notUsed)],
56
+ refused: scan.refusals.map((refusal) => `${refusal.file}:${refusal.line}: ${refusal.message}`),
57
+ }
58
+ }
59
+
60
+ /** One line per thing a person is told about before a module is allowed to run. */
61
+ export function hookModuleConsentLines(summary: HookModuleSummary): string[] {
62
+ const lines: string[] = []
63
+ lines.push(
64
+ summary.events.length > 0
65
+ ? `hooks ${summary.events.join(', ')}`
66
+ : 'hooks no event that Namzu runs',
67
+ )
68
+ if (summary.runsCommands) lines.push('runs commands')
69
+ if (summary.readsFiles) lines.push('reads files in the plugin and the project')
70
+ if (summary.usesNetwork) lines.push('uses the network')
71
+ if (summary.keepsData) lines.push("keeps data in the plugin's data folder")
72
+ if (summary.readsEnvironment.length > 0) {
73
+ lines.push(`reads environment variables ${summary.readsEnvironment.join(', ')}`)
74
+ }
75
+ return lines
76
+ }
77
+
78
+ /**
79
+ * The entry a consent surface (the trust screen, an install prompt) shows for a
80
+ * plugin's hooks module: who ships it, which file, and what it does.
81
+ */
82
+ export interface HookModuleConsentEntry {
83
+ readonly plugin: string
84
+ readonly module: string
85
+ /** What the module does, one line each, ready to show. */
86
+ readonly lines: readonly string[]
87
+ readonly summary: HookModuleSummary
88
+ }
89
+
90
+ export function hookModuleConsentEntry(
91
+ plugin: string,
92
+ scan: HookModuleScan,
93
+ ): HookModuleConsentEntry {
94
+ const summary = summarizeHookModule(scan)
95
+ return { plugin, module: scan.entry, lines: hookModuleConsentLines(summary), summary }
96
+ }
@@ -0,0 +1,177 @@
1
+ import { COMMON_MODULE_EVENT_NAMESPACE } from '../common-layout-names.js'
2
+ import {
3
+ SHELL_HOOK_EVENTS,
4
+ SHELL_HOOK_PASCAL_EVENT_NAMES,
5
+ type ShellHookEvent,
6
+ } from '../shell-hook.js'
7
+
8
+ /**
9
+ * The settings-style hook events a hooks module may name, as `classic.<Event>`.
10
+ * Some have no counterpart in Namzu; they are accepted and never run.
11
+ */
12
+ export const CLASSIC_HOOK_EVENTS: readonly string[] = [
13
+ 'PreToolUse',
14
+ 'PostToolUse',
15
+ 'PostToolUseFailure',
16
+ 'PostToolBatch',
17
+ 'PermissionDenied',
18
+ 'Notification',
19
+ 'UserPromptSubmit',
20
+ 'UserPromptExpansion',
21
+ 'SessionStart',
22
+ 'SessionEnd',
23
+ 'Stop',
24
+ 'StopFailure',
25
+ 'SubagentStart',
26
+ 'SubagentStop',
27
+ 'PreCompact',
28
+ 'PostCompact',
29
+ 'PreModelSwitch',
30
+ 'PostModelSwitch',
31
+ 'PermissionRequest',
32
+ 'Setup',
33
+ 'TeammateIdle',
34
+ 'TaskCreated',
35
+ 'TaskCompleted',
36
+ 'Elicitation',
37
+ 'ElicitationResult',
38
+ 'ConfigChange',
39
+ 'InstructionsLoaded',
40
+ 'WorktreeCreate',
41
+ 'WorktreeRemove',
42
+ 'CwdChanged',
43
+ 'FileChanged',
44
+ 'DirectoryAdded',
45
+ 'MessageDisplay',
46
+ 'PreSkillShellCommand',
47
+ ]
48
+
49
+ /**
50
+ * The namespaces of the events the other engine runs inside itself (tool calls,
51
+ * the interface, agents and the rest). A module may register on them; Namzu has
52
+ * no such events, so none of those hooks run.
53
+ */
54
+ const ENGINE_NAMESPACES: ReadonlySet<string> = new Set([
55
+ 'tool',
56
+ 'turn',
57
+ 'session',
58
+ 'prompt',
59
+ 'agent',
60
+ 'command',
61
+ 'config',
62
+ 'settings',
63
+ 'env',
64
+ 'state',
65
+ 'store',
66
+ 'telemetry',
67
+ 'skill',
68
+ 'attribution',
69
+ 'ui',
70
+ 'theme',
71
+ 'vcs',
72
+ 'process',
73
+ 'fs',
74
+ 'http',
75
+ 'model',
76
+ 'mcp',
77
+ 'audio',
78
+ 'clock',
79
+ 'wasm',
80
+ 'plugin',
81
+ 'engine',
82
+ ])
83
+
84
+ const NAMESPACE = COMMON_MODULE_EVENT_NAMESPACE
85
+
86
+ /** Each classic name that Namzu has an event for, to that event. */
87
+ const CLASSIC_TO_NAMZU: ReadonlyMap<string, ShellHookEvent> = new Map(
88
+ SHELL_HOOK_EVENTS.flatMap((event) => {
89
+ const written = SHELL_HOOK_PASCAL_EVENT_NAMES[event]
90
+ return written !== undefined && CLASSIC_HOOK_EVENTS.includes(written)
91
+ ? [[written, event] as const]
92
+ : []
93
+ }),
94
+ )
95
+
96
+ const NAMZU_TO_CLASSIC: ReadonlyMap<ShellHookEvent, string> = new Map(
97
+ [...CLASSIC_TO_NAMZU].map(([classic, event]) => [event, classic] as const),
98
+ )
99
+
100
+ /** The Namzu events a module can run on. */
101
+ export const MODULE_HOOK_EVENTS: readonly ShellHookEvent[] = [...NAMZU_TO_CLASSIC.keys()]
102
+
103
+ /** The name a module registers on for a Namzu event: `classic.PreToolUse`. */
104
+ export function classicEventName(event: ShellHookEvent): string | undefined {
105
+ const written = NAMZU_TO_CLASSIC.get(event)
106
+ return written === undefined ? undefined : `${NAMESPACE}.${written}`
107
+ }
108
+
109
+ /** The written (PascalCase) name of a Namzu event, as a module's `e.hook_event_name` spells it. */
110
+ export function classicWrittenName(event: ShellHookEvent): string | undefined {
111
+ return NAMZU_TO_CLASSIC.get(event)
112
+ }
113
+
114
+ export type ResolvedPattern =
115
+ | {
116
+ readonly ok: true
117
+ /** The Namzu events the pattern selects and Namzu runs. */
118
+ readonly runs: readonly ShellHookEvent[]
119
+ /**
120
+ * Set when the pattern names only events Namzu does not have: nothing it
121
+ * hooks ever runs, and the message says so.
122
+ */
123
+ readonly notUsed?: string
124
+ }
125
+ | { readonly ok: false; readonly message: string }
126
+
127
+ function notAvailable(pattern: string): string {
128
+ return `Namzu runs ${NAMESPACE}.* hooks from modules; ${pattern} is not available.`
129
+ }
130
+
131
+ function isEngineName(name: string): boolean {
132
+ const dot = name.indexOf('.')
133
+ if (dot <= 0 || dot === name.length - 1) return false
134
+ return (
135
+ ENGINE_NAMESPACES.has(name.slice(0, dot)) && /^[A-Za-z][A-Za-z0-9]*$/.test(name.slice(dot + 1))
136
+ )
137
+ }
138
+
139
+ /**
140
+ * What a pattern selects: one event by name, every event under a namespace
141
+ * (`classic.*`), every event (`*`), or every event but those another pattern
142
+ * selects (`!tool.*`, `!classic.Stop`). A name that is no event and a glob that
143
+ * selects nothing are refused.
144
+ */
145
+ export function resolvePattern(pattern: string): ResolvedPattern {
146
+ const all = (): readonly ShellHookEvent[] => [...MODULE_HOOK_EVENTS]
147
+ if (pattern === '*') return { ok: true, runs: all() }
148
+ if (pattern.startsWith('!')) {
149
+ const inner = resolvePattern(pattern.slice(1))
150
+ if (!inner.ok) return inner
151
+ if (pattern.startsWith('!!')) {
152
+ return { ok: false, message: `"${pattern}" is not a pattern: a negation is made once` }
153
+ }
154
+ const taken = new Set(inner.runs)
155
+ return { ok: true, runs: all().filter((event) => !taken.has(event)) }
156
+ }
157
+ if (pattern.endsWith('.*')) {
158
+ const space = pattern.slice(0, -2)
159
+ if (space === NAMESPACE) return { ok: true, runs: all() }
160
+ if (ENGINE_NAMESPACES.has(space)) {
161
+ return { ok: true, runs: [], notUsed: notAvailable(pattern) }
162
+ }
163
+ return { ok: false, message: `"${pattern}" is not a pattern: it selects no event` }
164
+ }
165
+ if (pattern.startsWith(`${NAMESPACE}.`)) {
166
+ const name = pattern.slice(NAMESPACE.length + 1)
167
+ if (!CLASSIC_HOOK_EVENTS.includes(name)) {
168
+ return { ok: false, message: `"${pattern}" is not an event` }
169
+ }
170
+ const event = CLASSIC_TO_NAMZU.get(name)
171
+ return event === undefined
172
+ ? { ok: true, runs: [], notUsed: notAvailable(pattern) }
173
+ : { ok: true, runs: [event] }
174
+ }
175
+ if (isEngineName(pattern)) return { ok: true, runs: [], notUsed: notAvailable(pattern) }
176
+ return { ok: false, message: `"${pattern}" is not an event` }
177
+ }