@ycodium-ai/plugin-api 0.2.5004 → 0.2.5093

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 (55) hide show
  1. package/README.md +19 -1
  2. package/dist/_private/ycodium-executor-common/catalogModel.d.ts +9 -0
  3. package/dist/_private/ycodium-executor-common/catalogModel.js +39 -0
  4. package/dist/_private/ycodium-executor-common/eventTypes.d.ts +7 -0
  5. package/dist/_private/ycodium-executor-common/eventTypes.js +1 -0
  6. package/dist/_private/ycodium-executor-common/modelSelection.d.ts +7 -0
  7. package/dist/_private/ycodium-executor-common/modelSelection.js +24 -0
  8. package/dist/_private/ycodium-executor-common/nodeStreams.d.ts +44 -0
  9. package/dist/_private/ycodium-executor-common/nodeStreams.js +158 -0
  10. package/dist/_private/ycodium-executor-common/raceAbort.d.ts +8 -0
  11. package/dist/_private/ycodium-executor-common/raceAbort.js +25 -0
  12. package/dist/_private/ycodium-executor-common/reasoningLevelFallback.d.ts +13 -0
  13. package/dist/_private/ycodium-executor-common/reasoningLevelFallback.js +22 -0
  14. package/dist/_private/ycodium-executor-common/stderrTail.d.ts +9 -0
  15. package/dist/_private/ycodium-executor-common/stderrTail.js +29 -0
  16. package/dist/_private/ycodium-executor-common/toolPresentation.d.ts +19 -0
  17. package/dist/_private/ycodium-executor-common/toolPresentation.js +222 -0
  18. package/dist/dataPorts.gen.d.ts +716 -639
  19. package/dist/dataPorts.gen.d.ts.map +1 -1
  20. package/dist/dataPorts.gen.js.map +1 -1
  21. package/dist/executor.d.ts +3 -14
  22. package/dist/executor.d.ts.map +1 -1
  23. package/dist/executor.js +19 -47
  24. package/dist/executor.js.map +1 -1
  25. package/dist/executorEvents.d.ts +2 -1
  26. package/dist/executorEvents.d.ts.map +1 -1
  27. package/dist/executorEvents.js.map +1 -1
  28. package/dist/executorModelOptions.d.ts +0 -5
  29. package/dist/executorModelOptions.d.ts.map +1 -1
  30. package/dist/executorModelOptions.js +2 -16
  31. package/dist/executorModelOptions.js.map +1 -1
  32. package/dist/pluginContextCommands.d.ts +5 -3
  33. package/dist/pluginContextCommands.d.ts.map +1 -1
  34. package/dist/process-stdin.d.ts +1 -1
  35. package/dist/process-stdin.d.ts.map +1 -1
  36. package/dist/process-stdin.js +13 -124
  37. package/dist/process-stdin.js.map +1 -1
  38. package/dist/reasoningLevelFallback.d.ts +18 -0
  39. package/dist/reasoningLevelFallback.d.ts.map +1 -0
  40. package/dist/reasoningLevelFallback.js +9 -0
  41. package/dist/reasoningLevelFallback.js.map +1 -0
  42. package/dist/timeline-process.d.ts +32 -0
  43. package/dist/timeline-process.d.ts.map +1 -0
  44. package/dist/timeline-process.js +2 -0
  45. package/dist/timeline-process.js.map +1 -0
  46. package/dist/timeline-row-error.d.ts +15 -0
  47. package/dist/timeline-row-error.d.ts.map +1 -0
  48. package/dist/timeline-row-error.js +2 -0
  49. package/dist/timeline-row-error.js.map +1 -0
  50. package/dist/ui.d.ts +15 -0
  51. package/dist/ui.d.ts.map +1 -1
  52. package/dist/ui.js.map +1 -1
  53. package/dist/version.d.ts +3 -3
  54. package/dist/version.js +2 -2
  55. package/package.json +4 -3
