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,280 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
12
|
+
import { randomUUID } from 'node:crypto';
|
|
13
|
+
import { configDir } from "../cli/config.js";
|
|
14
|
+
import { fields, inspectPackage, object, pluginId } from "./package.js";
|
|
15
|
+
import { findStateright } from "../tools/stateright-runtime.js";
|
|
16
|
+
import { builtinMicroagents, staterightMicroagent } from "../lisp/builtin-agents.js";
|
|
17
|
+
import { SubagentRegistry } from "./registry.js";
|
|
18
|
+
const EMPTY = () => ({ version: 1, plugins: Object.create(null), disabledBuiltins: [] });
|
|
19
|
+
export class PluginLoadInterrupted extends Error {
|
|
20
|
+
}
|
|
21
|
+
async function importWithSignal(url, signal) {
|
|
22
|
+
if (!signal)
|
|
23
|
+
return import(__rewriteRelativeImportExtension(url));
|
|
24
|
+
let abort = () => { };
|
|
25
|
+
const interrupted = new Promise((_resolve, reject) => {
|
|
26
|
+
abort = () => reject(new PluginLoadInterrupted('Plugin import interrupted; module effects and cleanup remain unknown'));
|
|
27
|
+
if (signal.aborted)
|
|
28
|
+
abort();
|
|
29
|
+
else
|
|
30
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
31
|
+
});
|
|
32
|
+
try {
|
|
33
|
+
return await Promise.race([import(__rewriteRelativeImportExtension(url)), interrupted]);
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
signal.removeEventListener('abort', abort);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export class PluginManager {
|
|
40
|
+
home;
|
|
41
|
+
builtinDir;
|
|
42
|
+
stateright;
|
|
43
|
+
constructor(home = configDir(), builtinDir = fileURLToPath(new URL('../../plugins/', import.meta.url)), stateright) {
|
|
44
|
+
this.home = path.resolve(home);
|
|
45
|
+
this.stateright = stateright;
|
|
46
|
+
this.builtinDir = builtinDir;
|
|
47
|
+
}
|
|
48
|
+
sessionEntries;
|
|
49
|
+
registerSessionDefinitions(entries, sourceDigest) {
|
|
50
|
+
if (this.sessionEntries)
|
|
51
|
+
throw new Error('Session definitions already registered; no implicit reload');
|
|
52
|
+
const registry = new SubagentRegistry();
|
|
53
|
+
for (const entry of entries) {
|
|
54
|
+
if (entry.descriptor.digest !== sourceDigest || !entry.descriptor.id.startsWith('micro-'))
|
|
55
|
+
throw new Error('Invalid session definition');
|
|
56
|
+
registry.register(entry.descriptor);
|
|
57
|
+
}
|
|
58
|
+
this.sessionEntries = structuredClone(entries);
|
|
59
|
+
}
|
|
60
|
+
base() { return path.join(this.home, 'plugins'); }
|
|
61
|
+
packagePath(id, digest) { return path.join(this.base(), 'packages', id, digest); }
|
|
62
|
+
catalog() {
|
|
63
|
+
const file = path.join(this.base(), 'catalog.json');
|
|
64
|
+
if (!fs.existsSync(file))
|
|
65
|
+
return EMPTY();
|
|
66
|
+
const stat = fs.lstatSync(file);
|
|
67
|
+
if (!stat.isFile() || stat.size > 1024 * 1024)
|
|
68
|
+
throw new Error('Invalid plugin catalog');
|
|
69
|
+
const raw = object(JSON.parse(fs.readFileSync(file, 'utf8')));
|
|
70
|
+
fields(raw, ['version', 'plugins', 'disabledBuiltins']);
|
|
71
|
+
if (raw.version !== 1 || !Array.isArray(raw.disabledBuiltins) || raw.disabledBuiltins.length > 1000)
|
|
72
|
+
throw new Error('Invalid plugin catalog version');
|
|
73
|
+
const result = EMPTY();
|
|
74
|
+
for (const [id, value] of Object.entries(object(raw.plugins))) {
|
|
75
|
+
pluginId(id);
|
|
76
|
+
if (id.startsWith('modkh-'))
|
|
77
|
+
throw new Error('Reserved plugin ID');
|
|
78
|
+
const row = object(value);
|
|
79
|
+
fields(row, ['digest', 'enabled']);
|
|
80
|
+
if (typeof row.digest !== 'string' || !/^[a-f0-9]{64}$/.test(row.digest) || typeof row.enabled !== 'boolean')
|
|
81
|
+
throw new Error('Invalid plugin catalog entry');
|
|
82
|
+
result.plugins[id] = { digest: row.digest, enabled: row.enabled };
|
|
83
|
+
}
|
|
84
|
+
result.disabledBuiltins = raw.disabledBuiltins.map(pluginId);
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
/** Single writer for registration and lease admission; fail closed after a crashed writer. */
|
|
88
|
+
transaction(action) {
|
|
89
|
+
fs.mkdirSync(this.base(), { recursive: true, mode: 0o700 });
|
|
90
|
+
const lock = path.join(this.base(), 'catalog.lock');
|
|
91
|
+
const fd = fs.openSync(lock, 'wx', 0o600);
|
|
92
|
+
try {
|
|
93
|
+
return action();
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
fs.closeSync(fd);
|
|
97
|
+
fs.unlinkSync(lock);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
save(catalog) {
|
|
101
|
+
const temp = path.join(this.base(), `catalog-${randomUUID()}.tmp`);
|
|
102
|
+
fs.writeFileSync(temp, `${JSON.stringify(catalog, null, 2)}\n`, { flag: 'wx', mode: 0o600, flush: true });
|
|
103
|
+
fs.renameSync(temp, path.join(this.base(), 'catalog.json'));
|
|
104
|
+
}
|
|
105
|
+
discover() {
|
|
106
|
+
const registry = new SubagentRegistry();
|
|
107
|
+
const diagnostics = [];
|
|
108
|
+
if (this.sessionEntries) {
|
|
109
|
+
for (const entry of this.sessionEntries)
|
|
110
|
+
registry.register(structuredClone(entry.descriptor));
|
|
111
|
+
return { registry, diagnostics };
|
|
112
|
+
}
|
|
113
|
+
let catalog;
|
|
114
|
+
try {
|
|
115
|
+
catalog = this.catalog();
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
return { registry, diagnostics: [`Plugin settings unavailable: ${String(e)}`] };
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
for (const id of fs.readdirSync(this.builtinDir).sort()) {
|
|
122
|
+
try {
|
|
123
|
+
const snapshot = inspectPackage(path.join(this.builtinDir, id));
|
|
124
|
+
if (!snapshot.manifest.id.startsWith('modkh-') || snapshot.manifest.id !== id)
|
|
125
|
+
throw new Error('Invalid built-in ID');
|
|
126
|
+
registry.register({ ...snapshot.manifest, digest: snapshot.digest, enabled: !catalog.disabledBuiltins.includes(id), builtin: true });
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
diagnostics.push(`${id}: ${String(e)}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
diagnostics.push(`Built-in plugins unavailable: ${String(e)}`);
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
for (const { descriptor } of [...builtinMicroagents(), ...(findStateright(this.stateright) ? [staterightMicroagent()] : [])]) {
|
|
138
|
+
registry.register({ ...descriptor, enabled: !catalog.disabledBuiltins.includes(descriptor.id) });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
diagnostics.push(`Built-in microagents unavailable: ${String(e)}`);
|
|
143
|
+
}
|
|
144
|
+
for (const [id, row] of Object.entries(catalog.plugins)) {
|
|
145
|
+
try {
|
|
146
|
+
const snapshot = inspectPackage(this.packagePath(id, row.digest));
|
|
147
|
+
if (snapshot.digest !== row.digest || snapshot.manifest.id !== id)
|
|
148
|
+
throw new Error('Plugin digest mismatch; not loaded');
|
|
149
|
+
registry.register({ ...snapshot.manifest, digest: row.digest, enabled: row.enabled, builtin: false });
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
diagnostics.push(`${id}: ${String(e)}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { registry, diagnostics };
|
|
156
|
+
}
|
|
157
|
+
preview(directory) {
|
|
158
|
+
const snapshot = inspectPackage(path.resolve(directory));
|
|
159
|
+
if (snapshot.manifest.id.startsWith('modkh-'))
|
|
160
|
+
throw new Error('modkh- IDs are reserved');
|
|
161
|
+
return snapshot;
|
|
162
|
+
}
|
|
163
|
+
/** Called only after the human approves the displayed exact package digest. */
|
|
164
|
+
install(directory, approvedDigest) {
|
|
165
|
+
const snapshot = this.preview(directory);
|
|
166
|
+
if (snapshot.digest !== approvedDigest)
|
|
167
|
+
throw new Error('Plugin changed after trust confirmation');
|
|
168
|
+
return this.transaction(() => {
|
|
169
|
+
const catalog = this.catalog();
|
|
170
|
+
const id = snapshot.manifest.id;
|
|
171
|
+
if (Object.hasOwn(catalog.plugins, id))
|
|
172
|
+
throw new Error(`Duplicate plugin: ${id}. Remove its registration before replacing it.`);
|
|
173
|
+
const destination = this.packagePath(id, snapshot.digest);
|
|
174
|
+
if (!fs.existsSync(destination)) {
|
|
175
|
+
const staging = `${destination}.staging-${randomUUID()}`;
|
|
176
|
+
fs.mkdirSync(staging, { recursive: true, mode: 0o700 });
|
|
177
|
+
for (const [relative, bytes] of snapshot.files) {
|
|
178
|
+
const file = path.join(staging, relative);
|
|
179
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
180
|
+
fs.writeFileSync(file, bytes, { flag: 'wx', mode: 0o600, flush: true });
|
|
181
|
+
}
|
|
182
|
+
if (inspectPackage(staging).digest !== snapshot.digest)
|
|
183
|
+
throw new Error('Staged plugin digest mismatch');
|
|
184
|
+
fs.renameSync(staging, destination);
|
|
185
|
+
// Interrupted staging directories are retained for inspection, never loaded.
|
|
186
|
+
}
|
|
187
|
+
if (inspectPackage(destination).digest !== snapshot.digest)
|
|
188
|
+
throw new Error('Installed plugin digest mismatch');
|
|
189
|
+
catalog.plugins[id] = { digest: snapshot.digest, enabled: true };
|
|
190
|
+
this.save(catalog);
|
|
191
|
+
return { ...snapshot.manifest, digest: snapshot.digest, enabled: true, builtin: false };
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
setEnabled(id, enabled) {
|
|
195
|
+
pluginId(id);
|
|
196
|
+
this.transaction(() => {
|
|
197
|
+
const catalog = this.catalog();
|
|
198
|
+
if (id.startsWith('modkh-')) {
|
|
199
|
+
if (!this.discover().registry.get(id))
|
|
200
|
+
throw new Error(`Unknown plugin: ${id}`);
|
|
201
|
+
catalog.disabledBuiltins = catalog.disabledBuiltins.filter(value => value !== id);
|
|
202
|
+
if (!enabled)
|
|
203
|
+
catalog.disabledBuiltins.push(id);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const row = catalog.plugins[id];
|
|
207
|
+
if (!row)
|
|
208
|
+
throw new Error(`Unknown plugin: ${id}`);
|
|
209
|
+
// Enabling a corrupted package is not a new trust decision.
|
|
210
|
+
if (enabled && inspectPackage(this.packagePath(id, row.digest)).digest !== row.digest)
|
|
211
|
+
throw new Error('Plugin digest mismatch');
|
|
212
|
+
row.enabled = enabled;
|
|
213
|
+
}
|
|
214
|
+
this.save(catalog);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
remove(id) {
|
|
218
|
+
pluginId(id);
|
|
219
|
+
this.transaction(() => {
|
|
220
|
+
if (id.startsWith('modkh-'))
|
|
221
|
+
throw new Error('Built-in plugins can be disabled, not removed');
|
|
222
|
+
const catalog = this.catalog();
|
|
223
|
+
if (!catalog.plugins[id])
|
|
224
|
+
throw new Error(`Unknown plugin: ${id}`);
|
|
225
|
+
const leases = path.join(this.base(), 'leases', id);
|
|
226
|
+
if (fs.existsSync(leases) && fs.readdirSync(leases).length)
|
|
227
|
+
throw new Error('Plugin is in use or has an unreconciled lease; stop/reconcile it before removing');
|
|
228
|
+
delete catalog.plugins[id];
|
|
229
|
+
this.save(catalog);
|
|
230
|
+
// Retain immutable packages for audit. Removal unregisters; it never prunes history.
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
async acquire(id, digest, signal) {
|
|
234
|
+
signal?.throwIfAborted();
|
|
235
|
+
pluginId(id);
|
|
236
|
+
if (this.sessionEntries) {
|
|
237
|
+
const entry = this.sessionEntries.find(e => e.descriptor.id === id);
|
|
238
|
+
if (!entry?.descriptor.enabled || entry.descriptor.digest !== digest)
|
|
239
|
+
throw new Error('Session agent unavailable or digest mismatch');
|
|
240
|
+
return { descriptor: structuredClone(entry.descriptor), module: { define: () => structuredClone(entry.definition) }, release() { } };
|
|
241
|
+
}
|
|
242
|
+
const admitted = this.transaction(() => {
|
|
243
|
+
const descriptor = this.discover().registry.get(id);
|
|
244
|
+
if (!descriptor?.enabled)
|
|
245
|
+
throw new Error(`Plugin unavailable or disabled: ${id}`);
|
|
246
|
+
if (descriptor.digest !== digest)
|
|
247
|
+
throw new Error('Plugin changed before dispatch');
|
|
248
|
+
const microagent = descriptor.builtin && !descriptor.entry
|
|
249
|
+
? [...builtinMicroagents(), staterightMicroagent()].find(entry => entry.descriptor.id === id)
|
|
250
|
+
: undefined;
|
|
251
|
+
const directory = descriptor.builtin ? path.join(this.builtinDir, id) : this.packagePath(id, digest);
|
|
252
|
+
const leases = path.join(this.base(), 'leases', id);
|
|
253
|
+
fs.mkdirSync(leases, { recursive: true, mode: 0o700 });
|
|
254
|
+
const lease = path.join(leases, `${randomUUID()}.json`);
|
|
255
|
+
fs.writeFileSync(lease, JSON.stringify({ pid: process.pid, digest }), { flag: 'wx', mode: 0o600, flush: true });
|
|
256
|
+
return { descriptor: { ...descriptor }, directory, lease, microagent };
|
|
257
|
+
});
|
|
258
|
+
let released = false;
|
|
259
|
+
const release = () => { if (!released) {
|
|
260
|
+
fs.unlinkSync(admitted.lease);
|
|
261
|
+
released = true;
|
|
262
|
+
} };
|
|
263
|
+
try {
|
|
264
|
+
if (admitted.microagent) {
|
|
265
|
+
const definition = admitted.microagent.definition;
|
|
266
|
+
return { descriptor: admitted.descriptor, module: { define: () => structuredClone(definition) }, release };
|
|
267
|
+
}
|
|
268
|
+
if (inspectPackage(admitted.directory).digest !== digest)
|
|
269
|
+
throw new Error('Plugin changed before import');
|
|
270
|
+
const module = await importWithSignal(`${pathToFileURL(path.join(admitted.directory, admitted.descriptor.entry)).href}?digest=${digest}`, signal);
|
|
271
|
+
return { descriptor: admitted.descriptor, module, release };
|
|
272
|
+
}
|
|
273
|
+
catch (e) {
|
|
274
|
+
// A cancelled dynamic import cannot be unloaded; retain its lease for inspection.
|
|
275
|
+
if (!(e instanceof PluginLoadInterrupted))
|
|
276
|
+
release();
|
|
277
|
+
throw e;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PluginManifest } from './api.ts';
|
|
2
|
+
export declare function object(value: unknown): Record<string, unknown>;
|
|
3
|
+
export declare function text(value: unknown, name: string, max?: number): string;
|
|
4
|
+
export declare function fields(value: Record<string, unknown>, names: string[]): void;
|
|
5
|
+
export declare function pluginId(value: unknown): string;
|
|
6
|
+
export declare function parseManifest(value: unknown): PluginManifest;
|
|
7
|
+
export interface PackageSnapshot {
|
|
8
|
+
manifest: PluginManifest;
|
|
9
|
+
digest: string;
|
|
10
|
+
files: Map<string, Buffer>;
|
|
11
|
+
}
|
|
12
|
+
/** Bounded, deterministic package capture. No executable code is imported here. */
|
|
13
|
+
export declare function inspectPackage(directory: string): PackageSnapshot;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
export function object(value) {
|
|
5
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
6
|
+
throw new Error('JSON object required');
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
export function text(value, name, max = 4096) {
|
|
10
|
+
if (typeof value !== 'string' || !value.trim() || Buffer.byteLength(value) > max || /[\u0000-\u0008\u000b-\u001f\u007f]/.test(value))
|
|
11
|
+
throw new Error(`Invalid ${name}`);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
export function fields(value, names) {
|
|
15
|
+
for (const name of Object.keys(value))
|
|
16
|
+
if (!names.includes(name))
|
|
17
|
+
throw new Error(`Unknown field: ${name}`);
|
|
18
|
+
}
|
|
19
|
+
export function pluginId(value) {
|
|
20
|
+
const id = text(value, 'plugin ID', 64);
|
|
21
|
+
if (!/^[a-z][a-z0-9-]*$/.test(id))
|
|
22
|
+
throw new Error('Invalid plugin ID');
|
|
23
|
+
return id;
|
|
24
|
+
}
|
|
25
|
+
export function parseManifest(value) {
|
|
26
|
+
const m = object(value);
|
|
27
|
+
fields(m, ['apiVersion', 'id', 'version', 'title', 'description', 'kind', 'entry']);
|
|
28
|
+
if (m.apiVersion !== 1)
|
|
29
|
+
throw new Error('Unsupported plugin API version');
|
|
30
|
+
if (m.kind !== 'local' && m.kind !== 'external')
|
|
31
|
+
throw new Error('Invalid plugin kind');
|
|
32
|
+
const entry = text(m.entry, 'entry', 512);
|
|
33
|
+
if (!/^\.\//.test(entry) || entry.includes('\\') || entry.split('/').includes('..') || !/\.(?:mjs|js)$/.test(entry))
|
|
34
|
+
throw new Error('Entry must be a relative ESM file inside the package');
|
|
35
|
+
return { apiVersion: 1, id: pluginId(m.id), version: text(m.version, 'version', 128), title: text(m.title, 'title', 256), description: text(m.description, 'description'), kind: m.kind, entry };
|
|
36
|
+
}
|
|
37
|
+
/** Bounded, deterministic package capture. No executable code is imported here. */
|
|
38
|
+
export function inspectPackage(directory) {
|
|
39
|
+
if (!fs.lstatSync(directory).isDirectory())
|
|
40
|
+
throw new Error('Plugin root must be a real directory');
|
|
41
|
+
const files = new Map();
|
|
42
|
+
let bytes = 0;
|
|
43
|
+
let entries = 0;
|
|
44
|
+
function visit(relative, depth) {
|
|
45
|
+
if (depth > 32)
|
|
46
|
+
throw new Error('Plugin directory depth exceeds 32');
|
|
47
|
+
for (const name of fs.readdirSync(path.join(directory, relative)).sort()) {
|
|
48
|
+
if (++entries > 1000)
|
|
49
|
+
throw new Error('Plugin exceeds 1000 entries');
|
|
50
|
+
const rel = relative ? `${relative}/${name}` : name;
|
|
51
|
+
const full = path.join(directory, rel);
|
|
52
|
+
const stat = fs.lstatSync(full);
|
|
53
|
+
if (stat.isSymbolicLink())
|
|
54
|
+
throw new Error('Plugin symlinks are not allowed');
|
|
55
|
+
if (stat.isDirectory()) {
|
|
56
|
+
visit(rel, depth + 1);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (!stat.isFile())
|
|
60
|
+
throw new Error('Plugin contains a non-regular file');
|
|
61
|
+
bytes += stat.size;
|
|
62
|
+
if (bytes > 10 * 1024 * 1024 || (rel === 'plugin.json' && stat.size > 65536))
|
|
63
|
+
throw new Error('Plugin size limit exceeded');
|
|
64
|
+
const fd = fs.openSync(full, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
|
65
|
+
try {
|
|
66
|
+
const current = fs.fstatSync(fd);
|
|
67
|
+
if (!current.isFile() || current.ino !== stat.ino || current.dev !== stat.dev || current.size !== stat.size)
|
|
68
|
+
throw new Error('Plugin changed during capture');
|
|
69
|
+
// Never read an unbounded growing file after the initial size check.
|
|
70
|
+
const data = Buffer.alloc(stat.size);
|
|
71
|
+
let offset = 0;
|
|
72
|
+
while (offset < data.length) {
|
|
73
|
+
const count = fs.readSync(fd, data, offset, data.length - offset, offset);
|
|
74
|
+
if (!count)
|
|
75
|
+
throw new Error('Plugin changed during capture');
|
|
76
|
+
offset += count;
|
|
77
|
+
}
|
|
78
|
+
const end = fs.fstatSync(fd);
|
|
79
|
+
if (end.size !== stat.size || end.mtimeMs !== current.mtimeMs || end.ctimeMs !== current.ctimeMs)
|
|
80
|
+
throw new Error('Plugin changed during capture');
|
|
81
|
+
files.set(rel, data);
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
fs.closeSync(fd);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
visit('', 0);
|
|
89
|
+
const manifestBytes = files.get('plugin.json');
|
|
90
|
+
if (!manifestBytes)
|
|
91
|
+
throw new Error('Missing plugin.json');
|
|
92
|
+
const manifest = parseManifest(JSON.parse(manifestBytes.toString('utf8')));
|
|
93
|
+
if (!files.has(manifest.entry.slice(2)))
|
|
94
|
+
throw new Error('Missing plugin entry');
|
|
95
|
+
const hash = createHash('sha256');
|
|
96
|
+
for (const [name, data] of files)
|
|
97
|
+
hash.update(JSON.stringify([name, data.length])).update(data);
|
|
98
|
+
return { manifest, digest: hash.digest('hex'), files };
|
|
99
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PluginDescriptor } from './api.ts';
|
|
2
|
+
/** Registration ownership is exact: an old disposer cannot remove a replacement. */
|
|
3
|
+
export declare class SubagentRegistry {
|
|
4
|
+
private entries;
|
|
5
|
+
register(descriptor: PluginDescriptor): () => void;
|
|
6
|
+
list(): PluginDescriptor[];
|
|
7
|
+
get(id: string): Readonly<PluginDescriptor> | undefined;
|
|
8
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Registration ownership is exact: an old disposer cannot remove a replacement. */
|
|
2
|
+
export class SubagentRegistry {
|
|
3
|
+
entries = new Map();
|
|
4
|
+
register(descriptor) {
|
|
5
|
+
if (this.entries.has(descriptor.id))
|
|
6
|
+
throw new Error(`Duplicate plugin: ${descriptor.id}`);
|
|
7
|
+
const entry = Object.freeze(structuredClone(descriptor));
|
|
8
|
+
this.entries.set(entry.id, entry);
|
|
9
|
+
return () => { if (this.entries.get(entry.id) === entry)
|
|
10
|
+
this.entries.delete(entry.id); };
|
|
11
|
+
}
|
|
12
|
+
list() { return [...this.entries.values()].map(d => structuredClone(d)); }
|
|
13
|
+
get(id) { const value = this.entries.get(id); return value ? structuredClone(value) : undefined; }
|
|
14
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { AgentMessage, ToolResult } from '../agent/types.ts';
|
|
2
|
+
import { type CompactionState } from '../agent/compaction.ts';
|
|
3
|
+
import type { DelegationRecord } from '../subagents/types.ts';
|
|
4
|
+
export type SessionStatus = 'active' | 'complete' | 'interrupted' | 'error' | 'turn-limit';
|
|
5
|
+
/** 圧縮要約の保存上限。壊れた・巨大な記録で入力が膨らむのを防ぐ。 */
|
|
6
|
+
export declare const MAX_SUMMARY_CHARS = 20000;
|
|
7
|
+
/** JSONL の1行目。セッションの基本情報。seq は同ディレクトリ内の作成順(一覧の決定的並び替え用)。 */
|
|
8
|
+
export interface SessionHeader {
|
|
9
|
+
type: 'session';
|
|
10
|
+
version?: 2;
|
|
11
|
+
parentSessionId?: string;
|
|
12
|
+
rootSessionId?: string;
|
|
13
|
+
id: string;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
cwd: string;
|
|
16
|
+
model: string;
|
|
17
|
+
seq: number;
|
|
18
|
+
}
|
|
19
|
+
export interface MemoryObservation {
|
|
20
|
+
stage: 'retrieved' | 'supplied' | 'unavailable' | 'capture';
|
|
21
|
+
content?: string;
|
|
22
|
+
outcome?: string;
|
|
23
|
+
elapsedMs?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface SessionSummary {
|
|
26
|
+
id: string;
|
|
27
|
+
createdAt: string;
|
|
28
|
+
cwd: string;
|
|
29
|
+
model: string;
|
|
30
|
+
status: SessionStatus;
|
|
31
|
+
seq: number;
|
|
32
|
+
}
|
|
33
|
+
/** 既定の保存先。MODKH_HOME で差し替え可能(検証用)。 */
|
|
34
|
+
export declare function defaultSessionDir(): string;
|
|
35
|
+
/**
|
|
36
|
+
* JSONL セッションストア。1行1イベント。append で追記し、読み込みで再構築する。
|
|
37
|
+
* ステータスはイベントとして追記し、最後のものが有効。完了と中断を区別する。
|
|
38
|
+
*/
|
|
39
|
+
export declare class SessionStore {
|
|
40
|
+
private readonly dir;
|
|
41
|
+
constructor(dir?: string);
|
|
42
|
+
create(cwd: string, model: string, child?: {
|
|
43
|
+
id: string;
|
|
44
|
+
parentSessionId: string;
|
|
45
|
+
rootSessionId: string;
|
|
46
|
+
}): Session;
|
|
47
|
+
load(id: string): Session;
|
|
48
|
+
list(): SessionSummary[];
|
|
49
|
+
private fileOf;
|
|
50
|
+
}
|
|
51
|
+
export declare class Session {
|
|
52
|
+
messages: AgentMessage[];
|
|
53
|
+
status: SessionStatus;
|
|
54
|
+
lastError?: string;
|
|
55
|
+
/** 直近の圧縮状態。未圧縮なら undefined。原文の messages は常に全文。 */
|
|
56
|
+
compaction?: CompactionState;
|
|
57
|
+
id: string;
|
|
58
|
+
/** ヘッダの作成時刻(ワークスペース記録に使う)。古いファイルは作成時刻がない。 */
|
|
59
|
+
createdAt: string;
|
|
60
|
+
cwd: string;
|
|
61
|
+
model: string;
|
|
62
|
+
private file;
|
|
63
|
+
modelBaseUrl?: string;
|
|
64
|
+
private persistedCount;
|
|
65
|
+
private version;
|
|
66
|
+
parentSessionId?: string;
|
|
67
|
+
rootSessionId?: string;
|
|
68
|
+
private delegationLog;
|
|
69
|
+
private constructor();
|
|
70
|
+
static fromText(id: string, file: string, text: string): Session;
|
|
71
|
+
private recoverPending;
|
|
72
|
+
append(msg: AgentMessage): void;
|
|
73
|
+
/**
|
|
74
|
+
* ループが配列へ直接追加したメッセージをファイルへ追記する(メモリには既にある)。
|
|
75
|
+
* 既存呼び出しのindex引数は互換用。保存済み位置はSession自身が追跡し、二重追記しない。
|
|
76
|
+
*/
|
|
77
|
+
persistFrom(_index: number): void;
|
|
78
|
+
recordMemory(observation: MemoryObservation): void;
|
|
79
|
+
/**
|
|
80
|
+
* 圧縮を記録する。原文の messages は変更しない(監査・再実行防止の根拠を保つ)。
|
|
81
|
+
* 書き込みに失敗した場合はメモリ上の状態も戻し、保存と表示の不一致を作らない。
|
|
82
|
+
*/
|
|
83
|
+
recordCompaction(state: CompactionState, keptTurns: number): void;
|
|
84
|
+
setConnection(model: string, baseUrl?: string): void;
|
|
85
|
+
setStatus(status: SessionStatus, diagnostic?: string): void;
|
|
86
|
+
get delegationCount(): number;
|
|
87
|
+
delegations(): DelegationRecord[];
|
|
88
|
+
private acceptDelegation;
|
|
89
|
+
recordDelegation(record: DelegationRecord): void;
|
|
90
|
+
/** 結果不明のツール呼び出し(中断の痕跡)。再開時の表示と再実行禁止の根拠に使う。 */
|
|
91
|
+
unknownToolResults(): ToolResult[];
|
|
92
|
+
private write;
|
|
93
|
+
}
|