@gajae-code/coding-agent 0.7.2 → 0.7.4
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 +86 -0
- package/bin/gjc.js +4 -0
- package/dist/types/cli/mcp-cli.d.ts +25 -0
- package/dist/types/cli/plugin-cli.d.ts +2 -0
- package/dist/types/cli.d.ts +6 -0
- package/dist/types/commands/mcp.d.ts +70 -0
- package/dist/types/commands/plugin.d.ts +6 -0
- package/dist/types/commands/session.d.ts +6 -0
- package/dist/types/config/keybindings.d.ts +2 -2
- package/dist/types/config/model-profile-activation.d.ts +8 -1
- package/dist/types/deep-interview/plaintext-gate-guard.d.ts +11 -0
- package/dist/types/extensibility/gjc-plugins/compiler.d.ts +19 -0
- package/dist/types/extensibility/gjc-plugins/constrained-hooks.d.ts +29 -0
- package/dist/types/extensibility/gjc-plugins/index.d.ts +9 -0
- package/dist/types/extensibility/gjc-plugins/injection.d.ts +9 -0
- package/dist/types/extensibility/gjc-plugins/installer.d.ts +13 -0
- package/dist/types/extensibility/gjc-plugins/mcp-policy.d.ts +26 -0
- package/dist/types/extensibility/gjc-plugins/observability.d.ts +27 -0
- package/dist/types/extensibility/gjc-plugins/prompt-appendix.d.ts +16 -0
- package/dist/types/extensibility/gjc-plugins/registry.d.ts +32 -0
- package/dist/types/extensibility/gjc-plugins/runtime-adapters.d.ts +64 -0
- package/dist/types/extensibility/gjc-plugins/session-validation.d.ts +42 -0
- package/dist/types/extensibility/gjc-plugins/types.d.ts +158 -2
- package/dist/types/extensibility/gjc-plugins/validation.d.ts +8 -1
- package/dist/types/gjc-runtime/launch-tmux.d.ts +1 -0
- package/dist/types/gjc-runtime/psmux-detect.d.ts +78 -0
- package/dist/types/gjc-runtime/team-runtime.d.ts +2 -0
- package/dist/types/gjc-runtime/tmux-common.d.ts +20 -1
- package/dist/types/gjc-runtime/tmux-sessions.d.ts +18 -0
- package/dist/types/main.d.ts +2 -0
- package/dist/types/modes/components/custom-editor.d.ts +1 -1
- package/dist/types/modes/components/model-selector.d.ts +8 -0
- package/dist/types/modes/components/status-line/git-utils.d.ts +6 -0
- package/dist/types/modes/theme/defaults/index.d.ts +99 -0
- package/dist/types/notifications/html-format.d.ts +11 -0
- package/dist/types/notifications/index.d.ts +149 -1
- package/dist/types/notifications/lifecycle-commands.d.ts +72 -0
- package/dist/types/notifications/lifecycle-control-runtime.d.ts +98 -0
- package/dist/types/notifications/lifecycle-orchestrator.d.ts +144 -0
- package/dist/types/notifications/operator-runtime.d.ts +52 -0
- package/dist/types/notifications/rate-limit-pool.d.ts +2 -0
- package/dist/types/notifications/recent-activity.d.ts +35 -0
- package/dist/types/notifications/telegram-daemon.d.ts +114 -16
- package/dist/types/notifications/telegram-reference.d.ts +3 -1
- package/dist/types/notifications/topic-registry.d.ts +12 -9
- package/dist/types/runtime-mcp/types.d.ts +7 -0
- package/dist/types/sdk.d.ts +2 -0
- package/dist/types/session/agent-session.d.ts +14 -4
- package/dist/types/session/blob-store.d.ts +25 -0
- package/dist/types/session/session-manager.d.ts +57 -0
- package/dist/types/slash-commands/helpers/fast-status-report.d.ts +6 -0
- package/dist/types/system-prompt.d.ts +2 -0
- package/dist/types/task/executor.d.ts +9 -1
- package/dist/types/tools/composer-bash-policy.d.ts +14 -0
- package/dist/types/tools/index.d.ts +3 -1
- package/dist/types/utils/changelog.d.ts +1 -0
- package/dist/types/web/insane/url-guard.d.ts +6 -3
- package/dist/types/web/scrapers/types.d.ts +5 -0
- package/dist/types/web/scrapers/utils.d.ts +7 -1
- package/package.json +11 -9
- package/scripts/g004-tmux-smoke.ts +100 -0
- package/scripts/g005-daemon-smoke.ts +181 -0
- package/scripts/g011-daemon-path-smoke.ts +153 -0
- package/src/cli/mcp-cli.ts +272 -0
- package/src/cli/plugin-cli.ts +66 -3
- package/src/cli.ts +27 -6
- package/src/commands/mcp.ts +117 -0
- package/src/commands/plugin.ts +4 -0
- package/src/commands/session.ts +18 -0
- package/src/config/keybindings.ts +2 -2
- package/src/config/model-profile-activation.ts +55 -7
- package/src/deep-interview/plaintext-gate-guard.ts +94 -0
- package/src/defaults/gjc/extensions/grok-cli-vendor/biome.json +1 -1
- package/src/defaults/gjc/skills/deep-interview/SKILL.md +7 -6
- package/src/defaults/gjc/skills/team/SKILL.md +5 -3
- package/src/defaults/gjc/skills/ultragoal/SKILL.md +41 -13
- package/src/export/html/index.ts +2 -2
- package/src/extensibility/extensions/runner.ts +1 -0
- package/src/extensibility/gjc-plugins/compiler.ts +351 -0
- package/src/extensibility/gjc-plugins/constrained-hooks.ts +170 -0
- package/src/extensibility/gjc-plugins/index.ts +9 -0
- package/src/extensibility/gjc-plugins/injection.ts +109 -0
- package/src/extensibility/gjc-plugins/installer.ts +434 -0
- package/src/extensibility/gjc-plugins/loader.ts +3 -1
- package/src/extensibility/gjc-plugins/mcp-policy.ts +239 -0
- package/src/extensibility/gjc-plugins/observability.ts +84 -0
- package/src/extensibility/gjc-plugins/paths.ts +1 -1
- package/src/extensibility/gjc-plugins/prompt-appendix.ts +109 -0
- package/src/extensibility/gjc-plugins/registry.ts +180 -0
- package/src/extensibility/gjc-plugins/runtime-adapters.ts +234 -0
- package/src/extensibility/gjc-plugins/schema.ts +250 -20
- package/src/extensibility/gjc-plugins/session-validation.ts +147 -0
- package/src/extensibility/gjc-plugins/types.ts +199 -3
- package/src/extensibility/gjc-plugins/validation.ts +80 -0
- package/src/extensibility/skills.ts +15 -0
- package/src/gjc-runtime/launch-tmux.ts +61 -7
- package/src/gjc-runtime/psmux-detect.ts +239 -0
- package/src/gjc-runtime/team-runtime.ts +56 -23
- package/src/gjc-runtime/tmux-common.ts +30 -3
- package/src/gjc-runtime/tmux-sessions.ts +51 -1
- package/src/gjc-runtime/ultragoal-guard.ts +25 -8
- package/src/gjc-runtime/ultragoal-runtime.ts +75 -15
- package/src/hooks/skill-state.ts +57 -0
- package/src/internal-urls/docs-index.generated.ts +12 -8
- package/src/main.ts +14 -3
- package/src/modes/bridge/bridge-mode.ts +11 -0
- package/src/modes/components/custom-editor.ts +2 -0
- package/src/modes/components/footer.ts +2 -3
- package/src/modes/components/hook-editor.ts +1 -1
- package/src/modes/components/hook-selector.ts +67 -43
- package/src/modes/components/model-selector.ts +56 -11
- package/src/modes/components/status-line/git-utils.ts +25 -0
- package/src/modes/components/status-line.ts +10 -11
- package/src/modes/components/welcome.ts +2 -3
- package/src/modes/controllers/extension-ui-controller.ts +0 -27
- package/src/modes/controllers/selector-controller.ts +53 -11
- package/src/modes/interactive-mode.ts +4 -1
- package/src/modes/shared/agent-wire/scopes.ts +1 -1
- package/src/modes/theme/defaults/gruvbox-dark.json +99 -0
- package/src/modes/theme/defaults/index.ts +2 -0
- package/src/modes/utils/hotkeys-markdown.ts +1 -1
- package/src/notifications/html-format.ts +38 -0
- package/src/notifications/index.ts +242 -12
- package/src/notifications/lifecycle-commands.ts +228 -0
- package/src/notifications/lifecycle-control-runtime.ts +400 -0
- package/src/notifications/lifecycle-orchestrator.ts +358 -0
- package/src/notifications/operator-runtime.ts +171 -0
- package/src/notifications/rate-limit-pool.ts +19 -0
- package/src/notifications/recent-activity.ts +132 -0
- package/src/notifications/telegram-daemon.ts +778 -257
- package/src/notifications/telegram-reference.ts +25 -7
- package/src/notifications/topic-registry.ts +23 -9
- package/src/prompts/agents/executor.md +2 -2
- package/src/runtime-mcp/transports/stdio.ts +38 -4
- package/src/runtime-mcp/types.ts +7 -0
- package/src/sdk.ts +157 -10
- package/src/session/agent-session.ts +166 -74
- package/src/session/blob-store.ts +196 -8
- package/src/session/session-manager.ts +678 -7
- package/src/slash-commands/builtin-registry.ts +23 -3
- package/src/slash-commands/helpers/fast-status-report.ts +13 -3
- package/src/slash-commands/helpers/parse.ts +2 -1
- package/src/system-prompt.ts +9 -0
- package/src/task/executor.ts +31 -7
- package/src/task/index.ts +2 -0
- package/src/tools/ask.ts +5 -1
- package/src/tools/bash.ts +9 -0
- package/src/tools/composer-bash-policy.ts +96 -0
- package/src/tools/fetch.ts +18 -2
- package/src/tools/index.ts +3 -1
- package/src/utils/changelog.ts +8 -0
- package/src/web/insane/url-guard.ts +18 -14
- package/src/web/scrapers/types.ts +143 -45
- package/src/web/scrapers/utils.ts +70 -19
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { isKnownWorkflowState } from "../../gjc-runtime/workflow-manifest";
|
|
2
2
|
import type { CanonicalGjcWorkflowSkill } from "../../skill-state/active-state";
|
|
3
|
+
import { assertMcpInstallPolicy } from "./mcp-policy";
|
|
3
4
|
import {
|
|
4
5
|
GJC_AGENT_SUBSKILL_PHASES,
|
|
5
6
|
GJC_SUBSKILL_PARENT_AGENTS,
|
|
6
7
|
GJC_SUBSKILL_PARENT_SKILLS,
|
|
7
8
|
GjcPluginLoadError,
|
|
9
|
+
type GjcPluginRegistryEntry,
|
|
8
10
|
type GjcSubskillParentAgent,
|
|
9
11
|
type LoadedSubskillBinding,
|
|
12
|
+
type NormalizedGjcPluginBundle,
|
|
10
13
|
type SubskillFrontmatter,
|
|
11
14
|
} from "./types";
|
|
12
15
|
|
|
@@ -74,3 +77,80 @@ export function buildParentPhaseSet(bindings: readonly LoadedSubskillBinding[]):
|
|
|
74
77
|
}
|
|
75
78
|
return new Set(seen.keys());
|
|
76
79
|
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Hard install-time collision + security validation for a compiled bundle
|
|
83
|
+
* against the effective installed registry (other plugins in the target scope
|
|
84
|
+
* universe). Collisions are hard errors; the registry is the collision
|
|
85
|
+
* authority, never capability first-wins.
|
|
86
|
+
*/
|
|
87
|
+
export function validateInstallPlan(
|
|
88
|
+
bundle: NormalizedGjcPluginBundle,
|
|
89
|
+
effectiveEntries: readonly GjcPluginRegistryEntry[],
|
|
90
|
+
): void {
|
|
91
|
+
const others = effectiveEntries.filter(e => e.name !== bundle.name);
|
|
92
|
+
|
|
93
|
+
const toolNames = new Set<string>();
|
|
94
|
+
const hookKeys = new Set<string>();
|
|
95
|
+
const mcpNames = new Set<string>();
|
|
96
|
+
const appendixIds = new Set<string>();
|
|
97
|
+
const subskillArgs = new Set<string>();
|
|
98
|
+
const parentPhases = new Set<string>();
|
|
99
|
+
for (const e of others) {
|
|
100
|
+
for (const t of e.surfaces.tools) toolNames.add(t.name);
|
|
101
|
+
for (const h of e.surfaces.hooks) hookKeys.add(h.extensionId);
|
|
102
|
+
for (const m of e.surfaces.mcps) mcpNames.add(m.name);
|
|
103
|
+
for (const a of e.surfaces.systemAppendices) appendixIds.add(a.extensionId);
|
|
104
|
+
for (const a of e.surfaces.agentAppendices) appendixIds.add(a.extensionId);
|
|
105
|
+
for (const s of e.surfaces.subskills) {
|
|
106
|
+
subskillArgs.add(`${s.parent}\u0000${s.activationArg}`);
|
|
107
|
+
parentPhases.add(`${s.parent}\u0000${s.phase}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Check candidate surfaces against the effective registry AND against each
|
|
112
|
+
// other (intra-bundle duplicates are also hard errors).
|
|
113
|
+
for (const t of bundle.surfaces.tools) {
|
|
114
|
+
if (toolNames.has(t.name)) {
|
|
115
|
+
throw new GjcPluginLoadError("duplicate_tool", `GJC plugin tool name collides: ${t.name}`);
|
|
116
|
+
}
|
|
117
|
+
toolNames.add(t.name);
|
|
118
|
+
}
|
|
119
|
+
for (const h of bundle.surfaces.hooks) {
|
|
120
|
+
if (hookKeys.has(h.extensionId)) {
|
|
121
|
+
throw new GjcPluginLoadError("duplicate_hook", `GJC plugin hook collides: ${h.extensionId}`);
|
|
122
|
+
}
|
|
123
|
+
hookKeys.add(h.extensionId);
|
|
124
|
+
}
|
|
125
|
+
for (const m of bundle.surfaces.mcps) {
|
|
126
|
+
if (mcpNames.has(m.name)) {
|
|
127
|
+
throw new GjcPluginLoadError("duplicate_mcp", `GJC plugin MCP name collides: ${m.name}`);
|
|
128
|
+
}
|
|
129
|
+
mcpNames.add(m.name);
|
|
130
|
+
assertMcpInstallPolicy(m.config, { pluginRoot: bundle.root });
|
|
131
|
+
}
|
|
132
|
+
for (const a of [...bundle.surfaces.systemAppendices, ...bundle.surfaces.agentAppendices]) {
|
|
133
|
+
if (appendixIds.has(a.extensionId)) {
|
|
134
|
+
throw new GjcPluginLoadError("duplicate_appendix", `GJC plugin appendix collides: ${a.extensionId}`);
|
|
135
|
+
}
|
|
136
|
+
appendixIds.add(a.extensionId);
|
|
137
|
+
}
|
|
138
|
+
for (const s of bundle.surfaces.subskills) {
|
|
139
|
+
const argKey = `${s.parent}\u0000${s.activationArg}`;
|
|
140
|
+
const phaseKey = `${s.parent}\u0000${s.phase}`;
|
|
141
|
+
if (subskillArgs.has(argKey)) {
|
|
142
|
+
throw new GjcPluginLoadError(
|
|
143
|
+
"duplicate_arg",
|
|
144
|
+
`GJC plugin subskill activation_arg collides for ${s.parent}: ${s.activationArg}`,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
if (parentPhases.has(phaseKey)) {
|
|
148
|
+
throw new GjcPluginLoadError(
|
|
149
|
+
"duplicate_parent_phase",
|
|
150
|
+
`GJC plugin subskill parent/phase collides: ${s.parent}/${s.phase}`,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
subskillArgs.add(argKey);
|
|
154
|
+
parentPhases.add(phaseKey);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -10,6 +10,7 @@ import type { SkillPromptDetails } from "../session/messages";
|
|
|
10
10
|
import { expandTilde } from "../tools/path-utils";
|
|
11
11
|
import type { LoadedSubskillActivation } from "./gjc-plugins";
|
|
12
12
|
import { buildSubskillInjection } from "./gjc-plugins/injection";
|
|
13
|
+
import { renderSkillAdvertisement } from "./gjc-plugins/runtime-adapters";
|
|
13
14
|
export interface Skill {
|
|
14
15
|
name: string;
|
|
15
16
|
description: string;
|
|
@@ -415,6 +416,20 @@ export async function buildSkillPromptMessage(
|
|
|
415
416
|
} else if (context.subskillActivation) {
|
|
416
417
|
details.subskillActivation = context.subskillActivation;
|
|
417
418
|
}
|
|
419
|
+
// Tier-1 advertisement: metadata-only list of installed sub-skills bound to
|
|
420
|
+
// this parent skill, so the agent can choose one contextually.
|
|
421
|
+
if (context.cwd) {
|
|
422
|
+
try {
|
|
423
|
+
const advert = await renderSkillAdvertisement({
|
|
424
|
+
cwd: context.cwd,
|
|
425
|
+
skillName: skill.name,
|
|
426
|
+
phase: context.currentPhase,
|
|
427
|
+
});
|
|
428
|
+
if (advert) message += `\n\n${advert}`;
|
|
429
|
+
} catch {
|
|
430
|
+
// Advertisement is best-effort; never block skill prompt construction.
|
|
431
|
+
}
|
|
432
|
+
}
|
|
418
433
|
}
|
|
419
434
|
return {
|
|
420
435
|
message,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
import { safeStderrWrite } from "@gajae-code/utils";
|
|
4
3
|
import { VERSION } from "@gajae-code/utils/dirs";
|
|
4
|
+
import { safeStderrWrite } from "@gajae-code/utils/safe-stderr";
|
|
5
5
|
import type { Args } from "../cli/args";
|
|
6
6
|
import { tmuxRuntimeSessionPath } from "./session-layout";
|
|
7
7
|
import { GJC_COORDINATOR_SESSION_ID_ENV, GJC_COORDINATOR_SESSION_STATE_FILE_ENV } from "./session-state-sidecar";
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
GJC_TMUX_PROFILE_ENV,
|
|
16
16
|
GJC_TMUX_SESSION_PREFIX,
|
|
17
17
|
type GjcTmuxProfileCommand,
|
|
18
|
+
resolveGjcTmuxBinary,
|
|
18
19
|
resolveGjcTmuxCommand,
|
|
19
20
|
} from "./tmux-common";
|
|
20
21
|
import { findGjcTmuxSessionByName, findGjcTmuxSessionByScope, type GjcTmuxSessionStatus } from "./tmux-sessions";
|
|
@@ -31,6 +32,26 @@ export {
|
|
|
31
32
|
export const GJC_TMUX_LAUNCHED_ENV = "GJC_TMUX_LAUNCHED";
|
|
32
33
|
export const GJC_LAUNCH_POLICY_ENV = "GJC_LAUNCH_POLICY";
|
|
33
34
|
export const GJC_TMUX_WINDOW_LABEL_MAX_WIDTH = 48;
|
|
35
|
+
export const GJC_PSMUX_PROFILE_FORCE_ENV = "GJC_PSMUX_PROFILE_FORCE";
|
|
36
|
+
|
|
37
|
+
function envFlagDisabled(value: string | undefined): boolean {
|
|
38
|
+
const normalized = value?.trim().toLowerCase();
|
|
39
|
+
return normalized === "0" || normalized === "false" || normalized === "off" || normalized === "no";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Decide whether the mouse / clipboard / mode-style UX profile commands should
|
|
44
|
+
* be dropped for the active multiplexer. Psmux historically does not
|
|
45
|
+
* round-trip every user option perfectly; the ownership-tag round-trip is the
|
|
46
|
+
* only piece gjc session / gjc team actually need, so dropping the rest keeps
|
|
47
|
+
* native Windows `gjc --tmux` bootable when those UX options would otherwise
|
|
48
|
+
* hard-fail.
|
|
49
|
+
*/
|
|
50
|
+
function psmuxProfileCommandsShouldDropUx(env: NodeJS.ProcessEnv, tmuxCommand: string): boolean {
|
|
51
|
+
if (envFlagDisabled(env[GJC_PSMUX_PROFILE_FORCE_ENV])) return false;
|
|
52
|
+
const resolved = resolveGjcTmuxBinary({ env });
|
|
53
|
+
return resolved.command === tmuxCommand && resolved.isPsmux;
|
|
54
|
+
}
|
|
34
55
|
|
|
35
56
|
type LaunchPolicy = "direct" | "tmux";
|
|
36
57
|
|
|
@@ -166,6 +187,18 @@ function formatTmuxLaunchDiagnostic(stage: string, stderr?: string): string {
|
|
|
166
187
|
return `gjc --tmux failed after creating tmux session: ${stage}.${suffix}\n`;
|
|
167
188
|
}
|
|
168
189
|
|
|
190
|
+
function formatTmuxUnavailableDiagnostic(platform: NodeJS.Platform, tmuxCommand: string): string {
|
|
191
|
+
if (platform === "win32") {
|
|
192
|
+
return (
|
|
193
|
+
`gjc --tmux requested but no tmux executable was found; starting without a tmux-backed session. ` +
|
|
194
|
+
`GJC searched for psmux, pmux, and tmux on PATH (got \`${tmuxCommand}\`). ` +
|
|
195
|
+
"Install psmux (https://github.com/psmux/psmux) for native Windows tmux support, or use WSL with real tmux. " +
|
|
196
|
+
"You can also point GJC at a specific binary via GJC_TMUX_COMMAND.\n"
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
return `gjc --tmux requested but no ${tmuxCommand} executable was found; starting without a tmux-backed session.\n`;
|
|
200
|
+
}
|
|
201
|
+
|
|
169
202
|
function shellQuote(value: string): string {
|
|
170
203
|
if (value.length === 0) return "''";
|
|
171
204
|
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
@@ -199,7 +232,7 @@ function buildWindowsPowerShellInnerCommand(context: CommandResolutionContext, r
|
|
|
199
232
|
export function applyGjcTmuxProfile(context: GjcTmuxProfileContext): GjcTmuxProfileResult {
|
|
200
233
|
const env = context.env ?? process.env;
|
|
201
234
|
const branchSlug = context.branch ? buildGjcTmuxSessionSlug(context.branch) : (context.branchSlug ?? null);
|
|
202
|
-
|
|
235
|
+
let commands = buildGjcTmuxProfileCommands(context.target, env, {
|
|
203
236
|
branch: context.branch ?? null,
|
|
204
237
|
branchSlug,
|
|
205
238
|
project: context.project ?? null,
|
|
@@ -207,6 +240,17 @@ export function applyGjcTmuxProfile(context: GjcTmuxProfileContext): GjcTmuxProf
|
|
|
207
240
|
sessionStateFile: context.sessionStateFile ?? env[GJC_COORDINATOR_SESSION_STATE_FILE_ENV] ?? null,
|
|
208
241
|
version: context.version ?? null,
|
|
209
242
|
});
|
|
243
|
+
if (psmuxProfileCommandsShouldDropUx(env, context.tmuxCommand)) {
|
|
244
|
+
// Keep the ownership-tag round-trip (required for `gjc session` and
|
|
245
|
+
// `gjc team`); drop only the UX profile commands whose option keys
|
|
246
|
+
// historically do not round-trip cleanly on psmux.
|
|
247
|
+
const dropArgs = new Set(["mouse", "set-clipboard", "mode-style"]);
|
|
248
|
+
commands = commands.filter(command => {
|
|
249
|
+
const flag = command.args[0];
|
|
250
|
+
const key = command.args[command.args.length - 2];
|
|
251
|
+
return !(dropArgs.has(String(key)) && (flag === "set-option" || flag === "set-window-option"));
|
|
252
|
+
});
|
|
253
|
+
}
|
|
210
254
|
if (commands.length === 0) return { skipped: true, commands: [], failures: [] };
|
|
211
255
|
const spawnSync = context.spawnSync ?? defaultSpawnSync;
|
|
212
256
|
const cwd = context.cwd ?? process.cwd();
|
|
@@ -315,8 +359,10 @@ function renameExistingTmuxWindowIfNeeded(context: TmuxLaunchContext): void {
|
|
|
315
359
|
if (!env.TMUX || env[GJC_TMUX_LAUNCHED_ENV] === "1") return;
|
|
316
360
|
if (parseLaunchPolicy(env) === "direct") return;
|
|
317
361
|
|
|
318
|
-
|
|
319
|
-
|
|
362
|
+
// Note: Windows is intentionally allowed here. Psmux supports
|
|
363
|
+
// `rename-window` and we want the leader window to inherit the
|
|
364
|
+
// project:branch title even on native Windows, where gjc --tmux runs
|
|
365
|
+
// through PowerShell to a psmux backend.
|
|
320
366
|
|
|
321
367
|
const tty = context.tty ?? { stdin: Boolean(process.stdin.isTTY), stdout: Boolean(process.stdout.isTTY) };
|
|
322
368
|
if (!isInteractiveRootLaunch(context.parsed, tty)) return;
|
|
@@ -375,7 +421,12 @@ export function buildDefaultTmuxLaunchPlan(context: TmuxLaunchContext): TmuxLaun
|
|
|
375
421
|
const branch = context.worktreeBranch ?? context.currentBranch ?? readCurrentBranch(cwd);
|
|
376
422
|
const project = context.project ?? cwd;
|
|
377
423
|
const sessionName = buildGjcTmuxSessionName(env, { branch });
|
|
378
|
-
|
|
424
|
+
// Pick the most appropriate tmux binary for this platform. On native Windows
|
|
425
|
+
// the resolver walks psmux / pmux / tmux and uses the first one present on
|
|
426
|
+
// PATH, so the default `gjc --tmux` flow lands on a real multiplexer even
|
|
427
|
+
// without an explicit GJC_TMUX_COMMAND override.
|
|
428
|
+
const resolvedBinary = resolveGjcTmuxBinary({ platform, env });
|
|
429
|
+
const tmuxCommand = resolvedBinary.command;
|
|
379
430
|
const sessionId = env[GJC_COORDINATOR_SESSION_ID_ENV]?.trim() || sessionName;
|
|
380
431
|
// The session ROOT is keyed by the active GJC session (GJC_SESSION_ID), NOT the
|
|
381
432
|
// coordinator/tmux identity. Fall back to the coordinator id only for standalone
|
|
@@ -385,7 +436,10 @@ export function buildDefaultTmuxLaunchPlan(context: TmuxLaunchContext): TmuxLaun
|
|
|
385
436
|
env[GJC_COORDINATOR_SESSION_STATE_FILE_ENV]?.trim() ||
|
|
386
437
|
tmuxRuntimeSessionPath(cwd, gjcSessionId, buildGjcTmuxSessionSlug(sessionName));
|
|
387
438
|
const tmuxAvailable = context.tmuxAvailable ?? Bun.which(tmuxCommand) !== null;
|
|
388
|
-
if (!tmuxAvailable)
|
|
439
|
+
if (!tmuxAvailable) {
|
|
440
|
+
(context.diagnosticWriter ?? safeStderrWrite)(formatTmuxUnavailableDiagnostic(platform, tmuxCommand));
|
|
441
|
+
return undefined;
|
|
442
|
+
}
|
|
389
443
|
const existingSessionName = allowsExistingTmuxAttach(context.parsed, env)
|
|
390
444
|
? "existingBranchSessionName" in context
|
|
391
445
|
? (context.existingBranchSessionName ?? undefined)
|
|
@@ -451,7 +505,7 @@ export function launchDefaultTmuxIfNeeded(context: TmuxLaunchContext): boolean {
|
|
|
451
505
|
|
|
452
506
|
if (plan.attachSessionName) {
|
|
453
507
|
const attached = spawnSync(plan.tmuxCommand, ["attach-session", "-t", `=${plan.attachSessionName}`], options);
|
|
454
|
-
|
|
508
|
+
if (attached.exitCode === 0) return true;
|
|
455
509
|
}
|
|
456
510
|
|
|
457
511
|
const created = spawnSync(plan.tmuxCommand, plan.newSessionArgs, options);
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows psmux detection and tmux-binary resolution.
|
|
3
|
+
*
|
|
4
|
+
* Recent psmux releases (see docs/compatibility.md in the psmux repo) close
|
|
5
|
+
* the round-trip gap for set-option / show-options user options and the
|
|
6
|
+
* set-window-option profile values gjc emits, which is what unblocks the
|
|
7
|
+
* native Windows gjc --tmux path. This module detects that capability so gjc
|
|
8
|
+
* can pick psmux when tmux is missing on Windows, and so callers can decide
|
|
9
|
+
* whether to treat a given tmux binary as psmux (affecting e.g. the untagged
|
|
10
|
+
* diagnostic wording and namespace handling).
|
|
11
|
+
*
|
|
12
|
+
* The probe is intentionally lightweight: it runs a single tmux -V (or
|
|
13
|
+
* --version) once per process and caches the verdict. Cache invalidation
|
|
14
|
+
* knobs:
|
|
15
|
+
* - force: true re-probes on every call (used by tests).
|
|
16
|
+
* - GJC_PSMUX_FORCE_DETECT=1 re-probes each call.
|
|
17
|
+
* - GJC_PSMUX_DETECTION=off skips probing entirely.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export const GJC_PSMUX_COMMAND_ENV = "GJC_PSMUX_COMMAND";
|
|
21
|
+
export const GJC_PSMUX_DETECTION_ENV = "GJC_PSMUX_DETECTION";
|
|
22
|
+
export const GJC_PSMUX_FORCE_DETECT_ENV = "GJC_PSMUX_FORCE_DETECT";
|
|
23
|
+
|
|
24
|
+
/** Names that psmux installs as the canonical executable / alias. */
|
|
25
|
+
export const PSMUX_BINARY_NAMES = ["psmux", "pmux", "tmux"] as const;
|
|
26
|
+
|
|
27
|
+
/** Substrings that uniquely identify psmux in version/help output. */
|
|
28
|
+
const PSMUX_VERSION_MARKERS = ["psmux", "pmux"] as const;
|
|
29
|
+
|
|
30
|
+
export type PsmuxSpawnRunner = (
|
|
31
|
+
command: string,
|
|
32
|
+
args: string[],
|
|
33
|
+
) => { exitCode: number | null; stdout?: string; stderr?: string };
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Resolves a tmux-class binary name (e.g. "psmux", "tmux") to an absolute
|
|
37
|
+
* filesystem path or returns null when the binary cannot be located. The
|
|
38
|
+
* default implementation uses `Bun.which`; production callers leave it
|
|
39
|
+
* alone and unit tests inject a stub via `__setBinaryResolverForTests`
|
|
40
|
+
* so the version-banner probe can be exercised hermetically.
|
|
41
|
+
*/
|
|
42
|
+
export type BinaryResolver = (candidate: string) => string | null;
|
|
43
|
+
|
|
44
|
+
const DEFAULT_BINARY_RESOLVER: BinaryResolver = candidate => {
|
|
45
|
+
if (!candidate) return null;
|
|
46
|
+
const stripped = candidate.trim().replace(/^["']|["']$/g, "");
|
|
47
|
+
if (!stripped) return null;
|
|
48
|
+
if (Bun.which(stripped)) return stripped;
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
let activeBinaryResolver: BinaryResolver = DEFAULT_BINARY_RESOLVER;
|
|
53
|
+
|
|
54
|
+
/** @internal Test-only seam; production code never calls this. */
|
|
55
|
+
export function __setBinaryResolverForTests(resolver: BinaryResolver | null): void {
|
|
56
|
+
activeBinaryResolver = resolver ?? DEFAULT_BINARY_RESOLVER;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface CacheEntry {
|
|
60
|
+
command: string;
|
|
61
|
+
isPsmux: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const detectionCache = new Map<string, CacheEntry>();
|
|
65
|
+
|
|
66
|
+
export function envDisabled(value: string | undefined): boolean {
|
|
67
|
+
const normalized = value?.trim().toLowerCase();
|
|
68
|
+
return normalized === "0" || normalized === "false" || normalized === "off" || normalized === "no";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* GJC_PSMUX_FORCE_DETECT opt-in re-probe switch. Any non-empty value other
|
|
73
|
+
* than a "disabled" sentinel forces a fresh probe on every call. The unset
|
|
74
|
+
* (undefined) case must NOT force probing, otherwise the in-process cache
|
|
75
|
+
* never engages.
|
|
76
|
+
*/
|
|
77
|
+
function envForcesProbe(value: string | undefined): boolean {
|
|
78
|
+
if (value === undefined) return false;
|
|
79
|
+
if (envDisabled(value)) return false;
|
|
80
|
+
return value.trim().length > 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function readSpawnRunner(): PsmuxSpawnRunner {
|
|
84
|
+
return (command, args) => {
|
|
85
|
+
try {
|
|
86
|
+
const result = Bun.spawnSync({
|
|
87
|
+
cmd: [command, ...args],
|
|
88
|
+
stdout: "pipe",
|
|
89
|
+
stderr: "pipe",
|
|
90
|
+
env: process.env,
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
exitCode: result.exitCode,
|
|
94
|
+
stdout: result.stdout.toString(),
|
|
95
|
+
stderr: result.stderr.toString(),
|
|
96
|
+
};
|
|
97
|
+
} catch {
|
|
98
|
+
return { exitCode: -1, stdout: "", stderr: "" };
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function probeVersionOutput(command: string, runner: PsmuxSpawnRunner): string {
|
|
104
|
+
const flags = ["-V", "--version"];
|
|
105
|
+
for (const flag of flags) {
|
|
106
|
+
const result = runner(command, [flag]);
|
|
107
|
+
const text = `${result.stdout ?? ""}\n${result.stderr ?? ""}`.toLowerCase();
|
|
108
|
+
if (result.exitCode === 0 && text.trim().length > 0) return text;
|
|
109
|
+
}
|
|
110
|
+
return "";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function outputMentionsPsmux(output: string): boolean {
|
|
114
|
+
if (!output) return false;
|
|
115
|
+
return PSMUX_VERSION_MARKERS.some(marker => output.includes(marker));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function resolveBinaryPath(candidate: string): string | null {
|
|
119
|
+
return activeBinaryResolver(candidate);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function detectPsmuxForCommand(command: string, runner: PsmuxSpawnRunner): boolean {
|
|
123
|
+
const resolved = resolveBinaryPath(command);
|
|
124
|
+
if (!resolved) return false;
|
|
125
|
+
const output = probeVersionOutput(resolved, runner);
|
|
126
|
+
return outputMentionsPsmux(output);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Decide whether command resolves to a psmux binary by probing its version
|
|
131
|
+
* output. The result is cached per process unless force is set or
|
|
132
|
+
* GJC_PSMUX_FORCE_DETECT=1.
|
|
133
|
+
*/
|
|
134
|
+
export function detectPsmux(
|
|
135
|
+
command: string,
|
|
136
|
+
options: { force?: boolean; env?: NodeJS.ProcessEnv; runner?: PsmuxSpawnRunner } = {},
|
|
137
|
+
): boolean {
|
|
138
|
+
const env = options.env ?? process.env;
|
|
139
|
+
const explicit = env[GJC_PSMUX_COMMAND_ENV]?.trim();
|
|
140
|
+
if (explicit) {
|
|
141
|
+
// The override is authoritative on its own — we trust the user's
|
|
142
|
+
// GJC_PSMUX_COMMAND value when they name a psmux-class binary, even
|
|
143
|
+
// when the binary cannot be located on PATH in the current process.
|
|
144
|
+
// This keeps the override usable from CI runners and from test
|
|
145
|
+
// environments where Bun.which would otherwise return null.
|
|
146
|
+
const normalized = explicit.toLowerCase();
|
|
147
|
+
if (
|
|
148
|
+
normalized === "psmux" ||
|
|
149
|
+
normalized === "pmux" ||
|
|
150
|
+
normalized.endsWith("/psmux") ||
|
|
151
|
+
normalized.endsWith("/pmux") ||
|
|
152
|
+
normalized.endsWith("\\psmux") ||
|
|
153
|
+
normalized.endsWith("\\pmux")
|
|
154
|
+
) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
const explicitPath = resolveBinaryPath(explicit);
|
|
158
|
+
if (explicitPath && explicitPath === resolveBinaryPath(command)) return true;
|
|
159
|
+
}
|
|
160
|
+
if (envDisabled(env[GJC_PSMUX_DETECTION_ENV])) return false;
|
|
161
|
+
const force = options.force === true || envForcesProbe(env[GJC_PSMUX_FORCE_DETECT_ENV]);
|
|
162
|
+
const useCache = !force && !options.force;
|
|
163
|
+
if (useCache) {
|
|
164
|
+
const cached = detectionCache.get(command);
|
|
165
|
+
if (cached) return cached.isPsmux;
|
|
166
|
+
}
|
|
167
|
+
const runner = options.runner ?? readSpawnRunner();
|
|
168
|
+
const isPsmux = detectPsmuxForCommand(command, runner);
|
|
169
|
+
if (useCache) detectionCache.set(command, { command, isPsmux });
|
|
170
|
+
return isPsmux;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface ResolveGjcTmuxBinaryOptions {
|
|
174
|
+
platform?: NodeJS.Platform;
|
|
175
|
+
env?: NodeJS.ProcessEnv;
|
|
176
|
+
runner?: PsmuxSpawnRunner;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface ResolvedTmuxBinary {
|
|
180
|
+
command: string;
|
|
181
|
+
isPsmux: boolean;
|
|
182
|
+
viaExplicitOverride: boolean;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Resolve the tmux command GJC should invoke. Honors the existing
|
|
187
|
+
* GJC_TMUX_COMMAND / GJC_TEAM_TMUX_COMMAND overrides; on Windows when no
|
|
188
|
+
* override is set, psmux (installed as psmux, pmux, or tmux) is picked
|
|
189
|
+
* automatically so the default gjc --tmux flow lands on a real multiplexer.
|
|
190
|
+
*/
|
|
191
|
+
export function resolveGjcTmuxBinary(options: ResolveGjcTmuxBinaryOptions = {}): ResolvedTmuxBinary {
|
|
192
|
+
const env = options.env ?? process.env;
|
|
193
|
+
const platform = options.platform ?? process.platform;
|
|
194
|
+
const runner = options.runner ?? readSpawnRunner();
|
|
195
|
+
const explicit = env.GJC_TMUX_COMMAND?.trim() || env.GJC_TEAM_TMUX_COMMAND?.trim();
|
|
196
|
+
if (explicit) {
|
|
197
|
+
const isPsmux = detectPsmux(explicit, { env, runner });
|
|
198
|
+
return { command: explicit, isPsmux, viaExplicitOverride: true };
|
|
199
|
+
}
|
|
200
|
+
if (platform === "win32") {
|
|
201
|
+
for (const candidate of PSMUX_BINARY_NAMES) {
|
|
202
|
+
if (resolveBinaryPath(candidate)) {
|
|
203
|
+
const isPsmux = detectPsmux(candidate, { env, runner });
|
|
204
|
+
return { command: candidate, isPsmux, viaExplicitOverride: false };
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const tmuxPath = resolveBinaryPath("tmux");
|
|
209
|
+
if (tmuxPath) {
|
|
210
|
+
const isPsmux = detectPsmux("tmux", { env, runner });
|
|
211
|
+
return { command: "tmux", isPsmux, viaExplicitOverride: false };
|
|
212
|
+
}
|
|
213
|
+
return { command: "tmux", isPsmux: false, viaExplicitOverride: false };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Test-only helper: drop the in-process detection cache. */
|
|
217
|
+
export function clearPsmuxDetectionCache(): void {
|
|
218
|
+
detectionCache.clear();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface PsmuxProbe {
|
|
222
|
+
command: string;
|
|
223
|
+
versionOutput: string;
|
|
224
|
+
isPsmux: boolean;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function probePsmux(
|
|
228
|
+
command: string,
|
|
229
|
+
options: { env?: NodeJS.ProcessEnv; runner?: PsmuxSpawnRunner; force?: boolean } = {},
|
|
230
|
+
): PsmuxProbe {
|
|
231
|
+
const env = options.env ?? process.env;
|
|
232
|
+
const runner = options.runner ?? readSpawnRunner();
|
|
233
|
+
const resolved = resolveBinaryPath(command);
|
|
234
|
+
if (!resolved) return { command, versionOutput: "", isPsmux: false };
|
|
235
|
+
if (options.force) clearPsmuxDetectionCache();
|
|
236
|
+
const output = probeVersionOutput(resolved, runner);
|
|
237
|
+
const isPsmux = outputMentionsPsmux(output) || env[GJC_PSMUX_COMMAND_ENV]?.trim() === resolved;
|
|
238
|
+
return { command: resolved, versionOutput: output, isPsmux };
|
|
239
|
+
}
|
|
@@ -5,7 +5,7 @@ import type { WorkflowHudSummary } from "../skill-state/active-state";
|
|
|
5
5
|
import { buildTeamHudSummary as buildWorkflowTeamHudSummary } from "../skill-state/workflow-hud";
|
|
6
6
|
import { WORKFLOW_STATE_VERSION } from "../skill-state/workflow-state-contract";
|
|
7
7
|
import type { GcPidProbe, GcRecord } from "./gc-runtime";
|
|
8
|
-
import { applyGjcTmuxProfile
|
|
8
|
+
import { applyGjcTmuxProfile } from "./launch-tmux";
|
|
9
9
|
import { modeStatePath, sessionIdFromDirName, sessionReportsDir, teamStateRoot } from "./session-layout";
|
|
10
10
|
import { resolveGjcSessionForWrite, writeSessionActivityMarker } from "./session-resolution";
|
|
11
11
|
import {
|
|
@@ -595,6 +595,16 @@ function teamDir(stateRoot: string, teamName: string): string {
|
|
|
595
595
|
function shellQuote(value: string): string {
|
|
596
596
|
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
597
597
|
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* PowerShell-safe single-quote escape: doubles single quotes inside a
|
|
601
|
+
* single-quoted PowerShell literal ('it''s ok') and uses the same
|
|
602
|
+
* surrounding quotes. Used to build worker command strings that psmux
|
|
603
|
+
* will hand to a Windows ConPTY pane running PowerShell.
|
|
604
|
+
*/
|
|
605
|
+
function powershellQuote(value: string): string {
|
|
606
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
607
|
+
}
|
|
598
608
|
function safePathSegment(kind: string, value: string): string {
|
|
599
609
|
assertSafeId(kind, value);
|
|
600
610
|
return value;
|
|
@@ -1812,7 +1822,7 @@ async function ensureWorkerWorktree(
|
|
|
1812
1822
|
|
|
1813
1823
|
function buildTeamTmuxLeaderRequirementMessage(detail?: string): string {
|
|
1814
1824
|
const suffix = detail?.trim() ? `:${detail.trim()}` : "";
|
|
1815
|
-
return `gjc_team_requires_tmux_leader: run \`gjc --tmux
|
|
1825
|
+
return `gjc_team_requires_tmux_leader: start a tmux session first (run \`gjc --tmux\`, or launch tmux yourself), then run \`gjc team ...\` inside it, or use \`gjc team --dry-run\` for state-only smoke tests${suffix}`;
|
|
1816
1826
|
}
|
|
1817
1827
|
function readGjcTmuxProfileValue(tmuxCommand: string, sessionName: string): string {
|
|
1818
1828
|
const result = Bun.spawnSync(
|
|
@@ -1826,7 +1836,7 @@ function readGjcTmuxProfileValue(tmuxCommand: string, sessionName: string): stri
|
|
|
1826
1836
|
return result.stdout.toString().trim();
|
|
1827
1837
|
}
|
|
1828
1838
|
|
|
1829
|
-
function
|
|
1839
|
+
function tagTmuxSessionAsGjcLeader(tmuxCommand: string, sessionName: string): boolean {
|
|
1830
1840
|
const result = Bun.spawnSync(
|
|
1831
1841
|
[
|
|
1832
1842
|
tmuxCommand,
|
|
@@ -1845,25 +1855,39 @@ function retagGjcLaunchedTmuxSession(tmuxCommand: string, sessionName: string):
|
|
|
1845
1855
|
}
|
|
1846
1856
|
|
|
1847
1857
|
function readCurrentTmuxLeaderContext(tmuxCommand: string, env: NodeJS.ProcessEnv): GjcTmuxLeaderContext {
|
|
1858
|
+
if (Bun.which(tmuxCommand) === null)
|
|
1859
|
+
throw new Error(buildTeamTmuxLeaderRequirementMessage(`tmux_not_installed:${tmuxCommand}`));
|
|
1848
1860
|
const paneTarget = env.TMUX_PANE?.trim();
|
|
1849
1861
|
const args = paneTarget
|
|
1850
1862
|
? ["display-message", "-p", "-t", paneTarget, "#S:#I #{pane_id}"]
|
|
1851
1863
|
: ["display-message", "-p", "#S:#I #{pane_id}"];
|
|
1852
1864
|
const result = Bun.spawnSync([tmuxCommand, ...args], { stdout: "pipe", stderr: "pipe" });
|
|
1853
|
-
if (result.exitCode !== 0)
|
|
1865
|
+
if (result.exitCode !== 0) {
|
|
1866
|
+
// Distinguish "you are not inside any tmux session" from a genuine tmux
|
|
1867
|
+
// query failure so the caller gets actionable guidance instead of raw
|
|
1868
|
+
// tmux stderr. `gjc team` needs a tmux leader; outside tmux there is none.
|
|
1869
|
+
const insideTmux = Boolean(env.TMUX?.trim() || env.TMUX_PANE?.trim());
|
|
1870
|
+
const stderr = result.stderr.toString().trim();
|
|
1871
|
+
throw new Error(
|
|
1872
|
+
buildTeamTmuxLeaderRequirementMessage(
|
|
1873
|
+
insideTmux ? `tmux_query_failed${stderr ? `:${stderr}` : ""}` : "not_inside_tmux",
|
|
1874
|
+
),
|
|
1875
|
+
);
|
|
1876
|
+
}
|
|
1854
1877
|
const [sessionAndWindow = "", leaderPaneId = ""] = result.stdout.toString().trim().split(/\s+/);
|
|
1855
1878
|
const [sessionName = "", windowIndex = ""] = sessionAndWindow.split(":");
|
|
1856
1879
|
if (!sessionName || !windowIndex || !leaderPaneId.startsWith("%"))
|
|
1857
1880
|
throw new Error(buildTeamTmuxLeaderRequirementMessage(`invalid_tmux_context:${result.stdout.toString().trim()}`));
|
|
1858
1881
|
if (readGjcTmuxProfileValue(tmuxCommand, sessionName) !== GJC_TMUX_PROFILE_VALUE) {
|
|
1859
|
-
//
|
|
1860
|
-
//
|
|
1861
|
-
//
|
|
1862
|
-
//
|
|
1863
|
-
//
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1882
|
+
// Adopt any real tmux leader as a GJC team leader — including a session
|
|
1883
|
+
// the user created outside `gjc --tmux` — by writing GJC's @gjc-profile
|
|
1884
|
+
// ownership tag and reading it back. A provider that round-trips tmux
|
|
1885
|
+
// user options (real tmux) keeps the tag and is adopted; one that does
|
|
1886
|
+
// not (e.g. psmux on Windows) drops it, so the readback still fails and
|
|
1887
|
+
// the leader is rejected as unmanaged. This also self-heals a genuine
|
|
1888
|
+
// `gjc --tmux` pane that lost its @gjc-profile tag mid-startup.
|
|
1889
|
+
const tagged = tagTmuxSessionAsGjcLeader(tmuxCommand, sessionName);
|
|
1890
|
+
if (!tagged || readGjcTmuxProfileValue(tmuxCommand, sessionName) !== GJC_TMUX_PROFILE_VALUE)
|
|
1867
1891
|
throw new Error(
|
|
1868
1892
|
buildTeamTmuxLeaderRequirementMessage(
|
|
1869
1893
|
`unmanaged_tmux_session:${sessionName} — ${buildGjcTmuxUntaggedSessionHint(tmuxCommand)}`,
|
|
@@ -1881,7 +1905,15 @@ export function resolveGjcWorkerCommand(cwd = process.cwd(), env: NodeJS.Process
|
|
|
1881
1905
|
if (entrypoint && path.basename(entrypoint).startsWith("gjc")) return shellQuote(path.resolve(cwd, entrypoint));
|
|
1882
1906
|
return "gjc";
|
|
1883
1907
|
}
|
|
1884
|
-
|
|
1908
|
+
/** @internal Exported for unit tests. */
|
|
1909
|
+
export function buildWorkerCommand(
|
|
1910
|
+
config: GjcTeamConfig,
|
|
1911
|
+
worker: GjcTeamWorker,
|
|
1912
|
+
platform: NodeJS.Platform = process.platform,
|
|
1913
|
+
): string {
|
|
1914
|
+
const quote = platform === "win32" ? powershellQuote : shellQuote;
|
|
1915
|
+
const envAssignment = (key: string, value: string): string =>
|
|
1916
|
+
platform === "win32" ? `$env:${key} = ${quote(value)};` : `${key}=${quote(value)}`;
|
|
1885
1917
|
const workspace = worker.worktree_path
|
|
1886
1918
|
? `Worker worktree: ${worker.worktree_path}.`
|
|
1887
1919
|
: `Worker cwd: ${config.leader.cwd}.`;
|
|
@@ -1894,17 +1926,18 @@ function buildWorkerCommand(config: GjcTeamConfig, worker: GjcTeamWorker): strin
|
|
|
1894
1926
|
`Before claiming work, send startup ACK: gjc team api worker-startup-ack --input '{"team_name":"${config.team_name}","worker_id":"${worker.id}","protocol_version":"1"}' --json.`,
|
|
1895
1927
|
`Use gjc team api update-worker-status to report task-local activity, then claim-task/transition-task-status with this worker id; keep heartbeat current during long work, record completion_evidence (summary plus a passed command or verified inspection/artifact item) before completed, and do not mutate leader-owned goal state.`,
|
|
1896
1928
|
].join("\n");
|
|
1897
|
-
const
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
...(worker.worktree_path ? [
|
|
1929
|
+
const envLines = [
|
|
1930
|
+
envAssignment("GJC_TEAM_WORKER", `${config.team_name}/${worker.id}`),
|
|
1931
|
+
envAssignment("GJC_TEAM_INTERNAL_WORKER", `${config.team_name}/${worker.id}`),
|
|
1932
|
+
envAssignment("GJC_TEAM_NAME", config.team_name),
|
|
1933
|
+
envAssignment("GJC_TEAM_WORKER_ID", worker.id),
|
|
1934
|
+
envAssignment("GJC_TEAM_STATE_ROOT", config.state_root),
|
|
1935
|
+
envAssignment("GJC_TEAM_LEADER_CWD", config.leader.cwd),
|
|
1936
|
+
envAssignment("GJC_TEAM_DISPLAY_NAME", config.display_name),
|
|
1937
|
+
...(worker.worktree_path ? [envAssignment("GJC_TEAM_WORKTREE_PATH", worker.worktree_path)] : []),
|
|
1906
1938
|
];
|
|
1907
|
-
|
|
1939
|
+
const joined = platform === "win32" ? envLines.join(" ") : envLines.join(" ");
|
|
1940
|
+
return `${joined} ${config.worker_command} ${quote(prompt)}`;
|
|
1908
1941
|
}
|
|
1909
1942
|
interface GjcTeamInitialLane {
|
|
1910
1943
|
label: string;
|