@gajae-code/coding-agent 0.16.7 → 0.17.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/CHANGELOG.md +180 -1
- package/dist/types/capability/fs.d.ts +37 -4
- package/dist/types/capability/index.d.ts +19 -0
- package/dist/types/capability/types.d.ts +9 -0
- package/dist/types/cli/doctor/args.d.ts +36 -0
- package/dist/types/cli/doctor/checks.d.ts +18 -0
- package/dist/types/cli/doctor/config-repairs.d.ts +38 -0
- package/dist/types/cli/doctor/context.d.ts +89 -0
- package/dist/types/cli/doctor/files.d.ts +27 -0
- package/dist/types/cli/doctor/ids.d.ts +20 -0
- package/dist/types/cli/doctor/install-repairs.d.ts +94 -0
- package/dist/types/cli/doctor/journal.d.ts +43 -0
- package/dist/types/cli/doctor/managed-link.d.ts +39 -0
- package/dist/types/cli/doctor/native-probe.d.ts +2 -0
- package/dist/types/cli/doctor/permission-repairs.d.ts +25 -0
- package/dist/types/cli/doctor/plugin-quarantine.d.ts +77 -0
- package/dist/types/cli/doctor/plugin-restore.d.ts +40 -0
- package/dist/types/cli/doctor/plugin-targets.d.ts +11 -0
- package/dist/types/cli/doctor/probe-client.d.ts +9 -0
- package/dist/types/cli/doctor/probe-types.d.ts +18 -0
- package/dist/types/cli/doctor/probe.d.ts +3 -0
- package/dist/types/cli/doctor/projection-probe.d.ts +2 -0
- package/dist/types/cli/doctor/repairs.d.ts +28 -0
- package/dist/types/cli/doctor/report.d.ts +27 -0
- package/dist/types/cli/doctor/runner.d.ts +4 -0
- package/dist/types/cli/doctor/safety.d.ts +10 -0
- package/dist/types/cli/doctor/service-repairs.d.ts +8 -0
- package/dist/types/cli/doctor/service-targets.d.ts +41 -0
- package/dist/types/cli/doctor/types.d.ts +145 -0
- package/dist/types/cli/doctor-cli.d.ts +7 -0
- package/dist/types/cli/doctor-supervisor.d.ts +121 -0
- package/dist/types/cli/doctor-worker.d.ts +29 -0
- package/dist/types/cli/install-activation.d.ts +158 -0
- package/dist/types/cli/macos-community-app.d.ts +41 -0
- package/dist/types/cli/mcp-cli.d.ts +0 -11
- package/dist/types/cli/update-cli.d.ts +41 -4
- package/dist/types/cli-main.d.ts +174 -0
- package/dist/types/cli.d.ts +1 -171
- package/dist/types/commands/doctor.d.ts +7 -0
- package/dist/types/commands/sdk.d.ts +17 -8
- package/dist/types/config/autorouting-tier-map.d.ts +19 -0
- package/dist/types/config/file-lock.d.ts +27 -3
- package/dist/types/config/model-preset-registry.d.ts +1 -0
- package/dist/types/config/model-registry.d.ts +12 -5
- package/dist/types/config/model-resolver.d.ts +16 -3
- package/dist/types/config/models-config-schema.d.ts +2 -0
- package/dist/types/config/settings-schema.d.ts +1 -1
- package/dist/types/coordinator-mcp/question-gate-codec.d.ts +1 -1
- package/dist/types/coordinator-mcp/session-reaper.d.ts +15 -5
- package/dist/types/cursor.d.ts +9 -9
- package/dist/types/discovery/agents-md.d.ts +6 -1
- package/dist/types/discovery/helpers.d.ts +36 -7
- package/dist/types/discovery/index.d.ts +1 -1
- package/dist/types/discovery/mcp-json.d.ts +2 -0
- package/dist/types/extensibility/extensions/loader.d.ts +22 -1
- package/dist/types/extensibility/gjc-plugins/lifecycle.d.ts +14 -1
- package/dist/types/extensibility/gjc-plugins/paths.d.ts +2 -1
- package/dist/types/extensibility/gjc-plugins/types.d.ts +25 -0
- package/dist/types/extensibility/plugins/manager.d.ts +33 -4
- package/dist/types/extensibility/plugins/marketplace/cache.d.ts +6 -0
- package/dist/types/extensibility/plugins/marketplace/manager.d.ts +186 -0
- package/dist/types/extensibility/plugins/marketplace/registry.d.ts +27 -0
- package/dist/types/extensibility/plugins/marketplace/source-resolver.d.ts +16 -1
- package/dist/types/extensibility/runtime-skill-discovery.d.ts +16 -3
- package/dist/types/gjc-runtime/autoresearch-runtime.d.ts +6 -0
- package/dist/types/gjc-runtime/launch-worktree.d.ts +53 -0
- package/dist/types/gjc-runtime/session-layout.d.ts +8 -0
- package/dist/types/gjc-runtime/session-state-lock.d.ts +15 -0
- package/dist/types/gjc-runtime/session-state-sidecar.d.ts +13 -0
- package/dist/types/gjc-runtime/ultragoal-runtime.d.ts +6 -0
- package/dist/types/main.d.ts +19 -1
- package/dist/types/modes/acp/acp-agent.d.ts +40 -0
- package/dist/types/modes/components/agent-dashboard.d.ts +1 -0
- package/dist/types/modes/components/model-selector.d.ts +2 -0
- package/dist/types/modes/interactive-mode.d.ts +1 -1
- package/dist/types/runtime-mcp/config-writer.d.ts +47 -0
- package/dist/types/runtime-mcp/policy-json-edit.d.ts +60 -0
- package/dist/types/runtime-mcp/startup-policy.d.ts +4 -0
- package/dist/types/runtime-mcp/types.d.ts +2 -2
- package/dist/types/sdk/acp/adapter.d.ts +5 -1
- package/dist/types/sdk/broker/broker.d.ts +51 -0
- package/dist/types/sdk/broker/daemon-entry.d.ts +39 -0
- package/dist/types/sdk/broker/discovery.d.ts +38 -0
- package/dist/types/sdk/broker/doctor-restart.d.ts +79 -0
- package/dist/types/sdk/broker/endpoint-authority.d.ts +7 -0
- package/dist/types/sdk/broker/ensure.d.ts +14 -0
- package/dist/types/sdk/broker/lifecycle.d.ts +2 -0
- package/dist/types/sdk/broker/process-incarnation.d.ts +50 -0
- package/dist/types/sdk/broker/runtime.d.ts +26 -0
- package/dist/types/sdk/broker/session-index.d.ts +13 -4
- package/dist/types/sdk/broker/worktree-occupancy.d.ts +14 -0
- package/dist/types/sdk/bus/chat-daemon-cli.d.ts +16 -0
- package/dist/types/sdk/bus/chat-daemon-control.d.ts +101 -6
- package/dist/types/sdk/bus/chat-daemon-runtime.d.ts +16 -0
- package/dist/types/sdk/bus/daemon-startup-exclusion.d.ts +43 -0
- package/dist/types/sdk/bus/doctor-daemon-restart-client.d.ts +51 -0
- package/dist/types/sdk/bus/doctor-daemon-restart.d.ts +39 -0
- package/dist/types/sdk/bus/index.d.ts +2 -0
- package/dist/types/sdk/bus/notification-service.d.ts +3 -0
- package/dist/types/sdk/bus/telegram-daemon-cli.d.ts +11 -0
- package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +1 -1
- package/dist/types/sdk/bus/telegram-daemon-control.d.ts +5 -0
- package/dist/types/sdk/bus/telegram-daemon-owner-registry.d.ts +1 -0
- package/dist/types/sdk/bus/telegram-daemon.d.ts +36 -5
- package/dist/types/sdk/cli/session-cli.d.ts +1 -0
- package/dist/types/sdk/host/session-runtime.d.ts +4 -0
- package/dist/types/sdk/host/surface-policy.d.ts +3 -1
- package/dist/types/sdk/lifecycle/service.d.ts +44 -10
- package/dist/types/sdk/prompt-deadline-lease.d.ts +6 -3
- package/dist/types/sdk/prompt-deadline-manager.d.ts +2 -2
- package/dist/types/sdk/prompt-failure.d.ts +47 -0
- package/dist/types/sdk/prompt-status.d.ts +19 -0
- package/dist/types/sdk/router/session-router.d.ts +3 -4
- package/dist/types/sdk/service-artifact-paths.d.ts +16 -0
- package/dist/types/sdk/session-authority.d.ts +9 -0
- package/dist/types/sdk/session.d.ts +3 -1
- package/dist/types/session/agent-session.d.ts +1 -1
- package/dist/types/session/blob-store.d.ts +1 -1
- package/dist/types/session/fallback-chain-controller.d.ts +3 -6
- package/dist/types/session/internal/managed-session-scope.d.ts +44 -0
- package/dist/types/session/primary-control-surface.d.ts +4 -0
- package/dist/types/session/session-manager.d.ts +6 -0
- package/dist/types/system-prompt.d.ts +6 -0
- package/dist/types/tools/ask.d.ts +25 -0
- package/dist/types/tools/image-gen.d.ts +0 -4
- package/dist/types/tools/skill-discovery.d.ts +7 -5
- package/dist/types/tools/ultragoal-ask-guard.d.ts +7 -4
- package/dist/types/utils/changelog.d.ts +0 -9
- package/dist/types/utils/mupdf-wasm.d.ts +1 -0
- package/package.json +9 -8
- package/scripts/compile-args.ts +8 -4
- package/src/capability/fs.ts +395 -17
- package/src/capability/index.ts +273 -10
- package/src/capability/types.ts +9 -0
- package/src/cli/customize-doctor.ts +18 -12
- package/src/cli/doctor/args.ts +236 -0
- package/src/cli/doctor/checks.ts +431 -0
- package/src/cli/doctor/config-repairs.ts +517 -0
- package/src/cli/doctor/context.ts +149 -0
- package/src/cli/doctor/files.ts +149 -0
- package/src/cli/doctor/ids.ts +115 -0
- package/src/cli/doctor/install-repairs.ts +335 -0
- package/src/cli/doctor/journal.ts +423 -0
- package/src/cli/doctor/managed-link.ts +514 -0
- package/src/cli/doctor/native-probe.ts +13 -0
- package/src/cli/doctor/permission-repairs.ts +242 -0
- package/src/cli/doctor/plugin-quarantine.ts +377 -0
- package/src/cli/doctor/plugin-restore.ts +59 -0
- package/src/cli/doctor/plugin-targets.ts +373 -0
- package/src/cli/doctor/probe-client.ts +195 -0
- package/src/cli/doctor/probe-types.ts +21 -0
- package/src/cli/doctor/probe.ts +42 -0
- package/src/cli/doctor/projection-probe.ts +249 -0
- package/src/cli/doctor/repairs.ts +1157 -0
- package/src/cli/doctor/report.ts +176 -0
- package/src/cli/doctor/runner.ts +342 -0
- package/src/cli/doctor/safety.ts +40 -0
- package/src/cli/doctor/service-repairs.ts +452 -0
- package/src/cli/doctor/service-targets.ts +274 -0
- package/src/cli/doctor/types.ts +164 -0
- package/src/cli/doctor-cli.ts +62 -0
- package/src/cli/doctor-supervisor.ts +571 -0
- package/src/cli/doctor-worker.ts +181 -0
- package/src/cli/install-activation.ts +666 -0
- package/src/cli/macos-community-app.ts +1449 -0
- package/src/cli/mcp-cli.ts +11 -21
- package/src/cli/nofile-limit.ts +5 -1
- package/src/cli/plugin-cli.ts +6 -1
- package/src/cli/update-cli.ts +362 -264
- package/src/cli-main.ts +517 -0
- package/src/cli.ts +64 -433
- package/src/commands/autoresearch.ts +11 -5
- package/src/commands/completion.ts +1 -1
- package/src/commands/doctor.ts +13 -0
- package/src/commands/sdk.ts +58 -10
- package/src/commands/ultragoal.ts +11 -5
- package/src/config/autorouting-tier-map.ts +7 -0
- package/src/config/file-lock.ts +736 -71
- package/src/config/mcp-schema.json +3 -3
- package/src/config/model-preset-registry.ts +1 -0
- package/src/config/model-registry.ts +80 -27
- package/src/config/model-resolver.ts +33 -4
- package/src/config/models-config-schema.ts +2 -0
- package/src/config/settings-schema.ts +6 -2
- package/src/coordinator-mcp/question-gate-codec.ts +1 -0
- package/src/coordinator-mcp/server.ts +534 -51
- package/src/coordinator-mcp/session-reaper.ts +64 -8
- package/src/cursor.ts +223 -53
- package/src/discovery/agents-md.ts +74 -8
- package/src/discovery/agents.ts +32 -7
- package/src/discovery/builtin.ts +184 -75
- package/src/discovery/claude-plugins.ts +85 -17
- package/src/discovery/cline.ts +38 -10
- package/src/discovery/cursor.ts +19 -6
- package/src/discovery/gemini.ts +62 -22
- package/src/discovery/github.ts +13 -3
- package/src/discovery/helpers.ts +483 -89
- package/src/discovery/index.ts +1 -0
- package/src/discovery/mcp-json.ts +36 -10
- package/src/discovery/opencode.ts +36 -19
- package/src/discovery/ssh.ts +11 -8
- package/src/discovery/windsurf.ts +12 -3
- package/src/exec/bash-executor.ts +10 -3
- package/src/exec/isolated-shell.ts +15 -2
- package/src/extensibility/extensions/loader.ts +88 -26
- package/src/extensibility/gjc-plugins/lifecycle.ts +189 -0
- package/src/extensibility/gjc-plugins/paths.ts +4 -1
- package/src/extensibility/gjc-plugins/types.ts +27 -0
- package/src/extensibility/plugins/manager.ts +200 -22
- package/src/extensibility/plugins/marketplace/cache.ts +55 -2
- package/src/extensibility/plugins/marketplace/manager.ts +1262 -162
- package/src/extensibility/plugins/marketplace/registry.ts +153 -0
- package/src/extensibility/plugins/marketplace/source-resolver.ts +116 -10
- package/src/extensibility/runtime-skill-discovery.ts +61 -9
- package/src/extensibility/skill-management.ts +7 -1
- package/src/gjc-runtime/autoresearch-runtime.ts +10 -1
- package/src/gjc-runtime/launch-worktree.test.ts +248 -0
- package/src/gjc-runtime/launch-worktree.ts +275 -38
- package/src/gjc-runtime/repository-binding.ts +26 -1
- package/src/gjc-runtime/session-layout.ts +10 -0
- package/src/gjc-runtime/session-state-lock.ts +330 -23
- package/src/gjc-runtime/session-state-sidecar.ts +328 -80
- package/src/gjc-runtime/ultragoal-runtime.ts +10 -1
- package/src/harness-control-plane/session-lease.ts +2 -2
- package/src/internal-urls/docs-index.generated.ts +28 -26
- package/src/main.ts +150 -29
- package/src/memories/index.ts +24 -2
- package/src/modes/acp/acp-agent.ts +522 -68
- package/src/modes/components/agent-dashboard.ts +3 -1
- package/src/modes/components/model-selector.ts +28 -19
- package/src/modes/components/plugin-settings.ts +2 -1
- package/src/modes/controllers/selector-controller.ts +15 -9
- package/src/modes/interactive-mode.ts +21 -3
- package/src/prompts/system/system-prompt.md +5 -1
- package/src/prompts/tools/browser.md +1 -1
- package/src/prompts/tools/move-session.md +4 -0
- package/src/prompts/tools/read.md +2 -1
- package/src/prompts/tools/skill-discovery.md +6 -5
- package/src/prompts/tools/task.md +1 -0
- package/src/runtime-mcp/config-writer.ts +228 -0
- package/src/runtime-mcp/oauth-discovery.ts +114 -14
- package/src/runtime-mcp/policy-json-edit.ts +129 -0
- package/src/runtime-mcp/startup-policy.ts +14 -0
- package/src/runtime-mcp/types.ts +2 -2
- package/src/sdk/acp/adapter.ts +27 -12
- package/src/sdk/broker/broker.ts +273 -44
- package/src/sdk/broker/daemon-entry.ts +119 -0
- package/src/sdk/broker/discovery.ts +173 -20
- package/src/sdk/broker/doctor-restart.ts +206 -0
- package/src/sdk/broker/endpoint-authority.ts +36 -0
- package/src/sdk/broker/ensure.ts +49 -14
- package/src/sdk/broker/lifecycle.ts +174 -42
- package/src/sdk/broker/process-incarnation.ts +86 -2
- package/src/sdk/broker/runtime.ts +145 -21
- package/src/sdk/broker/session-index.ts +136 -22
- package/src/sdk/broker/spawn-substrate.ts +4 -1
- package/src/sdk/broker/transport.ts +5 -0
- package/src/sdk/broker/worktree-occupancy.ts +21 -1
- package/src/sdk/bus/chat-daemon-cli.ts +63 -0
- package/src/sdk/bus/chat-daemon-control.ts +260 -64
- package/src/sdk/bus/chat-daemon-runtime.ts +141 -25
- package/src/sdk/bus/daemon-startup-exclusion.ts +119 -0
- package/src/sdk/bus/doctor-daemon-restart-client.ts +291 -0
- package/src/sdk/bus/doctor-daemon-restart.ts +92 -0
- package/src/sdk/bus/index.ts +252 -51
- package/src/sdk/bus/kind-aware-reconciliation.ts +76 -41
- package/src/sdk/bus/notification-service.ts +21 -3
- package/src/sdk/bus/reconciliation-store.ts +17 -11
- package/src/sdk/bus/telegram-daemon-cli.ts +91 -5
- package/src/sdk/bus/telegram-daemon-contract.ts +1 -1
- package/src/sdk/bus/telegram-daemon-control.ts +47 -0
- package/src/sdk/bus/telegram-daemon-owner-registry.ts +1 -1
- package/src/sdk/bus/telegram-daemon.ts +178 -13
- package/src/sdk/cli/session-cli.ts +100 -12
- package/src/sdk/host/host.ts +2 -7
- package/src/sdk/host/session-runtime.test.ts +329 -8
- package/src/sdk/host/session-runtime.ts +202 -50
- package/src/sdk/host/surface-policy.ts +8 -1
- package/src/sdk/lifecycle/service.ts +199 -22
- package/src/sdk/mcp/server.ts +1 -1
- package/src/sdk/prompt-deadline-lease.ts +12 -4
- package/src/sdk/prompt-deadline-manager.ts +5 -7
- package/src/sdk/prompt-failure.ts +148 -0
- package/src/sdk/prompt-status.ts +30 -1
- package/src/sdk/prompt-watchdog.ts +11 -3
- package/src/sdk/protocol/operation-inventory.generated.json +18 -0
- package/src/sdk/protocol/operation-registry.ts +20 -8
- package/src/sdk/router/session-router.ts +8 -3
- package/src/sdk/service-artifact-paths.ts +26 -0
- package/src/sdk/session-authority.ts +10 -0
- package/src/sdk/session.ts +361 -194
- package/src/session/agent-session.ts +398 -93
- package/src/session/blob-store.ts +9 -9
- package/src/session/fallback-chain-controller.ts +3 -7
- package/src/session/internal/managed-session-scope.ts +445 -29
- package/src/session/internal/managed-session-storage.ts +38 -6
- package/src/session/primary-control-surface.ts +12 -0
- package/src/session/session-manager.ts +11 -3
- package/src/session/session-storage.ts +1 -1
- package/src/session-import/codex.ts +6 -1
- package/src/session-import/redact.ts +7 -0
- package/src/skill-state/workflow-mutation-guard.ts +645 -39
- package/src/slash-commands/builtin-registry.ts +7 -3
- package/src/system-prompt.ts +8 -0
- package/src/task/executor.ts +36 -3
- package/src/task/types.ts +27 -5
- package/src/tools/ask.ts +114 -34
- package/src/tools/browser/actions.ts +2 -2
- package/src/tools/browser/tab-worker.ts +11 -8
- package/src/tools/descriptors.ts +6 -1
- package/src/tools/fetch.ts +7 -2
- package/src/tools/image-gen.ts +33 -34
- package/src/tools/read.ts +78 -32
- package/src/tools/skill-discovery.ts +17 -7
- package/src/tools/tool-catalog.generated.ts +8 -8
- package/src/tools/ultragoal-ask-guard.ts +16 -26
- package/src/utils/changelog.ts +7 -1
- package/src/utils/git.ts +3 -1
- package/src/utils/markit.ts +24 -2
- package/src/utils/mupdf-wasm.ts +26 -0
- package/src/web/search/providers/openai-compatible.ts +191 -14
package/src/cli-main.ts
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* CLI entry point — registers all commands explicitly and delegates to the
|
|
5
|
+
* lightweight CLI runner from pi-utils.
|
|
6
|
+
*/
|
|
7
|
+
import "@gajae-code/utils/postmortem";
|
|
8
|
+
import { Args, type CliConfig, Command, type CommandEntry, run } from "@gajae-code/utils/cli";
|
|
9
|
+
import { APP_NAME, formatBunRuntimeError, MIN_BUN_VERSION, VERSION } from "@gajae-code/utils/dirs";
|
|
10
|
+
import { time } from "@gajae-code/utils/logger";
|
|
11
|
+
import { runFixtureReport } from "./cli/fixture-report";
|
|
12
|
+
import { ROOT_LAUNCH_FLAGS } from "./cli/root-flags";
|
|
13
|
+
import QuickLane from "./commands/quick-lane";
|
|
14
|
+
import { runBashShellGuardian } from "./exec/bash-shell-guardian";
|
|
15
|
+
import { runBashShellSupervisor } from "./exec/bash-shell-supervisor";
|
|
16
|
+
import { runBashShellWorker } from "./exec/bash-shell-worker";
|
|
17
|
+
import {
|
|
18
|
+
BASH_SHELL_RUNTIME_ARG,
|
|
19
|
+
BASH_SHELL_SUPERVISOR_ARG,
|
|
20
|
+
BASH_SHELL_WORKER_ARG,
|
|
21
|
+
} from "./exec/bash-shell-worker-protocol";
|
|
22
|
+
import { smokeTestIsolatedShell } from "./exec/isolated-shell";
|
|
23
|
+
import { smokeTestTabWorker } from "./tools/browser/tab-worker-smoke";
|
|
24
|
+
|
|
25
|
+
if (Bun.semver.order(Bun.version, MIN_BUN_VERSION) < 0) {
|
|
26
|
+
process.stderr.write(
|
|
27
|
+
formatBunRuntimeError({
|
|
28
|
+
currentVersion: Bun.version,
|
|
29
|
+
minVersion: MIN_BUN_VERSION,
|
|
30
|
+
execPath: process.execPath,
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
process.title = APP_NAME;
|
|
37
|
+
const rootHelpFlags = ["--help", "-h", "help"];
|
|
38
|
+
const versionFlags = ["--version", "-v"];
|
|
39
|
+
const MANAGED_OWNER_SUPERVISOR_ARG = "--internal-managed-owner-supervisor";
|
|
40
|
+
const MANAGED_OWNER_CHILD_TOKEN_ENV = "GJC_MANAGED_OWNER_CHILD_TOKEN";
|
|
41
|
+
const TMUX_OWNER_ISOLATION_ARG = "--internal-tmux-owner-isolation";
|
|
42
|
+
|
|
43
|
+
export const commands: CommandEntry[] = [
|
|
44
|
+
{ name: "doctor", load: () => import("./commands/doctor").then(m => m.default) },
|
|
45
|
+
{ name: "codex-native-hook", load: () => import("./commands/codex-native-hook").then(m => m.default) },
|
|
46
|
+
{ name: "state", load: () => import("./commands/state").then(m => m.default) },
|
|
47
|
+
{ name: "setup", load: () => import("./commands/setup").then(m => m.default) },
|
|
48
|
+
{ name: "acp", load: () => import("./commands/acp").then(m => m.default) },
|
|
49
|
+
{ name: "auth-broker", load: () => import("./commands/auth-broker").then(m => m.default) },
|
|
50
|
+
{ name: "auth-gateway", load: () => import("./commands/auth-gateway").then(m => m.default) },
|
|
51
|
+
{ name: "skills", load: () => import("./commands/skills").then(m => m.default) },
|
|
52
|
+
{ name: "session", load: () => import("./commands/session").then(m => m.default) },
|
|
53
|
+
{ name: "accounts", load: () => import("./commands/accounts").then(m => m.default) },
|
|
54
|
+
{ name: "harness", load: () => import("./commands/harness").then(m => m.default) },
|
|
55
|
+
{ name: "coordinator", load: () => import("./commands/coordinator").then(m => m.default) },
|
|
56
|
+
{ name: "ultragoal", load: () => import("./commands/ultragoal").then(m => m.default) },
|
|
57
|
+
{ name: "gc", load: () => import("./commands/gc").then(m => m.default) },
|
|
58
|
+
{ name: "crash", load: () => import("./commands/crash").then(m => m.default) },
|
|
59
|
+
{ name: "autoresearch", load: () => import("./commands/autoresearch").then(m => m.default) },
|
|
60
|
+
{ name: "ralplan", load: () => import("./commands/ralplan").then(m => m.default) },
|
|
61
|
+
{ name: "config", load: () => import("./commands/config").then(m => m.default) },
|
|
62
|
+
{ name: "stats", load: () => import("./commands/stats").then(m => m.default) },
|
|
63
|
+
{ name: "notify", load: () => import("./commands/notify").then(m => m.default) },
|
|
64
|
+
{ name: "sdk", load: () => import("./commands/sdk").then(m => m.default) },
|
|
65
|
+
{ name: "daemon", load: () => import("./commands/daemon").then(m => m.default) },
|
|
66
|
+
{ name: "web-search", aliases: ["q"], load: () => import("./commands/web-search").then(m => m.default) },
|
|
67
|
+
{ name: "local-provider", load: () => import("./commands/local-provider").then(m => m.default) },
|
|
68
|
+
{ name: "model-presets", load: () => import("./commands/model-presets").then(m => m.default) },
|
|
69
|
+
{ name: "mcp-serve", load: () => import("./commands/mcp-serve").then(m => m.default) },
|
|
70
|
+
{ name: "mcp", load: () => import("./commands/mcp").then(m => m.default) },
|
|
71
|
+
{
|
|
72
|
+
name: "contribute-pr",
|
|
73
|
+
aliases: ["contribution-prep"],
|
|
74
|
+
load: () => import("./commands/contribution-prep").then(m => m.default),
|
|
75
|
+
},
|
|
76
|
+
{ name: "deep-interview", load: () => import("./commands/deep-interview").then(m => m.default) },
|
|
77
|
+
{ name: "migrate", load: () => import("./commands/migrate").then(m => m.default) },
|
|
78
|
+
{ name: "update", load: () => import("./commands/update").then(m => m.default) },
|
|
79
|
+
{ name: "read", load: () => import("./commands/read").then(m => m.default) },
|
|
80
|
+
{ name: "customize", load: () => import("./commands/customize").then(m => m.default) },
|
|
81
|
+
{ name: "plugin", load: () => import("./commands/plugin").then(m => m.default) },
|
|
82
|
+
{ name: "completion", load: () => import("./commands/completion").then(m => m.default) },
|
|
83
|
+
{ name: "launch", load: () => import("./commands/launch").then(m => m.default) },
|
|
84
|
+
{ name: "quick-lane", load: async () => QuickLane },
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
async function showHelp(config: CliConfig): Promise<void> {
|
|
88
|
+
const { renderRootHelp } = await import("@gajae-code/utils/cli");
|
|
89
|
+
const { getExtraHelpText } = await import("./cli/fast-help");
|
|
90
|
+
renderRootHelp(config);
|
|
91
|
+
const extra = getExtraHelpText();
|
|
92
|
+
if (extra.trim().length > 0) {
|
|
93
|
+
process.stdout.write(`\n${extra}\n`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function installRuntimeGlobals(): Promise<void> {
|
|
98
|
+
const { installH2Fetch } = await import("@gajae-code/ai/utils/h2-fetch");
|
|
99
|
+
// Activate HTTP/2 for all `fetch()` calls (provider streams, OAuth, model
|
|
100
|
+
// discovery, web tools). Bun's HTTP/2 client is gated on a startup flag we
|
|
101
|
+
// can't toggle from JS, so we patch globalThis.fetch to pass
|
|
102
|
+
// `protocol: "http2"` per request, with transparent HTTP/1.1 fallback on
|
|
103
|
+
// `HTTP2Unsupported`. See @gajae-code/ai/utils/h2-fetch for details.
|
|
104
|
+
installH2Fetch();
|
|
105
|
+
|
|
106
|
+
const { warnIfMacOSNoFileLimitTooLow } = await import("./cli/nofile-limit");
|
|
107
|
+
warnIfMacOSNoFileLimitTooLow();
|
|
108
|
+
|
|
109
|
+
// Secondary in-process scrub of the macOS malloc-stack-logging vars. The real
|
|
110
|
+
// boundary is the darwin re-exec guard at the top of runCli(): Bun snapshots the
|
|
111
|
+
// spawn-default environment at startup, so deleting these here does NOT clean the
|
|
112
|
+
// env children inherit by default — it only tidies `process.env` for code that
|
|
113
|
+
// reads it directly. Kept as belt-and-braces for the rare re-exec-unavailable
|
|
114
|
+
// fallback; managed spawns already use filterProcessEnv and the native PTY lane
|
|
115
|
+
// strips them independently.
|
|
116
|
+
delete process.env.MallocStackLogging;
|
|
117
|
+
delete process.env.MallocStackLoggingNoCompact;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function isStatsHelpFastPath(argv: string[]): boolean {
|
|
121
|
+
return argv[0] === "stats" && (argv.includes("--help") || argv.includes("-h"));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function showStatsFastHelp(): void {
|
|
125
|
+
process.stdout.write(`Usage: ${APP_NAME} stats [options]
|
|
126
|
+
|
|
127
|
+
View usage statistics
|
|
128
|
+
|
|
129
|
+
Options:
|
|
130
|
+
-p, --port <number> Port for the dashboard server (default: 3847)
|
|
131
|
+
-j, --json Output stats as JSON
|
|
132
|
+
-s, --summary Print summary to console
|
|
133
|
+
-h, --help Show this help
|
|
134
|
+
`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function interactiveBootstrapText(
|
|
138
|
+
argv: readonly string[],
|
|
139
|
+
stdinIsTTY = process.stdin.isTTY,
|
|
140
|
+
stdoutIsTTY = process.stdout.isTTY,
|
|
141
|
+
): string | undefined {
|
|
142
|
+
if (!stdinIsTTY || !stdoutIsTTY || argv[0] !== "launch") return undefined;
|
|
143
|
+
for (let index = 1; index < argv.length; index++) {
|
|
144
|
+
const arg = argv[index];
|
|
145
|
+
if (
|
|
146
|
+
arg === "--print" ||
|
|
147
|
+
arg?.startsWith("--print=") ||
|
|
148
|
+
arg === "-p" ||
|
|
149
|
+
arg === "--export" ||
|
|
150
|
+
arg?.startsWith("--export=") ||
|
|
151
|
+
arg === "--list-models" ||
|
|
152
|
+
arg?.startsWith("--list-models=") ||
|
|
153
|
+
arg === "--mode" ||
|
|
154
|
+
arg?.startsWith("--mode=") ||
|
|
155
|
+
arg === "--help" ||
|
|
156
|
+
arg?.startsWith("--help=") ||
|
|
157
|
+
arg === "-h" ||
|
|
158
|
+
arg === "--version" ||
|
|
159
|
+
arg?.startsWith("--version=") ||
|
|
160
|
+
arg === "-v"
|
|
161
|
+
)
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
return "\u001b[?25h\u001b[38;5;45mGJC\u001b[0m warming workspace\r\n\r\n> ";
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function isNotifyDaemonInternalFastPath(argv: string[]): boolean {
|
|
168
|
+
return argv[0] === "notify" && argv[1] === "daemon-internal";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function runNotifyDaemonInternalFastPath(argv: string[]): Promise<void> {
|
|
172
|
+
const { parseNotifyArgs, runNotifyCommand } = await import("./cli/notify-cli");
|
|
173
|
+
const cmd = parseNotifyArgs(argv);
|
|
174
|
+
if (cmd?.action !== "daemon-internal") {
|
|
175
|
+
throw new Error("invalid notify daemon-internal fast path");
|
|
176
|
+
}
|
|
177
|
+
await runNotifyCommand(cmd);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function isChatDaemonInternalFastPath(argv: string[]): boolean {
|
|
181
|
+
return argv[0] === "daemon" && (argv[1] === "discord-internal" || argv[1] === "slack-internal");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async function runChatDaemonInternalFastPath(argv: string[]): Promise<void> {
|
|
185
|
+
const action = argv[1];
|
|
186
|
+
if (action !== "discord-internal" && action !== "slack-internal") {
|
|
187
|
+
throw new Error("invalid chat daemon internal fast path");
|
|
188
|
+
}
|
|
189
|
+
const { runChatDaemonInternal } = await import("./sdk/bus/chat-daemon-cli");
|
|
190
|
+
await runChatDaemonInternal(action === "discord-internal" ? "discord" : "slack", argv.slice(2));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
type MemoryGuardNativeSmokeLoad = () => Record<string, unknown>;
|
|
194
|
+
type WindowsJobMemoryProbeResult = Record<string, unknown> & { kind: string };
|
|
195
|
+
type MemoryGuardNativeSmokeReceipt = {
|
|
196
|
+
api: "memory_guard_windows_job_probe_v1";
|
|
197
|
+
source: "pi_natives";
|
|
198
|
+
result: WindowsJobMemoryProbeResult;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export function isMemoryGuardNativeSmokeFastPath(argv: readonly string[]): boolean {
|
|
202
|
+
return (
|
|
203
|
+
argv.length === 3 && argv[0] === "internal" && argv[1] === "memory-guard-native-smoke" && argv[2] === "--json"
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function parseWindowsJobMemoryProbeResult(value: unknown): WindowsJobMemoryProbeResult {
|
|
208
|
+
if (!value || typeof value !== "object") {
|
|
209
|
+
throw new Error("memory-guard-native-smoke: native probe returned a non-object result");
|
|
210
|
+
}
|
|
211
|
+
const result = value as Record<string, unknown>;
|
|
212
|
+
if (typeof result.kind !== "string") {
|
|
213
|
+
throw new Error("memory-guard-native-smoke: native probe result is missing a string kind tag");
|
|
214
|
+
}
|
|
215
|
+
return result as WindowsJobMemoryProbeResult;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function runMemoryGuardNativeSmokeFastPath(
|
|
219
|
+
options: { loadNative?: MemoryGuardNativeSmokeLoad; writeStdout?: (text: string) => void } = {},
|
|
220
|
+
): void {
|
|
221
|
+
if (!options.loadNative)
|
|
222
|
+
throw new Error("memory-guard-native-smoke: native loader is unavailable on the static CLI path");
|
|
223
|
+
const probe = options.loadNative().probeWindowsJobMemory;
|
|
224
|
+
if (typeof probe !== "function") {
|
|
225
|
+
throw new Error("memory-guard-native-smoke: probeWindowsJobMemory export missing from native addon");
|
|
226
|
+
}
|
|
227
|
+
const receipt: MemoryGuardNativeSmokeReceipt = {
|
|
228
|
+
api: "memory_guard_windows_job_probe_v1",
|
|
229
|
+
source: "pi_natives",
|
|
230
|
+
result: parseWindowsJobMemoryProbeResult((probe as () => unknown)()),
|
|
231
|
+
};
|
|
232
|
+
(options.writeStdout ?? (text => process.stdout.write(text)))(`${JSON.stringify(receipt)}\n`);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async function runMemoryGuardNativeSmokeFastPathFromCli(): Promise<void> {
|
|
236
|
+
const { runMemoryGuardNativeSmoke } = await import("./cli/native-smoke");
|
|
237
|
+
runMemoryGuardNativeSmoke();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function isLaunchWorktreeSelector(arg: string): boolean {
|
|
241
|
+
return (
|
|
242
|
+
arg === "--worktree" ||
|
|
243
|
+
arg === "-w" ||
|
|
244
|
+
arg.startsWith("--worktree=") ||
|
|
245
|
+
arg.startsWith("-w=") ||
|
|
246
|
+
(arg.startsWith("-w") && arg.length > 2)
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function rootFlagDescriptor(arg: string) {
|
|
251
|
+
if (arg.startsWith("--") && !arg.includes("="))
|
|
252
|
+
return ROOT_LAUNCH_FLAGS[arg.slice(2) as keyof typeof ROOT_LAUNCH_FLAGS];
|
|
253
|
+
if (/^-[^-]$/.test(arg))
|
|
254
|
+
return Object.values(ROOT_LAUNCH_FLAGS).find(descriptor => descriptor.char === arg.slice(1));
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function rootFlagValueIndex(argv: readonly string[], index: number): number {
|
|
259
|
+
const descriptor = rootFlagDescriptor(argv[index] ?? "");
|
|
260
|
+
if (!descriptor || descriptor.kind === "boolean") return index;
|
|
261
|
+
const value = argv[index + 1];
|
|
262
|
+
return value && !value.startsWith("-") ? index + 1 : index;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function rootFixtureArg(argv: string[]): { present: boolean; id: string | undefined } {
|
|
266
|
+
for (let i = 0; i < argv.length; i++) {
|
|
267
|
+
const arg = argv[i] ?? "";
|
|
268
|
+
if (arg === "--" || isSubcommand(arg)) return { present: false, id: undefined };
|
|
269
|
+
if (arg === "--fixture") return { present: true, id: argv[i + 1] };
|
|
270
|
+
const descriptor = rootFlagDescriptor(arg);
|
|
271
|
+
if (descriptor && descriptor.kind !== "boolean") {
|
|
272
|
+
const value = argv[i + 1];
|
|
273
|
+
if (!value || value.startsWith("-")) return { present: false, id: undefined };
|
|
274
|
+
i++;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return { present: false, id: undefined };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function hasRootFastFlag(argv: string[], flags: readonly string[]): boolean {
|
|
281
|
+
for (let i = 0; i < argv.length; i++) {
|
|
282
|
+
const arg = argv[i] ?? "";
|
|
283
|
+
if (arg === "--" || isSubcommand(arg) || isLaunchWorktreeSelector(arg)) return false;
|
|
284
|
+
if (flags.includes(arg)) return true;
|
|
285
|
+
i = rootFlagValueIndex(argv, i);
|
|
286
|
+
}
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function hasRootHelpFlag(argv: string[]): boolean {
|
|
291
|
+
return hasRootFastFlag(argv, rootHelpFlags);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function hasRootVersionFlag(argv: string[]): boolean {
|
|
295
|
+
return hasRootFastFlag(argv, versionFlags);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export class RootHelpCommand extends Command {
|
|
299
|
+
static description = "Red-claw AI coding assistant";
|
|
300
|
+
static hidden = true;
|
|
301
|
+
static args = {
|
|
302
|
+
messages: Args.string({
|
|
303
|
+
description: "Messages to send (prefix files with @)",
|
|
304
|
+
required: false,
|
|
305
|
+
multiple: true,
|
|
306
|
+
}),
|
|
307
|
+
};
|
|
308
|
+
static flags = ROOT_LAUNCH_FLAGS;
|
|
309
|
+
static examples = [
|
|
310
|
+
`# Interactive mode\n ${APP_NAME}`,
|
|
311
|
+
`# Interactive mode with initial prompt\n ${APP_NAME} "List all .ts files in src/"`,
|
|
312
|
+
`# Include files in initial message\n ${APP_NAME} @prompt.md @image.png "What color is the sky?"`,
|
|
313
|
+
`# Non-interactive mode (process and exit)\n ${APP_NAME} -p "List all .ts files in src/"`,
|
|
314
|
+
`# Continue previous session\n ${APP_NAME} --continue "What did we discuss?"`,
|
|
315
|
+
`# Launch in a sibling git worktree\n ${APP_NAME} --worktree`,
|
|
316
|
+
`# Use different model (fuzzy matching)\n ${APP_NAME} --model opus "Help me refactor this code"`,
|
|
317
|
+
`# Limit model cycling to specific models\n ${APP_NAME} --models claude-sonnet,claude-haiku,gpt-4o`,
|
|
318
|
+
`# Pin a stored credential for this session\n ${APP_NAME} --credential email:me@example.com`,
|
|
319
|
+
`# Prefer a stored credential, falling back on quota limits\n ${APP_NAME} --prefer-credential id:15`,
|
|
320
|
+
`# Activate a model profile for this session\n ${APP_NAME} --mpreset codex-medium`,
|
|
321
|
+
`# Persist a model profile as the default\n ${APP_NAME} --mpreset opencodego --default`,
|
|
322
|
+
`# Export a session file to HTML\n ${APP_NAME} --export ~/.gjc/agent/sessions/--path--/session.jsonl`,
|
|
323
|
+
];
|
|
324
|
+
static strict = false;
|
|
325
|
+
async run(): Promise<void> {}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Determine whether argv[0] is a known subcommand name.
|
|
330
|
+
* If not, the entire argv is treated as args to the default "launch" command.
|
|
331
|
+
*/
|
|
332
|
+
function isSubcommand(first: string | undefined): boolean {
|
|
333
|
+
if (!first || first.startsWith("-") || first.startsWith("@")) return false;
|
|
334
|
+
return commands.some(e => e.name === first || e.aliases?.includes(first));
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Smoke-test entry. Spawns the stats sync worker and the browser tab worker, then verifies their protocol.
|
|
339
|
+
*
|
|
340
|
+
* Purpose: catch silent compiled-worker load regressions (issues #1011,
|
|
341
|
+
* #1027, and #2598). Neither `--version` nor `stats --summary` spawns both
|
|
342
|
+
* worker entries on a fresh install. This probe proves each bundled worker
|
|
343
|
+
* module resolves and evaluates; the tab-worker probe also completes its
|
|
344
|
+
* bootstrap/closed protocol without launching a browser. Wired into
|
|
345
|
+
* `scripts/install-tests/run-ci.sh` so binary / source-link / tarball installs
|
|
346
|
+
* exercise it on every CI run.
|
|
347
|
+
*/
|
|
348
|
+
async function runSmokeTest(): Promise<void> {
|
|
349
|
+
const { smokeTestSyncWorker } = await import("@gajae-code/stats");
|
|
350
|
+
await smokeTestSyncWorker();
|
|
351
|
+
const { runNativeSmokeTest } = await import("./cli/native-smoke");
|
|
352
|
+
await runNativeSmokeTest();
|
|
353
|
+
await smokeTestTabWorker();
|
|
354
|
+
await smokeTestIsolatedShell();
|
|
355
|
+
process.stdout.write("smoke-test: ok\n");
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Normalize the sole `gjc resume` alias into the value-less launch intent. */
|
|
359
|
+
export function normalizeResumeAlias(argv: readonly string[]): string[] {
|
|
360
|
+
return argv.length === 1 && argv[0] === "resume" ? ["--resume"] : [...argv];
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function routeLegacyRootArgv(argv: readonly string[]): string[] | undefined {
|
|
364
|
+
if (argv[0] === "coordinator-mcp") return ["mcp-serve", "coordinator", ...argv.slice(1)];
|
|
365
|
+
return undefined;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Map the common mistaken `models` subcommand spelling to non-agent listing.
|
|
370
|
+
*
|
|
371
|
+
* Agents frequently run `gjc models` from the bash tool expecting a catalog.
|
|
372
|
+
* Without this route, `models` was a positional launch prompt and nested agents
|
|
373
|
+
* re-invoked `gjc models`, spawning an unbounded process chain (#3857).
|
|
374
|
+
* Always rewrite to `launch --list-models` so the invocation exits after a
|
|
375
|
+
* bounded listing and never starts an interactive agent session.
|
|
376
|
+
*/
|
|
377
|
+
export function routeModelsAlias(argv: readonly string[]): string[] | undefined {
|
|
378
|
+
if (argv[0] !== "models") return undefined;
|
|
379
|
+
const rest = argv.slice(1);
|
|
380
|
+
if (rest[0] === "presets") return ["model-presets", ...rest.slice(1)];
|
|
381
|
+
if (rest.length === 0) return ["launch", "--list-models"];
|
|
382
|
+
// Pure search tokens become a single fuzzy pattern (matches --list-models).
|
|
383
|
+
if (rest.every(token => !token.startsWith("-") && !token.startsWith("@"))) {
|
|
384
|
+
return ["launch", "--list-models", rest.join(" ")];
|
|
385
|
+
}
|
|
386
|
+
// Mixed flags still go through list-models first so "models" is never a prompt.
|
|
387
|
+
return ["launch", "--list-models", ...rest];
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** Apply the same default-launch routing used by runCli after root fast paths. */
|
|
391
|
+
export function routeRootArgv(argv: readonly string[]): string[] {
|
|
392
|
+
const normalizedArgv = normalizeResumeAlias(argv);
|
|
393
|
+
const legacyArgv = routeLegacyRootArgv(normalizedArgv);
|
|
394
|
+
if (legacyArgv) return legacyArgv;
|
|
395
|
+
const modelsArgv = routeModelsAlias(normalizedArgv);
|
|
396
|
+
if (modelsArgv) return modelsArgv;
|
|
397
|
+
const first = normalizedArgv[0];
|
|
398
|
+
return first === "--help" || first === "-h" || first === "--version" || first === "-v" || first === "help"
|
|
399
|
+
? normalizedArgv
|
|
400
|
+
: isSubcommand(first)
|
|
401
|
+
? normalizedArgv
|
|
402
|
+
: ["launch", ...normalizedArgv];
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** Run the CLI with the given argv (no `process.argv` prefix). */
|
|
406
|
+
export async function runCliAfterAdmission(argv: string[]): Promise<void> {
|
|
407
|
+
if (argv.length === 1 && argv[0] === BASH_SHELL_WORKER_ARG) {
|
|
408
|
+
await runBashShellGuardian();
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (argv.length === 1 && argv[0] === BASH_SHELL_SUPERVISOR_ARG) {
|
|
412
|
+
await runBashShellSupervisor();
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (argv.length === 1 && argv[0] === BASH_SHELL_RUNTIME_ARG) {
|
|
416
|
+
await runBashShellWorker();
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
// macOS malloc-env launch boundary. Re-exec once with a scrubbed environment
|
|
420
|
+
// BEFORE any fast path or subprocess spawn, so the startup env snapshot Bun hands
|
|
421
|
+
// to every child lane (Bun.spawn defaults, node:child_process, native PTY, tmux
|
|
422
|
+
// owner, plugin installs, subagents) is clean. This runs ahead of the
|
|
423
|
+
// tmux-owner-isolation and notify-daemon fast paths so those lanes execute inside
|
|
424
|
+
// the already-scrubbed process too. The cheap inline predicate keeps the common
|
|
425
|
+
// (uncontaminated / non-darwin) path free of extra module loads; the guard module
|
|
426
|
+
// (MACOS_MALLOC_ENV_VARS / GJC_MALLOC_ENV_REEXEC) loads only when a re-exec is due.
|
|
427
|
+
if (
|
|
428
|
+
process.platform === "darwin" &&
|
|
429
|
+
process.env.GJC_MALLOC_ENV_REEXEC === undefined &&
|
|
430
|
+
(process.env.MallocStackLogging !== undefined || process.env.MallocStackLoggingNoCompact !== undefined)
|
|
431
|
+
) {
|
|
432
|
+
const { reexecWithScrubbedMallocEnv } = await import("./cli/malloc-env-guard");
|
|
433
|
+
const code = await reexecWithScrubbedMallocEnv();
|
|
434
|
+
if (code !== null) {
|
|
435
|
+
process.exitCode = code;
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
// Re-exec could not be spawned; fall through and run in this process.
|
|
439
|
+
}
|
|
440
|
+
if (isMemoryGuardNativeSmokeFastPath(argv)) {
|
|
441
|
+
await runMemoryGuardNativeSmokeFastPathFromCli();
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
if (argv.length === 1 && argv[0] === TMUX_OWNER_ISOLATION_ARG) {
|
|
445
|
+
const { runTmuxOwnerIsolationCliFromStdin } = await import("./gjc-runtime/tmux-owner-isolation-cli");
|
|
446
|
+
await runTmuxOwnerIsolationCliFromStdin();
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (argv.length === 1 && argv[0] === MANAGED_OWNER_SUPERVISOR_ARG) {
|
|
450
|
+
const { runManagedOwnerSupervisor } = await import("./gjc-runtime/managed-owner-supervisor");
|
|
451
|
+
await runManagedOwnerSupervisor();
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (process.env[MANAGED_OWNER_CHILD_TOKEN_ENV] !== undefined) {
|
|
455
|
+
const { admitManagedOwnerBeforeCli, completeManagedOwnerRecovery } = await import(
|
|
456
|
+
"./gjc-runtime/managed-owner-admission"
|
|
457
|
+
);
|
|
458
|
+
const admission = await admitManagedOwnerBeforeCli();
|
|
459
|
+
if (admission.kind === "blocked") return;
|
|
460
|
+
if (admission.kind === "recovery") {
|
|
461
|
+
await completeManagedOwnerRecovery(admission.context);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if (isNotifyDaemonInternalFastPath(argv)) {
|
|
466
|
+
await runNotifyDaemonInternalFastPath(argv);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (isChatDaemonInternalFastPath(argv)) {
|
|
470
|
+
await runChatDaemonInternalFastPath(argv);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
if (argv[0] === "--smoke-test") {
|
|
474
|
+
await runSmokeTest();
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const fixtureArg = rootFixtureArg(argv);
|
|
478
|
+
if (fixtureArg.present) {
|
|
479
|
+
const id = fixtureArg.id;
|
|
480
|
+
if (!id || id.startsWith("-")) {
|
|
481
|
+
process.stderr.write(`${APP_NAME} --fixture requires a fixture id\n`);
|
|
482
|
+
process.exitCode = 1;
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
process.exitCode = await runFixtureReport(id);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
const normalizedArgv = normalizeResumeAlias(argv);
|
|
489
|
+
const legacyArgv = routeLegacyRootArgv(normalizedArgv);
|
|
490
|
+
const modelPresetsArgv =
|
|
491
|
+
normalizedArgv[0] === "models" && normalizedArgv[1] === "presets" ? routeModelsAlias(normalizedArgv) : undefined;
|
|
492
|
+
if (!legacyArgv && !modelPresetsArgv && hasRootHelpFlag(normalizedArgv)) {
|
|
493
|
+
const { renderRootHelp } = await import("@gajae-code/utils/cli");
|
|
494
|
+
const { getExtraHelpText } = await import("./cli/fast-help");
|
|
495
|
+
renderRootHelp({ bin: APP_NAME, version: VERSION, commands: new Map([["launch", RootHelpCommand]]) });
|
|
496
|
+
const extra = getExtraHelpText();
|
|
497
|
+
if (extra.trim().length > 0) {
|
|
498
|
+
process.stdout.write(`\n${extra}\n`);
|
|
499
|
+
}
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (!legacyArgv && hasRootVersionFlag(normalizedArgv)) {
|
|
503
|
+
process.stdout.write(`${APP_NAME}/${VERSION}\n`);
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const runArgv = legacyArgv ?? modelPresetsArgv ?? routeRootArgv(normalizedArgv);
|
|
507
|
+
if (isStatsHelpFastPath(runArgv)) {
|
|
508
|
+
showStatsFastHelp();
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
const bootstrap = interactiveBootstrapText(runArgv);
|
|
512
|
+
if (bootstrap) process.stdout.write(bootstrap);
|
|
513
|
+
await time("cli:installRuntimeGlobals", installRuntimeGlobals);
|
|
514
|
+
return time("cli:dispatch", () => run({ bin: APP_NAME, version: VERSION, argv: runArgv, commands, help: showHelp }));
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
export const runCli = runCliAfterAdmission;
|