prehello 0.0.0-stage → 0.1.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 (51) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/LICENSE +21 -0
  3. package/README.md +515 -2
  4. package/THIRD_PARTY_NOTICES.md +33 -0
  5. package/assets/fonts/Inter-ExtraBold.subset.ttf +0 -0
  6. package/assets/fonts/Inter-Regular.subset.ttf +0 -0
  7. package/assets/fonts/Inter-SemiBold.subset.ttf +0 -0
  8. package/assets/fonts/OFL.txt +94 -0
  9. package/dist/adapters/claude-code.js +480 -0
  10. package/dist/adapters/codex.js +184 -0
  11. package/dist/adapters/common.js +157 -0
  12. package/dist/adapters/cursor.js +257 -0
  13. package/dist/adapters/skills.js +155 -0
  14. package/dist/adapters/types.js +2 -0
  15. package/dist/analyze/findings.js +82 -0
  16. package/dist/analyze/grade.js +55 -0
  17. package/dist/analyze/savings.js +111 -0
  18. package/dist/analyze/summary.js +57 -0
  19. package/dist/analyze/totals.js +21 -0
  20. package/dist/cli.js +454 -0
  21. package/dist/context.js +331 -0
  22. package/dist/fixtures.js +52 -0
  23. package/dist/fs-safe.js +222 -0
  24. package/dist/mcp/catalog.js +44 -0
  25. package/dist/mcp/configs.js +42 -0
  26. package/dist/model.js +11 -0
  27. package/dist/platform.js +115 -0
  28. package/dist/redact.js +39 -0
  29. package/dist/render/card.js +305 -0
  30. package/dist/render/fix.js +22 -0
  31. package/dist/render/json.js +97 -0
  32. package/dist/render/markdown.js +182 -0
  33. package/dist/render/png.js +162 -0
  34. package/dist/render/sarif.js +472 -0
  35. package/dist/render/terminal.js +329 -0
  36. package/dist/render/treemap.js +58 -0
  37. package/dist/safe-write.js +120 -0
  38. package/dist/scan.js +104 -0
  39. package/dist/spec.js +27 -0
  40. package/dist/text/comments.js +60 -0
  41. package/dist/text/frontmatter.js +90 -0
  42. package/dist/text/imports.js +81 -0
  43. package/dist/tokens/counter.js +41 -0
  44. package/dist/tokens/families.js +47 -0
  45. package/dist/util/fmt.js +102 -0
  46. package/dist/util/secrets.js +35 -0
  47. package/package.json +66 -4
  48. package/spec/claude-code.json +22 -0
  49. package/spec/codex.json +14 -0
  50. package/spec/cursor.json +15 -0
  51. package/spec/mcp-weights.json +62 -0
