@bastani/atomic 0.9.0-alpha.3 → 0.9.0-alpha.4
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 +15 -0
- package/dist/builtin/cursor/package.json +2 -2
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +17 -0
- package/dist/builtin/workflows/README.md +12 -12
- package/dist/builtin/workflows/builtin/goal-prompts.ts +8 -0
- package/dist/builtin/workflows/builtin/goal-runner.ts +96 -1
- package/dist/builtin/workflows/builtin/goal-types.ts +2 -0
- package/dist/builtin/workflows/builtin/goal.d.ts +3 -0
- package/dist/builtin/workflows/builtin/goal.ts +12 -1
- package/dist/builtin/workflows/builtin/index.d.ts +8 -8
- package/dist/builtin/workflows/builtin/open-claude-design-feedback.ts +359 -0
- package/dist/builtin/workflows/builtin/open-claude-design-phases.ts +254 -352
- package/dist/builtin/workflows/builtin/open-claude-design-runner.ts +256 -414
- package/dist/builtin/workflows/builtin/open-claude-design-setup.ts +272 -0
- package/dist/builtin/workflows/builtin/open-claude-design-utils.ts +58 -68
- package/dist/builtin/workflows/builtin/open-claude-design.d.ts +5 -9
- package/dist/builtin/workflows/builtin/open-claude-design.ts +14 -26
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/skills/impeccable/SKILL.md +14 -23
- package/dist/builtin/workflows/skills/impeccable/reference/brand.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/live.md +25 -4
- package/dist/builtin/workflows/skills/impeccable/scripts/context-signals.mjs +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/context.mjs +724 -29
- package/dist/builtin/workflows/skills/impeccable/scripts/critique-storage.mjs +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/browser/injected/index.mjs +219 -7
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/cli/main.mjs +57 -11
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/design-system.mjs +750 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/detect-antipatterns-browser.js +648 -53
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/detect-antipatterns.mjs +7 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/browser/detect-url.mjs +29 -4
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/regex/detect-text.mjs +44 -11
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/static-html/css-cascade.mjs +29 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/static-html/detect-html.mjs +27 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/node/file-system.mjs +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/registry/antipatterns.mjs +29 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/rules/checks.mjs +401 -46
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/inline-ignores.mjs +148 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/page.mjs +6 -6
- package/dist/builtin/workflows/skills/impeccable/scripts/{design-parser.mjs → lib/design-parser.mjs} +8 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-config.mjs +638 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-paths.mjs +128 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/{is-generated.mjs → lib/is-generated.mjs} +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/target-args.mjs +42 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/browser-script-parts.mjs +49 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/{live-completion.mjs → live/completion.mjs} +1 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/{live-event-validation.mjs → live/event-validation.mjs} +6 -5
- package/dist/builtin/workflows/skills/impeccable/scripts/live/manual-apply.mjs +939 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/manual-edit-routes.mjs +357 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/{live-manual-edits-buffer.mjs → live/manual-edits-buffer.mjs} +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/{live-session-store.mjs → live/session-store.mjs} +21 -3
- package/dist/builtin/workflows/skills/impeccable/scripts/live/svelte-component.mjs +835 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/sveltekit-adapter.mjs +274 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/ui-core.mjs +180 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/vocabulary.mjs +36 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-accept.mjs +185 -60
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-dom.js +146 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser.js +3369 -1026
- package/dist/builtin/workflows/skills/impeccable/scripts/live-commit-manual-edits.mjs +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/live-complete.mjs +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/live-discard-manual-edits.mjs +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/live-inject.mjs +133 -9
- package/dist/builtin/workflows/skills/impeccable/scripts/live-insert.mjs +42 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/live-manual-edit-evidence.mjs +4 -4
- package/dist/builtin/workflows/skills/impeccable/scripts/live-poll.mjs +21 -15
- package/dist/builtin/workflows/skills/impeccable/scripts/live-resume.mjs +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/live-server.mjs +205 -1269
- package/dist/builtin/workflows/skills/impeccable/scripts/live-status.mjs +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/live-target.mjs +30 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-wrap.mjs +69 -26
- package/dist/builtin/workflows/skills/impeccable/scripts/live.mjs +73 -22
- package/dist/core/atomic-guide-command.d.ts.map +1 -1
- package/dist/core/atomic-guide-command.js +5 -5
- package/dist/core/atomic-guide-command.js.map +1 -1
- package/docs/index.md +2 -2
- package/docs/quickstart.md +9 -9
- package/docs/workflows.md +42 -23
- package/package.json +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/cleanup-deprecated.mjs +0 -284
- package/dist/builtin/workflows/skills/impeccable/scripts/impeccable-paths.mjs +0 -126
- /package/dist/builtin/workflows/skills/impeccable/scripts/{live-insert-ui.mjs → live/insert-ui.mjs} +0 -0
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
* init flow.
|
|
6
6
|
*
|
|
7
7
|
* Path resolution (first match wins):
|
|
8
|
-
* 1.
|
|
9
|
-
* 2. .agents/context/ then docs/
|
|
10
|
-
* 3.
|
|
8
|
+
* 1. Active project root, if PRODUCT.md or DESIGN.md is there
|
|
9
|
+
* 2. Active project .agents/context/ then docs/
|
|
10
|
+
* 3. Monorepo root context, using the same order, as a per-file fallback
|
|
11
|
+
* 4. $IMPECCABLE_CONTEXT_DIR (absolute or cwd-relative) — power-user
|
|
11
12
|
* escape hatch, only consulted when defaults are empty
|
|
12
|
-
*
|
|
13
|
+
* 5. Active project root as a "nothing found" default
|
|
13
14
|
*
|
|
14
15
|
* `resolveContextDir()` and `loadContext()` are also exported for the
|
|
15
16
|
* server-side scripts (live.mjs, live-server.mjs) that need the structured
|
|
@@ -19,15 +20,30 @@ import fs from 'node:fs';
|
|
|
19
20
|
import os from 'node:os';
|
|
20
21
|
import path from 'node:path';
|
|
21
22
|
import { fileURLToPath } from 'node:url';
|
|
23
|
+
import { parseTargetOptions } from './lib/target-args.mjs';
|
|
22
24
|
|
|
23
25
|
const PRODUCT_NAMES = ['PRODUCT.md', 'Product.md', 'product.md'];
|
|
24
26
|
const DESIGN_NAMES = ['DESIGN.md', 'Design.md', 'design.md'];
|
|
25
27
|
const FALLBACK_DIRS = ['.agents/context', 'docs'];
|
|
28
|
+
const MONOREPO_MARKER_FILES = ['pnpm-workspace.yaml', 'turbo.json', 'nx.json', 'lerna.json'];
|
|
29
|
+
const MONOREPO_FALLBACK_PROJECT_DIRS = ['apps', 'packages'];
|
|
30
|
+
const WORKSPACE_DISCOVERY_IGNORED_DIRS = new Set([
|
|
31
|
+
'node_modules',
|
|
32
|
+
'.git',
|
|
33
|
+
'dist',
|
|
34
|
+
'build',
|
|
35
|
+
'.next',
|
|
36
|
+
'.nuxt',
|
|
37
|
+
'.svelte-kit',
|
|
38
|
+
'.turbo',
|
|
39
|
+
'.cache',
|
|
40
|
+
'coverage',
|
|
41
|
+
]);
|
|
26
42
|
|
|
27
43
|
// ─── Update check ──────────────────────────────────────────────────────────
|
|
28
44
|
// Piggyback a lightweight skill-version check on the once-per-session boot.
|
|
29
45
|
// When a newer skill ships, append an UPDATE_AVAILABLE directive so the agent
|
|
30
|
-
// can offer `npx impeccable
|
|
46
|
+
// can offer `npx impeccable update`. Everything here is best-effort and
|
|
31
47
|
// silent on failure: a network problem, sandbox, or missing cache must never
|
|
32
48
|
// block context output or print an error.
|
|
33
49
|
|
|
@@ -38,41 +54,623 @@ const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000; // throttle the network poll to o
|
|
|
38
54
|
const RENOTIFY_INTERVAL_MS = 7 * 24 * 60 * 60 * 1000; // don't re-surface the same version for a week
|
|
39
55
|
const FETCH_TIMEOUT_MS = 1200;
|
|
40
56
|
|
|
41
|
-
export function resolveContextDir(cwd = process.cwd()) {
|
|
42
|
-
|
|
43
|
-
|
|
57
|
+
export function resolveContextDir(cwd = process.cwd(), options = {}) {
|
|
58
|
+
return resolveContext(cwd, options).contextDir;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function loadContext(cwd = process.cwd(), options = {}) {
|
|
62
|
+
const resolved = resolveContext(cwd, options);
|
|
63
|
+
const absCwd = path.resolve(cwd);
|
|
64
|
+
const productPath = resolved.productPath;
|
|
65
|
+
const designPath = resolved.designPath;
|
|
66
|
+
const product = productPath ? safeRead(productPath) : null;
|
|
67
|
+
const design = designPath ? safeRead(designPath) : null;
|
|
68
|
+
return {
|
|
69
|
+
hasProduct: !!product,
|
|
70
|
+
product,
|
|
71
|
+
productPath: productPath ? path.relative(absCwd, productPath) : null,
|
|
72
|
+
hasDesign: !!design,
|
|
73
|
+
design,
|
|
74
|
+
designPath: designPath ? path.relative(absCwd, designPath) : null,
|
|
75
|
+
contextDir: resolved.contextDir,
|
|
76
|
+
productContextDir: productPath ? path.dirname(productPath) : null,
|
|
77
|
+
designContextDir: designPath ? path.dirname(designPath) : null,
|
|
78
|
+
projectRoot: resolved.projectRoot,
|
|
79
|
+
repoRoot: resolved.repoRoot,
|
|
80
|
+
isMonorepo: resolved.isMonorepo,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function resolveContext(cwd = process.cwd(), options = {}) {
|
|
85
|
+
const absCwd = path.resolve(cwd);
|
|
86
|
+
const project = resolveProject(absCwd, options);
|
|
87
|
+
const projectContextDir = resolveLocalContextDir(project.projectRoot);
|
|
88
|
+
const rootContextDir = project.isMonorepo && project.repoRoot !== project.projectRoot
|
|
89
|
+
? resolveLocalContextDir(project.repoRoot)
|
|
90
|
+
: null;
|
|
91
|
+
|
|
92
|
+
let productPath =
|
|
93
|
+
(projectContextDir ? firstExisting(projectContextDir, PRODUCT_NAMES) : null)
|
|
94
|
+
|| (rootContextDir ? firstExisting(rootContextDir, PRODUCT_NAMES) : null);
|
|
95
|
+
let designPath =
|
|
96
|
+
(projectContextDir ? firstExisting(projectContextDir, DESIGN_NAMES) : null)
|
|
97
|
+
|| (rootContextDir ? firstExisting(rootContextDir, DESIGN_NAMES) : null);
|
|
98
|
+
|
|
99
|
+
let envContextDir = null;
|
|
100
|
+
if (!productPath && !designPath) {
|
|
101
|
+
envContextDir = resolveEnvContextDir(absCwd);
|
|
102
|
+
if (envContextDir) {
|
|
103
|
+
productPath = firstExisting(envContextDir, PRODUCT_NAMES);
|
|
104
|
+
designPath = firstExisting(envContextDir, DESIGN_NAMES);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
contextDir: productPath
|
|
110
|
+
? path.dirname(productPath)
|
|
111
|
+
: designPath
|
|
112
|
+
? path.dirname(designPath)
|
|
113
|
+
: envContextDir || project.projectRoot,
|
|
114
|
+
productPath,
|
|
115
|
+
designPath,
|
|
116
|
+
projectRoot: project.projectRoot,
|
|
117
|
+
repoRoot: project.repoRoot,
|
|
118
|
+
isMonorepo: project.isMonorepo,
|
|
119
|
+
targetDir: project.targetDir,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function resolveProjectRoot(cwd = process.cwd(), options = {}) {
|
|
124
|
+
return resolveProject(cwd, options).projectRoot;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function resolveTargetSelection(cwd = process.cwd(), options = {}) {
|
|
128
|
+
if (hasTargetOption(options)) return null;
|
|
129
|
+
const project = resolveProject(cwd);
|
|
130
|
+
if (
|
|
131
|
+
!project.isMonorepo
|
|
132
|
+
|| !project.projectRoot
|
|
133
|
+
|| !project.repoRoot
|
|
134
|
+
|| path.resolve(project.projectRoot) !== path.resolve(project.repoRoot)
|
|
135
|
+
) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const targetCandidates = discoverTargetCandidates(project.repoRoot);
|
|
139
|
+
// No discoverable child apps (e.g. `workspaces: ["."]`, a root-only workspace,
|
|
140
|
+
// or a marker file with no apps/packages children): there is nothing to choose,
|
|
141
|
+
// so treat the repo root as the active project rather than blocking on an empty
|
|
142
|
+
// selection prompt that the user cannot answer.
|
|
143
|
+
if (targetCandidates.length === 0) return null;
|
|
144
|
+
return {
|
|
145
|
+
targetPath: null,
|
|
146
|
+
projectRoot: project.projectRoot,
|
|
147
|
+
repoRoot: project.repoRoot,
|
|
148
|
+
targetCandidates,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function resolveProject(cwd = process.cwd(), options = {}) {
|
|
153
|
+
const absCwd = path.resolve(cwd);
|
|
154
|
+
const targetDir = resolveTargetDir(absCwd, options);
|
|
155
|
+
let repoRoot = findMonorepoRoot(targetDir);
|
|
156
|
+
if (!repoRoot && targetDir !== absCwd) {
|
|
157
|
+
const cwdRepoRoot = findMonorepoRoot(absCwd);
|
|
158
|
+
if (cwdRepoRoot && isPathInside(targetDir, cwdRepoRoot)) {
|
|
159
|
+
repoRoot = cwdRepoRoot;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (!repoRoot) {
|
|
163
|
+
return {
|
|
164
|
+
targetDir,
|
|
165
|
+
projectRoot: absCwd,
|
|
166
|
+
repoRoot: absCwd,
|
|
167
|
+
isMonorepo: false,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
targetDir,
|
|
172
|
+
projectRoot: resolveWorkspaceProjectRoot(repoRoot, targetDir) || repoRoot,
|
|
173
|
+
repoRoot,
|
|
174
|
+
isMonorepo: true,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function isPathInside(candidate, root) {
|
|
179
|
+
const rel = path.relative(root, candidate);
|
|
180
|
+
return !!rel && !rel.startsWith('..') && !path.isAbsolute(rel);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function resolveLocalContextDir(root) {
|
|
184
|
+
if (firstExisting(root, [...PRODUCT_NAMES, ...DESIGN_NAMES])) {
|
|
185
|
+
return root;
|
|
44
186
|
}
|
|
45
187
|
for (const rel of FALLBACK_DIRS) {
|
|
46
|
-
const candidate = path.resolve(
|
|
188
|
+
const candidate = path.resolve(root, rel);
|
|
47
189
|
if (firstExisting(candidate, [...PRODUCT_NAMES, ...DESIGN_NAMES])) {
|
|
48
190
|
return candidate;
|
|
49
191
|
}
|
|
50
192
|
}
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function resolveEnvContextDir(cwd) {
|
|
51
197
|
const envDir = process.env.IMPECCABLE_CONTEXT_DIR;
|
|
52
|
-
if (envDir
|
|
53
|
-
|
|
54
|
-
|
|
198
|
+
if (!envDir || !envDir.trim()) return null;
|
|
199
|
+
const trimmed = envDir.trim();
|
|
200
|
+
return path.isAbsolute(trimmed) ? trimmed : path.resolve(cwd, trimmed);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function resolveTargetDir(cwd, options = {}) {
|
|
204
|
+
const targetPath = options && typeof options === 'object' ? options.targetPath : null;
|
|
205
|
+
if (!targetPath || !String(targetPath).trim()) return cwd;
|
|
206
|
+
const abs = path.isAbsolute(targetPath) ? targetPath : path.resolve(cwd, targetPath);
|
|
207
|
+
try {
|
|
208
|
+
const stat = fs.statSync(abs);
|
|
209
|
+
return stat.isDirectory() ? abs : path.dirname(abs);
|
|
210
|
+
} catch {
|
|
211
|
+
return path.extname(abs) ? path.dirname(abs) : abs;
|
|
55
212
|
}
|
|
56
|
-
return cwd;
|
|
57
213
|
}
|
|
58
214
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
215
|
+
function findMonorepoRoot(startDir) {
|
|
216
|
+
let dir = path.resolve(startDir);
|
|
217
|
+
const homeDir = path.resolve(os.homedir());
|
|
218
|
+
while (true) {
|
|
219
|
+
if (dir === homeDir) return null;
|
|
220
|
+
// isMonorepoRoot is checked before hasGitBoundary on purpose: a workspace
|
|
221
|
+
// root that also carries its own .git is still recognized. The trade-off is
|
|
222
|
+
// deliberate — a directory with a monorepo *marker* but no workspace patterns
|
|
223
|
+
// and no apps/packages children is not a monorepo root, so its .git stops
|
|
224
|
+
// traversal and a further-up root is not searched. The nested .git is treated
|
|
225
|
+
// as an independent project boundary, which is the intended isolation.
|
|
226
|
+
if (isMonorepoRoot(dir)) return dir;
|
|
227
|
+
if (hasGitBoundary(dir)) return null;
|
|
228
|
+
const parent = path.dirname(dir);
|
|
229
|
+
if (parent === dir) return null;
|
|
230
|
+
dir = parent;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function isMonorepoRoot(dir) {
|
|
235
|
+
if (readWorkspacePatterns(dir).some((pattern) => !normalizeWorkspacePattern(pattern).startsWith('!'))) return true;
|
|
236
|
+
if (!MONOREPO_MARKER_FILES.some((file) => fs.existsSync(path.join(dir, file)))) return false;
|
|
237
|
+
return hasFallbackWorkspaceChildren(dir);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function hasGitBoundary(dir) {
|
|
241
|
+
return fs.existsSync(path.join(dir, '.git'));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function hasFallbackWorkspaceChildren(dir) {
|
|
245
|
+
for (const name of MONOREPO_FALLBACK_PROJECT_DIRS) {
|
|
246
|
+
const base = path.join(dir, name);
|
|
247
|
+
let entries;
|
|
248
|
+
try {
|
|
249
|
+
entries = fs.readdirSync(base, { withFileTypes: true });
|
|
250
|
+
} catch {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (entries.some((entry) => entry.isDirectory() && !isIgnoredWorkspaceDiscoveryDir(entry.name))) return true;
|
|
254
|
+
}
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function discoverTargetCandidates(repoRoot) {
|
|
259
|
+
const roots = new Map();
|
|
260
|
+
const patterns = readWorkspacePatterns(repoRoot);
|
|
261
|
+
for (const pattern of patterns) {
|
|
262
|
+
for (const root of discoverRootsForPattern(repoRoot, pattern)) {
|
|
263
|
+
roots.set(path.relative(repoRoot, root).split(path.sep).join('/'), root);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (MONOREPO_MARKER_FILES.some((file) => fs.existsSync(path.join(repoRoot, file)))) {
|
|
267
|
+
for (const name of MONOREPO_FALLBACK_PROJECT_DIRS) {
|
|
268
|
+
const base = path.join(repoRoot, name);
|
|
269
|
+
let entries;
|
|
270
|
+
try {
|
|
271
|
+
entries = fs.readdirSync(base, { withFileTypes: true });
|
|
272
|
+
} catch {
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
for (const entry of entries) {
|
|
276
|
+
if (!entry.isDirectory() || isIgnoredWorkspaceDiscoveryDir(entry.name)) continue;
|
|
277
|
+
const root = path.join(base, entry.name);
|
|
278
|
+
roots.set(path.relative(repoRoot, root).split(path.sep).join('/'), root);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return [...roots.entries()]
|
|
283
|
+
.filter(([rel]) => rel && !rel.startsWith('..'))
|
|
284
|
+
// Honor negated workspace patterns (e.g. "!packages/internal"). resolveWorkspaceProjectRoot
|
|
285
|
+
// sends an excluded package back to the repo root, so an excluded folder must not appear as a
|
|
286
|
+
// selectable target — choosing it would silently resolve to the root instead.
|
|
287
|
+
.filter(([rel]) => !isExcludedByWorkspacePattern(rel.split('/').filter(Boolean), patterns))
|
|
288
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
289
|
+
.map(([rel, root]) => {
|
|
290
|
+
const targetExample = findTargetExample(repoRoot, root);
|
|
291
|
+
return {
|
|
292
|
+
name: path.basename(root),
|
|
293
|
+
path: rel,
|
|
294
|
+
targetExample,
|
|
295
|
+
...resolveCandidateContextSummary(repoRoot, root, targetExample),
|
|
296
|
+
};
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function resolveCandidateContextSummary(repoRoot, projectRoot, targetPath) {
|
|
301
|
+
const ctx = resolveContext(repoRoot, { targetPath });
|
|
65
302
|
return {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
design,
|
|
71
|
-
designPath: designPath ? path.relative(cwd, designPath) : null,
|
|
72
|
-
contextDir,
|
|
303
|
+
productStatus: contextSourceStatus(ctx.productPath, repoRoot, projectRoot),
|
|
304
|
+
productPath: contextSourcePath(ctx.productPath, repoRoot),
|
|
305
|
+
designStatus: contextSourceStatus(ctx.designPath, repoRoot, projectRoot),
|
|
306
|
+
designPath: contextSourcePath(ctx.designPath, repoRoot),
|
|
73
307
|
};
|
|
74
308
|
}
|
|
75
309
|
|
|
310
|
+
// Selection candidates surface one of four statuses: 'child' (a canonical
|
|
311
|
+
// PRODUCT.md/DESIGN.md directly in the app root), 'inherited' (resolved from the
|
|
312
|
+
// repo root in a monorepo), 'missing' (no file found), and 'fallback'. 'fallback'
|
|
313
|
+
// intentionally covers two non-canonical locations: a file inside the project
|
|
314
|
+
// root but in a subdirectory (FALLBACK_DIRS, e.g. `.agents/context/`), and a file
|
|
315
|
+
// outside both the project and repo roots (IMPECCABLE_CONTEXT_DIR override).
|
|
316
|
+
function contextSourceStatus(filePath, repoRoot, projectRoot) {
|
|
317
|
+
if (!filePath) return 'missing';
|
|
318
|
+
const absPath = path.resolve(filePath);
|
|
319
|
+
const absProjectRoot = path.resolve(projectRoot);
|
|
320
|
+
const absRepoRoot = path.resolve(repoRoot);
|
|
321
|
+
if (isPathInsideOrEqual(absPath, absProjectRoot)) {
|
|
322
|
+
return path.dirname(absPath) === absProjectRoot ? 'child' : 'fallback';
|
|
323
|
+
}
|
|
324
|
+
if (absProjectRoot !== absRepoRoot && isPathInsideOrEqual(absPath, absRepoRoot)) {
|
|
325
|
+
return 'inherited';
|
|
326
|
+
}
|
|
327
|
+
return 'fallback';
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function contextSourcePath(filePath, repoRoot) {
|
|
331
|
+
if (!filePath) return null;
|
|
332
|
+
const rel = path.relative(repoRoot, filePath);
|
|
333
|
+
if (rel && !rel.startsWith('..') && !path.isAbsolute(rel)) {
|
|
334
|
+
return rel.split(path.sep).join('/');
|
|
335
|
+
}
|
|
336
|
+
return filePath;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function discoverRootsForPattern(repoRoot, rawPattern) {
|
|
340
|
+
const pattern = normalizeWorkspacePattern(rawPattern);
|
|
341
|
+
if (!pattern || pattern.startsWith('!')) return [];
|
|
342
|
+
const segments = pattern.split('/').filter(Boolean);
|
|
343
|
+
if (!segments.length) return [];
|
|
344
|
+
const firstGlobIndex = segments.findIndex((segment) => segment.includes('*'));
|
|
345
|
+
const literalPrefix = firstGlobIndex === -1 ? segments : segments.slice(0, firstGlobIndex);
|
|
346
|
+
const base = path.join(repoRoot, ...literalPrefix);
|
|
347
|
+
if (!fs.existsSync(base)) return [];
|
|
348
|
+
if (segments.includes('**')) {
|
|
349
|
+
const packageRoots = [];
|
|
350
|
+
walkDirs(base, (dir) => {
|
|
351
|
+
if (dir !== base && isCandidateProjectRoot(dir)) packageRoots.push(dir);
|
|
352
|
+
});
|
|
353
|
+
if (packageRoots.length) return packageRoots;
|
|
354
|
+
return directChildDirs(base);
|
|
355
|
+
}
|
|
356
|
+
return expandSimplePattern(repoRoot, segments);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function expandSimplePattern(repoRoot, patternSegments, index = 0, current = repoRoot) {
|
|
360
|
+
if (index >= patternSegments.length) return fs.existsSync(current) ? [current] : [];
|
|
361
|
+
const segment = patternSegments[index];
|
|
362
|
+
if (!segment.includes('*')) {
|
|
363
|
+
return expandSimplePattern(repoRoot, patternSegments, index + 1, path.join(current, segment));
|
|
364
|
+
}
|
|
365
|
+
let entries;
|
|
366
|
+
try {
|
|
367
|
+
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
368
|
+
} catch {
|
|
369
|
+
return [];
|
|
370
|
+
}
|
|
371
|
+
const roots = [];
|
|
372
|
+
for (const entry of entries) {
|
|
373
|
+
if (!entry.isDirectory() || isIgnoredWorkspaceDiscoveryDir(entry.name)) continue;
|
|
374
|
+
if (!segmentMatches(segment, entry.name)) continue;
|
|
375
|
+
roots.push(...expandSimplePattern(repoRoot, patternSegments, index + 1, path.join(current, entry.name)));
|
|
376
|
+
}
|
|
377
|
+
return roots;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function directChildDirs(dir) {
|
|
381
|
+
try {
|
|
382
|
+
return fs.readdirSync(dir, { withFileTypes: true })
|
|
383
|
+
.filter((entry) => entry.isDirectory() && !isIgnoredWorkspaceDiscoveryDir(entry.name))
|
|
384
|
+
.map((entry) => path.join(dir, entry.name));
|
|
385
|
+
} catch {
|
|
386
|
+
return [];
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function walkDirs(root, visit) {
|
|
391
|
+
let entries;
|
|
392
|
+
try {
|
|
393
|
+
entries = fs.readdirSync(root, { withFileTypes: true });
|
|
394
|
+
} catch {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
for (const entry of entries) {
|
|
398
|
+
if (!entry.isDirectory() || isIgnoredWorkspaceDiscoveryDir(entry.name)) continue;
|
|
399
|
+
const dir = path.join(root, entry.name);
|
|
400
|
+
visit(dir);
|
|
401
|
+
walkDirs(dir, visit);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function isCandidateProjectRoot(dir) {
|
|
406
|
+
return !!(
|
|
407
|
+
fs.existsSync(path.join(dir, 'package.json'))
|
|
408
|
+
|| firstExisting(dir, [...PRODUCT_NAMES, ...DESIGN_NAMES])
|
|
409
|
+
|| fs.existsSync(path.join(dir, 'src'))
|
|
410
|
+
|| fs.existsSync(path.join(dir, 'app'))
|
|
411
|
+
|| fs.existsSync(path.join(dir, 'pages'))
|
|
412
|
+
|| fs.existsSync(path.join(dir, 'public'))
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function isIgnoredWorkspaceDiscoveryDir(name) {
|
|
417
|
+
return name.startsWith('.') || WORKSPACE_DISCOVERY_IGNORED_DIRS.has(name);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function findTargetExample(repoRoot, projectRoot) {
|
|
421
|
+
const examples = [
|
|
422
|
+
'src/App.jsx',
|
|
423
|
+
'src/App.tsx',
|
|
424
|
+
'src/main.jsx',
|
|
425
|
+
'src/main.tsx',
|
|
426
|
+
'src/index.jsx',
|
|
427
|
+
'src/index.ts',
|
|
428
|
+
'app/page.tsx',
|
|
429
|
+
'pages/index.tsx',
|
|
430
|
+
'public/index.html',
|
|
431
|
+
];
|
|
432
|
+
for (const rel of examples) {
|
|
433
|
+
const abs = path.join(projectRoot, rel);
|
|
434
|
+
if (fs.existsSync(abs)) return path.relative(repoRoot, abs).split(path.sep).join('/');
|
|
435
|
+
}
|
|
436
|
+
return path.relative(repoRoot, projectRoot).split(path.sep).join('/');
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function resolveWorkspaceProjectRoot(repoRoot, targetDir) {
|
|
440
|
+
const rel = path.relative(repoRoot, targetDir);
|
|
441
|
+
if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return repoRoot;
|
|
442
|
+
const relSegments = rel.split(path.sep).filter(Boolean);
|
|
443
|
+
const patterns = readWorkspacePatterns(repoRoot);
|
|
444
|
+
const excluded = isExcludedByWorkspacePattern(relSegments, patterns);
|
|
445
|
+
if (!excluded) {
|
|
446
|
+
for (const pattern of patterns) {
|
|
447
|
+
const projectRoot = projectRootFromWorkspacePattern(repoRoot, relSegments, pattern);
|
|
448
|
+
if (projectRoot) return projectRoot;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if (excluded) return repoRoot;
|
|
452
|
+
if (
|
|
453
|
+
relSegments.length >= 2
|
|
454
|
+
&& MONOREPO_FALLBACK_PROJECT_DIRS.includes(relSegments[0])
|
|
455
|
+
) {
|
|
456
|
+
return path.join(repoRoot, relSegments[0], relSegments[1]);
|
|
457
|
+
}
|
|
458
|
+
const nearest = nearestProjectLikeRoot(repoRoot, targetDir);
|
|
459
|
+
if (nearest) return nearest;
|
|
460
|
+
return repoRoot;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function isExcludedByWorkspacePattern(relSegments, patterns) {
|
|
464
|
+
return patterns.some((rawPattern) => {
|
|
465
|
+
const pattern = normalizeWorkspacePattern(rawPattern);
|
|
466
|
+
if (!pattern.startsWith('!')) return false;
|
|
467
|
+
return workspacePatternMatchesRel(pattern.slice(1), relSegments);
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function nearestProjectLikeRoot(repoRoot, targetDir) {
|
|
472
|
+
let dir = path.resolve(targetDir);
|
|
473
|
+
const stop = path.resolve(repoRoot);
|
|
474
|
+
while (dir && dir !== stop) {
|
|
475
|
+
if (
|
|
476
|
+
firstExisting(dir, [...PRODUCT_NAMES, ...DESIGN_NAMES])
|
|
477
|
+
|| fs.existsSync(path.join(dir, 'package.json'))
|
|
478
|
+
) {
|
|
479
|
+
return dir;
|
|
480
|
+
}
|
|
481
|
+
const parent = path.dirname(dir);
|
|
482
|
+
if (parent === dir) break;
|
|
483
|
+
dir = parent;
|
|
484
|
+
}
|
|
485
|
+
return null;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function nearestPackageRootBetween(repoRoot, targetDir, stopDir) {
|
|
489
|
+
let dir = path.resolve(targetDir);
|
|
490
|
+
const stop = path.resolve(stopDir || repoRoot);
|
|
491
|
+
const root = path.resolve(repoRoot);
|
|
492
|
+
while (dir && dir !== stop && isPathInsideOrEqual(dir, root)) {
|
|
493
|
+
if (fs.existsSync(path.join(dir, 'package.json'))) return dir;
|
|
494
|
+
const parent = path.dirname(dir);
|
|
495
|
+
if (parent === dir) break;
|
|
496
|
+
dir = parent;
|
|
497
|
+
}
|
|
498
|
+
return null;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function isPathInsideOrEqual(candidate, root) {
|
|
502
|
+
return path.resolve(candidate) === path.resolve(root) || isPathInside(candidate, root);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function workspacePatternMatchesRel(pattern, relSegments) {
|
|
506
|
+
const patternSegments = normalizeWorkspacePattern(pattern).split('/').filter(Boolean);
|
|
507
|
+
if (!patternSegments.length) return false;
|
|
508
|
+
if (patternSegments.includes('**')) {
|
|
509
|
+
const firstGlobIndex = patternSegments.findIndex((segment) => segment.includes('*'));
|
|
510
|
+
const literalPrefix = firstGlobIndex === -1
|
|
511
|
+
? patternSegments
|
|
512
|
+
: patternSegments.slice(0, firstGlobIndex);
|
|
513
|
+
if (relSegments.length < literalPrefix.length + 1) return false;
|
|
514
|
+
for (let i = 0; i < literalPrefix.length; i++) {
|
|
515
|
+
if (!segmentMatches(literalPrefix[i], relSegments[i])) return false;
|
|
516
|
+
}
|
|
517
|
+
return true;
|
|
518
|
+
}
|
|
519
|
+
if (relSegments.length < patternSegments.length) return false;
|
|
520
|
+
for (let i = 0; i < patternSegments.length; i++) {
|
|
521
|
+
if (!segmentMatches(patternSegments[i], relSegments[i])) return false;
|
|
522
|
+
}
|
|
523
|
+
return true;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function readWorkspacePatterns(repoRoot) {
|
|
527
|
+
return [
|
|
528
|
+
...readPackageWorkspaces(repoRoot),
|
|
529
|
+
...readPnpmWorkspaces(repoRoot),
|
|
530
|
+
...readLernaWorkspaces(repoRoot),
|
|
531
|
+
].filter(Boolean);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function readPackageWorkspaces(repoRoot) {
|
|
535
|
+
const pkg = readJson(path.join(repoRoot, 'package.json'));
|
|
536
|
+
const workspaces = pkg?.workspaces;
|
|
537
|
+
if (Array.isArray(workspaces)) return workspaces;
|
|
538
|
+
if (Array.isArray(workspaces?.packages)) return workspaces.packages;
|
|
539
|
+
return [];
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function readLernaWorkspaces(repoRoot) {
|
|
543
|
+
const lerna = readJson(path.join(repoRoot, 'lerna.json'));
|
|
544
|
+
return Array.isArray(lerna?.packages) ? lerna.packages : [];
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function readPnpmWorkspaces(repoRoot) {
|
|
548
|
+
try {
|
|
549
|
+
const body = fs.readFileSync(path.join(repoRoot, 'pnpm-workspace.yaml'), 'utf-8');
|
|
550
|
+
const patterns = [];
|
|
551
|
+
let inPackages = false;
|
|
552
|
+
for (const line of body.split(/\r?\n/)) {
|
|
553
|
+
const trimmed = stripYamlInlineComment(line).trim();
|
|
554
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
555
|
+
const flowMatch = trimmed.match(/^packages:\s*\[(.*)\]\s*$/);
|
|
556
|
+
if (flowMatch) {
|
|
557
|
+
patterns.push(...parseYamlFlowList(flowMatch[1]));
|
|
558
|
+
inPackages = false;
|
|
559
|
+
continue;
|
|
560
|
+
}
|
|
561
|
+
if (/^packages:\s*$/.test(trimmed)) {
|
|
562
|
+
inPackages = true;
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
if (inPackages && /^[A-Za-z0-9_-]+:\s*/.test(trimmed)) break;
|
|
566
|
+
if (inPackages) {
|
|
567
|
+
const match = trimmed.match(/^-\s*(.+)$/);
|
|
568
|
+
if (match) patterns.push(unquoteYamlValue(match[1]));
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
return patterns;
|
|
572
|
+
} catch {
|
|
573
|
+
return [];
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
function stripYamlInlineComment(line) {
|
|
578
|
+
let quote = null;
|
|
579
|
+
for (let i = 0; i < line.length; i++) {
|
|
580
|
+
const ch = line[i];
|
|
581
|
+
if ((ch === '"' || ch === "'") && line[i - 1] !== '\\') {
|
|
582
|
+
quote = quote === ch ? null : quote || ch;
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
if (ch === '#' && !quote) return line.slice(0, i);
|
|
586
|
+
}
|
|
587
|
+
return line;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function parseYamlFlowList(body) {
|
|
591
|
+
const items = [];
|
|
592
|
+
let quote = null;
|
|
593
|
+
let current = '';
|
|
594
|
+
for (let i = 0; i < body.length; i++) {
|
|
595
|
+
const ch = body[i];
|
|
596
|
+
if ((ch === '"' || ch === "'") && body[i - 1] !== '\\') {
|
|
597
|
+
quote = quote === ch ? null : quote || ch;
|
|
598
|
+
current += ch;
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
if (ch === ',' && !quote) {
|
|
602
|
+
const value = unquoteYamlValue(current);
|
|
603
|
+
if (value) items.push(value);
|
|
604
|
+
current = '';
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
current += ch;
|
|
608
|
+
}
|
|
609
|
+
const value = unquoteYamlValue(current);
|
|
610
|
+
if (value) items.push(value);
|
|
611
|
+
return items;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function unquoteYamlValue(value) {
|
|
615
|
+
return String(value || '')
|
|
616
|
+
.trim()
|
|
617
|
+
.replace(/^['"]|['"]$/g, '');
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function readJson(filePath) {
|
|
621
|
+
try {
|
|
622
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
623
|
+
} catch {
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
function projectRootFromWorkspacePattern(repoRoot, relSegments, rawPattern) {
|
|
629
|
+
const pattern = normalizeWorkspacePattern(rawPattern);
|
|
630
|
+
if (!pattern || pattern.startsWith('!')) return null;
|
|
631
|
+
const patternSegments = pattern.split('/').filter(Boolean);
|
|
632
|
+
if (!patternSegments.length) return null;
|
|
633
|
+
if (patternSegments.includes('**')) {
|
|
634
|
+
return projectRootFromDoubleStarPattern(repoRoot, relSegments, patternSegments);
|
|
635
|
+
}
|
|
636
|
+
if (relSegments.length < patternSegments.length) return null;
|
|
637
|
+
for (let i = 0; i < patternSegments.length; i++) {
|
|
638
|
+
if (!segmentMatches(patternSegments[i], relSegments[i])) return null;
|
|
639
|
+
}
|
|
640
|
+
return path.join(repoRoot, ...relSegments.slice(0, patternSegments.length));
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function projectRootFromDoubleStarPattern(repoRoot, relSegments, patternSegments) {
|
|
644
|
+
const firstGlobIndex = patternSegments.findIndex((segment) => segment.includes('*'));
|
|
645
|
+
const literalPrefix = firstGlobIndex === -1
|
|
646
|
+
? patternSegments
|
|
647
|
+
: patternSegments.slice(0, firstGlobIndex);
|
|
648
|
+
if (relSegments.length < literalPrefix.length + 1) return null;
|
|
649
|
+
for (let i = 0; i < literalPrefix.length; i++) {
|
|
650
|
+
if (!segmentMatches(literalPrefix[i], relSegments[i])) return null;
|
|
651
|
+
}
|
|
652
|
+
const prefixDir = path.join(repoRoot, ...literalPrefix);
|
|
653
|
+
const targetDir = path.join(repoRoot, ...relSegments);
|
|
654
|
+
const packageRoot = nearestPackageRootBetween(repoRoot, targetDir, prefixDir);
|
|
655
|
+
if (packageRoot) return packageRoot;
|
|
656
|
+
return path.join(repoRoot, ...relSegments.slice(0, literalPrefix.length + 1));
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
function normalizeWorkspacePattern(pattern) {
|
|
660
|
+
return String(pattern || '')
|
|
661
|
+
.trim()
|
|
662
|
+
.replace(/^['"]|['"]$/g, '')
|
|
663
|
+
.replace(/^\.\//, '')
|
|
664
|
+
.replace(/\/+$/, '');
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
function segmentMatches(patternSegment, relSegment) {
|
|
668
|
+
if (patternSegment === '*') return true;
|
|
669
|
+
if (!patternSegment.includes('*')) return patternSegment === relSegment;
|
|
670
|
+
const re = new RegExp(`^${escapeRegExp(patternSegment).replace(/\\\*/g, '[^/]*')}$`);
|
|
671
|
+
return re.test(relSegment);
|
|
672
|
+
}
|
|
673
|
+
|
|
76
674
|
function firstExisting(dir, names) {
|
|
77
675
|
for (const name of names) {
|
|
78
676
|
const abs = path.join(dir, name);
|
|
@@ -89,6 +687,10 @@ function safeRead(p) {
|
|
|
89
687
|
}
|
|
90
688
|
}
|
|
91
689
|
|
|
690
|
+
function escapeRegExp(value) {
|
|
691
|
+
return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
692
|
+
}
|
|
693
|
+
|
|
92
694
|
/**
|
|
93
695
|
* Pull the register (`brand` or `product`) out of PRODUCT.md by looking
|
|
94
696
|
* for a `## Register` section and reading the first non-empty line that
|
|
@@ -172,8 +774,8 @@ function buildUpdateDirective(localVersion, latestVersion) {
|
|
|
172
774
|
`UPDATE_AVAILABLE: A newer Impeccable skill is available ` +
|
|
173
775
|
`(installed v${localVersion}, latest v${latestVersion}). ` +
|
|
174
776
|
`Before continuing, ask the user once: "A newer Impeccable (v${latestVersion}) is available. ` +
|
|
175
|
-
`Update now? It runs \`npx impeccable
|
|
176
|
-
`If they agree, run \`npx impeccable
|
|
777
|
+
`Update now? It runs \`npx impeccable update\`." ` +
|
|
778
|
+
`If they agree, run \`npx impeccable update\` (the update applies to the next session, not this one). ` +
|
|
177
779
|
`Either way, continue the current task without waiting, and do not raise this again.`
|
|
178
780
|
);
|
|
179
781
|
}
|
|
@@ -184,9 +786,23 @@ function buildUpdateDirective(localVersion, latestVersion) {
|
|
|
184
786
|
* the user's home dir) and re-surfaces a given version at most once per week so
|
|
185
787
|
* the agent never nags. Opt out entirely with IMPECCABLE_NO_UPDATE_CHECK=1.
|
|
186
788
|
*/
|
|
789
|
+
// Read the unified config's top-level `updateCheck` (local overrides shared).
|
|
790
|
+
// Inlined rather than importing hook-lib so the boot path stays lightweight.
|
|
791
|
+
function updateCheckDisabledByConfig(cwd = process.cwd()) {
|
|
792
|
+
let value;
|
|
793
|
+
for (const name of ['config.json', 'config.local.json']) {
|
|
794
|
+
try {
|
|
795
|
+
const raw = JSON.parse(fs.readFileSync(path.join(cwd, '.impeccable', name), 'utf-8'));
|
|
796
|
+
if (raw && typeof raw === 'object' && typeof raw.updateCheck === 'boolean') value = raw.updateCheck;
|
|
797
|
+
} catch { /* missing or malformed: ignore */ }
|
|
798
|
+
}
|
|
799
|
+
return value === false;
|
|
800
|
+
}
|
|
801
|
+
|
|
187
802
|
async function computeUpdateDirective(now = Date.now()) {
|
|
188
803
|
try {
|
|
189
804
|
if (process.env.IMPECCABLE_NO_UPDATE_CHECK) return null;
|
|
805
|
+
if (updateCheckDisabledByConfig()) return null;
|
|
190
806
|
const localVersion = readLocalSkillVersion();
|
|
191
807
|
if (!localVersion) return null;
|
|
192
808
|
|
|
@@ -219,7 +835,24 @@ async function computeUpdateDirective(now = Date.now()) {
|
|
|
219
835
|
}
|
|
220
836
|
|
|
221
837
|
async function cli() {
|
|
222
|
-
|
|
838
|
+
let cliOptions;
|
|
839
|
+
try {
|
|
840
|
+
cliOptions = parseCliOptions(process.argv.slice(2));
|
|
841
|
+
} catch (err) {
|
|
842
|
+
if (err?.name === 'TargetArgError') {
|
|
843
|
+
process.stderr.write(`${err.message}\n`);
|
|
844
|
+
process.exit(1);
|
|
845
|
+
}
|
|
846
|
+
throw err;
|
|
847
|
+
}
|
|
848
|
+
const targetProvided = hasTargetOption(cliOptions);
|
|
849
|
+
const targetExists = targetProvided ? pathExistsForTarget(process.cwd(), cliOptions.targetPath) : null;
|
|
850
|
+
const selection = resolveTargetSelection(process.cwd(), cliOptions);
|
|
851
|
+
if (selection) {
|
|
852
|
+
process.stdout.write(buildTargetSelectionDirective(selection) + '\n');
|
|
853
|
+
process.exit(0);
|
|
854
|
+
}
|
|
855
|
+
const ctx = loadContext(process.cwd(), cliOptions);
|
|
223
856
|
const updateDirective = await computeUpdateDirective();
|
|
224
857
|
|
|
225
858
|
if (!ctx.hasProduct) {
|
|
@@ -230,6 +863,10 @@ async function cli() {
|
|
|
230
863
|
'Stop the current task, load reference/init.md, and follow its ' +
|
|
231
864
|
'instructions to write PRODUCT.md before resuming.',
|
|
232
865
|
];
|
|
866
|
+
parts.push(buildResolvedContextDirective(ctx, cliOptions, { targetExists }));
|
|
867
|
+
if (shouldWarnMissingTarget(ctx, targetProvided, targetExists)) {
|
|
868
|
+
parts.push(buildMissingTargetDirective());
|
|
869
|
+
}
|
|
233
870
|
if (updateDirective) parts.push(updateDirective);
|
|
234
871
|
process.stdout.write(parts.join('\n\n---\n\n') + '\n');
|
|
235
872
|
process.exit(0);
|
|
@@ -238,6 +875,10 @@ async function cli() {
|
|
|
238
875
|
if (ctx.hasDesign) {
|
|
239
876
|
parts.push(`# DESIGN.md\n\n${ctx.design.trim()}`);
|
|
240
877
|
}
|
|
878
|
+
parts.push(buildResolvedContextDirective(ctx, cliOptions, { targetExists }));
|
|
879
|
+
if (shouldWarnMissingTarget(ctx, targetProvided, targetExists)) {
|
|
880
|
+
parts.push(buildMissingTargetDirective());
|
|
881
|
+
}
|
|
241
882
|
const register = extractRegister(ctx.product);
|
|
242
883
|
const next = register
|
|
243
884
|
? `NEXT STEP: This project's register is \`${register}\`. You MUST now read \`reference/${register}.md\` before producing any design output.`
|
|
@@ -247,6 +888,60 @@ async function cli() {
|
|
|
247
888
|
process.stdout.write(parts.join('\n\n---\n\n') + '\n');
|
|
248
889
|
}
|
|
249
890
|
|
|
891
|
+
function parseCliOptions(args) {
|
|
892
|
+
return parseTargetOptions(args, { strict: true });
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
function hasTargetOption(options) {
|
|
896
|
+
return !!(options && typeof options.targetPath === 'string' && options.targetPath.trim());
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
function pathExistsForTarget(cwd, targetPath) {
|
|
900
|
+
const abs = path.isAbsolute(targetPath) ? targetPath : path.resolve(cwd, targetPath);
|
|
901
|
+
return fs.existsSync(abs);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
function buildResolvedContextDirective(ctx, options, { targetExists = null } = {}) {
|
|
905
|
+
const targetPath = hasTargetOption(options) ? options.targetPath : null;
|
|
906
|
+
return `RESOLVED_CONTEXT:\n${JSON.stringify({
|
|
907
|
+
targetPath,
|
|
908
|
+
...(targetPath ? { targetExists } : {}),
|
|
909
|
+
projectRoot: ctx.projectRoot,
|
|
910
|
+
repoRoot: ctx.repoRoot,
|
|
911
|
+
productPath: ctx.productPath,
|
|
912
|
+
designPath: ctx.designPath,
|
|
913
|
+
}, null, 2)}`;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
function shouldWarnMissingTarget(ctx, targetProvided, targetExists = null) {
|
|
917
|
+
if (ctx.isMonorepo && targetProvided && targetExists === false) return true;
|
|
918
|
+
return !!(
|
|
919
|
+
ctx.isMonorepo
|
|
920
|
+
&& (!targetProvided || targetExists === false)
|
|
921
|
+
&& ctx.projectRoot
|
|
922
|
+
&& ctx.repoRoot
|
|
923
|
+
&& path.resolve(ctx.projectRoot) === path.resolve(ctx.repoRoot)
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
function buildMissingTargetDirective() {
|
|
928
|
+
const script = process.argv[1] || 'context.mjs';
|
|
929
|
+
return (
|
|
930
|
+
'MONOREPO_TARGET_REQUIRED: This is a monorepo and context.mjs ran without --target. ' +
|
|
931
|
+
'If the user named a file, route, or child app, do not answer from this output. ' +
|
|
932
|
+
`Rerun \`node ${script} --target <path>\` and answer from that run's RESOLVED_CONTEXT fields.`
|
|
933
|
+
);
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
function buildTargetSelectionDirective(selection) {
|
|
937
|
+
return (
|
|
938
|
+
`TARGET_SELECTION_REQUIRED:\n${JSON.stringify(selection, null, 2)}\n\n` +
|
|
939
|
+
'Show each app with its productStatus/productPath and designStatus/designPath so the user can see child overrides, inherited root files, fallback files, or missing files before choosing. ' +
|
|
940
|
+
'Ask the user which app Impeccable should use, then rerun Impeccable helper commands from that child app cwd using this same scripts directory. ' +
|
|
941
|
+
'Use `--target <path>` only as a fallback when changing cwd is not possible, or when the user explicitly named a file/path.'
|
|
942
|
+
);
|
|
943
|
+
}
|
|
944
|
+
|
|
250
945
|
// Run cli() only when this module is the entry point. Compare realpaths
|
|
251
946
|
// rather than endsWith(): a loose suffix match also fires for unrelated
|
|
252
947
|
// scripts like `load-context.mjs`, and realpath tolerates symlinked
|