quiver-cli 0.7.0 → 1.0.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/README.md +110 -45
- package/bin/quiver-cli.mjs +3 -1
- package/dist/cli.js +733 -499
- package/package.json +2 -2
- package/template/.agents/AGENTS.md +4 -3
- package/template/.agents/config.json +7 -0
- package/template/.agents/plugins/opencode/rtk.ts +34 -0
- package/template/.agents/skills/agent-browser/SKILL.md +1 -0
- package/template/.agents/skills/apps/skybridge/SKILL.md +4 -0
- package/template/.agents/skills/design/impeccable/SKILL.md +36 -118
- package/template/.agents/skills/design/impeccable/reference/adapt.md +1 -0
- package/template/.agents/skills/design/impeccable/reference/adapt.native.md +58 -0
- package/template/.agents/skills/design/impeccable/reference/android.md +40 -0
- package/template/.agents/skills/design/impeccable/reference/animate.md +73 -188
- package/template/.agents/skills/design/impeccable/reference/audit.md +12 -9
- package/template/.agents/skills/design/impeccable/reference/audit.native.md +139 -0
- package/template/.agents/skills/design/impeccable/reference/bolder.md +19 -101
- package/template/.agents/skills/design/impeccable/reference/clarify.md +59 -253
- package/template/.agents/skills/design/impeccable/reference/colorize.md +51 -222
- package/template/.agents/skills/design/impeccable/reference/craft-floor.md +42 -0
- package/template/.agents/skills/design/impeccable/reference/craft.md +3 -121
- package/template/.agents/skills/design/impeccable/reference/critique.md +44 -23
- package/template/.agents/skills/design/impeccable/reference/degraded/asset-producer.md +90 -0
- package/template/.agents/skills/design/impeccable/reference/degraded/documenter.md +24 -0
- package/template/.agents/skills/design/impeccable/reference/degraded/finish-reviewer.md +37 -0
- package/template/.agents/skills/design/impeccable/reference/degraded/manual-edit-applier.md +92 -0
- package/template/.agents/skills/design/impeccable/reference/delight.md +47 -279
- package/template/.agents/skills/design/impeccable/reference/distill.md +2 -2
- package/template/.agents/skills/design/impeccable/reference/doctor.md +53 -0
- package/template/.agents/skills/design/impeccable/reference/document.md +60 -73
- package/template/.agents/skills/design/impeccable/reference/harden.md +1 -12
- package/template/.agents/skills/design/impeccable/reference/hooks.md +20 -5
- package/template/.agents/skills/design/impeccable/reference/init.md +72 -119
- package/template/.agents/skills/design/impeccable/reference/ios.md +45 -0
- package/template/.agents/skills/design/impeccable/reference/layout.md +54 -131
- package/template/.agents/skills/design/impeccable/reference/live-setup.md +102 -0
- package/template/.agents/skills/design/impeccable/reference/live.md +116 -511
- package/template/.agents/skills/design/impeccable/reference/new-work.md +105 -0
- package/template/.agents/skills/design/impeccable/reference/{product.md → operate.md} +6 -5
- package/template/.agents/skills/design/impeccable/reference/optimize.md +4 -4
- package/template/.agents/skills/design/impeccable/reference/overdrive.md +1 -4
- package/template/.agents/skills/design/impeccable/reference/polish.md +68 -212
- package/template/.agents/skills/design/impeccable/reference/quieter.md +3 -3
- package/template/.agents/skills/design/impeccable/reference/routing.md +18 -0
- package/template/.agents/skills/design/impeccable/reference/shape.md +38 -144
- package/template/.agents/skills/design/impeccable/reference/typeset.md +51 -250
- package/template/.agents/skills/design/impeccable/reference/visualize.md +47 -0
- package/template/.agents/skills/design/impeccable/scripts/command-metadata.json +1 -1
- package/template/.agents/skills/design/impeccable/scripts/concept-seed.mjs +558 -0
- package/template/.agents/skills/design/impeccable/scripts/context-signals.mjs +119 -10
- package/template/.agents/skills/design/impeccable/scripts/context.mjs +534 -45
- package/template/.agents/skills/design/impeccable/scripts/critique-storage.mjs +18 -47
- package/template/.agents/skills/design/impeccable/scripts/detector/browser/injected/index.mjs +96 -10
- package/template/.agents/skills/design/impeccable/scripts/detector/cli/main.mjs +174 -26
- package/template/.agents/skills/design/impeccable/scripts/detector/design-system.mjs +233 -0
- package/template/.agents/skills/design/impeccable/scripts/detector/detect-antipatterns-browser.js +3348 -203
- package/template/.agents/skills/design/impeccable/scripts/detector/engines/browser/detect-url.mjs +102 -7
- package/template/.agents/skills/design/impeccable/scripts/detector/engines/regex/detect-text.mjs +297 -97
- package/template/.agents/skills/design/impeccable/scripts/detector/engines/static-html/css-cascade.mjs +187 -16
- package/template/.agents/skills/design/impeccable/scripts/detector/engines/static-html/detect-html.mjs +41 -11
- package/template/.agents/skills/design/impeccable/scripts/detector/findings.mjs +7 -1
- package/template/.agents/skills/design/impeccable/scripts/detector/node/file-system.mjs +16 -2
- package/template/.agents/skills/design/impeccable/scripts/detector/registry/antipatterns.mjs +207 -38
- package/template/.agents/skills/design/impeccable/scripts/detector/rules/checks.mjs +3082 -173
- package/template/.agents/skills/design/impeccable/scripts/detector/shared/constants.mjs +11 -0
- package/template/.agents/skills/design/impeccable/scripts/detector/shared/fonts.mjs +30 -0
- package/template/.agents/skills/design/impeccable/scripts/doctor.mjs +336 -0
- package/template/.agents/skills/design/impeccable/scripts/embed-prompt.mjs +133 -0
- package/template/.agents/skills/design/impeccable/scripts/generate-image.mjs +240 -0
- package/template/.agents/skills/design/impeccable/scripts/hook-admin.mjs +98 -18
- package/template/.agents/skills/design/impeccable/scripts/hook-before-edit.mjs +46 -6
- package/template/.agents/skills/design/impeccable/scripts/hook-lib.mjs +518 -50
- package/template/.agents/skills/design/impeccable/scripts/hook.mjs +25 -8
- package/template/.agents/skills/design/impeccable/scripts/lib/artifact-schema.mjs +93 -0
- package/template/.agents/skills/design/impeccable/scripts/lib/composition-catalog.mjs +200 -0
- package/template/.agents/skills/design/impeccable/scripts/lib/concept-catalog.mjs +357 -0
- package/template/.agents/skills/design/impeccable/scripts/lib/impeccable-config.mjs +27 -7
- package/template/.agents/skills/design/impeccable/scripts/lib/impeccable-paths.mjs +17 -8
- package/template/.agents/skills/design/impeccable/scripts/lib/provider.mjs +5 -0
- package/template/.agents/skills/design/impeccable/scripts/lib/roll-selection.mjs +362 -0
- package/template/.agents/skills/design/impeccable/scripts/lib/staleness-deep.mjs +457 -0
- package/template/.agents/skills/design/impeccable/scripts/lib/staleness-notice.mjs +169 -0
- package/template/.agents/skills/design/impeccable/scripts/lib/staleness.mjs +457 -0
- package/template/.agents/skills/design/impeccable/scripts/lib/surface-briefs.mjs +151 -0
- package/template/.agents/skills/design/impeccable/scripts/lib/target-slug.mjs +33 -0
- package/template/.agents/skills/design/impeccable/scripts/lib/template-extensions.mjs +146 -0
- package/template/.agents/skills/design/impeccable/scripts/live/accept-css.mjs +617 -0
- package/template/.agents/skills/design/impeccable/scripts/live/accept-verify.mjs +60 -0
- package/template/.agents/skills/design/impeccable/scripts/live/browser-script-parts.mjs +7 -1
- package/template/.agents/skills/design/impeccable/scripts/live/completion.mjs +10 -1
- package/template/.agents/skills/design/impeccable/scripts/live/event-validation.mjs +67 -5
- package/template/.agents/skills/design/impeccable/scripts/live/frameworks/astro.mjs +47 -0
- package/template/.agents/skills/design/impeccable/scripts/live/frameworks/detect-utils.mjs +73 -0
- package/template/.agents/skills/design/impeccable/scripts/live/frameworks/index.mjs +143 -0
- package/template/.agents/skills/design/impeccable/scripts/live/frameworks/journal.mjs +197 -0
- package/template/.agents/skills/design/impeccable/scripts/live/frameworks/nextjs.mjs +49 -0
- package/template/.agents/skills/design/impeccable/scripts/live/frameworks/nuxt.mjs +161 -0
- package/template/.agents/skills/design/impeccable/scripts/live/frameworks/script-src.mjs +17 -0
- package/template/.agents/skills/design/impeccable/scripts/live/frameworks/static-html.mjs +26 -0
- package/template/.agents/skills/design/impeccable/scripts/live/frameworks/sveltekit.mjs +71 -0
- package/template/.agents/skills/design/impeccable/scripts/live/frameworks/tag-strategy.mjs +247 -0
- package/template/.agents/skills/design/impeccable/scripts/live/frameworks/tanstack-start.mjs +70 -0
- package/template/.agents/skills/design/impeccable/scripts/live/frameworks/vite-generic.mjs +42 -0
- package/template/.agents/skills/design/impeccable/scripts/live/generation-preflight.mjs +149 -0
- package/template/.agents/skills/design/impeccable/scripts/live/instructions.mjs +142 -0
- package/template/.agents/skills/design/impeccable/scripts/live/poll-lanes.mjs +14 -0
- package/template/.agents/skills/design/impeccable/scripts/live/roots.mjs +508 -0
- package/template/.agents/skills/design/impeccable/scripts/live/session-store.mjs +324 -50
- package/template/.agents/skills/design/impeccable/scripts/live/source-lock.mjs +105 -0
- package/template/.agents/skills/design/impeccable/scripts/live/source-search.mjs +105 -0
- package/template/.agents/skills/design/impeccable/scripts/live/svelte-ast.mjs +961 -0
- package/template/.agents/skills/design/impeccable/scripts/live/svelte-component.mjs +588 -72
- package/template/.agents/skills/design/impeccable/scripts/live/sveltekit-adapter.mjs +59 -17
- package/template/.agents/skills/design/impeccable/scripts/live/tanstack-adapter.mjs +280 -0
- package/template/.agents/skills/design/impeccable/scripts/live/vocabulary.mjs +135 -0
- package/template/.agents/skills/design/impeccable/scripts/live-accept.mjs +210 -68
- package/template/.agents/skills/design/impeccable/scripts/live-browser.js +1562 -223
- package/template/.agents/skills/design/impeccable/scripts/live-commit-manual-edits.mjs +3 -0
- package/template/.agents/skills/design/impeccable/scripts/live-complete.mjs +33 -1
- package/template/.agents/skills/design/impeccable/scripts/live-inject.mjs +175 -255
- package/template/.agents/skills/design/impeccable/scripts/live-insert.mjs +26 -6
- package/template/.agents/skills/design/impeccable/scripts/live-manual-edit-evidence.mjs +6 -1
- package/template/.agents/skills/design/impeccable/scripts/live-poll.mjs +61 -16
- package/template/.agents/skills/design/impeccable/scripts/live-resume.mjs +39 -10
- package/template/.agents/skills/design/impeccable/scripts/live-server.mjs +573 -47
- package/template/.agents/skills/design/impeccable/scripts/live-status.mjs +17 -7
- package/template/.agents/skills/design/impeccable/scripts/live-wrap.mjs +124 -91
- package/template/.agents/skills/design/impeccable/scripts/live.mjs +88 -26
- package/template/.agents/skills/design/impeccable/scripts/palette.mjs +76 -81
- package/template/.agents/skills/design/impeccable/scripts/pin.mjs +18 -11
- package/template/.agents/skills/design/impeccable/scripts/serve-question.mjs +932 -0
- package/template/.agents/skills/design/impeccable/scripts/surface-brief.mjs +74 -0
- package/template/.agents/skills/design/shadcn/SKILL.md +46 -11
- package/template/.agents/skills/design/shadcn/cli.md +49 -16
- package/template/.agents/skills/design/shadcn/customization.md +14 -7
- package/template/.agents/skills/design/shadcn/evals/evals.json +30 -0
- package/template/.agents/skills/design/shadcn/mcp.md +27 -16
- package/template/.agents/skills/design/shadcn/registry.md +277 -0
- package/template/.agents/skills/design/shadcn/rules/chat.md +224 -0
- package/template/.agents/skills/design/shadcn/rules/composition.md +20 -2
- package/template/.agents/skills/design/shadcn/rules/styling.md +23 -0
- package/template/.agents/skills/find-skills/SKILL.md +2 -3
- package/template/.agents/skills/hono/SKILL.md +579 -0
- package/template/.agents/skills/integrations/langfuse/SKILL.md +10 -6
- package/template/.agents/skills/integrations/langfuse/references/ci-cd.md +41 -0
- package/template/.agents/skills/integrations/langfuse/references/cli.md +8 -0
- package/template/.agents/skills/integrations/langfuse/references/error-analysis.md +15 -27
- package/template/.agents/skills/integrations/langfuse/references/instrumentation.md +39 -52
- package/template/.agents/skills/integrations/langfuse/references/judge-calibration.md +5 -2
- package/template/.agents/skills/integrations/langfuse/references/prompt-engineering.md +35 -0
- package/template/.agents/skills/integrations/langfuse/references/prompt-migration.md +41 -196
- package/template/.agents/skills/integrations/langfuse/references/skill-feedback.md +3 -0
- package/template/.agents/skills/integrations/langfuse/references/trace-evaluator-upgrade.md +76 -0
- package/template/.agents/skills/integrations/langfuse/references/user-feedback.md +4 -0
- package/template/.agents/skills/integrations/langfuse/references/v4-project-migration.md +73 -0
- package/template/.agents/skills/supabase/CHANGELOG.md +71 -0
- package/template/.agents/skills/supabase/SKILL.md +145 -0
- package/template/.agents/skills/supabase/assets/feedback-issue-template.md +17 -0
- package/template/.agents/skills/supabase/references/skill-feedback.md +17 -0
- package/template/.agents/skills/supabase-postgres-best-practices/CHANGELOG.md +73 -0
- package/template/.agents/skills/supabase-postgres-best-practices/SKILL.md +64 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/_contributing.md +170 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/_sections.md +39 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/_template.md +34 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +55 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +49 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +46 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/conn-limits.md +44 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/conn-pooling.md +41 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +46 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/data-batch-inserts.md +54 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/data-n-plus-one.md +53 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/data-pagination.md +50 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/data-upsert.md +50 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/lock-advisory.md +56 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +68 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/lock-short-transactions.md +50 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/lock-skip-locked.md +54 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +45 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +55 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +55 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/query-composite-indexes.md +44 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/query-covering-indexes.md +40 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/query-index-types.md +48 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/query-missing-indexes.md +43 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/query-partial-indexes.md +45 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/schema-constraints.md +80 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/schema-data-types.md +46 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +59 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +55 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/schema-partitioning.md +55 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/schema-primary-keys.md +61 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/security-privileges.md +54 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/security-rls-basics.md +50 -0
- package/template/.agents/skills/supabase-postgres-best-practices/references/security-rls-performance.md +63 -0
- package/template/.agents/upstreams.json +34 -12
- package/template/.agents/skills/design/impeccable/reference/brand.md +0 -108
- package/template/.agents/skills/design/impeccable/reference/codex.md +0 -105
- package/template/.agents/skills/design/impeccable/reference/interaction-design.md +0 -189
- package/template/.agents/skills/integrations/langfuse/references/sdk-upgrade.md +0 -175
|
@@ -68,6 +68,15 @@ const GENERIC_FONTS = new Set([
|
|
|
68
68
|
const WCAG_LARGE_TEXT_PX = 18 * (96 / 72);
|
|
69
69
|
const WCAG_LARGE_BOLD_TEXT_PX = 14 * (96 / 72);
|
|
70
70
|
|
|
71
|
+
// Em-dash overuse (advisory) thresholds, shared by the regex/static-HTML
|
|
72
|
+
// analyzer and the browser DOM check so both fire on the same saturation
|
|
73
|
+
// pattern. Two gates must hold: an absolute floor of EM_DASH_FLOOR dashes, and
|
|
74
|
+
// a density of at least one dash per EM_DASH_CHARS_PER_DASH characters of body
|
|
75
|
+
// text. A long article that uses a few em-dashes is left alone; a short,
|
|
76
|
+
// dash-per-clause page is not.
|
|
77
|
+
const EM_DASH_FLOOR = 8;
|
|
78
|
+
const EM_DASH_CHARS_PER_DASH = 500;
|
|
79
|
+
|
|
71
80
|
// Serif faces that show up in italic-display heroes. The rule also fires when
|
|
72
81
|
// the primary face is unknown but the stack ends in the generic `serif` token,
|
|
73
82
|
// which catches custom/private faces with a serif fallback.
|
|
@@ -97,5 +106,7 @@ export {
|
|
|
97
106
|
GENERIC_FONTS,
|
|
98
107
|
WCAG_LARGE_TEXT_PX,
|
|
99
108
|
WCAG_LARGE_BOLD_TEXT_PX,
|
|
109
|
+
EM_DASH_FLOOR,
|
|
110
|
+
EM_DASH_CHARS_PER_DASH,
|
|
100
111
|
KNOWN_SERIF_FONTS,
|
|
101
112
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const GOOGLE_FONTS_URL_RE = /fonts\.googleapis\.com\/css2?\?[^"'\s)<>]*/gi;
|
|
2
|
+
|
|
3
|
+
function normalizeGoogleFontFamilyParam(value) {
|
|
4
|
+
return String(value || '')
|
|
5
|
+
.split('|')
|
|
6
|
+
.map(part => part.split(':')[0].trim().toLowerCase())
|
|
7
|
+
.filter(Boolean);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function extractGoogleFontFamilies(text) {
|
|
11
|
+
const families = [];
|
|
12
|
+
if (!text) return families;
|
|
13
|
+
|
|
14
|
+
GOOGLE_FONTS_URL_RE.lastIndex = 0;
|
|
15
|
+
let urlMatch;
|
|
16
|
+
while ((urlMatch = GOOGLE_FONTS_URL_RE.exec(text)) !== null) {
|
|
17
|
+
const url = urlMatch[0];
|
|
18
|
+
const queryStart = url.indexOf('?');
|
|
19
|
+
if (queryStart === -1) continue;
|
|
20
|
+
|
|
21
|
+
const params = new URLSearchParams(url.slice(queryStart + 1).replace(/&/g, '&'));
|
|
22
|
+
for (const value of params.getAll('family')) {
|
|
23
|
+
families.push(...normalizeGoogleFontFamilyParam(value));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return families;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { extractGoogleFontFamilies };
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Deep staleness pass over Impeccable's own project artifacts.
|
|
4
|
+
*
|
|
5
|
+
* node doctor.mjs # human-readable report
|
|
6
|
+
* node doctor.mjs --json # machine-readable, for the skill command
|
|
7
|
+
* node doctor.mjs --fix # apply the mechanical migrations only
|
|
8
|
+
* node doctor.mjs --target <path> # pick a monorepo workspace
|
|
9
|
+
*
|
|
10
|
+
* The boot check in context.mjs reports what a session can afford to measure.
|
|
11
|
+
* This runs everything: git drift, per-workspace sweep, ignore-list validation
|
|
12
|
+
* against the live rule registry, hook script resolution.
|
|
13
|
+
*
|
|
14
|
+
* `--fix` is deliberately narrow. It performs only the migrations marked
|
|
15
|
+
* severity 'auto', the ones with no judgment in them: stamp the product record,
|
|
16
|
+
* move a sidecar out of a retired location. Anything that needs an answer from
|
|
17
|
+
* the user (a platform value, whether an inherited record still describes an
|
|
18
|
+
* app, whether a document has drifted from the code) is reported and left
|
|
19
|
+
* alone. Exit code is 0 unless the run itself failed; findings are not errors.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import fs from 'node:fs';
|
|
23
|
+
import path from 'node:path';
|
|
24
|
+
import { fileURLToPath } from 'node:url';
|
|
25
|
+
|
|
26
|
+
import { loadContext, extractPlatform, resolveTargetSelection } from './context.mjs';
|
|
27
|
+
import { parseTargetOptions } from './lib/target-args.mjs';
|
|
28
|
+
import { IMPECCABLE_COMMAND, IMPECCABLE_PROVIDER_ID } from './lib/provider.mjs';
|
|
29
|
+
import { parseDesignMd } from './lib/design-parser.mjs';
|
|
30
|
+
import {
|
|
31
|
+
PRODUCT_SCHEMA_VERSION,
|
|
32
|
+
readProductSchemaVersion,
|
|
33
|
+
stampProductSchema,
|
|
34
|
+
} from './lib/artifact-schema.mjs';
|
|
35
|
+
import {
|
|
36
|
+
checkConfig,
|
|
37
|
+
checkDesignSidecar,
|
|
38
|
+
checkNativePlatformEvidence,
|
|
39
|
+
checkProduct,
|
|
40
|
+
checkProjectRoots,
|
|
41
|
+
checkSurfaceBriefs,
|
|
42
|
+
designSidecarCandidatesFor,
|
|
43
|
+
} from './lib/staleness.mjs';
|
|
44
|
+
import {
|
|
45
|
+
checkDesignCoverage,
|
|
46
|
+
checkDesignDrift,
|
|
47
|
+
checkDetectorIgnores,
|
|
48
|
+
checkHookInstallation,
|
|
49
|
+
checkLegacyLiveState,
|
|
50
|
+
checkWorkspaces,
|
|
51
|
+
loadKnownRuleIds,
|
|
52
|
+
} from './lib/staleness-deep.mjs';
|
|
53
|
+
|
|
54
|
+
const SCRIPTS_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
55
|
+
|
|
56
|
+
function safeRead(filePath) {
|
|
57
|
+
try {
|
|
58
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
59
|
+
} catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function parseArgs(argv) {
|
|
65
|
+
const passthrough = [];
|
|
66
|
+
const flags = { json: false, fix: false, help: false };
|
|
67
|
+
for (const arg of argv) {
|
|
68
|
+
if (arg === '--json') flags.json = true;
|
|
69
|
+
else if (arg === '--fix') flags.fix = true;
|
|
70
|
+
else if (arg === '--help' || arg === '-h') flags.help = true;
|
|
71
|
+
else passthrough.push(arg);
|
|
72
|
+
}
|
|
73
|
+
return { flags, targetOptions: parseTargetOptions(passthrough, { strict: true }) };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function usage() {
|
|
77
|
+
return [
|
|
78
|
+
`Usage: node doctor.mjs [--json] [--fix] [--target <path>]`,
|
|
79
|
+
'',
|
|
80
|
+
"Report drift between this project's Impeccable artifacts and what the",
|
|
81
|
+
'installed version reads: PRODUCT.md, DESIGN.md and its sidecar,',
|
|
82
|
+
'.impeccable/config.json, surface briefs, and the design hook.',
|
|
83
|
+
'',
|
|
84
|
+
' --json Emit findings as JSON.',
|
|
85
|
+
' --fix Apply the mechanical migrations (severity "auto") only.',
|
|
86
|
+
' --target <path> Select a workspace in a monorepo.',
|
|
87
|
+
].join('\n');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function collect(cwd, targetOptions) {
|
|
91
|
+
const ctx = loadContext(cwd, targetOptions);
|
|
92
|
+
const projectRoot = ctx.projectRoot || cwd;
|
|
93
|
+
const absProductPath = ctx.productPath ? path.resolve(cwd, ctx.productPath) : null;
|
|
94
|
+
const absDesignPath = ctx.designPath ? path.resolve(cwd, ctx.designPath) : null;
|
|
95
|
+
const sidecarCandidates = designSidecarCandidatesFor(projectRoot, ctx.contextDir);
|
|
96
|
+
const knownRuleIds = await loadKnownRuleIds(SCRIPTS_DIR);
|
|
97
|
+
|
|
98
|
+
const selection = resolveTargetSelection(cwd, targetOptions);
|
|
99
|
+
const workspaceCandidates = selection?.targetCandidates || [];
|
|
100
|
+
|
|
101
|
+
const workspaceResult = checkWorkspaces({
|
|
102
|
+
repoRoot: ctx.repoRoot,
|
|
103
|
+
candidates: workspaceCandidates,
|
|
104
|
+
checkNativePlatformEvidence,
|
|
105
|
+
extractPlatform,
|
|
106
|
+
readFile: safeRead,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const findings = [
|
|
110
|
+
...checkProduct(ctx.product, ctx.productPath || 'PRODUCT.md'),
|
|
111
|
+
...(ctx.product
|
|
112
|
+
? checkNativePlatformEvidence({
|
|
113
|
+
projectRoot,
|
|
114
|
+
platform: ctx.platform,
|
|
115
|
+
product: ctx.product,
|
|
116
|
+
productPath: ctx.productPath,
|
|
117
|
+
})
|
|
118
|
+
: []),
|
|
119
|
+
...checkDesignSidecar({ designPath: absDesignPath, sidecarCandidates, projectRoot }),
|
|
120
|
+
...checkDesignDrift({ designPath: absDesignPath, projectRoot }),
|
|
121
|
+
...checkDesignCoverage({ design: ctx.design, designPath: ctx.designPath, parseDesignMd }),
|
|
122
|
+
...checkConfig({ projectRoot, repoRoot: ctx.repoRoot }),
|
|
123
|
+
...checkDetectorIgnores({ projectRoot, knownRuleIds }),
|
|
124
|
+
...checkSurfaceBriefs({ candidates: ctx.surfaceBriefCandidates, projectRoot }),
|
|
125
|
+
...checkHookInstallation({
|
|
126
|
+
projectRoot,
|
|
127
|
+
repoRoot: ctx.repoRoot,
|
|
128
|
+
providerId: IMPECCABLE_PROVIDER_ID,
|
|
129
|
+
}),
|
|
130
|
+
...checkLegacyLiveState({ projectRoot }),
|
|
131
|
+
...checkProjectRoots({
|
|
132
|
+
patterns: readProjectRootPatterns(ctx.repoRoot),
|
|
133
|
+
candidates: workspaceCandidates,
|
|
134
|
+
}),
|
|
135
|
+
...workspaceResult.findings,
|
|
136
|
+
];
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
ctx,
|
|
140
|
+
projectRoot,
|
|
141
|
+
absProductPath,
|
|
142
|
+
sidecarCandidates,
|
|
143
|
+
findings,
|
|
144
|
+
workspaces: workspaceResult.workspaces,
|
|
145
|
+
ruleRegistryAvailable: knownRuleIds !== null,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Read straight from disk rather than importing context.mjs's private reader.
|
|
150
|
+
// Only the positive/negative pattern strings matter here.
|
|
151
|
+
function readProjectRootPatterns(repoRoot) {
|
|
152
|
+
if (!repoRoot) return [];
|
|
153
|
+
const patterns = [];
|
|
154
|
+
for (const name of ['config.json', 'config.local.json']) {
|
|
155
|
+
try {
|
|
156
|
+
const raw = JSON.parse(fs.readFileSync(path.join(repoRoot, '.impeccable', name), 'utf-8'));
|
|
157
|
+
if (Array.isArray(raw?.projectRoots)) {
|
|
158
|
+
for (const entry of raw.projectRoots) {
|
|
159
|
+
if (typeof entry === 'string' && entry.trim()) patterns.push(entry.trim());
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
} catch { /* missing or malformed: nothing to check */ }
|
|
163
|
+
}
|
|
164
|
+
return patterns;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Apply the migrations that carry no decision. Returns what was done and what
|
|
169
|
+
* was deliberately left for the user.
|
|
170
|
+
*/
|
|
171
|
+
function applyFixes(report) {
|
|
172
|
+
const applied = [];
|
|
173
|
+
const skipped = [];
|
|
174
|
+
|
|
175
|
+
for (const entry of report.findings) {
|
|
176
|
+
if (entry.severity !== 'auto') {
|
|
177
|
+
skipped.push({ id: entry.id, reason: 'needs a decision from the user' });
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (entry.id === 'design-sidecar-legacy-path') {
|
|
181
|
+
const canonical = report.sidecarCandidates[0];
|
|
182
|
+
const present = report.sidecarCandidates.find((candidate) => fs.existsSync(candidate));
|
|
183
|
+
if (!canonical || !present || path.resolve(canonical) === path.resolve(present)) continue;
|
|
184
|
+
if (fs.existsSync(canonical)) {
|
|
185
|
+
skipped.push({ id: entry.id, reason: `${rel(canonical, report.projectRoot)} already exists; not overwriting` });
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
fs.mkdirSync(path.dirname(canonical), { recursive: true });
|
|
189
|
+
fs.renameSync(present, canonical);
|
|
190
|
+
applied.push(`Moved ${rel(present, report.projectRoot)} to ${rel(canonical, report.projectRoot)}.`);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (entry.id === 'legacy-live-state') {
|
|
194
|
+
// Reported, never deleted here: a running live session still reads these,
|
|
195
|
+
// and losing session state to a doctor run is a worse outcome than a
|
|
196
|
+
// stale file. The report says what to remove and when.
|
|
197
|
+
skipped.push({ id: entry.id, reason: 'delete by hand once no live session is running' });
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
skipped.push({ id: entry.id, reason: 'no automatic migration implemented' });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Stamping the product record is additive and safe, and it is what stops a
|
|
204
|
+
// later version proposing an interview the user has already sat through.
|
|
205
|
+
const productPath = report.absProductPath;
|
|
206
|
+
if (productPath && report.ctx.product && readProductSchemaVersion(report.ctx.product) === null
|
|
207
|
+
&& !report.findings.some((entry) => entry.id === 'product-schema-legacy')) {
|
|
208
|
+
fs.writeFileSync(productPath, stampProductSchema(report.ctx.product), 'utf-8');
|
|
209
|
+
applied.push(`Stamped ${rel(productPath, report.projectRoot)} as product-schema ${PRODUCT_SCHEMA_VERSION}.`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return { applied, skipped };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function rel(filePath, root) {
|
|
216
|
+
const value = path.relative(root, filePath);
|
|
217
|
+
return value && !value.startsWith('..') ? value.split(path.sep).join('/') : filePath;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const SEVERITY_LABEL = {
|
|
221
|
+
auto: 'automatic',
|
|
222
|
+
mention: 'worth saying',
|
|
223
|
+
route: 'needs a command',
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
function renderText(report, fixes) {
|
|
227
|
+
const lines = [];
|
|
228
|
+
const { findings } = report;
|
|
229
|
+
|
|
230
|
+
lines.push(`Impeccable doctor: ${rel(report.projectRoot, process.cwd()) || '.'}`);
|
|
231
|
+
if (report.ctx.isMonorepo) {
|
|
232
|
+
lines.push(`Monorepo, repo root ${rel(report.ctx.repoRoot, process.cwd()) || '.'}.`);
|
|
233
|
+
}
|
|
234
|
+
lines.push('');
|
|
235
|
+
|
|
236
|
+
if (!findings.length) {
|
|
237
|
+
lines.push('No drift found. Every artifact matches what this version reads.');
|
|
238
|
+
} else {
|
|
239
|
+
const order = ['route', 'mention', 'auto'];
|
|
240
|
+
for (const severity of order) {
|
|
241
|
+
const group = findings.filter((entry) => entry.severity === severity);
|
|
242
|
+
if (!group.length) continue;
|
|
243
|
+
lines.push(`${SEVERITY_LABEL[severity]} (${group.length}):`);
|
|
244
|
+
for (const entry of group) {
|
|
245
|
+
lines.push(` ${entry.id}${entry.path ? ` [${entry.path}]` : ''}`);
|
|
246
|
+
lines.push(` ${entry.summary}`);
|
|
247
|
+
lines.push(` → ${entry.fix}`);
|
|
248
|
+
}
|
|
249
|
+
lines.push('');
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (report.workspaces.length) {
|
|
254
|
+
lines.push('Workspaces:');
|
|
255
|
+
for (const workspace of report.workspaces) {
|
|
256
|
+
lines.push(` ${workspace.path} product: ${workspace.productStatus}`
|
|
257
|
+
+ ` design: ${workspace.designStatus}`
|
|
258
|
+
+ `${workspace.platform ? ` platform: ${workspace.platform}` : ''}`);
|
|
259
|
+
}
|
|
260
|
+
lines.push('');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (!report.ruleRegistryAvailable) {
|
|
264
|
+
lines.push('Note: the bundled detector could not be resolved, so ignored rule ids were not validated.');
|
|
265
|
+
lines.push('');
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (fixes) {
|
|
269
|
+
lines.push(fixes.applied.length ? 'Applied:' : 'Applied nothing.');
|
|
270
|
+
for (const entry of fixes.applied) lines.push(` ${entry}`);
|
|
271
|
+
const held = fixes.skipped.filter((entry) => entry.reason !== 'needs a decision from the user');
|
|
272
|
+
if (held.length) {
|
|
273
|
+
lines.push('Left alone:');
|
|
274
|
+
for (const entry of held) lines.push(` ${entry.id}: ${entry.reason}`);
|
|
275
|
+
}
|
|
276
|
+
} else if (findings.some((entry) => entry.severity === 'auto')) {
|
|
277
|
+
lines.push(`Run \`node doctor.mjs --fix\` to apply the automatic migrations, `
|
|
278
|
+
+ `or \`${IMPECCABLE_COMMAND} doctor\` to work through all of them.`);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return lines.join('\n');
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async function cli() {
|
|
285
|
+
let parsed;
|
|
286
|
+
try {
|
|
287
|
+
parsed = parseArgs(process.argv.slice(2));
|
|
288
|
+
} catch (err) {
|
|
289
|
+
process.stderr.write(`${err.message}\n`);
|
|
290
|
+
process.exit(1);
|
|
291
|
+
}
|
|
292
|
+
if (parsed.flags.help) {
|
|
293
|
+
process.stdout.write(`${usage()}\n`);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const report = await collect(process.cwd(), parsed.targetOptions);
|
|
298
|
+
const fixes = parsed.flags.fix ? applyFixes(report) : null;
|
|
299
|
+
|
|
300
|
+
if (parsed.flags.json) {
|
|
301
|
+
process.stdout.write(`${JSON.stringify({
|
|
302
|
+
projectRoot: report.projectRoot,
|
|
303
|
+
repoRoot: report.ctx.repoRoot,
|
|
304
|
+
isMonorepo: report.ctx.isMonorepo,
|
|
305
|
+
productPath: report.ctx.productPath,
|
|
306
|
+
designPath: report.ctx.designPath,
|
|
307
|
+
platform: report.ctx.platform,
|
|
308
|
+
ruleRegistryAvailable: report.ruleRegistryAvailable,
|
|
309
|
+
findings: report.findings,
|
|
310
|
+
workspaces: report.workspaces,
|
|
311
|
+
...(fixes ? { fixes } : {}),
|
|
312
|
+
}, null, 2)}\n`);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
process.stdout.write(`${renderText(report, fixes)}\n`);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function invokedAsScript() {
|
|
320
|
+
const arg = process.argv[1];
|
|
321
|
+
if (!arg) return false;
|
|
322
|
+
try {
|
|
323
|
+
return fs.realpathSync(arg) === fs.realpathSync(fileURLToPath(import.meta.url));
|
|
324
|
+
} catch {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (invokedAsScript()) {
|
|
330
|
+
cli().catch((err) => {
|
|
331
|
+
process.stderr.write(`impeccable doctor failed: ${err?.message || err}\n`);
|
|
332
|
+
process.exit(1);
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export { collect, applyFixes, renderText };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Embed a generation prompt into an image so the intent travels with the file,
|
|
3
|
+
// across harnesses and machines. Read it back with --read.
|
|
4
|
+
//
|
|
5
|
+
// node embed-prompt.mjs <image> --prompt "the prompt text"
|
|
6
|
+
// node embed-prompt.mjs <image> --prompt-file prompt.txt
|
|
7
|
+
// node embed-prompt.mjs <image> --read
|
|
8
|
+
//
|
|
9
|
+
// Formats: PNG (tEXt chunk, keyword "impeccable:prompt"), JPEG (COM segment).
|
|
10
|
+
// WebP and anything else fall back to a `<image>.json` sidecar; --read checks
|
|
11
|
+
// the sidecar for every format, so the fallback stays recoverable. Embedding
|
|
12
|
+
// rewrites a few MB at most: latency is milliseconds, generation is minutes.
|
|
13
|
+
// Caveat worth knowing: image optimizers in build pipelines often strip
|
|
14
|
+
// metadata from their OUTPUT files; the intent lives on the source asset,
|
|
15
|
+
// which is the one a builder reads.
|
|
16
|
+
|
|
17
|
+
import fs from 'node:fs';
|
|
18
|
+
import zlib from 'node:zlib';
|
|
19
|
+
|
|
20
|
+
const KEYWORD = 'impeccable:prompt';
|
|
21
|
+
const args = process.argv.slice(2);
|
|
22
|
+
const file = args.find(a => !a.startsWith('--'));
|
|
23
|
+
const readMode = args.includes('--read');
|
|
24
|
+
const argOf = (name) => { const i = args.indexOf(name); return i !== -1 ? args[i + 1] : null; };
|
|
25
|
+
|
|
26
|
+
if (!file || !fs.existsSync(file)) { console.error('embed-prompt: image file required'); process.exit(1); }
|
|
27
|
+
|
|
28
|
+
const buf = fs.readFileSync(file);
|
|
29
|
+
const isPng = buf.length > 8 && buf.readUInt32BE(0) === 0x89504e47;
|
|
30
|
+
const isJpeg = buf.length > 3 && buf[0] === 0xff && buf[1] === 0xd8;
|
|
31
|
+
|
|
32
|
+
const crcTable = (() => {
|
|
33
|
+
const t = new Uint32Array(256);
|
|
34
|
+
for (let n = 0; n < 256; n++) { let c = n; for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; t[n] = c >>> 0; }
|
|
35
|
+
return t;
|
|
36
|
+
})();
|
|
37
|
+
const crc32 = (data) => { let c = 0xffffffff; for (const b of data) c = crcTable[(c ^ b) & 0xff] ^ (c >>> 8); return (c ^ 0xffffffff) >>> 0; };
|
|
38
|
+
|
|
39
|
+
function pngChunk(type, data) {
|
|
40
|
+
const out = Buffer.alloc(12 + data.length);
|
|
41
|
+
out.writeUInt32BE(data.length, 0);
|
|
42
|
+
out.write(type, 4, 'ascii');
|
|
43
|
+
data.copy(out, 8);
|
|
44
|
+
out.writeUInt32BE(crc32(Buffer.concat([Buffer.from(type, 'ascii'), data])), 8 + data.length);
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function readPngText(b) {
|
|
49
|
+
let off = 8;
|
|
50
|
+
while (off + 12 <= b.length) {
|
|
51
|
+
const len = b.readUInt32BE(off);
|
|
52
|
+
const type = b.toString('ascii', off + 4, off + 8);
|
|
53
|
+
if (type === 'tEXt' || type === 'zTXt') {
|
|
54
|
+
const data = b.subarray(off + 8, off + 8 + len);
|
|
55
|
+
const nul = data.indexOf(0);
|
|
56
|
+
if (nul !== -1 && data.toString('latin1', 0, nul) === KEYWORD) {
|
|
57
|
+
if (type === 'tEXt') return data.toString('utf8', nul + 1);
|
|
58
|
+
return zlib.inflateSync(data.subarray(nul + 2)).toString('utf8');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
off += 12 + len;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function readJpegCom(b) {
|
|
67
|
+
let off = 2;
|
|
68
|
+
while (off + 4 <= b.length && b[off] === 0xff) {
|
|
69
|
+
const marker = b[off + 1];
|
|
70
|
+
if (marker === 0xda) break; // start of scan: no more segments
|
|
71
|
+
const len = b.readUInt16BE(off + 2);
|
|
72
|
+
if (marker === 0xfe) {
|
|
73
|
+
const text = b.toString('utf8', off + 4, off + 2 + len);
|
|
74
|
+
if (text.startsWith(KEYWORD + '\0')) return text.slice(KEYWORD.length + 1);
|
|
75
|
+
}
|
|
76
|
+
off += 2 + len;
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const sidecar = `${file}.json`;
|
|
82
|
+
if (readMode) {
|
|
83
|
+
let prompt = null;
|
|
84
|
+
if (isPng) prompt = readPngText(buf);
|
|
85
|
+
else if (isJpeg) prompt = readJpegCom(buf);
|
|
86
|
+
if (prompt == null && fs.existsSync(sidecar)) {
|
|
87
|
+
try { prompt = JSON.parse(fs.readFileSync(sidecar, 'utf8')).prompt ?? null; } catch { /* fall through */ }
|
|
88
|
+
}
|
|
89
|
+
if (prompt == null) { console.error('embed-prompt: no embedded prompt found'); process.exit(2); }
|
|
90
|
+
console.log(prompt);
|
|
91
|
+
process.exit(0);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const prompt = argOf('--prompt') ?? (argOf('--prompt-file') ? fs.readFileSync(argOf('--prompt-file'), 'utf8') : null);
|
|
95
|
+
if (!prompt) { console.error('embed-prompt: --prompt or --prompt-file required'); process.exit(1); }
|
|
96
|
+
|
|
97
|
+
if (isPng) {
|
|
98
|
+
// Insert (or replace) our tEXt chunk immediately before IEND.
|
|
99
|
+
const iend = buf.indexOf(Buffer.from('IEND', 'ascii')) - 4;
|
|
100
|
+
if (iend < 8) { console.error('embed-prompt: malformed PNG'); process.exit(1); }
|
|
101
|
+
// Drop any existing chunk with our keyword to keep embedding idempotent.
|
|
102
|
+
let body = buf.subarray(8, iend);
|
|
103
|
+
const existing = readPngText(buf);
|
|
104
|
+
if (existing != null) {
|
|
105
|
+
const parts = [];
|
|
106
|
+
let off = 8;
|
|
107
|
+
while (off + 12 <= buf.length && off < iend + 12) {
|
|
108
|
+
const len = buf.readUInt32BE(off);
|
|
109
|
+
const type = buf.toString('ascii', off + 4, off + 8);
|
|
110
|
+
const chunk = buf.subarray(off, off + 12 + len);
|
|
111
|
+
const data = buf.subarray(off + 8, off + 8 + len);
|
|
112
|
+
const nul = data.indexOf(0);
|
|
113
|
+
const ours = (type === 'tEXt' || type === 'zTXt') && nul !== -1 && data.toString('latin1', 0, nul) === KEYWORD;
|
|
114
|
+
if (!ours && type !== 'IEND') parts.push(chunk);
|
|
115
|
+
off += 12 + len;
|
|
116
|
+
}
|
|
117
|
+
body = Buffer.concat(parts).subarray(8 * 0); // parts exclude signature
|
|
118
|
+
fs.writeFileSync(file, Buffer.concat([buf.subarray(0, 8), body, pngChunk('tEXt', Buffer.concat([Buffer.from(KEYWORD, 'latin1'), Buffer.from([0]), Buffer.from(prompt, 'utf8')])), pngChunk('IEND', Buffer.alloc(0))]));
|
|
119
|
+
} else {
|
|
120
|
+
fs.writeFileSync(file, Buffer.concat([buf.subarray(0, iend), pngChunk('tEXt', Buffer.concat([Buffer.from(KEYWORD, 'latin1'), Buffer.from([0]), Buffer.from(prompt, 'utf8')])), buf.subarray(iend)]));
|
|
121
|
+
}
|
|
122
|
+
console.log(`EMBEDDED: ${file} (png tEXt, ${prompt.length} chars)`);
|
|
123
|
+
} else if (isJpeg) {
|
|
124
|
+
const seg = Buffer.from(`${KEYWORD}\0${prompt}`, 'utf8');
|
|
125
|
+
if (seg.length + 2 > 0xffff) { console.error('embed-prompt: prompt too long for a JPEG segment'); process.exit(1); }
|
|
126
|
+
const com = Buffer.alloc(4 + seg.length);
|
|
127
|
+
com[0] = 0xff; com[1] = 0xfe; com.writeUInt16BE(seg.length + 2, 2); seg.copy(com, 4);
|
|
128
|
+
fs.writeFileSync(file, Buffer.concat([buf.subarray(0, 2), com, buf.subarray(2)]));
|
|
129
|
+
console.log(`EMBEDDED: ${file} (jpeg COM, ${prompt.length} chars)`);
|
|
130
|
+
} else {
|
|
131
|
+
fs.writeFileSync(sidecar, JSON.stringify({ prompt, createdAt: new Date().toISOString() }, null, 2));
|
|
132
|
+
console.log(`EMBEDDED: ${sidecar} (sidecar fallback for this format)`);
|
|
133
|
+
}
|