@toddzheng024/dscode-bundle 0.3.0 → 0.5.0

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 (113) hide show
  1. package/THIRD_PARTY_NOTICES.md +15 -0
  2. package/cordis.patch.yml +5 -3
  3. package/package.json +14 -1
  4. package/plugins/clipboard-image/clipboard-image.swift +56 -0
  5. package/plugins/clipboard-image/index.mjs +70 -0
  6. package/plugins/code-review/git.mjs +95 -0
  7. package/plugins/code-review/index.mjs +88 -0
  8. package/plugins/dscode/index.mjs +17 -3
  9. package/plugins/email/cli.mjs +32 -0
  10. package/plugins/email/contacts.mjs +36 -0
  11. package/plugins/email/gmail-oauth.mjs +69 -0
  12. package/plugins/email/gmail-store.mjs +2 -0
  13. package/plugins/email/gmail.mjs +194 -0
  14. package/plugins/email/imap.mjs +136 -0
  15. package/plugins/email/inbox.d.mts +25 -0
  16. package/plugins/email/inbox.mjs +76 -0
  17. package/plugins/email/smtp.mjs +69 -0
  18. package/plugins/email/store.mjs +32 -0
  19. package/plugins/email-tools/index.mjs +44 -0
  20. package/plugins/session-metrics/index.mjs +6 -2
  21. package/plugins/session-metrics/rate.mjs +62 -0
  22. package/plugins/session-metrics/view.mjs +15 -9
  23. package/plugins/tui-tools/doctor-cli.mjs +22 -0
  24. package/plugins/tui-tools/doctor.mjs +141 -0
  25. package/plugins/tui-tools/index.mjs +14 -6
  26. package/plugins/ultra/policy.mjs +12 -1
  27. package/plugins/worktree-subagent/worktree.mjs +50 -0
  28. package/presets/dscode/agent.cordis.yml +7 -2
  29. package/vendor/deepseek/index.js +12 -2
  30. package/vendor/subagent/index.js +29 -9
  31. package/vendor/subagent-core/LICENSE +21 -0
  32. package/vendor/subagent-core/index.js +3232 -0
  33. package/vendor/subagent-core/invariant.js +76 -0
  34. package/vendor/subagent-core/typert.host.d.ts +3 -0
  35. package/vendor/subagent-core/typert.host.js +964 -0
  36. package/vendor/subagent-core/typert.remote-client.d.ts +27 -0
  37. package/vendor/subagent-core/typert.remote-client.js +160 -0
  38. package/vendor/subagent-core/types/assistant-output.d.ts +48 -0
  39. package/vendor/subagent-core/types/assistant-output.js +73 -0
  40. package/vendor/subagent-core/types/catalog.d.ts +77 -0
  41. package/vendor/subagent-core/types/catalog.js +103 -0
  42. package/vendor/subagent-core/types/child-agent.d.ts +150 -0
  43. package/vendor/subagent-core/types/child-agent.js +207 -0
  44. package/vendor/subagent-core/types/client.d.ts +8 -0
  45. package/vendor/subagent-core/types/client.js +7 -0
  46. package/vendor/subagent-core/types/continuation-activation.d.ts +251 -0
  47. package/vendor/subagent-core/types/continuation-activation.js +663 -0
  48. package/vendor/subagent-core/types/continuation-messages.d.ts +62 -0
  49. package/vendor/subagent-core/types/continuation-messages.js +102 -0
  50. package/vendor/subagent-core/types/continuation.d.ts +124 -0
  51. package/vendor/subagent-core/types/continuation.js +455 -0
  52. package/vendor/subagent-core/types/control-types.d.ts +146 -0
  53. package/vendor/subagent-core/types/control-types.js +9 -0
  54. package/vendor/subagent-core/types/control.d.ts +71 -0
  55. package/vendor/subagent-core/types/control.js +116 -0
  56. package/vendor/subagent-core/types/depth.d.ts +31 -0
  57. package/vendor/subagent-core/types/depth.js +39 -0
  58. package/vendor/subagent-core/types/descriptor.d.ts +144 -0
  59. package/vendor/subagent-core/types/descriptor.js +193 -0
  60. package/vendor/subagent-core/types/error.d.ts +11 -0
  61. package/vendor/subagent-core/types/error.js +14 -0
  62. package/vendor/subagent-core/types/inbox.d.ts +43 -0
  63. package/vendor/subagent-core/types/inbox.js +61 -0
  64. package/vendor/subagent-core/types/index.d.ts +316 -0
  65. package/vendor/subagent-core/types/index.js +511 -0
  66. package/vendor/subagent-core/types/internal.d.ts +58 -0
  67. package/vendor/subagent-core/types/internal.js +58 -0
  68. package/vendor/subagent-core/types/invariant.d.ts +13 -0
  69. package/vendor/subagent-core/types/invariant.js +91 -0
  70. package/vendor/subagent-core/types/lifecycle.d.ts +113 -0
  71. package/vendor/subagent-core/types/lifecycle.js +178 -0
  72. package/vendor/subagent-core/types/list-children.d.ts +65 -0
  73. package/vendor/subagent-core/types/list-children.js +381 -0
  74. package/vendor/subagent-core/types/out-of-process.d.ts +118 -0
  75. package/vendor/subagent-core/types/out-of-process.js +219 -0
  76. package/vendor/subagent-core/types/projection-types.d.ts +74 -0
  77. package/vendor/subagent-core/types/projection-types.js +7 -0
  78. package/vendor/subagent-core/types/projection.d.ts +95 -0
  79. package/vendor/subagent-core/types/projection.js +151 -0
  80. package/vendor/subagent-core/types/run-settlement.d.ts +17 -0
  81. package/vendor/subagent-core/types/run-settlement.js +70 -0
  82. package/vendor/subagent-core/types/types.d.ts +377 -0
  83. package/vendor/subagent-core/types/types.js +19 -0
  84. package/vendor/subagent-driver/LICENSE +21 -0
  85. package/vendor/subagent-driver/index.js +255 -0
  86. package/vendor/subagent-driver/types/index.d.ts +33 -0
  87. package/vendor/subagent-driver/types/structured.d.ts +42 -0
  88. package/vendor/subagent-fork/LICENSE +21 -0
  89. package/vendor/subagent-fork/index.js +61 -0
  90. package/vendor/subagent-fork/types/index.d.ts +20 -0
  91. package/vendor/subagent-spawn/LICENSE +21 -0
  92. package/vendor/subagent-spawn/index.js +45 -0
  93. package/vendor/subagent-spawn/types/index.d.ts +19 -0
  94. package/vendor/terminal/LICENSE +21 -0
  95. package/vendor/terminal/index.js +1013 -0
  96. package/vendor/terminal/types/config.d.ts +71 -0
  97. package/vendor/terminal/types/index.d.ts +36 -0
  98. package/vendor/terminal/types/sanitize.d.ts +47 -0
  99. package/vendor/terminal/types/session.d.ts +87 -0
  100. package/vendor/tui/dscode-clipboard-image/clipboard-image.swift +56 -0
  101. package/vendor/tui/dscode-clipboard-image/index.mjs +70 -0
  102. package/vendor/tui/dscode-email/cli.mjs +32 -0
  103. package/vendor/tui/dscode-email/contacts.mjs +36 -0
  104. package/vendor/tui/dscode-email/gmail-oauth.mjs +69 -0
  105. package/vendor/tui/dscode-email/gmail-store.mjs +2 -0
  106. package/vendor/tui/dscode-email/gmail.mjs +194 -0
  107. package/vendor/tui/dscode-email/imap.mjs +136 -0
  108. package/vendor/tui/dscode-email/inbox.d.mts +25 -0
  109. package/vendor/tui/dscode-email/inbox.mjs +76 -0
  110. package/vendor/tui/dscode-email/smtp.mjs +69 -0
  111. package/vendor/tui/dscode-email/store.mjs +32 -0
  112. package/vendor/tui/dscode-email.mjs +69 -0
  113. package/vendor/tui/index.mjs +473 -82
