-
Notifications
You must be signed in to change notification settings - Fork 34
feat(copilot): add agent configuration and model settings support #2180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,11 @@ | |
| * SPDX-License-Identifier: Apache-2.0 | ||
| ***********************************************************************/ | ||
|
|
||
| import type { ExtensionContext } from '@openkaiden/api'; | ||
| import type { AgentWorkspaceContext, ExtensionContext } from '@openkaiden/api'; | ||
| import { agents } from '@openkaiden/api'; | ||
|
|
||
| export const COPILOT_SETTINGS_PATH = '.copilot/settings.json'; | ||
|
|
||
| export async function activate(extensionContext: ExtensionContext): Promise<void> { | ||
| const disposable = agents.registerAgent({ | ||
| id: 'copilot', | ||
|
|
@@ -39,13 +41,41 @@ export async function activate(extensionContext: ExtensionContext): Promise<void | |
| command: 'copilot', | ||
| acp: { args: ['--acp'] }, | ||
| tags: [], | ||
| configurationFiles: [], | ||
| destinationSkillsFolder: '${HOME}/.copilot/skills', | ||
| configurationFiles: [ | ||
| { | ||
| path: COPILOT_SETTINGS_PATH, | ||
| async read(): Promise<string> { | ||
| return '{}'; | ||
| }, | ||
| }, | ||
| ], | ||
| isSupportedModelType(type): boolean { | ||
| return type.name !== 'vertexai'; | ||
| }, | ||
| async preWorkspaceStart(): Promise<void> { | ||
| throw new Error('not implemented'); | ||
| async preWorkspaceStart(context: AgentWorkspaceContext): Promise<void> { | ||
| const configFile = context.configurationFiles.find(f => f.path === COPILOT_SETTINGS_PATH); | ||
| if (!configFile) { | ||
| return; | ||
| } | ||
|
|
||
| const content = await configFile.read(); | ||
| let config: Record<string, unknown>; | ||
| try { | ||
| const parsed: unknown = JSON.parse(content); | ||
| config = | ||
| typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed) | ||
| ? (parsed as Record<string, unknown>) | ||
| : {}; | ||
| } catch { | ||
| config = {}; | ||
| } | ||
|
|
||
| const chat = (config.chat as Record<string, unknown> | undefined) ?? {}; | ||
| chat.model = context.model.model.label; | ||
| config.chat = chat; | ||
|
Comment on lines
+74
to
+76
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: git ls-files | grep -E "extensions/copilot/src/extension.ts"Repository: openkaiden/kaiden Length of output: 97 🏁 Script executed: head -100 extensions/copilot/src/extension.ts | tail -50Repository: openkaiden/kaiden Length of output: 1445 🏁 Script executed: sed -n '60,90p' extensions/copilot/src/extension.tsRepository: openkaiden/kaiden Length of output: 764 Guard At line 74, the type-cast does not enforce runtime shape. If Proposed fix- const chat = (config.chat as Record<string, unknown> | undefined) ?? {};
+ const existingChat = config.chat;
+ const chat =
+ typeof existingChat === 'object' && existingChat !== null && !Array.isArray(existingChat)
+ ? (existingChat as Record<string, unknown>)
+ : {};
chat.model = context.model.model.label;
config.chat = chat;🤖 Prompt for AI Agents |
||
|
|
||
| await configFile.update(JSON.stringify(config, undefined, 2)); | ||
| }, | ||
| }); | ||
| extensionContext.subscriptions.push(disposable); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Add a regression case for malformed
chatfield shape.Current cases cover non-object top-level JSON, but not object payloads where
chatitself is invalid (string/array/null). Add one case to ensurepreWorkspaceStartreplaces malformedchatwith an object and still preserves sibling fields.Suggested test addition
🤖 Prompt for AI Agents