modkh 0.0.0-stage → 0.1.0

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.
Files changed (256) hide show
  1. package/README.md +24 -2
  2. package/dist/agent/bundled-skills.d.ts +13 -0
  3. package/dist/agent/bundled-skills.js +95 -0
  4. package/dist/agent/images.d.ts +10 -0
  5. package/dist/agent/images.js +33 -0
  6. package/dist/agent/loop.d.ts +56 -0
  7. package/dist/agent/loop.js +155 -0
  8. package/dist/agent/skills.d.ts +20 -0
  9. package/dist/agent/skills.js +169 -0
  10. package/dist/agent/types.d.ts +132 -0
  11. package/dist/agent/types.js +12 -0
  12. package/dist/cli/agents.d.ts +8 -0
  13. package/dist/cli/agents.js +12 -0
  14. package/dist/cli/approval.d.ts +27 -0
  15. package/dist/cli/approval.js +62 -0
  16. package/dist/cli/catalog.d.ts +39 -0
  17. package/dist/cli/catalog.js +76 -0
  18. package/dist/cli/chat.d.ts +18 -0
  19. package/dist/cli/chat.js +733 -0
  20. package/dist/cli/clipboard.d.ts +9 -0
  21. package/dist/cli/clipboard.js +54 -0
  22. package/dist/cli/color.d.ts +42 -0
  23. package/dist/cli/color.js +176 -0
  24. package/dist/cli/config.d.ts +41 -0
  25. package/dist/cli/config.js +188 -0
  26. package/dist/cli/editor.d.ts +16 -0
  27. package/dist/cli/editor.js +77 -0
  28. package/dist/cli/keys.d.ts +18 -0
  29. package/dist/cli/keys.js +82 -0
  30. package/dist/cli/language.d.ts +1 -0
  31. package/dist/cli/language.js +105 -0
  32. package/dist/cli/limits.d.ts +13 -0
  33. package/dist/cli/limits.js +19 -0
  34. package/dist/cli/lines.d.ts +18 -0
  35. package/dist/cli/lines.js +80 -0
  36. package/dist/cli/models.d.ts +4 -0
  37. package/dist/cli/models.js +69 -0
  38. package/dist/cli/permissions.d.ts +25 -0
  39. package/dist/cli/permissions.js +30 -0
  40. package/dist/cli/plugins.d.ts +1 -0
  41. package/dist/cli/plugins.js +53 -0
  42. package/dist/cli/providers.d.ts +46 -0
  43. package/dist/cli/providers.js +76 -0
  44. package/dist/cli/terminal.d.ts +143 -0
  45. package/dist/cli/terminal.js +742 -0
  46. package/dist/cli/usage.d.ts +29 -0
  47. package/dist/cli/usage.js +75 -0
  48. package/dist/index.d.ts +11 -0
  49. package/dist/index.js +164 -0
  50. package/dist/language/catalog.d.ts +44 -0
  51. package/dist/language/catalog.js +100 -0
  52. package/dist/language/commonlisp-bundled.d.ts +11 -0
  53. package/dist/language/commonlisp-bundled.js +22 -0
  54. package/dist/language/commonlisp-dependencies.d.ts +16 -0
  55. package/dist/language/commonlisp-dependencies.js +68 -0
  56. package/dist/language/commonlisp-install.d.ts +14 -0
  57. package/dist/language/commonlisp-install.js +213 -0
  58. package/dist/language/commonlisp-reader.d.ts +17 -0
  59. package/dist/language/commonlisp-reader.js +47 -0
  60. package/dist/language/commonlisp-systems.d.ts +3 -0
  61. package/dist/language/commonlisp-systems.js +32 -0
  62. package/dist/language/commonlisp-tls.d.ts +10 -0
  63. package/dist/language/commonlisp-tls.js +51 -0
  64. package/dist/language/detect.d.ts +29 -0
  65. package/dist/language/detect.js +103 -0
  66. package/dist/language/grammars/LICENSE +24 -0
  67. package/dist/language/grammars/manifest.json +76 -0
  68. package/dist/language/grammars/tree-sitter-c.wasm +0 -0
  69. package/dist/language/grammars/tree-sitter-cpp.wasm +0 -0
  70. package/dist/language/grammars/tree-sitter-css.wasm +0 -0
  71. package/dist/language/grammars/tree-sitter-html.wasm +0 -0
  72. package/dist/language/grammars/tree-sitter-javascript.wasm +0 -0
  73. package/dist/language/grammars/tree-sitter-php.wasm +0 -0
  74. package/dist/language/grammars/tree-sitter-python.wasm +0 -0
  75. package/dist/language/grammars/tree-sitter-ruby.wasm +0 -0
  76. package/dist/language/grammars/tree-sitter-rust.wasm +0 -0
  77. package/dist/language/grammars/tree-sitter-swift.wasm +0 -0
  78. package/dist/language/grammars/tree-sitter-tsx.wasm +0 -0
  79. package/dist/language/grammars/tree-sitter-typescript.wasm +0 -0
  80. package/dist/language/install.d.ts +50 -0
  81. package/dist/language/install.js +293 -0
  82. package/dist/language/lsp/client.d.ts +97 -0
  83. package/dist/language/lsp/client.js +337 -0
  84. package/dist/language/lsp/pool.d.ts +67 -0
  85. package/dist/language/lsp/pool.js +122 -0
  86. package/dist/language/lsp/service.d.ts +46 -0
  87. package/dist/language/lsp/service.js +138 -0
  88. package/dist/language/native.d.ts +8 -0
  89. package/dist/language/native.js +100 -0
  90. package/dist/language/platform.d.ts +14 -0
  91. package/dist/language/platform.js +20 -0
  92. package/dist/language/positions.d.ts +20 -0
  93. package/dist/language/positions.js +46 -0
  94. package/dist/language/syntax/assets.d.ts +9 -0
  95. package/dist/language/syntax/assets.js +73 -0
  96. package/dist/language/syntax/parser.d.ts +24 -0
  97. package/dist/language/syntax/parser.js +144 -0
  98. package/dist/language/typescript-capability.d.ts +6 -0
  99. package/dist/language/typescript-capability.js +42 -0
  100. package/dist/lisp/config.d.ts +16 -0
  101. package/dist/lisp/config.js +159 -0
  102. package/dist/lisp/routing.d.ts +5 -0
  103. package/dist/lisp/routing.js +24 -0
  104. package/dist/lisp/runtime.d.ts +21 -0
  105. package/dist/lisp/runtime.js +83 -0
  106. package/dist/memory/kiokuko.d.ts +32 -0
  107. package/dist/memory/kiokuko.js +102 -0
  108. package/dist/memory/mcp.d.ts +38 -0
  109. package/dist/memory/mcp.js +211 -0
  110. package/dist/model/ai-sdk.d.ts +27 -0
  111. package/dist/model/ai-sdk.js +180 -0
  112. package/dist/model/chatgpt/login.d.ts +42 -0
  113. package/dist/model/chatgpt/login.js +180 -0
  114. package/dist/model/chatgpt/responses.d.ts +41 -0
  115. package/dist/model/chatgpt/responses.js +202 -0
  116. package/dist/model/chatgpt/tokens.d.ts +11 -0
  117. package/dist/model/chatgpt/tokens.js +50 -0
  118. package/dist/model/connection.d.ts +6 -0
  119. package/dist/model/connection.js +65 -0
  120. package/dist/model/context.d.ts +9 -0
  121. package/dist/model/context.js +69 -0
  122. package/dist/model/factory.d.ts +25 -0
  123. package/dist/model/factory.js +88 -0
  124. package/dist/model/fixed.d.ts +17 -0
  125. package/dist/model/fixed.js +41 -0
  126. package/dist/model/reasoning.d.ts +16 -0
  127. package/dist/model/reasoning.js +62 -0
  128. package/dist/plugins/api.d.ts +60 -0
  129. package/dist/plugins/api.js +1 -0
  130. package/dist/plugins/manager.d.ts +34 -0
  131. package/dist/plugins/manager.js +261 -0
  132. package/dist/plugins/package.d.ts +13 -0
  133. package/dist/plugins/package.js +99 -0
  134. package/dist/plugins/registry.d.ts +8 -0
  135. package/dist/plugins/registry.js +14 -0
  136. package/dist/session/store.d.ts +82 -0
  137. package/dist/session/store.js +285 -0
  138. package/dist/session/workspace.d.ts +19 -0
  139. package/dist/session/workspace.js +73 -0
  140. package/dist/subagents/processes.d.ts +18 -0
  141. package/dist/subagents/processes.js +73 -0
  142. package/dist/subagents/request.d.ts +4 -0
  143. package/dist/subagents/request.js +21 -0
  144. package/dist/subagents/service.d.ts +39 -0
  145. package/dist/subagents/service.js +352 -0
  146. package/dist/subagents/settings.d.ts +10 -0
  147. package/dist/subagents/settings.js +32 -0
  148. package/dist/subagents/types.d.ts +43 -0
  149. package/dist/subagents/types.js +1 -0
  150. package/dist/subagents/verification.d.ts +31 -0
  151. package/dist/subagents/verification.js +178 -0
  152. package/dist/tools/diff.d.ts +6 -0
  153. package/dist/tools/diff.js +82 -0
  154. package/dist/tools/edit.d.ts +3 -0
  155. package/dist/tools/edit.js +152 -0
  156. package/dist/tools/files.d.ts +6 -0
  157. package/dist/tools/files.js +96 -0
  158. package/dist/tools/formal.d.ts +8 -0
  159. package/dist/tools/formal.js +77 -0
  160. package/dist/tools/guard.d.ts +7 -0
  161. package/dist/tools/guard.js +48 -0
  162. package/dist/tools/job-tools.d.ts +19 -0
  163. package/dist/tools/job-tools.js +148 -0
  164. package/dist/tools/jobs.d.ts +77 -0
  165. package/dist/tools/jobs.js +181 -0
  166. package/dist/tools/language.d.ts +6 -0
  167. package/dist/tools/language.js +174 -0
  168. package/dist/tools/registry.d.ts +28 -0
  169. package/dist/tools/registry.js +105 -0
  170. package/dist/tools/run.d.ts +13 -0
  171. package/dist/tools/run.js +159 -0
  172. package/dist/tools/search.d.ts +2 -0
  173. package/dist/tools/search.js +156 -0
  174. package/dist/tools/shell-process.d.ts +115 -0
  175. package/dist/tools/shell-process.js +286 -0
  176. package/dist/tools/skills.d.ts +2 -0
  177. package/dist/tools/skills.js +46 -0
  178. package/dist/tools/web.d.ts +24 -0
  179. package/dist/tools/web.js +386 -0
  180. package/docs/ci-repair-20261116.md +30 -0
  181. package/docs/commonlisp-provider-migration.md +22 -0
  182. package/docs/commonlisp-qlot-recovery.md +28 -0
  183. package/docs/commonlisp-tls-recovery.md +28 -0
  184. package/docs/context-efficiency.md +100 -0
  185. package/docs/input.md +66 -0
  186. package/docs/languages.md +117 -0
  187. package/docs/models.md +85 -0
  188. package/docs/modkh-evidence.json +641 -0
  189. package/docs/modkh-failure-comparison.json +675 -0
  190. package/docs/modkh-namespace.md +39 -0
  191. package/docs/modkh-qlot-evidence.json +37 -0
  192. package/docs/modkh-verification.md +173 -0
  193. package/docs/modkh.md +124 -0
  194. package/docs/presets.md +19 -0
  195. package/docs/setup.md +112 -0
  196. package/docs/subagents.md +134 -0
  197. package/docs/web.md +57 -0
  198. package/experiments/presets/common-lisp.lisp +38 -0
  199. package/experiments/presets/css.lisp +38 -0
  200. package/experiments/presets/formal.lisp +7 -0
  201. package/experiments/presets/html.lisp +38 -0
  202. package/experiments/presets/js.lisp +38 -0
  203. package/experiments/presets/php.lisp +38 -0
  204. package/experiments/presets/svelte.lisp +38 -0
  205. package/experiments/presets/tailwindcss.lisp +24 -0
  206. package/experiments/presets/ts.lisp +38 -0
  207. package/package.json +49 -4
  208. package/plugins/modkh-explorer/index.mjs +3 -0
  209. package/plugins/modkh-explorer/plugin.json +1 -0
  210. package/plugins/modkh-worker/index.mjs +3 -0
  211. package/plugins/modkh-worker/plugin.json +1 -0
  212. package/skills/kiokuko-dsh/LICENSE +21 -0
  213. package/skills/kiokuko-dsh/coding-ideal-routine-skill/SKILL.md +106 -0
  214. package/skills/kiokuko-dsh/japanese-translation-for-oss-models/SKILL.md +65 -0
  215. package/skills/kiokuko-dsh/kiokuko-architecture/SKILL.md +20 -0
  216. package/skills/kiokuko-dsh/kiokuko-architecture/references/cases.md +11 -0
  217. package/skills/kiokuko-dsh/kiokuko-benchmark/SKILL.md +20 -0
  218. package/skills/kiokuko-dsh/kiokuko-benchmark/references/cases.md +11 -0
  219. package/skills/kiokuko-dsh/kiokuko-investigate/SKILL.md +20 -0
  220. package/skills/kiokuko-dsh/kiokuko-investigate/references/cases.md +11 -0
  221. package/skills/kiokuko-dsh/kiokuko-lisp/SKILL.md +390 -0
  222. package/skills/kiokuko-dsh/kiokuko-review/SKILL.md +20 -0
  223. package/skills/kiokuko-dsh/kiokuko-review/references/cases.md +11 -0
  224. package/skills/kiokuko-dsh/kiokuko-simple-work/SKILL.md +70 -0
  225. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/SKILL.md +79 -0
  226. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/boundaries-and-ownership.md +52 -0
  227. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/domain-and-types.md +48 -0
  228. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/effects-and-data.md +43 -0
  229. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/kiokuko-patterns.md +314 -0
  230. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/problem-shaping-and-language.md +90 -0
  231. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/protocols-and-idempotency.md +42 -0
  232. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/review-checklist.md +92 -0
  233. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/verification.md +45 -0
  234. package/skills/kiokuko-dsh/kiokuko-skill-authoring/SKILL.md +20 -0
  235. package/skills/kiokuko-dsh/kiokuko-skill-authoring/references/cases.md +11 -0
  236. package/skills/kiokuko-dsh/kiokuko-soul/SKILL.md +25 -0
  237. package/skills/kiokuko-dsh/kiokuko-technical-writing/SKILL.md +20 -0
  238. package/skills/kiokuko-dsh/kiokuko-technical-writing/references/cases.md +11 -0
  239. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/SKILL.md +64 -0
  240. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/accessibility-and-navigation.md +31 -0
  241. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/async-recovery.md +49 -0
  242. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/forms-and-controls.md +35 -0
  243. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/interaction-feedback.md +34 -0
  244. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/responsive-and-platform.md +38 -0
  245. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/safety-and-review.md +43 -0
  246. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/ui-checklist.md +75 -0
  247. package/skills/kiokuko-dsh/kiokuko-verification/SKILL.md +20 -0
  248. package/skills/kiokuko-dsh/kiokuko-verification/references/cases.md +11 -0
  249. package/skills/kiokuko-dsh/manifest.json +168 -0
  250. package/skills/kiokuko-dsh/memory-reasoning/SKILL.md +44 -0
  251. package/skills/kiokuko-dsh/one-shot-software-completion/SKILL.md +113 -0
  252. package/skills/kiokuko-dsh/one-shot-software-completion/references/boundaries-and-lifecycle.md +70 -0
  253. package/skills/kiokuko-dsh/one-shot-software-completion/references/discovery-and-scope.md +71 -0
  254. package/skills/kiokuko-dsh/one-shot-software-completion/references/failure-recovery.md +43 -0
  255. package/skills/kiokuko-dsh/one-shot-software-completion/references/verification-and-completion.md +73 -0
  256. package/skills/kiokuko-dsh/veteran-programmer-skill/SKILL.md +66 -0
