@ilya-lesikov/pi-pi 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 (271) hide show
  1. package/3p/pi-ask-user/index.ts +1835 -0
  2. package/3p/pi-ask-user/package.json +50 -0
  3. package/3p/pi-ask-user/single-select-layout.ts +203 -0
  4. package/3p/pi-lsp/extensions/lsp/client.ts +542 -0
  5. package/3p/pi-lsp/extensions/lsp/config.ts +135 -0
  6. package/3p/pi-lsp/extensions/lsp/effects/command.ts +42 -0
  7. package/3p/pi-lsp/extensions/lsp/effects/filesystem.ts +50 -0
  8. package/3p/pi-lsp/extensions/lsp/effects/runtime.ts +21 -0
  9. package/3p/pi-lsp/extensions/lsp/errors.ts +113 -0
  10. package/3p/pi-lsp/extensions/lsp/formatting.ts +315 -0
  11. package/3p/pi-lsp/extensions/lsp/index.ts +231 -0
  12. package/3p/pi-lsp/extensions/lsp/protocol.ts +209 -0
  13. package/3p/pi-lsp/extensions/lsp/retry.ts +39 -0
  14. package/3p/pi-lsp/extensions/lsp/tools/programs.ts +293 -0
  15. package/3p/pi-lsp/extensions/lsp/tools.ts +89 -0
  16. package/3p/pi-lsp/extensions/lsp/types.ts +243 -0
  17. package/3p/pi-lsp/package.json +54 -0
  18. package/3p/pi-plannotator/AGENTS.md +583 -0
  19. package/3p/pi-plannotator/apps/pi-extension/README.md +228 -0
  20. package/3p/pi-plannotator/apps/pi-extension/assistant-message.ts +128 -0
  21. package/3p/pi-plannotator/apps/pi-extension/config.test.ts +166 -0
  22. package/3p/pi-plannotator/apps/pi-extension/config.ts +318 -0
  23. package/3p/pi-plannotator/apps/pi-extension/current-pi-session.ts +147 -0
  24. package/3p/pi-plannotator/apps/pi-extension/index.ts +1279 -0
  25. package/3p/pi-plannotator/apps/pi-extension/package.json +56 -0
  26. package/3p/pi-plannotator/apps/pi-extension/plannotator-browser.test.ts +13 -0
  27. package/3p/pi-plannotator/apps/pi-extension/plannotator-browser.ts +616 -0
  28. package/3p/pi-plannotator/apps/pi-extension/plannotator-events.ts +342 -0
  29. package/3p/pi-plannotator/apps/pi-extension/plannotator.json +12 -0
  30. package/3p/pi-plannotator/apps/pi-extension/server/agent-jobs.ts +515 -0
  31. package/3p/pi-plannotator/apps/pi-extension/server/ai-runtime.ts +169 -0
  32. package/3p/pi-plannotator/apps/pi-extension/server/annotations.ts +85 -0
  33. package/3p/pi-plannotator/apps/pi-extension/server/external-annotations.ts +189 -0
  34. package/3p/pi-plannotator/apps/pi-extension/server/handlers.ts +210 -0
  35. package/3p/pi-plannotator/apps/pi-extension/server/helpers.ts +78 -0
  36. package/3p/pi-plannotator/apps/pi-extension/server/ide.ts +46 -0
  37. package/3p/pi-plannotator/apps/pi-extension/server/integrations.ts +195 -0
  38. package/3p/pi-plannotator/apps/pi-extension/server/network.test.ts +158 -0
  39. package/3p/pi-plannotator/apps/pi-extension/server/network.ts +268 -0
  40. package/3p/pi-plannotator/apps/pi-extension/server/pr.ts +126 -0
  41. package/3p/pi-plannotator/apps/pi-extension/server/project.ts +64 -0
  42. package/3p/pi-plannotator/apps/pi-extension/server/reference.ts +362 -0
  43. package/3p/pi-plannotator/apps/pi-extension/server/serverAnnotate.ts +199 -0
  44. package/3p/pi-plannotator/apps/pi-extension/server/serverPlan.ts +505 -0
  45. package/3p/pi-plannotator/apps/pi-extension/server/serverReview.ts +1229 -0
  46. package/3p/pi-plannotator/apps/pi-extension/server/vcs.ts +121 -0
  47. package/3p/pi-plannotator/apps/pi-extension/server.test.ts +966 -0
  48. package/3p/pi-plannotator/apps/pi-extension/server.ts +44 -0
  49. package/3p/pi-plannotator/apps/pi-extension/tool-scope.test.ts +88 -0
  50. package/3p/pi-plannotator/apps/pi-extension/tool-scope.ts +39 -0
  51. package/3p/pi-plannotator/apps/pi-extension/tsconfig.json +16 -0
  52. package/3p/pi-plannotator/apps/pi-extension/vendor.sh +48 -0
  53. package/3p/pi-plannotator/package.json +53 -0
  54. package/3p/pi-plannotator/packages/ai/ai.test.ts +1407 -0
  55. package/3p/pi-plannotator/packages/ai/base-session.ts +94 -0
  56. package/3p/pi-plannotator/packages/ai/context.ts +250 -0
  57. package/3p/pi-plannotator/packages/ai/endpoints.ts +326 -0
  58. package/3p/pi-plannotator/packages/ai/index.ts +105 -0
  59. package/3p/pi-plannotator/packages/ai/package.json +21 -0
  60. package/3p/pi-plannotator/packages/ai/provider.ts +103 -0
  61. package/3p/pi-plannotator/packages/ai/providers/claude-agent-sdk.ts +447 -0
  62. package/3p/pi-plannotator/packages/ai/providers/codex-sdk.ts +430 -0
  63. package/3p/pi-plannotator/packages/ai/providers/command-path.ts +115 -0
  64. package/3p/pi-plannotator/packages/ai/providers/opencode-sdk.ts +546 -0
  65. package/3p/pi-plannotator/packages/ai/providers/pi-events.ts +110 -0
  66. package/3p/pi-plannotator/packages/ai/providers/pi-sdk-node.ts +425 -0
  67. package/3p/pi-plannotator/packages/ai/providers/pi-sdk.ts +469 -0
  68. package/3p/pi-plannotator/packages/ai/session-manager.ts +195 -0
  69. package/3p/pi-plannotator/packages/ai/tsconfig.json +15 -0
  70. package/3p/pi-plannotator/packages/ai/types.ts +379 -0
  71. package/3p/pi-plannotator/packages/server/agent-jobs.ts +538 -0
  72. package/3p/pi-plannotator/packages/server/agent-review-message.test.ts +135 -0
  73. package/3p/pi-plannotator/packages/server/agent-review-message.ts +243 -0
  74. package/3p/pi-plannotator/packages/server/ai-runtime.ts +108 -0
  75. package/3p/pi-plannotator/packages/server/annotate.ts +401 -0
  76. package/3p/pi-plannotator/packages/server/browser.test.ts +87 -0
  77. package/3p/pi-plannotator/packages/server/browser.ts +245 -0
  78. package/3p/pi-plannotator/packages/server/claude-review.ts +352 -0
  79. package/3p/pi-plannotator/packages/server/code-nav.ts +73 -0
  80. package/3p/pi-plannotator/packages/server/codex-review-schema.json +41 -0
  81. package/3p/pi-plannotator/packages/server/codex-review.ts +330 -0
  82. package/3p/pi-plannotator/packages/server/config.ts +8 -0
  83. package/3p/pi-plannotator/packages/server/draft.ts +1 -0
  84. package/3p/pi-plannotator/packages/server/editor-annotations.ts +76 -0
  85. package/3p/pi-plannotator/packages/server/external-annotations.test.ts +18 -0
  86. package/3p/pi-plannotator/packages/server/external-annotations.ts +207 -0
  87. package/3p/pi-plannotator/packages/server/git.ts +141 -0
  88. package/3p/pi-plannotator/packages/server/goal-setup.test.ts +55 -0
  89. package/3p/pi-plannotator/packages/server/goal-setup.ts +248 -0
  90. package/3p/pi-plannotator/packages/server/ide.ts +43 -0
  91. package/3p/pi-plannotator/packages/server/image.test.ts +63 -0
  92. package/3p/pi-plannotator/packages/server/image.ts +66 -0
  93. package/3p/pi-plannotator/packages/server/index.ts +648 -0
  94. package/3p/pi-plannotator/packages/server/integrations.test.ts +172 -0
  95. package/3p/pi-plannotator/packages/server/integrations.ts +214 -0
  96. package/3p/pi-plannotator/packages/server/jj.test.ts +69 -0
  97. package/3p/pi-plannotator/packages/server/jj.ts +86 -0
  98. package/3p/pi-plannotator/packages/server/p4.ts +417 -0
  99. package/3p/pi-plannotator/packages/server/package.json +40 -0
  100. package/3p/pi-plannotator/packages/server/path-utils.ts +18 -0
  101. package/3p/pi-plannotator/packages/server/pr.ts +146 -0
  102. package/3p/pi-plannotator/packages/server/project.test.ts +115 -0
  103. package/3p/pi-plannotator/packages/server/project.ts +45 -0
  104. package/3p/pi-plannotator/packages/server/reference-handlers.ts +404 -0
  105. package/3p/pi-plannotator/packages/server/remote.test.ts +150 -0
  106. package/3p/pi-plannotator/packages/server/remote.ts +74 -0
  107. package/3p/pi-plannotator/packages/server/repo.ts +80 -0
  108. package/3p/pi-plannotator/packages/server/resolve-file.test.ts +310 -0
  109. package/3p/pi-plannotator/packages/server/review-workspace.test.ts +1032 -0
  110. package/3p/pi-plannotator/packages/server/review-workspace.ts +48 -0
  111. package/3p/pi-plannotator/packages/server/review.ts +1318 -0
  112. package/3p/pi-plannotator/packages/server/sessions.ts +111 -0
  113. package/3p/pi-plannotator/packages/server/share-url.ts +53 -0
  114. package/3p/pi-plannotator/packages/server/shared-handlers.test.ts +43 -0
  115. package/3p/pi-plannotator/packages/server/shared-handlers.ts +177 -0
  116. package/3p/pi-plannotator/packages/server/storage.test.ts +176 -0
  117. package/3p/pi-plannotator/packages/server/storage.ts +17 -0
  118. package/3p/pi-plannotator/packages/server/tour/tour-review.test.ts +146 -0
  119. package/3p/pi-plannotator/packages/server/tour/tour-review.ts +604 -0
  120. package/3p/pi-plannotator/packages/server/tsconfig.json +15 -0
  121. package/3p/pi-plannotator/packages/server/vcs.test.ts +48 -0
  122. package/3p/pi-plannotator/packages/server/vcs.ts +80 -0
  123. package/3p/pi-plannotator/packages/shared/agent-jobs.ts +132 -0
  124. package/3p/pi-plannotator/packages/shared/agents.ts +53 -0
  125. package/3p/pi-plannotator/packages/shared/annotate-args.test.ts +386 -0
  126. package/3p/pi-plannotator/packages/shared/annotate-args.ts +107 -0
  127. package/3p/pi-plannotator/packages/shared/at-reference.test.ts +99 -0
  128. package/3p/pi-plannotator/packages/shared/at-reference.ts +52 -0
  129. package/3p/pi-plannotator/packages/shared/checklist.ts +52 -0
  130. package/3p/pi-plannotator/packages/shared/code-file.test.ts +112 -0
  131. package/3p/pi-plannotator/packages/shared/code-file.ts +41 -0
  132. package/3p/pi-plannotator/packages/shared/code-nav.test.ts +515 -0
  133. package/3p/pi-plannotator/packages/shared/code-nav.ts +436 -0
  134. package/3p/pi-plannotator/packages/shared/compress.ts +51 -0
  135. package/3p/pi-plannotator/packages/shared/config.ts +262 -0
  136. package/3p/pi-plannotator/packages/shared/crypto.test.ts +172 -0
  137. package/3p/pi-plannotator/packages/shared/crypto.ts +97 -0
  138. package/3p/pi-plannotator/packages/shared/data-dir.ts +42 -0
  139. package/3p/pi-plannotator/packages/shared/diff-paths.test.ts +30 -0
  140. package/3p/pi-plannotator/packages/shared/diff-paths.ts +137 -0
  141. package/3p/pi-plannotator/packages/shared/draft.ts +64 -0
  142. package/3p/pi-plannotator/packages/shared/external-annotation.ts +397 -0
  143. package/3p/pi-plannotator/packages/shared/extract-code-paths.test.ts +59 -0
  144. package/3p/pi-plannotator/packages/shared/extract-code-paths.ts +66 -0
  145. package/3p/pi-plannotator/packages/shared/favicon.ts +5 -0
  146. package/3p/pi-plannotator/packages/shared/feedback-templates.test.ts +65 -0
  147. package/3p/pi-plannotator/packages/shared/feedback-templates.ts +29 -0
  148. package/3p/pi-plannotator/packages/shared/goal-setup.test.ts +231 -0
  149. package/3p/pi-plannotator/packages/shared/goal-setup.ts +336 -0
  150. package/3p/pi-plannotator/packages/shared/html-to-markdown.test.ts +62 -0
  151. package/3p/pi-plannotator/packages/shared/html-to-markdown.ts +32 -0
  152. package/3p/pi-plannotator/packages/shared/improvement-hooks.test.ts +135 -0
  153. package/3p/pi-plannotator/packages/shared/improvement-hooks.ts +115 -0
  154. package/3p/pi-plannotator/packages/shared/integrations-common.ts +243 -0
  155. package/3p/pi-plannotator/packages/shared/jj-core.test.ts +236 -0
  156. package/3p/pi-plannotator/packages/shared/jj-core.ts +433 -0
  157. package/3p/pi-plannotator/packages/shared/package.json +55 -0
  158. package/3p/pi-plannotator/packages/shared/pfm-reminder.test.ts +88 -0
  159. package/3p/pi-plannotator/packages/shared/pfm-reminder.ts +80 -0
  160. package/3p/pi-plannotator/packages/shared/pr-github.ts +661 -0
  161. package/3p/pi-plannotator/packages/shared/pr-gitlab.test.ts +202 -0
  162. package/3p/pi-plannotator/packages/shared/pr-gitlab.ts +620 -0
  163. package/3p/pi-plannotator/packages/shared/pr-provider.test.ts +266 -0
  164. package/3p/pi-plannotator/packages/shared/pr-provider.ts +123 -0
  165. package/3p/pi-plannotator/packages/shared/pr-stack.test.ts +104 -0
  166. package/3p/pi-plannotator/packages/shared/pr-stack.ts +194 -0
  167. package/3p/pi-plannotator/packages/shared/pr-types.ts +326 -0
  168. package/3p/pi-plannotator/packages/shared/project.ts +71 -0
  169. package/3p/pi-plannotator/packages/shared/prompts-integration.test.ts +421 -0
  170. package/3p/pi-plannotator/packages/shared/prompts.test.ts +504 -0
  171. package/3p/pi-plannotator/packages/shared/prompts.ts +247 -0
  172. package/3p/pi-plannotator/packages/shared/reference-common.ts +87 -0
  173. package/3p/pi-plannotator/packages/shared/repo.ts +71 -0
  174. package/3p/pi-plannotator/packages/shared/resolve-file.test.ts +113 -0
  175. package/3p/pi-plannotator/packages/shared/resolve-file.ts +509 -0
  176. package/3p/pi-plannotator/packages/shared/review-args.test.ts +64 -0
  177. package/3p/pi-plannotator/packages/shared/review-args.ts +85 -0
  178. package/3p/pi-plannotator/packages/shared/review-core.test.ts +286 -0
  179. package/3p/pi-plannotator/packages/shared/review-core.ts +895 -0
  180. package/3p/pi-plannotator/packages/shared/review-workspace-node.ts +230 -0
  181. package/3p/pi-plannotator/packages/shared/review-workspace.ts +436 -0
  182. package/3p/pi-plannotator/packages/shared/semantic-diff-types.ts +76 -0
  183. package/3p/pi-plannotator/packages/shared/semantic-diff.test.ts +322 -0
  184. package/3p/pi-plannotator/packages/shared/semantic-diff.ts +520 -0
  185. package/3p/pi-plannotator/packages/shared/storage.ts +378 -0
  186. package/3p/pi-plannotator/packages/shared/tour.ts +61 -0
  187. package/3p/pi-plannotator/packages/shared/tsconfig.json +15 -0
  188. package/3p/pi-plannotator/packages/shared/types.ts +29 -0
  189. package/3p/pi-plannotator/packages/shared/url-to-markdown.test.ts +177 -0
  190. package/3p/pi-plannotator/packages/shared/url-to-markdown.ts +351 -0
  191. package/3p/pi-plannotator/packages/shared/vcs-core.test.ts +332 -0
  192. package/3p/pi-plannotator/packages/shared/vcs-core.ts +482 -0
  193. package/3p/pi-plannotator/packages/shared/worktree-pool.test.ts +162 -0
  194. package/3p/pi-plannotator/packages/shared/worktree-pool.ts +103 -0
  195. package/3p/pi-plannotator/packages/shared/worktree.ts +119 -0
  196. package/3p/pi-subagents/package.json +50 -0
  197. package/3p/pi-subagents/src/agent-manager.ts +413 -0
  198. package/3p/pi-subagents/src/agent-runner.ts +502 -0
  199. package/3p/pi-subagents/src/agent-types.ts +248 -0
  200. package/3p/pi-subagents/src/context.ts +58 -0
  201. package/3p/pi-subagents/src/cross-extension-rpc.ts +135 -0
  202. package/3p/pi-subagents/src/custom-agents.ts +137 -0
  203. package/3p/pi-subagents/src/default-agents.ts +144 -0
  204. package/3p/pi-subagents/src/env.ts +33 -0
  205. package/3p/pi-subagents/src/group-join.ts +141 -0
  206. package/3p/pi-subagents/src/index.ts +1811 -0
  207. package/3p/pi-subagents/src/invocation-config.ts +40 -0
  208. package/3p/pi-subagents/src/memory.ts +165 -0
  209. package/3p/pi-subagents/src/model-resolver.ts +81 -0
  210. package/3p/pi-subagents/src/output-file.ts +77 -0
  211. package/3p/pi-subagents/src/prompts.ts +85 -0
  212. package/3p/pi-subagents/src/skill-loader.ts +79 -0
  213. package/3p/pi-subagents/src/types.ts +111 -0
  214. package/3p/pi-subagents/src/ui/agent-widget.ts +496 -0
  215. package/3p/pi-subagents/src/ui/conversation-viewer.ts +250 -0
  216. package/3p/pi-subagents/src/worktree.ts +162 -0
  217. package/3p/pi-tasks/package.json +52 -0
  218. package/3p/pi-tasks/src/auto-clear.ts +91 -0
  219. package/3p/pi-tasks/src/index.ts +1150 -0
  220. package/3p/pi-tasks/src/process-tracker.ts +140 -0
  221. package/3p/pi-tasks/src/reminder-cadence.ts +90 -0
  222. package/3p/pi-tasks/src/task-store.ts +324 -0
  223. package/3p/pi-tasks/src/tasks-config.ts +27 -0
  224. package/3p/pi-tasks/src/types.ts +40 -0
  225. package/3p/pi-tasks/src/ui/settings-menu.ts +152 -0
  226. package/3p/pi-tasks/src/ui/task-widget.ts +296 -0
  227. package/AGENTS.md +28 -0
  228. package/LICENSE +201 -0
  229. package/extensions/orchestrator/agents/brainstorm-reviewer.ts +77 -0
  230. package/extensions/orchestrator/agents/code-reviewer.ts +89 -0
  231. package/extensions/orchestrator/agents/explore.ts +33 -0
  232. package/extensions/orchestrator/agents/librarian.ts +43 -0
  233. package/extensions/orchestrator/agents/plan-reviewer.ts +75 -0
  234. package/extensions/orchestrator/agents/planner.ts +61 -0
  235. package/extensions/orchestrator/agents/registry.ts +156 -0
  236. package/extensions/orchestrator/agents/task.ts +50 -0
  237. package/extensions/orchestrator/agents/tool-routing.ts +84 -0
  238. package/extensions/orchestrator/ast-search.ts +85 -0
  239. package/extensions/orchestrator/cbm.ts +330 -0
  240. package/extensions/orchestrator/command-handlers.test.ts +163 -0
  241. package/extensions/orchestrator/command-handlers.ts +116 -0
  242. package/extensions/orchestrator/commands.test.ts +81 -0
  243. package/extensions/orchestrator/commands.ts +75 -0
  244. package/extensions/orchestrator/config.test.ts +221 -0
  245. package/extensions/orchestrator/config.ts +230 -0
  246. package/extensions/orchestrator/context.test.ts +293 -0
  247. package/extensions/orchestrator/context.ts +206 -0
  248. package/extensions/orchestrator/event-handlers.test.ts +190 -0
  249. package/extensions/orchestrator/event-handlers.ts +1416 -0
  250. package/extensions/orchestrator/exa.ts +104 -0
  251. package/extensions/orchestrator/flant-infra.ts +486 -0
  252. package/extensions/orchestrator/index.ts +80 -0
  253. package/extensions/orchestrator/integration.test.ts +1214 -0
  254. package/extensions/orchestrator/orchestrator.test.ts +252 -0
  255. package/extensions/orchestrator/orchestrator.ts +538 -0
  256. package/extensions/orchestrator/phases/brainstorm.test.ts +15 -0
  257. package/extensions/orchestrator/phases/brainstorm.ts +273 -0
  258. package/extensions/orchestrator/phases/implementation.ts +40 -0
  259. package/extensions/orchestrator/phases/machine.test.ts +293 -0
  260. package/extensions/orchestrator/phases/machine.ts +209 -0
  261. package/extensions/orchestrator/phases/planning.ts +255 -0
  262. package/extensions/orchestrator/phases/review.ts +193 -0
  263. package/extensions/orchestrator/plannotator.ts +56 -0
  264. package/extensions/orchestrator/pp-menu.ts +866 -0
  265. package/extensions/orchestrator/state.test.ts +343 -0
  266. package/extensions/orchestrator/state.ts +237 -0
  267. package/extensions/orchestrator/validate-artifacts.test.ts +88 -0
  268. package/extensions/orchestrator/validate-artifacts.ts +272 -0
  269. package/extensions/orchestrator/vendor.d.ts +26 -0
  270. package/package.json +73 -0
  271. package/scripts/postinstall.sh +18 -0
