gipity 1.1.16 → 1.1.19

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 +58 -75
  2. package/dist/adopt-cwd.js +2 -13
  3. package/dist/api.js +26 -44
  4. package/dist/auth.js +1 -1
  5. package/dist/banner.js +3 -7
  6. package/dist/catalog.js +8 -7
  7. package/dist/commands/add.js +26 -9
  8. package/dist/commands/approval.js +1 -1
  9. package/dist/commands/ask.js +112 -0
  10. package/dist/commands/bug.js +5 -5
  11. package/dist/commands/build.js +10 -35
  12. package/dist/commands/credits.js +3 -3
  13. package/dist/commands/doctor.js +7 -8
  14. package/dist/commands/email.js +6 -56
  15. package/dist/commands/generate.js +4 -4
  16. package/dist/commands/init.js +40 -30
  17. package/dist/commands/key.js +1 -1
  18. package/dist/commands/load.js +2 -12
  19. package/dist/commands/logs.js +2 -2
  20. package/dist/commands/memory.js +5 -17
  21. package/dist/commands/notify.js +1 -1
  22. package/dist/commands/page-eval.js +55 -38
  23. package/dist/commands/page-inspect.js +6 -6
  24. package/dist/commands/page-screenshot.js +51 -54
  25. package/dist/commands/page-test.js +188 -14
  26. package/dist/commands/payments.js +2 -2
  27. package/dist/commands/project.js +66 -15
  28. package/dist/commands/realtime.js +96 -4
  29. package/dist/commands/records.js +4 -6
  30. package/dist/commands/sandbox.js +2 -3
  31. package/dist/commands/skill.js +50 -22
  32. package/dist/commands/status.js +7 -9
  33. package/dist/commands/test.js +2 -2
  34. package/dist/commands/token.js +4 -4
  35. package/dist/commands/workflow.js +45 -8
  36. package/dist/config.js +22 -6
  37. package/dist/flag-aliases.js +75 -18
  38. package/dist/help-skills.js +2 -2
  39. package/dist/hooks/capture-runner.js +5 -3
  40. package/dist/index.js +1616 -1498
  41. package/dist/knowledge.js +24 -21
  42. package/dist/login-flow.js +4 -4
  43. package/dist/net.js +91 -0
  44. package/dist/opencode-setup.js +2 -2
  45. package/dist/page-fixtures.js +3 -3
  46. package/dist/project-setup.js +2 -3
  47. package/dist/prompts.js +1 -1
  48. package/dist/realtime-bench.js +12040 -0
  49. package/dist/relay/agent-token.js +1 -1
  50. package/dist/relay/daemon.js +0 -1
  51. package/dist/relay/setup.js +13 -2
  52. package/dist/setup.js +11 -12
  53. package/dist/sync.js +3 -3
  54. package/dist/utils.js +1 -1
  55. package/package.json +10 -4
  56. package/dist/commands/agent.js +0 -251
  57. package/dist/commands/chat.js +0 -137
  58. package/dist/commands/claude.js +0 -1056
  59. package/dist/commands/plan.js +0 -93
@@ -1,6 +1,9 @@
1
1
  import { Command, Option } from 'commander';
2
+ import { existsSync, mkdirSync, writeFileSync } from 'fs';
3
+ import { join } from 'path';
2
4
  import { get, post, put, del } from '../api.js';
3
- import { getConfig, requireConfig } from '../config.js';
5
+ import { getConfig, requireConfig, getProjectRoot } from '../config.js';
6
+ import { pushFile } from '../sync.js';
4
7
  import { success, error as clrError, muted, bold } from '../colors.js';
5
8
  import { run, printList, printResult } from '../helpers/index.js';
6
9
  // `--json` is declared on the parent `workflow` command (so the bare list
@@ -273,7 +276,7 @@ workflowCommand
273
276
  const wf = await resolveWorkflow(name);
274
277
  const res = await put(`/workflows/${wf.short_guid}`, { is_active: true });
275
278
  if (!res.data?.is_active) {
276
- console.error(clrError(`Workflow "${wf.name}" is still inactive after enable — not enabled.`));
279
+ console.error(clrError(`Workflow "${wf.name}" is still inactive after enable: not enabled.`));
277
280
  process.exit(1);
278
281
  }
279
282
  printResult(`Enabled "${wf.name}".`, opts, { enabled: wf.name, is_active: true });
@@ -287,29 +290,63 @@ workflowCommand
287
290
  const wf = await resolveWorkflow(name);
288
291
  const res = await put(`/workflows/${wf.short_guid}`, { is_active: false });
