@agenthead/cli 0.0.0-stage → 0.3.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 (101) 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 +91 -0
  10. package/dist/claude-code-skill.js.map +1 -0
  11. package/dist/cli.d.ts +5 -0
  12. package/dist/cli.js +221 -0
  13. package/dist/cli.js.map +1 -0
  14. package/dist/codex-trust.d.ts +3 -0
  15. package/dist/codex-trust.js +19 -0
  16. package/dist/codex-trust.js.map +1 -0
  17. package/dist/commands.d.ts +9 -0
  18. package/dist/commands.js +275 -0
  19. package/dist/commands.js.map +1 -0
  20. package/dist/context.d.ts +50 -0
  21. package/dist/context.js +37 -0
  22. package/dist/context.js.map +1 -0
  23. package/dist/diagram-command.d.ts +2 -0
  24. package/dist/diagram-command.js +73 -0
  25. package/dist/diagram-command.js.map +1 -0
  26. package/dist/doctor-command.d.ts +67 -0
  27. package/dist/doctor-command.js +329 -0
  28. package/dist/doctor-command.js.map +1 -0
  29. package/dist/doctor-probes.d.ts +46 -0
  30. package/dist/doctor-probes.js +206 -0
  31. package/dist/doctor-probes.js.map +1 -0
  32. package/dist/doctor-process.d.ts +8 -0
  33. package/dist/doctor-process.js +149 -0
  34. package/dist/doctor-process.js.map +1 -0
  35. package/dist/graph-command.d.ts +4 -0
  36. package/dist/graph-command.js +88 -0
  37. package/dist/graph-command.js.map +1 -0
  38. package/dist/hook-command.d.ts +2 -0
  39. package/dist/hook-command.js +259 -0
  40. package/dist/hook-command.js.map +1 -0
  41. package/dist/index.d.ts +1 -0
  42. package/dist/index.js +2 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/ledger-command.d.ts +2 -0
  45. package/dist/ledger-command.js +269 -0
  46. package/dist/ledger-command.js.map +1 -0
  47. package/dist/ledger.d.ts +19 -0
  48. package/dist/ledger.js +47 -0
  49. package/dist/ledger.js.map +1 -0
  50. package/dist/mcp-command.d.ts +2 -0
  51. package/dist/mcp-command.js +9 -0
  52. package/dist/mcp-command.js.map +1 -0
  53. package/dist/memory-command.d.ts +4 -0
  54. package/dist/memory-command.js +231 -0
  55. package/dist/memory-command.js.map +1 -0
  56. package/dist/pack-adapter.d.ts +14 -0
  57. package/dist/pack-adapter.js +39 -0
  58. package/dist/pack-adapter.js.map +1 -0
  59. package/dist/parallel-command.d.ts +2 -0
  60. package/dist/parallel-command.js +129 -0
  61. package/dist/parallel-command.js.map +1 -0
  62. package/dist/route-command.d.ts +2 -0
  63. package/dist/route-command.js +76 -0
  64. package/dist/route-command.js.map +1 -0
  65. package/dist/route-learn-command.d.ts +9 -0
  66. package/dist/route-learn-command.js +114 -0
  67. package/dist/route-learn-command.js.map +1 -0
  68. package/dist/run-command.d.ts +6 -0
  69. package/dist/run-command.js +128 -0
  70. package/dist/run-command.js.map +1 -0
  71. package/dist/security-command.d.ts +2 -0
  72. package/dist/security-command.js +234 -0
  73. package/dist/security-command.js.map +1 -0
  74. package/dist/security-confirmation.d.ts +2 -0
  75. package/dist/security-confirmation.js +53 -0
  76. package/dist/security-confirmation.js.map +1 -0
  77. package/dist/setup-auto-command.d.ts +25 -0
  78. package/dist/setup-auto-command.js +147 -0
  79. package/dist/setup-auto-command.js.map +1 -0
  80. package/dist/setup-command.d.ts +27 -0
  81. package/dist/setup-command.js +535 -0
  82. package/dist/setup-command.js.map +1 -0
  83. package/dist/setup-consent.d.ts +3 -0
  84. package/dist/setup-consent.js +14 -0
  85. package/dist/setup-consent.js.map +1 -0
  86. package/dist/setup-guidance-hashes.d.ts +6 -0
  87. package/dist/setup-guidance-hashes.js +48 -0
  88. package/dist/setup-guidance-hashes.js.map +1 -0
  89. package/dist/setup-instructions.d.ts +5 -0
  90. package/dist/setup-instructions.js +76 -0
  91. package/dist/setup-instructions.js.map +1 -0
  92. package/dist/setup-toml.d.ts +6 -0
  93. package/dist/setup-toml.js +318 -0
  94. package/dist/setup-toml.js.map +1 -0
  95. package/dist/start-command.d.ts +2 -0
  96. package/dist/start-command.js +99 -0
  97. package/dist/start-command.js.map +1 -0
  98. package/dist/version.d.ts +1 -0
  99. package/dist/version.js +3 -0
  100. package/dist/version.js.map +1 -0
  101. package/package.json +55 -4
