@use-aistack/cli 0.16.6 → 0.16.7
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/README.md +3 -1
- package/dist/cursor-worker.js +14 -9
- package/dist/cursor-worker.js.map +1 -1
- package/dist/index.js +104 -44
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -18891,7 +18891,7 @@ function apiEquivalentCost(modelKey, t, atMs) {
|
|
|
18891
18891
|
}
|
|
18892
18892
|
|
|
18893
18893
|
// src/version.ts
|
|
18894
|
-
var CLI_VERSION = true ? "0.16.
|
|
18894
|
+
var CLI_VERSION = true ? "0.16.7" : "0.0.0-dev";
|
|
18895
18895
|
|
|
18896
18896
|
// src/api.ts
|
|
18897
18897
|
var BASE_URL = process.env.AISTACK_URL || "https://aistack.to";
|
|
@@ -22663,6 +22663,7 @@ function buildSyncBody(built, syncConfig, autoSync, trigger = "manual", measured
|
|
|
22663
22663
|
measuredDays: {
|
|
22664
22664
|
aggregateVersion: MEASURED_DAYS_V1,
|
|
22665
22665
|
utcOffsetMinutes: measuredDays.utcOffsetMinutes,
|
|
22666
|
+
...measuredDays.partial ? { partial: true } : {},
|
|
22666
22667
|
days: applyDayConsent(measuredDays.days, syncConfig)
|
|
22667
22668
|
}
|
|
22668
22669
|
} : base;
|
|
@@ -24570,6 +24571,9 @@ async function readLocalOnce(root, before, onProgress, sourceReadLimits) {
|
|
|
24570
24571
|
const readDone = traceTimer("cursor history read");
|
|
24571
24572
|
let context;
|
|
24572
24573
|
let retrySmallPage = false;
|
|
24574
|
+
let unresolved = 0;
|
|
24575
|
+
let corrupted = 0;
|
|
24576
|
+
let ambiguous = 0;
|
|
24573
24577
|
try {
|
|
24574
24578
|
const reader = await Promise.resolve().then(() => (init_lib(), lib_exports));
|
|
24575
24579
|
const options = {
|
|
@@ -24598,19 +24602,14 @@ async function readLocalOnce(root, before, onProgress, sourceReadLimits) {
|
|
|
24598
24602
|
for (const summary of page.data) {
|
|
24599
24603
|
stats.filesFound++;
|
|
24600
24604
|
if (summary.resolutionState === "ambiguous") {
|
|
24601
|
-
trace(
|
|
24602
|
-
"cursor session resolution incomplete \xB7 ambiguous source",
|
|
24603
|
-
"warn"
|
|
24604
|
-
);
|
|
24605
24605
|
out.complete = false;
|
|
24606
24606
|
}
|
|
24607
24607
|
try {
|
|
24608
24608
|
const session = await reader.getSession(summary.id, config);
|
|
24609
24609
|
if (session.resolutionState !== "complete" || session.messages.some((m) => m.metadata?.corrupted)) {
|
|
24610
|
-
|
|
24611
|
-
|
|
24612
|
-
|
|
24613
|
-
);
|
|
24610
|
+
if (session.resolutionState !== "complete") unresolved++;
|
|
24611
|
+
if (session.messages.some((m) => m.metadata?.corrupted))
|
|
24612
|
+
corrupted++;
|
|
24614
24613
|
out.complete = false;
|
|
24615
24614
|
}
|
|
24616
24615
|
const tokens = await readTokenEvidence(root, session);
|
|
@@ -24619,7 +24618,8 @@ async function readLocalOnce(root, before, onProgress, sourceReadLimits) {
|
|
|
24619
24618
|
onProgress?.(stats.filesRead, page.pagination.total);
|
|
24620
24619
|
} catch (error) {
|
|
24621
24620
|
if (isPageByteLimit(error)) throw error;
|
|
24622
|
-
|
|
24621
|
+
if (traceErrorCode(error) === "SESSION_AMBIGUOUS") ambiguous++;
|
|
24622
|
+
else traceError("cursor session skipped", error, "warn");
|
|
24623
24623
|
out.complete = false;
|
|
24624
24624
|
stats.filesUnreadable++;
|
|
24625
24625
|
} finally {
|
|
@@ -24671,6 +24671,12 @@ async function readLocalOnce(root, before, onProgress, sourceReadLimits) {
|
|
|
24671
24671
|
);
|
|
24672
24672
|
out.complete = false;
|
|
24673
24673
|
}
|
|
24674
|
+
if (unresolved || corrupted || ambiguous) {
|
|
24675
|
+
trace(
|
|
24676
|
+
`cursor partial history \xB7 ${unresolved} sessions unresolved, ${corrupted} with corrupted messages, ${ambiguous} skipped with conflicting copies${ambiguous ? " (SESSION_AMBIGUOUS)" : ""} \xB7 available dated usage retained`,
|
|
24677
|
+
"warn"
|
|
24678
|
+
);
|
|
24679
|
+
}
|
|
24674
24680
|
readDone(
|
|
24675
24681
|
`${stats.filesRead}/${stats.filesFound} sessions read, ${stats.filesUnreadable} unreadable${out.complete ? "" : ", incomplete"}`,
|
|
24676
24682
|
out.complete ? "success" : "warn"
|
|
@@ -24790,9 +24796,13 @@ async function fetchWindow(account, from, to, fetchImpl = fetch) {
|
|
|
24790
24796
|
});
|
|
24791
24797
|
const payload = asObj(await response.json());
|
|
24792
24798
|
const events = payload?.usageEventsDisplay;
|
|
24793
|
-
if (!Array.isArray(events)
|
|
24799
|
+
if (!Array.isArray(events))
|
|
24794
24800
|
throw Object.assign(new Error("Invalid Cursor page"), {
|
|
24795
|
-
code: "
|
|
24801
|
+
code: "CURSOR_INVALID_PAGE_SHAPE"
|
|
24802
|
+
});
|
|
24803
|
+
if (events.length > pageSize)
|
|
24804
|
+
throw Object.assign(new Error("Cursor page exceeds requested size"), {
|
|
24805
|
+
code: "CURSOR_PAGE_TOO_LARGE"
|
|
24796
24806
|
});
|
|
24797
24807
|
if (payload?.totalUsageEventsCount !== void 0) {
|
|
24798
24808
|
const reported = count(payload.totalUsageEventsCount);
|
|
@@ -24911,7 +24921,11 @@ async function refreshAccount(input) {
|
|
|
24911
24921
|
if (previous?.events.length && events.length === 0 && to <= now) continue;
|
|
24912
24922
|
next.windows[key2] = { from, to, fetchedAt: now, events };
|
|
24913
24923
|
} catch (error) {
|
|
24914
|
-
traceError(
|
|
24924
|
+
traceError(
|
|
24925
|
+
"cursor account usage refresh (using local and previously cached usage)",
|
|
24926
|
+
error,
|
|
24927
|
+
"warn"
|
|
24928
|
+
);
|
|
24915
24929
|
break;
|
|
24916
24930
|
}
|
|
24917
24931
|
}
|
|
@@ -28016,28 +28030,57 @@ function selectDaysToPublish(input) {
|
|
|
28016
28030
|
|
|
28017
28031
|
// src/workflow/git.ts
|
|
28018
28032
|
import { execFile, execFileSync as execFileSync2 } from "node:child_process";
|
|
28033
|
+
import { existsSync as existsSync17 } from "node:fs";
|
|
28019
28034
|
import path12 from "node:path";
|
|
28020
28035
|
var TEST_FILE_RULE_VERSION = "test-files/v2";
|
|
28021
28036
|
var FILE_TYPE_RULE_VERSION = "file-types/v3";
|
|
28022
28037
|
var COMMIT_SET_RULE_VERSION = "commit-set/v1";
|
|
28023
|
-
|
|
28038
|
+
function gitDiagnostics() {
|
|
28039
|
+
let missing = 0;
|
|
28040
|
+
let nonRepositories = 0;
|
|
28041
|
+
const report = (error, cwd, args, stderr) => {
|
|
28042
|
+
const details = error;
|
|
28043
|
+
if (args[0] === "rev-parse") {
|
|
28044
|
+
if (details.code === "ENOENT" && !existsSync17(cwd)) {
|
|
28045
|
+
missing++;
|
|
28046
|
+
return;
|
|
28047
|
+
}
|
|
28048
|
+
const message = stderr ?? (typeof details.stderr === "string" ? details.stderr : "");
|
|
28049
|
+
if (/not a git repository/i.test(message)) {
|
|
28050
|
+
nonRepositories++;
|
|
28051
|
+
return;
|
|
28052
|
+
}
|
|
28053
|
+
}
|
|
28054
|
+
traceError(
|
|
28055
|
+
args.includes("log") ? "git history" : "git repository discovery",
|
|
28056
|
+
error,
|
|
28057
|
+
"warn"
|
|
28058
|
+
);
|
|
28059
|
+
};
|
|
28060
|
+
return {
|
|
28061
|
+
report,
|
|
28062
|
+
finish: () => {
|
|
28063
|
+
if (missing || nonRepositories)
|
|
28064
|
+
trace(
|
|
28065
|
+
`git discovery \xB7 skipped ${missing} missing directories, ${nonRepositories} non-repository directories`
|
|
28066
|
+
);
|
|
28067
|
+
}
|
|
28068
|
+
};
|
|
28069
|
+
}
|
|
28070
|
+
var defaultRunner = (cwd, args, report) => {
|
|
28024
28071
|
try {
|
|
28025
28072
|
return execFileSync2("git", [...args], {
|
|
28026
28073
|
cwd,
|
|
28027
28074
|
encoding: "utf8",
|
|
28028
|
-
stdio: ["ignore", "pipe", "
|
|
28075
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
28029
28076
|
maxBuffer: 64 * 1024 * 1024
|
|
28030
28077
|
});
|
|
28031
28078
|
} catch (error) {
|
|
28032
|
-
|
|
28033
|
-
args[0] === "log" ? "git history" : "git repository discovery",
|
|
28034
|
-
error,
|
|
28035
|
-
"warn"
|
|
28036
|
-
);
|
|
28079
|
+
report(error, cwd, args);
|
|
28037
28080
|
return null;
|
|
28038
28081
|
}
|
|
28039
28082
|
};
|
|
28040
|
-
var defaultAsyncRunner = (cwd, args) => new Promise((resolve3) => {
|
|
28083
|
+
var defaultAsyncRunner = (cwd, args, report) => new Promise((resolve3) => {
|
|
28041
28084
|
execFile(
|
|
28042
28085
|
"git",
|
|
28043
28086
|
[...args],
|
|
@@ -28046,13 +28089,8 @@ var defaultAsyncRunner = (cwd, args) => new Promise((resolve3) => {
|
|
|
28046
28089
|
encoding: "utf8",
|
|
28047
28090
|
maxBuffer: 64 * 1024 * 1024
|
|
28048
28091
|
},
|
|
28049
|
-
(error, stdout) => {
|
|
28050
|
-
if (error)
|
|
28051
|
-
traceError(
|
|
28052
|
-
args[0] === "log" ? "git history" : "git repository discovery",
|
|
28053
|
-
error,
|
|
28054
|
-
"warn"
|
|
28055
|
-
);
|
|
28092
|
+
(error, stdout, stderr) => {
|
|
28093
|
+
if (error) report(error, cwd, args, stderr);
|
|
28056
28094
|
resolve3(error ? null : stdout);
|
|
28057
28095
|
}
|
|
28058
28096
|
);
|
|
@@ -28207,12 +28245,14 @@ function isLateNight(hour) {
|
|
|
28207
28245
|
return hour >= 23 || hour < 3;
|
|
28208
28246
|
}
|
|
28209
28247
|
function extractGitWorkflow(options) {
|
|
28210
|
-
const
|
|
28248
|
+
const diagnostics = gitDiagnostics();
|
|
28249
|
+
const run = options.run ?? ((cwd, args) => defaultRunner(cwd, args, diagnostics.report));
|
|
28211
28250
|
const roots = /* @__PURE__ */ new Map();
|
|
28212
28251
|
for (const directory of options.workingDirectories) {
|
|
28213
28252
|
const root = parseRepositoryRoot(run(directory, gitRevParseArgs()));
|
|
28214
28253
|
if (root && !roots.has(root.key)) roots.set(root.key, root.cwd);
|
|
28215
28254
|
}
|
|
28255
|
+
diagnostics.finish();
|
|
28216
28256
|
const histories = [];
|
|
28217
28257
|
let index = 0;
|
|
28218
28258
|
for (const cwd of roots.values()) {
|
|
@@ -28224,12 +28264,14 @@ function extractGitWorkflow(options) {
|
|
|
28224
28264
|
return reduceGitHistories(histories, options);
|
|
28225
28265
|
}
|
|
28226
28266
|
async function extractGitWorkflowAsync(options) {
|
|
28227
|
-
const
|
|
28267
|
+
const diagnostics = gitDiagnostics();
|
|
28268
|
+
const run = options.run ?? ((cwd, args) => defaultAsyncRunner(cwd, args, diagnostics.report));
|
|
28228
28269
|
const roots = /* @__PURE__ */ new Map();
|
|
28229
28270
|
for (const directory of options.workingDirectories) {
|
|
28230
28271
|
const root = parseRepositoryRoot(await run(directory, gitRevParseArgs()));
|
|
28231
28272
|
if (root && !roots.has(root.key)) roots.set(root.key, root.cwd);
|
|
28232
28273
|
}
|
|
28274
|
+
diagnostics.finish();
|
|
28233
28275
|
const queue = [...roots.values()];
|
|
28234
28276
|
const total = queue.length;
|
|
28235
28277
|
const histories = [];
|
|
@@ -28479,7 +28521,7 @@ function buildWorkflowExtraction(harnessWorkflows, git, utcOffsetMinutes = machi
|
|
|
28479
28521
|
|
|
28480
28522
|
// src/sync/grokDateCache.ts
|
|
28481
28523
|
import { createHash as createHash9 } from "node:crypto";
|
|
28482
|
-
import { existsSync as
|
|
28524
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync8, readFileSync as readFileSync18, writeFileSync as writeFileSync8 } from "node:fs";
|
|
28483
28525
|
import { homedir as homedir21 } from "node:os";
|
|
28484
28526
|
import path13 from "node:path";
|
|
28485
28527
|
var defaultFile = path13.join(
|
|
@@ -28492,7 +28534,7 @@ function grokCacheScope(baseUrl, stack, token) {
|
|
|
28492
28534
|
return createHash9("sha256").update(`${baseUrl}\0${stack}\0${token}`).digest("hex");
|
|
28493
28535
|
}
|
|
28494
28536
|
function read2(file) {
|
|
28495
|
-
if (!
|
|
28537
|
+
if (!existsSync18(file)) return {};
|
|
28496
28538
|
try {
|
|
28497
28539
|
const value = JSON.parse(readFileSync18(file, "utf8"));
|
|
28498
28540
|
return value && typeof value === "object" ? value : {};
|
|
@@ -28865,10 +28907,11 @@ function buildGateSummary(ctx) {
|
|
|
28865
28907
|
out.push("", DIVIDER, "", "ALSO PUBLISHING");
|
|
28866
28908
|
if (body.measuredDays) {
|
|
28867
28909
|
out.push(...daysBlock(body.measuredDays, ctx.days));
|
|
28868
|
-
}
|
|
28910
|
+
}
|
|
28911
|
+
if (ctx.incompleteDayScan) {
|
|
28869
28912
|
out.push(
|
|
28870
|
-
"
|
|
28871
|
-
"
|
|
28913
|
+
"coverage partial history: publishing the dated evidence available",
|
|
28914
|
+
" Previously recorded evidence is retained; missing usage is not estimated."
|
|
28872
28915
|
);
|
|
28873
28916
|
}
|
|
28874
28917
|
const workflowDays = (body.measuredDays?.days ?? []).flatMap(
|
|
@@ -28941,7 +28984,14 @@ async function stageSync(deps) {
|
|
|
28941
28984
|
`${label} \xB7 ${state}${note ? ` \xB7 ${note}` : ""}`,
|
|
28942
28985
|
level ?? (state === "failed" ? "error" : state === "done" ? "success" : state === "skipped" ? "warn" : "info")
|
|
28943
28986
|
);
|
|
28944
|
-
emit2({
|
|
28987
|
+
emit2({
|
|
28988
|
+
kind: "step",
|
|
28989
|
+
id,
|
|
28990
|
+
label,
|
|
28991
|
+
state,
|
|
28992
|
+
...note ? { note } : {},
|
|
28993
|
+
...level ? { level } : {}
|
|
28994
|
+
});
|
|
28945
28995
|
};
|
|
28946
28996
|
let prices = {
|
|
28947
28997
|
id: BUNDLED_PRICE_TABLE_ID,
|
|
@@ -29133,7 +29183,8 @@ async function stageSync(deps) {
|
|
|
29133
29183
|
for (const { adapter, history } of readings) {
|
|
29134
29184
|
if (!history) continue;
|
|
29135
29185
|
const { aggregate, workflow: workflow2, workflowLocal, scanComplete, sessionDates } = history;
|
|
29136
|
-
if (scanComplete === false
|
|
29186
|
+
if (scanComplete === false || history.stats.filesUnreadable > 0 || aggregate.parseErrors > 0)
|
|
29187
|
+
dayScansComplete = false;
|
|
29137
29188
|
if (adapter.name === "grok-build" || adapter.name === "cursor")
|
|
29138
29189
|
sessionDatesByHarness.set(adapter.name, sessionDates ?? /* @__PURE__ */ new Map());
|
|
29139
29190
|
workflowScans.push({ aggregate: workflow2, local: workflowLocal });
|
|
@@ -29189,7 +29240,7 @@ async function stageSync(deps) {
|
|
|
29189
29240
|
dayScansComplete = false;
|
|
29190
29241
|
acknowledgements.push(() => saveGrokDateHints(scope, current));
|
|
29191
29242
|
}
|
|
29192
|
-
if (acknowledgements.length)
|
|
29243
|
+
if (acknowledgements.length && dayScansComplete)
|
|
29193
29244
|
acknowledgePublish = () => {
|
|
29194
29245
|
for (const acknowledge of acknowledgements) acknowledge();
|
|
29195
29246
|
};
|
|
@@ -29199,12 +29250,13 @@ async function stageSync(deps) {
|
|
|
29199
29250
|
...workflow ? { workflow: workflow.days } : {},
|
|
29200
29251
|
from: utcDate2(daysSinceMs),
|
|
29201
29252
|
to: utcDate2(now),
|
|
29202
|
-
|
|
29253
|
+
// A partial scan cannot prove that a formerly dated session disappeared.
|
|
29254
|
+
includeDates: dayScansComplete ? correctionDates : /* @__PURE__ */ new Set()
|
|
29203
29255
|
}),
|
|
29204
29256
|
config
|
|
29205
29257
|
);
|
|
29206
29258
|
const days = selectDaysToPublish({
|
|
29207
|
-
local:
|
|
29259
|
+
local: localDays,
|
|
29208
29260
|
manifest,
|
|
29209
29261
|
todayUtc: utcDate2(now)
|
|
29210
29262
|
});
|
|
@@ -29213,8 +29265,9 @@ async function stageSync(deps) {
|
|
|
29213
29265
|
config,
|
|
29214
29266
|
settings.autoSync,
|
|
29215
29267
|
deps.trigger,
|
|
29216
|
-
historical.length > 0
|
|
29268
|
+
historical.length > 0 ? {
|
|
29217
29269
|
aggregateVersion: MEASURED_DAYS_V1,
|
|
29270
|
+
...!dayScansComplete ? { partial: true } : {},
|
|
29218
29271
|
utcOffsetMinutes: workflow?.utcOffsetMinutes ?? machineUtcOffsetMinutes(),
|
|
29219
29272
|
days: days.send
|
|
29220
29273
|
} : void 0,
|
|
@@ -29223,11 +29276,17 @@ async function stageSync(deps) {
|
|
|
29223
29276
|
step("review", "Review", "running");
|
|
29224
29277
|
const bodyJson = JSON.stringify(body);
|
|
29225
29278
|
trace(
|
|
29226
|
-
`days \xB7 ${days.mode}, ${days.send.length} to send${dayScansComplete ? "" : " (
|
|
29279
|
+
`days \xB7 ${days.mode}, ${days.send.length} to send${dayScansComplete ? "" : " (partial history; publishing available evidence)"}`,
|
|
29227
29280
|
dayScansComplete ? "success" : "warn"
|
|
29228
29281
|
);
|
|
29229
29282
|
trace(`body \xB7 ${bodyJson.length} bytes, ${built.length} harness payloads`);
|
|
29230
|
-
step(
|
|
29283
|
+
step(
|
|
29284
|
+
"review",
|
|
29285
|
+
"Review",
|
|
29286
|
+
"done",
|
|
29287
|
+
`${days.send.length} days to send${dayScansComplete ? "" : " \xB7 partial history"}`,
|
|
29288
|
+
dayScansComplete ? "success" : "warn"
|
|
29289
|
+
);
|
|
29231
29290
|
const keptPrivate = mergeKeptPrivate(built.map((b) => b.keptPrivate));
|
|
29232
29291
|
const ctx = {
|
|
29233
29292
|
body,
|
|
@@ -29443,6 +29502,7 @@ function applyEvent(rows, event, now) {
|
|
|
29443
29502
|
row.label = event.label;
|
|
29444
29503
|
row.state = event.state;
|
|
29445
29504
|
row.note = event.note;
|
|
29505
|
+
row.level = event.level;
|
|
29446
29506
|
if (event.state === "running" && row.startedAt === void 0)
|
|
29447
29507
|
row.startedAt = now;
|
|
29448
29508
|
if (event.state === "done" || event.state === "failed") row.endedAt = now;
|
|
@@ -29500,7 +29560,7 @@ function renderRows(rows, opts) {
|
|
|
29500
29560
|
break;
|
|
29501
29561
|
}
|
|
29502
29562
|
case "done":
|
|
29503
|
-
icon = lime("\u25CF");
|
|
29563
|
+
icon = row.level === "warn" ? yellow("\u26A0") : lime("\u25CF");
|
|
29504
29564
|
body = dim(row.note ?? "done");
|
|
29505
29565
|
break;
|
|
29506
29566
|
case "skipped":
|