@link-assistant/agent 0.0.8 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/EXAMPLES.md +80 -1
  2. package/MODELS.md +72 -24
  3. package/README.md +95 -2
  4. package/TOOLS.md +20 -0
  5. package/package.json +36 -2
  6. package/src/agent/agent.ts +68 -54
  7. package/src/auth/claude-oauth.ts +426 -0
  8. package/src/auth/index.ts +28 -26
  9. package/src/auth/plugins.ts +876 -0
  10. package/src/bun/index.ts +53 -43
  11. package/src/bus/global.ts +5 -5
  12. package/src/bus/index.ts +59 -53
  13. package/src/cli/bootstrap.js +12 -12
  14. package/src/cli/bootstrap.ts +6 -6
  15. package/src/cli/cmd/agent.ts +97 -92
  16. package/src/cli/cmd/auth.ts +468 -0
  17. package/src/cli/cmd/cmd.ts +2 -2
  18. package/src/cli/cmd/export.ts +41 -41
  19. package/src/cli/cmd/mcp.ts +210 -53
  20. package/src/cli/cmd/models.ts +30 -29
  21. package/src/cli/cmd/run.ts +269 -213
  22. package/src/cli/cmd/stats.ts +185 -146
  23. package/src/cli/error.ts +17 -13
  24. package/src/cli/ui.ts +78 -0
  25. package/src/command/index.ts +26 -26
  26. package/src/config/config.ts +528 -288
  27. package/src/config/markdown.ts +15 -15
  28. package/src/file/ripgrep.ts +201 -169
  29. package/src/file/time.ts +21 -18
  30. package/src/file/watcher.ts +51 -42
  31. package/src/file.ts +1 -1
  32. package/src/flag/flag.ts +26 -11
  33. package/src/format/formatter.ts +206 -162
  34. package/src/format/index.ts +61 -61
  35. package/src/global/index.ts +21 -21
  36. package/src/id/id.ts +47 -33
  37. package/src/index.js +554 -332
  38. package/src/json-standard/index.ts +173 -0
  39. package/src/mcp/index.ts +135 -128
  40. package/src/patch/index.ts +336 -267
  41. package/src/project/bootstrap.ts +15 -15
  42. package/src/project/instance.ts +43 -36
  43. package/src/project/project.ts +47 -47
  44. package/src/project/state.ts +37 -33
  45. package/src/provider/models-macro.ts +5 -5
  46. package/src/provider/models.ts +32 -32
  47. package/src/provider/opencode.js +19 -19
  48. package/src/provider/provider.ts +518 -277
  49. package/src/provider/transform.ts +143 -102
  50. package/src/server/project.ts +21 -21
  51. package/src/server/server.ts +111 -105
  52. package/src/session/agent.js +66 -60
  53. package/src/session/compaction.ts +136 -111
  54. package/src/session/index.ts +189 -156
  55. package/src/session/message-v2.ts +312 -268
  56. package/src/session/message.ts +73 -57
  57. package/src/session/processor.ts +180 -166
  58. package/src/session/prompt.ts +678 -533
  59. package/src/session/retry.ts +26 -23
  60. package/src/session/revert.ts +76 -62
  61. package/src/session/status.ts +26 -26
  62. package/src/session/summary.ts +97 -76
  63. package/src/session/system.ts +77 -63
  64. package/src/session/todo.ts +22 -16
  65. package/src/snapshot/index.ts +92 -76
  66. package/src/storage/storage.ts +157 -120
  67. package/src/tool/bash.ts +116 -106
  68. package/src/tool/batch.ts +73 -59
  69. package/src/tool/codesearch.ts +60 -53
  70. package/src/tool/edit.ts +319 -263
  71. package/src/tool/glob.ts +32 -28
  72. package/src/tool/grep.ts +72 -53
  73. package/src/tool/invalid.ts +7 -7
  74. package/src/tool/ls.ts +77 -64
  75. package/src/tool/multiedit.ts +30 -21
  76. package/src/tool/patch.ts +121 -94
  77. package/src/tool/read.ts +140 -122
  78. package/src/tool/registry.ts +38 -38
  79. package/src/tool/task.ts +93 -60
  80. package/src/tool/todo.ts +16 -16
  81. package/src/tool/tool.ts +45 -36
  82. package/src/tool/webfetch.ts +97 -74
  83. package/src/tool/websearch.ts +78 -64
  84. package/src/tool/write.ts +21 -15
  85. package/src/util/binary.ts +27 -19
  86. package/src/util/context.ts +8 -8
  87. package/src/util/defer.ts +7 -5
  88. package/src/util/error.ts +24 -19
  89. package/src/util/eventloop.ts +16 -10
  90. package/src/util/filesystem.ts +37 -33
  91. package/src/util/fn.ts +11 -8
  92. package/src/util/iife.ts +1 -1
  93. package/src/util/keybind.ts +44 -44
  94. package/src/util/lazy.ts +7 -7
  95. package/src/util/locale.ts +20 -16
  96. package/src/util/lock.ts +43 -38
  97. package/src/util/log.ts +95 -85
  98. package/src/util/queue.ts +8 -8
  99. package/src/util/rpc.ts +35 -23
  100. package/src/util/scrap.ts +4 -4
  101. package/src/util/signal.ts +5 -5
  102. package/src/util/timeout.ts +6 -6
  103. package/src/util/token.ts +2 -2
  104. package/src/util/wildcard.ts +38 -27
