gipity 1.1.6 → 1.1.9
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/agents/agy.js +31 -0
- package/dist/agents/claude-code.js +21 -0
- package/dist/agents/codex.js +21 -0
- package/dist/agents/grok.js +38 -0
- package/dist/agents/types.js +6 -17
- package/dist/capture/sources/agy.js +77 -13
- package/dist/catalog.js +2 -2
- package/dist/client-context.js +17 -21
- package/dist/commands/add.js +49 -8
- package/dist/commands/brand.js +5 -1
- package/dist/commands/build.js +26 -12
- package/dist/commands/db.js +66 -0
- package/dist/commands/email.js +12 -8
- package/dist/commands/file.js +5 -1
- package/dist/commands/generate.js +25 -30
- package/dist/commands/init.js +3 -2
- package/dist/commands/page-eval.js +39 -3
- package/dist/commands/page-screenshot.js +34 -6
- package/dist/commands/records.js +38 -6
- package/dist/commands/service.js +71 -7
- package/dist/commands/skill.js +158 -24
- package/dist/commands/uninstall.js +14 -72
- package/dist/commands/upload.js +8 -11
- package/dist/commands/workflow.js +59 -6
- package/dist/db-checkpoint.js +42 -0
- package/dist/hooks/capture-runner.js +35 -50
- package/dist/index.js +2606 -1562
- package/dist/knowledge.js +2 -2
- package/dist/provider-docs.js +1 -1
- package/dist/relay/diagnostics.js +13 -11
- package/dist/relay/onboarding.js +3 -3
- package/dist/setup.js +83 -2
- package/dist/utils.js +36 -12
- package/package.json +2 -2
package/dist/commands/skill.js
CHANGED
|
@@ -16,6 +16,105 @@ function readInstalledKitReadme(name) {
|
|
|
16
16
|
const readme = join(kitDir, 'README.md');
|
|
17
17
|
return existsSync(readme) ? readFileSync(readme, 'utf-8') : null;
|
|
18
18
|
}
|
|
19
|
+
function slugify(title) {
|
|
20
|
+
return title.toLowerCase().replace(/[`*_]/g, '').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
21
|
+
}
|
|
22
|
+
/** Markdown headings, skipping anything inside a fenced code block (shell
|
|
23
|
+
* comments in examples start with `#` too). A section runs until the next
|
|
24
|
+
* heading at the same or a shallower level, so it carries its subsections. */
|
|
25
|
+
function parseSections(lines) {
|
|
26
|
+
const out = [];
|
|
27
|
+
let fenced = false;
|
|
28
|
+
lines.forEach((line, i) => {
|
|
29
|
+
if (/^\s*(```|~~~)/.test(line)) {
|
|
30
|
+
fenced = !fenced;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (fenced)
|
|
34
|
+
return;
|
|
35
|
+
const m = /^(#{1,6})\s+(.*\S)\s*$/.exec(line);
|
|
36
|
+
if (!m)
|
|
37
|
+
return;
|
|
38
|
+
out.push({ level: m[1].length, title: m[2], slug: slugify(m[2]), start: i + 1, end: lines.length });
|
|
39
|
+
});
|
|
40
|
+
out.forEach((s, i) => {
|
|
41
|
+
const next = out.find((o, j) => j > i && o.level <= s.level);
|
|
42
|
+
if (next)
|
|
43
|
+
s.end = next.start - 1;
|
|
44
|
+
});
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/** The heading level worth listing in the one-line map: the shallowest level
|
|
48
|
+
* with more than one heading (docs open with a single `# Title`, so that lone
|
|
49
|
+
* H1 is never the useful outline), else the shallowest level present. */
|
|
50
|
+
function outlineLevel(sections) {
|
|
51
|
+
const levels = [...new Set(sections.map(s => s.level))].sort((a, b) => a - b);
|
|
52
|
+
return levels.find(l => sections.filter(s => s.level === l).length > 1) ?? levels[0];
|
|
53
|
+
}
|
|
54
|
+
function sectionText(lines, s) {
|
|
55
|
+
return lines.slice(s.start - 1, s.end).join('\n').replace(/\s+$/, '');
|
|
56
|
+
}
|
|
57
|
+
const MAX_MAPPED_SECTIONS = 12;
|
|
58
|
+
/** One line above every read: how long the doc is and what is in it, with the
|
|
59
|
+
* flag for pulling one part inline. Printed to stdout so it survives an
|
|
60
|
+
* agent's `| head -N`. */
|
|
61
|
+
function mapLine(name, lines, sections) {
|
|
62
|
+
const head = `${bold(name)} ${muted(`· ${lines.length} lines`)}`;
|
|
63
|
+
if (sections.length === 0)
|
|
64
|
+
return head;
|
|
65
|
+
const shown = sections.filter(s => s.level === outlineLevel(sections));
|
|
66
|
+
const names = shown.slice(0, MAX_MAPPED_SECTIONS).map(s => s.slug).join(', ');
|
|
67
|
+
const more = shown.length > MAX_MAPPED_SECTIONS ? `, +${shown.length - MAX_MAPPED_SECTIONS} more (--toc)` : '';
|
|
68
|
+
return `${head} ${muted(`· sections (--section <slug>): ${names}${more}`)}`;
|
|
69
|
+
}
|
|
70
|
+
function tocText(sections) {
|
|
71
|
+
return sections
|
|
72
|
+
.map(s => `${String(s.start).padStart(5)} ${' '.repeat(s.level - 1)}${s.slug}${muted(` - ${s.title}`)}`)
|
|
73
|
+
.join('\n');
|
|
74
|
+
}
|
|
75
|
+
/** Apply --toc / --section / --grep to a doc. Returns the text to print, or
|
|
76
|
+
* null when the filter matched nothing (caller reports it and exits 1). */
|
|
77
|
+
function filterContent(content, sections, opts) {
|
|
78
|
+
const lines = content.split('\n');
|
|
79
|
+
if (opts.toc)
|
|
80
|
+
return tocText(sections);
|
|
81
|
+
let hits = [];
|
|
82
|
+
if (opts.section) {
|
|
83
|
+
const want = slugify(opts.section);
|
|
84
|
+
hits = sections.filter(s => s.slug === want);
|
|
85
|
+
if (hits.length === 0)
|
|
86
|
+
hits = sections.filter(s => s.slug.includes(want));
|
|
87
|
+
}
|
|
88
|
+
else if (opts.grep) {
|
|
89
|
+
let re;
|
|
90
|
+
try {
|
|
91
|
+
re = new RegExp(opts.grep, 'i');
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
throw new Error(`--grep "${opts.grep}" is not a valid regex.`);
|
|
95
|
+
}
|
|
96
|
+
// Deepest matching section per hit: the smallest chunk that still answers
|
|
97
|
+
// the question, rather than the whole chapter it sits in.
|
|
98
|
+
const matched = new Set();
|
|
99
|
+
lines.forEach((line, i) => {
|
|
100
|
+
if (!re.test(line))
|
|
101
|
+
return;
|
|
102
|
+
const owning = sections.filter(s => s.start <= i + 1 && i + 1 <= s.end);
|
|
103
|
+
const deepest = owning[owning.length - 1];
|
|
104
|
+
if (deepest)
|
|
105
|
+
matched.add(deepest);
|
|
106
|
+
});
|
|
107
|
+
hits = sections.filter(s => matched.has(s));
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
return content;
|
|
111
|
+
}
|
|
112
|
+
if (hits.length === 0)
|
|
113
|
+
return null;
|
|
114
|
+
// Drop sections already contained in an outer hit so nothing prints twice.
|
|
115
|
+
const outer = hits.filter(s => !hits.some(o => o !== s && o.start <= s.start && s.end <= o.end));
|
|
116
|
+
return outer.map(s => sectionText(lines, s)).join('\n\n');
|
|
117
|
+
}
|
|
19
118
|
export const skillCommand = new Command('skill')
|
|
20
119
|
.description('Task docs - read the matching skill before building');
|
|
21
120
|
skillCommand
|
|
@@ -30,43 +129,78 @@ skillCommand
|
|
|
30
129
|
}
|
|
31
130
|
const res = await get(`/skills?agent=${config.agentGuid}`);
|
|
32
131
|
const width = res.data.reduce((m, s) => Math.max(m, s.name.length), 0);
|
|
33
|
-
printList(res.data, opts, 'No skills available.', s => ` ${bold(s.name.padEnd(width))} ${muted(s.description)}`, 'Read
|
|
132
|
+
printList(res.data, opts, 'No skills available.', s => ` ${bold(s.name.padEnd(width))} ${muted(s.description)}`, 'Read with `gipity skill read <name> [<name>...]` (one turn, many docs; `--toc`, `--section <slug>` or `--grep <term>` for one part):');
|
|
34
133
|
}));
|
|
35
134
|
skillCommand
|
|
36
|
-
.command('read <
|
|
37
|
-
.description('Read
|
|
135
|
+
.command('read <names...>')
|
|
136
|
+
.description('Read one or more skills (whole doc, or one part with --toc/--section/--grep)')
|
|
137
|
+
.option('--toc', 'Print the doc outline (section slugs + line numbers) instead of the content')
|
|
138
|
+
.option('--section <slug>', 'Print only this section (slug or heading text; subsections included)')
|
|
139
|
+
.option('--grep <term>', 'Print only the sections matching this term (case-insensitive regex)')
|
|
38
140
|
.option('--json', 'Output as JSON')
|
|
39
|
-
.action((
|
|
141
|
+
.action((names, opts) => run('Read', async () => {
|
|
40
142
|
const { config } = await resolveProjectContext();
|
|
41
143
|
if (!config.agentGuid) {
|
|
42
144
|
console.error(clrError('No agent configured for this project. Run `gipity init` to refresh.'));
|
|
43
145
|
process.exit(1);
|
|
44
146
|
}
|
|
45
147
|
const listRes = await get(`/skills?agent=${config.agentGuid}`);
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
148
|
+
const jsonDocs = [];
|
|
149
|
+
let failed = false;
|
|
150
|
+
let printed = 0;
|
|
151
|
+
for (const name of names) {
|
|
152
|
+
const match = listRes.data.find(s => s.name.toLowerCase() === name.toLowerCase());
|
|
153
|
+
let content;
|
|
154
|
+
let detail;
|
|
155
|
+
let note = null;
|
|
156
|
+
if (match) {
|
|
157
|
+
const res = await get(`/skills/${match.guid}?agent=${config.agentGuid}`);
|
|
158
|
+
content = res.data.content;
|
|
159
|
+
detail = { ...res.data };
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
// No catalog skill — but if a kit by this name is installed, its README is
|
|
163
|
+
// the guidance the agent is after. Surface it instead of dead-ending.
|
|
164
|
+
const readme = readInstalledKitReadme(name);
|
|
165
|
+
if (!readme) {
|
|
166
|
+
console.error(clrError(`Skill "${name}" not found. Run: gipity skill list`));
|
|
167
|
+
failed = true;
|
|
168
|
+
continue;
|
|
58
169
|
}
|
|
59
|
-
|
|
170
|
+
content = readme;
|
|
171
|
+
detail = { name, source: 'kit-readme' };
|
|
172
|
+
note = muted(`No skill doc for "${name}"; showing the installed kit's README (src/packages/${name}/README.md):`);
|
|
60
173
|
}
|
|
61
|
-
|
|
62
|
-
|
|
174
|
+
const lines = content.split('\n');
|
|
175
|
+
const sections = parseSections(lines);
|
|
176
|
+
const filtered = filterContent(content, sections, opts);
|
|
177
|
+
if (filtered === null) {
|
|
178
|
+
const what = opts.section ? `section "${opts.section}"` : `match for "${opts.grep}"`;
|
|
179
|
+
console.error(clrError(`No ${what} in "${name}". Sections: ${sections.map(s => s.slug).join(', ') || '(none)'}`));
|
|
180
|
+
failed = true;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (opts.json) {
|
|
184
|
+
jsonDocs.push({
|
|
185
|
+
...detail,
|
|
186
|
+
content: filtered,
|
|
187
|
+
lines: lines.length,
|
|
188
|
+
sections: sections.map(s => ({ slug: s.slug, title: s.title, level: s.level, line: s.start })),
|
|
189
|
+
});
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (printed > 0)
|
|
193
|
+
console.log(''); // blank line between docs in a multi-name read
|
|
194
|
+
if (note)
|
|
195
|
+
console.log(note);
|
|
196
|
+
console.log(mapLine(name, lines, sections));
|
|
197
|
+
console.log(filtered);
|
|
198
|
+
printed++;
|
|
63
199
|
}
|
|
64
|
-
const res = await get(`/skills/${match.guid}?agent=${config.agentGuid}`);
|
|
65
200
|
if (opts.json) {
|
|
66
|
-
console.log(JSON.stringify(
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
console.log(res.data.content);
|
|
201
|
+
console.log(JSON.stringify(names.length === 1 ? jsonDocs[0] ?? null : jsonDocs, null, 2));
|
|
70
202
|
}
|
|
203
|
+
if (failed)
|
|
204
|
+
process.exit(1);
|
|
71
205
|
}));
|
|
72
206
|
//# sourceMappingURL=skill.js.map
|
|
@@ -12,46 +12,14 @@ import { Command } from 'commander';
|
|
|
12
12
|
import { existsSync, rmSync, unlinkSync, readFileSync, writeFileSync } from 'fs';
|
|
13
13
|
import { homedir, platform as osPlatform } from 'os';
|
|
14
14
|
import { join, resolve } from 'path';
|
|
15
|
-
import { spawnSyncCommand
|
|
15
|
+
import { spawnSyncCommand } from '../platform.js';
|
|
16
16
|
import { post } from '../api.js';
|
|
17
17
|
import { getAuth } from '../auth.js';
|
|
18
18
|
import { confirm, getAutoConfirm } from '../utils.js';
|
|
19
19
|
import { bold, brand, dim, success, error as clrError, muted } from '../colors.js';
|
|
20
20
|
import * as relayState from '../relay/state.js';
|
|
21
21
|
import { planFor, UnsupportedPlatformError } from '../relay/installers.js';
|
|
22
|
-
import {
|
|
23
|
-
/** Remove Gipity's entries from the user-scope Claude Code settings: the
|
|
24
|
-
* plugin enablement, the marketplace registration, and any legacy hook
|
|
25
|
-
* blocks older CLI versions wrote there. Surgical - everything else in the
|
|
26
|
-
* file (the user's own permissions, hooks, other plugins) is untouched. */
|
|
27
|
-
function removeGipityPluginConfig() {
|
|
28
|
-
const settingsPath = join(homedir(), '.claude', 'settings.json');
|
|
29
|
-
if (!existsSync(settingsPath))
|
|
30
|
-
return false;
|
|
31
|
-
let settings;
|
|
32
|
-
try {
|
|
33
|
-
settings = JSON.parse(readFileSync(settingsPath, 'utf-8'));
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
let changed = stripGipityHooks(settings);
|
|
39
|
-
if (settings.enabledPlugins && GIPITY_PLUGIN_ID in settings.enabledPlugins) {
|
|
40
|
-
delete settings.enabledPlugins[GIPITY_PLUGIN_ID];
|
|
41
|
-
if (Object.keys(settings.enabledPlugins).length === 0)
|
|
42
|
-
delete settings.enabledPlugins;
|
|
43
|
-
changed = true;
|
|
44
|
-
}
|
|
45
|
-
if (settings.extraKnownMarketplaces?.[GIPITY_MARKETPLACE_NAME]) {
|
|
46
|
-
delete settings.extraKnownMarketplaces[GIPITY_MARKETPLACE_NAME];
|
|
47
|
-
if (Object.keys(settings.extraKnownMarketplaces).length === 0)
|
|
48
|
-
delete settings.extraKnownMarketplaces;
|
|
49
|
-
changed = true;
|
|
50
|
-
}
|
|
51
|
-
if (changed)
|
|
52
|
-
writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
|
|
53
|
-
return changed;
|
|
54
|
-
}
|
|
22
|
+
import { AGENT_ADAPTERS } from '../agents/index.js';
|
|
55
23
|
/** The install.sh / install.ps1 launcher appends a line to the user's shell rc
|
|
56
24
|
* files putting ~/.gipity/launcher/bin on PATH. Once ~/.gipity is deleted that
|
|
57
25
|
* line points at nothing, so strip it back out - matched by the installer's own
|
|
@@ -212,46 +180,20 @@ export const uninstallCommand = new Command('uninstall')
|
|
|
212
180
|
// 3. Revoke device on server.
|
|
213
181
|
await revokeDeviceBestEffort();
|
|
214
182
|
console.log(`${success('Device revoked on server (or was already revoked).')}`);
|
|
215
|
-
// 4. Remove
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (grokInstallState().exists) {
|
|
226
|
-
spawnSyncCommand(resolveCommand('grok'), ['plugin', 'uninstall', 'gipity', '--confirm'], {
|
|
227
|
-
stdio: 'ignore',
|
|
228
|
-
timeout: 60_000,
|
|
229
|
-
});
|
|
230
|
-
console.log(`${success('Gipity plugin removed from Grok.')}`);
|
|
231
|
-
}
|
|
232
|
-
const agentSkills = agentSkillsState();
|
|
233
|
-
if (agentSkills.skills.length) {
|
|
234
|
-
for (const name of agentSkills.skills) {
|
|
235
|
-
// Only names our manifest recorded - never someone else's skills.
|
|
236
|
-
try {
|
|
237
|
-
rmSync(join(AGENTS_SKILLS_DIR, name), { recursive: true, force: true });
|
|
238
|
-
}
|
|
239
|
-
catch { /* best-effort */ }
|
|
183
|
+
// 4. Remove each detected agent's Gipity integration: the Claude Code
|
|
184
|
+
// plugin enablement + legacy hook blocks, the Grok plugin, and the
|
|
185
|
+
// skills the CLI copied into Codex's/Antigravity's skill roots. Every
|
|
186
|
+
// step is best-effort - none existing is the common case.
|
|
187
|
+
let anyAgentIntegration = false;
|
|
188
|
+
for (const agent of AGENT_ADAPTERS) {
|
|
189
|
+
const note = agent.setup?.uninstall();
|
|
190
|
+
if (note) {
|
|
191
|
+
console.log(`${success(note)}`);
|
|
192
|
+
anyAgentIntegration = true;
|
|
240
193
|
}
|
|
241
|
-
console.log(`${success(`Removed ${agentSkills.skills.length} Gipity skills from ~/.agents/skills.`)}`);
|
|
242
194
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
// Codex's ~/.agents/skills, see setup.ts).
|
|
246
|
-
const agySkills = agySkillsState();
|
|
247
|
-
if (agySkills.skills.length) {
|
|
248
|
-
for (const name of agySkills.skills) {
|
|
249
|
-
try {
|
|
250
|
-
rmSync(join(AGY_SKILLS_DIR, name), { recursive: true, force: true });
|
|
251
|
-
}
|
|
252
|
-
catch { /* best-effort */ }
|
|
253
|
-
}
|
|
254
|
-
console.log(`${success(`Removed ${agySkills.skills.length} Gipity skills from ~/.gemini/config/skills.`)}`);
|
|
195
|
+
if (!anyAgentIntegration) {
|
|
196
|
+
console.log(`${muted('No Gipity entries in any detected coding agent.')}`);
|
|
255
197
|
}
|
|
256
198
|
// 5. Wipe ~/.gipity/ (this also removes the agent-hooks scripts and the
|
|
257
199
|
// agent-skills manifest, which live under it).
|
package/dist/commands/upload.js
CHANGED
|
@@ -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(
|
|
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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
1
|
+
import { Command, Option } from 'commander';
|
|
2
2
|
import { get, post, put, del } from '../api.js';
|
|
3
3
|
import { getConfig, requireConfig } from '../config.js';
|
|
4
4
|
import { success, error as clrError, muted, bold } from '../colors.js';
|
|
@@ -29,6 +29,51 @@ function formatRunLine(r) {
|
|
|
29
29
|
const statusColor = r.status === 'completed' ? success : r.status === 'failed' ? clrError : muted;
|
|
30
30
|
return `${muted(r.short_guid)} ${statusColor(r.status)} ${dur} ${runTokens(r)} tokens ${muted(fmtTime(r.started_at))}`;
|
|
31
31
|
}
|
|
32
|
+
/** Classify a step-output value that is a *string* holding JSON: parsed, or
|
|
33
|
+
* looks-like-JSON-but-doesn't-parse (a truncated / cut-off llm response — the
|
|
34
|
+
* step reports `completed` and the next step then can't read a field out of
|
|
35
|
+
* it). `null` means "not a JSON string at all". */
|
|
36
|
+
function jsonStringInfo(v) {
|
|
37
|
+
if (typeof v !== 'string')
|
|
38
|
+
return null;
|
|
39
|
+
const t = v.trim();
|
|
40
|
+
if (!t.startsWith('{') && !t.startsWith('['))
|
|
41
|
+
return null;
|
|
42
|
+
try {
|
|
43
|
+
const parsed = JSON.parse(t);
|
|
44
|
+
return typeof parsed === 'object' && parsed !== null ? { ok: true, value: parsed } : null;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return { ok: false };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function labelFor(info) {
|
|
51
|
+
return info.ok ? '(JSON string)' : clrError('(truncated/invalid JSON string)');
|
|
52
|
+
}
|
|
53
|
+
/** Render one step's output for humans.
|
|
54
|
+
*
|
|
55
|
+
* Step outputs routinely carry a JSON *string* under a key — an `llm` step's
|
|
56
|
+
* `result` is the common case. Dumped through a plain JSON.stringify that
|
|
57
|
+
* arrives as one enormous backslash-escaped line: unreadable, and it hides the
|
|
58
|
+
* single fact you need most, that the NEXT step sees a string, not an object
|
|
59
|
+
* (so `{{step.summary}}` resolves to nothing). Label such keys
|
|
60
|
+
* `"key" (JSON string)` and print the decoded value indented under it, so both
|
|
61
|
+
* the content and the string-vs-object handoff are obvious at a glance. */
|
|
62
|
+
function renderStepOutput(output) {
|
|
63
|
+
if (output && typeof output === 'object' && !Array.isArray(output)) {
|
|
64
|
+
return Object.entries(output).map(([k, v]) => {
|
|
65
|
+
const info = jsonStringInfo(v);
|
|
66
|
+
if (!info)
|
|
67
|
+
return `${JSON.stringify(k)}: ${JSON.stringify(v, null, 2)}`;
|
|
68
|
+
const body = info.ok ? JSON.stringify(info.value, null, 2) : JSON.stringify(v);
|
|
69
|
+
return `${JSON.stringify(k)} ${labelFor(info)}: ${body}`;
|
|
70
|
+
}).join('\n');
|
|
71
|
+
}
|
|
72
|
+
const info = jsonStringInfo(output);
|
|
73
|
+
if (info?.ok)
|
|
74
|
+
return JSON.stringify(info.value, null, 2);
|
|
75
|
+
return JSON.stringify(output, null, 2);
|
|
76
|
+
}
|
|
32
77
|
/** Print each step's status, tokens, model, error and output. A run line alone
|
|
33
78
|
* says a run finished, not what it did — without the steps you can't tell a
|
|
34
79
|
* workflow that wrote a row from one that silently skipped every step. */
|
|
@@ -46,7 +91,7 @@ function printStepRuns(steps, emptyNote) {
|
|
|
46
91
|
if (s.error_message)
|
|
47
92
|
console.log(` ${clrError(s.error_message)}`);
|
|
48
93
|
if (s.output_json !== null && s.output_json !== undefined) {
|
|
49
|
-
console.log(
|
|
94
|
+
console.log(renderStepOutput(s.output_json).split('\n').map(l => ` ${l}`).join('\n'));
|
|
50
95
|
}
|
|
51
96
|
}
|
|
52
97
|
}
|
|
@@ -149,10 +194,18 @@ workflowCommand
|
|
|
149
194
|
}));
|
|
150
195
|
workflowCommand
|
|
151
196
|
.command('run <name>')
|
|
152
|
-
.description(
|
|
197
|
+
.description("Run a workflow: waits for it to finish and prints each step's status and output (--no-wait to fire and forget)")
|
|
153
198
|
.option('--json', 'Output as JSON')
|
|
154
|
-
|
|
155
|
-
|
|
199
|
+
// Waiting is the default: a bare trigger tells you nothing about what the
|
|
200
|
+
// workflow did, so every caller followed it with a poll-and-drill-in loop.
|
|
201
|
+
// `--no-wait` is the escape hatch for fire-and-forget.
|
|
202
|
+
.option('--no-wait', 'Trigger and return immediately instead of waiting for the run')
|
|
203
|
+
// Waiting is already the default, but `--wait` reads naturally and older
|
|
204
|
+
// docs/muscle memory reach for it — accept it silently rather than erroring.
|
|
205
|
+
.addOption(new Option('--wait', 'Wait for the run (already the default)').hideHelp())
|
|
206
|
+
// LLM steps routinely take a couple of minutes; a 120s default timed out on
|
|
207
|
+
// healthy runs and taught callers to always pass --timeout.
|
|
208
|
+
.option('--timeout <s>', 'Max seconds to wait for the run to finish', '300')
|
|
156
209
|
.action((name, _opts, cmd) => run('Run', async () => {
|
|
157
210
|
const opts = mergedOpts(cmd);
|
|
158
211
|
const wf = await resolveWorkflow(name);
|
|
@@ -168,7 +221,7 @@ workflowCommand
|
|
|
168
221
|
const before = await get(`/workflows/${wf.short_guid}/runs?limit=1`);
|
|
169
222
|
const prevGuid = before.data[0]?.short_guid;
|
|
170
223
|
await post(`/workflows/${wf.short_guid}/run`, {});
|
|
171
|
-
const r = await waitForRun(wf.short_guid, prevGuid, Number(opts.timeout) ||
|
|
224
|
+
const r = await waitForRun(wf.short_guid, prevGuid, Number(opts.timeout) || 300);
|
|
172
225
|
if (opts.json) {
|
|
173
226
|
console.log(JSON.stringify(r));
|
|
174
227
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database checkpoint / restore — the undo for a LIVE write test.
|
|
3
|
+
*
|
|
4
|
+
* Verifying a write path for real (clicking Approve in the deployed UI, calling
|
|
5
|
+
* a function that inserts, letting a scheduled workflow run) mutates the
|
|
6
|
+
* project's real data, and there was no way to put it back - agents ended up
|
|
7
|
+
* hand-writing SQL to scrub their own test strings out.
|
|
8
|
+
*
|
|
9
|
+
* The snapshot itself is the SERVER's job: it lives in a sibling schema the app
|
|
10
|
+
* can't see, and restore runs in one transaction. This module is just the
|
|
11
|
+
* client - the CLI never composes checkpoint DDL, so a snapshot can never show
|
|
12
|
+
* up in `db query`, in a migration diff, or in app code that enumerates tables.
|
|
13
|
+
*/
|
|
14
|
+
import { get, post } from './api.js';
|
|
15
|
+
/** First database in the project, or null when the project has none. */
|
|
16
|
+
export async function resolveDatabase(projectGuid, explicit) {
|
|
17
|
+
if (explicit)
|
|
18
|
+
return explicit;
|
|
19
|
+
const res = await get(`/projects/${projectGuid}/databases`);
|
|
20
|
+
return res.data.length > 0 ? res.data[0].friendlyName : null;
|
|
21
|
+
}
|
|
22
|
+
async function checkpoint(projectGuid, database, action, keep) {
|
|
23
|
+
const res = await post(`/projects/${projectGuid}/db/checkpoint`, { database, action, ...(keep ? { keep } : {}) });
|
|
24
|
+
return res.data;
|
|
25
|
+
}
|
|
26
|
+
/** Snapshot every app table. Replaces any previous checkpoint. */
|
|
27
|
+
export function createCheckpoint(projectGuid, database) {
|
|
28
|
+
return checkpoint(projectGuid, database, 'create');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Put every checkpointed table back to its snapshot contents and drop the
|
|
32
|
+
* snapshot (unless `keep`). Sequences are deliberately NOT rewound - leaving
|
|
33
|
+
* them ahead keeps ids unique against anything the test run handed out.
|
|
34
|
+
*/
|
|
35
|
+
export function restoreCheckpoint(projectGuid, database, opts = {}) {
|
|
36
|
+
return checkpoint(projectGuid, database, 'restore', opts.keep);
|
|
37
|
+
}
|
|
38
|
+
/** Drop the checkpoint without restoring (keep whatever the run wrote). */
|
|
39
|
+
export function dropCheckpoint(projectGuid, database) {
|
|
40
|
+
return checkpoint(projectGuid, database, 'drop');
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=db-checkpoint.js.map
|
|
@@ -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 {
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
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
|
|
372
|
-
if (
|
|
373
|
-
|
|
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 =
|
|
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.
|
|
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
|
-
|
|
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;
|