pi-cowboy 0.0.0 → 0.3.2
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/LICENSE +21 -0
- package/README.md +281 -2
- package/agents/explore.toml +40 -0
- package/dist/agents/agent-assets.js +261 -0
- package/dist/agents/agent-cleanup.js +284 -0
- package/dist/agents/agent-discovery.js +108 -0
- package/dist/agents/agent-host.js +10 -0
- package/dist/agents/agent-manager.js +367 -0
- package/dist/agents/agent-reviver.js +64 -0
- package/dist/agents/agent-runner.js +288 -0
- package/dist/agents/agent-spawn-store.js +57 -0
- package/dist/agents/agent-template.js +46 -0
- package/dist/agents/agent-types.js +144 -0
- package/dist/agents/batch.js +92 -0
- package/dist/agents/cleanup-policy.js +194 -0
- package/dist/agents/cleanup-report.js +128 -0
- package/dist/agents/default-agents.js +19 -0
- package/dist/agents/harness/pi-bolt.js +15 -0
- package/dist/agents/harness/pi-compatible.js +68 -0
- package/dist/agents/harness/pig.js +16 -0
- package/dist/agents/harness/registry.js +27 -0
- package/dist/agents/harness.js +32 -0
- package/dist/agents/result-file-permissions.js +29 -0
- package/dist/agents/run-state.js +270 -0
- package/dist/agents/schemas/cleanup-batch.schema.js +19 -0
- package/dist/agents/schemas/cowboy-agents.schema.js +39 -0
- package/dist/agents/schemas/merge-batch.schema.js +25 -0
- package/dist/agents/schemas/steer-batch.schema.js +22 -0
- package/dist/agents/schemas/stop-batch.schema.js +18 -0
- package/dist/agents/spawn-defaults.js +70 -0
- package/dist/agents/subagent-session.js +601 -0
- package/dist/agents/tool-cleanup.js +57 -0
- package/dist/agents/tool-execution.js +125 -0
- package/dist/agents/tool-merge.js +190 -0
- package/dist/agents/tool-result.js +17 -0
- package/dist/agents/tool-steer.js +89 -0
- package/dist/agents/types.js +1 -0
- package/dist/availability.js +38 -0
- package/dist/config/config-io.js +261 -0
- package/dist/config/config-store.js +321 -0
- package/dist/config/config-validation.js +173 -0
- package/dist/config/layered-config.js +117 -0
- package/dist/config/types.js +23 -0
- package/dist/cow-support-launch.js +43 -0
- package/dist/events.js +146 -0
- package/dist/extension-toggle.js +28 -0
- package/dist/harness-availability-launch.js +23 -0
- package/dist/index.js +52 -0
- package/dist/infrastructure/exec-path.js +35 -0
- package/dist/infrastructure/git/cow-clone.js +398 -0
- package/dist/infrastructure/git/git-materializer.js +342 -0
- package/dist/infrastructure/git/git-merger.js +234 -0
- package/dist/infrastructure/git/git-retention.js +43 -0
- package/dist/infrastructure/git/git-runner.js +145 -0
- package/dist/infrastructure/git/git-worktree.js +143 -0
- package/dist/infrastructure/git/index.js +11 -0
- package/dist/infrastructure/git-client.js +11 -0
- package/dist/infrastructure/herdr/agent-stopper.js +60 -0
- package/dist/infrastructure/herdr/agents.js +329 -0
- package/dist/infrastructure/herdr/herdr-client.js +36 -0
- package/dist/infrastructure/herdr/herdr-transport.js +158 -0
- package/dist/infrastructure/herdr/index.js +15 -0
- package/dist/infrastructure/herdr/panes.js +174 -0
- package/dist/infrastructure/herdr/polling.js +44 -0
- package/dist/infrastructure/herdr/worktrees.js +76 -0
- package/dist/infrastructure/herdr-client.js +6 -0
- package/dist/infrastructure/herdr-host.js +163 -0
- package/dist/logger.js +79 -0
- package/dist/models/model-groups.js +72 -0
- package/dist/models/model-precedence.js +50 -0
- package/dist/models/model-request.js +108 -0
- package/dist/orchestrators/briefing-section.js +14 -0
- package/dist/orchestrators/context.js +116 -0
- package/dist/orchestrators/cues.js +90 -0
- package/dist/orchestrators/default-orchestrators.js +36 -0
- package/dist/orchestrators/orchestrator-discovery.js +68 -0
- package/dist/orchestrators/orchestrator-template.js +43 -0
- package/dist/orchestrators/orchestrator-types.js +78 -0
- package/dist/orchestrators/protocol.js +292 -0
- package/dist/orchestrators/types.js +7 -0
- package/dist/paths.js +66 -0
- package/dist/pi-settings.js +7 -0
- package/dist/predicates.js +25 -0
- package/dist/prompt/prompts.js +110 -0
- package/dist/prompt/skill-loader.js +153 -0
- package/dist/prompt/subagent-system-prompt.js +173 -0
- package/dist/registration.js +220 -0
- package/dist/shell.js +225 -0
- package/dist/spawn/cow-support.js +53 -0
- package/dist/spawn/herdr-launcher.js +80 -0
- package/dist/spawn/repo-lock.js +34 -0
- package/dist/spawn/sandbox.js +286 -0
- package/dist/spawn/spawn-coordinator.js +255 -0
- package/dist/spawn/spawn-id.js +39 -0
- package/dist/spawn/worktree-policy.js +137 -0
- package/dist/status-note.js +30 -0
- package/dist/subagent/ipc-protocol.js +68 -0
- package/dist/subagent/ipc.js +110 -0
- package/dist/subagent/pane-supervisor.js +24 -0
- package/dist/subagent/socket-ipc.js +240 -0
- package/dist/subagent/supervisor.js +315 -0
- package/dist/task-registry.js +258 -0
- package/dist/templates/template-files.js +84 -0
- package/dist/types.js +84 -0
- package/dist/ui/action-report.js +21 -0
- package/dist/ui/format.js +47 -0
- package/dist/ui/indicator.js +480 -0
- package/dist/ui/menu/helpers.js +227 -0
- package/dist/ui/menu/menu-agent-settings.js +182 -0
- package/dist/ui/menu/menu-agent-status.js +444 -0
- package/dist/ui/menu/menu-concurrency.js +226 -0
- package/dist/ui/menu/menu-model-settings.js +244 -0
- package/dist/ui/menu/menu-spawn-defaults.js +71 -0
- package/dist/ui/menu/menu-spawn-wizard.js +367 -0
- package/dist/ui/menu/menu-spawn-worktree.js +107 -0
- package/dist/ui/menu/menu-system-prompt.js +104 -0
- package/dist/ui/menu/menu-worktree-command.js +150 -0
- package/dist/ui/menu/menus.js +187 -0
- package/dist/ui/menu/model-picker.js +160 -0
- package/dist/ui/menu/screen-host.js +87 -0
- package/dist/ui/menu/submenus/confirm.js +23 -0
- package/dist/ui/menu/submenus/model-select.js +42 -0
- package/dist/ui/menu/submenus/name-field.js +43 -0
- package/dist/ui/menu/submenus/numeric-input.js +61 -0
- package/dist/ui/menu/submenus/target-select.js +129 -0
- package/dist/ui/menu/submenus/text-editor.js +49 -0
- package/dist/ui/menu/submenus/worktree-command-name.js +73 -0
- package/dist/ui/menu/submenus/worktree-name.js +53 -0
- package/dist/ui/menu/wrappers/settings-list.js +101 -0
- package/dist/ui/searchable-select.js +147 -0
- package/dist/ui/types.js +1 -0
- package/dist/utils.js +70 -0
- package/docs/assets/grazing.png +0 -0
- package/docs/assets/herdr-containers.png +0 -0
- package/docs/assets/logo-transparent.png +0 -0
- package/orchestrators/with-code-review.toml +20 -0
- package/package.json +109 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* worktree-name.ts — the spawn wizard's worktree name field, shown after Spawn.
|
|
3
|
+
*
|
|
4
|
+
* The field owns the naming rule for a manually created worktree: the name is
|
|
5
|
+
* the git branch, the worktree directory, and the spawned agent's herdr name,
|
|
6
|
+
* so it must be `cow-` + a non-empty lowercase `[a-z0-9_-]` suffix within
|
|
7
|
+
* herdr's 32-character agent-name cap. Submit re-prompts with a notification
|
|
8
|
+
* instead of completing on a rejected name.
|
|
9
|
+
*/
|
|
10
|
+
import { HERDR_AGENT_NAME_MAX_LENGTH } from "../../../spawn/worktree-policy.js";
|
|
11
|
+
import { createNameField } from "./name-field.js";
|
|
12
|
+
/** Prefix every worktree name carries; the field is prefilled with it. */
|
|
13
|
+
export const WORKTREE_BRANCH_PREFIX = "cow-";
|
|
14
|
+
/** Longest accepted name: the branch is the herdr agent name, capped at `[a-z][a-z0-9_-]{0,31}`. */
|
|
15
|
+
export const WORKTREE_BRANCH_MAX_LENGTH = HERDR_AGENT_NAME_MAX_LENGTH;
|
|
16
|
+
/** Validate a trimmed worktree name; null means accepted. */
|
|
17
|
+
export function validateWorktreeBranchName(input) {
|
|
18
|
+
if (!input.startsWith(WORKTREE_BRANCH_PREFIX)) {
|
|
19
|
+
return { kind: "missing-prefix" };
|
|
20
|
+
}
|
|
21
|
+
const suffix = input.slice(WORKTREE_BRANCH_PREFIX.length);
|
|
22
|
+
if (suffix === "")
|
|
23
|
+
return { kind: "empty-name" };
|
|
24
|
+
if (!/^[a-z0-9_-]+$/.test(suffix))
|
|
25
|
+
return { kind: "invalid-characters" };
|
|
26
|
+
if (input.length > WORKTREE_BRANCH_MAX_LENGTH)
|
|
27
|
+
return { kind: "too-long" };
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
/** User-facing message for a rejected worktree name. */
|
|
31
|
+
export function describeWorktreeNameProblem(problem) {
|
|
32
|
+
switch (problem.kind) {
|
|
33
|
+
case "missing-prefix":
|
|
34
|
+
return `Worktree name must start with "${WORKTREE_BRANCH_PREFIX}" — it is prefilled; add your name after it.`;
|
|
35
|
+
case "empty-name":
|
|
36
|
+
return `Enter a name after "${WORKTREE_BRANCH_PREFIX}" (for example cow-fix-login).`;
|
|
37
|
+
case "invalid-characters":
|
|
38
|
+
return "Invalid name: only lowercase letters, numbers, hyphens, and underscores allowed.";
|
|
39
|
+
case "too-long":
|
|
40
|
+
return `Worktree name is too long: herdr agent names cap at ${WORKTREE_BRANCH_MAX_LENGTH} characters, so the name after "${WORKTREE_BRANCH_PREFIX}" can be at most ${WORKTREE_BRANCH_MAX_LENGTH - WORKTREE_BRANCH_PREFIX.length} characters.`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Single-line name field, prefilled `cow-`; a rejected submit keeps the text. */
|
|
44
|
+
export function createWorktreeNameInput(options) {
|
|
45
|
+
return createNameField({
|
|
46
|
+
prefill: WORKTREE_BRANCH_PREFIX,
|
|
47
|
+
notify: options.notify,
|
|
48
|
+
validate: validateWorktreeBranchName,
|
|
49
|
+
describeProblem: describeWorktreeNameProblem,
|
|
50
|
+
onDone: options.onDone,
|
|
51
|
+
onCancel: options.onCancel,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* settings-list-wrapper.ts — title bar and separators around a SettingsList or SelectList.
|
|
3
|
+
* Menus close via Escape, back-arrow, and Ctrl-C.
|
|
4
|
+
*/
|
|
5
|
+
import { isFocusable, } from "@earendil-works/pi-tui";
|
|
6
|
+
import { installSeparatorSkip, withVimKeys } from "../helpers.js";
|
|
7
|
+
import { asListFields } from "../screen-host.js";
|
|
8
|
+
/** Horizontal arrows as main-list keys (→ enters, ← escapes); submenus get them raw. */
|
|
9
|
+
const HORIZONTAL_ARROWS = new Map([
|
|
10
|
+
["\x1b[C", "\r"],
|
|
11
|
+
["\x1bOC", "\r"],
|
|
12
|
+
["\x1b[D", "\x1b"],
|
|
13
|
+
["\x1bOD", "\x1b"],
|
|
14
|
+
]);
|
|
15
|
+
export class SettingsListWrapper {
|
|
16
|
+
settingsList;
|
|
17
|
+
title;
|
|
18
|
+
theme;
|
|
19
|
+
separatorChar;
|
|
20
|
+
passthroughKeys;
|
|
21
|
+
constructor(settingsList, options) {
|
|
22
|
+
// A list body navigates with j/k; a passthrough body takes keys as they come.
|
|
23
|
+
this.settingsList = options.passthroughKeys
|
|
24
|
+
? settingsList
|
|
25
|
+
: withVimKeys(settingsList);
|
|
26
|
+
this.title = options.title;
|
|
27
|
+
this.theme = options.theme;
|
|
28
|
+
this.separatorChar = options.separatorChar ?? "─";
|
|
29
|
+
this.passthroughKeys = options.passthroughKeys ?? false;
|
|
30
|
+
const list = asListFields(this.settingsList);
|
|
31
|
+
// SelectList has no onCancel; wire it so Escape/back-arrow/Ctrl-C close the menu.
|
|
32
|
+
if (options.onCancel && !list.onCancel) {
|
|
33
|
+
const closeMenu = options.onCancel;
|
|
34
|
+
list.onCancel = () => closeMenu();
|
|
35
|
+
}
|
|
36
|
+
// Menus push their own SEPARATOR_ID items; keep the cursor off them.
|
|
37
|
+
if (options.onCancel) {
|
|
38
|
+
installSeparatorSkip(list);
|
|
39
|
+
}
|
|
40
|
+
// Descriptions render from the items, so a bare reset stays correct.
|
|
41
|
+
if (options.onRebuild) {
|
|
42
|
+
const rebuild = (newItems, focusId) => {
|
|
43
|
+
list.items = newItems;
|
|
44
|
+
list.filteredItems = newItems;
|
|
45
|
+
list.submenuComponent = null;
|
|
46
|
+
// Ids survive a rebuild that reorders or drops rows; an id that is gone
|
|
47
|
+
// falls back to the reset row.
|
|
48
|
+
const focusIndex = newItems.findIndex((item) => item.id === focusId);
|
|
49
|
+
list.selectedIndex = focusIndex > 0 ? focusIndex : 0;
|
|
50
|
+
};
|
|
51
|
+
options.onRebuild(rebuild);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
invalidate() {
|
|
55
|
+
this.settingsList.invalidate();
|
|
56
|
+
}
|
|
57
|
+
get submenuComponent() {
|
|
58
|
+
return asListFields(this.settingsList).submenuComponent ?? null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Whether a leaf is focused, so this list is not the control receiving keys.
|
|
62
|
+
*/
|
|
63
|
+
get hasSubmenu() {
|
|
64
|
+
return isFocusable(this.submenuComponent);
|
|
65
|
+
}
|
|
66
|
+
handleInput(data) {
|
|
67
|
+
// An open submenu owns every key: a text field there reads j/k as letters,
|
|
68
|
+
// a list there maps them itself.
|
|
69
|
+
if (this.passthroughKeys || this.hasSubmenu) {
|
|
70
|
+
this.settingsList.handleInput?.(data);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const mainListKey = HORIZONTAL_ARROWS.get(data);
|
|
74
|
+
if (mainListKey !== undefined) {
|
|
75
|
+
this.settingsList.handleInput?.(mainListKey);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.settingsList.handleInput?.(data);
|
|
79
|
+
}
|
|
80
|
+
render(width) {
|
|
81
|
+
const lines = [];
|
|
82
|
+
lines.push(this.separatorChar.repeat(width));
|
|
83
|
+
lines.push("");
|
|
84
|
+
const styledTitle = this.theme.bold(this.theme.fg("accent", this.title));
|
|
85
|
+
lines.push(" " + styledTitle);
|
|
86
|
+
lines.push("");
|
|
87
|
+
// Strip pi-tui's trailing hint line; descriptions already cover it.
|
|
88
|
+
const settingsLines = this.settingsList.render(width);
|
|
89
|
+
const hintPattern = /Enter\/Space|Esc to cancel/;
|
|
90
|
+
if (settingsLines.length >= 2 &&
|
|
91
|
+
hintPattern.test(settingsLines[settingsLines.length - 1] ?? "")) {
|
|
92
|
+
lines.push(...settingsLines.slice(0, -2));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
lines.push(...settingsLines);
|
|
96
|
+
}
|
|
97
|
+
lines.push("");
|
|
98
|
+
lines.push(this.separatorChar.repeat(width));
|
|
99
|
+
return lines;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paginated, searchable pick-list dialog.
|
|
3
|
+
*
|
|
4
|
+
* Same building blocks as pi's ModelSelectorComponent without the SettingsManager dependency.
|
|
5
|
+
*/
|
|
6
|
+
import { Container, fuzzyFilter, getKeybindings, Input, Spacer, Text, } from "@earendil-works/pi-tui";
|
|
7
|
+
import { DynamicBorder } from "@earendil-works/pi-coding-agent";
|
|
8
|
+
const MAX_VISIBLE = 10;
|
|
9
|
+
/** Searchable selection dialog. Rendering mirrors pi's ModelSelectorComponent. */
|
|
10
|
+
export class SearchableSelectDialog extends Container {
|
|
11
|
+
searchInput;
|
|
12
|
+
listContainer;
|
|
13
|
+
items;
|
|
14
|
+
filteredItems;
|
|
15
|
+
selectedIndex;
|
|
16
|
+
currentValue;
|
|
17
|
+
callbacks;
|
|
18
|
+
theme;
|
|
19
|
+
// Propagated to searchInput for the IME cursor.
|
|
20
|
+
_focused = false;
|
|
21
|
+
get focused() {
|
|
22
|
+
return this._focused;
|
|
23
|
+
}
|
|
24
|
+
set focused(value) {
|
|
25
|
+
this._focused = value;
|
|
26
|
+
this.searchInput.focused = value;
|
|
27
|
+
}
|
|
28
|
+
constructor(items, currentValue, callbacks, theme) {
|
|
29
|
+
super();
|
|
30
|
+
this.items = items;
|
|
31
|
+
this.currentValue = currentValue;
|
|
32
|
+
this.callbacks = callbacks;
|
|
33
|
+
this.theme = theme;
|
|
34
|
+
this.filteredItems = [...items];
|
|
35
|
+
const currentIdx = items.findIndex((m) => m.value === currentValue);
|
|
36
|
+
this.selectedIndex = currentIdx >= 0 ? currentIdx : 0;
|
|
37
|
+
this.addChild(new DynamicBorder());
|
|
38
|
+
this.addChild(new Spacer(1));
|
|
39
|
+
this.searchInput = new Input();
|
|
40
|
+
this.searchInput.onSubmit = () => {
|
|
41
|
+
if (this.filteredItems[this.selectedIndex]) {
|
|
42
|
+
this.callbacks.onSelect(this.filteredItems[this.selectedIndex].value);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
this.addChild(this.searchInput);
|
|
46
|
+
this.addChild(new Spacer(1));
|
|
47
|
+
this.listContainer = new Container();
|
|
48
|
+
this.addChild(this.listContainer);
|
|
49
|
+
this.addChild(new Spacer(1));
|
|
50
|
+
this.addChild(new DynamicBorder());
|
|
51
|
+
this.updateList();
|
|
52
|
+
}
|
|
53
|
+
handleInput(keyData) {
|
|
54
|
+
const kb = getKeybindings();
|
|
55
|
+
if (this.filteredItems.length === 0) {
|
|
56
|
+
if (kb.matches(keyData, "tui.select.up") ||
|
|
57
|
+
kb.matches(keyData, "tui.select.down") ||
|
|
58
|
+
kb.matches(keyData, "tui.select.pageUp") ||
|
|
59
|
+
kb.matches(keyData, "tui.select.pageDown")) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (kb.matches(keyData, "tui.select.up")) {
|
|
64
|
+
this.selectedIndex =
|
|
65
|
+
this.selectedIndex === 0
|
|
66
|
+
? this.filteredItems.length - 1
|
|
67
|
+
: this.selectedIndex - 1;
|
|
68
|
+
this.updateList();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (kb.matches(keyData, "tui.select.down")) {
|
|
72
|
+
this.selectedIndex =
|
|
73
|
+
this.selectedIndex === this.filteredItems.length - 1
|
|
74
|
+
? 0
|
|
75
|
+
: this.selectedIndex + 1;
|
|
76
|
+
this.updateList();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (kb.matches(keyData, "tui.select.pageUp")) {
|
|
80
|
+
this.selectedIndex = Math.max(0, this.selectedIndex - MAX_VISIBLE);
|
|
81
|
+
this.updateList();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (kb.matches(keyData, "tui.select.pageDown")) {
|
|
85
|
+
this.selectedIndex = Math.min(this.filteredItems.length - 1, this.selectedIndex + MAX_VISIBLE);
|
|
86
|
+
this.updateList();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (kb.matches(keyData, "tui.select.confirm")) {
|
|
90
|
+
const selected = this.filteredItems.at(this.selectedIndex);
|
|
91
|
+
if (selected) {
|
|
92
|
+
this.callbacks.onSelect(selected.value);
|
|
93
|
+
}
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (kb.matches(keyData, "tui.select.cancel")) {
|
|
97
|
+
this.callbacks.onCancel();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.searchInput.handleInput(keyData);
|
|
101
|
+
this.filterItems();
|
|
102
|
+
}
|
|
103
|
+
invalidate() {
|
|
104
|
+
// No cached state to invalidate
|
|
105
|
+
}
|
|
106
|
+
filterItems() {
|
|
107
|
+
const query = this.searchInput.getValue();
|
|
108
|
+
if (!query) {
|
|
109
|
+
this.filteredItems = [...this.items];
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
this.filteredItems = fuzzyFilter(this.items, query, (item) => `${item.label} ${item.provider} ${item.value ?? ""}`);
|
|
113
|
+
}
|
|
114
|
+
this.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredItems.length - 1));
|
|
115
|
+
this.updateList();
|
|
116
|
+
}
|
|
117
|
+
updateList() {
|
|
118
|
+
this.listContainer.clear();
|
|
119
|
+
const { filteredItems } = this;
|
|
120
|
+
if (filteredItems.length === 0) {
|
|
121
|
+
this.listContainer.addChild(new Text(this.theme.fg("muted", " No matching items"), 0, 0));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const startIndex = Math.max(0, Math.min(this.selectedIndex - Math.floor(MAX_VISIBLE / 2), filteredItems.length - MAX_VISIBLE));
|
|
125
|
+
const endIndex = Math.min(startIndex + MAX_VISIBLE, filteredItems.length);
|
|
126
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
127
|
+
const item = filteredItems.at(i);
|
|
128
|
+
if (!item)
|
|
129
|
+
continue;
|
|
130
|
+
const isSelected = i === this.selectedIndex;
|
|
131
|
+
const isCurrent = item.value === this.currentValue;
|
|
132
|
+
const labelText = isSelected
|
|
133
|
+
? this.theme.fg("accent", "→ ") + this.theme.fg("accent", item.label)
|
|
134
|
+
: ` ${item.label}`;
|
|
135
|
+
const providerBadge = item.provider
|
|
136
|
+
? this.theme.fg("muted", `[${item.provider}]`)
|
|
137
|
+
: "";
|
|
138
|
+
const checkmark = isCurrent ? this.theme.fg("success", " ✓") : "";
|
|
139
|
+
const line = `${labelText} ${providerBadge}${checkmark}`;
|
|
140
|
+
this.listContainer.addChild(new Text(line, 0, 0));
|
|
141
|
+
}
|
|
142
|
+
if (startIndex > 0 || endIndex < filteredItems.length) {
|
|
143
|
+
const scrollInfo = this.theme.fg("muted", ` (${this.selectedIndex + 1}/${filteredItems.length})`);
|
|
144
|
+
this.listContainer.addChild(new Text(scrollInfo, 0, 0));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
package/dist/ui/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* utils.ts — security helpers and general utilities.
|
|
3
|
+
* isUnsafeName guards agent/skill name resolution against path traversal.
|
|
4
|
+
*/
|
|
5
|
+
/** Alphanumeric, hyphen, underscore, dot — no leading dot. */
|
|
6
|
+
export function isUnsafeName(name) {
|
|
7
|
+
return (!name || name.length > 128 || !/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(name));
|
|
8
|
+
}
|
|
9
|
+
/** Tuple shape: the agent-template Zod schema builds an enum from it, so the two can never drift. */
|
|
10
|
+
export const VALID_THINKING_LEVELS = [
|
|
11
|
+
"off",
|
|
12
|
+
"minimal",
|
|
13
|
+
"low",
|
|
14
|
+
"medium",
|
|
15
|
+
"high",
|
|
16
|
+
"xhigh",
|
|
17
|
+
"max",
|
|
18
|
+
];
|
|
19
|
+
export function parseThinkingLevel(raw) {
|
|
20
|
+
if (raw === undefined)
|
|
21
|
+
return undefined;
|
|
22
|
+
return VALID_THINKING_LEVELS.includes(raw)
|
|
23
|
+
? raw
|
|
24
|
+
: undefined;
|
|
25
|
+
}
|
|
26
|
+
/** Line-based TUI output breaks on raw CR/LF. */
|
|
27
|
+
function toSingleLine(msg) {
|
|
28
|
+
return msg.replace(/[\r\n]+/g, " ").trim();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Await a delay. The timer is left ref'd: an unref'd timer lets an otherwise
|
|
32
|
+
* idle event loop exit mid-wait, so an awaited delay would never resolve.
|
|
33
|
+
*/
|
|
34
|
+
export function sleep(ms) {
|
|
35
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
36
|
+
}
|
|
37
|
+
export function errorMessage(err) {
|
|
38
|
+
return toSingleLine(err instanceof Error ? err.message : String(err));
|
|
39
|
+
}
|
|
40
|
+
/** Null when unparseable (no slash or empty provider). */
|
|
41
|
+
export function parseModelKey(value) {
|
|
42
|
+
// Config values flow from JSON, so a mistyped value can reach here at runtime.
|
|
43
|
+
if (typeof value !== "string")
|
|
44
|
+
return null;
|
|
45
|
+
const slashIdx = value.indexOf("/");
|
|
46
|
+
if (slashIdx <= 0)
|
|
47
|
+
return null;
|
|
48
|
+
return {
|
|
49
|
+
provider: value.slice(0, slashIdx),
|
|
50
|
+
modelId: value.slice(slashIdx + 1),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function findModelInRegistry(value, registry, fallback) {
|
|
54
|
+
if (!value)
|
|
55
|
+
return fallback;
|
|
56
|
+
const parsed = parseModelKey(value);
|
|
57
|
+
if (!parsed)
|
|
58
|
+
return fallback;
|
|
59
|
+
return registry.find(parsed.provider, parsed.modelId) ?? fallback;
|
|
60
|
+
}
|
|
61
|
+
/** Shared by agent-runner and worktree-validator. */
|
|
62
|
+
export const GIT_EXEC_TIMEOUT_MS = 5000;
|
|
63
|
+
/**
|
|
64
|
+
* Exhaustiveness guard for a discriminated union's discriminant: every member
|
|
65
|
+
* must have its own arm, because an unhandled one leaves this argument typed
|
|
66
|
+
* as `never` and fails to compile. Untyped input can still reach the throw.
|
|
67
|
+
*/
|
|
68
|
+
export function assertNever(value) {
|
|
69
|
+
throw new Error(`Unhandled variant: ${JSON.stringify(value)}`);
|
|
70
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name = "with code review"
|
|
2
|
+
display_name = "with code review"
|
|
3
|
+
guidance = "If you make changes to the code: before committing them, launch the code review tool. Once the code is approved by the user, commit the changes to your branch. (This applies even if the task prompt says not to commit — commits stay on that branch and are needed for merging.)"
|
|
4
|
+
|
|
5
|
+
[cues]
|
|
6
|
+
spawned = '''
|
|
7
|
+
Success! You delegated to an agent. A notification will arrive when done - USER: do not poll, don't check status and don't duplicate the delegated work!{{#has_worktree}}
|
|
8
|
+
(Worktree: {{worktree_path}} (branch {{worktree_branch}}) — the agent's commits land on that branch, never on main. Merge it with the merge_cowboy_branch tool when done, then remove the worktree with cleanup_cowboy_agent.){{/has_worktree}}
|
|
9
|
+
|
|
10
|
+
Agent ID: {{agent_id}}'''
|
|
11
|
+
queued = '''
|
|
12
|
+
Agent QUEUED — the concurrency limit is reached ({{queue_running}} {{queue_running_label}} already spawned), so this task is waiting for a slot. It is NOT spawned yet: the process has not started. It will start automatically when another agent settles; you'll get a message when it starts and when it settles. Do NOT re-delegate — this task IS in flight.{{#has_worktree}}
|
|
13
|
+
(Worktree: {{worktree_path}} (branch {{worktree_branch}}) — the agent's commits land on that branch, never on main. Merge it with the merge_cowboy_branch tool when done, then remove the worktree with cleanup_cowboy_agent.){{/has_worktree}}
|
|
14
|
+
|
|
15
|
+
Agent ID: {{agent_id}}'''
|
|
16
|
+
settled = '''
|
|
17
|
+
{{result}}{{#error}}
|
|
18
|
+
|
|
19
|
+
Error: {{error}}{{/error}}{{#has_worktree}}
|
|
20
|
+
(Worktree: {{worktree_path}} (branch {{worktree_branch}}){{#retention}} — KEPT: {{retention}}{{/retention}}.{{#process_alive}} The agent process and its herdr pane stay until you call cleanup_cowboy_agent — its pane is closed, which ends that process.{{/process_alive}} {{#retention}}Clean the worktree up, then call cleanup_cowboy_agent to remove it.{{/retention}}{{^retention}}The worktree stays until you call cleanup_cowboy_agent to remove it — call it once the branch is merged or rejected.{{/retention}}){{/has_worktree}}{{status_note}}'''
|
package/package.json
CHANGED
|
@@ -1,7 +1,113 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-cowboy",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.3.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"packageManager": "pnpm@12.9.1",
|
|
6
|
+
"description": "Agent orchestrator for pi: each subagent runs as its own pi process in a background Herdr pane, isolated by a copy-on-write git worktree.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"pi-package",
|
|
9
|
+
"pi",
|
|
10
|
+
"pi-agent",
|
|
11
|
+
"pi-coding-agent",
|
|
12
|
+
"pi-extension",
|
|
13
|
+
"subagents",
|
|
14
|
+
"herdr",
|
|
15
|
+
"ai",
|
|
16
|
+
"agents"
|
|
17
|
+
],
|
|
5
18
|
"license": "MIT",
|
|
6
|
-
"
|
|
19
|
+
"author": "electric-dragon-80000v",
|
|
20
|
+
"homepage": "https://github.com/electric-dragon-80000v/pi-cowboy#readme",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/electric-dragon-80000v/pi-cowboy.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/electric-dragon-80000v/pi-cowboy/issues"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=24.20.0",
|
|
30
|
+
"pnpm": ">=12"
|
|
31
|
+
},
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/",
|
|
35
|
+
"!dist/**/*.tsbuildinfo",
|
|
36
|
+
"!dist/**/*.d.ts",
|
|
37
|
+
"agents/",
|
|
38
|
+
"orchestrators/",
|
|
39
|
+
"docs/assets/*.png",
|
|
40
|
+
"!docs/assets/logo.png",
|
|
41
|
+
"!docs/assets/logo-pi-package.png",
|
|
42
|
+
"README.md",
|
|
43
|
+
"LICENSE"
|
|
44
|
+
],
|
|
45
|
+
"exports": {
|
|
46
|
+
".": "./dist/index.js",
|
|
47
|
+
"./package.json": "./package.json"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"format": "prettier --write src/ test/ scripts/ lint/ docs/",
|
|
51
|
+
"format:check": "prettier --check src/ test/ scripts/ lint/ docs/",
|
|
52
|
+
"typecheck": "tsc6 --noEmit",
|
|
53
|
+
"find-unused": "node --disable-warning=ExperimentalWarning scripts/find-unused.ts",
|
|
54
|
+
"build": "tsc6 -p tsconfig.build.json",
|
|
55
|
+
"prepack": "pnpm run build",
|
|
56
|
+
"test": "pnpm run build && vitest run",
|
|
57
|
+
"test:unit": "vitest run --project unit",
|
|
58
|
+
"test:integration": "pnpm run build && vitest run --project integration-no-cow --project integration-cow",
|
|
59
|
+
"test:integration-no-cow": "pnpm run build && vitest run --project integration-no-cow",
|
|
60
|
+
"test:integration-cow": "pnpm run build && vitest run --project integration-cow",
|
|
61
|
+
"lint": "oxlint",
|
|
62
|
+
"lint:fix": "oxlint --fix",
|
|
63
|
+
"commitlint": "commitlint",
|
|
64
|
+
"release": "semantic-release",
|
|
65
|
+
"release:stage": "npm stage publish",
|
|
66
|
+
"prepare": "husky"
|
|
67
|
+
},
|
|
68
|
+
"pi": {
|
|
69
|
+
"image": "https://raw.githubusercontent.com/electric-dragon-80000v/pi-cowboy/main/docs/assets/logo-pi-package.png",
|
|
70
|
+
"video": "https://raw.githubusercontent.com/electric-dragon-80000v/pi-cowboy/main/docs/assets/pi-cowboy-ad-trimmed.mp4",
|
|
71
|
+
"extensions": [
|
|
72
|
+
"./dist/index.js"
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"@earendil-works/pi-ai": "*",
|
|
77
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
78
|
+
"@earendil-works/pi-tui": "*",
|
|
79
|
+
"typebox": "*"
|
|
80
|
+
},
|
|
81
|
+
"devDependencies": {
|
|
82
|
+
"@commitlint/cli": "^21.2.3",
|
|
83
|
+
"@commitlint/config-conventional": "^21.2.3",
|
|
84
|
+
"@commitlint/types": "^21.2.3",
|
|
85
|
+
"@semantic-release/changelog": "^7.0.0",
|
|
86
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
87
|
+
"@semantic-release/exec": "^7.1.0",
|
|
88
|
+
"@semantic-release/git": "^11.0.1",
|
|
89
|
+
"@semantic-release/github": "^12.0.10",
|
|
90
|
+
"@semantic-release/npm": "^13.2.0",
|
|
91
|
+
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
92
|
+
"@types/estree": "^1.0.9",
|
|
93
|
+
"@types/mustache": "^4.2.6",
|
|
94
|
+
"@types/node": "^26.6.4",
|
|
95
|
+
"@vitest/ui": "^5.0.3",
|
|
96
|
+
"eslint": "^10.12.0",
|
|
97
|
+
"eslint-plugin-import-x": "^4.17.1",
|
|
98
|
+
"husky": "^9.1.7",
|
|
99
|
+
"oxlint": "1.86.0",
|
|
100
|
+
"oxlint-tsgolint": "7.0.2003",
|
|
101
|
+
"prettier": "^3.9.9",
|
|
102
|
+
"semantic-release": "^25.0.9",
|
|
103
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
104
|
+
"vitest": "^5.0.3"
|
|
105
|
+
},
|
|
106
|
+
"dependencies": {
|
|
107
|
+
"caller-id": "^0.1.0",
|
|
108
|
+
"crockford-base32": "^2.1.0",
|
|
109
|
+
"mustache": "^4.2.0",
|
|
110
|
+
"smol-toml": "^1.9.0",
|
|
111
|
+
"zod": "^4.6.5"
|
|
112
|
+
}
|
|
7
113
|
}
|