@demicodes/agent 0.25.7 → 0.25.9
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 +11 -0
- package/dist/index.mjs +34 -3
- package/package.json +5 -5
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
|
@@ -2727,6 +2727,7 @@ async function finishShellToolResult(environment, result, ctx, previewBudget = s
|
|
|
2727
2727
|
}
|
|
2728
2728
|
function shellCommandHandleRequired(result, budgetTokens) {
|
|
2729
2729
|
if (result.status === "running") return true;
|
|
2730
|
+
if (result.status === "exited" && (result.binaryStdout || result.binaryStderr)) return true;
|
|
2730
2731
|
const preview = boundedPreview(result.output.text, budgetTokens);
|
|
2731
2732
|
const maxChars = Math.max(0, Math.floor(budgetTokens * APPROX_CHARS_PER_TOKEN));
|
|
2732
2733
|
return preview.truncated || result.output.truncated || result.output.bytes > maxChars || result.stdout.truncated || result.stderr.truncated;
|
|
@@ -2848,6 +2849,8 @@ const INHERIT_PROFILE = {
|
|
|
2848
2849
|
var ChildSupervisor = class ChildSupervisor {
|
|
2849
2850
|
options;
|
|
2850
2851
|
jobs = /* @__PURE__ */ new Map();
|
|
2852
|
+
/** Shell commandId → the child that command hosts ('' while its spawn or resume is starting). */
|
|
2853
|
+
childByCommandId = /* @__PURE__ */ new Map();
|
|
2851
2854
|
parentSession = null;
|
|
2852
2855
|
isDisposed = false;
|
|
2853
2856
|
constructor(options) {
|
|
@@ -2878,7 +2881,7 @@ var ChildSupervisor = class ChildSupervisor {
|
|
|
2878
2881
|
const profileNames = this.configuredProfileNames();
|
|
2879
2882
|
return {
|
|
2880
2883
|
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.
|
|
2884
|
+
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
2885
|
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
2886
|
failureOutput: "non-zero exit with the abort or failure reason on stderr",
|
|
2884
2887
|
input: {
|
|
@@ -2894,12 +2897,13 @@ var ChildSupervisor = class ChildSupervisor {
|
|
|
2894
2897
|
text: z.string()
|
|
2895
2898
|
}) },
|
|
2896
2899
|
runningHint: SPAWN_RUNNING_HINT,
|
|
2897
|
-
run: async ({ parsed, io, signal, stdinStream }) => {
|
|
2900
|
+
run: async ({ parsed, io, signal, stdinStream, commandId }) => {
|
|
2898
2901
|
const prompt = String(parsed.values.prompt ?? "").trim();
|
|
2899
2902
|
if (!prompt) {
|
|
2900
2903
|
await io.stderr("demi agent: prompt must not be empty\n");
|
|
2901
2904
|
return { exitCode: 1 };
|
|
2902
2905
|
}
|
|
2906
|
+
if (!await this.claimHostingCommand(commandId, io, "demi agent")) return { exitCode: 1 };
|
|
2903
2907
|
let job;
|
|
2904
2908
|
try {
|
|
2905
2909
|
job = await this.spawn({
|
|
@@ -2909,9 +2913,11 @@ var ChildSupervisor = class ChildSupervisor {
|
|
|
2909
2913
|
isSpawnForbidden: parsed.values["no-subagents"] === true
|
|
2910
2914
|
});
|
|
2911
2915
|
} catch (error) {
|
|
2916
|
+
this.releaseHostingCommand(commandId);
|
|
2912
2917
|
await io.stderr(`demi agent: ${errorMessage(error)}\n`);
|
|
2913
2918
|
return { exitCode: 1 };
|
|
2914
2919
|
}
|
|
2920
|
+
this.recordHostedChild(commandId, job.id);
|
|
2915
2921
|
return this.attendChild(job, {
|
|
2916
2922
|
io,
|
|
2917
2923
|
isJson: parsed.json === true,
|
|
@@ -3021,20 +3027,23 @@ var ChildSupervisor = class ChildSupervisor {
|
|
|
3021
3027
|
text: z.string()
|
|
3022
3028
|
}) },
|
|
3023
3029
|
runningHint: SPAWN_RUNNING_HINT,
|
|
3024
|
-
run: async ({ parsed, io, signal, stdinStream }) => {
|
|
3030
|
+
run: async ({ parsed, io, signal, stdinStream, commandId }) => {
|
|
3025
3031
|
const id = String(parsed.values.id);
|
|
3026
3032
|
const message = String(parsed.values.message ?? "").trim();
|
|
3027
3033
|
if (!message) {
|
|
3028
3034
|
await io.stderr("demi agent resume: message must not be empty\n");
|
|
3029
3035
|
return { exitCode: 1 };
|
|
3030
3036
|
}
|
|
3037
|
+
if (!await this.claimHostingCommand(commandId, io, "demi agent resume")) return { exitCode: 1 };
|
|
3031
3038
|
let job;
|
|
3032
3039
|
try {
|
|
3033
3040
|
job = await this.resumeArchived(id, message);
|
|
3034
3041
|
} catch (error) {
|
|
3042
|
+
this.releaseHostingCommand(commandId);
|
|
3035
3043
|
await io.stderr(`demi agent resume: ${errorMessage(error)}\n`);
|
|
3036
3044
|
return { exitCode: 1 };
|
|
3037
3045
|
}
|
|
3046
|
+
this.recordHostedChild(commandId, job.id);
|
|
3038
3047
|
return this.attendChild(job, {
|
|
3039
3048
|
io,
|
|
3040
3049
|
isJson: parsed.json === true,
|
|
@@ -3432,6 +3441,28 @@ var ChildSupervisor = class ChildSupervisor {
|
|
|
3432
3441
|
loadCheckpoint: () => this.options.store.readJson(this.childStoreKey(childId, "checkpoint.json"))
|
|
3433
3442
|
};
|
|
3434
3443
|
}
|
|
3444
|
+
/**
|
|
3445
|
+
* One shell command hosts at most one child lifecycle, so `shell_abort` on
|
|
3446
|
+
* that command and aborting that child are the same act. A script that loops
|
|
3447
|
+
* or chains spawns would otherwise start the next child as soon as the
|
|
3448
|
+
* previous one is aborted, outliving every abort aimed at it.
|
|
3449
|
+
*/
|
|
3450
|
+
async claimHostingCommand(commandId, io, verb) {
|
|
3451
|
+
if (commandId === null) return true;
|
|
3452
|
+
const hostedId = this.childByCommandId.get(commandId);
|
|
3453
|
+
if (hostedId === void 0) {
|
|
3454
|
+
this.childByCommandId.set(commandId, "");
|
|
3455
|
+
return true;
|
|
3456
|
+
}
|
|
3457
|
+
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`);
|
|
3458
|
+
return false;
|
|
3459
|
+
}
|
|
3460
|
+
releaseHostingCommand(commandId) {
|
|
3461
|
+
if (commandId !== null) this.childByCommandId.delete(commandId);
|
|
3462
|
+
}
|
|
3463
|
+
recordHostedChild(commandId, childId) {
|
|
3464
|
+
if (commandId !== null) this.childByCommandId.set(commandId, childId);
|
|
3465
|
+
}
|
|
3435
3466
|
/** Shared spawn/resume foreground behaviour: announce the id, wire abort and stdin steers, wait for close, report the outcome. */
|
|
3436
3467
|
async attendChild(job, ctx) {
|
|
3437
3468
|
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.
|
|
4
|
+
"version": "0.25.9",
|
|
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.
|
|
23
|
-
"@demicodes/provider": "^0.25.
|
|
24
|
-
"@demicodes/shell": "^0.25.
|
|
25
|
-
"@demicodes/utils": "^0.25.
|
|
22
|
+
"@demicodes/core": "^0.25.9",
|
|
23
|
+
"@demicodes/provider": "^0.25.9",
|
|
24
|
+
"@demicodes/shell": "^0.25.9",
|
|
25
|
+
"@demicodes/utils": "^0.25.9",
|
|
26
26
|
"zod": "^4.0.0"
|
|
27
27
|
},
|
|
28
28
|
"license": "Apache-2.0",
|