@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.
- package/CHANGELOG.md +25 -0
- package/dist/authorization/readonly-commands.d.ts.map +1 -1
- package/dist/authorization/readonly-commands.js +30 -2
- package/dist/authorization/readonly-commands.js.map +1 -1
- package/dist/constants/plugin/index.d.ts +8 -0
- package/dist/constants/plugin/index.d.ts.map +1 -1
- package/dist/constants/plugin/index.js +8 -0
- package/dist/constants/plugin/index.js.map +1 -1
- package/dist/plugin/common-layout/index.d.ts +5 -0
- package/dist/plugin/common-layout/index.d.ts.map +1 -0
- package/dist/plugin/common-layout/index.js +3 -0
- package/dist/plugin/common-layout/index.js.map +1 -0
- package/dist/plugin/common-layout/mcp.d.ts +21 -0
- package/dist/plugin/common-layout/mcp.d.ts.map +1 -0
- package/dist/plugin/common-layout/mcp.js +305 -0
- package/dist/plugin/common-layout/mcp.js.map +1 -0
- package/dist/plugin/common-layout/paths.d.ts +27 -0
- package/dist/plugin/common-layout/paths.d.ts.map +1 -0
- package/dist/plugin/common-layout/paths.js +48 -0
- package/dist/plugin/common-layout/paths.js.map +1 -0
- package/dist/plugin/common-layout/read.d.ts +25 -0
- package/dist/plugin/common-layout/read.d.ts.map +1 -0
- package/dist/plugin/common-layout/read.js +1155 -0
- package/dist/plugin/common-layout/read.js.map +1 -0
- package/dist/plugin/common-layout/types.d.ts +66 -0
- package/dist/plugin/common-layout/types.d.ts.map +1 -0
- package/dist/plugin/common-layout/types.js +2 -0
- package/dist/plugin/common-layout/types.js.map +1 -0
- package/dist/plugin/common-layout-names.d.ts +65 -0
- package/dist/plugin/common-layout-names.d.ts.map +1 -0
- package/dist/plugin/common-layout-names.js +94 -0
- package/dist/plugin/common-layout-names.js.map +1 -0
- package/dist/plugin/hook-module/capabilities.d.ts +41 -0
- package/dist/plugin/hook-module/capabilities.d.ts.map +1 -0
- package/dist/plugin/hook-module/capabilities.js +438 -0
- package/dist/plugin/hook-module/capabilities.js.map +1 -0
- package/dist/plugin/hook-module/consent.d.ts +39 -0
- package/dist/plugin/hook-module/consent.d.ts.map +1 -0
- package/dist/plugin/hook-module/consent.js +59 -0
- package/dist/plugin/hook-module/consent.js.map +1 -0
- package/dist/plugin/hook-module/events.d.ts +33 -0
- package/dist/plugin/hook-module/events.d.ts.map +1 -0
- package/dist/plugin/hook-module/events.js +149 -0
- package/dist/plugin/hook-module/events.js.map +1 -0
- package/dist/plugin/hook-module/host.d.ts +79 -0
- package/dist/plugin/hook-module/host.d.ts.map +1 -0
- package/dist/plugin/hook-module/host.js +546 -0
- package/dist/plugin/hook-module/host.js.map +1 -0
- package/dist/plugin/hook-module/index.d.ts +11 -0
- package/dist/plugin/hook-module/index.d.ts.map +1 -0
- package/dist/plugin/hook-module/index.js +6 -0
- package/dist/plugin/hook-module/index.js.map +1 -0
- package/dist/plugin/hook-module/scan.d.ts +99 -0
- package/dist/plugin/hook-module/scan.d.ts.map +1 -0
- package/dist/plugin/hook-module/scan.js +789 -0
- package/dist/plugin/hook-module/scan.js.map +1 -0
- package/dist/plugin/hook-module/worker-source.d.ts +31 -0
- package/dist/plugin/hook-module/worker-source.d.ts.map +1 -0
- package/dist/plugin/hook-module/worker-source.js +498 -0
- package/dist/plugin/hook-module/worker-source.js.map +1 -0
- package/dist/plugin/index.d.ts +5 -2
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +4 -1
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/lifecycle.d.ts +57 -0
- package/dist/plugin/lifecycle.d.ts.map +1 -1
- package/dist/plugin/lifecycle.js +92 -11
- package/dist/plugin/lifecycle.js.map +1 -1
- package/dist/plugin/loader.d.ts +30 -0
- package/dist/plugin/loader.d.ts.map +1 -1
- package/dist/plugin/loader.js +76 -19
- package/dist/plugin/loader.js.map +1 -1
- package/dist/plugin/shell-hook-env.d.ts +7 -0
- package/dist/plugin/shell-hook-env.d.ts.map +1 -1
- package/dist/plugin/shell-hook-env.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts +10 -1
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +81 -70
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
- package/dist/prompt/coding-agent-doctrine.js +1 -1
- package/dist/provider/side-request-reasoning.d.ts.map +1 -1
- package/dist/provider/side-request-reasoning.js +5 -1
- package/dist/provider/side-request-reasoning.js.map +1 -1
- package/dist/public-runtime.d.ts +3 -2
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +2 -2
- package/dist/public-runtime.js.map +1 -1
- package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/classifier.js +13 -2
- package/dist/runtime/query/auto-review/classifier.js.map +1 -1
- package/dist/runtime/query/auto-review/failure.d.ts +12 -5
- package/dist/runtime/query/auto-review/failure.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/failure.js +42 -7
- package/dist/runtime/query/auto-review/failure.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +22 -6
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/turn/check-scope.d.ts +18 -0
- package/dist/runtime/query/turn/check-scope.d.ts.map +1 -0
- package/dist/runtime/query/turn/check-scope.js +90 -0
- package/dist/runtime/query/turn/check-scope.js.map +1 -0
- package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.js +13 -0
- package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
- package/dist/skills/loader.d.ts +8 -2
- package/dist/skills/loader.d.ts.map +1 -1
- package/dist/skills/loader.js +22 -11
- package/dist/skills/loader.js.map +1 -1
- package/dist/skills/registry.d.ts.map +1 -1
- package/dist/skills/registry.js +9 -1
- package/dist/skills/registry.js.map +1 -1
- package/dist/tools/builtins/job.d.ts.map +1 -1
- package/dist/tools/builtins/job.js +4 -1
- package/dist/tools/builtins/job.js.map +1 -1
- package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
- package/dist/tools/builtins/wait-for-job.js +2 -1
- package/dist/tools/builtins/wait-for-job.js.map +1 -1
- package/dist/types/plugin/index.d.ts +73 -0
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +28 -6
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/skills/index.d.ts +6 -0
- package/dist/types/skills/index.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/authorization/readonly-commands.ts +30 -2
- package/src/constants/plugin/index.ts +9 -0
- package/src/plugin/common-layout/index.ts +19 -0
- package/src/plugin/common-layout/mcp.ts +362 -0
- package/src/plugin/common-layout/paths.ts +70 -0
- package/src/plugin/common-layout/read.ts +1282 -0
- package/src/plugin/common-layout/types.ts +77 -0
- package/src/plugin/common-layout-names.ts +108 -0
- package/src/plugin/hook-module/capabilities.ts +500 -0
- package/src/plugin/hook-module/consent.ts +96 -0
- package/src/plugin/hook-module/events.ts +177 -0
- package/src/plugin/hook-module/host.ts +649 -0
- package/src/plugin/hook-module/index.ts +52 -0
- package/src/plugin/hook-module/scan.ts +1004 -0
- package/src/plugin/hook-module/worker-source.ts +500 -0
- package/src/plugin/index.ts +13 -1
- package/src/plugin/lifecycle.ts +179 -17
- package/src/plugin/loader.ts +97 -18
- package/src/plugin/shell-hook-env.ts +7 -0
- package/src/plugin/shell-hook.ts +91 -70
- package/src/prompt/coding-agent-doctrine.ts +1 -1
- package/src/provider/side-request-reasoning.ts +5 -1
- package/src/public-runtime.ts +35 -0
- package/src/runtime/query/auto-review/classifier.ts +14 -2
- package/src/runtime/query/auto-review/failure.ts +52 -7
- package/src/runtime/query/review-policy.ts +30 -6
- package/src/runtime/query/turn/check-scope.ts +90 -0
- package/src/runtime/query/turn/outcome-ledger.ts +11 -0
- package/src/skills/loader.ts +26 -9
- package/src/skills/registry.ts +9 -1
- package/src/tools/builtins/job.ts +4 -1
- package/src/tools/builtins/wait-for-job.ts +3 -1
- package/src/types/plugin/index.ts +81 -24
- package/src/types/skills/index.ts +7 -0
|
@@ -0,0 +1,1282 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import type { Dirent } from 'node:fs'
|
|
3
|
+
import { lstat, readFile, readdir } from 'node:fs/promises'
|
|
4
|
+
import { basename, join } from 'node:path'
|
|
5
|
+
import { AGENT_FILE_KEYS } from '../../agents/file-definitions.js'
|
|
6
|
+
import {
|
|
7
|
+
COMMON_LAYOUT_MAX_AGENTS,
|
|
8
|
+
COMMON_LAYOUT_MAX_BYTES,
|
|
9
|
+
COMMON_LAYOUT_MAX_COMMANDS,
|
|
10
|
+
COMMON_LAYOUT_MAX_FILES,
|
|
11
|
+
COMMON_LAYOUT_MAX_MCP_SERVERS,
|
|
12
|
+
COMMON_LAYOUT_MAX_SKILLS,
|
|
13
|
+
PLUGIN_MANIFEST_FILENAME,
|
|
14
|
+
PLUGIN_NAME_MAX_LENGTH,
|
|
15
|
+
PLUGIN_NAME_PATTERN,
|
|
16
|
+
} from '../../constants/plugin/index.js'
|
|
17
|
+
import { parseSkillMarkdown } from '../../skills/loader.js'
|
|
18
|
+
import {
|
|
19
|
+
CommonLayoutManifestSchema,
|
|
20
|
+
type PluginManifest,
|
|
21
|
+
RENAMED_PLUGIN_HOOK_EVENTS,
|
|
22
|
+
} from '../../types/plugin/index.js'
|
|
23
|
+
import {
|
|
24
|
+
COMMON_AGENTS_DIR,
|
|
25
|
+
COMMON_COMMANDS_DIR,
|
|
26
|
+
COMMON_HOOKS_FILE,
|
|
27
|
+
COMMON_MANIFEST_DIR,
|
|
28
|
+
COMMON_MANIFEST_FILE,
|
|
29
|
+
COMMON_MCP_FILE,
|
|
30
|
+
COMMON_ROOT_SKILL_FILE,
|
|
31
|
+
COMMON_SKILLS_DIR,
|
|
32
|
+
COMMON_UNUSED_DIRS,
|
|
33
|
+
ENTRY_SIDECAR_FILE,
|
|
34
|
+
} from '../common-layout-names.js'
|
|
35
|
+
import { summarizeHookModule } from '../hook-module/consent.js'
|
|
36
|
+
import { locateHookModule, scanHookModule } from '../hook-module/scan.js'
|
|
37
|
+
import { SHELL_HOOK_EVENTS, SHELL_HOOK_PASCAL_EVENT_NAMES } from '../shell-hook.js'
|
|
38
|
+
import { type McpSource, readMcpSources, serversOf } from './mcp.js'
|
|
39
|
+
import type {
|
|
40
|
+
CommonLayoutOptions,
|
|
41
|
+
CommonLayoutRead,
|
|
42
|
+
CommonLayoutSource,
|
|
43
|
+
LayoutFinding,
|
|
44
|
+
} from './types.js'
|
|
45
|
+
|
|
46
|
+
/** A manifest, sidecar or hooks file larger than this is refused unread. */
|
|
47
|
+
export const MAX_LAYOUT_MANIFEST_BYTES = 256 * 1024
|
|
48
|
+
|
|
49
|
+
/** Fields that name a component Namzu has no place for. */
|
|
50
|
+
const NOT_USED_FIELDS: readonly string[] = [
|
|
51
|
+
'outputStyles',
|
|
52
|
+
'themes',
|
|
53
|
+
'workflows',
|
|
54
|
+
'monitors',
|
|
55
|
+
'channels',
|
|
56
|
+
'lspServers',
|
|
57
|
+
'binaries',
|
|
58
|
+
'settings',
|
|
59
|
+
'types',
|
|
60
|
+
'network',
|
|
61
|
+
'experimental',
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
/** Fields the sidecar may carry; anything else in it is dropped. */
|
|
65
|
+
const SIDECAR_FIELDS: readonly string[] = [
|
|
66
|
+
'name',
|
|
67
|
+
'description',
|
|
68
|
+
'version',
|
|
69
|
+
'author',
|
|
70
|
+
'strict',
|
|
71
|
+
'skills',
|
|
72
|
+
'commands',
|
|
73
|
+
'agents',
|
|
74
|
+
'hooks',
|
|
75
|
+
'mcpServers',
|
|
76
|
+
'platforms',
|
|
77
|
+
'engines',
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
const COMPONENT_FIELDS: readonly string[] = ['skills', 'commands', 'agents', 'hooks', 'mcpServers']
|
|
81
|
+
|
|
82
|
+
const KNOWN_MANIFEST_KEYS = new Set([
|
|
83
|
+
'$schema',
|
|
84
|
+
'name',
|
|
85
|
+
'displayName',
|
|
86
|
+
'version',
|
|
87
|
+
'description',
|
|
88
|
+
'author',
|
|
89
|
+
'homepage',
|
|
90
|
+
'repository',
|
|
91
|
+
'license',
|
|
92
|
+
'keywords',
|
|
93
|
+
'metadata',
|
|
94
|
+
'icon',
|
|
95
|
+
'defaultEnabled',
|
|
96
|
+
'engines',
|
|
97
|
+
'platforms',
|
|
98
|
+
'dependencies',
|
|
99
|
+
'optionalDependencies',
|
|
100
|
+
'skills',
|
|
101
|
+
'commands',
|
|
102
|
+
'agents',
|
|
103
|
+
'hooks',
|
|
104
|
+
'mcpServers',
|
|
105
|
+
'userConfig',
|
|
106
|
+
'connectors',
|
|
107
|
+
'personas',
|
|
108
|
+
...NOT_USED_FIELDS,
|
|
109
|
+
])
|
|
110
|
+
|
|
111
|
+
function isMapping(value: unknown): value is Record<string, unknown> {
|
|
112
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function kebab(text: string): string {
|
|
116
|
+
return text
|
|
117
|
+
.toLowerCase()
|
|
118
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
119
|
+
.replace(/^-+|-+$/g, '')
|
|
120
|
+
.slice(0, PLUGIN_NAME_MAX_LENGTH)
|
|
121
|
+
.replace(/-+$/g, '')
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The folder name of a path, written plugin-style. */
|
|
125
|
+
function nameFromFolder(root: string): string {
|
|
126
|
+
return kebab(basename(root))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
type Kind = 'file' | 'dir' | 'link' | 'other' | 'missing'
|
|
130
|
+
|
|
131
|
+
async function kindOf(path: string): Promise<Kind> {
|
|
132
|
+
try {
|
|
133
|
+
const info = await lstat(path)
|
|
134
|
+
if (info.isSymbolicLink()) return 'link'
|
|
135
|
+
if (info.isFile()) return 'file'
|
|
136
|
+
if (info.isDirectory()) return 'dir'
|
|
137
|
+
return 'other'
|
|
138
|
+
} catch {
|
|
139
|
+
return 'missing'
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Why a path a manifest names is not allowed, or undefined when it is. */
|
|
144
|
+
function relativeProblem(rel: string): string | undefined {
|
|
145
|
+
if (rel.length === 0) return 'is empty'
|
|
146
|
+
if (/^([A-Za-z]:|[\\/])/.test(rel)) return 'is an absolute path'
|
|
147
|
+
if (rel.includes('\0')) return 'holds a NUL character'
|
|
148
|
+
if (rel.split(/[\\/]/).some((part) => part === '..')) return 'leaves the plugin folder with ".."'
|
|
149
|
+
return undefined
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function trimDot(rel: string): string {
|
|
153
|
+
let out = rel.replace(/\\/g, '/')
|
|
154
|
+
while (out.startsWith('./')) out = out.slice(2)
|
|
155
|
+
out = out.replace(/\/+$/, '')
|
|
156
|
+
return out === '' ? '.' : out
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Walk the path one component at a time, never following a link. `link` means a
|
|
161
|
+
* component on the way (or the end) is a symbolic link.
|
|
162
|
+
*/
|
|
163
|
+
async function walk(root: string, rel: string): Promise<Kind> {
|
|
164
|
+
if (rel === '.') return kindOf(root)
|
|
165
|
+
let current = root
|
|
166
|
+
let last: Kind = 'dir'
|
|
167
|
+
for (const part of rel.split('/')) {
|
|
168
|
+
if (part === '' || part === '.') continue
|
|
169
|
+
current = join(current, part)
|
|
170
|
+
last = await kindOf(current)
|
|
171
|
+
if (last === 'link' || last === 'missing') return last
|
|
172
|
+
}
|
|
173
|
+
return last
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function readCapped(path: string): Promise<{ text: string } | { problem: string }> {
|
|
177
|
+
try {
|
|
178
|
+
const info = await lstat(path)
|
|
179
|
+
if (info.size > MAX_LAYOUT_MANIFEST_BYTES) {
|
|
180
|
+
return {
|
|
181
|
+
problem: `is larger than ${MAX_LAYOUT_MANIFEST_BYTES / 1024} KiB`,
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return { text: await readFile(path, 'utf-8') }
|
|
185
|
+
} catch (error) {
|
|
186
|
+
return {
|
|
187
|
+
problem: `cannot be read (${error instanceof Error ? error.message : String(error)})`,
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function toList(value: unknown): unknown[] {
|
|
193
|
+
if (value === undefined || value === null) return []
|
|
194
|
+
return Array.isArray(value) ? value : [value]
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function countOf(value: unknown): number {
|
|
198
|
+
if (Array.isArray(value)) return value.length
|
|
199
|
+
if (isMapping(value)) return Object.keys(value).length
|
|
200
|
+
return value === undefined || value === null ? 0 : 1
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function topKeys(raw: string): string[] {
|
|
204
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(raw)
|
|
205
|
+
if (!match) return []
|
|
206
|
+
const keys: string[] = []
|
|
207
|
+
for (const line of (match[1] as string).split(/\r?\n/)) {
|
|
208
|
+
const key = /^([A-Za-z][\w-]*)\s*:/.exec(line)
|
|
209
|
+
if (key) keys.push(key[1] as string)
|
|
210
|
+
}
|
|
211
|
+
return keys
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
class Collector {
|
|
215
|
+
readonly findings: LayoutFinding[] = []
|
|
216
|
+
add(finding: LayoutFinding): void {
|
|
217
|
+
this.findings.push(finding)
|
|
218
|
+
}
|
|
219
|
+
refusal: LayoutFinding | undefined
|
|
220
|
+
refuseAll(code: string, field: string, message: string): void {
|
|
221
|
+
const finding: LayoutFinding = { level: 'refused', code, field, message }
|
|
222
|
+
this.refusal ??= finding
|
|
223
|
+
this.findings.push(finding)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* What the hooks module a plugin names in its hooks file comes to: a finding
|
|
229
|
+
* for what runs, for what Namzu has no place for, and for what refuses the
|
|
230
|
+
* module (its plain hook entries still load either way).
|
|
231
|
+
*/
|
|
232
|
+
function noteHookModule(root: string, out: Collector): void {
|
|
233
|
+
const located = locateHookModule(root)
|
|
234
|
+
if (located.kind === 'none') return
|
|
235
|
+
if (located.kind === 'refused') {
|
|
236
|
+
out.add({
|
|
237
|
+
level: 'refused',
|
|
238
|
+
code: 'hooks-modules-refused',
|
|
239
|
+
field: 'hooks',
|
|
240
|
+
path: located.hooksFile,
|
|
241
|
+
message: `${located.message} Its plain hook entries still load.`,
|
|
242
|
+
})
|
|
243
|
+
return
|
|
244
|
+
}
|
|
245
|
+
const scan = scanHookModule(root, located.entry)
|
|
246
|
+
for (const refusal of scan.refusals) {
|
|
247
|
+
out.add({
|
|
248
|
+
level: 'refused',
|
|
249
|
+
code: 'hooks-module-scan-refused',
|
|
250
|
+
field: 'hooks',
|
|
251
|
+
path: refusal.file,
|
|
252
|
+
message: `${refusal.file}:${refusal.line}: ${refusal.message}. The module does not run; its plain hook entries still load.`,
|
|
253
|
+
})
|
|
254
|
+
}
|
|
255
|
+
if (scan.refusals.length > 0) return
|
|
256
|
+
const summary = summarizeHookModule(scan)
|
|
257
|
+
for (const line of summary.notUsed) {
|
|
258
|
+
out.add({
|
|
259
|
+
level: 'notUsed',
|
|
260
|
+
code: 'hooks-module-not-used',
|
|
261
|
+
field: 'hooks',
|
|
262
|
+
path: located.entry,
|
|
263
|
+
message: line,
|
|
264
|
+
})
|
|
265
|
+
}
|
|
266
|
+
if (summary.events.length === 0) {
|
|
267
|
+
out.add({
|
|
268
|
+
level: 'notUsed',
|
|
269
|
+
code: 'hooks-module-not-loaded',
|
|
270
|
+
field: 'hooks',
|
|
271
|
+
path: located.entry,
|
|
272
|
+
message: `${located.entry} is not loaded: it registers nothing Namzu runs.`,
|
|
273
|
+
})
|
|
274
|
+
return
|
|
275
|
+
}
|
|
276
|
+
out.add({
|
|
277
|
+
level: 'used',
|
|
278
|
+
code: 'hooks-module-used',
|
|
279
|
+
field: 'hooks',
|
|
280
|
+
path: located.entry,
|
|
281
|
+
message: `${located.entry} runs in an isolated worker (events: ${summary.events.join(', ') || 'none'}).`,
|
|
282
|
+
})
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Read a plugin folder written in the common plugin layout.
|
|
287
|
+
*
|
|
288
|
+
* Pure: it reads inside the folder, never follows a symbolic link, runs and
|
|
289
|
+
* imports nothing (a hooks module is parsed, not run), and opens no connection. It returns the manifest Namzu
|
|
290
|
+
* would admit, the remote servers it found, and a finding for everything it
|
|
291
|
+
* used, left out or refused (see {@link LayoutFinding}).
|
|
292
|
+
*
|
|
293
|
+
* Which file speaks, in order: a `plugin.json` at the root (Namzu's own; this
|
|
294
|
+
* reader says only that it was there), the common layout's manifest, the
|
|
295
|
+
* install sidecar (only when `options.entrySidecar` is set), a root `SKILL.md`
|
|
296
|
+
* (a one-skill plugin), or the conventional folders alone.
|
|
297
|
+
*/
|
|
298
|
+
export async function readCommonLayout(
|
|
299
|
+
root: string,
|
|
300
|
+
options: CommonLayoutOptions = {},
|
|
301
|
+
): Promise<CommonLayoutRead> {
|
|
302
|
+
const out = new Collector()
|
|
303
|
+
const finish = (
|
|
304
|
+
source: CommonLayoutSource,
|
|
305
|
+
manifest?: PluginManifest,
|
|
306
|
+
remote: CommonLayoutRead['remoteServers'] = [],
|
|
307
|
+
): CommonLayoutRead => ({
|
|
308
|
+
source,
|
|
309
|
+
...(manifest !== undefined ? { manifest } : {}),
|
|
310
|
+
remoteServers: remote,
|
|
311
|
+
findings: out.findings,
|
|
312
|
+
...(out.refusal !== undefined ? { refusal: out.refusal } : {}),
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
if ((await kindOf(root)) !== 'dir') {
|
|
316
|
+
out.refuseAll('root-not-directory', 'root', `Plugin root must be a regular directory: ${root}`)
|
|
317
|
+
return finish('none')
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// The reader owns the plugin-level size caps: it stops counting at the cap.
|
|
321
|
+
const size = await measureFolder(root)
|
|
322
|
+
if (size !== undefined) {
|
|
323
|
+
out.refuseAll('too-large', 'root', size)
|
|
324
|
+
return finish('none')
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const commonDir = await kindOf(join(root, COMMON_MANIFEST_DIR))
|
|
328
|
+
const commonFile =
|
|
329
|
+
commonDir === 'dir'
|
|
330
|
+
? await kindOf(join(root, COMMON_MANIFEST_DIR, COMMON_MANIFEST_FILE))
|
|
331
|
+
: commonDir
|
|
332
|
+
if ((await kindOf(join(root, PLUGIN_MANIFEST_FILENAME))) === 'file') {
|
|
333
|
+
if (commonFile === 'file') {
|
|
334
|
+
out.add({
|
|
335
|
+
level: 'ignored',
|
|
336
|
+
code: 'manifest-both',
|
|
337
|
+
field: 'manifest',
|
|
338
|
+
message: `Both ${PLUGIN_MANIFEST_FILENAME} and ${COMMON_MANIFEST_DIR}/${COMMON_MANIFEST_FILE} are here; ${PLUGIN_MANIFEST_FILENAME} is used and the other is ignored.`,
|
|
339
|
+
})
|
|
340
|
+
}
|
|
341
|
+
return finish('namzu')
|
|
342
|
+
}
|
|
343
|
+
if (commonDir === 'link' || commonFile === 'link') {
|
|
344
|
+
out.refuseAll(
|
|
345
|
+
'path-escapes',
|
|
346
|
+
'manifest',
|
|
347
|
+
`${COMMON_MANIFEST_DIR} is a link, so it is not read.`,
|
|
348
|
+
)
|
|
349
|
+
return finish('none')
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// The manifest, then the sidecar, each read whole and refused over the size cap.
|
|
353
|
+
let base: Record<string, unknown> | undefined
|
|
354
|
+
if (commonFile === 'file') {
|
|
355
|
+
const read = await readCapped(join(root, COMMON_MANIFEST_DIR, COMMON_MANIFEST_FILE))
|
|
356
|
+
if ('problem' in read) {
|
|
357
|
+
out.refuseAll('manifest-invalid', 'manifest', `The manifest ${read.problem}.`)
|
|
358
|
+
return finish('none')
|
|
359
|
+
}
|
|
360
|
+
try {
|
|
361
|
+
const parsed: unknown = JSON.parse(read.text)
|
|
362
|
+
if (!isMapping(parsed)) throw new Error('it is not an object')
|
|
363
|
+
base = parsed
|
|
364
|
+
} catch (error) {
|
|
365
|
+
out.refuseAll(
|
|
366
|
+
'manifest-invalid',
|
|
367
|
+
'manifest',
|
|
368
|
+
`The manifest is not valid JSON (${error instanceof Error ? error.message : String(error)}).`,
|
|
369
|
+
)
|
|
370
|
+
return finish('none')
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
let sidecar: Record<string, unknown> | undefined
|
|
375
|
+
if (options.entrySidecar === true) {
|
|
376
|
+
const kind = await kindOf(join(root, ENTRY_SIDECAR_FILE))
|
|
377
|
+
if (kind === 'link') {
|
|
378
|
+
out.add({
|
|
379
|
+
level: 'ignored',
|
|
380
|
+
code: 'symlink',
|
|
381
|
+
field: ENTRY_SIDECAR_FILE,
|
|
382
|
+
message: `${ENTRY_SIDECAR_FILE} is a link and is not read.`,
|
|
383
|
+
path: ENTRY_SIDECAR_FILE,
|
|
384
|
+
})
|
|
385
|
+
} else if (kind === 'file') {
|
|
386
|
+
const read = await readCapped(join(root, ENTRY_SIDECAR_FILE))
|
|
387
|
+
if ('problem' in read) {
|
|
388
|
+
out.refuseAll(
|
|
389
|
+
'manifest-invalid',
|
|
390
|
+
ENTRY_SIDECAR_FILE,
|
|
391
|
+
`${ENTRY_SIDECAR_FILE} ${read.problem}.`,
|
|
392
|
+
)
|
|
393
|
+
return finish('none')
|
|
394
|
+
}
|
|
395
|
+
try {
|
|
396
|
+
const parsed: unknown = JSON.parse(read.text)
|
|
397
|
+
if (!isMapping(parsed)) throw new Error('it is not an object')
|
|
398
|
+
sidecar = parsed
|
|
399
|
+
} catch (error) {
|
|
400
|
+
out.refuseAll(
|
|
401
|
+
'manifest-invalid',
|
|
402
|
+
ENTRY_SIDECAR_FILE,
|
|
403
|
+
`${ENTRY_SIDECAR_FILE} is not valid JSON (${error instanceof Error ? error.message : String(error)}).`,
|
|
404
|
+
)
|
|
405
|
+
return finish('none')
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const rootSkill = await kindOf(join(root, COMMON_ROOT_SKILL_FILE))
|
|
411
|
+
const conventional = await Promise.all(
|
|
412
|
+
[COMMON_SKILLS_DIR, COMMON_COMMANDS_DIR, COMMON_AGENTS_DIR, 'hooks'].map((dir) =>
|
|
413
|
+
kindOf(join(root, dir)),
|
|
414
|
+
),
|
|
415
|
+
)
|
|
416
|
+
const hasConventional =
|
|
417
|
+
conventional.includes('dir') ||
|
|
418
|
+
rootSkill === 'file' ||
|
|
419
|
+
(await kindOf(join(root, COMMON_MCP_FILE))) === 'file'
|
|
420
|
+
|
|
421
|
+
let source: CommonLayoutSource
|
|
422
|
+
if (base !== undefined) source = 'manifest'
|
|
423
|
+
else if (sidecar !== undefined) source = 'sidecar'
|
|
424
|
+
else if (rootSkill === 'file' && !conventional.includes('dir')) source = 'single-skill'
|
|
425
|
+
else if (hasConventional) {
|
|
426
|
+
if (
|
|
427
|
+
(await kindOf(join(root, COMMON_HOOKS_FILE))) !== 'missing' ||
|
|
428
|
+
(await kindOf(join(root, COMMON_MCP_FILE))) !== 'missing'
|
|
429
|
+
) {
|
|
430
|
+
out.refuseAll(
|
|
431
|
+
'manifest-required',
|
|
432
|
+
'manifest',
|
|
433
|
+
`Hooks and servers run code, so a plugin that ships them needs a ${COMMON_MANIFEST_DIR}/${COMMON_MANIFEST_FILE}. Add one, or remove ${COMMON_HOOKS_FILE} and ${COMMON_MCP_FILE}.`,
|
|
434
|
+
)
|
|
435
|
+
return finish('conventional')
|
|
436
|
+
}
|
|
437
|
+
source = 'conventional'
|
|
438
|
+
} else {
|
|
439
|
+
out.refuseAll(
|
|
440
|
+
'not-a-plugin',
|
|
441
|
+
'root',
|
|
442
|
+
`There is nothing here Namzu reads: no ${COMMON_MANIFEST_DIR}/${COMMON_MANIFEST_FILE}, no ${COMMON_SKILLS_DIR}/, ${COMMON_COMMANDS_DIR}/ or ${COMMON_AGENTS_DIR}/.`,
|
|
443
|
+
)
|
|
444
|
+
return finish('none')
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// The merged view: the manifest, with the sidecar's allow-listed fields over it when the
|
|
448
|
+
// entry says `strict: false`, and only its identity fields filling gaps otherwise.
|
|
449
|
+
const merged: Record<string, unknown> = { ...(base ?? {}) }
|
|
450
|
+
if (sidecar !== undefined) {
|
|
451
|
+
const entry: Record<string, unknown> = {}
|
|
452
|
+
for (const key of SIDECAR_FIELDS) if (sidecar[key] !== undefined) entry[key] = sidecar[key]
|
|
453
|
+
const inlineAllowed = entry.strict === false
|
|
454
|
+
for (const [key, value] of Object.entries(entry)) {
|
|
455
|
+
if (key === 'strict') continue
|
|
456
|
+
const component = COMPONENT_FIELDS.includes(key) || key === 'platforms' || key === 'engines'
|
|
457
|
+
if (component && !inlineAllowed) {
|
|
458
|
+
if (COMPONENT_FIELDS.includes(key)) {
|
|
459
|
+
out.add({
|
|
460
|
+
level: 'ignored',
|
|
461
|
+
code: 'entry-inline-ignored',
|
|
462
|
+
field: key,
|
|
463
|
+
message: `The marketplace entry lists "${key}", and the plugin's own manifest decides that (the entry does not say strict: false), so it is ignored.`,
|
|
464
|
+
})
|
|
465
|
+
}
|
|
466
|
+
continue
|
|
467
|
+
}
|
|
468
|
+
if (inlineAllowed || merged[key] === undefined) merged[key] = value
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
return readMerged(root, merged, source, options, out, finish)
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
type Finish = (
|
|
476
|
+
source: CommonLayoutSource,
|
|
477
|
+
manifest?: PluginManifest,
|
|
478
|
+
remote?: CommonLayoutRead['remoteServers'],
|
|
479
|
+
) => CommonLayoutRead
|
|
480
|
+
|
|
481
|
+
async function readMerged(
|
|
482
|
+
root: string,
|
|
483
|
+
m: Record<string, unknown>,
|
|
484
|
+
source: CommonLayoutSource,
|
|
485
|
+
options: CommonLayoutOptions,
|
|
486
|
+
out: Collector,
|
|
487
|
+
finish: Finish,
|
|
488
|
+
): Promise<CommonLayoutRead> {
|
|
489
|
+
// --- identity ---------------------------------------------------------
|
|
490
|
+
const name = typeof m.name === 'string' ? m.name : nameFromFolder(root)
|
|
491
|
+
if (
|
|
492
|
+
name.length === 0 ||
|
|
493
|
+
name.length > PLUGIN_NAME_MAX_LENGTH ||
|
|
494
|
+
!PLUGIN_NAME_PATTERN.test(name)
|
|
495
|
+
) {
|
|
496
|
+
out.refuseAll('name-invalid', 'name', 'name must be lowercase words joined by dashes.')
|
|
497
|
+
return finish(source)
|
|
498
|
+
}
|
|
499
|
+
for (const key of Object.keys(m)) {
|
|
500
|
+
if (!KNOWN_MANIFEST_KEYS.has(key) && !SIDECAR_FIELDS.includes(key)) {
|
|
501
|
+
out.add({
|
|
502
|
+
level: 'ignored',
|
|
503
|
+
code: 'manifest-unknown-key',
|
|
504
|
+
field: key,
|
|
505
|
+
message: `"${key}" is not read.`,
|
|
506
|
+
})
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
for (const key of [
|
|
510
|
+
'displayName',
|
|
511
|
+
'homepage',
|
|
512
|
+
'repository',
|
|
513
|
+
'license',
|
|
514
|
+
'keywords',
|
|
515
|
+
'metadata',
|
|
516
|
+
'$schema',
|
|
517
|
+
'icon',
|
|
518
|
+
'defaultEnabled',
|
|
519
|
+
'connectors',
|
|
520
|
+
'personas',
|
|
521
|
+
'optionalDependencies',
|
|
522
|
+
]) {
|
|
523
|
+
if (m[key] !== undefined) {
|
|
524
|
+
out.add({
|
|
525
|
+
level: 'ignored',
|
|
526
|
+
code: 'manifest-metadata',
|
|
527
|
+
field: key,
|
|
528
|
+
message:
|
|
529
|
+
key === 'defaultEnabled'
|
|
530
|
+
? 'defaultEnabled is ignored: Namzu turns a plugin on only after a recorded yes.'
|
|
531
|
+
: `${key} is kept for display at most and never runs.`,
|
|
532
|
+
})
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
let author: string | undefined
|
|
537
|
+
if (typeof m.author === 'string') author = m.author
|
|
538
|
+
else if (isMapping(m.author) && typeof m.author.name === 'string') {
|
|
539
|
+
author =
|
|
540
|
+
typeof m.author.email === 'string' ? `${m.author.name} <${m.author.email}>` : m.author.name
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// --- dependencies -----------------------------------------------------
|
|
544
|
+
if (m.dependencies !== undefined) {
|
|
545
|
+
const ids = toList(m.dependencies).flatMap((entry) =>
|
|
546
|
+
typeof entry === 'string'
|
|
547
|
+
? [entry]
|
|
548
|
+
: isMapping(entry) && typeof entry.name === 'string'
|
|
549
|
+
? [entry.name]
|
|
550
|
+
: [],
|
|
551
|
+
)
|
|
552
|
+
const installed = options.installedIds ?? new Set<string>()
|
|
553
|
+
const missing = ids.find(
|
|
554
|
+
(id) => !installed.has(id) && ![...installed].some((have) => have.split('@')[0] === id),
|
|
555
|
+
)
|
|
556
|
+
if (missing !== undefined) {
|
|
557
|
+
out.refuseAll(
|
|
558
|
+
'dependency-unmet',
|
|
559
|
+
'dependencies',
|
|
560
|
+
`It needs ${missing}, which is not installed. Add it first (the /plugin screen, or --plugin-dir), then add this plugin.`,
|
|
561
|
+
)
|
|
562
|
+
return finish(source)
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// --- skills -----------------------------------------------------------
|
|
567
|
+
const skillPaths: string[] = []
|
|
568
|
+
const skillSeen = new Set<string>()
|
|
569
|
+
const checkSkill = async (rel: string, field: string): Promise<boolean> => {
|
|
570
|
+
const where = rel === '.' ? COMMON_ROOT_SKILL_FILE : `${rel}/${COMMON_ROOT_SKILL_FILE}`
|
|
571
|
+
const file = await walk(root, where)
|
|
572
|
+
if (file === 'link') {
|
|
573
|
+
out.add({
|
|
574
|
+
level: 'ignored',
|
|
575
|
+
code: 'symlink',
|
|
576
|
+
field,
|
|
577
|
+
path: where,
|
|
578
|
+
message: `${where} is a link and is not followed.`,
|
|
579
|
+
})
|
|
580
|
+
return false
|
|
581
|
+
}
|
|
582
|
+
if (file !== 'file') {
|
|
583
|
+
out.add({
|
|
584
|
+
level: 'ignored',
|
|
585
|
+
code: 'skill-no-file',
|
|
586
|
+
field,
|
|
587
|
+
path: rel,
|
|
588
|
+
message: `${rel} has no ${COMMON_ROOT_SKILL_FILE}, so it is not a skill.`,
|
|
589
|
+
})
|
|
590
|
+
return false
|
|
591
|
+
}
|
|
592
|
+
const read = await readCapped(join(root, where))
|
|
593
|
+
try {
|
|
594
|
+
if ('problem' in read) throw new Error(`${where} ${read.problem}`)
|
|
595
|
+
parseSkillMarkdown(read.text, rel === '.' ? root : join(root, rel), {
|
|
596
|
+
anyFolderName: rel === '.',
|
|
597
|
+
})
|
|
598
|
+
} catch (error) {
|
|
599
|
+
out.add({
|
|
600
|
+
level: 'refused',
|
|
601
|
+
code: 'skill-invalid',
|
|
602
|
+
field,
|
|
603
|
+
path: where,
|
|
604
|
+
message: `${where}: ${(error instanceof Error ? error.message : String(error)).split(root).join('.')}`,
|
|
605
|
+
})
|
|
606
|
+
return false
|
|
607
|
+
}
|
|
608
|
+
return true
|
|
609
|
+
}
|
|
610
|
+
const addSkill = async (rel: string, field: string): Promise<void> => {
|
|
611
|
+
if (skillSeen.has(rel)) return
|
|
612
|
+
skillSeen.add(rel)
|
|
613
|
+
if (await checkSkill(rel, field)) skillPaths.push(rel)
|
|
614
|
+
}
|
|
615
|
+
if (m.skills !== undefined) {
|
|
616
|
+
for (const entry of toList(m.skills)) {
|
|
617
|
+
if (typeof entry !== 'string') {
|
|
618
|
+
out.refuseAll('manifest-invalid', 'skills', 'skills must be a list of folder paths.')
|
|
619
|
+
return finish(source)
|
|
620
|
+
}
|
|
621
|
+
const problem = relativeProblem(entry)
|
|
622
|
+
const rel = trimDot(entry)
|
|
623
|
+
if (problem !== undefined || (await walk(root, rel)) === 'link') {
|
|
624
|
+
out.refuseAll(
|
|
625
|
+
'path-escapes',
|
|
626
|
+
'skills',
|
|
627
|
+
`skills: "${entry}" ${problem ?? 'goes through a link'}, so the plugin is not loaded.`,
|
|
628
|
+
)
|
|
629
|
+
return finish(source)
|
|
630
|
+
}
|
|
631
|
+
await addSkill(rel, 'skills')
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
if (
|
|
635
|
+
source === 'single-skill' ||
|
|
636
|
+
(source === 'conventional' && (await kindOf(join(root, COMMON_ROOT_SKILL_FILE))) === 'file')
|
|
637
|
+
) {
|
|
638
|
+
await addSkill('.', 'skills')
|
|
639
|
+
}
|
|
640
|
+
const skillsDir = await walk(root, COMMON_SKILLS_DIR)
|
|
641
|
+
if (skillsDir === 'link') {
|
|
642
|
+
out.add({
|
|
643
|
+
level: 'ignored',
|
|
644
|
+
code: 'symlink',
|
|
645
|
+
field: 'skills',
|
|
646
|
+
path: COMMON_SKILLS_DIR,
|
|
647
|
+
message: `${COMMON_SKILLS_DIR} is a link and is not followed.`,
|
|
648
|
+
})
|
|
649
|
+
} else if (skillsDir === 'dir') {
|
|
650
|
+
let entries: Dirent[] = []
|
|
651
|
+
try {
|
|
652
|
+
entries = (await readdir(join(root, COMMON_SKILLS_DIR), { withFileTypes: true })).sort(
|
|
653
|
+
(a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0),
|
|
654
|
+
)
|
|
655
|
+
} catch (error) {
|
|
656
|
+
out.add({
|
|
657
|
+
level: 'ignored',
|
|
658
|
+
code: 'skills-unreadable',
|
|
659
|
+
field: 'skills',
|
|
660
|
+
path: COMMON_SKILLS_DIR,
|
|
661
|
+
message: `${COMMON_SKILLS_DIR}/ could not be read (${error instanceof Error ? error.message : String(error)}), so its skills are not loaded.`,
|
|
662
|
+
})
|
|
663
|
+
}
|
|
664
|
+
for (const entry of entries) {
|
|
665
|
+
if (skillPaths.length > COMMON_LAYOUT_MAX_SKILLS) break
|
|
666
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === '__MACOSX')
|
|
667
|
+
continue
|
|
668
|
+
const rel = `${COMMON_SKILLS_DIR}/${entry.name}`
|
|
669
|
+
if (entry.isSymbolicLink()) {
|
|
670
|
+
out.add({
|
|
671
|
+
level: 'ignored',
|
|
672
|
+
code: 'symlink',
|
|
673
|
+
field: 'skills',
|
|
674
|
+
path: rel,
|
|
675
|
+
message: `${rel} is a link and is not followed.`,
|
|
676
|
+
})
|
|
677
|
+
continue
|
|
678
|
+
}
|
|
679
|
+
if (!entry.isDirectory()) continue
|
|
680
|
+
await addSkill(rel, 'skills')
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
if (skillPaths.length > COMMON_LAYOUT_MAX_SKILLS) {
|
|
684
|
+
out.refuseAll(
|
|
685
|
+
'too-many-skills',
|
|
686
|
+
'skills',
|
|
687
|
+
`The plugin has ${skillPaths.length} skills; Namzu reads at most ${COMMON_LAYOUT_MAX_SKILLS} from one plugin.`,
|
|
688
|
+
)
|
|
689
|
+
return finish(source)
|
|
690
|
+
}
|
|
691
|
+
if (skillPaths.length > 0) {
|
|
692
|
+
out.add({
|
|
693
|
+
level: 'used',
|
|
694
|
+
code: 'skills-used',
|
|
695
|
+
field: 'skills',
|
|
696
|
+
message: `${skillPaths.length} skill${skillPaths.length === 1 ? '' : 's'}.`,
|
|
697
|
+
})
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// --- commands and agents ---------------------------------------------
|
|
701
|
+
const filePaths = async (
|
|
702
|
+
field: 'commands' | 'agents',
|
|
703
|
+
dir: string,
|
|
704
|
+
cap: number,
|
|
705
|
+
): Promise<string[] | undefined> => {
|
|
706
|
+
const paths: string[] = []
|
|
707
|
+
const declared = m[field]
|
|
708
|
+
if (declared !== undefined) {
|
|
709
|
+
const entries: unknown[] = isMapping(declared)
|
|
710
|
+
? Object.entries(declared).map(([key, value]) => {
|
|
711
|
+
if (isMapping(value) && typeof value.content === 'string') {
|
|
712
|
+
out.add({
|
|
713
|
+
level: 'refused',
|
|
714
|
+
code: 'inline-text-unsupported',
|
|
715
|
+
field: `${field}.${key}`,
|
|
716
|
+
message: `${field}.${key}: inline text is not supported`,
|
|
717
|
+
})
|
|
718
|
+
return undefined
|
|
719
|
+
}
|
|
720
|
+
return isMapping(value) && typeof value.source === 'string' ? value.source : value
|
|
721
|
+
})
|
|
722
|
+
: toList(declared)
|
|
723
|
+
for (const entry of entries) {
|
|
724
|
+
if (entry === undefined) continue
|
|
725
|
+
if (typeof entry !== 'string') {
|
|
726
|
+
out.refuseAll('manifest-invalid', field, `${field} must be paths.`)
|
|
727
|
+
return undefined
|
|
728
|
+
}
|
|
729
|
+
const problem = relativeProblem(entry)
|
|
730
|
+
const rel = trimDot(entry)
|
|
731
|
+
const kind = problem === undefined ? await walk(root, rel) : 'missing'
|
|
732
|
+
if (problem !== undefined || kind === 'link') {
|
|
733
|
+
out.refuseAll(
|
|
734
|
+
'path-escapes',
|
|
735
|
+
field,
|
|
736
|
+
`${field}: "${entry}" ${problem ?? 'goes through a link'}, so the plugin is not loaded.`,
|
|
737
|
+
)
|
|
738
|
+
return undefined
|
|
739
|
+
}
|
|
740
|
+
if (kind === 'missing') {
|
|
741
|
+
out.add({
|
|
742
|
+
level: 'refused',
|
|
743
|
+
code: 'path-missing',
|
|
744
|
+
field,
|
|
745
|
+
path: rel,
|
|
746
|
+
message: `${field}: "${entry}" was not found.`,
|
|
747
|
+
})
|
|
748
|
+
continue
|
|
749
|
+
}
|
|
750
|
+
if (kind === 'file' && !rel.toLowerCase().endsWith('.md')) {
|
|
751
|
+
out.add({
|
|
752
|
+
level: 'ignored',
|
|
753
|
+
code: 'file-not-markdown',
|
|
754
|
+
field,
|
|
755
|
+
path: rel,
|
|
756
|
+
message: `${field}: "${entry}" is not a .md file.`,
|
|
757
|
+
})
|
|
758
|
+
continue
|
|
759
|
+
}
|
|
760
|
+
paths.push(rel)
|
|
761
|
+
}
|
|
762
|
+
if ((await walk(root, dir)) === 'dir') {
|
|
763
|
+
out.add({
|
|
764
|
+
level: 'notUsed',
|
|
765
|
+
code: 'folder-shadowed-by-manifest',
|
|
766
|
+
field,
|
|
767
|
+
message: `${dir}/ is not read on its own because the manifest lists ${field}. Add its files to the ${field} list if you want both.`,
|
|
768
|
+
})
|
|
769
|
+
}
|
|
770
|
+
} else {
|
|
771
|
+
const kind = await walk(root, dir)
|
|
772
|
+
if (kind === 'link') {
|
|
773
|
+
out.add({
|
|
774
|
+
level: 'ignored',
|
|
775
|
+
code: 'symlink',
|
|
776
|
+
field,
|
|
777
|
+
path: dir,
|
|
778
|
+
message: `${dir} is a link and is not followed.`,
|
|
779
|
+
})
|
|
780
|
+
} else if (kind === 'dir') paths.push(dir)
|
|
781
|
+
}
|
|
782
|
+
if (paths.length > cap) {
|
|
783
|
+
out.refuseAll(
|
|
784
|
+
`too-many-${field}`,
|
|
785
|
+
field,
|
|
786
|
+
`The plugin lists ${paths.length} ${field}; Namzu reads at most ${cap}.`,
|
|
787
|
+
)
|
|
788
|
+
return undefined
|
|
789
|
+
}
|
|
790
|
+
return paths
|
|
791
|
+
}
|
|
792
|
+
const commands = await filePaths('commands', COMMON_COMMANDS_DIR, COMMON_LAYOUT_MAX_COMMANDS)
|
|
793
|
+
if (out.refusal) return finish(source)
|
|
794
|
+
const agents = await filePaths('agents', COMMON_AGENTS_DIR, COMMON_LAYOUT_MAX_AGENTS)
|
|
795
|
+
if (out.refusal) return finish(source)
|
|
796
|
+
for (const rel of agents ?? []) await noteAgentKeys(root, rel, out)
|
|
797
|
+
if ((commands?.length ?? 0) > 0) {
|
|
798
|
+
out.add({
|
|
799
|
+
level: 'used',
|
|
800
|
+
code: 'commands-used',
|
|
801
|
+
field: 'commands',
|
|
802
|
+
message: `${commands?.length} command source(s).`,
|
|
803
|
+
})
|
|
804
|
+
}
|
|
805
|
+
if ((agents?.length ?? 0) > 0) {
|
|
806
|
+
out.add({
|
|
807
|
+
level: 'used',
|
|
808
|
+
code: 'agents-used',
|
|
809
|
+
field: 'agents',
|
|
810
|
+
message: `${agents?.length} agent source(s).`,
|
|
811
|
+
})
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// --- hooks ------------------------------------------------------------
|
|
815
|
+
const hookFiles: string[] = []
|
|
816
|
+
const hookEntries: Record<string, unknown[]> = {}
|
|
817
|
+
let inlineHooks = false
|
|
818
|
+
for (const entry of toList(m.hooks)) {
|
|
819
|
+
if (typeof entry === 'string') {
|
|
820
|
+
const problem = relativeProblem(entry)
|
|
821
|
+
const rel = trimDot(entry)
|
|
822
|
+
if (problem !== undefined || (await walk(root, rel)) === 'link') {
|
|
823
|
+
out.refuseAll(
|
|
824
|
+
'path-escapes',
|
|
825
|
+
'hooks',
|
|
826
|
+
`hooks: "${entry}" ${problem ?? 'goes through a link'}, so the plugin is not loaded.`,
|
|
827
|
+
)
|
|
828
|
+
return finish(source)
|
|
829
|
+
}
|
|
830
|
+
if (!rel.toLowerCase().endsWith('.json')) {
|
|
831
|
+
out.add({
|
|
832
|
+
level: 'refused',
|
|
833
|
+
code: 'hooks-module-refused',
|
|
834
|
+
field: 'hooks',
|
|
835
|
+
path: rel,
|
|
836
|
+
message: `hooks: "${entry}" is program code, not a file of hook entries. Namzu does not run plugin code at startup, so it is skipped.`,
|
|
837
|
+
})
|
|
838
|
+
continue
|
|
839
|
+
}
|
|
840
|
+
hookFiles.push(rel)
|
|
841
|
+
} else if (isMapping(entry)) {
|
|
842
|
+
const events = isMapping(entry.hooks) ? entry.hooks : entry
|
|
843
|
+
for (const [event, list] of Object.entries(events)) {
|
|
844
|
+
inlineHooks = true
|
|
845
|
+
hookEntries[event] = [...(hookEntries[event] ?? []), ...toList(list)]
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
const conventionalHooks = await walk(root, COMMON_HOOKS_FILE)
|
|
850
|
+
if (conventionalHooks === 'file' && !hookFiles.includes(COMMON_HOOKS_FILE)) {
|
|
851
|
+
hookFiles.push(COMMON_HOOKS_FILE)
|
|
852
|
+
} else if (conventionalHooks === 'link') {
|
|
853
|
+
out.add({
|
|
854
|
+
level: 'ignored',
|
|
855
|
+
code: 'symlink',
|
|
856
|
+
field: 'hooks',
|
|
857
|
+
path: COMMON_HOOKS_FILE,
|
|
858
|
+
message: `${COMMON_HOOKS_FILE} is a link and is not followed.`,
|
|
859
|
+
})
|
|
860
|
+
}
|
|
861
|
+
let hookCount = 0
|
|
862
|
+
const knownEvents = new Set<string>([
|
|
863
|
+
...(SHELL_HOOK_EVENTS as readonly string[]),
|
|
864
|
+
...(Object.values(SHELL_HOOK_PASCAL_EVENT_NAMES) as string[]),
|
|
865
|
+
...Object.keys(RENAMED_PLUGIN_HOOK_EVENTS),
|
|
866
|
+
])
|
|
867
|
+
const noteEvents = (events: Record<string, unknown>, field: string, path?: string): void => {
|
|
868
|
+
for (const [event, list] of Object.entries(events)) {
|
|
869
|
+
if (!knownEvents.has(event)) {
|
|
870
|
+
out.add({
|
|
871
|
+
level: 'ignored',
|
|
872
|
+
code: 'hook-event-unknown',
|
|
873
|
+
field,
|
|
874
|
+
...(path !== undefined ? { path } : {}),
|
|
875
|
+
message: `The hook event "${event}" is not one Namzu has, so its hooks do not run.`,
|
|
876
|
+
})
|
|
877
|
+
} else hookCount += toList(list).length
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
for (const rel of hookFiles) {
|
|
881
|
+
const kind = await walk(root, rel)
|
|
882
|
+
if (kind !== 'file') {
|
|
883
|
+
out.add({
|
|
884
|
+
level: 'refused',
|
|
885
|
+
code: 'hooks-file-missing',
|
|
886
|
+
field: 'hooks',
|
|
887
|
+
path: rel,
|
|
888
|
+
message: `${rel} is listed as a hooks file and is not there.`,
|
|
889
|
+
})
|
|
890
|
+
continue
|
|
891
|
+
}
|
|
892
|
+
const read = await readCapped(join(root, rel))
|
|
893
|
+
if ('problem' in read) {
|
|
894
|
+
out.add({
|
|
895
|
+
level: 'refused',
|
|
896
|
+
code: 'hooks-file-invalid',
|
|
897
|
+
field: 'hooks',
|
|
898
|
+
path: rel,
|
|
899
|
+
message: `${rel} ${read.problem}.`,
|
|
900
|
+
})
|
|
901
|
+
continue
|
|
902
|
+
}
|
|
903
|
+
let parsed: unknown
|
|
904
|
+
try {
|
|
905
|
+
parsed = JSON.parse(read.text)
|
|
906
|
+
} catch {
|
|
907
|
+
out.add({
|
|
908
|
+
level: 'refused',
|
|
909
|
+
code: 'hooks-file-invalid',
|
|
910
|
+
field: 'hooks',
|
|
911
|
+
path: rel,
|
|
912
|
+
message: `${rel} is not valid JSON.`,
|
|
913
|
+
})
|
|
914
|
+
continue
|
|
915
|
+
}
|
|
916
|
+
if (isMapping(parsed) && parsed.modules !== undefined) {
|
|
917
|
+
if (rel === COMMON_HOOKS_FILE) {
|
|
918
|
+
noteHookModule(root, out)
|
|
919
|
+
} else {
|
|
920
|
+
out.add({
|
|
921
|
+
level: 'refused',
|
|
922
|
+
code: 'hooks-modules-refused',
|
|
923
|
+
field: 'hooks',
|
|
924
|
+
path: rel,
|
|
925
|
+
message: `${rel}: "modules" is read only in ${COMMON_HOOKS_FILE}, so this module does not run; its plain hook entries still load.`,
|
|
926
|
+
})
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
const events = isMapping(parsed)
|
|
930
|
+
? isMapping(parsed.hooks)
|
|
931
|
+
? parsed.hooks
|
|
932
|
+
: parsed.modules !== undefined
|
|
933
|
+
? {}
|
|
934
|
+
: parsed
|
|
935
|
+
: {}
|
|
936
|
+
noteEvents(events, 'hooks', rel)
|
|
937
|
+
}
|
|
938
|
+
if (inlineHooks) noteEvents(hookEntries, 'hooks')
|
|
939
|
+
if (hookCount > 0) {
|
|
940
|
+
out.add({
|
|
941
|
+
level: 'used',
|
|
942
|
+
code: 'hooks-used',
|
|
943
|
+
field: 'hooks',
|
|
944
|
+
message: `${hookCount} hook entr${hookCount === 1 ? 'y' : 'ies'}.`,
|
|
945
|
+
})
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// --- servers ----------------------------------------------------------
|
|
949
|
+
const sources: McpSource[] = []
|
|
950
|
+
const mcpFile = async (rel: string, listed: boolean): Promise<void> => {
|
|
951
|
+
if (/\.(mcpb|dxt)$/i.test(rel)) {
|
|
952
|
+
out.add({
|
|
953
|
+
level: 'ignored',
|
|
954
|
+
code: 'mcp-bundle',
|
|
955
|
+
field: 'mcpServers',
|
|
956
|
+
path: rel,
|
|
957
|
+
message: `${rel} is a packaged server bundle, which Namzu does not read.`,
|
|
958
|
+
})
|
|
959
|
+
return
|
|
960
|
+
}
|
|
961
|
+
const kind = await walk(root, rel)
|
|
962
|
+
if (kind === 'link') {
|
|
963
|
+
out.add({
|
|
964
|
+
level: 'ignored',
|
|
965
|
+
code: 'symlink',
|
|
966
|
+
field: 'mcpServers',
|
|
967
|
+
path: rel,
|
|
968
|
+
message: `${rel} is a link and is not followed.`,
|
|
969
|
+
})
|
|
970
|
+
return
|
|
971
|
+
}
|
|
972
|
+
if (kind !== 'file') {
|
|
973
|
+
if (listed)
|
|
974
|
+
out.add({
|
|
975
|
+
level: 'refused',
|
|
976
|
+
code: 'mcp-file-missing',
|
|
977
|
+
field: 'mcpServers',
|
|
978
|
+
path: rel,
|
|
979
|
+
message: `${rel} is listed and is not there.`,
|
|
980
|
+
})
|
|
981
|
+
return
|
|
982
|
+
}
|
|
983
|
+
const read = await readCapped(join(root, rel))
|
|
984
|
+
if ('problem' in read) {
|
|
985
|
+
out.add({
|
|
986
|
+
level: 'refused',
|
|
987
|
+
code: 'mcp-file-invalid',
|
|
988
|
+
field: 'mcpServers',
|
|
989
|
+
path: rel,
|
|
990
|
+
message: `${rel} ${read.problem}.`,
|
|
991
|
+
})
|
|
992
|
+
return
|
|
993
|
+
}
|
|
994
|
+
let parsed: unknown
|
|
995
|
+
try {
|
|
996
|
+
parsed = JSON.parse(read.text)
|
|
997
|
+
} catch {
|
|
998
|
+
out.add({
|
|
999
|
+
level: 'refused',
|
|
1000
|
+
code: 'mcp-file-invalid',
|
|
1001
|
+
field: 'mcpServers',
|
|
1002
|
+
path: rel,
|
|
1003
|
+
message: `${rel} is not valid JSON.`,
|
|
1004
|
+
})
|
|
1005
|
+
return
|
|
1006
|
+
}
|
|
1007
|
+
const map = serversOf(parsed)
|
|
1008
|
+
if (map === undefined) {
|
|
1009
|
+
out.add({
|
|
1010
|
+
level: 'refused',
|
|
1011
|
+
code: 'mcp-file-invalid',
|
|
1012
|
+
field: 'mcpServers',
|
|
1013
|
+
path: rel,
|
|
1014
|
+
message: `${rel} must be an object of servers.`,
|
|
1015
|
+
})
|
|
1016
|
+
return
|
|
1017
|
+
}
|
|
1018
|
+
sources.push({ origin: rel, map })
|
|
1019
|
+
}
|
|
1020
|
+
for (const entry of toList(m.mcpServers)) {
|
|
1021
|
+
if (typeof entry === 'string') {
|
|
1022
|
+
const problem = relativeProblem(entry)
|
|
1023
|
+
if (problem !== undefined) {
|
|
1024
|
+
out.refuseAll(
|
|
1025
|
+
'path-escapes',
|
|
1026
|
+
'mcpServers',
|
|
1027
|
+
`mcpServers: "${entry}" ${problem}, so the plugin is not loaded.`,
|
|
1028
|
+
)
|
|
1029
|
+
return finish(source)
|
|
1030
|
+
}
|
|
1031
|
+
await mcpFile(trimDot(entry), true)
|
|
1032
|
+
} else {
|
|
1033
|
+
const map = serversOf(entry)
|
|
1034
|
+
if (map !== undefined) sources.push({ origin: 'the manifest', map })
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
await mcpFile(COMMON_MCP_FILE, false)
|
|
1038
|
+
const dataAndProject = options.paths?.(name) ?? {}
|
|
1039
|
+
const servers = readMcpSources(
|
|
1040
|
+
sources,
|
|
1041
|
+
{ root, ...dataAndProject },
|
|
1042
|
+
options.environment ?? (process.env as Record<string, string | undefined>),
|
|
1043
|
+
)
|
|
1044
|
+
for (const finding of servers.findings) out.add(finding)
|
|
1045
|
+
if (servers.local.length + servers.remote.length > COMMON_LAYOUT_MAX_MCP_SERVERS) {
|
|
1046
|
+
out.refuseAll(
|
|
1047
|
+
'too-many-servers',
|
|
1048
|
+
'mcpServers',
|
|
1049
|
+
`The plugin lists ${servers.local.length + servers.remote.length} servers; Namzu reads at most ${COMMON_LAYOUT_MAX_MCP_SERVERS} from one plugin.`,
|
|
1050
|
+
)
|
|
1051
|
+
return finish(source)
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
// --- what Namzu has no place for ---------------------------------------
|
|
1055
|
+
for (const field of NOT_USED_FIELDS) {
|
|
1056
|
+
if (m[field] === undefined) continue
|
|
1057
|
+
const count = countOf(m[field])
|
|
1058
|
+
if (count === 0) continue
|
|
1059
|
+
const loud =
|
|
1060
|
+
field === 'settings'
|
|
1061
|
+
? ' This plugin asks to change your settings. Namzu does not apply that.'
|
|
1062
|
+
: field === 'binaries'
|
|
1063
|
+
? ' This plugin asks for programs to be put on this computer. Namzu does not do that.'
|
|
1064
|
+
: field === 'network'
|
|
1065
|
+
? ` It says it reaches: ${JSON.stringify(m[field]).slice(0, 200)}.`
|
|
1066
|
+
: ''
|
|
1067
|
+
out.add({
|
|
1068
|
+
level: 'notUsed',
|
|
1069
|
+
code: 'component-unsupported',
|
|
1070
|
+
field,
|
|
1071
|
+
message: `${field} (${count}) is not used by Namzu.${loud}`,
|
|
1072
|
+
})
|
|
1073
|
+
}
|
|
1074
|
+
for (const dir of COMMON_UNUSED_DIRS) {
|
|
1075
|
+
if ((await kindOf(join(root, dir))) === 'dir') {
|
|
1076
|
+
const count = (await readdir(join(root, dir)).catch(() => [])).length
|
|
1077
|
+
if (count === 0) continue
|
|
1078
|
+
out.add({
|
|
1079
|
+
level: 'notUsed',
|
|
1080
|
+
code: 'component-unsupported',
|
|
1081
|
+
field: dir,
|
|
1082
|
+
path: dir,
|
|
1083
|
+
message: `${dir}/ (${count}) is not used by Namzu.${dir === 'bin' ? ' Programs in bin/ are not put on your path.' : ''}`,
|
|
1084
|
+
})
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
if (m.userConfig !== undefined) {
|
|
1088
|
+
out.add({
|
|
1089
|
+
level: 'notUsed',
|
|
1090
|
+
code: 'user-config-unsupported',
|
|
1091
|
+
field: 'userConfig',
|
|
1092
|
+
message:
|
|
1093
|
+
'userConfig (saved options) is not supported yet; a server that needs one is not started.',
|
|
1094
|
+
})
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
// --- nothing usable ---------------------------------------------------
|
|
1098
|
+
const usable =
|
|
1099
|
+
skillPaths.length > 0 ||
|
|
1100
|
+
(commands?.length ?? 0) > 0 ||
|
|
1101
|
+
(agents?.length ?? 0) > 0 ||
|
|
1102
|
+
hookCount > 0 ||
|
|
1103
|
+
hookFiles.length > 0 ||
|
|
1104
|
+
inlineHooks ||
|
|
1105
|
+
servers.local.length > 0 ||
|
|
1106
|
+
servers.remote.length > 0 ||
|
|
1107
|
+
// A remote server that needs setup is listed with its reason, so a plugin with nothing else still loads.
|
|
1108
|
+
out.findings.some((f) => f.code === 'mcp-needs-setup' && f.server?.kind === 'remote')
|
|
1109
|
+
if (!usable) {
|
|
1110
|
+
const only = [
|
|
1111
|
+
...NOT_USED_FIELDS.filter((field) => m[field] !== undefined),
|
|
1112
|
+
...COMMON_UNUSED_DIRS.filter((dir) => out.findings.some((f) => f.path === dir)),
|
|
1113
|
+
]
|
|
1114
|
+
out.refuseAll(
|
|
1115
|
+
'nothing-used',
|
|
1116
|
+
'manifest',
|
|
1117
|
+
`Nothing in ${name} is used by Namzu${only.length > 0 ? ` (it only has: ${only.join(', ')})` : ''}.`,
|
|
1118
|
+
)
|
|
1119
|
+
return finish(source)
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
// --- version and description -------------------------------------------
|
|
1123
|
+
const surfaceDigest = createHash('sha256')
|
|
1124
|
+
.update(
|
|
1125
|
+
JSON.stringify({
|
|
1126
|
+
skillPaths,
|
|
1127
|
+
commands,
|
|
1128
|
+
agents,
|
|
1129
|
+
hookFiles,
|
|
1130
|
+
servers: [...servers.local, ...servers.remote],
|
|
1131
|
+
}),
|
|
1132
|
+
)
|
|
1133
|
+
.digest('hex')
|
|
1134
|
+
.slice(0, 8)
|
|
1135
|
+
const version =
|
|
1136
|
+
typeof m.version === 'string' && m.version.length > 0
|
|
1137
|
+
? m.version
|
|
1138
|
+
: (options.version ?? `0.0.0+${surfaceDigest}`)
|
|
1139
|
+
let description =
|
|
1140
|
+
typeof m.description === 'string' && m.description.length > 0 ? m.description : undefined
|
|
1141
|
+
if (description === undefined) {
|
|
1142
|
+
const readme =
|
|
1143
|
+
(await kindOf(join(root, 'README.md'))) === 'file'
|
|
1144
|
+
? await readCapped(join(root, 'README.md'))
|
|
1145
|
+
: undefined
|
|
1146
|
+
const line =
|
|
1147
|
+
readme && 'text' in readme
|
|
1148
|
+
? readme.text.split(/\r?\n/).find((l) => l.trim().length > 0 && !l.trim().startsWith('#'))
|
|
1149
|
+
: undefined
|
|
1150
|
+
description = line?.trim().slice(0, 300) ?? options.description ?? '(no description)'
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
// --- the manifest Namzu admits ------------------------------------------
|
|
1154
|
+
const platforms = Array.isArray(m.platforms)
|
|
1155
|
+
? m.platforms.filter((p) => typeof p === 'string')
|
|
1156
|
+
: undefined
|
|
1157
|
+
const engineNamzu =
|
|
1158
|
+
isMapping(m.engines) && typeof m.engines.namzu === 'string' ? m.engines.namzu : undefined
|
|
1159
|
+
const candidate = {
|
|
1160
|
+
name,
|
|
1161
|
+
version,
|
|
1162
|
+
description,
|
|
1163
|
+
...(author !== undefined ? { author } : {}),
|
|
1164
|
+
...(skillPaths.length > 0 ? { skills: skillPaths } : {}),
|
|
1165
|
+
...(hookFiles.length > 0 ? { hooks: hookFiles } : {}),
|
|
1166
|
+
...(inlineHooks ? { hookEntries } : {}),
|
|
1167
|
+
...(servers.local.length > 0 ? { mcpServers: servers.local } : {}),
|
|
1168
|
+
...(servers.remote.length > 0 ? { remoteMcpServers: servers.remote } : {}),
|
|
1169
|
+
...((commands?.length ?? 0) > 0 ? { commands } : {}),
|
|
1170
|
+
...((agents?.length ?? 0) > 0 ? { agents } : {}),
|
|
1171
|
+
...(platforms && platforms.length > 0 ? { platforms } : {}),
|
|
1172
|
+
...(engineNamzu !== undefined ? { engines: { namzu: engineNamzu } } : {}),
|
|
1173
|
+
}
|
|
1174
|
+
const parsed = CommonLayoutManifestSchema.safeParse(candidate)
|
|
1175
|
+
if (!parsed.success) {
|
|
1176
|
+
out.refuseAll(
|
|
1177
|
+
'manifest-invalid',
|
|
1178
|
+
'manifest',
|
|
1179
|
+
parsed.error.issues
|
|
1180
|
+
.map((issue) => `${issue.path.join('.') || 'manifest'}: ${issue.message}`)
|
|
1181
|
+
.join('; '),
|
|
1182
|
+
)
|
|
1183
|
+
return finish(source)
|
|
1184
|
+
}
|
|
1185
|
+
const manifest: PluginManifest = Object.freeze({
|
|
1186
|
+
...parsed.data,
|
|
1187
|
+
layout: 'common' as const,
|
|
1188
|
+
})
|
|
1189
|
+
return finish(source, manifest, servers.remote)
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
async function noteAgentKeys(root: string, rel: string, out: Collector): Promise<void> {
|
|
1193
|
+
const files: string[] = []
|
|
1194
|
+
if ((await walk(root, rel)) === 'file') files.push(rel)
|
|
1195
|
+
else {
|
|
1196
|
+
const entries = await readdir(join(root, rel), {
|
|
1197
|
+
withFileTypes: true,
|
|
1198
|
+
}).catch(() => [])
|
|
1199
|
+
for (const entry of entries) {
|
|
1200
|
+
if (entry.isFile() && entry.name.endsWith('.md')) files.push(`${rel}/${entry.name}`)
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
for (const file of files.sort()) {
|
|
1204
|
+
const read = await readCapped(join(root, file))
|
|
1205
|
+
if ('problem' in read) continue
|
|
1206
|
+
const extra = topKeys(read.text).filter((key) => !AGENT_FILE_KEYS.includes(key))
|
|
1207
|
+
if (extra.length > 0) {
|
|
1208
|
+
out.add({
|
|
1209
|
+
level: 'ignored',
|
|
1210
|
+
code: 'agent-key-ignored',
|
|
1211
|
+
field: 'agents',
|
|
1212
|
+
path: file,
|
|
1213
|
+
message: `${file}: ${extra.map((key) => `"${key}"`).join(', ')} ${extra.length === 1 ? 'is' : 'are'} not read.`,
|
|
1214
|
+
})
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* Count a folder's files and bytes without following links, stopping as soon as
|
|
1221
|
+
* either cap is passed. The reason it is too large, or undefined.
|
|
1222
|
+
*/
|
|
1223
|
+
async function measureFolder(root: string): Promise<string | undefined> {
|
|
1224
|
+
let files = 0
|
|
1225
|
+
let bytes = 0
|
|
1226
|
+
const pending = [root]
|
|
1227
|
+
while (pending.length > 0) {
|
|
1228
|
+
const dir = pending.pop() as string
|
|
1229
|
+
const entries = await readdir(dir, { withFileTypes: true }).catch(() => [])
|
|
1230
|
+
for (const entry of entries) {
|
|
1231
|
+
if (entry.isSymbolicLink()) continue
|
|
1232
|
+
const full = join(dir, entry.name)
|
|
1233
|
+
if (entry.isDirectory()) {
|
|
1234
|
+
if (entry.name === '.git' || entry.name === 'node_modules') continue
|
|
1235
|
+
pending.push(full)
|
|
1236
|
+
continue
|
|
1237
|
+
}
|
|
1238
|
+
files += 1
|
|
1239
|
+
bytes += (await lstat(full).catch(() => undefined))?.size ?? 0
|
|
1240
|
+
if (files > COMMON_LAYOUT_MAX_FILES) {
|
|
1241
|
+
return `The plugin has more than ${COMMON_LAYOUT_MAX_FILES} files; Namzu reads at most that many from one plugin.`
|
|
1242
|
+
}
|
|
1243
|
+
if (bytes > COMMON_LAYOUT_MAX_BYTES) {
|
|
1244
|
+
return `The plugin is larger than ${COMMON_LAYOUT_MAX_BYTES / (1024 * 1024)} MiB; Namzu reads at most that much from one plugin.`
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
return undefined
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
/**
|
|
1252
|
+
* The folder to read when a download or archive was unpacked: a single
|
|
1253
|
+
* wrapping folder is descended into when it holds the manifest folder or a
|
|
1254
|
+
* recognised component, ignoring `__MACOSX` and `.DS_Store`. The folder itself
|
|
1255
|
+
* when it already holds one, or when there is no such wrapper.
|
|
1256
|
+
*/
|
|
1257
|
+
export async function findCommonLayoutRoot(dir: string): Promise<string> {
|
|
1258
|
+
const recognised = async (path: string): Promise<boolean> => {
|
|
1259
|
+
for (const name of [
|
|
1260
|
+
COMMON_MANIFEST_DIR,
|
|
1261
|
+
COMMON_SKILLS_DIR,
|
|
1262
|
+
COMMON_COMMANDS_DIR,
|
|
1263
|
+
COMMON_AGENTS_DIR,
|
|
1264
|
+
'hooks',
|
|
1265
|
+
COMMON_MCP_FILE,
|
|
1266
|
+
COMMON_ROOT_SKILL_FILE,
|
|
1267
|
+
PLUGIN_MANIFEST_FILENAME,
|
|
1268
|
+
]) {
|
|
1269
|
+
if ((await kindOf(join(path, name))) !== 'missing') return true
|
|
1270
|
+
}
|
|
1271
|
+
return false
|
|
1272
|
+
}
|
|
1273
|
+
if (await recognised(dir)) return dir
|
|
1274
|
+
const entries = (await readdir(dir, { withFileTypes: true }).catch(() => [])).filter(
|
|
1275
|
+
(entry) => entry.name !== '__MACOSX' && entry.name !== '.DS_Store',
|
|
1276
|
+
)
|
|
1277
|
+
if (entries.length === 1 && entries[0]?.isDirectory()) {
|
|
1278
|
+
const inner = join(dir, entries[0].name)
|
|
1279
|
+
if (await recognised(inner)) return inner
|
|
1280
|
+
}
|
|
1281
|
+
return dir
|
|
1282
|
+
}
|