@ai-setting/roy-task-plugin 0.7.3 → 0.7.5
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.
- package/dist/cli.js +154 -121
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -444,126 +444,6 @@ class NdjsonAssembler {
|
|
|
444
444
|
}
|
|
445
445
|
}
|
|
446
446
|
|
|
447
|
-
// ../../../packages/cli/src/daemon/runners/codex-stream.ts
|
|
448
|
-
var CODEX_ITEM_TYPES = Object.freeze({
|
|
449
|
-
AGENT_MESSAGE: "agent_message",
|
|
450
|
-
COMMAND_EXECUTION: "command_execution",
|
|
451
|
-
MCP_TOOL_CALL: "mcp_tool_call",
|
|
452
|
-
ERROR: "error"
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
class CodexStreamDecoder {
|
|
456
|
-
lines = new LineSplitter;
|
|
457
|
-
state = { tools: [], errors: [], turnCompleted: false };
|
|
458
|
-
mcpSeen = new Set;
|
|
459
|
-
pushChunk(chunk) {
|
|
460
|
-
for (const line of this.lines.pushChunk(chunk))
|
|
461
|
-
this.consume(line);
|
|
462
|
-
}
|
|
463
|
-
finish() {
|
|
464
|
-
for (const line of this.lines.finish())
|
|
465
|
-
this.consume(line);
|
|
466
|
-
return this.toResult();
|
|
467
|
-
}
|
|
468
|
-
snapshot() {
|
|
469
|
-
return { ...this.state, tools: [...this.state.tools], errors: [...this.state.errors] };
|
|
470
|
-
}
|
|
471
|
-
consume(rawLine) {
|
|
472
|
-
const line = rawLine.trim();
|
|
473
|
-
if (!line.startsWith("{"))
|
|
474
|
-
return;
|
|
475
|
-
let event;
|
|
476
|
-
try {
|
|
477
|
-
event = JSON.parse(line);
|
|
478
|
-
} catch {
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
if (typeof event !== "object" || event === null)
|
|
482
|
-
return;
|
|
483
|
-
const ev = event;
|
|
484
|
-
if (ev.type === "thread.started") {
|
|
485
|
-
const id = ev.thread_id;
|
|
486
|
-
if (typeof id === "string" && id)
|
|
487
|
-
this.state.sessionId = id;
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
if (ev.type === "turn.completed") {
|
|
491
|
-
this.state.turnCompleted = true;
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
|
-
if (ev.type === "item.started" || ev.type === "item.completed") {
|
|
495
|
-
this.consumeItem(ev.item, ev.type === "item.completed");
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
consumeItem(raw, completed) {
|
|
499
|
-
if (typeof raw !== "object" || raw === null)
|
|
500
|
-
return;
|
|
501
|
-
const item = raw;
|
|
502
|
-
if (item.type === CODEX_ITEM_TYPES.AGENT_MESSAGE) {
|
|
503
|
-
if (typeof item.text === "string" && item.text.length > 0) {
|
|
504
|
-
this.state.text = item.text;
|
|
505
|
-
}
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
if (item.type === CODEX_ITEM_TYPES.ERROR) {
|
|
509
|
-
if (typeof item.message === "string" && item.message.length > 0) {
|
|
510
|
-
this.state.errors.push(item.message);
|
|
511
|
-
}
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
if (item.type === CODEX_ITEM_TYPES.COMMAND_EXECUTION) {
|
|
515
|
-
const id = item.id;
|
|
516
|
-
if (typeof id === "string" && id && this.state.tools.includes(id)) {} else {
|
|
517
|
-
this.state.tools.push(typeof id === "string" ? id : `cmd-${this.state.tools.length}`);
|
|
518
|
-
}
|
|
519
|
-
if (completed && this.state.createdTask === undefined) {
|
|
520
|
-
this.state.createdTask = extractCreatedTask(item.aggregated_output);
|
|
521
|
-
}
|
|
522
|
-
return;
|
|
523
|
-
}
|
|
524
|
-
if (item.type === CODEX_ITEM_TYPES.MCP_TOOL_CALL) {
|
|
525
|
-
const id = item.id;
|
|
526
|
-
if (typeof id === "string" && id) {
|
|
527
|
-
if (this.mcpSeen.has(id))
|
|
528
|
-
return;
|
|
529
|
-
this.mcpSeen.add(id);
|
|
530
|
-
}
|
|
531
|
-
const name = typeof item.tool === "string" && item.tool ? item.tool : undefined;
|
|
532
|
-
this.state.tools.push(name ?? (typeof id === "string" && id ? id : `mcp-${this.state.tools.length}`));
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
toResult() {
|
|
537
|
-
const result = {
|
|
538
|
-
text: this.state.text ?? ""
|
|
539
|
-
};
|
|
540
|
-
if (this.state.sessionId)
|
|
541
|
-
result.sessionId = this.state.sessionId;
|
|
542
|
-
if (this.state.tools.length > 0) {
|
|
543
|
-
result.toolCalls = this.state.tools.length;
|
|
544
|
-
result.tools = [...this.state.tools];
|
|
545
|
-
}
|
|
546
|
-
if (this.state.createdTask)
|
|
547
|
-
result.createdTask = this.state.createdTask;
|
|
548
|
-
return result;
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
// ../../../packages/cli/src/daemon/runners/codex-sessions.ts
|
|
553
|
-
function createCodexSessionRegistry() {
|
|
554
|
-
const sessions = new Map;
|
|
555
|
-
return {
|
|
556
|
-
get: (key) => sessions.get(key),
|
|
557
|
-
set: (key, id) => {
|
|
558
|
-
sessions.set(key, id);
|
|
559
|
-
},
|
|
560
|
-
delete: (key) => {
|
|
561
|
-
sessions.delete(key);
|
|
562
|
-
},
|
|
563
|
-
size: () => sessions.size
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
|
|
567
447
|
// ../../../packages/cli/src/daemon/runners/claude-agents.ts
|
|
568
448
|
var CLAUDE_ROY_AGENT_NAME = "roy";
|
|
569
449
|
var ROY_AGENT_DESCRIPTION = "Roy — task-as-first-class-citizen agent. Uses the roy-agent task lifecycle " + "(task_tree → task_create → task_update → task_operation_create → task_complete) " + "so every piece of work is tracked in the local task store.";
|
|
@@ -714,6 +594,159 @@ function buildClaudeAgentsJson(opts = {}) {
|
|
|
714
594
|
return JSON.stringify({ [opts.name ?? CLAUDE_ROY_AGENT_NAME]: def });
|
|
715
595
|
}
|
|
716
596
|
|
|
597
|
+
// ../../../packages/cli/src/daemon/runners/codex-stream.ts
|
|
598
|
+
var CODEX_ITEM_TYPES = Object.freeze({
|
|
599
|
+
AGENT_MESSAGE: "agent_message",
|
|
600
|
+
COMMAND_EXECUTION: "command_execution",
|
|
601
|
+
MCP_TOOL_CALL: "mcp_tool_call",
|
|
602
|
+
ERROR: "error"
|
|
603
|
+
});
|
|
604
|
+
function isCreationTool(tool) {
|
|
605
|
+
if (isTaskCreateTool(tool))
|
|
606
|
+
return true;
|
|
607
|
+
const bare = tool.includes("/") ? tool.slice(tool.lastIndexOf("/") + 1) : tool;
|
|
608
|
+
return isTaskCreateTool(bare);
|
|
609
|
+
}
|
|
610
|
+
function isSuccessfulMcpStatus(status) {
|
|
611
|
+
return status === undefined || status === "completed";
|
|
612
|
+
}
|
|
613
|
+
function isRoyTaskServer(server) {
|
|
614
|
+
return server === undefined || server === ROY_TASK_MCP_SERVER;
|
|
615
|
+
}
|
|
616
|
+
function mcpResultText(result) {
|
|
617
|
+
if (typeof result !== "object" || result === null)
|
|
618
|
+
return;
|
|
619
|
+
const content = result.content;
|
|
620
|
+
if (!Array.isArray(content))
|
|
621
|
+
return;
|
|
622
|
+
for (const block of content) {
|
|
623
|
+
if (typeof block === "object" && block !== null && block.type === "text" && typeof block.text === "string") {
|
|
624
|
+
return block.text;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
class CodexStreamDecoder {
|
|
631
|
+
lines = new LineSplitter;
|
|
632
|
+
state = { tools: [], errors: [], turnCompleted: false };
|
|
633
|
+
mcpSeen = new Set;
|
|
634
|
+
pushChunk(chunk) {
|
|
635
|
+
for (const line of this.lines.pushChunk(chunk))
|
|
636
|
+
this.consume(line);
|
|
637
|
+
}
|
|
638
|
+
finish() {
|
|
639
|
+
for (const line of this.lines.finish())
|
|
640
|
+
this.consume(line);
|
|
641
|
+
return this.toResult();
|
|
642
|
+
}
|
|
643
|
+
snapshot() {
|
|
644
|
+
return { ...this.state, tools: [...this.state.tools], errors: [...this.state.errors] };
|
|
645
|
+
}
|
|
646
|
+
consume(rawLine) {
|
|
647
|
+
const line = rawLine.trim();
|
|
648
|
+
if (!line.startsWith("{"))
|
|
649
|
+
return;
|
|
650
|
+
let event;
|
|
651
|
+
try {
|
|
652
|
+
event = JSON.parse(line);
|
|
653
|
+
} catch {
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
if (typeof event !== "object" || event === null)
|
|
657
|
+
return;
|
|
658
|
+
const ev = event;
|
|
659
|
+
if (ev.type === "thread.started") {
|
|
660
|
+
const id = ev.thread_id;
|
|
661
|
+
if (typeof id === "string" && id)
|
|
662
|
+
this.state.sessionId = id;
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
if (ev.type === "turn.completed") {
|
|
666
|
+
this.state.turnCompleted = true;
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
if (ev.type === "item.started" || ev.type === "item.completed") {
|
|
670
|
+
this.consumeItem(ev.item, ev.type === "item.completed");
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
consumeItem(raw, completed) {
|
|
674
|
+
if (typeof raw !== "object" || raw === null)
|
|
675
|
+
return;
|
|
676
|
+
const item = raw;
|
|
677
|
+
if (item.type === CODEX_ITEM_TYPES.AGENT_MESSAGE) {
|
|
678
|
+
if (typeof item.text === "string" && item.text.length > 0) {
|
|
679
|
+
this.state.text = item.text;
|
|
680
|
+
}
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
if (item.type === CODEX_ITEM_TYPES.ERROR) {
|
|
684
|
+
if (typeof item.message === "string" && item.message.length > 0) {
|
|
685
|
+
this.state.errors.push(item.message);
|
|
686
|
+
}
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
if (item.type === CODEX_ITEM_TYPES.COMMAND_EXECUTION) {
|
|
690
|
+
const id = item.id;
|
|
691
|
+
if (typeof id === "string" && id && this.state.tools.includes(id)) {} else {
|
|
692
|
+
this.state.tools.push(typeof id === "string" ? id : `cmd-${this.state.tools.length}`);
|
|
693
|
+
}
|
|
694
|
+
if (completed && this.state.createdTask === undefined) {
|
|
695
|
+
this.state.createdTask = extractCreatedTask(item.aggregated_output);
|
|
696
|
+
}
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
if (item.type === CODEX_ITEM_TYPES.MCP_TOOL_CALL) {
|
|
700
|
+
const id = item.id;
|
|
701
|
+
const seen = typeof id === "string" && id && this.mcpSeen.has(id);
|
|
702
|
+
if (typeof id === "string" && id)
|
|
703
|
+
this.mcpSeen.add(id);
|
|
704
|
+
if (!seen) {
|
|
705
|
+
const name = typeof item.tool === "string" && item.tool ? item.tool : undefined;
|
|
706
|
+
this.state.tools.push(name ?? (typeof id === "string" && id ? id : `mcp-${this.state.tools.length}`));
|
|
707
|
+
}
|
|
708
|
+
if (completed && this.state.createdTask === undefined && isSuccessfulMcpStatus(item.status) && typeof item.tool === "string" && isCreationTool(item.tool) && isRoyTaskServer(item.server)) {
|
|
709
|
+
const text = mcpResultText(item.result);
|
|
710
|
+
if (text !== undefined) {
|
|
711
|
+
const args = item.arguments;
|
|
712
|
+
const hint = typeof args?.title === "string" ? args.title : undefined;
|
|
713
|
+
this.state.createdTask = extractCreatedTask(text, hint);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
toResult() {
|
|
720
|
+
const result = {
|
|
721
|
+
text: this.state.text ?? ""
|
|
722
|
+
};
|
|
723
|
+
if (this.state.sessionId)
|
|
724
|
+
result.sessionId = this.state.sessionId;
|
|
725
|
+
if (this.state.tools.length > 0) {
|
|
726
|
+
result.toolCalls = this.state.tools.length;
|
|
727
|
+
result.tools = [...this.state.tools];
|
|
728
|
+
}
|
|
729
|
+
if (this.state.createdTask)
|
|
730
|
+
result.createdTask = this.state.createdTask;
|
|
731
|
+
return result;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
// ../../../packages/cli/src/daemon/runners/codex-sessions.ts
|
|
736
|
+
function createCodexSessionRegistry() {
|
|
737
|
+
const sessions = new Map;
|
|
738
|
+
return {
|
|
739
|
+
get: (key) => sessions.get(key),
|
|
740
|
+
set: (key, id) => {
|
|
741
|
+
sessions.set(key, id);
|
|
742
|
+
},
|
|
743
|
+
delete: (key) => {
|
|
744
|
+
sessions.delete(key);
|
|
745
|
+
},
|
|
746
|
+
size: () => sessions.size
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
|
|
717
750
|
// ../../../packages/cli/src/daemon/runners/claude.ts
|
|
718
751
|
import { createHash } from "node:crypto";
|
|
719
752
|
import { appendFileSync, existsSync } from "node:fs";
|
|
@@ -3230,7 +3263,7 @@ function formatStatus(report) {
|
|
|
3230
3263
|
}
|
|
3231
3264
|
|
|
3232
3265
|
// ../../../packages/cli/src/main.ts
|
|
3233
|
-
var VERSION = "0.7.
|
|
3266
|
+
var VERSION = "0.7.5";
|
|
3234
3267
|
async function main(argv) {
|
|
3235
3268
|
const parsed = parseArgs(argv);
|
|
3236
3269
|
switch (parsed.command) {
|