@apholdings/jensen-code 0.0.4 → 0.0.6

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 (161) hide show
  1. package/CHANGELOG.md +3061 -3061
  2. package/README.md +1 -1
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +6 -6
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/config.d.ts +17 -6
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/config.js +55 -28
  9. package/dist/config.js.map +1 -1
  10. package/dist/core/agent-session.d.ts.map +1 -1
  11. package/dist/core/agent-session.js +10 -0
  12. package/dist/core/agent-session.js.map +1 -1
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/modes/interactive/components/assistant-message.d.ts +1 -6
  18. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  19. package/dist/modes/interactive/components/assistant-message.js +10 -40
  20. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  21. package/dist/modes/interactive/components/custom-editor.d.ts +1 -0
  22. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  23. package/dist/modes/interactive/components/custom-editor.js +5 -0
  24. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  25. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  26. package/dist/modes/interactive/components/tool-execution.js +1 -2
  27. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  28. package/dist/modes/interactive/components/top-bar.d.ts.map +1 -1
  29. package/dist/modes/interactive/components/top-bar.js +1 -1
  30. package/dist/modes/interactive/components/top-bar.js.map +1 -1
  31. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  32. package/dist/modes/interactive/components/user-message.js +1 -1
  33. package/dist/modes/interactive/components/user-message.js.map +1 -1
  34. package/dist/modes/interactive/interactive-mode.d.ts +6 -3
  35. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  36. package/dist/modes/interactive/interactive-mode.js +204 -86
  37. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  38. package/dist/utils/frontmatter.d.ts.map +1 -1
  39. package/dist/utils/frontmatter.js +8 -4
  40. package/dist/utils/frontmatter.js.map +1 -1
  41. package/dist/utils/tools-manager.d.ts.map +1 -1
  42. package/dist/utils/tools-manager.js +2 -2
  43. package/dist/utils/tools-manager.js.map +1 -1
  44. package/docs/custom-provider.md +592 -592
  45. package/docs/session.md +412 -412
  46. package/examples/extensions/osgrep.ts +643 -0
  47. package/examples/extensions/subagent/agents.ts +150 -37
  48. package/examples/extensions/subagent/index.ts +634 -513
  49. package/package.json +3 -3
  50. package/examples/README.md +0 -25
  51. package/examples/extensions/README.md +0 -206
  52. package/examples/extensions/antigravity-image-gen.ts +0 -415
  53. package/examples/extensions/auto-commit-on-exit.ts +0 -49
  54. package/examples/extensions/bash-spawn-hook.ts +0 -30
  55. package/examples/extensions/bookmark.ts +0 -50
  56. package/examples/extensions/built-in-tool-renderer.ts +0 -246
  57. package/examples/extensions/claude-rules.ts +0 -86
  58. package/examples/extensions/commands.ts +0 -72
  59. package/examples/extensions/confirm-destructive.ts +0 -59
  60. package/examples/extensions/custom-compaction.ts +0 -114
  61. package/examples/extensions/custom-footer.ts +0 -64
  62. package/examples/extensions/custom-header.ts +0 -73
  63. package/examples/extensions/custom-provider-anthropic/index.ts +0 -604
  64. package/examples/extensions/custom-provider-anthropic/package-lock.json +0 -24
  65. package/examples/extensions/custom-provider-anthropic/package.json +0 -19
  66. package/examples/extensions/custom-provider-gitlab-duo/index.ts +0 -349
  67. package/examples/extensions/custom-provider-gitlab-duo/package.json +0 -16
  68. package/examples/extensions/custom-provider-gitlab-duo/test.ts +0 -82
  69. package/examples/extensions/custom-provider-qwen-cli/index.ts +0 -345
  70. package/examples/extensions/custom-provider-qwen-cli/package.json +0 -16
  71. package/examples/extensions/dirty-repo-guard.ts +0 -56
  72. package/examples/extensions/doom-overlay/README.md +0 -46
  73. package/examples/extensions/doom-overlay/doom/build/doom.js +0 -21
  74. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  75. package/examples/extensions/doom-overlay/doom/build.sh +0 -152
  76. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +0 -72
  77. package/examples/extensions/doom-overlay/doom-component.ts +0 -132
  78. package/examples/extensions/doom-overlay/doom-engine.ts +0 -173
  79. package/examples/extensions/doom-overlay/doom-keys.ts +0 -104
  80. package/examples/extensions/doom-overlay/index.ts +0 -74
  81. package/examples/extensions/doom-overlay/wad-finder.ts +0 -51
  82. package/examples/extensions/dynamic-resources/SKILL.md +0 -8
  83. package/examples/extensions/dynamic-resources/dynamic.json +0 -79
  84. package/examples/extensions/dynamic-resources/dynamic.md +0 -5
  85. package/examples/extensions/dynamic-resources/index.ts +0 -15
  86. package/examples/extensions/dynamic-tools.ts +0 -74
  87. package/examples/extensions/event-bus.ts +0 -43
  88. package/examples/extensions/file-trigger.ts +0 -41
  89. package/examples/extensions/git-checkpoint.ts +0 -53
  90. package/examples/extensions/handoff.ts +0 -150
  91. package/examples/extensions/hello.ts +0 -25
  92. package/examples/extensions/inline-bash.ts +0 -94
  93. package/examples/extensions/input-transform.ts +0 -43
  94. package/examples/extensions/interactive-shell.ts +0 -196
  95. package/examples/extensions/mac-system-theme.ts +0 -47
  96. package/examples/extensions/message-renderer.ts +0 -59
  97. package/examples/extensions/minimal-mode.ts +0 -426
  98. package/examples/extensions/modal-editor.ts +0 -85
  99. package/examples/extensions/model-status.ts +0 -31
  100. package/examples/extensions/notify.ts +0 -55
  101. package/examples/extensions/overlay-qa-tests.ts +0 -1348
  102. package/examples/extensions/overlay-test.ts +0 -150
  103. package/examples/extensions/permission-gate.ts +0 -34
  104. package/examples/extensions/pirate.ts +0 -47
  105. package/examples/extensions/plan-mode/README.md +0 -65
  106. package/examples/extensions/plan-mode/index.ts +0 -340
  107. package/examples/extensions/plan-mode/utils.ts +0 -168
  108. package/examples/extensions/preset.ts +0 -398
  109. package/examples/extensions/protected-paths.ts +0 -30
  110. package/examples/extensions/provider-payload.ts +0 -14
  111. package/examples/extensions/qna.ts +0 -119
  112. package/examples/extensions/question.ts +0 -264
  113. package/examples/extensions/questionnaire.ts +0 -427
  114. package/examples/extensions/rainbow-editor.ts +0 -88
  115. package/examples/extensions/reload-runtime.ts +0 -37
  116. package/examples/extensions/rpc-demo.ts +0 -124
  117. package/examples/extensions/sandbox/index.ts +0 -318
  118. package/examples/extensions/sandbox/package-lock.json +0 -92
  119. package/examples/extensions/sandbox/package.json +0 -19
  120. package/examples/extensions/send-user-message.ts +0 -97
  121. package/examples/extensions/session-name.ts +0 -27
  122. package/examples/extensions/shutdown-command.ts +0 -63
  123. package/examples/extensions/snake.ts +0 -343
  124. package/examples/extensions/space-invaders.ts +0 -560
  125. package/examples/extensions/ssh.ts +0 -220
  126. package/examples/extensions/status-line.ts +0 -40
  127. package/examples/extensions/subagent/README.md +0 -172
  128. package/examples/extensions/subagent/agents/planner.md +0 -37
  129. package/examples/extensions/subagent/agents/reviewer.md +0 -35
  130. package/examples/extensions/subagent/agents/scout.md +0 -50
  131. package/examples/extensions/subagent/agents/worker.md +0 -24
  132. package/examples/extensions/subagent/prompts/implement-and-review.md +0 -10
  133. package/examples/extensions/subagent/prompts/implement.md +0 -10
  134. package/examples/extensions/subagent/prompts/scout-and-plan.md +0 -9
  135. package/examples/extensions/summarize.ts +0 -195
  136. package/examples/extensions/system-prompt-header.ts +0 -17
  137. package/examples/extensions/timed-confirm.ts +0 -70
  138. package/examples/extensions/titlebar-spinner.ts +0 -58
  139. package/examples/extensions/todo.ts +0 -299
  140. package/examples/extensions/tool-override.ts +0 -143
  141. package/examples/extensions/tools.ts +0 -146
  142. package/examples/extensions/trigger-compact.ts +0 -40
  143. package/examples/extensions/truncated-tool.ts +0 -192
  144. package/examples/extensions/widget-placement.ts +0 -17
  145. package/examples/extensions/with-deps/index.ts +0 -32
  146. package/examples/extensions/with-deps/package-lock.json +0 -31
  147. package/examples/extensions/with-deps/package.json +0 -22
  148. package/examples/rpc-extension-ui.ts +0 -632
  149. package/examples/sdk/01-minimal.ts +0 -22
  150. package/examples/sdk/02-custom-model.ts +0 -49
  151. package/examples/sdk/03-custom-prompt.ts +0 -55
  152. package/examples/sdk/04-skills.ts +0 -46
  153. package/examples/sdk/05-tools.ts +0 -56
  154. package/examples/sdk/06-extensions.ts +0 -88
  155. package/examples/sdk/07-context-files.ts +0 -40
  156. package/examples/sdk/08-prompt-templates.ts +0 -47
  157. package/examples/sdk/09-api-keys-and-oauth.ts +0 -48
  158. package/examples/sdk/10-settings.ts +0 -51
  159. package/examples/sdk/11-sessions.ts +0 -48
  160. package/examples/sdk/12-full-control.ts +0 -82
  161. package/examples/sdk/README.md +0 -145
