indusagi-coding-agent 0.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 (240) hide show
  1. package/CHANGELOG.md +2249 -0
  2. package/README.md +546 -0
  3. package/dist/cli/args.js +282 -0
  4. package/dist/cli/config-selector.js +30 -0
  5. package/dist/cli/file-processor.js +78 -0
  6. package/dist/cli/list-models.js +91 -0
  7. package/dist/cli/session-picker.js +31 -0
  8. package/dist/cli.js +10 -0
  9. package/dist/config.js +158 -0
  10. package/dist/core/agent-session.js +2097 -0
  11. package/dist/core/auth-storage.js +278 -0
  12. package/dist/core/bash-executor.js +211 -0
  13. package/dist/core/compaction/branch-summarization.js +241 -0
  14. package/dist/core/compaction/compaction.js +606 -0
  15. package/dist/core/compaction/index.js +6 -0
  16. package/dist/core/compaction/utils.js +137 -0
  17. package/dist/core/diagnostics.js +1 -0
  18. package/dist/core/event-bus.js +24 -0
  19. package/dist/core/exec.js +70 -0
  20. package/dist/core/export-html/ansi-to-html.js +248 -0
  21. package/dist/core/export-html/index.js +221 -0
  22. package/dist/core/export-html/template.css +905 -0
  23. package/dist/core/export-html/template.html +54 -0
  24. package/dist/core/export-html/template.js +1549 -0
  25. package/dist/core/export-html/tool-renderer.js +56 -0
  26. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  27. package/dist/core/export-html/vendor/marked.min.js +6 -0
  28. package/dist/core/extensions/index.js +8 -0
  29. package/dist/core/extensions/loader.js +395 -0
  30. package/dist/core/extensions/runner.js +499 -0
  31. package/dist/core/extensions/types.js +31 -0
  32. package/dist/core/extensions/wrapper.js +101 -0
  33. package/dist/core/footer-data-provider.js +133 -0
  34. package/dist/core/index.js +8 -0
  35. package/dist/core/keybindings.js +140 -0
  36. package/dist/core/messages.js +122 -0
  37. package/dist/core/model-registry.js +454 -0
  38. package/dist/core/model-resolver.js +309 -0
  39. package/dist/core/package-manager.js +1142 -0
  40. package/dist/core/prompt-templates.js +250 -0
  41. package/dist/core/resource-loader.js +569 -0
  42. package/dist/core/sdk.js +225 -0
  43. package/dist/core/session-manager.js +1078 -0
  44. package/dist/core/settings-manager.js +430 -0
  45. package/dist/core/skills.js +339 -0
  46. package/dist/core/system-prompt.js +136 -0
  47. package/dist/core/timings.js +24 -0
  48. package/dist/core/tools/bash.js +226 -0
  49. package/dist/core/tools/edit-diff.js +242 -0
  50. package/dist/core/tools/edit.js +145 -0
  51. package/dist/core/tools/find.js +205 -0
  52. package/dist/core/tools/grep.js +238 -0
  53. package/dist/core/tools/index.js +60 -0
  54. package/dist/core/tools/ls.js +117 -0
  55. package/dist/core/tools/path-utils.js +52 -0
  56. package/dist/core/tools/read.js +165 -0
  57. package/dist/core/tools/truncate.js +204 -0
  58. package/dist/core/tools/write.js +77 -0
  59. package/dist/index.js +41 -0
  60. package/dist/main.js +565 -0
  61. package/dist/migrations.js +260 -0
  62. package/dist/modes/index.js +7 -0
  63. package/dist/modes/interactive/components/armin.js +328 -0
  64. package/dist/modes/interactive/components/assistant-message.js +86 -0
  65. package/dist/modes/interactive/components/bash-execution.js +155 -0
  66. package/dist/modes/interactive/components/bordered-loader.js +47 -0
  67. package/dist/modes/interactive/components/branch-summary-message.js +41 -0
  68. package/dist/modes/interactive/components/compaction-summary-message.js +42 -0
  69. package/dist/modes/interactive/components/config-selector.js +458 -0
  70. package/dist/modes/interactive/components/countdown-timer.js +27 -0
  71. package/dist/modes/interactive/components/custom-editor.js +61 -0
  72. package/dist/modes/interactive/components/custom-message.js +80 -0
  73. package/dist/modes/interactive/components/diff.js +132 -0
  74. package/dist/modes/interactive/components/dynamic-border.js +19 -0
  75. package/dist/modes/interactive/components/extension-editor.js +96 -0
  76. package/dist/modes/interactive/components/extension-input.js +54 -0
  77. package/dist/modes/interactive/components/extension-selector.js +70 -0
  78. package/dist/modes/interactive/components/footer.js +213 -0
  79. package/dist/modes/interactive/components/index.js +31 -0
  80. package/dist/modes/interactive/components/keybinding-hints.js +60 -0
  81. package/dist/modes/interactive/components/login-dialog.js +138 -0
  82. package/dist/modes/interactive/components/model-selector.js +253 -0
  83. package/dist/modes/interactive/components/oauth-selector.js +91 -0
  84. package/dist/modes/interactive/components/scoped-models-selector.js +262 -0
  85. package/dist/modes/interactive/components/session-selector-search.js +145 -0
  86. package/dist/modes/interactive/components/session-selector.js +698 -0
  87. package/dist/modes/interactive/components/settings-selector.js +250 -0
  88. package/dist/modes/interactive/components/show-images-selector.js +33 -0
  89. package/dist/modes/interactive/components/skill-invocation-message.js +44 -0
  90. package/dist/modes/interactive/components/theme-selector.js +43 -0
  91. package/dist/modes/interactive/components/thinking-selector.js +45 -0
  92. package/dist/modes/interactive/components/tool-execution.js +608 -0
  93. package/dist/modes/interactive/components/tree-selector.js +892 -0
  94. package/dist/modes/interactive/components/user-message-selector.js +109 -0
  95. package/dist/modes/interactive/components/user-message.js +15 -0
  96. package/dist/modes/interactive/components/visual-truncate.js +32 -0
  97. package/dist/modes/interactive/interactive-mode.js +3576 -0
  98. package/dist/modes/interactive/theme/dark.json +85 -0
  99. package/dist/modes/interactive/theme/light.json +84 -0
  100. package/dist/modes/interactive/theme/theme-schema.json +335 -0
  101. package/dist/modes/interactive/theme/theme.js +938 -0
  102. package/dist/modes/print-mode.js +96 -0
  103. package/dist/modes/rpc/rpc-client.js +390 -0
  104. package/dist/modes/rpc/rpc-mode.js +448 -0
  105. package/dist/modes/rpc/rpc-types.js +7 -0
  106. package/dist/utils/changelog.js +86 -0
  107. package/dist/utils/clipboard-image.js +116 -0
  108. package/dist/utils/clipboard.js +58 -0
  109. package/dist/utils/frontmatter.js +25 -0
  110. package/dist/utils/git.js +5 -0
  111. package/dist/utils/image-convert.js +34 -0
  112. package/dist/utils/image-resize.js +180 -0
  113. package/dist/utils/mime.js +25 -0
  114. package/dist/utils/photon.js +120 -0
  115. package/dist/utils/shell.js +164 -0
  116. package/dist/utils/sleep.js +16 -0
  117. package/dist/utils/tools-manager.js +186 -0
  118. package/docs/compaction.md +390 -0
  119. package/docs/custom-provider.md +538 -0
  120. package/docs/development.md +69 -0
  121. package/docs/extensions.md +1733 -0
  122. package/docs/images/doom-extension.png +0 -0
  123. package/docs/images/interactive-mode.png +0 -0
  124. package/docs/images/tree-view.png +0 -0
  125. package/docs/json.md +79 -0
  126. package/docs/keybindings.md +162 -0
  127. package/docs/models.md +193 -0
  128. package/docs/packages.md +163 -0
  129. package/docs/prompt-templates.md +67 -0
  130. package/docs/providers.md +147 -0
  131. package/docs/rpc.md +1048 -0
  132. package/docs/sdk.md +957 -0
  133. package/docs/session.md +412 -0
  134. package/docs/settings.md +216 -0
  135. package/docs/shell-aliases.md +13 -0
  136. package/docs/skills.md +226 -0
  137. package/docs/terminal-setup.md +65 -0
  138. package/docs/themes.md +295 -0
  139. package/docs/tree.md +219 -0
  140. package/docs/tui.md +887 -0
  141. package/docs/windows.md +17 -0
  142. package/examples/README.md +25 -0
  143. package/examples/extensions/README.md +192 -0
  144. package/examples/extensions/antigravity-image-gen.ts +414 -0
  145. package/examples/extensions/auto-commit-on-exit.ts +49 -0
  146. package/examples/extensions/bookmark.ts +50 -0
  147. package/examples/extensions/claude-rules.ts +86 -0
  148. package/examples/extensions/confirm-destructive.ts +59 -0
  149. package/examples/extensions/custom-compaction.ts +115 -0
  150. package/examples/extensions/custom-footer.ts +65 -0
  151. package/examples/extensions/custom-header.ts +73 -0
  152. package/examples/extensions/custom-provider-anthropic/index.ts +605 -0
  153. package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  154. package/examples/extensions/custom-provider-anthropic/package.json +19 -0
  155. package/examples/extensions/custom-provider-gitlab-duo/index.ts +350 -0
  156. package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  157. package/examples/extensions/custom-provider-gitlab-duo/test.ts +83 -0
  158. package/examples/extensions/dirty-repo-guard.ts +56 -0
  159. package/examples/extensions/doom-overlay/README.md +46 -0
  160. package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  161. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  162. package/examples/extensions/doom-overlay/doom/build.sh +152 -0
  163. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  164. package/examples/extensions/doom-overlay/doom-component.ts +133 -0
  165. package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  166. package/examples/extensions/doom-overlay/doom-keys.ts +105 -0
  167. package/examples/extensions/doom-overlay/index.ts +74 -0
  168. package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
  169. package/examples/extensions/event-bus.ts +43 -0
  170. package/examples/extensions/file-trigger.ts +41 -0
  171. package/examples/extensions/git-checkpoint.ts +53 -0
  172. package/examples/extensions/handoff.ts +151 -0
  173. package/examples/extensions/hello.ts +25 -0
  174. package/examples/extensions/inline-bash.ts +94 -0
  175. package/examples/extensions/input-transform.ts +43 -0
  176. package/examples/extensions/interactive-shell.ts +196 -0
  177. package/examples/extensions/mac-system-theme.ts +47 -0
  178. package/examples/extensions/message-renderer.ts +60 -0
  179. package/examples/extensions/modal-editor.ts +86 -0
  180. package/examples/extensions/model-status.ts +31 -0
  181. package/examples/extensions/notify.ts +25 -0
  182. package/examples/extensions/overlay-qa-tests.ts +882 -0
  183. package/examples/extensions/overlay-test.ts +151 -0
  184. package/examples/extensions/permission-gate.ts +34 -0
  185. package/examples/extensions/pirate.ts +47 -0
  186. package/examples/extensions/plan-mode/README.md +65 -0
  187. package/examples/extensions/plan-mode/index.ts +341 -0
  188. package/examples/extensions/plan-mode/utils.ts +168 -0
  189. package/examples/extensions/preset.ts +399 -0
  190. package/examples/extensions/protected-paths.ts +30 -0
  191. package/examples/extensions/qna.ts +120 -0
  192. package/examples/extensions/question.ts +265 -0
  193. package/examples/extensions/questionnaire.ts +428 -0
  194. package/examples/extensions/rainbow-editor.ts +88 -0
  195. package/examples/extensions/sandbox/index.ts +318 -0
  196. package/examples/extensions/sandbox/package-lock.json +92 -0
  197. package/examples/extensions/sandbox/package.json +19 -0
  198. package/examples/extensions/send-user-message.ts +97 -0
  199. package/examples/extensions/session-name.ts +27 -0
  200. package/examples/extensions/shutdown-command.ts +63 -0
  201. package/examples/extensions/snake.ts +344 -0
  202. package/examples/extensions/space-invaders.ts +561 -0
  203. package/examples/extensions/ssh.ts +220 -0
  204. package/examples/extensions/status-line.ts +40 -0
  205. package/examples/extensions/subagent/README.md +172 -0
  206. package/examples/extensions/subagent/agents/planner.md +37 -0
  207. package/examples/extensions/subagent/agents/reviewer.md +35 -0
  208. package/examples/extensions/subagent/agents/scout.md +50 -0
  209. package/examples/extensions/subagent/agents/worker.md +24 -0
  210. package/examples/extensions/subagent/agents.ts +127 -0
  211. package/examples/extensions/subagent/index.ts +964 -0
  212. package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  213. package/examples/extensions/subagent/prompts/implement.md +10 -0
  214. package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  215. package/examples/extensions/summarize.ts +196 -0
  216. package/examples/extensions/timed-confirm.ts +70 -0
  217. package/examples/extensions/todo.ts +300 -0
  218. package/examples/extensions/tool-override.ts +144 -0
  219. package/examples/extensions/tools.ts +147 -0
  220. package/examples/extensions/trigger-compact.ts +40 -0
  221. package/examples/extensions/truncated-tool.ts +193 -0
  222. package/examples/extensions/widget-placement.ts +17 -0
  223. package/examples/extensions/with-deps/index.ts +36 -0
  224. package/examples/extensions/with-deps/package-lock.json +31 -0
  225. package/examples/extensions/with-deps/package.json +22 -0
  226. package/examples/sdk/01-minimal.ts +22 -0
  227. package/examples/sdk/02-custom-model.ts +50 -0
  228. package/examples/sdk/03-custom-prompt.ts +55 -0
  229. package/examples/sdk/04-skills.ts +46 -0
  230. package/examples/sdk/05-tools.ts +56 -0
  231. package/examples/sdk/06-extensions.ts +88 -0
  232. package/examples/sdk/07-context-files.ts +40 -0
  233. package/examples/sdk/08-prompt-templates.ts +47 -0
  234. package/examples/sdk/09-api-keys-and-oauth.ts +48 -0
  235. package/examples/sdk/10-settings.ts +38 -0
  236. package/examples/sdk/11-sessions.ts +48 -0
  237. package/examples/sdk/12-full-control.ts +82 -0
  238. package/examples/sdk/13-codex-oauth.ts +37 -0
  239. package/examples/sdk/README.md +144 -0
  240. package/package.json +85 -0
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Hello Tool - Minimal custom tool example
3
+ */
4
+
5
+ import type { ExtensionAPI } from "indusagi-coding-agent";
6
+ import { Type } from "@sinclair/typebox";
7
+
8
+ export default function (indusagi: ExtensionAPI) {
9
+ indusagi.registerTool({
10
+ name: "hello",
11
+ label: "Hello",
12
+ description: "A simple greeting tool",
13
+ parameters: Type.Object({
14
+ name: Type.String({ description: "Name to greet" }),
15
+ }),
16
+
17
+ async execute(_toolCallId, params, _onUpdate, _ctx, _signal) {
18
+ const { name } = params as { name: string };
19
+ return {
20
+ content: [{ type: "text", text: `Hello, ${name}!` }],
21
+ details: { greeted: name },
22
+ };
23
+ },
24
+ });
25
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Inline Bash Extension - expands inline bash commands in user prompts.
3
+ *
4
+ * Start indusagi with this extension:
5
+ * indusagi -e ./examples/extensions/inline-bash.ts
6
+ *
7
+ * Then type prompts with inline bash:
8
+ * What's in !{pwd}?
9
+ * The current branch is !{git branch --show-current} and status: !{git status --short}
10
+ * My node version is !{node --version}
11
+ *
12
+ * The !{command} patterns are executed and replaced with their output before
13
+ * the prompt is sent to the agent.
14
+ *
15
+ * Note: Regular !command syntax (whole-line bash) is preserved and works as before.
16
+ */
17
+ import type { ExtensionAPI } from "indusagi-coding-agent";
18
+
19
+ export default function (indusagi: ExtensionAPI) {
20
+ const PATTERN = /!\{([^}]+)\}/g;
21
+ const TIMEOUT_MS = 30000;
22
+
23
+ indusagi.on("input", async (event, ctx) => {
24
+ const text = event.text;
25
+
26
+ // Don't process if it's a whole-line bash command (starts with !)
27
+ // This preserves the existing !command behavior
28
+ if (text.trimStart().startsWith("!") && !text.trimStart().startsWith("!{")) {
29
+ return { action: "continue" };
30
+ }
31
+
32
+ // Check if there are any inline bash patterns
33
+ if (!PATTERN.test(text)) {
34
+ return { action: "continue" };
35
+ }
36
+
37
+ // Reset regex state after test()
38
+ PATTERN.lastIndex = 0;
39
+
40
+ let result = text;
41
+ const expansions: Array<{ command: string; output: string; error?: string }> = [];
42
+
43
+ // Find all matches first (to avoid issues with replacing while iterating)
44
+ const matches: Array<{ full: string; command: string }> = [];
45
+ let match = PATTERN.exec(text);
46
+ while (match) {
47
+ matches.push({ full: match[0], command: match[1] });
48
+ match = PATTERN.exec(text);
49
+ }
50
+
51
+ // Execute each command and collect results
52
+ for (const { full, command } of matches) {
53
+ try {
54
+ const bashResult = await indusagi.exec("bash", ["-c", command], {
55
+ timeout: TIMEOUT_MS,
56
+ });
57
+
58
+ const output = bashResult.stdout || bashResult.stderr || "";
59
+ const trimmed = output.trim();
60
+
61
+ if (bashResult.code !== 0 && bashResult.stderr) {
62
+ expansions.push({
63
+ command,
64
+ output: trimmed,
65
+ error: `exit code ${bashResult.code}`,
66
+ });
67
+ } else {
68
+ expansions.push({ command, output: trimmed });
69
+ }
70
+
71
+ result = result.replace(full, trimmed);
72
+ } catch (err) {
73
+ const errorMsg = err instanceof Error ? err.message : String(err);
74
+ expansions.push({ command, output: "", error: errorMsg });
75
+ result = result.replace(full, `[error: ${errorMsg}]`);
76
+ }
77
+ }
78
+
79
+ // Show what was expanded (if UI available)
80
+ if (ctx.hasUI && expansions.length > 0) {
81
+ const summary = expansions
82
+ .map((e) => {
83
+ const status = e.error ? ` (${e.error})` : "";
84
+ const preview = e.output.length > 50 ? `${e.output.slice(0, 50)}...` : e.output;
85
+ return `!{${e.command}}${status} -> "${preview}"`;
86
+ })
87
+ .join("\n");
88
+
89
+ ctx.ui.notify(`Expanded ${expansions.length} inline command(s):\n${summary}`, "info");
90
+ }
91
+
92
+ return { action: "transform", text: result, images: event.images };
93
+ });
94
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Input Transform Example - demonstrates the `input` event for intercepting user input.
3
+ *
4
+ * Start indusagi with this extension:
5
+ * indusagi -e ./examples/extensions/input-transform.ts
6
+ *
7
+ * Then type these inside indusagi:
8
+ * ?quick What is TypeScript? → "Respond briefly: What is TypeScript?"
9
+ * ping → "pong" (instant, no LLM)
10
+ * time → current time (instant, no LLM)
11
+ */
12
+ import type { ExtensionAPI } from "indusagi-coding-agent";
13
+
14
+ export default function (indusagi: ExtensionAPI) {
15
+ indusagi.on("input", async (event, ctx) => {
16
+ // Source-based logic: skip processing for extension-injected messages
17
+ if (event.source === "extension") {
18
+ return { action: "continue" };
19
+ }
20
+
21
+ // Transform: ?quick prefix for brief responses
22
+ if (event.text.startsWith("?quick ")) {
23
+ const query = event.text.slice(7).trim();
24
+ if (!query) {
25
+ ctx.ui.notify("Usage: ?quick <question>", "warning");
26
+ return { action: "handled" };
27
+ }
28
+ return { action: "transform", text: `Respond briefly in 1-2 sentences: ${query}` };
29
+ }
30
+
31
+ // Handle: instant responses without LLM (extension shows its own feedback)
32
+ if (event.text.toLowerCase() === "ping") {
33
+ ctx.ui.notify("pong", "info");
34
+ return { action: "handled" };
35
+ }
36
+ if (event.text.toLowerCase() === "time") {
37
+ ctx.ui.notify(new Date().toLocaleString(), "info");
38
+ return { action: "handled" };
39
+ }
40
+
41
+ return { action: "continue" };
42
+ });
43
+ }
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Interactive Shell Commands Extension
3
+ *
4
+ * Enables running interactive commands (vim, git rebase -i, htop, etc.)
5
+ * with full terminal access. The TUI suspends while they run.
6
+ *
7
+ * Usage:
8
+ * indusagi -e examples/extensions/interactive-shell.ts
9
+ *
10
+ * !vim file.txt # Auto-detected as interactive
11
+ * !i any-command # Force interactive mode with !i prefix
12
+ * !git rebase -i HEAD~3
13
+ * !htop
14
+ *
15
+ * Configuration via environment variables:
16
+ * INTERACTIVE_COMMANDS - Additional commands (comma-separated)
17
+ * INTERACTIVE_EXCLUDE - Commands to exclude (comma-separated)
18
+ *
19
+ * Note: This only intercepts user `!` commands, not agent bash tool calls.
20
+ * If the agent runs an interactive command, it will fail (which is fine).
21
+ */
22
+
23
+ import { spawnSync } from "node:child_process";
24
+ import type { ExtensionAPI } from "indusagi-coding-agent";
25
+
26
+ // Default interactive commands - editors, pagers, git ops, TUIs
27
+ const DEFAULT_INTERACTIVE_COMMANDS = [
28
+ // Editors
29
+ "vim",
30
+ "nvim",
31
+ "vi",
32
+ "nano",
33
+ "emacs",
34
+ "pico",
35
+ "micro",
36
+ "helix",
37
+ "hx",
38
+ "kak",
39
+ // Pagers
40
+ "less",
41
+ "more",
42
+ "most",
43
+ // Git interactive
44
+ "git commit",
45
+ "git rebase",
46
+ "git merge",
47
+ "git cherry-pick",
48
+ "git revert",
49
+ "git add -p",
50
+ "git add --patch",
51
+ "git add -i",
52
+ "git add --interactive",
53
+ "git stash -p",
54
+ "git stash --patch",
55
+ "git reset -p",
56
+ "git reset --patch",
57
+ "git checkout -p",
58
+ "git checkout --patch",
59
+ "git difftool",
60
+ "git mergetool",
61
+ // System monitors
62
+ "htop",
63
+ "top",
64
+ "btop",
65
+ "glances",
66
+ // File managers
67
+ "ranger",
68
+ "nnn",
69
+ "lf",
70
+ "mc",
71
+ "vifm",
72
+ // Git TUIs
73
+ "tig",
74
+ "lazygit",
75
+ "gitui",
76
+ // Fuzzy finders
77
+ "fzf",
78
+ "sk",
79
+ // Remote sessions
80
+ "ssh",
81
+ "telnet",
82
+ "mosh",
83
+ // Database clients
84
+ "psql",
85
+ "mysql",
86
+ "sqlite3",
87
+ "mongosh",
88
+ "redis-cli",
89
+ // Kubernetes/Docker
90
+ "kubectl edit",
91
+ "kubectl exec -it",
92
+ "docker exec -it",
93
+ "docker run -it",
94
+ // Other
95
+ "tmux",
96
+ "screen",
97
+ "ncdu",
98
+ ];
99
+
100
+ function getInteractiveCommands(): string[] {
101
+ const additional =
102
+ process.env.INTERACTIVE_COMMANDS?.split(",")
103
+ .map((s) => s.trim())
104
+ .filter(Boolean) ?? [];
105
+ const excluded = new Set(process.env.INTERACTIVE_EXCLUDE?.split(",").map((s) => s.trim().toLowerCase()) ?? []);
106
+ return [...DEFAULT_INTERACTIVE_COMMANDS, ...additional].filter((cmd) => !excluded.has(cmd.toLowerCase()));
107
+ }
108
+
109
+ function isInteractiveCommand(command: string): boolean {
110
+ const trimmed = command.trim().toLowerCase();
111
+ const commands = getInteractiveCommands();
112
+
113
+ for (const cmd of commands) {
114
+ const cmdLower = cmd.toLowerCase();
115
+ // Match at start
116
+ if (trimmed === cmdLower || trimmed.startsWith(`${cmdLower} `) || trimmed.startsWith(`${cmdLower}\t`)) {
117
+ return true;
118
+ }
119
+ // Match after pipe: "cat file | less"
120
+ const pipeIdx = trimmed.lastIndexOf("|");
121
+ if (pipeIdx !== -1) {
122
+ const afterPipe = trimmed.slice(pipeIdx + 1).trim();
123
+ if (afterPipe === cmdLower || afterPipe.startsWith(`${cmdLower} `)) {
124
+ return true;
125
+ }
126
+ }
127
+ }
128
+ return false;
129
+ }
130
+
131
+ export default function (indusagi: ExtensionAPI) {
132
+ indusagi.on("user_bash", async (event, ctx) => {
133
+ let command = event.command;
134
+ let forceInteractive = false;
135
+
136
+ // Check for !i prefix (command comes without the leading !)
137
+ // The prefix parsing happens before this event, so we check if command starts with "i "
138
+ if (command.startsWith("i ") || command.startsWith("i\t")) {
139
+ forceInteractive = true;
140
+ command = command.slice(2).trim();
141
+ }
142
+
143
+ const shouldBeInteractive = forceInteractive || isInteractiveCommand(command);
144
+ if (!shouldBeInteractive) {
145
+ return; // Let normal handling proceed
146
+ }
147
+
148
+ // No UI available (print mode, RPC, etc.)
149
+ if (!ctx.hasUI) {
150
+ return {
151
+ result: { output: "(interactive commands require TUI)", exitCode: 1, cancelled: false, truncated: false },
152
+ };
153
+ }
154
+
155
+ // Use ctx.ui.custom() to get TUI access, then run the command
156
+ const exitCode = await ctx.ui.custom<number | null>((tui, _theme, _kb, done) => {
157
+ // Stop TUI to release terminal
158
+ tui.stop();
159
+
160
+ // Clear screen
161
+ process.stdout.write("\x1b[2J\x1b[H");
162
+
163
+ // Run command with full terminal access
164
+ const shell = process.env.SHELL || "/bin/sh";
165
+ const result = spawnSync(shell, ["-c", command], {
166
+ stdio: "inherit",
167
+ env: process.env,
168
+ });
169
+
170
+ // Restart TUI
171
+ tui.start();
172
+ tui.requestRender(true);
173
+
174
+ // Signal completion
175
+ done(result.status);
176
+
177
+ // Return empty component (immediately disposed since done() was called)
178
+ return { render: () => [], invalidate: () => {} };
179
+ });
180
+
181
+ // Return result to prevent default bash handling
182
+ const output =
183
+ exitCode === 0
184
+ ? "(interactive command completed successfully)"
185
+ : `(interactive command exited with code ${exitCode})`;
186
+
187
+ return {
188
+ result: {
189
+ output,
190
+ exitCode: exitCode ?? 1,
191
+ cancelled: false,
192
+ truncated: false,
193
+ },
194
+ };
195
+ });
196
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Syncs indusagi theme with macOS system appearance (dark/light mode).
3
+ *
4
+ * Usage:
5
+ * indusagi -e examples/extensions/mac-system-theme.ts
6
+ */
7
+
8
+ import { exec } from "node:child_process";
9
+ import { promisify } from "node:util";
10
+ import type { ExtensionAPI } from "indusagi-coding-agent";
11
+
12
+ const execAsync = promisify(exec);
13
+
14
+ async function isDarkMode(): Promise<boolean> {
15
+ try {
16
+ const { stdout } = await execAsync(
17
+ "osascript -e 'tell application \"System Events\" to tell appearance preferences to return dark mode'",
18
+ );
19
+ return stdout.trim() === "true";
20
+ } catch {
21
+ return false;
22
+ }
23
+ }
24
+
25
+ export default function (indusagi: ExtensionAPI) {
26
+ let intervalId: ReturnType<typeof setInterval> | null = null;
27
+
28
+ indusagi.on("session_start", async (_event, ctx) => {
29
+ let currentTheme = (await isDarkMode()) ? "dark" : "light";
30
+ ctx.ui.setTheme(currentTheme);
31
+
32
+ intervalId = setInterval(async () => {
33
+ const newTheme = (await isDarkMode()) ? "dark" : "light";
34
+ if (newTheme !== currentTheme) {
35
+ currentTheme = newTheme;
36
+ ctx.ui.setTheme(currentTheme);
37
+ }
38
+ }, 2000);
39
+ });
40
+
41
+ indusagi.on("session_shutdown", () => {
42
+ if (intervalId) {
43
+ clearInterval(intervalId);
44
+ intervalId = null;
45
+ }
46
+ });
47
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Custom message rendering example.
3
+ *
4
+ * Shows how to use registerMessageRenderer to control how custom messages
5
+ * appear in the TUI, with colors, formatting, and expandable details.
6
+ *
7
+ * Usage: /status [message] - sends a status message with custom rendering
8
+ */
9
+
10
+ import type { ExtensionAPI } from "indusagi-coding-agent";
11
+ import { Box, Text } from "indusagi/tui";
12
+
13
+ export default function (indusagi: ExtensionAPI) {
14
+ // Register custom renderer for "status-update" messages
15
+ indusagi.registerMessageRenderer("status-update", (message, { expanded }, theme) => {
16
+ const details = message.details as { level: string; timestamp: number } | undefined;
17
+ const level = details?.level ?? "info";
18
+
19
+ // Color based on level
20
+ const color = level === "error" ? "error" : level === "warn" ? "warning" : "success";
21
+ const prefix = theme.fg(color, `[${level.toUpperCase()}]`);
22
+
23
+ let text = `${prefix} ${message.content}`;
24
+
25
+ // Show timestamp when expanded
26
+ if (expanded && details?.timestamp) {
27
+ const time = new Date(details.timestamp).toLocaleTimeString();
28
+ text += `\n${theme.fg("dim", ` at ${time}`)}`;
29
+ }
30
+
31
+ // Use Box with customMessageBg for consistent styling
32
+ const box = new Box(1, 1, (t) => theme.bg("customMessageBg", t));
33
+ box.addChild(new Text(text, 0, 0));
34
+ return box;
35
+ });
36
+
37
+ // Command to send status messages
38
+ indusagi.registerCommand("status", {
39
+ description: "Send a status message (usage: /status [warn|error] message)",
40
+ handler: async (args, _ctx) => {
41
+ const parts = args.trim().split(/\s+/);
42
+ let level = "info";
43
+ let content = args.trim();
44
+
45
+ // Check for level prefix
46
+ if (parts[0] === "warn" || parts[0] === "error") {
47
+ level = parts[0];
48
+ content = parts.slice(1).join(" ") || "Status update";
49
+ }
50
+
51
+ indusagi.sendMessage({
52
+ customType: "status-update",
53
+ content,
54
+ display: true,
55
+ details: { level, timestamp: Date.now() },
56
+ });
57
+ },
58
+ });
59
+ }
60
+
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Modal Editor - vim-like modal editing example
3
+ *
4
+ * Usage: indusagi --extension ./examples/extensions/modal-editor.ts
5
+ *
6
+ * - Escape: insert → normal mode (in normal mode, aborts agent)
7
+ * - i: normal → insert mode
8
+ * - hjkl: navigation in normal mode
9
+ * - ctrl+c, ctrl+d, etc. work in both modes
10
+ */
11
+
12
+ import { CustomEditor, type ExtensionAPI } from "indusagi-coding-agent";
13
+ import { matchesKey, truncateToWidth, visibleWidth } from "indusagi/tui";
14
+
15
+ // Normal mode key mappings: key -> escape sequence (or null for mode switch)
16
+ const NORMAL_KEYS: Record<string, string | null> = {
17
+ h: "\x1b[D", // left
18
+ j: "\x1b[B", // down
19
+ k: "\x1b[A", // up
20
+ l: "\x1b[C", // right
21
+ "0": "\x01", // line start
22
+ $: "\x05", // line end
23
+ x: "\x1b[3~", // delete char
24
+ i: null, // insert mode
25
+ a: null, // append (insert + right)
26
+ };
27
+
28
+ class ModalEditor extends CustomEditor {
29
+ private mode: "normal" | "insert" = "insert";
30
+
31
+ handleInput(data: string): void {
32
+ // Escape toggles to normal mode, or passes through for app handling
33
+ if (matchesKey(data, "escape")) {
34
+ if (this.mode === "insert") {
35
+ this.mode = "normal";
36
+ } else {
37
+ super.handleInput(data); // abort agent, etc.
38
+ }
39
+ return;
40
+ }
41
+
42
+ // Insert mode: pass everything through
43
+ if (this.mode === "insert") {
44
+ super.handleInput(data);
45
+ return;
46
+ }
47
+
48
+ // Normal mode: check mapped keys
49
+ if (data in NORMAL_KEYS) {
50
+ const seq = NORMAL_KEYS[data];
51
+ if (data === "i") {
52
+ this.mode = "insert";
53
+ } else if (data === "a") {
54
+ this.mode = "insert";
55
+ super.handleInput("\x1b[C"); // move right first
56
+ } else if (seq) {
57
+ super.handleInput(seq);
58
+ }
59
+ return;
60
+ }
61
+
62
+ // Pass control sequences (ctrl+c, etc.) to super, ignore printable chars
63
+ if (data.length === 1 && data.charCodeAt(0) >= 32) return;
64
+ super.handleInput(data);
65
+ }
66
+
67
+ render(width: number): string[] {
68
+ const lines = super.render(width);
69
+ if (lines.length === 0) return lines;
70
+
71
+ // Add mode indicator to bottom border
72
+ const label = this.mode === "normal" ? " NORMAL " : " INSERT ";
73
+ const last = lines.length - 1;
74
+ if (visibleWidth(lines[last]!) >= label.length) {
75
+ lines[last] = truncateToWidth(lines[last]!, width - label.length, "") + label;
76
+ }
77
+ return lines;
78
+ }
79
+ }
80
+
81
+ export default function (indusagi: ExtensionAPI) {
82
+ indusagi.on("session_start", (_event, ctx) => {
83
+ ctx.ui.setEditorComponent((tui, theme, kb) => new ModalEditor(tui, theme, kb));
84
+ });
85
+ }
86
+
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Model status extension - shows model changes in the status bar.
3
+ *
4
+ * Demonstrates the `model_select` hook which fires when the model changes
5
+ * via /model command, Ctrl+P cycling, or session restore.
6
+ *
7
+ * Usage: indusagi -e ./model-status.ts
8
+ */
9
+
10
+ import type { ExtensionAPI } from "indusagi-coding-agent";
11
+
12
+ export default function (indusagi: ExtensionAPI) {
13
+ indusagi.on("model_select", async (event, ctx) => {
14
+ const { model, previousModel, source } = event;
15
+
16
+ // Format model identifiers
17
+ const next = `${model.provider}/${model.id}`;
18
+ const prev = previousModel ? `${previousModel.provider}/${previousModel.id}` : "none";
19
+
20
+ // Show notification on change
21
+ if (source !== "restore") {
22
+ ctx.ui.notify(`Model: ${next}`, "info");
23
+ }
24
+
25
+ // Update status bar with current model
26
+ ctx.ui.setStatus("model", `🤖 ${model.id}`);
27
+
28
+ // Log change details (visible in debug output)
29
+ console.log(`[model_select] ${prev} → ${next} (${source})`);
30
+ });
31
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Desktop Notification Extension
3
+ *
4
+ * Sends a native desktop notification when the agent finishes and is waiting for input.
5
+ * Uses OSC 777 escape sequence - no external dependencies.
6
+ *
7
+ * Supported terminals: Ghostty, iTerm2, WezTerm, rxvt-unicode
8
+ * Not supported: Kitty (uses OSC 99), Terminal.app, Windows Terminal, Alacritty
9
+ */
10
+
11
+ import type { ExtensionAPI } from "indusagi-coding-agent";
12
+
13
+ /**
14
+ * Send a desktop notification via OSC 777 escape sequence.
15
+ */
16
+ function notify(title: string, body: string): void {
17
+ // OSC 777 format: ESC ] 777 ; notify ; title ; body BEL
18
+ process.stdout.write(`\x1b]777;notify;${title};${body}\x07`);
19
+ }
20
+
21
+ export default function (indusagi: ExtensionAPI) {
22
+ indusagi.on("agent_end", async () => {
23
+ notify("Indusagi", "Ready for input");
24
+ });
25
+ }