eve 0.88.0 → 0.89.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 (60) hide show
  1. package/CHANGELOG.md +10 -21
  2. package/dist/src/channel/interaction-prompts.d.ts +0 -2
  3. package/dist/src/channel/interaction-prompts.js +1 -1
  4. package/dist/src/chunks/{use-eve-agent-BExXjBv6.js → use-eve-agent-Bbl4H5aA.js} +19 -2
  5. package/dist/src/chunks/{use-eve-agent-C0KHCyb9.js → use-eve-agent-CNpxgKEH.js} +19 -2
  6. package/dist/src/client/conversation.js +1 -1
  7. package/dist/src/client/transcript.d.ts +7 -4
  8. package/dist/src/client/transcript.js +1 -1
  9. package/dist/src/compiled/.vendor-stamp.json +3 -3
  10. package/dist/src/execution/dynamic-workflow/tool.js +1 -1
  11. package/dist/src/execution/tools/agent-router-workflow.js +1 -1
  12. package/dist/src/extensions/git/extension/extension.d.ts +12 -9
  13. package/dist/src/extensions/git/extension/extension.js +1 -1
  14. package/dist/src/extensions/git/extension/lib/gh-tool.d.ts +4 -12
  15. package/dist/src/extensions/git/extension/lib/gh-tool.js +1 -1
  16. package/dist/src/extensions/git/extension/lib/github-guidance.js +4 -4
  17. package/dist/src/extensions/git/extension/lib/github-shell-schema.d.ts +3 -5
  18. package/dist/src/extensions/git/extension/lib/github-shell-schema.js +1 -1
  19. package/dist/src/extensions/git/extension/lib/github-shell.d.ts +31 -21
  20. package/dist/src/extensions/git/extension/lib/github-shell.js +1 -1
  21. package/dist/src/extensions/git/extension/lib/signed-commit.js +1 -1
  22. package/dist/src/extensions/git/tools.d.ts +2 -10
  23. package/dist/src/instrumentation/content.js +1 -1
  24. package/dist/src/instrumentation/lifecycle.d.ts +5 -0
  25. package/dist/src/instrumentation/native-events.d.ts +4 -1
  26. package/dist/src/instrumentation/native-events.js +1 -1
  27. package/dist/src/instrumentation/principal-summary.d.ts +2 -0
  28. package/dist/src/instrumentation/principal-summary.js +1 -1
  29. package/dist/src/instrumentation/runtime.js +1 -1
  30. package/dist/src/instrumentation/session-context.js +1 -1
  31. package/dist/src/internal/application/stamped-package-version.js +1 -1
  32. package/dist/src/internal/invocation/agent-invocation.d.ts +2 -0
  33. package/dist/src/internal/invocation/workflow-execution.js +1 -1
  34. package/dist/src/protocol/session-events/families/delivery.d.ts +3 -2
  35. package/dist/src/protocol/session-projection/reader.d.ts +3 -1
  36. package/dist/src/protocol/session-projection/reader.js +1 -1
  37. package/dist/src/public/channels/mcp.js +1 -1
  38. package/dist/src/public/channels/slack/request-cards.js +2 -2
  39. package/dist/src/runtime/subagents/workflow.js +1 -1
  40. package/dist/src/setup/scaffold/create/project.js +1 -1
  41. package/dist/src/shared/session-history.d.ts +4 -2
  42. package/dist/src/shared/session-history.js +1 -1
  43. package/dist/src/svelte/index.js +1 -1
  44. package/dist/src/svelte/use-eve-agent.js +1 -1
  45. package/dist/src/tools/provided/ask-question-workflow.js +1 -1
  46. package/dist/src/tools/provided/sleep-workflow.js +1 -1
  47. package/dist/src/tracing/eve/agent-approval-instrumentation.js +1 -1
  48. package/dist/src/tracing/eve/session.js +1 -1
  49. package/dist/src/vue/index.js +1 -1
  50. package/dist/src/vue/use-eve-agent.js +1 -1
  51. package/docs/channels/eve.mdx +1 -1
  52. package/docs/channels/mcp.mdx +1 -1
  53. package/docs/code-extension.mdx +17 -60
  54. package/docs/concepts/execution-model-and-durability.mdx +1 -1
  55. package/docs/concepts/sessions-runs-and-streaming.md +3 -1
  56. package/docs/guides/client/streaming.mdx +1 -1
  57. package/docs/guides/frontend/use-eve-agent.mdx +1 -1
  58. package/docs/guides/instrumentation/instrumentation.mdx +1 -1
  59. package/docs/tools/human-in-the-loop.md +2 -0
  60. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,25 +1,14 @@
1
- # Release eve@0.88.0 | 2026-10-29 | minor
1
+ # eve 0.89.0
2
2
 
