@cortexkit/aft-opencode 0.2.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.
- package/dist/bridge.d.ts +43 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +194 -0
- package/dist/bridge.js.map +1 -0
- package/dist/config.d.ts +42 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +180 -0
- package/dist/config.js.map +1 -0
- package/dist/downloader.d.ts +32 -0
- package/dist/downloader.d.ts.map +1 -0
- package/dist/downloader.js +140 -0
- package/dist/downloader.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/lsp.d.ts +32 -0
- package/dist/lsp.d.ts.map +1 -0
- package/dist/lsp.js +71 -0
- package/dist/lsp.js.map +1 -0
- package/dist/pool.d.ts +33 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/pool.js +86 -0
- package/dist/pool.js.map +1 -0
- package/dist/resolver.d.ts +36 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +122 -0
- package/dist/resolver.js.map +1 -0
- package/dist/tools/ast.d.ts +9 -0
- package/dist/tools/ast.d.ts.map +1 -0
- package/dist/tools/ast.js +102 -0
- package/dist/tools/ast.js.map +1 -0
- package/dist/tools/editing.d.ts +7 -0
- package/dist/tools/editing.d.ts.map +1 -0
- package/dist/tools/editing.js +150 -0
- package/dist/tools/editing.js.map +1 -0
- package/dist/tools/imports.d.ts +7 -0
- package/dist/tools/imports.d.ts.map +1 -0
- package/dist/tools/imports.js +67 -0
- package/dist/tools/imports.js.map +1 -0
- package/dist/tools/lsp.d.ts +8 -0
- package/dist/tools/lsp.d.ts.map +1 -0
- package/dist/tools/lsp.js +120 -0
- package/dist/tools/lsp.js.map +1 -0
- package/dist/tools/navigation.d.ts +7 -0
- package/dist/tools/navigation.d.ts.map +1 -0
- package/dist/tools/navigation.js +46 -0
- package/dist/tools/navigation.js.map +1 -0
- package/dist/tools/reading.d.ts +7 -0
- package/dist/tools/reading.d.ts.map +1 -0
- package/dist/tools/reading.js +103 -0
- package/dist/tools/reading.js.map +1 -0
- package/dist/tools/refactoring.d.ts +7 -0
- package/dist/tools/refactoring.d.ts.map +1 -0
- package/dist/tools/refactoring.js +80 -0
- package/dist/tools/refactoring.js.map +1 -0
- package/dist/tools/safety.d.ts +8 -0
- package/dist/tools/safety.d.ts.map +1 -0
- package/dist/tools/safety.js +53 -0
- package/dist/tools/safety.js.map +1 -0
- package/dist/tools/structure.d.ts +8 -0
- package/dist/tools/structure.d.ts.map +1 -0
- package/dist/tools/structure.js +107 -0
- package/dist/tools/structure.js.map +1 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { tool } from "@opencode-ai/plugin";
|
|
2
|
+
import { queryLspHints } from "../lsp.js";
|
|
3
|
+
const z = tool.schema;
|
|
4
|
+
/**
|
|
5
|
+
* Tool definitions for refactoring commands: move_symbol, extract_function, inline_symbol.
|
|
6
|
+
*/
|
|
7
|
+
export function refactoringTools(ctx) {
|
|
8
|
+
return {
|
|
9
|
+
aft_refactor: {
|
|
10
|
+
description: "Workspace-wide refactoring operations that update imports and references across files.\n" +
|
|
11
|
+
"Ops:\n" +
|
|
12
|
+
"- 'move': Move a symbol to another file, updating all imports workspace-wide. Needs 'symbol', 'destination'. Creates a checkpoint before mutating.\n" +
|
|
13
|
+
"- 'extract': Extract a line range into a new function with auto-detected parameters. Needs 'name', 'start_line', 'end_line' (all 1-based). Supports TS/JS/TSX and Python.\n" +
|
|
14
|
+
"- 'inline': Replace a function call with the function's body, substituting args for params. Needs 'symbol', 'call_site_line' (1-based). Validates single-return constraint.\n" +
|
|
15
|
+
"All ops need 'file'. Use dry_run to preview.",
|
|
16
|
+
args: {
|
|
17
|
+
op: z.enum(["move", "extract", "inline"]).describe("Refactoring operation"),
|
|
18
|
+
file: z.string().describe("Path to the source file"),
|
|
19
|
+
symbol: z
|
|
20
|
+
.string()
|
|
21
|
+
.optional()
|
|
22
|
+
.describe("Symbol name (move: symbol to move, inline: function to inline)"),
|
|
23
|
+
// move
|
|
24
|
+
destination: z
|
|
25
|
+
.string()
|
|
26
|
+
.optional()
|
|
27
|
+
.describe("Destination file path (move op — will be created if needed)"),
|
|
28
|
+
scope: z
|
|
29
|
+
.string()
|
|
30
|
+
.optional()
|
|
31
|
+
.describe("Disambiguation scope when multiple symbols share the same name (move op)"),
|
|
32
|
+
// extract
|
|
33
|
+
name: z.string().optional().describe("Name for the new extracted function (extract op)"),
|
|
34
|
+
start_line: z.number().describe("First line of range to extract, 1-based (extract op)"),
|
|
35
|
+
end_line: z.number().describe("Last line of range, exclusive, 1-based (extract op)"),
|
|
36
|
+
// inline
|
|
37
|
+
call_site_line: z
|
|
38
|
+
.number()
|
|
39
|
+
.describe("Line where the call expression is located, 1-based (inline op)"),
|
|
40
|
+
// common
|
|
41
|
+
dry_run: z.boolean().optional().describe("Preview as diff without modifying files"),
|
|
42
|
+
},
|
|
43
|
+
execute: async (args, context) => {
|
|
44
|
+
const bridge = ctx.pool.getBridge(context.directory);
|
|
45
|
+
const op = args.op;
|
|
46
|
+
const commandMap = {
|
|
47
|
+
move: "move_symbol",
|
|
48
|
+
extract: "extract_function",
|
|
49
|
+
inline: "inline_symbol",
|
|
50
|
+
};
|
|
51
|
+
const params = { file: args.file };
|
|
52
|
+
if (args.dry_run !== undefined)
|
|
53
|
+
params.dry_run = args.dry_run;
|
|
54
|
+
switch (op) {
|
|
55
|
+
case "move":
|
|
56
|
+
params.symbol = args.symbol;
|
|
57
|
+
params.destination = args.destination;
|
|
58
|
+
if (args.scope !== undefined)
|
|
59
|
+
params.scope = args.scope;
|
|
60
|
+
break;
|
|
61
|
+
case "extract":
|
|
62
|
+
params.name = args.name;
|
|
63
|
+
params.start_line = Number(args.start_line);
|
|
64
|
+
params.end_line = Number(args.end_line);
|
|
65
|
+
break;
|
|
66
|
+
case "inline":
|
|
67
|
+
params.symbol = args.symbol;
|
|
68
|
+
params.call_site_line = Number(args.call_site_line);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
const hints = await queryLspHints(ctx.client, (args.symbol ?? args.name));
|
|
72
|
+
if (hints)
|
|
73
|
+
params.lsp_hints = hints;
|
|
74
|
+
const response = await bridge.send(commandMap[op], params);
|
|
75
|
+
return JSON.stringify(response);
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=refactoring.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refactoring.js","sourceRoot":"","sources":["../../src/tools/refactoring.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG1C,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;AAEtB;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAkB;IACjD,OAAO;QACL,YAAY,EAAE;YACZ,WAAW,EACT,0FAA0F;gBAC1F,QAAQ;gBACR,sJAAsJ;gBACtJ,6KAA6K;gBAC7K,+KAA+K;gBAC/K,8CAA8C;YAChD,IAAI,EAAE;gBACJ,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,uBAAuB,CAAC;gBAC3E,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,yBAAyB,CAAC;gBACpD,MAAM,EAAE,CAAC;qBACN,MAAM,EAAE;qBACR,QAAQ,EAAE;qBACV,QAAQ,CAAC,gEAAgE,CAAC;gBAC7E,OAAO;gBACP,WAAW,EAAE,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AAM,CAAC;wBAC5B,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;wBACtC,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS;4BAAE,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;wBACxD,MAAM;oBACR,KAAK,SAAS;wBACZ,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;wBACxB,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;wBAC5C,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;wBACxC,MAAM;oBACR,KAAK,QAAQ;wBACX,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;wBAC5B,MAAM,CAAC,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;wBACpD,MAAM;gBACV,CAAC;gBAED,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAW,CAAC,CAAC;gBACpF,IAAI,KAAK;oBAAE,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC;gBAEpC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;gBAC3D,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YAClC,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolDefinition } from "@opencode-ai/plugin";
|
|
2
|
+
import type { PluginContext } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Tool definitions for safety & recovery commands: undo, edit_history,
|
|
5
|
+
* checkpoint, restore_checkpoint, list_checkpoints.
|
|
6
|
+
*/
|
|
7
|
+
export declare function safetyTools(ctx: PluginContext): Record<string, ToolDefinition>;
|
|
8
|
+
//# sourceMappingURL=safety.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safety.d.ts","sourceRoot":"","sources":["../../src/tools/safety.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CA6C9E"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { tool } from "@opencode-ai/plugin";
|
|
2
|
+
const z = tool.schema;
|
|
3
|
+
/**
|
|
4
|
+
* Tool definitions for safety & recovery commands: undo, edit_history,
|
|
5
|
+
* checkpoint, restore_checkpoint, list_checkpoints.
|
|
6
|
+
*/
|
|
7
|
+
export function safetyTools(ctx) {
|
|
8
|
+
return {
|
|
9
|
+
aft_safety: {
|
|
10
|
+
description: "File safety and recovery operations.\n" +
|
|
11
|
+
"Ops:\n" +
|
|
12
|
+
"- 'undo': Undo the last edit to a file. Needs 'file'.\n" +
|
|
13
|
+
"- 'history': List all edit snapshots for a file. Needs 'file'.\n" +
|
|
14
|
+
"- 'checkpoint': Save a named snapshot of tracked files. Needs 'name', optional 'files' array.\n" +
|
|
15
|
+
"- 'restore': Restore files to a checkpoint state. Needs 'name'.\n" +
|
|
16
|
+
"- 'list': List all available checkpoints.\n" +
|
|
17
|
+
"Use checkpoint before risky multi-file changes. Use undo for quick single-file rollback.\n" +
|
|
18
|
+
"Note: backups are in-memory (lost on restart). Per-file undo stack is capped at 20 entries (oldest evicted).",
|
|
19
|
+
args: {
|
|
20
|
+
op: z
|
|
21
|
+
.enum(["undo", "history", "checkpoint", "restore", "list"])
|
|
22
|
+
.describe("Safety operation"),
|
|
23
|
+
file: z.string().optional().describe("File path (required for undo, history)"),
|
|
24
|
+
name: z.string().optional().describe("Checkpoint name (required for checkpoint, restore)"),
|
|
25
|
+
files: z
|
|
26
|
+
.array(z.string())
|
|
27
|
+
.optional()
|
|
28
|
+
.describe("Specific files to include in checkpoint (optional, defaults to all tracked files)"),
|
|
29
|
+
},
|
|
30
|
+
execute: async (args, context) => {
|
|
31
|
+
const bridge = ctx.pool.getBridge(context.directory);
|
|
32
|
+
const op = args.op;
|
|
33
|
+
const commandMap = {
|
|
34
|
+
undo: "undo",
|
|
35
|
+
history: "edit_history",
|
|
36
|
+
checkpoint: "checkpoint",
|
|
37
|
+
restore: "restore_checkpoint",
|
|
38
|
+
list: "list_checkpoints",
|
|
39
|
+
};
|
|
40
|
+
const params = {};
|
|
41
|
+
if (args.file !== undefined)
|
|
42
|
+
params.file = args.file;
|
|
43
|
+
if (args.name !== undefined)
|
|
44
|
+
params.name = args.name;
|
|
45
|
+
if (args.files !== undefined)
|
|
46
|
+
params.files = args.files;
|
|
47
|
+
const response = await bridge.send(commandMap[op], params);
|
|
48
|
+
return JSON.stringify(response);
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=safety.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safety.js","sourceRoot":"","sources":["../../src/tools/safety.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAG3C,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;AAEtB;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAAkB;IAC5C,OAAO;QACL,UAAU,EAAE;YACV,WAAW,EACT,wCAAwC;gBACxC,QAAQ;gBACR,yDAAyD;gBACzD,kEAAkE;gBAClE,iGAAiG;gBACjG,mEAAmE;gBACnE,6CAA6C;gBAC7C,4FAA4F;gBAC5F,8GAA8G;YAChH,IAAI,EAAE;gBACJ,EAAE,EAAE,CAA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C,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;gBAC3D,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YAClC,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolDefinition } from "@opencode-ai/plugin";
|
|
2
|
+
import type { PluginContext } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Tool definitions for scope-aware structure commands:
|
|
5
|
+
* add_member, add_derive, wrap_try_catch, add_decorator, add_struct_tags.
|
|
6
|
+
*/
|
|
7
|
+
export declare function structureTools(ctx: PluginContext): Record<string, ToolDefinition>;
|
|
8
|
+
//# sourceMappingURL=structure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structure.d.ts","sourceRoot":"","sources":["../../src/tools/structure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAqGjF"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { tool } from "@opencode-ai/plugin";
|
|
2
|
+
const z = tool.schema;
|
|
3
|
+
/**
|
|
4
|
+
* Tool definitions for scope-aware structure commands:
|
|
5
|
+
* add_member, add_derive, wrap_try_catch, add_decorator, add_struct_tags.
|
|
6
|
+
*/
|
|
7
|
+
export function structureTools(ctx) {
|
|
8
|
+
return {
|
|
9
|
+
aft_transform: {
|
|
10
|
+
description: "Scope-aware structural code transformations with correct indentation.\n" +
|
|
11
|
+
"Ops:\n" +
|
|
12
|
+
"- 'add_member': Insert method/field into class, struct, or impl block. Needs 'scope' (target container) and 'code'. Optional 'position' (first/last/before:name/after:name).\n" +
|
|
13
|
+
"- 'add_derive': Add Rust derive macros to struct/enum. Needs 'target' and 'derives' array. Deduplicates.\n" +
|
|
14
|
+
"- 'wrap_try_catch': Wrap a TS/JS function body in try/catch. Needs 'target' (function name). Optional 'catch_body'.\n" +
|
|
15
|
+
"- 'add_decorator': Add Python decorator to function/class. Needs 'target' and 'decorator' (without @). Optional 'position' (first/last).\n" +
|
|
16
|
+
"- 'add_struct_tags': Add/update Go struct field tags. Needs 'target' (struct), 'field', 'tag', 'value'.\n" +
|
|
17
|
+
"All ops need 'file'. Returns formatted, validation_errors.",
|
|
18
|
+
args: {
|
|
19
|
+
op: z
|
|
20
|
+
.enum(["add_member", "add_derive", "wrap_try_catch", "add_decorator", "add_struct_tags"])
|
|
21
|
+
.describe("Transformation operation"),
|
|
22
|
+
file: z.string().describe("Path to the source file"),
|
|
23
|
+
// add_member
|
|
24
|
+
scope: z
|
|
25
|
+
.string()
|
|
26
|
+
.optional()
|
|
27
|
+
.describe("Container name to insert into (add_member — class, struct, or impl block)"),
|
|
28
|
+
code: z.string().optional().describe("Member code to insert (add_member)"),
|
|
29
|
+
position: z
|
|
30
|
+
.string()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe("Insert position: 'first', 'last' (default), 'before:name', 'after:name' (add_member, add_decorator)"),
|
|
33
|
+
// add_derive, wrap_try_catch, add_decorator, add_struct_tags
|
|
34
|
+
target: z
|
|
35
|
+
.string()
|
|
36
|
+
.optional()
|
|
37
|
+
.describe("Target symbol name (add_derive: struct/enum, wrap_try_catch: function, add_decorator: function/class, add_struct_tags: struct)"),
|
|
38
|
+
derives: z
|
|
39
|
+
.array(z.string())
|
|
40
|
+
.optional()
|
|
41
|
+
.describe("Derive macro names (add_derive — e.g. ['Clone', 'Debug'])"),
|
|
42
|
+
catch_body: z
|
|
43
|
+
.string()
|
|
44
|
+
.optional()
|
|
45
|
+
.describe("Catch block body (wrap_try_catch — default: 'throw error;')"),
|
|
46
|
+
decorator: z
|
|
47
|
+
.string()
|
|
48
|
+
.optional()
|
|
49
|
+
.describe("Decorator text without @ (add_decorator — e.g. 'staticmethod')"),
|
|
50
|
+
// add_struct_tags
|
|
51
|
+
field: z.string().optional().describe("Struct field name (add_struct_tags)"),
|
|
52
|
+
tag: z.string().optional().describe("Tag key (add_struct_tags — e.g. 'json')"),
|
|
53
|
+
value: z
|
|
54
|
+
.string()
|
|
55
|
+
.optional()
|
|
56
|
+
.describe("Tag value (add_struct_tags — e.g. 'user_name,omitempty')"),
|
|
57
|
+
// common
|
|
58
|
+
validate: z
|
|
59
|
+
.enum(["syntax", "full"])
|
|
60
|
+
.optional()
|
|
61
|
+
.describe("Validation level: 'syntax' (default) or 'full'"),
|
|
62
|
+
dry_run: z.boolean().optional().describe("Preview without modifying the file"),
|
|
63
|
+
},
|
|
64
|
+
execute: async (args, context) => {
|
|
65
|
+
const bridge = ctx.pool.getBridge(context.directory);
|
|
66
|
+
const op = args.op;
|
|
67
|
+
const params = { file: args.file };
|
|
68
|
+
if (args.validate !== undefined)
|
|
69
|
+
params.validate = args.validate;
|
|
70
|
+
if (args.dry_run !== undefined)
|
|
71
|
+
params.dry_run = args.dry_run;
|
|
72
|
+
switch (op) {
|
|
73
|
+
case "add_member":
|
|
74
|
+
params.scope = args.scope;
|
|
75
|
+
params.code = args.code;
|
|
76
|
+
if (args.position !== undefined)
|
|
77
|
+
params.position = args.position;
|
|
78
|
+
break;
|
|
79
|
+
case "add_derive":
|
|
80
|
+
params.target = args.target;
|
|
81
|
+
params.derives = args.derives;
|
|
82
|
+
break;
|
|
83
|
+
case "wrap_try_catch":
|
|
84
|
+
params.target = args.target;
|
|
85
|
+
if (args.catch_body !== undefined)
|
|
86
|
+
params.catch_body = args.catch_body;
|
|
87
|
+
break;
|
|
88
|
+
case "add_decorator":
|
|
89
|
+
params.target = args.target;
|
|
90
|
+
params.decorator = args.decorator;
|
|
91
|
+
if (args.position !== undefined)
|
|
92
|
+
params.position = args.position;
|
|
93
|
+
break;
|
|
94
|
+
case "add_struct_tags":
|
|
95
|
+
params.target = args.target;
|
|
96
|
+
params.field = args.field;
|
|
97
|
+
params.tag = args.tag;
|
|
98
|
+
params.value = args.value;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
const response = await bridge.send(op, params);
|
|
102
|
+
return JSON.stringify(response);
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=structure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structure.js","sourceRoot":"","sources":["../../src/tools/structure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAG3C,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;AAEtB;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,GAAkB;IAC/C,OAAO;QACL,aAAa,EAAE;YACb,WAAW,EACT,yEAAyE;gBACzE,QAAQ;gBACR,gLAAgL;gBAChL,4GAA4G;gBAC5G,uHAAuH;gBACvH,4IAA4I;gBAC5I,2GAA2G;gBAC3G,4DAA4D;YAC9D,IAAI,EAAE;gBACJ,EAAE,EAAE,CAAC;qBACF,IAAI,CAAC,CAAC,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,CAAC,CAAC;qBACxF,QAAQ,CAAC,0BAA0B,CAAC;gBACvC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,yBAAyB,CAAC;gBACpD,aAAa;gBACb,KAAK,EAAE,CAAC;qBACL,MAAM,EAAE;qBACR,QAAQ,EAAE;qBACV,QAAQ,CAAC,2EAA2E,CAAC;gBACxF,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,oCAAoC,CAAC;gBAC1E,QAAQ,EAAE,CAAC;qBACR,MAAM,EAAE;qBACR,QAAQ,EAAE;qBACV,QAAQ,CACP,qGAAqG,CACtG;gBACH,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M,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;wBACtB,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;wBAC1B,MAAM;gBACV,CAAC;gBAED,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;gBAC/C,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YAClC,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PluginInput } from "@opencode-ai/plugin";
|
|
2
|
+
import type { AftConfig } from "./config.js";
|
|
3
|
+
import type { BridgePool } from "./pool.js";
|
|
4
|
+
/**
|
|
5
|
+
* Shared context passed to all tool factory functions.
|
|
6
|
+
* Bundles the binary bridge, the OpenCode SDK client, and plugin config.
|
|
7
|
+
*/
|
|
8
|
+
export interface PluginContext {
|
|
9
|
+
pool: BridgePool;
|
|
10
|
+
client: PluginInput["client"];
|
|
11
|
+
config: AftConfig;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC9B,MAAM,EAAE,SAAS,CAAC;CACnB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cortexkit/aft-opencode",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "OpenCode plugin for Agent File Tools (AFT) — tree-sitter powered code analysis",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/ualtinok/aft"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"typecheck": "tsc --noEmit",
|
|
20
|
+
"pretest": "cd ../.. && cargo build",
|
|
21
|
+
"test": "bun test",
|
|
22
|
+
"prepublishOnly": "tsc"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@opencode-ai/plugin": "^1.2.26",
|
|
26
|
+
"jsonc-parser": "^3.3.1",
|
|
27
|
+
"zod": "^4.1.8"
|
|
28
|
+
},
|
|
29
|
+
"optionalDependencies": {
|
|
30
|
+
"@cortexkit/aft-darwin-arm64": "0.2.0",
|
|
31
|
+
"@cortexkit/aft-darwin-x64": "0.2.0",
|
|
32
|
+
"@cortexkit/aft-linux-arm64": "0.2.0",
|
|
33
|
+
"@cortexkit/aft-linux-x64": "0.2.0",
|
|
34
|
+
"@cortexkit/aft-win32-x64": "0.2.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^22.0.0",
|
|
38
|
+
"typescript": "^5.8.0"
|
|
39
|
+
}
|
|
40
|
+
}
|