tenjin-cli 0.1.0-alpha.13 → 0.1.0-alpha.14
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 +35 -2
- package/dist/{buy-X4VPHFUA.js → buy-2JBYPHAI.js} +16 -14
- package/dist/{chunk-6JKD46OJ.js → chunk-3ZW7HPY5.js} +4 -4
- package/dist/chunk-4UHNXY6B.js +786 -0
- package/dist/chunk-4UHNXY6B.js.map +1 -0
- package/dist/{chunk-IFPKA32J.js → chunk-4Y53PDH6.js} +2 -2
- package/dist/{chunk-SPUORKD7.js → chunk-54AJIO3E.js} +11 -12
- package/dist/chunk-54AJIO3E.js.map +1 -0
- package/dist/{chunk-JVBMPU5G.js → chunk-7GJQ5RGA.js} +5 -3
- package/dist/{chunk-JVBMPU5G.js.map → chunk-7GJQ5RGA.js.map} +1 -1
- package/dist/{chunk-BRAVLUGI.js → chunk-7NADDA2V.js} +9 -6
- package/dist/{chunk-BRAVLUGI.js.map → chunk-7NADDA2V.js.map} +1 -1
- package/dist/{chunk-T4UWMVKV.js → chunk-ACBEHJAH.js} +4 -4
- package/dist/{chunk-XXY77EZJ.js → chunk-DAZAXFSF.js} +7 -7
- package/dist/{chunk-OE36HRWG.js → chunk-DTCXO7HS.js} +257 -405
- package/dist/chunk-DTCXO7HS.js.map +1 -0
- package/dist/{chunk-CA3JV7FX.js → chunk-ETKZWJ4B.js} +2 -2
- package/dist/{chunk-CA3JV7FX.js.map → chunk-ETKZWJ4B.js.map} +1 -1
- package/dist/{chunk-NKN4YC5C.js → chunk-FDUD3W5V.js} +2 -2
- package/dist/{chunk-L4XNT3UW.js → chunk-GEHL43VE.js} +49 -17
- package/dist/chunk-GEHL43VE.js.map +1 -0
- package/dist/chunk-IU2HVT3Y.js +313 -0
- package/dist/chunk-IU2HVT3Y.js.map +1 -0
- package/dist/{chunk-OXUJ3FXU.js → chunk-IUQZ4Z7M.js} +36 -8
- package/dist/chunk-IUQZ4Z7M.js.map +1 -0
- package/dist/{chunk-YMUJZWHB.js → chunk-IXZJ3JOO.js} +5 -5
- package/dist/{chunk-47YKYDOF.js → chunk-L6G35FU5.js} +2 -2
- package/dist/{chunk-ELVDOTU7.js → chunk-LSWP7MU2.js} +4 -4
- package/dist/chunk-LSWP7MU2.js.map +1 -0
- package/dist/{chunk-OUJDDY5L.js → chunk-MJSXP4LW.js} +30 -28
- package/dist/chunk-MJSXP4LW.js.map +1 -0
- package/dist/{chunk-WVHPGQH5.js → chunk-NAAMHWSI.js} +5 -2
- package/dist/chunk-NAAMHWSI.js.map +1 -0
- package/dist/{chunk-IKAJSA7E.js → chunk-O75FOHXS.js} +29 -11
- package/dist/chunk-O75FOHXS.js.map +1 -0
- package/dist/{chunk-WMFRCSNC.js → chunk-PCX2JQ2J.js} +3 -3
- package/dist/{chunk-IGHSLJUF.js → chunk-PKW3H26Z.js} +5 -5
- package/dist/{chunk-3NZCU6SD.js → chunk-PQZVDCCA.js} +4 -4
- package/dist/{chunk-OC3EIDCP.js → chunk-QWBUKIP2.js} +7 -1
- package/dist/chunk-QWBUKIP2.js.map +1 -0
- package/dist/{chunk-FKSAUOJU.js → chunk-UO22YNY4.js} +1 -69
- package/dist/chunk-UO22YNY4.js.map +1 -0
- package/dist/chunk-VEAERJVJ.js +43 -0
- package/dist/chunk-VEAERJVJ.js.map +1 -0
- package/dist/{chunk-GCGMXA2O.js → chunk-VRPLZERE.js} +16 -5
- package/dist/chunk-VRPLZERE.js.map +1 -0
- package/dist/{chunk-IAR25V2E.js → chunk-W4VW5XYB.js} +4 -4
- package/dist/chunk-WYLMJQVH.js +240 -0
- package/dist/chunk-WYLMJQVH.js.map +1 -0
- package/dist/{chunk-TXVC46SA.js → chunk-XVPQGCH4.js} +11 -10
- package/dist/chunk-XVPQGCH4.js.map +1 -0
- package/dist/chunk-ZOBNS7CX.js +73 -0
- package/dist/chunk-ZOBNS7CX.js.map +1 -0
- package/dist/{cli-XK5JZWU6.js → cli-U2BEUA55.js} +34 -36
- package/dist/{cli-XK5JZWU6.js.map → cli-U2BEUA55.js.map} +1 -1
- package/dist/{config-CNK7MYUR.js → config-CNUIX23Q.js} +12 -6
- package/dist/{doctor-R7N7FUX5.js → doctor-QJJXRWTO.js} +11 -7
- package/dist/{edit-QSUEG7CL.js → edit-HJ44P44P.js} +13 -11
- package/dist/{fund-JF6A76YS.js → fund-Y5IAHZ5D.js} +10 -8
- package/dist/index.js +1 -1
- package/dist/{inspect-NFNAA4LA.js → inspect-NFQ6SQQQ.js} +14 -12
- package/dist/{install-YQVM3SUW.js → install-DXX7PVUP.js} +122 -401
- package/dist/install-DXX7PVUP.js.map +1 -0
- package/dist/outcome-ANV4QIED.js +24 -0
- package/dist/{publish-O2I6IAEL.js → publish-PCBTCXCZ.js} +14 -12
- package/dist/{read-UF7QVQOU.js → read-W7QVRBVD.js} +14 -12
- package/dist/{read-UF7QVQOU.js.map → read-W7QVRBVD.js.map} +1 -1
- package/dist/{run-GDZWHNWZ.js → run-CJWPGMIQ.js} +26 -24
- package/dist/{run-GDZWHNWZ.js.map → run-CJWPGMIQ.js.map} +1 -1
- package/dist/search-JGAVKTYJ.js +25 -0
- package/dist/{send-SI254H3R.js → send-C5EOKXOU.js} +7 -6
- package/dist/{send-SI254H3R.js.map → send-C5EOKXOU.js.map} +1 -1
- package/dist/{session-GJZJEXLJ.js → session-OBCUUIFX.js} +7 -6
- package/dist/{session-GJZJEXLJ.js.map → session-OBCUUIFX.js.map} +1 -1
- package/dist/{skill-heal-BPFT22XS.js → skill-heal-D6EPLPS6.js} +3 -3
- package/dist/skill-heal-D6EPLPS6.js.map +1 -0
- package/dist/{uninstall-7ZZG6WQ5.js → uninstall-OWJNJ5LI.js} +11 -5
- package/dist/uninstall-OWJNJ5LI.js.map +1 -0
- package/dist/{update-FPSBITLB.js → update-24Y2CQTT.js} +16 -13
- package/dist/update-24Y2CQTT.js.map +1 -0
- package/dist/{wallet-TZVD2M4I.js → wallet-OFXDIIGP.js} +7 -6
- package/dist/{wallet-NS7TYWNN.js → wallet-SLRIYJ2U.js} +4 -3
- package/docs/agent-permissions.md +100 -16
- package/docs/command-reference.md +21 -11
- package/package.json +1 -1
- package/skills/tenjin-publish/SKILL.md +181 -205
- package/skills/tenjin-publish/references/maintain.md +39 -0
- package/skills/tenjin-search/SKILL.md +86 -279
- package/skills/tenjin-search/references/permissions.md +106 -0
- package/dist/chunk-ELVDOTU7.js.map +0 -1
- package/dist/chunk-FKSAUOJU.js.map +0 -1
- package/dist/chunk-GCGMXA2O.js.map +0 -1
- package/dist/chunk-IKAJSA7E.js.map +0 -1
- package/dist/chunk-L4XNT3UW.js.map +0 -1
- package/dist/chunk-OC3EIDCP.js.map +0 -1
- package/dist/chunk-OE36HRWG.js.map +0 -1
- package/dist/chunk-OUJDDY5L.js.map +0 -1
- package/dist/chunk-OXUJ3FXU.js.map +0 -1
- package/dist/chunk-SPUORKD7.js.map +0 -1
- package/dist/chunk-TXVC46SA.js.map +0 -1
- package/dist/chunk-UUARTUY2.js +0 -349
- package/dist/chunk-UUARTUY2.js.map +0 -1
- package/dist/chunk-WVHPGQH5.js.map +0 -1
- package/dist/install-YQVM3SUW.js.map +0 -1
- package/dist/outcome-IUSYFJTN.js +0 -22
- package/dist/search-JVOHEF3E.js +0 -23
- package/dist/skill-heal-BPFT22XS.js.map +0 -1
- package/dist/uninstall-7ZZG6WQ5.js.map +0 -1
- package/dist/update-FPSBITLB.js.map +0 -1
- /package/dist/{buy-X4VPHFUA.js.map → buy-2JBYPHAI.js.map} +0 -0
- /package/dist/{chunk-6JKD46OJ.js.map → chunk-3ZW7HPY5.js.map} +0 -0
- /package/dist/{chunk-IFPKA32J.js.map → chunk-4Y53PDH6.js.map} +0 -0
- /package/dist/{chunk-T4UWMVKV.js.map → chunk-ACBEHJAH.js.map} +0 -0
- /package/dist/{chunk-XXY77EZJ.js.map → chunk-DAZAXFSF.js.map} +0 -0
- /package/dist/{chunk-NKN4YC5C.js.map → chunk-FDUD3W5V.js.map} +0 -0
- /package/dist/{chunk-YMUJZWHB.js.map → chunk-IXZJ3JOO.js.map} +0 -0
- /package/dist/{chunk-47YKYDOF.js.map → chunk-L6G35FU5.js.map} +0 -0
- /package/dist/{chunk-WMFRCSNC.js.map → chunk-PCX2JQ2J.js.map} +0 -0
- /package/dist/{chunk-IGHSLJUF.js.map → chunk-PKW3H26Z.js.map} +0 -0
- /package/dist/{chunk-3NZCU6SD.js.map → chunk-PQZVDCCA.js.map} +0 -0
- /package/dist/{chunk-IAR25V2E.js.map → chunk-W4VW5XYB.js.map} +0 -0
- /package/dist/{config-CNK7MYUR.js.map → config-CNUIX23Q.js.map} +0 -0
- /package/dist/{doctor-R7N7FUX5.js.map → doctor-QJJXRWTO.js.map} +0 -0
- /package/dist/{edit-QSUEG7CL.js.map → edit-HJ44P44P.js.map} +0 -0
- /package/dist/{fund-JF6A76YS.js.map → fund-Y5IAHZ5D.js.map} +0 -0
- /package/dist/{inspect-NFNAA4LA.js.map → inspect-NFQ6SQQQ.js.map} +0 -0
- /package/dist/{outcome-IUSYFJTN.js.map → outcome-ANV4QIED.js.map} +0 -0
- /package/dist/{publish-O2I6IAEL.js.map → publish-PCBTCXCZ.js.map} +0 -0
- /package/dist/{search-JVOHEF3E.js.map → search-JGAVKTYJ.js.map} +0 -0
- /package/dist/{wallet-NS7TYWNN.js.map → wallet-OFXDIIGP.js.map} +0 -0
- /package/dist/{wallet-TZVD2M4I.js.map → wallet-SLRIYJ2U.js.map} +0 -0
|
@@ -1,194 +1,17 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
skillFrontmatterName,
|
|
13
|
-
skillsDirsFor
|
|
14
|
-
} from "./chunk-OC3EIDCP.js";
|
|
15
|
-
import {
|
|
16
|
-
writeFileAtomic
|
|
17
|
-
} from "./chunk-PAOVPSP6.js";
|
|
18
|
-
|
|
19
|
-
// src/lib/harness-permissions.ts
|
|
20
|
-
import { lstat, readFile, realpath } from "fs/promises";
|
|
21
|
-
import { join } from "path";
|
|
22
|
-
function claudeSettingsPath(homeDir) {
|
|
23
|
-
return join(homeDir, ".claude", "settings.json");
|
|
24
|
-
}
|
|
25
|
-
var FREE_VERB_RULES = [
|
|
26
|
-
"Bash(tenjin search:*)",
|
|
27
|
-
"Bash(tenjin fund:*)",
|
|
28
|
-
"Bash(tenjin inspect:*)",
|
|
29
|
-
"Bash(tenjin read:*)",
|
|
30
|
-
"Bash(tenjin outcome:*)",
|
|
31
|
-
"Bash(tenjin doctor:*)",
|
|
32
|
-
"Bash(tenjin wallet show:*)",
|
|
33
|
-
"Bash(tenjin wallet balance:*)",
|
|
34
|
-
"Bash(tenjin config get:*)"
|
|
35
|
-
];
|
|
36
|
-
var LEGACY_FREE_VERB_RULES = ["Bash(tenjin candidate list:*)"];
|
|
37
|
-
function fixFor(reason) {
|
|
38
|
-
switch (reason) {
|
|
39
|
-
case "harness-not-claude":
|
|
40
|
-
return "This allowlist is Claude Code only. Run `tenjin doctor` for the lines your harness needs.";
|
|
41
|
-
case "not-requested":
|
|
42
|
-
case "declined":
|
|
43
|
-
case "dry-run":
|
|
44
|
-
return "Add them with `tenjin install --allow-free-verbs`.";
|
|
45
|
-
case "changed-since-read":
|
|
46
|
-
return "Another process changed the file mid-run; re-run `tenjin install`.";
|
|
47
|
-
default:
|
|
48
|
-
return "Fix the reported file, then run `tenjin install --allow-free-verbs`.";
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function skip(harness, path, reason, warning) {
|
|
52
|
-
return {
|
|
53
|
-
harness,
|
|
54
|
-
...path !== void 0 ? { path } : {},
|
|
55
|
-
added: [],
|
|
56
|
-
removed: [],
|
|
57
|
-
alreadyPresent: [],
|
|
58
|
-
skipped: reason,
|
|
59
|
-
...warning !== void 0 ? { warning } : {},
|
|
60
|
-
fix: fixFor(reason)
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function permissionsSkipped(harness, homeDir, reason) {
|
|
64
|
-
const path = harness === "claude" ? claudeSettingsPath(homeDir) : void 0;
|
|
65
|
-
return skip(harness, path, reason);
|
|
66
|
-
}
|
|
67
|
-
function isPlainObject(value) {
|
|
68
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
69
|
-
}
|
|
70
|
-
async function wireFreeVerbAllowlist(homeDir) {
|
|
71
|
-
const found = await inspectAllowlist(homeDir);
|
|
72
|
-
if ("result" in found) return found.result;
|
|
73
|
-
const { path, raw, settings, permissions, allow, added, alreadyPresent } = found;
|
|
74
|
-
const retired = new Set(LEGACY_FREE_VERB_RULES);
|
|
75
|
-
const removed = allow.filter((r) => typeof r === "string" && retired.has(r));
|
|
76
|
-
if (added.length === 0 && removed.length === 0) {
|
|
77
|
-
return { harness: "claude", path, added: [], alreadyPresent, removed: [] };
|
|
78
|
-
}
|
|
79
|
-
const kept = allow.filter((r) => !(typeof r === "string" && retired.has(r)));
|
|
80
|
-
const next = {
|
|
81
|
-
...settings,
|
|
82
|
-
permissions: { ...permissions, allow: [...kept, ...added] }
|
|
83
|
-
};
|
|
84
|
-
const current = await readFile(path, "utf8").catch(() => null);
|
|
85
|
-
if (current !== raw) {
|
|
86
|
-
return skip(
|
|
87
|
-
"claude",
|
|
88
|
-
path,
|
|
89
|
-
"changed-since-read",
|
|
90
|
-
`${path} changed while it was being updated, so nothing was written. Re-run \`tenjin install\`.`
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
await writeFileAtomic(path, `${JSON.stringify(next, null, 2)}
|
|
94
|
-
`);
|
|
95
|
-
return { harness: "claude", path, added, alreadyPresent, removed };
|
|
96
|
-
}
|
|
97
|
-
async function inspectFreeVerbRules(homeDir) {
|
|
98
|
-
const found = await inspectAllowlist(homeDir);
|
|
99
|
-
if ("result" in found) return { pending: null };
|
|
100
|
-
if (found.added.length > 0) return { pending: found.added };
|
|
101
|
-
const retired = new Set(LEGACY_FREE_VERB_RULES);
|
|
102
|
-
if (found.allow.some((r) => typeof r === "string" && retired.has(r))) return { pending: [] };
|
|
103
|
-
return {
|
|
104
|
-
pending: [],
|
|
105
|
-
satisfied: {
|
|
106
|
-
harness: "claude",
|
|
107
|
-
path: found.path,
|
|
108
|
-
added: [],
|
|
109
|
-
alreadyPresent: found.alreadyPresent,
|
|
110
|
-
removed: []
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
async function inspectAllowlist(homeDir) {
|
|
115
|
-
const declaredPath = claudeSettingsPath(homeDir);
|
|
116
|
-
const refuse = (p, reason, warning) => ({ result: skip("claude", p, reason, warning) });
|
|
117
|
-
const entry = await lstat(declaredPath).catch(() => null);
|
|
118
|
-
let path = declaredPath;
|
|
119
|
-
if (entry !== null) {
|
|
120
|
-
try {
|
|
121
|
-
path = await realpath(declaredPath);
|
|
122
|
-
} catch (err) {
|
|
123
|
-
return refuse(
|
|
124
|
-
declaredPath,
|
|
125
|
-
"unresolvable",
|
|
126
|
-
`${declaredPath} could not be resolved (${err.message}); it was left exactly as it is.`
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
let settings = {};
|
|
131
|
-
let raw = null;
|
|
132
|
-
if (entry !== null) {
|
|
133
|
-
try {
|
|
134
|
-
raw = await readFile(path, "utf8");
|
|
135
|
-
} catch (err) {
|
|
136
|
-
return refuse(
|
|
137
|
-
path,
|
|
138
|
-
"unreadable",
|
|
139
|
-
`${path} could not be read (${err.message}); no permissions were written.`
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
let parsed;
|
|
143
|
-
try {
|
|
144
|
-
parsed = JSON.parse(raw);
|
|
145
|
-
} catch (err) {
|
|
146
|
-
return refuse(
|
|
147
|
-
path,
|
|
148
|
-
"unparsable",
|
|
149
|
-
`${path} is not valid JSON (${err.message}); it was left exactly as it is.`
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
if (!isPlainObject(parsed)) {
|
|
153
|
-
return refuse(
|
|
154
|
-
path,
|
|
155
|
-
"unexpected-shape",
|
|
156
|
-
`${path} is not a JSON object; it was left exactly as it is.`
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
settings = parsed;
|
|
160
|
-
}
|
|
161
|
-
const permissionsValue = settings.permissions;
|
|
162
|
-
if (permissionsValue !== void 0 && !isPlainObject(permissionsValue)) {
|
|
163
|
-
return refuse(
|
|
164
|
-
path,
|
|
165
|
-
"unexpected-shape",
|
|
166
|
-
`${path} has a "permissions" key that is not an object; it was left exactly as it is.`
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
const permissions = permissionsValue ?? {};
|
|
170
|
-
const allowValue = permissions.allow;
|
|
171
|
-
if (allowValue !== void 0 && !Array.isArray(allowValue)) {
|
|
172
|
-
return refuse(
|
|
173
|
-
path,
|
|
174
|
-
"unexpected-shape",
|
|
175
|
-
`${path} has a "permissions.allow" key that is not an array; it was left exactly as it is.`
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
const allow = allowValue ?? [];
|
|
179
|
-
const present = new Set(allow.filter((e) => typeof e === "string"));
|
|
180
|
-
const added = FREE_VERB_RULES.filter((rule) => !present.has(rule));
|
|
181
|
-
const alreadyPresent = FREE_VERB_RULES.filter((rule) => present.has(rule));
|
|
182
|
-
return { path, raw, settings, permissions, allow, added, alreadyPresent: [...alreadyPresent] };
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// src/lib/uninstall.ts
|
|
186
|
-
import { lstat as lstat2, readFile as readFile2, readdir, rm, rmdir, realpath as realpath2 } from "fs/promises";
|
|
187
|
-
import { lstatSync } from "fs";
|
|
188
|
-
import { join as join2 } from "path";
|
|
3
|
+
CALLER_USER_AGENT_ENV,
|
|
4
|
+
PRINTABLE_ASCII_RE,
|
|
5
|
+
PRODUCT_RE,
|
|
6
|
+
TENJIN_COMMENT,
|
|
7
|
+
TENJIN_PRODUCT,
|
|
8
|
+
TENJIN_PRODUCT_NAME,
|
|
9
|
+
TENJIN_USER_AGENT,
|
|
10
|
+
USER_AGENT_MAX_LENGTH
|
|
11
|
+
} from "./chunk-VEAERJVJ.js";
|
|
189
12
|
|
|
190
13
|
// src/lib/hook-scripts.ts
|
|
191
|
-
var HOOK_SCRIPT_VERSION =
|
|
14
|
+
var HOOK_SCRIPT_VERSION = 17;
|
|
192
15
|
var WEBSEARCH_HOOK_FILE = "tenjin-websearch.mjs";
|
|
193
16
|
var STOP_HOOK_FILE = "tenjin-stop.mjs";
|
|
194
17
|
var SEARCH_TIMEOUT_MS = 2e3;
|
|
@@ -206,8 +29,9 @@ var REMIND_LINE = 'Tenjin (a marketplace of tested, paid answers) may already ha
|
|
|
206
29
|
function prelude(dataDir, watchdogMs) {
|
|
207
30
|
return `#!/usr/bin/env node
|
|
208
31
|
// tenjin-cli hook, generated by \`tenjin install\` (v${HOOK_SCRIPT_VERSION}). Safe to delete.
|
|
209
|
-
import { readFileSync, writeFileSync, renameSync, mkdirSync, rmSync } from 'node:fs';
|
|
210
|
-
import { join } from 'node:path';
|
|
32
|
+
import { readFileSync, writeFileSync, renameSync, mkdirSync, rmSync, statSync } from 'node:fs';
|
|
33
|
+
import { dirname, join } from 'node:path';
|
|
34
|
+
import { homedir } from 'node:os';
|
|
211
35
|
|
|
212
36
|
const DATA_DIR = ${JSON.stringify(dataDir)};
|
|
213
37
|
|
|
@@ -247,6 +71,11 @@ function isRecord(v) {
|
|
|
247
71
|
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
248
72
|
}
|
|
249
73
|
|
|
74
|
+
/** The three values \`publish.mode\` may take (lib/config.ts's PublishModeSchema). */
|
|
75
|
+
function isPublishMode(v) {
|
|
76
|
+
return v === 'review' || v === 'auto' || v === 'full-auto';
|
|
77
|
+
}
|
|
78
|
+
|
|
250
79
|
/**
|
|
251
80
|
* The harness session this event belongs to, or null when the payload does not
|
|
252
81
|
* name one. \`session_id\` is the documented field on every hook input, and null
|
|
@@ -256,7 +85,102 @@ function isRecord(v) {
|
|
|
256
85
|
function sessionIdOf(input) {
|
|
257
86
|
if (!isRecord(input)) return null;
|
|
258
87
|
const id = input.session_id;
|
|
259
|
-
|
|
88
|
+
// BOUNDED, because this becomes a hook-nags.json key held for a week and read
|
|
89
|
+
// at every turn end. Every other externally supplied string in that file is
|
|
90
|
+
// capped; an absurd one here falls back to the documented global behavior
|
|
91
|
+
// rather than growing the file it is stored in.
|
|
92
|
+
if (typeof id !== 'string' || id.length === 0 || id.length > 128) return null;
|
|
93
|
+
return id;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The session's working directory, which is where the next \`tenjin publish\`
|
|
98
|
+
* would run. Same parsed payload as the session id; null when unusable.
|
|
99
|
+
*/
|
|
100
|
+
function cwdOf(input) {
|
|
101
|
+
if (!isRecord(input)) return null;
|
|
102
|
+
const dir = input.cwd;
|
|
103
|
+
return typeof dir === 'string' && dir.length > 0 && dir.length <= 4096 ? dir : null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The project layer's publish.mode, walking up from \`start\` for a \`.tenjin.json\`.
|
|
108
|
+
*
|
|
109
|
+
* The Stop hook resolves this and the WebSearch hook does not, and the asymmetry
|
|
110
|
+
* is the point: a general hook's cwd may have nothing to do with the draft, but
|
|
111
|
+
* the Stop hook's cwd IS the session's working directory, so it is exactly where
|
|
112
|
+
* the publish it is talking about will run. Announcing the global mode there let
|
|
113
|
+
* an agent believe it held auto authority inside a repo the operator had pinned
|
|
114
|
+
* to review, and an exit 3 that is not a hard block is one \`--yes\` away from
|
|
115
|
+
* proceeding anyway.
|
|
116
|
+
*
|
|
117
|
+
* THE THREE BOUNDARIES ARE \`findProjectConfigFile\`'s, mirrored rule for rule. A
|
|
118
|
+
* generated hook cannot import lib/settings.ts, so the walk is duplicated, and a
|
|
119
|
+
* duplicate that drops a stop condition announces a mode the CLI will not run
|
|
120
|
+
* under. The first cut was a bare 12-level parent walk and diverged in BOTH
|
|
121
|
+
* directions: a \`~/.tenjin.json\` the CLI deliberately ignores made the hook
|
|
122
|
+
* promise unattended publishing that the CLI's own gate would then refuse.
|
|
123
|
+
*
|
|
124
|
+
* 1. Stop at the repo root. A directory's own \`.tenjin.json\` is checked BEFORE
|
|
125
|
+
* its \`.git\` probe, so a file AT the repo root is honored by both walks and
|
|
126
|
+
* the divergence begins strictly above it.
|
|
127
|
+
* 2. Never walk above \`$HOME\`.
|
|
128
|
+
* 3. Skip a file owned by another uid, then keep walking. On a shared host that
|
|
129
|
+
* is the difference between reading the operator's pin and reading a planted
|
|
130
|
+
* one; the CLI calls it a trust boundary and warns, and a hook stays silent.
|
|
131
|
+
*
|
|
132
|
+
* A project file may narrow, never widen, so \`full-auto\` from a project
|
|
133
|
+
* CONSERVATIVELY reads as \`auto\`. That is not an exact mirror: the CLI downgrades
|
|
134
|
+
* a committed project \`full-auto\` and honors a gitignored one, and this walk does
|
|
135
|
+
* not read .gitignore. It always announces the narrower of the two, which is the
|
|
136
|
+
* safe direction for a line an agent acts on. Every failure is silent and falls
|
|
137
|
+
* through to the global answer.
|
|
138
|
+
*/
|
|
139
|
+
function projectPublishMode(start) {
|
|
140
|
+
try {
|
|
141
|
+
const home = homedir();
|
|
142
|
+
const uid = typeof process.getuid === 'function' ? process.getuid() : undefined;
|
|
143
|
+
// Owned by someone else: skip the file and keep walking, exactly as
|
|
144
|
+
// findProjectConfigFile does. A platform with no uid model has no such gate.
|
|
145
|
+
const foreign = (path) => {
|
|
146
|
+
if (uid === undefined) return false;
|
|
147
|
+
try {
|
|
148
|
+
return statSync(path).uid !== uid;
|
|
149
|
+
} catch {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const exists = (path) => {
|
|
154
|
+
try {
|
|
155
|
+
statSync(path);
|
|
156
|
+
return true;
|
|
157
|
+
} catch {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
let dir = start;
|
|
163
|
+
for (;;) {
|
|
164
|
+
const candidate = join(dir, '.tenjin.json');
|
|
165
|
+
if (exists(candidate) && !foreign(candidate)) {
|
|
166
|
+
const found = readJsonFile(candidate);
|
|
167
|
+
if (isRecord(found)) {
|
|
168
|
+
const publish = isRecord(found.publish) ? found.publish : {};
|
|
169
|
+
const mode = publish.mode;
|
|
170
|
+
if (mode === 'review' || mode === 'auto') return mode;
|
|
171
|
+
if (mode === 'full-auto') return 'auto';
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
if (exists(join(dir, '.git'))) return null;
|
|
176
|
+
if (dir === home) return null;
|
|
177
|
+
const parent = dirname(dir);
|
|
178
|
+
if (parent === dir) return null;
|
|
179
|
+
dir = parent;
|
|
180
|
+
}
|
|
181
|
+
} catch {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
260
184
|
}
|
|
261
185
|
|
|
262
186
|
/**
|
|
@@ -265,16 +189,31 @@ function sessionIdOf(input) {
|
|
|
265
189
|
* off\` or \`hooks.stopNag off\` silences a hook immediately, with no re-install
|
|
266
190
|
* and nothing to unwire. An unreadable or unrecognized value falls back to the
|
|
267
191
|
* shipped default rather than failing.
|
|
192
|
+
*
|
|
193
|
+
* \`publishMode\` reads the global file and TENJIN_PUBLISH_MODE. \`envPinned\` says
|
|
194
|
+
* whether the env var decided it, because lib/config.ts resolves
|
|
195
|
+
* global < project < env < flag: an env var set for this process outranks a
|
|
196
|
+
* project file, so the caller must not layer one on top of it.
|
|
268
197
|
*/
|
|
269
198
|
function readConfig() {
|
|
270
199
|
const raw = readJsonFile(join(DATA_DIR, 'config.json'));
|
|
271
200
|
const cfg = isRecord(raw) ? raw : {};
|
|
272
201
|
const hooks = isRecord(cfg.hooks) ? cfg.hooks : {};
|
|
202
|
+
const publish = isRecord(cfg.publish) ? cfg.publish : {};
|
|
273
203
|
const mode = hooks.searchMode;
|
|
204
|
+
const nag = hooks.stopNag;
|
|
205
|
+
// env over file, matching lib/config.ts's resolvePublishMode; an unrecognized
|
|
206
|
+
// value in either place falls through to the shipped default rather than
|
|
207
|
+
// failing, exactly like every other key here.
|
|
208
|
+
const fromEnv = process.env.TENJIN_PUBLISH_MODE;
|
|
209
|
+
const envPinned = isPublishMode(fromEnv);
|
|
210
|
+
const publishMode = envPinned ? fromEnv : publish.mode;
|
|
274
211
|
const baseUrl = typeof cfg.baseUrl === 'string' ? cfg.baseUrl : 'https://tenjin.blog';
|
|
275
212
|
return {
|
|
276
213
|
mode: mode === 'off' || mode === 'remind' || mode === 'auto' ? mode : 'auto',
|
|
277
|
-
stopNag:
|
|
214
|
+
stopNag: nag === 'off' || nag === 'deliberate-only' ? nag : 'on',
|
|
215
|
+
publishMode: isPublishMode(publishMode) ? publishMode : 'review',
|
|
216
|
+
envPinned,
|
|
278
217
|
baseUrl,
|
|
279
218
|
};
|
|
280
219
|
}
|
|
@@ -371,8 +310,42 @@ function emit(hookEventName, additionalContext) {
|
|
|
371
310
|
}
|
|
372
311
|
`;
|
|
373
312
|
}
|
|
313
|
+
function userAgentSource() {
|
|
314
|
+
return `
|
|
315
|
+
const TENJIN_PRODUCT = ${JSON.stringify(TENJIN_PRODUCT)};
|
|
316
|
+
const TENJIN_USER_AGENT = ${JSON.stringify(TENJIN_USER_AGENT)};
|
|
317
|
+
const UA_COMMENT = ${JSON.stringify(TENJIN_COMMENT)};
|
|
318
|
+
const UA_PRODUCT_NAME = ${JSON.stringify(TENJIN_PRODUCT_NAME.toLowerCase())};
|
|
319
|
+
const UA_MAX_LENGTH = ${USER_AGENT_MAX_LENGTH};
|
|
320
|
+
const UA_PRODUCT_RE = ${PRODUCT_RE.toString()};
|
|
321
|
+
const UA_PRINTABLE_RE = ${PRINTABLE_ASCII_RE.toString()};
|
|
322
|
+
|
|
323
|
+
/** A copy of our own identity inside a caller value, in any casing. */
|
|
324
|
+
function isOwnUaIdentity(token) {
|
|
325
|
+
const lower = token.toLowerCase();
|
|
326
|
+
return lower === UA_COMMENT.toLowerCase() || lower === UA_PRODUCT_NAME ||
|
|
327
|
+
lower.startsWith(UA_PRODUCT_NAME + '/');
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Our product, then the launching harness's products in their order, then our
|
|
332
|
+
* comment. Rejection is TOTAL: a non-printable, non-product, or overlong handoff
|
|
333
|
+
* is omitted and the CLI identity travels alone, because truncating a product
|
|
334
|
+
* token would mint a different, false identity. This is self-reported telemetry
|
|
335
|
+
* and never trusted policy input.
|
|
336
|
+
*/
|
|
337
|
+
function composedUserAgent() {
|
|
338
|
+
const raw = process.env[${JSON.stringify(CALLER_USER_AGENT_ENV)}];
|
|
339
|
+
if (typeof raw !== 'string' || !UA_PRINTABLE_RE.test(raw)) return TENJIN_USER_AGENT;
|
|
340
|
+
const tokens = raw.split(' ').filter((t) => t.length > 0 && !isOwnUaIdentity(t));
|
|
341
|
+
if (tokens.length === 0 || !tokens.every((t) => UA_PRODUCT_RE.test(t))) return TENJIN_USER_AGENT;
|
|
342
|
+
const composed = TENJIN_PRODUCT + ' ' + tokens.join(' ') + ' ' + UA_COMMENT;
|
|
343
|
+
return composed.length <= UA_MAX_LENGTH ? composed : TENJIN_USER_AGENT;
|
|
344
|
+
}
|
|
345
|
+
`;
|
|
346
|
+
}
|
|
374
347
|
function websearchHookScript(dataDir) {
|
|
375
|
-
return `${prelude(dataDir, WATCHDOG_MS)}
|
|
348
|
+
return `${prelude(dataDir, WATCHDOG_MS)}${userAgentSource()}
|
|
376
349
|
const LOCK_PATH = SEARCH_STORE + '.lock';
|
|
377
350
|
|
|
378
351
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -504,7 +477,7 @@ async function main() {
|
|
|
504
477
|
|
|
505
478
|
const res = await fetch(url, {
|
|
506
479
|
method: 'POST',
|
|
507
|
-
headers: { 'content-type': 'application/json' },
|
|
480
|
+
headers: { 'content-type': 'application/json', 'user-agent': composedUserAgent() },
|
|
508
481
|
body: JSON.stringify({ schemaVersion: 2, question, limit: ${SEARCH_LIMIT} }),
|
|
509
482
|
signal: AbortSignal.timeout(${SEARCH_TIMEOUT_MS}),
|
|
510
483
|
});
|
|
@@ -613,23 +586,54 @@ function stopHookScript(dataDir) {
|
|
|
613
586
|
return `${prelude(dataDir, STOP_WATCHDOG_MS)}
|
|
614
587
|
const NAGS_PATH = join(DATA_DIR, 'hook-nags.json');
|
|
615
588
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
const nagged = isRecord(raw) && isRecord(raw.nagged) ? raw.nagged : {};
|
|
589
|
+
/** The string-valued members of a record, dropping anything else. */
|
|
590
|
+
function stampsOf(value) {
|
|
619
591
|
const out = {};
|
|
620
|
-
|
|
621
|
-
|
|
592
|
+
if (!isRecord(value)) return out;
|
|
593
|
+
for (const [key, at] of Object.entries(value)) {
|
|
594
|
+
if (typeof at === 'string') out[key] = at;
|
|
622
595
|
}
|
|
623
596
|
return out;
|
|
624
597
|
}
|
|
625
598
|
|
|
599
|
+
/**
|
|
600
|
+
* What has already been raised: \`nagged\` per searchId, \`sessions\` per harness
|
|
601
|
+
* session that has had its weak batch. Both are additive on the same file, and a
|
|
602
|
+
* file written by an older hook simply has no \`sessions\` key, which reads as
|
|
603
|
+
* "no session has been batched yet" \u2014 one extra weak batch, never a lost nag.
|
|
604
|
+
*/
|
|
605
|
+
function loadNags() {
|
|
606
|
+
const raw = readJsonFile(NAGS_PATH);
|
|
607
|
+
return {
|
|
608
|
+
nagged: stampsOf(isRecord(raw) ? raw.nagged : null),
|
|
609
|
+
sessions: stampsOf(isRecord(raw) ? raw.sessions : null),
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
|
|
626
613
|
/** Persist through a temp file + rename, so a crash cannot leave a torn file. */
|
|
627
|
-
function saveNags(nagged) {
|
|
614
|
+
function saveNags(nagged, sessions) {
|
|
628
615
|
const tmp = NAGS_PATH + '.' + process.pid + '.tmp';
|
|
629
|
-
writeFileSync(tmp, JSON.stringify({ schemaVersion: 1, nagged }, null, 2) + '\\n', {
|
|
616
|
+
writeFileSync(tmp, JSON.stringify({ schemaVersion: 1, nagged, sessions }, null, 2) + '\\n', {
|
|
617
|
+
mode: 0o644,
|
|
618
|
+
});
|
|
630
619
|
renameSync(tmp, NAGS_PATH);
|
|
631
620
|
}
|
|
632
621
|
|
|
622
|
+
/**
|
|
623
|
+
* The publish consent mode the next \`tenjin publish\` will run under, stated in
|
|
624
|
+
* the terms that decide what the agent does next: whether it has to ask.
|
|
625
|
+
*
|
|
626
|
+
* NEVER EMITTED ALONE. It is context for the loops below it, not a standing
|
|
627
|
+
* announcement, so a turn with nothing open says nothing at all.
|
|
628
|
+
*/
|
|
629
|
+
function modeLine(mode) {
|
|
630
|
+
if (mode === 'auto') return 'publish.mode=auto: a clean publish proceeds without asking.';
|
|
631
|
+
if (mode === 'full-auto') {
|
|
632
|
+
return 'publish.mode=full-auto: publish without asking; hedge warnings, stop only on hard blocks.';
|
|
633
|
+
}
|
|
634
|
+
return 'publish.mode=review: publishing asks first.';
|
|
635
|
+
}
|
|
636
|
+
|
|
633
637
|
/**
|
|
634
638
|
* One line per deliberate search nobody had answered, naming its searchId. The
|
|
635
639
|
* publish arm is QUALIFIED: this line lands in a model's context at every turn
|
|
@@ -643,11 +647,11 @@ function saveNags(nagged) {
|
|
|
643
647
|
function strongLine(s) {
|
|
644
648
|
const id = clean(s.searchId, 64);
|
|
645
649
|
return (
|
|
646
|
-
"Open Tenjin loop:
|
|
650
|
+
"Open Tenjin loop: '" +
|
|
647
651
|
clean(s.question, 160) +
|
|
648
|
-
"'
|
|
652
|
+
"' was a MISS. Solved it with a public, reusable, rights-clean finding? Publish it: tenjin publish <file> --search-id " +
|
|
649
653
|
id +
|
|
650
|
-
'. If
|
|
654
|
+
'. If not, close it: tenjin outcome --search-id ' +
|
|
651
655
|
id +
|
|
652
656
|
' --status regenerated.'
|
|
653
657
|
);
|
|
@@ -663,7 +667,7 @@ function weakLine(batch) {
|
|
|
663
667
|
String(batch.length) +
|
|
664
668
|
' web search(es) this session had no Tenjin answer: ' +
|
|
665
669
|
items +
|
|
666
|
-
'.
|
|
670
|
+
'. Durable public finding among them? Publish it: tenjin publish <file> --search-id <id>. If not, close them: tenjin outcome --search-id <id> --status regenerated.'
|
|
667
671
|
);
|
|
668
672
|
}
|
|
669
673
|
|
|
@@ -690,16 +694,40 @@ async function main() {
|
|
|
690
694
|
// and tolerantly \u2014 a shape this hook does not recognize costs the scoping, not
|
|
691
695
|
// the reminder.
|
|
692
696
|
let sessionId = null;
|
|
697
|
+
let cwd = null;
|
|
693
698
|
try {
|
|
694
|
-
|
|
699
|
+
const input = JSON.parse(await readStdin());
|
|
700
|
+
sessionId = sessionIdOf(input);
|
|
701
|
+
cwd = cwdOf(input);
|
|
695
702
|
} catch {
|
|
696
703
|
// Unparseable stdin: fall back to machine-global behavior.
|
|
697
704
|
}
|
|
698
|
-
|
|
705
|
+
const config = readConfig();
|
|
706
|
+
if (config.stopNag === 'off') return quiet();
|
|
707
|
+
// The mode the next publish IN THIS DIRECTORY would actually run under. The
|
|
708
|
+
// Stop hook's cwd IS the session's working directory, so it is the place that
|
|
709
|
+
// publish runs. Precedence follows lib/config.ts: an env var outranks the
|
|
710
|
+
// project file, so the project layer is consulted only when nothing pinned it.
|
|
711
|
+
const project = cwd === null || config.envPinned ? null : projectPublishMode(cwd);
|
|
712
|
+
const publishMode = project === null ? config.publishMode : project;
|
|
699
713
|
|
|
700
714
|
const searches = loadSearches();
|
|
701
715
|
const now = Date.now();
|
|
702
|
-
const nagged = loadNags();
|
|
716
|
+
const { nagged, sessions } = loadNags();
|
|
717
|
+
|
|
718
|
+
// ONE WEAK BATCH PER SESSION. Per-searchId dedupe cannot rate-limit the weak
|
|
719
|
+
// arm, because a research fan-out mints new ids every turn and each one is
|
|
720
|
+
// un-nagged by construction; the batch then fires at every turn end for the
|
|
721
|
+
// whole session and reads as harness debug output rather than a product
|
|
722
|
+
// (tenjin-agent #162). \`deliberate-only\` is the operator's standing version of
|
|
723
|
+
// the same suppression, and it exists so silencing this arm is not the cliff
|
|
724
|
+
// that \`off\` is: the strong arm, which is the high-signal half, keeps running.
|
|
725
|
+
//
|
|
726
|
+
// A null sessionId keeps the old behavior. There is nothing to key on, and
|
|
727
|
+
// refusing the batch outright would silence it on every harness that names no
|
|
728
|
+
// session.
|
|
729
|
+
const batchedThisSession = sessionId !== null && sessions[sessionId] !== undefined;
|
|
730
|
+
const weakAllowed = config.stopNag !== 'deliberate-only' && !batchedThisSession;
|
|
703
731
|
|
|
704
732
|
const strong = [];
|
|
705
733
|
const weak = [];
|
|
@@ -714,23 +742,38 @@ async function main() {
|
|
|
714
742
|
const at = Date.parse(String(s.at));
|
|
715
743
|
if (!Number.isFinite(at) || now - at > ${OPEN_LOOP_WINDOW_MS} || at > now) continue;
|
|
716
744
|
// An entry with no source predates sources, and those were all deliberate.
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
745
|
+
if (s.source === 'websearch-hook') {
|
|
746
|
+
// A suppressed weak entry is skipped UNNAGGED, exactly like an entry owned
|
|
747
|
+
// by another session: the batch was rate-limited, not delivered, so the id
|
|
748
|
+
// stays available to whatever raises it next.
|
|
749
|
+
if (!weakAllowed) continue;
|
|
750
|
+
if (weak.length < ${MAX_WEAK_LOOPS}) weak.push(s);
|
|
751
|
+
} else if (strong.length < ${MAX_STRONG_LOOPS}) {
|
|
752
|
+
strong.push(s);
|
|
753
|
+
}
|
|
720
754
|
}
|
|
721
755
|
const surfaced = strong.concat(weak);
|
|
722
756
|
if (surfaced.length === 0) return quiet();
|
|
723
757
|
|
|
724
758
|
const stamp = new Date(now).toISOString();
|
|
725
759
|
for (const s of surfaced) nagged[s.searchId] = stamp;
|
|
760
|
+
if (weak.length > 0 && sessionId !== null) sessions[sessionId] = stamp;
|
|
726
761
|
for (const [id, at] of Object.entries(nagged)) {
|
|
727
762
|
const t = Date.parse(at);
|
|
728
763
|
if (!Number.isFinite(t) || now - t > ${NAG_RETENTION_MS}) delete nagged[id];
|
|
729
764
|
}
|
|
765
|
+
for (const [id, at] of Object.entries(sessions)) {
|
|
766
|
+
const t = Date.parse(at);
|
|
767
|
+
if (!Number.isFinite(t) || now - t > ${NAG_RETENTION_MS}) delete sessions[id];
|
|
768
|
+
}
|
|
730
769
|
// Record first: a nag we cannot mark is a nag that would repeat every turn.
|
|
731
|
-
saveNags(nagged);
|
|
770
|
+
saveNags(nagged, sessions);
|
|
732
771
|
|
|
733
|
-
|
|
772
|
+
// The mode heads the block: it is what decides whether the publish arm below
|
|
773
|
+
// needs the operator's word, and an agent that has to run \`tenjin config get\`
|
|
774
|
+
// to find out defaults to asking (tenjin-agent #161).
|
|
775
|
+
const lines = [modeLine(publishMode)];
|
|
776
|
+
for (const s of strong) lines.push(strongLine(s));
|
|
734
777
|
if (weak.length > 0) lines.push(weakLine(weak));
|
|
735
778
|
emit('Stop', lines.join('\\n'));
|
|
736
779
|
}
|
|
@@ -739,201 +782,10 @@ main().catch(quiet);
|
|
|
739
782
|
`;
|
|
740
783
|
}
|
|
741
784
|
|
|
742
|
-
// src/lib/uninstall.ts
|
|
743
|
-
var KEPT_ITEMS = [
|
|
744
|
-
"everything under ~/.tenjin: your wallet, config, library, and search history",
|
|
745
|
-
"anything an older version left in ~/.tenjin/candidates (nothing reads it now)"
|
|
746
|
-
];
|
|
747
|
-
var SKILLS_MARKER = "<!-- tenjin-cli:skills -->";
|
|
748
|
-
function isPlainObject2(value) {
|
|
749
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
750
|
-
}
|
|
751
|
-
function ownsHookEntry(entry) {
|
|
752
|
-
if (!isPlainObject2(entry)) return false;
|
|
753
|
-
const handlers = entry.hooks;
|
|
754
|
-
if (!Array.isArray(handlers)) return false;
|
|
755
|
-
return handlers.some(
|
|
756
|
-
(h) => isPlainObject2(h) && typeof h.command === "string" && (h.command.includes(WEBSEARCH_HOOK_FILE) || h.command.includes(STOP_HOOK_FILE))
|
|
757
|
-
);
|
|
758
|
-
}
|
|
759
|
-
async function removeFromSettings(homeDir) {
|
|
760
|
-
const declaredPath = claudeSettingsPath(homeDir);
|
|
761
|
-
const skip2 = (path2, skipped, warning) => ({
|
|
762
|
-
path: path2,
|
|
763
|
-
hooks: [],
|
|
764
|
-
rules: [],
|
|
765
|
-
skipped,
|
|
766
|
-
...warning !== void 0 ? { warning } : {}
|
|
767
|
-
});
|
|
768
|
-
const entry = await lstat2(declaredPath).catch(() => null);
|
|
769
|
-
if (entry === null) return skip2(declaredPath, "absent");
|
|
770
|
-
let path;
|
|
771
|
-
try {
|
|
772
|
-
path = await realpath2(declaredPath);
|
|
773
|
-
} catch (err) {
|
|
774
|
-
return skip2(
|
|
775
|
-
declaredPath,
|
|
776
|
-
"unresolvable",
|
|
777
|
-
`${declaredPath} could not be resolved (${err.message}); it was left exactly as it is.`
|
|
778
|
-
);
|
|
779
|
-
}
|
|
780
|
-
let raw;
|
|
781
|
-
try {
|
|
782
|
-
raw = await readFile2(path, "utf8");
|
|
783
|
-
} catch (err) {
|
|
784
|
-
return skip2(
|
|
785
|
-
path,
|
|
786
|
-
"unreadable",
|
|
787
|
-
`${path} could not be read (${err.message}); it was left exactly as it is.`
|
|
788
|
-
);
|
|
789
|
-
}
|
|
790
|
-
let parsed;
|
|
791
|
-
try {
|
|
792
|
-
parsed = JSON.parse(raw);
|
|
793
|
-
} catch (err) {
|
|
794
|
-
return skip2(
|
|
795
|
-
path,
|
|
796
|
-
"unparsable",
|
|
797
|
-
`${path} is not valid JSON (${err.message}); it was left exactly as it is.`
|
|
798
|
-
);
|
|
799
|
-
}
|
|
800
|
-
if (!isPlainObject2(parsed)) {
|
|
801
|
-
return skip2(path, "unexpected-shape", `${path} is not a JSON object; it was left as it is.`);
|
|
802
|
-
}
|
|
803
|
-
const settings = parsed;
|
|
804
|
-
const removedHooks = [];
|
|
805
|
-
const removedRules = [];
|
|
806
|
-
let next = settings;
|
|
807
|
-
const hooksValue = settings.hooks;
|
|
808
|
-
if (hooksValue !== void 0 && !isPlainObject2(hooksValue)) {
|
|
809
|
-
return skip2(
|
|
810
|
-
path,
|
|
811
|
-
"unexpected-shape",
|
|
812
|
-
`${path} has a "hooks" key that is not an object; it was left exactly as it is.`
|
|
813
|
-
);
|
|
814
|
-
}
|
|
815
|
-
if (isPlainObject2(hooksValue)) {
|
|
816
|
-
const nextHooks = {};
|
|
817
|
-
for (const [event, value] of Object.entries(hooksValue)) {
|
|
818
|
-
if (!Array.isArray(value)) {
|
|
819
|
-
nextHooks[event] = value;
|
|
820
|
-
continue;
|
|
821
|
-
}
|
|
822
|
-
const kept = value.filter((e) => !ownsHookEntry(e));
|
|
823
|
-
if (kept.length !== value.length) removedHooks.push(event);
|
|
824
|
-
const emptiedByUs = kept.length === 0 && value.length > 0;
|
|
825
|
-
if (!emptiedByUs) nextHooks[event] = kept;
|
|
826
|
-
}
|
|
827
|
-
next = { ...next, hooks: nextHooks };
|
|
828
|
-
if (Object.keys(nextHooks).length === 0) delete next.hooks;
|
|
829
|
-
}
|
|
830
|
-
const permissions = settings.permissions;
|
|
831
|
-
if (isPlainObject2(permissions) && Array.isArray(permissions.allow)) {
|
|
832
|
-
const ours = /* @__PURE__ */ new Set([...FREE_VERB_RULES, ...LEGACY_FREE_VERB_RULES]);
|
|
833
|
-
const kept = permissions.allow.filter((r) => !(typeof r === "string" && ours.has(r)));
|
|
834
|
-
if (kept.length !== permissions.allow.length) {
|
|
835
|
-
for (const rule of permissions.allow) {
|
|
836
|
-
if (typeof rule === "string" && ours.has(rule)) removedRules.push(rule);
|
|
837
|
-
}
|
|
838
|
-
const nextPermissions = { ...permissions, allow: kept };
|
|
839
|
-
if (kept.length === 0) delete nextPermissions.allow;
|
|
840
|
-
next = { ...next, permissions: nextPermissions };
|
|
841
|
-
if (Object.keys(nextPermissions).length === 0) delete next.permissions;
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
if (removedHooks.length === 0 && removedRules.length === 0) {
|
|
845
|
-
return { path, hooks: [], rules: [] };
|
|
846
|
-
}
|
|
847
|
-
const current = await readFile2(path, "utf8").catch(() => null);
|
|
848
|
-
if (current !== raw) {
|
|
849
|
-
return skip2(
|
|
850
|
-
path,
|
|
851
|
-
"changed-since-read",
|
|
852
|
-
`${path} changed while it was being updated, so nothing was removed from it. Re-run \`tenjin uninstall\`.`
|
|
853
|
-
);
|
|
854
|
-
}
|
|
855
|
-
await writeFileAtomic(path, `${JSON.stringify(next, null, 2)}
|
|
856
|
-
`);
|
|
857
|
-
return { path, hooks: removedHooks, rules: removedRules };
|
|
858
|
-
}
|
|
859
|
-
async function removeHookScripts(dataDir) {
|
|
860
|
-
const dir = hooksDir(dataDir);
|
|
861
|
-
const removed = [];
|
|
862
|
-
for (const file of [WEBSEARCH_HOOK_FILE, STOP_HOOK_FILE]) {
|
|
863
|
-
const path = join2(dir, file);
|
|
864
|
-
if (lstatSync(path, { throwIfNoEntry: false })?.isFile() !== true) continue;
|
|
865
|
-
await rm(path, { force: true });
|
|
866
|
-
removed.push(path);
|
|
867
|
-
}
|
|
868
|
-
const rest = await readdir(dir).catch(() => null);
|
|
869
|
-
if (rest !== null && rest.length === 0) {
|
|
870
|
-
const gone = await rmdir(dir).then(
|
|
871
|
-
() => true,
|
|
872
|
-
() => false
|
|
873
|
-
);
|
|
874
|
-
if (gone) return { scripts: removed, removedDir: dir };
|
|
875
|
-
}
|
|
876
|
-
return { scripts: removed };
|
|
877
|
-
}
|
|
878
|
-
async function removeSkills(homeDir) {
|
|
879
|
-
const removed = [];
|
|
880
|
-
const names = [...CLI_SKILL_NAMES, HOSTED_SKILL_NAME];
|
|
881
|
-
for (const dir of skillsDirsFor(homeDir)) {
|
|
882
|
-
if (lstatSync(dir, { throwIfNoEntry: false })?.isDirectory() !== true) continue;
|
|
883
|
-
for (const name of names) {
|
|
884
|
-
const skillDir = join2(dir, name);
|
|
885
|
-
if (lstatSync(skillDir, { throwIfNoEntry: false })?.isDirectory() !== true) continue;
|
|
886
|
-
const path = join2(skillDir, "SKILL.md");
|
|
887
|
-
if (lstatSync(path, { throwIfNoEntry: false })?.isFile() !== true) continue;
|
|
888
|
-
const read = await readSkillFile(path);
|
|
889
|
-
if (read.kind !== "ok") continue;
|
|
890
|
-
if (skillFrontmatterName(read.bytes.toString("utf8")) !== name) continue;
|
|
891
|
-
await rm(path, { force: true });
|
|
892
|
-
const rest = await readdir(skillDir).catch(() => null);
|
|
893
|
-
if (rest !== null && rest.length === 0) {
|
|
894
|
-
await rmdir(skillDir).catch(() => void 0);
|
|
895
|
-
}
|
|
896
|
-
removed.push(skillDir);
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
return removed;
|
|
900
|
-
}
|
|
901
|
-
async function removeMarkerLines(homeDir) {
|
|
902
|
-
const cleaned = [];
|
|
903
|
-
for (const path of markerFiles(homeDir)) {
|
|
904
|
-
const read = await readSkillFile(path);
|
|
905
|
-
if (read.kind !== "ok") continue;
|
|
906
|
-
const text = read.bytes.toString("utf8");
|
|
907
|
-
if (!text.split("\n").some((l) => l.startsWith(SKILLS_MARKER))) continue;
|
|
908
|
-
const kept = text.split("\n").filter((l) => !l.startsWith(SKILLS_MARKER));
|
|
909
|
-
const writeTo = await resolveThroughLink(path, "the Tenjin pointer");
|
|
910
|
-
await writeFileAtomic(writeTo, kept.join("\n"));
|
|
911
|
-
cleaned.push(path);
|
|
912
|
-
}
|
|
913
|
-
return cleaned;
|
|
914
|
-
}
|
|
915
|
-
function markerFiles(homeDir) {
|
|
916
|
-
return [
|
|
917
|
-
join2(homeDir, ".claude", "CLAUDE.md"),
|
|
918
|
-
join2(homeDir, ".agents", "AGENTS.md"),
|
|
919
|
-
join2(homeDir, ".codex", "AGENTS.md")
|
|
920
|
-
];
|
|
921
|
-
}
|
|
922
|
-
|
|
923
785
|
export {
|
|
924
|
-
claudeSettingsPath,
|
|
925
|
-
FREE_VERB_RULES,
|
|
926
|
-
permissionsSkipped,
|
|
927
|
-
wireFreeVerbAllowlist,
|
|
928
|
-
inspectFreeVerbRules,
|
|
929
786
|
WEBSEARCH_HOOK_FILE,
|
|
930
787
|
STOP_HOOK_FILE,
|
|
931
788
|
websearchHookScript,
|
|
932
|
-
stopHookScript
|
|
933
|
-
KEPT_ITEMS,
|
|
934
|
-
removeFromSettings,
|
|
935
|
-
removeHookScripts,
|
|
936
|
-
removeSkills,
|
|
937
|
-
removeMarkerLines
|
|
789
|
+
stopHookScript
|
|
938
790
|
};
|
|
939
|
-
//# sourceMappingURL=chunk-
|
|
791
|
+
//# sourceMappingURL=chunk-DTCXO7HS.js.map
|