@ycodium-ai/agent-opencode 0.2.2984 → 0.2.2990

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 (2) hide show
  1. package/dist/index.js +213 -211
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -8148,111 +8148,6 @@ async function emitProducedFile(events, context, file) {
8148
8148
  }
8149
8149
  }
8150
8150
 
8151
- // src/textMerge.ts
8152
- function commonPrefixLength(left, right) {
8153
- let index = 0;
8154
- while (index < left.length && index < right.length && left[index] === right[index]) {
8155
- index += 1;
8156
- }
8157
- return index;
8158
- }
8159
- function resolveLatestAssistantText(previousText, nextText) {
8160
- if (previousText && previousText.length > nextText.length && previousText.startsWith(nextText)) {
8161
- return previousText;
8162
- }
8163
- return nextText;
8164
- }
8165
- function mergeOpenCodeAssistantText(previousText, nextText) {
8166
- const latestText = resolveLatestAssistantText(previousText, nextText);
8167
- return {
8168
- latestText,
8169
- deltaToEmit: latestText.slice(commonPrefixLength(previousText ?? "", latestText))
8170
- };
8171
- }
8172
- function appendOpenCodeAssistantTextDelta(previousText, delta) {
8173
- return {
8174
- nextText: previousText + delta,
8175
- deltaToEmit: delta
8176
- };
8177
- }
8178
-
8179
- // src/toolClassify.ts
8180
- function toToolLifecycleItemType(toolName) {
8181
- const normalized = toolName.toLowerCase();
8182
- if (normalized === "todowrite" || normalized === "todoread") {
8183
- return "dynamic_tool_call";
8184
- }
8185
- if (normalized.includes("bash") || normalized.includes("command")) {
8186
- return "command_execution";
8187
- }
8188
- if (normalized.includes("edit") || normalized.includes("write") || normalized.includes("patch") || normalized.includes("multiedit")) {
8189
- return "file_change";
8190
- }
8191
- if (normalized.includes("web")) {
8192
- return "web_search";
8193
- }
8194
- if (normalized.includes("mcp")) {
8195
- return "mcp_tool_call";
8196
- }
8197
- if (normalized.includes("image")) {
8198
- return "image_view";
8199
- }
8200
- if (normalized.includes("task") || normalized.includes("agent") || normalized.includes("subtask")) {
8201
- return "collab_agent_tool_call";
8202
- }
8203
- return "dynamic_tool_call";
8204
- }
8205
- function openCodeToolStateFields(state) {
8206
- const input = Object.keys(state.input).length > 0 ? { input: state.input } : {};
8207
- switch (state.status) {
8208
- case "pending":
8209
- return {
8210
- ...input,
8211
- ...state.raw.length > 0 ? { argumentText: state.raw } : {}
8212
- };
8213
- case "running":
8214
- return input;
8215
- case "completed":
8216
- return { ...input, output: state.output };
8217
- case "error":
8218
- return { ...input, output: state.error };
8219
- default: {
8220
- const unexpected = state;
8221
- return unexpected;
8222
- }
8223
- }
8224
- }
8225
- function openCodeToolActivityData(part) {
8226
- return {
8227
- tool: part.tool,
8228
- state: part.state.status,
8229
- ...part.metadata ? { metadata: part.metadata } : {},
8230
- ...openCodeToolStateFields(part.state)
8231
- };
8232
- }
8233
- function detailFromToolPart(part) {
8234
- switch (part.state.status) {
8235
- case "completed":
8236
- return part.state.output;
8237
- case "error":
8238
- return part.state.error;
8239
- case "running":
8240
- return part.state.title;
8241
- default:
8242
- return void 0;
8243
- }
8244
- }
8245
- function resolveTextStreamKind(part) {
8246
- return part?.type === "reasoning" ? "reasoning_text" : "assistant_text";
8247
- }
8248
- function messageRoleForPart(messageRoleById, part) {
8249
- const known = messageRoleById.get(part.messageID);
8250
- if (known) {
8251
- return known;
8252
- }
8253
- return part.type === "tool" ? "assistant" : void 0;
8254
- }
8255
-
8256
8151
  // src/usage.ts
8257
8152
  var OPENCODE_COMPACTION_SUMMARY_MAX_CHARS = 8e3;
8258
8153
  function withOpenCodeCompactionSummary(snapshot, summary) {
@@ -8327,112 +8222,7 @@ function takeTurnUsage(usageByMessageId, sessionId) {
8327
8222
  };
8328
8223
  }
8329
8224
 
