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.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +281 -2
  3. package/agents/explore.toml +40 -0
  4. package/dist/agents/agent-assets.js +261 -0
  5. package/dist/agents/agent-cleanup.js +284 -0
  6. package/dist/agents/agent-discovery.js +108 -0
  7. package/dist/agents/agent-host.js +10 -0
  8. package/dist/agents/agent-manager.js +367 -0
  9. package/dist/agents/agent-reviver.js +64 -0
  10. package/dist/agents/agent-runner.js +288 -0
  11. package/dist/agents/agent-spawn-store.js +57 -0
  12. package/dist/agents/agent-template.js +46 -0
  13. package/dist/agents/agent-types.js +144 -0
  14. package/dist/agents/batch.js +92 -0
  15. package/dist/agents/cleanup-policy.js +194 -0
  16. package/dist/agents/cleanup-report.js +128 -0
  17. package/dist/agents/default-agents.js +19 -0
  18. package/dist/agents/harness/pi-bolt.js +15 -0
  19. package/dist/agents/harness/pi-compatible.js +68 -0
  20. package/dist/agents/harness/pig.js +16 -0
  21. package/dist/agents/harness/registry.js +27 -0
  22. package/dist/agents/harness.js +32 -0
  23. package/dist/agents/result-file-permissions.js +29 -0
  24. package/dist/agents/run-state.js +270 -0
  25. package/dist/agents/schemas/cleanup-batch.schema.js +19 -0
  26. package/dist/agents/schemas/cowboy-agents.schema.js +39 -0
  27. package/dist/agents/schemas/merge-batch.schema.js +25 -0
  28. package/dist/agents/schemas/steer-batch.schema.js +22 -0
  29. package/dist/agents/schemas/stop-batch.schema.js +18 -0
  30. package/dist/agents/spawn-defaults.js +70 -0
  31. package/dist/agents/subagent-session.js +601 -0
  32. package/dist/agents/tool-cleanup.js +57 -0
  33. package/dist/agents/tool-execution.js +125 -0
  34. package/dist/agents/tool-merge.js +190 -0
  35. package/dist/agents/tool-result.js +17 -0
  36. package/dist/agents/tool-steer.js +89 -0
  37. package/dist/agents/types.js +1 -0
  38. package/dist/availability.js +38 -0
  39. package/dist/config/config-io.js +261 -0
  40. package/dist/config/config-store.js +321 -0
  41. package/dist/config/config-validation.js +173 -0
  42. package/dist/config/layered-config.js +117 -0
  43. package/dist/config/types.js +23 -0
  44. package/dist/cow-support-launch.js +43 -0
  45. package/dist/events.js +146 -0
  46. package/dist/extension-toggle.js +28 -0
  47. package/dist/harness-availability-launch.js +23 -0
  48. package/dist/index.js +52 -0
  49. package/dist/infrastructure/exec-path.js +35 -0
  50. package/dist/infrastructure/git/cow-clone.js +398 -0
  51. package/dist/infrastructure/git/git-materializer.js +342 -0
  52. package/dist/infrastructure/git/git-merger.js +234 -0
  53. package/dist/infrastructure/git/git-retention.js +43 -0
  54. package/dist/infrastructure/git/git-runner.js +145 -0
  55. package/dist/infrastructure/git/git-worktree.js +143 -0
  56. package/dist/infrastructure/git/index.js +11 -0
  57. package/dist/infrastructure/git-client.js +11 -0
  58. package/dist/infrastructure/herdr/agent-stopper.js +60 -0
  59. package/dist/infrastructure/herdr/agents.js +329 -0
  60. package/dist/infrastructure/herdr/herdr-client.js +36 -0
  61. package/dist/infrastructure/herdr/herdr-transport.js +158 -0
  62. package/dist/infrastructure/herdr/index.js +15 -0
  63. package/dist/infrastructure/herdr/panes.js +174 -0
  64. package/dist/infrastructure/herdr/polling.js +44 -0
  65. package/dist/infrastructure/herdr/worktrees.js +76 -0
  66. package/dist/infrastructure/herdr-client.js +6 -0
  67. package/dist/infrastructure/herdr-host.js +163 -0
  68. package/dist/logger.js +79 -0
  69. package/dist/models/model-groups.js +72 -0
  70. package/dist/models/model-precedence.js +50 -0
  71. package/dist/models/model-request.js +108 -0
  72. package/dist/orchestrators/briefing-section.js +14 -0
  73. package/dist/orchestrators/context.js +116 -0
  74. package/dist/orchestrators/cues.js +90 -0
  75. package/dist/orchestrators/default-orchestrators.js +36 -0
  76. package/dist/orchestrators/orchestrator-discovery.js +68 -0
  77. package/dist/orchestrators/orchestrator-template.js +43 -0
  78. package/dist/orchestrators/orchestrator-types.js +78 -0
  79. package/dist/orchestrators/protocol.js +292 -0
  80. package/dist/orchestrators/types.js +7 -0
  81. package/dist/paths.js +66 -0
  82. package/dist/pi-settings.js +7 -0
  83. package/dist/predicates.js +25 -0
  84. package/dist/prompt/prompts.js +110 -0
  85. package/dist/prompt/skill-loader.js +153 -0
  86. package/dist/prompt/subagent-system-prompt.js +173 -0
  87. package/dist/registration.js +220 -0
  88. package/dist/shell.js +225 -0
  89. package/dist/spawn/cow-support.js +53 -0
  90. package/dist/spawn/herdr-launcher.js +80 -0
  91. package/dist/spawn/repo-lock.js +34 -0
  92. package/dist/spawn/sandbox.js +286 -0
  93. package/dist/spawn/spawn-coordinator.js +255 -0
  94. package/dist/spawn/spawn-id.js +39 -0
  95. package/dist/spawn/worktree-policy.js +137 -0
  96. package/dist/status-note.js +30 -0
  97. package/dist/subagent/ipc-protocol.js +68 -0
  98. package/dist/subagent/ipc.js +110 -0
  99. package/dist/subagent/pane-supervisor.js +24 -0
  100. package/dist/subagent/socket-ipc.js +240 -0
  101. package/dist/subagent/supervisor.js +315 -0
  102. package/dist/task-registry.js +258 -0
  103. package/dist/templates/template-files.js +84 -0
  104. package/dist/types.js +84 -0
  105. package/dist/ui/action-report.js +21 -0
  106. package/dist/ui/format.js +47 -0
  107. package/dist/ui/indicator.js +480 -0
  108. package/dist/ui/menu/helpers.js +227 -0
  109. package/dist/ui/menu/menu-agent-settings.js +182 -0
  110. package/dist/ui/menu/menu-agent-status.js +444 -0
  111. package/dist/ui/menu/menu-concurrency.js +226 -0
  112. package/dist/ui/menu/menu-model-settings.js +244 -0
  113. package/dist/ui/menu/menu-spawn-defaults.js +71 -0
  114. package/dist/ui/menu/menu-spawn-wizard.js +367 -0
  115. package/dist/ui/menu/menu-spawn-worktree.js +107 -0
  116. package/dist/ui/menu/menu-system-prompt.js +104 -0
  117. package/dist/ui/menu/menu-worktree-command.js +150 -0
  118. package/dist/ui/menu/menus.js +187 -0
  119. package/dist/ui/menu/model-picker.js +160 -0
  120. package/dist/ui/menu/screen-host.js +87 -0
  121. package/dist/ui/menu/submenus/confirm.js +23 -0
  122. package/dist/ui/menu/submenus/model-select.js +42 -0
  123. package/dist/ui/menu/submenus/name-field.js +43 -0
  124. package/dist/ui/menu/submenus/numeric-input.js +61 -0
  125. package/dist/ui/menu/submenus/target-select.js +129 -0
  126. package/dist/ui/menu/submenus/text-editor.js +49 -0
  127. package/dist/ui/menu/submenus/worktree-command-name.js +73 -0
  128. package/dist/ui/menu/submenus/worktree-name.js +53 -0
  129. package/dist/ui/menu/wrappers/settings-list.js +101 -0
  130. package/dist/ui/searchable-select.js +147 -0
  131. package/dist/ui/types.js +1 -0
  132. package/dist/utils.js +70 -0
  133. package/docs/assets/grazing.png +0 -0
  134. package/docs/assets/herdr-containers.png +0 -0
  135. package/docs/assets/logo-transparent.png +0 -0
  136. package/orchestrators/with-code-review.toml +20 -0
  137. package/package.json +109 -3
