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,162 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { Parser, Language, Query } from 'web-tree-sitter';
|
|
3
|
+
import { grammarPaths } from "./assets.js";
|
|
4
|
+
const loaded = new Map();
|
|
5
|
+
let initializing = null;
|
|
6
|
+
/** One WASM runtime per process; grammars are loaded lazily and kept small. */
|
|
7
|
+
async function runtime() {
|
|
8
|
+
initializing ??= Parser.init();
|
|
9
|
+
await initializing;
|
|
10
|
+
}
|
|
11
|
+
const DEFINITION_QUERIES = {
|
|
12
|
+
typescript: `(function_declaration name: (identifier) @name)
|
|
13
|
+
(class_declaration name: (type_identifier) @name)
|
|
14
|
+
(interface_declaration name: (type_identifier) @name)
|
|
15
|
+
(type_alias_declaration name: (type_identifier) @name)
|
|
16
|
+
(enum_declaration name: (identifier) @name)
|
|
17
|
+
(method_definition name: (property_identifier) @name)
|
|
18
|
+
(lexical_declaration (variable_declarator name: (identifier) @name))`,
|
|
19
|
+
python: `(function_definition name: (identifier) @name)
|
|
20
|
+
(class_definition name: (identifier) @name)`,
|
|
21
|
+
rust: `(function_item name: (identifier) @name)
|
|
22
|
+
(struct_item name: (type_identifier) @name)
|
|
23
|
+
(enum_item name: (type_identifier) @name)
|
|
24
|
+
(trait_item name: (type_identifier) @name)
|
|
25
|
+
(impl_item type: (type_identifier) @name)`,
|
|
26
|
+
c: `(function_definition declarator: (function_declarator declarator: (identifier) @name))
|
|
27
|
+
(struct_specifier name: (type_identifier) @name)`,
|
|
28
|
+
cpp: `(function_definition declarator: (function_declarator declarator: (_) @name))
|
|
29
|
+
(class_specifier name: (type_identifier) @name)
|
|
30
|
+
(struct_specifier name: (type_identifier) @name)
|
|
31
|
+
(namespace_definition name: (namespace_identifier) @name)`,
|
|
32
|
+
ruby: `(method name: (_) @name)
|
|
33
|
+
(class name: (constant) @name)
|
|
34
|
+
(module name: (constant) @name)`,
|
|
35
|
+
php: `(function_definition name: (name) @name)
|
|
36
|
+
(class_declaration name: (name) @name)
|
|
37
|
+
(method_declaration name: (name) @name)`,
|
|
38
|
+
swift: `(function_declaration name: (simple_identifier) @name)
|
|
39
|
+
(class_declaration name: (type_identifier) @name)
|
|
40
|
+
(protocol_declaration name: (type_identifier) @name)`,
|
|
41
|
+
html: `(element (start_tag (tag_name) @name))`,
|
|
42
|
+
css: `(rule_set (selectors) @name)`,
|
|
43
|
+
};
|
|
44
|
+
// JS/TSX share the TypeScript-family grammar names but have their own wasm files.
|
|
45
|
+
for (const alias of ['javascript', 'tsx']) {
|
|
46
|
+
DEFINITION_QUERIES[alias] = DEFINITION_QUERIES['typescript'] ?? '';
|
|
47
|
+
}
|
|
48
|
+
DEFINITION_QUERIES['javascript'] = `(function_declaration name: (identifier) @name)
|
|
49
|
+
(class_declaration name: (identifier) @name)
|
|
50
|
+
(method_definition name: (property_identifier) @name)
|
|
51
|
+
(lexical_declaration (variable_declarator name: (identifier) @name))`;
|
|
52
|
+
/** Bare `enclosing` lookups do not need naming; queries above name definitions only. */
|
|
53
|
+
export function definitionQuery(grammar) {
|
|
54
|
+
return DEFINITION_QUERIES[grammar];
|
|
55
|
+
}
|
|
56
|
+
async function load(grammar) {
|
|
57
|
+
const cached = loaded.get(grammar);
|
|
58
|
+
if (cached instanceof Error)
|
|
59
|
+
throw cached;
|
|
60
|
+
if (cached)
|
|
61
|
+
return cached;
|
|
62
|
+
try {
|
|
63
|
+
const paths = grammarPaths(grammar);
|
|
64
|
+
if (!paths)
|
|
65
|
+
throw new Error(`文法 ${grammar} は同梱されていません`);
|
|
66
|
+
await runtime();
|
|
67
|
+
const language = await Language.load(paths.bytes);
|
|
68
|
+
const parser = new Parser();
|
|
69
|
+
parser.setLanguage(language);
|
|
70
|
+
const value = { parser, language };
|
|
71
|
+
loaded.set(grammar, value);
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
const failure = e instanceof Error ? e : new Error(String(e));
|
|
76
|
+
loaded.set(grammar, failure);
|
|
77
|
+
throw failure;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** A short parse proves the grammar works before it is advertised as ready. */
|
|
81
|
+
export async function verifyGrammar(grammar) {
|
|
82
|
+
try {
|
|
83
|
+
const { parser } = await load(grammar);
|
|
84
|
+
const tree = parser.parse('x');
|
|
85
|
+
if (!tree)
|
|
86
|
+
return { ok: false, detail: '空の構文木が返った' };
|
|
87
|
+
tree.delete();
|
|
88
|
+
return { ok: true };
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
return { ok: false, detail: e instanceof Error ? e.message : String(e) };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const MAX_STRUCTURE_NODES = 400;
|
|
95
|
+
function describeDeclaration(name) {
|
|
96
|
+
let declaration = name.parent ?? name;
|
|
97
|
+
if (['variable_declarator', 'start_tag', 'function_declarator'].includes(declaration.type)) {
|
|
98
|
+
declaration = declaration.parent ?? declaration;
|
|
99
|
+
}
|
|
100
|
+
const kind = declaration.type;
|
|
101
|
+
const range = declaration.parent?.type === 'export_statement' ? declaration.parent : declaration;
|
|
102
|
+
return {
|
|
103
|
+
kind, name: name.text.slice(0, 200),
|
|
104
|
+
startLine: name.startPosition.row + 1,
|
|
105
|
+
startColumn: name.startPosition.column + 1,
|
|
106
|
+
endLine: name.endPosition.row + 1,
|
|
107
|
+
endColumn: name.endPosition.column + 1,
|
|
108
|
+
declaration: {
|
|
109
|
+
startLine: range.startPosition.row + 1,
|
|
110
|
+
startColumn: range.startPosition.column + 1,
|
|
111
|
+
endLine: range.endPosition.row + 1,
|
|
112
|
+
endColumn: range.endPosition.column + 1,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export async function outline(grammar, source, options = {}) {
|
|
117
|
+
const query = definitionQuery(grammar);
|
|
118
|
+
if (!query)
|
|
119
|
+
return { status: 'unsupported', language: grammar, detail: 'この言語の構造抽出は未対応' };
|
|
120
|
+
let tree;
|
|
121
|
+
let matcher;
|
|
122
|
+
try {
|
|
123
|
+
const bundle = await load(grammar);
|
|
124
|
+
tree = bundle.parser.parse(source);
|
|
125
|
+
if (!tree)
|
|
126
|
+
return { status: 'error', language: grammar, detail: '構文木を作成できなかった' };
|
|
127
|
+
matcher = new Query(bundle.language, query);
|
|
128
|
+
const nodes = [];
|
|
129
|
+
let truncated = false;
|
|
130
|
+
for (const capture of matcher.captures(tree.rootNode)) {
|
|
131
|
+
if (options.nameIncludes && !capture.node.text.includes(options.nameIncludes))
|
|
132
|
+
continue;
|
|
133
|
+
if (nodes.length >= MAX_STRUCTURE_NODES) {
|
|
134
|
+
truncated = true;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
nodes.push(describeDeclaration(capture.node));
|
|
138
|
+
}
|
|
139
|
+
return { status: 'ok', language: grammar, nodes, truncated, errorCount: countErrors(tree.rootNode) };
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
return { status: 'error', language: grammar, detail: e instanceof Error ? e.message : String(e) };
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
matcher?.delete();
|
|
146
|
+
tree?.delete();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function countErrors(node, budget = 5000) {
|
|
150
|
+
const stack = [node];
|
|
151
|
+
let count = 0, visited = 0;
|
|
152
|
+
while (stack.length && visited < budget) {
|
|
153
|
+
const current = stack.pop();
|
|
154
|
+
visited++;
|
|
155
|
+
if (!current.hasError)
|
|
156
|
+
continue;
|
|
157
|
+
count++;
|
|
158
|
+
for (let i = 0; i < current.childCount; i++)
|
|
159
|
+
stack.push(current.child(i));
|
|
160
|
+
}
|
|
161
|
+
return count;
|
|
162
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Only accept a package argument from the installed official README, never shell text. */
|
|
2
|
+
export declare function recommendedTypescript(readme: string): string | undefined;
|
|
3
|
+
export declare function probeTypescript(prefix: string, signal?: AbortSignal): Promise<{
|
|
4
|
+
version: string;
|
|
5
|
+
apiSha256: string;
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { executeBounded, privateEnvironment, sha256 } from "../lisp/runtime.js";
|
|
4
|
+
/** Only accept a package argument from the installed official README, never shell text. */
|
|
5
|
+
export function recommendedTypescript(readme) {
|
|
6
|
+
const candidates = [...readme.matchAll(/\bnpm install[^\r\n]*\btypescript-language-server\b[^\r\n]*\btypescript@([0-9]+(?:\.[0-9x*]+){0,2})(?=\s|$)/gm)].map(match => `typescript@${match[1]}`);
|
|
7
|
+
return new Set(candidates).size === 1 ? candidates[0] : undefined;
|
|
8
|
+
}
|
|
9
|
+
const probe = String.raw `
|
|
10
|
+
const {createRequire}=require('node:module');
|
|
11
|
+
const ts=createRequire(process.argv[1])(process.argv[1]);
|
|
12
|
+
if(typeof ts.createLanguageService!=='function'||typeof ts.ScriptSnapshot?.fromString!=='function')throw Error('Missing language service API');
|
|
13
|
+
const text='const answer: number = "wrong";';
|
|
14
|
+
const service=ts.createLanguageService({
|
|
15
|
+
getScriptFileNames:()=>['probe.ts'],getScriptVersion:()=> '1',
|
|
16
|
+
getScriptSnapshot:f=>f==='probe.ts'?ts.ScriptSnapshot.fromString(text):undefined,
|
|
17
|
+
getCurrentDirectory:()=>process.cwd(),getCompilationSettings:()=>({noLib:true,strict:true}),
|
|
18
|
+
getDefaultLibFileName:()=>'',fileExists:f=>f==='probe.ts',readFile:()=>undefined
|
|
19
|
+
});
|
|
20
|
+
try{if(!service.getSemanticDiagnostics('probe.ts').some(d=>d.code===2322))throw Error('Type mismatch diagnostic missing');}
|
|
21
|
+
finally{service.dispose();}
|
|
22
|
+
process.stdout.write('MODKH_TYPESCRIPT_API_OK');
|
|
23
|
+
`;
|
|
24
|
+
export async function probeTypescript(prefix, signal) {
|
|
25
|
+
const api = path.join(prefix, 'node_modules/typescript/lib/typescript.js');
|
|
26
|
+
const bytes = fs.readFileSync(api);
|
|
27
|
+
const home = path.join(prefix, '.typescript-probe');
|
|
28
|
+
fs.mkdirSync(home, { mode: 0o700 });
|
|
29
|
+
try {
|
|
30
|
+
const result = await executeBounded(process.execPath, ['-e', probe, api], {
|
|
31
|
+
cwd: home, env: privateEnvironment(home), inputDigest: sha256(bytes), timeoutMs: 10000, signal,
|
|
32
|
+
});
|
|
33
|
+
if (result.state !== 'exited' || result.exitCode !== 0 || result.stdout !== 'MODKH_TYPESCRIPT_API_OK') {
|
|
34
|
+
throw new Error(`TypeScript language service capability failed (${result.state}): ${result.stderr.slice(-500)}`);
|
|
35
|
+
}
|
|
36
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(prefix, 'node_modules/typescript/package.json'), 'utf8'));
|
|
37
|
+
return { version: String(manifest.version), apiSha256: sha256(bytes) };
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type SessionDefinition } from './config.ts';
|
|
2
|
+
/** Use the same role validation and tool limits as explicitly configured Lisp agents. */
|
|
3
|
+
export declare function builtinMicroagents(): readonly SessionDefinition[];
|
|
4
|
+
/** Native checker is detected by the host; the agent cannot select an executable. */
|
|
5
|
+
export declare function staterightMicroagent(): SessionDefinition;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { validateDefinitions } from "./config.js";
|
|
2
|
+
import { sha256 } from "./runtime.js";
|
|
3
|
+
const LANGUAGES = ['php', 'common-lisp', 'js', 'ts', 'svelte', 'html', 'css'];
|
|
4
|
+
const OBSERVATION_TOOLS = {
|
|
5
|
+
outline: 'code_outline',
|
|
6
|
+
'syntax-search': 'code_syntax_search',
|
|
7
|
+
definition: 'code_definition',
|
|
8
|
+
references: 'code_references',
|
|
9
|
+
diagnostics: 'code_diagnostics',
|
|
10
|
+
hover: 'code_hover',
|
|
11
|
+
};
|
|
12
|
+
function observationRole(language, taskKind) {
|
|
13
|
+
return {
|
|
14
|
+
id: `micro-${language}-${taskKind}`,
|
|
15
|
+
title: `${language} ${taskKind}`,
|
|
16
|
+
language,
|
|
17
|
+
'task-kind': taskKind,
|
|
18
|
+
tool: OBSERVATION_TOOLS[taskKind],
|
|
19
|
+
instruction: taskKind === 'syntax-search'
|
|
20
|
+
? `${language} の宣言検索担当。指定ファイル一件と宣言名を code_syntax_search に渡し、候補のファイルと宣言全体の範囲を返す。`
|
|
21
|
+
: `${language} の ${taskKind} 担当。指定対象を実ツールで調べ、根拠と未確認事項を返す。`,
|
|
22
|
+
enabled: true,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
let builtins;
|
|
26
|
+
/** Use the same role validation and tool limits as explicitly configured Lisp agents. */
|
|
27
|
+
export function builtinMicroagents() {
|
|
28
|
+
if (builtins)
|
|
29
|
+
return builtins;
|
|
30
|
+
const roles = LANGUAGES.flatMap(language => ['outline', 'definition', 'references', 'diagnostics'].map(kind => observationRole(language, kind)));
|
|
31
|
+
roles.push(...['php', 'js', 'ts', 'html', 'css'].map(language => observationRole(language, 'syntax-search')), observationRole('tailwindcss', 'hover'), observationRole('tailwindcss', 'diagnostics'));
|
|
32
|
+
builtins = validateDefinitions(roles, '').map(({ descriptor, definition }) => ({
|
|
33
|
+
descriptor: {
|
|
34
|
+
...descriptor, id: `modkh-${descriptor.id}`, version: 'builtin', builtin: true,
|
|
35
|
+
digest: sha256(JSON.stringify({ descriptor, definition })),
|
|
36
|
+
},
|
|
37
|
+
definition,
|
|
38
|
+
}));
|
|
39
|
+
return builtins;
|
|
40
|
+
}
|
|
41
|
+
let zenki;
|
|
42
|
+
/** Native checker is detected by the host; the agent cannot select an executable. */
|
|
43
|
+
export function staterightMicroagent() {
|
|
44
|
+
if (!zenki) {
|
|
45
|
+
const entry = validateDefinitions([{ id: 'micro-zenki', title: '前鬼(Stateright)', tool: 'verify_stateright',
|
|
46
|
+
language: 'stateright', 'task-kind': 'verify', enabled: true,
|
|
47
|
+
instruction: '指定された有限状態JSONモデル一件をverify_staterightで検査する。探索範囲、不変条件、反例、未確認事項を報告する。モデルの検査を実装全体の証明と扱わない。' }], '')[0];
|
|
48
|
+
zenki = { definition: entry.definition, descriptor: { ...entry.descriptor, id: 'modkh-micro-zenki', builtin: true,
|
|
49
|
+
version: 'builtin', digest: sha256(JSON.stringify(entry)) } };
|
|
50
|
+
}
|
|
51
|
+
return zenki;
|
|
52
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LocalDefinition, PluginDescriptor } from '../plugins/api.ts';
|
|
2
|
+
export interface SessionDefinition {
|
|
3
|
+
descriptor: PluginDescriptor;
|
|
4
|
+
definition: LocalDefinition;
|
|
5
|
+
}
|
|
6
|
+
export interface HeadChecks {
|
|
7
|
+
inputs?: {
|
|
8
|
+
model: string;
|
|
9
|
+
lean: string;
|
|
10
|
+
editor?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface LispConfiguration {
|
|
14
|
+
digest: string;
|
|
15
|
+
entries: SessionDefinition[];
|
|
16
|
+
headInstruction?: string;
|
|
17
|
+
headChecks?: HeadChecks;
|
|
18
|
+
}
|
|
19
|
+
export declare const REQUIRED_SKILLS: readonly ["kiokuko-single-purpose-functions", "one-shot-software-completion"];
|
|
20
|
+
export declare function validateDefinitions(raw: unknown, digest: string): SessionDefinition[];
|
|
21
|
+
export declare function loadLispConfiguration(file: string, trustedDigest: string, options?: {
|
|
22
|
+
sbcl?: string;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
}): Promise<LispConfiguration>;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { readBundledSkill, MODKH_SKILL_BINDING } from "../agent/bundled-skills.js";
|
|
4
|
+
import { executeBounded, privateEnvironment, temporaryDirectory, sha256 } from "./runtime.js";
|
|
5
|
+
const TOOLS = new Set(['code_outline', 'code_syntax_search', 'code_definition', 'code_references', 'code_diagnostics', 'code_hover', 'edit_file', 'verify_stateright', 'verify_lean']);
|
|
6
|
+
const LANGUAGES = new Set(['php', 'common-lisp', 'js', 'ts', 'svelte', 'tailwindcss', 'html', 'css', 'stateright', 'lean']);
|
|
7
|
+
const KINDS = new Set(['outline', 'syntax-search', 'definition', 'references', 'diagnostics', 'hover', 'edit', 'verify']);
|
|
8
|
+
export const REQUIRED_SKILLS = ['kiokuko-single-purpose-functions', 'one-shot-software-completion'];
|
|
9
|
+
function string(value, name, max) {
|
|
10
|
+
if (typeof value !== 'string' || !value.trim() || Buffer.byteLength(value) > max || /[\x00-\x08\x0b\x0c\x0e-\x1f]/.test(value))
|
|
11
|
+
throw new Error(`Invalid ${name}`);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function paths(value) {
|
|
15
|
+
if (!Array.isArray(value) || !value.length || value.length > 128 || !value.every(v => typeof v === 'string' && v.length < 1024 && !path.isAbsolute(v) && !v.split(/[\\/]/).some((p) => !p || p === '.' || p === '..')))
|
|
16
|
+
throw new Error('Invalid verification manifest paths');
|
|
17
|
+
if (new Set(value).size !== value.length)
|
|
18
|
+
throw new Error('Duplicate manifest path');
|
|
19
|
+
return [...value];
|
|
20
|
+
}
|
|
21
|
+
export function validateDefinitions(raw, digest) {
|
|
22
|
+
if (!Array.isArray(raw) || raw.length > 64)
|
|
23
|
+
throw new Error('Expected at most 64 definitions');
|
|
24
|
+
const ids = new Set();
|
|
25
|
+
const skills = REQUIRED_SKILLS.map(name => `\n\n--- ${name} (full SKILL.md) ---\n${readBundledSkill(name, 'SKILL.md', false)}`).join('');
|
|
26
|
+
return raw.map(row => {
|
|
27
|
+
if (!row || typeof row !== 'object' || Array.isArray(row))
|
|
28
|
+
throw new Error('Invalid definition');
|
|
29
|
+
const allowed = ['id', 'title', 'tool', 'language', 'task-kind', 'instruction', 'max-turns', 'enabled', 'workflow', 'check', 'sources', 'protected'];
|
|
30
|
+
if (Object.keys(row).some(key => !allowed.includes(key)))
|
|
31
|
+
throw new Error('Unknown definition field');
|
|
32
|
+
const id = string(row.id, 'id', 64);
|
|
33
|
+
if (!/^micro-[a-z0-9]+(?:-[a-z0-9]+)*$/.test(id) || ids.has(id))
|
|
34
|
+
throw new Error('Duplicate or unsafe microagent ID');
|
|
35
|
+
ids.add(id);
|
|
36
|
+
const tool = string(row.tool, 'tool', 64);
|
|
37
|
+
if (!TOOLS.has(tool))
|
|
38
|
+
throw new Error(`Unknown tool: ${tool}`);
|
|
39
|
+
const language = row.language ?? '';
|
|
40
|
+
const taskKind = row['task-kind'] ?? '';
|
|
41
|
+
if (language && !LANGUAGES.has(language))
|
|
42
|
+
throw new Error('Unknown language');
|
|
43
|
+
if (taskKind && !KINDS.has(taskKind))
|
|
44
|
+
throw new Error('Unknown task kind');
|
|
45
|
+
const maxTurns = row['max-turns'] ?? 4;
|
|
46
|
+
if (!Number.isInteger(maxTurns) || maxTurns < 1 || maxTurns > 32)
|
|
47
|
+
throw new Error('max-turns must be 1..32');
|
|
48
|
+
if (typeof row.enabled !== 'boolean')
|
|
49
|
+
throw new Error('Invalid enabled flag');
|
|
50
|
+
if (row.workflow && row.workflow !== 'edit-verify')
|
|
51
|
+
throw new Error('Unknown workflow');
|
|
52
|
+
if ((tool === 'edit_file') !== (row.workflow === 'edit-verify'))
|
|
53
|
+
throw new Error('edit_file requires edit-verify workflow');
|
|
54
|
+
if (row.check && row.workflow !== 'edit-verify')
|
|
55
|
+
throw new Error('Only edit workflows accept checks');
|
|
56
|
+
const instruction = string(row.instruction, 'instruction', 8192);
|
|
57
|
+
const definition = {
|
|
58
|
+
system: `MoDKH microagent ${id}. ${row.workflow ? 'Edit only the explicit owner-approved source snapshots. Never change the verifier.' : 'Observe only using your assigned tools.'} Host/parent owns final acceptance. Skills do not add tools or authority. Unread references are not evidence.\n${MODKH_SKILL_BINDING}\n${instruction}${skills}`,
|
|
59
|
+
tools: tool === 'edit_file' ? ['read_file', 'edit_file'] : [tool],
|
|
60
|
+
skillPolicy: 'none', maxTurns, requireAllTools: true,
|
|
61
|
+
...(language === 'tailwindcss' ? { languageServer: 'tailwind' } : {}),
|
|
62
|
+
...(row.workflow ? { workflow: 'edit-verify' } : {}),
|
|
63
|
+
};
|
|
64
|
+
if (row.check)
|
|
65
|
+
definition.verificationCommand = string(row.check, 'check', 4096);
|
|
66
|
+
if (row.sources || row.protected) {
|
|
67
|
+
definition.verificationManifest = { sources: paths(row.sources), protected: paths(row.protected) };
|
|
68
|
+
if (definition.verificationManifest.sources.some(p => definition.verificationManifest.protected.includes(p)))
|
|
69
|
+
throw new Error('Source and verifier paths overlap');
|
|
70
|
+
}
|
|
71
|
+
return { descriptor: { apiVersion: 1, id, version: 'session', title: row.title ? string(row.title, 'title', 256) : id,
|
|
72
|
+
description: instruction, kind: 'local', entry: '', digest, builtin: false,
|
|
73
|
+
capabilities: [...definition.tools], enabled: row.enabled && (tool !== 'edit_file' || !!(definition.verificationCommand && definition.verificationManifest)), language, taskKind }, definition };
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
// This is Common Lisp evaluated by SBCL, not an S-expression parser in JavaScript.
|
|
77
|
+
function validateHeadChecks(value, entries) {
|
|
78
|
+
if (value === null)
|
|
79
|
+
return undefined;
|
|
80
|
+
for (const [id, tool] of [['micro-zenki', 'verify_stateright'], ['micro-goki', 'verify_lean']]) {
|
|
81
|
+
if (!entries.some(entry => entry.descriptor.id === id && entry.definition.tools.includes(tool))) {
|
|
82
|
+
throw new Error(`Head checks require ${id} with ${tool}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (value === true)
|
|
86
|
+
return {};
|
|
87
|
+
if (!Array.isArray(value) || value.length < 2 || value.length > 3)
|
|
88
|
+
throw new Error('Invalid head check inputs');
|
|
89
|
+
const [model, lean] = paths(value.slice(0, 2));
|
|
90
|
+
if (path.extname(model) !== '.json' || path.extname(lean) !== '.lean') {
|
|
91
|
+
throw new Error('Head check inputs must be a model .json and .lean file (TLA/config inputs must be migrated)');
|
|
92
|
+
}
|
|
93
|
+
const editor = value[2];
|
|
94
|
+
if (editor !== undefined && !entries.some(entry => entry.descriptor.id === editor &&
|
|
95
|
+
entry.descriptor.enabled && entry.definition.verificationManifest?.sources.length === 1)) {
|
|
96
|
+
throw new Error('Head check editor must have exactly one owner-configured source');
|
|
97
|
+
}
|
|
98
|
+
return { inputs: { model, lean, ...(typeof editor === 'string' ? { editor } : {}) } };
|
|
99
|
+
}
|
|
100
|
+
const DRIVER = String.raw `
|
|
101
|
+
(defpackage :modkh (:use :cl) (:export :defmicroagent :register-agent :disable-agent :remove-agent :list-agents :set-agent-check :set-head-instruction :require-head-checks :set-head-check-inputs))
|
|
102
|
+
(in-package :modkh)
|
|
103
|
+
(defvar *agents* (make-hash-table :test 'equal))
|
|
104
|
+
(defvar *head-instruction* nil)
|
|
105
|
+
(defvar *head-checks* nil)
|
|
106
|
+
(defun require-head-checks () (setf *head-checks* t))
|
|
107
|
+
(defun set-head-check-inputs (model lean &optional editor)
|
|
108
|
+
(setf *head-checks* (if editor (list model lean editor) (list model lean))))
|
|
109
|
+
(defun set-head-instruction (instruction)
|
|
110
|
+
(check-type instruction string)
|
|
111
|
+
(setf *head-instruction* instruction))
|
|
112
|
+
(defun agent-id (id) (string-downcase (string id)))
|
|
113
|
+
(defun register-agent (id &rest fields)
|
|
114
|
+
(setf id (agent-id id))
|
|
115
|
+
(when (gethash id *agents*) (error "Duplicate agent: ~a" id))
|
|
116
|
+
(unless (evenp (length fields)) (error "Odd keyword list"))
|
|
117
|
+
(loop for (key value) on fields by #'cddr
|
|
118
|
+
unless (member key '(:title :tool :language :task-kind :instruction :max-turns :workflow)) do (error "Unknown field: ~a" key))
|
|
119
|
+
(let ((keys (loop for (key value) on fields by #'cddr collect key)))
|
|
120
|
+
(unless (= (length keys) (length (remove-duplicates keys))) (error "Duplicate field")))
|
|
121
|
+
(when (>= (hash-table-count *agents*) 64) (error "Too many agents"))
|
|
122
|
+
(setf (gethash id *agents*) (append (list :id id :enabled t) fields)) id)
|
|
123
|
+
(defmacro defmicroagent (id &rest fields) (list* 'register-agent (list 'quote id) fields))
|
|
124
|
+
(defun disable-agent (id) (let ((row (gethash (agent-id id) *agents*))) (unless row (error "Unknown agent")) (setf (getf row :enabled) nil)))
|
|
125
|
+
(defun remove-agent (id) (remhash (agent-id id) *agents*))
|
|
126
|
+
(defun list-agents () (loop for row being the hash-values of *agents* collect (copy-tree row)))
|
|
127
|
+
(defun set-agent-check (id command &key sources protected)
|
|
128
|
+
(let ((row (gethash (agent-id id) *agents*)))
|
|
129
|
+
(unless row (error "Unknown agent"))
|
|
130
|
+
(setf (getf row :check) command (getf row :sources) sources (getf row :protected) protected
|
|
131
|
+
(gethash (agent-id id) *agents*) row)))
|
|
132
|
+
(defun json-string (value out)
|
|
133
|
+
(write-char #\" out)
|
|
134
|
+
(loop for c across value do
|
|
135
|
+
(case c (#\" (write-string "\\\"" out)) (#\\ (write-string "\\\\" out))
|
|
136
|
+
(#\Newline (write-string "\\n" out)) (#\Return (write-string "\\r" out)) (#\Tab (write-string "\\t" out))
|
|
137
|
+
(otherwise (if (< (char-code c) 32) (format out "\\u~4,'0x" (char-code c)) (write-char c out)))))
|
|
138
|
+
(write-char #\" out))
|
|
139
|
+
(defun json-value (value out)
|
|
140
|
+
(cond ((null value) (write-string "null" out)) ((eq value t) (write-string "true" out))
|
|
141
|
+
((stringp value) (json-string value out)) ((integerp value) (princ value out))
|
|
142
|
+
((listp value) (write-char #\[ out) (loop for v in value for i from 0 do (when (> i 0) (write-char #\, out)) (json-value v out)) (write-char #\] out))
|
|
143
|
+
(t (error "Non-JSON value"))))
|
|
144
|
+
(let ((protocol *standard-output*))
|
|
145
|
+
(let ((*standard-output* (make-broadcast-stream)) (*trace-output* (make-broadcast-stream))
|
|
146
|
+
(*error-output* (make-broadcast-stream)) (*terminal-io* (make-two-way-stream (make-string-input-stream "") (make-broadcast-stream))))
|
|
147
|
+
(load "input.lisp" :verbose nil :print nil))
|
|
148
|
+
(write-string "{\"headInstruction\":" protocol)
|
|
149
|
+
(json-value *head-instruction* protocol)
|
|
150
|
+
(write-string ",\"headChecks\":" protocol)
|
|
151
|
+
(json-value *head-checks* protocol)
|
|
152
|
+
(write-string ",\"entries\":[" protocol)
|
|
153
|
+
(loop for row being the hash-values of *agents* for i from 0 do
|
|
154
|
+
(when (> i 0) (write-char #\, protocol)) (write-char #\{ protocol)
|
|
155
|
+
(loop for (key value) on row by #'cddr for j from 0 do
|
|
156
|
+
(when (> j 0) (write-char #\, protocol)) (json-string (string-downcase (symbol-name key)) protocol) (write-char #\: protocol)
|
|
157
|
+
(if (eq key :enabled) (write-string (if value "true" "false") protocol) (json-value value protocol)))
|
|
158
|
+
(write-char #\} protocol))
|
|
159
|
+
(write-string "]}" protocol) (finish-output protocol))
|
|
160
|
+
`;
|
|
161
|
+
export async function loadLispConfiguration(file, trustedDigest, options = {}) {
|
|
162
|
+
if (!/^[a-f0-9]{64}$/.test(trustedDigest))
|
|
163
|
+
throw new Error('Explicit --trust-lisp-sha256 required');
|
|
164
|
+
const fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
|
165
|
+
let bytes;
|
|
166
|
+
try {
|
|
167
|
+
const stat = fs.fstatSync(fd);
|
|
168
|
+
if (!stat.isFile() || stat.size > 64 * 1024)
|
|
169
|
+
throw new Error('Lisp input must be a file of at most 64 KiB');
|
|
170
|
+
bytes = fs.readFileSync(fd);
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
fs.closeSync(fd);
|
|
174
|
+
}
|
|
175
|
+
if (bytes.length > 64 * 1024 || sha256(bytes) !== trustedDigest)
|
|
176
|
+
throw new Error('Lisp trust digest mismatch; not evaluated');
|
|
177
|
+
const dir = temporaryDirectory('modkh-lisp-');
|
|
178
|
+
let settled = true;
|
|
179
|
+
try {
|
|
180
|
+
fs.writeFileSync(path.join(dir, 'input.lisp'), bytes, { flag: 'wx', mode: 0o600 });
|
|
181
|
+
fs.writeFileSync(path.join(dir, 'driver.lisp'), DRIVER, { flag: 'wx', mode: 0o600 });
|
|
182
|
+
const receipt = await executeBounded(options.sbcl ?? 'sbcl', ['--noinform', '--no-sysinit', '--no-userinit', '--disable-debugger', '--script', 'driver.lisp'], {
|
|
183
|
+
cwd: dir, env: privateEnvironment(dir), inputDigest: trustedDigest, timeoutMs: Math.min(options.timeoutMs ?? 10000, 10000), signal: options.signal,
|
|
184
|
+
});
|
|
185
|
+
settled = receipt.cleanup === 'settled';
|
|
186
|
+
if (receipt.state !== 'exited' || receipt.exitCode !== 0)
|
|
187
|
+
throw new Error(`Lisp evaluation ${receipt.state}/${receipt.exitCode}: ${receipt.stderr.slice(0, 4096)}`);
|
|
188
|
+
const { entries, headInstruction, headChecks } = JSON.parse(receipt.stdout);
|
|
189
|
+
const definitions = validateDefinitions(entries, trustedDigest);
|
|
190
|
+
const checks = validateHeadChecks(headChecks, definitions);
|
|
191
|
+
return {
|
|
192
|
+
digest: trustedDigest,
|
|
193
|
+
entries: definitions,
|
|
194
|
+
...(checks ? { headChecks: checks } : {}),
|
|
195
|
+
...(headInstruction === null ? {} : { headInstruction: string(headInstruction, 'head instruction', 8192) }),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
finally {
|
|
199
|
+
if (settled)
|
|
200
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PluginDescriptor } from '../plugins/api.ts';
|
|
2
|
+
import type { DelegationRequest } from '../subagents/types.ts';
|
|
3
|
+
/** Conservative opt-in rules, never described as LLM judgment. Ambiguity delegates nothing. */
|
|
4
|
+
export declare function routeIntent(task: string, available: PluginDescriptor[]): DelegationRequest | undefined;
|
|
5
|
+
export declare function routeRole(language: string, taskKind: string, task: string, available: PluginDescriptor[]): DelegationRequest | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const EXT = { php: 'php', lisp: 'common-lisp', cl: 'common-lisp', asd: 'common-lisp', js: 'js', mjs: 'js', ts: 'ts', mts: 'ts', svelte: 'svelte', html: 'html', css: 'css', json: 'stateright', lean: 'lean' };
|
|
2
|
+
/** Conservative opt-in rules, never described as LLM judgment. Ambiguity delegates nothing. */
|
|
3
|
+
export function routeIntent(task, available) {
|
|
4
|
+
if (/\b(if|unless|not|don't|without|maybe|or)\b|しない|するな|不要|なら|場合|もし|または|https?:|\.\.|[\\]/i.test(task))
|
|
5
|
+
return;
|
|
6
|
+
const files = [...task.matchAll(/(?:^|\s|`)([A-Za-z0-9_-]+(?:\/[A-Za-z0-9_.-]+)*\.[a-z]+)(?=$|\s|`|[、。])/g)].map(m => m[1]);
|
|
7
|
+
if (files.length !== 1)
|
|
8
|
+
return;
|
|
9
|
+
const language = EXT[files[0].split('.').at(-1)];
|
|
10
|
+
if (!language)
|
|
11
|
+
return;
|
|
12
|
+
const rules = [['outline', /\b(outline|structure)\b|構造/], ['syntax-search', /\bsyntax search\b|構文検索|宣言検索/], ['definition', /\bdefinition\b|定義/], ['references', /\breferences\b|参照/], ['diagnostics', /\bdiagnostics\b|診断/], ['hover', /\bhover\b|ホバー/], ['edit', /\b(edit|fix|change)\b|修正|編集/], ['verify', /\bverify\b|検証/]];
|
|
13
|
+
const kinds = rules.filter(([, re]) => re.test(task));
|
|
14
|
+
if (kinds.length !== 1)
|
|
15
|
+
return;
|
|
16
|
+
const matches = available.filter(d => d.language === language && d.taskKind === kinds[0][0]);
|
|
17
|
+
if (matches.length !== 1)
|
|
18
|
+
return;
|
|
19
|
+
return { pluginId: matches[0].id, task, ...(kinds[0][0] === 'edit' ? { targetPaths: files } : {}) };
|
|
20
|
+
}
|
|
21
|
+
export function routeRole(language, taskKind, task, available) {
|
|
22
|
+
const matches = available.filter(d => d.language === language && d.taskKind === taskKind);
|
|
23
|
+
return matches.length === 1 && taskKind !== 'edit' ? { pluginId: matches[0].id, task } : undefined;
|
|
24
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const sha256: (bytes: string | Buffer) => string;
|
|
2
|
+
export interface ExecutionReceipt {
|
|
3
|
+
state: 'exited' | 'aborted' | 'timed-out' | 'not-started' | 'output-limit' | 'unknown';
|
|
4
|
+
exitCode: number | null;
|
|
5
|
+
signal: string | null;
|
|
6
|
+
stdout: string;
|
|
7
|
+
stderr: string;
|
|
8
|
+
inputDigest: string;
|
|
9
|
+
cleanup: 'settled' | 'unknown';
|
|
10
|
+
outputBytes?: number;
|
|
11
|
+
outputTruncated?: boolean;
|
|
12
|
+
terminationReason?: 'aborted' | 'timed-out' | 'output-limit' | 'unknown';
|
|
13
|
+
}
|
|
14
|
+
export declare function privateEnvironment(home: string): NodeJS.ProcessEnv;
|
|
15
|
+
export declare function temporaryDirectory(prefix: string): string;
|
|
16
|
+
/** shell:false, bounded pipes and owned POSIX process group. Escaped sessions are not a sandbox. */
|
|
17
|
+
export declare function executeBounded(command: string, args: string[], options: {
|
|
18
|
+
cwd: string;
|
|
19
|
+
env: NodeJS.ProcessEnv;
|
|
20
|
+
inputDigest: string;
|
|
21
|
+
timeoutMs: number;
|
|
22
|
+
maxOutputBytes?: number;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
/** Trusted verbose builds may retain a bounded tail instead of being killed. */
|
|
25
|
+
outputOverflow?: 'stop' | 'tail';
|
|
26
|
+
}): Promise<ExecutionReceipt>;
|