tenjin-cli 0.1.0-alpha.10 → 0.1.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +236 -573
- package/dist/{buy-FMDBZ4NY.js → buy-3DTBFZ4B.js} +17 -17
- package/dist/{chunk-5SE6BJRP.js → chunk-4NTZETIL.js} +25 -2
- package/dist/chunk-4NTZETIL.js.map +1 -0
- package/dist/{chunk-TWRYSGAW.js → chunk-4TCU3YRD.js} +8 -12
- package/dist/chunk-4TCU3YRD.js.map +1 -0
- package/dist/{chunk-7WDY4AXV.js → chunk-6BGYHARE.js} +18 -18
- package/dist/{chunk-VRRLTZ2Q.js → chunk-6RMEX74N.js} +40 -17
- package/dist/chunk-6RMEX74N.js.map +1 -0
- package/dist/{chunk-UOJRKQTZ.js → chunk-6UY2UQMY.js} +3 -3
- package/dist/{chunk-AWQ6A4CI.js → chunk-7MJVNALU.js} +83 -72
- package/dist/chunk-7MJVNALU.js.map +1 -0
- package/dist/{chunk-36X2CA3N.js → chunk-ALUNME53.js} +1 -6
- package/dist/{chunk-36X2CA3N.js.map → chunk-ALUNME53.js.map} +1 -1
- package/dist/{chunk-BUDHTDKL.js → chunk-CBNXUQGM.js} +6 -6
- package/dist/{chunk-JSSIMGQT.js → chunk-CLOEU7RA.js} +27 -26
- package/dist/chunk-CLOEU7RA.js.map +1 -0
- package/dist/{chunk-GECSWJ7O.js → chunk-CNUXRXI2.js} +2 -2
- package/dist/chunk-E6YOODH7.js +913 -0
- package/dist/chunk-E6YOODH7.js.map +1 -0
- package/dist/{chunk-A6KCZPNQ.js → chunk-HWHYPCCH.js} +2 -2
- package/dist/{chunk-A6KCZPNQ.js.map → chunk-HWHYPCCH.js.map} +1 -1
- package/dist/{chunk-R2VLGNFD.js → chunk-IB63U6BM.js} +5 -1
- package/dist/chunk-IB63U6BM.js.map +1 -0
- package/dist/{chunk-ZUAQRIVP.js → chunk-ILDVGY7K.js} +64 -25
- package/dist/chunk-ILDVGY7K.js.map +1 -0
- package/dist/{chunk-BJJ5BQO6.js → chunk-JTYIX6OD.js} +3 -4
- package/dist/{chunk-6BZLSRNU.js → chunk-L3I2MVKR.js} +6 -6
- package/dist/{chunk-KYH4KPE5.js → chunk-MBKFZBB2.js} +26 -26
- package/dist/{chunk-5JXAZP7H.js → chunk-NUF2PKJO.js} +2 -1
- package/dist/{chunk-GSDZRCGF.js → chunk-OZHJ3FLR.js} +4 -4
- package/dist/{chunk-V4WWTZHZ.js → chunk-ROAK2DOX.js} +7 -7
- package/dist/{chunk-X3OOVSPX.js → chunk-RSBN67PA.js} +2 -4
- package/dist/{chunk-5JMKIDMM.js → chunk-SFGXAZ3M.js} +3 -3
- package/dist/{chunk-POF7HPRV.js → chunk-TDDN5GXR.js} +3 -3
- package/dist/{chunk-DKQMJTG7.js → chunk-TUXKOIOU.js} +14 -3
- package/dist/{chunk-DKQMJTG7.js.map → chunk-TUXKOIOU.js.map} +1 -1
- package/dist/{chunk-STND72DS.js → chunk-UFPJBS4C.js} +4 -4
- package/dist/chunk-UFPJBS4C.js.map +1 -0
- package/dist/{chunk-MD7WGYYI.js → chunk-V5UHKC46.js} +9 -9
- package/dist/chunk-V5UHKC46.js.map +1 -0
- package/dist/chunk-WWIKAJFO.js +235 -0
- package/dist/chunk-WWIKAJFO.js.map +1 -0
- package/dist/{chunk-O6CAUZGY.js → chunk-X2WZPGCF.js} +4 -4
- package/dist/{chunk-O6CAUZGY.js.map → chunk-X2WZPGCF.js.map} +1 -1
- package/dist/{cli-HK2XAWNW.js → cli-3WZGLZDP.js} +57 -60
- package/dist/{cli-HK2XAWNW.js.map → cli-3WZGLZDP.js.map} +1 -1
- package/dist/{config-LYCHHNAJ.js → config-WDGMZKHU.js} +4 -4
- package/dist/{doctor-2KPUQURC.js → doctor-EKVCP7JP.js} +9 -9
- package/dist/{edit-TST3OCKQ.js → edit-4UZQVFCK.js} +15 -15
- package/dist/fund-JAPOFTUG.js +38 -0
- package/dist/index.js +1 -1
- package/dist/{inspect-TPTHVPBB.js → inspect-IEV75A42.js} +13 -13
- package/dist/{install-PT3XEDJ6.js → install-WXTOHDWC.js} +88 -823
- package/dist/install-WXTOHDWC.js.map +1 -0
- package/dist/{outcome-NPNSF2Q7.js → outcome-FYOFDOUK.js} +9 -9
- package/dist/{publish-XP5SEWST.js → publish-6QNARH7E.js} +16 -17
- package/dist/{read-D4VXRWOG.js → read-UAZGZ4UL.js} +18 -18
- package/dist/{run-3IPGEXW7.js → run-AJNCOT5R.js} +71 -90
- package/dist/{run-3IPGEXW7.js.map → run-AJNCOT5R.js.map} +1 -1
- package/dist/{search-YOBD6VDI.js → search-EEKTW6VK.js} +10 -11
- package/dist/{send-BWNP6WN4.js → send-F34ZDXDZ.js} +5 -5
- package/dist/{session-GZEZBOMI.js → session-4N4ZT3AH.js} +13 -13
- package/dist/{skill-heal-OK6YALW6.js → skill-heal-XBEK272G.js} +3 -3
- package/dist/uninstall-BTKPHPDL.js +68 -0
- package/dist/uninstall-BTKPHPDL.js.map +1 -0
- package/dist/{wallet-YEGQBWWL.js → wallet-UL4P2JRO.js} +3 -3
- package/dist/{wallet-5RHDFPN2.js → wallet-WJ6UP5OU.js} +5 -5
- package/docs/agent-permissions.md +44 -31
- package/docs/command-reference.md +204 -0
- package/docs/safety-model.md +45 -0
- package/package.json +1 -1
- package/skills/tenjin/SKILL.md +3 -3
- package/skills/tenjin-publish/SKILL.md +55 -39
- package/skills/tenjin-search/SKILL.md +48 -41
- package/dist/candidate-7LAELUQD.js +0 -23
- package/dist/chunk-2GSRYTZS.js +0 -127
- package/dist/chunk-2GSRYTZS.js.map +0 -1
- package/dist/chunk-5SE6BJRP.js.map +0 -1
- package/dist/chunk-AWQ6A4CI.js.map +0 -1
- package/dist/chunk-JSSIMGQT.js.map +0 -1
- package/dist/chunk-MD7WGYYI.js.map +0 -1
- package/dist/chunk-R2VLGNFD.js.map +0 -1
- package/dist/chunk-STND72DS.js.map +0 -1
- package/dist/chunk-TEL27PR5.js +0 -124
- package/dist/chunk-TEL27PR5.js.map +0 -1
- package/dist/chunk-TWRYSGAW.js.map +0 -1
- package/dist/chunk-VRRLTZ2Q.js.map +0 -1
- package/dist/chunk-ZUAQRIVP.js.map +0 -1
- package/dist/install-PT3XEDJ6.js.map +0 -1
- /package/dist/{buy-FMDBZ4NY.js.map → buy-3DTBFZ4B.js.map} +0 -0
- /package/dist/{chunk-7WDY4AXV.js.map → chunk-6BGYHARE.js.map} +0 -0
- /package/dist/{chunk-UOJRKQTZ.js.map → chunk-6UY2UQMY.js.map} +0 -0
- /package/dist/{chunk-BUDHTDKL.js.map → chunk-CBNXUQGM.js.map} +0 -0
- /package/dist/{chunk-GECSWJ7O.js.map → chunk-CNUXRXI2.js.map} +0 -0
- /package/dist/{chunk-BJJ5BQO6.js.map → chunk-JTYIX6OD.js.map} +0 -0
- /package/dist/{chunk-6BZLSRNU.js.map → chunk-L3I2MVKR.js.map} +0 -0
- /package/dist/{chunk-KYH4KPE5.js.map → chunk-MBKFZBB2.js.map} +0 -0
- /package/dist/{chunk-5JXAZP7H.js.map → chunk-NUF2PKJO.js.map} +0 -0
- /package/dist/{chunk-GSDZRCGF.js.map → chunk-OZHJ3FLR.js.map} +0 -0
- /package/dist/{chunk-V4WWTZHZ.js.map → chunk-ROAK2DOX.js.map} +0 -0
- /package/dist/{chunk-X3OOVSPX.js.map → chunk-RSBN67PA.js.map} +0 -0
- /package/dist/{chunk-5JMKIDMM.js.map → chunk-SFGXAZ3M.js.map} +0 -0
- /package/dist/{chunk-POF7HPRV.js.map → chunk-TDDN5GXR.js.map} +0 -0
- /package/dist/{candidate-7LAELUQD.js.map → config-WDGMZKHU.js.map} +0 -0
- /package/dist/{config-LYCHHNAJ.js.map → doctor-EKVCP7JP.js.map} +0 -0
- /package/dist/{doctor-2KPUQURC.js.map → edit-4UZQVFCK.js.map} +0 -0
- /package/dist/{edit-TST3OCKQ.js.map → fund-JAPOFTUG.js.map} +0 -0
- /package/dist/{inspect-TPTHVPBB.js.map → inspect-IEV75A42.js.map} +0 -0
- /package/dist/{outcome-NPNSF2Q7.js.map → outcome-FYOFDOUK.js.map} +0 -0
- /package/dist/{publish-XP5SEWST.js.map → publish-6QNARH7E.js.map} +0 -0
- /package/dist/{read-D4VXRWOG.js.map → read-UAZGZ4UL.js.map} +0 -0
- /package/dist/{search-YOBD6VDI.js.map → search-EEKTW6VK.js.map} +0 -0
- /package/dist/{send-BWNP6WN4.js.map → send-F34ZDXDZ.js.map} +0 -0
- /package/dist/{session-GZEZBOMI.js.map → session-4N4ZT3AH.js.map} +0 -0
- /package/dist/{skill-heal-OK6YALW6.js.map → skill-heal-XBEK272G.js.map} +0 -0
- /package/dist/{wallet-5RHDFPN2.js.map → wallet-UL4P2JRO.js.map} +0 -0
- /package/dist/{wallet-YEGQBWWL.js.map → wallet-WJ6UP5OU.js.map} +0 -0
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
assertOnBaseOrigin
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-6UY2UQMY.js";
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
recordSearch
|
|
7
|
+
} from "./chunk-4NTZETIL.js";
|
|
8
8
|
import {
|
|
9
9
|
MAX_LIMIT,
|
|
10
10
|
buildSearchRequest,
|
|
11
11
|
postSearch
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import {
|
|
14
|
-
recordSearch
|
|
15
|
-
} from "./chunk-5SE6BJRP.js";
|
|
12
|
+
} from "./chunk-X2WZPGCF.js";
|
|
16
13
|
import {
|
|
17
14
|
sanitizeForTerminal
|
|
18
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-IB63U6BM.js";
|
|
19
16
|
import {
|
|
20
17
|
resolveContextSettings
|
|
21
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-JTYIX6OD.js";
|
|
22
19
|
import {
|
|
23
20
|
formatUsdDisplay,
|
|
24
21
|
isPaidPrice,
|
|
25
22
|
parseUsdToAtomic
|
|
26
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-ALUNME53.js";
|
|
27
24
|
import {
|
|
28
25
|
CliError
|
|
29
26
|
} from "./chunk-PZRAAAY2.js";
|
|
@@ -38,6 +35,7 @@ async function runSearch(args, ctx, deps = {}) {
|
|
|
38
35
|
if (args.appliesTo !== void 0 && args.appliesTo.length > 0) {
|
|
39
36
|
input.appliesTo = parseAppliesTo(args.appliesTo);
|
|
40
37
|
}
|
|
38
|
+
const sessionId = readSessionId(deps.env ?? process.env);
|
|
41
39
|
const request = buildSearchRequest(input);
|
|
42
40
|
const response = await postSearch(request, {
|
|
43
41
|
baseUrl: settings.baseUrl,
|
|
@@ -77,6 +75,9 @@ async function runSearch(args, ctx, deps = {}) {
|
|
|
77
75
|
// The Stop hook nags on the two differently, so the tag has to be written
|
|
78
76
|
// here rather than inferred later from anything.
|
|
79
77
|
source: "cli",
|
|
78
|
+
// Usually absent; see readSessionId. An unstamped entry is raised in every
|
|
79
|
+
// session, which is the safe direction for a reminder.
|
|
80
|
+
...sessionId !== void 0 ? { sessionId } : {},
|
|
80
81
|
candidates: candidates.map((c) => ({
|
|
81
82
|
resourceId: c.resourceId,
|
|
82
83
|
url: c.url,
|
|
@@ -94,7 +95,6 @@ async function runSearch(args, ctx, deps = {}) {
|
|
|
94
95
|
if (response.decision === "MISS") {
|
|
95
96
|
ctx.io.stderr.write(`${publishBackLine(response.searchId)}
|
|
96
97
|
`);
|
|
97
|
-
await emitCandidateNudge(ctx);
|
|
98
98
|
}
|
|
99
99
|
const browse = response.browse ?? [];
|
|
100
100
|
const browseHint = browse.length > 0 ? [
|
|
@@ -116,27 +116,28 @@ async function runSearch(args, ctx, deps = {}) {
|
|
|
116
116
|
const data = response.decision === "MISS" ? { ...response, publishBack: publishBackHint(response.searchId) } : response;
|
|
117
117
|
return { data, humanLines };
|
|
118
118
|
}
|
|
119
|
+
function readSessionId(env) {
|
|
120
|
+
return firstNonEmpty(env.TENJIN_SESSION_ID) ?? firstNonEmpty(env.CLAUDE_CODE_SESSION_ID);
|
|
121
|
+
}
|
|
122
|
+
function firstNonEmpty(raw) {
|
|
123
|
+
if (typeof raw !== "string") return void 0;
|
|
124
|
+
const trimmed = raw.trim();
|
|
125
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
126
|
+
}
|
|
119
127
|
function publishBackHint(searchId) {
|
|
120
128
|
return {
|
|
121
129
|
searchId,
|
|
122
130
|
reason: "Nothing on the marketplace answered this. If you solve it, publish it back.",
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
// Both arms carry the searchId, because both are commands to run verbatim and
|
|
132
|
+
// a publish without it leaves this very loop open (see publish's --search-id).
|
|
133
|
+
// The second arm is DECLINE, not park: nothing is saved to come back to, and
|
|
134
|
+
// reporting the outcome is what closes the loop so it never raises again.
|
|
135
|
+
publish: `tenjin publish <file.md> --json --search-id ${searchId}`,
|
|
136
|
+
decline: `tenjin outcome --search-id ${searchId} --status regenerated --json`
|
|
125
137
|
};
|
|
126
138
|
}
|
|
127
139
|
function publishBackLine(searchId) {
|
|
128
|
-
return `Nobody has published this yet - if you solve it, publish it back (tenjin publish)
|
|
129
|
-
}
|
|
130
|
-
var STALE_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
131
|
-
async function emitCandidateNudge(ctx) {
|
|
132
|
-
const records = await listCandidates(ctx.dataDir);
|
|
133
|
-
if (records.length === 0) return;
|
|
134
|
-
const now = Date.now();
|
|
135
|
-
const stale = records.filter((r) => now - Date.parse(r.meta.created) > STALE_MS).length;
|
|
136
|
-
ctx.io.stderr.write(
|
|
137
|
-
`${records.length} candidate(s) parked (${stale} stale >7d) - tenjin candidate list
|
|
138
|
-
`
|
|
139
|
-
);
|
|
140
|
+
return `Nobody has published this yet - if you solve it, publish it back (tenjin publish <file.md> --search-id ${searchId}); if you will not, close the loop: tenjin outcome --search-id ${searchId} --status regenerated`;
|
|
140
141
|
}
|
|
141
142
|
function parseLimit(raw) {
|
|
142
143
|
const n = Number(raw);
|
|
@@ -171,4 +172,4 @@ function parseAppliesTo(pairs) {
|
|
|
171
172
|
export {
|
|
172
173
|
runSearch
|
|
173
174
|
};
|
|
174
|
-
//# sourceMappingURL=chunk-
|
|
175
|
+
//# sourceMappingURL=chunk-CLOEU7RA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/search.ts"],"sourcesContent":["import { CliError } from '../lib/errors';\nimport { formatUsdDisplay, isPaidPrice, parseUsdToAtomic } from '../lib/money';\nimport { resolveContextSettings } from '../lib/settings';\nimport { buildSearchRequest, postSearch, MAX_LIMIT, type SearchInput } from '../lib/agent-api';\nimport { recordSearch } from '../lib/search-store';\nimport { assertOnBaseOrigin } from '../lib/resource-ref';\nimport { sanitizeForTerminal } from '../lib/output';\nimport type { CommandContext, CommandResult } from '../context';\n\n/**\n * `tenjin search \"<question>\"`, one POST to /api/agent/search. Prints the compact\n * CANDIDATES/MISS response (spec 10) and records the searchId + candidates\n * locally so `outcome --last` and `buy <resourceId>` can use them. No wallet, no\n * signing: search is anonymous.\n *\n * The machine envelope is the server's response verbatim plus exactly one\n * CLI-owned key, `publishBack`, and only on a MISS. It carries no server data: it\n * is the local searchId and the two commands that close the loop, which is\n * information the CLI owns and the contract does not describe.\n *\n * Search is the breadth step: a candidate is a lean hit (identity, price,\n * freshness, why it matched), and the full answer card comes from `tenjin inspect`,\n * which is free. So a candidate line stays short on purpose.\n *\n * The response's `searchId` is the outcome-reporting capability for\n * POST /api/searches/<searchId>/outcomes. tenjin#463 renamed the field (from\n * `lookupId`) and tenjin#616 dropped the `/agent` prefix from the path; this\n * client follows both end to end, so nothing on the wire or in the local store\n * still speaks `lookupId` or the prefixed spelling.\n */\n\nexport interface SearchArgs {\n question: string;\n /** Decimal USD at the edge (O1); converted to atomic for the wire. */\n maxPrice?: string;\n freshWithin?: string;\n limit?: string;\n /** Raw `k=v` / `k=v1,v2` pairs from repeated --applies-to. */\n appliesTo?: string[];\n}\n\nexport interface SearchDeps {\n fetchImpl?: typeof fetch;\n /** Environment seam (TENJIN_SESSION_ID); defaults to process.env. */\n env?: NodeJS.ProcessEnv;\n}\n\nexport async function runSearch(\n args: SearchArgs,\n ctx: CommandContext,\n deps: SearchDeps = {},\n): Promise<CommandResult> {\n const settings = await resolveContextSettings(ctx);\n const input: SearchInput = { question: args.question };\n if (args.maxPrice !== undefined) input.maxPrice = parseUsdToAtomic(args.maxPrice);\n if (args.freshWithin !== undefined) input.freshWithin = args.freshWithin;\n if (args.limit !== undefined) input.limit = parseLimit(args.limit);\n if (args.appliesTo !== undefined && args.appliesTo.length > 0) {\n input.appliesTo = parseAppliesTo(args.appliesTo);\n }\n\n const sessionId = readSessionId(deps.env ?? process.env);\n const request = buildSearchRequest(input);\n const response = await postSearch(request, {\n baseUrl: settings.baseUrl,\n timeoutMs: ctx.flags.timeout,\n evalCohort: settings.evalCohort,\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n });\n\n const candidates = response.candidates ?? [];\n // Ingest trust boundary: a candidate url that points off the configured origin\n // would later route a wallet-signed SIWX header and payment to that host via\n // `buy <resourceId>`. Refuse the whole response as a contract violation.\n for (const c of candidates) {\n try {\n assertOnBaseOrigin(c.url, settings.baseUrl, 'search candidate URL');\n } catch (err) {\n throw new CliError(\n 'CONTRACT_MISMATCH',\n `Search candidate ${c.resourceId} points off the configured base URL.`,\n { cause: err },\n );\n }\n }\n // Browse pointers are never buyable through `buy <resourceId>` (they are not\n // recorded), but their urls are still emitted into the agent's transcript, so\n // they get the same origin check rather than a weaker one.\n for (const b of response.browse ?? []) {\n try {\n assertOnBaseOrigin(b.url, settings.baseUrl, 'browse pointer URL');\n } catch (err) {\n throw new CliError(\n 'CONTRACT_MISMATCH',\n `Browse pointer ${b.resourceId} points off the configured base URL.`,\n { cause: err },\n );\n }\n }\n await recordSearch(ctx.dataDir, {\n searchId: response.searchId,\n at: new Date().toISOString(),\n question: request.question,\n decision: response.decision,\n // A deliberate search, as opposed to one the WebSearch hook rode along with.\n // The Stop hook nags on the two differently, so the tag has to be written\n // here rather than inferred later from anything.\n source: 'cli',\n // Usually absent; see readSessionId. An unstamped entry is raised in every\n // session, which is the safe direction for a reminder.\n ...(sessionId !== undefined ? { sessionId } : {}),\n candidates: candidates.map((c) => ({\n resourceId: c.resourceId,\n url: c.url,\n title: c.title,\n price: c.price,\n })),\n // The pointers stay unrecorded on purpose (see below); only how many of them\n // cost money, so `outcome` can tell a MISS that offered a payable browse tail\n // from one that offered nothing to buy. A zero-priced pointer does not count:\n // `read` delivers it for nothing, so there was no purchase to decline. Zero on\n // a CANDIDATES decision, where the contract carries no browse array and the\n // parser drops any that appears.\n paidBrowseCount: (response.browse ?? []).filter((b) => isPaidPrice(b.price) === true).length,\n });\n\n // One stderr line on a MISS (never in the machine JSON): a MISS is the moment\n // to publish the answer you are about to derive. There is deliberately no\n // second line about drafts waiting somewhere — a reminder that re-raises work\n // nobody chose to come back to is the class this CLI stopped emitting.\n if (response.decision === 'MISS') {\n ctx.io.stderr.write(`${publishBackLine(response.searchId)}\\n`);\n }\n\n // A MISS may carry up to 3 browse pointers from the broad corpus. They are\n // pointers, NOT candidates: rendered as ONE hint line with no scores and no\n // per-item detail, so a MISS still reads as a MISS and an agent is never\n // nudged to treat a browse pointer as an answer. The machine JSON keeps the\n // full `browse` array; this line is only the human tail.\n //\n // The price rides this line because a browse url IS payable: it is the read\n // endpoint that answers a 402, and `buy <url>` resolves the URL arm by origin\n // without consulting the search store, so a browse pointer can be bought even\n // though `buy <resourceId>` can never reach one. All spend gates (price cap,\n // session budget, allowlist, confirm) still run; showing the price keeps the\n // only human-visible surface from being a blind spend.\n //\n // It renders in DOLLARS, not atomic units, because the whole point of the line\n // is that a human can size the spend against the gates they set, and every gate\n // is entered in decimal USD (`--max-price 0.10`, the `maxAutoSpend` config).\n // `formatUsdDisplay` is the canonical human-copy form (always two decimals, so\n // a dime reads \"0.10\" and not \"0.1\"); the machine `browse` array in --json still\n // carries the exact atomic string, per the money-units contract in the README.\n const browse = response.browse ?? [];\n const browseHint =\n browse.length > 0\n ? [\n `no match, ${browse.length} piece(s) you could browse: ${browse\n .map((b) => `${sanitizeForTerminal(b.title)} (${formatUsdDisplay(b.price)} USD)`)\n .join('; ')}`,\n ]\n : [];\n\n // `truncated` means the server's size backstop dropped candidates, either a\n // trailing few the limit had room for or a single oversized one. The response\n // ceiling GROWS with the number of candidates returned (tenjin#501), so the\n // remedy is counter-intuitive and worth stating outright: a larger --limit\n // recovers the tail, a smaller one returns strictly fewer. Only at the maximum\n // is the tail unrecoverable and narrowing the question the answer.\n //\n // The CLI knows the limit it sent, so it names the next step instead of\n // restating the rule and leaving the reader to work out which half applies.\n // The flag stays in the machine envelope (--json) untouched, where it is\n // omitted rather than false when it did not fire.\n //\n // Rendering it on a MISS too is DEFENSIVE, not wire behavior: the server only\n // ever sets the flag alongside candidates it dropped. Handling both keeps the\n // flag from going unrendered if that ever changes.\n const truncatedHint =\n response.truncated === true\n ? [\n request.limit < MAX_LIMIT\n ? `some candidates were dropped for size; retry with --limit ${MAX_LIMIT} (the size ceiling grows with the number of candidates returned)`\n : `some candidates were dropped for size; at --limit ${MAX_LIMIT} the dropped tail cannot be recovered, so narrow the question`,\n ]\n : [];\n\n const humanLines =\n response.decision === 'MISS'\n ? [`MISS, no candidates (searchId ${response.searchId})`, ...browseHint, ...truncatedHint]\n : [\n `${candidates.length} candidate(s) (searchId ${response.searchId}):`,\n // Dollars for the same reason the browse hint uses them: this is the\n // human's cue to size the spend against gates they entered in decimal\n // USD. The machine `candidates` array in --json keeps atomic.\n ...candidates.map(\n (c, i) =>\n ` ${i + 1}. ${sanitizeForTerminal(c.title)}, ${formatUsdDisplay(c.price)} USD, ${sanitizeForTerminal(c.url)}`,\n ),\n ...truncatedHint,\n ];\n\n // The one CLI-owned field in this envelope. Everything else is the server's\n // response verbatim (spec 10), so the addition is namespaced under a key the\n // contract does not define and is present ONLY on a MISS: a MISS is the moment\n // the demand this searcher just expressed can still be met, and the searchId is\n // what ties the answer they are about to derive back to it. A CANDIDATES\n // response is byte-identical to what it was.\n const data =\n response.decision === 'MISS'\n ? { ...response, publishBack: publishBackHint(response.searchId) }\n : response;\n\n return { data, humanLines };\n}\n\n/**\n * The session to stamp this search with, so the Stop hook can tell one session's\n * open loops from a sibling's, or undefined when nothing can say.\n *\n * Two sources, in precedence order. TENJIN_SESSION_ID is the explicit operator\n * override and wins. CLAUDE_CODE_SESSION_ID is what Claude Code exports to Bash\n * tool subprocesses, which is what a `tenjin search` runs as; its value is the\n * same `session_id` the hook scripts are handed on stdin, so a CLI search and a\n * WebSearch-hook search in one session stamp identically. It is verified against\n * a live session rather than documented, hence the fallback rather than a\n * requirement: on a harness that does not export it this stays undefined, and\n * undefined is the safe answer — the hook raises an unstamped entry in every\n * session rather than in none.\n */\nfunction readSessionId(env: NodeJS.ProcessEnv): string | undefined {\n return firstNonEmpty(env.TENJIN_SESSION_ID) ?? firstNonEmpty(env.CLAUDE_CODE_SESSION_ID);\n}\n\nfunction firstNonEmpty(raw: string | undefined): string | undefined {\n if (typeof raw !== 'string') return undefined;\n const trimmed = raw.trim();\n return trimmed.length > 0 ? trimmed : undefined;\n}\n\n/** The publish-back hint, as machine fields rather than prose to re-parse. */\nfunction publishBackHint(searchId: string): {\n searchId: string;\n reason: string;\n publish: string;\n decline: string;\n} {\n return {\n searchId,\n reason: 'Nothing on the marketplace answered this. If you solve it, publish it back.',\n // Both arms carry the searchId, because both are commands to run verbatim and\n // a publish without it leaves this very loop open (see publish's --search-id).\n // The second arm is DECLINE, not park: nothing is saved to come back to, and\n // reporting the outcome is what closes the loop so it never raises again.\n publish: `tenjin publish <file.md> --json --search-id ${searchId}`,\n decline: `tenjin outcome --search-id ${searchId} --status regenerated --json`,\n };\n}\n\n/** The same hint as one stderr line for a human. */\nfunction publishBackLine(searchId: string): string {\n return `Nobody has published this yet - if you solve it, publish it back (tenjin publish <file.md> --search-id ${searchId}); if you will not, close the loop: tenjin outcome --search-id ${searchId} --status regenerated`;\n}\n\nfunction parseLimit(raw: string): number {\n const n = Number(raw);\n if (!Number.isInteger(n)) {\n throw new CliError('USAGE', `Invalid --limit: ${JSON.stringify(raw)}`, {\n fix: 'Pass an integer between 1 and 10.',\n });\n }\n return n;\n}\n\n/** `products=Vercel` or `products=Vercel,Next` → { products: [\"Vercel\",\"Next\"] }. Repeated\n * keys merge their values. */\nfunction parseAppliesTo(pairs: string[]): Record<string, string[]> {\n const out: Record<string, string[]> = {};\n for (const pair of pairs) {\n const eq = pair.indexOf('=');\n if (eq <= 0) {\n throw new CliError('USAGE', `Invalid --applies-to: ${JSON.stringify(pair)}`, {\n fix: 'Use key=value, e.g. --applies-to products=Vercel.',\n });\n }\n const key = pair.slice(0, eq).trim();\n const values = pair\n .slice(eq + 1)\n .split(',')\n .map((v) => v.trim())\n .filter((v) => v.length > 0);\n if (values.length === 0) {\n throw new CliError('USAGE', `--applies-to ${JSON.stringify(key)} has no values`, {\n fix: 'Give each key at least one value, e.g. products=Vercel.',\n });\n }\n out[key] = [...(out[key] ?? []), ...values];\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,eAAsB,UACpB,MACA,KACA,OAAmB,CAAC,GACI;AACxB,QAAM,WAAW,MAAM,uBAAuB,GAAG;AACjD,QAAM,QAAqB,EAAE,UAAU,KAAK,SAAS;AACrD,MAAI,KAAK,aAAa,OAAW,OAAM,WAAW,iBAAiB,KAAK,QAAQ;AAChF,MAAI,KAAK,gBAAgB,OAAW,OAAM,cAAc,KAAK;AAC7D,MAAI,KAAK,UAAU,OAAW,OAAM,QAAQ,WAAW,KAAK,KAAK;AACjE,MAAI,KAAK,cAAc,UAAa,KAAK,UAAU,SAAS,GAAG;AAC7D,UAAM,YAAY,eAAe,KAAK,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,QAAI,GAAG,IAAI,CAAC,GAAI,IAAI,GAAG,KAAK,CAAC,GAAI,GAAG,MAAM;AAAA,EAC5C;AACA,SAAO;AACT;","names":[]}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "./chunk-Y7ERTA7D.js";
|
|
9
9
|
import {
|
|
10
10
|
emitNotice
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-IB63U6BM.js";
|
|
12
12
|
import {
|
|
13
13
|
evaluateSpendPolicy,
|
|
14
14
|
withFileLock
|
|
@@ -1642,4 +1642,4 @@ export {
|
|
|
1642
1642
|
@noble/ciphers/esm/utils.js:
|
|
1643
1643
|
(*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
|
|
1644
1644
|
*/
|
|
1645
|
-
//# sourceMappingURL=chunk-
|
|
1645
|
+
//# sourceMappingURL=chunk-CNUXRXI2.js.map
|