@qlzt/dsh-subagent 0.0.0-stage → 0.2.1-alpha.3
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/LICENSE +21 -0
- package/README.i18n.yaml +94 -0
- package/README.md +215 -2
- package/README.zh.md +216 -0
- package/lib/index.js +3333 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +991 -0
- package/lib/typert.remote-client.d.ts +25 -0
- package/lib/typert.remote-client.js +114 -0
- package/lib/types/activation.d.ts +114 -0
- package/lib/types/activation.js +112 -0
- package/lib/types/archive-admission.d.ts +16 -0
- package/lib/types/archive-admission.js +151 -0
- package/lib/types/assistant-output.d.ts +48 -0
- package/lib/types/assistant-output.js +73 -0
- package/lib/types/catalog.d.ts +92 -0
- package/lib/types/catalog.js +113 -0
- package/lib/types/child-agent.d.ts +154 -0
- package/lib/types/child-agent.js +211 -0
- package/lib/types/client.d.ts +8 -0
- package/lib/types/client.js +7 -0
- package/lib/types/continuation-messages.d.ts +63 -0
- package/lib/types/continuation-messages.js +114 -0
- package/lib/types/control-types.d.ts +142 -0
- package/lib/types/control-types.js +8 -0
- package/lib/types/control.d.ts +45 -0
- package/lib/types/control.js +79 -0
- package/lib/types/depth.d.ts +31 -0
- package/lib/types/depth.js +39 -0
- package/lib/types/descriptor.d.ts +105 -0
- package/lib/types/descriptor.js +192 -0
- package/lib/types/error.d.ts +11 -0
- package/lib/types/error.js +14 -0
- package/lib/types/index.d.ts +319 -0
- package/lib/types/index.js +455 -0
- package/lib/types/internal.d.ts +58 -0
- package/lib/types/internal.js +58 -0
- package/lib/types/lifecycle.d.ts +83 -0
- package/lib/types/lifecycle.js +115 -0
- package/lib/types/list-children.d.ts +36 -0
- package/lib/types/list-children.js +166 -0
- package/lib/types/manager.d.ts +247 -0
- package/lib/types/manager.js +1294 -0
- package/lib/types/out-of-process.d.ts +92 -0
- package/lib/types/out-of-process.js +178 -0
- package/lib/types/projection-types.d.ts +85 -0
- package/lib/types/projection-types.js +7 -0
- package/lib/types/projection.d.ts +100 -0
- package/lib/types/projection.js +157 -0
- package/lib/types/structured.d.ts +49 -0
- package/lib/types/structured.js +130 -0
- package/lib/types/types.d.ts +353 -0
- package/lib/types/types.js +19 -0
- package/package.json +136 -4
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parent-owned durable subagent catalog events and their chunked projection.
|
|
3
|
+
*
|
|
4
|
+
* @module @qlzt/dsh-subagent/catalog
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import type { ChunkedList } from '@qlzt/dsh-chunked-list';
|
|
8
|
+
import type { Session, SessionEvent, SessionHeader, SessionId, SessionLogOffset } from '@qlzt/dsh-session';
|
|
9
|
+
import type { SubagentCatalogEntry } from './projection-types.ts';
|
|
10
|
+
/** Catalog payload version emitted by local child creation. */
|
|
11
|
+
export declare const SUBAGENT_CATALOG_VERSION = 0;
|
|
12
|
+
type KnownCatalogMode = {
|
|
13
|
+
readonly mode: 'one-shot';
|
|
14
|
+
readonly label?: string;
|
|
15
|
+
} | {
|
|
16
|
+
readonly mode: 'continuable';
|
|
17
|
+
readonly label: string;
|
|
18
|
+
};
|
|
19
|
+
/** Parent catalog v0 records local modes, v1 adds unknown children, and v2 records external executions. */
|
|
20
|
+
export type SubagentCatalogEvent = {
|
|
21
|
+
readonly childId: SessionId;
|
|
22
|
+
readonly childCreatedAt: number;
|
|
23
|
+
} & (({
|
|
24
|
+
readonly version: 0;
|
|
25
|
+
} & KnownCatalogMode) | ({
|
|
26
|
+
readonly version: 1;
|
|
27
|
+
} & (KnownCatalogMode | {
|
|
28
|
+
readonly mode: 'unknown';
|
|
29
|
+
readonly label?: string;
|
|
30
|
+
})) | {
|
|
31
|
+
readonly version: 2;
|
|
32
|
+
readonly mode: 'external';
|
|
33
|
+
readonly label?: string;
|
|
34
|
+
});
|
|
35
|
+
declare module '@qlzt/dsh-session/types' {
|
|
36
|
+
interface SessionEventMap {
|
|
37
|
+
/**
|
|
38
|
+
* A direct child's identity and available discovery fields.
|
|
39
|
+
* @param data - versioned parent-owned catalog entry.
|
|
40
|
+
*/
|
|
41
|
+
'subagent/catalog': SubagentCatalogEvent;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Host fold state for one parent catalog. */
|
|
45
|
+
export interface SubagentCatalogState {
|
|
46
|
+
readonly inheritedEventCount: SessionLogOffset;
|
|
47
|
+
readonly head?: ChunkedList<SubagentCatalogEvent> | undefined;
|
|
48
|
+
}
|
|
49
|
+
declare module '@qlzt/dsh-session-projection/types' {
|
|
50
|
+
interface SessionProjectionStateMap {
|
|
51
|
+
subagentCatalog: SubagentCatalogState;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Materialize complete and unknown-mode child identities from parent catalog events.
|
|
56
|
+
* @param state - parent catalog fold state.
|
|
57
|
+
* @returns current direct-child rows in parent catalog event order.
|
|
58
|
+
*/
|
|
59
|
+
declare function subagentCatalogEntries(state: SubagentCatalogState): SubagentCatalogEntry[];
|
|
60
|
+
/** Parent-owned direct-child catalog projection; invalid own facts reject restoration. */
|
|
61
|
+
export declare const subagentCatalogProjectionDefinition: {
|
|
62
|
+
key: "subagentCatalog";
|
|
63
|
+
stateSchema: z.ZodType<SubagentCatalogState, unknown, z.core.$ZodTypeInternals<SubagentCatalogState, unknown>>;
|
|
64
|
+
init: (_header: SessionHeader, inheritedEventCount: SessionLogOffset) => {
|
|
65
|
+
inheritedEventCount: SessionLogOffset;
|
|
66
|
+
};
|
|
67
|
+
apply: (state: NoInfer<SubagentCatalogState>, event: SessionEvent) => SubagentCatalogState;
|
|
68
|
+
stateVersion: number;
|
|
69
|
+
wire: {
|
|
70
|
+
viewSchema: z.ZodType<SubagentCatalogEntry[], unknown, z.core.$ZodTypeInternals<SubagentCatalogEntry[], unknown>>;
|
|
71
|
+
view: typeof subagentCatalogEntries;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Append a complete direct-child discovery fact to its parent Session.
|
|
76
|
+
* @param parent - durable direct parent receiving the discovery fact.
|
|
77
|
+
* @param child - established child's immutable Session metadata.
|
|
78
|
+
* @param descriptor - mode-discriminated creation label frozen with the child.
|
|
79
|
+
*/
|
|
80
|
+
export declare function establishCatalogChild(parent: Session, child: SessionHeader, descriptor: {
|
|
81
|
+
readonly mode: 'continuable';
|
|
82
|
+
readonly label: string;
|
|
83
|
+
}): void;
|
|
84
|
+
/**
|
|
85
|
+
* Record an external execution without a local child Session.
|
|
86
|
+
* @param parent - durable direct parent receiving the discovery fact.
|
|
87
|
+
* @param childId - identity returned by the external provider.
|
|
88
|
+
* @param label - display label assigned by the caller.
|
|
89
|
+
*/
|
|
90
|
+
export declare function establishExternalCatalogChild(parent: Session, childId: SessionId, label: string): void;
|
|
91
|
+
export {};
|
|
92
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parent-owned durable subagent catalog events and their chunked projection.
|
|
3
|
+
*
|
|
4
|
+
* @module @qlzt/dsh-subagent/catalog
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { appendChunkedList, chunkedListSchema, iterateChunkedList } from '@qlzt/dsh-chunked-list';
|
|
8
|
+
/** Catalog payload version emitted by local child creation. */
|
|
9
|
+
export const SUBAGENT_CATALOG_VERSION = 0;
|
|
10
|
+
const sessionIdSchema = z.string();
|
|
11
|
+
const oneShotCatalogSchema = z.object({
|
|
12
|
+
version: z.union([z.literal(0), z.literal(1)]),
|
|
13
|
+
childId: sessionIdSchema,
|
|
14
|
+
childCreatedAt: z.number().int().nonnegative(),
|
|
15
|
+
mode: z.literal('one-shot'),
|
|
16
|
+
label: z.string().optional(),
|
|
17
|
+
}).strict();
|
|
18
|
+
const continuableCatalogSchema = z.object({
|
|
19
|
+
version: z.union([z.literal(0), z.literal(1)]),
|
|
20
|
+
childId: sessionIdSchema,
|
|
21
|
+
childCreatedAt: z.number().int().nonnegative(),
|
|
22
|
+
mode: z.literal('continuable'),
|
|
23
|
+
label: z.string(),
|
|
24
|
+
}).strict();
|
|
25
|
+
const externalCatalogSchema = oneShotCatalogSchema.extend({ version: z.literal(2), mode: z.literal('external') });
|
|
26
|
+
const unknownCatalogSchema = oneShotCatalogSchema.extend({ version: z.literal(1), mode: z.literal('unknown') });
|
|
27
|
+
const eventDataSchema = z.union([
|
|
28
|
+
oneShotCatalogSchema,
|
|
29
|
+
externalCatalogSchema,
|
|
30
|
+
continuableCatalogSchema,
|
|
31
|
+
unknownCatalogSchema,
|
|
32
|
+
]);
|
|
33
|
+
const viewSchema = z.array(z.union([
|
|
34
|
+
oneShotCatalogSchema.omit({ version: true, childId: true, childCreatedAt: true }).extend({
|
|
35
|
+
id: sessionIdSchema,
|
|
36
|
+
createdAt: oneShotCatalogSchema.shape.childCreatedAt,
|
|
37
|
+
}),
|
|
38
|
+
externalCatalogSchema.omit({ version: true, childId: true, childCreatedAt: true }).extend({
|
|
39
|
+
id: sessionIdSchema,
|
|
40
|
+
createdAt: externalCatalogSchema.shape.childCreatedAt,
|
|
41
|
+
}),
|
|
42
|
+
continuableCatalogSchema.omit({ version: true, childId: true, childCreatedAt: true }).extend({
|
|
43
|
+
id: sessionIdSchema,
|
|
44
|
+
createdAt: continuableCatalogSchema.shape.childCreatedAt,
|
|
45
|
+
}),
|
|
46
|
+
unknownCatalogSchema.omit({ version: true, childId: true, childCreatedAt: true }).extend({
|
|
47
|
+
id: sessionIdSchema,
|
|
48
|
+
createdAt: unknownCatalogSchema.shape.childCreatedAt,
|
|
49
|
+
}),
|
|
50
|
+
]));
|
|
51
|
+
const stateSchema = z.object({
|
|
52
|
+
inheritedEventCount: z.number().int().nonnegative(),
|
|
53
|
+
head: chunkedListSchema(eventDataSchema).optional(),
|
|
54
|
+
}).strict();
|
|
55
|
+
/**
|
|
56
|
+
* Materialize complete and unknown-mode child identities from parent catalog events.
|
|
57
|
+
* @param state - parent catalog fold state.
|
|
58
|
+
* @returns current direct-child rows in parent catalog event order.
|
|
59
|
+
*/
|
|
60
|
+
function subagentCatalogEntries(state) {
|
|
61
|
+
const entries = [];
|
|
62
|
+
for (const data of iterateChunkedList(state.head)) {
|
|
63
|
+
const { version: _version, childId, childCreatedAt, ...descriptor } = data;
|
|
64
|
+
entries.push({ id: childId, createdAt: childCreatedAt, ...descriptor });
|
|
65
|
+
}
|
|
66
|
+
return entries;
|
|
67
|
+
}
|
|
68
|
+
/** Parent-owned direct-child catalog projection; invalid own facts reject restoration. */
|
|
69
|
+
export const subagentCatalogProjectionDefinition = {
|
|
70
|
+
key: 'subagentCatalog',
|
|
71
|
+
stateSchema,
|
|
72
|
+
init: (_header, inheritedEventCount) => ({ inheritedEventCount }),
|
|
73
|
+
apply: (state, event) => {
|
|
74
|
+
if (event.type !== 'subagent/catalog' || event.seq < state.inheritedEventCount)
|
|
75
|
+
return state;
|
|
76
|
+
return { ...state, head: appendChunkedList(state.head, eventDataSchema.parse(event.data)) };
|
|
77
|
+
},
|
|
78
|
+
stateVersion: 6,
|
|
79
|
+
wire: { viewSchema, view: subagentCatalogEntries },
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Append a complete direct-child discovery fact to its parent Session.
|
|
83
|
+
* @param parent - durable direct parent receiving the discovery fact.
|
|
84
|
+
* @param child - established child's immutable Session metadata.
|
|
85
|
+
* @param descriptor - mode-discriminated creation label frozen with the child.
|
|
86
|
+
*/
|
|
87
|
+
export function establishCatalogChild(parent, child, descriptor) {
|
|
88
|
+
parent.append('subagent/catalog', {
|
|
89
|
+
version: SUBAGENT_CATALOG_VERSION,
|
|
90
|
+
childId: child.id,
|
|
91
|
+
childCreatedAt: child.createdAt,
|
|
92
|
+
mode: descriptor.mode,
|
|
93
|
+
label: descriptor.label,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** Catalog payload version emitted by external execution creation. */
|
|
97
|
+
const EXTERNAL_SUBAGENT_CATALOG_VERSION = 2;
|
|
98
|
+
/**
|
|
99
|
+
* Record an external execution without a local child Session.
|
|
100
|
+
* @param parent - durable direct parent receiving the discovery fact.
|
|
101
|
+
* @param childId - identity returned by the external provider.
|
|
102
|
+
* @param label - display label assigned by the caller.
|
|
103
|
+
*/
|
|
104
|
+
export function establishExternalCatalogChild(parent, childId, label) {
|
|
105
|
+
parent.append('subagent/catalog', {
|
|
106
|
+
version: EXTERNAL_SUBAGENT_CATALOG_VERSION,
|
|
107
|
+
childId,
|
|
108
|
+
childCreatedAt: Date.now(),
|
|
109
|
+
mode: 'external',
|
|
110
|
+
label,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared in-process child composition: the delegation-depth budget, the
|
|
3
|
+
* durable session metadata, the resolved child `AgentOptions`, the delegated
|
|
4
|
+
* policy seed, and the scoped setup used by local activations.
|
|
5
|
+
*
|
|
6
|
+
* @module @qlzt/dsh-subagent/child-agent
|
|
7
|
+
*/
|
|
8
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
9
|
+
import type { Agent, AgentOptions, CreateAgentOptions } from '@qlzt/dsh-agent';
|
|
10
|
+
import type { SandboxMode } from '@qlzt/dsh-sandbox';
|
|
11
|
+
import type { Session, SessionId } from '@qlzt/dsh-session';
|
|
12
|
+
import type { ToolRestriction } from '@qlzt/dsh-tools';
|
|
13
|
+
/** Thrown when starting a child would exceed the requested depth cap. */
|
|
14
|
+
export declare class SubagentDepthError extends Error {
|
|
15
|
+
readonly attemptedDepth: number;
|
|
16
|
+
readonly maxDepth: number;
|
|
17
|
+
constructor(attemptedDepth: number, maxDepth: number);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Resolve the child's delegation depth from its parent and enforce an optional
|
|
21
|
+
* cap. The persisted parent header is the monotone floor, so a resumed parent
|
|
22
|
+
* cannot delegate as if it were top-level.
|
|
23
|
+
* @param parent - the delegating parent agent.
|
|
24
|
+
* @param maxDepth - optional absolute cap the resolved depth must not exceed.
|
|
25
|
+
* @returns the child's non-negative safe-integer depth.
|
|
26
|
+
* @throws {SubagentDepthError} when the resolved depth exceeds `maxDepth`.
|
|
27
|
+
* @throws {RangeError} when the resolved depth leaves the safe-integer range.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveChildDepth(parent: Agent, maxDepth: number | undefined): number;
|
|
30
|
+
/**
|
|
31
|
+
* Resolve the parent values inherited by a child. The latest request header
|
|
32
|
+
* owns provider, model, and reasoning effort after request-time selection;
|
|
33
|
+
* creation options remain the fallback before the first request and retain
|
|
34
|
+
* the configured output-token limit.
|
|
35
|
+
* @param parent - delegating parent Agent.
|
|
36
|
+
* @returns detached Agent options for child-option merging.
|
|
37
|
+
*/
|
|
38
|
+
export declare function parentAgentOptionsForDelegation(parent: Agent): AgentOptions;
|
|
39
|
+
/**
|
|
40
|
+
* Resolve the child's `AgentOptions`: the parent's provider/model,
|
|
41
|
+
* reasoning-effort, and maxTokens values unless the request overrides them,
|
|
42
|
+
* stamped with the child's own delegation depth. Changing the route without
|
|
43
|
+
* naming an effort clears the parent's route-owned effort so the selected
|
|
44
|
+
* model resolves its own default.
|
|
45
|
+
* @param parent - the delegating parent whose route the child inherits.
|
|
46
|
+
* @param requested - per-child overrides, if any.
|
|
47
|
+
* @param childDepth - the resolved delegation depth to stamp.
|
|
48
|
+
* @returns the resolved options for `ctx.agents.create()`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveChildAgentOptions(parent: Agent, requested: AgentOptions | undefined, childDepth: number): AgentOptions;
|
|
51
|
+
/**
|
|
52
|
+
* Build the child session's durable creation metadata: the parent's workspace,
|
|
53
|
+
* its direct lineage, coarse product origin, the recursion budget that must
|
|
54
|
+
* survive persistence, the seed boundary that separates inherited parent
|
|
55
|
+
* history from child work, and the composition the child runs under.
|
|
56
|
+
*
|
|
57
|
+
* The preset is read from the parent's LIVE scope chain rather than from its
|
|
58
|
+
* header, because a parent that switched preset while blank runs on the newer
|
|
59
|
+
* composition and its header still names the older one. Recording it is what
|
|
60
|
+
* makes a child's history reconstructable: without it a cold read of the child
|
|
61
|
+
* resolves the deployment default and rebuilds turns under a tool set the
|
|
62
|
+
* child never had.
|
|
63
|
+
* @param parent - the delegating parent agent.
|
|
64
|
+
* @param childDepth - the resolved delegation depth to persist.
|
|
65
|
+
* @param isSeeded - whether this child inherits a parent-log prefix, including an explicitly empty one.
|
|
66
|
+
* @returns the `meta` for `ctx.agents.create()`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function childSessionMeta(parent: Agent, childDepth: number, isSeeded: boolean): NonNullable<CreateAgentOptions['meta']>;
|
|
69
|
+
/** The scoped composition a child agent's creation window applies. */
|
|
70
|
+
export interface ChildComposition {
|
|
71
|
+
/** Per-child persona shadowing the deployment persona. */
|
|
72
|
+
readonly persona?: string | undefined;
|
|
73
|
+
/** Per-child tool scoping. */
|
|
74
|
+
readonly toolFilter?: ToolRestriction | undefined;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Model-facing delegation-scope statement for every in-process child. A
|
|
78
|
+
* runtime-context contribution rather than a system-prompt section, so the
|
|
79
|
+
* deployment's system prompt stays uniform across parents and children.
|
|
80
|
+
*/
|
|
81
|
+
export declare const SUBAGENT_DELEGATION_CONTEXT: string;
|
|
82
|
+
/**
|
|
83
|
+
* Compose one child inside its creation window: join its parent's preset,
|
|
84
|
+
* register the fixed delegation-scope statement, then apply the child's own
|
|
85
|
+
* shadowing persona section and tool restriction, all owned by the child's
|
|
86
|
+
* scope and therefore invisible to its parent and siblings. Creation and cold
|
|
87
|
+
* resume both pass through here.
|
|
88
|
+
*
|
|
89
|
+
* The join comes first and the child's own registrations second, which is the
|
|
90
|
+
* order the layering already implies — the nearest scope wins a name, and a
|
|
91
|
+
* per-child restriction intersects with everything its chain admits — but
|
|
92
|
+
* stating it here keeps the two steps from being read as independent.
|
|
93
|
+
*
|
|
94
|
+
* The join and the per-child registrations live in ONE call because a child
|
|
95
|
+
* composed without the join is exactly the defect this function exists to
|
|
96
|
+
* prevent: with every model-facing row on the agent plane, a child that joins
|
|
97
|
+
* no preset sees an empty tool registry and none of its parent's prompt
|
|
98
|
+
* sections. Taking the parent as a parameter is what makes that omission
|
|
99
|
+
* unrepresentable at the call sites.
|
|
100
|
+
* @param childCtx - the child agent's scoped creation context.
|
|
101
|
+
* @param parent - the delegating parent whose composition the child joins.
|
|
102
|
+
* @param composition - the per-child persona and tool filter to install.
|
|
103
|
+
*/
|
|
104
|
+
export declare function applyChildComposition(childCtx: Context, parent: Agent, composition: ChildComposition): void;
|
|
105
|
+
/** Policy seeded onto a child session's log at the delegation boundary. */
|
|
106
|
+
export interface DelegatedPolicyOverrides {
|
|
107
|
+
/**
|
|
108
|
+
* The parent's current preset identity when it runs in Auto or Full access;
|
|
109
|
+
* the child keeps it under the pinned `never` approval policy.
|
|
110
|
+
*/
|
|
111
|
+
readonly permissionPreset: 'auto' | 'danger-full-access' | undefined;
|
|
112
|
+
/** The parent session's explicit sandbox-mode override, or `undefined` without one. */
|
|
113
|
+
readonly sandboxMode: SandboxMode | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* `'never'` whenever the approval capability is composed, `undefined`
|
|
116
|
+
* otherwise: a delegated child acts only within the sandbox scope fixed at
|
|
117
|
+
* delegation, so its asks are rejected deterministically.
|
|
118
|
+
*/
|
|
119
|
+
readonly approvalPolicy: 'never' | undefined;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Capture the permission state to seed into one delegation. Call synchronously before
|
|
123
|
+
* the child start's first await: a later parent switch belongs to the
|
|
124
|
+
* parent's future, not to this child. Auto and Full access identities are
|
|
125
|
+
* inherited only through the in-process DSH path so either can replace a stale
|
|
126
|
+
* same-bundle fork value. Only the parent session's explicit sandbox override
|
|
127
|
+
* is captured — never deployment defaults or one-shot grants — and the approval
|
|
128
|
+
* policy is pinned to `'never'` regardless of the parent's own policy.
|
|
129
|
+
* @param parent - the delegating parent agent.
|
|
130
|
+
* @returns the sandbox override (or `undefined` without one) and the approval pin.
|
|
131
|
+
*/
|
|
132
|
+
export declare function captureDelegatedPolicyOverrides(parent: Agent): DelegatedPolicyOverrides;
|
|
133
|
+
/**
|
|
134
|
+
* Append the captured delegation policy onto the child's own log as
|
|
135
|
+
* `source: 'delegation'` events inside the unpublished creation window, so the
|
|
136
|
+
* child's effective policy is reconstructable from its log alone. Appends land
|
|
137
|
+
* after any fork seed, so fresh policy wins stale seed state; later child
|
|
138
|
+
* switches still win over these events.
|
|
139
|
+
* @param childSession - the unpublished child's session.
|
|
140
|
+
* @param overrides - the policy captured at delegation.
|
|
141
|
+
*/
|
|
142
|
+
export declare function appendDelegatedPolicyOverrides(childSession: Session, overrides: DelegatedPolicyOverrides): void;
|
|
143
|
+
/** Identity and lineage inputs shared by every in-process child creation. */
|
|
144
|
+
export interface ChildCreateInputs {
|
|
145
|
+
/** The child's reserved session id. */
|
|
146
|
+
readonly sessionId: SessionId;
|
|
147
|
+
/** The delegating parent agent. */
|
|
148
|
+
readonly parent: Agent;
|
|
149
|
+
/** The resolved delegation depth. */
|
|
150
|
+
readonly childDepth: number;
|
|
151
|
+
/** How many leading seed events came from the parent's log. */
|
|
152
|
+
readonly lineageSeedLength: number;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=child-agent.d.ts.map
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared in-process child composition: the delegation-depth budget, the
|
|
3
|
+
* durable session metadata, the resolved child `AgentOptions`, the delegated
|
|
4
|
+
* policy seed, and the scoped setup used by local activations.
|
|
5
|
+
*
|
|
6
|
+
* @module @qlzt/dsh-subagent/child-agent
|
|
7
|
+
*/
|
|
8
|
+
import { delegationDepthOf } from "./depth.js";
|
|
9
|
+
/** Thrown when starting a child would exceed the requested depth cap. */
|
|
10
|
+
export class SubagentDepthError extends Error {
|
|
11
|
+
attemptedDepth;
|
|
12
|
+
maxDepth;
|
|
13
|
+
constructor(attemptedDepth, maxDepth) {
|
|
14
|
+
super(`subagent depth ${attemptedDepth} exceeds maxDepth ${maxDepth}`);
|
|
15
|
+
this.attemptedDepth = attemptedDepth;
|
|
16
|
+
this.maxDepth = maxDepth;
|
|
17
|
+
this.name = 'SubagentDepthError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the child's delegation depth from its parent and enforce an optional
|
|
22
|
+
* cap. The persisted parent header is the monotone floor, so a resumed parent
|
|
23
|
+
* cannot delegate as if it were top-level.
|
|
24
|
+
* @param parent - the delegating parent agent.
|
|
25
|
+
* @param maxDepth - optional absolute cap the resolved depth must not exceed.
|
|
26
|
+
* @returns the child's non-negative safe-integer depth.
|
|
27
|
+
* @throws {SubagentDepthError} when the resolved depth exceeds `maxDepth`.
|
|
28
|
+
* @throws {RangeError} when the resolved depth leaves the safe-integer range.
|
|
29
|
+
*/
|
|
30
|
+
export function resolveChildDepth(parent, maxDepth) {
|
|
31
|
+
const childDepth = delegationDepthOf(parent) + 1;
|
|
32
|
+
if (!Number.isSafeInteger(childDepth)) {
|
|
33
|
+
throw new RangeError('subagent child depth exceeds the safe-integer range');
|
|
34
|
+
}
|
|
35
|
+
if (maxDepth !== undefined && childDepth > maxDepth) {
|
|
36
|
+
throw new SubagentDepthError(childDepth, maxDepth);
|
|
37
|
+
}
|
|
38
|
+
return childDepth;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resolve the parent values inherited by a child. The latest request header
|
|
42
|
+
* owns provider, model, and reasoning effort after request-time selection;
|
|
43
|
+
* creation options remain the fallback before the first request and retain
|
|
44
|
+
* the configured output-token limit.
|
|
45
|
+
* @param parent - delegating parent Agent.
|
|
46
|
+
* @returns detached Agent options for child-option merging.
|
|
47
|
+
*/
|
|
48
|
+
export function parentAgentOptionsForDelegation(parent) {
|
|
49
|
+
const requestConfig = parent.session.requestHeader()?.config;
|
|
50
|
+
if (requestConfig === undefined)
|
|
51
|
+
return { ...parent.options };
|
|
52
|
+
const { provider: _createdProvider, model: _createdModel, reasoningEffort: _createdReasoningEffort, ...createdOptions } = parent.options;
|
|
53
|
+
return {
|
|
54
|
+
...createdOptions,
|
|
55
|
+
provider: requestConfig.provider,
|
|
56
|
+
model: requestConfig.model,
|
|
57
|
+
...requestConfig.reasoningEffort === undefined
|
|
58
|
+
? {}
|
|
59
|
+
: { reasoningEffort: requestConfig.reasoningEffort },
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Resolve the child's `AgentOptions`: the parent's provider/model,
|
|
64
|
+
* reasoning-effort, and maxTokens values unless the request overrides them,
|
|
65
|
+
* stamped with the child's own delegation depth. Changing the route without
|
|
66
|
+
* naming an effort clears the parent's route-owned effort so the selected
|
|
67
|
+
* model resolves its own default.
|
|
68
|
+
* @param parent - the delegating parent whose route the child inherits.
|
|
69
|
+
* @param requested - per-child overrides, if any.
|
|
70
|
+
* @param childDepth - the resolved delegation depth to stamp.
|
|
71
|
+
* @returns the resolved options for `ctx.agents.create()`.
|
|
72
|
+
*/
|
|
73
|
+
export function resolveChildAgentOptions(parent, requested, childDepth) {
|
|
74
|
+
const parentOptions = parentAgentOptionsForDelegation(parent);
|
|
75
|
+
const parentProvider = parentOptions.provider;
|
|
76
|
+
const parentModel = parentOptions.model;
|
|
77
|
+
const parentReasoningEffort = parentOptions.reasoningEffort;
|
|
78
|
+
const parentMaxTokens = parentOptions.maxTokens;
|
|
79
|
+
const resolved = {
|
|
80
|
+
...parentProvider !== undefined ? { provider: parentProvider } : {},
|
|
81
|
+
...parentModel !== undefined ? { model: parentModel } : {},
|
|
82
|
+
...parentReasoningEffort !== undefined ? { reasoningEffort: parentReasoningEffort } : {},
|
|
83
|
+
...parentMaxTokens !== undefined ? { maxTokens: parentMaxTokens } : {},
|
|
84
|
+
...requested,
|
|
85
|
+
subagentDepth: childDepth,
|
|
86
|
+
};
|
|
87
|
+
const routeChanged = resolved.provider !== parentProvider || resolved.model !== parentModel;
|
|
88
|
+
if (routeChanged && requested?.reasoningEffort === undefined)
|
|
89
|
+
delete resolved.reasoningEffort;
|
|
90
|
+
return resolved;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Build the child session's durable creation metadata: the parent's workspace,
|
|
94
|
+
* its direct lineage, coarse product origin, the recursion budget that must
|
|
95
|
+
* survive persistence, the seed boundary that separates inherited parent
|
|
96
|
+
* history from child work, and the composition the child runs under.
|
|
97
|
+
*
|
|
98
|
+
* The preset is read from the parent's LIVE scope chain rather than from its
|
|
99
|
+
* header, because a parent that switched preset while blank runs on the newer
|
|
100
|
+
* composition and its header still names the older one. Recording it is what
|
|
101
|
+
* makes a child's history reconstructable: without it a cold read of the child
|
|
102
|
+
* resolves the deployment default and rebuilds turns under a tool set the
|
|
103
|
+
* child never had.
|
|
104
|
+
* @param parent - the delegating parent agent.
|
|
105
|
+
* @param childDepth - the resolved delegation depth to persist.
|
|
106
|
+
* @param isSeeded - whether this child inherits a parent-log prefix, including an explicitly empty one.
|
|
107
|
+
* @returns the `meta` for `ctx.agents.create()`.
|
|
108
|
+
*/
|
|
109
|
+
export function childSessionMeta(parent, childDepth, isSeeded) {
|
|
110
|
+
const parentHeader = parent.session.header;
|
|
111
|
+
const agentPreset = parent.ctx.get('agentPresets')?.composedPreset(parent.ctx);
|
|
112
|
+
return {
|
|
113
|
+
...parentHeader.cwd !== undefined ? { cwd: parentHeader.cwd } : {},
|
|
114
|
+
...agentPreset === undefined ? {} : { agentPreset },
|
|
115
|
+
parentSession: parentHeader.id,
|
|
116
|
+
isSeeded,
|
|
117
|
+
// Navigation classification only; the descriptor remains the authority
|
|
118
|
+
// for mode and continuation capability.
|
|
119
|
+
origin: 'subagent',
|
|
120
|
+
// Durable: the recursion budget must survive persistence and resume.
|
|
121
|
+
delegationDepth: childDepth,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Model-facing delegation-scope statement for every in-process child. A
|
|
126
|
+
* runtime-context contribution rather than a system-prompt section, so the
|
|
127
|
+
* deployment's system prompt stays uniform across parents and children.
|
|
128
|
+
*/
|
|
129
|
+
export const SUBAGENT_DELEGATION_CONTEXT = 'You are a delegated subagent: your permission scope was fixed when you were started and cannot be '
|
|
130
|
+
+ 'widened from inside this session — operations that require approval are rejected automatically. '
|
|
131
|
+
+ 'When the task needs access beyond that scope, do not retry the denied operation; state the '
|
|
132
|
+
+ 'limitation in your reply so the delegating agent can handle it.';
|
|
133
|
+
/**
|
|
134
|
+
* Compose one child inside its creation window: join its parent's preset,
|
|
135
|
+
* register the fixed delegation-scope statement, then apply the child's own
|
|
136
|
+
* shadowing persona section and tool restriction, all owned by the child's
|
|
137
|
+
* scope and therefore invisible to its parent and siblings. Creation and cold
|
|
138
|
+
* resume both pass through here.
|
|
139
|
+
*
|
|
140
|
+
* The join comes first and the child's own registrations second, which is the
|
|
141
|
+
* order the layering already implies — the nearest scope wins a name, and a
|
|
142
|
+
* per-child restriction intersects with everything its chain admits — but
|
|
143
|
+
* stating it here keeps the two steps from being read as independent.
|
|
144
|
+
*
|
|
145
|
+
* The join and the per-child registrations live in ONE call because a child
|
|
146
|
+
* composed without the join is exactly the defect this function exists to
|
|
147
|
+
* prevent: with every model-facing row on the agent plane, a child that joins
|
|
148
|
+
* no preset sees an empty tool registry and none of its parent's prompt
|
|
149
|
+
* sections. Taking the parent as a parameter is what makes that omission
|
|
150
|
+
* unrepresentable at the call sites.
|
|
151
|
+
* @param childCtx - the child agent's scoped creation context.
|
|
152
|
+
* @param parent - the delegating parent whose composition the child joins.
|
|
153
|
+
* @param composition - the per-child persona and tool filter to install.
|
|
154
|
+
*/
|
|
155
|
+
export function applyChildComposition(childCtx, parent, composition) {
|
|
156
|
+
childCtx.get('agentPresets')?.composeFrom(childCtx, parent.ctx);
|
|
157
|
+
childCtx.systemPrompt.context({
|
|
158
|
+
name: 'subagent:delegation',
|
|
159
|
+
order: childCtx.systemPrompt.getContextOrder('SUBAGENT_DELEGATION'),
|
|
160
|
+
text: SUBAGENT_DELEGATION_CONTEXT,
|
|
161
|
+
});
|
|
162
|
+
if (composition.persona !== undefined) {
|
|
163
|
+
childCtx.systemPrompt.section({
|
|
164
|
+
name: 'deployment:persona-prefix',
|
|
165
|
+
order: childCtx.systemPrompt.getSectionOrder('DEPLOYMENT_PERSONA_PREFIX'),
|
|
166
|
+
text: composition.persona,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (composition.toolFilter !== undefined)
|
|
170
|
+
childCtx.tools.restrict(composition.toolFilter);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Capture the permission state to seed into one delegation. Call synchronously before
|
|
174
|
+
* the child start's first await: a later parent switch belongs to the
|
|
175
|
+
* parent's future, not to this child. Auto and Full access identities are
|
|
176
|
+
* inherited only through the in-process DSH path so either can replace a stale
|
|
177
|
+
* same-bundle fork value. Only the parent session's explicit sandbox override
|
|
178
|
+
* is captured — never deployment defaults or one-shot grants — and the approval
|
|
179
|
+
* policy is pinned to `'never'` regardless of the parent's own policy.
|
|
180
|
+
* @param parent - the delegating parent agent.
|
|
181
|
+
* @returns the sandbox override (or `undefined` without one) and the approval pin.
|
|
182
|
+
*/
|
|
183
|
+
export function captureDelegatedPolicyOverrides(parent) {
|
|
184
|
+
const preset = parent.ctx.get('permissionPresets')?.current(parent.session);
|
|
185
|
+
return {
|
|
186
|
+
permissionPreset: preset === 'auto' || preset === 'danger-full-access' ? preset : undefined,
|
|
187
|
+
sandboxMode: parent.ctx.get('sandboxPolicy')?.overrideOf(parent.session),
|
|
188
|
+
approvalPolicy: parent.ctx.get('approval') === undefined ? undefined : 'never',
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Append the captured delegation policy onto the child's own log as
|
|
193
|
+
* `source: 'delegation'` events inside the unpublished creation window, so the
|
|
194
|
+
* child's effective policy is reconstructable from its log alone. Appends land
|
|
195
|
+
* after any fork seed, so fresh policy wins stale seed state; later child
|
|
196
|
+
* switches still win over these events.
|
|
197
|
+
* @param childSession - the unpublished child's session.
|
|
198
|
+
* @param overrides - the policy captured at delegation.
|
|
199
|
+
*/
|
|
200
|
+
export function appendDelegatedPolicyOverrides(childSession, overrides) {
|
|
201
|
+
if (overrides.sandboxMode !== undefined) {
|
|
202
|
+
childSession.append('sandbox/mode', { mode: overrides.sandboxMode, source: 'delegation' });
|
|
203
|
+
}
|
|
204
|
+
if (overrides.approvalPolicy !== undefined) {
|
|
205
|
+
childSession.append('approval/policy', { policy: overrides.approvalPolicy, source: 'delegation' });
|
|
206
|
+
}
|
|
207
|
+
if (overrides.permissionPreset !== undefined) {
|
|
208
|
+
childSession.append('permission/preset', { preset: overrides.permissionPreset });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=child-agent.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe subagent projection and control vocabulary.
|
|
3
|
+
*
|
|
4
|
+
* @module @qlzt/dsh-subagent/client
|
|
5
|
+
*/
|
|
6
|
+
export type * from './control-types.ts';
|
|
7
|
+
export type { SubagentCatalogEntry, SubagentIdentityProjection, SubagentTimingProjection } from './projection-types.ts';
|
|
8
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-visible messages owned by continuable-subagent orchestration.
|
|
3
|
+
*
|
|
4
|
+
* @module @qlzt/dsh-subagent/continuation-messages
|
|
5
|
+
*/
|
|
6
|
+
import type { Agent } from '@qlzt/dsh-agent';
|
|
7
|
+
import { createUserMessage } from '@qlzt/dsh-llm';
|
|
8
|
+
import type { ContentBlock } from '@qlzt/dsh-llm';
|
|
9
|
+
import type { SessionId } from '@qlzt/dsh-session';
|
|
10
|
+
import type { SubagentResult } from './types.ts';
|
|
11
|
+
/** Durable attribution for one model-authored message between Agents. */
|
|
12
|
+
export interface AgentMessageSource {
|
|
13
|
+
readonly kind: 'agent-message';
|
|
14
|
+
/** A message another agent addressed to this one (`relay` context form). */
|
|
15
|
+
readonly form: 'relay';
|
|
16
|
+
/** Session id of the Agent whose tool call produced the message. */
|
|
17
|
+
readonly senderSessionId: SessionId;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Durable attribution for the runtime's own account of a continuable child
|
|
21
|
+
* settling. Deliberately a different kind from
|
|
22
|
+
* {@link AgentMessageSource}: an Agent message is content the sender chose,
|
|
23
|
+
* while this message is the manager stating what became of the child, and a
|
|
24
|
+
* transcript that merged them would credit the child with words it never wrote.
|
|
25
|
+
*/
|
|
26
|
+
export interface SubagentSettledMessageSource {
|
|
27
|
+
readonly kind: 'subagent-settled';
|
|
28
|
+
/** A runtime account shown without expanding the row (`notice` context form). */
|
|
29
|
+
readonly form: 'notice';
|
|
30
|
+
/** One-line account of how the child ended. */
|
|
31
|
+
readonly summary: string;
|
|
32
|
+
/** Session id of the child that settled. */
|
|
33
|
+
readonly senderSessionId: SessionId;
|
|
34
|
+
}
|
|
35
|
+
declare module '@qlzt/dsh-llm' {
|
|
36
|
+
interface MessageSourceMap {
|
|
37
|
+
'agent-message': AgentMessageSource;
|
|
38
|
+
'subagent-settled': SubagentSettledMessageSource;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build the model-visible and durable representation of one adjacent-Agent message.
|
|
43
|
+
* @param sender - exact live Agent that authored the message.
|
|
44
|
+
* @param content - model-visible message blocks supplied by the sender.
|
|
45
|
+
* @returns the durable user-message representation delivered to the recipient.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createAgentMessage(sender: Agent, content: ContentBlock[]): ReturnType<typeof createUserMessage>;
|
|
48
|
+
/**
|
|
49
|
+
* Append adjacent-Agent return guidance to a continuable child's initial task.
|
|
50
|
+
* @param parentId - durable parent session id named in the guidance.
|
|
51
|
+
* @param prompt - initial model-visible task blocks.
|
|
52
|
+
* @returns task blocks followed by the continuable return guidance.
|
|
53
|
+
*/
|
|
54
|
+
export declare function withContinuableReturnGuidance(parentId: SessionId, prompt: ContentBlock[]): ContentBlock[];
|
|
55
|
+
/**
|
|
56
|
+
* Build the runtime-owned settlement notice from the child's nonempty closing text.
|
|
57
|
+
* @param childId - durable child session id named in the notice.
|
|
58
|
+
* @param terminal - recorded terminal state for the settled Activation.
|
|
59
|
+
* @param continuable - whether the child can accept another task.
|
|
60
|
+
* @returns the durable user-message representation delivered to the parent.
|
|
61
|
+
*/
|
|
62
|
+
export declare function createSettlementMessage(childId: SessionId, terminal: SubagentResult, continuable?: boolean): ReturnType<typeof createUserMessage>;
|
|
63
|
+
//# sourceMappingURL=continuation-messages.d.ts.map
|