@gajae-code/coding-agent 0.22.1 → 0.22.2

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 (75) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/types/cli/doctor/probe-types.d.ts +1 -1
  3. package/dist/types/cli/doctor/session-owners-probe.d.ts +7 -0
  4. package/dist/types/cli/doctor/session-owners.d.ts +16 -0
  5. package/dist/types/cli/github-release.d.ts +16 -0
  6. package/dist/types/cli/session-owners-cli.d.ts +13 -0
  7. package/dist/types/cli/update-cli.d.ts +2 -0
  8. package/dist/types/commands/sdk.d.ts +23 -14
  9. package/dist/types/config/settings-schema.d.ts +6 -0
  10. package/dist/types/exec/bash-shell-guardian.d.ts +61 -0
  11. package/dist/types/export/html/html-export-destination.d.ts +16 -0
  12. package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +1 -1
  13. package/dist/types/sdk/host/control/runtime-gate.d.ts +7 -0
  14. package/dist/types/session/internal/graph-successor-proof.d.ts +33 -0
  15. package/dist/types/session/internal/managed-session-storage.d.ts +6 -1
  16. package/dist/types/session/internal/session-claim-set.d.ts +69 -0
  17. package/dist/types/session/operator-error-message.d.ts +29 -0
  18. package/dist/types/session/session-manager.d.ts +57 -3
  19. package/dist/types/session/session-owners-layout.d.ts +24 -0
  20. package/dist/types/session/session-ownership-mode.d.ts +45 -0
  21. package/dist/types/session/session-ownership.d.ts +195 -0
  22. package/dist/types/session/session-storage.d.ts +36 -0
  23. package/dist/types/slash-commands/helpers/parse.d.ts +1 -0
  24. package/package.json +12 -8
  25. package/scripts/verify-gjc-sdk-canonicalization.ts +2 -0
  26. package/src/cli/doctor/probe-types.ts +1 -1
  27. package/src/cli/doctor/probe.ts +9 -5
  28. package/src/cli/doctor/runner.ts +6 -1
  29. package/src/cli/doctor/session-owners-probe.ts +69 -0
  30. package/src/cli/doctor/session-owners.ts +106 -0
  31. package/src/cli/github-release.ts +100 -0
  32. package/src/cli/session-owners-cli.ts +118 -0
  33. package/src/cli/stats-cli.ts +19 -1
  34. package/src/cli/update-cli.ts +50 -3
  35. package/src/cli-ordinary.ts +1 -1
  36. package/src/commands/sdk.ts +36 -33
  37. package/src/commands/session.ts +10 -2
  38. package/src/config/settings-schema.ts +18 -0
  39. package/src/config/settings.ts +127 -13
  40. package/src/exec/bash-shell-guardian.ts +181 -12
  41. package/src/exec/isolated-shell.ts +13 -3
  42. package/src/export/html/html-export-destination.ts +47 -2
  43. package/src/export/html/index.ts +161 -13
  44. package/src/internal-urls/docs-index.generated.ts +4 -4
  45. package/src/main.ts +20 -14
  46. package/src/modes/acp/acp-agent.ts +6 -0
  47. package/src/modes/action-registry.ts +4 -1
  48. package/src/modes/controllers/command-controller.ts +12 -5
  49. package/src/modes/controllers/extension-ui-controller.ts +6 -22
  50. package/src/modes/controllers/input-controller.ts +3 -2
  51. package/src/modes/controllers/selector-controller.ts +14 -1
  52. package/src/modes/interactive-mode.ts +6 -3
  53. package/src/modes/print-mode.ts +2 -1
  54. package/src/modes/runtime-init.ts +2 -17
  55. package/src/modes/utils/ui-helpers.ts +5 -3
  56. package/src/sdk/bus/index.ts +22 -0
  57. package/src/sdk/bus/telegram-daemon-contract.ts +1 -1
  58. package/src/sdk/host/control/dispatch.ts +5 -1
  59. package/src/sdk/host/control/runtime-gate.ts +22 -0
  60. package/src/sdk/host/host.ts +4 -1
  61. package/src/sdk/session-readonly/metadata.ts +24 -18
  62. package/src/sdk/session.ts +2 -0
  63. package/src/session/agent-session.ts +101 -22
  64. package/src/session/internal/graph-successor-proof.ts +108 -0
  65. package/src/session/internal/managed-session-storage.ts +8 -1
  66. package/src/session/internal/session-claim-set.ts +242 -0
  67. package/src/session/operator-error-message.ts +79 -0
  68. package/src/session/session-manager.ts +524 -108
  69. package/src/session/session-owners-layout.ts +52 -0
  70. package/src/session/session-ownership-mode.ts +176 -0
  71. package/src/session/session-ownership.ts +851 -0
  72. package/src/session/session-storage.ts +60 -16
  73. package/src/setup/credential-import.ts +2 -1
  74. package/src/slash-commands/builtin-registry.ts +2 -0
  75. package/src/slash-commands/helpers/parse.ts +3 -1
