oh-my-codex 0.11.11 → 0.11.13
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/Cargo.lock +5 -5
- package/Cargo.toml +1 -1
- package/README.de.md +12 -6
- package/README.el.md +223 -0
- package/README.es.md +12 -6
- package/README.fr.md +11 -5
- package/README.it.md +12 -6
- package/README.ja.md +12 -6
- package/README.ko.md +12 -6
- package/README.md +56 -28
- package/README.pl.md +216 -0
- package/README.pt.md +12 -6
- package/README.ru.md +12 -6
- package/README.tr.md +12 -6
- package/README.vi.md +148 -183
- package/README.zh-TW.md +14 -17
- package/README.zh.md +12 -6
- package/crates/omx-runtime-core/src/engine.rs +122 -4
- package/crates/omx-runtime-core/src/lib.rs +17 -0
- package/dist/autoresearch/contracts.d.ts.map +1 -1
- package/dist/autoresearch/contracts.js +1 -0
- package/dist/autoresearch/contracts.js.map +1 -1
- package/dist/autoresearch/runtime.d.ts.map +1 -1
- package/dist/autoresearch/runtime.js +7 -1
- package/dist/autoresearch/runtime.js.map +1 -1
- package/dist/cli/__tests__/agents.test.js +24 -1
- package/dist/cli/__tests__/agents.test.js.map +1 -1
- package/dist/cli/__tests__/autoresearch.test.js +11 -0
- package/dist/cli/__tests__/autoresearch.test.js.map +1 -1
- package/dist/cli/__tests__/cleanup.test.js +117 -4
- package/dist/cli/__tests__/cleanup.test.js.map +1 -1
- package/dist/cli/__tests__/doctor-warning-copy.test.js +33 -3
- package/dist/cli/__tests__/doctor-warning-copy.test.js.map +1 -1
- package/dist/cli/__tests__/error-handling-warnings.test.js +13 -0
- package/dist/cli/__tests__/error-handling-warnings.test.js.map +1 -1
- package/dist/cli/__tests__/exec.test.js +6 -0
- package/dist/cli/__tests__/exec.test.js.map +1 -1
- package/dist/cli/__tests__/index.test.js +101 -1
- package/dist/cli/__tests__/index.test.js.map +1 -1
- package/dist/cli/__tests__/launch-fallback.test.js +3 -0
- package/dist/cli/__tests__/launch-fallback.test.js.map +1 -1
- package/dist/cli/__tests__/package-bin-contract.test.js +10 -0
- package/dist/cli/__tests__/package-bin-contract.test.js.map +1 -1
- package/dist/cli/__tests__/packaged-script-resolution.test.js +4 -3
- package/dist/cli/__tests__/packaged-script-resolution.test.js.map +1 -1
- package/dist/cli/__tests__/resume.test.js +6 -0
- package/dist/cli/__tests__/resume.test.js.map +1 -1
- package/dist/cli/__tests__/setup-refresh.test.js +29 -12
- package/dist/cli/__tests__/setup-refresh.test.js.map +1 -1
- package/dist/cli/__tests__/setup-scope.test.js +1 -1
- package/dist/cli/__tests__/setup-scope.test.js.map +1 -1
- package/dist/cli/__tests__/star-prompt.test.js +16 -0
- package/dist/cli/__tests__/star-prompt.test.js.map +1 -1
- package/dist/cli/__tests__/uninstall.test.js +112 -1
- package/dist/cli/__tests__/uninstall.test.js.map +1 -1
- package/dist/cli/__tests__/windows-popup-loop-contract.test.d.ts +2 -0
- package/dist/cli/__tests__/windows-popup-loop-contract.test.d.ts.map +1 -0
- package/dist/cli/__tests__/windows-popup-loop-contract.test.js +30 -0
- package/dist/cli/__tests__/windows-popup-loop-contract.test.js.map +1 -0
- package/dist/cli/agents.d.ts.map +1 -1
- package/dist/cli/agents.js +9 -3
- package/dist/cli/agents.js.map +1 -1
- package/dist/cli/autoresearch-guided.d.ts.map +1 -1
- package/dist/cli/autoresearch-guided.js +9 -3
- package/dist/cli/autoresearch-guided.js.map +1 -1
- package/dist/cli/autoresearch.d.ts.map +1 -1
- package/dist/cli/autoresearch.js +8 -2
- package/dist/cli/autoresearch.js.map +1 -1
- package/dist/cli/cleanup.d.ts +2 -0
- package/dist/cli/cleanup.d.ts.map +1 -1
- package/dist/cli/cleanup.js +27 -1
- package/dist/cli/cleanup.js.map +1 -1
- package/dist/cli/doctor.js +7 -0
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/index.d.ts +9 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +171 -55
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli/setup.js +18 -15
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli/star-prompt.d.ts.map +1 -1
- package/dist/cli/star-prompt.js +2 -0
- package/dist/cli/star-prompt.js.map +1 -1
- package/dist/cli/team.d.ts.map +1 -1
- package/dist/cli/team.js +5 -1
- package/dist/cli/team.js.map +1 -1
- package/dist/cli/tmux-hook.d.ts.map +1 -1
- package/dist/cli/tmux-hook.js +4 -1
- package/dist/cli/tmux-hook.js.map +1 -1
- package/dist/cli/uninstall.d.ts.map +1 -1
- package/dist/cli/uninstall.js +26 -0
- package/dist/cli/uninstall.js.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/update.js +1 -0
- package/dist/cli/update.js.map +1 -1
- package/dist/compat/__tests__/rust-runtime-compat.test.js +84 -1
- package/dist/compat/__tests__/rust-runtime-compat.test.js.map +1 -1
- package/dist/config/__tests__/generator-idempotent.test.js +4 -4
- package/dist/config/__tests__/generator-idempotent.test.js.map +1 -1
- package/dist/config/__tests__/mcp-registry.test.js +13 -16
- package/dist/config/__tests__/mcp-registry.test.js.map +1 -1
- package/dist/config/mcp-registry.d.ts +1 -0
- package/dist/config/mcp-registry.d.ts.map +1 -1
- package/dist/config/mcp-registry.js +4 -4
- package/dist/config/mcp-registry.js.map +1 -1
- package/dist/config/models.d.ts +1 -0
- package/dist/config/models.d.ts.map +1 -1
- package/dist/config/models.js +39 -1
- package/dist/config/models.js.map +1 -1
- package/dist/hooks/__tests__/keyword-detector.test.js +12 -1
- package/dist/hooks/__tests__/keyword-detector.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-fallback-watcher.test.js +554 -18
- package/dist/hooks/__tests__/notify-fallback-watcher.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-auto-nudge.test.js +347 -16
- package/dist/hooks/__tests__/notify-hook-auto-nudge.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-modules.test.js +5 -0
- package/dist/hooks/__tests__/notify-hook-modules.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-ralph-resume.test.d.ts +2 -0
- package/dist/hooks/__tests__/notify-hook-ralph-resume.test.d.ts.map +1 -0
- package/dist/hooks/__tests__/notify-hook-ralph-resume.test.js +597 -0
- package/dist/hooks/__tests__/notify-hook-ralph-resume.test.js.map +1 -0
- package/dist/hooks/__tests__/notify-hook-regression-205.test.js +19 -1
- package/dist/hooks/__tests__/notify-hook-regression-205.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-session-scope.test.js +73 -53
- package/dist/hooks/__tests__/notify-hook-session-scope.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-team-dispatch.test.js +193 -2
- package/dist/hooks/__tests__/notify-hook-team-dispatch.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-team-leader-nudge.test.js +183 -0
- package/dist/hooks/__tests__/notify-hook-team-leader-nudge.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-tmux-heal.test.js +255 -97
- package/dist/hooks/__tests__/notify-hook-tmux-heal.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-tmux-scrollback.test.js +0 -0
- package/dist/hooks/__tests__/notify-hook-tmux-scrollback.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-worker-idle.test.js +46 -0
- package/dist/hooks/__tests__/notify-hook-worker-idle.test.js.map +1 -1
- package/dist/hooks/__tests__/prompt-team-routing.test.js +34 -0
- package/dist/hooks/__tests__/prompt-team-routing.test.js.map +1 -1
- package/dist/hooks/__tests__/tmux-hook-engine.test.js +32 -1
- package/dist/hooks/__tests__/tmux-hook-engine.test.js.map +1 -1
- package/dist/hooks/code-simplifier/index.d.ts.map +1 -1
- package/dist/hooks/code-simplifier/index.js +1 -0
- package/dist/hooks/code-simplifier/index.js.map +1 -1
- package/dist/hooks/codebase-map.d.ts.map +1 -1
- package/dist/hooks/codebase-map.js +1 -0
- package/dist/hooks/codebase-map.js.map +1 -1
- package/dist/hooks/extensibility/sdk/tmux.d.ts.map +1 -1
- package/dist/hooks/extensibility/sdk/tmux.js +3 -1
- package/dist/hooks/extensibility/sdk/tmux.js.map +1 -1
- package/dist/hooks/keyword-detector.d.ts +1 -0
- package/dist/hooks/keyword-detector.d.ts.map +1 -1
- package/dist/hooks/keyword-detector.js +48 -0
- package/dist/hooks/keyword-detector.js.map +1 -1
- package/dist/hooks/prompt-guidance-contract.d.ts.map +1 -1
- package/dist/hooks/prompt-guidance-contract.js +6 -0
- package/dist/hooks/prompt-guidance-contract.js.map +1 -1
- package/dist/hooks/session.d.ts.map +1 -1
- package/dist/hooks/session.js +1 -0
- package/dist/hooks/session.js.map +1 -1
- package/dist/hud/__tests__/state.test.js +70 -1
- package/dist/hud/__tests__/state.test.js.map +1 -1
- package/dist/hud/authority.d.ts.map +1 -1
- package/dist/hud/authority.js +1 -0
- package/dist/hud/authority.js.map +1 -1
- package/dist/hud/state.d.ts.map +1 -1
- package/dist/hud/state.js +52 -0
- package/dist/hud/state.js.map +1 -1
- package/dist/mcp/state-server.d.ts.map +1 -1
- package/dist/mcp/state-server.js +5 -0
- package/dist/mcp/state-server.js.map +1 -1
- package/dist/modes/__tests__/base-session-scope.test.js +46 -0
- package/dist/modes/__tests__/base-session-scope.test.js.map +1 -1
- package/dist/modes/base.d.ts.map +1 -1
- package/dist/modes/base.js +4 -0
- package/dist/modes/base.js.map +1 -1
- package/dist/notifications/__tests__/custom-alias-enablement.test.d.ts +2 -0
- package/dist/notifications/__tests__/custom-alias-enablement.test.d.ts.map +1 -0
- package/dist/notifications/__tests__/custom-alias-enablement.test.js +84 -0
- package/dist/notifications/__tests__/custom-alias-enablement.test.js.map +1 -0
- package/dist/notifications/__tests__/idle-cooldown.test.js +55 -0
- package/dist/notifications/__tests__/idle-cooldown.test.js.map +1 -1
- package/dist/notifications/idle-cooldown.d.ts +8 -6
- package/dist/notifications/idle-cooldown.d.ts.map +1 -1
- package/dist/notifications/idle-cooldown.js +53 -22
- package/dist/notifications/idle-cooldown.js.map +1 -1
- package/dist/notifications/notifier.js +1 -1
- package/dist/notifications/notifier.js.map +1 -1
- package/dist/notifications/reply-listener.d.ts.map +1 -1
- package/dist/notifications/reply-listener.js +1 -0
- package/dist/notifications/reply-listener.js.map +1 -1
- package/dist/notifications/tmux.d.ts.map +1 -1
- package/dist/notifications/tmux.js +4 -0
- package/dist/notifications/tmux.js.map +1 -1
- package/dist/openclaw/config.js +2 -2
- package/dist/openclaw/config.js.map +1 -1
- package/dist/runtime/bridge.d.ts +2 -0
- package/dist/runtime/bridge.d.ts.map +1 -1
- package/dist/runtime/bridge.js +8 -0
- package/dist/runtime/bridge.js.map +1 -1
- package/dist/scripts/notify-fallback-watcher.js +103 -53
- package/dist/scripts/notify-fallback-watcher.js.map +1 -1
- package/dist/scripts/notify-hook/auto-nudge.d.ts +2 -1
- package/dist/scripts/notify-hook/auto-nudge.d.ts.map +1 -1
- package/dist/scripts/notify-hook/auto-nudge.js +90 -104
- package/dist/scripts/notify-hook/auto-nudge.js.map +1 -1
- package/dist/scripts/notify-hook/managed-tmux.d.ts +19 -0
- package/dist/scripts/notify-hook/managed-tmux.d.ts.map +1 -0
- package/dist/scripts/notify-hook/managed-tmux.js +320 -0
- package/dist/scripts/notify-hook/managed-tmux.js.map +1 -0
- package/dist/scripts/notify-hook/operational-events.d.ts.map +1 -1
- package/dist/scripts/notify-hook/operational-events.js +2 -0
- package/dist/scripts/notify-hook/operational-events.js.map +1 -1
- package/dist/scripts/notify-hook/ralph-session-resume.d.ts +22 -0
- package/dist/scripts/notify-hook/ralph-session-resume.d.ts.map +1 -0
- package/dist/scripts/notify-hook/ralph-session-resume.js +277 -0
- package/dist/scripts/notify-hook/ralph-session-resume.js.map +1 -0
- package/dist/scripts/notify-hook/state-io.d.ts +1 -1
- package/dist/scripts/notify-hook/state-io.d.ts.map +1 -1
- package/dist/scripts/notify-hook/state-io.js +2 -10
- package/dist/scripts/notify-hook/state-io.js.map +1 -1
- package/dist/scripts/notify-hook/team-dispatch.d.ts +1 -1
- package/dist/scripts/notify-hook/team-dispatch.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-dispatch.js +123 -72
- package/dist/scripts/notify-hook/team-dispatch.js.map +1 -1
- package/dist/scripts/notify-hook/team-leader-nudge.d.ts +2 -1
- package/dist/scripts/notify-hook/team-leader-nudge.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-leader-nudge.js +13 -5
- package/dist/scripts/notify-hook/team-leader-nudge.js.map +1 -1
- package/dist/scripts/notify-hook/team-tmux-guard.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-tmux-guard.js +1 -19
- package/dist/scripts/notify-hook/team-tmux-guard.js.map +1 -1
- package/dist/scripts/notify-hook/team-worker.js +4 -4
- package/dist/scripts/notify-hook/team-worker.js.map +1 -1
- package/dist/scripts/notify-hook/tmux-injection.d.ts +1 -1
- package/dist/scripts/notify-hook/tmux-injection.d.ts.map +1 -1
- package/dist/scripts/notify-hook/tmux-injection.js +102 -35
- package/dist/scripts/notify-hook/tmux-injection.js.map +1 -1
- package/dist/scripts/notify-hook.js +144 -20
- package/dist/scripts/notify-hook.js.map +1 -1
- package/dist/scripts/run-provider-advisor.js +2 -0
- package/dist/scripts/run-provider-advisor.js.map +1 -1
- package/dist/scripts/run-test-files.d.ts +2 -0
- package/dist/scripts/run-test-files.d.ts.map +1 -0
- package/dist/scripts/run-test-files.js +41 -0
- package/dist/scripts/run-test-files.js.map +1 -0
- package/dist/scripts/tmux-hook-engine.d.ts +2 -0
- package/dist/scripts/tmux-hook-engine.d.ts.map +1 -1
- package/dist/scripts/tmux-hook-engine.js +15 -0
- package/dist/scripts/tmux-hook-engine.js.map +1 -1
- package/dist/team/__tests__/api-interop.test.js +136 -4
- package/dist/team/__tests__/api-interop.test.js.map +1 -1
- package/dist/team/__tests__/leader-activity.test.js +107 -2
- package/dist/team/__tests__/leader-activity.test.js.map +1 -1
- package/dist/team/__tests__/runtime-cli.test.js +32 -0
- package/dist/team/__tests__/runtime-cli.test.js.map +1 -1
- package/dist/team/__tests__/runtime.test.js +148 -0
- package/dist/team/__tests__/runtime.test.js.map +1 -1
- package/dist/team/__tests__/shutdown-fallback.test.js +13 -0
- package/dist/team/__tests__/shutdown-fallback.test.js.map +1 -1
- package/dist/team/__tests__/state-root.test.js +11 -1
- package/dist/team/__tests__/state-root.test.js.map +1 -1
- package/dist/team/__tests__/state.test.js +237 -0
- package/dist/team/__tests__/state.test.js.map +1 -1
- package/dist/team/__tests__/tmux-session.test.js +521 -2
- package/dist/team/__tests__/tmux-session.test.js.map +1 -1
- package/dist/team/api-interop.d.ts.map +1 -1
- package/dist/team/api-interop.js +41 -31
- package/dist/team/api-interop.js.map +1 -1
- package/dist/team/commit-hygiene.d.ts +60 -0
- package/dist/team/commit-hygiene.d.ts.map +1 -0
- package/dist/team/commit-hygiene.js +232 -0
- package/dist/team/commit-hygiene.js.map +1 -0
- package/dist/team/leader-activity.d.ts.map +1 -1
- package/dist/team/leader-activity.js +56 -4
- package/dist/team/leader-activity.js.map +1 -1
- package/dist/team/runtime-cli.d.ts +9 -1
- package/dist/team/runtime-cli.d.ts.map +1 -1
- package/dist/team/runtime-cli.js +15 -6
- package/dist/team/runtime-cli.js.map +1 -1
- package/dist/team/runtime.d.ts +7 -2
- package/dist/team/runtime.d.ts.map +1 -1
- package/dist/team/runtime.js +392 -171
- package/dist/team/runtime.js.map +1 -1
- package/dist/team/scaling.d.ts.map +1 -1
- package/dist/team/scaling.js +6 -2
- package/dist/team/scaling.js.map +1 -1
- package/dist/team/state/dispatch.d.ts +2 -0
- package/dist/team/state/dispatch.d.ts.map +1 -1
- package/dist/team/state/dispatch.js +86 -40
- package/dist/team/state/dispatch.js.map +1 -1
- package/dist/team/state/mailbox.d.ts +3 -0
- package/dist/team/state/mailbox.d.ts.map +1 -1
- package/dist/team/state/mailbox.js +93 -19
- package/dist/team/state/mailbox.js.map +1 -1
- package/dist/team/state-root.d.ts +1 -1
- package/dist/team/state-root.d.ts.map +1 -1
- package/dist/team/state-root.js +8 -3
- package/dist/team/state-root.js.map +1 -1
- package/dist/team/state.d.ts.map +1 -1
- package/dist/team/state.js +96 -2
- package/dist/team/state.js.map +1 -1
- package/dist/team/tmux-session.d.ts.map +1 -1
- package/dist/team/tmux-session.js +81 -29
- package/dist/team/tmux-session.js.map +1 -1
- package/dist/team/worker-bootstrap.d.ts.map +1 -1
- package/dist/team/worker-bootstrap.js +4 -0
- package/dist/team/worker-bootstrap.js.map +1 -1
- package/dist/team/worktree.d.ts.map +1 -1
- package/dist/team/worktree.js +9 -0
- package/dist/team/worktree.js.map +1 -1
- package/dist/utils/__tests__/paths.test.js +98 -11
- package/dist/utils/__tests__/paths.test.js.map +1 -1
- package/dist/utils/__tests__/platform-command.test.js +101 -2
- package/dist/utils/__tests__/platform-command.test.js.map +1 -1
- package/dist/utils/git-layout.d.ts +8 -0
- package/dist/utils/git-layout.d.ts.map +1 -0
- package/dist/utils/git-layout.js +58 -0
- package/dist/utils/git-layout.js.map +1 -0
- package/dist/utils/paths.d.ts +3 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +14 -4
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/platform-command.d.ts.map +1 -1
- package/dist/utils/platform-command.js +35 -3
- package/dist/utils/platform-command.js.map +1 -1
- package/package.json +9 -5
- package/src/scripts/notify-fallback-watcher.ts +103 -53
- package/src/scripts/notify-hook/auto-nudge.ts +97 -103
- package/src/scripts/notify-hook/managed-tmux.ts +324 -0
- package/src/scripts/notify-hook/operational-events.ts +2 -0
- package/src/scripts/notify-hook/ralph-session-resume.ts +337 -0
- package/src/scripts/notify-hook/state-io.ts +2 -10
- package/src/scripts/notify-hook/team-dispatch.ts +131 -66
- package/src/scripts/notify-hook/team-leader-nudge.ts +19 -5
- package/src/scripts/notify-hook/team-tmux-guard.ts +0 -20
- package/src/scripts/notify-hook/team-worker.ts +4 -4
- package/src/scripts/notify-hook/tmux-injection.ts +103 -33
- package/src/scripts/notify-hook.ts +150 -21
- package/src/scripts/run-provider-advisor.ts +4 -2
- package/src/scripts/run-test-files.ts +48 -0
- package/src/scripts/tmux-hook-engine.ts +16 -0
- package/templates/AGENTS.md +51 -43
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import { mkdir, readFile, readdir, rename, rm, stat, writeFile } from 'fs/promises';
|
|
3
|
+
import { dirname, join } from 'path';
|
|
4
|
+
import { captureTmuxPaneFromEnv } from '../../state/mode-state-context.js';
|
|
5
|
+
import { resolveCodexPane } from '../tmux-hook-engine.js';
|
|
6
|
+
import { safeString } from './utils.js';
|
|
7
|
+
|
|
8
|
+
const SESSION_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
|
|
9
|
+
const RALPH_TERMINAL_PHASES = new Set(['complete', 'failed', 'cancelled']);
|
|
10
|
+
const RALPH_RESUME_LOCK_STALE_MS = 10_000;
|
|
11
|
+
const RALPH_RESUME_LOCK_TIMEOUT_MS = 5_000;
|
|
12
|
+
const RALPH_RESUME_LOCK_RETRY_MS = 25;
|
|
13
|
+
|
|
14
|
+
interface RalphSessionResumeHooks {
|
|
15
|
+
afterLockAcquired?: () => Promise<void> | void;
|
|
16
|
+
afterTargetWrite?: () => Promise<void> | void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface RalphSessionResumeParams {
|
|
20
|
+
stateDir: string;
|
|
21
|
+
payloadSessionId: string;
|
|
22
|
+
payloadThreadId?: string;
|
|
23
|
+
env?: NodeJS.ProcessEnv;
|
|
24
|
+
hooks?: RalphSessionResumeHooks;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface RalphSessionResumeResult {
|
|
28
|
+
currentOmxSessionId: string;
|
|
29
|
+
resumed: boolean;
|
|
30
|
+
updatedCurrentOwner: boolean;
|
|
31
|
+
reason: string;
|
|
32
|
+
sourcePath?: string;
|
|
33
|
+
targetPath?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface RalphStateCandidate {
|
|
37
|
+
sessionId: string;
|
|
38
|
+
path: string;
|
|
39
|
+
state: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function lockOwnerToken(): string {
|
|
43
|
+
return `${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function sleep(ms: number): Promise<void> {
|
|
47
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function maybeRecoverStaleLock(lockDir: string): Promise<boolean> {
|
|
51
|
+
try {
|
|
52
|
+
const info = await stat(lockDir);
|
|
53
|
+
if (Date.now() - info.mtimeMs <= RALPH_RESUME_LOCK_STALE_MS) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
await rm(lockDir, { recursive: true, force: true });
|
|
57
|
+
return true;
|
|
58
|
+
} catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function withRalphResumeLock<T>(
|
|
64
|
+
stateDir: string,
|
|
65
|
+
fn: () => Promise<T>,
|
|
66
|
+
): Promise<T | null> {
|
|
67
|
+
const lockDir = join(stateDir, '.lock.ralph-session-resume');
|
|
68
|
+
const ownerPath = join(lockDir, 'owner');
|
|
69
|
+
const ownerToken = lockOwnerToken();
|
|
70
|
+
const deadline = Date.now() + RALPH_RESUME_LOCK_TIMEOUT_MS;
|
|
71
|
+
await mkdir(dirname(lockDir), { recursive: true }).catch(() => {});
|
|
72
|
+
|
|
73
|
+
while (true) {
|
|
74
|
+
try {
|
|
75
|
+
await mkdir(lockDir, { recursive: false });
|
|
76
|
+
try {
|
|
77
|
+
await writeFile(ownerPath, ownerToken, 'utf8');
|
|
78
|
+
} catch (error) {
|
|
79
|
+
await rm(lockDir, { recursive: true, force: true }).catch(() => {});
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
const err = error as NodeJS.ErrnoException;
|
|
85
|
+
if (err.code !== 'EEXIST') throw error;
|
|
86
|
+
if (await maybeRecoverStaleLock(lockDir)) continue;
|
|
87
|
+
if (Date.now() > deadline) return null;
|
|
88
|
+
await sleep(RALPH_RESUME_LOCK_RETRY_MS);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
return await fn();
|
|
94
|
+
} finally {
|
|
95
|
+
try {
|
|
96
|
+
const currentOwner = await readFile(ownerPath, 'utf8');
|
|
97
|
+
if (currentOwner.trim() === ownerToken) {
|
|
98
|
+
await rm(lockDir, { recursive: true, force: true });
|
|
99
|
+
}
|
|
100
|
+
} catch {
|
|
101
|
+
// Lock may already be gone after stale recovery or process interruption.
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function readJson(path: string): Promise<Record<string, unknown> | null> {
|
|
107
|
+
try {
|
|
108
|
+
return JSON.parse(await readFile(path, 'utf-8')) as Record<string, unknown>;
|
|
109
|
+
} catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function writeJsonAtomic(path: string, value: unknown): Promise<void> {
|
|
115
|
+
await mkdir(dirname(path), { recursive: true }).catch(() => {});
|
|
116
|
+
const tempPath = `${path}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
117
|
+
await writeFile(tempPath, JSON.stringify(value, null, 2));
|
|
118
|
+
await rename(tempPath, path);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function isTerminalRalphPhase(value: unknown): boolean {
|
|
122
|
+
return RALPH_TERMINAL_PHASES.has(safeString(value).trim().toLowerCase());
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function isActiveRalphCandidate(state: Record<string, unknown> | null): state is Record<string, unknown> {
|
|
126
|
+
if (!state || typeof state !== 'object') return false;
|
|
127
|
+
return state.active === true && !isTerminalRalphPhase(state.current_phase);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function readCurrentOmxSessionId(stateDir: string): Promise<string> {
|
|
131
|
+
const session = await readJson(join(stateDir, 'session.json'));
|
|
132
|
+
const sessionId = safeString(session?.session_id).trim();
|
|
133
|
+
return SESSION_ID_PATTERN.test(sessionId) ? sessionId : '';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function resolveResumePane(env: NodeJS.ProcessEnv = process.env): string {
|
|
137
|
+
const injectedPane = captureTmuxPaneFromEnv(env);
|
|
138
|
+
if (env !== process.env && injectedPane) return injectedPane;
|
|
139
|
+
return resolveCodexPane() || injectedPane || '';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function bindCurrentPane(state: Record<string, unknown>, nowIso: string, env: NodeJS.ProcessEnv = process.env): Record<string, unknown> {
|
|
143
|
+
const paneId = resolveResumePane(env);
|
|
144
|
+
if (!paneId) return state;
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
...state,
|
|
148
|
+
tmux_pane_id: paneId,
|
|
149
|
+
tmux_pane_set_at: nowIso,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function scanMatchingRalphCandidates(
|
|
154
|
+
stateDir: string,
|
|
155
|
+
currentOmxSessionId: string,
|
|
156
|
+
payloadSessionId: string,
|
|
157
|
+
payloadThreadId: string,
|
|
158
|
+
): Promise<RalphStateCandidate[]> {
|
|
159
|
+
const sessionsRoot = join(stateDir, 'sessions');
|
|
160
|
+
if (!existsSync(sessionsRoot)) return [];
|
|
161
|
+
|
|
162
|
+
const entries = await readdir(sessionsRoot, { withFileTypes: true }).catch(() => []);
|
|
163
|
+
const matches: RalphStateCandidate[] = [];
|
|
164
|
+
for (const entry of entries) {
|
|
165
|
+
if (!entry.isDirectory() || !SESSION_ID_PATTERN.test(entry.name) || entry.name === currentOmxSessionId) continue;
|
|
166
|
+
const path = join(sessionsRoot, entry.name, 'ralph-state.json');
|
|
167
|
+
if (!existsSync(path)) continue;
|
|
168
|
+
const state = await readJson(path);
|
|
169
|
+
if (!isActiveRalphCandidate(state)) continue;
|
|
170
|
+
const ownerSessionId = safeString(state.owner_codex_session_id).trim();
|
|
171
|
+
const ownerThreadId = safeString(state.owner_codex_thread_id).trim();
|
|
172
|
+
if (ownerSessionId) {
|
|
173
|
+
if (!payloadSessionId || ownerSessionId !== payloadSessionId) continue;
|
|
174
|
+
} else if (!payloadThreadId || !ownerThreadId || ownerThreadId !== payloadThreadId) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
matches.push({
|
|
178
|
+
sessionId: entry.name,
|
|
179
|
+
path,
|
|
180
|
+
state,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return matches;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export async function reconcileRalphSessionResume({
|
|
187
|
+
stateDir,
|
|
188
|
+
payloadSessionId,
|
|
189
|
+
payloadThreadId = '',
|
|
190
|
+
env = process.env,
|
|
191
|
+
hooks,
|
|
192
|
+
}: RalphSessionResumeParams): Promise<RalphSessionResumeResult> {
|
|
193
|
+
const lockedResult = await withRalphResumeLock(stateDir, async () => {
|
|
194
|
+
await hooks?.afterLockAcquired?.();
|
|
195
|
+
|
|
196
|
+
const currentOmxSessionId = await readCurrentOmxSessionId(stateDir);
|
|
197
|
+
if (!currentOmxSessionId) {
|
|
198
|
+
return {
|
|
199
|
+
currentOmxSessionId: '',
|
|
200
|
+
resumed: false,
|
|
201
|
+
updatedCurrentOwner: false,
|
|
202
|
+
reason: 'current_omx_session_missing',
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const currentSessionDir = join(stateDir, 'sessions', currentOmxSessionId);
|
|
207
|
+
const currentRalphPath = join(currentSessionDir, 'ralph-state.json');
|
|
208
|
+
const currentRalphExists = existsSync(currentRalphPath);
|
|
209
|
+
const currentRalphState = currentRalphExists
|
|
210
|
+
? await readJson(currentRalphPath)
|
|
211
|
+
: null;
|
|
212
|
+
const nowIso = new Date().toISOString();
|
|
213
|
+
|
|
214
|
+
if (currentRalphState && currentRalphState.active === true) {
|
|
215
|
+
let changed = false;
|
|
216
|
+
const updated: Record<string, unknown> = { ...currentRalphState };
|
|
217
|
+
if (safeString(updated.owner_omx_session_id).trim() !== currentOmxSessionId) {
|
|
218
|
+
updated.owner_omx_session_id = currentOmxSessionId;
|
|
219
|
+
changed = true;
|
|
220
|
+
}
|
|
221
|
+
if (payloadSessionId && !safeString(updated.owner_codex_session_id).trim()) {
|
|
222
|
+
updated.owner_codex_session_id = payloadSessionId;
|
|
223
|
+
changed = true;
|
|
224
|
+
}
|
|
225
|
+
if (
|
|
226
|
+
typeof updated.owner_codex_thread_id === 'string'
|
|
227
|
+
&& safeString(updated.owner_codex_session_id).trim()
|
|
228
|
+
) {
|
|
229
|
+
delete updated.owner_codex_thread_id;
|
|
230
|
+
changed = true;
|
|
231
|
+
}
|
|
232
|
+
const currentPaneId = resolveResumePane(env);
|
|
233
|
+
const currentStatePaneId = safeString(updated.tmux_pane_id).trim();
|
|
234
|
+
if (currentPaneId && currentPaneId !== currentStatePaneId) {
|
|
235
|
+
Object.assign(updated, bindCurrentPane(updated, nowIso, env));
|
|
236
|
+
changed = true;
|
|
237
|
+
}
|
|
238
|
+
if (changed) {
|
|
239
|
+
await writeJsonAtomic(currentRalphPath, updated);
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
currentOmxSessionId,
|
|
243
|
+
resumed: false,
|
|
244
|
+
updatedCurrentOwner: changed,
|
|
245
|
+
reason: 'current_ralph_active',
|
|
246
|
+
targetPath: currentRalphPath,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (currentRalphExists) {
|
|
251
|
+
return {
|
|
252
|
+
currentOmxSessionId,
|
|
253
|
+
resumed: false,
|
|
254
|
+
updatedCurrentOwner: false,
|
|
255
|
+
reason: currentRalphState ? 'current_ralph_present' : 'current_ralph_unreadable',
|
|
256
|
+
targetPath: currentRalphPath,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const normalizedPayloadSessionId = safeString(payloadSessionId).trim();
|
|
261
|
+
const normalizedPayloadThreadId = safeString(payloadThreadId).trim();
|
|
262
|
+
if (!normalizedPayloadSessionId && !normalizedPayloadThreadId) {
|
|
263
|
+
return {
|
|
264
|
+
currentOmxSessionId,
|
|
265
|
+
resumed: false,
|
|
266
|
+
updatedCurrentOwner: false,
|
|
267
|
+
reason: 'payload_codex_identity_missing',
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const candidates = await scanMatchingRalphCandidates(
|
|
272
|
+
stateDir,
|
|
273
|
+
currentOmxSessionId,
|
|
274
|
+
normalizedPayloadSessionId,
|
|
275
|
+
normalizedPayloadThreadId,
|
|
276
|
+
);
|
|
277
|
+
if (candidates.length !== 1) {
|
|
278
|
+
return {
|
|
279
|
+
currentOmxSessionId,
|
|
280
|
+
resumed: false,
|
|
281
|
+
updatedCurrentOwner: false,
|
|
282
|
+
reason: candidates.length === 0 ? 'no_matching_prior_ralph' : 'multiple_matching_prior_ralphs',
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const source = candidates[0];
|
|
287
|
+
await mkdir(currentSessionDir, { recursive: true });
|
|
288
|
+
|
|
289
|
+
const nextState = bindCurrentPane({
|
|
290
|
+
...source.state,
|
|
291
|
+
owner_omx_session_id: currentOmxSessionId,
|
|
292
|
+
...(normalizedPayloadSessionId ? { owner_codex_session_id: normalizedPayloadSessionId } : {}),
|
|
293
|
+
}, nowIso, env);
|
|
294
|
+
if (safeString(nextState.owner_codex_session_id).trim()) {
|
|
295
|
+
delete nextState.owner_codex_thread_id;
|
|
296
|
+
}
|
|
297
|
+
delete nextState.completed_at;
|
|
298
|
+
delete nextState.stop_reason;
|
|
299
|
+
|
|
300
|
+
const previousState: Record<string, unknown> = {
|
|
301
|
+
...source.state,
|
|
302
|
+
active: false,
|
|
303
|
+
current_phase: 'cancelled',
|
|
304
|
+
completed_at: nowIso,
|
|
305
|
+
stop_reason: 'ownership_transferred',
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
await writeJsonAtomic(currentRalphPath, nextState);
|
|
309
|
+
try {
|
|
310
|
+
await hooks?.afterTargetWrite?.();
|
|
311
|
+
await writeJsonAtomic(source.path, previousState);
|
|
312
|
+
} catch (error) {
|
|
313
|
+
await rm(currentRalphPath, { force: true }).catch(() => {});
|
|
314
|
+
throw error;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return {
|
|
318
|
+
currentOmxSessionId,
|
|
319
|
+
resumed: true,
|
|
320
|
+
updatedCurrentOwner: false,
|
|
321
|
+
reason: 'resumed_same_codex_session',
|
|
322
|
+
sourcePath: source.path,
|
|
323
|
+
targetPath: currentRalphPath,
|
|
324
|
+
};
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
if (lockedResult) {
|
|
328
|
+
return lockedResult;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return {
|
|
332
|
+
currentOmxSessionId: '',
|
|
333
|
+
resumed: false,
|
|
334
|
+
updatedCurrentOwner: false,
|
|
335
|
+
reason: 'resume_lock_timeout',
|
|
336
|
+
};
|
|
337
|
+
}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { readFile, readdir } from 'fs/promises';
|
|
6
|
-
import { existsSync } from 'fs';
|
|
7
6
|
import { join } from 'path';
|
|
8
7
|
import { asNumber, safeString } from './utils.js';
|
|
9
8
|
|
|
@@ -17,20 +16,13 @@ export function readJsonIfExists(path: string, fallback: any): Promise<any> {
|
|
|
17
16
|
.catch(() => fallback);
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
export async function getScopedStateDirsForCurrentSession(baseStateDir: string
|
|
21
|
-
const explicitSessionId = safeString(payloadSessionId || '');
|
|
22
|
-
if (SESSION_ID_PATTERN.test(explicitSessionId)) {
|
|
23
|
-
const sessionDir = join(baseStateDir, 'sessions', explicitSessionId);
|
|
24
|
-
return [sessionDir];
|
|
25
|
-
}
|
|
26
|
-
|
|
19
|
+
export async function getScopedStateDirsForCurrentSession(baseStateDir: string): Promise<string[]> {
|
|
27
20
|
const sessionPath = join(baseStateDir, 'session.json');
|
|
28
21
|
try {
|
|
29
22
|
const session = JSON.parse(await readFile(sessionPath, 'utf-8'));
|
|
30
23
|
const sessionId = safeString(session && session.session_id ? session.session_id : '');
|
|
31
24
|
if (SESSION_ID_PATTERN.test(sessionId)) {
|
|
32
|
-
|
|
33
|
-
if (existsSync(sessionDir)) return [sessionDir];
|
|
25
|
+
return [join(baseStateDir, 'sessions', sessionId)];
|
|
34
26
|
}
|
|
35
27
|
} catch {
|
|
36
28
|
// No session file or malformed - fall back to global only
|