@genspark/cli 1.14.2 → 1.15.1-beta.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 (59) hide show
  1. package/README.md +43 -1
  2. package/dist/client.d.ts +6 -0
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +32 -6
  5. package/dist/client.js.map +1 -1
  6. package/dist/commands/aidrive-contract.generated.d.ts.map +1 -1
  7. package/dist/commands/aidrive-contract.generated.js +141 -4
  8. package/dist/commands/aidrive-contract.generated.js.map +1 -1
  9. package/dist/commands/aidrive-upload.js +2 -1
  10. package/dist/commands/aidrive-upload.js.map +1 -1
  11. package/dist/commands/sb-box-session.d.ts +128 -0
  12. package/dist/commands/sb-box-session.d.ts.map +1 -0
  13. package/dist/commands/sb-box-session.js +477 -0
  14. package/dist/commands/sb-box-session.js.map +1 -0
  15. package/dist/config.d.ts +43 -0
  16. package/dist/config.d.ts.map +1 -1
  17. package/dist/config.js +46 -0
  18. package/dist/config.js.map +1 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +178 -31
  21. package/dist/index.js.map +1 -1
  22. package/dist/native-waf.d.ts +24 -0
  23. package/dist/native-waf.d.ts.map +1 -0
  24. package/dist/native-waf.js +183 -0
  25. package/dist/native-waf.js.map +1 -0
  26. package/dist/object-args.d.ts +4 -0
  27. package/dist/object-args.d.ts.map +1 -0
  28. package/dist/object-args.js +34 -0
  29. package/dist/object-args.js.map +1 -0
  30. package/dist/project-binding.d.ts.map +1 -1
  31. package/dist/project-binding.js +14 -2
  32. package/dist/project-binding.js.map +1 -1
  33. package/dist/types.d.ts +1 -0
  34. package/dist/types.d.ts.map +1 -1
  35. package/dist/updater.d.ts +5 -0
  36. package/dist/updater.d.ts.map +1 -1
  37. package/dist/updater.js +30 -3
  38. package/dist/updater.js.map +1 -1
  39. package/docs/skills.md +9 -7
  40. package/package.json +1 -1
  41. package/skills/gsk-aidrive/SKILL.md +241 -27
  42. package/skills/gsk-audio-generation/SKILL.md +1 -1
  43. package/skills/gsk-audio-transcribe/SKILL.md +5 -2
  44. package/skills/gsk-calendar-search/SKILL.md +42 -0
  45. package/skills/gsk-calendar-source/SKILL.md +44 -0
  46. package/skills/gsk-connector/SKILL.md +34 -7
  47. package/skills/gsk-create-task/SKILL.md +1 -1
  48. package/skills/gsk-genteam/SKILL.md +4 -2
  49. package/skills/gsk-github/SKILL.md +4 -3
  50. package/skills/gsk-google-drive/SKILL.md +6 -5
  51. package/skills/gsk-google-sheets/SKILL.md +1 -1
  52. package/skills/gsk-image-generation/SKILL.md +3 -1
  53. package/skills/gsk-meeting/SKILL.md +1 -1
  54. package/skills/gsk-notion/SKILL.md +2 -2
  55. package/skills/gsk-onedrive/SKILL.md +6 -4
  56. package/skills/gsk-second-brain/SKILL.md +2 -2
  57. package/skills/gsk-shared/SKILL.md +4 -3
  58. package/skills/gsk-sharepoint/SKILL.md +6 -5
  59. package/skills/gsk-video-generation/SKILL.md +2 -1
