toolcraft 0.0.168 → 0.0.169
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/composition.json
CHANGED
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
},
|
|
114
114
|
{
|
|
115
115
|
"name": "toolcraft",
|
|
116
|
-
"version": "0.0.
|
|
116
|
+
"version": "0.0.169",
|
|
117
117
|
"license": "MIT"
|
|
118
118
|
},
|
|
119
119
|
{
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
},
|
|
124
124
|
{
|
|
125
125
|
"name": "toolcraft-schema",
|
|
126
|
-
"version": "0.0.
|
|
126
|
+
"version": "0.0.169",
|
|
127
127
|
"license": "MIT"
|
|
128
128
|
},
|
|
129
129
|
{
|
package/dist/composition.json
CHANGED
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
},
|
|
114
114
|
{
|
|
115
115
|
"name": "toolcraft",
|
|
116
|
-
"version": "0.0.
|
|
116
|
+
"version": "0.0.169",
|
|
117
117
|
"license": "MIT"
|
|
118
118
|
},
|
|
119
119
|
{
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
},
|
|
124
124
|
{
|
|
125
125
|
"name": "toolcraft-schema",
|
|
126
|
-
"version": "0.0.
|
|
126
|
+
"version": "0.0.169",
|
|
127
127
|
"license": "MIT"
|
|
128
128
|
},
|
|
129
129
|
{
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
2
|
import * as readline from "node:readline";
|
|
3
|
+
import { Readable } from "node:stream";
|
|
4
|
+
import { StringDecoder } from "node:string_decoder";
|
|
3
5
|
import { graphemes } from "../../dashboard/terminal-width.js";
|
|
4
6
|
import { CANCEL } from "./cancel-symbol.js";
|
|
5
7
|
import { mapKey } from "./keys.js";
|
|
6
8
|
import { wrapFrame } from "./wrap.js";
|
|
9
|
+
const pendingCarriageReturns = new WeakMap();
|
|
7
10
|
const cursor = {
|
|
8
11
|
hide: "\x1b[?25l",
|
|
9
12
|
show: "\x1b[?25h",
|
|
@@ -128,6 +131,88 @@ export class Prompt extends EventEmitter {
|
|
|
128
131
|
this.state = "cancel";
|
|
129
132
|
return Promise.resolve(CANCEL);
|
|
130
133
|
}
|
|
134
|
+
const input = this.input;
|
|
135
|
+
if (input instanceof Readable) {
|
|
136
|
+
return new Promise((resolve, reject) => {
|
|
137
|
+
const decoder = new StringDecoder("utf8");
|
|
138
|
+
let line = "";
|
|
139
|
+
let settled = false;
|
|
140
|
+
const settle = (value, remainder) => {
|
|
141
|
+
if (settled)
|
|
142
|
+
return;
|
|
143
|
+
settled = true;
|
|
144
|
+
input.removeListener("data", onData);
|
|
145
|
+
input.removeListener("end", onEnd);
|
|
146
|
+
input.removeListener("close", onCancel);
|
|
147
|
+
input.removeListener("error", settle);
|
|
148
|
+
this.signal?.removeEventListener("abort", onCancel);
|
|
149
|
+
input.pause();
|
|
150
|
+
if (remainder?.length)
|
|
151
|
+
input.unshift(remainder, input.readableEncoding ?? undefined);
|
|
152
|
+
if (value instanceof Error)
|
|
153
|
+
reject(value);
|
|
154
|
+
else
|
|
155
|
+
resolve(value);
|
|
156
|
+
};
|
|
157
|
+
const onCancel = () => {
|
|
158
|
+
this.state = "cancel";
|
|
159
|
+
settle(CANCEL);
|
|
160
|
+
};
|
|
161
|
+
const onEnd = () => settle(line + decoder.end());
|
|
162
|
+
const onData = (chunk) => {
|
|
163
|
+
if (chunk.length === 0)
|
|
164
|
+
return;
|
|
165
|
+
if (settled) {
|
|
166
|
+
if (!input.destroyed)
|
|
167
|
+
input.unshift(chunk, input.readableEncoding ?? undefined);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
let offset = 0;
|
|
171
|
+
const previousCarriageReturn = pendingCarriageReturns.get(input);
|
|
172
|
+
if (previousCarriageReturn !== undefined) {
|
|
173
|
+
pendingCarriageReturns.delete(input);
|
|
174
|
+
const isLineFeed = typeof chunk === "string" ? chunk[0] === "\n" : chunk[0] === 10;
|
|
175
|
+
if (isLineFeed && Date.now() - previousCarriageReturn <= 100)
|
|
176
|
+
offset = 1;
|
|
177
|
+
}
|
|
178
|
+
for (; offset < chunk.length; offset += 1) {
|
|
179
|
+
const character = typeof chunk === "string" ? chunk[offset] : decoder.write(chunk.subarray(offset, offset + 1));
|
|
180
|
+
if (character.endsWith("\r") || character.endsWith("\n")) {
|
|
181
|
+
line += character.slice(0, -1);
|
|
182
|
+
offset += 1;
|
|
183
|
+
if (character.endsWith("\r")) {
|
|
184
|
+
if (offset === chunk.length) {
|
|
185
|
+
pendingCarriageReturns.set(input, Date.now());
|
|
186
|
+
}
|
|
187
|
+
else if (typeof chunk === "string" ? chunk[offset] === "\n" : chunk[offset] === 10) {
|
|
188
|
+
offset += 1;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
settle(line, chunk.slice(offset));
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
line += character;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
input.once("end", onEnd);
|
|
198
|
+
input.once("close", onCancel);
|
|
199
|
+
input.once("error", settle);
|
|
200
|
+
this.signal?.addEventListener("abort", onCancel, { once: true });
|
|
201
|
+
if (this.signal?.aborted)
|
|
202
|
+
onCancel();
|
|
203
|
+
else if (input.readableEnded)
|
|
204
|
+
onEnd();
|
|
205
|
+
else if (input.destroyed)
|
|
206
|
+
onCancel();
|
|
207
|
+
else if (!settled) {
|
|
208
|
+
input.on("data", onData);
|
|
209
|
+
if (!settled)
|
|
210
|
+
input.resume();
|
|
211
|
+
if (settled)
|
|
212
|
+
input.pause();
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
131
216
|
return new Promise((resolve, reject) => {
|
|
132
217
|
let rl = null;
|
|
133
218
|
let settled = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toolcraft",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.169",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -158,7 +158,7 @@
|
|
|
158
158
|
"yaml"
|
|
159
159
|
],
|
|
160
160
|
"optionalDependencies": {
|
|
161
|
-
"toolcraft-schema": "0.0.
|
|
161
|
+
"toolcraft-schema": "0.0.169",
|
|
162
162
|
"toolcraft-design": "*",
|
|
163
163
|
"@poe-code/frontmatter": "*",
|
|
164
164
|
"@poe-code/agent-mcp-config": "*",
|