289
292
  if (res.data?.is_active) {
290
- console.error(clrError(`Workflow "${wf.name}" is still active after disable — not disabled.`));
293
+ console.error(clrError(`Workflow "${wf.name}" is still active after disable: not disabled.`));
291
294
  process.exit(1);
292
295
  }
293
296
  printResult(`Disabled "${wf.name}".`, opts, { disabled: wf.name, is_active: false });
294
297
  }));
298
+ const HEARTBEAT_PATH = 'workflows/heartbeat.yaml';
299
+ /** The `--heartbeat` starter: a daily llm step that keeps notes in project memory. */
300
+ const HEARTBEAT_YAML = `# A heartbeat: once a day, look at this project and keep notes in project memory.
301
+ # Edit the prompt and tools, then \`gipity deploy\` (or \`gipity workflow edit heartbeat --from ${HEARTBEAT_PATH}\`).
302
+ name: heartbeat
303
+ description: Daily check-in on this project, with notes kept in project memory.
304
+ trigger: schedule
305
+ cron: "0 9 * * *"
306
+ steps:
307
+ - name: check_in
308
+ prompt: |
309
+ Check in on this project. Read the "heartbeat" memory topic for what you noted last time.
310
+ Look at what changed since then and anything that needs attention.
311
+ Write the "heartbeat" memory topic again with what you saw and what to watch next time,
312
+ then return { summary, needs_attention } where needs_attention is a list of short strings.
313
+ tools: [memory, db_query]
314
+ `;
295
315
  workflowCommand
296
316
  .command('create')
297
317
  .description('Create a workflow from a YAML file in the project (e.g. workflows/foo.yaml)')
298
- .requiredOption('--from <path>', 'Project-relative YAML file path')
318
+ .option('--from <path>', 'Project-relative YAML file path')
319
+ .option('--heartbeat', `Scaffold ${HEARTBEAT_PATH} (a daily check-in that keeps notes in project memory) and create it`)
299
320
  .option('--name <name>', 'Override the name in the YAML')
300
321
  .option('--json', 'Output as JSON')
301
322
  .action((_opts, cmd) => run('Create', async () => {
302
323
  const opts = mergedOpts(cmd);
303
324
  const config = requireConfig();
325
+ if (opts.from && opts.heartbeat)
326
+ throw new Error('Pass --from <path> or --heartbeat, not both.');
327
+ if (!opts.from && !opts.heartbeat)
328
+ throw new Error('Pass --from <path> (a workflows/*.yaml file), or --heartbeat to start from a daily check-in.');
329
+ let from = opts.from;
330
+ if (opts.heartbeat) {
331
+ from = HEARTBEAT_PATH;
332
+ const root = getProjectRoot();
333
+ const local = join(root, HEARTBEAT_PATH);
334
+ // Never overwrite: an existing heartbeat.yaml is the user's edited copy.
335
+ if (!existsSync(local)) {
336
+ mkdirSync(join(root, 'workflows'), { recursive: true });
337
+ writeFileSync(local, HEARTBEAT_YAML);
338
+ }
339
+ await pushFile(local);
340
+ }
304
341
  const body = {
305
- config_yaml_path: opts.from,
342
+ config_yaml_path: from,
306
343
  project_guid: config.projectGuid,
307
344
  };
308
345
  if (opts.name)
309
346
  body.name = opts.name;
310
347
  const res = await post('/workflows', body);
311
348
  const guid = res.data.short_guid ?? res.data.guid;
312
- printResult(`Workflow created (${guid}).`, opts, { created: true, guid });
349
+ printResult(`Workflow created from ${from} (${guid}).`, opts, { created: true, guid, from });
313
350
  }));
314
351
  workflowCommand
315
352
  .command('edit <name>')
@@ -339,7 +376,7 @@ workflowCommand
339
376
  // actually went inactive rather than trusting the request was accepted.
340
377
  const after = await get(`/workflows/${wf.short_guid}`);
341
378
  if (after.data?.is_active) {
342
- console.error(clrError(`Workflow "${wf.name}" (${wf.short_guid}) is still active — delete had no effect.`));
379
+ console.error(clrError(`Workflow "${wf.name}" (${wf.short_guid}) is still active: delete had no effect.`));
343
380
  process.exit(1);
344
381
  }
345
382
  printResult(`Deleted "${wf.name}".`, opts, { deleted: wf.name, short_guid: wf.short_guid });
