@lmzhen/dsh-evolution-core 0.48.0 → 0.50.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 (97) hide show
  1. package/lib/authority-plugin.js +2 -1
  2. package/lib/citations-CZKTUGQF.js +198 -0
  3. package/lib/composition/index.js +2 -2
  4. package/lib/{composition-Cqjbho0t.js → composition-DA8XPfMc.js} +1 -1
  5. package/lib/connection-DAJy7Xjm.js +28 -0
  6. package/lib/{ensure-CAjLGd9f.js → ensure-Bx4ksgJk.js} +15 -5
  7. package/lib/errors.js +2 -0
  8. package/lib/extract-plan-Bru3c9ec.js +271 -0
  9. package/lib/extract.js +240 -0
  10. package/lib/http-routes.js +27 -7
  11. package/lib/index.js +41 -822
  12. package/lib/{numeric-D8js3sqC.js → limits-C9jfvxBl.js} +1 -43
  13. package/lib/{mutation-authority-l57R626O.js → mutation-authority-DQfpXs1O.js} +2 -54
  14. package/lib/numeric-Dc53KQoe.js +43 -0
  15. package/lib/platform/index.js +4 -3
  16. package/lib/platform-DyHnHUmQ.js +251 -0
  17. package/lib/policy.js +3 -2
  18. package/lib/quality-WAU6YatF.js +554 -0
  19. package/lib/restrictor.js +1 -1
  20. package/lib/result.js +33 -0
  21. package/lib/runtime/plugin.js +97 -43
  22. package/lib/{session-projection-DSXnUNZG.js → session-projection-ByNxQi9O.js} +2 -198
  23. package/lib/skill-health-Bl-MdXZ4.js +1409 -0
  24. package/lib/skills.js +7 -4
  25. package/lib/state-store-Jpa-iYIZ.js +54 -0
  26. package/lib/subagent/index.js +214 -176
  27. package/lib/{tools-DzcNFex2.js → tools-BrUswg8v.js} +3 -1
  28. package/lib/types/composition/ensure.js +21 -7
  29. package/lib/types/extract-plan.d.ts +2 -0
  30. package/lib/types/extract.d.ts +12 -0
  31. package/lib/types/extract.js +12 -0
  32. package/lib/types/http-routes.js +32 -9
  33. package/lib/types/index.d.ts +0 -3
  34. package/lib/types/index.js +0 -3
  35. package/lib/types/long-runs.d.ts +0 -5
  36. package/lib/types/long-runs.js +0 -7
  37. package/lib/types/opt-in.js +4 -3
  38. package/lib/types/params.js +2 -1
  39. package/lib/types/platform/agents.d.ts +32 -0
  40. package/lib/types/platform/agents.js +26 -0
  41. package/lib/types/platform/commands.d.ts +14 -0
  42. package/lib/types/platform/commands.js +9 -0
  43. package/lib/types/platform/connection.d.ts +26 -0
  44. package/lib/types/platform/connection.js +27 -0
  45. package/lib/types/platform/index.d.ts +26 -0
  46. package/lib/types/platform/index.js +13 -0
  47. package/lib/types/platform/llm.d.ts +3 -1
  48. package/lib/types/platform/llm.js +1 -0
  49. package/lib/types/platform/platformView.d.ts +21 -0
  50. package/lib/types/platform/platformView.js +29 -0
  51. package/lib/types/platform/profileContext.d.ts +16 -0
  52. package/lib/types/platform/profileContext.js +14 -0
  53. package/lib/types/platform/sessionQuery.d.ts +14 -0
  54. package/lib/types/platform/sessionQuery.js +9 -0
  55. package/lib/types/platform/settings.d.ts +22 -0
  56. package/lib/types/platform/settings.js +14 -0
  57. package/lib/types/platform/skills.d.ts +16 -0
  58. package/lib/types/platform/skills.js +9 -0
  59. package/lib/types/platform/storageDomain.d.ts +13 -0
  60. package/lib/types/platform/storageDomain.js +9 -0
  61. package/lib/types/platform/subagents.d.ts +25 -0
  62. package/lib/types/platform/subagents.js +17 -0
  63. package/lib/types/platform/systemPrompt.d.ts +16 -0
  64. package/lib/types/platform/systemPrompt.js +13 -0
  65. package/lib/types/platform/tools.d.ts +4 -0
  66. package/lib/types/platform/tools.js +2 -0
  67. package/lib/types/platform/userQuestions.d.ts +33 -0
  68. package/lib/types/platform/userQuestions.js +9 -0
  69. package/lib/types/platform/workingDirectory.d.ts +14 -0
  70. package/lib/types/platform/workingDirectory.js +9 -0
  71. package/lib/types/platform-line.generated.d.ts +5 -5
  72. package/lib/types/platform-line.generated.js +5 -5
  73. package/lib/types/platform-services.js +3 -0
  74. package/lib/types/result.d.ts +35 -0
  75. package/lib/types/result.js +25 -0
  76. package/lib/types/runtime/llm.d.ts +2 -2
  77. package/lib/types/runtime/llm.js +5 -8
  78. package/lib/types/runtime/platform.d.ts +37 -4
  79. package/lib/types/runtime/platform.js +40 -5
  80. package/lib/types/runtime/projections.d.ts +9 -4
  81. package/lib/types/runtime/projections.js +64 -28
  82. package/lib/types/subagent/channel.d.ts +1 -3
  83. package/lib/types/subagent/channel.js +2 -332
  84. package/lib/types/subagent/index.d.ts +2 -0
  85. package/lib/types/subagent/index.js +2 -0
  86. package/lib/types/subagent/kernel.d.ts +4 -0
  87. package/lib/types/subagent/kernel.js +234 -0
  88. package/lib/types/subagent/readiness.js +5 -7
  89. package/lib/types/subagent/run.d.ts +53 -0
  90. package/lib/types/subagent/run.js +125 -0
  91. package/lib/types/subagent/types.d.ts +2 -2
  92. package/lib/types/write-inventory.d.ts +0 -11
  93. package/lib/types/write-inventory.js +0 -16
  94. package/lib/usage-DdjIBAkm.js +1252 -0
  95. package/package.json +37 -25
  96. package/lib/platform-Cc9cNt5j.js +0 -111
  97. package/lib/skill-health-DP8z9TPf.js +0 -2923
