@obtoai/agent-bridge 0.1.0-beta.10 → 0.1.0-beta.11

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/daemon.js +38 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obtoai/agent-bridge",
3
- "version": "0.1.0-beta.10",
3
+ "version": "0.1.0-beta.11",
4
4
  "description": "Local consumer for the OBTO Agent Bridge. Receives bridge events over SSE and drives a coding agent (Claude Code or OpenAI Codex) on your machine.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "OBTO Inc.",
package/src/daemon.js CHANGED
@@ -102,7 +102,43 @@ const handleEvent = async (sseEvent) => {
102
102
 
103
103
  // v1.1 — which agent this thread is bound to (server-set, on the event).
104
104
  const agent = agentFor(payload);
105
- const session = getAgentSession(state, threadId, agent);
105
+ let session = getAgentSession(state, threadId, agent);
106
+ let wasAdoption = false;
107
+
108
+ // Phase 6.2 — adopt external session on first turn. The bridge attaches
109
+ // `externalAdoption: {sessionId, projectDir, projectName, source}` to the
110
+ // reply payload for adopted threads. With no prior session for this
111
+ // (thread, agent), synthesize a binding pointing at the original engine
112
+ // session so the driver resumes it instead of first-touching fresh —
113
+ // context preserved end-to-end. After the first successful drive, the
114
+ // session is persisted to state.json and externalAdoption stops mattering.
115
+ if (!session && payload.externalAdoption && payload.externalAdoption.sessionId) {
116
+ const ea = payload.externalAdoption;
117
+ // Prefer projectName (already-decoded filesystem path) for cwd. Claude
118
+ // scanner emits both raw `-Users-foo` and decoded `/Users/foo`; the
119
+ // decoded form is what the SDK's cwd argument expects.
120
+ let resumeCwd = ea.projectName || ea.projectDir || cfg.projectDir;
121
+ if (typeof resumeCwd === 'string' && resumeCwd.startsWith('//')) {
122
+ resumeCwd = '/' + resumeCwd.replace(/^\/+/, '');
123
+ }
124
+ session = {
125
+ sessionId: ea.sessionId,
126
+ projectDir: resumeCwd,
127
+ jsonlPath: null,
128
+ lastJsonlMtimeMs: null,
129
+ createdAt: new Date().toISOString(),
130
+ lastDriveAt: null,
131
+ };
132
+ wasAdoption = true;
133
+ log('info', 'adopting external session on first touch', {
134
+ threadId,
135
+ agent,
136
+ sessionId: ea.sessionId,
137
+ cwd: resumeCwd,
138
+ source: ea.source,
139
+ });
140
+ }
141
+
106
142
  log('event', 'reply received', {
107
143
  threadId,
108
144
  agent,
@@ -135,7 +171,7 @@ const handleEvent = async (sseEvent) => {
135
171
  if (
136
172
  result &&
137
173
  result.sessionId &&
138
- (!session || session.sessionId !== result.sessionId)
174
+ (!session || session.sessionId !== result.sessionId || wasAdoption)
139
175
  ) {
140
176
  setAgentSession(
141
177
  state,