baro-ai 0.44.1 → 0.45.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.
- package/dist/cli.mjs +213 -201
- package/dist/cli.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -9886,6 +9886,10 @@ function buildDag(stories, options = {}) {
|
|
|
9886
9886
|
return levels;
|
|
9887
9887
|
}
|
|
9888
9888
|
|
|
9889
|
+
// ../baro-orchestrator/src/participants/auditor.ts
|
|
9890
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
9891
|
+
import { dirname } from "path";
|
|
9892
|
+
|
|
9889
9893
|
// ../baro-orchestrator/src/semantic-events.ts
|
|
9890
9894
|
function defineSemanticEvent(type) {
|
|
9891
9895
|
return {
|
|
@@ -9924,8 +9928,6 @@ var ConductorState = defineSemanticEvent("conductor_state");
|
|
|
9924
9928
|
var StoryResult = defineSemanticEvent("story_result");
|
|
9925
9929
|
|
|
9926
9930
|
// ../baro-orchestrator/src/participants/auditor.ts
|
|
9927
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
9928
|
-
import { dirname } from "path";
|
|
9929
9931
|
var Auditor = class extends BaseObserver {
|
|
9930
9932
|
path;
|
|
9931
9933
|
skipStreamChunks;
|
|
@@ -10097,6 +10099,14 @@ function buildDefaultStoryPrompt(story) {
|
|
|
10097
10099
|
"- If a single-file edit is sufficient, make a single-file edit. Resist expanding.",
|
|
10098
10100
|
"- If you notice unrelated bugs or improvements, mention them in your final commit",
|
|
10099
10101
|
" message under a `Noted (out of scope):` line so the user can file follow-ups.",
|
|
10102
|
+
"- Do NOT take external side-effecting actions \u2014 opening GitHub issues, posting PR",
|
|
10103
|
+
" comments, sending notifications, pushing tags \u2014 UNLESS this story's acceptance",
|
|
10104
|
+
" criteria explicitly require it. In a parallel run many agents share one working",
|
|
10105
|
+
" tree, so a failure you observe is very likely produced by another story, not you.",
|
|
10106
|
+
"- If `npm test` / `cargo test` / the build surfaces a FAILURE in a file this story",
|
|
10107
|
+
" did not create or modify, it is not yours to fix OR report. Note it under",
|
|
10108
|
+
" `Noted (out of scope):` and move on \u2014 do not open an issue for it. A dedicated",
|
|
10109
|
+
" triage story (or the user) owns deciding whether a shared failure is a real bug.",
|
|
10100
10110
|
"",
|
|
10101
10111
|
"IMPORTANT: Before you commit, you MUST verify the project builds successfully:",
|
|
10102
10112
|
" - If Cargo.toml exists: run `cargo build` and fix all errors and warnings",
|
|
@@ -11611,6 +11621,206 @@ function matchCommit(story, commits) {
|
|
|
11611
11621
|
return bestScore >= 2 ? bestSha : null;
|
|
11612
11622
|
}
|
|
11613
11623
|
|
|
11624
|
+
// ../baro-orchestrator/src/tui-protocol.ts
|
|
11625
|
+
function emit(event) {
|
|
11626
|
+
const line = JSON.stringify(event) + "\n";
|
|
11627
|
+
process.stdout.write(line);
|
|
11628
|
+
}
|
|
11629
|
+
|
|
11630
|
+
// ../baro-orchestrator/src/participants/forwarders/agent-stream.ts
|
|
11631
|
+
var AgentStreamForwarder = class extends BaseObserver {
|
|
11632
|
+
async onExternalModelMessage(source, item) {
|
|
11633
|
+
const agentId = source.agentId;
|
|
11634
|
+
if (typeof agentId !== "string") return;
|
|
11635
|
+
const json = item.toJSON();
|
|
11636
|
+
const text = json.content?.[0]?.text ?? "";
|
|
11637
|
+
if (!text.trim()) return;
|
|
11638
|
+
emitMultiline(agentId, text);
|
|
11639
|
+
}
|
|
11640
|
+
async onExternalFunctionCall(source, item) {
|
|
11641
|
+
const agentId = source.agentId;
|
|
11642
|
+
if (typeof agentId !== "string") return;
|
|
11643
|
+
emitMultiline(agentId, `[tool_call] ${item.name} ${item.args}`);
|
|
11644
|
+
}
|
|
11645
|
+
async onExternalFunctionCallOutput(source, item) {
|
|
11646
|
+
const agentId = source.agentId;
|
|
11647
|
+
if (typeof agentId !== "string") return;
|
|
11648
|
+
const json = item.toJSON();
|
|
11649
|
+
const text = json.output?.[0]?.text ?? "";
|
|
11650
|
+
emitMultiline(agentId, `[tool_result ${json.call_id}] ${text}`);
|
|
11651
|
+
}
|
|
11652
|
+
};
|
|
11653
|
+
function emitMultiline(agentId, text) {
|
|
11654
|
+
if (!text) return;
|
|
11655
|
+
const lines = text.split("\n");
|
|
11656
|
+
for (const line of lines) {
|
|
11657
|
+
if (line.length === 0 && lines.length === 1) continue;
|
|
11658
|
+
emit({ type: "story_log", id: agentId, line });
|
|
11659
|
+
}
|
|
11660
|
+
}
|
|
11661
|
+
|
|
11662
|
+
// ../baro-orchestrator/src/participants/forwarders/coordination.ts
|
|
11663
|
+
var CoordinationForwarder = class extends BaseObserver {
|
|
11664
|
+
async onExternalEvent(_source, event) {
|
|
11665
|
+
if (Coordination.is(event)) {
|
|
11666
|
+
this.handleCoordination(event.data);
|
|
11667
|
+
return;
|
|
11668
|
+
}
|
|
11669
|
+
if (Critique.is(event)) {
|
|
11670
|
+
this.handleCritique(event.data);
|
|
11671
|
+
return;
|
|
11672
|
+
}
|
|
11673
|
+
}
|
|
11674
|
+
handleCoordination(item) {
|
|
11675
|
+
emit({
|
|
11676
|
+
type: "story_log",
|
|
11677
|
+
id: item.recipientId,
|
|
11678
|
+
line: `[sentry/${item.kind}] ${item.reason}`
|
|
11679
|
+
});
|
|
11680
|
+
}
|
|
11681
|
+
handleCritique(item) {
|
|
11682
|
+
emit({
|
|
11683
|
+
type: "story_log",
|
|
11684
|
+
id: item.agentId,
|
|
11685
|
+
line: `[critic/${item.verdict}] ${item.reasoning}`
|
|
11686
|
+
});
|
|
11687
|
+
}
|
|
11688
|
+
};
|
|
11689
|
+
|
|
11690
|
+
// ../baro-orchestrator/src/participants/forwarders/finalization.ts
|
|
11691
|
+
var FinalizationForwarder = class extends BaseObserver {
|
|
11692
|
+
async onExternalEvent(_source, event) {
|
|
11693
|
+
if (FinalizeStarted.is(event)) {
|
|
11694
|
+
const _item = event.data;
|
|
11695
|
+
emit({ type: "finalize_start" });
|
|
11696
|
+
return;
|
|
11697
|
+
}
|
|
11698
|
+
if (PrCreated.is(event)) {
|
|
11699
|
+
const item = event.data;
|
|
11700
|
+
emit({ type: "finalize_complete", pr_url: item.url });
|
|
11701
|
+
return;
|
|
11702
|
+
}
|
|
11703
|
+
}
|
|
11704
|
+
};
|
|
11705
|
+
|
|
11706
|
+
// ../baro-orchestrator/src/participants/forwarders/progress.ts
|
|
11707
|
+
var ProgressForwarder = class extends BaseObserver {
|
|
11708
|
+
async onExternalEvent(_source, event) {
|
|
11709
|
+
if (!ConductorState.is(event)) return;
|
|
11710
|
+
const item = event.data;
|
|
11711
|
+
if (item.phase === "running_level" && item.currentLevel != null && item.totalLevels != null) {
|
|
11712
|
+
emit({
|
|
11713
|
+
type: "progress",
|
|
11714
|
+
completed: item.currentLevel - 1,
|
|
11715
|
+
total: item.totalLevels,
|
|
11716
|
+
percentage: Math.round(
|
|
11717
|
+
(item.currentLevel - 1) / Math.max(1, item.totalLevels) * 100
|
|
11718
|
+
)
|
|
11719
|
+
});
|
|
11720
|
+
}
|
|
11721
|
+
}
|
|
11722
|
+
};
|
|
11723
|
+
|
|
11724
|
+
// ../baro-orchestrator/src/participants/forwarders/story-lifecycle.ts
|
|
11725
|
+
var StoryLifecycleForwarder = class extends BaseObserver {
|
|
11726
|
+
startedStories = /* @__PURE__ */ new Set();
|
|
11727
|
+
retryCounts = /* @__PURE__ */ new Map();
|
|
11728
|
+
async onExternalEvent(_source, event) {
|
|
11729
|
+
if (AgentState.is(event)) {
|
|
11730
|
+
this.handleAgentState(event.data);
|
|
11731
|
+
return;
|
|
11732
|
+
}
|
|
11733
|
+
if (StoryResult.is(event)) {
|
|
11734
|
+
this.handleStoryResult(event.data);
|
|
11735
|
+
return;
|
|
11736
|
+
}
|
|
11737
|
+
}
|
|
11738
|
+
handleAgentState(item) {
|
|
11739
|
+
if (item.phase === "running" && !this.startedStories.has(item.agentId)) {
|
|
11740
|
+
this.startedStories.add(item.agentId);
|
|
11741
|
+
emit({ type: "story_start", id: item.agentId, title: item.agentId });
|
|
11742
|
+
}
|
|
11743
|
+
if (item.phase === "waiting" && item.detail?.includes("retrying")) {
|
|
11744
|
+
const count = (this.retryCounts.get(item.agentId) ?? 0) + 1;
|
|
11745
|
+
this.retryCounts.set(item.agentId, count);
|
|
11746
|
+
emit({ type: "story_retry", id: item.agentId, attempt: count });
|
|
11747
|
+
}
|
|
11748
|
+
}
|
|
11749
|
+
handleStoryResult(item) {
|
|
11750
|
+
if (item.success) {
|
|
11751
|
+
emit({
|
|
11752
|
+
type: "story_complete",
|
|
11753
|
+
id: item.storyId,
|
|
11754
|
+
duration_secs: item.durationSecs,
|
|
11755
|
+
files_created: 0,
|
|
11756
|
+
files_modified: 0
|
|
11757
|
+
});
|
|
11758
|
+
} else {
|
|
11759
|
+
emit({
|
|
11760
|
+
type: "story_error",
|
|
11761
|
+
id: item.storyId,
|
|
11762
|
+
error: item.error ?? "unknown error",
|
|
11763
|
+
attempt: item.attempts,
|
|
11764
|
+
max_retries: item.attempts
|
|
11765
|
+
});
|
|
11766
|
+
}
|
|
11767
|
+
}
|
|
11768
|
+
};
|
|
11769
|
+
|
|
11770
|
+
// ../baro-orchestrator/src/participants/forwarders/token-usage.ts
|
|
11771
|
+
var TokenUsageForwarder = class extends BaseObserver {
|
|
11772
|
+
async onExternalEvent(_source, event) {
|
|
11773
|
+
if (AgentResult.is(event)) {
|
|
11774
|
+
this.handleClaudeResult(event.data);
|
|
11775
|
+
return;
|
|
11776
|
+
}
|
|
11777
|
+
if (CodexTurnEvent.is(event)) {
|
|
11778
|
+
this.handleCodexTurnEvent(event.data);
|
|
11779
|
+
return;
|
|
11780
|
+
}
|
|
11781
|
+
}
|
|
11782
|
+
handleClaudeResult(item) {
|
|
11783
|
+
const usage = item.usage;
|
|
11784
|
+
const inputTokens = typeof usage?.input_tokens === "number" ? usage.input_tokens : 0;
|
|
11785
|
+
const outputTokens = typeof usage?.output_tokens === "number" ? usage.output_tokens : 0;
|
|
11786
|
+
emit({
|
|
11787
|
+
type: "token_usage",
|
|
11788
|
+
id: item.agentId,
|
|
11789
|
+
input_tokens: inputTokens,
|
|
11790
|
+
output_tokens: outputTokens
|
|
11791
|
+
});
|
|
11792
|
+
}
|
|
11793
|
+
handleCodexTurnEvent(item) {
|
|
11794
|
+
if (item.phase !== "completed") return;
|
|
11795
|
+
const raw = item.raw;
|
|
11796
|
+
const usage = raw.usage;
|
|
11797
|
+
if (!usage) return;
|
|
11798
|
+
const inputTokens = typeof usage.input_tokens === "number" ? usage.input_tokens : 0;
|
|
11799
|
+
const outputBase = typeof usage.output_tokens === "number" ? usage.output_tokens : 0;
|
|
11800
|
+
const reasoning = typeof usage.reasoning_output_tokens === "number" ? usage.reasoning_output_tokens : 0;
|
|
11801
|
+
const outputTokens = outputBase + reasoning;
|
|
11802
|
+
emit({
|
|
11803
|
+
type: "token_usage",
|
|
11804
|
+
id: item.agentId,
|
|
11805
|
+
input_tokens: inputTokens,
|
|
11806
|
+
output_tokens: outputTokens
|
|
11807
|
+
});
|
|
11808
|
+
}
|
|
11809
|
+
};
|
|
11810
|
+
|
|
11811
|
+
// ../baro-orchestrator/src/participants/forwarders/index.ts
|
|
11812
|
+
function joinBaroEventForwarders(env) {
|
|
11813
|
+
const forwarders = [
|
|
11814
|
+
new AgentStreamForwarder(),
|
|
11815
|
+
new StoryLifecycleForwarder(),
|
|
11816
|
+
new TokenUsageForwarder(),
|
|
11817
|
+
new ProgressForwarder(),
|
|
11818
|
+
new CoordinationForwarder(),
|
|
11819
|
+
new FinalizationForwarder()
|
|
11820
|
+
];
|
|
11821
|
+
for (const f of forwarders) f.join(env);
|
|
11822
|
+
}
|
|
11823
|
+
|
|
11614
11824
|
// ../baro-orchestrator/src/participants/librarian.ts
|
|
11615
11825
|
var EXPLORATION_TOOLS = /* @__PURE__ */ new Set([
|
|
11616
11826
|
"Read",
|
|
@@ -14456,12 +14666,6 @@ var SurgeonOpenAI = class extends BaseObserver {
|
|
|
14456
14666
|
}
|
|
14457
14667
|
};
|
|
14458
14668
|
|
|
14459
|
-
// ../baro-orchestrator/src/tui-protocol.ts
|
|
14460
|
-
function emit(event) {
|
|
14461
|
-
const line = JSON.stringify(event) + "\n";
|
|
14462
|
-
process.stdout.write(line);
|
|
14463
|
-
}
|
|
14464
|
-
|
|
14465
14669
|
// ../baro-orchestrator/src/orchestrate.ts
|
|
14466
14670
|
async function orchestrate(config) {
|
|
14467
14671
|
const env = new AgenticEnvironment();
|
|
@@ -14497,7 +14701,7 @@ async function orchestrate(config) {
|
|
|
14497
14701
|
for (const p of config.extraParticipants) p.join(env);
|
|
14498
14702
|
}
|
|
14499
14703
|
if (emitTui) {
|
|
14500
|
-
|
|
14704
|
+
joinBaroEventForwarders(env);
|
|
14501
14705
|
}
|
|
14502
14706
|
const operator = new Operator(config.operatorHooks ?? {});
|
|
14503
14707
|
operator.setEnvironment(env);
|
|
@@ -14698,198 +14902,6 @@ async function orchestrate(config) {
|
|
|
14698
14902
|
storyAgents: /* @__PURE__ */ new Map()
|
|
14699
14903
|
};
|
|
14700
14904
|
}
|
|
14701
|
-
var BaroEventForwarder = class extends BaseObserver {
|
|
14702
|
-
/** Story IDs that have already received a `story_start`. */
|
|
14703
|
-
startedStories = /* @__PURE__ */ new Set();
|
|
14704
|
-
/** Number of in-flight retry attempts per story (for `story_retry`). */
|
|
14705
|
-
retryCounts = /* @__PURE__ */ new Map();
|
|
14706
|
-
/** Token-usage tally per story (incrementally updated from results). */
|
|
14707
|
-
tokensByStory = /* @__PURE__ */ new Map();
|
|
14708
|
-
async onExternalModelMessage(source, item) {
|
|
14709
|
-
this.handleModelMessage(source, item);
|
|
14710
|
-
}
|
|
14711
|
-
async onExternalFunctionCall(source, item) {
|
|
14712
|
-
this.handleToolCall(source, item);
|
|
14713
|
-
}
|
|
14714
|
-
async onExternalFunctionCallOutput(source, item) {
|
|
14715
|
-
this.handleToolResult(source, item);
|
|
14716
|
-
}
|
|
14717
|
-
async onExternalEvent(_source, event) {
|
|
14718
|
-
if (ConductorState.is(event)) {
|
|
14719
|
-
this.handleConductorState(event.data);
|
|
14720
|
-
return;
|
|
14721
|
-
}
|
|
14722
|
-
if (StoryResult.is(event)) {
|
|
14723
|
-
this.handleStoryResult(event.data);
|
|
14724
|
-
return;
|
|
14725
|
-
}
|
|
14726
|
-
if (AgentResult.is(event)) {
|
|
14727
|
-
this.handleClaudeResult(event.data);
|
|
14728
|
-
return;
|
|
14729
|
-
}
|
|
14730
|
-
if (CodexTurnEvent.is(event)) {
|
|
14731
|
-
this.handleCodexTurnEvent(event.data);
|
|
14732
|
-
return;
|
|
14733
|
-
}
|
|
14734
|
-
if (AgentState.is(event)) {
|
|
14735
|
-
this.handleAgentState(event.data);
|
|
14736
|
-
return;
|
|
14737
|
-
}
|
|
14738
|
-
if (ClaudeSystem.is(event)) {
|
|
14739
|
-
return;
|
|
14740
|
-
}
|
|
14741
|
-
if (Coordination.is(event)) {
|
|
14742
|
-
this.handleCoordination(event.data);
|
|
14743
|
-
return;
|
|
14744
|
-
}
|
|
14745
|
-
if (Critique.is(event)) {
|
|
14746
|
-
this.handleCritique(event.data);
|
|
14747
|
-
return;
|
|
14748
|
-
}
|
|
14749
|
-
if (FinalizeStarted.is(event)) {
|
|
14750
|
-
emit({ type: "finalize_start" });
|
|
14751
|
-
return;
|
|
14752
|
-
}
|
|
14753
|
-
if (PrCreated.is(event)) {
|
|
14754
|
-
emit({ type: "finalize_complete", pr_url: event.data.url });
|
|
14755
|
-
return;
|
|
14756
|
-
}
|
|
14757
|
-
}
|
|
14758
|
-
handleCoordination(item) {
|
|
14759
|
-
emit({
|
|
14760
|
-
type: "story_log",
|
|
14761
|
-
id: item.recipientId,
|
|
14762
|
-
line: `[sentry/${item.kind}] ${item.reason}`
|
|
14763
|
-
});
|
|
14764
|
-
}
|
|
14765
|
-
handleCritique(item) {
|
|
14766
|
-
emit({
|
|
14767
|
-
type: "story_log",
|
|
14768
|
-
id: item.agentId,
|
|
14769
|
-
line: `[critic/${item.verdict}] ${item.reasoning}`
|
|
14770
|
-
});
|
|
14771
|
-
}
|
|
14772
|
-
handleConductorState(item) {
|
|
14773
|
-
if (item.phase === "running_level" && item.currentLevel != null && item.totalLevels != null) {
|
|
14774
|
-
emit({
|
|
14775
|
-
type: "progress",
|
|
14776
|
-
completed: item.currentLevel - 1,
|
|
14777
|
-
total: item.totalLevels,
|
|
14778
|
-
percentage: Math.round(
|
|
14779
|
-
(item.currentLevel - 1) / Math.max(1, item.totalLevels) * 100
|
|
14780
|
-
)
|
|
14781
|
-
});
|
|
14782
|
-
}
|
|
14783
|
-
}
|
|
14784
|
-
handleStoryResult(item) {
|
|
14785
|
-
if (item.success) {
|
|
14786
|
-
emit({
|
|
14787
|
-
type: "story_complete",
|
|
14788
|
-
id: item.storyId,
|
|
14789
|
-
duration_secs: item.durationSecs,
|
|
14790
|
-
files_created: 0,
|
|
14791
|
-
files_modified: 0
|
|
14792
|
-
});
|
|
14793
|
-
} else {
|
|
14794
|
-
emit({
|
|
14795
|
-
type: "story_error",
|
|
14796
|
-
id: item.storyId,
|
|
14797
|
-
error: item.error ?? "unknown error",
|
|
14798
|
-
attempt: item.attempts,
|
|
14799
|
-
max_retries: item.attempts
|
|
14800
|
-
});
|
|
14801
|
-
}
|
|
14802
|
-
}
|
|
14803
|
-
handleClaudeResult(item) {
|
|
14804
|
-
const usage = item.usage;
|
|
14805
|
-
const inputTokens = typeof usage?.input_tokens === "number" ? usage.input_tokens : 0;
|
|
14806
|
-
const outputTokens = typeof usage?.output_tokens === "number" ? usage.output_tokens : 0;
|
|
14807
|
-
const tally = this.tokensByStory.get(item.agentId) ?? { input: 0, output: 0 };
|
|
14808
|
-
tally.input += inputTokens;
|
|
14809
|
-
tally.output += outputTokens;
|
|
14810
|
-
this.tokensByStory.set(item.agentId, tally);
|
|
14811
|
-
emit({
|
|
14812
|
-
type: "token_usage",
|
|
14813
|
-
id: item.agentId,
|
|
14814
|
-
input_tokens: inputTokens,
|
|
14815
|
-
output_tokens: outputTokens
|
|
14816
|
-
});
|
|
14817
|
-
}
|
|
14818
|
-
/**
|
|
14819
|
-
* Codex emits its usage stats inside `turn.completed` envelopes
|
|
14820
|
-
* (shape: `{type:"turn.completed", usage:{input_tokens,
|
|
14821
|
-
* cached_input_tokens, output_tokens, reasoning_output_tokens}}`).
|
|
14822
|
-
* Translate to the same `token_usage` BaroEvent shape Claude uses
|
|
14823
|
-
* so the TUI's existing counter works without backend-specific
|
|
14824
|
-
* branching. `cached_input_tokens` is rolled into `input_tokens`
|
|
14825
|
-
* (Codex reports both — Claude only reports the combined total —
|
|
14826
|
-
* so we surface the same number here for parity). Reasoning
|
|
14827
|
-
* tokens are billed as output tokens by OpenAI so we lump them
|
|
14828
|
-
* with output_tokens.
|
|
14829
|
-
*/
|
|
14830
|
-
handleCodexTurnEvent(item) {
|
|
14831
|
-
if (item.phase !== "completed") return;
|
|
14832
|
-
const raw = item.raw;
|
|
14833
|
-
const usage = raw.usage;
|
|
14834
|
-
if (!usage) return;
|
|
14835
|
-
const inputTokens = typeof usage.input_tokens === "number" ? usage.input_tokens : 0;
|
|
14836
|
-
const outputBase = typeof usage.output_tokens === "number" ? usage.output_tokens : 0;
|
|
14837
|
-
const reasoning = typeof usage.reasoning_output_tokens === "number" ? usage.reasoning_output_tokens : 0;
|
|
14838
|
-
const outputTokens = outputBase + reasoning;
|
|
14839
|
-
const tally = this.tokensByStory.get(item.agentId) ?? {
|
|
14840
|
-
input: 0,
|
|
14841
|
-
output: 0
|
|
14842
|
-
};
|
|
14843
|
-
tally.input += inputTokens;
|
|
14844
|
-
tally.output += outputTokens;
|
|
14845
|
-
this.tokensByStory.set(item.agentId, tally);
|
|
14846
|
-
emit({
|
|
14847
|
-
type: "token_usage",
|
|
14848
|
-
id: item.agentId,
|
|
14849
|
-
input_tokens: inputTokens,
|
|
14850
|
-
output_tokens: outputTokens
|
|
14851
|
-
});
|
|
14852
|
-
}
|
|
14853
|
-
handleAgentState(item) {
|
|
14854
|
-
if (item.phase === "running" && !this.startedStories.has(item.agentId)) {
|
|
14855
|
-
this.startedStories.add(item.agentId);
|
|
14856
|
-
emit({ type: "story_start", id: item.agentId, title: item.agentId });
|
|
14857
|
-
}
|
|
14858
|
-
if (item.phase === "waiting" && item.detail?.includes("retrying")) {
|
|
14859
|
-
const count = (this.retryCounts.get(item.agentId) ?? 0) + 1;
|
|
14860
|
-
this.retryCounts.set(item.agentId, count);
|
|
14861
|
-
emit({ type: "story_retry", id: item.agentId, attempt: count });
|
|
14862
|
-
}
|
|
14863
|
-
}
|
|
14864
|
-
handleModelMessage(source, item) {
|
|
14865
|
-
const agentId = source.agentId;
|
|
14866
|
-
if (typeof agentId !== "string") return;
|
|
14867
|
-
const json = item.toJSON();
|
|
14868
|
-
const text = json.content?.[0]?.text ?? "";
|
|
14869
|
-
if (!text.trim()) return;
|
|
14870
|
-
emitMultiline(agentId, text);
|
|
14871
|
-
}
|
|
14872
|
-
handleToolCall(source, item) {
|
|
14873
|
-
const agentId = source.agentId;
|
|
14874
|
-
if (typeof agentId !== "string") return;
|
|
14875
|
-
emitMultiline(agentId, `[tool_call] ${item.name} ${item.args}`);
|
|
14876
|
-
}
|
|
14877
|
-
handleToolResult(source, item) {
|
|
14878
|
-
const agentId = source.agentId;
|
|
14879
|
-
if (typeof agentId !== "string") return;
|
|
14880
|
-
const json = item.toJSON();
|
|
14881
|
-
const text = json.output?.[0]?.text ?? "";
|
|
14882
|
-
emitMultiline(agentId, `[tool_result ${json.call_id}] ${text}`);
|
|
14883
|
-
}
|
|
14884
|
-
};
|
|
14885
|
-
function emitMultiline(agentId, text) {
|
|
14886
|
-
if (!text) return;
|
|
14887
|
-
const lines = text.split("\n");
|
|
14888
|
-
for (const line of lines) {
|
|
14889
|
-
if (line.length === 0 && lines.length === 1) continue;
|
|
14890
|
-
emit({ type: "story_log", id: agentId, line });
|
|
14891
|
-
}
|
|
14892
|
-
}
|
|
14893
14905
|
function tokenizeForHints(text) {
|
|
14894
14906
|
const seen = /* @__PURE__ */ new Set();
|
|
14895
14907
|
const out = [];
|