@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.
- package/EXAMPLES.md +80 -1
- package/MODELS.md +72 -24
- package/README.md +95 -2
- package/TOOLS.md +20 -0
- package/package.json +36 -2
- package/src/agent/agent.ts +68 -54
- package/src/auth/claude-oauth.ts +426 -0
- package/src/auth/index.ts +28 -26
- package/src/auth/plugins.ts +876 -0
- package/src/bun/index.ts +53 -43
- package/src/bus/global.ts +5 -5
- package/src/bus/index.ts +59 -53
- package/src/cli/bootstrap.js +12 -12
- package/src/cli/bootstrap.ts +6 -6
- package/src/cli/cmd/agent.ts +97 -92
- package/src/cli/cmd/auth.ts +468 -0
- package/src/cli/cmd/cmd.ts +2 -2
- package/src/cli/cmd/export.ts +41 -41
- package/src/cli/cmd/mcp.ts +210 -53
- package/src/cli/cmd/models.ts +30 -29
- package/src/cli/cmd/run.ts +269 -213
- package/src/cli/cmd/stats.ts +185 -146
- package/src/cli/error.ts +17 -13
- package/src/cli/ui.ts +78 -0
- package/src/command/index.ts +26 -26
- package/src/config/config.ts +528 -288
- package/src/config/markdown.ts +15 -15
- package/src/file/ripgrep.ts +201 -169
- package/src/file/time.ts +21 -18
- package/src/file/watcher.ts +51 -42
- package/src/file.ts +1 -1
- package/src/flag/flag.ts +26 -11
- package/src/format/formatter.ts +206 -162
- package/src/format/index.ts +61 -61
- package/src/global/index.ts +21 -21
- package/src/id/id.ts +47 -33
- package/src/index.js +554 -332
- package/src/json-standard/index.ts +173 -0
- package/src/mcp/index.ts +135 -128
- package/src/patch/index.ts +336 -267
- package/src/project/bootstrap.ts +15 -15
- package/src/project/instance.ts +43 -36
- package/src/project/project.ts +47 -47
- package/src/project/state.ts +37 -33
- package/src/provider/models-macro.ts +5 -5
- package/src/provider/models.ts +32 -32
- package/src/provider/opencode.js +19 -19
- package/src/provider/provider.ts +518 -277
- package/src/provider/transform.ts +143 -102
- package/src/server/project.ts +21 -21
- package/src/server/server.ts +111 -105
- package/src/session/agent.js +66 -60
- package/src/session/compaction.ts +136 -111
- package/src/session/index.ts +189 -156
- package/src/session/message-v2.ts +312 -268
- package/src/session/message.ts +73 -57
- package/src/session/processor.ts +180 -166
- package/src/session/prompt.ts +678 -533
- package/src/session/retry.ts +26 -23
- package/src/session/revert.ts +76 -62
- package/src/session/status.ts +26 -26
- package/src/session/summary.ts +97 -76
- package/src/session/system.ts +77 -63
- package/src/session/todo.ts +22 -16
- package/src/snapshot/index.ts +92 -76
- package/src/storage/storage.ts +157 -120
- package/src/tool/bash.ts +116 -106
- package/src/tool/batch.ts +73 -59
- package/src/tool/codesearch.ts +60 -53
- package/src/tool/edit.ts +319 -263
- package/src/tool/glob.ts +32 -28
- package/src/tool/grep.ts +72 -53
- package/src/tool/invalid.ts +7 -7
- package/src/tool/ls.ts +77 -64
- package/src/tool/multiedit.ts +30 -21
- package/src/tool/patch.ts +121 -94
- package/src/tool/read.ts +140 -122
- package/src/tool/registry.ts +38 -38
- package/src/tool/task.ts +93 -60
- package/src/tool/todo.ts +16 -16
- package/src/tool/tool.ts +45 -36
- package/src/tool/webfetch.ts +97 -74
- package/src/tool/websearch.ts +78 -64
- package/src/tool/write.ts +21 -15
- package/src/util/binary.ts +27 -19
- package/src/util/context.ts +8 -8
- package/src/util/defer.ts +7 -5
- package/src/util/error.ts +24 -19
- package/src/util/eventloop.ts +16 -10
- package/src/util/filesystem.ts +37 -33
- package/src/util/fn.ts +11 -8
- package/src/util/iife.ts +1 -1
- package/src/util/keybind.ts +44 -44
- package/src/util/lazy.ts +7 -7
- package/src/util/locale.ts +20 -16
- package/src/util/lock.ts +43 -38
- package/src/util/log.ts +95 -85
- package/src/util/queue.ts +8 -8
- package/src/util/rpc.ts +35 -23
- package/src/util/scrap.ts +4 -4
- package/src/util/signal.ts +5 -5
- package/src/util/timeout.ts +6 -6
- package/src/util/token.ts +2 -2
- package/src/util/wildcard.ts +38 -27
package/src/global/index.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import { xdgData, xdgCache, xdgConfig, xdgState } from
|
|
3
|
-
import path from
|
|
4
|
-
import os from
|
|
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 =
|
|
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,
|
|
18
|
-
log: path.join(data,
|
|
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 =
|
|
33
|
+
const CACHE_VERSION = '9';
|
|
34
34
|
|
|
35
|
-
const version = await Bun.file(path.join(Global.Path.cache,
|
|
35
|
+
const version = await Bun.file(path.join(Global.Path.cache, 'version'))
|
|
36
36
|
.text()
|
|
37
|
-
.catch(() =>
|
|
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,
|
|
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
|
|
2
|
-
import { randomBytes } from
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import { randomBytes } from 'crypto';
|
|
3
3
|
|
|
4
4
|
export namespace Identifier {
|
|
5
5
|
const prefixes = {
|
|
6
|
-
session:
|
|
7
|
-
message:
|
|
8
|
-
permission:
|
|
9
|
-
user:
|
|
10
|
-
part:
|
|
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(
|
|
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 =
|
|
44
|
-
|
|
45
|
-
|
|
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(
|
|
53
|
-
|
|
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
|
|
79
|
+
return (
|
|
80
|
+
prefixes[prefix] +
|
|
81
|
+
'_' +
|
|
82
|
+
timeBytes.toString('hex') +
|
|
83
|
+
randomBase62(LENGTH - 12)
|
|
84
|
+
);
|
|
71
85
|
}
|
|
72
86
|
}
|