@namzu/sdk 69.1.0 → 69.3.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 (133) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/constants/plugin/index.d.ts +8 -0
  3. package/dist/constants/plugin/index.d.ts.map +1 -1
  4. package/dist/constants/plugin/index.js +8 -0
  5. package/dist/constants/plugin/index.js.map +1 -1
  6. package/dist/persona/assembler.d.ts.map +1 -1
  7. package/dist/persona/assembler.js +7 -1
  8. package/dist/persona/assembler.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/public-runtime.d.ts +3 -2
  81. package/dist/public-runtime.d.ts.map +1 -1
  82. package/dist/public-runtime.js +2 -2
  83. package/dist/public-runtime.js.map +1 -1
  84. package/dist/public-tools.d.ts +2 -0
  85. package/dist/public-tools.d.ts.map +1 -1
  86. package/dist/public-tools.js +4 -0
  87. package/dist/public-tools.js.map +1 -1
  88. package/dist/skills/loader.d.ts +8 -2
  89. package/dist/skills/loader.d.ts.map +1 -1
  90. package/dist/skills/loader.js +22 -11
  91. package/dist/skills/loader.js.map +1 -1
  92. package/dist/skills/registry.d.ts.map +1 -1
  93. package/dist/skills/registry.js +9 -1
  94. package/dist/skills/registry.js.map +1 -1
  95. package/dist/tools/builtins/atomic-write-file.d.ts +19 -3
  96. package/dist/tools/builtins/atomic-write-file.d.ts.map +1 -1
  97. package/dist/tools/builtins/atomic-write-file.js +56 -3
  98. package/dist/tools/builtins/atomic-write-file.js.map +1 -1
  99. package/dist/types/plugin/index.d.ts +73 -0
  100. package/dist/types/plugin/index.d.ts.map +1 -1
  101. package/dist/types/plugin/index.js +28 -6
  102. package/dist/types/plugin/index.js.map +1 -1
  103. package/dist/types/skills/index.d.ts +13 -0
  104. package/dist/types/skills/index.d.ts.map +1 -1
  105. package/dist/types/skills/index.js.map +1 -1
  106. package/package.json +2 -1
  107. package/src/constants/plugin/index.ts +9 -0
  108. package/src/persona/assembler.ts +7 -1
  109. package/src/plugin/common-layout/index.ts +19 -0
  110. package/src/plugin/common-layout/mcp.ts +362 -0
  111. package/src/plugin/common-layout/paths.ts +70 -0
  112. package/src/plugin/common-layout/read.ts +1282 -0
  113. package/src/plugin/common-layout/types.ts +77 -0
  114. package/src/plugin/common-layout-names.ts +108 -0
  115. package/src/plugin/hook-module/capabilities.ts +500 -0
  116. package/src/plugin/hook-module/consent.ts +96 -0
  117. package/src/plugin/hook-module/events.ts +177 -0
  118. package/src/plugin/hook-module/host.ts +649 -0
  119. package/src/plugin/hook-module/index.ts +52 -0
  120. package/src/plugin/hook-module/scan.ts +1004 -0
  121. package/src/plugin/hook-module/worker-source.ts +500 -0
  122. package/src/plugin/index.ts +13 -1
  123. package/src/plugin/lifecycle.ts +179 -17
  124. package/src/plugin/loader.ts +97 -18
  125. package/src/plugin/shell-hook-env.ts +7 -0
  126. package/src/plugin/shell-hook.ts +91 -70
  127. package/src/public-runtime.ts +35 -0
  128. package/src/public-tools.ts +6 -0
  129. package/src/skills/loader.ts +26 -9
  130. package/src/skills/registry.ts +9 -1
  131. package/src/tools/builtins/atomic-write-file.ts +73 -5
  132. package/src/types/plugin/index.ts +81 -24
  133. package/src/types/skills/index.ts +15 -0
@@ -108,6 +108,11 @@
108
108
  import { spawn } from 'node:child_process'
109
109
  import { constants, accessSync, mkdirSync, statSync } from 'node:fs'
110
110
  import { basename, delimiter } from 'node:path'
111
+ import {
112
+ COMMON_DATA_VARIABLE,
113
+ COMMON_PROJECT_VARIABLE,
114
+ COMMON_ROOT_VARIABLE,
115
+ } from './common-layout-names.js'
111
116
 
112
117
  import { decodedCommands, decomposeCommandLine } from '../authorization/command-line.js'
