@kingsoftcloud/agentkit-harness-ui 0.0.0-stage → 0.0.2

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 (56) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +116 -0
  3. package/README.md +292 -2
  4. package/markdown/build/build-markdown.cjs +66 -0
  5. package/markdown/dist/THIRD_PARTY_LICENSES.txt +2993 -0
  6. package/markdown/dist/markdown.css +1 -0
  7. package/markdown/dist/markdown.mjs +325 -0
  8. package/markdown/source/markdown-factory.mjs +613 -0
  9. package/markdown/source/markdown.css +288 -0
  10. package/markdown/source/table-factory.mjs +1588 -0
  11. package/markdown/source/table.css +487 -0
  12. package/package.json +96 -4
  13. package/src/activity-groups.mjs +74 -0
  14. package/src/browser-response-groups.mjs +57 -0
  15. package/src/command-output.mjs +57 -0
  16. package/src/components.mjs +9 -0
  17. package/src/context-markers.mjs +19 -0
  18. package/src/context-status.mjs +34 -0
  19. package/src/diff.mjs +240 -0
  20. package/src/explore-tool-call.mjs +139 -0
  21. package/src/file-preview.mjs +50 -0
  22. package/src/host/native-a2a.mjs +90 -0
  23. package/src/host/native-child-file-pane.mjs +49 -0
  24. package/src/host/native-child-pane.mjs +94 -0
  25. package/src/host/native-command-pane.mjs +64 -0
  26. package/src/host/native-run-panel.mjs +202 -0
  27. package/src/host/session-task-events.mjs +247 -0
  28. package/src/host/state/native-a2a.mjs +122 -0
  29. package/src/host/state/native-child-observation.mjs +35 -0
  30. package/src/host/state/native-children.mjs +93 -0
  31. package/src/host/state/native-outcome.mjs +35 -0
  32. package/src/host/state/native-recovery.mjs +187 -0
  33. package/src/host/state/native-runtime-route.mjs +26 -0
  34. package/src/host/state/native-session-stop.mjs +40 -0
  35. package/src/host/state/native-status-panel.mjs +23 -0
  36. package/src/host/state/native-task-read-model.mjs +89 -0
  37. package/src/host/state/task-links.mjs +40 -0
  38. package/src/host/task-timeline.mjs +185 -0
  39. package/src/index.mjs +52 -0
  40. package/src/input-preview.mjs +44 -0
  41. package/src/inspector.mjs +40 -0
  42. package/src/project.mjs +132 -0
  43. package/src/protocol.mjs +362 -0
  44. package/src/react-binding.mjs +486 -0
  45. package/src/reducer.mjs +355 -0
  46. package/src/renderers.mjs +644 -0
  47. package/src/status-panel.mjs +1156 -0
  48. package/src/styles.mjs +278 -0
  49. package/src/summary-playback.mjs +39 -0
  50. package/src/summary.mjs +160 -0
  51. package/src/terminal.mjs +157 -0
  52. package/src/tool-detail.mjs +208 -0
  53. package/src/tool-error.mjs +33 -0
  54. package/src/tool-identity.mjs +40 -0
  55. package/src/view.mjs +364 -0
  56. package/src/work-segments.mjs +41 -0
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.
package/NOTICE ADDED
@@ -0,0 +1,116 @@
1
+ @kingsoftcloud/agentkit-harness-ui — THIRD-PARTY NOTICES
2
+
3
+ Browser response grouping follows the response classification and stable CUA
4
+ stage semantics in ZCode packages/ui/src/v4/conversationCuaGroups.ts
5
+ (reference commit 3c5b227649371507ddc4eb46ac5133afe6db1cab, Apache-2.0).
6
+ It is reimplemented as a read-only ESM projection over Host response identities;
7
+ the Apache-2.0 license text is included as LICENSE.
8
+
9
+ This package is Apache-2.0 licensed (see LICENSE).
10
+
11
+ Portions of the presentation semantics in the thought (reasoning) block —
12
+ collapsed-by-default streaming with a latest-line summary, auto-collapse on
13
+ stream end unless the user interacted, content scroll-follow with a bottom
14
+ lock, and a host-supplied real duration label — are derived from the
15
+ vercel/ai-elements `reasoning.tsx` component:
16
+
17
+ Original: packages/elements/src/reasoning.tsx
18
+ Copyright 2023 Vercel, Inc.
19
+ Licensed under the Apache License, Version 2.0
20
+ https://github.com/vercel/ai-elements
21
+
22
+ The derived behavior was reimplemented from scratch in plain ESM with no
23
+ source copied; the original Apache-2.0 notice is retained here per the
24
+ license's redistribution terms. No "inspired by" product branding is asserted.
25
+
26
+ The execute/read/edit renderer contracts and the unified-diff line-number
27
+ parsing are adapted from the ZCode DESKTOP task conversation presentation
28
+ (also Apache-2.0 within this reference set): execute `$` prompt + bounded
29
+ command and safe-ANSI stdout/stderr/exit/cwd, read file chip, edit file chips
30
+ with +N/-N count and inline diff carrying real @@ line numbers. These were
31
+ reimplemented as pure, function-free view-model fragments; the Markdown table adaptation described below includes derived source.
32
+
33
+
34
+ The reasoning summary playback queue is adapted from
35
+ packages/ui/src/ToolCallBlocks/QueuedSummaryContent.tsx and the latest-line
36
+ selection in packages/ui/src/components/ai-elements/reasoning.tsx of ZCode,
37
+ revision 3c5b227649371507ddc4eb46ac5133afe6db1cab, under Apache-2.0.
38
+ This distribution changes the implementation to a host-independent ESM
39
+ scheduler and CSS transitions; it retains no dependency on that application.
40
+
41
+ Inline tool and reasoning icons contain Lucide SVG paths from lucide-static 0.544.0.
42
+
43
+ ISC License
44
+
45
+ Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2023 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2025.
46
+
47
+ Permission to use, copy, modify, and/or distribute this software for any
48
+ purpose with or without fee is hereby granted, provided that the above
49
+ copyright notice and this permission notice appear in all copies.
50
+
51
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
52
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
53
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
54
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
55
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
56
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
57
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
58
+
59
+ ---
60
+
61
+ The MIT License (MIT) (for portions derived from Feather)
62
+
63
+ Copyright (c) 2013-2023 Cole Bemis
64
+
65
+ Permission is hereby granted, free of charge, to any person obtaining a copy
66
+ of this software and associated documentation files (the "Software"), to deal
67
+ in the Software without restriction, including without limitation the rights
68
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
69
+ copies of the Software, and to permit persons to whom the Software is
70
+ furnished to do so, subject to the following conditions:
71
+
72
+ The above copyright notice and this permission notice shall be included in all
73
+ copies or substantial portions of the Software.
74
+
75
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
76
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
77
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
78
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
79
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
80
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
81
+ SOFTWARE.
82
+
83
+
84
+ Bundled Markdown rendering dependencies and their license texts are listed in
85
+ markdown/dist/THIRD_PARTY_LICENSES.txt. Original inline license notices are
86
+ also retained in the generated Markdown factory.
87
+
88
+ Markdown table layout, toolbar, overflow scrolling, sticky scrollbar and fullscreen
89
+ preview are adapted from packages/ui/src/components/ai-elements/markdown-table.tsx
90
+ of ZCode, revision 3c5b227649371507ddc4eb46ac5133afe6db1cab, Apache-2.0.
91
+ The host supplies React and portals; scoped CSS replaces utility classes, and local
92
+ status announcements replace application toasts. Dialog focus and scroll lifecycle
93
+ are implemented within this independent package.
94
+
95
+ Subagent parent-row interaction and deterministic role colors are adapted from
96
+ packages/ui/src/ToolCallBlocks/renderers/agent.tsx, lib/subagentColors.ts,
97
+ v4/ConversationAgentToolCallRow.tsx and app-shell/SubagentSessionSidePane.tsx
98
+ of the same revision and license. The read-only child timeline is composed with
99
+ the independent renderer; docking is supplied by the host.
100
+
101
+ Conversation status panel shell, mini/panel/auto modes, Todo focus window,
102
+ background-work and child-session sections are adapted from
103
+ packages/ui/src/v4/ConversationStatusPanel.tsx, conversationStatusPanelModel.ts
104
+ and conversationLayout.ts of ZCode, revision
105
+ 3c5b227649371507ddc4eb46ac5133afe6db1cab, Apache-2.0.
106
+ The host supplies committed activity facts, Git observations and navigation
107
+ actions; this independent component carries no execution authority.
108
+
109
+ src/explore-tool-call.mjs adapts packages/ui/src/lib/exploreToolCall.ts from
110
+ ZCode revision 3c5b227649371507ddc4eb46ac5133afe6db1cab, Apache-2.0. The copied
111
+ presentation classifier retains its command extraction and Explore/Execute
112
+ rules, with TypeScript erased and application identity imports replaced by
113
+ the independent tool identity registry. It never decides execution permissions.
114
+ The stage grouping defaults and Explore count buckets in activity-groups.mjs
115
+ follow that revision's v4/conversationAssistantWorkItems.ts and
116
+ ToolCallBlocks/renderers/explore.tsx.
package/README.md CHANGED
@@ -1,3 +1,293 @@
1
- # Temporary Holding Version
1
+ # @kingsoftcloud/agentkit-harness-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A reusable, framework-lightweight **task-process UI** for AgentKit Native. It
4
+ takes a stream of versioned events from a host (the Native runtime, a Studio
5
+ adapter, or a test harness) and renders an accessible React timeline of
6
+ streaming assistant text, provider-supplied thinking, and live tool calls —
7
+ with ordered items, replay-safe deduplication, bounded summaries, and redacted
8
+ errors.
9
+
10
+ The package is intentionally free of Studio / DSH / Python imports. React is a
11
+ **peer dependency** (`>=18`). Source is plain ESM (`.mjs`, no JSX) and is
12
+ exposed directly, with no transpiler required at runtime. The optional Markdown
13
+ renderer is bundled by `npm run build` before packing the package. The
14
+ pure logic modules (protocol, reducer, projection, summaries, tool details,
15
+ view model) do **not** import React and run in plain Node `>=22`; only the
16
+ React binding (`./components`) and the barrel (`.`) require React.
17
+
18
+ `./file-preview` exports `createFilePreviewComponents(React)`. Its read-only
19
+ `FilePreviewPane` displays one bounded UTF-8 page of an isolated child file.
20
+ The host supplies authenticated observations, byte cursors and navigation/copy
21
+ callbacks; the component never resolves execution roots or performs I/O. These
22
+ are current workspace observations, separate from immutable tool receipts and
23
+ task acceptance. Failed or canceled reads must not fall back to a parent file.
24
+
25
+ ## Design
26
+
27
+ ```
28
+ host events ──▶ normalizeEvent ──▶ reduce ──▶ state ──▶ buildViewModel ──▶ React
29
+ (protocol v1) (protocol.mjs) (reducer.mjs) (view.mjs) (components.mjs)
30
+ │
31
+ └─▶ renderers.mjs (execute/read/edit/default)
32
+ diff.mjs · terminal.mjs
33
+ ```
34
+
35
+ - **`protocol.mjs`** — the explicitly versioned, stable event contract
36
+ (`PROTOCOL_VERSION = 1`). `normalizeEvent` validates and coerces each event,
37
+ including the optional `display` presentation payload (`DisplayKind`:
38
+ `command_output`, `command_preview`, `file_diff`, `file_read`, `file_edit`,
39
+ `generic`).
40
+ - **`reducer.mjs`** — a pure `(state, event) => state` machine. Handles
41
+ streaming text, provider thinking (with optional host-supplied real
42
+ `duration`), single keyed tool calls (scheduled/started/progress/result/error),
43
+ task-state interruption/failure/recovery, ordered items, and idempotent
44
+ replay by event id. It never invents reasoning or success.
45
+
46
+ A closed interrupted execution uses `task.finished` with
47
+ `outcome: "unverified"` and `executionState: "interrupted"`. This separates
48
+ stopping the driver from proving its effects. The host can supply a factual
49
+ summary; the renderer never changes an unknown operation into success or
50
+ failure. A resumable `task.state` interruption without a finished outcome
51
+ remains distinct. Existing v1 events without this optional field are unchanged.
52
+ - **`project.mjs`** — read-only selectors (ordered items, streaming/waiting
53
+ flags, plan progress, active tool, errors, status label).
54
+ - **`summary.mjs`** — bounded text helpers: latest-line preview, truncation,
55
+ sensitive-key redaction, a deterministic summary-line queue.
56
+ - **`tool-detail.mjs`** — per-tool audit titles and bounded, redacted detail
57
+ blocks; a bounded `file_diff` preview; error redaction.
58
+ - **`diff.mjs`** — pure unified-diff parsing: real line numbers from
59
+ `@@ -oldStart,oldCount +newStart,newCount @@` headers (never synthesized),
60
+ addition/deletion counts, operation-kind inference, bounded unified AND
61
+ split representations. No file is read; no write is inferred from input.
62
+ - **`terminal.mjs`** — pure command/output extraction and safe ANSI
63
+ sanitization for the execute renderer. Output is plain text (never
64
+ innerHTML), so escape sequences cannot inject markup. Exit/cwd are shown
65
+ only when the host supplied them.
66
+ - **`renderers.mjs`** — the tool-call renderer registry. Dispatches by tool
67
+ name to `execute` (terminal: `$` prompt + bounded command, live
68
+ stdout/stderr/exit/cwd, copy + open-terminal), `read` (file chip, opens via
69
+ host callback, non-toggleable), `edit` (file chips, +N/-N count, inline diff
70
+ with real line numbers, unified + split responsive, bounded preview with a
71
+ full-retrieval callback), and `default` (bounded redacted detail for
72
+ unknown/MCP tools). All host actions are `data-action` attributes; the tree
73
+ stays function-free.
74
+ - **`view.mjs`** — builds a serializable element tree with stable
75
+ `data-testid` selectors and accessibility attributes. Dispatches tool
76
+ rendering through the registry. Carries the "no invented content"
77
+ invariants (see below). Testable without a DOM.
78
+ - **`components.mjs`** — thin React binding; maps the tree to
79
+ `React.createElement` and owns presentation-only state (expanded
80
+ thoughts/tools, follow). Event handlers are delegated from the root.
81
+ - **`styles.mjs`** — an optional CSS string (light/dark, reduced-motion aware).
82
+
83
+ ## Minimal usage
84
+
85
+ The host owns the event stream and the reducer state (e.g. in `useReducer` or
86
+ an external store); the component is a pure projection of that state.
87
+
88
+ ```jsx
89
+ import { useReducer } from "react";
90
+ import { HarnessTimeline } from "@kingsoftcloud/agentkit-harness-ui";
91
+ import { initialState, reduce } from "@kingsoftcloud/agentkit-harness-ui/reducer";
92
+
93
+ function App({ eventStream }) {
94
+ const [state, dispatch] = useReducer(reduce, undefined, initialState);
95
+ // forward your runtime events to the reducer as they arrive
96
+ useEffect(() => eventStream.on("event", e => dispatch(e)), [eventStream]);
97
+
98
+ return <HarnessTimeline state={state} autoFollow workspaceRoot={process.cwd()} />;
99
+ }
100
+ ```
101
+
102
+ Hosts that do not use React can import the pure subpaths directly and render
103
+ `buildViewModel(state)` with any renderer (the tree is React-element-shaped):
104
+ `@kingsoftcloud/agentkit-harness-ui/view`, `/reducer`, `/protocol`, etc.
105
+
106
+ ## Host event integration
107
+
108
+ Emit one event per lifecycle transition. Every event carries `v: 1`, a stable
109
+ `type`, and a unique `id` (used for idempotent replay — re-applying the same
110
+ event is a no-op). `ts` and `seq` are optional diagnostics.
111
+
112
+ | Event | Payload | Reducer effect |
113
+ |---|---|---|
114
+ | `task.started` | `taskId`, `title?`, `runId?` | enters `running` |
115
+ | `task.state` | `state`, `reason?`, `message?` | validated transition (see below) |
116
+ | `task.finished` | `outcome`, `summary?`, `error?`, `reason?` | terminal; finalizes live streams |
117
+ | `text.delta` | `itemId`, `delta` | append (creates the item on first delta) |
118
+ | `text.done` | `itemId` | stop streaming |
119
+ | `thinking.start` | `itemId` | records pending; **creates no visible item** |
120
+ | `thinking.delta` | `itemId`, `delta` | first non-empty delta creates the thought |
121
+ | `thinking.done` | `itemId`, `duration?` | stop streaming; `duration` (seconds, host-supplied) is shown if present |
122
+ | `tool.scheduled` | `callId`, `name`, `input` | create/update the part (bounded input) |
123
+ | `tool.started` | `callId` | move to `running` |
124
+ | `tool.progress` | `callId`, `progress?`/`message?`, `display?` | running + progress text; a `command_preview` display streams live output before the result |
125
+ | `tool.result` | `callId`, `result?`, `display?` | `completed` + display payload |
126
+ | `tool.error` | `callId`, `error` | `failed` + redacted error |
127
+ | `plan.updated` | `items[]` | replace the task plan |
128
+
129
+ **`display` presentation payloads** (optional, on `tool.result`/`tool.progress`).
130
+ The UI renders a purpose-built block for each known `kind`; unknown kinds fall
131
+ back to the generic bounded object preview.
132
+
133
+ | `kind` | Fields | Renderer |
134
+ |---|---|---|
135
+ | `command_output` | `stdout`, `stderr`, `exit`, `cwd` | execute output with exit badge + cwd |
136
+ | `command_preview` | `fullText` | live streaming output while running |
137
+ | `file_diff` | `path`, `patch`, `changeStat?`, `operationKind?` | edit inline diff (real line numbers) |
138
+ | `file_read` | `path`, `entryType` | read file chip |
139
+ | `file_edit` | `files[]` (`path`, `patch`, `changeStat?`, `operationKind?`) | edit multi-file chips + per-file diff |
140
+ | `generic` / unknown | any | bounded redacted object preview |
141
+
142
+ **Task states:** `idle → running → interrupted → recovered → running`,
143
+ `running → failed → recovered/running`, `running → completed`, and
144
+ `cancelled` from any state. Invalid `task.state` transitions are ignored
145
+ rather than crashing the timeline.
146
+
147
+ **Ordering, deduplication, and replay.** Items keep their first-appearance
148
+ (provider stream) order; a tool part is updated in place for the same `callId`
149
+ across its whole lifecycle — there is one visible row per call, not separate
150
+ pending/running/completed rows. Replaying an event with an already-seen `id`
151
+ is a no-op, so a host can replay a batch safely. A `tool.result`/`tool.error`
152
+ arriving without a prior `tool.scheduled` appends a minimal fallback part so
153
+ transcript rendering is never missing; a later `tool.scheduled` fills it in.
154
+
155
+ ### Mapping a runtime to the protocol
156
+
157
+ The UI consumes only these events. A typical Native runtime adapter maps its
158
+ internal `SessionEvent`s once at the boundary: reasoning deltas →
159
+ `thinking.delta`, tool lifecycle → the `tool.*` family, assistant text →
160
+ `text.delta`/`text.done`, and run lifecycle → the `task.*` family. Do **not**
161
+ import runtime, provider, or session-store internals into the UI; keep the
162
+ event seam stable and versioned.
163
+
164
+ ## No invented thinking or success
165
+
166
+ The UI is deliberately conservative, matching the reference TUI/Studio
167
+ behavior:
168
+
169
+ - A thought block exists **only** after a non-empty `thinking.delta`. A bare
170
+ `thinking.start` produces no transcript item (only the neutral "Thinking…"
171
+ status placeholder, which is a status indicator, not reasoning content).
172
+ - The UI never renders token/character counts for thinking, and never
173
+ attributes aggregate turn usage to an individual segment.
174
+ - A completed task shows **only** a host-supplied `summary`. If the host
175
+ provides none, the UI shows the declared `Completed` state label and no
176
+ success prose.
177
+ - Tool inputs and errors are bounded and redacted; large content blobs are
178
+ never dumped verbatim. Sensitive keys (`token`, `secret`, `password`,
179
+ `api_key`, `authorization`, …) and `env` values are redacted.
180
+
181
+ ## Stable selectors
182
+
183
+ The view model exposes stable `data-testid` hooks for host integration and
184
+ tests: `harness-timeline`, `harness-timeline-list`, `plan-dock`, `plan-count`,
185
+ `plan-current`, `task-waiting`, `status-line`, `task-state`, `task-summary`,
186
+ `task-error`, `text-block`, `thought-block`, `thought-details`, `thought-toggle`,
187
+ `thought-label`, `thought-preview`, `thought-body`, `tool-block` (carries
188
+ `data-renderer` ∈ `execute`|`read`|`edit`|`default`), `tool-details`,
189
+ `tool-toggle`, `tool-title`, `tool-status`, `tool-detail`, `tool-progress`,
190
+ `tool-error`, `tool-result`, `execute-command`, `execute-command-prompt`,
191
+ `execute-command-text`, `execute-output`, `execute-exit`, `execute-cwd`,
192
+ `execute-no-output`, `bash-output-preview-full` (streaming), `bash-result-output`
193
+ (done), `bash-result-stderr`, `read-chip`, `read-file-name`, `read-file-path`,
194
+ `edit-chips`, `edit-chip`, `edit-file-name`, `edit-diff`, `edit-diff-path`,
195
+ `edit-diff-count`, `edit-diff-unified`, `edit-diff-split`, `edit-diff-line`,
196
+ `edit-diff-old-line`, `edit-diff-new-line`, `edit-open-file`,
197
+ `edit-show-full-diff`, `jump-latest`. Roles: `log`
198
+ (timeline), `status` (streaming/progress/waiting), `alert` (errors).
199
+
200
+ ## Accessibility
201
+
202
+ - The timeline is a `role="log"` container; streaming state sets `aria-busy`.
203
+ - Thoughts and tools use native `<details>`/`<summary>` for collapsible
204
+ disclosure (keyboard-operable, no JS needed) with `aria-expanded` mirrored.
205
+ Read chips are non-toggleable (one-line) and use a `<button>` when a host
206
+ `onOpenFile` callback is provided.
207
+ - Streaming labels use `role="status"`; errors use `role="alert"`.
208
+ - The built-in CSS honors `prefers-reduced-motion` (shimmer/caret disabled).
209
+ - Expansion state is presentation-only and never written back to reducer
210
+ state. Desktop thought auto-collapse: a thought that stops streaming
211
+ collapses back to its summary UNLESS the user opened it themselves; a
212
+ user-opened thought stays open across stream end.
213
+
214
+ ## Host callbacks
215
+
216
+ `HarnessTimeline` accepts optional callbacks; the tree carries them as
217
+ `data-action` attributes and a single delegated click handler dispatches to
218
+ them (the view tree stays function-free and serializable):
219
+
220
+ - `onOpenFile({path, kind, callId?})` — open a file or patch (read chip, edit chip, edit-diff "Open").
221
+ - `onCopy(text)` — copy command or output.
222
+ - `onOpenTerminal({callId, cwd?})` — open a live terminal for an execute call.
223
+ - `onRetrieveFullDiff({callId, path})` — fetch the full diff when the bounded preview is truncated.
224
+ - `onJumpLatest()` — jump the timeline to the bottom (falls back to the built-in scroll when omitted).
225
+
226
+ ## Testing
227
+
228
+ Focused tests use `node:test` (no DOM, no React required):
229
+
230
+ ```sh
231
+ cd packages/agentkit-harness-ui
232
+ node --test test/*.test.mjs
233
+ ```
234
+
235
+ The tests cover the protocol graph (incl. display kinds), the reducer
236
+ lifecycle/ordering/dedup/replay, bounded summaries and redaction, per-tool
237
+ detail blocks, the unified-diff line-number parser and ANSI sanitization, the
238
+ renderer registry (execute/read/edit/default), the projection selectors, the
239
+ view-model invariants (stable selectors, accessibility, ordering, the
240
+ no-invented-content rules), and the React binding (delegated callbacks, desktop
241
+ thought auto-collapse, scroll-follow wiring) via a minimal React shim.
242
+
243
+ ## Exposed API
244
+
245
+ ```
246
+ . # barrel (pulls React via the binding)
247
+ ./protocol # PROTOCOL_VERSION, EventType, TaskState, ToolStatus, DisplayKind, normalizeEvent, isDisplayKind, …
248
+ ./reducer # initialState, reduce, reduceAll
249
+ ./project # visibleItems, isStreaming, isWaitingForFirstToken, planProgress, activeTool, …
250
+ ./summary # latestNonEmptyLine, truncateText, redactValue, boundedDetailLines, SummaryQueue
251
+ ./tool-detail # toolTitle, toolDetailLines, workspaceRelative, fileDiffPreview, redactError
252
+ ./diff # parseDiffHunks, countChangeStat, patchFilePath, inferOperationKind, diffPreviewLines
253
+ ./terminal # extractCommand, extractOutput, sanitizeAnsi, normalizeCwd
254
+ ./renderers # renderTool, toolRendererKind
255
+ ./view # buildViewModel, h, isElement, DEFAULT_VIEW_OPTIONS
256
+ ./components # HarnessTimeline (React peer dep)
257
+ ./styles # styles (CSS string)
258
+ ./react-binding # createHarnessComponents (host-injected React)
259
+ ```
260
+
261
+ ## License
262
+
263
+ Apache-2.0. See `LICENSE`. Third-party notices (vercel/ai-elements reasoning
264
+ semantics retained under Apache-2.0) are in `NOTICE`.
265
+
266
+ ## Markdown renderer
267
+
268
+ `createMarkdownComponents(React, ReactDOM)` from `./markdown` uses the same React instances as the host. Render `MarkdownResponse` with a string child and the actual `streaming` flag; inject `markdownStyles` once. Code stays plain while streaming and is highlighted after completion. Unknown languages remain plain text. File/external link callbacks perform host navigation, while image rendering requires a host resolver; this package does not read files or fetch images. Pass a `scopeKey` for the session/workspace to release stale navigation closures when switching contexts. The host must validate the original file href before opening it.
269
+
270
+ Build with `node markdown/build/build-markdown.cjs` after installing the pinned development dependencies. The distributed ESM factory is self contained except for the injected React/ReactDOM. Dependency notices ship with it.
271
+
272
+ ### Context notices
273
+
274
+ Hosts emit `context.marker` with `marker: { id, status, origin, after }`. The
275
+ `after` boundary is `start`, a `tool` call ID, or a `message` source ID. Text and
276
+ reasoning completion events may carry `sourceMessageId` for stable anchoring.
277
+ The reducer updates a marker in place; the view renders a single divider row.
278
+ Only an adopted summary may be marked completed, not a summary model response.
279
+ Unloaded history anchors remain hidden until the corresponding items arrive.
280
+ Token counters and policy diagnostics belong in the host's run details.
281
+ Ordinary `unverified` completion has a neutral finish label; an explicit host
282
+ `verificationRequired: true` enables the verification warning without changing
283
+ the stored outcome.
284
+
285
+ `@kingsoftcloud/agentkit-harness-ui/command-output` exports
286
+ `appendCommandOutput(previous, page, request)` and
287
+ `createCommandOutputComponents(React).CommandOutputPane`. The Host supplies
288
+ authenticated `agentkit.studio-command-output/v1` pages and owns disclosure,
289
+ byte cursors, docking and cancellation. Display redaction never changes raw
290
+ continuation cursors. The view retains the latest 131072 Unicode code points
291
+ per channel and labels omissions; stdout/stderr remain plain sanitized text.
292
+ Process states and known exits come from observations, not synthetic Harness
293
+ events. Unknown evidence is never rendered as successful execution.