gipity 1.1.12 → 1.1.13

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/dist/index.js CHANGED
@@ -6765,6 +6765,10 @@ function parseTranscript(content, afterUuid) {
6765
6765
  let lastUuid = afterUuid;
6766
6766
  const out = [];
6767
6767
  const toolNames = /* @__PURE__ */ new Map();
6768
+ const countedUsage = /* @__PURE__ */ new Set();
6769
+ let tokensIn = 0;
6770
+ let tokensOut = 0;
6771
+ const num = (v7) => typeof v7 === "number" && v7 > 0 ? v7 : 0;
6768
6772
  for (const raw of content.split("\n")) {
6769
6773
  const line = raw.trim();
6770
6774
  if (!line) continue;
@@ -6785,6 +6789,16 @@ function parseTranscript(content, afterUuid) {
6785
6789
  if (parsed?.uuid === afterUuid) seenWatermark = true;
6786
6790
  continue;
6787
6791
  }
6792
+ if (parsed?.type === "assistant" && parsed?.isSidechain !== true) {
6793
+ const m = parsed.message;
6794
+ const u = m?.usage;
6795
+ const key = typeof m?.id === "string" && m.id ? m.id : parsed.uuid;
6796
+ if (u && typeof key === "string" && !countedUsage.has(key)) {
6797
+ countedUsage.add(key);
6798
+ tokensIn += num(u.input_tokens) + num(u.cache_read_input_tokens) + num(u.cache_creation_input_tokens);
6799
+ tokensOut += num(u.output_tokens);
6800
+ }
6801
+ }
6788
6802
  const entries = transcriptLineToEntries(parsed, toolNames);
6789
6803
  if (entries.length) {
6790
6804
  for (const e of entries) out.push(e);
@@ -6796,7 +6810,8 @@ function parseTranscript(content, afterUuid) {
6796
6810
  return {
6797
6811
  entries: out,
6798
6812
  lastUuid,
6799
- foundWatermark: seenWatermark
6813
+ foundWatermark: seenWatermark,
6814
+ usage: { tokensIn, tokensOut }
6800
6815
  };
6801
6816
  }
6802
6817
  var init_claude_code = __esm({
@@ -7104,7 +7119,15 @@ function ensureOpencodeInstalled(opts = {}) {
7104
7119
  }
7105
7120
  function ensureOpencodePluginInstalled() {
7106
7121
  const src = stagedPluginPath();
7107
- if (!existsSync4(src)) return existsSync4(opencodePluginDest());
7122
+ if (!existsSync4(src)) {
7123
+ const installed = existsSync4(opencodePluginDest());
7124
+ if (!installed) {
7125
+ console.warn(
7126
+ "Gipity opencode plugin is not staged (skills install incomplete?) - session capture is off. Re-run `gipity init` with network access to fix."
7127
+ );
7128
+ }
7129
+ return installed;
7130
+ }
7108
7131
  const dest = opencodePluginDest();
7109
7132
  try {
7110
7133
  if (existsSync4(dest) && readFileSync3(dest, "utf-8") === readFileSync3(src, "utf-8")) return true;
@@ -7511,7 +7534,7 @@ function setupCodexIntegration() {
7511
7534
  setupCodexHooks();
7512
7535
  }
7513
7536
  function ensureOpencodeSkillsInstalled() {
7514
- if (agentSkillsState().current) return;
7537
+ if (agentSkillsState().current && existsSync5(stagedPluginPath())) return;
7515
7538
  if (!binaryOnPath("opencode")) return;
7516
7539
  installSkillsAndHooks(AGENTS_SKILLS_DIR, AGENT_SKILLS_MANIFEST, "opencode");
7517
7540
  }
@@ -7799,7 +7822,7 @@ var init_setup = __esm({
7799
7822
  GIPITY_MARKETPLACE_NAME = "gipity";
7800
7823
  GIPITY_MARKETPLACE_REPO = "GipityAI/skills";
7801
7824
  LEGACY_MARKETPLACE_REPO = "GipityAI/claude-plugin";
7802
- GIPITY_PLUGIN_VERSION = "0.7.0";
7825
+ GIPITY_PLUGIN_VERSION = "0.8.0";
7803
7826
  AGENTS_SKILLS_DIR = join6(homedir4(), ".agents", "skills");
7804
7827
  AGENT_HOOKS_DIR = join6(homedir4(), ".gipity", "agent-hooks");
7805
7828
  AGENT_SKILLS_MANIFEST = join6(homedir4(), ".gipity", "agent-skills.json");
@@ -8046,6 +8069,12 @@ function lineToEntries(parsed, sessionId, idx, toolNames) {
8046
8069
  }
8047
8070
  return [];
8048
8071
  }
8072
+ function tokenTotals(payload) {
8073
+ const t = payload?.info?.total_token_usage;
8074
+ if (!t || typeof t !== "object") return null;
8075
+ const num = (v7) => typeof v7 === "number" && v7 > 0 ? v7 : 0;
8076
+ return { input: num(t.input_tokens), output: num(t.output_tokens) };
8077
+ }
8049
8078
  function parseTranscript2(content, afterUuid) {
8050
8079
  const lines = content.split("\n");
8051
8080
  let sessionId = "";
@@ -8067,6 +8096,8 @@ function parseTranscript2(content, afterUuid) {
8067
8096
  const out = [];
8068
8097
  const toolNames = /* @__PURE__ */ new Map();
8069
8098
  let lastIdx = startAfter;
8099
+ let baseUsage = null;
8100
+ let lastUsage = null;
8070
8101
  for (let i = 0; i < lines.length; i++) {
8071
8102
  const line = lines[i].trim();
8072
8103
  if (!line) continue;
@@ -8076,13 +8107,16 @@ function parseTranscript2(content, afterUuid) {
8076
8107
  } catch {
8077
8108
  continue;
8078
8109
  }
8110
+ const isTokenCount = parsed?.type === "event_msg" && parsed?.payload?.type === "token_count";
8079
8111
  if (startAfter !== null && i <= startAfter) {
8080
8112
  const p = parsed?.payload;
8081
8113
  if (parsed?.type === "response_item" && p && (p.type === "custom_tool_call" || p.type === "function_call") && typeof p.call_id === "string") {
8082
8114
  toolNames.set(p.call_id, typeof p.name === "string" && p.name ? p.name : "tool");
8083
8115
  }
8116
+ if (isTokenCount) baseUsage = tokenTotals(parsed.payload) ?? baseUsage;
8084
8117
  continue;
8085
8118
  }
8119
+ if (isTokenCount) lastUsage = tokenTotals(parsed.payload) ?? lastUsage;
8086
8120
  const entries = lineToEntries(parsed, sessionId, i, toolNames);
8087
8121
  for (const e of entries) out.push(e);
8088
8122
  lastIdx = i;
@@ -8090,7 +8124,11 @@ function parseTranscript2(content, afterUuid) {
8090
8124
  return {
8091
8125
  entries: out,
8092
8126
  lastUuid: lastIdx === null ? afterUuid : positional(sessionId, lastIdx),
8093
- foundWatermark
8127
+ foundWatermark,
8128
+ usage: lastUsage === null ? { tokensIn: 0, tokensOut: 0 } : {
8129
+ tokensIn: Math.max(0, lastUsage.input - (baseUsage?.input ?? 0)),
8130
+ tokensOut: Math.max(0, lastUsage.output - (baseUsage?.output ?? 0))
8131
+ }
8094
8132
  };
8095
8133
  }
8096
8134
  var init_codex = __esm({
@@ -8647,6 +8685,9 @@ function parseTranscript5(content, afterUuid) {
8647
8685
  const foundWatermark = afterUuid === null || watermarkLine !== -1;
8648
8686
  const out = [];
8649
8687
  let lastUuid = foundWatermark ? afterUuid : null;
8688
+ let tokensIn = 0;
8689
+ let tokensOut = 0;
8690
+ const num = (v7) => typeof v7 === "number" && v7 > 0 ? v7 : 0;
8650
8691
  for (let i = 0; i < lines.length; i++) {
8651
8692
  if (watermarkLine !== -1 && i <= watermarkLine) continue;
8652
8693
  const line = lines[i].trim();
@@ -8657,12 +8698,17 @@ function parseTranscript5(content, afterUuid) {
8657
8698
  } catch {
8658
8699
  continue;
8659
8700
  }
8660
- const entries = messageToEntries(parsed?.info, Array.isArray(parsed?.parts) ? parsed.parts : []);
8701
+ const info2 = parsed?.info;
8702
+ const entries = messageToEntries(info2, Array.isArray(parsed?.parts) ? parsed.parts : []);
8661
8703
  if (!entries.length) continue;
8704
+ if (info2?.role === "assistant" && info2?.tokens) {
8705
+ tokensIn += num(info2.tokens.input) + num(info2.tokens.cache?.read) + num(info2.tokens.cache?.write);
8706
+ tokensOut += num(info2.tokens.output);
8707
+ }
8662
8708
  for (const e of entries) out.push(e);
8663
- if (typeof parsed?.info?.id === "string") lastUuid = parsed.info.id;
8709
+ if (typeof info2?.id === "string") lastUuid = info2.id;
8664
8710
  }
8665
- return { entries: out, lastUuid, foundWatermark };
8711
+ return { entries: out, lastUuid, foundWatermark, usage: { tokensIn, tokensOut } };
8666
8712
  }
8667
8713
  var init_opencode = __esm({
8668
8714
  "src/capture/sources/opencode.ts"() {
@@ -8881,6 +8927,7 @@ var init_client_context = __esm({
8881
8927
  var api_exports = {};
8882
8928
  __export(api_exports, {
8883
8929
  ApiError: () => ApiError,
8930
+ LONG_REQUEST_TIMEOUT_MS: () => LONG_REQUEST_TIMEOUT_MS,
8884
8931
  del: () => del,
8885
8932
  download: () => download,
8886
8933
  downloadStream: () => downloadStream,
@@ -8948,16 +8995,16 @@ async function getAuthHeader() {
8948
8995
  const headers = await getHeaders();
8949
8996
  return headers.Authorization;
8950
8997
  }
8951
- async function request(method, path5, body, retrying = false) {
8998
+ async function request(method, path5, body, retrying = false, timeoutMs = REQUEST_TIMEOUT_MS) {
8952
8999
  const headers = await getHeaders();
8953
9000
  const url = `${baseUrl()}${path5}`;
8954
9001
  const res = await fetchWithTimeout(url, {
8955
9002
  method,
8956
9003
  headers,
8957
9004
  body: body ? JSON.stringify(body) : void 0
8958
- }, REQUEST_TIMEOUT_MS, `${method} ${path5}`);
9005
+ }, timeoutMs, `${method} ${path5}`);
8959
9006
  if (await shouldRetryAfter401(res.status, retrying)) {
8960
- return request(method, path5, body, true);
9007
+ return request(method, path5, body, true, timeoutMs);
8961
9008
  }
8962
9009
  if (!res.ok) {
8963
9010
  const json = await res.json().catch(() => ({ error: { code: "UNKNOWN", message: res.statusText } }));
@@ -8969,8 +9016,8 @@ async function request(method, path5, body, retrying = false) {
8969
9016
  function get(path5) {
8970
9017
  return request("GET", path5);
8971
9018
  }
8972
- function post(path5, body) {
8973
- return request("POST", path5, body);
9019
+ function post(path5, body, opts) {
9020
+ return request("POST", path5, body, false, opts?.timeoutMs);
8974
9021
  }
8975
9022
  async function postForTarEntries(path5, body, retried = false) {
8976
9023
  const headers = await getHeaders();
@@ -9176,7 +9223,7 @@ async function mintAppToken(projectGuid2) {
9176
9223
  return void 0;
9177
9224
  }
9178
9225
  }
9179
- var tar, ApiError, REQUEST_TIMEOUT_MS, DOWNLOAD_HEADER_TIMEOUT_MS, PUT_TIMEOUT_FLOOR_MS, PUT_MIN_BYTES_PER_SEC, accountSlugCache;
9226
+ var tar, ApiError, REQUEST_TIMEOUT_MS, DOWNLOAD_HEADER_TIMEOUT_MS, LONG_REQUEST_TIMEOUT_MS, PUT_TIMEOUT_FLOOR_MS, PUT_MIN_BYTES_PER_SEC, accountSlugCache;
9180
9227
  var init_api = __esm({
9181
9228
  "src/api.ts"() {
9182
9229
  "use strict";
@@ -9198,6 +9245,7 @@ var init_api = __esm({
9198
9245
  };
9199
9246
  REQUEST_TIMEOUT_MS = 6e4;
9200
9247
  DOWNLOAD_HEADER_TIMEOUT_MS = 3e4;
9248
+ LONG_REQUEST_TIMEOUT_MS = 31e4;
9201
9249
  PUT_TIMEOUT_FLOOR_MS = 12e4;
9202
9250
  PUT_MIN_BYTES_PER_SEC = 256 * 1024;
9203
9251
  accountSlugCache = null;
@@ -36078,14 +36126,14 @@ init_agents();
36078
36126
  init_colors();
36079
36127
  init_utils();
36080
36128
  import { basename as basename2, resolve as resolve7, dirname as dirname7 } from "path";
36081
- import { existsSync as existsSync11, readFileSync as readFileSync12 } from "fs";
36129
+ import { existsSync as existsSync10, readFileSync as readFileSync11 } from "fs";
36082
36130
 
36083
36131
  // src/adopt-cwd.ts
36084
36132
  init_api();
36085
36133
  init_setup();
36086
36134
  import { readdirSync as readdirSync6, statSync as statSync4 } from "fs";
36087
- import { join as join14, resolve as resolve6, sep as sep3, parse as parsePath } from "path";
36088
- import { homedir as homedir10 } from "os";
36135
+ import { join as join13, resolve as resolve6, sep as sep3, parse as parsePath } from "path";
36136
+ import { homedir as homedir9 } from "os";
36089
36137
 
36090
36138
  // src/project-setup.ts
36091
36139
  init_config();
@@ -36352,165 +36400,6 @@ function getProjectsRoot() {
36352
36400
  return defaultDir;
36353
36401
  }
36354
36402
 
36355
- // src/relay/state.ts
36356
- import { readFileSync as readFileSync11, writeFileSync as writeFileSync8, mkdirSync as mkdirSync7, existsSync as existsSync10, chmodSync as chmodSync3, unlinkSync as unlinkSync5 } from "fs";
36357
- import { join as join13 } from "path";
36358
- import { homedir as homedir9 } from "os";
36359
- var RELAY_DIR = process.env.GIPITY_DIR || join13(homedir9(), ".gipity");
36360
- var RELAY_FILE = join13(RELAY_DIR, "relay.json");
36361
- var FILE_MODE = 384;
36362
- function emptyState() {
36363
- return { device: null, paused: false };
36364
- }
36365
- function loadState() {
36366
- if (!existsSync10(RELAY_FILE)) return emptyState();
36367
- try {
36368
- const raw = JSON.parse(readFileSync11(RELAY_FILE, "utf-8"));
36369
- return {
36370
- device: raw.device ?? null,
36371
- paused: Boolean(raw.paused),
36372
- relay_enabled: typeof raw.relay_enabled === "boolean" ? raw.relay_enabled : void 0,
36373
- onboard_shown: Boolean(raw.onboard_shown),
36374
- diagnostics_consent: typeof raw.diagnostics_consent === "boolean" ? raw.diagnostics_consent : void 0,
36375
- agent_updates: typeof raw.agent_updates === "boolean" ? raw.agent_updates : void 0,
36376
- agent_token: typeof raw.agent_token === "string" ? raw.agent_token : null,
36377
- agent_token_guid: typeof raw.agent_token_guid === "string" ? raw.agent_token_guid : null
36378
- };
36379
- } catch {
36380
- return emptyState();
36381
- }
36382
- }
36383
- function saveState(state) {
36384
- mkdirSync7(RELAY_DIR, { recursive: true });
36385
- writeFileSync8(RELAY_FILE, JSON.stringify(state, null, 2) + "\n", { mode: FILE_MODE });
36386
- try {
36387
- chmodSync3(RELAY_FILE, FILE_MODE);
36388
- } catch {
36389
- }
36390
- }
36391
- function mutate(fn) {
36392
- const s = loadState();
36393
- fn(s);
36394
- saveState(s);
36395
- }
36396
- function getDevice() {
36397
- return loadState().device;
36398
- }
36399
- function setDevice(device) {
36400
- mutate((s) => {
36401
- s.device = device;
36402
- });
36403
- }
36404
- function clearDevice() {
36405
- mutate((s) => {
36406
- s.device = null;
36407
- s.paused = false;
36408
- s.agent_token = null;
36409
- s.agent_token_guid = null;
36410
- });
36411
- }
36412
- function getAgentToken() {
36413
- const s = loadState();
36414
- return s.agent_token ? { token: s.agent_token, guid: s.agent_token_guid ?? null } : null;
36415
- }
36416
- function setAgentToken(token, guid) {
36417
- mutate((s) => {
36418
- s.agent_token = token;
36419
- s.agent_token_guid = guid;
36420
- });
36421
- }
36422
- function isPaused() {
36423
- return loadState().paused;
36424
- }
36425
- function setPaused(paused) {
36426
- mutate((s) => {
36427
- s.paused = paused;
36428
- });
36429
- }
36430
- function getRelayEnabled() {
36431
- return loadState().relay_enabled;
36432
- }
36433
- function isRelayEnabled() {
36434
- return loadState().relay_enabled === true;
36435
- }
36436
- function setRelayEnabled(enabled) {
36437
- mutate((s) => {
36438
- s.relay_enabled = enabled;
36439
- });
36440
- }
36441
- function getDiagnosticsConsent() {
36442
- return loadState().diagnostics_consent;
36443
- }
36444
- function setDiagnosticsConsent(consent) {
36445
- mutate((s) => {
36446
- s.diagnostics_consent = consent;
36447
- });
36448
- }
36449
- function diagnosticsConsented() {
36450
- const env = process.env.GIPITY_NO_DIAGNOSTICS ?? process.env.DO_NOT_TRACK;
36451
- if (env && env !== "0" && env.toLowerCase() !== "false") return false;
36452
- return loadState().diagnostics_consent !== false;
36453
- }
36454
- function getAgentUpdatesPref() {
36455
- return loadState().agent_updates;
36456
- }
36457
- function setAgentUpdatesPref(on2) {
36458
- mutate((s) => {
36459
- s.agent_updates = on2;
36460
- });
36461
- }
36462
- function agentUpdatesEnabled() {
36463
- if (process.env.DISABLE_AUTOUPDATER === "1") return false;
36464
- const env = (process.env.GIPITY_RELAY_AGENT_UPDATES || "").toLowerCase();
36465
- if (["0", "off", "false", "no"].includes(env)) return false;
36466
- if (["1", "on", "true", "yes"].includes(env)) return true;
36467
- if (process.env.CI || process.env.NODE_ENV === "test") return false;
36468
- return loadState().agent_updates !== false;
36469
- }
36470
- var RELAY_PID_FILE = join13(RELAY_DIR, "relay.pid");
36471
- function getDaemonPidPath() {
36472
- return RELAY_PID_FILE;
36473
- }
36474
- function writeDaemonPid(pid) {
36475
- mkdirSync7(RELAY_DIR, { recursive: true });
36476
- writeFileSync8(RELAY_PID_FILE, String(pid), { flag: "wx" });
36477
- }
36478
- function clearDaemonPid() {
36479
- try {
36480
- unlinkSync5(RELAY_PID_FILE);
36481
- } catch {
36482
- }
36483
- }
36484
- function isDaemonRunning() {
36485
- if (!existsSync10(RELAY_PID_FILE)) return false;
36486
- try {
36487
- const raw = readFileSync11(RELAY_PID_FILE, "utf-8").trim();
36488
- const pid = parseInt(raw, 10);
36489
- if (!pid || isNaN(pid)) {
36490
- try {
36491
- unlinkSync5(RELAY_PID_FILE);
36492
- } catch {
36493
- }
36494
- return false;
36495
- }
36496
- if (pid === process.pid) {
36497
- try {
36498
- unlinkSync5(RELAY_PID_FILE);
36499
- } catch {
36500
- }
36501
- return false;
36502
- }
36503
- process.kill(pid, 0);
36504
- return true;
36505
- } catch {
36506
- try {
36507
- unlinkSync5(RELAY_PID_FILE);
36508
- } catch {
36509
- }
36510
- return false;
36511
- }
36512
- }
36513
-
36514
36403
  // src/adopt-cwd.ts
36515
36404
  var EASY_FILES = 200;
36516
36405
  var EASY_BYTES = 100 * 1024 * 1024;
@@ -36531,7 +36420,7 @@ function scanForAdoption(cwd) {
36531
36420
  for (const name of entries) {
36532
36421
  if (truncated) return;
36533
36422
  if (isSyncIgnored(name)) continue;
36534
- const full = join14(dir, name);
36423
+ const full = join13(dir, name);
36535
36424
  let st2;
36536
36425
  try {
36537
36426
  st2 = statSync4(full);
@@ -36568,7 +36457,7 @@ function isLikelyEmpty(cwd) {
36568
36457
  }
36569
36458
  function canAdoptCwd(cwd) {
36570
36459
  const norm = resolve6(cwd);
36571
- const home = resolve6(homedir10());
36460
+ const home = resolve6(homedir9());
36572
36461
  const blocked = /* @__PURE__ */ new Set([
36573
36462
  sep3,
36574
36463
  home,
@@ -36605,10 +36494,10 @@ function countGitRepoChildren(dir) {
36605
36494
  let count = 0;
36606
36495
  for (const name of entries.slice(0, 50)) {
36607
36496
  if (name.startsWith(".")) continue;
36608
- const child = join14(dir, name);
36497
+ const child = join13(dir, name);
36609
36498
  try {
36610
36499
  if (!statSync4(child).isDirectory()) continue;
36611
- const gitPath = join14(child, ".git");
36500
+ const gitPath = join13(child, ".git");
36612
36501
  if (statSync4(gitPath)) count++;
36613
36502
  } catch {
36614
36503
  }
@@ -36618,7 +36507,7 @@ function countGitRepoChildren(dir) {
36618
36507
  }
36619
36508
  function formatCwdLabel(cwd) {
36620
36509
  const norm = resolve6(cwd);
36621
- const home = resolve6(homedir10());
36510
+ const home = resolve6(homedir9());
36622
36511
  if (norm === home) return "~";
36623
36512
  if (norm.startsWith(home + sep3)) {
36624
36513
  const tail2 = norm.slice(home.length + 1).split(sep3);
@@ -36645,15 +36534,10 @@ async function adoptCurrentDir(opts) {
36645
36534
  }
36646
36535
  let isNew = false;
36647
36536
  if (!project) {
36648
- const device = getDevice();
36649
36537
  const body = {
36650
36538
  name: opts.projectName,
36651
36539
  slug: opts.projectSlug
36652
36540
  };
36653
- if (device) {
36654
- body.autoChat = "claude_code";
36655
- body.deviceGuid = device.guid;
36656
- }
36657
36541
  try {
36658
36542
  const res = await post("/projects", body);
36659
36543
  project = res.data;
@@ -36748,7 +36632,7 @@ Working with an existing Gipity project:
36748
36632
  process.exit(1);
36749
36633
  }
36750
36634
  const cwd = process.cwd();
36751
- if (existsSync11(resolve7(cwd, ".gipity.json"))) {
36635
+ if (existsSync10(resolve7(cwd, ".gipity.json"))) {
36752
36636
  const existing = getConfig();
36753
36637
  console.log(`Already linked to ${info(`"${existing?.projectSlug ?? ""}"`)} ${muted(`(${existing?.projectGuid ?? ""})`)}`);
36754
36638
  setupProjectTools(tools);
@@ -36831,7 +36715,7 @@ Working with an existing Gipity project:
36831
36715
  if (adopted.applied > 0) console.log(`Synced ${adopted.applied} change${adopted.applied > 1 ? "s" : ""} with Gipity.`);
36832
36716
  if (opts.capture === false) {
36833
36717
  try {
36834
- const cfg = JSON.parse(readFileSync12(resolve7(cwd, ".gipity.json"), "utf-8"));
36718
+ const cfg = JSON.parse(readFileSync11(resolve7(cwd, ".gipity.json"), "utf-8"));
36835
36719
  cfg.captureHooks = false;
36836
36720
  saveConfigAt(cwd, cfg);
36837
36721
  } catch {
@@ -36866,15 +36750,15 @@ init_api();
36866
36750
  init_config();
36867
36751
  init_colors();
36868
36752
  init_setup();
36869
- import { existsSync as existsSync12, readFileSync as readFileSync13 } from "fs";
36870
- import { join as join15, resolve as resolve8 } from "path";
36871
- import { homedir as homedir11 } from "os";
36753
+ import { existsSync as existsSync11, readFileSync as readFileSync12 } from "fs";
36754
+ import { join as join14, resolve as resolve8 } from "path";
36755
+ import { homedir as homedir10 } from "os";
36872
36756
  function checkGipityPlugin() {
36873
- const path5 = join15(homedir11(), ".claude", "settings.json");
36757
+ const path5 = join14(homedir10(), ".claude", "settings.json");
36874
36758
  let settings = {};
36875
- if (existsSync12(path5)) {
36759
+ if (existsSync11(path5)) {
36876
36760
  try {
36877
- settings = JSON.parse(readFileSync13(path5, "utf-8"));
36761
+ settings = JSON.parse(readFileSync12(path5, "utf-8"));
36878
36762
  } catch {
36879
36763
  }
36880
36764
  }
@@ -37126,7 +37010,7 @@ init_colors();
37126
37010
  init_auth();
37127
37011
 
37128
37012
  // src/commands/page-eval.ts
37129
- import { readFileSync as readFileSync15 } from "node:fs";
37013
+ import { readFileSync as readFileSync14 } from "node:fs";
37130
37014
  init_api();
37131
37015
  init_colors();
37132
37016
  init_auth();
@@ -37159,8 +37043,8 @@ function dropCheckpoint(projectGuid2, database) {
37159
37043
  // src/page-fixtures.ts
37160
37044
  init_api();
37161
37045
  init_config();
37162
- import { readFileSync as readFileSync14, statSync as statSync6, existsSync as existsSync13, readdirSync as readdirSync7 } from "node:fs";
37163
- import { basename as basename4, resolve as resolve10, relative as relative3, join as join16 } from "node:path";
37046
+ import { readFileSync as readFileSync13, statSync as statSync6, existsSync as existsSync12, readdirSync as readdirSync7 } from "node:fs";
37047
+ import { basename as basename4, resolve as resolve10, relative as relative3, join as join15 } from "node:path";
37164
37048
  var FIND_SKIP = /* @__PURE__ */ new Set(["node_modules", ".git", ".gipity", "dist", "build", ".next", "coverage"]);
37165
37049
  function findByBasename(root, name, limit = 3) {
37166
37050
  const hits = [];
@@ -37177,9 +37061,9 @@ function findByBasename(root, name, limit = 3) {
37177
37061
  }
37178
37062
  for (const e of entries) {
37179
37063
  if (e.isDirectory()) {
37180
- if (!FIND_SKIP.has(e.name)) queue.push(join16(dir, e.name));
37064
+ if (!FIND_SKIP.has(e.name)) queue.push(join15(dir, e.name));
37181
37065
  } else if (e.name === name && hits.length < limit) {
37182
- hits.push(join16(dir, e.name));
37066
+ hits.push(join15(dir, e.name));
37183
37067
  }
37184
37068
  }
37185
37069
  }
@@ -37187,7 +37071,7 @@ function findByBasename(root, name, limit = 3) {
37187
37071
  }
37188
37072
  function assertLocalAsset(flag, localPath) {
37189
37073
  const abs = resolve10(localPath);
37190
- if (existsSync13(abs)) return;
37074
+ if (existsSync12(abs)) return;
37191
37075
  const root = getProjectRoot() ?? process.cwd();
37192
37076
  const elsewhere = findByBasename(root, basename4(localPath)).filter((p) => p !== abs);
37193
37077
  const found = elsewhere.length ? `
@@ -37213,7 +37097,7 @@ async function uploadPublicFixture(projectGuid2, localPath, flag = "--fixture")
37213
37097
  const res = await fetch(init.data.url, {
37214
37098
  method: "PUT",
37215
37099
  headers: { "Content-Type": contentType },
37216
- body: readFileSync14(localPath)
37100
+ body: readFileSync13(localPath)
37217
37101
  });
37218
37102
  if (!res.ok) {
37219
37103
  throw new Error(`upload of fixture "${name}" failed: ${res.status} ${res.statusText}`);
@@ -37313,7 +37197,7 @@ function capWaitForTimeoutMs(raw) {
37313
37197
  return WAIT_FOR_MAX_MS;
37314
37198
  }
37315
37199
  function readScriptFile(pathArg) {
37316
- return readFileSync15(pathArg === "-" ? 0 : pathArg, "utf8");
37200
+ return readFileSync14(pathArg === "-" ? 0 : pathArg, "utf8");
37317
37201
  }
37318
37202
  function parsesAsExpression(s) {
37319
37203
  try {
@@ -37757,8 +37641,8 @@ init_config();
37757
37641
  init_auth();
37758
37642
  init_colors();
37759
37643
  init_utils();
37760
- import { mkdirSync as mkdirSync8, writeFileSync as writeFileSync9 } from "fs";
37761
- import { dirname as dirname9, extname as extname4, join as join17, resolve as resolvePath } from "path";
37644
+ import { mkdirSync as mkdirSync7, writeFileSync as writeFileSync8 } from "fs";
37645
+ import { dirname as dirname9, extname as extname4, join as join16, resolve as resolvePath } from "path";
37762
37646
  var DEVICE_PRESETS = {
37763
37647
  default: { width: 1280, height: 720 },
37764
37648
  desktop: { width: 1920, height: 1080 },
@@ -37822,7 +37706,7 @@ function dimSuffix(vp2) {
37822
37706
  }
37823
37707
  function defaultScreenshotDir() {
37824
37708
  const root = getProjectRoot();
37825
- return join17(root ?? ".", "screenshots");
37709
+ return join16(root ?? ".", "screenshots");
37826
37710
  }
37827
37711
  function timestampSlug(d = /* @__PURE__ */ new Date()) {
37828
37712
  const p = (n) => String(n).padStart(2, "0");
@@ -38034,9 +37918,9 @@ var pageScreenshotCommand = new Command("screenshot").description("Screenshot a
38034
37918
  return stemPath(opts.output, suffix);
38035
37919
  };
38036
37920
  for (let i = 0; i < pngs.length; i++) {
38037
- const target = opts.output ? outputPath(i) : join17(dir, names[i] ?? shotName(meta.screenshots[i].viewport));
38038
- mkdirSync8(dirname9(target), { recursive: true });
38039
- writeFileSync9(target, pngs[i].buffer);
37921
+ const target = opts.output ? outputPath(i) : join16(dir, names[i] ?? shotName(meta.screenshots[i].viewport));
37922
+ mkdirSync7(dirname9(target), { recursive: true });
37923
+ writeFileSync8(target, pngs[i].buffer);
38040
37924
  savedFiles.push(resolvePath(target));
38041
37925
  }
38042
37926
  if (opts.json) {
@@ -38678,7 +38562,7 @@ memoryCommand.command("delete <topic>").description("Delete a topic").option("--
38678
38562
  init_api();
38679
38563
  init_config();
38680
38564
  init_setup();
38681
- import { readFileSync as readFileSync16, existsSync as existsSync14, statSync as statSync7, mkdirSync as mkdirSync9, writeFileSync as writeFileSync10 } from "fs";
38565
+ import { readFileSync as readFileSync15, existsSync as existsSync13, statSync as statSync7, mkdirSync as mkdirSync8, writeFileSync as writeFileSync9 } from "fs";
38682
38566
  import { dirname as dirname10, extname as extname5, relative as relative4, resolve as resolve11, sep as sep4 } from "path";
38683
38567
  init_colors();
38684
38568
  var LANG_MAP = {
@@ -38899,7 +38783,7 @@ GCC/Rust).
38899
38783
  if (args.length >= 2 && INTERPRETERS[args[0].toLowerCase()] !== void 0) {
38900
38784
  langFromInterp = INTERPRETERS[args[0].toLowerCase()];
38901
38785
  const rest = args.slice(1).join(" ");
38902
- if (existsSync14(rest) && statSync7(rest).isFile()) filePath = rest;
38786
+ if (existsSync13(rest) && statSync7(rest).isFile()) filePath = rest;
38903
38787
  else inlineCode = rest;
38904
38788
  } else if (args.length === 1) {
38905
38789
  inlineCode = args[0];
@@ -38920,7 +38804,7 @@ GCC/Rust).
38920
38804
  let source = inlineCode;
38921
38805
  if (filePath) {
38922
38806
  try {
38923
- source = readFileSync16(filePath, "utf8");
38807
+ source = readFileSync15(filePath, "utf8");
38924
38808
  } catch {
38925
38809
  console.error(error(`Cannot read file: ${filePath}`));
38926
38810
  process.exit(1);
@@ -38947,7 +38831,7 @@ GCC/Rust).
38947
38831
  }
38948
38832
  if (source) {
38949
38833
  const scratchReads = scratchRefsInCode(source).filter(
38950
- (p) => shouldIgnore(p, SCRATCH_IGNORE) && existsSync14(resolve11(process.cwd(), p)) && !isWriteTarget(source, p)
38834
+ (p) => shouldIgnore(p, SCRATCH_IGNORE) && existsSync13(resolve11(process.cwd(), p)) && !isWriteTarget(source, p)
38951
38835
  );
38952
38836
  if (scratchReads.length) {
38953
38837
  console.error(error(`Scratch files are never mirrored into the sandbox, so it can't read: ${scratchReads.join(", ")}`));
@@ -38984,8 +38868,8 @@ GCC/Rust).
38984
38868
  const rel2 = f.path.replace(/\\/g, "/");
38985
38869
  const abs = resolve11(base, rel2);
38986
38870
  if (abs !== base && !abs.startsWith(base + sep4)) continue;
38987
- mkdirSync9(dirname10(abs), { recursive: true });
38988
- writeFileSync10(abs, Buffer.from(f.contentBase64, "base64"));
38871
+ mkdirSync8(dirname10(abs), { recursive: true });
38872
+ writeFileSync9(abs, Buffer.from(f.contentBase64, "base64"));
38989
38873
  scratchWritten.push(rel2);
38990
38874
  }
38991
38875
  }
@@ -39008,7 +38892,7 @@ GCC/Rust).
39008
38892
  }
39009
38893
  if (res.data.outputFiles && res.data.outputFiles.length > 0) {
39010
38894
  const projectRoot = getProjectRoot();
39011
- const landed = (f) => pulledLocal && !!projectRoot && existsSync14(resolve11(projectRoot, f));
38895
+ const landed = (f) => pulledLocal && !!projectRoot && existsSync13(resolve11(projectRoot, f));
39012
38896
  const onDisk = res.data.outputFiles.filter(landed);
39013
38897
  const notOnDisk = res.data.outputFiles.filter((f) => !landed(f));
39014
38898
  if (onDisk.length > 0) {
@@ -39162,6 +39046,167 @@ init_colors();
39162
39046
  init_utils();
39163
39047
  import { join as join18 } from "path";
39164
39048
  import { mkdirSync as mkdirSync10 } from "fs";
39049
+
39050
+ // src/relay/state.ts
39051
+ import { readFileSync as readFileSync16, writeFileSync as writeFileSync10, mkdirSync as mkdirSync9, existsSync as existsSync14, chmodSync as chmodSync3, unlinkSync as unlinkSync5 } from "fs";
39052
+ import { join as join17 } from "path";
39053
+ import { homedir as homedir11 } from "os";
39054
+ var RELAY_DIR = process.env.GIPITY_DIR || join17(homedir11(), ".gipity");
39055
+ var RELAY_FILE = join17(RELAY_DIR, "relay.json");
39056
+ var FILE_MODE = 384;
39057
+ function emptyState() {
39058
+ return { device: null, paused: false };
39059
+ }
39060
+ function loadState() {
39061
+ if (!existsSync14(RELAY_FILE)) return emptyState();
39062
+ try {
39063
+ const raw = JSON.parse(readFileSync16(RELAY_FILE, "utf-8"));
39064
+ return {
39065
+ device: raw.device ?? null,
39066
+ paused: Boolean(raw.paused),
39067
+ relay_enabled: typeof raw.relay_enabled === "boolean" ? raw.relay_enabled : void 0,
39068
+ onboard_shown: Boolean(raw.onboard_shown),
39069
+ diagnostics_consent: typeof raw.diagnostics_consent === "boolean" ? raw.diagnostics_consent : void 0,
39070
+ agent_updates: typeof raw.agent_updates === "boolean" ? raw.agent_updates : void 0,
39071
+ agent_token: typeof raw.agent_token === "string" ? raw.agent_token : null,
39072
+ agent_token_guid: typeof raw.agent_token_guid === "string" ? raw.agent_token_guid : null
39073
+ };
39074
+ } catch {
39075
+ return emptyState();
39076
+ }
39077
+ }
39078
+ function saveState(state) {
39079
+ mkdirSync9(RELAY_DIR, { recursive: true });
39080
+ writeFileSync10(RELAY_FILE, JSON.stringify(state, null, 2) + "\n", { mode: FILE_MODE });
39081
+ try {
39082
+ chmodSync3(RELAY_FILE, FILE_MODE);
39083
+ } catch {
39084
+ }
39085
+ }
39086
+ function mutate(fn) {
39087
+ const s = loadState();
39088
+ fn(s);
39089
+ saveState(s);
39090
+ }
39091
+ function getDevice() {
39092
+ return loadState().device;
39093
+ }
39094
+ function setDevice(device) {
39095
+ mutate((s) => {
39096
+ s.device = device;
39097
+ });
39098
+ }
39099
+ function clearDevice() {
39100
+ mutate((s) => {
39101
+ s.device = null;
39102
+ s.paused = false;
39103
+ s.agent_token = null;
39104
+ s.agent_token_guid = null;
39105
+ });
39106
+ }
39107
+ function getAgentToken() {
39108
+ const s = loadState();
39109
+ return s.agent_token ? { token: s.agent_token, guid: s.agent_token_guid ?? null } : null;
39110
+ }
39111
+ function setAgentToken(token, guid) {
39112
+ mutate((s) => {
39113
+ s.agent_token = token;
39114
+ s.agent_token_guid = guid;
39115
+ });
39116
+ }
39117
+ function isPaused() {
39118
+ return loadState().paused;
39119
+ }
39120
+ function setPaused(paused) {
39121
+ mutate((s) => {
39122
+ s.paused = paused;
39123
+ });
39124
+ }
39125
+ function getRelayEnabled() {
39126
+ return loadState().relay_enabled;
39127
+ }
39128
+ function isRelayEnabled() {
39129
+ return loadState().relay_enabled === true;
39130
+ }
39131
+ function setRelayEnabled(enabled) {
39132
+ mutate((s) => {
39133
+ s.relay_enabled = enabled;
39134
+ });
39135
+ }
39136
+ function getDiagnosticsConsent() {
39137
+ return loadState().diagnostics_consent;
39138
+ }
39139
+ function setDiagnosticsConsent(consent) {
39140
+ mutate((s) => {
39141
+ s.diagnostics_consent = consent;
39142
+ });
39143
+ }
39144
+ function diagnosticsConsented() {
39145
+ const env = process.env.GIPITY_NO_DIAGNOSTICS ?? process.env.DO_NOT_TRACK;
39146
+ if (env && env !== "0" && env.toLowerCase() !== "false") return false;
39147
+ return loadState().diagnostics_consent !== false;
39148
+ }
39149
+ function getAgentUpdatesPref() {
39150
+ return loadState().agent_updates;
39151
+ }
39152
+ function setAgentUpdatesPref(on2) {
39153
+ mutate((s) => {
39154
+ s.agent_updates = on2;
39155
+ });
39156
+ }
39157
+ function agentUpdatesEnabled() {
39158
+ if (process.env.DISABLE_AUTOUPDATER === "1") return false;
39159
+ const env = (process.env.GIPITY_RELAY_AGENT_UPDATES || "").toLowerCase();
39160
+ if (["0", "off", "false", "no"].includes(env)) return false;
39161
+ if (["1", "on", "true", "yes"].includes(env)) return true;
39162
+ if (process.env.CI || process.env.NODE_ENV === "test") return false;
39163
+ return loadState().agent_updates !== false;
39164
+ }
39165
+ var RELAY_PID_FILE = join17(RELAY_DIR, "relay.pid");
39166
+ function getDaemonPidPath() {
39167
+ return RELAY_PID_FILE;
39168
+ }
39169
+ function writeDaemonPid(pid) {
39170
+ mkdirSync9(RELAY_DIR, { recursive: true });
39171
+ writeFileSync10(RELAY_PID_FILE, String(pid), { flag: "wx" });
39172
+ }
39173
+ function clearDaemonPid() {
39174
+ try {
39175
+ unlinkSync5(RELAY_PID_FILE);
39176
+ } catch {
39177
+ }
39178
+ }
39179
+ function isDaemonRunning() {
39180
+ if (!existsSync14(RELAY_PID_FILE)) return false;
39181
+ try {
39182
+ const raw = readFileSync16(RELAY_PID_FILE, "utf-8").trim();
39183
+ const pid = parseInt(raw, 10);
39184
+ if (!pid || isNaN(pid)) {
39185
+ try {
39186
+ unlinkSync5(RELAY_PID_FILE);
39187
+ } catch {
39188
+ }
39189
+ return false;
39190
+ }
39191
+ if (pid === process.pid) {
39192
+ try {
39193
+ unlinkSync5(RELAY_PID_FILE);
39194
+ } catch {
39195
+ }
39196
+ return false;
39197
+ }
39198
+ process.kill(pid, 0);
39199
+ return true;
39200
+ } catch {
39201
+ try {
39202
+ unlinkSync5(RELAY_PID_FILE);
39203
+ } catch {
39204
+ }
39205
+ return false;
39206
+ }
39207
+ }
39208
+
39209
+ // src/commands/project.ts
39165
39210
  var projectCommand = new Command("project").description("Manage projects").argument("[name]", "Switch to project by name/slug").option("--json", "Output as JSON").action((name, opts) => run("Project", async () => {
39166
39211
  const config = requireConfig();
39167
39212
  if (name) {
@@ -41949,12 +41994,7 @@ async function createNewProject(existingSlugs, preset) {
41949
41994
  continue;
41950
41995
  }
41951
41996
  try {
41952
- const device = getDevice();
41953
41997
  const body = { name: projectName, slug: projectSlug };
41954
- if (device) {
41955
- body.autoChat = "claude_code";
41956
- body.deviceGuid = device.guid;
41957
- }
41958
41998
  const res = await post("/projects", body);
41959
41999
  console.log(` ${info(`Creating "${projectName}"...`)} ${success("Created.")}`);
41960
42000
  return res.data;
@@ -43364,7 +43404,7 @@ serviceCommand.command("call <name> [body]").description("Call an app service by
43364
43404
  }
43365
43405
  res = await publicRequest(opts.get ? "GET" : "POST", url, opts.get ? void 0 : body, headers);
43366
43406
  } else {
43367
- res = opts.get ? await get(url) : await post(url, body);
43407
+ res = opts.get ? await get(url) : await post(url, body, { timeoutMs: LONG_REQUEST_TIMEOUT_MS });
43368
43408
  }
43369
43409
  } catch (err) {
43370
43410
  const hint = opts.anon ? anonBillingHint(name, err) : null;
@@ -44334,7 +44374,7 @@ Examples:
44334
44374
  image_size: opts.imageSize,
44335
44375
  seed: Number.isFinite(opts.seed) ? opts.seed : void 0,
44336
44376
  input_images: inputImages
44337
- });
44377
+ }, { timeoutMs: LONG_REQUEST_TIMEOUT_MS });
44338
44378
  const verb = inputImages ? "Editing image..." : "Generating image...";
44339
44379
  const started = Date.now();
44340
44380
  const result = opts.json ? await doGenerate() : await withSpinner(verb, doGenerate, { done: null });
@@ -44383,7 +44423,7 @@ Examples:
44383
44423
  aspect_ratio: opts.aspect,
44384
44424
  resolution: opts.resolution,
44385
44425
  duration_seconds: opts.duration ? Number(opts.duration) : void 0
44386
- });
44426
+ }, { timeoutMs: LONG_REQUEST_TIMEOUT_MS });
44387
44427
  const started = Date.now();
44388
44428
  const result = opts.json ? await doGenerate() : await withSpinner("Generating video...", doGenerate, { done: null });
44389
44429
  const elapsed = (Date.now() - started) / 1e3;
@@ -44438,7 +44478,7 @@ Examples:
44438
44478
  voice: opts.voice,
44439
44479
  language: opts.language,
44440
44480
  speakers
44441
- });
44481
+ }, { timeoutMs: LONG_REQUEST_TIMEOUT_MS });
44442
44482
  const started = Date.now();
44443
44483
  const result = opts.json ? await doGenerate() : await withSpinner("Generating speech...", doGenerate, { done: null });
44444
44484
  const elapsed = (Date.now() - started) / 1e3;
@@ -44490,7 +44530,7 @@ Examples:
44490
44530
  // Lyrics imply vocals; otherwise instrumental unless --vocals.
44491
44531
  instrumental: lyrics ? false : !opts.vocals,
44492
44532
  lyrics: lyrics || void 0
44493
- });
44533
+ }, { timeoutMs: LONG_REQUEST_TIMEOUT_MS });
44494
44534
  const started = Date.now();
44495
44535
  const result = opts.json ? await doGenerate() : await withSpinner("Generating music...", doGenerate, { done: null });
44496
44536
  const elapsed = (Date.now() - started) / 1e3;
@@ -44530,7 +44570,7 @@ Examples:
44530
44570
  text,
44531
44571
  duration_seconds: opts.duration,
44532
44572
  prompt_influence: opts.influence
44533
- });
44573
+ }, { timeoutMs: LONG_REQUEST_TIMEOUT_MS });
44534
44574
  const started = Date.now();
44535
44575
  const result = opts.json ? await doGenerate() : await withSpinner("Generating sound effect...", doGenerate, { done: null });
44536
44576
  const elapsed = (Date.now() - started) / 1e3;