@opencode/simulation 0.0.0-reserved → 2.0.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/dist/backend/index.d.ts +17 -0
- package/dist/backend/index.js +29 -0
- package/dist/backend/network.d.ts +33 -0
- package/dist/backend/network.js +44 -0
- package/dist/backend/openai.d.ts +4 -0
- package/dist/backend/openai.js +101 -0
- package/dist/backend/simulated-provider.d.ts +27 -0
- package/dist/backend/simulated-provider.js +485 -0
- package/dist/control-server.d.ts +27 -0
- package/dist/control-server.js +99 -0
- package/dist/frontend/actions.d.ts +122 -0
- package/dist/frontend/actions.js +180 -0
- package/dist/frontend/renderer.d.ts +20 -0
- package/dist/frontend/renderer.js +41 -0
- package/dist/frontend/semantics.d.ts +8 -0
- package/dist/frontend/semantics.js +7 -0
- package/dist/frontend/server.d.ts +6 -0
- package/dist/frontend/server.js +66 -0
- package/dist/frontend/simulation.d.ts +5 -0
- package/dist/frontend/simulation.js +20 -0
- package/dist/manifest.d.ts +27 -0
- package/dist/manifest.js +61 -0
- package/dist/protocol/index.d.ts +2 -0
- package/dist/protocol/index.js +10 -0
- package/dist/recording.d.ts +77 -0
- package/dist/recording.js +131 -0
- package/package.json +56 -6
- package/README.md +0 -5
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { createWriteStream } from "node:fs";
|
|
2
|
+
import { mkdir } from "node:fs/promises";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
import { Writable } from "node:stream";
|
|
5
|
+
import { finished } from "node:stream/promises";
|
|
6
|
+
import { Schema } from "effect";
|
|
7
|
+
export const Header = Schema.Struct({
|
|
8
|
+
type: Schema.Literal("header"),
|
|
9
|
+
version: Schema.Literal(1),
|
|
10
|
+
cols: Schema.Number,
|
|
11
|
+
rows: Schema.Number,
|
|
12
|
+
encoding: Schema.Literal("base64")
|
|
13
|
+
}), Output = Schema.Struct({
|
|
14
|
+
type: Schema.Literal("output"),
|
|
15
|
+
at_ms: Schema.Number,
|
|
16
|
+
data: Schema.String
|
|
17
|
+
}), Resize = Schema.Struct({
|
|
18
|
+
type: Schema.Literal("resize"),
|
|
19
|
+
at_ms: Schema.Number,
|
|
20
|
+
cols: Schema.Number,
|
|
21
|
+
rows: Schema.Number
|
|
22
|
+
}), Event = Schema.Union([Header, Output, Resize]), Pointer = Schema.Struct({
|
|
23
|
+
atMs: Schema.Number,
|
|
24
|
+
action: Schema.Literals(["move", "down", "up", "click", "scroll"]),
|
|
25
|
+
x: Schema.Number,
|
|
26
|
+
y: Schema.Number
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export class Timeline extends Writable {
|
|
30
|
+
isTTY = !0;
|
|
31
|
+
path;
|
|
32
|
+
columns;
|
|
33
|
+
rows;
|
|
34
|
+
output;
|
|
35
|
+
started = performance.now();
|
|
36
|
+
timestamps = [];
|
|
37
|
+
done;
|
|
38
|
+
pointers;
|
|
39
|
+
constructor(path, cols, rows, output) {
|
|
40
|
+
super();
|
|
41
|
+
this.path = path;
|
|
42
|
+
this.columns = cols;
|
|
43
|
+
this.rows = rows;
|
|
44
|
+
this.output = output;
|
|
45
|
+
this.on("error", () => {});
|
|
46
|
+
output.on("error", (error) => this.destroy(error));
|
|
47
|
+
}
|
|
48
|
+
static async create(path, cols, rows) {
|
|
49
|
+
await mkdir(dirname(path), { recursive: !0 });
|
|
50
|
+
const output = createWriteStream(path), timeline = new Timeline(path, cols, rows, output);
|
|
51
|
+
await new Promise((resolve, reject) => {
|
|
52
|
+
output.write(`${JSON.stringify({ type: "header", version: 1, cols, rows, encoding: "base64" })}
|
|
53
|
+
`, (error) => error ? reject(error) : resolve());
|
|
54
|
+
});
|
|
55
|
+
return timeline;
|
|
56
|
+
}
|
|
57
|
+
getColorDepth() {
|
|
58
|
+
return 24;
|
|
59
|
+
}
|
|
60
|
+
write(chunk, encoding, callback) {
|
|
61
|
+
if (!this.writableEnded) {
|
|
62
|
+
this.timestamps.push(this.elapsed());
|
|
63
|
+
if (typeof encoding === "function")
|
|
64
|
+
return super.write(chunk, encoding);
|
|
65
|
+
if (encoding === void 0)
|
|
66
|
+
return super.write(chunk, callback);
|
|
67
|
+
return super.write(chunk, encoding, callback);
|
|
68
|
+
}
|
|
69
|
+
const done = typeof encoding === "function" ? encoding : callback;
|
|
70
|
+
queueMicrotask(() => done?.(null));
|
|
71
|
+
return !0;
|
|
72
|
+
}
|
|
73
|
+
_write(chunk, _encoding, callback) {
|
|
74
|
+
this.writeOutput(chunk, this.timestamps.shift() ?? this.elapsed(), callback);
|
|
75
|
+
}
|
|
76
|
+
_final(callback) {
|
|
77
|
+
this.writeOutput(Buffer.alloc(0), this.elapsed(), (error) => {
|
|
78
|
+
if (error)
|
|
79
|
+
return callback(error);
|
|
80
|
+
this.output.end();
|
|
81
|
+
this.pointers?.end();
|
|
82
|
+
Promise.all(this.streams().map((stream) => finished(stream, { cleanup: !0 }))).then(() => callback(), callback);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
_destroy(error, callback) {
|
|
86
|
+
const streams = this.streams(), closed = streams.map((stream) => finished(stream, { cleanup: !0 }));
|
|
87
|
+
streams.forEach((stream) => stream.destroy());
|
|
88
|
+
Promise.allSettled(closed).then(() => callback(error));
|
|
89
|
+
}
|
|
90
|
+
finish() {
|
|
91
|
+
if (this.done)
|
|
92
|
+
return this.done;
|
|
93
|
+
this.end();
|
|
94
|
+
this.done = finished(this, { cleanup: !0 }).then(() => this.path);
|
|
95
|
+
return this.done;
|
|
96
|
+
}
|
|
97
|
+
resize(cols, rows) {
|
|
98
|
+
if (this.writableEnded)
|
|
99
|
+
return;
|
|
100
|
+
const event = { type: "resize", at_ms: this.elapsed(), cols, rows };
|
|
101
|
+
this.output.write(`${JSON.stringify(event)}
|
|
102
|
+
`);
|
|
103
|
+
}
|
|
104
|
+
pointer(action, x, y) {
|
|
105
|
+
if (this.writableEnded || this.destroyed)
|
|
106
|
+
return;
|
|
107
|
+
if (!this.pointers) {
|
|
108
|
+
this.pointers = createWriteStream(`${this.path.replace(/\.jsonl$/, "")}.pointers.jsonl`);
|
|
109
|
+
this.pointers.on("error", (error) => this.destroy(error));
|
|
110
|
+
}
|
|
111
|
+
this.pointers.write(`${JSON.stringify({ atMs: this.elapsed(), action, x, y })}
|
|
112
|
+
`);
|
|
113
|
+
}
|
|
114
|
+
streams() {
|
|
115
|
+
return this.pointers ? [this.output, this.pointers] : [this.output];
|
|
116
|
+
}
|
|
117
|
+
elapsed() {
|
|
118
|
+
return Math.max(0, Math.round(performance.now() - this.started));
|
|
119
|
+
}
|
|
120
|
+
writeOutput(data, at_ms, callback) {
|
|
121
|
+
const event = {
|
|
122
|
+
type: "output",
|
|
123
|
+
at_ms,
|
|
124
|
+
data: data.toString("base64")
|
|
125
|
+
};
|
|
126
|
+
this.output.write(`${JSON.stringify(event)}
|
|
127
|
+
`, callback);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export * as SimulationRecording from "./recording";
|
package/package.json
CHANGED
|
@@ -1,15 +1,65 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
2
3
|
"name": "@opencode/simulation",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
4
|
+
"version": "2.0.1",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"license": "MIT",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/anomalyco/opencode.git"
|
|
9
|
+
"url": "git+https://github.com/anomalyco/opencode.git",
|
|
10
|
+
"directory": "packages/simulation"
|
|
9
11
|
},
|
|
10
12
|
"publishConfig": {
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
"./backend": {
|
|
20
|
+
"import": "./dist/backend/index.js",
|
|
21
|
+
"types": "./dist/backend/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./backend/*": {
|
|
24
|
+
"import": "./dist/backend/*.js",
|
|
25
|
+
"types": "./dist/backend/*.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"./frontend": {
|
|
28
|
+
"import": "./dist/frontend/simulation.js",
|
|
29
|
+
"types": "./dist/frontend/simulation.d.ts"
|
|
30
|
+
},
|
|
31
|
+
"./frontend/*": {
|
|
32
|
+
"import": "./dist/frontend/*.js",
|
|
33
|
+
"types": "./dist/frontend/*.d.ts"
|
|
34
|
+
},
|
|
35
|
+
"./protocol": {
|
|
36
|
+
"import": "./dist/protocol/index.js",
|
|
37
|
+
"types": "./dist/protocol/index.d.ts"
|
|
38
|
+
},
|
|
39
|
+
"./recording": {
|
|
40
|
+
"import": "./dist/recording.js",
|
|
41
|
+
"types": "./dist/recording.d.ts"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "bun run script/build.ts",
|
|
46
|
+
"test": "bun test --timeout 30000 --only-failures",
|
|
47
|
+
"typecheck": "tsgo -b"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@opencode/core": "2.0.1",
|
|
51
|
+
"@opencode/ai": "2.0.1",
|
|
52
|
+
"@opencode/plugin": "2.0.1",
|
|
53
|
+
"@opencode/protocol": "2.0.1",
|
|
54
|
+
"@opencode/util": "2.0.1",
|
|
55
|
+
"@opentui/core": "0.5.10",
|
|
56
|
+
"effect": "4.0.0-rc.112",
|
|
57
|
+
"ws": "8.21.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@tsconfig/bun": "1.0.9",
|
|
61
|
+
"@types/bun": "1.4.0",
|
|
62
|
+
"@types/ws": "8.18.1",
|
|
63
|
+
"@typescript/native-preview": "7.0.0-dev.20251207.1"
|
|
14
64
|
}
|
|
15
65
|
}
|