mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-19 12:04:08 +00:00
Add SDK for programmatic AgentSession usage
- Add src/core/sdk.ts with createAgentSession() factory and discovery functions - Update loaders to accept cwd/agentDir parameters (skills, hooks, custom-tools, slash-commands, system-prompt) - Export SDK from package index Addresses #272
This commit is contained in:
parent
11e743373d
commit
5482bf3e14
8 changed files with 737 additions and 40 deletions
|
|
@ -215,17 +215,28 @@ function discoverHooksInDir(dir: string): string[] {
|
|||
}
|
||||
}
|
||||
|
||||
export interface DiscoverAndLoadHooksOptions {
|
||||
/** Explicit paths from settings.json or CLI */
|
||||
configuredPaths?: string[];
|
||||
/** Current working directory */
|
||||
cwd?: string;
|
||||
/** Agent config directory. Default: from getAgentDir() */
|
||||
agentDir?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Discover and load hooks from standard locations:
|
||||
* 1. ~/.pi/agent/hooks/*.ts (global)
|
||||
* 1. agentDir/hooks/*.ts (global)
|
||||
* 2. cwd/.pi/hooks/*.ts (project-local)
|
||||
*
|
||||
* Plus any explicitly configured paths from settings.
|
||||
*
|
||||
* @param configuredPaths - Explicit paths from settings.json
|
||||
* @param cwd - Current working directory
|
||||
*/
|
||||
export async function discoverAndLoadHooks(configuredPaths: string[], cwd: string): Promise<LoadHooksResult> {
|
||||
export async function discoverAndLoadHooks(
|
||||
configuredPaths: string[],
|
||||
cwd: string,
|
||||
agentDir?: string,
|
||||
): Promise<LoadHooksResult> {
|
||||
const resolvedAgentDir = agentDir ?? getAgentDir();
|
||||
const allPaths: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
|
||||
|
|
@ -240,8 +251,8 @@ export async function discoverAndLoadHooks(configuredPaths: string[], cwd: strin
|
|||
}
|
||||
};
|
||||
|
||||
// 1. Global hooks: ~/.pi/agent/hooks/
|
||||
const globalHooksDir = path.join(getAgentDir(), "hooks");
|
||||
// 1. Global hooks: agentDir/hooks/
|
||||
const globalHooksDir = path.join(resolvedAgentDir, "hooks");
|
||||
addPaths(discoverHooksInDir(globalHooksDir));
|
||||
|
||||
// 2. Project-local hooks: cwd/.pi/hooks/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue