@oh-my-pi/pi-coding-agent 16.1.15 → 16.1.17
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/CHANGELOG.md +78 -0
- package/dist/cli.js +3531 -3812
- package/dist/types/auto-thinking/classifier.d.ts +4 -2
- package/dist/types/cli/args.d.ts +2 -5
- package/dist/types/cli/flag-tables.d.ts +2 -2
- package/dist/types/cli/session-picker.d.ts +4 -2
- package/dist/types/commands/launch.d.ts +1 -1
- package/dist/types/config/model-discovery.d.ts +1 -0
- package/dist/types/config/model-registry.d.ts +4 -0
- package/dist/types/config/settings-schema.d.ts +12 -1
- package/dist/types/eval/agent-bridge.d.ts +19 -0
- package/dist/types/eval/js/shared/helpers.d.ts +1 -13
- package/dist/types/eval/js/shared/types.d.ts +1 -1
- package/dist/types/eval/js/worker-protocol.d.ts +1 -1
- package/dist/types/eval/py/executor.d.ts +1 -1
- package/dist/types/extensibility/plugins/legacy-pi-compat.d.ts +22 -7
- package/dist/types/extensibility/plugins/loader.d.ts +16 -9
- package/dist/types/extensibility/tool-event-input.d.ts +2 -0
- package/dist/types/hindsight/content.d.ts +2 -10
- package/dist/types/internal-urls/local-protocol.d.ts +18 -1
- package/dist/types/main.d.ts +2 -0
- package/dist/types/modes/components/chat-transcript-builder.d.ts +2 -0
- package/dist/types/modes/components/custom-editor.d.ts +3 -0
- package/dist/types/modes/components/plugin-settings.d.ts +5 -0
- package/dist/types/modes/components/session-selector.d.ts +25 -0
- package/dist/types/modes/components/status-line/types.d.ts +1 -0
- package/dist/types/modes/controllers/command-controller.d.ts +2 -0
- package/dist/types/modes/controllers/input-controller.d.ts +14 -0
- package/dist/types/modes/controllers/selector-controller.d.ts +11 -0
- package/dist/types/session/agent-session.d.ts +6 -6
- package/dist/types/session/provider-image-budget.d.ts +3 -0
- package/dist/types/session/session-context.d.ts +6 -5
- package/dist/types/task/isolation-runner.d.ts +128 -0
- package/dist/types/task/parallel.d.ts +4 -0
- package/dist/types/task/worktree.d.ts +14 -1
- package/dist/types/thinking.d.ts +23 -1
- package/dist/types/tiny/title-client.d.ts +2 -2
- package/dist/types/tools/eval-render.d.ts +3 -0
- package/dist/types/tools/eval.d.ts +11 -17
- package/dist/types/tools/todo.d.ts +26 -28
- package/dist/types/tui/output-block.d.ts +8 -0
- package/dist/types/utils/image-resize.d.ts +2 -0
- package/dist/types/utils/tools-manager.d.ts +2 -0
- package/dist/types/web/search/providers/exa.d.ts +2 -0
- package/package.json +12 -12
- package/scripts/build-binary.ts +18 -4
- package/src/auto-thinking/classifier.ts +7 -2
- package/src/cli/args.ts +4 -5
- package/src/cli/flag-tables.ts +3 -3
- package/src/cli/gallery-fixtures/interaction.ts +6 -9
- package/src/cli/gallery-fixtures/shell.ts +15 -23
- package/src/cli/profile-alias.ts +38 -7
- package/src/cli/session-picker.ts +17 -3
- package/src/cli/usage-cli.ts +5 -1
- package/src/commands/launch.ts +3 -3
- package/src/config/model-discovery.ts +59 -8
- package/src/config/model-registry.ts +74 -3
- package/src/config/settings-schema.ts +13 -1
- package/src/discovery/omp-extension-roots.ts +1 -3
- package/src/edit/renderer.ts +34 -12
- package/src/eval/__tests__/agent-bridge.test.ts +462 -3
- package/src/eval/__tests__/helpers-local-roots.test.ts +2 -5
- package/src/eval/__tests__/julia-prelude.test.ts +1 -30
- package/src/eval/__tests__/prelude-agent.test.ts +42 -8
- package/src/eval/agent-bridge.ts +301 -71
- package/src/eval/jl/prelude.jl +32 -227
- package/src/eval/jl/runner.jl +38 -12
- package/src/eval/js/shared/helpers.ts +1 -114
- package/src/eval/js/shared/prelude.txt +13 -27
- package/src/eval/js/shared/runtime.ts +0 -6
- package/src/eval/js/shared/types.ts +1 -1
- package/src/eval/js/worker-protocol.ts +1 -1
- package/src/eval/py/__tests__/prelude.test.ts +13 -0
- package/src/eval/py/executor.ts +1 -1
- package/src/eval/py/prelude.py +47 -105
- package/src/eval/py/runner.py +0 -6
- package/src/eval/rb/prelude.rb +21 -189
- package/src/eval/rb/runner.rb +116 -9
- package/src/export/html/tool-views.generated.js +29 -29
- package/src/extensibility/extensions/wrapper.ts +3 -2
- package/src/extensibility/hooks/tool-wrapper.ts +4 -3
- package/src/extensibility/plugins/legacy-pi-compat.ts +40 -8
- package/src/extensibility/plugins/loader.ts +71 -23
- package/src/extensibility/plugins/marketplace/manager.ts +134 -0
- package/src/extensibility/tool-event-input.ts +57 -0
- package/src/hindsight/content.ts +21 -12
- package/src/internal-urls/docs-index.generated.txt +1 -1
- package/src/internal-urls/local-protocol.ts +100 -53
- package/src/main.ts +15 -4
- package/src/mcp/tool-bridge.ts +27 -2
- package/src/mnemopi/state.ts +5 -2
- package/src/modes/acp/acp-event-mapper.ts +7 -2
- package/src/modes/components/agent-transcript-viewer.ts +193 -41
- package/src/modes/components/chat-transcript-builder.ts +6 -0
- package/src/modes/components/custom-editor.test.ts +18 -1
- package/src/modes/components/custom-editor.ts +77 -45
- package/src/modes/components/hook-editor.ts +15 -2
- package/src/modes/components/plugin-settings.ts +7 -1
- package/src/modes/components/session-selector.ts +143 -29
- package/src/modes/components/settings-selector.ts +2 -2
- package/src/modes/components/status-line/component.ts +52 -8
- package/src/modes/components/status-line/segments.ts +5 -1
- package/src/modes/components/status-line/types.ts +1 -0
- package/src/modes/components/welcome.ts +12 -14
- package/src/modes/controllers/command-controller.ts +21 -5
- package/src/modes/controllers/input-controller.ts +115 -3
- package/src/modes/controllers/selector-controller.ts +19 -1
- package/src/modes/interactive-mode.ts +3 -3
- package/src/modes/rpc/rpc-mode.ts +6 -0
- package/src/modes/utils/copy-targets.ts +7 -2
- package/src/modes/utils/ui-helpers.ts +3 -3
- package/src/prompts/system/system-prompt.md +3 -3
- package/src/prompts/system/workflow-notice.md +3 -3
- package/src/prompts/tools/bash.md +16 -0
- package/src/prompts/tools/eval.md +19 -19
- package/src/prompts/tools/todo.md +1 -1
- package/src/sdk.ts +8 -10
- package/src/session/agent-session.ts +422 -97
- package/src/session/provider-image-budget.ts +86 -0
- package/src/session/session-context.ts +14 -7
- package/src/session/session-storage.ts +24 -2
- package/src/session/snapcompact-inline.ts +19 -3
- package/src/slash-commands/builtin-registry.ts +0 -22
- package/src/slash-commands/helpers/usage-report.ts +9 -1
- package/src/task/index.ts +61 -207
- package/src/task/isolation-runner.ts +354 -0
- package/src/task/parallel.ts +6 -1
- package/src/task/worktree.ts +46 -9
- package/src/thinking.ts +29 -2
- package/src/tiny/title-client.ts +75 -21
- package/src/tools/ask.ts +44 -38
- package/src/tools/bash.ts +9 -2
- package/src/tools/browser/tab-worker.ts +1 -1
- package/src/tools/eval-render.ts +34 -27
- package/src/tools/eval.ts +100 -103
- package/src/tools/index.ts +8 -1
- package/src/tools/read.ts +136 -60
- package/src/tools/todo.ts +60 -64
- package/src/tui/code-cell.ts +1 -1
- package/src/tui/output-block.ts +11 -0
- package/src/utils/image-resize.ts +30 -0
- package/src/utils/tools-manager.ts +67 -10
- package/src/web/search/providers/exa.ts +85 -1
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import type { AgentMessage } from "@oh-my-pi/pi-agent-core";
|
|
4
|
-
import type { AssistantMessage } from "@oh-my-pi/pi-ai";
|
|
4
|
+
import type { AssistantMessage, UsageLimit, UsageReport } from "@oh-my-pi/pi-ai";
|
|
5
5
|
import { type Component, truncateToWidth, visibleWidth } from "@oh-my-pi/pi-tui";
|
|
6
6
|
import { getProjectDir } from "@oh-my-pi/pi-utils";
|
|
7
7
|
import { $ } from "bun";
|
|
8
8
|
import { settings } from "../../../config/settings";
|
|
9
9
|
import type { AgentSession } from "../../../session/agent-session";
|
|
10
|
+
import type { OAuthAccountIdentity } from "../../../session/auth-storage";
|
|
11
|
+
import { limitMatchesActiveAccount } from "../../../slash-commands/helpers/active-oauth-account";
|
|
10
12
|
import * as git from "../../../utils/git";
|
|
11
13
|
import { getSessionAccentAnsi, getSessionAccentHex } from "../../../utils/session-color";
|
|
12
14
|
import { sanitizeStatusText } from "../../shared";
|
|
@@ -207,11 +209,13 @@ export class StatusLineComponent implements Component {
|
|
|
207
209
|
#lastTokensPerSecond: number | null = null;
|
|
208
210
|
#lastTokensPerSecondTimestamp: number | null = null;
|
|
209
211
|
|
|
210
|
-
//
|
|
212
|
+
// Provider usage caching (5-min TTL, OAuth/sub only)
|
|
211
213
|
#cachedUsage: {
|
|
214
|
+
tier?: string;
|
|
212
215
|
fiveHour?: { percent: number; resetMinutes?: number };
|
|
213
216
|
sevenDay?: { percent: number; resetHours?: number };
|
|
214
217
|
} | null = null;
|
|
218
|
+
#cachedUsageContextKey: string | null = null;
|
|
215
219
|
#usageFetchedAt = 0;
|
|
216
220
|
#usageInFlight = false;
|
|
217
221
|
#usageStartTimer: Timer | null = null;
|
|
@@ -531,15 +535,28 @@ export class StatusLineComponent implements Component {
|
|
|
531
535
|
return null;
|
|
532
536
|
}
|
|
533
537
|
|
|
538
|
+
#getUsageContextKey(session: AgentSession): string {
|
|
539
|
+
const activeProvider = session.state.model?.provider ?? session.model?.provider ?? "";
|
|
540
|
+
if (!activeProvider) return "";
|
|
541
|
+
const identity = session.modelRegistry?.authStorage?.getOAuthAccountIdentity(activeProvider, session.sessionId);
|
|
542
|
+
return [activeProvider, identity?.accountId ?? "", identity?.email ?? "", identity?.projectId ?? ""].join("\0");
|
|
543
|
+
}
|
|
544
|
+
|
|
534
545
|
/**
|
|
535
546
|
* Startup redraws only arm a short-delayed task; timeout releases the render
|
|
536
547
|
* cadence while a late successful fetch can still refresh the cached segment.
|
|
537
548
|
*/
|
|
538
549
|
refreshUsageInBackground(): void {
|
|
539
550
|
const now = Date.now();
|
|
551
|
+
const session = this.session;
|
|
552
|
+
const usageContextKey = this.#getUsageContextKey(session);
|
|
553
|
+
if (this.#cachedUsageContextKey !== usageContextKey) {
|
|
554
|
+
this.#cachedUsage = null;
|
|
555
|
+
this.#usageFetchedAt = 0;
|
|
556
|
+
this.#cachedUsageContextKey = usageContextKey;
|
|
557
|
+
}
|
|
540
558
|
if (this.#usageInFlight || this.#usageStartTimer) return;
|
|
541
559
|
if (this.#usageFetchedAt > 0 && now - this.#usageFetchedAt < 5 * 60_000) return;
|
|
542
|
-
const session = this.session;
|
|
543
560
|
const fetcher = (session as { fetchUsageReports?: (signal?: AbortSignal) => Promise<unknown> }).fetchUsageReports;
|
|
544
561
|
if (typeof fetcher !== "function") return;
|
|
545
562
|
this.#usageInFlight = true;
|
|
@@ -572,7 +589,12 @@ export class StatusLineComponent implements Component {
|
|
|
572
589
|
|
|
573
590
|
#applyUsageRefreshReports(session: AgentSession, reports: unknown): void {
|
|
574
591
|
if (this.#disposed || this.session !== session) return;
|
|
575
|
-
|
|
592
|
+
const activeProvider = session.state.model?.provider ?? session.model?.provider;
|
|
593
|
+
const activeIdentity =
|
|
594
|
+
activeProvider && session.modelRegistry?.authStorage
|
|
595
|
+
? session.modelRegistry.authStorage.getOAuthAccountIdentity(activeProvider, session.sessionId)
|
|
596
|
+
: undefined;
|
|
597
|
+
this.#cachedUsage = this.#normalizeUsageReports(reports, activeProvider, activeIdentity);
|
|
576
598
|
this.#usageFetchedAt = Date.now();
|
|
577
599
|
}
|
|
578
600
|
|
|
@@ -599,20 +621,35 @@ export class StatusLineComponent implements Component {
|
|
|
599
621
|
}
|
|
600
622
|
}
|
|
601
623
|
|
|
602
|
-
#normalizeUsageReports(
|
|
624
|
+
#normalizeUsageReports(
|
|
625
|
+
reports: unknown,
|
|
626
|
+
activeProvider?: string,
|
|
627
|
+
activeIdentity?: OAuthAccountIdentity,
|
|
628
|
+
): {
|
|
629
|
+
tier?: string;
|
|
603
630
|
fiveHour?: { percent: number; resetMinutes?: number };
|
|
604
631
|
sevenDay?: { percent: number; resetHours?: number };
|
|
605
632
|
} | null {
|
|
606
633
|
if (!Array.isArray(reports)) return null;
|
|
607
634
|
let fiveHour: { percent: number; resetMinutes?: number } | undefined;
|
|
608
635
|
let sevenDay: { percent: number; resetHours?: number } | undefined;
|
|
636
|
+
let fiveHourTier: string | undefined;
|
|
637
|
+
let sevenDayTier: string | undefined;
|
|
609
638
|
const now = Date.now();
|
|
610
639
|
for (const report of reports) {
|
|
611
640
|
if (!report || typeof report !== "object") continue;
|
|
641
|
+
const provider = (report as { provider?: unknown }).provider;
|
|
642
|
+
if (activeProvider && provider !== activeProvider) continue;
|
|
612
643
|
const limits = (report as { limits?: unknown }).limits;
|
|
613
644
|
if (!Array.isArray(limits)) continue;
|
|
614
645
|
for (const limit of limits) {
|
|
615
646
|
if (!limit || typeof limit !== "object") continue;
|
|
647
|
+
if (
|
|
648
|
+
activeIdentity &&
|
|
649
|
+
!limitMatchesActiveAccount(report as UsageReport, limit as UsageLimit, activeIdentity)
|
|
650
|
+
) {
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
616
653
|
const l = limit as {
|
|
617
654
|
scope?: { windowId?: string; tier?: string };
|
|
618
655
|
window?: { resetsAt?: number };
|
|
@@ -623,23 +660,30 @@ export class StatusLineComponent implements Component {
|
|
|
623
660
|
const windowId = l.scope?.windowId;
|
|
624
661
|
const tier = l.scope?.tier;
|
|
625
662
|
const resetsAt = l.window?.resetsAt;
|
|
626
|
-
|
|
663
|
+
// Accept tiered limits, but prefer untiered (backward compat with Anthropic).
|
|
664
|
+
// An untiered limit always replaces a tiered one; among same-tieredness, first wins.
|
|
665
|
+
if (windowId === "5h" && (!fiveHour || (fiveHourTier !== undefined && !tier))) {
|
|
627
666
|
fiveHour = {
|
|
628
667
|
percent: fraction * 100,
|
|
629
668
|
resetMinutes:
|
|
630
669
|
typeof resetsAt === "number" ? Math.max(0, Math.round((resetsAt - now) / 60_000)) : undefined,
|
|
631
670
|
};
|
|
632
|
-
|
|
671
|
+
fiveHourTier = tier || undefined;
|
|
672
|
+
}
|
|
673
|
+
if (windowId === "7d" && (!sevenDay || (sevenDayTier !== undefined && !tier))) {
|
|
633
674
|
sevenDay = {
|
|
634
675
|
percent: fraction * 100,
|
|
635
676
|
resetHours:
|
|
636
677
|
typeof resetsAt === "number" ? Math.max(0, Math.round((resetsAt - now) / 3_600_000)) : undefined,
|
|
637
678
|
};
|
|
679
|
+
sevenDayTier = tier || undefined;
|
|
638
680
|
}
|
|
639
681
|
}
|
|
640
682
|
}
|
|
641
683
|
if (!fiveHour && !sevenDay) return null;
|
|
642
|
-
|
|
684
|
+
// Single compact label; prefer the five-hour tier if displayed windows ever disagree.
|
|
685
|
+
const effectiveTier = fiveHourTier ?? sevenDayTier;
|
|
686
|
+
return { tier: effectiveTier, fiveHour, sevenDay };
|
|
643
687
|
}
|
|
644
688
|
|
|
645
689
|
/**
|
|
@@ -4,7 +4,7 @@ import { ThinkingLevel } from "@oh-my-pi/pi-agent-core";
|
|
|
4
4
|
import { TERMINAL } from "@oh-my-pi/pi-tui";
|
|
5
5
|
import { formatDuration, formatNumber, getProjectDir, pathIsWithin, relativePathWithinRoot } from "@oh-my-pi/pi-utils";
|
|
6
6
|
import { type ThemeColor, theme } from "../../../modes/theme/theme";
|
|
7
|
-
import { shortenPath } from "../../../tools/render-utils";
|
|
7
|
+
import { shortenPath, TRUNCATE_LENGTHS, truncateToWidth } from "../../../tools/render-utils";
|
|
8
8
|
import { getSessionAccentAnsi, getSessionAccentHex } from "../../../utils/session-color";
|
|
9
9
|
import { sanitizeStatusText } from "../../shared";
|
|
10
10
|
import { formatContextUsage, getContextUsageLevel, getContextUsageThemeColor } from "./context-thresholds";
|
|
@@ -551,6 +551,10 @@ const usageSegment: StatusLineSegment = {
|
|
|
551
551
|
return { content: "", visible: false };
|
|
552
552
|
}
|
|
553
553
|
const parts: string[] = [];
|
|
554
|
+
if (u.tier) {
|
|
555
|
+
const tier = truncateToWidth(sanitizeStatusText(u.tier), TRUNCATE_LENGTHS.SHORT);
|
|
556
|
+
if (tier) parts.push(theme.fg("accent", tier));
|
|
557
|
+
}
|
|
554
558
|
if (u.fiveHour) {
|
|
555
559
|
const pct = u.fiveHour.percent;
|
|
556
560
|
const pctText = theme.fg(pickUsageColor(pct), `${Math.round(pct)}%`);
|
|
@@ -95,24 +95,23 @@ export function renderWelcomeTip(tip: string, boxWidth: number, phase = 0): stri
|
|
|
95
95
|
const wrappedBody = wrapTextWithAnsi(replaceTabs(body), bodyBudget);
|
|
96
96
|
if (wrappedBody.length === 0) return [];
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const italic = "\x1b[3m";
|
|
102
|
-
const dim = "\x1b[2m";
|
|
103
|
-
const reset = "\x1b[0m";
|
|
98
|
+
// Pull both colors from the active theme so the line stays readable on light
|
|
99
|
+
// themes; the previous hardcoded `#b48cff` / `#9ccfff` pastels (plus a manual
|
|
100
|
+
// `\x1b[2m` dim on the body) dropped to ~1.5:1 contrast on a white background.
|
|
104
101
|
const continuationIndent = padding(labelWidth);
|
|
102
|
+
const styledLabel = theme.fg("customMessageLabel", label);
|
|
105
103
|
|
|
106
|
-
const lines = wrappedBody.map((line, index) =>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
);
|
|
104
|
+
const lines = wrappedBody.map((line, index) => {
|
|
105
|
+
const styledBody = theme.fg("muted", line);
|
|
106
|
+
const content = index === 0 ? `${styledLabel}${styledBody}` : `${continuationIndent}${styledBody}`;
|
|
107
|
+
return ` ${theme.italic(content)}`;
|
|
108
|
+
});
|
|
111
109
|
|
|
112
110
|
if (isNew) {
|
|
113
111
|
// Append the rainbow tag to the final body line when it fits within the
|
|
114
112
|
// box; otherwise drop it onto its own indented continuation line so the
|
|
115
113
|
// styled glyphs never overflow or reflow the wrapped body.
|
|
114
|
+
const encoding: ColorEncoding = TERMINAL.trueColor ? "ansi-16m" : "ansi-256";
|
|
116
115
|
const tag = renderNewTag(phase, encoding);
|
|
117
116
|
const tagWidth = 1 + visibleWidth(NEW_TAG_TEXT); // 1 = space separator
|
|
118
117
|
const lastLine = lines[lines.length - 1];
|
|
@@ -330,7 +329,6 @@ export class WelcomeComponent implements Component {
|
|
|
330
329
|
// Right column
|
|
331
330
|
const rightLines = [
|
|
332
331
|
` ${theme.bold(theme.fg("accent", "Tips"))}`,
|
|
333
|
-
` ${theme.fg("dim", "?")}${theme.fg("muted", " for keyboard shortcuts")}`,
|
|
334
332
|
` ${theme.fg("dim", "#")}${theme.fg("muted", " for prompt actions")}`,
|
|
335
333
|
` ${theme.fg("dim", "/")}${theme.fg("muted", " for commands")}`,
|
|
336
334
|
` ${theme.fg("dim", "!")}${theme.fg("muted", " to run bash")}`,
|
|
@@ -393,8 +391,8 @@ export class WelcomeComponent implements Component {
|
|
|
393
391
|
}
|
|
394
392
|
|
|
395
393
|
/**
|
|
396
|
-
* Render the per-instance tip line:
|
|
397
|
-
*
|
|
394
|
+
* Render the per-instance tip line: the `customMessageLabel`-themed `Tip:`
|
|
395
|
+
* label followed by a `muted` body, the whole line italicized. Returns `[]`
|
|
398
396
|
* when no tip is available or the box is too narrow to be useful.
|
|
399
397
|
*/
|
|
400
398
|
#renderTip(boxWidth: number): string[] {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
type UsageReport,
|
|
11
11
|
} from "@oh-my-pi/pi-ai";
|
|
12
12
|
import { Loader, Markdown, padding, Spacer, Text, visibleWidth } from "@oh-my-pi/pi-tui";
|
|
13
|
-
import { formatDuration, Snowflake } from "@oh-my-pi/pi-utils";
|
|
13
|
+
import { formatDuration, Snowflake, sanitizeText } from "@oh-my-pi/pi-utils";
|
|
14
14
|
import { shouldEnableAppendOnlyContext } from "../../config/append-only-context-mode";
|
|
15
15
|
import { type LoadedCustomShare, loadCustomShare } from "../../export/custom-share";
|
|
16
16
|
import { shareSession } from "../../export/share";
|
|
@@ -44,7 +44,7 @@ import { formatShakeSummary, type ShakeMode, type ShakeResult } from "../../sess
|
|
|
44
44
|
import { limitMatchesActiveAccount } from "../../slash-commands/helpers/active-oauth-account";
|
|
45
45
|
import { outputMeta } from "../../tools/output-meta";
|
|
46
46
|
import { resolveToCwd, stripOuterDoubleQuotes } from "../../tools/path-utils";
|
|
47
|
-
import { replaceTabs } from "../../tools/render-utils";
|
|
47
|
+
import { replaceTabs, truncateToWidth } from "../../tools/render-utils";
|
|
48
48
|
import { getChangelogPath, parseChangelog } from "../../utils/changelog";
|
|
49
49
|
import { copyToClipboard } from "../../utils/clipboard";
|
|
50
50
|
import { openPath } from "../../utils/open";
|
|
@@ -1172,6 +1172,11 @@ export class CommandController {
|
|
|
1172
1172
|
}
|
|
1173
1173
|
|
|
1174
1174
|
async handleHandoffCommand(customInstructions?: string): Promise<void> {
|
|
1175
|
+
if (this.ctx.session.isStreaming) {
|
|
1176
|
+
this.ctx.showWarning("Wait for the current response to finish or abort it before handing off.");
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1175
1180
|
const entries = this.ctx.sessionManager.getEntries();
|
|
1176
1181
|
const messageCount = entries.filter(e => e.type === "message").length;
|
|
1177
1182
|
|
|
@@ -1518,7 +1523,7 @@ function resolveColumnWidth(count: number, available: number, trailing: number):
|
|
|
1518
1523
|
return ideal;
|
|
1519
1524
|
}
|
|
1520
1525
|
|
|
1521
|
-
function renderUsageReports(
|
|
1526
|
+
export function renderUsageReports(
|
|
1522
1527
|
reports: UsageReport[],
|
|
1523
1528
|
uiTheme: typeof theme,
|
|
1524
1529
|
nowMs: number,
|
|
@@ -1578,6 +1583,15 @@ function renderUsageReports(
|
|
|
1578
1583
|
lines.push(` ${uiTheme.fg("accent", "in use by this session:")} ${activeAccountLabel}`);
|
|
1579
1584
|
}
|
|
1580
1585
|
|
|
1586
|
+
// Provider-wide disclaimers (e.g. "OMP-observed spend only") render once
|
|
1587
|
+
// above the per-account sections instead of duplicating onto every limit.
|
|
1588
|
+
const providerNotes = [...new Set(providerReports.flatMap(report => report.notes ?? []))];
|
|
1589
|
+
if (providerNotes.length > 0) {
|
|
1590
|
+
lines.push(
|
|
1591
|
+
` ${uiTheme.fg("dim", replaceTabs(truncateToWidth(sanitizeText(providerNotes.map(n => n.replace(/[\r\n]+/g, " ")).join(" • ")), 110)))}`.trimEnd(),
|
|
1592
|
+
);
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1581
1595
|
const resetAccountLines: string[] = [];
|
|
1582
1596
|
for (const report of providerReports) {
|
|
1583
1597
|
const count = report.resetCredits?.availableCount ?? 0;
|
|
@@ -1646,9 +1660,11 @@ function renderUsageReports(
|
|
|
1646
1660
|
if (resetText) {
|
|
1647
1661
|
lines.push(` ${uiTheme.fg("dim", resetText)}`.trimEnd());
|
|
1648
1662
|
}
|
|
1649
|
-
const notes = sortedLimits.flatMap(limit => limit.notes ?? []);
|
|
1663
|
+
const notes = [...new Set(sortedLimits.flatMap(limit => limit.notes ?? []))];
|
|
1650
1664
|
if (notes.length > 0) {
|
|
1651
|
-
lines.push(
|
|
1665
|
+
lines.push(
|
|
1666
|
+
` ${uiTheme.fg("dim", replaceTabs(truncateToWidth(sanitizeText(notes.map(n => n.replace(/[\r\n]+/g, " ")).join(" • ")), 110)))}`.trimEnd(),
|
|
1667
|
+
);
|
|
1652
1668
|
}
|
|
1653
1669
|
}
|
|
1654
1670
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as fs from "node:fs/promises";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
3
4
|
import type { ImageContent } from "@oh-my-pi/pi-ai";
|
|
4
5
|
import { type AutocompleteProvider, matchesKey, type SlashCommand } from "@oh-my-pi/pi-tui";
|
|
5
6
|
import { $env, isEnoent, logger, sanitizeText } from "@oh-my-pi/pi-utils";
|
|
@@ -19,6 +20,7 @@ import { isTinyTitleLocalModelKey } from "../../tiny/models";
|
|
|
19
20
|
import { isLowSignalTitleInput } from "../../tiny/text";
|
|
20
21
|
import { tinyTitleClient } from "../../tiny/title-client";
|
|
21
22
|
import type { TinyTitleProgressEvent } from "../../tiny/title-protocol";
|
|
23
|
+
import { resolveReadPath } from "../../tools/path-utils";
|
|
22
24
|
import { shortenPath, TRUNCATE_LENGTHS, truncateToWidth } from "../../tools/render-utils";
|
|
23
25
|
import { copyToClipboard, readImageFromClipboard, readTextFromClipboard } from "../../utils/clipboard";
|
|
24
26
|
import { EnhancedPasteController } from "../../utils/enhanced-paste";
|
|
@@ -27,6 +29,39 @@ import { ensureSupportedImageInput, ImageInputTooLargeError, loadImageInput } fr
|
|
|
27
29
|
import { resizeImage } from "../../utils/image-resize";
|
|
28
30
|
import { generateSessionTitle, setSessionTerminalTitle } from "../../utils/title-generator";
|
|
29
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Slash commands that may carry secrets in their arguments should never be
|
|
34
|
+
* persisted to history.
|
|
35
|
+
*
|
|
36
|
+
* - /login accepts three callback forms (redirect URL, query string, raw auth
|
|
37
|
+
* code) — all can contain OAuth code=/state= params.
|
|
38
|
+
* - /join <link> carries a 32-byte room key and optional write token.
|
|
39
|
+
* - /mcp add --token <token> carries a bearer token.
|
|
40
|
+
*
|
|
41
|
+
* The command name is extracted the same way as parseSlashCommand() — splitting
|
|
42
|
+
* on the earliest whitespace or colon — so /login:?code=... is correctly matched.
|
|
43
|
+
*/
|
|
44
|
+
export function shouldSkipHistory(slashText: string): boolean {
|
|
45
|
+
if (!slashText.startsWith("/")) return false;
|
|
46
|
+
const body = slashText.slice(1);
|
|
47
|
+
// Match parseSlashCommand: split on earliest whitespace or colon.
|
|
48
|
+
const firstWs = body.search(/\s/);
|
|
49
|
+
const firstColon = body.indexOf(":");
|
|
50
|
+
const sep = firstWs === -1 ? firstColon : firstColon === -1 ? firstWs : Math.min(firstWs, firstColon);
|
|
51
|
+
const name = sep === -1 ? body : body.slice(0, sep);
|
|
52
|
+
const hasArgs = sep !== -1;
|
|
53
|
+
// /login <anything> — parseCallbackInput() accepts redirect URLs, query
|
|
54
|
+
// strings (?code=...), and raw auth codes, all of which carry secrets.
|
|
55
|
+
if (name === "login" && hasArgs) return true;
|
|
56
|
+
// /join <link> — the link carries the 32-byte room key and write token.
|
|
57
|
+
if (name === "join" && hasArgs) return true;
|
|
58
|
+
if (name === "mcp") {
|
|
59
|
+
const args = body.slice(sep + 1).trim();
|
|
60
|
+
return args.startsWith("add") && /--token\s/.test(args);
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
30
65
|
interface Expandable {
|
|
31
66
|
setExpanded(expanded: boolean): void;
|
|
32
67
|
}
|
|
@@ -69,6 +104,20 @@ function wrapPasteInAttachmentBlock(content: string): string {
|
|
|
69
104
|
return `<attachment>\n${content}\n</attachment>`;
|
|
70
105
|
}
|
|
71
106
|
|
|
107
|
+
const FILE_URI_REGEX = /^file:\/\//i;
|
|
108
|
+
|
|
109
|
+
function pastedFileAttachmentExtension(sourcePath: string): string {
|
|
110
|
+
const ext = path.extname(sourcePath);
|
|
111
|
+
const bareExt = ext.slice(1);
|
|
112
|
+
if (!bareExt || bareExt.length > 32 || !/^[a-z0-9][a-z0-9._-]*$/i.test(bareExt)) return "";
|
|
113
|
+
return ext;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function resolvePastedFilePath(filePath: string, cwd: string): string {
|
|
117
|
+
if (FILE_URI_REGEX.test(filePath)) return fileURLToPath(filePath);
|
|
118
|
+
return resolveReadPath(filePath, cwd);
|
|
119
|
+
}
|
|
120
|
+
|
|
72
121
|
const TINY_TITLE_PROGRESS_DONE_TTL_MS = 3_000;
|
|
73
122
|
// A cached model fires its file-load events in a short burst and then goes silent
|
|
74
123
|
// while onnxruntime builds the session; a genuine download keeps streaming progress
|
|
@@ -104,8 +153,8 @@ export class InputController {
|
|
|
104
153
|
// (>= LEFT_DOUBLE_TAP_MAX_GAP_MS) starts a fresh sequence. See
|
|
105
154
|
// #detectLeftDoubleTap.
|
|
106
155
|
#leftTapCount = 0;
|
|
107
|
-
// Sequential index for `local://attachment-N` references created by
|
|
108
|
-
//
|
|
156
|
+
// Sequential index for `local://attachment-N` references created by large-paste and
|
|
157
|
+
// pasted-file attachments. Seeded from 0 and bumped past existing attachment files.
|
|
109
158
|
#attachmentCounter = 0;
|
|
110
159
|
|
|
111
160
|
#showTinyTitleDownloadProgress(modelKey: string): void {
|
|
@@ -343,6 +392,7 @@ export class InputController {
|
|
|
343
392
|
);
|
|
344
393
|
this.ctx.editor.onPasteImage = () => this.handleImagePaste();
|
|
345
394
|
this.ctx.editor.onPasteImagePath = path => this.handleImagePathPaste(path);
|
|
395
|
+
this.ctx.editor.onPasteFilePath = path => this.handleFilePathPaste(path);
|
|
346
396
|
this.ctx.editor.setActionKeys(
|
|
347
397
|
"app.clipboard.pasteTextRaw",
|
|
348
398
|
this.ctx.keybindings.getKeys("app.clipboard.pasteTextRaw"),
|
|
@@ -572,10 +622,14 @@ export class InputController {
|
|
|
572
622
|
ctx: this.ctx,
|
|
573
623
|
});
|
|
574
624
|
if (slashResult === true) {
|
|
625
|
+
if (!shouldSkipHistory(text)) this.ctx.editor.addToHistory(text);
|
|
575
626
|
return;
|
|
576
627
|
}
|
|
577
628
|
if (typeof slashResult === "string") {
|
|
578
|
-
// Command handled but returned remaining text to use as prompt
|
|
629
|
+
// Command handled but returned remaining text to use as prompt.
|
|
630
|
+
// Record the original slash command text so Up Arrow recalls
|
|
631
|
+
// "/loop 10 fix bug" rather than just "fix bug".
|
|
632
|
+
if (!shouldSkipHistory(text)) this.ctx.editor.addToHistory(text);
|
|
579
633
|
text = slashResult;
|
|
580
634
|
}
|
|
581
635
|
|
|
@@ -1011,9 +1065,13 @@ export class InputController {
|
|
|
1011
1065
|
ctx: this.ctx,
|
|
1012
1066
|
});
|
|
1013
1067
|
if (slashResult === true) {
|
|
1068
|
+
if (!shouldSkipHistory(text)) this.ctx.editor.addToHistory(text);
|
|
1014
1069
|
return;
|
|
1015
1070
|
}
|
|
1016
1071
|
if (typeof slashResult === "string") {
|
|
1072
|
+
// Command handled but returned remaining text to use as prompt.
|
|
1073
|
+
// Record the original slash command text so Up Arrow recalls it.
|
|
1074
|
+
if (!shouldSkipHistory(text)) this.ctx.editor.addToHistory(text);
|
|
1017
1075
|
text = slashResult;
|
|
1018
1076
|
}
|
|
1019
1077
|
|
|
@@ -1203,6 +1261,37 @@ export class InputController {
|
|
|
1203
1261
|
}
|
|
1204
1262
|
}
|
|
1205
1263
|
|
|
1264
|
+
async handleFilePathPaste(filePath: string): Promise<void> {
|
|
1265
|
+
try {
|
|
1266
|
+
const resolvedPath = resolvePastedFilePath(filePath, this.ctx.sessionManager.getCwd());
|
|
1267
|
+
const stat = await Bun.file(resolvedPath).stat();
|
|
1268
|
+
if (!stat.isFile()) {
|
|
1269
|
+
this.ctx.editor.pasteText(filePath);
|
|
1270
|
+
this.ctx.ui.requestRender();
|
|
1271
|
+
this.ctx.showStatus("Pasted path is not a file");
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
const reference = await this.#attachExistingFileAsLocal(resolvedPath);
|
|
1276
|
+
this.ctx.editor.insertText(`${reference} `);
|
|
1277
|
+
this.ctx.ui.requestRender();
|
|
1278
|
+
this.ctx.showStatus(`Attached file as ${reference}`);
|
|
1279
|
+
} catch (error) {
|
|
1280
|
+
if (isEnoent(error)) {
|
|
1281
|
+
this.ctx.editor.pasteText(filePath);
|
|
1282
|
+
this.ctx.ui.requestRender();
|
|
1283
|
+
this.ctx.showStatus("Pasted file path was not found");
|
|
1284
|
+
return;
|
|
1285
|
+
}
|
|
1286
|
+
logger.warn("failed to attach pasted file path", {
|
|
1287
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1288
|
+
});
|
|
1289
|
+
this.ctx.editor.pasteText(filePath);
|
|
1290
|
+
this.ctx.ui.requestRender();
|
|
1291
|
+
this.ctx.showError("Failed to attach pasted file path — pasted path inline instead");
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1206
1295
|
async handleImagePathPaste(path: string): Promise<void> {
|
|
1207
1296
|
try {
|
|
1208
1297
|
const image = await loadImageInput({
|
|
@@ -1373,6 +1462,29 @@ export class InputController {
|
|
|
1373
1462
|
this.ctx.ui.requestRender();
|
|
1374
1463
|
}
|
|
1375
1464
|
|
|
1465
|
+
async #attachExistingFileAsLocal(sourcePath: string): Promise<string> {
|
|
1466
|
+
const localRoot = resolveLocalRoot({
|
|
1467
|
+
getArtifactsDir: () => this.ctx.sessionManager.getArtifactsDir(),
|
|
1468
|
+
getSessionId: () => this.ctx.sessionManager.getSessionId(),
|
|
1469
|
+
});
|
|
1470
|
+
await fs.mkdir(localRoot, { recursive: true });
|
|
1471
|
+
const ext = pastedFileAttachmentExtension(sourcePath);
|
|
1472
|
+
let name: string;
|
|
1473
|
+
let filePath: string;
|
|
1474
|
+
do {
|
|
1475
|
+
this.#attachmentCounter++;
|
|
1476
|
+
name = `attachment-${this.#attachmentCounter}${ext}`;
|
|
1477
|
+
filePath = path.join(localRoot, name);
|
|
1478
|
+
} while (await Bun.file(filePath).exists());
|
|
1479
|
+
|
|
1480
|
+
try {
|
|
1481
|
+
await fs.link(sourcePath, filePath);
|
|
1482
|
+
} catch {
|
|
1483
|
+
await fs.copyFile(sourcePath, filePath);
|
|
1484
|
+
}
|
|
1485
|
+
return `local://${name}`;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1376
1488
|
/**
|
|
1377
1489
|
* Save a large paste to the session's `local://` store and insert a clean `local://attachment-N`
|
|
1378
1490
|
* reference into the editor so the agent can `read` it on demand — instead of inlining the text or
|
|
@@ -84,6 +84,22 @@ export class SelectorController {
|
|
|
84
84
|
),
|
|
85
85
|
);
|
|
86
86
|
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Restore keyboard focus to whatever currently owns the editor slot. The
|
|
90
|
+
* slot can hold the editor itself or a hook selector/input/editor pushed
|
|
91
|
+
* in by `ExtensionUiController` — e.g. an approval prompt that fired while
|
|
92
|
+
* a fullscreen overlay was up. `overlayHandle.hide()` restores focus to
|
|
93
|
+
* the component focused when the overlay opened, which is stale in that
|
|
94
|
+
* case (the editor was swapped out): keys land on a hidden editor and the
|
|
95
|
+
* visible prompt receives nothing (issue #3349). Call this after the
|
|
96
|
+
* overlay hides to re-target focus at the visible slot owner.
|
|
97
|
+
*/
|
|
98
|
+
focusActiveEditorArea(): void {
|
|
99
|
+
const visible = this.ctx.editorContainer.children[0] ?? this.ctx.editor;
|
|
100
|
+
this.ctx.ui.setFocus(visible);
|
|
101
|
+
}
|
|
102
|
+
|
|
87
103
|
/**
|
|
88
104
|
* Shows a selector component in place of the editor.
|
|
89
105
|
* @param create Factory that receives a `done` callback and returns the component and focus target
|
|
@@ -109,7 +125,7 @@ export class SelectorController {
|
|
|
109
125
|
let overlayHandle: OverlayHandle | undefined;
|
|
110
126
|
const done = () => {
|
|
111
127
|
overlayHandle?.hide();
|
|
112
|
-
this.
|
|
128
|
+
this.focusActiveEditorArea();
|
|
113
129
|
this.ctx.ui.requestRender();
|
|
114
130
|
};
|
|
115
131
|
const selector = new SettingsSelectorComponent(
|
|
@@ -224,6 +240,7 @@ export class SelectorController {
|
|
|
224
240
|
});
|
|
225
241
|
dashboard.onClose = () => {
|
|
226
242
|
overlay.hide();
|
|
243
|
+
this.focusActiveEditorArea();
|
|
227
244
|
this.ctx.ui.requestRender();
|
|
228
245
|
};
|
|
229
246
|
dashboard.onRequestRender = () => {
|
|
@@ -251,6 +268,7 @@ export class SelectorController {
|
|
|
251
268
|
});
|
|
252
269
|
dashboard.onClose = () => {
|
|
253
270
|
overlay.hide();
|
|
271
|
+
this.focusActiveEditorArea();
|
|
254
272
|
this.ctx.ui.requestRender();
|
|
255
273
|
};
|
|
256
274
|
dashboard.onRequestRender = () => {
|
|
@@ -1441,9 +1441,9 @@ export class InteractiveMode implements InteractiveModeContext {
|
|
|
1441
1441
|
|
|
1442
1442
|
rebuildChatFromMessages(): void {
|
|
1443
1443
|
this.chatContainer.clear();
|
|
1444
|
-
//
|
|
1445
|
-
//
|
|
1446
|
-
const context = this.viewSession.buildTranscriptSessionContext();
|
|
1444
|
+
// Live display uses the compacted transcript tail; export/resume callers
|
|
1445
|
+
// can still request the full inline compaction history.
|
|
1446
|
+
const context = this.viewSession.buildTranscriptSessionContext({ collapseCompactedHistory: true });
|
|
1447
1447
|
this.renderSessionContext(context);
|
|
1448
1448
|
// During the pre-streaming window — after `startPendingSubmission` has
|
|
1449
1449
|
// optimistically rendered the user's message but before the user
|
|
@@ -1008,6 +1008,12 @@ export async function runRpcMode(
|
|
|
1008
1008
|
}
|
|
1009
1009
|
|
|
1010
1010
|
case "handoff": {
|
|
1011
|
+
// Resetting the agent mid-stream lets the live turn keep emitting into a
|
|
1012
|
+
// session that handoff has already torn down. Refuse while a prompt is in
|
|
1013
|
+
// flight (mirrors the TUI /handoff guard).
|
|
1014
|
+
if (session.isStreaming) {
|
|
1015
|
+
return error(id, "handoff", "Cannot hand off while a response is in progress");
|
|
1016
|
+
}
|
|
1011
1017
|
const result = await session.handoff(command.customInstructions);
|
|
1012
1018
|
return success(id, "handoff", result ? { savedPath: result.savedPath } : null);
|
|
1013
1019
|
}
|
|
@@ -127,8 +127,13 @@ export function extractQuoteBlocks(text: string): QuoteBlock[] {
|
|
|
127
127
|
|
|
128
128
|
function extractEvalCode(args: unknown): { code: string; language: string } | undefined {
|
|
129
129
|
if (!args || typeof args !== "object") return undefined;
|
|
130
|
-
const
|
|
131
|
-
|
|
130
|
+
const argsObj = args as { cells?: unknown; code?: unknown };
|
|
131
|
+
const cells = Array.isArray(argsObj.cells)
|
|
132
|
+
? argsObj.cells
|
|
133
|
+
: typeof argsObj.code === "string"
|
|
134
|
+
? [argsObj]
|
|
135
|
+
: undefined;
|
|
136
|
+
if (!cells) return undefined;
|
|
132
137
|
|
|
133
138
|
const codeBlocks: string[] = [];
|
|
134
139
|
let language = "python";
|
|
@@ -517,9 +517,9 @@ export class UiHelpers {
|
|
|
517
517
|
this.ctx.pendingBashComponents = [];
|
|
518
518
|
this.ctx.pendingPythonComponents = [];
|
|
519
519
|
|
|
520
|
-
//
|
|
521
|
-
//
|
|
522
|
-
const context = this.ctx.viewSession.buildTranscriptSessionContext();
|
|
520
|
+
// Live display uses the compacted transcript tail; export/resume callers
|
|
521
|
+
// can still request the full inline compaction history.
|
|
522
|
+
const context = this.ctx.viewSession.buildTranscriptSessionContext({ collapseCompactedHistory: true });
|
|
523
523
|
this.ctx.renderSessionContext(context, {
|
|
524
524
|
updateFooter: true,
|
|
525
525
|
populateHistory: !this.ctx.focusedAgentId,
|
|
@@ -109,9 +109,9 @@ You MUST use the specialized tool over its shell equivalent:
|
|
|
109
109
|
{{#has tools "lsp"}}- Code intelligence → `{{toolRefs.lsp}}`.{{/has}}
|
|
110
110
|
{{#has tools "search"}}- Regex search → `{{toolRefs.search}}`, not `grep`, `rg`, or `awk`.{{/has}}
|
|
111
111
|
{{#has tools "find"}}- Globbing → `{{toolRefs.find}}`, not `ls **/*.ext` or `fd`.{{/has}}
|
|
112
|
-
{{#has tools "eval"}}-
|
|
113
|
-
{{#has tools "bash"}}-
|
|
114
|
-
- Litmus:
|
|
112
|
+
{{#has tools "eval"}}- Default for any compute: `{{toolRefs.eval}}` cells. Bash is the EXCEPTION — only single binary calls or short fact-computing pipelines (`wc -l`, `sort | uniq -c`, `diff`, checksums). The moment a command grows a loop, conditional, heredoc, `-e`/`-c` script, `$(…)` nesting, or >2 pipe stages, it's a program → `{{toolRefs.eval}}`. NEVER write multiline or inline-script bash.{{/has}}
|
|
113
|
+
{{#has tools "bash"}}- `{{toolRefs.bash}}`: real binaries and short fact pipelines only. Commands shadowing the specialized tools above are blocked.{{/has}}
|
|
114
|
+
{{#has tools "bash"}}- Litmus: one external-CLI call or short pipeline returning a count, frequency, set difference, or checksum → bash.{{#has tools "eval"}} Needs control flow, state, or fights shell quoting → `{{toolRefs.eval}}`.{{/has}} Merely moves, pages, or trims bytes a tool can fetch → use the tool.{{/has}}
|
|
115
115
|
|
|
116
116
|
{{#has tools "report_tool_issue"}}
|
|
117
117
|
<critical>
|
|
@@ -11,16 +11,16 @@ Worth it when the task benefits from decomposition + parallel coverage, or from
|
|
|
11
11
|
</when>
|
|
12
12
|
|
|
13
13
|
<helpers>
|
|
14
|
-
State persists across
|
|
14
|
+
State persists across eval calls, so scout in one call and fan out in the next. Every eval call has:
|
|
15
15
|
|
|
16
|
-
- `agent(prompt, *,
|
|
16
|
+
- `agent(prompt, *, agent="task", model=None, label=None, schema=None, isolated=None, apply=None, merge=None, handle=False)` — run ONE subagent; returns its final text, or the validated object when `schema` (a JSON Schema dict) is given. With `schema` the subagent is forced to emit structured output that is validated for you — branch on the object, not on parsed prose. `agent` picks a discovered agent ("explore", "reviewer", "oracle", …); `label` names the artifact. Shared background goes in a `local://` file referenced from each prompt, not a parameter. Subagents are told their final text IS the return value, so they hand back raw data. `agent()` blocks until the subagent finishes; eval-spawned agents nest at most 3 deep. Pass `isolated=True` to run the spawn in a copy-on-write worktree so parallel `agent()` calls can edit overlapping files safely — strict opt-in, mirrors the `task` tool, defaults off regardless of `task.isolation.mode`; `isolated=True` while the setting is `"none"` errors out instead of silently downgrading. With isolation, `apply=False` keeps changes in the worktree, and `merge=False` forces patch mode even when the setting is `"branch"`. Captured root patch path, branch name, nested repo patches, and apply summary reach the workflow through `handle=True` — combine it with `apply=False` (or `apply=False, schema=…`) and read `node["patch_path"]`, `node["branch_name"]`, `node["nested_patches"]`, `node["changes_applied"]`, `node["isolation_summary"]` (JS: same keys camelCased) to recover artifacts.
|
|
17
17
|
- `parallel(thunks)` — run zero-arg callables concurrently through a bounded pool, preserving input order; returns once all finish. The pool is bounded by the session's `task` concurrency — don't hand-tune it; fan out as wide as the work divides. A thunk that raises propagates — wrap risky work in `try/except` inside the thunk to keep partial results. In a loop, bind each closure's value with a default arg (`lambda d=d: …`) or every thunk captures the last one.
|
|
18
18
|
- `pipeline(items, *stages)` — map items through `stages` left-to-right. There is a BARRIER between stages: ALL items clear stage N before stage N+1 begins. Each stage is a one-arg callable; stage 1 gets the original item, later stages get the previous result. Same pool width as `parallel()`.
|
|
19
19
|
- `completion(prompt, *, model="default", system=None, schema=None)` — oneshot, stateless model call (no tools, no history). Tiers: "smol", "default", "slow". Cheap classification/scoring inside a fan-out.
|
|
20
20
|
- `log(message)` — emit a progress line above the status tree. `phase(title)` — start a phase; the status lines that follow group under it.
|
|
21
21
|
- `budget` — `budget.total` (output-token ceiling, or `None` when none is set), `budget.spent()` (tokens spent this turn — main loop + eval subagents), `budget.remaining()` (`math.inf` when total is `None`), `budget.hard` (whether it's enforced). A ceiling is set by the user: `+Nk` in their message is advisory (you self-limit via `budget.remaining()`), `+Nk!` (or Goal Mode) is hard — `agent()` refuses to spawn once spent reaches it. Gate loops on `budget.total` first, since it's `None` when the user set no budget.
|
|
22
22
|
|
|
23
|
-
Everything runs INLINE and synchronously inside the eval call — no background mode, no resume, no separate progress app. Each eval call is one well-scoped fan-out; chain several across
|
|
23
|
+
Everything runs INLINE and synchronously inside the eval call — no background mode, no resume, no separate progress app. Each eval call is one well-scoped fan-out; chain several across calls and turns for multi-phase work, reading each result before you decide the next phase.
|
|
24
24
|
</helpers>
|
|
25
25
|
|
|
26
26
|
<structure>
|