@agenthead/cli 0.0.0-stage → 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.
Files changed (83) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +12 -2
  3. package/THIRD_PARTY_NOTICES.md +471 -0
  4. package/bin/agenthead.js +5 -0
  5. package/dist/agents-command.d.ts +2 -0
  6. package/dist/agents-command.js +12 -0
  7. package/dist/agents-command.js.map +1 -0
  8. package/dist/claude-code-skill.d.ts +6 -0
  9. package/dist/claude-code-skill.js +88 -0
  10. package/dist/claude-code-skill.js.map +1 -0
  11. package/dist/cli.d.ts +5 -0
  12. package/dist/cli.js +199 -0
  13. package/dist/cli.js.map +1 -0
  14. package/dist/commands.d.ts +9 -0
  15. package/dist/commands.js +298 -0
  16. package/dist/commands.js.map +1 -0
  17. package/dist/context.d.ts +48 -0
  18. package/dist/context.js +37 -0
  19. package/dist/context.js.map +1 -0
  20. package/dist/doctor-command.d.ts +66 -0
  21. package/dist/doctor-command.js +323 -0
  22. package/dist/doctor-command.js.map +1 -0
  23. package/dist/doctor-probes.d.ts +44 -0
  24. package/dist/doctor-probes.js +176 -0
  25. package/dist/doctor-probes.js.map +1 -0
  26. package/dist/doctor-process.d.ts +7 -0
  27. package/dist/doctor-process.js +149 -0
  28. package/dist/doctor-process.js.map +1 -0
  29. package/dist/graph-command.d.ts +4 -0
  30. package/dist/graph-command.js +88 -0
  31. package/dist/graph-command.js.map +1 -0
  32. package/dist/hook-command.d.ts +2 -0
  33. package/dist/hook-command.js +256 -0
  34. package/dist/hook-command.js.map +1 -0
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.js +2 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/ledger-command.d.ts +2 -0
  39. package/dist/ledger-command.js +269 -0
  40. package/dist/ledger-command.js.map +1 -0
  41. package/dist/ledger.d.ts +19 -0
  42. package/dist/ledger.js +47 -0
  43. package/dist/ledger.js.map +1 -0
  44. package/dist/memory-command.d.ts +4 -0
  45. package/dist/memory-command.js +231 -0
  46. package/dist/memory-command.js.map +1 -0
  47. package/dist/pack-adapter.d.ts +14 -0
  48. package/dist/pack-adapter.js +39 -0
  49. package/dist/pack-adapter.js.map +1 -0
  50. package/dist/parallel-command.d.ts +2 -0
  51. package/dist/parallel-command.js +129 -0
  52. package/dist/parallel-command.js.map +1 -0
  53. package/dist/route-command.d.ts +2 -0
  54. package/dist/route-command.js +54 -0
  55. package/dist/route-command.js.map +1 -0
  56. package/dist/run-command.d.ts +6 -0
  57. package/dist/run-command.js +91 -0
  58. package/dist/run-command.js.map +1 -0
  59. package/dist/security-command.d.ts +2 -0
  60. package/dist/security-command.js +203 -0
  61. package/dist/security-command.js.map +1 -0
  62. package/dist/security-confirmation.d.ts +2 -0
  63. package/dist/security-confirmation.js +53 -0
  64. package/dist/security-confirmation.js.map +1 -0
  65. package/dist/setup-auto-command.d.ts +6 -0
  66. package/dist/setup-auto-command.js +113 -0
  67. package/dist/setup-auto-command.js.map +1 -0
  68. package/dist/setup-command.d.ts +25 -0
  69. package/dist/setup-command.js +398 -0
  70. package/dist/setup-command.js.map +1 -0
  71. package/dist/setup-guidance-hashes.d.ts +6 -0
  72. package/dist/setup-guidance-hashes.js +45 -0
  73. package/dist/setup-guidance-hashes.js.map +1 -0
  74. package/dist/setup-instructions.d.ts +5 -0
  75. package/dist/setup-instructions.js +76 -0
  76. package/dist/setup-instructions.js.map +1 -0
  77. package/dist/setup-toml.d.ts +4 -0
  78. package/dist/setup-toml.js +302 -0
  79. package/dist/setup-toml.js.map +1 -0
  80. package/dist/version.d.ts +1 -0
  81. package/dist/version.js +3 -0
  82. package/dist/version.js.map +1 -0
  83. package/package.json +55 -4
