@preapexis/honeycomb 0.0.0-stage → 1.1.0

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 (97) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +443 -2
  3. package/bin/bee.js +18 -0
  4. package/package.json +66 -4
  5. package/plan/tools/tool-parity.md +61 -0
  6. package/src/commands/btw.ts +95 -0
  7. package/src/commands/claude-migrate.ts +63 -0
  8. package/src/commands/diff.ts +119 -0
  9. package/src/commands/discovery.ts +112 -0
  10. package/src/commands/doctor.ts +80 -0
  11. package/src/commands/goal/index.ts +254 -0
  12. package/src/commands/goal/report.ts +66 -0
  13. package/src/commands/goal/state.ts +74 -0
  14. package/src/commands/hooks.ts +38 -0
  15. package/src/commands/index.ts +13 -0
  16. package/src/commands/init.ts +66 -0
  17. package/src/commands/memory.ts +70 -0
  18. package/src/commands/plan.ts +36 -0
  19. package/src/commands/review-report.ts +23 -0
  20. package/src/commands/review.ts +21 -0
  21. package/src/commands/rewind-history.ts +40 -0
  22. package/src/commands/security-review.ts +138 -0
  23. package/src/commands/simplify.ts +21 -0
  24. package/src/commands/stats.ts +125 -0
  25. package/src/commands/tasks.ts +87 -0
  26. package/src/commands/verify.ts +21 -0
  27. package/src/commands/worktree.ts +138 -0
  28. package/src/config/bi.config.json +77 -0
  29. package/src/config/index.ts +47 -0
  30. package/src/config/limits.ts +12 -0
  31. package/src/config/path-rules.ts +19 -0
  32. package/src/config/project.ts +133 -0
  33. package/src/extension/ask-user.ts +52 -0
  34. package/src/extension/index.ts +4 -0
  35. package/src/extension/lsp-install.ts +95 -0
  36. package/src/extension/lsp-menu.ts +90 -0
  37. package/src/extension/permission-modes/index.ts +337 -0
  38. package/src/extension/permission-modes/mcp-resources.ts +21 -0
  39. package/src/extension/permission-modes/metadata.ts +18 -0
  40. package/src/extension/permission-modes/paths.ts +44 -0
  41. package/src/extension/permission-modes/plan-note.ts +58 -0
  42. package/src/extension/permission-modes/policy.ts +236 -0
  43. package/src/extension/permission-modes/preview.ts +104 -0
  44. package/src/extension/permission-modes/rules.ts +67 -0
  45. package/src/extension/permission-modes/shell.ts +183 -0
  46. package/src/extension/permission-modes/state.ts +6 -0
  47. package/src/extension/quiet-startup.ts +25 -0
  48. package/src/extension/register-tools.ts +312 -0
  49. package/src/extension/scoped-rules.ts +91 -0
  50. package/src/extension/system-instruction.ts +74 -0
  51. package/src/index.ts +71 -0
  52. package/src/tools/advanced.ts +133 -0
  53. package/src/tools/agent.ts +379 -0
  54. package/src/tools/dispatcher.ts +80 -0
  55. package/src/tools/executable.ts +15 -0
  56. package/src/tools/execution.ts +289 -0
  57. package/src/tools/filesystem.ts +662 -0
  58. package/src/tools/git.ts +196 -0
  59. package/src/tools/glob.ts +81 -0
  60. package/src/tools/grep.ts +203 -0
  61. package/src/tools/image-read.ts +71 -0
  62. package/src/tools/index.ts +52 -0
  63. package/src/tools/lsp-client.ts +104 -0
  64. package/src/tools/lsp.ts +172 -0
  65. package/src/tools/memory-store.ts +77 -0
  66. package/src/tools/notebook.ts +169 -0
  67. package/src/tools/registry.ts +31 -0
  68. package/src/tools/shells.ts +63 -0
  69. package/src/tools/todo.ts +119 -0
  70. package/src/tools/undo-journal.ts +46 -0
  71. package/src/tools/web-fetch.ts +119 -0
  72. package/src/tools/web-search.ts +76 -0
  73. package/src/tools/write-file.ts +14 -0
  74. package/src/tui/editor.ts +65 -0
  75. package/src/tui/footer-stats.ts +35 -0
  76. package/src/tui/header.ts +81 -0
  77. package/src/tui/index.ts +124 -0
  78. package/src/tui/mascot.ts +59 -0
  79. package/src/tui/permission-dialog.ts +94 -0
  80. package/src/tui/permission-rules.ts +64 -0
  81. package/src/tui/tasks-panel.ts +84 -0
  82. package/src/tui/text.ts +55 -0
  83. package/src/tui/tool-renderer.ts +42 -0
  84. package/src/tui/working-feedback.ts +220 -0
  85. package/src/types/agent.ts +54 -0
  86. package/src/types/common.ts +1 -0
  87. package/src/types/execution.ts +24 -0
  88. package/src/types/index.ts +4 -0
  89. package/src/types/tools.ts +61 -0
  90. package/themes/catppuccin-mocha.json +80 -0
  91. package/themes/github-dark.json +80 -0
  92. package/themes/honeycomb-dark.json +81 -0
  93. package/themes/honeycomb-light.json +81 -0
  94. package/themes/tokyo-day.json +80 -0
  95. package/themes/tokyo-night.json +80 -0
  96. package/themes/vercel-black.json +80 -0
  97. package/themes/vercel-light.json +80 -0
