Files
orca/src/main/jcode/hook-settings.ts
T
OrcaWinandOrcaWin 4687e90a16 [comment audit] Continue main-process comment cleanup (#32946)
* [comment audit] Shorten daemon, hook, and emulator comments [skip ci]

* [comment audit] Shorten VM, conversation, SQLite, and theme-import comments [skip ci]

* [comment audit] Tighten Git execution and source-control comment contracts [skip ci]

* [comment audit] Clarify repository probes and maintenance comments [skip ci]

* [comment audit] Shorten status, diff-cache, and checkout comments [skip ci]

* [comment audit] Clarify worktree lifecycle and WSL routing comments [skip ci]

* [comment audit] Shorten forge identity and review-refresh comments [skip ci]

* [comment audit] Tighten hosted-review client comment contracts [skip ci]

* [comment audit] Clarify GitLab compatibility and review comments [skip ci]

* [comment audit] Tighten hook ownership and watchdog rationale [skip ci]

* [comment audit] Condense host and integration compatibility comments [skip ci]

* [comment audit] Clarify IPC authority and remote-routing rationale [skip ci]

* [comment audit] Finalize file-import and containment comment cleanup

* [comment audit] Fix stale Jira type imports blocking full CI

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-23 16:27:37 -07:00

60 lines
2.0 KiB
TypeScript

// Honor JCODE_HOME so hooks land in the config jcode actually reads.
import { homedir } from 'node:os'
import { join } from 'node:path'
const JCODE_SCRIPT_BASE = 'jcode-hook'
// pre_tool observes running tools and unanswered questions; its POST is detached so the gate never blocks on HTTP.
export const JCODE_HOOK_EVENTS = [
'session_start',
'turn_start',
'pre_tool',
'post_tool',
'turn_end',
'session_end'
] as const
export type JcodeHookEvent = (typeof JCODE_HOOK_EVENTS)[number]
export function getJcodeConfigPath(env: NodeJS.ProcessEnv = process.env): string {
const explicit = env.JCODE_HOME?.trim()
return explicit ? join(explicit, 'config.toml') : join(homedir(), '.jcode', 'config.toml')
}
export function getJcodeRemoteConfigPath(remoteHome: string): string {
return `${remoteHome.replace(/\/+$/, '')}/.jcode/config.toml`
}
export function getJcodeManagedScriptFileName(): string {
return process.platform === 'win32' ? `${JCODE_SCRIPT_BASE}.cmd` : `${JCODE_SCRIPT_BASE}.sh`
}
export function getJcodePosixManagedScriptFileName(): string {
return `${JCODE_SCRIPT_BASE}.sh`
}
export function getJcodeManagedScriptPath(): string {
return getSharedJcodeScriptPath(getJcodeManagedScriptFileName())
}
export function getSharedJcodeScriptPath(scriptFileName: string): string {
return join(homedir(), '.orca', 'agent-hooks', scriptFileName)
}
// jcode tokenizes commands before direct execution; quote paths to preserve Windows separators and spaces.
export function getJcodeManagedCommand(scriptPath: string): string {
return scriptPath.includes("'")
? `"${scriptPath.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`
: `'${scriptPath}'`
}
export function getJcodeRemoteManagedCommand(scriptPath: string): string {
return getJcodeManagedCommand(scriptPath)
}
// Normalize Windows separators before matching the managed script.
export function isJcodeManagedCommand(command: string | null | undefined): boolean {
return (
typeof command === 'string' && command.replaceAll('\\', '/').includes('agent-hooks/jcode-hook')
)
}