113
118
  import {
@@ -1011,6 +1016,13 @@ export function runShellHook(
1011
1016
  ...(input.plugin !== undefined
1012
1017
  ? { NAMZU_PLUGIN_ROOT: input.plugin.root, NAMZU_PLUGIN_DATA: input.plugin.dataDir }
1013
1018
  : {}),
1019
+ ...(input.plugin?.layout === 'common'
1020
+ ? {
1021
+ [COMMON_ROOT_VARIABLE]: input.plugin.root,
1022
+ [COMMON_DATA_VARIABLE]: input.plugin.dataDir,
1023
+ [COMMON_PROJECT_VARIABLE]: projectDir,
1024
+ }
1025
+ : {}),
1014
1026
  ...(input.turnId !== undefined ? { NAMZU_TURN_ID: input.turnId } : {}),
1015
1027
  ...(input.envFile !== undefined ? { NAMZU_ENV_FILE: input.envFile } : {}),
1016
1028
  ...(input.toolName !== undefined
@@ -2239,6 +2251,83 @@ async function runWorktreeHook(
2239
2251
  */
2240
2252
  let nextHookEnvSlot = 0
2241
2253
 
2254
+ /**
2255
+ * What a hook is told about an event: the context the kernel dispatched, turned
2256
+ * into the input every kind of hook reads. A command gets it as JSON on stdin,
2257
+ * a module as its `e`.
2258
+ */
2259
+ export function shellHookInputFor(
2260
+ event: ShellHookEvent,
2261
+ context: PluginHookContext,
2262
+ options: ShellHookOptions,
2263
+ extra: { readonly envFile?: string; readonly toolNames?: ShellHookToolNames } = {},
2264
+ ): ShellHookInput {
2265
+ const transcriptPath = options.transcriptPath?.(String(context.sessionId))
2266
+ const permissionMode = options.permissionMode?.()
2267
+ return {
2268
+ event,
2269
+ // A hook told the folder changed runs in the folder entered.
2270
+ cwd: event === 'cwd_changed' && context.newCwd !== undefined ? context.newCwd : options.cwd,
2271
+ ...(extra.envFile !== undefined ? { envFile: extra.envFile } : {}),
2272
+ ...(context.filePath !== undefined ? { filePath: context.filePath } : {}),
2273
+ ...(context.change !== undefined ? { change: context.change } : {}),
2274
+ ...(context.oldCwd !== undefined ? { oldCwd: context.oldCwd } : {}),
2275
+ ...(context.newCwd !== undefined ? { newCwd: context.newCwd } : {}),
2276
+ ...(context.worktreeName !== undefined ? { worktreeName: context.worktreeName } : {}),
2277
+ ...(context.worktreeRoot !== undefined ? { worktreeRoot: context.worktreeRoot } : {}),
2278
+ ...(context.worktreeBaseRef !== undefined ? { worktreeBaseRef: context.worktreeBaseRef } : {}),
2279
+ ...(context.worktreePath !== undefined ? { worktreePath: context.worktreePath } : {}),
2280
+ ...(context.modelSwitch !== undefined ? { modelSwitch: context.modelSwitch } : {}),
2281
+ ...(context.elicitation !== undefined ? { elicitation: context.elicitation } : {}),
2282
+ ...(context.directory !== undefined ? { directory: context.directory } : {}),
2283
+ ...(context.directorySource !== undefined ? { directorySource: context.directorySource } : {}),
2284
+ ...(context.instructions !== undefined ? { instructions: context.instructions } : {}),
2285
+ ...(context.expansion !== undefined ? { expansion: context.expansion } : {}),
2286
+ ...(context.skillShell !== undefined ? { skillShell: context.skillShell } : {}),
2287
+ ...(context.task !== undefined ? { task: context.task } : {}),
2288
+ ...(context.teammateName !== undefined ? { teammateName: context.teammateName } : {}),
2289
+ ...(context.teamName !== undefined ? { teamName: context.teamName } : {}),
2290
+ ...(options.projectDir !== undefined ? { projectDir: options.projectDir } : {}),
2291
+ ...(options.plugin !== undefined ? { plugin: options.plugin } : {}),
2292
+ sessionId: String(context.sessionId),
2293
+ ...(context.source !== undefined ? { sessionSource: context.source } : {}),
2294
+ ...(context.endReason !== undefined ? { endReason: context.endReason } : {}),
2295
+ ...(context.turnId !== undefined ? { turnId: String(context.turnId) } : {}),
2296
+ ...(context.parentSessionId !== undefined
2297
+ ? { parentSessionId: String(context.parentSessionId) }
2298
+ : {}),
2299
+ ...(context.parentTurnId !== undefined ? { parentTurnId: String(context.parentTurnId) } : {}),
2300
+ ...(context.agentType !== undefined ? { agentType: context.agentType } : {}),
2301
+ ...(context.prompt !== undefined ? { prompt: context.prompt } : {}),
2302
+ ...(context.compaction !== undefined ? { compaction: context.compaction } : {}),
2303
+ ...(context.toolName !== undefined ? { toolName: context.toolName } : {}),
2304
+ ...(extra.toolNames !== undefined ? { toolNames: extra.toolNames } : {}),
2305
+ ...(context.toolCallId !== undefined ? { toolCallId: context.toolCallId } : {}),
2306
+ ...(context.toolInput !== undefined ? { toolInput: context.toolInput } : {}),
2307
+ ...(context.toolResult !== undefined
2308
+ ? {
2309
+ toolResult: {
2310
+ success: context.toolResult.success,
2311
+ output: context.toolResult.output,
2312
+ ...(context.toolResult.error !== undefined ? { error: context.toolResult.error } : {}),
2313
+ },
2314
+ }
2315
+ : {}),
2316
+ ...(context.toolCalls !== undefined ? { toolCalls: context.toolCalls } : {}),
2317
+ ...(context.reason !== undefined ? { reason: context.reason } : {}),
2318
+ ...(context.error !== undefined ? { error: context.error } : {}),
2319
+ ...(context.notification !== undefined ? { notification: context.notification } : {}),
2320
+ ...(context.stopHookActive === true ? { stopHookActive: true } : {}),
2321
+ ...(context.lastAssistantMessage !== undefined
2322
+ ? { lastAssistantMessage: context.lastAssistantMessage }
2323
+ : {}),
2324
+ ...(transcriptPath !== undefined ? { transcriptPath } : {}),
2325
+ ...(permissionMode !== undefined ? { permissionMode } : {}),
2326
+ ...(options.extraEnv !== undefined ? { extraEnv: options.extraEnv } : {}),
2327
+ ...(options.skillRoot !== undefined ? { skillRoot: options.skillRoot } : {}),
2328
+ }
2329
+ }
2330
+
2242
2331
  /** One entry as a hook definition the lifecycle manager accepts. */
2243
2332
  export function createShellHook(
2244
2333
  event: ShellHookEvent,
@@ -2343,8 +2432,6 @@ export function createShellHook(
2343
2432
  }
2344
2433
  if (entry.once === true && !doesTheWork) spent = true
2345
2434
  options.onRun?.({ event })
2346
- const transcriptPath = options.transcriptPath?.(String(context.sessionId))
2347
- const permissionMode = options.permissionMode?.()
2348
2435
  const envEvent =
2349
2436
  event === 'session_start' || event === 'cwd_changed' || event === 'file_changed'
2350
2437
  ? event
@@ -2354,76 +2441,10 @@ export function createShellHook(
2354
2441
  envEvent !== undefined && runsACommand
2355
2442
  ? options.hookEnv?.fileFor(envEvent, envSlot)
2356
2443
  : undefined
2357
- const hookInput: ShellHookInput = {
2358
- event,
2359
- // A hook told the folder changed runs in the folder entered.
2360
- cwd: event === 'cwd_changed' && context.newCwd !== undefined ? context.newCwd : options.cwd,
2444
+ const hookInput = shellHookInputFor(event, context, options, {
2361
2445
  ...(envFile !== undefined ? { envFile } : {}),
2362
- ...(context.filePath !== undefined ? { filePath: context.filePath } : {}),
2363
- ...(context.change !== undefined ? { change: context.change } : {}),
2364
- ...(context.oldCwd !== undefined ? { oldCwd: context.oldCwd } : {}),
2365
- ...(context.newCwd !== undefined ? { newCwd: context.newCwd } : {}),
2366
- ...(context.worktreeName !== undefined ? { worktreeName: context.worktreeName } : {}),
2367
- ...(context.worktreeRoot !== undefined ? { worktreeRoot: context.worktreeRoot } : {}),
2368
- ...(context.worktreeBaseRef !== undefined
2369
- ? { worktreeBaseRef: context.worktreeBaseRef }
2370
- : {}),
2371
- ...(context.worktreePath !== undefined ? { worktreePath: context.worktreePath } : {}),
2372
- ...(context.modelSwitch !== undefined ? { modelSwitch: context.modelSwitch } : {}),
2373
- ...(context.elicitation !== undefined ? { elicitation: context.elicitation } : {}),
2374
- ...(context.directory !== undefined ? { directory: context.directory } : {}),
2375
- ...(context.directorySource !== undefined
2376
- ? { directorySource: context.directorySource }
2377
- : {}),
2378
- ...(context.instructions !== undefined ? { instructions: context.instructions } : {}),
2379
- ...(context.expansion !== undefined ? { expansion: context.expansion } : {}),
2380
- ...(context.skillShell !== undefined ? { skillShell: context.skillShell } : {}),
2381
- ...(context.task !== undefined ? { task: context.task } : {}),
2382
- ...(context.teammateName !== undefined ? { teammateName: context.teammateName } : {}),
2383
- ...(context.teamName !== undefined ? { teamName: context.teamName } : {}),
2384
- ...(options.projectDir !== undefined ? { projectDir: options.projectDir } : {}),
2385
- ...(options.plugin !== undefined ? { plugin: options.plugin } : {}),
2386
- sessionId: String(context.sessionId),
2387
- ...(context.source !== undefined ? { sessionSource: context.source } : {}),
2388
- ...(context.endReason !== undefined ? { endReason: context.endReason } : {}),
2389
- ...(context.turnId !== undefined ? { turnId: String(context.turnId) } : {}),
2390
- ...(context.parentSessionId !== undefined
2391
- ? { parentSessionId: String(context.parentSessionId) }
2392
- : {}),
2393
- ...(context.parentTurnId !== undefined
2394
- ? { parentTurnId: String(context.parentTurnId) }
2395
- : {}),
2396
- ...(context.agentType !== undefined ? { agentType: context.agentType } : {}),
2397
- ...(context.prompt !== undefined ? { prompt: context.prompt } : {}),
2398
- ...(context.compaction !== undefined ? { compaction: context.compaction } : {}),
2399
- ...(context.toolName !== undefined ? { toolName: context.toolName } : {}),
2400
2446
  ...(entry.toolNames !== undefined ? { toolNames: entry.toolNames } : {}),
2401
- ...(context.toolCallId !== undefined ? { toolCallId: context.toolCallId } : {}),
2402
- ...(context.toolInput !== undefined ? { toolInput: context.toolInput } : {}),
2403
- ...(context.toolResult !== undefined
2404
- ? {
2405
- toolResult: {
2406
- success: context.toolResult.success,
2407
- output: context.toolResult.output,
2408
- ...(context.toolResult.error !== undefined
2409
- ? { error: context.toolResult.error }
2410
- : {}),
2411
- },
2412
- }
2413
- : {}),
2414
- ...(context.toolCalls !== undefined ? { toolCalls: context.toolCalls } : {}),
2415
- ...(context.reason !== undefined ? { reason: context.reason } : {}),
2416
- ...(context.error !== undefined ? { error: context.error } : {}),
2417
- ...(context.notification !== undefined ? { notification: context.notification } : {}),
2418
- ...(context.stopHookActive === true ? { stopHookActive: true } : {}),
2419
- ...(context.lastAssistantMessage !== undefined
2420
- ? { lastAssistantMessage: context.lastAssistantMessage }
2421
- : {}),
2422
- ...(transcriptPath !== undefined ? { transcriptPath } : {}),
2423
- ...(permissionMode !== undefined ? { permissionMode } : {}),
2424
- ...(options.extraEnv !== undefined ? { extraEnv: options.extraEnv } : {}),
2425
- ...(options.skillRoot !== undefined ? { skillRoot: options.skillRoot } : {}),
2426
- }
2447
+ })
2427
2448
  const verdictCall: ShellHookCall = {
2428
2449
  ...(context.toolName !== undefined ? { toolName: context.toolName } : {}),
2429
2450
  ...(context.toolInput !== undefined ? { toolInput: context.toolInput } : {}),
@@ -846,6 +846,40 @@ export {
846
846
  worktreeHookVerdict,
847
847
  worktreeHookPrinted,
848
848
  WORKTREE_HOOK_SHOWN_CHARS,
849
+ expandPluginPaths,
850
+ expandPluginRootText,
851
+ COMMON_MARKETPLACE_DIR,
852
+ COMMON_MARKETPLACE_FILE,
853
+ findCommonLayoutRoot,
854
+ isOfficialLookingMarketplaceName,
855
+ loadPluginManifestWithFindings,
856
+ readCommonLayout,
857
+ hookModuleConsentEntry,
858
+ hookModuleConsentLines,
859
+ locateHookModule,
860
+ scanHookModule,
861
+ startHookModule,
862
+ summarizeHookModule,
863
+ } from './plugin/index.js'
864
+ export type {
865
+ CommonLayoutOptions,
866
+ CommonLayoutRead,
867
+ CommonLayoutSource,
868
+ ExpandedPaths,
869
+ LayoutFinding,
870
+ LayoutFindingLevel,
871
+ HookModuleConsentEntry,
872
+ HookModuleHandle,
873
+ HookModuleLocation,
874
+ HookModuleScan,
875
+ HookModuleSummary,
876
+ LayoutSetupServer,
877
+ LoadedPluginManifest,
878
+ PluginPathValues,
879
+ ScanRefusal,
880
+ ScannedCall,
881
+ ScannedHook,
882
+ StartHookModuleOptions,
849
883
  } from './plugin/index.js'
850
884
  export type { DefinedPlugin, DefinePluginOptions } from './plugin/define.js'
851
885
 
@@ -1480,6 +1514,7 @@ export {
1480
1514
  assertPluginStatus,
1481
1515
  PluginManifestSchema,
1482
1516
  PluginMCPServerConfigSchema,
1517
+ PluginRemoteMCPServerConfigSchema,
1483
1518
  RENAMED_PLUGIN_HOOK_EVENTS,
1484
1519
  } from './types/plugin/index.js'
1485
1520
  export { toMemoryCandidate } from './types/session/memory-promotion.js'
@@ -44,6 +44,12 @@ export type { UntrustedEnvelope, WrapUntrustedOptions } from './tools/untrusted-
44
44
 
45
45
  // ─── Built-in tools ──────────────────────────────────────────────────────
46
46
 
47
+ // The one atomic file write the file tools use, for a host that writes a file
48
+ // of its own the same safe way (temporary beside it, flushed, renamed), with an
49
+ // opt-in refusal of symbolic links below a folder it names.
50
+ export { UnsafeWritePathError, atomicWriteFile } from './tools/builtins/atomic-write-file.js'
51
+ export type { AtomicWriteOptions } from './tools/builtins/atomic-write-file.js'
52
+
47
53
  export { getBuiltinTools } from './tools/builtins/index.js'
48
54
  // A host compiling operator permissions has a tool name and needs an argument
49
55
  // to attach a pattern to. Without one it can only match against the serialised
@@ -152,7 +152,11 @@ function mappingAt(
152
152
  return found?.kind === 'mapping' ? found.entries : undefined
153
153
  }
154
154
 
155
- function toSkillMetadata(parsed: ParsedFrontmatter, dirPath: string): SkillMetadata {
155
+ function toSkillMetadata(
156
+ parsed: ParsedFrontmatter,
157
+ dirPath: string,
158
+ anyFolderName = false,
159
+ ): SkillMetadata {
156
160
  const source = sourceLabel(dirPath)
157
161
  const { values } = parsed
158
162
 
@@ -166,7 +170,7 @@ function toSkillMetadata(parsed: ParsedFrontmatter, dirPath: string): SkillMetad
166
170
  throw new Error(`${source} missing required field: description`)
167
171
  }
168
172
 
169
- validateSkillName(name, dirPath)
173
+ validateSkillName(name, dirPath, anyFolderName)
170
174
  validateDescription(description, dirPath)
171
175
 
172
176
  const skillMetadata: SkillMetadata = { name, description }
@@ -272,7 +276,7 @@ const REASONING_EFFORTS: readonly ReasoningEffort[] = [
272
276
 
273
277
  const SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
274
278
 
275
- function validateSkillName(name: string, dirPath: string): void {
279
+ function validateSkillName(name: string, dirPath: string, anyFolderName = false): void {
276
280
  if (name.length > 64) {
277
281
  throw new Error(`SKILL.md at "${dirPath}": name exceeds 64 characters`)
278
282
  }
@@ -282,7 +286,7 @@ function validateSkillName(name: string, dirPath: string): void {
282
286
  )
283
287
  }
284
288
  const expectedName = basename(dirPath)
285
- if (name !== expectedName) {
289
+ if (!anyFolderName && name !== expectedName) {
286
290
  throw new Error(
287
291
  `SKILL.md at "${dirPath}": name "${name}" must match directory name "${expectedName}"`,
288
292
  )
@@ -313,23 +317,30 @@ function estimateTokens(text: string): number {
313
317
  * so the two cannot disagree about what a valid skill is.
314
318
  *
315
319
  * @param dirPath The skill's folder: the name must match its last segment.
320
+ * @param options `anyFolderName` skips that match, for a plugin whose own folder
321
+ * is the skill (the folder is named for a version, not the skill).
316
322
  */
317
323
  export function parseSkillMarkdown(
318
324
  raw: string,
319
325
  dirPath: string,
326
+ options?: { readonly anyFolderName?: boolean },
320
327
  ): { readonly metadata: SkillMetadata; readonly body: string } {
321
328
  const parsed = parseFrontmatter(raw, sourceLabel(dirPath), SKILL_FRONTMATTER_OPTIONS)
322
- return { metadata: toSkillMetadata(parsed, dirPath), body: parsed.body }
329
+ return {
330
+ metadata: toSkillMetadata(parsed, dirPath, options?.anyFolderName === true),
331
+ body: parsed.body,
332
+ }
323
333
  }
324
334
 
325
335
  export async function loadSkill(
326
336
  dirPath: string,
327
337
  level: SkillDisclosureLevel = 'metadata',
328
338
  log?: Logger,
339
+ options?: { readonly anyFolderName?: boolean },
329
340
  ): Promise<SkillLoadResult> {
330
341
  const skillMdPath = join(dirPath, SKILL_FILENAME)
331
342
  const raw = await readFile(skillMdPath, 'utf-8')
332
- const parsedSkill = parseSkillMarkdown(raw, dirPath)
343
+ const parsedSkill = parseSkillMarkdown(raw, dirPath, options)
333
344
  const metadata = parsedSkill.metadata
334
345
 
335
346
  const skill: Skill = {
@@ -354,7 +365,9 @@ export async function loadSkill(
354
365
  // it. Without a `log`, this loader emits nothing (`resolveLogger` is
355
366
  // `NOOP_LOGGER`), which is the deliberate default rather than a fallback
356
367
  // to somebody else's stream.
357
- const logger = resolveLogger(log).child({ [SCOPE_ATTRIBUTE]: 'skills/loader' })
368
+ const logger = resolveLogger(log).child({
369
+ [SCOPE_ATTRIBUTE]: 'skills/loader',
370
+ })
358
371
  logger.debug('Loaded skill', {
359
372
  'namzu.skills.name': metadata.name,
360
373
  'namzu.skills.level': level,
@@ -371,7 +384,9 @@ export async function loadSkill(
371
384
  export async function discoverSkills(parentDir: string, log?: Logger): Promise<string[]> {
372
385
  // Resolved here too — see loadSkill above for why module scope froze
373
386
  // this logger's level, and its very reference, at import time.
374
- const logger = resolveLogger(log).child({ [SCOPE_ATTRIBUTE]: 'skills/loader' })
387
+ const logger = resolveLogger(log).child({
388
+ [SCOPE_ATTRIBUTE]: 'skills/loader',
389
+ })
375
390
  const dirs: string[] = []
376
391
 
377
392
  try {
@@ -389,7 +404,9 @@ export async function discoverSkills(parentDir: string, log?: Logger): Promise<s
389
404
  } catch {}
390
405
  }
391
406
  } catch {
392
- logger.debug('Skills directory not found', { 'namzu.skills.parent_dir': parentDir })
407
+ logger.debug('Skills directory not found', {
408
+ 'namzu.skills.parent_dir': parentDir,
409
+ })
393
410
  }
394
411
 
395
412
  return dirs.sort()
@@ -11,6 +11,7 @@ import {
11
11
  import { SCOPE_ATTRIBUTE } from '../utils/log/types.js'
12
12
  import { type Logger, resolveLogger } from '../utils/logger.js'
13
13
 
14
+ import { expandPluginRootText } from '../plugin/common-layout/paths.js'
14
15
  import { SKILL_FILENAME, discoverSkills, loadSkill } from './loader.js'
15
16
 
16
17
  /** Two skills claiming one registered name. */
@@ -205,7 +206,14 @@ export class SkillRegistry {
205
206
  // registry the registered one, which is the divergence this re-keying
206
207
  // exists to prevent, reintroduced one line below the comment saying
207
208
  // so.
208
- const rekeyed: Skill = { ...result.skill, metadata: { ...result.skill.metadata, name } }
209
+ const rekeyed: Skill = {
210
+ ...result.skill,
211
+ ...(result.skill.body !== undefined && existing.pluginRoot !== undefined
212
+ ? { body: expandPluginRootText(result.skill.body, existing.pluginRoot) }
213
+ : {}),
214
+ ...(existing.pluginRoot !== undefined ? { pluginRoot: existing.pluginRoot } : {}),
215
+ metadata: { ...result.skill.metadata, name },
216
+ }
209
217
  this.skills.set(name, rekeyed)
210
218
  await this.stamp(name, existing.dirPath)
211
219
  return { ...result, skill: rekeyed }
@@ -1,10 +1,74 @@
1
1
  import { randomUUID } from 'node:crypto'
2
+ import { lstatSync, realpathSync } from 'node:fs'
2
3
  import { type FileHandle, mkdir, open, realpath, rename, stat, unlink } from 'node:fs/promises'
3
- import { basename, dirname, join } from 'node:path'
4
+ import nodePath, { basename, dirname, join, sep } from 'node:path'
4
5
 
5
- interface AtomicWriteHooks {
6
+ /** A write refused because its path runs through a symbolic link or out of its root. */
7
+ export class UnsafeWritePathError extends Error {
8
+ override readonly name = 'UnsafeWritePathError'
9
+ }
10
+
11
+ export interface AtomicWriteOptions {
6
12
  /** Internal fault-injection seam; production callers never pass this. */
7
13
  beforeCommit?: () => Promise<void>
14
+ /** The permission bits of a new file; an existing file keeps its own mode when this is left out. */
15
+ mode?: number
16
+ /**
17
+ * Never write through a symbolic link below this folder. Every component of
18
+ * the path under `refuseLinksBelow` that exists is looked at with `lstat`: a
19
+ * link anywhere (a folder or the file itself) is refused with
20
+ * {@link UnsafeWritePathError}, and the real path of the deepest existing
21
+ * folder must stay inside the real `refuseLinksBelow`. The folder itself is
22
+ * trusted (it may be a link its owner made on purpose). The check runs before
23
+ * anything is created and again just before the rename. Left out, the write
24
+ * goes THROUGH a link and keeps it, which is what the file tools mean.
25
+ */
26
+ refuseLinksBelow?: string
27
+ }
28
+
29
+ function lstatOrUndefined(path: string): ReturnType<typeof lstatSync> | undefined {
30
+ try {
31
+ return lstatSync(path)
32
+ } catch (error) {
33
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined
34
+ throw error
35
+ }
36
+ }
37
+
38
+ function realOrSelf(path: string): string {
39
+ try {
40
+ return realpathSync(path)
41
+ } catch {
42
+ return path
43
+ }
44
+ }
45
+
46
+ function isInside(root: string, path: string): boolean {
47
+ const rel = nodePath.relative(root, path)
48
+ return rel === '' || (!nodePath.isAbsolute(rel) && rel !== '..' && !rel.startsWith(`..${sep}`))
49
+ }
50
+
51
+ function assertNoLinkBelow(anchor: string, file: string): void {
52
+ const rel = nodePath.relative(anchor, file)
53
+ if (rel === '' || nodePath.isAbsolute(rel) || rel === '..' || rel.startsWith(`..${sep}`)) {
54
+ throw new UnsafeWritePathError(`${file} is not inside ${anchor}.`)
55
+ }
56
+ let current = anchor
57
+ let deepest = anchor
58
+ for (const part of rel.split(sep)) {
59
+ current = join(current, part)
60
+ const stat = lstatOrUndefined(current)
61
+ if (stat === undefined) break
62
+ if (stat.isSymbolicLink()) {
63
+ throw new UnsafeWritePathError(
64
+ `${current} is a symbolic link; it is never written through. Remove the link or save somewhere else.`,
65
+ )
66
+ }
67
+ deepest = current
68
+ }
69
+ if (!isInside(realOrSelf(anchor), realOrSelf(deepest))) {
70
+ throw new UnsafeWritePathError(`${file} resolves outside ${anchor}; nothing was written.`)
71
+ }
8
72
  }
9
73
 
10
74
  /**
@@ -16,7 +80,7 @@ interface AtomicWriteHooks {
16
80
  export async function atomicWriteFile(
17
81
  requestedPath: string,
18
82
  content: string,
19
- hooks: AtomicWriteHooks = {},
83
+ hooks: AtomicWriteOptions = {},
20
84
  ): Promise<void> {
21
85
  // Write THROUGH a symlink, not over it. `rename` replaces whatever sits
22
86
  // at the destination, so committing onto a link path swaps the link for
@@ -24,7 +88,10 @@ export async function atomicWriteFile(
24
88
  // through it now reads stale content. Resolving first keeps the link and
25
89
  // updates what it points at, which is what a caller editing a linked
26
90
  // file means. A path that does not exist yet resolves to itself.
27
- const filePath = await realpath(requestedPath).catch(() => requestedPath)
91
+ const anchor = hooks.refuseLinksBelow
92
+ if (anchor !== undefined) assertNoLinkBelow(anchor, requestedPath)
93
+ const filePath =
94
+ anchor === undefined ? await realpath(requestedPath).catch(() => requestedPath) : requestedPath
28
95
  const directory = dirname(filePath)
29
96
  await mkdir(directory, { recursive: true })
30
97
 
@@ -39,12 +106,13 @@ export async function atomicWriteFile(
39
106
  let committed = false
40
107
 
41
108
  try {
42
- handle = await open(tempPath, 'wx', existingMode ?? 0o666)
109
+ handle = await open(tempPath, 'wx', hooks.mode ?? existingMode ?? 0o666)
43
110
  await handle.writeFile(content, 'utf-8')
44
111
  await handle.sync()
45
112
  await handle.close()
46
113
  handle = undefined
47
114
  await hooks.beforeCommit?.()
115
+ if (anchor !== undefined) assertNoLinkBelow(anchor, filePath)
48
116
  await rename(tempPath, filePath)
49
117
  committed = true
50
118
  await syncDirectory(directory)
@@ -1,5 +1,9 @@
1
1
  import { z } from 'zod'
2
2
  import {
3
+ COMMON_LAYOUT_MAX_AGENTS,
4
+ COMMON_LAYOUT_MAX_COMMANDS,
5
+ COMMON_LAYOUT_MAX_MCP_SERVERS,
6
+ COMMON_LAYOUT_MAX_SKILLS,
3
7
  MAX_AGENT_DIRS_PER_PLUGIN,
4
8
  MAX_COMMAND_DIRS_PER_PLUGIN,
5
9
  MAX_CONNECTORS_PER_PLUGIN,
@@ -839,7 +843,9 @@ export type PluginHookResultFor<E extends PluginHookEvent> = E extends 'user_pro
839
843
  : E extends 'pre_compact'
840
844
  ? Extract<
841
845
  PluginHookResult,
842
- { action: 'continue' | 'annotate' | 'skip' | 'error' }
846
+ {
847
+ action: 'continue' | 'annotate' | 'skip' | 'error'
848
+ }
843
849
  >
844
850
  : E extends 'turn_end' | 'subagent_stop'
845
851
  ? Extract<PluginHookResult, { action: 'continue' | 'skip' | 'error' }>
@@ -902,6 +908,19 @@ export interface PluginMCPServerConfig {
902
908
  readonly connectTimeoutMs?: number
903
909
  }
904
910
 
911
+ /**
912
+ * A server a plugin reaches over the network instead of starting. It is read
913
+ * and reported; nothing connects to it yet, and the plugin file holds no
914
+ * secret (a header value may name an environment variable as `${NAME}`).
915
+ */
916
+ export interface PluginRemoteMCPServerConfig {
917
+ readonly name: string
918
+ readonly url: string
919
+ /** Absent means `http`. */
920
+ readonly transport?: 'http' | 'sse'
921
+ readonly headers?: Readonly<Record<string, string>>
922
+ }
923
+
905
924
  // ---------------------------------------------------------------------------
906
925
  // Plugin manifest — validated at load time
907
926
  // ---------------------------------------------------------------------------
@@ -928,6 +947,8 @@ export interface PluginManifest {
928
947
  */
929
948
  readonly hookEntries?: Readonly<Record<string, unknown>>
930
949
  readonly mcpServers?: readonly PluginMCPServerConfig[]
950
+ /** Servers reached over the network: read and reported, never started by the lifecycle. */
951
+ readonly remoteMcpServers?: readonly PluginRemoteMCPServerConfig[]
931
952
  readonly connectors?: readonly string[]
932
953
  readonly personas?: readonly string[]
933
954
  /**
@@ -946,6 +967,11 @@ export interface PluginManifest {
946
967
  readonly platforms?: readonly string[]
947
968
  /** Runtime versions the plugin supports. Absent means any. */
948
969
  readonly engines?: { readonly namzu?: string }
970
+ /**
971
+ * Which layout the manifest was read from. Set only by the common-layout
972
+ * reader, never by the schema: a `plugin.json` cannot claim it.
973
+ */
974
+ readonly layout?: 'common'
949
975
  }
950
976
 
951
977
  export const PluginMCPServerConfigSchema = z
@@ -958,6 +984,15 @@ export const PluginMCPServerConfigSchema = z
958
984
  })
959
985
  .strict()
960
986
 
987
+ export const PluginRemoteMCPServerConfigSchema = z
988
+ .object({
989
+ name: z.string().min(1),
990
+ url: z.string().min(1).max(2048),
991
+ transport: z.enum(['http', 'sse']).optional(),
992
+ headers: z.record(z.string(), z.string()).optional(),
993
+ })
994
+ .strict()
995
+
961
996
  /** A folder inside the plugin: relative, no `..` step, no drive or root. */
962
997
  const PluginRelativeDirSchema = z
963
998
  .string()
@@ -968,29 +1003,51 @@ const PluginRelativeDirSchema = z
968
1003
  'must be a folder inside the plugin, with no ".." and no absolute path',
969
1004
  )
970
1005
 
971
- export const PluginManifestSchema = z.object({
972
- name: z
973
- .string()
974
- .min(1)
975
- .max(PLUGIN_NAME_MAX_LENGTH)
976
- .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, 'Plugin name must be lowercase kebab-case'),
977
- version: z.string().min(1),
978
- description: z.string().min(1),
979
- author: z.string().optional(),
980
- instructions: z.string().min(1).optional(),
981
- tools: z.array(z.string()).max(MAX_TOOLS_PER_PLUGIN).optional(),
982
- skills: z.array(z.string()).max(MAX_SKILLS_PER_PLUGIN).optional(),
983
- hooks: z.array(z.string()).max(MAX_HOOKS_PER_PLUGIN).optional(),
984
- hookEntries: z.record(z.string(), z.unknown()).optional(),
985
- mcpServers: z.array(PluginMCPServerConfigSchema).max(MAX_MCP_SERVERS_PER_PLUGIN).optional(),
986
- connectors: z.array(z.string()).max(MAX_CONNECTORS_PER_PLUGIN).optional(),
987
- personas: z.array(z.string()).max(MAX_PERSONAS_PER_PLUGIN).optional(),
988
- commands: z.array(PluginRelativeDirSchema).max(MAX_COMMAND_DIRS_PER_PLUGIN).optional(),
989
- agents: z.array(PluginRelativeDirSchema).max(MAX_AGENT_DIRS_PER_PLUGIN).optional(),
990
- /** Operating systems the plugin supports, as `process.platform` names them. Absent means all. */
991
- platforms: z.array(z.string().min(1)).max(16).optional(),
992
- /** Runtime versions the plugin supports. Absent means any. */
993
- engines: z.object({ namzu: z.string().min(1).max(200).optional() }).optional(),
1006
+ const makePluginManifestSchema = (limits: {
1007
+ readonly mcpServers: number
1008
+ readonly skills: number
1009
+ readonly commands: number
1010
+ readonly agents: number
1011
+ }) =>
1012
+ z.object({
1013
+ name: z
1014
+ .string()
1015
+ .min(1)
1016
+ .max(PLUGIN_NAME_MAX_LENGTH)
1017
+ .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, 'Plugin name must be lowercase kebab-case'),
1018
+ version: z.string().min(1),
1019
+ description: z.string().min(1),
1020
+ author: z.string().optional(),
1021
+ instructions: z.string().min(1).optional(),
1022
+ tools: z.array(z.string()).max(MAX_TOOLS_PER_PLUGIN).optional(),
1023
+ skills: z.array(z.string()).max(limits.skills).optional(),
1024
+ hooks: z.array(z.string()).max(MAX_HOOKS_PER_PLUGIN).optional(),
1025
+ hookEntries: z.record(z.string(), z.unknown()).optional(),
1026
+ mcpServers: z.array(PluginMCPServerConfigSchema).max(limits.mcpServers).optional(),
1027
+ remoteMcpServers: z.array(PluginRemoteMCPServerConfigSchema).max(limits.mcpServers).optional(),
1028
+ connectors: z.array(z.string()).max(MAX_CONNECTORS_PER_PLUGIN).optional(),
1029
+ personas: z.array(z.string()).max(MAX_PERSONAS_PER_PLUGIN).optional(),
1030
+ commands: z.array(PluginRelativeDirSchema).max(limits.commands).optional(),
1031
+ agents: z.array(PluginRelativeDirSchema).max(limits.agents).optional(),
1032
+ /** Operating systems the plugin supports, as `process.platform` names them. Absent means all. */
1033
+ platforms: z.array(z.string().min(1)).max(16).optional(),
1034
+ /** Runtime versions the plugin supports. Absent means any. */
1035
+ engines: z.object({ namzu: z.string().min(1).max(200).optional() }).optional(),
1036
+ })
1037
+
1038
+ export const PluginManifestSchema = makePluginManifestSchema({
1039
+ mcpServers: MAX_MCP_SERVERS_PER_PLUGIN,
1040
+ skills: MAX_SKILLS_PER_PLUGIN,
1041
+ commands: MAX_COMMAND_DIRS_PER_PLUGIN,
1042
+ agents: MAX_AGENT_DIRS_PER_PLUGIN,
1043
+ })
1044
+
1045
+ /** The same shape with the larger limits a plugin in the common plugin layout may use. */
1046
+ export const CommonLayoutManifestSchema = makePluginManifestSchema({
1047
+ mcpServers: COMMON_LAYOUT_MAX_MCP_SERVERS,
1048
+ skills: COMMON_LAYOUT_MAX_SKILLS,
1049
+ commands: COMMON_LAYOUT_MAX_COMMANDS,
1050
+ agents: COMMON_LAYOUT_MAX_AGENTS,
994
1051
  })
995
1052
 
996
1053
  // ---------------------------------------------------------------------------