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,11 @@
|
|
|
1
|
+
import { type ImageAttachment } from '../agent/images.ts';
|
|
2
|
+
/** Read only on an explicit Ctrl+V. No clipboard text, files, credentials or network access. */
|
|
3
|
+
export declare const MAC_IMAGE_SCRIPT = "\nObjC.import('AppKit');\nObjC.import('Foundation');\nconst board = $.NSPasteboard.generalPasteboard;\nconst revision = Number(board.changeCount);\nlet data = board.dataForType('public.png');\nif (data.isNil()) {\n const tiff = board.dataForType('public.tiff');\n if (tiff.isNil()) throw new Error('\u30AF\u30EA\u30C3\u30D7\u30DC\u30FC\u30C9\u306B\u753B\u50CF\u304C\u3042\u308A\u307E\u305B\u3093');\n if (Number(tiff.length) > 40 * 1024 * 1024) throw new Error('\u753B\u50CF\u304C\u5927\u304D\u3059\u304E\u307E\u3059');\n const bitmap = $.NSBitmapImageRep.imageRepWithData(tiff);\n if (bitmap.isNil()) throw new Error('\u753B\u50CF\u3092\u8AAD\u307F\u53D6\u308C\u307E\u305B\u3093');\n if (Number(bitmap.pixelsWide) * Number(bitmap.pixelsHigh) > 40000000) throw new Error('\u753B\u50CF\u306F4,000\u4E07\u753B\u7D20\u4EE5\u5185\u306B\u3057\u3066\u304F\u3060\u3055\u3044');\n data = bitmap.representationUsingTypeProperties($.NSBitmapImageFileTypePNG, $.NSDictionary.dictionary);\n}\nif (data.isNil()) throw new Error('PNG\u3078\u306E\u5909\u63DB\u306B\u5931\u6557\u3057\u307E\u3057\u305F');\nif (Number(data.length) > 5242880) throw new Error('\u753B\u50CF\u306F1\u679A5 MiB\u4EE5\u5185\u306B\u3057\u3066\u304F\u3060\u3055\u3044');\nif (Number(board.changeCount) !== revision) throw new Error('\u30AF\u30EA\u30C3\u30D7\u30DC\u30FC\u30C9\u304C\u5909\u66F4\u3055\u308C\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6Ctrl+V\u3057\u3066\u304F\u3060\u3055\u3044');\nJSON.stringify({mediaType:'image/png', data:ObjC.unwrap(data.base64EncodedStringWithOptions(0))});\n";
|
|
4
|
+
export type ClipboardReader = (signal: AbortSignal) => Promise<ImageAttachment>;
|
|
5
|
+
export type ClipboardCommand = (signal: AbortSignal) => Promise<string>;
|
|
6
|
+
export declare function readClipboardImage(signal: AbortSignal, options?: {
|
|
7
|
+
platform?: string;
|
|
8
|
+
command?: ClipboardCommand;
|
|
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>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { pipeline } from 'node:stream/promises';
|
|
3
|
+
import { MAX_IMAGE_BYTES, parseImage } from "../agent/images.js";
|
|
4
|
+
/** Read only on an explicit Ctrl+V. No clipboard text, files, credentials or network access. */
|
|
5
|
+
export const MAC_IMAGE_SCRIPT = `
|
|
6
|
+
ObjC.import('AppKit');
|
|
7
|
+
ObjC.import('Foundation');
|
|
8
|
+
const board = $.NSPasteboard.generalPasteboard;
|
|
9
|
+
const revision = Number(board.changeCount);
|
|
10
|
+
let data = board.dataForType('public.png');
|
|
11
|
+
if (data.isNil()) {
|
|
12
|
+
const tiff = board.dataForType('public.tiff');
|
|
13
|
+
if (tiff.isNil()) throw new Error('クリップボードに画像がありません');
|
|
14
|
+
if (Number(tiff.length) > 40 * 1024 * 1024) throw new Error('画像が大きすぎます');
|
|
15
|
+
const bitmap = $.NSBitmapImageRep.imageRepWithData(tiff);
|
|
16
|
+
if (bitmap.isNil()) throw new Error('画像を読み取れません');
|
|
17
|
+
if (Number(bitmap.pixelsWide) * Number(bitmap.pixelsHigh) > 40000000) throw new Error('画像は4,000万画素以内にしてください');
|
|
18
|
+
data = bitmap.representationUsingTypeProperties($.NSBitmapImageFileTypePNG, $.NSDictionary.dictionary);
|
|
19
|
+
}
|
|
20
|
+
if (data.isNil()) throw new Error('PNGへの変換に失敗しました');
|
|
21
|
+
if (Number(data.length) > ${MAX_IMAGE_BYTES}) throw new Error('画像は1枚5 MiB以内にしてください');
|
|
22
|
+
if (Number(board.changeCount) !== revision) throw new Error('クリップボードが変更されました。もう一度Ctrl+Vしてください');
|
|
23
|
+
JSON.stringify({mediaType:'image/png', data:ObjC.unwrap(data.base64EncodedStringWithOptions(0))});
|
|
24
|
+
`;
|
|
25
|
+
function macClipboardCommand(signal) {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
execFile('/usr/bin/osascript', ['-l', 'JavaScript', '-e', MAC_IMAGE_SCRIPT], {
|
|
28
|
+
signal, timeout: 5000, killSignal: 'SIGKILL', encoding: 'utf8',
|
|
29
|
+
maxBuffer: Math.ceil(MAX_IMAGE_BYTES / 3) * 4 + 4096,
|
|
30
|
+
env: { PATH: '/usr/bin:/bin', HOME: process.env.HOME, TMPDIR: process.env.TMPDIR, LANG: process.env.LANG },
|
|
31
|
+
}, (error, stdout, stderr) => {
|
|
32
|
+
if (error)
|
|
33
|
+
reject(new Error(signal.aborted ? '画像の読み取りを中止しました' : `画像を貼り付けられません: ${stderr.trim().slice(0, 240) || error.message}`));
|
|
34
|
+
else
|
|
35
|
+
resolve(stdout);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
export async function readClipboardImage(signal, options = {}) {
|
|
40
|
+
signal.throwIfAborted();
|
|
41
|
+
if ((options.platform ?? process.platform) !== 'darwin')
|
|
42
|
+
throw new Error('Ctrl+Vの画像貼り付けは現在macOSのみ対応しています');
|
|
43
|
+
const output = await (options.command ?? macClipboardCommand)(signal);
|
|
44
|
+
signal.throwIfAborted();
|
|
45
|
+
if (output.length > Math.ceil(MAX_IMAGE_BYTES / 3) * 4 + 1024)
|
|
46
|
+
throw new Error('画像が大きすぎます');
|
|
47
|
+
let value;
|
|
48
|
+
try {
|
|
49
|
+
value = JSON.parse(output);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
throw new Error('クリップボードの画像を読み取れませんでした');
|
|
53
|
+
}
|
|
54
|
+
return parseImage(value);
|
|
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
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export type Background = 'dark' | 'light';
|
|
2
|
+
export interface Palette {
|
|
3
|
+
reasoning: string;
|
|
4
|
+
user: string;
|
|
5
|
+
tool: string;
|
|
6
|
+
result: string;
|
|
7
|
+
system: string;
|
|
8
|
+
heading: string;
|
|
9
|
+
accent: string;
|
|
10
|
+
diffAdd: string;
|
|
11
|
+
diffDel: string;
|
|
12
|
+
diffMeta: string;
|
|
13
|
+
codeComment: string;
|
|
14
|
+
codeString: string;
|
|
15
|
+
codeNumber: string;
|
|
16
|
+
codeKeyword: string;
|
|
17
|
+
}
|
|
18
|
+
/** ダーク背景は明るい標準色、ライト背景は256色パレットの暗い色。 */
|
|
19
|
+
export declare function paletteFor(background: Background): Palette;
|
|
20
|
+
/** `rgb:rrrr/gggg/bbbb` または `color:0/9` 形式の OSC 11 応答を解析する。 */
|
|
21
|
+
export declare function parseOscBackground(text: string): string | null;
|
|
22
|
+
/** 0〜65535 の16進3成分から輝度を0..1で出す。 */
|
|
23
|
+
export declare function backgroundLuminance(osc: string): number | null;
|
|
24
|
+
/** OSC応答または COLORFGBG 環境変数から背景を分類する。根拠がなければ null。 */
|
|
25
|
+
export declare function classifyBackground(oscReply: string | null, env?: NodeJS.ProcessEnv): 'dark' | 'light' | null;
|
|
26
|
+
/** コード fenced block 内の1行を簡易ハイライトする。 */
|
|
27
|
+
export declare function highlightCodeLine(line: string, palette: Palette): string;
|
|
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';
|
|
39
|
+
export interface ColorizerState {
|
|
40
|
+
answerFence?: string;
|
|
41
|
+
mode: ColorMode;
|
|
42
|
+
inDiff: boolean;
|
|
43
|
+
inToolOutput: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** コードブロックとdiffの状態を行間で引き継いで色を付ける。 */
|
|
46
|
+
export declare class TranscriptColorizer {
|
|
47
|
+
private answerFence?;
|
|
48
|
+
private mode;
|
|
49
|
+
private inDiff;
|
|
50
|
+
/** Set while drawing the body of one tool result, cleared by the next `▶` line or blank line. */
|
|
51
|
+
private inToolOutput;
|
|
52
|
+
/** 完成行までの状態を保存しておき、未完了行(ライブ表示)の色分けに複製する。 */
|
|
53
|
+
state(): ColorizerState;
|
|
54
|
+
restore(state: ColorizerState): void;
|
|
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;
|
|
58
|
+
private diffLine;
|
|
59
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* トランスクリプトの行単位の色分け。外部依存なし。
|
|
3
|
+
* - 推論はグレー、回答は Markdown の強調やコードを端末のスタイルで表示
|
|
4
|
+
* - diff(+/-/@@/---/+++)は追加=緑・削除=赤
|
|
5
|
+
* - ``` コードブロック内は簡易トークナイザー(文字列・コメント・キーワード・数値)
|
|
6
|
+
* ライト/ダーク両方で読みやすいよう背景判定ごとにパレットを替える。
|
|
7
|
+
*/
|
|
8
|
+
import { answerMarkdown } from "./answer-markdown.js";
|
|
9
|
+
import { stripVTControlCharacters } from 'node:util';
|
|
10
|
+
/** ダーク背景は明るい標準色、ライト背景は256色パレットの暗い色。 */
|
|
11
|
+
export function paletteFor(background) {
|
|
12
|
+
return background === 'dark'
|
|
13
|
+
? {
|
|
14
|
+
reasoning: '90', result: '90', system: '90',
|
|
15
|
+
user: '1', heading: '1', accent: '36', tool: '94',
|
|
16
|
+
diffAdd: '92', diffDel: '91', diffMeta: '96',
|
|
17
|
+
codeComment: '90', codeString: '33',
|
|
18
|
+
codeNumber: '95', codeKeyword: '94',
|
|
19
|
+
}
|
|
20
|
+
: {
|
|
21
|
+
reasoning: '90', result: '90', system: '90',
|
|
22
|
+
user: '1', heading: '1', accent: '36', tool: '38;5;26',
|
|
23
|
+
diffAdd: '38;5;28', diffDel: '38;5;160', diffMeta: '38;5;30',
|
|
24
|
+
codeComment: '38;5;242', codeString: '38;5;130',
|
|
25
|
+
codeNumber: '38;5;52', codeKeyword: '38;5;19',
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** `rgb:rrrr/gggg/bbbb` または `color:0/9` 形式の OSC 11 応答を解析する。 */
|
|
29
|
+
export function parseOscBackground(text) {
|
|
30
|
+
const match = /\x1b]11;([^\x07\x1b]*)/.exec(text);
|
|
31
|
+
if (match === null)
|
|
32
|
+
return null;
|
|
33
|
+
return stripVTControlCharacters(match[1]).trim() || null;
|
|
34
|
+
}
|
|
35
|
+
/** 0〜65535 の16進3成分から輝度を0..1で出す。 */
|
|
36
|
+
export function backgroundLuminance(osc) {
|
|
37
|
+
const rgb = /rgb:([0-9a-fA-F]+)\/([0-9a-fA-F]+)\/([0-9a-fA-F]+)/.exec(osc)
|
|
38
|
+
?? /rgba?:([0-9a-fA-F]+)\/([0-9a-fA-F]+)\/([0-9a-fA-F]+)/.exec(osc);
|
|
39
|
+
if (rgb !== null) {
|
|
40
|
+
const components = [rgb[1], rgb[2], rgb[3]].map((c) => parseInt(c, 16) / (16 ** c.length - 1));
|
|
41
|
+
if (components.some((n) => !Number.isFinite(n)))
|
|
42
|
+
return null;
|
|
43
|
+
return 0.2126 * components[0] + 0.7152 * components[1] + 0.0722 * components[2];
|
|
44
|
+
}
|
|
45
|
+
const gray = /^(\d+)$/.exec(osc.trim());
|
|
46
|
+
if (gray !== null) {
|
|
47
|
+
const n = Number(gray[1]);
|
|
48
|
+
return Number.isFinite(n) ? n / 255 : null;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
/** OSC応答または COLORFGBG 環境変数から背景を分類する。根拠がなければ null。 */
|
|
53
|
+
export function classifyBackground(oscReply, env) {
|
|
54
|
+
if (oscReply !== null) {
|
|
55
|
+
const l = backgroundLuminance(oscReply);
|
|
56
|
+
if (l !== null)
|
|
57
|
+
return l < 0.5 ? 'dark' : 'light';
|
|
58
|
+
}
|
|
59
|
+
const fgbg = env?.['COLORFGBG'];
|
|
60
|
+
if (typeof fgbg === 'string' && /;/.test(fgbg)) {
|
|
61
|
+
const bg = Number(fgbg.split(';').at(-1));
|
|
62
|
+
// 0-6 暗い色、7/8-15 明るい色(xterm系の慣習)。15以上は256色拡張。
|
|
63
|
+
if (Number.isFinite(bg)) {
|
|
64
|
+
if (bg <= 6)
|
|
65
|
+
return 'dark';
|
|
66
|
+
if (bg >= 8 && bg <= 15)
|
|
67
|
+
return 'light';
|
|
68
|
+
if (bg >= 16)
|
|
69
|
+
return bg >= 238 ? 'dark' : 'light';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
/** 汎用キーワード群(C/JS/TS/Python/Rust/Go/Ruby/Shell など)。誤着色より無着色を避ける単純リスト。 */
|
|
75
|
+
const KEYWORDS = [
|
|
76
|
+
'function', 'const', 'let', 'var', 'return', 'if', 'else', 'elif', 'for', 'while', 'class', 'import', 'export',
|
|
77
|
+
'from', 'def', 'async', 'await', 'type', 'interface', 'extends', 'implements', 'new', 'try', 'catch', 'finally',
|
|
78
|
+
'throw', 'switch', 'case', 'break', 'continue', 'do', 'in', 'of', 'null', 'true', 'false', 'void', 'static',
|
|
79
|
+
'public', 'private', 'protected', 'this', 'super', 'yield', 'match', 'struct', 'impl', 'trait', 'fn', 'pub',
|
|
80
|
+
'use', 'mod', 'self', 'None', 'Some', 'end', 'local', 'require', 'lambda', 'package', 'func', 'range',
|
|
81
|
+
'select', 'defer', 'go', 'with', 'unless', 'until', 'nil', 'then', 'fi', 'esac', 'echo', 'done', 'set',
|
|
82
|
+
];
|
|
83
|
+
const TOKEN_PATTERN = new RegExp([
|
|
84
|
+
'(\\/\\/[^\\n]*|--[^\\n]*)', // 行コメント(/ / --)
|
|
85
|
+
'(#[^\\n]*)', // # コメント(shell/ruby/python風)
|
|
86
|
+
'("(?:[^"\\\\]|\\\\.)*"|\'(?:[^\'\\\\]|\\\\.)*\'|`(?:[^`\\\\]|\\\\.)*`)',
|
|
87
|
+
'\\b(\\d+(?:\\.\\d+)*)\\b',
|
|
88
|
+
`\\b(${KEYWORDS.join('|')})\\b`,
|
|
89
|
+
].join('|'), 'g');
|
|
90
|
+
/** コード fenced block 内の1行を簡易ハイライトする。 */
|
|
91
|
+
export function highlightCodeLine(line, palette) {
|
|
92
|
+
return line.replace(TOKEN_PATTERN, (match, lineComment, hashComment, str, num, keyword) => {
|
|
93
|
+
const code = lineComment !== undefined || hashComment !== undefined ? palette.codeComment
|
|
94
|
+
: str !== undefined ? palette.codeString
|
|
95
|
+
: num !== undefined ? palette.codeNumber
|
|
96
|
+
: palette.codeKeyword;
|
|
97
|
+
return `\x1b[${code}m${match}\x1b[0m`;
|
|
98
|
+
});
|
|
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の状態を行間で引き継いで色を付ける。 */
|
|
120
|
+
export class TranscriptColorizer {
|
|
121
|
+
answerFence;
|
|
122
|
+
mode = 'text';
|
|
123
|
+
inDiff = false;
|
|
124
|
+
/** Set while drawing the body of one tool result, cleared by the next `▶` line or blank line. */
|
|
125
|
+
inToolOutput = false;
|
|
126
|
+
/** 完成行までの状態を保存しておき、未完了行(ライブ表示)の色分けに複製する。 */
|
|
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);
|
|
143
|
+
}
|
|
144
|
+
if (fence && !(fence[1][0] === '`' && fence[2].includes('`'))) {
|
|
145
|
+
this.answerFence = fence[1];
|
|
146
|
+
return '';
|
|
147
|
+
}
|
|
148
|
+
return answerMarkdown(raw, palette);
|
|
149
|
+
}
|
|
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') {
|
|
169
|
+
if (/^(\s*)(```|~~~)/.test(raw)) {
|
|
170
|
+
this.mode = 'text';
|
|
171
|
+
return `\x1b[${palette.reasoning}m${raw}\x1b[0m`;
|
|
172
|
+
}
|
|
173
|
+
return highlightCodeLine(raw, palette);
|
|
174
|
+
}
|
|
175
|
+
if (blank) {
|
|
176
|
+
this.inToolOutput = false;
|
|
177
|
+
return raw;
|
|
178
|
+
}
|
|
179
|
+
if (/^(\s*)(```|~~~)/.test(raw)) {
|
|
180
|
+
this.mode = 'code';
|
|
181
|
+
return `\x1b[${palette.reasoning}m${raw}\x1b[0m`;
|
|
182
|
+
}
|
|
183
|
+
const diff = this.diffLine(trimmed, raw, palette);
|
|
184
|
+
if (diff !== null)
|
|
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
|
+
}
|
|
197
|
+
if (/^#{1,6} /.test(trimmed))
|
|
198
|
+
return `\x1b[${palette.heading}m${raw}\x1b[0m`;
|
|
199
|
+
if (/^▶ You:/.test(raw))
|
|
200
|
+
return `\x1b[${palette.user}m${raw}\x1b[0m`;
|
|
201
|
+
if (/^▶ /.test(raw)) {
|
|
202
|
+
this.inToolOutput = false;
|
|
203
|
+
return `\x1b[${palette.tool}m${raw}\x1b[0m`;
|
|
204
|
+
}
|
|
205
|
+
if (/^\(承認\)|^\(拒否\)|^\(中断|^\(接続|^\(モデル|^\(推論/.test(trimmed)
|
|
206
|
+
|| /^ {0,2}\(結果\./.test(trimmed) || /^ {0,2}\(結果:/.test(raw) || /^ {0,2}\(エラー/.test(trimmed)) {
|
|
207
|
+
this.inDiff = false;
|
|
208
|
+
this.inToolOutput = /^ {0,2}\(結果:/.test(raw);
|
|
209
|
+
return `\x1b[${palette.result}m${raw}\x1b[0m`;
|
|
210
|
+
}
|
|
211
|
+
if (/^\[exit code/.test(trimmed))
|
|
212
|
+
return `\x1b[${palette.result}m${raw}\x1b[0m`;
|
|
213
|
+
return raw;
|
|
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
|
+
}
|
|
220
|
+
diffLine(trimmed, raw, palette) {
|
|
221
|
+
if (/^--- 承認要求/.test(raw)) {
|
|
222
|
+
this.inDiff = false;
|
|
223
|
+
return `\x1b[${palette.system}m${raw}\x1b[0m`;
|
|
224
|
+
}
|
|
225
|
+
if (/^--- /.test(raw) && !this.inDiff) {
|
|
226
|
+
this.inDiff = true;
|
|
227
|
+
return `\x1b[${palette.diffMeta}m${raw}\x1b[0m`;
|
|
228
|
+
}
|
|
229
|
+
if (!this.inDiff)
|
|
230
|
+
return null;
|
|
231
|
+
if (/^\+\+\+ /.test(raw))
|
|
232
|
+
return `\x1b[${palette.diffMeta}m${raw}\x1b[0m`;
|
|
233
|
+
if (/^@@/.test(raw))
|
|
234
|
+
return `\x1b[${palette.diffMeta}m${raw}\x1b[0m`;
|
|
235
|
+
if (/^\+ /.test(raw))
|
|
236
|
+
return `\x1b[${palette.diffAdd}m${raw}\x1b[0m`;
|
|
237
|
+
if (/^- /.test(raw))
|
|
238
|
+
return `\x1b[${palette.diffDel}m${raw}\x1b[0m`;
|
|
239
|
+
if (/^ {2}/.test(raw))
|
|
240
|
+
return raw; // 文脈行
|
|
241
|
+
this.inDiff = false;
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export interface MemoryConfig {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
command: string;
|
|
4
|
+
args: string[];
|
|
5
|
+
}
|
|
6
|
+
export interface LiteConfig {
|
|
7
|
+
memory: MemoryConfig;
|
|
8
|
+
/** Validated per plugin by the subagent boundary; malformed entries fail closed. */
|
|
9
|
+
subagents?: unknown;
|
|
10
|
+
subagentLimit?: unknown;
|
|
11
|
+
/** Validated by parseLanguageSettings; malformed values fall back to defaults. */
|
|
12
|
+
language?: unknown;
|
|
13
|
+
/** all | workspace | none. Validated by parsePermissionPolicy; malformed values fall back. */
|
|
14
|
+
permissions?: unknown;
|
|
15
|
+
/** Tool round-trip limit for one turn. Validated by parseMaxTurns; malformed values fall back. */
|
|
16
|
+
maxTurns?: unknown;
|
|
17
|
+
/** 前回接続したモデル(--base-url の情報は modelBaseUrl に残す)。起動時の復元に使う。 */
|
|
18
|
+
model?: unknown;
|
|
19
|
+
modelBaseUrl?: unknown;
|
|
20
|
+
/** 前回の /reasoning レベル。起動時に復元する。 */
|
|
21
|
+
reasoning?: unknown;
|
|
22
|
+
/** モデル応答の無通信タイムアウト(ms)。1〜上限で検証し、不正値は使わない。 */
|
|
23
|
+
timeoutMs?: unknown;
|
|
24
|
+
/** 圧縮で生のまま残す直近ターン数。parseKeepTurns で検証する。 */
|
|
25
|
+
compactionKeepTurns?: unknown;
|
|
26
|
+
/**
|
|
27
|
+
* 会話本文がこのサイズ(推定UTF-8バイト)に達したら自動で圧縮する。既定では入力トークン数を使う、0で無効。
|
|
28
|
+
* トークン数やプロバイダーのコンテキスト上限とは別の目安。
|
|
29
|
+
*/
|
|
30
|
+
compactionAutoBytes?: unknown;
|
|
31
|
+
modelContextWindows?: Record<string, unknown>;
|
|
32
|
+
diagnostics?: string[];
|
|
33
|
+
}
|
|
34
|
+
export declare const DEFAULT_CONFIG: LiteConfig;
|
|
35
|
+
/** タイムアウトは 5秒〜30分の整数で受ける。それ以外は無効値として扱う。 */
|
|
36
|
+
export declare const TIMEOUT_MS_MIN = 5000;
|
|
37
|
+
export declare const TIMEOUT_MS_MAX = 1800000;
|
|
38
|
+
export declare function parseTimeoutMs(value: unknown): number | null;
|
|
39
|
+
export declare function configDir(): string;
|
|
40
|
+
export declare function configPath(): string;
|
|
41
|
+
/** 既定値は毎回コピーして返す(呼び出し元が書き換えても共有しない)。 */
|
|
42
|
+
export declare function defaultConfig(): LiteConfig;
|
|
43
|
+
/** 一時ファイルに書いてrenameする。中断されても config.json が途中まで書かれた状態を残さない。 */
|
|
44
|
+
export declare function saveConfig(config: LiteConfig): void;
|
|
45
|
+
export declare function loadConfig(): LiteConfig;
|
|
46
|
+
/**
|
|
47
|
+
* 起動時に読んだ設定を壊さず1フィールドだけ更新する。書き込み前に実ファイルから
|
|
48
|
+
* 読み直すので、並行する別セッションの保存を失わない。
|
|
49
|
+
*/
|
|
50
|
+
export declare function updateConfig(apply: (config: LiteConfig) => void): void;
|