@tachikomagundam/abathur 0.2.2 → 0.2.4

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/plugin/abathur.ts CHANGED
@@ -1,4 +1,4 @@
1
- // abathur-opencode-plugin v0.2.2
1
+ // abathur-opencode-plugin v0.2.4
2
2
  // Official opencode plugin adapter for the abathur evolution harness.
3
3
  // Registers ONE agent tool, `abathur`, that shells out to the abathur CLI —
4
4
  // argv-only (node:child_process execFile, never a shell), top-level commands
@@ -9,17 +9,19 @@
9
9
  // server(input, options) resolves to Hooks; Hooks.tool is a
10
10
  // { [name]: ToolDefinition } record (see @opencode-ai/plugin).
11
11
  // This file is shipped as-is (package.json "files") and reaches a session by
12
- // two routes, neither compiling it through abathur's tsc:
13
- // (A) copied into ~/.config/opencode/plugins/ by `abathur opencode install`
14
- // (adds the /abathur command too); "@opencode-ai/plugin" then resolves in
15
- // opencode's config-directory node_modules.
12
+ // two routes, neither compiling it through abathur's tsc. Both deliver the
13
+ // tool AND the /abathur slash command:
14
+ // (A) copied into ~/.config/opencode/plugins/ by `abathur opencode install`,
15
+ // which also drops commands/abathur.md; "@opencode-ai/plugin" then
16
+ // resolves in opencode's config-directory node_modules.
16
17
  // (B) served as the package's "./server" export when the npm package name is
17
18
  // listed in opencode.jsonc "plugin" — opencode's arborist install places
18
19
  // @opencode-ai/plugin (runtime dependency) next to the package in its
19
- // cache, so the same import resolves there too.
20
+ // cache, so the same import resolves there too; with no commands/abathur.md
21
+ // on disk, the config hook below self-registers the command instead.
20
22
 
21
23
  import { execFile } from "node:child_process";
22
- import { tool } from "@opencode-ai/plugin";
24
+ import { tool, type Config } from "@opencode-ai/plugin";
23
25
 
24
26
  /** Spawn cap: a CLI call that outlives this is killed and reported, never awaited forever. */
25
27
  const TIMEOUT_MS = 120_000;
@@ -114,9 +116,47 @@ function runCli(bin: string, argv: readonly string[]): Promise<CliResult> {
114
116
  });
115
117
  }
116
118
 
119
+
120
+ /**
121
+ * /abathur slash-command template, injected into cfg.command.abathur by the
122
+ * config hook for installs without a commands/abathur.md on disk (Route B).
123
+ * Byte-mirror of plugin/abathur-command.md minus its first-line marker —
124
+ * src/test/opencode.test.ts pins the equality.
125
+ */
126
+ const COMMAND_TEMPLATE = `Drive the abathur evolution harness through the \`abathur\` tool on this machine.
127
+
128
+ User request: $ARGUMENTS
129
+
130
+ Interpret the request as one \`abathur\` CLI invocation: the first word is the
131
+ top-level command (\`genome\`, \`run\`, \`status\`, \`bundle\`, \`graft\`, \`self-eval\`,
132
+ \`kernel\`, or \`--help\`) and the rest are argv tokens. Call the \`abathur\` tool
133
+ with \`command\` set to the first word and \`extra\` set to the remaining tokens,
134
+ then report the CLI exit code (0 ok / 1 blocked decision / 2 cannot-answer)
135
+ and the relevant lines of its output. If no request was given, call the tool
136
+ with \`command: "--help"\` and summarize the command list. \`promote\` and
137
+ \`tombstone\` cannot be called through the tool at all — the tool refuses them.
138
+ They are human gates that belong to a terminal: if the user asks for one,
139
+ tell them to run \`abathur promote …\` / \`abathur tombstone …\` there.
140
+ `;
141
+
117
142
  export default {
118
143
  id: "abathur",
119
144
  server: async () => ({
145
+ // Self-registering /abathur: opencode calls hook.config(cfg) once per
146
+ // instance after ALL config sources are merged — file-based commands are
147
+ // already in cfg.command by then (config.ts merges {command,commands}/**/*.md;
148
+ // the hook fires from plugin/index.ts after config.get()). `??=` keeps a
149
+ // Route-A commands/abathur.md authoritative (identical behaviour to 0.2.2)
150
+ // and only fills the gap for Route B; the command map is keyed by name, so
151
+ // a same-name file + injection never duplicates the entry. Proven upstream
152
+ // mechanism: opencode-acp registers its /acp command exactly this way.
153
+ config: async (cfg: Config) => {
154
+ cfg.command ??= {};
155
+ cfg.command.abathur ??= {
156
+ description: "Drive the abathur evolution harness (usage: /abathur <command> [args...])",
157
+ template: COMMAND_TEMPLATE,
158
+ };
159
+ },
120
160
  tool: {
121
161
  abathur: tool({
122
162
  description: