@oxbit/cli 0.10.1 → 0.11.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/agent/dist/assets/{index-BrBnidfI.js → index-T_6HaJx-.js} +496 -155
- package/agent/dist/assets/memory-Bdy8hvTl.js +135 -0
- package/agent/dist/index.js +1190 -303
- package/package.json +1 -1
- package/runtime/dist/index.js +1 -1
- package/runtime/package.json +1 -1
- package/web/dist/assets/{index-CUIuo9fs.js → index-W9bbEyD_.js} +159 -158
- package/web/dist/assets/{typescript-BU_Up1oE.js → typescript-DTI4y3t9.js} +2 -2
- package/web/dist/index.html +1 -1
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdirSync, appendFileSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
import { w as walkFiles } from "../index.js";
|
|
5
|
+
import "node:util";
|
|
6
|
+
import "node:readline";
|
|
7
|
+
import "node:fs/promises";
|
|
8
|
+
import "node:crypto";
|
|
9
|
+
import "node:os";
|
|
10
|
+
import "node:child_process";
|
|
11
|
+
import "node:http";
|
|
12
|
+
const FILE_LIST_TTL_MS = 1e4;
|
|
13
|
+
const FILE_MATCHES = 2e3;
|
|
14
|
+
const HISTORY_LIMIT = 500;
|
|
15
|
+
const subsequence = (query, path) => {
|
|
16
|
+
let at = 0;
|
|
17
|
+
for (const char of query) {
|
|
18
|
+
at = path.indexOf(char, at) + 1;
|
|
19
|
+
if (!at) return false;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
function memoryTuiConnection(initial, options = {}) {
|
|
24
|
+
let connection = initial;
|
|
25
|
+
let info = { provider: options.provider, usingChatGPTPlan: options.usingChatGPTPlan };
|
|
26
|
+
let mode = options.mode;
|
|
27
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
28
|
+
let permission;
|
|
29
|
+
const attach = (target) => [
|
|
30
|
+
target.onUpdate((sessionId, update) => {
|
|
31
|
+
for (const listener of [...listeners]) {
|
|
32
|
+
try {
|
|
33
|
+
listener(sessionId, update);
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
38
|
+
target.onPermission(async (request) => permission ? (await permission(request)).outcome : { outcome: "cancelled" })
|
|
39
|
+
];
|
|
40
|
+
let detach = attach(connection);
|
|
41
|
+
const listed = /* @__PURE__ */ new Map();
|
|
42
|
+
const files = (cwd) => {
|
|
43
|
+
const cached = listed.get(cwd);
|
|
44
|
+
if (cached && Date.now() - cached.at < FILE_LIST_TTL_MS) return cached.files;
|
|
45
|
+
const entry = { at: Date.now(), files: walkFiles(cwd).catch(() => []) };
|
|
46
|
+
listed.set(cwd, entry);
|
|
47
|
+
return entry.files;
|
|
48
|
+
};
|
|
49
|
+
const settings = options.settings;
|
|
50
|
+
return {
|
|
51
|
+
get connection() {
|
|
52
|
+
return connection;
|
|
53
|
+
},
|
|
54
|
+
async replace(next, nextInfo) {
|
|
55
|
+
const previous = connection;
|
|
56
|
+
for (const stop of detach) stop();
|
|
57
|
+
connection = next;
|
|
58
|
+
detach = attach(next);
|
|
59
|
+
info = { ...nextInfo };
|
|
60
|
+
await previous.close();
|
|
61
|
+
},
|
|
62
|
+
info: () => ({ ...info }),
|
|
63
|
+
async newSession(cwd) {
|
|
64
|
+
const state = await connection.newSession({ cwd });
|
|
65
|
+
if (!mode || !state.modes || state.modes.currentModeId === mode) return state;
|
|
66
|
+
await connection.setMode(state.sessionId, mode);
|
|
67
|
+
return { ...state, modes: { ...state.modes, currentModeId: mode } };
|
|
68
|
+
},
|
|
69
|
+
loadSession: async (sessionId, cwd) => await connection.loadSession(sessionId, { cwd }),
|
|
70
|
+
listSessions: async (cwd) => (await connection.listSessions(cwd)).sessions,
|
|
71
|
+
prompt: (sessionId, prompt) => connection.prompt(sessionId, prompt),
|
|
72
|
+
cancel: (sessionId) => connection.cancel(sessionId),
|
|
73
|
+
setMode: (sessionId, modeId) => connection.setMode(sessionId, modeId),
|
|
74
|
+
setModel: async (sessionId, modelId) => await connection.setModel(sessionId, modelId),
|
|
75
|
+
setConfigOption: async (sessionId, configId, value) => await connection.setConfigOption(sessionId, configId, value),
|
|
76
|
+
onUpdate(listener) {
|
|
77
|
+
listeners.add(listener);
|
|
78
|
+
return () => void listeners.delete(listener);
|
|
79
|
+
},
|
|
80
|
+
onPermission(handler) {
|
|
81
|
+
permission = handler;
|
|
82
|
+
return () => {
|
|
83
|
+
if (permission === handler) permission = void 0;
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
async listFiles(query, cwd) {
|
|
87
|
+
const term = query.toLowerCase();
|
|
88
|
+
return (await files(cwd)).filter((path) => subsequence(term, path.toLowerCase())).slice(0, FILE_MATCHES);
|
|
89
|
+
},
|
|
90
|
+
...settings ? { settings: {
|
|
91
|
+
panel: (id, context) => settings.panel(id, context),
|
|
92
|
+
toggle: (id, rowId, enabled, context) => settings.toggle(id, rowId, enabled, context),
|
|
93
|
+
async choose(id, rowId, value, context) {
|
|
94
|
+
const change = await settings.choose(id, rowId, value, context);
|
|
95
|
+
if (change.mode) mode = change.mode;
|
|
96
|
+
return change;
|
|
97
|
+
},
|
|
98
|
+
act: (id, rowId, actionId, inputs, context) => settings.act(id, rowId, actionId, inputs, context)
|
|
99
|
+
} } : {}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function fileHistory(path) {
|
|
103
|
+
return {
|
|
104
|
+
load() {
|
|
105
|
+
try {
|
|
106
|
+
return readFileSync(path, "utf8").split("\n").flatMap((line) => {
|
|
107
|
+
try {
|
|
108
|
+
const entry = JSON.parse(line);
|
|
109
|
+
return typeof entry === "string" ? [entry] : [];
|
|
110
|
+
} catch {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
}).slice(-HISTORY_LIMIT);
|
|
114
|
+
} catch {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
save(entry) {
|
|
119
|
+
try {
|
|
120
|
+
mkdirSync(dirname(path), { recursive: true, mode: 448 });
|
|
121
|
+
appendFileSync(path, `${JSON.stringify(entry)}
|
|
122
|
+
`, { mode: 384 });
|
|
123
|
+
const lines = readFileSync(path, "utf8").split("\n").filter(Boolean);
|
|
124
|
+
if (lines.length > HISTORY_LIMIT * 2) writeFileSync(path, `${lines.slice(-HISTORY_LIMIT).join("\n")}
|
|
125
|
+
`, { mode: 384 });
|
|
126
|
+
} catch {
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export {
|
|
132
|
+
fileHistory,
|
|
133
|
+
memoryTuiConnection
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=memory-Bdy8hvTl.js.map
|