@xneog/dsh-subagent 0.1.0 → 0.1.3-alpha.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.
Files changed (41) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +108 -76
  3. package/README.zh.md +112 -80
  4. package/lib/index.js +1258 -718
  5. package/lib/typert.host.d.ts +3 -0
  6. package/lib/typert.host.js +923 -0
  7. package/lib/typert.remote-client.d.ts +27 -0
  8. package/lib/typert.remote-client.js +159 -0
  9. package/lib/types/assistant-output.d.ts +3 -3
  10. package/lib/types/assistant-output.js +8 -4
  11. package/lib/types/child-agent.d.ts +16 -5
  12. package/lib/types/child-agent.js +51 -13
  13. package/lib/types/client.d.ts +2 -1
  14. package/lib/types/client.js +1 -1
  15. package/lib/types/continuation.d.ts +100 -72
  16. package/lib/types/continuation.js +439 -169
  17. package/lib/types/control-types.d.ts +144 -0
  18. package/lib/types/control-types.js +9 -0
  19. package/lib/types/control.d.ts +67 -0
  20. package/lib/types/control.js +115 -0
  21. package/lib/types/descriptor-seed.d.ts +1 -1
  22. package/lib/types/descriptor-seed.js +1 -1
  23. package/lib/types/descriptor.d.ts +6 -1
  24. package/lib/types/descriptor.js +6 -2
  25. package/lib/types/index.d.ts +103 -69
  26. package/lib/types/index.js +436 -287
  27. package/lib/types/internal.d.ts +59 -0
  28. package/lib/types/internal.js +58 -0
  29. package/lib/types/lifecycle.js +4 -3
  30. package/lib/types/list-children.d.ts +12 -59
  31. package/lib/types/list-children.js +166 -101
  32. package/lib/types/out-of-process.d.ts +5 -2
  33. package/lib/types/out-of-process.js +42 -4
  34. package/lib/types/projection-types.d.ts +4 -3
  35. package/lib/types/projection.d.ts +55 -8
  36. package/lib/types/projection.js +33 -17
  37. package/lib/types/run-settlement.js +17 -6
  38. package/lib/types/types.d.ts +25 -0
  39. package/package.json +67 -37
  40. package/lib/types/activation-setup-registry.d.ts +0 -57
  41. package/lib/types/activation-setup-registry.js +0 -148
