@spunto/build 0.28.2 → 0.28.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spunto/build",
3
- "version": "0.28.2",
3
+ "version": "0.28.4",
4
4
  "description": "Spunto's shared Build engine — the devcontainer image protocol and VS Code extension registry clients, with no database, no HTTP framework and no UI.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -16,7 +16,8 @@
16
16
  // (`./catalogs.ts`): `{"effort":"high"}`
17
17
  // SPUNTO_AGENT_MCP — the org's MCP servers (RFC 0049), in the platform's words:
18
18
  // `[{"name":"linear","path":"/api/mcp-gateway/…"}]`, reached through the platform's
19
- // gateway with the machine's own identity (`SPUNTO_WORKER_TOKEN`)
19
+ // gateway with the machine's own identity (`SPUNTO_WORKER_TOKEN`), and reconnected
20
+ // before each turn after the first, so a server's new tools reach a running session
20
21
  // SPUNTO_AGENT_STREAM — "1": also print the tokens of a message as they are written
21
22
  // (`stream_event` lines), set behind the org flag `token-streaming`
22
23
  // exit 0 once the input is closed and the last turn is over, 1 when the session could not run
@@ -176,6 +177,25 @@ const session = sdk.query({
176
177
  },
177
178
  })
178
179
 
180
+ /**
181
+ * The gateway's servers are connected once, when the process starts, and the session lives as long
182
+ * as the task: a server redeployed with new tools since would stay invisible until the task ends.
183
+ * So before a turn that comes after the session went idle, each is reconnected — which lists its
184
+ * tools again (~30 ms each, measured with the SDK 0.3.310). Never during a turn: that could cut a
185
+ * call in flight. A server that fails to reconnect keeps the tools it had.
186
+ */
187
+ let idle = false
188
+ let ahead = Promise.resolve()
189
+ async function refreshMcpServers() {
190
+ if (!idle) return
191
+ idle = false
192
+ await Promise.all(
193
+ Object.keys(mcpServers).map((name) =>
194
+ session.reconnectMcpServer(name).catch((err) => process.stderr.write(`claude runner: reconnecting ${name} failed: ${err?.message ?? err}\n`)),
195
+ ),
196
+ )
197
+ }
198
+
179
199
  createInterface({ input: process.stdin, crlfDelay: Infinity })
180
200
  .on("line", (line) => {
181
201
  let msg
@@ -186,7 +206,9 @@ createInterface({ input: process.stdin, crlfDelay: Infinity })
186
206
  }
187
207
  if (!msg || typeof msg !== "object") return
188
208
  if (msg.type === "user" && typeof msg.text === "string") {
189
- input.push({ type: "user", message: { role: "user", content: [{ type: "text", text: msg.text }] }, parent_tool_use_id: null })
209
+ const turn = { type: "user", message: { role: "user", content: [{ type: "text", text: msg.text }] }, parent_tool_use_id: null }
210
+ // Chained, so that a turn refreshed between two others still goes in the order it was sent.
211
+ ahead = ahead.then(refreshMcpServers).then(() => input.push(turn))
190
212
  } else if (msg.type === "interrupt") {
191
213
  session.interrupt().catch((err) => process.stderr.write(`claude runner: interrupt failed: ${err?.message ?? err}\n`))
192
214
  } else if (msg.type === "title" && typeof msg.description === "string") {
@@ -210,6 +232,7 @@ try {
210
232
  for await (const message of session) {
211
233
  await emit(message)
212
234
  lastType = message?.type ?? null
235
+ if (lastType === "result") idle = true
213
236
  }
214
237
  } catch (err) {
215
238
  if (lastType === "result") process.exit(1)
@@ -278,10 +278,12 @@ while IFS= read -r line; do
278
278
  esac
279
279
  done
280
280
  REPO="\${REPO%.git}"
281
- RESPONSE=$(curl -fsS -m 20 -X POST "$SPUNTO_API_URL/api/workers/git-credential" -H "Authorization: Bearer $SPUNTO_WORKER_TOKEN" -H "Content-Type: application/json" -d "{\\"repo\\":\\"$REPO\\"}" 2>/dev/null)
281
+ # No -f: a refusal's body says why (which account the member authorized, what to do about it).
282
+ RESPONSE=$(curl -sS -m 20 -X POST "$SPUNTO_API_URL/api/workers/git-credential" -H "Authorization: Bearer $SPUNTO_WORKER_TOKEN" -H "Content-Type: application/json" -d "{\\"repo\\":\\"$REPO\\"}" 2>/dev/null)
282
283
  PASSWORD=$(printf "%s" "$RESPONSE" | sed -n 's/.*"password":"\\([^"]*\\)".*/\\1/p')
283
284
  if [ -z "$PASSWORD" ]; then
284
- echo "spunto: no git credential for $REPO - authorize the provider in Integrations." >&2
285
+ REASON=$(printf "%s" "$RESPONSE" | sed -n 's/.*"error":"\\([^"]*\\)".*/\\1/p')
286
+ echo "spunto: no git credential for $REPO - \${REASON:-authorize the provider in Integrations.}" >&2
285
287
  exit 0
286
288
  fi
287
289
  USERNAME=$(printf "%s" "$RESPONSE" | sed -n 's/.*"username":"\\([^"]*\\)".*/\\1/p')