@@ -0,0 +1,7 @@
1
+ export interface McpLaunch {
2
+ command: string;
3
+ args: string[];
4
+ env?: NodeJS.ProcessEnv;
5
+ }
6
+ /** Bounded stdio probes. Never echo server output: it may contain credentials. */
7
+ export declare function probeProcess(launch: McpLaunch, cwd: string, mode: "version" | "mcp", timeoutMs?: number): Promise<string>;
@@ -0,0 +1,149 @@
1
+ import { spawn } from "node:child_process";
2
+ import { readFileSync, statSync } from "node:fs";
3
+ import { basename, dirname, join, resolve } from "node:path";
4
+ import { killProcessGroup } from "@agenthead/conductor";
5
+ import { version } from "./version.js";
6
+ /** npm's Windows shims need cmd.exe; resolve their declared JS bin instead of using a shell. */
7
+ function probeLaunch(launch, cwd) {
8
+ if (!/\.(?:cmd|bat)$/i.test(launch.command))
9
+ return launch;
10
+ try {
11
+ const name = basename(launch.command).replace(/\.(?:cmd|bat)$/i, "");
12
+ const packageName = name === "agenthead"
13
+ ? "@agenthead/cli"
14
+ : name === "agenthead-mcp"
15
+ ? "@agenthead/mcp"
16
+ : undefined;
17
+ if (!packageName)
18
+ throw new Error();
19
+ const shim = resolve(cwd, launch.command);
20
+ const text = readFileSync(shim, "utf8");
21
+ const target = /"%dp0%[\\/]([^"\r\n]+\.js)"\s+%\*/i.exec(text)?.[1];
22
+ if (!target)
23
+ throw new Error();
24
+ const script = resolve(dirname(shim), target.replaceAll("\\", "/"));
25
+ const packageRoot = dirname(dirname(script));
26
+ const manifest = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
27
+ if (manifest.name !== packageName ||
28
+ typeof manifest.bin?.[name] !== "string" ||
29
+ resolve(packageRoot, manifest.bin[name]) !== script)
30
+ throw new Error();
31
+ const localNode = join(dirname(shim), "node.exe");
32
+ return {
33
+ ...launch,
34
+ command: statSync(localNode, { throwIfNoEntry: false })?.isFile()
35
+ ? localNode
36
+ : "node",
37
+ args: [script, ...launch.args],
38
+ };
39
+ }
40
+ catch {
41
+ throw new Error("Cannot resolve npm launcher; reinstall the matching CLI/MCP tarballs");
42
+ }
43
+ }
44
+ /** Bounded stdio probes. Never echo server output: it may contain credentials. */
45
+ export function probeProcess(launch, cwd, mode, timeoutMs = 5000) {
46
+ return new Promise((resolve, reject) => {
47
+ const executable = probeLaunch(launch, cwd);
48
+ const child = spawn(executable.command, executable.args, {
49
+ cwd,
50
+ env: { ...process.env, ...launch.env, AGENTHEAD_LSP: "off" },
51
+ stdio: ["pipe", "pipe", "pipe"],
52
+ detached: true,
53
+ });
54
+ let settled = false;
55
+ let output = "";
56
+ let bytes = 0;
57
+ let stage = "initialize";
58
+ const finish = (error, value = "") => {
59
+ if (settled)
60
+ return;
61
+ settled = true;
62
+ clearTimeout(timer);
63
+ child.stdin.destroy();
64
+ killProcessGroup(child);
65
+ // Wait for the child and its pipes to close before returning to the caller.
66
+ child.once("close", () => error ? reject(new Error(error)) : resolve(value));
67
+ };
68
+ const timer = setTimeout(() => finish(`${mode} probe timed out`), timeoutMs);
69
+ child.on("error", () => finish(`${mode} executable could not start`));
70
+ child.stdin.on("error", () => finish(`${mode} stdin closed`));
71
+ child.stderr.on("data", () => {
72
+ /* Drain, never disclose. */
73
+ });
74
+ child.on("close", () => {
75
+ if (!settled) {
76
+ settled = true;
77
+ clearTimeout(timer);
78
+ if (mode === "version" &&
79
+ child.exitCode === 0 &&
80
+ /^\d+\.\d+\.\d+(?:-[\w.-]+)?\s*$/.test(output))
81
+ resolve(output.trim());
82
+ else
83
+ reject(new Error(`${mode} process exited before a valid response`));
84
+ }
85
+ });
86
+ const send = (value) => child.stdin.write(JSON.stringify(value) + "\n");
87
+ child.stdout.setEncoding("utf8");
88
+ child.stdout.on("data", (chunk) => {
89
+ bytes += Buffer.byteLength(chunk);
90
+ if (bytes > 1024 * 1024)
91
+ return finish(`${mode} output exceeded 1 MiB`);
92
+ output += chunk;
93
+ if (mode === "version")
94
+ return;
95
+ let newline;
96
+ while (!settled && (newline = output.indexOf("\n")) >= 0) {
97
+ const line = output.slice(0, newline);
98
+ output = output.slice(newline + 1);
99
+ try {
100
+ const message = JSON.parse(line);
101
+ if (message.jsonrpc !== "2.0")
102
+ throw new Error();
103
+ if (message.id !== (stage === "initialize" ? 1 : 2))
104
+ continue;
105
+ const result = message.result;
106
+ if (message.error || !result || typeof result !== "object")
107
+ throw new Error();
108
+ if (stage === "initialize") {
109
+ const info = result.serverInfo;
110
+ if (!info ||
111
+ info.name !== "agenthead" ||
112
+ info.version !== version ||
113
+ result.protocolVersion !== "2024-11-05" ||
114
+ !result.capabilities ||
115
+ typeof result.capabilities !== "object")
116
+ throw new Error();
117
+ stage = "tools/list";
118
+ send({ jsonrpc: "2.0", method: "notifications/initialized" });
119
+ send({ jsonrpc: "2.0", id: 2, method: "tools/list", params: {} });
120
+ }
121
+ else {
122
+ const tools = result.tools;
123
+ if (!Array.isArray(tools) ||
124
+ !["pack", "search"].every((name) => tools.some((tool) => tool?.name === name)))
125
+ throw new Error();
126
+ finish(undefined, "initialize and tools/list succeeded");
127
+ }
128
+ }
129
+ catch {
130
+ finish(`Invalid MCP ${stage} response`);
131
+ }
132
+ }
133
+ });
134
+ if (mode === "version")
135
+ child.stdin.end();
136
+ else
137
+ send({
138
+ jsonrpc: "2.0",
139
+ id: 1,
140
+ method: "initialize",
141
+ params: {
142
+ protocolVersion: "2024-11-05",
143
+ capabilities: {},
144
+ clientInfo: { name: "agenthead-doctor", version: "1" },
145
+ },
146
+ });
147
+ });
148
+ }
149
+ //# sourceMappingURL=doctor-process.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doctor-process.js","sourceRoot":"","sources":["../src/doctor-process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAQvC,gGAAgG;AAChG,SAAS,WAAW,CAAC,MAAiB,EAAE,GAAW;IACjD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAA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CAAC,CAAC,CAAC;QACH,IAAI,IAAI,KAAK,SAAS;YAAE,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;;YAExC,IAAI,CAAC;gBACH,OAAO,EAAE,KAAK;gBACd,EAAE,EAAE,CAAC;gBACL,MAAM,EAAE,YAAY;gBACpB,MAAM,EAAE;oBACN,eAAe,EAAE,YAAY;oBAC7B,YAAY,EAAE,EAAE;oBAChB,UAAU,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,GAAG,EAAE;iBACvD;aACF,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type Context } from "./context.js";
2
+ export declare function graph(args: string[], ctx: Context): Promise<void>;
3
+ export declare function definitions(args: string[], ctx: Context): Promise<void>;
4
+ export declare function references(args: string[], ctx: Context): Promise<void>;
@@ -0,0 +1,88 @@
1
+ import { GraphStore } from "@agenthead/graph";
2
+ import { LspBridge, lspOptionsFromEnv, } from "@agenthead/graph/lsp";
3
+ import { UsageError, emit, parse } from "./context.js";
4
+ const reasons = {
5
+ disabled: "language servers are off; AGENTHEAD_LSP=on turns them on",
6
+ unavailable: "no language server was available",
7
+ timeout: "the language server did not answer in time",
8
+ crashed: "the language server stopped",
9
+ error: "the language server returned an error",
10
+ };
11
+ function describeIndex(report) {
12
+ const lines = [
13
+ `Indexed ${report.totalFiles} file${report.totalFiles === 1 ? "" : "s"}: ` +
14
+ `${report.parsedFiles} parsed, ${report.reusedFiles} reused, ${report.removedFiles} removed.`,
15
+ ];
16
+ if (report.filesWithErrors.length > 0)
17
+ lines.push(`Files with errors: ${report.filesWithErrors.join(", ")}`);
18
+ return lines.join("\n");
19
+ }
20
+ async function index(args, ctx) {
21
+ const { values, positionals } = parse(args, {});
22
+ if (positionals.length > 0)
23
+ throw new UsageError("agenthead graph index takes no arguments");
24
+ const graph = new GraphStore(ctx.cwd);
25
+ try {
26
+ const report = await graph.index();
27
+ emit(ctx, values.json, report, describeIndex(report));
28
+ }
29
+ finally {
30
+ graph.close();
31
+ }
32
+ }
33
+ export async function graph(args, ctx) {
34
+ const [name, ...rest] = args;
35
+ if (name === undefined || name.startsWith("-"))
36
+ throw new UsageError("Missing graph subcommand: index");
37
+ if (name !== "index")
38
+ throw new UsageError(`Unknown graph subcommand ${JSON.stringify(name)}; expected index`);
39
+ await index(rest, ctx);
40
+ }
41
+ /** `<file>:<line>:<column>`, split at the last two colons. */
42
+ function position(positionals, command) {
43
+ const [value, ...extra] = positionals;
44
+ const match = value !== undefined && extra.length === 0
45
+ ? /^(.+):([1-9]\d*):([1-9]\d*)$/.exec(value)
46
+ : null;
47
+ const [line, column] = [Number(match?.[2]), Number(match?.[3])];
48
+ if (!match || !(line < 2 ** 31) || !(column < 2 ** 31))
49
+ throw new UsageError(`agenthead ${command} takes one position: <file>:<line>:<column>, one-based`);
50
+ return { file: match[1], line, column };
51
+ }
52
+ function describeResult(kind, result) {
53
+ const lines = result.locations.map(({ file, line, column }) => `${file}:${line}:${column}`);
54
+ if (lines.length === 0)
55
+ lines.push(`No ${kind} found.`);
56
+ lines.push(result.source === "lsp"
57
+ ? "Source: language server"
58
+ : `Source: graph name matches (${reasons[result.reason]})`);
59
+ return lines.join("\n");
60
+ }
61
+ /** Index the graph, so it is current, then ask the bridge. */
62
+ async function navigate(kind, args, ctx) {
63
+ const { values, positionals } = parse(args, {});
64
+ const at = position(positionals, kind);
65
+ const options = lspOptionsFromEnv();
66
+ const graph = new GraphStore(ctx.cwd);
67
+ try {
68
+ await graph.index();
69
+ const lsp = new LspBridge(graph, options);
70
+ try {
71
+ const result = await lsp[kind](at);
72
+ emit(ctx, values.json, result, describeResult(kind, result));
73
+ }
74
+ finally {
75
+ await lsp.close();
76
+ }
77
+ }
78
+ finally {
79
+ graph.close();
80
+ }
81
+ }
82
+ export function definitions(args, ctx) {
83
+ return navigate("definitions", args, ctx);
84
+ }
85
+ export function references(args, ctx) {
86
+ return navigate("references", args, ctx);
87
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C,KAAK,EAAE,CAAC;QACpB,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;YACnC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC/D,CAAC;gBAAS,CAAC;YACT,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAc,EAAE,GAAY;IACtD,OAAO,QAAQ,CAAC,aAAa,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAc,EAAE,GAAY;IACrD,OAAO,QAAQ,CAAC,YAAY,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { type Context } from "./context.js";
2
+ export declare function hook(args: string[], ctx: Context): Promise<void>;
@@ -0,0 +1,256 @@
1
+ import process from "node:process";
2
+ import { closeSync, constants, fstatSync, openSync, readSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+ import { StringDecoder } from "node:string_decoder";
5
+ import { resolveProjectRoot } from "@agenthead/core";
6
+ import { readStdin } from "./commands.js";
7
+ import { CommandError, openStore, parse } from "./context.js";
8
+ const producer = "claude-code";
9
+ function isRecord(value) {
10
+ return typeof value === "object" && value !== null && !Array.isArray(value);
11
+ }
12
+ async function readInput(ctx) {
13
+ if (ctx.stdin.isTTY)
14
+ return {};
15
+ const text = (await readStdin(ctx)).toString("utf8");
16
+ if (!text.trim())
17
+ return {};
18
+ let value;
19
+ try {
20
+ value = JSON.parse(text);
21
+ }
22
+ catch {
23
+ // The parser's message quotes the input, which may hold secrets.
24
+ throw new Error("hook input is not valid JSON");
25
+ }
26
+ if (!isRecord(value))
27
+ throw new Error("hook input is not a JSON object");
28
+ return value;
29
+ }
30
+ /**
31
+ * Claude Code's own lines in a failure that say the output is incomplete: it
32
+ * cut long output out of the middle, or the command timed out or was killed.
33
+ */
34
+ const truncated = /\[\d+ characters truncated\]/;
35
+ const incomplete = /Command timed out after|Command killed:|output may be cut short|Command running in background with ID:/;
36
+ const persistedOutputLimit = 32 * 1024 * 1024;
37
+ /** Saved command output can live outside the project, in Claude Code's temp directory. */
38
+ function persistedOutput(path, cwd) {
39
+ let fd;
40
+ try {
41
+ // Refuse links and special files, including FIFOs that could stall the hook.
42
+ fd = openSync(resolve(cwd, path), constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
43
+ const stat = fstatSync(fd);
44
+ if (!stat.isFile())
45
+ return undefined;
46
+ const buffer = Buffer.alloc(Math.min(stat.size, persistedOutputLimit));
47
+ let length = 0;
48
+ while (length < buffer.length) {
49
+ const read = readSync(fd, buffer, length, buffer.length - length, null);
50
+ if (read === 0)
51
+ break;
52
+ length += read;
53
+ }
54
+ const decoder = new StringDecoder("utf8");
55
+ // Keep an incomplete UTF-8 character buffered when the byte cap cuts it off.
56
+ const output = decoder.write(buffer.subarray(0, length));
57
+ return stat.size > persistedOutputLimit
58
+ ? output + "\n[AgentHead: persisted output truncated at 32 MiB]\n"
59
+ : output + decoder.end();
60
+ }
61
+ catch {
62
+ // Missing/unreadable output is not evidence; never echo its path or contents.
63
+ return undefined;
64
+ }
65
+ finally {
66
+ if (fd !== undefined)
67
+ closeSync(fd);
68
+ }
69
+ }
70
+ /** "Exit code N" then the output, as Claude Code reports a failed command. */
71
+ function failedRun(command, text) {
72
+ const match = /^(?:Error: )?Exit code (-?\d+)(?:\r?\n|$)/.exec(text);
73
+ // Without the line, the shell never started: there is no command output.
74
+ if (!match || truncated.test(text) || incomplete.test(text))
75
+ return undefined;
76
+ return {
77
+ command,
78
+ exitCode: Number(match[1]),
79
+ output: text.slice(match[0].length),
80
+ };
81
+ }
82
+ /** The Bash command, exit code and output in a hook event, when all are known. */
83
+ function bashRun(input, cwd) {
84
+ if (input["tool_name"] !== "Bash")
85
+ return undefined;
86
+ const toolInput = input["tool_input"];
87
+ const command = isRecord(toolInput) ? toolInput["command"] : undefined;
88
+ if (typeof command !== "string" || !command.trim())
89
+ return undefined;
90
+ if (input["hook_event_name"] === "PostToolUseFailure") {
91
+ const error = input["error"];
92
+ if (input["is_interrupt"] === true || typeof error !== "string") {
93
+ return undefined;
94
+ }
95
+ return failedRun(command, error);
96
+ }
97
+ if (input["hook_event_name"] !== "PostToolUse")
98
+ return undefined;
99
+ const response = input["tool_response"];
100
+ // A failed call can reach PostToolUse as the error text.
101
+ if (typeof response === "string")
102
+ return failedRun(command, response);
103
+ if (!isRecord(response))
104
+ return undefined;
105
+ // Success means exit code 0 unless one of these says otherwise. Claude Code
106
+ // treats some non-zero codes as success (grep with no match), and a timed
107
+ // out, interrupted or backgrounded run has no exit code yet. Output it saved
108
+ // to a file reaches the hook cut down; read that file rather than its preview.
109
+ if (response["interrupted"] === true ||
110
+ response["isImage"] === true ||
111
+ response["returnCodeInterpretation"] !== undefined ||
112
+ response["timedOutAfterMs"] !== undefined ||
113
+ response["backgroundTaskId"] !== undefined ||
114
+ (isRecord(toolInput) && toolInput["run_in_background"] === true)) {
115
+ return undefined;
116
+ }
117
+ // The command's stdout and stderr both arrive in stdout. Claude Code's own
118
+ // notes, such as a reset working directory, arrive in stderr.
119
+ let output = response["stdout"];
120
+ // These fields are not part of the documented hook contract. Check Claude
121
+ // Code's markers too, including notes it may put in stderr.
122
+ for (const text of [output, response["stderr"]]) {
123
+ if (typeof text === "string" &&
124
+ (incomplete.test(text) ||
125
+ (response["persistedOutputPath"] === undefined && truncated.test(text))))
126
+ return undefined;
127
+ }
128
+ const path = response["persistedOutputPath"];
129
+ if (path !== undefined) {
130
+ if (typeof path !== "string" || !path.trim())
131
+ return undefined;
132
+ output = persistedOutput(path, cwd);
133
+ }
134
+ if (typeof output !== "string" ||
135
+ truncated.test(output) ||
136
+ incomplete.test(output))
137
+ return undefined;
138
+ if (/^(?:Error: )?Exit code -?\d+(?:\r?\n|$)/.test(output)) {
139
+ // stdout can imitate a failure marker; it is not an exit status.
140
+ return undefined;
141
+ }
142
+ return { command, exitCode: 0, output };
143
+ }
144
+ /** The directory the session started in; a Bash `cd` can move the hook's cwd. */
145
+ function projectRoot(ctx) {
146
+ return resolveProjectRoot(undefined, process.env["CLAUDE_PROJECT_DIR"] || ctx.cwd);
147
+ }
148
+ function postTool(input, ctx, task) {
149
+ const run = bashRun(input, ctx.cwd);
150
+ if (!run?.output.trim())
151
+ return;
152
+ const store = openStore({ ...ctx, cwd: projectRoot(ctx) });
153
+ try {
154
+ // The store filters secrets out of the output and the command before
155
+ // anything reaches the disk.
156
+ store.put({
157
+ kind: "tool_output",
158
+ raw: Buffer.from(run.output, "utf8"),
159
+ source: {
160
+ type: "command",
161
+ command: run.command,
162
+ exit_code: run.exitCode,
163
+ },
164
+ provenance: "executed",
165
+ produced_by: producer,
166
+ task_id: task ?? producer,
167
+ });
168
+ }
169
+ finally {
170
+ store.close();
171
+ }
172
+ }
173
+ /**
174
+ * Why the task is not verified. Hook output skips the MCP envelope, so this
175
+ * names ledger entries by id and quotes none of their stored text: check
176
+ * commands and claims stay behind ledger_status.
177
+ */
178
+ function whyNotVerified(status) {
179
+ const lines = [];
180
+ if (status.changes === 0)
181
+ lines.push("no change recorded");
182
+ if (status.checks.length === 0) {
183
+ lines.push(status.changes === 0
184
+ ? "no executed check recorded"
185
+ : "no executed check recorded after the last change");
186
+ }
187
+ const ids = (entries) => entries.map((entry) => `#${entry.id}`).join(", ");
188
+ const failing = status.checks.filter((check) => !check.passed);
189
+ if (failing.length > 0)
190
+ lines.push(`failing checks: ${ids(failing)}`);
191
+ if (status.unverified_claims.length > 0) {
192
+ lines.push(`unverified claims: ${ids(status.unverified_claims)}`);
193
+ }
194
+ return lines;
195
+ }
196
+ function blockReason(status) {
197
+ return [
198
+ `AgentHead: task ${status.task_id} is not verified.`,
199
+ ...whyNotVerified(status).map((line) => `- ${line}`),
200
+ "See ledger_status for the details. Record the change and the checks you ran with the " +
201
+ "agenthead ledger_record tool, then confirm with ledger_status. If it cannot be verified " +
202
+ "now, say what is still unverified.",
203
+ ].join("\n");
204
+ }
205
+ function stop(input, ctx, task) {
206
+ const store = openStore({ ...ctx, cwd: projectRoot(ctx) });
207
+ let status;
208
+ try {
209
+ status = store.taskStatus(task);
210
+ }
211
+ finally {
212
+ store.close();
213
+ }
214
+ if (status.verified)
215
+ return;
216
+ // Block once. If Claude is already continuing because of a stop hook, let
217
+ // it stop and tell the user, rather than loop on something it cannot fix.
218
+ const output = input["stop_hook_active"] === true
219
+ ? {
220
+ systemMessage: `AgentHead: task ${status.task_id} is still not verified (${whyNotVerified(status).join("; ")}).`,
221
+ }
222
+ : { decision: "block", reason: blockReason(status) };
223
+ ctx.stdout.write(JSON.stringify(output) + "\n");
224
+ }
225
+ export async function hook(args, ctx) {
226
+ let parsed;
227
+ try {
228
+ parsed = parse(args, { task: { type: "string" } });
229
+ }
230
+ catch (error) {
231
+ throw new CommandError(error.message);
232
+ }
233
+ const [name, ...extra] = parsed.positionals;
234
+ if ((name !== "post-tool" && name !== "stop") || extra.length > 0) {
235
+ throw new CommandError("agenthead hook takes one hook: post-tool or stop");
236
+ }
237
+ const task = parsed.values.task?.trim() || process.env["AGENTHEAD_TASK"]?.trim() || "";
238
+ try {
239
+ if (name === "stop" && !task) {
240
+ // No task to check: drain stdin and let Claude stop.
241
+ if (!ctx.stdin.isTTY)
242
+ await readStdin(ctx);
243
+ return;
244
+ }
245
+ const input = await readInput(ctx);
246
+ if (name === "post-tool")
247
+ postTool(input, ctx, task || undefined);
248
+ else
249
+ stop(input, ctx, task);
250
+ }
251
+ catch (error) {
252
+ const message = error instanceof Error ? error.message : String(error);
253
+ ctx.stderr.write(`agenthead hook ${name}: ${message}; continuing\n`);
254
+ }
255
+ }
256
+ //# sourceMappingURL=hook-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook-command.js","sourceRoot":"","sources":["../src/hook-command.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAmB,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,KAAK,EAAgB,MAAM,cAAc,CAAC;AAgB5E,MAAM,QAAQ,GAAG,aAAa,CAAC;AAE/B,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,GAAY;IACnC,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IAC/B,MAAM,IAAI,GAAG,CAAC,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACrD,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC;IAC5B,IAAI,KAAc,CAAC;IACnB,IAAI,CAAC;QACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,iEAAiE;QACjE,MAAM,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GAAG,CAAC,CAAC;YAC3C,OAAO;QACT,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,IAAI,KAAK,WAAW;YAAE,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,IAAI,SAAS,CAAC,CAAC;;YAC7D,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,OAAO,gBAAgB,CAAC,CAAC;IACvE,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const packageName = "@agenthead/cli";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export const packageName = "@agenthead/cli";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { type Context } from "./context.js";
2
+ export declare function ledger(args: string[], ctx: Context): Promise<void>;