modkh 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -0
- package/dist/agent/bundled-skills.d.ts +1 -1
- package/dist/agent/bundled-skills.js +1 -1
- package/dist/agent/compaction.d.ts +53 -0
- package/dist/agent/compaction.js +191 -0
- package/dist/agent/loop.d.ts +55 -8
- package/dist/agent/loop.js +119 -7
- package/dist/agent/skills.d.ts +7 -1
- package/dist/agent/skills.js +26 -5
- package/dist/agent/types.d.ts +14 -9
- package/dist/cli/agenticreplay.d.ts +1 -0
- package/dist/cli/agenticreplay.js +66 -0
- package/dist/cli/answer-markdown.d.ts +3 -0
- package/dist/cli/answer-markdown.js +29 -0
- package/dist/cli/approval.d.ts +2 -0
- package/dist/cli/approval.js +35 -5
- package/dist/cli/catalog.d.ts +30 -32
- package/dist/cli/catalog.js +37 -67
- package/dist/cli/chat.js +406 -78
- package/dist/cli/clipboard.d.ts +2 -0
- package/dist/cli/clipboard.js +28 -0
- package/dist/cli/color.d.ts +20 -3
- package/dist/cli/color.js +87 -19
- package/dist/cli/compaction-settings.d.ts +21 -0
- package/dist/cli/compaction-settings.js +54 -0
- package/dist/cli/completion-art.d.ts +2 -0
- package/dist/cli/completion-art.js +62 -0
- package/dist/cli/config.d.ts +9 -0
- package/dist/cli/config.js +5 -1
- package/dist/cli/editor.d.ts +7 -0
- package/dist/cli/editor.js +43 -5
- package/dist/cli/file-mentions.d.ts +14 -0
- package/dist/cli/file-mentions.js +141 -0
- package/dist/cli/head-checks.d.ts +41 -0
- package/dist/cli/head-checks.js +146 -0
- package/dist/cli/initial-connection.d.ts +7 -0
- package/dist/cli/initial-connection.js +20 -0
- package/dist/cli/keys.d.ts +12 -1
- package/dist/cli/keys.js +29 -4
- package/dist/cli/model-catalog.d.ts +16 -0
- package/dist/cli/model-catalog.js +130 -0
- package/dist/cli/models.d.ts +2 -2
- package/dist/cli/models.js +51 -19
- package/dist/cli/official-models.d.ts +6 -0
- package/dist/cli/official-models.js +77 -0
- package/dist/cli/pdf.d.ts +8 -0
- package/dist/cli/pdf.js +71 -0
- package/dist/cli/providers.d.ts +6 -42
- package/dist/cli/providers.js +44 -38
- package/dist/cli/shell-display.d.ts +6 -0
- package/dist/cli/shell-display.js +35 -0
- package/dist/cli/stateright.d.ts +1 -0
- package/dist/cli/stateright.js +37 -0
- package/dist/cli/terminal-mouse.d.ts +21 -0
- package/dist/cli/terminal-mouse.js +51 -0
- package/dist/cli/terminal.d.ts +95 -7
- package/dist/cli/terminal.js +783 -108
- package/dist/cli/tool-display.d.ts +9 -0
- package/dist/cli/tool-display.js +87 -0
- package/dist/cli/transcript-selection.d.ts +22 -0
- package/dist/cli/transcript-selection.js +75 -0
- package/dist/cli/usage.d.ts +9 -16
- package/dist/cli/usage.js +60 -18
- package/dist/cli/waiting-nyan.d.ts +3 -0
- package/dist/cli/waiting-nyan.js +17 -0
- package/dist/cli/waiting-whales.d.ts +3 -0
- package/dist/cli/waiting-whales.js +24 -0
- package/dist/index.js +30 -8
- package/dist/language/commonlisp-install.d.ts +1 -0
- package/dist/language/commonlisp-install.js +3 -2
- package/dist/language/lsp/client.js +4 -1
- package/dist/language/lsp/pool.d.ts +8 -0
- package/dist/language/lsp/pool.js +21 -3
- package/dist/language/lsp/service.d.ts +8 -4
- package/dist/language/lsp/service.js +51 -15
- package/dist/language/syntax/parser.d.ts +10 -1
- package/dist/language/syntax/parser.js +34 -16
- package/dist/lisp/builtin-agents.d.ts +5 -0
- package/dist/lisp/builtin-agents.js +52 -0
- package/dist/lisp/config.d.ts +9 -0
- package/dist/lisp/config.js +50 -7
- package/dist/lisp/routing.js +2 -2
- package/dist/lisp/runtime.d.ts +5 -0
- package/dist/lisp/runtime.js +26 -2
- package/dist/model/ai-sdk.js +13 -8
- package/dist/model/chatgpt/login.js +1 -1
- package/dist/model/chatgpt/responses.js +56 -4
- package/dist/model/connection.js +2 -0
- package/dist/model/context-window.d.ts +3 -0
- package/dist/model/context-window.js +64 -0
- package/dist/model/context.d.ts +3 -1
- package/dist/model/context.js +24 -24
- package/dist/model/factory.d.ts +3 -1
- package/dist/model/factory.js +28 -27
- package/dist/model/harness-profile.d.ts +6 -0
- package/dist/model/harness-profile.js +23 -0
- package/dist/model/providers.d.ts +32 -0
- package/dist/model/providers.js +72 -0
- package/dist/model/reasoning.d.ts +3 -3
- package/dist/model/reasoning.js +30 -8
- package/dist/model/record-fetch.d.ts +2 -0
- package/dist/model/record-fetch.js +19 -0
- package/dist/plugins/manager.d.ts +2 -1
- package/dist/plugins/manager.js +21 -2
- package/dist/session/store.d.ts +11 -0
- package/dist/session/store.js +27 -1
- package/dist/subagents/head-assignment.d.ts +11 -0
- package/dist/subagents/head-assignment.js +47 -0
- package/dist/subagents/limits.d.ts +4 -0
- package/dist/subagents/limits.js +6 -0
- package/dist/subagents/request.js +18 -1
- package/dist/subagents/service.d.ts +36 -2
- package/dist/subagents/service.js +331 -38
- package/dist/subagents/types.d.ts +20 -0
- package/dist/subagents/verification.d.ts +5 -2
- package/dist/subagents/verification.js +59 -22
- package/dist/tools/browse.d.ts +13 -0
- package/dist/tools/browse.js +117 -0
- package/dist/tools/browser-capability.d.ts +3 -0
- package/dist/tools/browser-capability.js +29 -0
- package/dist/tools/formal-input.d.ts +6 -0
- package/dist/tools/formal-input.js +29 -0
- package/dist/tools/formal.d.ts +3 -2
- package/dist/tools/formal.js +54 -52
- package/dist/tools/jobs.d.ts +2 -0
- package/dist/tools/jobs.js +5 -0
- package/dist/tools/language.js +25 -27
- package/dist/tools/lean-proof.d.ts +38 -0
- package/dist/tools/lean-proof.js +83 -0
- package/dist/tools/registry.d.ts +5 -3
- package/dist/tools/registry.js +13 -5
- package/dist/tools/run.js +13 -9
- package/dist/tools/shell-process.js +17 -6
- package/dist/tools/stateright-runtime.d.ts +3 -0
- package/dist/tools/stateright-runtime.js +16 -0
- package/dist/tools/stateright.d.ts +3 -0
- package/dist/tools/stateright.js +78 -0
- package/dist/tools/web.js +7 -2
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/docs/commonlisp-build-output.md +14 -0
- package/docs/context-efficiency.md +25 -3
- package/docs/input.md +63 -3
- package/docs/languages.md +3 -3
- package/docs/models.md +30 -6
- package/docs/modkh.md +11 -7
- package/docs/presets.md +45 -0
- package/docs/setup.md +3 -16
- package/docs/stateright.md +45 -0
- package/docs/subagents.md +21 -3
- package/docs/web.md +1 -1
- package/experiments/presets/formal.lisp +15 -4
- package/experiments/presets/language-microagents.lisp +29 -0
- package/native/stateright/Cargo.lock +478 -0
- package/native/stateright/Cargo.toml +11 -0
- package/native/stateright/src/lib.rs +163 -0
- package/native/stateright/src/main.rs +38 -0
- package/package.json +10 -2
package/dist/cli/clipboard.d.ts
CHANGED
|
@@ -7,3 +7,5 @@ export declare function readClipboardImage(signal: AbortSignal, options?: {
|
|
|
7
7
|
platform?: string;
|
|
8
8
|
command?: ClipboardCommand;
|
|
9
9
|
}): Promise<ImageAttachment>;
|
|
10
|
+
export declare const MAC_TEXT_SCRIPT = "\nObjC.import('AppKit');\nObjC.import('Foundation');\nconst data = $.NSFileHandle.fileHandleWithStandardInput.readDataToEndOfFile;\nconst text = $.NSString.alloc.initWithDataEncoding(data, $.NSUTF8StringEncoding);\nif (text.isNil()) throw new Error('Invalid UTF-8');\nconst board = $.NSPasteboard.generalPasteboard;\nboard.clearContents;\nif (!board.setStringForType(text, $.NSPasteboardTypeString)) throw new Error('Pasteboard write failed');\n";
|
|
11
|
+
export declare function writeClipboardText(text: string): Promise<void>;
|
package/dist/cli/clipboard.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
|
+
import { pipeline } from 'node:stream/promises';
|
|
2
3
|
import { MAX_IMAGE_BYTES, parseImage } from "../agent/images.js";
|
|
3
4
|
/** Read only on an explicit Ctrl+V. No clipboard text, files, credentials or network access. */
|
|
4
5
|
export const MAC_IMAGE_SCRIPT = `
|
|
@@ -52,3 +53,30 @@ export async function readClipboardImage(signal, options = {}) {
|
|
|
52
53
|
}
|
|
53
54
|
return parseImage(value);
|
|
54
55
|
}
|
|
56
|
+
export const MAC_TEXT_SCRIPT = `
|
|
57
|
+
ObjC.import('AppKit');
|
|
58
|
+
ObjC.import('Foundation');
|
|
59
|
+
const data = $.NSFileHandle.fileHandleWithStandardInput.readDataToEndOfFile;
|
|
60
|
+
const text = $.NSString.alloc.initWithDataEncoding(data, $.NSUTF8StringEncoding);
|
|
61
|
+
if (text.isNil()) throw new Error('Invalid UTF-8');
|
|
62
|
+
const board = $.NSPasteboard.generalPasteboard;
|
|
63
|
+
board.clearContents;
|
|
64
|
+
if (!board.setStringForType(text, $.NSPasteboardTypeString)) throw new Error('Pasteboard write failed');
|
|
65
|
+
`;
|
|
66
|
+
export async function writeClipboardText(text) {
|
|
67
|
+
if (process.platform !== 'darwin')
|
|
68
|
+
throw new Error('回答のコピーはmacOSで使えます');
|
|
69
|
+
try {
|
|
70
|
+
const child = execFile('/usr/bin/osascript', ['-l', 'JavaScript', '-e', MAC_TEXT_SCRIPT], {
|
|
71
|
+
timeout: 5000, killSignal: 'SIGKILL',
|
|
72
|
+
});
|
|
73
|
+
const completion = new Promise((resolve, reject) => {
|
|
74
|
+
child.once('error', reject);
|
|
75
|
+
child.once('close', code => code === 0 ? resolve() : reject(new Error('Pasteboard write failed')));
|
|
76
|
+
});
|
|
77
|
+
await Promise.all([completion, pipeline([text], child.stdin)]);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
throw new Error('クリップボードに回答をコピーできませんでした');
|
|
81
|
+
}
|
|
82
|
+
}
|
package/dist/cli/color.d.ts
CHANGED
|
@@ -25,18 +25,35 @@ export declare function backgroundLuminance(osc: string): number | null;
|
|
|
25
25
|
export declare function classifyBackground(oscReply: string | null, env?: NodeJS.ProcessEnv): 'dark' | 'light' | null;
|
|
26
26
|
/** コード fenced block 内の1行を簡易ハイライトする。 */
|
|
27
27
|
export declare function highlightCodeLine(line: string, palette: Palette): string;
|
|
28
|
-
export
|
|
28
|
+
export declare const READABLE_TEXT_STYLE = "1;39";
|
|
29
|
+
/**
|
|
30
|
+
* Tool output quoting source, as produced by `search_files` (`path:line: body`) and
|
|
31
|
+
* `read_file` (`line: body`). Output without a source prefix stays plain: highlighting
|
|
32
|
+
* a JSON body or a log line as code would claim more context than the text carries.
|
|
33
|
+
*/
|
|
34
|
+
export declare function sourceLine(raw: string): {
|
|
35
|
+
body: string;
|
|
36
|
+
} | null;
|
|
37
|
+
export type TranscriptKind = 'system' | 'user' | 'answer' | 'reasoning';
|
|
38
|
+
export type ColorMode = 'text' | 'code';
|
|
29
39
|
export interface ColorizerState {
|
|
40
|
+
answerFence?: string;
|
|
30
41
|
mode: ColorMode;
|
|
31
42
|
inDiff: boolean;
|
|
43
|
+
inToolOutput: boolean;
|
|
32
44
|
}
|
|
33
|
-
/**
|
|
45
|
+
/** コードブロックとdiffの状態を行間で引き継いで色を付ける。 */
|
|
34
46
|
export declare class TranscriptColorizer {
|
|
47
|
+
private answerFence?;
|
|
35
48
|
private mode;
|
|
36
49
|
private inDiff;
|
|
50
|
+
/** Set while drawing the body of one tool result, cleared by the next `▶` line or blank line. */
|
|
51
|
+
private inToolOutput;
|
|
37
52
|
/** 完成行までの状態を保存しておき、未完了行(ライブ表示)の色分けに複製する。 */
|
|
38
53
|
state(): ColorizerState;
|
|
39
54
|
restore(state: ColorizerState): void;
|
|
40
|
-
line(raw: string, palette: Palette): string;
|
|
55
|
+
line(raw: string, palette: Palette, kind?: TranscriptKind): string;
|
|
56
|
+
/** Rebuild a line from its untouched prefix (`path:12: `) and its highlighted body. */
|
|
57
|
+
private prefix;
|
|
41
58
|
private diffLine;
|
|
42
59
|
}
|
package/dist/cli/color.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* トランスクリプトの行単位の色分け。外部依存なし。
|
|
3
|
-
* -
|
|
3
|
+
* - 推論はグレー、回答は Markdown の強調やコードを端末のスタイルで表示
|
|
4
4
|
* - diff(+/-/@@/---/+++)は追加=緑・削除=赤
|
|
5
5
|
* - ``` コードブロック内は簡易トークナイザー(文字列・コメント・キーワード・数値)
|
|
6
6
|
* ライト/ダーク両方で読みやすいよう背景判定ごとにパレットを替える。
|
|
7
7
|
*/
|
|
8
|
+
import { answerMarkdown } from "./answer-markdown.js";
|
|
8
9
|
import { stripVTControlCharacters } from 'node:util';
|
|
9
10
|
/** ダーク背景は明るい標準色、ライト背景は256色パレットの暗い色。 */
|
|
10
11
|
export function paletteFor(background) {
|
|
@@ -96,36 +97,84 @@ export function highlightCodeLine(line, palette) {
|
|
|
96
97
|
return `\x1b[${code}m${match}\x1b[0m`;
|
|
97
98
|
});
|
|
98
99
|
}
|
|
99
|
-
|
|
100
|
+
export const READABLE_TEXT_STYLE = '1;39';
|
|
101
|
+
/**
|
|
102
|
+
* Tool output quoting source, as produced by `search_files` (`path:line: body`) and
|
|
103
|
+
* `read_file` (`line: body`). Output without a source prefix stays plain: highlighting
|
|
104
|
+
* a JSON body or a log line as code would claim more context than the text carries.
|
|
105
|
+
*/
|
|
106
|
+
export function sourceLine(raw) {
|
|
107
|
+
const hit = /^\s{0,2}([^\s:]+):(\d+)(?::(\d+))?: (.*)$/.exec(raw)
|
|
108
|
+
?? /^\s{0,2}(\d+): (.*)$/.exec(raw);
|
|
109
|
+
if (hit === null)
|
|
110
|
+
return null;
|
|
111
|
+
const numbered = hit.length === 4 ? hit[2] : hit[1];
|
|
112
|
+
if (Number(numbered) < 1)
|
|
113
|
+
return null;
|
|
114
|
+
const body = hit[hit.length - 1];
|
|
115
|
+
return body.trim().length === 0 ? null : { body };
|
|
116
|
+
}
|
|
117
|
+
/** Tool output lines that never quote source: they carry their own meaning. */
|
|
118
|
+
const TOOL_OUTPUT_META = /^\s*(?:\(結果[.:]|… 残り|検索 |対象: |作業場所: |\[exit code|\(エラー)/;
|
|
119
|
+
/** コードブロックとdiffの状態を行間で引き継いで色を付ける。 */
|
|
100
120
|
export class TranscriptColorizer {
|
|
121
|
+
answerFence;
|
|
101
122
|
mode = 'text';
|
|
102
123
|
inDiff = false;
|
|
124
|
+
/** Set while drawing the body of one tool result, cleared by the next `▶` line or blank line. */
|
|
125
|
+
inToolOutput = false;
|
|
103
126
|
/** 完成行までの状態を保存しておき、未完了行(ライブ表示)の色分けに複製する。 */
|
|
104
|
-
state() { return { mode: this.mode, inDiff: this.inDiff }; }
|
|
105
|
-
restore(state) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
127
|
+
state() { return { answerFence: this.answerFence, mode: this.mode, inDiff: this.inDiff, inToolOutput: this.inToolOutput }; }
|
|
128
|
+
restore(state) {
|
|
129
|
+
this.answerFence = state.answerFence;
|
|
130
|
+
this.mode = state.mode;
|
|
131
|
+
this.inDiff = state.inDiff;
|
|
132
|
+
this.inToolOutput = state.inToolOutput;
|
|
133
|
+
}
|
|
134
|
+
line(raw, palette, kind = 'system') {
|
|
135
|
+
if (kind === 'answer') {
|
|
136
|
+
const fence = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(raw);
|
|
137
|
+
if (this.answerFence) {
|
|
138
|
+
if (fence?.[1].startsWith(this.answerFence) && !fence[2].trim()) {
|
|
139
|
+
this.answerFence = undefined;
|
|
140
|
+
return '';
|
|
141
|
+
}
|
|
142
|
+
return highlightCodeLine(raw, palette);
|
|
112
143
|
}
|
|
113
|
-
|
|
114
|
-
|
|
144
|
+
if (fence && !(fence[1][0] === '`' && fence[2].includes('`'))) {
|
|
145
|
+
this.answerFence = fence[1];
|
|
146
|
+
return '';
|
|
115
147
|
}
|
|
148
|
+
return answerMarkdown(raw, palette);
|
|
116
149
|
}
|
|
117
|
-
|
|
150
|
+
this.answerFence = undefined;
|
|
151
|
+
if (kind === 'user')
|
|
152
|
+
return raw;
|
|
153
|
+
const trimmed = raw.trim();
|
|
154
|
+
const blank = trimmed.length === 0;
|
|
155
|
+
if (kind === 'reasoning')
|
|
156
|
+
return blank ? raw : `\x1b[${palette.reasoning}m${raw}\x1b[0m`;
|
|
157
|
+
// Shell cards are terminal output, not Markdown or source code. Keep their body literal.
|
|
158
|
+
if (kind === 'system' && /^(╭ |│ |╰ )/.test(raw)) {
|
|
159
|
+
this.inToolOutput = false;
|
|
160
|
+
this.inDiff = false;
|
|
161
|
+
this.mode = 'text';
|
|
162
|
+
if (raw.startsWith('╭ '))
|
|
163
|
+
return `\x1b[${palette.tool}m${raw}\x1b[0m`;
|
|
164
|
+
if (raw.startsWith('╰ '))
|
|
165
|
+
return `\x1b[${palette.result}m${raw}\x1b[0m`;
|
|
166
|
+
return `\x1b[${palette.reasoning}m│\x1b[0m${raw.slice(1)}`;
|
|
167
|
+
}
|
|
168
|
+
if (this.mode === 'code') {
|
|
118
169
|
if (/^(\s*)(```|~~~)/.test(raw)) {
|
|
119
170
|
this.mode = 'text';
|
|
120
171
|
return `\x1b[${palette.reasoning}m${raw}\x1b[0m`;
|
|
121
172
|
}
|
|
122
173
|
return highlightCodeLine(raw, palette);
|
|
123
174
|
}
|
|
124
|
-
if (blank)
|
|
175
|
+
if (blank) {
|
|
176
|
+
this.inToolOutput = false;
|
|
125
177
|
return raw;
|
|
126
|
-
if (trimmed === '(推論)' || /^(推論)$/.test(trimmed)) {
|
|
127
|
-
this.mode = 'reasoning';
|
|
128
|
-
return `\x1b[${palette.reasoning}m${raw}\x1b[0m`;
|
|
129
178
|
}
|
|
130
179
|
if (/^(\s*)(```|~~~)/.test(raw)) {
|
|
131
180
|
this.mode = 'code';
|
|
@@ -134,21 +183,40 @@ export class TranscriptColorizer {
|
|
|
134
183
|
const diff = this.diffLine(trimmed, raw, palette);
|
|
135
184
|
if (diff !== null)
|
|
136
185
|
return diff;
|
|
186
|
+
// A tool result body may quote source, so grep/read hits stay readable where they appear.
|
|
187
|
+
// The state ends with the result, so ordinary prose after it is never treated as code.
|
|
188
|
+
if (this.inToolOutput) {
|
|
189
|
+
// Meta lines are summarized in the result color but do not end the body: search
|
|
190
|
+
// output puts `対象: …` between the header and the hits it describes.
|
|
191
|
+
if (TOOL_OUTPUT_META.test(raw))
|
|
192
|
+
return `\x1b[${palette.result}m${raw}\x1b[0m`;
|
|
193
|
+
const source = sourceLine(raw);
|
|
194
|
+
if (source !== null)
|
|
195
|
+
return this.prefix(raw, source.body, highlightCodeLine(source.body, palette));
|
|
196
|
+
}
|
|
137
197
|
if (/^#{1,6} /.test(trimmed))
|
|
138
198
|
return `\x1b[${palette.heading}m${raw}\x1b[0m`;
|
|
139
199
|
if (/^▶ You:/.test(raw))
|
|
140
200
|
return `\x1b[${palette.user}m${raw}\x1b[0m`;
|
|
141
|
-
if (/^▶ /.test(raw))
|
|
201
|
+
if (/^▶ /.test(raw)) {
|
|
202
|
+
this.inToolOutput = false;
|
|
142
203
|
return `\x1b[${palette.tool}m${raw}\x1b[0m`;
|
|
143
|
-
|
|
204
|
+
}
|
|
205
|
+
if (/^\(承認\)|^\(拒否\)|^\(中断|^\(接続|^\(モデル|^\(推論/.test(trimmed)
|
|
144
206
|
|| /^ {0,2}\(結果\./.test(trimmed) || /^ {0,2}\(結果:/.test(raw) || /^ {0,2}\(エラー/.test(trimmed)) {
|
|
145
207
|
this.inDiff = false;
|
|
208
|
+
this.inToolOutput = /^ {0,2}\(結果:/.test(raw);
|
|
146
209
|
return `\x1b[${palette.result}m${raw}\x1b[0m`;
|
|
147
210
|
}
|
|
148
211
|
if (/^\[exit code/.test(trimmed))
|
|
149
212
|
return `\x1b[${palette.result}m${raw}\x1b[0m`;
|
|
150
213
|
return raw;
|
|
151
214
|
}
|
|
215
|
+
/** Rebuild a line from its untouched prefix (`path:12: `) and its highlighted body. */
|
|
216
|
+
prefix(raw, body, painted) {
|
|
217
|
+
const index = raw.indexOf(body);
|
|
218
|
+
return index <= 0 || raw.slice(index, index + body.length) !== body ? painted : raw.slice(0, index) + painted;
|
|
219
|
+
}
|
|
152
220
|
diffLine(trimmed, raw, palette) {
|
|
153
221
|
if (/^--- 承認要求/.test(raw)) {
|
|
154
222
|
this.inDiff = false;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 圧縮(compaction)の設定値。値の検証だけを持ち、判断は呼び出し元が行う。
|
|
3
|
+
*/
|
|
4
|
+
import { DEFAULT_COMPACTION_KEEP_TURNS, type CompactionSettings } from '../agent/compaction.ts';
|
|
5
|
+
export { DEFAULT_COMPACTION_KEEP_TURNS };
|
|
6
|
+
/** 直近ターン数。1〜50の整数のみ受け付ける。 */
|
|
7
|
+
export declare const KEEP_TURNS_MIN = 1;
|
|
8
|
+
export declare const KEEP_TURNS_MAX = 50;
|
|
9
|
+
export declare function parseKeepTurns(value: unknown): number | null;
|
|
10
|
+
/** 自動圧縮のしきい値(推定UTF-8バイト)。0は自動圧縮を無効化する明示値。 */
|
|
11
|
+
export declare const AUTO_BYTES_MIN: number;
|
|
12
|
+
export declare const AUTO_BYTES_MAX: number;
|
|
13
|
+
export declare function parseAutoBytes(value: unknown): number | null;
|
|
14
|
+
/**
|
|
15
|
+
* 設定から圧縮の実効値を決める。不正値は既定値へ戻し、その事実を warnings で返す。
|
|
16
|
+
* 黙って別の値を適用しない。
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseCompactionSettings(keepTurnsValue: unknown, autoBytesValue: unknown): {
|
|
19
|
+
settings: CompactionSettings;
|
|
20
|
+
warnings: string[];
|
|
21
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 圧縮(compaction)の設定値。値の検証だけを持ち、判断は呼び出し元が行う。
|
|
3
|
+
*/
|
|
4
|
+
import { DEFAULT_COMPACTION_KEEP_TURNS } from "../agent/compaction.js";
|
|
5
|
+
export { DEFAULT_COMPACTION_KEEP_TURNS };
|
|
6
|
+
/** 直近ターン数。1〜50の整数のみ受け付ける。 */
|
|
7
|
+
export const KEEP_TURNS_MIN = 1;
|
|
8
|
+
export const KEEP_TURNS_MAX = 50;
|
|
9
|
+
export function parseKeepTurns(value) {
|
|
10
|
+
const numeric = typeof value === 'string' && /^\d+$/.test(value.trim()) ? Number(value.trim())
|
|
11
|
+
: typeof value === 'number' ? value : Number.NaN;
|
|
12
|
+
if (!Number.isSafeInteger(numeric) || numeric < KEEP_TURNS_MIN || numeric > KEEP_TURNS_MAX)
|
|
13
|
+
return null;
|
|
14
|
+
return numeric;
|
|
15
|
+
}
|
|
16
|
+
/** 自動圧縮のしきい値(推定UTF-8バイト)。0は自動圧縮を無効化する明示値。 */
|
|
17
|
+
export const AUTO_BYTES_MIN = 32 * 1024;
|
|
18
|
+
export const AUTO_BYTES_MAX = 8 * 1024 * 1024;
|
|
19
|
+
export function parseAutoBytes(value) {
|
|
20
|
+
const numeric = typeof value === 'string' && /^\d+$/.test(value.trim()) ? Number(value.trim())
|
|
21
|
+
: typeof value === 'number' ? value : Number.NaN;
|
|
22
|
+
if (numeric === 0)
|
|
23
|
+
return 0;
|
|
24
|
+
if (!Number.isSafeInteger(numeric) || numeric < AUTO_BYTES_MIN || numeric > AUTO_BYTES_MAX)
|
|
25
|
+
return null;
|
|
26
|
+
return numeric;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 設定から圧縮の実効値を決める。不正値は既定値へ戻し、その事実を warnings で返す。
|
|
30
|
+
* 黙って別の値を適用しない。
|
|
31
|
+
*/
|
|
32
|
+
export function parseCompactionSettings(keepTurnsValue, autoBytesValue) {
|
|
33
|
+
const warnings = [];
|
|
34
|
+
let keepTurns = DEFAULT_COMPACTION_KEEP_TURNS;
|
|
35
|
+
if (keepTurnsValue !== undefined) {
|
|
36
|
+
const parsed = parseKeepTurns(keepTurnsValue);
|
|
37
|
+
if (parsed === null) {
|
|
38
|
+
warnings.push(`設定の compactionKeepTurns が不正なため ${DEFAULT_COMPACTION_KEEP_TURNS} を使用します。${KEEP_TURNS_MIN}〜${KEEP_TURNS_MAX} の整数`);
|
|
39
|
+
}
|
|
40
|
+
else
|
|
41
|
+
keepTurns = parsed;
|
|
42
|
+
}
|
|
43
|
+
let autoBytes;
|
|
44
|
+
if (autoBytesValue !== undefined) {
|
|
45
|
+
const parsed = parseAutoBytes(autoBytesValue);
|
|
46
|
+
if (parsed === null) {
|
|
47
|
+
autoBytes = 0;
|
|
48
|
+
warnings.push(`設定の compactionAutoBytes が不正なため自動圧縮は行いません。0(無効)か ${AUTO_BYTES_MIN}〜${AUTO_BYTES_MAX} の整数`);
|
|
49
|
+
}
|
|
50
|
+
else
|
|
51
|
+
autoBytes = parsed;
|
|
52
|
+
}
|
|
53
|
+
return { settings: { keepTurns, autoBytes }, warnings };
|
|
54
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { randomInt } from 'node:crypto';
|
|
2
|
+
const celebrations = [
|
|
3
|
+
String.raw ` \ | /
|
|
4
|
+
-(°∀°)- /\_/\
|
|
5
|
+
/ | \ ∩(・∀・)∩`,
|
|
6
|
+
String.raw ` /) /)
|
|
7
|
+
(。・ω・。)っ ☆
|
|
8
|
+
c(_つ_ノ`,
|
|
9
|
+
String.raw ` + *
|
|
10
|
+
/\_/\
|
|
11
|
+
ヽ(^▽^)ノ ♪
|
|
12
|
+
/ /`,
|
|
13
|
+
String.raw ` ♪ ʕ•ᴥ•ʔ ♪
|
|
14
|
+
へ( )へ
|
|
15
|
+
/ >`,
|
|
16
|
+
String.raw ` .-.
|
|
17
|
+
(•ө•) ♪
|
|
18
|
+
<( )>
|
|
19
|
+
^ ^`,
|
|
20
|
+
String.raw ` /\ /\
|
|
21
|
+
( ゚∀゚)人(゚∀゚ )
|
|
22
|
+
/_/ \_)`,
|
|
23
|
+
String.raw ` ☆
|
|
24
|
+
/_\
|
|
25
|
+
\(^o^)/
|
|
26
|
+
| |`,
|
|
27
|
+
String.raw ` * \o/ *
|
|
28
|
+
o | o
|
|
29
|
+
\ / \ /
|
|
30
|
+
'-------'`,
|
|
31
|
+
String.raw ` /\ *
|
|
32
|
+
/ \
|
|
33
|
+
| () | ↑
|
|
34
|
+
/|__|\
|
|
35
|
+
vv`,
|
|
36
|
+
String.raw ` __________
|
|
37
|
+
( ・∀・ )
|
|
38
|
+
\ /
|
|
39
|
+
'----'
|
|
40
|
+
_||_`,
|
|
41
|
+
];
|
|
42
|
+
/** Deal every picture once per round, keeping adjacent rounds distinct too. */
|
|
43
|
+
export function completionArtPicker() {
|
|
44
|
+
let deck = [];
|
|
45
|
+
let previous;
|
|
46
|
+
return () => {
|
|
47
|
+
if (!deck.length) {
|
|
48
|
+
deck = [...celebrations];
|
|
49
|
+
for (let i = deck.length - 1; i > 0; i--) {
|
|
50
|
+
const j = randomInt(i + 1);
|
|
51
|
+
[deck[i], deck[j]] = [deck[j], deck[i]];
|
|
52
|
+
}
|
|
53
|
+
const last = deck.length - 1;
|
|
54
|
+
if (deck[last] === previous) {
|
|
55
|
+
const j = randomInt(last);
|
|
56
|
+
[deck[last], deck[j]] = [deck[j], deck[last]];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
previous = deck.pop();
|
|
60
|
+
return `${previous} < 作業が終わったよ!`;
|
|
61
|
+
};
|
|
62
|
+
}
|
package/dist/cli/config.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface LiteConfig {
|
|
|
7
7
|
memory: MemoryConfig;
|
|
8
8
|
/** Validated per plugin by the subagent boundary; malformed entries fail closed. */
|
|
9
9
|
subagents?: unknown;
|
|
10
|
+
subagentLimit?: unknown;
|
|
10
11
|
/** Validated by parseLanguageSettings; malformed values fall back to defaults. */
|
|
11
12
|
language?: unknown;
|
|
12
13
|
/** all | workspace | none. Validated by parsePermissionPolicy; malformed values fall back. */
|
|
@@ -20,6 +21,14 @@ export interface LiteConfig {
|
|
|
20
21
|
reasoning?: unknown;
|
|
21
22
|
/** モデル応答の無通信タイムアウト(ms)。1〜上限で検証し、不正値は使わない。 */
|
|
22
23
|
timeoutMs?: unknown;
|
|
24
|
+
/** 圧縮で生のまま残す直近ターン数。parseKeepTurns で検証する。 */
|
|
25
|
+
compactionKeepTurns?: unknown;
|
|
26
|
+
/**
|
|
27
|
+
* 会話本文がこのサイズ(推定UTF-8バイト)に達したら自動で圧縮する。既定では入力トークン数を使う、0で無効。
|
|
28
|
+
* トークン数やプロバイダーのコンテキスト上限とは別の目安。
|
|
29
|
+
*/
|
|
30
|
+
compactionAutoBytes?: unknown;
|
|
31
|
+
modelContextWindows?: Record<string, unknown>;
|
|
23
32
|
diagnostics?: string[];
|
|
24
33
|
}
|
|
25
34
|
export declare const DEFAULT_CONFIG: LiteConfig;
|
package/dist/cli/config.js
CHANGED
|
@@ -32,7 +32,7 @@ export function defaultConfig() {
|
|
|
32
32
|
return { ...DEFAULT_CONFIG, memory: { ...DEFAULT_CONFIG.memory } };
|
|
33
33
|
}
|
|
34
34
|
/** 書き込み時に意味を持つ既知のキー。これ以外は利用者の手書き設定として保持する。 */
|
|
35
|
-
const KNOWN_KEYS = new Set(['memory', 'subagents', 'language', 'permissions', 'maxTurns', 'model', 'modelBaseUrl', 'reasoning', 'timeoutMs']);
|
|
35
|
+
const KNOWN_KEYS = new Set(['memory', 'subagents', 'subagentLimit', 'language', 'permissions', 'maxTurns', 'model', 'modelBaseUrl', 'reasoning', 'timeoutMs']);
|
|
36
36
|
function readRawConfig() {
|
|
37
37
|
try {
|
|
38
38
|
return fs.readFileSync(configPath(), 'utf8');
|
|
@@ -59,6 +59,7 @@ function toLiteConfig(parsed) {
|
|
|
59
59
|
: undefined;
|
|
60
60
|
return {
|
|
61
61
|
subagents: parsed.subagents,
|
|
62
|
+
subagentLimit: parsed.subagentLimit,
|
|
62
63
|
language: parsed.language,
|
|
63
64
|
permissions: parsed.permissions,
|
|
64
65
|
maxTurns: parsed.maxTurns,
|
|
@@ -66,6 +67,9 @@ function toLiteConfig(parsed) {
|
|
|
66
67
|
modelBaseUrl: parsed.modelBaseUrl,
|
|
67
68
|
reasoning: parsed.reasoning,
|
|
68
69
|
timeoutMs: parsed.timeoutMs,
|
|
70
|
+
compactionKeepTurns: parsed.compactionKeepTurns,
|
|
71
|
+
compactionAutoBytes: parsed.compactionAutoBytes,
|
|
72
|
+
modelContextWindows: parsed.modelContextWindows,
|
|
69
73
|
memory: {
|
|
70
74
|
enabled: memory?.enabled === true,
|
|
71
75
|
command: memory?.command ?? DEFAULT_CONFIG.memory.command,
|
package/dist/cli/editor.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare function chars(text: string): string[];
|
|
2
2
|
export declare function clean(text: string): string;
|
|
3
|
+
export declare function cellWidth(char: string, column?: number): number;
|
|
3
4
|
export declare function textWidth(text: string): number;
|
|
4
5
|
export declare function fitText(text: string, width: number): string;
|
|
5
6
|
export interface CursorPosition {
|
|
@@ -12,5 +13,11 @@ export declare function editorLayout(text: string, width: number): {
|
|
|
12
13
|
positions: CursorPosition[];
|
|
13
14
|
};
|
|
14
15
|
export declare function wrap(text: string, width: number): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Transcript wrapping: same cell budget as `wrap`, but it prefers a break after a space or
|
|
18
|
+
* Japanese punctuation so a copied line does not split a token such as `headBudget+tailBudget`.
|
|
19
|
+
* A token wider than the line is still hard-split; nothing is dropped.
|
|
20
|
+
*/
|
|
21
|
+
export declare function wrapText(text: string, width: number): string[];
|
|
15
22
|
export declare function verticalCursor(text: string, cursor: number, width: number, delta: number): number;
|
|
16
23
|
export declare function lineEdge(text: string, cursor: number, edge: 'start' | 'end'): number;
|
package/dist/cli/editor.js
CHANGED
|
@@ -2,18 +2,20 @@ import { stripVTControlCharacters } from 'node:util';
|
|
|
2
2
|
const segments = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
|
|
3
3
|
export function chars(text) { return [...segments.segment(text)].map(s => s.segment); }
|
|
4
4
|
export function clean(text) { return stripVTControlCharacters(text).replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, ''); }
|
|
5
|
-
function cellWidth(char) {
|
|
5
|
+
export function cellWidth(char, column = 0) {
|
|
6
|
+
if (char === '\t')
|
|
7
|
+
return 8 - column % 8;
|
|
6
8
|
if (/\p{Extended_Pictographic}/u.test(char))
|
|
7
9
|
return 2;
|
|
8
10
|
const cp = char.codePointAt(0);
|
|
9
11
|
return cp >= 0x1100 && (cp <= 0x115f || cp >= 0x2e80 && cp <= 0xa4cf || cp >= 0xac00 && cp <= 0xd7a3
|
|
10
12
|
|| cp >= 0xf900 && cp <= 0xfaff || cp >= 0xfe10 && cp <= 0xfe6f || cp >= 0xff00 && cp <= 0xff60 || cp >= 0x20000) ? 2 : 1;
|
|
11
13
|
}
|
|
12
|
-
export function textWidth(text) { return chars(clean(text)).reduce((sum, c) => sum + cellWidth(c), 0); }
|
|
14
|
+
export function textWidth(text) { return chars(clean(text)).reduce((sum, c) => sum + cellWidth(c, sum), 0); }
|
|
13
15
|
export function fitText(text, width) {
|
|
14
16
|
let result = '', used = 0;
|
|
15
17
|
for (const c of chars(clean(text))) {
|
|
16
|
-
const n = cellWidth(c);
|
|
18
|
+
const n = cellWidth(c, used);
|
|
17
19
|
if (used + n > width)
|
|
18
20
|
break;
|
|
19
21
|
result += c;
|
|
@@ -26,7 +28,7 @@ export function editorLayout(text, width) {
|
|
|
26
28
|
const parts = chars(text), lines = [], positions = [];
|
|
27
29
|
let line = '', column = 0;
|
|
28
30
|
for (let i = 0; i < parts.length; i++) {
|
|
29
|
-
const c = parts[i], n = c === '\n' ? 0 : cellWidth(c);
|
|
31
|
+
const c = parts[i], n = c === '\n' ? 0 : cellWidth(c, column);
|
|
30
32
|
if (c !== '\n' && column + n > width) {
|
|
31
33
|
lines.push(line);
|
|
32
34
|
line = '';
|
|
@@ -40,7 +42,7 @@ export function editorLayout(text, width) {
|
|
|
40
42
|
}
|
|
41
43
|
else {
|
|
42
44
|
line += c;
|
|
43
|
-
column +=
|
|
45
|
+
column += cellWidth(c, column);
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
positions[parts.length] = { row: lines.length, column };
|
|
@@ -48,6 +50,42 @@ export function editorLayout(text, width) {
|
|
|
48
50
|
return { lines, positions };
|
|
49
51
|
}
|
|
50
52
|
export function wrap(text, width) { return editorLayout(clean(text), width).lines; }
|
|
53
|
+
/** Characters a line may break AFTER without splitting a word (CJK punctuation and spaces). */
|
|
54
|
+
const BREAK_AFTER = /[ \t、。,.,.;:!?!?))」』】〕》〉〉\]}}ぁ-んァ-ヶ一-龠々ー…]/u;
|
|
55
|
+
/**
|
|
56
|
+
* Transcript wrapping: same cell budget as `wrap`, but it prefers a break after a space or
|
|
57
|
+
* Japanese punctuation so a copied line does not split a token such as `headBudget+tailBudget`.
|
|
58
|
+
* A token wider than the line is still hard-split; nothing is dropped.
|
|
59
|
+
*/
|
|
60
|
+
export function wrapText(text, width) {
|
|
61
|
+
const out = [];
|
|
62
|
+
for (const logical of clean(text).split('\n')) {
|
|
63
|
+
let line = '', used = 0;
|
|
64
|
+
let pending = ''; // the tail after the last break opportunity on this line
|
|
65
|
+
for (const c of chars(logical)) {
|
|
66
|
+
if (used + cellWidth(c, used) > width && pending.length > 0 && pending.length < line.length) {
|
|
67
|
+
out.push(line.slice(0, line.length - pending.length));
|
|
68
|
+
line = pending;
|
|
69
|
+
used = textWidth(pending);
|
|
70
|
+
pending = '';
|
|
71
|
+
}
|
|
72
|
+
if (used + cellWidth(c, used) > width) {
|
|
73
|
+
out.push(line);
|
|
74
|
+
line = '';
|
|
75
|
+
used = 0;
|
|
76
|
+
pending = '';
|
|
77
|
+
}
|
|
78
|
+
line += c;
|
|
79
|
+
used += cellWidth(c, used);
|
|
80
|
+
if (BREAK_AFTER.test(c))
|
|
81
|
+
pending = '';
|
|
82
|
+
else
|
|
83
|
+
pending += c;
|
|
84
|
+
}
|
|
85
|
+
out.push(line);
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
51
89
|
export function verticalCursor(text, cursor, width, delta) {
|
|
52
90
|
const layout = editorLayout(text, width), current = layout.positions[cursor];
|
|
53
91
|
const row = Math.max(0, Math.min(layout.lines.length - 1, current.row + delta));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type FileMention = {
|
|
2
|
+
start: number;
|
|
3
|
+
end: number;
|
|
4
|
+
query: string;
|
|
5
|
+
};
|
|
6
|
+
export type FileCandidate = {
|
|
7
|
+
path: string;
|
|
8
|
+
directory: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function activeFileMention(text: string, cursor: number): FileMention | undefined;
|
|
11
|
+
export declare function formatFileMention(file: string): string;
|
|
12
|
+
export declare function fileCandidates(root: string, query: string, acceptFile?: (name: string) => boolean): FileCandidate[];
|
|
13
|
+
/** Return model context only; never echo attachment contents into the terminal. */
|
|
14
|
+
export declare function readFileMentions(root: string, input: string): string | undefined;
|