@vibesdotdev/integrations-pi 0.0.0-stage → 1.0.0-rc.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 (163) hide show
  1. package/LICENSE +126 -0
  2. package/REFERENCE.md +284 -0
  3. package/dist/extension/active-tools.d.ts +17 -0
  4. package/dist/extension/active-tools.d.ts.map +1 -0
  5. package/dist/extension/active-tools.js +47 -0
  6. package/dist/extension/active-tools.js.map +1 -0
  7. package/dist/extension/approvals.d.ts +26 -0
  8. package/dist/extension/approvals.d.ts.map +1 -0
  9. package/dist/extension/approvals.js +124 -0
  10. package/dist/extension/approvals.js.map +1 -0
  11. package/dist/extension/boot.d.ts +18 -0
  12. package/dist/extension/boot.d.ts.map +1 -0
  13. package/dist/extension/boot.js +129 -0
  14. package/dist/extension/boot.js.map +1 -0
  15. package/dist/extension/chrome.d.ts +33 -0
  16. package/dist/extension/chrome.d.ts.map +1 -0
  17. package/dist/extension/chrome.js +167 -0
  18. package/dist/extension/chrome.js.map +1 -0
  19. package/dist/extension/commands.d.ts +41 -0
  20. package/dist/extension/commands.d.ts.map +1 -0
  21. package/dist/extension/commands.js +47 -0
  22. package/dist/extension/commands.js.map +1 -0
  23. package/dist/extension/entry.d.ts +9 -0
  24. package/dist/extension/entry.d.ts.map +1 -0
  25. package/dist/extension/entry.js +16 -0
  26. package/dist/extension/entry.js.map +1 -0
  27. package/dist/extension/events.d.ts +17 -0
  28. package/dist/extension/events.d.ts.map +1 -0
  29. package/dist/extension/events.js +42 -0
  30. package/dist/extension/events.js.map +1 -0
  31. package/dist/extension/index.d.ts +54 -0
  32. package/dist/extension/index.d.ts.map +1 -0
  33. package/dist/extension/index.js +541 -0
  34. package/dist/extension/index.js.map +1 -0
  35. package/dist/extension/models.d.ts +30 -0
  36. package/dist/extension/models.d.ts.map +1 -0
  37. package/dist/extension/models.js +104 -0
  38. package/dist/extension/models.js.map +1 -0
  39. package/dist/extension/render.d.ts +17 -0
  40. package/dist/extension/render.d.ts.map +1 -0
  41. package/dist/extension/render.js +107 -0
  42. package/dist/extension/render.js.map +1 -0
  43. package/dist/extension/runtime-host.d.ts +6 -0
  44. package/dist/extension/runtime-host.d.ts.map +1 -0
  45. package/dist/extension/runtime-host.js +2 -0
  46. package/dist/extension/runtime-host.js.map +1 -0
  47. package/dist/external/external.plugin.d.ts +7 -0
  48. package/dist/external/external.plugin.d.ts.map +1 -0
  49. package/dist/external/external.plugin.js +44 -0
  50. package/dist/external/external.plugin.js.map +1 -0
  51. package/dist/external/index.d.ts +8 -0
  52. package/dist/external/index.d.ts.map +1 -0
  53. package/dist/external/index.js +8 -0
  54. package/dist/external/index.js.map +1 -0
  55. package/dist/external/pi/bootstrap.d.ts +34 -0
  56. package/dist/external/pi/bootstrap.d.ts.map +1 -0
  57. package/dist/external/pi/bootstrap.js +238 -0
  58. package/dist/external/pi/bootstrap.js.map +1 -0
  59. package/dist/external/pi/guide.d.ts +3 -0
  60. package/dist/external/pi/guide.d.ts.map +1 -0
  61. package/dist/external/pi/guide.js +33 -0
  62. package/dist/external/pi/guide.js.map +1 -0
  63. package/dist/external/pi/index.d.ts +162 -0
  64. package/dist/external/pi/index.d.ts.map +1 -0
  65. package/dist/external/pi/index.js +7 -0
  66. package/dist/external/pi/index.js.map +1 -0
  67. package/dist/external/pi/installer.d.ts +19 -0
  68. package/dist/external/pi/installer.d.ts.map +1 -0
  69. package/dist/external/pi/installer.descriptor.d.ts +373 -0
  70. package/dist/external/pi/installer.descriptor.d.ts.map +1 -0
  71. package/dist/external/pi/installer.descriptor.js +43 -0
  72. package/dist/external/pi/installer.descriptor.js.map +1 -0
  73. package/dist/external/pi/installer.js +82 -0
  74. package/dist/external/pi/installer.js.map +1 -0
  75. package/dist/external/pi/installers/errors.d.ts +16 -0
  76. package/dist/external/pi/installers/errors.d.ts.map +1 -0
  77. package/dist/external/pi/installers/errors.js +15 -0
  78. package/dist/external/pi/installers/errors.js.map +1 -0
  79. package/dist/external/pi/installers/extension.d.ts +16 -0
  80. package/dist/external/pi/installers/extension.d.ts.map +1 -0
  81. package/dist/external/pi/installers/extension.js +292 -0
  82. package/dist/external/pi/installers/extension.js.map +1 -0
  83. package/dist/external/pi/installers/plan.d.ts +29 -0
  84. package/dist/external/pi/installers/plan.d.ts.map +1 -0
  85. package/dist/external/pi/installers/plan.js +391 -0
  86. package/dist/external/pi/installers/plan.js.map +1 -0
  87. package/dist/external/pi/installers/transaction.d.ts +5 -0
  88. package/dist/external/pi/installers/transaction.d.ts.map +1 -0
  89. package/dist/external/pi/installers/transaction.js +66 -0
  90. package/dist/external/pi/installers/transaction.js.map +1 -0
  91. package/dist/external/pi/manifest.d.ts +6 -0
  92. package/dist/external/pi/manifest.d.ts.map +1 -0
  93. package/dist/external/pi/manifest.js +91 -0
  94. package/dist/external/pi/manifest.js.map +1 -0
  95. package/dist/external/pi-presets.d.ts +817 -0
  96. package/dist/external/pi-presets.d.ts.map +1 -0
  97. package/dist/external/pi-presets.js +75 -0
  98. package/dist/external/pi-presets.js.map +1 -0
  99. package/dist/harness/constants.d.ts +46 -0
  100. package/dist/harness/constants.d.ts.map +1 -0
  101. package/dist/harness/constants.js +52 -0
  102. package/dist/harness/constants.js.map +1 -0
  103. package/dist/harness/identity.d.ts +29 -0
  104. package/dist/harness/identity.d.ts.map +1 -0
  105. package/dist/harness/identity.js +40 -0
  106. package/dist/harness/identity.js.map +1 -0
  107. package/dist/harness/index.d.ts +19 -0
  108. package/dist/harness/index.d.ts.map +1 -0
  109. package/dist/harness/index.js +18 -0
  110. package/dist/harness/index.js.map +1 -0
  111. package/dist/harness/managed-block.d.ts +20 -0
  112. package/dist/harness/managed-block.d.ts.map +1 -0
  113. package/dist/harness/managed-block.js +23 -0
  114. package/dist/harness/managed-block.js.map +1 -0
  115. package/dist/harness/pi-naming.d.ts +32 -0
  116. package/dist/harness/pi-naming.d.ts.map +1 -0
  117. package/dist/harness/pi-naming.js +110 -0
  118. package/dist/harness/pi-naming.js.map +1 -0
  119. package/dist/harness/preflight.d.ts +5 -0
  120. package/dist/harness/preflight.d.ts.map +1 -0
  121. package/dist/harness/preflight.js +163 -0
  122. package/dist/harness/preflight.js.map +1 -0
  123. package/dist/harness/prompt.d.ts +14 -0
  124. package/dist/harness/prompt.d.ts.map +1 -0
  125. package/dist/harness/prompt.js +15 -0
  126. package/dist/harness/prompt.js.map +1 -0
  127. package/dist/harness/runtime.d.ts +137 -0
  128. package/dist/harness/runtime.d.ts.map +1 -0
  129. package/dist/harness/runtime.js +53 -0
  130. package/dist/harness/runtime.js.map +1 -0
  131. package/dist/harness/scope.d.ts +11 -0
  132. package/dist/harness/scope.d.ts.map +1 -0
  133. package/dist/harness/scope.js +47 -0
  134. package/dist/harness/scope.js.map +1 -0
  135. package/dist/harness/themes.d.ts +30 -0
  136. package/dist/harness/themes.d.ts.map +1 -0
  137. package/dist/harness/themes.js +225 -0
  138. package/dist/harness/themes.js.map +1 -0
  139. package/dist/index.d.ts +2 -0
  140. package/dist/index.d.ts.map +1 -0
  141. package/dist/index.js +2 -0
  142. package/dist/index.js.map +1 -0
  143. package/dist/schemas/extension-api.d.ts +102 -0
  144. package/dist/schemas/extension-api.d.ts.map +1 -0
  145. package/dist/schemas/extension-api.js +2 -0
  146. package/dist/schemas/extension-api.js.map +1 -0
  147. package/dist/schemas/extension-host.d.ts +11 -0
  148. package/dist/schemas/extension-host.d.ts.map +1 -0
  149. package/dist/schemas/extension-host.js +12 -0
  150. package/dist/schemas/extension-host.js.map +1 -0
  151. package/dist/schemas/extension.d.ts +193 -0
  152. package/dist/schemas/extension.d.ts.map +1 -0
  153. package/dist/schemas/extension.js +82 -0
  154. package/dist/schemas/extension.js.map +1 -0
  155. package/dist/schemas/installer.d.ts +872 -0
  156. package/dist/schemas/installer.d.ts.map +1 -0
  157. package/dist/schemas/installer.js +138 -0
  158. package/dist/schemas/installer.js.map +1 -0
  159. package/dist/themes/vibes-dark.json +63 -0
  160. package/dist/themes/vibes-high-contrast.json +63 -0
  161. package/dist/themes/vibes-light.json +63 -0
  162. package/package.json +110 -4
  163. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,126 @@