@@ -0,0 +1,132 @@
1
+ import type { ImageAttachment } from './images.ts';
2
+ /** モデルが出した1件のツール要求。 */
3
+ export interface ToolCall {
4
+ id: string;
5
+ name: string;
6
+ args: Record<string, unknown>;
7
+ }
8
+ /** unknown は副作用が不明、not-executed は未実行を確認済み。okはツール終了であり目標達成ではない。 */
9
+ export interface ToolResult {
10
+ callId: string;
11
+ name: string;
12
+ status: 'ok' | 'error' | 'unknown' | 'not-executed';
13
+ output: string;
14
+ }
15
+ /** モデルへ渡すツール定義(JSON Schema の parameters を含む)。 */
16
+ export interface ToolSpec {
17
+ name: string;
18
+ description: string;
19
+ parameters: Record<string, unknown>;
20
+ }
21
+ /** 承認要求。edit は diff、command は実行内容と作業場所を detail に載せる。 */
22
+ export interface ApprovalRequest {
23
+ kind: 'edit' | 'command';
24
+ title: string;
25
+ detail: string;
26
+ /**
27
+ * True when the caller proved the target is outside the working root. Omitted means "not proven",
28
+ * which an approval policy must treat as outside, so a policy can never skip a wider effect.
29
+ */
30
+ outsideWorkspace?: boolean;
31
+ /** Cancels only this approval request (e.g. a timed-out child). */
32
+ signal?: AbortSignal;
33
+ }
34
+ export interface ApprovalGate {
35
+ approve(req: ApprovalRequest): Promise<boolean>;
36
+ }
37
+ export interface ToolContext {
38
+ /** 作業ルート(絶対パス)。すべてのファイル操作とコマンド cwd をここに制限する。 */
39
+ root: string;
40
+ approval: ApprovalGate;
41
+ /** Ctrl+C などで中断されたときに打ち切る。 */
42
+ signal?: AbortSignal;
43
+ /** Assigned by the registry, never a model-controlled argument. */
44
+ callId?: string;
45
+ /**
46
+ * Post-effect analysis (structure, diagnostics). It runs after a successful read/write and its
47
+ * failure must never change the tool's own result or cause a second edit.
48
+ */
49
+ analyze?(file: string, kind: 'read' | 'write'): Promise<string | null>;
50
+ /**
51
+ * Background jobs owned by this session. Absent means foreground execution only; a tool that
52
+ * cannot reach a registry must say so instead of silently running a long command inline.
53
+ */
54
+ jobs?: import('../tools/jobs.ts').JobRegistry;
55
+ }
56
+ /** ツール内部の期待される失敗。モデルへ status:'error' として返す。 */
57
+ export declare class ToolError extends Error {
58
+ code: string;
59
+ constructor(code: string, message: string);
60
+ }
61
+ /** ツール本体。失敗は ToolError を throw し、実装外の事故は上位で error 扱いにする。 */
62
+ export interface Tool {
63
+ /** Trusted implementation metadata, never a model argument. Defaults to effectful. */
64
+ readOnly?: boolean;
65
+ /** Pure trusted identity for uncertain-operation matching; never normalize command text.
66
+ * Call-ID conflicts still compare original arguments, not this identity. */
67
+ operationIdentity?(args: Record<string, unknown>, ctx: ToolContext): unknown;
68
+ name: string;
69
+ description: string;
70
+ parameters: Record<string, unknown>;
71
+ execute(args: Record<string, unknown>, ctx: ToolContext): Promise<string | Pick<ToolResult, 'status' | 'output'>>;
72
+ }
73
+ /** モデルストリームのイベント。 */
74
+ export type ModelEvent = {
75
+ type: 'activity';
76
+ stage: 'reasoning' | 'tool-input';
77
+ } | {
78
+ type: 'usage';
79
+ input?: number;
80
+ output?: number;
81
+ cacheRead?: number;
82
+ cacheWrite?: number;
83
+ } | {
84
+ type: 'text-delta';
85
+ text: string;
86
+ }
87
+ /** Provider-reported reasoning. Shown to the human, never merged into assistant content. */
88
+ | {
89
+ type: 'reasoning-delta';
90
+ text: string;
91
+ } | {
92
+ type: 'tool-call';
93
+ call: ToolCall;
94
+ } | {
95
+ type: 'finish';
96
+ stopReason: 'stop' | 'tool-calls' | 'aborted' | 'error';
97
+ errorMessage?: string;
98
+ };
99
+ /** 会話メッセージ。tool メッセージは1つのアシスタント応答に対する結果群を保持する。 */
100
+ export type AgentMessage = {
101
+ role: 'user';
102
+ content: string;
103
+ images?: ImageAttachment[];
104
+ } | {
105
+ role: 'assistant';
106
+ content: string;
107
+ toolCalls?: ToolCall[];
108
+ origin?: 'manual';
109
+ } | {
110
+ role: 'tool';
111
+ results: ToolResult[];
112
+ };
113
+ /**
114
+ * 推論レベル。off は「明示的に止めたい」意志であり、その対応はプロバイダーごとに置く。
115
+ */
116
+ export type ReasoningLevel = 'off' | 'minimal' | 'low' | 'medium' | 'high';
117
+ export interface ModelRequest {
118
+ messages: AgentMessage[];
119
+ tools: ToolSpec[];
120
+ system?: string;
121
+ /** この要求での推論レベル。省略はプロバイダーの初期値。 */
122
+ reasoning?: ReasoningLevel;
123
+ }
124
+ /**
125
+ * 接続方式の違いを Agent ループから隠す。実装は各アダプターに置く。
126
+ * 中断は signal で要求し、アダプターは 'aborted' の finish で静かに終わる。
127
+ */
128
+ export interface Model {
129
+ readonly id: string;
130
+ stream(req: ModelRequest, signal: AbortSignal): AsyncIterable<ModelEvent>;
131
+ }
132
+ export declare function isToolError(e: unknown): e is ToolError;
@@ -0,0 +1,12 @@
1
+ /** ツール内部の期待される失敗。モデルへ status:'error' として返す。 */
2
+ export class ToolError extends Error {
3
+ code;
4
+ constructor(code, message) {
5
+ super(message);
6
+ this.name = 'ToolError';
7
+ this.code = code;
8
+ }
9
+ }
10
+ export function isToolError(e) {
11
+ return e instanceof ToolError;
12
+ }
@@ -0,0 +1,8 @@
1
+ import type { ApprovalGate } from '../agent/types.ts';
2
+ import type { TurnResult } from '../agent/loop.ts';
3
+ import type { Session } from '../session/store.ts';
4
+ import type { ToolRegistry } from '../tools/registry.ts';
5
+ import type { DelegationRequest } from '../subagents/types.ts';
6
+ import type { ChatTerminal } from './terminal.ts';
7
+ /** Manual invocation uses exactly the same registered tool and durable parent ledger. */
8
+ export declare function runDirectAgent(request: DelegationRequest, session: Session, registry: ToolRegistry, root: string, signal: AbortSignal, approval: ApprovalGate, ui: ChatTerminal): Promise<TurnResult>;
@@ -0,0 +1,12 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ /** Manual invocation uses exactly the same registered tool and durable parent ledger. */
3
+ export async function runDirectAgent(request, session, registry, root, signal, approval, ui) {
4
+ const call = { id: randomUUID(), name: 'run_subagent', args: { ...request } };
5
+ session.append({ role: 'assistant', origin: 'manual', content: '', toolCalls: [call] });
6
+ const result = await registry.executeOne(call, { root, signal, approval });
7
+ session.append({ role: 'tool', results: [result] });
8
+ ui.write(`\n子の実行結果: ${result.status}\n${result.output}\n`);
9
+ return result.status === 'ok' ? { outcome: 'complete' }
10
+ : signal.aborted || result.status === 'unknown' ? { outcome: 'interrupted' }
11
+ : { outcome: 'error', errorMessage: result.output };
12
+ }
@@ -0,0 +1,27 @@
1
+ import type { ApprovalGate, ApprovalRequest } from '../agent/types.ts';
2
+ import { type PermissionPolicy } from './permissions.ts';
3
+ export interface ApprovalIo {
4
+ /** 同じ入力キューを共有し、中断時はこの質問の待機だけを解除する。 */
5
+ ask(prompt: string, signal?: AbortSignal): Promise<string>;
6
+ write(text: string): void;
7
+ }
8
+ /**
9
+ * A caller can prove a request stays inside the workspace, which lets `workspace` skip the prompt.
10
+ * `outsideWorkspace` defaults to true so an unproven request still asks.
11
+ */
12
+ export interface ApprovalScope extends ApprovalRequest {
13
+ outsideWorkspace?: boolean;
14
+ }
15
+ /** 端末承認。Stop は承認待ちと、その質問が所有する入力待ちを取り消す。 */
16
+ export declare class TerminalApprovalGate implements ApprovalGate {
17
+ private readonly io;
18
+ private policy;
19
+ private pending;
20
+ constructor(io: ApprovalIo, policy?: PermissionPolicy);
21
+ /** Changing the policy affects later requests only; an open prompt is not cancelled. */
22
+ setPolicy(policy: PermissionPolicy): void;
23
+ currentPolicy(): PermissionPolicy;
24
+ interrupt(): void;
25
+ approve(request: ApprovalRequest): Promise<boolean>;
26
+ private askOrInterrupt;
27
+ }
@@ -0,0 +1,62 @@
1
+ import { DEFAULT_POLICY, describePolicy, shouldAsk } from "./permissions.js";
2
+ /** 端末承認。Stop は承認待ちと、その質問が所有する入力待ちを取り消す。 */
3
+ export class TerminalApprovalGate {
4
+ io;
5
+ policy;
6
+ pending = new Set();
7
+ constructor(io, policy = DEFAULT_POLICY) {
8
+ this.io = io;
9
+ this.policy = policy;
10
+ }
11
+ /** Changing the policy affects later requests only; an open prompt is not cancelled. */
12
+ setPolicy(policy) {
13
+ this.policy = policy;
14
+ this.io.write(`(${describePolicy(policy)})\n`);
15
+ }
16
+ currentPolicy() {
17
+ return this.policy;
18
+ }
19
+ interrupt() {
20
+ for (const controller of this.pending)
21
+ controller.abort();
22
+ }
23
+ async approve(request) {
24
+ const req = request;
25
+ if (!shouldAsk({ policy: this.policy, kind: req.kind, outsideWorkspace: req.outsideWorkspace !== false })) {
26
+ // Say what ran without asking, so an automatic effect is still visible in the transcript.
27
+ this.io.write(`(自動承認: ${req.kind} — ${req.title})\n`);
28
+ return true;
29
+ }
30
+ this.io.write(`\n--- 承認要求(${req.kind}) ---\n${req.title}\n${req.detail}\n`);
31
+ const answer = await this.askOrInterrupt('実行しますか? [y/N] ', req.signal);
32
+ if (answer === null) {
33
+ this.io.write('(中断により拒否)\n');
34
+ return false;
35
+ }
36
+ const ok = answer.trim().toLowerCase() === 'y';
37
+ this.io.write(ok ? '(承認)\n' : '(拒否)\n');
38
+ return ok;
39
+ }
40
+ async askOrInterrupt(prompt, signal) {
41
+ if (signal?.aborted)
42
+ return null;
43
+ const controller = new AbortController();
44
+ const cancel = () => controller.abort();
45
+ signal?.addEventListener('abort', cancel, { once: true });
46
+ this.pending.add(controller);
47
+ let onAbort = () => { };
48
+ try {
49
+ const interrupted = new Promise((resolve) => {
50
+ onAbort = () => resolve(null);
51
+ controller.signal.addEventListener('abort', onAbort, { once: true });
52
+ });
53
+ const answer = await Promise.race([this.io.ask(prompt, controller.signal), interrupted]);
54
+ return controller.signal.aborted ? null : answer;
55
+ }
56
+ finally {
57
+ signal?.removeEventListener('abort', cancel);
58
+ controller.signal.removeEventListener('abort', onAbort);
59
+ this.pending.delete(controller);
60
+ }
61
+ }
62
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Model catalogs shown by the picker and `/models`.
3
+ *
4
+ * The Ollama Cloud list is a snapshot of `GET https://ollama.com/v1/models` taken while building
5
+ * this release, so the picker works offline and without a key. It is a convenience list, not an
6
+ * entitlement: a model may require a plan the account does not have, and the service may add or
7
+ * retire models at any time. `/connect <provider>/<model>` always accepts an ID from outside this
8
+ * list, and `modkh models refresh` can rewrite the snapshot from the live endpoint.
9
+ */
10
+ export interface CatalogEntry {
11
+ /** Full `<provider>/<model>` reference used everywhere else. */
12
+ readonly ref: string;
13
+ /** Short description for the picker; never a capability guarantee. */
14
+ readonly note?: string;
15
+ }
16
+ /** Snapshot of the Ollama Cloud catalogue with a short note for well-known families. */
17
+ export declare const OLLAMA_CLOUD_CATALOG: readonly CatalogEntry[];
18
+ /** Sentinel value for the pinned search row; never a real model reference. */
19
+ export declare const SEARCH_ROW_VALUE = "\0search";
20
+ /** The endpoint and the date of the snapshot above; shown by `modkh models status`. */
21
+ export declare const OLLAMA_CLOUD_SOURCE: {
22
+ readonly url: "https://ollama.com/v1/models";
23
+ readonly capturedAt: "2026-11-14";
24
+ };
25
+ /**
26
+ * Recommended defaults per provider, marked in the picker rather than reordered: existing
27
+ * references and their positions are relied on by other callers, so the list order is stable.
28
+ */
29
+ export declare const PROVIDER_DEFAULTS: Readonly<Record<string, readonly string[]>>;
30
+ /** Extra suggestions for providers without a published catalogue. */
31
+ export declare const OTHER_SUGGESTIONS: readonly string[];
32
+ /** Every known reference, catalogued providers first. */
33
+ export declare function allSuggestions(): string[];
34
+ /** The catalogue in display order; recommendations are marked, never moved. */
35
+ export declare function suggestionsFor(provider: string, current?: string | null): string[];
36
+ /** Marks a recommended entry for the picker without changing its position. */
37
+ export declare function isRecommended(ref: string): boolean;
38
+ /** Notes are advisory labels for the picker, keyed by full reference. */
39
+ export declare function noteFor(ref: string): string | undefined;
@@ -0,0 +1,76 @@
1
+ /** Snapshot of the Ollama Cloud catalogue with a short note for well-known families. */
2
+ export const OLLAMA_CLOUD_CATALOG = [
3
+ { ref: 'ollama-cloud/gemma4:31b' },
4
+ { ref: 'ollama-cloud/gpt-oss:120b', note: '大規模' },
5
+ { ref: 'ollama-cloud/gpt-oss:20b', note: '軽量' },
6
+ { ref: 'ollama-cloud/deepseek-v4.1-flash', note: '高速・低コスト' },
7
+ { ref: 'ollama-cloud/deepseek-v4.1-flash:1017', note: '高速・版固定' },
8
+ { ref: 'ollama-cloud/deepseek-v4-pro:0813', note: '高精度' },
9
+ { ref: 'ollama-cloud/glm-5.3', note: '汎用' },
10
+ { ref: 'ollama-cloud/glm-5.3-flash', note: '高速' },
11
+ { ref: 'ollama-cloud/glm-5.2' },
12
+ { ref: 'ollama-cloud/kimi-k3.1-pro', note: '長文・高精度' },
13
+ { ref: 'ollama-cloud/kimi-k3' },
14
+ { ref: 'ollama-cloud/kimi-k2.7-code', note: 'コード' },
15
+ { ref: 'ollama-cloud/kimi-k2.6' },
16
+ { ref: 'ollama-cloud/minimax-m3' },
17
+ { ref: 'ollama-cloud/minimax-m3.1-flash', note: '高速' },
18
+ { ref: 'ollama-cloud/mimo-v2.6-pro' },
19
+ { ref: 'ollama-cloud/mimo-v2.6-flash', note: '高速' },
20
+ { ref: 'ollama-cloud/mistral-large-4' },
21
+ { ref: 'ollama-cloud/nemotron-3-ultra', note: '大規模' },
22
+ { ref: 'ollama-cloud/nemotron-3-super' },
23
+ { ref: 'ollama-cloud/inkling-2-small', note: '軽量' },
24
+ { ref: 'ollama-cloud/clef:27b' },
25
+ { ref: 'ollama-cloud/muse-spark-open' },
26
+ { ref: 'ollama-cloud/beam' },
27
+ ];
28
+ /** Sentinel value for the pinned search row; never a real model reference. */
29
+ export const SEARCH_ROW_VALUE = '\u0000search';
30
+ /** The endpoint and the date of the snapshot above; shown by `modkh models status`. */
31
+ export const OLLAMA_CLOUD_SOURCE = {
32
+ url: 'https://ollama.com/v1/models',
33
+ capturedAt: '2026-11-14',
34
+ };
35
+ /**
36
+ * Recommended defaults per provider, marked in the picker rather than reordered: existing
37
+ * references and their positions are relied on by other callers, so the list order is stable.
38
+ */
39
+ export const PROVIDER_DEFAULTS = {
40
+ 'ollama-cloud': ['ollama-cloud/deepseek-v4.1-flash', 'ollama-cloud/glm-5.3-flash', 'ollama-cloud/glm-5.3'],
41
+ };
42
+ /** Extra suggestions for providers without a published catalogue. */
43
+ export const OTHER_SUGGESTIONS = [
44
+ 'chatgpt/gpt-5.2', 'chatgpt/gpt-5.1-codex',
45
+ 'opencode/gpt-6-sol', 'opencode/gpt-5.4',
46
+ 'infron/openai/gpt-5.2', 'hermes/hermes-agent',
47
+ 'openai/gpt-5.2', 'openai/gpt-4.1',
48
+ 'anthropic/claude-sonnet-4-5', 'anthropic/claude-opus-4-5',
49
+ 'google/gemini-2.5-pro', 'google/gemini-2.5-flash',
50
+ 'deepseek/deepseek-chat', 'deepseek/deepseek-reasoner',
51
+ 'openrouter/openai/gpt-5.2', 'groq/llama-3.3-70b-versatile',
52
+ 'xai/grok-3', 'ollama/llama3.2', 'lmstudio/local-model', 'fixed/scripted',
53
+ ];
54
+ function unique(refs) {
55
+ return [...new Set(refs)];
56
+ }
57
+ /** Every known reference, catalogued providers first. */
58
+ export function allSuggestions() {
59
+ return unique([...OLLAMA_CLOUD_CATALOG.map(entry => entry.ref), ...OTHER_SUGGESTIONS]);
60
+ }
61
+ /** The catalogue in display order; recommendations are marked, never moved. */
62
+ export function suggestionsFor(provider, current) {
63
+ const catalog = provider === 'ollama-cloud'
64
+ ? OLLAMA_CLOUD_CATALOG.map(entry => entry.ref)
65
+ : OTHER_SUGGESTIONS.filter(ref => ref.startsWith(`${provider}/`));
66
+ return unique([...catalog, ...(current ? [current] : [])]);
67
+ }
68
+ /** Marks a recommended entry for the picker without changing its position. */
69
+ export function isRecommended(ref) {
70
+ const provider = ref.split('/')[0] ?? '';
71
+ return (PROVIDER_DEFAULTS[provider] ?? []).includes(ref);
72
+ }
73
+ /** Notes are advisory labels for the picker, keyed by full reference. */
74
+ export function noteFor(ref) {
75
+ return OLLAMA_CLOUD_CATALOG.find(entry => entry.ref === ref)?.note;
76
+ }
@@ -0,0 +1,18 @@
1
+ import { buildModelFromRef } from '../model/connection.ts';
2
+ export { buildModelFromRef } from '../model/connection.ts';
3
+ import { type LoginOptions } from '../model/chatgpt/login.ts';
4
+ import { type ChatTerminal } from './terminal.ts';
5
+ export interface ChatOptions {
6
+ args: Record<string, string | undefined>;
7
+ loginOptions?: LoginOptions;
8
+ /** Optional terminal owner for embedding; CLI defaults to the native terminal. */
9
+ terminal?: ChatTerminal;
10
+ /** Trusted embedding seam; never read from model arguments or workspace configuration. */
11
+ modelFactory?: typeof buildModelFromRef;
12
+ }
13
+ /** `/connect` の引数を解析する。失敗(引数なし/空)は null。 */
14
+ export declare function parseConnectArgs(rest: string): {
15
+ ref: string;
16
+ baseUrl?: string;
17
+ } | null;
18
+ export declare function runChat(opts: ChatOptions): Promise<void>;