@pi-chamber/web 0.4.0 → 0.5.1

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 (87) hide show
  1. package/dist/assets/{CommitSection-0zl1puqf.js → CommitSection-MZJqMxUT.js} +1 -1
  2. package/dist/assets/DiagramEditor-DmDE7OFs.js +1 -0
  3. package/dist/assets/DiagramView-DjMwKAR1.js +1 -0
  4. package/dist/assets/{DiffView-BoTz2Zqe.js → DiffView-C3F9al7D.js} +2 -2
  5. package/dist/assets/{FilesView-CVMNE9Pr.js → FilesView-DzboGeAe.js} +6 -6
  6. package/dist/assets/{GitView-DnsbCAWl.js → GitView-BfyNIPaR.js} +4 -4
  7. package/dist/assets/{JsonTreeView-Cn1Mk0Wf.js → JsonTreeView-CGH92Uqo.js} +1 -1
  8. package/dist/assets/{MarkdownRendererImpl-DJKD8tNq.js → MarkdownRendererImpl-DAV0eoSb.js} +2 -2
  9. package/dist/assets/{PatchDiff-GdGq3IlM.js → PatchDiff-Dux9rNuF.js} +1 -1
  10. package/dist/assets/{PierreDiffViewer-CdkAUt-S.js → PierreDiffViewer-9imQKDgh.js} +2 -2
  11. package/dist/assets/{SessionSwitcherContent-BTzVmIop.js → SessionSwitcherContent-BL7f43TK.js} +1 -1
  12. package/dist/assets/SessionSwitcherDropdown-D86K7VFR.js +2 -0
  13. package/dist/assets/SessionUnreadDot-BfH_vRW9.js +1 -0
  14. package/dist/assets/SettingsView-CRYyy2nz.js +4 -0
  15. package/dist/assets/SettingsWindow-CAMrbwzB.js +1 -0
  16. package/dist/assets/{ToolOutputDialog-BHaf293m.js → ToolOutputDialog-D6AeevDV.js} +6 -6
  17. package/dist/assets/{ToolPartDiffPreview-BTMXNcqG.js → ToolPartDiffPreview-Bkjc2WKO.js} +2 -2
  18. package/dist/assets/{VirtualizedFileDiff-CRVvv23V.js → VirtualizedFileDiff-B2HHw9NH.js} +4 -4
  19. package/dist/assets/{WindowsWindowControls-CTtxXnD1.js → WindowsWindowControls-D1V7M-q1.js} +131 -126
  20. package/dist/assets/collapsible-IV1T6v7c.js +1 -0
  21. package/dist/assets/{computeVirtualFileMetrics-D1I8YrPV.js → computeVirtualFileMetrics-BxQbLxY-.js} +1 -1
  22. package/dist/assets/contextFileOpenGuard-xvnEr8Go.js +1 -0
  23. package/dist/assets/index--5Zr-fSk.js +8 -0
  24. package/dist/assets/index--zDkVFU6.css +1 -0
  25. package/dist/assets/{index-DbghctxK.js → index-Jd0py_uf.js} +1 -1
  26. package/dist/assets/{isDiffPlainText-BK9bF1l5.js → isDiffPlainText-BEflvkV4.js} +1 -1
  27. package/dist/assets/{isFilePlainText-Cua0RCRz.js → isFilePlainText-Byt9dFxj.js} +1 -1
  28. package/dist/assets/{main-CoA--JT-.js → main-DLedH1mh.js} +7 -7
  29. package/dist/assets/main-DOqxJvVh.js +2 -0
  30. package/dist/assets/markdownCore-U_gf0I8i.js +3 -0
  31. package/dist/assets/miniChat-BkwDDO9w.js +2 -0
  32. package/dist/assets/mobile-BrrYaFh4.js +2 -0
  33. package/dist/assets/renderElectronMiniChatApp-IM1L48Ek.js +2 -0
  34. package/dist/assets/renderMobileApp-ChddJ_wj.js +14 -0
  35. package/dist/assets/{runtimeSurface-UriLeO95.js → runtimeSurface-D3p7a-uO.js} +1 -1
  36. package/dist/assets/{useInlineCommentController-5XANmO1k.js → useInlineCommentController-BASCWgsn.js} +2 -2
  37. package/dist/assets/usePanelSlide-UOz-oH7E.js +56 -0
  38. package/dist/assets/usePushVisibilityBeacon-DAaVsdjo.js +10 -0
  39. package/dist/assets/{useSwitcherItems-Cc6Tx-LO.js → useSwitcherItems-CAx_SuxF.js} +1 -1
  40. package/dist/assets/{vendor-codemirror-language-data-DxpwplIe.js → vendor-codemirror-language-data-UQYGQ5y2.js} +2 -2
  41. package/dist/assets/{web-components-g7DKkne_.js → web-components-D08z3xzy.js} +4 -4
  42. package/dist/index.html +7 -4
  43. package/dist/mini-chat.html +6 -3
  44. package/dist/mobile.html +6 -3
  45. package/package.json +1 -1
  46. package/server/lib/git/DOCUMENTATION.md +2 -2
  47. package/server/lib/git/issue-2746-longpaths.test.js +11 -11
  48. package/server/lib/git/service.js +16 -53
  49. package/server/lib/git/service.test.js +40 -40
  50. package/server/lib/pi/extension-protocol.js +62 -0
  51. package/server/lib/pi/extension-protocol.test.js +34 -0
  52. package/server/lib/pi/fixtures/pichamber-gui-demo.ts +251 -0
  53. package/server/lib/pi/routes-extension-events.test.js +152 -0
  54. package/server/lib/pi/routes.js +278 -5
  55. package/server/lib/pi/routes.test.js +0 -25
  56. package/server/lib/pi/session-daemon/DOCUMENTATION.md +6 -3
  57. package/server/lib/pi/session-daemon/extension-bridge.js +488 -0
  58. package/server/lib/pi/session-daemon/session-daemon-extensions.e2e.test.js +215 -0
  59. package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +559 -0
  60. package/server/lib/pi/session-daemon/session-daemon.js +304 -34
  61. package/server/lib/pi/session-daemon/session-daemon.test.js +89 -1
  62. package/server/lib/pi/small-model-generation.js +14 -1
  63. package/server/lib/pi/small-model-generation.test.js +20 -5
  64. package/server/lib/server/cors.js +0 -2
  65. package/server/lib/server/cors.test.js +4 -4
  66. package/server/lib/stt/providers/openai-compatible-provider.test.js +1 -1
  67. package/server/lib/workspace/host.js +1 -1
  68. package/dist/assets/DiagramEditor-CFV_TjE2.js +0 -1
  69. package/dist/assets/DiagramView-0I4PZUpw.js +0 -1
  70. package/dist/assets/SessionSwitcherDropdown-DuPmnk3k.js +0 -2
  71. package/dist/assets/SessionUnreadDot-ogHL0INY.js +0 -1
  72. package/dist/assets/SettingsView-SHhVrRdh.js +0 -4
  73. package/dist/assets/SettingsWindow-D_D1qqLF.js +0 -1
  74. package/dist/assets/collapsible-BO4qEdib.js +0 -1
  75. package/dist/assets/contextFileOpenGuard-w5xG9Qz2.js +0 -1
  76. package/dist/assets/index-3zee2IYy.css +0 -1
  77. package/dist/assets/index-CI-cd-mw.js +0 -8
  78. package/dist/assets/main-BNJQ6mSF.js +0 -2
  79. package/dist/assets/markdownCore-BGlLZrb8.js +0 -3
  80. package/dist/assets/miniChat-DU2jFhXq.js +0 -2
  81. package/dist/assets/mobile-B3lJ_CJR.js +0 -2
  82. package/dist/assets/renderElectronMiniChatApp-BfXYv3zl.js +0 -2
  83. package/dist/assets/renderMobileApp-Cd_F7yMe.js +0 -14
  84. package/dist/assets/usePanelSlide-CBZw2Cjo.js +0 -56
  85. package/dist/assets/useWindowTitle-Bf8ZNN_R.js +0 -10
  86. package/server/lib/pi/legacy-ui-model-defaults.js +0 -57
  87. package/server/lib/pi/legacy-ui-model-defaults.test.js +0 -65
