runwork 0.40.0 → 0.41.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 +362 -109
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5071,7 +5071,7 @@ function resolveAgentCli(agent) {
|
|
|
5071
5071
|
return;
|
|
5072
5072
|
return detectionBinaryTarget(agent.detection);
|
|
5073
5073
|
}
|
|
5074
|
-
var CLAUDE_CODE_NATIVE_INSTALL_PATHS, CODEX_CONFIG_FILE = ".codex/config.toml", CODEX_BUNDLED_CLI_PATHS, CHATGPT_SECURITY_SETTINGS_URL = "https://chatgpt.com/plugins#settings/Security", CHATGPT_CREATE_CONNECTOR_URL = "https://chatgpt.com/plugins#settings/Connectors?create-connector=true&redirectAfter=%2Fplugins", CLAUDE_CONNECTORS_URL = "https://claude.ai/customize/connectors", CODEX_TOOL_CREDENTIALS, AGENT_REGISTRY, slugIndex, nameIndex, CUSTOM_ADAPTER_SLUGS, SHARED_INSTRUCTION_NAMES, toolCredentialKinds = null, getRegistryAgent, getRegistryAgents;
|
|
5074
|
+
var CLAUDE_CODE_NATIVE_INSTALL_PATHS, CODEX_CONFIG_FILE = ".codex/config.toml", CODEX_BUNDLED_CLI_PATHS, CHATGPT_SECURITY_SETTINGS_URL = "https://chatgpt.com/plugins#settings/Security", CHATGPT_CREATE_CONNECTOR_URL = "https://chatgpt.com/plugins#settings/Connectors?create-connector=true&redirectAfter=%2Fplugins", CLAUDE_CONNECTORS_URL = "https://claude.ai/customize/connectors", CODEX_TOOL_CREDENTIALS, ANTIGRAVITY_TOOL_CREDENTIALS, AGY_INSTALL_PATHS, AGENT_REGISTRY, slugIndex, nameIndex, CUSTOM_ADAPTER_SLUGS, SHARED_INSTRUCTION_NAMES, toolCredentialKinds = null, getRegistryAgent, getRegistryAgents;
|
|
5075
5075
|
var init_registry_data = __esm(() => {
|
|
5076
5076
|
CLAUDE_CODE_NATIVE_INSTALL_PATHS = [
|
|
5077
5077
|
{ macos: ".local/bin/claude", linux: ".local/bin/claude", windows: ".local/bin/claude.exe" }
|
|
@@ -5081,6 +5081,8 @@ var init_registry_data = __esm(() => {
|
|
|
5081
5081
|
{ macos: "/Applications/Codex.app/Contents/Resources/codex" }
|
|
5082
5082
|
];
|
|
5083
5083
|
CODEX_TOOL_CREDENTIALS = { config: { kind: "codex", name: "Codex" } };
|
|
5084
|
+
ANTIGRAVITY_TOOL_CREDENTIALS = { config: { kind: "antigravity", name: "Antigravity" } };
|
|
5085
|
+
AGY_INSTALL_PATHS = [{ macos: ".local/bin/agy" }];
|
|
5084
5086
|
AGENT_REGISTRY = [
|
|
5085
5087
|
{
|
|
5086
5088
|
slug: "claude-code",
|
|
@@ -5540,6 +5542,7 @@ var init_registry_data = __esm(() => {
|
|
|
5540
5542
|
aliases: ["Antigravity (Google)"],
|
|
5541
5543
|
description: "Google's agent-first IDE for building with AI -- Editor view for code, Manager view to orchestrate multiple agents in parallel",
|
|
5542
5544
|
category: "ide",
|
|
5545
|
+
family: "antigravity",
|
|
5543
5546
|
detection: {
|
|
5544
5547
|
method: "any",
|
|
5545
5548
|
target: [
|
|
@@ -5549,9 +5552,7 @@ var init_registry_data = __esm(() => {
|
|
|
5549
5552
|
},
|
|
5550
5553
|
launch: {
|
|
5551
5554
|
app: { macos: "Antigravity", windows: "Antigravity" },
|
|
5552
|
-
bundleId: { macos: "com.google.antigravity" }
|
|
5553
|
-
cli: "antigravity",
|
|
5554
|
-
openInFolder: { rank: 5, shell: "cd {dir} && antigravity" }
|
|
5555
|
+
bundleId: { macos: "com.google.antigravity" }
|
|
5555
5556
|
},
|
|
5556
5557
|
logo: "antigravity",
|
|
5557
5558
|
downloadUrl: "https://antigravity.google",
|
|
@@ -5559,6 +5560,7 @@ var init_registry_data = __esm(() => {
|
|
|
5559
5560
|
mcpConfigPath: ".gemini/antigravity/mcp_config.json",
|
|
5560
5561
|
mcpConfigKey: "mcpServers",
|
|
5561
5562
|
firstClass: true,
|
|
5563
|
+
toolCredentials: ANTIGRAVITY_TOOL_CREDENTIALS,
|
|
5562
5564
|
quickStart: {
|
|
5563
5565
|
launchHint: "Open Antigravity",
|
|
5564
5566
|
examplePrompts: [
|
|
@@ -5567,6 +5569,42 @@ var init_registry_data = __esm(() => {
|
|
|
5567
5569
|
]
|
|
5568
5570
|
}
|
|
5569
5571
|
},
|
|
5572
|
+
{
|
|
5573
|
+
slug: "agy",
|
|
5574
|
+
name: "Antigravity CLI",
|
|
5575
|
+
aliases: ["agy"],
|
|
5576
|
+
description: "Google's Antigravity agent in your terminal, for coding, research, and automating work",
|
|
5577
|
+
category: "cli",
|
|
5578
|
+
family: "antigravity",
|
|
5579
|
+
detection: {
|
|
5580
|
+
method: "any",
|
|
5581
|
+
target: [
|
|
5582
|
+
{ method: "binary", target: "agy" },
|
|
5583
|
+
...AGY_INSTALL_PATHS.map((target) => ({ method: "path", target }))
|
|
5584
|
+
]
|
|
5585
|
+
},
|
|
5586
|
+
launch: {
|
|
5587
|
+
cli: "agy",
|
|
5588
|
+
cliAcceptsPrompt: true,
|
|
5589
|
+
cliPromptFlag: "-i",
|
|
5590
|
+
cliWellKnownPaths: AGY_INSTALL_PATHS,
|
|
5591
|
+
openInFolder: { rank: 5, shell: "cd {dir} && agy" }
|
|
5592
|
+
},
|
|
5593
|
+
logo: "antigravity",
|
|
5594
|
+
downloadUrl: "https://antigravity.google",
|
|
5595
|
+
skillsPaths: { global: ".gemini/config/skills", project: ".agents/skills" },
|
|
5596
|
+
mcpConfigPath: ".gemini/config/mcp_config.json",
|
|
5597
|
+
mcpConfigKey: "mcpServers",
|
|
5598
|
+
firstClass: true,
|
|
5599
|
+
toolCredentials: ANTIGRAVITY_TOOL_CREDENTIALS,
|
|
5600
|
+
quickStart: {
|
|
5601
|
+
launchHint: "Open your terminal and type `agy`",
|
|
5602
|
+
examplePrompts: [
|
|
5603
|
+
"What workspace skills do I have available?",
|
|
5604
|
+
"Use Runwork tools to check team data"
|
|
5605
|
+
]
|
|
5606
|
+
}
|
|
5607
|
+
},
|
|
5570
5608
|
{
|
|
5571
5609
|
slug: "copilot-vscode",
|
|
5572
5610
|
name: "GitHub Copilot (VS Code)",
|
|
@@ -6065,7 +6103,7 @@ var init_workspace_server = __esm(() => {
|
|
|
6065
6103
|
});
|
|
6066
6104
|
|
|
6067
6105
|
// src/generated/version.ts
|
|
6068
|
-
var VERSION = "0.
|
|
6106
|
+
var VERSION = "0.41.0";
|
|
6069
6107
|
|
|
6070
6108
|
// ../../shared/agent-instructions/managed-blocks.ts
|
|
6071
6109
|
function stripManagedBlocks(content, markers) {
|
|
@@ -6958,25 +6996,37 @@ var init_native_transcript = __esm(() => {
|
|
|
6958
6996
|
});
|
|
6959
6997
|
|
|
6960
6998
|
// src/agents/claude/analyst.ts
|
|
6961
|
-
function
|
|
6999
|
+
function readClaudeResult(stdout) {
|
|
6962
7000
|
try {
|
|
6963
7001
|
const d = JSON.parse(stdout.trim());
|
|
6964
|
-
|
|
6965
|
-
return null;
|
|
6966
|
-
const models = Object.entries(d.modelUsage ?? {});
|
|
6967
|
-
const input = models.reduce((s, [, u]) => s + (u.inputTokens ?? 0), 0);
|
|
6968
|
-
const output = models.reduce((s, [, u]) => s + (u.outputTokens ?? 0), 0);
|
|
6969
|
-
return {
|
|
6970
|
-
text: d.result,
|
|
6971
|
-
model: models[0]?.[0] ?? null,
|
|
6972
|
-
inputTokens: models.length ? input : null,
|
|
6973
|
-
outputTokens: models.length ? output : null,
|
|
6974
|
-
costUSD: typeof d.total_cost_usd === "number" ? d.total_cost_usd : null
|
|
6975
|
-
};
|
|
7002
|
+
return d && typeof d === "object" ? d : null;
|
|
6976
7003
|
} catch {
|
|
6977
7004
|
return null;
|
|
6978
7005
|
}
|
|
6979
7006
|
}
|
|
7007
|
+
function parseClaudeAnalystOutput(stdout) {
|
|
7008
|
+
const d = readClaudeResult(stdout);
|
|
7009
|
+
if (!d || d.is_error === true || typeof d.result !== "string")
|
|
7010
|
+
return null;
|
|
7011
|
+
const models = Object.entries(d.modelUsage ?? {});
|
|
7012
|
+
const input = models.reduce((s, [, u]) => s + (u.inputTokens ?? 0), 0);
|
|
7013
|
+
const output = models.reduce((s, [, u]) => s + (u.outputTokens ?? 0), 0);
|
|
7014
|
+
return {
|
|
7015
|
+
text: d.result,
|
|
7016
|
+
model: models[0]?.[0] ?? null,
|
|
7017
|
+
inputTokens: models.length ? input : null,
|
|
7018
|
+
outputTokens: models.length ? output : null,
|
|
7019
|
+
costUSD: typeof d.total_cost_usd === "number" ? d.total_cost_usd : null
|
|
7020
|
+
};
|
|
7021
|
+
}
|
|
7022
|
+
function claudeAnalystFailure(run) {
|
|
7023
|
+
const d = readClaudeResult(run.stdout);
|
|
7024
|
+
if (!d || d.is_error !== true)
|
|
7025
|
+
return null;
|
|
7026
|
+
const unused = Object.keys(d.modelUsage ?? {}).length === 0 && d.total_cost_usd === 0 && d.duration_api_ms === 0;
|
|
7027
|
+
const said = typeof d.result === "string" ? d.result.trim() : "";
|
|
7028
|
+
return { reachedModel: !unused, message: said || `Claude Code reported an error (exit ${run.exitCode})` };
|
|
7029
|
+
}
|
|
6980
7030
|
function claudeAnalystArgs(model, tools) {
|
|
6981
7031
|
return [
|
|
6982
7032
|
"-p",
|
|
@@ -6999,6 +7049,7 @@ function withClaudeAnalyst(base) {
|
|
|
6999
7049
|
structured: {
|
|
7000
7050
|
args: claudeAnalystArgs("sonnet", DEEP_ANALYST_TOOLS),
|
|
7001
7051
|
parse: parseClaudeAnalystOutput,
|
|
7052
|
+
failure: claudeAnalystFailure,
|
|
7002
7053
|
cheap: () => ({ args: claudeAnalystArgs("haiku", NO_TOOLS) })
|
|
7003
7054
|
}
|
|
7004
7055
|
};
|
|
@@ -7197,7 +7248,7 @@ function parseCall(value) {
|
|
|
7197
7248
|
const v = value;
|
|
7198
7249
|
if (!isIso(v.at) || typeof v.agent !== "string" || typeof v.kind !== "string" || !CALL_KINDS.has(v.kind))
|
|
7199
7250
|
return null;
|
|
7200
|
-
return { at: v.at, agent: v.agent, kind: v.kind, ok: v.ok === true };
|
|
7251
|
+
return { at: v.at, agent: v.agent, kind: v.kind, ok: v.ok === true, reachedModel: v.reachedModel !== false };
|
|
7201
7252
|
}
|
|
7202
7253
|
function loadCalls() {
|
|
7203
7254
|
const raw = loadCadenceState().aiCalls;
|
|
@@ -7211,6 +7262,20 @@ function recordAiCall(call, now) {
|
|
|
7211
7262
|
const calls = [...loadCalls().filter((c) => Date.parse(c.at) > floor), { ...call, at: now.toISOString() }];
|
|
7212
7263
|
saveCadenceState({ ...loadCadenceState(), aiCalls: calls });
|
|
7213
7264
|
}
|
|
7265
|
+
function markCallsUnreached(spans) {
|
|
7266
|
+
const calls = loadCalls();
|
|
7267
|
+
let changed = 0;
|
|
7268
|
+
const next = calls.map((c) => {
|
|
7269
|
+
const t = Date.parse(c.at);
|
|
7270
|
+
if (!c.ok && c.reachedModel === false || !spans.some((s) => t >= s.from && t <= s.to))
|
|
7271
|
+
return c;
|
|
7272
|
+
changed++;
|
|
7273
|
+
return { ...c, ok: false, reachedModel: false };
|
|
7274
|
+
});
|
|
7275
|
+
if (changed > 0)
|
|
7276
|
+
saveCadenceState({ ...loadCadenceState(), aiCalls: next });
|
|
7277
|
+
return changed;
|
|
7278
|
+
}
|
|
7214
7279
|
function spentToday(calls, kind, now) {
|
|
7215
7280
|
const today = utcDay(now);
|
|
7216
7281
|
return calls.filter((c) => c.kind === kind && c.ok && utcDay(c.at) === today).length;
|
|
@@ -7241,6 +7306,7 @@ function createAiScheduler(analysts, opts) {
|
|
|
7241
7306
|
}
|
|
7242
7307
|
return snapshots.get(a.slug) ?? null;
|
|
7243
7308
|
};
|
|
7309
|
+
let freesAt = null;
|
|
7244
7310
|
return {
|
|
7245
7311
|
admit(kind, exclude = new Set) {
|
|
7246
7312
|
const at = now();
|
|
@@ -7264,9 +7330,12 @@ function createAiScheduler(analysts, opts) {
|
|
|
7264
7330
|
refusal = "no-plan-budget";
|
|
7265
7331
|
continue;
|
|
7266
7332
|
}
|
|
7267
|
-
const inWindow = calls.filter((c) => c.agent === a.slug && at.getTime() - Date.parse(c.at) < CALL_WINDOW_MS)
|
|
7268
|
-
if (inWindow >= budget.callsPer5h)
|
|
7333
|
+
const inWindow = calls.filter((c) => c.agent === a.slug && c.reachedModel !== false && at.getTime() - Date.parse(c.at) < CALL_WINDOW_MS);
|
|
7334
|
+
if (inWindow.length >= budget.callsPer5h) {
|
|
7335
|
+
const oldest = Math.min(...inWindow.map((c) => Date.parse(c.at)));
|
|
7336
|
+
freesAt = new Date(oldest + CALL_WINDOW_MS).toISOString();
|
|
7269
7337
|
return { refused: "window-full" };
|
|
7338
|
+
}
|
|
7270
7339
|
if (opts.mode === "auto" && kind !== "periodic") {
|
|
7271
7340
|
const cap = kind === "deep" ? budget.deepPerDay : budget.triagePerDay;
|
|
7272
7341
|
if (budget.usedToday[kind] >= cap)
|
|
@@ -7280,7 +7349,7 @@ function createAiScheduler(analysts, opts) {
|
|
|
7280
7349
|
},
|
|
7281
7350
|
settle(analyst, kind, outcome) {
|
|
7282
7351
|
const at = now();
|
|
7283
|
-
recordAiCall({ agent: analyst.slug, kind, ok: outcome.ok }, at);
|
|
7352
|
+
recordAiCall({ agent: analyst.slug, kind, ok: outcome.ok, reachedModel: outcome.reachedModel !== false }, at);
|
|
7284
7353
|
if (outcome.hit) {
|
|
7285
7354
|
recordLimitHit(analyst.slug, outcome.hit, at);
|
|
7286
7355
|
if (outcome.hit.kind !== "rate" && !autoDisabledByRunwork() && shouldAutoDisable(at)) {
|
|
@@ -7288,7 +7357,8 @@ function createAiScheduler(analysts, opts) {
|
|
|
7288
7357
|
}
|
|
7289
7358
|
}
|
|
7290
7359
|
publishBudget(analyst.slug, snapshotOf(analyst), at);
|
|
7291
|
-
}
|
|
7360
|
+
},
|
|
7361
|
+
windowFreesAt: () => freesAt
|
|
7292
7362
|
};
|
|
7293
7363
|
}
|
|
7294
7364
|
function nextLocalClockTime(hour, minute, now) {
|
|
@@ -14062,9 +14132,8 @@ function withEphemeral(args, command) {
|
|
|
14062
14132
|
}
|
|
14063
14133
|
return listed ? [...args.slice(0, at + 1), EPHEMERAL, ...args.slice(at + 1)] : args;
|
|
14064
14134
|
}
|
|
14065
|
-
function
|
|
14066
|
-
|
|
14067
|
-
let usage = null;
|
|
14135
|
+
function readCodexStream(stdout) {
|
|
14136
|
+
const stream = { text: "", completed: false, usage: null, failed: null };
|
|
14068
14137
|
for (const line of stdout.split(`
|
|
14069
14138
|
`)) {
|
|
14070
14139
|
if (!line.trim().startsWith("{"))
|
|
@@ -14072,13 +14141,30 @@ function parseCodexAnalystOutput(stdout) {
|
|
|
14072
14141
|
try {
|
|
14073
14142
|
const o = JSON.parse(line);
|
|
14074
14143
|
if (o.type === "item.completed" && o.item?.type === "agent_message" && typeof o.item.text === "string") {
|
|
14075
|
-
text = o.item.text;
|
|
14076
|
-
} else if (o.type === "turn.completed"
|
|
14077
|
-
|
|
14144
|
+
stream.text = o.item.text;
|
|
14145
|
+
} else if (o.type === "turn.completed") {
|
|
14146
|
+
stream.completed = true;
|
|
14147
|
+
if (o.usage)
|
|
14148
|
+
stream.usage = o.usage;
|
|
14149
|
+
} else if (o.type === "turn.failed") {
|
|
14150
|
+
stream.failed = typeof o.error?.message === "string" ? o.error.message.trim() : "";
|
|
14078
14151
|
}
|
|
14079
14152
|
} catch {}
|
|
14080
14153
|
}
|
|
14081
|
-
|
|
14154
|
+
return stream;
|
|
14155
|
+
}
|
|
14156
|
+
function codexAnalystFailure(run) {
|
|
14157
|
+
const stream = readCodexStream(run.stdout);
|
|
14158
|
+
if (stream.completed || stream.failed === null)
|
|
14159
|
+
return null;
|
|
14160
|
+
return {
|
|
14161
|
+
reachedModel: !/\b401 Unauthorized\b/.test(stream.failed),
|
|
14162
|
+
message: stream.failed || `Codex failed the turn (exit ${run.exitCode})`
|
|
14163
|
+
};
|
|
14164
|
+
}
|
|
14165
|
+
function parseCodexAnalystOutput(stdout) {
|
|
14166
|
+
const { text, completed, usage, failed } = readCodexStream(stdout);
|
|
14167
|
+
if (!text || failed !== null && !completed)
|
|
14082
14168
|
return null;
|
|
14083
14169
|
return {
|
|
14084
14170
|
text,
|
|
@@ -14095,6 +14181,7 @@ function withCodexAnalyst(base) {
|
|
|
14095
14181
|
structured: {
|
|
14096
14182
|
args: [...STRUCTURED_BASE, "-"],
|
|
14097
14183
|
parse: parseCodexAnalystOutput,
|
|
14184
|
+
failure: codexAnalystFailure,
|
|
14098
14185
|
cheap: (modelHint) => {
|
|
14099
14186
|
const effort = ["-c", "model_reasoning_effort=low"];
|
|
14100
14187
|
return {
|
|
@@ -15983,6 +16070,7 @@ var init_generic_adapter = __esm(() => {
|
|
|
15983
16070
|
init_types();
|
|
15984
16071
|
init_json_config();
|
|
15985
16072
|
init_instruction_hint();
|
|
16073
|
+
init_registry_data();
|
|
15986
16074
|
init_registry();
|
|
15987
16075
|
init_detection_probes();
|
|
15988
16076
|
init_detection();
|
|
@@ -16009,6 +16097,9 @@ var init_generic_adapter = __esm(() => {
|
|
|
16009
16097
|
spaceSyncRules() {
|
|
16010
16098
|
return { neverSync: this.def.spaceNeverSync ?? [] };
|
|
16011
16099
|
}
|
|
16100
|
+
toolCredentials() {
|
|
16101
|
+
return getAgentToolCredentials(this.slug);
|
|
16102
|
+
}
|
|
16012
16103
|
mcpFilePath() {
|
|
16013
16104
|
if (!this.def.mcpConfigPath)
|
|
16014
16105
|
return null;
|
|
@@ -16396,6 +16487,11 @@ function mergeSent(mine, disk) {
|
|
|
16396
16487
|
}
|
|
16397
16488
|
return merged;
|
|
16398
16489
|
}
|
|
16490
|
+
function lastDeepEvent(v) {
|
|
16491
|
+
const analyzed = v.analyzedAt ?? "";
|
|
16492
|
+
const reopened = v.reopenedAt ?? "";
|
|
16493
|
+
return analyzed > reopened ? analyzed : reopened;
|
|
16494
|
+
}
|
|
16399
16495
|
function laterVerdict(mine, disk) {
|
|
16400
16496
|
if (!isCensusTriageVerdict(disk))
|
|
16401
16497
|
return mine;
|
|
@@ -16403,7 +16499,7 @@ function laterVerdict(mine, disk) {
|
|
|
16403
16499
|
return disk;
|
|
16404
16500
|
if (disk.at !== mine.at)
|
|
16405
16501
|
return disk.at > mine.at ? disk : mine;
|
|
16406
|
-
return
|
|
16502
|
+
return lastDeepEvent(disk) > lastDeepEvent(mine) ? disk : mine;
|
|
16407
16503
|
}
|
|
16408
16504
|
function saveCensusStore(store) {
|
|
16409
16505
|
const { store: disk, unreadable } = readCensusFile();
|
|
@@ -17219,7 +17315,9 @@ var init_integration_display = __esm(() => {
|
|
|
17219
17315
|
whatsapp: "WhatsApp",
|
|
17220
17316
|
openai: "OpenAI",
|
|
17221
17317
|
aws: "AWS",
|
|
17222
|
-
"0codekit": "0CodeKit"
|
|
17318
|
+
"0codekit": "0CodeKit",
|
|
17319
|
+
bingwebmasters: "Bing Webmaster Tools",
|
|
17320
|
+
bingwebmastersapi: "Bing Webmaster Tools"
|
|
17223
17321
|
};
|
|
17224
17322
|
});
|
|
17225
17323
|
|
|
@@ -42604,6 +42702,88 @@ function parseHandoffResult(kind, text) {
|
|
|
42604
42702
|
return { ok: false, reason: "wrong-shape" };
|
|
42605
42703
|
}
|
|
42606
42704
|
|
|
42705
|
+
// ../../shared/reflect/analysis-reasons.ts
|
|
42706
|
+
function windowFullSentence({ windowFreesAt, now = new Date }) {
|
|
42707
|
+
const base = "Reflection has used its share of this 5-hour window.";
|
|
42708
|
+
const at = windowFreesAt ? Date.parse(windowFreesAt) : NaN;
|
|
42709
|
+
if (!Number.isFinite(at) || at <= now.getTime())
|
|
42710
|
+
return `${base} The rest waits for the next one.`;
|
|
42711
|
+
const time = new Date(at).toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit" });
|
|
42712
|
+
return `${base} The next analysis can run at ${time}.`;
|
|
42713
|
+
}
|
|
42714
|
+
function isAnalysisReason(value) {
|
|
42715
|
+
return typeof value === "string" && ANALYSIS_REASONS.includes(value);
|
|
42716
|
+
}
|
|
42717
|
+
function describeAnalysisReason(reason, ctx = {}) {
|
|
42718
|
+
if (!isAnalysisReason(reason))
|
|
42719
|
+
return UNKNOWN_REASON;
|
|
42720
|
+
const sentence = SENTENCES[reason](ctx);
|
|
42721
|
+
const hint = ctx.terminal ? TERMINAL_HINTS[reason] : undefined;
|
|
42722
|
+
return hint ? `${sentence} ${hint}` : sentence;
|
|
42723
|
+
}
|
|
42724
|
+
function describeAnalystFailure(analystError) {
|
|
42725
|
+
const said = analystError.replace(/\s+/g, " ").trim();
|
|
42726
|
+
if (!said)
|
|
42727
|
+
return "The last analysis failed.";
|
|
42728
|
+
const quoted = said.length > FAILURE_QUOTE_CHARS ? `${said.slice(0, FAILURE_QUOTE_CHARS)}…` : said;
|
|
42729
|
+
return `The last analysis failed. It said: ${quoted}`;
|
|
42730
|
+
}
|
|
42731
|
+
function describeAnalysisStop(outcome, opts = {}) {
|
|
42732
|
+
const failure = outcome.analystError ? describeAnalystFailure(outcome.analystError) : null;
|
|
42733
|
+
if (outcome.reason) {
|
|
42734
|
+
const sentence = describeAnalysisReason(outcome.reason, { ...opts, windowFreesAt: outcome.windowFreesAt, pendingLeft: outcome.pendingLeft });
|
|
42735
|
+
return failure ? `${sentence} ${failure}` : sentence;
|
|
42736
|
+
}
|
|
42737
|
+
return (outcome.analyzed?.length ?? 0) === 0 ? failure : null;
|
|
42738
|
+
}
|
|
42739
|
+
var ANALYSIS_REASONS, UNKNOWN_REASON = "Analysis did not run this time.", SENTENCES, TERMINAL_HINTS, FAILURE_QUOTE_CHARS = 200;
|
|
42740
|
+
var init_analysis_reasons = __esm(() => {
|
|
42741
|
+
ANALYSIS_REASONS = [
|
|
42742
|
+
"auto-disabled",
|
|
42743
|
+
"workspace-disabled",
|
|
42744
|
+
"no-analyst",
|
|
42745
|
+
"run-in-progress",
|
|
42746
|
+
"session-not-found",
|
|
42747
|
+
"nothing-pending",
|
|
42748
|
+
"no-sessions",
|
|
42749
|
+
"not-due",
|
|
42750
|
+
"quota-disabled",
|
|
42751
|
+
"quota-paused",
|
|
42752
|
+
"no-plan-budget",
|
|
42753
|
+
"window-full",
|
|
42754
|
+
"budget-exhausted",
|
|
42755
|
+
"limit-reached",
|
|
42756
|
+
"analyst-failed"
|
|
42757
|
+
];
|
|
42758
|
+
SENTENCES = {
|
|
42759
|
+
"auto-disabled": () => "Automatic reflection is off.",
|
|
42760
|
+
"workspace-disabled": () => "Reflection is turned off for this workspace by an admin.",
|
|
42761
|
+
"no-analyst": () => "No AI agent on this computer could run the analysis. If one is installed, it may need signing in or reinstalling.",
|
|
42762
|
+
"run-in-progress": () => "Another analysis is already running on this computer.",
|
|
42763
|
+
"session-not-found": () => "That conversation is not in the list of conversations on this computer.",
|
|
42764
|
+
"nothing-pending": () => "No finished conversations are waiting for analysis.",
|
|
42765
|
+
"no-sessions": () => "No finished conversations to reflect on yet. Use your AI tools a bit, then try again.",
|
|
42766
|
+
"not-due": () => "Not enough new work since the last reflection.",
|
|
42767
|
+
"quota-disabled": () => "Your AI plan hit its usage limit twice this week, so automatic reflection is off.",
|
|
42768
|
+
"quota-paused": () => "Your AI agent reported a usage limit, so analysis waits until it resets.",
|
|
42769
|
+
"no-plan-budget": () => "Your AI plan leaves no room for automatic analysis.",
|
|
42770
|
+
"window-full": windowFullSentence,
|
|
42771
|
+
"budget-exhausted": ({ pendingLeft }) => {
|
|
42772
|
+
if (pendingLeft === undefined || pendingLeft <= 0)
|
|
42773
|
+
return "Today's share of analyses is used up, so the rest waits until tomorrow.";
|
|
42774
|
+
const waiting = pendingLeft === 1 ? "1 conversation waits" : `${pendingLeft} conversations wait`;
|
|
42775
|
+
return `Today's share of analyses is used up, so ${waiting} until tomorrow.`;
|
|
42776
|
+
},
|
|
42777
|
+
"limit-reached": () => "Your AI agent reported a usage limit, so reflection waits until it resets.",
|
|
42778
|
+
"analyst-failed": () => "Your AI agent could not complete the analysis. Make sure it is signed in."
|
|
42779
|
+
};
|
|
42780
|
+
TERMINAL_HINTS = {
|
|
42781
|
+
"auto-disabled": "Turn it on with runwork reflect --enable-auto, or run with --force.",
|
|
42782
|
+
"quota-disabled": "Turn it back on with runwork reflect --enable-auto.",
|
|
42783
|
+
"no-sessions": "The desktop app records conversations as they finish; runwork conversations scan records them now."
|
|
42784
|
+
};
|
|
42785
|
+
});
|
|
42786
|
+
|
|
42607
42787
|
// src/commands/reflect.ts
|
|
42608
42788
|
import { Command as Command18 } from "commander";
|
|
42609
42789
|
import { writeFileSync as writeFileSync40, mkdirSync as mkdirSync38 } from "fs";
|
|
@@ -42623,6 +42803,7 @@ function analystRoster() {
|
|
|
42623
42803
|
args: spec.args,
|
|
42624
42804
|
spec,
|
|
42625
42805
|
...spec.prepareArgs ? { prepareArgs: spec.prepareArgs } : {},
|
|
42806
|
+
...spec.structured?.failure ? { failure: spec.structured.failure } : {},
|
|
42626
42807
|
...adapter.readQuota ? { readQuota: () => adapter.readQuota?.() ?? null } : {},
|
|
42627
42808
|
...adapter.limitHit ? { limitHit: (run) => adapter.limitHit?.(run) ?? null } : {}
|
|
42628
42809
|
}];
|
|
@@ -42800,10 +42981,16 @@ ${summary}`;
|
|
|
42800
42981
|
function runHeadless(command, args, prompt, timeoutMs = ANALYST_TIMEOUT_MS) {
|
|
42801
42982
|
return new Promise((resolve, reject) => {
|
|
42802
42983
|
const spec = toSpawnSpec(command, args);
|
|
42803
|
-
|
|
42804
|
-
|
|
42805
|
-
|
|
42806
|
-
|
|
42984
|
+
let child;
|
|
42985
|
+
try {
|
|
42986
|
+
child = spawn2(spec.command, spec.args, {
|
|
42987
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
42988
|
+
...spec.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
|
|
42989
|
+
});
|
|
42990
|
+
} catch (e) {
|
|
42991
|
+
reject(new AnalystLaunchError(`could not launch ${command}: ${e instanceof Error ? e.message : String(e)}`));
|
|
42992
|
+
return;
|
|
42993
|
+
}
|
|
42807
42994
|
let out = "";
|
|
42808
42995
|
let err = "";
|
|
42809
42996
|
let settled = false;
|
|
@@ -42828,7 +43015,7 @@ function runHeadless(command, args, prompt, timeoutMs = ANALYST_TIMEOUT_MS) {
|
|
|
42828
43015
|
child.stderr?.on("data", (d) => {
|
|
42829
43016
|
err += d.toString();
|
|
42830
43017
|
});
|
|
42831
|
-
child.on("error", (e) => finish(() => reject(new
|
|
43018
|
+
child.on("error", (e) => finish(() => reject(new AnalystLaunchError(`could not launch ${command}: ${e.message}`))));
|
|
42832
43019
|
child.on("close", (code) => finish(() => {
|
|
42833
43020
|
let json = null;
|
|
42834
43021
|
try {
|
|
@@ -42844,19 +43031,26 @@ function runHeadless(command, args, prompt, timeoutMs = ANALYST_TIMEOUT_MS) {
|
|
|
42844
43031
|
}
|
|
42845
43032
|
});
|
|
42846
43033
|
}
|
|
43034
|
+
function failureOf2(analyst, run) {
|
|
43035
|
+
try {
|
|
43036
|
+
return analyst.failure?.(run) ?? null;
|
|
43037
|
+
} catch {
|
|
43038
|
+
return null;
|
|
43039
|
+
}
|
|
43040
|
+
}
|
|
42847
43041
|
function spawnArgs(analyst, args) {
|
|
42848
43042
|
return analyst.prepareArgs ? analyst.prepareArgs(args, analyst.command) : args;
|
|
42849
43043
|
}
|
|
42850
43044
|
async function meteredCall(analyst, kind, args, prompt, parse, opts = {}) {
|
|
42851
|
-
const fail = (error, hit) => {
|
|
42852
|
-
opts.scheduler?.settle(analyst, kind, { ok: false, hit });
|
|
42853
|
-
return { ok: false, error, hit };
|
|
43045
|
+
const fail = (error, hit, reachedModel = true) => {
|
|
43046
|
+
opts.scheduler?.settle(analyst, kind, { ok: false, hit, reachedModel });
|
|
43047
|
+
return { ok: false, error, hit, reachedModel };
|
|
42854
43048
|
};
|
|
42855
43049
|
let run;
|
|
42856
43050
|
try {
|
|
42857
43051
|
run = await (opts.runner ?? runHeadless)(analyst.command, spawnArgs(analyst, args), prompt, opts.timeoutMs);
|
|
42858
43052
|
} catch (e) {
|
|
42859
|
-
return fail(e instanceof Error ? e.message : String(e), null);
|
|
43053
|
+
return fail(e instanceof Error ? e.message : String(e), null, !(e instanceof AnalystLaunchError));
|
|
42860
43054
|
}
|
|
42861
43055
|
const hit = limitHitOf(analyst, run);
|
|
42862
43056
|
if (hit) {
|
|
@@ -42864,6 +43058,9 @@ async function meteredCall(analyst, kind, args, prompt, parse, opts = {}) {
|
|
|
42864
43058
|
${run.stderr}`.trim().split(/\r?\n/)[0]?.slice(0, 200) ?? "";
|
|
42865
43059
|
return fail(`${analyst.slug} hit a ${hit.kind === "rate" ? "rate" : "usage"} limit${said ? `: ${said}` : ""}`, hit);
|
|
42866
43060
|
}
|
|
43061
|
+
const failure = failureOf2(analyst, run);
|
|
43062
|
+
if (failure)
|
|
43063
|
+
return fail(failure.message, null, failure.reachedModel);
|
|
42867
43064
|
if (!run.stdout.trim()) {
|
|
42868
43065
|
return fail(`${analyst.command} exited ${run.exitCode} with no output${run.stderr ? `: ${run.stderr.slice(0, 300)}` : ""}`, null);
|
|
42869
43066
|
}
|
|
@@ -42885,6 +43082,8 @@ async function runPeriodicAnalysis(candidates, prompt, deps = {}) {
|
|
|
42885
43082
|
const tried = new Set;
|
|
42886
43083
|
const next = (only) => {
|
|
42887
43084
|
const exclude = new Set(only ? candidates.filter((c) => c.slug !== only.slug).map((c) => c.slug) : tried);
|
|
43085
|
+
if (candidates.every((c) => exclude.has(c.slug)))
|
|
43086
|
+
return null;
|
|
42888
43087
|
if (!deps.scheduler)
|
|
42889
43088
|
return candidates.find((c) => !exclude.has(c.slug)) ?? null;
|
|
42890
43089
|
const admitted = deps.scheduler.admit("periodic", exclude);
|
|
@@ -43152,19 +43351,8 @@ function consumeImportedConversation() {
|
|
|
43152
43351
|
return false;
|
|
43153
43352
|
}
|
|
43154
43353
|
}
|
|
43155
|
-
function
|
|
43156
|
-
|
|
43157
|
-
case "runwork-disabled":
|
|
43158
|
-
return "your AI plan hit its usage limit twice this week, so automatic reflection is off (runwork reflect --enable-auto turns it back on)";
|
|
43159
|
-
case "paused":
|
|
43160
|
-
return "your agent reported a usage limit and is paused until it resets";
|
|
43161
|
-
case "no-plan-budget":
|
|
43162
|
-
return "your AI plan leaves no room for automatic reflection";
|
|
43163
|
-
case "window-full":
|
|
43164
|
-
return "this 5-hour window already had its share of reflection calls";
|
|
43165
|
-
case "day-cap":
|
|
43166
|
-
return "today's share of analyses is used up";
|
|
43167
|
-
}
|
|
43354
|
+
function terminalReason(reason, ctx = {}) {
|
|
43355
|
+
return describeAnalysisReason(reason, { ...ctx, terminal: true });
|
|
43168
43356
|
}
|
|
43169
43357
|
function printInsight(i) {
|
|
43170
43358
|
console.log(bold(`
|
|
@@ -43201,7 +43389,7 @@ Runwork is the team's shared AI-work platform. Every capability below syncs acro
|
|
|
43201
43389
|
- connect-tool: an AI tool not yet connected to the workspace via Runwork sync/MCP.
|
|
43202
43390
|
- active-in-ai: general working habits in AI tools; use sparingly.
|
|
43203
43391
|
|
|
43204
|
-
Also part of the platform (fold into the closest capability above): team file storage (upload/serve files instead of local paths), AI agents that run headless tasks in the cloud, MCP servers distributed to the whole team, and team instructions that steer every member's agents.`, SUMMARY_MAX_CHATS = 120, SUMMARY_MAX_PATTERNS = 40, SUMMARY_MAX_INSIGHTS = 40, UNREADABLE_OUTPUT_CHARS = 500, reflectCommand;
|
|
43392
|
+
Also part of the platform (fold into the closest capability above): team file storage (upload/serve files instead of local paths), AI agents that run headless tasks in the cloud, MCP servers distributed to the whole team, and team instructions that steer every member's agents.`, SUMMARY_MAX_CHATS = 120, SUMMARY_MAX_PATTERNS = 40, SUMMARY_MAX_INSIGHTS = 40, AnalystLaunchError, UNREADABLE_OUTPUT_CHARS = 500, reflectCommand;
|
|
43205
43393
|
var init_reflect = __esm(async () => {
|
|
43206
43394
|
init_subprocess();
|
|
43207
43395
|
init_which();
|
|
@@ -43218,6 +43406,7 @@ var init_reflect = __esm(async () => {
|
|
|
43218
43406
|
init_atomic_json();
|
|
43219
43407
|
init_colors();
|
|
43220
43408
|
init_output();
|
|
43409
|
+
init_analysis_reasons();
|
|
43221
43410
|
await __promiseAll([
|
|
43222
43411
|
init_acting(),
|
|
43223
43412
|
init_client(),
|
|
@@ -43241,6 +43430,8 @@ var init_reflect = __esm(async () => {
|
|
|
43241
43430
|
"register-component",
|
|
43242
43431
|
"build-endpoint"
|
|
43243
43432
|
];
|
|
43433
|
+
AnalystLaunchError = class AnalystLaunchError extends Error {
|
|
43434
|
+
};
|
|
43244
43435
|
reflectCommand = new Command18("reflect").description("Weekly reflection: analyze your local AI agent usage on-device and surface patterns").option("--days <n>", "Look back this many days", "7").option("--analyst <slug>", "Agent that runs the analysis, by registry slug. Default: first available").option("--digest-only", "Build and print the summary the reflection reads (verdicts, recurring work, suggestions) only").option("--prompt-only", "Print the full reflection prompt and stop (run the analyst yourself)").option("--out <dir>", "Write summary.md, prompt.md, reflection.md, evidence.json to this directory").option("--no-sync", "Do not sync insight metadata to the server (keep everything local)").option("--if-due", "Only reflect when cadence says it is due AND auto-reflect is enabled (for automation)").option("--full", "Re-analyze the whole window even if a recent reflection already covered part of it").option("--enable-auto", "Turn on cadence-driven automatic reflection, then exit").option("--disable-auto", "Turn off cadence-driven automatic reflection, then exit").option("--import [file]", "Save a reflection you ran yourself: paste the agent's answer (reads stdin when no file is given)").action(async (opts, command) => {
|
|
43245
43436
|
const json = command.optsWithGlobals().json === true;
|
|
43246
43437
|
if (opts.import !== undefined) {
|
|
@@ -43285,18 +43476,20 @@ Reflection over the last ${days} days`));
|
|
|
43285
43476
|
jsonOut({ insights: [], reason: "no-sessions" });
|
|
43286
43477
|
return;
|
|
43287
43478
|
}
|
|
43288
|
-
console.error(yellow(
|
|
43479
|
+
console.error(yellow(`
|
|
43480
|
+
${terminalReason("no-sessions")}`));
|
|
43289
43481
|
return;
|
|
43290
43482
|
}
|
|
43291
43483
|
if (opts.ifDue) {
|
|
43292
43484
|
const cadence = loadCadenceState();
|
|
43293
43485
|
if (!cadence.enabled || !isReflectionDue(cadence, windowChats.length)) {
|
|
43486
|
+
const reason = cadence.enabled ? "not-due" : "auto-disabled";
|
|
43294
43487
|
if (json) {
|
|
43295
|
-
jsonOut({ insights: [], reason
|
|
43488
|
+
jsonOut({ insights: [], reason });
|
|
43296
43489
|
return;
|
|
43297
43490
|
}
|
|
43298
43491
|
console.error(gray(`
|
|
43299
|
-
|
|
43492
|
+
${terminalReason(reason)}`));
|
|
43300
43493
|
return;
|
|
43301
43494
|
}
|
|
43302
43495
|
await Promise.resolve().then(() => init_run_log());
|
|
@@ -43307,7 +43500,7 @@ Skipping: ${cadence.enabled ? "not enough new work since the last reflection" :
|
|
|
43307
43500
|
return;
|
|
43308
43501
|
}
|
|
43309
43502
|
console.error(gray(`
|
|
43310
|
-
|
|
43503
|
+
${terminalReason("run-in-progress")}`));
|
|
43311
43504
|
return;
|
|
43312
43505
|
}
|
|
43313
43506
|
}
|
|
@@ -43336,7 +43529,7 @@ Skipping: another analysis is already running on this machine.`));
|
|
|
43336
43529
|
return;
|
|
43337
43530
|
}
|
|
43338
43531
|
console.error(yellow(`
|
|
43339
|
-
|
|
43532
|
+
${terminalReason("workspace-disabled")}`));
|
|
43340
43533
|
return;
|
|
43341
43534
|
}
|
|
43342
43535
|
}
|
|
@@ -43387,7 +43580,7 @@ ${brokenAnalysts.map((b) => ` ${b}: on PATH but it will not run, so its install
|
|
|
43387
43580
|
The prompt is saved at:
|
|
43388
43581
|
${promptPath}
|
|
43389
43582
|
Paste it into any AI agent you have to get this reflection.` : "";
|
|
43390
|
-
const hint =
|
|
43583
|
+
const hint = `${terminalReason("no-analyst")}${brokenNote}${savedNote}
|
|
43391
43584
|
|
|
43392
43585
|
Or re-run with --prompt-only (or --out <dir>) to print it:
|
|
43393
43586
|
runwork reflect --out ./reflection
|
|
@@ -43404,12 +43597,13 @@ ${hint}`));
|
|
|
43404
43597
|
const gate = scheduler.admit("periodic");
|
|
43405
43598
|
if ("refused" in gate) {
|
|
43406
43599
|
const reason = REFUSAL_REASONS[gate.refused];
|
|
43600
|
+
const windowFreesAt = scheduler.windowFreesAt();
|
|
43407
43601
|
if (json) {
|
|
43408
|
-
jsonOut({ insights: [], reason });
|
|
43602
|
+
jsonOut({ insights: [], reason, ...windowFreesAt ? { windowFreesAt } : {} });
|
|
43409
43603
|
return;
|
|
43410
43604
|
}
|
|
43411
43605
|
console.error(gray(`
|
|
43412
|
-
|
|
43606
|
+
${terminalReason(reason, { windowFreesAt })}`));
|
|
43413
43607
|
return;
|
|
43414
43608
|
}
|
|
43415
43609
|
if (!json)
|
|
@@ -43437,7 +43631,7 @@ Analyzing with ${gate.analyst.slug} (your own agent, on-device)...`));
|
|
|
43437
43631
|
return;
|
|
43438
43632
|
}
|
|
43439
43633
|
console.error(yellow(`
|
|
43440
|
-
|
|
43634
|
+
${terminalReason("run-in-progress")}`));
|
|
43441
43635
|
return;
|
|
43442
43636
|
}
|
|
43443
43637
|
let reflectionText;
|
|
@@ -43466,6 +43660,7 @@ ${note}`));
|
|
|
43466
43660
|
}
|
|
43467
43661
|
} else if (analysis.limitHits > 0 || analysis.refused) {
|
|
43468
43662
|
const reason = analysis.refused ? REFUSAL_REASONS[analysis.refused] : "limit-reached";
|
|
43663
|
+
const windowFreesAt = scheduler.windowFreesAt();
|
|
43469
43664
|
runEntry.status = "failed";
|
|
43470
43665
|
runEntry.analystError = summarizeAnalystError(failures.join("; ") || reason);
|
|
43471
43666
|
runEntry.failed = 1;
|
|
@@ -43474,11 +43669,11 @@ ${note}`));
|
|
|
43474
43669
|
saveRun(runEntry);
|
|
43475
43670
|
} catch {}
|
|
43476
43671
|
if (json) {
|
|
43477
|
-
jsonOut({ insights: [], reason });
|
|
43672
|
+
jsonOut({ insights: [], reason, ...windowFreesAt ? { windowFreesAt } : {} });
|
|
43478
43673
|
return;
|
|
43479
43674
|
}
|
|
43480
43675
|
console.error(yellow(`
|
|
43481
|
-
|
|
43676
|
+
${terminalReason(reason, { windowFreesAt })}`));
|
|
43482
43677
|
return;
|
|
43483
43678
|
} else {
|
|
43484
43679
|
const e = failures.join("; ") || "no analyst produced output";
|
|
@@ -44358,6 +44553,53 @@ var init_triage = __esm(async () => {
|
|
|
44358
44553
|
TASK_TYPES = ["build", "automate", "analyze", "write", "research", "admin", "debug"];
|
|
44359
44554
|
});
|
|
44360
44555
|
|
|
44556
|
+
// src/reflect/unspent-analyses.ts
|
|
44557
|
+
function isUnspentAnalysisRun(r) {
|
|
44558
|
+
return (r.kind === "per-conversation" || r.kind === "history") && r.completed > 0 && r.insights === 0 && r.inputTokens === 0 && r.outputTokens === 0 && r.costUSD === 0 && (r.models?.length ?? 0) === 0;
|
|
44559
|
+
}
|
|
44560
|
+
function reopenUnspentAnalyses(now = new Date) {
|
|
44561
|
+
const spans = loadRunLog().filter(isUnspentAnalysisRun).map((r) => ({ from: Date.parse(r.startedAt), to: Date.parse(r.updatedAt) }));
|
|
44562
|
+
if (spans.length === 0)
|
|
44563
|
+
return [];
|
|
44564
|
+
markCallsUnreached(spans);
|
|
44565
|
+
const inSpan = (at) => {
|
|
44566
|
+
const t = Date.parse(at);
|
|
44567
|
+
return spans.some((s) => t >= s.from && t <= s.to);
|
|
44568
|
+
};
|
|
44569
|
+
const census = loadCensusStore();
|
|
44570
|
+
const levels = new Map;
|
|
44571
|
+
for (const [key, record] of Object.entries(census.sessions)) {
|
|
44572
|
+
const v = record.triage;
|
|
44573
|
+
if (!isCensusTriageVerdict(v) || !v.analyzedAt || !inSpan(v.analyzedAt))
|
|
44574
|
+
continue;
|
|
44575
|
+
const { analyzedAt: _unspent, ...open } = v;
|
|
44576
|
+
census.sessions[key] = { ...record, triage: { ...open, reopenedAt: now.toISOString() } };
|
|
44577
|
+
levels.set(key, v.at);
|
|
44578
|
+
}
|
|
44579
|
+
if (levels.size === 0)
|
|
44580
|
+
return [];
|
|
44581
|
+
saveCensusStore(census);
|
|
44582
|
+
const queue = loadQueueState();
|
|
44583
|
+
let queueChanged = false;
|
|
44584
|
+
for (const [key, level] of levels) {
|
|
44585
|
+
const e = queue.entries[key];
|
|
44586
|
+
if (!e || e.status !== "done" || e.doneReason !== "analyzed" || e.doneActivityAt !== level)
|
|
44587
|
+
continue;
|
|
44588
|
+
const { doneReason: _reason, doneActivityAt: _level, ...rest } = e;
|
|
44589
|
+
queue.entries[key] = { ...rest, status: "pending" };
|
|
44590
|
+
queueChanged = true;
|
|
44591
|
+
}
|
|
44592
|
+
if (queueChanged)
|
|
44593
|
+
saveQueueState(queue);
|
|
44594
|
+
return [...levels.keys()];
|
|
44595
|
+
}
|
|
44596
|
+
var init_unspent_analyses = __esm(async () => {
|
|
44597
|
+
init_conversation_queue();
|
|
44598
|
+
init_quota_policy();
|
|
44599
|
+
init_run_log();
|
|
44600
|
+
await init_asset_census();
|
|
44601
|
+
});
|
|
44602
|
+
|
|
44361
44603
|
// src/reflect/conversation-analysis.ts
|
|
44362
44604
|
import { existsSync as existsSync77 } from "fs";
|
|
44363
44605
|
import { basename as basename14 } from "path";
|
|
@@ -44374,7 +44616,8 @@ function tier2Roster() {
|
|
|
44374
44616
|
cheap: structured.cheap,
|
|
44375
44617
|
...a.prepareArgs ? { prepareArgs: a.prepareArgs } : {},
|
|
44376
44618
|
...a.readQuota ? { readQuota: a.readQuota } : {},
|
|
44377
|
-
...a.limitHit ? { limitHit: a.limitHit } : {}
|
|
44619
|
+
...a.limitHit ? { limitHit: a.limitHit } : {},
|
|
44620
|
+
...structured.failure ? { failure: structured.failure } : {}
|
|
44378
44621
|
}];
|
|
44379
44622
|
});
|
|
44380
44623
|
}
|
|
@@ -44615,7 +44858,7 @@ function deepRunner(run, tally, deps) {
|
|
|
44615
44858
|
const startedAt = new Date().toISOString();
|
|
44616
44859
|
const startedMs = Date.now();
|
|
44617
44860
|
const triedHere = new Set;
|
|
44618
|
-
let
|
|
44861
|
+
let usedAttempt = false;
|
|
44619
44862
|
let lastError;
|
|
44620
44863
|
for (;; ) {
|
|
44621
44864
|
if (deps.explicitAnalyst && triedHere.size > 0)
|
|
@@ -44640,7 +44883,8 @@ function deepRunner(run, tally, deps) {
|
|
|
44640
44883
|
if (!result.ok) {
|
|
44641
44884
|
lastError = result.error;
|
|
44642
44885
|
if (!result.hit) {
|
|
44643
|
-
|
|
44886
|
+
if (result.reachedModel)
|
|
44887
|
+
usedAttempt = true;
|
|
44644
44888
|
consumption.analystsFailed.add(analyst.slug);
|
|
44645
44889
|
}
|
|
44646
44890
|
continue;
|
|
@@ -44713,7 +44957,7 @@ function deepRunner(run, tally, deps) {
|
|
|
44713
44957
|
const triedNote = triedHere.size > 1 ? ` (tried ${[...triedHere].join(", ")})` : "";
|
|
44714
44958
|
progress(` -> failed after ${Math.round((Date.now() - startedMs) / 1000)}s${attemptNote}${triedNote}`);
|
|
44715
44959
|
checkpoint();
|
|
44716
|
-
return { status: "failed",
|
|
44960
|
+
return { status: "failed", usedAttempt };
|
|
44717
44961
|
};
|
|
44718
44962
|
return {
|
|
44719
44963
|
analyze,
|
|
@@ -44722,8 +44966,9 @@ function deepRunner(run, tally, deps) {
|
|
|
44722
44966
|
get started() {
|
|
44723
44967
|
return started;
|
|
44724
44968
|
},
|
|
44725
|
-
noteFailedAnalyst: (slug) => {
|
|
44969
|
+
noteFailedAnalyst: (slug, error) => {
|
|
44726
44970
|
consumption.analystsFailed.add(slug);
|
|
44971
|
+
run.analystError = summarizeAnalystError(error);
|
|
44727
44972
|
},
|
|
44728
44973
|
attachTriage: (summary, triagedOut) => {
|
|
44729
44974
|
triage = triage ? { ...triage, batches: triage.batches + summary.batches, inputTokens: triage.inputTokens + summary.inputTokens, outputTokens: triage.outputTokens + summary.outputTokens, triagedOut: triage.triagedOut + triagedOut } : { ...summary, triagedOut };
|
|
@@ -44958,7 +45203,7 @@ async function runSelector(deps) {
|
|
|
44958
45203
|
const invocation = triageInvocation(analyst, deps.hints);
|
|
44959
45204
|
if (invocation) {
|
|
44960
45205
|
let result = await meteredCall(analyst, "triage", invocation.args, prompt, analyst.parse, { scheduler, timeoutMs: TRIAGE_TIMEOUT_MS });
|
|
44961
|
-
if (!result.ok && !result.hit && invocation.fallbackArgs) {
|
|
45206
|
+
if (!result.ok && !result.hit && result.reachedModel && invocation.fallbackArgs) {
|
|
44962
45207
|
const only = analyst.slug;
|
|
44963
45208
|
const again = scheduler.admit("triage", new Set(deps.analysts.filter((a) => a.slug !== only).map((a) => a.slug)));
|
|
44964
45209
|
if ("analyst" in again) {
|
|
@@ -44968,7 +45213,7 @@ async function runSelector(deps) {
|
|
|
44968
45213
|
if (result.ok)
|
|
44969
45214
|
return { analyst: analyst.slug, parsed: result.value };
|
|
44970
45215
|
if (!result.hit)
|
|
44971
|
-
runner.noteFailedAnalyst(analyst.slug);
|
|
45216
|
+
runner.noteFailedAnalyst(analyst.slug, result.error);
|
|
44972
45217
|
}
|
|
44973
45218
|
triageFailed.add(analyst.slug);
|
|
44974
45219
|
const next = scheduler.admit("triage", triageFailed);
|
|
@@ -45067,7 +45312,7 @@ async function runSelector(deps) {
|
|
|
45067
45312
|
queueDone(pick.key, pick.lastActivityAt, "analyzed");
|
|
45068
45313
|
return true;
|
|
45069
45314
|
}
|
|
45070
|
-
if (
|
|
45315
|
+
if (result.usedAttempt) {
|
|
45071
45316
|
pick.attempts++;
|
|
45072
45317
|
if (pick.verdict)
|
|
45073
45318
|
updateCensusVerdict(pick.key, pick.lastActivityAt, (v) => ({ ...v ?? { worthy: true, confidence: 0.5, at: pick.lastActivityAt }, deepAttempts: pick.attempts }));
|
|
@@ -45097,6 +45342,21 @@ async function runSelector(deps) {
|
|
|
45097
45342
|
function runDeepCap(opts) {
|
|
45098
45343
|
return opts.budget ?? Number.MAX_SAFE_INTEGER;
|
|
45099
45344
|
}
|
|
45345
|
+
function windowFailure(nowMs) {
|
|
45346
|
+
const newest = loadRunLog().find((r) => nowMs - Date.parse(r.updatedAt) < CALL_WINDOW_MS);
|
|
45347
|
+
return newest && (newest.status === "failed" || newest.status === "blocked") ? newest.analystError : undefined;
|
|
45348
|
+
}
|
|
45349
|
+
function refuseOutcome(outcome, refused, scheduler) {
|
|
45350
|
+
outcome.reason = REFUSAL_REASONS[refused];
|
|
45351
|
+
if (refused !== "window-full")
|
|
45352
|
+
return;
|
|
45353
|
+
const freesAt = scheduler.windowFreesAt();
|
|
45354
|
+
if (freesAt)
|
|
45355
|
+
outcome.windowFreesAt = freesAt;
|
|
45356
|
+
const failure = windowFailure(Date.now());
|
|
45357
|
+
if (failure)
|
|
45358
|
+
outcome.analystError = failure;
|
|
45359
|
+
}
|
|
45100
45360
|
async function analyzeConversationsLocked(opts, outcome, gates) {
|
|
45101
45361
|
const { explicitSession, manual } = gates;
|
|
45102
45362
|
const cadence = loadCadenceState();
|
|
@@ -45162,6 +45422,9 @@ async function analyzeConversationsLocked(opts, outcome, gates) {
|
|
|
45162
45422
|
return outcome;
|
|
45163
45423
|
}
|
|
45164
45424
|
const progress = opts.onProgress ?? (() => {});
|
|
45425
|
+
const reopened = reopenUnspentAnalyses();
|
|
45426
|
+
if (reopened.length > 0)
|
|
45427
|
+
progress(`${reopened.length} conversation(s) marked analyzed while the agent could not reach its model are open again.`);
|
|
45165
45428
|
const userSeed = (() => {
|
|
45166
45429
|
try {
|
|
45167
45430
|
return requireAuth().email;
|
|
@@ -45233,9 +45496,9 @@ async function analyzeConversationsLocked(opts, outcome, gates) {
|
|
|
45233
45496
|
const analyzedAt = new Date().toISOString();
|
|
45234
45497
|
updateCensusVerdict(key, level, (v) => ({ ...v ?? { worthy: true, confidence: 0.5, at: level }, analyzedAt }));
|
|
45235
45498
|
} else if (result.status === "failed") {
|
|
45236
|
-
state = { entries: { ...state.entries, [key]: { ...entry, attempts: 1 } } };
|
|
45499
|
+
state = { entries: { ...state.entries, [key]: { ...entry, attempts: result.usedAttempt ? 1 : 0 } } };
|
|
45237
45500
|
} else {
|
|
45238
|
-
outcome
|
|
45501
|
+
refuseOutcome(outcome, result.refused, scheduler);
|
|
45239
45502
|
}
|
|
45240
45503
|
}
|
|
45241
45504
|
saveQueueState(state);
|
|
@@ -45243,7 +45506,7 @@ async function analyzeConversationsLocked(opts, outcome, gates) {
|
|
|
45243
45506
|
const deepGate = scheduler.admit("deep");
|
|
45244
45507
|
const triageGate = scheduler.admit("triage");
|
|
45245
45508
|
if ("refused" in deepGate && "refused" in triageGate) {
|
|
45246
|
-
outcome
|
|
45509
|
+
refuseOutcome(outcome, deepGate.refused, scheduler);
|
|
45247
45510
|
outcome.pendingLeft = pendingLeft();
|
|
45248
45511
|
return outcome;
|
|
45249
45512
|
}
|
|
@@ -45263,14 +45526,19 @@ async function analyzeConversationsLocked(opts, outcome, gates) {
|
|
|
45263
45526
|
progress
|
|
45264
45527
|
});
|
|
45265
45528
|
if (!runner.started) {
|
|
45266
|
-
|
|
45529
|
+
if (refused)
|
|
45530
|
+
refuseOutcome(outcome, refused, scheduler);
|
|
45531
|
+
else
|
|
45532
|
+
outcome.reason = "nothing-pending";
|
|
45267
45533
|
outcome.pendingLeft = pendingLeft();
|
|
45268
45534
|
return outcome;
|
|
45269
45535
|
}
|
|
45270
45536
|
}
|
|
45271
45537
|
outcome.pendingLeft = pendingLeft();
|
|
45272
45538
|
if (runner.started) {
|
|
45273
|
-
run.status = outcome.analyzed.length === 0 && outcome.failed > 0 ? "failed" : "done";
|
|
45539
|
+
run.status = outcome.analyzed.length === 0 && (outcome.failed > 0 || run.analystError !== undefined) ? "failed" : "done";
|
|
45540
|
+
if (run.analystError)
|
|
45541
|
+
outcome.analystError = run.analystError;
|
|
45274
45542
|
run.finishedAt = new Date().toISOString();
|
|
45275
45543
|
delete run.currentKey;
|
|
45276
45544
|
runner.checkpoint();
|
|
@@ -45278,31 +45546,13 @@ async function analyzeConversationsLocked(opts, outcome, gates) {
|
|
|
45278
45546
|
return outcome;
|
|
45279
45547
|
}
|
|
45280
45548
|
function describeAnalysisOutcome(o) {
|
|
45281
|
-
|
|
45282
|
-
|
|
45283
|
-
|
|
45284
|
-
return "Reflection is turned off for this workspace by an admin.";
|
|
45285
|
-
if (o.reason === "no-analyst")
|
|
45286
|
-
return "No analyst agent could run the analysis. If an analyst agent is installed, it may need signing in or reinstalling.";
|
|
45287
|
-
if (o.reason === "budget-exhausted")
|
|
45288
|
-
return `Today's share of analyses is used up; ${o.pendingLeft} conversation(s) wait for tomorrow.`;
|
|
45289
|
-
if (o.reason === "window-full")
|
|
45290
|
-
return "This 5-hour window already had its share of analysis calls; the rest waits for the next one.";
|
|
45291
|
-
if (o.reason === "quota-paused")
|
|
45292
|
-
return "Your agent reported a usage limit; analysis waits until it resets.";
|
|
45293
|
-
if (o.reason === "quota-disabled")
|
|
45294
|
-
return "Your AI plan hit its usage limit twice this week, so automatic reflection is off. Turn it back on with runwork reflect --enable-auto.";
|
|
45295
|
-
if (o.reason === "no-plan-budget")
|
|
45296
|
-
return "Your AI plan leaves no room for automatic analysis.";
|
|
45297
|
-
if (o.reason === "nothing-pending")
|
|
45298
|
-
return "No finished conversations waiting for analysis.";
|
|
45299
|
-
if (o.reason === "session-not-found")
|
|
45300
|
-
return "That conversation is not in the local registry.";
|
|
45301
|
-
if (o.reason === "run-in-progress")
|
|
45302
|
-
return "Another analysis is already running on this machine.";
|
|
45549
|
+
const stop = describeAnalysisStop(o, { terminal: true });
|
|
45550
|
+
if (o.reason)
|
|
45551
|
+
return o.reason === "auto-disabled" ? `${stop} Or run it now with --force.` : `${stop}`;
|
|
45303
45552
|
const insights = o.analyzed.reduce((s, a) => s + a.insights, 0);
|
|
45304
45553
|
const triaged = o.triaged > 0 ? `, ${o.triaged} triaged (${o.triagedOut} not worth a closer look)` : "";
|
|
45305
|
-
|
|
45554
|
+
const counts = `Analyzed ${o.analyzed.length} conversation(s): ${insights} insight(s)${triaged}, ${o.gated} gated, ${o.failed} failed, ${o.pendingLeft} still pending.`;
|
|
45555
|
+
return stop ? `${counts} ${stop}` : counts;
|
|
45306
45556
|
}
|
|
45307
45557
|
var MIN_USER_MESSAGES = 2, MAX_ANALYSIS_ATTEMPTS = 3, CANDIDATE_HORIZONS_DAYS, HANDFUL_OF_CANDIDATES = 5, RECENCY_SCALE_DAYS = 14, DAY_MS2, TIER2_ANALYSTS, CENSUS_MAX_FILES = 30;
|
|
45308
45558
|
var init_conversation_analysis = __esm(async () => {
|
|
@@ -45316,6 +45566,7 @@ var init_conversation_analysis = __esm(async () => {
|
|
|
45316
45566
|
init_setup_state();
|
|
45317
45567
|
init_run_log();
|
|
45318
45568
|
init_quota_policy();
|
|
45569
|
+
init_analysis_reasons();
|
|
45319
45570
|
init_session_digest();
|
|
45320
45571
|
init_insight_store();
|
|
45321
45572
|
await __promiseAll([
|
|
@@ -45329,6 +45580,7 @@ var init_conversation_analysis = __esm(async () => {
|
|
|
45329
45580
|
init_pattern_store(),
|
|
45330
45581
|
init_desk_backfill(),
|
|
45331
45582
|
init_space_mappings(),
|
|
45583
|
+
init_unspent_analyses(),
|
|
45332
45584
|
init_reflect()
|
|
45333
45585
|
]);
|
|
45334
45586
|
CANDIDATE_HORIZONS_DAYS = [30, 60, 90];
|
|
@@ -45963,7 +46215,8 @@ Conversation sources`));
|
|
|
45963
46215
|
jsonOut(outcome);
|
|
45964
46216
|
return;
|
|
45965
46217
|
}
|
|
45966
|
-
|
|
46218
|
+
const ranOk = !outcome.reason && !(outcome.analyzed.length === 0 && outcome.analystError);
|
|
46219
|
+
console.log(ranOk ? green(describeAnalysisOutcome(outcome)) : dim(describeAnalysisOutcome(outcome)));
|
|
45967
46220
|
});
|
|
45968
46221
|
conversationsCommand.command("stores").description("Every local transcript store: what is in it, who wrote it, and whether anything reads it").option("--max-files <n>", "Cap transcripts inspected per store", String(DEFAULT_MAX_FILES)).option("--no-markers", "Skip provenance reads; counts, sizes and mtimes only").action(async (opts, command) => {
|
|
45969
46222
|
const json = command.optsWithGlobals().json === true || !process.stdout.isTTY;
|
|
@@ -50362,7 +50615,7 @@ function fail5(message) {
|
|
|
50362
50615
|
function atTerminal2(useJson) {
|
|
50363
50616
|
return !useJson && Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
50364
50617
|
}
|
|
50365
|
-
function
|
|
50618
|
+
function failureOf3(err, baseUrl) {
|
|
50366
50619
|
return unreachableMessage(err, baseUrl) ?? (err instanceof Error ? err.message : String(err));
|
|
50367
50620
|
}
|
|
50368
50621
|
function isAuthChoice(value) {
|
|
@@ -50420,7 +50673,7 @@ async function addMcpIntegration(context, body, extra = {}) {
|
|
|
50420
50673
|
try {
|
|
50421
50674
|
added = await client.createCustomIntegration(workspaceId, body);
|
|
50422
50675
|
} catch (err) {
|
|
50423
|
-
fail5(`Could not add "${body.displayName}": ${
|
|
50676
|
+
fail5(`Could not add "${body.displayName}": ${failureOf3(err, baseUrl)}`);
|
|
50424
50677
|
}
|
|
50425
50678
|
const { integration } = added;
|
|
50426
50679
|
if (useJson) {
|
|
@@ -50524,7 +50777,7 @@ Workspace: ${workspaceName || workspaceId}
|
|
|
50524
50777
|
}
|
|
50525
50778
|
console.log("");
|
|
50526
50779
|
} catch (err) {
|
|
50527
|
-
fail5(`Failed to list MCP servers: ${
|
|
50780
|
+
fail5(`Failed to list MCP servers: ${failureOf3(err, baseUrl)}`);
|
|
50528
50781
|
}
|
|
50529
50782
|
});
|
|
50530
50783
|
addCommand = withAuthOptions(new Command33("add").description("Add an MCP server to your workspace as an integration, which AI tools reach through Runwork").argument("<name>", "The name people and AI tools see it under").argument("<url>", "The server's Streamable HTTP address (https)"), "none").option("--workspace <name-or-id>", "Workspace name or ID").action(async (name, url, opts, command) => {
|
|
@@ -50543,7 +50796,7 @@ Workspace: ${workspaceName || workspaceId}
|
|
|
50543
50796
|
try {
|
|
50544
50797
|
listed = await client.listWorkspaceOAuthClients(workspaceId);
|
|
50545
50798
|
} catch (err) {
|
|
50546
|
-
fail5(`Failed to read the workspace's integrations: ${
|
|
50799
|
+
fail5(`Failed to read the workspace's integrations: ${failureOf3(err, baseUrl)}`);
|
|
50547
50800
|
}
|
|
50548
50801
|
const picked = pickCustomIntegration(listed.customIntegrations ?? [], named);
|
|
50549
50802
|
if (picked && "problem" in picked)
|
|
@@ -50574,7 +50827,7 @@ Workspace: ${workspaceName || workspaceId}
|
|
|
50574
50827
|
console.log(`Removed the MCP server "${picked.displayName}".`);
|
|
50575
50828
|
console.log("Run `runwork sync` to update your local AI tools.");
|
|
50576
50829
|
} catch (err) {
|
|
50577
|
-
fail5(`Could not remove "${picked.displayName}": ${
|
|
50830
|
+
fail5(`Could not remove "${picked.displayName}": ${failureOf3(err, baseUrl)}`);
|
|
50578
50831
|
}
|
|
50579
50832
|
});
|
|
50580
50833
|
searchCommand3 = new Command33("search").description("Search community MCP servers: searches the MCP Registry through Runwork, so it needs a connection to Runwork").argument("<query>", "Search query").option("--limit <n>", "Max results (1-50)", "10").action(async (query, opts, command) => {
|
|
@@ -50616,7 +50869,7 @@ Workspace: ${workspaceName || workspaceId}
|
|
|
50616
50869
|
try {
|
|
50617
50870
|
found = (await client.searchCommunityMcpServers(query, 5)).servers[0];
|
|
50618
50871
|
} catch (err) {
|
|
50619
|
-
fail5(`Search failed: ${
|
|
50872
|
+
fail5(`Search failed: ${failureOf3(err, baseUrl)}`);
|
|
50620
50873
|
}
|
|
50621
50874
|
if (!found)
|
|
50622
50875
|
fail5(`No remote-capable MCP servers found for "${query}".`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "runwork",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "CLI for Runwork: develop, preview, and deploy Runwork apps from your local machine.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "Runwork, Inc. <info@runwork.ai> (https://www.runwork.ai)",
|