@@ -1,114 +0,0 @@
1
- /**
2
- * Custom Compaction Extension
3
- *
4
- * Replaces the default compaction behavior with a full summary of the entire context.
5
- * Instead of keeping the last 20k tokens of conversation turns, this extension:
6
- * 1. Summarizes ALL messages (messagesToSummarize + turnPrefixMessages)
7
- * 2. Discards all old turns completely, keeping only the summary
8
- *
9
- * This example also demonstrates using a different model (Gemini Flash) for summarization,
10
- * which can be cheaper/faster than the main conversation model.
11
- *
12
- * Usage:
13
- * pi --extension examples/extensions/custom-compaction.ts
14
- */
15
-
16
- import { complete } from "@apholdings/jensen-ai";
17
- import type { ExtensionAPI } from "@apholdings/jensen-code";
18
- import { convertToLlm, serializeConversation } from "@apholdings/jensen-code";
19
-
20
- export default function (pi: ExtensionAPI) {
21
- pi.on("session_before_compact", async (event, ctx) => {
22
- ctx.ui.notify("Custom compaction extension triggered", "info");
23
-
24
- const { preparation, branchEntries: _, signal } = event;
25
- const { messagesToSummarize, turnPrefixMessages, tokensBefore, firstKeptEntryId, previousSummary } = preparation;
26
-
27
- // Use Gemini Flash for summarization (cheaper/faster than most conversation models)
28
- const model = ctx.modelRegistry.find("google", "gemini-2.5-flash");
29
- if (!model) {
30
- ctx.ui.notify(`Could not find Gemini Flash model, using default compaction`, "warning");
31
- return;
32
- }
33
-
34
- // Resolve API key for the summarization model
35
- const apiKey = await ctx.modelRegistry.getApiKey(model);
36
- if (!apiKey) {
37
- ctx.ui.notify(`No API key for ${model.provider}, using default compaction`, "warning");
38
- return;
39
- }
40
-
41
- // Combine all messages for full summary
42
- const allMessages = [...messagesToSummarize, ...turnPrefixMessages];
43
-
44
- ctx.ui.notify(
45
- `Custom compaction: summarizing ${allMessages.length} messages (${tokensBefore.toLocaleString()} tokens) with ${model.id}...`,
46
- "info",
47
- );
48
-
49
- // Convert messages to readable text format
50
- const conversationText = serializeConversation(convertToLlm(allMessages));
51
-
52
- // Include previous summary context if available
53
- const previousContext = previousSummary ? `\n\nPrevious session summary for context:\n${previousSummary}` : "";
54
-
55
- // Build messages that ask for a comprehensive summary
56
- const summaryMessages = [
57
- {
58
- role: "user" as const,
59
- content: [
60
- {
61
- type: "text" as const,
62
- text: `You are a conversation summarizer. Create a comprehensive summary of this conversation that captures:${previousContext}
63
-
64
- 1. The main goals and objectives discussed
65
- 2. Key decisions made and their rationale
66
- 3. Important code changes, file modifications, or technical details
67
- 4. Current state of any ongoing work
68
- 5. Any blockers, issues, or open questions
69
- 6. Next steps that were planned or suggested
70
-
71
- Be thorough but concise. The summary will replace the ENTIRE conversation history, so include all information needed to continue the work effectively.
72
-
73
- Format the summary as structured markdown with clear sections.
74
-
75
- <conversation>
76
- ${conversationText}
77
- </conversation>`,
78
- },
79
- ],
80
- timestamp: Date.now(),
81
- },
82
- ];
83
-
84
- try {
85
- // Pass signal to honor abort requests (e.g., user cancels compaction)
86
- const response = await complete(model, { messages: summaryMessages }, { apiKey, maxTokens: 8192, signal });
87
-
88
- const summary = response.content
89
- .filter((c): c is { type: "text"; text: string } => c.type === "text")
90
- .map((c) => c.text)
91
- .join("\n");
92
-
93
- if (!summary.trim()) {
94
- if (!signal.aborted) ctx.ui.notify("Compaction summary was empty, using default compaction", "warning");
95
- return;
96
- }
97
-
98
- // Return compaction content - SessionManager adds id/parentId
99
- // Use firstKeptEntryId from preparation to keep recent messages
100
- return {
101
- compaction: {
102
- summary,
103
- firstKeptEntryId,
104
- tokensBefore,
105
- },
106
- };
107
- } catch (error) {
108
- const message = error instanceof Error ? error.message : String(error);
109
- ctx.ui.notify(`Compaction failed: ${message}`, "error");
110
- // Fall back to default compaction on error
111
- return;
112
- }
113
- });
114
- }
@@ -1,64 +0,0 @@
1
- /**
2
- * Custom Footer Extension - demonstrates ctx.ui.setFooter()
3
- *
4
- * footerData exposes data not otherwise accessible:
5
- * - getGitBranch(): current git branch
6
- * - getExtensionStatuses(): texts from ctx.ui.setStatus()
7
- *
8
- * Token stats come from ctx.sessionManager/ctx.model (already accessible).
9
- */
10
-
11
- import type { AssistantMessage } from "@apholdings/jensen-ai";
12
- import type { ExtensionAPI } from "@apholdings/jensen-code";
13
- import { truncateToWidth, visibleWidth } from "@apholdings/jensen-tui";
14
-
15
- export default function (pi: ExtensionAPI) {
16
- let enabled = false;
17
-
18
- pi.registerCommand("footer", {
19
- description: "Toggle custom footer",
20
- handler: async (_args, ctx) => {
21
- enabled = !enabled;
22
-
23
- if (enabled) {
24
- ctx.ui.setFooter((tui, theme, footerData) => {
25
- const unsub = footerData.onBranchChange(() => tui.requestRender());
26
-
27
- return {
28
- dispose: unsub,
29
- invalidate() {},
30
- render(width: number): string[] {
31
- // Compute tokens from ctx (already accessible to extensions)
32
- let input = 0,
33
- output = 0,
34
- cost = 0;
35
- for (const e of ctx.sessionManager.getBranch()) {
36
- if (e.type === "message" && e.message.role === "assistant") {
37
- const m = e.message as AssistantMessage;
38
- input += m.usage.input;
39
- output += m.usage.output;
40
- cost += m.usage.cost.total;
41
- }
42
- }
43
-
44
- // Get git branch (not otherwise accessible)
45
- const branch = footerData.getGitBranch();
46
- const fmt = (n: number) => (n < 1000 ? `${n}` : `${(n / 1000).toFixed(1)}k`);
47
-
48
- const left = theme.fg("dim", `↑${fmt(input)} ↓${fmt(output)} $${cost.toFixed(3)}`);
49
- const branchStr = branch ? ` (${branch})` : "";
50
- const right = theme.fg("dim", `${ctx.model?.id || "no-model"}${branchStr}`);
51
-
52
- const pad = " ".repeat(Math.max(1, width - visibleWidth(left) - visibleWidth(right)));
53
- return [truncateToWidth(left + pad + right, width)];
54
- },
55
- };
56
- });
57
- ctx.ui.notify("Custom footer enabled", "info");
58
- } else {
59
- ctx.ui.setFooter(undefined);
60
- ctx.ui.notify("Default footer restored", "info");
61
- }
62
- },
63
- });
64
- }
@@ -1,73 +0,0 @@
1
- /**
2
- * Custom Header Extension
3
- *
4
- * Demonstrates ctx.ui.setHeader() for replacing the built-in header
5
- * (logo + keybinding hints) with a custom component showing the pi mascot.
6
- */
7
-
8
- import type { ExtensionAPI, Theme } from "@apholdings/jensen-code";
9
- import { VERSION } from "@apholdings/jensen-code";
10
-
11
- // --- PI MASCOT ---
12
- // Based on pi_mascot.ts - the pi agent character
13
- function getPiMascot(theme: Theme): string[] {
14
- // --- COLORS ---
15
- // 3b1b Blue: R=80, G=180, B=230
16
- const piBlue = (text: string) => theme.fg("accent", text);
17
- const white = (text: string) => text; // Use plain white (or theme.fg("text", text))
18
- const black = (text: string) => theme.fg("dim", text); // Use dim for contrast
19
-
20
- // --- GLYPHS ---
21
- const BLOCK = "█";
22
- const PUPIL = "▌"; // Vertical half-block for the pupil
23
-
24
- // --- CONSTRUCTION ---
25
-
26
- // 1. The Eye Unit: [White Full Block][Black Vertical Sliver]
27
- // This creates the "looking sideways" effect
28
- const eye = `${white(BLOCK)}${black(PUPIL)}`;
29
-
30
- // 2. Line 1: The Eyes
31
- // 5 spaces indent aligns them with the start of the legs
32
- const lineEyes = ` ${eye} ${eye}`;
33
-
34
- // 3. Line 2: The Wide Top Bar (The "Overhang")
35
- // 14 blocks wide for that serif-style roof
36
- const lineBar = ` ${piBlue(BLOCK.repeat(14))}`;
37
-
38
- // 4. Lines 3-6: The Legs
39
- // Indented 5 spaces relative to the very left edge
40
- // Leg width: 2 blocks | Gap: 4 blocks
41
- const lineLeg = ` ${piBlue(BLOCK.repeat(2))} ${piBlue(BLOCK.repeat(2))}`;
42
-
43
- // --- ASSEMBLY ---
44
- return ["", lineEyes, lineBar, lineLeg, lineLeg, lineLeg, lineLeg, ""];
45
- }
46
-
47
- export default function (pi: ExtensionAPI) {
48
- // Set custom header immediately on load (if UI is available)
49
- pi.on("session_start", async (_event, ctx) => {
50
- if (ctx.hasUI) {
51
- ctx.ui.setHeader((_tui, theme) => {
52
- return {
53
- render(_width: number): string[] {
54
- const mascotLines = getPiMascot(theme);
55
- // Add a subtitle with hint
56
- const subtitle = `${theme.fg("muted", " shitty coding agent")}${theme.fg("dim", ` v${VERSION}`)}`;
57
- return [...mascotLines, subtitle];
58
- },
59
- invalidate() {},
60
- };
61
- });
62
- }
63
- });
64
-
65
- // Command to restore built-in header
66
- pi.registerCommand("builtin-header", {
67
- description: "Restore built-in header with keybinding hints",
68
- handler: async (_args, ctx) => {
69
- ctx.ui.setHeader(undefined);
70
- ctx.ui.notify("Built-in header restored", "info");
71
- },
72
- });
73
- }