@yourtechbudstudio/fluidcast-tool-agent 0.0.0-stage → 0.0.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 (91) hide show
  1. package/LICENSE +201 -0
  2. package/dist/claude/attach.d.ts +24 -0
  3. package/dist/claude/attach.d.ts.map +1 -0
  4. package/dist/claude/attach.js +25 -0
  5. package/dist/claude/attach.js.map +1 -0
  6. package/dist/claude/connect.d.ts +52 -0
  7. package/dist/claude/connect.d.ts.map +1 -0
  8. package/dist/claude/connect.js +93 -0
  9. package/dist/claude/connect.js.map +1 -0
  10. package/dist/claude/failure.d.ts +35 -0
  11. package/dist/claude/failure.d.ts.map +1 -0
  12. package/dist/claude/failure.js +42 -0
  13. package/dist/claude/failure.js.map +1 -0
  14. package/dist/claude/index.d.ts +30 -0
  15. package/dist/claude/index.d.ts.map +1 -0
  16. package/dist/claude/index.js +41 -0
  17. package/dist/claude/index.js.map +1 -0
  18. package/dist/claude/transcript.d.ts +33 -0
  19. package/dist/claude/transcript.d.ts.map +1 -0
  20. package/dist/claude/transcript.js +217 -0
  21. package/dist/claude/transcript.js.map +1 -0
  22. package/dist/claude/turn.d.ts +57 -0
  23. package/dist/claude/turn.d.ts.map +1 -0
  24. package/dist/claude/turn.js +96 -0
  25. package/dist/claude/turn.js.map +1 -0
  26. package/dist/codex/attach.d.ts +29 -0
  27. package/dist/codex/attach.d.ts.map +1 -0
  28. package/dist/codex/attach.js +78 -0
  29. package/dist/codex/attach.js.map +1 -0
  30. package/dist/codex/connect.d.ts +71 -0
  31. package/dist/codex/connect.d.ts.map +1 -0
  32. package/dist/codex/connect.js +93 -0
  33. package/dist/codex/connect.js.map +1 -0
  34. package/dist/codex/index.d.ts +60 -0
  35. package/dist/codex/index.d.ts.map +1 -0
  36. package/dist/codex/index.js +53 -0
  37. package/dist/codex/index.js.map +1 -0
  38. package/dist/codex/process.d.ts +41 -0
  39. package/dist/codex/process.d.ts.map +1 -0
  40. package/dist/codex/process.js +66 -0
  41. package/dist/codex/process.js.map +1 -0
  42. package/dist/codex/protocol.d.ts +133 -0
  43. package/dist/codex/protocol.d.ts.map +1 -0
  44. package/dist/codex/protocol.js +189 -0
  45. package/dist/codex/protocol.js.map +1 -0
  46. package/dist/codex/rpc.d.ts +51 -0
  47. package/dist/codex/rpc.d.ts.map +1 -0
  48. package/dist/codex/rpc.js +133 -0
  49. package/dist/codex/rpc.js.map +1 -0
  50. package/dist/codex/transcript.d.ts +38 -0
  51. package/dist/codex/transcript.d.ts.map +1 -0
  52. package/dist/codex/transcript.js +246 -0
  53. package/dist/codex/transcript.js.map +1 -0
  54. package/dist/codex/turn.d.ts +35 -0
  55. package/dist/codex/turn.d.ts.map +1 -0
  56. package/dist/codex/turn.js +132 -0
  57. package/dist/codex/turn.js.map +1 -0
  58. package/dist/content.d.ts +9 -0
  59. package/dist/content.d.ts.map +1 -0
  60. package/dist/content.js +8 -0
  61. package/dist/content.js.map +1 -0
  62. package/dist/forward-tool.d.ts +68 -0
  63. package/dist/forward-tool.d.ts.map +1 -0
  64. package/dist/forward-tool.js +57 -0
  65. package/dist/forward-tool.js.map +1 -0
  66. package/dist/handoff.d.ts +70 -0
  67. package/dist/handoff.d.ts.map +1 -0
  68. package/dist/handoff.js +238 -0
  69. package/dist/handoff.js.map +1 -0
  70. package/dist/index.d.ts +6 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +6 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/progress.d.ts +42 -0
  75. package/dist/progress.d.ts.map +1 -0
  76. package/dist/progress.js +88 -0
  77. package/dist/progress.js.map +1 -0
  78. package/dist/schema.d.ts +267 -0
  79. package/dist/schema.d.ts.map +1 -0
  80. package/dist/schema.js +112 -0
  81. package/dist/schema.js.map +1 -0
  82. package/dist/session.d.ts +100 -0
  83. package/dist/session.d.ts.map +1 -0
  84. package/dist/session.js +316 -0
  85. package/dist/session.js.map +1 -0
  86. package/dist/worker.d.ts +69 -0
  87. package/dist/worker.d.ts.map +1 -0
  88. package/dist/worker.js +9 -0
  89. package/dist/worker.js.map +1 -0
  90. package/package.json +74 -3
  91. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Preloading a stored Claude Code session, with the SDK's session readers as a parameter so it can
