opencode-sat 0.0.14 → 0.0.16-next.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/sat.d.ts.map +1 -1
- package/dist/sat.js +16 -25
- package/dist/sat.js.map +1 -1
- package/dist/src/append.d.ts +12 -9
- package/dist/src/append.d.ts.map +1 -1
- package/dist/src/append.js +32 -37
- package/dist/src/append.js.map +1 -1
- package/dist/src/format-prompt.d.ts.map +1 -1
- package/dist/src/format-prompt.js +39 -30
- package/dist/src/format-prompt.js.map +1 -1
- package/dist/src/format.d.ts +16 -0
- package/dist/src/format.d.ts.map +1 -0
- package/dist/src/format.js +30 -0
- package/dist/src/format.js.map +1 -0
- package/dist/src/process.d.ts +7 -9
- package/dist/src/process.d.ts.map +1 -1
- package/dist/src/process.js +8 -30
- package/dist/src/process.js.map +1 -1
- package/dist/src/tools.d.ts +24 -15
- package/dist/src/tools.d.ts.map +1 -1
- package/dist/src/tools.js +135 -159
- package/dist/src/tools.js.map +1 -1
- package/dist/src/utils/compare.d.ts.map +1 -1
- package/dist/src/utils/compare.js +4 -2
- package/dist/src/utils/compare.js.map +1 -1
- package/dist/src/utils/validate.d.ts.map +1 -1
- package/dist/src/utils/validate.js +4 -2
- package/dist/src/utils/validate.js.map +1 -1
- package/package.json +3 -3
- package/dist/src/opencode/notify.d.ts +0 -10
- package/dist/src/opencode/notify.d.ts.map +0 -1
- package/dist/src/opencode/notify.js +0 -14
- package/dist/src/opencode/notify.js.map +0 -1
- package/dist/src/process-prompt.d.ts +0 -21
- package/dist/src/process-prompt.d.ts.map +0 -1
- package/dist/src/process-prompt.js +0 -20
- package/dist/src/process-prompt.js.map +0 -1
- package/dist/src/prompt-prompt.d.ts +0 -3
- package/dist/src/prompt-prompt.d.ts.map +0 -1
- package/dist/src/prompt-prompt.js +0 -47
- package/dist/src/prompt-prompt.js.map +0 -1
- package/dist/src/prompt.d.ts +0 -7
- package/dist/src/prompt.d.ts.map +0 -1
- package/dist/src/prompt.js +0 -84
- package/dist/src/prompt.js.map +0 -1
- package/dist/src/session.d.ts +0 -23
- package/dist/src/session.d.ts.map +0 -1
- package/dist/src/session.js +0 -116
- package/dist/src/session.js.map +0 -1
- package/dist/src/utils/extractLlmError.d.ts +0 -13
- package/dist/src/utils/extractLlmError.d.ts.map +0 -1
- package/dist/src/utils/extractLlmError.js +0 -12
- package/dist/src/utils/extractLlmError.js.map +0 -1
- package/dist/src/utils/stripCodeFences.d.ts +0 -2
- package/dist/src/utils/stripCodeFences.d.ts.map +0 -1
- package/dist/src/utils/stripCodeFences.js +0 -9
- package/dist/src/utils/stripCodeFences.js.map +0 -1
package/dist/sat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sat.d.ts","sourceRoot":"","sources":["../sat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAGjD,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"sat.d.ts","sourceRoot":"","sources":["../sat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAGjD,QAAA,MAAM,MAAM,EAAE,MAqDb,CAAA;AAED,eAAe,MAAM,CAAA"}
|
package/dist/sat.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import { createAppendTool, createRefineTool, createRewriteTool } from "./src/tools.js";
|
|
2
|
-
const plugin = async ({ directory
|
|
3
|
-
const
|
|
1
|
+
import { createAppendTool, createDiscoverTool, createRefineTool, createRewriteTool } from "./src/tools.js";
|
|
2
|
+
const plugin = async ({ directory }) => {
|
|
3
|
+
const discovered = new Set();
|
|
4
4
|
return {
|
|
5
5
|
tool: {
|
|
6
|
+
'discover-instructions': createDiscoverTool({
|
|
7
|
+
directory,
|
|
8
|
+
discovered,
|
|
9
|
+
description: [
|
|
10
|
+
'- Discover instruction files from opencode.json configuration.',
|
|
11
|
+
'- Read discovered instruction files and return their paths and contents.',
|
|
12
|
+
'- Optionally accept a files parameter to read specific files instead of running discovery.',
|
|
13
|
+
].join('\n'),
|
|
14
|
+
}),
|
|
6
15
|
'rewrite-instructions': createRewriteTool({
|
|
7
|
-
|
|
16
|
+
directory,
|
|
17
|
+
discovered,
|
|
8
18
|
description: [
|
|
9
19
|
'- Discover instruction files from opencode.json configuration.',
|
|
10
20
|
'- Parse discovered instruction files into structured rules.',
|
|
@@ -16,12 +26,8 @@ const plugin = async ({ directory, client }) => {
|
|
|
16
26
|
].join('\n'),
|
|
17
27
|
}),
|
|
18
28
|
'add-instruction': createAppendTool({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
sessionTitle: 'SAT Add',
|
|
22
|
-
defaultMode: 'balanced',
|
|
23
|
-
hasMode: true,
|
|
24
|
-
successPrefix: 'Added',
|
|
29
|
+
directory,
|
|
30
|
+
discovered,
|
|
25
31
|
description: [
|
|
26
32
|
'- Parse unstructured input into structured rules.',
|
|
27
33
|
'- Format parsed rules after parsing unstructured input into structured rules.',
|
|
@@ -32,22 +38,7 @@ const plugin = async ({ directory, client }) => {
|
|
|
32
38
|
'- Append to the first discovered instruction file when no file parameter is specified.',
|
|
33
39
|
].join('\n'),
|
|
34
40
|
}),
|
|
35
|
-
'automatic-rule': createAppendTool({
|
|
36
|
-
deps,
|
|
37
|
-
toolName: 'automatic-rule',
|
|
38
|
-
sessionTitle: 'SAT Candidate',
|
|
39
|
-
defaultMode: 'balanced',
|
|
40
|
-
hasMode: false,
|
|
41
|
-
successPrefix: 'Learned',
|
|
42
|
-
description: [
|
|
43
|
-
'- Detect user corrections when the user says something was done wrong, expresses a preference about how code should be written, or gives feedback that implies a repeatable guideline.',
|
|
44
|
-
'- Extract the implicit rule from the correction after detecting a user correction or preference.',
|
|
45
|
-
'- Persist the extracted rule as a new instruction rule.',
|
|
46
|
-
'- Append the new rule to the instruction file.',
|
|
47
|
-
].join('\n'),
|
|
48
|
-
}),
|
|
49
41
|
'refine-prompt': createRefineTool({
|
|
50
|
-
deps,
|
|
51
42
|
description: [
|
|
52
43
|
'- Restructure messy, ambiguous, or voice-transcribed user input before starting work when the message is vague, run-on, contains multiple interleaved requests, or reads like unpunctuated speech.',
|
|
53
44
|
'- Invoke this tool BEFORE starting work on vague, run-on, multi-request, or speech-like user messages.',
|
package/dist/sat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sat.js","sourceRoot":"","sources":["../sat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"sat.js","sourceRoot":"","sources":["../sat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAE1G,MAAM,MAAM,GAAW,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE;IAC7C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAA;IAEpC,OAAO;QACL,IAAI,EAAE;YACJ,uBAAuB,EAAE,kBAAkB,CAAC;gBAC1C,SAAS;gBACT,UAAU;gBACV,WAAW,EAAE;oBACX,gEAAgE;oBAChE,0EAA0E;oBAC1E,4FAA4F;iBAC7F,CAAC,IAAI,CAAC,IAAI,CAAC;aACb,CAAC;YAEF,sBAAsB,EAAE,iBAAiB,CAAC;gBACxC,SAAS;gBACT,UAAU;gBACV,WAAW,EAAE;oBACX,gEAAgE;oBAChE,6DAA6D;oBAC7D,sDAAsD;oBACtD,iEAAiE;oBACjE,6FAA6F;oBAC7F,uDAAuD;oBACvD,+FAA+F;iBAChG,CAAC,IAAI,CAAC,IAAI,CAAC;aACb,CAAC;YAEF,iBAAiB,EAAE,gBAAgB,CAAC;gBAClC,SAAS;gBACT,UAAU;gBACV,WAAW,EAAE;oBACX,mDAAmD;oBACnD,+EAA+E;oBAC/E,sFAAsF;oBACtF,uEAAuE;oBACvE,iEAAiE;oBACjE,8EAA8E;oBAC9E,wFAAwF;iBACzF,CAAC,IAAI,CAAC,IAAI,CAAC;aACb,CAAC;YAEF,eAAe,EAAE,gBAAgB,CAAC;gBAChC,WAAW,EAAE;oBACX,oMAAoM;oBACpM,wGAAwG;oBACxG,yFAAyF;oBACzF,0DAA0D;iBAC3D,CAAC,IAAI,CAAC,IAAI,CAAC;aACb,CAAC;SACH;KACF,CAAA;AACH,CAAC,CAAA;AAED,eAAe,MAAM,CAAA"}
|
package/dist/src/append.d.ts
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
1
|
+
import { type FormatMode } from './format.ts';
|
|
2
|
+
import type { ParsedRule } from './rule-schema.ts';
|
|
3
3
|
type AppendResultSuccess = {
|
|
4
4
|
status: 'success';
|
|
5
5
|
path: string;
|
|
6
6
|
rulesCount: number;
|
|
7
7
|
};
|
|
8
|
-
type
|
|
9
|
-
status: '
|
|
8
|
+
type AppendResultReadError = {
|
|
9
|
+
status: 'readError';
|
|
10
10
|
path: string;
|
|
11
11
|
error: string;
|
|
12
12
|
};
|
|
13
|
-
type
|
|
13
|
+
type AppendResultWriteError = {
|
|
14
|
+
status: 'writeError';
|
|
15
|
+
path: string;
|
|
16
|
+
error: string;
|
|
17
|
+
};
|
|
18
|
+
export type AppendResult = AppendResultSuccess | AppendResultReadError | AppendResultWriteError;
|
|
14
19
|
type AppendRulesOptions = {
|
|
15
|
-
input: string;
|
|
16
20
|
filePath: string;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
mode?: FormatMode;
|
|
21
|
+
rules: Array<ParsedRule>;
|
|
22
|
+
mode: FormatMode;
|
|
20
23
|
};
|
|
21
24
|
export declare const appendRules: (options: AppendRulesOptions) => Promise<AppendResult>;
|
|
22
25
|
export {};
|
package/dist/src/append.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"append.d.ts","sourceRoot":"","sources":["../../src/append.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"append.d.ts","sourceRoot":"","sources":["../../src/append.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAGlD,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,SAAS,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,KAAK,qBAAqB,GAAG;IAC3B,MAAM,EAAE,WAAW,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,KAAK,sBAAsB,GAAG;IAC5B,MAAM,EAAE,YAAY,CAAA;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,YAAY,GACpB,mBAAmB,GACnB,qBAAqB,GACrB,sBAAsB,CAAA;AAE1B,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;IACxB,IAAI,EAAE,UAAU,CAAA;CACjB,CAAA;AAyBD,eAAO,MAAM,WAAW,GAAU,SAAS,kBAAkB,KAAG,OAAO,CAAC,YAAY,CAiCnF,CAAA"}
|
package/dist/src/append.js
CHANGED
|
@@ -1,46 +1,41 @@
|
|
|
1
1
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export const appendRules = async (options) => {
|
|
8
|
-
const mode = options.mode ?? 'balanced';
|
|
9
|
-
const fullPath = resolve(options.directory, options.filePath);
|
|
10
|
-
// read existing file content
|
|
11
|
-
const existing = await safeAsync(() => readFile(fullPath, 'utf-8'));
|
|
12
|
-
if (existing.error !== null) {
|
|
13
|
-
return {
|
|
14
|
-
status: 'readError',
|
|
15
|
-
path: options.filePath,
|
|
16
|
-
error: existing.error.message,
|
|
17
|
-
};
|
|
2
|
+
import { formatRules } from "./format.js";
|
|
3
|
+
import { safeAsync } from "./utils/safe.js";
|
|
4
|
+
const computeSeparator = (existing, mode) => {
|
|
5
|
+
if (existing.length === 0) {
|
|
6
|
+
return '';
|
|
18
7
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
if (mode === 'concise') {
|
|
9
|
+
if (existing.endsWith('\n')) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
return '\n';
|
|
13
|
+
}
|
|
14
|
+
if (existing.endsWith('\n\n')) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
if (existing.endsWith('\n')) {
|
|
18
|
+
return '\n';
|
|
27
19
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
return '\n\n';
|
|
21
|
+
};
|
|
22
|
+
export const appendRules = async (options) => {
|
|
23
|
+
const readResult = await safeAsync(() => readFile(options.filePath, 'utf-8'));
|
|
24
|
+
if (readResult.error) {
|
|
32
25
|
return {
|
|
33
|
-
status: '
|
|
26
|
+
status: 'readError',
|
|
34
27
|
path: options.filePath,
|
|
35
|
-
error:
|
|
28
|
+
error: readResult.error.message,
|
|
36
29
|
};
|
|
37
30
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
const
|
|
31
|
+
const formatted = formatRules({
|
|
32
|
+
rules: options.rules,
|
|
33
|
+
mode: options.mode,
|
|
34
|
+
});
|
|
35
|
+
const existing = readResult.data;
|
|
36
|
+
const separator = computeSeparator(existing, options.mode);
|
|
37
|
+
const content = existing + separator + formatted;
|
|
38
|
+
const writeResult = await safeAsync(() => writeFile(options.filePath, content, 'utf-8'));
|
|
44
39
|
if (writeResult.error) {
|
|
45
40
|
return {
|
|
46
41
|
status: 'writeError',
|
|
@@ -51,7 +46,7 @@ export const appendRules = async (options) => {
|
|
|
51
46
|
return {
|
|
52
47
|
status: 'success',
|
|
53
48
|
path: options.filePath,
|
|
54
|
-
rulesCount:
|
|
49
|
+
rulesCount: options.rules.length,
|
|
55
50
|
};
|
|
56
51
|
};
|
|
57
52
|
//# sourceMappingURL=append.js.map
|
package/dist/src/append.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"append.js","sourceRoot":"","sources":["../../src/append.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,
|
|
1
|
+
{"version":3,"file":"append.js","sourceRoot":"","sources":["../../src/append.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAA;AAE1D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AA+B3C,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAE,IAAgB,EAAU,EAAE;IACtE,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5B,OAAO,EAAE,CAAA;QACX,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9B,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,QA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AO,CAAC,KAAK,CAAC,MAAM;KACjC,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-prompt.d.ts","sourceRoot":"","sources":["../../src/format-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"format-prompt.d.ts","sourceRoot":"","sources":["../../src/format-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,oBAAoB,CAAA;AAoHlE,eAAO,MAAM,YAAY,GAAI,QAAQ,YAAY,KAAG,MA8BnD,CAAA"}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
const buildNode = (options) => {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
counter.value++;
|
|
2
|
+
const label = String(options.counter.value) + '. ' + options.task.intent;
|
|
3
|
+
options.counter.value++;
|
|
5
4
|
const metaLines = [];
|
|
6
|
-
if (task.targets.length > 0) {
|
|
7
|
-
metaLines.push('> Targets: ' + task.targets.join(', '));
|
|
5
|
+
if (options.task.targets.length > 0) {
|
|
6
|
+
metaLines.push('> Targets: ' + options.task.targets.join(', '));
|
|
8
7
|
}
|
|
9
|
-
if (task.constraints.length > 0) {
|
|
10
|
-
metaLines.push('> Constraints: ' + task.constraints.join(', '));
|
|
8
|
+
if (options.task.constraints.length > 0) {
|
|
9
|
+
metaLines.push('> Constraints: ' + options.task.constraints.join(', '));
|
|
11
10
|
}
|
|
12
|
-
if (task.context) {
|
|
13
|
-
metaLines.push('> Context: ' + task.context);
|
|
11
|
+
if (options.task.context) {
|
|
12
|
+
metaLines.push('> Context: ' + options.task.context);
|
|
14
13
|
}
|
|
15
|
-
const children = task.subtasks.map((subtask) => {
|
|
16
|
-
return buildNode({ task: subtask, counter });
|
|
14
|
+
const children = options.task.subtasks.map((subtask) => {
|
|
15
|
+
return buildNode({ task: subtask, counter: options.counter });
|
|
17
16
|
});
|
|
18
17
|
return { label, metaLines, children };
|
|
19
18
|
};
|
|
@@ -28,37 +27,47 @@ const flatten = (nodes) => {
|
|
|
28
27
|
return result;
|
|
29
28
|
};
|
|
30
29
|
const renderNode = (options) => {
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const firstLine = prefix + node.label;
|
|
30
|
+
const hasChildren = options.node.children.length > 0;
|
|
31
|
+
const firstLine = options.prefix + options.node.label;
|
|
34
32
|
const lines = [firstLine];
|
|
35
|
-
const numEnd = node.label.indexOf('. ') + 2;
|
|
36
|
-
const textStart = prefix.length + numEnd;
|
|
33
|
+
const numEnd = options.node.label.indexOf('. ') + 2;
|
|
34
|
+
const textStart = options.prefix.length + numEnd;
|
|
37
35
|
const pipe = hasChildren ? '│' : ' ';
|
|
38
|
-
const padLen = textStart - childPrefix.length - 1;
|
|
39
|
-
const metaPad = childPrefix + pipe + ' '.repeat(padLen > 0 ? padLen : 0);
|
|
40
|
-
for (const meta of node.metaLines) {
|
|
36
|
+
const padLen = textStart - options.childPrefix.length - 1;
|
|
37
|
+
const metaPad = options.childPrefix + pipe + ' '.repeat(padLen > 0 ? padLen : 0);
|
|
38
|
+
for (const meta of options.node.metaLines) {
|
|
41
39
|
lines.push(metaPad + meta);
|
|
42
40
|
}
|
|
43
41
|
if (hasChildren) {
|
|
44
|
-
lines.push(childPrefix + '│');
|
|
45
|
-
for (let i = 0; i < node.children.length; i++) {
|
|
46
|
-
const child = node.children[i];
|
|
42
|
+
lines.push(options.childPrefix + '│');
|
|
43
|
+
for (let i = 0; i < options.node.children.length; i++) {
|
|
44
|
+
const child = options.node.children[i];
|
|
47
45
|
if (!child)
|
|
48
46
|
continue;
|
|
49
47
|
if (i > 0) {
|
|
50
|
-
lines.push(childPrefix + '│');
|
|
48
|
+
lines.push(options.childPrefix + '│');
|
|
51
49
|
}
|
|
52
|
-
const isLast = i === node.children.length - 1;
|
|
50
|
+
const isLast = i === options.node.children.length - 1;
|
|
53
51
|
const childHasChildren = child.children.length > 0;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
let connector = isLast ? '└──' : '├──';
|
|
53
|
+
connector += childHasChildren ? '┬ ' : '─ ';
|
|
54
|
+
let continuation = '';
|
|
55
|
+
if (isLast && childHasChildren) {
|
|
56
|
+
continuation = ' ';
|
|
57
|
+
}
|
|
58
|
+
else if (isLast) {
|
|
59
|
+
continuation = ' ';
|
|
60
|
+
}
|
|
61
|
+
else if (childHasChildren) {
|
|
62
|
+
continuation = '│ ';
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
continuation = '│ ';
|
|
66
|
+
}
|
|
58
67
|
const childLines = renderNode({
|
|
59
68
|
node: child,
|
|
60
|
-
prefix: childPrefix + connector,
|
|
61
|
-
childPrefix: childPrefix + continuation,
|
|
69
|
+
prefix: options.childPrefix + connector,
|
|
70
|
+
childPrefix: options.childPrefix + continuation,
|
|
62
71
|
});
|
|
63
72
|
lines.push(...childLines);
|
|
64
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-prompt.js","sourceRoot":"","sources":["../../src/format-prompt.ts"],"names":[],"mappings":"AAeA,MAAM,SAAS,GAAG,CAAC,OAAyB,EAAY,EAAE;IACxD,MAAM,
|
|
1
|
+
{"version":3,"file":"format-prompt.js","sourceRoot":"","sources":["../../src/format-prompt.ts"],"names":[],"mappings":"AAeA,MAAM,SAAS,GAAG,CAAC,OAAyB,EAAY,EAAE;IACxD,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAA;IACxE,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;IAEvB,MAAM,SAAS,GAAkB,EAAE,CAAA;IAEnC,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpC,SAAS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IAAI,CAAC,IAAI,CAAC,CAAA;AACnF,CAAC,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ParsedRule } from './rule-schema.ts';
|
|
2
|
+
export type FormatMode = 'verbose' | 'balanced' | 'concise';
|
|
3
|
+
export declare const FORMAT_MODES: ReadonlyArray<FormatMode>;
|
|
4
|
+
export declare const isFormatMode: (value: unknown) => value is FormatMode;
|
|
5
|
+
type FormatRuleOptions = {
|
|
6
|
+
rule: ParsedRule;
|
|
7
|
+
mode: FormatMode;
|
|
8
|
+
};
|
|
9
|
+
export declare const formatRule: (options: FormatRuleOptions) => string;
|
|
10
|
+
type FormatRulesOptions = {
|
|
11
|
+
rules: Array<ParsedRule>;
|
|
12
|
+
mode: FormatMode;
|
|
13
|
+
};
|
|
14
|
+
export declare const formatRules: (options: FormatRulesOptions) => string;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAA;AAE3D,eAAO,MAAM,YAAY,EAAE,aAAa,CAAC,UAAU,CAIlD,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,UAEtD,CAAA;AAED,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE,UAAU,CAAA;IAChB,IAAI,EAAE,UAAU,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,SAAS,iBAAiB,KAAG,MAavD,CAAA;AAED,KAAK,kBAAkB,GAAG;IACxB,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;IACxB,IAAI,EAAE,UAAU,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,SAAS,kBAAkB,KAAG,MAYzD,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const FORMAT_MODES = [
|
|
2
|
+
'verbose',
|
|
3
|
+
'balanced',
|
|
4
|
+
'concise',
|
|
5
|
+
];
|
|
6
|
+
export const isFormatMode = (value) => {
|
|
7
|
+
return FORMAT_MODES.includes(value);
|
|
8
|
+
};
|
|
9
|
+
export const formatRule = (options) => {
|
|
10
|
+
const parts = [options.rule.action, options.rule.target];
|
|
11
|
+
if (options.rule.context) {
|
|
12
|
+
parts.push(options.rule.context);
|
|
13
|
+
}
|
|
14
|
+
const ruleLine = 'Rule: ' + parts.join(' ');
|
|
15
|
+
if (options.mode === 'concise') {
|
|
16
|
+
return ruleLine;
|
|
17
|
+
}
|
|
18
|
+
return ruleLine + '\nReason: ' + options.rule.reason;
|
|
19
|
+
};
|
|
20
|
+
export const formatRules = (options) => {
|
|
21
|
+
if (options.rules.length === 0) {
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
const formatted = options.rules.map((rule) => {
|
|
25
|
+
return formatRule({ rule, mode: options.mode });
|
|
26
|
+
});
|
|
27
|
+
const joiner = options.mode === 'concise' ? '\n' : '\n\n';
|
|
28
|
+
return formatted.join(joiner) + '\n';
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,YAAY,GAA8B;IACrD,SAAS;IACT,UAAU;IACV,SAAS;CACV,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAc,EAAuB,EAAE;IAClE,OAAO,YAAY,CAAC,QAAQ,CAAC,KAAmB,CAAC,CAAA;AACnD,CAAC,CAAA;AAOD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAA0B,EAAU,EAAE;IAC/D,MAAM,KAAK,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAExD,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACzB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAClC,CAAC;IAED,MAAM,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC3C,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,OAAO,QAAQ,GAAG,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAA;AACtD,CAAC,CAAA;AAOD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAA2B,EAAU,EAAE;IACjE,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3C,OAAO,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;IACjD,CAAC,CAAC,CAAA;IAEF,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAA;IAEzD,OAAO,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAA;AACtC,CAAC,CAAA"}
|
package/dist/src/process.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
4
|
-
import { type ComparisonResult } from './utils/compare';
|
|
5
|
-
import type { Result } from './utils/safe';
|
|
1
|
+
import type { InstructionFile } from './discover.ts';
|
|
2
|
+
import { type FormatMode } from './format.ts';
|
|
3
|
+
import type { ParsedRule } from './rule-schema.ts';
|
|
4
|
+
import { type ComparisonResult } from './utils/compare.ts';
|
|
6
5
|
type FileResultSuccess = {
|
|
7
6
|
status: 'success';
|
|
8
7
|
path: string;
|
|
@@ -10,16 +9,15 @@ type FileResultSuccess = {
|
|
|
10
9
|
comparison: ComparisonResult;
|
|
11
10
|
};
|
|
12
11
|
type FileResultError = {
|
|
13
|
-
status: 'readError' | '
|
|
12
|
+
status: 'readError' | 'writeError';
|
|
14
13
|
path: string;
|
|
15
14
|
error: string;
|
|
16
15
|
};
|
|
17
16
|
export type FileResult = FileResultSuccess | FileResultError;
|
|
18
|
-
export type PromptFn = <T>(prompt: string, schema: z.ZodType<T>) => Promise<Result<T>>;
|
|
19
17
|
type ProcessFileOptions = {
|
|
20
18
|
file: InstructionFile;
|
|
21
|
-
|
|
22
|
-
mode
|
|
19
|
+
rules: Array<ParsedRule>;
|
|
20
|
+
mode: FormatMode;
|
|
23
21
|
};
|
|
24
22
|
export declare const processFile: (options: ProcessFileOptions) => Promise<FileResult>;
|
|
25
23
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/process.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/process.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AACpD,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAGxE,KAAK,iBAAiB,GAAG;IACvB,MAAM,EAAE,SAAS,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,gBAAgB,CAAA;CAC7B,CAAA;AAED,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE,WAAW,GAAG,YAAY,CAAA;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,iBAAiB,GAAG,eAAe,CAAA;AAE5D,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,eAAe,CAAA;IACrB,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;IACxB,IAAI,EAAE,UAAU,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,WAAW,GAAU,SAAS,kBAAkB,KAAG,OAAO,CAAC,UAAU,CA+BjF,CAAA"}
|
package/dist/src/process.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { writeFile } from 'node:fs/promises';
|
|
2
2
|
import { basename } from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { safeAsync } from './utils/safe';
|
|
7
|
-
// process a single instruction file through the parse -> format -> write pipeline
|
|
3
|
+
import { formatRules } from "./format.js";
|
|
4
|
+
import { compareBytes } from "./utils/compare.js";
|
|
5
|
+
import { safeAsync } from "./utils/safe.js";
|
|
8
6
|
export const processFile = async (options) => {
|
|
9
|
-
const mode = options.mode ?? 'balanced';
|
|
10
|
-
// skip files that failed to read
|
|
11
7
|
if (options.file.error) {
|
|
12
8
|
return {
|
|
13
9
|
status: 'readError',
|
|
@@ -15,28 +11,10 @@ export const processFile = async (options) => {
|
|
|
15
11
|
error: options.file.error,
|
|
16
12
|
};
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
status: 'parseError',
|
|
23
|
-
path: options.file.path,
|
|
24
|
-
error: String(parseResult.error),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
// step 2: format structured rules -> human-readable rules
|
|
28
|
-
const formatResult = await options.prompt(buildFormatPrompt(JSON.stringify(parseResult.data), mode), FormatResponseSchema);
|
|
29
|
-
if (formatResult.error !== null) {
|
|
30
|
-
return {
|
|
31
|
-
status: 'formatError',
|
|
32
|
-
path: options.file.path,
|
|
33
|
-
error: String(formatResult.error),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
// step 3: write formatted rules back to original file
|
|
37
|
-
const formattedRules = formatResult.data.rules;
|
|
38
|
-
const joiner = mode === 'concise' ? '\n' : '\n\n';
|
|
39
|
-
const content = formattedRules.join(joiner) + '\n';
|
|
14
|
+
const content = formatRules({
|
|
15
|
+
rules: options.rules,
|
|
16
|
+
mode: options.mode,
|
|
17
|
+
});
|
|
40
18
|
const writeResult = await safeAsync(() => writeFile(options.file.path, content, 'utf-8'));
|
|
41
19
|
if (writeResult.error) {
|
|
42
20
|
return {
|
|
@@ -49,7 +27,7 @@ export const processFile = async (options) => {
|
|
|
49
27
|
return {
|
|
50
28
|
status: 'success',
|
|
51
29
|
path: options.file.path,
|
|
52
|
-
rulesCount:
|
|
30
|
+
rulesCount: options.rules.length,
|
|
53
31
|
comparison,
|
|
54
32
|
};
|
|
55
33
|
};
|
package/dist/src/process.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,OAAO,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAA;AAE1D,OAAO,EAAE,YAAY,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type Client = PluginInput['client'];
|
|
4
|
-
type ToolDeps = {
|
|
1
|
+
type DiscoverToolOptions = {
|
|
2
|
+
description: string;
|
|
5
3
|
directory: string;
|
|
6
|
-
|
|
4
|
+
discovered: Set<string>;
|
|
5
|
+
};
|
|
6
|
+
export declare const createDiscoverTool: (options: DiscoverToolOptions) => {
|
|
7
|
+
description: string;
|
|
8
|
+
args: {
|
|
9
|
+
files: import("zod").ZodOptional<import("zod").ZodString>;
|
|
10
|
+
};
|
|
11
|
+
execute(args: {
|
|
12
|
+
files?: string | undefined;
|
|
13
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
7
14
|
};
|
|
8
15
|
type RewriteToolOptions = {
|
|
9
16
|
description: string;
|
|
10
|
-
|
|
17
|
+
directory: string;
|
|
18
|
+
discovered: Set<string>;
|
|
11
19
|
};
|
|
12
20
|
export declare const createRewriteTool: (options: RewriteToolOptions) => {
|
|
13
21
|
description: string;
|
|
14
22
|
args: {
|
|
23
|
+
rules: import("zod").ZodString;
|
|
15
24
|
mode: import("zod").ZodOptional<import("zod").ZodString>;
|
|
16
25
|
files: import("zod").ZodOptional<import("zod").ZodString>;
|
|
17
26
|
};
|
|
18
27
|
execute(args: {
|
|
28
|
+
rules: string;
|
|
19
29
|
mode?: string | undefined;
|
|
20
30
|
files?: string | undefined;
|
|
21
31
|
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
22
32
|
};
|
|
23
33
|
type AppendToolOptions = {
|
|
24
34
|
description: string;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
sessionTitle: string;
|
|
28
|
-
defaultMode: FormatMode;
|
|
29
|
-
successPrefix: string;
|
|
30
|
-
hasMode: boolean;
|
|
35
|
+
directory: string;
|
|
36
|
+
discovered: Set<string>;
|
|
31
37
|
};
|
|
32
38
|
export declare const createAppendTool: (options: AppendToolOptions) => {
|
|
33
39
|
description: string;
|
|
34
40
|
args: {
|
|
35
|
-
mode?: import("zod").ZodOptional<import("zod").ZodString> | undefined;
|
|
36
41
|
input: import("zod").ZodString;
|
|
42
|
+
rules: import("zod").ZodString;
|
|
37
43
|
file: import("zod").ZodOptional<import("zod").ZodString>;
|
|
44
|
+
mode: import("zod").ZodOptional<import("zod").ZodString>;
|
|
38
45
|
};
|
|
39
46
|
execute(args: {
|
|
40
|
-
mode?: unknown;
|
|
41
47
|
input: string;
|
|
48
|
+
rules: string;
|
|
42
49
|
file?: string | undefined;
|
|
50
|
+
mode?: string | undefined;
|
|
43
51
|
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
44
52
|
};
|
|
45
53
|
type RefineToolOptions = {
|
|
46
54
|
description: string;
|
|
47
|
-
deps: ToolDeps;
|
|
48
55
|
};
|
|
49
56
|
export declare const createRefineTool: (options: RefineToolOptions) => {
|
|
50
57
|
description: string;
|
|
51
58
|
args: {
|
|
52
59
|
input: import("zod").ZodString;
|
|
60
|
+
tasks: import("zod").ZodString;
|
|
53
61
|
};
|
|
54
62
|
execute(args: {
|
|
55
63
|
input: string;
|
|
64
|
+
tasks: string;
|
|
56
65
|
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
57
66
|
};
|
|
58
67
|
export {};
|
package/dist/src/tools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/tools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/tools.ts"],"names":[],"mappings":"AAyDA,KAAK,mBAAmB,GAAG;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,SAAS,mBAAmB;;;;;;;;CAsC9D,CAAA;AAED,KAAK,kBAAkB,GAAG;IACxB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,SAAS,kBAAkB;;;;;;;;;;;;CAkD5D,CAAA;AAED,KAAK,iBAAiB,GAAG;IACvB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,SAAS,iBAAiB;;;;;;;;;;;;;;CA0D1D,CAAA;AAED,KAAK,iBAAiB,GAAG;IACvB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,SAAS,iBAAiB;;;;;;;;;;CAuB1D,CAAA"}
|