tenjin-cli 0.1.0-alpha.1 → 0.1.0-alpha.10
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/NOTICE.md +33 -0
- package/README.md +572 -79
- package/dist/{_esm-ZH2J4QEH.js → _esm-C5CRWCYU.js} +2 -2
- package/dist/_esm-N4KAVXQR.js +881 -0
- package/dist/buy-FMDBZ4NY.js +44 -0
- package/dist/candidate-7LAELUQD.js +23 -0
- package/dist/ccip-RPPPKTJR.js +19 -0
- package/dist/{ccip-UCLT5VOW.js → ccip-ZGGWQN4X.js} +6 -5
- package/dist/chunk-2GSRYTZS.js +127 -0
- package/dist/chunk-2GSRYTZS.js.map +1 -0
- package/dist/chunk-2I4QTOLB.js +11 -0
- package/dist/chunk-2I4QTOLB.js.map +1 -0
- package/dist/chunk-36X2CA3N.js +311 -0
- package/dist/chunk-36X2CA3N.js.map +1 -0
- package/dist/{chunk-BRJHUQSY.js → chunk-47PP7TAG.js} +908 -812
- package/dist/chunk-47PP7TAG.js.map +1 -0
- package/dist/chunk-5JMKIDMM.js +316 -0
- package/dist/chunk-5JMKIDMM.js.map +1 -0
- package/dist/chunk-5JXAZP7H.js +206 -0
- package/dist/chunk-5JXAZP7H.js.map +1 -0
- package/dist/chunk-5SE6BJRP.js +135 -0
- package/dist/chunk-5SE6BJRP.js.map +1 -0
- package/dist/chunk-6BZLSRNU.js +149 -0
- package/dist/chunk-6BZLSRNU.js.map +1 -0
- package/dist/{chunk-IPOWB3G3.js → chunk-7FK2UN2T.js} +3515 -507
- package/dist/chunk-7FK2UN2T.js.map +1 -0
- package/dist/chunk-7WDY4AXV.js +14620 -0
- package/dist/chunk-7WDY4AXV.js.map +1 -0
- package/dist/chunk-A6KCZPNQ.js +83 -0
- package/dist/chunk-A6KCZPNQ.js.map +1 -0
- package/dist/chunk-AWQ6A4CI.js +341 -0
- package/dist/chunk-AWQ6A4CI.js.map +1 -0
- package/dist/chunk-BJJ5BQO6.js +162 -0
- package/dist/chunk-BJJ5BQO6.js.map +1 -0
- package/dist/chunk-BUDHTDKL.js +612 -0
- package/dist/chunk-BUDHTDKL.js.map +1 -0
- package/dist/chunk-DKQMJTG7.js +188 -0
- package/dist/chunk-DKQMJTG7.js.map +1 -0
- package/dist/chunk-FKSAUOJU.js +137 -0
- package/dist/chunk-FKSAUOJU.js.map +1 -0
- package/dist/{chunk-EXBMF5X7.js → chunk-GECSWJ7O.js} +526 -79
- package/dist/chunk-GECSWJ7O.js.map +1 -0
- package/dist/chunk-GSDZRCGF.js +105 -0
- package/dist/chunk-GSDZRCGF.js.map +1 -0
- package/dist/chunk-JSSIMGQT.js +174 -0
- package/dist/chunk-JSSIMGQT.js.map +1 -0
- package/dist/chunk-KYH4KPE5.js +1357 -0
- package/dist/chunk-KYH4KPE5.js.map +1 -0
- package/dist/chunk-KYQVEKP5.js +209 -0
- package/dist/chunk-KYQVEKP5.js.map +1 -0
- package/dist/chunk-KZAAWQNP.js +6199 -0
- package/dist/chunk-KZAAWQNP.js.map +1 -0
- package/dist/{chunk-T4LKNY7T.js → chunk-M2O56UK7.js} +225 -70
- package/dist/chunk-M2O56UK7.js.map +1 -0
- package/dist/chunk-MD7WGYYI.js +125 -0
- package/dist/chunk-MD7WGYYI.js.map +1 -0
- package/dist/chunk-MJZZTKCC.js +323 -0
- package/dist/chunk-MJZZTKCC.js.map +1 -0
- package/dist/chunk-O6CAUZGY.js +317 -0
- package/dist/chunk-O6CAUZGY.js.map +1 -0
- package/dist/chunk-P74I3WH4.js +204 -0
- package/dist/chunk-P74I3WH4.js.map +1 -0
- package/dist/chunk-POF7HPRV.js +145 -0
- package/dist/chunk-POF7HPRV.js.map +1 -0
- package/dist/chunk-POJRB2AE.js +83 -0
- package/dist/chunk-POJRB2AE.js.map +1 -0
- package/dist/{chunk-YG2DO46P.js → chunk-PZRAAAY2.js} +107 -22
- package/dist/chunk-PZRAAAY2.js.map +1 -0
- package/dist/chunk-PZSUWDF2.js +35 -0
- package/dist/chunk-PZSUWDF2.js.map +1 -0
- package/dist/chunk-QW2Q2KAH.js +27 -0
- package/dist/chunk-QW2Q2KAH.js.map +1 -0
- package/dist/chunk-R2VLGNFD.js +181 -0
- package/dist/chunk-R2VLGNFD.js.map +1 -0
- package/dist/{chunk-CUWUHTIL.js → chunk-RBJPAZFI.js} +16 -202
- package/dist/chunk-RBJPAZFI.js.map +1 -0
- package/dist/chunk-S5RYMCV6.js +70 -0
- package/dist/chunk-S5RYMCV6.js.map +1 -0
- package/dist/chunk-SGK2B724.js +67 -0
- package/dist/chunk-SGK2B724.js.map +1 -0
- package/dist/chunk-STND72DS.js +242 -0
- package/dist/chunk-STND72DS.js.map +1 -0
- package/dist/chunk-TEL27PR5.js +124 -0
- package/dist/chunk-TEL27PR5.js.map +1 -0
- package/dist/chunk-TWRYSGAW.js +134 -0
- package/dist/chunk-TWRYSGAW.js.map +1 -0
- package/dist/{chunk-LPRVHM7P.js → chunk-U5S527PP.js} +1655 -114
- package/dist/chunk-U5S527PP.js.map +1 -0
- package/dist/chunk-UHTVXQ2O.js +140 -0
- package/dist/chunk-UHTVXQ2O.js.map +1 -0
- package/dist/chunk-UOJRKQTZ.js +213 -0
- package/dist/chunk-UOJRKQTZ.js.map +1 -0
- package/dist/chunk-V4WWTZHZ.js +233 -0
- package/dist/chunk-V4WWTZHZ.js.map +1 -0
- package/dist/chunk-VRRLTZ2Q.js +651 -0
- package/dist/chunk-VRRLTZ2Q.js.map +1 -0
- package/dist/{chunk-Q53IYV2G.js → chunk-W6R3HAAG.js} +20 -17
- package/dist/{chunk-Q53IYV2G.js.map → chunk-W6R3HAAG.js.map} +1 -1
- package/dist/chunk-X3OOVSPX.js +154 -0
- package/dist/chunk-X3OOVSPX.js.map +1 -0
- package/dist/chunk-XJN5WUKL.js +204 -0
- package/dist/chunk-XJN5WUKL.js.map +1 -0
- package/dist/{chunk-DXPYFVKG.js → chunk-Y7ERTA7D.js} +35 -15
- package/dist/chunk-Y7ERTA7D.js.map +1 -0
- package/dist/chunk-YLYINX2H.js +7806 -0
- package/dist/chunk-YLYINX2H.js.map +1 -0
- package/dist/chunk-ZQIQ55KK.js +51 -0
- package/dist/chunk-ZQIQ55KK.js.map +1 -0
- package/dist/chunk-ZUAQRIVP.js +1369 -0
- package/dist/chunk-ZUAQRIVP.js.map +1 -0
- package/dist/{chunk-3IMLRUZE.js → chunk-ZXTAQYNA.js} +6 -2
- package/dist/chunk-ZXTAQYNA.js.map +1 -0
- package/dist/{cli-WA65NP4Y.js → cli-HK2XAWNW.js} +440 -175
- package/dist/cli-HK2XAWNW.js.map +1 -0
- package/dist/config-LYCHHNAJ.js +26 -0
- package/dist/config-LYCHHNAJ.js.map +1 -0
- package/dist/dist-U4M6QCKE.js +2842 -0
- package/dist/dist-U4M6QCKE.js.map +1 -0
- package/dist/doctor-2KPUQURC.js +27 -0
- package/dist/doctor-2KPUQURC.js.map +1 -0
- package/dist/edit-TST3OCKQ.js +38 -0
- package/dist/edit-TST3OCKQ.js.map +1 -0
- package/dist/ethersCompat-Df4a6QIZ-WHYKB6HA.js +18 -0
- package/dist/ethersCompat-Df4a6QIZ-WHYKB6HA.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/inspect-TPTHVPBB.js +35 -0
- package/dist/inspect-TPTHVPBB.js.map +1 -0
- package/dist/install-PT3XEDJ6.js +1869 -0
- package/dist/install-PT3XEDJ6.js.map +1 -0
- package/dist/{mine.wasm-GQECMSGN.js → mine.wasm-6PIT3DK6.js} +2 -2
- package/dist/outcome-NPNSF2Q7.js +22 -0
- package/dist/outcome-NPNSF2Q7.js.map +1 -0
- package/dist/publish-XP5SEWST.js +41 -0
- package/dist/publish-XP5SEWST.js.map +1 -0
- package/dist/read-D4VXRWOG.js +158 -0
- package/dist/read-D4VXRWOG.js.map +1 -0
- package/dist/run-3IPGEXW7.js +16902 -0
- package/dist/run-3IPGEXW7.js.map +1 -0
- package/dist/search-YOBD6VDI.js +24 -0
- package/dist/search-YOBD6VDI.js.map +1 -0
- package/dist/{secp256k1-BEZS642W.js → secp256k1-XRPVBC6V.js} +5 -4
- package/dist/secp256k1-XRPVBC6V.js.map +1 -0
- package/dist/send-BWNP6WN4.js +223 -0
- package/dist/send-BWNP6WN4.js.map +1 -0
- package/dist/session-GZEZBOMI.js +88 -0
- package/dist/session-GZEZBOMI.js.map +1 -0
- package/dist/skill-heal-OK6YALW6.js +85 -0
- package/dist/skill-heal-OK6YALW6.js.map +1 -0
- package/dist/usdc-4VCDHFWX.js +38 -0
- package/dist/usdc-4VCDHFWX.js.map +1 -0
- package/dist/viemAdapter-By13KInL-TUQJBMHM.js +14 -0
- package/dist/viemAdapter-By13KInL-TUQJBMHM.js.map +1 -0
- package/dist/wallet-5RHDFPN2.js +32 -0
- package/dist/wallet-5RHDFPN2.js.map +1 -0
- package/dist/wallet-YEGQBWWL.js +42 -0
- package/dist/wallet-YEGQBWWL.js.map +1 -0
- package/docs/agent-permissions.md +281 -0
- package/package.json +25 -18
- package/skills/tenjin/SKILL.md +364 -0
- package/skills/tenjin-publish/SKILL.md +219 -0
- package/skills/tenjin-search/SKILL.md +335 -0
- package/dist/chunk-BRJHUQSY.js.map +0 -1
- package/dist/chunk-CUWUHTIL.js.map +0 -1
- package/dist/chunk-DXPYFVKG.js.map +0 -1
- package/dist/chunk-EXBMF5X7.js.map +0 -1
- package/dist/chunk-EZROUI5U.js +0 -135
- package/dist/chunk-EZROUI5U.js.map +0 -1
- package/dist/chunk-IPOWB3G3.js.map +0 -1
- package/dist/chunk-LPRVHM7P.js.map +0 -1
- package/dist/chunk-T4LKNY7T.js.map +0 -1
- package/dist/chunk-YBMMV4Y4.js +0 -51
- package/dist/chunk-YBMMV4Y4.js.map +0 -1
- package/dist/chunk-YG2DO46P.js.map +0 -1
- package/dist/chunk-ZPZFPVDN.js +0 -67
- package/dist/chunk-ZPZFPVDN.js.map +0 -1
- package/dist/cli-WA65NP4Y.js.map +0 -1
- package/dist/config-CEFTL5ZL.js +0 -164
- package/dist/config-CEFTL5ZL.js.map +0 -1
- package/dist/doctor-3QBYN46N.js +0 -338
- package/dist/doctor-3QBYN46N.js.map +0 -1
- package/dist/usdc-44R6XZF2.js +0 -18
- package/dist/wallet-ELBTBMXO.js +0 -20
- package/dist/wallet-XD576HF3.js +0 -173
- package/dist/wallet-XD576HF3.js.map +0 -1
- /package/dist/{_esm-ZH2J4QEH.js.map → _esm-C5CRWCYU.js.map} +0 -0
- /package/dist/{ccip-UCLT5VOW.js.map → _esm-N4KAVXQR.js.map} +0 -0
- /package/dist/{chunk-3IMLRUZE.js.map → buy-FMDBZ4NY.js.map} +0 -0
- /package/dist/{secp256k1-BEZS642W.js.map → candidate-7LAELUQD.js.map} +0 -0
- /package/dist/{usdc-44R6XZF2.js.map → ccip-RPPPKTJR.js.map} +0 -0
- /package/dist/{wallet-ELBTBMXO.js.map → ccip-ZGGWQN4X.js.map} +0 -0
- /package/dist/{mine.wasm-GQECMSGN.js.map → mine.wasm-6PIT3DK6.js.map} +0 -0
|
@@ -0,0 +1,1369 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
SESSION_CHAIN_ID,
|
|
4
|
+
createSessionKeyAuth,
|
|
5
|
+
createSiwxAuth
|
|
6
|
+
} from "./chunk-POF7HPRV.js";
|
|
7
|
+
import {
|
|
8
|
+
rateLimitError
|
|
9
|
+
} from "./chunk-O6CAUZGY.js";
|
|
10
|
+
import {
|
|
11
|
+
httpRequest
|
|
12
|
+
} from "./chunk-DKQMJTG7.js";
|
|
13
|
+
import {
|
|
14
|
+
trimSlash
|
|
15
|
+
} from "./chunk-PZSUWDF2.js";
|
|
16
|
+
import {
|
|
17
|
+
ATOMIC_RE,
|
|
18
|
+
PublishModeSchema,
|
|
19
|
+
UUID_RE
|
|
20
|
+
} from "./chunk-36X2CA3N.js";
|
|
21
|
+
import {
|
|
22
|
+
CliError,
|
|
23
|
+
external_exports
|
|
24
|
+
} from "./chunk-PZRAAAY2.js";
|
|
25
|
+
|
|
26
|
+
// src/lib/scan.ts
|
|
27
|
+
var LONG_QUOTE_WORDS = 80;
|
|
28
|
+
function scan(text, context = {}) {
|
|
29
|
+
const lines = text.split("\n");
|
|
30
|
+
const findings = [
|
|
31
|
+
...scanHex64(lines),
|
|
32
|
+
...scanLineDetectors(lines),
|
|
33
|
+
...scanPemBlocks(lines),
|
|
34
|
+
...scanLongVerbatim(lines),
|
|
35
|
+
...scanProjectMarkers(lines, context.projectMarkers ?? [])
|
|
36
|
+
];
|
|
37
|
+
return dedupeAndSort(suppressEmailsInDbUris(findings));
|
|
38
|
+
}
|
|
39
|
+
function scanProjectMarkers(lines, markers) {
|
|
40
|
+
const cleaned = [...new Set(markers.filter((m) => m.trim().length >= 3))];
|
|
41
|
+
if (cleaned.length === 0) return [];
|
|
42
|
+
const needles = cleaned.map((marker) => ({
|
|
43
|
+
marker,
|
|
44
|
+
re: new RegExp(`(?<![A-Za-z0-9._-])${escapeRegExp(marker)}(?![A-Za-z0-9_-])`, "gi")
|
|
45
|
+
}));
|
|
46
|
+
const out = [];
|
|
47
|
+
for (let i = 0; i < lines.length; i++) {
|
|
48
|
+
const line = lines[i] ?? "";
|
|
49
|
+
for (const { marker, re } of needles) {
|
|
50
|
+
re.lastIndex = 0;
|
|
51
|
+
let m;
|
|
52
|
+
while ((m = re.exec(line)) !== null) {
|
|
53
|
+
out.push({
|
|
54
|
+
check: "private-repo-reference",
|
|
55
|
+
severity: "warn",
|
|
56
|
+
line: i + 1,
|
|
57
|
+
span: [m.index, m.index + m[0].length],
|
|
58
|
+
excerpt: marker
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
function escapeRegExp(s) {
|
|
66
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
67
|
+
}
|
|
68
|
+
var PLACEHOLDER_USERNAME = /^(?:user(?:name)?|you(?:rname)?|example|foo|me|myuser|somebody)$/i;
|
|
69
|
+
function suppressEmailsInDbUris(findings) {
|
|
70
|
+
const uris = findings.filter((f) => f.check === "db-connection-uri");
|
|
71
|
+
if (uris.length === 0) return findings;
|
|
72
|
+
return findings.filter(
|
|
73
|
+
(f) => f.check !== "email" || !uris.some((u) => u.line === f.line && f.span[0] >= u.span[0] && f.span[1] <= u.span[1])
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
function maskKeeping(match, prefixLen) {
|
|
77
|
+
const prefix = match.slice(0, Math.min(prefixLen, match.length));
|
|
78
|
+
return `${prefix}\u2026[redacted ${match.length - prefix.length} chars]`;
|
|
79
|
+
}
|
|
80
|
+
var LINE_DETECTORS = [
|
|
81
|
+
// Secrets/keys — severity block, excerpt always masked. Provider patterns
|
|
82
|
+
// adapted from gitleaks (MIT). The 0x-64-hex EVM key is handled separately
|
|
83
|
+
// (scanHex64) so a tx/block hash is not hard-blocked. See header + NOTICE.md.
|
|
84
|
+
{
|
|
85
|
+
check: "aws-access-key",
|
|
86
|
+
severity: "block",
|
|
87
|
+
// gitleaks aws-access-token.
|
|
88
|
+
re: /\b(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[0-9A-Z]{16}\b/g,
|
|
89
|
+
excerpt: (m) => maskKeeping(m[0], 4)
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
check: "jwt",
|
|
93
|
+
severity: "block",
|
|
94
|
+
// gitleaks jwt (three base64url segments, header starts eyJ).
|
|
95
|
+
re: /\beyJ[A-Za-z0-9_-]{5,}\.eyJ[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\b/g,
|
|
96
|
+
excerpt: (m) => maskKeeping(m[0], 3)
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
check: "github-token",
|
|
100
|
+
severity: "block",
|
|
101
|
+
// gitleaks github-pat / -oauth / -app / -refresh (36 chars) + fine-grained pat.
|
|
102
|
+
re: /\b(?:gh[posru]_[0-9A-Za-z]{36}|github_pat_[0-9A-Za-z_]{82})\b/g,
|
|
103
|
+
excerpt: (m) => maskKeeping(m[0], 4)
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
check: "slack-token",
|
|
107
|
+
severity: "block",
|
|
108
|
+
// gitleaks slack tokens (bot/user/app/refresh/legacy prefixes).
|
|
109
|
+
re: /\bxox[baprs]-[0-9A-Za-z-]{10,}\b/g,
|
|
110
|
+
excerpt: (m) => maskKeeping(m[0], 5)
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
check: "stripe-token",
|
|
114
|
+
severity: "block",
|
|
115
|
+
// gitleaks stripe-access-token.
|
|
116
|
+
re: /\b[sr]k_(?:live|test)_[0-9A-Za-z]{10,99}\b/g,
|
|
117
|
+
excerpt: (m) => maskKeeping(m[0], 8)
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
check: "anthropic-key",
|
|
121
|
+
severity: "block",
|
|
122
|
+
// gitleaks anthropic-api-key. Ordered before openai so sk-ant- isn't
|
|
123
|
+
// mis-typed as a bare OpenAI sk- key.
|
|
124
|
+
re: /\bsk-ant-[0-9A-Za-z_-]{20,}\b/g,
|
|
125
|
+
excerpt: (m) => maskKeeping(m[0], 7)
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
check: "openai-key",
|
|
129
|
+
severity: "block",
|
|
130
|
+
// gitleaks openai-api-key: classic sk- plus the modern sk-proj-/sk-svcacct-/
|
|
131
|
+
// sk-admin- keys. The body is base62 and MUST contain a digit (real keys are
|
|
132
|
+
// high-entropy), which keeps sk- kebab identifiers (sk-user-profile-updated…)
|
|
133
|
+
// from hard-blocking. `(?!ant-)` keeps an Anthropic key out. Only the base62
|
|
134
|
+
// leading run of a modern key is matched — enough to flag it. The run is
|
|
135
|
+
// terminated by a non-base62 lookahead (not \b, which a trailing `_` — a word
|
|
136
|
+
// char — would not fire), so an underscore-adjacent key still matches.
|
|
137
|
+
// Assumption + chosen tradeoff: a real key opens with a >=20-char base62 run,
|
|
138
|
+
// so the {20,} floor is what separates a key from a kebab identifier. A key
|
|
139
|
+
// whose FIRST segment is shorter than 20 (e.g. `sk-proj-abc123_` then more,
|
|
140
|
+
// broken up by underscores) slips past this BARE-PASTE detector; that is
|
|
141
|
+
// accepted, because such a value in an assignment still warns via
|
|
142
|
+
// secret-assignment — the bare-paste path is the only gap.
|
|
143
|
+
re: /\bsk-(?!ant-)(?:proj-|svcacct-|admin-)?(?=[0-9A-Za-z]*[0-9])[0-9A-Za-z]{20,}(?![0-9A-Za-z])/g,
|
|
144
|
+
excerpt: (m) => maskKeeping(m[0], 3)
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
check: "google-key",
|
|
148
|
+
severity: "block",
|
|
149
|
+
// gitleaks gcp-api-key (AIza) and gcp-oauth-client-secret (GOCSPX-).
|
|
150
|
+
re: /\b(?:AIza[0-9A-Za-z_-]{35}|GOCSPX-[0-9A-Za-z_-]{20,})\b/g,
|
|
151
|
+
excerpt: (m) => maskKeeping(m[0], m[0].startsWith("AIza") ? 4 : 7)
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
check: "npm-token",
|
|
155
|
+
severity: "block",
|
|
156
|
+
// gitleaks npm-access-token.
|
|
157
|
+
re: /\bnpm_[0-9A-Za-z]{36}\b/g,
|
|
158
|
+
excerpt: (m) => maskKeeping(m[0], 4)
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
check: "db-connection-uri",
|
|
162
|
+
severity: "block",
|
|
163
|
+
// A connection string with an embedded password (scheme://user:pass@host).
|
|
164
|
+
// Only the password (group 3) is secret; the excerpt masks it and keeps the
|
|
165
|
+
// rest so the finding is legible. Placeholder-gated like the other high-
|
|
166
|
+
// confidence shapes so a docs example (postgres://postgres:postgres@…,
|
|
167
|
+
// ://user:<password>@…) doesn't hard-block; a real password still blocks.
|
|
168
|
+
re: /\b([a-z][a-z0-9+.-]*):\/\/([^\s:@/]+):([^\s@/]+)@([^\s/:]+)/gi,
|
|
169
|
+
excerpt: (m) => `${m[1]}://${m[2]}:[redacted]@${m[4]}`,
|
|
170
|
+
skip: (m) => isPlaceholder(m[3] ?? "") || isExamplePassword(m[3] ?? "")
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
check: "bearer-token",
|
|
174
|
+
severity: "block",
|
|
175
|
+
// An Authorization: Bearer header carrying a live token; placeholder-gated
|
|
176
|
+
// like secret-assignment so `Bearer <token>` examples don't hard-block.
|
|
177
|
+
re: /\bAuthorization:\s*Bearer\s+(\S{8,})/gi,
|
|
178
|
+
excerpt: (m) => `Authorization: Bearer [redacted ${m[1]?.length ?? 0} chars]`,
|
|
179
|
+
skip: (m) => isPlaceholder(m[1] ?? "")
|
|
180
|
+
},
|
|
181
|
+
// Generic secret-named assignment — WARN, not block (review): a keyword match is
|
|
182
|
+
// lower-confidence than a structured shape, and a warn still forces confirmation
|
|
183
|
+
// under `review` and `auto`, while benign config (SECRET_NAME=…,
|
|
184
|
+
// MYSQL_ROOT_PASSWORD=…) is not permanently non-bypassable. `full-auto` and a bare
|
|
185
|
+
// `--yes` DO clear it unseen, which is the price of that choice; the publish skill
|
|
186
|
+
// says so rather than implying keys and tokens are all in the blocking tier. The
|
|
187
|
+
// excerpt stays masked. Placeholder and structural (path/URL/regex) values are
|
|
188
|
+
// skipped entirely.
|
|
189
|
+
{
|
|
190
|
+
check: "secret-assignment",
|
|
191
|
+
severity: "warn",
|
|
192
|
+
// Key: api[_-]?key, secret, access/private key, passw(or)?d, token,
|
|
193
|
+
// credential(s), auth token — camelCase-insensitive. Value: a quoted string
|
|
194
|
+
// (interior spaces allowed) or an unquoted run, ≥6 chars. Value is masked.
|
|
195
|
+
re: /\b([A-Za-z0-9_]*(?:API[_-]?KEY|SECRET|ACCESS[_-]?KEY|PRIVATE[_-]?KEY|PASSW(?:OR)?D|TOKEN|CREDENTIALS?|AUTH[_-]?TOKEN)[A-Za-z0-9_]*)\s*[:=]\s*("[^"]{6,}"|'[^']{6,}'|[^\s"']{6,})/gi,
|
|
196
|
+
excerpt: (m) => `${m[1]}=[redacted ${dequote(m[2] ?? "").length} chars]`,
|
|
197
|
+
skip: skipNonLiteralValue
|
|
198
|
+
},
|
|
199
|
+
// Wallet addresses — warn (a contract address may be intentional). Not a secret,
|
|
200
|
+
// shown abbreviated. viem's checksum validation is deliberately NOT used to gate
|
|
201
|
+
// this: EIP-55 strict validation rejects the valid all-lowercase/all-uppercase
|
|
202
|
+
// forms, which a scanner must still surface, so shape matching is the right test.
|
|
203
|
+
{
|
|
204
|
+
check: "wallet-address",
|
|
205
|
+
severity: "warn",
|
|
206
|
+
re: /(?<![0-9a-fx])0x[0-9a-fA-F]{40}(?![0-9a-fA-F])/gi,
|
|
207
|
+
excerpt: (m) => `${m[0].slice(0, 6)}\u2026${m[0].slice(-4)}`
|
|
208
|
+
},
|
|
209
|
+
// Employer-internal markers — warn. Marker-SHAPED, not word-in-phrase (#36):
|
|
210
|
+
// the detector targets the classification legend a document stamp carries
|
|
211
|
+
// (CONFIDENTIAL, CONFIDENTIAL DRAFT/INFORMATION, STRICTLY/COMPANY
|
|
212
|
+
// CONFIDENTIAL, "Acme Inc. Confidential", INTERNAL (USE) ONLY, DO NOT
|
|
213
|
+
// DISTRIBUTE), so it is case-SENSITIVE — prose about "confidential computing"
|
|
214
|
+
// never fires. The phrase-vs-legend split is positional, not a blanket
|
|
215
|
+
// next-word lookahead (review r5: the old lookahead lost CONFIDENTIAL
|
|
216
|
+
// INFORMATION and every title-case legend):
|
|
217
|
+
// - all-caps CONFIDENTIAL is suppressed only when all-caps words flank it on
|
|
218
|
+
// BOTH sides — that is what a mid-phrase mention in a shouting heading
|
|
219
|
+
// looks like (A SURVEY OF CONFIDENTIAL COMPUTING …). A legend either leads
|
|
220
|
+
// its line (CONFIDENTIAL DRAFT) or ends it (ACME CONFIDENTIAL, HIGHLY
|
|
221
|
+
// CONFIDENTIAL, PROPRIETARY AND CONFIDENTIAL), so one-sided caps still
|
|
222
|
+
// fire (review r6: the caps-prefixed company stamp is the most common real
|
|
223
|
+
// legend form, and the old left-only rule missed the whole family).
|
|
224
|
+
// Accepted FP: a caps heading that LEADS with the topic word
|
|
225
|
+
// (# CONFIDENTIAL COMPUTING ON AWS) warns — fail-safe direction. Accepted
|
|
226
|
+
// FN: a caps-flanked legend without a whitelisted prefix (ACME
|
|
227
|
+
// CONFIDENTIAL INFORMATION) is indistinguishable from a shouting-heading
|
|
228
|
+
// phrase and misses; STRICTLY/COMPANY/HIGHLY prefixes are legend-only
|
|
229
|
+
// vocabulary and are whitelisted through.
|
|
230
|
+
// - Title-case Confidential fires only before punctuation or end-of-line
|
|
231
|
+
// ("Acme Inc. Confidential", "## Confidential: …"), never mid-title
|
|
232
|
+
// ("Confidential Computing: a TEE survey").
|
|
233
|
+
{
|
|
234
|
+
check: "confidential-marker",
|
|
235
|
+
severity: "warn",
|
|
236
|
+
re: /\b(?:STRICTLY|COMPANY|HIGHLY)\s+CONFIDENTIAL\b|(?<![A-Z]{2,}[ \t]+)\bCONFIDENTIAL\b|\bCONFIDENTIAL\b(?![ \t]+[A-Z]{2,})|\bConfidential(?=\s*(?:[-:.,;–—]|$))|\b(?:INTERNAL|Internal)(?:\s+(?:USE|Use))?\s+(?:ONLY|Only)\b|\b(?:DO\s+NOT\s+DISTRIBUTE|Do\s+Not\s+Distribute)\b/g,
|
|
237
|
+
excerpt: (m) => m[0]
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
check: "internal-hostname",
|
|
241
|
+
severity: "warn",
|
|
242
|
+
re: /\b(?:[a-z0-9-]+\.)+(?:internal|corp|local|lan|intranet)\b/gi,
|
|
243
|
+
excerpt: (m) => m[0]
|
|
244
|
+
},
|
|
245
|
+
// Home-anchored local filesystem paths — warn (open-questions publishing-safety:
|
|
246
|
+
// private paths). A /Users/<name>/… or /home/<name>/… or C:\Users\<name>\…
|
|
247
|
+
// path leaks the machine username and private project layout. The username
|
|
248
|
+
// segment is masked in the excerpt; obvious placeholder usernames
|
|
249
|
+
// (/home/user/…, /Users/username/…) are docs examples and skip. `~/…` paths
|
|
250
|
+
// deliberately do NOT fire: they are already generalized. The unix branch
|
|
251
|
+
// requires a non-name left boundary so a web-URL path segment
|
|
252
|
+
// (docs.example.com/home/…) is not a local path, and the segment class
|
|
253
|
+
// excludes `?`/`&` so a query string (…?api_key=…) is never swallowed into a
|
|
254
|
+
// verbatim excerpt a sibling detector would have masked (review r5). Windows
|
|
255
|
+
// matches [Uu]sers: the filesystem is case-insensitive.
|
|
256
|
+
{
|
|
257
|
+
check: "local-path",
|
|
258
|
+
severity: "warn",
|
|
259
|
+
re: /(?:(?<![\w.-])\/(?:Users|home)\/([A-Za-z0-9._-]+)(?:\/[^\s"'`)\]}>:,;?&]+)+|\b[A-Za-z]:\\[Uu]sers\\([^\\\s"']+)(?:\\[^\\\s"']+)+)/dg,
|
|
260
|
+
excerpt: (m) => {
|
|
261
|
+
const bounds = m.indices?.[1] ?? m.indices?.[2];
|
|
262
|
+
const masked = bounds === void 0 ? m[0] : `${m[0].slice(0, bounds[0] - m.index)}[user]${m[0].slice(bounds[1] - m.index)}`;
|
|
263
|
+
return masked.length > 60 ? `${masked.slice(0, 57)}\u2026` : masked;
|
|
264
|
+
},
|
|
265
|
+
skip: (m) => PLACEHOLDER_USERNAME.test(m[1] ?? m[2] ?? "")
|
|
266
|
+
},
|
|
267
|
+
// Labeled customer/account identifiers — warn (open-questions publishing-safety:
|
|
268
|
+
// customer identifiers). Fires only on the explicit label + separator + value
|
|
269
|
+
// shape (customer_id: 84213, Account Number: ACME-0042); the value is masked
|
|
270
|
+
// like a secret-assignment value since a customer identifier is third-party
|
|
271
|
+
// data. Chosen tradeoff: an unlabeled identifier (bare CUST-4812) is a false
|
|
272
|
+
// negative — an unlabeled token is indistinguishable from a SKU or version tag.
|
|
273
|
+
{
|
|
274
|
+
check: "customer-identifier",
|
|
275
|
+
severity: "warn",
|
|
276
|
+
re: /\b((?:customer|client|account|tenant|subscriber)[ _-]?(?:id|number|no))\b\s*[:=#]\s*("[^"]{2,}"|'[^']{2,}'|[A-Za-z0-9][A-Za-z0-9._-]{2,})/gi,
|
|
277
|
+
excerpt: (m) => `${m[1]}=[redacted ${dequote(m[2] ?? "").length} chars]`,
|
|
278
|
+
skip: skipNonLiteralValue
|
|
279
|
+
},
|
|
280
|
+
// Third-party paid/licensed-content markers — warn (open-questions
|
|
281
|
+
// publishing-safety: third-party copyrighted inputs). A rights LEGEND in the
|
|
282
|
+
// draft suggests copied licensed material; ambiguity-class (the author may
|
|
283
|
+
// hold the rights), so warn, never block. Legend shapes only — bare paywall
|
|
284
|
+
// vocabulary (paywalled, premium content, subscriber-only, behind a paywall)
|
|
285
|
+
// deliberately does NOT fire: it is this marketplace's own subject matter and
|
|
286
|
+
// measured 100% false-positive on the dogfood corpus (review r5), the exact
|
|
287
|
+
// word-in-phrase failure #36 is about.
|
|
288
|
+
{
|
|
289
|
+
check: "paid-content-marker",
|
|
290
|
+
severity: "warn",
|
|
291
|
+
re: /\ball rights reserved\b|\b(?:reprinted|reproduced|used) with permission\b|\bnot for (?:redistribution|republication)\b|\bdo not (?:redistribute|republish)\b|(?:©|\(c\)|copyright)\s*(?:19|20)\d{2}\b/gi,
|
|
292
|
+
excerpt: (m) => m[0]
|
|
293
|
+
},
|
|
294
|
+
// Embedded prompt/tool-output instruction patterns — warn (open-questions
|
|
295
|
+
// publishing-safety: embedded instructions). Source material captured from
|
|
296
|
+
// prompts or tool output can carry injection-shaped imperatives that would
|
|
297
|
+
// ship to every future buyer. High-precision imperative shapes only: a bare
|
|
298
|
+
// "system prompt" mention, chat-template delimiters (<system>, [INST]), and
|
|
299
|
+
// persona phrases ("you are an assistant", "as an AI") deliberately do NOT
|
|
300
|
+
// fire — legitimate agent-engineering exposition quotes all of them
|
|
301
|
+
// constantly (review r5), and only the imperative shapes are injection-typed.
|
|
302
|
+
// Two entries under one check name: the imperative shapes are case-INsensitive
|
|
303
|
+
// (adversarial text uses any case), while BEGIN SYSTEM/HIDDEN PROMPT is
|
|
304
|
+
// case-SENSITIVE — its signal is that it reads as a document header, and
|
|
305
|
+
// lowercase "begin system prompt" is ordinary prose on this marketplace's own
|
|
306
|
+
// subject matter (greptile r7), the #36 word-in-phrase class again.
|
|
307
|
+
{
|
|
308
|
+
check: "embedded-instruction",
|
|
309
|
+
severity: "warn",
|
|
310
|
+
re: /\b(?:ignore|disregard|forget)\s+(?:all\s+|any\s+)?(?:previous|prior|above|earlier|preceding)\s+(?:instructions?|prompts?|context|messages?)\b|\bdo not (?:reveal|disclose|mention) (?:this|these|the above)\b/gi,
|
|
311
|
+
excerpt: (m) => m[0]
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
check: "embedded-instruction",
|
|
315
|
+
severity: "warn",
|
|
316
|
+
re: /\bBEGIN (?:SYSTEM|HIDDEN) (?:PROMPT|INSTRUCTIONS)\b/g,
|
|
317
|
+
excerpt: (m) => m[0]
|
|
318
|
+
},
|
|
319
|
+
// Personal data — warn. `email` subsumes corp-domain emails (an internal marker).
|
|
320
|
+
{
|
|
321
|
+
check: "email",
|
|
322
|
+
severity: "warn",
|
|
323
|
+
re: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g,
|
|
324
|
+
excerpt: (m) => m[0]
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
check: "phone",
|
|
328
|
+
severity: "warn",
|
|
329
|
+
re: /(?<!\d)(?:\+?\d{1,2}[\s.-]?)?(?:\(\d{3}\)|\d{3})[\s.-]\d{3}[\s.-]\d{4}(?!\d)/g,
|
|
330
|
+
excerpt: (m) => m[0]
|
|
331
|
+
}
|
|
332
|
+
];
|
|
333
|
+
function scanLineDetectors(lines) {
|
|
334
|
+
const out = [];
|
|
335
|
+
for (let i = 0; i < lines.length; i++) {
|
|
336
|
+
const line = lines[i] ?? "";
|
|
337
|
+
for (const detector of LINE_DETECTORS) {
|
|
338
|
+
detector.re.lastIndex = 0;
|
|
339
|
+
let m;
|
|
340
|
+
while ((m = detector.re.exec(line)) !== null) {
|
|
341
|
+
if (!detector.skip?.(m)) {
|
|
342
|
+
out.push({
|
|
343
|
+
check: detector.check,
|
|
344
|
+
severity: detector.severity,
|
|
345
|
+
line: i + 1,
|
|
346
|
+
span: [m.index, m.index + m[0].length],
|
|
347
|
+
excerpt: detector.excerpt(m)
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return out;
|
|
354
|
+
}
|
|
355
|
+
function skipNonLiteralValue(m) {
|
|
356
|
+
const raw = m[2] ?? "";
|
|
357
|
+
const value = dequote(raw);
|
|
358
|
+
if (isPlaceholder(value) || isStructural(value)) return true;
|
|
359
|
+
return raw === value && isCodeExpression(value);
|
|
360
|
+
}
|
|
361
|
+
function dequote(value) {
|
|
362
|
+
const m = /^"([^"]*)"$|^'([^']*)'$/.exec(value);
|
|
363
|
+
return m !== null ? m[1] ?? m[2] ?? "" : value;
|
|
364
|
+
}
|
|
365
|
+
var PLACEHOLDER_WORD = /^(?:xxx+|example|example-value|placeholder|redacted|changeme|dummy|sample|todo|tbd|none|null|secret|test|\*+|\.{3,})$/i;
|
|
366
|
+
var PLACEHOLDER_PREFIX = /^(?:your|my)[-_][a-z]+(?:[-_][a-z]+)*$/i;
|
|
367
|
+
function isPlaceholder(value) {
|
|
368
|
+
if (/^[<${%]/.test(value)) return true;
|
|
369
|
+
return PLACEHOLDER_WORD.test(value) || PLACEHOLDER_PREFIX.test(value);
|
|
370
|
+
}
|
|
371
|
+
function isCodeExpression(value) {
|
|
372
|
+
const v = value.replace(/[,;]+$/, "");
|
|
373
|
+
if (/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/.test(v)) return true;
|
|
374
|
+
if (/^[A-Za-z_$][\w$.]*\([^)]*\)$/.test(v)) return true;
|
|
375
|
+
if (/\($/.test(v)) return true;
|
|
376
|
+
return /^[a-z_$][a-z_$]*$/.test(v);
|
|
377
|
+
}
|
|
378
|
+
function isStructural(value) {
|
|
379
|
+
return /^(?:\.?\.?\/|~\/|https?:\/\/|\^)/.test(value);
|
|
380
|
+
}
|
|
381
|
+
var EXAMPLE_PASSWORDS = /* @__PURE__ */ new Set([
|
|
382
|
+
"password",
|
|
383
|
+
"postgres",
|
|
384
|
+
"mysql",
|
|
385
|
+
"root",
|
|
386
|
+
"admin",
|
|
387
|
+
"changeme",
|
|
388
|
+
"example",
|
|
389
|
+
"secret",
|
|
390
|
+
"test",
|
|
391
|
+
"guest",
|
|
392
|
+
"toor"
|
|
393
|
+
]);
|
|
394
|
+
function isExamplePassword(password) {
|
|
395
|
+
return EXAMPLE_PASSWORDS.has(password.toLowerCase());
|
|
396
|
+
}
|
|
397
|
+
var HEX64_RE = /(?<![0-9a-fx])0x[0-9a-fA-F]{64}(?![0-9a-fA-F])/gi;
|
|
398
|
+
var HASH_LABEL_RE = /(?:^|[^a-z0-9])(?:blockhash|txhash|txn|tx|hash)[\s/:=]*$/i;
|
|
399
|
+
function scanHex64(lines) {
|
|
400
|
+
const out = [];
|
|
401
|
+
for (let i = 0; i < lines.length; i++) {
|
|
402
|
+
const line = lines[i] ?? "";
|
|
403
|
+
HEX64_RE.lastIndex = 0;
|
|
404
|
+
let m;
|
|
405
|
+
while ((m = HEX64_RE.exec(line)) !== null) {
|
|
406
|
+
const hash = isHashContext(line, m.index);
|
|
407
|
+
out.push({
|
|
408
|
+
check: hash ? "hex32-value" : "raw-private-key",
|
|
409
|
+
severity: hash ? "warn" : "block",
|
|
410
|
+
line: i + 1,
|
|
411
|
+
span: [m.index, m.index + m[0].length],
|
|
412
|
+
excerpt: hash ? `${m[0].slice(0, 6)}\u2026${m[0].slice(-4)}` : maskKeeping(m[0], 2)
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return out;
|
|
417
|
+
}
|
|
418
|
+
function isHashContext(line, matchIndex) {
|
|
419
|
+
const before = line.slice(0, matchIndex);
|
|
420
|
+
if (HASH_LABEL_RE.test(before)) return true;
|
|
421
|
+
const prefix = /(\S*)$/.exec(before)?.[1] ?? "";
|
|
422
|
+
return /^https?:\/\//.test(line.slice(matchIndex - prefix.length));
|
|
423
|
+
}
|
|
424
|
+
var PEM_BEGIN = /-----BEGIN[ A-Z0-9]*PRIVATE KEY(?: BLOCK)?-----/;
|
|
425
|
+
function scanPemBlocks(lines) {
|
|
426
|
+
const out = [];
|
|
427
|
+
for (let i = 0; i < lines.length; i++) {
|
|
428
|
+
const line = lines[i] ?? "";
|
|
429
|
+
const m = PEM_BEGIN.exec(line);
|
|
430
|
+
if (m !== null) {
|
|
431
|
+
out.push({
|
|
432
|
+
check: "pem-private-key",
|
|
433
|
+
severity: "block",
|
|
434
|
+
line: i + 1,
|
|
435
|
+
span: [m.index, m.index + m[0].length],
|
|
436
|
+
excerpt: m[0]
|
|
437
|
+
// the header marker only — no key material follows on it
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return out;
|
|
442
|
+
}
|
|
443
|
+
var FENCE = /^(\s*)(`{3,}|~{3,})/;
|
|
444
|
+
function scanLongVerbatim(lines) {
|
|
445
|
+
const out = [];
|
|
446
|
+
let i = 0;
|
|
447
|
+
while (i < lines.length) {
|
|
448
|
+
const line = lines[i] ?? "";
|
|
449
|
+
const fence = FENCE.exec(line);
|
|
450
|
+
if (fence !== null) {
|
|
451
|
+
const marker = fence[2] ?? "```";
|
|
452
|
+
const start = i;
|
|
453
|
+
const body = [];
|
|
454
|
+
i++;
|
|
455
|
+
while (i < lines.length && !closesFence(lines[i] ?? "", marker)) {
|
|
456
|
+
body.push(lines[i] ?? "");
|
|
457
|
+
i++;
|
|
458
|
+
}
|
|
459
|
+
i++;
|
|
460
|
+
pushIfLong(out, body, start, line);
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
if (/^\s*>/.test(line)) {
|
|
464
|
+
const start = i;
|
|
465
|
+
const body = [];
|
|
466
|
+
while (i < lines.length && /^\s*>/.test(lines[i] ?? "")) {
|
|
467
|
+
body.push((lines[i] ?? "").replace(/^\s*>\s?/, ""));
|
|
468
|
+
i++;
|
|
469
|
+
}
|
|
470
|
+
pushIfLong(out, body, start, lines[start] ?? "");
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
i++;
|
|
474
|
+
}
|
|
475
|
+
return out;
|
|
476
|
+
}
|
|
477
|
+
function closesFence(line, marker) {
|
|
478
|
+
const m = FENCE.exec(line);
|
|
479
|
+
return m !== null && (m[2] ?? "").startsWith(marker);
|
|
480
|
+
}
|
|
481
|
+
function pushIfLong(out, body, startLine, firstLine) {
|
|
482
|
+
const text = body.join(" ").trim();
|
|
483
|
+
const words = text.length === 0 ? 0 : text.split(/\s+/).length;
|
|
484
|
+
if (words < LONG_QUOTE_WORDS) return;
|
|
485
|
+
const excerpt = text.length > 60 ? `${text.slice(0, 57)}\u2026` : text;
|
|
486
|
+
out.push({
|
|
487
|
+
check: "long-verbatim-quote",
|
|
488
|
+
severity: "warn",
|
|
489
|
+
line: startLine + 1,
|
|
490
|
+
span: [0, firstLine.length],
|
|
491
|
+
excerpt
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
function dedupeAndSort(findings) {
|
|
495
|
+
const seen = /* @__PURE__ */ new Set();
|
|
496
|
+
const unique = findings.filter((f) => {
|
|
497
|
+
const key = `${f.check}:${f.line}:${f.span[0]}:${f.span[1]}`;
|
|
498
|
+
if (seen.has(key)) return false;
|
|
499
|
+
seen.add(key);
|
|
500
|
+
return true;
|
|
501
|
+
});
|
|
502
|
+
return unique.sort(
|
|
503
|
+
(a, b) => a.line - b.line || a.span[0] - b.span[0] || a.check.localeCompare(b.check)
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// src/lib/scan-context.ts
|
|
508
|
+
import { readFile, stat } from "fs/promises";
|
|
509
|
+
import { dirname, isAbsolute, join, resolve } from "path";
|
|
510
|
+
async function deriveProjectMarkers(cwd) {
|
|
511
|
+
try {
|
|
512
|
+
const configPath = await findGitConfig(resolve(cwd));
|
|
513
|
+
if (configPath === void 0) return [];
|
|
514
|
+
const config = await readSmallFile(configPath);
|
|
515
|
+
return config === void 0 ? [] : extractRemoteSlugs(config);
|
|
516
|
+
} catch {
|
|
517
|
+
return [];
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
var MAX_GIT_FILE_BYTES = 1024 * 1024;
|
|
521
|
+
async function readSmallFile(path) {
|
|
522
|
+
const s = await stat(path).catch(() => void 0);
|
|
523
|
+
if (s?.isFile() !== true || s.size > MAX_GIT_FILE_BYTES) return void 0;
|
|
524
|
+
return readFile(path, "utf8").catch(() => void 0);
|
|
525
|
+
}
|
|
526
|
+
async function findGitConfig(dir) {
|
|
527
|
+
for (let current = dir; ; current = dirname(current)) {
|
|
528
|
+
const dotGit = join(current, ".git");
|
|
529
|
+
const s = await stat(dotGit).catch(() => void 0);
|
|
530
|
+
if (s?.isDirectory() === true) return join(dotGit, "config");
|
|
531
|
+
if (s?.isFile() === true) {
|
|
532
|
+
const resolved = await resolveGitFile(dotGit, current);
|
|
533
|
+
if (resolved !== void 0) return resolved;
|
|
534
|
+
}
|
|
535
|
+
if (dirname(current) === current) return void 0;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
async function resolveGitFile(dotGitFile, containingDir) {
|
|
539
|
+
const content = await readSmallFile(dotGitFile);
|
|
540
|
+
if (content === void 0) return void 0;
|
|
541
|
+
const m = /^gitdir:\s*(.+)\s*$/m.exec(content);
|
|
542
|
+
if (m?.[1] === void 0) return void 0;
|
|
543
|
+
const gitdir = isAbsolute(m[1]) ? m[1] : resolve(containingDir, m[1]);
|
|
544
|
+
const commondirFile = await readSmallFile(join(gitdir, "commondir"));
|
|
545
|
+
if (commondirFile !== void 0) {
|
|
546
|
+
const common = commondirFile.trim();
|
|
547
|
+
return join(isAbsolute(common) ? common : resolve(gitdir, common), "config");
|
|
548
|
+
}
|
|
549
|
+
return join(gitdir, "config");
|
|
550
|
+
}
|
|
551
|
+
var SECTION_LINE = /^\s*\[([^\]]*)\]/;
|
|
552
|
+
var URL_LINE = /^\s*url\s*=\s*(.+?)\s*$/i;
|
|
553
|
+
function extractRemoteSlugs(gitConfig) {
|
|
554
|
+
const slugs = /* @__PURE__ */ new Set();
|
|
555
|
+
let inRemoteSection = false;
|
|
556
|
+
for (const line of gitConfig.split("\n")) {
|
|
557
|
+
const section = SECTION_LINE.exec(line);
|
|
558
|
+
if (section !== null) {
|
|
559
|
+
inRemoteSection = /^remote\b/i.test((section[1] ?? "").trim());
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
562
|
+
if (!inRemoteSection) continue;
|
|
563
|
+
const m = URL_LINE.exec(line);
|
|
564
|
+
if (m === null) continue;
|
|
565
|
+
const value = (m[1] ?? "").split(/[#;]/, 1)[0]?.trim() ?? "";
|
|
566
|
+
const slug = slugFromRemoteUrl(value);
|
|
567
|
+
if (slug !== void 0) slugs.add(slug);
|
|
568
|
+
}
|
|
569
|
+
return [...slugs];
|
|
570
|
+
}
|
|
571
|
+
function slugFromRemoteUrl(url) {
|
|
572
|
+
let path;
|
|
573
|
+
const scheme = /^[a-z][a-z0-9+.-]*:\/\/(?:[^/@\s]+@)?[^/\s]+\/(.+)$/i.exec(url);
|
|
574
|
+
const scp = /^[^/@\s]+@[^:/\s]+:(.+)$/.exec(url);
|
|
575
|
+
if (scheme !== null) path = scheme[1];
|
|
576
|
+
else if (scp !== null) path = scp[1];
|
|
577
|
+
if (path === void 0) return void 0;
|
|
578
|
+
const slug = path.replace(/^\/+/, "").replace(/\/+$/, "").replace(/\.git$/i, "");
|
|
579
|
+
return slug.includes("/") && slug.length >= 3 ? slug : void 0;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// src/lib/card.ts
|
|
583
|
+
var FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
|
|
584
|
+
function parseFrontmatter(text) {
|
|
585
|
+
const match = FRONTMATTER_RE.exec(text);
|
|
586
|
+
if (match === null) return { frontmatter: {}, body: text };
|
|
587
|
+
const block = match[1] ?? "";
|
|
588
|
+
const body = text.slice(match[0].length);
|
|
589
|
+
return { frontmatter: parseBlock(block), body };
|
|
590
|
+
}
|
|
591
|
+
function indentOf(line) {
|
|
592
|
+
return line.length - line.trimStart().length;
|
|
593
|
+
}
|
|
594
|
+
function parseBlock(block) {
|
|
595
|
+
const lines = block.split(/\r?\n/).filter((l) => l.trim().length > 0 && !/^\s*#/.test(l));
|
|
596
|
+
const out = {};
|
|
597
|
+
let i = 0;
|
|
598
|
+
while (i < lines.length) {
|
|
599
|
+
const line = lines[i] ?? "";
|
|
600
|
+
if (indentOf(line) !== 0) {
|
|
601
|
+
throw usage(`Unexpected indentation in frontmatter: ${JSON.stringify(line)}`);
|
|
602
|
+
}
|
|
603
|
+
const kv = splitKey(line);
|
|
604
|
+
if (kv === null) throw usage(`Malformed frontmatter line: ${JSON.stringify(line)}`);
|
|
605
|
+
const { key, value } = kv;
|
|
606
|
+
if (value.length > 0) {
|
|
607
|
+
out[key] = parseInlineValue(value);
|
|
608
|
+
i++;
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
const child = [];
|
|
612
|
+
i++;
|
|
613
|
+
while (i < lines.length && indentOf(lines[i] ?? "") > 0) {
|
|
614
|
+
child.push(lines[i] ?? "");
|
|
615
|
+
i++;
|
|
616
|
+
}
|
|
617
|
+
if (child.length === 0) {
|
|
618
|
+
out[key] = "";
|
|
619
|
+
} else if (child.every((c) => /^\s*-\s/.test(c))) {
|
|
620
|
+
out[key] = child.map((c) => unquote(c.replace(/^\s*-\s+/, "").trim()));
|
|
621
|
+
} else {
|
|
622
|
+
out[key] = parseNestedMap(child);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
return out;
|
|
626
|
+
}
|
|
627
|
+
function parseNestedMap(lines) {
|
|
628
|
+
const out = {};
|
|
629
|
+
const baseIndent = indentOf(lines[0] ?? "");
|
|
630
|
+
let i = 0;
|
|
631
|
+
while (i < lines.length) {
|
|
632
|
+
const line = lines[i] ?? "";
|
|
633
|
+
if (indentOf(line) !== baseIndent)
|
|
634
|
+
throw usage(`Malformed nested frontmatter: ${JSON.stringify(line)}`);
|
|
635
|
+
const kv = splitKey(line);
|
|
636
|
+
if (kv === null) throw usage(`Malformed nested frontmatter line: ${JSON.stringify(line)}`);
|
|
637
|
+
const { key, value } = kv;
|
|
638
|
+
if (value.length > 0) {
|
|
639
|
+
const parsed = parseInlineValue(value);
|
|
640
|
+
out[key] = Array.isArray(parsed) ? parsed : [parsed];
|
|
641
|
+
i++;
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
const items = [];
|
|
645
|
+
i++;
|
|
646
|
+
while (i < lines.length && indentOf(lines[i] ?? "") > baseIndent) {
|
|
647
|
+
const c = lines[i] ?? "";
|
|
648
|
+
if (!/^\s*-\s/.test(c))
|
|
649
|
+
throw usage(`Expected a list item in frontmatter: ${JSON.stringify(c)}`);
|
|
650
|
+
items.push(unquote(c.replace(/^\s*-\s+/, "").trim()));
|
|
651
|
+
i++;
|
|
652
|
+
}
|
|
653
|
+
out[key] = items;
|
|
654
|
+
}
|
|
655
|
+
return out;
|
|
656
|
+
}
|
|
657
|
+
function splitKey(line) {
|
|
658
|
+
const m = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*:\s?(.*)$/.exec(line);
|
|
659
|
+
if (m === null || m[1] === void 0) return null;
|
|
660
|
+
guardKey(m[1]);
|
|
661
|
+
return { key: m[1], value: (m[2] ?? "").trim() };
|
|
662
|
+
}
|
|
663
|
+
var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
664
|
+
function guardKey(key) {
|
|
665
|
+
if (UNSAFE_KEYS.has(key)) {
|
|
666
|
+
throw new CliError("USAGE", `Unsupported key: ${JSON.stringify(key)}`, {
|
|
667
|
+
fix: "Rename it; __proto__, constructor, and prototype are not allowed as keys."
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
function parseInlineValue(value) {
|
|
672
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
673
|
+
const inner = value.slice(1, -1).trim();
|
|
674
|
+
if (inner.length === 0) return [];
|
|
675
|
+
return inner.split(",").map((v) => unquote(v.trim()));
|
|
676
|
+
}
|
|
677
|
+
return unquote(value);
|
|
678
|
+
}
|
|
679
|
+
function unquote(value) {
|
|
680
|
+
if (value.startsWith('"') && value.endsWith('"') && value.length >= 2 || value.startsWith("'") && value.endsWith("'") && value.length >= 2) {
|
|
681
|
+
return value.slice(1, -1);
|
|
682
|
+
}
|
|
683
|
+
return value;
|
|
684
|
+
}
|
|
685
|
+
var ARTIFACT_TYPES = ["document", "skill", "dataset"];
|
|
686
|
+
var TEMPORAL_MODES = ["snapshot", "maintained", "evergreen"];
|
|
687
|
+
var MEDIA_TYPE_RE = /^[a-z0-9]+\/[a-z0-9][a-z0-9.+-]*$/i;
|
|
688
|
+
var CANONICAL_KEY_RE = /^[a-z][a-z0-9_]{0,31}$/;
|
|
689
|
+
var ISO_OFFSET_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
|
|
690
|
+
var CardErrors = class {
|
|
691
|
+
fieldErrors = {};
|
|
692
|
+
add(field, message) {
|
|
693
|
+
const key = `resource.${field}`;
|
|
694
|
+
(this.fieldErrors[key] ??= []).push(message);
|
|
695
|
+
}
|
|
696
|
+
get empty() {
|
|
697
|
+
return Object.keys(this.fieldErrors).length === 0;
|
|
698
|
+
}
|
|
699
|
+
throwIfAny() {
|
|
700
|
+
if (this.empty) return;
|
|
701
|
+
const first = Object.entries(this.fieldErrors)[0];
|
|
702
|
+
const summary = first !== void 0 ? `${first[0]}: ${first[1][0]}` : "invalid card";
|
|
703
|
+
throw new CliError("USAGE", `Invalid answer card (${summary})`, {
|
|
704
|
+
fix: "Correct the reported resource.<field> values (frontmatter or flags), then re-run.",
|
|
705
|
+
details: { fieldErrors: this.fieldErrors }
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
function deriveCard(frontmatter, flags) {
|
|
710
|
+
const errs = new CardErrors();
|
|
711
|
+
const card = {};
|
|
712
|
+
const scalar = (fmKey, flagVal) => {
|
|
713
|
+
if (flagVal !== void 0) return flagVal;
|
|
714
|
+
const fm = frontmatter[fmKey];
|
|
715
|
+
if (fm === void 0) return void 0;
|
|
716
|
+
if (typeof fm !== "string") {
|
|
717
|
+
errs.add(fmKey, "expected a single string value");
|
|
718
|
+
return void 0;
|
|
719
|
+
}
|
|
720
|
+
return fm;
|
|
721
|
+
};
|
|
722
|
+
const list = (fmKey, flagVal) => {
|
|
723
|
+
if (flagVal !== void 0 && flagVal.length > 0) return flagVal;
|
|
724
|
+
const fm = frontmatter[fmKey];
|
|
725
|
+
if (fm === void 0) return void 0;
|
|
726
|
+
if (!Array.isArray(fm)) {
|
|
727
|
+
errs.add(fmKey, "expected a list");
|
|
728
|
+
return void 0;
|
|
729
|
+
}
|
|
730
|
+
return fm;
|
|
731
|
+
};
|
|
732
|
+
const artifactType = scalar("artifactType", flags.artifactType);
|
|
733
|
+
if (artifactType !== void 0) {
|
|
734
|
+
if (ARTIFACT_TYPES.includes(artifactType)) {
|
|
735
|
+
card.artifactType = artifactType;
|
|
736
|
+
} else {
|
|
737
|
+
errs.add("artifactType", `must be one of ${ARTIFACT_TYPES.join(", ")}`);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
const mediaType = scalar("mediaType", void 0);
|
|
741
|
+
if (mediaType !== void 0) {
|
|
742
|
+
if (mediaType.length > 100) errs.add("mediaType", "must be at most 100 characters");
|
|
743
|
+
else if (!MEDIA_TYPE_RE.test(mediaType))
|
|
744
|
+
errs.add("mediaType", "must be a MIME type, e.g. text/markdown");
|
|
745
|
+
else card.mediaType = mediaType;
|
|
746
|
+
}
|
|
747
|
+
const temporalMode = scalar("temporalMode", flags.temporalMode);
|
|
748
|
+
if (temporalMode !== void 0) {
|
|
749
|
+
if (TEMPORAL_MODES.includes(temporalMode)) {
|
|
750
|
+
card.temporalMode = temporalMode;
|
|
751
|
+
} else {
|
|
752
|
+
errs.add("temporalMode", `must be one of ${TEMPORAL_MODES.join(", ")}`);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
const asOf = validateIso(scalar("asOf", flags.asOf), "asOf", errs);
|
|
756
|
+
if (asOf !== void 0) card.asOf = asOf;
|
|
757
|
+
const validUntil = validateIso(scalar("validUntil", flags.validUntil), "validUntil", errs);
|
|
758
|
+
if (validUntil !== void 0) card.validUntil = validUntil;
|
|
759
|
+
if (asOf !== void 0 && validUntil !== void 0 && Date.parse(validUntil) < Date.parse(asOf)) {
|
|
760
|
+
errs.add("validUntil", "must be at or after asOf");
|
|
761
|
+
}
|
|
762
|
+
const supersedes = scalar("supersedesPostId", void 0);
|
|
763
|
+
if (supersedes !== void 0) {
|
|
764
|
+
if (UUID_RE.test(supersedes)) card.supersedesPostId = supersedes;
|
|
765
|
+
else errs.add("supersedesPostId", "must be a post uuid");
|
|
766
|
+
}
|
|
767
|
+
const questions = list("questionsAnswered", flags.question);
|
|
768
|
+
if (questions !== void 0) {
|
|
769
|
+
validateStringList(questions, "questionsAnswered", errs);
|
|
770
|
+
card.questionsAnswered = questions;
|
|
771
|
+
}
|
|
772
|
+
const tasks = list("tasksSupported", flags.task);
|
|
773
|
+
if (tasks !== void 0) {
|
|
774
|
+
validateStringList(tasks, "tasksSupported", errs);
|
|
775
|
+
card.tasksSupported = tasks;
|
|
776
|
+
}
|
|
777
|
+
const scope = scalar("scope", flags.scope);
|
|
778
|
+
if (scope !== void 0) {
|
|
779
|
+
if (scope.length > 500) errs.add("scope", "must be at most 500 characters");
|
|
780
|
+
else card.scope = scope;
|
|
781
|
+
}
|
|
782
|
+
const exclusions = scalar("exclusions", flags.exclusions);
|
|
783
|
+
if (exclusions !== void 0) {
|
|
784
|
+
if (exclusions.length > 500) errs.add("exclusions", "must be at most 500 characters");
|
|
785
|
+
else card.exclusions = exclusions;
|
|
786
|
+
}
|
|
787
|
+
const provenance = scalar("provenanceSummary", flags.provenance);
|
|
788
|
+
if (provenance !== void 0) {
|
|
789
|
+
if (provenance.length > 500) errs.add("provenanceSummary", "must be at most 500 characters");
|
|
790
|
+
else card.provenanceSummary = provenance;
|
|
791
|
+
}
|
|
792
|
+
const methodology = scalar("methodologySummary", flags.methodology);
|
|
793
|
+
if (methodology !== void 0) {
|
|
794
|
+
if (methodology.length > 500) errs.add("methodologySummary", "must be at most 500 characters");
|
|
795
|
+
else card.methodologySummary = methodology;
|
|
796
|
+
}
|
|
797
|
+
const appliesTo = flags.appliesTo ?? readAppliesTo(frontmatter, errs);
|
|
798
|
+
if (appliesTo !== void 0) {
|
|
799
|
+
const validated = validateAppliesTo(appliesTo, errs);
|
|
800
|
+
if (validated !== void 0) card.appliesTo = validated;
|
|
801
|
+
}
|
|
802
|
+
const cadence = scalar("maintenanceCadence", void 0);
|
|
803
|
+
if (cadence !== void 0) {
|
|
804
|
+
if (cadence.length > 120) errs.add("maintenanceCadence", "must be at most 120 characters");
|
|
805
|
+
else card.maintenanceCadence = cadence;
|
|
806
|
+
}
|
|
807
|
+
const repro = scalar("reproductionMinutes", void 0);
|
|
808
|
+
if (repro !== void 0) {
|
|
809
|
+
const n = Number(repro);
|
|
810
|
+
if (!Number.isInteger(n) || n < 0 || n > 1e6) {
|
|
811
|
+
errs.add("reproductionMinutes", "must be an integer from 0 to 1000000");
|
|
812
|
+
} else {
|
|
813
|
+
card.reproductionMinutes = n;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
const cost = scalar("estimatedPaidInputCost", void 0);
|
|
817
|
+
if (cost !== void 0) {
|
|
818
|
+
if (ATOMIC_RE.test(cost)) card.estimatedPaidInputCost = cost;
|
|
819
|
+
else errs.add("estimatedPaidInputCost", "must be an atomic USDC digit string");
|
|
820
|
+
}
|
|
821
|
+
errs.throwIfAny();
|
|
822
|
+
return Object.keys(card).length > 0 ? card : void 0;
|
|
823
|
+
}
|
|
824
|
+
function validateIso(value, field, errs) {
|
|
825
|
+
if (value === void 0) return void 0;
|
|
826
|
+
if (!ISO_OFFSET_RE.test(value) || !Number.isFinite(Date.parse(value))) {
|
|
827
|
+
errs.add(field, "must be an ISO-8601 timestamp with an offset, e.g. 2026-07-01T00:00:00Z");
|
|
828
|
+
return void 0;
|
|
829
|
+
}
|
|
830
|
+
return value;
|
|
831
|
+
}
|
|
832
|
+
function validateStringList(list, field, errs) {
|
|
833
|
+
if (list.length > 10) errs.add(field, "at most 10 items");
|
|
834
|
+
for (const item of list) {
|
|
835
|
+
if (item.length === 0) errs.add(field, "items must be non-empty");
|
|
836
|
+
else if (item.length > 200) errs.add(field, "each item is at most 200 characters");
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
function readAppliesTo(frontmatter, errs) {
|
|
840
|
+
const fm = frontmatter.appliesTo;
|
|
841
|
+
if (fm === void 0) return void 0;
|
|
842
|
+
if (typeof fm === "string" || Array.isArray(fm)) {
|
|
843
|
+
errs.add("appliesTo", "must be a map of key to a list of values");
|
|
844
|
+
return void 0;
|
|
845
|
+
}
|
|
846
|
+
return fm;
|
|
847
|
+
}
|
|
848
|
+
function validateAppliesTo(appliesTo, errs) {
|
|
849
|
+
const keys = Object.keys(appliesTo);
|
|
850
|
+
if (keys.length > 8) errs.add("appliesTo", "at most 8 keys");
|
|
851
|
+
const out = {};
|
|
852
|
+
for (const [key, rawValues] of Object.entries(appliesTo)) {
|
|
853
|
+
if (!CANONICAL_KEY_RE.test(key)) {
|
|
854
|
+
errs.add("appliesTo", `key ${JSON.stringify(key)} must match ^[a-z][a-z0-9_]{0,31}$`);
|
|
855
|
+
continue;
|
|
856
|
+
}
|
|
857
|
+
const values = rawValues.map((v) => v.trim());
|
|
858
|
+
if (values.length > 20) errs.add("appliesTo", `key ${key} has more than 20 values`);
|
|
859
|
+
for (const v of values) {
|
|
860
|
+
if (v.length < 1 || v.length > 120) {
|
|
861
|
+
errs.add("appliesTo", `key ${key} values must be 1 to 120 characters`);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
out[key] = values;
|
|
865
|
+
}
|
|
866
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
867
|
+
}
|
|
868
|
+
function parseAppliesToFlags(pairs) {
|
|
869
|
+
const out = {};
|
|
870
|
+
for (const pair of pairs) {
|
|
871
|
+
const eq = pair.indexOf("=");
|
|
872
|
+
if (eq <= 0) {
|
|
873
|
+
throw new CliError("USAGE", `Invalid --applies-to ${JSON.stringify(pair)}`, {
|
|
874
|
+
fix: "Use key=value, e.g. --applies-to products=Vercel."
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
const key = pair.slice(0, eq).trim();
|
|
878
|
+
const value = pair.slice(eq + 1).trim();
|
|
879
|
+
guardKey(key);
|
|
880
|
+
(out[key] ??= []).push(value);
|
|
881
|
+
}
|
|
882
|
+
return out;
|
|
883
|
+
}
|
|
884
|
+
var MISSING_SENTENCES = {
|
|
885
|
+
questionsOrTasks: "Add at least one question answered or task supported.",
|
|
886
|
+
scope: "Describe the scope (what this piece covers).",
|
|
887
|
+
exclusions: "State the exclusions (what this piece does not cover).",
|
|
888
|
+
asOf: "Set an as-of date (a snapshot card needs one).",
|
|
889
|
+
provenanceOrMethodology: "Add a provenance or methodology summary."
|
|
890
|
+
};
|
|
891
|
+
function missingSentences(tokens) {
|
|
892
|
+
return tokens.map((t) => MISSING_SENTENCES[t] ?? t);
|
|
893
|
+
}
|
|
894
|
+
function localCardEligibility(card) {
|
|
895
|
+
const tokens = [];
|
|
896
|
+
const hasQuestionsOrTasks = (card?.questionsAnswered?.some(hasText) ?? false) || (card?.tasksSupported?.some(hasText) ?? false);
|
|
897
|
+
if (!hasQuestionsOrTasks) tokens.push("questionsOrTasks");
|
|
898
|
+
if (!hasText(card?.scope)) tokens.push("scope");
|
|
899
|
+
if (!hasText(card?.exclusions)) tokens.push("exclusions");
|
|
900
|
+
if (card?.temporalMode === "snapshot" && !hasText(card.asOf)) tokens.push("asOf");
|
|
901
|
+
if (!hasText(card?.provenanceSummary) && !hasText(card?.methodologySummary)) {
|
|
902
|
+
tokens.push("provenanceOrMethodology");
|
|
903
|
+
}
|
|
904
|
+
return { cacheEligible: tokens.length === 0, missing: missingSentences(tokens) };
|
|
905
|
+
}
|
|
906
|
+
function hasText(value) {
|
|
907
|
+
return value !== void 0 && value.trim().length > 0;
|
|
908
|
+
}
|
|
909
|
+
function usage(message) {
|
|
910
|
+
return new CliError("USAGE", message, {
|
|
911
|
+
fix: "Frontmatter supports key: value, key: [a, b], block lists, and a one-level appliesTo map."
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// src/lib/posts-api.ts
|
|
916
|
+
var PUBLISH_STATUSES = ["draft", "published", "unlisted"];
|
|
917
|
+
var PRICE_RE = /^(0|[1-9]\d{0,12})$/;
|
|
918
|
+
var HANDLE_RE = /^[a-z0-9-]{2,32}$/;
|
|
919
|
+
var RESERVED_HANDLES = /* @__PURE__ */ new Set(["latest"]);
|
|
920
|
+
function buildPostCreateBody(input) {
|
|
921
|
+
const isDraft = input.status === "draft";
|
|
922
|
+
const title = input.title?.trim();
|
|
923
|
+
const bodyMd = input.bodyMd;
|
|
924
|
+
const hasTitle = title !== void 0 && title.length > 0;
|
|
925
|
+
const hasBody = bodyMd !== void 0 && bodyMd.trim().length > 0;
|
|
926
|
+
if (isDraft && !hasTitle && !hasBody) {
|
|
927
|
+
throw new CliError("USAGE", "A draft needs a title or a body.", {
|
|
928
|
+
fix: "Add a `title:` or some Markdown; a completely empty draft is rejected."
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
if (!isDraft && !hasTitle) {
|
|
932
|
+
throw new CliError("USAGE", "A published post needs a title.", {
|
|
933
|
+
fix: "Add a `title:` to the frontmatter or a leading `# Heading`, or pass --draft."
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
if (!isDraft && !hasBody) {
|
|
937
|
+
throw new CliError("USAGE", "A published post needs a body.", {
|
|
938
|
+
fix: "Add Markdown below the frontmatter, or pass --draft."
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
if (title !== void 0 && title.length > 200) {
|
|
942
|
+
throw new CliError("USAGE", "title must be at most 200 characters.");
|
|
943
|
+
}
|
|
944
|
+
if (bodyMd !== void 0 && bodyMd.length > 2e5) {
|
|
945
|
+
throw new CliError("USAGE", "bodyMd must be at most 200000 characters.");
|
|
946
|
+
}
|
|
947
|
+
const excerpt = input.excerpt?.trim();
|
|
948
|
+
if (excerpt !== void 0 && excerpt.length > 500) {
|
|
949
|
+
throw new CliError("USAGE", "excerpt must be at most 500 characters.");
|
|
950
|
+
}
|
|
951
|
+
if (input.tags !== void 0) {
|
|
952
|
+
if (input.tags.length > 5) throw new CliError("USAGE", "at most 5 tags.");
|
|
953
|
+
for (const tag of input.tags) {
|
|
954
|
+
if (tag.length === 0 || tag.length > 50) {
|
|
955
|
+
throw new CliError("USAGE", "each tag is 1 to 50 characters.");
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
if (input.priceAtomic !== void 0 && !PRICE_RE.test(input.priceAtomic)) {
|
|
960
|
+
throw new CliError("USAGE", `Invalid price: ${JSON.stringify(input.priceAtomic)}`, {
|
|
961
|
+
fix: "A price is an atomic USDC integer up to 13 digits, e.g. 100000 for $0.10."
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
if (input.handle !== void 0) {
|
|
965
|
+
if (!HANDLE_RE.test(input.handle)) {
|
|
966
|
+
throw new CliError("USAGE", `Invalid handle: ${JSON.stringify(input.handle)}`, {
|
|
967
|
+
fix: "A handle is 2 to 32 chars of a-z, 0-9, or hyphen."
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
if (input.handle.startsWith("0x") || RESERVED_HANDLES.has(input.handle)) {
|
|
971
|
+
throw new CliError("USAGE", `Reserved handle: ${JSON.stringify(input.handle)}`, {
|
|
972
|
+
fix: "Pick a handle that is not 0x-prefixed and not a reserved word (e.g. latest)."
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
return {
|
|
977
|
+
...title !== void 0 && title.length > 0 ? { title } : {},
|
|
978
|
+
...bodyMd !== void 0 ? { bodyMd } : {},
|
|
979
|
+
...excerpt !== void 0 ? { excerpt } : {},
|
|
980
|
+
...input.tags !== void 0 && input.tags.length > 0 ? { tags: input.tags } : {},
|
|
981
|
+
...input.priceAtomic !== void 0 ? { price: input.priceAtomic } : {},
|
|
982
|
+
...input.handle !== void 0 ? { handle: input.handle } : {},
|
|
983
|
+
status: input.status,
|
|
984
|
+
...input.resource !== void 0 ? { resource: input.resource } : {}
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
var resourceEchoSchema = external_exports.object({
|
|
988
|
+
artifactType: external_exports.string().nullish(),
|
|
989
|
+
mediaType: external_exports.string().nullish(),
|
|
990
|
+
temporalMode: external_exports.string().nullish(),
|
|
991
|
+
asOf: external_exports.string().nullish(),
|
|
992
|
+
validUntil: external_exports.string().nullish(),
|
|
993
|
+
supersedesPostId: external_exports.string().nullish(),
|
|
994
|
+
questionsAnswered: external_exports.array(external_exports.string()).nullish(),
|
|
995
|
+
tasksSupported: external_exports.array(external_exports.string()).nullish(),
|
|
996
|
+
scope: external_exports.string().nullish(),
|
|
997
|
+
exclusions: external_exports.string().nullish(),
|
|
998
|
+
appliesTo: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())).nullish(),
|
|
999
|
+
provenanceSummary: external_exports.string().nullish(),
|
|
1000
|
+
methodologySummary: external_exports.string().nullish(),
|
|
1001
|
+
maintenanceCadence: external_exports.string().nullish(),
|
|
1002
|
+
reproductionMinutes: external_exports.number().nullish(),
|
|
1003
|
+
estimatedPaidInputCost: external_exports.string().nullish(),
|
|
1004
|
+
cacheEligible: external_exports.boolean(),
|
|
1005
|
+
cacheEligibleMissing: external_exports.array(external_exports.string())
|
|
1006
|
+
}).passthrough();
|
|
1007
|
+
var ownPostSchema = external_exports.object({
|
|
1008
|
+
id: external_exports.string(),
|
|
1009
|
+
slug: external_exports.string(),
|
|
1010
|
+
title: external_exports.string(),
|
|
1011
|
+
status: external_exports.string(),
|
|
1012
|
+
price: external_exports.string(),
|
|
1013
|
+
url: external_exports.string(),
|
|
1014
|
+
excerpt: external_exports.string().nullish(),
|
|
1015
|
+
bodyMd: external_exports.string().nullish(),
|
|
1016
|
+
tags: external_exports.array(external_exports.string()).nullish(),
|
|
1017
|
+
warnings: external_exports.array(external_exports.string()).optional(),
|
|
1018
|
+
resource: resourceEchoSchema.optional()
|
|
1019
|
+
}).passthrough();
|
|
1020
|
+
var MAX_RECOVERIES = 3;
|
|
1021
|
+
async function publishPost(input, auth, opts) {
|
|
1022
|
+
const body = buildPostCreateBody(input);
|
|
1023
|
+
const url = `${trimSlash(opts.baseUrl)}/api/posts`;
|
|
1024
|
+
const bodyStr = JSON.stringify(body);
|
|
1025
|
+
let recoveries = 0;
|
|
1026
|
+
for (; ; ) {
|
|
1027
|
+
const authHeaders = await auth.headersFor({ method: "POST", url, body: bodyStr });
|
|
1028
|
+
const res = await httpRequest(url, {
|
|
1029
|
+
method: "POST",
|
|
1030
|
+
timeoutMs: opts.timeoutMs,
|
|
1031
|
+
headers: { ...authHeaders },
|
|
1032
|
+
jsonBody: body,
|
|
1033
|
+
...opts.fetchImpl !== void 0 ? { fetchImpl: opts.fetchImpl } : {}
|
|
1034
|
+
});
|
|
1035
|
+
if (!res.ok) throw writeTransportError(url, res);
|
|
1036
|
+
if (res.status === 401 && recoveries < MAX_RECOVERIES) {
|
|
1037
|
+
const code = auth401Code(res);
|
|
1038
|
+
if (await auth.recover(code)) {
|
|
1039
|
+
recoveries++;
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
1042
|
+
throw authError(code, res);
|
|
1043
|
+
}
|
|
1044
|
+
if (res.status === 401) throw authError(auth401Code(res), res);
|
|
1045
|
+
if (res.status === 429) throw rateLimitError(url, (n) => res.header(n));
|
|
1046
|
+
if (res.status !== 201 && res.status !== 200) throw publishFailed(res);
|
|
1047
|
+
const parsed = ownPostSchema.safeParse(res.json);
|
|
1048
|
+
if (!parsed.success) {
|
|
1049
|
+
throw new CliError("CONTRACT_MISMATCH", "The publish response did not match the contract.", {
|
|
1050
|
+
fix: "Update tenjin-cli; the server contract may have changed.",
|
|
1051
|
+
details: parsed.error.issues
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
const post = parsed.data;
|
|
1055
|
+
return {
|
|
1056
|
+
resourceId: post.id,
|
|
1057
|
+
slug: post.slug,
|
|
1058
|
+
title: post.title,
|
|
1059
|
+
status: post.status,
|
|
1060
|
+
priceAtomic: post.price,
|
|
1061
|
+
url: post.url,
|
|
1062
|
+
...post.resource !== void 0 ? { cacheEligible: post.resource.cacheEligible } : {},
|
|
1063
|
+
cacheEligibleMissing: post.resource?.cacheEligibleMissing ?? [],
|
|
1064
|
+
warnings: post.warnings ?? []
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
function buildPostUpdateBody(input) {
|
|
1069
|
+
const title = input.title?.trim();
|
|
1070
|
+
if (input.title !== void 0 && (title === void 0 || title.length === 0)) {
|
|
1071
|
+
throw new CliError("USAGE", "title cannot be empty.", {
|
|
1072
|
+
fix: "Pass a title, or omit --title to keep the stored one."
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
if (title !== void 0 && title.length > 200) {
|
|
1076
|
+
throw new CliError("USAGE", "title must be at most 200 characters.");
|
|
1077
|
+
}
|
|
1078
|
+
if (input.bodyMd !== void 0) {
|
|
1079
|
+
if (input.bodyMd.trim().length === 0) {
|
|
1080
|
+
throw new CliError("USAGE", "bodyMd cannot be empty.", {
|
|
1081
|
+
fix: "Pass a file with Markdown in it, or omit --body to keep the stored body."
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
if (input.bodyMd.length > 2e5) {
|
|
1085
|
+
throw new CliError("USAGE", "bodyMd must be at most 200000 characters.");
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
const excerpt = input.excerpt?.trim();
|
|
1089
|
+
if (excerpt !== void 0 && excerpt.length > 500) {
|
|
1090
|
+
throw new CliError("USAGE", "excerpt must be at most 500 characters.");
|
|
1091
|
+
}
|
|
1092
|
+
if (input.tags !== void 0) {
|
|
1093
|
+
if (input.tags.length > 5) throw new CliError("USAGE", "at most 5 tags.");
|
|
1094
|
+
for (const tag of input.tags) {
|
|
1095
|
+
if (tag.length === 0 || tag.length > 50) {
|
|
1096
|
+
throw new CliError("USAGE", "each tag is 1 to 50 characters.");
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
if (input.priceAtomic !== void 0 && !PRICE_RE.test(input.priceAtomic)) {
|
|
1101
|
+
throw new CliError("USAGE", `Invalid price: ${JSON.stringify(input.priceAtomic)}`, {
|
|
1102
|
+
fix: "A price is an atomic USDC integer up to 13 digits, e.g. 100000 for $0.10."
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
const body = {
|
|
1106
|
+
...title !== void 0 ? { title } : {},
|
|
1107
|
+
...input.bodyMd !== void 0 ? { bodyMd: input.bodyMd } : {},
|
|
1108
|
+
...excerpt !== void 0 ? { excerpt } : {},
|
|
1109
|
+
...input.tags !== void 0 ? { tags: input.tags } : {},
|
|
1110
|
+
...input.priceAtomic !== void 0 ? { price: input.priceAtomic } : {},
|
|
1111
|
+
...input.status !== void 0 ? { status: input.status } : {},
|
|
1112
|
+
...input.resource !== void 0 ? { resource: input.resource } : {}
|
|
1113
|
+
};
|
|
1114
|
+
if (Object.keys(body).length === 0) {
|
|
1115
|
+
throw new CliError("USAGE", "Nothing to update.", {
|
|
1116
|
+
fix: "Pass at least one field flag, or run `tenjin edit <postId>` with no flags to view the post."
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
return body;
|
|
1120
|
+
}
|
|
1121
|
+
async function getOwnPost(id, auth, opts) {
|
|
1122
|
+
const url = `${trimSlash(opts.baseUrl)}/api/posts/${encodeURIComponent(id)}`;
|
|
1123
|
+
let recoveries = 0;
|
|
1124
|
+
for (; ; ) {
|
|
1125
|
+
const authHeaders = await auth.headersFor({ method: "GET", url });
|
|
1126
|
+
const res = await httpRequest(url, {
|
|
1127
|
+
method: "GET",
|
|
1128
|
+
timeoutMs: opts.timeoutMs,
|
|
1129
|
+
headers: { accept: "application/json", ...authHeaders },
|
|
1130
|
+
...opts.fetchImpl !== void 0 ? { fetchImpl: opts.fetchImpl } : {}
|
|
1131
|
+
});
|
|
1132
|
+
if (!res.ok) throw writeTransportError(url, res);
|
|
1133
|
+
if (res.status === 401 && recoveries < MAX_RECOVERIES) {
|
|
1134
|
+
const code = auth401Code(res);
|
|
1135
|
+
if (await auth.recover(code)) {
|
|
1136
|
+
recoveries++;
|
|
1137
|
+
continue;
|
|
1138
|
+
}
|
|
1139
|
+
throw readAuthError(code, res);
|
|
1140
|
+
}
|
|
1141
|
+
if (res.status === 401) throw readAuthError(auth401Code(res), res);
|
|
1142
|
+
if (res.status === 404) throw postNotFound(id);
|
|
1143
|
+
if (res.status === 429) throw rateLimitError(url, (n) => res.header(n));
|
|
1144
|
+
if (res.status !== 200) {
|
|
1145
|
+
throw new CliError(
|
|
1146
|
+
"API_UNREACHABLE",
|
|
1147
|
+
serverMessage(res.json) ?? `Could not read post ${id} (${res.status}).`,
|
|
1148
|
+
{
|
|
1149
|
+
fix: "Review the server error, then retry.",
|
|
1150
|
+
details: { status: res.status, ...res.json !== void 0 ? { server: res.json } : {} }
|
|
1151
|
+
}
|
|
1152
|
+
);
|
|
1153
|
+
}
|
|
1154
|
+
return parseOwnPost(res.json, "read");
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
async function updatePost(id, input, auth, opts) {
|
|
1158
|
+
const body = buildPostUpdateBody(input);
|
|
1159
|
+
const url = `${trimSlash(opts.baseUrl)}/api/posts/${encodeURIComponent(id)}`;
|
|
1160
|
+
const bodyStr = JSON.stringify(body);
|
|
1161
|
+
let recoveries = 0;
|
|
1162
|
+
for (; ; ) {
|
|
1163
|
+
const authHeaders = await auth.headersFor({ method: "PUT", url, body: bodyStr });
|
|
1164
|
+
const res = await httpRequest(url, {
|
|
1165
|
+
method: "PUT",
|
|
1166
|
+
timeoutMs: opts.timeoutMs,
|
|
1167
|
+
headers: { ...authHeaders },
|
|
1168
|
+
jsonBody: body,
|
|
1169
|
+
...opts.fetchImpl !== void 0 ? { fetchImpl: opts.fetchImpl } : {}
|
|
1170
|
+
});
|
|
1171
|
+
if (!res.ok) throw writeTransportError(url, res);
|
|
1172
|
+
if (res.status === 401 && recoveries < MAX_RECOVERIES) {
|
|
1173
|
+
const code = auth401Code(res);
|
|
1174
|
+
if (await auth.recover(code)) {
|
|
1175
|
+
recoveries++;
|
|
1176
|
+
continue;
|
|
1177
|
+
}
|
|
1178
|
+
throw authError(code, res);
|
|
1179
|
+
}
|
|
1180
|
+
if (res.status === 401) throw authError(auth401Code(res), res);
|
|
1181
|
+
if (res.status === 404) throw postNotFound(id);
|
|
1182
|
+
if (res.status === 429) throw rateLimitError(url, (n) => res.header(n));
|
|
1183
|
+
if (res.status !== 200) throw updateFailed(res);
|
|
1184
|
+
return parseOwnPost(res.json, "update");
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
function parseOwnPost(json, what) {
|
|
1188
|
+
const parsed = ownPostSchema.safeParse(json);
|
|
1189
|
+
if (!parsed.success) {
|
|
1190
|
+
throw new CliError(
|
|
1191
|
+
"CONTRACT_MISMATCH",
|
|
1192
|
+
`The post ${what} response did not match the contract.`,
|
|
1193
|
+
{
|
|
1194
|
+
fix: "Update tenjin-cli; the server contract may have changed.",
|
|
1195
|
+
details: parsed.error.issues
|
|
1196
|
+
}
|
|
1197
|
+
);
|
|
1198
|
+
}
|
|
1199
|
+
return parsed.data;
|
|
1200
|
+
}
|
|
1201
|
+
function postNotFound(id) {
|
|
1202
|
+
return new CliError("RESOURCE_NOT_FOUND", `Post ${id} was not found, or is not yours.`, {
|
|
1203
|
+
fix: "Check the post id on your desk; owner-scoped routes do not distinguish the two."
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
function readAuthError(code, res) {
|
|
1207
|
+
return new CliError(
|
|
1208
|
+
"API_UNREACHABLE",
|
|
1209
|
+
serverMessage(res.json) ?? `Reading the post was not authorized (${code ?? "401"}).`,
|
|
1210
|
+
{
|
|
1211
|
+
fix: code === "session_key_unbound" ? "Delete ~/.tenjin/session.json to re-establish the session key." : "Check the wallet and retry.",
|
|
1212
|
+
details: {
|
|
1213
|
+
code: code ?? "unauthorized",
|
|
1214
|
+
...res.json !== void 0 ? { server: res.json } : {}
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
);
|
|
1218
|
+
}
|
|
1219
|
+
function updateFailed(res) {
|
|
1220
|
+
const fields = fieldErrorKeys(res.json);
|
|
1221
|
+
const base = serverMessage(res.json) ?? `Update failed (${res.status}).`;
|
|
1222
|
+
return new CliError(
|
|
1223
|
+
"PUBLISH_FAILED",
|
|
1224
|
+
fields.length > 0 ? `${base} (${fields.join(", ")})` : base,
|
|
1225
|
+
{
|
|
1226
|
+
fix: fields.length > 0 ? "Correct the reported fields, then re-run `tenjin edit`." : "Review the server error, then re-run `tenjin edit`.",
|
|
1227
|
+
details: { status: res.status, ...res.json !== void 0 ? { server: res.json } : {} }
|
|
1228
|
+
}
|
|
1229
|
+
);
|
|
1230
|
+
}
|
|
1231
|
+
function fieldErrorKeys(json) {
|
|
1232
|
+
if (typeof json !== "object" || json === null) return [];
|
|
1233
|
+
const err = json.error;
|
|
1234
|
+
if (typeof err !== "object" || err === null) return [];
|
|
1235
|
+
const details = err.details;
|
|
1236
|
+
if (typeof details !== "object" || details === null) return [];
|
|
1237
|
+
const fieldErrors = details.fieldErrors;
|
|
1238
|
+
if (typeof fieldErrors !== "object" || fieldErrors === null) return [];
|
|
1239
|
+
return Object.keys(fieldErrors);
|
|
1240
|
+
}
|
|
1241
|
+
function auth401Code(res) {
|
|
1242
|
+
const header = res.header("www-authenticate");
|
|
1243
|
+
const m = header !== void 0 ? /error="([^"]+)"/.exec(header) : null;
|
|
1244
|
+
if (m?.[1] !== void 0) return m[1];
|
|
1245
|
+
return bodyErrorCode(res.json);
|
|
1246
|
+
}
|
|
1247
|
+
function bodyErrorCode(json) {
|
|
1248
|
+
if (typeof json === "object" && json !== null) {
|
|
1249
|
+
const err = json.error;
|
|
1250
|
+
if (typeof err === "object" && err !== null) {
|
|
1251
|
+
const code = err.code;
|
|
1252
|
+
if (typeof code === "string") return code;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
return void 0;
|
|
1256
|
+
}
|
|
1257
|
+
function serverMessage(json) {
|
|
1258
|
+
if (typeof json === "object" && json !== null) {
|
|
1259
|
+
const err = json.error;
|
|
1260
|
+
if (typeof err === "object" && err !== null) {
|
|
1261
|
+
const m = err.message;
|
|
1262
|
+
if (typeof m === "string") return m;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
return void 0;
|
|
1266
|
+
}
|
|
1267
|
+
function authError(code, res) {
|
|
1268
|
+
return new CliError(
|
|
1269
|
+
"PUBLISH_FAILED",
|
|
1270
|
+
serverMessage(res.json) ?? `Publish was not authorized (${code ?? "401"}).`,
|
|
1271
|
+
{
|
|
1272
|
+
fix: code === "session_key_unbound" ? "Delete ~/.tenjin/session.json to re-establish the session key." : "Check the wallet and retry.",
|
|
1273
|
+
details: {
|
|
1274
|
+
code: code ?? "unauthorized",
|
|
1275
|
+
...res.json !== void 0 ? { server: res.json } : {}
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
);
|
|
1279
|
+
}
|
|
1280
|
+
function publishFailed(res) {
|
|
1281
|
+
return new CliError(
|
|
1282
|
+
"PUBLISH_FAILED",
|
|
1283
|
+
serverMessage(res.json) ?? `Publish failed (${res.status}).`,
|
|
1284
|
+
{
|
|
1285
|
+
fix: "Review the server error, then re-run `tenjin publish`.",
|
|
1286
|
+
details: { status: res.status, ...res.json !== void 0 ? { server: res.json } : {} }
|
|
1287
|
+
}
|
|
1288
|
+
);
|
|
1289
|
+
}
|
|
1290
|
+
function writeTransportError(url, result) {
|
|
1291
|
+
const code = result.kind === "network" || result.kind === "timeout" ? "NETWORK_ERROR" : "API_UNREACHABLE";
|
|
1292
|
+
return new CliError(code, `${url}: ${result.message}`, {
|
|
1293
|
+
fix: "Check your network and the configured base URL (`tenjin config get baseUrl`), then retry."
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
// src/lib/consent.ts
|
|
1298
|
+
var WRITE_CHAIN_ID = SESSION_CHAIN_ID;
|
|
1299
|
+
function resolveWriteAuth(opts) {
|
|
1300
|
+
const config = {
|
|
1301
|
+
signer: opts.signer,
|
|
1302
|
+
baseUrl: opts.baseUrl,
|
|
1303
|
+
chainId: WRITE_CHAIN_ID,
|
|
1304
|
+
dataDir: opts.dataDir,
|
|
1305
|
+
scope: opts.scope
|
|
1306
|
+
};
|
|
1307
|
+
const useSession = opts.useSession ?? opts.env.TENJIN_NO_SESSION !== "1";
|
|
1308
|
+
return useSession ? createSessionKeyAuth(config) : createSiwxAuth(config);
|
|
1309
|
+
}
|
|
1310
|
+
function needsConfirmation(mode, warnCount) {
|
|
1311
|
+
return mode === "review" || mode === "auto" && warnCount > 0;
|
|
1312
|
+
}
|
|
1313
|
+
function writeModeNotices(stderr, settings, env, defaultExplainer) {
|
|
1314
|
+
for (const warning of settings.warnings) {
|
|
1315
|
+
stderr.write(`${warning}
|
|
1316
|
+
`);
|
|
1317
|
+
}
|
|
1318
|
+
const envMode = env.TENJIN_PUBLISH_MODE;
|
|
1319
|
+
if (envMode !== void 0 && envMode.length > 0 && !PublishModeSchema.safeParse(envMode).success) {
|
|
1320
|
+
stderr.write(
|
|
1321
|
+
`Ignoring invalid TENJIN_PUBLISH_MODE=${JSON.stringify(envMode)}; using ${settings.mode} (${settings.modeSource}).
|
|
1322
|
+
`
|
|
1323
|
+
);
|
|
1324
|
+
}
|
|
1325
|
+
if (settings.modeSource === "default") {
|
|
1326
|
+
stderr.write(
|
|
1327
|
+
`publish.mode: ${settings.mode} (default) - ${defaultExplainer}: tenjin config set publish.mode auto.
|
|
1328
|
+
`
|
|
1329
|
+
);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
function publicFinding(f) {
|
|
1333
|
+
return { check: f.check, severity: f.severity, line: f.line, excerpt: f.excerpt };
|
|
1334
|
+
}
|
|
1335
|
+
function dedupeFindings(findings) {
|
|
1336
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1337
|
+
return findings.filter((f) => {
|
|
1338
|
+
const key = `${f.check}:${f.excerpt}`;
|
|
1339
|
+
if (seen.has(key)) return false;
|
|
1340
|
+
seen.add(key);
|
|
1341
|
+
return true;
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
function describeFindings(blocking) {
|
|
1345
|
+
const checks = [...new Set(blocking.map((f) => f.check))].join(", ");
|
|
1346
|
+
return `${blocking.length} secret finding(s) (${checks})`;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
export {
|
|
1350
|
+
scan,
|
|
1351
|
+
deriveProjectMarkers,
|
|
1352
|
+
parseFrontmatter,
|
|
1353
|
+
deriveCard,
|
|
1354
|
+
parseAppliesToFlags,
|
|
1355
|
+
missingSentences,
|
|
1356
|
+
localCardEligibility,
|
|
1357
|
+
PUBLISH_STATUSES,
|
|
1358
|
+
publishPost,
|
|
1359
|
+
buildPostUpdateBody,
|
|
1360
|
+
getOwnPost,
|
|
1361
|
+
updatePost,
|
|
1362
|
+
resolveWriteAuth,
|
|
1363
|
+
needsConfirmation,
|
|
1364
|
+
writeModeNotices,
|
|
1365
|
+
publicFinding,
|
|
1366
|
+
dedupeFindings,
|
|
1367
|
+
describeFindings
|
|
1368
|
+
};
|
|
1369
|
+
//# sourceMappingURL=chunk-ZUAQRIVP.js.map
|