@@ -0,0 +1,27 @@
1
+ /* Generated by @xneog/dsh-typert-generator from the Host FaceModel — do not edit. */
2
+ import type {
3
+ RemoteResult,
4
+ TypertRemoteContribution,
5
+ } from '@xneog/dsh-typert-protocol'
6
+ import type { SessionId } from '@xneog/dsh-session/types'
7
+ import type { SubagentCatalog, SubagentInterruptReceipt, SubagentPromptReceipt, SubagentPromptRequest } from '@xneog/dsh-subagent/client'
8
+
9
+ declare module '@xneog/dsh-typert-protocol' {
10
+ interface TypertRemoteNamespace$7375626167656e7473 {
11
+ interruptByParent: (childSessionId: SessionId, parentSessionId: SessionId, mode: 'continuable') => Promise<RemoteResult<SubagentInterruptReceipt>>
12
+ list: (parentSessionId: SessionId, signal?: AbortSignal) => Promise<RemoteResult<SubagentCatalog>>
13
+ prompt: (request: SubagentPromptRequest, signal?: AbortSignal) => Promise<RemoteResult<SubagentPromptReceipt>>
14
+ }
15
+ interface TypertRemoteMap {
16
+ 'subagents/interruptByParent': (childSessionId: SessionId, parentSessionId: SessionId, mode: 'continuable') => Promise<RemoteResult<SubagentInterruptReceipt>>
17
+ 'subagents/list': (parentSessionId: SessionId, signal?: AbortSignal) => Promise<RemoteResult<SubagentCatalog>>
18
+ 'subagents/prompt': (request: SubagentPromptRequest, signal?: AbortSignal) => Promise<RemoteResult<SubagentPromptReceipt>>
19
+ }
20
+ interface TypertRemoteNamespaceMap {
21
+ 'subagents': TypertRemoteNamespace$7375626167656e7473
22
+ }
23
+ }
24
+
25
+ export declare const TYPERT_REMOTE: TypertRemoteContribution
26
+ export default TYPERT_REMOTE
27
+ //# sourceMappingURL=typert.remote-client.d.ts.map
@@ -0,0 +1,159 @@
1
+ /* Generated by @xneog/dsh-typert-generator from the Host FaceModel — do not edit. */
2
+ import { z } from 'zod'
3
+
4
+ const _xneog_dsh_subagent_subagents_interruptByParent_parameter_0$schema = z.intersection(z.string(), z.unknown())
5
+ const _xneog_dsh_subagent_subagents_interruptByParent_parameter_1$schema = z.intersection(z.string(), z.unknown())
6
+ const _xneog_dsh_subagent_subagents_interruptByParent_parameter_2$schema = z.literal("continuable")
7
+ const _xneog_dsh_subagent_subagents_interruptByParent_result$schema = z.object({
8
+ 'accepted': z.literal(true).readonly(),
9
+ })
10
+ const _xneog_dsh_subagent_subagents_list_parameter_0$schema = z.intersection(z.string(), z.unknown())
11
+ const _xneog_dsh_subagent_subagents_list_result$schema = z.object({
12
+ 'entries': z.array(z.union([z.intersection(z.object({
13
+ 'kind': z.literal("child").readonly(),
14
+ 'id': z.intersection(z.string(), z.unknown()).readonly(),
15
+ 'activity': z.union([z.literal("running"), z.literal("inactive")]).readonly(),
16
+ 'hasChildren': z.boolean().readonly(),
17
+ }), z.object({
18
+ 'mode': z.literal("one-shot").readonly(),
19
+ 'label': z.string().readonly().optional(),
20
+ })), z.intersection(z.object({
21
+ 'kind': z.literal("child").readonly(),
22
+ 'id': z.intersection(z.string(), z.unknown()).readonly(),
23
+ 'activity': z.union([z.literal("running"), z.literal("inactive")]).readonly(),
24
+ 'hasChildren': z.boolean().readonly(),
25
+ }), z.object({
26
+ 'mode': z.literal("continuable").readonly(),
27
+ 'label': z.string().readonly(),
28
+ })), z.object({
29
+ 'kind': z.literal("diagnostic").readonly(),
30
+ 'id': z.intersection(z.string(), z.unknown()).readonly(),
31
+ 'reason': z.union([z.literal("corrupt"), z.literal("unsupported"), z.literal("unavailable")]).readonly(),
32
+ })])).readonly(),
33
+ 'parentAvailable': z.boolean().readonly(),
34
+ })
35
+ const _xneog_dsh_subagent_subagents_prompt_parameter_0$schema = z.object({
36
+ 'requestId': z.intersection(z.string(), z.unknown()).readonly(),
37
+ 'parentSessionId': z.intersection(z.string(), z.unknown()).readonly(),
38
+ 'childSessionId': z.intersection(z.string(), z.unknown()).readonly(),
39
+ 'mode': z.literal("continuable").readonly(),
40
+ 'content': z.array(z.union([z.object({
41
+ 'type': z.literal("text").readonly(),
42
+ 'text': z.string().readonly(),
43
+ }), z.object({
44
+ 'type': z.literal("image").readonly(),
45
+ 'mediaType': z.union([z.literal("image/png"), z.literal("image/jpeg"), z.literal("image/webp"), z.literal("image/gif")]).readonly(),
46
+ 'data': z.string().readonly(),
47
+ 'name': z.string().readonly().optional(),
48
+ })])).readonly(),
49
+ 'clientTimeZone': z.string().readonly().optional(),
50
+ })
51
+ const _xneog_dsh_subagent_subagents_prompt_result$schema = z.object({
52
+ 'messageId': z.intersection(z.string(), z.unknown()).readonly(),
53
+ })
54
+
55
+ export const TYPERT_REMOTE = {
56
+ package: '@xneog/dsh-subagent',
57
+ descriptors: [
58
+ {
59
+ id: '@xneog/dsh-subagent#subagents/interruptByParent',
60
+ service: 'subagents',
61
+ namespace: 'subagents',
62
+ method: 'interruptByParent',
63
+ invocation: { kind: 'direct' },
64
+ parameters: [
65
+ {
66
+ name: 'childSessionId',
67
+ wire: 'childSessionId',
68
+ source: 'json',
69
+ codec: {
70
+ mode: 'strict',
71
+ typeSymbol: '@xneog/dsh-session/types#SessionId',
72
+ schema: _xneog_dsh_subagent_subagents_interruptByParent_parameter_0$schema,
73
+ },
74
+ },
75
+ {
76
+ name: 'parentSessionId',
77
+ wire: 'parentSessionId',
78
+ source: 'json',
79
+ codec: {
80
+ mode: 'strict',
81
+ typeSymbol: '@xneog/dsh-session/types#SessionId',
82
+ schema: _xneog_dsh_subagent_subagents_interruptByParent_parameter_1$schema,
83
+ },
84
+ },
85
+ {
86
+ name: 'mode',
87
+ wire: 'mode',
88
+ source: 'json',
89
+ codec: {
90
+ mode: 'strict',
91
+ typeSymbol: '@xneog/dsh-subagent#subagents/interruptByParent:mode',
92
+ schema: _xneog_dsh_subagent_subagents_interruptByParent_parameter_2$schema,
93
+ },
94
+ },
95
+ ],
96
+ result: {
97
+ mode: 'strict',
98
+ typeSymbol: '@xneog/dsh-subagent/client#SubagentInterruptReceipt',
99
+ schema: _xneog_dsh_subagent_subagents_interruptByParent_result$schema,
100
+ },
101
+ sourceLocation: {"file":"packages/subagent/subagent/src/index.ts","line":480,"column":3},
102
+ },
103
+ {
104
+ id: '@xneog/dsh-subagent#subagents/list',
105
+ service: 'subagents',
106
+ namespace: 'subagents',
107
+ method: 'list',
108
+ implementation: 'remoteExportList',
109
+ invocation: { kind: 'direct' },
110
+ parameters: [
111
+ {
112
+ name: 'parentSessionId',
113
+ wire: 'parentSessionId',
114
+ source: 'json',
115
+ codec: {
116
+ mode: 'strict',
117
+ typeSymbol: '@xneog/dsh-session/types#SessionId',
118
+ schema: _xneog_dsh_subagent_subagents_list_parameter_0$schema,
119
+ },
120
+ },
121
+ ],
122
+ cancellation: { parameter: 'signal' },
123
+ result: {
124
+ mode: 'strict',
125
+ typeSymbol: '@xneog/dsh-subagent/client#SubagentCatalog',
126
+ schema: _xneog_dsh_subagent_subagents_list_result$schema,
127
+ },
128
+ sourceLocation: {"file":"packages/subagent/subagent/src/index.ts","line":387,"column":9},
129
+ },
130
+ {
131
+ id: '@xneog/dsh-subagent#subagents/prompt',
132
+ service: 'subagents',
133
+ namespace: 'subagents',
134
+ method: 'prompt',
135
+ invocation: { kind: 'direct' },
136
+ parameters: [
137
+ {
138
+ name: 'request',
139
+ wire: 'request',
140
+ source: 'json',
141
+ codec: {
142
+ mode: 'strict',
143
+ typeSymbol: '@xneog/dsh-subagent/client#SubagentPromptRequest',
144
+ schema: _xneog_dsh_subagent_subagents_prompt_parameter_0$schema,
145
+ },
146
+ },
147
+ ],
148
+ cancellation: { parameter: 'signal' },
149
+ result: {
150
+ mode: 'strict',
151
+ typeSymbol: '@xneog/dsh-subagent/client#SubagentPromptReceipt',
152
+ schema: _xneog_dsh_subagent_subagents_prompt_result$schema,
153
+ },
154
+ sourceLocation: {"file":"packages/subagent/subagent/src/index.ts","line":413,"column":9},
155
+ },
156
+ ],
157
+ }
158
+
159
+ export default TYPERT_REMOTE
@@ -9,7 +9,7 @@
9
9
  *
