@gajae-code/coding-agent 0.22.2 → 0.22.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 (122) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/dist/types/cli/append-system-prompt.d.ts +7 -0
  3. package/dist/types/cli/doctor/session-owners.d.ts +8 -2
  4. package/dist/types/cli/public-command-errors.d.ts +1 -0
  5. package/dist/types/cli/session-picker.d.ts +16 -3
  6. package/dist/types/cli/update-cli.d.ts +0 -2
  7. package/dist/types/cli-ordinary.d.ts +1 -1
  8. package/dist/types/commands/sdk.d.ts +2 -0
  9. package/dist/types/config/machine-identity.d.ts +11 -0
  10. package/dist/types/config/model-registry.d.ts +9 -0
  11. package/dist/types/config/settings-schema.d.ts +84 -4
  12. package/dist/types/lsp/client.d.ts +9 -0
  13. package/dist/types/lsp/types.d.ts +2 -0
  14. package/dist/types/main.d.ts +40 -3
  15. package/dist/types/modes/components/session-held-warning.d.ts +27 -0
  16. package/dist/types/modes/components/session-selector.d.ts +32 -1
  17. package/dist/types/modes/controllers/selector-controller.d.ts +8 -1
  18. package/dist/types/modes/interactive-mode.d.ts +12 -1
  19. package/dist/types/sdk/broker/broker.d.ts +3 -0
  20. package/dist/types/sdk/broker/lifecycle-ledger.d.ts +5 -2
  21. package/dist/types/sdk/broker/lifecycle.d.ts +2 -0
  22. package/dist/types/sdk/broker/session-index.d.ts +11 -0
  23. package/dist/types/sdk/bus/index.d.ts +1 -1
  24. package/dist/types/sdk/host/control/dispatch.d.ts +3 -0
  25. package/dist/types/sdk/host/registration-test-hold.d.ts +7 -0
  26. package/dist/types/sdk/index.d.ts +1 -0
  27. package/dist/types/sdk/lifecycle/service.d.ts +3 -0
  28. package/dist/types/sdk/session-api-key.d.ts +11 -4
  29. package/dist/types/sdk/session-readonly/format.d.ts +7 -0
  30. package/dist/types/sdk/session.d.ts +11 -0
  31. package/dist/types/sdk/startup-capability.d.ts +11 -2
  32. package/dist/types/session/agent-session.d.ts +1 -2
  33. package/dist/types/session/internal/managed-session-storage.d.ts +1 -1
  34. package/dist/types/session/internal/session-claim-set.d.ts +168 -13
  35. package/dist/types/session/session-handover.d.ts +62 -0
  36. package/dist/types/session/session-manager.d.ts +75 -15
  37. package/dist/types/session/session-owner-holder.d.ts +77 -0
  38. package/dist/types/session/session-ownership-mode.d.ts +45 -2
  39. package/dist/types/session/session-ownership.d.ts +25 -29
  40. package/dist/types/session/yield-queue.d.ts +13 -0
  41. package/dist/types/tools/bash.d.ts +7 -0
  42. package/dist/types/tools/browser/deferred-profile-cleanup.d.ts +3 -0
  43. package/dist/types/tools/browser/launch.d.ts +24 -1
  44. package/dist/types/tools/index.d.ts +6 -0
  45. package/dist/types/tools/output-meta.d.ts +17 -11
  46. package/dist/types/tools/tool-result.d.ts +1 -0
  47. package/package.json +9 -7
  48. package/scripts/compile-args.ts +6 -3
  49. package/scripts/run-acp-conformance.ts +36 -10
  50. package/scripts/verify-gjc-sdk-canonicalization.ts +2 -0
  51. package/src/cli/append-system-prompt.ts +34 -0
  52. package/src/cli/auth-broker-cli.ts +5 -1
  53. package/src/cli/doctor/session-owners.ts +8 -2
  54. package/src/cli/public-command-errors.ts +4 -0
  55. package/src/cli/session-picker.ts +57 -7
  56. package/src/cli/update-cli.ts +0 -22
  57. package/src/cli-ordinary.ts +2 -17
  58. package/src/commands/sdk.ts +37 -15
  59. package/src/config/machine-identity.ts +31 -2
  60. package/src/config/model-registry.ts +40 -6
  61. package/src/config/settings-schema.ts +50 -6
  62. package/src/config/settings.ts +65 -3
  63. package/src/gjc-runtime/launch-tmux.ts +4 -1
  64. package/src/internal-urls/docs-index.generated.ts +12 -12
  65. package/src/lsp/client.ts +60 -6
  66. package/src/lsp/index.ts +2 -6
  67. package/src/lsp/types.ts +2 -0
  68. package/src/main.ts +364 -93
  69. package/src/modes/DESIGN.md +36 -0
  70. package/src/modes/acp/acp-agent.ts +215 -31
  71. package/src/modes/components/session-held-warning.ts +62 -0
  72. package/src/modes/components/session-selector.ts +234 -11
  73. package/src/modes/controllers/goal-mode-controller.ts +14 -2
  74. package/src/modes/controllers/selector-controller.ts +192 -3
  75. package/src/modes/interactive-mode.ts +40 -2
  76. package/src/prompts/tools/bash.md +1 -1
  77. package/src/prompts/tools/monitor.md +1 -1
  78. package/src/runtime-mcp/manager.ts +5 -1
  79. package/src/sdk/acp/adapter.ts +2 -0
  80. package/src/sdk/broker/broker.ts +29 -2
  81. package/src/sdk/broker/lifecycle-ledger.ts +9 -7
  82. package/src/sdk/broker/lifecycle.ts +280 -39
  83. package/src/sdk/broker/session-index.ts +24 -0
  84. package/src/sdk/bus/index.ts +1 -0
  85. package/src/sdk/bus/lifecycle-commands.ts +4 -0
  86. package/src/sdk/cli/session-cli.ts +8 -0
  87. package/src/sdk/host/control/dispatch.ts +18 -0
  88. package/src/sdk/host/host.ts +5 -0
  89. package/src/sdk/host/registration-test-hold.ts +51 -0
  90. package/src/sdk/host/session-runtime.test.ts +42 -0
  91. package/src/sdk/index.ts +10 -0
  92. package/src/sdk/lifecycle/service.ts +33 -10
  93. package/src/sdk/prompt-failure.ts +4 -0
  94. package/src/sdk/protocol/operation-registry.ts +7 -1
  95. package/src/sdk/session-api-key.ts +31 -16
  96. package/src/sdk/session-readonly/format.ts +10 -0
  97. package/src/sdk/session-readonly/scope.ts +2 -1
  98. package/src/sdk/session.ts +60 -7
  99. package/src/sdk/startup-capability.ts +27 -2
  100. package/src/session/agent-session.ts +411 -58
  101. package/src/session/internal/managed-session-storage.ts +16 -2
  102. package/src/session/internal/session-claim-set.ts +527 -49
  103. package/src/session/session-handover.ts +283 -0
  104. package/src/session/session-manager.ts +907 -148
  105. package/src/session/session-owner-holder.ts +177 -0
  106. package/src/session/session-ownership-mode.ts +84 -12
  107. package/src/session/session-ownership.ts +115 -89
  108. package/src/session/yield-queue.ts +43 -0
  109. package/src/session-import/provider-service.ts +8 -0
  110. package/src/setup/provider-onboarding.ts +5 -5
  111. package/src/task/executor.ts +2 -0
  112. package/src/tools/bash.ts +10 -0
  113. package/src/tools/browser/deferred-profile-cleanup.ts +20 -0
  114. package/src/tools/browser/launch.ts +133 -14
  115. package/src/tools/browser/registry.ts +72 -19
  116. package/src/tools/index.ts +10 -1
  117. package/src/tools/monitor.ts +267 -29
  118. package/src/tools/output-meta.ts +61 -28
  119. package/src/tools/tool-catalog.generated.ts +2 -2
  120. package/src/tools/tool-result.ts +5 -0
  121. package/dist/types/cli/macos-community-app.d.ts +0 -41
  122. package/src/cli/macos-community-app.ts +0 -1449
