@visual-z/xeno 0.8.4 → 0.9.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/CHANGELOG.md +19 -0
- package/README.md +31 -746
- package/bin/xeno.exe +26 -0
- package/install.cjs +88 -0
- package/package.json +18 -48
- package/docs/app-server.md +0 -115
- package/docs/foundations.md +0 -88
- package/docs/install.md +0 -244
- package/docs/providers.md +0 -172
- package/docs/research/foundation-clients-2026-10-09.md +0 -27
- package/docs/research/foundation-editing-2026-10-09.md +0 -56
- package/docs/research/foundation-network-2026-10-09.md +0 -37
- package/docs/research/foundation-workflow-2026-10-09.md +0 -37
- package/src/apps/acp-server.ts +0 -41
- package/src/apps/agent-profiles.ts +0 -19
- package/src/apps/app-server.ts +0 -30
- package/src/apps/approve.ts +0 -49
- package/src/apps/cli.ts +0 -99
- package/src/apps/commands.ts +0 -319
- package/src/apps/completions.ts +0 -87
- package/src/apps/control-transport.ts +0 -90
- package/src/apps/export-cli.ts +0 -24
- package/src/apps/goal-flow.ts +0 -70
- package/src/apps/image-draft.ts +0 -46
- package/src/apps/input.ts +0 -312
- package/src/apps/model-catalog.ts +0 -69
- package/src/apps/preferences.ts +0 -20
- package/src/apps/project-trust.ts +0 -9
- package/src/apps/provider-connect.ts +0 -346
- package/src/apps/question-ui.ts +0 -27
- package/src/apps/render.ts +0 -181
- package/src/apps/resources.ts +0 -66
- package/src/apps/review.ts +0 -109
- package/src/apps/session-hub.ts +0 -96
- package/src/apps/session-lifecycle.ts +0 -64
- package/src/apps/shell.ts +0 -2071
- package/src/apps/startup-input.ts +0 -135
- package/src/apps/startup.ts +0 -1677
- package/src/apps/ui/app.ts +0 -1818
- package/src/apps/ui/control-model.ts +0 -43
- package/src/apps/ui/extension-host.ts +0 -194
- package/src/apps/ui/image-cache.ts +0 -121
- package/src/apps/ui/palette.ts +0 -88
- package/src/apps/ui/project.ts +0 -127
- package/src/apps/ui/standalone.ts +0 -148
- package/src/apps/ui/status-model.ts +0 -68
- package/src/apps/ui/surface.ts +0 -91
- package/src/apps/ui/theme.ts +0 -86
- package/src/apps/update-check.ts +0 -112
- package/src/apps/workflow.ts +0 -58
- package/src/core/acceptance.ts +0 -139
- package/src/core/action-defaults.ts +0 -58
- package/src/core/activity-status.ts +0 -52
- package/src/core/agent-profile.ts +0 -130
- package/src/core/attachment-input.ts +0 -17
- package/src/core/blind-checks.ts +0 -72
- package/src/core/boundary.ts +0 -174
- package/src/core/branch-receipt.ts +0 -26
- package/src/core/catalog-merge.ts +0 -19
- package/src/core/checkpoints.ts +0 -85
- package/src/core/churn.ts +0 -61
- package/src/core/command-artifacts.ts +0 -94
- package/src/core/command-contract.ts +0 -151
- package/src/core/completion-action.ts +0 -20
- package/src/core/completion-review.ts +0 -98
- package/src/core/context-detail.ts +0 -37
- package/src/core/context-policy.ts +0 -133
- package/src/core/context-window.ts +0 -54
- package/src/core/continuation.ts +0 -130
- package/src/core/control-protocol.ts +0 -69
- package/src/core/control-view.ts +0 -39
- package/src/core/cycle.ts +0 -17
- package/src/core/data-query.ts +0 -201
- package/src/core/deadline.ts +0 -40
- package/src/core/derive.ts +0 -516
- package/src/core/draft-images.ts +0 -56
- package/src/core/edit-plan.ts +0 -200
- package/src/core/environment.ts +0 -181
- package/src/core/event-validation.ts +0 -220
- package/src/core/events.ts +0 -670
- package/src/core/evidence-ladder.ts +0 -62
- package/src/core/evidence-links.ts +0 -68
- package/src/core/evidence.ts +0 -240
- package/src/core/execution.ts +0 -18
- package/src/core/exhaustive.ts +0 -18
- package/src/core/export.ts +0 -179
- package/src/core/extension-flags.ts +0 -14
- package/src/core/external-effects.ts +0 -488
- package/src/core/failure-recovery.ts +0 -173
- package/src/core/file-precondition.ts +0 -78
- package/src/core/file-references.ts +0 -35
- package/src/core/frontmatter.ts +0 -213
- package/src/core/git-status.ts +0 -29
- package/src/core/goal-view.ts +0 -64
- package/src/core/goal.ts +0 -200
- package/src/core/handoff.ts +0 -479
- package/src/core/history-query.ts +0 -139
- package/src/core/history.ts +0 -237
- package/src/core/image-limits.ts +0 -72
- package/src/core/images.ts +0 -46
- package/src/core/integration-health.ts +0 -34
- package/src/core/json-event.ts +0 -131
- package/src/core/json-pointer.ts +0 -46
- package/src/core/keymap.ts +0 -153
- package/src/core/lsp-framing.ts +0 -34
- package/src/core/mcp-config.ts +0 -68
- package/src/core/model-picker.ts +0 -64
- package/src/core/model-preferences.ts +0 -28
- package/src/core/model-replay.ts +0 -22
- package/src/core/model-scope.ts +0 -53
- package/src/core/note-guidance.ts +0 -34
- package/src/core/oauth-fields.ts +0 -44
- package/src/core/observation-view.ts +0 -152
- package/src/core/outcome.ts +0 -44
- package/src/core/overflow.ts +0 -59
- package/src/core/packages.ts +0 -47
- package/src/core/patch.ts +0 -130
- package/src/core/path-suggestions.ts +0 -59
- package/src/core/permissions.ts +0 -410
- package/src/core/process-receipt.ts +0 -105
- package/src/core/process-state.ts +0 -37
- package/src/core/program-status.ts +0 -40
- package/src/core/progress.ts +0 -150
- package/src/core/project.ts +0 -431
- package/src/core/prompt-policy.ts +0 -46
- package/src/core/prompts.ts +0 -111
- package/src/core/question.ts +0 -94
- package/src/core/queue.ts +0 -78
- package/src/core/read-bounds.ts +0 -24
- package/src/core/read-observation.ts +0 -106
- package/src/core/recovery-sources.ts +0 -74
- package/src/core/regex-dialect.ts +0 -25
- package/src/core/request-budget.ts +0 -23
- package/src/core/request-progress.ts +0 -87
- package/src/core/request-state.ts +0 -273
- package/src/core/resource-selection.ts +0 -36
- package/src/core/response-recovery.ts +0 -59
- package/src/core/resume.ts +0 -59
- package/src/core/review.ts +0 -68
- package/src/core/ripgrep-release.ts +0 -64
- package/src/core/runtime-target.ts +0 -94
- package/src/core/scheduling.ts +0 -8
- package/src/core/search-observation.ts +0 -97
- package/src/core/secrets.ts +0 -188
- package/src/core/session-archive.ts +0 -4
- package/src/core/session-browser.ts +0 -82
- package/src/core/session-entry.ts +0 -61
- package/src/core/session-exit.ts +0 -42
- package/src/core/session-format.ts +0 -169
- package/src/core/session-position.ts +0 -26
- package/src/core/session-tree.ts +0 -147
- package/src/core/settings.ts +0 -192
- package/src/core/skills.ts +0 -165
- package/src/core/sql-query.ts +0 -211
- package/src/core/stall.ts +0 -128
- package/src/core/stop-report.ts +0 -68
- package/src/core/text-normalize.ts +0 -81
- package/src/core/theme.ts +0 -166
- package/src/core/thinking.ts +0 -26
- package/src/core/tokens.ts +0 -151
- package/src/core/tool-contract.ts +0 -153
- package/src/core/tool-discovery.ts +0 -87
- package/src/core/tool-failure.ts +0 -81
- package/src/core/tool-input.ts +0 -44
- package/src/core/transcript.ts +0 -108
- package/src/core/tui-mode.ts +0 -29
- package/src/core/update-check.ts +0 -157
- package/src/core/version.ts +0 -55
- package/src/core/web-content.ts +0 -80
- package/src/core/work-state.ts +0 -154
- package/src/core/workflow-mode.ts +0 -34
- package/src/core/working-set.ts +0 -119
- package/src/core/yaml.ts +0 -282
- package/src/runtime/acp-agent.ts +0 -289
- package/src/runtime/agent-profiles.ts +0 -21
- package/src/runtime/auth.ts +0 -367
- package/src/runtime/blind-check.ts +0 -36
- package/src/runtime/branch-jobs.ts +0 -36
- package/src/runtime/catalog.ts +0 -285
- package/src/runtime/clipboard.ts +0 -125
- package/src/runtime/command-artifacts.ts +0 -64
- package/src/runtime/connection-reuse.ts +0 -40
- package/src/runtime/control-client.ts +0 -149
- package/src/runtime/control-connection.ts +0 -139
- package/src/runtime/counter-check.ts +0 -74
- package/src/runtime/environment-tools.ts +0 -60
- package/src/runtime/evidence-notes.ts +0 -35
- package/src/runtime/exec-sessions.ts +0 -456
- package/src/runtime/execution-control.ts +0 -40
- package/src/runtime/extension-loader.ts +0 -37
- package/src/runtime/extension-ui.ts +0 -47
- package/src/runtime/extensions.ts +0 -370
- package/src/runtime/formatter-tool.ts +0 -38
- package/src/runtime/formatter.ts +0 -50
- package/src/runtime/foundation.ts +0 -116
- package/src/runtime/history-cache.ts +0 -57
- package/src/runtime/history-tools.ts +0 -168
- package/src/runtime/images.ts +0 -80
- package/src/runtime/integrations.ts +0 -216
- package/src/runtime/loop.ts +0 -3108
- package/src/runtime/lsp-client.ts +0 -201
- package/src/runtime/mcp-client.ts +0 -264
- package/src/runtime/mcp-oauth.ts +0 -168
- package/src/runtime/mcp-schema.ts +0 -51
- package/src/runtime/model-config.ts +0 -232
- package/src/runtime/model-data.LICENSE +0 -27
- package/src/runtime/model-data.ts +0 -21
- package/src/runtime/model-discovery.ts +0 -208
- package/src/runtime/model-replay.ts +0 -10
- package/src/runtime/model-scope.ts +0 -20
- package/src/runtime/model-sources.ts +0 -151
- package/src/runtime/model.ts +0 -686
- package/src/runtime/models-fetch.ts +0 -57
- package/src/runtime/oauth-device.ts +0 -86
- package/src/runtime/oauth.ts +0 -853
- package/src/runtime/open-image.ts +0 -42
- package/src/runtime/openai-responses.ts +0 -304
- package/src/runtime/openai.ts +0 -697
- package/src/runtime/output-schema.ts +0 -26
- package/src/runtime/package-manager.ts +0 -125
- package/src/runtime/patch-tool.ts +0 -38
- package/src/runtime/permission-resources.ts +0 -18
- package/src/runtime/pi-provider.ts +0 -423
- package/src/runtime/program-status.ts +0 -38
- package/src/runtime/progress.ts +0 -26
- package/src/runtime/provider-access.ts +0 -21
- package/src/runtime/provider-connect.ts +0 -109
- package/src/runtime/provider-presets.ts +0 -98
- package/src/runtime/provider-protocols.ts +0 -29
- package/src/runtime/provider-request.ts +0 -87
- package/src/runtime/provider-tool-policy.ts +0 -33
- package/src/runtime/provider.ts +0 -580
- package/src/runtime/question-tool.ts +0 -62
- package/src/runtime/retry.ts +0 -447
- package/src/runtime/review-tool.ts +0 -48
- package/src/runtime/rich-text.ts +0 -36
- package/src/runtime/runtime-target.ts +0 -149
- package/src/runtime/secrets.ts +0 -79
- package/src/runtime/self-update.ts +0 -74
- package/src/runtime/session-control.ts +0 -265
- package/src/runtime/session-hub.ts +0 -85
- package/src/runtime/stream-idle.ts +0 -80
- package/src/runtime/tool-broker.ts +0 -137
- package/src/runtime/tool-discovery.ts +0 -58
- package/src/runtime/tool-queue.ts +0 -77
- package/src/runtime/tools.ts +0 -1820
- package/src/runtime/turn-effects.ts +0 -31
- package/src/runtime/update-check.ts +0 -48
- package/src/runtime/usage.ts +0 -253
- package/src/runtime/version.ts +0 -12
- package/src/runtime/web-http.ts +0 -56
- package/src/runtime/web-tools.ts +0 -88
- package/src/runtime/working-notes.ts +0 -60
- package/src/runtime/workspace-lifecycle.ts +0 -141
- package/src/store/acceptance.ts +0 -15
- package/src/store/agent-profile-files.ts +0 -13
- package/src/store/atomic.ts +0 -31
- package/src/store/auth-store.ts +0 -50
- package/src/store/blind-checks.ts +0 -32
- package/src/store/blobs.ts +0 -143
- package/src/store/checkpoint-history.ts +0 -32
- package/src/store/command-artifacts.ts +0 -96
- package/src/store/command.ts +0 -111
- package/src/store/config.ts +0 -69
- package/src/store/context-files.ts +0 -436
- package/src/store/file-checkpoints.ts +0 -108
- package/src/store/file-index.ts +0 -174
- package/src/store/foundation-config.ts +0 -24
- package/src/store/git-checkpoints.ts +0 -67
- package/src/store/git-status.ts +0 -15
- package/src/store/history-search.ts +0 -19
- package/src/store/log.ts +0 -725
- package/src/store/lsp-document.ts +0 -30
- package/src/store/mcp-credentials.ts +0 -85
- package/src/store/models.ts +0 -60
- package/src/store/observations.ts +0 -224
- package/src/store/packages.ts +0 -98
- package/src/store/patch.ts +0 -92
- package/src/store/permission-paths.ts +0 -34
- package/src/store/process-receipts.ts +0 -34
- package/src/store/query-source.ts +0 -49
- package/src/store/recovery.ts +0 -44
- package/src/store/replay.ts +0 -76
- package/src/store/resource-index.ts +0 -170
- package/src/store/resources.ts +0 -285
- package/src/store/restore.ts +0 -110
- package/src/store/review.ts +0 -109
- package/src/store/runtime-target.ts +0 -64
- package/src/store/search.ts +0 -728
- package/src/store/secrets.ts +0 -44
- package/src/store/serial.ts +0 -13
- package/src/store/session-archive.ts +0 -165
- package/src/store/session-browser.ts +0 -68
- package/src/store/session-position.ts +0 -27
- package/src/store/sessions.ts +0 -525
- package/src/store/source-cancellation.ts +0 -6
- package/src/store/tool-binaries.ts +0 -90
- package/src/store/trust.ts +0 -82
- package/src/store/update-cache.ts +0 -36
- package/src/store/user-settings.ts +0 -30
- package/src/store/workspace-clone.ts +0 -42
- package/src/store/workspace-observation.ts +0 -113
- package/src/store/workspace.ts +0 -115
- package/src/store/worktree.ts +0 -278
- package/src/tui/ansi-spans.ts +0 -126
- package/src/tui/diff.ts +0 -160
- package/src/tui/exhaustive.ts +0 -14
- package/src/tui/fuzzy.ts +0 -75
- package/src/tui/style.ts +0 -208
- package/src/tui/ui/atomic-draft.ts +0 -121
- package/src/tui/ui/branch-panel.ts +0 -47
- package/src/tui/ui/canvas.ts +0 -96
- package/src/tui/ui/colors.ts +0 -70
- package/src/tui/ui/composer.ts +0 -199
- package/src/tui/ui/control-panel.ts +0 -25
- package/src/tui/ui/control-sidebar.ts +0 -49
- package/src/tui/ui/dialog.ts +0 -398
- package/src/tui/ui/draft.ts +0 -23
- package/src/tui/ui/duration.ts +0 -16
- package/src/tui/ui/edge.ts +0 -186
- package/src/tui/ui/image-size.ts +0 -44
- package/src/tui/ui/ink.ts +0 -210
- package/src/tui/ui/items.ts +0 -42
- package/src/tui/ui/keys.ts +0 -40
- package/src/tui/ui/layout.ts +0 -74
- package/src/tui/ui/list-model.ts +0 -86
- package/src/tui/ui/list-view.ts +0 -172
- package/src/tui/ui/mascot.ts +0 -67
- package/src/tui/ui/messages.ts +0 -518
- package/src/tui/ui/motion.ts +0 -28
- package/src/tui/ui/paths.ts +0 -10
- package/src/tui/ui/pictures.ts +0 -108
- package/src/tui/ui/prompt-history.ts +0 -60
- package/src/tui/ui/screen.ts +0 -579
- package/src/tui/ui/status.ts +0 -403
- package/src/tui/ui/styled.ts +0 -85
- package/src/tui/ui/tool-card.ts +0 -150
- package/src/tui/width.ts +0 -567
- package/src/vendor/pi-rich/LICENSE.upstream +0 -21
- package/src/vendor/pi-rich/UPSTREAM.json +0 -17
- package/src/vendor/pi-rich/clipboard-command.ts +0 -44
- package/src/vendor/pi-rich/exif-orientation.ts +0 -182
- package/src/vendor/pi-rich/html.ts +0 -51
- package/src/vendor/pi-rich/image-convert.ts +0 -49
- package/src/vendor/pi-rich/image-resize-core.ts +0 -164
- package/src/vendor/pi-rich/image-resize-worker.ts +0 -42
- package/src/vendor/pi-rich/image-resize.ts +0 -123
- package/src/vendor/pi-rich/mime.ts +0 -116
- package/src/vendor/pi-rich/photon.ts +0 -139
- package/src/vendor/pi-rich/syntax-highlight.ts +0 -214
package/src/core/data-query.ts
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
/** N.3: a finite read-only query algebra; no model-generated code is evaluated. */
|
|
2
|
-
import { isRecord } from "./event-validation.ts";
|
|
3
|
-
import { canonicalValue } from "./continuation.ts";
|
|
4
|
-
import { assertNever } from "./exhaustive.ts";
|
|
5
|
-
import { resolveJsonPointer, validateJsonPointer } from "./json-pointer.ts";
|
|
6
|
-
|
|
7
|
-
export type DataRow = Record<string, unknown>;
|
|
8
|
-
export type DataFormat = "csv" | "json" | "jsonl" | "lines";
|
|
9
|
-
type Predicate = { field: string; op: "eq" | "ne" | "contains" | "gt" | "gte" | "lt" | "lte"; value: unknown };
|
|
10
|
-
type Aggregate = { op: "count" | "sum" | "avg" | "min" | "max"; field?: string; as: string };
|
|
11
|
-
export interface DataQuery {
|
|
12
|
-
format: DataFormat;
|
|
13
|
-
pointer?: string;
|
|
14
|
-
where?: readonly Predicate[];
|
|
15
|
-
select?: readonly string[];
|
|
16
|
-
group_by?: readonly string[];
|
|
17
|
-
aggregate?: readonly Aggregate[];
|
|
18
|
-
order_by?: readonly { field: string; descending?: boolean }[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Resource bounds, not partial-result caps. Assumed for the synchronous parser;
|
|
22
|
-
// exceeding one rejects the query and asks for a smaller input, never reports totals.
|
|
23
|
-
export const MAX_QUERY_RECORDS = 250_000;
|
|
24
|
-
|
|
25
|
-
function fields(value: unknown, name: string): string[] | undefined {
|
|
26
|
-
if (value === undefined) return undefined;
|
|
27
|
-
if (!Array.isArray(value) || value.length > 64 || value.some((v) => typeof v !== "string" || !v) || new Set(value).size !== value.length) throw new Error(`invalid ${name}`);
|
|
28
|
-
return value as string[];
|
|
29
|
-
}
|
|
30
|
-
export function parseDataQuery(input: unknown): DataQuery {
|
|
31
|
-
if (!isRecord(input) || !["csv", "json", "jsonl", "lines"].includes(String(input["format"]))) throw new Error("query format must be csv, json, jsonl, or lines");
|
|
32
|
-
const out: DataQuery = { format: input["format"] as DataFormat };
|
|
33
|
-
for (const name of ["select", "group_by"] as const) {
|
|
34
|
-
const list = fields(input[name], name); if (list !== undefined) out[name] = list;
|
|
35
|
-
}
|
|
36
|
-
if (input["pointer"] !== undefined) {
|
|
37
|
-
if (typeof input["pointer"] !== "string") throw new Error("pointer must be a JSON pointer");
|
|
38
|
-
validateJsonPointer(input["pointer"]);
|
|
39
|
-
out.pointer = input["pointer"];
|
|
40
|
-
}
|
|
41
|
-
if (input["where"] !== undefined) {
|
|
42
|
-
if (!Array.isArray(input["where"]) || input["where"].length > 64) throw new Error("invalid where");
|
|
43
|
-
out.where = input["where"].map((value: unknown) => {
|
|
44
|
-
if (!isRecord(value) || typeof value["field"] !== "string" || !["eq", "ne", "contains", "gt", "gte", "lt", "lte"].includes(String(value["op"])) || !("value" in value)) throw new Error("invalid predicate");
|
|
45
|
-
return value as Predicate;
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
if (input["aggregate"] !== undefined) {
|
|
49
|
-
if (!Array.isArray(input["aggregate"]) || input["aggregate"].length > 64) throw new Error("invalid aggregate");
|
|
50
|
-
out.aggregate = input["aggregate"].map((value: unknown) => {
|
|
51
|
-
if (!isRecord(value) || !["count", "sum", "avg", "min", "max"].includes(String(value["op"])) ||
|
|
52
|
-
typeof value["as"] !== "string" || !value["as"] || (value["field"] !== undefined && typeof value["field"] !== "string") ||
|
|
53
|
-
(value["op"] !== "count" && !value["field"])) throw new Error("invalid aggregate; numeric operations need field, all operations need as");
|
|
54
|
-
return value as Aggregate;
|
|
55
|
-
});
|
|
56
|
-
const names = [...(out.group_by ?? []), ...out.aggregate.map((a) => a.as)];
|
|
57
|
-
if (new Set(names).size !== names.length) throw new Error("duplicate result column");
|
|
58
|
-
}
|
|
59
|
-
if (input["order_by"] !== undefined) {
|
|
60
|
-
if (!Array.isArray(input["order_by"]) || input["order_by"].length > 64) throw new Error("invalid order_by");
|
|
61
|
-
out.order_by = input["order_by"].map((value: unknown) => {
|
|
62
|
-
if (!isRecord(value) || typeof value["field"] !== "string" || (value["descending"] !== undefined && typeof value["descending"] !== "boolean")) throw new Error("invalid order_by field");
|
|
63
|
-
return value as { field: string; descending?: boolean };
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
if (out.group_by?.length && !out.aggregate?.length) throw new Error("group_by requires aggregate");
|
|
67
|
-
return out;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** CSV records, including quoted commas/newlines and doubled quotes (RFC 4180). */
|
|
71
|
-
export function csvRecords(text: string): string[][] {
|
|
72
|
-
const records: string[][] = [];
|
|
73
|
-
let row: string[] = [], cell = "", quoted = false, closed = false;
|
|
74
|
-
const push = () => {
|
|
75
|
-
row.push(cell); cell = ""; closed = false;
|
|
76
|
-
records.push(row);
|
|
77
|
-
row = [];
|
|
78
|
-
if (records.length > MAX_QUERY_RECORDS + 1) throw new Error("query record resource limit exceeded");
|
|
79
|
-
};
|
|
80
|
-
for (let i = text.charCodeAt(0) === 0xfeff ? 1 : 0; i < text.length; i++) {
|
|
81
|
-
const c = text[i]!;
|
|
82
|
-
if (quoted) {
|
|
83
|
-
if (c === '"') {
|
|
84
|
-
if (text[i + 1] === '"') { cell += '"'; i++; }
|
|
85
|
-
else { quoted = false; closed = true; }
|
|
86
|
-
} else cell += c;
|
|
87
|
-
} else if (c === ",") { row.push(cell); cell = ""; closed = false; }
|
|
88
|
-
else if (c === "\n" || c === "\r") { push(); if (c === "\r" && text[i + 1] === "\n") i++; }
|
|
89
|
-
else if (c === '"' && cell === "" && !closed) quoted = true;
|
|
90
|
-
else {
|
|
91
|
-
if (closed || c === '"') throw new Error("malformed CSV quoting");
|
|
92
|
-
cell += c;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (quoted) throw new Error("unterminated CSV quote");
|
|
96
|
-
if (cell !== "" || row.length > 0 || closed) push();
|
|
97
|
-
return records;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const rowOf = (value: unknown): DataRow => isRecord(value) ? value : { value };
|
|
101
|
-
function parseRows(text: string, query: DataQuery): DataRow[] {
|
|
102
|
-
if (query.format === "csv") {
|
|
103
|
-
const [header, ...records] = csvRecords(text);
|
|
104
|
-
if (!header) return [];
|
|
105
|
-
if (header.some((key) => key.length === 0) || new Set(header).size !== header.length) throw new Error("CSV headers must be nonempty and unique");
|
|
106
|
-
return records.map((row, i) => {
|
|
107
|
-
if (row.length !== header.length) throw new Error(`CSV record ${i + 2} has ${row.length} fields, expected ${header.length}`);
|
|
108
|
-
return Object.fromEntries(header.map((key, col) => [key, row[col]]));
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (query.format === "json") {
|
|
112
|
-
const value = resolveJsonPointer(JSON.parse(text.replace(/^\uFEFF/, "")), query.pointer ?? "");
|
|
113
|
-
const rows = Array.isArray(value) ? value : [value];
|
|
114
|
-
if (rows.length > MAX_QUERY_RECORDS) throw new Error("query record resource limit exceeded");
|
|
115
|
-
return rows.map(rowOf);
|
|
116
|
-
}
|
|
117
|
-
const lines = text.replace(/^\uFEFF/, "").split(/\r?\n/);
|
|
118
|
-
if (lines.at(-1) === "") lines.pop();
|
|
119
|
-
if (lines.length > MAX_QUERY_RECORDS) throw new Error("query record resource limit exceeded");
|
|
120
|
-
return query.format === "jsonl" ? lines.filter((line) => line.trim() !== "").map((line) => rowOf(JSON.parse(line))) : lines.map((line, i) => ({ line: i + 1, text: line }));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function field(row: DataRow, key: string): unknown {
|
|
124
|
-
if (Object.hasOwn(row, key)) return row[key];
|
|
125
|
-
let value: unknown = row;
|
|
126
|
-
for (const part of key.split(".")) {
|
|
127
|
-
if (value === null || typeof value !== "object" || !Object.hasOwn(value, part)) return null;
|
|
128
|
-
value = (value as DataRow)[part];
|
|
129
|
-
}
|
|
130
|
-
return value ?? null;
|
|
131
|
-
}
|
|
132
|
-
function compare(a: unknown, b: unknown): number {
|
|
133
|
-
if (a === b) return 0;
|
|
134
|
-
if (a === null || a === undefined) return -1;
|
|
135
|
-
if (b === null || b === undefined) return 1;
|
|
136
|
-
if (typeof a === "number" && typeof b === "number") return a - b;
|
|
137
|
-
const left = String(a), right = String(b);
|
|
138
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
139
|
-
}
|
|
140
|
-
function matches(row: DataRow, predicate: Predicate): boolean {
|
|
141
|
-
const raw = field(row, predicate.field), expected = predicate.value;
|
|
142
|
-
const value = typeof expected === "number" && typeof raw === "string" && raw.trim() !== "" ? Number(raw) : raw;
|
|
143
|
-
if (typeof value === "number" && !Number.isFinite(value)) return false;
|
|
144
|
-
switch (predicate.op) {
|
|
145
|
-
case "eq": return canonicalValue(value) === canonicalValue(expected);
|
|
146
|
-
case "ne": return canonicalValue(value) !== canonicalValue(expected);
|
|
147
|
-
case "contains": return String(value ?? "").includes(String(expected));
|
|
148
|
-
case "gt": return value !== null && compare(value, expected) > 0;
|
|
149
|
-
case "gte": return value !== null && compare(value, expected) >= 0;
|
|
150
|
-
case "lt": return value !== null && compare(value, expected) < 0;
|
|
151
|
-
case "lte": return value !== null && compare(value, expected) <= 0;
|
|
152
|
-
default: return assertNever(predicate.op, "query predicate");
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
function aggregate(rows: readonly DataRow[], spec: Aggregate): number | null {
|
|
156
|
-
const values = spec.field === undefined ? rows : rows.map((row) => field(row, spec.field!)).filter((value) => value !== null && value !== undefined && value !== "");
|
|
157
|
-
if (spec.op === "count") return values.length;
|
|
158
|
-
const numbers = values.map((value) => typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? Number(value) : NaN);
|
|
159
|
-
if (numbers.some((n) => !Number.isFinite(n))) throw new Error(`non-numeric value in ${spec.field}`);
|
|
160
|
-
if (numbers.length === 0) return spec.op === "sum" ? 0 : null;
|
|
161
|
-
let result: number;
|
|
162
|
-
switch (spec.op) {
|
|
163
|
-
case "sum": result = numbers.reduce((a, b) => a + b, 0); break;
|
|
164
|
-
case "avg": result = numbers.reduce((a, b) => a + b, 0) / numbers.length; break;
|
|
165
|
-
case "min": result = numbers.reduce((a, b) => Math.min(a, b)); break;
|
|
166
|
-
case "max": result = numbers.reduce((a, b) => Math.max(a, b)); break;
|
|
167
|
-
default: return assertNever(spec.op, "query aggregate");
|
|
168
|
-
}
|
|
169
|
-
if (!Number.isFinite(result)) throw new Error("numeric overflow in aggregate");
|
|
170
|
-
return result;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function queryData(text: string, query: DataQuery): { total: number; matched: number; rows: DataRow[] } {
|
|
174
|
-
const all = parseRows(text, query);
|
|
175
|
-
if (all.length > MAX_QUERY_RECORDS) throw new Error("query record resource limit exceeded");
|
|
176
|
-
const matched = all.filter((row) => (query.where ?? []).every((predicate) => matches(row, predicate)));
|
|
177
|
-
let rows = matched;
|
|
178
|
-
if (query.aggregate?.length) {
|
|
179
|
-
const groups = new Map<string, { keys: unknown[]; rows: DataRow[] }>();
|
|
180
|
-
if (!query.group_by?.length) groups.set("[]", { keys: [], rows: matched });
|
|
181
|
-
else for (const row of matched) {
|
|
182
|
-
const keys = query.group_by.map((key) => field(row, key)), key = canonicalValue(keys);
|
|
183
|
-
let group = groups.get(key);
|
|
184
|
-
if (!group) { group = { keys, rows: [] }; groups.set(key, group); }
|
|
185
|
-
group.rows.push(row);
|
|
186
|
-
}
|
|
187
|
-
rows = [...groups.values()].map((group) => Object.fromEntries([
|
|
188
|
-
...(query.group_by ?? []).map((key, i) => [key, group.keys[i]]),
|
|
189
|
-
...query.aggregate!.map((spec) => [spec.as, aggregate(group.rows, spec)]),
|
|
190
|
-
]));
|
|
191
|
-
}
|
|
192
|
-
if (query.order_by?.length) rows = rows.toSorted((a, b) => {
|
|
193
|
-
for (const order of query.order_by!) {
|
|
194
|
-
const result = compare(field(a, order.field), field(b, order.field));
|
|
195
|
-
if (result !== 0) return order.descending ? -result : result;
|
|
196
|
-
}
|
|
197
|
-
return 0;
|
|
198
|
-
});
|
|
199
|
-
if (query.select) rows = rows.map((row) => Object.fromEntries(query.select!.map((key) => [key, field(row, key)])));
|
|
200
|
-
return { total: all.length, matched: matched.length, rows };
|
|
201
|
-
}
|
package/src/core/deadline.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A wall-clock notice for runs judged against a deadline.
|
|
3
|
-
*
|
|
4
|
-
* An evaluation kills a task at its timeout; a model that does not know the
|
|
5
|
-
* time is often still exploring when it does, and leaves nothing verifiable
|
|
6
|
-
* behind. LangChain's Terminal-Bench harness injects the remaining budget for
|
|
7
|
-
* this reason. Time arrives as arguments: core reads no clock.
|
|
8
|
-
*/
|
|
9
|
-
import type { GuidanceEvent, LogEvent } from "./events.ts";
|
|
10
|
-
import { currentRequestEvents } from "./request-state.ts";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Assumed, not measured: a quarter of the budget leaves room for one
|
|
14
|
-
* fix-test-finish round. Earlier would cut exploration short; later is no
|
|
15
|
-
* warning at all.
|
|
16
|
-
*/
|
|
17
|
-
export const DEADLINE_FRACTION = 0.75;
|
|
18
|
-
|
|
19
|
-
const clock = (ms: number) => {
|
|
20
|
-
const total = Math.max(0, Math.round(ms / 1000));
|
|
21
|
-
const m = Math.floor(total / 60), s = total % 60;
|
|
22
|
-
return m === 0 ? `${s}s` : s === 0 ? `${m}m` : `${m}m ${s}s`;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export function deadlineNotice(
|
|
26
|
-
startedAt: string, now: string, budgetMs: number, events: readonly LogEvent[],
|
|
27
|
-
): Pick<GuidanceEvent, "reason" | "text" | "sources"> | null {
|
|
28
|
-
const start = Date.parse(startedAt), current = Date.parse(now);
|
|
29
|
-
if (!Number.isFinite(start) || !Number.isFinite(current) || !Number.isFinite(budgetMs) || budgetMs <= 0) {
|
|
30
|
-
throw new RangeError("deadline needs valid timestamps and a positive budget");
|
|
31
|
-
}
|
|
32
|
-
const request = currentRequestEvents(events);
|
|
33
|
-
if (request.some((event) => event.t === "guidance" && event.reason === "deadline")) return null;
|
|
34
|
-
const used = current - start;
|
|
35
|
-
if (used < budgetMs * DEADLINE_FRACTION) return null;
|
|
36
|
-
return { reason: "deadline", sources: [], text:
|
|
37
|
-
`Harness: ${clock(used)} of ${clock(budgetMs)} used; ${clock(budgetMs - used)} remain before this run is stopped. ` +
|
|
38
|
-
"Stop exploring. Converge on the most complete result you can verify now: finish the change in progress, run its check, " +
|
|
39
|
-
"and leave the workspace in a working state." };
|
|
40
|
-
}
|