@@ -369,7 +406,7 @@ async function resolveWorkflow(name) {
369
406
  const active = byName.filter(w => w.is_active);
370
407
  if (active.length === 1)
371
408
  return active[0];
372
- console.error(clrError(`${byName.length} workflows named "${name}" in this project — pass a short_guid:\n` +
409
+ console.error(clrError(`${byName.length} workflows named "${name}" in this project. Pass a short_guid:\n` +
373
410
  byName.map(w => ` ${w.short_guid}${w.is_active ? '' : ' (inactive)'}`).join('\n')));
374
411
  process.exit(1);
375
412
  }
package/dist/config.js CHANGED
@@ -57,7 +57,7 @@ export function resolveApiBase() {
57
57
  return fromConfig;
58
58
  if (!warnedHosts.has(fromConfig)) {
59
59
  warnedHosts.add(fromConfig);
60
- console.error(`⚠ Ignoring untrusted apiBase "${fromConfig}" from .gipity.json — not a gipity.ai host. Using ${DEFAULT_API_BASE}.`);
60
+ console.error(`⚠ Ignoring untrusted apiBase "${fromConfig}" from .gipity.json: not a gipity.ai host. Using ${DEFAULT_API_BASE}.`);
61
61
  }
62
62
  }
63
63
  return DEFAULT_API_BASE;
@@ -132,7 +132,6 @@ export async function resolveProjectContext(opts) {
132
132
  console.error(`Project not found: ${target}`);
133
133
  process.exit(1);
134
134
  }
135
- const agents = await get(`/projects/${match.short_guid}/agents`);
136
135
  const accountSlug = await getAccountSlug();
137
136
  console.error(dim(`→ (project: ${match.slug} · no file sync)`));
138
137
  console.error('');
@@ -141,7 +140,6 @@ export async function resolveProjectContext(opts) {
141
140
  projectGuid: match.short_guid,
142
141
  projectSlug: match.slug,
143
142
  accountSlug,
144
- agentGuid: agents.data[0]?.short_guid ?? '',
145
143
  conversationGuid: null,
146
144
  apiBase: getApiBaseOverride() || DEFAULT_API_BASE,
147
145
  ignore: [],
@@ -170,7 +168,6 @@ export async function resolveProjectContext(opts) {
170
168
  projectGuid: res.data.projectGuid,
171
169
  projectSlug: res.data.projectSlug,
172
170
  accountSlug: res.data.accountSlug,
173
- agentGuid: res.data.agentGuid ?? '',
174
171
  conversationGuid: null,
175
172
  apiBase: getApiBaseOverride() || DEFAULT_API_BASE,
176
173
  ignore: [],
@@ -195,7 +192,7 @@ export function clearConfigCache() {
195
192
  }
196
193
  export function saveConfig(data) {
197
194
  // saveConfig only ever *updates* an existing project config. It must never
198
- // create a new `.gipity.json`: a one-off command (e.g. `gipity chat`) run
195
+ // create a new `.gipity.json`: a one-off command (e.g. `gipity ask`) run
199
196
  // in an unrelated folder resolves to the server's Home project, and a
200
197
  // create-on-save here would silently turn that folder - in the wild, often
201
198
  // `$HOME` itself - into a Gipity project. Creating a config is always an
@@ -203,7 +200,7 @@ export function saveConfig(data) {
203
200
  const path = getConfigPath();
204
201
  if (!path) {
205
202
  throw new Error('saveConfig: no .gipity.json found to update. ' +
206
- 'Use saveConfigAt(dir, …) to create a new project config.');
203
+ 'Use saveConfigAt(dir, ...) to create a new project config.');
207
204
  }
208
205
  writeFileSync(path, JSON.stringify(data, null, 2) + '\n');
209
206
  cached = data;
@@ -214,10 +211,29 @@ export function saveConfig(data) {
214
211
  * accidentally rewrite a parent project's config file. */
215
212
  export function saveConfigAt(dir, data) {
216
213
  const path = resolve(dir, CONFIG_FILE);
214
+ // A new project starts with session capture OFF: recording someone's coding
215
+ // sessions is opt-in (`gipity init --capture`). Existing configs keep what
216
+ // they have - an absent key there still means on, as it always has.
217
+ if (!existsSync(path) && data.captureHooks === undefined)
218
+ data = { ...data, captureHooks: false };
217
219
  writeFileSync(path, JSON.stringify(data, null, 2) + '\n');
218
220
  cached = data;
219
221
  cachedPath = path;
220
222
  }
223
+ /**
224
+ * Whether this project's coding-agent sessions are recorded to Gipity.
225
+ * GIPITY_CAPTURE=off always wins (the relay daemon owns capture for its
226
+ * dispatches), GIPITY_CAPTURE=on forces it (GipRunner scores builds from the
227
+ * recording), otherwise `.gipity.json` decides: new projects are created with
228
+ * `captureHooks: false`, and an older config without the key records.
229
+ */
230
+ export function captureEnabled(config) {
231
+ if (process.env.GIPITY_CAPTURE === 'off')
232
+ return false;
233
+ if (process.env.GIPITY_CAPTURE === 'on')
234
+ return true;
235
+ return config?.captureHooks !== false;
236
+ }
221
237
  /** Compiled matchers cached by their pattern set so the per-file `shouldIgnore`
222
238
  * call in the sync loop doesn't rebuild the matcher every time. */
223
239
  const ignoreMatcherCache = new Map();
@@ -37,8 +37,14 @@ export const FLAG_ALIASES = {
37
37
  export function normalizeAliases(argv, program) {
38
38
  // Flags the targeted command declares for real — never alias these, so a
39
39
  // command's own option always wins over a global guess.
40
- const realFlags = program ? collectRealFlags(argv, program) : new Set();
41
- return argv.map(tok => {
40
+ const target = program ? resolveTarget(argv, program) : null;
41
+ const realFlags = new Set();
42
+ for (const c of target?.chain ?? []) {
43
+ for (const opt of c.options)
44
+ if (opt.long)
45
+ realFlags.add(opt.long);
46
+ }
47
+ const aliased = argv.map(tok => {
42
48
  if (!tok.startsWith('--'))
43
49
  return tok;
44
50
  const eq = tok.indexOf('=');
@@ -53,41 +59,92 @@ export function normalizeAliases(argv, program) {
53
59
  return tok;
54
60
  return FLAG_ALIASES[tok] ?? tok;
55
61
  });
62
+ return target ? rewriteKeyValuePositionals(aliased, target) : aliased;
63
+ }
64
+ /**
65
+ * `key=value` positional -> `--key=value`, when it can only have meant the flag.
66
+ *
67
+ * Agents keep carrying an option over as a bare `key=value` positional
68
+ * (`gipity add 2d-game title="Brick Breaker"`), the form many CLIs and
69
+ * Makefiles accept. Rather than error and cost a retry turn, read it as the
70
+ * option - but only when that is unambiguous: the token sits PAST the
71
+ * command's declared positionals (so it can't be a real argument that merely
72
+ * contains `=`, like a SQL string or an env assignment for `sandbox run`), the
73
+ * command has no variadic argument to soak it up, and `--key` (or its alias) is
74
+ * a value-taking option the targeted command actually declares. Anything else is
75
+ * left alone, so commander's excess-argument error still names it.
76
+ */
77
+ function rewriteKeyValuePositionals(argv, target) {
78
+ const { leaf, chain, firstOperand } = target;
79
+ const declared = leaf.registeredArguments;
80
+ if (leaf.commands.length > 0 || declared.some(a => a.variadic))
81
+ return argv;
82
+ const options = chain.flatMap(c => c.options);
83
+ const byLong = new Map(options.filter(o => o.long).map(o => [o.long, o]));
84
+ const byShort = new Map(options.filter(o => o.short).map(o => [o.short, o]));
85
+ const takesValue = (tok) => {
86
+ if (tok.includes('='))
87
+ return false;
88
+ const o = byLong.get(tok) ?? byShort.get(tok);
89
+ return !!o && (o.required || o.optional);
90
+ };
91
+ const out = argv.slice();
92
+ let positional = 0;
93
+ for (let i = firstOperand; i < out.length; i++) {
94
+ const tok = out[i];
95
+ if (tok === '--')
96
+ break; // everything after is a literal operand
97
+ if (tok.startsWith('-')) {
98
+ if (takesValue(tok))
99
+ i++; // skip its value
100
+ continue;
101
+ }
102
+ const index = positional++;
103
+ if (index < declared.length)
104
+ continue;
105
+ const kv = /^([A-Za-z][\w-]*)=([\s\S]*)$/.exec(tok);
106
+ if (!kv)
107
+ continue;
108
+ const flag = [`--${kv[1]}`, FLAG_ALIASES[`--${kv[1]}`]].find(f => {
109
+ const o = f ? byLong.get(f) : undefined;
110
+ return !!o && (o.required || o.optional);
111
+ });
112
+ if (flag)
113
+ out[i] = `${flag}=${kv[2]}`;
114
+ }
115
+ return out;
56
116
  }
57
117
  /**
58
118
  * Resolve the deepest subcommand argv targets (descending program → command →
59
- * subcommand by name/alias) and return every long flag declared on it and its
60
- * ancestors. Used to suppress an alias when the resolved command owns that flag.
119
+ * subcommand by name/alias). Used to suppress an alias when the resolved command
120
+ * owns that flag, and to find the command's operands.
61
121
  */
62
- function collectRealFlags(argv, program) {
63
- // process.argv is [node, script, ...args]; start scanning at the first arg.
64
- const args = argv.slice(2);
122
+ export function resolveTarget(argv, program) {
65
123
  let cmd = program;
66
124
  const chain = [program];
67
125
  // Root value-options (e.g. `--api-base <url>`) may legitimately precede the
68
126
  // subcommand; skip them (and their value token) rather than ending resolution
69
127
  // there, so a command's own flag is still discovered when a global flag leads.
70
128
  const rootValueFlags = new Set(program.options.filter(o => o.long && o.required).map(o => o.long));
71
- for (let i = 0; i < args.length; i++) {
72
- const tok = args[i];
129
+ // process.argv is [node, script, ...args]; start scanning at the first arg.
130
+ let firstOperand = 2;
131
+ let operand;
132
+ for (let i = 2; i < argv.length; i++) {
133
+ const tok = argv[i];
73
134
  if (tok.startsWith('-')) {
74
135
  if (!tok.includes('=') && rootValueFlags.has(tok))
75
136
  i++; // consume its value
76
137
  continue;
77
138
  }
78
139
  const next = cmd.commands.find(c => c.name() === tok || c.aliases().includes(tok));
79
- if (!next)
140
+ if (!next) {
141
+ operand = tok;
80
142
  break;
143
+ }
81
144
  cmd = next;
82
145
  chain.push(next);
146
+ firstOperand = i + 1;
83
147
  }
84
- const flags = new Set();
85
- for (const c of chain) {
86
- for (const opt of c.options) {
87
- if (opt.long)
88
- flags.add(opt.long);
89
- }
90
- }
91
- return flags;
148
+ return { chain, leaf: cmd, firstOperand, operand };
92
149
  }
93
150
  //# sourceMappingURL=flag-aliases.js.map
@@ -16,11 +16,11 @@ export async function fetchAndPrintSkill(skillName) {
16
16
  const config = getConfig();
17
17
  if (!config)
18
18
  return;
19
- const listRes = await get(`/skills?agent=${config.agentGuid}`);
19
+ const listRes = await get('/skills');
20
20
  const match = listRes.data.find(s => s.name.toLowerCase() === skillName.toLowerCase());
21
21
  if (!match)
22
22
  return;
23
- const res = await get(`/skills/${match.guid}?agent=${config.agentGuid}`);
23
+ const res = await get(`/skills/${match.guid}`);
24
24
  if (res.data.content) {
25
25
  console.log(muted(`\n── Skill: ${skillName} (auto-loaded from server) ──\n`));
26
26
  console.log(res.data.content);
@@ -36,7 +36,9 @@
36
36
  * - GIPITY_CAPTURE=off - the relay daemon owns capture for this run
37
37
  * (it parses stream-json from stdout), or the caller opted out.
38
38
  * - No binding resolvable: not a Gipity project, `captureHooks: false`
39
- * in .gipity.json, or the resolve call failed.
39
+ * in .gipity.json (new projects start that way; GIPITY_CAPTURE=on
40
+ * overrides it, which is how GipRunner records its builds), or the
41
+ * resolve call failed.
40
42
  * - The machine isn't paired - no device token available.
41
43
  * - Anything unexpected (parse error, network error, etc.). We must
42
44
  * not break the user's interactive session.
@@ -47,7 +49,7 @@ import { join } from 'path';
47
49
  import { getDevice } from '../relay/state.js';
48
50
  import { deviceFetch } from '../relay/device-http.js';
49
51
  import { ImageBlockRewriter } from '../relay/media-upload.js';
50
- import { getConfig } from '../config.js';
52
+ import { getConfig, captureEnabled } from '../config.js';
51
53
  import { AGENT_ADAPTERS } from '../agents/index.js';
52
54
  const CAPTURE_DIR = join(homedir(), '.gipity', 'capture-state');
53
55
  const INGEST_BATCH_MAX = 100; // server caps at 200; stay comfortably under
@@ -273,7 +275,7 @@ export async function resolveConvGuid(hook, serverSource = 'claude_code', sleep
273
275
  // (main() already checked the device, but resolveConvGuid is also the
274
276
  // unit-tested entry - keep it self-sufficient).
275
277
  const config = getConfig();
276
- if (!config?.projectGuid || config.captureHooks === false)
278
+ if (!config?.projectGuid || !captureEnabled(config))
277
279
  return null;
278
280
  if (!getDevice())
279
281
  return null;