opencode-irf 0.0.5 → 0.0.6
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/irf.d.ts +4 -0
- package/dist/irf.d.ts.map +1 -0
- package/dist/irf.js +125 -626
- package/dist/irf.js.map +1 -0
- package/dist/src/discover.d.ts +11 -0
- package/dist/src/discover.d.ts.map +1 -0
- package/dist/src/discover.js +92 -0
- package/dist/src/discover.js.map +1 -0
- package/dist/src/process.d.ts +26 -0
- package/dist/src/process.d.ts.map +1 -0
- package/dist/src/process.js +56 -0
- package/dist/src/process.js.map +1 -0
- package/dist/src/prompt.d.ts +7 -0
- package/dist/src/prompt.d.ts.map +1 -0
- package/dist/src/prompt.js +84 -0
- package/dist/src/prompt.js.map +1 -0
- package/dist/src/schema.d.ts +69 -0
- package/dist/src/schema.d.ts.map +1 -0
- package/dist/src/schema.js +48 -0
- package/dist/src/schema.js.map +1 -0
- package/dist/src/session.d.ts +23 -0
- package/dist/src/session.d.ts.map +1 -0
- package/dist/src/session.js +112 -0
- package/dist/src/session.js.map +1 -0
- package/dist/src/utils/compare.d.ts +18 -0
- package/dist/src/utils/compare.d.ts.map +1 -0
- package/dist/src/utils/compare.js +74 -0
- package/dist/src/utils/compare.js.map +1 -0
- package/dist/src/utils/extractLlmError.d.ts +13 -0
- package/dist/src/utils/extractLlmError.d.ts.map +1 -0
- package/dist/src/utils/extractLlmError.js +12 -0
- package/dist/src/utils/extractLlmError.js.map +1 -0
- package/dist/src/utils/safe.d.ts +12 -0
- package/dist/src/utils/safe.d.ts.map +1 -0
- package/dist/src/utils/safe.js +31 -0
- package/dist/src/utils/safe.js.map +1 -0
- package/dist/src/utils/stripCodeFences.d.ts +2 -0
- package/dist/src/utils/stripCodeFences.d.ts.map +1 -0
- package/dist/src/utils/stripCodeFences.js +9 -0
- package/dist/src/utils/stripCodeFences.js.map +1 -0
- package/dist/src/utils/validate.d.ts +19 -0
- package/dist/src/utils/validate.d.ts.map +1 -0
- package/dist/src/utils/validate.js +30 -0
- package/dist/src/utils/validate.js.map +1 -0
- package/package.json +5 -3
package/dist/irf.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"irf.js","sourceRoot":"","sources":["../irf.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAExD,OAAO,EAAmB,WAAW,EAAiB,MAAM,eAAe,CAAA;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAyB,MAAM,qBAAqB,CAAA;AAEvE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAE5C,2EAA2E;AAC3E,MAAM,YAAY,GAAG,KAAK,EAAE,SAAiB,EAAE,QAAiB,EAAsC,EAAE;IACtG,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAClF,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,8BAA8B,EAAE,CAAA;QAC9D,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;IACrE,CAAC;IAED,OAAO,MAAM,QAAQ,CAAC,SAAS,CAAC,CAAA;AAClC,CA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AG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;wBAC5D,OAAO,qBAAqB,GAAG,GAAG,CAAA;oBACpC,CAAC;gBACH,CAAC;aACF,CAAC;SACH;KACF,CAAA;AACH,CAAC,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Result } from './utils/safe';
|
|
2
|
+
export type InstructionFile = {
|
|
3
|
+
path: string;
|
|
4
|
+
content: string;
|
|
5
|
+
error?: string;
|
|
6
|
+
};
|
|
7
|
+
type DiscoverResult = Result<InstructionFile[]>;
|
|
8
|
+
export declare const readFilePaths: (directory: string, paths: string[]) => Promise<InstructionFile[]>;
|
|
9
|
+
export declare const discover: (directory: string) => Promise<DiscoverResult>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=discover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../../src/discover.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,MAAM,EAAmB,MAAM,cAAc,CAAA;AAE3D,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,KAAK,cAAc,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC,CAAA;AA4E/C,eAAO,MAAM,aAAa,GAAU,WAAW,MAAM,EAAE,OAAO,MAAM,EAAE,KAAG,OAAO,CAAC,eAAe,EAAE,CAGjG,CAAA;AAED,eAAO,MAAM,QAAQ,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,cAAc,CAwBxE,CAAA"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { glob, readFile } from 'node:fs/promises';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { safe, safeAsync } from './utils/safe';
|
|
4
|
+
const readConfig = async (directory) => {
|
|
5
|
+
const configPath = join(directory, 'opencode.json');
|
|
6
|
+
const { data, error } = await safeAsync(() => readFile(configPath, 'utf-8'));
|
|
7
|
+
if (error) {
|
|
8
|
+
return {
|
|
9
|
+
data: null,
|
|
10
|
+
error: 'Could not read ' + configPath + ': ' + error.message,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const { data: parsed, error: parseError } = safe(() => JSON.parse(data));
|
|
14
|
+
if (parseError) {
|
|
15
|
+
return {
|
|
16
|
+
data: null,
|
|
17
|
+
error: 'Invalid JSON in ' + configPath + ': ' + parseError.message,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const instructions = parsed.instructions;
|
|
21
|
+
if (!instructions || !Array.isArray(instructions) || instructions.length === 0) {
|
|
22
|
+
return {
|
|
23
|
+
data: null,
|
|
24
|
+
error: 'No "instructions" array found in ' + configPath,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const patterns = instructions.filter((entry) => typeof entry === 'string');
|
|
28
|
+
if (patterns.length === 0) {
|
|
29
|
+
return {
|
|
30
|
+
data: null,
|
|
31
|
+
error: 'No valid string patterns in "instructions" in ' + configPath,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
data: patterns,
|
|
36
|
+
error: null,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const resolveFiles = async (directory, patterns) => {
|
|
40
|
+
const seen = new Set();
|
|
41
|
+
const files = [];
|
|
42
|
+
for (const pattern of patterns) {
|
|
43
|
+
for await (const path of glob(pattern, { cwd: directory })) {
|
|
44
|
+
const full = join(directory, path);
|
|
45
|
+
if (!seen.has(full)) {
|
|
46
|
+
seen.add(full);
|
|
47
|
+
files.push(full);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return files;
|
|
52
|
+
};
|
|
53
|
+
const readFiles = async (files) => {
|
|
54
|
+
const results = [];
|
|
55
|
+
for (const file of files) {
|
|
56
|
+
const { data, error } = await safeAsync(() => readFile(file, 'utf-8'));
|
|
57
|
+
if (error) {
|
|
58
|
+
results.push({ path: file, content: '', error: error.message });
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
results.push({ path: file, content: data });
|
|
62
|
+
}
|
|
63
|
+
return results;
|
|
64
|
+
};
|
|
65
|
+
// read specific file paths into InstructionFile entries, resolving relative paths against directory
|
|
66
|
+
export const readFilePaths = async (directory, paths) => {
|
|
67
|
+
const resolved = paths.map((p) => resolve(directory, p));
|
|
68
|
+
return await readFiles(resolved);
|
|
69
|
+
};
|
|
70
|
+
export const discover = async (directory) => {
|
|
71
|
+
const config = await readConfig(directory);
|
|
72
|
+
if (config.error !== null) {
|
|
73
|
+
return {
|
|
74
|
+
data: null,
|
|
75
|
+
error: config.error,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const patterns = config.data;
|
|
79
|
+
const files = await resolveFiles(directory, patterns);
|
|
80
|
+
if (files.length === 0) {
|
|
81
|
+
return {
|
|
82
|
+
data: null,
|
|
83
|
+
error: 'No instruction files found matching patterns: ' + patterns.join(', '),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const results = await readFiles(files);
|
|
87
|
+
return {
|
|
88
|
+
data: results,
|
|
89
|
+
error: null,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=discover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.js","sourceRoot":"","sources":["../../src/discover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAe,IAAI,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAW3D,MAAM,UAAU,GAAG,KA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
+
import { type ComparisonResult } from './utils/compare';
|
|
5
|
+
import type { Result } from './utils/safe';
|
|
6
|
+
type FileResultSuccess = {
|
|
7
|
+
status: 'success';
|
|
8
|
+
path: string;
|
|
9
|
+
rulesCount: number;
|
|
10
|
+
comparison: ComparisonResult;
|
|
11
|
+
};
|
|
12
|
+
type FileResultError = {
|
|
13
|
+
status: 'readError' | 'parseError' | 'formatError' | 'writeError';
|
|
14
|
+
path: string;
|
|
15
|
+
error: string;
|
|
16
|
+
};
|
|
17
|
+
export type FileResult = FileResultSuccess | FileResultError;
|
|
18
|
+
export type PromptFn = <T>(prompt: string, schema: z.ZodType<T>) => Promise<Result<T>>;
|
|
19
|
+
type ProcessFileOptions = {
|
|
20
|
+
file: InstructionFile;
|
|
21
|
+
prompt: PromptFn;
|
|
22
|
+
mode?: FormatMode;
|
|
23
|
+
};
|
|
24
|
+
export declare const processFile: (options: ProcessFileOptions) => Promise<FileResult>;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/process.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAuC,KAAK,UAAU,EAAE,MAAM,UAAU,CAAA;AAE/E,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACrE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAG1C,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,GAAG,aAAa,GAAG,YAAY,CAAA;IACjE,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,iBAAiB,GAAG,eAAe,CAAA;AAG5D,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AAEtF,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,eAAe,CAAA;IACrB,MAAM,EAAE,QAAQ,CAAA;IAChB,IAAI,CAAC,EAAE,UAAU,CAAA;CAClB,CAAA;AAGD,eAAO,MAAM,WAAW,GAAU,SAAS,kBAAkB,KAAG,OAAO,CAAC,UAAU,CAsDjF,CAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
import { basename } from 'node:path';
|
|
3
|
+
import { buildFormatPrompt, buildParsePrompt } from './prompt';
|
|
4
|
+
import { FormatResponseSchema, ParseResponseSchema } from './schema';
|
|
5
|
+
import { compareBytes } from './utils/compare';
|
|
6
|
+
import { safeAsync } from './utils/safe';
|
|
7
|
+
// process a single instruction file through the parse -> format -> write pipeline
|
|
8
|
+
export const processFile = async (options) => {
|
|
9
|
+
const { file, prompt, mode = 'balanced' } = options;
|
|
10
|
+
// skip files that failed to read
|
|
11
|
+
if (file.error) {
|
|
12
|
+
return {
|
|
13
|
+
status: 'readError',
|
|
14
|
+
path: file.path,
|
|
15
|
+
error: file.error,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
// step 1: parse instruction text -> structured rules
|
|
19
|
+
const parseResult = await prompt(buildParsePrompt(file.content), ParseResponseSchema);
|
|
20
|
+
if (parseResult.error !== null) {
|
|
21
|
+
return {
|
|
22
|
+
status: 'parseError',
|
|
23
|
+
path: file.path,
|
|
24
|
+
error: String(parseResult.error),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// step 2: format structured rules -> human-readable rules
|
|
28
|
+
const formatResult = await prompt(buildFormatPrompt(JSON.stringify(parseResult.data), mode), FormatResponseSchema);
|
|
29
|
+
if (formatResult.error !== null) {
|
|
30
|
+
return {
|
|
31
|
+
status: 'formatError',
|
|
32
|
+
path: 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';
|
|
40
|
+
const { error: writeError } = await safeAsync(() => writeFile(file.path, content, 'utf-8'));
|
|
41
|
+
if (writeError) {
|
|
42
|
+
return {
|
|
43
|
+
status: 'writeError',
|
|
44
|
+
path: file.path,
|
|
45
|
+
error: writeError.message,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const comparison = compareBytes(basename(file.path), file.content, content);
|
|
49
|
+
return {
|
|
50
|
+
status: 'success',
|
|
51
|
+
path: file.path,
|
|
52
|
+
rulesCount: formattedRules.length,
|
|
53
|
+
comparison,
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +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;AAGpC,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAmB,MAAM,UAAU,CAAA;AAC/E,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AACpE,OAAO,EAAE,YAAY,EAAyB,MAAM,iBAAiB,C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AI,CAAC,CAAC,CAAC,MAAM,CAAA;IACjD,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAA;IAClD,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;IAC3F,IAAI,UAAU,EAAE,CAAC;QACf,OAAO;YACL,MAAM,EAAE,YAAY;YACpB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,UAAU,CAAC,OAAO;SAC1B,CAAA;IACH,CAAC;IAED,MAAM,UAAU,GAAG,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC3E,OAAO;QACL,MAAM,EAAE,SAAS;QACjB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,UAAU,EAAE,cAAc,CAAC,MAAM;QACjC,UAAU;KACX,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type FormatMode = 'verbose' | 'balanced' | 'concise';
|
|
2
|
+
export declare const FORMAT_MODES: FormatMode[];
|
|
3
|
+
export declare const isFormatMode: (v: unknown) => v is FormatMode;
|
|
4
|
+
export declare const buildParsePrompt: (input: string) => string;
|
|
5
|
+
export declare const buildFormatPrompt: (parsedRulesJson: string, mode?: FormatMode) => string;
|
|
6
|
+
export declare const buildRetryPrompt: (errorMessage: string) => string;
|
|
7
|
+
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/prompt.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAA;AAE3D,eAAO,MAAM,YAAY,EAAE,UAAU,EAAuC,CAAA;AAE5E,eAAO,MAAM,YAAY,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,UACkB,CAAA;AAEjE,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,KAAG,MAchD,CAAA;AAgED,eAAO,MAAM,iBAAiB,GAAI,iBAAiB,MAAM,EAAE,OAAM,UAAuB,KAAG,MAG1F,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,cAAc,MAAM,KAAG,MAGvD,CAAA"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { parseSchemaExample } from './schema';
|
|
2
|
+
export const FORMAT_MODES = ['verbose', 'balanced', 'concise'];
|
|
3
|
+
export const isFormatMode = (v) => typeof v === 'string' && FORMAT_MODES.includes(v);
|
|
4
|
+
export const buildParsePrompt = (input) => {
|
|
5
|
+
const instructions = [
|
|
6
|
+
'You are a rule parser that converts raw instructions into structured parsed rules.',
|
|
7
|
+
'Take the provided instructions and break them down into structured components.',
|
|
8
|
+
'Each rule should have: strength, action (verb), target (object), context (optional condition/scope), and reason (justification).',
|
|
9
|
+
'Focus on extracting the core components without adding extra details.',
|
|
10
|
+
'',
|
|
11
|
+
'Return ONLY valid JSON matching this exact schema:',
|
|
12
|
+
parseSchemaExample,
|
|
13
|
+
'',
|
|
14
|
+
'Do not include any text outside the JSON object. Do not wrap it in markdown code fences.',
|
|
15
|
+
].join('\n');
|
|
16
|
+
return [instructions, 'Instructions to parse:', input].join('\n\n');
|
|
17
|
+
};
|
|
18
|
+
const verboseInstructions = [
|
|
19
|
+
'You are a rule formatter that converts structured parsed rules into human-readable rules.',
|
|
20
|
+
'Take the provided parsed rule components and create natural language versions.',
|
|
21
|
+
'Every rule must include both a Rule line and a Reason line.',
|
|
22
|
+
'Each rule must follow this exact format:',
|
|
23
|
+
'',
|
|
24
|
+
'Rule: <clear, concise, actionable statement>',
|
|
25
|
+
'Reason: <justification from the parsed rule>',
|
|
26
|
+
'',
|
|
27
|
+
'Each human-readable rule should directly correspond to the parsed components without adding extra details.',
|
|
28
|
+
'Make the rules clear, concise, and actionable.',
|
|
29
|
+
'',
|
|
30
|
+
'Return ONLY valid JSON matching this exact schema:',
|
|
31
|
+
'{"rules": ["Rule: ...\\nReason: ...", "Rule: ...\\nReason: ..."]}',
|
|
32
|
+
'',
|
|
33
|
+
'Do not include any text outside the JSON object. Do not wrap it in markdown code fences.',
|
|
34
|
+
];
|
|
35
|
+
const balancedInstructions = [
|
|
36
|
+
'You are a rule formatter that converts structured parsed rules into human-readable rules.',
|
|
37
|
+
'Take the provided parsed rule components and create natural language versions.',
|
|
38
|
+
'Use your judgment for each rule:',
|
|
39
|
+
'- If the rule is non-obvious or counterintuitive, include both the Rule and Reason lines.',
|
|
40
|
+
'- If the rule is self-explanatory, include only the Rule line and omit the Reason.',
|
|
41
|
+
'',
|
|
42
|
+
'Format rules that include a reason:',
|
|
43
|
+
'Rule: <clear, concise, actionable statement>',
|
|
44
|
+
'Reason: <justification from the parsed rule>',
|
|
45
|
+
'',
|
|
46
|
+
'Format rules that are self-explanatory:',
|
|
47
|
+
'Rule: <clear, concise, actionable statement>',
|
|
48
|
+
'',
|
|
49
|
+
'Each human-readable rule should directly correspond to the parsed components without adding extra details.',
|
|
50
|
+
'Make the rules clear, concise, and actionable.',
|
|
51
|
+
'',
|
|
52
|
+
'Return ONLY valid JSON matching this exact schema:',
|
|
53
|
+
'{"rules": ["Rule: ...\\nReason: ...", "Rule: ..."]}',
|
|
54
|
+
'',
|
|
55
|
+
'Do not include any text outside the JSON object. Do not wrap it in markdown code fences.',
|
|
56
|
+
];
|
|
57
|
+
const conciseInstructions = [
|
|
58
|
+
'You are a rule formatter that converts structured parsed rules into concise directives.',
|
|
59
|
+
'Take the provided parsed rule components and create a bullet list of clear directives.',
|
|
60
|
+
'Do not include reasons or justifications. Output only the actionable statement.',
|
|
61
|
+
'Each rule must be a single line starting with "- " (dash space).',
|
|
62
|
+
'',
|
|
63
|
+
'Each directive should directly correspond to the parsed components without adding extra details.',
|
|
64
|
+
'Make the directives clear, concise, and actionable.',
|
|
65
|
+
'',
|
|
66
|
+
'Return ONLY valid JSON matching this exact schema:',
|
|
67
|
+
'{"rules": ["- ...", "- ..."]}',
|
|
68
|
+
'',
|
|
69
|
+
'Do not include any text outside the JSON object. Do not wrap it in markdown code fences.',
|
|
70
|
+
];
|
|
71
|
+
const formatInstructions = {
|
|
72
|
+
verbose: verboseInstructions,
|
|
73
|
+
balanced: balancedInstructions,
|
|
74
|
+
concise: conciseInstructions,
|
|
75
|
+
};
|
|
76
|
+
export const buildFormatPrompt = (parsedRulesJson, mode = 'balanced') => {
|
|
77
|
+
const instructions = formatInstructions[mode].join('\n');
|
|
78
|
+
return [instructions, 'Parsed rules to convert:', parsedRulesJson].join('\n\n');
|
|
79
|
+
};
|
|
80
|
+
export const buildRetryPrompt = (errorMessage) => {
|
|
81
|
+
return 'Your previous response was invalid. ' + errorMessage
|
|
82
|
+
+ '\n\nReturn ONLY valid JSON. Do not include any text outside the JSON object.';
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAI7C,MAAM,CAAC,MAAM,YAAY,GAAiB,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC,CAAA;AAE5E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAU,EAAmB,EAAE,CAC1D,OAAO,CAAC,KAAK,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAe,CAAC,CAAA;AAEjE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAU,EAAE;IACxD,MAAM,YAAY,GAAG;QACnB,oFAAoF;QACpF,gFAAgF;QAChF,kIAAkI;QAClI,uEAAuE;QACvE,EAAE;QACF,oDAAoD;QAC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AC,IAAI,CAAC,CAAA;IACxD,OAAO,CAAC,YAAY,EAAE,0BAA0B,EAAE,eAAe,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AACjF,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,YAAoB,EAAU,EAAE;IAC/D,OAAO,sCAAsC,GAAG,YAAY;UACxD,8EAA8E,CAAA;AACpF,CAAC,CAAA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const StrengthSchema: z.ZodEnum<{
|
|
3
|
+
obligatory: "obligatory";
|
|
4
|
+
permissible: "permissible";
|
|
5
|
+
forbidden: "forbidden";
|
|
6
|
+
optional: "optional";
|
|
7
|
+
supererogatory: "supererogatory";
|
|
8
|
+
indifferent: "indifferent";
|
|
9
|
+
omissible: "omissible";
|
|
10
|
+
}>;
|
|
11
|
+
export declare const ActionSchema: z.ZodString;
|
|
12
|
+
export declare const TargetSchema: z.ZodString;
|
|
13
|
+
export declare const ContextSchema: z.ZodString;
|
|
14
|
+
export declare const ReasonSchema: z.ZodString;
|
|
15
|
+
export declare const ParsedRuleSchema: z.ZodObject<{
|
|
16
|
+
strength: z.ZodEnum<{
|
|
17
|
+
obligatory: "obligatory";
|
|
18
|
+
permissible: "permissible";
|
|
19
|
+
forbidden: "forbidden";
|
|
20
|
+
optional: "optional";
|
|
21
|
+
supererogatory: "supererogatory";
|
|
22
|
+
indifferent: "indifferent";
|
|
23
|
+
omissible: "omissible";
|
|
24
|
+
}>;
|
|
25
|
+
action: z.ZodString;
|
|
26
|
+
target: z.ZodString;
|
|
27
|
+
context: z.ZodOptional<z.ZodString>;
|
|
28
|
+
reason: z.ZodString;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export declare const RuleSchema: z.ZodString;
|
|
31
|
+
export declare const ParsedSchema: z.ZodArray<z.ZodObject<{
|
|
32
|
+
strength: z.ZodEnum<{
|
|
33
|
+
obligatory: "obligatory";
|
|
34
|
+
permissible: "permissible";
|
|
35
|
+
forbidden: "forbidden";
|
|
36
|
+
optional: "optional";
|
|
37
|
+
supererogatory: "supererogatory";
|
|
38
|
+
indifferent: "indifferent";
|
|
39
|
+
omissible: "omissible";
|
|
40
|
+
}>;
|
|
41
|
+
action: z.ZodString;
|
|
42
|
+
target: z.ZodString;
|
|
43
|
+
context: z.ZodOptional<z.ZodString>;
|
|
44
|
+
reason: z.ZodString;
|
|
45
|
+
}, z.core.$strip>>;
|
|
46
|
+
export declare const ParseResponseSchema: z.ZodObject<{
|
|
47
|
+
rules: z.ZodArray<z.ZodObject<{
|
|
48
|
+
strength: z.ZodEnum<{
|
|
49
|
+
obligatory: "obligatory";
|
|
50
|
+
permissible: "permissible";
|
|
51
|
+
forbidden: "forbidden";
|
|
52
|
+
optional: "optional";
|
|
53
|
+
supererogatory: "supererogatory";
|
|
54
|
+
indifferent: "indifferent";
|
|
55
|
+
omissible: "omissible";
|
|
56
|
+
}>;
|
|
57
|
+
action: z.ZodString;
|
|
58
|
+
target: z.ZodString;
|
|
59
|
+
context: z.ZodOptional<z.ZodString>;
|
|
60
|
+
reason: z.ZodString;
|
|
61
|
+
}, z.core.$strip>>;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
export declare const FormatResponseSchema: z.ZodObject<{
|
|
64
|
+
rules: z.ZodArray<z.ZodString>;
|
|
65
|
+
}, z.core.$strip>;
|
|
66
|
+
export type Strength = z.infer<typeof StrengthSchema>;
|
|
67
|
+
export type ParsedRule = z.infer<typeof ParsedRuleSchema>;
|
|
68
|
+
export declare const parseSchemaExample: string;
|
|
69
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,cAAc;;;;;;;;EASoC,CAAA;AAE/D,eAAO,MAAM,YAAY,aACmC,CAAA;AAE5D,eAAO,MAAM,YAAY,aAC6B,CAAA;AAEtD,eAAO,MAAM,aAAa,aAC4C,CAAA;AAEtE,eAAO,MAAM,YAAY,aAC2B,CAAA;AAEpD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;iBAOuC,CAAA;AAEpE,eAAO,MAAM,UAAU,aAC0C,CAAA;AAEjE,eAAO,MAAM,YAAY;;;;;;;;;;;;;;kBACW,CAAA;AAEpC,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;iBAE9B,CAAA;AAEF,eAAO,MAAM,oBAAoB;;iBAE/B,CAAA;AAEF,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAA;AACrD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAGzD,eAAO,MAAM,kBAAkB,QAQ7B,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const StrengthSchema = z.enum([
|
|
3
|
+
'obligatory',
|
|
4
|
+
'permissible',
|
|
5
|
+
'forbidden',
|
|
6
|
+
'optional',
|
|
7
|
+
'supererogatory',
|
|
8
|
+
'indifferent',
|
|
9
|
+
'omissible',
|
|
10
|
+
])
|
|
11
|
+
.describe('Deontic modality expressing enforcement strength');
|
|
12
|
+
export const ActionSchema = z.string()
|
|
13
|
+
.describe('Imperative verb describing the action to take');
|
|
14
|
+
export const TargetSchema = z.string()
|
|
15
|
+
.describe('Object or subject the action applies to');
|
|
16
|
+
export const ContextSchema = z.string()
|
|
17
|
+
.describe('Condition, scope, or circumstance when the rule applies');
|
|
18
|
+
export const ReasonSchema = z.string()
|
|
19
|
+
.describe('Justification for why the rule exists');
|
|
20
|
+
export const ParsedRuleSchema = z.object({
|
|
21
|
+
strength: StrengthSchema,
|
|
22
|
+
action: ActionSchema,
|
|
23
|
+
target: TargetSchema,
|
|
24
|
+
context: ContextSchema.optional(),
|
|
25
|
+
reason: ReasonSchema,
|
|
26
|
+
})
|
|
27
|
+
.describe('Single instruction decomposed into deontic components');
|
|
28
|
+
export const RuleSchema = z.string()
|
|
29
|
+
.describe('Human-readable rule derived from parsed components');
|
|
30
|
+
export const ParsedSchema = z.array(ParsedRuleSchema)
|
|
31
|
+
.describe('Array of parsed rules');
|
|
32
|
+
export const ParseResponseSchema = z.object({
|
|
33
|
+
rules: ParsedSchema,
|
|
34
|
+
});
|
|
35
|
+
export const FormatResponseSchema = z.object({
|
|
36
|
+
rules: z.array(RuleSchema),
|
|
37
|
+
});
|
|
38
|
+
// generate a JSON schema example string from the Zod schema for use in prompts
|
|
39
|
+
export const parseSchemaExample = JSON.stringify({
|
|
40
|
+
rules: [{
|
|
41
|
+
strength: StrengthSchema.options.join('/'),
|
|
42
|
+
action: ActionSchema.description || 'verb',
|
|
43
|
+
target: TargetSchema.description || 'object',
|
|
44
|
+
context: ContextSchema.description || 'optional condition',
|
|
45
|
+
reason: ReasonSchema.description || 'justification',
|
|
46
|
+
}],
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,IAAI,CAAC;IACnC,YAAY;IACZ,aAAa;IACb,WAAW;IACX,UAAU;IACV,gBAAgB;IAChB,aAAa;IACb,WAAW;CACZ,CAAC;KACC,QAAQ,CAAC,kDAAkD,CAAC,CAAA;AAE/D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,EAAE;KACnC,QAAQ,CAAC,+CAA+C,CAAC,CAAA;AAE5D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,EA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AC5C,OAAO,EAAE,aAAa,CAAC,WAAW,IAAI,oBAAoB;YAC1D,MAAM,EAAE,YAAY,CAAC,WAAW,IAAI,eAAe;SACpD,CAAC;CACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { Result } from './utils/safe';
|
|
4
|
+
export type PromptModel = {
|
|
5
|
+
providerID: string;
|
|
6
|
+
modelID: string;
|
|
7
|
+
};
|
|
8
|
+
type Part = {
|
|
9
|
+
type: string;
|
|
10
|
+
text?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const extractText: (parts: Part[]) => string;
|
|
13
|
+
export declare const detectModel: (client: PluginInput["client"], sessionId: string) => Promise<PromptModel | null>;
|
|
14
|
+
type PromptWithRetryOptions<T> = {
|
|
15
|
+
client: PluginInput['client'];
|
|
16
|
+
sessionId: string;
|
|
17
|
+
initialPrompt: string;
|
|
18
|
+
schema: z.ZodType<T>;
|
|
19
|
+
model: PromptModel;
|
|
20
|
+
};
|
|
21
|
+
export declare const promptWithRetry: <T>(options: PromptWithRetryOptions<T>) => Promise<Result<T>>;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAG5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAM1C,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAGD,KAAK,IAAI,GAAG;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAgBD,eAAO,MAAM,WAAW,GAAI,OAAO,IAAI,EAAE,KAAG,MAM3C,CAAA;AAGD,eAAO,MAAM,WAAW,GAAU,QAAQ,WAAW,CAAC,QAAQ,CAAC,EAAE,WAAW,MAAM,KAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAuB9G,CAAA;AAED,KAAK,sBAAsB,CAAC,CAAC,IAAI;IAC/B,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IACpB,KAAK,EAAE,WAAW,CAAA;CACnB,CAAA;AAGD,eAAO,MAAM,eAAe,GAAU,CAAC,EAAE,SAAS,sBAAsB,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CA0E9F,CAAA"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { buildRetryPrompt } from './prompt';
|
|
2
|
+
import { extractLlmError } from './utils/extractLlmError';
|
|
3
|
+
import { stripCodeFences } from './utils/stripCodeFences';
|
|
4
|
+
import { formatValidationError, validateJson } from './utils/validate';
|
|
5
|
+
const MAX_RETRIES = 3;
|
|
6
|
+
// runtime type guards for untyped SDK responses
|
|
7
|
+
const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
8
|
+
const isPart = (v) => isRecord(v) && typeof v.type === 'string';
|
|
9
|
+
const isPartArray = (v) => Array.isArray(v) && v.every(isPart);
|
|
10
|
+
const isMessageInfo = (v) => isRecord(v) && typeof v.role === 'string';
|
|
11
|
+
const isMessageEntry = (v) => isRecord(v) && isMessageInfo(v.info) && isPartArray(v.parts);
|
|
12
|
+
const isMessageEntryArray = (v) => Array.isArray(v) && v.every(isMessageEntry);
|
|
13
|
+
// extract text content from response parts
|
|
14
|
+
export const extractText = (parts) => {
|
|
15
|
+
return parts
|
|
16
|
+
.filter((p) => p.type === 'text' && p.text)
|
|
17
|
+
// fallback needed because TS cannot narrow through .filter()
|
|
18
|
+
.map((p) => p.text || '')
|
|
19
|
+
.join('');
|
|
20
|
+
};
|
|
21
|
+
// detect model from the calling session's most recent assistant message
|
|
22
|
+
export const detectModel = async (client, sessionId) => {
|
|
23
|
+
const messagesResult = await client.session.messages({
|
|
24
|
+
path: { id: sessionId },
|
|
25
|
+
});
|
|
26
|
+
if (!messagesResult.data) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const messages = messagesResult.data;
|
|
30
|
+
if (!isMessageEntryArray(messages)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
34
|
+
const info = messages[i].info;
|
|
35
|
+
if (info.role === 'assistant' && info.providerID && info.modelID) {
|
|
36
|
+
return {
|
|
37
|
+
providerID: info.providerID,
|
|
38
|
+
modelID: info.modelID,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
};
|
|
44
|
+
// prompt the LLM and validate the response, retrying on failure
|
|
45
|
+
export const promptWithRetry = async (options) => {
|
|
46
|
+
const { client, sessionId, initialPrompt, schema, model } = options;
|
|
47
|
+
let prompt = initialPrompt;
|
|
48
|
+
let lastError = '';
|
|
49
|
+
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
|
50
|
+
const response = await client.session.prompt({
|
|
51
|
+
path: { id: sessionId },
|
|
52
|
+
body: {
|
|
53
|
+
parts: [{ type: 'text', text: prompt }],
|
|
54
|
+
tools: {},
|
|
55
|
+
model,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
// no response data means a transport/API failure — not retryable
|
|
59
|
+
if (!response.data) {
|
|
60
|
+
return {
|
|
61
|
+
data: null,
|
|
62
|
+
error: 'No response from LLM (attempt ' + (attempt + 1) + ')',
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const info = response.data.info;
|
|
66
|
+
if (!isMessageInfo(info)) {
|
|
67
|
+
return {
|
|
68
|
+
data: null,
|
|
69
|
+
error: 'Unexpected response shape: missing info (attempt ' + (attempt + 1) + ')',
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const llmError = extractLlmError(info);
|
|
73
|
+
if (llmError) {
|
|
74
|
+
return {
|
|
75
|
+
data: null,
|
|
76
|
+
error: llmError,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const parts = response.data.parts;
|
|
80
|
+
if (!isPartArray(parts)) {
|
|
81
|
+
return {
|
|
82
|
+
data: null,
|
|
83
|
+
error: 'Unexpected response shape: missing parts (attempt ' + (attempt + 1) + ')',
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// empty text is a model issue — retryable
|
|
87
|
+
const text = extractText(parts);
|
|
88
|
+
if (!text) {
|
|
89
|
+
lastError = 'Empty response';
|
|
90
|
+
prompt = buildRetryPrompt('Empty response. Return valid JSON.');
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
// validate against schema
|
|
94
|
+
const cleaned = stripCodeFences(text);
|
|
95
|
+
const validation = validateJson(cleaned, schema);
|
|
96
|
+
if (validation.error) {
|
|
97
|
+
const errorMsg = formatValidationError(validation);
|
|
98
|
+
lastError = errorMsg + ' | raw: ' + cleaned.slice(0, 200);
|
|
99
|
+
prompt = buildRetryPrompt(errorMsg);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
data: validation.data,
|
|
104
|
+
error: null,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
data: null,
|
|
109
|
+
error: 'Failed after ' + MAX_RETRIES + ' attempts. Last error: ' + lastError,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const compareBytes: (file: string, original: string, generated: string) => ComparisonResult;
|
|
9
|
+
export declare const formatRow: (result: ComparisonResult) => string;
|
|
10
|
+
export type ComparisonSummary = {
|
|
11
|
+
totalOriginal: number;
|
|
12
|
+
totalGenerated: number;
|
|
13
|
+
totalDifference: number;
|
|
14
|
+
totalPercentChange: number;
|
|
15
|
+
};
|
|
16
|
+
export declare const summarize: (results: ComparisonResult[]) => ComparisonSummary;
|
|
17
|
+
export declare const buildTable: (results: ComparisonResult[]) => string;
|
|
18
|
+
//# sourceMappingURL=compare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../../src/utils/compare.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,EAAE,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;CACtB,CAAA;AAGD,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,EAAE,UAAU,MAAM,EAAE,WAAW,MAAM,KAAG,gBAahF,CAAA;AAYD,eAAO,MAAM,SAAS,GAAI,QAAQ,gBAAgB,KAAG,MAUpD,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,aAAa,EAAE,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;IACtB,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,MAAM,CAAA;CAC3B,CAAA;AAGD,eAAO,MAAM,SAAS,GAAI,SAAS,gBAAgB,EAAE,KAAG,iBAYvD,CAAA;AAGD,eAAO,MAAM,UAAU,GAAI,SAAS,gBAAgB,EAAE,KAAG,MAqCxD,CAAA"}
|