@phnx-labs/artifacts-cli 0.4.7 → 0.6.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/CHANGELOG.md +135 -1
- package/README.md +161 -10
- package/dist/cli.d.ts +1 -6
- package/dist/cli.js +100 -88
- package/dist/cli.js.map +1 -1
- package/dist/commands/auth.d.ts +5 -0
- package/dist/commands/auth.js +112 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/favorite.d.ts +9 -0
- package/dist/commands/favorite.js +59 -0
- package/dist/commands/favorite.js.map +1 -0
- package/dist/commands/share.d.ts +297 -14
- package/dist/commands/share.js +1351 -71
- package/dist/commands/share.js.map +1 -1
- package/dist/lib/browser-detect.d.ts +28 -0
- package/dist/lib/browser-detect.js +126 -0
- package/dist/lib/browser-detect.js.map +1 -0
- package/dist/lib/components.d.ts +23 -0
- package/dist/lib/components.js +44 -0
- package/dist/lib/components.js.map +1 -0
- package/dist/lib/config.d.ts +17 -0
- package/dist/lib/config.js +8 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/embedded-html.d.ts +1 -1
- package/dist/lib/embedded-html.js +14 -0
- package/dist/lib/embedded-html.js.map +1 -1
- package/dist/lib/excerpt.d.ts +48 -0
- package/dist/lib/excerpt.js +167 -0
- package/dist/lib/excerpt.js.map +1 -0
- package/dist/lib/explorer.d.ts +37 -0
- package/dist/lib/explorer.js +166 -0
- package/dist/lib/explorer.js.map +1 -0
- package/dist/lib/favorites.d.ts +73 -0
- package/dist/lib/favorites.js +180 -0
- package/dist/lib/favorites.js.map +1 -0
- package/dist/lib/format.d.ts +2 -0
- package/dist/lib/format.js +14 -0
- package/dist/lib/format.js.map +1 -0
- package/dist/lib/github.d.ts +14 -0
- package/dist/lib/github.js +36 -0
- package/dist/lib/github.js.map +1 -0
- package/dist/lib/header-actions.d.ts +44 -0
- package/dist/lib/header-actions.js +181 -0
- package/dist/lib/header-actions.js.map +1 -0
- package/dist/lib/identity/client.d.ts +49 -0
- package/dist/lib/identity/client.js +97 -0
- package/dist/lib/identity/client.js.map +1 -0
- package/dist/lib/identity/index.d.ts +60 -0
- package/dist/lib/identity/index.js +69 -0
- package/dist/lib/identity/index.js.map +1 -0
- package/dist/lib/link-previews.d.ts +67 -0
- package/dist/lib/link-previews.js +427 -0
- package/dist/lib/link-previews.js.map +1 -0
- package/dist/lib/links.d.ts +2 -0
- package/dist/lib/links.js +21 -2
- package/dist/lib/links.js.map +1 -1
- package/dist/lib/math.d.ts +31 -0
- package/dist/lib/math.js +122 -0
- package/dist/lib/math.js.map +1 -0
- package/dist/lib/metadata-menu.d.ts +15 -0
- package/dist/lib/metadata-menu.js +23 -0
- package/dist/lib/metadata-menu.js.map +1 -1
- package/dist/lib/open.d.ts +6 -0
- package/dist/lib/open.js +54 -0
- package/dist/lib/open.js.map +1 -0
- package/dist/lib/render.d.ts +5 -0
- package/dist/lib/render.js +166 -35
- package/dist/lib/render.js.map +1 -1
- package/dist/lib/revisions.d.ts +17 -0
- package/dist/lib/revisions.js +6 -1
- package/dist/lib/revisions.js.map +1 -1
- package/dist/lib/share/analytics.d.ts +13 -0
- package/dist/lib/share/analytics.js +46 -0
- package/dist/lib/share/analytics.js.map +1 -0
- package/dist/lib/share/backend.d.ts +105 -0
- package/dist/lib/share/backend.js +161 -0
- package/dist/lib/share/backend.js.map +1 -0
- package/dist/lib/share/capture.d.ts +31 -0
- package/dist/lib/share/capture.js +175 -0
- package/dist/lib/share/capture.js.map +1 -0
- package/dist/lib/share/config.d.ts +82 -0
- package/dist/lib/share/config.js +181 -0
- package/dist/lib/share/config.js.map +1 -0
- package/dist/lib/share/delete.d.ts +122 -0
- package/dist/lib/share/delete.js +174 -0
- package/dist/lib/share/delete.js.map +1 -0
- package/dist/lib/share/html.d.ts +22 -0
- package/dist/lib/share/html.js +89 -0
- package/dist/lib/share/html.js.map +1 -0
- package/dist/lib/share/http-error.d.ts +52 -0
- package/dist/lib/share/http-error.js +66 -0
- package/dist/lib/share/http-error.js.map +1 -0
- package/dist/lib/share/og.d.ts +25 -0
- package/dist/lib/share/og.js +85 -0
- package/dist/lib/share/og.js.map +1 -0
- package/dist/lib/share/provision.d.ts +99 -0
- package/dist/lib/share/provision.js +271 -0
- package/dist/lib/share/provision.js.map +1 -0
- package/dist/lib/share/publish.d.ts +393 -0
- package/dist/lib/share/publish.js +829 -0
- package/dist/lib/share/publish.js.map +1 -0
- package/dist/lib/share/qr.d.ts +36 -0
- package/dist/lib/share/qr.js +102 -0
- package/dist/lib/share/qr.js.map +1 -0
- package/dist/lib/share/storage-policy.d.ts +9 -0
- package/dist/lib/share/storage-policy.js +43 -0
- package/dist/lib/share/storage-policy.js.map +1 -0
- package/dist/lib/share/visibility.d.ts +92 -0
- package/dist/lib/share/visibility.js +108 -0
- package/dist/lib/share/visibility.js.map +1 -0
- package/dist/lib/share/worker-template.d.ts +29 -0
- package/dist/lib/share/worker-template.js +2154 -0
- package/dist/lib/share/worker-template.js.map +1 -0
- package/dist/lib/status-list.d.ts +49 -0
- package/dist/lib/status-list.js +153 -0
- package/dist/lib/status-list.js.map +1 -0
- package/dist/lib/validate.js +128 -9
- package/dist/lib/validate.js.map +1 -1
- package/package.json +12 -3
- package/dist/lib/share-provision.d.ts +0 -31
- package/dist/lib/share-provision.js +0 -83
- package/dist/lib/share-provision.js.map +0 -1
- package/dist/lib/share-worker.d.ts +0 -1
- package/dist/lib/share-worker.js +0 -66
- package/dist/lib/share-worker.js.map +0 -1
- package/dist/lib/share.d.ts +0 -39
- package/dist/lib/share.js +0 -159
- package/dist/lib/share.js.map +0 -1
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
5
|
+
import { escapeHtml } from './html.js';
|
|
6
|
+
export function isExcerptFence(info) {
|
|
7
|
+
return /^excerpt(\s|$)/.test(info.trim());
|
|
8
|
+
}
|
|
9
|
+
function parseRange(value, label) {
|
|
10
|
+
const m = value.match(/^(\d+)(?:-(\d+))?$/);
|
|
11
|
+
if (!m)
|
|
12
|
+
return `${label} must be N or N-M, got "${value}"`;
|
|
13
|
+
const a = Number(m[1]);
|
|
14
|
+
const b = m[2] ? Number(m[2]) : a;
|
|
15
|
+
if (a < 1 || b < a)
|
|
16
|
+
return `${label} must be an ascending 1-based range, got "${value}"`;
|
|
17
|
+
return [a, b];
|
|
18
|
+
}
|
|
19
|
+
/** Parse the info string; returns the spec or a list of problems. */
|
|
20
|
+
export function parseExcerptInfo(info) {
|
|
21
|
+
const errors = [];
|
|
22
|
+
const attrs = {};
|
|
23
|
+
for (const token of info.trim().split(/\s+/).slice(1)) {
|
|
24
|
+
const eq = token.indexOf('=');
|
|
25
|
+
if (eq <= 0) {
|
|
26
|
+
errors.push(`excerpt attribute "${token}" is not key=value`);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
attrs[token.slice(0, eq)] = token.slice(eq + 1).replace(/^"|"$/g, '');
|
|
30
|
+
}
|
|
31
|
+
if (!attrs.path)
|
|
32
|
+
errors.push('excerpt needs path=<file>');
|
|
33
|
+
if (!attrs.lines)
|
|
34
|
+
errors.push('excerpt needs lines=A-B');
|
|
35
|
+
let lines;
|
|
36
|
+
let highlight;
|
|
37
|
+
if (attrs.lines) {
|
|
38
|
+
const r = parseRange(attrs.lines, 'lines');
|
|
39
|
+
if (typeof r === 'string')
|
|
40
|
+
errors.push(`excerpt ${r}`);
|
|
41
|
+
else
|
|
42
|
+
lines = r;
|
|
43
|
+
}
|
|
44
|
+
if (attrs.highlight) {
|
|
45
|
+
const r = parseRange(attrs.highlight, 'highlight');
|
|
46
|
+
if (typeof r === 'string')
|
|
47
|
+
errors.push(`excerpt ${r}`);
|
|
48
|
+
else
|
|
49
|
+
highlight = r;
|
|
50
|
+
}
|
|
51
|
+
if (lines && highlight && (highlight[0] < lines[0] || highlight[1] > lines[1])) {
|
|
52
|
+
errors.push(`excerpt highlight=${attrs.highlight} falls outside lines=${attrs.lines}`);
|
|
53
|
+
}
|
|
54
|
+
if (attrs.repo && !/^[\w.-]+\/[\w.-]+$/.test(attrs.repo))
|
|
55
|
+
errors.push(`excerpt repo must be org/name, got "${attrs.repo}"`);
|
|
56
|
+
if (errors.length || !lines || !attrs.path)
|
|
57
|
+
return { errors };
|
|
58
|
+
return { spec: { path: attrs.path, lines, highlight, repo: attrs.repo, ref: attrs.ref }, errors };
|
|
59
|
+
}
|
|
60
|
+
function findRepoRoot(start) {
|
|
61
|
+
let dir = resolve(start);
|
|
62
|
+
for (;;) {
|
|
63
|
+
if (existsSync(join(dir, '.git')))
|
|
64
|
+
return dir;
|
|
65
|
+
const parent = dirname(dir);
|
|
66
|
+
if (parent === dir)
|
|
67
|
+
return undefined;
|
|
68
|
+
dir = parent;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function git(root, args) {
|
|
72
|
+
try {
|
|
73
|
+
return execFileSync('git', ['-C', root, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || undefined;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function githubRepo(root) {
|
|
80
|
+
const url = git(root, ['config', '--get', 'remote.origin.url']);
|
|
81
|
+
const m = url?.match(/github\.com[:/]([\w.-]+\/[\w.-]+?)(?:\.git)?$/);
|
|
82
|
+
return m?.[1];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Resolve the excerpt's file from the artifact's directory: an absolute path or
|
|
86
|
+
* `~/` as given; otherwise relative to the enclosing git root, then the artifact
|
|
87
|
+
* directory, then the home directory. Returns the lines or a problem string.
|
|
88
|
+
*
|
|
89
|
+
* Confinement: the resolved file (symlinks followed) must be tracked by git in
|
|
90
|
+
* the checkout that contains it, and that checkout must be the artifact's own
|
|
91
|
+
* unless the fence names it with `repo=org/name` matching its origin. That is
|
|
92
|
+
* what makes the card citable at a commit, keeps `~/.ssh/id_rsa`, `.env`, or
|
|
93
|
+
* any untracked file out of a page that may later be published, and makes a
|
|
94
|
+
* citation into a sibling checkout an explicit, reviewable choice.
|
|
95
|
+
*/
|
|
96
|
+
export function resolveExcerpt(baseDir, spec) {
|
|
97
|
+
const expanded = spec.path.startsWith('~/') ? join(homedir(), spec.path.slice(2)) : spec.path;
|
|
98
|
+
const gitRoot = findRepoRoot(baseDir);
|
|
99
|
+
const candidates = isAbsolute(expanded)
|
|
100
|
+
? [expanded]
|
|
101
|
+
: [gitRoot ? join(gitRoot, expanded) : undefined, join(baseDir, expanded), join(homedir(), expanded)].filter((c) => Boolean(c));
|
|
102
|
+
const found = candidates.find((c) => existsSync(c));
|
|
103
|
+
if (!found)
|
|
104
|
+
return `excerpt path "${spec.path}" not found (looked under ${gitRoot ?? baseDir})`;
|
|
105
|
+
const absolutePath = realpathSync(found);
|
|
106
|
+
const fileRoot = findRepoRoot(dirname(absolutePath));
|
|
107
|
+
if (!fileRoot)
|
|
108
|
+
return `excerpt path "${spec.path}" is not inside a git checkout; an excerpt cites a tracked file at a commit`;
|
|
109
|
+
const tracked = git(fileRoot, ['ls-files', '--error-unmatch', '--', absolutePath.slice(fileRoot.length + 1)]);
|
|
110
|
+
if (!tracked)
|
|
111
|
+
return `excerpt path "${spec.path}" is not tracked by git in ${fileRoot}; untracked and ignored files cannot be cited`;
|
|
112
|
+
const ownRoot = gitRoot ? realpathSync(gitRoot) : undefined;
|
|
113
|
+
if (fileRoot !== ownRoot) {
|
|
114
|
+
const origin = githubRepo(fileRoot);
|
|
115
|
+
if (!spec.repo)
|
|
116
|
+
return `excerpt path "${spec.path}" lives in another checkout (${fileRoot}); cite it explicitly with repo=${origin ?? '<org/name>'} matching that checkout's origin`;
|
|
117
|
+
if (!origin || origin.toLowerCase() !== spec.repo.toLowerCase())
|
|
118
|
+
return `excerpt repo=${spec.repo} does not match the origin of the checkout holding "${spec.path}" (${origin ?? 'no GitHub origin'})`;
|
|
119
|
+
}
|
|
120
|
+
const all = readFileSync(absolutePath, 'utf8').split(/\r?\n/);
|
|
121
|
+
if (all.length && all[all.length - 1] === '')
|
|
122
|
+
all.pop();
|
|
123
|
+
const [a, b] = spec.lines;
|
|
124
|
+
if (b > all.length)
|
|
125
|
+
return `excerpt lines=${a}-${b} exceed "${spec.path}" (${all.length} lines)`;
|
|
126
|
+
const root = fileRoot;
|
|
127
|
+
const repo = spec.repo ?? githubRepo(root);
|
|
128
|
+
const ref = spec.ref ?? git(root, ['rev-parse', '--short=12', 'HEAD']);
|
|
129
|
+
const rel = absolutePath.startsWith(root + '/') ? absolutePath.slice(root.length + 1) : undefined;
|
|
130
|
+
const href = repo && ref && rel ? `https://github.com/${repo}/blob/${ref}/${rel}#L${a}${b > a ? `-L${b}` : ''}` : undefined;
|
|
131
|
+
return { spec, root, absolutePath, lines: all.slice(a - 1, b), totalLines: all.length, href };
|
|
132
|
+
}
|
|
133
|
+
/** Render the card. Invalid or unresolvable specs return a visible missing card;
|
|
134
|
+
* validate.ts errors before render ever reaches that branch. */
|
|
135
|
+
export function renderExcerpt(baseDir, info, body) {
|
|
136
|
+
const parsed = parseExcerptInfo(info);
|
|
137
|
+
if (!parsed.spec)
|
|
138
|
+
return missingCard(parsed.errors.join('; '));
|
|
139
|
+
const source = resolveExcerpt(baseDir, parsed.spec);
|
|
140
|
+
if (typeof source === 'string')
|
|
141
|
+
return missingCard(source);
|
|
142
|
+
const { spec, lines, href } = source;
|
|
143
|
+
const [a, b] = spec.lines;
|
|
144
|
+
const width = String(b).length;
|
|
145
|
+
const rows = lines.map((text, i) => {
|
|
146
|
+
const n = a + i;
|
|
147
|
+
const hl = spec.highlight && n >= spec.highlight[0] && n <= spec.highlight[1];
|
|
148
|
+
return `<span class="ex-line${hl ? ' ex-hl' : ''}"><span class="ex-no">${String(n).padStart(width, ' ')}</span><span class="ex-code">${escapeHtml(text) || ' '}</span></span>`;
|
|
149
|
+
});
|
|
150
|
+
const label = escapeHtml(spec.path);
|
|
151
|
+
const range = `lines ${a}${b > a ? `–${b}` : ''}`;
|
|
152
|
+
const file = href ? `<a href="${escapeHtml(href)}">${label}</a>` : `<code>${label}</code>`;
|
|
153
|
+
const note = body.trim() ? `<p class="artifact-excerpt-note">${escapeHtml(body.trim().replace(/^verdict:\s*/i, ''))}</p>` : '';
|
|
154
|
+
return `<figure class="artifact-excerpt"><figcaption class="artifact-excerpt-file">${file}<span class="artifact-excerpt-range">${range}</span></figcaption><pre class="artifact-excerpt-pre">${rows.join('')}</pre>${note}</figure>`;
|
|
155
|
+
}
|
|
156
|
+
function missingCard(problem) {
|
|
157
|
+
return `<figure class="artifact-excerpt artifact-excerpt-missing"><figcaption class="artifact-excerpt-file"><code>excerpt</code><span class="artifact-excerpt-range">${escapeHtml(problem)}</span></figcaption></figure>`;
|
|
158
|
+
}
|
|
159
|
+
/** Problems validate.ts reports for one excerpt fence. */
|
|
160
|
+
export function excerptProblems(baseDir, info) {
|
|
161
|
+
const parsed = parseExcerptInfo(info);
|
|
162
|
+
if (!parsed.spec)
|
|
163
|
+
return parsed.errors;
|
|
164
|
+
const source = resolveExcerpt(baseDir, parsed.spec);
|
|
165
|
+
return typeof source === 'string' ? [source] : [];
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=excerpt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excerpt.js","sourceRoot":"","sources":["../../src/lib/excerpt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;A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CAAC;IAC3F,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,oCAAoC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/H,OAAO,8EAA8E,IAAI,wCAAwC,KAAK,yDAAyD,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,IAAI,WAAW,CAAC;AACvO,CAAC;AAED,SAAS,WAAW,CAAC,OAAe;IAClC,OAAO,gKAAgK,UAAU,CAAC,OAAO,CAAC,+BAA+B,CAAC;AAC5N,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,IAAY;IAC3D,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,CAAC,MAAM,CAAC,IAAI;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC;IACvC,MAAM,MAAM,GAAG,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACpD,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface ExplorerItem {
|
|
2
|
+
label: string;
|
|
3
|
+
value?: number;
|
|
4
|
+
detail?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
sources?: Array<{
|
|
7
|
+
label: string;
|
|
8
|
+
href: string;
|
|
9
|
+
}>;
|
|
10
|
+
children?: ExplorerItem[];
|
|
11
|
+
}
|
|
12
|
+
export interface ExplorerData {
|
|
13
|
+
title: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
metric?: {
|
|
16
|
+
label: string;
|
|
17
|
+
unit: string;
|
|
18
|
+
max: number;
|
|
19
|
+
};
|
|
20
|
+
items: ExplorerItem[];
|
|
21
|
+
}
|
|
22
|
+
export declare const EXPLORER_EXAMPLE: ExplorerData;
|
|
23
|
+
/** Strict data only: misspelled fields fail instead of silently dropping evidence. */
|
|
24
|
+
export declare function parseExplorer(source: string): {
|
|
25
|
+
data?: ExplorerData;
|
|
26
|
+
error?: string;
|
|
27
|
+
};
|
|
28
|
+
/** Same lexer as validation: fenced examples, inline code and unknown languages never become controls. */
|
|
29
|
+
export declare function explorerFences(markdown: string): Array<{
|
|
30
|
+
raw: string;
|
|
31
|
+
text: string;
|
|
32
|
+
}>;
|
|
33
|
+
export declare function renderExplorer(source: string): string;
|
|
34
|
+
export declare const EXPLORER_CLASSES: string[];
|
|
35
|
+
export declare const EXPLORER_CSS = "\n.artifact-explorer{margin:var(--figure-spacing) 0;min-width:0}\n.artifact-explorer figcaption{font-size:18px;text-align:left;color:var(--text)}\n.artifact-explorer figcaption p{font-size:16px;font-weight:400;margin:6px 0 12px}\n.artifact-explorer .explorer-scale,.artifact-explorer .explorer-hint{font-size:14px;color:var(--muted);margin:4px 0}\n.artifact-explorer .explorer-list{list-style:none;padding:0;margin:14px 0}\n.artifact-explorer .explorer-list>li{margin:0;border-top:1px solid var(--line)}\n.artifact-explorer details{border:0;margin:0;padding:0;background:none}\n.artifact-explorer summary,.artifact-explorer .explorer-leaf{display:block;list-style:none;padding:16px 12px;font:inherit;color:var(--text);overflow-wrap:anywhere;border-radius:6px}\n.artifact-explorer summary{cursor:pointer}\n.artifact-explorer summary::-webkit-details-marker{display:none}\n.artifact-explorer summary::before,.artifact-explorer summary::after{display:none}\n.artifact-explorer summary:hover{background:var(--surface-alt)}\n.artifact-explorer summary:focus-visible{outline:2px solid var(--accent);outline-offset:2px}\n.artifact-explorer details[open]>summary{background:var(--surface-alt)}\n.explorer-heading{display:flex;align-items:baseline;gap:16px;font-size:16px;line-height:1.5}\n.explorer-heading>strong{flex:1;min-width:0}\n.explorer-value{font-variant-numeric:tabular-nums;font-weight:650;white-space:nowrap}\n.explorer-toggle{font:600 20px/1 monospace;flex:0 0 16px;color:var(--accent)}\n.artifact-explorer details[open]>summary .explorer-toggle{font-size:0}\n.artifact-explorer details[open]>summary .explorer-toggle::after{content:'\u2212';font-size:20px}\n.artifact-explorer .explorer-bar{display:block;width:100%;height:8px;margin:10px 0;border-radius:3px}\n.explorer-detail{display:block;font-size:14px;color:var(--muted);margin-top:5px}\n.artifact-explorer .explorer-content{padding:4px 12px 8px 24px;border-left:2px solid var(--line);margin-left:12px;font-size:16px;overflow-wrap:anywhere}\n.artifact-explorer .explorer-sources{padding-left:20px;font-size:14px}\n@media(max-width:600px){.artifact-explorer .explorer-content{padding-left:12px;margin-left:4px}.explorer-heading{gap:10px}.artifact-explorer summary,.artifact-explorer .explorer-leaf{padding:16px 8px}}\n@media print{.artifact-explorer summary{break-after:avoid}.artifact-explorer .explorer-hint,.explorer-toggle{display:none}}\n";
|
|
36
|
+
/** Native details work offline and without JS. Printing exposes the complete record and restores reading state. */
|
|
37
|
+
export declare const EXPLORER_SCRIPT = "<script>(()=>{\nlet closed=[];\naddEventListener('beforeprint',()=>{closed=[...document.querySelectorAll('.artifact-explorer details:not([open])')];closed.forEach(d=>d.open=true);});\naddEventListener('afterprint',()=>{closed.forEach(d=>d.open=false);closed=[];});\n})();</script>";
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { Marked } from 'marked';
|
|
2
|
+
import { escapeHtml } from './html.js';
|
|
3
|
+
export const EXPLORER_EXAMPLE = {
|
|
4
|
+
title: 'Where the cleanup is',
|
|
5
|
+
description: 'Illustrative data. Estimates are candidates for review, not confirmed deletions.',
|
|
6
|
+
metric: { label: 'Estimated removable share', unit: '%', max: 100 },
|
|
7
|
+
items: [{
|
|
8
|
+
label: 'Web', value: 25, detail: '2,000 of 8,000 lines',
|
|
9
|
+
description: 'Most candidates sit in the legacy editor.',
|
|
10
|
+
children: [{ label: 'Legacy editor', detail: '1,600 lines', description: 'Check remaining imports before removal.' },
|
|
11
|
+
{ label: 'Duplicate helpers', detail: '400 lines', description: 'Consolidate callers first.' }],
|
|
12
|
+
}, { label: 'API', value: 10, detail: '500 of 5,000 lines', description: 'Review unused route adapters.' }],
|
|
13
|
+
};
|
|
14
|
+
const fields = {
|
|
15
|
+
root: ['title', 'description', 'metric', 'items'],
|
|
16
|
+
metric: ['label', 'unit', 'max'],
|
|
17
|
+
item: ['label', 'value', 'detail', 'description', 'sources', 'children'],
|
|
18
|
+
source: ['label', 'href'],
|
|
19
|
+
};
|
|
20
|
+
/** Strict data only: misspelled fields fail instead of silently dropping evidence. */
|
|
21
|
+
export function parseExplorer(source) {
|
|
22
|
+
try {
|
|
23
|
+
if (source.length > 200_000)
|
|
24
|
+
throw new Error('Explorer exceeds 200 KB');
|
|
25
|
+
const data = JSON.parse(source);
|
|
26
|
+
const record = (value, allowed, path) => {
|
|
27
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
28
|
+
throw new Error(`${path} must be an object`);
|
|
29
|
+
for (const key of Object.keys(value))
|
|
30
|
+
if (!allowed.includes(key))
|
|
31
|
+
throw new Error(`${path}.${key} is not supported`);
|
|
32
|
+
};
|
|
33
|
+
const text = (value, path, optional = false) => {
|
|
34
|
+
if (optional && value === undefined)
|
|
35
|
+
return;
|
|
36
|
+
if (typeof value !== 'string' || !value.trim())
|
|
37
|
+
throw new Error(`${path} must be non-empty text`);
|
|
38
|
+
};
|
|
39
|
+
record(data, fields.root, 'explorer');
|
|
40
|
+
text(data.title, 'title');
|
|
41
|
+
text(data.description, 'description', true);
|
|
42
|
+
if (data.metric !== undefined) {
|
|
43
|
+
record(data.metric, fields.metric, 'metric');
|
|
44
|
+
text(data.metric.label, 'metric.label');
|
|
45
|
+
if (typeof data.metric.unit !== 'string')
|
|
46
|
+
throw new Error('metric.unit must be text (use "" for counts)');
|
|
47
|
+
if (!Number.isFinite(data.metric.max) || data.metric.max <= 0)
|
|
48
|
+
throw new Error('metric.max must be a positive finite number');
|
|
49
|
+
}
|
|
50
|
+
let count = 0;
|
|
51
|
+
const items = (values, path, depth) => {
|
|
52
|
+
if (!Array.isArray(values) || !values.length)
|
|
53
|
+
throw new Error(`${path} must be a non-empty array`);
|
|
54
|
+
if (depth > 4)
|
|
55
|
+
throw new Error('Explorer supports at most four levels; split deeper hierarchies into separate figures');
|
|
56
|
+
values.forEach((item, index) => {
|
|
57
|
+
if (++count > 200)
|
|
58
|
+
throw new Error('Explorer supports at most 200 items; move raw records to an appendix');
|
|
59
|
+
const at = `${path}[${index}]`;
|
|
60
|
+
record(item, fields.item, at);
|
|
61
|
+
text(item.label, `${at}.label`);
|
|
62
|
+
text(item.detail, `${at}.detail`, true);
|
|
63
|
+
text(item.description, `${at}.description`, true);
|
|
64
|
+
if (item.value !== undefined) {
|
|
65
|
+
if (!data.metric)
|
|
66
|
+
throw new Error(`${at}.value requires metric with an explicit scale`);
|
|
67
|
+
if (!Number.isFinite(item.value) || item.value < 0 || item.value > data.metric.max)
|
|
68
|
+
throw new Error(`${at}.value must be between 0 and metric.max`);
|
|
69
|
+
}
|
|
70
|
+
else if (depth === 1 && data.metric)
|
|
71
|
+
throw new Error(`${at}.value is required for each top-level item with a metric`);
|
|
72
|
+
if (item.sources !== undefined) {
|
|
73
|
+
if (!Array.isArray(item.sources) || !item.sources.length)
|
|
74
|
+
throw new Error(`${at}.sources must be a non-empty array`);
|
|
75
|
+
item.sources.forEach((link, i) => {
|
|
76
|
+
record(link, fields.source, `${at}.sources[${i}]`);
|
|
77
|
+
text(link.label, `${at}.sources[${i}].label`);
|
|
78
|
+
text(link.href, `${at}.sources[${i}].href`);
|
|
79
|
+
if (!/^#[^\s]+$/.test(link.href)) {
|
|
80
|
+
let url;
|
|
81
|
+
try {
|
|
82
|
+
url = new URL(link.href);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
throw new Error(`${at}.sources[${i}].href must be https, http, or a #section`);
|
|
86
|
+
}
|
|
87
|
+
if (!['https:', 'http:'].includes(url.protocol))
|
|
88
|
+
throw new Error(`${at}.sources[${i}].href must be https, http, or a #section`);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (item.children !== undefined)
|
|
93
|
+
items(item.children, `${at}.children`, depth + 1);
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
items(data.items, 'items', 1);
|
|
97
|
+
return { data };
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Same lexer as validation: fenced examples, inline code and unknown languages never become controls. */
|
|
104
|
+
export function explorerFences(markdown) {
|
|
105
|
+
const found = [];
|
|
106
|
+
const lexer = new Marked();
|
|
107
|
+
lexer.walkTokens(lexer.lexer(markdown), (token) => {
|
|
108
|
+
if (token.type === 'code' && token.lang?.trim() === 'explorer')
|
|
109
|
+
found.push({ raw: token.raw, text: token.text });
|
|
110
|
+
});
|
|
111
|
+
return found;
|
|
112
|
+
}
|
|
113
|
+
export function renderExplorer(source) {
|
|
114
|
+
const { data, error } = parseExplorer(source);
|
|
115
|
+
if (!data)
|
|
116
|
+
return `<p class="artifact-callout artifact-callout-danger">Invalid explorer: ${escapeHtml(error ?? '')}</p>`;
|
|
117
|
+
const renderItems = (items) => `<ul class="explorer-list">${items.map((item) => {
|
|
118
|
+
const expandable = !!(item.description || item.children || item.sources);
|
|
119
|
+
const metric = data.metric;
|
|
120
|
+
// Preserve the supplied number: default locale formatting rounds small measurements to zero.
|
|
121
|
+
const value = item.value === undefined || !metric ? '' : `${String(item.value)}${metric.unit === '%' ? '%' : metric.unit ? ` ${metric.unit}` : ''}`;
|
|
122
|
+
const bar = item.value === undefined || !metric ? '' : `<svg class="explorer-bar" viewBox="0 0 100 2" preserveAspectRatio="none" aria-hidden="true"><rect width="100" height="2" fill="var(--line)"/><rect width="${(item.value / metric.max) * 100}" height="2" fill="var(--accent)"/></svg>`;
|
|
123
|
+
const heading = `<span class="explorer-heading"><strong>${escapeHtml(item.label)}</strong>${value ? `<span class="explorer-value">${escapeHtml(value)}</span>` : ''}${expandable ? '<span class="explorer-toggle" aria-hidden="true">+</span>' : ''}</span>${bar}${item.detail ? `<span class="explorer-detail">${escapeHtml(item.detail)}</span>` : ''}`;
|
|
124
|
+
const content = `${item.description ? `<p>${escapeHtml(item.description)}</p>` : ''}${item.sources ? `<ul class="explorer-sources">${item.sources.map((s) => `<li><a href="${escapeHtml(s.href)}">${escapeHtml(s.label)}</a></li>`).join('')}</ul>` : ''}${item.children ? renderItems(item.children) : ''}`;
|
|
125
|
+
return `<li>${expandable ? `<details><summary>${heading}</summary><div class="explorer-content">${content}</div></details>` : `<div class="explorer-leaf">${heading}</div>`}</li>`;
|
|
126
|
+
}).join('')}</ul>`;
|
|
127
|
+
const hint = data.items.some(item => item.description || item.children || item.sources)
|
|
128
|
+
? '<p class="explorer-hint">Select a + row to explore details and sources.</p>' : '';
|
|
129
|
+
return `<figure class="artifact-explorer" aria-label="${escapeHtml(data.title)}"><figcaption><strong>${escapeHtml(data.title)}</strong>${data.description ? `<p>${escapeHtml(data.description)}</p>` : ''}</figcaption>${data.metric ? `<p class="explorer-scale">${escapeHtml(data.metric.label)} · 0–${escapeHtml(String(data.metric.max))}${data.metric.unit && data.metric.unit !== '%' ? ' ' : ''}${escapeHtml(data.metric.unit)}</p>` : ''}${hint}${renderItems(data.items)}</figure>`;
|
|
130
|
+
}
|
|
131
|
+
export const EXPLORER_CLASSES = ['artifact-explorer', 'explorer-list', 'explorer-heading', 'explorer-value', 'explorer-toggle', 'explorer-bar', 'explorer-detail', 'explorer-content', 'explorer-sources', 'explorer-scale', 'explorer-hint', 'explorer-leaf'];
|
|
132
|
+
export const EXPLORER_CSS = `
|
|
133
|
+
.artifact-explorer{margin:var(--figure-spacing) 0;min-width:0}
|
|
134
|
+
.artifact-explorer figcaption{font-size:18px;text-align:left;color:var(--text)}
|
|
135
|
+
.artifact-explorer figcaption p{font-size:16px;font-weight:400;margin:6px 0 12px}
|
|
136
|
+
.artifact-explorer .explorer-scale,.artifact-explorer .explorer-hint{font-size:14px;color:var(--muted);margin:4px 0}
|
|
137
|
+
.artifact-explorer .explorer-list{list-style:none;padding:0;margin:14px 0}
|
|
138
|
+
.artifact-explorer .explorer-list>li{margin:0;border-top:1px solid var(--line)}
|
|
139
|
+
.artifact-explorer details{border:0;margin:0;padding:0;background:none}
|
|
140
|
+
.artifact-explorer summary,.artifact-explorer .explorer-leaf{display:block;list-style:none;padding:16px 12px;font:inherit;color:var(--text);overflow-wrap:anywhere;border-radius:6px}
|
|
141
|
+
.artifact-explorer summary{cursor:pointer}
|
|
142
|
+
.artifact-explorer summary::-webkit-details-marker{display:none}
|
|
143
|
+
.artifact-explorer summary::before,.artifact-explorer summary::after{display:none}
|
|
144
|
+
.artifact-explorer summary:hover{background:var(--surface-alt)}
|
|
145
|
+
.artifact-explorer summary:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
|
|
146
|
+
.artifact-explorer details[open]>summary{background:var(--surface-alt)}
|
|
147
|
+
.explorer-heading{display:flex;align-items:baseline;gap:16px;font-size:16px;line-height:1.5}
|
|
148
|
+
.explorer-heading>strong{flex:1;min-width:0}
|
|
149
|
+
.explorer-value{font-variant-numeric:tabular-nums;font-weight:650;white-space:nowrap}
|
|
150
|
+
.explorer-toggle{font:600 20px/1 monospace;flex:0 0 16px;color:var(--accent)}
|
|
151
|
+
.artifact-explorer details[open]>summary .explorer-toggle{font-size:0}
|
|
152
|
+
.artifact-explorer details[open]>summary .explorer-toggle::after{content:'−';font-size:20px}
|
|
153
|
+
.artifact-explorer .explorer-bar{display:block;width:100%;height:8px;margin:10px 0;border-radius:3px}
|
|
154
|
+
.explorer-detail{display:block;font-size:14px;color:var(--muted);margin-top:5px}
|
|
155
|
+
.artifact-explorer .explorer-content{padding:4px 12px 8px 24px;border-left:2px solid var(--line);margin-left:12px;font-size:16px;overflow-wrap:anywhere}
|
|
156
|
+
.artifact-explorer .explorer-sources{padding-left:20px;font-size:14px}
|
|
157
|
+
@media(max-width:600px){.artifact-explorer .explorer-content{padding-left:12px;margin-left:4px}.explorer-heading{gap:10px}.artifact-explorer summary,.artifact-explorer .explorer-leaf{padding:16px 8px}}
|
|
158
|
+
@media print{.artifact-explorer summary{break-after:avoid}.artifact-explorer .explorer-hint,.explorer-toggle{display:none}}
|
|
159
|
+
`;
|
|
160
|
+
/** Native details work offline and without JS. Printing exposes the complete record and restores reading state. */
|
|
161
|
+
export const EXPLORER_SCRIPT = `<script>(()=>{
|
|
162
|
+
let closed=[];
|
|
163
|
+
addEventListener('beforeprint',()=>{closed=[...document.querySelectorAll('.artifact-explorer details:not([open])')];closed.forEach(d=>d.open=true);});
|
|
164
|
+
addEventListener('afterprint',()=>{closed.forEach(d=>d.open=false);closed=[];});
|
|
165
|
+
})();</script>`;
|
|
166
|
+
//# sourceMappingURL=explorer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explorer.js","sourceRoot":"","sources":["../../src/lib/explorer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAkBvC,MAAM,CAAC,MAAM,gBAAgB,GAAiB;IAC5C,KAAK,EAAE,sBAAsB;IAC7B,WAAW,EAAE,kFAAkF;IAC/F,MAAM,EAAE,EAAE,KAAK,EAAE,2BAA2B,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;IACnE,KAAK,EAAE,CAAC;YACN,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,sBAAsB;YACvD,WAAW,EAAE,2CAA2C;YACxD,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,yCAAyC,EAAE;gBAClH,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,WAAW,EAAE,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,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;AAC/d,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,mBAAmB,EAAE,eAAe,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC;AAE/P,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2B3B,CAAC;AAEF,mHAAmH;AACnH,MAAM,CAAC,MAAM,eAAe,GAAG;;;;eAIhB,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Favorites and the local artifact listing.
|
|
3
|
+
*
|
|
4
|
+
* The revision store (`revisions.ts`) already knows every rendered artifact:
|
|
5
|
+
* one directory per source under {@link historyRoot}, keyed by the SHA-256 of
|
|
6
|
+
* its canonical path, with a strict-integrity `manifest.json`. Favorites ride
|
|
7
|
+
* BESIDE that store in a single `favorites.json` at the same root rather than
|
|
8
|
+
* inside each manifest — a manifest is rewritten only inside the locked
|
|
9
|
+
* serialize→render→write transaction, and a favorite toggle must never touch
|
|
10
|
+
* (or be blocked by) that pipeline.
|
|
11
|
+
*
|
|
12
|
+
* Same env override as the revision store (`ARTIFACTS_HISTORY_DIR`), so a test
|
|
13
|
+
* or a scratch HOME relocates both together. Reads are lock-free (writes are
|
|
14
|
+
* atomic renames); writes take a lock on the store root so a served page and a
|
|
15
|
+
* CLI toggle never lose each other's update.
|
|
16
|
+
*/
|
|
17
|
+
export interface FavoriteEntry {
|
|
18
|
+
/** Canonical source path, when the favorite was recorded from a path. */
|
|
19
|
+
sourcePath?: string;
|
|
20
|
+
/** Display title, when known at toggle time (the served page sends document.title). */
|
|
21
|
+
title?: string;
|
|
22
|
+
favoritedAt: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function favoritesPath(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Read the favorites file. Absent means "no favorites yet"; present but
|
|
27
|
+
* unparseable or wrong-shaped is fatal — never silently reset a user's marks
|
|
28
|
+
* behind a transient read glitch (same rule as the revision manifest).
|
|
29
|
+
*/
|
|
30
|
+
export declare function readFavorites(file?: string): Record<string, FavoriteEntry>;
|
|
31
|
+
/**
|
|
32
|
+
* Set, clear, or flip the favorite flag for an artifact (a source path or a
|
|
33
|
+
* bare 64-hex id). The current-state read for a flip happens INSIDE the lock
|
|
34
|
+
* on the store root — reading before acquiring it would let two concurrent
|
|
35
|
+
* toggles both compute the same next state and collapse into one.
|
|
36
|
+
* Returns the resulting state.
|
|
37
|
+
*/
|
|
38
|
+
export declare function setFavorite(sourceOrId: string, favorite: boolean | 'toggle', extra?: {
|
|
39
|
+
sourcePath?: string;
|
|
40
|
+
title?: string;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
id: string;
|
|
43
|
+
favorite: boolean;
|
|
44
|
+
}>;
|
|
45
|
+
/** Flip the favorite flag (atomically, under the store lock); returns the resulting state. */
|
|
46
|
+
export declare function toggleFavorite(sourceOrId: string, extra?: {
|
|
47
|
+
sourcePath?: string;
|
|
48
|
+
title?: string;
|
|
49
|
+
}): Promise<{
|
|
50
|
+
id: string;
|
|
51
|
+
favorite: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
export declare function isFavorite(sourceOrId: string): boolean;
|
|
54
|
+
/** One artifact known to the local store, for `artifacts list`. */
|
|
55
|
+
export interface ArtifactSummary {
|
|
56
|
+
id: string;
|
|
57
|
+
sourcePath: string;
|
|
58
|
+
title: string;
|
|
59
|
+
/** First revision's timestamp; empty when the artifact has no saved revisions. */
|
|
60
|
+
createdAt: string;
|
|
61
|
+
/** Latest revision's timestamp; empty when the artifact has no saved revisions. */
|
|
62
|
+
updatedAt: string;
|
|
63
|
+
revisionCount: number;
|
|
64
|
+
favorite: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Enumerate every artifact the local store knows: the union of the revision
|
|
68
|
+
* manifests and the favorites file (a favorite can outlive — or predate — a
|
|
69
|
+
* manifest). A manifest that fails to parse is SKIPPED rather than fatal: a
|
|
70
|
+
* listing must degrade gracefully, unlike the integrity gate a targeted
|
|
71
|
+
* `history` read applies. Sorted most-recently-updated first.
|
|
72
|
+
*/
|
|
73
|
+
export declare function listArtifacts(): ArtifactSummary[];
|