runwork 0.11.0 → 0.13.1
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/__tests__/intro-skill.test.js +32 -0
- package/dist/agents/claude-code.d.ts +21 -0
- package/dist/agents/claude-code.js +58 -2
- package/dist/agents/claude-desktop-plugin-tree.d.ts +15 -0
- package/dist/agents/claude-desktop-plugin-tree.js +37 -1
- package/dist/agents/conversation-skills.d.ts +18 -0
- package/dist/agents/conversation-skills.js +229 -0
- package/dist/agents/intro-skill.d.ts +9 -0
- package/dist/agents/intro-skill.js +41 -0
- package/dist/agents/registry-data.d.ts +35 -0
- package/dist/agents/registry-data.js +58 -1
- package/dist/agents/runtime-detection.d.ts +82 -0
- package/dist/agents/runtime-detection.js +271 -0
- package/dist/agents/session-start-hook.d.ts +37 -0
- package/dist/agents/session-start-hook.js +159 -0
- package/dist/agents/types.d.ts +12 -0
- package/dist/api/client.d.ts +47 -0
- package/dist/api/client.js +32 -0
- package/dist/commands/__tests__/setup-persona.test.d.ts +1 -0
- package/dist/commands/__tests__/setup-persona.test.js +31 -0
- package/dist/commands/doctor.js +89 -2
- package/dist/commands/inbox.d.ts +11 -0
- package/dist/commands/inbox.js +60 -0
- package/dist/commands/info.d.ts +1 -1
- package/dist/commands/info.js +7 -2
- package/dist/commands/resume.d.ts +2 -0
- package/dist/commands/resume.js +265 -0
- package/dist/commands/save-convo.d.ts +8 -0
- package/dist/commands/save-convo.js +20 -0
- package/dist/commands/setup.d.ts +7 -0
- package/dist/commands/setup.js +22 -0
- package/dist/commands/share-convo.d.ts +24 -0
- package/dist/commands/share-convo.js +167 -0
- package/dist/commands/sync.js +96 -10
- package/dist/generated/bundled-types.js +33 -33
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/index.js +8 -0
- package/dist/types.d.ts +13 -0
- package/dist/utils/app-info.d.ts +4 -0
- package/dist/utils/app-info.js +17 -0
- package/package.json +1 -1
package/dist/agents/types.d.ts
CHANGED
|
@@ -33,6 +33,18 @@ export interface AgentAdapter {
|
|
|
33
33
|
mcpProvidesSkills?: boolean;
|
|
34
34
|
/** Write team-managed instructions (separate marker block from auto-generated hint) */
|
|
35
35
|
writeTeamInstructions?(instructions: string, scope: 'project' | 'user'): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Install the runwork SessionStart hook (or any equivalent platform-managed
|
|
38
|
+
* hook) into the agent's hook directory. Called once per (adapter, scope) by
|
|
39
|
+
* the main sync loop, AFTER writeSkills has fully populated the plugin tree.
|
|
40
|
+
* Separate from writeSkills because writeSkills is also invoked per-skill by
|
|
41
|
+
* the diff executor during push/pull, and hook installation must not be
|
|
42
|
+
* repeated for every skill.
|
|
43
|
+
*
|
|
44
|
+
* Optional - only adapters with a hook system implement it (Claude Code,
|
|
45
|
+
* eventually Claude Desktop Cowork plugin tree).
|
|
46
|
+
*/
|
|
47
|
+
writeBuiltInHooks?(scope: 'project' | 'user'): Promise<void>;
|
|
36
48
|
/**
|
|
37
49
|
* Write agent-specific config overrides from workspace admin (model, permissions).
|
|
38
50
|
*
|
package/dist/api/client.d.ts
CHANGED
|
@@ -266,6 +266,53 @@ export declare class ApiClient {
|
|
|
266
266
|
metadata?: Record<string, unknown>;
|
|
267
267
|
timestamp: string;
|
|
268
268
|
}>): Promise<void>;
|
|
269
|
+
createSharedConversation(workspaceId: string, body: {
|
|
270
|
+
recipients?: string[];
|
|
271
|
+
isPersonal?: boolean;
|
|
272
|
+
sourceAgent: string;
|
|
273
|
+
title: string;
|
|
274
|
+
note?: string;
|
|
275
|
+
bundles: Array<{
|
|
276
|
+
format: string;
|
|
277
|
+
content: string;
|
|
278
|
+
sizeBytes: number;
|
|
279
|
+
sha256: string;
|
|
280
|
+
}>;
|
|
281
|
+
metadata?: Record<string, unknown>;
|
|
282
|
+
ttlDays?: number;
|
|
283
|
+
}): Promise<{
|
|
284
|
+
share: {
|
|
285
|
+
id: string;
|
|
286
|
+
title: string;
|
|
287
|
+
expiresAt: string;
|
|
288
|
+
};
|
|
289
|
+
sharedCount: number;
|
|
290
|
+
invitedCount: number;
|
|
291
|
+
skipped: Array<{
|
|
292
|
+
identifier: string;
|
|
293
|
+
reason: string;
|
|
294
|
+
}>;
|
|
295
|
+
}>;
|
|
296
|
+
listSharedConversations(workspaceId: string, opts?: {
|
|
297
|
+
scope?: 'all' | 'received' | 'sent' | 'saved';
|
|
298
|
+
limit?: number;
|
|
299
|
+
offset?: number;
|
|
300
|
+
}): Promise<{
|
|
301
|
+
shares: Array<Record<string, unknown>>;
|
|
302
|
+
total: number;
|
|
303
|
+
}>;
|
|
304
|
+
getSharedConversation(workspaceId: string, shareId: string): Promise<{
|
|
305
|
+
share: Record<string, unknown>;
|
|
306
|
+
}>;
|
|
307
|
+
downloadSharedConversationBundle(workspaceId: string, shareId: string, format: string): Promise<{
|
|
308
|
+
format: string;
|
|
309
|
+
content: string;
|
|
310
|
+
sizeBytes: number;
|
|
311
|
+
sha256: string;
|
|
312
|
+
}>;
|
|
313
|
+
markSharedConversationResumed(workspaceId: string, shareId: string): Promise<{
|
|
314
|
+
success: boolean;
|
|
315
|
+
}>;
|
|
269
316
|
callIntegrationProxy(integrationDbId: string, method: string, path: string, opts?: {
|
|
270
317
|
body?: unknown;
|
|
271
318
|
headers?: Record<string, string>;
|
package/dist/api/client.js
CHANGED
|
@@ -355,6 +355,38 @@ export class ApiClient {
|
|
|
355
355
|
async reportTelemetry(workspaceId, events) {
|
|
356
356
|
await this.request(`/api/workspaces/${workspaceId}/team/telemetry`, { method: 'POST', body: JSON.stringify({ events }) });
|
|
357
357
|
}
|
|
358
|
+
// --- Shared Conversations ---
|
|
359
|
+
async createSharedConversation(workspaceId, body) {
|
|
360
|
+
const res = await this.request(`/api/workspaces/${workspaceId}/shared-conversations`, {
|
|
361
|
+
method: 'POST',
|
|
362
|
+
body: JSON.stringify(body),
|
|
363
|
+
});
|
|
364
|
+
return res.data;
|
|
365
|
+
}
|
|
366
|
+
async listSharedConversations(workspaceId, opts) {
|
|
367
|
+
const search = new URLSearchParams();
|
|
368
|
+
if (opts?.scope)
|
|
369
|
+
search.set('scope', opts.scope);
|
|
370
|
+
if (opts?.limit !== undefined)
|
|
371
|
+
search.set('limit', String(opts.limit));
|
|
372
|
+
if (opts?.offset !== undefined)
|
|
373
|
+
search.set('offset', String(opts.offset));
|
|
374
|
+
const query = search.toString() ? `?${search.toString()}` : '';
|
|
375
|
+
const res = await this.request(`/api/workspaces/${workspaceId}/shared-conversations${query}`);
|
|
376
|
+
return res.data;
|
|
377
|
+
}
|
|
378
|
+
async getSharedConversation(workspaceId, shareId) {
|
|
379
|
+
const res = await this.request(`/api/workspaces/${workspaceId}/shared-conversations/${shareId}`);
|
|
380
|
+
return res.data;
|
|
381
|
+
}
|
|
382
|
+
async downloadSharedConversationBundle(workspaceId, shareId, format) {
|
|
383
|
+
const res = await this.request(`/api/workspaces/${workspaceId}/shared-conversations/${shareId}/bundle/${encodeURIComponent(format)}`);
|
|
384
|
+
return res.data;
|
|
385
|
+
}
|
|
386
|
+
async markSharedConversationResumed(workspaceId, shareId) {
|
|
387
|
+
const res = await this.request(`/api/workspaces/${workspaceId}/shared-conversations/${shareId}/resumed`, { method: 'POST' });
|
|
388
|
+
return res.data;
|
|
389
|
+
}
|
|
358
390
|
// --- Integrations: Proxy Call ---
|
|
359
391
|
async callIntegrationProxy(integrationDbId, method, path, opts) {
|
|
360
392
|
const targetPath = opts?.query ? `${path}?${opts.query}` : path;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { resolvePersona } from '../setup.js';
|
|
3
|
+
/**
|
|
4
|
+
* resolvePersona decides what persona ends up in setup.json. The `--persona`
|
|
5
|
+
* flag (set by the desktop onboarding flow) wins; otherwise an existing persona
|
|
6
|
+
* on disk is preserved so a manual `runwork setup` re-run does not wipe it.
|
|
7
|
+
*/
|
|
8
|
+
describe('resolvePersona', () => {
|
|
9
|
+
it('maps a valid --persona flag to level and label', () => {
|
|
10
|
+
expect(resolvePersona('1', undefined)).toEqual({ level: 1, label: 'novice' });
|
|
11
|
+
expect(resolvePersona('2', undefined)).toEqual({ level: 2, label: 'curious' });
|
|
12
|
+
expect(resolvePersona('3', undefined)).toEqual({ level: 3, label: 'engineer' });
|
|
13
|
+
});
|
|
14
|
+
it('preserves the existing persona when no flag is given', () => {
|
|
15
|
+
const existing = { level: 2, label: 'curious' };
|
|
16
|
+
expect(resolvePersona(undefined, existing)).toEqual(existing);
|
|
17
|
+
});
|
|
18
|
+
it('falls back to the existing persona for an invalid flag', () => {
|
|
19
|
+
const existing = { level: 3, label: 'engineer' };
|
|
20
|
+
expect(resolvePersona('99', existing)).toEqual(existing);
|
|
21
|
+
expect(resolvePersona('abc', existing)).toEqual(existing);
|
|
22
|
+
expect(resolvePersona('0', existing)).toEqual(existing);
|
|
23
|
+
});
|
|
24
|
+
it('returns undefined when there is no flag and nothing on disk', () => {
|
|
25
|
+
expect(resolvePersona(undefined, undefined)).toBeUndefined();
|
|
26
|
+
});
|
|
27
|
+
it('prefers the flag over an existing on-disk persona', () => {
|
|
28
|
+
const existing = { level: 1, label: 'novice' };
|
|
29
|
+
expect(resolvePersona('3', existing)).toEqual({ level: 3, label: 'engineer' });
|
|
30
|
+
});
|
|
31
|
+
});
|
package/dist/commands/doctor.js
CHANGED
|
@@ -2,6 +2,88 @@ import { Command } from 'commander';
|
|
|
2
2
|
import { shouldOutputJson, jsonOut } from '../utils/output.js';
|
|
3
3
|
import { bold, dim, green, yellow, cyan } from '../ui/colors.js';
|
|
4
4
|
import { runAllChecks } from '../health/runner.js';
|
|
5
|
+
import { detectCurrentAgent } from '../agents/runtime-detection.js';
|
|
6
|
+
/**
|
|
7
|
+
* Env vars worth surfacing in --verbose for AI agents debugging their own
|
|
8
|
+
* environment. Filtered to known-safe runtime signals; never includes
|
|
9
|
+
* credentials, tokens, or anything matching common secret patterns.
|
|
10
|
+
*/
|
|
11
|
+
const VERBOSE_ENV_ALLOWLIST = [
|
|
12
|
+
// Claude Code
|
|
13
|
+
'CLAUDECODE',
|
|
14
|
+
'CLAUDE_CODE_ENTRYPOINT',
|
|
15
|
+
'CLAUDE_CODE_SESSION_ID',
|
|
16
|
+
'CLAUDE_CODE_EXECPATH',
|
|
17
|
+
'CLAUDE_EFFORT',
|
|
18
|
+
// Codex
|
|
19
|
+
'CODEX_CI',
|
|
20
|
+
'CODEX_THREAD_ID',
|
|
21
|
+
'CODEX_SANDBOX',
|
|
22
|
+
'CODEX_SANDBOX_NETWORK_DISABLED',
|
|
23
|
+
// Generic shell context
|
|
24
|
+
'PWD',
|
|
25
|
+
'SHELL',
|
|
26
|
+
'TERM',
|
|
27
|
+
'LANG',
|
|
28
|
+
// CI markers
|
|
29
|
+
'CI',
|
|
30
|
+
'GITHUB_ACTIONS',
|
|
31
|
+
];
|
|
32
|
+
function collectVerboseInfo() {
|
|
33
|
+
const env = {};
|
|
34
|
+
for (const key of VERBOSE_ENV_ALLOWLIST) {
|
|
35
|
+
if (process.env[key] !== undefined) {
|
|
36
|
+
env[key] = process.env[key];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const detected = detectCurrentAgent();
|
|
40
|
+
return {
|
|
41
|
+
hostAgent: detected ?? null,
|
|
42
|
+
env,
|
|
43
|
+
runtime: {
|
|
44
|
+
platform: process.platform,
|
|
45
|
+
arch: process.arch,
|
|
46
|
+
nodeVersion: process.version,
|
|
47
|
+
cwd: process.cwd(),
|
|
48
|
+
pid: process.pid,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function printVerboseBlock(info) {
|
|
53
|
+
console.log('');
|
|
54
|
+
console.log(bold('Verbose runtime info'));
|
|
55
|
+
console.log('');
|
|
56
|
+
const detected = info.hostAgent;
|
|
57
|
+
if (detected) {
|
|
58
|
+
console.log(` ${green('[detected]')} Host agent: ${detected.slug}`);
|
|
59
|
+
if (detected.sessionId)
|
|
60
|
+
console.log(` sessionId: ${detected.sessionId}`);
|
|
61
|
+
if (detected.sessionFilePath)
|
|
62
|
+
console.log(` sessionFilePath: ${detected.sessionFilePath}`);
|
|
63
|
+
console.log(` source: ${detected.source}`);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
console.log(` ${dim('[none]')} No host agent detected (not running inside a known AI agent)`);
|
|
67
|
+
}
|
|
68
|
+
console.log('');
|
|
69
|
+
console.log(bold('Env vars (allowlisted)'));
|
|
70
|
+
const envEntries = Object.entries(info.env);
|
|
71
|
+
if (envEntries.length === 0) {
|
|
72
|
+
console.log(` ${dim('(none set)')}`);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
for (const [k, v] of envEntries) {
|
|
76
|
+
console.log(` ${k.padEnd(38)} ${v}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
console.log('');
|
|
80
|
+
console.log(bold('Runtime'));
|
|
81
|
+
const r = info.runtime;
|
|
82
|
+
for (const [k, v] of Object.entries(r)) {
|
|
83
|
+
console.log(` ${k.padEnd(38)} ${v}`);
|
|
84
|
+
}
|
|
85
|
+
console.log('');
|
|
86
|
+
}
|
|
5
87
|
const STATUS_LABELS = {
|
|
6
88
|
pass: green('[pass]'),
|
|
7
89
|
warn: yellow('[warn]'),
|
|
@@ -67,14 +149,19 @@ function printHumanReport(report) {
|
|
|
67
149
|
}
|
|
68
150
|
export const doctorCommand = new Command('doctor')
|
|
69
151
|
.description('Check system health: auth, network, project config, agent setup')
|
|
70
|
-
.
|
|
152
|
+
.option('-v, --verbose', 'Include host-agent detection results, runtime info, and allowlisted env vars (useful for AI agents debugging their own environment)')
|
|
153
|
+
.action(async (opts, command) => {
|
|
71
154
|
const asJson = shouldOutputJson(command.optsWithGlobals().json);
|
|
72
155
|
const report = await runAllChecks();
|
|
156
|
+
const verboseInfo = opts.verbose ? collectVerboseInfo() : null;
|
|
73
157
|
if (asJson) {
|
|
74
|
-
jsonOut(report);
|
|
158
|
+
jsonOut(verboseInfo ? { ...report, verbose: verboseInfo } : report);
|
|
75
159
|
}
|
|
76
160
|
else {
|
|
77
161
|
printHumanReport(report);
|
|
162
|
+
if (verboseInfo) {
|
|
163
|
+
printVerboseBlock(verboseInfo);
|
|
164
|
+
}
|
|
78
165
|
}
|
|
79
166
|
if (report.checks.some(c => c.status === 'fail')) {
|
|
80
167
|
process.exit(1);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* `runwork inbox` - list shared conversations visible to the current user.
|
|
4
|
+
*
|
|
5
|
+
* Scopes:
|
|
6
|
+
* --filter received shares others sent to me
|
|
7
|
+
* --filter sent shares I sent to others
|
|
8
|
+
* --filter saved my personal checkpoints (save-convo)
|
|
9
|
+
* --filter all all of the above (default)
|
|
10
|
+
*/
|
|
11
|
+
export declare const inboxCommand: Command;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { requireAuth } from '../auth/store.js';
|
|
3
|
+
import { ApiClient } from '../api/client.js';
|
|
4
|
+
import { resolveWorkspace } from '../workspace/resolve.js';
|
|
5
|
+
import { shouldOutputJson, jsonOut } from '../utils/output.js';
|
|
6
|
+
/**
|
|
7
|
+
* `runwork inbox` - list shared conversations visible to the current user.
|
|
8
|
+
*
|
|
9
|
+
* Scopes:
|
|
10
|
+
* --filter received shares others sent to me
|
|
11
|
+
* --filter sent shares I sent to others
|
|
12
|
+
* --filter saved my personal checkpoints (save-convo)
|
|
13
|
+
* --filter all all of the above (default)
|
|
14
|
+
*/
|
|
15
|
+
export const inboxCommand = new Command('inbox')
|
|
16
|
+
.description('List shared conversations visible to you')
|
|
17
|
+
.option('--filter <scope>', 'Filter: all | received | sent | saved', 'all')
|
|
18
|
+
.option('--limit <n>', 'Max rows to return', '50')
|
|
19
|
+
.option('--workspace <id>', 'Workspace ID')
|
|
20
|
+
.action(async (opts, command) => {
|
|
21
|
+
const useJson = shouldOutputJson(command.optsWithGlobals().json);
|
|
22
|
+
const scope = opts.filter === 'received' || opts.filter === 'sent' || opts.filter === 'saved'
|
|
23
|
+
? opts.filter
|
|
24
|
+
: 'all';
|
|
25
|
+
const limit = opts.limit ? parseInt(opts.limit, 10) : 50;
|
|
26
|
+
const credentials = requireAuth();
|
|
27
|
+
const client = new ApiClient(credentials);
|
|
28
|
+
const { workspaceId } = await resolveWorkspace(client, { workspace: opts.workspace });
|
|
29
|
+
try {
|
|
30
|
+
const { shares, total } = await client.listSharedConversations(workspaceId, { scope, limit });
|
|
31
|
+
if (useJson) {
|
|
32
|
+
jsonOut({ shares, total });
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (shares.length === 0) {
|
|
36
|
+
console.log(`No shared conversations (scope: ${scope}).`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
console.log(`\nShared conversations (${scope}, ${total}):\n`);
|
|
40
|
+
console.log(` ${'ID'.padEnd(20)} ${'Title'.padEnd(40)} ${'Agent'.padEnd(14)} Status`);
|
|
41
|
+
console.log(' ' + '-'.repeat(96));
|
|
42
|
+
for (const raw of shares) {
|
|
43
|
+
const share = raw;
|
|
44
|
+
const id = share.id.slice(0, 18);
|
|
45
|
+
const title = (share.title || '').slice(0, 38);
|
|
46
|
+
const agent = (share.sourceAgent || 'unknown').slice(0, 12);
|
|
47
|
+
const status = share.deletedAt
|
|
48
|
+
? 'deleted'
|
|
49
|
+
: share.isPersonal
|
|
50
|
+
? 'saved'
|
|
51
|
+
: ((share.recipients ?? []).every(r => r.status === 'resumed') ? 'resumed' : 'pending');
|
|
52
|
+
console.log(` ${id.padEnd(20)} ${title.padEnd(40)} ${agent.padEnd(14)} ${status}`);
|
|
53
|
+
}
|
|
54
|
+
console.log('');
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
console.error(`Failed to list inbox: ${err instanceof Error ? err.message : err}`);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
});
|
package/dist/commands/info.d.ts
CHANGED
package/dist/commands/info.js
CHANGED
|
@@ -239,7 +239,12 @@ function printHumanOutput(data) {
|
|
|
239
239
|
else {
|
|
240
240
|
console.log(` ${dim(pad('Preview:'))}${dim('(not running)')}`);
|
|
241
241
|
}
|
|
242
|
-
|
|
242
|
+
if (data.production.url) {
|
|
243
|
+
console.log(` ${dim(pad('Production:'))}${green(data.production.url)} ${dim('(deployed)')}`);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
console.log(` ${dim(pad('Production:'))}${dim('(not deployed)')}`);
|
|
247
|
+
}
|
|
243
248
|
// Local dev session view: what's running on THIS machine, from the
|
|
244
249
|
// session file. This may disagree with the server's "preview"
|
|
245
250
|
// status above; that's diagnostic, not a bug.
|
|
@@ -422,7 +427,7 @@ export const infoCommand = new Command('info')
|
|
|
422
427
|
},
|
|
423
428
|
preview,
|
|
424
429
|
localDevSession,
|
|
425
|
-
production: { url: null, deployed: false },
|
|
430
|
+
production: appInfo?.production ?? { url: null, deployed: false },
|
|
426
431
|
integrations,
|
|
427
432
|
registries,
|
|
428
433
|
cli: {
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { writeFileSync, mkdirSync, realpathSync } from 'fs';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { spawn } from 'child_process';
|
|
6
|
+
import { requireAuth } from '../auth/store.js';
|
|
7
|
+
import { ApiClient } from '../api/client.js';
|
|
8
|
+
import { resolveWorkspace } from '../workspace/resolve.js';
|
|
9
|
+
import { shouldOutputJson, jsonOut } from '../utils/output.js';
|
|
10
|
+
import { getAgent } from '../agents/registry-data.js';
|
|
11
|
+
import { detectCurrentAgent } from '../agents/runtime-detection.js';
|
|
12
|
+
import { whichBinary } from '../utils/which.js';
|
|
13
|
+
/**
|
|
14
|
+
* Mirror of Claude Code's cwd encoding rule: replace every non-alphanumeric
|
|
15
|
+
* character with '-'. The canonical (realpath-resolved) cwd is encoded so
|
|
16
|
+
* /tmp/foo on macOS encodes the same as /private/tmp/foo (which is how
|
|
17
|
+
* Claude Code itself resolves the cwd).
|
|
18
|
+
*/
|
|
19
|
+
function encodeClaudeCodeCwd(cwd) {
|
|
20
|
+
let canonical;
|
|
21
|
+
try {
|
|
22
|
+
canonical = realpathSync(cwd);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
canonical = cwd;
|
|
26
|
+
}
|
|
27
|
+
return canonical.replace(/[^a-zA-Z0-9]/g, '-');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extract the original Claude Code session UUID from the first event of a
|
|
31
|
+
* JSONL bundle. Claude Code's `--resume <uuid>` expects this UUID; the
|
|
32
|
+
* filename on disk must match `<uuid>.jsonl`.
|
|
33
|
+
*/
|
|
34
|
+
function extractClaudeCodeUuid(jsonlContent) {
|
|
35
|
+
const firstLine = jsonlContent.split('\n').find(l => l.trim().length > 0);
|
|
36
|
+
if (!firstLine)
|
|
37
|
+
return null;
|
|
38
|
+
try {
|
|
39
|
+
const event = JSON.parse(firstLine);
|
|
40
|
+
return event.sessionId ?? null;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Extract the original Codex thread UUID from the first event of a rollout
|
|
48
|
+
* file. `codex resume <UUID>` accepts this id; the file's filename embeds it.
|
|
49
|
+
*/
|
|
50
|
+
function extractCodexUuid(rolloutContent) {
|
|
51
|
+
const firstLine = rolloutContent.split('\n').find(l => l.trim().length > 0);
|
|
52
|
+
if (!firstLine)
|
|
53
|
+
return null;
|
|
54
|
+
try {
|
|
55
|
+
const event = JSON.parse(firstLine);
|
|
56
|
+
return event.payload?.id ?? null;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function placeClaudeJsonl(uuid, content, recipientCwd) {
|
|
63
|
+
const encoded = encodeClaudeCodeCwd(recipientCwd);
|
|
64
|
+
const projectDir = join(homedir(), '.claude', 'projects', encoded);
|
|
65
|
+
mkdirSync(projectDir, { recursive: true });
|
|
66
|
+
const placedAt = join(projectDir, `${uuid}.jsonl`);
|
|
67
|
+
writeFileSync(placedAt, content);
|
|
68
|
+
return { placedAt, runFromCwd: recipientCwd };
|
|
69
|
+
}
|
|
70
|
+
function placeCodexRollout(uuid, content) {
|
|
71
|
+
const now = new Date();
|
|
72
|
+
const yyyy = String(now.getUTCFullYear());
|
|
73
|
+
const mm = String(now.getUTCMonth() + 1).padStart(2, '0');
|
|
74
|
+
const dd = String(now.getUTCDate()).padStart(2, '0');
|
|
75
|
+
const dir = join(homedir(), '.codex', 'sessions', yyyy, mm, dd);
|
|
76
|
+
mkdirSync(dir, { recursive: true });
|
|
77
|
+
// Filename pattern Codex itself uses: rollout-YYYY-MM-DDThh-mm-ss-<uuid>.jsonl
|
|
78
|
+
const ts = now.toISOString().replace(/\.\d+Z$/, '').replace(/:/g, '-');
|
|
79
|
+
const placedAt = join(dir, `rollout-${ts}-${uuid}.jsonl`);
|
|
80
|
+
writeFileSync(placedAt, content);
|
|
81
|
+
return { placedAt };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Pick the target agent based on flag overrides, the share's sourceAgent,
|
|
85
|
+
* and what's installed locally.
|
|
86
|
+
*/
|
|
87
|
+
function pickTargetAgent(opts, sourceAgent) {
|
|
88
|
+
if (opts.agent) {
|
|
89
|
+
return getAgent(opts.agent) ?? null;
|
|
90
|
+
}
|
|
91
|
+
// Prefer the same agent the sender used, if installed
|
|
92
|
+
const source = getAgent(sourceAgent);
|
|
93
|
+
if (source && isAgentInstalled(source)) {
|
|
94
|
+
return source;
|
|
95
|
+
}
|
|
96
|
+
// Fall back to the sender's agent registry entry even if not detectably installed
|
|
97
|
+
// (the user may have it; better to print accurate instructions than abort)
|
|
98
|
+
return source ?? null;
|
|
99
|
+
}
|
|
100
|
+
function isAgentInstalled(agent) {
|
|
101
|
+
// Lightweight check: just look for the launch binary on PATH.
|
|
102
|
+
// More comprehensive detection lives in agents/detection.ts but requires
|
|
103
|
+
// async resolution; this synchronous check is good enough for resume.
|
|
104
|
+
if (agent.launch?.cli) {
|
|
105
|
+
return !!whichBinary(agent.launch.cli);
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
export const resumeCommand = new Command('resume')
|
|
110
|
+
.description('Resume a shared conversation locally in your agent of choice')
|
|
111
|
+
.argument('<share-id>', 'The share ID (sc_*) returned by share-convo or save-convo')
|
|
112
|
+
.option('--agent <slug>', 'Override target agent (e.g. claude-code, codex)')
|
|
113
|
+
.option('--into <path>', 'Override target cwd (defaults to current $PWD)')
|
|
114
|
+
.option('--dry-run', 'Print the resume command instead of executing it')
|
|
115
|
+
.option('--pick', 'Show interactive picker (requires TTY) - not yet implemented')
|
|
116
|
+
.option('--workspace <id>', 'Workspace ID')
|
|
117
|
+
.action(async (shareId, opts, command) => {
|
|
118
|
+
const useJson = shouldOutputJson(command.optsWithGlobals().json);
|
|
119
|
+
const credentials = requireAuth();
|
|
120
|
+
const client = new ApiClient(credentials);
|
|
121
|
+
const { workspaceId } = await resolveWorkspace(client, { workspace: opts.workspace });
|
|
122
|
+
let share;
|
|
123
|
+
try {
|
|
124
|
+
const { share: raw } = await client.getSharedConversation(workspaceId, shareId);
|
|
125
|
+
share = raw;
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
console.error(`Failed to fetch share ${shareId}: ${err instanceof Error ? err.message : err}`);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
// If --agent not provided, detect what the user is currently in - that's
|
|
132
|
+
// often the best default ("share to me, resume in same agent")
|
|
133
|
+
if (!opts.agent) {
|
|
134
|
+
const detected = detectCurrentAgent();
|
|
135
|
+
if (detected) {
|
|
136
|
+
opts.agent = detected.slug;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const target = pickTargetAgent(opts, share.sourceAgent);
|
|
140
|
+
if (!target) {
|
|
141
|
+
console.error(`No target agent could be determined. Pass --agent <slug> or install the source agent (${share.sourceAgent}).`);
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
const cap = target.resumeCapability;
|
|
145
|
+
// Tier 3 fallback: no native resume - print a paste-prompt
|
|
146
|
+
if (!cap || cap.mode === 'unsupported' || !cap.nativeBundleFormat) {
|
|
147
|
+
const promptText = buildPastePrompt(shareId, share.title);
|
|
148
|
+
if (useJson) {
|
|
149
|
+
jsonOut({ mode: 'paste-prompt', shareId, prompt: promptText });
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
console.log(`\n${target.name} does not support native resume. Paste this prompt into your agent:\n`);
|
|
153
|
+
console.log('---');
|
|
154
|
+
console.log(promptText);
|
|
155
|
+
console.log('---\n');
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
// Need a matching native bundle on the share
|
|
159
|
+
const hasNative = (share.bundles ?? []).some(b => b.format === cap.nativeBundleFormat);
|
|
160
|
+
if (!hasNative) {
|
|
161
|
+
console.error(`This share has no ${cap.nativeBundleFormat} bundle (sourceAgent was ${share.sourceAgent}). ` +
|
|
162
|
+
`Falling back to paste-prompt.`);
|
|
163
|
+
const promptText = buildPastePrompt(shareId, share.title);
|
|
164
|
+
console.log('\n---');
|
|
165
|
+
console.log(promptText);
|
|
166
|
+
console.log('---\n');
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
// Download the native bundle content
|
|
170
|
+
const bundle = await client.downloadSharedConversationBundle(workspaceId, shareId, cap.nativeBundleFormat);
|
|
171
|
+
// Extract the ORIGINAL session UUID from the bundle content - that's
|
|
172
|
+
// what the native resume command expects, not our share ID.
|
|
173
|
+
let nativeUuid;
|
|
174
|
+
if (cap.nativeBundleFormat === 'claude-jsonl') {
|
|
175
|
+
nativeUuid = extractClaudeCodeUuid(bundle.content);
|
|
176
|
+
}
|
|
177
|
+
else if (cap.nativeBundleFormat === 'codex-rollout') {
|
|
178
|
+
nativeUuid = extractCodexUuid(bundle.content);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
console.error(`No UUID extraction strategy for native bundle format ${cap.nativeBundleFormat}`);
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
if (!nativeUuid) {
|
|
185
|
+
console.error(`Could not extract native session UUID from ${cap.nativeBundleFormat} bundle. ` +
|
|
186
|
+
`The bundle may be malformed.`);
|
|
187
|
+
process.exit(1);
|
|
188
|
+
}
|
|
189
|
+
// Place the file per-agent using the original UUID
|
|
190
|
+
let placement;
|
|
191
|
+
const recipientCwd = opts.into ?? process.cwd();
|
|
192
|
+
if (cap.nativeBundleFormat === 'claude-jsonl') {
|
|
193
|
+
placement = placeClaudeJsonl(nativeUuid, bundle.content, recipientCwd);
|
|
194
|
+
}
|
|
195
|
+
else if (cap.nativeBundleFormat === 'codex-rollout') {
|
|
196
|
+
placement = placeCodexRollout(nativeUuid, bundle.content);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
console.error(`No placement strategy for native bundle format ${cap.nativeBundleFormat}`);
|
|
200
|
+
process.exit(1);
|
|
201
|
+
}
|
|
202
|
+
// Tell the server we resumed it (best-effort)
|
|
203
|
+
client.markSharedConversationResumed(workspaceId, shareId).catch(() => {
|
|
204
|
+
// Non-fatal; the user is already up and resuming
|
|
205
|
+
});
|
|
206
|
+
if (cap.mode === 'file-drop-only') {
|
|
207
|
+
const result = {
|
|
208
|
+
mode: 'file-drop-only',
|
|
209
|
+
agent: target.slug,
|
|
210
|
+
placedAt: placement.placedAt,
|
|
211
|
+
hint: cap.manualOpenHint ?? `Open ${target.name} to find this session in your history.`,
|
|
212
|
+
};
|
|
213
|
+
if (useJson) {
|
|
214
|
+
jsonOut(result);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
console.log(`\nBundle placed at: ${placement.placedAt}`);
|
|
218
|
+
console.log(`${result.hint}\n`);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (cap.mode === 'cli-resume') {
|
|
222
|
+
// Substitute {uuid} in the resume command template with the original
|
|
223
|
+
// session UUID we extracted from the bundle content.
|
|
224
|
+
const cmd = (cap.cliResumeCommand ?? '').replace(/\{uuid\}/g, nativeUuid);
|
|
225
|
+
if (opts.dryRun) {
|
|
226
|
+
const fullCmd = placement.runFromCwd
|
|
227
|
+
? `cd "${placement.runFromCwd}" && ${cmd}`
|
|
228
|
+
: cmd;
|
|
229
|
+
const result = {
|
|
230
|
+
mode: 'cli-resume',
|
|
231
|
+
agent: target.slug,
|
|
232
|
+
placedAt: placement.placedAt,
|
|
233
|
+
command: fullCmd,
|
|
234
|
+
};
|
|
235
|
+
if (useJson) {
|
|
236
|
+
jsonOut(result);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
console.log(`\nBundle placed at: ${placement.placedAt}`);
|
|
240
|
+
console.log(`Run: ${fullCmd}\n`);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
// Exec the resume command
|
|
244
|
+
const parts = cmd.split(' ');
|
|
245
|
+
const child = spawn(parts[0], parts.slice(1), {
|
|
246
|
+
cwd: placement.runFromCwd ?? recipientCwd,
|
|
247
|
+
stdio: 'inherit',
|
|
248
|
+
});
|
|
249
|
+
child.on('exit', (code) => {
|
|
250
|
+
process.exit(code ?? 0);
|
|
251
|
+
});
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
console.error(`Unexpected resumeCapability.mode: ${cap.mode}`);
|
|
255
|
+
process.exit(1);
|
|
256
|
+
});
|
|
257
|
+
function buildPastePrompt(shareId, title) {
|
|
258
|
+
return `Continue the conversation that a teammate shared with me. The share ID is ${shareId} (title: "${title}").
|
|
259
|
+
|
|
260
|
+
PREFERRED: if the \`runwork\` CLI is installed locally, run:
|
|
261
|
+
runwork resume ${shareId}
|
|
262
|
+
That auto-detects your active agent and resumes natively if possible.
|
|
263
|
+
|
|
264
|
+
FALLBACK: use the Runwork MCP tool \`get_shared_conversation\` with this share ID to fetch the full transcript, then continue from where the conversation left off.`;
|
|
265
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* `runwork save-convo` - personal checkpoint of the current AI conversation.
|
|
4
|
+
*
|
|
5
|
+
* Thin alias over `share-convo` with isPersonal=true. The recipient is always
|
|
6
|
+
* the sender; no notifications are sent. Same capture mechanics otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export declare const saveConvoCommand: Command;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { runShareConvo } from './share-convo.js';
|
|
3
|
+
/**
|
|
4
|
+
* `runwork save-convo` - personal checkpoint of the current AI conversation.
|
|
5
|
+
*
|
|
6
|
+
* Thin alias over `share-convo` with isPersonal=true. The recipient is always
|
|
7
|
+
* the sender; no notifications are sent. Same capture mechanics otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export const saveConvoCommand = new Command('save-convo')
|
|
10
|
+
.description('Save the current AI conversation as a personal checkpoint')
|
|
11
|
+
.option('--transcript-file <path>', 'Path to the LLM-emitted markdown transcript (required)')
|
|
12
|
+
.option('--native-file <path>', 'Path to the native session file (optional; auto-detected from env vars)')
|
|
13
|
+
.option('--source-agent <slug>', 'Override host-agent detection')
|
|
14
|
+
.option('--title <string>', 'Short title for the conversation (required)')
|
|
15
|
+
.option('--note <string>', 'Optional note to your future self')
|
|
16
|
+
.option('--ttl-days <n>', 'Days until expiration (1-30, default 7)')
|
|
17
|
+
.option('--metadata-json <json>', 'Inline JSON object with workMode, openQuestions, etc.')
|
|
18
|
+
.option('--metadata-file <path>', 'Path to a JSON file with metadata fields')
|
|
19
|
+
.option('--workspace <id>', 'Workspace ID')
|
|
20
|
+
.action((opts, command) => runShareConvo({ ...opts, personal: true }, command, true));
|