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
|
@@ -24,16 +24,42 @@ export class LanguageService {
|
|
|
24
24
|
this.pool = options.pool ?? new ServerPool({ requestTimeoutMs: options.settings.requestTimeoutMs });
|
|
25
25
|
}
|
|
26
26
|
get poolSize() { return this.pool.size; }
|
|
27
|
-
/**
|
|
27
|
+
/** Running language servers, for display. Callers must not infer readiness from this list. */
|
|
28
|
+
runningServers() { return this.pool.running(); }
|
|
29
|
+
/** The ready server for a file, if its server target was analyzed before. */
|
|
28
30
|
poolFor(file, selector) {
|
|
29
31
|
const detection = this.detect(file);
|
|
30
32
|
if (!detection)
|
|
31
33
|
return undefined;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
const language = selector ? languageById(selector) : detection.language;
|
|
35
|
+
if (this.settings.disabled.includes(language.id))
|
|
36
|
+
return undefined;
|
|
37
|
+
const target = this.serverTarget(language, detection);
|
|
38
|
+
return this.pool.find(this.preferredRoot(target), target.language.id, target.configDigest);
|
|
35
39
|
}
|
|
36
40
|
detect(file) { return detectLanguage(file, this.root); }
|
|
41
|
+
serverTarget(language, detection) {
|
|
42
|
+
const { servers, disabled } = this.settings;
|
|
43
|
+
const configDigest = JSON.stringify(servers[language.id] ?? null);
|
|
44
|
+
const projectRoot = realRoot(detection.root);
|
|
45
|
+
if (language.id !== 'typescript' && language.id !== 'tsx') {
|
|
46
|
+
return { root: projectRoot, language, configDigest };
|
|
47
|
+
}
|
|
48
|
+
// tsserver discovers individual tsconfig projects inside the LSP workspace.
|
|
49
|
+
const shareTypeScript = language.id === 'tsx' && !disabled.includes('typescript')
|
|
50
|
+
&& configDigest === JSON.stringify(servers.typescript ?? null);
|
|
51
|
+
return {
|
|
52
|
+
root: this.root,
|
|
53
|
+
language: shareTypeScript ? languageById('typescript') : language,
|
|
54
|
+
configDigest,
|
|
55
|
+
...(projectRoot !== this.root ? { fallbackRoot: projectRoot } : {}),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
preferredRoot(target) {
|
|
59
|
+
// Keep using an established project-local server for analysis and navigation alike.
|
|
60
|
+
const { fallbackRoot, root, language, configDigest } = target;
|
|
61
|
+
return fallbackRoot && this.pool.find(fallbackRoot, language.id, configDigest) ? fallbackRoot : root;
|
|
62
|
+
}
|
|
37
63
|
/** Analyze a file after a read or a successful write. Never throws. */
|
|
38
64
|
async analyze(file, text, signal, selector) {
|
|
39
65
|
try {
|
|
@@ -56,24 +82,30 @@ export class LanguageService {
|
|
|
56
82
|
if (this.settings.disabled.includes(language.id)) {
|
|
57
83
|
return { status: 'unavailable', language: language.id, detail: `${language.id} は設定で無効` };
|
|
58
84
|
}
|
|
59
|
-
const
|
|
85
|
+
const target = this.serverTarget(language, detection);
|
|
86
|
+
const key = `${target.root}::${language.id}::${file}::${text}`;
|
|
60
87
|
const running = this.inflight.get(key);
|
|
61
88
|
if (running)
|
|
62
89
|
return running;
|
|
63
|
-
const work = this.analyzeOnce(
|
|
90
|
+
const work = this.analyzeOnce(target, language.id, file, text, signal).finally(() => this.inflight.delete(key));
|
|
64
91
|
this.inflight.set(key, work);
|
|
65
92
|
return work;
|
|
66
93
|
}
|
|
67
|
-
async analyzeOnce(
|
|
94
|
+
async analyzeOnce(target, languageId, file, text, signal) {
|
|
95
|
+
const { language } = target;
|
|
68
96
|
const configured = this.settings.servers[language.id];
|
|
69
|
-
|
|
97
|
+
let resolved = resolveServer(language, configured ? { server: configured } : {});
|
|
98
|
+
// Older installations may have the same server installed under the TSX recipe.
|
|
99
|
+
if (resolved.status === 'missing' && language.id === 'typescript' && !configured && !this.settings.servers.tsx) {
|
|
100
|
+
resolved = resolveServer(languageById('tsx'), {});
|
|
101
|
+
}
|
|
70
102
|
let launch = resolved.status === 'ready' && resolved.command
|
|
71
103
|
? { command: resolved.command, args: resolved.args ?? [] }
|
|
72
104
|
: undefined;
|
|
73
105
|
let installed = false;
|
|
74
106
|
if (!launch) {
|
|
75
107
|
if (!this.settings.autoInstall) {
|
|
76
|
-
return { status: 'unavailable', language:
|
|
108
|
+
return { status: 'unavailable', language: languageId, detail: resolved.detail ?? 'サーバー未導入(自動導入は無効)' };
|
|
77
109
|
}
|
|
78
110
|
this.progress?.(`${language.id} の言語サーバーを準備しています(初回のみ)…`);
|
|
79
111
|
const outcome = await ensureInstalled(language, {
|
|
@@ -82,30 +114,34 @@ export class LanguageService {
|
|
|
82
114
|
...(signal ? { signal } : {}),
|
|
83
115
|
});
|
|
84
116
|
if (outcome.status !== 'ready') {
|
|
85
|
-
return { status: 'unavailable', language:
|
|
117
|
+
return { status: 'unavailable', language: languageId, detail: outcome.detail ?? 'サーバーを準備できません' };
|
|
86
118
|
}
|
|
87
119
|
installed = true;
|
|
88
120
|
const after = resolveServer(language, {});
|
|
89
121
|
if (after.status !== 'ready' || !after.command) {
|
|
90
|
-
return { status: 'unavailable', language:
|
|
122
|
+
return { status: 'unavailable', language: languageId, detail: '導入後にサーバーを解決できない' };
|
|
91
123
|
}
|
|
92
124
|
launch = { command: after.command, args: after.args ?? [] };
|
|
93
125
|
}
|
|
94
|
-
const
|
|
126
|
+
const root = this.preferredRoot(target);
|
|
127
|
+
let started = await this.pool.acquire({ ...target, root }, launch, signal);
|
|
128
|
+
if (started.status === 'unavailable' && target.fallbackRoot && root === target.root && !signal?.aborted && !this.disposed) {
|
|
129
|
+
started = await this.pool.acquire({ ...target, root: target.fallbackRoot }, launch, signal);
|
|
130
|
+
}
|
|
95
131
|
if (started.status !== 'ready') {
|
|
96
|
-
return { status: 'unavailable', language:
|
|
132
|
+
return { status: 'unavailable', language: languageId, installed, detail: started.detail ?? 'サーバーを起動できません' };
|
|
97
133
|
}
|
|
98
134
|
let sync;
|
|
99
135
|
try {
|
|
100
136
|
sync = await started.server.synchronize(file, text);
|
|
101
137
|
}
|
|
102
138
|
catch (e) {
|
|
103
|
-
return { status: 'partial', language:
|
|
139
|
+
return { status: 'partial', language: languageId, installed, detail: `診断を取得できません: ${e.message}` };
|
|
104
140
|
}
|
|
105
141
|
const combined = aggregate([{ id: language.id, status: sync.status, diagnostics: sync.diagnostics }]);
|
|
106
142
|
return {
|
|
107
143
|
status: sync.status === 'observed' ? 'ok' : 'partial',
|
|
108
|
-
language:
|
|
144
|
+
language: languageId,
|
|
109
145
|
installed,
|
|
110
146
|
diagnostics: combined.diagnostics,
|
|
111
147
|
servers: combined.servers,
|
|
@@ -5,6 +5,12 @@ export interface StructureNode {
|
|
|
5
5
|
startColumn: number;
|
|
6
6
|
endLine: number;
|
|
7
7
|
endColumn: number;
|
|
8
|
+
declaration: {
|
|
9
|
+
startLine: number;
|
|
10
|
+
startColumn: number;
|
|
11
|
+
endLine: number;
|
|
12
|
+
endColumn: number;
|
|
13
|
+
};
|
|
8
14
|
}
|
|
9
15
|
export interface SyntaxResult {
|
|
10
16
|
status: 'ok' | 'unsupported' | 'error';
|
|
@@ -12,6 +18,7 @@ export interface SyntaxResult {
|
|
|
12
18
|
/** Present only on success; a failure reason is supplied otherwise. */
|
|
13
19
|
nodes?: StructureNode[];
|
|
14
20
|
errorCount?: number;
|
|
21
|
+
truncated?: boolean;
|
|
15
22
|
detail?: string;
|
|
16
23
|
}
|
|
17
24
|
/** Bare `enclosing` lookups do not need naming; queries above name definitions only. */
|
|
@@ -21,4 +28,6 @@ export declare function verifyGrammar(grammar: string): Promise<{
|
|
|
21
28
|
ok: boolean;
|
|
22
29
|
detail?: string;
|
|
23
30
|
}>;
|
|
24
|
-
export declare function outline(grammar: string, source: string,
|
|
31
|
+
export declare function outline(grammar: string, source: string, options?: {
|
|
32
|
+
nameIncludes?: string;
|
|
33
|
+
}): Promise<SyntaxResult>;
|
|
@@ -15,8 +15,7 @@ const DEFINITION_QUERIES = {
|
|
|
15
15
|
(type_alias_declaration name: (type_identifier) @name)
|
|
16
16
|
(enum_declaration name: (identifier) @name)
|
|
17
17
|
(method_definition name: (property_identifier) @name)
|
|
18
|
-
(lexical_declaration (variable_declarator name: (identifier) @name))
|
|
19
|
-
(export_statement declaration: (function_declaration name: (identifier) @name))`,
|
|
18
|
+
(lexical_declaration (variable_declarator name: (identifier) @name))`,
|
|
20
19
|
python: `(function_definition name: (identifier) @name)
|
|
21
20
|
(class_definition name: (identifier) @name)`,
|
|
22
21
|
rust: `(function_item name: (identifier) @name)
|
|
@@ -93,38 +92,57 @@ export async function verifyGrammar(grammar) {
|
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
const MAX_STRUCTURE_NODES = 400;
|
|
96
|
-
|
|
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 = {}) {
|
|
97
117
|
const query = definitionQuery(grammar);
|
|
98
118
|
if (!query)
|
|
99
119
|
return { status: 'unsupported', language: grammar, detail: 'この言語の構造抽出は未対応' };
|
|
100
120
|
let tree;
|
|
121
|
+
let matcher;
|
|
101
122
|
try {
|
|
102
123
|
const bundle = await load(grammar);
|
|
103
124
|
tree = bundle.parser.parse(source);
|
|
104
125
|
if (!tree)
|
|
105
126
|
return { status: 'error', language: grammar, detail: '構文木を作成できなかった' };
|
|
106
|
-
|
|
127
|
+
matcher = new Query(bundle.language, query);
|
|
107
128
|
const nodes = [];
|
|
129
|
+
let truncated = false;
|
|
108
130
|
for (const capture of matcher.captures(tree.rootNode)) {
|
|
109
|
-
if (
|
|
131
|
+
if (options.nameIncludes && !capture.node.text.includes(options.nameIncludes))
|
|
132
|
+
continue;
|
|
133
|
+
if (nodes.length >= MAX_STRUCTURE_NODES) {
|
|
134
|
+
truncated = true;
|
|
110
135
|
break;
|
|
111
|
-
|
|
112
|
-
nodes.push(
|
|
113
|
-
kind: node.parent?.parent?.type ?? node.parent?.type ?? node.type,
|
|
114
|
-
name: node.text.slice(0, 200),
|
|
115
|
-
startLine: node.startPosition.row + 1,
|
|
116
|
-
startColumn: node.startPosition.column + 1,
|
|
117
|
-
endLine: node.endPosition.row + 1,
|
|
118
|
-
endColumn: node.endPosition.column + 1,
|
|
119
|
-
});
|
|
136
|
+
}
|
|
137
|
+
nodes.push(describeDeclaration(capture.node));
|
|
120
138
|
}
|
|
121
|
-
|
|
122
|
-
return { status: 'ok', language: grammar, nodes, errorCount: countErrors(tree.rootNode) };
|
|
139
|
+
return { status: 'ok', language: grammar, nodes, truncated, errorCount: countErrors(tree.rootNode) };
|
|
123
140
|
}
|
|
124
141
|
catch (e) {
|
|
125
142
|
return { status: 'error', language: grammar, detail: e instanceof Error ? e.message : String(e) };
|
|
126
143
|
}
|
|
127
144
|
finally {
|
|
145
|
+
matcher?.delete();
|
|
128
146
|
tree?.delete();
|
|
129
147
|
}
|
|
130
148
|
}
|
|
@@ -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
|
+
}
|
package/dist/lisp/config.d.ts
CHANGED
|
@@ -3,9 +3,18 @@ export interface SessionDefinition {
|
|
|
3
3
|
descriptor: PluginDescriptor;
|
|
4
4
|
definition: LocalDefinition;
|
|
5
5
|
}
|
|
6
|
+
export interface HeadChecks {
|
|
7
|
+
inputs?: {
|
|
8
|
+
model: string;
|
|
9
|
+
lean: string;
|
|
10
|
+
editor?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
6
13
|
export interface LispConfiguration {
|
|
7
14
|
digest: string;
|
|
8
15
|
entries: SessionDefinition[];
|
|
16
|
+
headInstruction?: string;
|
|
17
|
+
headChecks?: HeadChecks;
|
|
9
18
|
}
|
|
10
19
|
export declare const REQUIRED_SKILLS: readonly ["kiokuko-single-purpose-functions", "one-shot-software-completion"];
|
|
11
20
|
export declare function validateDefinitions(raw: unknown, digest: string): SessionDefinition[];
|
package/dist/lisp/config.js
CHANGED
|
@@ -2,9 +2,9 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { readBundledSkill, MODKH_SKILL_BINDING } from "../agent/bundled-skills.js";
|
|
4
4
|
import { executeBounded, privateEnvironment, temporaryDirectory, sha256 } from "./runtime.js";
|
|
5
|
-
const TOOLS = new Set(['code_outline', 'code_definition', 'code_references', 'code_diagnostics', 'code_hover', 'edit_file', '
|
|
6
|
-
const LANGUAGES = new Set(['php', 'common-lisp', 'js', 'ts', 'svelte', 'tailwindcss', 'html', 'css', '
|
|
7
|
-
const KINDS = new Set(['outline', 'definition', 'references', 'diagnostics', 'hover', 'edit', 'verify']);
|
|
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
8
|
export const REQUIRED_SKILLS = ['kiokuko-single-purpose-functions', 'one-shot-software-completion'];
|
|
9
9
|
function string(value, name, max) {
|
|
10
10
|
if (typeof value !== 'string' || !value.trim() || Buffer.byteLength(value) > max || /[\x00-\x08\x0b\x0c\x0e-\x1f]/.test(value))
|
|
@@ -74,10 +74,41 @@ export function validateDefinitions(raw, digest) {
|
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
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
|
+
}
|
|
77
100
|
const DRIVER = String.raw `
|
|
78
|
-
(defpackage :modkh (:use :cl) (:export :defmicroagent :register-agent :disable-agent :remove-agent :list-agents :set-agent-check))
|
|
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))
|
|
79
102
|
(in-package :modkh)
|
|
80
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))
|
|
81
112
|
(defun agent-id (id) (string-downcase (string id)))
|
|
82
113
|
(defun register-agent (id &rest fields)
|
|
83
114
|
(setf id (agent-id id))
|
|
@@ -114,14 +145,18 @@ const DRIVER = String.raw `
|
|
|
114
145
|
(let ((*standard-output* (make-broadcast-stream)) (*trace-output* (make-broadcast-stream))
|
|
115
146
|
(*error-output* (make-broadcast-stream)) (*terminal-io* (make-two-way-stream (make-string-input-stream "") (make-broadcast-stream))))
|
|
116
147
|
(load "input.lisp" :verbose nil :print nil))
|
|
117
|
-
(write-
|
|
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)
|
|
118
153
|
(loop for row being the hash-values of *agents* for i from 0 do
|
|
119
154
|
(when (> i 0) (write-char #\, protocol)) (write-char #\{ protocol)
|
|
120
155
|
(loop for (key value) on row by #'cddr for j from 0 do
|
|
121
156
|
(when (> j 0) (write-char #\, protocol)) (json-string (string-downcase (symbol-name key)) protocol) (write-char #\: protocol)
|
|
122
157
|
(if (eq key :enabled) (write-string (if value "true" "false") protocol) (json-value value protocol)))
|
|
123
158
|
(write-char #\} protocol))
|
|
124
|
-
(write-
|
|
159
|
+
(write-string "]}" protocol) (finish-output protocol))
|
|
125
160
|
`;
|
|
126
161
|
export async function loadLispConfiguration(file, trustedDigest, options = {}) {
|
|
127
162
|
if (!/^[a-f0-9]{64}$/.test(trustedDigest))
|
|
@@ -150,7 +185,15 @@ export async function loadLispConfiguration(file, trustedDigest, options = {}) {
|
|
|
150
185
|
settled = receipt.cleanup === 'settled';
|
|
151
186
|
if (receipt.state !== 'exited' || receipt.exitCode !== 0)
|
|
152
187
|
throw new Error(`Lisp evaluation ${receipt.state}/${receipt.exitCode}: ${receipt.stderr.slice(0, 4096)}`);
|
|
153
|
-
|
|
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
|
+
};
|
|
154
197
|
}
|
|
155
198
|
finally {
|
|
156
199
|
if (settled)
|
package/dist/lisp/routing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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',
|
|
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
2
|
/** Conservative opt-in rules, never described as LLM judgment. Ambiguity delegates nothing. */
|
|
3
3
|
export function routeIntent(task, available) {
|
|
4
4
|
if (/\b(if|unless|not|don't|without|maybe|or)\b|しない|するな|不要|なら|場合|もし|または|https?:|\.\.|[\\]/i.test(task))
|
|
@@ -9,7 +9,7 @@ export function routeIntent(task, available) {
|
|
|
9
9
|
const language = EXT[files[0].split('.').at(-1)];
|
|
10
10
|
if (!language)
|
|
11
11
|
return;
|
|
12
|
-
const rules = [['outline', /\b(outline|structure)\b|構造/], ['definition', /\bdefinition\b|定義/], ['references', /\breferences\b|参照/], ['diagnostics', /\bdiagnostics\b|診断/], ['hover', /\bhover\b|ホバー/], ['edit', /\b(edit|fix|change)\b|修正|編集/], ['verify', /\bverify\b|検証/]];
|
|
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
13
|
const kinds = rules.filter(([, re]) => re.test(task));
|
|
14
14
|
if (kinds.length !== 1)
|
|
15
15
|
return;
|
package/dist/lisp/runtime.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export interface ExecutionReceipt {
|
|
|
7
7
|
stderr: string;
|
|
8
8
|
inputDigest: string;
|
|
9
9
|
cleanup: 'settled' | 'unknown';
|
|
10
|
+
outputBytes?: number;
|
|
11
|
+
outputTruncated?: boolean;
|
|
12
|
+
terminationReason?: 'aborted' | 'timed-out' | 'output-limit' | 'unknown';
|
|
10
13
|
}
|
|
11
14
|
export declare function privateEnvironment(home: string): NodeJS.ProcessEnv;
|
|
12
15
|
export declare function temporaryDirectory(prefix: string): string;
|
|
@@ -18,4 +21,6 @@ export declare function executeBounded(command: string, args: string[], options:
|
|
|
18
21
|
timeoutMs: number;
|
|
19
22
|
maxOutputBytes?: number;
|
|
20
23
|
signal?: AbortSignal;
|
|
24
|
+
/** Trusted verbose builds may retain a bounded tail instead of being killed. */
|
|
25
|
+
outputOverflow?: 'stop' | 'tail';
|
|
21
26
|
}): Promise<ExecutionReceipt>;
|
package/dist/lisp/runtime.js
CHANGED
|
@@ -52,7 +52,7 @@ export function executeBounded(command, args, options) {
|
|
|
52
52
|
options.signal?.removeEventListener('abort', abort);
|
|
53
53
|
child.stdout?.destroy();
|
|
54
54
|
child.stderr?.destroy();
|
|
55
|
-
resolve({ ...base, state: unknown ? 'unknown' : stopped ?? (base.exitCode === null ? 'not-started' : 'exited'), cleanup: unknown ? 'unknown' : 'settled' });
|
|
55
|
+
resolve({ ...base, outputBytes: bytes, ...(stopped ? { terminationReason: stopped } : {}), state: unknown ? 'unknown' : stopped ?? (base.exitCode === null ? 'not-started' : 'exited'), cleanup: unknown ? 'unknown' : 'settled' });
|
|
56
56
|
};
|
|
57
57
|
const stop = (state) => {
|
|
58
58
|
stopped ??= state;
|
|
@@ -67,6 +67,30 @@ export function executeBounded(command, args, options) {
|
|
|
67
67
|
abort();
|
|
68
68
|
const append = (key, data) => {
|
|
69
69
|
const budget = options.maxOutputBytes ?? 256 * 1024;
|
|
70
|
+
if (options.outputOverflow === 'tail') {
|
|
71
|
+
bytes += data.length;
|
|
72
|
+
const addition = decoders[key].write(data);
|
|
73
|
+
const text = base[key] + addition;
|
|
74
|
+
const buffer = Buffer.from(text);
|
|
75
|
+
const other = key === 'stdout' ? 'stderr' : 'stdout';
|
|
76
|
+
const otherBuffer = Buffer.from(base[other]);
|
|
77
|
+
let otherStart = Math.max(0, otherBuffer.length - Math.max(0, budget - Buffer.byteLength(addition)));
|
|
78
|
+
if (otherStart > 0) {
|
|
79
|
+
base.outputTruncated = true;
|
|
80
|
+
while (otherStart < otherBuffer.length && (otherBuffer[otherStart] & 0xc0) === 0x80)
|
|
81
|
+
otherStart++;
|
|
82
|
+
base[other] = otherBuffer.subarray(otherStart).toString('utf8');
|
|
83
|
+
}
|
|
84
|
+
const limit = Math.max(0, budget - Buffer.byteLength(base[other]));
|
|
85
|
+
let start = Math.max(0, buffer.length - limit);
|
|
86
|
+
if (start > 0) {
|
|
87
|
+
base.outputTruncated = true;
|
|
88
|
+
while (start < buffer.length && (buffer[start] & 0xc0) === 0x80)
|
|
89
|
+
start++;
|
|
90
|
+
}
|
|
91
|
+
base[key] = buffer.subarray(start).toString('utf8');
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
70
94
|
const room = Math.max(0, budget - bytes);
|
|
71
95
|
base[key] += decoders[key].write(data.subarray(0, room));
|
|
72
96
|
bytes += data.length;
|
|
@@ -76,7 +100,7 @@ export function executeBounded(command, args, options) {
|
|
|
76
100
|
child.stdout?.on('data', (data) => append('stdout', data));
|
|
77
101
|
child.stderr?.on('data', (data) => append('stderr', data));
|
|
78
102
|
child.on('error', error => { base.stderr = error.message.slice(0, 4096); });
|
|
79
|
-
child.on('exit', () => { if (alive())
|
|
103
|
+
child.on('exit', (code, signal) => { base.exitCode = code; base.signal = signal; if (alive())
|
|
80
104
|
stop('unknown'); });
|
|
81
105
|
child.on('close', (code, signal) => { closed = true; base.stdout += decoders.stdout.end(); base.stderr += decoders.stderr.end(); base.exitCode = code; base.signal = signal; finish(); });
|
|
82
106
|
});
|
package/dist/model/ai-sdk.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { streamText, jsonSchema, tool, } from 'ai';
|
|
2
2
|
import { toolContext } from "./context.js";
|
|
3
|
+
import { harnessProfile, CODEX_62_DEFAULTS } from "./harness-profile.js";
|
|
3
4
|
import { reasoningProviderOptions } from "./reasoning.js";
|
|
4
5
|
import { parseImages } from "../agent/images.js";
|
|
5
6
|
function toCoreMessages(req) {
|
|
@@ -83,7 +84,11 @@ export class AiSdkModel {
|
|
|
83
84
|
let errorMessage;
|
|
84
85
|
let sawToolCall = false;
|
|
85
86
|
let finishReason;
|
|
86
|
-
const
|
|
87
|
+
const defaults = harnessProfile(this.id) ? CODEX_62_DEFAULTS : undefined;
|
|
88
|
+
const reasoning = reasoningProviderOptions(this.provider ?? '', req.reasoning ?? defaults?.reasoning, this.id);
|
|
89
|
+
// Only native OpenAI Responses is known to support text.verbosity.
|
|
90
|
+
const providerOptions = defaults && this.provider === 'openai'
|
|
91
|
+
? { openai: { ...reasoning?.openai, textVerbosity: defaults.verbosity } } : reasoning;
|
|
87
92
|
const thinking = this.provider === 'anthropic' && reasoning?.anthropic !== undefined;
|
|
88
93
|
const thinkingBudget = thinking
|
|
89
94
|
? reasoning.anthropic.thinking.budgetTokens : undefined;
|
|
@@ -98,7 +103,7 @@ export class AiSdkModel {
|
|
|
98
103
|
onError: () => { },
|
|
99
104
|
maxRetries: 0, // A transport failure does not establish that the request was unsent.
|
|
100
105
|
// providerOptions の実値はすべて JSON オブジェクト。SDK型は index signature が緩いため型の詰め替え。
|
|
101
|
-
...(
|
|
106
|
+
...(providerOptions ? { providerOptions: providerOptions } : {}),
|
|
102
107
|
...(thinking ? { maxOutputTokens: (thinkingBudget ?? 0) + 8192 } : {}),
|
|
103
108
|
});
|
|
104
109
|
for await (const part of result.fullStream) {
|
|
@@ -112,10 +117,8 @@ export class AiSdkModel {
|
|
|
112
117
|
yield { type: 'reasoning-delta', text: part.text };
|
|
113
118
|
}
|
|
114
119
|
else if (part.type === 'tool-input-start') {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
yield { type: 'activity', stage: activity };
|
|
118
|
-
}
|
|
120
|
+
activity = 'tool-input';
|
|
121
|
+
yield { type: 'activity', stage: activity, toolName: part.toolName };
|
|
119
122
|
}
|
|
120
123
|
else if (part.type === 'text-delta') {
|
|
121
124
|
activity = undefined;
|
|
@@ -137,12 +140,13 @@ export class AiSdkModel {
|
|
|
137
140
|
if (part.totalUsage) {
|
|
138
141
|
usage = {
|
|
139
142
|
input: part.totalUsage.inputTokens,
|
|
143
|
+
uncachedInput: part.totalUsage.inputTokenDetails?.noCacheTokens,
|
|
140
144
|
output: part.totalUsage.outputTokens,
|
|
141
145
|
cacheRead: part.totalUsage.inputTokenDetails?.cacheReadTokens,
|
|
142
146
|
cacheWrite: part.totalUsage.inputTokenDetails?.cacheWriteTokens,
|
|
143
147
|
};
|
|
144
148
|
}
|
|
145
|
-
if (part.finishReason === 'stop' || part.finishReason === 'tool-calls') {
|
|
149
|
+
if (part.finishReason === 'stop' || part.finishReason === 'tool-calls' || part.finishReason === 'length') {
|
|
146
150
|
finishReason = part.finishReason;
|
|
147
151
|
}
|
|
148
152
|
else {
|
|
@@ -170,7 +174,8 @@ export class AiSdkModel {
|
|
|
170
174
|
if (aborted) {
|
|
171
175
|
yield { type: 'finish', stopReason: 'aborted' };
|
|
172
176
|
}
|
|
173
|
-
else if (errorMessage !== undefined || finishReason === undefined ||
|
|
177
|
+
else if (errorMessage !== undefined || finishReason === undefined ||
|
|
178
|
+
(finishReason !== 'length' && (finishReason === 'tool-calls') !== sawToolCall)) {
|
|
174
179
|
yield { type: 'finish', stopReason: 'error', errorMessage: errorMessage ?? 'モデル終了イベントがない、またはツール要求と終了理由が不整合' };
|
|
175
180
|
}
|
|
176
181
|
else {
|
|
@@ -3,7 +3,7 @@ import http from 'node:http';
|
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
4
|
import { saveChatGptTokens, loadChatGptTokens } from "./tokens.js";
|
|
5
5
|
export const DEFAULT_LOGIN = {
|
|
6
|
-
issuer: 'https://auth.openai.com', clientId: '
|
|
6
|
+
issuer: 'https://auth.openai.com', clientId: 'app_EMoamEEZ73f0CkXaXp7hrann', redirectPort: 1455,
|
|
7
7
|
};
|
|
8
8
|
export function createPkcePair() {
|
|
9
9
|
const verifier = crypto.randomBytes(48).toString('base64url');
|