tenjin-cli 0.1.0-alpha.14 → 0.1.0-alpha.15
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 +18 -3
- package/dist/{buy-2JBYPHAI.js → buy-VIRNSYGN.js} +24 -23
- package/dist/{chunk-QWBUKIP2.js → chunk-2MYQN7HM.js} +66 -27
- package/dist/chunk-2MYQN7HM.js.map +1 -0
- package/dist/{chunk-DAZAXFSF.js → chunk-2RF2GIJQ.js} +57 -226
- package/dist/chunk-2RF2GIJQ.js.map +1 -0
- package/dist/{chunk-VEAERJVJ.js → chunk-3GL2Z5QK.js} +23 -9
- package/dist/chunk-3GL2Z5QK.js.map +1 -0
- package/dist/{chunk-IUQZ4Z7M.js → chunk-4CQIDQOT.js} +6 -1
- package/dist/chunk-4CQIDQOT.js.map +1 -0
- package/dist/{chunk-IXZJ3JOO.js → chunk-4KG27W2S.js} +10 -10
- package/dist/chunk-4KG27W2S.js.map +1 -0
- package/dist/{chunk-54AJIO3E.js → chunk-5QQTYWEU.js} +4 -3
- package/dist/chunk-5QQTYWEU.js.map +1 -0
- package/dist/chunk-65DTCCJ7.js +21 -0
- package/dist/chunk-65DTCCJ7.js.map +1 -0
- package/dist/{chunk-7NADDA2V.js → chunk-A5DKHMUN.js} +20 -8
- package/dist/chunk-A5DKHMUN.js.map +1 -0
- package/dist/{chunk-WYLMJQVH.js → chunk-B63XPWQ4.js} +24 -18
- package/dist/chunk-B63XPWQ4.js.map +1 -0
- package/dist/{chunk-L6G35FU5.js → chunk-CAR6FHK6.js} +5 -5
- package/dist/{chunk-7GJQ5RGA.js → chunk-CPCX67TI.js} +20 -22
- package/dist/{chunk-7GJQ5RGA.js.map → chunk-CPCX67TI.js.map} +1 -1
- package/dist/{chunk-XVPQGCH4.js → chunk-CQBVCYI2.js} +36 -50
- package/dist/chunk-CQBVCYI2.js.map +1 -0
- package/dist/chunk-DBU5CXBV.js +4731 -0
- package/dist/chunk-DBU5CXBV.js.map +1 -0
- package/dist/chunk-DHJD77OW.js +81 -0
- package/dist/chunk-DHJD77OW.js.map +1 -0
- package/dist/{chunk-XGZ5EVMB.js → chunk-EDZSNPE5.js} +2 -2
- package/dist/{chunk-736DW4V3.js → chunk-EFWZPUTC.js} +2 -2
- package/dist/chunk-EPFL6CTE.js +448 -0
- package/dist/chunk-EPFL6CTE.js.map +1 -0
- package/dist/{chunk-3P3ES4XU.js → chunk-GHLVXVZD.js} +3 -5
- package/dist/{chunk-3P3ES4XU.js.map → chunk-GHLVXVZD.js.map} +1 -1
- package/dist/{chunk-4UHNXY6B.js → chunk-H3SOOJ2I.js} +88 -294
- package/dist/chunk-H3SOOJ2I.js.map +1 -0
- package/dist/{chunk-MJSXP4LW.js → chunk-HPJGOLTN.js} +6 -8
- package/dist/{chunk-MJSXP4LW.js.map → chunk-HPJGOLTN.js.map} +1 -1
- package/dist/{chunk-J6FUAIRR.js → chunk-HRGBS2PA.js} +4 -6
- package/dist/{chunk-J6FUAIRR.js.map → chunk-HRGBS2PA.js.map} +1 -1
- package/dist/{chunk-FDUD3W5V.js → chunk-ITUXPJIS.js} +55 -58
- package/dist/chunk-ITUXPJIS.js.map +1 -0
- package/dist/{chunk-ETKZWJ4B.js → chunk-JBIKAAT3.js} +2 -2
- package/dist/{chunk-ETKZWJ4B.js.map → chunk-JBIKAAT3.js.map} +1 -1
- package/dist/{chunk-3ZW7HPY5.js → chunk-KAJZHIQ4.js} +13 -10
- package/dist/chunk-KAJZHIQ4.js.map +1 -0
- package/dist/{chunk-OWVVI4VQ.js → chunk-KINZ23CV.js} +107 -4535
- package/dist/chunk-KINZ23CV.js.map +1 -0
- package/dist/{chunk-PCX2JQ2J.js → chunk-LRYV3SK7.js} +9 -7
- package/dist/{chunk-PCX2JQ2J.js.map → chunk-LRYV3SK7.js.map} +1 -1
- package/dist/{chunk-ACBEHJAH.js → chunk-NIKXHWOL.js} +11 -13
- package/dist/{chunk-ACBEHJAH.js.map → chunk-NIKXHWOL.js.map} +1 -1
- package/dist/chunk-OKDRDT74.js +209 -0
- package/dist/chunk-OKDRDT74.js.map +1 -0
- package/dist/chunk-OKYSNAS3.js +2144 -0
- package/dist/chunk-OKYSNAS3.js.map +1 -0
- package/dist/{chunk-B676GPS2.js → chunk-OLWTRUTS.js} +7 -3
- package/dist/{chunk-B676GPS2.js.map → chunk-OLWTRUTS.js.map} +1 -1
- package/dist/{chunk-WU5CZPLD.js → chunk-QQ6ELLSA.js} +6 -8
- package/dist/{chunk-WU5CZPLD.js.map → chunk-QQ6ELLSA.js.map} +1 -1
- package/dist/{chunk-NAAMHWSI.js → chunk-QZ6ROAJU.js} +5 -4
- package/dist/chunk-QZ6ROAJU.js.map +1 -0
- package/dist/{chunk-GEHL43VE.js → chunk-R7RSCBI7.js} +130 -47
- package/dist/chunk-R7RSCBI7.js.map +1 -0
- package/dist/{chunk-LSWP7MU2.js → chunk-U6VPKMGC.js} +127 -27
- package/dist/chunk-U6VPKMGC.js.map +1 -0
- package/dist/{chunk-W4VW5XYB.js → chunk-US456VUI.js} +6 -6
- package/dist/{chunk-O75FOHXS.js → chunk-V44J2MXV.js} +64 -36
- package/dist/chunk-V44J2MXV.js.map +1 -0
- package/dist/{chunk-4Y53PDH6.js → chunk-VJQKL3YH.js} +10 -7
- package/dist/{chunk-4Y53PDH6.js.map → chunk-VJQKL3YH.js.map} +1 -1
- package/dist/{chunk-VRPLZERE.js → chunk-VJSQSLBM.js} +47 -26
- package/dist/chunk-VJSQSLBM.js.map +1 -0
- package/dist/{chunk-PKW3H26Z.js → chunk-VYOJOX4Z.js} +9 -7
- package/dist/chunk-VYOJOX4Z.js.map +1 -0
- package/dist/chunk-WY2K35OL.js +269 -0
- package/dist/chunk-WY2K35OL.js.map +1 -0
- package/dist/{chunk-PAOVPSP6.js → chunk-ZFJJ3EXC.js} +53 -5
- package/dist/chunk-ZFJJ3EXC.js.map +1 -0
- package/dist/{cli-U2BEUA55.js → cli-KKRKBU5T.js} +71 -40
- package/dist/{cli-U2BEUA55.js.map → cli-KKRKBU5T.js.map} +1 -1
- package/dist/config-JMRUNYE6.js +37 -0
- package/dist/discover-B5HF6SHM.js +102 -0
- package/dist/discover-B5HF6SHM.js.map +1 -0
- package/dist/doctor-ZBG7X66D.js +32 -0
- package/dist/edit-PZJIILQE.js +40 -0
- package/dist/{fund-Y5IAHZ5D.js → fund-EUDH5KPA.js} +19 -19
- package/dist/index.js +1 -1
- package/dist/{inspect-NFQ6SQQQ.js → inspect-QC6WEQPN.js} +20 -20
- package/dist/{install-DXX7PVUP.js → install-GNK2W3PI.js} +196 -78
- package/dist/install-GNK2W3PI.js.map +1 -0
- package/dist/outcome-KSGWZHUS.js +24 -0
- package/dist/pay-BC4UICPA.js +361 -0
- package/dist/pay-BC4UICPA.js.map +1 -0
- package/dist/publish-LXWFDIKF.js +42 -0
- package/dist/{read-W7QVRBVD.js → read-JMNUQ56P.js} +21 -21
- package/dist/{run-CJWPGMIQ.js → run-XYTQ5TWQ.js} +52 -45
- package/dist/{run-CJWPGMIQ.js.map → run-XYTQ5TWQ.js.map} +1 -1
- package/dist/search-TSQAB45E.js +25 -0
- package/dist/{send-C5EOKXOU.js → send-G746D7PQ.js} +14 -15
- package/dist/{send-C5EOKXOU.js.map → send-G746D7PQ.js.map} +1 -1
- package/dist/{session-OBCUUIFX.js → session-JBKWMJ24.js} +17 -17
- package/dist/{skill-heal-D6EPLPS6.js → skill-heal-WKD67SLJ.js} +17 -9
- package/dist/skill-heal-WKD67SLJ.js.map +1 -0
- package/dist/skill-placement-RIU4AMC2.js +20 -0
- package/dist/{uninstall-OWJNJ5LI.js → uninstall-5E263VTS.js} +12 -12
- package/dist/uninstall-5E263VTS.js.map +1 -0
- package/dist/{update-24Y2CQTT.js → update-R76LHOZW.js} +7 -8
- package/dist/{update-24Y2CQTT.js.map → update-R76LHOZW.js.map} +1 -1
- package/dist/{wallet-SLRIYJ2U.js → wallet-TQ7D5EQ7.js} +7 -8
- package/dist/{wallet-OFXDIIGP.js → wallet-ZAVXWLWP.js} +11 -12
- package/dist/wallet-ZAVXWLWP.js.map +1 -0
- package/docs/agent-permissions.md +17 -2
- package/docs/command-reference.md +84 -42
- package/docs/safety-model.md +9 -0
- package/package.json +1 -1
- package/skills/tenjin/SKILL.md +38 -29
- package/skills/tenjin-pay/SKILL.md +76 -0
- package/skills/tenjin-publish/SKILL.md +10 -7
- package/skills/tenjin-search/SKILL.md +18 -13
- package/skills/tenjin-search/references/permissions.md +9 -3
- package/dist/chunk-3ZW7HPY5.js.map +0 -1
- package/dist/chunk-4UHNXY6B.js.map +0 -1
- package/dist/chunk-54AJIO3E.js.map +0 -1
- package/dist/chunk-7NADDA2V.js.map +0 -1
- package/dist/chunk-DAZAXFSF.js.map +0 -1
- package/dist/chunk-DTCXO7HS.js +0 -791
- package/dist/chunk-DTCXO7HS.js.map +0 -1
- package/dist/chunk-FDUD3W5V.js.map +0 -1
- package/dist/chunk-GEHL43VE.js.map +0 -1
- package/dist/chunk-IU2HVT3Y.js +0 -313
- package/dist/chunk-IU2HVT3Y.js.map +0 -1
- package/dist/chunk-IUQZ4Z7M.js.map +0 -1
- package/dist/chunk-IXZJ3JOO.js.map +0 -1
- package/dist/chunk-LSWP7MU2.js.map +0 -1
- package/dist/chunk-NAAMHWSI.js.map +0 -1
- package/dist/chunk-O75FOHXS.js.map +0 -1
- package/dist/chunk-OWVVI4VQ.js.map +0 -1
- package/dist/chunk-PAOVPSP6.js.map +0 -1
- package/dist/chunk-PKW3H26Z.js.map +0 -1
- package/dist/chunk-PQZVDCCA.js +0 -125
- package/dist/chunk-PQZVDCCA.js.map +0 -1
- package/dist/chunk-QWBUKIP2.js.map +0 -1
- package/dist/chunk-VEAERJVJ.js.map +0 -1
- package/dist/chunk-VRPLZERE.js.map +0 -1
- package/dist/chunk-WYLMJQVH.js.map +0 -1
- package/dist/chunk-XVPQGCH4.js.map +0 -1
- package/dist/chunk-ZQIQ55KK.js +0 -51
- package/dist/chunk-ZQIQ55KK.js.map +0 -1
- package/dist/config-CNUIX23Q.js +0 -32
- package/dist/doctor-QJJXRWTO.js +0 -31
- package/dist/edit-HJ44P44P.js +0 -40
- package/dist/install-DXX7PVUP.js.map +0 -1
- package/dist/outcome-ANV4QIED.js +0 -24
- package/dist/publish-PCBTCXCZ.js +0 -42
- package/dist/search-JGAVKTYJ.js +0 -25
- package/dist/skill-heal-D6EPLPS6.js.map +0 -1
- package/dist/uninstall-OWJNJ5LI.js.map +0 -1
- /package/dist/{buy-2JBYPHAI.js.map → buy-VIRNSYGN.js.map} +0 -0
- /package/dist/{chunk-L6G35FU5.js.map → chunk-CAR6FHK6.js.map} +0 -0
- /package/dist/{chunk-XGZ5EVMB.js.map → chunk-EDZSNPE5.js.map} +0 -0
- /package/dist/{chunk-736DW4V3.js.map → chunk-EFWZPUTC.js.map} +0 -0
- /package/dist/{chunk-W4VW5XYB.js.map → chunk-US456VUI.js.map} +0 -0
- /package/dist/{config-CNUIX23Q.js.map → config-JMRUNYE6.js.map} +0 -0
- /package/dist/{doctor-QJJXRWTO.js.map → doctor-ZBG7X66D.js.map} +0 -0
- /package/dist/{edit-HJ44P44P.js.map → edit-PZJIILQE.js.map} +0 -0
- /package/dist/{fund-Y5IAHZ5D.js.map → fund-EUDH5KPA.js.map} +0 -0
- /package/dist/{inspect-NFQ6SQQQ.js.map → inspect-QC6WEQPN.js.map} +0 -0
- /package/dist/{outcome-ANV4QIED.js.map → outcome-KSGWZHUS.js.map} +0 -0
- /package/dist/{publish-PCBTCXCZ.js.map → publish-LXWFDIKF.js.map} +0 -0
- /package/dist/{read-W7QVRBVD.js.map → read-JMNUQ56P.js.map} +0 -0
- /package/dist/{search-JGAVKTYJ.js.map → search-TSQAB45E.js.map} +0 -0
- /package/dist/{session-OBCUUIFX.js.map → session-JBKWMJ24.js.map} +0 -0
- /package/dist/{wallet-OFXDIIGP.js.map → skill-placement-RIU4AMC2.js.map} +0 -0
- /package/dist/{wallet-SLRIYJ2U.js.map → wallet-TQ7D5EQ7.js.map} +0 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
ownedByThisSession,
|
|
4
|
+
readSessionId
|
|
5
|
+
} from "./chunk-65DTCCJ7.js";
|
|
6
|
+
import {
|
|
7
|
+
buildOutcomeItem,
|
|
8
|
+
postOutcomes
|
|
9
|
+
} from "./chunk-ITUXPJIS.js";
|
|
10
|
+
import {
|
|
11
|
+
sanitizeForTerminal
|
|
12
|
+
} from "./chunk-OLWTRUTS.js";
|
|
13
|
+
import {
|
|
14
|
+
resolveContextSettings
|
|
15
|
+
} from "./chunk-VYOJOX4Z.js";
|
|
16
|
+
import {
|
|
17
|
+
UUID_RE,
|
|
18
|
+
isPaidPrice
|
|
19
|
+
} from "./chunk-EFWZPUTC.js";
|
|
20
|
+
import {
|
|
21
|
+
latestSearch,
|
|
22
|
+
loadSearches,
|
|
23
|
+
markSearchResolved
|
|
24
|
+
} from "./chunk-A5DKHMUN.js";
|
|
25
|
+
import {
|
|
26
|
+
CliError
|
|
27
|
+
} from "./chunk-ZFJJ3EXC.js";
|
|
28
|
+
|
|
29
|
+
// src/commands/outcome.ts
|
|
30
|
+
var HALTING_FAILURES = /* @__PURE__ */ new Set(["RATE_LIMITED", "NETWORK_ERROR"]);
|
|
31
|
+
async function runOutcome(args, ctx, deps = {}) {
|
|
32
|
+
const { targets, deliberateLeftOpen, answeredLeftOpen } = await resolveTargets(args, ctx, deps);
|
|
33
|
+
const item = buildOutcomeItem({
|
|
34
|
+
status: args.status,
|
|
35
|
+
...args.resource !== void 0 ? { resourceId: args.resource } : {},
|
|
36
|
+
...args.contentHash !== void 0 ? { contentHash: args.contentHash } : {}
|
|
37
|
+
});
|
|
38
|
+
if (item.resourceId !== void 0 && (targets.length > 1 || args.allOpen === true)) {
|
|
39
|
+
throw new CliError(
|
|
40
|
+
"USAGE",
|
|
41
|
+
"A --resource names one search's candidate, so it cannot describe a batch.",
|
|
42
|
+
{ fix: "Report the resource against its own search with a single --search-id <id>." }
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
for (const target of targets) {
|
|
46
|
+
assertReportableId(target.searchId);
|
|
47
|
+
if (target.stored !== null) assertOutcomeCoherent(item.status, target.stored, item.resourceId);
|
|
48
|
+
}
|
|
49
|
+
const settings = await resolveContextSettings(ctx);
|
|
50
|
+
const reports = [];
|
|
51
|
+
let halted = false;
|
|
52
|
+
for (const target of targets) {
|
|
53
|
+
const question = target.stored !== null ? echoQuestion(target.stored.question) : void 0;
|
|
54
|
+
if (halted) {
|
|
55
|
+
reports.push({ searchId: target.searchId, accepted: 0, untouched: true });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const result = await postOutcomes(target.searchId, [item], {
|
|
60
|
+
baseUrl: settings.baseUrl,
|
|
61
|
+
timeoutMs: ctx.flags.timeout,
|
|
62
|
+
...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
|
|
63
|
+
});
|
|
64
|
+
await markSearchResolved(ctx.dataDir, target.searchId, "outcome");
|
|
65
|
+
reports.push({
|
|
66
|
+
searchId: target.searchId,
|
|
67
|
+
accepted: result.accepted,
|
|
68
|
+
...question !== void 0 ? { question } : {}
|
|
69
|
+
});
|
|
70
|
+
} catch (err) {
|
|
71
|
+
if (targets.length === 1) throw err;
|
|
72
|
+
const error = describeFailure(err);
|
|
73
|
+
halted = HALTING_FAILURES.has(error.code);
|
|
74
|
+
reports.push({
|
|
75
|
+
searchId: target.searchId,
|
|
76
|
+
accepted: 0,
|
|
77
|
+
...question !== void 0 ? { question } : {},
|
|
78
|
+
error
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const failed = reports.filter((r) => r.error !== void 0);
|
|
83
|
+
const untouched = reports.filter((r) => r.untouched === true);
|
|
84
|
+
const closed = reports.length - failed.length - untouched.length;
|
|
85
|
+
const humanLines = reports.filter((r) => r.error === void 0 && r.untouched !== true).map((r) => reportLine(item.status, r));
|
|
86
|
+
if (targets.length === 0) humanLines.push("No open web-search loops in this session.");
|
|
87
|
+
humanLines.push(...leftOpenLines(deliberateLeftOpen, answeredLeftOpen));
|
|
88
|
+
if (failed.length > 0) {
|
|
89
|
+
const remainder = untouched.length > 0 ? `, ${untouched.length} left untouched` : "";
|
|
90
|
+
throw new CliError(
|
|
91
|
+
failureCode(failed),
|
|
92
|
+
`Reported ${item.status} for ${closed} of ${reports.length} searches; ${failed.length} failed${remainder}.`,
|
|
93
|
+
{
|
|
94
|
+
// In `fix`, not just `details`: the renderer drops other shapes.
|
|
95
|
+
fix: `Retry with ${retryFlags(failed.concat(untouched))}`,
|
|
96
|
+
details: { status: item.status, closed, results: reports }
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
// Flat fields repeat a lone result, so data.searchId still reads.
|
|
102
|
+
data: {
|
|
103
|
+
status: item.status,
|
|
104
|
+
closed,
|
|
105
|
+
results: reports,
|
|
106
|
+
...deliberateLeftOpen > 0 ? { deliberateLeftOpen } : {},
|
|
107
|
+
...answeredLeftOpen > 0 ? { answeredLeftOpen } : {},
|
|
108
|
+
...reports.length === 1 ? flatten(reports[0]) : {}
|
|
109
|
+
},
|
|
110
|
+
humanLines
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function leftOpenLines(deliberate, answered) {
|
|
114
|
+
const lines = [];
|
|
115
|
+
if (deliberate > 0) {
|
|
116
|
+
lines.push(`${deliberate} deliberate search(es) left open; close each with --search-id <id>.`);
|
|
117
|
+
}
|
|
118
|
+
if (answered > 0) {
|
|
119
|
+
lines.push(
|
|
120
|
+
`${answered} hook search(es) Tenjin answered left open; report each with --search-id <id>.`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return lines;
|
|
124
|
+
}
|
|
125
|
+
function failureCode(failed) {
|
|
126
|
+
const codes = new Set(failed.map((r) => r.error?.code));
|
|
127
|
+
if (codes.size !== 1) return "API_UNREACHABLE";
|
|
128
|
+
const [only] = [...codes];
|
|
129
|
+
if (only === "USAGE") return "USAGE";
|
|
130
|
+
return only === "RATE_LIMITED" ? "RATE_LIMITED" : "API_UNREACHABLE";
|
|
131
|
+
}
|
|
132
|
+
function retryFlags(pending) {
|
|
133
|
+
const MAX_NAMED = 5;
|
|
134
|
+
const named = pending.slice(0, MAX_NAMED).map((r) => `--search-id ${r.searchId}`);
|
|
135
|
+
const rest = pending.length - named.length;
|
|
136
|
+
return rest > 0 ? `${named.join(" ")} (and ${rest} more, see results)` : named.join(" ");
|
|
137
|
+
}
|
|
138
|
+
function flatten(report) {
|
|
139
|
+
return {
|
|
140
|
+
searchId: report.searchId,
|
|
141
|
+
accepted: report.accepted,
|
|
142
|
+
...report.question !== void 0 ? { question: report.question } : {}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function reportLine(status, report) {
|
|
146
|
+
const question = report.question !== void 0 ? ` "${sanitizeForTerminal(report.question)}"` : "";
|
|
147
|
+
return `Reported ${status} for search ${report.searchId}${question} (accepted ${report.accepted}).`;
|
|
148
|
+
}
|
|
149
|
+
function describeFailure(err) {
|
|
150
|
+
if (err instanceof CliError) return { code: err.code, message: err.message };
|
|
151
|
+
return { code: "INTERNAL", message: err instanceof Error ? err.message : String(err) };
|
|
152
|
+
}
|
|
153
|
+
function assertReportableId(searchId) {
|
|
154
|
+
if (UUID_RE.test(searchId)) return;
|
|
155
|
+
throw new CliError("USAGE", `Invalid search id: ${JSON.stringify(searchId)}`, {
|
|
156
|
+
fix: "Pass a searchId from a prior search (or use --last)."
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
async function resolveTargets(args, ctx, deps) {
|
|
160
|
+
const ids = idsOf(args.searchId);
|
|
161
|
+
const selectors = [ids.length > 0, args.last === true, args.allOpen === true].filter(
|
|
162
|
+
Boolean
|
|
163
|
+
).length;
|
|
164
|
+
if (selectors > 1) {
|
|
165
|
+
throw new CliError("USAGE", "Pass one of --search-id, --last or --all-open, not several.", {
|
|
166
|
+
fix: "Use --search-id <id> (repeatable) for specific searches, --last for the most recent, or --all-open to close this session's open web-search-hook loops."
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (args.allOpen === true) return resolveAllOpen(args, ctx, deps);
|
|
170
|
+
if (ids.length > 0) {
|
|
171
|
+
const searches = await loadSearches(ctx.dataDir);
|
|
172
|
+
return {
|
|
173
|
+
targets: ids.map((searchId) => ({
|
|
174
|
+
searchId,
|
|
175
|
+
stored: searches.find((s) => s.searchId === searchId) ?? null
|
|
176
|
+
})),
|
|
177
|
+
deliberateLeftOpen: 0,
|
|
178
|
+
answeredLeftOpen: 0
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (args.last === true) {
|
|
182
|
+
const latest = await latestSearch(ctx.dataDir);
|
|
183
|
+
if (latest === null) {
|
|
184
|
+
throw new CliError("SEARCH_NOT_FOUND", "No local search to target with --last.", {
|
|
185
|
+
fix: "Run `tenjin search` first, or pass --search-id <id>."
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
targets: [{ searchId: latest.searchId, stored: latest }],
|
|
190
|
+
deliberateLeftOpen: 0,
|
|
191
|
+
answeredLeftOpen: 0
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
throw new CliError("USAGE", "An outcome needs a search to report against.", {
|
|
195
|
+
fix: "Pass --search-id <id>, --last, or --all-open --status regenerated."
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
async function resolveAllOpen(args, ctx, deps) {
|
|
199
|
+
if (args.status !== "regenerated") {
|
|
200
|
+
throw new CliError(
|
|
201
|
+
"USAGE",
|
|
202
|
+
`--all-open closes searches nobody examined one by one, so it reports regenerated and nothing else (got ${JSON.stringify(args.status)}).`,
|
|
203
|
+
{
|
|
204
|
+
fix: "Use --all-open --status regenerated, or report other statuses per search with --search-id <id>."
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
const sessionId = readSessionId(deps.env);
|
|
209
|
+
const open = (await loadSearches(ctx.dataDir)).filter(
|
|
210
|
+
(s) => (s.resolved === void 0 || s.resolved === null) && ownedByThisSession(s.sessionId, sessionId)
|
|
211
|
+
);
|
|
212
|
+
const hook = open.filter((s) => s.source === "websearch-hook");
|
|
213
|
+
return {
|
|
214
|
+
targets: hook.filter((s) => s.decision === "MISS").map((stored) => ({ searchId: stored.searchId, stored })),
|
|
215
|
+
deliberateLeftOpen: open.length - hook.length,
|
|
216
|
+
answeredLeftOpen: hook.filter((s) => s.decision !== "MISS").length
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function idsOf(searchId) {
|
|
220
|
+
if (searchId === void 0) return [];
|
|
221
|
+
const ids = typeof searchId === "string" ? [searchId] : searchId;
|
|
222
|
+
return [...new Set(ids)];
|
|
223
|
+
}
|
|
224
|
+
var QUESTION_ECHO_MAX = 80;
|
|
225
|
+
function echoQuestion(question) {
|
|
226
|
+
return question.length > QUESTION_ECHO_MAX ? `${question.slice(0, QUESTION_ECHO_MAX - 1)}\u2026` : question;
|
|
227
|
+
}
|
|
228
|
+
function assertOutcomeCoherent(status, stored, resourceId) {
|
|
229
|
+
const named = resourceId !== void 0 ? stored.candidates.find((c) => c.resourceId === resourceId) : void 0;
|
|
230
|
+
if (resourceId !== void 0 && named === void 0 && stored.decision === "CANDIDATES") {
|
|
231
|
+
throw new CliError(
|
|
232
|
+
"USAGE",
|
|
233
|
+
`Search ${stored.searchId} "${echoQuestion(stored.question)}" surfaced no candidate ${resourceId}, so an outcome naming it would not be recorded.`,
|
|
234
|
+
{
|
|
235
|
+
fix: "Pass a resourceId from this search, or drop --resource to report on the search as a whole."
|
|
236
|
+
}
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
if (status !== "purchase_declined") return;
|
|
240
|
+
if (named !== void 0) {
|
|
241
|
+
if (isPaidPrice(named.price) !== false) return;
|
|
242
|
+
throw new CliError(
|
|
243
|
+
"USAGE",
|
|
244
|
+
`Search ${stored.searchId} "${echoQuestion(stored.question)}" listed ${resourceId} at no cost, so purchase_declined cannot describe it.`,
|
|
245
|
+
{
|
|
246
|
+
fix: "A free piece is reported as used, partially_used, rejected or regenerated; pass the --resource you actually declined to buy."
|
|
247
|
+
}
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
if (offeredSomethingToBuy(stored) !== false) return;
|
|
251
|
+
throw new CliError(
|
|
252
|
+
"USAGE",
|
|
253
|
+
`Search ${stored.searchId} "${echoQuestion(stored.question)}" was a ${stored.decision} that offered nothing to buy, so purchase_declined cannot describe it.`,
|
|
254
|
+
{
|
|
255
|
+
fix: "Report used, partially_used, rejected or regenerated for this search, or pass --search-id <id> for the search you meant to report against."
|
|
256
|
+
}
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
function offeredSomethingToBuy(stored) {
|
|
260
|
+
if (stored.candidates.some((c) => isPaidPrice(c.price) === true)) return true;
|
|
261
|
+
if (stored.candidates.some((c) => isPaidPrice(c.price) === null)) return null;
|
|
262
|
+
if (stored.paidBrowseCount === void 0) return null;
|
|
263
|
+
return stored.paidBrowseCount > 0;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export {
|
|
267
|
+
runOutcome
|
|
268
|
+
};
|
|
269
|
+
//# sourceMappingURL=chunk-WY2K35OL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/outcome.ts"],"sourcesContent":["import { CliError } from '../lib/errors';\nimport { resolveContextSettings } from '../lib/settings';\nimport { buildOutcomeItem, postOutcomes } from '../lib/agent-api';\nimport { UUID_RE } from '../lib/ids';\nimport { ownedByThisSession, readSessionId } from '../lib/session';\nimport {\n latestSearch,\n loadSearches,\n markSearchResolved,\n type StoredSearch,\n} from '../lib/search-store';\nimport { isPaidPrice } from '../lib/money';\nimport { sanitizeForTerminal } from '../lib/output';\nimport type { CommandContext, CommandResult } from '../context';\n\n/**\n * `tenjin outcome --search-id <id> --status <s>`, POST to\n * /api/searches/:id/outcomes, closing the reuse loop (used / partially_used\n * / rejected / regenerated / purchase_declined). The searchId is the capability,\n * so no wallet is needed; `--last` sugar targets the most recent DELIBERATE\n * search — entries the WebSearch hook rode along with are skipped, or every web\n * search in auto mode would silently re-aim the report (a hook entry is reached\n * by explicit --search-id, which is what the Stop hook's reminder names).\n *\n * `--last` binds to whatever search ran most recently, which in a multi-search\n * session is often not the one the agent means (issue #100). Two guards, both\n * local: the targeted search's question is echoed back in the success line and in\n * the machine data, so a misfire is visible in the same breath as the report; and\n * an outcome that could not describe that search, whether by its status or by\n * naming a resource the search never surfaced, is refused before the request.\n *\n * ONE STATUS, MANY SEARCHES. `--search-id` repeats and `--all-open` sweeps this\n * session's unanswered hook loops, because a session that closed seventeen of\n * them one call at a time is one where the honest close stops happening. Both\n * report per id, both refuse before sending if one target's id or status could\n * not be right, and both stop at an unhealthy server and report the rest\n * untouched, because an open loop is the state the Stop hook can recover.\n */\n\nexport interface OutcomeArgs {\n /** One search, or several the same status describes. */\n searchId?: string | string[];\n last?: boolean;\n /** Close this session's open websearch-hook MISSes; `regenerated` only. */\n allOpen?: boolean;\n status: string;\n resource?: string;\n contentHash?: string;\n}\n\nexport interface OutcomeDeps {\n fetchImpl?: typeof fetch;\n /** Environment seam (TENJIN_SESSION_ID); defaults to process.env. */\n env?: NodeJS.ProcessEnv;\n}\n\n/** `error` when the report did not land, `untouched` when it was never tried. */\ninterface OutcomeReport {\n searchId: string;\n accepted: number;\n question?: string;\n error?: { code: string; message: string };\n untouched?: true;\n}\n\n/** Failures where the next id fails the same way: the budget signal itself (a\n * sweep can spend 50 of the 60/min window) and the dead network (50 ids at the\n * 10s default stalls a turn end). NOT `API_UNREACHABLE` — postOutcomes gives\n * that to any non-202, so halting would abandon a batch over a per-id 400. */\nconst HALTING_FAILURES = new Set(['RATE_LIMITED', 'NETWORK_ERROR']);\n\nexport async function runOutcome(\n args: OutcomeArgs,\n ctx: CommandContext,\n deps: OutcomeDeps = {},\n): Promise<CommandResult> {\n const { targets, deliberateLeftOpen, answeredLeftOpen } = await resolveTargets(args, ctx, deps);\n // The status VOCABULARY; `--all-open`'s narrower rule already ran above.\n const item = buildOutcomeItem({\n status: args.status,\n ...(args.resource !== undefined ? { resourceId: args.resource } : {}),\n ...(args.contentHash !== undefined ? { contentHash: args.contentHash } : {}),\n });\n if (item.resourceId !== undefined && (targets.length > 1 || args.allOpen === true)) {\n throw new CliError(\n 'USAGE',\n \"A --resource names one search's candidate, so it cannot describe a batch.\",\n { fix: 'Report the resource against its own search with a single --search-id <id>.' },\n );\n }\n // Ids and statuses, before any request: half a batch is worse than none.\n for (const target of targets) {\n assertReportableId(target.searchId);\n if (target.stored !== null) assertOutcomeCoherent(item.status, target.stored, item.resourceId);\n }\n\n const settings = await resolveContextSettings(ctx);\n const reports: OutcomeReport[] = [];\n let halted = false;\n for (const target of targets) {\n const question = target.stored !== null ? echoQuestion(target.stored.question) : undefined;\n if (halted) {\n reports.push({ searchId: target.searchId, accepted: 0, untouched: true });\n continue;\n }\n try {\n const result = await postOutcomes(target.searchId, [item], {\n baseUrl: settings.baseUrl,\n timeoutMs: ctx.flags.timeout,\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n });\n // The loop is closed, so the Stop hook has nothing left to raise about it.\n // AFTER the post, so a refused or failed report leaves the loop open. Local\n // bookkeeping only, and it never throws: see markSearchResolved.\n await markSearchResolved(ctx.dataDir, target.searchId, 'outcome');\n reports.push({\n searchId: target.searchId,\n accepted: result.accepted,\n ...(question !== undefined ? { question } : {}),\n });\n } catch (err) {\n // One id keeps its own error envelope, with the code callers already read.\n if (targets.length === 1) throw err;\n const error = describeFailure(err);\n halted = HALTING_FAILURES.has(error.code);\n reports.push({\n searchId: target.searchId,\n accepted: 0,\n ...(question !== undefined ? { question } : {}),\n error,\n });\n }\n }\n\n const failed = reports.filter((r) => r.error !== undefined);\n const untouched = reports.filter((r) => r.untouched === true);\n const closed = reports.length - failed.length - untouched.length;\n // The question rides both renderings, so the misfire this guards against is\n // visible whether a human is reading the line or an agent is reading the JSON.\n // Sanitized on the human line only: the envelope is machine data and keeps the\n // bytes it was given (see output.ts).\n const humanLines = reports\n .filter((r) => r.error === undefined && r.untouched !== true)\n .map((r) => reportLine(item.status, r));\n if (targets.length === 0) humanLines.push('No open web-search loops in this session.');\n humanLines.push(...leftOpenLines(deliberateLeftOpen, answeredLeftOpen));\n\n if (failed.length > 0) {\n const remainder = untouched.length > 0 ? `, ${untouched.length} left untouched` : '';\n throw new CliError(\n failureCode(failed),\n `Reported ${item.status} for ${closed} of ${reports.length} searches; ${failed.length} failed${remainder}.`,\n {\n // In `fix`, not just `details`: the renderer drops other shapes.\n fix: `Retry with ${retryFlags(failed.concat(untouched))}`,\n details: { status: item.status, closed, results: reports },\n },\n );\n }\n\n return {\n // Flat fields repeat a lone result, so data.searchId still reads.\n data: {\n status: item.status,\n closed,\n results: reports,\n ...(deliberateLeftOpen > 0 ? { deliberateLeftOpen } : {}),\n ...(answeredLeftOpen > 0 ? { answeredLeftOpen } : {}),\n ...(reports.length === 1 ? flatten(reports[0]!) : {}),\n },\n humanLines,\n };\n}\n\nfunction leftOpenLines(deliberate: number, answered: number): string[] {\n const lines: string[] = [];\n if (deliberate > 0) {\n lines.push(`${deliberate} deliberate search(es) left open; close each with --search-id <id>.`);\n }\n if (answered > 0) {\n lines.push(\n `${answered} hook search(es) Tenjin answered left open; report each with --search-id <id>.`,\n );\n }\n return lines;\n}\n\n/** One shared code when every failure agrees, so an all-USAGE batch keeps its\n * exit 2 and an all-RATE_LIMITED one stays recoverable; mixed is an outage. */\nfunction failureCode(failed: OutcomeReport[]): 'USAGE' | 'RATE_LIMITED' | 'API_UNREACHABLE' {\n const codes = new Set(failed.map((r) => r.error?.code));\n if (codes.size !== 1) return 'API_UNREACHABLE';\n const [only] = [...codes];\n if (only === 'USAGE') return 'USAGE';\n return only === 'RATE_LIMITED' ? 'RATE_LIMITED' : 'API_UNREACHABLE';\n}\n\n/** The copy-pasteable retry, bounded: a fix line naming fifty ids is not a fix. */\nfunction retryFlags(pending: OutcomeReport[]): string {\n const MAX_NAMED = 5;\n const named = pending.slice(0, MAX_NAMED).map((r) => `--search-id ${r.searchId}`);\n const rest = pending.length - named.length;\n return rest > 0 ? `${named.join(' ')} (and ${rest} more, see results)` : named.join(' ');\n}\n\nfunction flatten(report: OutcomeReport): Record<string, unknown> {\n return {\n searchId: report.searchId,\n accepted: report.accepted,\n ...(report.question !== undefined ? { question: report.question } : {}),\n };\n}\n\nfunction reportLine(status: string, report: OutcomeReport): string {\n const question =\n report.question !== undefined ? ` \"${sanitizeForTerminal(report.question)}\"` : '';\n return `Reported ${status} for search ${report.searchId}${question} (accepted ${report.accepted}).`;\n}\n\nfunction describeFailure(err: unknown): { code: string; message: string } {\n if (err instanceof CliError) return { code: err.code, message: err.message };\n return { code: 'INTERNAL', message: err instanceof Error ? err.message : String(err) };\n}\n\n/** The search this report will land on, plus the local record of it when there is\n * one. `stored` is null for a `--search-id` from another machine or an evicted\n * entry: unknown, so neither echoed nor checked. */\ninterface OutcomeTarget {\n searchId: string;\n stored: StoredSearch | null;\n}\n\n/** The searches to report against, plus what `--all-open` walked past. */\ninterface ResolvedTargets {\n targets: OutcomeTarget[];\n deliberateLeftOpen: number;\n answeredLeftOpen: number;\n}\n\n/** The shape `postOutcomes` enforces, hoisted in front of the send loop, where\n * it would otherwise run per id after earlier reports already left. UUID_RE and\n * not `SEARCH_ID_WIRE_RE`: this path parameter is `format: uuid` with no pattern\n * (openapi.fixture.json), so the POST /api/posts regex is stricter than the\n * route. */\nfunction assertReportableId(searchId: string): void {\n if (UUID_RE.test(searchId)) return;\n throw new CliError('USAGE', `Invalid search id: ${JSON.stringify(searchId)}`, {\n fix: 'Pass a searchId from a prior search (or use --last).',\n });\n}\n\nasync function resolveTargets(\n args: OutcomeArgs,\n ctx: CommandContext,\n deps: OutcomeDeps,\n): Promise<ResolvedTargets> {\n const ids = idsOf(args.searchId);\n const selectors = [ids.length > 0, args.last === true, args.allOpen === true].filter(\n Boolean,\n ).length;\n if (selectors > 1) {\n throw new CliError('USAGE', 'Pass one of --search-id, --last or --all-open, not several.', {\n fix: \"Use --search-id <id> (repeatable) for specific searches, --last for the most recent, or --all-open to close this session's open web-search-hook loops.\",\n });\n }\n if (args.allOpen === true) return resolveAllOpen(args, ctx, deps);\n if (ids.length > 0) {\n const searches = await loadSearches(ctx.dataDir);\n return {\n targets: ids.map((searchId) => ({\n searchId,\n stored: searches.find((s) => s.searchId === searchId) ?? null,\n })),\n deliberateLeftOpen: 0,\n answeredLeftOpen: 0,\n };\n }\n if (args.last === true) {\n const latest = await latestSearch(ctx.dataDir);\n if (latest === null) {\n throw new CliError('SEARCH_NOT_FOUND', 'No local search to target with --last.', {\n fix: 'Run `tenjin search` first, or pass --search-id <id>.',\n });\n }\n return {\n targets: [{ searchId: latest.searchId, stored: latest }],\n deliberateLeftOpen: 0,\n answeredLeftOpen: 0,\n };\n }\n throw new CliError('USAGE', 'An outcome needs a search to report against.', {\n fix: 'Pass --search-id <id>, --last, or --all-open --status regenerated.',\n });\n}\n\n/**\n * This session's open loops that the hook recorded and Tenjin could not answer.\n *\n * THIS SESSION ONLY, no flag for a wider sweep: the loop is per-session by\n * design, a session's loops are its own, and one that ends leaves its debt to\n * decay rather than handing it to whoever stops next. `readSessionId` and the\n * unstamped rule are shared with the Stop hook, so this covers the same set the\n * nag is drawn from.\n *\n * `regenerated` ONLY, and MISS ONLY: the other statuses claim what a search did\n * for the agent, and the hook records CANDIDATES under this same source, where a\n * priced answer was shown and may have been bought — `regenerated` there would\n * overwrite the one positive attribution this loop collects. Deliberate and\n * answered searches are counted, never swept.\n */\nasync function resolveAllOpen(\n args: OutcomeArgs,\n ctx: CommandContext,\n deps: OutcomeDeps,\n): Promise<ResolvedTargets> {\n if (args.status !== 'regenerated') {\n throw new CliError(\n 'USAGE',\n `--all-open closes searches nobody examined one by one, so it reports regenerated and nothing else (got ${JSON.stringify(args.status)}).`,\n {\n fix: 'Use --all-open --status regenerated, or report other statuses per search with --search-id <id>.',\n },\n );\n }\n const sessionId = readSessionId(deps.env);\n const open = (await loadSearches(ctx.dataDir)).filter(\n (s) =>\n (s.resolved === undefined || s.resolved === null) &&\n ownedByThisSession(s.sessionId, sessionId),\n );\n // Absent source predates sources, and those entries were all deliberate.\n const hook = open.filter((s) => s.source === 'websearch-hook');\n return {\n targets: hook\n .filter((s) => s.decision === 'MISS')\n .map((stored) => ({ searchId: stored.searchId, stored })),\n deliberateLeftOpen: open.length - hook.length,\n answeredLeftOpen: hook.filter((s) => s.decision !== 'MISS').length,\n };\n}\n\nfunction idsOf(searchId: string | string[] | undefined): string[] {\n if (searchId === undefined) return [];\n const ids = typeof searchId === 'string' ? [searchId] : searchId;\n return [...new Set(ids)];\n}\n\n/** Long enough to tell two searches apart on one line, short enough not to bury\n * the searchId next to it. The ellipsis is part of the echo: a question cut with\n * no marker reads as a shorter question that was never asked. */\nconst QUESTION_ECHO_MAX = 80;\n\nfunction echoQuestion(question: string): string {\n return question.length > QUESTION_ECHO_MAX\n ? `${question.slice(0, QUESTION_ECHO_MAX - 1)}…`\n : question;\n}\n\n/**\n * Refuse an outcome that could not describe the search it is aimed at. Two\n * independent checks, because they answer to different rules.\n *\n * MEMBERSHIP, for any status that names a `--resource`: the id has to be one this\n * search surfaced. On a CANDIDATES decision that is provable, since browse\n * pointers are MISS-only by contract AND truncateResponse deletes the array\n * outright on CANDIDATES rather than trust the server, so `candidates` is the\n * entire payable set the agent was shown and `search` records all of it. A uuid\n * outside it is a typo or another search's, and the server drops the item behind\n * its 202 (tenjin#641) whatever the status says, leaving the CLI to report\n * success for an outcome nobody stored. A MISS keeps the fail-open: its browse\n * tail is payable and deliberately unrecorded, so an absent id there is\n * unknowable rather than wrong. So does any other decision value.\n *\n * PAYABILITY, for `purchase_declined` alone. The status matrix is deliberately\n * one-sided: four of the five describe ANY search, so only this one has a\n * precondition.\n *\n * used, partially_used always. A MISS's browse tail is readable, and a free\n * piece is used without any purchase, so \"used\" on a\n * MISS, or on a free candidate, is a real report and not\n * a mistake (issue #100).\n * rejected, regenerated always. \"Nothing here helped, I wrote it myself\" is\n * exactly what a MISS deserves to record.\n * purchase_declined needs the search to have offered something to buy, or,\n * when `--resource` names a candidate the store knows,\n * needs THAT candidate to have cost money. Declining a\n * purchase nobody offered cannot have happened, and that\n * is the shape the dogfooding misfire took: a\n * purchase_declined aimed at a bare MISS.\n *\n * Local knowledge only, and fail-open by construction: an unknown is never a\n * refusal. The server owns the checks this cannot make.\n */\nfunction assertOutcomeCoherent(status: string, stored: StoredSearch, resourceId?: string): void {\n const named =\n resourceId !== undefined\n ? stored.candidates.find((c) => c.resourceId === resourceId)\n : undefined;\n\n if (resourceId !== undefined && named === undefined && stored.decision === 'CANDIDATES') {\n throw new CliError(\n 'USAGE',\n `Search ${stored.searchId} \"${echoQuestion(stored.question)}\" surfaced no candidate ${resourceId}, so an outcome naming it would not be recorded.`,\n {\n fix: 'Pass a resourceId from this search, or drop --resource to report on the search as a whole.',\n },\n );\n }\n\n if (status !== 'purchase_declined') return;\n\n // A named candidate the store knows answers for itself. A piece that was free\n // is not made purchasable by a paid sibling in the same result, so the specific\n // claim is checked against the specific price rather than the search's total.\n if (named !== undefined) {\n if (isPaidPrice(named.price) !== false) return;\n throw new CliError(\n 'USAGE',\n `Search ${stored.searchId} \"${echoQuestion(stored.question)}\" listed ${resourceId} at no cost, so purchase_declined cannot describe it.`,\n {\n fix: 'A free piece is reported as used, partially_used, rejected or regenerated; pass the --resource you actually declined to buy.',\n },\n );\n }\n\n if (offeredSomethingToBuy(stored) !== false) return;\n throw new CliError(\n 'USAGE',\n `Search ${stored.searchId} \"${echoQuestion(stored.question)}\" was a ${stored.decision} that offered nothing to buy, so purchase_declined cannot describe it.`,\n {\n fix: 'Report used, partially_used, rejected or regenerated for this search, or pass --search-id <id> for the search you meant to report against.',\n },\n );\n}\n\n/**\n * Whether the search put anything payable in front of the agent. Priced at zero\n * does not count: `read` delivers a free piece with no payment, so a result that\n * was free end to end offered no purchase to decline, however many rows it had.\n * Null when the stored entry cannot say: it predates `paidBrowseCount`, so an\n * all-free candidate list might still have sat above a payable browse tail.\n */\nfunction offeredSomethingToBuy(stored: StoredSearch): boolean | null {\n if (stored.candidates.some((c) => isPaidPrice(c.price) === true)) return true;\n // A price the store cannot parse is not evidence that the result was free.\n if (stored.candidates.some((c) => isPaidPrice(c.price) === null)) return null;\n if (stored.paidBrowseCount === undefined) return null;\n return stored.paidBrowseCount > 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEA,IAAM,mBAAmB,oBAAI,IAAI,CAAC,gBAAgB,eAAe,CAAC;AAElE,eAAsB,WACpB,MACA,KACA,OAAoB,CAAC,GACG;AACxB,QAAM,EAAE,SAAS,oBAAoB,iBAAiB,IAAI,MAAM,eAAe,MAAM,KAAK,IAAI;AAE9F,QAAM,OAAO,iBAAiB;AAAA,IAC5B,QAAQ,KAAK;AAAA,IACb,GAAI,KAAK,aAAa,SAAY,EAAE,YAAY,KAAK,SAAS,IAAI,CAAC;AAAA,IACnE,GAAI,KAAK,gBAAgB,SAAY,EAAE,aAAa,KAAK,YAAY,IAAI,CAAC;AAAA,EAC5E,CAAC;AACD,MAAI,KAAK,eAAe,WAAc,QAAQ,SAAS,KAAK,KAAK,YAAY,OAAO;AAClF,UAAM,IAAI;AAAA,MACR;AAAA,MACA;AAAA,MACA,EAAE,KAAK,6EAA6E;AAAA,IACtF;AAAA,EACF;AAEA,aAAW,UAAU,SAAS;AAC5B,uBAAmB,OAAO,QAAQ;AAClC,QAAI,OAAO,WAAW,KAAM,uBAAsB,KAAK,QAAQ,OAAO,QAAQ,KAAK,UAAU;AAAA,EAC/F;AAEA,QAAM,WAAW,MAAM,uBAAuB,GAAG;AACjD,QAAM,UAA2B,CAAC;AAClC,MAAI,SA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ACjF;AAAA,QACE,KAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF;AAEA,MAAI,sBAAsB,MAAM,MAAM,MAAO;AAC7C,QAAM,IAAI;AAAA,IACR;AAAA,IACA,UAAU,OAAO,QAAQ,KAAK,aAAa,OAAO,QAAQ,CAAC,WAAW,OAAO,QAAQ;AAAA,IACrF;AAAA,MACE,KAAK;AAAA,IACP;AAAA,EACF;AACF;AASA,SAAS,sBAAsB,QAAsC;AACnE,MAAI,OAAO,WAAW,KAAK,CAAC,MAAM,YAAY,EAAE,KAAK,MAAM,IAAI,EAAG,QAAO;AAEzE,MAAI,OAAO,WAAW,KAAK,CAAC,MAAM,YAAY,EAAE,KAAK,MAAM,IAAI,EAAG,QAAO;AACzE,MAAI,OAAO,oBAAoB,OAAW,QAAO;AACjD,SAAO,OAAO,kBAAkB;AAClC;","names":[]}
|
|
@@ -14547,7 +14547,9 @@ var EXIT_BY_CODE = {
|
|
|
14547
14547
|
// A send that reverted or stalled AFTER the human approved it and it was
|
|
14548
14548
|
// broadcast: the post-decision failure class (4), like PAYMENT_FAILED.
|
|
14549
14549
|
SEND_FAILED: 4,
|
|
14550
|
-
UPDATE_FAILED: 1
|
|
14550
|
+
UPDATE_FAILED: 1,
|
|
14551
|
+
// Refused BEFORE any signature existed: the Bazaar lane's fail-closed check.
|
|
14552
|
+
REGISTRY_MISMATCH: 3
|
|
14551
14553
|
};
|
|
14552
14554
|
function exitCodeFor(code) {
|
|
14553
14555
|
return EXIT_BY_CODE[code];
|
|
@@ -14567,17 +14569,53 @@ var CliError = class extends Error {
|
|
|
14567
14569
|
}
|
|
14568
14570
|
};
|
|
14569
14571
|
|
|
14572
|
+
// src/lib/paths.ts
|
|
14573
|
+
import { homedir } from "os";
|
|
14574
|
+
import { join } from "path";
|
|
14575
|
+
function dataDir(env = process.env) {
|
|
14576
|
+
const override = env.TENJIN_DATA_DIR;
|
|
14577
|
+
if (override !== void 0 && override.length > 0) return override;
|
|
14578
|
+
return join(homedir(), ".tenjin");
|
|
14579
|
+
}
|
|
14580
|
+
function configPath(dir = dataDir()) {
|
|
14581
|
+
return join(dir, "config.json");
|
|
14582
|
+
}
|
|
14583
|
+
function walletPath(dir = dataDir()) {
|
|
14584
|
+
return join(dir, "wallet.json");
|
|
14585
|
+
}
|
|
14586
|
+
function sessionPath(dir = dataDir()) {
|
|
14587
|
+
return join(dir, "session.json");
|
|
14588
|
+
}
|
|
14589
|
+
function spendLedgerPath(dir = dataDir()) {
|
|
14590
|
+
return join(dir, "spend.json");
|
|
14591
|
+
}
|
|
14592
|
+
function updateCheckPath(dir = dataDir()) {
|
|
14593
|
+
return join(dir, "update-check.json");
|
|
14594
|
+
}
|
|
14595
|
+
function hooksDir(dir = dataDir()) {
|
|
14596
|
+
return join(dir, "hooks");
|
|
14597
|
+
}
|
|
14598
|
+
function passphraseBlobPath(dir = dataDir()) {
|
|
14599
|
+
return join(dir, "passphrase.dpapi");
|
|
14600
|
+
}
|
|
14601
|
+
function passphraseBlobPathFor(account, dir = dataDir()) {
|
|
14602
|
+
return join(dir, `passphrase.${account}.dpapi`);
|
|
14603
|
+
}
|
|
14604
|
+
function archivedWalletPath(account, dir = dataDir()) {
|
|
14605
|
+
return join(dir, `wallet.${account}.json.bak`);
|
|
14606
|
+
}
|
|
14607
|
+
|
|
14570
14608
|
// src/lib/atomic-json.ts
|
|
14571
14609
|
import { chmod, link, mkdir, open, rename, rm, writeFile } from "fs/promises";
|
|
14572
14610
|
import { randomBytes } from "crypto";
|
|
14573
|
-
import { basename, dirname, join } from "path";
|
|
14611
|
+
import { basename, dirname, join as join2 } from "path";
|
|
14574
14612
|
var isWindows = process.platform === "win32";
|
|
14575
14613
|
async function writeFileAtomic(targetPath, data, opts = {}) {
|
|
14576
14614
|
const dir = dirname(targetPath);
|
|
14577
14615
|
const fileMode = opts.mode ?? 420;
|
|
14578
14616
|
const dirMode = opts.dirMode ?? 493;
|
|
14579
14617
|
await mkdir(dir, { recursive: true, ...isWindows ? {} : { mode: dirMode } });
|
|
14580
|
-
const tmpPath =
|
|
14618
|
+
const tmpPath = join2(dir, `.${basename(targetPath)}.${randomBytes(6).toString("hex")}.tmp`);
|
|
14581
14619
|
try {
|
|
14582
14620
|
await writeFile(tmpPath, data, isWindows ? void 0 : { mode: fileMode });
|
|
14583
14621
|
if (!isWindows) await chmod(tmpPath, fileMode);
|
|
@@ -14602,7 +14640,7 @@ async function writeFileAtomicExclusive(targetPath, data, opts = {}) {
|
|
|
14602
14640
|
}
|
|
14603
14641
|
return;
|
|
14604
14642
|
}
|
|
14605
|
-
const tmpPath =
|
|
14643
|
+
const tmpPath = join2(dir, `.${basename(targetPath)}.${randomBytes(6).toString("hex")}.tmp`);
|
|
14606
14644
|
try {
|
|
14607
14645
|
const handle = await open(tmpPath, "wx", fileMode);
|
|
14608
14646
|
try {
|
|
@@ -14665,9 +14703,19 @@ export {
|
|
|
14665
14703
|
preprocess,
|
|
14666
14704
|
external_exports,
|
|
14667
14705
|
CliError,
|
|
14706
|
+
dataDir,
|
|
14707
|
+
configPath,
|
|
14708
|
+
walletPath,
|
|
14709
|
+
sessionPath,
|
|
14710
|
+
spendLedgerPath,
|
|
14711
|
+
updateCheckPath,
|
|
14712
|
+
hooksDir,
|
|
14713
|
+
passphraseBlobPath,
|
|
14714
|
+
passphraseBlobPathFor,
|
|
14715
|
+
archivedWalletPath,
|
|
14668
14716
|
writeFileAtomic,
|
|
14669
14717
|
writeFileAtomicExclusive,
|
|
14670
14718
|
fsyncDir,
|
|
14671
14719
|
hasCode
|
|
14672
14720
|
};
|
|
14673
|
-
//# sourceMappingURL=chunk-
|
|
14721
|
+
//# sourceMappingURL=chunk-ZFJJ3EXC.js.map
|