gipity 1.1.7 → 1.1.10

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.
@@ -9,7 +9,7 @@ export const updateCommand = new Command('update')
9
9
  console.log('');
10
10
  if (result.updated) {
11
11
  console.log(success(`Updated ${result.from} → ${result.to}`));
12
- console.log(dim('The new version takes effect on your next gipity command.'));
12
+ console.log(dim(`Installed. This command ran on ${result.from}; everything from here on uses ${result.to}.`));
13
13
  }
14
14
  else if (result.reason === 'up-to-date') {
15
15
  console.log(success('Already on the latest version.'));
@@ -15,21 +15,18 @@ import { run } from '../helpers/index.js';
15
15
  // (Uploading into the project tree with `gipity push` does NOT give a public URL
16
16
  // until you deploy; this does.)
17
17
  export const uploadCommand = new Command('upload')
18
- .description(`Upload a local file and print a durable, worker-reachable URL for it.
19
-
20
- The URL works immediately - no \`gipity deploy\` - and any job or function can
21
- fetch it. Use it to hand a GPU/CPU job a real input file when testing end-to-end:
22
-
23
- gipity upload song.mp3
24
- gipity job submit split-stems --data '{"audio_url":"<printed url>"}'
25
-
26
- By default the file is PUBLIC: a plain \`media.gipity.ai\` CDN url that resolves
27
- from anywhere, so a cloud worker can always fetch it. Pass --private for a
28
- token-signed serve url instead (reachable only by holders of the url).`)
18
+ .description('Upload a file and print a durable public URL (works immediately, no deploy)')
29
19
  .argument('<file>', 'Local file to upload')
30
20
  .option('--private', 'Store as a private token-signed serve URL instead of a public CDN url')
31
21
  .option('--content-type <mime>', 'Override the content type (default: detected from the file extension)')
32
22
  .option('--json', 'Output as JSON')
23
+ .addHelpText('after', `
24
+ Public by default (a media.gipity.ai CDN url any job or function can fetch);
25
+ --private mints a token-signed serve url instead. Example:
26
+
27
+ gipity upload song.mp3
28
+ gipity job submit split-stems --data '{"audio_url":"<printed url>"}'
29
+ `)
33
30
  .action((file, opts) => run('Upload', async () => {
34
31
  const { config } = await resolveProjectContext();
35
32
  let size;
@@ -48,45 +48,17 @@ import { getDevice } from '../relay/state.js';
48
48
  import { deviceFetch } from '../relay/device-http.js';
49
49
  import { ImageBlockRewriter } from '../relay/media-upload.js';
50
50
  import { getConfig } from '../config.js';
51
- import { parseTranscript as parseClaudeTranscript, } from '../capture/sources/claude-code.js';
52
- import { parseTranscript as parseCodexTranscript } from '../capture/sources/codex.js';
53
- import { parseTranscript as parseGrokTranscript } from '../capture/sources/grok.js';
54
- import { parseTranscript as parseAgyTranscript } from '../capture/sources/agy.js';
51
+ import { AGENT_ADAPTERS } from '../agents/index.js';
55
52
  const CAPTURE_DIR = join(homedir(), '.gipity', 'capture-state');
56
53
  const INGEST_BATCH_MAX = 100; // server caps at 200; stay comfortably under
57
- export const CAPTURE_SOURCES = {
58
- 'claude-code': {
59
- serverSource: 'claude_code',
60
- displayName: 'Claude Code',
61
- parse: (content, afterUuid) => parseClaudeTranscript(content, afterUuid),
62
- },
63
- codex: {
64
- serverSource: 'codex',
65
- displayName: 'Codex',
66
- // Codex hook payloads always carry transcript_path (the rollout file).
67
- parse: (content, afterUuid) => parseCodexTranscript(content, afterUuid),
68
- },
69
- grok: {
70
- serverSource: 'grok',
71
- displayName: 'Grok',
72
- parse: (content, afterUuid, hook) => parseGrokTranscript(content, afterUuid, { sessionId: hook.session_id }),
73
- // Grok's session dir is derivable: ~/.grok/sessions/<urlencoded-cwd>/<sid>/
74
- resolveTranscriptPath: (hook) => {
75
- if (!hook.session_id)
76
- return null;
77
- const cwd = hook.cwd ?? process.cwd();
78
- return join(homedir(), '.grok', 'sessions', encodeURIComponent(cwd), hook.session_id, 'chat_history.jsonl');
79
- },
80
- },
81
- agy: {
82
- serverSource: 'agy',
83
- displayName: 'Antigravity',
84
- // agy hook payloads always carry transcriptPath directly (no derivation
85
- // needed, unlike Grok) - the agy-specific hook wrapper normalizes it into
86
- // this HookInput's transcript_path before invoking this runner.
87
- parse: (content, afterUuid, hook) => parseAgyTranscript(content, afterUuid, { conversationId: hook.session_id }),
88
- },
89
- };
54
+ /** Find the agent adapter whose capture wiring owns this hook-argv source
55
+ * spelling (what the hook scripts pass - NOT the server's `source` value;
56
+ * those differ for Claude: 'claude-code' vs 'claude_code'). Adding an agent
57
+ * = one file under cli/src/agents/ with a `capture` field; no separate
58
+ * registry to keep in sync. */
59
+ function findCaptureAdapter(hookKey) {
60
+ return AGENT_ADAPTERS.find((a) => a.capture.hookKey === hookKey);
61
+ }
90
62
  // PostToolUse fires after every tool call. We flush on it so a session that is
91
63
  // killed/crashes mid-run (e.g. a long headless `gipity claude -p` build that
92
64
  // hits a timeout) still has its transcript in the DB - Stop/SessionEnd only
@@ -110,6 +82,7 @@ function readState(convGuid) {
110
82
  return {
111
83
  last_uuid: typeof parsed.last_uuid === 'string' ? parsed.last_uuid : null,
112
84
  last_flush_ms: typeof parsed.last_flush_ms === 'number' ? parsed.last_flush_ms : undefined,
85
+ attached: typeof parsed.attached === 'boolean' ? parsed.attached : undefined,
113
86
  };
114
87
  }
115
88
  catch {
@@ -365,12 +338,22 @@ async function readWholeFile(path) {
365
338
  s.on('error', (err) => reject(err));
366
339
  });
367
340
  }
368
- async function handleSessionStart(convGuid, hook) {
341
+ /** Bind the session_id to this conversation server-side (remote_session_id -
342
+ * what makes resume work), once per conversation. Called for EVERY event,
343
+ * not just SessionStart: Claude/Codex fire a real SessionStart hook, but
344
+ * agy's event set has no equivalent (PreToolUse/PostToolUse/PreInvocation/
345
+ * PostInvocation/Stop only) - and the dispatch path (GIPITY_CONVERSATION_GUID
346
+ * env var) never touches resolveFromServer's own attach either, since it
347
+ * short-circuits before that call. Idempotent both here (the `attached`
348
+ * state flag) and server-side (attachRemoteSessionId only assigns when
349
+ * remote_session_id IS NULL), so calling it redundantly for agents that DO
350
+ * have a SessionStart event is harmless. */
351
+ async function ensureAttached(convGuid, hook) {
369
352
  if (!hook.session_id)
370
353
  return;
371
- const existing = readState(convGuid);
372
- if (!existing)
373
- writeState(convGuid, { last_uuid: null });
354
+ const state = readState(convGuid);
355
+ if (state?.attached)
356
+ return;
374
357
  const entries = [{
375
358
  kind: 'attach',
376
359
  session_id: hook.session_id,
@@ -378,7 +361,9 @@ async function handleSessionStart(convGuid, hook) {
378
361
  source: 'startup',
379
362
  source_uuid: `${hook.session_id}-attach`,
380
363
  }];
381
- await postEntries(convGuid, entries);
364
+ const ok = await postEntries(convGuid, entries);
365
+ if (ok)
366
+ writeState(convGuid, { ...(state ?? { last_uuid: null }), attached: true });
382
367
  }
383
368
  async function handleStopFamily(convGuid, src, hook, isSubagent, minIntervalMs = 0) {
384
369
  void isSubagent;
@@ -397,11 +382,11 @@ async function handleStopFamily(convGuid, src, hook, isSubagent, minIntervalMs =
397
382
  try {
398
383
  const state = readState(convGuid) ?? { last_uuid: null };
399
384
  const content = await readWholeFile(hook.transcript_path);
400
- let result = src.parse(content, state.last_uuid, hook);
385
+ let result = src.capture.parse(content, state.last_uuid, hook);
401
386
  if (!result.foundWatermark && state.last_uuid !== null) {
402
387
  // Transcript rotated (/clear or compact) - watermark isn't present.
403
388
  // Replay from top; server dedupes via the source_uuid unique index.
404
- result = src.parse(content, null, hook);
389
+ result = src.capture.parse(content, null, hook);
405
390
  }
406
391
  // Base64 image blocks (Read-of-image tool results) upload to VFS and
407
392
  // become image_ref blocks — same no-inline-base64 chokepoint as the
@@ -503,7 +488,7 @@ async function main() {
503
488
  const [source, event] = process.argv.slice(2);
504
489
  if (!source || !event)
505
490
  return;
506
- const src = CAPTURE_SOURCES[source];
491
+ const src = findCaptureAdapter(source);
507
492
  if (!src)
508
493
  return; // unknown agent - silent no-op
509
494
  const stdin = await readStdin();
@@ -516,22 +501,22 @@ async function main() {
516
501
  }
517
502
  // Agents whose hook payloads omit the transcript path (Grok) get it
518
503
  // derived from the session id + cwd.
519
- if (!hook.transcript_path && src.resolveTranscriptPath) {
520
- const derived = src.resolveTranscriptPath(hook);
504
+ if (!hook.transcript_path && src.capture.resolveTranscriptPath) {
505
+ const derived = src.capture.resolveTranscriptPath(hook);
521
506
  if (derived)
522
507
  hook.transcript_path = derived;
523
508
  }
524
509
  // Opportunistic hygiene: Codex and agy never fire session-end, so their
525
510
  // state files are TTL-swept instead of deleted at end-of-session.
526
511
  sweepStaleState();
527
- const convGuid = await resolveConvGuid(hook, src.serverSource);
512
+ const convGuid = await resolveConvGuid(hook, src.source);
528
513
  if (!convGuid)
529
514
  return; // not a Gipity-bound session - nothing to capture
515
+ await ensureAttached(convGuid, hook);
530
516
  try {
531
517
  switch (event) {
532
518
  case 'session-start':
533
- await handleSessionStart(convGuid, hook);
534
- break;
519
+ break; // ensureAttached above already covers what this event used to do
535
520
  case 'stop':
536
521
  await handleStopFamily(convGuid, src, hook, false);
537
522
  break;