@@ -0,0 +1,227 @@
1
+ import { SearchableSelectDialog, } from "../searchable-select.js";
2
+ import { parseModelKey } from "../../utils.js";
3
+ import { SwappableView } from "./screen-host.js";
4
+ export { actionReport } from "../action-report.js";
5
+ /** Group header marker. */
6
+ const GROUP_HEADER_KIND = "group-header";
7
+ /** Create a non-selectable group header row for SettingsList. */
8
+ export function headerItem(theme, label) {
9
+ return {
10
+ id: SEPARATOR_ID,
11
+ kind: GROUP_HEADER_KIND,
12
+ label: theme.bold(theme.fg("accent", label)),
13
+ currentValue: "",
14
+ };
15
+ }
16
+ /** Separator/section-header row id; installSeparatorSkip keeps the cursor off these. */
17
+ export const SEPARATOR_ID = "__sep__";
18
+ /** Real selectedIndex storage, off the list's own properties (see NavigableList). */
19
+ const rawIndexes = new WeakMap();
20
+ /**
21
+ * Keep navigation off SEPARATOR_ID rows by overriding selectedIndex with a
22
+ * get/set pair (raw index in rawIndexes). pi-tui writes the index directly
23
+ * on up/down, so the setter intercepts every move: travel direction first,
24
+ * then the opposite, else stay put. Reads list.items (no caller filters).
25
+ * The construction index is sanitized the same way, so a menu starting on a
26
+ * header opens on the first selectable row.
27
+ */
28
+ export function installSeparatorSkip(list) {
29
+ if (!Array.isArray(list.items))
30
+ return;
31
+ const isSep = (item) => item?.value === SEPARATOR_ID || item?.id === SEPARATOR_ID;
32
+ // First non-separator past `start` in `step` direction, else out of bounds.
33
+ const firstNonSepFrom = (items, start, step) => {
34
+ let next = start + step;
35
+ while (next >= 0 && next < items.length && isSep(items[next]))
36
+ next += step;
37
+ return next;
38
+ };
39
+ const inBounds = (items, i) => i >= 0 && i < items.length;
40
+ // Seed only: first selectable at or after `start`, else nearest before, else 0.
41
+ const seedIndex = (items, start) => {
42
+ const clamped = Math.max(0, Math.min(start, items.length - 1));
43
+ for (let i = clamped; i < items.length; i += 1) {
44
+ if (!isSep(items[i]))
45
+ return i;
46
+ }
47
+ for (let i = clamped - 1; i >= 0; i -= 1) {
48
+ if (!isSep(items[i]))
49
+ return i;
50
+ }
51
+ return 0;
52
+ };
53
+ // Read before defineProperty: after it, the getter returns the unseeded WeakMap entry.
54
+ const initialIndex = list.selectedIndex ?? 0;
55
+ Object.defineProperty(list, "selectedIndex", {
56
+ get() {
57
+ return rawIndexes.get(list);
58
+ },
59
+ set(idx) {
60
+ const items = list.items;
61
+ const cur = rawIndexes.get(list) ?? 0;
62
+ const clamped = Math.max(0, Math.min(idx, items.length - 1));
63
+ if (!isSep(items[clamped])) {
64
+ rawIndexes.set(list, clamped);
65
+ return;
66
+ }
67
+ // Landed on a separator: travel direction first, then the opposite.
68
+ const step = idx > cur ? 1 : -1;
69
+ const fwd = firstNonSepFrom(items, clamped, step);
70
+ const back = firstNonSepFrom(items, clamped, -step);
71
+ if (inBounds(items, fwd))
72
+ rawIndexes.set(list, fwd);
73
+ else if (inBounds(items, back))
74
+ rawIndexes.set(list, back);
75
+ else
76
+ rawIndexes.set(list, clamped);
77
+ },
78
+ configurable: true,
79
+ });
80
+ rawIndexes.set(list, seedIndex(list.items, initialIndex));
81
+ }
82
+ /**
83
+ * SelectOptions from "provider/model-id" strings, inherit row first.
84
+ * With currentModel/configuredModels: current, then configured, then the rest.
85
+ */
86
+ export function buildModelOptions(rawOptions, currentModel, configuredModels) {
87
+ const items = [
88
+ { value: null, label: "(inherits parent)", provider: "" },
89
+ ];
90
+ const parsed = [];
91
+ for (const opt of rawOptions) {
92
+ const parsedKey = parseModelKey(opt);
93
+ if (!parsedKey)
94
+ continue;
95
+ parsed.push({
96
+ value: opt,
97
+ label: parsedKey.modelId,
98
+ provider: parsedKey.provider,
99
+ });
100
+ }
101
+ if (!currentModel && !configuredModels) {
102
+ items.push(...parsed);
103
+ return items;
104
+ }
105
+ const current = [];
106
+ const configured = [];
107
+ const remaining = [];
108
+ const added = new Set();
109
+ if (currentModel) {
110
+ const currentParsed = parseModelKey(currentModel);
111
+ if (currentParsed) {
112
+ current.push({
113
+ value: currentModel,
114
+ label: currentParsed.modelId,
115
+ provider: currentParsed.provider,
116
+ });
117
+ added.add(currentModel);
118
+ }
119
+ }
120
+ for (const modelId of configuredModels ?? []) {
121
+ if (added.has(modelId))
122
+ continue;
123
+ const parsedKey = parseModelKey(modelId);
124
+ if (parsedKey) {
125
+ configured.push({
126
+ value: modelId,
127
+ label: parsedKey.modelId,
128
+ provider: parsedKey.provider,
129
+ });
130
+ added.add(modelId);
131
+ }
132
+ }
133
+ for (const item of parsed) {
134
+ if (item.value != null && !added.has(item.value)) {
135
+ remaining.push(item);
136
+ }
137
+ }
138
+ items.push(...current, ...configured, ...remaining);
139
+ return items;
140
+ }
141
+ /** Deduplicated configured model ids (default + per-type overrides). */
142
+ export function extractConfiguredModels(agentConfig) {
143
+ const models = [];
144
+ if (agentConfig.default && typeof agentConfig.default === "string") {
145
+ models.push(agentConfig.default);
146
+ }
147
+ for (const [key, value] of Object.entries(agentConfig)) {
148
+ if (key !== "default" && typeof value === "string" && value.includes("/")) {
149
+ models.push(value);
150
+ }
151
+ }
152
+ return [...new Set(models)];
153
+ }
154
+ /** Build a SettingsListTheme from a pi-coding-agent Theme. */
155
+ export function buildSettingsListTheme(theme) {
156
+ return {
157
+ label: (text, selected) => (selected ? theme.fg("accent", text) : text),
158
+ value: (text, selected) => selected ? theme.fg("accent", text) : theme.fg("muted", text),
159
+ description: (text) => theme.fg("dim", text),
160
+ // "→ " matches the 2-space non-selected prefix, so rows don't shift under the cursor.
161
+ cursor: theme.fg("accent", "→ "),
162
+ hint: (text) => theme.fg("dim", text),
163
+ };
164
+ }
165
+ /**
166
+ * Pure numeric validation. Returns parsed number ≥ min, or undefined.
167
+ */
168
+ export function validateNumeric(value, min) {
169
+ const trimmed = value.trim();
170
+ // Accept integers and decimals (e.g. 0.5 for 30 seconds)
171
+ if (!/^\d*\.?\d+$/.test(trimmed))
172
+ return undefined;
173
+ const parsed = parseFloat(trimmed);
174
+ if (parsed < min)
175
+ return undefined;
176
+ return parsed;
177
+ }
178
+ /** Vim navigation keys, as the arrows pi-tui's lists bind. */
179
+ const VIM_ARROWS = new Map([
180
+ ["k", "\x1b[A"],
181
+ ["j", "\x1b[B"],
182
+ ]);
183
+ /**
184
+ * j/k as list navigation. pi-tui's lists bind arrows only, so this decorates a
185
+ * list in place (handleInput on the instance; instanceof and plain field reads
186
+ * are untouched): a key goes verbatim to an open submenu — whatever is focused
187
+ * there decides what it means — and becomes an arrow only while this list
188
+ * itself is the focused control.
189
+ */
190
+ export function withVimKeys(list) {
191
+ const inner = list;
192
+ const handle = inner.handleInput?.bind(inner);
193
+ if (!handle)
194
+ return list;
195
+ inner.handleInput = (data) => {
196
+ const arrow = inner.submenuComponent ? undefined : VIM_ARROWS.get(data);
197
+ handle(arrow ?? data);
198
+ };
199
+ return list;
200
+ }
201
+ /** SelectListTheme matching buildSettingsListTheme's style. */
202
+ export function buildSelectListTheme(theme) {
203
+ return {
204
+ selectedPrefix: () => theme.fg("accent", "→ "),
205
+ selectedText: (text) => theme.fg("accent", text),
206
+ description: (text) => theme.fg("muted", text),
207
+ scrollInfo: (text) => theme.fg("dim", text),
208
+ noMatch: (text) => theme.fg("dim", text),
209
+ };
210
+ }
211
+ /**
212
+ * Searchable pick-list submenu over a flat option list. onSelect may return
213
+ * a Component to chain into; returning void leaves closing to done().
214
+ */
215
+ export function createSearchableSelect(items, callbacks, theme) {
216
+ let view;
217
+ const selector = new SearchableSelectDialog(items, null, {
218
+ onSelect: (value) => {
219
+ const next = callbacks.onSelect(value);
220
+ if (next)
221
+ view.activate(next);
222
+ },
223
+ onCancel: callbacks.onCancel,
224
+ }, theme);
225
+ view = new SwappableView(selector);
226
+ return view;
227
+ }
@@ -0,0 +1,182 @@
1
+ /**
2
+ * menu-agent-settings.ts — the spawn-options screen: spawn defaults, delivery,
3
+ * worktrees, and tools.
4
+ *
5
+ * SettingsList keeps cursor state internally (ctx.ui.select resets it).
6
+ */
7
+ import { SettingsList, SelectList, Input, } from "@earendil-works/pi-tui";
8
+ import { VALID_THINKING_LEVELS } from "../../utils.js";
9
+ import { defaultWorktreeRoot } from "../../paths.js";
10
+ import { HARNESS_IDS, parseHarnessId, } from "../../agents/harness.js";
11
+ import { isAvailable, selectable, } from "../../availability.js";
12
+ import { parseWorktreeCheckoutType, parseWorktreeMaterialization, VALID_WORKTREE_CHECKOUT_TYPES, VALID_WORKTREE_MATERIALIZATIONS, } from "../../spawn/worktree-policy.js";
13
+ import { getCowAvailability, getHarnessAvailability, getHarnessType, getPiInstance, getStore, getWorktreeMaterialization, } from "../../shell.js";
14
+ import { refreshCowSupportProbe } from "../../cow-support-launch.js";
15
+ import { SettingsListWrapper } from "./wrappers/settings-list.js";
16
+ import { ScreenHost } from "./screen-host.js";
17
+ import { createTargetSelectSubmenu } from "./submenus/target-select.js";
18
+ import { SEPARATOR_ID, buildSettingsListTheme, buildSelectListTheme, headerItem, withVimKeys, } from "./helpers.js";
19
+ /**
20
+ * The harness row's description. Narrows with the row: an unlaunchable harness is
21
+ * named as missing rather than silently absent from the values.
22
+ */
23
+ function harnessDescription(availability) {
24
+ const base = "Harness that launches agents whose template omits harness_type. pi = the real pi binary; pig and pi-bolt = pi-compatible binaries launched through a shell function in the agent's own pane.";
25
+ const missing = HARNESS_IDS.filter((id) => id !== "pi" && !isAvailable(id, availability));
26
+ return missing.length === 0
27
+ ? base
28
+ : `${base} Not on PATH: ${missing.join(", ")}.`;
29
+ }
30
+ export async function showSpawnOptionsMenu(ctx) {
31
+ const store = getStore();
32
+ /** " [project]" when the effective value comes from the project layer. */
33
+ const projectTag = (key) => store.hasProjectModelKey(key) ? " [project]" : "";
34
+ /** Submenu: pick a persisted layer (global or project), then edit the value. No session target. */
35
+ const persistedTargetSubmenu = (theme, onPick) => createTargetSelectSubmenu({
36
+ theme,
37
+ projectOffered: store.isProjectWritable,
38
+ includeSession: false,
39
+ // Narrow TargetChoice: only global/project are offered here.
40
+ onPick: (target, pickDone) => onPick(target, pickDone),
41
+ });
42
+ const buildItems = (theme) => {
43
+ return [
44
+ headerItem(theme, "Spawn defaults"),
45
+ { id: SEPARATOR_ID, label: " ", currentValue: "" },
46
+ {
47
+ id: "defaultThinking",
48
+ label: "Default thinking level",
49
+ currentValue: `${store.agent.defaultThinking ?? "inherit"}${projectTag("defaultThinking")}`,
50
+ submenu: persistedTargetSubmenu(theme, (target, pickDone) => {
51
+ const levelItems = [...VALID_THINKING_LEVELS, "inherit"].map((v) => ({
52
+ value: v,
53
+ label: v,
54
+ }));
55
+ const list = withVimKeys(new SelectList(levelItems, 10, buildSelectListTheme(theme)));
56
+ list.onSelect = (item) => {
57
+ store.mutate.agent.setDefaultThinking(item.value === "inherit"
58
+ ? undefined
59
+ : item.value, target);
60
+ ctx.ui.notify(`Default thinking level set to ${item.value} (${target})`, "info");
61
+ pickDone(item.value);
62
+ };
63
+ list.onCancel = () => pickDone();
64
+ return list;
65
+ }),
66
+ description: "Thinking level applied when an agent template omits one.",
67
+ },
68
+ {
69
+ id: "harnessType",
70
+ label: "Default harness",
71
+ currentValue: getHarnessType(),
72
+ values: [...selectable(HARNESS_IDS, getHarnessAvailability())],
73
+ description: harnessDescription(getHarnessAvailability()),
74
+ },
75
+ { id: SEPARATOR_ID, label: " ", currentValue: "" },
76
+ headerItem(theme, "Worktrees"),
77
+ {
78
+ id: "worktreeRoot",
79
+ label: "Worktree root",
80
+ currentValue: store.agent.worktreeRoot ?? "(default)",
81
+ submenu: (initialValue, done) => {
82
+ const input = new Input();
83
+ input.setValue(initialValue === "(default)" ? "" : initialValue);
84
+ input.onSubmit = (value) => {
85
+ const trimmed = value.trim();
86
+ store.mutate.agent.setWorktreeRoot(trimmed || undefined);
87
+ // The new root may sit on another volume; the launch probe answered
88
+ // for the old one, and nothing else refreshes it.
89
+ refreshCowSupportProbe(getPiInstance());
90
+ ctx.ui.notify(trimmed
91
+ ? `Worktree root set to ${trimmed}`
92
+ : "Worktree root cleared (default)", "info");
93
+ done(trimmed || "(default)");
94
+ };
95
+ input.onEscape = () => done();
96
+ return input;
97
+ },
98
+ description: `Where worktrees are created. Blank = ${defaultWorktreeRoot()}.`,
99
+ },
100
+ {
101
+ id: "worktreeMaterialization",
102
+ label: "Worktree materialization",
103
+ currentValue: getWorktreeMaterialization(),
104
+ values: [
105
+ ...selectable(VALID_WORKTREE_MATERIALIZATIONS, getCowAvailability()),
106
+ ],
107
+ description: isAvailable("copy-on-write", getCowAvailability())
108
+ ? "Copy-on-write = clone of the parent working tree (shares node_modules, .env). checkout = git's classic checkout, nothing shared."
109
+ : "This volume cannot clone, so copy-on-write is unavailable and new worktrees use git's classic checkout.",
110
+ },
111
+ {
112
+ id: "worktreeCheckoutType",
113
+ label: "Worktree checkout",
114
+ currentValue: store.agent.worktreeCheckoutType,
115
+ values: [...VALID_WORKTREE_CHECKOUT_TYPES],
116
+ description: "Where a new worktree's checkout starts when the parent has uncommitted work. clean = the worktree starts at HEAD: under copy-on-write, only ignored files like node_modules and .env are copied in; under checkout, it is git's plain checkout. dirty = the parent's work rides along: copy-on-write clones its edits and untracked files too, while checkout applies only its tracked changes, leaving untracked files behind. A clean parent starts at HEAD either way.",
117
+ },
118
+ { id: SEPARATOR_ID, label: " ", currentValue: "" },
119
+ headerItem(theme, "Tools"),
120
+ {
121
+ id: "disableDefaultAgents",
122
+ label: "Disable default agents",
123
+ currentValue: store.agent.disableDefaultAgents ? "ON" : "OFF",
124
+ values: ["ON", "OFF"],
125
+ description: "Skip auto-loading built-in agent types next session; only .pi/agents types load.",
126
+ },
127
+ ];
128
+ };
129
+ const onChange = (id, newValue) => {
130
+ switch (id) {
131
+ case "worktreeRoot":
132
+ break;
133
+ case "worktreeMaterialization": {
134
+ const materialization = parseWorktreeMaterialization(newValue);
135
+ if (materialization !== undefined) {
136
+ store.mutate.agent.setWorktreeMaterialization(materialization);
137
+ ctx.ui.notify(`Worktree materialization set to ${materialization}`, "info");
138
+ }
139
+ break;
140
+ }
141
+ case "worktreeCheckoutType": {
142
+ const policy = parseWorktreeCheckoutType(newValue);
143
+ if (policy !== undefined) {
144
+ store.mutate.agent.setWorktreeCheckoutType(policy);
145
+ ctx.ui.notify(`Worktree checkout set to ${policy}`, "info");
146
+ }
147
+ break;
148
+ }
149
+ case "harnessType": {
150
+ const harnessType = parseHarnessId(newValue);
151
+ if (harnessType !== undefined) {
152
+ store.mutate.agent.setHarnessType(harnessType);
153
+ ctx.ui.notify(`Default harness set to ${harnessType}`, "info");
154
+ }
155
+ break;
156
+ }
157
+ case "disableDefaultAgents":
158
+ store.mutate.agent.setDisableDefaultAgents(newValue === "ON");
159
+ ctx.ui.notify(`Disable default agents ${newValue} (takes effect on next session)`, "info");
160
+ break;
161
+ }
162
+ };
163
+ let rebuild;
164
+ await new ScreenHost(ctx).open(({ theme, close }) => {
165
+ const items = buildItems(theme);
166
+ const triggerRebuild = () => rebuild?.(buildItems(theme));
167
+ const settingsList = new SettingsList(items, 10, buildSettingsListTheme(theme), (id, newValue) => {
168
+ onChange(id, newValue);
169
+ // Submenu rows rebuild to refresh value + tag; toggle rows update in place (a rebuild would reset the cursor).
170
+ if (items.some((i) => i.id === id && i.submenu))
171
+ triggerRebuild();
172
+ }, close);
173
+ return new SettingsListWrapper(settingsList, {
174
+ title: "Agent settings",
175
+ theme,
176
+ onCancel: close,
177
+ onRebuild: (r) => {
178
+ rebuild = r;
179
+ },
180
+ });
181
+ });
182
+ }