agentic-diff 0.1.7 → 0.1.8

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.
package/dist/cli.js CHANGED
@@ -4031,11 +4031,11 @@ function effortOption(agent) {
4031
4031
  function findValue(option, word) {
4032
4032
  const wanted = normalize(word);
4033
4033
  if (!option || wanted === "") return void 0;
4034
- const names = (value) => [normalize(value.id), normalize(value.name)];
4035
- const exact = option.values.find((value) => names(value).includes(wanted));
4034
+ const names2 = (value) => [normalize(value.id), normalize(value.name)];
4035
+ const exact = option.values.find((value) => names2(value).includes(wanted));
4036
4036
  if (exact) return exact;
4037
4037
  for (const test of [(name) => name.startsWith(wanted), (name) => name.includes(wanted)]) {
4038
- const matches = option.values.filter((value) => names(value).some(test));
4038
+ const matches = option.values.filter((value) => names2(value).some(test));
4039
4039
  if (matches.length === 1) return matches[0];
4040
4040
  }
4041
4041
  return void 0;
@@ -4098,20 +4098,32 @@ function settlePending(pending, options, agentName) {
4098
4098
  }
4099
4099
 
4100
4100
  // packages/core/src/shared/pullSearch.ts
4101
+ var AUTHOR = /^(?:@|author:)([A-Za-z0-9][A-Za-z0-9_-]{0,63}(?:\[bot\])?)$/i;
4102
+ var BARE_NUMBER = /^\d{1,9}$/;
4101
4103
  function parsePullSearch(text) {
4102
4104
  const search = { words: [] };
4103
4105
  const tokens = text.trim().split(/\s+/).filter((token) => token !== "");
4104
4106
  for (const token of tokens) {
4105
- const author = /^(?:@|author:)([A-Za-z0-9][A-Za-z0-9-]{0,38}(?:\[bot\])?)$/i.exec(token);
4106
- const number3 = /^#?(\d{1,9})$/.exec(token);
4107
+ const author = AUTHOR.exec(token);
4108
+ const number3 = /^#(\d{1,9})$/.exec(token);
4107
4109
  if (author && search.author === void 0) search.author = author[1];
4108
- else if (number3 && search.number === void 0 && Number(number3[1]) > 0) {
4109
- search.number = Number(number3[1]);
4110
- if (!token.startsWith("#")) search.words.push(token);
4111
- } else if (token !== "@" && token !== "#") search.words.push(token);
4110
+ else if (number3 && search.number === void 0 && Number(number3[1]) > 0) search.number = Number(number3[1]);
4111
+ else if (token !== "@" && token !== "#") search.words.push(token);
4112
4112
  }
4113
+ const [only] = tokens;
4114
+ if (tokens.length === 1 && only !== void 0 && BARE_NUMBER.test(only) && Number(only) > 0) search.number = Number(only);
4113
4115
  return search;
4114
4116
  }
4117
+ function isBareNumber(search) {
4118
+ const [only] = search.words;
4119
+ return search.number !== void 0 && search.author === void 0 && search.words.length === 1 && only !== void 0 && BARE_NUMBER.test(only) && Number(only) === search.number;
4120
+ }
4121
+ var loginKey = (login) => login.toLowerCase().replace(/\[bot\]$/, "");
4122
+ function fitsNumbered(pull, search) {
4123
+ if (search.number !== pull.number) return false;
4124
+ if (search.author !== void 0 && loginKey(pull.author ?? "") !== loginKey(search.author)) return false;
4125
+ return isBareNumber(search) || search.words.every((word) => pull.title.toLowerCase().includes(word.toLowerCase()));
4126
+ }
4115
4127
 
4116
4128
  // node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/base.js
4117
4129
  var Diff = class {
@@ -6677,7 +6689,7 @@ function remoteOrder(remotes, preferred) {
6677
6689
  const rank = (remote) => remote.name === preferred ? 0 : remote.name === "origin" ? 1 : remote.name === "upstream" ? 2 : 3;
6678
6690
  return [...remotes].sort((a, b) => rank(a) - rank(b));
6679
6691
  }
6680
- var publicPull = ({ remote: _remote, nodeId: _nodeId, ...pull }) => pull;
6692
+ var publicPull = ({ nodeId: _nodeId, ...pull }) => pull;
6681
6693
  async function importPull(context, number3, options = {}) {
6682
6694
  const { repo, pulls } = context;
6683
6695
  if (!Number.isInteger(number3) || number3 < 1) throw new AppError("invalid_request", "Not a pull request number");
@@ -6688,6 +6700,7 @@ async function importPull(context, number3, options = {}) {
6688
6700
  throw new AppError("invalid_request", `This repository has no remote named ${JSON.stringify(options.remote)}`);
6689
6701
  }
6690
6702
  const previous = pulls.get(number3);
6703
+ const previousBase = previous ? await resolveCommit(repo, refs.base).catch(() => void 0) : void 0;
6691
6704
  let remote;
6692
6705
  for (const candidate of remoteOrder(remotes, options.remote ?? previous?.remote)) {
6693
6706
  if (await fetchInto(repo, candidate.name, `refs/pull/${number3}/head`, refs.head)) {
@@ -6726,6 +6739,12 @@ async function importPull(context, number3, options = {}) {
6726
6739
  baseRef = baseBranch ?? (await listRefs(repo)).defaultBranch?.replace(/^[^/]+\//, "") ?? "the default branch";
6727
6740
  }
6728
6741
  if (!baseRef) throw new AppError("pull_base_not_found", `Could not fetch the branch pull request #${number3} is to be merged into.`, 404);
6742
+ const settled = fetched ? fetched.pull.state !== "OPEN" : kept !== void 0 && kept.state !== "open";
6743
+ const settledBase = settled ? fetched ? fetched.pull.baseRefOid : previousBase : void 0;
6744
+ if (settledBase !== void 0 && await hasCommit(repo, settledBase)) {
6745
+ await runGit(["update-ref", refs.base, settledBase], { cwd: repo.root });
6746
+ }
6747
+ const alreadyIn = !fetched && !kept && (await runGit(["merge-base", "--is-ancestor", headOid2, refs.base], { cwd: repo.root, allowExitCodes: [1, 128] })).exitCode === 0;
6729
6748
  const base = { number: number3, remote: remote.name, headOid: headOid2, baseRef, importedAt: (/* @__PURE__ */ new Date()).toISOString() };
6730
6749
  let stored;
6731
6750
  if (fetched) {
@@ -6754,7 +6773,7 @@ async function importPull(context, number3, options = {}) {
6754
6773
  body: "",
6755
6774
  state: "unknown",
6756
6775
  draft: false,
6757
- notice: `${notice ?? ""} The commits are compared with ${baseRef}; the real base branch of the pull request is not known without GitHub.`.trim()
6776
+ notice: alreadyIn ? `${notice ?? ""} The commits of this pull request are already part of ${baseRef}, so there is nothing left to compare: it seems to be merged. What it changed can only be shown with GitHub's help.`.trim() : `${notice ?? ""} The commits are compared with ${baseRef}; the real base branch of the pull request is not known without GitHub.`.trim()
6758
6777
  });
6759
6778
  }
6760
6779
  return stored;
@@ -7014,12 +7033,12 @@ async function prepare(repo, comparison, github) {
7014
7033
  const [base, head] = await Promise.all([branchOf(repo, comparison.base.label, remotes), branchOf(repo, comparison.head.label, remotes)]);
7015
7034
  if (!head) return blocked("The compare side is not a branch. A pull request is made from a branch.");
7016
7035
  if (!base) return blocked("The base side is not a branch. A pull request is merged into a branch.");
7017
- const names = { base: base.name, head: head.name };
7018
- if (base.name === head.name) return blocked("The two sides are the same branch.", names);
7036
+ const names2 = { base: base.name, head: head.name };
7037
+ if (base.name === head.name) return blocked("The two sides are the same branch.", names2);
7019
7038
  const remote = remotes.find((candidate) => candidate.name === (head.remote ?? base.remote ?? "origin")) ?? remotes[0];
7020
7039
  const target = remote ? githubRepoOf(remote.url) : void 0;
7021
- if (!remote || !target) return blocked("This repository has no GitHub remote to open a pull request on.", names);
7022
- const where = { ...names, remote: remote.name, repository: `${target.owner}/${target.name}` };
7040
+ if (!remote || !target) return blocked("This repository has no GitHub remote to open a pull request on.", names2);
7041
+ const where = { ...names2, remote: remote.name, repository: `${target.owner}/${target.name}` };
7023
7042
  const connection = await connectGitHub(target.host, github);
7024
7043
  if (!connection.client) return blocked(connection.reason ?? "GitHub is not available.", where);
7025
7044
  const heads = await remoteHeads(repo, remote.name, [head.name, base.name]);
@@ -7081,17 +7100,35 @@ async function createPull(repo, comparison, input, github) {
7081
7100
 
7082
7101
  // packages/core/src/github/search.ts
7083
7102
  var MAX_PULLS = 30;
7103
+ var MAX_REPOSITORIES = 4;
7084
7104
  var FIELDS = "number title state isDraft url updatedAt author { login } baseRefName headRefName repository { nameWithOwner }";
7105
+ var LIST_QUERY = `
7106
+ query PullList($owner: String!, $name: String!, $states: [PullRequestState!], $first: Int!) {
7107
+ repository(owner: $owner, name: $name) {
7108
+ nameWithOwner
7109
+ pullRequests(states: $states, first: $first, orderBy: { field: UPDATED_AT, direction: DESC }) { totalCount nodes { ${FIELDS} } }
7110
+ }
7111
+ }`;
7112
+ var NAME_QUERY = `
7113
+ query RepositoryName($owner: String!, $name: String!) {
7114
+ repository(owner: $owner, name: $name) { nameWithOwner }
7115
+ }`;
7085
7116
  var SEARCH_QUERY = `
7086
7117
  query PullSearch($query: String!, $first: Int!) {
7087
- search(query: $query, type: ISSUE, first: $first) { nodes { ... on PullRequest { ${FIELDS} } } }
7118
+ search(query: $query, type: ISSUE, first: $first) { issueCount nodes { ... on PullRequest { ${FIELDS} } } }
7088
7119
  }`;
7089
7120
  var NUMBER_QUERY = `
7090
7121
  query PullNumber($owner: String!, $name: String!, $number: Int!) {
7091
7122
  repository(owner: $owner, name: $name) { pullRequest(number: $number) { ${FIELDS} } }
7092
7123
  }`;
7093
7124
  var STATES2 = { OPEN: "open", CLOSED: "closed", MERGED: "merged" };
7094
- var summary = (node2) => ({
7125
+ var BY_NUMBER = "A pull request can still be opened by typing its number.";
7126
+ var isPull = (node2) => typeof node2?.number === "number";
7127
+ var defined = (value) => value !== void 0;
7128
+ var sameName = (a, b) => b !== void 0 && a.toLowerCase() === b.toLowerCase();
7129
+ var pullKey = (pull) => `${pull.repository.toLowerCase()}#${pull.number}`;
7130
+ var byUpdate = (a, b) => b.updatedAt.localeCompare(a.updatedAt) || b.number - a.number;
7131
+ var summary = (node2, target) => ({
7095
7132
  number: node2.number,
7096
7133
  title: node2.title,
7097
7134
  state: STATES2[node2.state] ?? "closed",
@@ -7100,40 +7137,158 @@ var summary = (node2) => ({
7100
7137
  baseRef: node2.baseRefName,
7101
7138
  headRef: node2.headRefName,
7102
7139
  updatedAt: node2.updatedAt,
7103
- url: node2.url
7104
- });
7105
- function pullSearchQuery(repository, text, includeClosed) {
7106
- const search = parsePullSearch(text);
7107
- const parts = [`repo:${repository}`, "is:pr", "sort:updated-desc"];
7140
+ url: node2.url,
7141
+ repository: target.repository,
7142
+ remote: target.remote
7143
+ });
7144
+ var NAME_TTL_MS = 10 * 6e4;
7145
+ var MISSING_TTL_MS = 6e4;
7146
+ var names = /* @__PURE__ */ new Map();
7147
+ var nameKey = (target) => `${target.host}/${target.owner}/${target.name}`;
7148
+ function remembered(target) {
7149
+ const known = names.get(nameKey(target));
7150
+ if (known && Date.now() - known.at > (known.repository === void 0 ? MISSING_TTL_MS : NAME_TTL_MS)) {
7151
+ names.delete(nameKey(target));
7152
+ return void 0;
7153
+ }
7154
+ return known;
7155
+ }
7156
+ function remember(target, nameWithOwner) {
7157
+ const repository = nameWithOwner !== void 0 && /^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/.test(nameWithOwner) ? nameWithOwner : void 0;
7158
+ names.set(nameKey(target), { at: Date.now(), repository });
7159
+ return repository;
7160
+ }
7161
+ async function ask(question) {
7162
+ try {
7163
+ return await question();
7164
+ } catch (error2) {
7165
+ if (!(error2 instanceof AppError) || error2.code !== "github_not_found") throw error2;
7166
+ return void 0;
7167
+ }
7168
+ }
7169
+ async function githubTargets(repo) {
7170
+ const targets = [];
7171
+ const seen = /* @__PURE__ */ new Set();
7172
+ for (const remote of remoteOrder(await repoRemotes(repo), void 0)) {
7173
+ const parsed = githubRepoOf(remote.url);
7174
+ if (!parsed) continue;
7175
+ const target = { remote: remote.name, ...parsed };
7176
+ if (seen.has(nameKey(target))) continue;
7177
+ seen.add(nameKey(target));
7178
+ targets.push(target);
7179
+ }
7180
+ return targets.slice(0, MAX_REPOSITORIES);
7181
+ }
7182
+ function distinct(reached) {
7183
+ return reached.filter((target, index) => reached.findIndex((other) => sameName(other.repository, target.repository) && other.host === target.host) === index);
7184
+ }
7185
+ async function reach(connected) {
7186
+ const resolved = await Promise.all(
7187
+ connected.map(async (target) => {
7188
+ let known = remembered(target);
7189
+ if (!known) {
7190
+ const data = await ask(() => target.client.graphql("RepositoryName", NAME_QUERY, { owner: target.owner, name: target.name }));
7191
+ known = { repository: remember(target, data?.repository?.nameWithOwner) };
7192
+ }
7193
+ return known.repository === void 0 ? void 0 : { ...target, repository: known.repository };
7194
+ })
7195
+ );
7196
+ return distinct(resolved.filter(defined));
7197
+ }
7198
+ var notFound = (connected) => {
7199
+ const first = connected[0];
7200
+ return {
7201
+ pulls: [],
7202
+ repositories: [],
7203
+ unavailable: `${first.owner}/${first.name} was not found on ${first.host}, or the account the GitHub CLI is signed in with has no access to it. ${BY_NUMBER}`
7204
+ };
7205
+ };
7206
+ function pullSearchQueries(repositories, search, includeClosed) {
7207
+ const parts = [...repositories.map((repository) => `repo:${repository}`), "is:pr", "sort:updated-desc"];
7108
7208
  if (!includeClosed) parts.push("is:open");
7109
- if (search.author !== void 0) parts.push(`author:${search.author}`);
7110
7209
  const words = search.words.map((word) => word.replace(/["\\]/g, "")).filter((word) => word !== "");
7111
- if (words.length > 0) parts.push("in:title", ...words.map((word) => `"${word}"`));
7112
- return parts.join(" ");
7210
+ const text = words.length > 0 ? ["in:title", ...words.map((word) => `"${word}"`)] : [];
7211
+ if (search.author === void 0) return [[...parts, ...text].join(" ")];
7212
+ const isApp = /\[bot\]$/i.test(search.author);
7213
+ const login = search.author.replace(/\[bot\]$/i, "");
7214
+ return (isApp ? [`app/${login}`] : [login, `app/${login}`]).map((author) => [...parts, `author:${author}`, ...text].join(" "));
7215
+ }
7216
+ async function listPulls(connected, includeClosed) {
7217
+ const states = includeClosed ? ["OPEN", "CLOSED", "MERGED"] : ["OPEN"];
7218
+ const answers = await Promise.all(
7219
+ connected.map(async (target) => {
7220
+ const data = await ask(() => target.client.graphql("PullList", LIST_QUERY, { owner: target.owner, name: target.name, states, first: MAX_PULLS }));
7221
+ const repository = remember(target, data?.repository?.nameWithOwner);
7222
+ if (!data?.repository || repository === void 0) return void 0;
7223
+ return { target: { ...target, repository }, total: data.repository.pullRequests.totalCount, nodes: data.repository.pullRequests.nodes.filter(isPull) };
7224
+ })
7225
+ );
7226
+ const found = answers.filter(defined);
7227
+ const kept = distinct(found.map((answer) => answer.target));
7228
+ if (kept.length === 0) return notFound(connected);
7229
+ const listed = found.filter((answer) => kept.includes(answer.target));
7230
+ const pulls = listed.flatMap((answer) => answer.nodes.map((node2) => summary(node2, answer.target))).sort(byUpdate).slice(0, MAX_PULLS);
7231
+ const total = listed.reduce((sum, answer) => sum + answer.total, 0);
7232
+ return { pulls, repositories: kept.map((target) => target.repository), ...total > pulls.length ? { more: true } : {} };
7233
+ }
7234
+ async function pullByNumber(target, number3) {
7235
+ const [owner, name] = target.repository.split("/");
7236
+ const data = await ask(() => target.client.graphql("PullNumber", NUMBER_QUERY, { owner, name, number: number3 }));
7237
+ const node2 = data?.repository?.pullRequest;
7238
+ return node2 && isPull(node2) ? summary(node2, target) : void 0;
7239
+ }
7240
+ async function searchIn(reached, search, includeClosed) {
7241
+ const hosts = [...new Set(reached.map((target) => target.host))];
7242
+ const answers = await Promise.all(
7243
+ hosts.flatMap((host) => {
7244
+ const targets = reached.filter((target) => target.host === host);
7245
+ const { client: client2 } = targets[0];
7246
+ const repositories = targets.map((target) => target.repository);
7247
+ return pullSearchQueries(repositories, search, includeClosed).map(async (query) => {
7248
+ const data = await client2.graphql("PullSearch", SEARCH_QUERY, { query, first: MAX_PULLS });
7249
+ const pulls2 = data.search.nodes.filter(isPull).flatMap((node2) => {
7250
+ const target = targets.find((candidate) => sameName(candidate.repository, node2.repository?.nameWithOwner));
7251
+ return target ? [summary(node2, target)] : [];
7252
+ });
7253
+ return { pulls: pulls2, more: data.search.issueCount > data.search.nodes.length };
7254
+ });
7255
+ })
7256
+ );
7257
+ const pulls = /* @__PURE__ */ new Map();
7258
+ for (const pull of answers.flatMap((answer) => answer.pulls)) if (!pulls.has(pullKey(pull))) pulls.set(pullKey(pull), pull);
7259
+ return { pulls: [...pulls.values()].sort(byUpdate).slice(0, MAX_PULLS), more: pulls.size > MAX_PULLS || answers.some((answer) => answer.more) };
7260
+ }
7261
+ async function findPulls(connected, search, includeClosed) {
7262
+ const reached = await reach(connected);
7263
+ if (reached.length === 0) return notFound(connected);
7264
+ const { number: number3 } = search;
7265
+ const numbered = number3 === void 0 ? Promise.resolve([]) : Promise.all(reached.map((target) => pullByNumber(target, number3))).then((pulls) => pulls.filter(defined).filter((pull) => fitsNumbered(pull, search)));
7266
+ const searched = number3 === void 0 || isBareNumber(search) ? searchIn(reached, search, includeClosed) : Promise.resolve({ pulls: [], more: false });
7267
+ const [exact, found] = await Promise.all([numbered, searched]);
7268
+ const first = new Set(exact.map(pullKey));
7269
+ return {
7270
+ pulls: [...exact, ...found.pulls.filter((pull) => !first.has(pullKey(pull)))],
7271
+ repositories: reached.map((target) => target.repository),
7272
+ ...found.more ? { more: true } : {}
7273
+ };
7113
7274
  }
7114
7275
  async function searchPulls(repo, input, github) {
7115
7276
  if (input.query.length > 200) throw new AppError("invalid_request", "That is too long to search for");
7116
- const remote = remoteOrder(await repoRemotes(repo), void 0).find((candidate) => githubRepoOf(candidate.url));
7117
- const target = remote ? githubRepoOf(remote.url) : void 0;
7118
- if (!target) return { pulls: [], unavailable: "This repository has no GitHub remote to list pull requests of." };
7119
- const repository = `${target.owner}/${target.name}`;
7120
- const connection = await connectGitHub(target.host, github);
7121
- if (!connection.client) return { pulls: [], repository, unavailable: connection.reason ?? "GitHub is not available." };
7122
- const client2 = connection.client;
7123
- const search = parsePullSearch(input.query);
7124
- const byNumber = search.number === void 0 ? Promise.resolve(void 0) : client2.graphql("PullNumber", NUMBER_QUERY, { owner: target.owner, name: target.name, number: search.number }).then((data) => data.repository?.pullRequest ?? void 0).catch((error2) => {
7125
- if (error2 instanceof AppError && error2.code === "github_not_found") return void 0;
7126
- throw error2;
7277
+ const targets = await githubTargets(repo);
7278
+ if (targets.length === 0) return { pulls: [], repositories: [], unavailable: "This repository has no remote on GitHub, so there are no pull requests to list." };
7279
+ const hosts = [...new Set(targets.map((target) => target.host))];
7280
+ const connections = new Map(await Promise.all(hosts.map(async (host) => [host, await connectGitHub(host, github)])));
7281
+ const connected = targets.flatMap((target) => {
7282
+ const client2 = connections.get(target.host)?.client;
7283
+ return client2 ? [{ ...target, client: client2 }] : [];
7127
7284
  });
7128
- const numberOnly = search.number !== void 0 && search.words.length === 0 && search.author === void 0;
7129
- const found = numberOnly ? Promise.resolve([]) : client2.graphql("PullSearch", SEARCH_QUERY, { query: pullSearchQuery(repository, input.query, input.includeClosed), first: MAX_PULLS }).then((data) => data.search.nodes.filter((node2) => typeof node2?.number === "number"));
7130
- const [exact, nodes] = await Promise.all([byNumber, found]);
7131
- const pulls = nodes.filter((node2) => !node2.repository || node2.repository.nameWithOwner.toLowerCase() === repository.toLowerCase()).map(summary);
7132
- if (exact && typeof exact.number === "number") {
7133
- const first = summary(exact);
7134
- return { repository, pulls: [first, ...pulls.filter((pull) => pull.number !== first.number)] };
7285
+ if (connected.length === 0) {
7286
+ const reason = connections.get(targets[0].host)?.reason ?? "GitHub is not available.";
7287
+ return { pulls: [], repositories: [], unavailable: `${reason} ${BY_NUMBER}` };
7135
7288
  }
7136
- return { repository, pulls };
7289
+ const search = parsePullSearch(input.query);
7290
+ const nothingTyped = search.number === void 0 && search.author === void 0 && search.words.length === 0;
7291
+ return nothingTyped ? listPulls(connected, input.includeClosed) : findPulls(connected, search, input.includeClosed);
7137
7292
  }
7138
7293
 
7139
7294
  // packages/core/src/viewed.ts
@@ -7282,17 +7437,17 @@ function save(home, file) {
7282
7437
  writeFileAtomic(optionsFile(home), `${JSON.stringify(file, null, 2)}
7283
7438
  `);
7284
7439
  }
7285
- function validChoices(remembered) {
7440
+ function validChoices(remembered2) {
7286
7441
  const valid = {};
7287
- for (const [id, value] of Object.entries(remembered?.chosen ?? {})) {
7288
- if (remembered?.options.find((option) => option.id === id)?.values.some((candidate) => candidate.id === value)) valid[id] = value;
7442
+ for (const [id, value] of Object.entries(remembered2?.chosen ?? {})) {
7443
+ if (remembered2?.options.find((option) => option.id === id)?.values.some((candidate) => candidate.id === value)) valid[id] = value;
7289
7444
  }
7290
7445
  return valid;
7291
7446
  }
7292
7447
  function agentOptions(home, agentId) {
7293
- const remembered = load2(home)[agentId];
7294
- const chosen = validChoices(remembered);
7295
- return (remembered?.options ?? []).map((option) => ({ ...option, chosen: chosen[option.id] }));
7448
+ const remembered2 = load2(home)[agentId];
7449
+ const chosen = validChoices(remembered2);
7450
+ return (remembered2?.options ?? []).map((option) => ({ ...option, chosen: chosen[option.id] }));
7296
7451
  }
7297
7452
  function chosenOptions(home, agentId) {
7298
7453
  return validChoices(load2(home)[agentId]);
@@ -7307,14 +7462,14 @@ function rememberAgentOptions(home, agentId, options) {
7307
7462
  }
7308
7463
  function chooseAgentOption(home, agentId, optionId, value) {
7309
7464
  const file = load2(home);
7310
- const remembered = file[agentId];
7311
- const option = remembered?.options.find((candidate) => candidate.id === optionId);
7312
- if (!remembered || !option) throw new AppError("option_not_found", "This agent has not offered that option", 404);
7465
+ const remembered2 = file[agentId];
7466
+ const option = remembered2?.options.find((candidate) => candidate.id === optionId);
7467
+ if (!remembered2 || !option) throw new AppError("option_not_found", "This agent has not offered that option", 404);
7313
7468
  if (value === void 0) {
7314
- delete remembered.chosen[optionId];
7469
+ delete remembered2.chosen[optionId];
7315
7470
  } else {
7316
7471
  if (!option.values.some((candidate) => candidate.id === value)) throw new AppError("invalid_request", "This agent does not offer that value");
7317
- remembered.chosen[optionId] = value;
7472
+ remembered2.chosen[optionId] = value;
7318
7473
  }
7319
7474
  save(home, file);
7320
7475
  return agentOptions(home, agentId);
@@ -13982,12 +14137,12 @@ function rewriteKeyNames(ctx) {
13982
14137
  const rewrites = /* @__PURE__ */ new Map();
13983
14138
  for (const record2 of pendingRecords.get(ctx) ?? []) {
13984
14139
  const seen = ctx.seen.get(record2);
13985
- const names = (seen?.def ?? seen?.schema)?.propertyNames;
13986
- if (!names || names === true || rewrites.has(names))
14140
+ const names2 = (seen?.def ?? seen?.schema)?.propertyNames;
14141
+ if (!names2 || names2 === true || rewrites.has(names2))
13987
14142
  continue;
13988
- const rewritten = stringifyKeyNames(bySchema, names, /* @__PURE__ */ new Set());
13989
- if (rewritten !== names)
13990
- rewrites.set(names, rewritten);
14143
+ const rewritten = stringifyKeyNames(bySchema, names2, /* @__PURE__ */ new Set());
14144
+ if (rewritten !== names2)
14145
+ rewrites.set(names2, rewritten);
13991
14146
  }
13992
14147
  if (!rewrites.size)
13993
14148
  return;
@@ -17646,7 +17801,7 @@ async function runPrompt(options) {
17646
17801
  let text = "";
17647
17802
  const tools = /* @__PURE__ */ new Map();
17648
17803
  const pendingAsks = /* @__PURE__ */ new Set();
17649
- const remember = (update) => {
17804
+ const remember2 = (update) => {
17650
17805
  const known = tools.get(update.toolCallId) ?? { kind: "other", title: "Tool call", edits: [] };
17651
17806
  if (update.kind) known.kind = toolKind(update.kind);
17652
17807
  if (update.title) known.title = update.title;
@@ -17677,7 +17832,7 @@ async function runPrompt(options) {
17677
17832
  case "tool_call":
17678
17833
  case "tool_call_update": {
17679
17834
  const id = String(event.toolCallId);
17680
- const known = remember({ toolCallId: id, kind: event.kind, title: event.title, name: event.name, content: event.content });
17835
+ const known = remember2({ toolCallId: id, kind: event.kind, title: event.title, name: event.name, content: event.content });
17681
17836
  onEvent({ t: "tool", id, kind: known.kind, title: known.title, status: typeof event.status === "string" ? event.status : "pending" });
17682
17837
  break;
17683
17838
  }
@@ -17712,7 +17867,7 @@ async function runPrompt(options) {
17712
17867
  };
17713
17868
  const onPermission = async (request) => {
17714
17869
  const call = request.toolCall;
17715
- const known = remember({ toolCallId: call.toolCallId, kind: call.kind, title: call.title, name: call.name, content: call.content });
17870
+ const known = remember2({ toolCallId: call.toolCallId, kind: call.kind, title: call.title, name: call.name, content: call.content });
17716
17871
  const pick2 = (...kinds) => {
17717
17872
  const option = kinds.map((kind) => request.options.find((candidate) => candidate.kind === kind)).find(Boolean);
17718
17873
  return option ? { outcome: { outcome: "selected", optionId: option.optionId } } : { outcome: { outcome: "cancelled" } };
@@ -18807,13 +18962,13 @@ var AgentRuns = class {
18807
18962
  */
18808
18963
  removeLeftovers() {
18809
18964
  const root = join13(this.options.home, "snapshots");
18810
- let names;
18965
+ let names2;
18811
18966
  try {
18812
- names = readdirSync2(root);
18967
+ names2 = readdirSync2(root);
18813
18968
  } catch {
18814
18969
  return;
18815
18970
  }
18816
- for (const name of names) {
18971
+ for (const name of names2) {
18817
18972
  if (!this.runs.has(name)) rmSync4(join13(root, name), { recursive: true, force: true });
18818
18973
  }
18819
18974
  }
@@ -18931,7 +19086,7 @@ ${request.message}`}` : request.message);
18931
19086
  onToolContext: (context) => {
18932
19087
  run.tools = context;
18933
19088
  },
18934
- askUser: (ask) => new Promise((resolve3) => run.asks.set(ask.id, resolve3)),
19089
+ askUser: (ask2) => new Promise((resolve3) => run.asks.set(ask2.id, resolve3)),
18935
19090
  onEvent: (event) => this.apply(run, event),
18936
19091
  // What the agent offers to choose from is kept for the page, which shows it from the next time on.
18937
19092
  onSessionOptions: (options) => rememberAgentOptions(home, agent.id, options),
@@ -20010,7 +20165,7 @@ import { dirname as dirname7, join as join15 } from "node:path";
20010
20165
  import { fileURLToPath } from "node:url";
20011
20166
 
20012
20167
  // packages/cli/src/version.ts
20013
- var VERSION = true ? "0.1.7" : "0.0.0-dev";
20168
+ var VERSION = true ? "0.1.8" : "0.0.0-dev";
20014
20169
 
20015
20170
  // packages/cli/src/daemon.ts
20016
20171
  var CLI_FILE = fileURLToPath(import.meta.url);
@@ -1,4 +1,4 @@
1
- import{a as e,c as t,d as n,f as r,h as i,i as a,l as o,m as s,n as c,o as l,p as u,r as d,s as f,t as p,u as m}from"./index-d4NXhSxY.js";var h=[],g=[];(()=>{let e=`lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5`.split(`,`).map(e=>e?parseInt(e,36):1);for(let t=0,n=0;t<e.length;t++)(t%2?g:h).push(n+=e[t])})();function _(e){if(e<768)return!1;for(let t=0,n=h.length;;){let r=t+n>>1;if(e<h[r])n=r;else if(e>=g[r])t=r+1;else return!0;if(t==n)return!1}}function v(e){return e>=127462&&e<=127487}var y=8205;function b(e,t,n=!0,r=!0){return(n?x:S)(e,t,r)}function x(e,t,n){if(t==e.length)return t;t&&te(e.charCodeAt(t))&&ne(e.charCodeAt(t-1))&&t--;let r=ee(e,t);for(t+=re(r);t<e.length;){let i=ee(e,t);if(r==y||i==y||n&&_(i))t+=re(i),r=i;else if(v(i)){let n=0,r=t-2;for(;r>=0&&v(ee(e,r));)n++,r-=2;if(n%2==0)break;t+=2}else break}return t}function S(e,t,n){for(;t>1;){let r=x(e,t-2,n);if(r<t)return r;t--}return 0}function ee(e,t){let n=e.charCodeAt(t);if(!ne(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return te(r)?(n-55296<<10)+(r-56320)+65536:n}function te(e){return e>=56320&&e<57344}function ne(e){return e>=55296&&e<56320}function re(e){return e<65536?1:2}var C=class e{lineAt(e){if(e<0||e>this.length)throw RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=fe(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),ie.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=fe(this,e,t);let n=[];return this.decompose(e,t,n,0),ie.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=new ce(this),i=new ce(e);for(let e=t,a=t;;){if(r.next(e),i.next(e),e=0,r.lineBreak!=i.lineBreak||r.done!=i.done||r.value!=i.value)return!1;if(a+=r.value.length,r.done||a>=n)return!0}}iter(e=1){return new ce(this,e)}iterRange(e,t=this.length){return new le(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t??=this.lines+1;let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new ue(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(t){if(t.length==0)throw RangeError(`A document must have at least one line`);return t.length==1&&!t[0]?e.empty:t.length<=32?new w(t):ie.from(w.split(t,[]))}},w=class e extends C{constructor(e,t=ae(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.text[i],o=r+a.length;if((t?n:o)>=e)return new de(r,o,n,a);r=o+1,n++}}decompose(t,n,r,i){let a=t<=0&&n>=this.length?this:new e(se(this.text,t,n),Math.min(n,this.length)-Math.max(0,t));if(i&1){let t=r.pop(),n=oe(a.text,t.text.slice(),0,a.length);if(n.length<=32)r.push(new e(n,t.length+a.length));else{let t=n.length>>1;r.push(new e(n.slice(0,t)),new e(n.slice(t)))}}else r.push(a)}replace(t,n,r){if(!(r instanceof e))return super.replace(t,n,r);[t,n]=fe(this,t,n);let i=oe(this.text,oe(r.text,se(this.text,0,t)),n),a=this.length+r.length-(n-t);return i.length<=32?new e(i,a):ie.from(e.split(i,[]),a)}sliceString(e,t=this.length,n=`
1
+ import{a as e,c as t,d as n,f as r,h as i,i as a,l as o,m as s,n as c,o as l,p as u,r as d,s as f,t as p,u as m}from"./index-2aup9CVk.js";var h=[],g=[];(()=>{let e=`lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5`.split(`,`).map(e=>e?parseInt(e,36):1);for(let t=0,n=0;t<e.length;t++)(t%2?g:h).push(n+=e[t])})();function _(e){if(e<768)return!1;for(let t=0,n=h.length;;){let r=t+n>>1;if(e<h[r])n=r;else if(e>=g[r])t=r+1;else return!0;if(t==n)return!1}}function v(e){return e>=127462&&e<=127487}var y=8205;function b(e,t,n=!0,r=!0){return(n?x:S)(e,t,r)}function x(e,t,n){if(t==e.length)return t;t&&te(e.charCodeAt(t))&&ne(e.charCodeAt(t-1))&&t--;let r=ee(e,t);for(t+=re(r);t<e.length;){let i=ee(e,t);if(r==y||i==y||n&&_(i))t+=re(i),r=i;else if(v(i)){let n=0,r=t-2;for(;r>=0&&v(ee(e,r));)n++,r-=2;if(n%2==0)break;t+=2}else break}return t}function S(e,t,n){for(;t>1;){let r=x(e,t-2,n);if(r<t)return r;t--}return 0}function ee(e,t){let n=e.charCodeAt(t);if(!ne(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return te(r)?(n-55296<<10)+(r-56320)+65536:n}function te(e){return e>=56320&&e<57344}function ne(e){return e>=55296&&e<56320}function re(e){return e<65536?1:2}var C=class e{lineAt(e){if(e<0||e>this.length)throw RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=fe(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),ie.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=fe(this,e,t);let n=[];return this.decompose(e,t,n,0),ie.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=new ce(this),i=new ce(e);for(let e=t,a=t;;){if(r.next(e),i.next(e),e=0,r.lineBreak!=i.lineBreak||r.done!=i.done||r.value!=i.value)return!1;if(a+=r.value.length,r.done||a>=n)return!0}}iter(e=1){return new ce(this,e)}iterRange(e,t=this.length){return new le(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t??=this.lines+1;let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new ue(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(t){if(t.length==0)throw RangeError(`A document must have at least one line`);return t.length==1&&!t[0]?e.empty:t.length<=32?new w(t):ie.from(w.split(t,[]))}},w=class e extends C{constructor(e,t=ae(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.text[i],o=r+a.length;if((t?n:o)>=e)return new de(r,o,n,a);r=o+1,n++}}decompose(t,n,r,i){let a=t<=0&&n>=this.length?this:new e(se(this.text,t,n),Math.min(n,this.length)-Math.max(0,t));if(i&1){let t=r.pop(),n=oe(a.text,t.text.slice(),0,a.length);if(n.length<=32)r.push(new e(n,t.length+a.length));else{let t=n.length>>1;r.push(new e(n.slice(0,t)),new e(n.slice(t)))}}else r.push(a)}replace(t,n,r){if(!(r instanceof e))return super.replace(t,n,r);[t,n]=fe(this,t,n);let i=oe(this.text,oe(r.text,se(this.text,0,t)),n),a=this.length+r.length-(n-t);return i.length<=32?new e(i,a):ie.from(e.split(i,[]),a)}sliceString(e,t=this.length,n=`
2
2
  `){[e,t]=fe(this,e,t);let r=``;for(let i=0,a=0;i<=t&&a<this.text.length;a++){let o=this.text[a],s=i+o.length;i>e&&a&&(r+=n),e<s&&t>i&&(r+=o.slice(Math.max(0,e-i),t-i)),i=s+1}return r}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(t,n){let r=[],i=-1;for(let a of t)r.push(a),i+=a.length+1,r.length==32&&(n.push(new e(r,i)),r=[],i=-1);return i>-1&&n.push(new e(r,i)),n}},ie=class e extends C{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let t of e)this.lines+=t.lines}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.children[i],o=r+a.length,s=n+a.lines-1;if((t?s:o)>=e)return a.lineInner(e,t,n,r);r=o+1,n=s+1}}decompose(e,t,n,r){for(let i=0,a=0;a<=t&&i<this.children.length;i++){let o=this.children[i],s=a+o.length;if(e<=s&&t>=a){let i=r&(a<=e|(s>=t?2:0));a>=e&&s<=t&&!i?n.push(o):o.decompose(e-a,t-a,n,i)}a=s+1}}replace(t,n,r){if([t,n]=fe(this,t,n),r.lines<this.lines)for(let i=0,a=0;i<this.children.length;i++){let o=this.children[i],s=a+o.length;if(t>=a&&n<=s){let c=o.replace(t-a,n-a,r),l=this.lines-o.lines+c.lines;if(c.lines<l>>4&&c.lines>l>>6){let a=this.children.slice();return a[i]=c,new e(a,this.length-(n-t)+r.length)}return super.replace(a,s,c)}a=s+1}return super.replace(t,n,r)}sliceString(e,t=this.length,n=`
3
3
  `){[e,t]=fe(this,e,t);let r=``;for(let i=0,a=0;i<this.children.length&&a<=t;i++){let o=this.children[i],s=a+o.length;a>e&&i&&(r+=n),e<s&&t>a&&(r+=o.sliceString(e-a,t-a,n)),a=s+1}return r}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(t,n){if(!(t instanceof e))return 0;let r=0,[i,a,o,s]=n>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;i+=n,a+=n){if(i==o||a==s)return r;let e=this.children[i],c=t.children[a];if(e!=c)return r+e.scanIdentical(c,n);r+=e.length+1}}static from(t,n=t.reduce((e,t)=>e+t.length+1,-1)){let r=0;for(let e of t)r+=e.lines;if(r<32){let e=[];for(let n of t)n.flatten(e);return new w(e,n)}let i=Math.max(32,r>>5),a=i<<1,o=i>>1,s=[],c=0,l=-1,u=[];function d(t){let n;if(t.lines>a&&t instanceof e)for(let e of t.children)d(e);else t.lines>o&&(c>o||!c)?(f(),s.push(t)):t instanceof w&&c&&(n=u[u.length-1])instanceof w&&t.lines+n.lines<=32?(c+=t.lines,l+=t.length+1,u[u.length-1]=new w(n.text.concat(t.text),n.length+1+t.length)):(c+t.lines>i&&f(),c+=t.lines,l+=t.length+1,u.push(t))}function f(){c!=0&&(s.push(u.length==1?u[0]:e.from(u,l)),l=-1,c=u.length=0)}for(let e of t)d(e);return f(),s.length==1?s[0]:new e(s,n)}};C.empty=new w([``],0);function ae(e){let t=-1;for(let n of e)t+=n.length+1;return t}function oe(e,t,n=0,r=1e9){for(let i=0,a=0,o=!0;a<e.length&&i<=r;a++){let s=e[a],c=i+s.length;c>=n&&(c>r&&(s=s.slice(0,r-i)),i<n&&(s=s.slice(n-i)),o?(t[t.length-1]+=s,o=!1):t.push(s)),i=c+1}return t}function se(e,t,n){return oe(e,[``],t,n)}var ce=class{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value=``,this.nodes=[e],this.offsets=[t>0?1:(e instanceof w?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,r=this.nodes[n],i=this.offsets[n],a=i>>1,o=r instanceof w?r.text.length:r.children.length;if(a==(t>0?o:0)){if(n==0)return this.done=!0,this.value=``,this;t>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((i&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=`
4
4
  `,this;e--}else if(r instanceof w){let i=r.text[a+(t<0?-1:0)];if(this.offsets[n]+=t,i.length>Math.max(0,e))return this.value=e==0?i:t>0?i.slice(e):i.slice(0,i.length-e),this;e-=i.length}else{let i=r.children[a+(t<0?-1:0)];e>i.length?(e-=i.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(i),this.offsets.push(t>0?1:(i instanceof w?i.text.length:i.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},le=class{constructor(e,t,n){this.value=``,this.done=!1,this.cursor=new ce(e,t>n?-1:1),this.pos=t>n?e.length:0,this.from=Math.min(t,n),this.to=Math.max(t,n)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value=``,this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n),n-=e;let{value:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=n?r:t<0?r.slice(r.length-n):r.slice(0,n),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=``}},ue=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value=``,this.done=!1}next(e=0){let{done:t,lineBreak:n,value:r}=this.inner.next(e);return t&&this.afterBreak?(this.value=``,this.afterBreak=!1):t?(this.done=!0,this.value=``):n?this.afterBreak?this.value=``:(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<`u`&&(C.prototype[Symbol.iterator]=function(){return this.iter()},ce.prototype[Symbol.iterator]=le.prototype[Symbol.iterator]=ue.prototype[Symbol.iterator]=function(){return this});var de=class{constructor(e,t,n,r){this.from=e,this.to=t,this.number=n,this.text=r}get length(){return this.to-this.from}};function fe(e,t,n){return t=Math.max(0,Math.min(e.length,t)),[t,Math.max(t,Math.min(e.length,n))]}function T(e,t,n=!0,r=!0){return b(e,t,n,r)}function pe(e){return e>=56320&&e<57344}function me(e){return e>=55296&&e<56320}function he(e,t){let n=e.charCodeAt(t);if(!me(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return pe(r)?(n-55296<<10)+(r-56320)+65536:n}function ge(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode((e>>10)+55296,(e&1023)+56320))}function _e(e){return e<65536?1:2}var ve=/\r\n?|\n/,ye=(function(e){return e[e.Simple=0]=`Simple`,e[e.TrackDel=1]=`TrackDel`,e[e.TrackBefore=2]=`TrackBefore`,e[e.TrackAfter=3]=`TrackAfter`,e})(ye||={}),be=class e{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t+1];e+=n<0?this.sections[t]:n}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,n=0,r=0;t<this.sections.length;){let i=this.sections[t++],a=this.sections[t++];a<0?(e(n,r,i),r+=i):r+=a,n+=i}}iterChangedRanges(e,t=!1){Ce(this,e,t)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let n=this.sections[e++],r=this.sections[e++];r<0?t.push(n,r):t.push(r,n)}return new e(t)}composeDesc(e){return this.empty?e:e.empty?this:Te(this,e)}mapDesc(e,t=!1){return e.empty?this:we(this,e,t)}mapPos(e,t=-1,n=ye.Simple){let r=0,i=0;for(let a=0;a<this.sections.length;){let o=this.sections[a++],s=this.sections[a++],c=r+o;if(s<0){if(c>e)return i+(e-r);i+=o}else{if(n!=ye.Simple&&c>=e&&(n==ye.TrackDel&&r<e&&c>e||n==ye.TrackBefore&&r<e||n==ye.TrackAfter&&c>e))return null;if(c>e||c==e&&t<0&&!o)return e==r||t<0?i:i+s;i+=s}r=c}if(e>r)throw RangeError(`Position ${e} is out of range for changeset of length ${r}`);return i}touchesRange(e,t=e){for(let n=0,r=0;n<this.sections.length&&r<=t;){let i=this.sections[n++],a=this.sections[n++],o=r+i;if(a>=0&&r<=t&&o>=e)return r<e&&o>t?`cover`:!0;r=o}return!1}toString(){let e=``;for(let t=0;t<this.sections.length;){let n=this.sections[t++],r=this.sections[t++];e+=(e?` `:``)+n+(r>=0?`:`+r:``)}return e}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!=`number`))throw RangeError(`Invalid JSON representation of ChangeDesc`);return new e(t)}static create(t){return new e(t)}},xe=class e extends be{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw RangeError(`Applying change set to a document with the wrong length`);return Ce(this,(t,n,r,i,a)=>e=e.replace(r,r+(n-t),a),!1),e}mapDesc(e,t=!1){return we(this,e,t,!0)}invert(t){let n=this.sections.slice(),r=[];for(let e=0,i=0;e<n.length;e+=2){let a=n[e],o=n[e+1];if(o>=0){n[e]=o,n[e+1]=a;let s=e>>1;for(;r.length<s;)r.push(C.empty);r.push(a?t.slice(i,i+a):C.empty)}i+=a}return new e(n,r)}compose(e){return this.empty?e:e.empty?this:Te(this,e,!0)}map(e,t=!1){return e.empty?this:we(this,e,t,!0)}iterChanges(e,t=!1){Ce(this,e,t)}get desc(){return be.create(this.sections)}filter(t){let n=[],r=[],i=[],a=new Ee(this);e:for(let e=0,o=0;;){let s=e==t.length?1e9:t[e++];for(;o<s||o==s&&a.len==0;){if(a.done)break e;let e=Math.min(a.len,s-o);E(i,e,-1);let t=a.ins==-1?-1:a.off==0?a.ins:0;E(n,e,t),t>0&&Se(r,n,a.text),a.forward(e),o+=e}let c=t[e++];for(;o<c;){if(a.done)break e;let e=Math.min(a.len,c-o);E(n,e,-1),E(i,e,a.ins==-1?-1:a.off==0?a.ins:0),a.forward(e),o+=e}}return{changes:new e(n,r),filtered:be.create(i)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t],r=this.sections[t+1];r<0?e.push(n):r==0?e.push([n]):e.push([n].concat(this.inserted[t>>1].toJSON()))}return e}static of(t,n,r){let i=[],a=[],o=0,s=null;function c(t=!1){if(!t&&!i.length)return;o<n&&E(i,n-o,-1);let r=new e(i,a);s=s?s.compose(r.map(s)):r,i=[],a=[],o=0}function l(t){if(Array.isArray(t))for(let e of t)l(e);else if(t instanceof e){if(t.length!=n)throw RangeError(`Mismatched change set length (got ${t.length}, expected ${n})`);c(),s=s?s.compose(t.map(s)):t}else{let{from:e,to:s=e,insert:l}=t;if(e>s||e<0||s>n)throw RangeError(`Invalid change range ${e} to ${s} (in doc of length ${n})`);let u=l?typeof l==`string`?C.of(l.split(r||ve)):l:C.empty,d=u.length;if(e==s&&d==0)return;e<o&&c(),e>o&&E(i,e-o,-1),E(i,s-e,d),Se(a,i,u),o=s}}return l(t),c(!s),s}static empty(t){return new e(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw RangeError(`Invalid JSON representation of ChangeSet`);let n=[],r=[];for(let e=0;e<t.length;e++){let i=t[e];if(typeof i==`number`)n.push(i,-1);else if(!Array.isArray(i)||typeof i[0]!=`number`||i.some((e,t)=>t&&typeof e!=`string`))throw RangeError(`Invalid JSON representation of ChangeSet`);else if(i.length==1)n.push(i[0],0);else{for(;r.length<e;)r.push(C.empty);r[e]=C.of(i.slice(1)),n.push(i[0],r[e].length)}}return new e(n,r)}static createSet(t,n){return new e(t,n)}};function E(e,t,n,r=!1){if(t==0&&n<=0)return;let i=e.length-2;i>=0&&n<=0&&n==e[i+1]?e[i]+=t:i>=0&&t==0&&e[i]==0?e[i+1]+=n:r?(e[i]+=t,e[i+1]+=n):e.push(t,n)}function Se(e,t,n){if(n.length==0)return;let r=t.length-2>>1;if(r<e.length)e[e.length-1]=e[e.length-1].append(n);else{for(;e.length<r;)e.push(C.empty);e.push(n)}}function Ce(e,t,n){let r=e.inserted;for(let i=0,a=0,o=0;o<e.sections.length;){let s=e.sections[o++],c=e.sections[o++];if(c<0)i+=s,a+=s;else{let l=i,u=a,d=C.empty;for(;l+=s,u+=c,c&&r&&(d=d.append(r[o-2>>1])),!(n||o==e.sections.length||e.sections[o+1]<0);)s=e.sections[o++],c=e.sections[o++];t(i,l,a,u,d),i=l,a=u}}}function we(e,t,n,r=!1){let i=[],a=r?[]:null,o=new Ee(e),s=new Ee(t);for(let e=-1;;)if(o.done&&s.len||s.done&&o.len)throw Error(`Mismatched change set lengths`);else if(o.ins==-1&&s.ins==-1){let e=Math.min(o.len,s.len);E(i,e,-1),o.forward(e),s.forward(e)}else if(s.ins>=0&&(o.ins<0||e==o.i||o.off==0&&(s.len<o.len||s.len==o.len&&!n))){let t=s.len;for(E(i,s.ins,-1);t;){let n=Math.min(o.len,t);o.ins>=0&&e<o.i&&o.len<=n&&(E(i,0,o.ins),a&&Se(a,i,o.text),e=o.i),o.forward(n),t-=n}s.next()}else if(o.ins>=0){let t=0,n=o.len;for(;n;)if(s.ins==-1){let e=Math.min(n,s.len);t+=e,n-=e,s.forward(e)}else if(s.ins==0&&s.len<n)n-=s.len,s.next();else break;E(i,t,e<o.i?o.ins:0),a&&e<o.i&&Se(a,i,o.text),e=o.i,o.forward(o.len-n)}else if(o.done&&s.done)return a?xe.createSet(i,a):be.create(i);else throw Error(`Mismatched change set lengths`)}function Te(e,t,n=!1){let r=[],i=n?[]:null,a=new Ee(e),o=new Ee(t);for(let e=!1;;)if(a.done&&o.done)return i?xe.createSet(r,i):be.create(r);else if(a.ins==0)E(r,a.len,0,e),a.next();else if(o.len==0&&!o.done)E(r,0,o.ins,e),i&&Se(i,r,o.text),o.next();else if(a.done||o.done)throw Error(`Mismatched change set lengths`);else{let t=Math.min(a.len2,o.len),n=r.length;if(a.ins==-1){let n=o.ins==-1?-1:o.off?0:o.ins;E(r,t,n,e),i&&n&&Se(i,r,o.text)}else o.ins==-1?(E(r,a.off?0:a.len,t,e),i&&Se(i,r,a.textBit(t))):(E(r,a.off?0:a.len,o.off?0:o.ins,e),i&&!o.off&&Se(i,r,o.text));e=(a.ins>t||o.ins>=0&&o.len>t)&&(e||r.length>n),a.forward2(t),o.forward(t)}}var Ee=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?C.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?C.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},De=class e{constructor(e,t,n,r){this.from=e,this.to=t,this.flags=n,this.goalColumn=r}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(t,n=-1){let r,i;return this.empty?r=i=t.mapPos(this.from,n):(r=t.mapPos(this.from,1),i=t.mapPos(this.to,-1)),r==this.from&&i==this.to?this:new e(r,i,this.flags,this.goalColumn)}extend(e,t=e,n=0){if(e<=this.anchor&&t>=this.anchor)return D.range(e,t,void 0,void 0,n);let r=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return D.range(this.anchor,r,void 0,void 0,n)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!=`number`||typeof e.head!=`number`)throw RangeError(`Invalid JSON representation for SelectionRange`);return D.range(e.anchor,e.head)}static create(t,n,r,i){return new e(t,n,r,i)}},D=class e{constructor(e,t){this.ranges=e,this.mainIndex=t}map(t,n=-1){return t.empty?this:e.create(this.ranges.map(e=>e.map(t,n)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let n=0;n<this.ranges.length;n++)if(!this.ranges[n].eq(e.ranges[n],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new e([this.main],0)}addRange(t,n=!0){return e.create([t].concat(this.ranges),n?0:this.mainIndex+1)}replaceRange(t,n=this.mainIndex){let r=this.ranges.slice();return r[n]=t,e.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!=`number`||t.main>=t.ranges.length)throw RangeError(`Invalid JSON representation for EditorSelection`);return new e(t.ranges.map(e=>De.fromJSON(e)),t.main)}static single(t,n=t){return new e([e.range(t,n)],0)}static create(t,n=0){if(t.length==0)throw RangeError(`A selection needs at least one range`);for(let r=0,i=0;i<t.length;i++){let a=t[i];if(a.empty?a.from<=r:a.from<r)return e.normalized(t.slice(),n);r=a.to}return new e(t,n)}static cursor(e,t=0,n,r){return De.create(e,e,(t==0?0:t<0?8:16)|(n==null?7:Math.min(6,n)),r)}static range(e,t,n,r,i){let a=r==null?7:Math.min(6,r);return!i&&e!=t&&(i=t<e?1:-1),i&&(a|=i<0?8:16),t<e?De.create(t,e,a|32,n):De.create(e,t,a,n)}static undirectionalRange(e,t){return De.create(e,t,64,void 0)}static normalized(t,n=0){let r=t[n];t.sort((e,t)=>e.from-t.from),n=t.indexOf(r);for(let r=1;r<t.length;r++){let i=t[r],a=t[r-1];if(i.empty?i.from<=a.to:i.from<a.to){let o=a.from,s=Math.max(i.to,a.to);r<=n&&n--,t.splice(--r,2,i.anchor>i.head?e.range(s,o):e.range(o,s))}}return new e(t,n)}};function Oe(e,t){for(let n of e.ranges)if(n.to>t)throw RangeError(`Selection points outside of document`)}var ke=0,O=class e{constructor(e,t,n,r,i){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=r,this.id=ke++,this.default=e([]),this.extensions=typeof i==`function`?i(this):i}get reader(){return this}static define(t={}){return new e(t.combine||(e=>e),t.compareInput||((e,t)=>e===t),t.compare||(t.combine?(e,t)=>e===t:Ae),!!t.static,t.enables)}of(e){return new je([],this,0,e)}compute(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new je(e,this,1,t)}computeN(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new je(e,this,2,t)}from(e,t){return t||=e=>e,this.compute([e],n=>t(n.field(e)))}};function Ae(e,t){return e==t||e.length==t.length&&e.every((e,n)=>e===t[n])}var je=class{constructor(e,t,n,r){this.dependencies=e,this.facet=t,this.type=n,this.value=r,this.id=ke++}dynamicSlot(e){let t=this.value,n=this.facet.compareInput,r=this.id,i=e[r]>>1,a=this.type==2,o=!1,s=!1,c=[];for(let t of this.dependencies)t==`doc`?o=!0:t==`selection`?s=!0:(e[t.id]??1)&1||c.push(e[t.id]);return{create(e){return e.values[i]=t(e),1},update(e,r){if(o&&r.docChanged||s&&(r.docChanged||r.selection)||Ne(e,c)){let r=t(e);if(a?!Me(r,e.values[i],n):!n(r,e.values[i]))return e.values[i]=r,1}return 0},reconfigure:(e,o)=>{let s,c=o.config.address[r];if(c!=null){let r=Ke(o,c);if(this.dependencies.every(t=>t instanceof O?o.facet(t)===e.facet(t):t instanceof Ie?o.field(t,!1)==e.field(t,!1):!0)||(a?Me(s=t(e),r,n):n(s=t(e),r)))return e.values[i]=r,0}else s=t(e);return e.values[i]=s,1}}}get extension(){return this}};function Me(e,t,n){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!n(e[r],t[r]))return!1;return!0}function Ne(e,t){let n=!1;for(let r of t)Ge(e,r)&1&&(n=!0);return n}function Pe(e,t,n){let r=n.map(t=>e[t.id]),i=n.map(e=>e.type),a=r.filter(e=>!(e&1)),o=e[t.id]>>1;function s(e){let n=[];for(let t=0;t<r.length;t++){let a=Ke(e,r[t]);if(i[t]==2)for(let e of a)n.push(e);else n.push(a)}return t.combine(n)}return{create(e){for(let t of r)Ge(e,t);return e.values[o]=s(e),1},update(e,n){if(!Ne(e,a))return 0;let r=s(e);return t.compare(r,e.values[o])?0:(e.values[o]=r,1)},reconfigure(e,i){let a=Ne(e,r),c=i.config.facets[t.id],l=i.facet(t);if(c&&!a&&Ae(n,c))return e.values[o]=l,0;let u=s(e);return t.compare(u,l)?(e.values[o]=l,0):(e.values[o]=u,1)}}}var Fe=O.define({static:!0}),Ie=class e{constructor(e,t,n,r,i){this.id=e,this.createF=t,this.updateF=n,this.compareF=r,this.spec=i,this.provides=void 0}static define(t){let n=new e(ke++,t.create,t.update,t.compare||((e,t)=>e===t),t);return t.provide&&(n.provides=t.provide(n)),n}create(e){return(e.facet(Fe).find(e=>e.field==this)?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:e=>(e.values[t]=this.create(e),1),update:(e,n)=>{let r=e.values[t],i=this.updateF(r,n);return this.compareF(r,i)?0:(e.values[t]=i,1)},reconfigure:(e,n)=>{let r=e.facet(Fe),i=n.facet(Fe),a;return(a=r.find(e=>e.field==this))&&a!=i.find(e=>e.field==this)?(e.values[t]=a.create(e),1):n.config.address[this.id]==null?(e.values[t]=this.create(e),1):(e.values[t]=n.field(this),0)}}}init(e){return[this,Fe.of({field:this,create:e})]}get extension(){return this}},Le={lowest:4,low:3,default:2,high:1,highest:0};function Re(e){return t=>new Be(t,e)}var ze={highest:Re(Le.highest),high:Re(Le.high),default:Re(Le.default),low:Re(Le.low),lowest:Re(Le.lowest)},Be=class{constructor(e,t){this.inner=e,this.prec=t}get extension(){return this}},Ve=class e{of(e){return new He(this,e)}reconfigure(t){return e.reconfigure.of({compartment:this,extension:t})}get(e){return e.config.compartments.get(this)}},He=class{constructor(e,t){this.compartment=e,this.inner=t}get extension(){return this}},Ue=class e{constructor(e,t,n,r,i,a){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=r,this.staticValues=i,this.facets=a,this.statusTemplate=[];this.statusTemplate.length<n.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(t,n,r){let i=[],a=Object.create(null),o=new Map;for(let e of We(t,n,o))e instanceof Ie?i.push(e):(a[e.facet.id]||(a[e.facet.id]=[])).push(e);let s=Object.create(null),c=[],l=[];for(let e of i)s[e.id]=l.length<<1,l.push(t=>e.slot(t));let u=r?.config.facets;for(let e in a){let t=a[e],n=t[0].facet,i=u&&u[e]||[];if(t.every(e=>e.type==0)){if(s[n.id]=c.length<<1|1,Ae(i,t))c.push(r.facet(n));else{let e=n.combine(t.map(e=>e.value));c.push(r&&n.compare(e,r.facet(n))?r.facet(n):e)}}else{for(let e of t)e.type==0?(s[e.id]=c.length<<1|1,c.push(e.value)):(s[e.id]=l.length<<1,l.push(t=>e.dynamicSlot(t)));s[n.id]=l.length<<1,l.push(e=>Pe(e,n,t))}}let d=l.map(e=>e(s));return new e(t,o,d,s,c,a)}};function We(e,t,n){let r=[[],[],[],[],[]],i=new Map;function a(e,o){let s=i.get(e);if(s!=null){if(s<=o)return;let t=r[s].indexOf(e);t>-1&&r[s].splice(t,1),e instanceof He&&n.delete(e.compartment)}if(i.set(e,o),Array.isArray(e))for(let t of e)a(t,o);else if(e instanceof He){if(n.has(e.compartment))throw RangeError(`Duplicate use of compartment in extensions`);let r=t.get(e.compartment)||e.inner;n.set(e.compartment,r),a(r,o)}else if(e instanceof Be)a(e.inner,e.prec);else if(e instanceof Ie)r[o].push(e),e.provides&&a(e.provides,o);else if(e instanceof je)r[o].push(e),e.facet.extensions&&a(e.facet.extensions,Le.default);else{let t=e.extension;if(!t)throw Error(`Unrecognized extension value in extension set (${e}).`);if(t==e)throw Error(`Unrecognized extension value in extension set (${e}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);a(t,o)}}return a(e,Le.default),r.reduce((e,t)=>e.concat(t))}function Ge(e,t){if(t&1)return 2;let n=t>>1,r=e.status[n];if(r==4)throw Error(`Cyclic dependency between fields and/or facets`);if(r&2)return r;e.status[n]=4;let i=e.computeSlot(e,e.config.dynamicSlots[n]);return e.status[n]=2|i}function Ke(e,t){return t&1?e.config.staticValues[t>>1]:e.values[t>>1]}var qe=O.define(),Je=O.define({combine:e=>e.some(e=>e),static:!0}),Ye=O.define({combine:e=>e.length?e[0]:void 0,static:!0}),Xe=O.define(),Ze=O.define(),Qe=O.define(),$e=O.define({combine:e=>e.length?e[0]:!1}),et=class{constructor(e,t){this.type=e,this.value=t}static define(){return new tt}},tt=class{of(e){return new et(this,e)}},nt=class{constructor(e){this.map=e}of(e){return new k(this,e)}},k=class e{constructor(e,t){this.type=e,this.value=t}map(t){let n=this.type.map(this.value,t);return n===void 0?void 0:n==this.value?this:new e(this.type,n)}is(e){return this.type==e}static define(e={}){return new nt(e.map||(e=>e))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let r of e){let e=r.map(t);e&&n.push(e)}return n}};k.reconfigure=k.define(),k.appendConfig=k.define();var rt=class e{constructor(t,n,r,i,a,o){this.startState=t,this.changes=n,this.selection=r,this.effects=i,this.annotations=a,this.scrollIntoView=o,this._doc=null,this._state=null,r&&Oe(r,n.newLength),a.some(t=>t.type==e.time)||(this.annotations=a.concat(e.time.of(Date.now())))}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}get newDoc(){return this._doc||=this.changes.apply(this.startState.doc)}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let n=this.annotation(e.userEvent);return!!(n&&(n==t||n.length>t.length&&n.slice(0,t.length)==t&&n[t.length]==`.`))}};rt.time=et.define(),rt.userEvent=et.define(),rt.addToHistory=et.define(),rt.remote=et.define();function it(e,t){let n=[];for(let r=0,i=0;;){let a,o;if(r<e.length&&(i==t.length||t[i]>=e[r]))a=e[r++],o=e[r++];else if(i<t.length)a=t[i++],o=t[i++];else return n;!n.length||n[n.length-1]<a?n.push(a,o):n[n.length-1]<o&&(n[n.length-1]=o)}}function at(e,t,n){let r,i,a;return n?(r=t.changes,i=xe.empty(t.changes.length),a=e.changes.compose(t.changes)):(r=t.changes.map(e.changes),i=e.changes.mapDesc(t.changes,!0),a=e.changes.compose(r)),{changes:a,selection:t.selection?t.selection.map(i):e.selection?.map(r),effects:k.mapEffects(e.effects,r).concat(k.mapEffects(t.effects,i)),annotations:e.annotations.length?e.annotations.concat(t.annotations):t.annotations,scrollIntoView:e.scrollIntoView||t.scrollIntoView}}function ot(e,t,n){let r=t.selection,i=dt(t.annotations);return t.userEvent&&(i=i.concat(rt.userEvent.of(t.userEvent))),{changes:t.changes instanceof xe?t.changes:xe.of(t.changes||[],n,e.facet(Ye)),selection:r&&(r instanceof D?r:D.single(r.anchor,r.head)),effects:dt(t.effects),annotations:i,scrollIntoView:!!t.scrollIntoView}}function st(e,t,n){let r=ot(e,t.length?t[0]:{},e.doc.length);t.length&&t[0].filter===!1&&(n=!1);for(let i=1;i<t.length;i++){t[i].filter===!1&&(n=!1);let a=!!t[i].sequential;r=at(r,ot(e,t[i],a?r.changes.newLength:e.doc.length),a)}let i=rt.create(e,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return lt(n?ct(i):i)}function ct(e){let t=e.startState,n=!0;for(let r of t.facet(Xe)){let t=r(e);if(t===!1){n=!1;break}Array.isArray(t)&&(n=n===!0?t:it(n,t))}if(n!==!0){let r,i;if(n===!1)i=e.changes.invertedDesc,r=xe.empty(t.doc.length);else{let t=e.changes.filter(n);r=t.changes,i=t.filtered.mapDesc(t.changes).invertedDesc}e=rt.create(t,r,e.selection&&e.selection.map(i),k.mapEffects(e.effects,i),e.annotations,e.scrollIntoView)}let r=t.facet(Ze);for(let n=r.length-1;n>=0;n--){let i=r[n](e);e=i instanceof rt?i:Array.isArray(i)&&i.length==1&&i[0]instanceof rt?i[0]:st(t,dt(i),!1)}return e}function lt(e){let t=e.startState,n=t.facet(Qe),r=e;for(let i=n.length-1;i>=0;i--){let a=n[i](e);a&&Object.keys(a).length&&(r=at(r,ot(t,a,e.changes.newLength),!0))}return r==e?e:rt.create(t,e.changes,e.selection,r.effects,r.annotations,r.scrollIntoView)}var ut=[];function dt(e){return e==null?ut:Array.isArray(e)?e:[e]}var A=(function(e){return e[e.Word=0]=`Word`,e[e.Space=1]=`Space`,e[e.Other=2]=`Other`,e})(A||={}),ft=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,pt;try{pt=RegExp(`[\\p{Alphabetic}\\p{Number}_]`,`u`)}catch{}function mt(e){if(pt)return pt.test(e);for(let t=0;t<e.length;t++){let n=e[t];if(/\w/.test(n)||n>`€`&&(n.toUpperCase()!=n.toLowerCase()||ft.test(n)))return!0}return!1}function ht(e){return t=>{if(!/\S/.test(t))return A.Space;if(mt(t))return A.Word;for(let n=0;n<e.length;n++)if(t.indexOf(e[n])>-1)return A.Word;return A.Other}}var j=class e{constructor(e,t,n,r,i,a){this.config=e,this.doc=t,this.selection=n,this.values=r,this.status=e.statusTemplate.slice(),this.computeSlot=i,a&&(a._state=this);for(let e=0;e<this.config.dynamicSlots.length;e++)Ge(this,e<<1);this.computeSlot=null}field(e,t=!0){let n=this.config.address[e.id];if(n==null){if(t)throw RangeError(`Field is not present in this state`)}else return Ge(this,n),Ke(this,n)}update(...e){return st(this,e,!0)}applyTransaction(t){let n=this.config,{base:r,compartments:i}=n;for(let e of t.effects)e.is(Ve.reconfigure)?(n&&=(i=new Map,n.compartments.forEach((e,t)=>i.set(t,e)),null),i.set(e.value.compartment,e.value.extension)):e.is(k.reconfigure)?(n=null,r=e.value):e.is(k.appendConfig)&&(n=null,r=dt(r).concat(e.value));let a;n?a=t.startState.values.slice():(n=Ue.resolve(r,i,this),a=new e(n,this.doc,this.selection,n.dynamicSlots.map(()=>null),(e,t)=>t.reconfigure(e,this),null).values);let o=t.startState.facet(Je)?t.newSelection:t.newSelection.asSingle();new e(n,t.newDoc,o,a,(e,n)=>n.update(e,t),t)}replaceSelection(e){return typeof e==`string`&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:D.cursor(t.from+e.length,-1)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),r=this.changes(n.changes),i=[n.range],a=dt(n.effects);for(let n=1;n<t.ranges.length;n++){let o=e(t.ranges[n]),s=this.changes(o.changes),c=s.map(r);for(let e=0;e<n;e++)i[e]=i[e].map(c);let l=r.mapDesc(s,!0);i.push(o.range.map(l)),r=r.compose(c),a=k.mapEffects(a,c).concat(k.mapEffects(dt(o.effects),l))}return{changes:r,selection:D.create(i,t.mainIndex),effects:a}}changes(t=[]){return t instanceof xe?t:xe.of(t,this.doc.length,this.facet(e.lineSeparator))}toText(t){return C.of(t.split(this.facet(e.lineSeparator)||ve))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(Ge(this,t),Ke(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let n in e){let r=e[n];r instanceof Ie&&this.config.address[r.id]!=null&&(t[n]=r.spec.toJSON(this.field(e[n]),this))}return t}static fromJSON(t,n={},r){if(!t||typeof t.doc!=`string`)throw RangeError(`Invalid JSON representation for EditorState`);let i=[];if(r){for(let e in r)if(Object.prototype.hasOwnProperty.call(t,e)){let n=r[e],a=t[e];i.push(n.init(e=>n.spec.fromJSON(a,e)))}}return e.create({doc:t.doc,selection:D.fromJSON(t.selection),extensions:n.extensions?i.concat([n.extensions]):i})}static create(t={}){let n=Ue.resolve(t.extensions||[],new Map),r=t.doc instanceof C?t.doc:C.of((t.doc||``).split(n.staticFacet(e.lineSeparator)||ve)),i=t.selection?t.selection instanceof D?t.selection:D.single(t.selection.anchor,t.selection.head):D.single(0);return Oe(i,r.length),n.staticFacet(Je)||(i=i.asSingle()),new e(n,r,i,n.dynamicSlots.map(()=>null),(e,t)=>t.create(e),null)}get tabSize(){return this.facet(e.tabSize)}get lineBreak(){return this.facet(e.lineSeparator)||`