kiki-agent 0.4.2 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/cpu-worker.mjs +52744 -0
- package/dist/docs/en/configuration/config-files.md +121 -46
- package/dist/docs/en/configuration/data-locations.md +34 -7
- package/dist/docs/en/configuration/env-vars.md +37 -9
- package/dist/docs/en/configuration/overrides.md +20 -9
- package/dist/docs/en/configuration/providers.md +114 -9
- package/dist/docs/en/customization/agent-profiles.md +1 -1
- package/dist/docs/en/customization/agents-and-subagents.md +55 -12
- package/dist/docs/en/customization/hooks.md +3 -3
- package/dist/docs/en/customization/personas.md +36 -2
- package/dist/docs/en/customization/plugins.md +56 -3
- package/dist/docs/en/customization/prompt-fields.md +65 -5
- package/dist/docs/en/customization/recipes.md +77 -0
- package/dist/docs/en/customization/skins.md +2 -2
- package/dist/docs/en/customization/themes.md +1 -1
- package/dist/docs/en/features/agent-workflows.md +8 -8
- package/dist/docs/en/features/browser-and-computer.md +40 -0
- package/dist/docs/en/features/daily.md +13 -13
- package/dist/docs/en/features/ecosystem.md +6 -6
- package/dist/docs/en/features/extend.md +11 -10
- package/dist/docs/en/features/freedom.md +9 -9
- package/dist/docs/en/features/index.md +58 -28
- package/dist/docs/en/features/long-work.md +18 -14
- package/dist/docs/en/features/look.md +6 -6
- package/dist/docs/en/features/people.md +6 -6
- package/dist/docs/en/features/phone.md +13 -3
- package/dist/docs/en/features/spaces.md +12 -12
- package/dist/docs/en/features/workbench.md +8 -8
- package/dist/docs/en/getting-started/desktop-app.md +4 -8
- package/dist/docs/en/getting-started/first-launch.md +1 -1
- package/dist/docs/en/guides/goals.md +4 -2
- package/dist/docs/en/guides/interface.md +32 -10
- package/dist/docs/en/guides/memory.md +64 -10
- package/dist/docs/en/guides/sessions.md +21 -9
- package/dist/docs/en/guides/settings.md +64 -40
- package/dist/docs/en/index.md +3 -1
- package/dist/docs/en/reference/command.md +90 -31
- package/dist/docs/en/reference/model-vocabulary.md +2 -2
- package/dist/docs/en/reference/slash-commands.md +1 -1
- package/dist/docs/en/reference/tools.md +65 -20
- package/dist/docs/en/server/acp.md +9 -3
- package/dist/docs/en/server/local-server.md +19 -27
- package/dist/docs/en/server/mcp.md +9 -5
- package/dist/docs/en/server/rest-api.md +350 -22
- package/dist/docs/en/server/script-tools.md +268 -0
- package/dist/docs/zh/configuration/config-files.md +121 -46
- package/dist/docs/zh/configuration/data-locations.md +34 -7
- package/dist/docs/zh/configuration/env-vars.md +37 -9
- package/dist/docs/zh/configuration/overrides.md +20 -9
- package/dist/docs/zh/configuration/providers.md +114 -9
- package/dist/docs/zh/customization/agent-profiles.md +1 -1
- package/dist/docs/zh/customization/agents-and-subagents.md +55 -12
- package/dist/docs/zh/customization/hooks.md +3 -3
- package/dist/docs/zh/customization/personas.md +36 -2
- package/dist/docs/zh/customization/plugins.md +56 -3
- package/dist/docs/zh/customization/prompt-fields.md +65 -5
- package/dist/docs/zh/customization/recipes.md +77 -0
- package/dist/docs/zh/customization/skins.md +2 -2
- package/dist/docs/zh/customization/themes.md +1 -1
- package/dist/docs/zh/features/agent-workflows.md +10 -10
- package/dist/docs/zh/features/browser-and-computer.md +40 -0
- package/dist/docs/zh/features/daily.md +13 -13
- package/dist/docs/zh/features/ecosystem.md +6 -6
- package/dist/docs/zh/features/extend.md +10 -9
- package/dist/docs/zh/features/freedom.md +9 -9
- package/dist/docs/zh/features/index.md +58 -28
- package/dist/docs/zh/features/long-work.md +17 -13
- package/dist/docs/zh/features/look.md +6 -6
- package/dist/docs/zh/features/people.md +5 -5
- package/dist/docs/zh/features/phone.md +13 -3
- package/dist/docs/zh/features/spaces.md +12 -12
- package/dist/docs/zh/features/workbench.md +8 -8
- package/dist/docs/zh/getting-started/desktop-app.md +4 -8
- package/dist/docs/zh/getting-started/first-launch.md +1 -1
- package/dist/docs/zh/guides/goals.md +4 -2
- package/dist/docs/zh/guides/interface.md +32 -10
- package/dist/docs/zh/guides/memory.md +64 -10
- package/dist/docs/zh/guides/sessions.md +21 -9
- package/dist/docs/zh/guides/settings.md +64 -40
- package/dist/docs/zh/index.md +4 -2
- package/dist/docs/zh/reference/command.md +90 -31
- package/dist/docs/zh/reference/model-vocabulary.md +2 -2
- package/dist/docs/zh/reference/slash-commands.md +1 -1
- package/dist/docs/zh/reference/tools.md +65 -20
- package/dist/docs/zh/server/acp.md +9 -3
- package/dist/docs/zh/server/local-server.md +19 -27
- package/dist/docs/zh/server/mcp.md +9 -5
- package/dist/docs/zh/server/rest-api.md +338 -21
- package/dist/docs/zh/server/script-tools.md +268 -0
- package/dist/external-harness/agy-cli-acp.mjs +168 -162
- package/dist/external-harness/agy-hook-registration.mjs +69 -30
- package/dist/external-harness/agy-mcp-plugin.mjs +19 -0
- package/dist/external-harness/agy-permission-hook.mjs +29 -2
- package/dist/hostRunner.mjs +112 -3
- package/dist/mailbox-worker.mjs +403 -0
- package/dist/main.mjs +2 -2
- package/dist/memory-worker.mjs +1008 -0
- package/dist/native/windows-process-helper.exe +0 -0
- package/dist/query-store-worker.mjs +487 -0
- package/dist/sqlite-indexer.mjs +255 -403
- package/dist/sqlite-query-worker.mjs +261 -249
- package/dist/usage-parser-worker.mjs +3977 -9
- package/dist/usage-read-model-worker.mjs +761 -0
- package/dist/web/assets/AppErrorBoundary-B5Fc4f6-.js +1 -0
- package/dist/web/assets/NavScopeBoundary-C7MnGQio.js +1 -0
- package/dist/web/assets/{arc-DYDCMlOS.js → arc-DGB9OVgQ.js} +1 -1
- package/dist/web/assets/{architectureDiagram-3BPJPVTR-C9Y7T0O2.js → architectureDiagram-3BPJPVTR-glnQCMub.js} +1 -1
- package/dist/web/assets/{blockDiagram-GPEHLZMM-CdUrp-tD.js → blockDiagram-GPEHLZMM-bM0tnGby.js} +1 -1
- package/dist/web/assets/{c4Diagram-AAUBKEIU-PrwvB9IJ.js → c4Diagram-AAUBKEIU-DMf_rTtt.js} +1 -1
- package/dist/web/assets/channel-Cj8SKJ38.js +1 -0
- package/dist/web/assets/{chunk-2J33WTMH-BL56g_Es.js → chunk-2J33WTMH-mTccJ3tW.js} +1 -1
- package/dist/web/assets/{chunk-4BX2VUAB-DvJD5M9M.js → chunk-4BX2VUAB-DhqPYMjY.js} +1 -1
- package/dist/web/assets/{chunk-55IACEB6-C8f-nzvx.js → chunk-55IACEB6-BujrYRoO.js} +1 -1
- package/dist/web/assets/{chunk-727SXJPM-DOGkWKkV.js → chunk-727SXJPM-ciMmSI4G.js} +1 -1
- package/dist/web/assets/{chunk-AQP2D5EJ-fFOuz7g6.js → chunk-AQP2D5EJ-CZW9pKTc.js} +1 -1
- package/dist/web/assets/{chunk-FMBD7UC4-BpeXZ9LM.js → chunk-FMBD7UC4-hdALNnnU.js} +1 -1
- package/dist/web/assets/{chunk-ND2GUHAM-CRUh76fb.js → chunk-ND2GUHAM-CgKyqUdb.js} +1 -1
- package/dist/web/assets/{chunk-QZHKN3VN-uNfxaPk0.js → chunk-QZHKN3VN-B2mmUz_E.js} +1 -1
- package/dist/web/assets/classDiagram-4FO5ZUOK-f8V9p-dD.js +1 -0
- package/dist/web/assets/classDiagram-v2-Q7XG4LA2-f8V9p-dD.js +1 -0
- package/dist/web/assets/client-ClWQBErG.js +3 -0
- package/dist/web/assets/connection-C0J3BPgk.js +1 -0
- package/dist/web/assets/{cose-bilkent-S5V4N54A-BNkxG-qX.js → cose-bilkent-S5V4N54A-UV3uPjkK.js} +1 -1
- package/dist/web/assets/{dagre-BM42HDAG-BerioUei.js → dagre-BM42HDAG-Zjy-gQ6C.js} +1 -1
- package/dist/web/assets/{diagram-2AECGRRQ-Czv2SR07.js → diagram-2AECGRRQ-DL-kilIf.js} +1 -1
- package/dist/web/assets/{diagram-5GNKFQAL-Uzi1weGK.js → diagram-5GNKFQAL-CjB_xR5B.js} +1 -1
- package/dist/web/assets/{diagram-KO2AKTUF-W36h_ff3.js → diagram-KO2AKTUF-CjN4i3b9.js} +1 -1
- package/dist/web/assets/{diagram-LMA3HP47-FG4dDk52.js → diagram-LMA3HP47-CPCAMndo.js} +1 -1
- package/dist/web/assets/{diagram-OG6HWLK6-CQoEjIAY.js → diagram-OG6HWLK6-DVeBWBKd.js} +1 -1
- package/dist/web/assets/{erDiagram-TEJ5UH35-Ck06KVyZ.js → erDiagram-TEJ5UH35-CHKzBHrr.js} +1 -1
- package/dist/web/assets/export-CXoWon32.js +2 -0
- package/dist/web/assets/{flowDiagram-I6XJVG4X-C5hgxdFZ.js → flowDiagram-I6XJVG4X-C5rQa2pq.js} +1 -1
- package/dist/web/assets/{ganttDiagram-6RSMTGT7-BS52Pw5_.js → ganttDiagram-6RSMTGT7-BrLjEsNJ.js} +1 -1
- package/dist/web/assets/{gitGraphDiagram-PVQCEYII-DLlQKZHs.js → gitGraphDiagram-PVQCEYII-3DRR5VZj.js} +1 -1
- package/dist/web/assets/highlighted-body-OFNGDK62-Bdj5SJfv.js +1 -0
- package/dist/web/assets/index-2Vx5mHRn.js +1 -0
- package/dist/web/assets/index-B1UXw2C9.js +1 -0
- package/dist/web/assets/{index-CM-nNfuV.js → index-BJxtlf4P.js} +4 -4
- package/dist/web/assets/{index-DKIysLbI.js → index-BY7jPurv.js} +1 -1
- package/dist/web/assets/index-Bq79v-Sa.js +1 -0
- package/dist/web/assets/index-BqD3iTIl.js +1 -0
- package/dist/web/assets/index-Br3AlBrQ.js +1 -0
- package/dist/web/assets/{index-Ca607_hK.js → index-BvRBCpc6.js} +2 -2
- package/dist/web/assets/index-BxYCSNg_.js +3 -0
- package/dist/web/assets/{index-B2Pu0Iuu.js → index-C62wjCF_.js} +1 -1
- package/dist/web/assets/index-CBvwNH_H.js +1 -0
- package/dist/web/assets/{index-BNch_a4L.js → index-CG9e6lgq.js} +1 -1
- package/dist/web/assets/{index-ByiwExpV.js → index-CPSWYh_R.js} +2 -2
- package/dist/web/assets/index-CS4xJLZV.js +1 -0
- package/dist/web/assets/index-CjvqtF2I.js +1 -0
- package/dist/web/assets/index-CprdjRRk.js +13 -0
- package/dist/web/assets/{index-Bg99yVX_.js → index-CypTtrCB.js} +1 -1
- package/dist/web/assets/{index-BwcG86o3.js → index-DDJQGcUL.js} +1 -1
- package/dist/web/assets/index-DLWzxUOO.js +1 -0
- package/dist/web/assets/index-DQxkxZmn.js +7 -0
- package/dist/web/assets/index-DRo5Y_9p.js +1 -0
- package/dist/web/assets/index-De_LkTZx.js +1 -0
- package/dist/web/assets/{index-CZX3qUe2.js → index-DfUpwUTM.js} +2 -2
- package/dist/web/assets/{index-BLU8_Um7.js → index-Dkbz748K.js} +2 -2
- package/dist/web/assets/index-DmwFFSkV.js +1 -0
- package/dist/web/assets/index-DpcWEDhW.js +1 -0
- package/dist/web/assets/index-Dqq1RDP4.js +1 -0
- package/dist/web/assets/index-H1uMvIoa.css +1 -0
- package/dist/web/assets/index-ICHWJ2SM.js +1 -0
- package/dist/web/assets/index-O5fSd569.js +229 -0
- package/dist/web/assets/index-odjtqLLS.js +1 -0
- package/dist/web/assets/index-v_yAQ0Am.js +1 -0
- package/dist/web/assets/{infoDiagram-5YYISTIA-CD4XJGFm.js → infoDiagram-5YYISTIA-CCwV4Z0v.js} +1 -1
- package/dist/web/assets/{ishikawaDiagram-YF4QCWOH-fu5E3_CT.js → ishikawaDiagram-YF4QCWOH-BwwZcGyZ.js} +1 -1
- package/dist/web/assets/{journeyDiagram-JHISSGLW-CXcnKBfJ.js → journeyDiagram-JHISSGLW-Dc6WqniQ.js} +1 -1
- package/dist/web/assets/{kanban-definition-UN3LZRKU-BawKH6Pl.js → kanban-definition-UN3LZRKU-DVUqULOS.js} +1 -1
- package/dist/web/assets/{linear-BplJuXph.js → linear-d6rWsNOU.js} +1 -1
- package/dist/web/assets/memoryAdvisor-DBQXJB1o.js +1 -0
- package/dist/web/assets/mermaid-GHXKKRXX-Ik6SkVDT.js +642 -0
- package/dist/web/assets/{mindmap-definition-RKZ34NQL-DA1SE2uy.js → mindmap-definition-RKZ34NQL-_JHAkhHL.js} +1 -1
- package/dist/web/assets/navViewState-DaCMIYWA.js +1 -0
- package/dist/web/assets/{pieDiagram-4H26LBE5-6i021QeX.js → pieDiagram-4H26LBE5-BlhlygGy.js} +1 -1
- package/dist/web/assets/{quadrantDiagram-W4KKPZXB-CcKSZDMT.js → quadrantDiagram-W4KKPZXB-jn6R_C0S.js} +1 -1
- package/dist/web/assets/{requirementDiagram-4Y6WPE33-lYVuWRuD.js → requirementDiagram-4Y6WPE33-B9fXCHBr.js} +1 -1
- package/dist/web/assets/{sankeyDiagram-5OEKKPKP-4Zfb4_h4.js → sankeyDiagram-5OEKKPKP-fPJwIxkl.js} +1 -1
- package/dist/web/assets/{sequenceDiagram-3UESZ5HK-DqltKmlY.js → sequenceDiagram-3UESZ5HK-1v1DTNGt.js} +1 -1
- package/dist/web/assets/{spaces-CjuXbmxF.js → spaces-CvL2DRZM.js} +1 -1
- package/dist/web/assets/{stateDiagram-AJRCARHV-HFdhqxzx.js → stateDiagram-AJRCARHV-CEc_PLov.js} +1 -1
- package/dist/web/assets/stateDiagram-v2-BHNVJYJU-iAMctzaT.js +1 -0
- package/dist/web/assets/theme-LRSmy8mD.js +1 -0
- package/dist/web/assets/{timeline-definition-PNZ67QCA-HNRxaB3t.js → timeline-definition-PNZ67QCA-CEjhuitj.js} +1 -1
- package/dist/web/assets/{vennDiagram-CIIHVFJN-DwsCTyaD.js → vennDiagram-CIIHVFJN-CActt9h9.js} +1 -1
- package/dist/web/assets/{wardley-L42UT6IY-BWW2wtVO.js → wardley-L42UT6IY-Bp3q2izt.js} +1 -1
- package/dist/web/assets/{wardleyDiagram-YWT4CUSO-C-ktKm7v.js → wardleyDiagram-YWT4CUSO-C_zutiQ2.js} +1 -1
- package/dist/web/assets/{xychartDiagram-2RQKCTM6-48AxNW9k.js → xychartDiagram-2RQKCTM6-CRafvv33.js} +1 -1
- package/dist/web/icons/apple-touch-icon.png +0 -0
- package/dist/web/icons/icon-192.png +0 -0
- package/dist/web/icons/icon-512.png +0 -0
- package/dist/web/icons/maskable-512.png +0 -0
- package/dist/web/index.html +12 -2
- package/dist/web/manifest.webmanifest +16 -0
- package/native/auth-native/prebuilds/linux-arm64/auth-native.node +0 -0
- package/native/auth-native/prebuilds/linux-x64/auth-native.node +0 -0
- package/native/auth-native/prebuilds/win32-arm64/auth-native.node +0 -0
- package/native/auth-native/prebuilds/win32-x64/auth-native.node +0 -0
- package/package.json +23 -4
- package/dist/search-worker.mjs +0 -14177
- package/dist/web/assets/AppErrorBoundary-DiGMUg4r.js +0 -1
- package/dist/web/assets/LifeMark-CL6-HWDu.js +0 -1
- package/dist/web/assets/NavScopeBoundary-CFCnvZR0.js +0 -1
- package/dist/web/assets/channel-Bj_gZ_Lv.js +0 -1
- package/dist/web/assets/classDiagram-4FO5ZUOK-ssCwe2R4.js +0 -1
- package/dist/web/assets/classDiagram-v2-Q7XG4LA2-ssCwe2R4.js +0 -1
- package/dist/web/assets/client-DGj93bGT.js +0 -3
- package/dist/web/assets/connection-Bpf-EjrL.js +0 -1
- package/dist/web/assets/export-T_izwEkQ.js +0 -2
- package/dist/web/assets/highlighted-body-OFNGDK62-Btm6MuZ4.js +0 -1
- package/dist/web/assets/index-5_yzg61S.js +0 -1
- package/dist/web/assets/index-B-6LiYTY.js +0 -1
- package/dist/web/assets/index-B4iu4SJW.js +0 -1
- package/dist/web/assets/index-B9MlqF7J.js +0 -1
- package/dist/web/assets/index-BECSk4If.js +0 -1
- package/dist/web/assets/index-BFcyN2Zw.js +0 -1
- package/dist/web/assets/index-BIebkSEI.css +0 -1
- package/dist/web/assets/index-BMWid2q9.js +0 -1
- package/dist/web/assets/index-BeMvPEXs.js +0 -1
- package/dist/web/assets/index-Bezli3SF.js +0 -1
- package/dist/web/assets/index-BkPV0psm.js +0 -1
- package/dist/web/assets/index-CG8uIlD7.js +0 -1
- package/dist/web/assets/index-CJ92kLtO.js +0 -1
- package/dist/web/assets/index-CRDDqofN.js +0 -1
- package/dist/web/assets/index-Cd62y0wD.js +0 -1
- package/dist/web/assets/index-CgcJPsK6.js +0 -3
- package/dist/web/assets/index-Cy8C_eFR.js +0 -7
- package/dist/web/assets/index-D8z7lcQn.js +0 -166
- package/dist/web/assets/index-D_oPSlBL.js +0 -1
- package/dist/web/assets/index-Dceu0bqY.js +0 -1
- package/dist/web/assets/index-eUyF-8Sq.js +0 -1
- package/dist/web/assets/index-hG2s2Spn.js +0 -13
- package/dist/web/assets/mermaid-GHXKKRXX-BO9hkP3Z.js +0 -621
- package/dist/web/assets/stateDiagram-v2-BHNVJYJU-Dx28QuZF.js +0 -1
- package/dist/web/assets/theme-beWE_6f8.js +0 -1
|
@@ -2,10 +2,10 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import { appendFile, mkdir, readFile, open, unlink } from 'node:fs/promises';
|
|
4
4
|
import { createInterface } from 'node:readline';
|
|
5
|
-
import { registerProjectMcpPlugin, recoverProjectMcpPlugin } from './agy-mcp-plugin.mjs';
|
|
5
|
+
import { registerProjectMcpPlugin, recoverProjectMcpPlugin, recoverDeadProjectMcpPlugins } from './agy-mcp-plugin.mjs';
|
|
6
6
|
import { resolve, isAbsolute } from 'node:path';
|
|
7
7
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
8
|
-
import { registerProjectHook, recoverProjectHook } from './agy-hook-registration.mjs';
|
|
8
|
+
import { registerProjectHook, recoverProjectHook, AGY_STEERING_HOOK_KEY } from './agy-hook-registration.mjs';
|
|
9
9
|
import { Readable, Writable } from 'node:stream';
|
|
10
10
|
import { StringDecoder } from 'node:string_decoder';
|
|
11
11
|
import { openPermissionChannel, permissionChannelIdentity, requestHookPermission } from './agy-permission-hook.mjs';
|
|
@@ -24,54 +24,18 @@ export function launchArgs(session) {
|
|
|
24
24
|
const args = ['--input-format', 'stream-json', '--output-format', 'stream-json'];
|
|
25
25
|
if (session.conversationId) args.push('--conversation', session.conversationId);
|
|
26
26
|
if (session.model !== DEFAULT) args.push('--model', session.model);
|
|
27
|
-
if (session.effort !== DEFAULT) args.push('--effort', session.effort);
|
|
28
|
-
|
|
27
|
+
if (session.effort !== DEFAULT && !session.model.startsWith('claude-')) args.push('--effort', session.effort);
|
|
28
|
+
const mode = session.permissionMode ?? DEFAULT;
|
|
29
|
+
if (mode === 'yolo') args.push('--dangerously-skip-permissions');
|
|
30
|
+
const settings = mode === 'manual' ? { toolPermission: 'request-review', agentMode: 'default' }
|
|
31
|
+
: mode === 'auto' ? { toolPermission: 'request-review', agentMode: 'auto' }
|
|
32
|
+
: mode === 'yolo' ? { toolPermission: 'always-proceed', agentMode: 'accept-edits', allowNonWorkspaceAccess: true, enableTerminalSandbox: false }
|
|
33
|
+
: undefined;
|
|
34
|
+
if (settings !== undefined) args.push('--settings', JSON.stringify(settings));
|
|
29
35
|
for (const dir of session.additionalDirectories) args.push('--add-dir', dir);
|
|
30
36
|
return args;
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
function readUrlTarget(args) {
|
|
34
|
-
if (!args || Object.keys(args).some(key => key !== 'Url') || typeof args.Url !== 'string' ||
|
|
35
|
-
!/^https?:\/\//iu.test(args.Url) || /[\s\\\u0000-\u001F\u007F]/u.test(args.Url)) throw new Error('AGY URL reads require one credential-free HTTP(S) Url');
|
|
36
|
-
let url;
|
|
37
|
-
try { url = new URL(args.Url); } catch { throw new Error('AGY URL reads require one credential-free HTTP(S) Url'); }
|
|
38
|
-
if (!url.hostname || url.username || url.password) throw new Error('AGY URL reads require one credential-free HTTP(S) Url');
|
|
39
|
-
if (url.hostname.endsWith('.')) url.hostname = url.hostname.slice(0, -1);
|
|
40
|
-
return url;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function canonicalTool(name, args, cwd) {
|
|
44
|
-
if (name === 'read_url_content') return { name: 'FetchURL', nativeName: name, kind: 'fetch', input: { url: readUrlTarget(args).href } };
|
|
45
|
-
if (name === 'manage_task' && Object.keys(args).every(key => ['Action', 'TaskId', 'Input'].includes(key)) &&
|
|
46
|
-
['TaskId', 'Input'].every(key => args[key] === undefined || typeof args[key] === 'string')) {
|
|
47
|
-
if (args.Action === 'list') return { name: 'TaskList', nativeName: name, kind: 'read', input: args };
|
|
48
|
-
if (args.Action === 'status' && typeof args.TaskId === 'string' && args.TaskId.length > 0) {
|
|
49
|
-
return { name: 'TaskOutput', nativeName: name, kind: 'read', input: args };
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (name === 'run_command') return { name: 'Bash', kind: 'execute', input: { command: args.CommandLine, cwd: args.Cwd ?? cwd } };
|
|
53
|
-
if (name === 'view_file') return { name: 'Read', kind: 'read', input: { path: args.AbsolutePath } };
|
|
54
|
-
if (name === 'write_to_file') return { name: 'Write', kind: 'edit', input: { path: args.TargetFile } };
|
|
55
|
-
if (name === 'replace_file_content' || name === 'multi_replace_file_content') return { name: 'Edit', kind: 'edit', input: { path: args.TargetFile } };
|
|
56
|
-
if (name === 'find_by_name') return { name: 'Glob', kind: 'search', input: { path: args.SearchDirectory, pattern: args.Pattern } };
|
|
57
|
-
if (name === 'list_dir') return { name: 'Glob', kind: 'search', input: { path: args.DirectoryPath } };
|
|
58
|
-
if (name === 'grep_search') return { name: 'Grep', kind: 'search', input: { path: args.SearchPath, pattern: args.Query } };
|
|
59
|
-
return { name, kind: 'other', input: args };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Official PreToolUse resource strings for this call only; never a cached grant. */
|
|
63
|
-
export function toolPermissionResources(name, args) {
|
|
64
|
-
if (name === 'read_url_content') return [`read_url(${readUrlTarget(args).hostname})`];
|
|
65
|
-
let action; let target;
|
|
66
|
-
if (name === 'run_command') { action = 'command'; target = args.CommandLine; }
|
|
67
|
-
else if (['write_to_file', 'replace_file_content', 'multi_replace_file_content'].includes(name)) { action = 'write_file'; target = args.TargetFile; }
|
|
68
|
-
else if (name === 'view_file') { action = 'read_file'; target = args.AbsolutePath; }
|
|
69
|
-
else if (name === 'list_dir') { action = 'read_file'; target = args.DirectoryPath; }
|
|
70
|
-
else if (name === 'find_by_name') { action = 'read_file'; target = args.SearchDirectory; }
|
|
71
|
-
else if (name === 'grep_search') { action = 'read_file'; target = args.SearchPath; }
|
|
72
|
-
return action && typeof target === 'string' && target.length > 0 ? [`${action}(${target})`] : undefined;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
39
|
export function promptText(blocks) {
|
|
76
40
|
if (!Array.isArray(blocks) || blocks.some(b => b.type !== 'text' || typeof b.text !== 'string')) {
|
|
77
41
|
throw new Error('This AGY ACP adapter accepts text prompts only; CLI rich-input support has not been verified');
|
|
@@ -180,6 +144,11 @@ export function configOptions(session) {
|
|
|
180
144
|
}
|
|
181
145
|
options.push({ id: 'native-agent', name: 'AGY native agent', category: 'native_agent', type: 'select',
|
|
182
146
|
currentValue: DEFAULT, options: [{ value: DEFAULT, name: 'Follow AGY default agent' }] });
|
|
147
|
+
options.push({ id: 'permission-mode', name: 'AGY permissions', category: 'permission_mode', type: 'select',
|
|
148
|
+
currentValue: session.permissionMode ?? DEFAULT, options: [
|
|
149
|
+
{ value: DEFAULT, name: 'Follow AGY settings' }, { value: 'manual', name: 'Request review' },
|
|
150
|
+
{ value: 'auto', name: 'AGY auto mode' }, { value: 'yolo', name: 'Full access' },
|
|
151
|
+
] });
|
|
183
152
|
return options;
|
|
184
153
|
}
|
|
185
154
|
|
|
@@ -214,53 +183,14 @@ export class AgyBridge {
|
|
|
214
183
|
}
|
|
215
184
|
|
|
216
185
|
initialize(version) {
|
|
217
|
-
return { protocolVersion: version, agentInfo: { name: 'agy-cli-acp', version: '0.
|
|
186
|
+
return { protocolVersion: version, agentInfo: { name: 'agy-cli-acp', version: '0.2.0' },
|
|
218
187
|
agentCapabilities: { loadSession: Boolean(this.auditDir), promptCapabilities: { image: false, audio: false, embeddedContext: false },
|
|
219
188
|
mcpCapabilities: { http: false, sse: false }, sessionCapabilities: { additionalDirectories: {} } },
|
|
220
|
-
authMethods: [] };
|
|
189
|
+
authMethods: [], _meta: { steering: { supported: true } } };
|
|
221
190
|
}
|
|
222
191
|
|
|
223
|
-
async requestPermission(
|
|
224
|
-
|
|
225
|
-
const active = session.active;
|
|
226
|
-
const reject = reason => ({ decision: 'deny', reason });
|
|
227
|
-
if (!active || session.broken || typeof active.client.request !== 'function') return reject('Kiki AGY permission gate is unavailable for this turn');
|
|
228
|
-
if (!input || typeof input.conversationId !== 'string' || !Number.isSafeInteger(input.stepIdx) || input.stepIdx < 0
|
|
229
|
-
|| !input.toolCall || typeof input.toolCall.name !== 'string' || !input.toolCall.args || typeof input.toolCall.args !== 'object') {
|
|
230
|
-
return reject('Invalid AGY PreToolUse payload');
|
|
231
|
-
}
|
|
232
|
-
if (!session.init || input.conversationId !== session.init.conversation_id) return reject('AGY permission conversation identity does not match this session');
|
|
233
|
-
const id = `agy-${input.conversationId}-${input.stepIdx}`;
|
|
234
|
-
const name = input.toolCall.name;
|
|
235
|
-
const args = input.toolCall.args;
|
|
236
|
-
const { kind, ...permissionTool } = canonicalTool(name, args, session.cwd);
|
|
237
|
-
await this.audit(session, 'permission_request', { toolCallId: id, name, policyIdentity: session.permission.policyIdentity, override: session.permission.override });
|
|
238
|
-
const controller = new AbortController();
|
|
239
|
-
session.permissionRequests.add(controller);
|
|
240
|
-
let response;
|
|
241
|
-
try {
|
|
242
|
-
response = await active.client.request('session/request_permission', {
|
|
243
|
-
sessionId: session.id,
|
|
244
|
-
toolCall: { toolCallId: id, title: name, kind, status: 'in_progress', rawInput: args },
|
|
245
|
-
options: [{ optionId: 'allow_once', name: 'Allow once', kind: 'allow_once' },
|
|
246
|
-
{ optionId: 'reject_once', name: 'Reject once', kind: 'reject_once' },
|
|
247
|
-
{ optionId: 'kiki.vendor_default', name: 'Use vendor permissions', kind: 'allow_once' }],
|
|
248
|
-
_meta: { 'kiki.tool': permissionTool },
|
|
249
|
-
}, { signal: controller.signal });
|
|
250
|
-
} finally { session.permissionRequests.delete(controller); }
|
|
251
|
-
if (session.active !== active || session.broken) return reject('Kiki AGY turn ended while awaiting permission');
|
|
252
|
-
if (response?.outcome?.outcome === 'selected' && response.outcome.optionId === 'kiki.vendor_default') {
|
|
253
|
-
await this.audit(session, 'permission_decision', { toolCallId: id, decision: 'vendor_default' });
|
|
254
|
-
return { decision: 'ask' };
|
|
255
|
-
}
|
|
256
|
-
const allow = response?.outcome?.outcome === 'selected' && ['allow_once', 'allow_always'].includes(response.outcome.optionId);
|
|
257
|
-
const permissionOverrides = allow ? toolPermissionResources(name, args) : undefined;
|
|
258
|
-
if (allow) (active.hostApproved ??= new Set()).add(id);
|
|
259
|
-
else (active.hostDenied ??= new Set()).add(id);
|
|
260
|
-
await this.audit(session, 'permission_decision', { toolCallId: id, decision: allow ? 'allow' : 'deny', permissionOverrides });
|
|
261
|
-
if (!allow) await this.settleTool(session, active, id, 'failed', 'The current Kiki permission gate rejected or cancelled this action before execution');
|
|
262
|
-
return allow ? { decision: 'allow', reason: 'Approved by the current Kiki permission gate', permissionOverrides }
|
|
263
|
-
: reject('The current Kiki permission gate rejected or cancelled this action');
|
|
192
|
+
async requestPermission() {
|
|
193
|
+
return { decision: 'ask' };
|
|
264
194
|
}
|
|
265
195
|
|
|
266
196
|
async newSession(params, id = randomUUID(), event = 'session_new') {
|
|
@@ -278,22 +208,16 @@ export class AgyBridge {
|
|
|
278
208
|
const session = { id, cwd: params.cwd, additionalDirectories: dirs, model: this.model, effort: DEFAULT,
|
|
279
209
|
modelChoices: this.modelChoices,
|
|
280
210
|
mcpServers: structuredClone(mcpServers), mcpPlugin: undefined, mcpBound: new Set(), mcpReady: new Set(),
|
|
281
|
-
|
|
282
|
-
permissionRequests: new Set(), permissionChannel: undefined, permissionRegistration: undefined,
|
|
211
|
+
permissionIdentity: permissionChannelIdentity(), permissionChannel: undefined,
|
|
283
212
|
child: undefined, active: undefined, broken: false, init: undefined, exited: undefined, toolIds: new Map(), toolDetails: new Map() };
|
|
284
|
-
this.permissionSnapshot(session, params._meta?.['kiki.permission']);
|
|
285
213
|
this.sessions.set(session.id, session);
|
|
286
214
|
try {
|
|
287
|
-
|
|
288
|
-
await this.syncPermissionHook(session);
|
|
289
|
-
session.permissionReceipt = { version: 1, sessionId: session.id, openMode: event === 'session_new' ? 'new' : 'load',
|
|
290
|
-
gate: 'pre-tool-hook', applied: structuredClone(session.permission) };
|
|
291
|
-
}
|
|
215
|
+
await this.recoverDeadOwnedResources(session);
|
|
292
216
|
await this.audit(session, event, { cwd: session.cwd, additionalDirectories: dirs, delivery: event === 'session_new' ? 'first_user_preamble' : 'native_conversation', systemOverride: false });
|
|
293
|
-
return { sessionId: session.id, configOptions: configOptions(session)
|
|
217
|
+
return { sessionId: session.id, configOptions: configOptions(session) };
|
|
294
218
|
} catch (error) {
|
|
295
219
|
await session.permissionChannel?.close();
|
|
296
|
-
await session.
|
|
220
|
+
await this.closeSteeringHook(session).catch(() => {});
|
|
297
221
|
this.sessions.delete(session.id);
|
|
298
222
|
throw error;
|
|
299
223
|
}
|
|
@@ -325,7 +249,7 @@ export class AgyBridge {
|
|
|
325
249
|
const argValue = name => { const index = launch.args.lastIndexOf(name); return index < 0 ? DEFAULT : launch.args[index + 1]; };
|
|
326
250
|
const model = argValue('--model') === DEFAULT ? init.model : argValue('--model');
|
|
327
251
|
if (typeof model !== 'string' || !model || this.model !== DEFAULT && model !== this.model) throw new Error('AGY native load model differs from its original binding or was not confirmed');
|
|
328
|
-
const effort = argValue('--effort');
|
|
252
|
+
const effort = launch.effort ?? argValue('--effort');
|
|
329
253
|
validateEffort(model, effort);
|
|
330
254
|
if (processAlive(launch.pid)) throw new Error('AGY native conversation still has an owned process; close it before loading');
|
|
331
255
|
const path = resolve(this.auditDir, `${params.sessionId}.resume-lock`);
|
|
@@ -352,7 +276,7 @@ export class AgyBridge {
|
|
|
352
276
|
session.conversationId = init.conversationId;
|
|
353
277
|
session.mcpNamespace = mcpBinding?.name;
|
|
354
278
|
session.releaseResume = release;
|
|
355
|
-
return { configOptions: configOptions(session)
|
|
279
|
+
return { configOptions: configOptions(session) };
|
|
356
280
|
} catch (error) { await release(); this.sessions.delete(params.sessionId); throw error; }
|
|
357
281
|
}
|
|
358
282
|
|
|
@@ -390,6 +314,7 @@ export class AgyBridge {
|
|
|
390
314
|
setConfig(params) {
|
|
391
315
|
const session = this.session(params.sessionId);
|
|
392
316
|
if (params.configId === 'model') return this.setModel(session, params.value);
|
|
317
|
+
if (params.configId === 'permission-mode') return this.setPermissionMode(session, params.value);
|
|
393
318
|
if (params.configId === 'native-agent') {
|
|
394
319
|
if (params.value !== DEFAULT) throw Error('AGY adapter supports only the native default agent; other native agents have not been discovered');
|
|
395
320
|
return { configOptions: configOptions(session) };
|
|
@@ -402,41 +327,38 @@ export class AgyBridge {
|
|
|
402
327
|
return { configOptions: configOptions(session) };
|
|
403
328
|
}
|
|
404
329
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
if (
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
||
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
330
|
+
async setPermissionMode(session, value) {
|
|
331
|
+
if (![DEFAULT, 'manual', 'auto', 'yolo'].includes(value)) throw Error(`AGY native permission mode ${value} is unsupported; review requires the Kiki native executor`);
|
|
332
|
+
if (session.permissionMode === value) return { configOptions: configOptions(session) };
|
|
333
|
+
if (session.active) throw Error('AGY permission mode cannot change during an active turn');
|
|
334
|
+
if (session.child) {
|
|
335
|
+
const conversationId = session.init?.conversation_id;
|
|
336
|
+
if (!conversationId || session.broken) throw Error('AGY permission changes require a confirmed healthy native conversation');
|
|
337
|
+
session.restarting = true;
|
|
338
|
+
try {
|
|
339
|
+
await this.stopProcess(session.child);
|
|
340
|
+
await session.cleanup;
|
|
341
|
+
session.conversationId = conversationId;
|
|
342
|
+
session.child = undefined;
|
|
343
|
+
session.init = undefined;
|
|
344
|
+
session.exited = undefined;
|
|
345
|
+
session.cleanup = undefined;
|
|
346
|
+
session.permissionChannel = undefined;
|
|
347
|
+
session.mcpPlugin = undefined;
|
|
348
|
+
session.mcpBound.clear();
|
|
349
|
+
session.mcpReady.clear();
|
|
350
|
+
session.broken = false;
|
|
351
|
+
} finally { session.restarting = false; }
|
|
419
352
|
}
|
|
420
|
-
session.
|
|
421
|
-
session
|
|
353
|
+
session.permissionMode = value;
|
|
354
|
+
await this.audit(session, 'permission_mode_configured', { value, mechanism: 'native-session-settings' });
|
|
355
|
+
return { configOptions: configOptions(session) };
|
|
422
356
|
}
|
|
423
357
|
|
|
424
|
-
/**
|
|
425
|
-
* A native child cannot receive new environment variables mid-session. Its random
|
|
426
|
-
* channel identity is fixed at launch; inherited turns return the vendor's empty
|
|
427
|
-
* default and do not register a project hook. The per-turn hostGate snapshot
|
|
428
|
-
* controls only the owned project key, preserving the native process and history.
|
|
429
|
-
*/
|
|
430
358
|
async syncPermissionHook(session) {
|
|
431
359
|
session.permissionChannel ??= await openPermissionChannel(input => ['mcp_bootstrap', 'mcp_ready'].includes(input?.type)
|
|
432
|
-
? this.bindMcpBootstrap(session, input) : this.
|
|
433
|
-
|
|
434
|
-
await session.permissionRegistration?.close();
|
|
435
|
-
session.permissionRegistration = undefined;
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
session.permissionRegistration ??= await registerProjectHook({ cwd: session.cwd, nodePath: process.execPath,
|
|
439
|
-
handlerPath: fileURLToPath(new URL('./agy-permission-hook.mjs', import.meta.url)), sessionId: session.id });
|
|
360
|
+
? this.bindMcpBootstrap(session, input) : input?.type === 'steer_poll' ? this.pollSteering(session, input)
|
|
361
|
+
: this.requestPermission(), session.permissionIdentity);
|
|
440
362
|
}
|
|
441
363
|
|
|
442
364
|
async registerMcpPlugin(session) {
|
|
@@ -460,6 +382,97 @@ export class AgyBridge {
|
|
|
460
382
|
return { decision: 'allow' };
|
|
461
383
|
}
|
|
462
384
|
|
|
385
|
+
/**
|
|
386
|
+
* A previous adapter killed before its close ran can leave its owned hook keys and MCP
|
|
387
|
+
* plugin in this workspace. Before this session registers its own, recover only those
|
|
388
|
+
* whose every recorded owner process has exited; live leases, edited files and foreign
|
|
389
|
+
* entries are preserved and reported in the audit instead of failing the session.
|
|
390
|
+
*/
|
|
391
|
+
async recoverDeadOwnedResources(session) {
|
|
392
|
+
if (session.ownedRecoveryDone) return;
|
|
393
|
+
session.ownedRecoveryDone = true;
|
|
394
|
+
const results = {};
|
|
395
|
+
try {
|
|
396
|
+
results.hooks = (await recoverProjectHook({ cwd: session.cwd, nodePath: process.execPath,
|
|
397
|
+
handlerPath: fileURLToPath(new URL('./agy-permission-hook.mjs', import.meta.url)) })).status;
|
|
398
|
+
} catch (error) { results.hooks = { status: 'preserved', reason: error instanceof Error ? error.message : String(error) }; }
|
|
399
|
+
try { results.plugins = await recoverDeadProjectMcpPlugins({ cwd: session.cwd }); }
|
|
400
|
+
catch (error) { results.plugins = { status: 'preserved', reason: error instanceof Error ? error.message : String(error) }; }
|
|
401
|
+
if (results.hooks !== 'no-owned-registration' || results.plugins.length) this.auditQuietly(session, 'owned_recovery', results);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
async registerSteeringHook(session) {
|
|
405
|
+
session.steeringRegistration ??= await registerProjectHook({ cwd: session.cwd, nodePath: process.execPath,
|
|
406
|
+
handlerPath: fileURLToPath(new URL('./agy-permission-hook.mjs', import.meta.url)), sessionId: session.id,
|
|
407
|
+
key: AGY_STEERING_HOOK_KEY, args: ['--steering'] });
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Removes this turn's owned PostInvocation key. A failed removal keeps the registration
|
|
412
|
+
* on the session so the next turn end, cancel or close retries it; the turn result is
|
|
413
|
+
* never replaced by the cleanup error.
|
|
414
|
+
*/
|
|
415
|
+
async closeSteeringHook(session) {
|
|
416
|
+
const registration = session.steeringRegistration;
|
|
417
|
+
if (!registration) return;
|
|
418
|
+
try {
|
|
419
|
+
await registration.close();
|
|
420
|
+
if (session.steeringRegistration === registration) session.steeringRegistration = undefined;
|
|
421
|
+
} catch (error) {
|
|
422
|
+
this.auditQuietly(session, 'steering_hook_close_failed', { error: error instanceof Error ? error.message : String(error) });
|
|
423
|
+
throw error;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
auditQuietly(session, type, data) {
|
|
428
|
+
this.audit(session, type, data).catch(() => {});
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Accepts one steering message for the running native turn. The text waits in this
|
|
433
|
+
* session until AGY's next PostInvocation hook drains it into the same invocation loop.
|
|
434
|
+
* An idle session returns `promptRequired` so the host submits a normal prompt instead.
|
|
435
|
+
*/
|
|
436
|
+
async steer(params) {
|
|
437
|
+
const session = this.session(params.sessionId);
|
|
438
|
+
const active = session.active;
|
|
439
|
+
if (!active || session.broken || !session.steeringRegistration) return { outcome: 'promptRequired', reason: 'noRunningTurn' };
|
|
440
|
+
const text = promptText(params.prompt);
|
|
441
|
+
const id = randomUUID();
|
|
442
|
+
await this.audit(session, 'steer_queued', { steerId: id, sha256: createHash('sha256').update(text).digest('hex') });
|
|
443
|
+
if (session.active !== active || session.broken || !session.steeringRegistration) {
|
|
444
|
+
this.auditQuietly(session, 'steer_not_delivered', { steerIds: [id] });
|
|
445
|
+
return { outcome: 'promptRequired', reason: 'turnEnded' };
|
|
446
|
+
}
|
|
447
|
+
return new Promise(resolveSteer => active.steering.push({ id, text, resolve: resolveSteer }));
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
releaseSteering(session, active) {
|
|
451
|
+
const pending = active.steering.splice(0);
|
|
452
|
+
if (pending.length) this.auditQuietly(session, 'steer_not_delivered', { steerIds: pending.map(item => item.id) });
|
|
453
|
+
for (const item of pending) item.resolve({ outcome: 'promptRequired', reason: 'turnEnded' });
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
async pollSteering(session, input) {
|
|
457
|
+
const active = session.active;
|
|
458
|
+
if (!active || session.broken || !session.init || input.conversationId !== session.init.conversation_id) {
|
|
459
|
+
return { decision: 'deny', reason: 'AGY steering poll does not belong to the running turn' };
|
|
460
|
+
}
|
|
461
|
+
if (active.steering.length === 0) return { decision: 'allow', steering: { injectSteps: [] } };
|
|
462
|
+
const batch = active.steering.splice(0);
|
|
463
|
+
this.auditQuietly(session, 'steer_delivering', { steerIds: batch.map(item => item.id), invocationNum: input.invocationNum });
|
|
464
|
+
let settled = false;
|
|
465
|
+
const settle = (outcome, type) => {
|
|
466
|
+
if (settled) return;
|
|
467
|
+
settled = true;
|
|
468
|
+
this.auditQuietly(session, type, { steerIds: batch.map(item => item.id) });
|
|
469
|
+
for (const item of batch) item.resolve({ outcome });
|
|
470
|
+
};
|
|
471
|
+
return { decision: 'allow', steering: { injectSteps: batch.map(item => ({ userMessage: item.text })) },
|
|
472
|
+
afterWrite: () => settle('injected', 'steer_delivered'),
|
|
473
|
+
afterFailure: () => settle('deliveryUnknown', 'steer_delivery_unknown') };
|
|
474
|
+
}
|
|
475
|
+
|
|
463
476
|
async start(session) {
|
|
464
477
|
await this.registerMcpPlugin(session);
|
|
465
478
|
const args = [...this.cliPrefix, ...launchArgs(session)];
|
|
@@ -472,12 +485,11 @@ export class AgyBridge {
|
|
|
472
485
|
child = this.spawnProcess(this.cliPath, args, { cwd: session.cwd, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true, env });
|
|
473
486
|
} catch (error) {
|
|
474
487
|
await session.permissionChannel?.close();
|
|
475
|
-
await session.
|
|
488
|
+
await this.closeSteeringHook(session).catch(() => {});
|
|
476
489
|
await session.mcpPlugin?.close();
|
|
477
490
|
throw error;
|
|
478
491
|
}
|
|
479
492
|
session.child = child;
|
|
480
|
-
session.nativePermissionBypass = args.includes('--dangerously-skip-permissions');
|
|
481
493
|
session.exited = new Promise(done => child.once('close', done));
|
|
482
494
|
const decoder = new StringDecoder('utf8');
|
|
483
495
|
let buffer = '';
|
|
@@ -533,18 +545,17 @@ export class AgyBridge {
|
|
|
533
545
|
session.active.reject(error);
|
|
534
546
|
session.active = undefined;
|
|
535
547
|
}
|
|
536
|
-
for (const controller of session.permissionRequests) controller.abort(new Error('AGY process ended'));
|
|
537
548
|
await session.permissionChannel?.close();
|
|
538
|
-
await session.
|
|
549
|
+
await this.closeSteeringHook(session).catch(() => {});
|
|
539
550
|
await session.mcpPlugin?.close();
|
|
540
|
-
await session.releaseResume?.();
|
|
551
|
+
if (!session.restarting) await session.releaseResume?.();
|
|
541
552
|
}
|
|
542
553
|
})();
|
|
543
554
|
session.cleanup.catch(error => { process.stderr.write(`AGY owned permission cleanup failed: ${error.message}\n`); });
|
|
544
555
|
});
|
|
545
556
|
try { await session.mcpPlugin?.launched(child.pid); }
|
|
546
557
|
catch (error) { await this.stopProcess(child); await session.cleanup; throw error; }
|
|
547
|
-
return this.audit(session, 'launch', { cliPath: this.cliPath, args, pid: child.pid, cwd: session.cwd });
|
|
558
|
+
return this.audit(session, 'launch', { cliPath: this.cliPath, args, effort: session.effort, pid: child.pid, cwd: session.cwd });
|
|
548
559
|
}
|
|
549
560
|
|
|
550
561
|
async settleTool(session, active, toolCallId, status, message) {
|
|
@@ -606,10 +617,6 @@ export class AgyBridge {
|
|
|
606
617
|
(active.preToolDenied ??= new Set()).add(id);
|
|
607
618
|
await this.audit(session, 'pre_tool_hook_denied', { toolCallId: id, error: errorText ?? output });
|
|
608
619
|
}
|
|
609
|
-
if (failed && active.hostApproved?.has(id) && /\bpermissions?\s+(?:check\s+)?(?:denied|failed)\b|\b(?:user|resource)\s+denied\s+permission\b/i.test(errorText ?? output ?? '')) {
|
|
610
|
-
(active.vendorRejected ??= new Set()).add(id);
|
|
611
|
-
await this.audit(session, 'vendor_denied_after_host_allow', { toolCallId: id, error: errorText ?? output });
|
|
612
|
-
}
|
|
613
620
|
await active.client.notify('session/update', { sessionId: session.id,
|
|
614
621
|
update: { sessionUpdate: 'tool_call_update', toolCallId: id, status: failed ? 'failed' : 'completed',
|
|
615
622
|
rawOutput: output, content: typeof output === 'string'
|
|
@@ -627,9 +634,6 @@ export class AgyBridge {
|
|
|
627
634
|
if (result.status === 'SUCCESS' && session.mcpServers.length !== session.mcpReady.size) {
|
|
628
635
|
throw new Error('AGY did not activate and initialize the requested session MCP plugin; preserve native plugin/MCP off settings and review the connection instead of switching agents');
|
|
629
636
|
}
|
|
630
|
-
for (const toolCallId of active.hostDenied ?? []) {
|
|
631
|
-
await this.settleTool(session, active, toolCallId, 'failed', 'The current Kiki permission gate rejected or cancelled this action before execution');
|
|
632
|
-
}
|
|
633
637
|
const unresolved = [...session.toolIds].filter(([, status]) => status === 'pending')
|
|
634
638
|
.map(([toolCallId]) => ({ toolCallId, ...session.toolDetails.get(toolCallId) }));
|
|
635
639
|
const unresolvedMessage = unresolved.length
|
|
@@ -640,21 +644,17 @@ export class AgyBridge {
|
|
|
640
644
|
session.failure = unresolvedMessage;
|
|
641
645
|
await this.audit(session, 'tool_terminal_missing', { conversationId: result.conversation_id, nativeStatus: result.status, tools: unresolved });
|
|
642
646
|
}
|
|
643
|
-
if (session.denied || result.denied_actions?.length || active.preToolDenied?.size
|
|
647
|
+
if (session.denied || result.denied_actions?.length || active.preToolDenied?.size) {
|
|
644
648
|
session.denied = false;
|
|
645
649
|
const actions = [...new Set((result.denied_actions ?? []).map(action => typeof action?.action === 'string' ? action.action : 'unknown'))];
|
|
646
|
-
const message = `AGY permission denied${actions.length ? ` for ${actions.join(', ')}` : ''}; ${active.
|
|
647
|
-
?
|
|
648
|
-
:
|
|
649
|
-
? 'a PreToolUse hook rejected a tool before execution; retain the denial; terminal SUCCESS is not evidence that the requested work ran'
|
|
650
|
-
: active.vendorRejected?.size
|
|
651
|
-
? 'the native AGY permission engine rejected a tool after Kiki approved this exact call; retain the denial and restore the vendor approval contract before retrying'
|
|
652
|
-
: 'the native AGY permission policy did not approve the action'}${unresolvedMessage ? `; ${unresolvedMessage}` : ''}`;
|
|
650
|
+
const message = `AGY permission denied${actions.length ? ` for ${actions.join(', ')}` : ''}; ${active.preToolDenied?.size
|
|
651
|
+
? 'a PreToolUse hook rejected a tool before execution; retain the denial; terminal SUCCESS is not evidence that the requested work ran'
|
|
652
|
+
: 'the native AGY permission policy did not approve the action'}${unresolvedMessage ? `; ${unresolvedMessage}` : ''}`;
|
|
653
653
|
await this.settlePendingTools(session, active, 'failed', message);
|
|
654
654
|
process.stderr.write(`${message}\n`);
|
|
655
655
|
const error = new Error(message);
|
|
656
656
|
error.code = 'AGY_PERMISSION_DENIED';
|
|
657
|
-
error.details = { deniedToolCallIds: [...
|
|
657
|
+
error.details = { deniedToolCallIds: [...(active.preToolDenied ?? [])], unresolvedTools: unresolved };
|
|
658
658
|
active.reject(error);
|
|
659
659
|
} else if (result.status === 'CANCELED' || result.status === 'INTERRUPTED') {
|
|
660
660
|
await this.settlePendingTools(session, active, 'failed', unresolvedMessage ?? `AGY turn ${result.status.toLowerCase()}`);
|
|
@@ -682,12 +682,18 @@ export class AgyBridge {
|
|
|
682
682
|
if (session.broken) throw new Error(session.failure ?? 'AGY process ended; create a fresh session (no implicit resume/history handoff)');
|
|
683
683
|
if (session.active) throw new Error('AGY session already has an active turn');
|
|
684
684
|
const content = promptText(params.prompt);
|
|
685
|
-
const promise = new Promise((resolveTurn,
|
|
685
|
+
const promise = new Promise((resolveTurn, rejectTurn) => {
|
|
686
|
+
const active = { client, text: '', steering: [],
|
|
687
|
+
resolve: value => { this.releaseSteering(session, active); void this.closeSteeringHook(session).catch(() => {}).then(() => resolveTurn(value)); },
|
|
688
|
+
reject: error => { this.releaseSteering(session, active); void this.closeSteeringHook(session).catch(() => {}).then(() => rejectTurn(error)); } };
|
|
689
|
+
session.active = active;
|
|
690
|
+
});
|
|
686
691
|
promise.catch(() => {});
|
|
687
692
|
try {
|
|
688
|
-
if (Object.hasOwn(params._meta ?? {}, 'kiki.permission')) this.permissionSnapshot(session, params._meta['kiki.permission']);
|
|
689
693
|
session.preparing = (async () => {
|
|
694
|
+
await this.recoverDeadOwnedResources(session);
|
|
690
695
|
await this.syncPermissionHook(session);
|
|
696
|
+
await this.registerSteeringHook(session);
|
|
691
697
|
if (!session.broken && !session.child) await this.start(session);
|
|
692
698
|
})();
|
|
693
699
|
try { await session.preparing; } finally { session.preparing = undefined; }
|
|
@@ -704,7 +710,8 @@ export class AgyBridge {
|
|
|
704
710
|
frameSha256: createHash('sha256').update(frame).digest('hex'), delivery: 'unchanged_user_text' });
|
|
705
711
|
return await promise;
|
|
706
712
|
} catch (error) {
|
|
707
|
-
if (session.active) { session.active = undefined; }
|
|
713
|
+
if (session.active) { this.releaseSteering(session, session.active); session.active = undefined; }
|
|
714
|
+
await this.closeSteeringHook(session).catch(() => {});
|
|
708
715
|
throw error;
|
|
709
716
|
}
|
|
710
717
|
}
|
|
@@ -714,13 +721,12 @@ export class AgyBridge {
|
|
|
714
721
|
const active = session.active;
|
|
715
722
|
session.active = undefined;
|
|
716
723
|
session.broken = true;
|
|
717
|
-
for (const controller of session.permissionRequests) controller.abort(new Error('AGY turn cancelled'));
|
|
718
724
|
if (active) await this.settlePendingTools(session, active, 'failed', 'AGY turn cancelled');
|
|
719
725
|
await session.preparing?.catch(() => {});
|
|
720
726
|
await session.permissionChannel?.close();
|
|
721
727
|
await this.stopProcess(session.child);
|
|
722
728
|
await session.cleanup;
|
|
723
|
-
await session.
|
|
729
|
+
await this.closeSteeringHook(session).catch(() => {});
|
|
724
730
|
await session.mcpPlugin?.close();
|
|
725
731
|
await this.audit(session, 'cancel', { pid: session.child?.pid, processEnded: true, resumeSupported: false });
|
|
726
732
|
active?.resolve({ stopReason: 'cancelled' });
|
|
@@ -729,7 +735,6 @@ export class AgyBridge {
|
|
|
729
735
|
close() {
|
|
730
736
|
this.closePromise ??= Promise.all([...this.sessions.values()].map(async session => {
|
|
731
737
|
const active = session.active; session.active = undefined; session.broken = true;
|
|
732
|
-
for (const controller of session.permissionRequests) controller.abort(new Error('ACP connection closed'));
|
|
733
738
|
try {
|
|
734
739
|
if (active) await this.settlePendingTools(session, active, 'failed', 'ACP connection closed');
|
|
735
740
|
} finally {
|
|
@@ -742,7 +747,7 @@ export class AgyBridge {
|
|
|
742
747
|
try { await session.exited; } finally { clearTimeout(timer); }
|
|
743
748
|
}
|
|
744
749
|
await session.cleanup;
|
|
745
|
-
await session.
|
|
750
|
+
await this.closeSteeringHook(session).catch(() => {});
|
|
746
751
|
await session.mcpPlugin?.close();
|
|
747
752
|
await session.releaseResume?.();
|
|
748
753
|
await this.audit(session, 'close', { pid: session.child?.pid, processEnded: true });
|
|
@@ -836,12 +841,13 @@ export async function runBridge({ sdkPath, cliPath, cliPrefix = [], auditDir, mo
|
|
|
836
841
|
{ adapterCode: error?.code, details: error?.details });
|
|
837
842
|
}
|
|
838
843
|
};
|
|
839
|
-
const connection = acp.agent({ name: 'agy-cli-acp', version: '0.
|
|
844
|
+
const connection = acp.agent({ name: 'agy-cli-acp', version: '0.2.0' })
|
|
840
845
|
.onRequest('initialize', () => bridge.initialize(acp.PROTOCOL_VERSION))
|
|
841
846
|
.onRequest('session/new', sessionRequest(ctx => bridge.newSession(ctx.params)))
|
|
842
847
|
.onRequest('session/load', sessionRequest(ctx => bridge.loadSession(ctx.params)))
|
|
843
848
|
.onRequest('session/set_config_option', ctx => bridge.setConfig(ctx.params))
|
|
844
849
|
.onRequest('session/prompt', sessionRequest(ctx => bridge.prompt(ctx.params, ctx.client)))
|
|
850
|
+
.onRequest('_session/steering', params => params, sessionRequest(ctx => bridge.steer(ctx.params)))
|
|
845
851
|
.onNotification('session/cancel', ctx => bridge.cancel(ctx.params))
|
|
846
852
|
.connect(acp.ndJsonStream(Writable.toWeb(process.stdout), Readable.toWeb(process.stdin)));
|
|
847
853
|
let shuttingDown = false;
|
|
@@ -857,7 +863,7 @@ export async function runBridge({ sdkPath, cliPath, cliPrefix = [], auditDir, mo
|
|
|
857
863
|
}
|
|
858
864
|
|
|
859
865
|
if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.meta.url) {
|
|
860
|
-
if (process.argv.includes('--version')) console.log('agy-cli-acp 0.
|
|
866
|
+
if (process.argv.includes('--version')) console.log('agy-cli-acp 0.2.0');
|
|
861
867
|
else {
|
|
862
868
|
const args = process.argv.slice(2);
|
|
863
869
|
if (args.length === 2 && args[0] === '--mcp-stdio') {
|