@oh-my-pi/pi-coding-agent 16.2.6 → 16.2.8
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 +46 -0
- package/dist/cli.js +2781 -2660
- package/dist/types/cli/bench-cli.d.ts +3 -3
- package/dist/types/commands/bench.d.ts +1 -1
- package/dist/types/config/service-tier.d.ts +39 -24
- package/dist/types/config/settings-schema.d.ts +92 -36
- package/dist/types/edit/hashline/filesystem.d.ts +1 -0
- package/dist/types/mcp/config-writer.d.ts +48 -0
- package/dist/types/mcp/types.d.ts +3 -0
- package/dist/types/session/agent-session.d.ts +33 -13
- package/dist/types/session/messages.d.ts +1 -1
- package/dist/types/session/session-context.d.ts +2 -7
- package/dist/types/session/session-entries.d.ts +2 -2
- package/dist/types/session/session-manager.d.ts +2 -2
- package/dist/types/session/settings-stream-fn.d.ts +2 -2
- package/dist/types/system-prompt.test.d.ts +1 -0
- package/dist/types/task/executor.d.ts +6 -6
- package/dist/types/task/types.d.ts +6 -0
- package/dist/types/task/worktree.d.ts +32 -6
- package/dist/types/tiny/title-client.d.ts +5 -1
- package/dist/types/tools/index.d.ts +3 -3
- package/dist/types/tools/output-schema-validator.d.ts +10 -0
- package/dist/types/utils/git.d.ts +17 -0
- package/package.json +12 -12
- package/src/cli/bench-cli.ts +19 -12
- package/src/cli/tiny-models-cli.ts +18 -4
- package/src/commands/bench.ts +3 -3
- package/src/config/mcp-schema.json +10 -1
- package/src/config/service-tier.ts +85 -56
- package/src/config/settings-schema.ts +81 -37
- package/src/config/settings.ts +47 -0
- package/src/discovery/builtin-rules/go-add-cleanup.md +32 -0
- package/src/discovery/builtin-rules/go-bench-loop.md +36 -0
- package/src/discovery/builtin-rules/go-exp-promoted.md +39 -0
- package/src/discovery/builtin-rules/go-ioutil.md +36 -0
- package/src/discovery/builtin-rules/go-join-hostport.md +29 -0
- package/src/discovery/builtin-rules/go-new-expr.md +44 -0
- package/src/discovery/builtin-rules/go-rand-v2.md +40 -0
- package/src/discovery/builtin-rules/go-range-int.md +45 -0
- package/src/discovery/builtin-rules/index.ts +16 -0
- package/src/edit/hashline/filesystem.ts +12 -0
- package/src/eval/agent-bridge.ts +4 -2
- package/src/internal-urls/docs-index.generated.txt +1 -1
- package/src/main.ts +1 -1
- package/src/mcp/config-writer.ts +121 -0
- package/src/mcp/config.ts +10 -6
- package/src/mcp/types.ts +3 -0
- package/src/modes/components/extensions/extension-dashboard.ts +46 -0
- package/src/modes/components/extensions/state-manager.ts +24 -3
- package/src/modes/controllers/event-controller.ts +7 -0
- package/src/modes/controllers/tool-args-reveal.ts +1 -1
- package/src/modes/utils/transcript-render-helpers.ts +2 -2
- package/src/prompts/tools/bash.md +1 -4
- package/src/sdk.ts +12 -11
- package/src/session/agent-session.ts +294 -82
- package/src/session/messages.ts +1 -1
- package/src/session/session-context.ts +17 -6
- package/src/session/session-entries.ts +2 -2
- package/src/session/session-manager.ts +9 -2
- package/src/session/settings-stream-fn.ts +12 -2
- package/src/slash-commands/builtin-registry.ts +2 -10
- package/src/system-prompt.test.ts +158 -0
- package/src/system-prompt.ts +69 -26
- package/src/task/executor.ts +23 -16
- package/src/task/index.ts +7 -5
- package/src/task/isolation-runner.ts +15 -1
- package/src/task/types.ts +6 -0
- package/src/task/worktree.ts +219 -38
- package/src/tiny/title-client.ts +19 -13
- package/src/tools/grep.ts +19 -1
- package/src/tools/index.ts +3 -3
- package/src/tools/irc.ts +9 -3
- package/src/tools/output-schema-validator.ts +38 -0
- package/src/tools/read.ts +28 -28
- package/src/tools/yield.ts +52 -15
- package/src/utils/file-mentions.ts +10 -1
- package/src/utils/git.ts +38 -0
- package/src/web/search/providers/duckduckgo.ts +17 -3
package/src/task/worktree.ts
CHANGED
|
@@ -148,21 +148,33 @@ export async function captureBaseline(repoRoot: string): Promise<WorktreeBaselin
|
|
|
148
148
|
return { root, nested };
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
async function captureRepoDeltaPatch(repoDir: string, rb: RepoBaseline): Promise<string> {
|
|
151
|
+
async function captureRepoDeltaPatch(repoDir: string, rb: RepoBaseline, objectRepoDir = repoDir): Promise<string> {
|
|
152
152
|
const currentHead = (await git.head.sha(repoDir)) ?? "";
|
|
153
153
|
const currentStaged = await git.diff(repoDir, { binary: true, cached: true });
|
|
154
154
|
const currentUnstaged = await git.diff(repoDir, { binary: true });
|
|
155
155
|
const currentUntracked = await git.ls.untracked(repoDir);
|
|
156
156
|
const currentUntrackedPatch = await captureUntrackedPatch(repoDir, currentUntracked);
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
const committedPatch =
|
|
158
|
+
currentHead && currentHead !== rb.headCommit
|
|
159
|
+
? await git.diff.tree(repoDir, rb.headCommit, currentHead, {
|
|
160
|
+
allowFailure: true,
|
|
161
|
+
binary: true,
|
|
162
|
+
})
|
|
163
|
+
: "";
|
|
164
|
+
|
|
165
|
+
const baselineTree = await writeSyntheticTree(objectRepoDir, rb.headCommit, [
|
|
166
|
+
rb.staged,
|
|
167
|
+
rb.unstaged,
|
|
168
|
+
rb.untrackedPatch,
|
|
169
|
+
]);
|
|
170
|
+
const currentTree = await writeSyntheticTree(objectRepoDir, rb.headCommit, [
|
|
171
|
+
committedPatch,
|
|
160
172
|
currentStaged,
|
|
161
173
|
currentUnstaged,
|
|
162
174
|
currentUntrackedPatch,
|
|
163
175
|
]);
|
|
164
176
|
|
|
165
|
-
return git.diff.tree(
|
|
177
|
+
return git.diff.tree(objectRepoDir, baselineTree, currentTree, {
|
|
166
178
|
allowFailure: true,
|
|
167
179
|
binary: true,
|
|
168
180
|
});
|
|
@@ -212,7 +224,7 @@ export interface DeltaPatchResult {
|
|
|
212
224
|
}
|
|
213
225
|
|
|
214
226
|
export async function captureDeltaPatch(isolationDir: string, baseline: WorktreeBaseline): Promise<DeltaPatchResult> {
|
|
215
|
-
const rootPatch = await captureRepoDeltaPatch(isolationDir, baseline.root);
|
|
227
|
+
const rootPatch = await captureRepoDeltaPatch(isolationDir, baseline.root, baseline.root.repoRoot);
|
|
216
228
|
const nestedPatches: NestedRepoPatch[] = [];
|
|
217
229
|
|
|
218
230
|
for (const { relativePath, baseline: nb } of baseline.nested) {
|
|
@@ -222,7 +234,7 @@ export async function captureDeltaPatch(isolationDir: string, baseline: Worktree
|
|
|
222
234
|
} catch {
|
|
223
235
|
continue;
|
|
224
236
|
}
|
|
225
|
-
const patch = await captureRepoDeltaPatch(nestedDir, nb);
|
|
237
|
+
const patch = await captureRepoDeltaPatch(nestedDir, nb, nb.repoRoot);
|
|
226
238
|
if (patch.trim()) nestedPatches.push({ relativePath, patch });
|
|
227
239
|
}
|
|
228
240
|
|
|
@@ -460,12 +472,137 @@ export async function cleanupIsolation(handle: IsolationHandle): Promise<void> {
|
|
|
460
472
|
export interface CommitToBranchResult {
|
|
461
473
|
branchName?: string;
|
|
462
474
|
nestedPatches: NestedRepoPatch[];
|
|
475
|
+
/**
|
|
476
|
+
* SHA of the parent-repo commit the task branch was created on top of, so
|
|
477
|
+
* {@link mergeTaskBranches} can cherry-pick the range `baseSha..branchName`
|
|
478
|
+
* and preserve every agent commit's message and author.
|
|
479
|
+
*/
|
|
480
|
+
baseSha?: string;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function baselineHasRootWip(baseline: RepoBaseline): boolean {
|
|
484
|
+
return !!(baseline.staged.trim() || baseline.unstaged.trim() || baseline.untrackedPatch.trim());
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
async function commitPatchToBranchWorktree(
|
|
488
|
+
tmpDir: string,
|
|
489
|
+
taskId: string,
|
|
490
|
+
patchText: string,
|
|
491
|
+
message: string,
|
|
492
|
+
author?: git.CommitAuthor,
|
|
493
|
+
): Promise<void> {
|
|
494
|
+
try {
|
|
495
|
+
await git.patch.applyText(tmpDir, patchText);
|
|
496
|
+
} catch (err) {
|
|
497
|
+
if (!(err instanceof git.GitCommandError)) throw err;
|
|
498
|
+
// Plain apply rejects when the parent checkout carries unrelated dirty
|
|
499
|
+
// context near the task's edits; retry with --3way before giving up.
|
|
500
|
+
try {
|
|
501
|
+
await git.patch.applyText(tmpDir, patchText, { threeWay: true });
|
|
502
|
+
} catch (threeWayErr) {
|
|
503
|
+
if (threeWayErr instanceof git.GitCommandError) {
|
|
504
|
+
const stderr = threeWayErr.result.stderr.slice(0, 2000);
|
|
505
|
+
logger.error("commitToBranch: git apply --3way failed", {
|
|
506
|
+
taskId,
|
|
507
|
+
exitCode: threeWayErr.result.exitCode,
|
|
508
|
+
stderr,
|
|
509
|
+
initialStderr: err.result.stderr.slice(0, 2000),
|
|
510
|
+
patchSize: patchText.length,
|
|
511
|
+
patchHead: patchText.slice(0, 500),
|
|
512
|
+
});
|
|
513
|
+
throw new Error(`git apply --3way failed for task ${taskId}: ${stderr}`);
|
|
514
|
+
}
|
|
515
|
+
throw threeWayErr;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
await git.stage.files(tmpDir);
|
|
519
|
+
await git.commit(tmpDir, message, author ? { author } : {});
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
interface FilteredAgentReplayOptions {
|
|
523
|
+
baseline: WorktreeBaseline;
|
|
524
|
+
branchName: string;
|
|
525
|
+
commitMessage?: (diff: string) => Promise<string | null>;
|
|
526
|
+
fallbackMessage: string;
|
|
527
|
+
isolationDir: string;
|
|
528
|
+
isolationHead: string;
|
|
529
|
+
repoRoot: string;
|
|
530
|
+
rootPatch: string;
|
|
531
|
+
taskId: string;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
async function replayFilteredAgentCommits(opts: FilteredAgentReplayOptions): Promise<void> {
|
|
535
|
+
const baselineSha = opts.baseline.root.headCommit;
|
|
536
|
+
await git.branch.create(opts.repoRoot, opts.branchName, baselineSha);
|
|
537
|
+
|
|
538
|
+
const tmpDir = path.join(os.tmpdir(), `omp-branch-${Snowflake.next()}`);
|
|
539
|
+
try {
|
|
540
|
+
await git.worktree.add(opts.repoRoot, tmpDir, opts.branchName);
|
|
541
|
+
const agentCommits = await git.revList.range(opts.isolationDir, baselineSha, opts.isolationHead);
|
|
542
|
+
const dirtyBaselineTree = await writeSyntheticTree(opts.isolationDir, baselineSha, [
|
|
543
|
+
opts.baseline.root.staged,
|
|
544
|
+
opts.baseline.root.unstaged,
|
|
545
|
+
opts.baseline.root.untrackedPatch,
|
|
546
|
+
]);
|
|
547
|
+
let previousFilteredTree = baselineSha;
|
|
548
|
+
|
|
549
|
+
for (const commitSha of agentCommits) {
|
|
550
|
+
const taskStatePatch = await git.diff.tree(opts.isolationDir, dirtyBaselineTree, `${commitSha}^{tree}`, {
|
|
551
|
+
allowFailure: true,
|
|
552
|
+
binary: true,
|
|
553
|
+
});
|
|
554
|
+
const currentFilteredTree = await writeSyntheticTree(opts.repoRoot, baselineSha, [taskStatePatch]);
|
|
555
|
+
const commitPatch = await git.diff.tree(opts.repoRoot, previousFilteredTree, currentFilteredTree, {
|
|
556
|
+
allowFailure: true,
|
|
557
|
+
binary: true,
|
|
558
|
+
});
|
|
559
|
+
if (commitPatch.trim()) {
|
|
560
|
+
const details = await git.commitDetails(opts.isolationDir, commitSha);
|
|
561
|
+
await commitPatchToBranchWorktree(
|
|
562
|
+
tmpDir,
|
|
563
|
+
opts.taskId,
|
|
564
|
+
commitPatch,
|
|
565
|
+
details.message || commitSha,
|
|
566
|
+
details.author,
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
previousFilteredTree = currentFilteredTree;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const finalFilteredTree = await writeSyntheticTree(opts.repoRoot, baselineSha, [opts.rootPatch]);
|
|
573
|
+
const leftoverPatch = await git.diff.tree(opts.repoRoot, previousFilteredTree, finalFilteredTree, {
|
|
574
|
+
allowFailure: true,
|
|
575
|
+
binary: true,
|
|
576
|
+
});
|
|
577
|
+
if (leftoverPatch.trim()) {
|
|
578
|
+
const msg = (opts.commitMessage && (await opts.commitMessage(leftoverPatch))) || opts.fallbackMessage;
|
|
579
|
+
await commitPatchToBranchWorktree(tmpDir, opts.taskId, leftoverPatch, msg);
|
|
580
|
+
}
|
|
581
|
+
} finally {
|
|
582
|
+
await git.worktree.tryRemove(opts.repoRoot, tmpDir);
|
|
583
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
584
|
+
}
|
|
463
585
|
}
|
|
464
586
|
|
|
465
587
|
/**
|
|
466
|
-
*
|
|
467
|
-
* Only root
|
|
468
|
-
* separately
|
|
588
|
+
* Capture task-only changes from the isolation worktree onto a parent-repo
|
|
589
|
+
* branch named `omp/task/${taskId}`. Only root-repo changes go on the branch;
|
|
590
|
+
* nested-repo patches are returned separately because the parent git can't
|
|
591
|
+
* track files inside gitlinks.
|
|
592
|
+
*
|
|
593
|
+
* If the agent committed inside isolation (HEAD moved past
|
|
594
|
+
* `baseline.root.headCommit`), clean-baseline runs fetch the raw commit range
|
|
595
|
+
* into the parent repo and later cherry-pick `baseSha..branchName`, preserving
|
|
596
|
+
* every message and author verbatim. Dirty-baseline runs rewrite each agent
|
|
597
|
+
* commit against the captured baseline WIP before committing it to the task
|
|
598
|
+
* branch, so user staged/unstaged/untracked changes present at isolation
|
|
599
|
+
* start are not replayed into the parent commit history.
|
|
600
|
+
*
|
|
601
|
+
* If the agent did not commit, the captured delta is collapsed onto a single
|
|
602
|
+
* branch commit with an AI-generated (or fallback) message — the legacy
|
|
603
|
+
* behaviour.
|
|
604
|
+
*
|
|
605
|
+
* Returns `null` when no root or nested changes exist.
|
|
469
606
|
*/
|
|
470
607
|
export async function commitToBranch(
|
|
471
608
|
isolationDir: string,
|
|
@@ -474,45 +611,84 @@ export async function commitToBranch(
|
|
|
474
611
|
description: string | undefined,
|
|
475
612
|
commitMessage?: (diff: string) => Promise<string | null>,
|
|
476
613
|
): Promise<CommitToBranchResult | null> {
|
|
614
|
+
const baselineSha = baseline.root.headCommit;
|
|
615
|
+
const isolationHead = (await git.head.sha(isolationDir)) ?? "";
|
|
616
|
+
const agentCommitted = isolationHead !== "" && isolationHead !== baselineSha;
|
|
617
|
+
|
|
477
618
|
const { rootPatch, nestedPatches } = await captureDeltaPatch(isolationDir, baseline);
|
|
478
619
|
if (!rootPatch.trim() && nestedPatches.length === 0) return null;
|
|
620
|
+
if (!rootPatch.trim()) return { nestedPatches };
|
|
479
621
|
|
|
480
622
|
const repoRoot = baseline.root.repoRoot;
|
|
481
623
|
const branchName = `omp/task/${taskId}`;
|
|
482
624
|
const fallbackMessage = description || taskId;
|
|
483
625
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
626
|
+
let branchCreated = false;
|
|
627
|
+
|
|
628
|
+
if (agentCommitted) {
|
|
629
|
+
if (baselineHasRootWip(baseline.root)) {
|
|
630
|
+
await replayFilteredAgentCommits({
|
|
631
|
+
baseline,
|
|
632
|
+
branchName,
|
|
633
|
+
commitMessage,
|
|
634
|
+
fallbackMessage,
|
|
635
|
+
isolationDir,
|
|
636
|
+
isolationHead,
|
|
637
|
+
repoRoot,
|
|
638
|
+
rootPatch,
|
|
639
|
+
taskId,
|
|
640
|
+
});
|
|
641
|
+
} else {
|
|
642
|
+
// Transfer the agent's commit objects (which live in isolation's `.git`,
|
|
643
|
+
// stranded once `cleanupIsolation` tears the overlay down) into the parent
|
|
644
|
+
// repo's object DB and create the branch at the agent's HEAD. `+HEAD:…`
|
|
645
|
+
// force-overwrites a stale branch from a prior run.
|
|
646
|
+
await git.fetch(repoRoot, isolationDir, "HEAD", `refs/heads/${branchName}`);
|
|
647
|
+
|
|
648
|
+
// Leftover = anything still uncommitted in isolation on top of the
|
|
649
|
+
// agent's last commit (staged, unstaged, untracked). The agent didn't
|
|
650
|
+
// commit it, so it goes in as one AI-summarized trailing commit.
|
|
651
|
+
const leftoverPatch = await captureRepoDeltaPatch(isolationDir, {
|
|
652
|
+
repoRoot: isolationDir,
|
|
653
|
+
headCommit: isolationHead,
|
|
654
|
+
staged: "",
|
|
655
|
+
unstaged: "",
|
|
656
|
+
untracked: [],
|
|
657
|
+
untrackedPatch: "",
|
|
658
|
+
});
|
|
659
|
+
if (leftoverPatch.trim()) {
|
|
660
|
+
const tmpDir = path.join(os.tmpdir(), `omp-branch-${Snowflake.next()}`);
|
|
661
|
+
try {
|
|
662
|
+
await git.worktree.add(repoRoot, tmpDir, branchName);
|
|
663
|
+
const msg = (commitMessage && (await commitMessage(leftoverPatch))) || fallbackMessage;
|
|
664
|
+
await commitPatchToBranchWorktree(tmpDir, taskId, leftoverPatch, msg);
|
|
665
|
+
} finally {
|
|
666
|
+
await git.worktree.tryRemove(repoRoot, tmpDir);
|
|
667
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
branchCreated = true;
|
|
672
|
+
} else if (rootPatch.trim()) {
|
|
673
|
+
await git.branch.create(repoRoot, branchName, baselineSha);
|
|
674
|
+
branchCreated = true;
|
|
487
675
|
const tmpDir = path.join(os.tmpdir(), `omp-branch-${Snowflake.next()}`);
|
|
488
676
|
try {
|
|
489
677
|
await git.worktree.add(repoRoot, tmpDir, branchName);
|
|
490
|
-
|
|
491
|
-
await git.patch.applyText(tmpDir, rootPatch);
|
|
492
|
-
} catch (err) {
|
|
493
|
-
if (err instanceof git.GitCommandError) {
|
|
494
|
-
const stderr = err.result.stderr.slice(0, 2000);
|
|
495
|
-
logger.error("commitToBranch: git apply failed", {
|
|
496
|
-
taskId,
|
|
497
|
-
exitCode: err.result.exitCode,
|
|
498
|
-
stderr,
|
|
499
|
-
patchSize: rootPatch.length,
|
|
500
|
-
patchHead: rootPatch.slice(0, 500),
|
|
501
|
-
});
|
|
502
|
-
throw new Error(`git apply failed for task ${taskId}: ${stderr}`);
|
|
503
|
-
}
|
|
504
|
-
throw err;
|
|
505
|
-
}
|
|
506
|
-
await git.stage.files(tmpDir);
|
|
678
|
+
|
|
507
679
|
const msg = (commitMessage && (await commitMessage(rootPatch))) || fallbackMessage;
|
|
508
|
-
await
|
|
680
|
+
await commitPatchToBranchWorktree(tmpDir, taskId, rootPatch, msg);
|
|
509
681
|
} finally {
|
|
510
682
|
await git.worktree.tryRemove(repoRoot, tmpDir);
|
|
511
683
|
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
512
684
|
}
|
|
513
685
|
}
|
|
514
686
|
|
|
515
|
-
return {
|
|
687
|
+
return {
|
|
688
|
+
branchName: branchCreated ? branchName : undefined,
|
|
689
|
+
baseSha: baselineSha,
|
|
690
|
+
nestedPatches,
|
|
691
|
+
};
|
|
516
692
|
}
|
|
517
693
|
|
|
518
694
|
export interface MergeBranchResult {
|
|
@@ -524,13 +700,17 @@ export interface MergeBranchResult {
|
|
|
524
700
|
}
|
|
525
701
|
|
|
526
702
|
/**
|
|
527
|
-
* Cherry-pick task branch commits sequentially onto HEAD.
|
|
528
|
-
*
|
|
529
|
-
*
|
|
703
|
+
* Cherry-pick task branch commits sequentially onto HEAD. When `baseSha` is
|
|
704
|
+
* provided the cherry-pick uses the inclusive range `baseSha..branchName`,
|
|
705
|
+
* replaying every commit individually and preserving each commit's message
|
|
706
|
+
* and author. When omitted, the branch is cherry-picked as a single commit
|
|
707
|
+
* (legacy callers).
|
|
708
|
+
*
|
|
709
|
+
* Stops on the first conflict and reports which branches succeeded.
|
|
530
710
|
*/
|
|
531
711
|
export async function mergeTaskBranches(
|
|
532
712
|
repoRoot: string,
|
|
533
|
-
branches: Array<{ branchName: string; taskId: string; description?: string }>,
|
|
713
|
+
branches: Array<{ branchName: string; taskId: string; description?: string; baseSha?: string }>,
|
|
534
714
|
): Promise<MergeBranchResult> {
|
|
535
715
|
// Serialize against other in-process git mutations on this repo: concurrent
|
|
536
716
|
// background merges interleaving stash push/pop + cherry-pick would corrupt
|
|
@@ -546,9 +726,10 @@ export async function mergeTaskBranches(
|
|
|
546
726
|
let conflictResult: MergeBranchResult | undefined;
|
|
547
727
|
|
|
548
728
|
try {
|
|
549
|
-
for (const { branchName } of branches) {
|
|
729
|
+
for (const { branchName, baseSha } of branches) {
|
|
550
730
|
try {
|
|
551
|
-
|
|
731
|
+
const target = baseSha ? `${baseSha}..${branchName}` : branchName;
|
|
732
|
+
await git.cherryPick(repoRoot, target);
|
|
552
733
|
} catch (err) {
|
|
553
734
|
try {
|
|
554
735
|
await git.cherryPick.abort(repoRoot);
|
package/src/tiny/title-client.ts
CHANGED
|
@@ -29,7 +29,12 @@ import type { TinyTitleProgressEvent, TinyTitleWorkerInbound, TinyTitleWorkerOut
|
|
|
29
29
|
type PendingRequest =
|
|
30
30
|
| { kind: "generate"; modelKey: TinyTitleLocalModelKey; resolve: (title: string | null) => void }
|
|
31
31
|
| { kind: "complete"; modelKey: TinyMemoryLocalModelKey; resolve: (text: string | null) => void }
|
|
32
|
-
| { kind: "download"; modelKey: TinyLocalModelKey; resolve: (
|
|
32
|
+
| { kind: "download"; modelKey: TinyLocalModelKey; resolve: (result: TinyTitleDownloadResult) => void };
|
|
33
|
+
|
|
34
|
+
export interface TinyTitleDownloadResult {
|
|
35
|
+
ok: boolean;
|
|
36
|
+
error?: string;
|
|
37
|
+
}
|
|
33
38
|
|
|
34
39
|
export interface TinyTitleDownloadOptions {
|
|
35
40
|
signal?: AbortSignal;
|
|
@@ -269,21 +274,21 @@ export class TinyTitleClient {
|
|
|
269
274
|
}
|
|
270
275
|
}
|
|
271
276
|
|
|
272
|
-
async downloadModel(modelKey: string, options: TinyTitleDownloadOptions = {}): Promise<
|
|
273
|
-
if (!isTinyLocalModelKey(modelKey)) return false;
|
|
274
|
-
if (options.signal?.aborted) return false;
|
|
277
|
+
async downloadModel(modelKey: string, options: TinyTitleDownloadOptions = {}): Promise<TinyTitleDownloadResult> {
|
|
278
|
+
if (!isTinyLocalModelKey(modelKey)) return { ok: false };
|
|
279
|
+
if (options.signal?.aborted) return { ok: false };
|
|
275
280
|
|
|
276
281
|
const unsubscribe = options.onProgress ? this.onProgress(options.onProgress) : undefined;
|
|
277
282
|
try {
|
|
278
283
|
const worker = this.#ensureWorker();
|
|
279
284
|
const id = String(++this.#nextRequestId);
|
|
280
|
-
const { promise, resolve } = Promise.withResolvers<
|
|
285
|
+
const { promise, resolve } = Promise.withResolvers<TinyTitleDownloadResult>();
|
|
281
286
|
this.#addPending(id, { kind: "download", modelKey, resolve });
|
|
282
287
|
const abort = (): void => {
|
|
283
288
|
const pending = this.#pending.get(id);
|
|
284
289
|
if (pending?.kind !== "download") return;
|
|
285
290
|
this.#deletePending(id);
|
|
286
|
-
pending.resolve(false);
|
|
291
|
+
pending.resolve({ ok: false });
|
|
287
292
|
};
|
|
288
293
|
options.signal?.addEventListener("abort", abort, { once: true });
|
|
289
294
|
try {
|
|
@@ -294,11 +299,12 @@ export class TinyTitleClient {
|
|
|
294
299
|
this.#deletePending(id);
|
|
295
300
|
}
|
|
296
301
|
} catch (error) {
|
|
302
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
297
303
|
logger.debug("tiny-title: local model download failed", {
|
|
298
304
|
modelKey,
|
|
299
|
-
error:
|
|
305
|
+
error: message,
|
|
300
306
|
});
|
|
301
|
-
return false;
|
|
307
|
+
return { ok: false, error: message };
|
|
302
308
|
} finally {
|
|
303
309
|
unsubscribe?.();
|
|
304
310
|
}
|
|
@@ -314,7 +320,7 @@ export class TinyTitleClient {
|
|
|
314
320
|
for (const pending of this.#pending.values()) {
|
|
315
321
|
this.#emitProgress({ modelKey: pending.modelKey, status: "error" });
|
|
316
322
|
if (pending.kind === "generate" || pending.kind === "complete") pending.resolve(null);
|
|
317
|
-
else pending.resolve(false);
|
|
323
|
+
else pending.resolve({ ok: false });
|
|
318
324
|
}
|
|
319
325
|
this.#pending.clear();
|
|
320
326
|
this.#refed = false;
|
|
@@ -379,7 +385,7 @@ export class TinyTitleClient {
|
|
|
379
385
|
return;
|
|
380
386
|
}
|
|
381
387
|
if (message.type === "downloaded") {
|
|
382
|
-
if (pending.kind === "download") pending.resolve(true);
|
|
388
|
+
if (pending.kind === "download") pending.resolve({ ok: true });
|
|
383
389
|
return;
|
|
384
390
|
}
|
|
385
391
|
if (message.type === "completion") {
|
|
@@ -389,8 +395,8 @@ export class TinyTitleClient {
|
|
|
389
395
|
logger.debug("tiny-title: worker returned error", { error: message.error });
|
|
390
396
|
this.#markFailedModel(pending);
|
|
391
397
|
this.#emitProgress({ modelKey: pending.modelKey, status: "error" });
|
|
392
|
-
if (pending.kind === "
|
|
393
|
-
else pending.resolve(
|
|
398
|
+
if (pending.kind === "download") pending.resolve({ ok: false, error: message.error });
|
|
399
|
+
else pending.resolve(null);
|
|
394
400
|
void this.terminate();
|
|
395
401
|
}
|
|
396
402
|
|
|
@@ -407,7 +413,7 @@ export class TinyTitleClient {
|
|
|
407
413
|
for (const pending of this.#pending.values()) {
|
|
408
414
|
this.#emitProgress({ modelKey: pending.modelKey, status: "error" });
|
|
409
415
|
if (pending.kind === "generate" || pending.kind === "complete") pending.resolve(null);
|
|
410
|
-
else pending.resolve(false);
|
|
416
|
+
else pending.resolve({ ok: false, error: error.message });
|
|
411
417
|
}
|
|
412
418
|
this.#pending.clear();
|
|
413
419
|
void this.terminate();
|
package/src/tools/grep.ts
CHANGED
|
@@ -85,8 +85,26 @@ const searchSchema = type({
|
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
export type GrepToolInput = typeof searchSchema.infer;
|
|
88
|
+
function parseStringEncodedPathArray(input: string): string[] | null {
|
|
89
|
+
const trimmed = input.trim();
|
|
90
|
+
if (!trimmed.startsWith("[") || !trimmed.endsWith("]")) return null;
|
|
91
|
+
|
|
92
|
+
let parsed: unknown;
|
|
93
|
+
try {
|
|
94
|
+
parsed = JSON.parse(trimmed);
|
|
95
|
+
} catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!Array.isArray(parsed) || parsed.some(entry => typeof entry !== "string")) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
return parsed;
|
|
103
|
+
}
|
|
104
|
+
|
|
88
105
|
export function toPathList(input: string | string[] | undefined): string[] {
|
|
89
|
-
|
|
106
|
+
if (typeof input === "string") return parseStringEncodedPathArray(input) ?? [input];
|
|
107
|
+
return input ?? [];
|
|
90
108
|
}
|
|
91
109
|
|
|
92
110
|
/** Maximum number of distinct files surfaced in a single response. The
|
package/src/tools/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { InMemorySnapshotStore } from "@oh-my-pi/hashline";
|
|
2
2
|
import type { AgentTelemetryConfig, AgentTool } from "@oh-my-pi/pi-agent-core";
|
|
3
|
-
import type { FetchImpl, ImageContent, Model,
|
|
3
|
+
import type { FetchImpl, ImageContent, Model, ServiceTierByFamily, ToolChoice } from "@oh-my-pi/pi-ai";
|
|
4
4
|
import { logger } from "@oh-my-pi/pi-utils";
|
|
5
5
|
import type { AsyncJobManager } from "../async/job-manager";
|
|
6
6
|
import type { Rule } from "../capability/rule";
|
|
@@ -240,8 +240,8 @@ export interface ToolSession {
|
|
|
240
240
|
getActiveModelString?: () => string | undefined;
|
|
241
241
|
/** Get the current session model object (provider/api capabilities), regardless of how it was chosen. */
|
|
242
242
|
getActiveModel?: () => Model | undefined;
|
|
243
|
-
/** Get the session's live
|
|
244
|
-
|
|
243
|
+
/** Get the session's live per-family service tiers (undefined = none). Source of truth for subagent `tier.subagent: inherit`. */
|
|
244
|
+
getServiceTierByFamily?: () => ServiceTierByFamily | undefined;
|
|
245
245
|
/** Auth storage for passing to subagents (avoids re-discovery) */
|
|
246
246
|
authStorage?: import("../session/auth-storage").AuthStorage;
|
|
247
247
|
/** Model registry for passing to subagents (avoids re-discovery) */
|
package/src/tools/irc.ts
CHANGED
|
@@ -172,7 +172,7 @@ export class IrcTool implements AgentTool<typeof ircSchema, IrcDetails> {
|
|
|
172
172
|
case "wait":
|
|
173
173
|
return this.#executeWait(senderId, params, signal);
|
|
174
174
|
case "inbox":
|
|
175
|
-
return this.#executeInbox(senderId, params);
|
|
175
|
+
return this.#executeInbox(registry, senderId, params);
|
|
176
176
|
default:
|
|
177
177
|
return errorResult("Unknown irc op.", { op: params.op });
|
|
178
178
|
}
|
|
@@ -371,8 +371,14 @@ export class IrcTool implements AgentTool<typeof ircSchema, IrcDetails> {
|
|
|
371
371
|
};
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
-
#executeInbox(senderId: string, params: IrcParams): AgentToolResult<IrcDetails> {
|
|
375
|
-
const
|
|
374
|
+
#executeInbox(registry: AgentRegistry, senderId: string, params: IrcParams): AgentToolResult<IrcDetails> {
|
|
375
|
+
const busMessages = IrcBus.global().inbox(senderId, { peek: params.peek });
|
|
376
|
+
const session = registry.get(senderId)?.session;
|
|
377
|
+
const pendingMessages =
|
|
378
|
+
typeof session?.drainPendingIrcInboxMessages === "function"
|
|
379
|
+
? session.drainPendingIrcInboxMessages(senderId)
|
|
380
|
+
: [];
|
|
381
|
+
const messages = [...busMessages, ...pendingMessages].sort((a, b) => a.ts - b.ts);
|
|
376
382
|
if (messages.length === 0) {
|
|
377
383
|
return {
|
|
378
384
|
content: [{ type: "text", text: "Inbox empty." }],
|
|
@@ -21,6 +21,16 @@ export interface OutputValidator {
|
|
|
21
21
|
validate(value: unknown): JsonSchemaValidationResult;
|
|
22
22
|
/** Top-level required property names. Empty if the schema has no `required` array at root. */
|
|
23
23
|
readonly requiredFields: readonly string[];
|
|
24
|
+
/**
|
|
25
|
+
* Per-label validators for incremental yields (`type: ["<label>"]`). Each entry validates the
|
|
26
|
+
* `data` payload of a single section against the matching top-level property's sub-schema —
|
|
27
|
+
* array-typed properties (e.g. `findings`) use the items schema since each yield contributes
|
|
28
|
+
* one element, while scalar properties use the property schema directly. Unknown labels (not
|
|
29
|
+
* top-level properties) have no entry and skip per-call validation. Lets the yield tool give
|
|
30
|
+
* the model retry feedback on a section as soon as it arrives, instead of deferring every
|
|
31
|
+
* mismatch to the parent's post-mortem `schema_violation`.
|
|
32
|
+
*/
|
|
33
|
+
readonly validateSection: ReadonlyMap<string, (value: unknown) => JsonSchemaValidationResult>;
|
|
24
34
|
}
|
|
25
35
|
|
|
26
36
|
export interface BuildOutputValidatorResult {
|
|
@@ -72,10 +82,38 @@ export function buildOutputValidator(schema: unknown): BuildOutputValidatorResul
|
|
|
72
82
|
validator: {
|
|
73
83
|
requiredFields: required,
|
|
74
84
|
validate: value => validateJsonSchemaValue(jsonSchemaRecord, value),
|
|
85
|
+
validateSection: buildSectionValidators(jsonSchemaRecord),
|
|
75
86
|
},
|
|
76
87
|
};
|
|
77
88
|
}
|
|
78
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Build per-top-level-property validators for incremental yields.
|
|
92
|
+
*
|
|
93
|
+
* Each entry validates the `data` payload of one `type: ["<label>"]` section against the
|
|
94
|
+
* matching property's sub-schema — array-typed properties (e.g. `findings`, derived from JTD
|
|
95
|
+
* `elements`) use the items schema since each yield contributes one element, while scalar
|
|
96
|
+
* properties use the property schema directly. Unknown labels (anything not declared as a
|
|
97
|
+
* top-level property) are deliberately omitted so user-defined section labels still pass.
|
|
98
|
+
*/
|
|
99
|
+
function buildSectionValidators(
|
|
100
|
+
jsonSchema: Record<string, unknown>,
|
|
101
|
+
): ReadonlyMap<string, (value: unknown) => JsonSchemaValidationResult> {
|
|
102
|
+
const validators = new Map<string, (value: unknown) => JsonSchemaValidationResult>();
|
|
103
|
+
const properties = jsonSchema.properties;
|
|
104
|
+
if (properties === null || typeof properties !== "object") return validators;
|
|
105
|
+
for (const [label, raw] of Object.entries(properties as Record<string, unknown>)) {
|
|
106
|
+
if (raw === null || typeof raw !== "object") continue;
|
|
107
|
+
const propRecord = raw as Record<string, unknown>;
|
|
108
|
+
const sectionSchema =
|
|
109
|
+
propRecord.type === "array" && propRecord.items !== undefined && propRecord.items !== null
|
|
110
|
+
? (propRecord.items as Record<string, unknown>)
|
|
111
|
+
: propRecord;
|
|
112
|
+
validators.set(label, value => validateJsonSchemaValue(sectionSchema, value));
|
|
113
|
+
}
|
|
114
|
+
return validators;
|
|
115
|
+
}
|
|
116
|
+
|
|
79
117
|
/** Produce the executor's headline+missing-required summary from a failed validation. */
|
|
80
118
|
export function summarizeValidationFailure(
|
|
81
119
|
result: JsonSchemaValidationResult,
|
package/src/tools/read.ts
CHANGED
|
@@ -14,7 +14,15 @@ import type { ImageContent, TextContent } from "@oh-my-pi/pi-ai";
|
|
|
14
14
|
import { glob, type SummaryResult, summarizeCode } from "@oh-my-pi/pi-natives";
|
|
15
15
|
import type { Component } from "@oh-my-pi/pi-tui";
|
|
16
16
|
import { Text } from "@oh-my-pi/pi-tui";
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
getRemoteDir,
|
|
19
|
+
type ImageMetadata,
|
|
20
|
+
isProbablyBinary,
|
|
21
|
+
logger,
|
|
22
|
+
prompt,
|
|
23
|
+
readImageMetadata,
|
|
24
|
+
untilAborted,
|
|
25
|
+
} from "@oh-my-pi/pi-utils";
|
|
18
26
|
import { type } from "arktype";
|
|
19
27
|
import { LRUCache } from "lru-cache/raw";
|
|
20
28
|
import {
|
|
@@ -2314,6 +2322,25 @@ export class ReadTool implements AgentTool<typeof readSchema, ReadToolDetails> {
|
|
|
2314
2322
|
content = [{ type: "text", text: `[Cannot read ${ext} file: conversion failed]` }];
|
|
2315
2323
|
}
|
|
2316
2324
|
} else {
|
|
2325
|
+
// Binary sniff before any UTF-8 text materialization. A binary file
|
|
2326
|
+
// (font, object, archive, packed blob) decodes to NUL/control bytes and
|
|
2327
|
+
// U+FFFD mojibake that corrupts the terminal and burns context. Images,
|
|
2328
|
+
// notebooks, and markit-convertible documents were already routed above;
|
|
2329
|
+
// everything reaching here is meant to be plain text. `:raw` stays the
|
|
2330
|
+
// explicit escape hatch for reading bytes verbatim. This single guard
|
|
2331
|
+
// covers both the multi-range and single-range disk paths below.
|
|
2332
|
+
if (!isRawSelector(parsed) && (await isProbablyBinary(absolutePath))) {
|
|
2333
|
+
return toolResult<ReadToolDetails>({ resolvedPath: absolutePath, suffixResolution })
|
|
2334
|
+
.text(
|
|
2335
|
+
prependSuffixResolutionNotice(
|
|
2336
|
+
`[Cannot read binary file '${formatPathRelativeToCwd(absolutePath, this.session.cwd)}' (${formatBytes(fileSize)}); not valid UTF-8 text. Use ':raw' to read bytes verbatim.]`,
|
|
2337
|
+
suffixResolution,
|
|
2338
|
+
),
|
|
2339
|
+
)
|
|
2340
|
+
.sourcePath(absolutePath)
|
|
2341
|
+
.done();
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2317
2344
|
if (
|
|
2318
2345
|
parsed.kind === "none" &&
|
|
2319
2346
|
this.session.settings.get("read.summarize.enabled") &&
|
|
@@ -2449,33 +2476,6 @@ export class ReadTool implements AgentTool<typeof readSchema, ReadToolDetails> {
|
|
|
2449
2476
|
// counts in `truncation` keep reflecting the source, not the trimmed
|
|
2450
2477
|
// view — column truncation surfaces separately via `.limits()`.
|
|
2451
2478
|
const rawSelector = isRawSelector(parsed);
|
|
2452
|
-
// Binary sniff: NUL bytes mean the file is not displayable text
|
|
2453
|
-
// (binary, or UTF-16 which has NULs in the ASCII range) — emit a
|
|
2454
|
-
// notice instead of mojibake filling the line budget. `:raw`
|
|
2455
|
-
// stays an explicit escape hatch.
|
|
2456
|
-
//
|
|
2457
|
-
// `collectedLines` covers the common case where at least one
|
|
2458
|
-
// physical line terminates within the byte budget. Binary blobs
|
|
2459
|
-
// without newlines (videos, archives, packed JSON) leave it
|
|
2460
|
-
// empty; their bytes only land in `firstLinePreview`, which the
|
|
2461
|
-
// `firstLineExceedsLimit` branch below would otherwise emit
|
|
2462
|
-
// verbatim. Sniffing the preview here keeps the refusal uniform.
|
|
2463
|
-
if (!rawSelector) {
|
|
2464
|
-
const hasNul = (text: string): boolean => text.includes("\u0000");
|
|
2465
|
-
const binaryDetected =
|
|
2466
|
-
collectedLines.some(hasNul) || (firstLinePreview !== undefined && hasNul(firstLinePreview.text));
|
|
2467
|
-
if (binaryDetected) {
|
|
2468
|
-
return toolResult<ReadToolDetails>({ resolvedPath: absolutePath, suffixResolution })
|
|
2469
|
-
.text(
|
|
2470
|
-
prependSuffixResolutionNotice(
|
|
2471
|
-
`[Cannot read binary file '${formatPathRelativeToCwd(absolutePath, this.session.cwd)}' (${formatBytes(fileSize)}); content contains NUL bytes (binary or UTF-16 encoded)]`,
|
|
2472
|
-
suffixResolution,
|
|
2473
|
-
),
|
|
2474
|
-
)
|
|
2475
|
-
.sourcePath(absolutePath)
|
|
2476
|
-
.done();
|
|
2477
|
-
}
|
|
2478
|
-
}
|
|
2479
2479
|
const maxColumns = resolveOutputMaxColumns(this.session.settings);
|
|
2480
2480
|
// Column truncation is display-only. `collectedLines` MUST stay
|
|
2481
2481
|
// byte-for-byte with the on-disk content so the snapshot recorded
|