@indigoai-us/hq-cli 5.345.242 → 5.345.244
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/CHANGELOG.md +13 -0
- package/dist/command-catalog.generated.d.ts +3 -3
- package/dist/command-catalog.generated.js +3 -3
- package/dist/commands/bot.d.ts +12 -0
- package/dist/commands/bot.js +126 -44
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +285 -225
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lib/bot/config.d.ts +10 -0
- package/dist/lib/bot/config.js +15 -0
- package/dist/lib/bot/continuity.js +2 -2
- package/dist/lib/bot/promote-sign-in.d.ts +78 -0
- package/dist/lib/bot/promote-sign-in.js +152 -0
- package/dist/lib/bot/promote.d.ts +19 -1
- package/dist/lib/bot/promote.js +25 -5
- package/dist/lib/bot/scaffold.d.ts +20 -3
- package/dist/lib/bot/scaffold.js +18 -8
- package/dist/lib/claude-md-imports.d.ts +52 -0
- package/dist/lib/claude-md-imports.js +226 -0
- package/dist/lib/daemon/hook-requests-fleet-session-start.d.ts +10 -0
- package/dist/lib/daemon/hook-requests-fleet-session-start.js +86 -42
- package/dist/lib/daemon/hook-requests.d.ts +2 -2
- package/dist/lib/daemon/hook-requests.js +13 -3
- package/dist/lib/doctor/checks/claude-imports.d.ts +29 -0
- package/dist/lib/doctor/checks/claude-imports.js +131 -0
- package/dist/lib/doctor/fix/apply.d.ts +7 -0
- package/dist/lib/doctor/fix/apply.js +77 -0
- package/dist/lib/doctor/fix/remediation.d.ts +11 -1
- package/dist/lib/doctor/fix/remediation.js +42 -0
- package/dist/lib/doctor/registry.js +4 -0
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/lanes/liveness.js +46 -16
- package/package.json +8 -8
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code `@import` paths that never load.
|
|
3
|
+
*
|
|
4
|
+
* Claude Code finds imports with `(?:^|\s)@((?:[^\s\\]|\\ )+)` and turns each
|
|
5
|
+
* `\ ` into a space, so `\ ` is an escaped space and any other backslash ends
|
|
6
|
+
* the path. `@C:\Users\me\hq\.claude\CLAUDE.md` therefore imports `C:` and
|
|
7
|
+
* nothing loads, while `@C:/Users/me/hq/.claude/CLAUDE.md` loads on Windows
|
|
8
|
+
* too. Nothing reports the failure (feedback_362cdca7).
|
|
9
|
+
*
|
|
10
|
+
* Pure text functions only. Claude Code does not import from code spans,
|
|
11
|
+
* fenced or indented code blocks, or HTML comments, so neither do these.
|
|
12
|
+
*/
|
|
13
|
+
/** `@` at the start of a line or after whitespace, then the path; `\ ` stays inside it. */
|
|
14
|
+
const IMPORT_TOKEN = /(^|\s)@((?:\\ |\S)+)/g;
|
|
15
|
+
/**
|
|
16
|
+
* A path backslash: not an escaped space, and not a Markdown escape (a
|
|
17
|
+
* backslash before ASCII punctuation, as in `my\_file.md`). A path that has
|
|
18
|
+
* one is a Windows path, and all of its backslashes are separators.
|
|
19
|
+
*/
|
|
20
|
+
const BAD_BACKSLASH = /\\(?![ !"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/;
|
|
21
|
+
/** One more space-separated chunk after a token, for a Windows path with a space in it. */
|
|
22
|
+
const CONTINUATION = /^ ((?:\\ |\S)+)/;
|
|
23
|
+
/**
|
|
24
|
+
* A chunk that is not part of the path before it: a new path (drive letter,
|
|
25
|
+
* `\`, `.`, `/`, `@`), so `@C:\x\y.md \foo` or `..\other.md` stays text.
|
|
26
|
+
*/
|
|
27
|
+
const NEW_PATH = /^(?:[A-Za-z]:|[\\./@])/;
|
|
28
|
+
/** A path that already names a Markdown file is complete. */
|
|
29
|
+
const ENDS_IN_MD = /\.md$/i;
|
|
30
|
+
/** Opening or closing fence of a fenced code block (up to three spaces of indent). */
|
|
31
|
+
const FENCE = /^ {0,3}(`{3,}|~{3,})/;
|
|
32
|
+
/** A list item line, whose indented continuation lines are not code. */
|
|
33
|
+
const LIST_ITEM = /^ {0,3}(?:[-*+]|\d{1,9}[.)])(?:\s|$)/;
|
|
34
|
+
/** Four spaces or a tab of indent: an indented code line when it is not a continuation. */
|
|
35
|
+
const INDENTED = /^(?: {4,}|\t)/;
|
|
36
|
+
const HQ_BLOCK_BEGIN = "<!-- hq-anywhere:begin";
|
|
37
|
+
/** Same text as `CLAUDE_MD_END` in src/lib/install/claude-targets.ts. */
|
|
38
|
+
const HQ_BLOCK_END = "<!-- hq-anywhere:end -->";
|
|
39
|
+
/** Split into lines, keeping each line's own terminator (`\n` or `\r\n`). */
|
|
40
|
+
function splitLines(text) {
|
|
41
|
+
const out = [];
|
|
42
|
+
const parts = text.split(/(\r?\n)/);
|
|
43
|
+
for (let i = 0; i < parts.length; i += 2) {
|
|
44
|
+
out.push({ body: parts[i] ?? "", eol: parts[i + 1] ?? "" });
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
const blank = (span) => " ".repeat(span.length);
|
|
49
|
+
/**
|
|
50
|
+
* Each line's text as Claude Code would scan it for imports: code spans and
|
|
51
|
+
* HTML comments blanked to spaces (same length), and lines inside fenced or
|
|
52
|
+
* indented code blocks or a multi-line comment replaced by null.
|
|
53
|
+
*/
|
|
54
|
+
function scannableLines(text) {
|
|
55
|
+
const out = [];
|
|
56
|
+
let fence = null;
|
|
57
|
+
let inComment = false;
|
|
58
|
+
let prevBlank = true;
|
|
59
|
+
let inIndentedCode = false;
|
|
60
|
+
let inList = false;
|
|
61
|
+
for (const { body } of splitLines(text)) {
|
|
62
|
+
if (fence !== null) {
|
|
63
|
+
const marker = FENCE.exec(body);
|
|
64
|
+
if (marker && marker[1][0] === fence.char && marker[1].length >= fence.length && body.trim() === marker[1])
|
|
65
|
+
fence = null;
|
|
66
|
+
out.push(null);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
let line = body;
|
|
70
|
+
if (inComment) {
|
|
71
|
+
const close = line.indexOf("-->");
|
|
72
|
+
if (close === -1) {
|
|
73
|
+
out.push(null);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
line = blank(line.slice(0, close + 3)) + line.slice(close + 3);
|
|
77
|
+
inComment = false;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const marker = FENCE.exec(line);
|
|
81
|
+
if (marker) {
|
|
82
|
+
fence = { char: marker[1][0], length: marker[1].length };
|
|
83
|
+
out.push(null);
|
|
84
|
+
prevBlank = false;
|
|
85
|
+
inIndentedCode = false;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (line.trim() === "") {
|
|
89
|
+
prevBlank = true;
|
|
90
|
+
out.push(line);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const indented = INDENTED.test(line);
|
|
94
|
+
if (indented && !inList && (prevBlank || inIndentedCode)) {
|
|
95
|
+
inIndentedCode = true;
|
|
96
|
+
prevBlank = false;
|
|
97
|
+
out.push(null);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
inIndentedCode = false;
|
|
101
|
+
if (LIST_ITEM.test(line))
|
|
102
|
+
inList = true;
|
|
103
|
+
else if (!indented)
|
|
104
|
+
inList = false;
|
|
105
|
+
prevBlank = false;
|
|
106
|
+
}
|
|
107
|
+
line = line.replace(/(`+)[^`]*?\1/g, blank).replace(/<!--[\s\S]*?-->/g, blank);
|
|
108
|
+
const open = line.indexOf("<!--");
|
|
109
|
+
if (open !== -1) {
|
|
110
|
+
line = line.slice(0, open) + blank(line.slice(open));
|
|
111
|
+
inComment = true;
|
|
112
|
+
}
|
|
113
|
+
out.push(line);
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
function locate(text) {
|
|
118
|
+
const found = [];
|
|
119
|
+
scannableLines(text).forEach((line, index) => {
|
|
120
|
+
if (line === null)
|
|
121
|
+
return;
|
|
122
|
+
for (const match of line.matchAll(IMPORT_TOKEN)) {
|
|
123
|
+
let importPath = match[2];
|
|
124
|
+
if (!BAD_BACKSLASH.test(importPath))
|
|
125
|
+
continue;
|
|
126
|
+
const start = match.index + match[1].length + 1;
|
|
127
|
+
// `@C:\Users\John Smith\hq\x.md`: Claude Code would stop at the first
|
|
128
|
+
// backslash anyway, so take the chunks after an unescaped space while
|
|
129
|
+
// each still holds a path backslash and does not start a new path. A
|
|
130
|
+
// path that already ends in .md is complete, so text after it stays.
|
|
131
|
+
for (;;) {
|
|
132
|
+
if (ENDS_IN_MD.test(importPath))
|
|
133
|
+
break;
|
|
134
|
+
const next = CONTINUATION.exec(line.slice(start + importPath.length));
|
|
135
|
+
if (!next || !BAD_BACKSLASH.test(next[1]) || NEW_PATH.test(next[1]))
|
|
136
|
+
break;
|
|
137
|
+
importPath += next[0];
|
|
138
|
+
}
|
|
139
|
+
found.push({ line: index + 1, path: importPath, start });
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return found;
|
|
143
|
+
}
|
|
144
|
+
/** Every `@import` in `text` whose path holds a backslash that is not an escaped space. */
|
|
145
|
+
export function findBackslashImports(text) {
|
|
146
|
+
return locate(text).map(({ line, path }) => ({ line, path }));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* An import path written as Claude Code reads it: each path backslash becomes
|
|
150
|
+
* `/`, an escaped space (`\ `) stays, and an unescaped space is escaped.
|
|
151
|
+
*/
|
|
152
|
+
export function toForwardSlashes(importPath) {
|
|
153
|
+
return importPath.replace(/\\ |\\| /g, (m) => (m === "\\ " ? m : m === "\\" ? "/" : "\\ "));
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* `text` with each such `@import` path rewritten by {@link toForwardSlashes}.
|
|
157
|
+
* Nothing else changes: other text, code, comments and line endings keep their
|
|
158
|
+
* bytes. Returns `text` itself when there is nothing to change.
|
|
159
|
+
*/
|
|
160
|
+
export function normalizeBackslashImports(text) {
|
|
161
|
+
const hits = locate(text);
|
|
162
|
+
if (hits.length === 0)
|
|
163
|
+
return text;
|
|
164
|
+
const byLine = new Map();
|
|
165
|
+
for (const hit of hits)
|
|
166
|
+
byLine.set(hit.line, [...(byLine.get(hit.line) ?? []), hit]);
|
|
167
|
+
return splitLines(text)
|
|
168
|
+
.map(({ body, eol }, index) => {
|
|
169
|
+
const lineHits = byLine.get(index + 1);
|
|
170
|
+
if (!lineHits)
|
|
171
|
+
return body + eol;
|
|
172
|
+
let next = body;
|
|
173
|
+
// Right to left so earlier offsets stay valid.
|
|
174
|
+
for (const hit of [...lineHits].sort((a, b) => b.start - a.start)) {
|
|
175
|
+
next = next.slice(0, hit.start) + toForwardSlashes(hit.path) + next.slice(hit.start + hit.path.length);
|
|
176
|
+
}
|
|
177
|
+
return next + eol;
|
|
178
|
+
})
|
|
179
|
+
.join("");
|
|
180
|
+
}
|
|
181
|
+
function hqBlockImportIndex(lines) {
|
|
182
|
+
const begin = lines.findIndex(({ body }) => body.startsWith(HQ_BLOCK_BEGIN));
|
|
183
|
+
if (begin === -1)
|
|
184
|
+
return -1;
|
|
185
|
+
for (let i = begin + 1; i < lines.length; i++) {
|
|
186
|
+
const body = lines[i].body;
|
|
187
|
+
if (body.trim() === HQ_BLOCK_END)
|
|
188
|
+
return -1;
|
|
189
|
+
if (body.startsWith("@"))
|
|
190
|
+
return i;
|
|
191
|
+
}
|
|
192
|
+
return -1;
|
|
193
|
+
}
|
|
194
|
+
/** The managed block's import line, or null when the file has no such block. */
|
|
195
|
+
export function findHqBlockImport(text) {
|
|
196
|
+
const lines = splitLines(text);
|
|
197
|
+
const index = hqBlockImportIndex(lines);
|
|
198
|
+
if (index === -1)
|
|
199
|
+
return null;
|
|
200
|
+
const raw = lines[index].body.slice(1).trimEnd();
|
|
201
|
+
const token = /^((?:[^\s\\]|\\ )*)/.exec(raw)[1];
|
|
202
|
+
return {
|
|
203
|
+
line: index + 1,
|
|
204
|
+
raw,
|
|
205
|
+
claudePath: token.replace(/\\ /g, " "),
|
|
206
|
+
intendedPath: raw.replace(/\\ /g, " ").replace(/\\/g, "/"),
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* `text` with the managed block's import line rewritten as the path it means,
|
|
211
|
+
* forward slashes and every space escaped (`\ `), so Claude Code reads the
|
|
212
|
+
* whole path. Only that one line changes; `text` itself when nothing would.
|
|
213
|
+
*/
|
|
214
|
+
export function escapeHqBlockImport(text) {
|
|
215
|
+
const lines = splitLines(text);
|
|
216
|
+
const index = hqBlockImportIndex(lines);
|
|
217
|
+
if (index === -1)
|
|
218
|
+
return text;
|
|
219
|
+
const found = findHqBlockImport(text);
|
|
220
|
+
const next = `@${found.intendedPath.replace(/ /g, "\\ ")}`;
|
|
221
|
+
if (next === lines[index].body)
|
|
222
|
+
return text;
|
|
223
|
+
lines[index] = { body: next, eol: lines[index].eol };
|
|
224
|
+
return lines.map(({ body, eol }) => body + eol).join("");
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=claude-md-imports.js.map
|
|
@@ -29,4 +29,14 @@ export interface FleetSessionStartOptions {
|
|
|
29
29
|
}
|
|
30
30
|
/** Run one `fleet-session-start` note. */
|
|
31
31
|
export declare function runFleetSessionStart(request: HookRequest, operation: FleetSessionStartOperation, options: FleetSessionStartOptions): Promise<HookRequestResult>;
|
|
32
|
+
export type FleetLocalPromptOperation = {
|
|
33
|
+
kind: "fleet-local-prompt";
|
|
34
|
+
deliver: boolean;
|
|
35
|
+
skip: string[];
|
|
36
|
+
budget: string | null;
|
|
37
|
+
helperLight: boolean;
|
|
38
|
+
};
|
|
39
|
+
export declare const FLEET_LOCAL_DEFERRED_DIR = ".hq-fleet-local-deferred";
|
|
40
|
+
export declare function parseFleetLocalPrompt(kind: unknown, args: Record<string, unknown>, session: string): FleetLocalPromptOperation | undefined;
|
|
41
|
+
export declare function runFleetLocalPrompt(request: HookRequest, operation: FleetLocalPromptOperation, options: FleetSessionStartOptions): Promise<HookRequestResult>;
|
|
32
42
|
//# sourceMappingURL=hook-requests-fleet-session-start.d.ts.map
|
|
@@ -42,7 +42,7 @@ import * as fs from "node:fs";
|
|
|
42
42
|
import * as os from "node:os";
|
|
43
43
|
import * as path from "node:path";
|
|
44
44
|
// A cycle with hook-requests.ts, which dispatches to this module: each side uses the other only inside functions.
|
|
45
|
-
import { spawnRequestProgram } from "./hook-requests.js";
|
|
45
|
+
import { fleetLocalSettingsUnderRoot, spawnRequestProgram } from "./hook-requests.js";
|
|
46
46
|
/** The folder under the fleet home that holds the session-start caches. */
|
|
47
47
|
export const FLEET_SESSION_START_CACHE_DIR = "cache/hook-session-start";
|
|
48
48
|
/** The in-flight marker in `<root>/workspace/sessions/<session>/`. */
|
|
@@ -141,6 +141,51 @@ function writeAtomically(target, text) {
|
|
|
141
141
|
return false;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
+
async function runPinnedEngine(request, event, switches, options) {
|
|
145
|
+
const base = { ...(options.env ?? process.env) };
|
|
146
|
+
const home = options.home ?? base.HOME ?? os.homedir();
|
|
147
|
+
const engine = pinnedHookEngine(home);
|
|
148
|
+
if (!engine || !request.body)
|
|
149
|
+
return undefined;
|
|
150
|
+
// Only the note decides the adapter's switches: none of the daemon's own reach the engine.
|
|
151
|
+
for (const name of Object.keys(base))
|
|
152
|
+
if (name.startsWith("HQ_FLEET_LOCAL_") || name === "HQ_FLEET_HOME")
|
|
153
|
+
delete base[name];
|
|
154
|
+
const env = {
|
|
155
|
+
...base, HQ_HOOK_REQUEST_ID: request.id,
|
|
156
|
+
...(switches.fleetHome !== null ? { HQ_FLEET_HOME: switches.fleetHome } : {}),
|
|
157
|
+
...(switches.skip.length ? { HQ_FLEET_LOCAL_HOOK_SKIP: switches.skip.join(" ") } : {}),
|
|
158
|
+
...(switches.budget !== null ? { HQ_FLEET_LOCAL_HOOK_BUDGET_SECONDS: switches.budget } : {}),
|
|
159
|
+
HQ_FLEET_LOCAL_HELPER_LIGHT: switches.helperLight ? "1" : "0",
|
|
160
|
+
};
|
|
161
|
+
const body = request.body;
|
|
162
|
+
return new Promise(resolve => {
|
|
163
|
+
if (options.signal?.aborted) {
|
|
164
|
+
resolve({ code: 1, ended: true, stdout: "" });
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const { child, settle } = spawnRequestProgram(engine, ["fleet-settings", event, "--hq-root", request.root], {
|
|
168
|
+
cwd: request.root, env, windowsHide: true, stdio: ["pipe", "pipe", "ignore"],
|
|
169
|
+
}, { timeoutMs: options.timeoutMs ?? FLEET_SESSION_START_KILL_MS, killGraceMs: options.killGraceMs, signal: options.signal });
|
|
170
|
+
child.stdin?.on("error", () => undefined);
|
|
171
|
+
child.stdin?.end(body);
|
|
172
|
+
let out = "";
|
|
173
|
+
child.stdout?.setEncoding("utf8");
|
|
174
|
+
child.stdout?.on("data", (text) => { if (out.length < STDOUT_MAX_BYTES)
|
|
175
|
+
out += text; });
|
|
176
|
+
child.stdout?.on("error", () => undefined);
|
|
177
|
+
let settled = false;
|
|
178
|
+
const done = (code) => {
|
|
179
|
+
if (settled)
|
|
180
|
+
return;
|
|
181
|
+
settled = true;
|
|
182
|
+
const ended = settle();
|
|
183
|
+
resolve({ code: ended && code === 0 ? 1 : code, ended, stdout: out });
|
|
184
|
+
};
|
|
185
|
+
child.once("error", () => done(1));
|
|
186
|
+
child.once("close", code => done(code ?? 1));
|
|
187
|
+
});
|
|
188
|
+
}
|
|
144
189
|
/** Run one `fleet-session-start` note. */
|
|
145
190
|
export async function runFleetSessionStart(request, operation, options) {
|
|
146
191
|
const cache = operation.fleetHome !== null && operation.cache !== null
|
|
@@ -156,48 +201,9 @@ export async function runFleetSessionStart(request, operation, options) {
|
|
|
156
201
|
catch { /* gone, or not an empty folder */ }
|
|
157
202
|
};
|
|
158
203
|
try {
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
const engine = pinnedHookEngine(home);
|
|
162
|
-
if (!engine || !request.body)
|
|
204
|
+
const ran = await runPinnedEngine(request, "SessionStart", operation, options);
|
|
205
|
+
if (!ran)
|
|
163
206
|
return { code: 1 };
|
|
164
|
-
// Only the note decides the adapter's switches: none of the daemon's own reach the engine.
|
|
165
|
-
for (const name of Object.keys(base))
|
|
166
|
-
if (name.startsWith("HQ_FLEET_LOCAL_") || name === "HQ_FLEET_HOME")
|
|
167
|
-
delete base[name];
|
|
168
|
-
const env = {
|
|
169
|
-
...base, HQ_HOOK_REQUEST_ID: request.id,
|
|
170
|
-
...(operation.fleetHome !== null ? { HQ_FLEET_HOME: operation.fleetHome } : {}),
|
|
171
|
-
...(operation.skip.length ? { HQ_FLEET_LOCAL_HOOK_SKIP: operation.skip.join(" ") } : {}),
|
|
172
|
-
...(operation.budget !== null ? { HQ_FLEET_LOCAL_HOOK_BUDGET_SECONDS: operation.budget } : {}),
|
|
173
|
-
HQ_FLEET_LOCAL_HELPER_LIGHT: operation.helperLight ? "1" : "0",
|
|
174
|
-
};
|
|
175
|
-
const ran = await new Promise(resolve => {
|
|
176
|
-
if (options.signal?.aborted) {
|
|
177
|
-
resolve({ code: 1, ended: true, stdout: "" });
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
const { child, settle } = spawnRequestProgram(engine, ["fleet-settings", "SessionStart", "--hq-root", request.root], {
|
|
181
|
-
cwd: request.root, env, windowsHide: true, stdio: ["pipe", "pipe", "ignore"],
|
|
182
|
-
}, { timeoutMs: options.timeoutMs ?? FLEET_SESSION_START_KILL_MS, killGraceMs: options.killGraceMs, signal: options.signal });
|
|
183
|
-
child.stdin?.on("error", () => undefined);
|
|
184
|
-
child.stdin?.end(request.body);
|
|
185
|
-
let out = "";
|
|
186
|
-
child.stdout?.setEncoding("utf8");
|
|
187
|
-
child.stdout?.on("data", (text) => { if (out.length < STDOUT_MAX_BYTES)
|
|
188
|
-
out += text; });
|
|
189
|
-
child.stdout?.on("error", () => undefined);
|
|
190
|
-
let settled = false;
|
|
191
|
-
const done = (code) => {
|
|
192
|
-
if (settled)
|
|
193
|
-
return;
|
|
194
|
-
settled = true;
|
|
195
|
-
const ended = settle();
|
|
196
|
-
resolve({ code: ended && code === 0 ? 1 : code, ended, stdout: out });
|
|
197
|
-
};
|
|
198
|
-
child.once("error", () => done(1));
|
|
199
|
-
child.once("close", code => done(code ?? 1));
|
|
200
|
-
});
|
|
201
207
|
// An engine ended at its limit (or a daemon stop) writes nothing, as a killed subshell's trap never ran.
|
|
202
208
|
if (ran.ended)
|
|
203
209
|
return { code: 1 };
|
|
@@ -211,4 +217,42 @@ export async function runFleetSessionStart(request, operation, options) {
|
|
|
211
217
|
finish();
|
|
212
218
|
}
|
|
213
219
|
}
|
|
220
|
+
export const FLEET_LOCAL_DEFERRED_DIR = ".hq-fleet-local-deferred";
|
|
221
|
+
export function parseFleetLocalPrompt(kind, args, session) {
|
|
222
|
+
if (kind !== "fleet-local-prompt")
|
|
223
|
+
return undefined;
|
|
224
|
+
const keys = Object.keys(args).sort();
|
|
225
|
+
if (keys.join(",") !== "budget,deliver,helperLight,skip")
|
|
226
|
+
return undefined;
|
|
227
|
+
const { deliver, skip, budget, helperLight } = args;
|
|
228
|
+
if (typeof deliver !== "boolean" || (deliver && !plainName(session)))
|
|
229
|
+
return undefined;
|
|
230
|
+
if (!Array.isArray(skip) || skip.length > SKIP_MAX || !skip.every(word => typeof word === "string" && SKIP_WORD.test(word)))
|
|
231
|
+
return undefined;
|
|
232
|
+
if (budget !== null && (typeof budget !== "string" || !BUDGET.test(budget)))
|
|
233
|
+
return undefined;
|
|
234
|
+
if (typeof helperLight !== "boolean")
|
|
235
|
+
return undefined;
|
|
236
|
+
return { kind, deliver, skip: skip, budget, helperLight };
|
|
237
|
+
}
|
|
238
|
+
export async function runFleetLocalPrompt(request, operation, options) {
|
|
239
|
+
const ran = await runPinnedEngine(request, "UserPromptSubmit", { fleetHome: null, ...operation }, options);
|
|
240
|
+
if (!ran)
|
|
241
|
+
return { code: 1 };
|
|
242
|
+
const context = printedContext(ran.stdout);
|
|
243
|
+
if (ran.ended || ran.code !== 0 || !context || !operation.deliver || !plainName(request.session))
|
|
244
|
+
return { code: 0 };
|
|
245
|
+
let folder = request.root;
|
|
246
|
+
for (const part of ["workspace", "sessions", request.session, FLEET_LOCAL_DEFERRED_DIR]) {
|
|
247
|
+
folder = path.join(folder, part);
|
|
248
|
+
try {
|
|
249
|
+
fs.mkdirSync(folder, { mode: 0o700 });
|
|
250
|
+
}
|
|
251
|
+
catch { /* already there, or checked below */ }
|
|
252
|
+
if (!fleetLocalSettingsUnderRoot(request.root, folder) || fs.lstatSync(folder, { throwIfNoEntry: false })?.isDirectory() !== true)
|
|
253
|
+
return { code: 0 };
|
|
254
|
+
}
|
|
255
|
+
writeAtomically(path.join(folder, `${Date.now()}.${process.pid}.${request.id}.txt`), context);
|
|
256
|
+
return { code: 0 };
|
|
257
|
+
}
|
|
214
258
|
//# sourceMappingURL=hook-requests-fleet-session-start.js.map
|
|
@@ -53,7 +53,7 @@ import { type ShareCandidate } from "./hook-requests-acl-suggest.js";
|
|
|
53
53
|
import { type MeshOperation } from "./hook-requests-mesh.js";
|
|
54
54
|
import { type MachineCheckResult, type RunMachineChecksOptions } from "./machine-checks.js";
|
|
55
55
|
import { type MeshToolWritesOperation } from "./hook-requests-mesh-tool-writes.js";
|
|
56
|
-
import { type FleetSessionStartOperation } from "./hook-requests-fleet-session-start.js";
|
|
56
|
+
import { type FleetLocalPromptOperation, type FleetSessionStartOperation } from "./hook-requests-fleet-session-start.js";
|
|
57
57
|
import { type ConductLinkOperation } from "./hook-requests-conduct-link.js";
|
|
58
58
|
import { type CodexSettingsOperation } from "./hook-requests-codex-settings.js";
|
|
59
59
|
/** What the daemon is asked to do. A closed list, the same as `Kind` in daemon_req.rs. */
|
|
@@ -108,7 +108,7 @@ export type HookOperation = {
|
|
|
108
108
|
disabled?: MeshSessionBindSwitch;
|
|
109
109
|
}
|
|
110
110
|
/** One machine check run by the daemon for a SessionStart where the hooks own the checks (the machine-check notes at the end of this file). */
|
|
111
|
-
| MachineCheckOperation | MeshOperation | MeshToolWritesOperation | CodexSettingsOperation | FleetSessionStartOperation
|
|
111
|
+
| MachineCheckOperation | MeshOperation | MeshToolWritesOperation | CodexSettingsOperation | FleetSessionStartOperation | FleetLocalPromptOperation
|
|
112
112
|
/** The Codex adapter's SubagentStop runs of the root's conduct-link hooks (hook-requests-conduct-link.ts). */
|
|
113
113
|
| ConductLinkOperation;
|
|
114
114
|
/**
|
|
@@ -62,7 +62,7 @@ import { executeAclSuggestion, parseShareCandidates } from "./hook-requests-acl-
|
|
|
62
62
|
import { parseMeshOperation, runMeshReconcile, runMeshRegisterRetry } from "./hook-requests-mesh.js";
|
|
63
63
|
import { MACHINE_CHECKS, machineCheckCollectOnlySupported, runMachineChecks } from "./machine-checks.js";
|
|
64
64
|
import { parseMeshToolWrites, runMeshToolWrites } from "./hook-requests-mesh-tool-writes.js";
|
|
65
|
-
import { parseFleetSessionStart, runFleetSessionStart } from "./hook-requests-fleet-session-start.js";
|
|
65
|
+
import { parseFleetLocalPrompt, parseFleetSessionStart, runFleetLocalPrompt, runFleetSessionStart } from "./hook-requests-fleet-session-start.js";
|
|
66
66
|
import { isConductLinkKind, parseConductLink, runConductLink } from "./hook-requests-conduct-link.js";
|
|
67
67
|
import { parseCodexSettings, runCodexSettings } from "./hook-requests-codex-settings.js";
|
|
68
68
|
/** The longest note the Rust writer leaves (`NOTE_MAX_BYTES`). */
|
|
@@ -306,6 +306,12 @@ export function parseHookRequest(text, stem) {
|
|
|
306
306
|
return undefined;
|
|
307
307
|
operation = fleet;
|
|
308
308
|
}
|
|
309
|
+
else if (value.kind === "fleet-local-prompt") {
|
|
310
|
+
const prompt = parseFleetLocalPrompt(value.kind, args, value.session);
|
|
311
|
+
if (!prompt)
|
|
312
|
+
return undefined;
|
|
313
|
+
operation = prompt;
|
|
314
|
+
}
|
|
309
315
|
else if (isConductLinkKind(value.kind)) {
|
|
310
316
|
const conduct = parseConductLink(value.kind, args, value.session);
|
|
311
317
|
if (!conduct)
|
|
@@ -389,7 +395,8 @@ export function hookRequestHasBody(operation) {
|
|
|
389
395
|
|| operation.kind === "startwork-prefetch"
|
|
390
396
|
|| operation.kind === "fleet-local-settings"
|
|
391
397
|
|| operation.kind === "codex-settings"
|
|
392
|
-
|| operation.kind === "fleet-session-start"
|
|
398
|
+
|| operation.kind === "fleet-session-start"
|
|
399
|
+
|| operation.kind === "fleet-local-prompt";
|
|
393
400
|
}
|
|
394
401
|
/** The helper a plan-sync request runs, inside the HQ root. */
|
|
395
402
|
export const PLAN_SYNC_HELPER = "core/scripts/session-project.sh";
|
|
@@ -424,7 +431,8 @@ export function hookRequestArguments(request) {
|
|
|
424
431
|
// Run by hook-requests-fleet-session-start.ts with the pinned engine.
|
|
425
432
|
// Not a CLI request: the Codex settings commands are started one by one (hook-requests-codex-settings.ts).
|
|
426
433
|
case "codex-settings": return [];
|
|
427
|
-
case "fleet-session-start":
|
|
434
|
+
case "fleet-session-start":
|
|
435
|
+
case "fleet-local-prompt": return [];
|
|
428
436
|
// Not a CLI request: the root's own conduct-link hook script is run (`runConductLink`).
|
|
429
437
|
case "conduct-lanes-link-deliver":
|
|
430
438
|
case "conduct-link-inherit": return [];
|
|
@@ -1625,6 +1633,8 @@ export function executeHookRequest(request, options) {
|
|
|
1625
1633
|
return runMeshToolWrites(operation, { ...options, root: request.root });
|
|
1626
1634
|
if (operation.kind === "fleet-session-start")
|
|
1627
1635
|
return runFleetSessionStart(request, operation, options);
|
|
1636
|
+
if (operation.kind === "fleet-local-prompt")
|
|
1637
|
+
return runFleetLocalPrompt(request, operation, options);
|
|
1628
1638
|
if (operation.kind === "codex-settings")
|
|
1629
1639
|
return runCodexSettings(request, operation, { ...options, timeoutMs: options.timeoutMs ?? HOOK_REQUEST_KILL_MS, killGraceMs: options.killGraceMs ?? HOOK_REQUEST_KILL_GRACE_MS }).catch(() => ({ code: 1 }));
|
|
1630
1640
|
const cliArgs = hookRequestArguments(request);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hq doctor` claude-imports family: CLAUDE.md `@import` paths written with
|
|
3
|
+
* backslashes (feedback_362cdca7).
|
|
4
|
+
*
|
|
5
|
+
* Claude Code skips an `@import` whose path contains a backslash and says
|
|
6
|
+
* nothing, so on Windows `@C:\Users\me\hq\.claude\CLAUDE.md` leaves every
|
|
7
|
+
* session without the HQ charter. This family reads the CLAUDE.md files HQ
|
|
8
|
+
* relies on (the user-scope file `hq install --global` writes, and the HQ
|
|
9
|
+
* tree's own) and reports each one that has such an import. `hq doctor --fix`
|
|
10
|
+
* rewrites those import paths with forward slashes (fix class
|
|
11
|
+
* `normalize-import-slashes`). The check itself only reads.
|
|
12
|
+
*/
|
|
13
|
+
import type { CheckContext, CheckFamily, CheckResult } from "../types.js";
|
|
14
|
+
export declare const CLAUDE_IMPORTS_FAMILY_ID = "claude-imports";
|
|
15
|
+
export declare const CLAUDE_IMPORTS_CHECK_ID = "claude-imports.backslash-path";
|
|
16
|
+
/** The `hq install --global` block's import names a path that is not on disk. */
|
|
17
|
+
export declare const CLAUDE_IMPORTS_UNRESOLVED_CHECK_ID = "claude-imports.unresolved-hq-import";
|
|
18
|
+
/** File names `--fix` may rewrite for this check. */
|
|
19
|
+
export declare const CLAUDE_IMPORT_FILE_NAMES: readonly ["CLAUDE.md", "CLAUDE.local.md", "personal-context.md"];
|
|
20
|
+
export interface ClaudeImportsDeps {
|
|
21
|
+
/** The user's home directory. Default: `os.homedir()`. */
|
|
22
|
+
home?: string;
|
|
23
|
+
}
|
|
24
|
+
/** The CLAUDE.md files this family reads, in report order. */
|
|
25
|
+
export declare function claudeImportFiles(hqRoot: string, home: string): string[];
|
|
26
|
+
export declare function createClaudeImportsFamily(deps?: ClaudeImportsDeps): CheckFamily;
|
|
27
|
+
export declare const claudeImportsFamily: CheckFamily;
|
|
28
|
+
export declare function checkClaudeImports(context: CheckContext, deps?: ClaudeImportsDeps): CheckResult[];
|
|
29
|
+
//# sourceMappingURL=claude-imports.d.ts.map
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hq doctor` claude-imports family: CLAUDE.md `@import` paths written with
|
|
3
|
+
* backslashes (feedback_362cdca7).
|
|
4
|
+
*
|
|
5
|
+
* Claude Code skips an `@import` whose path contains a backslash and says
|
|
6
|
+
* nothing, so on Windows `@C:\Users\me\hq\.claude\CLAUDE.md` leaves every
|
|
7
|
+
* session without the HQ charter. This family reads the CLAUDE.md files HQ
|
|
8
|
+
* relies on (the user-scope file `hq install --global` writes, and the HQ
|
|
9
|
+
* tree's own) and reports each one that has such an import. `hq doctor --fix`
|
|
10
|
+
* rewrites those import paths with forward slashes (fix class
|
|
11
|
+
* `normalize-import-slashes`). The check itself only reads.
|
|
12
|
+
*/
|
|
13
|
+
import * as fs from "node:fs";
|
|
14
|
+
import * as os from "node:os";
|
|
15
|
+
import * as path from "node:path";
|
|
16
|
+
import { findBackslashImports, findHqBlockImport } from "../../claude-md-imports.js";
|
|
17
|
+
export const CLAUDE_IMPORTS_FAMILY_ID = "claude-imports";
|
|
18
|
+
export const CLAUDE_IMPORTS_CHECK_ID = "claude-imports.backslash-path";
|
|
19
|
+
/** The `hq install --global` block's import names a path that is not on disk. */
|
|
20
|
+
export const CLAUDE_IMPORTS_UNRESOLVED_CHECK_ID = "claude-imports.unresolved-hq-import";
|
|
21
|
+
/** File names `--fix` may rewrite for this check. */
|
|
22
|
+
export const CLAUDE_IMPORT_FILE_NAMES = ["CLAUDE.md", "CLAUDE.local.md", "personal-context.md"];
|
|
23
|
+
/** The CLAUDE.md files this family reads, in report order. */
|
|
24
|
+
export function claudeImportFiles(hqRoot, home) {
|
|
25
|
+
const files = [path.join(home, ".claude", "CLAUDE.md")];
|
|
26
|
+
if (hqRoot) {
|
|
27
|
+
files.push(path.join(hqRoot, "CLAUDE.md"), path.join(hqRoot, "CLAUDE.local.md"), path.join(hqRoot, ".claude", "CLAUDE.md"), path.join(hqRoot, ".claude", "personal-context.md"), path.join(hqRoot, "personal", "CLAUDE.md"));
|
|
28
|
+
}
|
|
29
|
+
return [...new Set(files)];
|
|
30
|
+
}
|
|
31
|
+
export function createClaudeImportsFamily(deps = {}) {
|
|
32
|
+
return {
|
|
33
|
+
id: CLAUDE_IMPORTS_FAMILY_ID,
|
|
34
|
+
title: "CLAUDE.md imports",
|
|
35
|
+
run: (context) => Promise.resolve(checkClaudeImports(context, deps)),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export const claudeImportsFamily = createClaudeImportsFamily();
|
|
39
|
+
export function checkClaudeImports(context, deps = {}) {
|
|
40
|
+
const home = deps.home ?? os.homedir();
|
|
41
|
+
const results = [];
|
|
42
|
+
const userClaudeMd = path.join(home, ".claude", "CLAUDE.md");
|
|
43
|
+
let read = 0;
|
|
44
|
+
for (const file of claudeImportFiles(context.hqRoot, home)) {
|
|
45
|
+
let text;
|
|
46
|
+
try {
|
|
47
|
+
text = fs.readFileSync(file, "utf8");
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
continue; // Absent or unreadable: nothing Claude Code would import from it either.
|
|
51
|
+
}
|
|
52
|
+
read += 1;
|
|
53
|
+
const hits = findBackslashImports(text);
|
|
54
|
+
if (file === userClaudeMd) {
|
|
55
|
+
const unresolved = checkHqBlockImport(file, text, home, hits);
|
|
56
|
+
if (unresolved)
|
|
57
|
+
results.push(unresolved);
|
|
58
|
+
}
|
|
59
|
+
if (hits.length === 0)
|
|
60
|
+
continue;
|
|
61
|
+
const first = hits[0];
|
|
62
|
+
const more = hits.length > 1 ? ` and ${hits.length - 1} more` : "";
|
|
63
|
+
results.push({
|
|
64
|
+
status: "WARN",
|
|
65
|
+
checkId: CLAUDE_IMPORTS_CHECK_ID,
|
|
66
|
+
target: file,
|
|
67
|
+
message: `${file} line ${first.line}: @${first.path}${more}. Claude Code does not load an @import ` +
|
|
68
|
+
`written with backslashes, so this context never reaches the session.`,
|
|
69
|
+
details: { lines: hits.map((hit) => hit.line) },
|
|
70
|
+
remediation: "hq doctor --fix (rewrites those @import paths with forward slashes)",
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (results.length > 0)
|
|
74
|
+
return results;
|
|
75
|
+
if (read === 0) {
|
|
76
|
+
return [{ status: "NA", checkId: CLAUDE_IMPORTS_CHECK_ID, message: "No CLAUDE.md files to check." }];
|
|
77
|
+
}
|
|
78
|
+
return [
|
|
79
|
+
{
|
|
80
|
+
status: "PASS",
|
|
81
|
+
checkId: CLAUDE_IMPORTS_CHECK_ID,
|
|
82
|
+
message: `${read} CLAUDE.md file${read === 1 ? "" : "s"} checked; every @import path uses forward slashes.`,
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
/** Whether `p` is an existing file (following links); false on any error. */
|
|
87
|
+
function isFile(p) {
|
|
88
|
+
try {
|
|
89
|
+
return fs.statSync(p).isFile();
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Resolve an import path the way Claude Code does: `~/` from home, relative from the file's folder. */
|
|
96
|
+
function resolveImport(importPath, file, home) {
|
|
97
|
+
if (importPath.startsWith("~/"))
|
|
98
|
+
return path.join(home, importPath.slice(2));
|
|
99
|
+
if (path.isAbsolute(importPath))
|
|
100
|
+
return importPath;
|
|
101
|
+
return path.resolve(path.dirname(file), importPath);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The managed `hq install --global` block's import, read as Claude Code reads
|
|
105
|
+
* it. WARN when that path is not on disk, for example
|
|
106
|
+
* `@C:/Users/John Smith/hq/.claude/CLAUDE.md`, which Claude Code reads as
|
|
107
|
+
* `C:/Users/John`. Skipped when the line already has a backslash finding:
|
|
108
|
+
* that repair runs first and this check looks again afterwards.
|
|
109
|
+
*/
|
|
110
|
+
function checkHqBlockImport(file, text, home, hits) {
|
|
111
|
+
const found = findHqBlockImport(text);
|
|
112
|
+
if (!found || hits.some((hit) => hit.line === found.line))
|
|
113
|
+
return null;
|
|
114
|
+
// A file, not just any path: a cut-short `C:/Users/John` is often a real folder.
|
|
115
|
+
if (found.claudePath && isFile(resolveImport(found.claudePath, file, home)))
|
|
116
|
+
return null;
|
|
117
|
+
const repairable = found.intendedPath !== "" && isFile(resolveImport(found.intendedPath, file, home));
|
|
118
|
+
return {
|
|
119
|
+
status: "WARN",
|
|
120
|
+
checkId: CLAUDE_IMPORTS_UNRESOLVED_CHECK_ID,
|
|
121
|
+
target: file,
|
|
122
|
+
message: `${file} line ${found.line}: Claude Code reads the HQ import as @${found.claudePath || "(empty)"}, which does not exist, ` +
|
|
123
|
+
`so the HQ charter never reaches sessions outside HQ.` +
|
|
124
|
+
(repairable ? ` The full path ${found.intendedPath} exists.` : ` ${found.intendedPath || "The import"} does not exist either.`),
|
|
125
|
+
details: { line: found.line, repairable },
|
|
126
|
+
remediation: repairable
|
|
127
|
+
? "hq doctor --fix (rewrites the HQ import with forward slashes and escaped spaces)"
|
|
128
|
+
: "Run `hq install --global --runtime claude` from your HQ root to rewrite the HQ import.",
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=claude-imports.js.map
|
|
@@ -380,6 +380,13 @@ export declare function defaultRewriteBotNodePath(name: string): {
|
|
|
380
380
|
from: string;
|
|
381
381
|
to: string;
|
|
382
382
|
} | null;
|
|
383
|
+
/**
|
|
384
|
+
* Post-fix status of one file-targeted finding: the re-run result for this
|
|
385
|
+
* check id and target, else PASS when the re-run produced results for the
|
|
386
|
+
* family but none for this target (the file no longer has the finding), else
|
|
387
|
+
* null. Another file that still has the finding never decides this one.
|
|
388
|
+
*/
|
|
389
|
+
export declare function claudeImportStatusForTarget(results: CheckResult[], checkId: string, target: string, familyPrefix: string): DoctorStatus | null;
|
|
383
390
|
/** Default `remove-ps1-shims` repair: Windows only, a no-op elsewhere. */
|
|
384
391
|
export declare function defaultRemovePs1Shims(dir: string): RemovePs1ShimsResult;
|
|
385
392
|
/**
|