@@ -0,0 +1,125 @@
1
+ export function textOfValue(value) {
2
+ if (typeof value === 'string')
3
+ return value;
4
+ if (!Array.isArray(value))
5
+ return '';
6
+ return value
7
+ .filter(block => typeof block === 'object' && block !== null && block.type === 'text')
8
+ .map((block) => {
9
+ const text = block.text;
10
+ return typeof text === 'string' ? text : '';
11
+ })
12
+ .join('');
13
+ }
14
+ export function abortLink(signal, timeoutMs) {
15
+ const controller = new AbortController();
16
+ const timer = setTimeout(() => { controller.abort(new Error('subagent turn timeout')); }, timeoutMs);
17
+ const onAbort = () => { controller.abort(signal?.reason); };
18
+ signal?.addEventListener('abort', onAbort, { once: true });
19
+ return {
20
+ controller,
21
+ cleanup: () => {
22
+ clearTimeout(timer);
23
+ signal?.removeEventListener('abort', onAbort);
24
+ },
25
+ };
26
+ }
27
+ export function waitForSubagentEnd(ctx, childId, signal, timeoutMs) {
28
+ return new Promise((resolve, reject) => {
29
+ let settled = false;
30
+ const finish = (fn) => {
31
+ if (settled)
32
+ return;
33
+ settled = true;
34
+ cleanup();
35
+ fn();
36
+ };
37
+ const eventCtx = ctx;
38
+ const off = typeof eventCtx.on === 'function'
39
+ ? eventCtx.on('subagent/end', (info) => {
40
+ if (info.id !== childId)
41
+ return;
42
+ finish(() => { resolve(info); });
43
+ })
44
+ : () => { };
45
+ const timer = setTimeout(() => {
46
+ finish(() => { reject(new Error('timed out waiting for subagent/end: ' + childId)); });
47
+ }, timeoutMs);
48
+ const onAbort = () => {
49
+ finish(() => { reject(signal.reason instanceof Error ? signal.reason : new Error('conversation turn aborted')); });
50
+ };
51
+ signal.addEventListener('abort', onAbort, { once: true });
52
+ function cleanup() {
53
+ clearTimeout(timer);
54
+ signal.removeEventListener('abort', onAbort);
55
+ off();
56
+ }
57
+ if (signal.aborted)
58
+ onAbort();
59
+ });
60
+ }
61
+ /** Wrap one started activation in the single continuation handle. */
62
+ export function createSubagentRun(ctx, parent, name, activation) {
63
+ let disposed = false;
64
+ let pending;
65
+ const map = (value) => {
66
+ const output = value.output ?? value.lastAssistantMessage;
67
+ return {
68
+ childId: activation.childId,
69
+ stopReason: value.stopReason,
70
+ ...(output === undefined ? {} : { output }),
71
+ ...(value.structured === undefined ? {} : { structured: value.structured }),
72
+ ...(value.diagnostic === undefined ? {} : { diagnostic: value.diagnostic }),
73
+ };
74
+ };
75
+ const openTurn = (options) => {
76
+ const link = abortLink(options?.signal, options?.timeoutMs ?? 120_000);
77
+ return { promise: waitForSubagentEnd(ctx, activation.childId, link.controller.signal, options?.timeoutMs ?? 120_000), cleanup: link.cleanup, controller: link.controller };
78
+ };
79
+ return {
80
+ id: activation.childId,
81
+ name,
82
+ result: activation.result.then(map),
83
+ async send(prompt, options) {
84
+ if (disposed)
85
+ throw new Error('subagent run is disposed');
86
+ const platform = ctx.get('evolutionPlatform');
87
+ const send = platform?.ports.subagents?.sendMessage;
88
+ if (send === undefined)
89
+ throw new Error('subagents.sendMessage unavailable');
90
+ pending?.cleanup();
91
+ const turn = openTurn(options);
92
+ pending = turn;
93
+ try {
94
+ await send(parent, activation.childId, prompt, { signal: turn.controller.signal });
95
+ }
96
+ catch (error) {
97
+ pending = undefined;
98
+ turn.cleanup();
99
+ throw error;
100
+ }
101
+ },
102
+ async next(options) {
103
+ if (disposed)
104
+ throw new Error('subagent run is disposed');
105
+ const turn = pending ?? openTurn(options);
106
+ pending = undefined;
107
+ try {
108
+ const info = await turn.promise;
109
+ return map({ ...info, stopReason: info.stopReason ?? 'completed' });
110
+ }
111
+ finally {
112
+ turn.cleanup();
113
+ }
114
+ },
115
+ async dispose() {
116
+ if (disposed)
117
+ return;
118
+ disposed = true;
119
+ pending?.cleanup();
120
+ pending = undefined;
121
+ await activation.dispose();
122
+ },
123
+ };
124
+ }
125
+ //# sourceMappingURL=run.js.map
@@ -1,4 +1,4 @@
1
- import type { Agent, AgentOptions } from '../platform/index.ts';
1
+ import type { Agent, AgentIdentity, AgentOptions } from '../platform/index.ts';
2
2
  import type { SessionId } from '../platform/index.ts';