10
10
  * @module @xneog/dsh-subagent/assistant-output
11
11
  */
12
- import type { ContentBlock } from '@xneog/dsh-llm';
12
+ import { type ContentBlock } from '@xneog/dsh-llm';
13
13
  import type { SessionEvent } from '@xneog/dsh-session';
14
14
  /**
15
15
  * Incremental fold of the selection rule, for backends that observe a child's
@@ -22,8 +22,8 @@ export declare class AssistantOutputFold {
22
22
  private partial;
23
23
  /**
24
24
  * Fold one session event: a non-empty assistant message becomes the
25
- * candidate final answer, and a `text-delta` chunk extends the streamed
26
- * fallback; every other event contributes nothing.
25
+ * candidate final answer, while its embedded stream and any log-only attempt
26
+ * extend the streamed fallback; every other event contributes nothing.
27
27
  * @param event - the next observed session event.
28
28
  */
29
29
  push(event: SessionEvent): void;
@@ -9,6 +9,7 @@
9
9
  *
10
10
  * @module @xneog/dsh-subagent/assistant-output
11
11
  */
12
+ import { expandAssistantStream } from '@xneog/dsh-llm';
12
13
  /**
13
14
  * Incremental fold of the selection rule, for backends that observe a child's
14
15
  * output as it streams: session-event backends {@link push} each event, and
@@ -20,8 +21,8 @@ export class AssistantOutputFold {
20
21
  partial = [];
21
22
  /**
22
23
  * Fold one session event: a non-empty assistant message becomes the
23
- * candidate final answer, and a `text-delta` chunk extends the streamed
24
- * fallback; every other event contributes nothing.
24
+ * candidate final answer, while its embedded stream and any log-only attempt
25
+ * extend the streamed fallback; every other event contributes nothing.
25
26
  * @param event - the next observed session event.
26
27
  */