3
+ * be driven by synthetic history. Internal: the `./claude` entry builds `claudeWorker` from it.
4
+ */
5
+ import type { getSessionInfo, getSessionMessages, getSubagentMessages, listSubagents } from '@anthropic-ai/claude-agent-sdk';
6
+ import { Effect } from 'effect';
7
+ import type { TranscriptEntry } from '../schema.ts';
8
+ import { WorkerSetupError } from '../worker.ts';
9
+ /** The SDK's session readers. */
10
+ export interface SessionStore {
11
+ readonly getSessionInfo: typeof getSessionInfo;
12
+ readonly getSessionMessages: typeof getSessionMessages;
13
+ readonly listSubagents: typeof listSubagents;
14
+ readonly getSubagentMessages: typeof getSubagentMessages;
15
+ }
16
+ /**
17
+ * Checks a session exists and reads its directory (its recorded one, else `cwd`) and history,
18
+ * with each earlier subagent nested under its starting call. Spawns nothing.
19
+ */
20
+ export declare const attachWith: (store: SessionStore, cwd: string) => (sessionId: string) => Effect.Effect<{
21
+ readonly cwd: string;
22
+ readonly history: ReadonlyArray<TranscriptEntry>;
23
+ }, WorkerSetupError>;
24
+ //# sourceMappingURL=attach.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attach.d.ts","sourceRoot":"","sources":["../../src/claude/attach.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EACV,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACd,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,iCAAiC;AACjC,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,cAAc,EAAE,OAAO,cAAc,CAAC;IAC/C,QAAQ,CAAC,kBAAkB,EAAE,OAAO,kBAAkB,CAAC;IACvD,QAAQ,CAAC,aAAa,EAAE,OAAO,aAAa,CAAC;IAC7C,QAAQ,CAAC,mBAAmB,EAAE,OAAO,mBAAmB,CAAC;CAC1D;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,UACb,YAAY,OAAO,MAAM,iBAEpB,MAAM,KAChB,MAAM,CAAC,MAAM,CACd;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,eAAe,CAAC,CAAA;CAAE,EAC1E,gBAAgB,CAuBd,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { Effect } from 'effect';
2
+ import { WorkerSetupError } from '../worker.js';
3
+ import { historyEntries } from './transcript.js';
4
+ /**
5
+ * Checks a session exists and reads its directory (its recorded one, else `cwd`) and history,
6
+ * with each earlier subagent nested under its starting call. Spawns nothing.
7
+ */
8
+ export const attachWith = (store, cwd) => (sessionId) => Effect.gen(function* () {
9
+ const read = (promise) => Effect.tryPromise({
10
+ try: promise,
11
+ catch: () => new WorkerSetupError({ sessionId, reason: 'SessionUnreadable' }),
12
+ });
13
+ const info = yield* read(() => store.getSessionInfo(sessionId));
14
+ if (info === undefined) {
15
+ return yield* new WorkerSetupError({ sessionId, reason: 'SessionNotFound' });
16
+ }
17
+ const dir = info.cwd ?? cwd;
18
+ const [main, agentIds] = yield* Effect.all([
19
+ read(() => store.getSessionMessages(sessionId, { dir })),
20
+ read(() => store.listSubagents(sessionId, { dir })),
21
+ ]);
22
+ const subagents = yield* Effect.forEach(agentIds, (agentId) => read(() => store.getSubagentMessages(sessionId, agentId, { dir })).pipe(Effect.map((messages) => ({ agentId, messages }))));
23
+ return { cwd: dir, history: historyEntries(main, subagents) };
24
+ });
25
+ //# sourceMappingURL=attach.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attach.js","sourceRoot":"","sources":["../../src/claude/attach.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAUjD;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GACrB,CAAC,KAAmB,EAAE,GAAW,EAAE,EAAE,CACrC,CACE,SAAiB,EAIjB,EAAE,CACF,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,IAAI,GAAG,CAAI,OAAyB,EAAE,EAAE,CAC5C,MAAM,CAAC,UAAU,CAAC;QAChB,GAAG,EAAE,OAAO;QACZ,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC;KAC9E,CAAC,CAAC;IACL,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;IAChE,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC,CAAC,IAAI,gBAAgB,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAC/E,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC;IAC5B,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;QACzC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QACxD,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;KACpD,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE,CAC5D,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CACrE,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,CAClD,CACF,CAAC;IACF,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,CAAC;AAChE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The effectful side of a Claude Code worker, with the SDK's `query` as a parameter so it can be
3
+ * driven by synthetic frames. Internal: the `./claude` entry builds `claudeWorker` from it.
4
+ */
5
+ import type { EffortLevel, Options, PermissionMode, SDKMessage, SDKUserMessage } from '@anthropic-ai/claude-agent-sdk';
6
+ import { Stream } from 'effect';
7
+ import { ToolFault } from '@yourtechbudstudio/fluidcast-harness';
8
+ import type { WorkerEvent, WorkerMessage } from '../worker.ts';
9
+ import { type TurnState } from './turn.ts';
10
+ /** What the adapter needs of the SDK's `query`: frames to iterate, and a way to close them. */
11
+ export type QueryFunction = (params: {
12
+ readonly prompt: AsyncIterable<SDKUserMessage>;
13
+ readonly options: Options;
14
+ }) => AsyncIterable<SDKMessage> & {
15
+ readonly close: () => void;
16
+ };
17
+ export interface ConnectOptions {
18
+ /**
19
+ * The installed `claude` executable, absolute: the SDK checks that it exists. Required, so the SDK
20
+ * never falls back to its bundled one.
21
+ */
22
+ readonly executable: string;
23
+ readonly model?: string | undefined;
24
+ readonly effort?: EffortLevel | undefined;
25
+ readonly permissionMode?: PermissionMode | undefined;
26
+ /** The whole worker environment: the SDK replaces the process environment, never merges. */
27
+ readonly environment: Readonly<Record<string, string | undefined>>;
28
+ /** A settings file for this query only (per-invocation host instrumentation); default: none. */
29
+ readonly settings?: string | undefined;
30
+ }
31
+ export interface WorkerConnection {
32
+ readonly cwd: string;
33
+ /** The session to continue; `undefined`: a new session, whose ID Claude Code chooses. */
34
+ readonly resume: string | undefined;
35
+ }
36
+ /** The query options of one worker. */
37
+ export declare const queryOptions: (options: ConnectOptions, worker: WorkerConnection) => Options;
38
+ /**
39
+ * Frames through the turn tracker, one input at a time: one processing fiber over one queue of
40
+ * frames and elapsed grace timers, the timer in a `FiberHandle`. A failure of `frames` (the
41
+ * process ended or crashed) fails the stream after every earlier frame is processed; a fault a
42
+ * frame reports fails it at once.
43
+ */
44
+ export declare const runTracker: (frames: Stream.Stream<SDKMessage, ToolFault>, initial: TurnState) => Stream.Stream<WorkerEvent, ToolFault>;
45
+ /**
46
+ * One worker process for as long as the stream is consumed. Its input is `input` as ordinary user
47
+ * messages; the scope's release closes the query. The end of the frames is a crash
48
+ * (`ClaudeExited`); interruption is teardown and records nothing. `interrupt()` and
49
+ * `backgroundTasks()` are never used.
50
+ */
51
+ export declare const connectWith: (query: QueryFunction, options: ConnectOptions) => (worker: WorkerConnection, input: Stream.Stream<WorkerMessage>) => Stream.Stream<WorkerEvent, ToolFault>;
52
+ //# sourceMappingURL=connect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/claude/connect.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EACV,WAAW,EACX,OAAO,EACP,cAAc,EACd,UAAU,EACV,cAAc,EACf,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAA8B,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE5D,OAAO,EAAE,SAAS,EAAE,MAAM,sCA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AAC,MAAM,CAAC,WAAW,EAAE,SAAS,CA4CpC,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,WAAW,UACd,aAAa,WAAW,cAAc,cAEpC,gBAAgB,SACjB,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,KAClC,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAmBpC,CAAC"}
@@ -0,0 +1,93 @@
1
+ import { Effect, FiberHandle, Queue, Stream } from 'effect';
2
+ import { ToolFault } from '@yourtechbudstudio/fluidcast-harness';
3
+ import { initialTurnState, step } from './turn.js';
4
+ /** The query options of one worker. */
5
+ export const queryOptions = (options, worker) => ({
6
+ cwd: worker.cwd,
7
+ pathToClaudeCodeExecutable: options.executable,
8
+ ...(worker.resume === undefined ? {} : { resume: worker.resume }),
9
+ ...(options.model === undefined ? {} : { model: options.model }),
10
+ ...(options.effort === undefined ? {} : { effort: options.effort }),
11
+ ...(options.settings === undefined ? {} : { settings: options.settings }),
12
+ permissionMode: options.permissionMode ?? 'auto',
13
+ settingSources: ['user', 'project', 'local'],
14
+ disallowedTools: ['AskUserQuestion'],
15
+ forwardSubagentText: true,
16
+ agentProgressSummaries: true,
17
+ env: {
18
+ ...options.environment,
19
+ // Session state events carry the authoritative `idle`; startup failure results name known
20
+ // startup failures instead of ending with stderr alone.
21
+ CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS: '1',
22
+ CLAUDE_CODE_STARTUP_FAILURE_RESULTS: '1',
23
+ },
24
+ });
25
+ /** An ordinary user message with default priority: it folds into a running turn. */
26
+ const userMessage = ({ id, text }) => ({
27
+ type: 'user',
28
+ message: { role: 'user', content: text },
29
+ parent_tool_use_id: null,
30
+ // The pool's message IDs are UUIDs.
31
+ uuid: id,
32
+ });
33
+ /**
34
+ * The frames without the iterator's `return`. Effect awaits `return()` when the stream closes, and
35
+ * an async generator's `return()` waits behind a pending `next()`, so an idle worker would hang
36
+ * teardown. `close()` in the query's release is the teardown instead.
37
+ */
38
+ const readOnly = (iterable) => ({
39
+ [Symbol.asyncIterator]: () => {
40
+ const iterator = iterable[Symbol.asyncIterator]();
41
+ return { next: () => iterator.next() };
42
+ },
43
+ });
44
+ const graceDelay = '1 second';
45
+ /**
46
+ * Frames through the turn tracker, one input at a time: one processing fiber over one queue of
47
+ * frames and elapsed grace timers, the timer in a `FiberHandle`. A failure of `frames` (the
48
+ * process ended or crashed) fails the stream after every earlier frame is processed; a fault a
49
+ * frame reports fails it at once.
50
+ */
51
+ export const runTracker = (frames, initial) => Stream.callback((events) => Effect.gen(function* () {
52
+ const inputs = yield* Queue.unbounded();
53
+ const timer = yield* FiberHandle.make();
54
+ yield* frames.pipe(Stream.runForEach((frame) => Queue.offer(inputs, { _tag: 'Frame', frame })), Effect.catch((fault) => Queue.offer(inputs, { _tag: 'Ended', fault })), Effect.forkScoped);
55
+ const loop = (state) => Effect.gen(function* () {
56
+ const input = yield* Queue.take(inputs);
57
+ if (input._tag === 'Ended')
58
+ return yield* Queue.fail(events, input.fault);
59
+ const [next, outputs] = step(state, input);
60
+ for (const output of outputs) {
61
+ switch (output._tag) {
62
+ case 'StartGrace':
63
+ yield* FiberHandle.run(timer, Effect.sleep(graceDelay).pipe(Effect.andThen(Queue.offer(inputs, { _tag: 'GraceElapsed', grace: output.grace })), Effect.asVoid));
64
+ break;
65
+ case 'CancelGrace':
66
+ yield* FiberHandle.clear(timer);
67
+ break;
68
+ case 'Fault':
69
+ return yield* Queue.fail(events, output.fault);
70
+ default:
71
+ yield* Queue.offer(events, output);
72
+ }
73
+ }
74
+ return yield* loop(next);
75
+ });
76
+ yield* loop(initial);
77
+ }));
78
+ /**
79
+ * One worker process for as long as the stream is consumed. Its input is `input` as ordinary user
80
+ * messages; the scope's release closes the query. The end of the frames is a crash
81
+ * (`ClaudeExited`); interruption is teardown and records nothing. `interrupt()` and
82
+ * `backgroundTasks()` are never used.
83
+ */
84
+ export const connectWith = (query, options) => (worker, input) => Stream.unwrap(Effect.gen(function* () {
85
+ const prompt = Stream.toAsyncIterable(input.pipe(Stream.map(userMessage)));
86
+ const frames = yield* Effect.acquireRelease(Effect.try({
87
+ try: () => query({ prompt, options: queryOptions(options, worker) }),
88
+ catch: () => new ToolFault({ reason: 'ClaudeStartup' }),
89
+ }), (opened) => Effect.sync(() => opened.close()));
90
+ const exited = () => new ToolFault({ reason: 'ClaudeExited' });
91
+ return runTracker(Stream.fromAsyncIterable(readOnly(frames), exited).pipe(Stream.concat(Stream.fail(exited()))), initialTurnState(worker.resume === undefined));
92
+ }));
93
+ //# sourceMappingURL=connect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect.js","sourceRoot":"","sources":["../../src/claude/connect.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE5D,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAGjE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAqC,MAAM,WAAW,CAAC;AA6BtF,uCAAuC;AACvC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAuB,EAAE,MAAwB,EAAW,EAAE,CAAC,CAAC;IAC3F,GAAG,EAAE,MAAM,CAAC,GAAG;IACf,0BAA0B,EAAE,OAAO,CAAC,UAAU;IAC9C,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;IACjE,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;IAChE,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;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,EAAE,CAAC;QACpE,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;KACxD,CAAC,EACF,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAC9C,CAAC;IACF,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC;IAC/D,OAAO,UAAU,CACf,MAAM,CAAC,iBAAiB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,IAAI,CACrD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CACrC,EACD,gBAAgB,CAAC,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAC9C,CAAC;AACJ,CAAC,CAAC,CACH,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Failure classification for Claude Code frames: which frames are faults (the conversation halts)
3
+ * and what outcome a turn's result records.
4
+ *
5
+ * Usage limits: how Claude Code behaves when a subscription usage limit is hit is to be
6
+ * established by AC10. Either the SDK waits for the reset and resumes the turn by itself, in which
7
+ * case nothing special happens (the busy period stays open and the worker shows `working`), or it
8
+ * ends the turn with an error result after a rejected `rate_limit_event`, in which case the turn
9
+ * ends as `usage_limit` with the reset time when the event carried one, and the Forward tool's error
10
+ * names that time.
11
+ */
12
+ import type { SDKMessage, SDKResultMessage } from '@anthropic-ai/claude-agent-sdk';
13
+ import { ToolFault } from '@yourtechbudstudio/fluidcast-harness';
14
+ /**
15
+ * The fault a frame reports, if any. A known startup failure (`startup_failure_reason`, written on
16
+ * an `error_during_execution` result) is a fault, never a turn error; so is an account or
17
+ * credential error. Every other assistant error (`rate_limit`, `overloaded`, …) is left to the
18
+ * turn's result.
19
+ */
20
+ export declare const faultOf: (frame: SDKMessage) => ToolFault | undefined;
21
+ /** A rejected rate-limit event seen in the current turn, with its reset time when known. */
22
+ export interface RateLimit {
23
+ readonly resetsAt: number | undefined;
24
+ }
25
+ /** How a turn ended, as its `turnEnd` entry records it. */
26
+ export interface TurnOutcome {
27
+ readonly outcome: string;
28
+ readonly resetsAt?: number;
29
+ }
30
+ /**
31
+ * `success`; `usage_limit` for a failed turn that saw a rejected rate-limit event; `api_error` for
32
+ * a `success` result flagged `is_error`; else the error subtype.
33
+ */
34
+ export declare const turnOutcome: (result: SDKResultMessage, rateLimit: RateLimit | undefined) => TurnOutcome;
35
+ //# sourceMappingURL=failure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure.d.ts","sourceRoot":"","sources":["../../src/claude/failure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAEnF,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAYjE;;;;;GAKG;AACH,eAAO,MAAM,OAAO,UAAW,UAAU,KAAG,SAAS,GAAG,SAUvD,CAAC;AAEF,4FAA4F;AAC5F,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC;AAED,2DAA2D;AAC3D,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,WACd,gBAAgB,aACb,SAAS,GAAG,SAAS,KAC/B,WAQF,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { ToolFault } from '@yourtechbudstudio/fluidcast-harness';
2
+ /** Assistant errors that no retry fixes: the account or its credentials need attention. */
3
+ const authErrors = new Set([
4
+ 'authentication_failed',
5
+ 'oauth_org_not_allowed',
6
+ 'account_on_hold',
7
+ 'verification_required',
8
+ 'billing_error',
9
+ 'cloud_credential_error',
10
+ ]);
11
+ /**
12
+ * The fault a frame reports, if any. A known startup failure (`startup_failure_reason`, written on
13
+ * an `error_during_execution` result) is a fault, never a turn error; so is an account or
14
+ * credential error. Every other assistant error (`rate_limit`, `overloaded`, …) is left to the
15
+ * turn's result.
16
+ */
17
+ export const faultOf = (frame) => {
18
+ if (frame.type === 'result' && frame.subtype !== 'success') {
19
+ return frame.startup_failure_reason === undefined
20
+ ? undefined
21
+ : new ToolFault({ reason: 'ClaudeStartup' });
22
+ }
23
+ if (frame.type === 'assistant' && frame.error !== undefined && authErrors.has(frame.error)) {
24
+ return new ToolFault({ reason: 'ClaudeAuth' });
25
+ }
26
+ return undefined;
27
+ };
28
+ /**
29
+ * `success`; `usage_limit` for a failed turn that saw a rejected rate-limit event; `api_error` for
30
+ * a `success` result flagged `is_error`; else the error subtype.
31
+ */
32
+ export const turnOutcome = (result, rateLimit) => {
33
+ if (result.subtype === 'success' && !result.is_error)
34
+ return { outcome: 'success' };
35
+ if (rateLimit !== undefined) {
36
+ return rateLimit.resetsAt === undefined
37
+ ? { outcome: 'usage_limit' }
38
+ : { outcome: 'usage_limit', resetsAt: rateLimit.resetsAt };
39
+ }
40
+ return { outcome: result.subtype === 'success' ? 'api_error' : result.subtype };
41
+ };
42
+ //# sourceMappingURL=failure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure.js","sourceRoot":"","sources":["../../src/claude/failure.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAEjE,2FAA2F;AAC3F,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAC;IAC9C,uBAAuB;IACvB,uBAAuB;IACvB,iBAAiB;IACjB,uBAAuB;IACvB,eAAe;IACf,wBAAwB;CACzB,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAiB,EAAyB,EAA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
5
+ import { type EffortLevel, type PermissionMode } from '@anthropic-ai/claude-agent-sdk';
6
+ import type { WorkerType } from '../worker.ts';
7
+ export interface ClaudeWorkerOptions {
8
+ /** Where a new worker runs. A preloaded worker runs in its session's recorded directory. */
9
+ readonly cwd: string;
10
+ /**
11
+ * The installed `claude` executable, as an absolute path (the SDK checks it exists). Required: the
12
+ * worker never runs the SDK's bundled Claude Code.
13
+ */
14
+ readonly executable: string;
15
+ readonly model?: string;
16
+ readonly effort?: EffortLevel;
17
+ /** Default `'auto'`. */
18
+ readonly permissionMode?: PermissionMode;
19
+ /** The worker process environment. Default `process.env`. The SDK replaces, never merges. */
20
+ readonly environment?: Readonly<Record<string, string | undefined>>;
21
+ /**
22
+ * A settings file passed to this worker's query only, for per-invocation host instrumentation
23
+ * (e.g. hooks that report the session to the host) without touching user or project settings.
24
+ * Default: none.
25
+ */
26
+ readonly settings?: string;
27
+ }
28
+ /** The Claude Code worker: one long-lived streaming-input query. */
29
+ export declare const claudeWorker: (options: ClaudeWorkerOptions) => WorkerType;
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/claude/index.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,OAAO,EAML,KAAK,WAAW,EAChB,KAAK,cAAc,EACpB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI/C,MAAM,WAAW,mBAAmB;IAClC,4FAA4F;IAC5F,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,wBAAwB;IACxB,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IACzC,6FAA6F;IAC7F,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IACpE;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAoBD,oEAAoE;AACpE,eAAO,MAAM,YAAY,YAAa,mBAAmB,KAAG,UAe1D,CAAC"}
@@ -0,0 +1,41 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * The Claude Code worker type, over `@anthropic-ai/claude-agent-sdk` (an optional peer: only
4
+ * applications that import this entry load it).
5
+ */
6
+ import { getSessionInfo, getSessionMessages, getSubagentMessages, listSubagents, query, } from '@anthropic-ai/claude-agent-sdk';
7
+ import { attachWith } from './attach.js';
8
+ import { connectWith } from './connect.js';
9
+ /** One skill or command per message, for now: chaining several is not supported. */
10
+ const maxModifiers = 1;
11
+ const modifierName = /^[a-z0-9][a-z0-9:_-]*$/;
12
+ /**
13
+ * Claude Code recognises a command or skill only at the start of a message, as `/name <prompt>`:
14
+ * the modifier receives the whole prompt as its arguments.
15
+ */
16
+ const composeMessage = (prompt, modifiers) => {
17
+ const [modifier] = modifiers;
18
+ if (modifier === undefined)
19
+ return prompt;
20
+ if (modifiers.length > maxModifiers) {
21
+ throw new Error(`Claude Code takes at most ${maxModifiers} modifier, got ${modifiers.length}`);
22
+ }
23
+ if (!modifierName.test(modifier.name))
24
+ throw new Error('Invalid Claude Code modifier name');
25
+ return `/${modifier.name} ${prompt}`;
26
+ };
27
+ /** The Claude Code worker: one long-lived streaming-input query. */
28
+ export const claudeWorker = (options) => ({
29
+ cwd: options.cwd,
30
+ composeMessage,
31
+ attach: attachWith({ getSessionInfo, getSessionMessages, listSubagents, getSubagentMessages }, options.cwd),
32
+ connect: connectWith(query, {
33
+ executable: options.executable,
34
+ model: options.model,
35
+ effort: options.effort,
36
+ permissionMode: options.permissionMode,
37
+ environment: options.environment ?? process.env,
38
+ settings: options.settings,
39
+ }),
40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,EAAE,WAAW,CAAC,KAAK,EAAE;QAC1B,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG;QAC/C,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC;CACH,CAAC,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Claude Code frames and stored history as `TranscriptEntry`s. Pure.
3
+ *
4
+ * Live frames and stored messages share one block normaliser. Message content is read through
5
+ * small guards because stored messages are untyped (`SessionMessage.message` is `unknown`).
6
+ */
7
+ import type { SDKMessage, SessionMessage } from '@anthropic-ai/claude-agent-sdk';
8
+ import type { TranscriptEntry } from '../schema.ts';
9
+ import { type RateLimit } from './failure.ts';
10
+ /**
11
+ * The entries of one live frame. A top-level result becomes its turn's `turnEnd`; `rateLimit` is
12
+ * the rejected rate-limit event seen in that turn, if any. Replayed user messages are left out.
13
+ */
14
+ export declare const frameEntries: (frame: SDKMessage, rateLimit: RateLimit | undefined) => ReadonlyArray<TranscriptEntry>;
15
+ /**
16
+ * A stored session as entries: the main chain, with each earlier subagent inserted right after the
17
+ * tool call that started it (before that call's result) and its entries nested under that call.
18
+ * No `turnEnd` is invented: stored sessions record no turn results.
19
+ *
20
+ * A subagent's starting call is found by the first rule that matches:
21
+ * 1. the `parent_tool_use_id` its messages report, when that call is in the history (in the main
22
+ * chain or another subagent, so subagents started by subagents nest under their parent's call);
23
+ * 2. the earliest `Agent` (or older `Task`) call whose result has a line starting with exactly
24
+ * `agentId: <id>` followed by whitespace or the end of the line. Other tools mention agent IDs
25
+ * too (`SendMessage` results carry them in JSON), so nothing looser is accepted.
26
+ * 3. Otherwise, including a subagent whose calls lead back to itself, it is shown unlinked: a
27
+ * top-level `status` line naming it, then its entries at the top level, after the main chain.
28
+ */
29
+ export declare const historyEntries: (mainMessages: ReadonlyArray<SessionMessage>, subagents: ReadonlyArray<{
30
+ readonly agentId: string;
31
+ readonly messages: ReadonlyArray<SessionMessage>;
32
+ }>) => ReadonlyArray<TranscriptEntry>;
33
+ //# sourceMappingURL=transcript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../../src/claude/transcript.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AA2F3D;;;GAGG;AACH,eAAO,MAAM,YAAY,UAChB,UAAU,aACN,SAAS,GAAG,SAAS,KAC/B,aAAa,CAAC,eAAe,CAiB/B,CAAC;AA8CF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,iBACX,aAAa,CAAC,cAAc,CAAC,aAChC,aAAa,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;CAClD,CAAC,KACD,aAAa,CAAC,eAAe,CAgF/B,CAAC"}