@@ -0,0 +1,81 @@
1
+ import { mkdtempSync, rmSync, writeFileSync } from "fs";
2
+ import { tmpdir } from "os";
3
+ import { join } from "path";
4
+ import { execFileSync } from "child_process";
5
+ import { afterEach, describe, expect, it } from "vitest";
6
+ import { autoCommit } from "./commands.js";
7
+
8
+ const tempDirs: string[] = [];
9
+
10
+ function makeRepo(): string {
11
+ const cwd = mkdtempSync(join(tmpdir(), "pi-pi-commands-"));
12
+ tempDirs.push(cwd);
13
+
14
+ execFileSync("git", ["init"], { cwd, stdio: "pipe" });
15
+ execFileSync("git", ["config", "user.email", "tests@example.com"], { cwd, stdio: "pipe" });
16
+ execFileSync("git", ["config", "user.name", "Pi Pi Tests"], { cwd, stdio: "pipe" });
17
+
18
+ return cwd;
19
+ }
20
+
21
+ afterEach(() => {
22
+ while (tempDirs.length > 0) {
23
+ const dir = tempDirs.pop();
24
+ if (dir) rmSync(dir, { recursive: true, force: true });
25
+ }
26
+ });
27
+
28
+ describe("autoCommit", () => {
29
+ it("falls back to checkpoint when message is empty", () => {
30
+ const cwd = makeRepo();
31
+ const file = "a.ts";
32
+ writeFileSync(join(cwd, file), "export const a = 1;\n", "utf-8");
33
+
34
+ const result = autoCommit([file], " ", cwd);
35
+
36
+ expect(result.ok).toBe(true);
37
+ const head = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf-8", stdio: "pipe" }).trim();
38
+ expect(head).toMatch(/^[a-f0-9]+$/);
39
+ const subject = execFileSync("git", ["log", "-1", "--pretty=%s"], { cwd, encoding: "utf-8", stdio: "pipe" }).trim();
40
+ expect(subject).toBe("checkpoint");
41
+ });
42
+
43
+ it("uses message as-is for commit", () => {
44
+ const cwd = makeRepo();
45
+ const file = "b.ts";
46
+ writeFileSync(join(cwd, file), "export const b = 1;\n", "utf-8");
47
+
48
+ const result = autoCommit([file], "fix: resolve auth token expiry", cwd);
49
+
50
+ expect(result.ok).toBe(true);
51
+ const subject = execFileSync("git", ["log", "-1", "--pretty=%s"], { cwd, encoding: "utf-8", stdio: "pipe" }).trim();
52
+ expect(subject).toBe("fix: resolve auth token expiry");
53
+ });
54
+
55
+ it("truncates long messages to 72 chars", () => {
56
+ const cwd = makeRepo();
57
+ const file = "c.ts";
58
+ writeFileSync(join(cwd, file), "export const c = 1;\n", "utf-8");
59
+
60
+ const longMsg = "a".repeat(100);
61
+ const result = autoCommit([file], longMsg, cwd);
62
+
63
+ expect(result.ok).toBe(true);
64
+ const subject = execFileSync("git", ["log", "-1", "--pretty=%s"], { cwd, encoding: "utf-8", stdio: "pipe" }).trim();
65
+ expect(subject).toBe("a".repeat(72));
66
+ });
67
+
68
+ it("commits files with spaces in names", () => {
69
+ const cwd = makeRepo();
70
+ const file = "file with spaces.ts";
71
+ writeFileSync(join(cwd, file), "export const spaced = true;\n", "utf-8");
72
+
73
+ const result = autoCommit([file], "spaced file", cwd);
74
+
75
+ expect(result.ok).toBe(true);
76
+ const head = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf-8", stdio: "pipe" }).trim();
77
+ expect(head).toMatch(/^[a-f0-9]+$/);
78
+ const committedFiles = execFileSync("git", ["show", "--name-only", "--pretty="], { cwd, encoding: "utf-8", stdio: "pipe" });
79
+ expect(committedFiles.split("\n")).toContain(file);
80
+ });
81
+ });
@@ -0,0 +1,75 @@
1
+ import { execSync, execFileSync } from "child_process";
2
+ import { dirname } from "path";
3
+ import { minimatch } from "minimatch";
4
+ import type { PiPiConfig, AfterEditCommand } from "./config.js";
5
+
6
+ interface CommandResult {
7
+ ok: boolean;
8
+ command: string;
9
+ output: string;
10
+ }
11
+
12
+ function shellEscape(arg: string): string {
13
+ return "'" + arg.replace(/'/g, "'\\''") + "'";
14
+ }
15
+
16
+ function substituteVars(command: string, file?: string): string {
17
+ let result = command;
18
+ if (file) {
19
+ result = result.replace(/\$\{file\}/g, shellEscape(file));
20
+ result = result.replace(/\$\{dir\}/g, shellEscape(dirname(file)));
21
+ }
22
+ return result;
23
+ }
24
+
25
+ export function runAfterEdit(file: string, config: PiPiConfig, cwd: string): CommandResult[] {
26
+ const results: CommandResult[] = [];
27
+ const timeout = config.timeouts.afterEdit;
28
+
29
+ for (const cmd of config.commands.afterEdit) {
30
+ const matches = !cmd.glob || cmd.glob.length === 0 || cmd.glob.some((g) => minimatch(file, g, { matchBase: true }));
31
+ if (!matches) continue;
32
+
33
+ const command = substituteVars(cmd.run, file);
34
+ try {
35
+ const output = execSync(command, { cwd, encoding: "utf-8", timeout, stdio: "pipe" });
36
+ results.push({ ok: true, command, output: output.trim() });
37
+ } catch (err: any) {
38
+ results.push({ ok: false, command, output: err.stderr?.toString() || err.message || "unknown error" });
39
+ }
40
+ }
41
+
42
+ return results;
43
+ }
44
+
45
+ export function runAfterImplement(config: PiPiConfig, cwd: string): CommandResult[] {
46
+ const results: CommandResult[] = [];
47
+ const timeout = config.timeouts.afterImplement;
48
+
49
+ for (const cmd of config.commands.afterImplement) {
50
+ const command = substituteVars(cmd.run);
51
+ try {
52
+ const output = execSync(command, { cwd, encoding: "utf-8", timeout, stdio: "pipe" });
53
+ results.push({ ok: true, command, output: output.trim() });
54
+ } catch (err: any) {
55
+ results.push({ ok: false, command, output: err.stderr?.toString() || err.message || "unknown error" });
56
+ }
57
+ }
58
+
59
+ return results;
60
+ }
61
+
62
+ export function autoCommit(files: string[], message: string, cwd: string): { ok: boolean; commitHash?: string; error?: string } {
63
+ if (files.length === 0) return { ok: true };
64
+
65
+ const cleanMessage = message.trim().slice(0, 72) || "checkpoint";
66
+
67
+ try {
68
+ execFileSync("git", ["add", "--", ...files], { cwd, encoding: "utf-8", stdio: "pipe" });
69
+ const output = execFileSync("git", ["commit", "-m", cleanMessage], { cwd, encoding: "utf-8", stdio: "pipe" });
70
+ const hashMatch = output.match(/\[[\w-]+ (?:\([^)]+\) )?([a-f0-9]+)\]/);
71
+ return { ok: true, commitHash: hashMatch?.[1] };
72
+ } catch (err: any) {
73
+ return { ok: false, error: err.stderr?.toString() || err.message };
74
+ }
75
+ }
@@ -0,0 +1,221 @@
1
+ import { afterEach, describe, expect, it } from "vitest";
2
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "fs";
3
+ import { join } from "path";
4
+ import { tmpdir } from "os";
5
+ import { deepMerge, loadConfig, validateConfig } from "./config.js";
6
+
7
+ const tempDirs: string[] = [];
8
+
9
+ function makeTempDir(): string {
10
+ const dir = mkdtempSync(join(tmpdir(), "pi-pi-config-test-"));
11
+ tempDirs.push(dir);
12
+ return dir;
13
+ }
14
+
15
+ afterEach(() => {
16
+ for (const dir of tempDirs.splice(0)) {
17
+ rmSync(dir, { recursive: true, force: true });
18
+ }
19
+ });
20
+
21
+ describe("deepMerge", () => {
22
+ it("merges nested objects while replacing arrays and nulls", () => {
23
+ const target = {
24
+ nested: { left: 1, keep: true },
25
+ arr: [1, 2, 3],
26
+ nullable: "value",
27
+ emptyObjectTarget: { keep: "yes" },
28
+ };
29
+
30
+ const source = {
31
+ nested: { right: 2 },
32
+ arr: [99],
33
+ nullable: null,
34
+ emptyObjectTarget: {},
35
+ };
36
+
37
+ const merged = deepMerge(target, source);
38
+
39
+ expect(merged).toEqual({
40
+ nested: { left: 1, keep: true, right: 2 },
41
+ arr: [99],
42
+ nullable: null,
43
+ emptyObjectTarget: { keep: "yes" },
44
+ });
45
+ });
46
+ });
47
+
48
+ describe("validateConfig", () => {
49
+ it("throws for empty main model string", () => {
50
+ expect(() => validateConfig({ mainModel: { implement: { model: "" } } })).toThrow(
51
+ "config.mainModel.implement.model must be non-empty",
52
+ );
53
+ });
54
+
55
+ it("throws for enabled variant without model", () => {
56
+ expect(() => validateConfig({ planners: { broken: { enabled: true, model: "" } } })).toThrow(
57
+ "config.planners.broken is enabled but has no model",
58
+ );
59
+ });
60
+
61
+ it("throws when commands.afterEdit is not an array", () => {
62
+ expect(() => validateConfig({ commands: { afterEdit: { run: "npm test" } } })).toThrow(
63
+ "config.commands.afterEdit must be an array",
64
+ );
65
+ });
66
+
67
+ it("throws when commands.afterEdit entry has no run", () => {
68
+ expect(() => validateConfig({ commands: { afterEdit: [{ glob: ["*.ts"] }] } })).toThrow(
69
+ "config.commands.afterEdit[0] must have a 'run' field",
70
+ );
71
+ });
72
+
73
+ it("throws when commands.afterImplement entry has no run", () => {
74
+ expect(() => validateConfig({ commands: { afterImplement: [{}] } })).toThrow(
75
+ "config.commands.afterImplement[0] must have a 'run' field",
76
+ );
77
+ });
78
+
79
+ it("throws for negative timeout values", () => {
80
+ expect(() => validateConfig({ timeouts: { afterEdit: -1 } })).toThrow(
81
+ "config.timeouts.afterEdit must be a non-negative number",
82
+ );
83
+ });
84
+
85
+ it("accepts valid config", () => {
86
+ expect(() =>
87
+ validateConfig({
88
+ mainModel: {
89
+ implement: { model: "provider/model-1" },
90
+ debug: { model: "provider/model-2" },
91
+ brainstorm: { model: "provider/model-3" },
92
+ },
93
+ planners: {
94
+ good: { enabled: true, model: "provider/model-4" },
95
+ disabled: { enabled: false },
96
+ },
97
+ brainstormReviewers: {
98
+ good: { enabled: true, model: "provider/model-5" },
99
+ },
100
+ commands: {
101
+ afterEdit: [{ run: "npm test", glob: ["*.ts"] }],
102
+ afterImplement: [{ run: "npm run build" }],
103
+ },
104
+ timeouts: { afterEdit: 0, afterImplement: 1 },
105
+ }),
106
+ ).not.toThrow();
107
+ });
108
+ });
109
+
110
+ describe("loadConfig", () => {
111
+ it("loads existing config.json and deep merges with defaults", () => {
112
+ const cwd = makeTempDir();
113
+ const ppDir = join(cwd, ".pp");
114
+ const configPath = join(ppDir, "config.json");
115
+
116
+ mkdirSync(ppDir, { recursive: true });
117
+ writeFileSync(
118
+ configPath,
119
+ JSON.stringify({
120
+ mainModel: {
121
+ implement: { model: "custom/implement", thinking: "low" },
122
+ },
123
+ planners: {
124
+ opus: { enabled: false },
125
+ },
126
+ commands: {
127
+ afterImplement: [{ run: "npm run lint" }],
128
+ },
129
+ timeouts: {
130
+ afterEdit: 1234,
131
+ },
132
+ autoCommit: false,
133
+ }),
134
+ "utf-8",
135
+ );
136
+
137
+ const config = loadConfig(cwd, "/nonexistent/global/config.json");
138
+
139
+ expect(config.mainModel.implement.model).toBe("custom/implement");
140
+ expect(config.mainModel.debug.model).toBe("openai/gpt-5.4");
141
+ expect(config.planners.opus.enabled).toBe(false);
142
+ expect(config.planners.opus.model).toBe("anthropic/claude-opus-4-6");
143
+ expect(config.commands.afterEdit).toEqual([]);
144
+ expect(config.commands.afterImplement).toEqual([{ run: "npm run lint" }]);
145
+ expect(config.timeouts.afterEdit).toBe(1234);
146
+ expect(config.timeouts.afterImplement).toBe(300000);
147
+ expect(config.autoCommit).toBe(false);
148
+ });
149
+
150
+ it("creates default config when config.json does not exist", () => {
151
+ const cwd = makeTempDir();
152
+ const configPath = join(cwd, ".pp", "config.json");
153
+
154
+ const config = loadConfig(cwd, "/nonexistent/global/config.json");
155
+
156
+ expect(existsSync(configPath)).toBe(true);
157
+ const written = JSON.parse(readFileSync(configPath, "utf-8"));
158
+ expect(written.mainModel.implement.model).toBe("anthropic/claude-opus-4-6");
159
+ expect(config.mainModel.implement.model).toBe("anthropic/claude-opus-4-6");
160
+ });
161
+
162
+ it("throws parse errors with config file path", () => {
163
+ const cwd = makeTempDir();
164
+ const ppDir = join(cwd, ".pp");
165
+ const configPath = join(ppDir, "config.json");
166
+
167
+ mkdirSync(ppDir, { recursive: true });
168
+ writeFileSync(configPath, "{broken", "utf-8");
169
+
170
+ expect(() => loadConfig(cwd, "/nonexistent/global/config.json")).toThrow(`Failed to parse ${configPath}`);
171
+ });
172
+
173
+ it("propagates validation errors", () => {
174
+ const cwd = makeTempDir();
175
+ const ppDir = join(cwd, ".pp");
176
+ const configPath = join(ppDir, "config.json");
177
+
178
+ mkdirSync(ppDir, { recursive: true });
179
+ writeFileSync(configPath, JSON.stringify({ timeouts: { afterEdit: -1 } }), "utf-8");
180
+
181
+ expect(() => loadConfig(cwd, "/nonexistent/global/config.json")).toThrow("config.timeouts.afterEdit must be a non-negative number");
182
+ });
183
+ });
184
+
185
+ describe("config regressions", () => {
186
+ it("skips dangerous keys during deep merge", () => {
187
+ deepMerge({}, { __proto__: { polluted: true } } as Record<string, any>);
188
+ deepMerge({}, { constructor: { pollutedByConstructor: true }, prototype: { pollutedByPrototype: true } });
189
+
190
+ const plainObject: Record<string, unknown> = {};
191
+ expect((plainObject as any).polluted).toBeUndefined();
192
+ expect((plainObject as any).pollutedByConstructor).toBeUndefined();
193
+ expect((plainObject as any).pollutedByPrototype).toBeUndefined();
194
+ });
195
+
196
+ it("deep copies arrays during merge", () => {
197
+ const target = {};
198
+ const source = { items: [{ a: 1 }] };
199
+
200
+ const merged = deepMerge(target, source);
201
+ source.items[0].a = 999;
202
+
203
+ expect(merged.items[0].a).toBe(1);
204
+ });
205
+
206
+ it("rejects empty agents model and accepts valid agents config", () => {
207
+ expect(() => validateConfig({ agents: { explore: { model: "", thinking: "low" } } })).toThrow(
208
+ "config.agents.explore.model must be a non-empty string",
209
+ );
210
+
211
+ expect(() =>
212
+ validateConfig({
213
+ agents: {
214
+ explore: { model: "google/gemini-3.1-flash", thinking: "low" },
215
+ librarian: { model: "google/gemini-3.1-flash", thinking: "medium" },
216
+ task: { model: "anthropic/claude-opus-4-6", thinking: "medium" },
217
+ },
218
+ }),
219
+ ).not.toThrow();
220
+ });
221
+ });
@@ -0,0 +1,230 @@
1
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
2
+ import { join } from "path";
3
+
4
+ import { getAgentDir } from "@earendil-works/pi-coding-agent";
5
+
6
+ export interface ModelConfig {
7
+ model: string;
8
+ thinking: string;
9
+ maxTurns?: number;
10
+ }
11
+
12
+ export interface VariantConfig extends ModelConfig {
13
+ enabled: boolean;
14
+ }
15
+
16
+ export interface AfterEditCommand {
17
+ run: string;
18
+ glob: string[];
19
+ }
20
+
21
+ export interface AfterImplementCommand {
22
+ run: string;
23
+ }
24
+
25
+ export interface TimeoutConfig {
26
+ afterEdit: number;
27
+ afterImplement: number;
28
+ agentSpawn: number;
29
+ agentReadyPing: number;
30
+ agentStale: number;
31
+ lockStale: number;
32
+ lockUpdate: number;
33
+ }
34
+
35
+ export interface PiPiConfig {
36
+ mainModel: {
37
+ implement: ModelConfig;
38
+ debug: ModelConfig;
39
+ brainstorm: ModelConfig;
40
+ };
41
+ planners: Record<string, VariantConfig>;
42
+ planReviewers: Record<string, VariantConfig>;
43
+ codeReviewers: Record<string, VariantConfig>;
44
+ brainstormReviewers: Record<string, VariantConfig>;
45
+ agents: {
46
+ explore: ModelConfig;
47
+ librarian: ModelConfig;
48
+ task: ModelConfig;
49
+ };
50
+ commands: {
51
+ afterEdit: AfterEditCommand[];
52
+ afterImplement: AfterImplementCommand[];
53
+ };
54
+ timeouts: TimeoutConfig;
55
+ autoCommit: boolean;
56
+ diffBaseBranch?: string;
57
+ }
58
+
59
+ const DEFAULT_CONFIG: PiPiConfig = {
60
+ mainModel: {
61
+ implement: { model: "anthropic/claude-opus-4-6", thinking: "high" },
62
+ debug: { model: "openai/gpt-5.4", thinking: "high" },
63
+ brainstorm: { model: "anthropic/claude-opus-4-6", thinking: "high" },
64
+ },
65
+ planners: {
66
+ opus: { enabled: true, model: "anthropic/claude-opus-4-6", thinking: "high" },
67
+ gpt: { enabled: true, model: "openai/gpt-5.4", thinking: "high" },
68
+ gemini: { enabled: true, model: "google/gemini-3.1-pro", thinking: "high" },
69
+ },
70
+ planReviewers: {
71
+ opus: { enabled: true, model: "anthropic/claude-opus-4-6", thinking: "high" },
72
+ gpt: { enabled: true, model: "openai/gpt-5.4", thinking: "high" },
73
+ gemini: { enabled: true, model: "google/gemini-3.1-pro", thinking: "xhigh" },
74
+ },
75
+ codeReviewers: {
76
+ opus: { enabled: true, model: "anthropic/claude-opus-4-6", thinking: "high" },
77
+ gpt: { enabled: true, model: "openai/gpt-5.4", thinking: "high" },
78
+ gemini: { enabled: true, model: "google/gemini-3.1-pro", thinking: "xhigh" },
79
+ },
80
+ brainstormReviewers: {
81
+ opus: { enabled: true, model: "anthropic/claude-opus-4-6", thinking: "high" },
82
+ gpt: { enabled: true, model: "openai/gpt-5.4", thinking: "high" },
83
+ gemini: { enabled: true, model: "google/gemini-3.1-pro", thinking: "xhigh" },
84
+ },
85
+ agents: {
86
+ explore: { model: "google/gemini-3.1-flash", thinking: "low" },
87
+ librarian: { model: "google/gemini-3.1-flash", thinking: "medium" },
88
+ task: { model: "anthropic/claude-opus-4-6", thinking: "medium" },
89
+ },
90
+ commands: {
91
+ afterEdit: [],
92
+ afterImplement: [],
93
+ },
94
+ timeouts: {
95
+ afterEdit: 30000,
96
+ afterImplement: 300000,
97
+ agentSpawn: 30000,
98
+ agentReadyPing: 5000,
99
+ agentStale: 300000,
100
+ lockStale: 60000,
101
+ lockUpdate: 30000,
102
+ },
103
+ autoCommit: true,
104
+ };
105
+
106
+ const DANGEROUS_KEYS = new Set(["__proto__", "constructor", "prototype"]);
107
+
108
+ export function deepMerge(target: Record<string, any>, source: Record<string, any>): Record<string, any> {
109
+ const result = { ...target };
110
+ for (const key of Object.keys(source)) {
111
+ if (DANGEROUS_KEYS.has(key)) continue;
112
+ if (
113
+ source[key] !== null &&
114
+ typeof source[key] === "object" &&
115
+ !Array.isArray(source[key]) &&
116
+ typeof target[key] === "object" &&
117
+ !Array.isArray(target[key])
118
+ ) {
119
+ result[key] = deepMerge(target[key], source[key]);
120
+ } else if (Array.isArray(source[key])) {
121
+ result[key] = structuredClone(source[key]);
122
+ } else {
123
+ result[key] = source[key];
124
+ }
125
+ }
126
+ return result;
127
+ }
128
+
129
+ export function validateConfig(config: Record<string, any>): void {
130
+ if (config.mainModel) {
131
+ for (const key of ["implement", "debug", "brainstorm"]) {
132
+ const mc = config.mainModel[key];
133
+ if (mc && typeof mc.model === "string" && mc.model.length === 0) {
134
+ throw new Error(`config.mainModel.${key}.model must be non-empty`);
135
+ }
136
+ }
137
+ }
138
+
139
+ for (const group of ["planners", "planReviewers", "codeReviewers", "brainstormReviewers"]) {
140
+ const variants = config[group];
141
+ if (!variants || typeof variants !== "object") continue;
142
+ for (const [name, v] of Object.entries(variants)) {
143
+ const variant = v as Record<string, any>;
144
+ if (variant.enabled && (!variant.model || typeof variant.model !== "string" || variant.model.length === 0)) {
145
+ throw new Error(`config.${group}.${name} is enabled but has no model`);
146
+ }
147
+ }
148
+ }
149
+
150
+ if (config.commands?.afterEdit) {
151
+ if (!Array.isArray(config.commands.afterEdit)) {
152
+ throw new Error("config.commands.afterEdit must be an array");
153
+ }
154
+ for (const [i, cmd] of config.commands.afterEdit.entries()) {
155
+ if (!cmd.run || typeof cmd.run !== "string") {
156
+ throw new Error(`config.commands.afterEdit[${i}] must have a 'run' field`);
157
+ }
158
+ }
159
+ }
160
+
161
+ if (config.commands?.afterImplement) {
162
+ if (!Array.isArray(config.commands.afterImplement)) {
163
+ throw new Error("config.commands.afterImplement must be an array");
164
+ }
165
+ for (const [i, cmd] of config.commands.afterImplement.entries()) {
166
+ if (!cmd.run || typeof cmd.run !== "string") {
167
+ throw new Error(`config.commands.afterImplement[${i}] must have a 'run' field`);
168
+ }
169
+ }
170
+ }
171
+
172
+ if (config.timeouts) {
173
+ for (const [key, val] of Object.entries(config.timeouts)) {
174
+ if (typeof val !== "number" || val < 0) {
175
+ throw new Error(`config.timeouts.${key} must be a non-negative number`);
176
+ }
177
+ }
178
+ }
179
+
180
+ if (config.agents) {
181
+ for (const [name, agent] of Object.entries(config.agents)) {
182
+ const a = agent as Record<string, any>;
183
+ if (a.model !== undefined && (typeof a.model !== "string" || a.model.length === 0)) {
184
+ throw new Error(`config.agents.${name}.model must be a non-empty string`);
185
+ }
186
+ }
187
+ }
188
+ }
189
+
190
+ function loadJsonFile(path: string): Record<string, any> | null {
191
+ if (!existsSync(path)) return null;
192
+ const raw = readFileSync(path, "utf-8");
193
+ try {
194
+ return JSON.parse(raw);
195
+ } catch (err: any) {
196
+ throw new Error(`Failed to parse ${path}: ${err.message}`);
197
+ }
198
+ }
199
+
200
+ export const GLOBAL_CONFIG_PATH = join(getAgentDir(), "extensions", "pp", "config.json");
201
+ export function loadConfig(cwd: string, globalConfigPath = GLOBAL_CONFIG_PATH): PiPiConfig {
202
+ const ppDir = join(cwd, ".pp");
203
+ const projectConfigPath = join(ppDir, "config.json");
204
+
205
+ if (!existsSync(ppDir)) {
206
+ mkdirSync(ppDir, { recursive: true });
207
+ }
208
+
209
+ const globalConfig = loadJsonFile(globalConfigPath);
210
+ const projectConfig = loadJsonFile(projectConfigPath);
211
+
212
+ let merged = { ...DEFAULT_CONFIG } as Record<string, any>;
213
+
214
+ const getFlantConfig = (globalThis as any)[Symbol.for("pi-pi:flant-config")] as (() => Partial<PiPiConfig> | null) | undefined;
215
+ const flantConfig = getFlantConfig?.();
216
+ if (flantConfig) {
217
+ merged = deepMerge(merged, flantConfig as Record<string, any>);
218
+ }
219
+
220
+ if (globalConfig) {
221
+ validateConfig(globalConfig);
222
+ merged = deepMerge(merged, globalConfig);
223
+ }
224
+ if (projectConfig) {
225
+ validateConfig(projectConfig);
226
+ merged = deepMerge(merged, projectConfig);
227
+ }
228
+
229
+ return merged as unknown as PiPiConfig;
230
+ }