@@ -0,0 +1,128 @@
1
+ /**
2
+ * `gsk sb-box … --session <key>` — a client-side session → sandbox binding.
3
+ *
4
+ * Why: an agent that drives sandboxes from its shell has to carry the
5
+ * `sbx-…` id from one command to the next itself, and a tool wrapper
6
+ * (the former opencode `python.ts`) had to keep its own id file to give a
7
+ * conversation one stateful interpreter. Both are the same bookkeeping, so
8
+ * it lives here once: a key names the session, the CLI remembers which
9
+ * sandbox belongs to it, checks the sandbox is still alive before reuse and
10
+ * creates a new one when it is not.
11
+ *
12
+ * Why client-side: the backend tool is stateless per call and shared by
13
+ * REST users and in-product agents; the binding is a convenience of THIS
14
+ * process (like `--args-file` or sb-git's `--execute`). Nothing is sent to
15
+ * the server that it does not already accept — the resolved id goes out as
16
+ * the ordinary `sandbox_id` parameter.
17
+ *
18
+ * Key resolution (first hit wins): `--session <key>`, then the
19
+ * `GSK_SB_BOX_SESSION` env var, then the session id a host agent exports
20
+ * (`CLAUDE_CODE_SESSION_ID`). An explicit `--sandbox_id` always wins over
21
+ * all of them and leaves the binding untouched.
22
+ *
23
+ * Bindings live in `<config dir>/sb-box-sessions.json`, scoped by the API
24
+ * host so a dev and a prod key never resolve to each other's sandboxes.
25
+ */
26
+ import type { ApiResponse } from '../types.js';
27
+ export declare const SESSION_ENV = "GSK_SB_BOX_SESSION";
28
+ /** Session ids host agents export into the shells they spawn. */
29
+ export declare const HOST_SESSION_ENVS: readonly ["CLAUDE_CODE_SESSION_ID"];
30
+ export declare const SESSIONS_FILE = "sb-box-sessions.json";
31
+ /** Actions that address a sandbox (the server's "Required for" list). */
32
+ export declare const SANDBOX_ACTIONS: Set<string>;
33
+ /**
34
+ * Actions that may START a session's sandbox when it has none (or its last
35
+ * one is gone): the ones that put work on a machine. Reads, lifecycle and
36
+ * inspection never create — a `kill`/`get`/`read` on an empty session is a
37
+ * mistake worth surfacing, not a reason to bill a new sandbox.
38
+ */
39
+ export declare const CREATING_ACTIONS: Set<string>;
40
+ /**
41
+ * States in which the bound sandbox is reusable. frozen / paused are fine:
42
+ * the next data-plane call resumes it with its files and interpreter state.
43
+ */
44
+ export declare const ALIVE_STATES: Set<string>;
45
+ export declare class SessionError extends Error {
46
+ }
47
+ export interface SessionKey {
48
+ key: string;
49
+ source: 'flag' | typeof SESSION_ENV | (typeof HOST_SESSION_ENVS)[number];
50
+ }
51
+ /**
52
+ * Pick the session key for this invocation. `explicit` is the `--session`
53
+ * flag value; the env fallbacks make a host-spawned shell "just work"
54
+ * without the model ever handling an id.
55
+ */
56
+ export declare function resolveSessionKey(explicit: unknown, env?: NodeJS.ProcessEnv): SessionKey | undefined;
57
+ export interface SessionBinding {
58
+ sandbox_id: string;
59
+ template?: string;
60
+ updated_at: string;
61
+ }
62
+ export declare class SessionStore {
63
+ private readonly filePath;
64
+ private readonly scope;
65
+ constructor(filePath: string, scope: string);
66
+ private lockDir;
67
+ /**
68
+ * Run `fn` while holding this key's lock. `fn` receives `held()`, which
69
+ * re-reads the lock's owner: a holder about to commit something it must
70
+ * not do twice (bind a freshly created sandbox) checks it, because an
71
+ * eviction race can in theory move a live lock aside — see `evict`.
72
+ */
73
+ withLock<T>(key: string, fn: (held: () => boolean) => Promise<T>): Promise<T>;
74
+ static forConfig(configPath: string, baseUrl: string): SessionStore;
75
+ private readAll;
76
+ private writeAll;
77
+ get(key: string): SessionBinding | undefined;
78
+ set(key: string, binding: Omit<SessionBinding, 'updated_at'>): void;
79
+ delete(key: string): void;
80
+ }
81
+ /** Bindings are per API host: a dev and a prod key must never cross. */
82
+ export declare function scopeOf(baseUrl: string): string;
83
+ /** Newest ready public base template, the default when none is named. */
84
+ export declare function pickDefaultTemplate(templates: unknown): string | undefined;
85
+ /**
86
+ * `gsk sb-box create` with no --template: the newest ready public base
87
+ * (CLI-side default; the server still requires a template — it just
88
+ * receives the one picked here). Throws when the catalog has none.
89
+ */
90
+ export declare function defaultTemplate(call: ToolCall): Promise<string>;
91
+ export type ToolCall = (args: Record<string, unknown>) => Promise<ApiResponse>;
92
+ export interface BindResult {
93
+ key: SessionKey;
94
+ sandbox_id: string;
95
+ /** true when this invocation created the sandbox */
96
+ created: boolean;
97
+ /** state of the bound sandbox when it was reused */
98
+ state?: string;
99
+ }
100
+ /**
101
+ * Resolve the sandbox for a session before the real call: reuse the bound
102
+ * one if it is alive, otherwise create (for CREATING_ACTIONS) or fail with
103
+ * a message that says what to do. `args` is mutated: `sandbox_id` is set,
104
+ * and `template` (a create-only parameter) is consumed when a sandbox had
105
+ * to be created.
106
+ */
107
+ export declare function bindSession(opts: {
108
+ key: SessionKey;
109
+ action: string;
110
+ args: Record<string, unknown>;
111
+ call: ToolCall;
112
+ store: SessionStore;
113
+ log?: (line: string) => void;
114
+ }): Promise<BindResult>;
115
+ /**
116
+ * After the real call: keep the binding in step with explicit lifecycle
117
+ * actions (`create --session` binds the new sandbox, a successful `kill`
118
+ * drops it) and echo the binding on the envelope so a caller that never
119
+ * saw the id learns it once.
120
+ */
121
+ export declare function afterSessionCall(opts: {
122
+ key: SessionKey;
123
+ action: string;
124
+ bind: BindResult | undefined;
125
+ result: ApiResponse;
126
+ store: SessionStore;
127
+ }): void;
128
+ //# sourceMappingURL=sb-box-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sb-box-session.d.ts","sourceRoot":"","sources":["../../src/commands/sb-box-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAMH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,eAAO,MAAM,WAAW,uBAAuB,CAAA;AAC/C,iEAAiE;AACjE,eAAO,MAAM,iBAAiB,qCAAsC,CAAA;AACpE,eAAO,MAAM,aAAa,yBAAyB,CAAA;AAEnD,yEAAyE;AACzE,eAAO,MAAM,eAAe,aAe1B,CAAA;AACF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,aAAyC,CAAA;AACtE;;;GAGG;AACH,eAAO,MAAM,YAAY,aAQvB,CAAA;AAIF,qBAAa,YAAa,SAAQ,KAAK;CAAG;AAE1C,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,GAAG,OAAO,WAAW,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;CACzE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,OAAO,EACjB,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,UAAU,GAAG,SAAS,CAWxB;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;CACnB;AAoCD,qBAAa,YAAY;IAErB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM;IAGhC,OAAO,CAAC,OAAO;IASf;;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,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,IAAI,EAAE,QAAQ,CAAA;IACd,KAAK,EAAE,YAAY,CAAA;IACnB,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAC7B,GAAG,OAAO,CAAC,UAAU,CAAC,CAOtB;AA6HD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,GAAG,EAAE,UAAU,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,UAAU,GAAG,SAAS,CAAA;IAC5B,MAAM,EAAE,WAAW,CAAA;IACnB,KAAK,EAAE,YAAY,CAAA;CACpB,GAAG,IAAI,CAwBP"}
@@ -0,0 +1,477 @@
1
+ /**
2
+ * `gsk sb-box … --session <key>` — a client-side session → sandbox binding.
3
+ *
4
+ * Why: an agent that drives sandboxes from its shell has to carry the
5
+ * `sbx-…` id from one command to the next itself, and a tool wrapper
6
+ * (the former opencode `python.ts`) had to keep its own id file to give a
7
+ * conversation one stateful interpreter. Both are the same bookkeeping, so
8
+ * it lives here once: a key names the session, the CLI remembers which
9
+ * sandbox belongs to it, checks the sandbox is still alive before reuse and
10
+ * creates a new one when it is not.
11
+ *
12
+ * Why client-side: the backend tool is stateless per call and shared by
13
+ * REST users and in-product agents; the binding is a convenience of THIS
14
+ * process (like `--args-file` or sb-git's `--execute`). Nothing is sent to
15
+ * the server that it does not already accept — the resolved id goes out as
16
+ * the ordinary `sandbox_id` parameter.
17
+ *
18
+ * Key resolution (first hit wins): `--session <key>`, then the
19
+ * `GSK_SB_BOX_SESSION` env var, then the session id a host agent exports
20
+ * (`CLAUDE_CODE_SESSION_ID`). An explicit `--sandbox_id` always wins over
21
+ * all of them and leaves the binding untouched.
22
+ *
23
+ * Bindings live in `<config dir>/sb-box-sessions.json`, scoped by the API
24
+ * host so a dev and a prod key never resolve to each other's sandboxes.
25
+ */
26
+ import * as crypto from 'crypto';
27
+ import * as fs from 'fs';
28
+ import * as path from 'path';
29
+ export const SESSION_ENV = 'GSK_SB_BOX_SESSION';
30
+ /** Session ids host agents export into the shells they spawn. */
31
+ export const HOST_SESSION_ENVS = ['CLAUDE_CODE_SESSION_ID'];
32
+ export const SESSIONS_FILE = 'sb-box-sessions.json';
33
+ /** Actions that address a sandbox (the server's "Required for" list). */
34
+ export const SANDBOX_ACTIONS = new Set([
35
+ 'get',
36
+ 'kill',
37
+ 'exec',
38
+ 'run-code',
39
+ 'write',
40
+ 'read',
41
+ 'ls',
42
+ 'freeze',
43
+ 'pause',
44
+ 'resume',
45
+ 'rollback',
46
+ 'clone',
47
+ 'versions',
48
+ 'timeout',
49
+ ]);
50
+ /**
51
+ * Actions that may START a session's sandbox when it has none (or its last
52
+ * one is gone): the ones that put work on a machine. Reads, lifecycle and
53
+ * inspection never create — a `kill`/`get`/`read` on an empty session is a
54
+ * mistake worth surfacing, not a reason to bill a new sandbox.
55
+ */
56
+ export const CREATING_ACTIONS = new Set(['exec', 'run-code', 'write']);
57
+ /**
58
+ * States in which the bound sandbox is reusable. frozen / paused are fine:
59
+ * the next data-plane call resumes it with its files and interpreter state.
60
+ */
61
+ export const ALIVE_STATES = new Set([
62
+ 'starting',
63
+ 'running',
64
+ 'freezing',
65
+ 'frozen',
66
+ 'pausing',
67
+ 'paused',
68
+ 'resuming',
69
+ ]);
70
+ /** The public base template line (`gsk sb-box templates`, namespace public). */
71
+ const PUBLIC_BASE_RE = /^sb-box-base-/;
72
+ export class SessionError extends Error {
73
+ }
74
+ /**
75
+ * Pick the session key for this invocation. `explicit` is the `--session`
76
+ * flag value; the env fallbacks make a host-spawned shell "just work"
77
+ * without the model ever handling an id.
78
+ */
79
+ export function resolveSessionKey(explicit, env = process.env) {
80
+ if (typeof explicit === 'string' && explicit.trim()) {
81
+ return { key: explicit.trim(), source: 'flag' };
82
+ }
83
+ const own = env[SESSION_ENV];
84
+ if (own && own.trim())
85
+ return { key: own.trim(), source: SESSION_ENV };
86
+ for (const name of HOST_SESSION_ENVS) {
87
+ const value = env[name];
88
+ if (value && value.trim())
89
+ return { key: value.trim(), source: name };
90
+ }
91
+ return undefined;
92
+ }
93
+ /**
94
+ * Cross-process lock for one session key (parallel first calls from an
95
+ * agent are common: two `write`s fired together must end up on ONE
96
+ * sandbox, not create two and overwrite each other's binding). mkdir is
97
+ * atomic on every platform; a lock older than STALE_MS is a crashed owner.
98
+ */
99
+ const LOCK_WAIT_MS = 90_000; // a create + interpreter start fits comfortably
100
+ // Only reached when the owner pid cannot be checked (foreign host, unreadable
101
+ // pid file): a live owner is never evicted, a dead one is evicted at once.
102
+ const LOCK_STALE_MS = LOCK_WAIT_MS;
103
+ const sleep = (ms) => new Promise(r => setTimeout(r, ms));
104
+ /** The pid recorded in a lock, if readable and plausible. */
105
+ function lockOwnerPid(dir) {
106
+ try {
107
+ const pid = fs.readFileSync(path.join(dir, 'pid'), 'utf8').trim();
108
+ return /^[1-9]\d*$/.test(pid) ? pid : undefined;
109
+ }
110
+ catch {
111
+ return undefined; // no pid yet (owner between mkdir and write) or unreadable
112
+ }
113
+ }
114
+ /** Is the process with this pid alive on this host? */
115
+ function lockOwnerPidAlive(pid) {
116
+ try {
117
+ process.kill(Number(pid), 0);
118
+ return true;
119
+ }
120
+ catch (err) {
121
+ return err.code === 'EPERM';
122
+ }
123
+ }
124
+ export class SessionStore {
125
+ filePath;
126
+ scope;
127
+ constructor(filePath, scope) {
128
+ this.filePath = filePath;
129
+ this.scope = scope;
130
+ }
131
+ lockDir(key) {
132
+ const h = crypto
133
+ .createHash('sha1')
134
+ .update(`${this.scope}\u0000${key}`)
135
+ .digest('hex')
136
+ .slice(0, 16);
137
+ return `${this.filePath}.${h}.lock`;
138
+ }
139
+ /**
140
+ * Run `fn` while holding this key's lock. `fn` receives `held()`, which
141
+ * re-reads the lock's owner: a holder about to commit something it must
142
+ * not do twice (bind a freshly created sandbox) checks it, because an
143
+ * eviction race can in theory move a live lock aside — see `evict`.
144
+ */
145
+ async withLock(key, fn) {
146
+ const dir = this.lockDir(key);
147
+ fs.mkdirSync(path.dirname(dir), { recursive: true, mode: 0o700 });
148
+ const deadline = Date.now() + LOCK_WAIT_MS;
149
+ // Only the owner removes the lock: a waiter that evicted and re-took it
150
+ // is a new owner, and this process must not pull the lock out from
151
+ // under it on its own exit path.
152
+ const release = () => {
153
+ try {
154
+ const pid = fs.readFileSync(path.join(dir, 'pid'), 'utf8').trim();
155
+ if (pid !== String(process.pid))
156
+ return;
157
+ fs.rmSync(dir, { recursive: true, force: true });
158
+ }
159
+ catch {
160
+ /* already gone or not ours */
161
+ }
162
+ };
163
+ const held = () => {
164
+ try {
165
+ return (fs.readFileSync(path.join(dir, 'pid'), 'utf8').trim() ===
166
+ String(process.pid));
167
+ }
168
+ catch {
169
+ return false;
170
+ }
171
+ };
172
+ // Eviction is an atomic rename, then a check: of several waiters that
173
+ // saw the same dead owner exactly one rename succeeds. If what it moved
174
+ // turns out to be a LIVE lock (a waiter that evicted and re-took it in
175
+ // between), it is put back; should even that fail — a third process
176
+ // took the slot in the same instant — the displaced holder notices via
177
+ // `held()` before it commits and reconciles instead of double-binding.
178
+ const evict = (deadPid) => {
179
+ const tomb = `${dir}.evicted.${process.pid}.${Date.now()}`;
180
+ try {
181
+ fs.renameSync(dir, tomb);
182
+ }
183
+ catch {
184
+ return false;
185
+ }
186
+ let movedPid;
187
+ try {
188
+ movedPid = fs.readFileSync(path.join(tomb, 'pid'), 'utf8').trim();
189
+ }
190
+ catch {
191
+ movedPid = undefined;
192
+ }
193
+ if (movedPid !== deadPid && movedPid && lockOwnerPidAlive(movedPid)) {
194
+ try {
195
+ fs.renameSync(tomb, dir);
196
+ }
197
+ catch {
198
+ fs.rmSync(tomb, { recursive: true, force: true });
199
+ }
200
+ return false;
201
+ }
202
+ fs.rmSync(tomb, { recursive: true, force: true });
203
+ return true;
204
+ };
205
+ for (;;) {
206
+ try {
207
+ fs.mkdirSync(dir);
208
+ // Owner pid inside the lock: a lock left by a process that died
209
+ // mid-create (Ctrl+C, SIGKILL, crash) is recognised and evicted by
210
+ // the next command instead of blocking it for the full wait.
211
+ fs.writeFileSync(path.join(dir, 'pid'), String(process.pid));
212
+ break;
213
+ }
214
+ catch (err) {
215
+ if (err.code !== 'EEXIST')
216
+ throw err;
217
+ try {
218
+ const ownerPid = lockOwnerPid(dir);
219
+ const alive = ownerPid === undefined ? undefined : lockOwnerPidAlive(ownerPid);
220
+ if (alive === false ||
221
+ (alive === undefined &&
222
+ Date.now() - fs.statSync(dir).mtimeMs > LOCK_STALE_MS)) {
223
+ evict(ownerPid);
224
+ continue;
225
+ }
226
+ }
227
+ catch {
228
+ continue; // vanished between the two calls: retry at once
229
+ }
230
+ if (Date.now() > deadline) {
231
+ throw new SessionError(`session ${key}: another gsk process has held the session lock ` +
232
+ `for over ${LOCK_WAIT_MS / 1000}s (${dir}); remove it if that ` +
233
+ 'process is gone.');
234
+ }
235
+ await sleep(50 + Math.floor(Math.random() * 50));
236
+ }
237
+ }
238
+ // Release on every exit path, including a signal that would otherwise
239
+ // skip `finally` (Node's default SIGINT/SIGTERM handling exits at once).
240
+ const onSignal = (signal) => {
241
+ release();
242
+ process.exit(signal === 'SIGINT' ? 130 : 143);
243
+ };
244
+ process.once('SIGINT', onSignal);
245
+ process.once('SIGTERM', onSignal);
246
+ process.once('exit', release);
247
+ try {
248
+ return await fn(held);
249
+ }
250
+ finally {
251
+ release();
252
+ process.removeListener('SIGINT', onSignal);
253
+ process.removeListener('SIGTERM', onSignal);
254
+ process.removeListener('exit', release);
255
+ }
256
+ }
257
+ static forConfig(configPath, baseUrl) {
258
+ return new SessionStore(path.join(path.dirname(configPath), SESSIONS_FILE), scopeOf(baseUrl));
259
+ }
260
+ readAll() {
261
+ try {
262
+ const parsed = JSON.parse(fs.readFileSync(this.filePath, 'utf8'));
263
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
264
+ ? parsed
265
+ : {};
266
+ }
267
+ catch {
268
+ return {};
269
+ }
270
+ }
271
+ writeAll(all) {
272
+ fs.mkdirSync(path.dirname(this.filePath), { recursive: true, mode: 0o700 });
273
+ const tmp = `${this.filePath}.${process.pid}.tmp`;
274
+ fs.writeFileSync(tmp, JSON.stringify(all, null, 2) + '\n', { mode: 0o600 });
275
+ fs.renameSync(tmp, this.filePath);
276
+ }
277
+ get(key) {
278
+ return this.readAll()[this.scope]?.[key];
279
+ }
280
+ set(key, binding) {
281
+ const all = this.readAll();
282
+ all[this.scope] = all[this.scope] ?? {};
283
+ all[this.scope][key] = { ...binding, updated_at: new Date().toISOString() };
284
+ this.writeAll(all);
285
+ }
286
+ delete(key) {
287
+ const all = this.readAll();
288
+ if (!all[this.scope]?.[key])
289
+ return;
290
+ delete all[this.scope][key];
291
+ if (Object.keys(all[this.scope]).length === 0)
292
+ delete all[this.scope];
293
+ this.writeAll(all);
294
+ }
295
+ }
296
+ /** Bindings are per API host: a dev and a prod key must never cross. */
297
+ export function scopeOf(baseUrl) {
298
+ try {
299
+ return new URL(baseUrl).host;
300
+ }
301
+ catch {
302
+ return baseUrl;
303
+ }
304
+ }
305
+ /** Newest ready public base template, the default when none is named. */
306
+ export function pickDefaultTemplate(templates) {
307
+ if (!Array.isArray(templates))
308
+ return undefined;
309
+ const base = templates.filter((t) => !!t &&
310
+ typeof t === 'object' &&
311
+ t.status === 'ready' &&
312
+ t.namespace === 'public' &&
313
+ typeof t.name === 'string' &&
314
+ PUBLIC_BASE_RE.test(t.name) &&
315
+ typeof t.id === 'string');
316
+ base.sort((a, b) => ((a.created_at ?? '') < (b.created_at ?? '') ? 1 : -1));
317
+ return base[0]?.id;
318
+ }
319
+ /**
320
+ * `gsk sb-box create` with no --template: the newest ready public base
321
+ * (CLI-side default; the server still requires a template — it just
322
+ * receives the one picked here). Throws when the catalog has none.
323
+ */
324
+ export async function defaultTemplate(call) {
325
+ const listed = await call({ action: 'templates' });
326
+ const template = pickDefaultTemplate(listed.data?.templates);
327
+ if (!template) {
328
+ throw new SessionError('no ready public base template to create from; pass ' +
329
+ '--template <name|tpl-id> (see `gsk sb-box templates`).');
330
+ }
331
+ return template;
332
+ }
333
+ /**
334
+ * Resolve the sandbox for a session before the real call: reuse the bound
335
+ * one if it is alive, otherwise create (for CREATING_ACTIONS) or fail with
336
+ * a message that says what to do. `args` is mutated: `sandbox_id` is set,
337
+ * and `template` (a create-only parameter) is consumed when a sandbox had
338
+ * to be created.
339
+ */
340
+ export async function bindSession(opts) {
341
+ // The whole lookup → verify → create → bind sequence runs under the
342
+ // key's lock, so concurrent first calls serialize: the second one finds
343
+ // the first one's sandbox instead of creating its own.
344
+ return opts.store.withLock(opts.key.key, held => bindSessionLocked(opts, held));
345
+ }
346
+ /**
347
+ * The `get` says the sandbox no longer exists (as opposed to "ask again").
348
+ * Since the backend prefixes upstream errors with `HTTP <status> …`, that
349
+ * status decides: only a 404 is "gone" — a 503 whose detail happens to say
350
+ * "not found" must keep the binding (dropping it would orphan a live
351
+ * sandbox). The text match stays only for messages without that prefix.
352
+ */
353
+ function isGoneError(got) {
354
+ if (got.http_status === 404)
355
+ return true;
356
+ const message = got.message ?? '';
357
+ const upstream = /^HTTP (\d{3})\b/.exec(message);
358
+ if (upstream)
359
+ return upstream[1] === '404';
360
+ return /not found|no such sandbox|does not exist|unknown sandbox/i.test(message);
361
+ }
362
+ async function bindSessionLocked(opts, held) {
363
+ const { key, action, args, call, store } = opts;
364
+ const log = opts.log ?? (() => { });
365
+ const bound = store.get(key.key);
366
+ if (bound) {
367
+ const got = await call({ action: 'get', sandbox_id: bound.sandbox_id });
368
+ let state;
369
+ if (got.status === 'ok' && got.data && typeof got.data === 'object') {
370
+ state = String(got.data.state ?? '');
371
+ }
372
+ else if (!isGoneError(got)) {
373
+ // A rate limit, timeout or 5xx is not evidence the sandbox is gone:
374
+ // keep the binding and let the caller retry, rather than orphaning a
375
+ // live machine (and its interpreter state) behind a fresh one.
376
+ throw new SessionError(`session ${key.key}: could not check ${bound.sandbox_id} ` +
377
+ `(${got.message}); binding kept — retry, or pass --sandbox_id.`);
378
+ }
379
+ if (state && ALIVE_STATES.has(state)) {
380
+ args.sandbox_id = bound.sandbox_id;
381
+ delete args.template;
382
+ return { key, sandbox_id: bound.sandbox_id, created: false, state };
383
+ }
384
+ store.delete(key.key);
385
+ log(`session ${key.key}: ${bound.sandbox_id} is ${state ?? 'gone'}; ` +
386
+ (CREATING_ACTIONS.has(action)
387
+ ? 'creating a new sandbox'
388
+ : 'binding dropped'));
389
+ if (!CREATING_ACTIONS.has(action)) {
390
+ throw new SessionError(`session ${key.key} has no live sandbox (${bound.sandbox_id} is ` +
391
+ `${state ?? 'gone'}). Run exec, run-code or write on the session ` +
392
+ 'to start a new one, or pass --sandbox_id.');
393
+ }
394
+ }
395
+ else if (!CREATING_ACTIONS.has(action)) {
396
+ throw new SessionError(`session ${key.key} has no sandbox yet. Run exec, run-code or write ` +
397
+ 'on the session to start one, or pass --sandbox_id.');
398
+ }
399
+ let template = typeof args.template === 'string' && args.template.trim()
400
+ ? args.template.trim()
401
+ : undefined;
402
+ delete args.template;
403
+ if (!template)
404
+ template = await defaultTemplate(call);
405
+ // timeout 0 = no hard deadline: the sandbox lives across the whole
406
+ // session; the platform's idle freeze (nothing billed while frozen) and
407
+ // an explicit `kill --session` are the lifecycle.
408
+ const created = await call({ action: 'create', template, timeout: 0 });
409
+ const id = created.status === 'ok' && created.data && typeof created.data === 'object'
410
+ ? created.data.id
411
+ : undefined;
412
+ if (typeof id !== 'string' || !id) {
413
+ throw new SessionError(`session ${key.key}: could not create a sandbox: ${created.message}`);
414
+ }
415
+ if (!held()) {
416
+ // The lock was taken from us during the create (eviction race, see
417
+ // withLock). Re-acquire and reconcile: if another process bound a live
418
+ // sandbox meanwhile, use that one and give ours back — one sandbox per
419
+ // session is the contract, a wasted create is the lesser evil.
420
+ log(`session ${key.key}: lost the session lock during create; reconciling`);
421
+ return store.withLock(key.key, async () => {
422
+ const other = store.get(key.key);
423
+ if (other && other.sandbox_id !== id) {
424
+ const got = await call({ action: 'get', sandbox_id: other.sandbox_id });
425
+ const state = got.status === 'ok' && got.data && typeof got.data === 'object'
426
+ ? String(got.data.state ?? '')
427
+ : undefined;
428
+ if (state && ALIVE_STATES.has(state)) {
429
+ await call({ action: 'kill', sandbox_id: id });
430
+ log(`session ${key.key}: using ${other.sandbox_id}, killed ${id}`);
431
+ args.sandbox_id = other.sandbox_id;
432
+ return { key, sandbox_id: other.sandbox_id, created: false, state };
433
+ }
434
+ }
435
+ store.set(key.key, { sandbox_id: id, template });
436
+ log(`session ${key.key}: created ${id} from ${template}`);
437
+ args.sandbox_id = id;
438
+ return { key, sandbox_id: id, created: true };
439
+ });
440
+ }
441
+ store.set(key.key, { sandbox_id: id, template });
442
+ log(`session ${key.key}: created ${id} from ${template}`);
443
+ args.sandbox_id = id;
444
+ return { key, sandbox_id: id, created: true };
445
+ }
446
+ /**
447
+ * After the real call: keep the binding in step with explicit lifecycle
448
+ * actions (`create --session` binds the new sandbox, a successful `kill`
449
+ * drops it) and echo the binding on the envelope so a caller that never
450
+ * saw the id learns it once.
451
+ */
452
+ export function afterSessionCall(opts) {
453
+ const { key, action, bind, result, store } = opts;
454
+ const data = result.data &&
455
+ typeof result.data === 'object' &&
456
+ !Array.isArray(result.data)
457
+ ? result.data
458
+ : undefined;
459
+ if (result.status !== 'ok')
460
+ return;
461
+ let sandboxId = bind?.sandbox_id;
462
+ let created = bind?.created ?? false;
463
+ if (action === 'create' && data && typeof data.id === 'string') {
464
+ sandboxId = data.id;
465
+ created = true;
466
+ store.set(key.key, {
467
+ sandbox_id: data.id,
468
+ template: typeof data.templateId === 'string' ? data.templateId : undefined,
469
+ });
470
+ }
471
+ if (action === 'kill' && sandboxId)
472
+ store.delete(key.key);
473
+ if (data && sandboxId) {
474
+ data.session = { key: key.key, sandbox_id: sandboxId, created };
475
+ }
476
+ }
477
+ //# sourceMappingURL=sb-box-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sb-box-session.js","sourceRoot":"","sources":["../../src/commands/sb-box-session.ts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