@graphorin/cli 0.5.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 +7 -0
- package/LICENSE +21 -0
- package/README.md +130 -0
- package/dist/bin/graphorin.d.ts +1 -0
- package/dist/bin/graphorin.js +606 -0
- package/dist/bin/graphorin.js.map +1 -0
- package/dist/commands/audit.d.ts +59 -0
- package/dist/commands/audit.d.ts.map +1 -0
- package/dist/commands/audit.js +156 -0
- package/dist/commands/audit.js.map +1 -0
- package/dist/commands/auth.d.ts +48 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +148 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/consolidator.d.ts +49 -0
- package/dist/commands/consolidator.d.ts.map +1 -0
- package/dist/commands/consolidator.js +97 -0
- package/dist/commands/consolidator.js.map +1 -0
- package/dist/commands/doctor.d.ts +64 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +150 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/guard.d.ts +35 -0
- package/dist/commands/guard.d.ts.map +1 -0
- package/dist/commands/guard.js +86 -0
- package/dist/commands/guard.js.map +1 -0
- package/dist/commands/index.d.ts +21 -0
- package/dist/commands/index.js +22 -0
- package/dist/commands/init.d.ts +46 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +131 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/memory.d.ts +243 -0
- package/dist/commands/memory.d.ts.map +1 -0
- package/dist/commands/memory.js +471 -0
- package/dist/commands/memory.js.map +1 -0
- package/dist/commands/migrate-config.d.ts +20 -0
- package/dist/commands/migrate-config.d.ts.map +1 -0
- package/dist/commands/migrate-config.js +48 -0
- package/dist/commands/migrate-config.js.map +1 -0
- package/dist/commands/migrate-export.d.ts +26 -0
- package/dist/commands/migrate-export.d.ts.map +1 -0
- package/dist/commands/migrate-export.js +67 -0
- package/dist/commands/migrate-export.js.map +1 -0
- package/dist/commands/migrate.d.ts +31 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +59 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/pricing.d.ts +66 -0
- package/dist/commands/pricing.d.ts.map +1 -0
- package/dist/commands/pricing.js +128 -0
- package/dist/commands/pricing.js.map +1 -0
- package/dist/commands/secrets.d.ts +96 -0
- package/dist/commands/secrets.d.ts.map +1 -0
- package/dist/commands/secrets.js +182 -0
- package/dist/commands/secrets.js.map +1 -0
- package/dist/commands/skills.d.ts +58 -0
- package/dist/commands/skills.d.ts.map +1 -0
- package/dist/commands/skills.js +181 -0
- package/dist/commands/skills.js.map +1 -0
- package/dist/commands/start.d.ts +51 -0
- package/dist/commands/start.d.ts.map +1 -0
- package/dist/commands/start.js +122 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/storage.d.ts +110 -0
- package/dist/commands/storage.d.ts.map +1 -0
- package/dist/commands/storage.js +274 -0
- package/dist/commands/storage.js.map +1 -0
- package/dist/commands/telemetry.d.ts +21 -0
- package/dist/commands/telemetry.d.ts.map +1 -0
- package/dist/commands/telemetry.js +75 -0
- package/dist/commands/telemetry.js.map +1 -0
- package/dist/commands/token.d.ts +109 -0
- package/dist/commands/token.d.ts.map +1 -0
- package/dist/commands/token.js +246 -0
- package/dist/commands/token.js.map +1 -0
- package/dist/commands/tools-lint.d.ts +103 -0
- package/dist/commands/tools-lint.d.ts.map +1 -0
- package/dist/commands/tools-lint.js +240 -0
- package/dist/commands/tools-lint.js.map +1 -0
- package/dist/commands/traces.d.ts +33 -0
- package/dist/commands/traces.d.ts.map +1 -0
- package/dist/commands/traces.js +103 -0
- package/dist/commands/traces.js.map +1 -0
- package/dist/commands/triggers.d.ts +49 -0
- package/dist/commands/triggers.d.ts.map +1 -0
- package/dist/commands/triggers.js +129 -0
- package/dist/commands/triggers.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/exit.js +17 -0
- package/dist/internal/exit.js.map +1 -0
- package/dist/internal/load-config.js +84 -0
- package/dist/internal/load-config.js.map +1 -0
- package/dist/internal/offline.d.ts +58 -0
- package/dist/internal/offline.d.ts.map +1 -0
- package/dist/internal/offline.js +72 -0
- package/dist/internal/offline.js.map +1 -0
- package/dist/internal/output.d.ts +56 -0
- package/dist/internal/output.d.ts.map +1 -0
- package/dist/internal/output.js +86 -0
- package/dist/internal/output.js.map +1 -0
- package/dist/internal/prompts.js +49 -0
- package/dist/internal/prompts.js.map +1 -0
- package/dist/internal/store-context.js +69 -0
- package/dist/internal/store-context.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CommonOutputOptions } from "../internal/output.js";
|
|
2
|
+
|
|
3
|
+
//#region src/commands/migrate-export.d.ts
|
|
4
|
+
|
|
5
|
+
/** @stable */
|
|
6
|
+
interface MigrateExportOptions extends CommonOutputOptions {
|
|
7
|
+
readonly input: string;
|
|
8
|
+
readonly to: string;
|
|
9
|
+
/** Defaults to the writer's current schema (e.g. `'1.0'`). */
|
|
10
|
+
readonly toSchema?: string;
|
|
11
|
+
/** Surfaced on the meta header. Defaults to `'graphorin-cli@0.5.0'`. */
|
|
12
|
+
readonly writer?: string;
|
|
13
|
+
}
|
|
14
|
+
/** @stable */
|
|
15
|
+
interface MigrateExportResult {
|
|
16
|
+
readonly input: string;
|
|
17
|
+
readonly output: string;
|
|
18
|
+
readonly schemaIn: string;
|
|
19
|
+
readonly schemaOut: string;
|
|
20
|
+
readonly records: number;
|
|
21
|
+
}
|
|
22
|
+
/** @stable */
|
|
23
|
+
declare function runMigrateExport(options: MigrateExportOptions): Promise<MigrateExportResult>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { MigrateExportOptions, MigrateExportResult, runMigrateExport };
|
|
26
|
+
//# sourceMappingURL=migrate-export.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-export.d.ts","names":[],"sources":["../../src/commands/migrate-export.ts"],"sourcesContent":[],"mappings":";;;;;UAwCiB,oBAAA,SAA6B;;;;;;;;;UAU7B,mBAAA;;;;;;;;iBASK,gBAAA,UACX,uBACR,QAAQ"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { brand, defaultPrintSink, emitReport, statusMarker } from "../internal/output.js";
|
|
2
|
+
import { EXIT_CODES } from "../internal/exit.js";
|
|
3
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import { isAbsolute, resolve } from "node:path";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { SESSION_EXPORT_SCHEMA_CURRENT, createBufferSink, createSessionExportWriter, readSessionExport } from "@graphorin/sessions";
|
|
7
|
+
|
|
8
|
+
//#region src/commands/migrate-export.ts
|
|
9
|
+
/**
|
|
10
|
+
* `graphorin migrate-export <input> --to-schema <X.Y>` — schema-version
|
|
11
|
+
* migration for `graphorin-session-export/N.N` JSONL files (DEC-155 /
|
|
12
|
+
* ADR-042).
|
|
13
|
+
*
|
|
14
|
+
* The exporter ships schema 1.0 in v0.1; the migrator's main job today
|
|
15
|
+
* is to validate that the supplied input file is a well-formed session
|
|
16
|
+
* export with a schema in the framework's N-2 backwards-compat band
|
|
17
|
+
* and to round-trip the records through the writer with the desired
|
|
18
|
+
* target schema. When the runtime reaches MAJOR 2.x / 3.x the
|
|
19
|
+
* migrator extends the per-record transforms in place.
|
|
20
|
+
*
|
|
21
|
+
* The output path is required (`--to <file>`); the helper never
|
|
22
|
+
* overwrites the input.
|
|
23
|
+
*
|
|
24
|
+
* @packageDocumentation
|
|
25
|
+
*/
|
|
26
|
+
/** @stable */
|
|
27
|
+
async function runMigrateExport(options) {
|
|
28
|
+
const cwd = process.cwd();
|
|
29
|
+
const inputPath = isAbsolute(options.input) ? options.input : resolve(cwd, options.input);
|
|
30
|
+
const outputPath = isAbsolute(options.to) ? options.to : resolve(cwd, options.to);
|
|
31
|
+
const targetSchema = options.toSchema ?? SESSION_EXPORT_SCHEMA_CURRENT;
|
|
32
|
+
if (inputPath === outputPath) throw new Error(`[graphorin/cli] migrate-export refuses to overwrite the input file '${inputPath}'.`);
|
|
33
|
+
if (targetSchema !== SESSION_EXPORT_SCHEMA_CURRENT) {
|
|
34
|
+
(options.print ?? defaultPrintSink)(brand(`requested target schema '${targetSchema}' is not the writer's current schema (${SESSION_EXPORT_SCHEMA_CURRENT}); v0.1 supports the current schema only.`));
|
|
35
|
+
process.exit(EXIT_CODES.UNSUPPORTED);
|
|
36
|
+
}
|
|
37
|
+
const parsed = readSessionExport(await readFile(inputPath, "utf8"));
|
|
38
|
+
const buffer = createBufferSink();
|
|
39
|
+
const writer = createSessionExportWriter(buffer.sink, {
|
|
40
|
+
writer: options.writer ?? "graphorin-cli@0.5.0",
|
|
41
|
+
...parsed.meta.embedderIds !== void 0 ? { embedderIds: parsed.meta.embedderIds } : {}
|
|
42
|
+
});
|
|
43
|
+
for (const record of parsed.records) {
|
|
44
|
+
if (record.kind === "unknown") continue;
|
|
45
|
+
await writer.writeRecord(record);
|
|
46
|
+
}
|
|
47
|
+
await writer.close();
|
|
48
|
+
await writeFile(outputPath, buffer.toString(), { mode: 384 });
|
|
49
|
+
const out = Object.freeze({
|
|
50
|
+
input: inputPath,
|
|
51
|
+
output: outputPath,
|
|
52
|
+
schemaIn: parsed.meta.version,
|
|
53
|
+
schemaOut: targetSchema,
|
|
54
|
+
records: parsed.records.length
|
|
55
|
+
});
|
|
56
|
+
emitReport(options, out, () => {
|
|
57
|
+
const print = options.print ?? defaultPrintSink;
|
|
58
|
+
print(brand(`${statusMarker("ok")} migrated ${out.records} record(s) from schema ${out.schemaIn} -> ${out.schemaOut}`));
|
|
59
|
+
print(` input: ${out.input}`);
|
|
60
|
+
print(` output: ${out.output}`);
|
|
61
|
+
});
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { runMigrateExport };
|
|
67
|
+
//# sourceMappingURL=migrate-export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-export.js","names":["out: MigrateExportResult"],"sources":["../../src/commands/migrate-export.ts"],"sourcesContent":["/**\n * `graphorin migrate-export <input> --to-schema <X.Y>` — schema-version\n * migration for `graphorin-session-export/N.N` JSONL files (DEC-155 /\n * ADR-042).\n *\n * The exporter ships schema 1.0 in v0.1; the migrator's main job today\n * is to validate that the supplied input file is a well-formed session\n * export with a schema in the framework's N-2 backwards-compat band\n * and to round-trip the records through the writer with the desired\n * target schema. When the runtime reaches MAJOR 2.x / 3.x the\n * migrator extends the per-record transforms in place.\n *\n * The output path is required (`--to <file>`); the helper never\n * overwrites the input.\n *\n * @packageDocumentation\n */\n\nimport { readFile, writeFile } from 'node:fs/promises';\nimport { isAbsolute, resolve } from 'node:path';\nimport process from 'node:process';\n\nimport {\n createBufferSink,\n createSessionExportWriter,\n readSessionExport,\n SESSION_EXPORT_SCHEMA_CURRENT,\n type SessionExportRecord,\n} from '@graphorin/sessions';\n\nimport { EXIT_CODES } from '../internal/exit.js';\nimport {\n brand,\n type CommonOutputOptions,\n defaultPrintSink,\n emitReport,\n statusMarker,\n} from '../internal/output.js';\n\n/** @stable */\nexport interface MigrateExportOptions extends CommonOutputOptions {\n readonly input: string;\n readonly to: string;\n /** Defaults to the writer's current schema (e.g. `'1.0'`). */\n readonly toSchema?: string;\n /** Surfaced on the meta header. Defaults to `'graphorin-cli@0.5.0'`. */\n readonly writer?: string;\n}\n\n/** @stable */\nexport interface MigrateExportResult {\n readonly input: string;\n readonly output: string;\n readonly schemaIn: string;\n readonly schemaOut: string;\n readonly records: number;\n}\n\n/** @stable */\nexport async function runMigrateExport(\n options: MigrateExportOptions,\n): Promise<MigrateExportResult> {\n const cwd = process.cwd();\n const inputPath = isAbsolute(options.input) ? options.input : resolve(cwd, options.input);\n const outputPath = isAbsolute(options.to) ? options.to : resolve(cwd, options.to);\n const targetSchema = options.toSchema ?? SESSION_EXPORT_SCHEMA_CURRENT;\n\n if (inputPath === outputPath) {\n throw new Error(\n `[graphorin/cli] migrate-export refuses to overwrite the input file '${inputPath}'.`,\n );\n }\n if (targetSchema !== SESSION_EXPORT_SCHEMA_CURRENT) {\n const print = options.print ?? defaultPrintSink;\n print(\n brand(\n `requested target schema '${targetSchema}' is not the writer's current schema (${SESSION_EXPORT_SCHEMA_CURRENT}); v0.1 supports the current schema only.`,\n ),\n );\n process.exit(EXIT_CODES.UNSUPPORTED);\n }\n\n const raw = await readFile(inputPath, 'utf8');\n const parsed = readSessionExport(raw);\n\n const buffer = createBufferSink();\n const writer = createSessionExportWriter(buffer.sink, {\n writer: options.writer ?? 'graphorin-cli@0.5.0',\n ...(parsed.meta.embedderIds !== undefined ? { embedderIds: parsed.meta.embedderIds } : {}),\n });\n for (const record of parsed.records) {\n if (record.kind === 'unknown') continue;\n await writer.writeRecord(record as SessionExportRecord);\n }\n await writer.close();\n await writeFile(outputPath, buffer.toString(), { mode: 0o600 });\n\n const out: MigrateExportResult = Object.freeze({\n input: inputPath,\n output: outputPath,\n schemaIn: parsed.meta.version,\n schemaOut: targetSchema,\n records: parsed.records.length,\n });\n emitReport(options, out, () => {\n const print = options.print ?? defaultPrintSink;\n print(\n brand(\n `${statusMarker('ok')} migrated ${out.records} record(s) from schema ${out.schemaIn} -> ${out.schemaOut}`,\n ),\n );\n print(` input: ${out.input}`);\n print(` output: ${out.output}`);\n });\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,eAAsB,iBACpB,SAC8B;CAC9B,MAAM,MAAM,QAAQ,KAAK;CACzB,MAAM,YAAY,WAAW,QAAQ,MAAM,GAAG,QAAQ,QAAQ,QAAQ,KAAK,QAAQ,MAAM;CACzF,MAAM,aAAa,WAAW,QAAQ,GAAG,GAAG,QAAQ,KAAK,QAAQ,KAAK,QAAQ,GAAG;CACjF,MAAM,eAAe,QAAQ,YAAY;AAEzC,KAAI,cAAc,WAChB,OAAM,IAAI,MACR,uEAAuE,UAAU,IAClF;AAEH,KAAI,iBAAiB,+BAA+B;AAElD,GADc,QAAQ,SAAS,kBAE7B,MACE,4BAA4B,aAAa,wCAAwC,8BAA8B,2CAChH,CACF;AACD,UAAQ,KAAK,WAAW,YAAY;;CAItC,MAAM,SAAS,kBADH,MAAM,SAAS,WAAW,OAAO,CACR;CAErC,MAAM,SAAS,kBAAkB;CACjC,MAAM,SAAS,0BAA0B,OAAO,MAAM;EACpD,QAAQ,QAAQ,UAAU;EAC1B,GAAI,OAAO,KAAK,gBAAgB,SAAY,EAAE,aAAa,OAAO,KAAK,aAAa,GAAG,EAAE;EAC1F,CAAC;AACF,MAAK,MAAM,UAAU,OAAO,SAAS;AACnC,MAAI,OAAO,SAAS,UAAW;AAC/B,QAAM,OAAO,YAAY,OAA8B;;AAEzD,OAAM,OAAO,OAAO;AACpB,OAAM,UAAU,YAAY,OAAO,UAAU,EAAE,EAAE,MAAM,KAAO,CAAC;CAE/D,MAAMA,MAA2B,OAAO,OAAO;EAC7C,OAAO;EACP,QAAQ;EACR,UAAU,OAAO,KAAK;EACtB,WAAW;EACX,SAAS,OAAO,QAAQ;EACzB,CAAC;AACF,YAAW,SAAS,WAAW;EAC7B,MAAM,QAAQ,QAAQ,SAAS;AAC/B,QACE,MACE,GAAG,aAAa,KAAK,CAAC,YAAY,IAAI,QAAQ,yBAAyB,IAAI,SAAS,MAAM,IAAI,YAC/F,CACF;AACD,QAAM,aAAa,IAAI,QAAQ;AAC/B,QAAM,aAAa,IAAI,SAAS;GAChC;AACF,QAAO"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/commands/migrate.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* `graphorin migrate` — apply pending storage migrations.
|
|
4
|
+
*
|
|
5
|
+
* Idempotent: re-running the command after every migration has been
|
|
6
|
+
* applied is a no-op + a successful exit. Failures bubble up with the
|
|
7
|
+
* underlying SQLite error so operators can fix corrupted state.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* @stable
|
|
13
|
+
*/
|
|
14
|
+
interface MigrateCommandOptions {
|
|
15
|
+
readonly config?: string;
|
|
16
|
+
readonly target?: string;
|
|
17
|
+
readonly print?: (line: string) => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @stable
|
|
21
|
+
*/
|
|
22
|
+
interface MigrateCommandResult {
|
|
23
|
+
readonly applied: ReadonlyArray<string>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @stable
|
|
27
|
+
*/
|
|
28
|
+
declare function runMigrate(options?: MigrateCommandOptions): Promise<MigrateCommandResult>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { MigrateCommandOptions, MigrateCommandResult, runMigrate };
|
|
31
|
+
//# sourceMappingURL=migrate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","names":[],"sources":["../../src/commands/migrate.ts"],"sourcesContent":[],"mappings":";;AAoBA;AASA;AAOA;;;;;;;;;UAhBiB,qBAAA;;;;;;;;UASA,oBAAA;oBACG;;;;;iBAME,UAAA,WACX,wBACR,QAAQ"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { loadConfig } from "../internal/load-config.js";
|
|
2
|
+
import { applyHardeningEarly } from "./start.js";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { parseServerConfig } from "@graphorin/server";
|
|
5
|
+
import { createSqliteStore } from "@graphorin/store-sqlite";
|
|
6
|
+
|
|
7
|
+
//#region src/commands/migrate.ts
|
|
8
|
+
/**
|
|
9
|
+
* `graphorin migrate` — apply pending storage migrations.
|
|
10
|
+
*
|
|
11
|
+
* Idempotent: re-running the command after every migration has been
|
|
12
|
+
* applied is a no-op + a successful exit. Failures bubble up with the
|
|
13
|
+
* underlying SQLite error so operators can fix corrupted state.
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @stable
|
|
19
|
+
*/
|
|
20
|
+
async function runMigrate(options = {}) {
|
|
21
|
+
applyHardeningEarly();
|
|
22
|
+
const print = options.print ?? ((line) => process.stderr.write(`${line}\n`));
|
|
23
|
+
let loaded;
|
|
24
|
+
try {
|
|
25
|
+
loaded = await loadConfig(options.config);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
print(`[graphorin/cli] ${err.message}`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
print(`[graphorin/cli] resolved config: ${loaded.path}`);
|
|
31
|
+
let parsed;
|
|
32
|
+
try {
|
|
33
|
+
parsed = parseServerConfig(loaded.config);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
print(`[graphorin/cli] ${err.message}`);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
if (options.target !== void 0) print(`[graphorin/cli] --target is reserved for the Phase 15 migration runner; the v0.1 store applies every pending migration in order.`);
|
|
39
|
+
const store = await createSqliteStore({
|
|
40
|
+
path: parsed.storage.path,
|
|
41
|
+
mode: parsed.storage.mode
|
|
42
|
+
});
|
|
43
|
+
try {
|
|
44
|
+
await store.init();
|
|
45
|
+
const ids = store.appliedMigrations.map((m) => `${m.version} (${m.name})`);
|
|
46
|
+
print(`[graphorin/cli] applied ${ids.length} migration(s):`);
|
|
47
|
+
for (const id of ids) print(` - ${id}`);
|
|
48
|
+
return Object.freeze({ applied: Object.freeze(ids) });
|
|
49
|
+
} catch (err) {
|
|
50
|
+
print(`[graphorin/cli] migration failed: ${err.message}`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
} finally {
|
|
53
|
+
await store.close();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { runMigrate };
|
|
59
|
+
//# sourceMappingURL=migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.js","names":["loaded: Awaited<ReturnType<typeof loadConfig>>","parsed: ReturnType<typeof parseServerConfig>"],"sources":["../../src/commands/migrate.ts"],"sourcesContent":["/**\n * `graphorin migrate` — apply pending storage migrations.\n *\n * Idempotent: re-running the command after every migration has been\n * applied is a no-op + a successful exit. Failures bubble up with the\n * underlying SQLite error so operators can fix corrupted state.\n *\n * @packageDocumentation\n */\n\nimport process from 'node:process';\n\nimport { parseServerConfig } from '@graphorin/server';\nimport { createSqliteStore } from '@graphorin/store-sqlite';\nimport { loadConfig } from '../internal/load-config.js';\nimport { applyHardeningEarly } from './start.js';\n\n/**\n * @stable\n */\nexport interface MigrateCommandOptions {\n readonly config?: string;\n readonly target?: string;\n readonly print?: (line: string) => void;\n}\n\n/**\n * @stable\n */\nexport interface MigrateCommandResult {\n readonly applied: ReadonlyArray<string>;\n}\n\n/**\n * @stable\n */\nexport async function runMigrate(\n options: MigrateCommandOptions = {},\n): Promise<MigrateCommandResult> {\n applyHardeningEarly();\n const print = options.print ?? ((line: string) => process.stderr.write(`${line}\\n`));\n let loaded: Awaited<ReturnType<typeof loadConfig>>;\n try {\n loaded = await loadConfig(options.config);\n } catch (err) {\n print(`[graphorin/cli] ${(err as Error).message}`);\n process.exit(1);\n }\n print(`[graphorin/cli] resolved config: ${loaded.path}`);\n\n let parsed: ReturnType<typeof parseServerConfig>;\n try {\n parsed = parseServerConfig(loaded.config);\n } catch (err) {\n print(`[graphorin/cli] ${(err as Error).message}`);\n process.exit(1);\n }\n\n if (options.target !== undefined) {\n print(\n `[graphorin/cli] --target is reserved for the Phase 15 migration runner; the v0.1 store applies every pending migration in order.`,\n );\n }\n\n const store = await createSqliteStore({\n path: parsed.storage.path,\n mode: parsed.storage.mode,\n });\n try {\n await store.init();\n const ids = store.appliedMigrations.map((m) => `${m.version} (${m.name})`);\n print(`[graphorin/cli] applied ${ids.length} migration(s):`);\n for (const id of ids) {\n print(` - ${id}`);\n }\n return Object.freeze({ applied: Object.freeze(ids) });\n } catch (err) {\n print(`[graphorin/cli] migration failed: ${(err as Error).message}`);\n process.exit(1);\n } finally {\n await store.close();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoCA,eAAsB,WACpB,UAAiC,EAAE,EACJ;AAC/B,sBAAqB;CACrB,MAAM,QAAQ,QAAQ,WAAW,SAAiB,QAAQ,OAAO,MAAM,GAAG,KAAK,IAAI;CACnF,IAAIA;AACJ,KAAI;AACF,WAAS,MAAM,WAAW,QAAQ,OAAO;UAClC,KAAK;AACZ,QAAM,mBAAoB,IAAc,UAAU;AAClD,UAAQ,KAAK,EAAE;;AAEjB,OAAM,oCAAoC,OAAO,OAAO;CAExD,IAAIC;AACJ,KAAI;AACF,WAAS,kBAAkB,OAAO,OAAO;UAClC,KAAK;AACZ,QAAM,mBAAoB,IAAc,UAAU;AAClD,UAAQ,KAAK,EAAE;;AAGjB,KAAI,QAAQ,WAAW,OACrB,OACE,mIACD;CAGH,MAAM,QAAQ,MAAM,kBAAkB;EACpC,MAAM,OAAO,QAAQ;EACrB,MAAM,OAAO,QAAQ;EACtB,CAAC;AACF,KAAI;AACF,QAAM,MAAM,MAAM;EAClB,MAAM,MAAM,MAAM,kBAAkB,KAAK,MAAM,GAAG,EAAE,QAAQ,IAAI,EAAE,KAAK,GAAG;AAC1E,QAAM,2BAA2B,IAAI,OAAO,gBAAgB;AAC5D,OAAK,MAAM,MAAM,IACf,OAAM,OAAO,KAAK;AAEpB,SAAO,OAAO,OAAO,EAAE,SAAS,OAAO,OAAO,IAAI,EAAE,CAAC;UAC9C,KAAK;AACZ,QAAM,qCAAsC,IAAc,UAAU;AACpE,UAAQ,KAAK,EAAE;WACP;AACR,QAAM,MAAM,OAAO"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { CommonOutputOptions } from "../internal/output.js";
|
|
2
|
+
import * as _graphorin_pricing0 from "@graphorin/pricing";
|
|
3
|
+
import { PricingDiffEntry } from "@graphorin/pricing";
|
|
4
|
+
|
|
5
|
+
//#region src/commands/pricing.d.ts
|
|
6
|
+
|
|
7
|
+
/** @stable */
|
|
8
|
+
interface PricingCommonOptions extends CommonOutputOptions {}
|
|
9
|
+
/** @stable */
|
|
10
|
+
interface PricingStatusResult {
|
|
11
|
+
readonly version: string;
|
|
12
|
+
readonly snapshotDate: string;
|
|
13
|
+
readonly entries: number;
|
|
14
|
+
readonly digest: string;
|
|
15
|
+
}
|
|
16
|
+
/** @stable */
|
|
17
|
+
declare function runPricingStatus(options?: PricingCommonOptions): PricingStatusResult;
|
|
18
|
+
/** @stable */
|
|
19
|
+
interface PricingRefreshOptions extends PricingCommonOptions {
|
|
20
|
+
readonly url: string;
|
|
21
|
+
/**
|
|
22
|
+
* Optional path to write the refreshed snapshot to. When omitted the
|
|
23
|
+
* CLI prints a status summary only; `--out` triggers a JSON write.
|
|
24
|
+
*/
|
|
25
|
+
readonly out?: string;
|
|
26
|
+
/** Test seam — inject a fetch implementation. */
|
|
27
|
+
readonly fetchImpl?: typeof fetch;
|
|
28
|
+
}
|
|
29
|
+
/** @stable */
|
|
30
|
+
declare function runPricingRefresh(options: PricingRefreshOptions): Promise<{
|
|
31
|
+
readonly entries: number;
|
|
32
|
+
readonly version: string;
|
|
33
|
+
readonly out?: string;
|
|
34
|
+
}>;
|
|
35
|
+
/** @stable */
|
|
36
|
+
interface PricingDiffOptions extends PricingCommonOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Path to a JSON file containing a `PricingSnapshot`. The CLI diffs
|
|
39
|
+
* this against the bundled snapshot.
|
|
40
|
+
*/
|
|
41
|
+
readonly snapshot: string;
|
|
42
|
+
}
|
|
43
|
+
/** @stable */
|
|
44
|
+
declare function runPricingDiff(options: PricingDiffOptions): Promise<ReadonlyArray<PricingDiffEntry>>;
|
|
45
|
+
/** @stable */
|
|
46
|
+
interface PricingLookupOptions extends PricingCommonOptions {
|
|
47
|
+
readonly provider: string;
|
|
48
|
+
readonly model: string;
|
|
49
|
+
readonly region?: string;
|
|
50
|
+
}
|
|
51
|
+
/** @stable */
|
|
52
|
+
declare function runPricingLookup(options: PricingLookupOptions): _graphorin_pricing0.LookupPriceResult | null;
|
|
53
|
+
/** @stable */
|
|
54
|
+
interface PricingMissingOptions extends PricingCommonOptions {
|
|
55
|
+
/**
|
|
56
|
+
* Path to a JSON file containing an array of trace spans (each with
|
|
57
|
+
* an `attributes` map). Output of `graphorin traces export` (Phase
|
|
58
|
+
* 15) is the canonical source.
|
|
59
|
+
*/
|
|
60
|
+
readonly spans: string;
|
|
61
|
+
}
|
|
62
|
+
/** @stable */
|
|
63
|
+
declare function runPricingMissing(options: PricingMissingOptions): Promise<readonly _graphorin_pricing0.MissingModelEntry[]>;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { PricingCommonOptions, PricingDiffOptions, PricingLookupOptions, PricingMissingOptions, PricingRefreshOptions, PricingStatusResult, runPricingDiff, runPricingLookup, runPricingMissing, runPricingRefresh, runPricingStatus };
|
|
66
|
+
//# sourceMappingURL=pricing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.d.ts","names":[],"sources":["../../src/commands/pricing.ts"],"sourcesContent":[],"mappings":";;;;;;AAyLA;AAAiD,UA5IhC,oBAAA,SAA6B,mBA4IG,CAAA;;AAAqB,UAzIrD,mBAAA,CAyIqD;;;;;;;iBAjItD,gBAAA,WAA0B,uBAA4B;;UAiBrD,qBAAA,SAA8B;;;;;;;;8BAQjB;;;iBAIR,iBAAA,UACX,wBACR;;;;;;UA6Bc,kBAAA,SAA2B;;;;;;;;iBAStB,cAAA,UACX,qBACR,QAAQ,cAAc;;UAkBR,oBAAA,SAA6B;;;;;;iBAO9B,gBAAA,UAA0B,uBAAoB,mBAAA,CAAA,iBAAA;;UAuB7C,qBAAA,SAA8B;;;;;;;;;iBAUzB,iBAAA,UAA2B,wBAAqB,iBAAA,mBAAA,CAAA,iBAAA"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { brand, defaultPrintSink, emitReport, statusMarker } from "../internal/output.js";
|
|
2
|
+
import { EXIT_CODES } from "../internal/exit.js";
|
|
3
|
+
import { checkOfflineModeBlocked } from "../internal/offline.js";
|
|
4
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { BUNDLED_SNAPSHOT, SNAPSHOT_DATE, computeEntriesDigest, diffPricing, listMissingModels, lookupPrice, refreshPricing } from "@graphorin/pricing";
|
|
7
|
+
|
|
8
|
+
//#region src/commands/pricing.ts
|
|
9
|
+
/**
|
|
10
|
+
* `graphorin pricing` — operate on the bundled LLM pricing snapshot.
|
|
11
|
+
*
|
|
12
|
+
* Surface (per Phase 15 § Pricing):
|
|
13
|
+
*
|
|
14
|
+
* - `graphorin pricing status` — bundled snapshot version + entry
|
|
15
|
+
* count + canonical digest.
|
|
16
|
+
* - `graphorin pricing refresh --url <url>` — opt-in network call
|
|
17
|
+
* that fetches a fresh snapshot. Honours `GRAPHORIN_OFFLINE=1`.
|
|
18
|
+
* - `graphorin pricing diff` — row-by-row delta vs the bundled
|
|
19
|
+
* snapshot.
|
|
20
|
+
* - `graphorin pricing lookup --provider <name> --model <id>` — print
|
|
21
|
+
* the per-token price for a single (provider, model) pair.
|
|
22
|
+
* - `graphorin pricing missing` — read trace spans from a JSON file
|
|
23
|
+
* and report unknown (provider, model) pairs.
|
|
24
|
+
*
|
|
25
|
+
* @packageDocumentation
|
|
26
|
+
*/
|
|
27
|
+
/** @stable */
|
|
28
|
+
function runPricingStatus(options = {}) {
|
|
29
|
+
const out = Object.freeze({
|
|
30
|
+
version: BUNDLED_SNAPSHOT.version,
|
|
31
|
+
snapshotDate: SNAPSHOT_DATE,
|
|
32
|
+
entries: BUNDLED_SNAPSHOT.entries.length,
|
|
33
|
+
digest: computeEntriesDigest(BUNDLED_SNAPSHOT.entries)
|
|
34
|
+
});
|
|
35
|
+
emitReport(options, out, () => {
|
|
36
|
+
const print = options.print ?? defaultPrintSink;
|
|
37
|
+
print(brand(`pricing snapshot v${out.version} (${out.snapshotDate})`));
|
|
38
|
+
print(` entries: ${out.entries}`);
|
|
39
|
+
print(` digest: ${out.digest}`);
|
|
40
|
+
});
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/** @stable */
|
|
44
|
+
async function runPricingRefresh(options) {
|
|
45
|
+
if (!checkOfflineModeBlocked("pricing refresh", { ...options.print !== void 0 ? { print: options.print } : {} })) process.exit(EXIT_CODES.RECOVERABLE_FAILURE);
|
|
46
|
+
const refreshed = await refreshPricing({
|
|
47
|
+
url: options.url,
|
|
48
|
+
...options.fetchImpl !== void 0 ? { fetchImpl: options.fetchImpl } : {}
|
|
49
|
+
});
|
|
50
|
+
if (options.out !== void 0) await writeFile(options.out, JSON.stringify(refreshed, null, 2), { mode: 384 });
|
|
51
|
+
const result = {
|
|
52
|
+
entries: refreshed.entries.length,
|
|
53
|
+
version: refreshed.version,
|
|
54
|
+
...options.out !== void 0 ? { out: options.out } : {}
|
|
55
|
+
};
|
|
56
|
+
emitReport(options, result, () => {
|
|
57
|
+
const print = options.print ?? defaultPrintSink;
|
|
58
|
+
print(brand(`refreshed pricing snapshot v${result.version} (${result.entries} entries).`));
|
|
59
|
+
if (result.out !== void 0) print(brand(`written to ${result.out} (mode 0600).`));
|
|
60
|
+
});
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
/** @stable */
|
|
64
|
+
async function runPricingDiff(options) {
|
|
65
|
+
const diff = diffPricing(BUNDLED_SNAPSHOT, await readSnapshot(options.snapshot));
|
|
66
|
+
emitReport(options, diff, () => {
|
|
67
|
+
const print = options.print ?? defaultPrintSink;
|
|
68
|
+
if (diff.length === 0) {
|
|
69
|
+
print(brand("no diff between bundled snapshot and supplied snapshot."));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
print(brand(`${diff.length} pricing diff row(s):`));
|
|
73
|
+
for (const row of diff) print(` ${statusMarker("warn")} ${row.kind} ${row.provider}/${row.model}`);
|
|
74
|
+
});
|
|
75
|
+
return diff;
|
|
76
|
+
}
|
|
77
|
+
/** @stable */
|
|
78
|
+
function runPricingLookup(options) {
|
|
79
|
+
const result = lookupPrice({
|
|
80
|
+
provider: options.provider,
|
|
81
|
+
model: options.model,
|
|
82
|
+
...options.region !== void 0 ? { region: options.region } : {}
|
|
83
|
+
});
|
|
84
|
+
emitReport(options, result, () => {
|
|
85
|
+
const print = options.print ?? defaultPrintSink;
|
|
86
|
+
if (result === null) {
|
|
87
|
+
print(brand(`no pricing entry for ${options.provider}/${options.model}.`));
|
|
88
|
+
process.exitCode = EXIT_CODES.RECOVERABLE_FAILURE;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
print(brand(`${options.provider}/${options.model}: input=${result.inputUsdPerToken} / output=${result.outputUsdPerToken} USD per token (source=${result.source}, snapshot=${result.snapshotDate})`));
|
|
92
|
+
});
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
/** @stable */
|
|
96
|
+
async function runPricingMissing(options) {
|
|
97
|
+
const raw = await readFile(options.spans, "utf8");
|
|
98
|
+
let parsed;
|
|
99
|
+
try {
|
|
100
|
+
parsed = JSON.parse(raw);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
throw new Error(`[graphorin/cli] '${options.spans}' is not valid JSON: ${err.message}`);
|
|
103
|
+
}
|
|
104
|
+
if (!Array.isArray(parsed)) throw new Error(`[graphorin/cli] '${options.spans}' must contain an array of trace spans.`);
|
|
105
|
+
const missing = listMissingModels(parsed);
|
|
106
|
+
emitReport(options, missing, () => {
|
|
107
|
+
const print = options.print ?? defaultPrintSink;
|
|
108
|
+
if (missing.length === 0) {
|
|
109
|
+
print(brand("every (provider, model) pair in the spans is present in the bundled snapshot."));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
print(brand(`${missing.length} unknown (provider, model) pair(s):`));
|
|
113
|
+
for (const m of missing) print(` ${statusMarker("warn")} ${m.provider}/${m.model} (${m.count} span(s))`);
|
|
114
|
+
});
|
|
115
|
+
return missing;
|
|
116
|
+
}
|
|
117
|
+
async function readSnapshot(path) {
|
|
118
|
+
const raw = await readFile(path, "utf8");
|
|
119
|
+
try {
|
|
120
|
+
return JSON.parse(raw);
|
|
121
|
+
} catch (err) {
|
|
122
|
+
throw new Error(`[graphorin/cli] '${path}' is not a valid pricing snapshot JSON: ${err.message}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
export { runPricingDiff, runPricingLookup, runPricingMissing, runPricingRefresh, runPricingStatus };
|
|
128
|
+
//# sourceMappingURL=pricing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.js","names":["out: PricingStatusResult","result: { entries: number; version: string; out?: string }","parsed: unknown"],"sources":["../../src/commands/pricing.ts"],"sourcesContent":["/**\n * `graphorin pricing` — operate on the bundled LLM pricing snapshot.\n *\n * Surface (per Phase 15 § Pricing):\n *\n * - `graphorin pricing status` — bundled snapshot version + entry\n * count + canonical digest.\n * - `graphorin pricing refresh --url <url>` — opt-in network call\n * that fetches a fresh snapshot. Honours `GRAPHORIN_OFFLINE=1`.\n * - `graphorin pricing diff` — row-by-row delta vs the bundled\n * snapshot.\n * - `graphorin pricing lookup --provider <name> --model <id>` — print\n * the per-token price for a single (provider, model) pair.\n * - `graphorin pricing missing` — read trace spans from a JSON file\n * and report unknown (provider, model) pairs.\n *\n * @packageDocumentation\n */\n\nimport { readFile, writeFile } from 'node:fs/promises';\nimport process from 'node:process';\n\nimport {\n BUNDLED_SNAPSHOT,\n computeEntriesDigest,\n diffPricing,\n listMissingModels,\n lookupPrice,\n type PricingDiffEntry,\n type PricingSnapshot,\n refreshPricing,\n SNAPSHOT_DATE,\n} from '@graphorin/pricing';\n\nimport { EXIT_CODES } from '../internal/exit.js';\nimport { checkOfflineModeBlocked } from '../internal/offline.js';\nimport {\n brand,\n type CommonOutputOptions,\n defaultPrintSink,\n emitReport,\n statusMarker,\n} from '../internal/output.js';\n\n/** @stable */\nexport interface PricingCommonOptions extends CommonOutputOptions {}\n\n/** @stable */\nexport interface PricingStatusResult {\n readonly version: string;\n readonly snapshotDate: string;\n readonly entries: number;\n readonly digest: string;\n}\n\n/** @stable */\nexport function runPricingStatus(options: PricingCommonOptions = {}): PricingStatusResult {\n const out: PricingStatusResult = Object.freeze({\n version: BUNDLED_SNAPSHOT.version,\n snapshotDate: SNAPSHOT_DATE,\n entries: BUNDLED_SNAPSHOT.entries.length,\n digest: computeEntriesDigest(BUNDLED_SNAPSHOT.entries),\n });\n emitReport(options, out, () => {\n const print = options.print ?? defaultPrintSink;\n print(brand(`pricing snapshot v${out.version} (${out.snapshotDate})`));\n print(` entries: ${out.entries}`);\n print(` digest: ${out.digest}`);\n });\n return out;\n}\n\n/** @stable */\nexport interface PricingRefreshOptions extends PricingCommonOptions {\n readonly url: string;\n /**\n * Optional path to write the refreshed snapshot to. When omitted the\n * CLI prints a status summary only; `--out` triggers a JSON write.\n */\n readonly out?: string;\n /** Test seam — inject a fetch implementation. */\n readonly fetchImpl?: typeof fetch;\n}\n\n/** @stable */\nexport async function runPricingRefresh(\n options: PricingRefreshOptions,\n): Promise<{ readonly entries: number; readonly version: string; readonly out?: string }> {\n if (\n !checkOfflineModeBlocked('pricing refresh', {\n ...(options.print !== undefined ? { print: options.print } : {}),\n })\n ) {\n process.exit(EXIT_CODES.RECOVERABLE_FAILURE);\n }\n const refreshed = await refreshPricing({\n url: options.url,\n ...(options.fetchImpl !== undefined ? { fetchImpl: options.fetchImpl } : {}),\n });\n if (options.out !== undefined) {\n await writeFile(options.out, JSON.stringify(refreshed, null, 2), { mode: 0o600 });\n }\n const result: { entries: number; version: string; out?: string } = {\n entries: refreshed.entries.length,\n version: refreshed.version,\n ...(options.out !== undefined ? { out: options.out } : {}),\n };\n emitReport(options, result, () => {\n const print = options.print ?? defaultPrintSink;\n print(brand(`refreshed pricing snapshot v${result.version} (${result.entries} entries).`));\n if (result.out !== undefined) print(brand(`written to ${result.out} (mode 0600).`));\n });\n return result;\n}\n\n/** @stable */\nexport interface PricingDiffOptions extends PricingCommonOptions {\n /**\n * Path to a JSON file containing a `PricingSnapshot`. The CLI diffs\n * this against the bundled snapshot.\n */\n readonly snapshot: string;\n}\n\n/** @stable */\nexport async function runPricingDiff(\n options: PricingDiffOptions,\n): Promise<ReadonlyArray<PricingDiffEntry>> {\n const right = await readSnapshot(options.snapshot);\n const diff = diffPricing(BUNDLED_SNAPSHOT, right);\n emitReport(options, diff, () => {\n const print = options.print ?? defaultPrintSink;\n if (diff.length === 0) {\n print(brand('no diff between bundled snapshot and supplied snapshot.'));\n return;\n }\n print(brand(`${diff.length} pricing diff row(s):`));\n for (const row of diff) {\n print(` ${statusMarker('warn')} ${row.kind} ${row.provider}/${row.model}`);\n }\n });\n return diff;\n}\n\n/** @stable */\nexport interface PricingLookupOptions extends PricingCommonOptions {\n readonly provider: string;\n readonly model: string;\n readonly region?: string;\n}\n\n/** @stable */\nexport function runPricingLookup(options: PricingLookupOptions) {\n const result = lookupPrice({\n provider: options.provider,\n model: options.model,\n ...(options.region !== undefined ? { region: options.region } : {}),\n });\n emitReport(options, result, () => {\n const print = options.print ?? defaultPrintSink;\n if (result === null) {\n print(brand(`no pricing entry for ${options.provider}/${options.model}.`));\n process.exitCode = EXIT_CODES.RECOVERABLE_FAILURE;\n return;\n }\n print(\n brand(\n `${options.provider}/${options.model}: input=${result.inputUsdPerToken} / output=${result.outputUsdPerToken} USD per token (source=${result.source}, snapshot=${result.snapshotDate})`,\n ),\n );\n });\n return result;\n}\n\n/** @stable */\nexport interface PricingMissingOptions extends PricingCommonOptions {\n /**\n * Path to a JSON file containing an array of trace spans (each with\n * an `attributes` map). Output of `graphorin traces export` (Phase\n * 15) is the canonical source.\n */\n readonly spans: string;\n}\n\n/** @stable */\nexport async function runPricingMissing(options: PricingMissingOptions) {\n const raw = await readFile(options.spans, 'utf8');\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (err) {\n throw new Error(\n `[graphorin/cli] '${options.spans}' is not valid JSON: ${(err as Error).message}`,\n );\n }\n if (!Array.isArray(parsed)) {\n throw new Error(`[graphorin/cli] '${options.spans}' must contain an array of trace spans.`);\n }\n // The pricing helper trusts the shape; we cast through unknown.\n const missing = listMissingModels(\n parsed as ReadonlyArray<{ readonly attributes: Record<string, unknown> }>,\n );\n emitReport(options, missing, () => {\n const print = options.print ?? defaultPrintSink;\n if (missing.length === 0) {\n print(brand('every (provider, model) pair in the spans is present in the bundled snapshot.'));\n return;\n }\n print(brand(`${missing.length} unknown (provider, model) pair(s):`));\n for (const m of missing) {\n print(` ${statusMarker('warn')} ${m.provider}/${m.model} (${m.count} span(s))`);\n }\n });\n return missing;\n}\n\nasync function readSnapshot(path: string): Promise<PricingSnapshot> {\n const raw = await readFile(path, 'utf8');\n try {\n return JSON.parse(raw) as PricingSnapshot;\n } catch (err) {\n throw new Error(\n `[graphorin/cli] '${path}' is not a valid pricing snapshot JSON: ${(err as Error).message}`,\n );\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { CommonOutputOptions } from "../internal/output.js";
|
|
2
|
+
import { SecretsStoreKind } from "@graphorin/security";
|
|
3
|
+
import { SecretMetadata } from "@graphorin/core/contracts";
|
|
4
|
+
|
|
5
|
+
//#region src/commands/secrets.d.ts
|
|
6
|
+
|
|
7
|
+
/** @stable */
|
|
8
|
+
interface SecretsCommonOptions extends CommonOutputOptions {
|
|
9
|
+
/** Mirrors `--secrets-source` per DEC-136. */
|
|
10
|
+
readonly secretsSource?: SecretsStoreKind;
|
|
11
|
+
/** Mirrors `--strict-secrets` per DEC-136. */
|
|
12
|
+
readonly strictSecrets?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** @stable */
|
|
15
|
+
interface SecretsListOptions extends SecretsCommonOptions {}
|
|
16
|
+
/** @stable */
|
|
17
|
+
declare function runSecretsList(options?: SecretsListOptions): Promise<ReadonlyArray<SecretMetadata>>;
|
|
18
|
+
/** @stable */
|
|
19
|
+
interface SecretsGetOptions extends SecretsCommonOptions {
|
|
20
|
+
readonly key: string;
|
|
21
|
+
/**
|
|
22
|
+
* When `true`, print the raw value through the human report. The
|
|
23
|
+
* default is to print only structured metadata so the bytes do not
|
|
24
|
+
* surface in shell history.
|
|
25
|
+
*/
|
|
26
|
+
readonly reveal?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** @stable */
|
|
29
|
+
interface SecretsGetResult {
|
|
30
|
+
readonly key: string;
|
|
31
|
+
readonly found: boolean;
|
|
32
|
+
/** Only present when `reveal: true` AND the secret exists. */
|
|
33
|
+
readonly value?: string;
|
|
34
|
+
}
|
|
35
|
+
/** @stable */
|
|
36
|
+
declare function runSecretsGet(options: SecretsGetOptions): Promise<SecretsGetResult>;
|
|
37
|
+
/** @stable */
|
|
38
|
+
interface SecretsSetOptions extends SecretsCommonOptions {
|
|
39
|
+
readonly key: string;
|
|
40
|
+
readonly value?: string;
|
|
41
|
+
/** When `true`, read the value from stdin. */
|
|
42
|
+
readonly fromStdin?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** @stable */
|
|
45
|
+
declare function runSecretsSet(options: SecretsSetOptions): Promise<{
|
|
46
|
+
readonly ok: true;
|
|
47
|
+
}>;
|
|
48
|
+
/** @stable */
|
|
49
|
+
interface SecretsDeleteOptions extends SecretsCommonOptions {
|
|
50
|
+
readonly key: string;
|
|
51
|
+
}
|
|
52
|
+
/** @stable */
|
|
53
|
+
declare function runSecretsDelete(options: SecretsDeleteOptions): Promise<{
|
|
54
|
+
readonly ok: true;
|
|
55
|
+
}>;
|
|
56
|
+
/** @stable */
|
|
57
|
+
interface SecretsRefOptions extends CommonOutputOptions {
|
|
58
|
+
readonly uri: string;
|
|
59
|
+
readonly reveal?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/** @stable */
|
|
62
|
+
interface SecretsRefResult {
|
|
63
|
+
readonly uri: string;
|
|
64
|
+
readonly scheme: string;
|
|
65
|
+
readonly resolved: boolean;
|
|
66
|
+
readonly length?: number;
|
|
67
|
+
readonly value?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Test resolution of a `SecretRef` URI. The CLI parses the URI first
|
|
71
|
+
* (sanity check + scheme echo), then resolves through the registered
|
|
72
|
+
* resolver chain.
|
|
73
|
+
*
|
|
74
|
+
* @stable
|
|
75
|
+
*/
|
|
76
|
+
declare function runSecretsRef(options: SecretsRefOptions): Promise<SecretsRefResult>;
|
|
77
|
+
/** @stable */
|
|
78
|
+
interface SecretsRotateOptions extends SecretsCommonOptions {
|
|
79
|
+
readonly key: string;
|
|
80
|
+
readonly newValue?: string;
|
|
81
|
+
readonly fromStdin?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* `graphorin secrets rotate <key>` — overwrite the existing value
|
|
85
|
+
* with a fresh one. Functionally identical to `set` but the CLI
|
|
86
|
+
* surfaces the operation explicitly so audit logs can distinguish
|
|
87
|
+
* a rotation from an initial write.
|
|
88
|
+
*
|
|
89
|
+
* @stable
|
|
90
|
+
*/
|
|
91
|
+
declare function runSecretsRotate(options: SecretsRotateOptions): Promise<{
|
|
92
|
+
readonly ok: true;
|
|
93
|
+
}>;
|
|
94
|
+
//#endregion
|
|
95
|
+
export { SecretsCommonOptions, SecretsDeleteOptions, SecretsGetOptions, SecretsGetResult, SecretsListOptions, SecretsRefOptions, SecretsRefResult, SecretsRotateOptions, SecretsSetOptions, runSecretsDelete, runSecretsGet, runSecretsList, runSecretsRef, runSecretsRotate, runSecretsSet };
|
|
96
|
+
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","names":[],"sources":["../../src/commands/secrets.ts"],"sourcesContent":[],"mappings":";;;;;;AAqMA;AAA6C,UAvJ5B,oBAAA,SAA6B,mBAuJD,CAAA;EAA4B;EAAR,SAAA,aAAA,CAAA,EArJtC,gBAqJsC;EAAO;EAwCvD,SAAA,aAAA,CAAqB,EAAA,OAAA;AActC;;UArMiB,kBAAA,SAA2B;;iBAGtB,cAAA,WACX,qBACR,QAAQ,cAAc;;UAkBR,iBAAA,SAA0B;;;;;;;;;;UAW1B,gBAAA;;;;;;;iBAQK,aAAA,UAAuB,oBAAoB,QAAQ;;UA+BxD,iBAAA,SAA0B;;;;;;;iBAQrB,aAAA,UAAuB,oBAAoB;;;;UAuBhD,oBAAA,SAA6B;;;;iBAKxB,gBAAA,UACX,uBACR;;;;UAWc,iBAAA,SAA0B;;;;;UAM1B,gBAAA;;;;;;;;;;;;;;iBAeK,aAAA,UAAuB,oBAAoB,QAAQ;;UAwCxD,oBAAA,SAA6B;;;;;;;;;;;;;iBAcxB,gBAAA,UACX,uBACR"}
|