27
28
  push(event) {
@@ -30,8 +31,11 @@ export class AssistantOutputFold {
30
31
  if (content.length > 0)
31
32
  this.message = content;
32
33
  }
33
- else if (event.type === 'assistant/chunk' && event.data.chunk.type === 'text-delta') {
34
- this.pushText(event.data.chunk.text);
34
+ if (event.type === 'assistant/message' || event.type === 'assistant/attempt') {
35
+ for (const { chunk } of expandAssistantStream(event.data.stream)) {
36
+ if (chunk.type === 'text-delta')
37
+ this.pushText(chunk.text);
38
+ }
35
39
  }
36
40
  }
37
41
  /**
@@ -30,9 +30,20 @@ export declare class SubagentDepthError extends Error {
30
30
  */
31
31
  export declare function resolveChildDepth(parent: Agent, maxDepth: number | undefined): number;
32
32
  /**
33
- * Resolve the child's `AgentOptions`: the parent's provider/model/maxTokens
34
- * route unless the request overrides it, stamped with the child's own
35
- * delegation depth.
33
+ * Resolve the parent values inherited by a child. The latest request header
34
+ * owns provider, model, and reasoning effort after request-time selection;
35
+ * creation options remain the fallback before the first request and retain
36
+ * the configured output-token limit.
37
+ * @param parent - delegating parent Agent.
38
+ * @returns detached Agent options for child-option merging.
39
+ */
40
+ export declare function parentAgentOptionsForDelegation(parent: Agent): AgentOptions;
41
+ /**
42
+ * Resolve the child's `AgentOptions`: the parent's provider/model,
43
+ * reasoning-effort, and maxTokens values unless the request overrides them,
44
+ * stamped with the child's own delegation depth. Changing the route without
45
+ * naming an effort clears the parent's route-owned effort so the selected
46
+ * model resolves its own default.
36
47
  * @param parent - the delegating parent whose route the child inherits.
37
48
  * @param requested - per-child overrides, if any.
38
49
  * @param childDepth - the resolved delegation depth to stamp.
@@ -53,10 +64,10 @@ export declare function resolveChildAgentOptions(parent: Agent, requested: Agent
53
64
  * child never had.
54
65
  * @param parent - the delegating parent agent.
55
66
  * @param childDepth - the resolved delegation depth to persist.
56
- * @param lineageSeedLength - how many leading events came from the parent's log.
67
+ * @param isSeeded - whether this child inherits a parent-log prefix, including an explicitly empty one.
57
68
  * @returns the `meta` for `ctx.agents.create()`.
58
69
  */
59
- export declare function childSessionMeta(parent: Agent, childDepth: number, lineageSeedLength: number): NonNullable<CreateAgentOptions['meta']>;
70
+ export declare function childSessionMeta(parent: Agent, childDepth: number, isSeeded: boolean): NonNullable<CreateAgentOptions['meta']>;
60
71
  /** The scoped composition a child agent's creation window applies. */
61
72
  export interface ChildComposition {
62
73
  /** Per-child persona shadowing the deployment persona. */
@@ -40,25 +40,56 @@ export function resolveChildDepth(parent, maxDepth) {
40
40
  return childDepth;
41
41
  }
42
42
  /**
43
- * Resolve the child's `AgentOptions`: the parent's provider/model/maxTokens
44
- * route unless the request overrides it, stamped with the child's own
45
- * delegation depth.
43
+ * Resolve the parent values inherited by a child. The latest request header
44
+ * owns provider, model, and reasoning effort after request-time selection;
45
+ * creation options remain the fallback before the first request and retain
46
+ * the configured output-token limit.
47
+ * @param parent - delegating parent Agent.
48
+ * @returns detached Agent options for child-option merging.
49
+ */
50
+ export function parentAgentOptionsForDelegation(parent) {
51
+ const requestConfig = parent.session.requestHeader()?.config;
52
+ if (requestConfig === undefined)
53
+ return { ...parent.options };
54
+ const { provider: _createdProvider, model: _createdModel, reasoningEffort: _createdReasoningEffort, ...createdOptions } = parent.options;
55
+ return {
56
+ ...createdOptions,
57
+ provider: requestConfig.provider,
58
+ model: requestConfig.model,
59
+ ...requestConfig.reasoningEffort === undefined
60
+ ? {}
61
+ : { reasoningEffort: requestConfig.reasoningEffort },
62
+ };
63
+ }
64
+ /**
65
+ * Resolve the child's `AgentOptions`: the parent's provider/model,
66
+ * reasoning-effort, and maxTokens values unless the request overrides them,
67
+ * stamped with the child's own delegation depth. Changing the route without
68
+ * naming an effort clears the parent's route-owned effort so the selected
69
+ * model resolves its own default.
46
70
  * @param parent - the delegating parent whose route the child inherits.
47
71
  * @param requested - per-child overrides, if any.
48
72
  * @param childDepth - the resolved delegation depth to stamp.
49
73
  * @returns the resolved options for `ctx.agents.create()`.
50
74
  */
51
75
  export function resolveChildAgentOptions(parent, requested, childDepth) {
52
- const parentProvider = parent.options.provider;
53
- const parentModel = parent.options.model;
54
- const parentMaxTokens = parent.options.maxTokens;
55
- return {
76
+ const parentOptions = parentAgentOptionsForDelegation(parent);
77
+ const parentProvider = parentOptions.provider;
78
+ const parentModel = parentOptions.model;
79
+ const parentReasoningEffort = parentOptions.reasoningEffort;
80
+ const parentMaxTokens = parentOptions.maxTokens;
81
+ const resolved = {
56
82
  ...parentProvider !== undefined ? { provider: parentProvider } : {},
57
83
  ...parentModel !== undefined ? { model: parentModel } : {},
84
+ ...parentReasoningEffort !== undefined ? { reasoningEffort: parentReasoningEffort } : {},
58
85
  ...parentMaxTokens !== undefined ? { maxTokens: parentMaxTokens } : {},
59
86
  ...requested,
60
87
  subagentDepth: childDepth,
61
88
  };
89
+ const routeChanged = resolved.provider !== parentProvider || resolved.model !== parentModel;
90
+ if (routeChanged && requested?.reasoningEffort === undefined)
91
+ delete resolved.reasoningEffort;
92
+ return resolved;
62
93
  }
63
94
  /**
64
95
  * Build the child session's durable creation metadata: the parent's workspace,
@@ -74,22 +105,22 @@ export function resolveChildAgentOptions(parent, requested, childDepth) {
74
105
  * child never had.
75
106
  * @param parent - the delegating parent agent.
76
107
  * @param childDepth - the resolved delegation depth to persist.
77
- * @param lineageSeedLength - how many leading events came from the parent's log.
108
+ * @param isSeeded - whether this child inherits a parent-log prefix, including an explicitly empty one.
78
109
  * @returns the `meta` for `ctx.agents.create()`.
79
110
  */
80
- export function childSessionMeta(parent, childDepth, lineageSeedLength) {
111
+ export function childSessionMeta(parent, childDepth, isSeeded) {
81
112
  const parentHeader = parent.session.header;
82
113
  const agentPreset = parent.ctx.get('agentPresets')?.composedPreset(parent.ctx);
83
114
  return {
84
115
  ...parentHeader.cwd !== undefined ? { cwd: parentHeader.cwd } : {},
85
116
  ...agentPreset === undefined ? {} : { agentPreset },
86
117
  parentSession: parentHeader.id,
118
+ isSeeded,
87
119
  // Navigation classification only; the descriptor remains the authority
88
120
  // for mode and continuation capability.
89
121
  origin: 'subagent',
90
122
  // Durable: the recursion budget must survive persistence and resume.
91
123
  delegationDepth: childDepth,
92
- ...lineageSeedLength > 0 ? { seedLength: lineageSeedLength } : {},
93
124
  };
94
125
  }
95
126
  /**
@@ -125,10 +156,17 @@ export const SUBAGENT_DELEGATION_CONTEXT = 'You are a delegated subagent: your p
125
156
  */
126
157
  export function applyChildComposition(childCtx, parent, composition) {
127
158
  childCtx.get('agentPresets')?.composeFrom(childCtx, parent.ctx);
128
- // Order 120: after the sandbox:policy (110) and approval:policy (115) sentences.
129
- childCtx.systemPrompt.context({ name: 'subagent:delegation', order: 120, text: SUBAGENT_DELEGATION_CONTEXT });
159
+ childCtx.systemPrompt.context({
160
+ name: 'subagent:delegation',
161
+ order: childCtx.systemPrompt.getContextOrder('SUBAGENT_DELEGATION'),
162
+ text: SUBAGENT_DELEGATION_CONTEXT,
163
+ });
130
164
  if (composition.persona !== undefined) {
131
- childCtx.systemPrompt.section({ name: 'deployment:persona', order: 0, text: composition.persona });
165
+ childCtx.systemPrompt.section({
166
+ name: 'deployment:persona',
167
+ order: childCtx.systemPrompt.getSectionOrder('DEPLOYMENT_PERSONA'),
168
+ text: composition.persona,
169
+ });
132
170
  }
133
171
  if (composition.toolFilter !== undefined)
134
172
  childCtx.tools.restrict(composition.toolFilter);
@@ -1,7 +1,8 @@
1
1
  /**
2
- * Browser-safe subagent projection vocabulary.
2
+ * Browser-safe subagent projection and control vocabulary.
3
3
  *
4
4
  * @module @xneog/dsh-subagent/client
5
5
  */
6
+ export type * from './control-types.ts';
6
7
  export type { SubagentIdentityProjection, SubagentTimingProjection } from './projection-types.ts';
7
8
  //# sourceMappingURL=client.d.ts.map
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Browser-safe subagent projection vocabulary.
2
+ * Browser-safe subagent projection and control vocabulary.
3
3
  *
4
4
  * @module @xneog/dsh-subagent/client
5
5
  */