agent-whisker 0.1.0 → 0.2.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/README.md +12 -3
- package/README.zh-CN.md +12 -3
- package/package.json +3 -2
- package/packages/antigravity-plugin/package.json +1 -1
- package/packages/antigravity-plugin/plugin.json +1 -1
- package/packages/claude-plugin/.claude-plugin/plugin.json +1 -1
- package/packages/claude-plugin/.codex-plugin/plugin.json +1 -1
- package/packages/claude-plugin/README.md +11 -1
- package/packages/claude-plugin/README.zh-CN.md +4 -1
- package/packages/claude-plugin/bin/taskstate +145 -4
- package/packages/claude-plugin/hooks/codex.json +8 -8
- package/packages/claude-plugin/package.json +1 -1
- package/packages/cli/README.md +76 -3
- package/packages/cli/README.zh-CN.md +76 -3
- package/packages/cli/package.json +1 -1
- package/packages/cli/src/command.js +20 -3
- package/packages/cli/src/commands/catalog.js +26 -7
- package/packages/cli/src/commands/doctor.js +31 -27
- package/packages/cli/src/commands/exclude.js +156 -0
- package/packages/cli/src/commands/extract.js +4 -2
- package/packages/cli/src/commands/index-command.js +1 -1
- package/packages/cli/src/commands/index.js +4 -0
- package/packages/cli/src/commands/install.js +12 -1
- package/packages/cli/src/commands/nudge.js +39 -37
- package/packages/cli/src/commands/read.js +2 -1
- package/packages/cli/src/commands/search.js +33 -3
- package/packages/cli/src/commands/sessions.js +20 -12
- package/packages/cli/src/commands/status.js +6 -3
- package/packages/cli/src/commands/tui.js +62 -0
- package/packages/cli/src/commands/version.js +4 -4
- package/packages/cli/src/exclusion.js +88 -0
- package/packages/cli/src/install/codex-plugin.js +6 -5
- package/packages/cli/src/install/external.js +48 -37
- package/packages/cli/src/install/handlers.js +4 -3
- package/packages/cli/src/install/mcp.js +3 -3
- package/packages/cli/src/install/steps.js +43 -15
- package/packages/cli/src/install/wrapper.js +28 -5
- package/packages/cli/src/main.js +9 -12
- package/packages/cli/src/node-version.js +25 -0
- package/packages/cli/src/run.js +25 -5
- package/packages/cli/src/tui/app.js +1430 -0
- package/packages/cli/src/tui/data/call.js +83 -0
- package/packages/cli/src/tui/data/poll.js +24 -0
- package/packages/cli/src/tui/glyphs.js +93 -0
- package/packages/cli/src/tui/i18n.js +342 -0
- package/packages/cli/src/tui/model.js +251 -0
- package/packages/cli/src/tui/pages/common.js +71 -0
- package/packages/cli/src/tui/pages/library.js +154 -0
- package/packages/cli/src/tui/pages/sessions.js +96 -0
- package/packages/cli/src/tui/pages/system.js +124 -0
- package/packages/cli/src/tui/pages/tasks.js +297 -0
- package/packages/cli/src/tui/run.js +216 -0
- package/packages/cli/src/tui/term/keys.js +152 -0
- package/packages/cli/src/tui/term/screen.js +88 -0
- package/packages/cli/src/tui/term/term.js +157 -0
- package/packages/cli/src/tui/term/width.js +290 -0
- package/packages/cli/src/tui/ui/widgets.js +247 -0
- package/packages/core/README.md +1 -1
- package/packages/core/README.zh-CN.md +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/src/catalog.js +13 -1
- package/packages/core/src/clairic.js +1 -1
- package/packages/core/src/convert.js +1 -1
- package/packages/core/src/db.js +6 -1
- package/packages/core/src/host.js +104 -0
- package/packages/core/src/index.js +2 -2
- package/packages/core/src/library-read.js +12 -8
- package/packages/core/src/nudge.js +34 -1
- package/packages/core/src/schema.js +17 -0
- package/packages/core/src/sessions-read.js +23 -11
- package/packages/dsh-plugin/package.json +1 -1
- package/packages/herdr-plugin/herdr-plugin.toml +1 -1
- package/packages/herdr-plugin/package.json +1 -1
- package/packages/mcp/README.md +5 -5
- package/packages/mcp/README.zh-CN.md +5 -5
- package/packages/mcp/package.json +1 -1
- package/packages/pi-extension/README.md +1 -1
- package/packages/pi-extension/README.zh-CN.md +1 -1
- package/packages/pi-extension/package.json +1 -1
- package/packages/pi-extension/src/extension.ts +3 -3
- package/packages/service/package.json +1 -1
- package/packages/service/src/index.js +1 -1
- package/packages/service/src/runtime.js +4 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Where a library document's file lies on this device, and whether an exclusion marker (.agent-whisker-exclude) is
|
|
2
|
+
// over it, from the source label catalog lists: a user-scope label is relative to the home directory (absolute outside
|
|
3
|
+
// it), a project's relative to the project's root. Used by `exclude add --hide-ingested` (which documents lie under a
|
|
4
|
+
// directory), `search --json`'s avoided counts and `catalog --removed`'s excluded marks. Reads only directory entries
|
|
5
|
+
// (core's holdsExcludeMarker); never opens a document's file.
|
|
6
|
+
import { realpathSync } from "node:fs";
|
|
7
|
+
import { basename, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
8
|
+
import { holdsExcludeMarker, } from "../../core/src/index.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The absolute path a document's source label stands for: under homeDir for the user scope, under the project's root
|
|
12
|
+
* for the current project's scope, the label itself when absolute; null for another project's document (its root is
|
|
13
|
+
* not known here). Pure.
|
|
14
|
+
*/
|
|
15
|
+
export function documentPath(
|
|
16
|
+
doc ,
|
|
17
|
+
homeDir ,
|
|
18
|
+
project ,
|
|
19
|
+
) {
|
|
20
|
+
const label = doc.source.startsWith("~/") ? doc.source.slice(2) : doc.source;
|
|
21
|
+
if (isAbsolute(label)) return label;
|
|
22
|
+
if (doc.scope === "user") return join(homeDir, label);
|
|
23
|
+
if (project !== null && doc.scope === project.scope) return join(project.root, label);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Whether path lies at or below dir, both compared as real paths (the longest existing part resolved). */
|
|
28
|
+
export function isUnder(path , dir ) {
|
|
29
|
+
const real = (at ) => {
|
|
30
|
+
try {
|
|
31
|
+
return realpathSync.native(at);
|
|
32
|
+
} catch {
|
|
33
|
+
const parent = resolve(at, "..");
|
|
34
|
+
return parent === at ? at : join(real(parent), basename(at));
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const inside = relative(real(dir), real(path));
|
|
38
|
+
return inside === "" || !(inside === ".." || inside.startsWith(`..${sep}`) || isAbsolute(inside));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A check of whether an absolute path lies at or below a directory holding the marker, with each directory looked up
|
|
43
|
+
* once per checker (a marker found on the way up answers for every path below it). A lookup that fails counts as no
|
|
44
|
+
* marker here: the answer only sorts hidden documents for display, and ingest's own check stays strict.
|
|
45
|
+
*/
|
|
46
|
+
export function markerChecker() {
|
|
47
|
+
const known = new Map ();
|
|
48
|
+
const marked = (dir ) => {
|
|
49
|
+
const cached = known.get(dir);
|
|
50
|
+
if (cached !== undefined) return cached;
|
|
51
|
+
const parent = resolve(dir, "..");
|
|
52
|
+
let answer = parent !== dir && marked(parent);
|
|
53
|
+
if (!answer) {
|
|
54
|
+
try {
|
|
55
|
+
answer = holdsExcludeMarker(dir);
|
|
56
|
+
} catch {
|
|
57
|
+
answer = false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
known.set(dir, answer);
|
|
61
|
+
return answer;
|
|
62
|
+
};
|
|
63
|
+
return (path) => marked(resolve(path, ".."));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The folder filter catalog takes for the documents of one scope that lie under the absolute directory dir: the
|
|
68
|
+
* user scope's labels relative to homeDir (absolute outside it), a project's relative to its root, both compared as
|
|
69
|
+
* real paths; null when no label of that scope can lie under dir (dir outside the project). An empty string means
|
|
70
|
+
* every document of the scope (dir is the home directory or the project root); catalog's folder needs a non-empty
|
|
71
|
+
* value, so callers then pass none. Reads only the two paths' real paths.
|
|
72
|
+
*/
|
|
73
|
+
export function folderFor(dir , scope , homeDir ) {
|
|
74
|
+
// Compared as real paths: a working directory reached through a symlink (/tmp on macOS) names the same place.
|
|
75
|
+
const real = (path ) => {
|
|
76
|
+
try {
|
|
77
|
+
return realpathSync.native(path);
|
|
78
|
+
} catch {
|
|
79
|
+
return path;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const base = real(scope === "user" ? homeDir : scope.root);
|
|
83
|
+
dir = real(dir);
|
|
84
|
+
const inside = relative(base, dir);
|
|
85
|
+
if (inside === "") return "";
|
|
86
|
+
if (inside === ".." || inside.startsWith(`..${sep}`) || isAbsolute(inside)) return scope === "user" ? dir : null;
|
|
87
|
+
return inside.split(sep).join("/");
|
|
88
|
+
}
|
|
@@ -12,6 +12,7 @@ import { CLIENT, inEmptyDir, programHome } from "./clients.js";
|
|
|
12
12
|
import {
|
|
13
13
|
ask,
|
|
14
14
|
CHECK_TIMEOUT_MS,
|
|
15
|
+
COLD_CHECK_TIMEOUT_MS,
|
|
15
16
|
exitedText,
|
|
16
17
|
manifestVersion,
|
|
17
18
|
REPO_ROOT,
|
|
@@ -115,13 +116,13 @@ export function lookCodexPlugin(host )
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
/**
|
|
118
|
-
* argv's stdout as JSON, or why not
|
|
119
|
-
*
|
|
120
|
-
* `codex plugin list --json` after a while has been seen to take over a minute, and under a second the time after. The
|
|
121
|
-
* bound is not raised for it: doctor shares it, and how long a refresh takes is up to Codex.
|
|
119
|
+
* argv's stdout as JSON, or why not. The first plugin list can take over a minute while Codex refreshes its
|
|
120
|
+
* catalogue, so install and doctor give that command a longer deadline. A timeout names the command to retry.
|
|
122
121
|
*/
|
|
123
122
|
function codexJson(host , argv ) {
|
|
124
|
-
const answer = inEmptyDir(host, (cwd) =>
|
|
123
|
+
const answer = inEmptyDir(host, (cwd) =>
|
|
124
|
+
ask(host, argv, argv === LIST ? COLD_CHECK_TIMEOUT_MS : CHECK_TIMEOUT_MS, cwd),
|
|
125
|
+
);
|
|
125
126
|
if (answer.kind === "silent" && answer.started) {
|
|
126
127
|
const line = shellLine(argv);
|
|
127
128
|
return {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Queries external commands, versions and repository paths for install and doctor, and describes command failures.
|
|
2
2
|
// External commands run through Host with a deadline; checks are read-only, and the caller explicitly chooses when
|
|
3
3
|
// actions run.
|
|
4
|
-
import { readFileSync, realpathSync } from "node:fs";
|
|
4
|
+
import { accessSync, constants, readFileSync, realpathSync, statSync } from "node:fs";
|
|
5
5
|
import { basename, extname, isAbsolute, join, resolve, win32 } from "node:path";
|
|
6
6
|
import { isDeepStrictEqual } from "node:util";
|
|
7
7
|
import { envValue, findProgram, isPlainObject } from "../../../core/src/index.js";
|
|
@@ -12,11 +12,14 @@ import { envValue, findProgram, isPlainObject } from "../../../core/s
|
|
|
12
12
|
*/
|
|
13
13
|
export const SERVER_NAME = "agent-whisker";
|
|
14
14
|
|
|
15
|
+
export { isWantedNode, WANTED_NODE_TEXT } from "../node-version.js";
|
|
16
|
+
|
|
15
17
|
/** The launcher's file name, in `<home>/.local/bin`, and the command name messages tell a person to run. */
|
|
16
18
|
export const LAUNCHER_NAME = "agent-whisker";
|
|
17
19
|
|
|
18
|
-
/** Deadline for
|
|
20
|
+
/** Deadline for an ordinary external check. */
|
|
19
21
|
export const CHECK_TIMEOUT_MS = 10_000;
|
|
22
|
+
export const COLD_CHECK_TIMEOUT_MS = 120_000;
|
|
20
23
|
|
|
21
24
|
/**
|
|
22
25
|
* Deadline for each external command in an install action: 60 seconds. Not specified elsewhere: actions run only
|
|
@@ -49,32 +52,6 @@ export function tempBase(host ) {
|
|
|
49
52
|
);
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
/**
|
|
53
|
-
* The Node versions agent-whisker supports, the same range as `engines` in the root package.json
|
|
54
|
-
* (`>=24.22.1 <25 || >=26.13.0 <27`): per major line, its first supported release as [major, minor, patch].
|
|
55
|
-
* 24 starts at 24.22.1, the first 24 release with V8's fix for a JSON.parse defect: after an object key holding a
|
|
56
|
-
* backslash, a later escaped key of the same decoded length can come back as that earlier key (nodejs/node#66916; V8
|
|
57
|
-
* commit 93cd21e8254b, backported in 24.22.1). 25 is left out: an odd release, no longer supported upstream.
|
|
58
|
-
*/
|
|
59
|
-
const SUPPORTED_NODE = [
|
|
60
|
-
[24, 22, 1],
|
|
61
|
-
[26, 13, 0],
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
/** Three-part numeric format of a stable Node version; prerelease suffixes and leading zeros do not match. */
|
|
65
|
-
const NODE_VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
66
|
-
|
|
67
|
-
/** The human-readable Node requirement used in messages. */
|
|
68
|
-
export const WANTED_NODE_TEXT = "24.22.1 or later below 25, or 26.13.0 or later below 27";
|
|
69
|
-
|
|
70
|
-
/** Whether a version without a leading v is a stable release in SUPPORTED_NODE; no side effects, does not throw, needs no lock or transaction. */
|
|
71
|
-
export function isWantedNode(version ) {
|
|
72
|
-
const match = NODE_VERSION.exec(version);
|
|
73
|
-
if (match === null) return false;
|
|
74
|
-
const [major, minor, patch] = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
75
|
-
return SUPPORTED_NODE.some(([m, n, p]) => major === m && (minor > n || (minor === n && patch >= p)));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
55
|
// ---------------------------------------------------------------------------
|
|
79
56
|
// Repository paths (last segment: computed from the source file's location, not through Host)
|
|
80
57
|
// ---------------------------------------------------------------------------
|
|
@@ -155,16 +132,15 @@ export function taskHomeShown(host ) {
|
|
|
155
132
|
/**
|
|
156
133
|
* Runs argv through host.run (the first element is the program; no shell) with deadline timeoutMs, in cwd when given
|
|
157
134
|
* (otherwise this process's working directory). Does not throw (host.run itself does not). 127 counts as "failed to
|
|
158
|
-
* start": Host's convention is code 127 when a command is not found.
|
|
159
|
-
*
|
|
160
|
-
* mean anything else.
|
|
135
|
+
* start": Host's convention is code 127 when a command is not found. The login-shell probes turn a missing inner
|
|
136
|
+
* command into exit 1 so it is not mistaken for a missing shell.
|
|
161
137
|
*/
|
|
162
|
-
export function ask(host , argv , timeoutMs , cwd ) {
|
|
138
|
+
export function ask(host , argv , timeoutMs , cwd , shown = argv) {
|
|
163
139
|
const [command, ...args] = argv;
|
|
164
140
|
if (command === undefined) throw new Error("ask needs a command");
|
|
165
141
|
const result = host.run(command, args, cwd === undefined ? { timeoutMs } : { timeoutMs, cwd });
|
|
166
142
|
if (result.code === null) {
|
|
167
|
-
return { kind: "silent", why: `${shellLine(
|
|
143
|
+
return { kind: "silent", why: `${shellLine(shown)} did not finish within ${timeoutMs / 1000} s`, started: true };
|
|
168
144
|
}
|
|
169
145
|
if (result.code === 127) {
|
|
170
146
|
// Only core's Windows rule says why a call never started (stderr of a refused `.cmd` call); it is never retried.
|
|
@@ -174,7 +150,7 @@ export function ask(host , argv , timeoutMs , cwd
|
|
|
174
150
|
?.trim();
|
|
175
151
|
return {
|
|
176
152
|
kind: "silent",
|
|
177
|
-
why: `${shellLine(
|
|
153
|
+
why: `${shellLine(shown)} could not start${reason === undefined ? "" : `: ${reason}`}`,
|
|
178
154
|
started: false,
|
|
179
155
|
};
|
|
180
156
|
}
|
|
@@ -292,6 +268,27 @@ export function shellArgv(host , login ,
|
|
|
292
268
|
return [shell, login ? "-lc" : "-c", script];
|
|
293
269
|
}
|
|
294
270
|
|
|
271
|
+
const LOOKUP_MARKER = "agent-whisker:lookup";
|
|
272
|
+
|
|
273
|
+
function shellProbe(host , argv ) {
|
|
274
|
+
const script = `printf '\\n${LOOKUP_MARKER}\\n'; ${argv.at(-1)} || exit 1`;
|
|
275
|
+
const answer = ask(host, [...argv.slice(0, -1), script], CHECK_TIMEOUT_MS, undefined, argv);
|
|
276
|
+
if (answer.kind === "silent") return answer;
|
|
277
|
+
const marker = `\n${LOOKUP_MARKER}\n`;
|
|
278
|
+
const start = answer.stdout.lastIndexOf(marker);
|
|
279
|
+
if (start < 0) return { kind: "silent", why: unrecognised(argv), started: true };
|
|
280
|
+
return { ...answer, stdout: answer.stdout.slice(start + marker.length) };
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export function executable(path ) {
|
|
284
|
+
try {
|
|
285
|
+
accessSync(path, constants.X_OK);
|
|
286
|
+
return statSync(path).isFile();
|
|
287
|
+
} catch {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
295
292
|
/**
|
|
296
293
|
* The result of looking up a command in the shell: found (the line found, usually an absolute path), missing (not
|
|
297
294
|
* found), unknown (no answer or unrecognised; why is a sentence naming the whole command).
|
|
@@ -328,7 +325,15 @@ export function lookupOnce(host ) {
|
|
|
328
325
|
return (name) => {
|
|
329
326
|
const known = seen.get(name);
|
|
330
327
|
if (known !== undefined) return known;
|
|
331
|
-
|
|
328
|
+
let found = lookupCommand(host, name, true);
|
|
329
|
+
if (found.kind === "missing" && host.platform === "darwin" && name !== LAUNCHER_NAME) {
|
|
330
|
+
const path = (host.env.PATH ?? "")
|
|
331
|
+
.split(":")
|
|
332
|
+
.filter(isAbsolute)
|
|
333
|
+
.map((dir) => join(dir, name))
|
|
334
|
+
.find(executable);
|
|
335
|
+
if (path !== undefined) found = { kind: "found", path };
|
|
336
|
+
}
|
|
332
337
|
seen.set(name, found);
|
|
333
338
|
return found;
|
|
334
339
|
};
|
|
@@ -367,7 +372,7 @@ export function lookupCommand(host , name , login )
|
|
|
367
372
|
return path === null ? { kind: "missing" } : { kind: "found", path };
|
|
368
373
|
}
|
|
369
374
|
const argv = shellArgv(host, login, `command -v ${name}`);
|
|
370
|
-
const answer =
|
|
375
|
+
const answer = shellProbe(host, argv);
|
|
371
376
|
if (answer.kind === "silent") return { kind: "unknown", why: answer.why };
|
|
372
377
|
const lines = nonEmptyLines(answer.stdout);
|
|
373
378
|
if (answer.code === 0 && lines.length === 1) return { kind: "found", path: lines[0] ?? "" };
|
|
@@ -398,7 +403,7 @@ export function loginNode(host ) {
|
|
|
398
403
|
: { kind: "found", node: { path: found.path, version: version.version } };
|
|
399
404
|
}
|
|
400
405
|
const argv = shellArgv(host, true, LOGIN_NODE_SCRIPT);
|
|
401
|
-
const answer =
|
|
406
|
+
const answer = shellProbe(host, argv);
|
|
402
407
|
if (answer.kind === "silent") return { kind: "unknown", why: answer.why };
|
|
403
408
|
const lines = nonEmptyLines(answer.stdout);
|
|
404
409
|
const version = /^v(\d+\.\d+\.\d+\S*)$/.exec(lines[1] ?? "");
|
|
@@ -609,6 +614,12 @@ export function samePath(a , b ) {
|
|
|
609
614
|
}
|
|
610
615
|
}
|
|
611
616
|
|
|
617
|
+
export function isLauncherPath(path , wrapper , windows ) {
|
|
618
|
+
return windows
|
|
619
|
+
? win32.normalize(path).toLowerCase() === win32.join(win32.dirname(wrapper), `${LAUNCHER_NAME}.cmd`).toLowerCase()
|
|
620
|
+
: samePath(path, wrapper);
|
|
621
|
+
}
|
|
622
|
+
|
|
612
623
|
/**
|
|
613
624
|
* Whether version begins with dotted numbers that compare lower than oldest's, part by part, a missing part counting
|
|
614
625
|
* as 0 (`2.9.2.1` < `2.15`, `20.11.1` < `22`). false for a version that does not begin with a number, so that
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The hook handlers of the three programs that run hooks, as one table: the single source of the Windows lines. A row
|
|
2
2
|
// names the program (its session-source id), the event (and matcher), the program it calls, and the call's words after
|
|
3
3
|
// it. The POSIX lines in
|
|
4
|
-
// the plugin's hook files stay as they are; the Windows line of a row is
|
|
4
|
+
// the plugin's hook files stay as they are; the Windows line of a row is a quiet, best-effort call by name, which Codex reads
|
|
5
5
|
// as `commandWindows` and which Antigravity gets in a hooks.json generated for cmd.exe at install. A test checks
|
|
6
6
|
// every line of every hook file against these rows, so a copy that drifts fails it.
|
|
7
7
|
|
|
@@ -56,9 +56,10 @@ export const HANDLERS = [
|
|
|
56
56
|
row("antigravity", "Stop", "agent-whisker", NUDGE),
|
|
57
57
|
];
|
|
58
58
|
|
|
59
|
-
/** A row's Windows line:
|
|
59
|
+
/** A row's Windows line: a best-effort call that preserves hook output (PATHEXT finds the `.cmd`). */
|
|
60
60
|
export function windowsLine(handler ) {
|
|
61
|
-
|
|
61
|
+
const redirect = handler.args[0] === "nudge" ? ">nul 2>&1" : "2>nul";
|
|
62
|
+
return `cmd.exe /d /c "call ${[handler.call, ...handler.args].join(" ")} ${redirect} & exit /b 0"`;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
/**
|
|
@@ -6,7 +6,7 @@ import { isPlainObject } from "../../../core/src/index.js";
|
|
|
6
6
|
import { runsLauncher } from "./clients.js";
|
|
7
7
|
import {
|
|
8
8
|
ask,
|
|
9
|
-
|
|
9
|
+
COLD_CHECK_TIMEOUT_MS,
|
|
10
10
|
exitedText,
|
|
11
11
|
LAUNCHER_NAME,
|
|
12
12
|
|
|
@@ -72,7 +72,7 @@ export function listsClient(entry , names )
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
|
-
* Runs `magpie library mcp show <SERVER_NAME>` with a
|
|
75
|
+
* Runs `magpie library mcp show <SERVER_NAME>` with a COLD_CHECK_TIMEOUT_MS deadline. Read-only.
|
|
76
76
|
* - Exit code 0: stdout must be a JSON object whose name is agent-whisker, command a string, args absent or a string
|
|
77
77
|
* array, agents absent, null or a string array, local absent or a boolean, hub absent or a string; otherwise
|
|
78
78
|
* unrecognised.
|
|
@@ -82,7 +82,7 @@ export function listsClient(entry , names )
|
|
|
82
82
|
* Only these fields are taken; other entry fields are neither read nor reported (env and headers may hold secrets).
|
|
83
83
|
*/
|
|
84
84
|
function showEntry(host ) {
|
|
85
|
-
const answer = ask(host, SHOW_ARGV,
|
|
85
|
+
const answer = ask(host, SHOW_ARGV, COLD_CHECK_TIMEOUT_MS);
|
|
86
86
|
if (answer.kind === "silent") return { kind: "unknown", why: answer.why };
|
|
87
87
|
if (answer.code !== 0) {
|
|
88
88
|
if (answer.code === 1 && answer.stderr.includes(`no server called ${SERVER_NAME}`)) return { kind: "absent" };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// changes happen only through explicitly named actions. Nothing is required: a step for a program that is not
|
|
4
4
|
// installed has nothing to do.
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
|
-
import { dirname } from "node:path";
|
|
6
|
+
import { basename, dirname } from "node:path";
|
|
7
7
|
import { AGENTS_ENV, HARNESS_NAMES, RERANK_ENV, resolveHome } from "../../../core/src/index.js";
|
|
8
8
|
import { foreignPlist, installService, launchAgentState, restartService } from "../../../service/src/index.js";
|
|
9
9
|
import { errorText } from "../command.js";
|
|
@@ -78,6 +78,8 @@ import {
|
|
|
78
78
|
HERDR_TUI,
|
|
79
79
|
HERDR_TUI_NAME,
|
|
80
80
|
herdrPluginIds,
|
|
81
|
+
isLauncherPath,
|
|
82
|
+
isWantedNode,
|
|
81
83
|
LAUNCHER_NAME,
|
|
82
84
|
LOGIN_NODE_SCRIPT,
|
|
83
85
|
|
|
@@ -90,9 +92,11 @@ import {
|
|
|
90
92
|
runCommands,
|
|
91
93
|
SERVER_NAME,
|
|
92
94
|
StepFailure,
|
|
95
|
+
samePath,
|
|
93
96
|
shellArgv,
|
|
94
97
|
shellLine,
|
|
95
98
|
unrecognised,
|
|
99
|
+
WANTED_NODE_TEXT,
|
|
96
100
|
} from "./external.js";
|
|
97
101
|
import { APP_HOME_ENV, appHomeText, inspectMod, installMod, MOD_FILES } from "./herdr-mod.js";
|
|
98
102
|
import {
|
|
@@ -337,32 +341,42 @@ export function notOnWindows(host , id )
|
|
|
337
341
|
|
|
338
342
|
const STEPS = [
|
|
339
343
|
{
|
|
340
|
-
//
|
|
341
|
-
// run on it, and nothing this installer sets up needs it in agent-whisker's range (the launcher names the Node that
|
|
342
|
-
// ran install, and the pi extension starts the launcher). With both pi and Claude Code off, nothing needs it: it
|
|
343
|
-
// passes, asking nothing. No action: installing or switching the default Node affects the whole machine, so it is
|
|
344
|
-
// left to a person. A failure does not block other steps.
|
|
344
|
+
// Compare the host's Node with the shell's when pi or Claude Code uses it. Never switch Node for the user.
|
|
345
345
|
id: "node",
|
|
346
346
|
deps: [],
|
|
347
347
|
hasAction: false,
|
|
348
348
|
check(s) {
|
|
349
349
|
if (isOff(s.ctx.agents, "pi") && isOff(s.ctx.agents, "claude")) {
|
|
350
|
+
if (!isWantedNode(s.ctx.host.nodeVersion)) {
|
|
351
|
+
return {
|
|
352
|
+
ok: false,
|
|
353
|
+
detail: `install runs node ${s.ctx.host.nodeVersion}; agent-whisker requires Node ${WANTED_NODE_TEXT}`,
|
|
354
|
+
...NO_ACTION,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
350
357
|
const detail =
|
|
351
358
|
"pi and Claude Code are off for agent-whisker, so nothing install sets up runs on the login shell's node";
|
|
352
359
|
return { ok: true, detail, ...NO_ACTION };
|
|
353
360
|
}
|
|
354
361
|
const again = `check again with: ${s.ctx.host.platform === "win32" ? "node --version" : shellLine(shellArgv(s.ctx.host, true, LOGIN_NODE_SCRIPT))}`;
|
|
355
|
-
const
|
|
362
|
+
const host = s.ctx.host;
|
|
363
|
+
const where = host.platform === "win32" ? "this process's PATH" : "the login shell";
|
|
364
|
+
const running = `install runs node ${host.nodeVersion} (${host.execPath})`;
|
|
365
|
+
const found = loginNode(host);
|
|
356
366
|
if (found.kind === "unknown") return { ok: false, detail: `${found.why}; ${again}`, ...NO_ACTION };
|
|
357
367
|
if (found.kind === "missing") {
|
|
358
368
|
return {
|
|
359
369
|
ok: false,
|
|
360
|
-
detail:
|
|
370
|
+
detail: `${where} finds no node; ${running}; make a supported Node available there, then ${again}`,
|
|
361
371
|
...NO_ACTION,
|
|
362
372
|
};
|
|
363
373
|
}
|
|
364
374
|
const { path, version } = found.node;
|
|
365
|
-
|
|
375
|
+
const ok = isWantedNode(version) && isWantedNode(host.nodeVersion);
|
|
376
|
+
const detail = [`${where} runs node ${version} (${path})`];
|
|
377
|
+
if (version !== host.nodeVersion || !samePath(path, host.execPath)) detail.push(running);
|
|
378
|
+
if (!ok) detail.push(`agent-whisker requires Node ${WANTED_NODE_TEXT}`);
|
|
379
|
+
return { ok, detail: detail.join("; "), ...NO_ACTION };
|
|
366
380
|
},
|
|
367
381
|
},
|
|
368
382
|
{
|
|
@@ -1093,14 +1107,28 @@ function keptText(
|
|
|
1093
1107
|
* in place, since `command -v` finds no file that is not there and s.lookup keeps its first answer for the run.
|
|
1094
1108
|
*/
|
|
1095
1109
|
function notFoundText(s ) {
|
|
1096
|
-
|
|
1097
|
-
|
|
1110
|
+
const found = s.lookup(LAUNCHER_NAME);
|
|
1111
|
+
const windows = s.ctx.host.platform === "win32";
|
|
1112
|
+
if (found.kind === "unknown" || (found.kind === "found" && isLauncherPath(found.path, s.wrapper, windows))) return "";
|
|
1113
|
+
const reason =
|
|
1114
|
+
found.kind === "found"
|
|
1115
|
+
? `${found.path} takes precedence over ${s.wrapper}`
|
|
1116
|
+
: `${dirname(s.wrapper)} is not on ${windows ? "this process's PATH" : "the login shell's PATH, so agent-whisker and taskstate are not found by name until it is"}`;
|
|
1117
|
+
|
|
1118
|
+
if (windows) {
|
|
1098
1119
|
const dir = dirname(s.wrapper).replaceAll("'", "''");
|
|
1099
|
-
const line = `[Environment]::SetEnvironmentVariable('Path', [Environment]::GetEnvironmentVariable('Path', 'User')
|
|
1100
|
-
return `${
|
|
1120
|
+
const line = `[Environment]::SetEnvironmentVariable('Path', '${dir};' + [Environment]::GetEnvironmentVariable('Path', 'User'), 'User')`;
|
|
1121
|
+
return `${reason}; put the launcher directory first on your user PATH (install never changes PATH); in PowerShell: ${line}, then open a new terminal`;
|
|
1101
1122
|
}
|
|
1102
|
-
const
|
|
1103
|
-
|
|
1123
|
+
const shell = basename(s.ctx.host.env.SHELL || "zsh");
|
|
1124
|
+
if (!["fish", "bash", "sh", "zsh"].includes(shell))
|
|
1125
|
+
return `${reason}; put ${dirname(s.wrapper)} first on your shell's PATH`;
|
|
1126
|
+
const profile = shell === "bash" ? "~/.bash_profile" : shell === "sh" ? "~/.profile" : "~/.zprofile";
|
|
1127
|
+
const line =
|
|
1128
|
+
shell === "fish"
|
|
1129
|
+
? `echo 'fish_add_path --prepend --move "$HOME/.local/bin"' >> ~/.config/fish/config.fish`
|
|
1130
|
+
: `echo 'export PATH="$HOME/.local/bin:$PATH"' >> ${profile}`;
|
|
1131
|
+
return `${reason}; for ${shell}: ${line}, then open a new terminal`;
|
|
1104
1132
|
}
|
|
1105
1133
|
|
|
1106
1134
|
/**
|
|
@@ -3,8 +3,16 @@
|
|
|
3
3
|
// other file. The line shapes, and the reader of what a launcher carries, are ../launcher.ts's.
|
|
4
4
|
// Writes go through core's atomic writer; a target not written by this tool is never overwritten.
|
|
5
5
|
import { lstatSync, mkdirSync, realpathSync } from "node:fs";
|
|
6
|
-
import { basename, dirname, join } from "node:path";
|
|
7
|
-
import {
|
|
6
|
+
import { basename, dirname, join, posix, win32 } from "node:path";
|
|
7
|
+
import {
|
|
8
|
+
AGENTS_ENV,
|
|
9
|
+
HARNESSES,
|
|
10
|
+
|
|
11
|
+
RERANK_ENV,
|
|
12
|
+
resolveHome,
|
|
13
|
+
sessionSource,
|
|
14
|
+
writeFileAtomic,
|
|
15
|
+
} from "../../../core/src/index.js";
|
|
8
16
|
import { cleanLibraryDescription, LIBRARY_DESCRIPTION_ENV, LIBRARY_FOLDERS_ENV, PRAISE_ENV } from "../../../mcp/src/index.js";
|
|
9
17
|
import { KEYSTORE_ENV } from "../keystore.js";
|
|
10
18
|
import { CARRIED_LINE, HOME_LINE, readHead, SETTING_ENTRY, SETTING_NODE, WRAPPER_READ_MAX } from "../launcher.js";
|
|
@@ -21,11 +29,19 @@ import {
|
|
|
21
29
|
/** Characters the launcher must not contain: `"`, `$`, `` ` ``, `\`, `}` and newline. */
|
|
22
30
|
const UNQUOTABLE = /["$`\\}\n]/;
|
|
23
31
|
|
|
32
|
+
const PROGRAM_HOMES = new Map(
|
|
33
|
+
HARNESSES.flatMap((id) => {
|
|
34
|
+
const { root } = sessionSource(id);
|
|
35
|
+
return root.variable === null
|
|
36
|
+
? []
|
|
37
|
+
: [root.variable, ...(root.directory ? [root.directory] : [])].map((name) => [name, root] );
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
40
|
+
|
|
24
41
|
/**
|
|
25
42
|
* The settings the launcher carries besides the agent list, in the order it writes them: the rerank switch, URL, model
|
|
26
|
-
* and threshold, the library description,
|
|
27
|
-
*
|
|
28
|
-
* install used.
|
|
43
|
+
* and threshold, the library description, folder switch and whisker line, the key-store selection, and any custom
|
|
44
|
+
* session roots. The launcher carries key-store selection, not the keys themselves.
|
|
29
45
|
*/
|
|
30
46
|
export const CARRIED = [
|
|
31
47
|
RERANK_ENV.enabled,
|
|
@@ -36,6 +52,7 @@ export const CARRIED = [
|
|
|
36
52
|
LIBRARY_FOLDERS_ENV,
|
|
37
53
|
PRAISE_ENV,
|
|
38
54
|
KEYSTORE_ENV,
|
|
55
|
+
...PROGRAM_HOMES.keys(),
|
|
39
56
|
] ;
|
|
40
57
|
|
|
41
58
|
/** What the launcher keeps from an earlier one (wrapperContent's kept): the values of its own lines, by name. */
|
|
@@ -66,6 +83,12 @@ export function wrapperContent(
|
|
|
66
83
|
const given = (name ) => {
|
|
67
84
|
const value = host.env[name];
|
|
68
85
|
if (value === undefined) return undefined;
|
|
86
|
+
const root = PROGRAM_HOMES.get(name);
|
|
87
|
+
if (root) {
|
|
88
|
+
const path = host.platform === "win32" ? win32 : posix;
|
|
89
|
+
const read = root.reading(value, host.homeDir, path, host.platform === "win32");
|
|
90
|
+
if (!read || !path.isAbsolute(read) || /[\r\n]/.test(value)) return undefined;
|
|
91
|
+
}
|
|
69
92
|
if (name === LIBRARY_DESCRIPTION_ENV) return cleanLibraryDescription(value) ?? undefined;
|
|
70
93
|
if (name === PRAISE_ENV) return cleanLibraryDescription(value) ?? "";
|
|
71
94
|
return value;
|
package/packages/cli/src/main.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// real Host (core's systemHost) and stores the returned exit code in process.exitCode.
|
|
4
|
-
//
|
|
5
|
-
// It does not call process.exit(): writes from host.out and host.err to a pipe may be asynchronous (they are on macOS),
|
|
6
|
-
// and process.exit() would drop output not yet written. With process.exitCode set, the process exits on its own once
|
|
7
|
-
// the event loop drains, with that code.
|
|
8
|
-
// process.argv and process.exitCode here are the only two places in the cli package that touch `process` directly;
|
|
9
|
-
// everything else goes through Host. The launcher that `install` writes to ~/.local/bin/agent-whisker runs this file
|
|
10
|
-
// with a fixed node; the first line lets npm link it as the package's command, which runs on the PATH's node.
|
|
11
|
-
import { systemHost } from "../../core/src/index.js";
|
|
12
|
-
import { runCli } from "./index.js";
|
|
2
|
+
import { isWantedNode, WANTED_NODE_TEXT } from "./node-version.js";
|
|
13
3
|
|
|
14
|
-
|
|
4
|
+
if (!isWantedNode(process.versions.node)) {
|
|
5
|
+
process.stderr.write(`agent-whisker requires Node ${WANTED_NODE_TEXT}; running ${process.version}.\n`);
|
|
6
|
+
process.exitCode = 1;
|
|
7
|
+
} else {
|
|
8
|
+
const { systemHost } = await import("../../core/src/index.js");
|
|
9
|
+
const { runCli } = await import("./index.js");
|
|
10
|
+
process.exitCode = await runCli(process.argv.slice(2), systemHost());
|
|
11
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Node versions agent-whisker supports, the same range as `engines` in the root package.json
|
|
3
|
+
* (`>=24.22.1 <25 || >=26.13.0 <27`): per major line, its first supported release as [major, minor, patch].
|
|
4
|
+
* 24 starts at 24.22.1, the first 24 release with V8's fix for a JSON.parse defect: after an object key holding a
|
|
5
|
+
* backslash, a later escaped key of the same decoded length can come back as that earlier key (nodejs/node#66916; V8
|
|
6
|
+
* commit 93cd21e8254b, backported in 24.22.1). 25 is left out: an odd release, no longer supported upstream.
|
|
7
|
+
*/
|
|
8
|
+
const SUPPORTED_NODE = [
|
|
9
|
+
[24, 22, 1],
|
|
10
|
+
[26, 13, 0],
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
/** Three-part numeric format of a stable Node version; prerelease suffixes and leading zeros do not match. */
|
|
14
|
+
const NODE_VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
15
|
+
|
|
16
|
+
/** The human-readable Node requirement used in messages. */
|
|
17
|
+
export const WANTED_NODE_TEXT = "24.22.1 or later below 25, or 26.13.0 or later below 27";
|
|
18
|
+
|
|
19
|
+
/** Whether a version without a leading v is a stable release in SUPPORTED_NODE; no side effects, does not throw, needs no lock or transaction. */
|
|
20
|
+
export function isWantedNode(version ) {
|
|
21
|
+
const match = NODE_VERSION.exec(version);
|
|
22
|
+
if (match === null) return false;
|
|
23
|
+
const [major, minor, patch] = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
24
|
+
return SUPPORTED_NODE.some(([m, n, p]) => major === m && (minor > n || (minor === n && patch >= p)));
|
|
25
|
+
}
|