@demicodes/agent 0.24.1 → 0.25.1

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.
@@ -1,4 +1,4 @@
1
- import { f as TranscriptPatch, l as ServerFrame, n as AgentServerTransport, o as ClientFrame, r as AgentTransport, s as ClientSessionEvent, t as AgentClientTransport, u as ShellCommandStatusLike, x as AgentMetadata } from "./transport-vzA9vMxT.mjs";
2
- import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-CyoM_NS1.mjs";
1
+ import { f as TranscriptPatch, l as ServerFrame, n as AgentServerTransport, o as ClientFrame, r as AgentTransport, s as ClientSessionEvent, t as AgentClientTransport, u as ShellCommandStatusLike, x as AgentMetadata } from "./transport-Qj50JTjx.mjs";
2
+ import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-Ax8tieib.mjs";
3
3
  import { ProviderSelection } from "@demicodes/provider";
4
4
  export { type AgentActionOptions, AgentClient, type AgentClientListener, type AgentClientTransport, type AgentMetadata, type AgentServerTransport, type AgentTransport, type ClientFrame, type ClientSessionEvent, type JsonWebSocket, type ProviderSelection, type ServerFrame, type ShellCommandStatusLike, type TranscriptPatch, createWebSocketClientTransport, createWebSocketServerTransport };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { A as AgentSystemPromptContext, B as CompactionWindow, C as AgentReferenceResolveContext, D as AgentSessionParams, E as AgentSessionOptions, F as ExternalMutationReservation, G as DEFAULT_TURN_RETRY_POLICY, H as TranscriptLog, I as ModelSwitchApply, J as resolveRetryPolicy, K as TurnRetryPolicy, L as SessionEvent, M as AgentToolContext, N as AgentToolInvokeContext, O as AgentSessionRestoreParams, P as AgentToolInvokeResult, R as SessionEventListener, S as AgentPromptContext, T as AgentSessionCloneParams, U as TranscriptOptions, V as DrainedTranscriptPatches, W as estimateTranscriptBlockTokens, Y as retryDelayMs, _ as AgentHarnessContext, a as createInProcessTransportPair, b as AgentLifecycleEvent, c as ConversationSummary, d as SubagentJob, f as TranscriptPatch, g as AgentHarness, h as AgentDisposeContext, i as InProcessTransportPair, j as AgentTool, k as AgentSessionStore, l as ServerFrame, m as AbortTarget, n as AgentServerTransport, o as ClientFrame, p as AbortResult, q as isRetryableCode, r as AgentTransport, s as ClientSessionEvent, t as AgentClientTransport, u as ShellCommandStatusLike, v as AgentHarnessRuntime, w as AgentSessionCheckpoint, x as AgentMetadata, y as AgentHostContext, z as SubagentProfile } from "./transport-vzA9vMxT.mjs";
2
- import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-CyoM_NS1.mjs";
1
+ import { A as AgentSystemPromptContext, B as CompactionWindow, C as AgentReferenceResolveContext, D as AgentSessionParams, E as AgentSessionOptions, F as ExternalMutationReservation, G as DEFAULT_TURN_RETRY_POLICY, H as TranscriptLog, I as ModelSwitchApply, J as resolveRetryPolicy, K as TurnRetryPolicy, L as SessionEvent, M as AgentToolContext, N as AgentToolInvokeContext, O as AgentSessionRestoreParams, P as AgentToolInvokeResult, R as SessionEventListener, S as AgentPromptContext, T as AgentSessionCloneParams, U as TranscriptOptions, V as DrainedTranscriptPatches, W as estimateTranscriptBlockTokens, Y as retryDelayMs, _ as AgentHarnessContext, a as createInProcessTransportPair, b as AgentLifecycleEvent, c as ConversationSummary, d as SubagentJob, f as TranscriptPatch, g as AgentHarness, h as AgentDisposeContext, i as InProcessTransportPair, j as AgentTool, k as AgentSessionStore, l as ServerFrame, m as AbortTarget, n as AgentServerTransport, o as ClientFrame, p as AbortResult, q as isRetryableCode, r as AgentTransport, s as ClientSessionEvent, t as AgentClientTransport, u as ShellCommandStatusLike, v as AgentHarnessRuntime, w as AgentSessionCheckpoint, x as AgentMetadata, y as AgentHostContext, z as SubagentProfile } from "./transport-Qj50JTjx.mjs";
2
+ import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-Ax8tieib.mjs";
3
3
  import { BashAuditEvent, BashEnvironment, BashEnvironmentOptions, Command, CommandMetadataRecord, CommandRegistry, Host, HostStore, ShellCommandStatus, ShellOutputChunk } from "@demicodes/shell";