@@ -139,7 +139,7 @@ Authenticated `GET /api/git/worktrees`, `POST /api/git/worktrees/validate`, `POS
139
139
  - `path`: Absolute path to worktree directory.
140
140
  - `directoryCreated`: Present when create returned after the target directory exists while background Git/bootstrap work continues.
141
141
  - `bootstrapStatus`: Background setup state. The legacy `status` remains `pending`, `ready`, or `failed`, while `phase` reports `directory-created`, `git-ready`, or `setup-ready`. Fast create starts at `pending`/`directory-created`; population and upstream Git completion advances to `pending`/`git-ready` before setup/start scripts; completed setup is `ready`/`setup-ready`. A failed setup command becomes `failed` at `git-ready`, so clients do not create a session in a checkout whose required setup failed. A missing in-memory state falls back to `ready`/`setup-ready`; clients continue to accept legacy status responses that omit `phase`.
142
- - Fast-create background failures remove OpenCode sandbox metadata for directories that never became Git worktrees, and remove the pre-created directory only if it is still empty. User-created files are never recursively deleted by this cleanup.
142
+ - Fast-create background failures remove the pre-created directory only if it is still empty. User-created files are never recursively deleted by this cleanup.
143
143
  - Worktree removal waits for any active create/bootstrap task for that directory before deleting it, preventing a background Git or setup task from restoring removed state or racing filesystem cleanup.
144
144
  - Worktree bootstrap retries transient `index.lock` conflicts. If the lock remains byte-for-byte and metadata-identical across the retry window, it is treated as stale, removed, and population continues automatically; changing locks are left untouched and reported as failures.
145
145
  - Worktree population enables Git `core.longpaths` (local repo config plus `-c core.longpaths=true` on `git reset --hard`) so deeply nested checkouts under the managed data-dir worktree root do not fail on Windows MAX_PATH with "Filename too long". Path-component limits that the filesystem itself rejects still fail bootstrap, with a clearer path-length guidance message.
@@ -172,7 +172,7 @@ Authenticated `GET /api/git/worktrees`, `POST /api/git/worktrees/validate`, `POS
172
172
 