@@ -0,0 +1,91 @@
1
+ /** Package-owned subagent registry and lifecycle invariants. @module @deepseek-ai/dsh-subagent/invariant */
2
+ const PACKAGE_NAME = '@deepseek-ai/dsh-subagent';
3
+ /** Cordis companion plugin name. */
4
+ export const name = 'subagent-invariant';
5
+ /** Service required before the companion can reserve package ownership. */
6
+ export const inject = ['invariants'];
7
+ /** Assert that a terminal lifecycle payload matches its start identity. */
8
+ function validateRunEnd(start, end, fail) {
9
+ if (start.provider !== end.provider || start.id !== end.id || start.local !== end.local) {
10
+ fail(`subagent/end identity diverges from subagent/start for run ${JSON.stringify(end.runId)}`);
11
+ }
12
+ }
13
+ /** Install provider-registry and start/end pairing checks. */
14
+ const install = Object.assign((ctx, fail) => {
15
+ const providers = new Set(ctx.subagents.list());
16
+ const runs = new Map();
17
+ const stagedProviders = new WeakSet();
18
+ const stagedRemovals = new Set();
19
+ const stagedStarts = new WeakSet();
20
+ const stagedEnds = new WeakSet();
21
+ ctx.on('internal/dispatch', (_mode, eventName, args) => {
22
+ if (eventName === 'subagent/provider-added') {
23
+ const provider = args[0];
24
+ if (provider.name.length === 0)
25
+ fail('subagent provider names must be non-empty');
26
+ if (providers.has(provider.name))
27
+ fail(`subagent/provider-added repeated ${JSON.stringify(provider.name)}`);
28
+ stagedProviders.add(provider);
29
+ return;
30
+ }
31
+ if (eventName === 'subagent/provider-removed') {
32
+ const providerName = args[0];
33
+ if (!providers.has(providerName))
34
+ fail(`subagent/provider-removed names unknown provider ${JSON.stringify(providerName)}`);
35
+ stagedRemovals.add(providerName);
36
+ return;
37
+ }
38
+ if (eventName === 'subagent/start') {
39
+ const info = args[0];
40
+ // Provider availability is an admission-time relationship. A published
41
+ // one-shot run may outlive provider removal, and a cold-resumed Activation
42
+ // records the initial provider name without dispatching through it.
43
+ if (info.provider.length === 0 || String(info.runId).length === 0 || String(info.id).length === 0) {
44
+ fail('subagent/start provider, runId, and child id must be non-empty');
45
+ }
46
+ if (runs.has(info.runId))
47
+ fail(`subagent/start repeated run id ${JSON.stringify(info.runId)}`);
48
+ stagedStarts.add(info);
49
+ return;
50
+ }
51
+ if (eventName !== 'subagent/end')
52
+ return;
53
+ const info = args[0];
54
+ const start = runs.get(info.runId);
55
+ if (start === undefined)
56
+ fail(`subagent/end has no matching subagent/start for run ${JSON.stringify(info.runId)}`);
57
+ validateRunEnd(start, info, fail);
58
+ stagedEnds.add(info);
59
+ }, { global: true });
60
+ ctx.on('subagent/provider-added', (provider) => {
61
+ /* v8 ignore next -- internal/dispatch stages the same provider object */
62
+ if (!stagedProviders.delete(provider))
63
+ return;
64
+ providers.add(provider.name);
65
+ }, { global: true });
66
+ ctx.on('subagent/provider-removed', (providerName) => {
67
+ /* v8 ignore next -- internal/dispatch stages the same provider name */
68
+ if (!stagedRemovals.delete(providerName))
69
+ return;
70
+ providers.delete(providerName);
71
+ }, { global: true });
72
+ ctx.on('subagent/start', (info) => {
73
+ /* v8 ignore next -- internal/dispatch stages the same lifecycle object */
74
+ if (!stagedStarts.delete(info))
75
+ return;
76
+ runs.set(info.runId, info);
77
+ }, { global: true });
78
+ ctx.on('subagent/end', (info) => {
79
+ /* v8 ignore next -- internal/dispatch stages the same lifecycle object */
80
+ if (!stagedEnds.delete(info))
81
+ return;
82
+ runs.delete(info.runId);
83
+ }, { global: true });
84
+ }, { inject: ['subagents'] });
85
+ /**
86
+ * Register the subagent invariant companion.
87
+ * @param ctx - Cordis context carrying the invariant service.
88
+ * @returns the installed registration's disposer after setup succeeds.
89
+ */
90
+ export const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
91
+ //# sourceMappingURL=invariant.js.map
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Lifecycle-edge publication for both subagent shapes: the contained emitter,
3
+ * the one-shot run observer, and the continuable Activation observer.
4
+ *
5
+ * The public payload contracts ({@link SubagentRunInfo},
6
+ * {@link SubagentRunEndInfo}) live in `./types.ts` with the rest of the seam's
7
+ * consumer-facing types; this module owns only the implementation and the
8
+ * package-private {@link ActivationObserver} the continuation manager consumes.
9
+ * Keeping the internal control interface out of the published surface is
10
+ * deliberate: the observer's `start`/`capture`/`settle` ordering is a contract
11
+ * between this module and one in-package caller, not something a plugin may
12
+ * depend on.
13
+ *
14
+ * @module @deepseek-ai/dsh-subagent/lifecycle
15
+ */
16
+ import type { Context } from '@deepseek-ai/cordis';
17
+ import type { Agent } from '@deepseek-ai/dsh-agent';
18
+ import type { ContentBlock } from '@deepseek-ai/dsh-llm';
19
+ import type { SessionId } from '@deepseek-ai/dsh-session';
20
+ import type { SubagentResult, SubagentRun, SubagentRunEndInfo, SubagentRunInfo } from './types.ts';
21
+ /**
22
+ * How one Activation's residency epoch ended, as both the terminal lifecycle
23
+ * edge and the manager's own parent delivery report it.
24
+ */
25
+ export interface ActivationTerminal {
26
+ /** Why this epoch's last ordinary turn ended, or `error` when teardown failed. */
27
+ readonly stopReason: SubagentResult['stopReason'];
28
+ /** The epoch's final assistant content, absent when it produced none or failed. */
29
+ readonly output?: ContentBlock[];
30
+ }
31
+ /**
32
+ * Lifecycle observer for one Activation's residency epoch, so continuable
33
+ * children emit the same start/end pair as one-shot runs. Package-private: the
34
+ * continuation manager is the only consumer, and its call ordering is an
35
+ * in-package contract rather than a published extension point.
36
+ */
37
+ export interface ActivationObserver {
38
+ /**
39
+ * Publish the start edge once the epoch is resident.
40
+ * @param child - the resident child agent, whose log suffix bounds this epoch.
41
+ */
42
+ start(child: Agent): void;
43
+ /**
44
+ * Snapshot the child-dependent terminal facts while the child is still
45
+ * registered, because handle disposal unregisters it and consumers resolve it
46
+ * to read the child's own log and scope.
47
+ * @param child - the quiescent child agent about to be released.
48
+ */
49
+ capture(child: Agent): void;
50
+ /**
51
+ * Resolve the terminal facts {@link settle} will publish, without publishing
52
+ * them. The manager's parent delivery must run before the ownership release
53
+ * that lets the parent settle, which is earlier than the terminal edge; both
54
+ * therefore read one computation instead of restating the failure rule.
55
+ * @param failure - the teardown or durability failure, or `undefined` on success.
56
+ * @returns this epoch's stop reason and final assistant content.
57
+ */
58
+ terminal(failure: unknown): ActivationTerminal;
59
+ /**
60
+ * Publish the terminal edge exactly once, pairing this epoch's {@link start},
61
+ * after the disposal outcome is known. Called only for a resident epoch: a
62
+ * failure before residency publishes no edge, because inventing one would
63
+ * report a lifecycle the child never had.
64
+ * @param failure - the teardown or durability failure, or `undefined` on success.
65
+ */
66
+ settle(failure: unknown): void;
67
+ }
68
+ /**
69
+ * Publish one lifecycle edge with per-listener exception containment. Run edges
70
+ * carry the delegating parent that keys scoped dispatch; provider removal has no
71
+ * parent carrier and reaches listeners unscoped.
72
+ *
73
+ * The service owns this closure because scoped dispatch keys its carrier by the
74
+ * exact service instance, whose own context filter composes into the carrier;
75
+ * a narrowed stand-in would silently change scope filtering.
76
+ */
77
+ export type LifecycleEmitter = {
78
+ (name: 'subagent/start', info: SubagentRunInfo, parent: Agent): void;
79
+ (name: 'subagent/end', info: SubagentRunEndInfo, parent: Agent): void;
80
+ (name: 'subagent/provider-removed', info: string): void;
81
+ };
82
+ /**
83
+ * Build the contained lifecycle emitter this seam publishes every edge through.
84
+ * Every listener is independently contained: a synchronous throw or a rejected
85
+ * returned promise is logged without starving peer listeners, changing the run,
86
+ * or — for provider removal, which fires from a disposer — breaking teardown.
87
+ * @param ctx - the service's own context, owning dispatch and the logger.
88
+ * @param carrier - resolve the scoped dispatch carrier for one delegating parent.
89
+ * @returns the emitter both observers and the provider registry publish through.
90
+ */
91
+ export declare function createLifecycleEmitter(ctx: Context, carrier: (parent: Agent) => object): LifecycleEmitter;
92
+ /**
93
+ * Emit the start/end lifecycle pair for one accepted one-shot run.
94
+ * @param emit - the contained lifecycle emitter.
95
+ * @param provider - the provider that established the run.
96
+ * @param parent - the delegating parent keying scoped dispatch.
97
+ * @param run - the published run whose settlement closes the pair.
98
+ * @returns the same run, unchanged.
99
+ */
100
+ export declare function observeRun(emit: LifecycleEmitter, provider: string, parent: Agent, run: SubagentRun): SubagentRun;
101
+ /**
102
+ * Build the observer for one continuable Activation's residency epoch. Observers
103
+ * see the same vocabulary as a one-shot run, so a child's start and settlement
104
+ * remain observable without exposing whether the manager materialized, woke, or
105
+ * cold-resumed it. Creation failure before residency emits no lifecycle edge.
106
+ * @param emit - the contained lifecycle emitter.
107
+ * @param provider - the provider name recorded in the durable descriptor.
108
+ * @param childId - the durable child session id.
109
+ * @param parent - the exact live direct parent keying scoped dispatch.
110
+ * @returns the observer whose edges this epoch publishes.
111
+ */
112
+ export declare function createActivationObserver(emit: LifecycleEmitter, provider: string, childId: SessionId, parent: Agent): ActivationObserver;
113
+ //# sourceMappingURL=lifecycle.d.ts.map
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Lifecycle-edge publication for both subagent shapes: the contained emitter,
3
+ * the one-shot run observer, and the continuable Activation observer.
4
+ *
5
+ * The public payload contracts ({@link SubagentRunInfo},
6
+ * {@link SubagentRunEndInfo}) live in `./types.ts` with the rest of the seam's
7
+ * consumer-facing types; this module owns only the implementation and the
8
+ * package-private {@link ActivationObserver} the continuation manager consumes.
9
+ * Keeping the internal control interface out of the published surface is
10
+ * deliberate: the observer's `start`/`capture`/`settle` ordering is a contract
11
+ * between this module and one in-package caller, not something a plugin may
12
+ * depend on.
13
+ *
14
+ * @module @deepseek-ai/dsh-subagent/lifecycle
15
+ */
16
+ import { randomUUID } from 'node:crypto';
17
+ import { foldConsumedWork } from '@deepseek-ai/dsh-agent';
18
+ import { SessionLogOffset } from '@deepseek-ai/dsh-session';
19
+ import { finalAssistantOutput } from "./assistant-output.js";
20
+ import { SubagentRunId } from "./types.js";
21
+ /**
22
+ * Build the contained lifecycle emitter this seam publishes every edge through.
23
+ * Every listener is independently contained: a synchronous throw or a rejected
24
+ * returned promise is logged without starving peer listeners, changing the run,
25
+ * or — for provider removal, which fires from a disposer — breaking teardown.
26
+ * @param ctx - the service's own context, owning dispatch and the logger.
27
+ * @param carrier - resolve the scoped dispatch carrier for one delegating parent.
28
+ * @returns the emitter both observers and the provider registry publish through.
29
+ */
30
+ export function createLifecycleEmitter(ctx, carrier) {
31
+ return (name, info, parent) => {
32
+ const dispatchArgs = parent === undefined
33
+ ? [name, info]
34
+ : [carrier(parent), name, info];
35
+ for (const callback of ctx.events.dispatch('emit', dispatchArgs)) {
36
+ try {
37
+ const returned = callback(info);
38
+ void Promise.resolve(returned).catch((error) => {
39
+ ctx.logger.warn(`subagent: ${name} listener rejected: ${renderThrown(error)}`);
40
+ });
41
+ }
42
+ catch (error) {
43
+ ctx.logger.warn(`subagent: ${name} listener threw: ${renderThrown(error)}`);
44
+ }
45
+ }
46
+ };
47
+ }
48
+ /**
49
+ * Emit the start/end lifecycle pair for one accepted one-shot run.
50
+ * @param emit - the contained lifecycle emitter.
51
+ * @param provider - the provider that established the run.
52
+ * @param parent - the delegating parent keying scoped dispatch.
53
+ * @param run - the published run whose settlement closes the pair.
54
+ * @returns the same run, unchanged.
55
+ */
56
+ export function observeRun(emit, provider, parent, run) {
57
+ const identity = {
58
+ runId: SubagentRunId(randomUUID()),
59
+ provider,
60
+ id: run.id,
61
+ local: run.localAgent !== undefined,
62
+ };
63
+ // Attach the terminal observer before dispatching start. Promise reactions
64
+ // still run after this synchronous start emission, preserving start → end.
65
+ void run.result.then((result) => {
66
+ emit('subagent/end', {
67
+ ...identity,
68
+ stopReason: result.stopReason,
69
+ // Omit the field when no output exists, matching continuable epochs.
70
+ ...result.output.length === 0 ? {} : { lastAssistantMessage: result.output },
71
+ }, parent);
72
+ }, () => {
73
+ emit('subagent/end', { ...identity, stopReason: 'error' }, parent);
74
+ });
75
+ emit('subagent/start', identity, parent);
76
+ return run;
77
+ }
78
+ /**
79
+ * Build the observer for one continuable Activation's residency epoch. Observers
80
+ * see the same vocabulary as a one-shot run, so a child's start and settlement
81
+ * remain observable without exposing whether the manager materialized, woke, or
82
+ * cold-resumed it. Creation failure before residency emits no lifecycle edge.
83
+ * @param emit - the contained lifecycle emitter.
84
+ * @param provider - the provider name recorded in the durable descriptor.
85
+ * @param childId - the durable child session id.
86
+ * @param parent - the exact live direct parent keying scoped dispatch.
87
+ * @returns the observer whose edges this epoch publishes.
88
+ */
89
+ export function createActivationObserver(emit, provider, childId, parent) {
90
+ const identity = { runId: SubagentRunId(randomUUID()), provider, id: childId, local: true };
91
+ // A cold resume replays earlier turns, so this epoch's telemetry must come
92
+ // from the suffix it actually produced — never the whole session, which
93
+ // would report a previous epoch's answer when this one opened no turn.
94
+ let boundary = SessionLogOffset(0);
95
+ // Assigned by `capture()`, which the disposal path always runs before
96
+ // `settle()`; a resident epoch therefore always has its facts by then.
97
+ let captured = { stopReason: 'completed' };
98
+ // Teardown failure overrides the epoch's own outcome and withholds its
99
+ // output: an answer this harness could not durably release is not a result.
100
+ const terminal = (failure) => failure === undefined
101
+ ? captured
102
+ : { stopReason: 'error' };
103
+ return {
104
+ start: (child) => {
105
+ boundary = child.session.seq;
106
+ emit('subagent/start', identity, parent);
107
+ },
108
+ capture: (child) => {
109
+ const own = child.session.snapshotEvents(boundary);
110
+ const output = finalAssistantOutput(own);
111
+ captured = {
112
+ stopReason: epochStopReason(own),
113
+ ...output === undefined ? {} : { output },
114
+ };
115
+ },
116
+ terminal,
117
+ settle: (failure) => {
118
+ const { stopReason, output } = terminal(failure);
119
+ emit('subagent/end', {
120
+ ...identity,
121
+ stopReason,
122
+ ...output === undefined ? {} : { lastAssistantMessage: output },
123
+ }, parent);
124
+ },
125
+ };
126
+ }
127
+ /**
128
+ * Why this child's epoch ended, for the terminal lifecycle edge and the
129
+ * manager's own parent delivery. The child's own log is authoritative:
130
+ * teardown succeeding says nothing about whether the model errored, hit its
131
+ * token ceiling, or was cancelled, so deriving the reason from disposal would
132
+ * report failed work as completed.
133
+ *
134
+ * {@link foldConsumedWork} supplies both halves the raw turn sequence cannot:
135
+ * which turn accounts for the work this epoch consumed, and whether accepted
136
+ * work was cancelled after it without any turn opening over it. A recorded
137
+ * failure still wins over a cancellation — stopping a child that had already
138
+ * failed does not turn its failure into a cancellation.
139
+ * @param events - this epoch's own event suffix.
140
+ * @returns its terminal stop reason; `completed` only for an epoch that both
141
+ * closed cleanly and had nothing left to run.
142
+ */
143
+ function epochStopReason(events) {
144
+ const { end, droppedUnrun } = foldConsumedWork(events);
145
+ switch (end?.data.reason.kind) {
146
+ case 'max-tokens':
147
+ return 'max-tokens';
148
+ case 'aborted':
149
+ case 'interrupted':
150
+ return 'aborted';
151
+ case 'error':
152
+ return 'error';
153
+ // A pre-step rejection — a hook deny, a policy plugin — discarded input
154
+ // this epoch had claimed: the work was declined, not done.
155
+ case 'blocked':
156
+ return 'refusal';
157
+ // A clean ending and no accounting turn at all share one rule: the epoch
158
+ // finished what it was given unless a cancelled queue says otherwise.
159
+ case undefined:
160
+ case 'completed':
161
+ return droppedUnrun ? 'aborted' : 'completed';
162
+ /* v8 ignore next 3 -- `TurnEndReason` is merge-extensible, so this arm needs a
163
+ * backend that adds a variant; treating an unnameable reason as success would
164
+ * report failed work as completed. */
165
+ default:
166
+ return 'error';
167
+ }
168
+ }
169
+ /** Render any listener-thrown value without letting coercion escape containment. */
170
+ function renderThrown(value) {
171
+ try {
172
+ return value instanceof Error ? `${value.name}: ${value.message}` : String(value);
173
+ }
174
+ catch {
175
+ return '<unrenderable thrown value>';
176
+ }
177
+ }
178
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Read-only enumeration of durable subagent children and descendant trees
3
+ * through the Session query service. Candidates come from one live-preferred
4
+ * corpus; each child's mode/label is the registered `subagent` projection
5
+ * unit's value, resolved
6
+ * down a three-rung ladder: the registry's watermark cache for a live child,
7
+ * an unseeded durable projection-cache row, and one shared Session observation
8
+ * otherwise. A seeded header deliberately lacks its exact inherited cut, so
9
+ * it takes the body-bearing observation path before classifying an identity.
10
+ * The projection fold is the single classification
11
+ * authority — this module parses no descriptor
12
+ * itself. Absent persistence, enumeration is live-only: a cold child is
13
+ * unreachable for resume anyway, so its absence is capability absence, not an
14
+ * error. The module owns no catalog state and does not consult Activation,
15
+ * Agent-registry, continuation-manager, or provider state.
16
+ *
17
+ * @module @deepseek-ai/dsh-subagent
18
+ */
19
+ import type { Context } from '@deepseek-ai/cordis';
20
+ import type { SessionId } from '@deepseek-ai/dsh-session';
21
+ import type { SubagentListEntry } from './control-types.ts';
22
+ export type { SubagentListEntry } from './control-types.ts';
23
+ /**
24
+ * One entry of a descendant listing: the interpreted subagent facts plus its
25
+ * position in the complete session tree. `parentId` is the durable direct
26
+ * parent from the enumerated header, and `depth` counts edges from the root.
27
+ */
28
+ export type SubagentDescendantListEntry = SubagentListEntry & {
29
+ /** Durable direct parent of this candidate in the enumerated tree. */
30
+ readonly parentId: SessionId;
31
+ /** Edge distance from the requested root; direct children are `1`. */
32
+ readonly depth: number;
33
+ };
34
+ /**
35
+ * Enumerate one parent's origin-classified direct children from the
36
+ * live-preferred merge of `ctx.sessions` and optional session persistence,
37
+ * serving each identity from the `subagent` projection unit: the registry's
38
+ * watermark snapshot for a live child; for a cold one, a durable
39
+ * projection-cache read for an unseeded lifecycle, else one bounded-concurrency
40
+ * shared Session observation carrying the exact inherited cut.
41
+ * @see SubagentRuntime.listChildren for the public cancellation and failure contract.
42
+ * @param ctx - context carrying the session store, the projection registry,
43
+ * optional persistence, and the optional projection cache.
44
+ * @param parentSessionId - parent session whose direct children are listed.
45
+ * @param signal - caller-owned cancellation observed around every persistence read.
46
+ * @returns children and per-child diagnostics ordered by `createdAt`, then id.
47
+ * @throws {@link SubagentError} when the projection registry or the session
48
+ * store is not mounted, or the caller cancels the listing.
49
+ */
50
+ export declare function listChildren(ctx: Context, parentSessionId: SessionId, signal?: AbortSignal): Promise<SubagentListEntry[]>;
51
+ /**
52
+ * Enumerate every session-backed subagent below one root in stable pre-order.
53
+ * Ordinary sessions and one-shot children remain traversal nodes, so a
54
+ * continuable child below either is still discovered. Classification uses the
55
+ * same projection-backed runtime as {@link listChildren}; no Agent is loaded or
56
+ * resumed.
57
+ * @see SubagentRuntime.listDescendants for the public cancellation and failure contract.
58
+ * @param ctx - context carrying the session store, projection registry, and optional persistence/cache.
59
+ * @param rootSessionId - session whose complete descendant tree is listed.
60
+ * @param signal - caller-owned cancellation observed around every persistence read.
61
+ * @returns interpreted subagents with durable direct-parent and root-relative depth.
62
+ * @throws {@link SubagentError} under the same conditions as {@link listChildren}.
63
+ */
64
+ export declare function listDescendants(ctx: Context, rootSessionId: SessionId, signal?: AbortSignal): Promise<SubagentDescendantListEntry[]>;
65
+ //# sourceMappingURL=list-children.d.ts.map