modkh 0.0.0-stage → 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 +66 -2
- package/dist/agent/bundled-skills.d.ts +13 -0
- package/dist/agent/bundled-skills.js +95 -0
- package/dist/agent/compaction.d.ts +53 -0
- package/dist/agent/compaction.js +191 -0
- package/dist/agent/images.d.ts +10 -0
- package/dist/agent/images.js +33 -0
- package/dist/agent/loop.d.ts +103 -0
- package/dist/agent/loop.js +267 -0
- package/dist/agent/skills.d.ts +26 -0
- package/dist/agent/skills.js +190 -0
- package/dist/agent/types.d.ts +137 -0
- package/dist/agent/types.js +12 -0
- package/dist/cli/agenticreplay.d.ts +1 -0
- package/dist/cli/agenticreplay.js +66 -0
- package/dist/cli/agents.d.ts +8 -0
- package/dist/cli/agents.js +12 -0
- package/dist/cli/answer-markdown.d.ts +3 -0
- package/dist/cli/answer-markdown.js +29 -0
- package/dist/cli/approval.d.ts +29 -0
- package/dist/cli/approval.js +92 -0
- package/dist/cli/catalog.d.ts +37 -0
- package/dist/cli/catalog.js +46 -0
- package/dist/cli/chat.d.ts +18 -0
- package/dist/cli/chat.js +1061 -0
- package/dist/cli/clipboard.d.ts +11 -0
- package/dist/cli/clipboard.js +82 -0
- package/dist/cli/color.d.ts +59 -0
- package/dist/cli/color.js +244 -0
- 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 +50 -0
- package/dist/cli/config.js +192 -0
- package/dist/cli/editor.d.ts +23 -0
- package/dist/cli/editor.js +115 -0
- 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 +29 -0
- package/dist/cli/keys.js +107 -0
- package/dist/cli/language.d.ts +1 -0
- package/dist/cli/language.js +105 -0
- package/dist/cli/limits.d.ts +13 -0
- package/dist/cli/limits.js +19 -0
- package/dist/cli/lines.d.ts +18 -0
- package/dist/cli/lines.js +80 -0
- package/dist/cli/model-catalog.d.ts +16 -0
- package/dist/cli/model-catalog.js +130 -0
- package/dist/cli/models.d.ts +4 -0
- package/dist/cli/models.js +101 -0
- 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/permissions.d.ts +25 -0
- package/dist/cli/permissions.js +30 -0
- package/dist/cli/plugins.d.ts +1 -0
- package/dist/cli/plugins.js +53 -0
- package/dist/cli/providers.d.ts +10 -0
- package/dist/cli/providers.js +82 -0
- 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 +231 -0
- package/dist/cli/terminal.js +1417 -0
- 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 +22 -0
- package/dist/cli/usage.js +117 -0
- 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.d.ts +11 -0
- package/dist/index.js +186 -0
- package/dist/language/catalog.d.ts +44 -0
- package/dist/language/catalog.js +100 -0
- package/dist/language/commonlisp-bundled.d.ts +11 -0
- package/dist/language/commonlisp-bundled.js +22 -0
- package/dist/language/commonlisp-dependencies.d.ts +16 -0
- package/dist/language/commonlisp-dependencies.js +68 -0
- package/dist/language/commonlisp-install.d.ts +15 -0
- package/dist/language/commonlisp-install.js +214 -0
- package/dist/language/commonlisp-reader.d.ts +17 -0
- package/dist/language/commonlisp-reader.js +47 -0
- package/dist/language/commonlisp-systems.d.ts +3 -0
- package/dist/language/commonlisp-systems.js +32 -0
- package/dist/language/commonlisp-tls.d.ts +10 -0
- package/dist/language/commonlisp-tls.js +51 -0
- package/dist/language/detect.d.ts +29 -0
- package/dist/language/detect.js +103 -0
- package/dist/language/grammars/LICENSE +24 -0
- package/dist/language/grammars/manifest.json +76 -0
- package/dist/language/grammars/tree-sitter-c.wasm +0 -0
- package/dist/language/grammars/tree-sitter-cpp.wasm +0 -0
- package/dist/language/grammars/tree-sitter-css.wasm +0 -0
- package/dist/language/grammars/tree-sitter-html.wasm +0 -0
- package/dist/language/grammars/tree-sitter-javascript.wasm +0 -0
- package/dist/language/grammars/tree-sitter-php.wasm +0 -0
- package/dist/language/grammars/tree-sitter-python.wasm +0 -0
- package/dist/language/grammars/tree-sitter-ruby.wasm +0 -0
- package/dist/language/grammars/tree-sitter-rust.wasm +0 -0
- package/dist/language/grammars/tree-sitter-swift.wasm +0 -0
- package/dist/language/grammars/tree-sitter-tsx.wasm +0 -0
- package/dist/language/grammars/tree-sitter-typescript.wasm +0 -0
- package/dist/language/install.d.ts +50 -0
- package/dist/language/install.js +293 -0
- package/dist/language/lsp/client.d.ts +97 -0
- package/dist/language/lsp/client.js +340 -0
- package/dist/language/lsp/pool.d.ts +75 -0
- package/dist/language/lsp/pool.js +140 -0
- package/dist/language/lsp/service.d.ts +50 -0
- package/dist/language/lsp/service.js +174 -0
- package/dist/language/native.d.ts +8 -0
- package/dist/language/native.js +100 -0
- package/dist/language/platform.d.ts +14 -0
- package/dist/language/platform.js +20 -0
- package/dist/language/positions.d.ts +20 -0
- package/dist/language/positions.js +46 -0
- package/dist/language/syntax/assets.d.ts +9 -0
- package/dist/language/syntax/assets.js +73 -0
- package/dist/language/syntax/parser.d.ts +33 -0
- package/dist/language/syntax/parser.js +162 -0
- package/dist/language/typescript-capability.d.ts +6 -0
- package/dist/language/typescript-capability.js +42 -0
- package/dist/lisp/builtin-agents.d.ts +5 -0
- package/dist/lisp/builtin-agents.js +52 -0
- package/dist/lisp/config.d.ts +25 -0
- package/dist/lisp/config.js +202 -0
- package/dist/lisp/routing.d.ts +5 -0
- package/dist/lisp/routing.js +24 -0
- package/dist/lisp/runtime.d.ts +26 -0
- package/dist/lisp/runtime.js +107 -0
- package/dist/memory/kiokuko.d.ts +32 -0
- package/dist/memory/kiokuko.js +102 -0
- package/dist/memory/mcp.d.ts +38 -0
- package/dist/memory/mcp.js +211 -0
- package/dist/model/ai-sdk.d.ts +27 -0
- package/dist/model/ai-sdk.js +185 -0
- package/dist/model/chatgpt/login.d.ts +42 -0
- package/dist/model/chatgpt/login.js +180 -0
- package/dist/model/chatgpt/responses.d.ts +41 -0
- package/dist/model/chatgpt/responses.js +254 -0
- package/dist/model/chatgpt/tokens.d.ts +11 -0
- package/dist/model/chatgpt/tokens.js +50 -0
- package/dist/model/connection.d.ts +6 -0
- package/dist/model/connection.js +67 -0
- package/dist/model/context-window.d.ts +3 -0
- package/dist/model/context-window.js +64 -0
- package/dist/model/context.d.ts +11 -0
- package/dist/model/context.js +69 -0
- package/dist/model/factory.d.ts +27 -0
- package/dist/model/factory.js +89 -0
- package/dist/model/fixed.d.ts +17 -0
- package/dist/model/fixed.js +41 -0
- 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 +16 -0
- package/dist/model/reasoning.js +84 -0
- package/dist/model/record-fetch.d.ts +2 -0
- package/dist/model/record-fetch.js +19 -0
- package/dist/plugins/api.d.ts +60 -0
- package/dist/plugins/api.js +1 -0
- package/dist/plugins/manager.d.ts +35 -0
- package/dist/plugins/manager.js +280 -0
- package/dist/plugins/package.d.ts +13 -0
- package/dist/plugins/package.js +99 -0
- package/dist/plugins/registry.d.ts +8 -0
- package/dist/plugins/registry.js +14 -0
- package/dist/session/store.d.ts +93 -0
- package/dist/session/store.js +311 -0
- package/dist/session/workspace.d.ts +19 -0
- package/dist/session/workspace.js +73 -0
- 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/processes.d.ts +18 -0
- package/dist/subagents/processes.js +73 -0
- package/dist/subagents/request.d.ts +4 -0
- package/dist/subagents/request.js +38 -0
- package/dist/subagents/service.d.ts +73 -0
- package/dist/subagents/service.js +645 -0
- package/dist/subagents/settings.d.ts +10 -0
- package/dist/subagents/settings.js +32 -0
- package/dist/subagents/types.d.ts +63 -0
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/verification.d.ts +34 -0
- package/dist/subagents/verification.js +215 -0
- 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/diff.d.ts +6 -0
- package/dist/tools/diff.js +82 -0
- package/dist/tools/edit.d.ts +3 -0
- package/dist/tools/edit.js +152 -0
- package/dist/tools/files.d.ts +6 -0
- package/dist/tools/files.js +96 -0
- package/dist/tools/formal-input.d.ts +6 -0
- package/dist/tools/formal-input.js +29 -0
- package/dist/tools/formal.d.ts +9 -0
- package/dist/tools/formal.js +79 -0
- package/dist/tools/guard.d.ts +7 -0
- package/dist/tools/guard.js +48 -0
- package/dist/tools/job-tools.d.ts +19 -0
- package/dist/tools/job-tools.js +148 -0
- package/dist/tools/jobs.d.ts +79 -0
- package/dist/tools/jobs.js +186 -0
- package/dist/tools/language.d.ts +6 -0
- package/dist/tools/language.js +172 -0
- package/dist/tools/lean-proof.d.ts +38 -0
- package/dist/tools/lean-proof.js +83 -0
- package/dist/tools/registry.d.ts +30 -0
- package/dist/tools/registry.js +113 -0
- package/dist/tools/run.d.ts +13 -0
- package/dist/tools/run.js +163 -0
- package/dist/tools/search.d.ts +2 -0
- package/dist/tools/search.js +156 -0
- package/dist/tools/shell-process.d.ts +115 -0
- package/dist/tools/shell-process.js +297 -0
- package/dist/tools/skills.d.ts +2 -0
- package/dist/tools/skills.js +46 -0
- 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.d.ts +24 -0
- package/dist/tools/web.js +391 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/docs/ci-repair-20261116.md +30 -0
- package/docs/commonlisp-build-output.md +14 -0
- package/docs/commonlisp-provider-migration.md +22 -0
- package/docs/commonlisp-qlot-recovery.md +28 -0
- package/docs/commonlisp-tls-recovery.md +28 -0
- package/docs/context-efficiency.md +122 -0
- package/docs/input.md +126 -0
- package/docs/languages.md +117 -0
- package/docs/models.md +109 -0
- package/docs/modkh-evidence.json +641 -0
- package/docs/modkh-failure-comparison.json +675 -0
- package/docs/modkh-namespace.md +39 -0
- package/docs/modkh-qlot-evidence.json +37 -0
- package/docs/modkh-verification.md +173 -0
- package/docs/modkh.md +128 -0
- package/docs/presets.md +64 -0
- package/docs/setup.md +99 -0
- package/docs/stateright.md +45 -0
- package/docs/subagents.md +152 -0
- package/docs/web.md +57 -0
- package/experiments/presets/common-lisp.lisp +38 -0
- package/experiments/presets/css.lisp +38 -0
- package/experiments/presets/formal.lisp +18 -0
- package/experiments/presets/html.lisp +38 -0
- package/experiments/presets/js.lisp +38 -0
- package/experiments/presets/language-microagents.lisp +29 -0
- package/experiments/presets/php.lisp +38 -0
- package/experiments/presets/svelte.lisp +38 -0
- package/experiments/presets/tailwindcss.lisp +24 -0
- package/experiments/presets/ts.lisp +38 -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 +57 -4
- package/plugins/modkh-explorer/index.mjs +3 -0
- package/plugins/modkh-explorer/plugin.json +1 -0
- package/plugins/modkh-worker/index.mjs +3 -0
- package/plugins/modkh-worker/plugin.json +1 -0
- package/skills/kiokuko-dsh/LICENSE +21 -0
- package/skills/kiokuko-dsh/coding-ideal-routine-skill/SKILL.md +106 -0
- package/skills/kiokuko-dsh/japanese-translation-for-oss-models/SKILL.md +65 -0
- package/skills/kiokuko-dsh/kiokuko-architecture/SKILL.md +20 -0
- package/skills/kiokuko-dsh/kiokuko-architecture/references/cases.md +11 -0
- package/skills/kiokuko-dsh/kiokuko-benchmark/SKILL.md +20 -0
- package/skills/kiokuko-dsh/kiokuko-benchmark/references/cases.md +11 -0
- package/skills/kiokuko-dsh/kiokuko-investigate/SKILL.md +20 -0
- package/skills/kiokuko-dsh/kiokuko-investigate/references/cases.md +11 -0
- package/skills/kiokuko-dsh/kiokuko-lisp/SKILL.md +390 -0
- package/skills/kiokuko-dsh/kiokuko-review/SKILL.md +20 -0
- package/skills/kiokuko-dsh/kiokuko-review/references/cases.md +11 -0
- package/skills/kiokuko-dsh/kiokuko-simple-work/SKILL.md +70 -0
- package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/SKILL.md +79 -0
- package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/boundaries-and-ownership.md +52 -0
- package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/domain-and-types.md +48 -0
- package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/effects-and-data.md +43 -0
- package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/kiokuko-patterns.md +314 -0
- package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/problem-shaping-and-language.md +90 -0
- package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/protocols-and-idempotency.md +42 -0
- package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/review-checklist.md +92 -0
- package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/verification.md +45 -0
- package/skills/kiokuko-dsh/kiokuko-skill-authoring/SKILL.md +20 -0
- package/skills/kiokuko-dsh/kiokuko-skill-authoring/references/cases.md +11 -0
- package/skills/kiokuko-dsh/kiokuko-soul/SKILL.md +25 -0
- package/skills/kiokuko-dsh/kiokuko-technical-writing/SKILL.md +20 -0
- package/skills/kiokuko-dsh/kiokuko-technical-writing/references/cases.md +11 -0
- package/skills/kiokuko-dsh/kiokuko-ui-design-soul/SKILL.md +64 -0
- package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/accessibility-and-navigation.md +31 -0
- package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/async-recovery.md +49 -0
- package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/forms-and-controls.md +35 -0
- package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/interaction-feedback.md +34 -0
- package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/responsive-and-platform.md +38 -0
- package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/safety-and-review.md +43 -0
- package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/ui-checklist.md +75 -0
- package/skills/kiokuko-dsh/kiokuko-verification/SKILL.md +20 -0
- package/skills/kiokuko-dsh/kiokuko-verification/references/cases.md +11 -0
- package/skills/kiokuko-dsh/manifest.json +168 -0
- package/skills/kiokuko-dsh/memory-reasoning/SKILL.md +44 -0
- package/skills/kiokuko-dsh/one-shot-software-completion/SKILL.md +113 -0
- package/skills/kiokuko-dsh/one-shot-software-completion/references/boundaries-and-lifecycle.md +70 -0
- package/skills/kiokuko-dsh/one-shot-software-completion/references/discovery-and-scope.md +71 -0
- package/skills/kiokuko-dsh/one-shot-software-completion/references/failure-recovery.md +43 -0
- package/skills/kiokuko-dsh/one-shot-software-completion/references/verification-and-completion.md +73 -0
- package/skills/kiokuko-dsh/veteran-programmer-skill/SKILL.md +66 -0
|
@@ -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,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,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
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
private queue;
|
|
21
|
+
constructor(io: ApprovalIo, policy?: PermissionPolicy);
|
|
22
|
+
/** Changing the policy affects later requests only; an open prompt is not cancelled. */
|
|
23
|
+
setPolicy(policy: PermissionPolicy): void;
|
|
24
|
+
currentPolicy(): PermissionPolicy;
|
|
25
|
+
interrupt(): void;
|
|
26
|
+
approve(request: ApprovalRequest): Promise<boolean>;
|
|
27
|
+
private prompt;
|
|
28
|
+
private askOrInterrupt;
|
|
29
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { DEFAULT_POLICY, describePolicy, shouldAsk } from "./permissions.js";
|
|
2
|
+
/** 端末承認。Stop は承認待ちと、その質問が所有する入力待ちを取り消す。 */
|
|
3
|
+
export class TerminalApprovalGate {
|
|
4
|
+
io;
|
|
5
|
+
policy;
|
|
6
|
+
pending = new Set();
|
|
7
|
+
queue = Promise.resolve();
|
|
8
|
+
constructor(io, policy = DEFAULT_POLICY) {
|
|
9
|
+
this.io = io;
|
|
10
|
+
this.policy = policy;
|
|
11
|
+
}
|
|
12
|
+
/** Changing the policy affects later requests only; an open prompt is not cancelled. */
|
|
13
|
+
setPolicy(policy) {
|
|
14
|
+
this.policy = policy;
|
|
15
|
+
this.io.write(`(${describePolicy(policy)})\n`);
|
|
16
|
+
}
|
|
17
|
+
currentPolicy() {
|
|
18
|
+
return this.policy;
|
|
19
|
+
}
|
|
20
|
+
interrupt() {
|
|
21
|
+
for (const controller of this.pending)
|
|
22
|
+
controller.abort();
|
|
23
|
+
}
|
|
24
|
+
async approve(request) {
|
|
25
|
+
if (request.signal?.aborted)
|
|
26
|
+
return false;
|
|
27
|
+
const req = request;
|
|
28
|
+
if (!shouldAsk({ policy: this.policy, kind: req.kind, outsideWorkspace: req.outsideWorkspace !== false }))
|
|
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);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async prompt(req) {
|
|
51
|
+
this.io.write(`\n--- 承認要求(${req.kind}) ---\n${req.title}\n${req.detail}\n`);
|
|
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
|
+
}
|
|
62
|
+
if (answer === null) {
|
|
63
|
+
this.io.write(controller.signal.aborted ? '(3分以内に回答がなかったため拒否)\n' : '(中断により拒否)\n');
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const ok = answer.trim().toLowerCase() === 'y';
|
|
67
|
+
this.io.write(ok ? '(承認)\n' : '(拒否)\n');
|
|
68
|
+
return ok;
|
|
69
|
+
}
|
|
70
|
+
async askOrInterrupt(prompt, signal) {
|
|
71
|
+
if (signal?.aborted)
|
|
72
|
+
return null;
|
|
73
|
+
const controller = new AbortController();
|
|
74
|
+
const cancel = () => controller.abort();
|
|
75
|
+
signal?.addEventListener('abort', cancel, { once: true });
|
|
76
|
+
this.pending.add(controller);
|
|
77
|
+
let onAbort = () => { };
|
|
78
|
+
try {
|
|
79
|
+
const interrupted = new Promise((resolve) => {
|
|
80
|
+
onAbort = () => resolve(null);
|
|
81
|
+
controller.signal.addEventListener('abort', onAbort, { once: true });
|
|
82
|
+
});
|
|
83
|
+
const answer = await Promise.race([this.io.ask(prompt, controller.signal), interrupted]);
|
|
84
|
+
return controller.signal.aborted ? null : answer;
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
signal?.removeEventListener('abort', cancel);
|
|
88
|
+
controller.signal.removeEventListener('abort', onAbort);
|
|
89
|
+
this.pending.delete(controller);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
*/
|
|
9
|
+
/** Sentinel value for the pinned search row; never a real model reference. */
|
|
10
|
+
export declare const SEARCH_ROW_VALUE = "\0search";
|
|
11
|
+
/**
|
|
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
|
+
* 同じ経路を通す。既に接頭辞が付いた値は二重に付けない。
|
|
36
|
+
*/
|
|
37
|
+
export declare function toRefs(provider: string, ids: readonly string[], current?: string | null): string[];
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
*/
|
|
9
|
+
/** Sentinel value for the pinned search row; never a real model reference. */
|
|
10
|
+
export const SEARCH_ROW_VALUE = '\u0000search';
|
|
11
|
+
/**
|
|
12
|
+
* MODKH 自身が提供する擬似モデル。プロバイダーが公開する一覧ではないため、ここだけは固定で持つ
|
|
13
|
+
* (オフライン検証用の fixed と、任意URLの compatible は取得元が存在しない)。
|
|
14
|
+
*/
|
|
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 },
|
|
28
|
+
];
|
|
29
|
+
/** `/connect` に出す行(検索キー専用の登録は除く)。 */
|
|
30
|
+
export function modelProviders() {
|
|
31
|
+
return CONNECT_PROVIDERS.filter(provider => provider.keyOnly !== true);
|
|
32
|
+
}
|
|
33
|
+
function unique(refs) {
|
|
34
|
+
return [...new Set(refs)];
|
|
35
|
+
}
|
|
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] : [])]);
|
|
46
|
+
}
|
|
@@ -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>;
|