@alan-ai-hq/agent-manager-darwin-arm64 0.1.171 → 0.1.172

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/alan-agent.cjs CHANGED
@@ -23453,7 +23453,7 @@ function getAlanModePrompt(mode) {
23453
23453
  function getAlanAgentPrompt(agentId) {
23454
23454
  return getAgentSystemPrompt(agentId);
23455
23455
  }
23456
- var ALAN_CONTEXT_SEARCH_PROMPT, ALAN_PLATFORM_TOOL_ROUTING_PROMPT, ALAN_OPENUI_COMPONENT_SIGNATURES, ALAN_VISUAL_PROMPT, ALAN_VISUAL_REMINDER_PROMPT, ALAN_IDENTITY_PROMPT, ALAN_CODE_CONTEXT_PROMPT, PLAN_MODE_PROMPT, ASK_MODE_PROMPT, REVIEW_MODE_PROMPT;
23456
+ var ALAN_CONTEXT_SEARCH_PROMPT, ALAN_PLATFORM_TOOL_ROUTING_PROMPT, ALAN_OPENUI_COMPONENT_SIGNATURES, ALAN_VISUAL_PROMPT, ALAN_VISUAL_REMINDER_PROMPT, ALAN_SUGGESTING_WORK_PROMPT, ALAN_IDENTITY_PROMPT, ALAN_CODE_CONTEXT_PROMPT, PLAN_MODE_PROMPT, ASK_MODE_PROMPT, REVIEW_MODE_PROMPT;
23457
23457
  var init_system_prompt = __esm({
23458
23458
  "../shared/dist/agent/system-prompt.js"() {
23459
23459
  "use strict";
@@ -23532,6 +23532,12 @@ ${ALAN_OPENUI_COMPONENT_SIGNATURES.map((signature) => ` ${signature}`).join("\n
23532
23532
  ALAN_VISUAL_REMINDER_PROMPT = `## Answer format
23533
23533
 
23534
23534
  Before replying in the Alan chat, consider what the user is trying to do and whether a visual would serve it better than paragraphs: comparisons, trends, statuses, timelines, plans and options go in a \`\`\`chart, \`\`\`mermaid or \`\`\`openui block even when nobody asked for one. Trivial answers stay plain text.`;
23535
+ ALAN_SUGGESTING_WORK_PROMPT = `## Suggesting Work
23536
+
23537
+ When \`suggest_task\` is available, use it to put work in the session's side panel for the user to pick up; it creates nothing by itself.
23538
+ - \`convert_session\`: suggest once when a chat that is not linked to a task has turned into multi-step delivery work (code changes, a PR, several turns). Give the title and description the task should have.
23539
+ - \`follow_up\`: suggest real, separate work you found and did not do, such as a bug, risky debt or a missing test. Never the next step of the current request or work you are about to do. Include \`handoffContext\` with what a fresh session needs: verified findings, files, decisions.
23540
+ - Prefer none. At most three in a turn, never a duplicate (check \`list_task_suggestions\`), and withdraw one that stops applying. Do not mention suggestions in your reply.`;
23535
23541
  ALAN_IDENTITY_PROMPT = `You are Alan, the software factory agent. Alan ships software end to end \u2014 plan, write, review, test, deploy.
23536
23542
 
23537
23543
  ## How Alan is structured
@@ -23574,7 +23580,9 @@ When the user refers to a specific task, document, or epic by human identifier (
23574
23580
 
23575
23581
  ## Task Logging
23576
23582
 
23577
- For non-trivial tasks, log high-signal events as they happen: decisions, changed assumptions, validation results, known-good IDs, blockers, risks, direction changes, and session outcomes. Do not log routine commands or file reads. Before stopping, ensure the Agent Log and current session outcome are enough for a human to understand progress and for another agent to resume. If a prior event or decision is stale, supersede it instead of appending contradictory state.`;
23583
+ For non-trivial tasks, log high-signal events as they happen: decisions, changed assumptions, validation results, known-good IDs, blockers, risks, direction changes, and session outcomes. Do not log routine commands or file reads. Before stopping, ensure the Agent Log and current session outcome are enough for a human to understand progress and for another agent to resume. If a prior event or decision is stale, supersede it instead of appending contradictory state.
23584
+
23585
+ ${ALAN_SUGGESTING_WORK_PROMPT}`;
23578
23586
  ALAN_CODE_CONTEXT_PROMPT = buildAlanCodeContextPrompt();
23579
23587
  PLAN_MODE_PROMPT = [
23580
23588
  "You are in Alan plan mode.",
@@ -23940,6 +23948,17 @@ var init_models = __esm({
23940
23948
  contextWindow: 1048576,
23941
23949
  maxOutputTokens: HARNESS_MAX_OUTPUT_TOKENS
23942
23950
  },
23951
+ {
23952
+ id: "particle-ai/particle-1",
23953
+ name: "Particle-1",
23954
+ description: "Particle AI's token-efficient coding model via Alan",
23955
+ enabled: true,
23956
+ isDefault: false,
23957
+ sortOrder: 25,
23958
+ upstreamModelId: "particle-ai/particle-1",
23959
+ contextWindow: 1048576,
23960
+ maxOutputTokens: HARNESS_MAX_OUTPUT_TOKENS
23961
+ },
23943
23962
  {
23944
23963
  id: "z-ai/glm-5.3",
23945
23964
  name: "GLM 5.3",
@@ -39316,9 +39335,9 @@ function tokenCount(payload, state) {
39316
39335
  const totalRecord = asRecord(info?.total_token_usage);
39317
39336
  if (!totalRecord) return [];
39318
39337
  const total = rolloutTokens(totalRecord);
39319
- const lastRecord = asRecord(info?.last_token_usage);
39320
- if (lastRecord)
39321
- state.turnTokens.note(rolloutTokens(lastRecord), total, num(info?.model_context_window));
39338
+ const lastRecord2 = asRecord(info?.last_token_usage);
39339
+ if (lastRecord2)
39340
+ state.turnTokens.note(rolloutTokens(lastRecord2), total, num(info?.model_context_window));
39322
39341
  if (state.turnUsageSeen) return [];
39323
39342
  return reportedUsage(state.turnTokens.spend(total), state);
39324
39343
  }
@@ -40043,9 +40062,9 @@ var init_codex = __esm({
40043
40062
  }
40044
40063
  #usage(params) {
40045
40064
  const usage = asRecord(params.tokenUsage);
40046
- const lastRecord = asRecord(usage?.last);
40047
- if (!lastRecord) return [];
40048
- const last = appServerTokens(lastRecord);
40065
+ const lastRecord2 = asRecord(usage?.last);
40066
+ if (!lastRecord2) return [];
40067
+ const last = appServerTokens(lastRecord2);
40049
40068
  const totalRecord = asRecord(usage?.total);
40050
40069
  const total = totalRecord ? appServerTokens(totalRecord) : void 0;
40051
40070
  this.#tokens.note(last, total, asFiniteNumber(usage?.modelContextWindow));
@@ -53329,7 +53348,7 @@ var require_extract = __commonJS({
53329
53348
  var require_constants = __commonJS({
53330
53349
  "../../node_modules/tar-stream/constants.js"(exports2, module2) {
53331
53350
  "use strict";
53332
- var constants6 = {
53351
+ var constants7 = {
53333
53352
  // just for envs without fs
53334
53353
  S_IFMT: 61440,
53335
53354
  S_IFDIR: 16384,
@@ -53339,9 +53358,9 @@ var require_constants = __commonJS({
53339
53358
  S_IFLNK: 40960
53340
53359
  };
53341
53360
  try {
53342
- module2.exports = require("fs").constants || constants6;
53361
+ module2.exports = require("fs").constants || constants7;
53343
53362
  } catch {
53344
- module2.exports = constants6;
53363
+ module2.exports = constants7;
53345
53364
  }
53346
53365
  }
53347
53366
  });
@@ -53352,7 +53371,7 @@ var require_pack = __commonJS({
53352
53371
  "use strict";
53353
53372
  var { Readable: Readable2, Writable, getStreamError } = require_streamx();
53354
53373
  var b4a = require_b4a();
53355
- var constants6 = require_constants();
53374
+ var constants7 = require_constants();
53356
53375
  var headers = require_headers();
53357
53376
  var DMODE = 493;
53358
53377
  var FMODE = 420;
@@ -53555,16 +53574,16 @@ var require_pack = __commonJS({
53555
53574
  return new Pack(opts);
53556
53575
  };
53557
53576
  function modeToType(mode) {
53558
- switch (mode & constants6.S_IFMT) {
53559
- case constants6.S_IFBLK:
53577
+ switch (mode & constants7.S_IFMT) {
53578
+ case constants7.S_IFBLK:
53560
53579
  return "block-device";
53561
- case constants6.S_IFCHR:
53580
+ case constants7.S_IFCHR:
53562
53581
  return "character-device";
53563
- case constants6.S_IFDIR:
53582
+ case constants7.S_IFDIR:
53564
53583
  return "directory";
53565
- case constants6.S_IFIFO:
53584
+ case constants7.S_IFIFO:
53566
53585
  return "fifo";
53567
- case constants6.S_IFLNK:
53586
+ case constants7.S_IFLNK:
53568
53587
  return "symlink";
53569
53588
  }
53570
53589
  return "file";
@@ -58376,7 +58395,7 @@ var import_node_worker_threads2 = require("worker_threads");
58376
58395
  // package.json
58377
58396
  var package_default = {
58378
58397
  name: "@alan-ai-hq/agent-manager",
58379
- version: "0.1.171",
58398
+ version: "0.1.172",
58380
58399
  private: true,
58381
58400
  type: "module",
58382
58401
  description: "Alan machine runtime (alan-agent): identity, link, reconciler, session holders, run log, uploader, local API",
@@ -72645,9 +72664,24 @@ function tailWindows(size) {
72645
72664
  if (length >= size || length > MAX_RUN_LOG_RECORD_BYTES) return windows;
72646
72665
  }
72647
72666
  }
72648
- function lastLine(text3, wholeFile) {
72649
- const start2 = text3.lastIndexOf("\n") + 1;
72650
- return start2 === 0 && !wholeFile ? void 0 : text3.slice(start2);
72667
+ function parseRecord2(line) {
72668
+ try {
72669
+ const parsed = runLogRecordSchema.safeParse(JSON.parse(Buffer.from(line).toString("utf8")));
72670
+ return parsed.success ? parsed.data : null;
72671
+ } catch {
72672
+ return null;
72673
+ }
72674
+ }
72675
+ function lastRecord(window2, wholeFile) {
72676
+ let end = window2.lastIndexOf(RUN_LOG_RECORD_SEPARATOR) + 1;
72677
+ while (end > 0) {
72678
+ const start2 = end >= 2 ? window2.lastIndexOf(RUN_LOG_RECORD_SEPARATOR, end - 2) + 1 : 0;
72679
+ if (start2 === 0 && !wholeFile) return void 0;
72680
+ const record2 = parseRecord2(window2.subarray(start2, end - 1));
72681
+ if (record2 !== null) return { record: record2, end };
72682
+ end = start2;
72683
+ }
72684
+ return wholeFile ? null : void 0;
72651
72685
  }
72652
72686
 
72653
72687
  // src/run-log/reader.ts
@@ -72696,12 +72730,9 @@ async function readLastRecord(path4) {
72696
72730
  for (const length of tailWindows(size)) {
72697
72731
  const buffer = Buffer.alloc(length);
72698
72732
  await handle.read(buffer, 0, length, size - length);
72699
- const aligned = buffer.subarray(0, alignedLength(buffer)).toString("utf8").trimEnd();
72700
- const last = lastLine(aligned, length === size);
72733
+ const last = lastRecord(buffer, length === size);
72701
72734
  if (last === void 0) continue;
72702
- if (last.length === 0) return null;
72703
- const parsed = runLogRecordSchema.safeParse(JSON.parse(last));
72704
- return parsed.success ? parsed.data : null;
72735
+ return last?.record ?? null;
72705
72736
  }
72706
72737
  return null;
72707
72738
  } finally {
@@ -72725,24 +72756,33 @@ var decoder = new TextDecoder();
72725
72756
  var import_node_fs22 = require("fs");
72726
72757
  var import_node_path66 = require("path");
72727
72758
  init_runtime_v2();
72728
- function lastSeq(fd, size) {
72759
+ function readTail(fd, size) {
72729
72760
  for (const length of tailWindows(size)) {
72730
72761
  const buffer = Buffer.alloc(length);
72731
72762
  (0, import_node_fs22.readSync)(fd, buffer, 0, length, size - length);
72732
- const last = lastLine(buffer.toString("utf8").trimEnd(), length === size);
72763
+ const last = lastRecord(buffer, length === size);
72733
72764
  if (last === void 0) continue;
72734
- if (last.length === 0) return 0;
72735
- const parsed = runLogRecordSchema.safeParse(JSON.parse(last));
72736
- if (!parsed.success) throw new RuntimeFault("invalid_file", "Run log tail is not a record");
72737
- return parsed.data.seq;
72765
+ if (last === null) return { seq: 0, end: 0 };
72766
+ return { seq: last.record.seq, end: size - length + last.end };
72738
72767
  }
72739
72768
  throw new RuntimeFault("record_too_large", "Run log tail record is larger than any record");
72740
72769
  }
72770
+ function writeAt(fd, bytes, position) {
72771
+ for (let written = 0; written < bytes.length; ) {
72772
+ written += (0, import_node_fs22.writeSync)(fd, bytes, written, bytes.length - written, position + written);
72773
+ }
72774
+ }
72741
72775
  function openRunLog(path4, clock) {
72742
72776
  (0, import_node_fs22.mkdirSync)((0, import_node_path66.dirname)(path4), { recursive: true, mode: 448 });
72743
- const fd = (0, import_node_fs22.openSync)(path4, "a+", 384);
72744
- let size = (0, import_node_fs22.fstatSync)(fd).size;
72745
- let seq = lastSeq(fd, size);
72777
+ const fd = (0, import_node_fs22.openSync)(path4, import_node_fs22.constants.O_RDWR | import_node_fs22.constants.O_CREAT, 384);
72778
+ const fileSize = (0, import_node_fs22.fstatSync)(fd).size;
72779
+ const tail = readTail(fd, fileSize);
72780
+ let size = tail.end;
72781
+ let seq = tail.seq;
72782
+ if (fileSize > size) {
72783
+ (0, import_node_fs22.ftruncateSync)(fd, size);
72784
+ (0, import_node_fs22.fsyncSync)(fd);
72785
+ }
72746
72786
  let dirty = false;
72747
72787
  const sync = () => {
72748
72788
  (0, import_node_fs22.fsyncSync)(fd);
@@ -72750,16 +72790,21 @@ function openRunLog(path4, clock) {
72750
72790
  };
72751
72791
  return {
72752
72792
  append: (update, sessionId) => {
72753
- seq += 1;
72754
72793
  const record2 = {
72755
- seq,
72794
+ seq: seq + 1,
72756
72795
  at: clock.now(),
72757
72796
  ...sessionId === void 0 ? {} : { sessionId },
72758
72797
  update
72759
72798
  };
72760
72799
  const line = Buffer.from(`${JSON.stringify(record2)}
72761
72800
  `, "utf8");
72762
- (0, import_node_fs22.writeSync)(fd, line);
72801
+ try {
72802
+ writeAt(fd, line, size);
72803
+ } catch (error62) {
72804
+ (0, import_node_fs22.ftruncateSync)(fd, size);
72805
+ throw error62;
72806
+ }
72807
+ seq = record2.seq;
72763
72808
  size += line.length;
72764
72809
  dirty = true;
72765
72810
  if (isRunLifecycleKind(update.sessionUpdate)) sync();
@@ -72905,16 +72950,58 @@ async function claimRun(spec, context) {
72905
72950
  }
72906
72951
  return log;
72907
72952
  }
72953
+ var RUN_END_RETRY_MS = 5e3;
72954
+ var RUN_END_DEADLINE_MS = 10 * 6e4;
72908
72955
  async function runClaimedTurn(spec, claimed, context, signal) {
72909
72956
  var _stack = [];
72910
72957
  try {
72911
72958
  const log = __using(_stack, claimed);
72912
72959
  const reported = { error: false };
72960
+ const writeFailed = new AbortController();
72961
+ let writeError;
72913
72962
  const append = (update, sessionId) => {
72963
+ if (writeError !== void 0) return;
72914
72964
  if (update.sessionUpdate === "notice" && update.severity === "error") reported.error = true;
72915
- const offset = log.append(update, sessionId);
72965
+ let offset;
72966
+ try {
72967
+ offset = log.append(update, sessionId);
72968
+ } catch (error62) {
72969
+ writeError = error62;
72970
+ context.log.error("holder.run_log_write_failed", { runId: spec.runId, error: error62 });
72971
+ writeFailed.abort();
72972
+ return;
72973
+ }
72916
72974
  context.onAppended(spec.runId, offset);
72917
72975
  };
72976
+ const endRun = async (updates2) => {
72977
+ const deadline = context.clock.monotonic() + RUN_END_DEADLINE_MS;
72978
+ for (const update of updates2) {
72979
+ for (; ; ) {
72980
+ let offset;
72981
+ try {
72982
+ offset = log.append(update);
72983
+ } catch (error62) {
72984
+ context.log.warn("holder.run_end_write_failed", { runId: spec.runId, error: error62 });
72985
+ if (context.clock.monotonic() >= deadline) {
72986
+ throw new RuntimeFault("io_failed", `Run ${spec.runId} could not be ended`, {
72987
+ cause: error62
72988
+ });
72989
+ }
72990
+ await context.clock.sleep(RUN_END_RETRY_MS, new AbortController().signal);
72991
+ continue;
72992
+ }
72993
+ context.onAppended(spec.runId, offset);
72994
+ break;
72995
+ }
72996
+ }
72997
+ };
72998
+ const fail = async (message2) => {
72999
+ await endRun([
73000
+ noticeUpdate("error", "run_failed", message2),
73001
+ runEnded({ outcome: "failed", message: message2 })
73002
+ ]);
73003
+ return "failed";
73004
+ };
72918
73005
  let result;
72919
73006
  try {
72920
73007
  result = await admitAndRun(
@@ -72925,20 +73012,22 @@ async function runClaimedTurn(spec, claimed, context, signal) {
72925
73012
  // Base64 media in provider payloads and tool output never reaches the log (main 13590db369).
72926
73013
  onEvent: (event) => append(fitForRunLog(withoutInlineMedia(event.update)), event.sessionId)
72927
73014
  },
72928
- signal
73015
+ AbortSignal.any([signal, writeFailed.signal])
72929
73016
  );
72930
73017
  } catch (error62) {
72931
- const message2 = error62 instanceof Error ? error62.message : String(error62);
72932
73018
  context.log.error("holder.turn_threw", { runId: spec.runId, error: error62 });
72933
- append(noticeUpdate("error", "run_failed", message2));
72934
- append(runEnded({ outcome: "failed", message: message2 }));
72935
- return "failed";
73019
+ return await fail(error62 instanceof Error ? error62.message : String(error62));
73020
+ }
73021
+ if (writeError !== void 0) {
73022
+ const reason = writeError instanceof Error ? writeError.message : String(writeError);
73023
+ return await fail(`This run's log could not be written: ${reason}`);
72936
73024
  }
72937
73025
  const outcome2 = result.outcome === "aborted" && signal.reason === "interrupted" ? "interrupted" : result.outcome;
73026
+ const updates = [];
72938
73027
  if (outcome2 === "failed" && !reported.error && result.message !== void 0) {
72939
- append(noticeUpdate("error", "run_failed", result.message));
73028
+ updates.push(noticeUpdate("error", "run_failed", result.message));
72940
73029
  }
72941
- append(
73030
+ updates.push(
72942
73031
  runEnded({
72943
73032
  outcome: outcome2,
72944
73033
  ...result.providerSessionId === void 0 ? {} : { providerSessionId: result.providerSessionId },
@@ -72948,6 +73037,7 @@ async function runClaimedTurn(spec, claimed, context, signal) {
72948
73037
  ...result.unansweredSteerIds === void 0 ? {} : { unansweredSteerIds: [...result.unansweredSteerIds] }
72949
73038
  })
72950
73039
  );
73040
+ await endRun(updates);
72951
73041
  context.log.info("holder.turn_ended", { runId: spec.runId, outcome: outcome2 });
72952
73042
  return outcome2;
72953
73043
  } catch (_) {
@@ -82086,12 +82176,17 @@ var CAPABILITIES_ACK_TIMEOUT_MS = 1e4;
82086
82176
  var REDIAL_BASE_MS = 1e3;
82087
82177
  var REDIAL_MAX_MS = 1e4;
82088
82178
  var MAX_CREDENTIAL_FAILURES = 3;
82179
+ var CREDENTIAL_RETRY_BASE_MS = 3e4;
82180
+ var CREDENTIAL_RETRY_MAX_MS = 5 * 6e4;
82089
82181
  var DISABLED_RETRY_MS = 5 * 6e4;
82090
82182
  var WAKE_PROBE_MS = 5e3;
82091
82183
  var SERVER_DROPS_SILENT_SOCKET_MS = 55e3;
82092
82184
  function redialDelayMs(attempt2) {
82093
82185
  return Math.min(REDIAL_BASE_MS * 2 ** attempt2, REDIAL_MAX_MS) * (0.5 + 0.5 * Math.random());
82094
82186
  }
82187
+ function credentialRetryDelayMs(slowAttempt) {
82188
+ return Math.min(CREDENTIAL_RETRY_BASE_MS * 2 ** slowAttempt, CREDENTIAL_RETRY_MAX_MS);
82189
+ }
82095
82190
  async function answerWorkspaceQuery(raw, options, log) {
82096
82191
  const parsed = workspaceQueryRequestSchema.safeParse(raw);
82097
82192
  if (!parsed.success) {
@@ -82187,6 +82282,12 @@ function connectLink(options) {
82187
82282
  redialAfter(redialDelayMs(retry.attempt++), options.refreshCredential);
82188
82283
  return;
82189
82284
  }
82285
+ stop(failure7);
82286
+ redialAfter(
82287
+ credentialRetryDelayMs(retry.credentialFailures - MAX_CREDENTIAL_FAILURES),
82288
+ options.refreshCredential
82289
+ );
82290
+ return;
82190
82291
  }
82191
82292
  stop(failure7);
82192
82293
  if (refusal2.code === "machine_disabled") redialAfter(DISABLED_RETRY_MS);
package/alan-holder.cjs CHANGED
@@ -22257,7 +22257,7 @@ var init_cli_usage = __esm({
22257
22257
  function isRunLifecycleKind(sessionUpdate2) {
22258
22258
  return RUN_LIFECYCLE_KINDS.has(sessionUpdate2);
22259
22259
  }
22260
- var RUN_STEERS_MAX, runAcceptedUpdateSchema, runStartedUpdateSchema, runCodexRateLimitsUpdateSchema, runWorkspaceRelocatedUpdateSchema, runOutcomeSchema, runRejectionCodeSchema, runEndedUpdateSchema, runLifecycleUpdateSchema, RUN_LIFECYCLE_KINDS, runLogRecordSchema;
22260
+ var RUN_LOG_RECORD_SEPARATOR, RUN_STEERS_MAX, runAcceptedUpdateSchema, runStartedUpdateSchema, runCodexRateLimitsUpdateSchema, runWorkspaceRelocatedUpdateSchema, runOutcomeSchema, runRejectionCodeSchema, runEndedUpdateSchema, runLifecycleUpdateSchema, RUN_LIFECYCLE_KINDS, runLogRecordSchema;
22261
22261
  var init_run_log = __esm({
22262
22262
  "../shared/dist/runtime-v2/run-log.js"() {
22263
22263
  "use strict";
@@ -22265,6 +22265,7 @@ var init_run_log = __esm({
22265
22265
  init_problem();
22266
22266
  init_cli_usage();
22267
22267
  init_ids();
22268
+ RUN_LOG_RECORD_SEPARATOR = 10;
22268
22269
  RUN_STEERS_MAX = 100;
22269
22270
  runAcceptedUpdateSchema = external_exports.object({
22270
22271
  sessionUpdate: external_exports.literal("_alan/run.accepted"),
@@ -23334,7 +23335,7 @@ function getAlanModePrompt(mode) {
23334
23335
  function getAlanAgentPrompt(agentId) {
23335
23336
  return getAgentSystemPrompt(agentId);
23336
23337
  }
23337
- var ALAN_CONTEXT_SEARCH_PROMPT, ALAN_PLATFORM_TOOL_ROUTING_PROMPT, ALAN_OPENUI_COMPONENT_SIGNATURES, ALAN_VISUAL_PROMPT, ALAN_VISUAL_REMINDER_PROMPT, ALAN_IDENTITY_PROMPT, ALAN_CODE_CONTEXT_PROMPT, PLAN_MODE_PROMPT, ASK_MODE_PROMPT, REVIEW_MODE_PROMPT;
23338
+ var ALAN_CONTEXT_SEARCH_PROMPT, ALAN_PLATFORM_TOOL_ROUTING_PROMPT, ALAN_OPENUI_COMPONENT_SIGNATURES, ALAN_VISUAL_PROMPT, ALAN_VISUAL_REMINDER_PROMPT, ALAN_SUGGESTING_WORK_PROMPT, ALAN_IDENTITY_PROMPT, ALAN_CODE_CONTEXT_PROMPT, PLAN_MODE_PROMPT, ASK_MODE_PROMPT, REVIEW_MODE_PROMPT;
23338
23339
  var init_system_prompt = __esm({
23339
23340
  "../shared/dist/agent/system-prompt.js"() {
23340
23341
  "use strict";
@@ -23413,6 +23414,12 @@ ${ALAN_OPENUI_COMPONENT_SIGNATURES.map((signature) => ` ${signature}`).join("\n
23413
23414
  ALAN_VISUAL_REMINDER_PROMPT = `## Answer format
23414
23415
 
23415
23416
  Before replying in the Alan chat, consider what the user is trying to do and whether a visual would serve it better than paragraphs: comparisons, trends, statuses, timelines, plans and options go in a \`\`\`chart, \`\`\`mermaid or \`\`\`openui block even when nobody asked for one. Trivial answers stay plain text.`;
23417
+ ALAN_SUGGESTING_WORK_PROMPT = `## Suggesting Work
23418
+
23419
+ When \`suggest_task\` is available, use it to put work in the session's side panel for the user to pick up; it creates nothing by itself.
23420
+ - \`convert_session\`: suggest once when a chat that is not linked to a task has turned into multi-step delivery work (code changes, a PR, several turns). Give the title and description the task should have.
23421
+ - \`follow_up\`: suggest real, separate work you found and did not do, such as a bug, risky debt or a missing test. Never the next step of the current request or work you are about to do. Include \`handoffContext\` with what a fresh session needs: verified findings, files, decisions.
23422
+ - Prefer none. At most three in a turn, never a duplicate (check \`list_task_suggestions\`), and withdraw one that stops applying. Do not mention suggestions in your reply.`;
23416
23423
  ALAN_IDENTITY_PROMPT = `You are Alan, the software factory agent. Alan ships software end to end \u2014 plan, write, review, test, deploy.
23417
23424
 
23418
23425
  ## How Alan is structured
@@ -23455,7 +23462,9 @@ When the user refers to a specific task, document, or epic by human identifier (
23455
23462
 
23456
23463
  ## Task Logging
23457
23464
 
23458
- For non-trivial tasks, log high-signal events as they happen: decisions, changed assumptions, validation results, known-good IDs, blockers, risks, direction changes, and session outcomes. Do not log routine commands or file reads. Before stopping, ensure the Agent Log and current session outcome are enough for a human to understand progress and for another agent to resume. If a prior event or decision is stale, supersede it instead of appending contradictory state.`;
23465
+ For non-trivial tasks, log high-signal events as they happen: decisions, changed assumptions, validation results, known-good IDs, blockers, risks, direction changes, and session outcomes. Do not log routine commands or file reads. Before stopping, ensure the Agent Log and current session outcome are enough for a human to understand progress and for another agent to resume. If a prior event or decision is stale, supersede it instead of appending contradictory state.
23466
+
23467
+ ${ALAN_SUGGESTING_WORK_PROMPT}`;
23459
23468
  ALAN_CODE_CONTEXT_PROMPT = buildAlanCodeContextPrompt();
23460
23469
  PLAN_MODE_PROMPT = [
23461
23470
  "You are in Alan plan mode.",
@@ -23805,6 +23814,17 @@ var init_models = __esm({
23805
23814
  contextWindow: 1048576,
23806
23815
  maxOutputTokens: HARNESS_MAX_OUTPUT_TOKENS
23807
23816
  },
23817
+ {
23818
+ id: "particle-ai/particle-1",
23819
+ name: "Particle-1",
23820
+ description: "Particle AI's token-efficient coding model via Alan",
23821
+ enabled: true,
23822
+ isDefault: false,
23823
+ sortOrder: 25,
23824
+ upstreamModelId: "particle-ai/particle-1",
23825
+ contextWindow: 1048576,
23826
+ maxOutputTokens: HARNESS_MAX_OUTPUT_TOKENS
23827
+ },
23808
23828
  {
23809
23829
  id: "z-ai/glm-5.3",
23810
23830
  name: "GLM 5.3",
@@ -37126,9 +37146,9 @@ var init_codex = __esm({
37126
37146
  }
37127
37147
  #usage(params) {
37128
37148
  const usage = asRecord(params.tokenUsage);
37129
- const lastRecord = asRecord(usage?.last);
37130
- if (!lastRecord) return [];
37131
- const last = appServerTokens(lastRecord);
37149
+ const lastRecord2 = asRecord(usage?.last);
37150
+ if (!lastRecord2) return [];
37151
+ const last = appServerTokens(lastRecord2);
37132
37152
  const totalRecord = asRecord(usage?.total);
37133
37153
  const total = totalRecord ? appServerTokens(totalRecord) : void 0;
37134
37154
  this.#tokens.note(last, total, asFiniteNumber(usage?.modelContextWindow));
@@ -51699,9 +51719,24 @@ function tailWindows(size) {
51699
51719
  if (length >= size || length > MAX_RUN_LOG_RECORD_BYTES) return windows;
51700
51720
  }
51701
51721
  }
51702
- function lastLine(text2, wholeFile) {
51703
- const start = text2.lastIndexOf("\n") + 1;
51704
- return start === 0 && !wholeFile ? void 0 : text2.slice(start);
51722
+ function parseRecord(line) {
51723
+ try {
51724
+ const parsed = runLogRecordSchema.safeParse(JSON.parse(Buffer.from(line).toString("utf8")));
51725
+ return parsed.success ? parsed.data : null;
51726
+ } catch {
51727
+ return null;
51728
+ }
51729
+ }
51730
+ function lastRecord(window, wholeFile) {
51731
+ let end = window.lastIndexOf(RUN_LOG_RECORD_SEPARATOR) + 1;
51732
+ while (end > 0) {
51733
+ const start = end >= 2 ? window.lastIndexOf(RUN_LOG_RECORD_SEPARATOR, end - 2) + 1 : 0;
51734
+ if (start === 0 && !wholeFile) return void 0;
51735
+ const record2 = parseRecord(window.subarray(start, end - 1));
51736
+ if (record2 !== null) return { record: record2, end };
51737
+ end = start;
51738
+ }
51739
+ return wholeFile ? null : void 0;
51705
51740
  }
51706
51741
 
51707
51742
  // src/run-log/records.ts
@@ -51720,24 +51755,33 @@ var decoder = new TextDecoder();
51720
51755
  var import_node_fs10 = require("fs");
51721
51756
  var import_node_path28 = require("path");
51722
51757
  init_runtime_v2();
51723
- function lastSeq(fd, size) {
51758
+ function readTail(fd, size) {
51724
51759
  for (const length of tailWindows(size)) {
51725
51760
  const buffer = Buffer.alloc(length);
51726
51761
  (0, import_node_fs10.readSync)(fd, buffer, 0, length, size - length);
51727
- const last = lastLine(buffer.toString("utf8").trimEnd(), length === size);
51762
+ const last = lastRecord(buffer, length === size);
51728
51763
  if (last === void 0) continue;
51729
- if (last.length === 0) return 0;
51730
- const parsed = runLogRecordSchema.safeParse(JSON.parse(last));
51731
- if (!parsed.success) throw new RuntimeFault("invalid_file", "Run log tail is not a record");
51732
- return parsed.data.seq;
51764
+ if (last === null) return { seq: 0, end: 0 };
51765
+ return { seq: last.record.seq, end: size - length + last.end };
51733
51766
  }
51734
51767
  throw new RuntimeFault("record_too_large", "Run log tail record is larger than any record");
51735
51768
  }
51769
+ function writeAt(fd, bytes, position) {
51770
+ for (let written = 0; written < bytes.length; ) {
51771
+ written += (0, import_node_fs10.writeSync)(fd, bytes, written, bytes.length - written, position + written);
51772
+ }
51773
+ }
51736
51774
  function openRunLog(path, clock) {
51737
51775
  (0, import_node_fs10.mkdirSync)((0, import_node_path28.dirname)(path), { recursive: true, mode: 448 });
51738
- const fd = (0, import_node_fs10.openSync)(path, "a+", 384);
51739
- let size = (0, import_node_fs10.fstatSync)(fd).size;
51740
- let seq = lastSeq(fd, size);
51776
+ const fd = (0, import_node_fs10.openSync)(path, import_node_fs10.constants.O_RDWR | import_node_fs10.constants.O_CREAT, 384);
51777
+ const fileSize = (0, import_node_fs10.fstatSync)(fd).size;
51778
+ const tail = readTail(fd, fileSize);
51779
+ let size = tail.end;
51780
+ let seq = tail.seq;
51781
+ if (fileSize > size) {
51782
+ (0, import_node_fs10.ftruncateSync)(fd, size);
51783
+ (0, import_node_fs10.fsyncSync)(fd);
51784
+ }
51741
51785
  let dirty = false;
51742
51786
  const sync = () => {
51743
51787
  (0, import_node_fs10.fsyncSync)(fd);
@@ -51745,16 +51789,21 @@ function openRunLog(path, clock) {
51745
51789
  };
51746
51790
  return {
51747
51791
  append: (update, sessionId) => {
51748
- seq += 1;
51749
51792
  const record2 = {
51750
- seq,
51793
+ seq: seq + 1,
51751
51794
  at: clock.now(),
51752
51795
  ...sessionId === void 0 ? {} : { sessionId },
51753
51796
  update
51754
51797
  };
51755
51798
  const line = Buffer.from(`${JSON.stringify(record2)}
51756
51799
  `, "utf8");
51757
- (0, import_node_fs10.writeSync)(fd, line);
51800
+ try {
51801
+ writeAt(fd, line, size);
51802
+ } catch (error62) {
51803
+ (0, import_node_fs10.ftruncateSync)(fd, size);
51804
+ throw error62;
51805
+ }
51806
+ seq = record2.seq;
51758
51807
  size += line.length;
51759
51808
  dirty = true;
51760
51809
  if (isRunLifecycleKind(update.sessionUpdate)) sync();
@@ -51900,16 +51949,58 @@ async function claimRun(spec, context) {
51900
51949
  }
51901
51950
  return log;
51902
51951
  }
51952
+ var RUN_END_RETRY_MS = 5e3;
51953
+ var RUN_END_DEADLINE_MS = 10 * 6e4;
51903
51954
  async function runClaimedTurn(spec, claimed, context, signal) {
51904
51955
  var _stack = [];
51905
51956
  try {
51906
51957
  const log = __using(_stack, claimed);
51907
51958
  const reported = { error: false };
51959
+ const writeFailed = new AbortController();
51960
+ let writeError;
51908
51961
  const append = (update, sessionId) => {
51962
+ if (writeError !== void 0) return;
51909
51963
  if (update.sessionUpdate === "notice" && update.severity === "error") reported.error = true;
51910
- const offset = log.append(update, sessionId);
51964
+ let offset;
51965
+ try {
51966
+ offset = log.append(update, sessionId);
51967
+ } catch (error62) {
51968
+ writeError = error62;
51969
+ context.log.error("holder.run_log_write_failed", { runId: spec.runId, error: error62 });
51970
+ writeFailed.abort();
51971
+ return;
51972
+ }
51911
51973
  context.onAppended(spec.runId, offset);
51912
51974
  };
51975
+ const endRun = async (updates2) => {
51976
+ const deadline = context.clock.monotonic() + RUN_END_DEADLINE_MS;
51977
+ for (const update of updates2) {
51978
+ for (; ; ) {
51979
+ let offset;
51980
+ try {
51981
+ offset = log.append(update);
51982
+ } catch (error62) {
51983
+ context.log.warn("holder.run_end_write_failed", { runId: spec.runId, error: error62 });
51984
+ if (context.clock.monotonic() >= deadline) {
51985
+ throw new RuntimeFault("io_failed", `Run ${spec.runId} could not be ended`, {
51986
+ cause: error62
51987
+ });
51988
+ }
51989
+ await context.clock.sleep(RUN_END_RETRY_MS, new AbortController().signal);
51990
+ continue;
51991
+ }
51992
+ context.onAppended(spec.runId, offset);
51993
+ break;
51994
+ }
51995
+ }
51996
+ };
51997
+ const fail = async (message) => {
51998
+ await endRun([
51999
+ noticeUpdate("error", "run_failed", message),
52000
+ runEnded({ outcome: "failed", message })
52001
+ ]);
52002
+ return "failed";
52003
+ };
51913
52004
  let result;
51914
52005
  try {
51915
52006
  result = await admitAndRun(
@@ -51920,20 +52011,22 @@ async function runClaimedTurn(spec, claimed, context, signal) {
51920
52011
  // Base64 media in provider payloads and tool output never reaches the log (main 13590db369).
51921
52012
  onEvent: (event) => append(fitForRunLog(withoutInlineMedia(event.update)), event.sessionId)
51922
52013
  },
51923
- signal
52014
+ AbortSignal.any([signal, writeFailed.signal])
51924
52015
  );
51925
52016
  } catch (error62) {
51926
- const message = error62 instanceof Error ? error62.message : String(error62);
51927
52017
  context.log.error("holder.turn_threw", { runId: spec.runId, error: error62 });
51928
- append(noticeUpdate("error", "run_failed", message));
51929
- append(runEnded({ outcome: "failed", message }));
51930
- return "failed";
52018
+ return await fail(error62 instanceof Error ? error62.message : String(error62));
52019
+ }
52020
+ if (writeError !== void 0) {
52021
+ const reason = writeError instanceof Error ? writeError.message : String(writeError);
52022
+ return await fail(`This run's log could not be written: ${reason}`);
51931
52023
  }
51932
52024
  const outcome2 = result.outcome === "aborted" && signal.reason === "interrupted" ? "interrupted" : result.outcome;
52025
+ const updates = [];
51933
52026
  if (outcome2 === "failed" && !reported.error && result.message !== void 0) {
51934
- append(noticeUpdate("error", "run_failed", result.message));
52027
+ updates.push(noticeUpdate("error", "run_failed", result.message));
51935
52028
  }
51936
- append(
52029
+ updates.push(
51937
52030
  runEnded({
51938
52031
  outcome: outcome2,
51939
52032
  ...result.providerSessionId === void 0 ? {} : { providerSessionId: result.providerSessionId },
@@ -51943,6 +52036,7 @@ async function runClaimedTurn(spec, claimed, context, signal) {
51943
52036
  ...result.unansweredSteerIds === void 0 ? {} : { unansweredSteerIds: [...result.unansweredSteerIds] }
51944
52037
  })
51945
52038
  );
52039
+ await endRun(updates);
51946
52040
  context.log.info("holder.turn_ended", { runId: spec.runId, outcome: outcome2 });
51947
52041
  return outcome2;
51948
52042
  } catch (_) {
package/alan-lease.cjs CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alan-ai-hq/agent-manager-darwin-arm64",
3
- "version": "0.1.171",
3
+ "version": "0.1.172",
4
4
  "description": "Alan machine runtime (alan-agent) for one platform: the official Node.js binary, the runtime bundle and its launcher. Installed by @alan-ai-hq/agent-manager.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://tryalan.ai",