@demicodes/agent 0.25.7 → 0.25.8

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/index.d.mts CHANGED
@@ -565,6 +565,8 @@ interface PersistedSubagentJob {
565
565
  declare class ChildSupervisor<State = unknown> {
566
566
  private readonly options;
567
567
  private readonly jobs;
568
+ /** Shell commandId → the child that command hosts ('' while its spawn or resume is starting). */
569
+ private readonly childByCommandId;
568
570
  private parentSession;
569
571
  private isDisposed;
570
572
  constructor(options: ChildSupervisorOptions<State>);
@@ -628,6 +630,15 @@ declare class ChildSupervisor<State = unknown> {
628
630
  private attachSession;
629
631
  private childStoreKey;
630
632
  private childSessionStore;
633
+ /**
634
+ * One shell command hosts at most one child lifecycle, so `shell_abort` on
635
+ * that command and aborting that child are the same act. A script that loops
636
+ * or chains spawns would otherwise start the next child as soon as the
637
+ * previous one is aborted, outliving every abort aimed at it.
638
+ */
639
+ private claimHostingCommand;
640
+ private releaseHostingCommand;
641
+ private recordHostedChild;
631
642
  /** Shared spawn/resume foreground behaviour: announce the id, wire abort and stdin steers, wait for close, report the outcome. */
632
643
  private attendChild;
633
644
  /**
package/dist/index.mjs CHANGED
@@ -2848,6 +2848,8 @@ const INHERIT_PROFILE = {
2848
2848
  var ChildSupervisor = class ChildSupervisor {
2849
2849
  options;
2850
2850
  jobs = /* @__PURE__ */ new Map();
2851
+ /** Shell commandId → the child that command hosts ('' while its spawn or resume is starting). */
2852
+ childByCommandId = /* @__PURE__ */ new Map();
2851
2853
  parentSession = null;
2852
2854
  isDisposed = false;
2853
2855
  constructor(options) {
@@ -2878,7 +2880,7 @@ var ChildSupervisor = class ChildSupervisor {
2878
2880
  const profileNames = this.configuredProfileNames();
2879
2881
  return {
2880
2882
  name: "agent",
2881
- summary: "Start an isolated child agent session and wait for its result. The command stays running until the child session ends; stdout is the child's last assistant text. While it is the foreground job, shell_write steers the child and shell_abort aborts it. Run several in separate shell_exec calls with short timeoutMs to fan out, then end the turn — completion wakes an idle session; do not poll. Children can spawn children of their own.",
2883
+ summary: "Start an isolated child agent session and wait for its result. The command stays running until the child session ends; stdout is the child's last assistant text. While it is the foreground job, shell_write steers the child and shell_abort aborts it. One shell command hosts one child: run several in separate shell_exec calls with short timeoutMs to fan out, then end the turn — completion wakes an idle session; do not poll. Children can spawn children of their own.",
2882
2884
  successOutput: "first stderr line is \"subagentId: <id>\" at start; stdout is the child's last assistant text (empty is valid), written only at exit",
2883
2885
  failureOutput: "non-zero exit with the abort or failure reason on stderr",
2884
2886
  input: {
@@ -2894,12 +2896,13 @@ var ChildSupervisor = class ChildSupervisor {
2894
2896
  text: z.string()
2895
2897
  }) },
2896
2898
  runningHint: SPAWN_RUNNING_HINT,
2897
- run: async ({ parsed, io, signal, stdinStream }) => {
2899
+ run: async ({ parsed, io, signal, stdinStream, commandId }) => {
2898
2900
  const prompt = String(parsed.values.prompt ?? "").trim();
2899
2901
  if (!prompt) {
2900
2902
  await io.stderr("demi agent: prompt must not be empty\n");
2901
2903
  return { exitCode: 1 };
2902
2904
  }
2905
+ if (!await this.claimHostingCommand(commandId, io, "demi agent")) return { exitCode: 1 };
2903
2906
  let job;
2904
2907
  try {
2905
2908
  job = await this.spawn({
@@ -2909,9 +2912,11 @@ var ChildSupervisor = class ChildSupervisor {
2909
2912
  isSpawnForbidden: parsed.values["no-subagents"] === true
2910
2913
  });
2911
2914
  } catch (error) {
2915
+ this.releaseHostingCommand(commandId);
2912
2916
  await io.stderr(`demi agent: ${errorMessage(error)}\n`);
2913
2917
  return { exitCode: 1 };
2914
2918
  }
2919
+ this.recordHostedChild(commandId, job.id);
2915
2920
  return this.attendChild(job, {
2916
2921
  io,
2917
2922
  isJson: parsed.json === true,
@@ -3021,20 +3026,23 @@ var ChildSupervisor = class ChildSupervisor {
3021
3026
  text: z.string()
3022
3027
  }) },
3023
3028
  runningHint: SPAWN_RUNNING_HINT,
3024
- run: async ({ parsed, io, signal, stdinStream }) => {
3029
+ run: async ({ parsed, io, signal, stdinStream, commandId }) => {
3025
3030
  const id = String(parsed.values.id);
3026
3031
  const message = String(parsed.values.message ?? "").trim();
3027
3032
  if (!message) {
3028
3033
  await io.stderr("demi agent resume: message must not be empty\n");
3029
3034
  return { exitCode: 1 };
3030
3035
  }
3036
+ if (!await this.claimHostingCommand(commandId, io, "demi agent resume")) return { exitCode: 1 };
3031
3037
  let job;
3032
3038
  try {
3033
3039
  job = await this.resumeArchived(id, message);
3034
3040
  } catch (error) {
3041
+ this.releaseHostingCommand(commandId);
3035
3042
  await io.stderr(`demi agent resume: ${errorMessage(error)}\n`);
3036
3043
  return { exitCode: 1 };
3037
3044
  }
3045
+ this.recordHostedChild(commandId, job.id);
3038
3046
  return this.attendChild(job, {
3039
3047
  io,
3040
3048
  isJson: parsed.json === true,
@@ -3432,6 +3440,28 @@ var ChildSupervisor = class ChildSupervisor {
3432
3440
  loadCheckpoint: () => this.options.store.readJson(this.childStoreKey(childId, "checkpoint.json"))
3433
3441
  };
3434
3442
  }
3443
+ /**
3444
+ * One shell command hosts at most one child lifecycle, so `shell_abort` on
3445
+ * that command and aborting that child are the same act. A script that loops
3446
+ * or chains spawns would otherwise start the next child as soon as the
3447
+ * previous one is aborted, outliving every abort aimed at it.
3448
+ */
3449
+ async claimHostingCommand(commandId, io, verb) {
3450
+ if (commandId === null) return true;
3451
+ const hostedId = this.childByCommandId.get(commandId);
3452
+ if (hostedId === void 0) {
3453
+ this.childByCommandId.set(commandId, "");
3454
+ return true;
3455
+ }
3456
+ await io.stderr(`${verb}: this shell command already ran subagent ${hostedId || "(starting)"}; one shell command hosts one child — run each spawn or resume in its own shell_exec call\n`);
3457
+ return false;
3458
+ }
3459
+ releaseHostingCommand(commandId) {
3460
+ if (commandId !== null) this.childByCommandId.delete(commandId);
3461
+ }
3462
+ recordHostedChild(commandId, childId) {
3463
+ if (commandId !== null) this.childByCommandId.set(commandId, childId);
3464
+ }
3435
3465
  /** Shared spawn/resume foreground behaviour: announce the id, wire abort and stdin steers, wait for close, report the outcome. */
3436
3466
  async attendChild(job, ctx) {
3437
3467
  const { io, isJson, signal, stdinStream } = ctx;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@demicodes/agent",
3
3
  "description": "Session runtime and transport-neutral client and server protocol for Demi.",
4
- "version": "0.25.7",
4
+ "version": "0.25.8",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "exports": {
@@ -19,10 +19,10 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
- "@demicodes/core": "^0.25.7",
23
- "@demicodes/provider": "^0.25.7",
24
- "@demicodes/shell": "^0.25.7",
25
- "@demicodes/utils": "^0.25.7",
22
+ "@demicodes/core": "^0.25.8",
23
+ "@demicodes/provider": "^0.25.8",
24
+ "@demicodes/shell": "^0.25.8",
25
+ "@demicodes/utils": "^0.25.8",
26
26
  "zod": "^4.0.0"
27
27
  },
28
28
  "license": "Apache-2.0",