mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-18 11:02:06 +00:00
feat(coding-agent): ResourceLoader, package management, and /reload command (#645)
- Add ResourceLoader interface and DefaultResourceLoader implementation - Add PackageManager for npm/git extension sources with install/remove/update - Add session.reload() and session.bindExtensions() APIs - Add /reload command in interactive mode - Add CLI flags: --skill, --theme, --prompt-template, --no-themes, --no-prompt-templates - Add pi install/remove/update commands for extension management - Refactor settings.json to use arrays for skills, prompts, themes - Remove legacy SkillsSettings source flags and filters - Update SDK examples and documentation for ResourceLoader pattern - Add theme registration and loadThemeFromPath for dynamic themes - Add getShellEnv to include bin dir in PATH for bash commands
This commit is contained in:
parent
866d21c252
commit
b846a4bfcf
51 changed files with 2724 additions and 1852 deletions
|
|
@ -256,67 +256,9 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
|||
// Set up extensions with RPC-based UI context
|
||||
const extensionRunner = session.extensionRunner;
|
||||
if (extensionRunner) {
|
||||
extensionRunner.initialize(
|
||||
// ExtensionActions
|
||||
{
|
||||
sendMessage: (message, options) => {
|
||||
session.sendCustomMessage(message, options).catch((e) => {
|
||||
output(error(undefined, "extension_send", e.message));
|
||||
});
|
||||
},
|
||||
sendUserMessage: (content, options) => {
|
||||
session.sendUserMessage(content, options).catch((e) => {
|
||||
output(error(undefined, "extension_send_user", e.message));
|
||||
});
|
||||
},
|
||||
appendEntry: (customType, data) => {
|
||||
session.sessionManager.appendCustomEntry(customType, data);
|
||||
},
|
||||
setSessionName: (name) => {
|
||||
session.sessionManager.appendSessionInfo(name);
|
||||
},
|
||||
getSessionName: () => {
|
||||
return session.sessionManager.getSessionName();
|
||||
},
|
||||
setLabel: (entryId, label) => {
|
||||
session.sessionManager.appendLabelChange(entryId, label);
|
||||
},
|
||||
getActiveTools: () => session.getActiveToolNames(),
|
||||
getAllTools: () => session.getAllTools(),
|
||||
setActiveTools: (toolNames: string[]) => session.setActiveToolsByName(toolNames),
|
||||
setModel: async (model) => {
|
||||
const key = await session.modelRegistry.getApiKey(model);
|
||||
if (!key) return false;
|
||||
await session.setModel(model);
|
||||
return true;
|
||||
},
|
||||
getThinkingLevel: () => session.thinkingLevel,
|
||||
setThinkingLevel: (level) => session.setThinkingLevel(level),
|
||||
},
|
||||
// ExtensionContextActions
|
||||
{
|
||||
getModel: () => session.agent.state.model,
|
||||
isIdle: () => !session.isStreaming,
|
||||
abort: () => session.abort(),
|
||||
hasPendingMessages: () => session.pendingMessageCount > 0,
|
||||
shutdown: () => {
|
||||
shutdownRequested = true;
|
||||
},
|
||||
getContextUsage: () => session.getContextUsage(),
|
||||
compact: (options) => {
|
||||
void (async () => {
|
||||
try {
|
||||
const result = await session.compact(options?.customInstructions);
|
||||
options?.onComplete?.(result);
|
||||
} catch (error) {
|
||||
const err = error instanceof Error ? error : new Error(String(error));
|
||||
options?.onError?.(err);
|
||||
}
|
||||
})();
|
||||
},
|
||||
},
|
||||
// ExtensionCommandContextActions - commands invokable via prompt("/command")
|
||||
{
|
||||
await session.bindExtensions({
|
||||
uiContext: createExtensionUIContext(),
|
||||
commandContextActions: {
|
||||
waitForIdle: () => session.agent.waitForIdle(),
|
||||
newSession: async (options) => {
|
||||
const success = await session.newSession({ parentSession: options?.parentSession });
|
||||
|
|
@ -340,14 +282,12 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
|||
return { cancelled: result.cancelled };
|
||||
},
|
||||
},
|
||||
createExtensionUIContext(),
|
||||
);
|
||||
extensionRunner.onError((err) => {
|
||||
output({ type: "extension_error", extensionPath: err.extensionPath, event: err.event, error: err.error });
|
||||
});
|
||||
// Emit session_start event
|
||||
await extensionRunner.emit({
|
||||
type: "session_start",
|
||||
shutdownHandler: () => {
|
||||
shutdownRequested = true;
|
||||
},
|
||||
onError: (err) => {
|
||||
output({ type: "extension_error", extensionPath: err.extensionPath, event: err.event, error: err.error });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -577,8 +517,9 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
|||
async function checkShutdownRequested(): Promise<void> {
|
||||
if (!shutdownRequested) return;
|
||||
|
||||
if (extensionRunner?.hasHandlers("session_shutdown")) {
|
||||
await extensionRunner.emit({ type: "session_shutdown" });
|
||||
const currentRunner = session.extensionRunner;
|
||||
if (currentRunner?.hasHandlers("session_shutdown")) {
|
||||
await currentRunner.emit({ type: "session_shutdown" });
|
||||
}
|
||||
|
||||
// Close readline interface to stop waiting for input
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue