@honcho-ai/claude-honcho 0.3.4 → 0.4.0
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/.claude-plugin/plugin.json +1 -1
- package/README.md +111 -335
- package/dist/hooks/pre-tool-honcho.js +549 -615
- package/dist/hooks/pre-tool-honcho.js.map +11 -9
- package/dist/hooks/save-user-message.js +1721 -1066
- package/dist/hooks/save-user-message.js.map +24 -19
- package/dist/hooks/session-end.js +557 -628
- package/dist/hooks/session-end.js.map +11 -9
- package/dist/hooks/session-start.js +1925 -1313
- package/dist/hooks/session-start.js.map +31 -22
- package/dist/hooks/stop.js +1742 -1160
- package/dist/hooks/stop.js.map +25 -20
- package/dist/hooks/user-prompt.js +690 -16611
- package/dist/hooks/user-prompt.js.map +13 -90
- package/dist/mcp-server.js +1595 -1612
- package/dist/mcp-server.js.map +23 -20
- package/dist/skills/backfill-runner.js +1816 -919
- package/dist/skills/backfill-runner.js.map +27 -21
- package/dist/skills/{setup-runner.js → pane-runner.js} +1902 -1030
- package/dist/{hooks/pre-compact.js.map → skills/pane-runner.js.map} +28 -24
- package/dist/skills/status-runner.js +1567 -761
- package/dist/skills/status-runner.js.map +23 -19
- package/hooks/hooks.json +4 -36
- package/hooks/register.tsx +574 -0
- package/package.json +1 -1
- package/skills/insights/SKILL.md +3 -7
- package/dist/hooks/post-tool-use.js +0 -16924
- package/dist/hooks/post-tool-use.js.map +0 -97
- package/dist/hooks/pre-compact.js +0 -17111
- package/dist/skills/setup-runner.js.map +0 -96
- package/scripts/honcho-statusline.sh +0 -101
- package/skills/briefing/SKILL.md +0 -20
- package/skills/config/SKILL.md +0 -288
- package/skills/import/SKILL.md +0 -73
- package/skills/setup/SKILL.md +0 -60
- package/skills/status/SKILL.md +0 -30
|
@@ -1,274 +1,449 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
3
|
// src/config.ts
|
|
4
|
-
import {
|
|
5
|
-
import { join as join3, basename, dirname, resolve, sep } from "path";
|
|
4
|
+
import { join as join3, dirname as dirname2 } from "path";
|
|
6
5
|
import { fileURLToPath } from "url";
|
|
7
|
-
import {
|
|
6
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
|
|
8
7
|
|
|
9
|
-
//
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { join } from "path";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
`).filter((line) => line.trim()).map((line) => line.slice(3).trim()).slice(0, 20) : [];
|
|
8
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/config.js
|
|
9
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { join as join2 } from "node:path";
|
|
12
|
+
|
|
13
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/legacy/v01.js
|
|
14
|
+
var isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
15
|
+
var str = (v) => typeof v === "string" && v ? v : undefined;
|
|
16
|
+
function v01Reader(file, host) {
|
|
17
|
+
const hosts = isObj(file.hosts) ? file.hosts : {};
|
|
18
|
+
const v1 = typeof file.schemaVersion === "number" && file.schemaVersion >= 1;
|
|
19
|
+
const pick = (b) => {
|
|
20
|
+
const o = isObj(b) ? b : {};
|
|
21
|
+
if (v1)
|
|
22
|
+
return { apiKey: isObj(o.auth) ? str(o.auth.apiKey) : undefined, peerName: str(o.peerName), workspace: str(o.workspace), baseUrl: str(o.baseUrl) };
|
|
23
|
+
return {
|
|
24
|
+
apiKey: (isObj(o.auth) ? str(o.auth.apiKey) : undefined) ?? str(o.apiKey),
|
|
25
|
+
peerName: str(o.peerName),
|
|
26
|
+
workspace: str(o.workspace) ?? str(o.workspaceId),
|
|
27
|
+
baseUrl: str(o.baseUrl) ?? str(o.environmentUrl) ?? (isObj(o.endpoint) ? str(o.endpoint.baseUrl) : undefined)
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const own = pick(hosts[host]);
|
|
31
|
+
const top = pick(file);
|
|
34
32
|
return {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
timestamp: new Date().toISOString()
|
|
33
|
+
apiKey: own.apiKey ?? top.apiKey,
|
|
34
|
+
peerName: own.peerName ?? top.peerName,
|
|
35
|
+
workspace: own.workspace ?? top.workspace,
|
|
36
|
+
aiPeer: isObj(hosts[host]) ? str(hosts[host].aiPeer) : undefined,
|
|
37
|
+
baseUrl: own.baseUrl ?? top.baseUrl
|
|
41
38
|
};
|
|
42
39
|
}
|
|
43
40
|
|
|
44
|
-
//
|
|
45
|
-
import {
|
|
46
|
-
import { join
|
|
47
|
-
|
|
48
|
-
var
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/oauth.js
|
|
42
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
43
|
+
import { dirname, join } from "node:path";
|
|
44
|
+
var OAUTH_TOKEN_URL = "https://api.honcho.dev/oauth/token";
|
|
45
|
+
var OAUTH_SCOPE = "write";
|
|
46
|
+
var REQUEST_TIMEOUT_MS = 1e4;
|
|
47
|
+
var REFRESH_SKEW_S = 60;
|
|
48
|
+
var LOCK_STALE_MS = REQUEST_TIMEOUT_MS + 5000;
|
|
49
|
+
var LOCK_WAIT_MS = LOCK_STALE_MS + 5000;
|
|
50
|
+
var PERMANENT_ERRORS = new Set(["invalid_grant", "invalid_client", "unauthorized_client"]);
|
|
51
|
+
|
|
52
|
+
class OAuthError extends Error {
|
|
53
|
+
code;
|
|
54
|
+
constructor(code, description) {
|
|
55
|
+
super(description || code);
|
|
56
|
+
this.code = code;
|
|
57
|
+
this.name = "OAuthError";
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
function isCloud(baseUrl) {
|
|
61
|
+
return normalizeBaseUrl(baseUrl || DEFAULT_BASE_URL) === DEFAULT_BASE_URL;
|
|
62
|
+
}
|
|
63
|
+
function accessValid(t, skewS = REFRESH_SKEW_S, nowS = Date.now() / 1000) {
|
|
64
|
+
return !!t?.accessToken && nowS < t.accessExpiresAt - skewS;
|
|
65
|
+
}
|
|
66
|
+
async function post(url, form, t) {
|
|
67
|
+
const f = t?.fetch ?? fetch;
|
|
68
|
+
let res;
|
|
69
|
+
try {
|
|
70
|
+
res = await f(url, {
|
|
71
|
+
method: "POST",
|
|
72
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" },
|
|
73
|
+
body: new URLSearchParams(form).toString(),
|
|
74
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
75
|
+
});
|
|
76
|
+
} catch (e) {
|
|
77
|
+
throw new OAuthError("connection_error", `could not reach ${url}: ${e.message}`);
|
|
60
78
|
}
|
|
79
|
+
let body = null;
|
|
61
80
|
try {
|
|
62
|
-
|
|
81
|
+
body = await res.json();
|
|
63
82
|
} catch {
|
|
64
|
-
|
|
83
|
+
body = null;
|
|
65
84
|
}
|
|
85
|
+
return { status: res.status, body };
|
|
66
86
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const cache = loadIdCache();
|
|
73
|
-
if (!cache.sessions)
|
|
74
|
-
cache.sessions = {};
|
|
75
|
-
cache.sessions[cwd] = { name, id, updatedAt: new Date().toISOString(), instanceId };
|
|
76
|
-
saveIdCache(cache);
|
|
87
|
+
function errorOf(r) {
|
|
88
|
+
const b = r.body;
|
|
89
|
+
if (b && typeof b === "object" && typeof b.error === "string")
|
|
90
|
+
return new OAuthError(b.error, b.error_description);
|
|
91
|
+
return new OAuthError("invalid_response");
|
|
77
92
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return null;
|
|
82
|
-
let latest = null;
|
|
83
|
-
for (const [cwd, entry] of Object.entries(cache.sessions)) {
|
|
84
|
-
if (!latest || entry.updatedAt > latest.updatedAt) {
|
|
85
|
-
latest = { cwd, updatedAt: entry.updatedAt };
|
|
86
|
-
}
|
|
93
|
+
function tokensFrom(body, clientId, prev) {
|
|
94
|
+
if (!body || typeof body.access_token !== "string" || !Number.isFinite(Number(body.expires_in))) {
|
|
95
|
+
throw new OAuthError("invalid_response", "malformed token response");
|
|
87
96
|
}
|
|
88
|
-
return
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
"
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
97
|
+
return {
|
|
98
|
+
accessToken: body.access_token,
|
|
99
|
+
refreshToken: body.refresh_token || prev?.refreshToken || "",
|
|
100
|
+
accessExpiresAt: Math.floor(Date.now() / 1000) + Number(body.expires_in),
|
|
101
|
+
clientId,
|
|
102
|
+
scope: body.scope || prev?.scope || OAUTH_SCOPE
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async function refreshAccessToken(prev, opts = {}) {
|
|
106
|
+
const r = await post(opts.tokenUrl ?? OAUTH_TOKEN_URL, { grant_type: "refresh_token", refresh_token: prev.refreshToken, client_id: prev.clientId }, opts);
|
|
107
|
+
if (r.status !== 200)
|
|
108
|
+
throw errorOf(r);
|
|
109
|
+
return tokensFrom(r.body, prev.clientId, prev);
|
|
110
|
+
}
|
|
111
|
+
function isObj2(v) {
|
|
112
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
113
|
+
}
|
|
114
|
+
function asTokens(v) {
|
|
115
|
+
if (!isObj2(v) || typeof v.accessToken !== "string" || !v.accessToken)
|
|
116
|
+
return;
|
|
117
|
+
return {
|
|
118
|
+
accessToken: v.accessToken,
|
|
119
|
+
refreshToken: typeof v.refreshToken === "string" ? v.refreshToken : "",
|
|
120
|
+
accessExpiresAt: Number(v.accessExpiresAt) || 0,
|
|
121
|
+
clientId: typeof v.clientId === "string" ? v.clientId : "",
|
|
122
|
+
scope: typeof v.scope === "string" ? v.scope : ""
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function readFile(path) {
|
|
126
|
+
if (!existsSync(path))
|
|
111
127
|
return {};
|
|
112
|
-
|
|
128
|
+
const parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
129
|
+
return isObj2(parsed) ? parsed : {};
|
|
130
|
+
}
|
|
131
|
+
function readGrant(file, host, legacy) {
|
|
132
|
+
return asTokens(effectiveBlock(file, host, legacy).oauth);
|
|
133
|
+
}
|
|
134
|
+
function holderAlive(token, ageMs) {
|
|
135
|
+
if (token === "")
|
|
136
|
+
return ageMs < 1000;
|
|
137
|
+
const pid = Number(token.split(":")[0]);
|
|
138
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
139
|
+
return true;
|
|
113
140
|
try {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
delete raw[key];
|
|
119
|
-
cleaned = true;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (cleaned) {
|
|
123
|
-
writeFileSync(CONTEXT_CACHE_FILE, JSON.stringify(raw, null, 2));
|
|
124
|
-
}
|
|
125
|
-
return raw;
|
|
126
|
-
} catch {
|
|
127
|
-
return {};
|
|
141
|
+
process.kill(pid, 0);
|
|
142
|
+
return true;
|
|
143
|
+
} catch (e) {
|
|
144
|
+
return e.code === "EPERM";
|
|
128
145
|
}
|
|
129
146
|
}
|
|
130
|
-
function
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
function loadGitStateCache() {
|
|
151
|
-
ensureCacheDir();
|
|
152
|
-
if (!existsSync2(GIT_STATE_FILE)) {
|
|
153
|
-
return {};
|
|
147
|
+
async function withConfigLock(path, fn) {
|
|
148
|
+
const lock = `${path}.lock`;
|
|
149
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
150
|
+
const start = Date.now();
|
|
151
|
+
let fd;
|
|
152
|
+
while (fd === undefined) {
|
|
153
|
+
try {
|
|
154
|
+
fd = openSync(lock, "wx", 384);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
if (e.code !== "EEXIST")
|
|
157
|
+
throw e;
|
|
158
|
+
try {
|
|
159
|
+
const age = Date.now() - statSync(lock).mtimeMs;
|
|
160
|
+
if (age > LOCK_STALE_MS || !holderAlive(readFileSync(lock, "utf-8"), age))
|
|
161
|
+
unlinkSync(lock);
|
|
162
|
+
} catch {}
|
|
163
|
+
if (Date.now() - start > LOCK_WAIT_MS)
|
|
164
|
+
throw new Error(`timed out waiting for ${lock}`);
|
|
165
|
+
await new Promise((r) => setTimeout(r, 50 + Math.random() * 50));
|
|
166
|
+
}
|
|
154
167
|
}
|
|
168
|
+
const token = `${process.pid}:${Math.random().toString(36).slice(2)}`;
|
|
155
169
|
try {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
170
|
+
writeFileSync(fd, token);
|
|
171
|
+
return await fn();
|
|
172
|
+
} finally {
|
|
173
|
+
closeSync(fd);
|
|
174
|
+
try {
|
|
175
|
+
if (readFileSync(lock, "utf-8") === token)
|
|
176
|
+
unlinkSync(lock);
|
|
177
|
+
} catch {}
|
|
159
178
|
}
|
|
160
179
|
}
|
|
161
|
-
function
|
|
162
|
-
|
|
163
|
-
writeFileSync(
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
function
|
|
175
|
-
const
|
|
176
|
-
if (
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
180
|
+
function writeFileAtomic(path, data) {
|
|
181
|
+
const tmp = join(dirname(path), `.${Date.now()}-${process.pid}-${Math.random().toString(36).slice(2)}.tmp`);
|
|
182
|
+
writeFileSync(tmp, JSON.stringify(data, null, 2) + `
|
|
183
|
+
`, { mode: 384 });
|
|
184
|
+
renameSync(tmp, path);
|
|
185
|
+
}
|
|
186
|
+
async function updateConfigFile(path, mutate) {
|
|
187
|
+
await withConfigLock(path, async () => {
|
|
188
|
+
const file = readFile(path);
|
|
189
|
+
mutate(file);
|
|
190
|
+
writeFileAtomic(path, file);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
function setGrant(file, host, tokens) {
|
|
194
|
+
const block = hostBlock(file, host);
|
|
195
|
+
if (tokens)
|
|
196
|
+
block.oauth = tokens;
|
|
197
|
+
else
|
|
198
|
+
delete block.oauth;
|
|
199
|
+
}
|
|
200
|
+
function serverOf(block, baseUrl, env) {
|
|
201
|
+
return baseUrl ?? (env.HONCHO_BASE_URL || undefined) ?? (typeof block.baseUrl === "string" && block.baseUrl ? block.baseUrl : undefined);
|
|
202
|
+
}
|
|
203
|
+
function pickCredential(file, opts) {
|
|
204
|
+
const env = opts.env ?? process.env;
|
|
205
|
+
if (env.HONCHO_API_KEY)
|
|
206
|
+
return { token: env.HONCHO_API_KEY, source: "env" };
|
|
207
|
+
const block = effectiveBlock(file, opts.host, opts.legacy);
|
|
208
|
+
const g = isCloud(serverOf(block, opts.baseUrl, env)) ? asTokens(block.oauth) : undefined;
|
|
209
|
+
if (g)
|
|
210
|
+
return { token: g.accessToken, source: "oauth", expiresAt: g.accessExpiresAt, ...accessValid(g, 0) ? {} : { expired: true } };
|
|
211
|
+
return typeof block.apiKey === "string" && block.apiKey ? { token: block.apiKey, source: "apiKey" } : null;
|
|
212
|
+
}
|
|
213
|
+
async function ensureFreshCredential(opts) {
|
|
214
|
+
const env = opts.env ?? process.env;
|
|
215
|
+
if (env.HONCHO_API_KEY)
|
|
216
|
+
return { token: env.HONCHO_API_KEY, source: "env" };
|
|
217
|
+
let file;
|
|
218
|
+
try {
|
|
219
|
+
file = readFile(opts.path);
|
|
220
|
+
} catch {
|
|
221
|
+
file = {};
|
|
190
222
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
223
|
+
const block = effectiveBlock(file, opts.host, opts.legacy);
|
|
224
|
+
const g = isCloud(serverOf(block, opts.baseUrl, env)) ? asTokens(block.oauth) : undefined;
|
|
225
|
+
if (!g || accessValid(g) || !g.refreshToken)
|
|
226
|
+
return pickCredential(file, opts);
|
|
227
|
+
let error;
|
|
228
|
+
try {
|
|
229
|
+
await withConfigLock(opts.path, async () => {
|
|
230
|
+
const current = readGrant(readFile(opts.path), opts.host, opts.legacy);
|
|
231
|
+
if (!current || accessValid(current))
|
|
232
|
+
return;
|
|
233
|
+
const next = await refreshAccessToken(current, opts);
|
|
234
|
+
const latest = readFile(opts.path);
|
|
235
|
+
setGrant(latest, opts.host, next);
|
|
236
|
+
writeFileAtomic(opts.path, latest);
|
|
197
237
|
});
|
|
238
|
+
} catch (e) {
|
|
239
|
+
error = e instanceof OAuthError ? e.code : e.message;
|
|
198
240
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
241
|
+
try {
|
|
242
|
+
file = readFile(opts.path);
|
|
243
|
+
} catch {}
|
|
244
|
+
const cred = pickCredential(file, opts);
|
|
245
|
+
if (cred && error) {
|
|
246
|
+
cred.error = error;
|
|
247
|
+
if (PERMANENT_ERRORS.has(error))
|
|
248
|
+
cred.reauthRequired = true;
|
|
204
249
|
}
|
|
205
|
-
return
|
|
250
|
+
return cred;
|
|
206
251
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
252
|
+
|
|
253
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/config.js
|
|
254
|
+
var DEFAULT_BASE_URL = "https://api.honcho.dev";
|
|
255
|
+
var CONFIG_SCHEMA_VERSION = 2;
|
|
256
|
+
function isObj3(v) {
|
|
257
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
258
|
+
}
|
|
259
|
+
function str2(v) {
|
|
260
|
+
return typeof v === "string" && v ? v : undefined;
|
|
261
|
+
}
|
|
262
|
+
function normalizeBaseUrl(input) {
|
|
263
|
+
let s = input.trim();
|
|
264
|
+
if (!s)
|
|
265
|
+
return s;
|
|
266
|
+
if (!s.startsWith("http://") && !s.startsWith("https://")) {
|
|
267
|
+
const host = s.split("/")[0].split(":")[0].toLowerCase();
|
|
268
|
+
const local = host === "localhost" || host === "127.0.0.1" || host === "::1";
|
|
269
|
+
s = `${local ? "http" : "https"}://${s}`;
|
|
211
270
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
let splitIndex = remaining.lastIndexOf(`
|
|
220
|
-
`, maxSize);
|
|
221
|
-
if (splitIndex <= 0 || splitIndex < maxSize * 0.25) {
|
|
222
|
-
splitIndex = remaining.lastIndexOf(" ", maxSize);
|
|
223
|
-
}
|
|
224
|
-
if (splitIndex <= 0 || splitIndex < maxSize * 0.25) {
|
|
225
|
-
splitIndex = maxSize;
|
|
226
|
-
}
|
|
227
|
-
chunks.push(remaining.slice(0, splitIndex));
|
|
228
|
-
remaining = remaining.slice(splitIndex).trimStart();
|
|
271
|
+
try {
|
|
272
|
+
const u = new URL(s);
|
|
273
|
+
u.hostname = u.hostname.toLowerCase();
|
|
274
|
+
const path = u.pathname === "/" ? "" : u.pathname.replace(/\/+$/, "");
|
|
275
|
+
return `${u.protocol}//${u.host}${path}`;
|
|
276
|
+
} catch {
|
|
277
|
+
return s;
|
|
229
278
|
}
|
|
230
|
-
|
|
231
|
-
|
|
279
|
+
}
|
|
280
|
+
function resolveConfig(file, opts) {
|
|
281
|
+
const env = opts.env ?? process.env;
|
|
282
|
+
const { host } = opts;
|
|
283
|
+
const block = effectiveBlock(file, host, opts.legacy);
|
|
284
|
+
return {
|
|
285
|
+
host,
|
|
286
|
+
peerName: str2(env.HONCHO_PEER_NAME) ?? str2(block.peerName) ?? str2(env.USER) ?? str2(env.USERNAME) ?? "user",
|
|
287
|
+
workspace: str2(env.HONCHO_WORKSPACE) ?? str2(block.workspace) ?? opts.defaults?.workspace ?? host,
|
|
288
|
+
aiPeer: str2(env.HONCHO_AI_PEER) ?? str2(block.aiPeer) ?? opts.defaults?.aiPeer ?? host,
|
|
289
|
+
baseUrl: normalizeBaseUrl(str2(env.HONCHO_BASE_URL) ?? str2(block.baseUrl) ?? DEFAULT_BASE_URL),
|
|
290
|
+
warnings: checkConfig(file).map((i) => i.message)
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function configPath(env = process.env) {
|
|
294
|
+
if (env.HONCHO_CONFIG_PATH)
|
|
295
|
+
return env.HONCHO_CONFIG_PATH;
|
|
296
|
+
const home = env.HOME || env.USERPROFILE || homedir();
|
|
297
|
+
return join2(home, ".honcho", "config.json");
|
|
298
|
+
}
|
|
299
|
+
function readConfigFile(env = process.env) {
|
|
300
|
+
const path = configPath(env);
|
|
301
|
+
if (!existsSync2(path))
|
|
302
|
+
return {};
|
|
303
|
+
try {
|
|
304
|
+
const parsed = JSON.parse(readFileSync2(path, "utf-8"));
|
|
305
|
+
return isObj3(parsed) ? parsed : {};
|
|
306
|
+
} catch {
|
|
307
|
+
return {};
|
|
232
308
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
active = await resolveFallback(e);
|
|
247
|
-
usedFallback = true;
|
|
248
|
-
await active.addMessages(batch);
|
|
309
|
+
}
|
|
310
|
+
async function saveHost(path, host, patch, legacy) {
|
|
311
|
+
await updateConfigFile(path, (file) => {
|
|
312
|
+
if (isNewer(file))
|
|
313
|
+
throw new Error(`${path} was written by a newer Honcho plugin; update this one.`);
|
|
314
|
+
const block = writeBlock(file, host, hostMigration(file, host, [], legacy));
|
|
315
|
+
if ("baseUrl" in patch && !("apiKey" in patch) && !sameServer(patch.baseUrl, str2(block.baseUrl)))
|
|
316
|
+
delete block.apiKey;
|
|
317
|
+
for (const [k, v] of Object.entries(patch)) {
|
|
318
|
+
if (v === undefined)
|
|
319
|
+
delete block[k];
|
|
320
|
+
else
|
|
321
|
+
block[k] = v;
|
|
249
322
|
}
|
|
250
|
-
|
|
323
|
+
block.schemaVersion = CONFIG_SCHEMA_VERSION;
|
|
324
|
+
});
|
|
251
325
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
326
|
+
var MOVABLE = ["apiKey", "peerName", "workspace", "aiPeer", "baseUrl"];
|
|
327
|
+
function isNewer(file) {
|
|
328
|
+
return isObj3(file) && typeof file.schemaVersion === "number" && file.schemaVersion > CONFIG_SCHEMA_VERSION;
|
|
255
329
|
}
|
|
256
|
-
function
|
|
257
|
-
|
|
258
|
-
delete cache.peers;
|
|
259
|
-
saveIdCache(cache);
|
|
330
|
+
function isMigrated(block) {
|
|
331
|
+
return isObj3(block) && typeof block.schemaVersion === "number" && block.schemaVersion >= CONFIG_SCHEMA_VERSION;
|
|
260
332
|
}
|
|
261
|
-
function
|
|
262
|
-
|
|
263
|
-
delete cache.userContext;
|
|
264
|
-
saveContextCache(cache);
|
|
333
|
+
function sameServer(a, b) {
|
|
334
|
+
return normalizeBaseUrl(a ?? DEFAULT_BASE_URL) === normalizeBaseUrl(b ?? DEFAULT_BASE_URL);
|
|
265
335
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
336
|
+
var LEGACY_HOST_KEYS = ["auth", "endpoint", "environmentUrl", "workspaceId"];
|
|
337
|
+
function isGrant(v) {
|
|
338
|
+
return isObj3(v) && typeof v.accessToken === "string" && v.accessToken !== "";
|
|
339
|
+
}
|
|
340
|
+
function legacyGrantOf(b) {
|
|
341
|
+
return !isGrant(b.oauth) && isObj3(b.auth) && isObj3(b.auth.oauth) ? b.auth.oauth : undefined;
|
|
342
|
+
}
|
|
343
|
+
function checkConfig(file) {
|
|
344
|
+
if (!isObj3(file))
|
|
345
|
+
return [];
|
|
346
|
+
if (isNewer(file)) {
|
|
347
|
+
return [{ path: "schemaVersion", message: `This file is schema version ${file.schemaVersion}, newer than this plugin understands; update the plugin.` }];
|
|
348
|
+
}
|
|
349
|
+
const issues = [];
|
|
350
|
+
const hosts = isObj3(file.hosts) ? file.hosts : {};
|
|
351
|
+
const byWorkspace = new Map;
|
|
352
|
+
for (const h of Object.keys(hosts).filter((k) => isObj3(hosts[k]))) {
|
|
353
|
+
const block = hosts[h];
|
|
354
|
+
const peer = str2(block.peerName);
|
|
355
|
+
if (!peer)
|
|
356
|
+
continue;
|
|
357
|
+
const ws = str2(block.workspace) ?? h;
|
|
358
|
+
const peers = byWorkspace.get(ws) ?? new Map;
|
|
359
|
+
peers.set(peer, [...peers.get(peer) ?? [], h]);
|
|
360
|
+
byWorkspace.set(ws, peers);
|
|
361
|
+
}
|
|
362
|
+
for (const [ws, peers] of byWorkspace) {
|
|
363
|
+
if (peers.size < 2)
|
|
364
|
+
continue;
|
|
365
|
+
const list = [...peers].map(([p, hs]) => `${hs.join(", ")}: "${p}"`).join("; ");
|
|
366
|
+
issues.push({ path: "hosts", message: `Hosts in workspace "${ws}" use different peerNames (${list}), so the user is split across peers.` });
|
|
367
|
+
}
|
|
368
|
+
return issues;
|
|
369
|
+
}
|
|
370
|
+
function hostMigration(file, host, deadKeys = [], legacy = v01Reader) {
|
|
371
|
+
if (isNewer(file))
|
|
372
|
+
return { set: {}, remove: [] };
|
|
373
|
+
const f = isObj3(file) ? file : {};
|
|
374
|
+
const hosts = isObj3(f.hosts) ? f.hosts : {};
|
|
375
|
+
const block = isObj3(hosts[host]) ? hosts[host] : {};
|
|
376
|
+
const set = {};
|
|
377
|
+
const drop = [];
|
|
378
|
+
const grant = legacyGrantOf(block);
|
|
379
|
+
if (grant)
|
|
380
|
+
set.oauth = grant;
|
|
381
|
+
if (!isMigrated(block)) {
|
|
382
|
+
const old = { ...legacy(f, host) };
|
|
383
|
+
const signedIn = isGrant(block.oauth) || grant !== undefined;
|
|
384
|
+
if (old.baseUrl && sameServer(old.baseUrl, undefined))
|
|
385
|
+
old.baseUrl = undefined;
|
|
386
|
+
for (const key of MOVABLE) {
|
|
387
|
+
if (signedIn && (key === "apiKey" || key === "baseUrl"))
|
|
388
|
+
continue;
|
|
389
|
+
if (old[key] !== undefined && block[key] !== old[key])
|
|
390
|
+
set[key] = old[key];
|
|
391
|
+
else if (old[key] === undefined && block[key] !== undefined)
|
|
392
|
+
drop.push(key);
|
|
393
|
+
}
|
|
394
|
+
set.schemaVersion = CONFIG_SCHEMA_VERSION;
|
|
395
|
+
}
|
|
396
|
+
const remove = [...drop, ...LEGACY_HOST_KEYS, ...deadKeys].filter((k) => (k in block) && !(k in set));
|
|
397
|
+
return { set, remove };
|
|
398
|
+
}
|
|
399
|
+
function effectiveBlock(file, host, legacy) {
|
|
400
|
+
return writeBlock(structuredClone(isObj3(file) ? file : {}), host, hostMigration(file, host, [], legacy));
|
|
401
|
+
}
|
|
402
|
+
function hostBlock(file, host) {
|
|
403
|
+
if (host === "__proto__" || host === "constructor" || host === "prototype")
|
|
404
|
+
throw new Error(`invalid host name: ${host}`);
|
|
405
|
+
if (!isObj3(file.hosts))
|
|
406
|
+
file.hosts = {};
|
|
407
|
+
return isObj3(file.hosts[host]) ? file.hosts[host] : file.hosts[host] = {};
|
|
408
|
+
}
|
|
409
|
+
function writeBlock(file, host, { set, remove }) {
|
|
410
|
+
const block = hostBlock(file, host);
|
|
411
|
+
Object.assign(block, set);
|
|
412
|
+
for (const k of remove)
|
|
413
|
+
delete block[k];
|
|
414
|
+
return block;
|
|
415
|
+
}
|
|
416
|
+
async function migrateHost(path, host, deadKeys = [], legacy) {
|
|
417
|
+
const peek = hostMigration(readConfigFile({ HONCHO_CONFIG_PATH: path }), host, deadKeys, legacy);
|
|
418
|
+
if (!Object.keys(peek.set).length && !peek.remove.length)
|
|
419
|
+
return [];
|
|
420
|
+
let changed = [];
|
|
421
|
+
await updateConfigFile(path, (file) => {
|
|
422
|
+
const m = hostMigration(file, host, deadKeys, legacy);
|
|
423
|
+
changed = [...Object.keys(m.set).filter((k) => k !== "schemaVersion"), ...m.remove.map((k) => `-${k}`)];
|
|
424
|
+
if (Object.keys(m.set).length || m.remove.length)
|
|
425
|
+
writeBlock(file, host, m);
|
|
426
|
+
});
|
|
427
|
+
return changed;
|
|
428
|
+
}
|
|
429
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/legacy/claude-honcho.js
|
|
430
|
+
var isObj4 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
431
|
+
var str3 = (v) => typeof v === "string" && v ? v : undefined;
|
|
432
|
+
function claudeHonchoReader(file, host) {
|
|
433
|
+
const hosts = isObj4(file.hosts) ? file.hosts : {};
|
|
434
|
+
const found = hosts[host] ?? hosts[host.replace(/_/g, "-")] ?? hosts[host.replace(/-/g, "_")];
|
|
435
|
+
const block = isObj4(found) ? found : undefined;
|
|
436
|
+
const endpoint = block?.endpoint ?? file.endpoint;
|
|
437
|
+
const override = file.globalOverride === true;
|
|
438
|
+
return {
|
|
439
|
+
apiKey: str3(block?.apiKey) ?? str3(file.apiKey),
|
|
440
|
+
baseUrl: str3(endpoint?.baseUrl)?.replace(/\/v3\/?$/, "") ?? (endpoint?.environment === "local" ? "http://localhost:8000" : undefined),
|
|
441
|
+
peerName: str3(file.peerName),
|
|
442
|
+
workspace: str3(override || !block ? file.workspace : block.workspace),
|
|
443
|
+
aiPeer: str3(override ? file.aiPeer ?? block?.aiPeer : block ? block.aiPeer : file[host === "cursor" ? "cursorPeer" : "claudePeer"])
|
|
444
|
+
};
|
|
270
445
|
}
|
|
271
|
-
// node_modules/@honcho-ai/harness-plugin-core/
|
|
446
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/telemetry.js
|
|
272
447
|
var HEADER_HOST = "X-Honcho-Host";
|
|
273
448
|
var HEADER_PLUGIN = "X-Honcho-Plugin";
|
|
274
449
|
var HEADER_AGENT_MODEL = "X-Honcho-Agent-Model";
|
|
@@ -317,31 +492,10 @@ function telemetryHeaders(id = {}, extra) {
|
|
|
317
492
|
return headers;
|
|
318
493
|
}
|
|
319
494
|
// src/config.ts
|
|
495
|
+
var LEGACY = claudeHonchoReader;
|
|
320
496
|
function sanitizeForSessionName(s) {
|
|
321
497
|
return s.toLowerCase().replace(/[^a-z0-9-_]/g, "-");
|
|
322
498
|
}
|
|
323
|
-
var SESSION_START_COMPONENTS = ["directives", "summary", "peerCard", "peerRepresentation", "briefing"];
|
|
324
|
-
var PER_TURN_COMPONENTS = ["userContext", "assistantContext", "sessionContext", "dialectic"];
|
|
325
|
-
function normalizePerTurn(components) {
|
|
326
|
-
return components.map((c) => c === "context" ? "userContext" : c);
|
|
327
|
-
}
|
|
328
|
-
var DEFAULT_INJECTION = {
|
|
329
|
-
sessionStart: ["directives", "summary", "peerCard"],
|
|
330
|
-
perTurn: ["userContext"],
|
|
331
|
-
showContents: [],
|
|
332
|
-
searchTopK: 10,
|
|
333
|
-
maxConclusions: 15,
|
|
334
|
-
searchMaxDistance: 0.6,
|
|
335
|
-
searchQuerySource: "prompt",
|
|
336
|
-
sessionContextTokens: 1500,
|
|
337
|
-
dialecticTemplate: "Return a compact, factual list of anything from the user's history — preferences, prior decisions, relevant past work — that would help with the following. Write in the third person as background notes; do not address the user, ask questions, or offer next steps. If nothing relevant exists, say so in one line. Relevant to: %{user_query}",
|
|
338
|
-
dialecticReasoning: "medium"
|
|
339
|
-
};
|
|
340
|
-
var REASONING_LEVELS = ["minimal", "low", "medium", "high", "max"];
|
|
341
|
-
var HONCHO_BASE_URLS = {
|
|
342
|
-
production: "https://api.honcho.dev/v3",
|
|
343
|
-
local: "http://localhost:8000/v3"
|
|
344
|
-
};
|
|
345
499
|
var _detectedHost = null;
|
|
346
500
|
function setDetectedHost(host) {
|
|
347
501
|
_detectedHost = host;
|
|
@@ -369,13 +523,6 @@ var DEFAULT_AI_PEER = {
|
|
|
369
523
|
claude_code: "claude",
|
|
370
524
|
obsidian: "honcho"
|
|
371
525
|
};
|
|
372
|
-
function coerceBoolean(value) {
|
|
373
|
-
if (typeof value === "string") {
|
|
374
|
-
const v = value.trim().toLowerCase();
|
|
375
|
-
return v !== "false" && v !== "0" && v !== "";
|
|
376
|
-
}
|
|
377
|
-
return Boolean(value);
|
|
378
|
-
}
|
|
379
526
|
var _stdinText = null;
|
|
380
527
|
function cacheStdin(text) {
|
|
381
528
|
_stdinText = text;
|
|
@@ -402,31 +549,14 @@ async function initHook() {
|
|
|
402
549
|
process.exit(0);
|
|
403
550
|
setDetectedHost(detectHost(input));
|
|
404
551
|
}
|
|
405
|
-
function deepEqual(a, b) {
|
|
406
|
-
if (a === b)
|
|
407
|
-
return true;
|
|
408
|
-
if (a == null || b == null)
|
|
409
|
-
return a === b;
|
|
410
|
-
if (typeof a !== typeof b)
|
|
411
|
-
return false;
|
|
412
|
-
if (typeof a !== "object")
|
|
413
|
-
return false;
|
|
414
|
-
const aObj = a;
|
|
415
|
-
const bObj = b;
|
|
416
|
-
const keys = new Set([...Object.keys(aObj), ...Object.keys(bObj)]);
|
|
417
|
-
for (const key of keys) {
|
|
418
|
-
if (!deepEqual(aObj[key], bObj[key]))
|
|
419
|
-
return false;
|
|
420
|
-
}
|
|
421
|
-
return true;
|
|
422
|
-
}
|
|
423
|
-
var CONFIG_DIR = join3(homedir2(), ".honcho");
|
|
424
|
-
var CONFIG_FILE = join3(CONFIG_DIR, "config.json");
|
|
425
552
|
function getConfigPath() {
|
|
426
|
-
return
|
|
553
|
+
return configPath();
|
|
554
|
+
}
|
|
555
|
+
function getConfigDir() {
|
|
556
|
+
return dirname2(configPath());
|
|
427
557
|
}
|
|
428
558
|
function configExists() {
|
|
429
|
-
return existsSync3(
|
|
559
|
+
return existsSync3(configPath());
|
|
430
560
|
}
|
|
431
561
|
function getPluginVersion() {
|
|
432
562
|
const root = process.env.CLAUDE_PLUGIN_ROOT;
|
|
@@ -436,339 +566,142 @@ function getPluginVersion() {
|
|
|
436
566
|
];
|
|
437
567
|
for (const manifest of candidates) {
|
|
438
568
|
try {
|
|
439
|
-
const version = JSON.parse(
|
|
569
|
+
const version = JSON.parse(readFileSync3(manifest, "utf-8")).version;
|
|
440
570
|
if (typeof version === "string" && version)
|
|
441
571
|
return version;
|
|
442
572
|
} catch {}
|
|
443
573
|
}
|
|
444
574
|
return "unknown";
|
|
445
575
|
}
|
|
446
|
-
function
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
return resolveConfig2(raw, resolvedHost);
|
|
453
|
-
} catch {}
|
|
454
|
-
}
|
|
455
|
-
return loadConfigFromEnv(resolvedHost);
|
|
576
|
+
function legacyEndpoint(value) {
|
|
577
|
+
if (value === "local")
|
|
578
|
+
return "http://localhost:8000";
|
|
579
|
+
if (value?.startsWith("http"))
|
|
580
|
+
return value.replace(/\/v3\/?$/, "");
|
|
581
|
+
return;
|
|
456
582
|
}
|
|
457
|
-
function
|
|
458
|
-
const
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
if (
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
workspace,
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
sessionPeerPrefix: hostBlock?.sessionPeerPrefix ?? raw.sessionPeerPrefix,
|
|
486
|
-
sessions: raw.sessions,
|
|
487
|
-
saveMessages: hostBlock?.saveMessages ?? raw.saveMessages,
|
|
488
|
-
saveToolUse: hostBlock?.saveToolUse ?? raw.saveToolUse,
|
|
489
|
-
saveGitEvents: hostBlock?.saveGitEvents ?? raw.saveGitEvents,
|
|
490
|
-
reasoningLevel: hostBlock?.reasoningLevel ?? raw.reasoningLevel,
|
|
491
|
-
observationMode: hostBlock?.observationMode ?? raw.observationMode,
|
|
492
|
-
messageUpload: hostBlock?.messageUpload ?? raw.messageUpload,
|
|
493
|
-
contextRefresh: hostBlock?.contextRefresh ?? raw.contextRefresh,
|
|
494
|
-
endpoint: hostBlock?.endpoint ?? raw.endpoint,
|
|
495
|
-
redactPatterns: hostBlock?.redactPatterns ?? raw.redactPatterns,
|
|
496
|
-
injection: hostBlock?.injection ?? raw.injection,
|
|
497
|
-
rememberTool: hostBlock?.rememberTool ?? raw.rememberTool,
|
|
498
|
-
enabled: hostBlock?.enabled ?? raw.enabled,
|
|
499
|
-
logging: hostBlock?.logging ?? raw.logging,
|
|
500
|
-
globalOverride: raw.globalOverride
|
|
501
|
-
};
|
|
502
|
-
return mergeWithEnvVars(config);
|
|
583
|
+
function legacyEnv(host = getDetectedHost()) {
|
|
584
|
+
const env = process.env;
|
|
585
|
+
const peerVar = host === "cursor" ? "HONCHO_CURSOR_PEER" : "HONCHO_CLAUDE_PEER";
|
|
586
|
+
const candidates = [
|
|
587
|
+
["HONCHO_BASE_URL", "baseUrl", "HONCHO_ENDPOINT", legacyEndpoint(env.HONCHO_ENDPOINT)],
|
|
588
|
+
["HONCHO_AI_PEER", "aiPeer", peerVar, env[peerVar] || undefined]
|
|
589
|
+
];
|
|
590
|
+
const set = candidates.filter(([newVar, , , value]) => value && !env[newVar]);
|
|
591
|
+
if (!set.length)
|
|
592
|
+
return {};
|
|
593
|
+
const block = effectiveBlock(readConfigFile(), host, LEGACY);
|
|
594
|
+
if (block.apiKey || block.oauth)
|
|
595
|
+
return {};
|
|
596
|
+
return Object.fromEntries(set.filter(([, setting]) => !block[setting]).map(([newVar, , oldVar, value]) => [newVar, [oldVar, value]]));
|
|
597
|
+
}
|
|
598
|
+
function honchoEnv(host) {
|
|
599
|
+
const legacy = Object.entries(legacyEnv(host));
|
|
600
|
+
if (!legacy.length)
|
|
601
|
+
return process.env;
|
|
602
|
+
return { ...process.env, ...Object.fromEntries(legacy.map(([k, [, value]]) => [k, value])) };
|
|
603
|
+
}
|
|
604
|
+
function resolveHost(host) {
|
|
605
|
+
return resolveConfig(readConfigFile(), {
|
|
606
|
+
host,
|
|
607
|
+
env: honchoEnv(host),
|
|
608
|
+
defaults: { workspace: DEFAULT_WORKSPACE[host], aiPeer: DEFAULT_AI_PEER[host] },
|
|
609
|
+
legacy: LEGACY
|
|
610
|
+
});
|
|
503
611
|
}
|
|
504
|
-
function
|
|
505
|
-
|
|
506
|
-
|
|
612
|
+
function isLoggingEnabled(host = getDetectedHost()) {
|
|
613
|
+
if (process.env.HONCHO_LOGGING === "false")
|
|
614
|
+
return false;
|
|
615
|
+
const file = readConfigFile();
|
|
616
|
+
const hosts = file.hosts && typeof file.hosts === "object" ? file.hosts : {};
|
|
617
|
+
const own = [hosts[host], hosts[host.replace(/_/g, "-")]].map((block) => block && typeof block === "object" ? block.logging : undefined).find((v) => v !== undefined);
|
|
618
|
+
return (own ?? file.logging) !== false;
|
|
619
|
+
}
|
|
620
|
+
function loadConfig2(host = getDetectedHost()) {
|
|
621
|
+
const cfg = resolveHost(host);
|
|
622
|
+
const cred = pickCredential(readConfigFile(), { host, baseUrl: cfg.baseUrl, env: honchoEnv(host), legacy: LEGACY });
|
|
623
|
+
if (!cred)
|
|
507
624
|
return null;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
apiKey,
|
|
517
|
-
peerName,
|
|
518
|
-
workspace,
|
|
519
|
-
aiPeer,
|
|
520
|
-
saveMessages: process.env.HONCHO_SAVE_MESSAGES !== "false",
|
|
521
|
-
saveToolUse: process.env.HONCHO_SAVE_TOOL_USE === "true",
|
|
522
|
-
saveGitEvents: process.env.HONCHO_SAVE_GIT_EVENTS === "true",
|
|
523
|
-
enabled: process.env.HONCHO_ENABLED !== "false",
|
|
524
|
-
logging: process.env.HONCHO_LOGGING !== "false"
|
|
625
|
+
const { token, ...authState } = cred;
|
|
626
|
+
return {
|
|
627
|
+
apiKey: token,
|
|
628
|
+
auth: { ...authState, host },
|
|
629
|
+
peerName: cfg.peerName,
|
|
630
|
+
workspace: cfg.workspace,
|
|
631
|
+
aiPeer: cfg.aiPeer,
|
|
632
|
+
baseUrl: cfg.baseUrl
|
|
525
633
|
};
|
|
526
|
-
if (endpoint) {
|
|
527
|
-
if (endpoint === "local") {
|
|
528
|
-
config.endpoint = { environment: "local" };
|
|
529
|
-
} else if (endpoint.startsWith("http")) {
|
|
530
|
-
config.endpoint = { baseUrl: endpoint };
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
return config;
|
|
534
|
-
}
|
|
535
|
-
function mergeWithEnvVars(config) {
|
|
536
|
-
if (process.env.HONCHO_API_KEY) {
|
|
537
|
-
config.apiKey = process.env.HONCHO_API_KEY;
|
|
538
|
-
}
|
|
539
|
-
if (process.env.HONCHO_PEER_NAME) {
|
|
540
|
-
config.peerName = process.env.HONCHO_PEER_NAME;
|
|
541
|
-
}
|
|
542
|
-
if (process.env.HONCHO_ENABLED === "false") {
|
|
543
|
-
config.enabled = false;
|
|
544
|
-
}
|
|
545
|
-
if (process.env.HONCHO_LOGGING === "false") {
|
|
546
|
-
config.logging = false;
|
|
547
|
-
}
|
|
548
|
-
if (process.env.HONCHO_SAVE_MESSAGES === "false") {
|
|
549
|
-
config.saveMessages = false;
|
|
550
|
-
}
|
|
551
|
-
if (process.env.HONCHO_SAVE_TOOL_USE !== undefined) {
|
|
552
|
-
config.saveToolUse = process.env.HONCHO_SAVE_TOOL_USE === "true";
|
|
553
|
-
}
|
|
554
|
-
if (process.env.HONCHO_SAVE_GIT_EVENTS !== undefined) {
|
|
555
|
-
config.saveGitEvents = process.env.HONCHO_SAVE_GIT_EVENTS === "true";
|
|
556
|
-
}
|
|
557
|
-
return config;
|
|
558
|
-
}
|
|
559
|
-
function writeConfigFile(data) {
|
|
560
|
-
if (existsSync3(CONFIG_FILE))
|
|
561
|
-
chmodSync(CONFIG_FILE, 384);
|
|
562
|
-
writeFileSync2(CONFIG_FILE, JSON.stringify(data, null, 2), { mode: 384 });
|
|
563
634
|
}
|
|
564
|
-
function saveConfig(config) {
|
|
565
|
-
if (!existsSync3(CONFIG_DIR)) {
|
|
566
|
-
mkdirSync2(CONFIG_DIR, { recursive: true });
|
|
567
|
-
}
|
|
568
|
-
let existing = {};
|
|
569
|
-
if (existsSync3(CONFIG_FILE)) {
|
|
570
|
-
try {
|
|
571
|
-
existing = JSON.parse(readFileSync2(CONFIG_FILE, "utf-8"));
|
|
572
|
-
} catch {}
|
|
573
|
-
}
|
|
574
|
-
if (config.sessions !== undefined) {
|
|
575
|
-
existing.sessions = config.sessions;
|
|
576
|
-
}
|
|
635
|
+
async function saveConfig(config, field) {
|
|
577
636
|
const host = getDetectedHost();
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
const
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
function saveRootField(field, value) {
|
|
615
|
-
if (!existsSync3(CONFIG_DIR)) {
|
|
616
|
-
mkdirSync2(CONFIG_DIR, { recursive: true });
|
|
617
|
-
}
|
|
618
|
-
let existing = {};
|
|
619
|
-
if (existsSync3(CONFIG_FILE)) {
|
|
620
|
-
try {
|
|
621
|
-
existing = JSON.parse(readFileSync2(CONFIG_FILE, "utf-8"));
|
|
622
|
-
} catch {}
|
|
623
|
-
}
|
|
624
|
-
existing[field] = value;
|
|
625
|
-
writeConfigFile(existing);
|
|
626
|
-
}
|
|
627
|
-
function resolveWorktreeMainRoot(dir) {
|
|
628
|
-
try {
|
|
629
|
-
const gitPath = join3(dir, ".git");
|
|
630
|
-
if (!statSync(gitPath).isFile())
|
|
631
|
-
return null;
|
|
632
|
-
const match = readFileSync2(gitPath, "utf-8").match(/^gitdir:\s*(.+?)\s*$/m);
|
|
633
|
-
if (!match)
|
|
634
|
-
return null;
|
|
635
|
-
const gitdir = resolve(dir, match[1]);
|
|
636
|
-
const idx = gitdir.lastIndexOf(`${sep}worktrees${sep}`);
|
|
637
|
-
if (idx === -1)
|
|
638
|
-
return null;
|
|
639
|
-
const gitContainer = gitdir.slice(0, idx);
|
|
640
|
-
if (basename(gitContainer) === ".git")
|
|
641
|
-
return dirname(gitContainer);
|
|
642
|
-
if (gitContainer.endsWith(".git"))
|
|
643
|
-
return gitContainer;
|
|
644
|
-
return null;
|
|
645
|
-
} catch {
|
|
646
|
-
return null;
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
var MAX_GIT_WALK_UP = 12;
|
|
650
|
-
function worktreeMainRootFor(cwd) {
|
|
637
|
+
const env = honchoEnv(host);
|
|
638
|
+
const write = (key, envVar) => key === field || !env[envVar];
|
|
639
|
+
const patch = {};
|
|
640
|
+
if (write("peerName", "HONCHO_PEER_NAME"))
|
|
641
|
+
patch.peerName = config.peerName;
|
|
642
|
+
if (write("workspace", "HONCHO_WORKSPACE"))
|
|
643
|
+
patch.workspace = config.workspace === DEFAULT_WORKSPACE[host] ? undefined : config.workspace;
|
|
644
|
+
if (write("aiPeer", "HONCHO_AI_PEER"))
|
|
645
|
+
patch.aiPeer = config.aiPeer === DEFAULT_AI_PEER[host] ? undefined : config.aiPeer;
|
|
646
|
+
if (write("baseUrl", "HONCHO_BASE_URL"))
|
|
647
|
+
patch.baseUrl = config.baseUrl === DEFAULT_BASE_URL ? undefined : config.baseUrl;
|
|
648
|
+
await saveHost(configPath(), host, patch, LEGACY);
|
|
649
|
+
}
|
|
650
|
+
function getConfigIssues(host = getDetectedHost()) {
|
|
651
|
+
return checkConfig(readConfigFile()).filter((i) => i.path === "schemaVersion" || i.path === "hosts" && i.message.includes(host)).map((i) => i.message);
|
|
652
|
+
}
|
|
653
|
+
var DEAD_HOST_KEYS = [
|
|
654
|
+
"sessionStrategy",
|
|
655
|
+
"sessionPeerPrefix",
|
|
656
|
+
"sessions",
|
|
657
|
+
"injection",
|
|
658
|
+
"contextRefresh",
|
|
659
|
+
"messageUpload",
|
|
660
|
+
"reasoningLevel",
|
|
661
|
+
"statusline",
|
|
662
|
+
"saveToolUse",
|
|
663
|
+
"saveGitEvents",
|
|
664
|
+
"redactPatterns",
|
|
665
|
+
"rememberTool",
|
|
666
|
+
"observationMode",
|
|
667
|
+
"saveMessages",
|
|
668
|
+
"enabled",
|
|
669
|
+
"globalOverride",
|
|
670
|
+
"linkedHosts"
|
|
671
|
+
];
|
|
672
|
+
async function migrateConfig(host = getDetectedHost()) {
|
|
651
673
|
try {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
return resolveWorktreeMainRoot(dir);
|
|
656
|
-
const parent = dirname(dir);
|
|
657
|
-
if (parent === dir)
|
|
658
|
-
break;
|
|
659
|
-
dir = parent;
|
|
660
|
-
}
|
|
674
|
+
const changed = await migrateHost(configPath(), host, DEAD_HOST_KEYS, LEGACY);
|
|
675
|
+
if (changed.length)
|
|
676
|
+
return `[honcho] Moved your Honcho settings into hosts.${host} in ~/.honcho/config.json.`;
|
|
661
677
|
} catch {}
|
|
662
|
-
return
|
|
678
|
+
return;
|
|
663
679
|
}
|
|
664
|
-
function
|
|
665
|
-
const
|
|
666
|
-
|
|
667
|
-
return null;
|
|
668
|
-
if (config.sessions[cwd])
|
|
669
|
-
return config.sessions[cwd];
|
|
670
|
-
const mr = mainRoot === undefined ? worktreeMainRootFor(cwd) : mainRoot;
|
|
671
|
-
if (mr && config.sessions[mr])
|
|
672
|
-
return config.sessions[mr];
|
|
673
|
-
return null;
|
|
674
|
-
}
|
|
675
|
-
function deriveSessionName(strategy, cwd, opts = {}) {
|
|
676
|
-
const usePrefix = opts.sessionPeerPrefix !== false;
|
|
677
|
-
const peerPart = opts.peerName ? sanitizeForSessionName(opts.peerName) : "user";
|
|
678
|
-
const repoPart = sanitizeForSessionName(basename(cwd));
|
|
679
|
-
const base = usePrefix ? `${peerPart}-${repoPart}` : repoPart;
|
|
680
|
-
switch (strategy) {
|
|
681
|
-
case "git-branch": {
|
|
682
|
-
if (opts.branch) {
|
|
683
|
-
const branchPart = sanitizeForSessionName(opts.branch);
|
|
684
|
-
return `${base}-${branchPart}`;
|
|
685
|
-
}
|
|
686
|
-
return base;
|
|
687
|
-
}
|
|
688
|
-
case "chat-instance": {
|
|
689
|
-
if (opts.instanceId) {
|
|
690
|
-
return usePrefix ? `${peerPart}-chat-${opts.instanceId}` : `chat-${opts.instanceId}`;
|
|
691
|
-
}
|
|
692
|
-
return base;
|
|
693
|
-
}
|
|
694
|
-
case "per-directory":
|
|
695
|
-
default:
|
|
696
|
-
return base;
|
|
697
|
-
}
|
|
680
|
+
function getSessionName(sessionId) {
|
|
681
|
+
const id = sessionId || process.env.CLAUDE_CODE_SESSION_ID;
|
|
682
|
+
return id ? sanitizeForSessionName(id) : null;
|
|
698
683
|
}
|
|
699
|
-
function
|
|
700
|
-
const
|
|
701
|
-
|
|
702
|
-
const mainRoot = worktreeMainRootFor(cwd);
|
|
703
|
-
if (strategy === "per-directory") {
|
|
704
|
-
const configuredSession = getSessionForPath(cwd, mainRoot);
|
|
705
|
-
if (configuredSession) {
|
|
706
|
-
return configuredSession;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
let branch;
|
|
710
|
-
if (strategy === "git-branch") {
|
|
711
|
-
branch = captureGitState(cwd)?.branch;
|
|
712
|
-
}
|
|
713
|
-
let resolvedInstanceId;
|
|
714
|
-
if (strategy === "chat-instance") {
|
|
715
|
-
resolvedInstanceId = instanceId || getInstanceIdForCwd(cwd) || getClaudeInstanceId() || undefined;
|
|
716
|
-
}
|
|
717
|
-
return deriveSessionName(strategy, mainRoot ?? cwd, {
|
|
718
|
-
peerName: config?.peerName,
|
|
719
|
-
sessionPeerPrefix: config?.sessionPeerPrefix,
|
|
720
|
-
branch,
|
|
721
|
-
instanceId: resolvedInstanceId
|
|
722
|
-
});
|
|
684
|
+
function getKnownHosts() {
|
|
685
|
+
const hosts = readConfigFile().hosts;
|
|
686
|
+
return hosts && typeof hosts === "object" ? Object.keys(hosts) : [];
|
|
723
687
|
}
|
|
724
|
-
function
|
|
725
|
-
const
|
|
726
|
-
|
|
688
|
+
async function refreshCredential(config) {
|
|
689
|
+
const host = config.auth?.host ?? getDetectedHost();
|
|
690
|
+
const cred = await ensureFreshCredential({ path: configPath(), host, baseUrl: config.baseUrl, env: honchoEnv(host), legacy: LEGACY });
|
|
691
|
+
if (!cred)
|
|
727
692
|
return;
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
}
|
|
731
|
-
config.sessions[cwd] = sessionName;
|
|
732
|
-
saveConfig(config);
|
|
733
|
-
}
|
|
734
|
-
function getInjectionConfig(config) {
|
|
735
|
-
const injection = (config === undefined ? loadConfig2() : config)?.injection;
|
|
736
|
-
const resolved = { ...DEFAULT_INJECTION, ...injection ?? {} };
|
|
737
|
-
resolved.perTurn = Array.isArray(resolved.perTurn) ? normalizePerTurn(resolved.perTurn) : DEFAULT_INJECTION.perTurn;
|
|
738
|
-
resolved.showContents = Array.isArray(resolved.showContents) ? normalizePerTurn(resolved.showContents) : DEFAULT_INJECTION.showContents;
|
|
739
|
-
return resolved;
|
|
740
|
-
}
|
|
741
|
-
function isLoggingEnabled() {
|
|
742
|
-
const config = loadConfig2();
|
|
743
|
-
return config?.logging !== false;
|
|
744
|
-
}
|
|
745
|
-
function isPluginEnabled() {
|
|
746
|
-
const config = loadConfig2();
|
|
747
|
-
return config?.enabled !== false;
|
|
748
|
-
}
|
|
749
|
-
function getKnownHosts() {
|
|
750
|
-
const cfgPath = getConfigPath();
|
|
751
|
-
if (!existsSync3(cfgPath))
|
|
752
|
-
return [];
|
|
753
|
-
try {
|
|
754
|
-
const raw = JSON.parse(readFileSync2(cfgPath, "utf-8"));
|
|
755
|
-
return raw.hosts ? Object.keys(raw.hosts) : [];
|
|
756
|
-
} catch {
|
|
757
|
-
return [];
|
|
758
|
-
}
|
|
693
|
+
const { token, ...authState } = cred;
|
|
694
|
+
config.apiKey = token;
|
|
695
|
+
config.auth = { ...authState, host };
|
|
759
696
|
}
|
|
760
|
-
function
|
|
761
|
-
if (
|
|
762
|
-
|
|
763
|
-
return url.endsWith("/v3") ? url : `${url}/v3`;
|
|
697
|
+
function getAuthNotice(config) {
|
|
698
|
+
if (config.auth?.reauthRequired) {
|
|
699
|
+
return "[honcho] Your Honcho sign-in has expired. Run /honcho setup to sign in again.";
|
|
764
700
|
}
|
|
765
|
-
|
|
766
|
-
return HONCHO_BASE_URLS.local;
|
|
767
|
-
}
|
|
768
|
-
return HONCHO_BASE_URLS.production;
|
|
701
|
+
return;
|
|
769
702
|
}
|
|
770
703
|
function getHonchoBaseUrl(config) {
|
|
771
|
-
return
|
|
704
|
+
return `${config.baseUrl}/v3`;
|
|
772
705
|
}
|
|
773
706
|
function getTelemetryHeaders(host = getDetectedHost()) {
|
|
774
707
|
return telemetryHeaders({
|
|
@@ -788,49 +721,50 @@ function getHonchoClientOptions(config) {
|
|
|
788
721
|
};
|
|
789
722
|
}
|
|
790
723
|
function isProductionEndpoint(config) {
|
|
791
|
-
return
|
|
724
|
+
return config.baseUrl === DEFAULT_BASE_URL;
|
|
792
725
|
}
|
|
793
726
|
function getEndpointInfo(config) {
|
|
794
|
-
|
|
795
|
-
return { type: "custom", url: config.endpoint.baseUrl };
|
|
796
|
-
}
|
|
797
|
-
if (config.endpoint?.environment === "local") {
|
|
798
|
-
return { type: "local", url: HONCHO_BASE_URLS.local };
|
|
799
|
-
}
|
|
800
|
-
return { type: "production", url: HONCHO_BASE_URLS.production };
|
|
801
|
-
}
|
|
802
|
-
var VALID_ENVIRONMENTS = new Set(["production", "local"]);
|
|
803
|
-
function getObservationMode(config) {
|
|
804
|
-
return config.observationMode ?? "unified";
|
|
727
|
+
return { type: isProductionEndpoint(config) ? "production" : "custom", url: config.baseUrl };
|
|
805
728
|
}
|
|
806
729
|
|
|
807
730
|
// src/state.ts
|
|
808
|
-
import { homedir as
|
|
731
|
+
import { homedir as homedir2 } from "os";
|
|
809
732
|
import { join as join4 } from "path";
|
|
810
|
-
import { writeFileSync as
|
|
811
|
-
var DIR = join4(
|
|
733
|
+
import { writeFileSync as writeFileSync2, unlinkSync as unlinkSync2 } from "fs";
|
|
734
|
+
var DIR = join4(homedir2(), ".honcho");
|
|
812
735
|
function stateFile(sessionId) {
|
|
813
736
|
return join4(DIR, sessionId ? `state-${sessionId}.json` : "state.json");
|
|
814
737
|
}
|
|
815
738
|
function sessionFile(sessionId) {
|
|
816
739
|
return join4(DIR, sessionId ? `session-${sessionId}.json` : "session.json");
|
|
817
740
|
}
|
|
741
|
+
function noticeFile(sessionId) {
|
|
742
|
+
return join4(DIR, `notice-${sessionId}.json`);
|
|
743
|
+
}
|
|
744
|
+
function isModActive() {
|
|
745
|
+
return process.env.HONCHO_MOD_UI === "1";
|
|
746
|
+
}
|
|
747
|
+
function setNotice(text, sessionId) {
|
|
748
|
+
try {
|
|
749
|
+
writeFileSync2(noticeFile(sessionId), JSON.stringify({ text }));
|
|
750
|
+
} catch {}
|
|
751
|
+
}
|
|
818
752
|
function setMemoryState(phase, detail, sessionId) {
|
|
819
753
|
try {
|
|
820
|
-
|
|
754
|
+
writeFileSync2(stateFile(sessionId), JSON.stringify({ phase, since: Date.now(), detail }));
|
|
821
755
|
} catch {}
|
|
822
756
|
}
|
|
823
757
|
function setSessionLink(url, name, sessionId) {
|
|
824
758
|
try {
|
|
825
|
-
|
|
759
|
+
writeFileSync2(sessionFile(sessionId), JSON.stringify({ url, name }));
|
|
826
760
|
} catch {}
|
|
827
761
|
}
|
|
828
762
|
function clearSessionFiles(sessionId) {
|
|
829
763
|
if (!sessionId)
|
|
830
764
|
return;
|
|
831
|
-
for (const f of [stateFile(sessionId), sessionFile(sessionId)]) {
|
|
765
|
+
for (const f of [stateFile(sessionId), sessionFile(sessionId), noticeFile(sessionId)]) {
|
|
832
766
|
try {
|
|
833
|
-
|
|
767
|
+
unlinkSync2(f);
|
|
834
768
|
} catch {}
|
|
835
769
|
}
|
|
836
770
|
}
|
|
@@ -839,8 +773,6 @@ function clearSessionFiles(sessionId) {
|
|
|
839
773
|
var LABELS = {
|
|
840
774
|
search: "searching",
|
|
841
775
|
chat: "asking",
|
|
842
|
-
get_context: "context",
|
|
843
|
-
get_representation: "recall",
|
|
844
776
|
create_conclusion: "writing",
|
|
845
777
|
list_conclusions: "listing",
|
|
846
778
|
delete_conclusion: "writing",
|
|
@@ -848,6 +780,8 @@ var LABELS = {
|
|
|
848
780
|
set_config: "config"
|
|
849
781
|
};
|
|
850
782
|
async function handlePreToolHoncho() {
|
|
783
|
+
if (isModActive())
|
|
784
|
+
process.exit(0);
|
|
851
785
|
try {
|
|
852
786
|
const raw = getCachedStdin();
|
|
853
787
|
const input = raw && raw.trim() ? JSON.parse(raw) : {};
|
|
@@ -865,5 +799,5 @@ async function main() {
|
|
|
865
799
|
// hooks/pre-tool-honcho.ts
|
|
866
800
|
await main();
|
|
867
801
|
|
|
868
|
-
//# debugId=
|
|
802
|
+
//# debugId=F1F92C66A06367F864756E2164756E21
|
|
869
803
|
//# sourceMappingURL=pre-tool-honcho.js.map
|