@cortexkit/aft-opencode 0.42.0 → 0.43.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.
Files changed (59) hide show
  1. package/dist/bg-notifications.d.ts +35 -0
  2. package/dist/bg-notifications.d.ts.map +1 -1
  3. package/dist/config.d.ts +7 -3
  4. package/dist/config.d.ts.map +1 -1
  5. package/dist/configure-warnings.d.ts +3 -3
  6. package/dist/configure-warnings.d.ts.map +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +6092 -9528
  9. package/dist/notifications.d.ts +2 -2
  10. package/dist/notifications.d.ts.map +1 -1
  11. package/dist/shared/rpc-client.d.ts +6 -0
  12. package/dist/shared/rpc-client.d.ts.map +1 -1
  13. package/dist/shared/rpc-notifications.d.ts +29 -15
  14. package/dist/shared/rpc-notifications.d.ts.map +1 -1
  15. package/dist/shared/rpc-server.d.ts +10 -1
  16. package/dist/shared/rpc-server.d.ts.map +1 -1
  17. package/dist/subc-tool-schemas.d.ts +1 -1
  18. package/dist/subc-tool-schemas.d.ts.map +1 -1
  19. package/dist/tools/_shared.d.ts +12 -2
  20. package/dist/tools/_shared.d.ts.map +1 -1
  21. package/dist/tools/ast.d.ts.map +1 -1
  22. package/dist/tools/bash.d.ts.map +1 -1
  23. package/dist/tools/bash_watch.d.ts.map +1 -1
  24. package/dist/tools/hoisted.d.ts.map +1 -1
  25. package/dist/tools/imports.d.ts.map +1 -1
  26. package/dist/tools/inspect.d.ts +0 -1
  27. package/dist/tools/inspect.d.ts.map +1 -1
  28. package/dist/tools/navigation.d.ts.map +1 -1
  29. package/dist/tools/permissions.d.ts +23 -13
  30. package/dist/tools/permissions.d.ts.map +1 -1
  31. package/dist/tools/reading.d.ts +0 -1
  32. package/dist/tools/reading.d.ts.map +1 -1
  33. package/dist/tools/refactoring.d.ts.map +1 -1
  34. package/dist/tools/safety.d.ts.map +1 -1
  35. package/dist/tools/search.d.ts.map +1 -1
  36. package/dist/tools/semantic.d.ts.map +1 -1
  37. package/dist/tui/notification-socket.d.ts +41 -0
  38. package/dist/tui/notification-socket.d.ts.map +1 -0
  39. package/dist/tui.js +2460 -187
  40. package/dist/types.d.ts +4 -2
  41. package/dist/types.d.ts.map +1 -1
  42. package/package.json +8 -9
  43. package/src/shared/rpc-client.ts +9 -0
  44. package/src/shared/rpc-notifications.ts +97 -41
  45. package/src/shared/rpc-server.ts +286 -67
  46. package/src/tui/index.tsx +77 -125
  47. package/src/tui/notification-socket.ts +421 -0
  48. package/src/tui/sidebar.tsx +38 -54
  49. package/dist/patch-parser.d.ts +0 -33
  50. package/dist/patch-parser.d.ts.map +0 -1
  51. package/dist/shared/opencode-config-dir.d.ts +0 -16
  52. package/dist/shared/opencode-config-dir.d.ts.map +0 -1
  53. package/dist/shared/pty-cache.d.ts +0 -18
  54. package/dist/shared/pty-cache.d.ts.map +0 -1
  55. package/dist/shared/tui-config.d.ts +0 -2
  56. package/dist/shared/tui-config.d.ts.map +0 -1
  57. package/src/shared/opencode-config-dir.ts +0 -46
  58. package/src/shared/pty-cache.ts +0 -113
  59. package/src/shared/tui-config.ts +0 -58
