This commit is contained in:
34
packages/hive-mind-hooks-codex/src/hooks/pre-compact.ts
Normal file
34
packages/hive-mind-hooks-codex/src/hooks/pre-compact.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Codex PreCompact hook — fired just before Codex truncates context.
|
||||
* Triggers `cleanup_frames` so superseded P/B frames merge before the
|
||||
* native compaction step. Thin entrypoint over the shared handler body.
|
||||
* Codex carries the compaction `trigger` (`manual|auto`) on the payload.
|
||||
*/
|
||||
|
||||
import {
|
||||
makePreCompactHandler,
|
||||
runHook,
|
||||
type HookRunOptions,
|
||||
} from '@waggle/hive-mind-hooks-core';
|
||||
import { codexAdapter } from '../adapter.js';
|
||||
|
||||
export async function runPreCompact(opts: Partial<HookRunOptions> = {}): Promise<void> {
|
||||
return runHook(makePreCompactHandler(codexAdapter), {
|
||||
name: 'pre-compact',
|
||||
loggerPrefix: 'codex-hooks',
|
||||
...opts,
|
||||
});
|
||||
}
|
||||
|
||||
const isMain = (() => {
|
||||
try {
|
||||
if (typeof process.argv[1] !== 'string') return false;
|
||||
const url = new URL(`file://${process.argv[1].replace(/\\/g, '/')}`);
|
||||
return url.href === import.meta.url;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
if (isMain) {
|
||||
void runPreCompact();
|
||||
}
|
||||
37
packages/hive-mind-hooks-codex/src/hooks/session-start.ts
Normal file
37
packages/hive-mind-hooks-codex/src/hooks/session-start.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Codex SessionStart hook — recalls the top-N most relevant frames from
|
||||
* personal memory and injects them as additional context for the new
|
||||
* Codex session. Thin entrypoint over the shared handler body.
|
||||
*
|
||||
* If hive-mind-cli is unreachable, the hook logs and exits 0 with no
|
||||
* output (fail-open) — the session starts as it would have without the
|
||||
* shim.
|
||||
*/
|
||||
|
||||
import {
|
||||
makeSessionStartHandler,
|
||||
runHook,
|
||||
type HookRunOptions,
|
||||
} from '@waggle/hive-mind-hooks-core';
|
||||
import { codexAdapter } from '../adapter.js';
|
||||
|
||||
export async function runSessionStart(opts: Partial<HookRunOptions> = {}): Promise<void> {
|
||||
return runHook(makeSessionStartHandler(codexAdapter), {
|
||||
name: 'session-start',
|
||||
loggerPrefix: 'codex-hooks',
|
||||
...opts,
|
||||
});
|
||||
}
|
||||
|
||||
const isMain = (() => {
|
||||
try {
|
||||
if (typeof process.argv[1] !== 'string') return false;
|
||||
const url = new URL(`file://${process.argv[1].replace(/\\/g, '/')}`);
|
||||
return url.href === import.meta.url;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
if (isMain) {
|
||||
void runSessionStart();
|
||||
}
|
||||
35
packages/hive-mind-hooks-codex/src/hooks/stop.ts
Normal file
35
packages/hive-mind-hooks-codex/src/hooks/stop.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Codex Stop hook — fired when an assistant turn completes. Summarizes the
|
||||
* turn deterministically (no LLM call) and writes it as an `important`
|
||||
* frame parented to the originating prompt frame when known. Thin
|
||||
* entrypoint over the shared handler body; the adapter reads codex's
|
||||
* `last_assistant_message` in the response fallback list.
|
||||
*/
|
||||
|
||||
import {
|
||||
makeStopHandler,
|
||||
runHook,
|
||||
type HookRunOptions,
|
||||
} from '@waggle/hive-mind-hooks-core';
|
||||
import { codexAdapter } from '../adapter.js';
|
||||
|
||||
export async function runStop(opts: Partial<HookRunOptions> = {}): Promise<void> {
|
||||
return runHook(makeStopHandler(codexAdapter), {
|
||||
name: 'stop',
|
||||
loggerPrefix: 'codex-hooks',
|
||||
...opts,
|
||||
});
|
||||
}
|
||||
|
||||
const isMain = (() => {
|
||||
try {
|
||||
if (typeof process.argv[1] !== 'string') return false;
|
||||
const url = new URL(`file://${process.argv[1].replace(/\\/g, '/')}`);
|
||||
return url.href === import.meta.url;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
if (isMain) {
|
||||
void runStop();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Codex UserPromptSubmit hook — captures the user prompt as a temporary
|
||||
* frame scoped to the current Codex session. Thin entrypoint over the
|
||||
* shared handler body. No stdout output: pure side-effect on the .mind file.
|
||||
*/
|
||||
|
||||
import {
|
||||
makeUserPromptSubmitHandler,
|
||||
runHook,
|
||||
type HookRunOptions,
|
||||
} from '@waggle/hive-mind-hooks-core';
|
||||
import { codexAdapter } from '../adapter.js';
|
||||
|
||||
export async function runUserPromptSubmit(opts: Partial<HookRunOptions> = {}): Promise<void> {
|
||||
return runHook(makeUserPromptSubmitHandler(codexAdapter), {
|
||||
name: 'user-prompt-submit',
|
||||
loggerPrefix: 'codex-hooks',
|
||||
...opts,
|
||||
});
|
||||
}
|
||||
|
||||
const isMain = (() => {
|
||||
try {
|
||||
if (typeof process.argv[1] !== 'string') return false;
|
||||
const url = new URL(`file://${process.argv[1].replace(/\\/g, '/')}`);
|
||||
return url.href === import.meta.url;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
if (isMain) {
|
||||
void runUserPromptSubmit();
|
||||
}
|
||||
Reference in New Issue
Block a user