package/dist/cli.js ADDED
@@ -0,0 +1,221 @@
1
+ import process from "node:process";
2
+ import { agents } from "./agents-command.js";
3
+ import { UsageError } from "./context.js";
4
+ import { ingest, init, pack, recover, stats } from "./commands.js";
5
+ import { definitions, graph, references } from "./graph-command.js";
6
+ import { hook } from "./hook-command.js";
7
+ import { ledger } from "./ledger-command.js";
8
+ import { decision, links, task } from "./memory-command.js";
9
+ import { setup } from "./setup-command.js";
10
+ import { route } from "./route-command.js";
11
+ import { conductorRun } from "./run-command.js";
12
+ import { security } from "./security-command.js";
13
+ import { parallel } from "./parallel-command.js";
14
+ import { doctor } from "./doctor-command.js";
15
+ import { diagram } from "./diagram-command.js";
16
+ import { version } from "./version.js";
17
+ import { start } from "./start-command.js";
18
+ export const help = `Usage: agenthead <command> [options]
19
+
20
+ start [--yes] [--dry-run] Preview detected clients and storage, confirm, then set up and run doctor
21
+ security scope init | show Initialize or view defensive security scope
22
+ security scan Run installed static security scanners (--tools a,b)
23
+ security findings List recorded findings (--severity high)
24
+ security sbom Store a Syft CycloneDX SBOM as evidence
25
+ security verify-artifact <file> Offline cosign verification (--bundle, --identity, --issuer; optional --attestation)
26
+ security show <finding-id-or-fingerprint> Show a finding and its evidence recovery handle
27
+ security ingest <report.sarif> Archive and ingest a scoped SARIF report
28
+ security suppress <finding-id> Propose suppression (--reason required)
29
+ security audit List append-only security audit events
30
+ security approve <request-id> Review and confirm a code on /dev/tty; stdin/stdout must be TTYs
31
+ security deny <request-id> Revoke with confirmation on /dev/tty; stdin/stdout must be TTYs
32
+ security fix <finding-id> Verify a patch; --approve consumes prior TTY authorisation
33
+ agents List installed coding agents and local login status
34
+ doctor [--fix] Check installation, clients, MCP, graph and routing
35
+ init Create .agenthead/ in the current directory
36
+ ingest <file | -> Store a file, or piped output, as evidence.
37
+ Secrets are redacted first. Piped input is a
38
+ tool_output; a file is a source.
39
+ Binary evidence is not searchable or packed;
40
+ recover it by the returned handle.
41
+ --kind <kind> Override the evidence kind
42
+ pack --task "<text>" [--budget <tokens>] [--edit-context]
43
+ Print the evidence for a task within a token budget.
44
+ The budget counts evidence text only, not the task,
45
+ the headers or the omission notes. Without --budget,
46
+ AgentHead sizes it from the evidence (1,000 to 4,000
47
+ tokens), and prints no pack when the matches are
48
+ all files under 6,000 tokens in total, or when all
49
+ it would keep in full is files the task names.
50
+ --edit-context leads with pinned failures and
51
+ source files with their recorded line ranges.
52
+ recover <handle> Print the original behind a recovery handle
53
+ stats Store size, records by kind, recoveries, tokens saved
54
+ route "<task>" [--size <size>] [--risk <risk>]
55
+ route learn --from <report.json>... [--tolerance <0..1>] [--min-samples <n>] [--dry-run]
56
+ route explain "<task>"
57
+ Explain plan, implement and independent verify choices
58
+ and fallbacks. Sizes: tiny, small, medium, large;
59
+ risks: low, medium, high. Uses .agenthead/routing.json
60
+ overrides; never runs an agent or calls a model
61
+ run "<task>" Plan, implement and independently verify a task
62
+ --budget-tokens <tokens> Uncached input plus output budget (default 2000000)
63
+ --plan-timeout <seconds> Per planner call (default 300; routing config may override)
64
+ --implement-timeout <seconds> Per implementer call (default 300)
65
+ --verify-timeout <seconds> Per verifier call (default 900)
66
+ --pricing <file> Model-keyed USD/million rates for estimated JSON cost
67
+ --quota-cooldown <minutes> Agent cooldown after rate/quota errors (default 5)
68
+ --experimental-devin Enable the Devin remote API adapter (DEVIN_API_KEY)
69
+ --max-rounds <0|1|2> Fix rounds after implementation (default 2)
70
+ --agents <module> Override native adapters with a trusted local module;
71
+ AGENTHEAD_AGENTS_MODULE also sets it. See docs/conductor-run.md.
72
+ parallel <plan.json> Run independent parts in isolated git worktrees,
73
+ then merge serially. See docs/conductor-parallel.md.
74
+ ledger add <kind> --task <id> ... Record a fact, inference, change, check or claim for
75
+ a task. Secrets are redacted first.
76
+ fact | inference | claim --text <t> (a claim may take --check <id>, repeatable)
77
+ change --diff-file <path|-> or --diff-hash <h> --handle <handle>
78
+ check --command <c> --exit-code <n>
79
+ --output-file <path|-> or --output-hash <h> [--handle <handle>]
80
+ --provenance <observed|inferred|executed|reported> Default by kind; only an executed
81
+ check can verify a task
82
+ ledger show --task <id> List a task's ledger entries
83
+ ledger status --task <id> [--require] Verified only if the task has a change and every
84
+ command run since the last change last passed;
85
+ otherwise says why and lists unverified claims.
86
+ Exits 0 either way; --require exits 1 when the
87
+ task is not verified. A claim counts as backed
88
+ only by the latest run of its command
89
+ decision add "<title>" Record a project decision
90
+ --body <text> --status <proposed|accepted|rejected> (default accepted)
91
+ --supersedes <id> Replace an earlier decision, such as D1
92
+ --link <evidence-id> Evidence in this project (repeatable)
93
+ decision list [--status <status>] Decisions, oldest first; a replaced one is superseded
94
+ decision show <id> One decision in full
95
+ task add "<title>" Record a task: --notes <text>, --link <evidence-id>
96
+ --status <open|in_progress|blocked|done|cancelled> (default open)
97
+ task list [--status <status>] Tasks with their notes and links, oldest first
98
+ task update <id> Replace --title, --status or --notes; --link adds
99
+ Decisions and tasks never store credentials or model
100
+ reasoning: text that looks like either is refused.
101
+ links citing <evidence-id> Decisions and tasks that link to the evidence, even
102
+ evidence the store no longer holds
103
+ links stale Links whose evidence is stale (its file changed) or
104
+ missing from the store
105
+ diagram modules File dependencies grouped by directory
106
+ diagram impact <target> Dependencies and dependents of a path or symbol
107
+ diagram overview Top-level directories and their cached exports
108
+ --format <mermaid|svg|html> Render the existing code graph (default mermaid)
109
+ --depth <n> --max-nodes <n> Impact depth (default 2); cluster to node cap (default 80)
110
+ --out <file> --evidence Write a file; optionally annotate stored evidence counts
111
+ --symbols Include impact declarations within the node budget
112
+ graph index Build or update the code graph in .agenthead/graph.db,
113
+ which pack also uses for ranking
114
+ definitions <file>:<line>:<column> Where the symbol at a position is declared
115
+ references <file>:<line>:<column> Uses of the symbol at a position, without its
116
+ declaration. Both update the graph first and answer
117
+ from name matches in it, and say which source
118
+ answered. With AGENTHEAD_LSP=on they first ask an
119
+ installed language server (TypeScript, JavaScript,
120
+ Python). A language server can run code from the
121
+ project, so they are off unless you set it.
122
+ setup claude-code [--hooks] [--remove] Register agenthead-mcp in .mcp.json and add the AgentHead
123
+ skill and MCP tool permissions; --hooks adds hooks to .claude/settings.json.
124
+ Merges with existing entries and backs files up;
125
+ --remove takes out the AgentHead entries
126
+ setup codex [--remove] [--global] [--yes] [--force] Merge .codex/config.toml and an AGENTS.md snippet;
127
+ --force rewrites a different directory or removes
128
+ a customized AgentHead server with --remove;
129
+ --global writes user config after confirmation (--yes for CI)
130
+ setup cursor [--remove] Merge .cursor/mcp.json and add an AgentHead rule
131
+ setup generic Print MCP JSON for any client; writes no files
132
+ setup auto [--dry-run] [--remove] [--purge] Configure installed clients, initialize, index and run doctor
133
+ hook post-tool | stop [--task <id>] Claude Code hooks, reading the event on stdin:
134
+ post-tool stores Bash output as evidence; stop, when
135
+ a task is set (--task or AGENTHEAD_TASK), keeps Claude
136
+ from stopping once while it is not verified.
137
+ A hook never fails Claude Code: errors go to stderr
138
+
139
+ Recoveries count core recovery calls from all clients, including failed attempts.
140
+
141
+ Every command accepts --json for machine-readable output. Errors exit non-zero
142
+ (2 for usage, 3 for security approval required/denied, 1 otherwise) and print to stderr.
143
+ Doctor exits 0 for all ok, 1 for failures, 2 for warnings only. Setup accepts --dry-run.
144
+ Use agenthead --version to print the installed CLI version.
145
+ AgentHead runs locally and needs no API key. Only the real-agent benchmark needs one.
146
+ `;
147
+ const commands = {
148
+ start,
149
+ agents,
150
+ security,
151
+ doctor,
152
+ init,
153
+ ingest,
154
+ pack,
155
+ recover,
156
+ stats,
157
+ route,
158
+ run: conductorRun,
159
+ parallel,
160
+ ledger,
161
+ decision,
162
+ task,
163
+ links,
164
+ graph,
165
+ diagram,
166
+ definitions,
167
+ references,
168
+ setup,
169
+ hook,
170
+ };
171
+ function describe(error) {
172
+ return error instanceof Error ? error.message : String(error);
173
+ }
174
+ /** Run the CLI and return the exit code. */
175
+ export async function run(argv, ctx) {
176
+ const [name, ...args] = argv;
177
+ if (name === "--version" && args.length === 0) {
178
+ ctx.stdout.write(version + "\n");
179
+ return 0;
180
+ }
181
+ if (name === "--help" || name === "-h" || name === "help") {
182
+ ctx.stdout.write(help);
183
+ return 0;
184
+ }
185
+ const json = args.includes("--json");
186
+ try {
187
+ if (name === undefined)
188
+ throw new UsageError("Missing command");
189
+ if (!Object.hasOwn(commands, name)) {
190
+ throw new UsageError(`Unknown command ${JSON.stringify(name)}`);
191
+ }
192
+ if (args.includes("--help") || args.includes("-h")) {
193
+ ctx.stdout.write(help);
194
+ return 0;
195
+ }
196
+ const code = await commands[name](args, ctx);
197
+ return typeof code === "number" ? code : 0;
198
+ }
199
+ catch (error) {
200
+ const message = describe(error);
201
+ const usage = error instanceof UsageError;
202
+ ctx.stderr.write(json
203
+ ? JSON.stringify({ error: message }) + "\n"
204
+ : `agenthead: ${message}\n` +
205
+ (usage ? "Run `agenthead --help` for usage.\n" : ""));
206
+ return error instanceof Error && error.name === "ApprovalRequired"
207
+ ? 3
208
+ : usage
209
+ ? 2
210
+ : 1;
211
+ }
212
+ }
213
+ export function main(argv) {
214
+ return run(argv, {
215
+ cwd: process.cwd(),
216
+ stdin: process.stdin,
217
+ stdout: process.stdout,
218
+ stderr: process.stderr,
219
+ });
220
+ }
221
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C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AC,EAAE,CAAC;YACnD,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACvB,OAAO,CAAC,CAAC;QACX,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAA6B,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACtE,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,KAAK,YAAY,UAAU,CAAC;QAC1C,GAAG,CAAC,MAAM,CAAC,KAAK,CACd,IAAI;YACF,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI;YAC3C,CAAC,CAAC,cAAc,OAAO,IAAI;gBACvB,CAAC,KAAK,CAAC,CAAC,CAAC,qCAAqC,CAAC,CAAC,CAAC,EAAE,CAAC,CAC3D,CAAC;QACF,OAAO,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,kBAAkB;YAChE,CAAC,CAAC,CAAC;YACH,CAAC,CAAC,KAAK;gBACL,CAAC,CAAC,CAAC;gBACH,CAAC,CAAC,CAAC,CAAC;IACV,CAAC;AACH,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,IAAc;IACjC,OAAO,GAAG,CAAC,IAAI,EAAE;QACf,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;QAClB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function codexHome(): string;
2
+ export declare function codexTrust(root: string): boolean | null;
3
+ export declare function trustInstruction(root: string): string;
@@ -0,0 +1,19 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { codexProjectTrusted } from "./setup-toml.js";
5
+ export function codexHome() {
6
+ return process.env.CODEX_HOME || join(homedir(), ".codex");
7
+ }
8
+ export function codexTrust(root) {
9
+ try {
10
+ return codexProjectTrusted(readFileSync(join(codexHome(), "config.toml"), "utf8"), root);
11
+ }
12
+ catch (error) {
13
+ return error.code === "ENOENT" ? false : null;
14
+ }
15
+ }
16
+ export function trustInstruction(root) {
17
+ return `In ${join(codexHome(), "config.toml")}, set trust_level = "trusted" under [projects.${JSON.stringify(root)}]; or open codex in ${JSON.stringify(root)} and approve project trust.`;
18
+ }
19
+ //# sourceMappingURL=codex-trust.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex-trust.js","sourceRoot":"","sources":["../src/codex-trust.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,MAAM,UAAU,SAAS;IACvB,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,IAAI,CAAC;QACH,OAAO,mBAAmB,CACxB,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,aAAa,CAAC,EAAE,MAAM,CAAC,EACtD,IAAI,CACL,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAQ,KAA+B,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3E,CAAC;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,MAAM,IAAI,CAAC,SAAS,EAAE,EAAE,aAAa,CAAC,iDAAiD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,uBAAuB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,6BAA6B,CAAC;AAC7L,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { type Context } from "./context.js";
2
+ export declare function init(args: string[], ctx: Context): Promise<void>;
3
+ export declare function readStdin(ctx: Context): Promise<Buffer>;
4
+ export declare function ingest(args: string[], ctx: Context): Promise<void>;
5
+ export declare function statOrUndefined(path: string): import("fs").Stats | undefined;
6
+ export declare function decodeText(bytes: Buffer, name: string): string;
7
+ export declare function pack(args: string[], ctx: Context): Promise<void>;
8
+ export declare function recover(args: string[], ctx: Context): Promise<void>;
9
+ export declare function stats(args: string[], ctx: Context): Promise<void>;
@@ -0,0 +1,275 @@
1
+ import { readFileSync, statSync } from "node:fs";
2
+ import { isUtf8 } from "node:buffer";
3
+ import { join } from "node:path";
4
+ import { DEFAULT_NOOP_BELOW_TOKENS, EvidenceStore, WorkspaceBoundary, } from "@agenthead/core";
5
+ import { CommandError, UsageError, databaseFile, emit, openStore, parse, } from "./context.js";
6
+ import { directorySize, readTotals, recordEvent } from "./ledger.js";
7
+ import { packEvidence } from "./pack-adapter.js";
8
+ import { loadGraphSignals } from "@agenthead/graph";
9
+ const kinds = [
10
+ "source",
11
+ "tool_output",
12
+ "test_result",
13
+ "doc",
14
+ "decision",
15
+ "error",
16
+ "inference",
17
+ ];
18
+ function noExtraArguments(positionals, command) {
19
+ if (positionals.length > 0) {
20
+ throw new UsageError(`agenthead ${command} takes no arguments, got ${JSON.stringify(positionals[0])}`);
21
+ }
22
+ }
23
+ export async function init(args, ctx) {
24
+ const { values, positionals } = parse(args, {});
25
+ noExtraArguments(positionals, "init");
26
+ const created = !statSafe(join(ctx.cwd, databaseFile));
27
+ new EvidenceStore(ctx.cwd).close();
28
+ const path = join(ctx.cwd, ".agenthead");
29
+ emit(ctx, values.json, { path, created }, created
30
+ ? `Initialized agenthead store in ${path}`
31
+ : `Already initialized: ${path}`);
32
+ }
33
+ function statSafe(path) {
34
+ try {
35
+ statSync(path);
36
+ return true;
37
+ }
38
+ catch {
39
+ return false;
40
+ }
41
+ }
42
+ export async function readStdin(ctx) {
43
+ const chunks = [];
44
+ for await (const chunk of ctx.stdin)
45
+ chunks.push(chunk);
46
+ return Buffer.concat(chunks);
47
+ }
48
+ function lineCount(text) {
49
+ return Math.max(1, text.replace(/\n$/, "").split("\n").length);
50
+ }
51
+ export async function ingest(args, ctx) {
52
+ const { values, positionals } = parse(args, { kind: { type: "string" } });
53
+ if (positionals.length > 1) {
54
+ throw new UsageError("agenthead ingest takes one file, or '-' for stdin");
55
+ }
56
+ const kind = (values.kind ?? undefined);
57
+ if (kind !== undefined && !kinds.includes(kind)) {
58
+ throw new UsageError(`Unknown --kind ${JSON.stringify(kind)}; expected one of ${kinds.join(", ")}`);
59
+ }
60
+ const target = positionals[0];
61
+ const store = openStore(ctx);
62
+ try {
63
+ let input;
64
+ let source;
65
+ let defaultKind;
66
+ let name;
67
+ if (target === undefined || target === "-") {
68
+ if (ctx.stdin.isTTY) {
69
+ throw new UsageError("Nothing to ingest: pass a file, or pipe output in (command | agenthead ingest -)");
70
+ }
71
+ input = await readStdin(ctx);
72
+ if (input.length === 0)
73
+ throw new CommandError("No input on stdin");
74
+ source = { type: "command", command: "stdin", exit_code: 0 };
75
+ defaultKind = "tool_output";
76
+ name = "stdin";
77
+ }
78
+ else {
79
+ const { absolutePath, requestedPath } = new WorkspaceBoundary(ctx.cwd).resolveSource(target);
80
+ const stats = statOrUndefined(absolutePath);
81
+ if (!stats)
82
+ throw new CommandError(`File not found: ${target}`);
83
+ if (stats.isDirectory()) {
84
+ throw new CommandError(`${target} is a directory; ingest takes a file`);
85
+ }
86
+ input = readFileSync(absolutePath);
87
+ source = {
88
+ type: "file",
89
+ path: requestedPath,
90
+ start_line: 1,
91
+ end_line: lineCount(input.toString("utf8")),
92
+ };
93
+ defaultKind = "source";
94
+ name = target;
95
+ }
96
+ const meta = {
97
+ source,
98
+ provenance: "observed",
99
+ produced_by: "agenthead-cli",
100
+ task_id: "cli",
101
+ };
102
+ const stored = kind ?? defaultKind;
103
+ const record = stored === "tool_output"
104
+ ? store.put({ ...meta, kind: stored, raw: input })
105
+ : store.put({
106
+ ...meta,
107
+ kind: stored,
108
+ content: decodeText(input, name),
109
+ });
110
+ const original = store.getOriginal(record.id);
111
+ const redacted = !original.bytes.equals(input);
112
+ emit(ctx, values.json, {
113
+ id: record.id,
114
+ kind: record.kind,
115
+ handle: original.handle,
116
+ bytes: original.bytes.length,
117
+ redacted,
118
+ }, `Stored ${record.id} (${record.kind}, ${original.bytes.length} bytes)\n` +
119
+ `Recover with: agenthead recover ${original.handle}` +
120
+ (redacted ? "\nSecrets were redacted before storing." : ""));
121
+ }
122
+ finally {
123
+ store.close();
124
+ }
125
+ }
126
+ export function statOrUndefined(path) {
127
+ try {
128
+ return statSync(path);
129
+ }
130
+ catch {
131
+ return undefined;
132
+ }
133
+ }
134
+ export function decodeText(bytes, name) {
135
+ if (bytes.includes(0) || !isUtf8(bytes)) {
136
+ throw new CommandError(`${name} is not UTF-8 text; use --kind tool_output to archive it as raw bytes`);
137
+ }
138
+ return bytes.toString("utf8");
139
+ }
140
+ export async function pack(args, ctx) {
141
+ const { values, positionals } = parse(args, {
142
+ task: { type: "string" },
143
+ budget: { type: "string" },
144
+ "edit-context": { type: "boolean" },
145
+ });
146
+ noExtraArguments(positionals, "pack");
147
+ if (!values.task?.trim())
148
+ throw new UsageError('--task "<text>" is required');
149
+ if (values.budget !== undefined && !/^[1-9]\d*$/.test(values.budget)) {
150
+ throw new UsageError("--budget must be a positive whole number of tokens");
151
+ }
152
+ // Without --budget, core sizes the pack and may decide to send none.
153
+ const budget = values.budget === undefined ? undefined : Number(values.budget);
154
+ const store = openStore(ctx);
155
+ try {
156
+ const records = store.searchTask(values.task);
157
+ const fresh = records.filter((record) => !record.stale);
158
+ const skippedStale = records.length - fresh.length;
159
+ if (skippedStale > 0 && !values.json)
160
+ ctx.stderr.write(`agenthead: skipped ${skippedStale} stale evidence record${skippedStale === 1 ? "" : "s"}\n`);
161
+ const packed = packEvidence(store, fresh, values.task, budget, loadGraphSignals(ctx.cwd), values["edit-context"]);
162
+ recordEvent(ctx.cwd, {
163
+ type: "pack",
164
+ usedTokens: packed.usedTokens,
165
+ savedTokens: packed.savedTokens,
166
+ omitted: packed.omitted.length,
167
+ });
168
+ const lines = [];
169
+ for (const item of packed.items) {
170
+ if (item.mode === "omitted") {
171
+ lines.push(`[omitted over budget: ${item.id}; full text: agenthead recover ${item.handle}]`, "");
172
+ continue;
173
+ }
174
+ const how = item.mode === "view"
175
+ ? `compressed view; full text: agenthead recover ${item.handle}`
176
+ : "full";
177
+ const location = item.mode === "full" && item.source
178
+ ? `; likely edit: ${item.source.path}:${item.source.start_line}-${item.source.end_line}`
179
+ : "";
180
+ lines.push(`## ${item.id} [${item.kind}, ${how}${location}]`, item.text, "");
181
+ }
182
+ const matched = fresh.length - packed.skippedBinary;
183
+ if (packed.noop && matched > 0) {
184
+ lines.push(packed.noopReason === "named_files"
185
+ ? "No pack: all AgentHead would keep in full is files the task names, so read those directly, or pass --budget to pack the evidence anyway."
186
+ : `No pack: the matching files hold ${packed.candidateTokens} tokens, under the ${DEFAULT_NOOP_BELOW_TOKENS}-token threshold, so read them directly, or pass --budget to pack them anyway.`);
187
+ }
188
+ else if (packed.items.length === 0) {
189
+ lines.push("No evidence matched the task.");
190
+ }
191
+ lines.push(packed.noop
192
+ ? `Task class ${packed.taskClass}; output style ${packed.outputStyle}.`
193
+ : `Used ${packed.usedTokens} of ${packed.budget} tokens; task class ${packed.taskClass}; output style ${packed.outputStyle}.`);
194
+ if (packed.pinnedOverflow > 0) {
195
+ ctx.stderr.write(`agenthead: warning: pinned evidence alone exceeds the budget by ${packed.pinnedOverflow} tokens\n`);
196
+ }
197
+ emit(ctx, values.json, {
198
+ taskClass: packed.taskClass,
199
+ outputStyle: packed.outputStyle,
200
+ budget: packed.budget,
201
+ usedTokens: packed.usedTokens,
202
+ savedTokens: packed.savedTokens,
203
+ omitted: packed.omitted.length,
204
+ noop: packed.noop,
205
+ noopReason: packed.noopReason,
206
+ candidateTokens: packed.candidateTokens,
207
+ pinnedOverflow: packed.pinnedOverflow,
208
+ skippedStale,
209
+ skippedBinary: packed.skippedBinary,
210
+ items: packed.items,
211
+ }, lines.join("\n").trimEnd());
212
+ }
213
+ finally {
214
+ store.close();
215
+ }
216
+ }
217
+ const handlePattern = /^sha256:[a-f0-9]{64}:(?:0|[1-9]\d*):(?:0|[1-9]\d*)$/;
218
+ export async function recover(args, ctx) {
219
+ const { values, positionals } = parse(args, {});
220
+ const [handle, ...extra] = positionals;
221
+ if (handle === undefined || extra.length > 0) {
222
+ throw new UsageError("agenthead recover takes exactly one handle");
223
+ }
224
+ if (!handlePattern.test(handle)) {
225
+ throw new UsageError(`Invalid recovery handle ${JSON.stringify(handle)}; expected sha256:<hash>:<start>:<end>`);
226
+ }
227
+ const store = openStore(ctx);
228
+ let bytes;
229
+ try {
230
+ bytes = store.recover(handle);
231
+ }
232
+ finally {
233
+ store.close();
234
+ }
235
+ if (!values.json) {
236
+ ctx.stdout.write(bytes);
237
+ return;
238
+ }
239
+ const text = !bytes.includes(0) && isUtf8(bytes);
240
+ emit(ctx, true, {
241
+ handle,
242
+ bytes: bytes.length,
243
+ encoding: text ? "utf8" : "base64",
244
+ content: bytes.toString(text ? "utf8" : "base64"),
245
+ }, "");
246
+ }
247
+ export async function stats(args, ctx) {
248
+ const { values, positionals } = parse(args, {});
249
+ noExtraArguments(positionals, "stats");
250
+ const store = openStore(ctx);
251
+ let counts;
252
+ let recoveries;
253
+ try {
254
+ counts = store.stats();
255
+ recoveries = store
256
+ .recoveryStats()
257
+ .byTask.reduce((sum, row) => sum + row.count, 0);
258
+ }
259
+ finally {
260
+ store.close();
261
+ }
262
+ const byKind = Object.fromEntries(kinds.map((kind) => [kind, counts.byKind[kind] ?? 0]));
263
+ const { total, stale } = counts;
264
+ const sizeBytes = directorySize(join(ctx.cwd, ".agenthead"));
265
+ const totals = readTotals(ctx.cwd);
266
+ emit(ctx, values.json, { sizeBytes, records: { total, stale, byKind }, ...totals, recoveries }, [
267
+ `Store size: ${sizeBytes} bytes`,
268
+ `Records: ${total} (${stale} stale)`,
269
+ ...kinds.map((kind) => ` ${kind.padEnd(12)} ${byKind[kind]}`),
270
+ `Packs: ${totals.packs}`,
271
+ `Recoveries: ${recoveries}`,
272
+ `Tokens saved: ${totals.tokensSaved}`,
273
+ ].join("\n"));
274
+ }
275
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,yBAAyB,EACzB,aAAa,EACb,iBAAiB,GAGlB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,KAAK,GAEN,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,KAAK,GAAG;IACZ,QAAQ;IACR,aAAa;IACb,aAAa;IACb,KAAK;IACL,UAAU;IACV,OAAO;IACP,WAAW;CAC+B,CAAC;AAE7C,SAAS,gBAAgB,CAAC,WAAqB,EAAE,OA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AAC,GAAG,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAC/B,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CACtD,CAAC;IACF,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAChC,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnC,IAAI,CACF,GAAG,EACH,MAAM,CAAC,IAAI,EACX,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,EACvE;QACE,kBAAkB,SAAS,QAAQ;QACnC,kBAAkB,KAAK,KAAK,KAAK,SAAS;QAC1C,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9D,kBAAkB,MAAM,CAAC,KAAK,EAAE;QAChC,kBAAkB,UAAU,EAAE;QAC9B,kBAAkB,MAAM,CAAC,WAAW,EAAE;KACvC,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;AACJ,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { type ParseArgsOptionsConfig } from "node:util";
2
+ import { EvidenceStore } from "@agenthead/core";
3
+ export interface Writable {
4
+ write(chunk: string | Uint8Array): unknown;
5
+ isTTY?: boolean;
6
+ }
7
+ export interface Context {
8
+ /** The project root: every command works on `.agenthead/` under this directory. */
9
+ cwd: string;
10
+ stdin: AsyncIterable<Uint8Array> & {
11
+ isTTY?: boolean;
12
+ };
13
+ stdout: Writable;
14
+ stderr: Writable;
15
+ /** Start pins the MCP executable so clients can launch it after npx exits. */
16
+ mcpCommand?: string;
17
+ }
18
+ /** The command line was wrong. Reported with exit code 2. */
19
+ export declare class UsageError extends Error {
20
+ readonly name = "UsageError";
21
+ }
22
+ /** The command was valid but could not be completed. Reported with exit code 1. */
23
+ export declare class CommandError extends Error {
24
+ readonly name = "CommandError";
25
+ }
26
+ export declare const databaseFile: string;
27
+ export declare function parse<const O extends ParseArgsOptionsConfig>(args: string[], options: O): {
28
+ values: {
29
+ json: {
30
+ type: "boolean";
31
+ };
32
+ } & O extends ParseArgsOptionsConfig ? ({
33
+ json: {
34
+ type: "boolean";
35
+ };
36
+ } & O extends infer T extends ParseArgsOptionsConfig ? { -readonly [LongOption in keyof T]?: V[LongOption] | undefined; } : never) & ({
37
+ json: {
38
+ type: "boolean";
39
+ };
40
+ } & O extends infer T_1 extends ParseArgsOptionsConfig ? { [LongOption_1 in keyof T_1 as ({
41
+ json: {
42
+ type: "boolean";
43
+ };
44
+ } & O)[LongOption_1]["default"] extends {} ? LongOption_1 : never]: V[LongOption_1]; } : never) extends infer P ? { [K in keyof P]: P[K]; } : never : {};
45
+ positionals: string[];
46
+ };
47
+ /** Open the project's existing store. Never creates one: only `init` does. */
48
+ export declare function openStore(ctx: Context): EvidenceStore;
49
+ /** Print `data` as one JSON line when `json` is set, otherwise `text`. */
50
+ export declare function emit(ctx: Context, json: boolean | undefined, data: unknown, text: string): void;
@@ -0,0 +1,37 @@
1
+ import { existsSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { parseArgs } from "node:util";
4
+ import { EvidenceStore } from "@agenthead/core";
5
+ /** The command line was wrong. Reported with exit code 2. */
6
+ export class UsageError extends Error {
7
+ name = "UsageError";
8
+ }
9
+ /** The command was valid but could not be completed. Reported with exit code 1. */
10
+ export class CommandError extends Error {
11
+ name = "CommandError";
12
+ }
13
+ export const databaseFile = join(".agenthead", "agenthead.db");
14
+ export function parse(args, options) {
15
+ try {
16
+ return parseArgs({
17
+ args,
18
+ options: { json: { type: "boolean" }, ...options },
19
+ allowPositionals: true,
20
+ });
21
+ }
22
+ catch (error) {
23
+ throw new UsageError(error.message);
24
+ }
25
+ }
26
+ /** Open the project's existing store. Never creates one: only `init` does. */
27
+ export function openStore(ctx) {
28
+ if (!existsSync(join(ctx.cwd, databaseFile))) {
29
+ throw new CommandError(`No agenthead store in ${ctx.cwd}. Run \`agenthead init\` first.`);
30
+ }
31
+ return new EvidenceStore(ctx.cwd);
32
+ }
33
+ /** Print `data` as one JSON line when `json` is set, otherwise `text`. */
34
+ export function emit(ctx, json, data, text) {
35
+ ctx.stdout.write(json ? JSON.stringify(data) + "\n" : text + "\n");
36
+ }
37
+ //# sourceMappingURL=context.js.map