@@ -0,0 +1,222 @@
1
+ /**
2
+ * 工具活动摘要行的唯一规则:ACP 执行器与 `@ycodium/shared/toolActivity`(服务器、客户端)共用。
3
+ * 本包不发布;`ycodium-acp-executor` 构建时把它内联进 dist,shared 直接引源码。只依赖本模块自己。
4
+ */
5
+ function isRecord(value) {
6
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7
+ }
8
+ function asTrimmedString(value) {
9
+ if (typeof value !== "string")
10
+ return undefined;
11
+ const trimmed = value.trim();
12
+ return trimmed.length > 0 ? trimmed : undefined;
13
+ }
14
+ export function normalizeCommandValue(value) {
15
+ const direct = asTrimmedString(value);
16
+ if (direct) {
17
+ return direct;
18
+ }
19
+ if (!Array.isArray(value)) {
20
+ return undefined;
21
+ }
22
+ const parts = [];
23
+ for (const entry of value) {
24
+ const part = asTrimmedString(entry);
25
+ if (part !== undefined) {
26
+ parts.push(part);
27
+ }
28
+ }
29
+ return parts.length > 0 ? parts.join(" ") : undefined;
30
+ }
31
+ function stripTrailingExitCode(value) {
32
+ const trimmed = value?.trim();
33
+ if (!trimmed) {
34
+ return undefined;
35
+ }
36
+ const match = /^(?<output>[\s\S]*?)(?:\s*<exited with exit code \d+>)\s*$/iu.exec(trimmed);
37
+ const output = match?.groups?.output?.trim() ?? trimmed;
38
+ return output.length > 0 ? output : undefined;
39
+ }
40
+ function extractCommandFromTitle(title) {
41
+ if (!title) {
42
+ return undefined;
43
+ }
44
+ const backtickMatch = /`([^`]+)`/u.exec(title);
45
+ return backtickMatch?.[1]?.trim() || undefined;
46
+ }
47
+ export function extractToolCommand(data, title) {
48
+ const item = isRecord(data?.["item"]) ? data["item"] : undefined;
49
+ const itemInput = item && isRecord(item["input"]) ? item["input"] : undefined;
50
+ const itemResult = item && isRecord(item["result"]) ? item["result"] : undefined;
51
+ const rawInput = isRecord(data?.["rawInput"]) ? data["rawInput"] : undefined;
52
+ // Claude 的原生形态是 `data.input`(`data.item` 是 Codex / ACP 那一路)。不认这条
53
+ // 路径,Bash 的 IN 框就退回去画整份 input 的缩进 JSON,命令反而看不见。
54
+ const dataInput = isRecord(data?.["input"]) ? data["input"] : undefined;
55
+ const candidates = [
56
+ normalizeCommandValue(item?.["command"]),
57
+ normalizeCommandValue(itemInput?.["command"]),
58
+ normalizeCommandValue(itemResult?.["command"]),
59
+ normalizeCommandValue(data?.["command"]),
60
+ normalizeCommandValue(dataInput?.["command"]),
61
+ normalizeCommandValue(rawInput?.["command"]),
62
+ ];
63
+ const direct = candidates.find((candidate) => candidate !== undefined);
64
+ if (direct) {
65
+ return direct;
66
+ }
67
+ const executable = asTrimmedString(rawInput?.["executable"]);
68
+ const args = normalizeCommandValue(rawInput?.["args"]);
69
+ if (executable && args) {
70
+ return `${executable} ${args}`;
71
+ }
72
+ if (executable) {
73
+ return executable;
74
+ }
75
+ return extractCommandFromTitle(title);
76
+ }
77
+ function maybePathLike(value) {
78
+ if (!value) {
79
+ return undefined;
80
+ }
81
+ if (value.includes("/") ||
82
+ value.includes("\\") ||
83
+ value.startsWith(".") ||
84
+ /\.(?:[a-z0-9]{1,12})$/iu.test(value)) {
85
+ return value;
86
+ }
87
+ return undefined;
88
+ }
89
+ function collectPaths(value, paths, seen, depth) {
90
+ if (depth > 4 || paths.length >= 8) {
91
+ return;
92
+ }
93
+ if (Array.isArray(value)) {
94
+ for (const entry of value) {
95
+ collectPaths(entry, paths, seen, depth + 1);
96
+ if (paths.length >= 8) {
97
+ return;
98
+ }
99
+ }
100
+ return;
101
+ }
102
+ if (!isRecord(value)) {
103
+ return;
104
+ }
105
+ for (const key of ["path", "filePath", "relativePath", "filename", "newPath", "oldPath"]) {
106
+ const candidate = maybePathLike(asTrimmedString(value[key]));
107
+ if (!candidate || seen.has(candidate)) {
108
+ continue;
109
+ }
110
+ seen.add(candidate);
111
+ paths.push(candidate);
112
+ if (paths.length >= 8) {
113
+ return;
114
+ }
115
+ }
116
+ for (const nestedKey of ["locations", "item", "input", "result", "rawInput", "data", "changes"]) {
117
+ if (!(nestedKey in value)) {
118
+ continue;
119
+ }
120
+ collectPaths(value[nestedKey], paths, seen, depth + 1);
121
+ if (paths.length >= 8) {
122
+ return;
123
+ }
124
+ }
125
+ }
126
+ function extractPrimaryPath(data) {
127
+ const paths = [];
128
+ collectPaths(data, paths, new Set(), 0);
129
+ return paths[0];
130
+ }
131
+ function normalizeEquivalentValue(value) {
132
+ const trimmed = asTrimmedString(value);
133
+ if (!trimmed) {
134
+ return undefined;
135
+ }
136
+ return trimmed
137
+ .replace(/\s+/gu, " ")
138
+ .replace(/\s+(?:complete|completed|started)\s*$/iu, "")
139
+ .trim();
140
+ }
141
+ function isEquivalent(left, right) {
142
+ const normalizedLeft = normalizeEquivalentValue(left)?.toLowerCase();
143
+ const normalizedRight = normalizeEquivalentValue(right)?.toLowerCase();
144
+ return normalizedLeft !== undefined && normalizedLeft === normalizedRight;
145
+ }
146
+ function classifyToolAction(input) {
147
+ const itemType = input.itemType ?? undefined;
148
+ const kind = asTrimmedString(input.data?.["kind"])?.toLowerCase();
149
+ const title = asTrimmedString(input.title)?.toLowerCase();
150
+ if (itemType === "command_execution" || kind === "execute" || title === "terminal") {
151
+ return "command";
152
+ }
153
+ if (kind === "read" || title === "read file") {
154
+ return "read";
155
+ }
156
+ if (itemType === "file_change" ||
157
+ kind === "edit" ||
158
+ kind === "move" ||
159
+ kind === "delete" ||
160
+ kind === "write") {
161
+ return "file_change";
162
+ }
163
+ if (itemType === "web_search" || kind === "search" || title === "find" || title === "grep") {
164
+ return "search";
165
+ }
166
+ return "other";
167
+ }
168
+ export function deriveToolActivityPresentation(input) {
169
+ const title = asTrimmedString(input.title);
170
+ const detail = stripTrailingExitCode(asTrimmedString(input.detail));
171
+ const fallbackSummary = asTrimmedString(input.fallbackSummary) ?? "Tool";
172
+ const data = isRecord(input.data) ? input.data : undefined;
173
+ const command = extractToolCommand(data, title);
174
+ const primaryPath = extractPrimaryPath(data);
175
+ const action = classifyToolAction({
176
+ itemType: input.itemType,
177
+ title,
178
+ data,
179
+ });
180
+ if (action === "command") {
181
+ return {
182
+ summary: "Ran command",
183
+ ...(command ? { detail: command } : {}),
184
+ };
185
+ }
186
+ if (action === "read") {
187
+ if (primaryPath) {
188
+ return {
189
+ summary: "Read file",
190
+ detail: primaryPath,
191
+ };
192
+ }
193
+ return {
194
+ summary: "Read file",
195
+ };
196
+ }
197
+ if (action === "file_change") {
198
+ return {
199
+ summary: "Changed files",
200
+ ...(primaryPath ? { detail: primaryPath } : {}),
201
+ };
202
+ }
203
+ if (action === "search") {
204
+ const rawInput = isRecord(data?.["rawInput"]) ? data["rawInput"] : undefined;
205
+ const query = asTrimmedString(rawInput?.["query"]) ??
206
+ asTrimmedString(rawInput?.["pattern"]) ??
207
+ asTrimmedString(rawInput?.["searchTerm"]);
208
+ return {
209
+ summary: "Searched files",
210
+ ...(query ? { detail: query } : {}),
211
+ };
212
+ }
213
+ if (detail && !isEquivalent(detail, title) && !isEquivalent(detail, fallbackSummary)) {
214
+ return {
215
+ summary: title ?? fallbackSummary,
216
+ detail,
217
+ };
218
+ }
219
+ return {
220
+ summary: title ?? fallbackSummary,
221
+ };
222
+ }