claudecode-omc 5.9.1 → 5.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.local/settings/settings.json +8 -0
- package/.omc-curation/governance.json +3 -0
- package/.omc-curation/sources.lock.json +5 -0
- package/README.md +10 -1
- package/bundled/manifest.json +2 -1
- package/bundled/upstream/impeccable/.omc-source/bundle.json +20 -0
- package/bundled/upstream/impeccable/.omc-source/provenance.json +105 -0
- package/bundled/upstream/impeccable/agents/impeccable-manual-edit-applier.md +97 -0
- package/bundled/upstream/impeccable/skills/impeccable/SKILL.md +168 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/adapt.md +311 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/animate.md +201 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/audit.md +133 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/bolder.md +113 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/brand.md +108 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/clarify.md +288 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/codex.md +105 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/colorize.md +257 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/craft.md +123 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/critique.md +767 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/delight.md +302 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/distill.md +111 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/document.md +429 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/extract.md +69 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/harden.md +347 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/hooks.md +88 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/init.md +172 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/interaction-design.md +189 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/layout.md +161 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/live.md +718 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/onboard.md +234 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/optimize.md +258 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/overdrive.md +130 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/polish.md +241 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/product.md +60 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/quieter.md +99 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/shape.md +165 -0
- package/bundled/upstream/impeccable/skills/impeccable/reference/typeset.md +279 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/command-metadata.json +94 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/context-signals.mjs +225 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/context.mjs +280 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/critique-storage.mjs +242 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detect-csp.mjs +198 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detect.mjs +21 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/browser/injected/index.mjs +1735 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/cli/main.mjs +244 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/detect-antipatterns-browser.js +4907 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/detect-antipatterns.mjs +43 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/engines/browser/detect-url.mjs +252 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/engines/regex/detect-text.mjs +552 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/engines/static-html/css-cascade.mjs +1013 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/engines/static-html/detect-html.mjs +208 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/engines/visual/screenshot-contrast.mjs +189 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/findings.mjs +12 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/node/file-system.mjs +198 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/profile/profiler.mjs +166 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/registry/antipatterns.mjs +419 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/rules/checks.mjs +2671 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/shared/color.mjs +124 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/shared/constants.mjs +101 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/detector/shared/page.mjs +7 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/hook-admin.mjs +574 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/hook-before-edit.mjs +473 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/hook-lib.mjs +1286 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/hook.mjs +61 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/lib/design-parser.mjs +835 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/lib/impeccable-paths.mjs +126 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/lib/is-generated.mjs +69 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live/browser-script-parts.mjs +49 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live/completion.mjs +19 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live/event-validation.mjs +137 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live/insert-ui.mjs +458 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live/manual-apply.mjs +939 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live/manual-edit-routes.mjs +357 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live/manual-edits-buffer.mjs +152 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live/session-store.mjs +289 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live/svelte-component.mjs +826 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live/sveltekit-adapter.mjs +274 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live/ui-core.mjs +180 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live/vocabulary.mjs +36 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-accept.mjs +812 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-browser-dom.js +146 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-browser-session.js +123 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-browser.js +11086 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-commit-manual-edits.mjs +1241 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-complete.mjs +75 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-copy-edit-agent.mjs +683 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-discard-manual-edits.mjs +51 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-inject.mjs +583 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-insert.mjs +272 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-manual-edit-evidence.mjs +363 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-poll.mjs +379 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-resume.mjs +94 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-server.mjs +1134 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-status.mjs +61 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live-wrap.mjs +894 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/live.mjs +246 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/modern-screenshot.umd.js +14 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/palette.mjs +633 -0
- package/bundled/upstream/impeccable/skills/impeccable/scripts/pin.mjs +214 -0
- package/package.json +1 -1
- package/src/cli/source.js +6 -0
- package/src/config/sources.js +15 -0
- package/src/merge/content-patch.js +4 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context loader: prints PRODUCT.md (and DESIGN.md if present) as one
|
|
3
|
+
* markdown block on stdout, or exits with empty stdout when no PRODUCT.md
|
|
4
|
+
* is found anywhere. The skill keys off "empty stdout" to branch into the
|
|
5
|
+
* init flow.
|
|
6
|
+
*
|
|
7
|
+
* Path resolution (first match wins):
|
|
8
|
+
* 1. cwd, if PRODUCT.md or DESIGN.md is there
|
|
9
|
+
* 2. .agents/context/ then docs/
|
|
10
|
+
* 3. $IMPECCABLE_CONTEXT_DIR (absolute or cwd-relative) — power-user
|
|
11
|
+
* escape hatch, only consulted when defaults are empty
|
|
12
|
+
* 4. cwd as a "nothing found" default
|
|
13
|
+
*
|
|
14
|
+
* `resolveContextDir()` and `loadContext()` are also exported for the
|
|
15
|
+
* server-side scripts (live.mjs, live-server.mjs) that need the structured
|
|
16
|
+
* shape rather than the markdown block.
|
|
17
|
+
*/
|
|
18
|
+
import fs from 'node:fs';
|
|
19
|
+
import os from 'node:os';
|
|
20
|
+
import path from 'node:path';
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
22
|
+
|
|
23
|
+
const PRODUCT_NAMES = ['PRODUCT.md', 'Product.md', 'product.md'];
|
|
24
|
+
const DESIGN_NAMES = ['DESIGN.md', 'Design.md', 'design.md'];
|
|
25
|
+
const FALLBACK_DIRS = ['.agents/context', 'docs'];
|
|
26
|
+
|
|
27
|
+
// ─── Update check ──────────────────────────────────────────────────────────
|
|
28
|
+
// Piggyback a lightweight skill-version check on the once-per-session boot.
|
|
29
|
+
// When a newer skill ships, append an UPDATE_AVAILABLE directive so the agent
|
|
30
|
+
// can offer `npx impeccable update`. Everything here is best-effort and
|
|
31
|
+
// silent on failure: a network problem, sandbox, or missing cache must never
|
|
32
|
+
// block context output or print an error.
|
|
33
|
+
|
|
34
|
+
const UPDATE_HOST = (process.env.IMPECCABLE_UPDATE_HOST || 'https://impeccable.style').replace(/\/$/, '');
|
|
35
|
+
const UPDATE_CACHE_PATH =
|
|
36
|
+
process.env.IMPECCABLE_UPDATE_CACHE || path.join(os.homedir(), '.impeccable', 'update-check.json');
|
|
37
|
+
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000; // throttle the network poll to once a day
|
|
38
|
+
const RENOTIFY_INTERVAL_MS = 7 * 24 * 60 * 60 * 1000; // don't re-surface the same version for a week
|
|
39
|
+
const FETCH_TIMEOUT_MS = 1200;
|
|
40
|
+
|
|
41
|
+
export function resolveContextDir(cwd = process.cwd()) {
|
|
42
|
+
if (firstExisting(cwd, [...PRODUCT_NAMES, ...DESIGN_NAMES])) {
|
|
43
|
+
return cwd;
|
|
44
|
+
}
|
|
45
|
+
for (const rel of FALLBACK_DIRS) {
|
|
46
|
+
const candidate = path.resolve(cwd, rel);
|
|
47
|
+
if (firstExisting(candidate, [...PRODUCT_NAMES, ...DESIGN_NAMES])) {
|
|
48
|
+
return candidate;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const envDir = process.env.IMPECCABLE_CONTEXT_DIR;
|
|
52
|
+
if (envDir && envDir.trim()) {
|
|
53
|
+
const trimmed = envDir.trim();
|
|
54
|
+
return path.isAbsolute(trimmed) ? trimmed : path.resolve(cwd, trimmed);
|
|
55
|
+
}
|
|
56
|
+
return cwd;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function loadContext(cwd = process.cwd()) {
|
|
60
|
+
const contextDir = resolveContextDir(cwd);
|
|
61
|
+
const productPath = firstExisting(contextDir, PRODUCT_NAMES);
|
|
62
|
+
const designPath = firstExisting(contextDir, DESIGN_NAMES);
|
|
63
|
+
const product = productPath ? safeRead(productPath) : null;
|
|
64
|
+
const design = designPath ? safeRead(designPath) : null;
|
|
65
|
+
return {
|
|
66
|
+
hasProduct: !!product,
|
|
67
|
+
product,
|
|
68
|
+
productPath: productPath ? path.relative(cwd, productPath) : null,
|
|
69
|
+
hasDesign: !!design,
|
|
70
|
+
design,
|
|
71
|
+
designPath: designPath ? path.relative(cwd, designPath) : null,
|
|
72
|
+
contextDir,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function firstExisting(dir, names) {
|
|
77
|
+
for (const name of names) {
|
|
78
|
+
const abs = path.join(dir, name);
|
|
79
|
+
if (fs.existsSync(abs)) return abs;
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function safeRead(p) {
|
|
85
|
+
try {
|
|
86
|
+
return fs.readFileSync(p, 'utf-8');
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Pull the register (`brand` or `product`) out of PRODUCT.md by looking
|
|
94
|
+
* for a `## Register` section and reading the first non-empty line that
|
|
95
|
+
* follows it. Returns null when the file is legacy / register-less.
|
|
96
|
+
*/
|
|
97
|
+
export function extractRegister(product) {
|
|
98
|
+
if (!product) return null;
|
|
99
|
+
const lines = product.split('\n');
|
|
100
|
+
for (let i = 0; i < lines.length; i++) {
|
|
101
|
+
if (/^##\s+Register\b/i.test(lines[i].trim())) {
|
|
102
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
103
|
+
const next = lines[j].trim();
|
|
104
|
+
if (!next) continue;
|
|
105
|
+
const word = next.toLowerCase();
|
|
106
|
+
if (word === 'brand' || word === 'product') return word;
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Read the installed skill's own version from the sibling SKILL.md frontmatter
|
|
116
|
+
* (this file lives at `<skill>/scripts/context.mjs`). Returns null when the
|
|
117
|
+
* frontmatter is missing or unreadable.
|
|
118
|
+
*/
|
|
119
|
+
function readLocalSkillVersion() {
|
|
120
|
+
try {
|
|
121
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
122
|
+
const skillMd = path.join(here, '..', 'SKILL.md');
|
|
123
|
+
const content = fs.readFileSync(skillMd, 'utf-8');
|
|
124
|
+
const match = content.match(/^version:\s*(.+)$/m);
|
|
125
|
+
return match ? match[1].trim().replace(/^["']|["']$/g, '') : null;
|
|
126
|
+
} catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function readUpdateCache() {
|
|
132
|
+
try {
|
|
133
|
+
return JSON.parse(fs.readFileSync(UPDATE_CACHE_PATH, 'utf-8'));
|
|
134
|
+
} catch {
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function writeUpdateCache(cache) {
|
|
140
|
+
try {
|
|
141
|
+
fs.mkdirSync(path.dirname(UPDATE_CACHE_PATH), { recursive: true });
|
|
142
|
+
fs.writeFileSync(UPDATE_CACHE_PATH, JSON.stringify(cache));
|
|
143
|
+
} catch {
|
|
144
|
+
// Best-effort: a read-only home dir just means we re-poll next session.
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Compare dotted numeric versions. Returns >0 when a is newer than b. */
|
|
149
|
+
function compareSemver(a, b) {
|
|
150
|
+
const pa = String(a).split('.').map(n => parseInt(n, 10) || 0);
|
|
151
|
+
const pb = String(b).split('.').map(n => parseInt(n, 10) || 0);
|
|
152
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
153
|
+
const diff = (pa[i] || 0) - (pb[i] || 0);
|
|
154
|
+
if (diff !== 0) return diff;
|
|
155
|
+
}
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function fetchLatestSkillVersion() {
|
|
160
|
+
try {
|
|
161
|
+
const res = await fetch(`${UPDATE_HOST}/api/version`, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
162
|
+
if (!res.ok) return null;
|
|
163
|
+
const data = await res.json();
|
|
164
|
+
return typeof data?.skills === 'string' ? data.skills : null;
|
|
165
|
+
} catch {
|
|
166
|
+
return null; // offline, sandboxed, timed out, or bad JSON: all non-fatal
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function buildUpdateDirective(localVersion, latestVersion) {
|
|
171
|
+
return (
|
|
172
|
+
`UPDATE_AVAILABLE: A newer Impeccable skill is available ` +
|
|
173
|
+
`(installed v${localVersion}, latest v${latestVersion}). ` +
|
|
174
|
+
`Before continuing, ask the user once: "A newer Impeccable (v${latestVersion}) is available. ` +
|
|
175
|
+
`Update now? It runs \`npx impeccable update\`." ` +
|
|
176
|
+
`If they agree, run \`npx impeccable update\` (the update applies to the next session, not this one). ` +
|
|
177
|
+
`Either way, continue the current task without waiting, and do not raise this again.`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Best-effort update directive for the boot output. Returns a string to append
|
|
183
|
+
* or null. Polls the version endpoint at most once per day (cached globally in
|
|
184
|
+
* the user's home dir) and re-surfaces a given version at most once per week so
|
|
185
|
+
* the agent never nags. Opt out entirely with IMPECCABLE_NO_UPDATE_CHECK=1.
|
|
186
|
+
*/
|
|
187
|
+
// Read the unified config's top-level `updateCheck` (local overrides shared).
|
|
188
|
+
// Inlined rather than importing hook-lib so the boot path stays lightweight.
|
|
189
|
+
function updateCheckDisabledByConfig(cwd = process.cwd()) {
|
|
190
|
+
let value;
|
|
191
|
+
for (const name of ['config.json', 'config.local.json']) {
|
|
192
|
+
try {
|
|
193
|
+
const raw = JSON.parse(fs.readFileSync(path.join(cwd, '.impeccable', name), 'utf-8'));
|
|
194
|
+
if (raw && typeof raw === 'object' && typeof raw.updateCheck === 'boolean') value = raw.updateCheck;
|
|
195
|
+
} catch { /* missing or malformed: ignore */ }
|
|
196
|
+
}
|
|
197
|
+
return value === false;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function computeUpdateDirective(now = Date.now()) {
|
|
201
|
+
try {
|
|
202
|
+
if (process.env.IMPECCABLE_NO_UPDATE_CHECK) return null;
|
|
203
|
+
if (updateCheckDisabledByConfig()) return null;
|
|
204
|
+
const localVersion = readLocalSkillVersion();
|
|
205
|
+
if (!localVersion) return null;
|
|
206
|
+
|
|
207
|
+
const cache = readUpdateCache();
|
|
208
|
+
|
|
209
|
+
// Poll the network only when the throttle window has elapsed. Stamp
|
|
210
|
+
// lastCheck even on failure so an offline machine doesn't poll every boot.
|
|
211
|
+
if (!cache.lastCheck || now - cache.lastCheck > CHECK_INTERVAL_MS) {
|
|
212
|
+
const latest = await fetchLatestSkillVersion();
|
|
213
|
+
cache.lastCheck = now;
|
|
214
|
+
if (latest) cache.latestVersion = latest;
|
|
215
|
+
writeUpdateCache(cache);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const latest = cache.latestVersion;
|
|
219
|
+
if (!latest || compareSemver(latest, localVersion) <= 0) return null;
|
|
220
|
+
|
|
221
|
+
// Anti-nag: surface a given version at most once per RENOTIFY window.
|
|
222
|
+
if (cache.notifiedVersion === latest && cache.notifiedAt && now - cache.notifiedAt < RENOTIFY_INTERVAL_MS) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
cache.notifiedVersion = latest;
|
|
226
|
+
cache.notifiedAt = now;
|
|
227
|
+
writeUpdateCache(cache);
|
|
228
|
+
|
|
229
|
+
return buildUpdateDirective(localVersion, latest);
|
|
230
|
+
} catch {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async function cli() {
|
|
236
|
+
const ctx = loadContext(process.cwd());
|
|
237
|
+
const updateDirective = await computeUpdateDirective();
|
|
238
|
+
|
|
239
|
+
if (!ctx.hasProduct) {
|
|
240
|
+
// Direct stdout message instead of relying on empty output as a signal
|
|
241
|
+
// — cheap models miss the empty case more often than the explicit one.
|
|
242
|
+
const parts = [
|
|
243
|
+
'NO_PRODUCT_MD: This project has no PRODUCT.md yet. ' +
|
|
244
|
+
'Stop the current task, load reference/init.md, and follow its ' +
|
|
245
|
+
'instructions to write PRODUCT.md before resuming.',
|
|
246
|
+
];
|
|
247
|
+
if (updateDirective) parts.push(updateDirective);
|
|
248
|
+
process.stdout.write(parts.join('\n\n---\n\n') + '\n');
|
|
249
|
+
process.exit(0);
|
|
250
|
+
}
|
|
251
|
+
const parts = [`# PRODUCT.md\n\n${ctx.product.trim()}`];
|
|
252
|
+
if (ctx.hasDesign) {
|
|
253
|
+
parts.push(`# DESIGN.md\n\n${ctx.design.trim()}`);
|
|
254
|
+
}
|
|
255
|
+
const register = extractRegister(ctx.product);
|
|
256
|
+
const next = register
|
|
257
|
+
? `NEXT STEP: This project's register is \`${register}\`. You MUST now read \`reference/${register}.md\` before producing any design output.`
|
|
258
|
+
: `NEXT STEP: You MUST now read the matching register reference (\`reference/brand.md\` or \`reference/product.md\`) before producing any design output. Pick based on PRODUCT.md above.`;
|
|
259
|
+
parts.push(next);
|
|
260
|
+
if (updateDirective) parts.push(updateDirective);
|
|
261
|
+
process.stdout.write(parts.join('\n\n---\n\n') + '\n');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Run cli() only when this module is the entry point. Compare realpaths
|
|
265
|
+
// rather than endsWith(): a loose suffix match also fires for unrelated
|
|
266
|
+
// scripts like `load-context.mjs`, and realpath tolerates symlinked
|
|
267
|
+
// invocation (the test harness symlinks the skill dir).
|
|
268
|
+
function invokedAsScript() {
|
|
269
|
+
const arg = process.argv[1];
|
|
270
|
+
if (!arg) return false;
|
|
271
|
+
try {
|
|
272
|
+
return fs.realpathSync(arg) === fs.realpathSync(fileURLToPath(import.meta.url));
|
|
273
|
+
} catch {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (invokedAsScript()) {
|
|
279
|
+
cli();
|
|
280
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Critique persistence helper.
|
|
4
|
+
*
|
|
5
|
+
* Each run of /impeccable critique writes a per-target snapshot to
|
|
6
|
+
* .impeccable/critique/<timestamp>__<slug>.md
|
|
7
|
+
* with a small YAML frontmatter carrying the score + P0/P1 counts.
|
|
8
|
+
*
|
|
9
|
+
* /impeccable polish reads the latest matching snapshot at start as its
|
|
10
|
+
* fix backlog. No other skill auto-reads critique output.
|
|
11
|
+
*
|
|
12
|
+
* The slug is derived mechanically from the *resolved* primary artifact
|
|
13
|
+
* (file path or URL), never from the user's natural-language phrasing.
|
|
14
|
+
* Slug stability across runs is what lets the trend display work.
|
|
15
|
+
*
|
|
16
|
+
* CLI entry points (called from skill instructions):
|
|
17
|
+
* node critique-storage.mjs slug <resolved-target>
|
|
18
|
+
* node critique-storage.mjs write <slug> <snapshot-body-file>
|
|
19
|
+
* node critique-storage.mjs latest <slug>
|
|
20
|
+
* node critique-storage.mjs trend <slug> [limit]
|
|
21
|
+
*
|
|
22
|
+
* Note: there is intentionally no `ignore` subcommand. ignore.md is a plain
|
|
23
|
+
* markdown file; the model reads it directly with its file-read tool. This
|
|
24
|
+
* helper only exists for operations the model can't trivially do inline
|
|
25
|
+
* (normalizing paths, generating filenames, globbing + parsing frontmatter).
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import fs from 'node:fs';
|
|
29
|
+
import path from 'node:path';
|
|
30
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
31
|
+
import { getCritiqueDir } from './lib/impeccable-paths.mjs';
|
|
32
|
+
|
|
33
|
+
const SLUG_MAX = 50;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Mechanically derive a slug from a resolved target. Returns null if the
|
|
37
|
+
* input doesn't look like a stable identifier (empty, project root, etc).
|
|
38
|
+
*
|
|
39
|
+
* Accepts file paths and URLs. The model resolves "the homepage" to a
|
|
40
|
+
* concrete artifact before calling this — we never slug a natural-language
|
|
41
|
+
* phrase.
|
|
42
|
+
*/
|
|
43
|
+
export function slugFromTarget(resolved, { cwd = process.cwd() } = {}) {
|
|
44
|
+
if (!resolved || typeof resolved !== 'string') return null;
|
|
45
|
+
const trimmed = resolved.trim();
|
|
46
|
+
if (!trimmed) return null;
|
|
47
|
+
|
|
48
|
+
// URL
|
|
49
|
+
if (/^https?:\/\//i.test(trimmed)) {
|
|
50
|
+
let url;
|
|
51
|
+
try { url = new URL(trimmed); } catch { return null; }
|
|
52
|
+
const hostPath = `${url.hostname}${url.pathname}`;
|
|
53
|
+
return kebab(hostPath);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// File path. Make it project-relative so two devs critiquing the same
|
|
57
|
+
// checkout get the same slug regardless of where their repo is cloned.
|
|
58
|
+
const abs = path.isAbsolute(trimmed) ? trimmed : path.resolve(cwd, trimmed);
|
|
59
|
+
let rel = path.relative(cwd, abs);
|
|
60
|
+
// If the target is outside cwd, fall back to the basename so we still
|
|
61
|
+
// produce a stable slug (vs the absolute path, which would include
|
|
62
|
+
// home dirs / usernames).
|
|
63
|
+
if (rel.startsWith('..') || path.isAbsolute(rel)) {
|
|
64
|
+
rel = path.basename(abs);
|
|
65
|
+
}
|
|
66
|
+
if (!rel || rel === '.' || rel === '') return null;
|
|
67
|
+
return kebab(rel);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function kebab(s) {
|
|
71
|
+
const slug = s
|
|
72
|
+
.toLowerCase()
|
|
73
|
+
.replace(/[/\\.]+/g, '-')
|
|
74
|
+
.replace(/[^a-z0-9-]+/g, '-')
|
|
75
|
+
.replace(/-+/g, '-')
|
|
76
|
+
.replace(/^-|-$/g, '');
|
|
77
|
+
if (!slug) return null;
|
|
78
|
+
// Cap from the tail — the tail (filename) is more identifying than the
|
|
79
|
+
// top-level directory.
|
|
80
|
+
return slug.length <= SLUG_MAX ? slug : slug.slice(slug.length - SLUG_MAX).replace(/^-/, '');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Filename-safe UTC ISO timestamp: hyphens for separators, trailing Z.
|
|
85
|
+
* Plain colons aren't allowed on Windows filesystems.
|
|
86
|
+
*/
|
|
87
|
+
export function nowFilenameStamp(date = new Date()) {
|
|
88
|
+
const iso = date.toISOString(); // 2026-05-12T18:30:00.123Z
|
|
89
|
+
return iso.replace(/[:.]/g, '-').replace(/-\d+Z$/, 'Z');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Write a snapshot for `slug`. `meta` carries the small structured frontmatter
|
|
94
|
+
* keys read back by readTrend(). `body` is the human-readable critique
|
|
95
|
+
* report (everything below the frontmatter).
|
|
96
|
+
*
|
|
97
|
+
* Returns the absolute path written.
|
|
98
|
+
*/
|
|
99
|
+
export function writeSnapshot({ slug, meta, body, cwd = process.cwd(), now = new Date() }) {
|
|
100
|
+
if (!slug) throw new Error('writeSnapshot requires a slug');
|
|
101
|
+
const dir = getCritiqueDir(cwd);
|
|
102
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
103
|
+
const timestamp = nowFilenameStamp(now);
|
|
104
|
+
const filePath = path.join(dir, `${timestamp}__${slug}.md`);
|
|
105
|
+
// Spread `meta` first so internally computed `timestamp` and `slug`
|
|
106
|
+
// always win. Otherwise a caller-supplied meta blob (parsed from the
|
|
107
|
+
// IMPECCABLE_CRITIQUE_META env var) could clobber them, leaving the
|
|
108
|
+
// filename in disagreement with its frontmatter and corrupting trends.
|
|
109
|
+
const front = serializeFrontmatter({ ...meta, timestamp, slug });
|
|
110
|
+
fs.writeFileSync(filePath, `${front}\n${body.trim()}\n`, 'utf-8');
|
|
111
|
+
return filePath;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function serializeFrontmatter(obj) {
|
|
115
|
+
const lines = ['---'];
|
|
116
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
117
|
+
if (value === undefined || value === null) continue;
|
|
118
|
+
const str = typeof value === 'string' ? value : String(value);
|
|
119
|
+
// Quote strings that contain : or # to keep parsing simple.
|
|
120
|
+
const needsQuotes = typeof value === 'string' && /[:#]/.test(str);
|
|
121
|
+
lines.push(`${key}: ${needsQuotes ? JSON.stringify(str) : str}`);
|
|
122
|
+
}
|
|
123
|
+
lines.push('---');
|
|
124
|
+
return lines.join('\n');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function parseFrontmatter(text) {
|
|
128
|
+
const match = text.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
129
|
+
if (!match) return {};
|
|
130
|
+
const out = {};
|
|
131
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
132
|
+
const colon = line.indexOf(':');
|
|
133
|
+
if (colon < 0) continue;
|
|
134
|
+
const key = line.slice(0, colon).trim();
|
|
135
|
+
let value = line.slice(colon + 1).trim();
|
|
136
|
+
if (/^".*"$/.test(value)) {
|
|
137
|
+
try { value = JSON.parse(value); } catch { /* leave as-is */ }
|
|
138
|
+
} else if (/^-?\d+$/.test(value)) {
|
|
139
|
+
value = Number(value);
|
|
140
|
+
}
|
|
141
|
+
out[key] = value;
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Return all snapshot files for `slug`, sorted oldest → newest.
|
|
148
|
+
*/
|
|
149
|
+
function listSnapshotsForSlug(slug, cwd) {
|
|
150
|
+
const dir = getCritiqueDir(cwd);
|
|
151
|
+
if (!fs.existsSync(dir)) return [];
|
|
152
|
+
const suffix = `__${slug}.md`;
|
|
153
|
+
return fs.readdirSync(dir)
|
|
154
|
+
.filter((f) => f.endsWith(suffix))
|
|
155
|
+
.sort()
|
|
156
|
+
.map((f) => path.join(dir, f));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Return the most recent snapshot for `slug`, or null. Polish reads this
|
|
161
|
+
* to find its fix backlog when the slug matches.
|
|
162
|
+
*/
|
|
163
|
+
export function readLatestSnapshot(slug, { cwd = process.cwd() } = {}) {
|
|
164
|
+
const all = listSnapshotsForSlug(slug, cwd);
|
|
165
|
+
if (!all.length) return null;
|
|
166
|
+
const latest = all[all.length - 1];
|
|
167
|
+
const body = fs.readFileSync(latest, 'utf-8');
|
|
168
|
+
return { path: latest, body, meta: parseFrontmatter(body) };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Return the last `limit` snapshots' frontmatter, oldest → newest.
|
|
173
|
+
* Critique appends a one-line trend to its output using this.
|
|
174
|
+
*/
|
|
175
|
+
export function readTrend(slug, { limit = 5, cwd = process.cwd() } = {}) {
|
|
176
|
+
const all = listSnapshotsForSlug(slug, cwd);
|
|
177
|
+
const slice = all.slice(-limit);
|
|
178
|
+
return slice.map((file) => parseFrontmatter(fs.readFileSync(file, 'utf-8')));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ---- CLI ---------------------------------------------------------------
|
|
182
|
+
|
|
183
|
+
function main(argv) {
|
|
184
|
+
const [cmd, ...args] = argv;
|
|
185
|
+
switch (cmd) {
|
|
186
|
+
case 'slug': {
|
|
187
|
+
const slug = slugFromTarget(args[0]);
|
|
188
|
+
if (!slug) { process.stderr.write('no stable slug for input\n'); process.exit(1); }
|
|
189
|
+
process.stdout.write(`${slug}\n`);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
case 'write': {
|
|
193
|
+
const [slug, bodyFile] = args;
|
|
194
|
+
if (!slug || !bodyFile) { process.stderr.write('usage: write <slug> <body-file>\n'); process.exit(1); }
|
|
195
|
+
const raw = fs.readFileSync(bodyFile, 'utf-8');
|
|
196
|
+
// The body file may be a full report. The caller passes the meta as
|
|
197
|
+
// a JSON object on stdin if it wants structured frontmatter; otherwise
|
|
198
|
+
// we write with minimal metadata.
|
|
199
|
+
let meta = {};
|
|
200
|
+
const metaArg = process.env.IMPECCABLE_CRITIQUE_META;
|
|
201
|
+
if (metaArg) {
|
|
202
|
+
try { meta = JSON.parse(metaArg); } catch { /* ignore */ }
|
|
203
|
+
}
|
|
204
|
+
const out = writeSnapshot({ slug, meta, body: raw });
|
|
205
|
+
process.stdout.write(`${out}\n`);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
case 'latest': {
|
|
209
|
+
const latest = readLatestSnapshot(args[0]);
|
|
210
|
+
if (!latest) { process.exit(2); }
|
|
211
|
+
process.stdout.write(latest.body);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
case 'trend': {
|
|
215
|
+
const rows = readTrend(args[0], { limit: args[1] ? Number(args[1]) : 5 });
|
|
216
|
+
process.stdout.write(JSON.stringify(rows, null, 2) + '\n');
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
default:
|
|
220
|
+
process.stderr.write('usage: critique-storage.mjs <slug|write|latest|trend> [args]\n');
|
|
221
|
+
process.exit(1);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function isMainModule() {
|
|
226
|
+
if (!process.argv[1]) return false;
|
|
227
|
+
try {
|
|
228
|
+
return fs.realpathSync(fileURLToPath(import.meta.url)) === fs.realpathSync(process.argv[1]);
|
|
229
|
+
} catch {
|
|
230
|
+
// pathToFileURL normalizes Windows paths; keep it as a fallback for any
|
|
231
|
+
// environment where realpath is unavailable.
|
|
232
|
+
return import.meta.url === pathToFileURL(process.argv[1]).href;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Why the realpath check: generated skills are often reached through symlinked
|
|
237
|
+
// harness directories (for example a demo repo's `.agents` -> source `.agents`).
|
|
238
|
+
// Node resolves import.meta.url to the real file, while process.argv[1] keeps
|
|
239
|
+
// the symlink path. Comparing canonical paths prevents a silent exit-0 no-op.
|
|
240
|
+
if (isMainModule()) {
|
|
241
|
+
main(process.argv.slice(2));
|
|
242
|
+
}
|