@@ -63,7 +63,7 @@ import {
63
63
  } from "./task-artifact-owner-retirement";
64
64
 
65
65
  const newlineBuffer = Buffer.from("\n", "utf8");
66
- function canonicalPathSync(value: string): string {
66
+ export function canonicalPathSync(value: string): string {
67
67
  try {
68
68
  return fs.realpathSync.native(value);
69
69
  } catch {
@@ -93,7 +93,7 @@ function transcriptLockIdentity(transcriptPath: string): string {
93
93
  * writable without the sticky bit, or group-writable through a group other than the user's
94
94
  * primary group. (Windows profile DACLs grant only the user, SYSTEM, and Administrators.)
95
95
  */
96
- function assertAppendLockHomeNotSharedWritable(home: string): void {
96
+ export function assertAppendLockHomeNotSharedWritable(home: string): void {
97
97
  if (process.platform === "win32") return;
98
98
  const stat = fs.statSync(home);
99
99
  const uid = process.getuid?.();
@@ -106,21 +106,37 @@ function assertAppendLockHomeNotSharedWritable(home: string): void {
106
106
  }
107
107
  }
108
108
 
109
- interface DirectoryIdentity {
109
+ export interface DirectoryIdentity {
110
110
  readonly path: string;
111
111
  readonly dev: bigint;
112
112
  readonly ino: bigint;
113
113
  }
114
114
 
115
+ /** A prepared `<home>/.gjc/runtime/<name>` lock directory plus the identities of `.gjc`, `runtime` and itself. */
116
+ export interface RuntimeLockDirectory {
117
+ readonly path: string;
118
+ readonly directories: readonly DirectoryIdentity[];
119
+ /** The noun error text uses for this namespace's directories, e.g. `append-lock`. */
120
+ readonly label: string;
121
+ }
122
+
115
123
  /** A prepared append-lock path plus the identities of `.gjc`, `runtime`, and `append-locks`. */
116
124
  interface AppendLockTarget {
117
125
  readonly lockPath: string;
118
126
  readonly directories: readonly DirectoryIdentity[];
119
127
  }
120
128
 
121
- function realDirectoryIdentity(pathname: string): DirectoryIdentity {
129
+ /** A lock namespace name: one lower-case path segment, so it can never leave `runtime`. */
130
+ const RUNTIME_LOCK_DIRECTORY_NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
131
+
132
+ /** `append-locks` → `append-lock`: the noun error text uses for a namespace's directories. */
133
+ function runtimeLockDirectoryLabel(name: string): string {
134
+ return name.endsWith("s") ? name.slice(0, -1) : name;
135
+ }
136
+
137
+ function realDirectoryIdentity(pathname: string, label = "append-lock"): DirectoryIdentity {
122
138
  const stat = fs.lstatSync(pathname, { bigint: true });
123
- if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error(`Unsafe append-lock directory: ${pathname}`);
139
+ if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error(`Unsafe ${label} directory: ${pathname}`);
124
140
  return { path: pathname, dev: stat.dev, ino: stat.ino };
125
141
  }
126
142
 
@@ -129,26 +145,44 @@ function realDirectoryIdentity(pathname: string): DirectoryIdentity {
129
145
  * so a principal able to rename entries in `.gjc` cannot redirect a writer to a fresh,
130
146
  * empty lock directory and enter the critical section beside another writer.
131
147
  */
132
- function assertAppendLockTargetUnchanged(target: AppendLockTarget): void {
133
- for (const expected of target.directories) {
148
+ export function assertRuntimeLockDirectoryUnchanged(
149
+ directories: readonly DirectoryIdentity[],
150
+ code = "append_lock_root_changed",
151
+ label = "append-lock",
152
+ ): void {
153
+ for (const expected of directories) {
134
154
  let current: DirectoryIdentity;
135
155
  try {
136
- current = realDirectoryIdentity(expected.path);
156
+ current = realDirectoryIdentity(expected.path, label);
137
157
  } catch (error) {
138
- throw new Error(`append_lock_root_changed: ${expected.path}`, { cause: error });
158
+ throw new Error(`${code}: ${expected.path}`, { cause: error });
139
159
  }
140
160
  if (current.dev !== expected.dev || current.ino !== expected.ino) {
141
- throw new Error(`append_lock_root_changed: ${expected.path}`);
161
+ throw new Error(`${code}: ${expected.path}`);
142
162
  }
143
163
  }
144
164
  }
145
165
 
146
- function prepareAppendLockTarget(transcriptPath: string): AppendLockTarget {
147
- const home = canonicalPathSync(getTrustedHomeDir());
166
+ function assertAppendLockTargetUnchanged(target: AppendLockTarget): void {
167
+ assertRuntimeLockDirectoryUnchanged(target.directories);
168
+ }
169
+
170
+ /**
171
+ * Create `<trusted home>/.gjc/runtime/<name>` for kernel or exclusive-file locks, with the
172
+ * checks every lock namespace shares, and capture its directories' identities for
173
+ * {@link assertRuntimeLockDirectoryUnchanged}. Throws (fails closed) on a home other users can
174
+ * write, a reparse component, or a directory whose owner-only mode or ACL does not verify.
175
+ */
176
+ export function prepareRuntimeLockDirectory(
177
+ name: string,
178
+ trustedHome: string = getTrustedHomeDir(),
179
+ ): RuntimeLockDirectory {
180
+ if (!RUNTIME_LOCK_DIRECTORY_NAME.test(name)) throw new TypeError(`Invalid runtime lock directory name: ${name}`);
181
+ const home = canonicalPathSync(trustedHome);
148
182
  assertAppendLockHomeNotSharedWritable(home);
149
183
  const gjcRoot = path.join(home, ".gjc");
150
184
  const appendLockRuntimeRoot = path.join(gjcRoot, "runtime");
151
- const lockRoot = path.join(appendLockRuntimeRoot, "append-locks");
185
+ const lockRoot = path.join(appendLockRuntimeRoot, name);
152
186
  // No component below the trusted home may be a reparse point, including `.gjc`,
153
187
  // which ensureManagedDirectory would otherwise create through recursively.
154
188
  assertNoReparsePath(lockRoot);
@@ -160,12 +194,22 @@ function prepareAppendLockTarget(transcriptPath: string): AppendLockTarget {
160
194
  ensureManagedDirectory(gjcRoot, undefined, policy);
161
195
  ensureManagedDirectory(appendLockRuntimeRoot, undefined, policy);
162
196
  ensureManagedDirectory(lockRoot, undefined, policy);
197
+ const label = runtimeLockDirectoryLabel(name);
198
+ return {
199
+ path: lockRoot,
200
+ directories: [gjcRoot, appendLockRuntimeRoot, lockRoot].map(directory => realDirectoryIdentity(directory, label)),
201
+ label,
202
+ };
203
+ }
204
+
205
+ function prepareAppendLockTarget(transcriptPath: string): AppendLockTarget {
206
+ const directory = prepareRuntimeLockDirectory("append-locks");
163
207
  return {
164
208
  lockPath: path.join(
165
- lockRoot,
209
+ directory.path,
166
210
  `gjc-${createHash("sha256").update(transcriptLockIdentity(transcriptPath)).digest("hex")}.append-lock`,
167
211
  ),
168
- directories: [gjcRoot, appendLockRuntimeRoot, lockRoot].map(realDirectoryIdentity),
212
+ directories: directory.directories,
169
213
  };
170
214
  }
171
215
 
@@ -894,7 +938,7 @@ export function writeExplicitOwnerOnlyTextSync(pathname: string, content: string
894
938
  }
895
939
 
896
940
  /** Reject a symlink/junction/reparse component before a storage path is created or opened. */
897
- function assertNoReparsePath(pathname: string): void {
941
+ export function assertNoReparsePath(pathname: string): void {
898
942
  const resolved = path.resolve(pathname);
899
943
  const parsed = path.parse(resolved);
900
944
  let current = parsed.root;
@@ -320,7 +320,8 @@ function parseCodexAuth(raw: string, source: string): ImportableCredential | Ski
320
320
  access,
321
321
  refresh,
322
322
  expires: expiresAt ?? Date.now(),
323
- ...(accountId ? { accountId } : {}),
323
+ // The ChatGPT workspace id is also the credential's organization: one login holds a row per workspace.
324
+ ...(accountId ? { accountId, organizationId: accountId } : {}),
324
325
  ...(email ? { email } : {}),
325
326
  };
326
327
  const identity =
@@ -2633,6 +2633,8 @@ const BUILTIN_SLASH_COMMAND_REGISTRY: ReadonlyArray<SlashCommandSpec> = [
2633
2633
  }
2634
2634
  if (!isDirectory) return usage(`Directory does not exist or is not a directory: ${resolvedPath}`, runtime);
2635
2635
  try {
2636
+ // Refuse before flushing, not from inside moveTo.
2637
+ runtime.sessionManager.assertLegacyMutationAllowed("move session");
2636
2638
  await runtime.sessionManager.flush();
2637
2639
  await runtime.sessionManager.moveTo(resolvedPath);
2638
2640
  } catch (err) {
@@ -1,3 +1,4 @@
1
+ import { operatorErrorMessage } from "../../session/operator-error-message";
1
2
  import { parseCommandArgs } from "../../utils/command-args";
2
3
  import type { ParsedSlashCommand, SlashCommandResult, SlashCommandRuntime } from "../types";
3
4
 
@@ -56,8 +57,9 @@ export function parseSubcommand(input: string): ParsedSubcommand {
56
57
  return { verb: trimmed.slice(0, spaceIdx).toLowerCase(), rest: trimmed.slice(spaceIdx + 1).trim() };
57
58
  }
58
59
 
60
+ /** Human text for a failed slash command; session refusals render their operator message. */
59
61
  export function errorMessage(error: unknown): string {
60
- return error instanceof Error ? error.message : String(error);
62
+ return operatorErrorMessage(error, String(error));
61
63
  }
62
64
 
63
65
  /**