tenjin-cli 0.1.0-alpha.5 → 0.1.0-alpha.8
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 +169 -199
- package/dist/{buy-YMXXVNFH.js → buy-K2G6XQY2.js} +20 -18
- package/dist/{candidate-H7FR4AU5.js → candidate-DJB2NNTG.js} +7 -8
- package/dist/{chunk-ZW3B5LWX.js → chunk-2YX6LTCD.js} +5 -5
- package/dist/{chunk-4WVKXKDK.js → chunk-6OE2IJMH.js} +29 -238
- package/dist/chunk-6OE2IJMH.js.map +1 -0
- package/dist/{chunk-ADJYSM45.js → chunk-6ZBZCBR7.js} +27 -13
- package/dist/chunk-6ZBZCBR7.js.map +1 -0
- package/dist/{chunk-HTDALK7M.js → chunk-B7YB4MMU.js} +15 -12
- package/dist/{chunk-HTDALK7M.js.map → chunk-B7YB4MMU.js.map} +1 -1
- package/dist/{chunk-NFSOVL3C.js → chunk-BBUYCDSG.js} +12 -3
- package/dist/chunk-BBUYCDSG.js.map +1 -0
- package/dist/chunk-C3S6725N.js +337 -0
- package/dist/chunk-C3S6725N.js.map +1 -0
- package/dist/chunk-CYRYVZPN.js +213 -0
- package/dist/chunk-CYRYVZPN.js.map +1 -0
- package/dist/{chunk-MDDGEGSW.js → chunk-DAJ56EUU.js} +3 -3
- package/dist/{chunk-IOPWPMT2.js → chunk-DH6D6QIO.js} +5 -5
- package/dist/{chunk-NJF2WENW.js → chunk-DQDGBWWH.js} +4 -2
- package/dist/chunk-DQDGBWWH.js.map +1 -0
- package/dist/chunk-EDENZN2Q.js +614 -0
- package/dist/chunk-EDENZN2Q.js.map +1 -0
- package/dist/chunk-GABYDXWL.js +190 -0
- package/dist/chunk-GABYDXWL.js.map +1 -0
- package/dist/{chunk-LAM66WFJ.js → chunk-GM4RZUVU.js} +6 -8
- package/dist/{chunk-LAM66WFJ.js.map → chunk-GM4RZUVU.js.map} +1 -1
- package/dist/{chunk-PAUXMRSF.js → chunk-J6CVKC4M.js} +73 -2
- package/dist/chunk-J6CVKC4M.js.map +1 -0
- package/dist/chunk-L6AV2Q73.js +105 -0
- package/dist/chunk-L6AV2Q73.js.map +1 -0
- package/dist/{chunk-PYNSGYBE.js → chunk-NVHQCTIC.js} +249 -552
- package/dist/chunk-NVHQCTIC.js.map +1 -0
- package/dist/{chunk-CVX6JNGD.js → chunk-OTDI5FXG.js} +3 -5
- package/dist/{chunk-CVX6JNGD.js.map → chunk-OTDI5FXG.js.map} +1 -1
- package/dist/{chunk-3IRDP7TN.js → chunk-P3FBESBB.js} +6 -4
- package/dist/{chunk-3IRDP7TN.js.map → chunk-P3FBESBB.js.map} +1 -1
- package/dist/{chunk-FU6MCSLG.js → chunk-PCLPVJ3J.js} +16 -78
- package/dist/chunk-PCLPVJ3J.js.map +1 -0
- package/dist/chunk-QB2NNV6C.js +143 -0
- package/dist/chunk-QB2NNV6C.js.map +1 -0
- package/dist/{chunk-C444K6MI.js → chunk-RGFBBNGP.js} +42 -17
- package/dist/{chunk-C444K6MI.js.map → chunk-RGFBBNGP.js.map} +1 -1
- package/dist/{chunk-TXPPMK4L.js → chunk-RGTTACP3.js} +5 -5
- package/dist/chunk-SGK2B724.js +67 -0
- package/dist/chunk-SGK2B724.js.map +1 -0
- package/dist/{chunk-ZDY2KY5X.js → chunk-URSGGRO4.js} +28 -11
- package/dist/chunk-URSGGRO4.js.map +1 -0
- package/dist/{chunk-5SCU253N.js → chunk-UYP7G3GZ.js} +2 -2
- package/dist/{chunk-ZIYVN4CD.js → chunk-VZ3AJCO5.js} +3 -5
- package/dist/{chunk-ZIYVN4CD.js.map → chunk-VZ3AJCO5.js.map} +1 -1
- package/dist/{chunk-QONTBYQW.js → chunk-WRWCDLVK.js} +4 -6
- package/dist/{chunk-QONTBYQW.js.map → chunk-WRWCDLVK.js.map} +1 -1
- package/dist/chunk-XBJ3VLWX.js +35 -0
- package/dist/chunk-XBJ3VLWX.js.map +1 -0
- package/dist/{chunk-RTJLLPFA.js → chunk-XFHZWORF.js} +123 -24
- package/dist/chunk-XFHZWORF.js.map +1 -0
- package/dist/{chunk-BIKAUVC2.js → chunk-ZA3RFDAV.js} +40 -6
- package/dist/chunk-ZA3RFDAV.js.map +1 -0
- package/dist/{cli-IW76QTN3.js → cli-KNCYWMAG.js} +237 -25
- package/dist/cli-KNCYWMAG.js.map +1 -0
- package/dist/{config-VCOS7P5K.js → config-SAQEQRFB.js} +5 -6
- package/dist/dist-U4M6QCKE.js +2842 -0
- package/dist/dist-U4M6QCKE.js.map +1 -0
- package/dist/{doctor-WS65JG3V.js → doctor-FBRQNOUQ.js} +10 -9
- package/dist/{publish-DSFWQRUN.js → edit-IZZ2HIMR.js} +20 -18
- package/dist/index.js +1 -1
- package/dist/{inspect-SFJWUQHO.js → inspect-BFWZ5XOP.js} +17 -16
- package/dist/{install-RVPQPCKH.js → install-QXZCHIBT.js} +400 -166
- package/dist/install-QXZCHIBT.js.map +1 -0
- package/dist/outcome-VXCBEGNC.js +20 -0
- package/dist/publish-5NTCRF2V.js +40 -0
- package/dist/read-T6OTMU72.js +158 -0
- package/dist/read-T6OTMU72.js.map +1 -0
- package/dist/{run-OMPKA43G.js → run-5OGX64IY.js} +106 -32
- package/dist/{run-OMPKA43G.js.map → run-5OGX64IY.js.map} +1 -1
- package/dist/search-LIIWUMWV.js +24 -0
- package/dist/{send-3G4C64HJ.js → send-ENE47KQE.js} +7 -7
- package/dist/session-HY4QIWHV.js +87 -0
- package/dist/session-HY4QIWHV.js.map +1 -0
- package/dist/{wallet-PP22LAX7.js → wallet-OCCGEH6H.js} +7 -7
- package/dist/{wallet-B7KJS2R5.js → wallet-RBDVNZVR.js} +5 -5
- package/dist/wallet-RBDVNZVR.js.map +1 -0
- package/docs/agent-permissions.md +255 -0
- package/package.json +3 -1
- package/skills/tenjin/SKILL.md +57 -13
- package/skills/tenjin-publish/SKILL.md +12 -4
- package/skills/tenjin-search/SKILL.md +68 -12
- package/dist/chunk-2JQ5JSG6.js +0 -68
- package/dist/chunk-2JQ5JSG6.js.map +0 -1
- package/dist/chunk-4WVKXKDK.js.map +0 -1
- package/dist/chunk-ADJYSM45.js.map +0 -1
- package/dist/chunk-BIKAUVC2.js.map +0 -1
- package/dist/chunk-FU6MCSLG.js.map +0 -1
- package/dist/chunk-L4IHCN6B.js +0 -63
- package/dist/chunk-L4IHCN6B.js.map +0 -1
- package/dist/chunk-NFSOVL3C.js.map +0 -1
- package/dist/chunk-NJF2WENW.js.map +0 -1
- package/dist/chunk-PAUXMRSF.js.map +0 -1
- package/dist/chunk-PYNSGYBE.js.map +0 -1
- package/dist/chunk-RTJLLPFA.js.map +0 -1
- package/dist/chunk-ZDY2KY5X.js.map +0 -1
- package/dist/cli-IW76QTN3.js.map +0 -1
- package/dist/install-RVPQPCKH.js.map +0 -1
- package/dist/outcome-GNYCSZ7J.js +0 -20
- package/dist/search-KOI6Y7P6.js +0 -24
- /package/dist/{buy-YMXXVNFH.js.map → buy-K2G6XQY2.js.map} +0 -0
- /package/dist/{candidate-H7FR4AU5.js.map → candidate-DJB2NNTG.js.map} +0 -0
- /package/dist/{chunk-ZW3B5LWX.js.map → chunk-2YX6LTCD.js.map} +0 -0
- /package/dist/{chunk-MDDGEGSW.js.map → chunk-DAJ56EUU.js.map} +0 -0
- /package/dist/{chunk-IOPWPMT2.js.map → chunk-DH6D6QIO.js.map} +0 -0
- /package/dist/{chunk-TXPPMK4L.js.map → chunk-RGTTACP3.js.map} +0 -0
- /package/dist/{chunk-5SCU253N.js.map → chunk-UYP7G3GZ.js.map} +0 -0
- /package/dist/{config-VCOS7P5K.js.map → config-SAQEQRFB.js.map} +0 -0
- /package/dist/{doctor-WS65JG3V.js.map → doctor-FBRQNOUQ.js.map} +0 -0
- /package/dist/{inspect-SFJWUQHO.js.map → edit-IZZ2HIMR.js.map} +0 -0
- /package/dist/{outcome-GNYCSZ7J.js.map → inspect-BFWZ5XOP.js.map} +0 -0
- /package/dist/{publish-DSFWQRUN.js.map → outcome-VXCBEGNC.js.map} +0 -0
- /package/dist/{search-KOI6Y7P6.js.map → publish-5NTCRF2V.js.map} +0 -0
- /package/dist/{wallet-B7KJS2R5.js.map → search-LIIWUMWV.js.map} +0 -0
- /package/dist/{send-3G4C64HJ.js.map → send-ENE47KQE.js.map} +0 -0
- /package/dist/{wallet-PP22LAX7.js.map → wallet-OCCGEH6H.js.map} +0 -0
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
buildPostUpdateBody,
|
|
4
|
+
dedupeFindings,
|
|
5
|
+
deriveCard,
|
|
6
|
+
deriveProjectMarkers,
|
|
7
|
+
describeFindings,
|
|
8
|
+
getOwnPost,
|
|
9
|
+
missingSentences,
|
|
10
|
+
needsConfirmation,
|
|
11
|
+
parseAppliesToFlags,
|
|
12
|
+
parseFrontmatter,
|
|
13
|
+
publicFinding,
|
|
14
|
+
resolveWriteAuth,
|
|
15
|
+
scan,
|
|
16
|
+
updatePost,
|
|
17
|
+
writeModeNotices
|
|
18
|
+
} from "./chunk-NVHQCTIC.js";
|
|
19
|
+
import {
|
|
20
|
+
describeWallet,
|
|
21
|
+
resolveWalletProvider
|
|
22
|
+
} from "./chunk-RGFBBNGP.js";
|
|
23
|
+
import {
|
|
24
|
+
UUID_RE
|
|
25
|
+
} from "./chunk-WWX32ML4.js";
|
|
26
|
+
import {
|
|
27
|
+
sanitizeForTerminal
|
|
28
|
+
} from "./chunk-BBUYCDSG.js";
|
|
29
|
+
import {
|
|
30
|
+
resolveContextSettings,
|
|
31
|
+
resolvePublishSettings
|
|
32
|
+
} from "./chunk-DAJ56EUU.js";
|
|
33
|
+
import {
|
|
34
|
+
parsePublishModeFlag,
|
|
35
|
+
parseUsdToAtomic,
|
|
36
|
+
toMoney
|
|
37
|
+
} from "./chunk-UYP7G3GZ.js";
|
|
38
|
+
import {
|
|
39
|
+
CliError
|
|
40
|
+
} from "./chunk-J6CVKC4M.js";
|
|
41
|
+
|
|
42
|
+
// src/commands/edit.ts
|
|
43
|
+
import { readFile } from "fs/promises";
|
|
44
|
+
import { dirname, resolve } from "path";
|
|
45
|
+
async function runEdit(args, ctx, deps = {}) {
|
|
46
|
+
const env = deps.env ?? process.env;
|
|
47
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
48
|
+
if (!UUID_RE.test(args.postId)) {
|
|
49
|
+
throw new CliError("USAGE", `Invalid post id: ${JSON.stringify(args.postId)}`, {
|
|
50
|
+
fix: "Pass the post uuid from `tenjin publish`\u2019s receipt or your desk."
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (args.mode !== void 0) parsePublishModeFlag(args.mode, "--mode");
|
|
54
|
+
rejectEmptyValues(args);
|
|
55
|
+
assertAppendExclusivity(args);
|
|
56
|
+
const clears = parseClears(args);
|
|
57
|
+
const cardFlags = cardFlagsFrom(args);
|
|
58
|
+
const priceAtomic = args.price !== void 0 ? parseUsdToAtomic(args.price) : void 0;
|
|
59
|
+
const bodyFile = args.body !== void 0 ? await readBodyFile(args.body) : void 0;
|
|
60
|
+
const wantsChange = hasChangeFlags(args);
|
|
61
|
+
const runtime = await resolveContextSettings(ctx);
|
|
62
|
+
const provider = resolveWalletProvider(
|
|
63
|
+
ctx,
|
|
64
|
+
deps.provider !== void 0 ? { provider: deps.provider } : {}
|
|
65
|
+
);
|
|
66
|
+
await describeWallet(provider);
|
|
67
|
+
const signer = await provider.getSigner();
|
|
68
|
+
const auth = resolveWriteAuth({
|
|
69
|
+
signer,
|
|
70
|
+
baseUrl: runtime.baseUrl,
|
|
71
|
+
dataDir: ctx.dataDir,
|
|
72
|
+
scope: wantsChange ? "read+write" : "read",
|
|
73
|
+
...deps.useSession !== void 0 ? { useSession: deps.useSession } : {},
|
|
74
|
+
env
|
|
75
|
+
});
|
|
76
|
+
const client = {
|
|
77
|
+
baseUrl: runtime.baseUrl,
|
|
78
|
+
timeoutMs: ctx.flags.timeout,
|
|
79
|
+
...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
|
|
80
|
+
};
|
|
81
|
+
const stored = await getOwnPost(args.postId, auth, client);
|
|
82
|
+
if (!wantsChange) return showReceipt(stored);
|
|
83
|
+
if (args.addQuestion !== void 0 && args.addQuestion.length > 0) {
|
|
84
|
+
cardFlags.question = appendUnique(storedList(stored, "questionsAnswered"), args.addQuestion);
|
|
85
|
+
}
|
|
86
|
+
if (args.addTask !== void 0 && args.addTask.length > 0) {
|
|
87
|
+
cardFlags.task = appendUnique(storedList(stored, "tasksSupported"), args.addTask);
|
|
88
|
+
}
|
|
89
|
+
const intent = {
|
|
90
|
+
...args.title !== void 0 ? { title: args.title } : {},
|
|
91
|
+
...bodyFile !== void 0 ? { bodyMd: bodyFile.body } : {},
|
|
92
|
+
...args.excerpt !== void 0 ? { excerpt: args.excerpt } : {},
|
|
93
|
+
...priceAtomic !== void 0 ? { priceAtomic } : {},
|
|
94
|
+
...withClears(deriveCard({}, cardFlags), clears, stored.resource)
|
|
95
|
+
};
|
|
96
|
+
const { input, lines: changes } = diffUpdate(stored, intent);
|
|
97
|
+
if (changes.length === 0) return noChangeReceipt(stored);
|
|
98
|
+
buildPostUpdateBody(input);
|
|
99
|
+
const settings = await resolvePublishSettings({
|
|
100
|
+
dataDir: ctx.dataDir,
|
|
101
|
+
cwd,
|
|
102
|
+
...args.mode !== void 0 ? { flag: args.mode } : {},
|
|
103
|
+
env
|
|
104
|
+
});
|
|
105
|
+
writeModeNotices(
|
|
106
|
+
ctx.io.stderr,
|
|
107
|
+
settings,
|
|
108
|
+
env,
|
|
109
|
+
"each edit asks you once. Set auto to apply clean edits automatically"
|
|
110
|
+
);
|
|
111
|
+
const markerRoot = args.body !== void 0 ? dirname(resolve(cwd, args.body)) : cwd;
|
|
112
|
+
const scanContext = { projectMarkers: await deriveProjectMarkers(markerRoot) };
|
|
113
|
+
const findings = dedupeFindings([
|
|
114
|
+
...input.bodyMd !== void 0 ? scan(bodyFile?.raw ?? "", scanContext) : [],
|
|
115
|
+
...scan(shippedTypedText(args, input), scanContext)
|
|
116
|
+
]);
|
|
117
|
+
const blocking = findings.filter((f) => f.severity === "block");
|
|
118
|
+
const warns = findings.filter((f) => f.severity === "warn");
|
|
119
|
+
if (blocking.length > 0) {
|
|
120
|
+
throw new CliError("PUBLISH_BLOCKED", blockMessage(blocking), {
|
|
121
|
+
fix: "Remove the secret from the new content (it is never masked away by --yes), then re-run.",
|
|
122
|
+
details: { mode: settings.mode, findings: blocking.map(publicFinding) }
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
const notes = editNotes(args, stored, bodyFile, clears);
|
|
126
|
+
for (const line of [...notes, ...changes]) ctx.io.stderr.write(`${line}
|
|
127
|
+
`);
|
|
128
|
+
if (needsConfirmation(settings.mode, warns.length) && args.yes !== true) {
|
|
129
|
+
throw new CliError("NEEDS_CONFIRMATION", confirmMessage(warns.length, changes.length), {
|
|
130
|
+
fix: "Review the changes, then re-run with --yes.",
|
|
131
|
+
details: {
|
|
132
|
+
mode: settings.mode,
|
|
133
|
+
postId: stored.id,
|
|
134
|
+
title: sanitizeForTerminal(stored.title),
|
|
135
|
+
changes,
|
|
136
|
+
...notes.length > 0 ? { notes } : {},
|
|
137
|
+
findings: warns.map(publicFinding)
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const updated = await updatePost(args.postId, input, auth, client);
|
|
142
|
+
return updateReceipt(updated, changes, notes, settings.mode);
|
|
143
|
+
}
|
|
144
|
+
function showReceipt(post) {
|
|
145
|
+
const price = toMoney(post.price);
|
|
146
|
+
const card = post.resource;
|
|
147
|
+
const lines = [
|
|
148
|
+
`${sanitizeForTerminal(post.title)} (${sanitizeForTerminal(post.status)}), ${price.usd} USD (${price.atomic} atomic)`,
|
|
149
|
+
`url: ${sanitizeForTerminal(post.url)}`,
|
|
150
|
+
...hasText(post.excerpt) ? [`excerpt: ${preview(post.excerpt)}`] : [],
|
|
151
|
+
...cardLines(card),
|
|
152
|
+
eligibilityLine(card)
|
|
153
|
+
];
|
|
154
|
+
return { data: post, humanLines: lines };
|
|
155
|
+
}
|
|
156
|
+
function updateReceipt(post, changes, notes, mode) {
|
|
157
|
+
const card = post.resource;
|
|
158
|
+
const lines = [
|
|
159
|
+
`Updated ${sanitizeForTerminal(post.title)} \u2192 ${sanitizeForTerminal(post.url)}`,
|
|
160
|
+
eligibilityLine(card),
|
|
161
|
+
...(post.warnings ?? []).map((w) => `warning: ${sanitizeForTerminal(w)}`)
|
|
162
|
+
];
|
|
163
|
+
return {
|
|
164
|
+
// `mode` is echoed because a per-call --mode (or the MCP `mode` argument) is
|
|
165
|
+
// otherwise invisible in a transcript: the receipt would look identical
|
|
166
|
+
// whether the caller loosened the gate for this run or not.
|
|
167
|
+
data: { ...post, mode, changes, ...notes.length > 0 ? { notes } : {} },
|
|
168
|
+
humanLines: lines
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function noChangeReceipt(post) {
|
|
172
|
+
return {
|
|
173
|
+
data: { ...post, changes: [] },
|
|
174
|
+
humanLines: [
|
|
175
|
+
`No changes: every value given already matches ${sanitizeForTerminal(post.title)}. Nothing was written.`
|
|
176
|
+
]
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function cardLines(card) {
|
|
180
|
+
if (card === void 0) return [];
|
|
181
|
+
const lines = [];
|
|
182
|
+
const list = (label, values) => {
|
|
183
|
+
if (values !== void 0 && values !== null && values.length > 0) {
|
|
184
|
+
lines.push(
|
|
185
|
+
`${label} (${values.length}): ${values.map((v) => sanitizeForTerminal(v)).join(" | ")}`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
list("questionsAnswered", card.questionsAnswered);
|
|
190
|
+
list("tasksSupported", card.tasksSupported);
|
|
191
|
+
for (const [label, value] of [
|
|
192
|
+
["scope", card.scope],
|
|
193
|
+
["exclusions", card.exclusions],
|
|
194
|
+
["artifactType", card.artifactType],
|
|
195
|
+
["temporalMode", card.temporalMode],
|
|
196
|
+
["asOf", card.asOf],
|
|
197
|
+
["validUntil", card.validUntil],
|
|
198
|
+
["provenance", card.provenanceSummary],
|
|
199
|
+
["methodology", card.methodologySummary],
|
|
200
|
+
["supersedesPostId", card.supersedesPostId]
|
|
201
|
+
]) {
|
|
202
|
+
if (hasText(value)) lines.push(`${label}: ${preview(value)}`);
|
|
203
|
+
}
|
|
204
|
+
if (card.appliesTo !== void 0 && card.appliesTo !== null) {
|
|
205
|
+
for (const [key, values] of Object.entries(card.appliesTo)) {
|
|
206
|
+
lines.push(
|
|
207
|
+
`appliesTo ${sanitizeForTerminal(key)}: ${values.map((v) => sanitizeForTerminal(v)).join(", ")}`
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return lines;
|
|
212
|
+
}
|
|
213
|
+
function eligibilityLine(card) {
|
|
214
|
+
if (card === void 0) return "No answer card (browse-only document).";
|
|
215
|
+
const missing = missingSentences(card.cacheEligibleMissing).map(sanitizeForTerminal);
|
|
216
|
+
if (card.cacheEligible) return "Answer card is search-eligible.";
|
|
217
|
+
return missing.length > 0 ? `Answer card not search-eligible yet: ${missing.join(" ")}` : "Answer card is not search-eligible.";
|
|
218
|
+
}
|
|
219
|
+
function diffUpdate(stored, intent) {
|
|
220
|
+
const lines = [];
|
|
221
|
+
const input = {};
|
|
222
|
+
const title = intent.title?.trim();
|
|
223
|
+
if (title !== void 0 && title !== stored.title) {
|
|
224
|
+
input.title = title;
|
|
225
|
+
lines.push(`title: ${preview(stored.title)} \u2192 ${preview(title)}`);
|
|
226
|
+
}
|
|
227
|
+
if (intent.priceAtomic !== void 0 && intent.priceAtomic !== stored.price) {
|
|
228
|
+
const before = toMoney(stored.price);
|
|
229
|
+
const after = toMoney(intent.priceAtomic);
|
|
230
|
+
input.priceAtomic = intent.priceAtomic;
|
|
231
|
+
lines.push(
|
|
232
|
+
`price: ${before.usd} USD (${before.atomic} atomic) \u2192 ${after.usd} USD (${after.atomic} atomic)`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
if (intent.bodyMd !== void 0 && intent.bodyMd !== stored.bodyMd) {
|
|
236
|
+
input.bodyMd = intent.bodyMd;
|
|
237
|
+
lines.push(`body: ${(stored.bodyMd ?? "").length} \u2192 ${intent.bodyMd.length} characters`);
|
|
238
|
+
}
|
|
239
|
+
const excerpt = intent.excerpt?.trim();
|
|
240
|
+
if (excerpt !== void 0 && excerpt !== (stored.excerpt ?? "")) {
|
|
241
|
+
input.excerpt = excerpt;
|
|
242
|
+
lines.push(`excerpt: ${preview(stored.excerpt)} \u2192 ${preview(excerpt)}`);
|
|
243
|
+
}
|
|
244
|
+
const card = diffCard(stored.resource, intent.resource);
|
|
245
|
+
lines.push(...card.lines);
|
|
246
|
+
if (card.card !== void 0) input.resource = card.card;
|
|
247
|
+
return { input, lines };
|
|
248
|
+
}
|
|
249
|
+
var CARD_PASS = {
|
|
250
|
+
questionsAnswered: "list",
|
|
251
|
+
tasksSupported: "list",
|
|
252
|
+
asOf: "iso",
|
|
253
|
+
validUntil: "iso",
|
|
254
|
+
scope: "scalar",
|
|
255
|
+
exclusions: "scalar",
|
|
256
|
+
artifactType: "scalar",
|
|
257
|
+
temporalMode: "scalar",
|
|
258
|
+
provenanceSummary: "scalar",
|
|
259
|
+
methodologySummary: "scalar",
|
|
260
|
+
supersedesPostId: "scalar",
|
|
261
|
+
appliesTo: "map",
|
|
262
|
+
mediaType: "none",
|
|
263
|
+
maintenanceCadence: "none",
|
|
264
|
+
reproductionMinutes: "none",
|
|
265
|
+
estimatedPaidInputCost: "none"
|
|
266
|
+
};
|
|
267
|
+
function keysIn(pass) {
|
|
268
|
+
return Object.entries(CARD_PASS).filter(([, value]) => value === pass).map(([key]) => key);
|
|
269
|
+
}
|
|
270
|
+
var CARD_LABEL = {
|
|
271
|
+
provenanceSummary: "provenance",
|
|
272
|
+
methodologySummary: "methodology"
|
|
273
|
+
};
|
|
274
|
+
function cardLabel(key) {
|
|
275
|
+
return CARD_LABEL[key] ?? key;
|
|
276
|
+
}
|
|
277
|
+
function diffCard(stored, next) {
|
|
278
|
+
const lines = [];
|
|
279
|
+
const card = {};
|
|
280
|
+
const keep = (key, value, line) => {
|
|
281
|
+
card[key] = value;
|
|
282
|
+
lines.push(line);
|
|
283
|
+
};
|
|
284
|
+
if (next === void 0) return { lines };
|
|
285
|
+
for (const key of keysIn("list")) {
|
|
286
|
+
const after = next[key];
|
|
287
|
+
if (after === void 0) continue;
|
|
288
|
+
const old = stored?.[key] ?? [];
|
|
289
|
+
if (sameList(old, after)) continue;
|
|
290
|
+
const added = after.filter((v) => !old.includes(v));
|
|
291
|
+
const detail = after.length === 0 ? " (cleared)" : added.length > 0 ? ` (new: ${previewList(added)})` : "";
|
|
292
|
+
keep(key, after, `${key}: ${old.length} \u2192 ${after.length}${detail}`);
|
|
293
|
+
}
|
|
294
|
+
for (const key of keysIn("iso")) {
|
|
295
|
+
const after = next[key];
|
|
296
|
+
if (after === void 0) continue;
|
|
297
|
+
const from = isoInstant(stored?.[key]);
|
|
298
|
+
const to = isoInstant(after);
|
|
299
|
+
if (from === to) continue;
|
|
300
|
+
keep(key, to, `${key}: ${preview(from)} \u2192 ${to === null ? "(cleared)" : preview(to)}`);
|
|
301
|
+
}
|
|
302
|
+
for (const key of keysIn("scalar")) {
|
|
303
|
+
const after = next[key];
|
|
304
|
+
if (after === void 0) continue;
|
|
305
|
+
const from = stored?.[key] ?? null;
|
|
306
|
+
if (from === after) continue;
|
|
307
|
+
keep(
|
|
308
|
+
key,
|
|
309
|
+
after,
|
|
310
|
+
`${cardLabel(key)}: ${preview(from)} \u2192 ${after === null ? "(cleared)" : preview(after)}`
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
for (const key of keysIn("map")) {
|
|
314
|
+
const after = next[key];
|
|
315
|
+
if (after === void 0) continue;
|
|
316
|
+
const before = stored?.[key] ?? {};
|
|
317
|
+
if (sameAppliesTo(before, after)) continue;
|
|
318
|
+
keep(key, after, `${key}: ${appliesToPreview(before)} \u2192 ${appliesToPreview(after)}`);
|
|
319
|
+
}
|
|
320
|
+
return { ...Object.keys(card).length > 0 ? { card } : {}, lines };
|
|
321
|
+
}
|
|
322
|
+
function isoInstant(value) {
|
|
323
|
+
if (value === void 0 || value === null) return null;
|
|
324
|
+
const ms = Date.parse(value);
|
|
325
|
+
return Number.isFinite(ms) ? new Date(ms).toISOString() : value;
|
|
326
|
+
}
|
|
327
|
+
function sameAppliesTo(a, b) {
|
|
328
|
+
const aKeys = Object.keys(a).sort();
|
|
329
|
+
const bKeys = Object.keys(b).sort();
|
|
330
|
+
if (!sameList(aKeys, bKeys)) return false;
|
|
331
|
+
return aKeys.every((key) => sameList(a[key] ?? [], b[key] ?? []));
|
|
332
|
+
}
|
|
333
|
+
function editNotes(args, stored, bodyFile, clears) {
|
|
334
|
+
if (bodyFile === void 0) return [];
|
|
335
|
+
const notes = [];
|
|
336
|
+
if (bodyFile.hadFrontmatter) {
|
|
337
|
+
notes.push(
|
|
338
|
+
"note: frontmatter in the body file was ignored; metadata changes only through flags."
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
if (args.excerpt === void 0) {
|
|
342
|
+
notes.push(
|
|
343
|
+
`note: the excerpt stays as-is (${preview(stored.excerpt)}) and remains lexically indexed; the server does not re-derive it. Pass --excerpt to change it.`
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
const asOfMoves = args.asOf !== void 0 || clears.includes("asOf");
|
|
347
|
+
if (stored.resource?.temporalMode === "snapshot" && !asOfMoves) {
|
|
348
|
+
notes.push(
|
|
349
|
+
`note: asOf is unchanged (${preview(stored.resource.asOf)}) on this snapshot card, and search freshness gating uses it. Pass --as-of to move it.`
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
return notes;
|
|
353
|
+
}
|
|
354
|
+
var CLEAR_FIELDS = [
|
|
355
|
+
"scope",
|
|
356
|
+
"exclusions",
|
|
357
|
+
"asOf",
|
|
358
|
+
"validUntil",
|
|
359
|
+
"provenance",
|
|
360
|
+
"methodology",
|
|
361
|
+
"supersedesPostId",
|
|
362
|
+
"questionsAnswered",
|
|
363
|
+
"tasksSupported",
|
|
364
|
+
"appliesTo"
|
|
365
|
+
];
|
|
366
|
+
var CLEAR_KEY = {
|
|
367
|
+
scope: "scope",
|
|
368
|
+
exclusions: "exclusions",
|
|
369
|
+
asOf: "asOf",
|
|
370
|
+
validUntil: "validUntil",
|
|
371
|
+
provenance: "provenanceSummary",
|
|
372
|
+
methodology: "methodologySummary",
|
|
373
|
+
supersedesPostId: "supersedesPostId",
|
|
374
|
+
questionsAnswered: "questionsAnswered",
|
|
375
|
+
tasksSupported: "tasksSupported",
|
|
376
|
+
appliesTo: "appliesTo"
|
|
377
|
+
};
|
|
378
|
+
var CLEAR_VALUE = {
|
|
379
|
+
scope: null,
|
|
380
|
+
exclusions: null,
|
|
381
|
+
asOf: null,
|
|
382
|
+
validUntil: null,
|
|
383
|
+
provenance: null,
|
|
384
|
+
methodology: null,
|
|
385
|
+
supersedesPostId: null,
|
|
386
|
+
questionsAnswered: [],
|
|
387
|
+
tasksSupported: [],
|
|
388
|
+
appliesTo: {}
|
|
389
|
+
};
|
|
390
|
+
var CLEAR_CONFLICTS = {
|
|
391
|
+
scope: ["scope"],
|
|
392
|
+
exclusions: ["exclusions"],
|
|
393
|
+
asOf: ["asOf"],
|
|
394
|
+
validUntil: ["validUntil"],
|
|
395
|
+
provenance: ["provenance"],
|
|
396
|
+
methodology: ["methodology"],
|
|
397
|
+
supersedesPostId: [],
|
|
398
|
+
questionsAnswered: ["question", "addQuestion"],
|
|
399
|
+
tasksSupported: ["task", "addTask"],
|
|
400
|
+
appliesTo: ["appliesTo"]
|
|
401
|
+
};
|
|
402
|
+
var FLAG_NAME = {
|
|
403
|
+
question: "--question",
|
|
404
|
+
task: "--task",
|
|
405
|
+
addQuestion: "--add-question",
|
|
406
|
+
addTask: "--add-task",
|
|
407
|
+
scope: "--scope",
|
|
408
|
+
exclusions: "--exclusions",
|
|
409
|
+
appliesTo: "--applies-to",
|
|
410
|
+
asOf: "--as-of",
|
|
411
|
+
validUntil: "--valid-until",
|
|
412
|
+
artifactType: "--artifact-type",
|
|
413
|
+
temporalMode: "--temporal-mode",
|
|
414
|
+
provenance: "--provenance",
|
|
415
|
+
methodology: "--methodology",
|
|
416
|
+
title: "--title",
|
|
417
|
+
price: "--price",
|
|
418
|
+
body: "--body",
|
|
419
|
+
excerpt: "--excerpt"
|
|
420
|
+
};
|
|
421
|
+
var CHANGE_KEYS = [
|
|
422
|
+
"question",
|
|
423
|
+
"task",
|
|
424
|
+
"addQuestion",
|
|
425
|
+
"addTask",
|
|
426
|
+
"scope",
|
|
427
|
+
"exclusions",
|
|
428
|
+
"appliesTo",
|
|
429
|
+
"asOf",
|
|
430
|
+
"validUntil",
|
|
431
|
+
"artifactType",
|
|
432
|
+
"temporalMode",
|
|
433
|
+
"provenance",
|
|
434
|
+
"methodology",
|
|
435
|
+
"title",
|
|
436
|
+
"price",
|
|
437
|
+
"body",
|
|
438
|
+
"excerpt",
|
|
439
|
+
"clear"
|
|
440
|
+
];
|
|
441
|
+
function hasChangeFlags(args) {
|
|
442
|
+
return CHANGE_KEYS.some((key) => {
|
|
443
|
+
const value = args[key];
|
|
444
|
+
return Array.isArray(value) ? value.length > 0 : value !== void 0;
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
function rejectEmptyValues(args) {
|
|
448
|
+
for (const [key, flag] of Object.entries(FLAG_NAME)) {
|
|
449
|
+
const value = args[key];
|
|
450
|
+
const empties = typeof value === "string" ? [value] : Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
451
|
+
for (const v of empties) {
|
|
452
|
+
if (v.trim().length === 0) {
|
|
453
|
+
const clearable = CLEAR_FIELDS.includes(clearNameFor(key));
|
|
454
|
+
throw new CliError("USAGE", `${flag} cannot be empty.`, {
|
|
455
|
+
fix: clearable ? `Pass a value, or clear the field with \`--clear ${clearNameFor(key)}\`.` : "Pass a value, or omit the flag to keep the stored one."
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function clearNameFor(key) {
|
|
462
|
+
if (key === "question" || key === "addQuestion") return "questionsAnswered";
|
|
463
|
+
if (key === "task" || key === "addTask") return "tasksSupported";
|
|
464
|
+
return key;
|
|
465
|
+
}
|
|
466
|
+
function assertAppendExclusivity(args) {
|
|
467
|
+
const both = (a, b) => a !== void 0 && a.length > 0 && b !== void 0 && b.length > 0;
|
|
468
|
+
if (both(args.question, args.addQuestion)) {
|
|
469
|
+
throw new CliError("USAGE", "Pass either --question or --add-question, not both.", {
|
|
470
|
+
fix: "--question replaces the stored questions; --add-question appends to them."
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
if (both(args.task, args.addTask)) {
|
|
474
|
+
throw new CliError("USAGE", "Pass either --task or --add-task, not both.", {
|
|
475
|
+
fix: "--task replaces the stored tasks; --add-task appends to them."
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function parseClears(args) {
|
|
480
|
+
const raw = args.clear ?? [];
|
|
481
|
+
const out = [];
|
|
482
|
+
for (const name of raw) {
|
|
483
|
+
if (!CLEAR_FIELDS.includes(name)) {
|
|
484
|
+
throw new CliError("USAGE", `Cannot clear ${JSON.stringify(name)}.`, {
|
|
485
|
+
fix: `Clearable fields: ${CLEAR_FIELDS.join(", ")}.`
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
const field = name;
|
|
489
|
+
for (const key of CLEAR_CONFLICTS[field]) {
|
|
490
|
+
const value = args[key];
|
|
491
|
+
const given = Array.isArray(value) ? value.length > 0 : value !== void 0;
|
|
492
|
+
if (given) {
|
|
493
|
+
throw new CliError(
|
|
494
|
+
"USAGE",
|
|
495
|
+
`--clear ${field} contradicts ${FLAG_NAME[key] ?? String(key)}.`,
|
|
496
|
+
{ fix: "Set the field or clear it, not both in the same run." }
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (!out.includes(field)) out.push(field);
|
|
501
|
+
}
|
|
502
|
+
return out;
|
|
503
|
+
}
|
|
504
|
+
function cardFlagsFrom(args) {
|
|
505
|
+
return {
|
|
506
|
+
...args.question !== void 0 && args.question.length > 0 ? { question: args.question } : {},
|
|
507
|
+
...args.task !== void 0 && args.task.length > 0 ? { task: args.task } : {},
|
|
508
|
+
...args.scope !== void 0 ? { scope: args.scope } : {},
|
|
509
|
+
...args.exclusions !== void 0 ? { exclusions: args.exclusions } : {},
|
|
510
|
+
...args.asOf !== void 0 ? { asOf: args.asOf } : {},
|
|
511
|
+
...args.validUntil !== void 0 ? { validUntil: args.validUntil } : {},
|
|
512
|
+
...args.artifactType !== void 0 ? { artifactType: args.artifactType } : {},
|
|
513
|
+
...args.temporalMode !== void 0 ? { temporalMode: args.temporalMode } : {},
|
|
514
|
+
...args.provenance !== void 0 ? { provenance: args.provenance } : {},
|
|
515
|
+
...args.methodology !== void 0 ? { methodology: args.methodology } : {},
|
|
516
|
+
...args.appliesTo !== void 0 && args.appliesTo.length > 0 ? { appliesTo: parseAppliesToFlags(args.appliesTo) } : {}
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
function withClears(set, clears, stored) {
|
|
520
|
+
const applicable = stored !== void 0 ? clears : [];
|
|
521
|
+
if (set === void 0 && applicable.length === 0) return {};
|
|
522
|
+
const card = { ...set ?? {} };
|
|
523
|
+
for (const name of applicable) {
|
|
524
|
+
card[CLEAR_KEY[name]] = CLEAR_VALUE[name];
|
|
525
|
+
}
|
|
526
|
+
return Object.keys(card).length > 0 ? { resource: card } : {};
|
|
527
|
+
}
|
|
528
|
+
async function readBodyFile(file) {
|
|
529
|
+
let raw;
|
|
530
|
+
try {
|
|
531
|
+
raw = await readFile(file, "utf8");
|
|
532
|
+
} catch (err) {
|
|
533
|
+
throw new CliError("USAGE", `Could not read ${JSON.stringify(file)}`, {
|
|
534
|
+
fix: "Pass a path to a readable Markdown file, e.g. `tenjin edit <id> --body post.md`.",
|
|
535
|
+
cause: err
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
const { frontmatter, body } = parseFrontmatter(raw);
|
|
539
|
+
return { raw, body, hadFrontmatter: Object.keys(frontmatter).length > 0 };
|
|
540
|
+
}
|
|
541
|
+
function storedList(post, key) {
|
|
542
|
+
return post.resource?.[key] ?? [];
|
|
543
|
+
}
|
|
544
|
+
function appendUnique(stored, additions) {
|
|
545
|
+
const out = [...stored];
|
|
546
|
+
for (const item of additions) {
|
|
547
|
+
if (!out.includes(item)) out.push(item);
|
|
548
|
+
}
|
|
549
|
+
return out;
|
|
550
|
+
}
|
|
551
|
+
function shippedTypedText(args, input) {
|
|
552
|
+
const parts = [];
|
|
553
|
+
const add = (v) => {
|
|
554
|
+
if (v !== void 0) parts.push(v);
|
|
555
|
+
};
|
|
556
|
+
if (input.title !== void 0) add(args.title);
|
|
557
|
+
if (input.excerpt !== void 0) add(args.excerpt);
|
|
558
|
+
const card = input.resource;
|
|
559
|
+
if (card === void 0) return parts.join("\n");
|
|
560
|
+
if (card.scope !== void 0) add(args.scope);
|
|
561
|
+
if (card.exclusions !== void 0) add(args.exclusions);
|
|
562
|
+
if (card.provenanceSummary !== void 0) add(args.provenance);
|
|
563
|
+
if (card.methodologySummary !== void 0) add(args.methodology);
|
|
564
|
+
if (card.asOf !== void 0) add(args.asOf);
|
|
565
|
+
if (card.validUntil !== void 0) add(args.validUntil);
|
|
566
|
+
if (card.questionsAnswered !== void 0) {
|
|
567
|
+
for (const item of args.question ?? args.addQuestion ?? []) add(item);
|
|
568
|
+
}
|
|
569
|
+
if (card.tasksSupported !== void 0) {
|
|
570
|
+
for (const item of args.task ?? args.addTask ?? []) add(item);
|
|
571
|
+
}
|
|
572
|
+
if (card.appliesTo !== void 0 && args.appliesTo !== void 0) {
|
|
573
|
+
for (const values of Object.values(parseAppliesToFlags(args.appliesTo))) parts.push(...values);
|
|
574
|
+
}
|
|
575
|
+
return parts.join("\n");
|
|
576
|
+
}
|
|
577
|
+
function blockMessage(blocking) {
|
|
578
|
+
return `Edit blocked: the new content contains ${describeFindings(blocking)}.`;
|
|
579
|
+
}
|
|
580
|
+
function confirmMessage(warnCount, changeCount) {
|
|
581
|
+
return warnCount > 0 ? `Edit needs confirmation: ${changeCount} change(s), ${warnCount} finding(s).` : `Edit needs confirmation: ${changeCount} change(s).`;
|
|
582
|
+
}
|
|
583
|
+
var PREVIEW_MAX = 60;
|
|
584
|
+
var LINE_MAX = 200;
|
|
585
|
+
function clip(value, max = PREVIEW_MAX) {
|
|
586
|
+
const clean = sanitizeForTerminal(value).replace(/\s+/g, " ").trim();
|
|
587
|
+
return clean.length > max ? `${clean.slice(0, max)}\u2026` : clean;
|
|
588
|
+
}
|
|
589
|
+
function preview(value) {
|
|
590
|
+
if (value === void 0 || value === null || value.length === 0) return "(unset)";
|
|
591
|
+
const clean = sanitizeForTerminal(value).replace(/\s+/g, " ").trim();
|
|
592
|
+
if (clean.length === 0) return "(unset)";
|
|
593
|
+
return clean.length > PREVIEW_MAX ? `${JSON.stringify(clean.slice(0, PREVIEW_MAX))}\u2026` : JSON.stringify(clean);
|
|
594
|
+
}
|
|
595
|
+
function previewList(values) {
|
|
596
|
+
return values.map((v) => preview(v)).join(", ");
|
|
597
|
+
}
|
|
598
|
+
function appliesToPreview(appliesTo) {
|
|
599
|
+
const entries = Object.entries(appliesTo);
|
|
600
|
+
if (entries.length === 0) return "(unset)";
|
|
601
|
+
const rendered = entries.map(([key, values]) => `${clip(key)}=${values.map((v) => clip(v)).join("|")}`).join(", ");
|
|
602
|
+
return clip(rendered, LINE_MAX);
|
|
603
|
+
}
|
|
604
|
+
function sameList(a, b) {
|
|
605
|
+
return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
606
|
+
}
|
|
607
|
+
function hasText(value) {
|
|
608
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
export {
|
|
612
|
+
runEdit
|
|
613
|
+
};
|
|
614
|
+
//# sourceMappingURL=chunk-EDENZN2Q.js.map
|