@@ -0,0 +1,95 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
3
+ import type { PermissionController } from '../extension/permission-modes/index.ts';
4
+ import { fit, literal } from '../tui/text.ts';
5
+
6
+ export function registerBtwCommand(pi: ExtensionAPI, permissions: PermissionController, timeoutMs = 30_000): void {
7
+ let running: AbortController | undefined;
8
+ pi.on('session_shutdown', () => running?.abort());
9
+ pi.registerCommand('btw', {
10
+ description: 'Ask a separate, tool-free question using the active model',
11
+ async handler(args, ctx) {
12
+ if (ctx.mode !== 'tui' || !ctx.hasUI) {
13
+ if (ctx.hasUI) ctx.ui.notify('/btw requires the terminal UI.', 'warning');
14
+ return;
15
+ }
16
+ const available = () => ctx.isIdle() && !ctx.hasPendingMessages() && !['plan', 'dontAsk'].includes(permissions.mode);
17
+ if (!available() || running) return ctx.ui.notify('/btw requires an idle session outside Plan and No prompts modes.', 'warning');
18
+ const model = ctx.model;
19
+ if (!model) return ctx.ui.notify('Select a model before using /btw.', 'warning');
20
+ const question = (args.trim() || await ctx.ui.input('Side question (not added to the main transcript)'))?.trim();
21
+ if (!question) return;
22
+ if (question.length > 4000) return ctx.ui.notify('Side questions are limited to 4,000 characters.', 'warning');
23
+ if (!available() || running) return;
24
+ const controller = new AbortController();
25
+ running = controller;
26
+ try {
27
+ const label = literal(`${model.provider}/${model.id}`);
28
+ const send = await permissions.prompter.confirm(ctx, 'Send side question?', `${label} will receive only this question. Provider retention policies apply.\n\n${literal(question, true)}`, controller.signal);
29
+ if (!send || !available() || controller.signal.aborted) return;
30
+ await ctx.ui.custom<void>((tui, theme, keys, done) => {
31
+ let reply = '', status = 'Waiting for the model…', offset = 0, page = 1;
32
+ const timeout = setTimeout(() => {
33
+ controller.abort();
34
+ status = 'Request timed out.';
35
+ tui.requestRender();
36
+ }, timeoutMs);
37
+ const request = async () => {
38
+ try {
39
+ const stream = ctx.modelRegistry.streamSimple(model, {
40
+ systemPrompt: 'Answer this standalone question concisely. If context is missing, say so.',
41
+ messages: [{ role: 'user', content: question, timestamp: Date.now() }], tools: [],
42
+ }, { signal: controller.signal, sessionId: randomUUID(), cacheRetention: 'none', disableContinuation: true, maxTokens: 512, maxRetries: 0 });
43
+ for await (const event of stream) {
44
+ if (controller.signal.aborted) return;
45
+ if (event.type === 'text_delta') {
46
+ reply = (reply + event.delta).slice(0, 16000);
47
+ tui.requestRender();
48
+ }
49
+ }
50
+ const result = await stream.result();
51
+ if (controller.signal.aborted) return;
52
+ const usage = result.usage;
53
+ const cost = usage?.cost?.total;
54
+ status = result.stopReason === 'error' || result.stopReason === 'aborted' ? 'Request failed. Check model access and provider status.' :
55
+ `${usage?.totalTokens ?? 'Unknown'} tokens · ${typeof cost === 'number' && Number.isFinite(cost) ? `estimated $${cost.toFixed(4)}` : 'cost unavailable'}`;
56
+ if (!reply && result.stopReason !== 'error') reply = 'No text answer returned.';
57
+ tui.requestRender();
58
+ } catch {
59
+ if (!controller.signal.aborted) {
60
+ status = 'Request failed. Check model access and provider status.';
61
+ tui.requestRender();
62
+ }
63
+ } finally { clearTimeout(timeout); }
64
+ };
65
+ queueMicrotask(() => { if (!controller.signal.aborted) void request(); else clearTimeout(timeout); });
66
+ return {
67
+ render(width) {
68
+ page = Math.max(1, tui.terminal.rows - 6);
69
+ const lines = literal(reply, true).split('\n');
70
+ offset = Math.max(0, Math.min(offset, lines.length - 1));
71
+ return [theme.fg('accent', `Side question · ${label}`), status, ...lines.slice(offset, offset + page), '↑/↓/PgUp/PgDn: scroll · Esc: close'].map(line => fit(line, width));
72
+ },
73
+ handleInput(data) {
74
+ if (keys.matches(data, 'tui.select.cancel')) {
75
+ clearTimeout(timeout);
76
+ controller.abort();
77
+ return done(undefined);
78
+ }
79
+ if (keys.matches(data, 'tui.select.up')) offset--;
80
+ else if (keys.matches(data, 'tui.select.down')) offset++;
81
+ else if (keys.matches(data, 'tui.select.pageUp')) offset -= page;
82
+ else if (keys.matches(data, 'tui.select.pageDown')) offset += page;
83
+ else return;
84
+ tui.requestRender();
85
+ },
86
+ invalidate() {},
87
+ };
88
+ }, { overlay: true });
89
+ } finally {
90
+ controller.abort();
91
+ running = undefined;
92
+ }
93
+ },
94
+ });
95
+ }
@@ -0,0 +1,63 @@
1
+ import { lstat, opendir } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
4
+ import type { PermissionController } from '../extension/permission-modes/index.ts';
5
+ import { permittedMetadataPath } from '../extension/permission-modes/metadata.ts';
6
+ import { loadPermissionRules } from '../extension/permission-modes/rules.ts';
7
+ import { show } from './discovery.ts';
8
+
9
+ export function registerClaudeMigrationPreview(pi: ExtensionAPI, permissions: PermissionController): void {
10
+ pi.registerCommand('claude-migrate', {
11
+ description: 'Preview manual migration paths for user-owned Claude commands and skills',
12
+ async handler(args, ctx) {
13
+ if (!ctx.hasUI || !['tui', 'rpc'].includes(ctx.mode)) return;
14
+ if (args.trim()) return ctx.ui.notify('Usage: /claude-migrate', 'warning');
15
+ const mode = permissions.mode, session = ctx.sessionManager.getSessionId(), leaf = ctx.sessionManager.getLeafId();
16
+ const current = () => !ctx.signal?.aborted && ctx.isIdle() && !ctx.hasPendingMessages() && ctx.isProjectTrusted() &&
17
+ permissions.mode === mode && ctx.sessionManager.getSessionId() === session && ctx.sessionManager.getLeafId() === leaf;
18
+ if (!current()) return ctx.ui.notify('Migration preview requires an idle, trusted session.', 'warning');
19
+ const config = loadPermissionRules(ctx.cwd, () => {});
20
+ if (config.invalid) return ctx.ui.notify('Migration preview is unavailable with invalid permission rules.', 'warning');
21
+ const mayRead = (name: string, tool: 'ls' | 'read' = 'read') => permittedMetadataPath(ctx.cwd, mode, name, config.rules, tool);
22
+ const entries: { source: string; destination: string }[] = [];
23
+ let limited = false;
24
+ for (const kind of ['commands', 'skills'] as const) {
25
+ if (!current()) return;
26
+ const root = mayRead(`.claude/${kind}`, 'ls')?.absolute;
27
+ if (!root) continue;
28
+ let visited = 0;
29
+ try {
30
+ if (!(await lstat(root)).isDirectory() || !mayRead(root, 'ls')) continue;
31
+ for await (const entry of await opendir(root)) {
32
+ if (!current()) return;
33
+ if (visited++ >= 200 || entries.length >= 100) { limited = true; break; }
34
+ let relative: string, destination: string;
35
+ if (kind === 'commands') {
36
+ if (!entry.isFile() || !/^[\w-]{1,64}\.md$/.test(entry.name)) continue;
37
+ relative = entry.name;
38
+ destination = `.pi/prompts/${entry.name}`;
39
+ } else {
40
+ if (!entry.isDirectory() || !/^[a-z0-9][a-z0-9-]{0,63}$/.test(entry.name)) continue;
41
+ relative = `${entry.name}/SKILL.md`;
42
+ destination = `.agents/skills/${relative}`;
43
+ }
44
+ const source = mayRead(path.join(root, relative));
45
+ if (source && (await lstat(source.absolute).catch(() => undefined))?.isFile()) entries.push({ source: source.relative, destination });
46
+ }
47
+ } catch { /* Missing or unreadable folders have no entries to preview. */ }
48
+ }
49
+ if (!current()) return;
50
+ const latest = loadPermissionRules(ctx.cwd, () => {});
51
+ if (latest.invalid) return;
52
+ const rows = entries.filter(({ source }) => permittedMetadataPath(ctx.cwd, mode, source, latest.rules) &&
53
+ permittedMetadataPath(ctx.cwd, mode, source.startsWith('.claude/commands/') ? '.claude/commands' : '.claude/skills', latest.rules, 'ls'))
54
+ .map(({ source, destination }) => `${source} → ${destination}`).sort();
55
+ await show(ctx, 'Claude resource migration preview', [
56
+ 'Names only. Review and adapt your own files manually; nothing was read, copied, or executed.',
57
+ 'Review arguments, scripts and tool names. Do not import hooks or allowed-tools grants.',
58
+ ...(rows.length ? rows : ['No permitted top-level commands or skill manifests found.']),
59
+ ...(limited ? ['Preview reached its scan or entry limit.'] : []),
60
+ ]);
61
+ },
62
+ });
63
+ }
@@ -0,0 +1,119 @@
1
+ import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
2
+ import { matchesKey } from '@earendil-works/pi-tui';
3
+ import type { PermissionController } from '../extension/permission-modes/index.ts';
4
+ import { decidePermission } from '../extension/permission-modes/policy.ts';
5
+ import { loadPermissionRules } from '../extension/permission-modes/rules.ts';
6
+ import { runDiff } from '../tools/git.ts';
7
+ import { fit, literal } from '../tui/text.ts';
8
+
9
+ type File = { status: string; paths: string[] };
10
+ type Action = 'switch' | 'back' | 'sensitive' | number | undefined;
11
+
12
+ export function registerDiffCommand(pi: ExtensionAPI, permissions: PermissionController): void {
13
+ pi.registerCommand('diff', {
14
+ description: 'Browse staged and unstaged Git changes without a model call',
15
+ async handler(args, ctx) {
16
+ if (ctx.mode !== 'tui' || !ctx.hasUI) {
17
+ if (ctx.hasUI) ctx.ui.notify('/diff requires the terminal UI.', 'warning');
18
+ return;
19
+ }
20
+ const idle = () => ctx.isIdle() && !ctx.hasPendingMessages();
21
+ if (!idle()) return ctx.ui.notify('Wait for the current run before opening /diff.', 'warning');
22
+ const input = args.trim();
23
+ if (input && input !== 'staged' && input !== 'unstaged') return ctx.ui.notify('Usage: /diff [staged|unstaged]', 'warning');
24
+ let staged = input === 'staged';
25
+ const mode = permissions.mode;
26
+ const leaf = ctx.sessionManager.getLeafId();
27
+ const sessionId = ctx.sessionManager.getSessionId();
28
+ const current = () => permissions.mode === mode && idle() && ctx.sessionManager.getLeafId() === leaf && ctx.sessionManager.getSessionId() === sessionId;
29
+ let files: File[] = [], selected = 0, picking = true, sensitiveApproved = false;
30
+ let approval: string | undefined;
31
+ let reuseListing = false;
32
+ while (current()) {
33
+ const decision = () => {
34
+ const config = loadPermissionRules(ctx.cwd, () => {});
35
+ return config.invalid ? { action: 'deny', reason: 'Invalid permission rules. See /permissions.' } : decidePermission(mode, 'git_diff', { staged }, ctx.cwd, config.rules);
36
+ };
37
+ const initial = decision();
38
+ const scope = JSON.stringify([staged, initial]);
39
+ const check = () => current() && JSON.stringify([staged, decision()]) === scope;
40
+ if (initial.action === 'ask' && approval !== scope && mode !== 'dontAsk') {
41
+ if (await permissions.prompter.confirm(ctx, 'Open Git diff?', initial.reason) && check()) approval = scope;
42
+ else return;
43
+ }
44
+ if (!current()) return;
45
+ const abort = new AbortController();
46
+ let sensitive: string | undefined;
47
+ const file = picking ? undefined : files[selected];
48
+ const action = await ctx.ui.custom<Action>((tui, theme, keys, done) => {
49
+ let rows = ['Loading changes…'], loaded = false, offset = 0, page = 1;
50
+ const close = (next: Action) => { abort.abort(); done(next); };
51
+ const update = async () => {
52
+ try {
53
+ if (!check() || (initial.action !== 'allow' && approval !== scope)) rows = [literal(initial.reason)];
54
+ else if (picking && reuseListing) {
55
+ rows = files.length ? [] : ['No changes.'];
56
+ } else {
57
+ const value = await runDiff({ workingDirectory: ctx.cwd, sessionId, signal: abort.signal,
58
+ confirmSensitiveRead: async description => { sensitive = description; return sensitiveApproved && check(); },
59
+ }, staged, file ? { paths: file.paths } : { list: true });
60
+ if (abort.signal.aborted) return;
61
+ if (!check()) rows = ['Permission context changed.'];
62
+ else if (sensitive && !sensitiveApproved && mode !== 'dontAsk') return close('sensitive');
63
+ else if (!value.success) rows = [literal(value.error ?? 'Unable to load diff.')];
64
+ else if (picking) {
65
+ files = (value.metadata?.files as File[] | undefined) ?? [];
66
+ selected = Math.max(0, Math.min(selected, files.length - 1));
67
+ rows = files.length ? [] : ['No changes.'];
68
+ } else rows = (value.output || 'No changes.').split('\n').map(line => literal(line));
69
+ }
70
+ } catch { rows = ['Unable to inspect Git diff.']; }
71
+ loaded = true;
72
+ if (!abort.signal.aborted) tui.requestRender();
73
+ };
74
+ queueMicrotask(() => { if (!abort.signal.aborted) void update(); });
75
+ return {
76
+ render(width) {
77
+ page = Math.max(1, tui.terminal.rows - 6);
78
+ const list = loaded && picking && !rows.length && files.length > 0;
79
+ if (list) offset = Math.max(0, Math.min(offset, selected));
80
+ if (list && selected >= offset + page) offset = selected - page + 1;
81
+ if (!list) offset = Math.max(0, Math.min(offset, rows.length - page));
82
+ const body = list ? files.slice(offset, offset + page).map(({ paths, status }, i) => {
83
+ const title = `${status} ${paths.map(name => literal(name)).join(' → ')}`;
84
+ return offset + i === selected ? theme.fg('accent', `> ${title}`) : ` ${title}`;
85
+ }) : rows.slice(offset, offset + page);
86
+ return [theme.fg('accent', `Git diff — ${staged ? 'staged' : 'unstaged'}`), reuseListing && picking ? 'Previously loaded file list; switch tabs to refresh.' : 'Tracked files only; submodules omitted.', ...body,
87
+ picking ? 'Tab: switch · ↑/↓: select · Enter: open · Esc: close' : 'Tab: switch · ↑/↓/PgUp/PgDn: scroll · n/p: file · Esc: back'].map(line => fit(line, width));
88
+ },
89
+ handleInput(data) {
90
+ if (keys.matches(data, 'tui.select.cancel')) return close(picking ? undefined : 'back');
91
+ if (keys.matches(data, 'tui.input.tab')) return close('switch');
92
+ if (!loaded || !check()) return;
93
+ if (picking && !rows.length && keys.matches(data, 'tui.select.confirm')) return close(selected);
94
+ if (!picking && (matchesKey(data, 'n') || matchesKey(data, 'p'))) return close(Math.max(0, Math.min(files.length - 1, selected + (matchesKey(data, 'n') ? 1 : -1))));
95
+ const delta = keys.matches(data, 'tui.select.up') ? -1 : keys.matches(data, 'tui.select.down') ? 1 :
96
+ keys.matches(data, 'tui.select.pageUp') ? -page : keys.matches(data, 'tui.select.pageDown') ? page : 0;
97
+ if (!delta) return;
98
+ if (picking && !rows.length) selected = Math.max(0, Math.min(files.length - 1, selected + delta));
99
+ else offset += delta;
100
+ tui.requestRender();
101
+ },
102
+ invalidate() {},
103
+ };
104
+ });
105
+ abort.abort();
106
+ if (action === undefined) return;
107
+ if (action === 'sensitive') {
108
+ if (!await permissions.prompter.confirm(ctx, 'Allow sensitive Git diff?', sensitive!) || !check()) return;
109
+ sensitiveApproved = true;
110
+ continue;
111
+ }
112
+ sensitiveApproved = false;
113
+ if (action === 'switch') { staged = !staged; approval = undefined; files = []; selected = 0; picking = true; reuseListing = false; }
114
+ else if (action === 'back') { picking = true; reuseListing = true; }
115
+ else { selected = action; picking = false; reuseListing = false; }
116
+ }
117
+ },
118
+ });
119
+ }
@@ -0,0 +1,112 @@
1
+ import type { ExtensionAPI, ExtensionCommandContext } from '@earendil-works/pi-coding-agent';
2
+ import type { PermissionController } from '../extension/permission-modes/index.ts';
3
+ import { permittedMetadataPath } from '../extension/permission-modes/metadata.ts';
4
+ import { loadPermissionRules } from '../extension/permission-modes/rules.ts';
5
+ import { fit, literal } from '../tui/text.ts';
6
+ import { readGoalState } from './goal/state.ts';
7
+
8
+ export async function show(ctx: ExtensionCommandContext, title: string, rows: string[]) {
9
+ if (!ctx.hasUI) return;
10
+ const safe = rows.slice(0, 200).map(row => literal(row.slice(0, 1000)));
11
+ if (ctx.mode !== 'tui') return ctx.ui.notify(safe.join('\n').slice(0, 8000), 'info');
12
+ await ctx.ui.custom<void>((tui, theme, keys, done) => {
13
+ let offset = 0, page = 1;
14
+ return {
15
+ render(width) {
16
+ page = Math.max(1, tui.terminal.rows - 5);
17
+ offset = Math.max(0, Math.min(offset, safe.length - page));
18
+ return [theme.fg('accent', title), ...safe.slice(offset, offset + page), '↑/↓/PgUp/PgDn: scroll · Esc: close'].map(line => fit(line, width));
19
+ },
20
+ handleInput(data) {
21
+ if (keys.matches(data, 'tui.select.cancel')) return done(undefined);
22
+ if (keys.matches(data, 'tui.select.up')) offset--;
23
+ else if (keys.matches(data, 'tui.select.down')) offset++;
24
+ else if (keys.matches(data, 'tui.select.pageUp')) offset -= page;
25
+ else if (keys.matches(data, 'tui.select.pageDown')) offset += page;
26
+ else return;
27
+ tui.requestRender();
28
+ },
29
+ invalidate() {},
30
+ };
31
+ });
32
+ }
33
+
34
+ export function registerDiscoveryCommands(pi: ExtensionAPI, permissions: PermissionController): void {
35
+ pi.registerCommand('help', {
36
+ description: 'Discover commands and Pi equivalents',
37
+ async handler(args, ctx) {
38
+ const query = args.trim().replace(/^\//, '').toLowerCase();
39
+ const commands = pi.getCommands().filter(c => !query || c.name.toLowerCase() === query);
40
+ const rows = commands.map(c => `${c.source}: /${c.name}${c.description ? ` — ${c.description}` : ''}`);
41
+ if (!query) rows.push('Pi TUI built-ins include /settings, /session, /new, /quit, /model and /hotkeys.', 'Claude equivalents: /clear → /new; /config → /settings; /cost → /session; /exit → /quit.', 'Built-ins are not listed by command discovery and may not be available in RPC.');
42
+ if (!rows.length) rows.push('No discovered command. Pi TUI built-ins are not included in discovery.');
43
+ await show(ctx, 'Command help', rows);
44
+ },
45
+ });
46
+ pi.registerCommand('tool-search', {
47
+ description: 'Search registered tool names and see which are active',
48
+ async handler(args, ctx) {
49
+ if (!ctx.hasUI || !['tui', 'rpc'].includes(ctx.mode)) return;
50
+ const query = args.trim().toLowerCase();
51
+ const active = new Set(pi.getActiveTools());
52
+ const names = [...new Set(pi.getAllTools().map(tool => tool.name))].sort();
53
+ const matches = names.filter(name => name.toLowerCase().includes(query));
54
+ const rows = matches.slice(0, 198).map(name => `${active.has(name) ? 'Active' : 'Inactive'}: ${name}`);
55
+ if (!rows.length) rows.push('No matching registered tools.');
56
+ if (matches.length > 198) rows.push(`Showing 198 of ${matches.length} matches. Refine the search to see more.`);
57
+ rows.unshift('Active means exposed to the model, not pre-approved to run.');
58
+ await show(ctx, 'Tool catalog', rows);
59
+ },
60
+ });
61
+ pi.registerCommand('skills', {
62
+ description: 'List loaded skills and exposed commands',
63
+ async handler(_args, ctx) {
64
+ const skills = ctx.getSystemPromptOptions().skills ?? [];
65
+ const commands = pi.getCommands().filter(c => c.source === 'skill');
66
+ const rows = skills.map(skill => `${skill.name} — ${skill.description}`);
67
+ rows.push(...commands.map(c => `Available command: /${c.name}`));
68
+ await show(ctx, 'Skills', rows.length ? rows : ['No loaded skills or skill commands.']);
69
+ },
70
+ });
71
+ pi.registerCommand('context', {
72
+ description: 'Show context usage, or list permitted workspace instruction files with /context details',
73
+ async handler(args, ctx) {
74
+ if (!ctx.hasUI || !['tui', 'rpc'].includes(ctx.mode)) return;
75
+ const input = args.trim();
76
+ if (input && input !== 'details') return ctx.ui.notify('Usage: /context [details]', 'warning');
77
+ const usage = ctx.getContextUsage();
78
+ const options = ctx.getSystemPromptOptions();
79
+ const rows = [
80
+ `Estimated tokens: ${usage?.tokens ?? 'unknown'}`,
81
+ `Context window: ${usage?.contextWindow ?? 'unknown'}`,
82
+ `Estimated free: ${usage && usage.tokens !== null ? Math.max(0, usage.contextWindow - usage.tokens) : 'unknown'}`,
83
+ `Active tools: ${pi.getActiveTools().length}; context files: ${options.contextFiles?.length ?? 0}; skills: ${options.skills?.length ?? 0}`,
84
+ ];
85
+ if (input === 'details') {
86
+ rows.push('', 'Loaded workspace instruction files (not the exact context after compaction):');
87
+ const { invalid, rules } = loadPermissionRules(ctx.cwd, () => {});
88
+ const files = !invalid ? (options.contextFiles ?? []).slice(0, 100).flatMap(({ path }) => {
89
+ const file = permittedMetadataPath(ctx.cwd, permissions.mode, path, rules);
90
+ return file ? [file.relative] : [];
91
+ }) : [];
92
+ rows.push(...new Set(files.length ? files : ['No permitted workspace instruction files to list.']));
93
+ if ((options.contextFiles?.length ?? 0) > 100) rows.push('Checked the first 100 context-file entries.');
94
+ }
95
+ await show(ctx, 'Context', rows);
96
+ },
97
+ });
98
+ pi.registerCommand('status', {
99
+ description: 'Show local session status',
100
+ async handler(_args, ctx) {
101
+ const goal = readGoalState(ctx.sessionManager.getBranch());
102
+ await show(ctx, 'Status', [
103
+ `Model: ${ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : 'none'}`,
104
+ `Project trusted: ${ctx.isProjectTrusted() ? 'yes' : 'no'}`,
105
+ `Permission mode: ${permissions.label}`,
106
+ `Active tools: ${pi.getActiveTools().length}`,
107
+ `Goal: ${goal?.status ?? 'none'}`,
108
+ 'More: /doctor, /permissions, /session (Pi TUI).',
109
+ ]);
110
+ },
111
+ });
112
+ }
@@ -0,0 +1,80 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
4
+ import { BI_CONFIG } from '../config/index.ts';
5
+ import { loadProjectConfig, type ProjectConfig } from '../config/project.ts';
6
+ import { loadPermissionRules } from '../extension/permission-modes/rules.ts';
7
+ import type { PermissionController } from '../extension/permission-modes/index.ts';
8
+ import { hasBiPromptEditor } from '../tui/editor.ts';
9
+ import { fit, literal } from '../tui/text.ts';
10
+
11
+ const exec = promisify(execFile);
12
+
13
+ export function doctorPreferences(project: ProjectConfig, trusted: boolean): string[] {
14
+ const rows: string[] = [];
15
+ for (const section of ['filesystem', 'git', 'output', 'startup'] as const) {
16
+ const overrides = project[section] as Record<string, number | boolean> | undefined;
17
+ for (const [key, fallback] of Object.entries(BI_CONFIG[section])) {
18
+ const override = overrides?.[key];
19
+ rows.push(`${section}.${key}: ${override ?? fallback} (${override === undefined ? 'package default' : 'project'})`);
20
+ }
21
+ }
22
+ rows.push(`Project instructions: ${project.systemPrompt?.additional ? trusted ? 'configured' : 'ignored (untrusted project)' : 'not configured'}`);
23
+ return rows;
24
+ }
25
+
26
+ export function registerDoctorCommand(pi: ExtensionAPI, permissions: PermissionController): void {
27
+ pi.registerCommand('doctor', {
28
+ description: 'Inspect Honeycomb configuration, permission health, tool groups, and Git',
29
+ async handler(_args, ctx) {
30
+ if (!ctx.hasUI) return;
31
+ if (!ctx.isIdle()) return ctx.ui.notify('Wait for the current run before opening /doctor.', 'warning');
32
+ const issues: string[] = [];
33
+ const rules = loadPermissionRules(ctx.cwd, message => {
34
+ // The existing loader includes raw parser exceptions. Never display those.
35
+ const source = message.startsWith(`Invalid permission rules ${ctx.cwd}/.pi/`) ? 'project' : 'user';
36
+ issues.push(`Blocked: invalid ${source} permission rules. See /permissions.`);
37
+ });
38
+ const configIssues: string[] = [];
39
+ const project = await loadProjectConfig(ctx.cwd, issue => configIssues.push(`Warning: ${issue}`));
40
+ const active = new Set(pi.getActiveTools());
41
+ const inactive = pi.getAllTools().filter(tool => !active.has(tool.name)).map(tool => literal(tool.name));
42
+ const groups = Object.entries(BI_CONFIG.toolGroups).filter(([, enabled]) => !enabled).map(([name]) => name);
43
+ let git = 'OK: Git available';
44
+ try { await exec('git', ['--version'], { cwd: ctx.cwd, timeout: 1500, maxBuffer: 4096 }); }
45
+ catch { git = 'Warning: could not run Git. Check that Git is installed and on PATH.'; }
46
+ const rows = [
47
+ `Permission mode: ${permissions.label}`, ...(issues.length ? issues : ['OK: permission rules']), git,
48
+ `Disabled Honeycomb tool groups: ${groups.join(', ') || 'none'}`,
49
+ `Registered but inactive tools: ${inactive.slice(0, 30).join(', ') || 'none'}${inactive.length > 30 ? '…' : ''}`,
50
+ ...configIssues, ...doctorPreferences(project, ctx.isProjectTrusted()), 'Effective keyboard shortcuts: see /hotkeys.',
51
+ ];
52
+ if (ctx.mode !== 'tui') return ctx.ui.notify(rows.join('\n'), rules.invalid ? 'warning' : 'info');
53
+ await ctx.ui.custom<void>((tui, theme, keys, done) => {
54
+ const thinking = keys.getKeys('app.thinking.cycle');
55
+ if (hasBiPromptEditor(ctx)) {
56
+ rows.push('Honeycomb editor active: Shift+Tab cycles permissions outside autocomplete.');
57
+ if (thinking.includes('shift+tab')) rows.push('Shift+Tab thinking binding is intercepted; use Alt+T for thinking.');
58
+ } else rows.push('Honeycomb editor not active: use Alt+M to cycle permissions.');
59
+ let offset = 0, page = 1;
60
+ return {
61
+ render(width) {
62
+ page = Math.max(1, tui.terminal.rows - 5);
63
+ offset = Math.max(0, Math.min(offset, rows.length - page));
64
+ return [theme.fg('accent', 'Honeycomb diagnostics'), ...rows.slice(offset, offset + page), '↑/↓/PgUp/PgDn: scroll · Esc: close'].map(line => fit(line, width));
65
+ },
66
+ handleInput(data) {
67
+ if (keys.matches(data, 'tui.select.cancel')) return done(undefined);
68
+ if (keys.matches(data, 'tui.select.up')) offset--;
69
+ else if (keys.matches(data, 'tui.select.down')) offset++;
70
+ else if (keys.matches(data, 'tui.select.pageUp')) offset -= page;
71
+ else if (keys.matches(data, 'tui.select.pageDown')) offset += page;
72
+ else return;
73
+ tui.requestRender();
74
+ },
75
+ invalidate() {},
76
+ };
77
+ });
78
+ },
79
+ });
80
+ }