moving
This commit is contained in:
@@ -60,6 +60,19 @@ export interface HookHandler<TPayload = unknown, TStdoutPayload = unknown> {
|
||||
}
|
||||
|
||||
const STDIN_READ_TIMEOUT_MS = 2000;
|
||||
const HOOK_CLI_TIMEOUT_MS = 10_000;
|
||||
|
||||
export function buildHookBridgeOptions(
|
||||
logger: Logger,
|
||||
cliPath?: string,
|
||||
): CliBridgeOptions {
|
||||
return {
|
||||
logger,
|
||||
timeout_ms: HOOK_CLI_TIMEOUT_MS,
|
||||
max_retries: 0,
|
||||
...(cliPath !== undefined ? { cli_path: cliPath } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export async function readStdinAsString(timeoutMs: number = STDIN_READ_TIMEOUT_MS): Promise<string> {
|
||||
if (process.stdin.isTTY) return '';
|
||||
@@ -106,8 +119,7 @@ export async function runHook<TPayload, TStdoutPayload>(
|
||||
const reader = opts.readStdin ?? readStdinAsString;
|
||||
const argv = opts.argv ?? process.argv.slice(2);
|
||||
const argvFlags = parseHookArgs(argv);
|
||||
const bridgeOpts: CliBridgeOptions = { logger };
|
||||
if (argvFlags.cliPath !== undefined) bridgeOpts.cli_path = argvFlags.cliPath;
|
||||
const bridgeOpts = buildHookBridgeOptions(logger, argvFlags.cliPath);
|
||||
const bridge = opts.bridge ?? createCliBridge(bridgeOpts);
|
||||
|
||||
try {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
* native compaction step.
|
||||
*/
|
||||
|
||||
import { isDirectExecution } from '@waggle/hive-mind-shim-core';
|
||||
|
||||
import {
|
||||
pickStringFromObject,
|
||||
runHook,
|
||||
@@ -38,15 +40,6 @@ export async function runPreCompact(opts: Partial<HookRunOptions> = {}): Promise
|
||||
return runHook(preCompactHandler, { name: 'pre-compact', ...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) {
|
||||
if (isDirectExecution(import.meta.url)) {
|
||||
void runPreCompact();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
* output — the session starts as it would have without the shim.
|
||||
*/
|
||||
|
||||
import { recallPersonalAndWorkspace, type MemoryHit } from '@waggle/hive-mind-shim-core';
|
||||
import {
|
||||
isDirectExecution,
|
||||
recallPersonalAndWorkspace,
|
||||
type MemoryHit,
|
||||
} from '@waggle/hive-mind-shim-core';
|
||||
import {
|
||||
pickStringFromObject,
|
||||
runHook,
|
||||
@@ -88,15 +92,6 @@ export async function runSessionStart(opts: Partial<HookRunOptions> = {}): Promi
|
||||
return runHook(sessionStartHandler, { name: 'session-start', ...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) {
|
||||
if (isDirectExecution(import.meta.url)) {
|
||||
void runSessionStart();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import {
|
||||
classifyImportance,
|
||||
encodeFrame,
|
||||
isDirectExecution,
|
||||
maybeEmitDiscovery,
|
||||
summarizeTurn,
|
||||
type HookEvent,
|
||||
@@ -34,7 +35,8 @@ export const stopHandler: HookHandler<StopPayload, undefined> = {
|
||||
const sessionId = pickStringFromObject(obj, 'session_id')
|
||||
?? pickStringFromObject(obj, 'sessionId')
|
||||
?? 'default';
|
||||
const response = pickStringFromObject(obj, 'response')
|
||||
const response = pickStringFromObject(obj, 'last_assistant_message')
|
||||
?? pickStringFromObject(obj, 'response')
|
||||
?? pickStringFromObject(obj, 'assistant_message')
|
||||
?? pickStringFromObject(obj, 'transcript')
|
||||
?? '';
|
||||
@@ -115,15 +117,6 @@ export async function runStop(opts: Partial<HookRunOptions> = {}): Promise<void>
|
||||
return runHook(stopHandler, { name: 'stop', ...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) {
|
||||
if (isDirectExecution(import.meta.url)) {
|
||||
void runStop();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* No stdout output: this hook is purely a side-effect on the .mind file.
|
||||
*/
|
||||
|
||||
import { encodeFrame, type HookEvent } from '@waggle/hive-mind-shim-core';
|
||||
import { encodeFrame, isDirectExecution, type HookEvent } from '@waggle/hive-mind-shim-core';
|
||||
import {
|
||||
pickStringFromObject,
|
||||
runHook,
|
||||
@@ -58,15 +58,6 @@ export async function runUserPromptSubmit(opts: Partial<HookRunOptions> = {}): P
|
||||
return runHook(userPromptSubmitHandler, { name: 'user-prompt-submit', ...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) {
|
||||
if (isDirectExecution(import.meta.url)) {
|
||||
void runUserPromptSubmit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user