8330
- // src/sessionEvents.ts
8331
- function openCodeEventSessionId(event) {
8332
- const properties = event.properties;
8333
- if (!isRecord2(properties)) return void 0;
8334
- const sessionID = properties["sessionID"];
8335
- if (typeof sessionID === "string" && sessionID.length > 0) return sessionID;
8336
- const info = properties["info"];
8337
- if (isRecord2(info) && typeof info["id"] === "string" && info["id"].length > 0) {
8338
- return info["id"];
8339
- }
8340
- return void 0;
8341
- }
8342
- function emitAssistantTextDelta(events, context, part) {
8343
- const previous = context.assistantTextByPartId.get(part.id);
8344
- const { latestText, deltaToEmit } = mergeOpenCodeAssistantText(previous, part.text);
8345
- context.assistantTextByPartId.set(part.id, latestText);
8346
- context.partTypeById.set(part.id, part.type);
8347
- if (deltaToEmit.length > 0) {
8348
- emitEvent(
8349
- events,
8350
- context,
8351
- "content.delta",
8352
- { streamKind: resolveTextStreamKind(part), delta: deltaToEmit },
8353
- { itemId: part.id }
8354
- );
8355
- }
8356
- if (part.type === "text" && part.time?.end !== void 0 && !context.completedTextParts.has(part.id)) {
8357
- context.completedTextParts.add(part.id);
8358
- emitEvent(
8359
- events,
8360
- context,
8361
- "item.completed",
8362
- { itemType: "assistant_message", status: "completed", detail: latestText },
8363
- { itemId: part.id }
8364
- );
8365
- }
8366
- }
8367
- function emitToolLifecycle(events, context, part) {
8368
- const itemId = part.callID || part.id;
8369
- const itemType = toToolLifecycleItemType(part.tool);
8370
- const detail = detailFromToolPart(part);
8371
- const payload = {
8372
- itemType,
8373
- title: part.tool,
8374
- ...detail ? { detail } : {},
8375
- data: openCodeToolActivityData(part)
8376
- };
8377
- const extra = { itemId };
8378
- switch (part.state.status) {
8379
- case "pending":
8380
- case "running": {
8381
- const status = "inProgress";
8382
- if (!context.startedToolItems.has(itemId)) {
8383
- context.startedToolItems.add(itemId);
8384
- emitEvent(events, context, "item.started", { ...payload, status }, extra);
8385
- } else {
8386
- emitEvent(events, context, "item.updated", { ...payload, status }, extra);
8387
- }
8388
- return;
8389
- }
8390
- case "completed":
8391
- context.startedToolItems.add(itemId);
8392
- emitEvent(events, context, "item.completed", { ...payload, status: "completed" }, extra);
8393
- return;
8394
- case "error":
8395
- context.startedToolItems.add(itemId);
8396
- emitEvent(events, context, "item.completed", { ...payload, status: "failed" }, extra);
8397
- return;
8398
- default:
8399
- return;
8400
- }
8401
- }
8402
- function completeActiveTurn(events, context, state, extra) {
8403
- const turnId = context.session.activeTurnId;
8404
- const usage = takeTurnUsage(context.usageByMessageId, context.sessionId);
8405
- context.pendingTurnError = void 0;
8406
- if (!turnId) return usage;
8407
- if (state === "interrupted") {
8408
- emitEvent(
8409
- events,
8410
- context,
8411
- "turn.aborted",
8412
- { reason: extra?.reason ?? "Interrupted by user." },
8413
- { turnId }
8414
- );
8415
- } else {
8416
- emitEvent(
8417
- events,
8418
- context,
8419
- "turn.completed",
8420
- {
8421
- state,
8422
- ...usage ? { tokenUsage: usage } : {},
8423
- ...extra?.errorMessage ? { errorMessage: extra.errorMessage } : {}
8424
- },
8425
- { turnId }
8426
- );
8427
- }
8428
- context.session = {
8429
- ...withoutActiveTurn(context.session),
8430
- status: state === "failed" ? "error" : "ready",
8431
- updatedAt: nowIso(),
8432
- ...extra?.errorMessage ? { lastError: extra.errorMessage } : {}
8433
- };
8434
- return usage;
8435
- }
8225
+ // src/sessionRequests.ts
8436
8226
  var OPENCODE_REQUEST_TIMEOUT_MS = 1e4;
8437
8227
  var OPENCODE_SESSION_ANCESTRY_MAX_DEPTH = 32;
8438
8228
  async function autoReplyPermissionOnce(context, requestId) {
@@ -8668,6 +8458,218 @@ async function handleOtherSessionEvent(input) {
8668
8458
  return;
8669
8459
  }
8670
8460
  }