@@ -0,0 +1,94 @@
1
+ The fonts in this folder are subsets (Basic Latin, Latin-1, and a few punctuation marks) of static instances
2
+ (weights 400, 600, 800) of Inter. They are used only to draw the PNG share card.
3
+
4
+ Copyright 2016 The Inter Project Authors (https://github.com/rsms/inter)
5
+
6
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
7
+ This license is copied below, and is also available with a FAQ at: https://openfontlicense.org
8
+
9
+ -----------------------------------------------------------
10
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
11
+ -----------------------------------------------------------
12
+
13
+ PREAMBLE
14
+ The goals of the Open Font License (OFL) are to stimulate worldwide
15
+ development of collaborative font projects, to support the font creation
16
+ efforts of academic and linguistic communities, and to provide a free and
17
+ open framework in which fonts may be shared and improved in partnership
18
+ with others.
19
+
20
+ The OFL allows the licensed fonts to be used, studied, modified and
21
+ redistributed freely as long as they are not sold by themselves. The
22
+ fonts, including any derivative works, can be bundled, embedded,
23
+ redistributed and/or sold with any software provided that any reserved
24
+ names are not used by derivative works. The fonts and derivatives,
25
+ however, cannot be released under any other type of license. The
26
+ requirement for fonts to remain under this license does not apply
27
+ to any document created using the fonts or their derivatives.
28
+
29
+ DEFINITIONS
30
+ "Font Software" refers to the set of files released by the Copyright
31
+ Holder(s) under this license and clearly marked as such. This may
32
+ include source files, build scripts and documentation.
33
+
34
+ "Reserved Font Name" refers to any names specified as such after the
35
+ copyright statement(s).
36
+
37
+ "Original Version" refers to the collection of Font Software components as
38
+ distributed by the Copyright Holder(s).
39
+
40
+ "Modified Version" refers to any derivative made by adding to, deleting,
41
+ or substituting -- in part or in whole -- any of the components of the
42
+ Original Version, by changing formats or by porting the Font Software to a
43
+ new environment.
44
+
45
+ "Author" refers to any designer, engineer, programmer, technical
46
+ writer or other person who contributed to the Font Software.
47
+
48
+ PERMISSION & CONDITIONS
49
+ Permission is hereby granted, free of charge, to any person obtaining
50
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
51
+ redistribute, and sell modified and unmodified copies of the Font
52
+ Software, subject to the following conditions:
53
+
54
+ 1) Neither the Font Software nor any of its individual components,
55
+ in Original or Modified Versions, may be sold by itself.
56
+
57
+ 2) Original or Modified Versions of the Font Software may be bundled,
58
+ redistributed and/or sold with any software, provided that each copy
59
+ contains the above copyright notice and this license. These can be
60
+ included either as stand-alone text files, human-readable headers or
61
+ in the appropriate machine-readable metadata fields within text or
62
+ binary files as long as those fields can be easily viewed by the user.
63
+
64
+ 3) No Modified Version of the Font Software may use the Reserved Font
65
+ Name(s) unless explicit written permission is granted by the corresponding
66
+ Copyright Holder. This restriction only applies to the primary font name as
67
+ presented to the users.
68
+
69
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
70
+ Software shall not be used to promote, endorse or advertise any
71
+ Modified Version, except to acknowledge the contribution(s) of the
72
+ Copyright Holder(s) and the Author(s) or with their explicit written
73
+ permission.
74
+
75
+ 5) The Font Software, modified or unmodified, in part or in whole,
76
+ must be distributed entirely under this license, and must not be
77
+ distributed under any other license. The requirement for fonts to
78
+ remain under this license does not apply to any document created
79
+ using the Font Software.
80
+
81
+ TERMINATION
82
+ This license becomes null and void if any of the above conditions are
83
+ not met.
84
+
85
+ DISCLAIMER
86
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
87
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
88
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
89
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
90
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
91
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
92
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
93
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
94
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,480 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.detectClaude = detectClaude;
7
+ exports.discoverClaude = discoverClaude;
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const platform_1 = require("../platform");
10
+ const spec_1 = require("../spec");
11
+ const fs_safe_1 = require("../fs-safe");
12
+ const frontmatter_1 = require("../text/frontmatter");
13
+ const common_1 = require("./common");
14
+ const skills_1 = require("./skills");
15
+ const configs_1 = require("../mcp/configs");
16
+ const fmt_1 = require("../util/fmt");
17
+ const AGENT = "claude-code";
18
+ const ev = (doc) => (0, spec_1.evidenceFor)(AGENT, doc);
19
+ function configDir(ctx) {
20
+ return ctx.opts.env.CLAUDE_CONFIG_DIR || node_path_1.default.join(ctx.home, ".claude");
21
+ }
22
+ function userJsonPath(ctx) {
23
+ return ctx.opts.env.CLAUDE_CONFIG_DIR ? node_path_1.default.join(ctx.opts.env.CLAUDE_CONFIG_DIR, ".claude.json") : node_path_1.default.join(ctx.home, ".claude.json");
24
+ }
25
+ function managedDir(ctx) {
26
+ if (ctx.opts.managedDir)
27
+ return ctx.opts.managedDir;
28
+ if (ctx.opts.platform === "darwin")
29
+ return ctx.sys("/Library/Application Support/ClaudeCode");
30
+ if (ctx.opts.platform === "win32")
31
+ return ctx.sys(node_path_1.default.win32.join(ctx.opts.env.ProgramFiles && (0, platform_1.isWinAbsolute)(ctx.opts.env.ProgramFiles) ? ctx.opts.env.ProgramFiles : "C:\\Program Files", "ClaudeCode"));
32
+ return ctx.sys("/etc/claude-code");
33
+ }
34
+ function detectClaude(ctx) {
35
+ const by = [];
36
+ if ((0, fs_safe_1.isDir)(configDir(ctx)))
37
+ by.push("config dir");
38
+ if ((0, fs_safe_1.isFile)(userJsonPath(ctx)))
39
+ by.push("~/.claude.json");
40
+ if ((0, fs_safe_1.onPath)("claude", ctx.opts.env.PATH ?? ctx.opts.env.Path, { platform: ctx.opts.platform, pathExt: ctx.opts.env.PATHEXT }))
41
+ by.push("binary on PATH");
42
+ const repo = [];
43
+ for (const d of ctx.ancestorDirs()) {
44
+ for (const f of ["CLAUDE.md", ".claude/CLAUDE.md", "CLAUDE.local.md"])
45
+ if ((0, fs_safe_1.isFile)(node_path_1.default.join(d, f)))
46
+ repo.push(node_path_1.default.join(d, f));
47
+ }
48
+ if ((0, fs_safe_1.isDir)(node_path_1.default.join(ctx.cwd, ".claude")))
49
+ repo.push(node_path_1.default.join(ctx.cwd, ".claude"));
50
+ if ((0, fs_safe_1.isFile)(node_path_1.default.join(ctx.cwd, ".mcp.json")))
51
+ repo.push(node_path_1.default.join(ctx.cwd, ".mcp.json"));
52
+ return { detectedBy: by, repoFiles: repo };
53
+ }
54
+ function readSettings(ctx) {
55
+ const s = { excludes: [], disabledProjectMcp: [], env: {}, skillOverrides: Object.create(null), enabledPlugins: Object.create(null) };
56
+ const files = [node_path_1.default.join(configDir(ctx), "settings.json"), node_path_1.default.join(ctx.cwd, ".claude", "settings.json"), node_path_1.default.join(ctx.cwd, ".claude", "settings.local.json")];
57
+ for (const f of files) {
58
+ const j = ctx.readJson(f);
59
+ if (!j || typeof j !== "object")
60
+ continue;
61
+ if (Array.isArray(j.claudeMdExcludes))
62
+ s.excludes.push(...j.claudeMdExcludes.filter((x) => typeof x === "string"));
63
+ if (Array.isArray(j.disabledMcpjsonServers))
64
+ s.disabledProjectMcp.push(...j.disabledMcpjsonServers.filter((x) => typeof x === "string"));
65
+ if (j.env && typeof j.env === "object")
66
+ for (const [k, v] of Object.entries(j.env))
67
+ if (typeof v === "string")
68
+ s.env[k] = v;
69
+ if (typeof j.model === "string")
70
+ s.model = j.model;
71
+ if (typeof j.autoMemoryDirectory === "string")
72
+ s.autoMemoryDirectory = j.autoMemoryDirectory;
73
+ if (j.skillOverrides && typeof j.skillOverrides === "object")
74
+ for (const [k, v] of Object.entries(j.skillOverrides))
75
+ if (typeof v === "string")
76
+ s.skillOverrides[k] = v;
77
+ if (j.enabledPlugins && typeof j.enabledPlugins === "object" && !Array.isArray(j.enabledPlugins))
78
+ for (const [k, v] of Object.entries(j.enabledPlugins))
79
+ if (typeof v === "boolean")
80
+ s.enabledPlugins[k] = v;
81
+ if (typeof j.skillListingBudgetFraction === "number" && j.skillListingBudgetFraction > 0 && j.skillListingBudgetFraction <= 1)
82
+ s.skillListingBudgetFraction = j.skillListingBudgetFraction;
83
+ if (typeof j.skillListingMaxDescChars === "number" && j.skillListingMaxDescChars > 0)
84
+ s.skillListingMaxDescChars = Math.floor(j.skillListingMaxDescChars);
85
+ const pc = j.pluginConfigs;
86
+ const inst = pc?.["cc-plugin-agents-md@builtin"]?.options?.instructionFiles;
87
+ if (typeof inst === "string")
88
+ s.instructionFiles = inst;
89
+ }
90
+ return s;
91
+ }
92
+ /**
93
+ * Installed plugins: ~/.claude/plugins/installed_plugins.json records installPath per install (documented);
94
+ * enabledPlugins in settings says which are on (documented). The record's exact JSON shape is read defensively.
95
+ */
96
+ function findClaudePlugins(ctx, settings) {
97
+ const pdir = ctx.opts.env.CLAUDE_CODE_PLUGIN_CACHE_DIR || node_path_1.default.join(configDir(ctx), "plugins");
98
+ const rec = ctx.readJson(node_path_1.default.join(pdir, "installed_plugins.json"));
99
+ if (!rec || typeof rec !== "object")
100
+ return [];
101
+ const map = (rec.plugins && typeof rec.plugins === "object" ? rec.plugins : rec);
102
+ const out = [];
103
+ const projectKeys = new Set([ctx.cwd, ctx.gitRoot].filter((x) => !!x).map((x) => (0, fs_safe_1.realpathOrSelf)(x)));
104
+ for (const [id, v] of Object.entries(map)) {
105
+ if (out.length >= 100)
106
+ break;
107
+ if (id === "version")
108
+ continue;
109
+ if (settings.enabledPlugins[id] === false)
110
+ continue;
111
+ const entries = Array.isArray(v) ? v : [v];
112
+ for (const e of entries) {
113
+ if (!e || typeof e !== "object")
114
+ continue;
115
+ const x = e;
116
+ if (typeof x.installPath !== "string" || !node_path_1.default.isAbsolute(x.installPath))
117
+ continue;
118
+ if ((x.scope === "project" || x.scope === "local") && typeof x.projectPath === "string" && !projectKeys.has((0, fs_safe_1.realpathOrSelf)(x.projectPath)))
119
+ continue;
120
+ if (!(0, fs_safe_1.isDir)(x.installPath)) {
121
+ ctx.exclude(AGENT, x.installPath, `plugin "${id.slice(0, 60)}" is recorded in installed_plugins.json but its directory is missing`);
122
+ continue;
123
+ }
124
+ const mj = ctx.readJson(node_path_1.default.join(x.installPath, ".claude-plugin", "plugin.json"));
125
+ const name = mj && typeof mj.name === "string" && mj.name.trim() ? mj.name.trim().slice(0, 60) : id.split("@")[0].slice(0, 60);
126
+ out.push({ id: id.slice(0, 80), name, root: x.installPath, assumedEnabled: settings.enabledPlugins[id] !== true });
127
+ break;
128
+ }
129
+ }
130
+ return out.sort((a, b) => (0, fmt_1.cmp)(a.id, b.id));
131
+ }
132
+ function discoverClaude(ctx) {
133
+ const spec = (0, spec_1.loadSpec)(AGENT);
134
+ const caps = spec.caps;
135
+ const items = [];
136
+ const banner = [];
137
+ const settings = readSettings(ctx);
138
+ const isExcluded = settings.excludes.length ? (0, platform_1.makeGlobMatcher)(settings.excludes, ctx.opts.platform) : () => false;
139
+ const seen = new Set();
140
+ const pluginMcp = [];
141
+ const add = (it) => {
142
+ if (it)
143
+ items.push(it);
144
+ return it;
145
+ };
146
+ const instr = (file, o) => {
147
+ const real = (0, fs_safe_1.realpathOrSelf)(file);
148
+ if (seen.has(real))
149
+ return null;
150
+ if (o.canExclude && isExcluded(file)) {
151
+ if ((0, fs_safe_1.isFile)(file))
152
+ ctx.exclude(AGENT, file, "matched claudeMdExcludes");
153
+ return null;
154
+ }
155
+ const it = (0, common_1.loadInstruction)(ctx, file, {
156
+ agent: AGENT,
157
+ scope: o.scope,
158
+ loadMode: o.loadMode ?? "always",
159
+ label: o.label,
160
+ cardLabel: o.cardLabel,
161
+ jail: o.jail,
162
+ stripComments: true,
163
+ imports: true,
164
+ confidence: "documented",
165
+ evidence: ev("memory"),
166
+ guidelineLines: caps.instructionFileGuidelineLines,
167
+ notes: o.notes,
168
+ });
169
+ if (it)
170
+ seen.add(real);
171
+ return it;
172
+ };
173
+ // 1. managed, 2. user
174
+ add(instr(node_path_1.default.join(managedDir(ctx), "CLAUDE.md"), { scope: "managed", label: "Managed CLAUDE.md", cardLabel: "Managed CLAUDE.md", canExclude: false }));
175
+ add(instr(node_path_1.default.join(configDir(ctx), "CLAUDE.md"), { scope: "user", label: "~/.claude/CLAUDE.md", cardLabel: "User CLAUDE.md", canExclude: true }));
176
+ // 3. project chain: CLAUDE.md / .claude/CLAUDE.md / CLAUDE.local.md in cwd and every ancestor
177
+ let projectClaudeMd = false;
178
+ for (const dir of ctx.ancestorDirs()) {
179
+ const jail = ctx.jailFor(dir);
180
+ const rel = (f) => ctx.display(node_path_1.default.join(dir, f));
181
+ for (const [f, local] of [["CLAUDE.md", false], [node_path_1.default.join(".claude", "CLAUDE.md"), false], ["CLAUDE.local.md", true]]) {
182
+ const full = node_path_1.default.join(dir, f);
183
+ if (!(0, fs_safe_1.isFile)(full))
184
+ continue;
185
+ const it = instr(full, {
186
+ scope: dir === ctx.cwd ? (local ? "local" : "project") : "ancestor",
187
+ label: rel(f),
188
+ cardLabel: local ? "CLAUDE.local.md" : "CLAUDE.md",
189
+ jail,
190
+ canExclude: true,
191
+ notes: dir === ctx.cwd ? [] : ["ancestor directory (loaded at launch, root→cwd)"],
192
+ });
193
+ if (it) {
194
+ items.push(it);
195
+ projectClaudeMd = true;
196
+ }
197
+ else if (!seen.has((0, fs_safe_1.realpathOrSelf)(full)) && !isExcluded(full))
198
+ projectClaudeMd = true; // present but empty/unreadable still counts as "exists" for AGENTS.md precedence
199
+ }
200
+ }
201
+ // 4. AGENTS.md fallback (v2.1.277+): only if no CLAUDE.md anywhere in the chain (default), or both if configured
202
+ const both = (settings.instructionFiles ?? "").includes("and");
203
+ for (const dir of ctx.ancestorDirs())
204
+ for (const agentsPath of [node_path_1.default.join(dir, "AGENTS.md"), node_path_1.default.join(dir, ".claude", "AGENTS.md")]) { // docs: "every AGENTS.md and .claude/AGENTS.md in your working directory and the directories above it"
205
+ if (!(0, fs_safe_1.isFile)(agentsPath))
206
+ continue;
207
+ if (projectClaudeMd && !both) {
208
+ ctx.exclude(AGENT, agentsPath, "ignored by Claude Code: a CLAUDE.md exists in this directory tree (default instructionFiles = claude-md-or-agents-md)");
209
+ ctx.addFinding({
210
+ id: "F7",
211
+ severity: "warn",
212
+ agent: AGENT,
213
+ message: `Claude Code ignores ${ctx.display(agentsPath)}: a CLAUDE.md exists in this directory tree (Cursor and Codex still load it)`,
214
+ paths: [agentsPath],
215
+ confidence: "high",
216
+ fix: "Add `@AGENTS.md` to CLAUDE.md, or set the AGENTS.md plugin option instructionFiles to claude-md-and-agents-md.",
217
+ });
218
+ continue;
219
+ }
220
+ add(instr(agentsPath, {
221
+ scope: dir === ctx.cwd ? "project" : "ancestor",
222
+ label: ctx.display(agentsPath),
223
+ cardLabel: "AGENTS.md",
224
+ jail: ctx.jailFor(dir),
225
+ canExclude: true,
226
+ notes: [`AGENTS.md fallback needs Claude Code ≥ ${spec.minVersions?.agentsMdFallback}; ${both ? "both files loaded (instructionFiles setting)" : "no CLAUDE.md found"}`],
227
+ }));
228
+ }
229
+ // 5. nested CLAUDE.md under cwd -> conditional
230
+ for (const hit of ctx.walk().hits) {
231
+ for (const n of hit.names.filter((x) => x.startsWith("CLAUDE") || x === ".claude/CLAUDE.md")) {
232
+ add(instr(node_path_1.default.join(hit.dir, n), { scope: "nested", label: ctx.display(node_path_1.default.join(hit.dir, n)), cardLabel: "nested CLAUDE.md", jail: ctx.jailFor(hit.dir), loadMode: "conditional", canExclude: true, notes: ["loaded when Claude works in this subdirectory (not in /context at start)"] }));
233
+ }
234
+ }
235
+ // 6. rules
236
+ const ruleDirs = [
237
+ [node_path_1.default.join(configDir(ctx), "rules"), "user", "~/.claude/rules"],
238
+ [node_path_1.default.join(ctx.cwd, ".claude", "rules"), "project", ".claude/rules"],
239
+ ];
240
+ for (const [dir, scope, gl] of ruleDirs) {
241
+ for (const f of (0, common_1.listFilesRec)(dir, [".md"])) {
242
+ if (isExcluded(f)) {
243
+ ctx.exclude(AGENT, f, "matched claudeMdExcludes");
244
+ continue;
245
+ }
246
+ let conditional = false;
247
+ add((0, common_1.loadInstruction)(ctx, f, {
248
+ agent: AGENT,
249
+ scope,
250
+ loadMode: "always",
251
+ kind: "rule",
252
+ label: ctx.display(f),
253
+ cardLabel: "rule file",
254
+ jail: scope === "project" ? ctx.jailFor(ctx.cwd) : undefined,
255
+ stripComments: true,
256
+ imports: true,
257
+ confidence: "documented",
258
+ evidence: ev("memory"),
259
+ guidelineLines: caps.instructionFileGuidelineLines,
260
+ group: `${gl}`,
261
+ groupLabel: `${gl}/*.md`,
262
+ transform: (raw) => {
263
+ const fm = (0, frontmatter_1.parseFrontmatter)(raw);
264
+ const paths = (0, frontmatter_1.asList)(fm.data.paths);
265
+ conditional = paths.length > 0;
266
+ return { text: fm.body, notes: conditional ? [`path-scoped (paths: ${paths.length} pattern${paths.length > 1 ? "s" : ""}) → conditional`] : [] };
267
+ },
268
+ }));
269
+ const last = items[items.length - 1];
270
+ if (last && last.path === f && conditional) {
271
+ last.loadMode = "conditional";
272
+ last.group = `${gl}#conditional`;
273
+ last.groupLabel = `${gl}/*.md (path-scoped)`;
274
+ }
275
+ }
276
+ }
277
+ // 7. auto memory
278
+ const slugBase = ctx.gitRoot ?? ctx.cwd;
279
+ const slug = slugBase.replace(/[^A-Za-z0-9]/g, "-");
280
+ const memDir = settings.autoMemoryDirectory ? settings.autoMemoryDirectory.replace(/^~(?=[\\/]|$)/, ctx.home) : node_path_1.default.join(configDir(ctx), "projects", slug, "memory");
281
+ const memFile = node_path_1.default.join(memDir, "MEMORY.md");
282
+ if ((0, fs_safe_1.isFile)(memFile)) {
283
+ const it = (0, common_1.loadInstruction)(ctx, memFile, {
284
+ agent: AGENT,
285
+ scope: "user",
286
+ loadMode: "always",
287
+ kind: "memory",
288
+ label: "MEMORY.md (auto memory)",
289
+ cardLabel: "MEMORY.md",
290
+ stripComments: false,
291
+ imports: false,
292
+ confidence: "documented",
293
+ evidence: ev("memory"),
294
+ noAnalyze: true,
295
+ notes: [settings.autoMemoryDirectory ? "memory dir from autoMemoryDirectory setting" : "memory dir derived from project path (derivation assumed)"],
296
+ transform: (raw) => {
297
+ const lines = raw.split("\n");
298
+ const notes = [];
299
+ let out = lines.slice(0, caps.memoryMaxLines).join("\n");
300
+ if (lines.length > caps.memoryMaxLines)
301
+ notes.push(`truncated: only first ${caps.memoryMaxLines} of ${lines.length} lines are loaded`);
302
+ if (Buffer.byteLength(out) > caps.memoryMaxBytes) {
303
+ out = Buffer.from(out).subarray(0, caps.memoryMaxBytes).toString("utf8");
304
+ notes.push(`truncated at ${caps.memoryMaxBytes / 1024} KB`);
305
+ }
306
+ if (notes.length) {
307
+ ctx.addFinding({ id: "F8", severity: "warn", agent: AGENT, message: `MEMORY.md exceeds the load cap (${notes.join("; ")}); the rest is silently dropped`, paths: [memFile], confidence: "high", fix: "Move detail into topic files and keep MEMORY.md as a short index." });
308
+ }
309
+ return { text: out, notes };
310
+ },
311
+ });
312
+ add(it);
313
+ }
314
+ // 8. skills (listing always, body deferred), 9. subagents
315
+ // Documented: a skill's name + description (+ when_to_use, combined cap 1,536 chars) is listed; the body loads on use.
316
+ // disable-model-invocation / skillOverrides hide the description from the model; skillOverrides "name-only" lists the name alone.
317
+ const cap = settings.skillListingMaxDescChars ?? caps.skillDescriptionMaxChars;
318
+ const seenSkill = new Set();
319
+ const claudeLine = (r) => {
320
+ const ov = settings.skillOverrides[r.name];
321
+ if (ov === "off" || ov === "user-invocable-only")
322
+ return null;
323
+ if (r.disableModelInvocation)
324
+ return null;
325
+ if (ov === "name-only")
326
+ return `- ${r.name}`;
327
+ const combined = [r.desc, r.when].filter(Boolean).join(" ");
328
+ return `- ${r.name}: ${combined.length > cap ? combined.slice(0, cap) : combined}`;
329
+ };
330
+ const emit = (recs, dir, scope, tag, o = {}) => {
331
+ const fresh = recs.filter((r) => !seenSkill.has(r.realPath));
332
+ for (const r of fresh) {
333
+ seenSkill.add(r.realPath);
334
+ if (r.desc.length + (r.when ? r.when.length + 1 : 0) > cap && !r.disableModelInvocation) {
335
+ ctx.addFinding({ id: "F4", severity: "warn", agent: AGENT, message: `Skill description (description + when_to_use) in ${ctx.display(r.file)} exceeds ${cap} characters; the tail is dropped from the listing`, paths: [r.file], confidence: "high", fix: `Shorten description + when_to_use to ≤ ${cap} chars combined; put the key use case first.` });
336
+ }
337
+ }
338
+ if (!fresh.length)
339
+ return;
340
+ const its = (0, skills_1.skillItems)(ctx, {
341
+ agent: AGENT, dir, scope, tag, recs: fresh, lineFor: claudeLine, listingMode: o.conditional ? "conditional" : "always",
342
+ confidence: o.confidence ?? "documented", evidence: ev("skills"),
343
+ notes: [`name + description + when_to_use, combined cap ${cap} chars per skill`, ...(o.note ? [o.note] : [])],
344
+ });
345
+ items.push(...its);
346
+ const listing = its.find((i) => i.kind === "skills-listing");
347
+ if (listing?.tokens && !o.conditional) {
348
+ const budget = (settings.skillListingBudgetFraction ?? caps.skillListingBudgetFractionOfWindow) * ctx.opts.window;
349
+ const est = listing.tokens.est;
350
+ if (est > budget) {
351
+ ctx.addFinding({ id: "F13", severity: "info", agent: AGENT, message: `${tag} skills listing (~${est} tokens) exceeds ≈${Math.round((settings.skillListingBudgetFraction ?? caps.skillListingBudgetFractionOfWindow) * 100)}% of a ${ctx.opts.window / 1000}k window (~${Math.round(budget)}); Claude Code drops descriptions of the least-used skills to fit (documented; tokens-vs-characters unit of the budget is unclear)`, paths: [dir], confidence: "low", fix: 'Set rarely used skills to "name-only" in skillOverrides, or delete them.' });
352
+ }
353
+ }
354
+ };
355
+ const projJail = ctx.jailFor(ctx.cwd);
356
+ emit((0, skills_1.discoverSkills)(ctx, node_path_1.default.join(configDir(ctx), "skills")).filter((r) => !/[\\/]synced[\\/]/.test(r.file)), node_path_1.default.join(configDir(ctx), "skills"), "user", "user");
357
+ // claude.ai synced skills live in ~/.claude/skills/synced/<name>/ (documented)
358
+ emit((0, skills_1.discoverSkills)(ctx, node_path_1.default.join(configDir(ctx), "skills", "synced")), node_path_1.default.join(configDir(ctx), "skills", "synced"), "user", "claude.ai synced");
359
+ // project skills: cwd and every parent up to the repo root load at start (documented)
360
+ const root = ctx.gitRoot ?? ctx.cwd;
361
+ for (const dir of ctx.ancestorDirs().filter((d) => (0, fs_safe_1.isInside)(d, root)).reverse()) {
362
+ const sdir = node_path_1.default.join(dir, ".claude", "skills");
363
+ emit((0, skills_1.discoverSkills)(ctx, sdir, { jail: ctx.jailFor(dir) }), sdir, dir === ctx.cwd ? "project" : "ancestor", dir === ctx.cwd ? "project" : "ancestor");
364
+ }
365
+ // nested .claude/skills below cwd load lazily when Claude works in that subtree (documented)
366
+ for (const hit of ctx.walk().hits) {
367
+ if (!hit.names.includes(".claude/skills/"))
368
+ continue;
369
+ const sdir = node_path_1.default.join(hit.dir, ".claude", "skills");
370
+ emit((0, skills_1.discoverSkills)(ctx, sdir, { jail: ctx.jailFor(hit.dir) }), sdir, "nested", "nested", { conditional: true, note: "nested skill directory: loaded when Claude works in this subtree (documented)" });
371
+ }
372
+ // custom commands are merged into skills: same listing (documented)
373
+ for (const [dir, scope, tag, jail] of [[node_path_1.default.join(configDir(ctx), "commands"), "user", "user command", undefined], [node_path_1.default.join(ctx.cwd, ".claude", "commands"), "project", "project command", projJail]]) {
374
+ const recs = [];
375
+ for (const f of (0, common_1.listFilesRec)(dir, [".md"], 300, 3)) {
376
+ const r = ctx.read(f, jail ? { jail } : {});
377
+ if (r.ok)
378
+ recs.push((0, skills_1.toRec)(node_path_1.default.basename(f, ".md"), f, r.realPath, r.text));
379
+ }
380
+ emit(recs, dir, scope, tag);
381
+ }
382
+ // plugins
383
+ const plugins = findClaudePlugins(ctx, settings);
384
+ // One listing per kind for ALL plugins: a listing is one block of text in the prompt, and eight one-skill lines are noise.
385
+ const pSkills = [];
386
+ const pCmds = [];
387
+ for (const pl of plugins) {
388
+ const recs = (0, skills_1.discoverSkills)(ctx, node_path_1.default.join(pl.root, "skills"));
389
+ for (const r of recs)
390
+ r.source = pl.name;
391
+ pSkills.push(...recs);
392
+ for (const f of (0, common_1.listFilesRec)(node_path_1.default.join(pl.root, "commands"), [".md"], 200, 3)) {
393
+ const r = ctx.read(f);
394
+ if (r.ok)
395
+ pCmds.push({ ...(0, skills_1.toRec)(node_path_1.default.basename(f, ".md"), f, r.realPath, r.text), source: pl.name });
396
+ }
397
+ pluginMcp.push(pl);
398
+ }
399
+ if (plugins.length) {
400
+ const guess = plugins.some((x) => x.assumedEnabled);
401
+ const pdir = node_path_1.default.join(configDir(ctx), "plugins");
402
+ const pnote = `from ${plugins.length} installed plugin${plugins.length > 1 ? "s" : ""} (installed_plugins.json${guess ? "; some are not listed in enabledPlugins and are treated as enabled" : ""})`;
403
+ const tag = `from ${plugins.length} plugin${plugins.length > 1 ? "s" : ""}`;
404
+ emit(pSkills, pdir, "plugin", tag, { note: pnote, confidence: guess ? "assumed" : "documented" });
405
+ emit(pCmds, pdir, "plugin", `${tag}, command`, { note: pnote });
406
+ }
407
+ for (const [dir, scope, tag] of [[node_path_1.default.join(configDir(ctx), "agents"), "user", "user"], [node_path_1.default.join(ctx.cwd, ".claude", "agents"), "project", "project"]]) {
408
+ const files = (0, common_1.listFilesRec)(dir, [".md"], 200, 1);
409
+ let listing = "";
410
+ let n = 0;
411
+ for (const f of files) {
412
+ const r = ctx.read(f, scope === "project" ? { jail: ctx.jailFor(ctx.cwd) } : {});
413
+ if (!r.ok)
414
+ continue;
415
+ const fm = (0, frontmatter_1.parseFrontmatter)(r.text);
416
+ listing += `${(0, frontmatter_1.asString)(fm.data.name) || node_path_1.default.basename(f, ".md")}: ${(0, frontmatter_1.asString)(fm.data.description)}\n`;
417
+ n++;
418
+ }
419
+ if (n) {
420
+ items.push(ctx.makeItem({ agent: AGENT, path: dir, kind: "subagents", scope, loadMode: "always", raw: ctx.count(`agents|${dir}`, listing), chars: listing.length, confidence: "assumed", evidence: ev("memory"), label: `Subagents listing (${n} ${tag})`, cardLabel: "subagents listing", notes: ["/context lists subagents; how much of each is injected is unverified (name + description assumed)"] }));
421
+ }
422
+ }
423
+ // 10. MCP
424
+ const projectKeys = [...new Set([ctx.cwd, ctx.gitRoot].filter((x) => !!x))];
425
+ const toolSearchOff = (ctx.opts.env.ENABLE_TOOL_SEARCH ?? settings.env.ENABLE_TOOL_SEARCH) === "false";
426
+ const mode = toolSearchOff ? "full" : "split";
427
+ const modeNote = toolSearchOff ? "ENABLE_TOOL_SEARCH=false: full schemas load upfront" : "tool search assumed ON (default): names always, schemas deferred";
428
+ const mcpSeen = new Set();
429
+ const addServers = (defs, source, scope, disabled) => {
430
+ for (const def of defs) {
431
+ const k = `${scope}:${def.name}`;
432
+ if (mcpSeen.has(k))
433
+ continue;
434
+ mcpSeen.add(k);
435
+ if (def.disabled || disabled.includes(def.name)) {
436
+ ctx.exclude(AGENT, source, `MCP server "${def.name}" is disabled`);
437
+ continue;
438
+ }
439
+ items.push(...(0, common_1.mcpItems)(ctx, { agent: AGENT, def, source, scope, mode, evidence: ev("mcp"), notes: [modeNote, ...(scope === "project" ? ["project-scope server: Claude Code asks for approval before loading"] : [])], index: items.length }));
440
+ }
441
+ };
442
+ const projMcp = node_path_1.default.join(ctx.cwd, ".mcp.json");
443
+ const pj = ctx.readJson(projMcp);
444
+ if (pj)
445
+ addServers((0, configs_1.parseMcpMap)(pj.mcpServers, (m) => ctx.warn(m)), projMcp, "project", settings.disabledProjectMcp);
446
+ const uj = ctx.readJson(userJsonPath(ctx));
447
+ if (uj) {
448
+ for (const key of projectKeys) {
449
+ const pe = uj.projects?.[key];
450
+ if (pe)
451
+ addServers((0, configs_1.parseMcpMap)(pe.mcpServers, (m) => ctx.warn(m)), userJsonPath(ctx), "local", Array.isArray(pe.disabledMcpServers) ? pe.disabledMcpServers.filter((x) => typeof x === "string") : []);
452
+ }
453
+ addServers((0, configs_1.parseMcpMap)(uj.mcpServers, (m) => ctx.warn(m)), userJsonPath(ctx), "user", []);
454
+ }
455
+ // managed MCP file (name documented; location inside the managed dir assumed) and plugin-provided servers
456
+ const mm = node_path_1.default.join(managedDir(ctx), "managed-mcp.json");
457
+ const mj = ctx.readJson(mm);
458
+ if (mj)
459
+ addServers((0, configs_1.parseMcpMap)(mj.mcpServers, (m) => ctx.warn(m)), mm, "managed", []);
460
+ let pluginAgents = 0;
461
+ for (const pl of pluginMcp) {
462
+ const f = node_path_1.default.join(pl.root, ".mcp.json");
463
+ const pj2 = ctx.readJson(f);
464
+ if (pj2) {
465
+ for (const def of (0, configs_1.parseMcpMap)(pj2.mcpServers ?? pj2, (m) => ctx.warn(m))) {
466
+ if (def.disabled)
467
+ continue;
468
+ items.push(...(0, common_1.mcpItems)(ctx, { agent: AGENT, def, source: f, scope: "plugin", mode, evidence: ev("mcp"), notes: [modeNote, `provided by plugin ${pl.id}`], index: items.length }));
469
+ }
470
+ }
471
+ if ((0, fs_safe_1.isDir)(node_path_1.default.join(pl.root, "agents")))
472
+ pluginAgents++;
473
+ }
474
+ banner.push("built-in system prompt and built-in tools", "claude.ai connectors (not on disk)", "hook output");
475
+ if (pluginAgents)
476
+ banner.push(`subagents and hooks provided by plugins (${pluginAgents} plugin${pluginAgents > 1 ? "s" : ""})`);
477
+ if ((0, fs_safe_1.exists)(node_path_1.default.join(configDir(ctx), "plugins")) && !pluginMcp.length)
478
+ banner.push("plugins directory exists but no enabled plugin install was recorded");
479
+ return { items, unmeasuredBanner: banner };
480
+ }