tenjin-cli 0.1.0-alpha.3 → 0.1.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -188
- package/dist/{_esm-FEASBWRP.js → _esm-N4KAVXQR.js} +9 -9
- package/dist/buy-OOOLUDND.js +41 -0
- package/dist/candidate-TWCWTFGA.js +22 -0
- package/dist/{ccip-XR5NE5QK.js → ccip-RPPPKTJR.js} +5 -5
- package/dist/{ccip-NQXCEK2U.js → ccip-ZGGWQN4X.js} +4 -4
- package/dist/{chunk-XJIW7USF.js → chunk-333FOTUJ.js} +5 -5
- package/dist/{chunk-YALGASEU.js → chunk-47PP7TAG.js} +1610 -1610
- package/dist/chunk-47PP7TAG.js.map +1 -0
- package/dist/{buy-EE6SEXP6.js → chunk-4GR7DGD6.js} +23 -41
- package/dist/{buy-EE6SEXP6.js.map → chunk-4GR7DGD6.js.map} +1 -1
- package/dist/{chunk-DXTQ3CSI.js → chunk-5JH7ZB6Z.js} +7 -7
- package/dist/{chunk-DXTQ3CSI.js.map → chunk-5JH7ZB6Z.js.map} +1 -1
- package/dist/{chunk-OYMYCW7J.js → chunk-6WWVYYSB.js} +32 -2
- package/dist/{chunk-OYMYCW7J.js.map → chunk-6WWVYYSB.js.map} +1 -1
- package/dist/{chunk-UGX7YPX2.js → chunk-7FK2UN2T.js} +65 -65
- package/dist/{chunk-UGX7YPX2.js.map → chunk-7FK2UN2T.js.map} +1 -1
- package/dist/{chunk-ESPNTPQ2.js → chunk-BXUS5UCT.js} +9 -4
- package/dist/{chunk-ESPNTPQ2.js.map → chunk-BXUS5UCT.js.map} +1 -1
- package/dist/{chunk-4ONXEEQL.js → chunk-C4TIWOAM.js} +2 -2
- package/dist/{chunk-4ONXEEQL.js.map → chunk-C4TIWOAM.js.map} +1 -1
- package/dist/{chunk-AWPAWHNX.js → chunk-CJU555P5.js} +24 -24
- package/dist/{chunk-AWPAWHNX.js.map → chunk-CJU555P5.js.map} +1 -1
- package/dist/{chunk-YN5SHIXQ.js → chunk-DPET3TW5.js} +2 -2
- package/dist/{chunk-TLCMMYLY.js → chunk-DPUMEMGM.js} +5 -5
- package/dist/chunk-DPUMEMGM.js.map +1 -0
- package/dist/{chunk-XHC6FCGZ.js → chunk-EUQN3L5X.js} +9 -9
- package/dist/{chunk-XHC6FCGZ.js.map → chunk-EUQN3L5X.js.map} +1 -1
- package/dist/{chunk-GO75V3NZ.js → chunk-FHB3VKZW.js} +6 -6
- package/dist/{chunk-GO75V3NZ.js.map → chunk-FHB3VKZW.js.map} +1 -1
- package/dist/{chunk-S3IGX57D.js → chunk-FU6MCSLG.js} +9 -9
- package/dist/{lookup-ZPN2Q67N.js → chunk-H5ETJRQD.js} +40 -31
- package/dist/chunk-H5ETJRQD.js.map +1 -0
- package/dist/chunk-KXIX7YDV.js +59 -0
- package/dist/chunk-KXIX7YDV.js.map +1 -0
- package/dist/{chunk-5CLSD5YN.js → chunk-KYQVEKP5.js} +7 -7
- package/dist/{chunk-RRN3YTK7.js → chunk-KZAAWQNP.js} +3 -3
- package/dist/{chunk-NCE5NSN6.js → chunk-M2O56UK7.js} +158 -158
- package/dist/chunk-M2O56UK7.js.map +1 -0
- package/dist/{chunk-7KUW4MJD.js → chunk-MM4TGTST.js} +6 -6
- package/dist/{chunk-7KUW4MJD.js.map → chunk-MM4TGTST.js.map} +1 -1
- package/dist/{chunk-662MSGZB.js → chunk-NXCJN2FJ.js} +55 -28
- package/dist/chunk-NXCJN2FJ.js.map +1 -0
- package/dist/{candidate-ERMSYYQZ.js → chunk-OJD54DIU.js} +15 -19
- package/dist/{candidate-ERMSYYQZ.js.map → chunk-OJD54DIU.js.map} +1 -1
- package/dist/{chunk-ZABPQJ3M.js → chunk-POJRB2AE.js} +2 -2
- package/dist/{chunk-FJPLRISB.js → chunk-QH6677FJ.js} +5 -4
- package/dist/chunk-QH6677FJ.js.map +1 -0
- package/dist/{wallet-CWEMYVIH.js → chunk-R7BMDJZM.js} +15 -27
- package/dist/{wallet-CWEMYVIH.js.map → chunk-R7BMDJZM.js.map} +1 -1
- package/dist/{chunk-Z6MFJV5Z.js → chunk-S3KZ3PPK.js} +15 -11
- package/dist/{chunk-Z6MFJV5Z.js.map → chunk-S3KZ3PPK.js.map} +1 -1
- package/dist/{chunk-CYOF7ROH.js → chunk-S5RYMCV6.js} +3 -3
- package/dist/{chunk-ZMHYXMO6.js → chunk-U5S527PP.js} +3 -3
- package/dist/{chunk-RY4XKNV3.js → chunk-UHTVXQ2O.js} +3 -3
- package/dist/{publish-BKBQQAW4.js → chunk-ULLWHHIT.js} +19 -34
- package/dist/{publish-BKBQQAW4.js.map → chunk-ULLWHHIT.js.map} +1 -1
- package/dist/{chunk-Z52RA3NC.js → chunk-VV4P5RVK.js} +47 -20
- package/dist/chunk-VV4P5RVK.js.map +1 -0
- package/dist/{chunk-QVX5MWJZ.js → chunk-W6R3HAAG.js} +2 -2
- package/dist/{chunk-3OV7E5G5.js → chunk-WWX32ML4.js} +1 -1
- package/dist/{chunk-3OV7E5G5.js.map → chunk-WWX32ML4.js.map} +1 -1
- package/dist/{chunk-HIVZG55D.js → chunk-XJN5WUKL.js} +2 -2
- package/dist/{chunk-JPHG2JW3.js → chunk-XNNOR7F7.js} +25 -25
- package/dist/chunk-XNNOR7F7.js.map +1 -0
- package/dist/{inspect-LMKOXE4Y.js → chunk-YFREUEUI.js} +8 -26
- package/dist/{inspect-LMKOXE4Y.js.map → chunk-YFREUEUI.js.map} +1 -1
- package/dist/{chunk-HSDCI7OV.js → chunk-YLYINX2H.js} +3 -3
- package/dist/{cli-SBXI5AMS.js → cli-AFSLAKR6.js} +47 -36
- package/dist/{cli-SBXI5AMS.js.map → cli-AFSLAKR6.js.map} +1 -1
- package/dist/{config-VELDKLHY.js → config-DBEEM3UA.js} +5 -5
- package/dist/{doctor-T3KWNNP2.js → doctor-XDA3YU6H.js} +7 -7
- package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js → ethersCompat-Df4a6QIZ-WHYKB6HA.js} +5 -5
- package/dist/index.js +1 -1
- package/dist/inspect-YBGDAG47.js +33 -0
- package/dist/{install-LEX3ENQ6.js → install-7J6KKEEP.js} +240 -85
- package/dist/install-7J6KKEEP.js.map +1 -0
- package/dist/outcome-ZFGHX2XW.js +20 -0
- package/dist/publish-IH7RJXGB.js +36 -0
- package/dist/publish-IH7RJXGB.js.map +1 -0
- package/dist/run-DCZFEW2C.js +16806 -0
- package/dist/run-DCZFEW2C.js.map +1 -0
- package/dist/search-R6NIQFXI.js +24 -0
- package/dist/search-R6NIQFXI.js.map +1 -0
- package/dist/{secp256k1-N3ZHU7LB.js → secp256k1-XRPVBC6V.js} +3 -3
- package/dist/secp256k1-XRPVBC6V.js.map +1 -0
- package/dist/usdc-AU6ZIKA6.js +22 -0
- package/dist/usdc-AU6ZIKA6.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js → viemAdapter-By13KInL-TUQJBMHM.js} +5 -5
- package/dist/viemAdapter-By13KInL-TUQJBMHM.js.map +1 -0
- package/dist/{wallet-PA54CRBL.js → wallet-HKG3GSTX.js} +10 -10
- package/dist/wallet-HKG3GSTX.js.map +1 -0
- package/dist/wallet-UWHSHWC6.js +31 -0
- package/dist/wallet-UWHSHWC6.js.map +1 -0
- package/package.json +4 -3
- package/skills/tenjin/SKILL.md +56 -13
- package/skills/tenjin-publish/SKILL.md +21 -6
- package/skills/tenjin-search/SKILL.md +35 -20
- package/dist/chunk-662MSGZB.js.map +0 -1
- package/dist/chunk-FJPLRISB.js.map +0 -1
- package/dist/chunk-JPHG2JW3.js.map +0 -1
- package/dist/chunk-NCE5NSN6.js.map +0 -1
- package/dist/chunk-TLCMMYLY.js.map +0 -1
- package/dist/chunk-YALGASEU.js.map +0 -1
- package/dist/chunk-Z52RA3NC.js.map +0 -1
- package/dist/install-LEX3ENQ6.js.map +0 -1
- package/dist/lookup-ZPN2Q67N.js.map +0 -1
- package/dist/outcome-N7TAK6WR.js +0 -66
- package/dist/outcome-N7TAK6WR.js.map +0 -1
- package/dist/usdc-JIAJW4SV.js +0 -22
- /package/dist/{_esm-FEASBWRP.js.map → _esm-N4KAVXQR.js.map} +0 -0
- /package/dist/{ccip-NQXCEK2U.js.map → buy-OOOLUDND.js.map} +0 -0
- /package/dist/{ccip-XR5NE5QK.js.map → candidate-TWCWTFGA.js.map} +0 -0
- /package/dist/{config-VELDKLHY.js.map → ccip-RPPPKTJR.js.map} +0 -0
- /package/dist/{doctor-T3KWNNP2.js.map → ccip-ZGGWQN4X.js.map} +0 -0
- /package/dist/{chunk-XJIW7USF.js.map → chunk-333FOTUJ.js.map} +0 -0
- /package/dist/{chunk-YN5SHIXQ.js.map → chunk-DPET3TW5.js.map} +0 -0
- /package/dist/{chunk-S3IGX57D.js.map → chunk-FU6MCSLG.js.map} +0 -0
- /package/dist/{chunk-5CLSD5YN.js.map → chunk-KYQVEKP5.js.map} +0 -0
- /package/dist/{chunk-RRN3YTK7.js.map → chunk-KZAAWQNP.js.map} +0 -0
- /package/dist/{chunk-ZABPQJ3M.js.map → chunk-POJRB2AE.js.map} +0 -0
- /package/dist/{chunk-CYOF7ROH.js.map → chunk-S5RYMCV6.js.map} +0 -0
- /package/dist/{chunk-ZMHYXMO6.js.map → chunk-U5S527PP.js.map} +0 -0
- /package/dist/{chunk-RY4XKNV3.js.map → chunk-UHTVXQ2O.js.map} +0 -0
- /package/dist/{chunk-QVX5MWJZ.js.map → chunk-W6R3HAAG.js.map} +0 -0
- /package/dist/{chunk-HIVZG55D.js.map → chunk-XJN5WUKL.js.map} +0 -0
- /package/dist/{chunk-HSDCI7OV.js.map → chunk-YLYINX2H.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js.map → config-DBEEM3UA.js.map} +0 -0
- /package/dist/{secp256k1-N3ZHU7LB.js.map → doctor-XDA3YU6H.js.map} +0 -0
- /package/dist/{usdc-JIAJW4SV.js.map → ethersCompat-Df4a6QIZ-WHYKB6HA.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js.map → inspect-YBGDAG47.js.map} +0 -0
- /package/dist/{wallet-PA54CRBL.js.map → outcome-ZFGHX2XW.js.map} +0 -0
|
@@ -2,7 +2,7 @@ import { createRequire as __tenjinCreateRequire } from 'node:module'; const requ
|
|
|
2
2
|
import {
|
|
3
3
|
CliError,
|
|
4
4
|
external_exports
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-6WWVYYSB.js";
|
|
6
6
|
|
|
7
7
|
// src/lib/output.ts
|
|
8
8
|
import { styleText } from "util";
|
|
@@ -25,15 +25,15 @@ var ErrorCodeSchema = external_exports.enum([
|
|
|
25
25
|
"NETWORK_ERROR",
|
|
26
26
|
"INTERNAL",
|
|
27
27
|
"NOT_IMPLEMENTED",
|
|
28
|
-
// B2 (
|
|
28
|
+
// B2 (search/inspect/buy/outcome): a policy refusal (exit 3) has its own code
|
|
29
29
|
// so an agent can distinguish a spend-cap block from a generic REFUSED; a
|
|
30
30
|
// payment that failed after approval (exit 4) is PAYMENT_FAILED; the read
|
|
31
31
|
// route's own coded failures (402 preview parse, 409 gate) surface as these.
|
|
32
32
|
"POLICY_REFUSED",
|
|
33
33
|
"PAYMENT_FAILED",
|
|
34
34
|
"RESOURCE_NOT_FOUND",
|
|
35
|
-
"
|
|
36
|
-
// A 429 from the anonymous
|
|
35
|
+
"SEARCH_NOT_FOUND",
|
|
36
|
+
// A 429 from the anonymous search/outcome/read limits; error.details carries
|
|
37
37
|
// retryAfterSeconds so a looping agent can back off instead of hammering.
|
|
38
38
|
"RATE_LIMITED",
|
|
39
39
|
// B3 (publish): a publish that needs the human's yes (exit 3) — soft scan
|
|
@@ -80,28 +80,37 @@ function defaultIo() {
|
|
|
80
80
|
isTTY: Boolean(process.stdout.isTTY)
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
+
function buildSuccessEnvelope(command, data) {
|
|
84
|
+
return { schemaVersion: SCHEMA_VERSION, command, ok: true, data };
|
|
85
|
+
}
|
|
86
|
+
function buildFailureEnvelope(command, err) {
|
|
87
|
+
const error = {
|
|
88
|
+
code: err.code,
|
|
89
|
+
message: err.message,
|
|
90
|
+
...err.fix !== void 0 ? { fix: err.fix } : {},
|
|
91
|
+
...err.details !== void 0 ? { details: err.details } : {}
|
|
92
|
+
};
|
|
93
|
+
return { schemaVersion: SCHEMA_VERSION, command, ok: false, error };
|
|
94
|
+
}
|
|
83
95
|
function emitSuccess(io, command, data, humanLines = [], opts = {}) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
96
|
+
if (humanMode(io, opts)) {
|
|
97
|
+
writeLines(io.stdout, humanLines);
|
|
98
|
+
return;
|
|
87
99
|
}
|
|
100
|
+
writeJson(io.stdout, buildSuccessEnvelope(command, data));
|
|
88
101
|
}
|
|
89
102
|
function emitFailure(io, command, err, opts = {}) {
|
|
90
103
|
const cliErr = normalizeError(err);
|
|
91
|
-
|
|
92
|
-
code: cliErr.code,
|
|
93
|
-
message: cliErr.message,
|
|
94
|
-
...cliErr.fix !== void 0 ? { fix: cliErr.fix } : {},
|
|
95
|
-
...cliErr.details !== void 0 ? { details: cliErr.details } : {}
|
|
96
|
-
};
|
|
97
|
-
writeJson(io.stdout, { schemaVersion: SCHEMA_VERSION, command, ok: false, error });
|
|
98
|
-
if (shouldRenderHuman(io, opts)) {
|
|
104
|
+
if (humanMode(io, opts)) {
|
|
99
105
|
const lines = [paint(io, "red", `error: ${sanitizeForTerminal(cliErr.message)}`)];
|
|
100
106
|
if (cliErr.fix !== void 0) {
|
|
101
107
|
lines.push(paint(io, "dim", `fix: ${sanitizeForTerminal(cliErr.fix)}`));
|
|
102
108
|
}
|
|
103
|
-
|
|
109
|
+
lines.push(...findingLines(io, cliErr.details));
|
|
110
|
+
writeLines(io.stdout, lines);
|
|
111
|
+
return cliErr;
|
|
104
112
|
}
|
|
113
|
+
writeJson(io.stdout, buildFailureEnvelope(command, cliErr));
|
|
105
114
|
return cliErr;
|
|
106
115
|
}
|
|
107
116
|
function sanitizeForTerminal(text) {
|
|
@@ -112,9 +121,24 @@ function normalizeError(err) {
|
|
|
112
121
|
if (err instanceof Error) return new CliError("INTERNAL", err.message, { cause: err });
|
|
113
122
|
return new CliError("INTERNAL", "Unexpected error", { details: err });
|
|
114
123
|
}
|
|
115
|
-
function
|
|
124
|
+
function humanMode(io, opts) {
|
|
116
125
|
return io.isTTY && opts.json !== true;
|
|
117
126
|
}
|
|
127
|
+
function findingLines(io, details) {
|
|
128
|
+
if (typeof details !== "object" || details === null || !("findings" in details)) return [];
|
|
129
|
+
const { findings } = details;
|
|
130
|
+
if (!Array.isArray(findings) || findings.length === 0) return [];
|
|
131
|
+
const rendered = [];
|
|
132
|
+
for (const f of findings) {
|
|
133
|
+
if (typeof f !== "object" || f === null) continue;
|
|
134
|
+
const { check, line, excerpt } = f;
|
|
135
|
+
if (typeof check !== "string" || typeof line !== "number" || typeof excerpt !== "string") {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
rendered.push(paint(io, "dim", ` ${check} (line ${line}): ${sanitizeForTerminal(excerpt)}`));
|
|
139
|
+
}
|
|
140
|
+
return rendered;
|
|
141
|
+
}
|
|
118
142
|
function writeJson(stream, value) {
|
|
119
143
|
stream.write(`${JSON.stringify(value, null, 2)}
|
|
120
144
|
`);
|
|
@@ -124,14 +148,17 @@ function writeLines(stream, lines) {
|
|
|
124
148
|
`);
|
|
125
149
|
}
|
|
126
150
|
function paint(io, format, text) {
|
|
127
|
-
if (io.
|
|
151
|
+
if (io.stdout instanceof Stream) return styleText(format, text, { stream: io.stdout });
|
|
128
152
|
return styleText(format, text);
|
|
129
153
|
}
|
|
130
154
|
|
|
131
155
|
export {
|
|
132
156
|
defaultIo,
|
|
157
|
+
buildSuccessEnvelope,
|
|
158
|
+
buildFailureEnvelope,
|
|
133
159
|
emitSuccess,
|
|
134
160
|
emitFailure,
|
|
135
|
-
sanitizeForTerminal
|
|
161
|
+
sanitizeForTerminal,
|
|
162
|
+
normalizeError
|
|
136
163
|
};
|
|
137
|
-
//# sourceMappingURL=chunk-
|
|
164
|
+
//# sourceMappingURL=chunk-VV4P5RVK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/output.ts","../src/schemas.ts"],"sourcesContent":["import { styleText } from 'node:util';\nimport { Stream } from 'node:stream';\nimport { CliError } from './errors';\nimport { SCHEMA_VERSION } from '../schemas';\nimport type { FailureEnvelope, OutputError, SuccessEnvelope } from '../schemas';\n\n/**\n * Injected streams + TTY fact. Every command receives one via CommandContext,\n * so tests drive the CLI in-process with memory buffers and no child process.\n * `isTTY` is the real terminal fact; the separate `--json` flag (passed to the\n * emit functions) is what suppresses human rendering — the two are ANDed, never\n * conflated, so `--json` on a TTY still yields pure machine output.\n */\nexport interface Io {\n stdout: NodeJS.WritableStream;\n stderr: NodeJS.WritableStream;\n isTTY: boolean;\n}\n\nexport function defaultIo(): Io {\n return {\n stdout: process.stdout,\n stderr: process.stderr,\n isTTY: Boolean(process.stdout.isTTY),\n };\n}\n\nexport interface EmitOptions {\n /** The global --json flag. When true, the JSON envelope is emitted even at a TTY. */\n json?: boolean;\n}\n\n/**\n * The two pure envelope builders, shared by the CLI's emit functions and the MCP\n * adapter so both surfaces produce the identical wire object by construction. They\n * hold no I/O and no --json branching: they turn a (command, data) or a normalized\n * CliError into the exact object that goes to stdout / structuredContent.\n */\nexport function buildSuccessEnvelope(command: string, data: unknown): SuccessEnvelope {\n return { schemaVersion: SCHEMA_VERSION, command, ok: true, data };\n}\n\nexport function buildFailureEnvelope(command: string, err: CliError): FailureEnvelope {\n const error: OutputError = {\n code: err.code,\n message: err.message,\n ...(err.fix !== undefined ? { fix: err.fix } : {}),\n ...(err.details !== undefined ? { details: err.details } : {}),\n };\n return { schemaVersion: SCHEMA_VERSION, command, ok: false, error };\n}\n\n/**\n * Output contract (human-first): at a TTY without `--json`, print ONLY the human\n * rendering to stdout, no JSON envelope. With `--json`, or when stdout is not a\n * TTY (a pipe, an agent), print exactly one JSON envelope to stdout and nothing\n * else. Exit codes are identical on both paths; only the stdout shape differs.\n */\nexport function emitSuccess(\n io: Io,\n command: string,\n data: unknown,\n humanLines: string[] = [],\n opts: EmitOptions = {},\n): void {\n if (humanMode(io, opts)) {\n writeLines(io.stdout, humanLines);\n return;\n }\n writeJson(io.stdout, buildSuccessEnvelope(command, data));\n}\n\n/**\n * The failure half of the same contract: at a TTY without `--json`, a red error\n * line plus a `fix` line to stdout and no envelope; otherwise exactly one failure\n * envelope to stdout. Accepts a CliError or any thrown value (non-CliError\n * normalizes to INTERNAL). Returns the normalized CliError so the caller reads its\n * `exitCode`.\n */\nexport function emitFailure(\n io: Io,\n command: string,\n err: unknown,\n opts: EmitOptions = {},\n): CliError {\n const cliErr = normalizeError(err);\n if (humanMode(io, opts)) {\n // Error messages can embed server-sourced text (api error passthrough) and\n // never carry intentional ANSI, so sanitize before painting.\n const lines = [paint(io, 'red', `error: ${sanitizeForTerminal(cliErr.message)}`)];\n if (cliErr.fix !== undefined) {\n lines.push(paint(io, 'dim', `fix: ${sanitizeForTerminal(cliErr.fix)}`));\n }\n // Scan findings are the one detail shape a human needs inline: without them an\n // interactive publish hitting NEEDS_CONFIRMATION / PUBLISH_BLOCKED sees the\n // count but not WHICH lines tripped. Every other details shape stays machine-only.\n lines.push(...findingLines(io, cliErr.details));\n writeLines(io.stdout, lines);\n return cliErr;\n }\n writeJson(io.stdout, buildFailureEnvelope(command, cliErr));\n return cliErr;\n}\n\n/**\n * Strip C0/C1 control characters and ANSI escape sequences from a string headed\n * for a terminal. Commands apply this to every SERVER-sourced string (titles,\n * handles) they put into human lines or the buy confirm prompt; without it a\n * malicious deployment could use cursor-movement escapes to overwrite the very\n * price a human is being asked to confirm. It is not applied to whole human\n * lines here because trusted callers (doctor) paint their own ANSI colors. JSON\n * stdout is untouched (JSON.stringify escapes control characters itself).\n */\nexport function sanitizeForTerminal(text: string): string {\n return (\n text\n // CSI/OSC/charset escape sequences first, then any stray ESC and the rest\n // of C0 (except \\t) plus DEL and the C1 range.\n // eslint-disable-next-line no-control-regex\n .replace(/\\x1b(?:\\[[0-9;?]*[ -/]*[@-~]|\\][^\\x07\\x1b]*(?:\\x07|\\x1b\\\\)|[@-Z\\\\-_])/g, '')\n // eslint-disable-next-line no-control-regex\n .replace(/[\\x00-\\x08\\x0a-\\x1f\\x7f-\\x9f]/g, '')\n );\n}\n\n/** CliError passes through; every other thrown value becomes an INTERNAL CliError. */\nexport function normalizeError(err: unknown): CliError {\n if (err instanceof CliError) return err;\n if (err instanceof Error) return new CliError('INTERNAL', err.message, { cause: err });\n return new CliError('INTERNAL', 'Unexpected error', { details: err });\n}\n\n/** True in human-first mode: a TTY without --json. Otherwise the JSON envelope wins. */\nfunction humanMode(io: Io, opts: EmitOptions): boolean {\n return io.isTTY && opts.json !== true;\n}\n\n/**\n * Render `details.findings` (the scan-finding projection publish attaches to\n * NEEDS_CONFIRMATION / PUBLISH_BLOCKED) as one dim line per finding:\n * ` <check> (line N): <excerpt>`. The excerpt is already masked for secret\n * findings at the source; sanitize it anyway since it can echo file content.\n * Returns [] for any other details shape, so no other error leaks a detail dump.\n */\nfunction findingLines(io: Io, details: unknown): string[] {\n if (typeof details !== 'object' || details === null || !('findings' in details)) return [];\n const { findings } = details as { findings: unknown };\n if (!Array.isArray(findings) || findings.length === 0) return [];\n const rendered: string[] = [];\n for (const f of findings) {\n if (typeof f !== 'object' || f === null) continue;\n const { check, line, excerpt } = f as { check?: unknown; line?: unknown; excerpt?: unknown };\n if (typeof check !== 'string' || typeof line !== 'number' || typeof excerpt !== 'string') {\n continue;\n }\n rendered.push(paint(io, 'dim', ` ${check} (line ${line}): ${sanitizeForTerminal(excerpt)}`));\n }\n return rendered;\n}\n\nfunction writeJson(stream: NodeJS.WritableStream, value: unknown): void {\n stream.write(`${JSON.stringify(value, null, 2)}\\n`);\n}\n\nfunction writeLines(stream: NodeJS.WritableStream, lines: string[]): void {\n if (lines.length > 0) stream.write(`${lines.join('\\n')}\\n`);\n}\n\n/**\n * Color a human line for stdout (the human surface now). styleText emits ANSI only\n * when the target stream is color-capable (a real TTY with color depth) and honors\n * NO_COLOR/FORCE_COLOR natively. The `stream` option is passed only when stdout is\n * a genuine Stream; a test/redirected sink is not one, so it falls back to the\n * default capability check and comes out plain.\n */\nfunction paint(io: Io, format: Parameters<typeof styleText>[0], text: string): string {\n if (io.stdout instanceof Stream) return styleText(format, text, { stream: io.stdout });\n return styleText(format, text);\n}\n","import { z } from 'zod';\n\n/**\n * Bumped only on a breaking change to any stdout envelope shape. Agents pin on\n * this: a consumer that sees an unexpected value should refuse to parse rather\n * than guess. Every envelope carries it, success or failure.\n */\nexport const SCHEMA_VERSION = 1;\n\n/**\n * The closed set of machine error codes. `error.code` in a failure envelope is\n * always one of these; agents branch on it, humans read `message`/`fix`. The\n * exit-code mapping lives in lib/errors.ts (this enum is the single source of\n * the code names both sides agree on).\n */\nexport const ErrorCodeSchema = z.enum([\n 'NODE_UNSUPPORTED',\n 'USAGE',\n 'CONFIG_INVALID',\n 'WALLET_EXISTS',\n 'WALLET_MISSING',\n 'WALLET_INVALID_KEY',\n 'PROVIDER_ERROR',\n 'RPC_ERROR',\n 'API_UNREACHABLE',\n 'CONTRACT_MISMATCH',\n 'REFUSED',\n 'NETWORK_ERROR',\n 'INTERNAL',\n 'NOT_IMPLEMENTED',\n // B2 (search/inspect/buy/outcome): a policy refusal (exit 3) has its own code\n // so an agent can distinguish a spend-cap block from a generic REFUSED; a\n // payment that failed after approval (exit 4) is PAYMENT_FAILED; the read\n // route's own coded failures (402 preview parse, 409 gate) surface as these.\n 'POLICY_REFUSED',\n 'PAYMENT_FAILED',\n 'RESOURCE_NOT_FOUND',\n 'SEARCH_NOT_FOUND',\n // A 429 from the anonymous search/outcome/read limits; error.details carries\n // retryAfterSeconds so a looping agent can back off instead of hammering.\n 'RATE_LIMITED',\n // B3 (publish): a publish that needs the human's yes (exit 3) — soft scan\n // findings, or `review` mode always. NEEDS_CONFIRMATION clears with --yes;\n // PUBLISH_BLOCKED is a hard-block finding (a live secret) that no mode or --yes\n // ever clears. PUBLISH_FAILED (exit 4) is a write that failed AFTER approval,\n // mirroring PAYMENT_FAILED's post-decision failure class.\n 'NEEDS_CONFIRMATION',\n 'PUBLISH_BLOCKED',\n 'PUBLISH_FAILED',\n]);\nexport type ErrorCode = z.infer<typeof ErrorCodeSchema>;\n\n/**\n * All money in machine output is dual-form: `atomic` is the 6-decimal USDC base\n * unit as a decimal string (never a JS number — precision), `usd` is the same\n * value formatted as decimal dollars. Emit both so agents compute on `atomic`\n * and humans read `usd` without either side re-deriving the other.\n */\nexport const MoneySchema = z.object({\n atomic: z.string(),\n usd: z.string(),\n});\nexport type Money = z.infer<typeof MoneySchema>;\n\nexport const OutputErrorSchema = z.object({\n code: ErrorCodeSchema,\n message: z.string(),\n fix: z.string().optional(),\n details: z.unknown().optional(),\n});\nexport type OutputError = z.infer<typeof OutputErrorSchema>;\n\nexport const SuccessEnvelopeSchema = z.object({\n schemaVersion: z.literal(SCHEMA_VERSION),\n command: z.string(),\n ok: z.literal(true),\n data: z.unknown(),\n});\nexport type SuccessEnvelope = z.infer<typeof SuccessEnvelopeSchema>;\n\nexport const FailureEnvelopeSchema = z.object({\n schemaVersion: z.literal(SCHEMA_VERSION),\n command: z.string(),\n ok: z.literal(false),\n error: OutputErrorSchema,\n});\nexport type FailureEnvelope = z.infer<typeof FailureEnvelopeSchema>;\n\n/** The one thing every invocation prints to stdout, discriminated on `ok`. */\nexport const OutputEnvelopeSchema = z.discriminatedUnion('ok', [\n SuccessEnvelopeSchema,\n FailureEnvelopeSchema,\n]);\nexport type OutputEnvelope = z.infer<typeof OutputEnvelopeSchema>;\n"],"mappings":";;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,cAAc;;;ACMhB,IAAM,iBAAiB;AAQvB,IAAM,kBAAkB,iBAAE,KAAK;AAAA,EACpC;AAAA,EACA;AAAA,EAC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es,
|
|
36
36
|
rotr,
|
|
37
37
|
toBytes
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-KYQVEKP5.js";
|
|
39
39
|
|
|
40
40
|
// node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_md.js
|
|
41
41
|
function setBigUint64(view, byteOffset, value, isLE) {
|
|
@@ -2250,4 +2250,4 @@ export {
|
|
|
2250
2250
|
@noble/curves/esm/secp256k1.js:
|
|
2251
2251
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
2252
2252
|
*/
|
|
2253
|
-
//# sourceMappingURL=chunk-
|
|
2253
|
+
//# sourceMappingURL=chunk-W6R3HAAG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/ids.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\n/**\n * The shared identity patterns for server-controlled values that become file\n * paths, URL segments, or terminal output. One definition so a future change\n * (e.g. accepting uppercase ids) cannot be applied in one command and missed in\n * another. SLUG_RE must match the server's slugify charset (lib/posts.ts:\n * lowercase a-z0-9 groups joined by single hyphens, no leading/trailing hyphen).\n */\nexport const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\nexport const SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\n/** A non-negative atomic USDC integer string (6-decimal base units). */\nexport const ATOMIC_RE = /^\\d{1,39}$/;\n\n/**\n * Mint a fresh opaque id for a locally-created entity (a parked candidate). A v4\n * uuid: the same shape a
|
|
1
|
+
{"version":3,"sources":["../src/lib/ids.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\n/**\n * The shared identity patterns for server-controlled values that become file\n * paths, URL segments, or terminal output. One definition so a future change\n * (e.g. accepting uppercase ids) cannot be applied in one command and missed in\n * another. SLUG_RE must match the server's slugify charset (lib/posts.ts:\n * lowercase a-z0-9 groups joined by single hyphens, no leading/trailing hyphen).\n */\nexport const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\nexport const SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\n/** A non-negative atomic USDC integer string (6-decimal base units). */\nexport const ATOMIC_RE = /^\\d{1,39}$/;\n\n/**\n * Mint a fresh opaque id for a locally-created entity (a parked candidate). A v4\n * uuid: the same shape a searchId takes, so UUID_RE validates it and a `drop\n * <id>` argument that reaches a filesystem path can't traverse out of the store.\n */\nexport function newId(): string {\n return randomUUID();\n}\n"],"mappings":";;;AAAA,SAAS,kBAAkB;AASpB,IAAM,UAAU;AAChB,IAAM,UAAU;AAEhB,IAAM,YAAY;AAOlB,SAAS,QAAgB;AAC9B,SAAO,WAAW;AACpB;","names":[]}
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
swap32IfBE,
|
|
16
16
|
toBytes,
|
|
17
17
|
u32
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-KYQVEKP5.js";
|
|
19
19
|
|
|
20
20
|
// node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha3.js
|
|
21
21
|
var _0n = BigInt(0);
|
|
@@ -201,4 +201,4 @@ var keccak_256 = /* @__PURE__ */ (() => gen(1, 136, 256 / 8))();
|
|
|
201
201
|
export {
|
|
202
202
|
keccak_256
|
|
203
203
|
};
|
|
204
|
-
//# sourceMappingURL=chunk-
|
|
204
|
+
//# sourceMappingURL=chunk-XJN5WUKL.js.map
|
|
@@ -7,9 +7,9 @@ import {
|
|
|
7
7
|
} from "./chunk-MUBUQVC3.js";
|
|
8
8
|
import {
|
|
9
9
|
external_exports
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-6WWVYYSB.js";
|
|
11
11
|
|
|
12
|
-
// src/lib/
|
|
12
|
+
// src/lib/search-store.ts
|
|
13
13
|
import { mkdir, readFile } from "fs/promises";
|
|
14
14
|
import { join } from "path";
|
|
15
15
|
var MAX_ENTRIES = 50;
|
|
@@ -19,8 +19,8 @@ var StoredCandidateSchema = external_exports.object({
|
|
|
19
19
|
title: external_exports.string(),
|
|
20
20
|
price: external_exports.string()
|
|
21
21
|
});
|
|
22
|
-
var
|
|
23
|
-
|
|
22
|
+
var StoredSearchSchema = external_exports.object({
|
|
23
|
+
searchId: external_exports.string(),
|
|
24
24
|
at: external_exports.string(),
|
|
25
25
|
question: external_exports.string(),
|
|
26
26
|
decision: external_exports.string(),
|
|
@@ -28,12 +28,12 @@ var StoredLookupSchema = external_exports.object({
|
|
|
28
28
|
});
|
|
29
29
|
var StoreSchema = external_exports.object({
|
|
30
30
|
schemaVersion: external_exports.literal(1),
|
|
31
|
-
|
|
31
|
+
searches: external_exports.array(StoredSearchSchema)
|
|
32
32
|
});
|
|
33
33
|
function storePath(dataDir) {
|
|
34
|
-
return join(dataDir, "
|
|
34
|
+
return join(dataDir, "searches.json");
|
|
35
35
|
}
|
|
36
|
-
async function
|
|
36
|
+
async function loadSearches(dataDir) {
|
|
37
37
|
let raw;
|
|
38
38
|
try {
|
|
39
39
|
raw = await readFile(storePath(dataDir), "utf8");
|
|
@@ -47,50 +47,50 @@ async function loadLookups(dataDir) {
|
|
|
47
47
|
return [];
|
|
48
48
|
}
|
|
49
49
|
const parsed = StoreSchema.safeParse(json);
|
|
50
|
-
return parsed.success ? parsed.data.
|
|
50
|
+
return parsed.success ? parsed.data.searches : [];
|
|
51
51
|
}
|
|
52
|
-
async function
|
|
52
|
+
async function recordSearch(dataDir, entry) {
|
|
53
53
|
await mkdir(dataDir, { recursive: true, mode: 448 });
|
|
54
54
|
const lockPath = `${storePath(dataDir)}.lock`;
|
|
55
55
|
await withFileLock(lockPath, async () => {
|
|
56
|
-
const existing = await
|
|
57
|
-
const
|
|
56
|
+
const existing = await loadSearches(dataDir);
|
|
57
|
+
const searches = [entry, ...existing.filter((l) => l.searchId !== entry.searchId)].slice(
|
|
58
58
|
0,
|
|
59
59
|
MAX_ENTRIES
|
|
60
60
|
);
|
|
61
61
|
await writeFileAtomic(
|
|
62
62
|
storePath(dataDir),
|
|
63
|
-
`${JSON.stringify({ schemaVersion: 1,
|
|
63
|
+
`${JSON.stringify({ schemaVersion: 1, searches }, null, 2)}
|
|
64
64
|
`,
|
|
65
65
|
{ mode: 420, dirMode: 448 }
|
|
66
66
|
);
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
-
async function
|
|
70
|
-
const
|
|
71
|
-
return
|
|
69
|
+
async function latestSearch(dataDir) {
|
|
70
|
+
const searches = await loadSearches(dataDir);
|
|
71
|
+
return searches[0] ?? null;
|
|
72
72
|
}
|
|
73
73
|
async function findStoredCandidate(dataDir, resourceId) {
|
|
74
|
-
for (const
|
|
75
|
-
const hit =
|
|
74
|
+
for (const search of await loadSearches(dataDir)) {
|
|
75
|
+
const hit = search.candidates.find((c) => c.resourceId === resourceId);
|
|
76
76
|
if (hit) return hit;
|
|
77
77
|
}
|
|
78
78
|
return null;
|
|
79
79
|
}
|
|
80
|
-
async function
|
|
81
|
-
for (const
|
|
82
|
-
const hit =
|
|
80
|
+
async function findSearchForResource(dataDir, match) {
|
|
81
|
+
for (const search of await loadSearches(dataDir)) {
|
|
82
|
+
const hit = search.candidates.some(
|
|
83
83
|
(c) => match.resourceId !== void 0 && c.resourceId === match.resourceId || match.url !== void 0 && c.url === match.url
|
|
84
84
|
);
|
|
85
|
-
if (hit) return
|
|
85
|
+
if (hit) return search.searchId;
|
|
86
86
|
}
|
|
87
87
|
return null;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
export {
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
recordSearch,
|
|
92
|
+
latestSearch,
|
|
93
93
|
findStoredCandidate,
|
|
94
|
-
|
|
94
|
+
findSearchForResource
|
|
95
95
|
};
|
|
96
|
-
//# sourceMappingURL=chunk-
|
|
96
|
+
//# sourceMappingURL=chunk-XNNOR7F7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/search-store.ts"],"sourcesContent":["import { mkdir, readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { z } from 'zod';\nimport { writeFileAtomic } from './atomic-json';\nimport { withFileLock } from './lock';\n\n/**\n * A small local ledger of recent searches so `outcome --last` can target the most\n * recent one and `buy <resourceId>` can resolve the payable read URL a candidate\n * carried (the read route is keyed by handle/slug, not id, so an id alone can't\n * build the URL). Bounded and best-effort: a corrupt file reads as empty rather\n * than blocking a command. NOT an entitlement record, that is the library receipt.\n */\n\nconst MAX_ENTRIES = 50;\n\nconst StoredCandidateSchema = z.object({\n resourceId: z.string(),\n url: z.string(),\n title: z.string(),\n price: z.string(),\n});\nexport type StoredCandidate = z.infer<typeof StoredCandidateSchema>;\n\nconst StoredSearchSchema = z.object({\n searchId: z.string(),\n at: z.string(),\n question: z.string(),\n decision: z.string(),\n candidates: z.array(StoredCandidateSchema),\n});\nexport type StoredSearch = z.infer<typeof StoredSearchSchema>;\n\nconst StoreSchema = z.object({\n schemaVersion: z.literal(1),\n searches: z.array(StoredSearchSchema),\n});\n\nfunction storePath(dataDir: string): string {\n return join(dataDir, 'searches.json');\n}\n\nexport async function loadSearches(dataDir: string): Promise<StoredSearch[]> {\n let raw: string;\n try {\n raw = await readFile(storePath(dataDir), 'utf8');\n } catch {\n return [];\n }\n let json: unknown;\n try {\n json = JSON.parse(raw);\n } catch {\n return [];\n }\n const parsed = StoreSchema.safeParse(json);\n return parsed.success ? parsed.data.searches : [];\n}\n\n/** Prepend a search (newest first), cap to MAX_ENTRIES, persist under a lock so\n * concurrent searches don't drop each other's entry. */\nexport async function recordSearch(dataDir: string, entry: StoredSearch): Promise<void> {\n await mkdir(dataDir, { recursive: true, mode: 0o700 });\n const lockPath = `${storePath(dataDir)}.lock`;\n await withFileLock(lockPath, async () => {\n const existing = await loadSearches(dataDir);\n const searches = [entry, ...existing.filter((l) => l.searchId !== entry.searchId)].slice(\n 0,\n MAX_ENTRIES,\n );\n await writeFileAtomic(\n storePath(dataDir),\n `${JSON.stringify({ schemaVersion: 1, searches }, null, 2)}\\n`,\n { mode: 0o644, dirMode: 0o700 },\n );\n });\n}\n\nexport async function latestSearch(dataDir: string): Promise<StoredSearch | null> {\n const searches = await loadSearches(dataDir);\n return searches[0] ?? null;\n}\n\n/** The stored candidate for a resourceId across recent searches (newest first). */\nexport async function findStoredCandidate(\n dataDir: string,\n resourceId: string,\n): Promise<StoredCandidate | null> {\n for (const search of await loadSearches(dataDir)) {\n const hit = search.candidates.find((c) => c.resourceId === resourceId);\n if (hit) return hit;\n }\n return null;\n}\n\n/** The most recent searchId that surfaced this resource (by id or url), for\n * purchase attribution (`X-Tenjin-Search-Id`). Null when no local search did. */\nexport async function findSearchForResource(\n dataDir: string,\n match: { resourceId?: string; url?: string },\n): Promise<string | null> {\n for (const search of await loadSearches(dataDir)) {\n const hit = search.candidates.some(\n (c) =>\n (match.resourceId !== undefined && c.resourceId === match.resourceId) ||\n (match.url !== undefined && c.url === match.url),\n );\n if (hit) return search.searchId;\n }\n return null;\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,OAAO,gBAAgB;AAChC,SAAS,YAAY;AAarB,IAAM,cAAc;AAEpB,IAAM,wBAAwB,iBAAE,OAAO;AAAA,EACrC,YAAY,iBAAE,OAAO;AAAA,EACrB,KAAK,iBAAE,OAAO;AAAA,EACd,OAAO,iBAAE,OAAO;AAAA,EAChB,OAAO,iBAAE,OAAO;AAClB,CAAC;AAGD,IAAM,qBAAqB,iBAAE,OAAO;AAAA,EAClC,UAAU,iBAAE,OAAO;AAAA,EACnB,IAAI,iBAAE,OAAO;AAAA,EACb,UAAU,iBAAE,OAAO;AAAA,EACnB,UAAU,iBAAE,OAAO;AAAA,EACnB,YAAY,iBAAE,MAAM,qBAAqB;AAC3C,CAAC;AAGD,IAAM,cAAc,iBAAE,OAAO;AAAA,EAC3B,eAAe,iBAAE,QAAQ,CAAC;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AK,QAAO;AAAA,EAClB;AACA,SAAO;AACT;AAIA,eAAsB,sBACpB,SACA,OACwB;AACxB,aAAW,UAAU,MAAM,aAAa,OAAO,GAAG;AAChD,UAAM,MAAM,OAAO,WAAW;AAAA,MAC5B,CAAC,MACE,MAAM,eAAe,UAAa,EAAE,eAAe,MAAM,cACzD,MAAM,QAAQ,UAAa,EAAE,QAAQ,MAAM;AAAA,IAChD;AACA,QAAI,IAAK,QAAO,OAAO;AAAA,EACzB;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,41 +1,22 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
fetchRead
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-5JH7ZB6Z.js";
|
|
5
5
|
import {
|
|
6
6
|
headingOutline
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-FU6MCSLG.js";
|
|
8
8
|
import {
|
|
9
9
|
resolveResourceRef
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import "./chunk-JPHG2JW3.js";
|
|
12
|
-
import "./chunk-662MSGZB.js";
|
|
13
|
-
import "./chunk-3OV7E5G5.js";
|
|
10
|
+
} from "./chunk-MM4TGTST.js";
|
|
14
11
|
import {
|
|
15
12
|
sanitizeForTerminal
|
|
16
|
-
} from "./chunk-
|
|
17
|
-
import "./chunk-4ONXEEQL.js";
|
|
18
|
-
import "./chunk-FJPLRISB.js";
|
|
19
|
-
import "./chunk-RRN3YTK7.js";
|
|
20
|
-
import "./chunk-CYOF7ROH.js";
|
|
21
|
-
import "./chunk-ZABPQJ3M.js";
|
|
22
|
-
import "./chunk-HSDCI7OV.js";
|
|
13
|
+
} from "./chunk-VV4P5RVK.js";
|
|
23
14
|
import {
|
|
24
15
|
resolveContextSettings
|
|
25
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-FHB3VKZW.js";
|
|
26
17
|
import {
|
|
27
18
|
toMoney
|
|
28
|
-
} from "./chunk-
|
|
29
|
-
import "./chunk-YBMMV4Y4.js";
|
|
30
|
-
import "./chunk-UO22YNY4.js";
|
|
31
|
-
import "./chunk-MUBUQVC3.js";
|
|
32
|
-
import "./chunk-OYMYCW7J.js";
|
|
33
|
-
import "./chunk-RY4XKNV3.js";
|
|
34
|
-
import "./chunk-QVX5MWJZ.js";
|
|
35
|
-
import "./chunk-HIVZG55D.js";
|
|
36
|
-
import "./chunk-RBJPAZFI.js";
|
|
37
|
-
import "./chunk-5CLSD5YN.js";
|
|
38
|
-
import "./chunk-ZXTAQYNA.js";
|
|
19
|
+
} from "./chunk-BXUS5UCT.js";
|
|
39
20
|
|
|
40
21
|
// src/commands/inspect.ts
|
|
41
22
|
async function runInspect(args, ctx, deps = {}) {
|
|
@@ -90,7 +71,8 @@ async function runInspect(args, ctx, deps = {}) {
|
|
|
90
71
|
humanLines: [sanitizeForTerminal(result.message)]
|
|
91
72
|
};
|
|
92
73
|
}
|
|
74
|
+
|
|
93
75
|
export {
|
|
94
76
|
runInspect
|
|
95
77
|
};
|
|
96
|
-
//# sourceMappingURL=
|
|
78
|
+
//# sourceMappingURL=chunk-YFREUEUI.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/commands/inspect.ts"],"sourcesContent":["import { resolveResourceRef } from '../lib/resource-ref';\nimport { resolveContextSettings } from '../lib/settings';\nimport { fetchRead } from '../lib/read-client';\nimport { toMoney } from '../lib/money';\nimport { headingOutline } from '../lib/markdown';\nimport { sanitizeForTerminal } from '../lib/output';\nimport type { CommandContext, CommandResult } from '../context';\n\n/**\n * `tenjin inspect <resource-url-or-id>`, fetch the pre-purchase answer card /\n * preview from the read route's 402 body WITHOUT paying (spec 10). A free\n * resource returns 200 with the whole body; a paid one returns the leak-safe\n * preview plus the advertised price/network. Never signs, never pays, never saves.\n */\n\nexport interface InspectArgs {\n ref: string;\n}\n\nexport interface InspectDeps {\n fetchImpl?: typeof fetch;\n}\n\nexport async function runInspect(\n args: InspectArgs,\n ctx: CommandContext,\n deps: InspectDeps = {},\n): Promise<CommandResult> {\n const settings = await resolveContextSettings(ctx);\n const ref = await resolveResourceRef(args.ref, ctx.dataDir, settings.baseUrl);\n\n const result = await fetchRead(ref.url, {\n timeoutMs: ctx.flags.timeout,\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n });\n\n if (result.kind === 'entitled') {\n // Free (or already-entitled) resource: the body is readable now, no payment.\n const body = result.body;\n return {\n data: {\n url: ref.url,\n resourceId: body.id,\n access: 'free',\n title: body.title,\n price: toMoney(body.price),\n headings: headingOutline(body.bodyMd),\n },\n humanLines: [\n `${sanitizeForTerminal(body.title)}, free (${body.price} atomic). Read it with \\`tenjin buy\\`.`,\n ],\n };\n }\n\n if (result.kind === 'payment_required') {\n const requirement = result.paymentRequired.accepts[0];\n const price = requirement !== undefined ? toMoney(requirement.amount) : undefined;\n return {\n data: {\n url: ref.url,\n ...(ref.resourceId !== undefined ? { resourceId: ref.resourceId } : {}),\n access: 'paid',\n ...(price !== undefined ? { price } : {}),\n payment:\n requirement !== undefined\n ? {\n scheme: requirement.scheme,\n network: requirement.network,\n asset: requirement.asset,\n payTo: requirement.payTo,\n amount: requirement.amount,\n }\n : undefined,\n preview: result.preview,\n },\n humanLines: [\n `Paid resource${price !== undefined ? `, ${price.usd} USD (${price.atomic} atomic)` : ''}.`,\n 'This is the pre-purchase card; run `tenjin buy` to pay and read.',\n ],\n };\n }\n\n // already_purchased without a payment header is unexpected; report it plainly.\n return {\n data: { url: ref.url, access: 'entitled', message: result.message },\n humanLines: [sanitizeForTerminal(result.message)],\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/commands/inspect.ts"],"sourcesContent":["import { resolveResourceRef } from '../lib/resource-ref';\nimport { resolveContextSettings } from '../lib/settings';\nimport { fetchRead } from '../lib/read-client';\nimport { toMoney } from '../lib/money';\nimport { headingOutline } from '../lib/markdown';\nimport { sanitizeForTerminal } from '../lib/output';\nimport type { CommandContext, CommandResult } from '../context';\n\n/**\n * `tenjin inspect <resource-url-or-id>`, fetch the pre-purchase answer card /\n * preview from the read route's 402 body WITHOUT paying (spec 10). A free\n * resource returns 200 with the whole body; a paid one returns the leak-safe\n * preview plus the advertised price/network. Never signs, never pays, never saves.\n */\n\nexport interface InspectArgs {\n ref: string;\n}\n\nexport interface InspectDeps {\n fetchImpl?: typeof fetch;\n}\n\nexport async function runInspect(\n args: InspectArgs,\n ctx: CommandContext,\n deps: InspectDeps = {},\n): Promise<CommandResult> {\n const settings = await resolveContextSettings(ctx);\n const ref = await resolveResourceRef(args.ref, ctx.dataDir, settings.baseUrl);\n\n const result = await fetchRead(ref.url, {\n timeoutMs: ctx.flags.timeout,\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n });\n\n if (result.kind === 'entitled') {\n // Free (or already-entitled) resource: the body is readable now, no payment.\n const body = result.body;\n return {\n data: {\n url: ref.url,\n resourceId: body.id,\n access: 'free',\n title: body.title,\n price: toMoney(body.price),\n headings: headingOutline(body.bodyMd),\n },\n humanLines: [\n `${sanitizeForTerminal(body.title)}, free (${body.price} atomic). Read it with \\`tenjin buy\\`.`,\n ],\n };\n }\n\n if (result.kind === 'payment_required') {\n const requirement = result.paymentRequired.accepts[0];\n const price = requirement !== undefined ? toMoney(requirement.amount) : undefined;\n return {\n data: {\n url: ref.url,\n ...(ref.resourceId !== undefined ? { resourceId: ref.resourceId } : {}),\n access: 'paid',\n ...(price !== undefined ? { price } : {}),\n payment:\n requirement !== undefined\n ? {\n scheme: requirement.scheme,\n network: requirement.network,\n asset: requirement.asset,\n payTo: requirement.payTo,\n amount: requirement.amount,\n }\n : undefined,\n preview: result.preview,\n },\n humanLines: [\n `Paid resource${price !== undefined ? `, ${price.usd} USD (${price.atomic} atomic)` : ''}.`,\n 'This is the pre-purchase card; run `tenjin buy` to pay and read.',\n ],\n };\n }\n\n // already_purchased without a payment header is unexpected; report it plainly.\n return {\n data: { url: ref.url, access: 'entitled', message: result.message },\n humanLines: [sanitizeForTerminal(result.message)],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuBA,eAAsB,WACpB,MACA,KACA,OAAoB,CAAC,GACG;AACxB,QAAM,WAAW,MAAM,uBAAuB,GAAG;AACjD,QAAM,MAAM,MAAM,mBAAmB,KAAK,KAAK,IAAI,SAAS,SAAS,OAAO;AAE5E,QAAM,SAAS,MAAM,UAAU,IAAI,KAAK;AAAA,IACtC,WAAW,IAAI,MAAM;AAAA,IACrB,GAAI,KAAK,cAAc,SAAY,EAAE,WAAW,KAAK,UAAU,IAAI,CAAC;AAAA,EACtE,CAAC;AAED,MAAI,OAAO,SAAS,YAAY;AAE9B,UAAM,OAAO,OAAO;AACpB,WAAO;AAAA,MACL,MAAM;AAAA,QACJ,KAAK,IAAI;AAAA,QACT,YAAY,KAAK;AAAA,QACjB,QAAQ;AAAA,QACR,OAAO,KAAK;AAAA,QACZ,OAAO,QAAQ,KAAK,KAAK;AAAA,QACzB,UAAU,eAAe,KAAK,MAAM;AAAA,MACtC;AAAA,MACA,YAAY;AAAA,QACV,GAAG,oBAAoB,KAAK,KAAK,CAAC,WAAW,KAAK,KAAK;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AAEA,MAAI,OAAO,SAAS,oBAAoB;AACtC,UAAM,cAAc,OAAO,gBAAgB,QAAQ,CAAC;AACpD,UAAM,QAAQ,gBAAgB,SAAY,QAAQ,YAAY,MAAM,IAAI;AACxE,WAAO;AAAA,MACL,MAAM;AAAA,QACJ,KAAK,IAAI;AAAA,QACT,GAAI,IAAI,eAAe,SAAY,EAAE,YAAY,IAAI,WAAW,IAAI,CAAC;AAAA,QACrE,QAAQ;AAAA,QACR,GAAI,UAAU,SAAY,EAAE,MAAM,IAAI,CAAC;AAAA,QACvC,SACE,gBAAgB,SACZ;AAAA,UACE,QAAQ,YAAY;AAAA,UACpB,SAAS,YAAY;AAAA,UACrB,OAAO,YAAY;AAAA,UACnB,OAAO,YAAY;AAAA,UACnB,QAAQ,YAAY;AAAA,QACtB,IACA;AAAA,QACN,SAAS,OAAO;AAAA,MAClB;AAAA,MACA,YAAY;AAAA,QACV,gBAAgB,UAAU,SAAY,KAAK,MAAM,GAAG,SAAS,MAAM,MAAM,aAAa,EAAE;AAAA,QACxF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAGA,SAAO;AAAA,IACL,MAAM,EAAE,KAAK,IAAI,KAAK,QAAQ,YAAY,SAAS,OAAO,QAAQ;AAAA,IAClE,YAAY,CAAC,oBAAoB,OAAO,OAAO,CAAC;AAAA,EAClD;AACF;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
keccak_256
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-XJN5WUKL.js";
|
|
5
5
|
import {
|
|
6
6
|
bytesToHex
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-KYQVEKP5.js";
|
|
8
8
|
import {
|
|
9
9
|
__commonJS,
|
|
10
10
|
__require,
|
|
@@ -7803,4 +7803,4 @@ export {
|
|
|
7803
7803
|
p2 as p,
|
|
7804
7804
|
m2 as m
|
|
7805
7805
|
};
|
|
7806
|
-
//# sourceMappingURL=chunk-
|
|
7806
|
+
//# sourceMappingURL=chunk-YLYINX2H.js.map
|