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,135 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
withFileLock
|
|
4
|
+
} from "./chunk-FKSAUOJU.js";
|
|
5
|
+
import {
|
|
6
|
+
external_exports,
|
|
7
|
+
writeFileAtomic
|
|
8
|
+
} from "./chunk-PZRAAAY2.js";
|
|
9
|
+
|
|
10
|
+
// src/lib/search-store.ts
|
|
11
|
+
import { mkdir, readFile } from "fs/promises";
|
|
12
|
+
import { join } from "path";
|
|
13
|
+
var MAX_ENTRIES = 50;
|
|
14
|
+
var StoredCandidateSchema = external_exports.object({
|
|
15
|
+
resourceId: external_exports.string(),
|
|
16
|
+
url: external_exports.string(),
|
|
17
|
+
title: external_exports.string(),
|
|
18
|
+
price: external_exports.string()
|
|
19
|
+
});
|
|
20
|
+
var SearchResolutionSchema = external_exports.enum(["outcome", "publish", "candidate"]);
|
|
21
|
+
var SearchSourceSchema = external_exports.enum(["cli", "websearch-hook"]);
|
|
22
|
+
var StoredSearchSchema = external_exports.object({
|
|
23
|
+
searchId: external_exports.string(),
|
|
24
|
+
at: external_exports.string(),
|
|
25
|
+
question: external_exports.string(),
|
|
26
|
+
decision: external_exports.string(),
|
|
27
|
+
candidates: external_exports.array(StoredCandidateSchema),
|
|
28
|
+
/** Absent until something closes the loop; see {@link markSearchResolved}. */
|
|
29
|
+
resolved: external_exports.object({ by: SearchResolutionSchema, at: external_exports.string() }).optional(),
|
|
30
|
+
/** Absent on entries written before sources existed; see {@link SearchSourceSchema}. */
|
|
31
|
+
source: SearchSourceSchema.optional(),
|
|
32
|
+
// How many of the search's browse pointers cost money, and NOT the pointers
|
|
33
|
+
// themselves: keeping them out of the store is what makes `buy <resourceId>`
|
|
34
|
+
// unable to reach one (see the browse comment in agent-api.ts), and a count
|
|
35
|
+
// cannot undo that. It exists so `outcome` can tell "this search offered
|
|
36
|
+
// nothing to buy" from "this search offered a payable browse tail", which the
|
|
37
|
+
// candidates array alone cannot say. Counts only PAID pointers because a
|
|
38
|
+
// zero-priced piece is delivered by `read` with no purchase to decline.
|
|
39
|
+
// Optional because entries written before this field existed have no answer,
|
|
40
|
+
// and `undefined` must read as unknown rather than as zero.
|
|
41
|
+
paidBrowseCount: external_exports.number().int().nonnegative().optional()
|
|
42
|
+
});
|
|
43
|
+
var StoreSchema = external_exports.object({
|
|
44
|
+
schemaVersion: external_exports.literal(1),
|
|
45
|
+
searches: external_exports.array(StoredSearchSchema)
|
|
46
|
+
});
|
|
47
|
+
function searchStorePath(dataDir) {
|
|
48
|
+
return join(dataDir, "searches.json");
|
|
49
|
+
}
|
|
50
|
+
function storePath(dataDir) {
|
|
51
|
+
return searchStorePath(dataDir);
|
|
52
|
+
}
|
|
53
|
+
async function loadSearches(dataDir) {
|
|
54
|
+
let raw;
|
|
55
|
+
try {
|
|
56
|
+
raw = await readFile(storePath(dataDir), "utf8");
|
|
57
|
+
} catch {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
let json;
|
|
61
|
+
try {
|
|
62
|
+
json = JSON.parse(raw);
|
|
63
|
+
} catch {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
const parsed = StoreSchema.safeParse(json);
|
|
67
|
+
return parsed.success ? parsed.data.searches : [];
|
|
68
|
+
}
|
|
69
|
+
async function recordSearch(dataDir, entry) {
|
|
70
|
+
await mkdir(dataDir, { recursive: true, mode: 448 });
|
|
71
|
+
const lockPath = `${storePath(dataDir)}.lock`;
|
|
72
|
+
await withFileLock(lockPath, async () => {
|
|
73
|
+
const existing = await loadSearches(dataDir);
|
|
74
|
+
const searches = [entry, ...existing.filter((l) => l.searchId !== entry.searchId)].slice(
|
|
75
|
+
0,
|
|
76
|
+
MAX_ENTRIES
|
|
77
|
+
);
|
|
78
|
+
await writeFileAtomic(
|
|
79
|
+
storePath(dataDir),
|
|
80
|
+
`${JSON.stringify({ schemaVersion: 1, searches }, null, 2)}
|
|
81
|
+
`,
|
|
82
|
+
{ mode: 420, dirMode: 448 }
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async function markSearchResolved(dataDir, searchId, by, at = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
87
|
+
try {
|
|
88
|
+
const lockPath = `${storePath(dataDir)}.lock`;
|
|
89
|
+
await withFileLock(lockPath, async () => {
|
|
90
|
+
const existing = await loadSearches(dataDir);
|
|
91
|
+
const target = existing.find((s) => s.searchId === searchId);
|
|
92
|
+
if (target === void 0 || target.resolved !== void 0) return;
|
|
93
|
+
const searches = existing.map(
|
|
94
|
+
(s) => s.searchId === searchId ? { ...s, resolved: { by, at } } : s
|
|
95
|
+
);
|
|
96
|
+
await writeFileAtomic(
|
|
97
|
+
storePath(dataDir),
|
|
98
|
+
`${JSON.stringify({ schemaVersion: 1, searches }, null, 2)}
|
|
99
|
+
`,
|
|
100
|
+
{ mode: 420, dirMode: 448 }
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function latestSearch(dataDir) {
|
|
107
|
+
const searches = await loadSearches(dataDir);
|
|
108
|
+
return searches.find((s) => s.source !== "websearch-hook") ?? null;
|
|
109
|
+
}
|
|
110
|
+
async function findStoredCandidate(dataDir, resourceId) {
|
|
111
|
+
for (const search of await loadSearches(dataDir)) {
|
|
112
|
+
const hit = search.candidates.find((c) => c.resourceId === resourceId);
|
|
113
|
+
if (hit) return hit;
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
async function findSearchForResource(dataDir, match) {
|
|
118
|
+
for (const search of await loadSearches(dataDir)) {
|
|
119
|
+
const hit = search.candidates.some(
|
|
120
|
+
(c) => match.resourceId !== void 0 && c.resourceId === match.resourceId || match.url !== void 0 && c.url === match.url
|
|
121
|
+
);
|
|
122
|
+
if (hit) return search.searchId;
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export {
|
|
128
|
+
loadSearches,
|
|
129
|
+
recordSearch,
|
|
130
|
+
markSearchResolved,
|
|
131
|
+
latestSearch,
|
|
132
|
+
findStoredCandidate,
|
|
133
|
+
findSearchForResource
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=chunk-5SE6BJRP.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\n/**\n * What closed an open loop. A MISS the agent acted on ends in exactly one of\n * these three, and the Stop hook stays quiet once any of them is recorded:\n * `outcome` (the loop was reported), `publish` (the answer went back to the\n * marketplace), `candidate` (the draft was parked to publish later).\n */\nexport const SearchResolutionSchema = z.enum(['outcome', 'publish', 'candidate']);\nexport type SearchResolution = z.infer<typeof SearchResolutionSchema>;\n\n/**\n * Who ran the search. `cli` is a deliberate `tenjin search`: the agent decided\n * the question was worth looking up, so an unanswered one is a strong signal.\n * `websearch-hook` is the PreToolUse hook riding along with a WebSearch the agent\n * was going to run anyway, which is a much weaker signal, because nobody judged\n * the question suitable for the marketplace before it was sent.\n *\n * The distinction exists because the Stop hook must not treat them alike: an\n * unanswered deliberate search deserves being named on its own, while a batch of\n * hook searches deserves one line the agent can dismiss at a glance. Keeping both\n * in ONE store is what makes the hook's misses reachable by explicit\n * `outcome --search-id`, `buy <resourceId>`, and the open-loop reminder at all\n * (`--last` deliberately skips hook entries; see {@link latestSearch}).\n *\n * OPTIONAL, and absent means `cli`: a store written by an earlier version has no\n * source field, and those entries were all explicit searches.\n */\nexport const SearchSourceSchema = z.enum(['cli', 'websearch-hook']);\nexport type SearchSource = z.infer<typeof SearchSourceSchema>;\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 /** Absent until something closes the loop; see {@link markSearchResolved}. */\n resolved: z.object({ by: SearchResolutionSchema, at: z.string() }).optional(),\n /** Absent on entries written before sources existed; see {@link SearchSourceSchema}. */\n source: SearchSourceSchema.optional(),\n // How many of the search's browse pointers cost money, and NOT the pointers\n // themselves: keeping them out of the store is what makes `buy <resourceId>`\n // unable to reach one (see the browse comment in agent-api.ts), and a count\n // cannot undo that. It exists so `outcome` can tell \"this search offered\n // nothing to buy\" from \"this search offered a payable browse tail\", which the\n // candidates array alone cannot say. Counts only PAID pointers because a\n // zero-priced piece is delivered by `read` with no purchase to decline.\n // Optional because entries written before this field existed have no answer,\n // and `undefined` must read as unknown rather than as zero.\n paidBrowseCount: z.number().int().nonnegative().optional(),\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\n/**\n * The store and its lock. Both paths are EXPORTED because the installed hook\n * scripts write this same file from outside the CLI process: they cannot import\n * this module, so they reimplement the lock protocol against this exact path.\n * Two writers of one file must at least agree on where the mutex lives, and a\n * test pins the script's protocol against this one.\n */\nexport function searchStorePath(dataDir: string): string {\n return join(dataDir, 'searches.json');\n}\n\nexport function searchStoreLockPath(dataDir: string): string {\n return `${searchStorePath(dataDir)}.lock`;\n}\n\nfunction storePath(dataDir: string): string {\n return searchStorePath(dataDir);\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\n/**\n * Record that something closed the loop on `searchId`, so the Stop hook stops\n * raising it. Best-effort in both directions and it NEVER throws: an unknown id\n * (the search aged past MAX_ENTRIES, or came from another machine) writes\n * nothing, and a failure to persist costs one stale nag rather than the command\n * the caller actually ran. The FIRST resolution wins, so a publish after an\n * outcome report does not rewrite who closed it.\n */\nexport async function markSearchResolved(\n dataDir: string,\n searchId: string,\n by: SearchResolution,\n at: string = new Date().toISOString(),\n): Promise<void> {\n try {\n const lockPath = `${storePath(dataDir)}.lock`;\n await withFileLock(lockPath, async () => {\n const existing = await loadSearches(dataDir);\n const target = existing.find((s) => s.searchId === searchId);\n if (target === undefined || target.resolved !== undefined) return;\n const searches = existing.map((s) =>\n s.searchId === searchId ? { ...s, resolved: { by, at } } : s,\n );\n await writeFileAtomic(\n storePath(dataDir),\n `${JSON.stringify({ schemaVersion: 1, searches }, null, 2)}\\n`,\n { mode: 0o644, dirMode: 0o700 },\n );\n });\n } catch {\n // Bookkeeping for a hook nudge. It must never fail the verb that ran.\n }\n}\n\n/**\n * The most recent DELIBERATE search: `--last` means \"the search I just ran\", and\n * in auto mode the WebSearch hook prepends a ridealong entry on every web search,\n * so an unfiltered head would routinely re-target `outcome --last` at a query the\n * agent never chose to make (found in dogfooding). Hook entries stay reachable by\n * explicit `--search-id`, which is what the Stop hook's reminder names.\n */\nexport async function latestSearch(dataDir: string): Promise<StoredSearch | null> {\n const searches = await loadSearches(dataDir);\n return searches.find((s) => s.source !== 'websearch-hook') ?? 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;AASM,IAAM,yBAAyB,iBAAE,KAAK,CAAC,WAAW,WAAW,WAAW,CAAC;AAoBzE,IAAM,qBAAqB,iBAAE,KAAK,CAAC,OAAO,gBAAgB,CAAC;AAGlE,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;AAAA;AAAA,EAEzC,UAAU,iBAAE,OAAO,EAAE,IAAI,wBAAwB,IAAI,iBAAE,OAAO,EAAE,CAAC,EAAE,SAAS;AAAA;AAAA,EAE5E,QAAQ,mBAAmB,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUpC,iBAAiB,iBAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS;AAC3D,CAAC;AAGD,IAAM,cAAc,iBAAE,OAAO;AAAA,EAC3B,eAAe,iBAAE,QAAQ,CAAC;AAAA,EAC1B,UAAU,iBAAE,MAAM,kBAAkB;AACtC,CAAC;AASM,SAAS,gBAAgB,SAAyB;AACvD,SAAO,KAAK,SAAS,eAAe;AACtC;AAMA,SAAS,UAAU,SA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AI,CAAC,MAC7B,EAAE,aAAa,WAAW,EAAE,GAAG,GAAG,UAAU,EAAE,IAAI,GAAG,EAAE,IAAI;AAAA,MAC7D;AACA,YAAM;AAAA,QACJ,UAAU,OAAO;AAAA,QACjB,GAAG,KAAK,UAAU,EAAE,eAAe,GAAG,SAAS,GAAG,MAAM,CAAC,CAAC;AAAA;AAAA,QAC1D,EAAE,MAAM,KAAO,SAAS,IAAM;AAAA,MAChC;AAAA,IACF,CAAC;AAAA,EACH,QAAQ;AAAA,EAER;AACF;AASA,eAAsB,aAAa,SAA+C;AAChF,QAAM,WAAW,MAAM,aAAa,OAAO;AAC3C,SAAO,SAAS,KAAK,CAAC,MAAM,EAAE,WAAW,gBAAgB,KAAK;AAChE;AAGA,eAAsB,oBACpB,SACA,YACiC;AACjC,aAAW,UAAU,MAAM,aAAa,OAAO,GAAG;AAChD,UAAM,MAAM,OAAO,WAAW,KAAK,CAAC,MAAM,EAAE,eAAe,UAAU;AACrE,QAAI,IAAK,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":[]}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
fetchRead
|
|
4
|
+
} from "./chunk-V4WWTZHZ.js";
|
|
5
|
+
import {
|
|
6
|
+
headingOutline
|
|
7
|
+
} from "./chunk-SGK2B724.js";
|
|
8
|
+
import {
|
|
9
|
+
resolveResourceRef
|
|
10
|
+
} from "./chunk-UOJRKQTZ.js";
|
|
11
|
+
import {
|
|
12
|
+
sanitizeForTerminal
|
|
13
|
+
} from "./chunk-R2VLGNFD.js";
|
|
14
|
+
import {
|
|
15
|
+
resolveContextSettings
|
|
16
|
+
} from "./chunk-BJJ5BQO6.js";
|
|
17
|
+
import {
|
|
18
|
+
toMoney
|
|
19
|
+
} from "./chunk-36X2CA3N.js";
|
|
20
|
+
|
|
21
|
+
// src/commands/inspect.ts
|
|
22
|
+
async function runInspect(args, ctx, deps = {}) {
|
|
23
|
+
const settings = await resolveContextSettings(ctx);
|
|
24
|
+
const ref = await resolveResourceRef(args.ref, ctx.dataDir, settings.baseUrl);
|
|
25
|
+
const result = await fetchRead(ref.url, {
|
|
26
|
+
timeoutMs: ctx.flags.timeout,
|
|
27
|
+
...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
|
|
28
|
+
});
|
|
29
|
+
if (result.kind === "entitled") {
|
|
30
|
+
const body = result.body;
|
|
31
|
+
return {
|
|
32
|
+
data: {
|
|
33
|
+
url: ref.url,
|
|
34
|
+
resourceId: body.id,
|
|
35
|
+
access: "free",
|
|
36
|
+
title: body.title,
|
|
37
|
+
price: toMoney(body.price),
|
|
38
|
+
headings: headingOutline(body.bodyMd),
|
|
39
|
+
// The free/owned half of the verb split (#42): delivery here costs nothing,
|
|
40
|
+
// so point at the free-only verb, not at the paying one. Machine consumers
|
|
41
|
+
// read this; the human line below says the same thing.
|
|
42
|
+
nextCommand: `tenjin read ${ref.url}`
|
|
43
|
+
},
|
|
44
|
+
humanLines: [
|
|
45
|
+
`${sanitizeForTerminal(body.title)}, free (${body.price} atomic). Read it with \`tenjin read ${sanitizeForTerminal(ref.url)}\`.`
|
|
46
|
+
]
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (result.kind === "payment_required") {
|
|
50
|
+
const requirement = result.paymentRequired.accepts[0];
|
|
51
|
+
const price = requirement !== void 0 ? toMoney(requirement.amount) : void 0;
|
|
52
|
+
const card = result.preview.card;
|
|
53
|
+
return {
|
|
54
|
+
data: {
|
|
55
|
+
url: ref.url,
|
|
56
|
+
...ref.resourceId !== void 0 ? { resourceId: ref.resourceId } : {},
|
|
57
|
+
access: "paid",
|
|
58
|
+
...price !== void 0 ? { price } : {},
|
|
59
|
+
payment: requirement !== void 0 ? {
|
|
60
|
+
scheme: requirement.scheme,
|
|
61
|
+
network: requirement.network,
|
|
62
|
+
asset: requirement.asset,
|
|
63
|
+
payTo: requirement.payTo,
|
|
64
|
+
amount: requirement.amount
|
|
65
|
+
} : void 0,
|
|
66
|
+
// The card stays where the wire puts it, inside `preview`, and is emitted
|
|
67
|
+
// exactly once: it is the largest object in this envelope, and a second
|
|
68
|
+
// hoisted copy would double every inspect payload to save one key of
|
|
69
|
+
// depth.
|
|
70
|
+
preview: result.preview,
|
|
71
|
+
...result.cardError === true ? { cardError: true } : {},
|
|
72
|
+
// Paid and unowned: this one really does cost money, so it keeps pointing at
|
|
73
|
+
// `buy`. `tenjin read` would refuse it with exit 3.
|
|
74
|
+
nextCommand: `tenjin buy ${ref.url}`
|
|
75
|
+
},
|
|
76
|
+
humanLines: [
|
|
77
|
+
`Paid resource${price !== void 0 ? `, ${price.usd} USD (${price.atomic} atomic)` : ""}.`,
|
|
78
|
+
...cardLines(card),
|
|
79
|
+
// Three distinct states behind an absent card, and they call for three
|
|
80
|
+
// different actions: the piece attests nothing (a signal, judge on that),
|
|
81
|
+
// the server could not load a card it has (transient, retry), or this CLI
|
|
82
|
+
// could not parse what arrived (a client-side bug or server drift). Only
|
|
83
|
+
// the last is ours. `cardUnavailable` is server-sent and never rides
|
|
84
|
+
// alongside a card, so it is only worth saying when there is no card.
|
|
85
|
+
...card === void 0 && result.preview.cardUnavailable === true ? ["The piece has a card the server could not load; retry later."] : [],
|
|
86
|
+
...result.cardError === true ? [
|
|
87
|
+
"The server sent an answer card this CLI could not parse; judging on price and preview only."
|
|
88
|
+
] : [],
|
|
89
|
+
"This is the pre-purchase card; run `tenjin buy` to pay and read (`tenjin read` refuses paid pieces)."
|
|
90
|
+
]
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
data: {
|
|
95
|
+
url: ref.url,
|
|
96
|
+
access: "entitled",
|
|
97
|
+
message: result.message,
|
|
98
|
+
nextCommand: `tenjin read ${ref.url}`
|
|
99
|
+
},
|
|
100
|
+
humanLines: [
|
|
101
|
+
`${sanitizeForTerminal(result.message)} Read it with \`tenjin read ${sanitizeForTerminal(ref.url)}\`.`
|
|
102
|
+
]
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
var CARD_BOUNDS = {
|
|
106
|
+
list: 10 * 200 + 9 * 2,
|
|
107
|
+
appliesTo: 8 * (32 + 1 + 20 * 120 + 19 * 2) + 7 * 2,
|
|
108
|
+
prose: 500,
|
|
109
|
+
cadence: 120,
|
|
110
|
+
// artifactType and temporalMode are open strings on the wire, so the composed
|
|
111
|
+
// freshness line gets a bound of its own rather than trusting them.
|
|
112
|
+
freshness: 200
|
|
113
|
+
};
|
|
114
|
+
var CLIP_MARKER = "...";
|
|
115
|
+
function cardLine(label, value, max) {
|
|
116
|
+
if (value === null) return [];
|
|
117
|
+
const text = sanitizeForTerminal(value).trim();
|
|
118
|
+
if (text.length === 0) return [];
|
|
119
|
+
return [`${label}: ${text.length > max ? `${text.slice(0, max)}${CLIP_MARKER}` : text}`];
|
|
120
|
+
}
|
|
121
|
+
function cardLines(card) {
|
|
122
|
+
if (card === void 0) return [];
|
|
123
|
+
const list = (items) => items.length > 0 ? items.join("; ") : null;
|
|
124
|
+
const appliesTo = Object.entries(card.appliesTo).map(
|
|
125
|
+
([key, values]) => `${key}=${values.join(", ")}`
|
|
126
|
+
);
|
|
127
|
+
return [
|
|
128
|
+
...cardLine("Answers", list(card.questionsAnswered), CARD_BOUNDS.list),
|
|
129
|
+
...cardLine("Tasks", list(card.tasksSupported), CARD_BOUNDS.list),
|
|
130
|
+
...cardLine("Applies to", list(appliesTo), CARD_BOUNDS.appliesTo),
|
|
131
|
+
...cardLine("Scope", card.scope, CARD_BOUNDS.prose),
|
|
132
|
+
...cardLine("Excludes", card.exclusions, CARD_BOUNDS.prose),
|
|
133
|
+
...cardLine("Freshness", freshness(card), CARD_BOUNDS.freshness),
|
|
134
|
+
...cardLine("Provenance", card.provenanceSummary, CARD_BOUNDS.prose),
|
|
135
|
+
...cardLine("Method", card.methodologySummary, CARD_BOUNDS.prose),
|
|
136
|
+
...cardLine("Maintenance", card.maintenanceCadence, CARD_BOUNDS.cadence)
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
function freshness(card) {
|
|
140
|
+
const parts = [card.artifactType, card.temporalMode].filter((s) => s.trim().length > 0);
|
|
141
|
+
if (card.asOf !== null) parts.push(`as of ${card.asOf}`);
|
|
142
|
+
if (card.validUntil !== null) parts.push(`valid until ${card.validUntil}`);
|
|
143
|
+
return parts.join(", ");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export {
|
|
147
|
+
runInspect
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=chunk-6BZLSRNU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/inspect.ts"],"sourcesContent":["import { resolveResourceRef } from '../lib/resource-ref';\nimport { resolveContextSettings } from '../lib/settings';\nimport { fetchRead, type PreviewCard } 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, and the answer card when the piece\n * carries one. Never signs, never pays, never saves.\n *\n * The card is the depth half of the search/inspect split: search v2 candidates are\n * lean, so this free call is where an agent gets what it answers, what it applies\n * to, what it excludes, and how it is dated, before spending anything.\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 // The free/owned half of the verb split (#42): delivery here costs nothing,\n // so point at the free-only verb, not at the paying one. Machine consumers\n // read this; the human line below says the same thing.\n nextCommand: `tenjin read ${ref.url}`,\n },\n humanLines: [\n `${sanitizeForTerminal(body.title)}, free (${body.price} atomic). Read it with \\`tenjin read ${sanitizeForTerminal(ref.url)}\\`.`,\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 const card = result.preview.card;\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 // The card stays where the wire puts it, inside `preview`, and is emitted\n // exactly once: it is the largest object in this envelope, and a second\n // hoisted copy would double every inspect payload to save one key of\n // depth.\n preview: result.preview,\n ...(result.cardError === true ? { cardError: true } : {}),\n // Paid and unowned: this one really does cost money, so it keeps pointing at\n // `buy`. `tenjin read` would refuse it with exit 3.\n nextCommand: `tenjin buy ${ref.url}`,\n },\n humanLines: [\n `Paid resource${price !== undefined ? `, ${price.usd} USD (${price.atomic} atomic)` : ''}.`,\n ...cardLines(card),\n // Three distinct states behind an absent card, and they call for three\n // different actions: the piece attests nothing (a signal, judge on that),\n // the server could not load a card it has (transient, retry), or this CLI\n // could not parse what arrived (a client-side bug or server drift). Only\n // the last is ours. `cardUnavailable` is server-sent and never rides\n // alongside a card, so it is only worth saying when there is no card.\n ...(card === undefined && result.preview.cardUnavailable === true\n ? ['The piece has a card the server could not load; retry later.']\n : []),\n ...(result.cardError === true\n ? [\n 'The server sent an answer card this CLI could not parse; judging on price and preview only.',\n ]\n : []),\n 'This is the pre-purchase card; run `tenjin buy` to pay and read (`tenjin read` refuses paid pieces).',\n ],\n };\n }\n\n // already_purchased without a payment header is unexpected; report it plainly.\n // Owned means delivery is free, so this branch points at `read` too.\n return {\n data: {\n url: ref.url,\n access: 'entitled',\n message: result.message,\n nextCommand: `tenjin read ${ref.url}`,\n },\n humanLines: [\n `${sanitizeForTerminal(result.message)} Read it with \\`tenjin read ${sanitizeForTerminal(ref.url)}\\`.`,\n ],\n };\n}\n\n/**\n * Per-line caps for the rendered card, each derived from the server's write-time\n * bound for that field, so a VALID card is never clipped: the two lists are 10\n * items x 200 chars joined with '; '; appliesTo is 8 keys (<=32 chars) x 20\n * values x 120 chars; the prose fields have a 500-char column bound and cadence\n * 120. Exceeding one means a server that broke its own bounds.\n *\n * When that happens the clip is MARKED. A silently shortened claim reads as a\n * whole one, and \"applies to Postgres 14, 15\" is a different promise from\n * \"applies to Postgres 14, 15, 16\". The `--json` payload stays verbatim either\n * way, because that copy is what an agent decides a non-refundable purchase on.\n */\nconst CARD_BOUNDS = {\n list: 10 * 200 + 9 * 2,\n appliesTo: 8 * (32 + 1 + 20 * 120 + 19 * 2) + 7 * 2,\n prose: 500,\n cadence: 120,\n // artifactType and temporalMode are open strings on the wire, so the composed\n // freshness line gets a bound of its own rather than trusting them.\n freshness: 200,\n} as const;\n\nconst CLIP_MARKER = '...';\n\nfunction cardLine(label: string, value: string | null, max: number): string[] {\n if (value === null) return [];\n const text = sanitizeForTerminal(value).trim();\n if (text.length === 0) return [];\n return [`${label}: ${text.length > max ? `${text.slice(0, max)}${CLIP_MARKER}` : text}`];\n}\n\n/**\n * The answer card off the 402 body, as human lines. This is the depth half of the\n * search/inspect split: search v2 returns lean hits, and the card an agent judges\n * fit on arrives here, for free. Empty when the piece carries no card, so an\n * uncarded inspect renders exactly as it did before.\n */\nfunction cardLines(card: PreviewCard | undefined): string[] {\n if (card === undefined) return [];\n const list = (items: string[]): string | null => (items.length > 0 ? items.join('; ') : null);\n const appliesTo = Object.entries(card.appliesTo).map(\n ([key, values]) => `${key}=${values.join(', ')}`,\n );\n return [\n ...cardLine('Answers', list(card.questionsAnswered), CARD_BOUNDS.list),\n ...cardLine('Tasks', list(card.tasksSupported), CARD_BOUNDS.list),\n ...cardLine('Applies to', list(appliesTo), CARD_BOUNDS.appliesTo),\n ...cardLine('Scope', card.scope, CARD_BOUNDS.prose),\n ...cardLine('Excludes', card.exclusions, CARD_BOUNDS.prose),\n ...cardLine('Freshness', freshness(card), CARD_BOUNDS.freshness),\n ...cardLine('Provenance', card.provenanceSummary, CARD_BOUNDS.prose),\n ...cardLine('Method', card.methodologySummary, CARD_BOUNDS.prose),\n ...cardLine('Maintenance', card.maintenanceCadence, CARD_BOUNDS.cadence),\n ];\n}\n\n/** Type, temporal mode and the two dates on one line: they answer the single\n * question a buyer asks of freshness, which is whether this is still true here.\n *\n * Both labels are open strings on the wire, so an empty one is dropped rather\n * than joined: otherwise the line leads with a comma and reads as a rendering\n * bug. All four empty yields '', and cardLine then omits the line entirely. */\nfunction freshness(card: PreviewCard): string {\n const parts = [card.artifactType, card.temporalMode].filter((s) => s.trim().length > 0);\n if (card.asOf !== null) parts.push(`as of ${card.asOf}`);\n if (card.validUntil !== null) parts.push(`valid until ${card.validUntil}`);\n return parts.join(', ');\n}\n"],"mappings":";;;;;;;;;;;;;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