173
173
  ### Worktree Naming
174
174
  - Worktree names are slugified via `slugWorktreeName`.
175
- - Random names use adjectives/nouns from `OPENCODE_ADJECTIVES` and `OPENCODE_NOUNS` lists.
175
+ - Random names use adjectives/nouns from `PICHAMBER_ADJECTIVES` and `PICHAMBER_NOUNS` lists.
176
176
  - Branches created for new worktrees use `pichamber/<worktree-name>` pattern.
177
177
 
178
178
  ### Cross-Platform Considerations
@@ -17,7 +17,7 @@ import {
17
17
  // "[Bug] new worktree, Filename too long"
18
18
  //
19
19
  // PiChamber places worktrees under:
20
- // <XDG_DATA_HOME>/opencode/worktree/<40-char root commit hash>/<worktree name>
20
+ // <PICHAMBER_DATA_DIR>/worktree/<40-char root commit hash>/<worktree name>
21
21
  // and populates them with `git reset --hard`. On Windows, that deep prefix plus
22
22
  // a deeply nested repo file (e.g. yudao ~173 chars) exceeds MAX_PATH (260) and
23
23
  // git aborts with "Filename too long" unless `core.longpaths` is enabled.
@@ -58,9 +58,9 @@ describe('issue #2746 - worktree long path support', () => {
58
58
  it('enables core.longpaths and populates a deeply nested worktree checkout', async () => {
59
59
  if (!canRunGit()) return;
60
60
 
61
- const previousXdgDataHome = process.env.XDG_DATA_HOME;
61
+ const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
62
62
  const dataHome = createTempDir();
63
- process.env.XDG_DATA_HOME = dataHome;
63
+ process.env.PICHAMBER_DATA_DIR = dataHome;
64
64
 
65
65
  try {
66
66
  const repo = createTempDir();
@@ -109,10 +109,10 @@ describe('issue #2746 - worktree long path support', () => {
109
109
  expect(fs.existsSync(path.join(created.path, deepRelative))).toBe(true);
110
110
  expect(fs.existsSync(path.join(created.path, 'README.md'))).toBe(true);
111
111
  } finally {
112
- if (previousXdgDataHome === undefined) {
113
- delete process.env.XDG_DATA_HOME;
112
+ if (previousPiChamberDataDir === undefined) {
113
+ delete process.env.PICHAMBER_DATA_DIR;
114
114
  } else {
115
- process.env.XDG_DATA_HOME = previousXdgDataHome;
115
+ process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
116
116
  }
117
117
  }
118
118
  });
@@ -136,9 +136,9 @@ describe('issue #2746 - worktree long path support', () => {
136
136
  it('surfaces guided bootstrap failure when a path component exceeds the filesystem name limit', async () => {
137
137
  if (!canRunGit()) return;
138
138
 
139
- const previousXdgDataHome = process.env.XDG_DATA_HOME;
139
+ const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
140
140
  const dataHome = createTempDir();
141
- process.env.XDG_DATA_HOME = dataHome;
141
+ process.env.PICHAMBER_DATA_DIR = dataHome;
142
142
 
143
143
  try {
144
144
  const repo = createTempDir();
@@ -176,10 +176,10 @@ describe('issue #2746 - worktree long path support', () => {
176
176
  expect(status?.error).toMatch(/path-length limit/i);
177
177
  expect(runGit(created.path, ['config', '--get', 'core.longpaths']).trim()).toBe('true');
178
178
  } finally {
179
- if (previousXdgDataHome === undefined) {
180
- delete process.env.XDG_DATA_HOME;
179
+ if (previousPiChamberDataDir === undefined) {
180
+ delete process.env.PICHAMBER_DATA_DIR;
181
181
  } else {
182
- process.env.XDG_DATA_HOME = previousXdgDataHome;
182
+ process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
183
183
  }
184
184
  }
185
185
  });
@@ -554,7 +554,7 @@ const cleanBranchName = (branch) => {
554
554
  return branch;
555
555
  };
556
556
 
557
- const OPENCODE_ADJECTIVES = [
557
+ const PICHAMBER_ADJECTIVES = [
558
558
  'brave',
559
559
  'calm',
560
560
  'clever',
@@ -586,7 +586,7 @@ const OPENCODE_ADJECTIVES = [
586
586
  'witty',
587
587
  ];
588
588
 
589
- const OPENCODE_NOUNS = [
589
+ const PICHAMBER_NOUNS = [
590
590
  'cabin',
591
591
  'cactus',
592
592
  'canyon',
@@ -620,16 +620,11 @@ const OPENCODE_NOUNS = [
620
620
  'wolf',
621
621
  ];
622
622
 
623
- const OPENCODE_WORKTREE_ATTEMPTS = 26;
624
-
625
- const getOpenCodeDataPath = () => {
626
- const xdgDataHome = process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local', 'share');
627
- return path.join(xdgDataHome, 'opencode');
628
- };
623
+ const PICHAMBER_WORKTREE_ATTEMPTS = 26;
629
624
 
630
625
  const pickRandom = (values) => values[Math.floor(Math.random() * values.length)];
631
626
 
632
- const generateOpenCodeRandomName = () => `${pickRandom(OPENCODE_ADJECTIVES)}-${pickRandom(OPENCODE_NOUNS)}`;
627
+ const generatePiChamberRandomName = () => `${pickRandom(PICHAMBER_ADJECTIVES)}-${pickRandom(PICHAMBER_NOUNS)}`;
633
628
 
634
629
  const slugWorktreeName = (value) => {
635
630
  return String(value || '')
@@ -1003,8 +998,8 @@ const getFileIdentity = async (filePath) => {
1003
998
  }
1004
999
  };
1005
1000
 
1006
- // PiChamber places managed worktrees under a deep data-dir path
1007
- // (`<XDG_DATA_HOME>/opencode/worktree/<40-char project id>/<name>/`). On
1001
+ // PiChamber places managed worktrees under its application data path
1002
+ // (`<PICHAMBER_DATA_DIR>/worktree/<40-char project id>/<name>/`). On
1008
1003
  // Windows that prefix plus a deeply nested repo file routinely exceeds
1009
1004
  // MAX_PATH (260). Git can check those paths out when core.longpaths is
1010
1005
  // enabled; without it, `git reset --hard` during bootstrap fails with
@@ -1537,9 +1532,9 @@ export async function continueIntegrate(stateInput = {}) {
1537
1532
  return { kind: 'success', moved: state.remainingCommits.length };
1538
1533
  }
1539
1534
 
1540
- const ensureOpenCodeProjectId = async (primaryWorktree) => {
1535
+ const ensurePiChamberProjectId = async (primaryWorktree) => {
1541
1536
  const gitDir = path.join(primaryWorktree, '.git');
1542
- const idFile = path.join(gitDir, 'opencode');
1537
+ const idFile = path.join(gitDir, 'pichamber');
1543
1538
  const existing = await fsp.readFile(idFile, 'utf8').then((value) => value.trim()).catch(() => '');
1544
1539
  if (existing) {
1545
1540
  return existing;
@@ -1559,7 +1554,7 @@ const ensureOpenCodeProjectId = async (primaryWorktree) => {
1559
1554
 
1560
1555
  const projectId = roots[0] || '';
1561
1556
  if (!projectId) {
1562
- throw new Error('Failed to derive OpenCode project ID');
1557
+ throw new Error('Failed to derive PiChamber project ID');
1563
1558
  }
1564
1559
 
1565
1560
  await fsp.mkdir(gitDir, { recursive: true }).catch(() => undefined);
@@ -1588,11 +1583,10 @@ const resolveWorktreeProjectContext = async (directory) => {
1588
1583
  );
1589
1584
  const commonDir = path.resolve(sandbox, commonResult.stdout.trim());
1590
1585
  const primaryWorktree = path.dirname(commonDir);
1591
- const projectID = await ensureOpenCodeProjectId(primaryWorktree);
1592
- const worktreeRoot = path.join(getOpenCodeDataPath(), 'worktree', projectID);
1586
+ const projectID = await ensurePiChamberProjectId(primaryWorktree);
1587
+ const worktreeRoot = resolvePiChamberDataPath(['worktree', projectID]);
1593
1588
 
1594
1589
  return {
1595
- projectID,
1596
1590
  sandbox,
1597
1591
  primaryWorktree,
1598
1592
  worktreeRoot,
@@ -1611,13 +1605,13 @@ const listWorktreeEntries = async (directory) => {
1611
1605
  const resolveWorktreeNameCandidates = (baseName) => {
1612
1606
  const normalizedBase = slugWorktreeName(baseName || '');
1613
1607
  if (!normalizedBase) {
1614
- return Array.from({ length: OPENCODE_WORKTREE_ATTEMPTS }, () => generateOpenCodeRandomName());
1608
+ return Array.from({ length: PICHAMBER_WORKTREE_ATTEMPTS }, () => generatePiChamberRandomName());
1615
1609
  }
1616
- return Array.from({ length: OPENCODE_WORKTREE_ATTEMPTS }, (_, index) => {
1610
+ return Array.from({ length: PICHAMBER_WORKTREE_ATTEMPTS }, (_, index) => {
1617
1611
  if (index === 0) {
1618
1612
  return normalizedBase;
1619
1613
  }
1620
- return `${normalizedBase}-${generateOpenCodeRandomName()}`;
1614
+ return `${normalizedBase}-${generatePiChamberRandomName()}`;
1621
1615
  });
1622
1616
  };
1623
1617
 
@@ -1740,26 +1734,6 @@ const runWorktreeStartCommand = async (directory, command) => {
1740
1734
  return result;
1741
1735
  };
1742
1736
 
1743
- const loadProjectStartCommand = async (projectID) => {
1744
- const storagePath = path.join(getOpenCodeDataPath(), 'storage', 'project', `${projectID}.json`);
1745
- try {
1746
- const raw = await fsp.readFile(storagePath, 'utf8');
1747
- const parsed = JSON.parse(raw);
1748
- const start = typeof parsed?.commands?.start === 'string' ? parsed.commands.start.trim() : '';
1749
- return start || '';
1750
- } catch {
1751
- return '';
1752
- }
1753
- };
1754
-
1755
- // OpenCode owns its own project/sandbox registry. It records a worktree as a
1756
- // sandbox itself when an instance boots for that directory, and filters entries
1757
- // whose directory no longer exists when reading them back. PiChamber used to
1758
- // write that state directly into OpenCode's storage JSON and SQLite database,
1759
- // behind the back of the running process: the row changed but the server was
1760
- // never told, so a worktree created while OpenCode was running stayed unknown
1761
- // to it until a restart. Registration is not ours to perform.
1762
-
1763
1737
  const isAttachedGitWorktreeDirectory = async (directory) => {
1764
1738
  try {
1765
1739
  const result = await runGitCommand(directory, ['rev-parse', '--is-inside-work-tree']);
@@ -1791,16 +1765,7 @@ const cleanupFailedFastWorktreeCreate = async (context, candidate) => {
1791
1765
  }
1792
1766
  };
1793
1767
 
1794
- const runWorktreeStartScripts = async (directory, projectID, startCommand) => {
1795
- const projectStart = await loadProjectStartCommand(projectID);
1796
- if (projectStart) {
1797
- const projectResult = await runWorktreeStartCommand(directory, projectStart);
1798
- if (!projectResult.success) {
1799
- console.warn('Worktree project start command failed:', projectResult.message || projectResult.stderr || projectResult.stdout);
1800
- throw new Error('Project setup command failed');
1801
- }
1802
- }
1803
-
1768
+ const runWorktreeStartScripts = async (directory, startCommand) => {
1804
1769
  const extraCommand = String(startCommand || '').trim();
1805
1770
  if (!extraCommand) {
1806
1771
  return;
@@ -1815,7 +1780,6 @@ const runWorktreeStartScripts = async (directory, projectID, startCommand) => {
1815
1780
  const queueWorktreeBootstrap = (args) => {
1816
1781
  const {
1817
1782
  directory,
1818
- projectID,
1819
1783
  primaryWorktree,
1820
1784
  localBranch,
1821
1785
  setUpstream,
@@ -1848,7 +1812,7 @@ const queueWorktreeBootstrap = (args) => {
1848
1812
  WORKTREE_BOOTSTRAP_PENDING,
1849
1813
  WORKTREE_BOOTSTRAP_PHASE_GIT_READY
1850
1814
  );
1851
- await runWorktreeStartScripts(directory, projectID, startCommand);
1815
+ await runWorktreeStartScripts(directory, startCommand);
1852
1816
  setWorktreeBootstrapState(
1853
1817
  directory,
1854
1818
  WORKTREE_BOOTSTRAP_READY,
@@ -4032,7 +3996,6 @@ async function attachGitWorktreeToCandidate(context, candidate, input = {}) {
4032
3996
 
4033
3997
  queueWorktreeBootstrap({
4034
3998
  directory: candidate.directory,
4035
- projectID: context.projectID,
4036
3999
  primaryWorktree: context.primaryWorktree,
4037
4000
  localBranch,
4038
4001
  setUpstream: shouldSetUpstream,
@@ -517,11 +517,11 @@ describe('createWorktree', () => {
517
517
  it('reports directory, Git, and setup bootstrap phases while preserving legacy status', async () => {
518
518
  if (!canRunGit()) return;
519
519
 
520
- const previousXdgDataHome = process.env.XDG_DATA_HOME;
520
+ const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
521
521
  const dataHome = createTempDir();
522
522
  const setupMarker = path.join(dataHome, 'setup-started');
523
523
  const setupScript = path.join(dataHome, 'setup-phase.cjs');
524
- process.env.XDG_DATA_HOME = dataHome;
524
+ process.env.PICHAMBER_DATA_DIR = dataHome;
525
525
 
526
526
  fs.writeFileSync(
527
527
  setupScript,
@@ -568,10 +568,10 @@ describe('createWorktree', () => {
568
568
  error: null,
569
569
  });
570
570
  } finally {
571
- if (previousXdgDataHome === undefined) {
572
- delete process.env.XDG_DATA_HOME;
571
+ if (previousPiChamberDataDir === undefined) {
572
+ delete process.env.PICHAMBER_DATA_DIR;
573
573
  } else {
574
- process.env.XDG_DATA_HOME = previousXdgDataHome;
574
+ process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
575
575
  }
576
576
  }
577
577
  });
@@ -579,10 +579,10 @@ describe('createWorktree', () => {
579
579
  it('reports setup command failure after Git becomes ready', async () => {
580
580
  if (!canRunGit()) return;
581
581
 
582
- const previousXdgDataHome = process.env.XDG_DATA_HOME;
582
+ const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
583
583
  const dataHome = createTempDir();
584
584
  const setupScript = path.join(dataHome, 'setup-failure.cjs');
585
- process.env.XDG_DATA_HOME = dataHome;
585
+ process.env.PICHAMBER_DATA_DIR = dataHome;
586
586
  fs.writeFileSync(setupScript, 'process.exitCode = 1;\n');
587
587
 
588
588
  try {
@@ -612,8 +612,8 @@ describe('createWorktree', () => {
612
612
  error: 'Worktree setup command failed',
613
613
  });
614
614
  } finally {
615
- if (previousXdgDataHome === undefined) delete process.env.XDG_DATA_HOME;
616
- else process.env.XDG_DATA_HOME = previousXdgDataHome;
615
+ if (previousPiChamberDataDir === undefined) delete process.env.PICHAMBER_DATA_DIR;
616
+ else process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
617
617
  }
618
618
  });
619
619
 
@@ -629,9 +629,9 @@ describe('createWorktree', () => {
629
629
  it('runs the post-checkout hook after populating a created worktree', async () => {
630
630
  if (!canRunGit()) return;
631
631
 
632
- const previousXdgDataHome = process.env.XDG_DATA_HOME;
632
+ const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
633
633
  const dataHome = createTempDir();
634
- process.env.XDG_DATA_HOME = dataHome;
634
+ process.env.PICHAMBER_DATA_DIR = dataHome;
635
635
 
636
636
  try {
637
637
  const repo = createTempDir();
@@ -670,10 +670,10 @@ describe('createWorktree', () => {
670
670
  expect(flag).toBe('1');
671
671
  expect(cwd).toBe(fs.realpathSync(created.path));
672
672
  } finally {
673
- if (previousXdgDataHome === undefined) {
674
- delete process.env.XDG_DATA_HOME;
673
+ if (previousPiChamberDataDir === undefined) {
674
+ delete process.env.PICHAMBER_DATA_DIR;
675
675
  } else {
676
- process.env.XDG_DATA_HOME = previousXdgDataHome;
676
+ process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
677
677
  }
678
678
  }
679
679
  });
@@ -681,9 +681,9 @@ describe('createWorktree', () => {
681
681
  it('skips a non-executable post-checkout hook', async () => {
682
682
  if (!canRunGit()) return;
683
683
 
684
- const previousXdgDataHome = process.env.XDG_DATA_HOME;
684
+ const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
685
685
  const dataHome = createTempDir();
686
- process.env.XDG_DATA_HOME = dataHome;
686
+ process.env.PICHAMBER_DATA_DIR = dataHome;
687
687
 
688
688
  try {
689
689
  const repo = createTempDir();
@@ -714,10 +714,10 @@ describe('createWorktree', () => {
714
714
  ).toBe('ready');
715
715
  expect(fs.existsSync(hookLog)).toBe(false);
716
716
  } finally {
717
- if (previousXdgDataHome === undefined) {
718
- delete process.env.XDG_DATA_HOME;
717
+ if (previousPiChamberDataDir === undefined) {
718
+ delete process.env.PICHAMBER_DATA_DIR;
719
719
  } else {
720
- process.env.XDG_DATA_HOME = previousXdgDataHome;
720
+ process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
721
721
  }
722
722
  }
723
723
  });
@@ -725,9 +725,9 @@ describe('createWorktree', () => {
725
725
  it('does not fail worktree bootstrap when the post-checkout hook fails', async () => {
726
726
  if (!canRunGit()) return;
727
727
 
728
- const previousXdgDataHome = process.env.XDG_DATA_HOME;
728
+ const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
729
729
  const dataHome = createTempDir();
730
- process.env.XDG_DATA_HOME = dataHome;
730
+ process.env.PICHAMBER_DATA_DIR = dataHome;
731
731
 
732
732
  try {
733
733
  const repo = createTempDir();
@@ -757,10 +757,10 @@ describe('createWorktree', () => {
757
757
  ).toBe('ready');
758
758
  expect(fs.readFileSync(hookLog, 'utf8')).toBe('ran');
759
759
  } finally {
760
- if (previousXdgDataHome === undefined) {
761
- delete process.env.XDG_DATA_HOME;
760
+ if (previousPiChamberDataDir === undefined) {
761
+ delete process.env.PICHAMBER_DATA_DIR;
762
762
  } else {
763
- process.env.XDG_DATA_HOME = previousXdgDataHome;
763
+ process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
764
764
  }
765
765
  }
766
766
  });
@@ -768,12 +768,12 @@ describe('createWorktree', () => {
768
768
  it('waits for active bootstrap work before removing a worktree', async () => {
769
769
  if (!canRunGit()) return;
770
770
 
771
- const previousXdgDataHome = process.env.XDG_DATA_HOME;
771
+ const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
772
772
  const dataHome = createTempDir();
773
773
  const setupStarted = path.join(dataHome, 'remove-race-started');
774
774
  const setupCompleted = path.join(dataHome, 'remove-race-completed');
775
775
  const setupScript = path.join(dataHome, 'remove-race.cjs');
776
- process.env.XDG_DATA_HOME = dataHome;
776
+ process.env.PICHAMBER_DATA_DIR = dataHome;
777
777
 
778
778
  fs.writeFileSync(
779
779
  setupScript,
@@ -814,10 +814,10 @@ describe('createWorktree', () => {
814
814
  phase: 'setup-ready',
815
815
  });
816
816
  } finally {
817
- if (previousXdgDataHome === undefined) {
818
- delete process.env.XDG_DATA_HOME;
817
+ if (previousPiChamberDataDir === undefined) {
818
+ delete process.env.PICHAMBER_DATA_DIR;
819
819
  } else {
820
- process.env.XDG_DATA_HOME = previousXdgDataHome;
820
+ process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
821
821
  }
822
822
  }
823
823
  });
@@ -847,9 +847,9 @@ describe('createWorktree', () => {
847
847
  it('preflights fast create branch-in-use failures before creating the candidate directory', async () => {
848
848
  if (!canRunGit()) return;
849
849
 
850
- const previousXdgDataHome = process.env.XDG_DATA_HOME;
850
+ const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
851
851
  const dataHome = createTempDir();
852
- process.env.XDG_DATA_HOME = dataHome;
852
+ process.env.PICHAMBER_DATA_DIR = dataHome;
853
853
 
854
854
  try {
855
855
  const repo = createTempDir();
@@ -874,13 +874,13 @@ describe('createWorktree', () => {
874
874
  returnAfterDirectoryCreated: true,
875
875
  })).rejects.toThrow(`Branch is already checked out in ${canonicalWorktree}`);
876
876
 
877
- const candidateDirectory = path.join(dataHome, 'opencode', 'worktree', projectID, 'feature-in-use');
877
+ const candidateDirectory = path.join(dataHome, 'pi', 'worktree', projectID, 'feature-in-use');
878
878
  expect(fs.existsSync(candidateDirectory)).toBe(false);
879
879
  } finally {
880
- if (previousXdgDataHome === undefined) {
881
- delete process.env.XDG_DATA_HOME;
880
+ if (previousPiChamberDataDir === undefined) {
881
+ delete process.env.PICHAMBER_DATA_DIR;
882
882
  } else {
883
- process.env.XDG_DATA_HOME = previousXdgDataHome;
883
+ process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
884
884
  }
885
885
  }
886
886
  });
@@ -894,9 +894,9 @@ describe('removeWorktree', () => {
894
894
  it('forgets unmanaged orphan worktree entries without deleting files', async () => {
895
895
  if (!canRunGit()) return;
896
896
 
897
- const previousXdgDataHome = process.env.XDG_DATA_HOME;
897
+ const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
898
898
  const dataHome = createTempDir();
899
- process.env.XDG_DATA_HOME = dataHome;
899
+ process.env.PICHAMBER_DATA_DIR = dataHome;
900
900
 
901
901
  try {
902
902
  const repo = createTempDir();
@@ -917,10 +917,10 @@ describe('removeWorktree', () => {
917
917
  })).resolves.toBe(true);
918
918
  expect(fs.existsSync(canary)).toBe(true);
919
919
  } finally {
920
- if (previousXdgDataHome === undefined) {
921
- delete process.env.XDG_DATA_HOME;
920
+ if (previousPiChamberDataDir === undefined) {
921
+ delete process.env.PICHAMBER_DATA_DIR;
922
922
  } else {
923
- process.env.XDG_DATA_HOME = previousXdgDataHome;
923
+ process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
924
924
  }
925
925
  }
926
926
  });
@@ -0,0 +1,62 @@
1
+ export const MAX_EXTENSION_APP_HTML_CHARS = 200_000;
2
+ const MAX_EXTENSION_FORM_FIELDS = 12;
3
+ const MAX_EXTENSION_FORM_OPTIONS = 20;
4
+
5
+ const FORM_FIELD_TYPES = new Set(['text', 'textarea', 'number', 'select', 'checkbox']);
6
+
7
+ /**
8
+ * Normalize extension-authored form descriptors at both sides of the private
9
+ * daemon IPC seam. Keeping this in one module prevents the daemon bridge and
10
+ * public route projection from accepting different field shapes.
11
+ */
12
+ export const sanitizeExtensionFormFields = (fields) => {
13
+ if (!Array.isArray(fields)) return [];
14
+ return fields.slice(0, MAX_EXTENSION_FORM_FIELDS).flatMap((field) => {
15
+ if (!field || typeof field !== 'object') return [];
16
+ const id = typeof field.id === 'string' ? field.id.slice(0, 128) : '';
17
+ const label = typeof field.label === 'string' ? field.label.slice(0, 256) : '';
18
+ if (!id || !label) return [];
19
+ return [{
20
+ id,
21
+ label,
22
+ type: FORM_FIELD_TYPES.has(field.type) ? field.type : 'text',
23
+ ...(field.required === true ? { required: true } : {}),
24
+ ...(typeof field.placeholder === 'string' ? { placeholder: field.placeholder.slice(0, 256) } : {}),
25
+ ...(Array.isArray(field.options)
26
+ ? {
27
+ options: field.options
28
+ .filter((option) => typeof option === 'string')
29
+ .map((option) => option.slice(0, 256))
30
+ .slice(0, MAX_EXTENSION_FORM_OPTIONS),
31
+ }
32
+ : {}),
33
+ ...(typeof field.initial === 'string' ? { initial: field.initial.slice(0, 2_000) } : {}),
34
+ ...(Number.isFinite(field.min) ? { min: field.min } : {}),
35
+ ...(Number.isFinite(field.max) ? { max: field.max } : {}),
36
+ }];
37
+ });
38
+ };
39
+
40
+ /** Validate a form answer against the exact descriptor sent to the client. */
41
+ export const validateExtensionFormValues = (fields, values) => {
42
+ if (!Array.isArray(fields) || !values || typeof values !== 'object' || Array.isArray(values)) return false;
43
+ const fieldsById = new Map(fields.map((field) => [field.id, field]));
44
+ for (const key of Object.keys(values)) if (!fieldsById.has(key)) return false;
45
+ for (const field of fields) {
46
+ const value = values[field.id];
47
+ if (field.required === true && (typeof value !== 'string' || value.length === 0)) return false;
48
+ if (value === undefined || value.length === 0) continue;
49
+ if (typeof value !== 'string') return false;
50
+ if (field.type === 'number') {
51
+ const number = Number(value);
52
+ if (!Number.isFinite(number)) return false;
53
+ if (typeof field.min === 'number' && number < field.min) return false;
54
+ if (typeof field.max === 'number' && number > field.max) return false;
55
+ } else if (field.type === 'select' && !field.options?.includes(value)) {
56
+ return false;
57
+ } else if (field.type === 'checkbox' && value !== 'true' && value !== 'false') {
58
+ return false;
59
+ }
60
+ }
61
+ return true;
62
+ };
@@ -0,0 +1,34 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { sanitizeExtensionFormFields, validateExtensionFormValues } from './extension-protocol.js';
4
+
5
+ describe('extension form protocol', () => {
6
+ it('uses one bounded field projection for daemon and public routes', () => {
7
+ const fields = sanitizeExtensionFormFields([
8
+ { id: 'name', label: 'Name', type: 'text', required: true, placeholder: 'x'.repeat(300) },
9
+ { id: 'mode', label: 'Mode', type: 'select', options: ['fast', 'safe'] },
10
+ { id: 'count', label: 'Count', type: 'number', min: 1, max: 3 },
11
+ { id: '', label: 'Invalid' },
12
+ ]);
13
+ expect(fields).toHaveLength(3);
14
+ expect(fields[0].placeholder).toHaveLength(256);
15
+ expect(fields[1].options).toEqual(['fast', 'safe']);
16
+ });
17
+
18
+ it('rejects unknown, malformed, and out-of-range answers', () => {
19
+ const fields = sanitizeExtensionFormFields([
20
+ { id: 'name', label: 'Name', type: 'text', required: true },
21
+ { id: 'mode', label: 'Mode', type: 'select', options: ['fast', 'safe'] },
22
+ { id: 'count', label: 'Count', type: 'number', min: 1, max: 3 },
23
+ { id: 'enabled', label: 'Enabled', type: 'checkbox' },
24
+ ]);
25
+ expect(validateExtensionFormValues(fields, {
26
+ name: 'worker', mode: 'safe', count: '2', enabled: 'true',
27
+ })).toBe(true);
28
+ expect(validateExtensionFormValues(fields, { name: 'worker', unknown: 'x' })).toBe(false);
29
+ expect(validateExtensionFormValues(fields, { name: '', mode: 'safe' })).toBe(false);
30
+ expect(validateExtensionFormValues(fields, { name: 'worker', mode: 'turbo' })).toBe(false);
31
+ expect(validateExtensionFormValues(fields, { name: 'worker', count: '4' })).toBe(false);
32
+ expect(validateExtensionFormValues(fields, { name: 'worker', enabled: 'yes' })).toBe(false);
33
+ });
34
+ });