@shrkcrft/cli 0.1.0-alpha.8 → 0.1.0-alpha.9
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/README.md +1 -1
- package/dist/commands/boundaries.command.d.ts.map +1 -1
- package/dist/commands/boundaries.command.js +12 -0
- package/dist/commands/check.command.d.ts.map +1 -1
- package/dist/commands/check.command.js +30 -20
- package/dist/commands/command-catalog.d.ts +3 -7
- package/dist/commands/command-catalog.d.ts.map +1 -1
- package/dist/commands/command-catalog.js +47 -113
- package/dist/commands/commands.command.d.ts.map +1 -1
- package/dist/commands/commands.command.js +4 -4
- package/dist/commands/constructs.command.d.ts.map +1 -1
- package/dist/commands/constructs.command.js +22 -5
- package/dist/commands/doctor.command.d.ts.map +1 -1
- package/dist/commands/doctor.command.js +9 -42
- package/dist/commands/export.command.d.ts.map +1 -1
- package/dist/commands/export.command.js +3 -76
- package/dist/commands/help.command.d.ts +3 -4
- package/dist/commands/help.command.d.ts.map +1 -1
- package/dist/commands/help.command.js +21 -77
- package/dist/commands/helper.command.js +1 -1
- package/dist/commands/import.command.d.ts.map +1 -1
- package/dist/commands/import.command.js +5 -121
- package/dist/commands/init.command.d.ts.map +1 -1
- package/dist/commands/init.command.js +16 -184
- package/dist/commands/mcp.command.d.ts.map +1 -1
- package/dist/commands/mcp.command.js +131 -2
- package/dist/commands/onboard.command.d.ts.map +1 -1
- package/dist/commands/onboard.command.js +15 -3
- package/dist/commands/packs-new.d.ts +1 -1
- package/dist/commands/packs-new.d.ts.map +1 -1
- package/dist/commands/packs-new.js +36 -5
- package/dist/commands/packs.command.d.ts.map +1 -1
- package/dist/commands/packs.command.js +17 -3
- package/dist/commands/plugin.command.d.ts +11 -0
- package/dist/commands/plugin.command.d.ts.map +1 -0
- package/dist/commands/plugin.command.js +394 -0
- package/dist/commands/profiles.command.js +4 -4
- package/dist/commands/release.command.js +13 -13
- package/dist/commands/review.command.d.ts.map +1 -1
- package/dist/commands/review.command.js +28 -2
- package/dist/commands/search.command.js +1 -1
- package/dist/commands/task-context.command.js +16 -0
- package/dist/export/export-formats.d.ts +1 -1
- package/dist/export/export-formats.d.ts.map +1 -1
- package/dist/export/export-formats.js +12 -139
- package/dist/init/init-templates.d.ts.map +1 -1
- package/dist/init/init-templates.js +113 -133
- package/dist/main.d.ts +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +46 -117
- package/dist/output/failure-hints.d.ts +9 -1
- package/dist/output/failure-hints.d.ts.map +1 -1
- package/dist/output/failure-hints.js +8 -2
- package/dist/output/watch-loop.d.ts +1 -9
- package/dist/output/watch-loop.d.ts.map +1 -1
- package/dist/output/watch-loop.js +3 -13
- package/dist/schemas/json-schemas.d.ts +36 -36
- package/dist/schemas/json-schemas.js +36 -36
- package/dist/surface/about.d.ts.map +1 -1
- package/dist/surface/about.js +15 -37
- package/dist/surface/no-args-landing.d.ts.map +1 -1
- package/dist/surface/no-args-landing.js +13 -9
- package/dist/surface/surface-config-writer.d.ts.map +1 -1
- package/dist/surface/surface-config-writer.js +11 -23
- package/package.json +25 -26
- package/dist/commands/diff-check.command.d.ts +0 -30
- package/dist/commands/diff-check.command.d.ts.map +0 -1
- package/dist/commands/diff-check.command.js +0 -210
- package/dist/export/claude-commands-export.d.ts +0 -60
- package/dist/export/claude-commands-export.d.ts.map +0 -1
- package/dist/export/claude-commands-export.js +0 -276
- package/dist/init/paths-advisory.d.ts +0 -20
- package/dist/init/paths-advisory.d.ts.map +0 -1
- package/dist/init/paths-advisory.js +0 -88
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `.claude/commands/` generator — emits per-project slash commands
|
|
3
|
-
* for Claude Code. Companion to `claude-skill` export, but with a
|
|
4
|
-
* different inversion semantics:
|
|
5
|
-
*
|
|
6
|
-
* - **claude-skill** loads rules into Claude's prompt automatically
|
|
7
|
-
* based on description match. Passive — Claude reads the rules.
|
|
8
|
-
* - **claude-commands** registers slash commands the USER invokes
|
|
9
|
-
* (`/new-service`, `/check-changes`). Active — the command IS the
|
|
10
|
-
* recipe; Claude follows it step-by-step.
|
|
11
|
-
*
|
|
12
|
-
* Generated commands fall into two buckets:
|
|
13
|
-
*
|
|
14
|
-
* **Static commands** (always present, project-agnostic recipes):
|
|
15
|
-
* - `/follow-shrk` — short reminder of the apply-gate flow.
|
|
16
|
-
* - `/check-changes` — runs `shrk check boundaries --changed-only`
|
|
17
|
-
* scoped to the current diff and reports back.
|
|
18
|
-
* - `/shrk-brief` — runs `shrk brief` and uses the output for the
|
|
19
|
-
* current task.
|
|
20
|
-
* - `/explain-file <path>` — per-file rules / paths / boundary
|
|
21
|
-
* lookup (pairs with `shrk advise <path>` from Phase 3).
|
|
22
|
-
*
|
|
23
|
-
* **Per-template commands** (one per id in `sharkcraft/templates.ts`):
|
|
24
|
-
* - `/new-<template-id>` — Claude runs `shrk gen <template-id>
|
|
25
|
-
* <name> --dry-run --save-plan ...`, reviews the plan, and
|
|
26
|
-
* applies via `shrk apply ... --verify-signature --validate`.
|
|
27
|
-
*
|
|
28
|
-
* Generated files are self-contained markdown — no `@shrkcrft/*`
|
|
29
|
-
* imports, no shell expansions. Each one is a complete "recipe in a
|
|
30
|
-
* file" that Claude Code reads when the user types the slash command.
|
|
31
|
-
*/
|
|
32
|
-
// ─── Static commands (always emitted) ────────────────────────────────────────
|
|
33
|
-
const STATIC_FOLLOW_SHRK = `---
|
|
34
|
-
description: Reminder of the shrk apply-gate flow for this project. Use when generating or modifying code so the change passes the same boundary / validation gates the project CI uses.
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
# Follow the shrk apply-gate flow
|
|
38
|
-
|
|
39
|
-
This repo uses [SharkCraft](https://github.com/shrkcrft/sharkcraft) as the
|
|
40
|
-
gate for AI-written code. Skip the gate and CI will fail with the same
|
|
41
|
-
errors anyway — save the round-trip.
|
|
42
|
-
|
|
43
|
-
## The loop
|
|
44
|
-
|
|
45
|
-
1. **Get focused context first.**
|
|
46
|
-
- Run: \`shrk task "<one-sentence task>"\` for a task packet (relevant rules + templates + verification commands).
|
|
47
|
-
- Or: \`shrk brief\` for the single-page project brief.
|
|
48
|
-
|
|
49
|
-
2. **Scaffold via a template (not freehand).**
|
|
50
|
-
- List options: \`shrk templates list\`.
|
|
51
|
-
- Dry-run + save plan: \`shrk gen <template-id> <name> --dry-run --save-plan /tmp/plan.json\`.
|
|
52
|
-
|
|
53
|
-
3. **Apply the plan through the CLI.**
|
|
54
|
-
- \`shrk apply /tmp/plan.json --verify-signature --validate\`.
|
|
55
|
-
- Never write files directly through MCP — MCP is read-only in this repo.
|
|
56
|
-
|
|
57
|
-
4. **Verify before declaring done.**
|
|
58
|
-
- \`shrk check boundaries --changed-only\` — fails if the diff broke any layer rule.
|
|
59
|
-
- \`shrk check imports\` — fails on lazy requires / cross-package deep imports.
|
|
60
|
-
- Project verification commands (from \`shrk task\`'s \`actionHints.verificationCommands\`).
|
|
61
|
-
|
|
62
|
-
## When this loop doesn't apply
|
|
63
|
-
|
|
64
|
-
- Tiny changes that don't touch source files (docs, comments).
|
|
65
|
-
- Read-only investigations.
|
|
66
|
-
- Anything where shrk would clearly be in the way.
|
|
67
|
-
|
|
68
|
-
In all other cases: **follow the loop**. The gates are short; the rework if you skip them is long.
|
|
69
|
-
`;
|
|
70
|
-
const STATIC_CHECK_CHANGES = `---
|
|
71
|
-
description: Run shrk's boundary + import-hygiene checks on the current git diff. Use after making any file change to confirm the change didn't violate the project's architecture rules before declaring the task done.
|
|
72
|
-
---
|
|
73
|
-
|
|
74
|
-
# Check the current diff for boundary violations
|
|
75
|
-
|
|
76
|
-
Run the diff-scoped boundary check:
|
|
77
|
-
|
|
78
|
-
\`\`\`bash
|
|
79
|
-
shrk check boundaries --changed-only
|
|
80
|
-
\`\`\`
|
|
81
|
-
|
|
82
|
-
Run the import-hygiene check on the changed files:
|
|
83
|
-
|
|
84
|
-
\`\`\`bash
|
|
85
|
-
shrk check imports
|
|
86
|
-
\`\`\`
|
|
87
|
-
|
|
88
|
-
## Interpreting the output
|
|
89
|
-
|
|
90
|
-
- **Exit 0, "0 violations":** safe to declare done.
|
|
91
|
-
- **Exit non-zero with violations listed:** fix each violation before continuing. Each violation has a \`suggestedFix\` line — apply it.
|
|
92
|
-
- **A violation on a file you didn't change:** that's a pre-existing violation in the repo. Ignore it; the \`--changed-only\` filter only fails on violations your diff introduced.
|
|
93
|
-
|
|
94
|
-
If the violations look like false positives, consult \`sharkcraft/boundaries.ts\` (the rule definitions) — don't disable them ad-hoc.
|
|
95
|
-
`;
|
|
96
|
-
const STATIC_SHRK_BRIEF = `---
|
|
97
|
-
description: Pull shrk's single-page project brief — focused rules, paths, verification commands. Use when starting work in this codebase so you have the project's actual conventions in context before writing any code.
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
# Pull the shrk brief for this project
|
|
101
|
-
|
|
102
|
-
Run the project brief:
|
|
103
|
-
|
|
104
|
-
\`\`\`bash
|
|
105
|
-
shrk brief
|
|
106
|
-
\`\`\`
|
|
107
|
-
|
|
108
|
-
This returns a compact markdown brief covering:
|
|
109
|
-
- Project overview (name, frameworks, package manager).
|
|
110
|
-
- Top rules that apply to code generation in this repo.
|
|
111
|
-
- Path conventions (where different file types belong).
|
|
112
|
-
- Action hints (commands, MCP tools, verification commands).
|
|
113
|
-
- Forbidden actions (what NOT to do).
|
|
114
|
-
|
|
115
|
-
For a per-task version (only the rules + paths + templates relevant to one task):
|
|
116
|
-
|
|
117
|
-
\`\`\`bash
|
|
118
|
-
shrk task "<one-sentence task description>"
|
|
119
|
-
\`\`\`
|
|
120
|
-
|
|
121
|
-
Both are read-only — no files are touched. Use the output to shape your plan before making any changes.
|
|
122
|
-
`;
|
|
123
|
-
const STATIC_EXPLAIN_FILE = `---
|
|
124
|
-
description: Look up the rules, path conventions, and boundary rules that apply to a specific file in this codebase. Use before editing an unfamiliar file so you follow the project's per-area conventions instead of generic patterns.
|
|
125
|
-
---
|
|
126
|
-
|
|
127
|
-
# Explain what applies to a file in this codebase
|
|
128
|
-
|
|
129
|
-
For a given file path (e.g. \`apps/users/src/profile.service.ts\`):
|
|
130
|
-
|
|
131
|
-
\`\`\`bash
|
|
132
|
-
shrk why <file-path>
|
|
133
|
-
\`\`\`
|
|
134
|
-
|
|
135
|
-
Returns:
|
|
136
|
-
- Which package / layer the file belongs to.
|
|
137
|
-
- Which path conventions apply (e.g. "services live in \`apps/<x>/src/services/\`").
|
|
138
|
-
- Which rules are scoped to this file's path.
|
|
139
|
-
- Which boundary rules constrain this file's imports.
|
|
140
|
-
- Cross-references to related knowledge entries.
|
|
141
|
-
|
|
142
|
-
Use this *before* editing. The output is the project's actual conventions for that area, not your guess based on the file's content.
|
|
143
|
-
`;
|
|
144
|
-
// ─── Per-template command generator ──────────────────────────────────────────
|
|
145
|
-
/**
|
|
146
|
-
* Slugify a template id into a slash-command name. Template ids
|
|
147
|
-
* conventionally look like `typescript.service`; the slash command is
|
|
148
|
-
* `new-typescript-service` (or `new-service` if the segment after the
|
|
149
|
-
* dot is unique and shorter).
|
|
150
|
-
*/
|
|
151
|
-
function templateSlash(templateId) {
|
|
152
|
-
// Use the LAST dot-separated segment as the primary name —
|
|
153
|
-
// `typescript.service` → `new-service`. Falls back to the full id
|
|
154
|
-
// when there's no dot or the segment is too generic (single char).
|
|
155
|
-
const parts = templateId.split('.');
|
|
156
|
-
const tail = parts[parts.length - 1] ?? templateId;
|
|
157
|
-
const safeName = tail.length >= 3 ? tail : templateId.replace(/\./g, '-');
|
|
158
|
-
return `new-${safeName}`
|
|
159
|
-
.toLowerCase()
|
|
160
|
-
.replace(/[^a-z0-9-]+/g, '-')
|
|
161
|
-
.replace(/-+/g, '-')
|
|
162
|
-
.replace(/^-+|-+$/g, '');
|
|
163
|
-
}
|
|
164
|
-
function templateCommandBody(template) {
|
|
165
|
-
const displayName = template.name ?? template.id;
|
|
166
|
-
const description = template.description
|
|
167
|
-
? template.description.replace(/\s+/g, ' ').trim()
|
|
168
|
-
: `Scaffold a new ${displayName} using the project's actual template (\`${template.id}\`). Follows the shrk plan → apply → validate flow.`;
|
|
169
|
-
return `---
|
|
170
|
-
description: ${JSON.stringify(description)}
|
|
171
|
-
---
|
|
172
|
-
|
|
173
|
-
# /${templateSlash(template.id)} — scaffold ${displayName}
|
|
174
|
-
|
|
175
|
-
This command scaffolds a new ${displayName} using the project's actual template
|
|
176
|
-
defined in \`sharkcraft/templates.ts\`. The template encodes this repo's
|
|
177
|
-
conventions for path, naming, and structure — the result will match how
|
|
178
|
-
the rest of the codebase is organized, not generic patterns.
|
|
179
|
-
|
|
180
|
-
## The flow
|
|
181
|
-
|
|
182
|
-
When the user invokes \`/${templateSlash(template.id)} <name>\`:
|
|
183
|
-
|
|
184
|
-
1. **Generate a plan (no writes yet):**
|
|
185
|
-
\`\`\`bash
|
|
186
|
-
shrk gen ${template.id} <name> --dry-run --save-plan /tmp/${templateSlash(template.id)}.plan.json
|
|
187
|
-
\`\`\`
|
|
188
|
-
|
|
189
|
-
2. **Read the plan back** from \`/tmp/${templateSlash(template.id)}.plan.json\` and show the user which files will be created.
|
|
190
|
-
|
|
191
|
-
3. **Confirm.** Wait for the user to approve. If they want changes, adjust the plan or re-run \`shrk gen\` with different flags.
|
|
192
|
-
|
|
193
|
-
4. **Apply through the validated CLI path:**
|
|
194
|
-
\`\`\`bash
|
|
195
|
-
shrk apply /tmp/${templateSlash(template.id)}.plan.json --verify-signature --validate
|
|
196
|
-
\`\`\`
|
|
197
|
-
|
|
198
|
-
5. **Verify** the diff didn't break any boundary rules:
|
|
199
|
-
\`\`\`bash
|
|
200
|
-
shrk check boundaries --changed-only
|
|
201
|
-
\`\`\`
|
|
202
|
-
|
|
203
|
-
## If the template doesn't fit
|
|
204
|
-
|
|
205
|
-
If the user's request doesn't match the \`${template.id}\` template
|
|
206
|
-
shape, fall back to:
|
|
207
|
-
|
|
208
|
-
- \`shrk templates list\` — see all available templates.
|
|
209
|
-
- \`shrk gen <other-template> <name> --dry-run\` — try a different template.
|
|
210
|
-
- Hand-author only as last resort, and run \`/check-changes\` after.
|
|
211
|
-
|
|
212
|
-
The whole point of using the template is consistency with the rest of
|
|
213
|
-
this codebase. Skipping it means the new code will look different from
|
|
214
|
-
what's already there.
|
|
215
|
-
`;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Build the full set of `.claude/commands/*.md` files for a project.
|
|
219
|
-
*
|
|
220
|
-
* Pure — caller writes the bytes. Same shape as the `synthesize-*`
|
|
221
|
-
* functions in this codebase: input inspection → output file list.
|
|
222
|
-
*/
|
|
223
|
-
export function buildClaudeCommands(inspection, options = {}) {
|
|
224
|
-
const files = [];
|
|
225
|
-
files.push({
|
|
226
|
-
path: '.claude/commands/follow-shrk.md',
|
|
227
|
-
slash: 'follow-shrk',
|
|
228
|
-
source: 'static',
|
|
229
|
-
content: STATIC_FOLLOW_SHRK,
|
|
230
|
-
});
|
|
231
|
-
files.push({
|
|
232
|
-
path: '.claude/commands/check-changes.md',
|
|
233
|
-
slash: 'check-changes',
|
|
234
|
-
source: 'static',
|
|
235
|
-
content: STATIC_CHECK_CHANGES,
|
|
236
|
-
});
|
|
237
|
-
files.push({
|
|
238
|
-
path: '.claude/commands/shrk-brief.md',
|
|
239
|
-
slash: 'shrk-brief',
|
|
240
|
-
source: 'static',
|
|
241
|
-
content: STATIC_SHRK_BRIEF,
|
|
242
|
-
});
|
|
243
|
-
files.push({
|
|
244
|
-
path: '.claude/commands/explain-file.md',
|
|
245
|
-
slash: 'explain-file',
|
|
246
|
-
source: 'static',
|
|
247
|
-
content: STATIC_EXPLAIN_FILE,
|
|
248
|
-
});
|
|
249
|
-
// Per-template commands — bounded so a pack with 50 templates
|
|
250
|
-
// doesn't dump 50 slash commands into the user's palette. Sorted
|
|
251
|
-
// by id for deterministic emit order.
|
|
252
|
-
const cap = options.maxTemplateCommands ?? 20;
|
|
253
|
-
const templates = [...inspection.templates].sort((a, b) => a.id.localeCompare(b.id));
|
|
254
|
-
const seenSlash = new Set(files.map((f) => f.slash));
|
|
255
|
-
for (const t of templates) {
|
|
256
|
-
if (files.filter((f) => f.source === 'template').length >= cap)
|
|
257
|
-
break;
|
|
258
|
-
let slash = templateSlash(t.id);
|
|
259
|
-
if (seenSlash.has(slash)) {
|
|
260
|
-
// Two templates with the same tail (e.g. `ts.service` and
|
|
261
|
-
// `py.service` both → `new-service`) — fall back to the full id
|
|
262
|
-
// to disambiguate the second one.
|
|
263
|
-
slash = `new-${t.id.replace(/\./g, '-').toLowerCase()}`;
|
|
264
|
-
if (seenSlash.has(slash))
|
|
265
|
-
continue;
|
|
266
|
-
}
|
|
267
|
-
seenSlash.add(slash);
|
|
268
|
-
files.push({
|
|
269
|
-
path: `.claude/commands/${slash}.md`,
|
|
270
|
-
slash,
|
|
271
|
-
source: 'template',
|
|
272
|
-
content: templateCommandBody(t),
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
return { files };
|
|
276
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export interface IPathsAdvisory {
|
|
2
|
-
missingPaths: readonly string[];
|
|
3
|
-
existingPaths: readonly string[];
|
|
4
|
-
/** True when an advisory comment was prepended to the file. */
|
|
5
|
-
annotated: boolean;
|
|
6
|
-
pathsFile: string;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Scan the generated `sharkcraft/paths.ts` for `path: '<x>'` references
|
|
10
|
-
* and check each `<x>` against the live workspace. When any path is
|
|
11
|
-
* missing, prepend a clearly-labeled comment block listing the missing
|
|
12
|
-
* paths so the user knows which defaults to adjust.
|
|
13
|
-
*
|
|
14
|
-
* Idempotent — if the file already starts with the advisory marker,
|
|
15
|
-
* it is left untouched. Non-destructive — never edits, comments, or
|
|
16
|
-
* removes the original entries. The user is expected to revise them
|
|
17
|
-
* based on the advisory + `shrk onboard --dry-run` output.
|
|
18
|
-
*/
|
|
19
|
-
export declare function annotatePathsAgainstDisk(cwd: string, sharkcraftDir: string): IPathsAdvisory;
|
|
20
|
-
//# sourceMappingURL=paths-advisory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paths-advisory.d.ts","sourceRoot":"","sources":["../../src/init/paths-advisory.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,+DAA+D;IAC/D,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,MAAM,GACpB,cAAc,CAwChB"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import * as nodePath from 'node:path';
|
|
3
|
-
const ADVISORY_MARKER = '// ⚠️ Workspace-shape advisory (added by `shrk init`):';
|
|
4
|
-
/**
|
|
5
|
-
* Scan the generated `sharkcraft/paths.ts` for `path: '<x>'` references
|
|
6
|
-
* and check each `<x>` against the live workspace. When any path is
|
|
7
|
-
* missing, prepend a clearly-labeled comment block listing the missing
|
|
8
|
-
* paths so the user knows which defaults to adjust.
|
|
9
|
-
*
|
|
10
|
-
* Idempotent — if the file already starts with the advisory marker,
|
|
11
|
-
* it is left untouched. Non-destructive — never edits, comments, or
|
|
12
|
-
* removes the original entries. The user is expected to revise them
|
|
13
|
-
* based on the advisory + `shrk onboard --dry-run` output.
|
|
14
|
-
*/
|
|
15
|
-
export function annotatePathsAgainstDisk(cwd, sharkcraftDir) {
|
|
16
|
-
const pathsFile = nodePath.join(sharkcraftDir, 'paths.ts');
|
|
17
|
-
if (!existsSync(pathsFile)) {
|
|
18
|
-
return { missingPaths: [], existingPaths: [], annotated: false, pathsFile };
|
|
19
|
-
}
|
|
20
|
-
const original = readFileSync(pathsFile, 'utf8');
|
|
21
|
-
if (original.startsWith(ADVISORY_MARKER)) {
|
|
22
|
-
// Already annotated. Re-derive sets for caller diagnostics.
|
|
23
|
-
return classifyOnly(cwd, pathsFile, original);
|
|
24
|
-
}
|
|
25
|
-
const { existing, missing } = classifyPathReferences(cwd, original);
|
|
26
|
-
if (missing.length === 0) {
|
|
27
|
-
return {
|
|
28
|
-
missingPaths: [],
|
|
29
|
-
existingPaths: existing,
|
|
30
|
-
annotated: false,
|
|
31
|
-
pathsFile,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
const lines = [
|
|
35
|
-
ADVISORY_MARKER,
|
|
36
|
-
'//',
|
|
37
|
-
'// The following paths referenced below do NOT exist in this repository:',
|
|
38
|
-
...missing.map((p) => `// - ${p}`),
|
|
39
|
-
'//',
|
|
40
|
-
'// They are conservative defaults from the chosen preset. Adjust them to',
|
|
41
|
-
'// match your actual layout. Run `shrk onboard --dry-run` to see what',
|
|
42
|
-
'// the inference engine detects from your workspace.',
|
|
43
|
-
'//',
|
|
44
|
-
'',
|
|
45
|
-
];
|
|
46
|
-
writeFileSync(pathsFile, lines.join('\n') + original, 'utf8');
|
|
47
|
-
return {
|
|
48
|
-
missingPaths: missing,
|
|
49
|
-
existingPaths: existing,
|
|
50
|
-
annotated: true,
|
|
51
|
-
pathsFile,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function classifyOnly(cwd, pathsFile, original) {
|
|
55
|
-
const { existing, missing } = classifyPathReferences(cwd, original);
|
|
56
|
-
return {
|
|
57
|
-
missingPaths: missing,
|
|
58
|
-
existingPaths: existing,
|
|
59
|
-
annotated: false,
|
|
60
|
-
pathsFile,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function classifyPathReferences(cwd, source) {
|
|
64
|
-
// Match `path: '<x>'` / `path: "<x>"`. Ignore obvious code-context
|
|
65
|
-
// references (e.g. inside template literals); we only consume the
|
|
66
|
-
// first plain-string occurrence per entry.
|
|
67
|
-
const re = /\bpath\s*:\s*['"]([^'"\n]+)['"]/g;
|
|
68
|
-
const seen = new Set();
|
|
69
|
-
let m;
|
|
70
|
-
while ((m = re.exec(source)) !== null) {
|
|
71
|
-
if (m[1])
|
|
72
|
-
seen.add(m[1]);
|
|
73
|
-
}
|
|
74
|
-
const existing = [];
|
|
75
|
-
const missing = [];
|
|
76
|
-
for (const p of [...seen].sort()) {
|
|
77
|
-
if (isReachable(cwd, p))
|
|
78
|
-
existing.push(p);
|
|
79
|
-
else
|
|
80
|
-
missing.push(p);
|
|
81
|
-
}
|
|
82
|
-
return { existing, missing };
|
|
83
|
-
}
|
|
84
|
-
function isReachable(cwd, p) {
|
|
85
|
-
// Absolute or rooted-relative — resolve as-is.
|
|
86
|
-
const full = nodePath.isAbsolute(p) ? p : nodePath.resolve(cwd, p);
|
|
87
|
-
return existsSync(full);
|
|
88
|
-
}
|