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,156 @@
|
|
|
1
|
+
// `agent-whisker exclude add|remove <dir> [--hide-ingested]`: writes or removes the ingest exclusion marker,
|
|
2
|
+
// `<dir>/.agent-whisker-exclude`, which keeps the directory and everything below it out of later ingests (core's
|
|
3
|
+
// exclude.ts holds the rule). add writes an empty marker (an existing one is left as it is); with --hide-ingested it
|
|
4
|
+
// also hides the visible documents already ingested from under dir, as `document remove` does each (restore one with
|
|
5
|
+
// `document restore`). remove deletes the marker only when it is an empty regular file: a directory, a symlink or a
|
|
6
|
+
// file with content is refused, so no file of the user's is ever deleted; hidden documents stay hidden.
|
|
7
|
+
//
|
|
8
|
+
// Output: --json gives `{ dir, marker, created, hidden, documents }` for add (documents: the `{ scope, docId }` hidden
|
|
9
|
+
// by this call) and `{ dir, marker, removed }` for remove; text gives one line each. Needs an initialised data
|
|
10
|
+
// directory, opened right after the usage check, with quick_check, since --hide-ingested appends journal events.
|
|
11
|
+
import { lstatSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { join, resolve } from "node:path";
|
|
13
|
+
import { isErrno, } from "../../../core/src/index.js";
|
|
14
|
+
import {
|
|
15
|
+
CliError,
|
|
16
|
+
|
|
17
|
+
displayField,
|
|
18
|
+
EXIT,
|
|
19
|
+
errnoText,
|
|
20
|
+
parseCommandArgs,
|
|
21
|
+
UsageError,
|
|
22
|
+
writeResult,
|
|
23
|
+
} from "../command.js";
|
|
24
|
+
import { documentPath, folderFor, isUnder } from "../exclusion.js";
|
|
25
|
+
import { currentView, withStore } from "../store-access.js";
|
|
26
|
+
|
|
27
|
+
/** The marker's name, as core's exclude.ts names it. */
|
|
28
|
+
const EXCLUDE_MARKER = ".agent-whisker-exclude";
|
|
29
|
+
|
|
30
|
+
/** The most documents one `exclude add --hide-ingested` hides: 100 000. */
|
|
31
|
+
const HIDE_MAX = 100_000;
|
|
32
|
+
|
|
33
|
+
/** The `exclude` entry in the command table. */
|
|
34
|
+
export const excludeCommand = {
|
|
35
|
+
name: "exclude",
|
|
36
|
+
summary: "Keep a directory out of the library with an exclusion marker, or remove the marker",
|
|
37
|
+
usage: "agent-whisker exclude add|remove <dir> [--hide-ingested]",
|
|
38
|
+
needsStore: true,
|
|
39
|
+
checksIntegrity: true,
|
|
40
|
+
run(ctx) {
|
|
41
|
+
const [action, ...rest] = ctx.args;
|
|
42
|
+
if (action !== "add" && action !== "remove") throw new UsageError("use exclude add or remove");
|
|
43
|
+
const { values, positionals } = parseCommandArgs(
|
|
44
|
+
rest,
|
|
45
|
+
{ "hide-ingested": { type: "boolean" } },
|
|
46
|
+
{ min: 1, max: 1 },
|
|
47
|
+
);
|
|
48
|
+
if (action === "remove" && values["hide-ingested"] === true)
|
|
49
|
+
throw new UsageError("--hide-ingested goes with exclude add");
|
|
50
|
+
const dir = resolve(ctx.cwd, positionals[0] ?? "");
|
|
51
|
+
const marker = join(dir, EXCLUDE_MARKER);
|
|
52
|
+
return withStore(ctx, (store) => {
|
|
53
|
+
requireDirectory(dir);
|
|
54
|
+
if (action === "remove") {
|
|
55
|
+
const removed = removeMarker(marker);
|
|
56
|
+
writeResult(ctx, { dir, marker, removed }, [
|
|
57
|
+
removed ? `removed ${displayField(marker)}` : `no marker in ${displayField(dir)}`,
|
|
58
|
+
]);
|
|
59
|
+
return EXIT.ok;
|
|
60
|
+
}
|
|
61
|
+
let created = true;
|
|
62
|
+
try {
|
|
63
|
+
writeFileSync(marker, "", { flag: "wx", mode: 0o644 });
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (!isErrno(error, "EEXIST"))
|
|
66
|
+
throw new CliError("WriteFailed", `cannot write ${marker} (${errnoText(error)})`);
|
|
67
|
+
created = false;
|
|
68
|
+
}
|
|
69
|
+
const documents = values["hide-ingested"] === true ? hideUnder(store, ctx.cwd, ctx.host.homeDir, dir) : [];
|
|
70
|
+
const lines = [
|
|
71
|
+
`${created ? "wrote" : "kept"} ${displayField(marker)}: later ingests skip ${displayField(dir)}`,
|
|
72
|
+
...(values["hide-ingested"] === true
|
|
73
|
+
? [`hid ${documents.length} ingested ${documents.length === 1 ? "document" : "documents"}`]
|
|
74
|
+
: []),
|
|
75
|
+
];
|
|
76
|
+
writeResult(ctx, { dir, marker, created, hidden: documents.length, documents }, lines);
|
|
77
|
+
return EXIT.ok;
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/** Throws NotFound when dir does not exist and NotADirectory when it is something else; follows symlinks as ingest does. */
|
|
83
|
+
function requireDirectory(dir ) {
|
|
84
|
+
let stat ;
|
|
85
|
+
try {
|
|
86
|
+
stat = statSync(dir);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
throw new CliError("NotFound", `${dir} cannot be read (${errnoText(error)})`);
|
|
89
|
+
}
|
|
90
|
+
if (!stat.isDirectory()) throw new CliError("NotADirectory", `${dir} is not a directory`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Deletes marker when it is an empty regular file and returns true; false when there is none. Refuses (CliError
|
|
95
|
+
* NotAMarker) a directory, a symlink or anything else in its place, and (NotEmpty) a file with content, which
|
|
96
|
+
* someone may have written on purpose: only the empty file `exclude add` writes is ever deleted.
|
|
97
|
+
*/
|
|
98
|
+
function removeMarker(marker ) {
|
|
99
|
+
let stat ;
|
|
100
|
+
try {
|
|
101
|
+
stat = lstatSync(marker);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (isErrno(error, "ENOENT")) return false;
|
|
104
|
+
throw new CliError("NotFound", `${marker} cannot be read (${errnoText(error)})`);
|
|
105
|
+
}
|
|
106
|
+
if (!stat.isFile()) throw new CliError("NotAMarker", `${marker} is not a regular file, so it is left in place`);
|
|
107
|
+
if (stat.size !== 0) throw new CliError("NotEmpty", `${marker} is not empty, so it is left in place`);
|
|
108
|
+
// A file swapped in between this check and the unlink is a race with someone writing the marker at that instant;
|
|
109
|
+
// the check is what keeps a file written on purpose from ever being removed by mistake.
|
|
110
|
+
try {
|
|
111
|
+
unlinkSync(marker);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (isErrno(error, "ENOENT")) return false;
|
|
114
|
+
throw new CliError("RemoveFailed", `cannot remove ${marker} (${errnoText(error)})`);
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Hides each visible document of the current view whose label lies under dir, as `document remove` does, and returns
|
|
121
|
+
* the ones this call hid. The user scope's and the current project's documents are found by catalog's folder filter.
|
|
122
|
+
*/
|
|
123
|
+
function hideUnder(store , cwd , homeDir , dir ) {
|
|
124
|
+
const view = currentView(store, cwd);
|
|
125
|
+
const groups = [
|
|
126
|
+
{ scopes: ["user"], folder: folderFor(dir, "user", homeDir) },
|
|
127
|
+
];
|
|
128
|
+
if (view.project !== null)
|
|
129
|
+
groups.push({ scopes: [view.project.scope], folder: folderFor(dir, view.project, homeDir) });
|
|
130
|
+
const hidden = [];
|
|
131
|
+
for (const { scopes, folder } of groups) {
|
|
132
|
+
if (folder === null) continue;
|
|
133
|
+
const { documents } = store.catalog({
|
|
134
|
+
scopes,
|
|
135
|
+
maxTier: view.maxTier,
|
|
136
|
+
limit: HIDE_MAX,
|
|
137
|
+
...(folder === "" ? {} : { folder }),
|
|
138
|
+
});
|
|
139
|
+
for (const doc of documents) {
|
|
140
|
+
// The folder filter is by label; the file's own path decides, so a label outside dir (an absolute one when dir
|
|
141
|
+
// is the home directory) is never hidden by this call.
|
|
142
|
+
const path = documentPath(doc, homeDir, view.project);
|
|
143
|
+
if (path === null || !isUnder(path, dir)) continue;
|
|
144
|
+
const result = store.setDocumentDeleted({
|
|
145
|
+
scope: doc.scope,
|
|
146
|
+
maxTier: view.maxTier,
|
|
147
|
+
docId: doc.docId,
|
|
148
|
+
deleted: true,
|
|
149
|
+
actor: "human",
|
|
150
|
+
entry: "cli",
|
|
151
|
+
});
|
|
152
|
+
if (result.changed) hidden.push({ scope: doc.scope, docId: doc.docId });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return hidden;
|
|
156
|
+
}
|
|
@@ -7,7 +7,7 @@ export const extractCommand = {
|
|
|
7
7
|
name: "extract",
|
|
8
8
|
summary: "Extract typed fields from a library document, local files, or supplied text with Clairic",
|
|
9
9
|
usage:
|
|
10
|
-
"agent-whisker extract [<doc-or-path>…] --fields <json> [--pages 1,2] [--state <text>] [--source-only] [--reference-date YYYY-MM-DD] [--url <url>] [--model <model>]
|
|
10
|
+
"agent-whisker extract [<doc-or-path>…] --fields <json> [--pages 1,2] [--state <text>] [--source-only] [--reference-date YYYY-MM-DD] [--url <url>] [--model <model>]",
|
|
11
11
|
needsStore: false,
|
|
12
12
|
checksIntegrity: false,
|
|
13
13
|
async run(ctx) {
|
|
@@ -31,7 +31,7 @@ export const extractCommand = {
|
|
|
31
31
|
} catch {
|
|
32
32
|
throw new UsageError("--fields must be valid JSON");
|
|
33
33
|
}
|
|
34
|
-
if (values.pages !== undefined &&
|
|
34
|
+
if (values.pages !== undefined && !/^[1-9]\d*(,[1-9]\d*)*$/.test(values.pages))
|
|
35
35
|
throw new UsageError("--pages requires comma-separated positive page numbers");
|
|
36
36
|
const input = {
|
|
37
37
|
fields: validateExtractFields(parsed),
|
|
@@ -42,6 +42,8 @@ export const extractCommand = {
|
|
|
42
42
|
url: values.url,
|
|
43
43
|
model: values.model,
|
|
44
44
|
};
|
|
45
|
+
if (!positionals.length && !values.state?.trim())
|
|
46
|
+
throw new UsageError("extract needs a document, a file, or --state <text>");
|
|
45
47
|
const docId = positionals.length === 1 ? positionals[0] : undefined;
|
|
46
48
|
const result = await (docId && /^(?:do|dp|ds)_[A-Za-z0-9_-]{22}$/.test(docId)
|
|
47
49
|
? withStore(ctx, (store) =>
|
|
@@ -61,7 +61,7 @@ export const indexCommand = {
|
|
|
61
61
|
const statusRequested = values.status === true || action === "status";
|
|
62
62
|
const rebuildRequested = values.rebuild === true || action === "rebuild";
|
|
63
63
|
if (statusRequested && rebuildRequested) {
|
|
64
|
-
throw new UsageError("status and rebuild cannot be used together");
|
|
64
|
+
throw new UsageError("--status and --rebuild cannot be used together");
|
|
65
65
|
}
|
|
66
66
|
return withStore(ctx, (store) => {
|
|
67
67
|
if (statusRequested) {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { catalogCommand } from "./catalog.js";
|
|
5
5
|
import { doctorCommand } from "./doctor.js";
|
|
6
6
|
import { documentCommand } from "./document.js";
|
|
7
|
+
import { excludeCommand } from "./exclude.js";
|
|
7
8
|
import { extractCommand } from "./extract.js";
|
|
8
9
|
import { grepCommand } from "./grep.js";
|
|
9
10
|
import { hookCommand } from "./hook.js";
|
|
@@ -19,6 +20,7 @@ import { searchCommand } from "./search.js";
|
|
|
19
20
|
import { serviceCommand } from "./service.js";
|
|
20
21
|
import { sessionsCommand } from "./sessions.js";
|
|
21
22
|
import { statusCommand } from "./status.js";
|
|
23
|
+
import { tuiCommand } from "./tui.js";
|
|
22
24
|
import { versionCommand } from "./version.js";
|
|
23
25
|
|
|
24
26
|
/** Every command, sorted by name. Frozen: nothing can be added at runtime. */
|
|
@@ -26,6 +28,7 @@ export const commands = Object.freeze([
|
|
|
26
28
|
catalogCommand,
|
|
27
29
|
doctorCommand,
|
|
28
30
|
documentCommand,
|
|
31
|
+
excludeCommand,
|
|
29
32
|
extractCommand,
|
|
30
33
|
grepCommand,
|
|
31
34
|
hookCommand,
|
|
@@ -41,5 +44,6 @@ export const commands = Object.freeze([
|
|
|
41
44
|
serviceCommand,
|
|
42
45
|
sessionsCommand,
|
|
43
46
|
statusCommand,
|
|
47
|
+
tuiCommand,
|
|
44
48
|
versionCommand,
|
|
45
49
|
]);
|
|
@@ -38,7 +38,7 @@ const MCP_GROUP = "mcp";
|
|
|
38
38
|
/** The `install` entry in the command table. */
|
|
39
39
|
export const installCommand = {
|
|
40
40
|
name: "install",
|
|
41
|
-
summary: "Check each step that puts agent-whisker into this
|
|
41
|
+
summary: "Check each step that puts agent-whisker into this user's agent programs, and apply the ones named",
|
|
42
42
|
usage: `${LAUNCHER_NAME} install [--dry-run] [--apply <steps> | --remove <steps>] [--via ${MAGPIE}]`,
|
|
43
43
|
needsStore: false,
|
|
44
44
|
checksIntegrity: false,
|
|
@@ -67,6 +67,17 @@ export const installCommand = {
|
|
|
67
67
|
`install is only available on macOS and Windows for now; this host is ${ctx.host.platform}, nothing was checked`,
|
|
68
68
|
);
|
|
69
69
|
}
|
|
70
|
+
if (
|
|
71
|
+
ctx.host.platform !== "win32" &&
|
|
72
|
+
ctx.host.uid === 0 &&
|
|
73
|
+
!values["dry-run"] &&
|
|
74
|
+
(named.size || removing !== null)
|
|
75
|
+
) {
|
|
76
|
+
throw new CliError(
|
|
77
|
+
"NotAvailable",
|
|
78
|
+
"install changes per-user files; run it as the intended user, not root (without sudo)",
|
|
79
|
+
);
|
|
80
|
+
}
|
|
70
81
|
// On Windows each step that is not built there yet refuses by itself (steps.ts), apply and remove alike.
|
|
71
82
|
// A wrong agent list stops the run before any check: guessing nothing or everything could collect against the
|
|
72
83
|
// person's wish.
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// herdr with its own failures. Arguments are therefore parsed outside the try that catches errors (usage errors still
|
|
13
|
-
// exit 2), and every nudgeService error becomes a sentence.
|
|
14
|
-
|
|
15
|
-
import { isPlainObject, oneLine } from "../../../core/src/index.js";
|
|
16
|
-
import { ensureService, nudgeService } from "../../../service/src/index.js";
|
|
17
|
-
import { describeError, displayField, EXIT, parseCommandArgs, writeResult } from "../command.js";
|
|
1
|
+
import { isPlainObject, oneLine, resolveHome } from "../../../core/src/index.js";
|
|
2
|
+
import { ensureService, nudgeService, serviceRunning } from "../../../service/src/index.js";
|
|
3
|
+
import {
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
describeError,
|
|
7
|
+
displayField,
|
|
8
|
+
EXIT,
|
|
9
|
+
parseCommandArgs,
|
|
10
|
+
writeResult,
|
|
11
|
+
} from "../command.js";
|
|
18
12
|
|
|
19
13
|
/** Whether a Herdr `pane.agent_status_changed` payload names an active (non-idle) state that needs no nudge yet. */
|
|
20
14
|
function isActiveHerdrStatus(raw ) {
|
|
@@ -42,40 +36,48 @@ function startIfStopped(host ) {
|
|
|
42
36
|
}
|
|
43
37
|
}
|
|
44
38
|
|
|
45
|
-
|
|
46
|
-
* The `nudge` entry in the command table.
|
|
47
|
-
*
|
|
48
|
-
* `--from-herdr`: passed when the herdr plugin calls it. It is accepted but does not change behaviour yet
|
|
49
|
-
* (HERDR_PLUGIN_EVENT_JSON is not read). needsStore is false: on an uninitialised data directory it quietly returns 0
|
|
50
|
-
* and creates nothing.
|
|
51
|
-
*/
|
|
52
|
-
export const nudgeCommand = {
|
|
39
|
+
export const nudgeCommand = {
|
|
53
40
|
name: "nudge",
|
|
54
41
|
summary: "Tell the background service to bring the index up to date now",
|
|
55
42
|
usage: "agent-whisker nudge [--from-herdr]",
|
|
56
43
|
needsStore: false,
|
|
57
44
|
checksIntegrity: false,
|
|
58
|
-
run(ctx) {
|
|
45
|
+
run(ctx ) {
|
|
59
46
|
const { values } = parseCommandArgs(ctx.args, { "from-herdr": { type: "boolean" } }, { min: 0, max: 0 });
|
|
60
47
|
if (values["from-herdr"] === true && isActiveHerdrStatus(ctx.host.env.HERDR_PLUGIN_EVENT_JSON)) {
|
|
61
|
-
writeResult(ctx, { nudged: false }, [
|
|
48
|
+
if (ctx.json) writeResult(ctx, { nudged: false }, []);
|
|
62
49
|
return EXIT.ok;
|
|
63
50
|
}
|
|
64
|
-
let value
|
|
51
|
+
let value ;
|
|
65
52
|
let sentence ;
|
|
53
|
+
let nudged = false;
|
|
66
54
|
try {
|
|
67
|
-
|
|
55
|
+
nudged = nudgeService(ctx.host);
|
|
68
56
|
if (nudged && ctx.host.platform === "win32") startIfStopped(ctx.host);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
57
|
+
if (values["from-herdr"]) {
|
|
58
|
+
if (ctx.json) writeResult(ctx, { nudged }, []);
|
|
59
|
+
return EXIT.ok;
|
|
60
|
+
}
|
|
61
|
+
const home = resolveHome(ctx.host.env, ctx.host.homeDir);
|
|
62
|
+
if (nudged) {
|
|
63
|
+
const running = serviceRunning(home);
|
|
64
|
+
value = { nudged, running };
|
|
65
|
+
sentence = running
|
|
66
|
+
? "queued a nudge for the service's next tick"
|
|
67
|
+
: "queued a nudge; the service is not running (run: agent-whisker service run)";
|
|
68
|
+
} else {
|
|
69
|
+
value = { nudged };
|
|
70
|
+
sentence = `the data directory ${displayField(home)} is not initialised; nothing to nudge`;
|
|
71
|
+
}
|
|
73
72
|
} catch (error) {
|
|
74
73
|
const described = describeError(error);
|
|
75
|
-
value = { nudged
|
|
76
|
-
|
|
74
|
+
value = { nudged, error: described };
|
|
75
|
+
const detail = nudged
|
|
76
|
+
? "queued a nudge; could not check if the service is running"
|
|
77
|
+
: "could not nudge the service";
|
|
78
|
+
sentence = `${detail}: ${described.code}: ${displayField(oneLine(described.message))}`;
|
|
77
79
|
}
|
|
78
|
-
writeResult(ctx, value, [sentence]);
|
|
80
|
+
if (!values["from-herdr"] || ctx.json) writeResult(ctx, value, [sentence]);
|
|
79
81
|
return EXIT.ok;
|
|
80
82
|
},
|
|
81
|
-
};
|
|
83
|
+
} ;
|
|
@@ -49,7 +49,8 @@ export const readCommand = {
|
|
|
49
49
|
name: "read",
|
|
50
50
|
summary: "Read a document's outline, chunk, PDF page, section, continuation, or byte range",
|
|
51
51
|
usage:
|
|
52
|
-
"agent-whisker read <doc-id> [--version <version>] [--from <next> | --start <byte> [--end <byte>] | --chunk <n> | --page <n> | --section <n> [--before <n>] [--after <n>]] [--max-bytes <n>] [--outline]",
|
|
52
|
+
"agent-whisker read <doc-id> [--version <version>] [--from <next> | --start <byte> [--end <byte>] | (--chunk <n> | --page <n> | --section <n>) [--before <n>] [--after <n>]] [--max-bytes <n>] [--outline]",
|
|
53
|
+
help: "--version accepts a full hash or its unique 12-character cursor prefix. Competing locators use the first in the order shown; ignored options are reported. --outline alone returns an outline without text.",
|
|
53
54
|
needsStore: true,
|
|
54
55
|
checksIntegrity: false,
|
|
55
56
|
run(ctx) {
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
UsageError,
|
|
29
29
|
writeResult,
|
|
30
30
|
} from "../command.js";
|
|
31
|
+
import { documentPath, markerChecker } from "../exclusion.js";
|
|
31
32
|
import { currentView, VIEW_MAX_TIER, withStore } from "../store-access.js";
|
|
32
33
|
import { docKindOption } from "./catalog.js";
|
|
33
34
|
|
|
@@ -43,6 +44,17 @@ const OPTIONS = {
|
|
|
43
44
|
"eval-reserve-per-query": { type: "string" },
|
|
44
45
|
} ;
|
|
45
46
|
|
|
47
|
+
/** The most hidden documents of the view looked at for the avoided counts: 100 000. */
|
|
48
|
+
const AVOIDED_MAX = 100_000;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* What --json reports the search could not see: the hidden documents (doc.delete: `document remove`, `exclude add
|
|
52
|
+
* --hide-ingested`) in the view and filters it searched (scopes, tier ceiling, kind, folder), as two counts:
|
|
53
|
+
* excluded, those whose file lies under a directory holding .agent-whisker-exclude, and removed, the rest. Text output
|
|
54
|
+
* leaves it out, so its bytes stay as they were; MCP's answers do not carry it.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
|
|
46
58
|
/** The current project's identity in JSON output; null for an unregistered working directory. No side effects. */
|
|
47
59
|
|
|
48
60
|
|
|
@@ -55,6 +67,7 @@ export const searchCommand = {
|
|
|
55
67
|
summary: "Search the documents of the current project and the user's notes",
|
|
56
68
|
usage:
|
|
57
69
|
"agent-whisker search <query>… [--limit <n>] [--kind <kind>] [--folder <folder>] [--question <text>] [--no-rerank] [--group document] [--max-excerpt-bytes <n>] [--widen]",
|
|
70
|
+
help: "Supply up to 8 queries, at most 1024 UTF-8 bytes each; quote a multi-word query.",
|
|
58
71
|
needsStore: true,
|
|
59
72
|
checksIntegrity: false,
|
|
60
73
|
async run(ctx) {
|
|
@@ -66,7 +79,7 @@ export const searchCommand = {
|
|
|
66
79
|
const limit = integerOption(values.limit, "limit");
|
|
67
80
|
const maxExcerptBytes = integerOption(values["max-excerpt-bytes"], "max-excerpt-bytes");
|
|
68
81
|
const evalReservePerQuery = integerOption(values["eval-reserve-per-query"], "eval-reserve-per-query");
|
|
69
|
-
const { pending, project, sources } = withStore(ctx, (store) => {
|
|
82
|
+
const { pending, project, sources, hidden, resolved } = withStore(ctx, (store) => {
|
|
70
83
|
const view = currentView(store, ctx.cwd);
|
|
71
84
|
const docKinds = kind === undefined ? undefined : [kind];
|
|
72
85
|
// `group` is validated at core's query boundary so the CLI and MCP do not each keep a copy of the rule.
|
|
@@ -93,11 +106,28 @@ export const searchCommand = {
|
|
|
93
106
|
maxTier: view.maxTier,
|
|
94
107
|
docs: pending.found.hits.map(({ scope, docId, version }) => ({ scope, docId, version })),
|
|
95
108
|
});
|
|
96
|
-
|
|
109
|
+
const hidden = ctx.json
|
|
110
|
+
? store.catalog({
|
|
111
|
+
scopes: view.scopes,
|
|
112
|
+
maxTier: view.maxTier,
|
|
113
|
+
removed: true,
|
|
114
|
+
limit: AVOIDED_MAX,
|
|
115
|
+
...(docKinds === undefined ? {} : { docKinds }),
|
|
116
|
+
...(values.folder === undefined ? {} : { folder: values.folder }),
|
|
117
|
+
}).documents
|
|
118
|
+
: [];
|
|
119
|
+
return { pending, project: projectOf(store, view.project), sources, hidden, resolved: view.project };
|
|
97
120
|
});
|
|
98
121
|
const result = await finishLibrarySearch(pending, ctx.host);
|
|
99
122
|
const mark = sourceMarks(sources, ctx.host.homeDir);
|
|
100
|
-
|
|
123
|
+
const marked = markerChecker();
|
|
124
|
+
const avoided = { removed: 0, excluded: 0 };
|
|
125
|
+
for (const doc of hidden) {
|
|
126
|
+
const path = documentPath(doc, ctx.host.homeDir, resolved);
|
|
127
|
+
if (path !== null && marked(path)) avoided.excluded++;
|
|
128
|
+
else avoided.removed++;
|
|
129
|
+
}
|
|
130
|
+
writeResult(ctx, { ...withMarks(result, mark), project, avoided }, searchText(result, project, ctx.cwd, mark));
|
|
101
131
|
return EXIT.ok;
|
|
102
132
|
},
|
|
103
133
|
};
|
|
@@ -95,12 +95,13 @@ export const sessionsCommand = {
|
|
|
95
95
|
usage: [
|
|
96
96
|
"agent-whisker sessions status",
|
|
97
97
|
"agent-whisker sessions sync",
|
|
98
|
-
"agent-whisker sessions search [<query>…] [--parent <session>] [--session <session>] [--harness <name>] [--cwd-prefix <dir>] [--since <date>] [--until <date>] [--limit <n>] [--role <dialogue|user|assistant|tool>] [--no-subagents] [--group session] [--project]",
|
|
99
|
-
"agent-whisker sessions grep [-F] [-i|-s] [-w] [-l|-c] [-m <n>] [-e <pattern>|--regexp=<pattern>] [--limit <n>] [--parent <session>] [--session <session>] [--harness <name>] [--cwd-prefix <dir>] [--since <date>] [--until <date>] [--role <dialogue|user|assistant|tool>] [--no-subagents] [--project] <pattern>",
|
|
98
|
+
"agent-whisker sessions search [<query>…] [--parent <session>] [--session <session>] [--harness <name>] [--cwd-prefix <dir>] [--since <date>] [--until <date>] [--limit <n>] [--role <dialogue|user|assistant|tool|all>] [--no-subagents] [--group session] [--project]",
|
|
99
|
+
"agent-whisker sessions grep [-F] [-i|-s] [-w] [-l|-c] [-m <n>] [-e <pattern>|--regexp=<pattern>] [--limit <n>] [--parent <session>] [--session <session>] [--harness <name>] [--cwd-prefix <dir>] [--since <date>] [--until <date>] [--role <dialogue|user|assistant|tool|all>] [--no-subagents] [--project] <pattern>",
|
|
100
100
|
"agent-whisker sessions read <session> [--from <next> | --at <n> --before <n> | --tail <n>] [--after <n>] [--results]",
|
|
101
101
|
...WAIT_USAGE,
|
|
102
102
|
"agent-whisker sessions forget <session> [--undo]",
|
|
103
103
|
].join("\n"),
|
|
104
|
+
help: "Search takes up to 8 queries, at most 1024 UTF-8 bytes each; quote a multi-word query. Search defaults to dialogue; grep searches all retained roles. Read --results can also recover tool output from an unchanged source file.",
|
|
104
105
|
needsStore: true,
|
|
105
106
|
checksIntegrity: false,
|
|
106
107
|
run(ctx) {
|
|
@@ -157,9 +158,9 @@ function status(ctx , args ) {
|
|
|
157
158
|
*/
|
|
158
159
|
function statusText(result ) {
|
|
159
160
|
if (!result.present) return ["the session index has not been built yet (run: agent-whisker sessions sync)"];
|
|
161
|
+
const width = Math.max(...result.harnesses.map((h) => h.harness.length));
|
|
160
162
|
const lines = result.harnesses.map((h) => {
|
|
161
|
-
|
|
162
|
-
const name = `${h.harness.padEnd(7)} `;
|
|
163
|
+
const name = `${h.harness.padEnd(width)} `;
|
|
163
164
|
if (h.off === true) {
|
|
164
165
|
const span =
|
|
165
166
|
h.firstMs === null || h.lastMs === null
|
|
@@ -207,6 +208,7 @@ function search(ctx , args ) {
|
|
|
207
208
|
const filters = filterQuery(values, ctx.cwd);
|
|
208
209
|
return withSessions(ctx, (store) => {
|
|
209
210
|
const result = store.searchSessions({
|
|
211
|
+
...(positionals.length && values.role === undefined ? { role: "dialogue" } : {}),
|
|
210
212
|
...filters,
|
|
211
213
|
queries: positionals,
|
|
212
214
|
...(values.group === undefined ? {} : { group: values.group }),
|
|
@@ -245,7 +247,9 @@ function filterQuery(
|
|
|
245
247
|
...(values["cwd-prefix"] === undefined ? {} : { cwd: values["cwd-prefix"] }),
|
|
246
248
|
...(values.since === undefined ? {} : { since: values.since }),
|
|
247
249
|
...(values.until === undefined ? {} : { until: values.until }),
|
|
248
|
-
...(values.role === undefined
|
|
250
|
+
...(values.role === undefined || values.role === "all"
|
|
251
|
+
? {}
|
|
252
|
+
: { role: values.role }),
|
|
249
253
|
...(values["no-subagents"] ? { subagents: false } : {}),
|
|
250
254
|
...(values.project ? { projectCwd: cwd } : {}),
|
|
251
255
|
};
|
|
@@ -590,13 +594,17 @@ function forget(ctx , args ) {
|
|
|
590
594
|
const result = store.forgetSession(positionals[0] ?? "", values.undo === true);
|
|
591
595
|
const children = result.subagents?.length ?? 0;
|
|
592
596
|
const text =
|
|
593
|
-
result.
|
|
594
|
-
? `forgot ${result.session}
|
|
595
|
-
:
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
597
|
+
result.already === "forgotten"
|
|
598
|
+
? `already forgot ${result.session}`
|
|
599
|
+
: result.already === "not-forgotten"
|
|
600
|
+
? `no forget marker for ${displayField(result.session)}; nothing to undo`
|
|
601
|
+
: result.sourcePresent === undefined
|
|
602
|
+
? `forgot ${result.session}${children === 0 ? "" : ` and ${children} subagent session${children === 1 ? "" : "s"} with it`}`
|
|
603
|
+
: `undid forget for ${result.session}; ${
|
|
604
|
+
result.sourcePresent
|
|
605
|
+
? "the source file can be collected on the next sync"
|
|
606
|
+
: "the source file is gone, so the session cannot be collected again"
|
|
607
|
+
}`;
|
|
600
608
|
writeResult(ctx, result, [text]);
|
|
601
609
|
return EXIT.ok;
|
|
602
610
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Reports the state of the current device, project, service, index and retained sessions, with optional JSON output.
|
|
2
2
|
// Read-only; when the data directory cannot be opened it still reports the service state it can get independently.
|
|
3
|
-
import { openStore, probeStore, StoreError } from "../../../core/src/index.js";
|
|
3
|
+
import { initCreatesStore, openStore, probeStore, StoreError } from "../../../core/src/index.js";
|
|
4
4
|
import { serviceStatus } from "../../../service/src/index.js";
|
|
5
5
|
import { displayField, EXIT, parseCommandArgs, writeResult } from "../command.js";
|
|
6
6
|
import { VIEW_MAX_TIER } from "../store-access.js";
|
|
@@ -43,7 +43,7 @@ const STATUS_SCHEMA = 1;
|
|
|
43
43
|
export const statusCommand = {
|
|
44
44
|
name: "status",
|
|
45
45
|
summary: "Report the state of agent-whisker on this device: data directory, project, index and service",
|
|
46
|
-
usage: "agent-whisker status
|
|
46
|
+
usage: "agent-whisker status",
|
|
47
47
|
needsStore: false,
|
|
48
48
|
checksIntegrity: false,
|
|
49
49
|
run(ctx) {
|
|
@@ -159,7 +159,10 @@ export function lastSyncFinished(status
|
|
|
159
159
|
function textLines(report ) {
|
|
160
160
|
const row = (label , value ) => `${label.padEnd(13)}${value}`;
|
|
161
161
|
const lines = [row("home", displayField(report.home)), row("initialised", report.initialised ? "yes" : "no")];
|
|
162
|
-
if (!report.initialised)
|
|
162
|
+
if (!report.initialised) {
|
|
163
|
+
if (initCreatesStore(report.home)) lines.push("run: agent-whisker init");
|
|
164
|
+
return lines;
|
|
165
|
+
}
|
|
163
166
|
const { project, index, service } = report;
|
|
164
167
|
const projectText =
|
|
165
168
|
project === null ? "none" : project.name === "" ? project.id : `${displayField(project.name)} (${project.id})`;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// `agent-whisker tui [--page tasks|library|sessions|agents|doctor]`: the terminal interface (src/tui/). It needs an
|
|
2
|
+
// interactive terminal: Host.tty present, stdin and stdout both terminals, and TERM not `dumb`; otherwise it fails
|
|
3
|
+
// with NotATerminal before writing a byte to stdout. It opens no store itself: every read and write is one of the
|
|
4
|
+
// CLI's own commands with --json, run in this process (runCli), or taskstate's, so an idle interface holds no lock.
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { CliError, EXIT, parseCommandArgs, UsageError } from "../command.js";
|
|
7
|
+
import { CLAUDE_PLUGIN_DIR } from "../install/claude-plugin.js";
|
|
8
|
+
import { runCli } from "../run.js";
|
|
9
|
+
import { hostRunner } from "../tui/data/call.js";
|
|
10
|
+
import { PAGES, } from "../tui/model.js";
|
|
11
|
+
import { runTui } from "../tui/run.js";
|
|
12
|
+
|
|
13
|
+
/** The taskstate script of this checkout or package, run with this Node (never looked up on the PATH). */
|
|
14
|
+
const TASKSTATE_PATH = join(CLAUDE_PLUGIN_DIR, "bin", "taskstate");
|
|
15
|
+
|
|
16
|
+
/** The `tui` entry in the command table. */
|
|
17
|
+
export const tuiCommand = {
|
|
18
|
+
name: "tui",
|
|
19
|
+
summary: "Open the terminal interface: tasks, library, sessions, agents, and models and doctor",
|
|
20
|
+
usage: "agent-whisker tui [--page tasks|library|sessions|agents|doctor]",
|
|
21
|
+
needsStore: false,
|
|
22
|
+
checksIntegrity: false,
|
|
23
|
+
async run(ctx) {
|
|
24
|
+
const { values } = parseCommandArgs(ctx.args, { page: { type: "string" } }, { min: 0, max: 0 });
|
|
25
|
+
const page = PAGES.find((name) => name === (values.page ?? "tasks"));
|
|
26
|
+
if (page === undefined) throw new UsageError(`--page must be one of ${PAGES.join(", ")}`);
|
|
27
|
+
const tty = ctx.host.tty;
|
|
28
|
+
if (tty === undefined || ctx.host.env.TERM === "dumb" || !tty.isTTY())
|
|
29
|
+
throw new CliError(
|
|
30
|
+
"NotATerminal",
|
|
31
|
+
"tui needs an interactive terminal; use agent-whisker status, or taskstate show, instead",
|
|
32
|
+
);
|
|
33
|
+
const runner = hostRunner(
|
|
34
|
+
ctx.host,
|
|
35
|
+
(argv, host) =>
|
|
36
|
+
runCli(argv, host, {
|
|
37
|
+
keyStore: ctx.keyStore,
|
|
38
|
+
appModDir: ctx.appModDir,
|
|
39
|
+
...(ctx.observers ? { observers: ctx.observers } : {}),
|
|
40
|
+
}),
|
|
41
|
+
TASKSTATE_PATH,
|
|
42
|
+
ctx.cwd,
|
|
43
|
+
);
|
|
44
|
+
const code = await runTui({
|
|
45
|
+
tty,
|
|
46
|
+
runner,
|
|
47
|
+
env: ctx.host.env,
|
|
48
|
+
homeDir: ctx.host.homeDir,
|
|
49
|
+
home: ctx.home,
|
|
50
|
+
page: page ,
|
|
51
|
+
timers: {
|
|
52
|
+
setTimeout: (fn, ms) => setTimeout(fn, ms),
|
|
53
|
+
clearTimeout: (handle) => clearTimeout(handle ),
|
|
54
|
+
setInterval: (fn, ms) => setInterval(fn, ms),
|
|
55
|
+
clearInterval: (handle) => clearInterval(handle ),
|
|
56
|
+
},
|
|
57
|
+
now: () => ctx.host.now(),
|
|
58
|
+
err: (text) => ctx.host.err(text),
|
|
59
|
+
});
|
|
60
|
+
return code === 0 ? EXIT.ok : code;
|
|
61
|
+
},
|
|
62
|
+
};
|
|
@@ -7,19 +7,19 @@
|
|
|
7
7
|
// Output: text `agent-whisker <version> (node <node version>)`; with --json, `{ "version": <version>, "node": <node version> }`.
|
|
8
8
|
// Needs no data directory (needsStore is false) and touches no file. Takes no arguments; any extra is a usage error.
|
|
9
9
|
import manifest from "../../package.json" with { type: "json" };
|
|
10
|
-
import {
|
|
10
|
+
import { EXIT, parseCommandArgs, writeResult } from "../command.js";
|
|
11
11
|
|
|
12
12
|
/** The `version` entry in the command table. */
|
|
13
|
-
export const versionCommand
|
|
13
|
+
export const versionCommand = {
|
|
14
14
|
name: "version",
|
|
15
15
|
summary: "Print the version of agent-whisker and of the Node it runs on",
|
|
16
16
|
usage: "agent-whisker version",
|
|
17
17
|
needsStore: false,
|
|
18
18
|
checksIntegrity: false,
|
|
19
|
-
run(ctx) {
|
|
19
|
+
run(ctx ) {
|
|
20
20
|
parseCommandArgs(ctx.args, {}, { min: 0, max: 0 });
|
|
21
21
|
const node = ctx.host.nodeVersion;
|
|
22
22
|
writeResult(ctx, { version: manifest.version, node }, [`agent-whisker ${manifest.version} (node ${node})`]);
|
|
23
23
|
return EXIT.ok;
|
|
24
24
|
},
|
|
25
|
-
};
|
|
25
|
+
} ;
|