poe-code 5.0.3 → 6.0.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/dist/index.js +1859 -1313
- package/dist/index.js.map +4 -4
- package/dist/metafile.json +1 -1
- package/dist/providers/poe-agent.js +14 -2
- package/dist/providers/poe-agent.js.map +4 -4
- package/package.json +1 -1
- package/packages/safejs/dist/interp/async.js +31 -9
- package/packages/safejs/dist/interp/cancel.d.ts +7 -2
- package/packages/safejs/dist/interp/cancel.js +128 -92
- package/packages/safejs/dist/interp/exceptions.js +7 -3
- package/packages/safejs/dist/interp/globals/collections.js +2 -0
- package/packages/safejs/dist/interp/globals/console-json.js +4 -0
- package/packages/safejs/dist/interp/globals/error.js +1 -5
- package/packages/safejs/dist/interp/globals/math.js +2 -4
- package/packages/safejs/dist/interp/globals/misc.js +5 -0
- package/packages/safejs/dist/interp/globals/object-array.js +25 -0
- package/packages/safejs/dist/interp/globals/regex.js +1 -1
- package/packages/safejs/dist/interp/host-bridge.js +8 -5
- package/packages/safejs/dist/interp/interpreter.js +26 -32
- package/packages/safejs/dist/interp/iteration.d.ts +3 -3
- package/packages/safejs/dist/interp/iteration.js +20 -9
- package/packages/safejs/dist/interp/methods/array.js +1 -0
- package/packages/safejs/dist/interp/methods/function.d.ts +1 -1
- package/packages/safejs/dist/interp/methods/function.js +17 -1
- package/packages/safejs/dist/interp/methods/generator.js +1 -0
- package/packages/safejs/dist/interp/methods/map.js +1 -0
- package/packages/safejs/dist/interp/methods/number.js +1 -0
- package/packages/safejs/dist/interp/methods/regex.js +1 -0
- package/packages/safejs/dist/interp/methods/set.js +1 -0
- package/packages/safejs/dist/interp/methods/string.js +1 -0
- package/packages/safejs/dist/interp/promise-tracker.d.ts +12 -2
- package/packages/safejs/dist/interp/promise-tracker.js +65 -7
- package/packages/safejs/dist/interp/promise.d.ts +7 -5
- package/packages/safejs/dist/interp/promise.js +531 -148
- package/packages/safejs/dist/interp/values.d.ts +6 -0
- package/packages/safejs/dist/interp/values.js +25 -5
- package/packages/safejs/dist/lint/rules/AS001.js +0 -5
- package/packages/safejs/dist/snapshot/dump-format.d.ts +1 -1
- package/packages/safejs/dist/snapshot/dump-format.js +1 -1
- package/packages/safejs/dist/snapshot/replay-data.js +3 -0
- package/packages/toolcraft-design/dist/explorer/detail-content.d.ts +6 -0
- package/packages/toolcraft-design/dist/explorer/detail-content.js +32 -0
- package/packages/toolcraft-design/dist/explorer/layout.d.ts +1 -0
- package/packages/toolcraft-design/dist/explorer/layout.js +8 -0
- package/packages/toolcraft-design/dist/explorer/reducer.js +8 -19
- package/packages/toolcraft-design/dist/explorer/render/detail.d.ts +1 -1
- package/packages/toolcraft-design/dist/explorer/render/detail.js +8 -36
- package/packages/toolcraft-design/dist/explorer/render/pane.d.ts +1 -1
- package/packages/toolcraft-design/dist/explorer/render/pane.js +1 -8
|
@@ -52,6 +52,9 @@ export type SandboxCallContext = {
|
|
|
52
52
|
};
|
|
53
53
|
export type SandboxClosure = {
|
|
54
54
|
readonly async?: true;
|
|
55
|
+
readonly sandbox?: true;
|
|
56
|
+
readonly boundTarget?: SandboxClosure;
|
|
57
|
+
readonly cancellationSignal?: AbortSignal;
|
|
55
58
|
readonly kind: "fn";
|
|
56
59
|
readonly name?: string;
|
|
57
60
|
readonly properties?: SandboxObject;
|
|
@@ -82,6 +85,9 @@ type CopyFromSandboxOptions = {
|
|
|
82
85
|
};
|
|
83
86
|
export declare function createSandboxClosure(input: {
|
|
84
87
|
async?: boolean;
|
|
88
|
+
sandbox?: boolean;
|
|
89
|
+
boundTarget?: SandboxClosure;
|
|
90
|
+
cancellationSignal?: AbortSignal;
|
|
85
91
|
call: (args: readonly SandboxValue[], context?: SandboxCallContext) => SandboxValue | Promise<SandboxValue>;
|
|
86
92
|
construct?: (args: readonly SandboxValue[], context?: SandboxCallContext) => SandboxValue | Promise<SandboxValue>;
|
|
87
93
|
name?: string;
|
|
@@ -2,6 +2,7 @@ import { bindOtelSpan, getBoundOtelSpan } from "../observability/otel.js";
|
|
|
2
2
|
import { SandboxError } from "./budget.js";
|
|
3
3
|
import { observeSandboxPromise, trackSandboxPromise } from "./promise-tracker.js";
|
|
4
4
|
import { promiseReplayContext } from "./promise-replay.js";
|
|
5
|
+
import { invokeCancelableClosure, readPromiseCancellation, registerPromiseCancellation } from "./cancel.js";
|
|
5
6
|
import { parseRegex } from "./regex/parse.js";
|
|
6
7
|
import { assertSandboxDataDepth } from "../graph-depth.js";
|
|
7
8
|
import { copySandboxArgumentProperties, createSandboxArguments, getSandboxArgumentEntries, isSandboxArguments } from "./arguments.js";
|
|
@@ -17,15 +18,30 @@ const sandboxRetainedValues = Symbol("SandboxRetainedValues");
|
|
|
17
18
|
export function createSandboxClosure(input) {
|
|
18
19
|
const closure = {
|
|
19
20
|
kind: "fn",
|
|
20
|
-
call: input.call,
|
|
21
|
+
call: (args, context) => invokeCancelableClosure(closure, input.call, args, context),
|
|
21
22
|
name: input.name,
|
|
22
|
-
...(input.construct === undefined
|
|
23
|
+
...(input.construct === undefined
|
|
24
|
+
? {}
|
|
25
|
+
: {
|
|
26
|
+
construct: (args, context) => invokeCancelableClosure(closure, input.construct, args, context, true)
|
|
27
|
+
}),
|
|
23
28
|
...(input.async === true ? { async: true } : {})
|
|
24
29
|
};
|
|
25
30
|
Object.defineProperty(closure, sandboxClosureBrand, {
|
|
26
31
|
enumerable: false,
|
|
27
32
|
value: true
|
|
28
33
|
});
|
|
34
|
+
if (input.sandbox === true) {
|
|
35
|
+
Object.defineProperty(closure, "sandbox", { value: true });
|
|
36
|
+
}
|
|
37
|
+
if (input.boundTarget !== undefined) {
|
|
38
|
+
Object.defineProperty(closure, "boundTarget", { value: input.boundTarget });
|
|
39
|
+
}
|
|
40
|
+
if (input.cancellationSignal !== undefined) {
|
|
41
|
+
Object.defineProperty(closure, "cancellationSignal", {
|
|
42
|
+
value: input.cancellationSignal
|
|
43
|
+
});
|
|
44
|
+
}
|
|
29
45
|
if (input.properties !== undefined) {
|
|
30
46
|
Object.defineProperty(closure, "properties", {
|
|
31
47
|
enumerable: false,
|
|
@@ -40,11 +56,14 @@ export function createSandboxClosure(input) {
|
|
|
40
56
|
return Object.freeze(closure);
|
|
41
57
|
}
|
|
42
58
|
export function createSandboxPromise(promise, metadata = {}) {
|
|
59
|
+
const original = metadata.trackReplay === false
|
|
60
|
+
? promise
|
|
61
|
+
: (promiseReplayContext.getStore()?.track(promise) ?? promise);
|
|
43
62
|
const sandboxPromise = {
|
|
44
63
|
kind: "promise",
|
|
45
|
-
promise
|
|
46
|
-
|
|
47
|
-
|
|
64
|
+
get promise() {
|
|
65
|
+
return readPromiseCancellation(sandboxPromise, original);
|
|
66
|
+
}
|
|
48
67
|
};
|
|
49
68
|
Object.defineProperty(sandboxPromise, sandboxPromiseBrand, {
|
|
50
69
|
enumerable: false,
|
|
@@ -70,6 +89,7 @@ export function createSandboxPromise(promise, metadata = {}) {
|
|
|
70
89
|
});
|
|
71
90
|
}
|
|
72
91
|
trackSandboxPromise(sandboxPromise);
|
|
92
|
+
registerPromiseCancellation(sandboxPromise);
|
|
73
93
|
return Object.freeze(sandboxPromise);
|
|
74
94
|
}
|
|
75
95
|
export function createSandboxGenerator(channel, metadata = undefined) {
|
|
@@ -220,11 +220,6 @@ class AS001Scanner {
|
|
|
220
220
|
case "with":
|
|
221
221
|
this.report(token.value, token.start, token.end);
|
|
222
222
|
return;
|
|
223
|
-
case "new":
|
|
224
|
-
if (!this.source.slice(this.skipTriviaFrom(token.end.offset)).startsWith("RegExp")) {
|
|
225
|
-
this.report(token.value, token.start, token.end);
|
|
226
|
-
}
|
|
227
|
-
return;
|
|
228
223
|
default:
|
|
229
224
|
return;
|
|
230
225
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const DUMP_FORMAT_VERSION = 1;
|
|
2
|
-
export const EXECUTION_SEMANTICS = "jobs-
|
|
2
|
+
export const EXECUTION_SEMANTICS = "jobs-v2";
|
|
3
3
|
import { assertSnapshotGraphDepth } from "../graph-depth.js";
|
|
4
4
|
import { getSandboxArgumentEntries, isSandboxArguments } from "../interp/arguments.js";
|
|
5
5
|
import { serializeArguments } from "./arguments.js";
|
|
@@ -180,6 +180,9 @@ export function decodeReplayData(input, options = {}) {
|
|
|
180
180
|
}
|
|
181
181
|
return createSandboxClosure({
|
|
182
182
|
...capability,
|
|
183
|
+
boundTarget: capability.boundTarget,
|
|
184
|
+
cancellationSignal: capability.cancellationSignal,
|
|
185
|
+
sandbox: capability.sandbox,
|
|
183
186
|
retainedValues: () => [capability],
|
|
184
187
|
properties: (closure) => {
|
|
185
188
|
restored.set(id, closure);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ansiToCells } from "../screen/ansi-text.js";
|
|
2
|
+
import { renderMarkdown } from "../terminal-markdown/index.js";
|
|
3
|
+
const markdownCache = new Map();
|
|
4
|
+
export function prepareDetailContent(content, width) {
|
|
5
|
+
if (content.trim().length === 0) {
|
|
6
|
+
return { text: "", lines: [[]] };
|
|
7
|
+
}
|
|
8
|
+
width = Math.max(1, width);
|
|
9
|
+
const key = `${contentHash(content)}:${width}`;
|
|
10
|
+
const cached = markdownCache.get(key);
|
|
11
|
+
if (cached !== undefined)
|
|
12
|
+
return cached;
|
|
13
|
+
const text = renderMarkdown(content, { width }).trimEnd();
|
|
14
|
+
const lines = [[]];
|
|
15
|
+
for (const cell of ansiToCells(text)) {
|
|
16
|
+
if (cell.ch === "\n")
|
|
17
|
+
lines.push([]);
|
|
18
|
+
else
|
|
19
|
+
lines.at(-1).push(cell);
|
|
20
|
+
}
|
|
21
|
+
const prepared = { text, lines };
|
|
22
|
+
markdownCache.set(key, prepared);
|
|
23
|
+
return prepared;
|
|
24
|
+
}
|
|
25
|
+
function contentHash(content) {
|
|
26
|
+
let hash = 2166136261;
|
|
27
|
+
for (let index = 0; index < content.length; index += 1) {
|
|
28
|
+
hash ^= content.charCodeAt(index);
|
|
29
|
+
hash = Math.imul(hash, 16777619);
|
|
30
|
+
}
|
|
31
|
+
return hash >>> 0;
|
|
32
|
+
}
|
|
@@ -62,6 +62,14 @@ export function computeExplorerLayout(opts) {
|
|
|
62
62
|
footer
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
+
export function paneBodyRect(rect) {
|
|
66
|
+
return {
|
|
67
|
+
x: rect.x + 2,
|
|
68
|
+
y: rect.y + 1,
|
|
69
|
+
width: Math.max(0, rect.width - 4),
|
|
70
|
+
height: Math.max(0, rect.height - 2)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
65
73
|
function resolveMode(cols, rows) {
|
|
66
74
|
if (cols < 60 || rows < 8) {
|
|
67
75
|
return "too-narrow";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { graphemes } from "../dashboard/terminal-width.js";
|
|
2
2
|
import { buildActionContext, resolveAction } from "./actions.js";
|
|
3
|
+
import { prepareDetailContent } from "./detail-content.js";
|
|
3
4
|
import { filterRows } from "./filter.js";
|
|
5
|
+
import { computeExplorerLayout, paneBodyRect } from "./layout.js";
|
|
4
6
|
import { REGION_ALL, REGION_DETAIL, REGION_FOOTER, REGION_HEADER, REGION_LIST, REGION_MODAL, resolveExplorerLayoutMode } from "./state.js";
|
|
5
7
|
const NO_EFFECTS = [];
|
|
6
8
|
const DEFAULT_ACTION_HANDLES = {
|
|
@@ -640,31 +642,18 @@ function maxDetailScroll(state) {
|
|
|
640
642
|
return 0;
|
|
641
643
|
}
|
|
642
644
|
if (items.length === 1 && items[0]?.title === undefined) {
|
|
643
|
-
const
|
|
644
|
-
|
|
645
|
+
const body = paneBodyRect(computeExplorerLayout({ ...state.size, focused: state.focused }).detail);
|
|
646
|
+
const content = items[0]?.renderedContent;
|
|
647
|
+
if (body.width <= 0 || body.height <= 0 || content === undefined) {
|
|
645
648
|
return 0;
|
|
646
649
|
}
|
|
647
|
-
return Math.max(0,
|
|
650
|
+
return Math.max(0, prepareDetailContent(content, body.width).lines.length - body.height);
|
|
648
651
|
}
|
|
649
652
|
return Math.max(0, items.length - 1);
|
|
650
653
|
}
|
|
651
|
-
function detailContentLineCount(item) {
|
|
652
|
-
return (item.renderedContent ?? "").split("\n").length;
|
|
653
|
-
}
|
|
654
654
|
function detailBodyHeight(state) {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
}
|
|
658
|
-
const rows = normalizeSize(state.size.rows);
|
|
659
|
-
const footerHeight = rows > 0 ? Math.min(1, rows) : 0;
|
|
660
|
-
const headerHeight = Math.min(3, Math.max(0, rows - footerHeight));
|
|
661
|
-
const contentHeight = Math.max(0, rows - headerHeight - footerHeight);
|
|
662
|
-
if (state.layout === "narrow-vertical") {
|
|
663
|
-
const listHeight = Math.ceil(contentHeight / 2);
|
|
664
|
-
const detailHeight = contentHeight - listHeight;
|
|
665
|
-
return Math.max(0, detailHeight - 2);
|
|
666
|
-
}
|
|
667
|
-
return Math.max(0, contentHeight - 2);
|
|
655
|
+
const body = paneBodyRect(computeExplorerLayout({ ...state.size, focused: state.focused }).detail);
|
|
656
|
+
return body.width > 0 ? body.height : 0;
|
|
668
657
|
}
|
|
669
658
|
function extendSelection(state, delta) {
|
|
670
659
|
if (!state.multiSelect) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ScreenSurface as ScreenBuffer } from "../../screen/screen.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type ExplorerLayout } from "../layout.js";
|
|
3
3
|
import type { ExplorerState } from "../state.js";
|
|
4
4
|
export declare function renderDetail(state: ExplorerState, screen: ScreenBuffer, layout: ExplorerLayout): void;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { prepareDetailContent } from "../detail-content.js";
|
|
2
|
+
import { paneBodyRect } from "../layout.js";
|
|
3
3
|
import { getExplorerStyles } from "../theme.js";
|
|
4
|
-
import { drawPaneFrame
|
|
4
|
+
import { drawPaneFrame } from "./pane.js";
|
|
5
5
|
import { fitToWidth } from "./text.js";
|
|
6
|
-
const markdownCache = new Map();
|
|
7
6
|
export function renderDetail(state, screen, layout) {
|
|
8
7
|
const rect = layout.detail;
|
|
9
8
|
const styles = getExplorerStyles();
|
|
@@ -32,7 +31,8 @@ function renderDetailBody(state, screen, rect, row) {
|
|
|
32
31
|
return { start: 0, max: 0 };
|
|
33
32
|
}
|
|
34
33
|
if (items.length === 1 && items[0]?.title === undefined) {
|
|
35
|
-
|
|
34
|
+
const content = prepareDetailContent(renderItem(items[0], rect, row), rect.width);
|
|
35
|
+
return renderBlob(screen, rect, content.lines, state.detail.scroll);
|
|
36
36
|
}
|
|
37
37
|
return renderListMode(state, screen, rect, items, row);
|
|
38
38
|
}
|
|
@@ -54,7 +54,8 @@ function renderListMode(state, screen, rect, items, row) {
|
|
|
54
54
|
writeLine(screen, rect, y, ` ${item.subtitle}`, styles.muted);
|
|
55
55
|
y += 1;
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
const content = prepareDetailContent(renderItem(item, rect, row), rect.width);
|
|
58
|
+
for (const line of content.text.split("\n")) {
|
|
58
59
|
if (y >= rect.height) {
|
|
59
60
|
break;
|
|
60
61
|
}
|
|
@@ -67,14 +68,7 @@ function renderListMode(state, screen, rect, items, row) {
|
|
|
67
68
|
}
|
|
68
69
|
return { start, max };
|
|
69
70
|
}
|
|
70
|
-
function renderBlob(screen, rect,
|
|
71
|
-
const allLines = [[]];
|
|
72
|
-
for (const cell of ansiToCells(text)) {
|
|
73
|
-
if (cell.ch === "\n")
|
|
74
|
-
allLines.push([]);
|
|
75
|
-
else
|
|
76
|
-
allLines.at(-1).push(cell);
|
|
77
|
-
}
|
|
71
|
+
function renderBlob(screen, rect, allLines, scroll) {
|
|
78
72
|
const max = Math.max(0, allLines.length - rect.height);
|
|
79
73
|
const start = clamp(scroll, 0, max);
|
|
80
74
|
const lines = allLines.slice(start);
|
|
@@ -89,20 +83,6 @@ function renderBlob(screen, rect, text, scroll) {
|
|
|
89
83
|
}
|
|
90
84
|
return { start, max };
|
|
91
85
|
}
|
|
92
|
-
function renderItemMarkdown(item, rect, row) {
|
|
93
|
-
const content = renderItem(item, rect, row);
|
|
94
|
-
if (content.trim().length === 0) {
|
|
95
|
-
return "";
|
|
96
|
-
}
|
|
97
|
-
const width = Math.max(1, rect.width);
|
|
98
|
-
const key = `${contentHash(content)}:${width}`;
|
|
99
|
-
const cached = markdownCache.get(key);
|
|
100
|
-
if (cached !== undefined)
|
|
101
|
-
return cached;
|
|
102
|
-
const rendered = renderMarkdown(content, { width }).trimEnd();
|
|
103
|
-
markdownCache.set(key, rendered);
|
|
104
|
-
return rendered;
|
|
105
|
-
}
|
|
106
86
|
function renderItem(item, rect, row) {
|
|
107
87
|
if (item.renderedContent !== undefined) {
|
|
108
88
|
return item.renderedContent;
|
|
@@ -134,11 +114,3 @@ function scrollIndicator(state, start, max) {
|
|
|
134
114
|
return "⠋";
|
|
135
115
|
return `${max === 0 ? 0 : Math.round((start / max) * 100)}%`;
|
|
136
116
|
}
|
|
137
|
-
function contentHash(content) {
|
|
138
|
-
let hash = 2166136261;
|
|
139
|
-
for (let index = 0; index < content.length; index += 1) {
|
|
140
|
-
hash ^= content.charCodeAt(index);
|
|
141
|
-
hash = Math.imul(hash, 16777619);
|
|
142
|
-
}
|
|
143
|
-
return hash >>> 0;
|
|
144
|
-
}
|
|
@@ -23,11 +23,4 @@ export function drawPaneFrame(screen, rect, title, style = {}, options = {}) {
|
|
|
23
23
|
screen.put(rect.x, rect.y + rect.height - 1, `${options.focused ? "┗" : "└"}${horizontal.repeat(innerWidth)}${options.focused ? "┛" : "┘"}`, style);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
export
|
|
27
|
-
return {
|
|
28
|
-
x: rect.x + 2,
|
|
29
|
-
y: rect.y + 1,
|
|
30
|
-
width: Math.max(0, rect.width - 4),
|
|
31
|
-
height: Math.max(0, rect.height - 2)
|
|
32
|
-
};
|
|
33
|
-
}
|
|
26
|
+
export { paneBodyRect } from "../layout.js";
|