@@ -1,25 +1,25 @@
1
- import fs from "fs/promises"
2
- import { xdgData, xdgCache, xdgConfig, xdgState } from "xdg-basedir"
3
- import path from "path"
4
- import os from "os"
1
+ import fs from 'fs/promises';
2
+ import { xdgData, xdgCache, xdgConfig, xdgState } from 'xdg-basedir';
3
+ import path from 'path';
4
+ import os from 'os';
5
5
 
6
- const app = "opencode"
6
+ const app = 'opencode';
7
7
 
8
- const data = path.join(xdgData!, app)
9
- const cache = path.join(xdgCache!, app)
10
- const config = path.join(xdgConfig!, app)
11
- const state = path.join(xdgState!, app)
8
+ const data = path.join(xdgData!, app);
9
+ const cache = path.join(xdgCache!, app);
10
+ const config = path.join(xdgConfig!, app);
11
+ const state = path.join(xdgState!, app);
12
12
 
13
13
  export namespace Global {
14
14
  export const Path = {
15
15
  home: os.homedir(),
16
16
  data,
17
- bin: path.join(data, "bin"),
18
- log: path.join(data, "log"),
17
+ bin: path.join(data, 'bin'),
18
+ log: path.join(data, 'log'),
19
19
  cache,
20
20
  config,
21
21
  state,
22
- } as const
22
+ } as const;
23
23
  }
24
24
 
25
25
  await Promise.all([
@@ -28,25 +28,25 @@ await Promise.all([
28
28
  fs.mkdir(Global.Path.state, { recursive: true }),
29
29
  fs.mkdir(Global.Path.log, { recursive: true }),
30
30
  fs.mkdir(Global.Path.bin, { recursive: true }),
31
- ])
31
+ ]);
32
32
 
33
- const CACHE_VERSION = "9"
33
+ const CACHE_VERSION = '9';
34
34
 
35
- const version = await Bun.file(path.join(Global.Path.cache, "version"))
35
+ const version = await Bun.file(path.join(Global.Path.cache, 'version'))
36
36
  .text()
37
- .catch(() => "0")
37
+ .catch(() => '0');
38
38
 
39
39
  if (version !== CACHE_VERSION) {
40
40
  try {
41
- const contents = await fs.readdir(Global.Path.cache)
41
+ const contents = await fs.readdir(Global.Path.cache);
42
42
  await Promise.all(
43
43
  contents.map((item) =>
44
44
  fs.rm(path.join(Global.Path.cache, item), {
45
45
  recursive: true,
46
46
  force: true,
47
- }),
48
- ),
49
- )
47
+ })
48
+ )
49
+ );
50
50
  } catch (e) {}
51
- await Bun.file(path.join(Global.Path.cache, "version")).write(CACHE_VERSION)
51
+ await Bun.file(path.join(Global.Path.cache, 'version')).write(CACHE_VERSION);
52
52
  }
package/src/id/id.ts CHANGED
@@ -1,72 +1,86 @@
1
- import z from "zod"
2
- import { randomBytes } from "crypto"
1
+ import z from 'zod';
2
+ import { randomBytes } from 'crypto';
3
3
 