3
3
  import type { SubagentStopReason } from '../platform/index.ts';
4
4
  import type { ObjectJsonSchema } from '../platform/index.ts';
@@ -48,7 +48,7 @@ export interface ChannelSpec<T = undefined> {
48
48
  readonly maxDepth?: number;
49
49
  readonly timeoutMs: number;
50
50
  readonly signal?: AbortSignal;
51
- readonly afterResult?: (child: Agent) => T;
51
+ readonly afterResult?: (child: AgentIdentity) => T;
52
52
  }
53
53
  /** Open one child for a multi-turn conversation. Round 1 is the prompt. */
54
54
  export interface ConversationOpenSpec {
@@ -70,16 +70,5 @@ export declare const INSTANCE_KEYS: {
70
70
  * @returns the sites, in file order.
71
71
  */
72
72
  export declare function persistedWriteSites(): readonly PersistedWriteSite[];
73
- /** Sites serialized by the per-home instance claim, with their instance keys.
74
- * @internal S2.4 (PLAN 2026-09-16): no production caller — the arch guard
75
- * reads the JSON asset directly; the tests are the only in-tree consumers. */
76
- export declare function instanceClaimedWriteSites(): readonly (PersistedWriteSite & {
77
- readonly instance: string;
78
- })[];
79
- /** One declared site by id. An undeclared id throws — a stale caller must fail
80
- * loud rather than read "nothing is declared".
81
- * @internal S2.4 (PLAN 2026-09-16): no production caller — the arch guard
82
- * reads the JSON asset directly; the tests are the only in-tree consumers. */
83
- export declare function persistedWriteSite(id: string): PersistedWriteSite;
84
73
  export {};
85
74
  //# sourceMappingURL=write-inventory.d.ts.map
@@ -132,20 +132,4 @@ export function persistedWriteSites() {
132
132
  cachedSites = table.sites;
133
133
  return table.sites;
134
134
  }
135
- /** Sites serialized by the per-home instance claim, with their instance keys.
136
- * @internal S2.4 (PLAN 2026-09-16): no production caller — the arch guard
137
- * reads the JSON asset directly; the tests are the only in-tree consumers. */
138
- export function instanceClaimedWriteSites() {
139
- return persistedWriteSites().filter((site) => site.serializedBy === 'instance-claim');
140
- }
141
- /** One declared site by id. An undeclared id throws — a stale caller must fail
142
- * loud rather than read "nothing is declared".
143
- * @internal S2.4 (PLAN 2026-09-16): no production caller — the arch guard
144
- * reads the JSON asset directly; the tests are the only in-tree consumers. */
145
- export function persistedWriteSite(id) {
146
- const site = persistedWriteSites().find(candidate => candidate.id === id);
147
- if (site === undefined)
148
- throw new Error(`evolution-core: no persisted write site "${id}" in persisted-write-inventory.json`);
149
- return site;
150
- }
151
135
  //# sourceMappingURL=write-inventory.js.map