runwork 0.12.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/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/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/doctor.js +89 -2
- package/dist/commands/inbox.d.ts +11 -0
- package/dist/commands/inbox.js +60 -0
- 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/share-convo.d.ts +24 -0
- package/dist/commands/share-convo.js +167 -0
- package/dist/commands/sync.js +95 -10
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/index.js +8 -0
- package/package.json +1 -1
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
|
+
});
|
|
@@ -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));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* `runwork share-convo` - share the current AI conversation with a teammate.
|
|
4
|
+
*
|
|
5
|
+
* Typically invoked by the `share-conversation` skill from inside an AI agent.
|
|
6
|
+
* The skill is responsible for emitting the markdown transcript and metadata;
|
|
7
|
+
* this command does the upload, host-agent detection, and native-bundle pickup.
|
|
8
|
+
*/
|
|
9
|
+
interface ShareConvoOptions {
|
|
10
|
+
to?: string[];
|
|
11
|
+
transcriptFile?: string;
|
|
12
|
+
nativeFile?: string;
|
|
13
|
+
sourceAgent?: string;
|
|
14
|
+
title?: string;
|
|
15
|
+
note?: string;
|
|
16
|
+
personal?: boolean;
|
|
17
|
+
ttlDays?: string;
|
|
18
|
+
metadataJson?: string;
|
|
19
|
+
metadataFile?: string;
|
|
20
|
+
workspace?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function runShareConvo(opts: ShareConvoOptions, command: Command, isPersonalAlias?: boolean): Promise<void>;
|
|
23
|
+
export declare const shareConvoCommand: Command;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { readFileSync, existsSync } from 'fs';
|
|
3
|
+
import { createHash } from 'crypto';
|
|
4
|
+
import { requireAuth } from '../auth/store.js';
|
|
5
|
+
import { ApiClient } from '../api/client.js';
|
|
6
|
+
import { resolveWorkspace } from '../workspace/resolve.js';
|
|
7
|
+
import { shouldOutputJson, jsonOut } from '../utils/output.js';
|
|
8
|
+
import { detectCurrentAgent } from '../agents/runtime-detection.js';
|
|
9
|
+
function nativeBundleFormatForAgent(slug) {
|
|
10
|
+
if (slug === 'claude-code' || slug === 'claude-desktop')
|
|
11
|
+
return 'claude-jsonl';
|
|
12
|
+
if (slug === 'codex' || slug === 'codex-app')
|
|
13
|
+
return 'codex-rollout';
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
function sha256Hex(content) {
|
|
17
|
+
return createHash('sha256').update(content, 'utf8').digest('hex');
|
|
18
|
+
}
|
|
19
|
+
function utf8ByteLength(content) {
|
|
20
|
+
return Buffer.byteLength(content, 'utf8');
|
|
21
|
+
}
|
|
22
|
+
export async function runShareConvo(opts, command, isPersonalAlias = false) {
|
|
23
|
+
const useJson = shouldOutputJson(command.optsWithGlobals().json);
|
|
24
|
+
if (!opts.transcriptFile) {
|
|
25
|
+
console.error('Error: --transcript-file is required. Pass the path to the LLM-emitted markdown transcript.');
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
if (!existsSync(opts.transcriptFile)) {
|
|
29
|
+
console.error(`Error: transcript file does not exist: ${opts.transcriptFile}`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
if (!opts.title) {
|
|
33
|
+
console.error('Error: --title is required.');
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
const isPersonal = isPersonalAlias || !!opts.personal || (!opts.to || opts.to.length === 0);
|
|
37
|
+
const recipients = opts.to ?? [];
|
|
38
|
+
if (!isPersonal && recipients.length === 0) {
|
|
39
|
+
console.error('Error: at least one --to <email> is required (or use --personal to save for yourself)');
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
if (isPersonal && recipients.length > 0) {
|
|
43
|
+
console.error('Error: --personal and --to cannot be combined; personal shares are self-only');
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
const credentials = requireAuth();
|
|
47
|
+
const client = new ApiClient(credentials);
|
|
48
|
+
const { workspaceId } = await resolveWorkspace(client, { workspace: opts.workspace });
|
|
49
|
+
// Read transcript bundle (always required)
|
|
50
|
+
const transcriptContent = readFileSync(opts.transcriptFile, 'utf8');
|
|
51
|
+
const bundles = [
|
|
52
|
+
{
|
|
53
|
+
format: 'transcript',
|
|
54
|
+
content: transcriptContent,
|
|
55
|
+
sizeBytes: utf8ByteLength(transcriptContent),
|
|
56
|
+
sha256: sha256Hex(transcriptContent),
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
// Detect host agent (for source tagging and native bundle pickup)
|
|
60
|
+
const detected = detectCurrentAgent();
|
|
61
|
+
const sourceAgent = opts.sourceAgent ?? detected?.slug ?? 'generic';
|
|
62
|
+
// Resolve native bundle - explicit --native-file wins, else use detection
|
|
63
|
+
let nativeFilePath = null;
|
|
64
|
+
if (opts.nativeFile) {
|
|
65
|
+
if (!existsSync(opts.nativeFile)) {
|
|
66
|
+
console.error(`Error: --native-file path does not exist: ${opts.nativeFile}`);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
nativeFilePath = opts.nativeFile;
|
|
70
|
+
}
|
|
71
|
+
else if (detected?.sessionFilePath && existsSync(detected.sessionFilePath)) {
|
|
72
|
+
nativeFilePath = detected.sessionFilePath;
|
|
73
|
+
}
|
|
74
|
+
if (nativeFilePath) {
|
|
75
|
+
const nativeFormat = nativeBundleFormatForAgent(sourceAgent);
|
|
76
|
+
if (nativeFormat) {
|
|
77
|
+
try {
|
|
78
|
+
const content = readFileSync(nativeFilePath, 'utf8');
|
|
79
|
+
bundles.push({
|
|
80
|
+
format: nativeFormat,
|
|
81
|
+
content,
|
|
82
|
+
sizeBytes: utf8ByteLength(content),
|
|
83
|
+
sha256: sha256Hex(content),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
console.error(`Warning: could not read native file ${nativeFilePath}: ${err instanceof Error ? err.message : err}`);
|
|
88
|
+
console.error('Continuing with transcript-only bundle.');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Metadata - merge --metadata-json and --metadata-file
|
|
93
|
+
let metadata = {};
|
|
94
|
+
if (opts.metadataFile) {
|
|
95
|
+
try {
|
|
96
|
+
metadata = JSON.parse(readFileSync(opts.metadataFile, 'utf8'));
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
console.error(`Error: --metadata-file is not valid JSON: ${err instanceof Error ? err.message : err}`);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (opts.metadataJson) {
|
|
104
|
+
try {
|
|
105
|
+
metadata = { ...metadata, ...JSON.parse(opts.metadataJson) };
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
console.error(`Error: --metadata-json is not valid JSON: ${err instanceof Error ? err.message : err}`);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Augment metadata with detected host info if not already provided
|
|
113
|
+
if (detected && !metadata.sourceSessionId) {
|
|
114
|
+
metadata.sourceSessionId = detected.sessionId;
|
|
115
|
+
}
|
|
116
|
+
if (!metadata.os) {
|
|
117
|
+
metadata.os = process.platform === 'darwin' ? 'macos' : process.platform === 'win32' ? 'windows' : 'linux';
|
|
118
|
+
}
|
|
119
|
+
const ttlDays = opts.ttlDays ? parseInt(opts.ttlDays, 10) : undefined;
|
|
120
|
+
try {
|
|
121
|
+
const result = await client.createSharedConversation(workspaceId, {
|
|
122
|
+
recipients: isPersonal ? [] : recipients,
|
|
123
|
+
isPersonal,
|
|
124
|
+
sourceAgent,
|
|
125
|
+
title: opts.title,
|
|
126
|
+
note: opts.note,
|
|
127
|
+
bundles,
|
|
128
|
+
metadata,
|
|
129
|
+
ttlDays: ttlDays && Number.isFinite(ttlDays) ? ttlDays : undefined,
|
|
130
|
+
});
|
|
131
|
+
if (useJson) {
|
|
132
|
+
jsonOut(result);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (isPersonal) {
|
|
136
|
+
console.log(`Saved conversation: ${result.share.title}`);
|
|
137
|
+
console.log(`Share ID: ${result.share.id}`);
|
|
138
|
+
console.log(`Expires: ${result.share.expiresAt}`);
|
|
139
|
+
console.log(`\nResume with: runwork resume ${result.share.id}`);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
console.log(`Shared with ${result.sharedCount} member${result.sharedCount === 1 ? '' : 's'}` +
|
|
143
|
+
(result.invitedCount > 0 ? ` and invited ${result.invitedCount} new user${result.invitedCount === 1 ? '' : 's'}` : '') + '.');
|
|
144
|
+
console.log(`Share ID: ${result.share.id}`);
|
|
145
|
+
if (result.skipped.length > 0) {
|
|
146
|
+
console.log(`\nSkipped: ${result.skipped.map(s => `${s.identifier} (${s.reason})`).join(', ')}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
console.error(`Failed to share conversation: ${err instanceof Error ? err.message : err}`);
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export const shareConvoCommand = new Command('share-convo')
|
|
156
|
+
.description('Share the current AI conversation with a teammate')
|
|
157
|
+
.option('--to <email>', 'Recipient email (repeatable)', (value, prev = []) => [...prev, value], [])
|
|
158
|
+
.option('--transcript-file <path>', 'Path to the LLM-emitted markdown transcript (required)')
|
|
159
|
+
.option('--native-file <path>', 'Path to the native session file (optional; auto-detected from env vars otherwise)')
|
|
160
|
+
.option('--source-agent <slug>', 'Override host-agent detection (e.g. claude-code, codex, claude-desktop)')
|
|
161
|
+
.option('--title <string>', 'Short title for the conversation (required)')
|
|
162
|
+
.option('--note <string>', 'Optional personal note to recipients')
|
|
163
|
+
.option('--ttl-days <n>', 'Days until expiration (1-30, default 7)')
|
|
164
|
+
.option('--metadata-json <json>', 'Inline JSON object with workMode, openQuestions, suggestedNextStep, etc.')
|
|
165
|
+
.option('--metadata-file <path>', 'Path to a JSON file with the same metadata fields')
|
|
166
|
+
.option('--workspace <id>', 'Workspace ID')
|
|
167
|
+
.action((opts, command) => runShareConvo(opts, command, false));
|