@alas-ide/codex-acp 2.2.2-alas.2 → 2.2.2-alas.3

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.
Files changed (2) hide show
  1. package/dist/index.js +67 -26
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -34392,7 +34392,7 @@ var package_default = {
34392
34392
  publishConfig: {
34393
34393
  access: "public"
34394
34394
  },
34395
- version: "2.2.2-alas.2",
34395
+ version: "2.2.2-alas.3",
34396
34396
  description: "",
34397
34397
  main: "dist/index.js",
34398
34398
  bin: {
@@ -34469,7 +34469,7 @@ var package_default = {
34469
34469
  alasDownstream: {
34470
34470
  upstreamVersion: "2.2.2",
34471
34471
  upstreamCommit: "202e66e63343ec4f5a5e35ab590251d813d129ca",
34472
- sourceCommit: "f431e5cac0d2972bcb8295f8967d6f27f6633eea"
34472
+ sourceCommit: "2be0ccf63ad9c18131815207511597bb34d6adc0"
34473
34473
  }
34474
34474
  };
34475
34475
 
@@ -40217,9 +40217,6 @@ function titleSource(text) {
40217
40217
  return text.slice(0, end);
40218
40218
  }
40219
40219
 
40220
- // src/SessionIndexService.ts
40221
- import path13 from "node:path";
40222
-
40223
40220
  // src/SessionIndex.ts
40224
40221
  var AIR_SESSION_INDEX_KEY = "sessionIndex";
40225
40222
  var AIR_SESSION_ARCHIVE_KEY = "sessionArchive";
@@ -40240,6 +40237,32 @@ var AIR_FORKED_FROM_KEY = "forkedFrom";
40240
40237
  var DEFAULT_SESSION_INDEX_LIMIT = 50;
40241
40238
  var MAX_SESSION_INDEX_LIMIT = 100;
40242
40239
  var AIR_ARCHIVED_KEY = "archived";
40240
+ var NEUTRAL_SESSION_INDEX_META_KEY = "sessionIndex";
40241
+ var NEUTRAL_SESSION_INDEX_VERSION = 1;
40242
+ var AIR_SESSION_INDEX_META = {
40243
+ read: (meta3) => asRecord3(asRecord3(asRecord3(meta3)[JETBRAINS_META_KEY])[AIR_META_KEY]),
40244
+ write: withAirMeta
40245
+ };
40246
+ var NEUTRAL_SESSION_INDEX_META = {
40247
+ read: (meta3) => asRecord3(asRecord3(meta3)[NEUTRAL_SESSION_INDEX_META_KEY]),
40248
+ write: (meta3, key, value) => {
40249
+ const root = asRecord3(meta3);
40250
+ return { ...root, [NEUTRAL_SESSION_INDEX_META_KEY]: { ...asRecord3(root[NEUTRAL_SESSION_INDEX_META_KEY]), [key]: value } };
40251
+ }
40252
+ };
40253
+ function sessionIndexMetaOf(capabilities) {
40254
+ if (isAirClient(capabilities)) {
40255
+ return clientSupportsAirCapability(capabilities, AIR_SESSION_INDEX_KEY) ? AIR_SESSION_INDEX_META : null;
40256
+ }
40257
+ const declared = capabilities?._meta?.[NEUTRAL_SESSION_INDEX_META_KEY];
40258
+ if (declared === null || typeof declared !== "object" || Array.isArray(declared)) return null;
40259
+ const version2 = declared["version"];
40260
+ return typeof version2 === "number" && Number.isInteger(version2) && version2 >= 1 ? NEUTRAL_SESSION_INDEX_META : null;
40261
+ }
40262
+ function sessionIndexRowFields(row) {
40263
+ const air = AIR_SESSION_INDEX_META.read(row._meta);
40264
+ return Object.keys(air).length > 0 ? air : NEUTRAL_SESSION_INDEX_META.read(row._meta);
40265
+ }
40243
40266
  var ARCHIVED_FILTERS = ["unarchived", "archived", "all"];
40244
40267
  function archivedSides(filter) {
40245
40268
  switch (filter) {
@@ -40265,9 +40288,8 @@ var sessionListSubscriptionParamsParser = external_exports.preprocess(
40265
40288
  (params) => params ?? {},
40266
40289
  external_exports.record(external_exports.string(), external_exports.unknown())
40267
40290
  );
40268
- function readSessionIndexListOptions(meta3) {
40269
- const jetbrains = asRecord3(asRecord3(meta3)[JETBRAINS_META_KEY]);
40270
- const list = asRecord3(asRecord3(jetbrains[AIR_META_KEY])[AIR_SESSION_LIST_KEY]);
40291
+ function readSessionIndexListOptions(meta3, namespace = AIR_SESSION_INDEX_META) {
40292
+ const list = asRecord3(namespace.read(meta3)[AIR_SESSION_LIST_KEY]);
40271
40293
  return {
40272
40294
  limit: readLimit(list["limit"]),
40273
40295
  archived: readArchivedFilter(list["archived"]),
@@ -40453,7 +40475,7 @@ function decodeAdapterCursor(cursor) {
40453
40475
  function invalidCursorError(cursor) {
40454
40476
  return RequestError.invalidParams({ cursor }, "invalid cursor");
40455
40477
  }
40456
- function sessionIndexSessionInfo(thread, archived, activity) {
40478
+ function sessionIndexSessionInfo(thread, archived, activity, namespace = AIR_SESSION_INDEX_META) {
40457
40479
  const airFields = { [AIR_ARCHIVED_KEY]: archived };
40458
40480
  if (thread.recencyAt !== null) airFields[AIR_LAST_PROMPT_AT_KEY] = isoTime(thread.recencyAt);
40459
40481
  if (thread.model) airFields[AIR_MODEL_KEY] = thread.model;
@@ -40462,7 +40484,7 @@ function sessionIndexSessionInfo(thread, archived, activity) {
40462
40484
  if (activity?.lastTurnEndedAt !== void 0) airFields[AIR_LAST_TURN_ENDED_AT_KEY] = activity.lastTurnEndedAt;
40463
40485
  let meta3;
40464
40486
  for (const [key, value] of Object.entries(airFields)) {
40465
- meta3 = withAirMeta(meta3, key, value);
40487
+ meta3 = namespace.write(meta3, key, value);
40466
40488
  }
40467
40489
  return {
40468
40490
  sessionId: thread.id,
@@ -40550,7 +40572,7 @@ var SessionIndexActivity = class {
40550
40572
  }
40551
40573
  };
40552
40574
  function sessionIndexRowSignature(row) {
40553
- const air = asRecord3(asRecord3(asRecord3(row._meta)[JETBRAINS_META_KEY])[AIR_META_KEY]);
40575
+ const air = sessionIndexRowFields(row);
40554
40576
  return JSON.stringify([
40555
40577
  row.title ?? null,
40556
40578
  air[AIR_LAST_PROMPT_AT_KEY] ?? null,
@@ -40565,6 +40587,9 @@ function asRecord3(value) {
40565
40587
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
40566
40588
  }
40567
40589
 
40590
+ // src/SessionIndexService.ts
40591
+ import path13 from "node:path";
40592
+
40568
40593
  // src/SessionIndexWorktrees.ts
40569
40594
  import fs8 from "node:fs";
40570
40595
  import path9 from "node:path";
@@ -41292,10 +41317,7 @@ var SessionListSubscriptions = class {
41292
41317
  refreshLoadedThreads(threadIds) {
41293
41318
  this.appServerGeneration++;
41294
41319
  if (this.subscriptions.size === 0) return;
41295
- const loaded = [...this.groups.values()].flatMap((group) => [...group.rows].filter(([, { row }]) => {
41296
- const meta3 = row._meta;
41297
- return meta3?.["jetbrains"]?.["air"]?.["state"] !== void 0;
41298
- }).map(([threadId]) => threadId));
41320
+ const loaded = [...this.groups.values()].flatMap((group) => [...group.rows].filter(([, { row }]) => sessionIndexRowFields(row)[AIR_STATE_KEY] !== void 0).map(([threadId]) => threadId));
41299
41321
  for (const threadId of /* @__PURE__ */ new Set([...threadIds, ...loaded])) this.threadChanged(threadId);
41300
41322
  if (this.pendingThreads.size > 0) this.requestThreads(this.timings.ownChangeDelayMs);
41301
41323
  }
@@ -41771,8 +41793,8 @@ var SessionIndexService = class {
41771
41793
  });
41772
41794
  }
41773
41795
  host;
41774
- /** The client declared the AIR `sessionIndex` capability. */
41775
- enabled = false;
41796
+ /** Where this client's session index metadata goes, or `null` when it did not declare `sessionIndex`. */
41797
+ meta = null;
41776
41798
  activity;
41777
41799
  writes = new SessionWriteQueue();
41778
41800
  titles;
@@ -41785,14 +41807,25 @@ var SessionIndexService = class {
41785
41807
  rowsWithState = /* @__PURE__ */ new Set();
41786
41808
  /** Reads the client capabilities of `initialize`. */
41787
41809
  configure(clientCapabilities) {
41788
- this.enabled = clientSupportsAirCapability(clientCapabilities, AIR_SESSION_INDEX_KEY);
41810
+ this.meta = sessionIndexMetaOf(clientCapabilities);
41811
+ }
41812
+ /** The client declared `sessionIndex`, as AIR or as a client-neutral opt-in. */
41813
+ get enabled() {
41814
+ return this.meta !== null;
41789
41815
  }
41790
41816
  /**
41791
- * The AIR capabilities to answer: only a client that declares `sessionIndex` gets them. `sessionArchive` and
41792
- * `sessionRename` name the requests that come with it; the client need not declare them.
41817
+ * The AIR capabilities to answer: only an AIR client that declares `sessionIndex` gets them. `sessionArchive`
41818
+ * and `sessionRename` name the requests that come with it; the client need not declare them.
41793
41819
  */
41794
41820
  agentCapabilities() {
41795
- return this.enabled ? [AIR_SESSION_INDEX_KEY, AIR_SESSION_ARCHIVE_KEY, AIR_SESSION_RENAME_KEY, AIR_SESSION_LIST_SUBSCRIBE_KEY] : [];
41821
+ return this.meta === AIR_SESSION_INDEX_META ? [AIR_SESSION_INDEX_KEY, AIR_SESSION_ARCHIVE_KEY, AIR_SESSION_RENAME_KEY, AIR_SESSION_LIST_SUBSCRIBE_KEY] : [];
41822
+ }
41823
+ /** The `_meta.sessionIndex` answer of `initialize` to a client-neutral opt-in, or `null`. */
41824
+ neutralCapability() {
41825
+ return this.meta === NEUTRAL_SESSION_INDEX_META ? {
41826
+ version: NEUTRAL_SESSION_INDEX_VERSION,
41827
+ capabilities: [AIR_SESSION_ARCHIVE_KEY, AIR_SESSION_RENAME_KEY, AIR_SESSION_LIST_SUBSCRIBE_KEY]
41828
+ } : null;
41796
41829
  }
41797
41830
  /**
41798
41831
  * Feeds the thread notifications of an app-server, for every thread, to the session index. Each client is
@@ -41826,7 +41859,7 @@ var SessionIndexService = class {
41826
41859
  * reads the local state DB and works without one.
41827
41860
  */
41828
41861
  async list(params) {
41829
- const options = readSessionIndexListOptions(params._meta);
41862
+ const options = readSessionIndexListOptions(params._meta, this.requireMeta());
41830
41863
  const cwd = params.cwd?.trim() || null;
41831
41864
  return await this.readRows(cwd, options, params.cursor ?? null);
41832
41865
  }
@@ -41901,13 +41934,13 @@ var SessionIndexService = class {
41901
41934
  if (archived ? open3 : this.host.session(sessionId) !== void 0) {
41902
41935
  await new ACPSessionConnection(this.host.connection(), sessionId).update({
41903
41936
  sessionUpdate: "session_info_update",
41904
- _meta: withAirMeta(void 0, AIR_ARCHIVED_KEY, archived)
41937
+ _meta: this.requireMeta().write(void 0, AIR_ARCHIVED_KEY, archived)
41905
41938
  });
41906
41939
  }
41907
41940
  return {};
41908
41941
  }
41909
41942
  /**
41910
- * Deletes the thread for `session/delete`: AIR then means "delete", not "done", because it has
41943
+ * Deletes the thread for `session/delete`: a `sessionIndex` client then means "delete", not "done", because it has
41911
41944
  * `_session/archive` for that. A thread that this connection had open but Codex never persisted (no
41912
41945
  * prompt yet) is gone with the close, so it counts as deleted.
41913
41946
  */
@@ -41939,6 +41972,10 @@ var SessionIndexService = class {
41939
41972
  throw RequestError.methodNotFound(method);
41940
41973
  }
41941
41974
  }
41975
+ requireMeta() {
41976
+ if (this.meta === null) throw new Error("The client did not declare sessionIndex");
41977
+ return this.meta;
41978
+ }
41942
41979
  async readRows(cwd, options, cursor) {
41943
41980
  const relativeCwd = cwd !== null && !isAbsolutePathLike(cwd) ? cwd : null;
41944
41981
  const cwds = cwd === null || relativeCwd !== null ? null : options.includeWorktrees ? linkedWorktreeCwds(cwd) : canonicalCwds(cwd);
@@ -41964,7 +42001,7 @@ var SessionIndexService = class {
41964
42001
  if (activity?.state !== void 0) this.rowsWithState.add(thread.id);
41965
42002
  else this.rowsWithState.delete(thread.id);
41966
42003
  return this.withActiveAdditionalDirectories(
41967
- sessionIndexSessionInfo(thread, entry.archived, activity)
42004
+ sessionIndexSessionInfo(thread, entry.archived, activity, this.requireMeta())
41968
42005
  );
41969
42006
  });
41970
42007
  }
@@ -42449,7 +42486,7 @@ var CodexAcpServer = class {
42449
42486
  recovery;
42450
42487
  initializeRequest = null;
42451
42488
  providerUpdate = null;
42452
- /** The AIR `sessionIndex` extension, see `SessionIndexService.ts`. */
42489
+ /** The `sessionIndex` extension, for AIR or a client-neutral opt-in, see `SessionIndexService.ts`. */
42453
42490
  sessionIndex = new SessionIndexService({
42454
42491
  connection: () => this.connection,
42455
42492
  client: () => this.codexAcpClient,
@@ -42533,6 +42570,7 @@ var CodexAcpServer = class {
42533
42570
  controlMethod: GOAL_CONTROL_METHOD,
42534
42571
  actions: [...GOAL_CONTROL_ACTIONS]
42535
42572
  };
42573
+ const neutralSessionIndex = this.sessionIndex.neutralCapability();
42536
42574
  const sessionCapabilities = {
42537
42575
  resume: {},
42538
42576
  list: {},
@@ -42583,6 +42621,9 @@ var CodexAcpServer = class {
42583
42621
  ...this.capabilities.asyncTasks && !this.capabilities.airClient ? {
42584
42622
  "async-tasks": asyncTaskCapability()
42585
42623
  } : {},
42624
+ ...neutralSessionIndex ? {
42625
+ [NEUTRAL_SESSION_INDEX_META_KEY]: neutralSessionIndex
42626
+ } : {},
42586
42627
  // Only AIR gets the AIR extension, see `docs/air-extensions.md`.
42587
42628
  ...this.capabilities.airClient ? {
42588
42629
  [JETBRAINS_META_KEY]: {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "2.2.2-alas.2",
6
+ "version": "2.2.2-alas.3",
7
7
  "description": "",
8
8
  "main": "dist/index.js",
9
9
  "bin": {
@@ -80,6 +80,6 @@
80
80
  "alasDownstream": {
81
81
  "upstreamVersion": "2.2.2",
82
82
  "upstreamCommit": "202e66e63343ec4f5a5e35ab590251d813d129ca",
83
- "sourceCommit": "f431e5cac0d2972bcb8295f8967d6f27f6633eea"
83
+ "sourceCommit": "2be0ccf63ad9c18131815207511597bb34d6adc0"
84
84
  }
85
85
  }