micode 0.6.0 → 0.7.1
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 +64 -331
- package/package.json +9 -14
- package/src/agents/artifact-searcher.ts +46 -0
- package/src/agents/brainstormer.ts +145 -0
- package/src/agents/codebase-analyzer.ts +75 -0
- package/src/agents/codebase-locator.ts +71 -0
- package/src/agents/commander.ts +138 -0
- package/src/agents/executor.ts +215 -0
- package/src/agents/implementer.ts +99 -0
- package/src/agents/index.ts +44 -0
- package/src/agents/ledger-creator.ts +113 -0
- package/src/agents/pattern-finder.ts +70 -0
- package/src/agents/planner.ts +230 -0
- package/src/agents/project-initializer.ts +264 -0
- package/src/agents/reviewer.ts +102 -0
- package/src/config-loader.ts +89 -0
- package/src/hooks/artifact-auto-index.ts +111 -0
- package/src/hooks/auto-clear-ledger.ts +230 -0
- package/src/hooks/auto-compact.ts +241 -0
- package/src/hooks/comment-checker.ts +120 -0
- package/src/hooks/context-injector.ts +163 -0
- package/src/hooks/context-window-monitor.ts +106 -0
- package/src/hooks/file-ops-tracker.ts +96 -0
- package/src/hooks/ledger-loader.ts +78 -0
- package/src/hooks/preemptive-compaction.ts +183 -0
- package/src/hooks/session-recovery.ts +258 -0
- package/src/hooks/token-aware-truncation.ts +189 -0
- package/src/index.ts +258 -0
- package/src/tools/artifact-index/index.ts +269 -0
- package/src/tools/artifact-index/schema.sql +44 -0
- package/src/tools/artifact-search.ts +49 -0
- package/src/tools/ast-grep/index.ts +189 -0
- package/src/tools/background-task/manager.ts +374 -0
- package/src/tools/background-task/tools.ts +145 -0
- package/src/tools/background-task/types.ts +68 -0
- package/src/tools/btca/index.ts +82 -0
- package/src/tools/look-at.ts +210 -0
- package/src/tools/pty/buffer.ts +49 -0
- package/src/tools/pty/index.ts +34 -0
- package/src/tools/pty/manager.ts +159 -0
- package/src/tools/pty/tools/kill.ts +68 -0
- package/src/tools/pty/tools/list.ts +55 -0
- package/src/tools/pty/tools/read.ts +152 -0
- package/src/tools/pty/tools/spawn.ts +78 -0
- package/src/tools/pty/tools/write.ts +97 -0
- package/src/tools/pty/types.ts +62 -0
- package/src/utils/model-limits.ts +36 -0
- package/dist/agents/artifact-searcher.d.ts +0 -2
- package/dist/agents/brainstormer.d.ts +0 -2
- package/dist/agents/codebase-analyzer.d.ts +0 -2
- package/dist/agents/codebase-locator.d.ts +0 -2
- package/dist/agents/commander.d.ts +0 -3
- package/dist/agents/executor.d.ts +0 -2
- package/dist/agents/implementer.d.ts +0 -2
- package/dist/agents/index.d.ts +0 -15
- package/dist/agents/ledger-creator.d.ts +0 -2
- package/dist/agents/pattern-finder.d.ts +0 -2
- package/dist/agents/planner.d.ts +0 -2
- package/dist/agents/project-initializer.d.ts +0 -2
- package/dist/agents/reviewer.d.ts +0 -2
- package/dist/config-loader.d.ts +0 -20
- package/dist/hooks/artifact-auto-index.d.ts +0 -19
- package/dist/hooks/auto-clear-ledger.d.ts +0 -11
- package/dist/hooks/auto-compact.d.ts +0 -9
- package/dist/hooks/comment-checker.d.ts +0 -9
- package/dist/hooks/context-injector.d.ts +0 -15
- package/dist/hooks/context-window-monitor.d.ts +0 -15
- package/dist/hooks/file-ops-tracker.d.ts +0 -26
- package/dist/hooks/ledger-loader.d.ts +0 -16
- package/dist/hooks/preemptive-compaction.d.ts +0 -9
- package/dist/hooks/session-recovery.d.ts +0 -9
- package/dist/hooks/token-aware-truncation.d.ts +0 -15
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -16267
- package/dist/tools/artifact-index/index.d.ts +0 -38
- package/dist/tools/artifact-search.d.ts +0 -17
- package/dist/tools/ast-grep/index.d.ts +0 -88
- package/dist/tools/background-task/manager.d.ts +0 -27
- package/dist/tools/background-task/tools.d.ts +0 -41
- package/dist/tools/background-task/types.d.ts +0 -53
- package/dist/tools/btca/index.d.ts +0 -19
- package/dist/tools/look-at.d.ts +0 -11
- package/dist/utils/model-limits.d.ts +0 -7
- /package/{dist/tools/background-task/index.d.ts → src/tools/background-task/index.ts} +0 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// src/tools/pty/tools/read.ts
|
|
2
|
+
import { tool } from "@opencode-ai/plugin/tool";
|
|
3
|
+
import type { PTYManager } from "../manager";
|
|
4
|
+
|
|
5
|
+
const DESCRIPTION = `Reads output from a PTY session's buffer.
|
|
6
|
+
|
|
7
|
+
The PTY maintains a rolling buffer of output lines. Use offset and limit to paginate through the output, similar to reading a file.
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
- \`id\`: The PTY session ID (from pty_spawn or pty_list)
|
|
11
|
+
- \`offset\`: Line number to start reading from (0-based, defaults to 0)
|
|
12
|
+
- \`limit\`: Number of lines to read (defaults to 500)
|
|
13
|
+
- \`pattern\`: Regex pattern to filter lines (optional)
|
|
14
|
+
- \`ignoreCase\`: Case-insensitive pattern matching (default: false)
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
- Numbered lines of output (similar to cat -n format)
|
|
18
|
+
- Total line count in the buffer
|
|
19
|
+
- Indicator if more lines are available
|
|
20
|
+
|
|
21
|
+
The buffer stores up to PTY_MAX_BUFFER_LINES (default: 50000) lines. Older lines are discarded when the limit is reached.
|
|
22
|
+
|
|
23
|
+
Pattern Filtering:
|
|
24
|
+
- When \`pattern\` is set, lines are FILTERED FIRST using the regex, then offset/limit apply to the MATCHES
|
|
25
|
+
- Original line numbers are preserved so you can see where matches occurred in the buffer
|
|
26
|
+
- Supports full regex syntax (e.g., "error", "ERROR|WARN", "failed.*connection", etc.)
|
|
27
|
+
- If the pattern is invalid, an error message is returned explaining the issue
|
|
28
|
+
- If no lines match the pattern, a clear message indicates zero matches
|
|
29
|
+
|
|
30
|
+
Tips:
|
|
31
|
+
- To see the latest output, use a high offset or omit offset to read from the start
|
|
32
|
+
- To tail recent output, calculate offset as (totalLines - N) where N is how many recent lines you want
|
|
33
|
+
- Lines longer than 2000 characters are truncated
|
|
34
|
+
- Empty output may mean the process hasn't produced output yet
|
|
35
|
+
|
|
36
|
+
Examples:
|
|
37
|
+
- Read first 100 lines: offset=0, limit=100
|
|
38
|
+
- Read lines 500-600: offset=500, limit=100
|
|
39
|
+
- Read all available: omit both parameters
|
|
40
|
+
- Find errors: pattern="error", ignoreCase=true
|
|
41
|
+
- Find specific log levels: pattern="ERROR|WARN|FATAL"
|
|
42
|
+
- First 10 matches only: pattern="error", limit=10`;
|
|
43
|
+
|
|
44
|
+
const DEFAULT_LIMIT = 500;
|
|
45
|
+
const MAX_LINE_LENGTH = 2000;
|
|
46
|
+
|
|
47
|
+
export function createPtyReadTool(manager: PTYManager) {
|
|
48
|
+
return tool({
|
|
49
|
+
description: DESCRIPTION,
|
|
50
|
+
args: {
|
|
51
|
+
id: tool.schema.string().describe("The PTY session ID (e.g., pty_a1b2c3d4)"),
|
|
52
|
+
offset: tool.schema.number().optional().describe("Line number to start reading from (0-based, defaults to 0)"),
|
|
53
|
+
limit: tool.schema.number().optional().describe("Number of lines to read (defaults to 500)"),
|
|
54
|
+
pattern: tool.schema.string().optional().describe("Regex pattern to filter lines"),
|
|
55
|
+
ignoreCase: tool.schema.boolean().optional().describe("Case-insensitive pattern matching (default: false)"),
|
|
56
|
+
},
|
|
57
|
+
execute: async (args) => {
|
|
58
|
+
const session = manager.get(args.id);
|
|
59
|
+
if (!session) {
|
|
60
|
+
throw new Error(`PTY session '${args.id}' not found. Use pty_list to see active sessions.`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const offset = Math.max(0, args.offset ?? 0);
|
|
64
|
+
const limit = args.limit ?? DEFAULT_LIMIT;
|
|
65
|
+
|
|
66
|
+
if (args.pattern) {
|
|
67
|
+
let regex: RegExp;
|
|
68
|
+
try {
|
|
69
|
+
regex = new RegExp(args.pattern, args.ignoreCase ? "i" : "");
|
|
70
|
+
} catch (e) {
|
|
71
|
+
const error = e instanceof Error ? e.message : String(e);
|
|
72
|
+
throw new Error(`Invalid regex pattern '${args.pattern}': ${error}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const result = manager.search(args.id, regex, offset, limit);
|
|
76
|
+
if (!result) {
|
|
77
|
+
throw new Error(`PTY session '${args.id}' not found.`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (result.matches.length === 0) {
|
|
81
|
+
return [
|
|
82
|
+
`<pty_output id="${args.id}" status="${session.status}" pattern="${args.pattern}">`,
|
|
83
|
+
`No lines matched the pattern '${args.pattern}'.`,
|
|
84
|
+
`Total lines in buffer: ${result.totalLines}`,
|
|
85
|
+
`</pty_output>`,
|
|
86
|
+
].join("\n");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const formattedLines = result.matches.map((match) => {
|
|
90
|
+
const lineNum = match.lineNumber.toString().padStart(5, "0");
|
|
91
|
+
const truncatedLine =
|
|
92
|
+
match.text.length > MAX_LINE_LENGTH ? `${match.text.slice(0, MAX_LINE_LENGTH)}...` : match.text;
|
|
93
|
+
return `${lineNum}| ${truncatedLine}`;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const output = [
|
|
97
|
+
`<pty_output id="${args.id}" status="${session.status}" pattern="${args.pattern}">`,
|
|
98
|
+
...formattedLines,
|
|
99
|
+
"",
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
if (result.hasMore) {
|
|
103
|
+
output.push(
|
|
104
|
+
`(${result.matches.length} of ${result.totalMatches} matches shown. Use offset=${offset + result.matches.length} to see more.)`,
|
|
105
|
+
);
|
|
106
|
+
} else {
|
|
107
|
+
output.push(
|
|
108
|
+
`(${result.totalMatches} match${result.totalMatches === 1 ? "" : "es"} from ${result.totalLines} total lines)`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
output.push(`</pty_output>`);
|
|
112
|
+
|
|
113
|
+
return output.join("\n");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const result = manager.read(args.id, offset, limit);
|
|
117
|
+
if (!result) {
|
|
118
|
+
throw new Error(`PTY session '${args.id}' not found.`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (result.lines.length === 0) {
|
|
122
|
+
return [
|
|
123
|
+
`<pty_output id="${args.id}" status="${session.status}">`,
|
|
124
|
+
`(No output available - buffer is empty)`,
|
|
125
|
+
`Total lines: ${result.totalLines}`,
|
|
126
|
+
`</pty_output>`,
|
|
127
|
+
].join("\n");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const formattedLines = result.lines.map((line, index) => {
|
|
131
|
+
const lineNum = (result.offset + index + 1).toString().padStart(5, "0");
|
|
132
|
+
const truncatedLine = line.length > MAX_LINE_LENGTH ? `${line.slice(0, MAX_LINE_LENGTH)}...` : line;
|
|
133
|
+
return `${lineNum}| ${truncatedLine}`;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const output = [`<pty_output id="${args.id}" status="${session.status}">`, ...formattedLines];
|
|
137
|
+
|
|
138
|
+
if (result.hasMore) {
|
|
139
|
+
output.push("");
|
|
140
|
+
output.push(
|
|
141
|
+
`(Buffer has more lines. Use offset=${result.offset + result.lines.length} to read beyond line ${result.offset + result.lines.length})`,
|
|
142
|
+
);
|
|
143
|
+
} else {
|
|
144
|
+
output.push("");
|
|
145
|
+
output.push(`(End of buffer - total ${result.totalLines} lines)`);
|
|
146
|
+
}
|
|
147
|
+
output.push(`</pty_output>`);
|
|
148
|
+
|
|
149
|
+
return output.join("\n");
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/tools/pty/tools/spawn.ts
|
|
2
|
+
import { tool } from "@opencode-ai/plugin/tool";
|
|
3
|
+
import type { PTYManager } from "../manager";
|
|
4
|
+
|
|
5
|
+
const DESCRIPTION = `Spawns a new interactive PTY (pseudo-terminal) session that runs in the background.
|
|
6
|
+
|
|
7
|
+
Unlike the built-in bash tool which runs commands synchronously and waits for completion, PTY sessions persist and allow you to:
|
|
8
|
+
- Run long-running processes (dev servers, watch modes, etc.)
|
|
9
|
+
- Send interactive input (including Ctrl+C, arrow keys, etc.)
|
|
10
|
+
- Read output at any time
|
|
11
|
+
- Manage multiple concurrent terminal sessions
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
- The \`command\` parameter is required (e.g., "npm", "python", "bash")
|
|
15
|
+
- Use \`args\` to pass arguments to the command (e.g., ["run", "dev"])
|
|
16
|
+
- Use \`workdir\` to set the working directory (defaults to project root)
|
|
17
|
+
- Use \`env\` to set additional environment variables
|
|
18
|
+
- Use \`title\` to give the session a human-readable name
|
|
19
|
+
- Use \`description\` for a clear, concise 5-10 word description (optional)
|
|
20
|
+
|
|
21
|
+
Returns the session info including:
|
|
22
|
+
- \`id\`: Unique identifier (pty_XXXXXXXX) for use with other pty_* tools
|
|
23
|
+
- \`pid\`: Process ID
|
|
24
|
+
- \`status\`: Current status ("running")
|
|
25
|
+
|
|
26
|
+
After spawning, use:
|
|
27
|
+
- \`pty_write\` to send input to the PTY
|
|
28
|
+
- \`pty_read\` to read output from the PTY
|
|
29
|
+
- \`pty_list\` to see all active PTY sessions
|
|
30
|
+
- \`pty_kill\` to terminate the PTY
|
|
31
|
+
|
|
32
|
+
Examples:
|
|
33
|
+
- Start a dev server: command="npm", args=["run", "dev"], title="Dev Server"
|
|
34
|
+
- Start a Python REPL: command="python3", title="Python REPL"
|
|
35
|
+
- Run tests in watch mode: command="npm", args=["test", "--", "--watch"]`;
|
|
36
|
+
|
|
37
|
+
export function createPtySpawnTool(manager: PTYManager) {
|
|
38
|
+
return tool({
|
|
39
|
+
description: DESCRIPTION,
|
|
40
|
+
args: {
|
|
41
|
+
command: tool.schema.string().describe("The command/executable to run"),
|
|
42
|
+
args: tool.schema.array(tool.schema.string()).optional().describe("Arguments to pass to the command"),
|
|
43
|
+
workdir: tool.schema.string().optional().describe("Working directory for the PTY session"),
|
|
44
|
+
env: tool.schema
|
|
45
|
+
.record(tool.schema.string(), tool.schema.string())
|
|
46
|
+
.optional()
|
|
47
|
+
.describe("Additional environment variables"),
|
|
48
|
+
title: tool.schema.string().optional().describe("Human-readable title for the session"),
|
|
49
|
+
description: tool.schema
|
|
50
|
+
.string()
|
|
51
|
+
.optional()
|
|
52
|
+
.describe("Clear, concise description of what this PTY session is for in 5-10 words"),
|
|
53
|
+
},
|
|
54
|
+
execute: async (args, ctx) => {
|
|
55
|
+
const info = manager.spawn({
|
|
56
|
+
command: args.command,
|
|
57
|
+
args: args.args,
|
|
58
|
+
workdir: args.workdir,
|
|
59
|
+
env: args.env,
|
|
60
|
+
title: args.title,
|
|
61
|
+
parentSessionId: ctx.sessionID,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const output = [
|
|
65
|
+
`<pty_spawned>`,
|
|
66
|
+
`ID: ${info.id}`,
|
|
67
|
+
`Title: ${info.title}`,
|
|
68
|
+
`Command: ${info.command} ${info.args.join(" ")}`,
|
|
69
|
+
`Workdir: ${info.workdir}`,
|
|
70
|
+
`PID: ${info.pid}`,
|
|
71
|
+
`Status: ${info.status}`,
|
|
72
|
+
`</pty_spawned>`,
|
|
73
|
+
].join("\n");
|
|
74
|
+
|
|
75
|
+
return output;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// src/tools/pty/tools/write.ts
|
|
2
|
+
import { tool } from "@opencode-ai/plugin/tool";
|
|
3
|
+
import type { PTYManager } from "../manager";
|
|
4
|
+
|
|
5
|
+
const DESCRIPTION = `Sends input data to an active PTY session.
|
|
6
|
+
|
|
7
|
+
Use this tool to:
|
|
8
|
+
- Type commands or text into an interactive terminal
|
|
9
|
+
- Send special key sequences (Ctrl+C, Enter, arrow keys, etc.)
|
|
10
|
+
- Respond to prompts in interactive programs
|
|
11
|
+
|
|
12
|
+
Usage:
|
|
13
|
+
- \`id\`: The PTY session ID (from pty_spawn or pty_list)
|
|
14
|
+
- \`data\`: The input to send (text, commands, or escape sequences)
|
|
15
|
+
|
|
16
|
+
Common escape sequences:
|
|
17
|
+
- Enter/newline: "\\n" or "\\r"
|
|
18
|
+
- Ctrl+C (interrupt): "\\x03"
|
|
19
|
+
- Ctrl+D (EOF): "\\x04"
|
|
20
|
+
- Ctrl+Z (suspend): "\\x1a"
|
|
21
|
+
- Tab: "\\t"
|
|
22
|
+
- Arrow Up: "\\x1b[A"
|
|
23
|
+
- Arrow Down: "\\x1b[B"
|
|
24
|
+
- Arrow Right: "\\x1b[C"
|
|
25
|
+
- Arrow Left: "\\x1b[D"
|
|
26
|
+
|
|
27
|
+
Returns success or error message.
|
|
28
|
+
|
|
29
|
+
Examples:
|
|
30
|
+
- Send a command: data="ls -la\\n"
|
|
31
|
+
- Interrupt a process: data="\\x03"
|
|
32
|
+
- Answer a prompt: data="yes\\n"`;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Parse escape sequences in a string to their actual byte values.
|
|
36
|
+
* Handles: \n, \r, \t, \xNN (hex), \uNNNN (unicode), \\
|
|
37
|
+
*/
|
|
38
|
+
function parseEscapeSequences(input: string): string {
|
|
39
|
+
return input.replace(/\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|[nrt0\\])/g, (match, seq: string) => {
|
|
40
|
+
if (seq.startsWith("x")) {
|
|
41
|
+
return String.fromCharCode(parseInt(seq.slice(1), 16));
|
|
42
|
+
}
|
|
43
|
+
if (seq.startsWith("u")) {
|
|
44
|
+
return String.fromCharCode(parseInt(seq.slice(1), 16));
|
|
45
|
+
}
|
|
46
|
+
switch (seq) {
|
|
47
|
+
case "n":
|
|
48
|
+
return "\n";
|
|
49
|
+
case "r":
|
|
50
|
+
return "\r";
|
|
51
|
+
case "t":
|
|
52
|
+
return "\t";
|
|
53
|
+
case "0":
|
|
54
|
+
return "\0";
|
|
55
|
+
case "\\":
|
|
56
|
+
return "\\";
|
|
57
|
+
default:
|
|
58
|
+
return match;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function createPtyWriteTool(manager: PTYManager) {
|
|
64
|
+
return tool({
|
|
65
|
+
description: DESCRIPTION,
|
|
66
|
+
args: {
|
|
67
|
+
id: tool.schema.string().describe("The PTY session ID (e.g., pty_a1b2c3d4)"),
|
|
68
|
+
data: tool.schema.string().describe("The input data to send to the PTY"),
|
|
69
|
+
},
|
|
70
|
+
execute: async (args) => {
|
|
71
|
+
const session = manager.get(args.id);
|
|
72
|
+
if (!session) {
|
|
73
|
+
throw new Error(`PTY session '${args.id}' not found. Use pty_list to see active sessions.`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (session.status !== "running") {
|
|
77
|
+
throw new Error(`Cannot write to PTY '${args.id}' - session status is '${session.status}'.`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Parse escape sequences to actual bytes
|
|
81
|
+
const parsedData = parseEscapeSequences(args.data);
|
|
82
|
+
|
|
83
|
+
const success = manager.write(args.id, parsedData);
|
|
84
|
+
if (!success) {
|
|
85
|
+
throw new Error(`Failed to write to PTY '${args.id}'.`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const preview = args.data.length > 50 ? `${args.data.slice(0, 50)}...` : args.data;
|
|
89
|
+
const displayPreview = preview
|
|
90
|
+
.replace(/\x03/g, "^C")
|
|
91
|
+
.replace(/\x04/g, "^D")
|
|
92
|
+
.replace(/\n/g, "\\n")
|
|
93
|
+
.replace(/\r/g, "\\r");
|
|
94
|
+
return `Sent ${parsedData.length} bytes to ${args.id}: "${displayPreview}"`;
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/tools/pty/types.ts
|
|
2
|
+
import type { RingBuffer } from "./buffer";
|
|
3
|
+
|
|
4
|
+
export type PTYStatus = "running" | "exited" | "killed";
|
|
5
|
+
|
|
6
|
+
export interface PTYSession {
|
|
7
|
+
id: string;
|
|
8
|
+
title: string;
|
|
9
|
+
command: string;
|
|
10
|
+
args: string[];
|
|
11
|
+
workdir: string;
|
|
12
|
+
env?: Record<string, string>;
|
|
13
|
+
status: PTYStatus;
|
|
14
|
+
exitCode?: number;
|
|
15
|
+
pid: number;
|
|
16
|
+
createdAt: Date;
|
|
17
|
+
parentSessionId: string;
|
|
18
|
+
buffer: RingBuffer;
|
|
19
|
+
process: import("bun-pty").IPty;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface PTYSessionInfo {
|
|
23
|
+
id: string;
|
|
24
|
+
title: string;
|
|
25
|
+
command: string;
|
|
26
|
+
args: string[];
|
|
27
|
+
workdir: string;
|
|
28
|
+
status: PTYStatus;
|
|
29
|
+
exitCode?: number;
|
|
30
|
+
pid: number;
|
|
31
|
+
createdAt: Date;
|
|
32
|
+
lineCount: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SpawnOptions {
|
|
36
|
+
command: string;
|
|
37
|
+
args?: string[];
|
|
38
|
+
workdir?: string;
|
|
39
|
+
env?: Record<string, string>;
|
|
40
|
+
title?: string;
|
|
41
|
+
parentSessionId: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ReadResult {
|
|
45
|
+
lines: string[];
|
|
46
|
+
totalLines: number;
|
|
47
|
+
offset: number;
|
|
48
|
+
hasMore: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface SearchMatch {
|
|
52
|
+
lineNumber: number;
|
|
53
|
+
text: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface SearchResult {
|
|
57
|
+
matches: SearchMatch[];
|
|
58
|
+
totalMatches: number;
|
|
59
|
+
totalLines: number;
|
|
60
|
+
offset: number;
|
|
61
|
+
hasMore: boolean;
|
|
62
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Shared model context limits (tokens)
|
|
2
|
+
// Used by context-window-monitor and auto-clear-ledger hooks
|
|
3
|
+
|
|
4
|
+
export const MODEL_CONTEXT_LIMITS: Record<string, number> = {
|
|
5
|
+
// Claude models
|
|
6
|
+
"claude-opus": 200_000,
|
|
7
|
+
"claude-sonnet": 200_000,
|
|
8
|
+
"claude-haiku": 200_000,
|
|
9
|
+
"claude-3": 200_000,
|
|
10
|
+
"claude-4": 200_000,
|
|
11
|
+
// OpenAI models
|
|
12
|
+
"gpt-4o": 128_000,
|
|
13
|
+
"gpt-4-turbo": 128_000,
|
|
14
|
+
"gpt-4": 128_000,
|
|
15
|
+
"gpt-5": 200_000,
|
|
16
|
+
o1: 200_000,
|
|
17
|
+
o3: 200_000,
|
|
18
|
+
// Google models
|
|
19
|
+
gemini: 1_000_000,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const DEFAULT_CONTEXT_LIMIT = 200_000;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get the context window limit for a given model ID.
|
|
26
|
+
* Matches against known patterns and falls back to default.
|
|
27
|
+
*/
|
|
28
|
+
export function getContextLimit(modelID: string): number {
|
|
29
|
+
const modelLower = modelID.toLowerCase();
|
|
30
|
+
for (const [pattern, limit] of Object.entries(MODEL_CONTEXT_LIMITS)) {
|
|
31
|
+
if (modelLower.includes(pattern)) {
|
|
32
|
+
return limit;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return DEFAULT_CONTEXT_LIMIT;
|
|
36
|
+
}
|
package/dist/agents/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { AgentConfig } from "@opencode-ai/sdk";
|
|
2
|
-
import { brainstormerAgent } from "./brainstormer";
|
|
3
|
-
import { codebaseLocatorAgent } from "./codebase-locator";
|
|
4
|
-
import { codebaseAnalyzerAgent } from "./codebase-analyzer";
|
|
5
|
-
import { patternFinderAgent } from "./pattern-finder";
|
|
6
|
-
import { plannerAgent } from "./planner";
|
|
7
|
-
import { implementerAgent } from "./implementer";
|
|
8
|
-
import { reviewerAgent } from "./reviewer";
|
|
9
|
-
import { executorAgent } from "./executor";
|
|
10
|
-
import { primaryAgent, PRIMARY_AGENT_NAME } from "./commander";
|
|
11
|
-
import { projectInitializerAgent } from "./project-initializer";
|
|
12
|
-
import { ledgerCreatorAgent } from "./ledger-creator";
|
|
13
|
-
import { artifactSearcherAgent } from "./artifact-searcher";
|
|
14
|
-
export declare const agents: Record<string, AgentConfig>;
|
|
15
|
-
export { primaryAgent, PRIMARY_AGENT_NAME, brainstormerAgent, codebaseLocatorAgent, codebaseAnalyzerAgent, patternFinderAgent, plannerAgent, implementerAgent, reviewerAgent, executorAgent, projectInitializerAgent, ledgerCreatorAgent, artifactSearcherAgent, };
|
package/dist/agents/planner.d.ts
DELETED
package/dist/config-loader.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { AgentConfig } from "@opencode-ai/sdk";
|
|
2
|
-
export interface AgentOverride {
|
|
3
|
-
model?: string;
|
|
4
|
-
temperature?: number;
|
|
5
|
-
maxTokens?: number;
|
|
6
|
-
}
|
|
7
|
-
export interface MicodeConfig {
|
|
8
|
-
agents?: Record<string, AgentOverride>;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Load micode.json from ~/.config/opencode/micode.json
|
|
12
|
-
* Returns null if file doesn't exist or is invalid JSON
|
|
13
|
-
* @param configDir - Optional override for config directory (for testing)
|
|
14
|
-
*/
|
|
15
|
-
export declare function loadMicodeConfig(configDir?: string): Promise<MicodeConfig | null>;
|
|
16
|
-
/**
|
|
17
|
-
* Merge user config overrides into plugin agent configs
|
|
18
|
-
* User overrides take precedence for safe properties only
|
|
19
|
-
*/
|
|
20
|
-
export declare function mergeAgentConfigs(pluginAgents: Record<string, AgentConfig>, userConfig: MicodeConfig | null): Record<string, AgentConfig>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { PluginInput } from "@opencode-ai/plugin";
|
|
2
|
-
export declare function parseLedger(content: string, filePath: string, sessionName: string): {
|
|
3
|
-
id: string;
|
|
4
|
-
sessionName: string;
|
|
5
|
-
filePath: string;
|
|
6
|
-
goal: string;
|
|
7
|
-
stateNow: string;
|
|
8
|
-
keyDecisions: string;
|
|
9
|
-
filesRead: string;
|
|
10
|
-
filesModified: string;
|
|
11
|
-
};
|
|
12
|
-
export declare function createArtifactAutoIndexHook(_ctx: PluginInput): {
|
|
13
|
-
"tool.execute.after": (input: {
|
|
14
|
-
tool: string;
|
|
15
|
-
args?: Record<string, unknown>;
|
|
16
|
-
}, _output: {
|
|
17
|
-
output?: string;
|
|
18
|
-
}) => Promise<void>;
|
|
19
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { PluginInput } from "@opencode-ai/plugin";
|
|
2
|
-
export declare const DEFAULT_THRESHOLD = 0.8;
|
|
3
|
-
export declare const CLEAR_COOLDOWN_MS = 60000;
|
|
4
|
-
export declare function createAutoClearLedgerHook(ctx: PluginInput): {
|
|
5
|
-
event: ({ event }: {
|
|
6
|
-
event: {
|
|
7
|
-
type: string;
|
|
8
|
-
properties?: unknown;
|
|
9
|
-
};
|
|
10
|
-
}) => Promise<void>;
|
|
11
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { PluginInput } from "@opencode-ai/plugin";
|
|
2
|
-
export declare function createCommentCheckerHook(_ctx: PluginInput): {
|
|
3
|
-
"tool.execute.after": (input: {
|
|
4
|
-
tool: string;
|
|
5
|
-
args?: Record<string, unknown>;
|
|
6
|
-
}, output: {
|
|
7
|
-
output?: string;
|
|
8
|
-
}) => Promise<void>;
|
|
9
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { PluginInput } from "@opencode-ai/plugin";
|
|
2
|
-
export declare function createContextInjectorHook(ctx: PluginInput): {
|
|
3
|
-
"chat.params": (_input: {
|
|
4
|
-
sessionID: string;
|
|
5
|
-
}, output: {
|
|
6
|
-
options?: Record<string, unknown>;
|
|
7
|
-
system?: string;
|
|
8
|
-
}) => Promise<void>;
|
|
9
|
-
"tool.execute.after": (input: {
|
|
10
|
-
tool: string;
|
|
11
|
-
args?: Record<string, unknown>;
|
|
12
|
-
}, output: {
|
|
13
|
-
output?: string;
|
|
14
|
-
}) => Promise<void>;
|
|
15
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { PluginInput } from "@opencode-ai/plugin";
|
|
2
|
-
export declare function createContextWindowMonitorHook(ctx: PluginInput): {
|
|
3
|
-
"chat.params": (input: {
|
|
4
|
-
sessionID: string;
|
|
5
|
-
}, output: {
|
|
6
|
-
system?: string;
|
|
7
|
-
options?: Record<string, unknown>;
|
|
8
|
-
}) => Promise<void>;
|
|
9
|
-
event: ({ event }: {
|
|
10
|
-
event: {
|
|
11
|
-
type: string;
|
|
12
|
-
properties?: unknown;
|
|
13
|
-
};
|
|
14
|
-
}) => Promise<void>;
|
|
15
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { PluginInput } from "@opencode-ai/plugin";
|
|
2
|
-
interface FileOps {
|
|
3
|
-
read: Set<string>;
|
|
4
|
-
modified: Set<string>;
|
|
5
|
-
}
|
|
6
|
-
export declare function trackFileOp(sessionID: string, operation: "read" | "write" | "edit", filePath: string): void;
|
|
7
|
-
export declare function getFileOps(sessionID: string): FileOps;
|
|
8
|
-
export declare function clearFileOps(sessionID: string): void;
|
|
9
|
-
export declare function getAndClearFileOps(sessionID: string): FileOps;
|
|
10
|
-
export declare function formatFileOpsForPrompt(ops: FileOps): string;
|
|
11
|
-
export declare function createFileOpsTrackerHook(_ctx: PluginInput): {
|
|
12
|
-
"tool.execute.after": (input: {
|
|
13
|
-
tool: string;
|
|
14
|
-
sessionID: string;
|
|
15
|
-
args?: Record<string, unknown>;
|
|
16
|
-
}, _output: {
|
|
17
|
-
output?: string;
|
|
18
|
-
}) => Promise<void>;
|
|
19
|
-
event: ({ event }: {
|
|
20
|
-
event: {
|
|
21
|
-
type: string;
|
|
22
|
-
properties?: unknown;
|
|
23
|
-
};
|
|
24
|
-
}) => Promise<void>;
|
|
25
|
-
};
|
|
26
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { PluginInput } from "@opencode-ai/plugin";
|
|
2
|
-
export interface LedgerInfo {
|
|
3
|
-
sessionName: string;
|
|
4
|
-
filePath: string;
|
|
5
|
-
content: string;
|
|
6
|
-
}
|
|
7
|
-
export declare function findCurrentLedger(directory: string): Promise<LedgerInfo | null>;
|
|
8
|
-
export declare function formatLedgerInjection(ledger: LedgerInfo): string;
|
|
9
|
-
export declare function createLedgerLoaderHook(ctx: PluginInput): {
|
|
10
|
-
"chat.params": (_input: {
|
|
11
|
-
sessionID: string;
|
|
12
|
-
}, output: {
|
|
13
|
-
options?: Record<string, unknown>;
|
|
14
|
-
system?: string;
|
|
15
|
-
}) => Promise<void>;
|
|
16
|
-
};
|