4
- import { AgentProvider, Provider } from "@demicodes/provider";
4
+ import { AgentProvider, Provider, ProviderSelection } from "@demicodes/provider";
5
5
  import { Block, Model, ModelMediaKind, ModelSelection, ProviderErrorDiagnostics, QueuedMessage, SessionPhase, UserContentBlock } from "@demicodes/core";
6
6
  //#region src/recovery.d.ts
7
7
  /**
@@ -521,6 +521,7 @@ interface ChildSupervisorOptions<State> {
521
521
  shellOptions: Omit<BashEnvironmentOptions, 'host' | 'commands'>;
522
522
  prepareShell: PrepareShell | null;
523
523
  sessionOptions: AgentServerSessionOptions;
524
+ createRuntime(selection: ProviderSelection): Promise<AgentProvider>;
524
525
  /** When false, a child closing never wakes an idle parent; the host app orchestrates the wakeup from the `subagent closed` frame. */
525
526
  notifyParentOnIdle: boolean;
526
527
  /** Backing store for child checkpoints and job metadata. */
@@ -621,6 +622,7 @@ declare class ChildSupervisor<State = unknown> {
621
622
  /** Aborts every live child (each with its subtree); the archive is untouched. */
622
623
  abortAll(): Promise<void>;
623
624
  private spawn;
625
+ private createChildProvider;
624
626
  /**
625
627
  * Everything spawn and restore share: the command tree (identical to the
626
628
  * owner's — children spawn, message, and observe exactly like any session),
@@ -631,7 +633,6 @@ declare class ChildSupervisor<State = unknown> {
631
633
  private attachSession;
632
634
  private childStoreKey;
633
635
  private childSessionStore;
634
- private deletePersistedJob;
635
636
  /** Shared spawn/resume foreground behaviour: announce the id, wire abort and stdin steers, wait for close, report the outcome. */
636
637
  private attendChild;
637
638
  /**
package/dist/index.mjs CHANGED
@@ -2262,11 +2262,17 @@ function createStandardAgentTools(options) {
2262
2262
  inputSchema: {
2263
2263
  type: "object",
2264
2264
  additionalProperties: false,
2265
- required: ["script", "timeoutMs"],
2265
+ required: [
2266
+ "script",
2267
+ "description",
2268
+ "timeoutMs"
2269
+ ],
2266
2270
  properties: {
2267
2271
  script: { type: "string" },
2268
2272
  description: {
2269
2273
  type: "string",
2274
+ minLength: 1,
2275
+ pattern: "\\S",
2270
2276
  description: TOOL_DESCRIPTION_FIELD
2271
2277
  },
2272
2278
  shellId: { type: "string" },
@@ -2524,6 +2530,7 @@ function binaryStreamVerdict(binary, binPath, model, maxMediaBytes) {
2524
2530
  function parseShellExecInput(input) {
2525
2531
  const record = asRecord(input, "agent tool input must be an object");
2526
2532
  if (typeof record.script !== "string") throw new Error("shell_exec requires string field \"script\"");
2533
+ if (typeof record.description !== "string" || record.description.trim().length === 0) throw new Error("shell_exec requires non-empty string field \"description\"");
2527
2534
  return {
2528
2535
  script: record.script,
2529
2536
  shellId: asString(record.shellId),
@@ -3073,8 +3080,11 @@ var ChildSupervisor = class ChildSupervisor {
3073
3080
  if (this.jobs.has(id)) continue;
3074
3081
  try {
3075
3082
  await this.restoreJob(id);
3076
- } catch {
3077
- await this.deletePersistedJob(id);
3083
+ } catch (error) {
3084
+ this.options.emit({
3085
+ type: "error",
3086
+ message: `Failed to restore subagent "${id}": ${errorMessage(error)}`
3087
+ });
3078
3088
  }
3079
3089
  }
3080
3090
  }
@@ -3084,15 +3094,15 @@ var ChildSupervisor = class ChildSupervisor {
3084
3094
  if (meta?.closedPhase) return;
3085
3095
  const checkpoint = await this.childSessionStore(id).loadCheckpoint();
3086
3096
  if (!meta || !checkpoint) throw new Error("incomplete persisted subagent");
3087
- const job = this.reassembleJob(id, meta, checkpoint);
3097
+ const provider = await this.createChildProvider(checkpoint.model);
3098
+ const job = this.reassembleJob(id, meta, checkpoint, provider);
3088
3099
  this.trackTurn(job, job.session.resume(meta.metadata ? { metadata: meta.metadata } : {}));
3089
3100
  this.settleJob(job);
3090
3101
  await job.ownSupervisor.restore();
3091
3102
  }
3092
3103
  /** Shared by restore and resume: rebuild a persisted child's job and session from its checkpoint. */
3093
- reassembleJob(id, meta, checkpoint) {
3094
- const parent = this.parentSession;
3095
- if (!parent) throw new Error("subagent supervisor has no owner session");
3104
+ reassembleJob(id, meta, checkpoint, provider) {
3105
+ if (!this.parentSession) throw new Error("subagent supervisor has no owner session");
3096
3106
  const profile = this.resolveProfile(meta.profileName ?? void 0);
3097
3107
  const { job, runtime } = this.assembleJob({
3098
3108
  id,
@@ -3104,7 +3114,7 @@ var ChildSupervisor = class ChildSupervisor {
3104
3114
  canSpawnSubagents: meta.canSpawnSubagents !== false
3105
3115
  });
3106
3116
  const session = AgentSession.fromCheckpoint({
3107
- provider: parent.cloneProviderRuntime(),
3117
+ provider,
3108
3118
  runtime,
3109
3119
  checkpoint
3110
3120
  }, {
@@ -3139,8 +3149,9 @@ var ChildSupervisor = class ChildSupervisor {
3139
3149
  spawnedAt: Date.now(),
3140
3150
  ...meta.canSpawnSubagents === false ? { canSpawnSubagents: false } : {}
3141
3151
  };
3152
+ const provider = await this.createChildProvider(checkpoint.model);
3142
3153
  await this.options.store.writeJson(this.childStoreKey(id, "job.json"), liveMeta);
3143
- const job = this.reassembleJob(id, liveMeta, checkpoint);
3154
+ const job = this.reassembleJob(id, liveMeta, checkpoint, provider);
3144
3155
  this.trackTurn(job, job.session.send([{
3145
3156
  type: "text",
3146
3157
  text: message
@@ -3181,8 +3192,10 @@ var ChildSupervisor = class ChildSupervisor {
3181
3192
  if (this.isDisposed) throw new Error("owner session is closing");
3182
3193
  if (this.jobs.size >= this.options.maxLiveSubagents) throw new Error(`at most ${this.options.maxLiveSubagents} running subagents per session; abort one or wait for a result`);
3183
3194
  const profile = this.resolveProfile(input.profileName);
3184
- const id = createId();
3195
+ const model = structuredClone(profile.model ?? parent.modelSelection);
3185
3196
  const metadata = parent.actionMetadata();
3197
+ const provider = await this.createChildProvider(model);
3198
+ const id = createId();
3186
3199
  const profileName = input.profileName ?? null;
3187
3200
  const spawnedAt = Date.now();
3188
3201
  const canSpawnSubagents = !input.isSpawnForbidden && profile.canSpawnSubagents !== false;
@@ -3203,8 +3216,8 @@ var ChildSupervisor = class ChildSupervisor {
3203
3216
  ...canSpawnSubagents ? {} : { canSpawnSubagents }
3204
3217
  });
3205
3218
  const session = new AgentSession({
3206
- provider: parent.cloneProviderRuntime(),
3207
- model: profile.model ?? structuredClone(parent.modelSelection),
3219
+ provider,
3220
+ model,
3208
3221
  cwd: this.options.cwd,
3209
3222
  runtime,
3210
3223
  state: this.options.agent.initialState()
@@ -3221,6 +3234,19 @@ var ChildSupervisor = class ChildSupervisor {
3221
3234
  this.settleJob(job);
3222
3235
  return job;
3223
3236
  }
3237
+ async createChildProvider(model) {
3238
+ const parent = this.parentSession;
3239
+ if (!parent || this.isDisposed) throw new Error("owner session is closing");
3240
+ const provider = model.providerId === parent.modelSelection.providerId ? parent.cloneProviderRuntime() : await this.options.createRuntime({
3241
+ providerId: model.providerId,
3242
+ model
3243
+ });
3244
+ if (this.isDisposed) {
3245
+ await provider.dispose?.();
3246
+ throw new Error("owner session is closing");
3247
+ }
3248
+ return provider;
3249
+ }
3224
3250
  /**
3225
3251
  * Everything spawn and restore share: the command tree (identical to the
3226
3252
  * owner's — children spawn, message, and observe exactly like any session),
@@ -3336,10 +3362,6 @@ var ChildSupervisor = class ChildSupervisor {
3336
3362
  loadCheckpoint: () => this.options.store.readJson(this.childStoreKey(childId, "checkpoint.json"))
3337
3363
  };
3338
3364
  }
3339
- async deletePersistedJob(id) {
3340
- await this.options.store.delete(this.childStoreKey(id, "checkpoint.json")).catch(noop);
3341
- await this.options.store.delete(this.childStoreKey(id, "job.json")).catch(noop);
3342
- }
3343
3365
  /** Shared spawn/resume foreground behaviour: announce the id, wire abort and stdin steers, wait for close, report the outcome. */
3344
3366
  async attendChild(job, ctx) {
3345
3367
  const { io, isJson, signal, stdinStream } = ctx;
@@ -4250,6 +4272,7 @@ var AgentTransportBindingImpl = class {
4250
4272
  shellOptions: this.shellOptions,
4251
4273
  prepareShell: this.prepareShell,
4252
4274
  sessionOptions: this.sessionOptions,
4275
+ createRuntime: (selection) => this.createRuntime(selection),
4253
4276
  notifyParentOnIdle: this.notifyParentOnIdle,
4254
4277
  store: provisionalHost.store,
4255
4278
  storePrefix: `agent-sessions/${agentSessionId}`,
@@ -1,4 +1,4 @@
1
- import { n as AgentServerTransport, t as AgentClientTransport } from "./transport-vzA9vMxT.mjs";
1
+ import { n as AgentServerTransport, t as AgentClientTransport } from "./transport-Qj50JTjx.mjs";
2
2
  import { Readable, Writable } from "node:stream";
3
3
  //#region src/stdio-transport.d.ts
4
4
  declare function createStdioClientTransport(readable: Readable, writable: Writable): AgentClientTransport;
@@ -196,6 +196,7 @@ interface SubagentProfile<State = unknown> {
196
196
  readonly?: boolean;
197
197
  /** When false, the child cannot spawn subagents of its own (communication and reads remain). */
198
198
  canSpawnSubagents?: boolean;
199
+ /** Selects a model from any provider registered on AgentServer; omitted inherits the parent. */
199
200
  model?: ModelSelection;
200
201
  }
201
202
  interface AgentHarness<State = unknown> {
@@ -205,8 +206,8 @@ interface AgentHarness<State = unknown> {
205
206
  host(ctx: AgentHarnessContext<State> | AgentHostContext<State>): Host | Promise<Host>;
206
207
  commands?(ctx: AgentHarnessContext<State>): Promise<Command[]> | Command[];
207
208
  /**
208
- * Named subagent profiles for `demi agent`. Omitted: one implicit profile
209
- * named `default` that fully inherits the parent's setup.
209
+ * Named subagent profiles for `demi agent`. Omitting --profile always
210
+ * inherits the parent, independently of this list.
210
211
  */
211
212
  agents?(ctx: AgentHarnessContext<State>): Promise<SubagentProfile<State>[]> | SubagentProfile<State>[];
212
213
  systemPrompt(ctx: AgentSystemPromptContext<State>): Promise<string> | string;
@@ -1,4 +1,4 @@
1
- import { I as ModelSwitchApply, c as ConversationSummary, n as AgentServerTransport, p as AbortResult, s as ClientSessionEvent, t as AgentClientTransport, x as AgentMetadata } from "./transport-vzA9vMxT.mjs";
1
+ import { I as ModelSwitchApply, c as ConversationSummary, n as AgentServerTransport, p as AbortResult, s as ClientSessionEvent, t as AgentClientTransport, x as AgentMetadata } from "./transport-Qj50JTjx.mjs";
2
2
  import { ProviderSelection } from "@demicodes/provider";
3
3
  import { Block, UserContentBlock } from "@demicodes/core";
4
4
  //#region src/client.d.ts
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.24.1",
4
+ "version": "0.25.1",
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.24.1",
23
- "@demicodes/provider": "^0.24.1",
24
- "@demicodes/shell": "^0.24.1",
25
- "@demicodes/utils": "^0.24.1",
22
+ "@demicodes/core": "^0.25.1",
23
+ "@demicodes/provider": "^0.25.1",
24
+ "@demicodes/shell": "^0.25.1",
25
+ "@demicodes/utils": "^0.25.1",
26
26
  "zod": "^4.0.0"
27
27
  },
28
28
  "license": "Apache-2.0",