lody 0.66.0 → 0.67.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.
@@ -1,8 +1,3 @@
1
- import { execFile } from "node:child_process";
2
- import { readFile } from "node:fs/promises";
3
- import path__default from "node:path";
4
- import { promisify } from "node:util";
5
- import { a as countTextLines } from "./diff-line-counts-BLxwWP6r.js";
6
1
  const NEVER = Object.freeze({
7
2
  status: "aborted"
8
3
  });
@@ -1252,10 +1247,10 @@ const $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
1252
1247
  inst._zod.check = (payload) => {
1253
1248
  try {
1254
1249
  const trimmed = payload.value.trim();
1255
- const url = new URL(trimmed);
1250
+ const url2 = new URL(trimmed);
1256
1251
  if (def.hostname) {
1257
1252
  def.hostname.lastIndex = 0;
1258
- if (!def.hostname.test(url.hostname)) {
1253
+ if (!def.hostname.test(url2.hostname)) {
1259
1254
  payload.issues.push({
1260
1255
  code: "invalid_format",
1261
1256
  format: "url",
@@ -1269,7 +1264,7 @@ const $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
1269
1264
  }
1270
1265
  if (def.protocol) {
1271
1266
  def.protocol.lastIndex = 0;
1272
- if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
1267
+ if (!def.protocol.test(url2.protocol.endsWith(":") ? url2.protocol.slice(0, -1) : url2.protocol)) {
1273
1268
  payload.issues.push({
1274
1269
  code: "invalid_format",
1275
1270
  format: "url",
@@ -1282,7 +1277,7 @@ const $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
1282
1277
  }
1283
1278
  }
1284
1279
  if (def.normalize) {
1285
- payload.value = url.href;
1280
+ payload.value = url2.href;
1286
1281
  } else {
1287
1282
  payload.value = trimmed;
1288
1283
  }
@@ -4258,6 +4253,9 @@ const ZodURL = /* @__PURE__ */ $constructor("ZodURL", (inst, def) => {
4258
4253
  $ZodURL.init(inst, def);
4259
4254
  ZodStringFormat.init(inst, def);
4260
4255
  });
4256
+ function url(params) {
4257
+ return /* @__PURE__ */ _url(ZodURL, params);
4258
+ }
4261
4259
  const ZodEmoji = /* @__PURE__ */ $constructor("ZodEmoji", (inst, def) => {
4262
4260
  $ZodEmoji.init(inst, def);
4263
4261
  ZodStringFormat.init(inst, def);
@@ -4756,1003 +4754,40 @@ function superRefine(fn) {
4756
4754
  function preprocess(fn, schema) {
4757
4755
  return pipe(transform(fn), schema);
4758
4756
  }
4759
- _enum(["host", "write", "read"]);
4760
- _enum([
4761
- "not-started",
4762
- "starting",
4763
- "online",
4764
- "offline",
4765
- "stopping",
4766
- "unsupported"
4767
- ]);
4768
- _enum([
4769
- "live-collaborative",
4770
- "live-readonly",
4771
- "historical-turn",
4772
- "host-offline",
4773
- "degraded"
4774
- ]);
4775
- _enum(["code-collab", "none"]);
4776
- _enum([
4777
- "focused",
4778
- "background",
4779
- "idle",
4780
- "disconnected"
4781
- ]);
4782
- const CodeCollabFileKindSchema = _enum([
4783
- "text",
4784
- "binary",
4785
- "large",
4786
- "symlink",
4787
- "special",
4788
- "deleted"
4789
- ]);
4790
- const CodeCollabSpecialKindSchema = _enum([
4791
- "fifo",
4792
- "socket",
4793
- "block-device",
4794
- "char-device",
4795
- "unknown"
4796
- ]);
4797
- const CodeCollabTextEolSchema = _enum(["lf", "crlf", "mixed", "unknown"]);
4798
- const CodeCollabUnavailableReasonSchema = _enum([
4799
- "permission-denied",
4800
- "locked",
4801
- "transient-io",
4802
- "text-too-large",
4803
- "line-too-long",
4804
- "unsupported-encoding",
4805
- "unsupported-special",
4806
- "blob-too-large",
4807
- "path-collision",
4808
- "unknown"
4809
- ]);
4810
- _enum([
4811
- "deleted",
4812
- "metadata-only",
4813
- "missing-text-frontiers",
4814
- "missing-blob-digest",
4815
- "blob-expired",
4816
- ...CodeCollabUnavailableReasonSchema.options
4817
- ]);
4818
- const CodeCollabDomainErrorCodeSchema = _enum([
4819
- "permission-denied",
4820
- "space-not-found",
4821
- "secret-unavailable",
4822
- "streams-unavailable",
4823
- "blob-unavailable",
4824
- "workspace-path-rejected",
4825
- "file-ignored",
4826
- "file-too-large",
4827
- "binary-unsupported",
4828
- "hydration-failed",
4829
- "save-conflict",
4830
- "host-offline",
4831
- "lsp-unavailable",
4832
- "external-file-unavailable",
4833
- "unexpected"
4834
- ]);
4835
- object({
4836
- code: CodeCollabDomainErrorCodeSchema,
4837
- message: string().min(1),
4838
- redacted: boolean().optional()
4839
- }).strict();
4840
- const CODE_COLLAB_V2_TEXT_LIMITS = {
4841
- plainTextBytes: 64 * 1024,
4842
- maxCompressedBytes: 1024 * 1024,
4843
- maxRawTextBytes: 10 * 1024 * 1024
4844
- };
4845
- const CodeCollabV2FileDigestSchema = string().regex(/^sha256:[0-9a-f]{64}$/u);
4846
- const CodeCollabV2TextFormatSchema = object({
4847
- encoding: literal("utf8"),
4848
- bom: boolean().optional(),
4849
- eol: _enum(["lf", "crlf", "mixed", "unknown"]).optional()
4850
- }).strict();
4851
- const CodeCollabV2EncodedTextPayloadSchema = discriminatedUnion("encoding", [
4852
- object({
4853
- encoding: literal("plain"),
4854
- text: string(),
4855
- rawBytes: number().int().nonnegative()
4856
- }).strict(),
4857
- object({
4858
- encoding: literal("gzip-base64"),
4859
- data: string().min(1),
4860
- rawBytes: number().int().nonnegative(),
4861
- compressedBytes: number().int().nonnegative()
4862
- }).strict()
4863
- ]);
4864
- const CodeCollabV2ErrorCodeSchema = _enum([
4865
- "invalid_path",
4866
- "session_not_found",
4867
- "workspace_root_unavailable",
4868
- "machine_offline",
4869
- "file_not_found",
4870
- "path_conflict",
4871
- "unsupported_binary",
4872
- "unsupported_skipped",
4873
- "too_large",
4874
- "decode_error",
4875
- "digest_mismatch",
4876
- "permission_denied",
4877
- "transient_io",
4878
- "lsp_not_wired"
4879
- ]);
4880
- const CodeCollabV2ErrorSchema = object({
4881
- status: literal("error"),
4882
- code: CodeCollabV2ErrorCodeSchema,
4883
- message: string().min(1).optional(),
4884
- path: string().min(1).optional(),
4885
- retryable: boolean().optional()
4886
- }).strict();
4887
- const CodeCollabV2OpenTextRequestSchema = object({
4888
- sessionId: string().trim().min(1),
4889
- path: string().min(1)
4890
- }).strict();
4891
- const CodeCollabV2OpenTextOkSchema = object({
4892
- status: literal("ok"),
4893
- path: string().min(1),
4894
- digest: CodeCollabV2FileDigestSchema,
4895
- text: CodeCollabV2EncodedTextPayloadSchema,
4896
- format: CodeCollabV2TextFormatSchema.optional(),
4897
- readonly: boolean().optional()
4898
- }).strict();
4899
- const CodeCollabV2RefreshTextRequestSchema = object({
4900
- sessionId: string().trim().min(1),
4901
- path: string().min(1),
4902
- digest: CodeCollabV2FileDigestSchema
4903
- }).strict();
4904
- const CodeCollabV2RefreshTextResponseSchema = discriminatedUnion("status", [
4905
- object({
4906
- status: literal("up_to_date"),
4907
- path: string().min(1),
4908
- digest: CodeCollabV2FileDigestSchema
4909
- }).strict(),
4910
- object({
4911
- status: literal("updated"),
4912
- path: string().min(1),
4913
- digest: CodeCollabV2FileDigestSchema,
4914
- text: CodeCollabV2EncodedTextPayloadSchema,
4915
- format: CodeCollabV2TextFormatSchema.optional(),
4916
- readonly: boolean().optional()
4917
- }).strict()
4918
- ]);
4919
- const CodeCollabV2SaveTextRequestSchema = object({
4920
- sessionId: string().trim().min(1),
4921
- requestedByUserId: string().trim().min(1),
4922
- path: string().min(1),
4923
- baseDigest: CodeCollabV2FileDigestSchema,
4924
- text: CodeCollabV2EncodedTextPayloadSchema,
4925
- format: CodeCollabV2TextFormatSchema.optional()
4926
- }).strict();
4927
- const CodeCollabV2SaveTextOkSchema = object({
4928
- status: literal("ok"),
4929
- path: string().min(1),
4930
- digest: CodeCollabV2FileDigestSchema,
4931
- rawBytes: number().int().nonnegative()
4932
- }).strict();
4933
- const CodeCollabV2SaveTextConflictSchema = object({
4934
- status: literal("conflict"),
4935
- reason: _enum(["digest_mismatch", "path_changed", "file_deleted", "path_conflict"]),
4936
- path: string().min(1),
4937
- baseDigest: CodeCollabV2FileDigestSchema,
4938
- diskDigest: CodeCollabV2FileDigestSchema.optional(),
4939
- diskText: CodeCollabV2EncodedTextPayloadSchema.optional()
4940
- }).strict();
4941
- const CodeCollabV2SaveTextResponseSchema = discriminatedUnion("status", [
4942
- CodeCollabV2SaveTextOkSchema,
4943
- CodeCollabV2SaveTextConflictSchema
4944
- ]);
4945
- const CodeCollabV2OpenCurrentDiffRequestSchema = object({
4946
- sessionId: string().trim().min(1),
4947
- path: string().min(1)
4948
- }).strict();
4949
- const CodeCollabV2DiffSnapshotSchema = discriminatedUnion("kind", [
4950
- object({
4951
- kind: literal("text"),
4952
- text: CodeCollabV2EncodedTextPayloadSchema,
4953
- format: CodeCollabV2TextFormatSchema.optional()
4954
- }).strict(),
4955
- object({ kind: literal("missing") }).strict(),
4956
- object({ kind: literal("binary") }).strict(),
4957
- object({ kind: literal("too_large") }).strict()
4958
- ]);
4959
- const CodeCollabV2OpenCurrentDiffResponseSchema = discriminatedUnion("status", [
4960
- object({
4961
- status: literal("ok"),
4962
- path: string().min(1),
4963
- oldSnapshot: CodeCollabV2DiffSnapshotSchema,
4964
- newSnapshot: CodeCollabV2DiffSnapshotSchema,
4965
- add: number().int().nonnegative().optional(),
4966
- del: number().int().nonnegative().optional()
4967
- }).strict(),
4968
- object({
4969
- status: literal("unavailable"),
4970
- path: string().min(1),
4971
- reason: _enum([
4972
- "base_unavailable",
4973
- "not_changed",
4974
- "transient_io",
4975
- "unsupported_binary"
4976
- ]),
4977
- message: string().min(1).optional()
4978
- }).strict()
4979
- ]);
4980
- const CodeCollabV2OpenTurnDiffRequestSchema = object({
4981
- sessionId: string().trim().min(1),
4982
- turnId: string().trim().min(1),
4983
- path: string().min(1)
4984
- }).strict();
4985
- const CodeCollabV2OpenTurnDiffResponseSchema = discriminatedUnion("status", [
4986
- object({
4987
- status: literal("ok"),
4988
- path: string().min(1),
4989
- turnId: string().trim().min(1),
4990
- oldSnapshot: CodeCollabV2DiffSnapshotSchema,
4991
- newSnapshot: CodeCollabV2DiffSnapshotSchema,
4992
- add: number().int().nonnegative().optional(),
4993
- del: number().int().nonnegative().optional()
4994
- }).strict(),
4995
- object({
4996
- status: literal("unavailable"),
4997
- path: string().min(1),
4998
- turnId: string().trim().min(1),
4999
- reason: _enum(["turn_unavailable", "not_changed", "transient_io"]),
5000
- message: string().min(1).optional()
5001
- }).strict()
5002
- ]);
5003
- const CodeCollabV2InitDirectoryRequestSchema = object({
5004
- sessionId: string().trim().min(1),
5005
- path: string().min(1)
5006
- }).strict();
5007
- const CodeCollabV2InitDirectoryOkSchema = object({
5008
- status: literal("ok"),
5009
- path: string().min(1),
5010
- publishedEntries: number().int().nonnegative().optional()
5011
- }).strict();
5012
- const CodeCollabV2LspUnsupportedSchema = object({
5013
- status: literal("unsupported"),
5014
- code: literal("lsp_not_wired")
5015
- }).strict();
5016
- const CodeCollabV2FileTreeValueSchema = union([
5017
- literal(true),
5018
- object({ kind: literal("lazy") }).strict(),
5019
- object({ kind: literal("binary") }).strict(),
5020
- object({
5021
- kind: literal("skipped"),
5022
- reason: string().min(1)
5023
- }).strict(),
5024
- object({
5025
- kind: literal("too_large"),
5026
- rawBytes: number().int().nonnegative().optional(),
5027
- compressedBytes: number().int().nonnegative().optional()
5028
- }).strict()
5029
- ]);
5030
- record(
5031
- string().min(1),
5032
- CodeCollabV2FileTreeValueSchema
5033
- );
5034
- const CodeCollabV2AllChangesValueSchema = union([
5035
- literal(true),
5036
- object({
5037
- diff: tuple([number().int().nonnegative(), number().int().nonnegative()]).optional(),
5038
- del: literal(true).optional()
5039
- }).strict()
5040
- ]);
5041
- record(
5042
- string().min(1),
5043
- CodeCollabV2AllChangesValueSchema
5044
- );
5045
- const CodeCollabV2FileIndexValueSchema = union([
5046
- literal(true),
5047
- object({
5048
- kind: literal("file"),
5049
- change: CodeCollabV2AllChangesValueSchema.optional()
5050
- }).strict(),
5051
- object({
5052
- kind: literal("text"),
5053
- change: CodeCollabV2AllChangesValueSchema.optional()
5054
- }).strict(),
5055
- object({
5056
- kind: literal("binary"),
5057
- change: CodeCollabV2AllChangesValueSchema.optional()
5058
- }).strict(),
5059
- object({
5060
- kind: literal("too_large"),
5061
- rawBytes: number().int().nonnegative().optional(),
5062
- compressedBytes: number().int().nonnegative().optional(),
5063
- change: CodeCollabV2AllChangesValueSchema.optional()
5064
- }).strict(),
5065
- object({
5066
- kind: literal("deleted"),
5067
- change: CodeCollabV2AllChangesValueSchema
5068
- }).strict(),
5069
- object({ kind: literal("lazy") }).strict(),
5070
- object({
5071
- kind: literal("skipped"),
5072
- reason: string().min(1)
5073
- }).strict()
5074
- ]);
5075
- record(
5076
- string().min(1),
5077
- CodeCollabV2FileIndexValueSchema
5078
- );
5079
- const codeCollabFileIndexKeyForWorkspacePath = (workspacePath) => [
5080
- workspacePath
5081
- ];
5082
- function readCodeCollabFileIndexFromFlock(flock) {
5083
- const fileIndex = {};
5084
- for (const row of flock.scan()) {
5085
- if (row.value === void 0) {
5086
- continue;
5087
- }
5088
- const [workspacePath, ...extra] = row.key;
5089
- if (typeof workspacePath !== "string" || workspacePath.length === 0 || extra.length > 0) {
5090
- continue;
5091
- }
5092
- const parsed = CodeCollabV2FileIndexValueSchema.safeParse(row.value);
5093
- if (!parsed.success) {
5094
- continue;
5095
- }
5096
- fileIndex[workspacePath] = parsed.data;
5097
- }
5098
- return fileIndex;
5099
- }
5100
- function writeCodeCollabFileIndexToFlock(flock, next, nowMs) {
5101
- const previous = readCodeCollabFileIndexFromFlock(flock);
5102
- let changed = false;
5103
- for (const workspacePath of Object.keys(previous)) {
5104
- if (Object.prototype.hasOwnProperty.call(next, workspacePath)) {
5105
- continue;
5106
- }
5107
- flock.delete(codeCollabFileIndexKeyForWorkspacePath(workspacePath), nowMs);
5108
- changed = true;
5109
- }
5110
- for (const [workspacePath, value] of Object.entries(next)) {
5111
- if (codeCollabFileIndexValuesEqual(previous[workspacePath], value)) {
5112
- continue;
5113
- }
5114
- flock.set(codeCollabFileIndexKeyForWorkspacePath(workspacePath), value, nowMs);
5115
- changed = true;
5116
- }
5117
- if (changed) {
5118
- flock.commit();
5119
- }
5120
- return changed;
5121
- }
5122
- function codeCollabAllChangesValuesEqual(left, right) {
5123
- if (left === right) return true;
5124
- if (left === void 0 || right === void 0) return false;
5125
- if (left === true || right === true) return false;
5126
- const leftDiff = left.diff;
5127
- const rightDiff = right.diff;
5128
- return left.del === right.del && (leftDiff === void 0 && rightDiff === void 0 || leftDiff !== void 0 && rightDiff !== void 0 && leftDiff[0] === rightDiff[0] && leftDiff[1] === rightDiff[1]);
5129
- }
5130
- function codeCollabFileIndexValuesEqual(left, right) {
5131
- if (left === right) return true;
5132
- if (left === void 0 || right === void 0) return false;
5133
- if (left === true || right === true) return false;
5134
- switch (left.kind) {
5135
- case "file":
5136
- return right.kind === "file" && codeCollabAllChangesValuesEqual(left.change, right.change);
5137
- case "text":
5138
- return right.kind === "text" && codeCollabAllChangesValuesEqual(left.change, right.change);
5139
- case "binary":
5140
- return right.kind === "binary" && codeCollabAllChangesValuesEqual(left.change, right.change);
5141
- case "too_large":
5142
- return right.kind === "too_large" && left.rawBytes === right.rawBytes && left.compressedBytes === right.compressedBytes && codeCollabAllChangesValuesEqual(left.change, right.change);
5143
- case "deleted":
5144
- return right.kind === "deleted" && codeCollabAllChangesValuesEqual(left.change, right.change);
5145
- case "lazy":
5146
- return right.kind === "lazy";
5147
- case "skipped":
5148
- return right.kind === "skipped" && left.reason === right.reason;
5149
- }
5150
- return assertNever(left);
5151
- }
5152
- function codeCollabFileIndexStatesEqual(left, right) {
5153
- const leftPaths = Object.keys(left);
5154
- const rightPaths = Object.keys(right);
5155
- if (leftPaths.length !== rightPaths.length) return false;
5156
- for (const workspacePath of leftPaths) {
5157
- if (!Object.prototype.hasOwnProperty.call(right, workspacePath)) return false;
5158
- if (!codeCollabFileIndexValuesEqual(left[workspacePath], right[workspacePath])) return false;
5159
- }
5160
- return true;
5161
- }
5162
- function codeCollabFileTreeValueToFileIndexValue(value, change) {
5163
- if (value === true) {
5164
- return change === void 0 ? true : { kind: "file", change };
5165
- }
5166
- switch (value.kind) {
5167
- case "lazy":
5168
- return { kind: "lazy" };
5169
- case "binary":
5170
- case "too_large":
5171
- return change === void 0 ? true : { kind: "file", change };
5172
- case "skipped":
5173
- return { kind: "skipped", reason: value.reason };
5174
- }
5175
- return assertNever(value);
5176
- }
5177
- function buildCodeCollabFileIndexState(fileTree, allChanges) {
5178
- const fileIndex = {};
5179
- for (const [workspacePath, value] of Object.entries(fileTree)) {
5180
- fileIndex[workspacePath] = codeCollabFileTreeValueToFileIndexValue(
5181
- value,
5182
- allChanges[workspacePath]
5183
- );
5184
- }
5185
- for (const [workspacePath, change] of Object.entries(allChanges)) {
5186
- if (fileIndex[workspacePath] !== void 0) {
5187
- continue;
5188
- }
5189
- fileIndex[workspacePath] = { kind: "deleted", change };
5190
- }
5191
- return fileIndex;
5192
- }
5193
- const CODE_COLLAB_V2_RPC_CONTENT_ENVELOPE_TYPE = "code-collab-v2-content-envelope";
5194
- const CODE_COLLAB_V2_RPC_CONTENT_KEY_VERSION = 1;
5195
- const CODE_COLLAB_V2_RPC_CONTENT_KEY_ALGORITHM = "AES-256-GCM";
5196
- const CodeCollabV2RpcContentEnvelopeSchema = object({
5197
- type: literal(CODE_COLLAB_V2_RPC_CONTENT_ENVELOPE_TYPE),
5198
- keyVersion: literal(CODE_COLLAB_V2_RPC_CONTENT_KEY_VERSION),
5199
- algorithm: literal(CODE_COLLAB_V2_RPC_CONTENT_KEY_ALGORITHM),
5200
- ownerSessionId: string().trim().min(1),
5201
- keyId: string().trim().min(1),
5202
- iv: string().trim().min(1),
5203
- ciphertext: string().trim().min(1)
5204
- }).strict();
5205
- union([
5206
- CodeCollabV2OpenTextOkSchema,
5207
- CodeCollabV2RefreshTextResponseSchema,
5208
- CodeCollabV2SaveTextResponseSchema,
5209
- CodeCollabV2OpenCurrentDiffResponseSchema,
5210
- CodeCollabV2OpenTurnDiffResponseSchema,
5211
- CodeCollabV2InitDirectoryOkSchema,
5212
- CodeCollabV2LspUnsupportedSchema
5213
- ]);
5214
- const CODE_COLLAB_V2_CONTENT_KEY_DERIVATION_LABEL = "lody-code-collab-v2-bootstrap-content-key-v1";
5215
- const CODE_COLLAB_V2_CONTENT_KEY_ID_DERIVATION_LABEL = "lody-code-collab-v2-bootstrap-content-key-id-v1";
5216
- const CODE_COLLAB_V2_BOOTSTRAP_CONTENT_KEY_SALT = "lody-code-collab-v2-bootstrap-salt-v1";
5217
- function deriveCodeCollabV2ContentKeyBytes(ownerSessionId) {
5218
- return sha256Bytes(
5219
- `${CODE_COLLAB_V2_CONTENT_KEY_DERIVATION_LABEL}\0${CODE_COLLAB_V2_BOOTSTRAP_CONTENT_KEY_SALT}\0${ownerSessionId}`
5220
- );
5221
- }
5222
- function deriveCodeCollabV2ContentKeyId(ownerSessionId) {
5223
- const digest = sha256Bytes(
5224
- `${CODE_COLLAB_V2_CONTENT_KEY_ID_DERIVATION_LABEL}\0${CODE_COLLAB_V2_BOOTSTRAP_CONTENT_KEY_SALT}\0${ownerSessionId}`
5225
- );
5226
- return `ccv2:${bytesToHex(digest).slice(0, 24)}`;
5227
- }
5228
- object({
5229
- fileId: string().min(1),
5230
- path: string().min(1),
5231
- kind: CodeCollabFileKindSchema,
5232
- specialKind: CodeCollabSpecialKindSchema.optional(),
5233
- textEol: CodeCollabTextEolSchema.optional(),
5234
- hasBom: boolean().optional(),
5235
- mode: number().int().nonnegative().optional(),
5236
- executable: boolean().optional(),
5237
- sizeBytes: number().int().nonnegative().optional(),
5238
- mimeType: string().optional(),
5239
- contentDigest: string().optional(),
5240
- linkTarget: string().optional(),
5241
- unavailableReason: CodeCollabUnavailableReasonSchema.optional(),
5242
- updatedAt: string().optional(),
5243
- deletedAt: string().optional()
5244
- }).strict();
5245
- _enum([
5246
- "regular-file",
5247
- "directory",
5248
- "symlink",
5249
- "fifo",
5250
- "socket",
5251
- "block-device",
5252
- "char-device",
5253
- "unknown"
5254
- ]);
5255
- object({
5256
- exists: boolean(),
5257
- path: string().optional(),
5258
- kind: _enum(["text", "binary", "large"]).optional(),
5259
- textDocId: string().optional(),
5260
- textFrontiers: unknown().optional(),
5261
- contentDigest: string().optional(),
5262
- blobDigest: string().optional(),
5263
- mode: number().int().nonnegative().optional(),
5264
- executable: boolean().optional(),
5265
- sizeBytes: number().int().nonnegative().optional()
5266
- }).strict();
5267
- const SHA256_INITIAL_HASH = [
5268
- 1779033703,
5269
- 3144134277,
5270
- 1013904242,
5271
- 2773480762,
5272
- 1359893119,
5273
- 2600822924,
5274
- 528734635,
5275
- 1541459225
5276
- ];
5277
- const SHA256_K = [
5278
- 1116352408,
5279
- 1899447441,
5280
- 3049323471,
5281
- 3921009573,
5282
- 961987163,
5283
- 1508970993,
5284
- 2453635748,
5285
- 2870763221,
5286
- 3624381080,
5287
- 310598401,
5288
- 607225278,
5289
- 1426881987,
5290
- 1925078388,
5291
- 2162078206,
5292
- 2614888103,
5293
- 3248222580,
5294
- 3835390401,
5295
- 4022224774,
5296
- 264347078,
5297
- 604807628,
5298
- 770255983,
5299
- 1249150122,
5300
- 1555081692,
5301
- 1996064986,
5302
- 2554220882,
5303
- 2821834349,
5304
- 2952996808,
5305
- 3210313671,
5306
- 3336571891,
5307
- 3584528711,
5308
- 113926993,
5309
- 338241895,
5310
- 666307205,
5311
- 773529912,
5312
- 1294757372,
5313
- 1396182291,
5314
- 1695183700,
5315
- 1986661051,
5316
- 2177026350,
5317
- 2456956037,
5318
- 2730485921,
5319
- 2820302411,
5320
- 3259730800,
5321
- 3345764771,
5322
- 3516065817,
5323
- 3600352804,
5324
- 4094571909,
5325
- 275423344,
5326
- 430227734,
5327
- 506948616,
5328
- 659060556,
5329
- 883997877,
5330
- 958139571,
5331
- 1322822218,
5332
- 1537002063,
5333
- 1747873779,
5334
- 1955562222,
5335
- 2024104815,
5336
- 2227730452,
5337
- 2361852424,
5338
- 2428436474,
5339
- 2756734187,
5340
- 3204031479,
5341
- 3329325298
5342
- ];
5343
- const rightRotate = (value, bits) => value >>> bits | value << 32 - bits;
5344
- function sha256Bytes(value) {
5345
- const bytes = new TextEncoder().encode(value);
5346
- const bitLength = bytes.length * 8;
5347
- const paddingLength = (64 - (bytes.length + 1 + 8) % 64) % 64;
5348
- const data = new Uint8Array(bytes.length + 1 + paddingLength + 8);
5349
- data.set(bytes);
5350
- data[bytes.length] = 128;
5351
- const view = new DataView(data.buffer);
5352
- view.setUint32(data.length - 8, Math.floor(bitLength / 4294967296));
5353
- view.setUint32(data.length - 4, bitLength >>> 0);
5354
- const hash = [...SHA256_INITIAL_HASH];
5355
- const words = new Array(64).fill(0);
5356
- for (let offset = 0; offset < data.length; offset += 64) {
5357
- for (let i = 0; i < 16; i += 1) {
5358
- words[i] = view.getUint32(offset + i * 4);
5359
- }
5360
- for (let i = 16; i < 64; i += 1) {
5361
- const s0 = rightRotate(words[i - 15] ?? 0, 7) ^ rightRotate(words[i - 15] ?? 0, 18) ^ (words[i - 15] ?? 0) >>> 3;
5362
- const s1 = rightRotate(words[i - 2] ?? 0, 17) ^ rightRotate(words[i - 2] ?? 0, 19) ^ (words[i - 2] ?? 0) >>> 10;
5363
- words[i] = (words[i - 16] ?? 0) + s0 + (words[i - 7] ?? 0) + s1 >>> 0 >>> 0;
5364
- }
5365
- let [a, b, c, d, e, f, g, h] = hash;
5366
- for (let i = 0; i < 64; i += 1) {
5367
- const s1 = rightRotate(e ?? 0, 6) ^ rightRotate(e ?? 0, 11) ^ rightRotate(e ?? 0, 25);
5368
- const ch = (e ?? 0) & (f ?? 0) ^ ~(e ?? 0) & (g ?? 0);
5369
- const temp1 = (h ?? 0) + s1 + ch + SHA256_K[i] + words[i] >>> 0 >>> 0;
5370
- const s0 = rightRotate(a ?? 0, 2) ^ rightRotate(a ?? 0, 13) ^ rightRotate(a ?? 0, 22);
5371
- const maj = (a ?? 0) & (b ?? 0) ^ (a ?? 0) & (c ?? 0) ^ (b ?? 0) & (c ?? 0);
5372
- const temp2 = s0 + maj >>> 0;
5373
- h = g;
5374
- g = f;
5375
- f = e;
5376
- e = (d ?? 0) + temp1 >>> 0;
5377
- d = c;
5378
- c = b;
5379
- b = a;
5380
- a = temp1 + temp2 >>> 0;
5381
- }
5382
- hash[0] = (hash[0] ?? 0) + (a ?? 0) >>> 0;
5383
- hash[1] = (hash[1] ?? 0) + (b ?? 0) >>> 0;
5384
- hash[2] = (hash[2] ?? 0) + (c ?? 0) >>> 0;
5385
- hash[3] = (hash[3] ?? 0) + (d ?? 0) >>> 0;
5386
- hash[4] = (hash[4] ?? 0) + (e ?? 0) >>> 0;
5387
- hash[5] = (hash[5] ?? 0) + (f ?? 0) >>> 0;
5388
- hash[6] = (hash[6] ?? 0) + (g ?? 0) >>> 0;
5389
- hash[7] = (hash[7] ?? 0) + (h ?? 0) >>> 0;
5390
- }
5391
- const output = new Uint8Array(32);
5392
- const outputView = new DataView(output.buffer);
5393
- for (let i = 0; i < hash.length; i += 1) {
5394
- outputView.setUint32(i * 4, hash[i] ?? 0);
5395
- }
5396
- return output;
5397
- }
5398
- function bytesToHex(bytes) {
5399
- return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
5400
- }
5401
- function assertNever(value) {
5402
- throw new Error(`Unhandled Code Collab value: ${String(value)}`);
5403
- }
5404
- const execFileAsync = promisify(execFile);
5405
- const GIT_MAX_BUFFER_BYTES = 64 * 1024 * 1024;
5406
- async function isInsideGitWorktree(workspaceRoot) {
5407
- const inside = await runGit(workspaceRoot, ["rev-parse", "--is-inside-work-tree"]);
5408
- return inside.ok && inside.stdout.trim() === "true";
5409
- }
5410
- async function scanGitDirectoryEntries(options) {
5411
- if (!options.recursive) {
5412
- return null;
5413
- }
5414
- const result = await runGitLsFiles(options.directoryAbsolutePath);
5415
- if (!result.ok) {
5416
- return null;
5417
- }
5418
- return buildEntriesFromGitFilePaths({
5419
- directoryWorkspacePath: options.directoryWorkspacePath,
5420
- entryBudget: options.entryBudget,
5421
- recursive: options.recursive,
5422
- relativeFilePaths: result.paths
5423
- });
5424
- }
5425
- async function runGitLsFiles(cwd) {
5426
- try {
5427
- const [{ stdout }, deleted] = await Promise.all([
5428
- execFileAsync(
5429
- "git",
5430
- [
5431
- "-C",
5432
- cwd,
5433
- "ls-files",
5434
- "-z",
5435
- "--cached",
5436
- "--others",
5437
- "--exclude-standard",
5438
- "--deduplicate",
5439
- "--",
5440
- "."
5441
- ],
5442
- { maxBuffer: GIT_MAX_BUFFER_BYTES }
5443
- ),
5444
- runGit(cwd, ["ls-files", "--deleted", "-z", "--", "."])
5445
- ]);
5446
- const deletedPaths = deleted.ok ? new Set(deleted.stdout.split("\0").map(normalizeGitPath).filter(isValidRelativeGitPath)) : /* @__PURE__ */ new Set();
5447
- return {
5448
- ok: true,
5449
- paths: stdout.split("\0").map(normalizeGitPath).filter((filePath) => isValidRelativeGitPath(filePath) && !deletedPaths.has(filePath))
5450
- };
5451
- } catch {
5452
- return { ok: false };
5453
- }
5454
- }
5455
- async function computeAllChanges(workspaceRoot, options = {}) {
5456
- const diffBase = await resolveAllChangesDiffBase(workspaceRoot, options.preferredBaseBranch);
5457
- const diffTarget = diffBase ?? "HEAD";
5458
- const [numstat, nameStatus, untracked] = await Promise.all([
5459
- // `--numstat` cannot use `-z`, so disable `core.quotePath` to keep non-ASCII paths
5460
- // raw (matching the `-z` outputs below); otherwise they are mis-keyed and lose their
5461
- // All Changes diff counts.
5462
- runGit(workspaceRoot, [
5463
- "-c",
5464
- "core.quotePath=false",
5465
- "diff",
5466
- "--numstat",
5467
- "--no-renames",
5468
- "--relative",
5469
- diffTarget,
5470
- "--"
5471
- ]),
5472
- runGit(workspaceRoot, [
5473
- "diff",
5474
- "--name-status",
5475
- "--no-renames",
5476
- "-z",
5477
- "--relative",
5478
- diffTarget,
5479
- "--"
5480
- ]),
5481
- runGit(workspaceRoot, ["ls-files", "--others", "--exclude-standard", "-z"])
5482
- ]);
5483
- if (!numstat.ok && !nameStatus.ok && !untracked.ok) {
5484
- return {};
5485
- }
5486
- const deletedPaths = nameStatus.ok ? parseDeletedPathsFromNameStatus(nameStatus.stdout) : /* @__PURE__ */ new Set();
5487
- const changes = {};
5488
- if (numstat.ok) {
5489
- for (const line of numstat.stdout.split(/\r?\n/u)) {
5490
- const trimmed = line.trim();
5491
- if (!trimmed) continue;
5492
- const [addRaw, delRaw, ...pathParts] = trimmed.split(" ");
5493
- const filePath = pathParts.join(" ").trim();
5494
- if (!filePath) continue;
5495
- const normalizedPath = normalizeGitPath(filePath);
5496
- if (addRaw === "-" || delRaw === "-") {
5497
- changes[normalizedPath] = true;
5498
- continue;
5499
- }
5500
- const add = Number(addRaw);
5501
- const del = Number(delRaw);
5502
- const diff = [
5503
- Number.isFinite(add) && add >= 0 ? Math.trunc(add) : 0,
5504
- Number.isFinite(del) && del >= 0 ? Math.trunc(del) : 0
5505
- ];
5506
- changes[normalizedPath] = deletedPaths.has(normalizedPath) ? { diff: [0, diff[1]], del: true } : { diff };
5507
- }
5508
- }
5509
- if (untracked.ok) {
5510
- for (const filePath of untracked.stdout.split("\0")) {
5511
- if (!filePath) continue;
5512
- const normalizedPath = normalizeGitPath(filePath);
5513
- if (!(normalizedPath in changes)) {
5514
- changes[normalizedPath] = await lineStatsForUntrackedFile(workspaceRoot, normalizedPath);
5515
- }
5516
- }
5517
- }
5518
- return changes;
5519
- }
5520
- async function resolveAllChangesDiffBase(workspaceRoot, preferredBaseBranch) {
5521
- if (!await isInsideGitWorktree(workspaceRoot)) {
5522
- return null;
5523
- }
5524
- const baseRef = await resolveAllChangesBaseRef(workspaceRoot, preferredBaseBranch);
5525
- if (baseRef) {
5526
- const mergeBase = await runGit(workspaceRoot, ["merge-base", baseRef, "HEAD"]);
5527
- const trimmed = mergeBase.ok ? mergeBase.stdout.trim() : "";
5528
- if (trimmed) {
5529
- return trimmed;
5530
- }
5531
- }
5532
- const head = await runGit(workspaceRoot, ["rev-parse", "--verify", "HEAD^{commit}"]);
5533
- return head.ok && head.stdout.trim() ? "HEAD" : null;
5534
- }
5535
- async function resolveAllChangesBaseRef(workspaceRoot, preferredBaseBranch) {
5536
- const candidates = [
5537
- ...preferredBaseBranch ? [`origin/${preferredBaseBranch}`, preferredBaseBranch] : [],
5538
- "origin/main",
5539
- "main",
5540
- "origin/master",
5541
- "master",
5542
- "origin/HEAD"
5543
- ];
5544
- for (const candidate of candidates) {
5545
- const exists = await runGit(workspaceRoot, ["rev-parse", "--verify", `${candidate}^{commit}`]);
5546
- if (exists.ok) {
5547
- return candidate;
5548
- }
5549
- }
5550
- return null;
5551
- }
5552
- async function lineStatsForUntrackedFile(workspaceRoot, workspacePath) {
5553
- try {
5554
- const absolutePath = path__default.resolve(workspaceRoot, workspacePath);
5555
- const bytes = await readFile(absolutePath);
5556
- if (hasBinaryNul(bytes)) return true;
5557
- const text = decodeUtf8(bytes);
5558
- return { diff: [countTextLines(text), 0] };
5559
- } catch {
5560
- return true;
5561
- }
5562
- }
5563
- function parseDeletedPathsFromNameStatus(stdout) {
5564
- const deleted = /* @__PURE__ */ new Set();
5565
- const tokens = stdout.split("\0").filter(Boolean);
5566
- for (let index = 0; index < tokens.length; ) {
5567
- const status = tokens[index] ?? "";
5568
- index += 1;
5569
- if (status.startsWith("R") || status.startsWith("C")) {
5570
- const oldPath = tokens[index];
5571
- const newPath = tokens[index + 1];
5572
- index += 2;
5573
- if (oldPath) deleted.add(normalizeGitPath(oldPath));
5574
- if (newPath) deleted.delete(normalizeGitPath(newPath));
5575
- continue;
5576
- }
5577
- const filePath = tokens[index];
5578
- index += 1;
5579
- if (status.startsWith("D") && filePath) {
5580
- deleted.add(normalizeGitPath(filePath));
5581
- }
5582
- }
5583
- return deleted;
5584
- }
5585
- async function runGit(cwd, args) {
5586
- try {
5587
- const { stdout } = await execFileAsync("git", ["-C", cwd, ...args], {
5588
- maxBuffer: GIT_MAX_BUFFER_BYTES
5589
- });
5590
- return { ok: true, stdout };
5591
- } catch {
5592
- return { ok: false };
5593
- }
5594
- }
5595
- function buildEntriesFromGitFilePaths(options) {
5596
- const candidates = /* @__PURE__ */ new Map();
5597
- const conflicts = buildGitPathConflictIndex(options.relativeFilePaths);
5598
- for (const relativeFilePath of options.relativeFilePaths) {
5599
- const segments = relativeFilePath.split("/").filter((segment) => segment.length > 0);
5600
- const maxSegmentIndex = options.recursive ? segments.length - 1 : 0;
5601
- for (let index = 0; index <= maxSegmentIndex; index += 1) {
5602
- const segment = segments[index];
5603
- if (!segment) {
5604
- break;
5605
- }
5606
- const relativePath = segments.slice(0, index + 1).join("/");
5607
- const workspacePath = joinWorkspacePath(options.directoryWorkspacePath, relativePath);
5608
- if (conflicts.has(relativePath)) {
5609
- candidates.set(workspacePath, { kind: "skipped", reason: "path_conflict" });
5610
- break;
5611
- }
5612
- if (index < segments.length - 1) {
5613
- if (!candidates.has(workspacePath)) {
5614
- candidates.set(workspacePath, { kind: "lazy" });
5615
- }
5616
- } else {
5617
- candidates.set(workspacePath, true);
5618
- }
5619
- }
5620
- }
5621
- const sortedCandidates = [...candidates.entries()].sort(([leftPath], [rightPath]) => {
5622
- const depthOrder = pathDepth(leftPath) - pathDepth(rightPath);
5623
- return depthOrder === 0 ? leftPath.localeCompare(rightPath) : depthOrder;
5624
- });
5625
- return new Map(sortedCandidates.slice(0, Math.max(0, options.entryBudget)));
5626
- }
5627
- function buildGitPathConflictIndex(relativeFilePaths) {
5628
- const namesByDirectoryAndKey = /* @__PURE__ */ new Map();
5629
- for (const relativeFilePath of relativeFilePaths) {
5630
- const segments = relativeFilePath.split("/").filter((segment) => segment.length > 0);
5631
- for (let index = 0; index < segments.length; index += 1) {
5632
- const segment = segments[index];
5633
- if (!segment) {
5634
- continue;
5635
- }
5636
- const parent = segments.slice(0, index).join("/");
5637
- const comparisonKey = pathSegmentComparisonKey(segment);
5638
- let namesByKey = namesByDirectoryAndKey.get(parent);
5639
- if (!namesByKey) {
5640
- namesByKey = /* @__PURE__ */ new Map();
5641
- namesByDirectoryAndKey.set(parent, namesByKey);
5642
- }
5643
- let names = namesByKey.get(comparisonKey);
5644
- if (!names) {
5645
- names = /* @__PURE__ */ new Set();
5646
- namesByKey.set(comparisonKey, names);
5647
- }
5648
- names.add(segment);
5649
- }
5650
- }
5651
- const conflicts = /* @__PURE__ */ new Set();
5652
- for (const [parent, namesByKey] of namesByDirectoryAndKey) {
5653
- for (const names of namesByKey.values()) {
5654
- if (names.size <= 1) {
5655
- continue;
5656
- }
5657
- for (const name of names) {
5658
- conflicts.add(parent ? `${parent}/${name}` : name);
5659
- }
5660
- }
5661
- }
5662
- return conflicts;
5663
- }
5664
- function normalizeGitPath(filePath) {
5665
- return filePath.replace(/\\/gu, "/").normalize("NFC");
5666
- }
5667
- function isValidRelativeGitPath(filePath) {
5668
- return filePath.length > 0 && filePath !== "." && !path__default.isAbsolute(filePath) && !filePath.split("/").some((segment) => segment.length === 0 || segment === "..");
5669
- }
5670
- function joinWorkspacePath(parent, child) {
5671
- return (parent ? `${parent}/${child}` : child).normalize("NFC");
5672
- }
5673
- function pathSegmentComparisonKey(segment) {
5674
- return segment.normalize("NFC").toLocaleLowerCase("en-US");
5675
- }
5676
- function pathDepth(workspacePath) {
5677
- return workspacePath ? workspacePath.split("/").length : 0;
5678
- }
5679
- function hasBinaryNul(bytes) {
5680
- const limit = Math.min(bytes.byteLength, 8 * 1024);
5681
- for (let index = 0; index < limit; index += 1) {
5682
- if (bytes[index] === 0) {
5683
- return true;
5684
- }
5685
- }
5686
- return false;
5687
- }
5688
- function decodeUtf8(bytes) {
5689
- return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
5690
- }
5691
- async function closeDirectoryQuietly(directory) {
5692
- try {
5693
- await directory.close();
5694
- } catch {
5695
- }
5696
- }
5697
4757
  export {
5698
4758
  $constructor as $,
5699
- deriveCodeCollabV2ContentKeyId as A,
5700
- deriveCodeCollabV2ContentKeyBytes as B,
5701
- CodeCollabV2OpenTextRequestSchema as C,
5702
- CodeCollabV2ErrorCodeSchema as D,
5703
- _null as E,
5704
- CODE_COLLAB_V2_TEXT_LIMITS as F,
5705
- computeAllChanges as G,
5706
- buildCodeCollabFileIndexState as H,
5707
- codeCollabFileIndexStatesEqual as I,
5708
- scanGitDirectoryEntries as J,
5709
- closeDirectoryQuietly as K,
5710
- writeCodeCollabFileIndexToFlock as L,
5711
- normalizeParams as M,
4759
+ toJSONSchema as A,
4760
+ ZodOptional as B,
4761
+ int as C,
4762
+ url as D,
4763
+ tuple as E,
5712
4764
  NEVER as N,
5713
- $ZodObject as O,
5714
- defineLazy as P,
5715
- $ZodType as Q,
5716
- parse$1 as R,
5717
- safeParse$1 as S,
5718
- parseAsync$1 as T,
5719
- safeParseAsync$1 as U,
5720
- clone as V,
5721
- looseObject as W,
5722
- optional as X,
5723
- datetime as Y,
5724
4765
  ZodError as Z,
5725
4766
  _enum as _,
5726
4767
  array as a,
5727
- custom as a0,
5728
- toJSONSchema as a1,
5729
- ZodOptional as a2,
5730
- joinWorkspacePath as a3,
5731
- isInsideGitWorktree as a4,
5732
- pathSegmentComparisonKey as a5,
5733
4768
  boolean as b,
5734
4769
  unknown as c,
5735
4770
  discriminatedUnion as d,
5736
- CodeCollabV2RefreshTextRequestSchema as e,
5737
- CodeCollabV2SaveTextRequestSchema as f,
5738
- CodeCollabV2OpenCurrentDiffRequestSchema as g,
5739
- CodeCollabV2OpenTurnDiffRequestSchema as h,
4771
+ _null as e,
4772
+ normalizeParams as f,
4773
+ $ZodObject as g,
4774
+ defineLazy as h,
5740
4775
  intersection as i,
5741
- CodeCollabV2InitDirectoryRequestSchema as j,
5742
- CodeCollabV2OpenTextOkSchema as k,
4776
+ $ZodType as j,
4777
+ parse$1 as k,
5743
4778
  literal as l,
5744
- CodeCollabV2RefreshTextResponseSchema as m,
4779
+ safeParse$1 as m,
5745
4780
  number as n,
5746
4781
  object as o,
5747
4782
  preprocess as p,
5748
- CodeCollabV2SaveTextResponseSchema as q,
4783
+ parseAsync$1 as q,
5749
4784
  record as r,
5750
4785
  string as s,
5751
- CodeCollabV2OpenCurrentDiffResponseSchema as t,
4786
+ safeParseAsync$1 as t,
5752
4787
  union as u,
5753
- CodeCollabV2OpenTurnDiffResponseSchema as v,
5754
- CodeCollabV2InitDirectoryOkSchema as w,
5755
- CodeCollabV2LspUnsupportedSchema as x,
5756
- CodeCollabV2ErrorSchema as y,
5757
- CodeCollabV2RpcContentEnvelopeSchema as z
4788
+ clone as v,
4789
+ looseObject as w,
4790
+ optional as x,
4791
+ datetime as y,
4792
+ custom as z
5758
4793
  };