@phnx-labs/artifacts-cli 0.1.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 +20 -0
- package/LICENSE +16 -0
- package/README.md +223 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +239 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/setup.d.ts +5 -0
- package/dist/commands/setup.js +40 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/share.d.ts +20 -0
- package/dist/commands/share.js +75 -0
- package/dist/commands/share.js.map +1 -0
- package/dist/lib/config.d.ts +18 -0
- package/dist/lib/config.js +24 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/design.d.ts +52 -0
- package/dist/lib/design.js +168 -0
- package/dist/lib/design.js.map +1 -0
- package/dist/lib/embedded-html.d.ts +12 -0
- package/dist/lib/embedded-html.js +192 -0
- package/dist/lib/embedded-html.js.map +1 -0
- package/dist/lib/fonts.d.ts +12 -0
- package/dist/lib/fonts.js +58 -0
- package/dist/lib/fonts.js.map +1 -0
- package/dist/lib/icons.d.ts +2 -0
- package/dist/lib/icons.js +21 -0
- package/dist/lib/icons.js.map +1 -0
- package/dist/lib/pdf.d.ts +13 -0
- package/dist/lib/pdf.js +66 -0
- package/dist/lib/pdf.js.map +1 -0
- package/dist/lib/render.d.ts +12 -0
- package/dist/lib/render.js +346 -0
- package/dist/lib/render.js.map +1 -0
- package/dist/lib/share-provision.d.ts +31 -0
- package/dist/lib/share-provision.js +83 -0
- package/dist/lib/share-provision.js.map +1 -0
- package/dist/lib/share-worker.d.ts +1 -0
- package/dist/lib/share-worker.js +66 -0
- package/dist/lib/share-worker.js.map +1 -0
- package/dist/lib/share.d.ts +22 -0
- package/dist/lib/share.js +130 -0
- package/dist/lib/share.js.map +1 -0
- package/dist/lib/templates.d.ts +19 -0
- package/dist/lib/templates.js +196 -0
- package/dist/lib/templates.js.map +1 -0
- package/dist/lib/tokens.d.ts +10 -0
- package/dist/lib/tokens.js +24 -0
- package/dist/lib/tokens.js.map +1 -0
- package/dist/lib/validate.d.ts +12 -0
- package/dist/lib/validate.js +123 -0
- package/dist/lib/validate.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const DEFAULT_WORKER_NAME = "artifacts-share";
|
|
2
|
+
export declare const DEFAULT_BUCKET_NAME = "artifacts-share";
|
|
3
|
+
export declare const SHARE_LIFECYCLE_RULE_ID = "artifacts-share-expire-objects";
|
|
4
|
+
interface R2LifecycleRule {
|
|
5
|
+
id: string;
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
conditions: {
|
|
8
|
+
prefix: string;
|
|
9
|
+
};
|
|
10
|
+
deleteObjectsTransition?: {
|
|
11
|
+
condition: {
|
|
12
|
+
type: 'Age';
|
|
13
|
+
maxAge: number;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface CloudflareRequest {
|
|
18
|
+
apiToken: string;
|
|
19
|
+
method: string;
|
|
20
|
+
pathname: string;
|
|
21
|
+
body?: unknown;
|
|
22
|
+
form?: FormData;
|
|
23
|
+
}
|
|
24
|
+
export type CloudflareRequester = <T = unknown>(request: CloudflareRequest) => Promise<T>;
|
|
25
|
+
export declare function createBucket(apiToken: string, accountId: string, name: string, request?: CloudflareRequester): Promise<void>;
|
|
26
|
+
export declare function buildLifecycleRule(days?: number): R2LifecycleRule;
|
|
27
|
+
export declare function configureBucketLifecycle(apiToken: string, accountId: string, bucketName: string, request?: CloudflareRequester): Promise<void>;
|
|
28
|
+
export declare function deployWorker(apiToken: string, accountId: string, workerName: string, script: string, bucketName: string, request?: CloudflareRequester): Promise<void>;
|
|
29
|
+
export declare function setWorkerSecret(apiToken: string, accountId: string, workerName: string, writeToken: string, request?: CloudflareRequester): Promise<void>;
|
|
30
|
+
export declare function enableWorkersDev(apiToken: string, accountId: string, workerName: string, request?: CloudflareRequester): Promise<string>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const CF_API = 'https://api.cloudflare.com/client/v4';
|
|
2
|
+
const SECONDS_PER_DAY = 86400;
|
|
3
|
+
export const DEFAULT_WORKER_NAME = 'artifacts-share';
|
|
4
|
+
export const DEFAULT_BUCKET_NAME = 'artifacts-share';
|
|
5
|
+
export const SHARE_LIFECYCLE_RULE_ID = 'artifacts-share-expire-objects';
|
|
6
|
+
async function cf(request) {
|
|
7
|
+
const headers = { authorization: `Bearer ${request.apiToken}` };
|
|
8
|
+
let body;
|
|
9
|
+
if (request.form)
|
|
10
|
+
body = request.form;
|
|
11
|
+
else if (request.body !== undefined) {
|
|
12
|
+
headers['content-type'] = 'application/json';
|
|
13
|
+
body = JSON.stringify(request.body);
|
|
14
|
+
}
|
|
15
|
+
const response = await fetch(`${CF_API}${request.pathname}`, { method: request.method, headers, body });
|
|
16
|
+
const json = (await response.json().catch(() => ({})));
|
|
17
|
+
if (!response.ok || json.success === false) {
|
|
18
|
+
const message = (json.errors ?? []).map((error) => `${error.code ?? ''} ${error.message ?? ''}`.trim()).join('; ') || response.statusText;
|
|
19
|
+
throw new Error(`Cloudflare ${request.method} ${request.pathname} failed (${response.status}): ${message}`);
|
|
20
|
+
}
|
|
21
|
+
return json.result;
|
|
22
|
+
}
|
|
23
|
+
function existsError(error) {
|
|
24
|
+
return /already exists|duplicate|10004|10014/i.test(String(error));
|
|
25
|
+
}
|
|
26
|
+
export async function createBucket(apiToken, accountId, name, request = cf) {
|
|
27
|
+
try {
|
|
28
|
+
await request({ apiToken, method: 'POST', pathname: `/accounts/${accountId}/r2/buckets`, body: { name } });
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (!existsError(error))
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function buildLifecycleRule(days = 366) {
|
|
36
|
+
return {
|
|
37
|
+
id: SHARE_LIFECYCLE_RULE_ID,
|
|
38
|
+
enabled: true,
|
|
39
|
+
conditions: { prefix: '' },
|
|
40
|
+
deleteObjectsTransition: { condition: { type: 'Age', maxAge: days * SECONDS_PER_DAY } },
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export async function configureBucketLifecycle(apiToken, accountId, bucketName, request = cf) {
|
|
44
|
+
const lifecycle = await request({
|
|
45
|
+
apiToken,
|
|
46
|
+
method: 'GET',
|
|
47
|
+
pathname: `/accounts/${accountId}/r2/buckets/${bucketName}/lifecycle`,
|
|
48
|
+
});
|
|
49
|
+
const rules = [...(lifecycle.rules ?? []).filter((rule) => rule.id !== SHARE_LIFECYCLE_RULE_ID), buildLifecycleRule()];
|
|
50
|
+
await request({
|
|
51
|
+
apiToken,
|
|
52
|
+
method: 'PUT',
|
|
53
|
+
pathname: `/accounts/${accountId}/r2/buckets/${bucketName}/lifecycle`,
|
|
54
|
+
body: { rules },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export async function deployWorker(apiToken, accountId, workerName, script, bucketName, request = cf) {
|
|
58
|
+
const metadata = {
|
|
59
|
+
main_module: 'worker.js',
|
|
60
|
+
compatibility_date: '2024-11-06',
|
|
61
|
+
bindings: [{ type: 'r2_bucket', name: 'BUCKET', bucket_name: bucketName }],
|
|
62
|
+
};
|
|
63
|
+
const form = new FormData();
|
|
64
|
+
form.set('metadata', new Blob([JSON.stringify(metadata)], { type: 'application/json' }));
|
|
65
|
+
form.set('worker.js', new Blob([script], { type: 'application/javascript+module' }), 'worker.js');
|
|
66
|
+
await request({ apiToken, method: 'PUT', pathname: `/accounts/${accountId}/workers/scripts/${workerName}`, form });
|
|
67
|
+
}
|
|
68
|
+
export async function setWorkerSecret(apiToken, accountId, workerName, writeToken, request = cf) {
|
|
69
|
+
await request({
|
|
70
|
+
apiToken,
|
|
71
|
+
method: 'PUT',
|
|
72
|
+
pathname: `/accounts/${accountId}/workers/scripts/${workerName}/secrets`,
|
|
73
|
+
body: { name: 'WRITE_TOKEN', text: writeToken, type: 'secret_text' },
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
export async function enableWorkersDev(apiToken, accountId, workerName, request = cf) {
|
|
77
|
+
await request({ apiToken, method: 'POST', pathname: `/accounts/${accountId}/workers/scripts/${workerName}/subdomain`, body: { enabled: true, previews_enabled: false } });
|
|
78
|
+
const subdomain = await request({ apiToken, method: 'GET', pathname: `/accounts/${accountId}/workers/subdomain` });
|
|
79
|
+
if (!subdomain.subdomain)
|
|
80
|
+
throw new Error('No workers.dev subdomain is configured on this Cloudflare account.');
|
|
81
|
+
return subdomain.subdomain;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=share-provision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"share-provision.js","sourceRoot":"","sources":["../../src/lib/share-provision.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,sCAAsC,CAAC;AACtD,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B,MAAM,CAAC,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AACrD,MAAM,CAAC,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AACrD,MAAM,CAAC,MAAM,uBAAuB,GAAG,gCAAgC,CAAC;AAqBxE,KAAK,UAAU,EAAE,CAAI,OAA0B;IAC7C,MAAM,OAAO,GAA2B,EAAE,aAAa,EAAE,UAAU,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;IACxF,IAAI,IAAmC,CAAC;IACxC,IAAI,OAAO,CAAC,IAAI;QAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;SACjC,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACpC,OAAO,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAC;QAC7C,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,MAAM,GAAG,OAAO,CAAC,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IAC1K,MAAM,SAAS,GAAG,MAAM,OAAO,CAAyB,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa,SAAS,oBAAoB,EAAE,CAAC,CAAC;IAC3I,IAAI,CAAC,SAAS,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;IAChH,OAAO,SAAS,CAAC,SAAS,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function renderWorkerScript(): string;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export function renderWorkerScript() {
|
|
2
|
+
return `// GENERATED by artifacts share setup.
|
|
3
|
+
export default {
|
|
4
|
+
async fetch(request, env) {
|
|
5
|
+
const url = new URL(request.url);
|
|
6
|
+
const path = decodeURIComponent(url.pathname.replace(/^\\/+/, ''));
|
|
7
|
+
if (!path) return text('artifacts share endpoint: PUT /<user>/<slug> to publish, GET to view.', 200);
|
|
8
|
+
|
|
9
|
+
if (request.method === 'PUT') {
|
|
10
|
+
const token = (request.headers.get('authorization') || '').replace(/^Bearer\\s+/i, '');
|
|
11
|
+
if (!env.WRITE_TOKEN || !safeEqual(token, env.WRITE_TOKEN)) return json({ error: 'unauthorized' }, 401);
|
|
12
|
+
const expiresAt = request.headers.get('x-share-expires-at') || '';
|
|
13
|
+
const contentType = request.headers.get('content-type') || 'text/html; charset=utf-8';
|
|
14
|
+
await env.BUCKET.put(path, request.body, {
|
|
15
|
+
httpMetadata: { contentType },
|
|
16
|
+
customMetadata: expiresAt ? { 'expires-at': expiresAt } : {},
|
|
17
|
+
});
|
|
18
|
+
return json({ ok: true, url: url.origin + '/' + path, expiresAt: expiresAt || null }, 200);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (request.method === 'DELETE') {
|
|
22
|
+
const token = (request.headers.get('authorization') || '').replace(/^Bearer\\s+/i, '');
|
|
23
|
+
if (!env.WRITE_TOKEN || !safeEqual(token, env.WRITE_TOKEN)) return json({ error: 'unauthorized' }, 401);
|
|
24
|
+
await env.BUCKET.delete(path);
|
|
25
|
+
return json({ ok: true, deleted: path }, 200);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (request.method === 'GET' || request.method === 'HEAD') {
|
|
29
|
+
const obj = await env.BUCKET.get(path);
|
|
30
|
+
if (!obj) return text('not found', 404);
|
|
31
|
+
const expiresAt = obj.customMetadata && obj.customMetadata['expires-at'];
|
|
32
|
+
if (expiresAt && Date.now() > Date.parse(expiresAt)) {
|
|
33
|
+
await env.BUCKET.delete(path);
|
|
34
|
+
return text('gone - this link has expired', 410);
|
|
35
|
+
}
|
|
36
|
+
const headers = new Headers();
|
|
37
|
+
obj.writeHttpMetadata(headers);
|
|
38
|
+
headers.set('etag', obj.httpEtag);
|
|
39
|
+
if (!headers.has('content-type')) headers.set('content-type', 'text/html; charset=utf-8');
|
|
40
|
+
headers.set('cache-control', 'public, max-age=60');
|
|
41
|
+
headers.set('x-robots-tag', 'noindex');
|
|
42
|
+
return new Response(request.method === 'HEAD' ? null : obj.body, { status: 200, headers });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return text('method not allowed', 405);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
function text(body, status) {
|
|
50
|
+
return new Response(body, { status, headers: { 'content-type': 'text/plain; charset=utf-8' } });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function json(body, status) {
|
|
54
|
+
return new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function safeEqual(a, b) {
|
|
58
|
+
if (typeof a !== 'string' || typeof b !== 'string') return false;
|
|
59
|
+
const la = a.length, lb = b.length;
|
|
60
|
+
let out = la ^ lb;
|
|
61
|
+
for (let i = 0; i < la; i++) out |= a.charCodeAt(i) ^ b.charCodeAt(i % lb || 0);
|
|
62
|
+
return out === 0 && la === lb;
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=share-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"share-worker.js","sourceRoot":"","sources":["../../src/lib/share-worker.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB;IAChC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8DR,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ArtifactsConfig } from './config.js';
|
|
2
|
+
export interface PublishOptions {
|
|
3
|
+
slug?: string;
|
|
4
|
+
expire?: string;
|
|
5
|
+
githubUser?: string;
|
|
6
|
+
json?: boolean;
|
|
7
|
+
noAnalytics?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface PublishResult {
|
|
10
|
+
url: string;
|
|
11
|
+
expiresAt?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function generateWriteToken(): string;
|
|
14
|
+
export declare function parseExpire(spec: string | undefined): string | undefined;
|
|
15
|
+
export declare function readShareEndpoint(config?: ArtifactsConfig): {
|
|
16
|
+
baseUrl: string;
|
|
17
|
+
token: string;
|
|
18
|
+
analyticsToken?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function publishArtifact(file: string, opts?: PublishOptions): Promise<PublishResult>;
|
|
21
|
+
export declare function deleteShare(slugOrUrl: string): Promise<string>;
|
|
22
|
+
export declare function joinShare(baseUrl: string, token: string): ArtifactsConfig;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
5
|
+
import { compileArtifact } from './render.js';
|
|
6
|
+
import { readConfig, updateConfig } from './config.js';
|
|
7
|
+
const UNIT_MS = { s: 1e3, m: 6e4, h: 36e5, d: 864e5, w: 6048e5 };
|
|
8
|
+
export function generateWriteToken() {
|
|
9
|
+
return randomBytes(32).toString('hex');
|
|
10
|
+
}
|
|
11
|
+
export function parseExpire(spec) {
|
|
12
|
+
if (!spec)
|
|
13
|
+
return undefined;
|
|
14
|
+
const relative = /^(\d+)\s*([smhdw])$/i.exec(spec.trim());
|
|
15
|
+
if (relative)
|
|
16
|
+
return new Date(Date.now() + Number(relative[1]) * UNIT_MS[relative[2].toLowerCase()]).toISOString();
|
|
17
|
+
const date = new Date(spec);
|
|
18
|
+
if (!Number.isNaN(date.getTime()))
|
|
19
|
+
return date.toISOString();
|
|
20
|
+
throw new Error(`Bad --expire '${spec}'. Use 30d, 12h, or an absolute date like 2026-08-01.`);
|
|
21
|
+
}
|
|
22
|
+
function sanitizePart(value) {
|
|
23
|
+
return value.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
24
|
+
}
|
|
25
|
+
function slugify(file) {
|
|
26
|
+
return sanitizePart(basename(file).replace(/\.[^.]+$/, '')).slice(0, 60) || 'artifact';
|
|
27
|
+
}
|
|
28
|
+
function defaultSlug(file) {
|
|
29
|
+
const project = (() => {
|
|
30
|
+
try {
|
|
31
|
+
const top = execFileSync('git', ['-C', dirname(resolve(file)), 'rev-parse', '--show-toplevel'], { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
|
|
32
|
+
return sanitizePart(basename(top)) || 'artifact';
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return sanitizePart(basename(process.cwd())) || 'artifact';
|
|
36
|
+
}
|
|
37
|
+
})();
|
|
38
|
+
return `${project}-${slugify(file).replace(/^plan-/, '')}-${randomBytes(8).toString('hex')}`;
|
|
39
|
+
}
|
|
40
|
+
function githubUser(explicit) {
|
|
41
|
+
if (explicit)
|
|
42
|
+
return sanitizePart(explicit);
|
|
43
|
+
try {
|
|
44
|
+
const out = execFileSync('gh', ['api', 'user', '-q', '.login'], { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
|
|
45
|
+
if (out)
|
|
46
|
+
return sanitizePart(out);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Fall through to git config.
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const out = execFileSync('git', ['config', '--global', 'github.user'], { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
|
|
53
|
+
if (out)
|
|
54
|
+
return sanitizePart(out);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Fall through to error.
|
|
58
|
+
}
|
|
59
|
+
throw new Error('Could not determine GitHub username. Run gh auth login, set git config --global github.user, or pass --github-user.');
|
|
60
|
+
}
|
|
61
|
+
function contentType(file) {
|
|
62
|
+
const ext = extname(file).toLowerCase();
|
|
63
|
+
if (ext === '.html' || ext === '.htm')
|
|
64
|
+
return 'text/html; charset=utf-8';
|
|
65
|
+
if (ext === '.svg')
|
|
66
|
+
return 'image/svg+xml';
|
|
67
|
+
if (ext === '.png')
|
|
68
|
+
return 'image/png';
|
|
69
|
+
if (ext === '.jpg' || ext === '.jpeg')
|
|
70
|
+
return 'image/jpeg';
|
|
71
|
+
if (ext === '.pdf')
|
|
72
|
+
return 'application/pdf';
|
|
73
|
+
if (ext === '.json')
|
|
74
|
+
return 'application/json';
|
|
75
|
+
return 'application/octet-stream';
|
|
76
|
+
}
|
|
77
|
+
export function readShareEndpoint(config = readConfig()) {
|
|
78
|
+
const baseUrl = config.share?.baseUrl?.replace(/\/+$/, '');
|
|
79
|
+
const token = process.env.ARTIFACTS_SHARE_TOKEN?.trim() || config.share?.writeToken?.trim();
|
|
80
|
+
if (!baseUrl || !token)
|
|
81
|
+
throw new Error('Share is not configured. Run artifacts share setup or artifacts share join.');
|
|
82
|
+
return { baseUrl, token, analyticsToken: config.share?.analyticsToken };
|
|
83
|
+
}
|
|
84
|
+
export async function publishArtifact(file, opts = {}) {
|
|
85
|
+
const endpoint = readShareEndpoint();
|
|
86
|
+
let uploadPath = file;
|
|
87
|
+
if (/\.md$/i.test(file)) {
|
|
88
|
+
uploadPath = join(process.cwd(), '.artifacts', `${slugify(file)}.html`);
|
|
89
|
+
const result = await compileArtifact(file, uploadPath);
|
|
90
|
+
const errors = result.diagnostics.filter((diagnostic) => diagnostic.level === 'error');
|
|
91
|
+
if (errors.length)
|
|
92
|
+
throw new Error(`Artifact did not compile cleanly:\n${errors.map((error) => `- ${error.message}`).join('\n')}`);
|
|
93
|
+
}
|
|
94
|
+
if (!existsSync(uploadPath))
|
|
95
|
+
throw new Error(`File not found: ${uploadPath}`);
|
|
96
|
+
const username = githubUser(opts.githubUser);
|
|
97
|
+
const key = `${username}/${sanitizePart(opts.slug ?? defaultSlug(uploadPath))}`;
|
|
98
|
+
const url = `${endpoint.baseUrl}/${key}`;
|
|
99
|
+
const expiresAt = parseExpire(opts.expire);
|
|
100
|
+
const headers = {
|
|
101
|
+
authorization: `Bearer ${endpoint.token}`,
|
|
102
|
+
'content-type': contentType(uploadPath),
|
|
103
|
+
};
|
|
104
|
+
if (expiresAt)
|
|
105
|
+
headers['x-share-expires-at'] = expiresAt;
|
|
106
|
+
const response = await fetch(url, { method: 'PUT', headers, body: new Uint8Array(readFileSync(uploadPath)) });
|
|
107
|
+
if (!response.ok)
|
|
108
|
+
throw new Error(`Publish failed (${response.status}) for ${url}: ${await response.text().catch(() => '')}`);
|
|
109
|
+
return { url, expiresAt };
|
|
110
|
+
}
|
|
111
|
+
export async function deleteShare(slugOrUrl) {
|
|
112
|
+
const endpoint = readShareEndpoint();
|
|
113
|
+
const path = slugOrUrl.startsWith('http') ? new URL(slugOrUrl).pathname.replace(/^\/+/, '') : slugOrUrl.replace(/^\/+/, '');
|
|
114
|
+
const url = `${endpoint.baseUrl}/${path}`;
|
|
115
|
+
const response = await fetch(url, { method: 'DELETE', headers: { authorization: `Bearer ${endpoint.token}` } });
|
|
116
|
+
if (!response.ok)
|
|
117
|
+
throw new Error(`Delete failed (${response.status}) for ${url}: ${await response.text().catch(() => '')}`);
|
|
118
|
+
return path;
|
|
119
|
+
}
|
|
120
|
+
export function joinShare(baseUrl, token) {
|
|
121
|
+
return updateConfig((cfg) => ({
|
|
122
|
+
...cfg,
|
|
123
|
+
share: {
|
|
124
|
+
...(cfg.share ?? {}),
|
|
125
|
+
baseUrl: baseUrl.replace(/\/+$/, ''),
|
|
126
|
+
writeToken: token,
|
|
127
|
+
},
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=share.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"share.js","sourceRoot":"","sources":["../../src/lib/share.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAwB,MAAM,aAAa,CAAC;AAe7E,MAAM,OAAO,GAA2B,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;AAEzF,MAAM,UAAU,kBAAkB;IAChC,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAwB;IAClD,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,MAAM,QAAQ,GAAG,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,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ACd,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,OAAe,EAAE,KAAa;IACtD,OAAO,YAAY,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC5B,GAAG,GAAG;QACN,KAAK,EAAE;YACL,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACpC,UAAU,EAAE,KAAK;SAClB;KACF,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type TemplateKind = 'plan' | 'report' | 'visual';
|
|
2
|
+
export interface ArtifactContext {
|
|
3
|
+
project: string;
|
|
4
|
+
repository: string;
|
|
5
|
+
branch: string;
|
|
6
|
+
harness: string;
|
|
7
|
+
agent: string;
|
|
8
|
+
human: string;
|
|
9
|
+
host: string;
|
|
10
|
+
session: string;
|
|
11
|
+
date: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const STARTER_DESIGN = "---\nname: default\nfonts:\n body: Inter\n mono: JetBrains Mono\n display: Inter\ntheme:\n default: system\nthemes:\n light:\n background: \"#faf9f6\"\n surface: \"#ffffff\"\n surfaceAlt: \"#f2f4f0\"\n line: \"#e2e6df\"\n text: \"#1a1c1a\"\n muted: \"#5c655c\"\n accent: \"#4d7c0f\"\n accentAlt: \"#0e7490\"\n warn: \"#b45309\"\n danger: \"#dc2626\"\n dark:\n background: \"#0a0a0a\"\n surface: \"#111312\"\n surfaceAlt: \"#161a18\"\n line: \"#26302a\"\n text: \"#e7ece8\"\n muted: \"#8b938c\"\n accent: \"#a3e635\"\n accentAlt: \"#5ad6c0\"\n warn: \"#f5c451\"\n danger: \"#ff6b6b\"\nlayout:\n contentWidth: 980\n pagePadding: 24\n mobilePagePadding: 16\n heroTop: 40\n heroBottom: 28\n sectionSpacing: 36\n figureSpacing: 22\n panelPadding: 16\n footerSpacing: 64\n printMargin: 24\nartifact:\n density: compact\n radius: 10\n printTheme: light\n---\n\n# Design\n\nProject-wide artifact rendering defaults. Keep artifact-specific metadata in the Markdown artifact frontmatter.\n";
|
|
14
|
+
export declare function repositoryName(remote: string): string;
|
|
15
|
+
export declare function detectArtifactContext(cwd?: string): ArtifactContext;
|
|
16
|
+
export declare function templateFor(kind: TemplateKind, context?: Partial<ArtifactContext>): string;
|
|
17
|
+
export declare const PLAN_TEMPLATE: string;
|
|
18
|
+
export declare const REPORT_TEMPLATE: string;
|
|
19
|
+
export declare const VISUAL_TEMPLATE: string;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { hostname, userInfo } from 'node:os';
|
|
3
|
+
import matter from 'gray-matter';
|
|
4
|
+
export const STARTER_DESIGN = `---
|
|
5
|
+
name: default
|
|
6
|
+
fonts:
|
|
7
|
+
body: Inter
|
|
8
|
+
mono: JetBrains Mono
|
|
9
|
+
display: Inter
|
|
10
|
+
theme:
|
|
11
|
+
default: system
|
|
12
|
+
themes:
|
|
13
|
+
light:
|
|
14
|
+
background: "#faf9f6"
|
|
15
|
+
surface: "#ffffff"
|
|
16
|
+
surfaceAlt: "#f2f4f0"
|
|
17
|
+
line: "#e2e6df"
|
|
18
|
+
text: "#1a1c1a"
|
|
19
|
+
muted: "#5c655c"
|
|
20
|
+
accent: "#4d7c0f"
|
|
21
|
+
accentAlt: "#0e7490"
|
|
22
|
+
warn: "#b45309"
|
|
23
|
+
danger: "#dc2626"
|
|
24
|
+
dark:
|
|
25
|
+
background: "#0a0a0a"
|
|
26
|
+
surface: "#111312"
|
|
27
|
+
surfaceAlt: "#161a18"
|
|
28
|
+
line: "#26302a"
|
|
29
|
+
text: "#e7ece8"
|
|
30
|
+
muted: "#8b938c"
|
|
31
|
+
accent: "#a3e635"
|
|
32
|
+
accentAlt: "#5ad6c0"
|
|
33
|
+
warn: "#f5c451"
|
|
34
|
+
danger: "#ff6b6b"
|
|
35
|
+
layout:
|
|
36
|
+
contentWidth: 980
|
|
37
|
+
pagePadding: 24
|
|
38
|
+
mobilePagePadding: 16
|
|
39
|
+
heroTop: 40
|
|
40
|
+
heroBottom: 28
|
|
41
|
+
sectionSpacing: 36
|
|
42
|
+
figureSpacing: 22
|
|
43
|
+
panelPadding: 16
|
|
44
|
+
footerSpacing: 64
|
|
45
|
+
printMargin: 24
|
|
46
|
+
artifact:
|
|
47
|
+
density: compact
|
|
48
|
+
radius: 10
|
|
49
|
+
printTheme: light
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
# Design
|
|
53
|
+
|
|
54
|
+
Project-wide artifact rendering defaults. Keep artifact-specific metadata in the Markdown artifact frontmatter.
|
|
55
|
+
`;
|
|
56
|
+
const TEMPLATE_CONTENT = {
|
|
57
|
+
plan: `
|
|
58
|
+
## Purpose
|
|
59
|
+
|
|
60
|
+
## Proposed Changes
|
|
61
|
+
|
|
62
|
+
## Public Interface
|
|
63
|
+
|
|
64
|
+
## Validation
|
|
65
|
+
|
|
66
|
+
## Risks
|
|
67
|
+
|
|
68
|
+
## Tracking
|
|
69
|
+
`,
|
|
70
|
+
report: `
|
|
71
|
+
## Summary
|
|
72
|
+
|
|
73
|
+
## Findings
|
|
74
|
+
|
|
75
|
+
## Evidence
|
|
76
|
+
|
|
77
|
+
## Recommendations
|
|
78
|
+
`,
|
|
79
|
+
visual: `
|
|
80
|
+
## Story
|
|
81
|
+
|
|
82
|
+
## Data
|
|
83
|
+
|
|
84
|
+
## Figure
|
|
85
|
+
|
|
86
|
+
<!-- Optional embedded layout classes:
|
|
87
|
+
artifact-figure, artifact-figure-diagram, artifact-figure-wide, artifact-figure-tall,
|
|
88
|
+
artifact-grid, artifact-grid-2, artifact-grid-3, artifact-panel,
|
|
89
|
+
artifact-stat, artifact-stat-value, artifact-stat-label,
|
|
90
|
+
artifact-image, artifact-diagram, artifact-callout, artifact-callout-warn,
|
|
91
|
+
artifact-callout-danger, artifact-legend,
|
|
92
|
+
artifact-tag, and artifact-tag-accent.
|
|
93
|
+
Embedded block content is HTML, not Markdown.
|
|
94
|
+
Custom CSS, scripts, event handlers, and unlisted classes are rejected. -->
|
|
95
|
+
`,
|
|
96
|
+
};
|
|
97
|
+
function gitValue(cwd, args) {
|
|
98
|
+
try {
|
|
99
|
+
return execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return '';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function repositoryName(remote) {
|
|
106
|
+
const scpPath = remote.match(/^[^@]+@[^:]+:(.+)$/)?.[1];
|
|
107
|
+
if (scpPath)
|
|
108
|
+
return scpPath.replace(/^\/+|\.git$/g, '');
|
|
109
|
+
try {
|
|
110
|
+
return decodeURIComponent(new URL(remote).pathname).replace(/^\/+|\.git$/g, '');
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return remote.replace(/^\/+|\.git$/g, '');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function localDate() {
|
|
117
|
+
const now = new Date();
|
|
118
|
+
const month = String(now.getMonth() + 1).padStart(2, '0');
|
|
119
|
+
const day = String(now.getDate()).padStart(2, '0');
|
|
120
|
+
return `${now.getFullYear()}-${month}-${day}`;
|
|
121
|
+
}
|
|
122
|
+
function firstEnvironmentValue(names) {
|
|
123
|
+
for (const name of names) {
|
|
124
|
+
const value = process.env[name]?.trim();
|
|
125
|
+
if (value)
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
return '';
|
|
129
|
+
}
|
|
130
|
+
function osUsername() {
|
|
131
|
+
// userInfo() throws for uids without a passwd entry (rootless CI containers).
|
|
132
|
+
try {
|
|
133
|
+
return userInfo().username;
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return '';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export function detectArtifactContext(cwd = process.cwd()) {
|
|
140
|
+
const root = gitValue(cwd, ['rev-parse', '--show-toplevel']);
|
|
141
|
+
const remote = gitValue(cwd, ['remote', 'get-url', 'origin']);
|
|
142
|
+
const repository = repositoryName(remote);
|
|
143
|
+
const project = repository.split('/').at(-1) || (root ? root.split(/[\\/]/).at(-1) || '' : '');
|
|
144
|
+
const session = firstEnvironmentValue([
|
|
145
|
+
'CODEX_THREAD_ID',
|
|
146
|
+
'CLAUDE_SESSION_ID',
|
|
147
|
+
'GEMINI_SESSION_ID',
|
|
148
|
+
'AGENT_SESSION_ID',
|
|
149
|
+
'RUSH_SESSION_ID',
|
|
150
|
+
'AGENT_LAUNCH_ID',
|
|
151
|
+
]);
|
|
152
|
+
return {
|
|
153
|
+
project,
|
|
154
|
+
repository,
|
|
155
|
+
branch: gitValue(cwd, ['branch', '--show-current']),
|
|
156
|
+
harness: firstEnvironmentValue(['AGENTS_AGENT_NAME', 'AGENT_HARNESS']),
|
|
157
|
+
agent: firstEnvironmentValue(['AGENTS_MODEL', 'AGENT_MODEL', 'CODEX_MODEL', 'ANTHROPIC_MODEL', 'OPENAI_MODEL']),
|
|
158
|
+
human: gitValue(cwd, ['config', 'user.name'])
|
|
159
|
+
|| firstEnvironmentValue(['GIT_AUTHOR_NAME', 'USER', 'LOGNAME'])
|
|
160
|
+
|| osUsername(),
|
|
161
|
+
host: hostname(),
|
|
162
|
+
session: session.length > 8 ? session.slice(0, 8) : session,
|
|
163
|
+
date: localDate(),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function frontmatter(kind, context) {
|
|
167
|
+
return {
|
|
168
|
+
kind,
|
|
169
|
+
template: `${kind}.v1`,
|
|
170
|
+
title: '',
|
|
171
|
+
summary: '',
|
|
172
|
+
header: '',
|
|
173
|
+
footer: '',
|
|
174
|
+
project: context.project || '',
|
|
175
|
+
context: '',
|
|
176
|
+
repository: context.repository || '',
|
|
177
|
+
branch: context.branch || '',
|
|
178
|
+
tracking: '',
|
|
179
|
+
status: 'draft',
|
|
180
|
+
harness: context.harness || '',
|
|
181
|
+
agent: context.agent || '',
|
|
182
|
+
human: context.human || '',
|
|
183
|
+
host: context.host || '',
|
|
184
|
+
session: context.session || '',
|
|
185
|
+
date: context.date || '',
|
|
186
|
+
facts: [],
|
|
187
|
+
assets: [],
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
export function templateFor(kind, context = {}) {
|
|
191
|
+
return matter.stringify(TEMPLATE_CONTENT[kind], frontmatter(kind, context));
|
|
192
|
+
}
|
|
193
|
+
export const PLAN_TEMPLATE = templateFor('plan');
|
|
194
|
+
export const REPORT_TEMPLATE = templateFor('report');
|
|
195
|
+
export const VISUAL_TEMPLATE = templateFor('visual');
|
|
196
|
+
//# sourceMappingURL=templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/lib/templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,MAAM,MAAM,aAAa,CAAC;AAgBjC,MAAM,CAAC,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmD7B,CAAC;AAEF,MAAM,gBAAgB,GAAiC;IACrD,IAAI,EAAE;;;;;;;;;;;;CAYP;IACC,MAAM,EAAE;;;;;;;;CAQT;IACC,MAAM,EAAE;;;;;;;;;;;;;;;;CAgBT;CACA,CAAC;AAEF,SAAS,QAAQ,CAAC,GAAW,EAAE,IAAc;IAC3C,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1G,CAAC;IAAC,MAAM,CAAC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AC,CAAC;AAC9E,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;AACjD,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;AACrD,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type RenderResult } from './render.js';
|
|
2
|
+
export interface ArtifactTokenEstimate {
|
|
3
|
+
encoding: 'o200k_base';
|
|
4
|
+
markdownTokens: number;
|
|
5
|
+
htmlTokens: number;
|
|
6
|
+
avoidedTokens: number;
|
|
7
|
+
reductionPercent: number;
|
|
8
|
+
diagnostics: RenderResult['diagnostics'];
|
|
9
|
+
}
|
|
10
|
+
export declare function estimateArtifactTokens(filePath: string): Promise<ArtifactTokenEstimate>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { Tiktoken } from 'js-tiktoken/lite';
|
|
4
|
+
import o200kBase from 'js-tiktoken/ranks/o200k_base';
|
|
5
|
+
import { renderMarkdown } from './render.js';
|
|
6
|
+
export async function estimateArtifactTokens(filePath) {
|
|
7
|
+
if (!/\.md$/i.test(filePath))
|
|
8
|
+
throw new Error('Token estimates require a Markdown source file.');
|
|
9
|
+
const markdown = readFileSync(resolve(filePath), 'utf8');
|
|
10
|
+
const rendered = await renderMarkdown(filePath, { embedSource: false });
|
|
11
|
+
const tokenizer = new Tiktoken(o200kBase);
|
|
12
|
+
const markdownTokens = tokenizer.encode(markdown).length;
|
|
13
|
+
const htmlTokens = tokenizer.encode(rendered.html).length;
|
|
14
|
+
const avoidedTokens = htmlTokens - markdownTokens;
|
|
15
|
+
return {
|
|
16
|
+
encoding: 'o200k_base',
|
|
17
|
+
markdownTokens,
|
|
18
|
+
htmlTokens,
|
|
19
|
+
avoidedTokens,
|
|
20
|
+
reductionPercent: htmlTokens === 0 ? 0 : (avoidedTokens / htmlTokens) * 100,
|
|
21
|
+
diagnostics: rendered.diagnostics,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/lib/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,SAAS,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAqB,MAAM,aAAa,CAAC;AAWhE,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,QAAgB;IAC3D,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACjG,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;IACzD,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;IACxE,MAAM,SAAS,GAAG,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC1C,MAAM,cAAc,GAAG,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;IACzD,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IAC1D,MAAM,aAAa,GAAG,UAAU,GAAG,cAAc,CAAC;IAClD,OAAO;QACL,QAAQ,EAAE,YAAY;QACtB,cAAc;QACd,UAAU;QACV,aAAa;QACb,gBAAgB,EAAE,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,GAAG,UAAU,CAAC,GAAG,GAAG;QAC3E,WAAW,EAAE,QAAQ,CAAC,WAAW;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface Diagnostic {
|
|
2
|
+
level: 'error' | 'warning';
|
|
3
|
+
message: string;
|
|
4
|
+
line?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface ValidationResult {
|
|
7
|
+
ok: boolean;
|
|
8
|
+
diagnostics: Diagnostic[];
|
|
9
|
+
data: Record<string, any>;
|
|
10
|
+
content: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function validateMarkdown(filePath: string): ValidationResult;
|