@@ -1,46 +0,0 @@
1
- import { homedir } from "node:os";
2
- import { join, resolve } from "node:path";
3
-
4
- export type OpenCodeBinaryType = "opencode" | "opencode-desktop";
5
-
6
- export interface OpenCodeConfigDirOptions {
7
- binary: OpenCodeBinaryType;
8
- version?: string | null;
9
- checkExisting?: boolean;
10
- }
11
-
12
- export interface OpenCodeConfigPaths {
13
- configDir: string;
14
- configJson: string;
15
- configJsonc: string;
16
- packageJson: string;
17
- omoConfig: string;
18
- }
19
-
20
- function getCliConfigDir(): string {
21
- const envConfigDir = process.env.OPENCODE_CONFIG_DIR?.trim();
22
- if (envConfigDir) {
23
- return resolve(envConfigDir);
24
- }
25
-
26
- if (process.platform === "win32") {
27
- return join(homedir(), ".config", "opencode");
28
- }
29
-
30
- return join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "opencode");
31
- }
32
-
33
- export function getOpenCodeConfigDir(_options: OpenCodeConfigDirOptions): string {
34
- return getCliConfigDir();
35
- }
36
-
37
- export function getOpenCodeConfigPaths(options: OpenCodeConfigDirOptions): OpenCodeConfigPaths {
38
- const configDir = getOpenCodeConfigDir(options);
39
- return {
40
- configDir,
41
- configJson: join(configDir, "opencode.json"),
42
- configJsonc: join(configDir, "opencode.jsonc"),
43
- packageJson: join(configDir, "package.json"),
44
- omoConfig: join(configDir, "magic-context.jsonc"),
45
- };
46
- }
@@ -1,113 +0,0 @@
1
- import * as fs from "node:fs/promises";
2
- import { Terminal } from "@xterm/headless";
3
-
4
- const DEFAULT_COLS = 80;
5
- const DEFAULT_ROWS = 24;
6
- const READ_CHUNK_SIZE = 64 * 1024;
7
-
8
- export interface PtyTerminalState {
9
- terminal: Terminal;
10
- fileHandle: fs.FileHandle;
11
- offset: number;
12
- rows: number;
13
- cols: number;
14
- lastAccessMs: number;
15
- }
16
-
17
- const terminals = new Map<string, PtyTerminalState>();
18
-
19
- export async function getOrCreatePtyTerminal(
20
- key: string,
21
- outputPath: string,
22
- rows = DEFAULT_ROWS,
23
- cols = DEFAULT_COLS,
24
- ): Promise<PtyTerminalState> {
25
- const existing = terminals.get(key);
26
- if (existing) {
27
- existing.lastAccessMs = Date.now();
28
- if (existing.rows === rows && existing.cols === cols) {
29
- return existing;
30
- }
31
- terminals.delete(key);
32
- existing.terminal.dispose();
33
- await existing.fileHandle.close().catch(() => undefined);
34
- }
35
-
36
- const fileHandle = await fs.open(outputPath, "r");
37
- const state: PtyTerminalState = {
38
- terminal: new Terminal({ cols, rows, allowProposedApi: true }),
39
- fileHandle,
40
- offset: 0,
41
- rows,
42
- cols,
43
- lastAccessMs: Date.now(),
44
- };
45
- terminals.set(key, state);
46
- return state;
47
- }
48
-
49
- export async function readPtyBytes(state: PtyTerminalState): Promise<Buffer> {
50
- const chunks: Buffer[] = [];
51
- while (true) {
52
- const buffer = Buffer.allocUnsafe(READ_CHUNK_SIZE);
53
- const { bytesRead } = await state.fileHandle.read(buffer, 0, buffer.length, state.offset);
54
- if (bytesRead === 0) break;
55
- const chunk = buffer.subarray(0, bytesRead);
56
- chunks.push(Buffer.from(chunk));
57
- await writeTerminal(state.terminal, chunk);
58
- state.offset += bytesRead;
59
- }
60
- state.lastAccessMs = Date.now();
61
- return Buffer.concat(chunks);
62
- }
63
-
64
- export async function disposePtyTerminal(key: string): Promise<void> {
65
- const state = terminals.get(key);
66
- if (!state) return;
67
- terminals.delete(key);
68
- state.terminal.dispose();
69
- await state.fileHandle.close().catch(() => undefined);
70
- }
71
-
72
- export async function disposeAllPtyTerminals(): Promise<void> {
73
- await Promise.all([...terminals.keys()].map((key) => disposePtyTerminal(key)));
74
- }
75
-
76
- export function renderScreen(
77
- state: PtyTerminalState,
78
- rows = state.rows,
79
- cols = state.cols,
80
- ): string {
81
- const active = state.terminal.buffer.active;
82
- const lines: string[] = [];
83
- for (let y = 0; y < rows; y++) {
84
- const line = active.getLine(active.baseY + y);
85
- if (!line) {
86
- lines.push("");
87
- continue;
88
- }
89
- let text = "";
90
- for (let x = 0; x < cols; x++) {
91
- text += line.getCell(x)?.getChars() || " ";
92
- }
93
- lines.push(text.trimEnd());
94
- }
95
- while (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
96
- return lines.join("\n");
97
- }
98
-
99
- export function __resetPtyCacheForTests(): void {
100
- for (const state of terminals.values()) {
101
- state.terminal.dispose();
102
- void state.fileHandle.close().catch(() => undefined);
103
- }
104
- terminals.clear();
105
- }
106
-
107
- export function __ptyCacheSizeForTests(): number {
108
- return terminals.size;
109
- }
110
-
111
- function writeTerminal(terminal: Terminal, data: Uint8Array): Promise<void> {
112
- return new Promise((resolve) => terminal.write(data, resolve));
113
- }
@@ -1,58 +0,0 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
- import { dirname, join } from "node:path";
3
- import { parse, stringify } from "comment-json";
4
- import { log } from "../logger";
5
- import { getOpenCodeConfigPaths } from "./opencode-config-dir";
6
-
7
- const PLUGIN_NAME = "@cortexkit/aft-opencode";
8
- const PLUGIN_ENTRY = `${PLUGIN_NAME}@latest`;
9
-
10
- function resolveTuiConfigPath(): string {
11
- const configDir = getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
12
- const jsoncPath = join(configDir, "tui.jsonc");
13
- const jsonPath = join(configDir, "tui.json");
14
-
15
- if (existsSync(jsoncPath)) return jsoncPath;
16
- if (existsSync(jsonPath)) return jsonPath;
17
- return jsonPath;
18
- }
19
-
20
- export function ensureTuiPluginEntry(): boolean {
21
- try {
22
- const configPath = resolveTuiConfigPath();
23
-
24
- let config: Record<string, unknown> = {};
25
- if (existsSync(configPath)) {
26
- config = (parse(readFileSync(configPath, "utf-8")) as Record<string, unknown>) ?? {};
27
- }
28
-
29
- const plugins = Array.isArray(config.plugin)
30
- ? config.plugin.filter((value): value is string => typeof value === "string")
31
- : [];
32
-
33
- if (
34
- plugins.some(
35
- (plugin) =>
36
- plugin === PLUGIN_NAME ||
37
- plugin.startsWith(`${PLUGIN_NAME}@`) ||
38
- plugin.includes("opencode-plugin") ||
39
- plugin.includes("aft-opencode"),
40
- )
41
- ) {
42
- return false;
43
- }
44
-
45
- plugins.push(PLUGIN_ENTRY);
46
- config.plugin = plugins;
47
-
48
- mkdirSync(dirname(configPath), { recursive: true });
49
- writeFileSync(configPath, `${stringify(config, null, 2)}\n`);
50
- log(`[aft-plugin] added TUI plugin entry to ${configPath}`);
51
- return true;
52
- } catch (error) {
53
- log(
54
- `[aft-plugin] failed to update tui.json: ${error instanceof Error ? error.message : String(error)}`,
55
- );
56
- return false;
57
- }
58
- }