@pi-chamber/web 1.0.8-rc.2 → 1.0.8-rc.4

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 (113) hide show
  1. package/dist/assets/{AgentsSurface-CcWBqAWV.js → AgentsSurface-DbCBygRD.js} +1 -1
  2. package/dist/assets/{ChoicesArtifact-Kk-qvrSB.js → ChoicesArtifact-DUqhCvXh.js} +1 -1
  3. package/dist/assets/{DiagramView-DZUBo1uP.js → DiagramView-CnVOyJd2.js} +1 -1
  4. package/dist/assets/{DiffView-CiZy4jFA.js → DiffView-Db8JXsvA.js} +1 -1
  5. package/dist/assets/{FileSaveConflictDialog-DZ9NDwOO.js → FileSaveConflictDialog-D6xyf709.js} +1 -1
  6. package/dist/assets/{FilesView-DqiZ9kw9.js → FilesView-Cir0Wl9F.js} +1 -1
  7. package/dist/assets/{GitHubDetailScaffold-DM2DH7o8.js → GitHubDetailScaffold-US37Di_K.js} +1 -1
  8. package/dist/assets/{GitHubLinkPicker-ChB8NZ1h.js → GitHubLinkPicker-k_D-sk-e.js} +1 -1
  9. package/dist/assets/{GitHubListPrimitives-CibDiJGq.js → GitHubListPrimitives-DuUXrJGk.js} +1 -1
  10. package/dist/assets/{GitView--EaZQrBr.js → GitView-BdX_3XRr.js} +3 -3
  11. package/dist/assets/{IssuesSurface-CySTpaD1.js → IssuesSurface-Cw93HC0G.js} +2 -2
  12. package/dist/assets/{JsonTreeView-_yMHKKQZ.js → JsonTreeView-Bze4htWt.js} +1 -1
  13. package/dist/assets/{MarkdownRendererImpl-D_-2fQw0.js → MarkdownRendererImpl-Ch7NDkF9.js} +1 -1
  14. package/dist/assets/{PatchDiff-bHObDlhD.js → PatchDiff-l68Yz45X.js} +1 -1
  15. package/dist/assets/{PierreDiffViewer-UY7Cse-s.js → PierreDiffViewer-BHBySiXQ.js} +1 -1
  16. package/dist/assets/{PullRequestsSurface-iXy6chwc.js → PullRequestsSurface-CGD4_ljc.js} +2 -2
  17. package/dist/assets/{SessionSwitcherContent-DJGCa_wN.js → SessionSwitcherContent-DqP8OWzB.js} +1 -1
  18. package/dist/assets/{SessionSwitcherDropdown-CDOX-5Y2.js → SessionSwitcherDropdown-BkTg-cVd.js} +2 -2
  19. package/dist/assets/{SessionUnreadDot-Dwc3MdvA.js → SessionUnreadDot-CgvC3F5e.js} +1 -1
  20. package/dist/assets/SettingsView-CkIxCYhs.js +11 -0
  21. package/dist/assets/{SettingsWindow-CUg49Mfh.js → SettingsWindow-DSdhzapT.js} +1 -1
  22. package/dist/assets/{SubagentsArtifact-DUZX9tDe.js → SubagentsArtifact-BN3aX_8M.js} +1 -1
  23. package/dist/assets/{ToolOutputDialog-BuZZaRw4.js → ToolOutputDialog-CLwm4TjA.js} +1 -1
  24. package/dist/assets/{ToolPartDiffPreview-CKncG6i2.js → ToolPartDiffPreview-ERAStEKA.js} +1 -1
  25. package/dist/assets/{VirtualizedFileDiff-BGZiLPe_.js → VirtualizedFileDiff-DwR2fZHv.js} +1 -1
  26. package/dist/assets/VisualFrame-Dwp7B_st.js +22 -0
  27. package/dist/assets/{VisualsArtifact-Bq0vMO-i.js → VisualsArtifact-DlOxifHd.js} +1 -1
  28. package/dist/assets/{collapsible-Bro9KrfM.js → collapsible-CW-_qd6v.js} +1 -1
  29. package/dist/assets/{computeVirtualFileMetrics-DJQqK49u.js → computeVirtualFileMetrics-SlBfr8LB.js} +1 -1
  30. package/dist/assets/{contextFileOpenGuard-ByWK3Sru.js → contextFileOpenGuard-CHoFT50j.js} +1 -1
  31. package/dist/assets/{fileTreeStatus-CyJ3TOYD.js → fileTreeStatus-D0uiC1D0.js} +1 -1
  32. package/dist/assets/{gitStatusPredicates-BsXrwngT.js → gitStatusPredicates-Bj3pkh2e.js} +1 -1
  33. package/dist/assets/{githubLink-g2bmC0qi.js → githubLink-CheLNuP0.js} +1 -1
  34. package/dist/assets/index-BFkW-BPM.js +11 -0
  35. package/dist/assets/index-C5JgjS20.css +1 -0
  36. package/dist/assets/{index-C9rUUQ_Y.js → index-C8zaLvup.js} +1 -1
  37. package/dist/assets/{main-DT-4_fhe.js → main-CUEqZRu1.js} +2 -2
  38. package/dist/assets/{main-DsLMU9CT.js → main-V66ie29o.js} +4 -4
  39. package/dist/assets/{markdownCore-QmM_aOnZ.js → markdownCore-BRedKgCo.js} +1 -1
  40. package/dist/assets/{miniChat-BqGslD2z.js → miniChat-BXwuEQhz.js} +2 -2
  41. package/dist/assets/{mobile-C5JOcDIC.js → mobile-7s-xLDG3.js} +2 -2
  42. package/dist/assets/{nativeFileSave-DSMsJqXM.js → nativeFileSave-Bj-V_9ae.js} +1 -1
  43. package/dist/assets/{pi-session-focus-preference-Cc_S4zi1.js → pi-session-focus-preference-clbekCjz.js} +1 -1
  44. package/dist/assets/{renderDiffWithHighlighter-BXhnIAHg.js → renderDiffWithHighlighter-g9eKWi78.js} +1 -1
  45. package/dist/assets/{renderElectronMiniChatApp-CiSkecEE.js → renderElectronMiniChatApp-B6BN8YgC.js} +2 -2
  46. package/dist/assets/{renderFileWithHighlighter-CK29YZtC.js → renderFileWithHighlighter-DKl6vubK.js} +1 -1
  47. package/dist/assets/{renderMobileApp-C4JuoxsZ.js → renderMobileApp-Bp735rW7.js} +3 -3
  48. package/dist/assets/{runtimeEndpointReset-Dwj-jCDS.js → runtimeEndpointReset-CtHv_OMT.js} +7 -7
  49. package/dist/assets/{runtimeSurface-0K7vuUpd.js → runtimeSurface-DD4Vn4HC.js} +1 -1
  50. package/dist/assets/{selection-CnYkEsu_.js → selection-DDT954wY.js} +1 -1
  51. package/dist/assets/useAppFontEffects-DJCrUN2D.js +226 -0
  52. package/dist/assets/{useGitHubRemoteSearch-CgP-zEBj.js → useGitHubRemoteSearch-B77fMiwQ.js} +1 -1
  53. package/dist/assets/{useSwitcherItems-C8G5F0hs.js → useSwitcherItems-CFY3mP06.js} +1 -1
  54. package/dist/assets/{web-components-BpncHjnV.js → web-components-XIP_3VZv.js} +1 -1
  55. package/dist/index.html +4 -4
  56. package/dist/mini-chat.html +3 -3
  57. package/dist/mobile.html +3 -3
  58. package/package.json +2 -1
  59. package/pichamber.d.ts +139 -0
  60. package/plugins/subagents/extension.js +5 -5
  61. package/plugins/subagents/package.json +3 -2
  62. package/plugins/visuals/choices.js +8 -7
  63. package/plugins/visuals/extension.js +6 -6
  64. package/plugins/visuals/package.json +1 -1
  65. package/server/index.js +4 -0
  66. package/server/lib/marketplace/DOCUMENTATION.md +2 -2
  67. package/server/lib/marketplace/npm-registry.js +1 -1
  68. package/server/lib/marketplace/npm-registry.test.js +1 -1
  69. package/server/lib/marketplace/service.test.js +4 -4
  70. package/server/lib/open-url/DOCUMENTATION.md +1 -1
  71. package/server/lib/pi/extension-card.js +48 -0
  72. package/server/lib/pi/extension-card.test.js +35 -0
  73. package/server/lib/pi/extension-commands.js +49 -0
  74. package/server/lib/pi/extension-commands.test.js +38 -0
  75. package/server/lib/pi/extension-protocol.js +1 -2
  76. package/server/lib/pi/fixtures/pichamber-gui-demo.ts +52 -223
  77. package/server/lib/pi/routes-extension-events.test.js +35 -48
  78. package/server/lib/pi/routes.js +44 -54
  79. package/server/lib/pi/routes.test.js +32 -0
  80. package/server/lib/pi/session-daemon/DOCUMENTATION.md +7 -7
  81. package/server/lib/pi/session-daemon/extension-bridge-draft.test.js +0 -54
  82. package/server/lib/pi/session-daemon/extension-bridge.js +39 -162
  83. package/server/lib/pi/session-daemon/extension-controls.js +12 -57
  84. package/server/lib/pi/session-daemon/extension-controls.test.js +4 -34
  85. package/server/lib/pi/session-daemon/pichamber-api.js +38 -0
  86. package/server/lib/pi/session-daemon/pichamber-api.test.js +24 -0
  87. package/server/lib/pi/session-daemon/plugin-host.js +5 -7
  88. package/server/lib/pi/session-daemon/plugin-host.test.js +2 -3
  89. package/server/lib/pi/session-daemon/session-daemon-controls.e2e.test.js +53 -7
  90. package/server/lib/pi/session-daemon/session-daemon-drafts.e2e.test.js +5 -5
  91. package/server/lib/pi/session-daemon/session-daemon-extensions.e2e.test.js +9 -4
  92. package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +28 -71
  93. package/server/lib/pi/session-daemon/session-daemon-plugins.e2e.test.js +1 -1
  94. package/server/lib/pi/session-daemon/session-daemon.js +138 -78
  95. package/server/lib/pi/session-daemon/session-daemon.test.js +68 -0
  96. package/server/lib/pi/ui-settings-store.js +2 -1
  97. package/server/lib/plugins/DOCUMENTATION.md +3 -3
  98. package/server/lib/plugins/impact.js +2 -4
  99. package/server/lib/plugins/impact.test.js +0 -1
  100. package/server/lib/plugins/manifest.js +9 -5
  101. package/server/lib/plugins/manifest.test.js +5 -4
  102. package/server/lib/plugins/store.test.js +1 -1
  103. package/server/lib/plugins/visuals-extension.test.js +16 -14
  104. package/server/lib/wallpaper/DOCUMENTATION.md +25 -0
  105. package/server/lib/wallpaper/routes.js +63 -0
  106. package/server/lib/wallpaper/routes.test.js +109 -0
  107. package/server/lib/wallpaper/store.js +87 -0
  108. package/dist/assets/SettingsView-DA-U9lsj.js +0 -11
  109. package/dist/assets/VisualFrame-DBZkHFnG.js +0 -22
  110. package/dist/assets/index-B_L9GVYw.css +0 -1
  111. package/dist/assets/index-CKKWVoND.js +0 -11
  112. package/dist/assets/useAppFontEffects-CV5UyTRw.js +0 -226
  113. package/server/lib/pi/session-daemon/pichamber-ui.js +0 -44
