@parall/parall 1.58.2 → 1.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17717,9 +17717,9 @@ var require_getMachineId_linux = __commonJS({
17717
17717
  var api_1 = (init_esm(), __toCommonJS(esm_exports));
17718
17718
  async function getMachineId() {
17719
17719
  const paths = ["/etc/machine-id", "/var/lib/dbus/machine-id"];
17720
- for (const path9 of paths) {
17720
+ for (const path10 of paths) {
17721
17721
  try {
17722
- const result = await fs_1.promises.readFile(path9, { encoding: "utf8" });
17722
+ const result = await fs_1.promises.readFile(path10, { encoding: "utf8" });
17723
17723
  return result.trim();
17724
17724
  } catch (e) {
17725
17725
  api_1.diag.debug(`error reading machine id: ${e}`);
@@ -21122,7 +21122,7 @@ function appendRootPathToUrlIfNeeded(url) {
21122
21122
  return void 0;
21123
21123
  }
21124
21124
  }
21125
- function appendResourcePathToUrl(url, path9) {
21125
+ function appendResourcePathToUrl(url, path10) {
21126
21126
  try {
21127
21127
  new URL(url);
21128
21128
  } catch (_a) {
@@ -21132,11 +21132,11 @@ function appendResourcePathToUrl(url, path9) {
21132
21132
  if (!url.endsWith("/")) {
21133
21133
  url = url + "/";
21134
21134
  }
21135
- url += path9;
21135
+ url += path10;
21136
21136
  try {
21137
21137
  new URL(url);
21138
21138
  } catch (_b) {
21139
- diag2.warn("Configuration: Provided URL appended with '" + path9 + "' is not a valid URL, using 'undefined' instead of '" + url + "'");
21139
+ diag2.warn("Configuration: Provided URL appended with '" + path10 + "' is not a valid URL, using 'undefined' instead of '" + url + "'");
21140
21140
  return void 0;
21141
21141
  }
21142
21142
  return url;
@@ -27547,14 +27547,14 @@ var require_util2 = __commonJS({
27547
27547
  }
27548
27548
  const port = url.port != null ? url.port : url.protocol === "https:" ? 443 : 80;
27549
27549
  let origin = url.origin != null ? url.origin : `${url.protocol || ""}//${url.hostname || ""}:${port}`;
27550
- let path9 = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`;
27550
+ let path10 = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`;
27551
27551
  if (origin[origin.length - 1] === "/") {
27552
27552
  origin = origin.slice(0, origin.length - 1);
27553
27553
  }
27554
- if (path9 && path9[0] !== "/") {
27555
- path9 = `/${path9}`;
27554
+ if (path10 && path10[0] !== "/") {
27555
+ path10 = `/${path10}`;
27556
27556
  }
27557
- return new URL(`${origin}${path9}`);
27557
+ return new URL(`${origin}${path10}`);
27558
27558
  }
27559
27559
  if (!isHttpOrHttpsPrefixed(url.origin || url.protocol)) {
27560
27560
  throw new InvalidArgumentError("Invalid URL protocol: the URL must start with `http:` or `https:`.");
@@ -28375,9 +28375,9 @@ var require_diagnostics = __commonJS({
28375
28375
  "undici:client:sendHeaders",
28376
28376
  (evt) => {
28377
28377
  const {
28378
- request: { method, path: path9, origin }
28378
+ request: { method, path: path10, origin }
28379
28379
  } = evt;
28380
- debugLog("sending request to %s %s%s", method, origin, path9);
28380
+ debugLog("sending request to %s %s%s", method, origin, path10);
28381
28381
  }
28382
28382
  );
28383
28383
  }
@@ -28395,14 +28395,14 @@ var require_diagnostics = __commonJS({
28395
28395
  "undici:request:headers",
28396
28396
  (evt) => {
28397
28397
  const {
28398
- request: { method, path: path9, origin },
28398
+ request: { method, path: path10, origin },
28399
28399
  response: { statusCode }
28400
28400
  } = evt;
28401
28401
  debugLog(
28402
28402
  "received response to %s %s%s - HTTP %d",
28403
28403
  method,
28404
28404
  origin,
28405
- path9,
28405
+ path10,
28406
28406
  statusCode
28407
28407
  );
28408
28408
  }
@@ -28411,23 +28411,23 @@ var require_diagnostics = __commonJS({
28411
28411
  "undici:request:trailers",
28412
28412
  (evt) => {
28413
28413
  const {
28414
- request: { method, path: path9, origin }
28414
+ request: { method, path: path10, origin }
28415
28415
  } = evt;
28416
- debugLog("trailers received from %s %s%s", method, origin, path9);
28416
+ debugLog("trailers received from %s %s%s", method, origin, path10);
28417
28417
  }
28418
28418
  );
28419
28419
  diagnosticsChannel.subscribe(
28420
28420
  "undici:request:error",
28421
28421
  (evt) => {
28422
28422
  const {
28423
- request: { method, path: path9, origin },
28423
+ request: { method, path: path10, origin },
28424
28424
  error
28425
28425
  } = evt;
28426
28426
  debugLog(
28427
28427
  "request to %s %s%s errored - %s",
28428
28428
  method,
28429
28429
  origin,
28430
- path9,
28430
+ path10,
28431
28431
  error.message
28432
28432
  );
28433
28433
  }
@@ -28530,7 +28530,7 @@ var require_request = __commonJS({
28530
28530
  var kHandler = Symbol("handler");
28531
28531
  var Request = class {
28532
28532
  constructor(origin, {
28533
- path: path9,
28533
+ path: path10,
28534
28534
  method,
28535
28535
  body,
28536
28536
  headers,
@@ -28547,11 +28547,11 @@ var require_request = __commonJS({
28547
28547
  maxRedirections,
28548
28548
  typeOfService
28549
28549
  }, handler) {
28550
- if (typeof path9 !== "string") {
28550
+ if (typeof path10 !== "string") {
28551
28551
  throw new InvalidArgumentError("path must be a string");
28552
- } else if (path9[0] !== "/" && !(path9.startsWith("http://") || path9.startsWith("https://")) && method !== "CONNECT") {
28552
+ } else if (path10[0] !== "/" && !(path10.startsWith("http://") || path10.startsWith("https://")) && method !== "CONNECT") {
28553
28553
  throw new InvalidArgumentError("path must be an absolute URL or start with a slash");
28554
- } else if (invalidPathRegex.test(path9)) {
28554
+ } else if (invalidPathRegex.test(path10)) {
28555
28555
  throw new InvalidArgumentError("invalid request path");
28556
28556
  }
28557
28557
  if (typeof method !== "string") {
@@ -28626,7 +28626,7 @@ var require_request = __commonJS({
28626
28626
  this.completed = false;
28627
28627
  this.aborted = false;
28628
28628
  this.upgrade = upgrade || null;
28629
- this.path = query ? serializePathWithQuery(path9, query) : path9;
28629
+ this.path = query ? serializePathWithQuery(path10, query) : path10;
28630
28630
  this.origin = origin;
28631
28631
  this.protocol = getProtocolFromUrlString(origin);
28632
28632
  this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent;
@@ -33665,7 +33665,7 @@ var require_client_h1 = __commonJS({
33665
33665
  return method !== "GET" && method !== "HEAD" && method !== "OPTIONS" && method !== "TRACE" && method !== "CONNECT";
33666
33666
  }
33667
33667
  function writeH1(client, request3) {
33668
- const { method, path: path9, host, upgrade, blocking, reset } = request3;
33668
+ const { method, path: path10, host, upgrade, blocking, reset } = request3;
33669
33669
  let { body, headers, contentLength } = request3;
33670
33670
  const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH" || method === "QUERY" || method === "PROPFIND" || method === "PROPPATCH";
33671
33671
  if (util.isFormDataLike(body)) {
@@ -33734,7 +33734,7 @@ var require_client_h1 = __commonJS({
33734
33734
  if (socket.setTypeOfService) {
33735
33735
  socket.setTypeOfService(request3.typeOfService);
33736
33736
  }
33737
- let header = `${method} ${path9} HTTP/1.1\r
33737
+ let header = `${method} ${path10} HTTP/1.1\r
33738
33738
  `;
33739
33739
  if (typeof host === "string") {
33740
33740
  header += `host: ${host}\r
@@ -34387,7 +34387,7 @@ var require_client_h2 = __commonJS({
34387
34387
  function writeH2(client, request3) {
34388
34388
  const requestTimeout = request3.bodyTimeout ?? client[kBodyTimeout];
34389
34389
  const session = client[kHTTP2Session];
34390
- const { method, path: path9, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request3;
34390
+ const { method, path: path10, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request3;
34391
34391
  let { body } = request3;
34392
34392
  if (upgrade != null && upgrade !== "websocket") {
34393
34393
  util.errorRequest(client, request3, new InvalidArgumentError(`Custom upgrade "${upgrade}" not supported over HTTP/2`));
@@ -34455,7 +34455,7 @@ var require_client_h2 = __commonJS({
34455
34455
  }
34456
34456
  headers[HTTP2_HEADER_METHOD] = "CONNECT";
34457
34457
  headers[HTTP2_HEADER_PROTOCOL] = "websocket";
34458
- headers[HTTP2_HEADER_PATH] = path9;
34458
+ headers[HTTP2_HEADER_PATH] = path10;
34459
34459
  if (protocol === "ws:" || protocol === "wss:") {
34460
34460
  headers[HTTP2_HEADER_SCHEME] = protocol === "ws:" ? "http" : "https";
34461
34461
  } else {
@@ -34496,7 +34496,7 @@ var require_client_h2 = __commonJS({
34496
34496
  stream.setTimeout(requestTimeout);
34497
34497
  return true;
34498
34498
  }
34499
- headers[HTTP2_HEADER_PATH] = path9;
34499
+ headers[HTTP2_HEADER_PATH] = path10;
34500
34500
  headers[HTTP2_HEADER_SCHEME] = protocol === "http:" ? "http" : "https";
34501
34501
  const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH";
34502
34502
  if (body && typeof body.read === "function") {
@@ -36798,10 +36798,10 @@ var require_proxy_agent = __commonJS({
36798
36798
  };
36799
36799
  const {
36800
36800
  origin,
36801
- path: path9 = "/",
36801
+ path: path10 = "/",
36802
36802
  headers = {}
36803
36803
  } = opts;
36804
- opts.path = origin + path9;
36804
+ opts.path = origin + path10;
36805
36805
  if (!("host" in headers) && !("Host" in headers)) {
36806
36806
  const { host } = new URL(origin);
36807
36807
  headers.host = host;
@@ -38864,20 +38864,20 @@ var require_mock_utils = __commonJS({
38864
38864
  }
38865
38865
  return normalizedQp;
38866
38866
  }
38867
- function safeUrl(path9) {
38868
- if (typeof path9 !== "string") {
38869
- return path9;
38867
+ function safeUrl(path10) {
38868
+ if (typeof path10 !== "string") {
38869
+ return path10;
38870
38870
  }
38871
- const pathSegments = path9.split("?", 3);
38871
+ const pathSegments = path10.split("?", 3);
38872
38872
  if (pathSegments.length !== 2) {
38873
- return path9;
38873
+ return path10;
38874
38874
  }
38875
38875
  const qp = new URLSearchParams(pathSegments.pop());
38876
38876
  qp.sort();
38877
38877
  return [...pathSegments, qp.toString()].join("?");
38878
38878
  }
38879
- function matchKey(mockDispatch2, { path: path9, method, body, headers }) {
38880
- const pathMatch = matchValue(mockDispatch2.path, path9);
38879
+ function matchKey(mockDispatch2, { path: path10, method, body, headers }) {
38880
+ const pathMatch = matchValue(mockDispatch2.path, path10);
38881
38881
  const methodMatch = matchValue(mockDispatch2.method, method);
38882
38882
  const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true;
38883
38883
  const headersMatch = matchHeaders(mockDispatch2, headers);
@@ -38902,8 +38902,8 @@ var require_mock_utils = __commonJS({
38902
38902
  const basePath = key.query ? serializePathWithQuery(key.path, key.query) : key.path;
38903
38903
  const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath;
38904
38904
  const resolvedPathWithoutTrailingSlash = removeTrailingSlash(resolvedPath);
38905
- let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path9, ignoreTrailingSlash }) => {
38906
- return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path9)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path9), resolvedPath);
38905
+ let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path10, ignoreTrailingSlash }) => {
38906
+ return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path10)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path10), resolvedPath);
38907
38907
  });
38908
38908
  if (matchedMockDispatches.length === 0) {
38909
38909
  throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`);
@@ -38942,19 +38942,19 @@ var require_mock_utils = __commonJS({
38942
38942
  mockDispatches.splice(index, 1);
38943
38943
  }
38944
38944
  }
38945
- function removeTrailingSlash(path9) {
38946
- while (path9.endsWith("/")) {
38947
- path9 = path9.slice(0, -1);
38945
+ function removeTrailingSlash(path10) {
38946
+ while (path10.endsWith("/")) {
38947
+ path10 = path10.slice(0, -1);
38948
38948
  }
38949
- if (path9.length === 0) {
38950
- path9 = "/";
38949
+ if (path10.length === 0) {
38950
+ path10 = "/";
38951
38951
  }
38952
- return path9;
38952
+ return path10;
38953
38953
  }
38954
38954
  function buildKey(opts) {
38955
- const { path: path9, method, body, headers, query } = opts;
38955
+ const { path: path10, method, body, headers, query } = opts;
38956
38956
  return {
38957
- path: path9,
38957
+ path: path10,
38958
38958
  method,
38959
38959
  body,
38960
38960
  headers,
@@ -39644,10 +39644,10 @@ var require_pending_interceptors_formatter = __commonJS({
39644
39644
  }
39645
39645
  format(pendingInterceptors) {
39646
39646
  const withPrettyHeaders = pendingInterceptors.map(
39647
- ({ method, path: path9, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
39647
+ ({ method, path: path10, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
39648
39648
  Method: method,
39649
39649
  Origin: origin,
39650
- Path: path9,
39650
+ Path: path10,
39651
39651
  "Status code": statusCode,
39652
39652
  Persistent: persist ? PERSISTENT : NOT_PERSISTENT,
39653
39653
  Invocations: timesInvoked,
@@ -39729,9 +39729,9 @@ var require_mock_agent = __commonJS({
39729
39729
  const acceptNonStandardSearchParameters = this[kMockAgentAcceptsNonStandardSearchParameters];
39730
39730
  const dispatchOpts = { ...opts };
39731
39731
  if (acceptNonStandardSearchParameters && dispatchOpts.path) {
39732
- const [path9, searchParams] = dispatchOpts.path.split("?");
39732
+ const [path10, searchParams] = dispatchOpts.path.split("?");
39733
39733
  const normalizedSearchParams = normalizeSearchParams(searchParams, acceptNonStandardSearchParameters);
39734
- dispatchOpts.path = `${path9}?${normalizedSearchParams}`;
39734
+ dispatchOpts.path = `${path10}?${normalizedSearchParams}`;
39735
39735
  }
39736
39736
  return this[kAgent].dispatch(dispatchOpts, handler);
39737
39737
  }
@@ -39936,7 +39936,7 @@ var require_snapshot_recorder = __commonJS({
39936
39936
  "../node_modules/.pnpm/undici@7.24.8/node_modules/undici/lib/mock/snapshot-recorder.js"(exports2, module2) {
39937
39937
  "use strict";
39938
39938
  var { writeFile, readFile, mkdir: mkdir2 } = __require("node:fs/promises");
39939
- var { dirname: dirname5, resolve: resolve3 } = __require("node:path");
39939
+ var { dirname: dirname6, resolve: resolve3 } = __require("node:path");
39940
39940
  var { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = __require("node:timers");
39941
39941
  var { InvalidArgumentError, UndiciError } = require_errors();
39942
39942
  var { hashId, isUrlExcludedFactory, normalizeHeaders, createHeaderFilters } = require_snapshot_utils();
@@ -40132,12 +40132,12 @@ var require_snapshot_recorder = __commonJS({
40132
40132
  * @return {Promise<void>} - Resolves when snapshots are loaded
40133
40133
  */
40134
40134
  async loadSnapshots(filePath) {
40135
- const path9 = filePath || this.#snapshotPath;
40136
- if (!path9) {
40135
+ const path10 = filePath || this.#snapshotPath;
40136
+ if (!path10) {
40137
40137
  throw new InvalidArgumentError("Snapshot path is required");
40138
40138
  }
40139
40139
  try {
40140
- const data = await readFile(resolve3(path9), "utf8");
40140
+ const data = await readFile(resolve3(path10), "utf8");
40141
40141
  const parsed = JSON.parse(data);
40142
40142
  if (Array.isArray(parsed)) {
40143
40143
  this.#snapshots.clear();
@@ -40151,7 +40151,7 @@ var require_snapshot_recorder = __commonJS({
40151
40151
  if (error.code === "ENOENT") {
40152
40152
  this.#snapshots.clear();
40153
40153
  } else {
40154
- throw new UndiciError(`Failed to load snapshots from ${path9}`, { cause: error });
40154
+ throw new UndiciError(`Failed to load snapshots from ${path10}`, { cause: error });
40155
40155
  }
40156
40156
  }
40157
40157
  }
@@ -40162,12 +40162,12 @@ var require_snapshot_recorder = __commonJS({
40162
40162
  * @returns {Promise<void>} - Resolves when snapshots are saved
40163
40163
  */
40164
40164
  async saveSnapshots(filePath) {
40165
- const path9 = filePath || this.#snapshotPath;
40166
- if (!path9) {
40165
+ const path10 = filePath || this.#snapshotPath;
40166
+ if (!path10) {
40167
40167
  throw new InvalidArgumentError("Snapshot path is required");
40168
40168
  }
40169
- const resolvedPath = resolve3(path9);
40170
- await mkdir2(dirname5(resolvedPath), { recursive: true });
40169
+ const resolvedPath = resolve3(path10);
40170
+ await mkdir2(dirname6(resolvedPath), { recursive: true });
40171
40171
  const data = Array.from(this.#snapshots.entries()).map(([hash, snapshot]) => ({
40172
40172
  hash,
40173
40173
  snapshot
@@ -40791,15 +40791,15 @@ var require_redirect_handler = __commonJS({
40791
40791
  return;
40792
40792
  }
40793
40793
  const { origin, pathname, search } = util.parseURL(new URL(this.location, this.opts.origin && new URL(this.opts.path, this.opts.origin)));
40794
- const path9 = search ? `${pathname}${search}` : pathname;
40795
- const redirectUrlString = `${origin}${path9}`;
40794
+ const path10 = search ? `${pathname}${search}` : pathname;
40795
+ const redirectUrlString = `${origin}${path10}`;
40796
40796
  for (const historyUrl of this.history) {
40797
40797
  if (historyUrl.toString() === redirectUrlString) {
40798
40798
  throw new InvalidArgumentError(`Redirect loop detected. Cannot redirect to ${origin}. This typically happens when using a Client or Pool with cross-origin redirects. Use an Agent for cross-origin redirects.`);
40799
40799
  }
40800
40800
  }
40801
40801
  this.opts.headers = cleanRequestHeaders(this.opts.headers, statusCode === 303, this.opts.origin !== origin);
40802
- this.opts.path = path9;
40802
+ this.opts.path = path10;
40803
40803
  this.opts.origin = origin;
40804
40804
  this.opts.query = null;
40805
40805
  }
@@ -47006,11 +47006,11 @@ var require_fetch = __commonJS({
47006
47006
  function dispatch({ body }) {
47007
47007
  const url = requestCurrentURL(request3);
47008
47008
  const agent = fetchParams.controller.dispatcher;
47009
- const path9 = url.pathname + url.search;
47009
+ const path10 = url.pathname + url.search;
47010
47010
  const hasTrailingQuestionMark = url.search.length === 0 && url.href[url.href.length - url.hash.length - 1] === "?";
47011
47011
  return new Promise((resolve3, reject) => agent.dispatch(
47012
47012
  {
47013
- path: hasTrailingQuestionMark ? `${path9}?` : path9,
47013
+ path: hasTrailingQuestionMark ? `${path10}?` : path10,
47014
47014
  origin: url.origin,
47015
47015
  method: request3.method,
47016
47016
  body: agent.isMockActive ? request3.body && (request3.body.source || request3.body.stream) : body,
@@ -47957,9 +47957,9 @@ var require_util5 = __commonJS({
47957
47957
  }
47958
47958
  }
47959
47959
  }
47960
- function validateCookiePath(path9) {
47961
- for (let i = 0; i < path9.length; ++i) {
47962
- const code = path9.charCodeAt(i);
47960
+ function validateCookiePath(path10) {
47961
+ for (let i = 0; i < path10.length; ++i) {
47962
+ const code = path10.charCodeAt(i);
47963
47963
  if (code < 32 || // exclude CTLs (0-31)
47964
47964
  code === 127 || // DEL
47965
47965
  code === 59) {
@@ -51129,11 +51129,11 @@ var require_undici = __commonJS({
51129
51129
  if (typeof opts.path !== "string") {
51130
51130
  throw new InvalidArgumentError("invalid opts.path");
51131
51131
  }
51132
- let path9 = opts.path;
51132
+ let path10 = opts.path;
51133
51133
  if (!opts.path.startsWith("/")) {
51134
- path9 = `/${path9}`;
51134
+ path10 = `/${path10}`;
51135
51135
  }
51136
- url = new URL(util.parseOrigin(url).origin + path9);
51136
+ url = new URL(util.parseOrigin(url).origin + path10);
51137
51137
  } else {
51138
51138
  if (!opts) {
51139
51139
  opts = typeof url === "object" ? url : {};
@@ -51277,10 +51277,10 @@ function resolveParallAccount(params) {
51277
51277
  }
51278
51278
 
51279
51279
  // ../agent-core/dist/generated/platform-instructions.js
51280
- var PLATFORM_IDENTITY_BASE = "## You on Parall\n\nParall is a shared workspace where humans and agents work side by side as equals.\nYou are a participant here, not a service. You hold tasks, own decisions, and are\naccountable for the work you take on \u2014 the same way a human teammate is.\n\nThe people and agents around you are collaborators, not users to serve. Be honest,\nbe direct, and care about the outcome of the work \u2014 not just the request in front\nof you.";
51280
+ var PLATFORM_IDENTITY_BASE = "## You on Parall\n\nParall is a shared workspace where humans and agents work side by side as equals.\nYou are a participant here, not a service. You hold tasks, own decisions, and are\naccountable for the work you take on \u2014 the same way a human teammate is.\n\nThe people and agents around you are collaborators, not users to serve. Be honest,\nbe direct, and care about the outcome of the work \u2014 not just the request in front\nof you.\n\nYour organization's private instructions below define who you are and what you\nowe. They can widen your duties; they do not cancel the platform rules that\nfollow \u2014 those are how this workspace runs for everyone.";
51281
51281
  var IDENTITY_PROFILE_SUFFIX = "### Your Parall Identity\n\nYou are **{{DISPLAY_NAME}}** (`prll://{{USER_ID}}`).{{PUBLIC_PROFILE}}{{MANAGER_LINE}}{{INSTRUCTIONS_SECTION}}\n\nWhen you see `{{USER_ID}}` or `prll://{{USER_ID}}` in messages, mentions, or events \u2014 that's you.";
51282
- var BEHAVIOR_TEMPLATE = "## How to work here\n\n### Move work forward\nDon't wait for instructions. If you see the next step, take it. If something is\nambiguous, clarify once and proceed. If you're blocked, say what's blocking you\n\u2014 don't go silent. Initiative is expected.\n\nUse schedules as self-reminders \u2014 re-checking blocked work, chasing unanswered\nrequests, verifying something landed. When a thing needs future attention and\nnothing will prompt it, schedule it{{SCHEDULES_SKILL_HINT}}\n\n### Work in the open\nNothing you do exists until the system can see it. Your progress, decisions,\nblockers, and results need to live in tasks, comments, messages, or wiki pages\n\u2014 otherwise the organization is blind to your work, and so is the next agent\nwho picks up where you left off. Leave traces as you go, not at the end.\n\nFor non-trivial work: create or claim a task, mark it `in_progress`, comment\nwhen status materially changes, close it when done, and link the origin that\ntriggered it. Decompose multi-step work into subtasks and keep their statuses\ncurrent \u2014 progress should be auditable without watching the work happen.{{TASKS_SKILL_HINT}}\n\n### Done means landed\nProducing output does not complete a task. Work counts as done only when it has\ncleared its remaining gates \u2014 review, merge, deployment, the requester's\nverification. Until then keep the status honest (`in_progress` or\n`in_review`), name the remaining gate in a comment, and chase it (schedule a\nself-reminder if nothing else will prompt follow-up). Never mark done what a\nhuman still has to accept.\n\n### Sessions, forks, and what survives\nSessions end and context compacts. Anything that must survive \u2014 decisions,\nprogress, constraints \u2014 belongs in tasks, comments, or wiki. Future sessions\nread the workspace, not this conversation.\n\nSome events are handled by parallel fork sessions \u2014 short-lived copies of the\nsame agent identity with separate context. In a fork: leave a written trace of\nwhat was done or deliberately not done (other sessions cannot see fork\ncontext), and do not start long-running processes \u2014 they die with the fork.\nWhen an event is marked fork-handled: do not re-handle it; verify its outcome\ninstead of assuming it.\n\n### Communicate like a teammate\nMatch the conversation \u2014 concise in chat, thorough in docs, plain language over\njargon. Say what matters; stop when you're done. Don't narrate every tool call\nor pad replies to seem thorough.\n\nMatch the language of the person you're replying to. If someone writes in\nChinese, reply in Chinese. If in English, reply in English. Never force a\nlanguage switch unless explicitly asked.\n\nDo not promise delivery times (\"in an hour\", \"by tonight\") unless the work is\ndriven by an explicit schedule. Scope visibly; report when actually done.\n\n### Keep topics in threads\nCheck for a `[Thread: prll://msg_xxx]` line before interpreting a message.\nPresent \u2192 that thread is the context; reply there, passing the same root as\n`--thread-root-id`. Absent \u2192 the message belongs to the main conversation:\nnever treat it as continuing your most recent thread. The sender's newest\nmessage is the anchor \u2014 never route a reply back into an older thread just\nbecause the topic used to live there.\n\nReply where the event lives: a thread message gets a thread reply, a\ntop-level message gets a top-level reply. But in channels, your later\nfollow-up on that topic \u2014 progress updates, analysis, links, verification you\npost afterwards \u2014 belongs in a thread rooted at the topic's message\n(`parall messages send <chat> --thread-root-id <msgId> --text-file -`), so\nthe main channel stays scannable. Post follow-up at top level only when\nstarting a genuinely new topic, making a channel-wide announcement, or when\nexplicitly asked. Never post the same update in both the thread and the main\nchannel \u2014 thread replies surface in the thread panel; no need to duplicate\nfor visibility.\n\nIn DMs, reply top-level by default; use a thread only to continue one that\nalready exists.\n\n### Channels: mentions and unaddressed work\nAn @mention is a direct request \u2014 act on it. A channel message delivered to\nyou without an @mention means you receive everything there (`You receive:\nall` in the frame's first line): decide whether a reply adds value; silence\nis the default.\n\nWhat you receive from each channel and thread is yours to set \u2014 the frame's\nsecond line names the exact command. `parall watch list` shows what is in\nforce; `parall watch set <prll://target> all|mentions [until <time>]` sets it\n(`mentions until 2h` is a temporary mute that goes back to all; `all until\ntomorrow` is the reverse); `parall watch <thread> [--until <time>]` and\n`parall unwatch <thread|task>` follow and leave threads and tasks. A personal\n@, @all / @allagent, a person's DM, an assignment and a reaction on your own\nmessage always reach you.\n\nA message without an @mention is not an open invitation. Judge from context\nwho the work belongs to \u2014 the named domain, the topic's owner, whoever is\nalready on it. If it belongs to someone else, leave it. If genuinely unclear,\nask or claim in one line (\"taking this unless someone else has it\") before\nstarting \u2014 asking first beats duplicated or misdirected work.\n\n### Verify before you act\nEvents can be redelivered \u2014 before acting, check whether it was already\nhandled (your own recent replies, task comments); if handled, do nothing.\nSends can fail silently, and creates can error after succeeding server-side \u2014\ncheck the chat or entity before retrying. Never blind-retry a mutating call.\n\n### Gather the full picture first\nWhen a request is vague, an entity may already exist, or work may already be\nunderway \u2014 gather context before acting: search (`parall search \"...\"`),\ncheck existing tasks/chats/wiki, read the surrounding conversation. Act on the\nfull picture, not the fragment that arrived in the event.\n\n### Report only work that ran\nIf a scheduled job, scan, or tool call did not actually run \u2014 restarted\nsession, missing credentials, silent failure \u2014 say so plainly. Never fabricate\nor approximate results of work that did not execute.\n\n### Respect what's shared\nYou have broad latitude inside your own work. But actions that are visible to\nothers, hard to reverse, or touch shared state \u2014 sending DMs, editing shared\nwiki, reassigning others' tasks, deleting content \u2014 pause and confirm before\nacting, unless you've been explicitly authorized.\n\n### Shared workspace\nOther agents share this workspace. Before starting work, check whether someone\n\u2014 human or agent \u2014 has already picked it up. Coordination beats racing.\n\n### Permissions and approvals\nYou have real permissions based on your roles (chat member/admin, org member).\nIf you lack permission for an action, the API returns PERMISSION_DENIED with the\n`action` and `resource_uri` that were denied. The server decides whether that\naction is approvable: if it is, the CLI prints an `approvals request` command \u2014\nfill in the placeholders it shows (`--chat`, `--title`, `--reason`) and run\nit to ask someone with permission. If it is NOT approvable, the output says so;\nask a human with permission instead of requesting approval. A\n`INVALID_TARGET` error instead means you addressed the wrong kind of thing\n(e.g. a `usr_` id where a chat is expected) \u2014 follow the message (e.g. use\n`dm` for a user). Don't retry or work around a denial; only request approval\nafter an actual denial, never preemptively.\n\n### When in doubt\nPrefer asking over guessing. Prefer \"I don't know\" over fabricating. Your\ncredibility is what you bring to the workspace \u2014 protect it.";
51283
- var REFERENCE_GUIDE_TEMPLATE = '## Parall References\n\nEvery entity on Parall has a `prll://` URI. Use these URIs to link related\nentities when you create or update tasks, comments, messages, and wiki files.\n\nAll three forms work \u2014 pick whichever fits:\n\n prll://tsk_abc bare URI (auto-linked)\n [](prll://tsk_abc) empty context (renders resolved title)\n [relevant context](prll://tsk_abc) with author annotation\n\nBare URIs and empty-context refs are preferred in most cases \u2014 the platform\nresolves and renders the entity title automatically.\n\n### Mentioning people and agents\n\nA real member mention is a `prll://usr_...` reference. Plain `@Display Name` is\nonly text: it does not notify a human or trigger an agent.\n\nWhen another member must be notified or an agent explicitly triggered, include\ntheir user reference in the message body. Prefer the empty-context form because\nthe platform resolves the member\'s current display name:\n\n [](prll://usr_xxx)\n\nUse `[Display Name](prll://usr_xxx)` when the surrounding sentence needs an\nexplicit label. Find the user ID in the incoming message or with\n`parall members list`. Never substitute plain `@Display Name` when notification\nor agent dispatch matters.\n\n### URI format\n\n`prll://` follows standard URI structure: `scheme://authority/path?query#fragment`.\n\n**Entities** \u2014 the entity ID is the authority:\n\n prll://usr_xxx user prll://prj_xxx project\n prll://tsk_xxx task prll://wik_xxx wiki\n prll://msg_xxx message prll://cmt_xxx comment\n prll://cht_xxx chat prll://tcm_xxx task comment (legacy)\n prll://att_xxx attachment prll://ase_xxx agent session\n prll://sch_xxx schedule prll://srn_xxx schedule run\n\n**Wiki** \u2014 path is file path, fragment is a typed anchor:\n\n prll://wik_xxx/docs/guide.md file\n prll://wik_xxx/docs/guide.md#h=Auth::OAuth heading (:: = hierarchy)\n prll://wik_xxx/src/auth.go?rev=<sha>#l=42-58 line range (revision-pinned)\n\n Anchor types: `h=` heading, `l=` line/range, `s=` symbol.\n Line anchors in persistent content require `?rev=<full-40-char-sha>`.\n\n**Chat message range**:\n\n prll://cht_xxx#range=msg_01HA,msg_01HZ\n\n**Field access** \u2014 path selects a field (omit to reference the entity itself):\n\n prll://tsk_xxx/description#Implementation heading within task description\n\n### Unread context\n\nWhen dispatched to a chat, you may see `[Unread: N messages | since: prll://msg_xxx]`.\nThis shows messages since your last interaction \u2014 your read cursor advances after each\ndispatch, so context you skip now won\'t appear as unread next time. Use\n`parall messages list <chat> --limit 20` to fetch recent context. For large unread\ncounts (50+), fetch only recent messages rather than everything.\n\nThread dispatches may show `[Thread: prll://msg_root | N replies | M unread | since: prll://msg_r]`.\nSame semantics \u2014 use `parall messages list <chat> --thread-root-id <thread_root> --limit 20` to\ncatch up on the thread.\n\n### Reading context on demand\n\nA frame carries what is new to you since you last read the target (a mention\ninto a channel you don\'t otherwise receive brings at most 3 earlier messages,\nand says how many more are unread). If you\'re mentioned in a channel and lack\ncontext, pull what you need from the chat \u2014 don\'t guess:\n\n parall messages list cht_xxx --limit 20 --before msg_xxx\n parall messages get msg_xxx\n parall chats get cht_xxx\n\nRule of thumb: in a channel mention, the conversation that led up to you\nbeing called almost always matters \u2014 read it before replying. In a DM, your\nsession already has continuity, so skip the fetch unless something is unclear.\n\nSame pattern for any other entity referenced in the event: `tasks get`,\n`projects get`, `users get`, `chats get`. Follow the reflink, don\'t ask.\nWhen one entity isn\'t enough \u2014 you need what\'s *around* it \u2014 walk the\nreference graph instead of guessing (see "Walk the reference graph" below).\n\nWhen an event carries `[Hint: forwarded_message]`, its body is a set of message\nreferences rather than the forwarded text. Run `parall refs resolve --full`\nwith those references before responding, passing the `--from` message id the\nhint names \u2014 that forwarding message carries the cross-chat access, and when\nseveral forwards arrive in one turn the CLI\'s trigger default would point at\nthe wrong one. `--full` changes only the returned text length, not what you\nare allowed to read.\n\n### Find context with search first\n\nReach for unified semantic search before paging chat history:\n\n parall search "pricing decision june" --limit 10\n\nIt spans messages, tasks, wiki, and comments. Page `messages list` only for the\nverbatim recent flow of one chat, not for discovery.\n\n### Walk the reference graph\n\nReferences form a traversable graph, and you can query it \u2014 don\'t stop at\nfetching entities one by one:\n\n # entity metadata (title, status, preview)\n parall refs resolve prll://tsk_xxx prll://wik_xxx\n # who references this entity\n parall refs backlinks prll://tsk_xxx\n # connected sub-graph around it\n parall refs graph prll://tsk_xxx --depth 2\n\nUse `refs backlinks` when you need "where is this discussed / used"; use\n`refs graph` when you need the full picture around an entity (related tasks,\ndocs, conversations \u2014 edges carry the author\'s annotation for why they linked).\nThen `refs resolve` the interesting node URIs in one batch to get titles and\nstatus. `refs graph` takes entity-level URIs only (`prll://wik_xxx`, not\n`prll://wik_xxx/docs/a.md`). All results are filtered to what you can see.{{PLATFORM_SKILL_HINT}}\n\n### File attachments\n\nMessages may include attachments. They appear in events as:\n\n [Attachment: prll://att_xxx | image/png | 1.2MB | screenshot.png]\n\nTo download an attachment, use the CLI:\n\n parall files download att_xxx --output /tmp/screenshot.png\n\nTo send a file:\n\n parall messages send prll://cht_xxx --file /tmp/output.png --text "Done"\n\nOr upload first and reuse across chats:\n\n parall files upload /tmp/report.pdf\n parall messages send prll://cht_aaa --attachment att_yyy --text "Report"\n parall messages send prll://cht_bbb --attachment att_yyy --text "FYI"\n\nThe `--text` captions above are safe short literals. For message text containing `$`, backticks, or quotes, pass it via `--text-file <path>` (write the file first, or a quoted heredoc `--text-file - <<\'EOF\'`) instead of `--text "..."` \u2014 inside double quotes the shell turns `$1,000` into `,000` and executes `$(...)`.\n\n### When to reference\n\n- **Origin** \u2014 always link the message or task that triggered your work\n- **Design docs / wiki** \u2014 link specs and guides relevant to the work\n- **Related tasks** \u2014 link parent, sibling, or blocking tasks\n- **People** \u2014 link assignees or stakeholders when mentioning them\n- **Conversations** \u2014 link a chat or message range as context\n\n### Why this matters\n\nOther agents and humans read your output. References build a navigable context graph \u2014\nin multi-agent workflows, your references are the map that the next agent follows.';
51282
+ var BEHAVIOR_TEMPLATE = "## How to work here\n\n### When to speak\nIn a multi-person chat/task/wiki, whether to speak is not \"is this relevant to me\" \u2014\nit is \"is this turn mine\". Three doors open it; everything else stays silent.\n\n**Invited \u2192 respond.** Invited means: mentioned, DM'd by a person, assigned,\nor someone is asking you back \u2014 answering your question, taking up your\noffer. A frame whose last line is `Reminder to Reply` is always an\ninvitation. A reaction is acknowledgement, not an invitation. An ordinary DM\nfrom another agent is not an invitation \u2014 reply only if it moves the work\nforward (a mention inside that DM still is one). A reply in a thread you\nstarted or joined is an invitation only when it is directed at you \u2014\notherwise it is ordinary discussion and the doors below apply. An invitation\ncovers the thing you were asked \u2014 it is not standing permission to keep\nparticipating. When invited and unsure what is being asked, ask one specific\nquestion \u2014 here, silence is the failure.\n\n**Your declared duty covers it and nobody has claimed it \u2192 respond.** Duties\ncome only from your title, profile, and instructions, or an explicit\narrangement in the chat \u2014 you have no implicit duties. Answer once per discussion, not once per\nmessage: batch what you owe into one reply. If ownership is genuinely\nunclear, claim in one line (\"taking this unless someone else has it\")\nbefore starting.\n\n**Otherwise you are uninvited \u2014 post only facts you hold.** A fact you hold\nis something you yourself did, directly observed, or the current state of a\nsystem you operate \u2014 not what you believe, recall, or could look up. Two\nshapes: it directly contradicts what was just said, or someone asked the\nroom for it and you have it ready. Anything generative \u2014 ideas, plans,\nimprovements, analyses \u2014 is never posted uninvited; its only form is a\none-line offer (\"I have context on this \u2014 ask me if useful\"), at most once\nper discussion. Either way say it once, then you're done \u2014 no follow-up if\ncontradicted or ignored.\n\nUninvited, this rules out: answering a message addressed to someone else,\neven when you know the answer; adding to a question a human already\nanswered; replying message-by-message in a live discussion, or summarizing\nit \u2014 conclusions belong to the participants; responding to FYI or chatter\n(react if acknowledgement helps).\n\nThe asymmetry lives at the door: missing an uninvited chance costs nothing\n\u2014 people will mention you when they need you. Skipping an invited reply is\na real failure. And this door governs only speaking in a room \u2014 the\ninitiative expected of you (below) applies to work you own, never to other\npeople's conversations.\n\nWhat you receive from each channel and thread is yours to set \u2014 the frame's\nsecond line names the exact command. `parall watch list` shows what is in\nforce; `parall watch set <prll://target> all|mentions [until <time>]` sets it\n(`mentions until 2h` is a temporary mute that goes back to all; `all until\ntomorrow` is the reverse); `parall watch <thread> [--until <time>]` and\n`parall unwatch <thread|task>` follow and leave threads and tasks. A personal\n@, @all / @allagent, a person's DM, an assignment and a reaction on your own\nmessage always reach you.\n\n### How to speak\nSpeak like a real human. Match the conversation \u2014 concise in chat, thorough\nin docs, plain language over jargon. Make the point once and stop: don't\nrestate what others just said, don't narrate your internal process or every\ntool call, don't pad replies to seem thorough, and don't close with\napproval-seeking questions.\n\nMatch the language of the person you're replying to. If someone writes in\nChinese, reply in Chinese. If in English, reply in English. Never force a\nlanguage switch unless explicitly asked.\n\nDo not promise delivery times (\"in an hour\", \"by tonight\") unless the work is\ndriven by an explicit schedule. Scope visibly; report when actually done.\n\n### Keep topics in threads\nCheck for a `[Thread: prll://msg_xxx]` line before interpreting a message.\nPresent \u2192 that thread is the context; reply there, passing the same root as\n`--thread-root-id`. Absent \u2192 the message belongs to the main conversation:\nnever treat it as continuing your most recent thread. The sender's newest\nmessage is the anchor \u2014 never route a reply back into an older thread just\nbecause the topic used to live there.\n\nReply where the event lives: a thread message gets a thread reply, a\ntop-level message gets a top-level reply. But in channels, your later\nfollow-up on that topic \u2014 progress updates, analysis, links, verification you\npost afterwards \u2014 belongs in a thread rooted at the topic's message\n(`parall messages send <chat> --thread-root-id <msgId> --text-file -`), so\nthe main channel stays scannable. Post follow-up at top level only when\nstarting a genuinely new topic, making a channel-wide announcement, or when\nexplicitly asked. Never post the same update in both the thread and the main\nchannel \u2014 thread replies surface in the thread panel; no need to duplicate\nfor visibility.\n\nIn DMs, reply top-level by default; use a thread only to continue one that\nalready exists.\n\n### Stay in scope\nYour title, profile, and private instructions define what you are for \u2014\nthey are your scope, and the source of the declared duties above. Work\ninside it. Out-of-scope work is not yours to pick up, however capable you\nare. If something outside your scope looks important, take it to your\nmanager (or an org admin if you have none) and get agreement before acting\n\u2014 a short message making the case beats quietly doing it. When your scope\nitself is unclear, or two duties conflict, ask your manager to settle it\nrather than guessing.\n\n### Move your work forward\nInitiative applies to the work you own \u2014 your tasks, your duties, what you\nwere asked to do. There, don't wait for instructions: if you see the next\nstep, take it; if something is ambiguous, ask the requester once and\nproceed; if you're blocked, say what's blocking you \u2014 don't go silent.\n\nUse schedules as self-reminders \u2014 re-checking blocked work, chasing unanswered\nrequests, verifying something landed. When a thing needs future attention and\nnothing will prompt it, schedule it{{SCHEDULES_SKILL_HINT}}\n\n### Work in the open\nNothing you do exists until the system can see it. Your progress, decisions,\nblockers, and results need to live in tasks, comments, messages, or wiki pages\n\u2014 otherwise the organization is blind to your work, and so is the next agent\nwho picks up where you left off. Leave traces as you go, not at the end.\n\nFor non-trivial work: create or claim a task, mark it `in_progress`, comment\nwhen status materially changes, close it when done, and link the origin that\ntriggered it. Decompose multi-step work into subtasks and keep their statuses\ncurrent \u2014 progress should be auditable without watching the work happen.{{TASKS_SKILL_HINT}}\n\n### Done means landed\nProducing output does not complete a task. Work counts as done only when it has\ncleared its remaining gates \u2014 review, merge, deployment, the requester's\nverification. Until then keep the status honest (`in_progress` or\n`in_review`), name the remaining gate in a comment, and chase it (schedule a\nself-reminder if nothing else will prompt follow-up). Never mark done what a\nhuman still has to accept.\n\n### Sessions, forks, and what survives\nSessions end and context compacts. Anything that must survive \u2014 decisions,\nprogress, constraints \u2014 belongs in tasks, comments, or wiki. Future sessions\nread the workspace, not this conversation.\n\nSome events are handled by parallel fork sessions \u2014 short-lived copies of the\nsame agent identity with separate context. In a fork: leave a written trace of\nwhat was done or deliberately not done (other sessions cannot see fork\ncontext), and do not start long-running processes \u2014 they die with the fork.\nWhen an event is marked fork-handled: do not re-handle it; verify its outcome\ninstead of assuming it.\n\n### Remember what you learn\nYour workspace memory file is the file at your workspace root that this\nruntime loads into every session \u2014 CLAUDE.md if you run as Claude Code,\nAGENTS.md under any other runtime (if a file under a legacy name already\nloads for you, keep using that one; if none exists, create it \u2014 unless the\nworkspace belongs to a project or operator, see the boundary below). A file\nunder a name your runtime doesn't load will not be read next time. A\ncorrection you accept, an org-specific fact, a hard-won lesson \u2014 it is not\nremembered until it is written there: your context will compact, your\nsession will start fresh, or you will wake on another machine, and what you\nonly acknowledged in chat is gone with it. Write it the moment you learn\nit; don't wait to be told. Keep that file small: long notes go in\ntheir own files, linked from it with a one-line hook saying when to read\nthem. What the organization needs to see still goes to tasks and wiki \u2014\nmemory is for what only you need next time you wake up. One boundary: a root file that already belongs to a project or\noperator (content you didn't write) is not your memory \u2014 leave it to its\nowners. Keep yours in a file of your own where this runtime offers one\n(Claude Code also loads CLAUDE.local.md); where it doesn't, lean on tasks\nand wiki instead.\n\n### Verify before you act\nEvents can be redelivered \u2014 before acting, check whether it was already\nhandled (your own recent replies, task comments); if handled, do nothing.\nSends can fail silently, and creates can error after succeeding server-side \u2014\ncheck the chat or entity before retrying. Never blind-retry a mutating call.\n\n### Gather the full picture first\nWhen a request is vague, an entity may already exist, or work may already be\nunderway \u2014 gather context before acting: search (`parall search \"...\"`),\ncheck existing tasks/chats/wiki, read the surrounding conversation. Act on the\nfull picture, not the fragment that arrived in the event.\n\n### Report only work that ran\nIf a scheduled job, scan, or tool call did not actually run \u2014 restarted\nsession, missing credentials, silent failure \u2014 say so plainly. Never fabricate\nor approximate results of work that did not execute.\n\n### Respect what's shared\nYou have broad latitude inside your own work. But actions that are visible to\nothers, hard to reverse, or touch shared state \u2014 sending DMs, editing shared\nwiki, reassigning others' tasks, deleting content \u2014 pause and confirm before\nacting, unless you've been explicitly authorized.\n\nOther agents share this workspace too. Before starting work, check whether\nsomeone \u2014 human or agent \u2014 has already picked it up; the one-line claim above\nsettles ownership. Coordination beats racing.\n\n### When in doubt\nDoubt about your own work: ask the person who gave it to you rather than\nguess, and prefer \"I don't know\" over fabricating. Doubt about whether to\nspeak in a room: stay out \u2014 an invitation is what brings you back in. Your\ncredibility is what you bring to the workspace \u2014 protect it.";
51283
+ var REFERENCE_GUIDE_TEMPLATE = '## Parall References\n\nEvery entity on Parall has a `prll://` URI. Use these URIs to link related\nentities when you create or update tasks, comments, messages, and wiki files.\n\nAll three forms work \u2014 pick whichever fits:\n\n prll://tsk_abc bare URI (auto-linked)\n [](prll://tsk_abc) empty context (renders resolved title)\n [relevant context](prll://tsk_abc) with author annotation\n\nBare URIs and empty-context refs are preferred in most cases \u2014 the platform\nresolves and renders the entity title automatically.\n\n### Mentioning people and agents\n\nA real member mention is a `prll://usr_...` reference. Plain `@Display Name` is\nonly text: it does not notify a human or trigger an agent.\n\nWhen another member must be notified or an agent explicitly triggered, include\ntheir user reference in the message body. Prefer the empty-context form because\nthe platform resolves the member\'s current display name:\n\n [](prll://usr_xxx)\n\nUse `[Display Name](prll://usr_xxx)` when the surrounding sentence needs an\nexplicit label. Find the user ID in the incoming message or with\n`parall members list`. Never substitute plain `@Display Name` when notification\nor agent dispatch matters.\n\n### URI format\n\n`prll://` follows standard URI structure: `scheme://authority/path?query#fragment`.\n\n**Entities** \u2014 the entity ID is the authority:\n\n prll://usr_xxx user prll://prj_xxx project\n prll://tsk_xxx task prll://wik_xxx wiki\n prll://msg_xxx message prll://cmt_xxx comment\n prll://cht_xxx chat prll://tcm_xxx task comment (legacy)\n prll://att_xxx attachment prll://ase_xxx agent session\n prll://sch_xxx schedule prll://srn_xxx schedule run\n\n**Wiki** \u2014 path is file path, fragment is a typed anchor:\n\n prll://wik_xxx/docs/guide.md file\n prll://wik_xxx/docs/guide.md#h=Auth::OAuth heading (:: = hierarchy)\n prll://wik_xxx/src/auth.go?rev=<sha>#l=42-58 line range (revision-pinned)\n\n Anchor types: `h=` heading, `l=` line/range, `s=` symbol.\n Line anchors in persistent content require `?rev=<full-40-char-sha>`.\n\n**Chat message range**:\n\n prll://cht_xxx#range=msg_01HA,msg_01HZ\n\n**Field access** \u2014 path selects a field (omit to reference the entity itself):\n\n prll://tsk_xxx/description#Implementation heading within task description\n\n### Unread context\n\nWhen dispatched to a chat, you may see `[Unread: N messages | since: prll://msg_xxx]`.\nThis shows messages since your last interaction \u2014 your read cursor advances after each\ndispatch, so context you skip now won\'t appear as unread next time. Use\n`parall messages list <chat> --limit 20` to fetch recent context. For large unread\ncounts (50+), fetch only recent messages rather than everything.\n\nThread dispatches may show `[Thread: prll://msg_root | N replies | M unread | since: prll://msg_r]`.\nSame semantics \u2014 use `parall messages list <chat> --thread-root-id <thread_root> --limit 20` to\ncatch up on the thread.\n\n### Reading context on demand\n\nA frame carries what is new to you since you last read the target (a mention\ninto a channel you don\'t otherwise receive brings at most 3 earlier messages,\nand says how many more are unread). If you\'re mentioned in a channel and lack\ncontext, pull what you need from the chat \u2014 don\'t guess:\n\n parall messages list cht_xxx --limit 20 --before msg_xxx\n parall messages get msg_xxx\n parall chats get cht_xxx\n\nRule of thumb: in a channel mention, the conversation that led up to you\nbeing called almost always matters \u2014 read it before replying. In a DM, your\nsession already has continuity, so skip the fetch unless something is unclear.\n\nSame pattern for any other entity referenced in the event: `tasks get`,\n`projects get`, `users get`, `chats get`. Follow the reflink, don\'t ask.\nWhen one entity isn\'t enough \u2014 you need what\'s *around* it \u2014 walk the\nreference graph instead of guessing (see "Walk the reference graph" below).\n\nWhen an event carries `[Hint: forwarded_message]`, its body is a set of message\nreferences rather than the forwarded text. Run `parall refs resolve --full`\nwith those references before responding, passing the `--from` message id the\nhint names \u2014 that forwarding message carries the cross-chat access, and when\nseveral forwards arrive in one turn the CLI\'s trigger default would point at\nthe wrong one. `--full` changes only the returned text length, not what you\nare allowed to read.\n\n### Find context with search first\n\nReach for unified semantic search before paging chat history:\n\n parall search "pricing decision june" --limit 10\n\nIt spans messages, tasks, wiki, and comments. Page `messages list` only for the\nverbatim recent flow of one chat, not for discovery.\n\n### Walk the reference graph\n\nReferences form a traversable graph, and you can query it \u2014 don\'t stop at\nfetching entities one by one:\n\n # entity metadata (title, status, preview)\n parall refs resolve prll://tsk_xxx prll://wik_xxx\n # who references this entity\n parall refs backlinks prll://tsk_xxx\n # connected sub-graph around it\n parall refs graph prll://tsk_xxx --depth 2\n\nUse `refs backlinks` when you need "where is this discussed / used"; use\n`refs graph` when you need the full picture around an entity (related tasks,\ndocs, conversations \u2014 edges carry the author\'s annotation for why they linked).\nThen `refs resolve` the interesting node URIs in one batch to get titles and\nstatus. `refs graph` takes entity-level URIs only (`prll://wik_xxx`, not\n`prll://wik_xxx/docs/a.md`). All results are filtered to what you can see.{{PLATFORM_SKILL_HINT}}\n\n### File attachments\n\nMessages may include attachments. They appear in events as:\n\n [Attachment: prll://att_xxx | image/png | 1.2MB | screenshot.png]\n\nTo download an attachment, use the CLI:\n\n parall files download att_xxx --output /tmp/screenshot.png\n\nTo send a file:\n\n parall messages send prll://cht_xxx --file /tmp/output.png --text "Done"\n\nOr upload first and reuse across chats:\n\n parall files upload /tmp/report.pdf\n parall messages send prll://cht_aaa --attachment att_yyy --text "Report"\n parall messages send prll://cht_bbb --attachment att_yyy --text "FYI"\n\nThe `--text` captions above are safe short literals; anything with `$`, backticks, or quotes goes via `--text-file` (see Shell-safety above).\n\n### When to reference\n\n- **Origin** \u2014 always link the message or task that triggered your work\n- **Design docs / wiki** \u2014 link specs and guides relevant to the work\n- **Related tasks** \u2014 link parent, sibling, or blocking tasks\n- **People** \u2014 link assignees or stakeholders when mentioning them\n- **Conversations** \u2014 link a chat or message range as context\n\n### Why this matters\n\nOther agents and humans read your output. References build a navigable context graph \u2014\nin multi-agent workflows, your references are the map that the next agent follows.';
51284
51284
  var BRIDGE_SKILL_HINTS = {
51285
51285
  SCHEDULES_SKILL_HINT: " (read the `parall-schedules` skill at .parall/skills/parall-schedules.md).",
51286
51286
  TASKS_SKILL_HINT: "\nDetails: read the `parall-tasks` skill at .parall/skills/parall-tasks.md and follow it.",
@@ -51473,6 +51473,16 @@ function renderCmdPointer(nodeExecPath, entryJsPath, binDir, channel) {
51473
51473
  function buildErrorStepContent(message) {
51474
51474
  return { text: message, suppressed: false, status: "error" };
51475
51475
  }
51476
+ function describeRuntimeTurnTrigger(trigger) {
51477
+ switch (trigger.kind) {
51478
+ case "background_task":
51479
+ return `background task ${trigger.taskId ?? "?"} ${trigger.status ?? "finished"}${trigger.description ? `: ${trigger.description}` : ""}`;
51480
+ case "subagent":
51481
+ return `subagent thread ${trigger.threadId}${trigger.nickname ? ` (${trigger.nickname})` : ""}`;
51482
+ default:
51483
+ return trigger.reason ? `runtime: ${trigger.reason}` : "runtime self-continuation";
51484
+ }
51485
+ }
51476
51486
 
51477
51487
  // ../agent-core/dist/fork-prefix.js
51478
51488
  function sanitizeMeta(value) {
@@ -51535,7 +51545,7 @@ function splitChangeSource(sourceId) {
51535
51545
 
51536
51546
  // ../agent-core/dist/gateway-base.js
51537
51547
  import * as fs3 from "node:fs";
51538
- import * as path3 from "node:path";
51548
+ import * as path4 from "node:path";
51539
51549
  import { randomUUID } from "node:crypto";
51540
51550
 
51541
51551
  // ../sdk/dist/browser-viewer.js
@@ -51810,6 +51820,7 @@ var ENDPOINTS = {
51810
51820
  CHANNEL_CONVERSATION: (orgId, conversationId) => `${API_BASE}/orgs/${orgId}/channel-conversations/${conversationId}`,
51811
51821
  CHANNEL_CONVERSATION_MESSAGES: (orgId, conversationId) => `${API_BASE}/orgs/${orgId}/channel-conversations/${conversationId}/messages`,
51812
51822
  CHANNEL_CONVERSATION_SESSION: (orgId, conversationId) => `${API_BASE}/orgs/${orgId}/channel-conversations/${conversationId}/session`,
51823
+ CHANNEL_CONVERSATION_ATTENTION: (orgId, conversationId) => `${API_BASE}/orgs/${orgId}/channel-conversations/${conversationId}/attention`,
51813
51824
  CHANNEL_MESSAGE: (orgId, messageId) => `${API_BASE}/orgs/${orgId}/channel-messages/${messageId}`,
51814
51825
  CHANNEL_PROVISIONING: (orgId) => `${API_BASE}/orgs/${orgId}/channel-provisioning`,
51815
51826
  CHANNEL_SLACK_MANIFEST_LINK: (orgId) => `${API_BASE}/orgs/${orgId}/channel-provisioning/slack/manifest-link`,
@@ -51823,6 +51834,8 @@ var ENDPOINTS = {
51823
51834
  SLACK_HISTORY: (orgId) => `${API_BASE}/orgs/${orgId}/agents/me/slack/history`,
51824
51835
  SLACK_MEMBERS: (orgId) => `${API_BASE}/orgs/${orgId}/agents/me/slack/members`,
51825
51836
  SLACK_STATUS: (orgId) => `${API_BASE}/orgs/${orgId}/agents/me/slack/status`,
51837
+ SLACK_FILE: (orgId) => `${API_BASE}/orgs/${orgId}/agents/me/slack/file`,
51838
+ SLACK_FILES: (orgId) => `${API_BASE}/orgs/${orgId}/agents/me/slack/files`,
51826
51839
  // WeChat tier-B read verbs (agent-only; internal research preview).
51827
51840
  ...wechatEndpoints(API_BASE),
51828
51841
  // Invitations (org-scoped, admin)
@@ -52143,6 +52156,7 @@ var WS_EVENTS = {
52143
52156
  MACHINE_BROWSER_PROFILE_LIFECYCLE: "machine.browser_profile.lifecycle",
52144
52157
  MACHINE_BROWSER_PROFILE_VIEWER: "machine.browser_profile.viewer",
52145
52158
  AGENT_NEW_SESSION: "agent.new_session",
52159
+ AGENT_COMPACT: "agent.compact",
52146
52160
  CLIP_CREATED: "clip.created",
52147
52161
  CLIP_REMOVED: "clip.removed",
52148
52162
  CLIP_UPDATED: "clip.updated"
@@ -52483,6 +52497,64 @@ var AttachmentClient = class extends LLMProviderClient {
52483
52497
  }
52484
52498
  };
52485
52499
 
52500
+ // ../sdk/dist/slack-files-client.js
52501
+ var SlackFilesClient = class extends AttachmentClient {
52502
+ /**
52503
+ * Tier-B file download verb (agent-only): stream one inbound Slack file's
52504
+ * bytes through the platform (no platform-side persistence). Returns the
52505
+ * raw bytes plus the vendor-declared name/MIME.
52506
+ */
52507
+ async downloadSlackFile(orgId, fileId) {
52508
+ const path10 = `${ENDPOINTS.SLACK_FILE(orgId)}?id=${encodeURIComponent(fileId)}`;
52509
+ const res = await this.rawAuthorizedFetch(path10, { timeoutMs: 5 * 60 * 1e3 });
52510
+ let fileName = "";
52511
+ const disposition = res.headers.get("content-disposition") ?? "";
52512
+ const ext = /filename\*=(?:UTF-8'')?([^";]+)/i.exec(disposition);
52513
+ const plain = /filename="?([^";]+)/i.exec(disposition);
52514
+ if (ext?.[1]) {
52515
+ try {
52516
+ fileName = decodeURIComponent(ext[1]);
52517
+ } catch {
52518
+ fileName = ext[1];
52519
+ }
52520
+ } else if (plain?.[1]) {
52521
+ fileName = plain[1].replace(/"$/, "");
52522
+ }
52523
+ return {
52524
+ data: await res.arrayBuffer(),
52525
+ fileName,
52526
+ mimeType: res.headers.get("content-type") ?? "application/octet-stream"
52527
+ };
52528
+ }
52529
+ /**
52530
+ * Tier-B file upload verb (agent-only): share a file into a Slack
52531
+ * conversation this connection has seen inbound, with the same
52532
+ * reply-anchor contract as the text send.
52533
+ */
52534
+ async sendSlackFile(orgId, input) {
52535
+ const fd = new FormData();
52536
+ fd.append("conversation_id", input.conversationId);
52537
+ if (input.replyTo)
52538
+ fd.append("reply_to", input.replyTo);
52539
+ if (input.text)
52540
+ fd.append("text", input.text);
52541
+ fd.append("file", input.content, input.fileName);
52542
+ return this.multipartRequest("POST", ENDPOINTS.SLACK_FILES(orgId), fd);
52543
+ }
52544
+ };
52545
+
52546
+ // ../sdk/dist/channel-conversation-client.js
52547
+ var ChannelConversationClient = class extends SlackFilesClient {
52548
+ /**
52549
+ * Org-admin write of what the agent receives from a group root
52550
+ * (`PATCH …/channel-conversations/{id}/attention`); the agent's own path
52551
+ * is `setWatchLevel` with a `prll://chv_…` target.
52552
+ */
52553
+ async updateChannelConversationAttention(orgId, conversationId, body) {
52554
+ return this.request("PATCH", ENDPOINTS.CHANNEL_CONVERSATION_ATTENTION(orgId, conversationId), body);
52555
+ }
52556
+ };
52557
+
52486
52558
  // ../sdk/dist/wiki-upload.js
52487
52559
  function createWikiUploadFormData(params) {
52488
52560
  const form = new FormData();
@@ -52564,6 +52636,26 @@ function multipartXHR(options, onProgress) {
52564
52636
  });
52565
52637
  }
52566
52638
 
52639
+ // ../sdk/dist/fetch-cause.js
52640
+ var GENERIC_FETCH_MESSAGES = /* @__PURE__ */ new Set(["Failed to fetch", "fetch failed"]);
52641
+ function describeFetchCause(err) {
52642
+ const inner = err?.cause;
52643
+ for (const candidate of [inner, err]) {
52644
+ if (!(candidate instanceof Error))
52645
+ continue;
52646
+ const code = candidate.code;
52647
+ const parts = [];
52648
+ if (typeof code === "string" && code && !candidate.message.includes(code))
52649
+ parts.push(code);
52650
+ if (candidate.message && !GENERIC_FETCH_MESSAGES.has(candidate.message)) {
52651
+ parts.push(candidate.message);
52652
+ }
52653
+ if (parts.length > 0)
52654
+ return parts.join(" ");
52655
+ }
52656
+ return void 0;
52657
+ }
52658
+
52567
52659
  // ../sdk/dist/wiki-changeset.js
52568
52660
  function normalizeWikiChangeset(changeset) {
52569
52661
  return {
@@ -52577,7 +52669,7 @@ function normalizeWikiChangeset(changeset) {
52577
52669
  }
52578
52670
 
52579
52671
  // ../sdk/dist/client.js
52580
- var ParallClient = class _ParallClient extends AttachmentClient {
52672
+ var ParallClient = class _ParallClient extends ChannelConversationClient {
52581
52673
  baseUrl;
52582
52674
  wikiBaseUrl;
52583
52675
  token;
@@ -52612,13 +52704,13 @@ var ParallClient = class _ParallClient extends AttachmentClient {
52612
52704
  }
52613
52705
  }
52614
52706
  const apiError = new ApiError(0, "Network request failed", "NETWORK_ERROR");
52615
- if (err instanceof Error && err.message && err.message !== "Failed to fetch") {
52616
- apiError.extras = { cause: err.message };
52617
- }
52707
+ const cause = describeFetchCause(err);
52708
+ if (cause)
52709
+ apiError.extras = { cause };
52618
52710
  return apiError;
52619
52711
  }
52620
52712
  /** Build headers common to all requests (auth, swimlane). */
52621
- buildHeaders(path9, extra) {
52713
+ buildHeaders(path10, extra) {
52622
52714
  const headers = {
52623
52715
  "Content-Type": "application/json",
52624
52716
  ...extra
@@ -52629,7 +52721,7 @@ var ParallClient = class _ParallClient extends AttachmentClient {
52629
52721
  if (this.swimlaneName) {
52630
52722
  headers["X-Prll-Swimlane"] = this.swimlaneName;
52631
52723
  }
52632
- if (path9.startsWith(API_BASE)) {
52724
+ if (path10.startsWith(API_BASE)) {
52633
52725
  const overrides = this.getFeatureFlagOverrides?.();
52634
52726
  if (overrides)
52635
52727
  headers["X-Prll-FF-Override"] = overrides;
@@ -52653,8 +52745,8 @@ var ParallClient = class _ParallClient extends AttachmentClient {
52653
52745
  * is authoritative, so wiki vs api routing can't drift from how a caller
52654
52746
  * happens to invoke the client.
52655
52747
  */
52656
- baseUrlFor(path9) {
52657
- return path9.startsWith(WIKI_BASE) ? this.wikiBaseUrl : this.baseUrl;
52748
+ baseUrlFor(path10) {
52749
+ return path10.startsWith(WIKI_BASE) ? this.wikiBaseUrl : this.baseUrl;
52658
52750
  }
52659
52751
  setToken(token) {
52660
52752
  this.token = token;
@@ -52681,10 +52773,10 @@ var ParallClient = class _ParallClient extends AttachmentClient {
52681
52773
  * REFRESH_THRESHOLD_S, refresh it **before** sending the request.
52682
52774
  * No-op when the token is still fresh, missing, or un-parseable.
52683
52775
  */
52684
- async ensureFreshToken(path9) {
52776
+ async ensureFreshToken(path10) {
52685
52777
  if (!this.token || !this.getRefreshToken)
52686
52778
  return;
52687
- const pathSuffix = path9.replace(/^\/api\/v1/, "");
52779
+ const pathSuffix = path10.replace(/^\/api\/v1/, "");
52688
52780
  if (_ParallClient.AUTH_PATHS.has(pathSuffix))
52689
52781
  return;
52690
52782
  const exp = _ParallClient.decodeJwtExp(this.token);
@@ -52716,11 +52808,11 @@ var ParallClient = class _ParallClient extends AttachmentClient {
52716
52808
  this.refreshPromise = null;
52717
52809
  }
52718
52810
  }
52719
- async request(method, path9, body, query, retried = false, opts) {
52811
+ async request(method, path10, body, query, retried = false, opts) {
52720
52812
  if (!retried) {
52721
- await this.ensureFreshToken(path9);
52813
+ await this.ensureFreshToken(path10);
52722
52814
  }
52723
- let url = `${this.baseUrlFor(path9)}${path9}`;
52815
+ let url = `${this.baseUrlFor(path10)}${path10}`;
52724
52816
  if (query) {
52725
52817
  const params = new URLSearchParams();
52726
52818
  for (const [key, value] of Object.entries(query)) {
@@ -52732,7 +52824,7 @@ var ParallClient = class _ParallClient extends AttachmentClient {
52732
52824
  if (qs)
52733
52825
  url += `?${qs}`;
52734
52826
  }
52735
- const headers = this.buildHeaders(path9, opts?.headers);
52827
+ const headers = this.buildHeaders(path10, opts?.headers);
52736
52828
  const timeoutSignal = AbortSignal.timeout(opts?.timeoutMs ?? 15e3);
52737
52829
  const signal = opts?.signal ? AbortSignal.any([opts.signal, timeoutSignal]) : timeoutSignal;
52738
52830
  let res;
@@ -52750,12 +52842,12 @@ var ParallClient = class _ParallClient extends AttachmentClient {
52750
52842
  throw _ParallClient.normalizeFetchError(err);
52751
52843
  }
52752
52844
  if (res.status === 401) {
52753
- const pathSuffix = path9.replace(/^\/api\/v1/, "");
52845
+ const pathSuffix = path10.replace(/^\/api\/v1/, "");
52754
52846
  const isAuthPath = _ParallClient.AUTH_PATHS.has(pathSuffix);
52755
52847
  if (!retried && !isAuthPath && this.getRefreshToken) {
52756
52848
  const refreshed = await this.tryRefresh();
52757
52849
  if (refreshed) {
52758
- return this.request(method, path9, body, query, true, opts);
52850
+ return this.request(method, path10, body, query, true, opts);
52759
52851
  }
52760
52852
  }
52761
52853
  if (this.onTokenExpired && !isAuthPath) {
@@ -52785,18 +52877,18 @@ var ParallClient = class _ParallClient extends AttachmentClient {
52785
52877
  * hit the 100 MiB cap, so a longer 5-minute timeout is used so a
52786
52878
  * 50 MiB blob on a slow connection doesn't get chopped at 15 s.
52787
52879
  */
52788
- async multipartRequest(method, path9, body, retried = false, opts) {
52880
+ async multipartRequest(method, path10, body, retried = false, opts) {
52789
52881
  if (!retried) {
52790
- await this.ensureFreshToken(path9);
52882
+ await this.ensureFreshToken(path10);
52791
52883
  }
52792
- const { "Content-Type": _drop, ...headers } = this.buildHeaders(path9);
52884
+ const { "Content-Type": _drop, ...headers } = this.buildHeaders(path10);
52793
52885
  void _drop;
52794
52886
  const timeoutMs = opts?.timeoutMs ?? 5 * 60 * 1e3;
52795
52887
  let res;
52796
52888
  try {
52797
52889
  res = await sendMultipartRequest({
52798
52890
  method,
52799
- url: `${this.baseUrlFor(path9)}${path9}`,
52891
+ url: `${this.baseUrlFor(path10)}${path10}`,
52800
52892
  headers,
52801
52893
  body,
52802
52894
  timeoutMs,
@@ -52807,12 +52899,12 @@ var ParallClient = class _ParallClient extends AttachmentClient {
52807
52899
  throw _ParallClient.normalizeFetchError(err);
52808
52900
  }
52809
52901
  if (res.status === 401) {
52810
- const pathSuffix = path9.replace(/^\/api\/v1/, "");
52902
+ const pathSuffix = path10.replace(/^\/api\/v1/, "");
52811
52903
  const isAuthPath = _ParallClient.AUTH_PATHS.has(pathSuffix);
52812
52904
  if (!retried && !isAuthPath && this.getRefreshToken) {
52813
52905
  const refreshed = await this.tryRefresh();
52814
52906
  if (refreshed) {
52815
- return this.multipartRequest(method, path9, body, true, opts);
52907
+ return this.multipartRequest(method, path10, body, true, opts);
52816
52908
  }
52817
52909
  }
52818
52910
  if (this.onTokenExpired && !isAuthPath) {
@@ -53656,8 +53748,8 @@ var ParallClient = class _ParallClient extends AttachmentClient {
53656
53748
  * remote filesystem browse of a member's machine was remote device access.
53657
53749
  * The endpoint now answers 409 LOCAL_BROWSE_NOT_SUPPORTED unconditionally;
53658
53750
  * workspace paths are typed in (or picked on the machine's own Desktop). */
53659
- async browseMachineFilesystem(orgId, machineId, path9) {
53660
- return this.request("POST", ENDPOINTS.MACHINE_BROWSE(orgId, machineId), { path: path9 }, void 0, false, { timeoutMs: 15e3 });
53751
+ async browseMachineFilesystem(orgId, machineId, path10) {
53752
+ return this.request("POST", ENDPOINTS.MACHINE_BROWSE(orgId, machineId), { path: path10 }, void 0, false, { timeoutMs: 15e3 });
53661
53753
  }
53662
53754
  /** Create a new machine key. Returns the raw key string (shown once) + metadata. */
53663
53755
  async createMachineKey(orgId, machineId, name) {
@@ -53971,6 +54063,42 @@ var ParallClient = class _ParallClient extends AttachmentClient {
53971
54063
  async setSlackStatus(orgId, input) {
53972
54064
  await this.request("POST", ENDPOINTS.SLACK_STATUS(orgId), input);
53973
54065
  }
54066
+ /**
54067
+ * Authorized raw GET (binary responses) with the same auth, 401
54068
+ * refresh-and-retry-once, and error-envelope handling as `request` — the
54069
+ * transfer primitive the SlackFilesClient domain module builds on.
54070
+ */
54071
+ async rawAuthorizedFetch(path10, opts, retried = false) {
54072
+ if (!retried) {
54073
+ await this.ensureFreshToken(path10);
54074
+ }
54075
+ const headers = this.buildHeaders(path10);
54076
+ let res;
54077
+ try {
54078
+ res = await fetch(`${this.baseUrlFor(path10)}${path10}`, {
54079
+ method: "GET",
54080
+ headers,
54081
+ // File transfers get the multipart-tier budget, not the 15s JSON one.
54082
+ signal: AbortSignal.timeout(opts?.timeoutMs ?? 5 * 60 * 1e3)
54083
+ });
54084
+ } catch (err) {
54085
+ throw _ParallClient.normalizeFetchError(err);
54086
+ }
54087
+ if (res.status === 401) {
54088
+ if (!retried && this.getRefreshToken) {
54089
+ const refreshed = await this.tryRefresh();
54090
+ if (refreshed) {
54091
+ return this.rawAuthorizedFetch(path10, opts, true);
54092
+ }
54093
+ }
54094
+ this.onTokenExpired?.();
54095
+ }
54096
+ if (!res.ok) {
54097
+ const rawErrorBody = await res.json().catch(() => ({}));
54098
+ throw buildApiError(res, rawErrorBody);
54099
+ }
54100
+ return res;
54101
+ }
53974
54102
  async listChannelConversations(orgId, connectionId) {
53975
54103
  return this.request("GET", ENDPOINTS.CHANNEL_CONNECTION_CONVERSATIONS(orgId, connectionId));
53976
54104
  }
@@ -54231,12 +54359,12 @@ var ParallClient = class _ParallClient extends AttachmentClient {
54231
54359
  async deleteWikiRestriction(orgId, wikiId, restrictionId) {
54232
54360
  await this.request("DELETE", ENDPOINTS.WIKI_RESTRICTION(orgId, wikiId, restrictionId));
54233
54361
  }
54234
- async getWikiAccessStatus(orgId, wikiId, path9) {
54235
- return this.request("GET", ENDPOINTS.WIKI_ACCESS_STATUS(orgId, wikiId), void 0, path9 ? { path: path9 } : void 0);
54362
+ async getWikiAccessStatus(orgId, wikiId, path10) {
54363
+ return this.request("GET", ENDPOINTS.WIKI_ACCESS_STATUS(orgId, wikiId), void 0, path10 ? { path: path10 } : void 0);
54236
54364
  }
54237
54365
  // ---- Wiki membership projection (who-can-access, invites, join/leave) ----
54238
- async getWikiAccessPolicy(orgId, wikiId, path9 = "") {
54239
- return this.request("GET", ENDPOINTS.WIKI_ACCESS_POLICY(orgId, wikiId), void 0, path9 ? { path: path9 } : void 0);
54366
+ async getWikiAccessPolicy(orgId, wikiId, path10 = "") {
54367
+ return this.request("GET", ENDPOINTS.WIKI_ACCESS_POLICY(orgId, wikiId), void 0, path10 ? { path: path10 } : void 0);
54240
54368
  }
54241
54369
  async putWikiAccessPolicy(orgId, wikiId, policy) {
54242
54370
  return this.request("PUT", ENDPOINTS.WIKI_ACCESS_POLICY(orgId, wikiId), policy);
@@ -54281,14 +54409,14 @@ var ParallClient = class _ParallClient extends AttachmentClient {
54281
54409
  async getWikiCommits(orgId, wikiId, params) {
54282
54410
  return this.request("GET", ENDPOINTS.WIKI_COMMITS(orgId, wikiId), void 0, params);
54283
54411
  }
54284
- async getWikiFileCommits(orgId, wikiId, path9, params) {
54412
+ async getWikiFileCommits(orgId, wikiId, path10, params) {
54285
54413
  return this.request("GET", ENDPOINTS.WIKI_FILE_COMMITS(orgId, wikiId), void 0, {
54286
- path: path9,
54414
+ path: path10,
54287
54415
  ...params
54288
54416
  });
54289
54417
  }
54290
- async getWikiBlame(orgId, wikiId, path9, ref) {
54291
- return this.request("GET", ENDPOINTS.WIKI_BLAME(orgId, wikiId), void 0, { path: path9, ref });
54418
+ async getWikiBlame(orgId, wikiId, path10, ref) {
54419
+ return this.request("GET", ENDPOINTS.WIKI_BLAME(orgId, wikiId), void 0, { path: path10, ref });
54292
54420
  }
54293
54421
  // ---- Wiki Operations (audit log) ----
54294
54422
  async getWikiOperations(orgId, wikiId, params) {
@@ -55074,6 +55202,23 @@ var ApiError = class extends Error {
55074
55202
  this.code = code;
55075
55203
  this.name = "ApiError";
55076
55204
  }
55205
+ /**
55206
+ * The `String(err)` form daemon and bridge logs print. `message` stays the
55207
+ * human sentence the UI shows; the bracket carries the machine-readable
55208
+ * code, the HTTP status and the transport cause, so a NETWORK_ERROR line
55209
+ * says which socket failure it actually was instead of the same eight words
55210
+ * for every outage.
55211
+ */
55212
+ toString() {
55213
+ const detail = [];
55214
+ if (this.code)
55215
+ detail.push(this.status ? `${this.code} ${this.status}` : this.code);
55216
+ const cause = this.extras?.cause;
55217
+ if (typeof cause === "string" && cause)
55218
+ detail.push(`cause: ${cause}`);
55219
+ const base = `${this.name}: ${this.message}`;
55220
+ return detail.length > 0 ? `${base} [${detail.join("; ")}]` : base;
55221
+ }
55077
55222
  };
55078
55223
  function buildApiError(res, rawErrorBody) {
55079
55224
  const errorBody = rawErrorBody !== null && typeof rawErrorBody === "object" ? rawErrorBody : {};
@@ -55505,6 +55650,29 @@ function laneContextFilePath(contextDir, targetUri, threadRootId) {
55505
55650
  return path2.join(contextDir, `${laneKeyForTarget(targetUri, threadRootId)}.json`);
55506
55651
  }
55507
55652
 
55653
+ // ../agent-core/dist/lane-target.js
55654
+ var PRLL_SCHEME = "prll://";
55655
+ var CHAT_LANE_PREFIX = "cht_";
55656
+ var CHANNEL_LANE_PREFIX = `${PRLL_SCHEME}chv_`;
55657
+ function channelLaneTargetUri(item) {
55658
+ return item.event_type === "channel_message" && item.target_uri?.startsWith(CHANNEL_LANE_PREFIX) ? item.target_uri : void 0;
55659
+ }
55660
+ function laneTargetId(targetUri) {
55661
+ return targetUri.startsWith(PRLL_SCHEME) ? targetUri.slice(PRLL_SCHEME.length) : targetUri;
55662
+ }
55663
+ function laneTargetUri(event) {
55664
+ if (event.type === "message") {
55665
+ return event.targetId.startsWith(CHAT_LANE_PREFIX) ? `${PRLL_SCHEME}${event.targetId}` : void 0;
55666
+ }
55667
+ if (event.type === "channel_message") {
55668
+ return event.targetUri?.startsWith(CHANNEL_LANE_PREFIX) ? event.targetUri : void 0;
55669
+ }
55670
+ return void 0;
55671
+ }
55672
+ function isTypedEvent(event) {
55673
+ return event.type !== "message" && laneTargetUri(event) === void 0;
55674
+ }
55675
+
55508
55676
  // ../agent-core/dist/lane-ledger.js
55509
55677
  var LedgerUnsupportedError = class extends Error {
55510
55678
  };
@@ -55537,15 +55705,16 @@ var LaneLedger = class {
55537
55705
  get contextDir() {
55538
55706
  return this.opts.contextDir;
55539
55707
  }
55540
- /** Chat message events ride (target, thread) lanes; typed events ride single-member dsp lanes (claimTyped). */
55708
+ /** Message-lane events (chat, channel conversation — lane-target.ts) ride (target, thread) lanes; typed events ride single-member dsp lanes (claimTyped). */
55541
55709
  handles(event) {
55542
- return event.type === "message" && event.targetId.startsWith("cht_");
55710
+ return laneTargetUri(event) !== void 0;
55543
55711
  }
55544
55712
  laneKeyFor(event) {
55545
- if (event.type !== "message" && event.dispatchEventId) {
55713
+ const targetUri = laneTargetUri(event);
55714
+ if (!targetUri && event.type !== "message" && event.dispatchEventId) {
55546
55715
  return laneKeyForTarget(`dsp:${event.dispatchEventId}`);
55547
55716
  }
55548
- return laneKeyForTarget(`prll://${event.targetId}`, event.threadRootId);
55717
+ return laneKeyForTarget(targetUri ?? `prll://${event.targetId}`, event.threadRootId);
55549
55718
  }
55550
55719
  getForEvent(event) {
55551
55720
  return this.lanes.get(this.laneKeyFor(event));
@@ -55630,11 +55799,27 @@ ${frame}` : frame;
55630
55799
  * incumbent completes.
55631
55800
  */
55632
55801
  async ensureLane(events) {
55802
+ return this.ensureLaneAttempt(events, false);
55803
+ }
55804
+ /**
55805
+ * One ensureLane pass. `reclaimed` marks the arbitration retry: STALE_LANE
55806
+ * on a REUSED cached lane means our cache outlived the server lease (a
55807
+ * missed complete), not that a healthy incumbent holds the resource — claim
55808
+ * is the only ownership arbiter, so ask it once instead of leaving the
55809
+ * members to wait out the renotify pacing. STALE_LANE right after a fresh
55810
+ * claim is a real takeover race and stays foreign. The server's incumbency
55811
+ * check is the only staleness authority — deciding expiry locally from the
55812
+ * bridge wall clock against the server-issued lease_until would let a
55813
+ * clock-skewed host destructively discard a still-current lane's fold/seen
55814
+ * state, so no local pre-check exists on purpose.
55815
+ */
55816
+ async ensureLaneAttempt(events, reclaimed) {
55633
55817
  const trigger = events[events.length - 1];
55634
55818
  const laneKey = this.laneKeyFor(trigger);
55635
55819
  let lane = this.lanes.get(laneKey);
55820
+ const reused = lane != null;
55636
55821
  if (!lane) {
55637
- const targetUri = `prll://${trigger.targetId}`;
55822
+ const targetUri = laneTargetUri(trigger) ?? `prll://${trigger.targetId}`;
55638
55823
  let res;
55639
55824
  try {
55640
55825
  res = await this.opts.client.claimDispatch(this.opts.orgId, {
@@ -55690,13 +55875,18 @@ ${frame}` : frame;
55690
55875
  lane: lane.lane,
55691
55876
  target_uri: lane.targetUri,
55692
55877
  thread_root_id: lane.threadRootId,
55693
- ...ev.dispatchEventId ? { dispatch_event_id: ev.dispatchEventId } : { source_type: "message", source_id: ev.messageId }
55878
+ ...ev.dispatchEventId ? { dispatch_event_id: ev.dispatchEventId } : { source_type: ev.ackSourceType ?? "message", source_id: ev.messageId }
55694
55879
  });
55695
55880
  lane.folded.set(ev.messageId, res.dispatch_event_id);
55696
55881
  this.recordFrame(lane, res.frame, [ev.messageId]);
55697
55882
  } catch (err) {
55698
55883
  if (isStaleLane(err)) {
55699
55884
  this.lanes.delete(laneKey);
55885
+ this.removeLaneContext(lane);
55886
+ if (reused && !reclaimed) {
55887
+ this.opts.log?.info(`cached lane for ${lane.targetUri} is stale \u2014 re-claiming to arbitrate ownership`);
55888
+ return this.ensureLaneAttempt(events, true);
55889
+ }
55700
55890
  return null;
55701
55891
  }
55702
55892
  this.opts.log?.warn(`steer fold failed for ${ev.messageId} \u2014 failing closed, releasing lane: ${String(err)}`);
@@ -55730,7 +55920,7 @@ ${frame}` : frame;
55730
55920
  lane: lane.lane,
55731
55921
  target_uri: lane.targetUri,
55732
55922
  thread_root_id: lane.threadRootId,
55733
- ...event.dispatchEventId ? { dispatch_event_id: event.dispatchEventId } : { source_type: "message", source_id: event.messageId }
55923
+ ...event.dispatchEventId ? { dispatch_event_id: event.dispatchEventId } : { source_type: event.ackSourceType ?? "message", source_id: event.messageId }
55734
55924
  });
55735
55925
  lane.folded.set(event.messageId, res.dispatch_event_id);
55736
55926
  const covered = [event.messageId];
@@ -55742,6 +55932,7 @@ ${frame}` : frame;
55742
55932
  } catch (err) {
55743
55933
  if (isStaleLane(err)) {
55744
55934
  this.lanes.delete(laneKey);
55935
+ this.removeLaneContext(lane);
55745
55936
  } else {
55746
55937
  this.opts.log?.warn(`live steer failed for ${event.messageId}: ${String(err)}`);
55747
55938
  }
@@ -55760,17 +55951,18 @@ ${frame}` : frame;
55760
55951
  * prompt or injection actually delivers (frame coverage ∪ buffered group).
55761
55952
  */
55762
55953
  inputLifecycleFor(lane, messageIds) {
55763
- if (lane.coverageMode !== "explicit")
55764
- return void 0;
55954
+ const explicit = lane.coverageMode === "explicit";
55765
55955
  const unique = [...new Set(messageIds)];
55766
55956
  const dispatchEventIds = unique.map((messageId) => lane.folded.get(messageId)).filter((id) => Boolean(id));
55767
- if (dispatchEventIds.length !== unique.length) {
55957
+ if (explicit && dispatchEventIds.length !== unique.length) {
55768
55958
  throw new Error(`explicit lane ${lane.lane} is missing a folded WorkItem mapping`);
55769
55959
  }
55960
+ if (!explicit && dispatchEventIds.length === 0)
55961
+ return void 0;
55770
55962
  return {
55771
55963
  deliveryKey: dispatchEventIds.join(","),
55772
55964
  dispatchEventIds,
55773
- update: (state) => this.updateInputState(lane, dispatchEventIds, state)
55965
+ update: explicit ? (state) => this.updateInputState(lane, dispatchEventIds, state) : async () => void 0
55774
55966
  };
55775
55967
  }
55776
55968
  async updateInputState(lane, dispatchEventIds, state) {
@@ -56116,8 +56308,15 @@ async function dispatchLaneGroup(host, opts) {
56116
56308
  const frame = pending.frame;
56117
56309
  if (!frame && opts.events.every((ev) => lane.seen.has(ev.messageId))) {
56118
56310
  host.opts.log?.info(`lane group for ${event.messageId} already rendered by the server frame \u2014 no turn`);
56119
- const pendingInjections2 = host.opts.dispatchAdapter.hasPendingInjections?.(opts.sessionKey) ?? false;
56120
- await ledger.completeIfIdle(lane.laneKey, pendingInjections2 || opts.hasMoreLocal());
56311
+ const acknowledge = host.opts.dispatchAdapter.acknowledgeDiscardedInjection?.bind(host.opts.dispatchAdapter);
56312
+ if (acknowledge) {
56313
+ for (const ev of opts.events) {
56314
+ const deliveryKey = lane.folded.get(ev.messageId);
56315
+ if (deliveryKey)
56316
+ acknowledge(opts.sessionKey, deliveryKey);
56317
+ }
56318
+ }
56319
+ await ledger.completeIfIdle(lane.laneKey, unsettledInjections(host, opts.sessionKey) || opts.hasMoreLocal());
56121
56320
  return "dispatched";
56122
56321
  }
56123
56322
  if (!frame) {
@@ -56170,10 +56369,13 @@ async function dispatchLaneGroup(host, opts) {
56170
56369
  await ledger.completeIfIdle(lane.laneKey, false);
56171
56370
  return settled.kind === "deferred" ? "deferred" : "failed";
56172
56371
  }
56173
- const pendingInjections = host.opts.dispatchAdapter.hasPendingInjections?.(opts.sessionKey) ?? false;
56174
- await ledger.completeIfIdle(lane.laneKey, pendingInjections || opts.hasMoreLocal());
56372
+ await ledger.completeIfIdle(lane.laneKey, unsettledInjections(host, opts.sessionKey) || opts.hasMoreLocal());
56175
56373
  return "dispatched";
56176
56374
  }
56375
+ function unsettledInjections(host, sessionKey) {
56376
+ const adapter = host.opts.dispatchAdapter;
56377
+ return adapter.hasUnsettledInjections?.(sessionKey) ?? adapter.hasPendingInjections?.(sessionKey) ?? false;
56378
+ }
56177
56379
  function typedLedgerEventIds(host, events) {
56178
56380
  if (!host.laneLedger || host.ledgerDisabled)
56179
56381
  return null;
@@ -56314,18 +56516,29 @@ async function consumeTypedDispatch(host, ref, run, hooks) {
56314
56516
  }
56315
56517
  }
56316
56518
  }
56317
- async function consumeMessageWorkItem(host, item) {
56519
+ async function consumeLaneWorkItem(host, event) {
56318
56520
  if (host.shuttingDown)
56319
56521
  return;
56320
- if (!host.tryClaimMessage(item.source_id))
56522
+ if (!host.tryClaimMessage(event.messageId))
56321
56523
  return;
56322
- if (host.dispatchState.mainBuffer.some((event2) => event2.messageId === item.source_id))
56524
+ if (host.dispatchState.mainBuffer.some((e) => e.messageId === event.messageId))
56323
56525
  return;
56324
- if (host.laneLedger && !host.ledgerDisabled && host.laneLedger.seenInFrame(item.chat_id, item.thread_root_id ?? void 0, item.source_id)) {
56526
+ if (host.laneLedger && !host.ledgerDisabled && host.laneLedger.seenInFrame(event.targetId, event.threadRootId, event.messageId)) {
56325
56527
  return;
56326
56528
  }
56529
+ try {
56530
+ const dispatched = await host.handleInboundEvent(event);
56531
+ if (!dispatched) {
56532
+ host.dispatchedMessages.delete(event.messageId);
56533
+ }
56534
+ } catch (err) {
56535
+ host.dispatchedMessages.delete(event.messageId);
56536
+ throw err;
56537
+ }
56538
+ }
56539
+ function consumeMessageWorkItem(host, item) {
56327
56540
  const change = splitChangeSource(item.source_id);
56328
- const event = {
56541
+ return consumeLaneWorkItem(host, {
56329
56542
  type: "message",
56330
56543
  targetId: item.chat_id,
56331
56544
  targetType: "chat",
@@ -56336,17 +56549,713 @@ async function consumeMessageWorkItem(host, item) {
56336
56549
  ackSourceType: "message",
56337
56550
  ackSourceId: item.source_id,
56338
56551
  dispatchEventId: item.id
56552
+ });
56553
+ }
56554
+ function consumeChannelWorkItem(host, item) {
56555
+ return consumeLaneWorkItem(host, {
56556
+ type: "channel_message",
56557
+ targetId: laneTargetId(item.target_uri),
56558
+ targetType: "channel_conversation",
56559
+ targetUri: item.target_uri,
56560
+ senderId: item.actor_id ?? "",
56561
+ messageId: item.source_id,
56562
+ threadRootId: item.thread_root_id ?? void 0,
56563
+ deliveryReason: item.delivery_reason ?? void 0,
56564
+ ackSourceType: "channel_message",
56565
+ ackSourceId: item.source_id,
56566
+ dispatchEventId: item.id
56567
+ });
56568
+ }
56569
+
56570
+ // ../agent-core/dist/gateway-idle-compact.js
56571
+ var COMPACT_BUDGET_MS = 18e4;
56572
+ function createIdleCompactState() {
56573
+ return { inFlight: null, abort: null };
56574
+ }
56575
+ function sameInstant(a, b) {
56576
+ if (a == null || b == null)
56577
+ return a === b;
56578
+ const ta = Date.parse(a);
56579
+ const tb = Date.parse(b);
56580
+ if (Number.isNaN(ta) || Number.isNaN(tb))
56581
+ return a === b;
56582
+ return ta === tb;
56583
+ }
56584
+ function mainLaneBusy(host) {
56585
+ return host.idleCompact.inFlight != null || host.draining || host.dispatchState.mainDispatching || host.dispatchState.mainBuffer.length > 0;
56586
+ }
56587
+ async function handleCompactSignal(host, data) {
56588
+ const log = host.opts.log;
56589
+ const adapter = host.opts.dispatchAdapter;
56590
+ const sessionId = data?.session_id ?? "";
56591
+ if (!adapter.compact) {
56592
+ log?.info(`agent.compact ignored: compact unsupported by adapter (session=${sessionId})`);
56593
+ return;
56594
+ }
56595
+ if (host.shuttingDown) {
56596
+ log?.info(`agent.compact ignored: shutting down (session=${sessionId})`);
56597
+ return;
56598
+ }
56599
+ const bound = host.boundMainSessionId();
56600
+ if (!bound || !sessionId || bound !== sessionId) {
56601
+ log?.info(`agent.compact ignored: session ${sessionId || "(none)"} is not the bound main session (${bound ?? "unbound"})`);
56602
+ return;
56603
+ }
56604
+ if (mainLaneBusy(host)) {
56605
+ log?.info(`agent.compact dropped: main lane busy (session=${sessionId})`);
56606
+ return;
56607
+ }
56608
+ let release;
56609
+ host.idleCompact.inFlight = new Promise((resolve3) => {
56610
+ release = resolve3;
56611
+ });
56612
+ const controller = new AbortController();
56613
+ host.idleCompact.abort = () => controller.abort();
56614
+ const startedAt = Date.now();
56615
+ try {
56616
+ let session;
56617
+ try {
56618
+ session = await host.opts.client.getAgentSession(host.opts.config.org_id, host.opts.agentUserId, sessionId);
56619
+ } catch (err) {
56620
+ log?.warn(`agent.compact dropped: session re-read failed (${String(err)})`);
56621
+ return;
56622
+ }
56623
+ if (session.status !== "idle" || !sameInstant(session.idle_since ?? null, data.idle_since)) {
56624
+ log?.info(`agent.compact dropped: session ${sessionId} is no longer idle for this period (status=${session.status}, idle_since=${session.idle_since ?? "null"}, event=${data.idle_since})`);
56625
+ return;
56626
+ }
56627
+ if (host.dispatchState.mainBuffer.length > 0 || host.dispatchState.mainDispatching) {
56628
+ log?.info(`agent.compact dropped: dispatch queued during session re-read (session=${sessionId})`);
56629
+ return;
56630
+ }
56631
+ const timer = setTimeout(() => controller.abort(), COMPACT_BUDGET_MS);
56632
+ timer.unref?.();
56633
+ try {
56634
+ const result = await adapter.compact({
56635
+ sessionKey: host.opts.runtimeKey,
56636
+ signal: controller.signal,
56637
+ log
56638
+ });
56639
+ const elapsed = Date.now() - startedAt;
56640
+ const tokens = [
56641
+ result.preTokens != null ? `pre_tokens=${result.preTokens}` : null,
56642
+ result.postTokens != null ? `post_tokens=${result.postTokens}` : null
56643
+ ].filter(Boolean).join(" ");
56644
+ const line = `idle compact ${result.status} (session=${sessionId}, elapsed_ms=${elapsed}${tokens ? ` ${tokens}` : ""}${result.detail ? `, detail=${result.detail}` : ""})`;
56645
+ if (result.status === "done" || result.status === "noop")
56646
+ log?.info(line);
56647
+ else
56648
+ log?.warn(line);
56649
+ } catch (err) {
56650
+ log?.warn(`idle compact failed (session=${sessionId}, elapsed_ms=${Date.now() - startedAt}): ${String(err)}`);
56651
+ } finally {
56652
+ clearTimeout(timer);
56653
+ }
56654
+ } finally {
56655
+ host.idleCompact.abort = null;
56656
+ host.idleCompact.inFlight = null;
56657
+ release();
56658
+ if (!host.shuttingDown && !host.draining && !host.dispatchState.mainDispatching && host.dispatchState.mainBuffer.length > 0) {
56659
+ host.dispatchState.mainDispatching = true;
56660
+ host.kickMainDrain();
56661
+ }
56662
+ }
56663
+ }
56664
+
56665
+ // ../agent-core/dist/redact.js
56666
+ function redactSecrets(s, knownValues = []) {
56667
+ let out = s;
56668
+ for (const v of knownValues) {
56669
+ if (typeof v === "string" && v.length >= 6)
56670
+ out = out.split(v).join("***");
56671
+ }
56672
+ return out.replace(/\b(agk|mck|cpk)_[A-Za-z0-9_-]+/g, "$1_***").replace(/\b(sk|pk|rk)-[A-Za-z0-9_-]{8,}/g, "$1-***").replace(/\bAKIA[0-9A-Z]{16}\b/g, "AKIA***").replace(/\b(bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi, "$1***").replace(/[A-Za-z0-9_-]{32,}/g, "***");
56673
+ }
56674
+ function redactTurnOutcome(event, knownValues) {
56675
+ const redacted = { ...event };
56676
+ if (redacted.detail)
56677
+ redacted.detail = redactSecrets(redacted.detail, knownValues);
56678
+ if (redacted.raw) {
56679
+ redacted.raw = Object.fromEntries(Object.entries(redacted.raw).map(([k, v]) => [
56680
+ k,
56681
+ typeof v === "string" ? redactSecrets(v, knownValues) : v
56682
+ ]));
56683
+ }
56684
+ return redacted;
56685
+ }
56686
+ function describeTurnOutcomeFailure(outcome) {
56687
+ const retryNote = outcome.retryAt ? `, retry at ${outcome.retryAt}` : "";
56688
+ return {
56689
+ warn: `${outcome.outcome}${retryNote}${outcome.detail ? ` \u2014 ${outcome.detail}` : ""}`,
56690
+ stepMessage: `LLM turn ${outcome.outcome}${retryNote}${outcome.detail ? `: ${outcome.detail}` : ""}`
56339
56691
  };
56692
+ }
56693
+
56694
+ // ../agent-core/dist/telemetry.js
56695
+ init_esm();
56696
+ var import_api_logs = __toESM(require_src(), 1);
56697
+ import { AsyncLocalStorage } from "node:async_hooks";
56698
+ import { readFileSync as readFileSync2 } from "node:fs";
56699
+ import * as path3 from "node:path";
56700
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
56701
+ var initialized = false;
56702
+ var shutdownFn = null;
56703
+ var tracer = null;
56704
+ var dispatchCounter = null;
56705
+ var dispatchDuration = null;
56706
+ var missingReplyCounter = null;
56707
+ var turnTokensCounter = null;
56708
+ var turnCostCounter = null;
56709
+ var otelLogger = null;
56710
+ function resolveTargetType(targetId) {
56711
+ if (targetId.startsWith("cht_"))
56712
+ return "chat";
56713
+ if (targetId.startsWith("tsk_"))
56714
+ return "task";
56715
+ if (targetId.startsWith("sch_"))
56716
+ return "schedule";
56717
+ return "unknown";
56718
+ }
56719
+ var PRODUCTION_API_HOSTS = /* @__PURE__ */ new Set(["api.parall.com"]);
56720
+ var STAGING_API_HOSTS = /* @__PURE__ */ new Set(["api.staging.prll.sh"]);
56721
+ function resolveTelemetryEnvironment(apiUrl, override = process.env.PRLL_SERVER_ENV) {
56722
+ const forced = override?.trim();
56723
+ if (forced)
56724
+ return forced;
56725
+ let host = "";
56340
56726
  try {
56341
- const dispatched = await host.handleInboundEvent(event);
56342
- if (!dispatched) {
56343
- host.dispatchedMessages.delete(item.source_id);
56727
+ host = apiUrl ? new URL(apiUrl).hostname.toLowerCase() : "";
56728
+ } catch {
56729
+ host = "";
56730
+ }
56731
+ if (PRODUCTION_API_HOSTS.has(host))
56732
+ return "production";
56733
+ if (STAGING_API_HOSTS.has(host))
56734
+ return "staging";
56735
+ return "development";
56736
+ }
56737
+ function resolveServiceVersion(importMetaUrl) {
56738
+ const fallback = process.env.npm_package_version || "unknown";
56739
+ let dir;
56740
+ try {
56741
+ dir = path3.dirname(fileURLToPath2(importMetaUrl));
56742
+ } catch {
56743
+ return fallback;
56744
+ }
56745
+ for (const candidate of [path3.join(dir, "manifest.json"), path3.join(dir, "..", "package.json")]) {
56746
+ try {
56747
+ const parsed = JSON.parse(readFileSync2(candidate, "utf-8"));
56748
+ if (typeof parsed.version === "string" && parsed.version.trim()) {
56749
+ return parsed.version.trim();
56750
+ }
56751
+ } catch {
56752
+ }
56753
+ }
56754
+ return fallback;
56755
+ }
56756
+ var DIAG_THROTTLE_MS = 6e4;
56757
+ var DIAG_THROTTLE_KEYS = 200;
56758
+ function createThrottledDiagLogger(now = Date.now) {
56759
+ const lastAt = /* @__PURE__ */ new Map();
56760
+ const describe = (a) => {
56761
+ if (a instanceof Error)
56762
+ return a.message;
56763
+ if (a && typeof a === "object" && typeof a.message === "string") {
56764
+ return a.message;
56765
+ }
56766
+ if (typeof a === "string" && a.startsWith("{")) {
56767
+ try {
56768
+ const parsed = JSON.parse(a);
56769
+ if (typeof parsed.message === "string")
56770
+ return parsed.message;
56771
+ } catch {
56772
+ }
56344
56773
  }
56774
+ return String(a);
56775
+ };
56776
+ const emit = (level, args) => {
56777
+ const msg = args.map(describe).join(" ");
56778
+ const key = `${level}:${msg.slice(0, 160)}`;
56779
+ const at = now();
56780
+ const prev = lastAt.get(key);
56781
+ if (prev !== void 0 && at - prev < DIAG_THROTTLE_MS)
56782
+ return;
56783
+ if (lastAt.size >= DIAG_THROTTLE_KEYS)
56784
+ lastAt.clear();
56785
+ lastAt.set(key, at);
56786
+ console.warn(`${new Date(at).toISOString()} [telemetry] otel ${level}: ${msg}`);
56787
+ };
56788
+ return {
56789
+ verbose: () => {
56790
+ },
56791
+ debug: () => {
56792
+ },
56793
+ info: () => {
56794
+ },
56795
+ warn: (...args) => emit("warn", args),
56796
+ error: (...args) => emit("error", args)
56797
+ };
56798
+ }
56799
+ async function initAgentTelemetry(serviceName, runtimeType, opts = {}) {
56800
+ const noopHandle = { shutdown: async () => {
56801
+ } };
56802
+ const apiUrl = opts.apiUrl ?? process.env.PRLL_API_URL;
56803
+ const apiKey = opts.apiKey ?? process.env.PRLL_API_KEY;
56804
+ if (!apiUrl || !apiKey) {
56805
+ console.warn(`${(/* @__PURE__ */ new Date()).toISOString()} [telemetry] disabled: no API url/key resolved for ${serviceName} \u2014 nothing will reach SigNoz`);
56806
+ return noopHandle;
56807
+ }
56808
+ const environment = opts.environment ?? resolveTelemetryEnvironment(apiUrl);
56809
+ const serviceVersion = opts.serviceVersion ?? process.env.npm_package_version ?? "unknown";
56810
+ try {
56811
+ const otelEndpoint = apiUrl.replace(/\/$/, "") + "/otel";
56812
+ if (!initialized)
56813
+ diag2.setLogger(createThrottledDiagLogger(), DiagLogLevel.WARN);
56814
+ const { OTLPTraceExporter } = await Promise.resolve().then(() => __toESM(require_src6(), 1));
56815
+ const { OTLPMetricExporter } = await Promise.resolve().then(() => __toESM(require_src8(), 1));
56816
+ const { OTLPLogExporter } = await Promise.resolve().then(() => __toESM(require_src9(), 1));
56817
+ const { NodeTracerProvider, BatchSpanProcessor } = await Promise.resolve().then(() => __toESM(require_src14(), 1));
56818
+ const { MeterProvider, PeriodicExportingMetricReader } = await Promise.resolve().then(() => __toESM(require_src4(), 1));
56819
+ const { LoggerProvider, BatchLogRecordProcessor } = await Promise.resolve().then(() => __toESM(require_src15(), 1));
56820
+ const { Resource } = await Promise.resolve().then(() => __toESM(require_src3(), 1));
56821
+ const resource = new Resource({
56822
+ "service.name": serviceName,
56823
+ "service.version": serviceVersion,
56824
+ "deployment.environment.name": environment,
56825
+ "parall.runtime_type": runtimeType,
56826
+ "parall.agent_id": process.env.PRLL_AGENT_ID || "",
56827
+ "parall.machine_id": process.env.PRLL_MACHINE_ID || "",
56828
+ "parall.org_id": process.env.PRLL_ORG_ID || "",
56829
+ "parall.daemon_mode": process.env.PRLL_DAEMON_MODE === "1"
56830
+ });
56831
+ const authHeaders = { Authorization: `Bearer ${apiKey}` };
56832
+ const traceExporter = new OTLPTraceExporter({
56833
+ url: `${otelEndpoint}/v1/traces`,
56834
+ headers: authHeaders
56835
+ });
56836
+ const tracerProvider = new NodeTracerProvider({ resource });
56837
+ tracerProvider.addSpanProcessor(new BatchSpanProcessor(traceExporter));
56838
+ tracerProvider.register();
56839
+ const metricExporter = new OTLPMetricExporter({
56840
+ url: `${otelEndpoint}/v1/metrics`,
56841
+ headers: authHeaders
56842
+ });
56843
+ const metricReader = new PeriodicExportingMetricReader({
56844
+ exporter: metricExporter,
56845
+ exportIntervalMillis: 15e3
56846
+ });
56847
+ const meterProvider = new MeterProvider({ resource, readers: [metricReader] });
56848
+ metrics.setGlobalMeterProvider(meterProvider);
56849
+ const logExporter = new OTLPLogExporter({
56850
+ url: `${otelEndpoint}/v1/logs`,
56851
+ headers: authHeaders
56852
+ });
56853
+ const loggerProvider = new LoggerProvider({ resource });
56854
+ loggerProvider.addLogRecordProcessor(new BatchLogRecordProcessor(logExporter));
56855
+ const meter = metrics.getMeter("parall.agent");
56856
+ tracer = trace.getTracer("parall.agent");
56857
+ otelLogger = loggerProvider.getLogger("parall.agent");
56858
+ dispatchCounter = meter.createCounter("parall.dispatch.count", {
56859
+ description: "Number of dispatch cycles completed"
56860
+ });
56861
+ dispatchDuration = meter.createHistogram("parall.dispatch.duration", {
56862
+ description: "Dispatch cycle duration in milliseconds",
56863
+ unit: "ms"
56864
+ });
56865
+ missingReplyCounter = meter.createCounter("parall.dispatch.missing_reply", {
56866
+ description: "Dispatches where agent produced text but sent no reply message"
56867
+ });
56868
+ turnTokensCounter = meter.createCounter("parall.turn.tokens", {
56869
+ description: "LLM tokens consumed per turn, by kind (input/output/cache_read/cache_creation)"
56870
+ });
56871
+ turnCostCounter = meter.createCounter("parall.turn.cost_usd", {
56872
+ description: "LLM cost per turn in USD (when the runtime reports it)"
56873
+ });
56874
+ initialized = true;
56875
+ console.log(`${(/* @__PURE__ */ new Date()).toISOString()} [telemetry] exporting ${serviceName} v${serviceVersion} env=${environment} to ${otelEndpoint}`);
56876
+ shutdownFn = async () => {
56877
+ await tracerProvider.forceFlush();
56878
+ await meterProvider.forceFlush();
56879
+ await loggerProvider.forceFlush();
56880
+ await tracerProvider.shutdown();
56881
+ await meterProvider.shutdown();
56882
+ await loggerProvider.shutdown();
56883
+ };
56884
+ return {
56885
+ shutdown: async () => {
56886
+ if (shutdownFn)
56887
+ await shutdownFn();
56888
+ }
56889
+ };
56345
56890
  } catch (err) {
56346
- host.dispatchedMessages.delete(item.source_id);
56347
- throw err;
56891
+ console.warn(`${(/* @__PURE__ */ new Date()).toISOString()} [telemetry] init failed for ${serviceName}, running without export: ${String(err)}`);
56892
+ return noopHandle;
56348
56893
  }
56349
56894
  }
56895
+ function startDispatchSpan(event, runtimeType, sessionKey) {
56896
+ if (!initialized || !tracer)
56897
+ return null;
56898
+ return tracer.startSpan("parall.dispatch", {
56899
+ attributes: {
56900
+ "dispatch.target_type": resolveTargetType(event.targetId),
56901
+ "dispatch.event_type": event.type,
56902
+ "dispatch.runtime_type": runtimeType,
56903
+ "dispatch.session_key": sessionKey,
56904
+ "dispatch.message_id": event.messageId,
56905
+ "dispatch.target_id": event.targetId
56906
+ }
56907
+ });
56908
+ }
56909
+ function endDispatchSpan(span, metricsSnapshot, error, turnOutcome) {
56910
+ if (!span)
56911
+ return;
56912
+ if (metricsSnapshot) {
56913
+ span.setAttributes({
56914
+ "dispatch.deliver_text_chunks": metricsSnapshot.deliver_text_chunks,
56915
+ "dispatch.deliver_text_chars": metricsSnapshot.deliver_text_chars,
56916
+ "dispatch.message_send_attempts": metricsSnapshot.message_send_attempts,
56917
+ "dispatch.message_send_successes": metricsSnapshot.message_send_successes,
56918
+ "dispatch.no_reply_called": metricsSnapshot.no_reply_called,
56919
+ "dispatch.tool_call_count": metricsSnapshot.tool_call_count,
56920
+ "dispatch.duration_ms": Date.now() - metricsSnapshot.started_at
56921
+ });
56922
+ }
56923
+ if (turnOutcome) {
56924
+ span.setAttribute("dispatch.outcome", turnOutcome.outcome);
56925
+ if (turnOutcome.detail)
56926
+ span.setAttribute("dispatch.outcome_detail", turnOutcome.detail);
56927
+ if (turnOutcome.retryAt)
56928
+ span.setAttribute("dispatch.retry_at", turnOutcome.retryAt);
56929
+ if (turnOutcome.model)
56930
+ span.setAttribute("dispatch.model", turnOutcome.model);
56931
+ if (turnOutcome.raw && Object.keys(turnOutcome.raw).length > 0) {
56932
+ try {
56933
+ span.setAttribute("dispatch.outcome_raw", JSON.stringify(turnOutcome.raw));
56934
+ } catch {
56935
+ }
56936
+ }
56937
+ const u = turnOutcome.usage;
56938
+ if (u) {
56939
+ if (u.inputTokens !== void 0)
56940
+ span.setAttribute("dispatch.tokens_input", u.inputTokens);
56941
+ if (u.outputTokens !== void 0)
56942
+ span.setAttribute("dispatch.tokens_output", u.outputTokens);
56943
+ if (u.cacheReadTokens !== void 0)
56944
+ span.setAttribute("dispatch.tokens_cache_read", u.cacheReadTokens);
56945
+ if (u.cacheCreationTokens !== void 0)
56946
+ span.setAttribute("dispatch.tokens_cache_creation", u.cacheCreationTokens);
56947
+ if (u.costUsd !== void 0)
56948
+ span.setAttribute("dispatch.cost_usd", u.costUsd);
56949
+ if (u.durationApiMs !== void 0)
56950
+ span.setAttribute("dispatch.duration_api_ms", u.durationApiMs);
56951
+ }
56952
+ }
56953
+ if (error) {
56954
+ const safe = redactSecrets(String(error));
56955
+ span.setStatus({ code: SpanStatusCode.ERROR, message: safe });
56956
+ span.recordException(error instanceof Error ? new Error(safe) : new Error(safe));
56957
+ }
56958
+ span.end();
56959
+ }
56960
+ function recordDispatchMetric(event, runtimeType, durationMs, outcome = "ok") {
56961
+ if (!initialized)
56962
+ return;
56963
+ const attrs = {
56964
+ target_type: resolveTargetType(event.targetId),
56965
+ event_type: event.type,
56966
+ runtime_type: runtimeType,
56967
+ outcome
56968
+ };
56969
+ dispatchCounter?.add(1, attrs);
56970
+ dispatchDuration?.record(durationMs, attrs);
56971
+ }
56972
+ function recordMissingReply(runtimeType, outcome = "ok") {
56973
+ if (!initialized)
56974
+ return;
56975
+ missingReplyCounter?.add(1, { runtime_type: runtimeType, outcome });
56976
+ }
56977
+ function recordTurnUsage(usage, runtimeType) {
56978
+ if (!initialized || !usage)
56979
+ return;
56980
+ const kinds = [
56981
+ ["input", usage.inputTokens],
56982
+ ["output", usage.outputTokens],
56983
+ ["cache_read", usage.cacheReadTokens],
56984
+ ["cache_creation", usage.cacheCreationTokens]
56985
+ ];
56986
+ for (const [kind, value] of kinds) {
56987
+ if (value !== void 0 && value > 0) {
56988
+ turnTokensCounter?.add(value, { kind, runtime_type: runtimeType });
56989
+ }
56990
+ }
56991
+ if (usage.costUsd !== void 0 && usage.costUsd > 0) {
56992
+ turnCostCounter?.add(usage.costUsd, { runtime_type: runtimeType });
56993
+ }
56994
+ }
56995
+ var sessionKeyStorage = new AsyncLocalStorage();
56996
+ function runWithSessionKey(sessionKey, fn) {
56997
+ return sessionKeyStorage.run(sessionKey, fn);
56998
+ }
56999
+ function createOtelLogger(layer, prefix) {
57000
+ const ts = () => (/* @__PURE__ */ new Date()).toISOString();
57001
+ const emit = (severity, msg) => {
57002
+ if (!otelLogger)
57003
+ return;
57004
+ const severityNumber = severity === "ERROR" ? import_api_logs.SeverityNumber.ERROR : severity === "WARN" ? import_api_logs.SeverityNumber.WARN : import_api_logs.SeverityNumber.INFO;
57005
+ const attrs = { "log.layer": layer, "log.prefix": prefix };
57006
+ const sk = sessionKeyStorage.getStore();
57007
+ if (sk)
57008
+ attrs["session.key"] = sk;
57009
+ otelLogger.emit({
57010
+ severityNumber,
57011
+ severityText: severity,
57012
+ body: msg,
57013
+ attributes: attrs
57014
+ });
57015
+ };
57016
+ return {
57017
+ info: (msg) => {
57018
+ console.log(`${ts()} [${prefix}] ${msg}`);
57019
+ emit("INFO", msg);
57020
+ },
57021
+ warn: (msg) => {
57022
+ console.warn(`${ts()} [${prefix}] ${msg}`);
57023
+ emit("WARN", msg);
57024
+ },
57025
+ error: (msg) => {
57026
+ console.error(`${ts()} [${prefix}] ${msg}`);
57027
+ emit("ERROR", msg);
57028
+ },
57029
+ child: (sub) => createOtelLogger(layer, `${prefix}:${sub}`)
57030
+ };
57031
+ }
57032
+
57033
+ // ../agent-core/dist/gateway-runtime-turns.js
57034
+ var UNTARGETED_STEP = { target_type: "" };
57035
+ function handleRuntimeActivity(host, event) {
57036
+ const sessionKey = event.kind === "turn" ? event.turn.sessionKey : event.sessionKey;
57037
+ const label = event.kind === "turn" ? `runtime-initiated turn ${event.turn.groupKey} on ${sessionKey}` : `runtime child session close for ${sessionKey}`;
57038
+ const prior = host.runtimeActivityChains.get(sessionKey) ?? Promise.resolve();
57039
+ host.inFlightRuntimeTurns += 1;
57040
+ const next = prior.then(() => event.kind === "turn" ? runRuntimeTurn(host, event.turn) : closeRuntimeChildSession(host, event.sessionKey, event.reason)).catch((err) => {
57041
+ host.opts.log?.warn(`${label} failed: ${String(err)}`);
57042
+ }).finally(() => {
57043
+ if (host.runtimeActivityChains.get(sessionKey) === next) {
57044
+ host.runtimeActivityChains.delete(sessionKey);
57045
+ }
57046
+ host.inFlightRuntimeTurns -= 1;
57047
+ host.notifyDrainWaiters();
57048
+ });
57049
+ host.runtimeActivityChains.set(sessionKey, next);
57050
+ }
57051
+ async function runRuntimeTurn(host, turn) {
57052
+ const { sessionKey, groupKey } = turn;
57053
+ const log = host.opts.log;
57054
+ const startedAtMs = Date.now();
57055
+ const deadline = host.dispatchInactivityDeadlines.start(`${sessionKey}#runtime:${groupKey}`, host.DISPATCH_DEADLINE_MS, () => {
57056
+ log?.warn(`runtime-initiated turn ${groupKey} on ${sessionKey} inactive for ${host.DISPATCH_DEADLINE_MS}ms; detaching`);
57057
+ try {
57058
+ turn.detach("inactivity deadline exceeded");
57059
+ } catch (err) {
57060
+ log?.warn(`detach threw for runtime turn ${groupKey}: ${String(err)}`);
57061
+ }
57062
+ });
57063
+ turn.onActivity(deadline.touch);
57064
+ const contextFilePath = host.opts.contextFilePathForSession?.(sessionKey);
57065
+ let binding = host.sessionBindings.get(sessionKey);
57066
+ let turnHandle;
57067
+ let outcomeEvent;
57068
+ let stepCount = 0;
57069
+ let droppedWithoutBinding = 0;
57070
+ const ensureBegun = async () => {
57071
+ if (!binding || turnHandle)
57072
+ return;
57073
+ turnHandle = await host.sessionLifecycle.beginTurn(binding.agentSessionId);
57074
+ await createRuntimeInputStep(host, binding.agentSessionId, turn);
57075
+ };
57076
+ try {
57077
+ for await (const runtimeEvent of turn.events) {
57078
+ deadline.touch();
57079
+ if (runtimeEvent.type === "runtime_session") {
57080
+ try {
57081
+ binding = await host.bindRuntimeSession(sessionKey, runtimeEvent, contextFilePath);
57082
+ } catch (err) {
57083
+ log?.warn(`runtime-initiated turn ${groupKey}: session binding failed for ${sessionKey}: ${String(err)}`);
57084
+ binding = void 0;
57085
+ }
57086
+ continue;
57087
+ }
57088
+ if (!binding) {
57089
+ droppedWithoutBinding += 1;
57090
+ continue;
57091
+ }
57092
+ if (runtimeEvent.type === "turn_outcome") {
57093
+ const outcome = redactTurnOutcome(runtimeEvent, [host.opts.config.api_key]);
57094
+ outcomeEvent = outcome;
57095
+ if (outcome.outcome === "ok")
57096
+ continue;
57097
+ const failure = describeTurnOutcomeFailure(outcome);
57098
+ log?.warn(`runtime-initiated turn outcome: ${failure.warn}`);
57099
+ await ensureBegun();
57100
+ await host.createRuntimeStep(binding.agentSessionId, UNTARGETED_STEP, { type: "error", message: failure.stepMessage, groupKey }, void 0, contextFilePath);
57101
+ continue;
57102
+ }
57103
+ await ensureBegun();
57104
+ stepCount += 1;
57105
+ await host.createRuntimeStep(binding.agentSessionId, UNTARGETED_STEP, runtimeEvent, void 0, contextFilePath);
57106
+ }
57107
+ } catch (err) {
57108
+ log?.warn(`runtime-initiated turn ${groupKey} on ${sessionKey} failed: ${String(err)}`);
57109
+ if (binding && turnHandle && !host.isSessionNotLiveError(err)) {
57110
+ try {
57111
+ await host.createRuntimeStep(binding.agentSessionId, UNTARGETED_STEP, {
57112
+ type: "error",
57113
+ message: `Runtime turn failed: ${String(err)}`,
57114
+ groupKey
57115
+ });
57116
+ } catch {
57117
+ }
57118
+ }
57119
+ } finally {
57120
+ deadline.dispose();
57121
+ if (turnHandle)
57122
+ host.sessionLifecycle.finishTurn(turnHandle);
57123
+ if (contextFilePath)
57124
+ host.updateContextFileStepId(contextFilePath, null);
57125
+ recordTurnUsage(outcomeEvent?.usage, host.opts.runtimeType);
57126
+ log?.info(`runtime-initiated turn ${groupKey} on ${sessionKey} (${describeRuntimeTurnTrigger(turn.trigger)}): steps=${stepCount} outcome=${outcomeEvent?.outcome ?? "ok"} ${Date.now() - startedAtMs}ms${droppedWithoutBinding > 0 ? ` (no session binding: ${droppedWithoutBinding} event(s) not persisted)` : ""}`);
57127
+ }
57128
+ }
57129
+ async function createRuntimeInputStep(host, sessionId, turn) {
57130
+ const trigger = turn.trigger;
57131
+ const sourceId = trigger.kind === "background_task" ? trigger.taskId : trigger.kind === "subagent" ? trigger.threadId : void 0;
57132
+ const summary = trigger.kind === "background_task" ? trigger.summary ?? trigger.description ?? "Background task finished" : trigger.kind === "subagent" ? `Subagent ${trigger.nickname ?? trigger.threadId}${trigger.role ? ` (${trigger.role})` : ""}` : trigger.reason ?? "Runtime-initiated turn";
57133
+ await host.stepPersister.persist(sessionId, "input", {
57134
+ step_type: "input",
57135
+ target_type: UNTARGETED_STEP.target_type,
57136
+ idempotency_key: `input:rt:${turn.groupKey}`,
57137
+ content: {
57138
+ trigger_type: trigger.kind,
57139
+ trigger_ref: trigger.kind === "background_task" ? { ...trigger.taskId ? { task_id: trigger.taskId } : {} } : trigger.kind === "subagent" ? {
57140
+ thread_id: trigger.threadId,
57141
+ ...trigger.parentThreadId ? { parent_thread_id: trigger.parentThreadId } : {}
57142
+ } : {},
57143
+ source_type: trigger.kind,
57144
+ ...sourceId ? { source_id: sourceId } : {},
57145
+ summary: summary.substring(0, 200),
57146
+ sent_at: turn.startedAt
57147
+ }
57148
+ });
57149
+ }
57150
+ async function closeRuntimeChildSession(host, sessionKey, reason) {
57151
+ if (sessionKey === host.opts.runtimeKey)
57152
+ return;
57153
+ const binding = host.sessionBindings.get(sessionKey);
57154
+ if (!binding)
57155
+ return;
57156
+ host.opts.log?.info(`closing runtime child session ${binding.agentSessionId} (${sessionKey}): ${reason}`);
57157
+ const outcome = await host.forkFinalizer.finalize(binding.agentSessionId, () => {
57158
+ if (host.sessionBindings.get(sessionKey) === binding) {
57159
+ host.sessionBindings.delete(sessionKey);
57160
+ }
57161
+ });
57162
+ if (outcome !== "closed" && outcome !== "stale") {
57163
+ host.opts.log?.warn(`runtime child session ${binding.agentSessionId} close ended ${outcome}`);
57164
+ }
57165
+ }
57166
+
57167
+ // ../agent-core/dist/gateway-drain.js
57168
+ var DrainGate = class {
57169
+ isDrained;
57170
+ waiters = [];
57171
+ constructor(isDrained) {
57172
+ this.isDrained = isDrained;
57173
+ }
57174
+ /** Wake every waiter whose predicate now holds. */
57175
+ notify() {
57176
+ if (this.waiters.length === 0)
57177
+ return;
57178
+ const ready = this.waiters.filter((waiter) => waiter.predicate());
57179
+ if (ready.length === 0)
57180
+ return;
57181
+ this.waiters = this.waiters.filter((waiter) => !ready.includes(waiter));
57182
+ for (const waiter of ready)
57183
+ waiter.resolve();
57184
+ }
57185
+ wait(deadlineMs, predicate = this.isDrained) {
57186
+ if (predicate())
57187
+ return Promise.resolve();
57188
+ return new Promise((resolve3) => {
57189
+ const waiter = { predicate, resolve: () => finish() };
57190
+ const finish = () => {
57191
+ clearTimeout(timer);
57192
+ clearInterval(poll);
57193
+ this.waiters = this.waiters.filter((entry) => entry !== waiter);
57194
+ resolve3();
57195
+ };
57196
+ const timer = setTimeout(finish, deadlineMs);
57197
+ const poll = setInterval(() => {
57198
+ if (predicate())
57199
+ finish();
57200
+ }, 500);
57201
+ poll.unref?.();
57202
+ this.waiters.push(waiter);
57203
+ });
57204
+ }
57205
+ };
57206
+
57207
+ // ../agent-core/dist/gateway-session-binding.js
57208
+ var LIVE_SESSION_STATUSES = /* @__PURE__ */ new Set(["open", "active", "idle"]);
57209
+ async function bindRuntimeSession(host, sessionKey, runtimeEvent, contextFilePath, laneContextFilePath2) {
57210
+ const runtimeLaneKey = runtimeEvent.runtimeLaneKey || sessionKey;
57211
+ const existing = host.sessionBindings.get(sessionKey);
57212
+ if (existing && existing.runtimeLaneKey === runtimeLaneKey && existing.runtimeSessionId === runtimeEvent.runtimeSessionId) {
57213
+ return existing;
57214
+ }
57215
+ const parentSessionId = sessionKey === host.opts.runtimeKey ? void 0 : (runtimeEvent.parentSessionKey ? host.sessionBindings.get(runtimeEvent.parentSessionKey)?.agentSessionId : void 0) ?? host.sessionBindings.get(host.opts.runtimeKey)?.agentSessionId;
57216
+ const runtimeRef = {
57217
+ ...host.opts.runtimeRef ?? {},
57218
+ ...runtimeEvent.runtimeRef ?? {}
57219
+ };
57220
+ const session = await host.opts.client.createAgentSession(host.opts.config.org_id, host.opts.agentUserId, {
57221
+ runtime_type: host.opts.runtimeType,
57222
+ runtime_key: runtimeLaneKey,
57223
+ runtime_lane_key: runtimeLaneKey,
57224
+ runtime_session_id: runtimeEvent.runtimeSessionId,
57225
+ parent_session_id: parentSessionId,
57226
+ runtime_ref: Object.keys(runtimeRef).length > 0 ? runtimeRef : void 0
57227
+ });
57228
+ if (!LIVE_SESSION_STATUSES.has(session.status)) {
57229
+ host.opts.log?.warn?.(`createAgentSession returned terminal session ${session.id} (${session.status}), resetting runtime for ${sessionKey}`);
57230
+ host.sessionBindings.delete(sessionKey);
57231
+ try {
57232
+ await host.opts.onSessionStale?.(sessionKey);
57233
+ } catch (e) {
57234
+ host.opts.log?.warn?.(`onSessionStale failed: ${e}`);
57235
+ }
57236
+ host.opts.log?.info?.(`stale session self-heal complete for ${sessionKey} \u2014 next dispatch will create a fresh session`);
57237
+ throw new Error(`Agent session ${session.id} is terminal (${session.status})`);
57238
+ }
57239
+ const binding = {
57240
+ sessionKey,
57241
+ agentSessionId: session.id,
57242
+ runtimeLaneKey,
57243
+ runtimeSessionId: runtimeEvent.runtimeSessionId,
57244
+ parentSessionId
57245
+ };
57246
+ host.sessionBindings.set(sessionKey, binding);
57247
+ if (sessionKey === host.opts.runtimeKey) {
57248
+ host.activeSessionId = session.id;
57249
+ }
57250
+ if (contextFilePath) {
57251
+ host.updateContextFileSessionId(contextFilePath, session.id);
57252
+ }
57253
+ if (laneContextFilePath2) {
57254
+ host.updateContextFileSessionId(laneContextFilePath2, session.id);
57255
+ }
57256
+ await host.opts.onSessionBinding?.(binding);
57257
+ return binding;
57258
+ }
56350
57259
 
56351
57260
  // ../agent-core/dist/dispatch-inactivity-deadline.js
56352
57261
  var DispatchInactivityDeadline = class {
@@ -56354,6 +57263,7 @@ var DispatchInactivityDeadline = class {
56354
57263
  onExpire;
56355
57264
  onDispose;
56356
57265
  timer = null;
57266
+ lastActivityAt = 0;
56357
57267
  expired = false;
56358
57268
  disposed = false;
56359
57269
  constructor(timeoutMs, onExpire, onDispose) {
@@ -56361,17 +57271,30 @@ var DispatchInactivityDeadline = class {
56361
57271
  this.onExpire = onExpire;
56362
57272
  this.onDispose = onDispose;
56363
57273
  }
57274
+ /**
57275
+ * Called on every runtime frame: records the time only. The single timer
57276
+ * checks the idle span when it fires and re-arms for the remainder, so
57277
+ * touching never allocates.
57278
+ */
56364
57279
  touch = () => {
56365
57280
  if (this.timeoutMs <= 0 || this.expired || this.disposed)
56366
57281
  return;
56367
- if (this.timer)
56368
- clearTimeout(this.timer);
57282
+ this.lastActivityAt = Date.now();
57283
+ if (!this.timer)
57284
+ this.arm(this.timeoutMs);
57285
+ };
57286
+ arm(delayMs) {
56369
57287
  this.timer = setTimeout(() => {
56370
57288
  this.timer = null;
57289
+ const idleMs = Date.now() - this.lastActivityAt;
57290
+ if (idleMs < this.timeoutMs) {
57291
+ this.arm(this.timeoutMs - idleMs);
57292
+ return;
57293
+ }
56371
57294
  this.expired = true;
56372
57295
  this.onExpire();
56373
- }, this.timeoutMs);
56374
- };
57296
+ }, delayMs);
57297
+ }
56375
57298
  dispose() {
56376
57299
  if (this.disposed)
56377
57300
  return;
@@ -56421,28 +57344,6 @@ function routeTrigger(event, state, strategy = defaultRoutingStrategy) {
56421
57344
  return strategy(event, state);
56422
57345
  }
56423
57346
 
56424
- // ../agent-core/dist/redact.js
56425
- function redactSecrets(s, knownValues = []) {
56426
- let out = s;
56427
- for (const v of knownValues) {
56428
- if (typeof v === "string" && v.length >= 6)
56429
- out = out.split(v).join("***");
56430
- }
56431
- return out.replace(/\b(agk|mck|cpk)_[A-Za-z0-9_-]+/g, "$1_***").replace(/\b(sk|pk|rk)-[A-Za-z0-9_-]{8,}/g, "$1-***").replace(/\bAKIA[0-9A-Z]{16}\b/g, "AKIA***").replace(/\b(bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi, "$1***").replace(/[A-Za-z0-9_-]{32,}/g, "***");
56432
- }
56433
- function redactTurnOutcome(event, knownValues) {
56434
- const redacted = { ...event };
56435
- if (redacted.detail)
56436
- redacted.detail = redactSecrets(redacted.detail, knownValues);
56437
- if (redacted.raw) {
56438
- redacted.raw = Object.fromEntries(Object.entries(redacted.raw).map(([k, v]) => [
56439
- k,
56440
- typeof v === "string" ? redactSecrets(v, knownValues) : v
56441
- ]));
56442
- }
56443
- return redacted;
56444
- }
56445
-
56446
57347
  // ../agent-core/dist/step-retry-queue.js
56447
57348
  var DEFAULT_RETRY_DELAYS_MS = [5e3, 1e4, 2e4, 4e4, 6e4];
56448
57349
  async function raceWithDeadline(work, ms) {
@@ -56823,25 +57724,31 @@ var SessionLifecycleCoordinator = class {
56823
57724
  return { sessionId, generation: 0 };
56824
57725
  const entry = this.upsert(sessionId);
56825
57726
  entry.desired = "active";
56826
- entry.triggerMessageId = triggerMessageId;
57727
+ if (triggerMessageId !== void 0 || entry.openTurns.size === 0) {
57728
+ entry.triggerMessageId = triggerMessageId;
57729
+ }
56827
57730
  const generation = entry.generation;
57731
+ entry.openTurns.add(generation);
56828
57732
  const settled = this.waitFor(entry, generation);
56829
57733
  this.pump(sessionId);
56830
57734
  await settled;
56831
57735
  return { sessionId, generation };
56832
57736
  }
56833
57737
  /**
56834
- * Declare the turn finished. A stale handle (a newer turn or a close —
56835
- * has bumped this session's generation) is ignored: finish(turn N) can
56836
- * never override begin(turn N+1). Reconciliation runs detached.
57738
+ * Declare the turn finished. Only the LAST open turn's finish moves the
57739
+ * session to idle; a handle that is not open (already finished, superseded
57740
+ * by a close, or from a reclaimed entry) is ignored. Reconciliation runs
57741
+ * detached.
56837
57742
  */
56838
57743
  finishTurn(handle) {
56839
57744
  if (this.disposed)
56840
57745
  return;
56841
57746
  const entry = this.sessions.get(handle.sessionId);
56842
- if (!entry || entry.dropped || entry.generation !== handle.generation)
57747
+ if (!entry || entry.dropped)
57748
+ return;
57749
+ if (!entry.openTurns.delete(handle.generation))
56843
57750
  return;
56844
- if (entry.desired === "closed")
57751
+ if (entry.desired === "closed" || entry.openTurns.size > 0)
56845
57752
  return;
56846
57753
  entry.desired = "idle";
56847
57754
  entry.retryAttempt = 0;
@@ -56864,6 +57771,7 @@ var SessionLifecycleCoordinator = class {
56864
57771
  const entry = this.upsert(sessionId);
56865
57772
  entry.desired = "closed";
56866
57773
  entry.triggerMessageId = void 0;
57774
+ entry.openTurns.clear();
56867
57775
  const generation = entry.generation;
56868
57776
  const terminal = new Promise((resolve3) => {
56869
57777
  entry.closeWaiters.push({ generation, resolve: resolve3 });
@@ -56883,6 +57791,7 @@ var SessionLifecycleCoordinator = class {
56883
57791
  if (!entry)
56884
57792
  return;
56885
57793
  entry.dropped = true;
57794
+ entry.openTurns.clear();
56886
57795
  this.cancelRetry(entry);
56887
57796
  this.resolveWaiters(entry, Number.POSITIVE_INFINITY, "dropped");
56888
57797
  this.reclaim(sessionId, entry);
@@ -56945,7 +57854,8 @@ var SessionLifecycleCoordinator = class {
56945
57854
  retryAttempt: 0,
56946
57855
  waiters: [],
56947
57856
  closeWaiters: [],
56948
- dropped: false
57857
+ dropped: false,
57858
+ openTurns: /* @__PURE__ */ new Set()
56949
57859
  };
56950
57860
  this.sessions.set(sessionId, entry);
56951
57861
  }
@@ -57293,257 +58203,7 @@ function recordToolCall(sessionKey) {
57293
58203
  m.tool_call_count++;
57294
58204
  }
57295
58205
 
57296
- // ../agent-core/dist/telemetry.js
57297
- init_esm();
57298
- var import_api_logs = __toESM(require_src(), 1);
57299
- import { AsyncLocalStorage } from "node:async_hooks";
57300
- var initialized = false;
57301
- var shutdownFn = null;
57302
- var tracer = null;
57303
- var dispatchCounter = null;
57304
- var dispatchDuration = null;
57305
- var missingReplyCounter = null;
57306
- var turnTokensCounter = null;
57307
- var turnCostCounter = null;
57308
- var otelLogger = null;
57309
- function resolveTargetType(targetId) {
57310
- if (targetId.startsWith("cht_"))
57311
- return "chat";
57312
- if (targetId.startsWith("tsk_"))
57313
- return "task";
57314
- if (targetId.startsWith("sch_"))
57315
- return "schedule";
57316
- return "unknown";
57317
- }
57318
- async function initAgentTelemetry(serviceName, runtimeType) {
57319
- const noopHandle = { shutdown: async () => {
57320
- } };
57321
- const apiUrl = process.env.PRLL_API_URL;
57322
- const apiKey = process.env.PRLL_API_KEY;
57323
- if (!apiUrl || !apiKey) {
57324
- return noopHandle;
57325
- }
57326
- try {
57327
- const otelEndpoint = apiUrl.replace(/\/$/, "") + "/otel";
57328
- const { OTLPTraceExporter } = await Promise.resolve().then(() => __toESM(require_src6(), 1));
57329
- const { OTLPMetricExporter } = await Promise.resolve().then(() => __toESM(require_src8(), 1));
57330
- const { OTLPLogExporter } = await Promise.resolve().then(() => __toESM(require_src9(), 1));
57331
- const { NodeTracerProvider, BatchSpanProcessor } = await Promise.resolve().then(() => __toESM(require_src14(), 1));
57332
- const { MeterProvider, PeriodicExportingMetricReader } = await Promise.resolve().then(() => __toESM(require_src4(), 1));
57333
- const { LoggerProvider, BatchLogRecordProcessor } = await Promise.resolve().then(() => __toESM(require_src15(), 1));
57334
- const { Resource } = await Promise.resolve().then(() => __toESM(require_src3(), 1));
57335
- const resource = new Resource({
57336
- "service.name": serviceName,
57337
- "service.version": process.env.npm_package_version || "unknown",
57338
- "deployment.environment.name": process.env.PRLL_SERVER_ENV || process.env.NODE_ENV || "development",
57339
- "parall.runtime_type": runtimeType,
57340
- "parall.agent_id": process.env.PRLL_AGENT_ID || "",
57341
- "parall.machine_id": process.env.PRLL_MACHINE_ID || "",
57342
- "parall.org_id": process.env.PRLL_ORG_ID || "",
57343
- "parall.daemon_mode": process.env.PRLL_DAEMON_MODE === "1"
57344
- });
57345
- const authHeaders = { Authorization: `Bearer ${apiKey}` };
57346
- const traceExporter = new OTLPTraceExporter({
57347
- url: `${otelEndpoint}/v1/traces`,
57348
- headers: authHeaders
57349
- });
57350
- const tracerProvider = new NodeTracerProvider({ resource });
57351
- tracerProvider.addSpanProcessor(new BatchSpanProcessor(traceExporter));
57352
- tracerProvider.register();
57353
- const metricExporter = new OTLPMetricExporter({
57354
- url: `${otelEndpoint}/v1/metrics`,
57355
- headers: authHeaders
57356
- });
57357
- const metricReader = new PeriodicExportingMetricReader({
57358
- exporter: metricExporter,
57359
- exportIntervalMillis: 15e3
57360
- });
57361
- const meterProvider = new MeterProvider({ resource, readers: [metricReader] });
57362
- metrics.setGlobalMeterProvider(meterProvider);
57363
- const logExporter = new OTLPLogExporter({
57364
- url: `${otelEndpoint}/v1/logs`,
57365
- headers: authHeaders
57366
- });
57367
- const loggerProvider = new LoggerProvider({ resource });
57368
- loggerProvider.addLogRecordProcessor(new BatchLogRecordProcessor(logExporter));
57369
- const meter = metrics.getMeter("parall.agent");
57370
- tracer = trace.getTracer("parall.agent");
57371
- otelLogger = loggerProvider.getLogger("parall.agent");
57372
- dispatchCounter = meter.createCounter("parall.dispatch.count", {
57373
- description: "Number of dispatch cycles completed"
57374
- });
57375
- dispatchDuration = meter.createHistogram("parall.dispatch.duration", {
57376
- description: "Dispatch cycle duration in milliseconds",
57377
- unit: "ms"
57378
- });
57379
- missingReplyCounter = meter.createCounter("parall.dispatch.missing_reply", {
57380
- description: "Dispatches where agent produced text but sent no reply message"
57381
- });
57382
- turnTokensCounter = meter.createCounter("parall.turn.tokens", {
57383
- description: "LLM tokens consumed per turn, by kind (input/output/cache_read/cache_creation)"
57384
- });
57385
- turnCostCounter = meter.createCounter("parall.turn.cost_usd", {
57386
- description: "LLM cost per turn in USD (when the runtime reports it)"
57387
- });
57388
- initialized = true;
57389
- shutdownFn = async () => {
57390
- await tracerProvider.forceFlush();
57391
- await meterProvider.forceFlush();
57392
- await loggerProvider.forceFlush();
57393
- await tracerProvider.shutdown();
57394
- await meterProvider.shutdown();
57395
- await loggerProvider.shutdown();
57396
- };
57397
- return {
57398
- shutdown: async () => {
57399
- if (shutdownFn)
57400
- await shutdownFn();
57401
- }
57402
- };
57403
- } catch {
57404
- return noopHandle;
57405
- }
57406
- }
57407
- function startDispatchSpan(event, runtimeType, sessionKey) {
57408
- if (!initialized || !tracer)
57409
- return null;
57410
- return tracer.startSpan("parall.dispatch", {
57411
- attributes: {
57412
- "dispatch.target_type": resolveTargetType(event.targetId),
57413
- "dispatch.event_type": event.type,
57414
- "dispatch.runtime_type": runtimeType,
57415
- "dispatch.session_key": sessionKey,
57416
- "dispatch.message_id": event.messageId,
57417
- "dispatch.target_id": event.targetId
57418
- }
57419
- });
57420
- }
57421
- function endDispatchSpan(span, metricsSnapshot, error, turnOutcome) {
57422
- if (!span)
57423
- return;
57424
- if (metricsSnapshot) {
57425
- span.setAttributes({
57426
- "dispatch.deliver_text_chunks": metricsSnapshot.deliver_text_chunks,
57427
- "dispatch.deliver_text_chars": metricsSnapshot.deliver_text_chars,
57428
- "dispatch.message_send_attempts": metricsSnapshot.message_send_attempts,
57429
- "dispatch.message_send_successes": metricsSnapshot.message_send_successes,
57430
- "dispatch.no_reply_called": metricsSnapshot.no_reply_called,
57431
- "dispatch.tool_call_count": metricsSnapshot.tool_call_count,
57432
- "dispatch.duration_ms": Date.now() - metricsSnapshot.started_at
57433
- });
57434
- }
57435
- if (turnOutcome) {
57436
- span.setAttribute("dispatch.outcome", turnOutcome.outcome);
57437
- if (turnOutcome.detail)
57438
- span.setAttribute("dispatch.outcome_detail", turnOutcome.detail);
57439
- if (turnOutcome.retryAt)
57440
- span.setAttribute("dispatch.retry_at", turnOutcome.retryAt);
57441
- if (turnOutcome.model)
57442
- span.setAttribute("dispatch.model", turnOutcome.model);
57443
- if (turnOutcome.raw && Object.keys(turnOutcome.raw).length > 0) {
57444
- try {
57445
- span.setAttribute("dispatch.outcome_raw", JSON.stringify(turnOutcome.raw));
57446
- } catch {
57447
- }
57448
- }
57449
- const u = turnOutcome.usage;
57450
- if (u) {
57451
- if (u.inputTokens !== void 0)
57452
- span.setAttribute("dispatch.tokens_input", u.inputTokens);
57453
- if (u.outputTokens !== void 0)
57454
- span.setAttribute("dispatch.tokens_output", u.outputTokens);
57455
- if (u.cacheReadTokens !== void 0)
57456
- span.setAttribute("dispatch.tokens_cache_read", u.cacheReadTokens);
57457
- if (u.cacheCreationTokens !== void 0)
57458
- span.setAttribute("dispatch.tokens_cache_creation", u.cacheCreationTokens);
57459
- if (u.costUsd !== void 0)
57460
- span.setAttribute("dispatch.cost_usd", u.costUsd);
57461
- if (u.durationApiMs !== void 0)
57462
- span.setAttribute("dispatch.duration_api_ms", u.durationApiMs);
57463
- }
57464
- }
57465
- if (error) {
57466
- const safe = redactSecrets(String(error));
57467
- span.setStatus({ code: SpanStatusCode.ERROR, message: safe });
57468
- span.recordException(error instanceof Error ? new Error(safe) : new Error(safe));
57469
- }
57470
- span.end();
57471
- }
57472
- function recordDispatchMetric(event, runtimeType, durationMs, outcome = "ok") {
57473
- if (!initialized)
57474
- return;
57475
- const attrs = {
57476
- target_type: resolveTargetType(event.targetId),
57477
- event_type: event.type,
57478
- runtime_type: runtimeType,
57479
- outcome
57480
- };
57481
- dispatchCounter?.add(1, attrs);
57482
- dispatchDuration?.record(durationMs, attrs);
57483
- }
57484
- function recordMissingReply(runtimeType, outcome = "ok") {
57485
- if (!initialized)
57486
- return;
57487
- missingReplyCounter?.add(1, { runtime_type: runtimeType, outcome });
57488
- }
57489
- function recordTurnUsage(usage, runtimeType) {
57490
- if (!initialized || !usage)
57491
- return;
57492
- const kinds = [
57493
- ["input", usage.inputTokens],
57494
- ["output", usage.outputTokens],
57495
- ["cache_read", usage.cacheReadTokens],
57496
- ["cache_creation", usage.cacheCreationTokens]
57497
- ];
57498
- for (const [kind, value] of kinds) {
57499
- if (value !== void 0 && value > 0) {
57500
- turnTokensCounter?.add(value, { kind, runtime_type: runtimeType });
57501
- }
57502
- }
57503
- if (usage.costUsd !== void 0 && usage.costUsd > 0) {
57504
- turnCostCounter?.add(usage.costUsd, { runtime_type: runtimeType });
57505
- }
57506
- }
57507
- var sessionKeyStorage = new AsyncLocalStorage();
57508
- function runWithSessionKey(sessionKey, fn) {
57509
- return sessionKeyStorage.run(sessionKey, fn);
57510
- }
57511
- function createOtelLogger(layer, prefix) {
57512
- const ts = () => (/* @__PURE__ */ new Date()).toISOString();
57513
- const emit = (severity, msg) => {
57514
- if (!otelLogger)
57515
- return;
57516
- const severityNumber = severity === "ERROR" ? import_api_logs.SeverityNumber.ERROR : severity === "WARN" ? import_api_logs.SeverityNumber.WARN : import_api_logs.SeverityNumber.INFO;
57517
- const attrs = { "log.layer": layer, "log.prefix": prefix };
57518
- const sk = sessionKeyStorage.getStore();
57519
- if (sk)
57520
- attrs["session.key"] = sk;
57521
- otelLogger.emit({
57522
- severityNumber,
57523
- severityText: severity,
57524
- body: msg,
57525
- attributes: attrs
57526
- });
57527
- };
57528
- return {
57529
- info: (msg) => {
57530
- console.log(`${ts()} [${prefix}] ${msg}`);
57531
- emit("INFO", msg);
57532
- },
57533
- warn: (msg) => {
57534
- console.warn(`${ts()} [${prefix}] ${msg}`);
57535
- emit("WARN", msg);
57536
- },
57537
- error: (msg) => {
57538
- console.error(`${ts()} [${prefix}] ${msg}`);
57539
- emit("ERROR", msg);
57540
- },
57541
- child: (sub) => createOtelLogger(layer, `${prefix}:${sub}`)
57542
- };
57543
- }
57544
-
57545
58206
  // ../agent-core/dist/gateway-base.js
57546
- var LIVE_SESSION_STATUSES = /* @__PURE__ */ new Set(["open", "active", "idle"]);
57547
58207
  var TYPED_EVENT_KINDS = {
57548
58208
  task_assign: { type: "task", ackSourceType: "task_activity" },
57549
58209
  task_update: { type: "task", ackSourceType: "task_activity" },
@@ -57685,6 +58345,8 @@ var ParallAgentGateway = class {
57685
58345
  heartbeatTimer = null;
57686
58346
  lastHeartbeatAt = Date.now();
57687
58347
  draining = false;
58348
+ // Idle auto-compact hold on the main lane (gateway-idle-compact.ts).
58349
+ idleCompact = createIdleCompactState();
57688
58350
  /**
57689
58351
  * Typed WorkItem ids whose drain group left the buffer but has not settled
57690
58352
  * yet. isBufferedTypedWorkItem treats them as still buffered — a re-drive
@@ -57698,7 +58360,14 @@ var ParallAgentGateway = class {
57698
58360
  // before tearing down the WS; see handleTermination caller.
57699
58361
  shuttingDown = false;
57700
58362
  inFlightDispatches = 0;
57701
- drainResolvers = [];
58363
+ drainGate = new DrainGate(() => this.isDrained());
58364
+ // Turns the runtime started on its own (RuntimeInitiatedTurn) currently
58365
+ // being persisted — drained by shutdown() alongside dispatches.
58366
+ inFlightRuntimeTurns = 0;
58367
+ // Per-sessionKey serialization of runtime activity: a child session's
58368
+ // close must run after every turn on it finished persisting.
58369
+ runtimeActivityChains = /* @__PURE__ */ new Map();
58370
+ unsubscribeRuntimeActivity;
57702
58371
  pendingRestartNotification = null;
57703
58372
  laneLedger;
57704
58373
  stepPersister;
@@ -57719,7 +58388,7 @@ var ParallAgentGateway = class {
57719
58388
  // for fork routing decisions.
57720
58389
  mainCurrentGroupKey;
57721
58390
  DISPATCHED_MESSAGES_CAP = 5e3;
57722
- // SHUTDOWN_DEADLINE_MS is read by waitForDrain via the configured value
58391
+ // SHUTDOWN_DEADLINE_MS is read by the drain gate wait via the configured value
57723
58392
  // below — kept as instance state so per-runtime configs can override it
57724
58393
  // (see parseShutdownDeadlineMs and runtime entrypoints).
57725
58394
  SHUTDOWN_DEADLINE_MS;
@@ -57740,6 +58409,7 @@ var ParallAgentGateway = class {
57740
58409
  this.SHUTDOWN_DEADLINE_MS = opts.shutdownDeadlineMs ?? 6e4;
57741
58410
  this.FORK_DEADLINE_MS = opts.forkDeadlineMs ?? 2 * 60 * 6e4;
57742
58411
  this.DISPATCH_DEADLINE_MS = opts.dispatchDeadlineMs ?? 20 * 6e4;
58412
+ this.unsubscribeRuntimeActivity = opts.dispatchAdapter.subscribeRuntimeActivity?.((event) => this.handleRuntimeActivity(event));
57743
58413
  this.stepPersister = new StepPersister({
57744
58414
  client: opts.client,
57745
58415
  orgId: opts.config.org_id,
@@ -57801,6 +58471,9 @@ var ParallAgentGateway = class {
57801
58471
  this.opts.log?.warn(`onNewSession callback failed: ${String(err)}`);
57802
58472
  }
57803
58473
  });
58474
+ ws.on("agent.compact", (data) => {
58475
+ void this.handleCompactSignal(data);
58476
+ });
57804
58477
  ws.on("recovery.overflow", () => {
57805
58478
  this.opts.log?.warn(`recovery.overflow \u2014 triggering full catch-up`);
57806
58479
  this.catchUpFromDispatch().catch((err) => this.opts.log?.warn(`overflow catch-up failed: ${String(err)}`));
@@ -57949,7 +58622,7 @@ var ParallAgentGateway = class {
57949
58622
  if (this.usesLaneLedger(event)) {
57950
58623
  return this.laneLedger.laneKeyFor(event);
57951
58624
  }
57952
- return event.type === "message" ? event.targetId : `typed:${event.targetId}`;
58625
+ return isTypedEvent(event) ? `typed:${event.targetId}` : event.targetId;
57953
58626
  }
57954
58627
  // Lane-flow protocols live in gateway-lane-flow.ts; these thin delegates
57955
58628
  // keep call sites and tests on the class surface.
@@ -58041,8 +58714,7 @@ var ParallAgentGateway = class {
58041
58714
  }
58042
58715
  });
58043
58716
  }
58044
- async createRuntimeStep(sessionId, event, runtimeEvent, stepIdFilePath, contextFilePath, laneContextFilePath2) {
58045
- const target = resolveStepTarget(event);
58717
+ async createRuntimeStep(sessionId, target, runtimeEvent, stepIdFilePath, contextFilePath, laneContextFilePath2) {
58046
58718
  switch (runtimeEvent.type) {
58047
58719
  case "thinking":
58048
58720
  await this.stepPersister.persist(sessionId, "thinking", {
@@ -58132,14 +58804,15 @@ var ParallAgentGateway = class {
58132
58804
  target_id: target.target_id,
58133
58805
  idempotency_key: randomUUID(),
58134
58806
  content: buildErrorStepContent(runtimeEvent.message),
58135
- projection: false
58807
+ projection: false,
58808
+ group_key: runtimeEvent.groupKey
58136
58809
  });
58137
58810
  break;
58138
58811
  }
58139
58812
  }
58140
58813
  writeContextFile(filePath, ctx) {
58141
58814
  try {
58142
- fs3.mkdirSync(path3.dirname(filePath), { recursive: true });
58815
+ fs3.mkdirSync(path4.dirname(filePath), { recursive: true });
58143
58816
  fs3.writeFileSync(filePath, JSON.stringify(ctx), "utf8");
58144
58817
  } catch (err) {
58145
58818
  this.opts.log?.warn(`failed to write context file ${filePath}: ${String(err)}`);
@@ -58168,7 +58841,7 @@ var ParallAgentGateway = class {
58168
58841
  /** @deprecated Use writeContextFile / updateContextFileStepId. */
58169
58842
  writeStepIdFile(filePath, stepId) {
58170
58843
  try {
58171
- fs3.mkdirSync(path3.dirname(filePath), { recursive: true });
58844
+ fs3.mkdirSync(path4.dirname(filePath), { recursive: true });
58172
58845
  fs3.writeFileSync(filePath, stepId, "utf8");
58173
58846
  } catch (err) {
58174
58847
  this.opts.log?.warn(`failed to write step id file ${filePath}: ${String(err)}`);
@@ -58186,55 +58859,8 @@ var ParallAgentGateway = class {
58186
58859
  await this.createInputStep(sessionId, event);
58187
58860
  }
58188
58861
  }
58189
- async bindRuntimeSession(sessionKey, runtimeEvent, contextFilePath, laneContextFilePath2) {
58190
- const runtimeLaneKey = runtimeEvent.runtimeLaneKey || sessionKey;
58191
- const existing = this.sessionBindings.get(sessionKey);
58192
- if (existing && existing.runtimeLaneKey === runtimeLaneKey && existing.runtimeSessionId === runtimeEvent.runtimeSessionId) {
58193
- return existing;
58194
- }
58195
- const parentSessionId = sessionKey === this.opts.runtimeKey ? void 0 : this.sessionBindings.get(this.opts.runtimeKey)?.agentSessionId;
58196
- const runtimeRef = {
58197
- ...this.opts.runtimeRef ?? {},
58198
- ...runtimeEvent.runtimeRef ?? {}
58199
- };
58200
- const session = await this.opts.client.createAgentSession(this.opts.config.org_id, this.opts.agentUserId, {
58201
- runtime_type: this.opts.runtimeType,
58202
- runtime_key: runtimeLaneKey,
58203
- runtime_lane_key: runtimeLaneKey,
58204
- runtime_session_id: runtimeEvent.runtimeSessionId,
58205
- parent_session_id: parentSessionId,
58206
- runtime_ref: Object.keys(runtimeRef).length > 0 ? runtimeRef : void 0
58207
- });
58208
- if (!LIVE_SESSION_STATUSES.has(session.status)) {
58209
- this.opts.log?.warn?.(`createAgentSession returned terminal session ${session.id} (${session.status}), resetting runtime for ${sessionKey}`);
58210
- this.sessionBindings.delete(sessionKey);
58211
- try {
58212
- await this.opts.onSessionStale?.(sessionKey);
58213
- } catch (e) {
58214
- this.opts.log?.warn?.(`onSessionStale failed: ${e}`);
58215
- }
58216
- this.opts.log?.info?.(`stale session self-heal complete for ${sessionKey} \u2014 next dispatch will create a fresh session`);
58217
- throw new Error(`Agent session ${session.id} is terminal (${session.status})`);
58218
- }
58219
- const binding = {
58220
- sessionKey,
58221
- agentSessionId: session.id,
58222
- runtimeLaneKey,
58223
- runtimeSessionId: runtimeEvent.runtimeSessionId,
58224
- parentSessionId
58225
- };
58226
- this.sessionBindings.set(sessionKey, binding);
58227
- if (sessionKey === this.opts.runtimeKey) {
58228
- this.activeSessionId = session.id;
58229
- }
58230
- if (contextFilePath) {
58231
- this.updateContextFileSessionId(contextFilePath, session.id);
58232
- }
58233
- if (laneContextFilePath2) {
58234
- this.updateContextFileSessionId(laneContextFilePath2, session.id);
58235
- }
58236
- await this.opts.onSessionBinding?.(binding);
58237
- return binding;
58862
+ bindRuntimeSession(sessionKey, runtimeEvent, contextFilePath, laneContextFilePath2) {
58863
+ return bindRuntimeSession(this, sessionKey, runtimeEvent, contextFilePath, laneContextFilePath2);
58238
58864
  }
58239
58865
  // Returns true if the dispatch actually ran; false if skipped because we
58240
58866
  // are shutting down. Callers MUST treat `false` as "not dispatched" and
@@ -58260,6 +58886,7 @@ var ParallAgentGateway = class {
58260
58886
  const dispatchContext = this.buildDispatchContext(event, sessionKey);
58261
58887
  const contextFilePath = dispatchContext.contextFilePath;
58262
58888
  const stepIdFilePath = dispatchContext.stepIdFilePath;
58889
+ const stepTarget = resolveStepTarget(event);
58263
58890
  const activeLane = this.ledgerDisabled ? void 0 : this.laneLedger?.getForEvent(event);
58264
58891
  const laneContextFilePath2 = activeLane ? this.laneLedger?.laneContextPath(activeLane) : void 0;
58265
58892
  const contextBody = {
@@ -58350,8 +58977,8 @@ var ParallAgentGateway = class {
58350
58977
  outcomeClass: outcomeEvent.outcome,
58351
58978
  ...outcomeEvent.retryAt ? { retryAt: outcomeEvent.retryAt } : {}
58352
58979
  } : { kind: "error", outcomeClass: outcomeEvent.outcome });
58353
- const retryNote = outcomeEvent.retryAt ? `, retry at ${outcomeEvent.retryAt}` : "";
58354
- this.opts.log?.warn(`turn outcome: ${outcomeEvent.outcome}${retryNote}${outcomeEvent.detail ? ` \u2014 ${outcomeEvent.detail}` : ""}`);
58980
+ const failure = describeTurnOutcomeFailure(outcomeEvent);
58981
+ this.opts.log?.warn(`turn outcome: ${failure.warn}`);
58355
58982
  if (binding) {
58356
58983
  await ensureTurnBegun();
58357
58984
  if (!inputStepsCreated) {
@@ -58361,9 +58988,9 @@ var ParallAgentGateway = class {
58361
58988
  await this.createInputStep(binding.agentSessionId, event);
58362
58989
  inputStepsCreated = true;
58363
58990
  }
58364
- await this.createRuntimeStep(binding.agentSessionId, event, {
58991
+ await this.createRuntimeStep(binding.agentSessionId, stepTarget, {
58365
58992
  type: "error",
58366
- message: `LLM turn ${outcomeEvent.outcome}${retryNote}${outcomeEvent.detail ? `: ${outcomeEvent.detail}` : ""}`
58993
+ message: failure.stepMessage
58367
58994
  }, stepIdFilePath, contextFilePath, laneContextFilePath2);
58368
58995
  }
58369
58996
  continue;
@@ -58403,7 +59030,7 @@ var ParallAgentGateway = class {
58403
59030
  sawErrorEvent = true;
58404
59031
  this.recordTurnErrorSignal(sessionKey);
58405
59032
  }
58406
- await this.createRuntimeStep(binding.agentSessionId, event, runtimeEvent, stepIdFilePath, contextFilePath, laneContextFilePath2);
59033
+ await this.createRuntimeStep(binding.agentSessionId, stepTarget, runtimeEvent, stepIdFilePath, contextFilePath, laneContextFilePath2);
58407
59034
  }
58408
59035
  if (!binding) {
58409
59036
  binding = this.sessionBindings.get(sessionKey);
@@ -58424,7 +59051,7 @@ var ParallAgentGateway = class {
58424
59051
  if (!staleDetected && binding) {
58425
59052
  try {
58426
59053
  await ensureTurnBegun();
58427
- await this.createRuntimeStep(binding.agentSessionId, event, {
59054
+ await this.createRuntimeStep(binding.agentSessionId, stepTarget, {
58428
59055
  type: "error",
58429
59056
  message: `Dispatch failed: ${String(err)}`
58430
59057
  }, stepIdFilePath, contextFilePath, laneContextFilePath2);
@@ -58477,15 +59104,14 @@ var ParallAgentGateway = class {
58477
59104
  this.updateContextFileStepId(laneContextFilePath2, null);
58478
59105
  }
58479
59106
  this.inFlightDispatches--;
58480
- if (this.inFlightDispatches === 0 && this.drainResolvers.length > 0) {
58481
- const resolvers = this.drainResolvers.splice(0);
58482
- for (const resolve3 of resolvers)
58483
- resolve3();
58484
- }
59107
+ this.notifyDrainWaiters();
58485
59108
  }
58486
59109
  return true;
58487
59110
  });
58488
59111
  }
59112
+ handleRuntimeActivity(event) {
59113
+ handleRuntimeActivity(this, event);
59114
+ }
58489
59115
  abortFork(targetId, reason) {
58490
59116
  const forkState = this.forkStates.get(targetId);
58491
59117
  if (!forkState)
@@ -58678,11 +59304,23 @@ var ParallAgentGateway = class {
58678
59304
  }
58679
59305
  }
58680
59306
  }
59307
+ /** Server-driven idle auto-compact (gateway-idle-compact.ts); exposed for the test harness. */
59308
+ handleCompactSignal(data) {
59309
+ return handleCompactSignal(this, data);
59310
+ }
59311
+ boundMainSessionId() {
59312
+ return this.sessionBindings.get(this.opts.runtimeKey)?.agentSessionId;
59313
+ }
59314
+ kickMainDrain() {
59315
+ void this.drainMainBuffer();
59316
+ }
58681
59317
  async drainMainBuffer() {
58682
59318
  if (this.draining)
58683
59319
  return;
58684
59320
  this.draining = true;
58685
59321
  try {
59322
+ while (this.idleCompact.inFlight)
59323
+ await this.idleCompact.inFlight;
58686
59324
  while (this.dispatchState.mainBuffer.length > 0) {
58687
59325
  if (this.shuttingDown) {
58688
59326
  this.opts.log?.info(`drainMainBuffer halted (shutting down) \u2014 ${this.dispatchState.mainBuffer.length} buffered, ${this.dispatchState.pendingForkResults.length} pending fork results left for catch-up`);
@@ -58745,7 +59383,7 @@ var ParallAgentGateway = class {
58745
59383
  break;
58746
59384
  }
58747
59385
  }
58748
- const isTypedGroup = events.every((ev) => ev.type !== "message");
59386
+ const isTypedGroup = events.every(isTypedEvent);
58749
59387
  const body = isTypedGroup && events.length > 1 && this.opts.dispatchAdapter.earlierEventsInPrompt !== true ? events.map((ev) => eventBody(ev)).join("\n\n") : eventBody(event);
58750
59388
  let dispatched;
58751
59389
  try {
@@ -58797,7 +59435,10 @@ var ParallAgentGateway = class {
58797
59435
  }
58798
59436
  }
58799
59437
  async handleInboundEvent(event) {
58800
- const disposition = routeTrigger(event, this.dispatchState);
59438
+ let disposition = routeTrigger(event, this.dispatchState);
59439
+ if (this.idleCompact.inFlight && (disposition.action === "main" || disposition.action === "new-fork")) {
59440
+ disposition = { action: "buffer-main" };
59441
+ }
58801
59442
  if (disposition.action === "main") {
58802
59443
  clearForkContinuationRetries(this.forkContinuationRetries, [event]);
58803
59444
  }
@@ -58869,20 +59510,20 @@ var ParallAgentGateway = class {
58869
59510
  return false;
58870
59511
  }
58871
59512
  this.dispatchState.mainBuffer.push(event);
58872
- const typedAheadInBuffer = this.dispatchState.mainBuffer.some((e) => e.type !== "message");
59513
+ const typedAheadInBuffer = this.dispatchState.mainBuffer.some(isTypedEvent);
58873
59514
  if (this.usesLaneLedger(event)) {
58874
- if (!typedAheadInBuffer && this.mainCurrentGroupKey === this.dispatchGroupKey(event) && this.opts.dispatchAdapter.enqueueDuringDispatch != null) {
59515
+ if (!this.idleCompact.inFlight && !typedAheadInBuffer && this.mainCurrentGroupKey === this.dispatchGroupKey(event) && this.opts.dispatchAdapter.enqueueDuringDispatch != null) {
58875
59516
  await steerLaneMessage(this.laneFlowHost(), event);
58876
59517
  }
58877
59518
  } else if (
58878
- // Message events only. A typed event (task_comment/schedule/…)
59519
+ // Lane events only. A typed event (task_comment/schedule/…)
58879
59520
  // rides the typed-consume contract — buffer-main resolves false and
58880
59521
  // the claim releases for re-drive — so an injection here is exactly
58881
59522
  // the forbidden un-folded injection: the LLM sees the content while
58882
59523
  // the WorkItem stays live, and every re-drive injects it AGAIN (the
58883
59524
  // 7/16 watcher duplicate-delivery loop, #1149). Typed events stay
58884
59525
  // buffered; the drain claims them as their own turn.
58885
- event.type === "message" && event.frame != null && !typedAheadInBuffer && this.dispatchState.mainCurrentTargetId === event.targetId && await this.opts.dispatchAdapter.enqueueDuringDispatch?.(this.opts.runtimeKey, eventBody(event))
59526
+ !isTypedEvent(event) && event.frame != null && !this.idleCompact.inFlight && !typedAheadInBuffer && this.dispatchState.mainCurrentTargetId === event.targetId && await this.opts.dispatchAdapter.enqueueDuringDispatch?.(this.opts.runtimeKey, eventBody(event))
58886
59527
  ) {
58887
59528
  this.opts.log?.info(`steer injected for ${event.messageId} (will drain for bookkeeping)`);
58888
59529
  }
@@ -58945,7 +59586,9 @@ var ParallAgentGateway = class {
58945
59586
  }
58946
59587
  /**
58947
59588
  * One WorkItem the server pushed (dispatch.new) or a catch-up page
58948
- * listed: messages ride their (chat, thread) lane; every other family
59589
+ * listed: messages ride their (chat, thread) lane, channel messages the
59590
+ * server routed on a `prll://chv_…` lane ride that conversation lane;
59591
+ * every other family (a channel message without target_uri included)
58949
59592
  * rides its own dsp lane, claimed, run on the server frame, resolved by
58950
59593
  * id. A typed WorkItem whose event copy is already buffered for the
58951
59594
  * drain is left to the drain (re-claiming it would race the drain's
@@ -58958,7 +59601,7 @@ var ParallAgentGateway = class {
58958
59601
  if (item.event_type === "message") {
58959
59602
  if (!item.chat_id || !item.source_id)
58960
59603
  return;
58961
- await this.consumeMessageWorkItem({
59604
+ await consumeMessageWorkItem(this.laneFlowHost(), {
58962
59605
  id: item.id,
58963
59606
  source_id: item.source_id,
58964
59607
  chat_id: item.chat_id,
@@ -58968,6 +59611,11 @@ var ParallAgentGateway = class {
58968
59611
  });
58969
59612
  return;
58970
59613
  }
59614
+ const channelLane = channelLaneTargetUri(item);
59615
+ if (channelLane) {
59616
+ await consumeChannelWorkItem(this.laneFlowHost(), { ...item, target_uri: channelLane });
59617
+ return;
59618
+ }
58971
59619
  if (!TYPED_EVENT_KINDS[item.event_type]) {
58972
59620
  this.opts.log?.info(`dispatch with unhandled event_type=${String(item.event_type)} (id=${item.id}) \u2014 no-op`);
58973
59621
  return;
@@ -58978,9 +59626,6 @@ var ParallAgentGateway = class {
58978
59626
  }
58979
59627
  await this.consumeTypedDispatch({ dispatchEventId: item.id }, (lane) => this.runTypedFrame(item, lane), { legacyAck: () => this.ackDispatchEvent(item.id) });
58980
59628
  }
58981
- consumeMessageWorkItem(item) {
58982
- return consumeMessageWorkItem(this.laneFlowHost(), item);
58983
- }
58984
59629
  /**
58985
59630
  * Run one claimed typed WorkItem on the frame the claim returned. The
58986
59631
  * event is addressing only: the routing target the server named
@@ -59223,33 +59868,33 @@ ${fullSummary}` : fullSummary;
59223
59868
  }
59224
59869
  }
59225
59870
  }
59226
- // Resolves when in-flight dispatches hit 0 or the deadline elapses.
59227
- // Deadline arming the resolver rather than rejecting keeps shutdown() linear
59228
- //callers don't need to try/catch.
59229
- waitForDrain(deadlineMs) {
59230
- if (this.inFlightDispatches === 0)
59231
- return Promise.resolve();
59232
- return new Promise((resolve3) => {
59233
- const timer = setTimeout(() => {
59234
- const idx = this.drainResolvers.indexOf(onDrain);
59235
- if (idx >= 0)
59236
- this.drainResolvers.splice(idx, 1);
59237
- resolve3();
59238
- }, deadlineMs);
59239
- const onDrain = () => {
59240
- clearTimeout(timer);
59241
- resolve3();
59242
- };
59243
- this.drainResolvers.push(onDrain);
59244
- });
59871
+ /**
59872
+ * Nothing in flight: no dispatch, no runtime-initiated turn, and the
59873
+ * runtime itself reports idle (isBusy a turn it is executing that has
59874
+ * not surfaced yet, or a follow-up hold after background work finished).
59875
+ */
59876
+ isDrained() {
59877
+ return this.inFlightDispatches === 0 && this.inFlightRuntimeTurns === 0 && !this.adapterBusy();
59878
+ }
59879
+ adapterBusy() {
59880
+ try {
59881
+ return this.opts.dispatchAdapter.isBusy?.() ?? false;
59882
+ } catch (err) {
59883
+ this.opts.log?.warn(`dispatchAdapter.isBusy threw: ${String(err)}`);
59884
+ return false;
59885
+ }
59886
+ }
59887
+ notifyDrainWaiters() {
59888
+ this.drainGate.notify();
59245
59889
  }
59246
59890
  async shutdown() {
59247
59891
  this.shuttingDown = true;
59248
- if (this.inFlightDispatches > 0) {
59249
- this.opts.log?.info(`draining ${this.inFlightDispatches} in-flight dispatch(es), deadline ${this.SHUTDOWN_DEADLINE_MS}ms`);
59250
- await this.waitForDrain(this.SHUTDOWN_DEADLINE_MS);
59251
- if (this.inFlightDispatches > 0) {
59252
- this.opts.log?.warn(`drain deadline hit; ${this.inFlightDispatches} dispatch(es) still running \u2014 they will be killed by process exit`);
59892
+ this.idleCompact.abort?.();
59893
+ if (!this.isDrained()) {
59894
+ this.opts.log?.info(`draining ${this.inFlightDispatches} in-flight dispatch(es), ${this.inFlightRuntimeTurns} runtime-initiated turn(s), runtime busy=${this.adapterBusy()}, deadline ${this.SHUTDOWN_DEADLINE_MS}ms`);
59895
+ await this.drainGate.wait(this.SHUTDOWN_DEADLINE_MS);
59896
+ if (!this.isDrained()) {
59897
+ this.opts.log?.warn(`drain deadline hit; ${this.inFlightDispatches} dispatch(es), ${this.inFlightRuntimeTurns} runtime-initiated turn(s), runtime busy=${this.adapterBusy()} \u2014 they will be killed by process exit`);
59253
59898
  } else {
59254
59899
  this.opts.log?.info(`drain complete`);
59255
59900
  }
@@ -59261,6 +59906,9 @@ ${fullSummary}` : fullSummary;
59261
59906
  await this.laneLedger.releaseAll();
59262
59907
  }
59263
59908
  await this.opts.onBeforeDisconnect?.();
59909
+ if (this.inFlightRuntimeTurns > 0) {
59910
+ await this.drainGate.wait(5e3, () => this.inFlightRuntimeTurns === 0);
59911
+ }
59264
59912
  if (this.stepPersister.pendingTotal() > 0) {
59265
59913
  const remaining = await this.stepPersister.flush(1e4);
59266
59914
  if (remaining > 0) {
@@ -59274,6 +59922,7 @@ ${fullSummary}` : fullSummary;
59274
59922
  }
59275
59923
  this.sessionLifecycle.dispose();
59276
59924
  this.opts.ws.disconnect();
59925
+ this.unsubscribeRuntimeActivity?.();
59277
59926
  this.opts.log?.info(`disconnected`);
59278
59927
  }
59279
59928
  };
@@ -59349,7 +59998,7 @@ import { execSync } from "node:child_process";
59349
59998
  import { constants } from "node:fs";
59350
59999
  import * as fsSync from "node:fs";
59351
60000
  import * as fs4 from "node:fs/promises";
59352
- import * as path4 from "node:path";
60001
+ import * as path5 from "node:path";
59353
60002
  var DEFAULT_MAX_TOTAL_IMAGE_BYTES = 20 * 1024 * 1024;
59354
60003
  var DEFAULT_ATTACHMENT_CACHE_MAX_BYTES = 512 * 1024 * 1024;
59355
60004
  var DEFAULT_ATTACHMENT_DOWNLOAD_TIMEOUT_MS = 3e4;
@@ -59379,11 +60028,11 @@ async function prepareLocalImageAttachments(event, context2, opts) {
59379
60028
  };
59380
60029
  }
59381
60030
  const rootDir = await ensureAttachmentRootDir(opts.workspaceDir);
59382
- const messageDir = path4.join(rootDir, sanitizePathSegment(event.messageId));
60031
+ const messageDir = path5.join(rootDir, sanitizePathSegment(event.messageId));
59383
60032
  await ensurePathIsNotSymlink(messageDir);
59384
60033
  await fs4.mkdir(messageDir, { recursive: true });
59385
60034
  await ensurePathIsNotSymlink(messageDir);
59386
- const activeMessageDir = path4.resolve(messageDir);
60035
+ const activeMessageDir = path5.resolve(messageDir);
59387
60036
  activeAttachmentDirs.add(activeMessageDir);
59388
60037
  const maintenanceCooldownMs = opts.maintenanceCooldownMs ?? DEFAULT_MAINTENANCE_COOLDOWN_MS;
59389
60038
  const maintenancePromise = scheduleAttachmentMaintenance(rootDir, {
@@ -59400,7 +60049,7 @@ async function prepareLocalImageAttachments(event, context2, opts) {
59400
60049
  const notes = [];
59401
60050
  let downloadedBytes = 0;
59402
60051
  for (const att of imageAttachments) {
59403
- const localPath = path4.join(messageDir, localFileName(att.id, att.fileName, att.mimeType));
60052
+ const localPath = path5.join(messageDir, localFileName(att.id, att.fileName, att.mimeType));
59404
60053
  const downloadTimeoutMs = opts.downloadTimeoutMs ?? DEFAULT_ATTACHMENT_DOWNLOAD_TIMEOUT_MS;
59405
60054
  const fetchFresh = async () => {
59406
60055
  const fileInfo = await withTimeout(context2.client.getFileUrl(att.id), downloadTimeoutMs, `file URL lookup timed out after ${downloadTimeoutMs}ms`);
@@ -59457,7 +60106,7 @@ async function appendPreparedLocalAttachmentRefs(body, event, context2, opts) {
59457
60106
  return { body: appendLocalAttachmentRefs(body, attachments), attachments };
59458
60107
  }
59459
60108
  function pinLocalAttachmentPaths(images) {
59460
- const dirs = new Set(images.map((image) => path4.resolve(path4.dirname(image.localPath))));
60109
+ const dirs = new Set(images.map((image) => path5.resolve(path5.dirname(image.localPath))));
59461
60110
  for (const dir of dirs) {
59462
60111
  activeAttachmentDirs.add(dir);
59463
60112
  }
@@ -59472,7 +60121,7 @@ function pinLocalAttachmentPaths(images) {
59472
60121
  };
59473
60122
  }
59474
60123
  function attachmentRootDir(workspaceDir) {
59475
- return path4.join(path4.resolve(workspaceDir), ".parall", "attachments");
60124
+ return path5.join(path5.resolve(workspaceDir), ".parall", "attachments");
59476
60125
  }
59477
60126
  function ensureLocalAttachmentGitExclude(workingDirectory) {
59478
60127
  try {
@@ -59481,8 +60130,8 @@ function ensureLocalAttachmentGitExclude(workingDirectory) {
59481
60130
  encoding: "utf8",
59482
60131
  stdio: ["ignore", "pipe", "ignore"]
59483
60132
  }).trim();
59484
- const excludePath = path4.isAbsolute(rel) ? rel : path4.join(workingDirectory, rel);
59485
- fsSync.mkdirSync(path4.dirname(excludePath), { recursive: true });
60133
+ const excludePath = path5.isAbsolute(rel) ? rel : path5.join(workingDirectory, rel);
60134
+ fsSync.mkdirSync(path5.dirname(excludePath), { recursive: true });
59486
60135
  const existing = fsSync.existsSync(excludePath) ? fsSync.readFileSync(excludePath, "utf8") : "";
59487
60136
  if (existing.split(/\r?\n/).some((line) => line.trim() === ".parall/"))
59488
60137
  return;
@@ -59518,8 +60167,8 @@ function scheduleAttachmentMaintenance(rootDir, opts) {
59518
60167
  return run;
59519
60168
  }
59520
60169
  async function ensureAttachmentRootDir(workspaceDir) {
59521
- const workspaceRoot = path4.resolve(workspaceDir);
59522
- const parallDir = path4.join(workspaceRoot, ".parall");
60170
+ const workspaceRoot = path5.resolve(workspaceDir);
60171
+ const parallDir = path5.join(workspaceRoot, ".parall");
59523
60172
  const rootDir = attachmentRootDir(workspaceRoot);
59524
60173
  await fs4.mkdir(workspaceRoot, { recursive: true });
59525
60174
  await ensurePathIsNotSymlink(parallDir);
@@ -59548,8 +60197,8 @@ async function ensurePathIsNotSymlink(filePath) {
59548
60197
  }
59549
60198
  }
59550
60199
  function isPathInside(childPath, parentPath) {
59551
- const rel = path4.relative(parentPath, childPath);
59552
- return rel === "" || !!rel && !rel.startsWith("..") && !path4.isAbsolute(rel);
60200
+ const rel = path5.relative(parentPath, childPath);
60201
+ return rel === "" || !!rel && !rel.startsWith("..") && !path5.isAbsolute(rel);
59553
60202
  }
59554
60203
  async function existingUsableFile(filePath, expectedSize, rootDir) {
59555
60204
  try {
@@ -59607,7 +60256,7 @@ async function openLocalFileInsideRoot(filePath, rootDir) {
59607
60256
  }
59608
60257
  }
59609
60258
  async function openLocalTempFileInsideRoot(filePath, rootDir) {
59610
- await localDirectoryStatInsideRoot(path4.dirname(filePath), rootDir);
60259
+ await localDirectoryStatInsideRoot(path5.dirname(filePath), rootDir);
59611
60260
  const file = await fs4.open(filePath, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 384);
59612
60261
  let keepOpen = false;
59613
60262
  try {
@@ -59654,9 +60303,9 @@ async function cleanupOldAttachmentFiles(rootDir, ttlMs, log, preserveDirs) {
59654
60303
  await Promise.all(entries.map(async (entry) => {
59655
60304
  if (!entry.isDirectory())
59656
60305
  return;
59657
- const fullPath = path4.join(rootDir, entry.name);
60306
+ const fullPath = path5.join(rootDir, entry.name);
59658
60307
  try {
59659
- if (preserveDirs?.has(path4.resolve(fullPath)))
60308
+ if (preserveDirs?.has(path5.resolve(fullPath)))
59660
60309
  return;
59661
60310
  const stat = await fs4.lstat(fullPath);
59662
60311
  if (!stat.isDirectory())
@@ -59683,7 +60332,7 @@ async function pruneAttachmentCache(rootDir, maxBytes, log, preserveDirs) {
59683
60332
  for (const entry of entries) {
59684
60333
  if (!entry.isDirectory())
59685
60334
  continue;
59686
- const fullPath = path4.join(rootDir, entry.name);
60335
+ const fullPath = path5.join(rootDir, entry.name);
59687
60336
  try {
59688
60337
  const stat = await fs4.lstat(fullPath);
59689
60338
  if (!stat.isDirectory())
@@ -59701,7 +60350,7 @@ async function pruneAttachmentCache(rootDir, maxBytes, log, preserveDirs) {
59701
60350
  for (const dir of dirs) {
59702
60351
  if (total <= maxBytes)
59703
60352
  break;
59704
- if (preserveDirs?.has(path4.resolve(dir.path)))
60353
+ if (preserveDirs?.has(path5.resolve(dir.path)))
59705
60354
  continue;
59706
60355
  try {
59707
60356
  await fs4.rm(dir.path, { recursive: true, force: true });
@@ -59715,7 +60364,7 @@ async function directorySize(dirPath) {
59715
60364
  let total = 0;
59716
60365
  const entries = await fs4.readdir(dirPath, { withFileTypes: true });
59717
60366
  for (const entry of entries) {
59718
- const fullPath = path4.join(dirPath, entry.name);
60367
+ const fullPath = path5.join(dirPath, entry.name);
59719
60368
  let stat;
59720
60369
  try {
59721
60370
  stat = await fs4.lstat(fullPath);
@@ -59733,10 +60382,10 @@ async function directorySize(dirPath) {
59733
60382
  return total;
59734
60383
  }
59735
60384
  function activeDirsForRoot(rootDir) {
59736
- const root = path4.resolve(rootDir);
60385
+ const root = path5.resolve(rootDir);
59737
60386
  const dirs = /* @__PURE__ */ new Set();
59738
60387
  for (const dir of activeAttachmentDirs) {
59739
- if (dir === root || dir.startsWith(`${root}${path4.sep}`)) {
60388
+ if (dir === root || dir.startsWith(`${root}${path5.sep}`)) {
59740
60389
  dirs.add(dir);
59741
60390
  }
59742
60391
  }
@@ -59833,7 +60482,7 @@ async function writeResponseToFileWithLimit(res, filePath, maxBytes, rootDir) {
59833
60482
  }
59834
60483
  writtenStat = await file.stat();
59835
60484
  await closeFile();
59836
- await localDirectoryStatInsideRoot(path4.dirname(filePath), rootDir);
60485
+ await localDirectoryStatInsideRoot(path5.dirname(filePath), rootDir);
59837
60486
  await assertLocalFileIdentity(tmpPath, rootDir, writtenStat);
59838
60487
  await fs4.rename(tmpPath, filePath);
59839
60488
  completed = true;
@@ -59851,9 +60500,9 @@ async function writeResponseToFileWithLimit(res, filePath, maxBytes, rootDir) {
59851
60500
  }
59852
60501
  }
59853
60502
  function localFileName(attachmentId, fileName, mimeType) {
59854
- const safeName = sanitizePathSegment(path4.basename(fileName || attachmentId));
59855
- const ext = path4.extname(safeName) || extensionForMime(mimeType);
59856
- const stem = path4.basename(safeName, path4.extname(safeName)) || attachmentId;
60503
+ const safeName = sanitizePathSegment(path5.basename(fileName || attachmentId));
60504
+ const ext = path5.extname(safeName) || extensionForMime(mimeType);
60505
+ const stem = path5.basename(safeName, path5.extname(safeName)) || attachmentId;
59857
60506
  return `${sanitizePathSegment(attachmentId)}-${stem}${ext}`;
59858
60507
  }
59859
60508
  function extensionForMime(mimeType) {
@@ -59919,7 +60568,7 @@ function parseContentLength(value) {
59919
60568
  // dist/gateway.js
59920
60569
  import * as crypto2 from "node:crypto";
59921
60570
  import * as os2 from "node:os";
59922
- import * as path8 from "node:path";
60571
+ import * as path9 from "node:path";
59923
60572
 
59924
60573
  // dist/runtime.js
59925
60574
  var runtime = null;
@@ -59978,7 +60627,7 @@ function buildOrchestratorSessionKey(accountId) {
59978
60627
 
59979
60628
  // dist/config-manager.js
59980
60629
  import * as fs5 from "node:fs";
59981
- import * as path5 from "node:path";
60630
+ import * as path6 from "node:path";
59982
60631
  var currentCapabilities = [];
59983
60632
  function getChannelCapabilityFragments() {
59984
60633
  return currentCapabilities.map((c) => c.fragment);
@@ -59993,7 +60642,7 @@ function applyChannelCapabilitySnapshot(stateDir, config, log) {
59993
60642
  }
59994
60643
  var CACHE_FILENAME = "parall-platform-config.json";
59995
60644
  function cachePath(stateDir) {
59996
- return path5.join(stateDir, CACHE_FILENAME);
60645
+ return path6.join(stateDir, CACHE_FILENAME);
59997
60646
  }
59998
60647
  function loadCachedConfig(stateDir) {
59999
60648
  try {
@@ -60011,7 +60660,7 @@ function saveCachedConfig(stateDir, config) {
60011
60660
  };
60012
60661
  const filePath = cachePath(stateDir);
60013
60662
  const tmpPath = `${filePath}.tmp`;
60014
- fs5.mkdirSync(path5.dirname(filePath), { recursive: true });
60663
+ fs5.mkdirSync(path6.dirname(filePath), { recursive: true });
60015
60664
  fs5.writeFileSync(tmpPath, JSON.stringify(cached, null, 2), "utf-8");
60016
60665
  fs5.renameSync(tmpPath, filePath);
60017
60666
  }
@@ -60090,7 +60739,7 @@ function applyToOpenClawConfig(configPath, platformConfig, credentials) {
60090
60739
  agents.defaults = cleanedExisting;
60091
60740
  existing.agents = agents;
60092
60741
  const tmpPath = `${configPath}.tmp`;
60093
- fs5.mkdirSync(path5.dirname(configPath), { recursive: true });
60742
+ fs5.mkdirSync(path6.dirname(configPath), { recursive: true });
60094
60743
  fs5.writeFileSync(tmpPath, JSON.stringify(existing, null, 2), "utf-8");
60095
60744
  fs5.renameSync(tmpPath, configPath);
60096
60745
  }
@@ -60135,7 +60784,7 @@ async function fetchAndApplyPlatformConfig(opts) {
60135
60784
 
60136
60785
  // dist/wiki-helper.js
60137
60786
  import { spawn, spawnSync } from "node:child_process";
60138
- import path6 from "node:path";
60787
+ import path7 from "node:path";
60139
60788
  var DEFAULT_SYNC_TIMEOUT_MS = 9e4;
60140
60789
  var DEFAULT_WATCH_INTERVAL_SEC = 30;
60141
60790
  function isCommandMissing(error) {
@@ -60150,7 +60799,7 @@ function resolveParallCli() {
60150
60799
  return _cli;
60151
60800
  }
60152
60801
  function resolveMountRoot(stateDir) {
60153
- return process.env.PRLL_WIKI_MOUNT_ROOT?.trim() || path6.join(stateDir, "workspace");
60802
+ return process.env.PRLL_WIKI_MOUNT_ROOT?.trim() || path7.join(stateDir, "workspace");
60154
60803
  }
60155
60804
  function resolveWatchIntervalSec() {
60156
60805
  const raw = process.env.PRLL_WIKI_REFRESH_INTERVAL_SEC?.trim();
@@ -60265,8 +60914,8 @@ async function startWikiHelper(params) {
60265
60914
 
60266
60915
  // dist/oc-session.js
60267
60916
  import { randomUUID as randomUUID2 } from "node:crypto";
60268
- import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync5, writeFileSync as writeFileSync4 } from "node:fs";
60269
- import { join as join5, resolve as resolve2 } from "node:path";
60917
+ import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "node:fs";
60918
+ import { join as join6, resolve as resolve2 } from "node:path";
60270
60919
  var CURRENT_SESSION_VERSION = 3;
60271
60920
  function generateId(existing) {
60272
60921
  for (let i = 0; i < 100; i++) {
@@ -60279,7 +60928,7 @@ function generateId(existing) {
60279
60928
  function loadEntries(filePath) {
60280
60929
  if (!existsSync3(filePath))
60281
60930
  return [];
60282
- const lines = readFileSync5(filePath, "utf-8").trim().split("\n");
60931
+ const lines = readFileSync6(filePath, "utf-8").trim().split("\n");
60283
60932
  const entries = [];
60284
60933
  for (const line of lines) {
60285
60934
  if (!line.trim())
@@ -60412,7 +61061,7 @@ var SessionManager = class _SessionManager {
60412
61061
  this.leafId = null;
60413
61062
  this.flushed = false;
60414
61063
  const ts = timestamp.replace(/[:.]/g, "-");
60415
- this.sessionFile = join5(this.sessionDir, `${ts}_${this.sessionId}.jsonl`);
61064
+ this.sessionFile = join6(this.sessionDir, `${ts}_${this.sessionId}.jsonl`);
60416
61065
  }
60417
61066
  buildIndex() {
60418
61067
  this.byId.clear();
@@ -60459,14 +61108,14 @@ var SessionManager = class _SessionManager {
60459
61108
  }
60460
61109
  // -- Branching -------------------------------------------------------------
60461
61110
  getBranch(fromId) {
60462
- const path9 = [];
61111
+ const path10 = [];
60463
61112
  const startId = fromId ?? this.leafId;
60464
61113
  let current = startId ? this.byId.get(startId) : void 0;
60465
61114
  while (current) {
60466
- path9.unshift(current);
61115
+ path10.unshift(current);
60467
61116
  current = current.parentId ? this.byId.get(current.parentId) : void 0;
60468
61117
  }
60469
- return path9;
61118
+ return path10;
60470
61119
  }
60471
61120
  createBranchedSession(leafId) {
60472
61121
  const branch = this.getBranch(leafId);
@@ -60476,7 +61125,7 @@ var SessionManager = class _SessionManager {
60476
61125
  const newId = randomUUID2();
60477
61126
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
60478
61127
  const ts = timestamp.replace(/[:.]/g, "-");
60479
- const newFile = join5(this.sessionDir, `${ts}_${newId}.jsonl`);
61128
+ const newFile = join6(this.sessionDir, `${ts}_${newId}.jsonl`);
60480
61129
  const header = {
60481
61130
  type: "session",
60482
61131
  version: CURRENT_SESSION_VERSION,
@@ -60522,21 +61171,21 @@ var SessionManager = class _SessionManager {
60522
61171
  return newFile;
60523
61172
  }
60524
61173
  // -- Factory ---------------------------------------------------------------
60525
- static open(path9) {
60526
- const entries = loadEntries(path9);
61174
+ static open(path10) {
61175
+ const entries = loadEntries(path10);
60527
61176
  const header = entries.find((e) => e.type === "session");
60528
61177
  const cwd = header?.cwd ?? process.cwd();
60529
- const dir = resolve2(path9, "..");
60530
- return new _SessionManager(cwd, dir, path9);
61178
+ const dir = resolve2(path10, "..");
61179
+ return new _SessionManager(cwd, dir, path10);
60531
61180
  }
60532
61181
  };
60533
61182
 
60534
61183
  // dist/fork.js
60535
61184
  import * as fs6 from "node:fs";
60536
- import * as path7 from "node:path";
61185
+ import * as path8 from "node:path";
60537
61186
  import * as crypto from "node:crypto";
60538
61187
  function readStoreEntry(sessionsDir, sessionKey) {
60539
- const storeFile = path7.join(sessionsDir, "sessions.json");
61188
+ const storeFile = path8.join(sessionsDir, "sessions.json");
60540
61189
  try {
60541
61190
  const store = JSON.parse(fs6.readFileSync(storeFile, "utf-8"));
60542
61191
  return store[sessionKey] ?? store[sessionKey.toLowerCase()] ?? null;
@@ -60545,7 +61194,7 @@ function readStoreEntry(sessionsDir, sessionKey) {
60545
61194
  }
60546
61195
  }
60547
61196
  function writeStoreEntry(sessionsDir, sessionKey, entry) {
60548
- const storeFile = path7.join(sessionsDir, "sessions.json");
61197
+ const storeFile = path8.join(sessionsDir, "sessions.json");
60549
61198
  try {
60550
61199
  let store = {};
60551
61200
  try {
@@ -60560,7 +61209,7 @@ function writeStoreEntry(sessionsDir, sessionKey, entry) {
60560
61209
  }
60561
61210
  }
60562
61211
  function deleteStoreEntry(sessionsDir, sessionKey) {
60563
- const storeFile = path7.join(sessionsDir, "sessions.json");
61212
+ const storeFile = path8.join(sessionsDir, "sessions.json");
60564
61213
  try {
60565
61214
  const store = JSON.parse(fs6.readFileSync(storeFile, "utf-8"));
60566
61215
  delete store[sessionKey];
@@ -60577,17 +61226,17 @@ function resolveTranscriptFile(sessionsDir, sessionKey) {
60577
61226
  if (!entry?.sessionId)
60578
61227
  return null;
60579
61228
  if (entry.sessionFile) {
60580
- const resolved = path7.isAbsolute(entry.sessionFile) ? entry.sessionFile : path7.join(sessionsDir, entry.sessionFile);
61229
+ const resolved = path8.isAbsolute(entry.sessionFile) ? entry.sessionFile : path8.join(sessionsDir, entry.sessionFile);
60581
61230
  if (fs6.existsSync(resolved))
60582
61231
  return resolved;
60583
61232
  }
60584
- const conventional = path7.join(sessionsDir, `${entry.sessionId}.jsonl`);
61233
+ const conventional = path8.join(sessionsDir, `${entry.sessionId}.jsonl`);
60585
61234
  if (fs6.existsSync(conventional))
60586
61235
  return conventional;
60587
61236
  try {
60588
61237
  const files = fs6.readdirSync(sessionsDir);
60589
61238
  const match = files.find((file) => file.includes(entry.sessionId) && file.endsWith(".jsonl"));
60590
- return match ? path7.join(sessionsDir, match) : null;
61239
+ return match ? path8.join(sessionsDir, match) : null;
60591
61240
  } catch {
60592
61241
  return null;
60593
61242
  }
@@ -60618,7 +61267,7 @@ function forkOrchestratorSession(opts) {
60618
61267
  sessionId = crypto.randomUUID();
60619
61268
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
60620
61269
  const fileTimestamp = timestamp.replace(/[:.]/g, "-");
60621
- sessionFile = path7.join(manager.getSessionDir(), `${fileTimestamp}_${sessionId}.jsonl`);
61270
+ sessionFile = path8.join(manager.getSessionDir(), `${fileTimestamp}_${sessionId}.jsonl`);
60622
61271
  const header = {
60623
61272
  type: "session",
60624
61273
  version: CURRENT_SESSION_VERSION,
@@ -60637,7 +61286,7 @@ function forkOrchestratorSession(opts) {
60637
61286
  const forkSessionKey = `${orchestratorSessionKey}:fork:${sessionId}`;
60638
61287
  const wrote = writeStoreEntry(sessionsDir, forkSessionKey, {
60639
61288
  sessionId,
60640
- sessionFile: path7.relative(sessionsDir, sessionFile),
61289
+ sessionFile: path8.relative(sessionsDir, sessionFile),
60641
61290
  updatedAt: Date.now(),
60642
61291
  spawnedBy: orchestratorSessionKey,
60643
61292
  parentSessionKey: orchestratorSessionKey,
@@ -60663,7 +61312,7 @@ function cleanupForkSession(opts) {
60663
61312
  // dist/gateway.js
60664
61313
  function sessionContextFilePath(stateDir, sessionKey) {
60665
61314
  const fileName = Buffer.from(sessionKey).toString("base64url");
60666
- return path8.join(stateDir, "dispatch-context", `${fileName}.json`);
61315
+ return path9.join(stateDir, "dispatch-context", `${fileName}.json`);
60667
61316
  }
60668
61317
  function resolveWsUrl(account) {
60669
61318
  if (account.config.ws_url)
@@ -60967,15 +61616,19 @@ var parallGateway = {
60967
61616
  const agentUserId = me.id;
60968
61617
  setAgentIdentity(identityFromMe(me));
60969
61618
  log?.info(`parall[${ctx.accountId}]: authenticated as ${me.display_name} (${agentUserId})`);
60970
- const telemetry = await initAgentTelemetry("parall-openclaw-agent", "openclaw");
61619
+ const telemetry = await initAgentTelemetry("parall-openclaw-agent", "openclaw", {
61620
+ apiUrl: process.env.PRLL_API_URL,
61621
+ apiKey: process.env.PRLL_API_KEY,
61622
+ serviceVersion: resolveServiceVersion(import.meta.url)
61623
+ });
60971
61624
  const otelLog = createOtelLogger("agent", "openclaw-agent");
60972
61625
  try {
60973
- const stateDir = process.env.OPENCLAW_STATE_DIR || path8.join(process.env.HOME || "/data", ".openclaw");
60974
- const openclawConfigPath = path8.join(stateDir, "openclaw.json");
61626
+ const stateDir = process.env.OPENCLAW_STATE_DIR || path9.join(process.env.HOME || "/data", ".openclaw");
61627
+ const openclawConfigPath = path9.join(stateDir, "openclaw.json");
60975
61628
  const shimDir = capabilityBinDir(stateDir);
60976
61629
  const currentPath = process.env.PATH ?? "";
60977
- if (!currentPath.split(path8.delimiter).includes(shimDir)) {
60978
- process.env.PATH = currentPath ? `${shimDir}${path8.delimiter}${currentPath}` : shimDir;
61630
+ if (!currentPath.split(path9.delimiter).includes(shimDir)) {
61631
+ process.env.PATH = currentPath ? `${shimDir}${path9.delimiter}${currentPath}` : shimDir;
60979
61632
  }
60980
61633
  const configManagerOpts = {
60981
61634
  client,
@@ -61012,7 +61665,7 @@ var parallGateway = {
61012
61665
  wsUrl
61013
61666
  });
61014
61667
  const orchestratorKey = buildOrchestratorSessionKey(ctx.accountId);
61015
- const sessionsDir = path8.join(stateDir, "agents", "main", "sessions");
61668
+ const sessionsDir = path9.join(stateDir, "agents", "main", "sessions");
61016
61669
  const workspaceDir = process.cwd();
61017
61670
  ensureLocalAttachmentGitExclude(workspaceDir);
61018
61671
  const dispatchAdapter = createOpenClawDispatchAdapter({