atris 3.74.18 → 3.74.19

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/bin/atris.js CHANGED
@@ -1197,7 +1197,7 @@ const { runOrb: orbCmd } = require('../commands/orb');
1197
1197
  if (command === '2' && ['fast', 'pro'].includes(String(firstCommandArg || '').toLowerCase())) {
1198
1198
  const userInput = process.argv.slice(2).join(' ');
1199
1199
  planCmd(userInput)
1200
- .then(() => process.exit(0))
1200
+ .then(() => exitAfterStdoutDrain(0))
1201
1201
  .catch((error) => {
1202
1202
  console.error(`✗ Atris 2 failed: ${error.message || error}`);
1203
1203
  process.exit(1);
@@ -1336,7 +1336,7 @@ if (!command || !knownCommands.includes(command)) {
1336
1336
  optionError: natural.error,
1337
1337
  firstMinuteAlias,
1338
1338
  })
1339
- .then((code) => process.exit(Number.isInteger(code) ? code : 0))
1339
+ .then((code) => exitAfterStdoutDrain(Number.isInteger(code) ? code : 0))
1340
1340
  .catch((error) => {
1341
1341
  console.error(`✗ Error: ${error.message || error}`);
1342
1342
  process.exit(1);
@@ -2018,7 +2018,7 @@ if (command === 'guide') {
2018
2018
  initCmd();
2019
2019
  // Flow directly into interactive prompt
2020
2020
  interactiveEntry()
2021
- .then(() => process.exit(0))
2021
+ .then(() => exitAfterStdoutDrain(0))
2022
2022
  .catch((error) => {
2023
2023
  console.error(`✗ Error: ${error.message || error}`);
2024
2024
  process.exit(1);
@@ -2030,11 +2030,11 @@ if (command === 'guide') {
2030
2030
  } else if (command === 'task') {
2031
2031
  // SQLite-backed task plane. ~/.atris/tasks.db, gitignored, per-workspace.
2032
2032
  Promise.resolve().then(() => require('../commands/task').run(process.argv.slice(3)))
2033
- .then(() => process.exit(0))
2033
+ .then(() => exitAfterStdoutDrain(0))
2034
2034
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2035
2035
  } else if (command === 'team') {
2036
2036
  Promise.resolve().then(() => require('../commands/team').teamCommand(process.argv.slice(3)))
2037
- .then((code) => process.exit(code || 0))
2037
+ .then((code) => exitAfterStdoutDrain(code || 0))
2038
2038
  .catch((err) => { console.error(`\nerror: ${err.message || err}`); process.exit(1); });
2039
2039
  } else if (command === 'campaign') {
2040
2040
  Promise.resolve().then(() => require('../commands/campaign').campaignCommand(process.argv.slice(3)))
@@ -2042,19 +2042,19 @@ if (command === 'guide') {
2042
2042
  .catch((err) => { console.error(`\nerror: ${err.message || err}`); process.exit(1); });
2043
2043
  } else if (command === 'who') {
2044
2044
  Promise.resolve().then(() => require('../commands/who').whoCommand(process.argv.slice(3)))
2045
- .then((code) => process.exit(code || 0))
2045
+ .then((code) => exitAfterStdoutDrain(code || 0))
2046
2046
  .catch((err) => { console.error(`\nerror: ${err.message || err}`); process.exit(1); });
2047
2047
  } else if (command === 'wish') {
2048
2048
  Promise.resolve().then(() => require('../commands/wish').wishCommand(process.argv.slice(3)))
2049
- .then((code) => process.exit(code || 0))
2049
+ .then((code) => exitAfterStdoutDrain(code || 0))
2050
2050
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2051
2051
  } else if (command === 'drill') {
2052
2052
  Promise.resolve().then(() => require('../commands/drill').drillCommand(process.argv.slice(3)))
2053
- .then((code) => process.exit(code || 0))
2053
+ .then((code) => exitAfterStdoutDrain(code || 0))
2054
2054
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2055
2055
  } else if (command === 'bench') {
2056
2056
  Promise.resolve().then(() => require('../commands/bench').benchCommand(process.argv.slice(3)))
2057
- .then((code) => process.exit(code || 0))
2057
+ .then((code) => exitAfterStdoutDrain(code || 0))
2058
2058
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(2); });
2059
2059
  } else if (command === 'router') {
2060
2060
  const code = require('../commands/router').routerCommand(process.argv.slice(3));
@@ -2101,7 +2101,7 @@ if (command === 'guide') {
2101
2101
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); exitAfterStdoutDrain(1); });
2102
2102
  } else if (command === 'recover') {
2103
2103
  Promise.resolve().then(() => require('../commands/recover').recoverCommand(process.argv.slice(3)))
2104
- .then((code) => process.exit(code || 0))
2104
+ .then((code) => exitAfterStdoutDrain(code || 0))
2105
2105
  .catch((err) => { console.error(`\nerror: ${err.message || err}`); process.exit(1); });
2106
2106
  } else if (command === 'agents') {
2107
2107
  // Glanceable view of every member's state: stuck, waiting on you, working, resting.
@@ -2110,27 +2110,27 @@ if (command === 'guide') {
2110
2110
  } else if (command === 'pulse') {
2111
2111
  // Pulse: durable overnight self-improvement heartbeat (OS cron) for atris-cli.
2112
2112
  Promise.resolve().then(() => require('../commands/pulse').pulseCommand(process.argv.slice(3)))
2113
- .then((res) => process.exit(res && res.ok === false ? 1 : 0))
2113
+ .then((res) => exitAfterStdoutDrain(res && res.ok === false ? 1 : 0))
2114
2114
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2115
2115
  } else if (command === 'probe') {
2116
2116
  // Chat-lane probe (TRR-22): one real /atris2/turn over the full tool relay.
2117
2117
  Promise.resolve().then(() => require('../commands/probe').probeCommand(process.argv.slice(3)))
2118
- .then((code) => process.exit(code || 0))
2118
+ .then((code) => exitAfterStdoutDrain(code || 0))
2119
2119
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2120
2120
  } else if (command === 'worktree') {
2121
2121
  Promise.resolve().then(() => require('../commands/worktree').worktreeCommand(process.argv.slice(3)))
2122
- .then((code) => process.exit(code || 0))
2122
+ .then((code) => exitAfterStdoutDrain(code || 0))
2123
2123
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2124
2124
  } else if (command === 'autoland') {
2125
2125
  Promise.resolve().then(() => require('../commands/autoland').autolandCommand(process.argv.slice(3)))
2126
- .then((code) => process.exit(code || 0))
2126
+ .then((code) => exitAfterStdoutDrain(code || 0))
2127
2127
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2128
2128
  } else if (command === 'land') {
2129
2129
  // landCommand can throw synchronously on empty repos; wrap so callers get a
2130
2130
  // one-line sentence instead of an uncaught stack from Promise.resolve(fn()).
2131
2131
  Promise.resolve()
2132
2132
  .then(() => require('../commands/land').landCommand(process.argv.slice(3)))
2133
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2133
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2134
2134
  .catch((err) => {
2135
2135
  const msg = String(err && err.message || err || 'land could not run').split('\n')[0];
2136
2136
  console.log(msg);
@@ -2138,61 +2138,61 @@ if (command === 'guide') {
2138
2138
  });
2139
2139
  } else if (command === 'caretaker') {
2140
2140
  Promise.resolve().then(() => require('../commands/caretaker').caretakerCommand(process.argv.slice(3)))
2141
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2141
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2142
2142
  .catch((err) => { console.error(`\nerror: ${err.message || err}`); process.exit(1); });
2143
2143
  } else if (command === 'close') {
2144
2144
  Promise.resolve().then(() => require('../commands/close').run(process.argv.slice(3)))
2145
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2145
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2146
2146
  .catch((err) => { console.error(`\nerror: ${err.message || err}`); process.exit(1); });
2147
2147
  } else if (command === 'goal' || command === 'wtf') {
2148
2148
  Promise.resolve().then(() => require('../commands/goal').run(process.argv.slice(3)))
2149
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2149
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2150
2150
  .catch((err) => { console.error(`\nerror: ${err.message || err}`); process.exit(1); });
2151
2151
  } else if (command === 'founder') {
2152
2152
  Promise.resolve().then(() => require('../commands/founder').founderCommand(process.argv.slice(3)))
2153
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2153
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2154
2154
  .catch((err) => { console.error(`\nerror: ${err.message || err}`); process.exit(1); });
2155
2155
  } else if (command === 'drive') {
2156
2156
  // Drive: one self-driving tick, mission doctor -> auto-fix safe findings -> count disengagements.
2157
2157
  Promise.resolve().then(() => require('../commands/drive').driveCommand(process.argv.slice(3)))
2158
- .then((code) => process.exit(code || 0))
2158
+ .then((code) => exitAfterStdoutDrain(code || 0))
2159
2159
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2160
2160
  } else if (command === 'rsi') {
2161
2161
  // RSI: read the Dream-RSI attempt ledger (trees, attempts, policy, dreams).
2162
2162
  Promise.resolve().then(() => require('../commands/rsi').run(process.argv.slice(3)))
2163
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2163
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2164
2164
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2165
2165
  } else if (command === 'orb') {
2166
2166
  Promise.resolve().then(() => orbCmd(process.argv.slice(3)))
2167
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2167
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2168
2168
  .catch((err) => { console.error(`\nError: ${err.message || err}`); process.exit(1); });
2169
2169
  } else if (command === 'radar' || command === 'ctop') {
2170
2170
  const radarArgs = command === 'ctop' ? ['--agents', ...process.argv.slice(3)] : process.argv.slice(3);
2171
2171
  Promise.resolve().then(() => require('../commands/radar').radarCommand(radarArgs))
2172
- .then((code) => process.exit(code || 0))
2172
+ .then((code) => exitAfterStdoutDrain(code || 0))
2173
2173
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2174
2174
  } else if (command === 'stream') {
2175
2175
  Promise.resolve().then(() => require('../commands/stream').streamCommand(process.argv.slice(3)))
2176
- .then((code) => process.exit(code || 0))
2176
+ .then((code) => exitAfterStdoutDrain(code || 0))
2177
2177
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2178
2178
  } else if (command === 'truth') {
2179
2179
  // Truth: one table rolling up mission state, tasks, feature proof receipts, and loop heartbeats.
2180
2180
  Promise.resolve().then(() => require('../commands/truth').truthCommand(process.argv.slice(3)))
2181
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2181
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2182
2182
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2183
2183
  } else if (command === 'codex-goal') {
2184
2184
  Promise.resolve().then(() => require('../commands/codex-goal').codexGoalCommand(process.argv.slice(3)))
2185
- .then(() => process.exit(process.exitCode || 0))
2185
+ .then(() => exitAfterStdoutDrain(process.exitCode || 0))
2186
2186
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2187
2187
  } else if (command === 'aeo') {
2188
2188
  // AEO: AI Engine Optimization, credit-metered citation drafting against the customer workspace.
2189
2189
  Promise.resolve().then(() => require('../commands/aeo').run(process.argv.slice(3)))
2190
- .then(() => process.exit(0))
2190
+ .then(() => exitAfterStdoutDrain(0))
2191
2191
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2192
2192
  } else if (command === 'design') {
2193
2193
  // Design: extract a site's design system, check brand adherence, search brands.
2194
2194
  Promise.resolve().then(() => require('../commands/design').run(process.argv.slice(3)))
2195
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2195
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2196
2196
  .catch((err) => { console.error(String(err.message || err).replace(/\s+/g, ' ')); process.exit(1); });
2197
2197
  } else if (command === 'mcp') {
2198
2198
  // MCP: stdio Model Context Protocol server exposing the design tools.
@@ -2208,12 +2208,12 @@ if (command === 'guide') {
2208
2208
  } else if (command === 'improve') {
2209
2209
  // Improve: one paid RL tick via POST /api/improve (deducts credits), local autopilot fallback.
2210
2210
  Promise.resolve().then(() => require('../commands/improve').run(process.argv.slice(3)))
2211
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2211
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2212
2212
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2213
2213
  } else if (command === 'study') {
2214
2214
  // Study: on-demand learning feed ingest + local server + browser open.
2215
2215
  Promise.resolve().then(() => require('../commands/study').run(process.argv.slice(3)))
2216
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2216
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2217
2217
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2218
2218
  } else if (command === 'rainmaker') {
2219
2219
  {
@@ -2227,21 +2227,21 @@ if (command === 'guide') {
2227
2227
  const gate = requireAccountBound(process.argv.slice(3));
2228
2228
  if (!gate.ok) process.exit(refuseAccountGlobal());
2229
2229
  Promise.resolve().then(() => require('../commands/avail').availCommand(gate.args))
2230
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2230
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2231
2231
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2232
2232
  }
2233
2233
  } else if (command === 'scoreboard') {
2234
2234
  Promise.resolve().then(() => require('../commands/scoreboard').scoreboardCommand(process.argv.slice(3)))
2235
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2235
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2236
2236
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2237
2237
  } else if (command === 'meet') {
2238
2238
  Promise.resolve().then(() => require('../commands/meet').meetCommand(process.argv.slice(3)))
2239
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2239
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2240
2240
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2241
2241
  } else if (command === 'brain') {
2242
2242
  Promise.resolve()
2243
2243
  .then(() => require('../commands/brain').brainCommand(process.argv.slice(3)))
2244
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2244
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2245
2245
  .catch((err) => {
2246
2246
  const message = err.message || String(err);
2247
2247
  if (process.argv.slice(3).includes('--json')) {
@@ -2264,7 +2264,7 @@ if (command === 'guide') {
2264
2264
  const subcommand = logArgs[0];
2265
2265
  if (subcommand === 'sync') {
2266
2266
  require('../commands/log-sync').logSyncAtris()
2267
- .then(() => process.exit(0))
2267
+ .then(() => exitAfterStdoutDrain(0))
2268
2268
  .catch((error) => {
2269
2269
  console.error(`✗ Log sync failed: ${error.message || error}`);
2270
2270
  process.exit(1);
@@ -2359,14 +2359,14 @@ if (command === 'guide') {
2359
2359
  }
2360
2360
  if (isBusinessSync) {
2361
2361
  Promise.resolve().then(() => require('../commands/business-sync').businessSync(process.argv.slice(3)))
2362
- .then(() => process.exit(0))
2362
+ .then(() => exitAfterStdoutDrain(0))
2363
2363
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2364
2364
  } else if (process.argv.includes('--all')) {
2365
2365
  const dryRun = process.argv.includes('--dry-run');
2366
2366
  const yes = process.argv.includes('--yes') || process.argv.includes('-y');
2367
2367
  const force = process.argv.includes('--force') || yes;
2368
2368
  Promise.resolve().then(() => syncAllCmd({ dryRun, force, yes }))
2369
- .then(() => process.exit(0))
2369
+ .then(() => exitAfterStdoutDrain(0))
2370
2370
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2371
2371
  } else {
2372
2372
  syncCmd({
@@ -2384,7 +2384,7 @@ if (command === 'guide') {
2384
2384
  upgradeAtris().then(() => process.exit(0)).catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2385
2385
  } else if (command === 'chat' && (process.argv[3] === '--personal' || process.argv[3] === '-p')) {
2386
2386
  require('../commands/ask').askAtris(process.argv.slice(4))
2387
- .then(() => process.exit(0))
2387
+ .then(() => exitAfterStdoutDrain(0))
2388
2388
  .catch((error) => {
2389
2389
  console.error(`✗ Ask failed: ${error.message || error}`);
2390
2390
  process.exit(1);
@@ -2400,14 +2400,14 @@ if (command === 'guide') {
2400
2400
  }
2401
2401
  }
2402
2402
  chatAtris()
2403
- .then(() => process.exit(0))
2403
+ .then(() => exitAfterStdoutDrain(0))
2404
2404
  .catch((error) => {
2405
2405
  console.error(`✗ Chat failed: ${error.message || error}`);
2406
2406
  process.exit(1);
2407
2407
  });
2408
2408
  } else if (command === 'fast' || command === 'ax') {
2409
2409
  atrisFastChat()
2410
- .then(() => process.exit(0))
2410
+ .then(() => exitAfterStdoutDrain(0))
2411
2411
  .catch((error) => {
2412
2412
  console.error(`✗ Fast chat failed: ${error.message || error}`);
2413
2413
  process.exit(1);
@@ -2493,47 +2493,47 @@ if (command === 'guide') {
2493
2493
  require('../commands/auth').accountsCmd(args);
2494
2494
  } else if (command === 'balance') {
2495
2495
  Promise.resolve().then(() => require('../commands/balance').balanceCommand(process.argv.slice(3)))
2496
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2496
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2497
2497
  .catch((err) => { console.error(String(err.message || err).replace(/\s+/g, ' ')); process.exit(1); });
2498
2498
  } else if (command === 'usage') {
2499
2499
  Promise.resolve().then(() => require('../commands/usage').usageCommand(process.argv.slice(3)))
2500
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2500
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2501
2501
  .catch((err) => { console.error(String(err.message || err).replace(/\s+/g, ' ')); process.exit(1); });
2502
2502
  } else if (command === 'agent-client') {
2503
2503
  // Owner side of agent self-login: create, list, revoke, rotate agent clients.
2504
2504
  Promise.resolve().then(() => require('../commands/agent-client').agentClientCommand(process.argv.slice(3)))
2505
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2505
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2506
2506
  .catch((err) => { console.error(require('../utils/agent-client').scrub(err && err.message, [])); process.exit(1); });
2507
2507
  } else if (command === 'api-key') {
2508
2508
  Promise.resolve().then(() => require('../commands/api-key').apiKeyCommand(process.argv.slice(3)))
2509
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2509
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2510
2510
  .catch((err) => { console.error(String(err.message || err).replace(/\s+/g, ' ')); process.exit(1); });
2511
2511
  } else if (command === 'topup') {
2512
2512
  Promise.resolve().then(() => require('../commands/topup').topupCommand(process.argv.slice(3)))
2513
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2513
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2514
2514
  .catch((err) => { console.error(String(err.message || err).replace(/\s+/g, ' ')); process.exit(1); });
2515
2515
  } else if (command === 'buy') {
2516
2516
  // Buy: quote, then hand the person the approval step. Never charges.
2517
2517
  Promise.resolve().then(() => require('../commands/buy').buyCommand(process.argv.slice(3)))
2518
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2518
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2519
2519
  .catch((err) => { console.error(String(err.message || err).replace(/\s+/g, ' ')); process.exit(1); });
2520
2520
  } else if (command === 'hire') {
2521
2521
  // One-call hire: member + inbox + allowance + overnight loop (POST /business/{id}/hire).
2522
2522
  Promise.resolve().then(() => require('../commands/hire').hireCommand(process.argv.slice(3)))
2523
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2523
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2524
2524
  .catch((err) => { console.error(String(err.message || err).replace(/\s+/g, ' ')); process.exit(1); });
2525
2525
  } else if (command === 'hires') {
2526
2526
  Promise.resolve().then(() => require('../commands/hire').hiresCommand(process.argv.slice(3)))
2527
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2527
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2528
2528
  .catch((err) => { console.error(String(err.message || err).replace(/\s+/g, ' ')); process.exit(1); });
2529
2529
  } else if (command === 'mail') {
2530
2530
  // Agent inboxes (@atrismail.com), not Gmail. Send asks first unless --yes.
2531
2531
  Promise.resolve().then(() => require('../commands/mail').mailCommand(process.argv.slice(3)))
2532
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2532
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2533
2533
  .catch((err) => { console.error(String(err.message || err).replace(/\s+/g, ' ')); process.exit(1); });
2534
2534
  } else if (command === 'transactions') {
2535
2535
  Promise.resolve().then(() => require('../commands/transactions').transactionsCommand(process.argv.slice(3)))
2536
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2536
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2537
2537
  .catch((err) => { console.error(String(err.message || err).replace(/\s+/g, ' ')); process.exit(1); });
2538
2538
  } else if (command === '_resolve') {
2539
2539
  // Hidden: resolve a profile name query → print exact profile name
@@ -2551,7 +2551,7 @@ if (command === 'guide') {
2551
2551
  require('../commands/auth').shellInit();
2552
2552
  } else if (command === 'visualize') {
2553
2553
  require('../commands/visualize').visualizeAtris(process.argv.slice(3))
2554
- .then(() => process.exit(0))
2554
+ .then(() => exitAfterStdoutDrain(0))
2555
2555
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2556
2556
  } else if (command === 'youtube') {
2557
2557
  require('../commands/youtube').youtubeCommand(process.argv.slice(3))
@@ -2722,14 +2722,14 @@ if (command === 'guide') {
2722
2722
  const timeout = timeoutArg ? parseInt(timeoutArg.split('=')[1]) * 1000 : undefined;
2723
2723
 
2724
2724
  require('../commands/run').runAtris({ maxCycles, verbose, dryRun, once, push, timeout })
2725
- .then(() => process.exit(0))
2725
+ .then(() => exitAfterStdoutDrain(0))
2726
2726
  .catch((error) => {
2727
2727
  console.error(`\u2717 Run failed: ${error.message || error}`);
2728
2728
  process.exit(1);
2729
2729
  });
2730
2730
  } else {
2731
2731
  runMissionFront(args)
2732
- .then((code) => process.exit(code || 0))
2732
+ .then((code) => exitAfterStdoutDrain(code || 0))
2733
2733
  .catch((error) => {
2734
2734
  console.error(`\u2717 Run failed: ${error.message || error}`);
2735
2735
  process.exit(1);
@@ -2784,14 +2784,14 @@ if (command === 'guide') {
2784
2784
  };
2785
2785
 
2786
2786
  require('../commands/autopilot').autopilotAtris(description, options)
2787
- .then(() => process.exit(0))
2787
+ .then(() => exitAfterStdoutDrain(0))
2788
2788
  .catch((error) => {
2789
2789
  console.error(`✗ Autopilot failed: ${error.message || error}`);
2790
2790
  process.exit(1);
2791
2791
  });
2792
2792
  } else {
2793
2793
  Promise.resolve().then(() => require('../commands/autopilot-front').autopilotFront(args))
2794
- .then((code) => process.exit(code || 0))
2794
+ .then((code) => exitAfterStdoutDrain(code || 0))
2795
2795
  .catch((error) => {
2796
2796
  console.error(`✗ Autopilot failed: ${error.message || error}`);
2797
2797
  process.exit(1);
@@ -2799,21 +2799,21 @@ if (command === 'guide') {
2799
2799
  }
2800
2800
  } else if (command === 'brainstorm') {
2801
2801
  require('../commands/brainstorm').brainstormAtris()
2802
- .then(() => process.exit(0))
2802
+ .then(() => exitAfterStdoutDrain(0))
2803
2803
  .catch((error) => {
2804
2804
  console.error(`✗ Brainstorm failed: ${error.message || error}`);
2805
2805
  process.exit(1);
2806
2806
  });
2807
2807
  } else if (command === 'next') {
2808
2808
  Promise.resolve().then(() => require('../commands/next').nextCommand(process.argv.slice(3)))
2809
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2809
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2810
2810
  .catch((error) => {
2811
2811
  console.error(`✗ Error: ${error.message || error}`);
2812
2812
  process.exit(1);
2813
2813
  });
2814
2814
  } else if (command === 'dream') {
2815
2815
  Promise.resolve().then(() => require('../commands/dream').dreamCommand(process.argv.slice(3)))
2816
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
2816
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
2817
2817
  .catch((error) => {
2818
2818
  console.log('No dreams tonight: could not finish dream');
2819
2819
  console.log('Run me nightly: atris dream');
@@ -2833,7 +2833,7 @@ if (command === 'guide') {
2833
2833
  verifier: natural.verifier,
2834
2834
  optionError: natural.error,
2835
2835
  })
2836
- .then((code) => process.exit(Number.isInteger(code) ? code : 0))
2836
+ .then((code) => exitAfterStdoutDrain(Number.isInteger(code) ? code : 0))
2837
2837
  .catch((error) => {
2838
2838
  console.error(`✗ Error: ${error.message || error}`);
2839
2839
  process.exit(1);
@@ -2845,7 +2845,7 @@ if (command === 'guide') {
2845
2845
  process.exit(0);
2846
2846
  }
2847
2847
  planCmd()
2848
- .then(() => process.exit(0))
2848
+ .then(() => exitAfterStdoutDrain(0))
2849
2849
  .catch((error) => {
2850
2850
  console.error(`✗ Plan failed: ${error.message || error}`);
2851
2851
  process.exit(1);
@@ -2857,7 +2857,7 @@ if (command === 'guide') {
2857
2857
  process.exit(0);
2858
2858
  }
2859
2859
  doCmd()
2860
- .then(() => process.exit(0))
2860
+ .then(() => exitAfterStdoutDrain(0))
2861
2861
  .catch((error) => {
2862
2862
  console.error(`✗ Do failed: ${error.message || error}`);
2863
2863
  process.exit(1);
@@ -2869,7 +2869,7 @@ if (command === 'guide') {
2869
2869
  process.exit(0);
2870
2870
  }
2871
2871
  reviewCmd()
2872
- .then(() => process.exit(0))
2872
+ .then(() => exitAfterStdoutDrain(0))
2873
2873
  .catch((error) => {
2874
2874
  console.error(`✗ Review failed: ${error.message || error}`);
2875
2875
  process.exit(1);
@@ -2883,7 +2883,7 @@ if (command === 'guide') {
2883
2883
  let subcommand = process.argv[3];
2884
2884
  if (subcommand && !subcommand.startsWith('-')) {
2885
2885
  require('../commands/context-sync').businessStatus(subcommand)
2886
- .then(() => process.exit(0))
2886
+ .then(() => exitAfterStdoutDrain(0))
2887
2887
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2888
2888
  } else {
2889
2889
  const isQuick = process.argv.includes('--quick') || process.argv.includes('-q');
@@ -2977,7 +2977,7 @@ if (command === 'guide') {
2977
2977
  }
2978
2978
  const dryRun = process.argv.includes('--dry-run');
2979
2979
  require('../commands/release').releaseAtris({ dryRun })
2980
- .then(() => process.exit(0))
2980
+ .then(() => exitAfterStdoutDrain(0))
2981
2981
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
2982
2982
  } else if (command === 'search') {
2983
2983
  const code = require('../commands/search').searchCommand(process.argv.slice(3));
@@ -3000,19 +3000,19 @@ if (command === 'guide') {
3000
3000
  process.exit(reportCommand(args));
3001
3001
  } else if (command === 'play') {
3002
3002
  require('../commands/play').playCommand(...process.argv.slice(3))
3003
- .then(() => process.exit(0))
3003
+ .then(() => exitAfterStdoutDrain(0))
3004
3004
  .catch((err) => { console.error(`✗ Error: ${err.message || err}`); process.exit(1); });
3005
3005
  } else if (command === 'gm') {
3006
3006
  require('../commands/gm').gmCommand(...process.argv.slice(3))
3007
- .then(() => process.exit(process.exitCode || 0))
3007
+ .then(() => exitAfterStdoutDrain(process.exitCode || 0))
3008
3008
  .catch((err) => { console.error(`✗ Error: ${err.message || err}`); process.exit(1); });
3009
3009
  } else if (command === 'game') {
3010
3010
  require('../commands/game').gameCommand(process.argv.slice(3))
3011
- .then((status) => process.exit(status === 1 ? 1 : 0))
3011
+ .then((status) => exitAfterStdoutDrain(status === 1 ? 1 : 0))
3012
3012
  .catch((err) => { console.error(`✗ Error: ${err.message || err}`); process.exit(1); });
3013
3013
  } else if (command === 'ci') {
3014
3014
  Promise.resolve().then(() => require('../commands/ci').ciCommand(process.argv.slice(3)))
3015
- .then((status) => process.exit(status || 0))
3015
+ .then((status) => exitAfterStdoutDrain(status || 0))
3016
3016
  .catch((err) => { console.error(String(err.message || err).replace(/\s+/g, ' ').toLowerCase()); process.exit(1); });
3017
3017
  } else if (command === 'github') {
3018
3018
  const status = require('../commands/github').githubCommand(process.argv.slice(3));
@@ -3050,7 +3050,7 @@ if (command === 'guide') {
3050
3050
  const args = gate.args.slice(1);
3051
3051
  if (mailbox.mailboxAccountId) args.push('--account', mailbox.mailboxAccountId);
3052
3052
  gmailCommand(subcommand, ...args)
3053
- .then(() => process.exit(process.exitCode || 0))
3053
+ .then(() => exitAfterStdoutDrain(process.exitCode || 0))
3054
3054
  .catch((err) => { console.error(`✗ Error: ${err.message || err}`); process.exit(1); });
3055
3055
  }
3056
3056
  } else if (command === 'calendar') {
@@ -3058,7 +3058,7 @@ if (command === 'guide') {
3058
3058
  const subcommand = process.argv[3];
3059
3059
  const args = process.argv.slice(4);
3060
3060
  calendarCommand(subcommand, ...args)
3061
- .then(() => process.exit(0))
3061
+ .then(() => exitAfterStdoutDrain(0))
3062
3062
  .catch((err) => { console.error(`✗ Error: ${err.message || err}`); process.exit(1); });
3063
3063
  } else if (command === 'twitter') {
3064
3064
  {
@@ -3070,7 +3070,7 @@ if (command === 'guide') {
3070
3070
  const subcommand = gate.args[0];
3071
3071
  const args = gate.args.slice(1);
3072
3072
  twitterCommand(subcommand, ...args)
3073
- .then(() => process.exit(0))
3073
+ .then(() => exitAfterStdoutDrain(0))
3074
3074
  .catch((err) => { console.error(`✗ Error: ${err.message || err}`); process.exit(1); });
3075
3075
  }
3076
3076
  } else if (command === 'slack') {
@@ -3093,7 +3093,7 @@ if (command === 'guide') {
3093
3093
  const subcommand = gate.args[0];
3094
3094
  const args = gate.args.slice(1);
3095
3095
  slackCommand(subcommand, ...args)
3096
- .then(() => process.exit(0))
3096
+ .then(() => exitAfterStdoutDrain(0))
3097
3097
  .catch((err) => { console.error(`✗ Error: ${err.message || err}`); process.exit(1); });
3098
3098
  }
3099
3099
  } else if (command === 'imessage') {
@@ -3101,7 +3101,7 @@ if (command === 'guide') {
3101
3101
  const subcommand = process.argv[3];
3102
3102
  const args = process.argv.slice(4);
3103
3103
  imessageCommand(subcommand, ...args)
3104
- .then(() => process.exit(0))
3104
+ .then(() => exitAfterStdoutDrain(0))
3105
3105
  .catch((err) => { console.error(`✗ Error: ${err.message || err}`); process.exit(1); });
3106
3106
  } else if (command === 'integrations') {
3107
3107
  const args = process.argv.slice(3);
@@ -3111,7 +3111,7 @@ if (command === 'guide') {
3111
3111
  }
3112
3112
  const { integrationsStatus } = require('../commands/integrations');
3113
3113
  integrationsStatus(args)
3114
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3114
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3115
3115
  .catch((err) => { console.error(`✗ Error: ${err.message || err}`); process.exit(1); });
3116
3116
  } else if (command === 'apps') {
3117
3117
  // Keep APP.md app-pack operations independent from the heavier workspace boot
@@ -3119,7 +3119,7 @@ if (command === 'guide') {
3119
3119
  const subcommand = process.argv[3];
3120
3120
  const args = process.argv.slice(4);
3121
3121
  Promise.resolve().then(() => require('../commands/apps').appsCommand(subcommand, ...args))
3122
- .then(() => process.exit(0))
3122
+ .then(() => exitAfterStdoutDrain(0))
3123
3123
  .catch((err) => { console.error(`✗ Error: ${err.message || err}`); process.exit(1); });
3124
3124
  } else if (command === 'learn') {
3125
3125
  const subcommand = process.argv[3];
@@ -3131,7 +3131,7 @@ if (command === 'guide') {
3131
3131
  require('../commands/lesson')(subcommand, ...args);
3132
3132
  } else if (command === 'taste') {
3133
3133
  Promise.resolve().then(() => require('../commands/taste').tasteCommand(process.argv.slice(3)))
3134
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3134
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3135
3135
  .catch((err) => { console.error(`taste could not continue: ${err.message || err}.`); process.exit(1); });
3136
3136
  } else if (command === 'teach') {
3137
3137
  const subcommand = process.argv[3];
@@ -3147,7 +3147,7 @@ if (command === 'guide') {
3147
3147
  const subcommand = process.argv[3];
3148
3148
  const args = process.argv.slice(4);
3149
3149
  Promise.resolve().then(() => require('../commands/member').memberCommand(subcommand, ...args))
3150
- .then(() => process.exit(process.exitCode || 0))
3150
+ .then(() => exitAfterStdoutDrain(process.exitCode || 0))
3151
3151
  .catch((err) => { console.error(`✗ Error: ${err.message || err}`); process.exit(1); });
3152
3152
  } else if (command === 'app') {
3153
3153
  const subcommand = process.argv[3];
@@ -3155,25 +3155,25 @@ if (command === 'guide') {
3155
3155
  require('../commands/app').appCommand(subcommand, ...args);
3156
3156
  } else if (command === 'pull') {
3157
3157
  require('../commands/pull').pullAtris()
3158
- .then(() => process.exit(0))
3158
+ .then(() => exitAfterStdoutDrain(0))
3159
3159
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3160
3160
  } else if (command === 'push') {
3161
3161
  require('../commands/push').pushAtris()
3162
- .then(() => process.exit(0))
3162
+ .then(() => exitAfterStdoutDrain(0))
3163
3163
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3164
3164
  } else if (command === 'live') {
3165
3165
  require('../commands/live').liveCommand()
3166
- .then(() => process.exit(0))
3166
+ .then(() => exitAfterStdoutDrain(0))
3167
3167
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3168
3168
  } else if (command === 'align') {
3169
3169
  require('../commands/align').alignAtris()
3170
- .then(() => process.exit(0))
3170
+ .then(() => exitAfterStdoutDrain(0))
3171
3171
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3172
3172
  } else if (command === 'cloud') {
3173
3173
  require('../commands/cloud').cloudAtris();
3174
3174
  } else if (command === 'terminal') {
3175
3175
  require('../commands/terminal').terminalAtris()
3176
- .then(() => process.exit(0))
3176
+ .then(() => exitAfterStdoutDrain(0))
3177
3177
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3178
3178
  } else if (command === 'fleet-report') {
3179
3179
  require('../commands/fleet-report').fleetReport()
@@ -3192,7 +3192,7 @@ if (command === 'guide') {
3192
3192
  require('../commands/workflow').executeAgentSDKFast(userInput);
3193
3193
  } else if (command === 'computer') {
3194
3194
  require('../commands/computer').runComputer()
3195
- .then(() => process.exit(process.exitCode || 0))
3195
+ .then(() => exitAfterStdoutDrain(process.exitCode || 0))
3196
3196
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3197
3197
  } else if (command === 'diff') {
3198
3198
  let diffSlug = process.argv[3];
@@ -3209,7 +3209,7 @@ if (command === 'guide') {
3209
3209
  }
3210
3210
  if (!diffSlug) { console.error('Usage: atris diff [business] [path]'); process.exit(1); }
3211
3211
  require('../commands/context-sync').businessDiff(diffSlug)
3212
- .then(() => process.exit(0))
3212
+ .then(() => exitAfterStdoutDrain(0))
3213
3213
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3214
3214
  } else if (command === 'business') {
3215
3215
  {
@@ -3224,18 +3224,18 @@ if (command === 'guide') {
3224
3224
  const subcommand = gate.args[0];
3225
3225
  const args = gate.args.slice(1);
3226
3226
  require('../commands/business').businessCommand(subcommand, ...args)
3227
- .then(() => process.exit(process.exitCode || 0))
3227
+ .then(() => exitAfterStdoutDrain(process.exitCode || 0))
3228
3228
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3229
3229
  }
3230
3230
  } else if (command === 'soul') {
3231
3231
  const args = process.argv.slice(3);
3232
3232
  require('../commands/soul').soul(args)
3233
- .then(() => process.exit(0))
3233
+ .then(() => exitAfterStdoutDrain(0))
3234
3234
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3235
3235
  } else if (command === 'fleet') {
3236
3236
  const args = process.argv.slice(3);
3237
3237
  require('../commands/fleet').fleet(args)
3238
- .then(() => process.exit(0))
3238
+ .then(() => exitAfterStdoutDrain(0))
3239
3239
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3240
3240
  } else if (command === 'loops' || command === 'self-improve') {
3241
3241
  try {
@@ -3257,7 +3257,7 @@ if (command === 'guide') {
3257
3257
  } else if (command === 'spaceship') {
3258
3258
  const args = process.argv.slice(3);
3259
3259
  require('../commands/spaceship').spaceship(args)
3260
- .then(() => process.exit(0))
3260
+ .then(() => exitAfterStdoutDrain(0))
3261
3261
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3262
3262
  } else if (command === 'code-review' || command === 'cr') {
3263
3263
  const args = process.argv.slice(3);
@@ -3266,12 +3266,12 @@ if (command === 'guide') {
3266
3266
  const subcommand = process.argv[3];
3267
3267
  const args = process.argv.slice(4);
3268
3268
  require('../commands/wiki').wikiCommand(subcommand, ...args)
3269
- .then(() => process.exit(0))
3269
+ .then(() => exitAfterStdoutDrain(0))
3270
3270
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3271
3271
  } else if (command === 'ingest' || command === 'query' || command === 'lint') {
3272
3272
  const args = process.argv.slice(3);
3273
3273
  require('../commands/wiki').wikiCommand(command, ...args)
3274
- .then(() => process.exit(0))
3274
+ .then(() => exitAfterStdoutDrain(0))
3275
3275
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3276
3276
  } else if (command === 'loop') {
3277
3277
  const args = process.argv.slice(3);
@@ -3280,12 +3280,12 @@ if (command === 'guide') {
3280
3280
  process.exit(0);
3281
3281
  }
3282
3282
  Promise.resolve().then(() => require('../commands/loop-front').loopFront(args))
3283
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3283
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3284
3284
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3285
3285
  } else if (command === 'clean-workspace' || command === 'cw') {
3286
3286
  const { cleanWorkspace } = require('../commands/workspace-clean');
3287
3287
  cleanWorkspace()
3288
- .then(() => process.exit(0))
3288
+ .then(() => exitAfterStdoutDrain(0))
3289
3289
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3290
3290
  } else if (command === 'plugin') {
3291
3291
  const subcommand = process.argv[3] || 'build';
@@ -3299,7 +3299,7 @@ if (command === 'guide') {
3299
3299
  const subcommand = process.argv[3];
3300
3300
  const args = process.argv.slice(4);
3301
3301
  Promise.resolve().then(() => require('../commands/compile').compileCommand(subcommand, ...args))
3302
- .then(() => process.exit(process.exitCode || 0))
3302
+ .then(() => exitAfterStdoutDrain(process.exitCode || 0))
3303
3303
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3304
3304
  } else if (command === 'engine' || command === 'engines') {
3305
3305
  // Engine: bring any intelligence. Roster of installed coding CLIs, default
@@ -3314,12 +3314,12 @@ if (command === 'guide') {
3314
3314
  } else if (command === 'link') {
3315
3315
  // Link: ask the roster's engine what two things could become together.
3316
3316
  Promise.resolve().then(() => require('../commands/link').linkCommand(process.argv.slice(3)))
3317
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3317
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3318
3318
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3319
3319
  } else if (command === 'playbook') {
3320
3320
  Promise.resolve()
3321
3321
  .then(() => require('../commands/playbook').playbookCommand(process.argv.slice(3)))
3322
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3322
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3323
3323
  .catch((err) => { console.error(`playbook could not continue: ${err.message || err}`); process.exit(1); });
3324
3324
  } else if (command === 'sign') {
3325
3325
  // Sign: prepare-commit-msg hook that credits Atris as co-author on commits in atris workspaces.
@@ -3328,43 +3328,43 @@ if (command === 'guide') {
3328
3328
  } else if (command === 'slop') {
3329
3329
  // Slop: deterministic frontend-slop detector (no LLM). Exit 1 = slop found, for CI + the autopilot gate.
3330
3330
  Promise.resolve().then(() => require('../commands/slop').slopCommand(process.argv.slice(3)))
3331
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3331
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3332
3332
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3333
3333
  } else if (command === 'voice') {
3334
3334
  Promise.resolve().then(() => require('../commands/voice').voiceCommand(process.argv.slice(3)))
3335
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3335
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3336
3336
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3337
3337
  } else if (command === 'write') {
3338
3338
  // Write: guided writing sessions, human types every word, atris structures + reviews (plan-do-review for prose).
3339
3339
  Promise.resolve().then(() => require('../commands/write').writeCommand(process.argv.slice(3)))
3340
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3340
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3341
3341
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3342
3342
  } else if (command === 'strings') {
3343
3343
  // Strings: content design system from live code (no LLM). Extracts UI strings, flags variants,
3344
3344
  // enforces preferred terms at the gate. Exit 1 = variants/banned terms found, for CI + the gate.
3345
3345
  Promise.resolve().then(() => require('../commands/strings').stringsCommand(process.argv.slice(3)))
3346
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3346
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3347
3347
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3348
3348
  } else if (command === 'security-review' || command === 'secure') {
3349
3349
  // Security review: deterministic secrets/PII/code-risk scan (no LLM). Exit 1 = HIGH finding,
3350
3350
  // for the autopilot/mission/CI gate + a SOC 2 evidence artifact via --json.
3351
3351
  Promise.resolve().then(() => require('../commands/security-review').securityReviewCommand(process.argv.slice(3)))
3352
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3352
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3353
3353
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3354
3354
  } else if (command === 'signup') {
3355
3355
  // Signup: one-call seedless agent signup → writes the active profile (install→signup→play seam).
3356
3356
  Promise.resolve().then(() => require('../commands/signup').signupCommand(process.argv.slice(3)))
3357
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3357
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3358
3358
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3359
3359
  } else if (command === 'moves') {
3360
3360
  // Moves: your 3 next moves, approve one into the loop, kill, or skip.
3361
3361
  Promise.resolve().then(() => require('../commands/moves').movesCommand(process.argv.slice(3)))
3362
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3362
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3363
3363
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3364
3364
  } else if (command === 'unknowns') {
3365
3365
  // Unknowns: blindspot pass from local territory context into the SQLite ledger.
3366
3366
  Promise.resolve().then(() => require('../commands/unknowns').unknownsCommand(process.argv.slice(3)))
3367
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3367
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3368
3368
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3369
3369
  } else if (command === 'feed') {
3370
3370
  // Feed: read and post the business group feed, receipts and state changes only.
@@ -3375,17 +3375,17 @@ if (command === 'guide') {
3375
3375
  } else if (command === 'clarity') {
3376
3376
  // Clarity: interview yourself once; agents read how you work so you stop repeating it.
3377
3377
  Promise.resolve().then(() => require('../commands/clarity').clarityCommand(process.argv.slice(3)))
3378
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3378
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3379
3379
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3380
3380
  } else if (command === 'interview') {
3381
3381
  // Interview: the interlinked 1-on-1, live interview that extracts judgment into a member file.
3382
3382
  Promise.resolve().then(() => require('../commands/interview').interviewCommand(process.argv.slice(3)))
3383
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3383
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3384
3384
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3385
3385
  } else if (command === 'deck') {
3386
3386
  // Deck: premium Google Slides from a plain content spec, via the Atris deck engine (anti-slop design system).
3387
3387
  Promise.resolve().then(() => require('../commands/deck').run(process.argv.slice(3)))
3388
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3388
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3389
3389
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3390
3390
  } else if (command === 'site') {
3391
3391
  // Site: build markdown sites or publish static web folders.
@@ -3397,32 +3397,32 @@ if (command === 'guide') {
3397
3397
  const gate = deployWrite ? requireAccountBound(raw) : { ok: true, args: raw };
3398
3398
  if (!gate.ok) process.exit(refuseAccountGlobal());
3399
3399
  Promise.resolve().then(() => require('../commands/site').run(gate.args))
3400
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3400
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3401
3401
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3402
3402
  }
3403
3403
  } else if (command === 'theme') {
3404
3404
  // Theme: brand themes (.atris/theme.json) for the whole design system (deck/html/site).
3405
3405
  Promise.resolve().then(() => require('../commands/theme').run(process.argv.slice(3)))
3406
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3406
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3407
3407
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3408
3408
  } else if (command === 'card') {
3409
3409
  // Card: one line of text into an on-brand image (uses your theme + the design system).
3410
3410
  Promise.resolve().then(() => require('../commands/card').run(process.argv.slice(3)))
3411
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3411
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3412
3412
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3413
3413
  } else if (command === 'brief') {
3414
3414
  // Brief: one-glance operator surface for landings, waits, and next moves.
3415
3415
  Promise.resolve().then(() => require('../commands/brief').run(process.argv.slice(3)))
3416
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3416
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3417
3417
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3418
3418
  } else if (command === 'pack') {
3419
3419
  Promise.resolve().then(() => require('../commands/pack').run(process.argv.slice(3)))
3420
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3420
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3421
3421
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3422
3422
  } else if (command === 'reel') {
3423
3423
  // Reel: one line of text into a short on-brand video (an animated card; frames via Chrome + ffmpeg).
3424
3424
  Promise.resolve().then(() => require('../commands/reel').run(process.argv.slice(3)))
3425
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3425
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3426
3426
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3427
3427
  } else if (command === 'tree') {
3428
3428
  const subcommand = process.argv[3];
@@ -3440,27 +3440,27 @@ if (command === 'guide') {
3440
3440
  process.exit(0);
3441
3441
  }
3442
3442
  require('../commands/setup').setupAtris()
3443
- .then(() => process.exit(0))
3443
+ .then(() => exitAfterStdoutDrain(0))
3444
3444
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3445
3445
  } else if (command === 'fork') {
3446
3446
  require('../commands/fork').forkAtris()
3447
- .then(() => process.exit(0))
3447
+ .then(() => exitAfterStdoutDrain(0))
3448
3448
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3449
3449
  } else if (command === 'browse') {
3450
3450
  require('../commands/browse').browseAtris()
3451
- .then(() => process.exit(0))
3451
+ .then(() => exitAfterStdoutDrain(0))
3452
3452
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3453
3453
  } else if (command === 'publish') {
3454
3454
  require('../commands/publish').publishAtris()
3455
- .then(() => process.exit(0))
3455
+ .then(() => exitAfterStdoutDrain(0))
3456
3456
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3457
3457
  } else if (command === 'sleep') {
3458
3458
  require('../commands/lifecycle').sleepAtris()
3459
- .then(() => process.exit(0))
3459
+ .then(() => exitAfterStdoutDrain(0))
3460
3460
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3461
3461
  } else if (command === 'wake') {
3462
3462
  require('../commands/lifecycle').wakeAtris()
3463
- .then(() => process.exit(0))
3463
+ .then(() => exitAfterStdoutDrain(0))
3464
3464
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3465
3465
  } else if (command === 'feedback') {
3466
3466
  {
@@ -3468,7 +3468,7 @@ if (command === 'guide') {
3468
3468
  if (!gate.ok) process.exit(refuseAccountGlobal());
3469
3469
  process.argv = [process.argv[0], process.argv[1], 'feedback', ...gate.args];
3470
3470
  require('../commands/feedback').feedbackCommand()
3471
- .then(() => process.exit(0))
3471
+ .then(() => exitAfterStdoutDrain(0))
3472
3472
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3473
3473
  }
3474
3474
  } else if (command === 'errors') {
@@ -3479,34 +3479,34 @@ if (command === 'guide') {
3479
3479
  const errorArgs = gate.account ? ['--account', ...gate.args] : gate.args;
3480
3480
  process.argv = [process.argv[0], process.argv[1], 'errors', ...errorArgs];
3481
3481
  require('../commands/errors').errorsCommand()
3482
- .then(() => process.exit(0))
3482
+ .then(() => exitAfterStdoutDrain(0))
3483
3483
  .catch((err) => { console.error(`✗ Error: ${err.message || err}`); process.exit(1); });
3484
3484
  }
3485
3485
  } else if (command === 'host') {
3486
3486
  require('../commands/host').hostCommand();
3487
3487
  } else if (command === 'social') {
3488
3488
  require('../commands/social').socialCommand()
3489
- .then(() => process.exit(0))
3489
+ .then(() => exitAfterStdoutDrain(0))
3490
3490
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3491
3491
  } else if (command === 'people') {
3492
3492
  require('../commands/social').peopleCommand()
3493
- .then(() => process.exit(0))
3493
+ .then(() => exitAfterStdoutDrain(0))
3494
3494
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3495
3495
  } else if (command === 'follow') {
3496
3496
  require('../commands/social').followCommand()
3497
- .then(() => process.exit(0))
3497
+ .then(() => exitAfterStdoutDrain(0))
3498
3498
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3499
3499
  } else if (command === 'unfollow') {
3500
3500
  require('../commands/social').unfollowCommand()
3501
- .then(() => process.exit(0))
3501
+ .then(() => exitAfterStdoutDrain(0))
3502
3502
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3503
3503
  } else if (command === 'friends') {
3504
3504
  require('../commands/social').friendsCommand()
3505
- .then(() => process.exit(0))
3505
+ .then(() => exitAfterStdoutDrain(0))
3506
3506
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3507
3507
  } else if (command === 'msg') {
3508
3508
  require('../commands/social').msgCommand()
3509
- .then(() => process.exit(0))
3509
+ .then(() => exitAfterStdoutDrain(0))
3510
3510
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3511
3511
  } else if (command === 'inbox') {
3512
3512
  {
@@ -3514,24 +3514,24 @@ if (command === 'guide') {
3514
3514
  if (!gate.ok) process.exit(refuseAccountGlobal());
3515
3515
  process.argv = [process.argv[0], process.argv[1], 'inbox', ...gate.args];
3516
3516
  require('../commands/social').inboxCommand()
3517
- .then(() => process.exit(0))
3517
+ .then(() => exitAfterStdoutDrain(0))
3518
3518
  .catch((err) => { console.error(`✗ Error: ${err.message || err}`); process.exit(1); });
3519
3519
  }
3520
3520
  } else if (command === 'join') {
3521
3521
  require('../commands/social').joinCommand()
3522
- .then(() => process.exit(0))
3522
+ .then(() => exitAfterStdoutDrain(0))
3523
3523
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3524
3524
  } else if (command === 'invite') {
3525
3525
  require('../commands/social').inviteCommand()
3526
- .then(() => process.exit(0))
3526
+ .then(() => exitAfterStdoutDrain(0))
3527
3527
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3528
3528
  } else if (command === 'pay') {
3529
3529
  require('../commands/pay').payCommand()
3530
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3530
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3531
3531
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3532
3532
  } else if (command === 'trust') {
3533
3533
  require('../commands/trust').trustCommand()
3534
- .then((code) => process.exit(typeof code === 'number' ? code : 0))
3534
+ .then((code) => exitAfterStdoutDrain(typeof code === 'number' ? code : 0))
3535
3535
  .catch((err) => { console.error(`\n✗ Error: ${err.message || err}`); process.exit(1); });
3536
3536
  } else {
3537
3537
  console.log(`Unknown command: ${command}`);
@@ -4,6 +4,7 @@ const fs = require('fs');
4
4
  const path = require('path');
5
5
  const os = require('os');
6
6
  const { spawnSync } = require('child_process');
7
+ const { localDay } = require('../lib/local-day');
7
8
 
8
9
  const autoland = require('../lib/autoland');
9
10
  const { gateForHuman, plainLandingReason } = require('../lib/voice-gate');
@@ -1006,6 +1007,19 @@ function mergedCloseNote(receipt) {
1006
1007
  + (receipt.merged_close_error ? ', could not check which jobs already merged' : '');
1007
1008
  }
1008
1009
 
1010
+ // The digest goes out once per local day. A stamp written before the switch
1011
+ // to local days is the UTC day of a send at this same local hour, today or
1012
+ // yesterday. Across a clock change both can be the same UTC day; that stamp
1013
+ // cannot say which, so the digest goes out rather than go quiet.
1014
+ function digestSentToday(state, now = new Date()) {
1015
+ if (!state || !state.last_digest_date) return false;
1016
+ if (state.last_digest_local) return state.last_digest_date === localDay(now);
1017
+ const utcDay = (d) => d.toISOString().slice(0, 10);
1018
+ const yesterday = new Date(now);
1019
+ yesterday.setDate(yesterday.getDate() - 1);
1020
+ return state.last_digest_date === utcDay(now) && state.last_digest_date !== utcDay(yesterday);
1021
+ }
1022
+
1009
1023
  async function runTickBody(root, { json, policy, receipt, engineValidationDeps = {} }) {
1010
1024
 
1011
1025
  try {
@@ -1298,9 +1312,9 @@ async function runTickBody(root, { json, policy, receipt, engineValidationDeps =
1298
1312
  }
1299
1313
 
1300
1314
  // 4. daily digest at the configured hour
1301
- const today = new Date().toISOString().slice(0, 10);
1315
+ const today = localDay();
1302
1316
  const digestHour = Number(policy.digest_hour ?? autoland.DEFAULT_DIGEST_HOUR);
1303
- if (new Date().getHours() === digestHour && state.last_digest_date !== today) {
1317
+ if (new Date().getHours() === digestHour && !digestSentToday(state)) {
1304
1318
  receipt.digest_due = true;
1305
1319
  let waitingWishes = [];
1306
1320
  try {
@@ -1326,6 +1340,7 @@ async function runTickBody(root, { json, policy, receipt, engineValidationDeps =
1326
1340
  }
1327
1341
  receipt.digest_text = text;
1328
1342
  state.last_digest_date = today;
1343
+ state.last_digest_local = true;
1329
1344
  delete state.janitor;
1330
1345
 
1331
1346
  // 5. once a day, keep the receipt shelf lean: compress old run receipts
@@ -1472,6 +1487,7 @@ function autolandCommand(args = []) {
1472
1487
 
1473
1488
  module.exports = {
1474
1489
  autolandCommand,
1490
+ digestSentToday,
1475
1491
  digestNextMoves,
1476
1492
  acceptSweepTimeoutMs,
1477
1493
  describeAcceptKillCause,
@@ -17,6 +17,7 @@ const { loadCredentials } = require('../utils/auth');
17
17
  const { apiRequestJson } = require('../utils/api');
18
18
  const { looksLikeBusinessSlug, requireAccountBound, refuseAccountGlobal } = require('../lib/account-bound');
19
19
  const { argsWantHelp, wantsJson } = require('../lib/noninteractive');
20
+ const { localDay } = require('../lib/local-day');
20
21
 
21
22
  function sleep(ms) {
22
23
  return new Promise((r) => setTimeout(r, ms));
@@ -58,7 +59,7 @@ async function fetchDailyReport(token, businessId) {
58
59
  }
59
60
 
60
61
  async function writeReportToComputer(token, businessId, workspaceId, report) {
61
- const date = report.date || new Date().toISOString().slice(0, 10);
62
+ const date = report.date || localDay();
62
63
  const remotePath = `/workspace/atris/reports/daily-${date}.md`;
63
64
  const b64 = Buffer.from(report.markdown || '', 'utf8').toString('base64');
64
65
  const command =
@@ -231,4 +232,4 @@ async function fleetReport() {
231
232
  process.exitCode = delivered > 0 || dryRun || results.every((r) => r.reason === 'asleep') ? 0 : 1;
232
233
  }
233
234
 
234
- module.exports = { fleetReport, formatScoreboardPnl };
235
+ module.exports = { fleetReport, formatScoreboardPnl, writeReportToComputer };
@@ -8,6 +8,7 @@ const {
8
8
  } = require('./autopilot');
9
9
  const { detectLessonContradictions } = require('../lib/lesson-contradiction');
10
10
  const taskDb = require('../lib/task-db');
11
+ const { localDay } = require('../lib/local-day');
11
12
  const { validateDetector, appendLedgerEntry, readLedger } = require('../lib/lesson-ledger');
12
13
 
13
14
  /**
@@ -57,7 +58,7 @@ function autoResolveLessons(cwd, options = {}) {
57
58
  const dryRun = !!options.dryRun;
58
59
  const lessons = parseLessons(cwd);
59
60
  const metadata = loadLessonMetadata(cwd);
60
- const today = new Date().toISOString().slice(0, 10);
61
+ const today = localDay();
61
62
  const checked = [];
62
63
  const resolved = [];
63
64
 
@@ -67,10 +67,11 @@ function roundSummary(before, after) {
67
67
  }
68
68
  const fresh = after.missions.filter((m) => !previous.get(m.id)?.has(m.status));
69
69
  const kept = fresh.filter((m) => m.status === 'ended' && m.outcome === 'kept').length;
70
- const failed = fresh.filter((m) => m.status === 'ended' && m.outcome !== 'kept').length;
70
+ const held = fresh.filter((m) => m.status === 'ended' && m.outcome === 'held').length;
71
+ const failed = fresh.filter((m) => m.status === 'ended' && m.outcome !== 'kept' && m.outcome !== 'held').length;
71
72
  const vetoed = fresh.filter((m) => m.status === 'vetoed').length;
72
73
  const spent = Math.round((after.budget.spent - before.budget.spent) * 100) / 100;
73
- return { kept, failed, vetoed, spent, fresh };
74
+ return { kept, failed, held, vetoed, spent, fresh };
74
75
  }
75
76
 
76
77
  // Nothing finished and the check reads the same: there is nothing to learn.
@@ -81,7 +82,7 @@ function quietRound(before, after, summary) {
81
82
 
82
83
  // On a subscription the round is told without dollars, since none were paid.
83
84
  function roundTally(view, summary) {
84
- return `${summary.kept} kept, ${summary.failed} failed${paysDollars(view) ? `, $${summary.spent} spent` : ''}`;
85
+ return `${summary.kept} kept, ${summary.failed} failed${summary.held ? `, ${summary.held} waiting on you` : ''}${paysDollars(view) ? `, $${summary.spent} spent` : ''}`;
85
86
  }
86
87
 
87
88
  function reviewPrompt(view, summary, lessons) {
@@ -94,7 +95,7 @@ function reviewPrompt(view, summary, lessons) {
94
95
  `Campaign: ${view.title}`,
95
96
  `Judge: ${view.judge}`,
96
97
  `Judge now: ${view.last_judge ? `${view.last_judge.passed ? 'passed' : 'failed'}${view.last_judge.reading !== null ? ` (reading ${view.last_judge.reading})` : ''}: ${view.answer.text || ''}` : 'never run'}`,
97
- `This round: ${summary.kept} kept, ${summary.failed} failed, ${summary.vetoed} could not start${paid ? `, $${summary.spent} spent` : ''}`,
98
+ `This round: ${summary.kept} kept, ${summary.failed} failed, ${summary.vetoed} could not start${summary.held ? `, ${summary.held} paused for a person's review` : ''}${paid ? `, $${summary.spent} spent` : ''}`,
98
99
  'Missions this round:',
99
100
  missions,
100
101
  '',
@@ -174,4 +175,4 @@ function makeCadence(root, loop, options = {}, deps = {}) {
174
175
  return { run, review };
175
176
  }
176
177
 
177
- module.exports = { lessonsPath, makeCadence, parseDuration, readLessons, reviewPrompt };
178
+ module.exports = { lessonsPath, makeCadence, parseDuration, readLessons, reviewPrompt, roundSummary, roundTally };
@@ -79,6 +79,8 @@ function rankCampaignMembers(view, rsiSummary = null, events = null) {
79
79
  let streak = 0;
80
80
  for (let i = mine.length - 1; i >= 0; i -= 1) {
81
81
  const outcome = String(mine[i].outcome || '');
82
+ // held waits on a person's yes: it neither adds to a streak nor ends one
83
+ if (outcome === 'held') continue;
82
84
  if (outcome && outcome !== 'kept' && !mine[i].credited) streak += 1;
83
85
  else break;
84
86
  }
@@ -193,8 +193,11 @@ function missionCost(root, missionId, deps = {}) {
193
193
  return { cost_usd: cents / 100, runs: rows.length, uncosted_runs: uncosted };
194
194
  }
195
195
 
196
+ // A mission whose last tick paused for a person's review was held, not
197
+ // failed: the work waits on a yes, so the campaign should say so.
196
198
  function outcomeFor(mission) {
197
- return mission.status === 'complete' ? 'kept' : 'failed';
199
+ if (mission.status === 'complete') return 'kept';
200
+ return mission.last_tick_status === 'paused-for-review' ? 'held' : 'failed';
198
201
  }
199
202
 
200
203
  // Called from saveMission with the record before and after. Only the step
@@ -40,6 +40,12 @@ function dedupeLessons(lines) {
40
40
  return out;
41
41
  }
42
42
 
43
+ // Held is a mission paused for a person's yes: neither kept nor failed, so it
44
+ // adds no failure, streak, or lesson.
45
+ function failedOutcome(outcome) {
46
+ return Boolean(outcome) && outcome !== 'kept' && outcome !== 'held';
47
+ }
48
+
43
49
  function aggregateMembers(missions, failureOrder = missions) {
44
50
  const byMember = new Map();
45
51
  for (const m of missions) {
@@ -48,6 +54,7 @@ function aggregateMembers(missions, failureOrder = missions) {
48
54
  byMember.set(name, {
49
55
  member: name,
50
56
  missions: 0,
57
+ held: 0,
51
58
  kept: 0,
52
59
  failed: 0,
53
60
  reverted: 0,
@@ -63,12 +70,14 @@ function aggregateMembers(missions, failureOrder = missions) {
63
70
  });
64
71
  }
65
72
  const entry = byMember.get(name);
66
- entry.missions += 1;
73
+ // held is not decided yet, so it stays out of the totals a rating divides by
74
+ if (m.outcome === 'held') entry.held += 1;
75
+ else entry.missions += 1;
67
76
  const cost = typeof m.cost_usd === 'number' && Number.isFinite(m.cost_usd) ? m.cost_usd : 0;
68
77
  entry.cost_usd = round(entry.cost_usd + cost, 4);
69
78
  if (m.outcome === 'kept') {
70
79
  entry.kept += 1;
71
- } else if (m.outcome) {
80
+ } else if (failedOutcome(m.outcome)) {
72
81
  entry.failed += 1;
73
82
  if (m.outcome === 'reverted') entry.reverted += 1;
74
83
  entry.wasted_cost_usd = round(entry.wasted_cost_usd + cost, 4);
@@ -84,7 +93,7 @@ function aggregateMembers(missions, failureOrder = missions) {
84
93
  for (const m of failureOrder) {
85
94
  const entry = byMember.get(m.member || 'unknown');
86
95
  if (m.outcome === 'kept') entry.failure_streak = 0;
87
- else if (m.outcome) {
96
+ else if (failedOutcome(m.outcome)) {
88
97
  entry.failure_streak += 1;
89
98
  if (entry.failure_streak >= 2) entry.repeat_failures += 1;
90
99
  }
@@ -223,7 +232,7 @@ function summarizeTrace(events) {
223
232
  `- ${m.member} finished ${m.mission_id} on ${m.campaign_id} with ${m.reward === 0 ? 'no reading gain' : `reading change ${round(m.reward, 4)}`}; tie verify directly to a failing judge check`
224
233
  );
225
234
  }
226
- if (m.outcome && m.outcome !== 'kept') {
235
+ if (failedOutcome(m.outcome)) {
227
236
  rawLessons.push(
228
237
  `- ${m.member} had ${m.mission_id} end ${m.outcome} on ${m.campaign_id}; keep scope to one checkable slice`
229
238
  );
@@ -429,7 +438,7 @@ function writeRsiSnapshot(root, store, campaignId = null) {
429
438
  );
430
439
  const progressFile = path.join(root, 'atris', 'campaigns', cid, 'progress.md');
431
440
  const kept = (c.missions || []).filter((m) => m.outcome === 'kept').length;
432
- const failed = (c.missions || []).filter((m) => m.outcome && m.outcome !== 'kept').length;
441
+ const failed = (c.missions || []).filter((m) => failedOutcome(m.outcome)).length;
433
442
  const progressLines = [
434
443
  `# Progress: ${c.title}`,
435
444
  '',
@@ -559,7 +568,7 @@ function selectNextCampaigns(store, rsiSummary = null) {
559
568
  : rankCampaignMembers(current, rsi, events);
560
569
  const benched = ranked.filter((r) => r.benched).map((r) => r.member);
561
570
  const warm = ranked.find((r) => !r.benched) || ranked[0] || { member: v.owner, overall: 75 };
562
- const failedCount = (v.missions || []).filter((m) => m.status === 'ended' && m.outcome !== 'kept').length;
571
+ const failedCount = (v.missions || []).filter((m) => m.status === 'ended' && m.outcome !== 'kept' && m.outcome !== 'held').length;
563
572
  const recommendation = warm.overall < 65
564
573
  ? `add seat ${topStoreMember} (top ovr) to replace cold lineup (${ranked.map((r) => `${r.member} ${r.overall} ovr`).join(', ')})`
565
574
  : benched.length
@@ -33,8 +33,9 @@ const STATES = Object.freeze([
33
33
  const STOP_REASONS = Object.freeze(['judge_passed', 'stopped', 'done_by_human', 'budget_spent']);
34
34
 
35
35
  // A fault is a job that never ran (engine missing, crash before the first
36
- // step): the setup broke, not the work.
37
- const MISSION_OUTCOMES = Object.freeze(['kept', 'reverted', 'failed', 'fault']);
36
+ // step): the setup broke, not the work. Held is a mission that paused for a
37
+ // person's review before it could finish.
38
+ const MISSION_OUTCOMES = Object.freeze(['kept', 'reverted', 'failed', 'fault', 'held']);
38
39
 
39
40
  // What a person or agent writes. Everything else is folded from events.
40
41
  const CAMPAIGN_FIELDS = Object.freeze({
@@ -1615,12 +1615,28 @@ body.waiting .bet { position: absolute; left: 24px; right: 24px; width: auto; to
1615
1615
  if (reduced) {
1616
1616
  document.getElementById('lava').style.opacity = '0';
1617
1617
  planned('leave', 200);
1618
- setTimeout(function () { swap(); stageFade(); orb.melt(then, to, function () {}, fast); }, 200);
1618
+ afterFade(b, 200, function () { swap(); stageFade(); orb.melt(then, to, function () {}, fast); });
1619
1619
  return;
1620
1620
  }
1621
1621
  orb.melt(then, to, swap, fast);
1622
1622
  }
1623
1623
 
1624
+ // the card has faded all the way: its opacity fade ended, or ms passed with
1625
+ // a frame to spare when none ran. A timer alone cut the last sixth of a fade
1626
+ // that started a frame late on a slow phone, and the card vanished at 0.17.
1627
+ function afterFade(node, ms, cb) {
1628
+ var ran = false;
1629
+ var finish = function (e) {
1630
+ // eventPhase 2: the card's own fade, not one bubbling up from inside it
1631
+ if (ran || (e && (e.eventPhase !== 2 || e.propertyName !== 'opacity'))) return;
1632
+ ran = true;
1633
+ node.removeEventListener('transitionend', finish);
1634
+ cb();
1635
+ };
1636
+ node.addEventListener('transitionend', finish);
1637
+ setTimeout(finish, ms + 50);
1638
+ }
1639
+
1624
1640
  // under reduced motion the sphere never travels: it fades in where it now sits
1625
1641
  // and its line fades in with it
1626
1642
  function stageFade() {
@@ -1951,14 +1967,14 @@ body.waiting .bet { position: absolute; left: 24px; right: 24px; width: auto; to
1951
1967
  b.classList.add('leave', 'fast');
1952
1968
  // under reduced motion the sphere fades out with the words, then fades in at its own place
1953
1969
  fadeSphere();
1954
- setTimeout(function () {
1970
+ afterFade(b, 220, function () {
1955
1971
  b.hidden = true;
1956
1972
  b.classList.remove('leave', 'fast', 'holding', 'up');
1957
1973
  document.body.classList.remove('has-card', 'wide', 'waiting');
1958
1974
  stageFade();
1959
1975
  document.getElementById('orb').setAttribute('aria-label', 'the atris orb. tap to think of one new idea for the business');
1960
1976
  then();
1961
- }, 220);
1977
+ });
1962
1978
  }
1963
1979
 
1964
1980
  // The idea lands: the calm line's words fade while the dots spiral in
@@ -4,6 +4,7 @@
4
4
  // 0ms-to-greeting is the contract (atris/features/orb-desktop/PLAN.md).
5
5
  const fs = require('fs');
6
6
  const path = require('path');
7
+ const { localDay } = require('./local-day');
7
8
 
8
9
  const MAX_SUGGESTIONS = 12;
9
10
  const WARM_THREAD_WINDOW_MS = 48 * 60 * 60 * 1000;
@@ -37,7 +38,7 @@ function normalizeTime(value) {
37
38
  function todayKey(now) {
38
39
  const stamp = normalizeTime(now);
39
40
  if (!stamp) return '';
40
- return new Date(stamp).toISOString().slice(0, 10);
41
+ return localDay(new Date(stamp));
41
42
  }
42
43
 
43
44
  function normalizeStatus(value) {
@@ -467,7 +468,7 @@ async function appendOrbChoice(root, label, when = new Date()) {
467
468
  const safeRoot = typeof root === 'string' && root ? path.resolve(root) : null;
468
469
  const cleanLabel = cleanTitle(label, 120);
469
470
  if (!safeRoot || !cleanLabel) return { ok: false, error: 'invalid root or label' };
470
- const day = when.toISOString().slice(0, 10);
471
+ const day = localDay(when);
471
472
  const line = `orb: ${cleanLabel} · ${day}\n`;
472
473
  try {
473
474
  const nowPath = fs.existsSync(path.join(safeRoot, 'atris'))
@@ -86,7 +86,9 @@ function writeTaskReceipt({ taskId, command, root = process.cwd(), runner } = {}
86
86
  const dir = runsDir(root);
87
87
  fs.mkdirSync(dir, { recursive: true });
88
88
  const now = new Date();
89
- const date = now.toISOString().slice(0, 10);
89
+ // Local calendar day for the file name; toISOString() is the UTC day,
90
+ // already tomorrow in the evening west of Greenwich.
91
+ const date = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`;
90
92
  const safeTime = now.toISOString().replace(/[:.]/g, '-');
91
93
  const receiptFile = path.join(dir, `${date}-task-${slugifyTaskId(taskId)}-${safeTime}.json`);
92
94
  const receiptPath = path.relative(root, receiptFile);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atris",
3
- "version": "3.74.18",
3
+ "version": "3.74.19",
4
4
  "description": "you say what you want in plain words. atris builds it, checks it, and shows you proof.",
5
5
  "mcpName": "io.github.atrislabs/atris",
6
6
  "main": "bin/atris.js",