3
- ## 🚀 Features
3
+ Released 2026-10-29 · [Compare with 0.88.1](https://github.com/vercel/eve/compare/eve%400.88.1...eve%400.89.0)
4
4
 
5
- - `git({ github })` now requires an `authorize` callback as its only repository access control, drops `org`, and adds `principalType: "user"` to run `gh` commands with the caller's own GitHub permissions. [#5562](https://github.com/vercel/eve/pull/5562)
5
+ ## Breaking Changes
6
6
 
7
- To migrate, remove `github.org` and move the restriction into `authorize`, for example `authorize: ({ repository }) => repository.toLowerCase().startsWith("acme/")`. Each command still declares one `owner/name` repository; app tokens are scoped to that repository in its owner's installation.
7
+ - Client `messages` now show only the session's current conversation, so messages from before a clear no longer appear.
8
+ `messages` and `transcriptOf()` follow each turn's `follows` and a completed context change's `selects`, as `conversation(view)` does, and leave out turns outside the conversation. The session `view` still holds every retained turn. ([#5597](https://github.com/vercel/eve/pull/5597))
9
+ - The `gh` tool takes an optional `repository` instead of `permissions`, runs any `gh` or `git` subcommand, and leaves every access decision to `github.authorize`.
10
+ `github.principalType` is now required and decides what `authorize` receives: `{ argv, auth, owner, repository, token }` for `"app"`, and `{ argv, auth, repository, token }` for `"user"`, where `repository` may be `null`. eve no longer matches `--repo` and other explicit targets against the declared repository or limits `git` to `fetch`, `ls-remote`, `pull`, and `push`; check `argv` in `authorize` if your policy depends on them. ([#5595](https://github.com/vercel/eve/pull/5595))
11
+ - `history` passed to `send()`, `create()`, or the eve channel's `onMessage` now rejects an entry with a field other than `id`, `role`, or `text` instead of dropping it.
12
+ `InvalidSessionHistoryError` names the entry and its unknown fields. Map stored messages to `{ id, role, text }` before passing them, so fields a later release accepts never change what an existing caller sends. ([#5597](https://github.com/vercel/eve/pull/5597))
8
13
 
9
- With `principalType: "user"`, the `gh` tool resolves the caller's token through `ctx.getToken`, so eve signs the caller in once for every repository and again when GitHub rejects the token.
10
-
11
- - Slack channels can add each sender's display name, real name, and email to model-visible message metadata with the new `messageContext.users` option. [#5536](https://github.com/vercel/eve/pull/5536)
12
-
13
- `users: true` adds names, `users: { email: true }` adds emails too, and `users: { name: false, email: true }` adds emails only. The triggering author's profile is also written to `message.author` and the default Slack auth attributes. Pass `resolve(user, next)` to own caching around eve's `users.info` lookup.
14
-
15
- Slack message metadata is now grouped into `<sender>`, `<bot>`, and `<thread>` blocks. `sender_type` and `sender_id` become `type` and `id` inside `<sender>`, `bot_user_id` and `is_mentioned` become `id` and `mentioned` inside `<bot>`, and the team, channel, and timestamp fields move into `<thread>`.
16
-
17
- ## Other Changes
18
-
19
- See the [full list of changes](https://github.com/vercel/eve/compare/eve%400.87.0...eve%400.88.0).
20
-
21
- ## Contributors
22
-
23
- - [@ruiconti](https://github.com/ruiconti)
24
-
25
- For an upgrade across multiple releases, review each version between the installed and target versions in the [target version's changelog](https://raw.githubusercontent.com/vercel/eve/refs/tags/eve%400.88.0/packages/eve/CHANGELOG.md).
14
+ For an upgrade across multiple releases, review each version between the installed and target versions in the [target version's changelog](https://raw.githubusercontent.com/vercel/eve/refs/tags/eve%400.89.0/packages/eve/CHANGELOG.md).
@@ -46,8 +46,6 @@ export declare function firstOpenRequest(view: SessionView): Interaction | undef
46
46
  export declare function requestSettlementOf(view: SessionView, data: InteractionSettledData): RequestSettlement | undefined;
47
47
  /** An answer a check or policy refused, from its `response.settled`. */
48
48
  export declare function refusedAnswerOf(view: SessionView, data: ResponseSettledData): RefusedAnswer | undefined;
49
- /** Who gave an answer: the principal of the delivery it arrived in. */
50
- export declare function responderOf(view: SessionView, responseId: string): Principal | undefined;
51
49
  /** An option's style a channel can render: a style a newer eve added reads as none. */
52
50
  export declare function optionStyle(option: {
53
51
  readonly style?: string;
@@ -1 +1 @@
1
- import{decidingAnswer,interaction,interaction as interaction$1,promptQueueHead,signInEnding}from"#protocol/session-projection/reader.js";import{interactionBatches,interactionOwner}from"#protocol/session-projection/selectors.js";function requestBatchOf(e,t){let n=e.interactions[t.interactionId],r=interactionBatches(e).find(e=>e[0]===n);if(n===void 0||r===void 0)return;let i=r.flatMap(t=>interaction$1(e,t.interactionId)??[]);if(i.length===0)return;let a=interactionOwner(e,n),o={requests:i,turnId:a.turnId??``};return a.taskId!==void 0&&(o.taskId=a.taskId),(n.origin!==void 0||n.request.kind===`question`)&&`callId`in n.subject&&(o.callId=n.subject.callId),o}function firstOpenRequest(e){let t=promptQueueHead(e);return t===void 0?void 0:interaction$1(e,t.interactionId)}function requestSettlementOf(e,t){let n=e.interactions[t.interactionId];if(n===void 0||n.request.kind===`sign-in`)return;let r={interactionId:n.interactionId,kind:n.request.kind,outcome:t.outcome},i=decidingAnswer({...n,response:t.response});i!==void 0&&(r.answer=i),t.reason!==void 0&&(r.reason=t.reason);let a=t.cause!==void 0&&`responseId`in t.cause?responderOf(e,t.cause.responseId):void 0;return a!==void 0&&(r.responder=a),r}function refusedAnswerOf(e,t){if(t.outcome!==`refused`&&t.outcome!==`failed`)return;let n=e.responses[t.responseId];if(n===void 0)return;let r={interactionId:n.interactionId,outcome:t.outcome};t.reason!==void 0&&(r.reason=t.reason);let i=responderOf(e,t.responseId);return i!==void 0&&(r.responder=i),r}function responderOf(e,t){let n=e.responses[t];return n===void 0?void 0:e.deliveries[n.deliveryId]?.principal}function optionStyle(e){let{style:t}=e;return t===`primary`||t===`danger`||t==="default"?t:void 0}export{firstOpenRequest,interaction,optionStyle,refusedAnswerOf,requestBatchOf,requestSettlementOf,responderOf,signInEnding};
1
+ import{decidingAnswer,interaction,interaction as interaction$1,promptQueueHead,responderOf,signInEnding}from"#protocol/session-projection/reader.js";import{interactionBatches,interactionOwner}from"#protocol/session-projection/selectors.js";function requestBatchOf(e,t){let n=e.interactions[t.interactionId],r=interactionBatches(e).find(e=>e[0]===n);if(n===void 0||r===void 0)return;let i=r.flatMap(t=>interaction$1(e,t.interactionId)??[]);if(i.length===0)return;let a=interactionOwner(e,n),o={requests:i,turnId:a.turnId??``};return a.taskId!==void 0&&(o.taskId=a.taskId),(n.origin!==void 0||n.request.kind===`question`)&&`callId`in n.subject&&(o.callId=n.subject.callId),o}function firstOpenRequest(e){let t=promptQueueHead(e);return t===void 0?void 0:interaction$1(e,t.interactionId)}function requestSettlementOf(e,t){let n=e.interactions[t.interactionId];if(n===void 0||n.request.kind===`sign-in`)return;let r={interactionId:n.interactionId,kind:n.request.kind,outcome:t.outcome},i=decidingAnswer({...n,response:t.response});i!==void 0&&(r.answer=i),t.reason!==void 0&&(r.reason=t.reason);let a=t.cause!==void 0&&`responseId`in t.cause?responderOf(e,t.cause.responseId):void 0;return a!==void 0&&(r.responder=a),r}function refusedAnswerOf(e,t){if(t.outcome!==`refused`&&t.outcome!==`failed`)return;let n=e.responses[t.responseId];if(n===void 0)return;let r={interactionId:n.interactionId,outcome:t.outcome};t.reason!==void 0&&(r.reason=t.reason);let i=responderOf(e,t.responseId);return i!==void 0&&(r.responder=i),r}function optionStyle(e){let{style:t}=e;return t===`primary`||t===`danger`||t==="default"?t:void 0}export{firstOpenRequest,interaction,optionStyle,refusedAnswerOf,requestBatchOf,requestSettlementOf,signInEnding};
@@ -1409,6 +1409,21 @@ function activeTurn(view) {
1409
1409
  const row = latest === void 0 ? void 0 : view.turns[latest];
1410
1410
  return row !== void 0 && row.status !== "settled" ? row : void 0;
1411
1411
  }
1412
+ function conversation(view) {
1413
+ const selection = view.selection;
1414
+ const start = selection === void 0 ? view.session.latestTurnId : selection?.turnId;
1415
+ const turns = [];
1416
+ const seen = /* @__PURE__ */ new Set();
1417
+ let id = start;
1418
+ while (id !== void 0 && id !== null && !seen.has(id)) {
1419
+ seen.add(id);
1420
+ const row = view.turns[id];
1421
+ if (row === void 0) break;
1422
+ turns.push(row);
1423
+ id = row.follows;
1424
+ }
1425
+ return turns.reverse();
1426
+ }
1412
1427
  function failure(view, turnId) {
1413
1428
  const row = turnId === void 0 ? void 0 : view.turns[turnId];
1414
1429
  if (row?.outcome === "failed") return row.error ?? {
@@ -3896,6 +3911,8 @@ var Conversation = class {
3896
3911
  return interactions;
3897
3912
  }
3898
3913
  #orderedMessages() {
3914
+ const turnIds = conversation(this.view).map((turn) => turn.turnId);
3915
+ const inConversation = new Set(turnIds);
3899
3916
  const sent = /* @__PURE__ */ new Map();
3900
3917
  const imported = /* @__PURE__ */ new Map();
3901
3918
  for (const row of Object.values(this.view.deliveries)) {
@@ -3928,7 +3945,7 @@ var Conversation = class {
3928
3945
  }
3929
3946
  const local = /* @__PURE__ */ new Map();
3930
3947
  for (const submission of this.#submissions) {
3931
- const turnId = submission.turnId !== void 0 && this.view.turns[submission.turnId] !== void 0 ? submission.turnId : void 0;
3948
+ const turnId = submission.turnId !== void 0 && inConversation.has(submission.turnId) ? submission.turnId : void 0;
3932
3949
  const message = {
3933
3950
  id: `optimistic:${submission.id}:user`,
3934
3951
  metadata: {
@@ -3946,7 +3963,7 @@ var Conversation = class {
3946
3963
  else messages.push(message);
3947
3964
  }
3948
3965
  const messages = [];
3949
- for (const turnId of Object.keys(this.view.turns)) {
3966
+ for (const turnId of turnIds) {
3950
3967
  const placed = [
3951
3968
  ...(imported.get(turnId) ?? []).map((entry) => ({
3952
3969
  ...entry,
@@ -1410,6 +1410,21 @@ function activeTurn(view) {
1410
1410
  const row = latest === void 0 ? void 0 : view.turns[latest];
1411
1411
  return row !== void 0 && row.status !== "settled" ? row : void 0;
1412
1412
  }
1413
+ function conversation(view) {
1414
+ const selection = view.selection;
1415
+ const start = selection === void 0 ? view.session.latestTurnId : selection?.turnId;
1416
+ const turns = [];
1417
+ const seen = /* @__PURE__ */ new Set();
1418
+ let id = start;
1419
+ while (id !== void 0 && id !== null && !seen.has(id)) {
1420
+ seen.add(id);
1421
+ const row = view.turns[id];
1422
+ if (row === void 0) break;
1423
+ turns.push(row);
1424
+ id = row.follows;
1425
+ }
1426
+ return turns.reverse();
1427
+ }
1413
1428
  function failure(view, turnId) {
1414
1429
  const row = turnId === void 0 ? void 0 : view.turns[turnId];
1415
1430
  if (row?.outcome === "failed") return row.error ?? {
@@ -3897,6 +3912,8 @@ var Conversation = class {
3897
3912
  return interactions;
3898
3913
  }
3899
3914
  #orderedMessages() {
3915
+ const turnIds = conversation(this.view).map((turn) => turn.turnId);
3916
+ const inConversation = new Set(turnIds);
3900
3917
  const sent = /* @__PURE__ */ new Map();
3901
3918
  const imported = /* @__PURE__ */ new Map();
3902
3919
  for (const row of Object.values(this.view.deliveries)) {
@@ -3929,7 +3946,7 @@ var Conversation = class {
3929
3946
  }
3930
3947
  const local = /* @__PURE__ */ new Map();
3931
3948
  for (const submission of this.#submissions) {
3932
- const turnId = submission.turnId !== void 0 && this.view.turns[submission.turnId] !== void 0 ? submission.turnId : void 0;
3949
+ const turnId = submission.turnId !== void 0 && inConversation.has(submission.turnId) ? submission.turnId : void 0;
3933
3950
  const message = {
3934
3951
  id: `optimistic:${submission.id}:user`,
3935
3952
  metadata: {
@@ -3947,7 +3964,7 @@ var Conversation = class {
3947
3964
  else messages.push(message);
3948
3965
  }
3949
3966
  const messages = [];
3950
- for (const turnId of Object.keys(this.view.turns)) {
3967
+ for (const turnId of turnIds) {
3951
3968
  const placed = [
3952
3969
  ...(imported.get(turnId) ?? []).map((entry) => ({
3953
3970
  ...entry,
@@ -1 +1 @@
1
- import{isFactType}from"#protocol/session-events/catalog.js";import{emptyPreviews,emptySessionView,foldReceivedEvent}from"#protocol/session-projection/fold.js";import{callPlace,interaction,interactionPlace}from"#protocol/session-projection/reader.js";import{runTurn}from"#protocol/session-projection/selectors.js";import{snapshotOf}from"#protocol/session-projection/session-view.js";import{assistantMessages,importedMessages,userMessage}from"#client/messages.js";import{answersDeliveryId}from"#shared/answers-delivery-id.js";var Conversation=class{view=emptySessionView();previews=emptyPreviews();#e;#t;#n=[];#r=new Map;#i=[];#a=!1;#o=new Map;#s=new Map;#c=new Map;#l=new Map;#u=new Map;#d=`all`;#f;#p;#m=-1;observe(e){let t=e.meta?.position,n=this.#e;if(t!==void 0&&n!==void 0&&(t.line<n.line||t.line===n.line&&t.index<=n.index))return!1;if(t!==void 0&&(this.#e=t),this.#n.push(e),e.meta?.endOfLine===!1)return!0;let r=this.#n;this.#n=[],this.#t=this.#e;for(let e of r){foldReceivedEvent(this.view,e,this.previews),e.type===`delivery.consumed`&&(e.data.history?.length??0)>0&&this.#l.set(e.data.deliveryId,importedMessages(e.data.deliveryId,e.data.history)),isFactType(e.type)&&(this.#p=void 0);for(let t of touchedTurns(this.view,this.previews,e))this.#g(t)}return this.#x(),this.#f=void 0,!0}advancePosition(e){this.#n.length!==0||e<=this.view.position||(this.view.position=e,this.#f=void 0,this.#p=void 0)}discardUncommitted(){this.#n=[],this.#e=this.#t}answer(e){let t=e.map(e=>({answer:e,deliveryId:void 0}));for(let e of t)this.view.interactions[e.answer.interactionId]?.status===`open`&&this.#r.set(e.answer.interactionId,e);this.#_();let retract=()=>{for(let e of t){let t=e.answer.interactionId;this.#r.get(t)===e&&this.#r.delete(t)}this.#_()};return retract.accept=e=>{for(let n of t)n.deliveryId=e;this.#x(),this.#_()},retract}confirmSubmission(e,t){this.#u.set(t,e),this.#f=void 0}holdUnconfirmedMessages(e){this.#a!==e&&(this.#a=e,this.#f=void 0)}setSubmissions(e){this.#i=e,this.#f=void 0}get submissions(){return this.#i}observeAgent(e,t){this.#o.set(e,t),this.#f=void 0}get state(){if(this.#f!==void 0)return this.#f;let{previews:e,view:t}=this,n=this.#v(),r=this.#d===`all`?void 0:new Set([...this.#d,...Object.values(t.turns).flatMap(e=>e.status===`running`?[e.turnId]:[])]),i=assistantMessages({interactions:n,previews:e,view:t},r);r===void 0&&(this.#s=new Map);for(let[e,t]of i)t.length===0?this.#s.delete(e):this.#s.set(e,t);this.#d=new Set;let a={agents:this.#b(),view:this.#h,messages:this.#y()};return this.#f=a,a}get#h(){return this.#p!==void 0&&this.#m===this.view.position?this.#p:(this.#m=this.view.position,this.#p=snapshotOf(this.view,this.previews))}#g(e){this.#d!==`all`&&this.#d.add(e)}#_(){this.#d=`all`,this.#f=void 0}#v(){let e={};for(let t of Object.keys(this.view.interactions)){let n=interaction(this.view,t);if(n===void 0)continue;let r=this.#r.get(t)?.answer;e[t]=r!==void 0&&n.status===`open`?{...n,answer:r}:n}return e}#y(){let e=new Map,t=new Map;for(let n of Object.values(this.view.deliveries)){if(n.consumedAt===void 0||n.turnId===void 0)continue;let r=n.consumedAt,i=(this.#l.get(n.deliveryId)??[]).map(e=>({at:r,message:e}));i.length>0&&t.set(n.turnId,[...t.get(n.turnId)??[],...i]);let a=this.#u.get(n.deliveryId),o=this.#c.get(n.deliveryId);if(this.#a&&o===void 0&&a===void 0)continue;if(o===void 0){if(o=userMessage(n),o===void 0)continue;this.#c.set(n.deliveryId,o)}let s=a===void 0?o:{...o,id:`optimistic:${a}:user`},c={at:n.consumedAt,message:s},l=e.get(n.turnId);l===void 0?e.set(n.turnId,[c]):l.push(c)}let n=new Map;for(let e of this.#i){let t=e.turnId!==void 0&&this.view.turns[e.turnId]!==void 0?e.turnId:void 0,r={id:`optimistic:${e.id}:user`,metadata:{optimistic:!0,status:e.error===void 0?`submitted`:`failed`},parts:[{text:e.message,type:`text`}],role:`user`},i=n.get(t);i===void 0?n.set(t,[r]):i.push(r)}let r=[];for(let i of Object.keys(this.view.turns)){let a=[...(t.get(i)??[]).map(e=>({...e,rank:-1})),...(e.get(i)??[]).map(e=>({...e,rank:0})),...(this.#s.get(i)??[]).map(e=>({...e,rank:1}))].sort((e,t)=>e.at-t.at||e.rank-t.rank);r.push(...a.map(e=>e.message),...n.get(i)??[])}return r.push(...n.get(void 0)??[]),r}#b(){let e={};for(let t of Object.values(this.view.children)){let n=`callId`in t.owner?t.owner.callId:void 0,r={owner:t.owner,name:t.name,observation:this.#o.get(t.sessionId)??{status:`not-followed`},sessionId:t.sessionId};n===void 0?`taskId`in t.owner&&(r.taskId=t.owner.taskId):(r.callId=n,r.turnId=callPlace(this.view,n)?.turnId,r.taskId=this.view.calls[n]?.taskId),e[t.sessionId]=r}return e}#x(){for(let[e,t]of this.#r)t.deliveryId!==void 0&&(this.view.deliveries[t.deliveryId]!==void 0||this.view.deliveries[answersDeliveryId(t.deliveryId)]!==void 0)&&(this.#r.delete(e),this.#_())}};function conversationOf(e){let t=new Conversation;for(let n of e)t.observe(n);return t.state}function touchedTurns(e,t,n){let r=n.scope,i=n.data??{},a=new Set,add=e=>{e!==void 0&&a.add(e)};add(r?.turnId),typeof i.turnId==`string`&&add(i.turnId);let o=typeof i.runId==`string`?i.runId:typeof i.partId==`string`?e.parts[i.partId]?.runId??t.parts[i.partId]?.runId:void 0;o!==void 0&&add(runTurn(e,o)),typeof i.callId==`string`&&add(callPlace(e,i.callId)?.turnId);let s=typeof i.interactionId==`string`?i.interactionId:typeof i.responseId==`string`?e.responses[i.responseId]?.interactionId:void 0,c=s===void 0?void 0:e.interactions[s];return c!==void 0&&(add(interactionPlace(e,c).turnId),`callId`in c.subject&&add(callPlace(e,c.subject.callId)?.turnId)),[...a]}export{Conversation,conversationOf};
1
+ import{isFactType}from"#protocol/session-events/catalog.js";import{emptyPreviews,emptySessionView,foldReceivedEvent}from"#protocol/session-projection/fold.js";import{callPlace,interaction,interactionPlace}from"#protocol/session-projection/reader.js";import{conversation,runTurn}from"#protocol/session-projection/selectors.js";import{snapshotOf}from"#protocol/session-projection/session-view.js";import{assistantMessages,importedMessages,userMessage}from"#client/messages.js";import{answersDeliveryId}from"#shared/answers-delivery-id.js";var Conversation=class{view=emptySessionView();previews=emptyPreviews();#e;#t;#n=[];#r=new Map;#i=[];#a=!1;#o=new Map;#s=new Map;#c=new Map;#l=new Map;#u=new Map;#d=`all`;#f;#p;#m=-1;observe(e){let t=e.meta?.position,n=this.#e;if(t!==void 0&&n!==void 0&&(t.line<n.line||t.line===n.line&&t.index<=n.index))return!1;if(t!==void 0&&(this.#e=t),this.#n.push(e),e.meta?.endOfLine===!1)return!0;let r=this.#n;this.#n=[],this.#t=this.#e;for(let e of r){foldReceivedEvent(this.view,e,this.previews),e.type===`delivery.consumed`&&(e.data.history?.length??0)>0&&this.#l.set(e.data.deliveryId,importedMessages(e.data.deliveryId,e.data.history)),isFactType(e.type)&&(this.#p=void 0);for(let t of touchedTurns(this.view,this.previews,e))this.#g(t)}return this.#x(),this.#f=void 0,!0}advancePosition(e){this.#n.length!==0||e<=this.view.position||(this.view.position=e,this.#f=void 0,this.#p=void 0)}discardUncommitted(){this.#n=[],this.#e=this.#t}answer(e){let t=e.map(e=>({answer:e,deliveryId:void 0}));for(let e of t)this.view.interactions[e.answer.interactionId]?.status===`open`&&this.#r.set(e.answer.interactionId,e);this.#_();let retract=()=>{for(let e of t){let t=e.answer.interactionId;this.#r.get(t)===e&&this.#r.delete(t)}this.#_()};return retract.accept=e=>{for(let n of t)n.deliveryId=e;this.#x(),this.#_()},retract}confirmSubmission(e,t){this.#u.set(t,e),this.#f=void 0}holdUnconfirmedMessages(e){this.#a!==e&&(this.#a=e,this.#f=void 0)}setSubmissions(e){this.#i=e,this.#f=void 0}get submissions(){return this.#i}observeAgent(e,t){this.#o.set(e,t),this.#f=void 0}get state(){if(this.#f!==void 0)return this.#f;let{previews:e,view:t}=this,n=this.#v(),r=this.#d===`all`?void 0:new Set([...this.#d,...Object.values(t.turns).flatMap(e=>e.status===`running`?[e.turnId]:[])]),i=assistantMessages({interactions:n,previews:e,view:t},r);r===void 0&&(this.#s=new Map);for(let[e,t]of i)t.length===0?this.#s.delete(e):this.#s.set(e,t);this.#d=new Set;let a={agents:this.#b(),view:this.#h,messages:this.#y()};return this.#f=a,a}get#h(){return this.#p!==void 0&&this.#m===this.view.position?this.#p:(this.#m=this.view.position,this.#p=snapshotOf(this.view,this.previews))}#g(e){this.#d!==`all`&&this.#d.add(e)}#_(){this.#d=`all`,this.#f=void 0}#v(){let e={};for(let t of Object.keys(this.view.interactions)){let n=interaction(this.view,t);if(n===void 0)continue;let r=this.#r.get(t)?.answer;e[t]=r!==void 0&&n.status===`open`?{...n,answer:r}:n}return e}#y(){let e=conversation(this.view).map(e=>e.turnId),t=new Set(e),n=new Map,r=new Map;for(let e of Object.values(this.view.deliveries)){if(e.consumedAt===void 0||e.turnId===void 0)continue;let t=e.consumedAt,i=(this.#l.get(e.deliveryId)??[]).map(e=>({at:t,message:e}));i.length>0&&r.set(e.turnId,[...r.get(e.turnId)??[],...i]);let a=this.#u.get(e.deliveryId),o=this.#c.get(e.deliveryId);if(this.#a&&o===void 0&&a===void 0)continue;if(o===void 0){if(o=userMessage(e),o===void 0)continue;this.#c.set(e.deliveryId,o)}let s=a===void 0?o:{...o,id:`optimistic:${a}:user`},c={at:e.consumedAt,message:s},l=n.get(e.turnId);l===void 0?n.set(e.turnId,[c]):l.push(c)}let i=new Map;for(let e of this.#i){let n=e.turnId!==void 0&&t.has(e.turnId)?e.turnId:void 0,r={id:`optimistic:${e.id}:user`,metadata:{optimistic:!0,status:e.error===void 0?`submitted`:`failed`},parts:[{text:e.message,type:`text`}],role:`user`},a=i.get(n);a===void 0?i.set(n,[r]):a.push(r)}let a=[];for(let t of e){let e=[...(r.get(t)??[]).map(e=>({...e,rank:-1})),...(n.get(t)??[]).map(e=>({...e,rank:0})),...(this.#s.get(t)??[]).map(e=>({...e,rank:1}))].sort((e,t)=>e.at-t.at||e.rank-t.rank);a.push(...e.map(e=>e.message),...i.get(t)??[])}return a.push(...i.get(void 0)??[]),a}#b(){let e={};for(let t of Object.values(this.view.children)){let n=`callId`in t.owner?t.owner.callId:void 0,r={owner:t.owner,name:t.name,observation:this.#o.get(t.sessionId)??{status:`not-followed`},sessionId:t.sessionId};n===void 0?`taskId`in t.owner&&(r.taskId=t.owner.taskId):(r.callId=n,r.turnId=callPlace(this.view,n)?.turnId,r.taskId=this.view.calls[n]?.taskId),e[t.sessionId]=r}return e}#x(){for(let[e,t]of this.#r)t.deliveryId!==void 0&&(this.view.deliveries[t.deliveryId]!==void 0||this.view.deliveries[answersDeliveryId(t.deliveryId)]!==void 0)&&(this.#r.delete(e),this.#_())}};function conversationOf(e){let t=new Conversation;for(let n of e)t.observe(n);return t.state}function touchedTurns(e,t,n){let r=n.scope,i=n.data??{},a=new Set,add=e=>{e!==void 0&&a.add(e)};add(r?.turnId),typeof i.turnId==`string`&&add(i.turnId);let o=typeof i.runId==`string`?i.runId:typeof i.partId==`string`?e.parts[i.partId]?.runId??t.parts[i.partId]?.runId:void 0;o!==void 0&&add(runTurn(e,o)),typeof i.callId==`string`&&add(callPlace(e,i.callId)?.turnId);let s=typeof i.interactionId==`string`?i.interactionId:typeof i.responseId==`string`?e.responses[i.responseId]?.interactionId:void 0,c=s===void 0?void 0:e.interactions[s];return c!==void 0&&(add(interactionPlace(e,c).turnId),`callId`in c.subject&&add(callPlace(e,c.subject.callId)?.turnId)),[...a]}export{Conversation,conversationOf};
@@ -6,7 +6,7 @@ export interface TranscriptMessage {
6
6
  }
7
7
  /** A session's text conversation, as {@link transcriptOf} reads it. */
8
8
  export interface TranscriptData {
9
- /** Messages since the session's last clear, oldest first. */
9
+ /** The messages of the session's current conversation, oldest first. */
10
10
  readonly messages: readonly TranscriptMessage[];
11
11
  }
12
12
  /** Options for {@link transcriptOf}. */
@@ -24,9 +24,12 @@ export interface TranscriptOptions {
24
24
  * The user's text is what each consumed delivery carries, after the history it imported; the
25
25
  * assistant's is each completed reply part. When one line consumes several deliveries, their
26
26
  * history comes before their messages, as the model reads them. Reasoning, narration, tool calls
27
- * and results, attachments, interactions, and interrupted or unfinished output are left out. A completed clear (`context.settled` selecting
28
- * nothing), or a reset that ended a stranded session, starts the transcript over, so text the
29
- * session no longer holds is never returned.
27
+ * and results, attachments, interactions, and interrupted or unfinished output are left out.
28
+ *
29
+ * Only the session's current conversation is returned: the newest turn, or the one a later
30
+ * context change selected, and the turns it follows back. A completed clear (`context.settled`
31
+ * selecting nothing), or a reset that ended a stranded session, starts the transcript over, so
32
+ * text the session no longer holds is never returned.
30
33
  *
31
34
  * @example
32
35
  * ```ts
@@ -1,2 +1,2 @@
1
- function transcriptOf(e,t={}){let{maxMessages:n}=t;if(n!==void 0&&(!Number.isSafeInteger(n)||n<=0))throw TypeError(`transcriptOf: "maxMessages" must be a positive integer; received ${String(n)}.`);let r=[],i,a,append=e=>{e.text.trim().length>0&&r.push(e)};for(let t of e){let e=t.meta?.position?.line;switch((t.type!==`delivery.consumed`||a?.line!==e)&&(a=void 0),t.type){case`delivery.admitted`:t.data.source!==void 0&&`control`in t.data.source&&t.data.source.control===`reset`&&(i=t.data.deliveryId);break;case`delivery.consumed`:{a??={at:r.length,line:e};let n=(t.data.history??[]).filter(({text:e})=>e.trim().length>0).map(({role:e,text:t})=>({role:e,text:t}));r.splice(a.at,0,...n),a.at+=n.length,append({role:`user`,text:textOf(t.data.parts)});break}case`content.completed`:t.data.kind===`text`&&t.data.phase===`reply`&&t.data.interrupted!==!0&&typeof t.data.value==`string`&&append({role:`assistant`,text:t.data.value});break;case`context.settled`:t.data.selects===null&&(r=[]);break;case`session.ended`:t.data.cause!==void 0&&`deliveryId`in t.data.cause&&t.data.cause.deliveryId===i&&(r=[])}}return{messages:n===void 0?r:r.slice(-n)}}function textOf(e){return e.flatMap(e=>e.kind===`text`?[e.text]:[]).join(`
1
+ function transcriptOf(e,t={}){let{maxMessages:n}=t;if(n!==void 0&&(!Number.isSafeInteger(n)||n<=0))throw TypeError(`transcriptOf: "maxMessages" must be a positive integer; received ${String(n)}.`);let r=[],i=new Map,a,o,s,c,append=(e,t)=>{e.text.trim().length>0&&r.push({message:e,turnId:t})};for(let t of e){let e=t.meta?.position?.line;switch((t.type!==`delivery.consumed`||c?.line!==e)&&(c=void 0),t.type){case`delivery.admitted`:t.data.source!==void 0&&`control`in t.data.source&&t.data.source.control===`reset`&&(s=t.data.deliveryId);break;case`turn.started`:i.set(t.data.turnId,t.data.follows),a=t.data.turnId,o=void 0;break;case`delivery.consumed`:{let{turnId:n}=t.data;c??={at:r.length,line:e};let i=(t.data.history??[]).filter(({text:e})=>e.trim().length>0).map(({role:e,text:t})=>({message:{role:e,text:t},turnId:n}));r.splice(c.at,0,...i),c.at+=i.length,append({role:`user`,text:textOf(t.data.parts)},n);break}case`content.completed`:t.data.kind===`text`&&t.data.phase===`reply`&&t.data.interrupted!==!0&&typeof t.data.value==`string`&&append({role:`assistant`,text:t.data.value},t.scope?.turnId);break;case`context.settled`:if(t.data.outcome!==`completed`||t.data.selects===void 0)break;t.data.selects===null&&(r=[]),o=t.data.selects===null?null:t.data.selects.turnId;break;case`session.ended`:t.data.cause!==void 0&&`deliveryId`in t.data.cause&&t.data.cause.deliveryId===s&&(r=[])}}let l=conversationTurns(i,o===void 0?a:o),u=r.flatMap(({message:e,turnId:t})=>t===void 0||!i.has(t)||l.has(t)?[e]:[]);return{messages:n===void 0?u:u.slice(-n)}}function conversationTurns(e,t){let n=new Set,r=t;for(;r!=null&&!n.has(r);)n.add(r),r=e.get(r);return n}function textOf(e){return e.flatMap(e=>e.kind===`text`?[e.text]:[]).join(`
2
2
  `)}export{transcriptOf};
@@ -2,7 +2,7 @@
2
2
  "moduleFingerprints": {
3
3
  "@eve/catalog": "29b7529f6044427c750e4c27fe91da792014c60c660db31b7ca1fff0afe7f603",
4
4
  "just-secrets": "1ce67d437d0bb06df02e4e99180a3c5f5edf0010314010226e97b96d462bba5d",
5
- "@vercel/agent-runs": "e8052622a0ec8c1f46ed114b2258776baad4d8ec84ddfa270faa519b42e58ad9",
5
+ "@vercel/agent-runs": "8a64c66bdfa39999f05321865b37e84aba509ff993db76e7fe988e8630d756b0",
6
6
  "@workflow/world-local": "a10e78551f65fc607cf75261a569d852c40bc9cfac13a7fb6e15c88bf1ccf429"
7
7
  },
8
8
  "moduleVersions": {
@@ -42,7 +42,7 @@
42
42
  "@shadcn/registry": "0.1.3",
43
43
  "@standard-schema/spec": "1.1.0",
44
44
  "turndown": "7.2.4",
45
- "@vercel/agent-runs": "0.0.3",
45
+ "@vercel/agent-runs": "0.0.4",
46
46
  "@vercel/blob": "2.8.0",
47
47
  "@vercel/connect": "2.5.2",
48
48
  "@vercel/detect-agent": "1.2.3",
@@ -61,7 +61,7 @@
61
61
  "zod": "4.5.4",
62
62
  "zod-validation-error": "5.0.0"
63
63
  },
64
- "scriptHash": "5bbbecf1b39d50c2751d85ab49f4fe2578652d3f5d95cb2cd214e9908c7b900e",
64
+ "scriptHash": "04ba57b3b68f1f35520e6305a5a09628e1de93cd9434ee708f492c3bea8cf83d",
65
65
  "toolVersions": {
66
66
  "rolldown": "1.2.9",
67
67
  "typescript": "7.0.2"
@@ -1 +1 @@
1
- import{runJsProgram}from"#execution/dynamic-workflow/workflow.js";async function runWorkflowProgramTask(e,t){"use workflow";return runJsProgram(e.js,t,{maxSubagents:e.maxSubagents??0})}runWorkflowProgramTask.workflowId=`workflow//eve@0.88.0//runWorkflowProgramTask`;export{runWorkflowProgramTask};
1
+ import{runJsProgram}from"#execution/dynamic-workflow/workflow.js";async function runWorkflowProgramTask(e,t){"use workflow";return runJsProgram(e.js,t,{maxSubagents:e.maxSubagents??0})}runWorkflowProgramTask.workflowId=`workflow//eve@0.89.0//runWorkflowProgramTask`;export{runWorkflowProgramTask};
@@ -1 +1 @@
1
- import{decide}from"#ai/decide.js";async function runAgentRouterTask(e,t){"use workflow";let n=await chooseTarget(e.message,descriptions(t),t.abortSignal),{reply:r,status:i}=await(await t.agent(n).send(e.message,{signal:t.abortSignal})).result();if(i===`failed`)throw Error(`Agent "${n}" failed to handle the task.`);return r??null}async function chooseTarget(e,t,n){"use step";let r=Object.keys(t);if(r.length===0)throw Error(`agentRouter requires at least one available agent with a description.`);return r.length===1?r[0]:(await decide({signal:n,state:{message:e},questions:{route:{type:`choice`,instructions:`Which subagent should handle this task?`,criteria:t}}})).answers.route.choice}function descriptions(e){return Object.fromEntries(Object.entries(e.agents).flatMap(([e,t])=>{let n=t.description.trim();return n.length===0?[]:[[e,n]]}))}runAgentRouterTask.workflowId=`workflow//eve@0.88.0//runAgentRouterTask`;export{runAgentRouterTask};
1
+ import{decide}from"#ai/decide.js";async function runAgentRouterTask(e,t){"use workflow";let n=await chooseTarget(e.message,descriptions(t),t.abortSignal),{reply:r,status:i}=await(await t.agent(n).send(e.message,{signal:t.abortSignal})).result();if(i===`failed`)throw Error(`Agent "${n}" failed to handle the task.`);return r??null}async function chooseTarget(e,t,n){"use step";let r=Object.keys(t);if(r.length===0)throw Error(`agentRouter requires at least one available agent with a description.`);return r.length===1?r[0]:(await decide({signal:n,state:{message:e},questions:{route:{type:`choice`,instructions:`Which subagent should handle this task?`,criteria:t}}})).answers.route.choice}function descriptions(e){return Object.fromEntries(Object.entries(e.agents).flatMap(([e,t])=>{let n=t.description.trim();return n.length===0?[]:[[e,n]]}))}runAgentRouterTask.workflowId=`workflow//eve@0.89.0//runAgentRouterTask`;export{runAgentRouterTask};
@@ -1,20 +1,23 @@
1
1
  import { z } from "zod";
2
- import type { GitHubAttribution, GitHubAuthorize, GitHubConfig } from "./lib/github-shell.ts";
2
+ import type { GitHubAppAuthorizeRequest, GitHubAttribution, GitHubAuthorize, GitHubConfig, GitHubUserAuthorizeRequest } from "./lib/github-shell.ts";
3
3
  export type { GitHubLeaseRule } from "./lib/github-shell.ts";
4
4
  export type { GitHubCoAuthor } from "./lib/github-shell.ts";
5
- export type { GitHubAuthorize, GitHubAuthorizeRequest } from "./lib/github-shell.ts";
5
+ export type { GitHubAppAuthorizeRequest, GitHubAuthorize, GitHubAuthorizeRequest, GitHubUserAuthorizeRequest, } from "./lib/github-shell.ts";
6
6
  export type GitHubLeaseBroker = GitHubConfig["broker"];
7
7
  export type { GitHubAttribution } from "./lib/github-shell.ts";
8
8
  declare const _default: import("eve/extension").ExtensionHandle<z.ZodObject<{
9
- github: z.ZodOptional<z.ZodObject<{
9
+ github: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
10
10
  connector: z.ZodString;
11
11
  broker: z.ZodCustom<(sandbox: import("../../../shared/sandbox-session.ts").SandboxSession, rules: Readonly<Record<string, readonly import("./lib/github-shell.ts").GitHubLeaseRule[]>> | null) => Promise<void>, (sandbox: import("../../../shared/sandbox-session.ts").SandboxSession, rules: Readonly<Record<string, readonly import("./lib/github-shell.ts").GitHubLeaseRule[]>> | null) => Promise<void>>;
12
12
  attribution: z.ZodOptional<z.ZodCustom<GitHubAttribution, GitHubAttribution>>;
13
- authorize: z.ZodCustom<GitHubAuthorize, GitHubAuthorize>;
14
- principalType: z.ZodOptional<z.ZodEnum<{
15
- app: "app";
16
- user: "user";
17
- }>>;
18
- }, z.core.$strip>>;
13
+ authorize: z.ZodCustom<GitHubAuthorize<GitHubAppAuthorizeRequest>, GitHubAuthorize<GitHubAppAuthorizeRequest>>;
14
+ principalType: z.ZodLiteral<"app">;
15
+ }, z.core.$strip>, z.ZodObject<{
16
+ connector: z.ZodString;
17
+ broker: z.ZodCustom<(sandbox: import("../../../shared/sandbox-session.ts").SandboxSession, rules: Readonly<Record<string, readonly import("./lib/github-shell.ts").GitHubLeaseRule[]>> | null) => Promise<void>, (sandbox: import("../../../shared/sandbox-session.ts").SandboxSession, rules: Readonly<Record<string, readonly import("./lib/github-shell.ts").GitHubLeaseRule[]>> | null) => Promise<void>>;
18
+ attribution: z.ZodOptional<z.ZodCustom<GitHubAttribution, GitHubAttribution>>;
19
+ authorize: z.ZodCustom<GitHubAuthorize<GitHubUserAuthorizeRequest>, GitHubAuthorize<GitHubUserAuthorizeRequest>>;
20
+ principalType: z.ZodLiteral<"user">;
21
+ }, z.core.$strip>], "principalType">>;
19
22
  }, z.core.$strip>>;
20
23
  export default _default;
@@ -1 +1 @@
1
- import{z}from"#compiled/zod/index.js";import{defineExtension}from"eve/extension";const fn=()=>z.custom(e=>typeof e==`function`);var extension_default=defineExtension({config:z.object({github:z.object({connector:z.string().min(1),broker:fn(),attribution:fn().optional(),authorize:fn(),principalType:z.enum([`app`,`user`]).optional()}).optional()})});export{extension_default as default};
1
+ import{z}from"#compiled/zod/index.js";import{defineExtension}from"eve/extension";const fn=()=>z.custom(e=>typeof e==`function`),githubBase={connector:z.string().min(1),broker:fn(),attribution:fn().optional()};var extension_default=defineExtension({config:z.object({github:z.discriminatedUnion(`principalType`,[z.object({...githubBase,authorize:fn(),principalType:z.literal(`app`)}),z.object({...githubBase,authorize:fn(),principalType:z.literal(`user`)})]).optional()})});export{extension_default as default};
@@ -1,7 +1,7 @@
1
1
  import { type GitHubConfig } from "./github-shell.ts";
2
2
  declare const GH_TOOL_SCOPE: {
3
- readonly repository: "Connect mints the real token for only that repository, and the sandbox process receives only a placeholder GH_TOKEN that the firewall exchanges on matching GitHub requests. GitHub rejects access outside the token's server-side repository scope; commands that explicitly name another repository with -R, --repo, --repo=, or a repository argument to gh repo clone, view, or fork are denied before minting.";
4
- readonly caller: "Connect resolves the caller's own GitHub token for that command, and the sandbox process receives only a placeholder GH_TOKEN that the firewall exchanges on matching GitHub requests. The token carries the caller's GitHub permissions, so GitHub allows whatever the caller can access; commands that explicitly name another repository with -R, --repo, --repo=, or a repository argument to gh repo clone, view, or fork are denied before the token is resolved.";
3
+ readonly repository: "Connect mints a GitHub App installation token for that repository, or for the owner's installation when repository is an owner.";
4
+ readonly caller: "Connect resolves the caller's own GitHub token, which carries the caller's GitHub permissions, so GitHub allows whatever the caller can access.";
5
5
  };
6
6
  /** Describes the `gh` tool for app-installation (`repository`) or user-scoped (`caller`) tokens. */
7
7
  export declare function ghToolDescription(scope: keyof typeof GH_TOOL_SCOPE): string;
@@ -9,11 +9,7 @@ export declare const GH_TOOL_DESCRIPTION: string;
9
9
  /** The Connect-brokered `gh` tool, rebuilt by the dynamic resolver with its current config. */
10
10
  export declare function defineGhTool(github: () => GitHubConfig | undefined, description?: string): import("eve/tools").ToolDefinition<{
11
11
  command: string;
12
- permissions: {
13
- provider: "github";
14
- repositories: string[];
15
- access: "write";
16
- }[];
12
+ repository?: string | undefined;
17
13
  description: string;
18
14
  workingDirectory?: string | undefined;
19
15
  }, {
@@ -24,11 +20,7 @@ export declare function defineGhTool(github: () => GitHubConfig | undefined, des
24
20
  }> & {
25
21
  execute(input: {
26
22
  command: string;
27
- permissions: {
28
- provider: "github";
29
- repositories: string[];
30
- access: "write";
31
- }[];
23
+ repository?: string | undefined;
32
24
  description: string;
33
25
  workingDirectory?: string | undefined;
34
26
  }, ctx: import("eve/tools").ToolContext): Promise<import("./github-shell.ts").GitHubShellOutput>;
@@ -1 +1 @@
1
- import{executeGitHubShell,githubShellApproval}from"./github-shell.js";import{githubShellInputSchema}from"./github-shell-schema.js";import{z}from"#compiled/zod/index.js";import{defineTool}from"eve/tools";const GH_TOOL_SCOPE={repository:`Connect mints the real token for only that repository, and the sandbox process receives only a placeholder GH_TOKEN that the firewall exchanges on matching GitHub requests. GitHub rejects access outside the token's server-side repository scope; commands that explicitly name another repository with -R, --repo, --repo=, or a repository argument to gh repo clone, view, or fork are denied before minting.`,caller:`Connect resolves the caller's own GitHub token for that command, and the sandbox process receives only a placeholder GH_TOKEN that the firewall exchanges on matching GitHub requests. The token carries the caller's GitHub permissions, so GitHub allows whatever the caller can access; commands that explicitly name another repository with -R, --repo, --repo=, or a repository argument to gh repo clone, view, or fork are denied before the token is resolved.`};function ghToolDescription(e){return`Run one authenticated GitHub command in the sandbox. The full gh CLI surface is available. Commands run without an approval prompt; description records the GitHub-side result the command intends to produce. Declare exactly one owner/name repository; the agent's access policy decides which repositories commands may use. ${GH_TOOL_SCOPE[e]} Use simple argv quoting only, never environment assignments, pipes, redirects, substitutions, or other shell syntax. gh alias and extension commands may execute local code, but remain sandboxed. Use git here only for authenticated fetch, pull, push, or ls-remote against a strictly validated origin, and use gh-signed-commit only with --repo. Use ordinary bash for local git status, diff, add, commit, and rebase.`}const GH_TOOL_DESCRIPTION=ghToolDescription(`repository`),ghOutputSchema=z.object({exitCode:z.number().int(),stderr:z.string(),stdout:z.string(),truncated:z.boolean()});function defineGhTool(e,t=ghToolDescription(e()?.principalType===`user`?`caller`:`repository`)){return defineTool({description:t,approval:({toolInput:e})=>githubShellApproval(e),inputSchema:githubShellInputSchema,outputSchema:ghOutputSchema,execute(t,n){return executeGitHubShell(t,e(),{context:n,auth:n.session.auth.current,getToken:(e,t)=>n.getToken(e,t),requireAuth:(e,t)=>n.requireAuth(e,t),getSandbox:()=>n.getSandbox(),sessionId:n.session.id})}})}export{GH_TOOL_DESCRIPTION,defineGhTool,ghToolDescription};
1
+ import{githubShellInputSchema}from"./github-shell-schema.js";import{executeGitHubShell,githubShellApproval}from"./github-shell.js";import{z}from"#compiled/zod/index.js";import{defineTool}from"eve/tools";const GH_TOOL_SCOPE={repository:`Connect mints a GitHub App installation token for that repository, or for the owner's installation when repository is an owner.`,caller:`Connect resolves the caller's own GitHub token, which carries the caller's GitHub permissions, so GitHub allows whatever the caller can access.`},GH_TOOL_REPOSITORY={repository:`Set repository to the owner/name the command acts on, or to an owner for discovery such as gh repo list <owner> or gh search repos --owner <owner>.`,caller:`Set repository to the owner/name the command acts on, or omit it for commands that act on no single repository, such as gh repo list <owner>, gh search repos, or gh api user/repos.`};function ghToolDescription(e){return`Run one authenticated gh, git, or gh-signed-commit command in the sandbox. The full gh and git CLI surface is available. ${GH_TOOL_REPOSITORY[e]} The agent's access policy decides whether each command runs. ${GH_TOOL_SCOPE[e]} The sandbox process receives only a placeholder GH_TOKEN that the firewall exchanges on matching GitHub requests. Commands run without an approval prompt; description records the GitHub-side result the command intends to produce. Use simple argv quoting only, never environment assignments, pipes, redirects, substitutions, or other shell syntax. gh alias and extension commands may execute local code, but remain sandboxed. Use gh-signed-commit only with --repo. Use ordinary bash for local git status, diff, add, commit, and rebase.`}const GH_TOOL_DESCRIPTION=ghToolDescription(`repository`),ghOutputSchema=z.object({exitCode:z.number().int(),stderr:z.string(),stdout:z.string(),truncated:z.boolean()});function defineGhTool(e,t=ghToolDescription(e()?.principalType===`user`?`caller`:`repository`)){return defineTool({description:t,approval:({toolInput:e})=>githubShellApproval(e),inputSchema:githubShellInputSchema,outputSchema:ghOutputSchema,execute(t,n){return executeGitHubShell(t,e(),{context:n,auth:n.session.auth.current,getToken:(e,t)=>n.getToken(e,t),requireAuth:(e,t)=>n.requireAuth(e,t),getSandbox:()=>n.getSandbox(),sessionId:n.session.id})}})}export{GH_TOOL_DESCRIPTION,defineGhTool,ghToolDescription};
@@ -1,10 +1,10 @@
1
- const TOKEN_SCOPE={repository:{token:"Connect mints the real token for only the declared repository. The sandbox process receives only a placeholder `GH_TOKEN`, and the firewall exchanges it on matching GitHub requests. GitHub rejects access outside the token's server-side repository scope.",context:"Commands without an explicit repository may use normal `gh` context, but their token remains scoped to the declared repository."},caller:{token:"Connect resolves the caller's own GitHub token for each command. The sandbox process receives only a placeholder `GH_TOKEN`, and the firewall exchanges it on matching GitHub requests. The token carries the caller's GitHub permissions, so access is limited to what the caller can reach on GitHub.",context:"Commands without an explicit repository may use normal `gh` context."}},connectInstructions=e=>`# GitHub
1
+ const TOKEN_SCOPE={repository:{token:`Connect mints a GitHub App installation token for the declared repository, or for the owner's installation when you declare only an owner.`,repository:"Set `repository` to the `owner/name` the command acts on, or to an owner for discovery."},caller:{token:`Connect resolves the caller's own GitHub token for each command. It carries the caller's GitHub permissions, so access is limited to what the caller can reach on GitHub.`,repository:"Set `repository` to the `owner/name` the command acts on, or omit it for commands that act on no single repository, such as `gh repo list <owner>`, `gh search repos`, or `gh api user/repos`."}},connectInstructions=e=>`# GitHub
2
2
 
3
- GitHub credentials are not available to ordinary \`bash\`. Use the \`gh\` tool for every authenticated GitHub operation. The full \`gh\` CLI surface is available. Declare exactly one \`owner/name\` repository with write-capable access; the agent's access policy decides which repositories commands may use. Authenticated commands run without an approval prompt; describe the intended GitHub-side result accurately in \`description\`. ${e.token} Never put credentials in URLs or commands. If access is denied, report it plainly and stop.
3
+ GitHub credentials are not available to ordinary \`bash\`. Use the \`gh\` tool for every authenticated GitHub operation: \`gh\`, \`git\`, and \`gh-signed-commit\` commands. The full \`gh\` and \`git\` CLI surface is available. ${e.repository} The agent's access policy decides whether each command runs. Authenticated commands run without an approval prompt; describe the intended GitHub-side result accurately in \`description\`. ${e.token} The sandbox process receives only a placeholder \`GH_TOKEN\`, and the firewall exchanges it on matching GitHub requests. Never put credentials in URLs or commands. If access is denied, report it plainly and stop.
4
4
 
5
- Pass commands as simple argv with ordinary quoting. Do not use environment assignments, pipes, redirects, substitutions, or other shell syntax. ${e.context} An explicit \`-R\`, \`--repo\`, \`--repo=\`, or repository argument to \`gh repo clone\`, \`view\`, or \`fork\` must match the declaration.
5
+ Pass commands as simple argv with ordinary quoting. Do not use environment assignments, pipes, redirects, substitutions, or other shell syntax.
6
6
 
7
- Determine the repositories needed to complete the task through source discovery and investigation, even when the requester does not name them. Do not ask the requester to enumerate repositories that can be discovered, and never default to the current agent's repository. The agent may select additional repositories as the work reveals them. Each authenticated command declares exactly one target repository and mints a credential lease for that repository at the moment it is needed, so cross-repository work uses separate scoped commands and leases.
7
+ Find the repositories a task needs yourself, even when the requester does not name them or names them loosely. Search with \`gh repo list <owner>\`, \`gh search repos <query>\`, or \`gh search repos --owner <owner> <query>\`, and suggest the closest match when a name does not resolve. Do not ask the requester for an exact \`owner/name\` you can discover, and never default to the current agent's repository. Each command declares its own target, so cross-repository work uses separate commands.
8
8
 
9
9
  Clone with \`gh repo clone owner/name\`. Use authenticated \`git fetch\`, \`git pull\`, \`git push\`, and \`git ls-remote\` through the \`gh\` tool too. Local \`git status\`, \`diff\`, \`add\`, \`commit\`, and \`rebase\` remain ordinary \`bash\` commands because they need no GitHub credential.
10
10
 
@@ -1,11 +1,9 @@
1
1
  import { z } from "zod";
2
+ /** An `owner` or `owner/name` GitHub target. */
3
+ export declare const GITHUB_TARGET: RegExp;
2
4
  export declare const githubShellInputSchema: z.ZodObject<{
3
5
  command: z.ZodString;
4
- permissions: z.ZodArray<z.ZodObject<{
5
- provider: z.ZodLiteral<"github">;
6
- repositories: z.ZodArray<z.ZodString>;
7
- access: z.ZodLiteral<"write">;
8
- }, z.core.$strip>>;
6
+ repository: z.ZodOptional<z.ZodString>;
9
7
  description: z.ZodString;
10
8
  workingDirectory: z.ZodOptional<z.ZodString>;
11
9
  }, z.core.$strip>;
@@ -1 +1 @@
1
- import{z}from"#compiled/zod/index.js";const permissionSchema=z.object({provider:z.literal(`github`),repositories:z.array(z.string().regex(/^[A-Za-z0-9-]+\/[A-Za-z0-9._-]+$/u)).length(1),access:z.literal(`write`)}),githubShellInputSchema=z.object({command:z.string().trim().min(1).max(2e4),permissions:z.array(permissionSchema).length(1),description:z.string().trim().min(1).max(500).describe(`the concrete GitHub-side result expected from this command`),workingDirectory:z.string().trim().min(1).max(1e3).optional().describe(`sandbox workspace directory; defaults to the workspace root`)});export{githubShellInputSchema};
1
+ import{z}from"#compiled/zod/index.js";const GITHUB_TARGET=/^([A-Za-z0-9][A-Za-z0-9-]*)(?:\/([A-Za-z0-9._-]+))?$/u,githubShellInputSchema=z.object({command:z.string().trim().min(1).max(2e4),repository:z.string().trim().regex(GITHUB_TARGET).optional().describe(`the owner/name repository the command acts on, or an owner for discovery such as gh repo list <owner>; omit for commands tied to no owner`),description:z.string().trim().min(1).max(500).describe(`the concrete GitHub-side result expected from this command`),workingDirectory:z.string().trim().min(1).max(1e3).optional().describe(`sandbox workspace directory; defaults to the workspace root`)});export{GITHUB_TARGET,githubShellInputSchema};
@@ -3,15 +3,11 @@ import type { SandboxSession } from "eve/sandbox";
3
3
  import type { ToolContext } from "eve/tools";
4
4
  import { type GitHubCoAuthor } from "./attribution.ts";
5
5
  export type { GitHubCoAuthor } from "./attribution.ts";
6
- export interface GitHubPermission {
7
- readonly access: "write";
8
- readonly provider: "github";
9
- readonly repositories: readonly string[];
10
- }
11
6
  export interface GitHubShellInput {
12
7
  readonly command: string;
13
8
  readonly description: string;
14
- readonly permissions: readonly GitHubPermission[];
9
+ /** The `owner/name` repository the command acts on, an `owner` for discovery, or omitted. */
10
+ readonly repository?: string;
15
11
  readonly workingDirectory?: string;
16
12
  }
17
13
  export interface GitHubShellOutput {
@@ -22,7 +18,7 @@ export interface GitHubShellOutput {
22
18
  }
23
19
  /** Resolves the co-author credited by this turn's GitHub publishing commands. */
24
20
  export type GitHubAttribution = (ctx: ToolContext) => GitHubCoAuthor | null | PromiseLike<GitHubCoAuthor | null>;
25
- export interface GitHubConfig {
21
+ interface GitHubConfigBase {
26
22
  /**
27
23
  * Resolves who the current turn publishes for. When it returns a person,
28
24
  * `gh-signed-commit` messages and `gh pr create` bodies end with their
@@ -31,27 +27,41 @@ export interface GitHubConfig {
31
27
  * requester's linked accounts.
32
28
  */
33
29
  readonly attribution?: GitHubAttribution;
34
- /** The only repository access control: commands run only when it returns `true`. */
35
- readonly authorize: GitHubAuthorize;
36
30
  readonly broker: (sandbox: SandboxSession, rules: Readonly<Record<string, readonly GitHubLeaseRule[]>> | null) => Promise<void>;
37
31
  readonly connector: string;
38
- /**
39
- * `"app"` (default) mints GitHub App installation tokens. `"user"` resolves
40
- * the caller's own token through `ctx.getToken`, signing them in when needed.
41
- */
42
- readonly principalType?: "app" | "user";
43
32
  }
44
- /** What an `authorize` callback sees before a `gh` command runs. */
45
- export interface GitHubAuthorizeRequest {
33
+ /** Mints GitHub App installation tokens scoped to the declared repository or owner. */
34
+ export interface GitHubAppConfig extends GitHubConfigBase {
35
+ /** The only access control: commands run only when it returns `true`. */
36
+ readonly authorize: GitHubAuthorize<GitHubAppAuthorizeRequest>;
37
+ readonly principalType: "app";
38
+ }
39
+ /** Resolves the caller's own token through `ctx.getToken`, signing them in when needed. */
40
+ export interface GitHubUserConfig extends GitHubConfigBase {
41
+ /** The only access control: commands run only when it returns `true`. */
42
+ readonly authorize: GitHubAuthorize<GitHubUserAuthorizeRequest>;
43
+ readonly principalType: "user";
44
+ }
45
+ export type GitHubConfig = GitHubAppConfig | GitHubUserConfig;
46
+ /** What an `authorize` callback sees before a `gh` command runs with the caller's own token. */
47
+ export interface GitHubUserAuthorizeRequest {
48
+ /** The parsed command, such as `["gh", "pr", "view", "7", "--repo", "acme/widgets"]`. */
49
+ readonly argv: readonly string[];
46
50
  /** The session's current caller, or `null` when the session has none. */
47
51
  readonly auth: SessionAuthContext | null;
48
- /** The `owner/name` repository the command declared, which every explicit command target matches. */
49
- readonly repository: string;
52
+ /** The `owner/name` repository the command declared, or `null`. */
53
+ readonly repository: string | null;
50
54
  /** The token Connect minted for this command, for API lookups. It reaches the command only after `authorize` returns `true`. */
51
55
  readonly token: string;
52
56
  }
53
- /** Decides whether the session's caller may run a `gh` command against one repository. */
54
- export type GitHubAuthorize = (request: GitHubAuthorizeRequest) => boolean | Promise<boolean>;
57
+ /** What an `authorize` callback sees before a `gh` command runs with an installation token. */
58
+ export interface GitHubAppAuthorizeRequest extends GitHubUserAuthorizeRequest {
59
+ /** The owner whose installation minted the token. */
60
+ readonly owner: string;
61
+ }
62
+ export type GitHubAuthorizeRequest = GitHubAppAuthorizeRequest | GitHubUserAuthorizeRequest;
63
+ /** Decides whether the session's caller may run one `gh` command; the agent's only access control. */
64
+ export type GitHubAuthorize<Request extends GitHubAuthorizeRequest = GitHubAuthorizeRequest> = (request: Request) => boolean | Promise<boolean>;
55
65
  export interface GitHubLeaseRule {
56
66
  readonly match?: {
57
67
  readonly headers?: readonly {
@@ -76,7 +86,7 @@ interface GitHubShellDependencies {
76
86
  authorizationDetails: {
77
87
  type: "github_app_installation";
78
88
  org: string;
79
- repositories: string[];
89
+ repositories?: string[];
80
90
  }[];
81
91
  subject: {
82
92
  type: "app";
@@ -1 +1 @@
1
- import{attributeCommand,coAuthorTrailer,isAttributable}from"./attribution.js";import{connectUserAuthorization}from"./connect-user-auth.js";import{shellQuote}from"./shell.js";import{validateRepositoryRoot}from"./repository-root.js";import{GITHUB_TOOLING_PATHS}from"./tooling.js";import{posix}from"node:path";import{getToken}from"#compiled/@vercel/connect/index.js";const MAX_OUTPUT_BYTES=1e5,leaseQueues=new Map,ALLOWED_GIT_REMOTE_COMMANDS=new Set([`fetch`,`ls-remote`,`pull`,`push`]),GITHUB_UNAUTHORIZED=/HTTP 401\b|Bad credentials|Authentication failed for|failed: 401\b/u;function githubShellApproval(e){if(!e)return`not-applicable`;try{return validateGitHubShellInput(e),`not-applicable`}catch(e){return{type:`denied`,reason:e instanceof Error?e.message:`Invalid GitHub command.`}}}async function executeGitHubShell(e,t,n){if(!t)throw Error(`GitHub command access is not configured for this agent.`);let r=validateGitHubShellInput(e),i=await n.getSandbox(),a=resolveWorkingDirectory(i,e.workingDirectory);(r[0]===`git`||r[0]===`gh-signed-commit`)&&(a=await validateRepositoryRoot(i,a));let o=e.permissions[0].repositories,s=await assertCommandTargets(r,o,a,i),c=crypto.randomUUID(),l=`/tmp/eve-git-body-${c}.md`,{repository:u,owner:d,name:f}=declaredRepository(o),p=n.auth??null,m,h;if(t.principalType===`user`){if(!n.getToken||!n.requireAuth)throw Error(`User-scoped GitHub access requires ctx.getToken and ctx.requireAuth.`);m=connectUserAuthorization(t.connector),{token:h}=await n.getToken(m)}else h=await(n.getConnectToken??getToken)(t.connector,{authorizationDetails:[{type:`github_app_installation`,org:d,repositories:[f]}],subject:{type:`app`}});if(!h)throw Error(`Connect returned an empty token for ${JSON.stringify(t.connector)}.`);if(!await t.authorize({auth:p,repository:u,token:h}))throw Error(`The current caller is not authorized to access ${u}.`);let g=t.attribution&&n.context&&isAttributable(r)?await t.attribution(n.context):null,_=g?await attributeCommand(r,coAuthorTrailer(g),i,a,l):r,v=executablePath(_[0]),y=s?[`-c`,`protocol.allow=never`,`-c`,`protocol.https.allow=always`,_[1],`https://github.com/${s}.git`,..._.slice(3)]:_.slice(1),b=`cd ${shellQuote(a)} && exec ${shellQuote(v)} ${y.map(shellQuote).join(` `)}`,x=`Basic ${Buffer.from(`x-access-token:${h}`).toString(`base64`)}`,S=`eve-github-${c}`,C=`/tmp/eve-code-gh-${c}`,w=`Basic ${Buffer.from(`x-access-token:${S}`).toString(`base64`)}`,T;try{T=await withGitHubCredentialLease(i,n.sessionId,{authorization:x,placeholder:S,placeholderAuthorization:w,token:h},()=>{let e={GH_CONFIG_DIR:C,GH_PROMPT_DISABLED:`1`};return r[0]!==`git`&&(e.GH_TOKEN=S),e.GIT_CONFIG_COUNT=`2`,e.GIT_CONFIG_KEY_0=`http.https://github.com/.extraheader`,e.GIT_CONFIG_VALUE_0=`Authorization: ${w}`,e.GIT_CONFIG_KEY_1=`core.hooksPath`,e.GIT_CONFIG_VALUE_1=`/dev/null`,e.GIT_TERMINAL_PROMPT=`0`,e.PATH=`/usr/local/bin:/usr/bin:/bin`,i.run({command:b,env:e})},t.broker)}finally{await i.removePath({path:C,recursive:!0,force:!0}),await i.removePath({path:l,force:!0})}m&&T.exitCode!==0&&GITHUB_UNAUTHORIZED.test(T.stderr)&&n.requireAuth(m);let E=sanitizeOutput(T.stdout,h,x),D=sanitizeOutput(T.stderr,h,x);return{exitCode:T.exitCode,stdout:E.value,stderr:D.value,truncated:E.truncated||D.truncated}}async function withGitHubCredentialLease(e,t,n,r,i){let a=leaseQueues.get(t)??Promise.resolve(),o,s=new Promise(e=>{o=e}),c=a.then(()=>s);leaseQueues.set(t,c),await a;try{return await i(e,{"api.github.com":[{match:{headers:[{key:{exact:`authorization`},value:{regex:`^(?:token|Bearer) ${n.placeholder}$`}}]},transform:[{headers:{authorization:`Bearer ${n.token}`}}]}],"github.com":[{match:{headers:[{key:{exact:`authorization`},value:{exact:n.placeholderAuthorization}}]},transform:[{headers:{authorization:n.authorization}}]}]}),await r()}finally{try{await i(e,null)}finally{o(),leaseQueues.get(t)===c&&leaseQueues.delete(t)}}}function parseCommand(e){let t=e.trim();if(!t)throw Error(`GitHub command must not be empty.`);let n=[],r=``,i=null,a=!1,o=!1;for(let e of t){if(a){r+=e,a=!1,o=!0;continue}if(e===`\\`&&i!==`single`){a=!0,o=!0;continue}if(i===`single`){e===`'`?i=null:r+=e;continue}if(i===`double`){if(e===`"`)i=null;else if(e===`$`||e==="`")throw unsupportedSyntax();else r+=e;continue}if(e===`'`)i=`single`,o=!0;else if(e===`"`)i=`double`,o=!0;else if(/\s/u.test(e))o&&=(n.push(r),r=``,!1);else if(";&|<>$`(){}".includes(e))throw unsupportedSyntax();else r+=e,o=!0}if(a||i)throw Error(`GitHub command contains an unfinished quote or escape.`);if(o&&n.push(r),n.length===0)throw Error(`GitHub command must not be empty.`);return n}function validateGitHubShellInput(e){let t=parseCommand(e.command),n=e.permissions[0];if(e.permissions.length!==1||n?.provider!==`github`)throw Error(`Exactly one GitHub permission is required.`);if(n.access!==`write`)throw Error(`GitHub App commands require explicit write-capable access.`);if(!e.description.trim())throw Error(`description must describe the intended result.`);let[r,i]=t;if(r===`gh`){if(!i)throw Error(`A gh subcommand is required.`)}else if(r===`git`){if(!i||!ALLOWED_GIT_REMOTE_COMMANDS.has(i))throw Error(`Authenticated git supports only fetch, ls-remote, pull, and push; clone with gh repo clone.`)}else if(r!==`gh-signed-commit`)throw Error(`GitHub commands must use gh, an authenticated git remote command, or gh-signed-commit.`);return t}async function assertCommandTargets(e,t,n,r){let i=new Set(t.map(e=>e.toLowerCase())),a,o;if(e[0]===`git`){if(e[2]!==`origin`)throw Error(`Authenticated git commands must use the validated origin remote.`);let t=e[1]===`push`,i=await r.run({command:`cd ${shellQuote(n)} && git remote get-url ${t?`--push `:``}origin`,env:{GIT_TERMINAL_PROMPT:`0`,PATH:`/usr/bin:/bin`}});if(i.exitCode!==0)throw Error(`Could not resolve the origin GitHub repository.`);a=repositoryFromRemote(i.stdout.trim()),o=[a]}else if(e[0]===`gh-signed-commit`){if(o=repoFlagTargets(e.slice(1)),o.length===0)throw Error(`gh-signed-commit requires an explicit --repo owner/repository target.`)}else o=repoFlagTargets(e.slice(1)),e[1]===`repo`&&(e[2]===`clone`||e[2]===`view`||e[2]===`fork`)&&e[3]&&!e[3].startsWith(`-`)&&o.push(canonicalRepository(e[3]));for(let e of o)if(!i.has(e.toLowerCase()))throw Error(`Command target ${JSON.stringify(e)} is not in the declared repositories.`);return a}function repoFlagTargets(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n];if(r===`--repo`||r===`-R`){let i=e[n+1];if(!i)throw Error(`${r} requires an owner/repository value.`);t.push(canonicalRepository(i)),n+=1}else r?.startsWith(`--repo=`)&&t.push(canonicalRepository(r.slice(7)))}return t}function repositoryFromRemote(e){let t=/^https:\/\/github\.com\/([^/]+\/[^/]+?)(?:\.git)?$/iu.exec(e);if(t?.[1])return canonicalRepository(t[1]);let n=/^git@github\.com:([^/]+\/[^/]+?)(?:\.git)?$/iu.exec(e);if(n?.[1])return canonicalRepository(n[1]);throw Error(`The origin remote is not a canonical GitHub repository URL.`)}function canonicalRepository(e){let t=e.replace(/\.git$/iu,``);if(!/^[A-Za-z0-9-]+\/[A-Za-z0-9._-]+$/u.test(t))throw Error(`Invalid GitHub repository ${JSON.stringify(e)}.`);return t}function declaredRepository(e){if(e.length!==1)throw Error(`Exactly one GitHub repository is required.`);let t=e[0],n=/^([A-Za-z0-9-]+)\/([A-Za-z0-9._-]+)$/u.exec(t);if(!n)throw Error(`Invalid GitHub repository ${JSON.stringify(t)}.`);return{repository:t,owner:n[1],name:n[2]}}function executablePath(e){return e===`gh`?GITHUB_TOOLING_PATHS.ghReal:e===`gh-signed-commit`?GITHUB_TOOLING_PATHS.trustedSignedCommit:`git`}function resolveWorkingDirectory(e,t){let n=posix.resolve(`/`,e.resolvePath(``)),r=posix.resolve(`/`,e.resolvePath(t?.trim()||``));if(r!==n&&!r.startsWith(`${n}/`))throw Error(`GitHub command workingDirectory must stay inside the sandbox workspace.`);return r}function sanitizeOutput(e,t,n){let r=e.replaceAll(t,`[redacted]`).replaceAll(n,`[redacted]`);return Buffer.byteLength(r)<=MAX_OUTPUT_BYTES?{value:r,truncated:!1}:{value:`[output truncated: showing final ${MAX_OUTPUT_BYTES} bytes]\n${Buffer.from(r).subarray(-1e5).toString()}`,truncated:!0}}function unsupportedSyntax(){return Error(`GitHub commands support argv syntax only, not pipes, redirects, substitutions, or shell operators.`)}export{executeGitHubShell,githubShellApproval,parseCommand};
1
+ import{attributeCommand,coAuthorTrailer,isAttributable}from"./attribution.js";import{connectUserAuthorization}from"./connect-user-auth.js";import{shellQuote}from"./shell.js";import{validateRepositoryRoot}from"./repository-root.js";import{GITHUB_TARGET}from"./github-shell-schema.js";import{GITHUB_TOOLING_PATHS}from"./tooling.js";import{posix}from"node:path";import{getToken}from"#compiled/@vercel/connect/index.js";const MAX_OUTPUT_BYTES=1e5,leaseQueues=new Map,EXECUTABLES=new Set([`gh`,`git`,`gh-signed-commit`]),GITHUB_UNAUTHORIZED=/HTTP 401\b|Bad credentials|Authentication failed for|failed: 401\b/u;function githubShellApproval(e){if(!e)return`not-applicable`;try{return validateGitHubShellInput(e),`not-applicable`}catch(e){return{type:`denied`,reason:e instanceof Error?e.message:`Invalid GitHub command.`}}}async function executeGitHubShell(e,t,n){if(!t)throw Error(`GitHub command access is not configured for this agent.`);let{argv:r,target:{owner:i,repository:a,name:o}}=validateGitHubShellInput(e);if(t.principalType===`user`?i&&!a:!i)throw Error(t.principalType===`user`?`Set repository to owner/name or omit it; user tokens are not scoped to an owner.`:`App tokens need repository set to an owner or owner/name.`);let s=await n.getSandbox(),c=resolveWorkingDirectory(s,e.workingDirectory);r[0]===`gh-signed-commit`&&(c=await validateRepositoryRoot(s,c));let l=crypto.randomUUID(),u=`/tmp/eve-git-body-${l}.md`,d=n.auth??null,f,p;if(t.principalType===`user`){if(!n.getToken||!n.requireAuth)throw Error(`User-scoped GitHub access requires ctx.getToken and ctx.requireAuth.`);f=connectUserAuthorization(t.connector),{token:p}=await n.getToken(f)}else{let e={type:`github_app_installation`,org:i};o&&(e.repositories=[o]),p=await(n.getConnectToken??getToken)(t.connector,{authorizationDetails:[e],subject:{type:`app`}})}if(!p)throw Error(`Connect returned an empty token for ${JSON.stringify(t.connector)}.`);if(!(t.principalType===`user`?await t.authorize({argv:r,auth:d,repository:a,token:p}):await t.authorize({argv:r,auth:d,owner:i,repository:a,token:p})))throw Error(`The current caller is not authorized to run this command${a?` on ${a}`:i?` for ${i}`:``}.`);let m=t.attribution&&n.context&&isAttributable(r)?await t.attribution(n.context):null,h=m?await attributeCommand(r,coAuthorTrailer(m),s,c,u):r,g=executablePath(h[0]),_=`cd ${shellQuote(c)} && exec ${shellQuote(g)} ${h.slice(1).map(shellQuote).join(` `)}`,v=`Basic ${Buffer.from(`x-access-token:${p}`).toString(`base64`)}`,y=`eve-github-${l}`,b=`/tmp/eve-code-gh-${l}`,x=`Basic ${Buffer.from(`x-access-token:${y}`).toString(`base64`)}`,S;try{S=await withGitHubCredentialLease(s,n.sessionId,{authorization:v,placeholder:y,placeholderAuthorization:x,token:p},()=>{let e={GH_CONFIG_DIR:b,GH_PROMPT_DISABLED:`1`};r[0]!==`git`&&(e.GH_TOKEN=y);let t=[[`http.https://github.com/.extraheader`,`Authorization: ${x}`],[`url.https://github.com/.insteadOf`,`git@github.com:`],[`url.https://github.com/.insteadOf`,`ssh://git@github.com/`],[`core.hooksPath`,`/dev/null`],[`protocol.allow`,`never`],[`protocol.https.allow`,`always`]];return e.GIT_CONFIG_COUNT=String(t.length),t.forEach(([t,n],r)=>{e[`GIT_CONFIG_KEY_${r}`]=t,e[`GIT_CONFIG_VALUE_${r}`]=n}),e.GIT_TERMINAL_PROMPT=`0`,e.PATH=`/usr/local/bin:/usr/bin:/bin`,s.run({command:_,env:e})},t.broker)}finally{await s.removePath({path:b,recursive:!0,force:!0}),await s.removePath({path:u,force:!0})}f&&S.exitCode!==0&&GITHUB_UNAUTHORIZED.test(S.stderr)&&n.requireAuth(f);let C=sanitizeOutput(S.stdout,p,v),w=sanitizeOutput(S.stderr,p,v);return{exitCode:S.exitCode,stdout:C.value,stderr:w.value,truncated:C.truncated||w.truncated}}async function withGitHubCredentialLease(e,t,n,r,i){let a=leaseQueues.get(t)??Promise.resolve(),o,s=new Promise(e=>{o=e}),c=a.then(()=>s);leaseQueues.set(t,c),await a;try{return await i(e,{"api.github.com":[{match:{headers:[{key:{exact:`authorization`},value:{regex:`^(?:token|Bearer) ${n.placeholder}$`}}]},transform:[{headers:{authorization:`Bearer ${n.token}`}}]}],"github.com":[{match:{headers:[{key:{exact:`authorization`},value:{exact:n.placeholderAuthorization}}]},transform:[{headers:{authorization:n.authorization}}]}]}),await r()}finally{try{await i(e,null)}finally{o(),leaseQueues.get(t)===c&&leaseQueues.delete(t)}}}function parseCommand(e){let t=e.trim();if(!t)throw Error(`GitHub command must not be empty.`);let n=[],r=``,i=null,a=!1,o=!1;for(let e of t){if(a){r+=e,a=!1,o=!0;continue}if(e===`\\`&&i!==`single`){a=!0,o=!0;continue}if(i===`single`){e===`'`?i=null:r+=e;continue}if(i===`double`){if(e===`"`)i=null;else if(e===`$`||e==="`")throw unsupportedSyntax();else r+=e;continue}if(e===`'`)i=`single`,o=!0;else if(e===`"`)i=`double`,o=!0;else if(/\s/u.test(e))o&&=(n.push(r),r=``,!1);else if(";&|<>$`(){}".includes(e))throw unsupportedSyntax();else r+=e,o=!0}if(a||i)throw Error(`GitHub command contains an unfinished quote or escape.`);if(o&&n.push(r),n.length===0)throw Error(`GitHub command must not be empty.`);return n}function validateGitHubShellInput(e){let t=parseCommand(e.command);if(!e.description.trim())throw Error(`description must describe the intended result.`);if(!EXECUTABLES.has(t[0]))throw Error(`GitHub commands must use gh, git, or gh-signed-commit.`);if(t.length<2)throw Error(`A ${t[0]} subcommand or argument is required.`);return{argv:t,target:declaredTarget(e.repository)}}function declaredTarget(e){let t=e?.trim();if(!t)return{owner:null,repository:null,name:null};let n=GITHUB_TARGET.exec(t.replace(/\.git$/iu,``));if(!n)throw Error(`Invalid GitHub repository or owner ${JSON.stringify(e)}.`);let[,r,i]=n;return{owner:r,repository:i?`${r}/${i}`:null,name:i??null}}function executablePath(e){return e===`gh`?GITHUB_TOOLING_PATHS.ghReal:e===`gh-signed-commit`?GITHUB_TOOLING_PATHS.trustedSignedCommit:`git`}function resolveWorkingDirectory(e,t){let n=posix.resolve(`/`,e.resolvePath(``)),r=posix.resolve(`/`,e.resolvePath(t?.trim()||``));if(r!==n&&!r.startsWith(`${n}/`))throw Error(`GitHub command workingDirectory must stay inside the sandbox workspace.`);return r}function sanitizeOutput(e,t,n){let r=e.replaceAll(t,`[redacted]`).replaceAll(n,`[redacted]`);return Buffer.byteLength(r)<=MAX_OUTPUT_BYTES?{value:r,truncated:!1}:{value:`[output truncated: showing final ${MAX_OUTPUT_BYTES} bytes]\n${Buffer.from(r).subarray(-1e5).toString()}`,truncated:!0}}function unsupportedSyntax(){return Error(`GitHub commands support argv syntax only, not pipes, redirects, substitutions, or shell operators.`)}export{executeGitHubShell,githubShellApproval,parseCommand};
@@ -15,7 +15,7 @@ for (let i = 0; i < args.length; i += 1) {
15
15
  if (!/^[A-Za-z0-9-]+\/[A-Za-z0-9._-]+$/.test(options.repo || "")) fail("--repo owner/name is required");
16
16
  if (!options.branch) fail("--branch is required");
17
17
  if (!options.message) fail("-m headline is required");
18
- if (!process.env.GH_TOKEN) fail('GH_TOKEN is not set; invoke the configured authenticated gh tool with command "gh-signed-commit --repo owner/name --branch branch -m headline", permissions [{"provider":"github","repositories":["owner/name"],"access":"write"}], a description of the intended commit, and workingDirectory set to the repository. Use the same repository for --repo and permissions; the tool supplies the scoped credential lease.');
18
+ if (!process.env.GH_TOKEN) fail('GH_TOKEN is not set; invoke the configured authenticated gh tool with command "gh-signed-commit --repo owner/name --branch branch -m headline", repository "owner/name", a description of the intended commit, and workingDirectory set to the repository. Use the same repository for --repo and repository; the tool supplies the credential lease.');
19
19
 
20
20
  const [owner, repo] = options.repo.split("/");
21
21
  const api = "https://api.github.com";
@@ -1,11 +1,7 @@
1
1
  /** The Connect-brokered `gh` tool, bound to the `eve/extensions/git` mount's `github` config. */
2
2
  export declare const gh: import("../../tools/definition.ts").ToolDefinition<{
3
3
  command: string;
4
- permissions: {
5
- provider: "github";
6
- repositories: string[];
7
- access: "write";
8
- }[];
4
+ repository?: string | undefined;
9
5
  description: string;
10
6
  workingDirectory?: string | undefined;
11
7
  }, {
@@ -16,11 +12,7 @@ export declare const gh: import("../../tools/definition.ts").ToolDefinition<{
16
12
  }> & {
17
13
  execute(input: {
18
14
  command: string;
19
- permissions: {
20
- provider: "github";
21
- repositories: string[];
22
- access: "write";
23
- }[];
15
+ repository?: string | undefined;
24
16
  description: string;
25
17
  workingDirectory?: string | undefined;
26
18
  }, ctx: import("../../tools/definition.ts").ToolContext): Promise<import("./extension/lib/github-shell.ts").GitHubShellOutput>;
@@ -1 +1 @@
1
- import{readGatewayRouting}from"#shared/gateway-routing.js";function withoutInstrumentationContent(e){return withInstrumentationDecision(e,{action:`record`,recordInputs:!1,recordOutputs:!1})}function withInstrumentationDecision(e,t){switch(e.type){case`session.started`:return t.recordInputs?e:Object.freeze({...e,title:void 0});case`call.requested`:return t.recordInputs?e:Object.freeze({...e,input:void 0,capability:Object.freeze({...e.capability,label:void 0})});case`delivery.consumed`:case`model.call.started`:return t.recordInputs?e:Object.freeze({...e,input:void 0});case`interaction.opened`:return t.recordOutputs?e:Object.freeze({...e,request:void 0});case`interaction.settled`:return Object.freeze({...e,error:t.recordOutputs?e.error:void 0,answer:t.recordInputs?e.answer:void 0});case`call.settled`:return t.recordOutputs?e:Object.freeze({...e,error:void 0,output:void 0});case`model.call.settled`:return e.outcome===`failed`?t.recordOutputs?e:Object.freeze({...e,error:void 0}):t.recordOutputs?e:Object.freeze({...e,content:void 0,providerMetadata:e.providerMetadata===void 0?void 0:structuralProviderMetadata(e.providerMetadata)});case`memory.operation.settled`:return e.outcome===`failed`?t.recordOutputs?e:Object.freeze({...e,error:void 0}):t.recordInputs?e:Object.freeze({...e,outputRecords:void 0});case`model.retried`:case`model.settled`:case`session.ended`:case`turn.settled`:return t.recordOutputs?e:Object.freeze({...e,error:void 0});default:return e}}function structuralProviderMetadata(e){let t=e.gateway;if(typeof t!=`object`||!t||Array.isArray(t))return Object.freeze({});let n=t,r={};for(let e of[`cost`,`generationId`]){let t=n[e];(typeof t==`string`||typeof t==`number`)&&(r[e]=t)}let i=readGatewayRouting(n.routing);return i!==void 0&&(r.routing=i),Object.freeze(Object.keys(r).length===0?{}:{gateway:Object.freeze(r)})}export{structuralProviderMetadata,withInstrumentationDecision,withoutInstrumentationContent};
1
+ import{applyPrincipalTraceDecision}from"#instrumentation/principal-summary.js";import{readGatewayRouting}from"#shared/gateway-routing.js";function withoutInstrumentationContent(e){return withInstrumentationDecision(e,{action:`record`,recordInputs:!1,recordOutputs:!1})}function withInstrumentationDecision(e,t){switch(e.type){case`session.started`:return t.recordInputs?e:Object.freeze({...e,title:void 0});case`call.requested`:return t.recordInputs?e:Object.freeze({...e,input:void 0,capability:Object.freeze({...e.capability,label:void 0})});case`delivery.consumed`:case`model.call.started`:return t.recordInputs?e:Object.freeze({...e,input:void 0});case`interaction.opened`:return t.recordOutputs?e:Object.freeze({...e,request:void 0});case`interaction.settled`:return Object.freeze({...e,error:t.recordOutputs?e.error:void 0,answer:t.recordInputs?e.answer:void 0,responder:applyPrincipalTraceDecision(e.responder,t)});case`call.settled`:return t.recordOutputs?e:Object.freeze({...e,error:void 0,output:void 0});case`model.call.settled`:return e.outcome===`failed`?t.recordOutputs?e:Object.freeze({...e,error:void 0}):t.recordOutputs?e:Object.freeze({...e,content:void 0,providerMetadata:e.providerMetadata===void 0?void 0:structuralProviderMetadata(e.providerMetadata)});case`memory.operation.settled`:return e.outcome===`failed`?t.recordOutputs?e:Object.freeze({...e,error:void 0}):t.recordInputs?e:Object.freeze({...e,outputRecords:void 0});case`model.retried`:case`model.settled`:case`session.ended`:case`turn.settled`:return t.recordOutputs?e:Object.freeze({...e,error:void 0});default:return e}}function structuralProviderMetadata(e){let t=e.gateway;if(typeof t!=`object`||!t||Array.isArray(t))return Object.freeze({});let n=t,r={};for(let e of[`cost`,`generationId`]){let t=n[e];(typeof t==`string`||typeof t==`number`)&&(r[e]=t)}let i=readGatewayRouting(n.routing);return i!==void 0&&(r.routing=i),Object.freeze(Object.keys(r).length===0?{}:{gateway:Object.freeze(r)})}export{structuralProviderMetadata,withInstrumentationDecision,withoutInstrumentationContent};