@@ -4,7 +4,7 @@
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "description": "Lets the agent hand tasks to sub-agents that work in their own context.",
7
- "keywords": ["pi-package", "pichamber-plugin", "subagent", "subagents", "delegate", "parallel", "agents", "workflow", "orchestration"],
7
+ "keywords": ["pi-package", "pichamber", "subagent", "subagents", "delegate", "parallel", "agents", "workflow", "orchestration"],
8
8
  "license": "MIT",
9
9
  "pi": {
10
10
  "extensions": ["./extension.js"]
@@ -26,9 +26,10 @@
26
26
  }
27
27
  },
28
28
  "contributes": {
29
- "composerToggles": [
29
+ "controls": [
30
30
  {
31
31
  "id": "subagents",
32
+ "kind": "toggle",
32
33
  "state": "on",
33
34
  "label": "Sub-agents",
34
35
  "icon": "robot-2",
@@ -1,6 +1,6 @@
1
1
  // Visuals: `render_choices`. Shows a few variants (pages or images) in the
2
2
  // chat, one at a time, and waits for the user to pick one. PiChamber draws the
3
- // variants from the call's `details` and asks through `pichamber.ui.choose`, which
3
+ // variants from the call's `details` and asks through `pichamber.choose`, which
4
4
  // ties the question to this tool call so the chat component can answer it.
5
5
 
6
6
  import { MAX_PAGE_CHARS, readPageOrImage } from './files.js';
@@ -95,10 +95,11 @@ export const renderChoices = async (params, { cwd } = {}) => {
95
95
  * client has no way to ask, else `{ asked: true, id?, note? }` with no `id`
96
96
  * when the question was closed without an answer.
97
97
  */
98
- export const askChoice = async (pichamber, ctx, toolCallId, choices, signal) => {
98
+ export const askChoice = async (ctx, toolCallId, choices, signal) => {
99
99
  const ui = ctx?.ui;
100
- if (typeof pichamber?.ui?.choose === 'function') {
101
- const answer = await pichamber.ui.choose(
100
+ const { pichamber } = globalThis;
101
+ if (typeof pichamber?.choose === 'function') {
102
+ const answer = await pichamber.choose(
102
103
  ctx,
103
104
  choices.title,
104
105
  choices.options.map((option) => ({
@@ -146,9 +147,9 @@ export const choiceResult = (choices, answer) => {
146
147
 
147
148
  /**
148
149
  * Register `render_choices`. `getCwd` gives the session's folder when the
149
- * call has none. `pichamber` is PiChamber's handle; plain Pi passes none.
150
+ * call has none.
150
151
  */
151
- export const registerChoicesTool = (pi, getCwd, pichamber) => {
152
+ export const registerChoicesTool = (pi, getCwd) => {
152
153
  pi.registerTool({
153
154
  name: CHOICES_TOOL_NAME,
154
155
  label: 'Render choices',
@@ -162,7 +163,7 @@ export const registerChoicesTool = (pi, getCwd, pichamber) => {
162
163
  // Pi delivers that update after this turn of the event loop. Asking
163
164
  // only then keeps the question from arriving before its variants.
164
165
  await new Promise((resolve) => setImmediate(resolve));
165
- return choiceResult(choices, await askChoice(pichamber, ctx, toolCallId, choices, signal));
166
+ return choiceResult(choices, await askChoice(ctx, toolCallId, choices, signal));
166
167
  },
167
168
  });
168
169
  };
@@ -4,8 +4,8 @@
4
4
  // the result's `details`; this module only validates and returns them.
5
5
  //
6
6
  // It has no switch of its own: while the plugin is on in Settings, the tools
7
- // are there in every session. PiChamber's `pichamber` handle is used only to ask
8
- // `render_choices` questions; plain Pi passes none and gets a text list.
7
+ // are there in every session. `render_choices` asks through
8
+ // `globalThis.pichamber.choose`; plain Pi has none and gets a text list.
9
9
 
10
10
  import { CHOICES_TOOL_NAME, registerChoicesTool } from './choices.js';
11
11
  import { MAX_PAGE_CHARS, readPage } from './files.js';
@@ -20,7 +20,7 @@ export const MAX_HEIGHT = 2_000;
20
20
  const DESCRIPTION = 'Show a finished, self-contained HTML page (chart, diagram, table, mockup) in the chat above your reply. '
21
21
  + 'Inline all CSS and JS; no network. It sits in the reply column (~760px, ~360px on phones) on the chat background, so use fluid widths. '
22
22
  + 'No outer card, border, background, side padding or title heading; boxes get 12-16px padding and var(--pc-radius). '
23
- + 'Charts get a fixed px height; no vh. Text, tables, inputs, code and SVG text are pre-styled. '
23
+ + 'The frame fits the content: charts get a fixed px height; no vh or 100%. Text, tables, inputs, code and SVG text are pre-styled. '
24
24
  + 'Labels and axes 12px in --pc-muted, headings ≤16px, big numbers ≤24px. '
25
25
  + 'Colours: --pc-bg, --pc-surface, --pc-fg, --pc-muted, --pc-border, --pc-accent. One series = --pc-c1; '
26
26
  + 'ranked values: its shades --pc-shade-1..4; --pc-c2..5 only for more series, max 3 in all; '
@@ -33,7 +33,7 @@ const PARAMETERS = {
33
33
  title: { type: 'string', maxLength: MAX_TITLE_CHARS },
34
34
  html: { type: 'string', description: 'The page. Use this or path.' },
35
35
  path: { type: 'string', description: 'An .html file in the project instead of html.' },
36
- height: { type: 'integer', minimum: MIN_HEIGHT, maximum: MAX_HEIGHT, description: 'Frame height in pixels.' },
36
+ height: { type: 'integer', minimum: MIN_HEIGHT, maximum: MAX_HEIGHT, description: 'Pixels to hold until the page loads.' },
37
37
  },
38
38
  required: ['title'],
39
39
  additionalProperties: false,
@@ -61,7 +61,7 @@ export const renderHtml = async (params, { cwd } = {}) => {
61
61
  };
62
62
  };
63
63
 
64
- export default function visuals(pi, pichamber) {
64
+ export default function visuals(pi) {
65
65
  let cwd;
66
66
 
67
67
  pi.registerTool({
@@ -74,7 +74,7 @@ export default function visuals(pi, pichamber) {
74
74
  },
75
75
  });
76
76
 
77
- registerChoicesTool(pi, () => cwd, pichamber);
77
+ registerChoicesTool(pi, () => cwd);
78
78
 
79
79
  // Keep the rest of the active tools as they are; only add ours.
80
80
  pi.on('session_start', (_event, ctx) => {
@@ -4,7 +4,7 @@
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "description": "Lets the agent draw HTML pages in the chat.",
7
- "keywords": ["pi-package", "pichamber-plugin", "html", "visual", "visuals", "chart", "charts", "diagram", "mockup", "render", "preview", "ui", "design", "choices"],
7
+ "keywords": ["pi-package", "pichamber", "html", "visual", "visuals", "chart", "charts", "diagram", "mockup", "render", "preview", "ui", "design", "choices"],
8
8
  "pi": {
9
9
  "extensions": ["./extension.js"]
10
10
  },
package/server/index.js CHANGED
@@ -24,6 +24,8 @@ import { registerPluginRoutes } from './lib/plugins/routes.js';
24
24
  import { createFeaturedSource, DEFAULT_FEATURED_URL } from './lib/marketplace/featured.js';
25
25
  import { createNpmRegistry } from './lib/marketplace/npm-registry.js';
26
26
  import { registerMarketplaceRoutes } from './lib/marketplace/routes.js';
27
+ import { registerWallpaperRoutes } from './lib/wallpaper/routes.js';
28
+ import { createWallpaperImageStore } from './lib/wallpaper/store.js';
27
29
  import { createMarketplaceService } from './lib/marketplace/service.js';
28
30
  import { createDockerInitialLocalSettings, createPiUiSettingsStore } from './lib/pi/ui-settings-store.js';
29
31
  import { detectLinuxDistribution } from './lib/server/linux-distribution.js';
@@ -316,6 +318,8 @@ export async function startWebUiServer(options = {}) {
316
318
  },
317
319
  });
318
320
  registerPluginRoutes(app, { service: pluginService, onChange: pluginDaemonSync.changed });
321
+ // The new-session wallpaper picture (lib/wallpaper/DOCUMENTATION.md).
322
+ registerWallpaperRoutes(app, { express, store: createWallpaperImageStore({ dataDir: PICHAMBER_DATA_DIR }) });
319
323
  // Marketplace: npm search and the featured list (lib/marketplace/DOCUMENTATION.md).
320
324
  // PICHAMBER_NPM_REGISTRY_URL / PICHAMBER_NPM_DOWNLOADS_URL point it at a
321
325
  // mirror or a test fixture; PICHAMBER_FEATURED_URL=off stops refreshing the
@@ -69,9 +69,9 @@ hours; a release carries the file as the fallback.
69
69
  paging at the first page that has an unrelated hit, so the tail of
70
70
  unrelated packages never shows.
71
71
  - npm treats two keywords loosely, so the service asks for one
72
- (`pichamber-plugin` with `pichamber=1`, otherwise `pi-package`) and checks
72
+ (`pichamber` with `pichamber=1`, otherwise `pi-package`) and checks
73
73
  both itself.
74
- - The `pichamber-plugin` keyword is a claim by the author: it marks a list
74
+ - The `pichamber` keyword is a claim by the author: it marks a list
75
75
  row. The package page reads the manifest and calls it a PiChamber plugin only
76
76
  when the `pichamber` block is really there. A third-party package with
77
77
  that block installs and runs as a plain Pi package; PiChamber does not load
@@ -9,7 +9,7 @@ const DEFAULT_DOWNLOADS_URL = 'https://api.npmjs.org';
9
9
  /** Pi's gallery lists npm packages with this keyword (Pi docs/packages.md). */
10
10
  export const PI_PACKAGE_KEYWORD = 'pi-package';
11
11
  /** Authors add this keyword to say the package has PiChamber support. */
12
- export const PICHAMBER_KEYWORD = 'pichamber-plugin';
12
+ export const PICHAMBER_KEYWORD = 'pichamber';
13
13
 
14
14
  const USER_AGENT = 'PiChamber';
15
15
  const DEFAULT_TIMEOUT_MS = 8_000;
@@ -93,7 +93,7 @@ describe('summarizePackage', () => {
93
93
  name: 'pi-lens',
94
94
  version: '1.2.3',
95
95
  description: 'A lens for pi.',
96
- keywords: ['pi-package', 'pichamber-plugin'],
96
+ keywords: ['pi-package', 'pichamber'],
97
97
  maintainers: [{ username: 'alice' }],
98
98
  publisher: { username: 'GitHub Actions' },
99
99
  };
@@ -80,17 +80,17 @@ describe('search', () => {
80
80
  expect(result.nextFrom).toBe(20);
81
81
  });
82
82
 
83
- it('asks npm for pichamber-plugin only and requires both keywords', async () => {
83
+ it('asks npm for pichamber only and requires both keywords', async () => {
84
84
  const { registry, service } = setup({
85
85
  objects: [
86
- hit('pi-both', { keywords: ['pi-package', 'pichamber-plugin'] }),
87
- hit('pi-narrow', { keywords: ['pichamber-plugin'] }),
86
+ hit('pi-both', { keywords: ['pi-package', 'pichamber'] }),
87
+ hit('pi-narrow', { keywords: ['pichamber'] }),
88
88
  ],
89
89
  total: 2,
90
90
  });
91
91
  const result = await service.search({ query: '', from: 0, pichamberOnly: true });
92
92
  expect(registry.searchRaw).toHaveBeenCalledWith(
93
- expect.objectContaining({ keywords: ['pichamber-plugin'] }),
93
+ expect.objectContaining({ keywords: ['pichamber'] }),
94
94
  );
95
95
  expect(result.packages.map((entry) => entry.name)).toEqual(['pi-both']);
96
96
  });
@@ -13,7 +13,7 @@ When a tool on the server machine wants to show the person a URL (an extension s
13
13
  4. Devices ask the person whether to open it (`packages/ui/src/components/chat/OpenRequestAlerts.tsx`). Nothing opens without a click.
14
14
  5. The intake answers `{ delivered }`. `delivered` is true only when a device holds a live `/api/pi/events` stream and the daemon published. Otherwise the handler falls back to the original `$BROWSER` list, then `open` (macOS) or `xdg-open`, with `$BROWSER` restored in that child's environment so it cannot loop back.
15
15
 
16
- Extensions in PiChamber can call `pichamber.ui.openUrl(ctx, url)` (`globalThis.pichamber`, absent in plain Pi). The older `ctx.ui.openUrl(url)` is removed. The call runs the same handler in-process with the exact session id and resolves whether the URL was shown or opened.
16
+ Extensions in PiChamber can call `pichamber.openUrl(ctx, url)` (`globalThis.pichamber`, absent in plain Pi). The older `ctx.ui.openUrl(url)` is removed. The call runs the same handler in-process with the exact session id and resolves whether the URL was shown or opened.
17
17
 
18
18
  ## Invariants
19
19
 
@@ -0,0 +1,48 @@
1
+ // Chat cards: `pichamber.card(ctx, card)`, or a `pichamber.card` entry an
2
+ // extension appends itself. Releases up to 1.0.7 used the `pichamber.ui`
3
+ // label, which saved sessions still hold, so the browser draws both
4
+ // (packages/ui/src/lib/pi/extension-ui.ts, the parser every card goes
5
+ // through). This module checks a card's shape before the daemon saves it, so
6
+ // `pichamber.card()` rejects what the browser could not take for a card. It
7
+ // does not check each component's props: the browser does, and draws props
8
+ // it cannot read as the generic card.
9
+
10
+ import { parseExtensionCommandName } from './extension-commands.js';
11
+
12
+ export const CARD_ENTRY_TYPE = 'pichamber.card';
13
+
14
+ export const CARD_COMPONENTS = Object.freeze(['markdown', 'kv', 'list', 'table', 'progress', 'badges', 'code']);
15
+ const COMPONENTS = new Set(CARD_COMPONENTS);
16
+ const MAX_ACTIONS = 8;
17
+
18
+ const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
19
+
20
+ /**
21
+ * The card to save, or a reason it cannot be one. Fields the browser does not
22
+ * read (`id`, `protocol`, `version`) are left out, so a card written through
23
+ * `pichamber.card()` never turns into something else.
24
+ */
25
+ export const normalizeExtensionCard = (raw) => {
26
+ if (!isRecord(raw)) return { error: 'a card is an object' };
27
+ if (typeof raw.component !== 'string' || !COMPONENTS.has(raw.component)) {
28
+ return { error: `\`component\` is one of ${[...COMPONENTS].join(', ')}` };
29
+ }
30
+ if (raw.props !== undefined && !isRecord(raw.props)) return { error: '`props` is an object' };
31
+ if (raw.title !== undefined && typeof raw.title !== 'string') return { error: '`title` is a string' };
32
+ if (raw.actions !== undefined) {
33
+ if (!Array.isArray(raw.actions) || raw.actions.length > MAX_ACTIONS) return { error: `\`actions\` is a list of up to ${MAX_ACTIONS}` };
34
+ for (const action of raw.actions) {
35
+ if (!isRecord(action) || typeof action.label !== 'string' || action.label.trim() === '') return { error: 'every action has a `label`' };
36
+ if (!parseExtensionCommandName(action.command)) return { error: `action "${action.label}" names no valid command` };
37
+ if (action.args !== undefined && typeof action.args !== 'string') return { error: `action "${action.label}" has \`args\` that is not a string` };
38
+ }
39
+ }
40
+ return {
41
+ card: {
42
+ ...(typeof raw.title === 'string' ? { title: raw.title } : {}),
43
+ component: raw.component,
44
+ props: raw.props ?? {},
45
+ ...(raw.actions ? { actions: raw.actions } : {}),
46
+ },
47
+ };
48
+ };
@@ -0,0 +1,35 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { CARD_COMPONENTS, normalizeExtensionCard } from './extension-card.js';
4
+
5
+ describe('normalizeExtensionCard', () => {
6
+ it('keeps what the browser reads and drops the rest', () => {
7
+ const actions = [{ label: 'Focus', command: '/focus', args: 'src' }];
8
+ expect(normalizeExtensionCard({ id: 'old-panel', protocol: 'x', version: 1, title: 'Build', component: 'progress', props: { value: 4 }, actions }))
9
+ .toEqual({ card: { title: 'Build', component: 'progress', props: { value: 4 }, actions } });
10
+ expect(normalizeExtensionCard({ component: 'markdown' })).toEqual({ card: { component: 'markdown', props: {} } });
11
+ });
12
+
13
+ it('says why a card cannot be shown', () => {
14
+ for (const bad of [
15
+ null,
16
+ [],
17
+ { component: 'chart' },
18
+ { component: 'kv', props: [] },
19
+ { component: 'kv', title: 3 },
20
+ { component: 'kv', actions: Array.from({ length: 9 }, () => ({ label: 'A', command: 'a' })) },
21
+ { component: 'kv', actions: [{ label: ' ', command: 'a' }] },
22
+ { component: 'kv', actions: [{ label: 'Run', command: 'bad;name' }] },
23
+ { component: 'kv', actions: [{ label: 'Run', command: 'run', args: 3 }] },
24
+ ]) {
25
+ expect(normalizeExtensionCard(bad).error).toEqual(expect.any(String));
26
+ }
27
+ });
28
+
29
+ it('lists the components the types file declares', async () => {
30
+ const { readFile } = await import('node:fs/promises');
31
+ const types = await readFile(new URL('../../../pichamber.d.ts', import.meta.url), 'utf8');
32
+ const declared = [...types.matchAll(/\{ component: '([a-z]+)'/g)].map((match) => match[1]);
33
+ expect(declared.sort()).toEqual([...CARD_COMPONENTS].sort());
34
+ });
35
+ });
@@ -0,0 +1,49 @@
1
+ // The one rule for an extension naming one of its own slash commands.
2
+ //
3
+ // Composer controls and card actions both name a command the extension registered, and a click runs it
4
+ // through `extensions.command`/`extensions.control`, which refuse a name Pi
5
+ // has not registered. They share this module so the same command is valid in
6
+ // every one of them:
7
+ //
8
+ // - The name is Pi's invocation name: a letter or digit, then letters,
9
+ // digits, `_`, `.`, `:` or `-`, up to 128 characters. Pi adds `:<n>` to
10
+ // tell two extensions' commands of the same name apart. One leading `/` is
11
+ // allowed and dropped.
12
+ // - Arguments are one line: control characters become spaces, the ends are
13
+ // trimmed, and at most 2,000 characters are kept.
14
+ //
15
+ // The browser keeps a copy of this rule in
16
+ // `packages/ui/src/lib/pi/extension-command.ts`; keep the two in step.
17
+
18
+ export const EXTENSION_COMMAND_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/;
19
+ const MAX_EXTENSION_COMMAND_ARGS_CHARS = 2_000;
20
+
21
+ /** `review` or `/review` → `review`; null when it is not a command name. */
22
+ export const parseExtensionCommandName = (value) => {
23
+ if (typeof value !== 'string') return null;
24
+ const name = value.startsWith('/') ? value.slice(1) : value;
25
+ return EXTENSION_COMMAND_NAME_PATTERN.test(name) ? name : null;
26
+ };
27
+
28
+ /** Arguments as one trimmed line of at most 2,000 characters ('' when none). */
29
+ export const normalizeExtensionCommandArgs = (value) => {
30
+ if (typeof value !== 'string') return '';
31
+ return value.replace(/[\u0000-\u001f\u007f]/g, ' ').trim().slice(0, MAX_EXTENSION_COMMAND_ARGS_CHARS);
32
+ };
33
+
34
+ /**
35
+ * A command with its arguments in one string (`/plan on` or `plan on`) →
36
+ * `plan on`; null when the part before the first space is not a command name.
37
+ */
38
+ export const parseExtensionCommandText = (value) => {
39
+ if (typeof value !== 'string') return null;
40
+ const text = normalizeExtensionCommandArgs(value);
41
+ const space = text.indexOf(' ');
42
+ const name = parseExtensionCommandName(space === -1 ? text : text.slice(0, space));
43
+ if (!name) return null;
44
+ const args = space === -1 ? '' : text.slice(space + 1).trim();
45
+ return args ? `${name} ${args}` : name;
46
+ };
47
+
48
+ /** The command's invocation name: the part before the first space. */
49
+ export const commandName = (command) => command.split(' ')[0];
@@ -0,0 +1,38 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import {
4
+ commandName,
5
+ normalizeExtensionCommandArgs,
6
+ parseExtensionCommandName,
7
+ parseExtensionCommandText,
8
+ } from './extension-commands.js';
9
+
10
+ describe('extension command rule', () => {
11
+ it('reads a name with or without one leading slash', () => {
12
+ expect(parseExtensionCommandName('review')).toBe('review');
13
+ expect(parseExtensionCommandName('/review')).toBe('review');
14
+ expect(parseExtensionCommandName('agents:run')).toBe('agents:run');
15
+ expect(parseExtensionCommandName('review.staged')).toBe('review.staged');
16
+ expect(parseExtensionCommandName('a'.repeat(128))).toBe('a'.repeat(128));
17
+ });
18
+
19
+ it('refuses what is not a command name', () => {
20
+ for (const bad of ['', '/', '//review', 'a/b', '..etc', '.hidden', 'run now', 'a'.repeat(129), 3, undefined]) {
21
+ expect(parseExtensionCommandName(bad)).toBeNull();
22
+ }
23
+ });
24
+
25
+ it('keeps arguments to one trimmed line of 2,000 characters', () => {
26
+ expect(normalizeExtensionCommandArgs(' one\ntwo\t')).toBe('one two');
27
+ expect(normalizeExtensionCommandArgs('x'.repeat(3000))).toHaveLength(2000);
28
+ expect(normalizeExtensionCommandArgs(undefined)).toBe('');
29
+ });
30
+
31
+ it('reads a command with its arguments in one string', () => {
32
+ expect(parseExtensionCommandText('/plan on')).toBe('plan on');
33
+ expect(parseExtensionCommandText('review --staged')).toBe('review --staged');
34
+ expect(parseExtensionCommandText('plan')).toBe('plan');
35
+ expect(parseExtensionCommandText('a/b on')).toBeNull();
36
+ expect(commandName('review --staged')).toBe('review');
37
+ });
38
+ });
@@ -1,4 +1,3 @@
1
- export const MAX_EXTENSION_APP_HTML_CHARS = 200_000;
2
1
  const MAX_EXTENSION_FORM_FIELDS = 12;
3
2
  const MAX_EXTENSION_FORM_OPTIONS = 20;
4
3
 
@@ -63,7 +62,7 @@ export const validateExtensionFormValues = (fields, values) => {
63
62
 
64
63
  // ---------------------------------------------------------------- choose()
65
64
  //
66
- // `pichamber.ui.choose(ctx, title, choices, opts)`: one question, a short list of
65
+ // `pichamber.choose(ctx, title, choices, opts)`: one question, a short list of
67
66
  // choices that each have an id, a label and an optional description, and an
68
67
  // optional free-text note. A tool can name its own call (`toolCallId`), so a
69
68
  // plugin's chat component can draw the question beside what the call shows.