modkh 0.1.0 → 0.2.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.
- package/README.md +42 -0
- package/dist/agent/bundled-skills.d.ts +1 -1
- package/dist/agent/bundled-skills.js +1 -1
- package/dist/agent/compaction.d.ts +53 -0
- package/dist/agent/compaction.js +191 -0
- package/dist/agent/loop.d.ts +55 -8
- package/dist/agent/loop.js +119 -7
- package/dist/agent/skills.d.ts +7 -1
- package/dist/agent/skills.js +26 -5
- package/dist/agent/types.d.ts +14 -9
- package/dist/cli/agenticreplay.d.ts +1 -0
- package/dist/cli/agenticreplay.js +66 -0
- package/dist/cli/answer-markdown.d.ts +3 -0
- package/dist/cli/answer-markdown.js +29 -0
- package/dist/cli/approval.d.ts +2 -0
- package/dist/cli/approval.js +35 -5
- package/dist/cli/catalog.d.ts +30 -32
- package/dist/cli/catalog.js +37 -67
- package/dist/cli/chat.js +406 -78
- package/dist/cli/clipboard.d.ts +2 -0
- package/dist/cli/clipboard.js +28 -0
- package/dist/cli/color.d.ts +20 -3
- package/dist/cli/color.js +87 -19
- package/dist/cli/compaction-settings.d.ts +21 -0
- package/dist/cli/compaction-settings.js +54 -0
- package/dist/cli/completion-art.d.ts +2 -0
- package/dist/cli/completion-art.js +62 -0
- package/dist/cli/config.d.ts +9 -0
- package/dist/cli/config.js +5 -1
- package/dist/cli/editor.d.ts +7 -0
- package/dist/cli/editor.js +43 -5
- package/dist/cli/file-mentions.d.ts +14 -0
- package/dist/cli/file-mentions.js +141 -0
- package/dist/cli/head-checks.d.ts +41 -0
- package/dist/cli/head-checks.js +146 -0
- package/dist/cli/initial-connection.d.ts +7 -0
- package/dist/cli/initial-connection.js +20 -0
- package/dist/cli/keys.d.ts +12 -1
- package/dist/cli/keys.js +29 -4
- package/dist/cli/model-catalog.d.ts +16 -0
- package/dist/cli/model-catalog.js +130 -0
- package/dist/cli/models.d.ts +2 -2
- package/dist/cli/models.js +51 -19
- package/dist/cli/official-models.d.ts +6 -0
- package/dist/cli/official-models.js +77 -0
- package/dist/cli/pdf.d.ts +8 -0
- package/dist/cli/pdf.js +71 -0
- package/dist/cli/providers.d.ts +6 -42
- package/dist/cli/providers.js +44 -38
- package/dist/cli/shell-display.d.ts +6 -0
- package/dist/cli/shell-display.js +35 -0
- package/dist/cli/stateright.d.ts +1 -0
- package/dist/cli/stateright.js +37 -0
- package/dist/cli/terminal-mouse.d.ts +21 -0
- package/dist/cli/terminal-mouse.js +51 -0
- package/dist/cli/terminal.d.ts +95 -7
- package/dist/cli/terminal.js +783 -108
- package/dist/cli/tool-display.d.ts +9 -0
- package/dist/cli/tool-display.js +87 -0
- package/dist/cli/transcript-selection.d.ts +22 -0
- package/dist/cli/transcript-selection.js +75 -0
- package/dist/cli/usage.d.ts +9 -16
- package/dist/cli/usage.js +60 -18
- package/dist/cli/waiting-nyan.d.ts +3 -0
- package/dist/cli/waiting-nyan.js +17 -0
- package/dist/cli/waiting-whales.d.ts +3 -0
- package/dist/cli/waiting-whales.js +24 -0
- package/dist/index.js +30 -8
- package/dist/language/commonlisp-install.d.ts +1 -0
- package/dist/language/commonlisp-install.js +3 -2
- package/dist/language/lsp/client.js +4 -1
- package/dist/language/lsp/pool.d.ts +8 -0
- package/dist/language/lsp/pool.js +21 -3
- package/dist/language/lsp/service.d.ts +8 -4
- package/dist/language/lsp/service.js +51 -15
- package/dist/language/syntax/parser.d.ts +10 -1
- package/dist/language/syntax/parser.js +34 -16
- package/dist/lisp/builtin-agents.d.ts +5 -0
- package/dist/lisp/builtin-agents.js +52 -0
- package/dist/lisp/config.d.ts +9 -0
- package/dist/lisp/config.js +50 -7
- package/dist/lisp/routing.js +2 -2
- package/dist/lisp/runtime.d.ts +5 -0
- package/dist/lisp/runtime.js +26 -2
- package/dist/model/ai-sdk.js +13 -8
- package/dist/model/chatgpt/login.js +1 -1
- package/dist/model/chatgpt/responses.js +56 -4
- package/dist/model/connection.js +2 -0
- package/dist/model/context-window.d.ts +3 -0
- package/dist/model/context-window.js +64 -0
- package/dist/model/context.d.ts +3 -1
- package/dist/model/context.js +24 -24
- package/dist/model/factory.d.ts +3 -1
- package/dist/model/factory.js +28 -27
- package/dist/model/harness-profile.d.ts +6 -0
- package/dist/model/harness-profile.js +23 -0
- package/dist/model/providers.d.ts +32 -0
- package/dist/model/providers.js +72 -0
- package/dist/model/reasoning.d.ts +3 -3
- package/dist/model/reasoning.js +30 -8
- package/dist/model/record-fetch.d.ts +2 -0
- package/dist/model/record-fetch.js +19 -0
- package/dist/plugins/manager.d.ts +2 -1
- package/dist/plugins/manager.js +21 -2
- package/dist/session/store.d.ts +11 -0
- package/dist/session/store.js +27 -1
- package/dist/subagents/head-assignment.d.ts +11 -0
- package/dist/subagents/head-assignment.js +47 -0
- package/dist/subagents/limits.d.ts +4 -0
- package/dist/subagents/limits.js +6 -0
- package/dist/subagents/request.js +18 -1
- package/dist/subagents/service.d.ts +36 -2
- package/dist/subagents/service.js +331 -38
- package/dist/subagents/types.d.ts +20 -0
- package/dist/subagents/verification.d.ts +5 -2
- package/dist/subagents/verification.js +59 -22
- package/dist/tools/browse.d.ts +13 -0
- package/dist/tools/browse.js +117 -0
- package/dist/tools/browser-capability.d.ts +3 -0
- package/dist/tools/browser-capability.js +29 -0
- package/dist/tools/formal-input.d.ts +6 -0
- package/dist/tools/formal-input.js +29 -0
- package/dist/tools/formal.d.ts +3 -2
- package/dist/tools/formal.js +54 -52
- package/dist/tools/jobs.d.ts +2 -0
- package/dist/tools/jobs.js +5 -0
- package/dist/tools/language.js +25 -27
- package/dist/tools/lean-proof.d.ts +38 -0
- package/dist/tools/lean-proof.js +83 -0
- package/dist/tools/registry.d.ts +5 -3
- package/dist/tools/registry.js +13 -5
- package/dist/tools/run.js +13 -9
- package/dist/tools/shell-process.js +17 -6
- package/dist/tools/stateright-runtime.d.ts +3 -0
- package/dist/tools/stateright-runtime.js +16 -0
- package/dist/tools/stateright.d.ts +3 -0
- package/dist/tools/stateright.js +78 -0
- package/dist/tools/web.js +7 -2
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/docs/commonlisp-build-output.md +14 -0
- package/docs/context-efficiency.md +25 -3
- package/docs/input.md +63 -3
- package/docs/languages.md +3 -3
- package/docs/models.md +30 -6
- package/docs/modkh.md +11 -7
- package/docs/presets.md +45 -0
- package/docs/setup.md +3 -16
- package/docs/stateright.md +45 -0
- package/docs/subagents.md +21 -3
- package/docs/web.md +1 -1
- package/experiments/presets/formal.lisp +15 -4
- package/experiments/presets/language-microagents.lisp +29 -0
- package/native/stateright/Cargo.lock +478 -0
- package/native/stateright/Cargo.toml +11 -0
- package/native/stateright/src/lib.rs +163 -0
- package/native/stateright/src/main.rs +38 -0
- package/package.json +10 -2
package/dist/agent/skills.d.ts
CHANGED
|
@@ -10,11 +10,17 @@ export interface TaskSkill {
|
|
|
10
10
|
export interface SkillContext {
|
|
11
11
|
text: string;
|
|
12
12
|
selected: string[];
|
|
13
|
+
sections: {
|
|
14
|
+
name: string;
|
|
15
|
+
text: string;
|
|
16
|
+
}[];
|
|
13
17
|
warnings: string[];
|
|
14
18
|
bytes: number;
|
|
15
19
|
}
|
|
16
20
|
export declare const SKILL_CONTEXT_BYTES: number;
|
|
17
21
|
/** Explicit mentions precede deterministic task matches; no paid classifier call. */
|
|
18
22
|
export declare function selectTaskSkills(task: string, catalog: readonly TaskSkill[]): TaskSkill[];
|
|
19
|
-
/**
|
|
23
|
+
/** Keep delivered instructions verbatim, adding whole sections within the session budget. */
|
|
24
|
+
export declare function mergeSkillContext(previous: SkillContext | undefined, next: SkillContext): SkillContext;
|
|
25
|
+
/** Select guidance for a user turn without changing the conversation journal. */
|
|
20
26
|
export declare function prepareSkillContext(task: string, root: string): SkillContext;
|
package/dist/agent/skills.js
CHANGED
|
@@ -104,7 +104,28 @@ function localCatalog(root, warnings, builtin) {
|
|
|
104
104
|
return [];
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
/**
|
|
107
|
+
/** Keep delivered instructions verbatim, adding whole sections within the session budget. */
|
|
108
|
+
export function mergeSkillContext(previous, next) {
|
|
109
|
+
if (!previous?.text)
|
|
110
|
+
return next;
|
|
111
|
+
let { text, bytes } = previous;
|
|
112
|
+
const sections = [...previous.sections];
|
|
113
|
+
const warnings = [...next.warnings];
|
|
114
|
+
for (const section of next.sections) {
|
|
115
|
+
if (previous.selected.includes(section.name))
|
|
116
|
+
continue;
|
|
117
|
+
const size = Buffer.byteLength(section.text);
|
|
118
|
+
if (bytes + size > SKILL_CONTEXT_BYTES) {
|
|
119
|
+
warnings.push(`${section.name}: 注入上限を超えるため本文全体を省略`);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
text += section.text;
|
|
123
|
+
bytes += size;
|
|
124
|
+
sections.push(section);
|
|
125
|
+
}
|
|
126
|
+
return { text, bytes, sections, selected: sections.map(section => section.name), warnings };
|
|
127
|
+
}
|
|
128
|
+
/** Select guidance for a user turn without changing the conversation journal. */
|
|
108
129
|
export function prepareSkillContext(task, root) {
|
|
109
130
|
const warnings = [];
|
|
110
131
|
let canonical;
|
|
@@ -112,7 +133,7 @@ export function prepareSkillContext(task, root) {
|
|
|
112
133
|
canonical = fs.realpathSync(root);
|
|
113
134
|
}
|
|
114
135
|
catch {
|
|
115
|
-
return { text: '', selected: [], warnings: ['作業ルートを確認できないためスキル注入を省略'], bytes: 0 };
|
|
136
|
+
return { text: '', selected: [], sections: [], warnings: ['作業ルートを確認できないためスキル注入を省略'], bytes: 0 };
|
|
116
137
|
}
|
|
117
138
|
let builtin = [];
|
|
118
139
|
try {
|
|
@@ -139,7 +160,7 @@ export function prepareSkillContext(task, root) {
|
|
|
139
160
|
const selected = [...new Set(order)].filter(name => names.has(name)).map(name => catalog.find(skill => skill.name === name)).filter((skill) => !!skill);
|
|
140
161
|
const header = '\n\n' + MODKH_SKILL_BINDING;
|
|
141
162
|
let text = '';
|
|
142
|
-
const
|
|
163
|
+
const sections = [];
|
|
143
164
|
const bodies = new Set();
|
|
144
165
|
for (const skill of selected) {
|
|
145
166
|
let body;
|
|
@@ -163,7 +184,7 @@ export function prepareSkillContext(task, root) {
|
|
|
163
184
|
}
|
|
164
185
|
text = (text || header) + section;
|
|
165
186
|
bodies.add(body);
|
|
166
|
-
|
|
187
|
+
sections.push({ name: skill.name, text: section });
|
|
167
188
|
}
|
|
168
|
-
return { text, selected:
|
|
189
|
+
return { text, selected: sections.map(section => section.name), sections, warnings, bytes: Buffer.byteLength(text) };
|
|
169
190
|
}
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -70,17 +70,22 @@ export interface Tool {
|
|
|
70
70
|
parameters: Record<string, unknown>;
|
|
71
71
|
execute(args: Record<string, unknown>, ctx: ToolContext): Promise<string | Pick<ToolResult, 'status' | 'output'>>;
|
|
72
72
|
}
|
|
73
|
+
/** Input includes both cache reads and cache writes when the provider reports them. */
|
|
74
|
+
export interface TokenUsage {
|
|
75
|
+
input?: number | undefined;
|
|
76
|
+
uncachedInput?: number | undefined;
|
|
77
|
+
output?: number | undefined;
|
|
78
|
+
cacheRead?: number | undefined;
|
|
79
|
+
cacheWrite?: number | undefined;
|
|
80
|
+
}
|
|
73
81
|
/** モデルストリームのイベント。 */
|
|
74
82
|
export type ModelEvent = {
|
|
75
83
|
type: 'activity';
|
|
76
|
-
stage: 'reasoning' | 'tool-input';
|
|
77
|
-
|
|
84
|
+
stage: 'accepted' | 'reasoning' | 'tool-input';
|
|
85
|
+
toolName?: string;
|
|
86
|
+
} | ({
|
|
78
87
|
type: 'usage';
|
|
79
|
-
|
|
80
|
-
output?: number;
|
|
81
|
-
cacheRead?: number;
|
|
82
|
-
cacheWrite?: number;
|
|
83
|
-
} | {
|
|
88
|
+
} & TokenUsage) | {
|
|
84
89
|
type: 'text-delta';
|
|
85
90
|
text: string;
|
|
86
91
|
}
|
|
@@ -93,7 +98,7 @@ export type ModelEvent = {
|
|
|
93
98
|
call: ToolCall;
|
|
94
99
|
} | {
|
|
95
100
|
type: 'finish';
|
|
96
|
-
stopReason: 'stop' | 'tool-calls' | 'aborted' | 'error';
|
|
101
|
+
stopReason: 'stop' | 'tool-calls' | 'aborted' | 'error' | 'length';
|
|
97
102
|
errorMessage?: string;
|
|
98
103
|
};
|
|
99
104
|
/** 会話メッセージ。tool メッセージは1つのアシスタント応答に対する結果群を保持する。 */
|
|
@@ -113,7 +118,7 @@ export type AgentMessage = {
|
|
|
113
118
|
/**
|
|
114
119
|
* 推論レベル。off は「明示的に止めたい」意志であり、その対応はプロバイダーごとに置く。
|
|
115
120
|
*/
|
|
116
|
-
export type ReasoningLevel = 'off' | 'minimal' | 'low' | 'medium' | 'high';
|
|
121
|
+
export type ReasoningLevel = 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'max';
|
|
117
122
|
export interface ModelRequest {
|
|
118
123
|
messages: AgentMessage[];
|
|
119
124
|
tools: ToolSpec[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function recordChat(entry: string, argv: readonly string[], args: Readonly<Record<string, string | undefined>>): Promise<number | undefined>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import { statSync } from 'node:fs';
|
|
3
|
+
import { constants } from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { configureHttpModelRecording } from "../model/record-fetch.js";
|
|
6
|
+
import { SessionStore } from "../session/store.js";
|
|
7
|
+
import { loadConfig } from "./config.js";
|
|
8
|
+
import { loadResumedSession, selectInitialConnection } from "./initial-connection.js";
|
|
9
|
+
export async function recordChat(entry, argv, args) {
|
|
10
|
+
const launchCwd = process.env.MODKH_AGENTICREPLAY_LAUNCH_CWD;
|
|
11
|
+
if (launchCwd && process.env.AGENTICREPLAY_TLS_CA) {
|
|
12
|
+
// The recorder starts in the workspace, while chat resolves CLI paths from the launch directory.
|
|
13
|
+
process.chdir(launchCwd);
|
|
14
|
+
delete process.env.MODKH_AGENTICREPLAY_LAUNCH_CWD;
|
|
15
|
+
const { EnvHttpProxyAgent, setGlobalDispatcher } = await import('undici');
|
|
16
|
+
// AgenticReplay uses the negotiated protocol upstream too. Some model APIs only offer HTTP/1.1.
|
|
17
|
+
setGlobalDispatcher(new EnvHttpProxyAgent({ requestTls: { allowH2: false } }));
|
|
18
|
+
configureHttpModelRecording(process.env.HTTPS_PROXY);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (process.env.MODKH_AGENTICREPLAY === '0' ||
|
|
22
|
+
process.env.AGENTICREPLAY_TLS_CA || process.env.AGENTICREPLAY_PROXY_URL)
|
|
23
|
+
return;
|
|
24
|
+
const cwd = path.resolve(args.cwd ?? process.cwd());
|
|
25
|
+
if (!statSync(cwd, { throwIfNoEntry: false })?.isDirectory())
|
|
26
|
+
return;
|
|
27
|
+
const probe = spawnSync('agenticreplay', ['version'], {
|
|
28
|
+
encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 2000, killSignal: 'SIGKILL', maxBuffer: 4096,
|
|
29
|
+
});
|
|
30
|
+
if (probe.status !== 0 || !probe.stdout?.trim())
|
|
31
|
+
return;
|
|
32
|
+
const config = loadConfig();
|
|
33
|
+
const session = args.resume ? loadResumedSession(new SessionStore(), args.resume, cwd) : undefined;
|
|
34
|
+
const { model, baseUrl } = selectInitialConnection(args, config, session);
|
|
35
|
+
const provider = model?.match(/^([^/]+)\/.+/)?.[1];
|
|
36
|
+
const { modelBaseUrl } = await import("../model/factory.js");
|
|
37
|
+
const target = provider ? URL.parse(modelBaseUrl(provider, baseUrl) ?? '') : null;
|
|
38
|
+
// AgenticReplay interprets commas and wildcards as policy syntax.
|
|
39
|
+
const tlsHosts = target?.protocol === 'https:' && !/[,\x2a]/.test(target.hostname)
|
|
40
|
+
? ['--tls-hosts', `+${target.hostname}`] : [];
|
|
41
|
+
const child = spawn('agenticreplay', [
|
|
42
|
+
'record', 'exec', '--tls-intercept', ...tlsHosts, '--no-fs', '--no-shell', '--no-agent-spans', '--',
|
|
43
|
+
process.execPath, ...process.execArgv, entry, ...argv,
|
|
44
|
+
], { cwd, stdio: 'inherit', env: { ...process.env, MODKH_AGENTICREPLAY_LAUNCH_CWD: process.cwd() } });
|
|
45
|
+
const forwardInterrupt = () => child.kill('SIGINT');
|
|
46
|
+
const forwardTermination = () => child.kill('SIGTERM');
|
|
47
|
+
process.on('SIGINT', forwardInterrupt);
|
|
48
|
+
process.on('SIGTERM', forwardTermination);
|
|
49
|
+
try {
|
|
50
|
+
return await new Promise(resolve => {
|
|
51
|
+
child.once('error', error => {
|
|
52
|
+
process.stderr.write(`AgenticReplay を起動できませんでした: ${error.message}\n`);
|
|
53
|
+
resolve(undefined);
|
|
54
|
+
});
|
|
55
|
+
child.once('close', (code, signal) => {
|
|
56
|
+
// AgenticReplay exits 2 for an incomplete recording after a successful chat,
|
|
57
|
+
// including sessions closed before the first model request.
|
|
58
|
+
resolve(code === 2 ? 0 : code ?? (signal ? 128 + constants.signals[signal] : 1));
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
process.off('SIGINT', forwardInterrupt);
|
|
64
|
+
process.off('SIGTERM', forwardTermination);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Lexer } from 'marked';
|
|
2
|
+
function paint(text, style) {
|
|
3
|
+
return text && style ? `\x1b[${style}m${text}\x1b[0m` : text;
|
|
4
|
+
}
|
|
5
|
+
function inline(tokens, palette, styles) {
|
|
6
|
+
return tokens.map(token => {
|
|
7
|
+
switch (token.type) {
|
|
8
|
+
case 'strong': return inline(token.tokens ?? [], palette, [...styles, '1']);
|
|
9
|
+
case 'em': return inline(token.tokens ?? [], palette, [...styles, '3']);
|
|
10
|
+
case 'del': return inline(token.tokens ?? [], palette, [...styles, '9']);
|
|
11
|
+
case 'link': {
|
|
12
|
+
const label = inline(token.tokens ?? [], palette, [...styles, '4']);
|
|
13
|
+
return token.href && token.href !== token.text ? `${label} (${token.href})` : label;
|
|
14
|
+
}
|
|
15
|
+
case 'codespan': return paint(token.text, [...styles, palette.codeKeyword].join(';'));
|
|
16
|
+
case 'escape': return paint(token.text, styles.join(';'));
|
|
17
|
+
default: return paint(token.raw, styles.join(';'));
|
|
18
|
+
}
|
|
19
|
+
}).join('');
|
|
20
|
+
}
|
|
21
|
+
/** Parse before soft wrapping so delimiters and graphemes use independent coordinates. */
|
|
22
|
+
export function answerMarkdown(line, palette) {
|
|
23
|
+
if (/^( {4}|\t)/.test(line))
|
|
24
|
+
return line;
|
|
25
|
+
const heading = /^ {0,3}#{1,6}(?:\s+|$)/.exec(line);
|
|
26
|
+
const body = heading ? line.slice(heading[0].length).replace(/\s+#+\s*$/, '')
|
|
27
|
+
: line.replace(/^(\s*)[-+*] (?=\S)/, '$1• ');
|
|
28
|
+
return inline(Lexer.lexInline(body), palette, heading ? [palette.heading] : []);
|
|
29
|
+
}
|
package/dist/cli/approval.d.ts
CHANGED
|
@@ -17,11 +17,13 @@ export declare class TerminalApprovalGate implements ApprovalGate {
|
|
|
17
17
|
private readonly io;
|
|
18
18
|
private policy;
|
|
19
19
|
private pending;
|
|
20
|
+
private queue;
|
|
20
21
|
constructor(io: ApprovalIo, policy?: PermissionPolicy);
|
|
21
22
|
/** Changing the policy affects later requests only; an open prompt is not cancelled. */
|
|
22
23
|
setPolicy(policy: PermissionPolicy): void;
|
|
23
24
|
currentPolicy(): PermissionPolicy;
|
|
24
25
|
interrupt(): void;
|
|
25
26
|
approve(request: ApprovalRequest): Promise<boolean>;
|
|
27
|
+
private prompt;
|
|
26
28
|
private askOrInterrupt;
|
|
27
29
|
}
|
package/dist/cli/approval.js
CHANGED
|
@@ -4,6 +4,7 @@ export class TerminalApprovalGate {
|
|
|
4
4
|
io;
|
|
5
5
|
policy;
|
|
6
6
|
pending = new Set();
|
|
7
|
+
queue = Promise.resolve();
|
|
7
8
|
constructor(io, policy = DEFAULT_POLICY) {
|
|
8
9
|
this.io = io;
|
|
9
10
|
this.policy = policy;
|
|
@@ -21,16 +22,45 @@ export class TerminalApprovalGate {
|
|
|
21
22
|
controller.abort();
|
|
22
23
|
}
|
|
23
24
|
async approve(request) {
|
|
25
|
+
if (request.signal?.aborted)
|
|
26
|
+
return false;
|
|
24
27
|
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
|
+
if (!shouldAsk({ policy: this.policy, kind: req.kind, outsideWorkspace: req.outsideWorkspace !== false }))
|
|
28
29
|
return true;
|
|
30
|
+
const controller = new AbortController();
|
|
31
|
+
const cancel = () => controller.abort();
|
|
32
|
+
request.signal?.addEventListener('abort', cancel, { once: true });
|
|
33
|
+
this.pending.add(controller);
|
|
34
|
+
let onAbort = () => { };
|
|
35
|
+
const interrupted = new Promise(resolve => {
|
|
36
|
+
onAbort = () => resolve(false);
|
|
37
|
+
controller.signal.addEventListener('abort', onAbort, { once: true });
|
|
38
|
+
});
|
|
39
|
+
const operation = this.queue.then(() => controller.signal.aborted ? false : this.prompt({ ...req, signal: controller.signal }));
|
|
40
|
+
this.queue = operation.then(() => { }, () => { });
|
|
41
|
+
try {
|
|
42
|
+
return await Promise.race([operation, interrupted]);
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
request.signal?.removeEventListener('abort', cancel);
|
|
46
|
+
controller.signal.removeEventListener('abort', onAbort);
|
|
47
|
+
this.pending.delete(controller);
|
|
29
48
|
}
|
|
49
|
+
}
|
|
50
|
+
async prompt(req) {
|
|
30
51
|
this.io.write(`\n--- 承認要求(${req.kind}) ---\n${req.title}\n${req.detail}\n`);
|
|
31
|
-
const
|
|
52
|
+
const controller = new AbortController();
|
|
53
|
+
const timer = setTimeout(() => controller.abort(), 180_000);
|
|
54
|
+
const signal = req.signal ? AbortSignal.any([req.signal, controller.signal]) : controller.signal;
|
|
55
|
+
let answer;
|
|
56
|
+
try {
|
|
57
|
+
answer = await this.askOrInterrupt('実行しますか?(回答期限3分)', signal);
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
}
|
|
32
62
|
if (answer === null) {
|
|
33
|
-
this.io.write('(中断により拒否)\n');
|
|
63
|
+
this.io.write(controller.signal.aborted ? '(3分以内に回答がなかったため拒否)\n' : '(中断により拒否)\n');
|
|
34
64
|
return false;
|
|
35
65
|
}
|
|
36
66
|
const ok = answer.trim().toLowerCase() === 'y';
|
package/dist/cli/catalog.d.ts
CHANGED
|
@@ -1,39 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Picker metadata shared by `/connect` and `/models`.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* this
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* list, and `modkh models refresh` can rewrite the snapshot from the live endpoint.
|
|
4
|
+
* There is deliberately no bundled model list here. AI providers add and retire models far more
|
|
5
|
+
* often than this project releases, so a baked-in list silently offers IDs that no longer exist.
|
|
6
|
+
* Model candidates come from `model-catalog.ts`, which asks the provider each time the picker
|
|
7
|
+
* opens. This module only holds stable facts: display order, labels and the search-row marker.
|
|
9
8
|
*/
|
|
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
9
|
/** Sentinel value for the pinned search row; never a real model reference. */
|
|
19
10
|
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
11
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
12
|
+
* MODKH 自身が提供する擬似モデル。プロバイダーが公開する一覧ではないため、ここだけは固定で持つ
|
|
13
|
+
* (オフライン検証用の fixed と、任意URLの compatible は取得元が存在しない)。
|
|
14
|
+
*/
|
|
15
|
+
export declare const LOCAL_MODEL_REFS: readonly string[];
|
|
16
|
+
/**
|
|
17
|
+
* Providers offered by `/connect`, in display order. `keyOnly` entries store a credential
|
|
18
|
+
* without connecting a model (web search). A model list is never attached to these rows.
|
|
19
|
+
*/
|
|
20
|
+
export interface ConnectProvider {
|
|
21
|
+
readonly value: string;
|
|
22
|
+
readonly label: string;
|
|
23
|
+
/** Shown as the row detail; the credential or endpoint, never a model list. */
|
|
24
|
+
readonly detail: string;
|
|
25
|
+
/** Environment variable holding the API key; null when the endpoint needs none. */
|
|
26
|
+
readonly key: string | null;
|
|
27
|
+
readonly keyOnly?: true;
|
|
28
|
+
}
|
|
29
|
+
/** Rows are data only; providers and endpoints are validated by `model/providers.ts`. */
|
|
30
|
+
export declare const CONNECT_PROVIDERS: readonly ConnectProvider[];
|
|
31
|
+
/** `/connect` に出す行(検索キー専用の登録は除く)。 */
|
|
32
|
+
export declare function modelProviders(): ConnectProvider[];
|
|
33
|
+
/**
|
|
34
|
+
* 与えられたIDを `<provider>/<model>` の形に整える。取得した一覧も、利用者が直接入力したIDも
|
|
35
|
+
* 同じ経路を通す。既に接頭辞が付いた値は二重に付けない。
|
|
28
36
|
*/
|
|
29
|
-
export declare
|
|
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;
|
|
37
|
+
export declare function toRefs(provider: string, ids: readonly string[], current?: string | null): string[];
|
package/dist/cli/catalog.js
CHANGED
|
@@ -1,76 +1,46 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
];
|
|
1
|
+
/**
|
|
2
|
+
* Picker metadata shared by `/connect` and `/models`.
|
|
3
|
+
*
|
|
4
|
+
* There is deliberately no bundled model list here. AI providers add and retire models far more
|
|
5
|
+
* often than this project releases, so a baked-in list silently offers IDs that no longer exist.
|
|
6
|
+
* Model candidates come from `model-catalog.ts`, which asks the provider each time the picker
|
|
7
|
+
* opens. This module only holds stable facts: display order, labels and the search-row marker.
|
|
8
|
+
*/
|
|
28
9
|
/** Sentinel value for the pinned search row; never a real model reference. */
|
|
29
10
|
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
11
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
12
|
+
* MODKH 自身が提供する擬似モデル。プロバイダーが公開する一覧ではないため、ここだけは固定で持つ
|
|
13
|
+
* (オフライン検証用の fixed と、任意URLの compatible は取得元が存在しない)。
|
|
38
14
|
*/
|
|
39
|
-
export const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
'
|
|
45
|
-
'
|
|
46
|
-
'
|
|
47
|
-
'
|
|
48
|
-
'
|
|
49
|
-
'
|
|
50
|
-
|
|
51
|
-
'
|
|
52
|
-
'xai/grok-3', 'ollama/llama3.2', 'lmstudio/local-model', 'fixed/scripted',
|
|
15
|
+
export const LOCAL_MODEL_REFS = ['fixed/scripted'];
|
|
16
|
+
/** Rows are data only; providers and endpoints are validated by `model/providers.ts`. */
|
|
17
|
+
export const CONNECT_PROVIDERS = [
|
|
18
|
+
{ value: 'openai', label: 'OpenAI', detail: 'ChatGPT OAuth (chatgpt) / OPENAI_API_KEY', key: 'OPENAI_API_KEY' },
|
|
19
|
+
{ value: 'opencode', label: 'OpenCode Zen', detail: 'Console · OPENCODE_API_KEY', key: 'OPENCODE_API_KEY' },
|
|
20
|
+
{ value: 'opencode-go', label: 'OpenCode Go', detail: 'Console · 同じ OPENCODE_API_KEY', key: 'OPENCODE_API_KEY' },
|
|
21
|
+
{ value: 'ollama', label: 'Ollama Local', detail: 'ローカル · OLLAMA_BASE_URL', key: null },
|
|
22
|
+
{ value: 'ollama-cloud', label: 'Ollama Cloud', detail: 'ollama.com · OLLAMA_API_KEY', key: 'OLLAMA_API_KEY' },
|
|
23
|
+
{ value: 'openrouter', label: 'OpenRouter', detail: 'OPENROUTER_API_KEY', key: 'OPENROUTER_API_KEY' },
|
|
24
|
+
{ value: 'infron', label: 'Infron', detail: 'INFRON_API_KEY', key: 'INFRON_API_KEY' },
|
|
25
|
+
{ value: 'hermes', label: 'Hermes Agent', detail: 'API server · HERMES_API_KEY', key: 'HERMES_API_KEY' },
|
|
26
|
+
// Web検索のキー登録専用。モデル接続の一覧には含めない。
|
|
27
|
+
{ value: 'brave-search', label: 'Brave Search', detail: 'web_search 用のキー · BRAVE_SEARCH_API_KEY', key: 'BRAVE_SEARCH_API_KEY', keyOnly: true },
|
|
53
28
|
];
|
|
29
|
+
/** `/connect` に出す行(検索キー専用の登録は除く)。 */
|
|
30
|
+
export function modelProviders() {
|
|
31
|
+
return CONNECT_PROVIDERS.filter(provider => provider.keyOnly !== true);
|
|
32
|
+
}
|
|
54
33
|
function unique(refs) {
|
|
55
34
|
return [...new Set(refs)];
|
|
56
35
|
}
|
|
57
|
-
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return unique([...
|
|
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;
|
|
36
|
+
/**
|
|
37
|
+
* 与えられたIDを `<provider>/<model>` の形に整える。取得した一覧も、利用者が直接入力したIDも
|
|
38
|
+
* 同じ経路を通す。既に接頭辞が付いた値は二重に付けない。
|
|
39
|
+
*/
|
|
40
|
+
export function toRefs(provider, ids, current) {
|
|
41
|
+
const prefix = `${provider}/`;
|
|
42
|
+
const refs = ids
|
|
43
|
+
.filter(id => id.length > 0)
|
|
44
|
+
.map(id => (id.startsWith(prefix) ? id : `${prefix}${id}`));
|
|
45
|
+
return unique([...refs, ...(current ? [current] : [])]);
|
|
76
46
|
}
|