4
4
  export namespace Identifier {
5
5
  const prefixes = {
6
- session: "ses",
7
- message: "msg",
8
- permission: "per",
9
- user: "usr",
10
- part: "prt",
11
- } as const
6
+ session: 'ses',
7
+ message: 'msg',
8
+ permission: 'per',
9
+ user: 'usr',
10
+ part: 'prt',
11
+ } as const;
12
12
 
13
13
  export function schema(prefix: keyof typeof prefixes) {
14
- return z.string().startsWith(prefixes[prefix])
14
+ return z.string().startsWith(prefixes[prefix]);
15
15
  }
16
16
 
17
- const LENGTH = 26
17
+ const LENGTH = 26;
18
18
 
19
19
  // State for monotonic ID generation
20
- let lastTimestamp = 0
21
- let counter = 0
20
+ let lastTimestamp = 0;
21
+ let counter = 0;
22
22
 
23
23
  export function ascending(prefix: keyof typeof prefixes, given?: string) {
24
- return generateID(prefix, false, given)
24
+ return generateID(prefix, false, given);
25
25
  }
26
26
 
27
27
  export function descending(prefix: keyof typeof prefixes, given?: string) {
28
- return generateID(prefix, true, given)
28
+ return generateID(prefix, true, given);
29
29
  }
30
30
 
31
- function generateID(prefix: keyof typeof prefixes, descending: boolean, given?: string): string {
31
+ function generateID(
32
+ prefix: keyof typeof prefixes,
33
+ descending: boolean,
34
+ given?: string
35
+ ): string {
32
36
  if (!given) {
33
- return create(prefix, descending)
37
+ return create(prefix, descending);
34
38
  }
35
39
 
36
40
  if (!given.startsWith(prefixes[prefix])) {
37
- throw new Error(`ID ${given} does not start with ${prefixes[prefix]}`)
41
+ throw new Error(`ID ${given} does not start with ${prefixes[prefix]}`);
38
42
  }
39
- return given
43
+ return given;
40
44
  }
41
45
 
42
46
  function randomBase62(length: number): string {
43
- const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
44
- let result = ""
45
- const bytes = randomBytes(length)
47
+ const chars =
48
+ '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
49
+ let result = '';
50
+ const bytes = randomBytes(length);
46
51
  for (let i = 0; i < length; i++) {
47
- result += chars[bytes[i] % 62]
52
+ result += chars[bytes[i] % 62];
48
53
  }
49
- return result
54
+ return result;
50
55
  }
51
56
 
52
- export function create(prefix: keyof typeof prefixes, descending: boolean, timestamp?: number): string {
53
- const currentTimestamp = timestamp ?? Date.now()
57
+ export function create(
58
+ prefix: keyof typeof prefixes,
59
+ descending: boolean,
60
+ timestamp?: number
61
+ ): string {
62
+ const currentTimestamp = timestamp ?? Date.now();
54
63
 
55
64
  if (currentTimestamp !== lastTimestamp) {
56
- lastTimestamp = currentTimestamp
57
- counter = 0
65
+ lastTimestamp = currentTimestamp;
66
+ counter = 0;
58
67
  }
59
- counter++
68
+ counter++;
60
69
 
61
- let now = BigInt(currentTimestamp) * BigInt(0x1000) + BigInt(counter)
70
+ let now = BigInt(currentTimestamp) * BigInt(0x1000) + BigInt(counter);
62
71
 
63
- now = descending ? ~now : now
72
+ now = descending ? ~now : now;
64
73
 
65
- const timeBytes = Buffer.alloc(6)
74
+ const timeBytes = Buffer.alloc(6);
66
75
  for (let i = 0; i < 6; i++) {
67
- timeBytes[i] = Number((now >> BigInt(40 - 8 * i)) & BigInt(0xff))
76
+ timeBytes[i] = Number((now >> BigInt(40 - 8 * i)) & BigInt(0xff));
68
77
  }
69
78
 
70
- return prefixes[prefix] + "_" + timeBytes.toString("hex") + randomBase62(LENGTH - 12)
79
+ return (
80
+ prefixes[prefix] +
81
+ '_' +
82
+ timeBytes.toString('hex') +
83
+ randomBase62(LENGTH - 12)
84
+ );
71
85
  }
72
86
  }