1
+ Business Source License 1.1
2
+
3
+ Parameters
4
+
5
+ Licensor: VIBES DEV LLC
6
+ Licensed Work: @vibesdotdev/integrations-pi
7
+ The Licensed Work is (c) 2026 VIBES DEV LLC.
8
+ Additional Use Grant: In this grant, "Vibes Platform" means the hosted services VIBES DEV LLC
9
+ operates at vibes.dev and its subdomains.
10
+
11
+ You may make production use of the Licensed Work, including commercial
12
+ use, subject to the limits below. Permitted production use includes:
13
+ building, operating and selling your own applications, agents and services
14
+ on or with the Vibes Platform; self-hosting the Licensed Work for use inside
15
+ your own organization; and providing consulting, integration or development
16
+ services to clients who build on the Vibes Platform.
17
+
18
+ The production use permitted above does not include use that:
19
+
20
+ (a) offers third parties a hosted, managed or embedded service that
21
+ substitutes for the Vibes Platform or a material part of it (including
22
+ agent hosting; fleet, sandbox or container provisioning; package
23
+ registry; source hosting and continuous integration; and managed AI,
24
+ storage, secrets or messaging), where the Licensed Work provides a
25
+ material part of that service's value and that service earns more than
26
+ US$1,000,000 in gross revenue in any twelve-month period;
27
+ (b) sells, rents, sublicenses or white-labels the Licensed Work, or access
28
+ to Vibes Platform functionality, as a product in its own right;
29
+ (c) removes, disables or works around entitlement checks, usage metering,
30
+ quotas or plan limits, or reaches Vibes Platform features the user's
31
+ account is not entitled to;
32
+ (d) scrapes, bulk-exports or harvests data or content from the Vibes
33
+ Platform or its users other than through documented interfaces and
34
+ within their terms, or uses outputs or data obtained from the Vibes
35
+ Platform to train or improve a product that competes with it;
36
+ (e) violates applicable law, infringes anyone's rights, commits fraud or
37
+ deception, conducts unlawful surveillance or harassment, distributes
38
+ malware, or accesses systems without authorization; or
39
+ (f) violates applicable antitrust or competition law.
40
+
41
+ A written permission from the Licensor extends this grant.
42
+ Change Date: Four years from the date the Licensed Work is published.
43
+ Change License: MIT
44
+
45
+ For information about alternative licensing arrangements for the Licensed Work,
46
+ contact VIBES DEV LLC through https://vibes.dev.
47
+
48
+ Notice
49
+
50
+ The Business Source License (this document, or the "License") is not an Open
51
+ Source license. However, the Licensed Work will eventually be made available
52
+ under an Open Source License, as stated in this License.
53
+
54
+ -----------------------------------------------------------------------------
55
+
56
+ Business Source License 1.1
57
+
58
+ License text copyright © 2017 MariaDB Corporation Ab, All Rights Reserved.
59
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
60
+
61
+ Terms
62
+
63
+ The Licensor hereby grants you the right to copy, modify, create derivative
64
+ works, redistribute, and make non-production use of the Licensed Work. The
65
+ Licensor may make an Additional Use Grant, above, permitting limited
66
+ production use.
67
+
68
+ Effective on the Change Date, or the fourth anniversary of the first publicly
69
+ available distribution of a specific version of the Licensed Work under this
70
+ License, whichever comes first, the Licensor hereby grants you rights under
71
+ the terms of the Change License, and the rights granted in the paragraph
72
+ above terminate.
73
+
74
+ If your use of the Licensed Work does not comply with the requirements
75
+ currently in effect as described in this License, you must purchase a
76
+ commercial license from the Licensor, its affiliated entities, or authorized
77
+ resellers, or you must refrain from using the Licensed Work.
78
+
79
+ All copies of the original and modified Licensed Work, and derivative works
80
+ of the Licensed Work, are subject to this License. This License applies
81
+ separately for each version of the Licensed Work and the Change Date may vary
82
+ for each version of the Licensed Work released by Licensor.
83
+
84
+ You must conspicuously display this License on each original or modified copy
85
+ of the Licensed Work. If you receive the Licensed Work in original or
86
+ modified form from a third party, the terms and conditions set forth in this
87
+ License apply to your use of that work.
88
+
89
+ Any use of the Licensed Work in violation of this License will automatically
90
+ terminate your rights under this License for the current and all other
91
+ versions of the Licensed Work.
92
+
93
+ This License does not grant you any right in any trademark or logo of
94
+ Licensor or its affiliates (provided that you may use a trademark or logo of
95
+ Licensor as expressly required by this License).
96
+
97
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
98
+ AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
99
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
100
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
101
+ TITLE.
102
+
103
+ MariaDB hereby grants you permission to use this License’s text to license
104
+ your works, and to refer to it using the trademark “Business Source License”,
105
+ as long as you comply with the Covenants of Licensor below.
106
+
107
+ Covenants of Licensor
108
+
109
+ In consideration of the right to use this License’s text and the “Business
110
+ Source License” name and trademark, Licensor covenants to MariaDB, and to all
111
+ other recipients of the licensed work to be provided by Licensor:
112
+
113
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
114
+ or a license that is compatible with GPL Version 2.0 or a later version,
115
+ where “compatible” means that software provided under the Change License can
116
+ be included in a program with software provided under GPL Version 2.0 or a
117
+ later version. Licensor may specify additional Change Licenses without
118
+ limitation.
119
+
120
+ 2. To either: (a) specify an additional grant of rights to use that does not
121
+ impose any additional restriction on the right granted in this License, as
122
+ the Additional Use Grant; or (b) insert the text “None”.
123
+
124
+ 3. To specify a Change Date.
125
+
126
+ 4. Not to modify this License in any other way.
package/REFERENCE.md ADDED
@@ -0,0 +1,284 @@
1
+ # Pi extension reference
2
+
3
+ > **Scope.** This document describes what **Pi** can express, read from Pi's own
4
+ > extension documentation and the `ExtensionAPI` declaration it names. The Vibes
5
+ > side — what this package projects, and the decisions behind it — is
6
+ > [`./src/extension/SPEC.md`](./src/extension/SPEC.md). The runtime side is the
7
+ > workspace's `RUNTIME-REFERENCE.md`, regenerated by `vibes runtime export` from
8
+ > the workspace root (this package's checkout is four levels below it, so the link
9
+ > is not relative here). Host census across every harness:
10
+ > [`external/REFERENCE.md`](../../../framework/external/REFERENCE.md).
11
+
12
+ What a Vibes extension can do inside Pi, per Pi's own extension documentation
13
+ and the `ExtensionAPI` declaration in
14
+ `packages/coding-agent/src/core/extensions/types.ts`.
15
+
16
+ Source of truth: [Pi extensions documentation][pi-ext] and the `types.ts` it
17
+ names. This document describes **the host's** capabilities. What Vibes maps onto
18
+ them is [`./src/extension/SPEC.md`](./src/extension/SPEC.md); what Vibes can
19
+ offer is the workspace's `RUNTIME-REFERENCE.md`.
20
+
21
+ Compatibility target: Pi 0.85.x, whose TUI primitives are vendored as
22
+ `@earendil-works/pi-tui@0.85.1`.
23
+
24
+ [pi-ext]: https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/docs/extensions.md
25
+
26
+ ## An extension is a default-exported factory
27
+
28
+ An extension module exports a default factory receiving `ExtensionAPI`. It may
29
+ be synchronous or asynchronous; Pi awaits an async factory before startup
30
+ continues, so an async factory is the right place to fetch configuration or
31
+ register providers needed during startup.
32
+
33
+ ```ts
34
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
35
+ export default function (pi: ExtensionAPI) {
36
+ pi.registerCommand("hello", {
37
+ description: "Show a greeting",
38
+ handler: async (name, ctx) => { ctx.ui.notify(`Hello, ${name || "world"}!`, "info"); },
39
+ });
40
+ }
41
+ ```
42
+
43
+ Pi loads `.ts` directly through `jiti`; no build step is required for a local
44
+ extension. Extensions live in a user or project extensions directory, as a single
45
+ file or a directory with an `index.ts` entry point.
46
+
47
+ **Lifecycle.** Do not start processes, sockets, watchers or timers in the factory:
48
+ some invocations load extensions without starting a session. Start long-lived
49
+ resources from `session_start`, and release them in an idempotent
50
+ `session_shutdown`. A run proceeds `input` and `before_agent_start` → model,
51
+ message and tool events → `agent_end`; retries, compaction or queued work may
52
+ continue afterwards.
53
+
54
+ ## `ExtensionAPI`: everything an extension can call
55
+
56
+ ### Events
57
+
58
+ `pi.on(event, handler)` returns an unsubscribe function. Handlers run in
59
+ extension load and registration order. Some events notify; others transform data,
60
+ replace results, or cancel an operation.
61
+
62
+ **Startup and resources**
63
+
64
+ | Event | Payload | Can do |
65
+ | --- | --- | --- |
66
+ | `project_trust` | `{ cwd }` | Decide trust: `yes`, `no`, `undecided`, optionally remember. Personal and explicit CLI extensions only; runs before project extensions load |
67
+ | `resources_discover` | `{ cwd, reason }` | Contribute `skillPaths`, `promptPaths`, `themePaths` |
68
+ | `mcp_servers_change` | `{ servers }` | Observe servers extensions registered |
69
+
70
+ **Session**
71
+
72
+ | Event | Payload | Can do |
73
+ | --- | --- | --- |
74
+ | `session_start` | `{ reason: startup\|reload\|new\|resume\|fork, previousSessionFile? }` | Bind a session; the point where a runtime boots |
75
+ | `session_info_changed` | `{ name }` | Observe the session name |
76
+ | `session_before_switch` | `{ reason, targetSessionFile? }` | Cancel the switch |
77
+ | `session_before_fork` | `{ entryId, position }` | Cancel the fork |
78
+ | `session_before_compact` | `{ preparation, branchEntries, reason, willRetry, signal }` | Cancel or customize compaction |
79
+ | `session_compact` | `{ compactionEntry, fromExtension, reason, willRetry }` | Observe success |
80
+ | `session_compact_failed` | `{ reason, errorMessage?, aborted, willRetry, fromExtension }` | Observe failure |
81
+ | `session_shutdown` | `{ reason: quit\|reload\|new\|resume\|fork, targetSessionFile? }` | Release resources; idempotent |
82
+ | `session_tree` | `{ newLeafId, oldLeafId, summaryEntry?, fromExtension? }` | Observe tree navigation |
83
+
84
+ **Agent and turn**
85
+
86
+ | Event | Payload | Can do |
87
+ | --- | --- | --- |
88
+ | `context` | `{ messages }` | Transform conversation messages. Pi restores prompt and tool state afterwards |
89
+ | `context_with_system` | `{ messages }` | Own the **complete** transcript, system messages included. Keep a system message at index 0 |
90
+ | `before_agent_start` | `{ prompt, images?, systemPrompt, systemPromptOptions }` | Mutate prompt sections; return `{ message? }`, or `{ systemPrompt }` to replace the whole prompt for that run |
91
+ | `agent_start` / `agent_end` | `{}` / `{ messages }` | Observe the loop |
92
+ | `agent_before_settle` | boundary state | Append entries and request **one** continuation by returning `{ entries?, continue: true }`. Guard against loops |
93
+ | `agent_settled` | `{ aborted }` | Final, notification-only |
94
+ | `turn_start` | `{ turnIndex, timestamp }` | Observe turn start |
95
+ | `turn_end` | `{ turnIndex, message, toolResults, messageEntryId, toolResultEntryIds }` | Same boundary shape as `agent_before_settle` |
96
+ | `ui_prompt_start` / `ui_prompt_end` | `{ reason, kind, title? }` | Observe blocking UI |
97
+
98
+ **Message and tool execution**
99
+
100
+ | Event | Payload | Can do |
101
+ | --- | --- | --- |
102
+ | `message_start` / `message_update` / `message_end` | message | Observe; `message_end` may **replace** the finalized message, keeping its role |
103
+ | `tool_execution_start` | `{ toolCallId, toolName, args, parentToolCallId? }` | Observe |
104
+ | `tool_execution_update` | `{ toolCallId, toolName, partialResult, parentToolCallId? }` | Observe partial output |
105
+ | `tool_execution_end` | `{ toolCallId, toolName, result, isError, durationMs?, parentToolCallId? }` | Observe completion |
106
+ | `tool_call` | typed per built-in, or `{ toolName, input }` | Mutate `event.input` **in place**, or block by returning `{ block: true, reason? }`. `terminate: true` skips follow-up |
107
+ | `tool_result` | typed per built-in | Return `{ content?, details?, structuredContent?, isError?, usage? }`. Redacting `content` should replace `structuredContent` too |
108
+
109
+ **Model and provider**
110
+
111
+ | Event | Payload | Can do |
112
+ | --- | --- | --- |
113
+ | `model_select` | `{ model, previousModel, source: set\|cycle\|restore }` | Observe |
114
+ | `thinking_level_select` | `{ level, previousLevel }` | Observe |
115
+ | `before_provider_request` | `{ payload }` | Replace the provider payload |
116
+ | `before_provider_headers` | `{ headers }` | Mutate headers **in place**; `null` deletes a header. Return value ignored |
117
+ | `after_provider_response` | `{ status, headers }` | Observe |
118
+ | `provider_stream_event` | `{ provider, api, model, data }` | Observe each parsed stream event before normalization. Read-only, awaited in stream order, not persisted |
119
+
120
+ **User input and shell**
121
+
122
+ | Event | Payload | Can do |
123
+ | --- | --- | --- |
124
+ | `user_bash` | `{ command, excludeFromContext, cwd }` | Handle: return `{ operations }` to execute, or `{ result }` to answer. `undefined` passes through |
125
+ | `input` | `{ text, images?, source, streamingBehavior? }` | Return `{ action: 'continue' \| 'transform' \| 'handled' }` |
126
+ | `cache_warming_decision` | cache warmer event | Override with `{ action: 'warm' }` or `{ action: 'stop' }`; last handler wins |
127
+
128
+ ### Registration
129
+
130
+ | Method | Signature | What it does |
131
+ | --- | --- | --- |
132
+ | `registerTool` | `(tool: ToolDefinition) => void` | Add a model-callable tool |
133
+ | `registerCommand` | `(name, { description?, handler }) => void` | Add a `/` command |
134
+ | `registerShortcut` | `(KeyId, { description?, handler }) => void` | Add a keyboard shortcut |
135
+ | `registerFlag` | `(name, { type: 'boolean' \| 'string', default?, description? }) => void` | Add a CLI flag |
136
+ | `getFlag` | `(name) => boolean \| string \| undefined` | Read a registered flag |
137
+ | `registerProvider` | `(Provider)` or `(name, ProviderConfig)` | Add a model provider |
138
+ | `unregisterProvider` | `(name) => void` | Remove one |
139
+ | `registerVirtualModel` | `(definition)` | Add a model router |
140
+ | `unregisterVirtualModel` | `(provider, id) => void` | Remove one |
141
+ | `registerMcpServer` | `(name, McpServerConfig) => void` | Add an MCP server |
142
+ | `unregisterMcpServer` | `(name) => void` | Remove one and close it |
143
+ | `getMcpServers` | `() => RegisteredMcpServer[]` | List servers extensions registered |
144
+ | `registerMessageRenderer` | `(customType, renderer) => void` | Render a `CustomMessageEntry` |
145
+ | `registerEntryRenderer` | `(customType, renderer) => void` | Render a `CustomEntry` (not sent to the model) |
146
+ | `registerMarkdownTransformer` | `(transformer) => void` | Transform user/assistant markdown before rendering |
147
+ | `registerToolRenderer` | `(resolver) => void` | Choose how tool calls are drawn, including unregistered tools |
148
+
149
+ ### Session control
150
+
151
+ | Method | Signature | What it does |
152
+ | --- | --- | --- |
153
+ | `getActiveTools` | `() => string[]` | Names declared to the model |
154
+ | `setActiveTools` | `(names) => void` | Change the active set |
155
+ | `getAllTools` | `() => ToolInfo[]` | Every configured tool, with exposure, namespace, annotations |
156
+ | `getCommands` | `() => SlashCommandInfo[]` | Slash commands in this session |
157
+ | `getSettings` | `() => Settings` | Effective merged settings |
158
+ | `setModel` | `(model) => Promise<boolean>` | Switch model |
159
+ | `getThinkingLevel` / `setThinkingLevel` | | Read or set thinking level |
160
+ | `setSessionName` / `getSessionName` | `(name?) => void / string \| undefined` | Session display name |
161
+ | `setLabel` | `(entryId, label \| undefined) => void` | Bookmark an entry |
162
+
163
+ ### Messages and state
164
+
165
+ | Method | Signature | What it does |
166
+ | --- | --- | --- |
167
+ | `sendUserMessage` | `(content, { deliverAs?, expandPromptTemplates? })` | Send a user message to the session |
168
+ | `sendMessage` | `(message, { triggerTurn?, deliverAs? })` | Send a custom message |
169
+ | `appendEntry` | `(entry)` | Persist state that is **not** sent to the model |
170
+ | `exec` | `(command, args, options?) => Promise<ExecResult>` | Execute a shell command |
171
+ | `events` | shared bus | Communicate with other extensions |
172
+
173
+ Where state belongs: branch-following tool state goes in the tool result's
174
+ `details`; durable data excluded from context goes through `appendEntry`;
175
+ model-visible custom content goes through `sendMessage`; anything outside one
176
+ session goes to external storage.
177
+
178
+ ## Tool definitions
179
+
180
+ ```ts
181
+ interface ToolDefinition<TParams, TDetails, TState> {
182
+ name: string; label: string; description: string;
183
+ promptSnippet?: string; // one line in the "Available tools" prompt section
184
+ promptGuidelines?: string[]; // bullets appended when the tool is active
185
+ parameters: TParams; // TypeBox schema
186
+ outputSchema?: TSchema; // JSON Schema of structuredContent
187
+ constrainedSampling?: false | ConstrainedSamplingConfig;
188
+ renderShell?: "default" | "self";
189
+ exposure?: "direct" | "model-only" | "codemode" | "deferred" | "hidden";
190
+ namespace?: { name, description?, instructions? };
191
+ annotations?: { readOnlyHint?, destructiveHint?, idempotentHint?, openWorldHint? };
192
+ defaultActive?: boolean;
193
+ executionMode?: "sequential" | "parallel";
194
+ prepareArguments?: (args: unknown) => Static<TParams>;
195
+ prepareLoadout?: (loadout: ToolLoadout) => ToolLoadoutChanges | undefined;
196
+ execute(toolCallId, params, signal, onUpdate, ctx): Promise<AgentToolResult<TDetails>>;
197
+ renderCall?(args, theme, context): Component;
198
+ renderResult?(result, options, theme, context): Component;
199
+ }
200
+ ```
201
+
202
+ ### Tool exposure — how the model reaches a tool
203
+
204
+ | Exposure | Declared to the model | Callable by other tools | Activated on registration |
205
+ | --- | --- | --- | --- |
206
+ | `direct` (default) | while active | while active | yes |
207
+ | `model-only` | while active | never | yes |
208
+ | `codemode` | only if activated explicitly | always | no |
209
+ | `deferred` | only if activated explicitly | always; **not** listed by codemode, findable via `tool_search` | no |
210
+ | `hidden` | never | never | no |
211
+
212
+ This is the mechanism that lets a Vibes projection register 127 tools without
213
+ spending 127 tool schemas of prompt budget: register everything as `codemode`,
214
+ activate only the discovery tools, and let `tool_search` add tools on demand.
215
+
216
+ ### Nested tool calls
217
+
218
+ `ctx.executeTool(name, args, { signal?, onUpdate? })` runs another tool through
219
+ the same validation, hooks and permission checks as a model-issued call. It
220
+ never rejects for tool failure: unknown tools, validation errors, blocked calls
221
+ and thrown errors all come back as `isError: true`. Nested calls do not appear
222
+ in the transcript; a bounded `nestedCalls` record is kept on the calling tool's
223
+ result.
224
+
225
+ ## Contexts
226
+
227
+ `ExtensionContext` is available to every handler: `ui`, `mode`, `hasUI`, `cwd`,
228
+ `sessionManager`, `modelRegistry`, `model`, `scopedModels`, `thinkingLevel`,
229
+ `isIdle()`, `isProjectTrusted()`, `signal`, `abort()`, `hasPendingMessages()`,
230
+ `shutdown()`, `getContextUsage()`, `compact()`, `getSystemPrompt()`.
231
+
232
+ `ExtensionToolContext` adds `tools` and `executeTool`.
233
+ `ExtensionCommandContext` adds `getSystemPromptOptions()`, `waitForIdle()`,
234
+ `newSession()`, `fork()`, `navigateTree()`, `switchSession()`, `reload()`.
235
+
236
+ The command-only operations are command-only because calling them from a
237
+ lifecycle handler can deadlock the runtime.
238
+
239
+ ## UI
240
+
241
+ `ctx.ui` provides: `select`, `confirm`, `input`, `editor`, `custom`, `notify`,
242
+ `setStatus`, `setWorkingMessage`, `setWorkingVisible`, `setWorkingIndicator`,
243
+ `setHiddenThinkingLabel`, `setWidget`, `setFooter`, `setHeader`, `setTitle`,
244
+ `pasteToEditor`, `setEditorText`, `getEditorText`, `addAutocompleteProvider`,
245
+ `setEditorComponent`, `getEditorComponent`, `theme`, `getAllThemes`,
246
+ `getTheme`, `setTheme`, `getToolsExpanded`, `setToolsExpanded`, and
247
+ `onTerminalInput`.
248
+
249
+ Extensions load in four modes: `tui`, `rpc`, `json`, `print`. Only `tui` has the
250
+ full terminal UI; `rpc` can forward supported dialogs but not custom components;
251
+ `json` and `print` have no UI at all. Guard terminal-only behaviour with
252
+ `ctx.mode === 'tui'` and use `ctx.hasUI` for what `tui` and `rpc` share.
253
+
254
+ ## What a Vibes runtime offers to map onto this
255
+
256
+ | Vibes kind | Pi surface | Notes |
257
+ | --- | --- | --- |
258
+ | `tools/tool` | `registerTool` | One tool per descriptor; canonical id projected to a provider-safe name |
259
+ | `cli/command` | `registerCommand` | One command per descriptor; the handler executes it in the runtime |
260
+ | `prompts/manifest` | `before_agent_start` | Mutate prompt sections, or replace `systemPrompt` for the run |
261
+ | `ai/provider` | `registerProvider`, `registerVirtualModel` | Provider identity and routing |
262
+ | `ai/model` | `setModel`, `scopedModels` | Model selection, not a catalog |
263
+ | `agents` | — | No roster surface; see below |
264
+ | `runtime/event` | `pi.on(...)` | Vibes events into Pi's lifecycle |
265
+ | `cli/command` | `registerCommand` | One command per descriptor |
266
+
267
+ ### Why `ai/model` and `agents` have no surface here
268
+
269
+ Pi exposes **model selection, not a model catalog**. `setModel(model)` switches
270
+ the session's model and `scopedModels` is a read-only snapshot of what `--models`
271
+ already scoped; neither is a place to publish a registry. A Vibes `ai/model`
272
+ descriptor therefore has nowhere to go: Pi's provider list is the union of what
273
+ its own packages and `mcp.json` contribute, not something an extension declares.
274
+
275
+ `agents` is the same shape of absence. An extension can register a flag or a
276
+ command, but there is no API that enumerates or selects agents, so a Vibes roster
277
+ has no surface to project into. Both kinds are queryable from the runtime — a host
278
+ that grows a catalog surface can map them then.
279
+
280
+ ### Pi built-ins a projection must not shadow
281
+
282
+ `read`, `bash`, `edit`, `write`, `grep`, `find`, `ls`. Pi tool names must match
283
+ `[a-zA-Z0-9_-]+` for providers such as Bedrock, so a canonical dotted id is
284
+ projected to underscores: `workspace-fs` → `workspace_fs`.
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Pi only sends *active* tool schemas to the model. Registering the live
3
+ * catalog is required; activating all 100+ schemas overflows host context
4
+ * windows. Discovery tools stay active; search results are added additively.
5
+ */
6
+ import { type PiCatalogEntry } from '../harness/pi-naming.ts';
7
+ /** Capability-bridge tools the model should see on the first request. */
8
+ export declare const PI_INITIAL_TOOL_IDS: readonly ["tool-search", "tool-help", "tool-call", "workspace-fs", "session"];
9
+ export type PiActiveToolHost = {
10
+ getActiveTools?: () => string[];
11
+ setActiveTools?: (names: string[]) => void;
12
+ };
13
+ export declare function initialPiToolNames(entries: readonly PiCatalogEntry[]): string[];
14
+ export declare function restrictPiToolsToDiscovery(pi: PiActiveToolHost, entries: readonly PiCatalogEntry[]): string[] | undefined;
15
+ export declare function piNamesFromSearchOutput(text: string, idToName: ReadonlyMap<string, string>): string[];
16
+ export declare function activatePiSearchHits(pi: PiActiveToolHost, text: string, idToName: ReadonlyMap<string, string>): string[];
17
+ //# sourceMappingURL=active-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"active-tools.d.ts","sourceRoot":"","sources":["../../src/extension/active-tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE5E,yEAAyE;AACzE,eAAO,MAAM,mBAAmB,+EAAgF,CAAC;AAEjH,MAAM,MAAM,gBAAgB,GAAG;IAC9B,cAAc,CAAC,EAAE,MAAM,MAAM,EAAE,CAAC;IAChC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,EAAE,CAG/E;AAED,wBAAgB,0BAA0B,CACzC,EAAE,EAAE,gBAAgB,EACpB,OAAO,EAAE,SAAS,cAAc,EAAE,GAChC,MAAM,EAAE,GAAG,SAAS,CAQtB;AAED,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACnC,MAAM,EAAE,CAOV;AAED,wBAAgB,oBAAoB,CACnC,EAAE,EAAE,gBAAgB,EACpB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACnC,MAAM,EAAE,CASV"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Pi only sends *active* tool schemas to the model. Registering the live
3
+ * catalog is required; activating all 100+ schemas overflows host context
4
+ * windows. Discovery tools stay active; search results are added additively.
5
+ */
6
+ import { PiJsonTextSchema, PiSearchResultSchema } from "../schemas/extension.js";
7
+ import { toPiToolName } from "../harness/pi-naming.js";
8
+ /** Capability-bridge tools the model should see on the first request. */
9
+ export const PI_INITIAL_TOOL_IDS = ['tool-search', 'tool-help', 'tool-call', 'workspace-fs', 'session'];
10
+ export function initialPiToolNames(entries) {
11
+ const wanted = new Set(PI_INITIAL_TOOL_IDS);
12
+ return entries.filter((entry) => wanted.has(entry.id)).map((entry) => entry.name);
13
+ }
14
+ export function restrictPiToolsToDiscovery(pi, entries) {
15
+ const discovery = initialPiToolNames(entries);
16
+ if (discovery.length === 0 || !pi.setActiveTools || !pi.getActiveTools)
17
+ return undefined;
18
+ const vibes = new Set(entries.map((entry) => entry.name));
19
+ const kept = pi.getActiveTools().filter((name) => !vibes.has(name));
20
+ const next = [...new Set([...kept, ...discovery])];
21
+ pi.setActiveTools(next);
22
+ return next;
23
+ }
24
+ export function piNamesFromSearchOutput(text, idToName) {
25
+ const json = PiJsonTextSchema.safeParse(text);
26
+ if (!json.success)
27
+ return [];
28
+ const result = PiSearchResultSchema.safeParse(json.data);
29
+ if (!result.success)
30
+ return [];
31
+ const names = result.data.matches.map(({ toolId }) => idToName.get(toolId) ?? toPiToolName(toolId));
32
+ return names;
33
+ }
34
+ export function activatePiSearchHits(pi, text, idToName) {
35
+ if (!pi.setActiveTools || !pi.getActiveTools)
36
+ return [];
37
+ const hits = piNamesFromSearchOutput(text, idToName);
38
+ if (hits.length === 0)
39
+ return [];
40
+ const active = pi.getActiveTools();
41
+ const added = hits.filter((name) => !active.includes(name));
42
+ if (added.length === 0)
43
+ return [];
44
+ pi.setActiveTools([...new Set([...active, ...added])]);
45
+ return added;
46
+ }
47
+ //# sourceMappingURL=active-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"active-tools.js","sourceRoot":"","sources":["../../src/extension/active-tools.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,26 @@
1
+ import { BaseRuntimeClient } from '@vibesdotdev/kernel/client';
2
+ import { type RuntimeRef } from '@vibesdotdev/kernel';
3
+ import type { RuntimePath } from '@vibesdotdev/paths';
4
+ import { type PiObject, type PiJson, type ApprovalScope, type ApprovalPosture } from '../schemas/extension.ts';
5
+ export type { ApprovalScope, ApprovalPosture } from '../schemas/extension.ts';
6
+ export type ApprovalNotifier = {
7
+ notify?(message: string, type?: 'info' | 'warning' | 'error'): void;
8
+ };
9
+ export declare function approvalPosture(env: Readonly<Record<string, string | undefined>>, notifier?: ApprovalNotifier): ApprovalPosture;
10
+ export declare function dangerReason(toolName: string, action: string, input: PiObject | undefined, cwd: string, workspaceRoot: string | undefined, paths: RuntimePath): string | undefined;
11
+ /** Pi-specific grants are owned by the resolving runtime and never shared across workspaces. */
12
+ export declare class ApprovalMemory extends BaseRuntimeClient {
13
+ private readonly session;
14
+ get cwd(): string;
15
+ get vibesHome(): string;
16
+ lookup(key: string): Promise<boolean>;
17
+ isApproved(tool: string, action?: string): Promise<boolean>;
18
+ clearSession(): void;
19
+ protected onDispose(): void;
20
+ grant(scope: ApprovalScope, key: string): Promise<void>;
21
+ workspaceGrants(): Promise<string[]>;
22
+ repoGrants(): Promise<string[]>;
23
+ }
24
+ export declare function getPiApprovalMemory(runtime: RuntimeRef): Promise<ApprovalMemory>;
25
+ export declare function stableJson(value: PiJson): string;
26
+ //# sourceMappingURL=approvals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approvals.d.ts","sourceRoot":"","sources":["../../src/extension/approvals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAuC,MAAM,4BAA4B,CAAC;AACpG,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAEN,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,KAAK,eAAe,EACpE,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE9E,MAAM,MAAM,gBAAgB,GAAG;IAAE,MAAM,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,IAAI,CAAA;CAAE,CAAC;AAEvG,wBAAgB,eAAe,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,gBAAgB,GAAG,eAAe,CAK/H;AAcD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAYlL;AAED,gGAAgG;AAChG,qBAAa,cAAe,SAAQ,iBAAiB;IACpD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,IAAI,GAAG,IAAI,MAAM,CAIhB;IACD,IAAI,SAAS,IAAI,MAAM,CAAiD;IAClE,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKrC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAGjE,YAAY,IAAI,IAAI;cACD,SAAS,IAAI,IAAI;IAC9B,KAAK,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBvD,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IASpC,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAMrC;AACD,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAOtF;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD"}
@@ -0,0 +1,124 @@
1
+ import { BaseRuntimeClient, getVibesClient, runtimeClientPlugin } from '@vibesdotdev/kernel/client';
2
+ import { CapabilityError } from '@vibesdotdev/kernel';
3
+ import { getRuntimePath, getPathRoots } from '@vibesdotdev/paths';
4
+ import { resolveFileSystemAdapter } from '@vibesdotdev/filesystem';
5
+ import { readPiText } from "../harness/runtime.js";
6
+ import { PiActionInputSchema, PiWorkspaceGrantsSchema, PiRepoGrantsSchema } from "../schemas/extension.js";
7
+ export function approvalPosture(env, notifier) {
8
+ const raw = (env.VIBES_PI_APPROVAL ?? 'smart').trim().toLowerCase();
9
+ if (raw === 'strict' || raw === 'off')
10
+ return raw;
11
+ if (raw !== 'smart')
12
+ notifier?.notify?.('Unknown VIBES_PI_APPROVAL; using smart.', 'warning');
13
+ return 'smart';
14
+ }
15
+ const DANGEROUS_ACTIONS = new Set(['deploy', 'publish', 'install', 'destroy']);
16
+ const OUTSIDE_ACTIONS = new Set(['write', 'edit', 'delete', 'remove']);
17
+ const BASH_DANGER_PATTERNS = [
18
+ [/\brm\s+(?:\S+\s+)*-\w*[rf]\w*\b/, 'rm with -r/-f'],
19
+ [/\bgit\s+push\b[^\n]*(?:--force\b|--force-with-lease\b|\s-f\b)/, 'git push --force'],
20
+ [/\bsudo\b/, 'sudo'],
21
+ [/\b(?:curl|wget)\b[^|\n]*\|\s*(?:sudo\s+)?(?:ba|z|k|da)?sh\b/, 'piped remote script']
22
+ ];
23
+ function outside(paths, target, cwd) {
24
+ const rel = paths.relative(paths.resolve(cwd), paths.resolve(cwd, target));
25
+ return rel === '..' || rel.startsWith('../') || rel.startsWith('..\\') || paths.isAbsolute(rel);
26
+ }
27
+ export function dangerReason(toolName, action, input, cwd, workspaceRoot, paths) {
28
+ const fields = PiActionInputSchema.parse(input ?? {});
29
+ if (toolName === 'bash' || toolName === 'workspace_exec') {
30
+ for (const [pattern, label] of BASH_DANGER_PATTERNS)
31
+ if (pattern.test(fields.command ?? ''))
32
+ return label;
33
+ }
34
+ if (toolName === 'workspace_destroy' || DANGEROUS_ACTIONS.has(action))
35
+ return 'destructive or external action';
36
+ const target = fields.path ?? fields.file_path ?? fields.file ?? fields.destination ?? fields.target;
37
+ if (OUTSIDE_ACTIONS.has(action) && target) {
38
+ const root = workspaceRoot && !outside(paths, cwd, workspaceRoot) ? workspaceRoot : cwd;
39
+ if (outside(paths, target, root))
40
+ return 'path outside workspace';
41
+ }
42
+ return undefined;
43
+ }
44
+ /** Pi-specific grants are owned by the resolving runtime and never shared across workspaces. */
45
+ export class ApprovalMemory extends BaseRuntimeClient {
46
+ session = new Set();
47
+ get cwd() {
48
+ const root = this.runtime.scope?.workspace?.root;
49
+ if (!root)
50
+ throw new CapabilityError('Pi approvals require a bound workspace.', 'UNAVAILABLE', { reason: 'pi-workspace-required' });
51
+ return root;
52
+ }
53
+ get vibesHome() { return getPathRoots(this.runtime).vibesHome; }
54
+ async lookup(key) {
55
+ const alt = key.includes('_') ? key.replaceAll('_', '-') : key.replaceAll('-', '_');
56
+ const grants = [...this.session, ...await this.workspaceGrants(), ...await this.repoGrants()];
57
+ return grants.includes(key) || grants.includes(alt);
58
+ }
59
+ async isApproved(tool, action) {
60
+ return await this.lookup('*') || await this.lookup(tool) || (action ? await this.lookup(tool + ':' + action) : false);
61
+ }
62
+ clearSession() { this.session.clear(); }
63
+ onDispose() { this.session.clear(); }
64
+ async grant(scope, key) {
65
+ const paths = await getRuntimePath(this.runtime);
66
+ const fs = await resolveFileSystemAdapter(this.runtime, { binding: false });
67
+ if (scope === 'session') {
68
+ this.session.add(key);
69
+ return;
70
+ }
71
+ const file = scope === 'workspace' ? paths.join(this.vibesHome, 'pi-approvals.json') : paths.join(this.cwd, '.pi', 'approvals.json');
72
+ const raw = await readPiText(fs, file);
73
+ let content;
74
+ if (scope === 'workspace') {
75
+ const grants = PiWorkspaceGrantsSchema.parse(raw === undefined ? {} : JSON.parse(raw));
76
+ grants[this.cwd] = [...new Set([...(grants[this.cwd] ?? []), key])].sort();
77
+ content = stableJson(grants);
78
+ }
79
+ else {
80
+ const grants = PiRepoGrantsSchema.parse(raw === undefined ? {} : JSON.parse(raw));
81
+ content = stableJson({ grants: [...new Set([...grants.grants, key])].sort() });
82
+ }
83
+ await fs.mkdir(paths.dirname(file), { recursive: true });
84
+ await fs.writeFile(file, content);
85
+ this.session.add(key);
86
+ }
87
+ async workspaceGrants() {
88
+ const paths = await getRuntimePath(this.runtime);
89
+ const fs = await resolveFileSystemAdapter(this.runtime, { binding: false });
90
+ const raw = await readPiText(fs, paths.join(this.vibesHome, 'pi-approvals.json'));
91
+ const grants = PiWorkspaceGrantsSchema.parse(raw === undefined ? {} : JSON.parse(raw));
92
+ if (grants[this.cwd])
93
+ return grants[this.cwd];
94
+ const parent = Object.keys(grants).filter(root => !outside(paths, this.cwd, root)).sort((a, b) => b.length - a.length)[0];
95
+ return parent ? grants[parent] ?? [] : [];
96
+ }
97
+ async repoGrants() {
98
+ const paths = await getRuntimePath(this.runtime);
99
+ const fs = await resolveFileSystemAdapter(this.runtime, { binding: false });
100
+ const raw = await readPiText(fs, paths.join(this.cwd, '.pi', 'approvals.json'));
101
+ return PiRepoGrantsSchema.parse(raw === undefined ? {} : JSON.parse(raw)).grants;
102
+ }
103
+ }
104
+ export async function getPiApprovalMemory(runtime) {
105
+ if (!runtime.hasKind('runtime/client'))
106
+ await runtime.registerPlugin(runtimeClientPlugin);
107
+ if (!runtime.query('runtime/client').withId('integrations-pi.approvals').descriptors().length) {
108
+ runtime.registerDescriptor('runtime/client', { kind: 'runtime/client', id: 'integrations-pi.approvals' });
109
+ runtime.registerLoader('runtime/client', 'integrations-pi.approvals', async () => ({ impl: ApprovalMemory }));
110
+ }
111
+ return getVibesClient('integrations-pi.approvals', runtime);
112
+ }
113
+ export function stableJson(value) {
114
+ return JSON.stringify(sortKeys(value), null, 2) + '\n';
115
+ }
116
+ function sortKeys(value) {
117
+ if (Array.isArray(value))
118
+ return [...value].sort();
119
+ if (value !== null && value instanceof Object) {
120
+ return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => [key, sortKeys(item)]));
121
+ }
122
+ return value;
123
+ }
124
+ //# sourceMappingURL=approvals.js.map