@logicseek/hello-cc 0.1.4 → 0.1.6
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/CHANGELOG.md +126 -0
- package/bin/hcc.mjs +2739 -6482
- package/docs/README.md +2 -0
- package/docs/README.zh-CN.md +3 -1
- package/docs/architecture-split-review.md +217 -0
- package/docs/architecture.md +385 -0
- package/docs/architecture.zh-CN.md +364 -0
- package/docs/commands.md +21 -9
- package/docs/commands.zh-CN.md +19 -9
- package/docs/layout-split-stack-audit.md +298 -0
- package/lib/automation.mjs +8 -0
- package/lib/cli-args.mjs +89 -0
- package/lib/cli-runtime.mjs +44 -0
- package/lib/coordination-state.mjs +218 -0
- package/lib/core/coordination/automation.mjs +222 -0
- package/lib/core/coordination/locks.mjs +46 -0
- package/lib/core/coordination/messages.mjs +116 -0
- package/lib/core/coordination/tasks.mjs +224 -0
- package/lib/core/coordination/teams.mjs +73 -0
- package/lib/core/coordination/timeline.mjs +187 -0
- package/lib/core/peers/bindings.mjs +83 -0
- package/lib/core/peers/format.mjs +13 -0
- package/lib/core/peers/identity.mjs +53 -0
- package/lib/core/peers/liveness.mjs +90 -0
- package/lib/core/peers/reconcile.mjs +238 -0
- package/lib/core/peers/session.mjs +14 -0
- package/lib/core/sessions/launch.mjs +89 -0
- package/lib/db/schema.mjs +324 -0
- package/lib/db/stores/peers.mjs +231 -0
- package/lib/db-schema.mjs +7 -0
- package/lib/errors.mjs +1 -0
- package/lib/format.mjs +39 -0
- package/lib/guidance.mjs +10 -2
- package/lib/handoff.mjs +26 -0
- package/lib/help.mjs +3 -0
- package/lib/integrations/hooks.mjs +171 -0
- package/lib/integrations/peers/identity.mjs +208 -0
- package/lib/integrations/peers/processes.mjs +151 -0
- package/lib/integrations/providers.mjs +282 -0
- package/lib/integrations/shims/script.mjs +384 -0
- package/lib/integrations/shims.mjs +106 -0
- package/lib/json-file.mjs +1 -0
- package/lib/locks.mjs +10 -0
- package/lib/messages.mjs +3 -0
- package/lib/package-meta.mjs +6 -24
- package/lib/peer-bindings.mjs +14 -0
- package/lib/peer-format.mjs +4 -0
- package/lib/peer-identity.mjs +15 -0
- package/lib/project-context.mjs +6 -0
- package/lib/project-registry.mjs +7 -0
- package/lib/provider-commands.mjs +13 -0
- package/lib/release/package-meta.mjs +31 -0
- package/lib/release/release-notes.mjs +40 -0
- package/lib/release-notes.mjs +6 -40
- package/lib/runtime/client.mjs +42 -0
- package/lib/runtime/paths.mjs +45 -0
- package/lib/runtime/project-context.mjs +32 -0
- package/lib/runtime/projects.mjs +76 -0
- package/lib/runtime/state.mjs +128 -0
- package/lib/runtime-client.mjs +3 -0
- package/lib/runtime-paths.mjs +11 -0
- package/lib/runtime-state.mjs +11 -0
- package/lib/session-launch.mjs +17 -0
- package/lib/setup.mjs +18 -765
- package/lib/shared/errors.mjs +7 -0
- package/lib/shared/json-file.mjs +14 -0
- package/lib/shell-path.mjs +69 -0
- package/lib/shim-script.mjs +1 -0
- package/lib/state-render.mjs +5 -0
- package/lib/task-cli.mjs +45 -0
- package/lib/task-liveness.mjs +8 -0
- package/lib/task-store.mjs +3 -0
- package/lib/team-planning.mjs +7 -0
- package/lib/terminal/tmux.mjs +372 -0
- package/lib/timeline.mjs +12 -0
- package/lib/tmux.mjs +18 -0
- package/lib/ui/help.mjs +419 -0
- package/lib/ui/state-render.mjs +61 -0
- package/lib/web/http.mjs +55 -0
- package/lib/web/peer-actions.mjs +270 -0
- package/lib/web/runtime.mjs +154 -0
- package/lib/web/ui-template.mjs +2055 -0
- package/lib/web-http.mjs +7 -0
- package/lib/web-peer-actions.mjs +3 -0
- package/lib/web-runtime.mjs +17 -0
- package/lib/web-ui-template.mjs +3 -0
- package/package.json +1 -1
- package/scripts/github-release.mjs +2 -2
- package/scripts/regression.mjs +2738 -22
- package/scripts/release-notes.mjs +2 -2
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { CliError } from '../shared/errors.mjs';
|
|
2
|
+
import { shellQuoteArg } from '../format.mjs';
|
|
3
|
+
import { providerSessionParts } from '../core/peers/session.mjs';
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
providerSessionParts,
|
|
7
|
+
providerSessionPeerId
|
|
8
|
+
} from '../core/peers/session.mjs';
|
|
9
|
+
|
|
10
|
+
function shellCommand(args) {
|
|
11
|
+
return args.map(shellQuoteArg).join(' ');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function inferPeerKind(id, explicitKind, firstCommand) {
|
|
15
|
+
if (explicitKind) return explicitKind;
|
|
16
|
+
if (['codex', 'claude'].includes(firstCommand)) return firstCommand;
|
|
17
|
+
if (String(id).startsWith('codex')) return 'codex';
|
|
18
|
+
if (String(id).startsWith('claude')) return 'claude';
|
|
19
|
+
return 'shell';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function hasResumeOpts(opts) {
|
|
23
|
+
return opts.resume !== undefined || Boolean(opts.last) || Boolean(opts.continue) || Boolean(opts.fork) || opts.session !== undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function defaultSessionCommand(kind) {
|
|
27
|
+
if (kind === 'codex') return 'codex';
|
|
28
|
+
if (kind === 'claude') return 'claude';
|
|
29
|
+
return process.env.SHELL || 'bash';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function buildPeerCommand(id, kind, opts, cmdArgs) {
|
|
33
|
+
const explicitCommand = opts.command || cmdArgs.length > 0;
|
|
34
|
+
if (explicitCommand && hasResumeOpts(opts)) {
|
|
35
|
+
throw new CliError('BAD_ARGS', 'Use resume options without an explicit -- COMMAND');
|
|
36
|
+
}
|
|
37
|
+
if (explicitCommand) {
|
|
38
|
+
const command = opts.command || shellCommand(cmdArgs);
|
|
39
|
+
return {
|
|
40
|
+
command,
|
|
41
|
+
binding: {
|
|
42
|
+
peer: id,
|
|
43
|
+
provider: kind,
|
|
44
|
+
resume_mode: 'command',
|
|
45
|
+
resume_arg: null,
|
|
46
|
+
command
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (kind === 'codex') return buildCodexCommand(id, opts);
|
|
51
|
+
if (kind === 'claude') return buildClaudeCommand(id, opts);
|
|
52
|
+
if (hasResumeOpts(opts)) throw new CliError('BAD_ARGS', `Resume options are only supported for codex and claude peers`);
|
|
53
|
+
const command = defaultSessionCommand(kind);
|
|
54
|
+
return {
|
|
55
|
+
command,
|
|
56
|
+
binding: {
|
|
57
|
+
peer: id,
|
|
58
|
+
provider: kind,
|
|
59
|
+
resume_mode: 'new',
|
|
60
|
+
resume_arg: null,
|
|
61
|
+
command
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function buildCodexCommand(id, opts) {
|
|
67
|
+
let command;
|
|
68
|
+
let resumeMode = 'new';
|
|
69
|
+
let resumeArg = null;
|
|
70
|
+
let session = { provider_session_id: null, provider_session_name: null };
|
|
71
|
+
if (opts.fork) {
|
|
72
|
+
resumeMode = opts.last ? 'fork-last' : 'fork';
|
|
73
|
+
if (opts.last) {
|
|
74
|
+
command = 'codex fork --last';
|
|
75
|
+
resumeArg = '--last';
|
|
76
|
+
} else if (opts.resume) {
|
|
77
|
+
command = `codex fork ${shellQuoteArg(opts.resume)}`;
|
|
78
|
+
resumeArg = opts.resume;
|
|
79
|
+
} else {
|
|
80
|
+
command = 'codex fork';
|
|
81
|
+
}
|
|
82
|
+
} else if (opts.last) {
|
|
83
|
+
command = 'codex resume --last';
|
|
84
|
+
resumeMode = 'last';
|
|
85
|
+
resumeArg = '--last';
|
|
86
|
+
} else if (opts.resume) {
|
|
87
|
+
command = `codex resume ${shellQuoteArg(opts.resume)}`;
|
|
88
|
+
resumeMode = 'resume';
|
|
89
|
+
resumeArg = opts.resume;
|
|
90
|
+
session = providerSessionParts(opts.resume);
|
|
91
|
+
} else {
|
|
92
|
+
command = 'codex';
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
command,
|
|
96
|
+
binding: {
|
|
97
|
+
peer: id,
|
|
98
|
+
provider: 'codex',
|
|
99
|
+
...session,
|
|
100
|
+
resume_mode: resumeMode,
|
|
101
|
+
resume_arg: resumeArg,
|
|
102
|
+
command
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function buildClaudeCommand(id, opts) {
|
|
108
|
+
let command = 'claude';
|
|
109
|
+
let resumeMode = 'new';
|
|
110
|
+
let resumeArg = null;
|
|
111
|
+
let session = { provider_session_id: null, provider_session_name: null };
|
|
112
|
+
if (opts.continue) {
|
|
113
|
+
command += ' --continue';
|
|
114
|
+
resumeMode = opts.fork ? 'fork-continue' : 'continue';
|
|
115
|
+
resumeArg = '--continue';
|
|
116
|
+
} else if (opts.resume) {
|
|
117
|
+
command += ` --resume ${shellQuoteArg(opts.resume)}`;
|
|
118
|
+
resumeMode = opts.fork ? 'fork-resume' : 'resume';
|
|
119
|
+
resumeArg = opts.resume;
|
|
120
|
+
if (!opts.fork) session = providerSessionParts(opts.resume);
|
|
121
|
+
} else if (opts.session) {
|
|
122
|
+
command += ` --session-id ${shellQuoteArg(opts.session)}`;
|
|
123
|
+
resumeMode = 'session';
|
|
124
|
+
resumeArg = opts.session;
|
|
125
|
+
session = { provider_session_id: opts.session, provider_session_name: null };
|
|
126
|
+
}
|
|
127
|
+
if (opts.fork && (opts.continue || opts.resume)) command += ' --fork-session';
|
|
128
|
+
if (opts.name) command += ` --name ${shellQuoteArg(opts.name)}`;
|
|
129
|
+
return {
|
|
130
|
+
command,
|
|
131
|
+
binding: {
|
|
132
|
+
peer: id,
|
|
133
|
+
provider: 'claude',
|
|
134
|
+
...session,
|
|
135
|
+
resume_mode: resumeMode,
|
|
136
|
+
resume_arg: resumeArg,
|
|
137
|
+
command
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function bindingFromRun(id, kind, command, commandArgs, transport) {
|
|
143
|
+
const cmdline = [command, ...commandArgs];
|
|
144
|
+
const provider = kind || 'other';
|
|
145
|
+
let resumeMode = 'command';
|
|
146
|
+
let resumeArg = null;
|
|
147
|
+
let session = { provider_session_id: null, provider_session_name: null };
|
|
148
|
+
if (provider === 'codex') {
|
|
149
|
+
const parsed = parseCodexCommandArgs(cmdline);
|
|
150
|
+
resumeMode = parsed.resume_mode;
|
|
151
|
+
resumeArg = parsed.resume_arg;
|
|
152
|
+
session = parsed.session;
|
|
153
|
+
} else if (provider === 'claude') {
|
|
154
|
+
const parsed = parseClaudeCommandArgs(cmdline);
|
|
155
|
+
resumeMode = parsed.resume_mode;
|
|
156
|
+
resumeArg = parsed.resume_arg;
|
|
157
|
+
session = parsed.session;
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
peer: id,
|
|
161
|
+
provider,
|
|
162
|
+
...session,
|
|
163
|
+
resume_mode: resumeMode,
|
|
164
|
+
resume_arg: resumeArg,
|
|
165
|
+
command: cmdline.join(' '),
|
|
166
|
+
transport,
|
|
167
|
+
runtime_session_id: id
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function optionValue(args, names) {
|
|
172
|
+
const nameSet = new Set(names);
|
|
173
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
174
|
+
const arg = args[i];
|
|
175
|
+
if (nameSet.has(arg) && args[i + 1]) return args[i + 1];
|
|
176
|
+
for (const name of names) {
|
|
177
|
+
if (name.startsWith('--') && arg.startsWith(`${name}=`)) return arg.slice(name.length + 1);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function hasFlag(args, names) {
|
|
184
|
+
const nameSet = new Set(names);
|
|
185
|
+
return args.some((arg) => nameSet.has(arg));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function parseClaudeCommandArgs(args) {
|
|
189
|
+
const resumeId = optionValue(args, ['--resume', '-r']);
|
|
190
|
+
const sessionId = optionValue(args, ['--session-id']);
|
|
191
|
+
const name = optionValue(args, ['--name', '-n']);
|
|
192
|
+
const continuing = hasFlag(args, ['--continue', '-c']);
|
|
193
|
+
const fork = hasFlag(args, ['--fork-session']);
|
|
194
|
+
let resumeMode = 'command';
|
|
195
|
+
let resumeArg = null;
|
|
196
|
+
let session = { provider_session_id: null, provider_session_name: null };
|
|
197
|
+
|
|
198
|
+
if (sessionId) {
|
|
199
|
+
resumeMode = 'session';
|
|
200
|
+
resumeArg = sessionId;
|
|
201
|
+
session = { provider_session_id: sessionId, provider_session_name: null };
|
|
202
|
+
} else if (resumeId) {
|
|
203
|
+
resumeMode = fork ? 'fork-resume' : 'resume';
|
|
204
|
+
resumeArg = resumeId;
|
|
205
|
+
if (!fork) session = providerSessionParts(resumeId);
|
|
206
|
+
} else if (continuing) {
|
|
207
|
+
resumeMode = fork ? 'fork-continue' : 'continue';
|
|
208
|
+
resumeArg = '--continue';
|
|
209
|
+
} else if (fork) {
|
|
210
|
+
resumeMode = 'fork';
|
|
211
|
+
} else if (name) {
|
|
212
|
+
resumeMode = 'named';
|
|
213
|
+
resumeArg = name;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return { resume_mode: resumeMode, resume_arg: resumeArg, session };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function codexOptionTakesValue(arg) {
|
|
220
|
+
if (!arg || arg.includes('=')) return false;
|
|
221
|
+
return new Set([
|
|
222
|
+
'-c', '--config',
|
|
223
|
+
'--remote',
|
|
224
|
+
'--remote-auth-token-env',
|
|
225
|
+
'--enable',
|
|
226
|
+
'--disable',
|
|
227
|
+
'-i', '--image',
|
|
228
|
+
'-m', '--model',
|
|
229
|
+
'--local-provider',
|
|
230
|
+
'-p', '--profile',
|
|
231
|
+
'-s', '--sandbox',
|
|
232
|
+
'-C', '--cd',
|
|
233
|
+
'--add-dir',
|
|
234
|
+
'-a', '--ask-for-approval'
|
|
235
|
+
]).has(arg);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function firstCodexSessionArg(args, startIndex) {
|
|
239
|
+
for (let i = startIndex; i < args.length; i += 1) {
|
|
240
|
+
const arg = args[i];
|
|
241
|
+
if (arg === '--last') continue;
|
|
242
|
+
if (arg.startsWith('-')) {
|
|
243
|
+
if (codexOptionTakesValue(arg)) i += 1;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
return arg;
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function parseCodexCommandArgs(args) {
|
|
252
|
+
const subIndex = args.findIndex((arg) => arg === 'resume' || arg === 'fork');
|
|
253
|
+
if (subIndex < 0) {
|
|
254
|
+
return {
|
|
255
|
+
resume_mode: 'command',
|
|
256
|
+
resume_arg: null,
|
|
257
|
+
session: { provider_session_id: null, provider_session_name: null }
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const subcommand = args[subIndex];
|
|
262
|
+
const last = args.slice(subIndex + 1).includes('--last');
|
|
263
|
+
const sessionArg = firstCodexSessionArg(args, subIndex + 1);
|
|
264
|
+
let resumeMode = subcommand;
|
|
265
|
+
let resumeArg = sessionArg || null;
|
|
266
|
+
let session = { provider_session_id: null, provider_session_name: null };
|
|
267
|
+
|
|
268
|
+
if (subcommand === 'resume') {
|
|
269
|
+
if (last && !sessionArg) {
|
|
270
|
+
resumeMode = 'last';
|
|
271
|
+
resumeArg = '--last';
|
|
272
|
+
} else if (sessionArg) {
|
|
273
|
+
resumeMode = 'resume';
|
|
274
|
+
session = providerSessionParts(sessionArg);
|
|
275
|
+
}
|
|
276
|
+
} else if (subcommand === 'fork') {
|
|
277
|
+
resumeMode = last && !sessionArg ? 'fork-last' : 'fork';
|
|
278
|
+
resumeArg = sessionArg || (last ? '--last' : null);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return { resume_mode: resumeMode, resume_arg: resumeArg, session };
|
|
282
|
+
}
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
export function generateShim(hccBin, realBin, tool) {
|
|
2
|
+
if (tool.resumeFlag) {
|
|
3
|
+
// Claude: --resume/--continue/--session-id/--fork-session aware wrapper.
|
|
4
|
+
return `#!/usr/bin/env bash
|
|
5
|
+
# hello-cc shim for ${tool.name} (auto-generated; do not edit manually)
|
|
6
|
+
# Wraps ${tool.name} with hello-cc peer mesh integration.
|
|
7
|
+
# Real binary: ${realBin}
|
|
8
|
+
|
|
9
|
+
set -e
|
|
10
|
+
REAL_BIN="${realBin}"
|
|
11
|
+
HCC_BIN="${hccBin}"
|
|
12
|
+
|
|
13
|
+
if [ "\${HCC_SHIM_ENSURED:-}" != "1" ]; then
|
|
14
|
+
set +e
|
|
15
|
+
"$HCC_BIN" shim ensure "${tool.name}" "$0" >/dev/null 2>&1
|
|
16
|
+
ENSURE_STATUS=$?
|
|
17
|
+
set -e
|
|
18
|
+
if [ "$ENSURE_STATUS" = "75" ]; then
|
|
19
|
+
export HCC_SHIM_ENSURED=1
|
|
20
|
+
exec "$0" "$@"
|
|
21
|
+
fi
|
|
22
|
+
fi
|
|
23
|
+
|
|
24
|
+
should_passthrough() {
|
|
25
|
+
for arg in "$@"; do
|
|
26
|
+
case "$arg" in
|
|
27
|
+
-h|--help|-v|--version|-p|--print|--bare|--safe-mode)
|
|
28
|
+
return 0
|
|
29
|
+
;;
|
|
30
|
+
esac
|
|
31
|
+
done
|
|
32
|
+
|
|
33
|
+
case "\${1:-}" in
|
|
34
|
+
agents|auth|auto-mode|doctor|install|mcp|plugin|plugins|project|setup-token|ultrareview|update|upgrade)
|
|
35
|
+
return 0
|
|
36
|
+
;;
|
|
37
|
+
esac
|
|
38
|
+
|
|
39
|
+
return 1
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if should_passthrough "$@"; then
|
|
43
|
+
exec "$REAL_BIN" "$@"
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
# Use the current directory as the hello-cc project root unless HCC_ROOT is set.
|
|
47
|
+
HCC_ROOT=$("$HCC_BIN" find-root 2>/dev/null || true)
|
|
48
|
+
|
|
49
|
+
if [ -z "$HCC_ROOT" ]; then
|
|
50
|
+
exec "$REAL_BIN" "$@"
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
sanitize_peer_part() {
|
|
54
|
+
printf '%s' "$1" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9._-]/-/g; s/^-*//; s/-*$//' | cut -c 1-32
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
tty_peer_part() {
|
|
58
|
+
TTY_NUM=$(tty 2>/dev/null | tr -dc '0-9' | tail -c 4)
|
|
59
|
+
PARENT_PID="\${PPID:-$$}"
|
|
60
|
+
if [ -n "$TTY_NUM" ]; then
|
|
61
|
+
printf '%s-%s' "$TTY_NUM" "$PARENT_PID"
|
|
62
|
+
else
|
|
63
|
+
printf '%s' "$PARENT_PID"
|
|
64
|
+
fi
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
RESUME_ID=""
|
|
68
|
+
SESSION_ID=""
|
|
69
|
+
SESSION_NAME=""
|
|
70
|
+
IS_CONTINUE=0
|
|
71
|
+
IS_FORK=0
|
|
72
|
+
PREV_ARG=""
|
|
73
|
+
for arg in "$@"; do
|
|
74
|
+
case "$PREV_ARG" in
|
|
75
|
+
--resume|-r) RESUME_ID="$arg" ;;
|
|
76
|
+
--session-id) SESSION_ID="$arg" ;;
|
|
77
|
+
--name|-n) SESSION_NAME="$arg" ;;
|
|
78
|
+
esac
|
|
79
|
+
case "$arg" in
|
|
80
|
+
--resume=*) RESUME_ID="\${arg#--resume=}" ;;
|
|
81
|
+
--session-id=*) SESSION_ID="\${arg#--session-id=}" ;;
|
|
82
|
+
--name=*) SESSION_NAME="\${arg#--name=}" ;;
|
|
83
|
+
--continue|-c) IS_CONTINUE=1 ;;
|
|
84
|
+
--fork-session) IS_FORK=1 ;;
|
|
85
|
+
esac
|
|
86
|
+
PREV_ARG="$arg"
|
|
87
|
+
done
|
|
88
|
+
|
|
89
|
+
if [ -n "$HCC_PEER" ]; then
|
|
90
|
+
PEER_ID="$HCC_PEER"
|
|
91
|
+
elif [ -n "$SESSION_ID" ]; then
|
|
92
|
+
PEER_ID="${tool.kind}-\$(sanitize_peer_part "\${SESSION_ID:0:8}")"
|
|
93
|
+
elif [ -n "$RESUME_ID" ] && [ "$IS_FORK" != "1" ]; then
|
|
94
|
+
PEER_ID="${tool.kind}-\$(sanitize_peer_part "\${RESUME_ID:0:8}")"
|
|
95
|
+
elif [ -n "$CLAUDE_CODE_SESSION_ID" ]; then
|
|
96
|
+
PEER_ID="${tool.kind}-\$(sanitize_peer_part "\${CLAUDE_CODE_SESSION_ID:0:8}")"
|
|
97
|
+
elif [ -n "$SESSION_NAME" ] && [ "$IS_FORK" != "1" ] && [ "$IS_CONTINUE" != "1" ]; then
|
|
98
|
+
PEER_ID="${tool.kind}-\$(sanitize_peer_part "$SESSION_NAME")"
|
|
99
|
+
else
|
|
100
|
+
PEER_ID="${tool.kind}-\$(tty_peer_part)"
|
|
101
|
+
fi
|
|
102
|
+
|
|
103
|
+
export HCC_PEER="$PEER_ID"
|
|
104
|
+
export HCC_ROOT
|
|
105
|
+
|
|
106
|
+
current_tmux_pane() {
|
|
107
|
+
if [ -n "\${TMUX_PANE:-}" ]; then
|
|
108
|
+
printf '%s\\n' "$TMUX_PANE"
|
|
109
|
+
return 0
|
|
110
|
+
fi
|
|
111
|
+
TTY_PATH=$(tty 2>/dev/null || true)
|
|
112
|
+
if [ -z "$TTY_PATH" ] || [ "$TTY_PATH" = "not a tty" ]; then
|
|
113
|
+
return 1
|
|
114
|
+
fi
|
|
115
|
+
tmux list-panes -a -F '#{pane_id} #{pane_tty}' 2>/dev/null | awk -v tty="$TTY_PATH" '$2 == tty { print $1; found = 1; exit } END { exit found ? 0 : 1 }'
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
CURRENT_HCC_PANE=""
|
|
119
|
+
CURRENT_HCC_SESSION=""
|
|
120
|
+
detect_current_hcc_pane() {
|
|
121
|
+
CURRENT_HCC_SESSION=""
|
|
122
|
+
CURRENT_HCC_PANE=$(current_tmux_pane || true)
|
|
123
|
+
if [ -z "$CURRENT_HCC_PANE" ]; then
|
|
124
|
+
return 1
|
|
125
|
+
fi
|
|
126
|
+
CURRENT_HCC_SESSION=$(tmux display-message -p -t "$CURRENT_HCC_PANE" '#S' 2>/dev/null || true)
|
|
127
|
+
case "$CURRENT_HCC_SESSION" in
|
|
128
|
+
hcc-*-*) return 0 ;;
|
|
129
|
+
esac
|
|
130
|
+
CURRENT_HCC_PANE=""
|
|
131
|
+
CURRENT_HCC_SESSION=""
|
|
132
|
+
return 1
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if detect_current_hcc_pane; then
|
|
136
|
+
SESSION_PEER_ID=$(printf '%s' "$CURRENT_HCC_SESSION" | sed 's/^hcc-[^-]*-//')
|
|
137
|
+
if [ -n "$SESSION_PEER_ID" ] && [ "$SESSION_PEER_ID" != "$CURRENT_HCC_SESSION" ]; then
|
|
138
|
+
PEER_ID="$SESSION_PEER_ID"
|
|
139
|
+
fi
|
|
140
|
+
export HCC_PEER="$PEER_ID"
|
|
141
|
+
"$HCC_BIN" web >/dev/null 2>&1 || true
|
|
142
|
+
"$HCC_BIN" peer attach "$PEER_ID" --kind "${tool.kind}" --pane "$CURRENT_HCC_PANE" --cwd "$PWD" --force >/dev/null 2>&1 || true
|
|
143
|
+
exec "$REAL_BIN" "$@"
|
|
144
|
+
fi
|
|
145
|
+
|
|
146
|
+
set +e
|
|
147
|
+
# Wrap in shell so pane_pid stays as bash; Ctrl+C drops back to bash
|
|
148
|
+
START_OUT=$("$HCC_BIN" web >/dev/null 2>&1 || true; "$HCC_BIN" peer start "$PEER_ID" --kind "${tool.kind}" --restart-env -- bash -lc 'REAL_BIN="$1"; shift; hcc_provider_state() { HCC_TMUX_SESSION=$(tmux display-message -p "#S" 2>/dev/null || true); if [ -n "$HCC_TMUX_SESSION" ]; then tmux set-environment -t "$HCC_TMUX_SESSION" HCC_PROVIDER_STATE "$1" >/dev/null 2>&1 || true; fi; }; hcc_provider_state running; "$REAL_BIN" "$@"; hcc_provider_state exited; exec bash' _ "$REAL_BIN" "$@" 2>&1)
|
|
149
|
+
START_STATUS=$?
|
|
150
|
+
set -e
|
|
151
|
+
if [ "$START_STATUS" -ne 0 ]; then
|
|
152
|
+
printf '%s\\n' "$START_OUT" >&2
|
|
153
|
+
exit "$START_STATUS"
|
|
154
|
+
fi
|
|
155
|
+
|
|
156
|
+
PANE=$(printf '%s\\n' "$START_OUT" | sed -n 's/.*pane=\\(%[0-9][0-9]*\\).*/\\1/p' | tail -n 1)
|
|
157
|
+
if [ -z "$PANE" ]; then
|
|
158
|
+
printf '%s\\n' "$START_OUT"
|
|
159
|
+
exit 0
|
|
160
|
+
fi
|
|
161
|
+
|
|
162
|
+
if [ "$HCC_SHIM_NO_ATTACH" = "1" ] || [ ! -t 0 ]; then
|
|
163
|
+
printf '%s\\n' "$START_OUT"
|
|
164
|
+
exit 0
|
|
165
|
+
fi
|
|
166
|
+
|
|
167
|
+
SESSION=$(tmux display-message -p -t "$PANE" '#S' 2>/dev/null || true)
|
|
168
|
+
if [ -z "$SESSION" ]; then
|
|
169
|
+
printf '%s\\n' "$START_OUT"
|
|
170
|
+
exit 0
|
|
171
|
+
fi
|
|
172
|
+
|
|
173
|
+
if [ -n "$TMUX" ]; then
|
|
174
|
+
exec tmux switch-client -t "$SESSION"
|
|
175
|
+
fi
|
|
176
|
+
|
|
177
|
+
exec tmux attach-session -t "$SESSION"
|
|
178
|
+
`;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Codex: resume/fork subcommand aware wrapper.
|
|
182
|
+
return `#!/usr/bin/env bash
|
|
183
|
+
# hello-cc shim for ${tool.name} (auto-generated; do not edit manually)
|
|
184
|
+
# Wraps ${tool.name} with hello-cc peer mesh integration.
|
|
185
|
+
# Real binary: ${realBin}
|
|
186
|
+
|
|
187
|
+
set -e
|
|
188
|
+
REAL_BIN="${realBin}"
|
|
189
|
+
HCC_BIN="${hccBin}"
|
|
190
|
+
|
|
191
|
+
if [ "\${HCC_SHIM_ENSURED:-}" != "1" ]; then
|
|
192
|
+
set +e
|
|
193
|
+
"$HCC_BIN" shim ensure "${tool.name}" "$0" >/dev/null 2>&1
|
|
194
|
+
ENSURE_STATUS=$?
|
|
195
|
+
set -e
|
|
196
|
+
if [ "$ENSURE_STATUS" = "75" ]; then
|
|
197
|
+
export HCC_SHIM_ENSURED=1
|
|
198
|
+
exec "$0" "$@"
|
|
199
|
+
fi
|
|
200
|
+
fi
|
|
201
|
+
|
|
202
|
+
first_non_option() {
|
|
203
|
+
EXPECT_VALUE=0
|
|
204
|
+
for arg in "$@"; do
|
|
205
|
+
if [ "$EXPECT_VALUE" = "1" ]; then
|
|
206
|
+
EXPECT_VALUE=0
|
|
207
|
+
continue
|
|
208
|
+
fi
|
|
209
|
+
|
|
210
|
+
case "$arg" in
|
|
211
|
+
--)
|
|
212
|
+
EXPECT_VALUE=0
|
|
213
|
+
continue
|
|
214
|
+
;;
|
|
215
|
+
-c|--config|-i|--image|-m|--model|-p|--profile|-s|--sandbox|-C|--cd|--add-dir|-a|--ask-for-approval|--remote|--remote-auth-token-env)
|
|
216
|
+
EXPECT_VALUE=1
|
|
217
|
+
continue
|
|
218
|
+
;;
|
|
219
|
+
--config=*|--image=*|--model=*|--profile=*|--sandbox=*|--cd=*|--add-dir=*|--ask-for-approval=*|--remote=*|--remote-auth-token-env=*)
|
|
220
|
+
continue
|
|
221
|
+
;;
|
|
222
|
+
--*)
|
|
223
|
+
continue
|
|
224
|
+
;;
|
|
225
|
+
-*)
|
|
226
|
+
continue
|
|
227
|
+
;;
|
|
228
|
+
*)
|
|
229
|
+
printf '%s' "$arg"
|
|
230
|
+
return 0
|
|
231
|
+
;;
|
|
232
|
+
esac
|
|
233
|
+
done
|
|
234
|
+
return 1
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
should_passthrough() {
|
|
238
|
+
for arg in "$@"; do
|
|
239
|
+
case "$arg" in
|
|
240
|
+
-h|--help|-V|--version)
|
|
241
|
+
return 0
|
|
242
|
+
;;
|
|
243
|
+
esac
|
|
244
|
+
done
|
|
245
|
+
|
|
246
|
+
SUBCOMMAND=$(first_non_option "$@" || true)
|
|
247
|
+
case "$SUBCOMMAND" in
|
|
248
|
+
help|exec|e|review|login|logout|mcp|plugin|mcp-server|app-server|remote-control|completion|update|doctor|sandbox|debug|apply|a|archive|unarchive|cloud|exec-server|features)
|
|
249
|
+
return 0
|
|
250
|
+
;;
|
|
251
|
+
esac
|
|
252
|
+
|
|
253
|
+
return 1
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if should_passthrough "$@"; then
|
|
257
|
+
exec "$REAL_BIN" "$@"
|
|
258
|
+
fi
|
|
259
|
+
|
|
260
|
+
HCC_ROOT=$("$HCC_BIN" find-root 2>/dev/null || true)
|
|
261
|
+
|
|
262
|
+
if [ -z "$HCC_ROOT" ]; then
|
|
263
|
+
exec "$REAL_BIN" "$@"
|
|
264
|
+
fi
|
|
265
|
+
|
|
266
|
+
sanitize_peer_part() {
|
|
267
|
+
printf '%s' "$1" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9._-]/-/g; s/^-*//; s/-*$//' | cut -c 1-32
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
tty_peer_part() {
|
|
271
|
+
TTY_NUM=$(tty 2>/dev/null | tr -dc '0-9' | tail -c 4)
|
|
272
|
+
PARENT_PID="\${PPID:-$$}"
|
|
273
|
+
if [ -n "$TTY_NUM" ]; then
|
|
274
|
+
printf '%s-%s' "$TTY_NUM" "$PARENT_PID"
|
|
275
|
+
else
|
|
276
|
+
printf '%s' "$PARENT_PID"
|
|
277
|
+
fi
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
SUBCMD=""
|
|
281
|
+
RESUME_ID=""
|
|
282
|
+
EXPECT_SESSION=0
|
|
283
|
+
for arg in "$@"; do
|
|
284
|
+
if [ -z "$SUBCMD" ]; then
|
|
285
|
+
if [ "$arg" = "resume" ] || [ "$arg" = "fork" ]; then
|
|
286
|
+
SUBCMD="$arg"
|
|
287
|
+
EXPECT_SESSION=1
|
|
288
|
+
fi
|
|
289
|
+
continue
|
|
290
|
+
fi
|
|
291
|
+
if [ "$EXPECT_SESSION" = "1" ]; then
|
|
292
|
+
case "$arg" in
|
|
293
|
+
--last) EXPECT_SESSION=0 ;;
|
|
294
|
+
-*) ;;
|
|
295
|
+
*) RESUME_ID="$arg"; EXPECT_SESSION=0 ;;
|
|
296
|
+
esac
|
|
297
|
+
fi
|
|
298
|
+
done
|
|
299
|
+
|
|
300
|
+
if [ -n "$HCC_PEER" ]; then
|
|
301
|
+
PEER_ID="$HCC_PEER"
|
|
302
|
+
elif [ "$SUBCMD" = "resume" ] && [ -n "$RESUME_ID" ]; then
|
|
303
|
+
PEER_ID="${tool.kind}-\$(sanitize_peer_part "\${RESUME_ID:0:8}")"
|
|
304
|
+
else
|
|
305
|
+
PEER_ID="${tool.kind}-\$(tty_peer_part)"
|
|
306
|
+
fi
|
|
307
|
+
|
|
308
|
+
export HCC_PEER="$PEER_ID"
|
|
309
|
+
export HCC_ROOT
|
|
310
|
+
|
|
311
|
+
current_tmux_pane() {
|
|
312
|
+
if [ -n "\${TMUX_PANE:-}" ]; then
|
|
313
|
+
printf '%s\\n' "$TMUX_PANE"
|
|
314
|
+
return 0
|
|
315
|
+
fi
|
|
316
|
+
TTY_PATH=$(tty 2>/dev/null || true)
|
|
317
|
+
if [ -z "$TTY_PATH" ] || [ "$TTY_PATH" = "not a tty" ]; then
|
|
318
|
+
return 1
|
|
319
|
+
fi
|
|
320
|
+
tmux list-panes -a -F '#{pane_id} #{pane_tty}' 2>/dev/null | awk -v tty="$TTY_PATH" '$2 == tty { print $1; found = 1; exit } END { exit found ? 0 : 1 }'
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
CURRENT_HCC_PANE=""
|
|
324
|
+
CURRENT_HCC_SESSION=""
|
|
325
|
+
detect_current_hcc_pane() {
|
|
326
|
+
CURRENT_HCC_SESSION=""
|
|
327
|
+
CURRENT_HCC_PANE=$(current_tmux_pane || true)
|
|
328
|
+
if [ -z "$CURRENT_HCC_PANE" ]; then
|
|
329
|
+
return 1
|
|
330
|
+
fi
|
|
331
|
+
CURRENT_HCC_SESSION=$(tmux display-message -p -t "$CURRENT_HCC_PANE" '#S' 2>/dev/null || true)
|
|
332
|
+
case "$CURRENT_HCC_SESSION" in
|
|
333
|
+
hcc-*-*) return 0 ;;
|
|
334
|
+
esac
|
|
335
|
+
CURRENT_HCC_PANE=""
|
|
336
|
+
CURRENT_HCC_SESSION=""
|
|
337
|
+
return 1
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if detect_current_hcc_pane; then
|
|
341
|
+
SESSION_PEER_ID=$(printf '%s' "$CURRENT_HCC_SESSION" | sed 's/^hcc-[^-]*-//')
|
|
342
|
+
if [ -n "$SESSION_PEER_ID" ] && [ "$SESSION_PEER_ID" != "$CURRENT_HCC_SESSION" ]; then
|
|
343
|
+
PEER_ID="$SESSION_PEER_ID"
|
|
344
|
+
fi
|
|
345
|
+
export HCC_PEER="$PEER_ID"
|
|
346
|
+
"$HCC_BIN" web >/dev/null 2>&1 || true
|
|
347
|
+
"$HCC_BIN" peer attach "$PEER_ID" --kind "${tool.kind}" --pane "$CURRENT_HCC_PANE" --cwd "$PWD" --force >/dev/null 2>&1 || true
|
|
348
|
+
exec "$REAL_BIN" "$@"
|
|
349
|
+
fi
|
|
350
|
+
|
|
351
|
+
set +e
|
|
352
|
+
# Wrap in shell so pane_pid stays as bash; Ctrl+C drops back to bash
|
|
353
|
+
START_OUT=$("$HCC_BIN" web >/dev/null 2>&1 || true; "$HCC_BIN" peer start "$PEER_ID" --kind "${tool.kind}" --restart-env -- bash -lc 'REAL_BIN="$1"; shift; hcc_provider_state() { HCC_TMUX_SESSION=$(tmux display-message -p "#S" 2>/dev/null || true); if [ -n "$HCC_TMUX_SESSION" ]; then tmux set-environment -t "$HCC_TMUX_SESSION" HCC_PROVIDER_STATE "$1" >/dev/null 2>&1 || true; fi; }; hcc_provider_state running; "$REAL_BIN" "$@"; hcc_provider_state exited; exec bash' _ "$REAL_BIN" "$@" 2>&1)
|
|
354
|
+
START_STATUS=$?
|
|
355
|
+
set -e
|
|
356
|
+
if [ "$START_STATUS" -ne 0 ]; then
|
|
357
|
+
printf '%s\\n' "$START_OUT" >&2
|
|
358
|
+
exit "$START_STATUS"
|
|
359
|
+
fi
|
|
360
|
+
|
|
361
|
+
PANE=$(printf '%s\\n' "$START_OUT" | sed -n 's/.*pane=\\(%[0-9][0-9]*\\).*/\\1/p' | tail -n 1)
|
|
362
|
+
if [ -z "$PANE" ]; then
|
|
363
|
+
printf '%s\\n' "$START_OUT"
|
|
364
|
+
exit 0
|
|
365
|
+
fi
|
|
366
|
+
|
|
367
|
+
if [ "$HCC_SHIM_NO_ATTACH" = "1" ] || [ ! -t 0 ]; then
|
|
368
|
+
printf '%s\\n' "$START_OUT"
|
|
369
|
+
exit 0
|
|
370
|
+
fi
|
|
371
|
+
|
|
372
|
+
SESSION=$(tmux display-message -p -t "$PANE" '#S' 2>/dev/null || true)
|
|
373
|
+
if [ -z "$SESSION" ]; then
|
|
374
|
+
printf '%s\\n' "$START_OUT"
|
|
375
|
+
exit 0
|
|
376
|
+
fi
|
|
377
|
+
|
|
378
|
+
if [ -n "$TMUX" ]; then
|
|
379
|
+
exec tmux switch-client -t "$SESSION"
|
|
380
|
+
fi
|
|
381
|
+
|
|
382
|
+
exec tmux attach-session -t "$SESSION"
|
|
383
|
+
`;
|
|
384
|
+
}
|