package/src/lsp/client.ts CHANGED
@@ -688,6 +688,44 @@ export async function getOrCreateClient(config: ServerConfig, cwd: string, initT
688
688
  return clientPromise;
689
689
  }
690
690
 
691
+ /**
692
+ * Open documents no gjc operation has used for this long are closed before the next
693
+ * document opens. What a server releases on `didClose` is server-dependent; tsserver
694
+ * keeps the whole tsconfig program of every open document loaded and drops a project
695
+ * once all of its documents are closed, when it handles the next open.
696
+ */
697
+ export const OPEN_FILE_IDLE_MS = 5 * 60 * 1000;
698
+
699
+ /** Record that a gjc operation is using an open document. */
700
+ function markFileUsed(client: LspClient, uri: string): void {
701
+ const info = client.openFiles.get(uri);
702
+ if (info) info.lastUsedAt = Date.now();
703
+ }
704
+
705
+ /** Send `didClose` for a tracked document and forget it and its diagnostics. */
706
+ export async function closeDocument(client: LspClient, uri: string): Promise<void> {
707
+ client.openFiles.delete(uri);
708
+ client.diagnostics.delete(uri);
709
+ await sendNotification(client, "textDocument/didClose", { textDocument: { uri } });
710
+ }
711
+
712
+ /**
713
+ * Close documents no gjc operation has used within {@link OPEN_FILE_IDLE_MS}.
714
+ * Documents with an in-flight open, sync or refresh stay open. Called before a
715
+ * didOpen, so the closes reach the server ahead of that open (tsserver unloads
716
+ * projects with no open documents while handling it). Concurrent opens each run this; an entry another call already
717
+ * closed (or reopened) while this one awaited a send is skipped.
718
+ */
719
+ async function closeIdleDocuments(client: LspClient): Promise<void> {
720
+ const idleBefore = Date.now() - OPEN_FILE_IDLE_MS;
721
+ for (const [uri, info] of Array.from(client.openFiles)) {
722
+ if (client.openFiles.get(uri) !== info) continue;
723
+ if (info.lastUsedAt > idleBefore) continue;
724
+ if (fileOperationLocks.has(`${client.name}:${uri}`)) continue;
725
+ await closeDocument(client, uri);
726
+ }
727
+ }
728
+
691
729
  /**
692
730
  * Ensure a file is opened in the LSP client.
693
731
  * Sends didOpen notification if the file is not already tracked.
@@ -699,6 +737,7 @@ export async function ensureFileOpen(client: LspClient, filePath: string, signal
699
737
 
700
738
  // Check if file is already open
701
739
  if (client.openFiles.has(uri)) {
740
+ markFileUsed(client, uri);
702
741
  return;
703
742
  }
704
743
 
@@ -728,6 +767,7 @@ export async function ensureFileOpen(client: LspClient, filePath: string, signal
728
767
  const languageId = detectLanguageId(filePath);
729
768
  throwIfAborted(signal);
730
769
 
770
+ await closeIdleDocuments(client);
731
771
  await sendNotification(client, "textDocument/didOpen", {
732
772
  textDocument: {
733
773
  uri,
@@ -737,7 +777,7 @@ export async function ensureFileOpen(client: LspClient, filePath: string, signal
737
777
  },
738
778
  });
739
779
 
740
- client.openFiles.set(uri, { version: 1, languageId });
780
+ client.openFiles.set(uri, { version: 1, languageId, lastUsedAt: Date.now() });
741
781
  client.lastActivity = Date.now();
742
782
  })();
743
783
 
@@ -772,6 +812,7 @@ export async function syncContent(
772
812
  const uri = fileToUri(filePath);
773
813
  const lockKey = `${client.name}:${uri}`;
774
814
  throwIfAborted(signal);
815
+ markFileUsed(client, uri);
775
816
 
776
817
  const existingLock = fileOperationLocks.get(lockKey);
777
818
  if (existingLock) {
@@ -788,6 +829,7 @@ export async function syncContent(
788
829
  // Open file with provided content instead of reading from disk
789
830
  const languageId = detectLanguageId(filePath);
790
831
  throwIfAborted(signal);
832
+ await closeIdleDocuments(client);
791
833
  await sendNotification(client, "textDocument/didOpen", {
792
834
  textDocument: {
793
835
  uri,
@@ -796,7 +838,7 @@ export async function syncContent(
796
838
  text: content,
797
839
  },
798
840
  });
799
- client.openFiles.set(uri, { version: 1, languageId });
841
+ client.openFiles.set(uri, { version: 1, languageId, lastUsedAt: Date.now() });
800
842
  client.lastActivity = Date.now();
801
843
  return;
802
844
  }
@@ -826,6 +868,7 @@ export async function notifySaved(client: LspClient, filePath: string, signal?:
826
868
  const uri = fileToUri(filePath);
827
869
  const info = client.openFiles.get(uri);
828
870
  if (!info) return; // File not open, nothing to notify
871
+ info.lastUsedAt = Date.now();
829
872
 
830
873
  throwIfAborted(signal);
831
874
  await sendNotification(client, "textDocument/didSave", {
@@ -842,6 +885,7 @@ export async function refreshFile(client: LspClient, filePath: string, signal?:
842
885
  throwIfAborted(signal);
843
886
  const uri = fileToUri(filePath);
844
887
  const lockKey = `${client.name}:${uri}`;
888
+ markFileUsed(client, uri);
845
889
 
846
890
  const existingLock = fileOperationLocks.get(lockKey);
847
891
  if (existingLock) {
@@ -866,8 +910,10 @@ export async function refreshFile(client: LspClient, filePath: string, signal?:
866
910
  content = await Bun.file(filePath).text();
867
911
  throwIfAborted(signal);
868
912
  } catch (err) {
869
- if (isEnoent(err)) return;
870
- throw err;
913
+ if (!isEnoent(err)) throw err;
914
+ // Deleted outside the LSP: the server must not keep serving its last text.
915
+ await closeDocument(client, uri);
916
+ return;
871
917
  }
872
918
  const version = ++info.version;
873
919
  throwIfAborted(signal);
@@ -901,8 +947,16 @@ async function shutdownClientInstance(client: LspClient): Promise<void> {
901
947
  const err = new Error("LSP client shutdown");
902
948
  rejectPendingRequests(client, err);
903
949
 
904
- const shutdown = sendRequest(client, "shutdown", null, undefined, 5_000).catch(() => {});
905
- await Promise.race([shutdown, Bun.sleep(5_000)]);
950
+ // LSP shutdown sequence: the `shutdown` request, then the `exit` notification that
951
+ // tells the server to terminate itself. Process teardown only runs for a server
952
+ // that has not exited by the deadline.
953
+ const exited = client.proc.exited.catch(() => undefined);
954
+ const graceful = (async () => {
955
+ await sendRequest(client, "shutdown", null, undefined, 5_000);
956
+ await sendNotification(client, "exit", undefined);
957
+ await exited;
958
+ })().catch(() => {});
959
+ await Promise.race([graceful, Bun.sleep(5_000)]);
906
960
  await client.owner?.dispose();
907
961
  await client.owner?.awaitExit({ timeoutMs: 1_000 });
908
962
  await Promise.race([client.proc.exited.catch(() => undefined), Bun.sleep(1_000)]);
package/src/lsp/index.ts CHANGED
@@ -11,6 +11,7 @@ import { formatPathRelativeToCwd, resolveToCwd } from "../tools/path-utils";
11
11
  import { ToolAbortError, ToolError, throwIfAborted } from "../tools/tool-errors";
12
12
  import { clampTimeout } from "../tools/tool-timeouts";
13
13
  import {
14
+ closeDocument,
14
15
  ensureFileOpen,
15
16
  getActiveClients,
16
17
  getOrCreateClient,
@@ -1578,12 +1579,7 @@ export class LspTool implements AgentTool<typeof lspSchema, LspToolDetails, Them
1578
1579
  try {
1579
1580
  const client = await getOrCreateClient(serverConfig, this.session.cwd);
1580
1581
  for (const { oldUri } of pairs) {
1581
- if (client.openFiles.has(oldUri)) {
1582
- await sendNotification(client, "textDocument/didClose", {
1583
- textDocument: { uri: oldUri },
1584
- });
1585
- client.openFiles.delete(oldUri);
1586
- }
1582
+ if (client.openFiles.has(oldUri)) await closeDocument(client, oldUri);
1587
1583
  }
1588
1584
  await sendNotification(client, "workspace/didRenameFiles", lspParams);
1589
1585
  } catch (err) {
package/src/lsp/types.ts CHANGED
@@ -378,6 +378,8 @@ export interface ServerConfig {
378
378
  export interface OpenFile {
379
379
  version: number;
380
380
  languageId: string;
381
+ /** When a gjc operation last used this document; long-unused documents close before the next open. */
382
+ lastUsedAt: number;
381
383
  }
382
384
 
383
385
  export interface PendingRequest {