kibi-cli 0.2.0 → 0.2.2
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/prolog.d.ts +1 -0
- package/dist/prolog.d.ts.map +1 -1
- package/dist/prolog.js +82 -67
- package/package.json +9 -3
package/dist/prolog.d.ts
CHANGED
package/dist/prolog.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prolog.d.ts","sourceRoot":"","sources":["../src/prolog.ts"],"names":[],"mappings":"AAuDA,wBAAgB,eAAe,IAAI,MAAM,CAsCxC;AACD,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,WAAW,CAAM;IACzB,OAAO,CAAC,KAAK,CAAuC;IACpD,OAAO,CAAC,cAAc,CACyC;IAC/D,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,aAAa,CAA6B;gBAEtC,OAAO,GAAE,aAAkB;IAKjC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAoCd,YAAY;IAyCpB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"prolog.d.ts","sourceRoot":"","sources":["../src/prolog.ts"],"names":[],"mappings":"AAuDA,wBAAgB,eAAe,IAAI,MAAM,CAsCxC;AACD,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,WAAW,CAAM;IACzB,OAAO,CAAC,KAAK,CAAuC;IACpD,OAAO,CAAC,oBAAoB,CAAoC;IAChE,OAAO,CAAC,cAAc,CACyC;IAC/D,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,aAAa,CAA6B;gBAEtC,OAAO,GAAE,aAAkB;IAKjC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAoCd,YAAY;IAyCpB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IA8I1D,eAAe,IAAI,IAAI;IAIvB,OAAO,CAAC,eAAe;YAYT,YAAY;IA0B1B,OAAO,CAAC,WAAW;IA8EnB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,cAAc;IA8BtB,SAAS,IAAI,OAAO;IAIpB,MAAM,IAAI,MAAM;IAIV,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAyBjC"}
|
package/dist/prolog.js
CHANGED
|
@@ -85,6 +85,7 @@ export class PrologProcess {
|
|
|
85
85
|
outputBuffer = "";
|
|
86
86
|
errorBuffer = "";
|
|
87
87
|
cache = new Map();
|
|
88
|
+
interactiveQueryTail = Promise.resolve();
|
|
88
89
|
useOneShotMode = typeof globalThis.Bun !== "undefined";
|
|
89
90
|
attachedKbPath = null;
|
|
90
91
|
onProcessExit = null;
|
|
@@ -174,78 +175,92 @@ export class PrologProcess {
|
|
|
174
175
|
if (!this.process || !this.process.stdin) {
|
|
175
176
|
throw new Error("Prolog process not started");
|
|
176
177
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
clearTimeout(timeoutId);
|
|
216
|
-
const result = {
|
|
217
|
-
success: true,
|
|
218
|
-
bindings: this.extractBindings(this.outputBuffer),
|
|
219
|
-
};
|
|
220
|
-
if (cacheable) {
|
|
221
|
-
this.cache.set(goalKey, result);
|
|
178
|
+
const runInteractiveQuery = async () => {
|
|
179
|
+
this.outputBuffer = "";
|
|
180
|
+
this.errorBuffer = "";
|
|
181
|
+
const debug = !!process.env.KIBI_PROLOG_DEBUG;
|
|
182
|
+
const normalizedGoal = this.normalizeGoal(goal);
|
|
183
|
+
const wrappedGoal = /^once\s*\(/.test(normalizedGoal)
|
|
184
|
+
? normalizedGoal
|
|
185
|
+
: `once((${normalizedGoal}))`;
|
|
186
|
+
const start = Date.now();
|
|
187
|
+
if (debug) {
|
|
188
|
+
console.error(`[prolog debug] start query: ${normalizedGoal}`);
|
|
189
|
+
}
|
|
190
|
+
this.process?.stdin?.write(`${wrappedGoal}.\n`);
|
|
191
|
+
return new Promise((resolve, reject) => {
|
|
192
|
+
const timeoutId = setTimeout(() => {
|
|
193
|
+
const msg = `Query timeout after ${this.timeout / 1000}s (pid=${this.process?.pid ?? 0}, killed=${this.process?.killed ? "yes" : "no"}, exitCode=${this.process?.exitCode ?? "null"}, goal=${JSON.stringify(normalizedGoal.slice(0, 120))})`;
|
|
194
|
+
if (debug) {
|
|
195
|
+
const tailOut = this.outputBuffer.slice(-2048);
|
|
196
|
+
const tailErr = this.errorBuffer.slice(-2048);
|
|
197
|
+
console.error(`[prolog debug] timeout: ${msg}`);
|
|
198
|
+
console.error(`[prolog debug] last stdout: ---\n${tailOut}\n---`);
|
|
199
|
+
console.error(`[prolog debug] last stderr: ---\n${tailErr}\n---`);
|
|
200
|
+
}
|
|
201
|
+
reject(new Error(msg));
|
|
202
|
+
}, this.timeout);
|
|
203
|
+
const checkResult = () => {
|
|
204
|
+
if (this.errorBuffer.length > 0 &&
|
|
205
|
+
this.errorBuffer.includes("ERROR")) {
|
|
206
|
+
clearTimeout(timeoutId);
|
|
207
|
+
if (debug) {
|
|
208
|
+
console.error(`[prolog debug] query error: ${normalizedGoal} error=${this.errorBuffer.split("\n")[0]}`);
|
|
209
|
+
}
|
|
210
|
+
resolve({
|
|
211
|
+
success: false,
|
|
212
|
+
bindings: {},
|
|
213
|
+
error: this.translateError(this.errorBuffer),
|
|
214
|
+
});
|
|
215
|
+
return;
|
|
222
216
|
}
|
|
223
|
-
if (
|
|
224
|
-
|
|
217
|
+
if (this.outputBuffer.includes("true.") ||
|
|
218
|
+
this.outputBuffer.match(/^[A-Z_][A-Za-z0-9_]*\s*=\s*.+\./m) ||
|
|
219
|
+
this.outputBuffer.match(/\]\s*$/m)) {
|
|
220
|
+
clearTimeout(timeoutId);
|
|
221
|
+
const result = {
|
|
222
|
+
success: true,
|
|
223
|
+
bindings: this.extractBindings(this.outputBuffer),
|
|
224
|
+
};
|
|
225
|
+
if (cacheable) {
|
|
226
|
+
this.cache.set(goalKey, result);
|
|
227
|
+
}
|
|
228
|
+
if (debug) {
|
|
229
|
+
console.error(`[prolog debug] query success: ${normalizedGoal} elapsed=${(Date.now() - start) / 1000}s`);
|
|
230
|
+
}
|
|
231
|
+
resolve(result);
|
|
232
|
+
return;
|
|
225
233
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
234
|
+
if (this.outputBuffer.includes("false.") ||
|
|
235
|
+
this.outputBuffer.includes("fail.")) {
|
|
236
|
+
clearTimeout(timeoutId);
|
|
237
|
+
if (debug) {
|
|
238
|
+
console.error(`[prolog debug] query failed (false): ${normalizedGoal}`);
|
|
239
|
+
}
|
|
240
|
+
resolve({
|
|
241
|
+
success: false,
|
|
242
|
+
bindings: {},
|
|
243
|
+
error: "Query failed",
|
|
244
|
+
});
|
|
245
|
+
return;
|
|
230
246
|
}
|
|
231
|
-
}
|
|
232
|
-
else if (this.outputBuffer.includes("false.") ||
|
|
233
|
-
this.outputBuffer.includes("fail.")) {
|
|
234
|
-
clearTimeout(timeoutId);
|
|
235
|
-
if (debug && normalizedGoal)
|
|
236
|
-
console.error(`[prolog debug] query failed (false): ${normalizedGoal}`);
|
|
237
|
-
resolve({
|
|
238
|
-
success: false,
|
|
239
|
-
bindings: {},
|
|
240
|
-
error: "Query failed",
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
247
|
setTimeout(checkResult, 50);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
+
};
|
|
249
|
+
checkResult();
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
const previousQuery = this.interactiveQueryTail;
|
|
253
|
+
let releaseQuery;
|
|
254
|
+
this.interactiveQueryTail = new Promise((resolve) => {
|
|
255
|
+
releaseQuery = resolve;
|
|
248
256
|
});
|
|
257
|
+
await previousQuery;
|
|
258
|
+
try {
|
|
259
|
+
return await runInteractiveQuery();
|
|
260
|
+
}
|
|
261
|
+
finally {
|
|
262
|
+
releaseQuery();
|
|
263
|
+
}
|
|
249
264
|
}
|
|
250
265
|
invalidateCache() {
|
|
251
266
|
this.cache.clear();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kibi-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Kibi CLI for knowledge base management",
|
|
6
6
|
"engines": {
|
|
@@ -11,7 +11,13 @@
|
|
|
11
11
|
"bin": {
|
|
12
12
|
"kibi": "bin/kibi"
|
|
13
13
|
},
|
|
14
|
-
"files": [
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"bin",
|
|
17
|
+
"schema",
|
|
18
|
+
"src/schemas",
|
|
19
|
+
"src/public"
|
|
20
|
+
],
|
|
15
21
|
"scripts": {
|
|
16
22
|
"build": "tsc -p tsconfig.json",
|
|
17
23
|
"prepack": "npm run build"
|
|
@@ -58,7 +64,7 @@
|
|
|
58
64
|
"fast-glob": "^3.2.12",
|
|
59
65
|
"gray-matter": "^4.0.3",
|
|
60
66
|
"js-yaml": "^4.1.0",
|
|
61
|
-
"kibi-core": "^0.1.
|
|
67
|
+
"kibi-core": "^0.1.7",
|
|
62
68
|
"ts-morph": "^23.0.0"
|
|
63
69
|
},
|
|
64
70
|
"license": "AGPL-3.0-or-later",
|