8461
+
8462
+ // src/textMerge.ts
8463
+ function commonPrefixLength(left, right) {
8464
+ let index = 0;
8465
+ while (index < left.length && index < right.length && left[index] === right[index]) {
8466
+ index += 1;
8467
+ }
8468
+ return index;
8469
+ }
8470
+ function resolveLatestAssistantText(previousText, nextText) {
8471
+ if (previousText && previousText.length > nextText.length && previousText.startsWith(nextText)) {
8472
+ return previousText;
8473
+ }
8474
+ return nextText;
8475
+ }
8476
+ function mergeOpenCodeAssistantText(previousText, nextText) {
8477
+ const latestText = resolveLatestAssistantText(previousText, nextText);
8478
+ return {
8479
+ latestText,
8480
+ deltaToEmit: latestText.slice(commonPrefixLength(previousText ?? "", latestText))
8481
+ };
8482
+ }
8483
+ function appendOpenCodeAssistantTextDelta(previousText, delta) {
8484
+ return {
8485
+ nextText: previousText + delta,
8486
+ deltaToEmit: delta
8487
+ };
8488
+ }
8489
+
8490
+ // src/toolClassify.ts
8491
+ function toToolLifecycleItemType(toolName) {
8492
+ const normalized = toolName.toLowerCase();
8493
+ if (normalized === "todowrite" || normalized === "todoread") {
8494
+ return "dynamic_tool_call";
8495
+ }
8496
+ if (normalized.includes("bash") || normalized.includes("command")) {
8497
+ return "command_execution";
8498
+ }
8499
+ if (normalized.includes("edit") || normalized.includes("write") || normalized.includes("patch") || normalized.includes("multiedit")) {
8500
+ return "file_change";
8501
+ }
8502
+ if (normalized.includes("web")) {
8503
+ return "web_search";
8504
+ }
8505
+ if (normalized.includes("mcp")) {
8506
+ return "mcp_tool_call";
8507
+ }
8508
+ if (normalized.includes("image")) {
8509
+ return "image_view";
8510
+ }
8511
+ if (normalized.includes("task") || normalized.includes("agent") || normalized.includes("subtask")) {
8512
+ return "collab_agent_tool_call";
8513
+ }
8514
+ return "dynamic_tool_call";
8515
+ }
8516
+ function openCodeToolStateFields(state) {
8517
+ const input = Object.keys(state.input).length > 0 ? { input: state.input } : {};
8518
+ switch (state.status) {
8519
+ case "pending":
8520
+ return {
8521
+ ...input,
8522
+ ...state.raw.length > 0 ? { argumentText: state.raw } : {}
8523
+ };
8524
+ case "running":
8525
+ return input;
8526
+ case "completed":
8527
+ return { ...input, output: state.output };
8528
+ case "error":
8529
+ return { ...input, output: state.error };
8530
+ default: {
8531
+ const unexpected = state;
8532
+ return unexpected;
8533
+ }
8534
+ }
8535
+ }
8536
+ function openCodeToolActivityData(part) {
8537
+ return {
8538
+ tool: part.tool,
8539
+ state: part.state.status,
8540
+ ...part.metadata ? { metadata: part.metadata } : {},
8541
+ ...openCodeToolStateFields(part.state)
8542
+ };
8543
+ }
8544
+ function detailFromToolPart(part) {
8545
+ switch (part.state.status) {
8546
+ case "completed":
8547
+ return part.state.output;
8548
+ case "error":
8549
+ return part.state.error;
8550
+ case "running":
8551
+ return part.state.title;
8552
+ default:
8553
+ return void 0;
8554
+ }
8555
+ }
8556
+ function resolveTextStreamKind(part) {
8557
+ return part?.type === "reasoning" ? "reasoning_text" : "assistant_text";
8558
+ }
8559
+ function messageRoleForPart(messageRoleById, part) {
8560
+ const known = messageRoleById.get(part.messageID);
8561
+ if (known) {
8562
+ return known;
8563
+ }
8564
+ return part.type === "tool" ? "assistant" : void 0;
8565
+ }
8566
+
8567
+ // src/sessionEvents.ts
8568
+ function openCodeEventSessionId(event) {
8569
+ const properties = event.properties;
8570
+ if (!isRecord2(properties)) return void 0;
8571
+ const sessionID = properties["sessionID"];
8572
+ if (typeof sessionID === "string" && sessionID.length > 0) return sessionID;
8573
+ const info = properties["info"];
8574
+ if (isRecord2(info) && typeof info["id"] === "string" && info["id"].length > 0) {
8575
+ return info["id"];
8576
+ }
8577
+ return void 0;
8578
+ }
8579
+ function emitAssistantTextDelta(events, context, part) {
8580
+ const previous = context.assistantTextByPartId.get(part.id);
8581
+ const { latestText, deltaToEmit } = mergeOpenCodeAssistantText(previous, part.text);
8582
+ context.assistantTextByPartId.set(part.id, latestText);
8583
+ context.partTypeById.set(part.id, part.type);
8584
+ if (deltaToEmit.length > 0) {
8585
+ emitEvent(
8586
+ events,
8587
+ context,
8588
+ "content.delta",
8589
+ { streamKind: resolveTextStreamKind(part), delta: deltaToEmit },
8590
+ { itemId: part.id }
8591
+ );
8592
+ }
8593
+ if (part.type === "text" && part.time?.end !== void 0 && !context.completedTextParts.has(part.id)) {
8594
+ context.completedTextParts.add(part.id);
8595
+ emitEvent(
8596
+ events,
8597
+ context,
8598
+ "item.completed",
8599
+ { itemType: "assistant_message", status: "completed", detail: latestText },
8600
+ { itemId: part.id }
8601
+ );
8602
+ }
8603
+ }
8604
+ function emitToolLifecycle(events, context, part) {
8605
+ const itemId = part.callID || part.id;
8606
+ const itemType = toToolLifecycleItemType(part.tool);
8607
+ const detail = detailFromToolPart(part);
8608
+ const payload = {
8609
+ itemType,
8610
+ title: part.tool,
8611
+ ...detail ? { detail } : {},
8612
+ data: openCodeToolActivityData(part)
8613
+ };
8614
+ const extra = { itemId };
8615
+ switch (part.state.status) {
8616
+ case "pending":
8617
+ case "running": {
8618
+ const status = "inProgress";
8619
+ if (!context.startedToolItems.has(itemId)) {
8620
+ context.startedToolItems.add(itemId);
8621
+ emitEvent(events, context, "item.started", { ...payload, status }, extra);
8622
+ } else {
8623
+ emitEvent(events, context, "item.updated", { ...payload, status }, extra);
8624
+ }
8625
+ return;
8626
+ }
8627
+ case "completed":
8628
+ context.startedToolItems.add(itemId);
8629
+ emitEvent(events, context, "item.completed", { ...payload, status: "completed" }, extra);
8630
+ return;
8631
+ case "error":
8632
+ context.startedToolItems.add(itemId);
8633
+ emitEvent(events, context, "item.completed", { ...payload, status: "failed" }, extra);
8634
+ return;
8635
+ default:
8636
+ return;
8637
+ }
8638
+ }
8639
+ function completeActiveTurn(events, context, state, extra) {
8640
+ const turnId = context.session.activeTurnId;
8641
+ const usage = takeTurnUsage(context.usageByMessageId, context.sessionId);
8642
+ context.pendingTurnError = void 0;
8643
+ if (!turnId) return usage;
8644
+ if (state === "interrupted") {
8645
+ emitEvent(
8646
+ events,
8647
+ context,
8648
+ "turn.aborted",
8649
+ { reason: extra?.reason ?? "Interrupted by user." },
8650
+ { turnId }
8651
+ );
8652
+ } else {
8653
+ emitEvent(
8654
+ events,
8655
+ context,
8656
+ "turn.completed",
8657
+ {
8658
+ state,
8659
+ ...usage ? { tokenUsage: usage } : {},
8660
+ ...extra?.errorMessage ? { errorMessage: extra.errorMessage } : {}
8661
+ },
8662
+ { turnId }
8663
+ );
8664
+ }
8665
+ context.session = {
8666
+ ...withoutActiveTurn(context.session),
8667
+ status: state === "failed" ? "error" : "ready",
8668
+ updatedAt: nowIso(),
8669
+ ...extra?.errorMessage ? { lastError: extra.errorMessage } : {}
8670
+ };
8671
+ return usage;
8672
+ }
8671
8673
  async function handleSubscribedEvent(input) {
8672
8674
  const { events, context, event } = input;
8673
8675
  void input.declineRelay;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-opencode",
3
- "version": "0.2.2984",
3
+ "version": "0.2.2990",
4
4
  "description": "OpenCode executor: OpenCode CLI via @opencode-ai/sdk/v2.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -24,7 +24,7 @@
24
24
  "@types/node": "24.12.4",
25
25
  "esbuild": "0.28.1",
26
26
  "vite-plus": "0.2.2",
27
- "@ycodium-ai/plugin-api": "0.2.2984",
27
+ "@ycodium-ai/plugin-api": "0.2.2990",
28
28
  "ycodium-executor-testing": "0.0.0",
29
29
  "ycodium-fetch-ports": "0.0.0"
30
30
  },