modkh 0.0.0-stage → 0.1.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 +24 -2
- package/dist/agent/bundled-skills.d.ts +13 -0
- package/dist/agent/bundled-skills.js +95 -0
- package/dist/agent/images.d.ts +10 -0
- package/dist/agent/images.js +33 -0
- package/dist/agent/loop.d.ts +56 -0
- package/dist/agent/loop.js +155 -0
- package/dist/agent/skills.d.ts +20 -0
- package/dist/agent/skills.js +169 -0
- package/dist/agent/types.d.ts +132 -0
- package/dist/agent/types.js +12 -0
- package/dist/cli/agents.d.ts +8 -0
- package/dist/cli/agents.js +12 -0
- package/dist/cli/approval.d.ts +27 -0
- package/dist/cli/approval.js +62 -0
- package/dist/cli/catalog.d.ts +39 -0
- package/dist/cli/catalog.js +76 -0
- package/dist/cli/chat.d.ts +18 -0
- package/dist/cli/chat.js +733 -0
- package/dist/cli/clipboard.d.ts +9 -0
- package/dist/cli/clipboard.js +54 -0
- package/dist/cli/color.d.ts +42 -0
- package/dist/cli/color.js +176 -0
- package/dist/cli/config.d.ts +41 -0
- package/dist/cli/config.js +188 -0
- package/dist/cli/editor.d.ts +16 -0
- package/dist/cli/editor.js +77 -0
- package/dist/cli/keys.d.ts +18 -0
- package/dist/cli/keys.js +82 -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/models.d.ts +4 -0
- package/dist/cli/models.js +69 -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 +46 -0
- package/dist/cli/providers.js +76 -0
- package/dist/cli/terminal.d.ts +143 -0
- package/dist/cli/terminal.js +742 -0
- package/dist/cli/usage.d.ts +29 -0
- package/dist/cli/usage.js +75 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +164 -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 +14 -0
- package/dist/language/commonlisp-install.js +213 -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 +337 -0
- package/dist/language/lsp/pool.d.ts +67 -0
- package/dist/language/lsp/pool.js +122 -0
- package/dist/language/lsp/service.d.ts +46 -0
- package/dist/language/lsp/service.js +138 -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 +24 -0
- package/dist/language/syntax/parser.js +144 -0
- package/dist/language/typescript-capability.d.ts +6 -0
- package/dist/language/typescript-capability.js +42 -0
- package/dist/lisp/config.d.ts +16 -0
- package/dist/lisp/config.js +159 -0
- package/dist/lisp/routing.d.ts +5 -0
- package/dist/lisp/routing.js +24 -0
- package/dist/lisp/runtime.d.ts +21 -0
- package/dist/lisp/runtime.js +83 -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 +180 -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 +202 -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 +65 -0
- package/dist/model/context.d.ts +9 -0
- package/dist/model/context.js +69 -0
- package/dist/model/factory.d.ts +25 -0
- package/dist/model/factory.js +88 -0
- package/dist/model/fixed.d.ts +17 -0
- package/dist/model/fixed.js +41 -0
- package/dist/model/reasoning.d.ts +16 -0
- package/dist/model/reasoning.js +62 -0
- package/dist/plugins/api.d.ts +60 -0
- package/dist/plugins/api.js +1 -0
- package/dist/plugins/manager.d.ts +34 -0
- package/dist/plugins/manager.js +261 -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 +82 -0
- package/dist/session/store.js +285 -0
- package/dist/session/workspace.d.ts +19 -0
- package/dist/session/workspace.js +73 -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 +21 -0
- package/dist/subagents/service.d.ts +39 -0
- package/dist/subagents/service.js +352 -0
- package/dist/subagents/settings.d.ts +10 -0
- package/dist/subagents/settings.js +32 -0
- package/dist/subagents/types.d.ts +43 -0
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/verification.d.ts +31 -0
- package/dist/subagents/verification.js +178 -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.d.ts +8 -0
- package/dist/tools/formal.js +77 -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 +77 -0
- package/dist/tools/jobs.js +181 -0
- package/dist/tools/language.d.ts +6 -0
- package/dist/tools/language.js +174 -0
- package/dist/tools/registry.d.ts +28 -0
- package/dist/tools/registry.js +105 -0
- package/dist/tools/run.d.ts +13 -0
- package/dist/tools/run.js +159 -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 +286 -0
- package/dist/tools/skills.d.ts +2 -0
- package/dist/tools/skills.js +46 -0
- package/dist/tools/web.d.ts +24 -0
- package/dist/tools/web.js +386 -0
- package/docs/ci-repair-20261116.md +30 -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 +100 -0
- package/docs/input.md +66 -0
- package/docs/languages.md +117 -0
- package/docs/models.md +85 -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 +124 -0
- package/docs/presets.md +19 -0
- package/docs/setup.md +112 -0
- package/docs/subagents.md +134 -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 +7 -0
- package/experiments/presets/html.lisp +38 -0
- package/experiments/presets/js.lisp +38 -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/package.json +49 -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,77 @@
|
|
|
1
|
+
import { ShellProcess, type ShellName } from './shell-process.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Background job registry.
|
|
4
|
+
*
|
|
5
|
+
* Ownership and lifetime are the registry's; running the command is the producer's. A job keeps
|
|
6
|
+
* its own output cursor so repeated reads return only what is new, and a settled job stays
|
|
7
|
+
* readable so a late `job_output` still reports how it ended.
|
|
8
|
+
*
|
|
9
|
+
* Registered jobs never outlive the owning session: `close()` stops every job and waits for the
|
|
10
|
+
* process groups to disappear, so MODKH cannot exit leaving orphaned children.
|
|
11
|
+
*/
|
|
12
|
+
export type JobStatus = 'running' | 'stopping' | 'completed' | 'killed' | 'failed';
|
|
13
|
+
export interface JobView {
|
|
14
|
+
id: string;
|
|
15
|
+
kind: 'bash';
|
|
16
|
+
/** First line of the command, is bounded, and is what the human sees. */
|
|
17
|
+
label: string;
|
|
18
|
+
command: string;
|
|
19
|
+
cwd: string;
|
|
20
|
+
shell: ShellName;
|
|
21
|
+
status: JobStatus;
|
|
22
|
+
startedAt: number;
|
|
23
|
+
finishedAt?: number;
|
|
24
|
+
/** Exit code once settled normally; never invented for a killed or failed job. */
|
|
25
|
+
exitCode?: number | null;
|
|
26
|
+
/** Why the job ended, when it did not simply exit. */
|
|
27
|
+
detail?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface JobStartRequest {
|
|
30
|
+
command: string;
|
|
31
|
+
cwd: string;
|
|
32
|
+
shell: ShellName;
|
|
33
|
+
description?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare class JobRegistry {
|
|
36
|
+
private readonly jobs;
|
|
37
|
+
private closed;
|
|
38
|
+
/** Settlements the model has not been told about yet, in completion order. */
|
|
39
|
+
private readonly notices;
|
|
40
|
+
/** Owner-visible label for a notice; never contains the command's full output. */
|
|
41
|
+
private noticeBytes;
|
|
42
|
+
get size(): number;
|
|
43
|
+
/** Drain pending completion notices. Returns [] when every settlement was already reported. */
|
|
44
|
+
takeNotices(): string[];
|
|
45
|
+
get hasNotices(): boolean;
|
|
46
|
+
private notice;
|
|
47
|
+
start(request: JobStartRequest): JobView;
|
|
48
|
+
/**
|
|
49
|
+
* Take ownership of a process that is already running.
|
|
50
|
+
*
|
|
51
|
+
* This is how a foreground command that reached its deadline keeps its work: the caller
|
|
52
|
+
* abandons its own await and the job registry continues to observe, report, and stop it.
|
|
53
|
+
* Everything already produced on stdout/stderr is available to the first `job_output`.
|
|
54
|
+
*/
|
|
55
|
+
adopt(process: ShellProcess, request: JobStartRequest): JobView;
|
|
56
|
+
private register;
|
|
57
|
+
list(): JobView[];
|
|
58
|
+
get(id: string): JobView | undefined;
|
|
59
|
+
private require;
|
|
60
|
+
/** Output appended since the previous read. The cursor advances only for a delivered read. */
|
|
61
|
+
read(id: string): {
|
|
62
|
+
job: JobView;
|
|
63
|
+
stdout: string;
|
|
64
|
+
stderr: string;
|
|
65
|
+
dropped: number;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Wait until the job settles, new output appears, or the timeout expires.
|
|
69
|
+
*
|
|
70
|
+
* Returning early on new output is what makes polling useful: a long build reports progress
|
|
71
|
+
* instead of forcing the caller to choose between blocking for minutes and busy-looping.
|
|
72
|
+
*/
|
|
73
|
+
wait(id: string, timeoutMs: number, signal?: AbortSignal): Promise<void>;
|
|
74
|
+
kill(id: string, reason?: string): Promise<JobView>;
|
|
75
|
+
/** Stop every job and wait for the process groups to settle. */
|
|
76
|
+
close(): Promise<void>;
|
|
77
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { ShellProcess } from "./shell-process.js";
|
|
3
|
+
const MAX_RETAINED_JOBS = 32;
|
|
4
|
+
const LABEL_MAX = 120;
|
|
5
|
+
function label(command, description) {
|
|
6
|
+
const text = (description?.trim() || command.trim().split('\n')[0] || command).replace(/\s+/g, ' ');
|
|
7
|
+
return text.length <= LABEL_MAX ? text : `${text.slice(0, LABEL_MAX - 1)}…`;
|
|
8
|
+
}
|
|
9
|
+
export class JobRegistry {
|
|
10
|
+
jobs = new Map();
|
|
11
|
+
closed = false;
|
|
12
|
+
/** Settlements the model has not been told about yet, in completion order. */
|
|
13
|
+
notices = [];
|
|
14
|
+
/** Owner-visible label for a notice; never contains the command's full output. */
|
|
15
|
+
noticeBytes = 2048;
|
|
16
|
+
get size() { return this.jobs.size; }
|
|
17
|
+
/** Drain pending completion notices. Returns [] when every settlement was already reported. */
|
|
18
|
+
takeNotices() {
|
|
19
|
+
return this.notices.splice(0, this.notices.length);
|
|
20
|
+
}
|
|
21
|
+
get hasNotices() { return this.notices.length > 0; }
|
|
22
|
+
notice(record) {
|
|
23
|
+
const view = record.view;
|
|
24
|
+
const status = view.exitCode === undefined || view.exitCode === null ? view.status : `${view.status}, exit ${view.exitCode}`;
|
|
25
|
+
const head = `バックグラウンドジョブ ${view.id} (${view.label}) が終了した [${status}]`;
|
|
26
|
+
// Quote only what the model has not read, and only when it fits; otherwise name the tool.
|
|
27
|
+
const unread = record.process.out.read(record.outCursor).text + record.process.err.read(record.errCursor).text;
|
|
28
|
+
if (unread.trim().length === 0) {
|
|
29
|
+
this.notices.push(`${head}。新しい出力はない。`);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (unread.length <= this.noticeBytes) {
|
|
33
|
+
this.notices.push(`${head}。未読の出力:\n${unread.trimEnd()}\n(job_output で続きを読める)`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.notices.push(`${head}。未読の出力が ${unread.length} 文字ある。job_output で読む。`);
|
|
37
|
+
}
|
|
38
|
+
start(request) {
|
|
39
|
+
if (this.closed)
|
|
40
|
+
throw new Error('ジョブ実行は終了済み');
|
|
41
|
+
const process = new ShellProcess(request.command, request.cwd, { shell: request.shell });
|
|
42
|
+
return this.register(process, request);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Take ownership of a process that is already running.
|
|
46
|
+
*
|
|
47
|
+
* This is how a foreground command that reached its deadline keeps its work: the caller
|
|
48
|
+
* abandons its own await and the job registry continues to observe, report, and stop it.
|
|
49
|
+
* Everything already produced on stdout/stderr is available to the first `job_output`.
|
|
50
|
+
*/
|
|
51
|
+
adopt(process, request) {
|
|
52
|
+
if (this.closed) {
|
|
53
|
+
process.stop('killed');
|
|
54
|
+
throw new Error('ジョブ実行は終了済み');
|
|
55
|
+
}
|
|
56
|
+
return this.register(process, request);
|
|
57
|
+
}
|
|
58
|
+
register(process, request) {
|
|
59
|
+
// Bound retained history: drop the oldest settled record, never a live one.
|
|
60
|
+
if (this.jobs.size >= MAX_RETAINED_JOBS) {
|
|
61
|
+
const settled = [...this.jobs.values()].find(record => record.view.status !== 'running' && record.view.status !== 'stopping');
|
|
62
|
+
if (settled)
|
|
63
|
+
this.jobs.delete(settled.view.id);
|
|
64
|
+
}
|
|
65
|
+
const id = `bash-${randomUUID().replaceAll('-', '').slice(0, 16)}`;
|
|
66
|
+
const view = {
|
|
67
|
+
id, kind: 'bash', label: label(request.command, request.description),
|
|
68
|
+
command: request.command, cwd: request.cwd, shell: request.shell,
|
|
69
|
+
status: 'running', startedAt: Date.now(),
|
|
70
|
+
};
|
|
71
|
+
const record = { view, process, outCursor: 0, errCursor: 0, unreadOut: 0, unreadErr: 0, waiters: new Set() };
|
|
72
|
+
this.jobs.set(id, record);
|
|
73
|
+
void process.result.then(result => {
|
|
74
|
+
view.status = 'completed';
|
|
75
|
+
view.finishedAt = Date.now();
|
|
76
|
+
view.exitCode = result.code;
|
|
77
|
+
}, (error) => {
|
|
78
|
+
view.finishedAt = Date.now();
|
|
79
|
+
if (process.stoppedByKill) {
|
|
80
|
+
view.status = 'killed';
|
|
81
|
+
// A human-supplied reason is more useful than the generic cause; keep it.
|
|
82
|
+
view.detail ??= '停止を要求された';
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
view.status = 'failed';
|
|
86
|
+
view.detail = error.message.split('\n')[0];
|
|
87
|
+
}
|
|
88
|
+
}).finally(() => {
|
|
89
|
+
record.unreadOut = process.out.produced - record.outCursor;
|
|
90
|
+
record.unreadErr = process.err.produced - record.errCursor;
|
|
91
|
+
this.notice(record);
|
|
92
|
+
for (const wake of record.waiters)
|
|
93
|
+
wake();
|
|
94
|
+
record.waiters.clear();
|
|
95
|
+
});
|
|
96
|
+
return { ...view };
|
|
97
|
+
}
|
|
98
|
+
list() {
|
|
99
|
+
return [...this.jobs.values()].map(record => ({ ...record.view }));
|
|
100
|
+
}
|
|
101
|
+
get(id) {
|
|
102
|
+
const record = this.jobs.get(id);
|
|
103
|
+
return record ? { ...record.view } : undefined;
|
|
104
|
+
}
|
|
105
|
+
require(id) {
|
|
106
|
+
const record = this.jobs.get(id);
|
|
107
|
+
if (!record)
|
|
108
|
+
throw new Error(`不明なジョブ: ${id}`);
|
|
109
|
+
return record;
|
|
110
|
+
}
|
|
111
|
+
/** Output appended since the previous read. The cursor advances only for a delivered read. */
|
|
112
|
+
read(id) {
|
|
113
|
+
const record = this.require(id);
|
|
114
|
+
const out = record.process.out.read(record.outCursor);
|
|
115
|
+
const err = record.process.err.read(record.errCursor);
|
|
116
|
+
record.outCursor = out.next;
|
|
117
|
+
record.errCursor = err.next;
|
|
118
|
+
record.unreadOut = 0;
|
|
119
|
+
record.unreadErr = 0;
|
|
120
|
+
return { job: { ...record.view }, stdout: out.text, stderr: err.text, dropped: out.dropped + err.dropped };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Wait until the job settles, new output appears, or the timeout expires.
|
|
124
|
+
*
|
|
125
|
+
* Returning early on new output is what makes polling useful: a long build reports progress
|
|
126
|
+
* instead of forcing the caller to choose between blocking for minutes and busy-looping.
|
|
127
|
+
*/
|
|
128
|
+
wait(id, timeoutMs, signal) {
|
|
129
|
+
const record = this.require(id);
|
|
130
|
+
const settledNow = () => record.view.status !== 'running' && record.view.status !== 'stopping';
|
|
131
|
+
if (settledNow())
|
|
132
|
+
return Promise.resolve();
|
|
133
|
+
const outMark = record.process.out.produced;
|
|
134
|
+
const errMark = record.process.err.produced;
|
|
135
|
+
return new Promise(resolve => {
|
|
136
|
+
let done = false;
|
|
137
|
+
const finish = () => {
|
|
138
|
+
if (done)
|
|
139
|
+
return;
|
|
140
|
+
done = true;
|
|
141
|
+
clearTimeout(timer);
|
|
142
|
+
clearInterval(poll);
|
|
143
|
+
signal?.removeEventListener('abort', finish);
|
|
144
|
+
record.waiters.delete(finish);
|
|
145
|
+
resolve();
|
|
146
|
+
};
|
|
147
|
+
const timer = setTimeout(finish, timeoutMs);
|
|
148
|
+
// Output arrives through a stream, not an event the registry owns; a bounded poll keeps
|
|
149
|
+
// the seam small without making every job wake the registry on each chunk.
|
|
150
|
+
const poll = setInterval(() => {
|
|
151
|
+
if (settledNow()
|
|
152
|
+
|| record.process.out.produced !== outMark
|
|
153
|
+
|| record.process.err.produced !== errMark)
|
|
154
|
+
finish();
|
|
155
|
+
}, 10);
|
|
156
|
+
signal?.addEventListener('abort', finish, { once: true });
|
|
157
|
+
record.waiters.add(finish);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
async kill(id, reason) {
|
|
161
|
+
const record = this.require(id);
|
|
162
|
+
if (record.view.status === 'running') {
|
|
163
|
+
record.view.status = 'stopping';
|
|
164
|
+
if (reason !== undefined && reason.length > 0)
|
|
165
|
+
record.view.detail = reason.slice(0, 200);
|
|
166
|
+
record.process.stop('killed');
|
|
167
|
+
}
|
|
168
|
+
return { ...record.view };
|
|
169
|
+
}
|
|
170
|
+
/** Stop every job and wait for the process groups to settle. */
|
|
171
|
+
async close() {
|
|
172
|
+
this.closed = true;
|
|
173
|
+
const live = [...this.jobs.values()].filter(record => record.view.status === 'running' || record.view.status === 'stopping');
|
|
174
|
+
for (const record of live) {
|
|
175
|
+
record.view.status = 'stopping';
|
|
176
|
+
record.process.stop('killed');
|
|
177
|
+
}
|
|
178
|
+
await Promise.allSettled(live.map(record => record.process.result));
|
|
179
|
+
this.jobs.clear();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Tool } from '../agent/types.ts';
|
|
2
|
+
import { type LanguageService } from '../language/lsp/service.ts';
|
|
3
|
+
import { verifyGrammar } from '../language/syntax/parser.ts';
|
|
4
|
+
/** Lazy: constructing the tools must stay cheap for subagents with no language work. */
|
|
5
|
+
export declare function languageTools(service: LanguageService): Tool[];
|
|
6
|
+
export { verifyGrammar };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { commonLispReader } from "../language/commonlisp-reader.js";
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { ToolError } from "../agent/types.js";
|
|
5
|
+
import { resolveInRoot, assertRealInRoot } from "./guard.js";
|
|
6
|
+
import { detectLanguage } from "../language/detect.js";
|
|
7
|
+
import { formatDiagnostics } from "../language/lsp/service.js";
|
|
8
|
+
import { outline, verifyGrammar } from "../language/syntax/parser.js";
|
|
9
|
+
import { offsetToPosition, positionToOffset } from "../language/positions.js";
|
|
10
|
+
function selector(value) {
|
|
11
|
+
if (value !== undefined && value !== 'tailwind')
|
|
12
|
+
throw new ToolError('INVALID_ARGS', 'Unknown server selector');
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
const MAX_SOURCE_BYTES = 2 * 1024 * 1024;
|
|
16
|
+
function requireString(value, name) {
|
|
17
|
+
if (typeof value !== 'string' || value.length === 0)
|
|
18
|
+
throw new ToolError('INVALID_ARGS', `${name} は空でない文字列で指定する`);
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function readSource(root, rel) {
|
|
22
|
+
const abs = resolveInRoot(root, rel);
|
|
23
|
+
assertRealInRoot(root, abs);
|
|
24
|
+
let stat;
|
|
25
|
+
try {
|
|
26
|
+
stat = fs.statSync(abs);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw new ToolError('NOT_FOUND', `読めないファイル: ${rel}`);
|
|
30
|
+
}
|
|
31
|
+
if (!stat.isFile())
|
|
32
|
+
throw new ToolError('READ_FAILED', `ファイルではない: ${rel}`);
|
|
33
|
+
if (stat.size > MAX_SOURCE_BYTES)
|
|
34
|
+
throw new ToolError('TOO_LARGE', `2 MiBを超えるファイルは解析しない: ${rel}`);
|
|
35
|
+
return { abs, text: fs.readFileSync(abs, 'utf8') };
|
|
36
|
+
}
|
|
37
|
+
function renderDiagnostics(items, root) {
|
|
38
|
+
if (items.length === 0)
|
|
39
|
+
return '診断は0件(サーバーが通知した結果)';
|
|
40
|
+
return items.slice(0, 50).map(item => {
|
|
41
|
+
const rel = path.relative(root, item.path) || item.path;
|
|
42
|
+
return `${rel}:${item.line}:${item.column} ${item.severity}: ${item.message}${item.source ? ` (${item.source})` : ''}`;
|
|
43
|
+
}).join('\n');
|
|
44
|
+
}
|
|
45
|
+
/** Lazy: constructing the tools must stay cheap for subagents with no language work. */
|
|
46
|
+
export function languageTools(service) {
|
|
47
|
+
const outlineTool = {
|
|
48
|
+
readOnly: true,
|
|
49
|
+
name: 'code_outline',
|
|
50
|
+
description: 'tree-sitterで構造(関数・クラス・メソッド等)を取得する。行・桁は1開始。構文上の同名を意味上の同一参照とは扱わない。',
|
|
51
|
+
parameters: { type: 'object', properties: {
|
|
52
|
+
path: { type: 'string', description: '対象ファイル(ルート相対)' },
|
|
53
|
+
server: { type: 'string', enum: ['tailwind'], description: 'Explicit semantic overlay' },
|
|
54
|
+
}, required: ['path'] },
|
|
55
|
+
async execute(args, ctx) {
|
|
56
|
+
const rel = requireString(args.path, 'path');
|
|
57
|
+
const file = resolveInRoot(ctx.root, rel);
|
|
58
|
+
assertRealInRoot(ctx.root, file);
|
|
59
|
+
const detection = detectLanguage(file, ctx.root);
|
|
60
|
+
if (!detection?.language.grammar)
|
|
61
|
+
throw new ToolError('UNSUPPORTED', `構造抽出の対象外: ${rel}`);
|
|
62
|
+
const text = readSource(ctx.root, rel).text;
|
|
63
|
+
const result = await outline(detection.language.grammar, text);
|
|
64
|
+
if (result.status !== 'ok' || !result.nodes) {
|
|
65
|
+
throw new ToolError('PARSE_FAILED', `${rel} の構造を取得できない: ${result.detail ?? result.status}`);
|
|
66
|
+
}
|
|
67
|
+
const rows = result.nodes.map(node => `${node.startLine}:${node.startColumn}-${node.endLine}:${node.endColumn} ${node.kind}${node.name ? ` ${node.name}` : ''}`);
|
|
68
|
+
return `${rel} (${detection.language.id}, ${result.nodes.length}件, 構文エラー候補${result.errorCount ?? 0})\n${rows.join('\n') || '(構造なし)'}`;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
const syntaxSearchTool = {
|
|
72
|
+
readOnly: true,
|
|
73
|
+
name: 'code_syntax_search',
|
|
74
|
+
description: '構文上の定義を検索して名前と範囲を返す。意味上の参照ではない。',
|
|
75
|
+
parameters: { type: 'object', properties: {
|
|
76
|
+
path: { type: 'string', description: '対象ファイル(ルート相対)' },
|
|
77
|
+
server: { type: 'string', enum: ['tailwind'], description: 'Explicit semantic overlay' },
|
|
78
|
+
query: { type: 'string', description: '名前の部分一致(空なら全件)' },
|
|
79
|
+
}, required: ['path'] },
|
|
80
|
+
async execute(args, ctx) {
|
|
81
|
+
const rel = requireString(args.path, 'path');
|
|
82
|
+
const query = typeof args.query === 'string' ? args.query : '';
|
|
83
|
+
const file = resolveInRoot(ctx.root, rel);
|
|
84
|
+
assertRealInRoot(ctx.root, file);
|
|
85
|
+
const detection = detectLanguage(file, ctx.root);
|
|
86
|
+
if (!detection?.language.grammar)
|
|
87
|
+
throw new ToolError('UNSUPPORTED', `構文検索の対象外: ${rel}`);
|
|
88
|
+
const result = await outline(detection.language.grammar, readSource(ctx.root, rel).text);
|
|
89
|
+
if (result.status !== 'ok' || !result.nodes)
|
|
90
|
+
throw new ToolError('PARSE_FAILED', result.detail ?? result.status);
|
|
91
|
+
const hits = query ? result.nodes.filter(node => node.name?.includes(query)) : result.nodes;
|
|
92
|
+
return hits.length === 0 ? `${rel}: 構文上の一致なし(意味上の不在を意味しない)`
|
|
93
|
+
: hits.map(hit => `${hit.startLine}:${hit.startColumn} ${hit.kind} ${hit.name ?? ''}`).join('\n');
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
const diagnosticsTool = {
|
|
97
|
+
readOnly: true,
|
|
98
|
+
name: 'code_diagnostics',
|
|
99
|
+
description: '現在のファイル内容をLSPへ同期し、診断を取得する。診断0件・未通知・古い版を区別して返す。',
|
|
100
|
+
parameters: { type: 'object', properties: {
|
|
101
|
+
path: { type: 'string', description: '対象ファイル(ルート相対)' },
|
|
102
|
+
server: { type: 'string', enum: ['tailwind'], description: 'Explicit semantic overlay' },
|
|
103
|
+
}, required: ['path'] },
|
|
104
|
+
async execute(args, ctx) {
|
|
105
|
+
const rel = requireString(args.path, 'path');
|
|
106
|
+
const { text } = readSource(ctx.root, rel);
|
|
107
|
+
const result = await service.analyze(resolveInRoot(ctx.root, rel), text, ctx.signal, selector(args.server));
|
|
108
|
+
if (result.status !== 'ok') {
|
|
109
|
+
const supplemental = detectLanguage(resolveInRoot(ctx.root, rel), ctx.root)?.language.id === 'commonlisp'
|
|
110
|
+
? await commonLispReader(text, { signal: ctx.signal }) : undefined;
|
|
111
|
+
// Readable input is not a clean LSP diagnostic result. Keep the tool unverified.
|
|
112
|
+
throw new ToolError('LSP_UNVERIFIED', `${formatDiagnostics(result)}${supplemental ? `\nSupplemental ${supplemental.provider}: ${supplemental.status}; ${supplemental.scope}\n${supplemental.line ?? '?'}:${supplemental.column ?? '?'} ${supplemental.detail}` : ''}`);
|
|
113
|
+
}
|
|
114
|
+
return `${formatDiagnostics(result)}\n${renderDiagnostics(result.diagnostics ?? [], ctx.root)}`;
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
const positionTool = (name, description) => ({
|
|
118
|
+
readOnly: true,
|
|
119
|
+
name,
|
|
120
|
+
description,
|
|
121
|
+
parameters: { type: 'object', properties: {
|
|
122
|
+
path: { type: 'string', description: '対象ファイル(ルート相対)' },
|
|
123
|
+
server: { type: 'string', enum: ['tailwind'], description: 'Explicit semantic overlay' },
|
|
124
|
+
line: { type: 'number', description: '1開始の行' },
|
|
125
|
+
column: { type: 'number', description: '1開始の桁(UTF-16)' },
|
|
126
|
+
}, required: ['path', 'line', 'column'] },
|
|
127
|
+
async execute(args, ctx) {
|
|
128
|
+
const rel = requireString(args.path, 'path');
|
|
129
|
+
const line = Number(args.line), column = Number(args.column);
|
|
130
|
+
if (!Number.isSafeInteger(line) || line < 1 || !Number.isSafeInteger(column) || column < 1) {
|
|
131
|
+
throw new ToolError('INVALID_ARGS', 'line と column は1以上の整数');
|
|
132
|
+
}
|
|
133
|
+
const { abs, text } = readSource(ctx.root, rel);
|
|
134
|
+
const offset = positionToOffset(text, { line: line - 1, character: column - 1 });
|
|
135
|
+
const detection = detectLanguage(abs, ctx.root);
|
|
136
|
+
if (!detection)
|
|
137
|
+
throw new ToolError('UNSUPPORTED', `対応言語ではない: ${rel}`);
|
|
138
|
+
// Ensure the server has the current text before asking about a position.
|
|
139
|
+
await service.analyze(abs, text, ctx.signal, selector(args.server));
|
|
140
|
+
const position = offsetToPosition(text, offset);
|
|
141
|
+
const root = detection.root;
|
|
142
|
+
const configured = service.detect(abs);
|
|
143
|
+
if (!configured)
|
|
144
|
+
throw new ToolError('UNSUPPORTED', `対応言語ではない: ${rel}`);
|
|
145
|
+
try {
|
|
146
|
+
if (name === 'code_hover') {
|
|
147
|
+
const answer = await withServer(service, abs, text, ctx.signal, server => server.hover(abs, position), selector(args.server));
|
|
148
|
+
return answer ?? '型情報は得られなかった';
|
|
149
|
+
}
|
|
150
|
+
const locations = await withServer(service, abs, text, ctx.signal, server => name === 'code_definition' ? server.definition(abs, position) : server.references(abs, position), selector(args.server));
|
|
151
|
+
if (locations.length === 0)
|
|
152
|
+
return `${name}: 該当なし。この結果は未取得ではなく、サーバーが空を返した`;
|
|
153
|
+
return locations.map(location => `${path.relative(root, location.file) || location.file}:${location.line}:${location.character}`).join('\n');
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
throw new ToolError('LSP_FAILED', e.message);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
return [outlineTool, syntaxSearchTool, diagnosticsTool,
|
|
161
|
+
positionTool('code_definition', '定義位置を取得する(位置的問い合わせ)'),
|
|
162
|
+
positionTool('code_references', '参照位置を取得する(位置的問い合わせ)'),
|
|
163
|
+
positionTool('code_hover', '型・ドキュメントのホバー情報を取得する')];
|
|
164
|
+
}
|
|
165
|
+
/** Acquire the same pooled server used for diagnostics; absence is reported, never fabricated. */
|
|
166
|
+
async function withServer(service, file, text, signal, action, selector) {
|
|
167
|
+
const server = service.poolFor(file, selector);
|
|
168
|
+
if (!server)
|
|
169
|
+
throw new Error('言語サーバーを初期化できませんでした');
|
|
170
|
+
void text;
|
|
171
|
+
void signal;
|
|
172
|
+
return action(server);
|
|
173
|
+
}
|
|
174
|
+
export { verifyGrammar };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Tool, ToolCall, ToolContext, ToolResult } from '../agent/types.ts';
|
|
2
|
+
import type { JobRegistry } from './jobs.ts';
|
|
3
|
+
/**
|
|
4
|
+
* ツール名・引数形状・宣言外の引数を検証する。
|
|
5
|
+
* 各フィールドの値は個々のツールが boundary で検証する。
|
|
6
|
+
*/
|
|
7
|
+
export declare class ToolRegistry {
|
|
8
|
+
private tools;
|
|
9
|
+
constructor(tools: Tool[]);
|
|
10
|
+
specs(): {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
parameters: Record<string, unknown>;
|
|
14
|
+
}[];
|
|
15
|
+
get(name: string): Tool | undefined;
|
|
16
|
+
/** Match unresolved effects conservatively. Only trusted tool code defines defaults. */
|
|
17
|
+
sameOperation(a: ToolCall, b: ToolCall, ctx: ToolContext): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* モデルの要求を1件ずつ検証して実行する。
|
|
20
|
+
* 未知のツール・引数不正は結果として返す(例外を握らず、モデルに観測させる)。
|
|
21
|
+
* signal が abort された以降は新規実行しない(status:'not-executed')。
|
|
22
|
+
*/
|
|
23
|
+
executeOne(call: ToolCall, ctx: ToolContext): Promise<ToolResult>;
|
|
24
|
+
}
|
|
25
|
+
/** 初版が提供する5区分のツール群(作成/編集は別ツール)。 */
|
|
26
|
+
export declare function defaultTools(): Tool[];
|
|
27
|
+
/** The same tools plus background execution, which needs a per-session job registry. */
|
|
28
|
+
export declare function defaultToolsWithJobs(jobs: JobRegistry): Tool[];
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { ToolError } from "../agent/types.js";
|
|
3
|
+
import { listFilesTool, searchFilesTool, readFileTool } from "./files.js";
|
|
4
|
+
import { createFileTool, editFileTool } from "./edit.js";
|
|
5
|
+
import { runCommandTool } from "./run.js";
|
|
6
|
+
import { jobTools } from "./job-tools.js";
|
|
7
|
+
import { webTools } from "./web.js";
|
|
8
|
+
import { skillTools } from "./skills.js";
|
|
9
|
+
/**
|
|
10
|
+
* ツール名・引数形状・宣言外の引数を検証する。
|
|
11
|
+
* 各フィールドの値は個々のツールが boundary で検証する。
|
|
12
|
+
*/
|
|
13
|
+
export class ToolRegistry {
|
|
14
|
+
tools;
|
|
15
|
+
constructor(tools) {
|
|
16
|
+
this.tools = new Map();
|
|
17
|
+
for (const tool of tools) {
|
|
18
|
+
if (this.tools.has(tool.name))
|
|
19
|
+
throw new Error(`Duplicate tool: ${tool.name}`);
|
|
20
|
+
this.tools.set(tool.name, tool);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
specs() {
|
|
24
|
+
return [...this.tools.values()].map((t) => ({
|
|
25
|
+
name: t.name,
|
|
26
|
+
description: t.description,
|
|
27
|
+
parameters: t.parameters,
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
get(name) {
|
|
31
|
+
return this.tools.get(name);
|
|
32
|
+
}
|
|
33
|
+
/** Match unresolved effects conservatively. Only trusted tool code defines defaults. */
|
|
34
|
+
sameOperation(a, b, ctx) {
|
|
35
|
+
if (a.name !== b.name)
|
|
36
|
+
return false;
|
|
37
|
+
const tool = this.tools.get(a.name);
|
|
38
|
+
if (!tool?.operationIdentity)
|
|
39
|
+
return isDeepStrictEqual(a.args, b.args);
|
|
40
|
+
try {
|
|
41
|
+
return isDeepStrictEqual(tool.operationIdentity(a.args, ctx), tool.operationIdentity(b.args, ctx));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Failure to establish a different operation cannot authorize another effect.
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* モデルの要求を1件ずつ検証して実行する。
|
|
50
|
+
* 未知のツール・引数不正は結果として返す(例外を握らず、モデルに観測させる)。
|
|
51
|
+
* signal が abort された以降は新規実行しない(status:'not-executed')。
|
|
52
|
+
*/
|
|
53
|
+
async executeOne(call, ctx) {
|
|
54
|
+
const base = { callId: call.id, name: call.name };
|
|
55
|
+
if (ctx.signal?.aborted) {
|
|
56
|
+
return { ...base, status: 'not-executed', output: '中断済みのため実行していない' };
|
|
57
|
+
}
|
|
58
|
+
const tool = this.tools.get(call.name);
|
|
59
|
+
if (tool === undefined) {
|
|
60
|
+
return {
|
|
61
|
+
...base,
|
|
62
|
+
status: 'error',
|
|
63
|
+
output: `未知のツール名: ${call.name}(登録済み: ${[...this.tools.keys()].join(', ')})`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (call.args === null || typeof call.args !== 'object' || Array.isArray(call.args)) {
|
|
67
|
+
return { ...base, status: 'error', output: '引数は JSON オブジェクトで渡す' };
|
|
68
|
+
}
|
|
69
|
+
const properties = tool.parameters.properties;
|
|
70
|
+
if (properties !== null && typeof properties === 'object' && !Array.isArray(properties)) {
|
|
71
|
+
const unknown = Object.keys(call.args).filter(key => !Object.prototype.hasOwnProperty.call(properties, key));
|
|
72
|
+
if (unknown.length) {
|
|
73
|
+
return { ...base, status: 'error', output: `[INVALID_ARGS] 未知の引数: ${unknown.join(', ')}` };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const output = await tool.execute(call.args, { ...ctx, callId: call.id });
|
|
78
|
+
if (typeof output === 'string')
|
|
79
|
+
return { ...base, status: 'ok', output };
|
|
80
|
+
if (!output || !['ok', 'error', 'unknown', 'not-executed'].includes(output.status) || typeof output.output !== 'string')
|
|
81
|
+
throw new Error('Invalid tool outcome');
|
|
82
|
+
return { ...base, status: output.status, output: output.output };
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
if (e instanceof ToolError && (e.code === 'NOT_EXECUTED' || e.code === 'DENIED')) {
|
|
86
|
+
return { ...base, status: e.code === 'DENIED' ? 'error' : 'not-executed', output: `[${e.code}] ${e.message}` };
|
|
87
|
+
}
|
|
88
|
+
if (ctx.signal?.aborted || (e instanceof ToolError && (e.code === 'ABORTED' || e.code === 'RESULT_UNKNOWN'))) {
|
|
89
|
+
return { ...base, status: 'unknown', output: `中断により結果不明: ${e.message}` };
|
|
90
|
+
}
|
|
91
|
+
if (e instanceof ToolError)
|
|
92
|
+
return { ...base, status: 'error', output: `[${e.code}] ${e.message}` };
|
|
93
|
+
return { ...base, status: tool.readOnly ? 'error' : 'unknown',
|
|
94
|
+
output: `内部エラー(副作用の有無は未確認): ${e instanceof Error ? e.message : String(e)}` };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** 初版が提供する5区分のツール群(作成/編集は別ツール)。 */
|
|
99
|
+
export function defaultTools() {
|
|
100
|
+
return [listFilesTool, searchFilesTool, readFileTool, createFileTool, editFileTool, runCommandTool, ...webTools, ...skillTools];
|
|
101
|
+
}
|
|
102
|
+
/** The same tools plus background execution, which needs a per-session job registry. */
|
|
103
|
+
export function defaultToolsWithJobs(jobs) {
|
|
104
|
+
return [...defaultTools(), ...jobTools(jobs)];
|
|
105
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Tool } from '../agent/types.ts';
|
|
2
|
+
export { runShellProcess, runShell, describeShellResult, resolveShell, SHELLS, TextSink, ShellProcess } from './shell-process.ts';
|
|
3
|
+
export type { ShellName, ShellOptions, ShellResult } from './shell-process.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Whether a foreground command that hits its deadline becomes a job.
|
|
6
|
+
*
|
|
7
|
+
* On by default because killing a build at 120 seconds discards work the human wanted. A
|
|
8
|
+
* caller can turn it off to keep the strict "a deadline is a failure" contract.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_PROMOTE_ON_TIMEOUT = true;
|
|
11
|
+
export declare const runCommandTool: Tool;
|
|
12
|
+
/** Host-only acceptance path: same command authorization, no job promotion, no stdout parsing. */
|
|
13
|
+
export declare function executeAcceptance(command: string, root: string, approval: import('../agent/types.ts').ApprovalGate, signal: AbortSignal, inputDigest: string, env: NodeJS.ProcessEnv): Promise<import('../lisp/runtime.ts').ExecutionReceipt>;
|