@ancha-labs/cli 0.4.16 → 0.4.18
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/THIRD_PARTY_NOTICES.md +3 -1
- package/lib/ancha.mjs +1064 -681
- package/lib/assets/SKILL.md +1 -1
- package/lib/assets/agents-section.md +1 -1
- package/lib/assets/docs/cloud.md +1 -1
- package/lib/assets/docs/datasets.md +2 -2
- package/lib/assets/docs/scenes.md +1 -1
- package/lib/assets/docs/setup.md +2 -2
- package/lib/assets/docs/traces.md +1 -1
- package/lib/assets/harbor/companion.mjs +43 -25
- package/lib/assets/harbor/driver.py +17 -3
- package/lib/assets/ui/app.js +432 -395
- package/lib/assets/ui/style.css +372 -50
- package/lib/mcp-entry.mjs +9 -5
- package/lib/worker.mjs +53 -25
- package/lib/world-server.mjs +43 -25
- package/package.json +1 -1
package/lib/assets/SKILL.md
CHANGED
|
@@ -36,7 +36,7 @@ Add `--json` to every command. Runs print NDJSON events that end with `run_finis
|
|
|
36
36
|
ancha agent upload
|
|
37
37
|
```
|
|
38
38
|
- The install follows the project's own manifests and lockfiles; `agent.install` in `ancha.yaml` sets the command instead.
|
|
39
|
-
5. **Without production traces.** For an agent that uses NetSuite, `ancha init` writes a NetSuite world of a private-equity portfolio company (four subsidiaries, two currencies, thousands of transactions) and 25 tests
|
|
39
|
+
5. **Without production traces.** For an agent that uses NetSuite, `ancha init` writes a NetSuite world of a private-equity portfolio company (four subsidiaries, two currencies, thousands of transactions) and 25 tests: 10 read tasks and 15 write workflows.
|
|
40
40
|
- Your data: `ancha world import netsuite <your exports> --id <id>` reads REST record JSON, SuiteQL results and saved search CSV into `ancha/worlds/<id>.yaml`; check it with `ancha world validate`. To write the seed yourself, `ancha twins seed netsuite` lists its fields.
|
|
41
41
|
- Your evals: `ancha test import <file> --world <id>` (JSONL, JSON, CSV or YAML with a question and an expected answer).
|
|
42
42
|
- One test from a sentence: `ancha test new "<sentence>" --world <id>`.
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
ancha agent upload
|
|
22
22
|
```
|
|
23
23
|
- The install follows the project's own manifests and lockfiles; `agent.install` in `ancha.yaml` sets the command instead.
|
|
24
|
-
5. **Without production traces.** For an agent that uses NetSuite, `ancha init` writes a NetSuite world of a private-equity portfolio company (four subsidiaries, two currencies, thousands of transactions) and 25 tests
|
|
24
|
+
5. **Without production traces.** For an agent that uses NetSuite, `ancha init` writes a NetSuite world of a private-equity portfolio company (four subsidiaries, two currencies, thousands of transactions) and 25 tests: 10 read tasks and 15 write workflows.
|
|
25
25
|
- Your data: `ancha world import netsuite <your exports> --id <id>` reads REST record JSON, SuiteQL results and saved search CSV into `ancha/worlds/<id>.yaml`; check it with `ancha world validate`. To write the seed yourself, `ancha twins seed netsuite` lists its fields.
|
|
26
26
|
- Your evals: `ancha test import <file> --world <id>` (JSONL, JSON, CSV or YAML with a question and an expected answer).
|
|
27
27
|
- One test from a sentence: `ancha test new "<sentence>" --world <id>`.
|
package/lib/assets/docs/cloud.md
CHANGED
|
@@ -29,7 +29,7 @@ Without `--on`, a project with `ancha.yaml` (or `--config`) runs in the workspac
|
|
|
29
29
|
ancha agent upload
|
|
30
30
|
```
|
|
31
31
|
- The install follows the project's own manifests and lockfiles; `agent.install` in `ancha.yaml` sets the command instead.
|
|
32
|
-
5. **Without production traces.** For an agent that uses NetSuite, `ancha init` writes a NetSuite world of a private-equity portfolio company (four subsidiaries, two currencies, thousands of transactions) and 25 tests
|
|
32
|
+
5. **Without production traces.** For an agent that uses NetSuite, `ancha init` writes a NetSuite world of a private-equity portfolio company (four subsidiaries, two currencies, thousands of transactions) and 25 tests: 10 read tasks and 15 write workflows.
|
|
33
33
|
- Your data: `ancha world import netsuite <your exports> --id <id>` reads REST record JSON, SuiteQL results and saved search CSV into `ancha/worlds/<id>.yaml`; check it with `ancha world validate`. To write the seed yourself, `ancha twins seed netsuite` lists its fields.
|
|
34
34
|
- Your evals: `ancha test import <file> --world <id>` (JSONL, JSON, CSV or YAML with a question and an expected answer).
|
|
35
35
|
- One test from a sentence: `ancha test new "<sentence>" --world <id>`.
|
|
@@ -8,7 +8,7 @@ A world file (`ancha/worlds/<id>.yaml`) holds the records your agent's tools sta
|
|
|
8
8
|
ancha world gen --dataset netsuite-pe --size m
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
This writes the books of a private-equity portfolio company, `ancha/worlds/netsuite-pe-m.yaml`, and
|
|
11
|
+
This writes the books of a private-equity portfolio company, `ancha/worlds/netsuite-pe-m.yaml`, and 10 read tasks and 15 write workflows with computed answers and final-state checks, `ancha/evals/netsuite-pe-m.jsonl`. It needs no model and no description: the same size always gives the same files. The company has four subsidiaries, US dollar and euro books, eighteen months of order to cash and procure to pay, and the problems an operator finds at close: duplicate bills, unapplied payments and credits, overdue receivables, three-way-match exceptions, journal entries waiting for approval. Sizes `s`, `m` and `l` hold about 1,500, 11,400 and 22,000 transactions. `ancha sandbox datasets` lists it with the starter datasets.
|
|
12
12
|
|
|
13
13
|
## Your NetSuite exports
|
|
14
14
|
|
|
@@ -54,7 +54,7 @@ Give your coding agent this recipe and an export of your records (a spreadsheet,
|
|
|
54
54
|
|
|
55
55
|
```text
|
|
56
56
|
invalid ancha/worlds/our-books.yaml (our-books)
|
|
57
|
-
netsuite: 4 subsidiaries, 2 currencies,
|
|
57
|
+
netsuite: 4 subsidiaries, 2 currencies, 40 accounts, 400 customers, 180 vendors, 150 items, 11,431 transactions
|
|
58
58
|
seed.netsuite.invoices[212]: INV12213 (id 40213, customer 1297 Jarvis Food Processing Co.): invoice is over-applied: applications total USD 11,641.54 against a total of USD 11,601.54 (over by USD 40.00)
|
|
59
59
|
```
|
|
60
60
|
|
|
@@ -17,7 +17,7 @@ A version 2 test names a world (`ancha/worlds/<id>.yaml`: the company, its peopl
|
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
- The question is `question`, `input`, `prompt`, `query` or `task`; the expected answer is `expected`, `answer`, `ideal`, `output`, `reference` or `expected_output`. Optional: `id`, `read_only` (default true; false for an eval with `records`), `must_call` (`"METHOD /path"` or an MCP tool name), `numbers` (`[{ value, tolerance }]`), `contains`, `judge` (a rubric), `tags`, and `records`: the NetSuite state a write leaves, `[{ type, id or externalId, fields }]`. Other fields go in the test's header as comments.
|
|
20
|
-
- Each eval becomes a test whose task is the question, with an `answer` check: the `numbers` and `contains` it gives, or the numbers, document numbers (`INV-1043`) and quoted text of its expected answer. Numbers the question states and dates are left out. A test also gets `netsuite.unchanged` over every record type when it only reads and the world has NetSuite, a `trace.called` check for each `must_call`, and a `netsuite.record` check for each of its `records`. A record named by `externalId` can be one the agent creates:
|
|
20
|
+
- Each eval becomes a test whose task is the question, with an `answer` check: the `numbers` and `contains` it gives, or the numbers, document numbers (`INV-1043`) and quoted text of its expected answer. Numbers the question states and dates are left out. A test also gets `netsuite.unchanged` over every record type when it only reads and the world has NetSuite, a `trace.called` check for each `must_call`, and a `netsuite.record` check for each of its `records`. Write evals can also give `counts: [{type, count}]` and `unchanged: {types, except: [{type, id | externalId}]}` to check record counts and protect other records. `includeSettlement: true` in a count includes zero-cash settlement records. A record check’s `apply` names the exact applied documents; `credit` names the exact credit sources, both as `[{doc, amount}]` (with `line` for line-level identities). A record named by `externalId` can be one the agent creates:
|
|
21
21
|
|
|
22
22
|
```json
|
|
23
23
|
{"id": "approve-bf-2207", "question": "Approve the Bluefield Logistics bill BF-2207.", "records": [{"type": "vendorBill", "externalId": "BF-2207", "fields": {"approvalStatus": {"id": "2"}}}]}
|
package/lib/assets/docs/setup.md
CHANGED
|
@@ -27,7 +27,7 @@ Requirements: Node 24 or newer. Install once with `npm install -g @ancha-labs/cl
|
|
|
27
27
|
ancha agent upload
|
|
28
28
|
```
|
|
29
29
|
- The install follows the project's own manifests and lockfiles; `agent.install` in `ancha.yaml` sets the command instead.
|
|
30
|
-
5. **Without production traces.** For an agent that uses NetSuite, `ancha init` writes a NetSuite world of a private-equity portfolio company (four subsidiaries, two currencies, thousands of transactions) and 25 tests
|
|
30
|
+
5. **Without production traces.** For an agent that uses NetSuite, `ancha init` writes a NetSuite world of a private-equity portfolio company (four subsidiaries, two currencies, thousands of transactions) and 25 tests: 10 read tasks and 15 write workflows.
|
|
31
31
|
- Your data: `ancha world import netsuite <your exports> --id <id>` reads REST record JSON, SuiteQL results and saved search CSV into `ancha/worlds/<id>.yaml`; check it with `ancha world validate`. To write the seed yourself, `ancha twins seed netsuite` lists its fields.
|
|
32
32
|
- Your evals: `ancha test import <file> --world <id>` (JSONL, JSON, CSV or YAML with a question and an expected answer).
|
|
33
33
|
- One test from a sentence: `ancha test new "<sentence>" --world <id>`.
|
|
@@ -68,7 +68,7 @@ Requirements: Node 24 or newer. Install once with `npm install -g @ancha-labs/cl
|
|
|
68
68
|
`ancha init --agent "node agent.mjs"`, with your own start command, writes:
|
|
69
69
|
- `ancha.yaml`: how to start the agent, how many trials, which tests;
|
|
70
70
|
- `scenes/starter/`: a starter test that checks the agent reaches each tool, with two reference companions (`oracle.mjs` passes, `null.mjs` makes no calls);
|
|
71
|
-
- for an agent that uses NetSuite, in a project with no tests and no `traces/` folder: `ancha/worlds/netsuite-pe-m.yaml`, the NetSuite books of a private-equity portfolio company, and 25 tests in `ancha/tests
|
|
71
|
+
- for an agent that uses NetSuite, in a project with no tests and no `traces/` folder: `ancha/worlds/netsuite-pe-m.yaml`, the NetSuite books of a private-equity portfolio company, and 25 tests in `ancha/tests/`: 10 read tasks and 15 write workflows (their evals in `ancha/evals/`). `--data netsuite-pe:s` or `--data netsuite-pe:l` writes another size, `--data none` leaves them out;
|
|
72
72
|
- `.claude/skills/ancha/SKILL.md` and an Ancha section in `AGENTS.md`, for coding agents;
|
|
73
73
|
- `.ancha/` in `.gitignore`: run history, traces and fake tokens never belong in git.
|
|
74
74
|
|
|
@@ -24,7 +24,7 @@ The import lists the questions the trace leaves open, each with the default the
|
|
|
24
24
|
- `tools.simulate_writes`: the writes a test simulates when the agent makes one production never made; the others fail.
|
|
25
25
|
- `tools.pure`: tools that only compute from their arguments; a test runs them itself.
|
|
26
26
|
- `tools.run`: tools that can run their own code in a test, over a store the agent fills from `records.jsonl`. Production's answers are replayed until something changes; a call production never made, a write, and every call after a write run the tool itself. It also lists the tools the agent's model was given that production never called; a test does not require the agent to wrap those.
|
|
27
|
-
- `checks.success`: the required end state for the user's request,
|
|
27
|
+
- `checks.success`: the required end state for the user's request: what a correct run leaves changed, leaves unchanged and tells the user. For a run that went wrong it is the right action, and the import asks for it plainly; every check of the test judges against the answer, and it stays required. `success:` in the import's output says which end state the test uses.
|
|
28
28
|
- `github.members.<org>`: who was a member of the GitHub organization when the run started, as logins or `none`. The import asks when the agent removed someone's direct access to the organization's repositories; a member keeps read access to all of them.
|
|
29
29
|
|
|
30
30
|
Reimporting into the workspace keeps the latest saved answers, including `task` and `--expect`. Offline imports keep the answers saved in the destination test folder. `--answer task=default` restores one default; `--reset-answers` starts with the trace defaults. Pull preserves checks you add and their membership in `pass`; a conflicting check ID names the check to rename.
|
|
@@ -79642,10 +79642,10 @@ var BetterStackSeedSchema = external_exports.strictObject({
|
|
|
79642
79642
|
open2.add(entry2.source);
|
|
79643
79643
|
}
|
|
79644
79644
|
});
|
|
79645
|
-
seed43.onCall.forEach((
|
|
79645
|
+
seed43.onCall.forEach((calendar4, i) => calendar4.users.forEach((user8, j) => {
|
|
79646
79646
|
if (!people3.has(user8)) issue6(["onCall", i, "users", j], `${user8} is not a user`);
|
|
79647
79647
|
}));
|
|
79648
|
-
if (seed43.onCall.filter((
|
|
79648
|
+
if (seed43.onCall.filter((calendar4) => calendar4.default).length > 1) issue6(["onCall"], "only one default calendar");
|
|
79649
79649
|
seed43.statusPages.forEach((page18, i) => {
|
|
79650
79650
|
const names5 = new Set(page18.resources.map((resource2) => resource2.publicName));
|
|
79651
79651
|
page18.resources.forEach((resource2, j) => {
|
|
@@ -86334,10 +86334,14 @@ var NetsuiteRecordCheckSchema = external_exports.strictObject({
|
|
|
86334
86334
|
id: id8.optional(),
|
|
86335
86335
|
externalId: text11.optional(),
|
|
86336
86336
|
fields: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
|
|
86337
|
-
apply: external_exports.array(application).optional()
|
|
86337
|
+
apply: external_exports.array(application).optional(),
|
|
86338
|
+
credit: external_exports.array(application).optional()
|
|
86338
86339
|
}).refine((check3) => check3.id === void 0 !== (check3.externalId === void 0), { message: "name the record with id or with externalId, not both", path: ["id"] });
|
|
86339
|
-
var NetsuiteUnchangedCheckSchema = external_exports.strictObject({
|
|
86340
|
-
|
|
86340
|
+
var NetsuiteUnchangedCheckSchema = external_exports.strictObject({
|
|
86341
|
+
types: external_exports.array(external_exports.enum(netsuiteRecordTypes)).min(1),
|
|
86342
|
+
except: external_exports.array(external_exports.strictObject({ type: external_exports.enum(netsuiteRecordTypes), id: id8.optional(), externalId: text11.optional() }).refine((check3) => check3.id === void 0 !== (check3.externalId === void 0), { message: "name the record with id or with externalId, not both" })).optional()
|
|
86343
|
+
});
|
|
86344
|
+
var NetsuiteCountCheckSchema = external_exports.strictObject({ type: external_exports.enum(netsuiteRecordTypes), count: external_exports.number().int().min(0), includeSettlement: external_exports.boolean().optional() });
|
|
86341
86345
|
|
|
86342
86346
|
// packages/core/src/scene/schema.ts
|
|
86343
86347
|
var SUPPORTED_TWINS = ["slack", "github", "datadog", "pagerduty", "linkedin-ads", "salesforce", "gong", "hubspot", "ga4", "google-ads", "chatgpt-ads", "open-meteo", "google-drive", "gmail", "amazon-s3", "linear", "okta", "stripe", "clerk", "better-stack", "notion", "attio", "dropbox", "resend", "microsoft-word", "outlook", "shopify", "lob", "paypal", "jira", "kalshi", "intercom", "zendesk", "google-calendar", "twilio", "asana", "discord", "sentry", "airtable", "netsuite", "carrier-portal"];
|
|
@@ -107398,7 +107402,7 @@ var catalogRoutes3 = [
|
|
|
107398
107402
|
return json8({ elements: entities.filter((e) => e.facet === q.get("facet")).map((e) => ({ urn: e.urn, facetUrn: e.facet, name: e.name })) });
|
|
107399
107403
|
} }
|
|
107400
107404
|
];
|
|
107401
|
-
function
|
|
107405
|
+
function calendar2(raw3) {
|
|
107402
107406
|
const match3 = /^\((?:year:(\d{4}),month:(\d{1,2}),day:(\d{1,2})|day:(\d{1,2}),month:(\d{1,2}),year:(\d{4}))\)$/.exec(raw3);
|
|
107403
107407
|
if (!match3) invalid8("Date must be (year:YYYY,month:M,day:D) or (day:D,month:M,year:YYYY)");
|
|
107404
107408
|
const y = match3[1] ?? match3[6], m = match3[2] ?? match3[5], d = match3[3] ?? match3[4], date10 = `${y}-${m.padStart(2, "0")}-${d.padStart(2, "0")}`;
|
|
@@ -107420,7 +107424,7 @@ var analyticsRoutes = [{ method: "GET", path: "/rest/adAnalytics", notes: "analy
|
|
|
107420
107424
|
if (!["DAILY", "ALL"].includes(q.get("timeGranularity") ?? "")) gap2(`timeGranularity ${q.get("timeGranularity")}`);
|
|
107421
107425
|
const range2 = /^\(start:(\([^()]+\))(?:,end:(\([^()]+\)))?\)$/.exec(q.get("dateRange") ?? "");
|
|
107422
107426
|
if (!range2) invalid8("dateRange requires start and optional end tuples");
|
|
107423
|
-
const start =
|
|
107427
|
+
const start = calendar2(range2[1]), end = range2[2] ? calendar2(range2[2]) : c.env.ctx.clock.now().toISOString().slice(0, 10);
|
|
107424
107428
|
if (end < start) invalid8("dateRange.end precedes start");
|
|
107425
107429
|
const selectedFields2 = q.get("fields")?.split(",") ?? ["impressions", "clicks"];
|
|
107426
107430
|
const allowed2 = ["pivotValues", "dateRange", "impressions", "clicks", "oneClickLeads", "costInLocalCurrency"];
|
|
@@ -117598,9 +117602,9 @@ function seed21(ctx) {
|
|
|
117598
117602
|
entry2.resolved?.by ?? null
|
|
117599
117603
|
);
|
|
117600
117604
|
}
|
|
117601
|
-
for (const
|
|
117602
|
-
const users5 =
|
|
117603
|
-
db3.prepare("INSERT INTO bs_calendars (id, name, is_default, users) VALUES (?, ?, ?, ?)").run(nextId3(ctx, "calendar"),
|
|
117605
|
+
for (const calendar4 of input4.onCall) {
|
|
117606
|
+
const users5 = calendar4.users.map((email11) => db3.prepare("SELECT id FROM bs_users WHERE email = ?").get(email11).id);
|
|
117607
|
+
db3.prepare("INSERT INTO bs_calendars (id, name, is_default, users) VALUES (?, ?, ?, ?)").run(nextId3(ctx, "calendar"), calendar4.name, calendar4.default ? 1 : 0, JSON.stringify(users5));
|
|
117604
117608
|
}
|
|
117605
117609
|
for (const page18 of input4.statusPages) {
|
|
117606
117610
|
const id14 = nextId3(ctx, "page");
|
|
@@ -117656,9 +117660,9 @@ function dumpState20(ctx) {
|
|
|
117656
117660
|
resolvedBy: row2.resolved_by,
|
|
117657
117661
|
...row2.summary && { summary: row2.summary }
|
|
117658
117662
|
})),
|
|
117659
|
-
onCall: db3.prepare("SELECT * FROM bs_calendars ORDER BY rowid").all().map((
|
|
117660
|
-
name:
|
|
117661
|
-
users: JSON.parse(
|
|
117663
|
+
onCall: db3.prepare("SELECT * FROM bs_calendars ORDER BY rowid").all().map((calendar4) => ({
|
|
117664
|
+
name: calendar4.name,
|
|
117665
|
+
users: JSON.parse(calendar4.users).map((id14) => db3.prepare("SELECT email FROM bs_users WHERE id = ?").get(id14)?.email ?? id14)
|
|
117662
117666
|
})),
|
|
117663
117667
|
statusPages: db3.prepare("SELECT * FROM bs_pages ORDER BY rowid").all().map((page18) => ({
|
|
117664
117668
|
id: page18.id,
|
|
@@ -131079,7 +131083,7 @@ function feeFor(series2, count4, price3, taker) {
|
|
|
131079
131083
|
const exact = rate * series2.fee_multiplier * (count4 / 100) * (price3 / ONE) * (1 - price3 / ONE);
|
|
131080
131084
|
return Math.ceil(exact * 100 - 1e-9) * 1e4;
|
|
131081
131085
|
}
|
|
131082
|
-
function
|
|
131086
|
+
function ledger2(ctx, now11) {
|
|
131083
131087
|
const db3 = ctx.store.db, positions2 = /* @__PURE__ */ new Map();
|
|
131084
131088
|
let cash = db3.prepare("SELECT COALESCE(SUM(amount), 0) AS total FROM kx_deposits WHERE at_ms <= ?").get(now11).total;
|
|
131085
131089
|
for (const fill of db3.prepare("SELECT * FROM kx_fills WHERE created_ms <= ? ORDER BY created_ms, rowid").all(now11)) {
|
|
@@ -131118,7 +131122,7 @@ function ledger(ctx, now11) {
|
|
|
131118
131122
|
}
|
|
131119
131123
|
var collateral = (order5) => (order5.initial - order5.filled) * (order5.book_side === "bid" ? order5.price : ONE - order5.price);
|
|
131120
131124
|
function balances(ctx, now11) {
|
|
131121
|
-
const { cash, positions: positions2 } =
|
|
131125
|
+
const { cash, positions: positions2 } = ledger2(ctx, now11);
|
|
131122
131126
|
const held = restingOrders(ctx, now11).reduce((total2, order5) => total2 + collateral(order5), 0);
|
|
131123
131127
|
let value4 = 0;
|
|
131124
131128
|
for (const entry2 of positions2.values()) if (entry2.position) value4 += Math.abs(entry2.position) * (entry2.position > 0 ? getMarket(ctx, entry2.ticker).last_price : ONE - getMarket(ctx, entry2.ticker).last_price);
|
|
@@ -131163,7 +131167,7 @@ function seed32(ctx) {
|
|
|
131163
131167
|
});
|
|
131164
131168
|
});
|
|
131165
131169
|
input4.orders.forEach((entry2, i) => {
|
|
131166
|
-
const id14 = seededUuid(`order:${i}`), created3 = at3(entry2.created), series2 = seriesOfMarket(ctx, getMarket(ctx, entry2.market)), positionBefore =
|
|
131170
|
+
const id14 = seededUuid(`order:${i}`), created3 = at3(entry2.created), series2 = seriesOfMarket(ctx, getMarket(ctx, entry2.market)), positionBefore = ledger2(ctx, created3).positions.get(entry2.market)?.position ?? 0;
|
|
131167
131171
|
const legacy2 = legacySide(entry2.side, positionBefore);
|
|
131168
131172
|
db3.prepare(`INSERT INTO kx_orders (id, client_order_id, ticker, book_side, side, action, outcome_side, price, initial, filled, time_in_force, post_only, stp, cancel_on_pause, expiration_ms, created_ms, updated_ms, canceled_ms,
|
|
131169
131173
|
taker_cost, maker_cost, taker_fees, maker_fees) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, 0, 'taker_at_cross', 0, NULL, ?, ?, ?, 0, 0, 0, 0)`).run(id14, entry2.clientOrderId ?? null, entry2.market, entry2.side, legacy2.side, legacy2.action, legacy2.outcome, price3(entry2.price), count4(entry2.count), entry2.timeInForce, created3, created3, entry2.canceled === void 0 ? null : at3(entry2.canceled));
|
|
@@ -131644,7 +131648,7 @@ function positions(call2) {
|
|
|
131644
131648
|
choice2(settlement, "settlement_status", ["all", "settled", "unsettled"]);
|
|
131645
131649
|
for (const name5 of counts) choice2(name5, "count_filter", ["position", "total_traded"]);
|
|
131646
131650
|
const ticker2 = params10.get("ticker"), eventTicker = params10.get("event_ticker");
|
|
131647
|
-
const entries3 = [...
|
|
131651
|
+
const entries3 = [...ledger2(ctx, now11).positions.values()].filter((entry2) => {
|
|
131648
131652
|
const market2 = getMarket(ctx, entry2.ticker);
|
|
131649
131653
|
return (settlement === "all" || settlement === "settled" === (entry2.settlement !== void 0)) && (!ticker2 || entry2.ticker === ticker2) && (!eventTicker || market2.event === eventTicker) && (!counts.length || counts.some((name5) => name5 === "position" ? entry2.position !== 0 : entry2.traded !== 0));
|
|
131650
131654
|
});
|
|
@@ -131706,7 +131710,7 @@ function settlements(call2) {
|
|
|
131706
131710
|
const ctx = call2.ctx, now11 = ctx.clock.nowMs(), params10 = query8(call2, ["limit", "cursor", "ticker", "event_ticker", "min_ts", "max_ts", "subaccount"]), ticker2 = params10.get("ticker"), eventTicker = params10.get("event_ticker");
|
|
131707
131711
|
primary2(params10.get("subaccount"));
|
|
131708
131712
|
const within = timeRange2(params10, "min_ts", "max_ts");
|
|
131709
|
-
const rows7 = [...
|
|
131713
|
+
const rows7 = [...ledger2(ctx, now11).positions.values()].filter((entry2) => entry2.settlement && (!ticker2 || entry2.ticker === ticker2) && (!eventTicker || getMarket(ctx, entry2.ticker).event === eventTicker) && within(entry2.settlement.at)).sort((a, b) => b.settlement.at - a.settlement.at);
|
|
131710
131714
|
const result = page11(call2, rows7, 200, 100);
|
|
131711
131715
|
return json22({
|
|
131712
131716
|
settlements: result.items.map((entry2) => ({
|
|
@@ -147160,7 +147164,7 @@ function bindValue(value4) {
|
|
|
147160
147164
|
}
|
|
147161
147165
|
var pad2 = (n2, width = 2) => String(n2).padStart(width, "0");
|
|
147162
147166
|
var MONTHS2 = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
147163
|
-
function
|
|
147167
|
+
function calendar3(y, m, d) {
|
|
147164
147168
|
const date10 = /* @__PURE__ */ new Date(0);
|
|
147165
147169
|
date10.setUTCFullYear(y, m - 1, d);
|
|
147166
147170
|
date10.setUTCHours(0, 0, 0, 0);
|
|
@@ -147170,7 +147174,7 @@ function calendar2(y, m, d) {
|
|
|
147170
147174
|
function isoDate(text23) {
|
|
147171
147175
|
const match3 = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text23);
|
|
147172
147176
|
if (!match3) invalid24("Expected a YYYY-MM-DD world date.");
|
|
147173
|
-
|
|
147177
|
+
calendar3(+match3[1], +match3[2], +match3[3]);
|
|
147174
147178
|
return text23;
|
|
147175
147179
|
}
|
|
147176
147180
|
function dateModel(model) {
|
|
@@ -147210,7 +147214,7 @@ function parseDate2(value4, model) {
|
|
|
147210
147214
|
const values2 = new Map(tokens3.map((t, i) => [t, match3[i + 1]]));
|
|
147211
147215
|
if (!values2.has("YYYY") || !values2.has("DD") || !["MM", "MON", "MONTH"].some((t) => values2.has(t))) invalid24("TO_DATE requires year, month and day.", true);
|
|
147212
147216
|
const month = values2.has("MM") ? Number(values2.get("MM")) : MONTHS2.findIndex((m) => values2.has("MON") ? m.slice(0, 3).toLowerCase() === values2.get("MON").toLowerCase() : m.toLowerCase() === values2.get("MONTH").toLowerCase()) + 1;
|
|
147213
|
-
const date10 =
|
|
147217
|
+
const date10 = calendar3(Number(values2.get("YYYY")), month, Number(values2.get("DD")));
|
|
147214
147218
|
let hour2 = Number(values2.get("HH24") ?? values2.get("HH12") ?? values2.get("HH") ?? 0);
|
|
147215
147219
|
const minute2 = Number(values2.get("MI") ?? 0), second = Number(values2.get("SS") ?? 0);
|
|
147216
147220
|
if (values2.has("HH12") || values2.has("HH")) {
|
|
@@ -151051,15 +151055,29 @@ function record8(ctx, args) {
|
|
|
151051
151055
|
}
|
|
151052
151056
|
const applied = composite2 ? [...byLine.values()].sort((a, b) => a.doc - b.doc || a.line - b.line) : applications(ctx, id14).map((a) => ({ doc: a.doc, amount: a.amount })).sort((a, b) => a.doc - b.doc);
|
|
151053
151057
|
const wanted = args.apply?.map((a) => composite2 ? { ...a, line: a.line ?? 0 } : { ...a }).sort((a, b) => a.doc - b.doc || (a.line ?? 0) - (b.line ?? 0));
|
|
151054
|
-
|
|
151058
|
+
const creditLines = args.credit?.some((a) => a.line !== void 0);
|
|
151059
|
+
const credits = /* @__PURE__ */ new Map();
|
|
151060
|
+
for (const a of edges(ctx, id14).filter((a2) => a2.source !== id14)) {
|
|
151061
|
+
const key4 = creditLines ? `${a.source}:${a.sourceline}` : String(a.source);
|
|
151062
|
+
const item2 = credits.get(key4) ?? { doc: a.source, ...creditLines && { line: a.sourceline }, amount: 0 };
|
|
151063
|
+
item2.amount = Math.round((item2.amount + a.amount) * 100) / 100;
|
|
151064
|
+
credits.set(key4, item2);
|
|
151065
|
+
}
|
|
151066
|
+
const sort = (a, b) => a.doc - b.doc || (a.line ?? 0) - (b.line ?? 0);
|
|
151067
|
+
const credited = [...credits.values()].sort(sort);
|
|
151068
|
+
const wantedCredits = args.credit?.map((a) => creditLines ? { ...a, line: a.line ?? 0 } : { ...a }).sort(sort);
|
|
151069
|
+
const creditExpected = args.credit === void 0 ? "" : ` and credits ${JSON.stringify(args.credit)}`;
|
|
151070
|
+
return checkOutcome(matches8(actual, args.fields ?? {}) && (wanted === void 0 || isDeepStrictEqual(applied, wanted)) && (wantedCredits === void 0 || isDeepStrictEqual(credited, wantedCredits)), expected + creditExpected, JSON.stringify({ record: actual, apply: applied, credit: credited }));
|
|
151055
151071
|
}
|
|
151056
151072
|
function unchanged(ctx, args) {
|
|
151057
|
-
const
|
|
151073
|
+
const allowed2 = (args.except ?? []).map((r2) => ({ type: r2.type, id: r2.id ?? byExternalId(ctx, r2.type, r2.externalId) }));
|
|
151074
|
+
const changes = sql(ctx).prepare("SELECT recordtype, id, operation FROM ns_history ORDER BY ordinal").all().filter((row2) => args.types.includes(row2.recordtype) && !allowed2.some((r2) => r2.type === row2.recordtype && r2.id === row2.id));
|
|
151058
151075
|
const types = args.types.length >= netsuiteRecordTypes.length && netsuiteRecordTypes.every((type) => args.types.includes(type)) ? "NetSuite records" : args.types.length > 4 ? `${args.types.slice(0, 3).join(", ")} and ${args.types.length - 3} more record types` : args.types.join(", ");
|
|
151059
|
-
|
|
151076
|
+
const except = args.except?.length ? ` except ${args.except.map((r2) => `${r2.type} ${r2.id ?? `eid:${r2.externalId}`}`).join(", ")}` : "";
|
|
151077
|
+
return checkOutcome(changes.length === 0, `no writes to ${types}${except}`, changes.length ? JSON.stringify(changes) : except ? "no other committed writes" : "no committed writes");
|
|
151060
151078
|
}
|
|
151061
151079
|
function count3(ctx, args) {
|
|
151062
|
-
const actual = recordIds(ctx, args.type).length;
|
|
151080
|
+
const actual = args.includeSettlement && isTx(args.type) ? sql(ctx).prepare("SELECT COUNT(*) AS count FROM ns_transactions WHERE recordtype = ?").get(args.type).count : recordIds(ctx, args.type).length;
|
|
151063
151081
|
return checkOutcome(actual === args.count, `${args.count} ${args.type} records`, `${actual} records`);
|
|
151064
151082
|
}
|
|
151065
151083
|
|
|
@@ -193,7 +193,7 @@ class AnchaAgent(BaseInstalledAgent):
|
|
|
193
193
|
ran = time.monotonic() - getattr(self, 'ran_from', time.monotonic())
|
|
194
194
|
limit = max(1, min(max(60, math.ceil(2 * ran)), max(60, math.ceil(self.attempt['timeoutMs'] / 1000))))
|
|
195
195
|
for _ in range(2):
|
|
196
|
-
began = time.monotonic()
|
|
196
|
+
began = time.monotonic(); capture = None
|
|
197
197
|
try:
|
|
198
198
|
capture = await asyncio.shield(environment.service_exec('node /opt/ancha/companion.mjs capture',service='tools',timeout_sec=limit))
|
|
199
199
|
check(capture,'Could not collect final tool state')
|
|
@@ -201,10 +201,22 @@ class AnchaAgent(BaseInstalledAgent):
|
|
|
201
201
|
return
|
|
202
202
|
except BaseException as exc:
|
|
203
203
|
timed_out = isinstance(exc, (TimeoutError, asyncio.TimeoutError)) or time.monotonic() - began >= limit - 1
|
|
204
|
-
CAPTURES[self.aid] = {'captureError':'Final tool state could not be collected','invalidReason':'capture_timeout' if timed_out else 'capture_failed'
|
|
204
|
+
CAPTURES[self.aid] = {'captureError':'Final tool state could not be collected','invalidReason':'capture_timeout' if timed_out else 'capture_failed',
|
|
205
|
+
'detail':capture_detail(capture, exc, timed_out, limit)}
|
|
205
206
|
if CANCELLED or isinstance(exc, asyncio.CancelledError): return
|
|
206
207
|
|
|
207
208
|
|
|
209
|
+
def capture_detail(result, exc, timed_out, limit):
|
|
210
|
+
"""Why the final capture failed, in one line: the world's own error, the end of its output, or the exception."""
|
|
211
|
+
if timed_out: return f'no answer within {limit} s'
|
|
212
|
+
if result is not None and getattr(result, 'return_code', 0) != 0:
|
|
213
|
+
out = (getattr(result, 'stdout', None) or '').strip()
|
|
214
|
+
try: message = json.loads(out).get('error')
|
|
215
|
+
except (ValueError, TypeError, AttributeError): message = None
|
|
216
|
+
return safe(message or out or (getattr(result, 'stderr', None) or '').strip() or f'exit {result.return_code}')[-300:]
|
|
217
|
+
return safe(f'{type(exc).__name__}: {exc}')[:300]
|
|
218
|
+
|
|
219
|
+
|
|
208
220
|
def render(template, info, attempt):
|
|
209
221
|
import re
|
|
210
222
|
values={'task':attempt['prompt'],'env.id':info['id'],'trial':str(attempt['number']),
|
|
@@ -235,8 +247,10 @@ def final_event(aid, error):
|
|
|
235
247
|
status='completed';fields['outcome']='invalid'
|
|
236
248
|
fields['invalidReason']='people_model_failed' if any(issue.get('service')=='people' for issue in issues) else 'harness_failed'
|
|
237
249
|
elif capture and status=='completed':
|
|
238
|
-
# The agent finished; only the final capture failed. Complete, but invalid: not graded, not an error.
|
|
250
|
+
# The agent finished; only the final capture failed. Complete, but invalid: not graded, not an error. Why it
|
|
251
|
+
# failed stays with the attempt as a harness issue.
|
|
239
252
|
fields['outcome']='invalid';fields['invalidReason']=capture.get('invalidReason','capture_failed')
|
|
253
|
+
if capture.get('detail'): fields['harnessIssues']=[{'owner':'harness','service':'tools','kind':'capture','message':f"{capture['captureError']}: {capture['detail']}"}]
|
|
240
254
|
elif capture and status!='stopped':
|
|
241
255
|
status='error';fields['error']=capture['captureError']
|
|
242
256
|
if error and fields.get('outcome')!='invalid': fields['error']=safe(error.exception_message)[:2000]
|