@instruction.md/agents 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/dist/converse.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/converse.ts
2
2
  import { basename } from "node:path";
3
+ var SUBAGENT_TOOLS = /* @__PURE__ */ new Set(["Task", "Agent"]);
3
4
  var VALUE_FLAGS = /* @__PURE__ */ new Set([
4
5
  "--model",
5
6
  "--fallback-model",
@@ -140,6 +141,8 @@ var ClaudeSession = class {
140
141
  pending = /* @__PURE__ */ new Map();
141
142
  ended = false;
142
143
  lastSaid = "";
144
+ /** The subagents of its current task, the newest last (at most 20). */
145
+ subagents = [];
143
146
  write(o) {
144
147
  if (this.ended || !this.child.stdin || this.child.stdin.destroyed) return false;
145
148
  try {
@@ -158,6 +161,10 @@ var ClaudeSession = class {
158
161
  /** A user message: the task, or a person's words. */
159
162
  say(text) {
160
163
  this.busy = true;
164
+ if (this.subagents.some((x) => !x.running)) {
165
+ this.subagents = this.subagents.filter((x) => x.running);
166
+ this.hooks.subagents?.(this.subagents);
167
+ }
161
168
  return this.write({ type: "user", message: { role: "user", content: text }, parent_tool_use_id: null, session_id: this.sessionId });
162
169
  }
163
170
  interrupt() {
@@ -170,6 +177,19 @@ var ClaudeSession = class {
170
177
  } catch {
171
178
  }
172
179
  }
180
+ started(id, input) {
181
+ const i = input && typeof input === "object" ? input : {};
182
+ const said = (k) => typeof i[k] === "string" && i[k].trim() ? cut(maskText(i[k].trim().replace(/\s+/g, " ")), 110) : void 0;
183
+ const type = said("subagent_type");
184
+ this.subagents = [...this.subagents.filter((x) => x.id !== id), { id, name: said("description") ?? type ?? "A subagent", ...type ? { type } : {}, running: true }].slice(-20);
185
+ this.hooks.subagents?.(this.subagents);
186
+ }
187
+ finished(id) {
188
+ const x = this.subagents.find((y) => y.id === id);
189
+ if (!x || !x.running) return;
190
+ this.subagents = this.subagents.map((y) => y.id === id ? { ...y, running: false } : y);
191
+ this.hooks.subagents?.(this.subagents);
192
+ }
173
193
  feed(s) {
174
194
  this.buf += s;
175
195
  let i;
@@ -190,15 +210,22 @@ var ClaudeSession = class {
190
210
  on(m) {
191
211
  if (m.type === "system" && m.subtype === "init" && typeof m.session_id === "string") this.sessionId = m.session_id;
192
212
  else if (m.type === "assistant" && Array.isArray(m.message?.content)) {
193
- if (m.parent_tool_use_id) return;
213
+ const sub = typeof m.parent_tool_use_id === "string" && m.parent_tool_use_id ? m.parent_tool_use_id : void 0;
214
+ const of = sub ? { agent: sub } : {};
194
215
  for (const b of m.message.content) {
195
216
  if (b?.type === "text" && typeof b.text === "string" && b.text.trim()) {
196
- this.lastSaid = b.text.trim();
197
- this.hooks.line({ type: "said", text: cut(maskText(b.text.trim().replace(/\s+/g, " ")), 480) });
198
- } else if (b?.type === "tool_use" && b.name !== "AskUserQuestion") this.hooks.line({ type: "ran", text: toolLine(String(b.name), b.input) });
217
+ if (!sub) this.lastSaid = b.text.trim();
218
+ this.hooks.line({ type: "said", text: cut(maskText(b.text.trim().replace(/\s+/g, " ")), 480), ...of });
219
+ } else if (b?.type === "tool_use" && b.name !== "AskUserQuestion") {
220
+ this.hooks.line({ type: "ran", text: toolLine(String(b.name), b.input), ...of });
221
+ if (SUBAGENT_TOOLS.has(String(b.name)) && typeof b.id === "string") this.started(b.id, b.input);
222
+ }
199
223
  }
224
+ } else if (m.type === "user" && Array.isArray(m.message?.content)) {
225
+ for (const b of m.message.content) if (b?.type === "tool_result" && typeof b.tool_use_id === "string") this.finished(b.tool_use_id);
200
226
  } else if (m.type === "result") {
201
227
  this.busy = false;
228
+ for (const x of this.subagents) if (x.running) this.finished(x.id);
202
229
  const err = m.is_error === true || typeof m.subtype === "string" && m.subtype !== "success";
203
230
  const said = !err && typeof m.result === "string" && m.result.trim() === this.lastSaid;
204
231
  this.lastSaid = "";
package/dist/fleet.js CHANGED
@@ -347,7 +347,8 @@ var Fleet = class {
347
347
  idle: () => {
348
348
  if (this.onceMode) a.session?.end();
349
349
  },
350
- decide: (req, signal) => this.decide(a, req, signal)
350
+ decide: (req, signal) => this.decide(a, req, signal),
351
+ subagents: () => void this.reportOne(a.d.id, this.reportFor(a))
351
352
  });
352
353
  a.session.begin(conv.prompt);
353
354
  } else child.stdout?.on("data", (c) => keep(c, false));
@@ -503,7 +504,8 @@ var Fleet = class {
503
504
  ...v ? { versionId: v } : {},
504
505
  health: signIn ? "needs_sign_in" : failed ? "failed" : "ok",
505
506
  ...failed ? { error: (a.stderr.slice(-5).join("\n") || `exited (${a.exitSignal ?? `code ${a.exitCode}`})`).slice(0, 2e3) } : {},
506
- ...signIn && app ? { needs: [{ kind: "host", name: app, what: signIn.slice(0, 300), fix: HOST_FIX[app] }] } : {}
507
+ ...signIn && app ? { needs: [{ kind: "host", name: app, what: signIn.slice(0, 300), fix: HOST_FIX[app] }] } : {},
508
+ ...a.session ? { subagents: alive ? a.session.subagents : [] } : {}
507
509
  };
508
510
  }
509
511
  async reportAll() {
@@ -856,7 +858,7 @@ function registryFleetClient(c, q, log = (l) => process.stderr.write(`${l}
856
858
  }
857
859
  },
858
860
  async report(r) {
859
- await call("deployments_report", { deploymentId: r.deploymentId, running: r.running, ...r.versionId ? { versionId: r.versionId } : {}, ...r.health ? { health: r.health } : {}, ...r.error ? { error: r.error } : {}, ...r.host ? { host: r.host } : {}, ...r.needs?.length ? { needs: r.needs } : {}, ...r.activity?.length ? { activity: r.activity } : {} });
861
+ await call("deployments_report", { deploymentId: r.deploymentId, running: r.running, ...r.versionId ? { versionId: r.versionId } : {}, ...r.health ? { health: r.health } : {}, ...r.error ? { error: r.error } : {}, ...r.host ? { host: r.host } : {}, ...r.needs?.length ? { needs: r.needs } : {}, ...r.activity?.length ? { activity: r.activity } : {}, ...r.subagents ? { subagents: r.subagents } : {} });
860
862
  },
861
863
  converse: {
862
864
  async ask(card) {
package/dist/hook.js CHANGED
@@ -5,7 +5,7 @@ import { hostname } from "node:os";
5
5
  import { isAbsolute, join, relative } from "node:path";
6
6
 
7
7
  // package.json
8
- var version = "0.1.0";
8
+ var version = "0.2.0";
9
9
 
10
10
  // src/hook.ts
11
11
  import {
package/dist/main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  // package.json
3
3
  var name = "@instruction.md/agents";
4
- var version = "0.1.0";
4
+ var version = "0.2.0";
5
5
 
6
6
  // src/main.ts
7
7
  import { cmdHook } from "./hook.js";
package/dist/turns.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { hostname } from "node:os";
3
3
 
4
4
  // package.json
5
- var version = "0.1.0";
5
+ var version = "0.2.0";
6
6
 
7
7
  // src/turns.ts
8
8
  import { runHook } from "./hook.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instruction.md/agents",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Run agents with instruction.md: the `instruction-agents` CLI. Hooks that give Claude Code, Codex and other agents the instruction a project follows, and each new version as it is released; the ACP proxy, pi's extension and the SDK helper; `fleet`, an agent for every deployment, whose questions and permission requests reach you on instruction.md/agents; and an agent's MCP servers, skills and sign-ins (apply, doctor, accounts, signin, credential). Built on the instruction.md package.",
5
5
  "keywords": [
6
6
  "instruction.md",