@causyne/agent 1.20.100 → 1.20.104

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.
@@ -14,116 +14,104 @@
14
14
  //
15
15
  // Path safety, size limits and sanitising all live in userSkills.js, and this
16
16
  // tool cannot reach the filesystem except through it.
17
-
18
- import {
19
- parseSkillId, writeUserSkill, userSkillsRoot, MAX_SKILL_BYTES
20
- } from '../userSkills.js';
17
+ import { parseSkillId, writeUserSkill, userSkillsRoot, MAX_SKILL_BYTES } from '../userSkills.js';
21
18
  import { invalidateUserSkills } from '../skillsManager.js';
22
-
23
19
  /** Everything the contract requires, reported at once rather than one at a time. */
24
20
  function contractProblems(content) {
25
- const problems = [];
26
- if (!/^---\r?\n[\s\S]*?\r?\n---/.test(content)) {
27
- problems.push('missing the `---` frontmatter block at the very top');
28
- }
29
- if (!/^description:\s*\S/m.test(content)) {
30
- problems.push("frontmatter needs a `description:` — it is the ONLY thing the agent reads when deciding whether this skill applies, so write it as \"what this does. Use when …\"");
31
- }
32
- if (!/^name:\s*\S/m.test(content)) {
33
- problems.push('frontmatter needs a `name:`');
34
- }
35
- if (!/\*\*Done when:\*\*/.test(content)) {
36
- problems.push("no step ends with a `**Done when:**` criterion — without one this is a description of a task, not a procedure someone can follow to a known end");
37
- }
38
- if (!/##\s+Verification/i.test(content)) {
39
- problems.push('no `## Verification` section — a skill has to say how to confirm it worked');
40
- }
41
- return problems;
42
- }
43
-
44
- export const createSkill = {
45
- schema: {
46
- name: 'skill_create',
47
- description:
48
- "Write a reusable skill into the user's own skill library so it is available in every future session. Use when the user describes a procedure specific to them — their "
49
- + 'deployment steps, their review checklist, their project conventions — that would '
50
- + 'otherwise have to be explained again next time. Ask the user before writing one they '
51
- + 'did not request. The body must follow the skill contract: frontmatter with name and a '
52
- + '"Use when ..." description, numbered steps each ending with a "**Done when:**" line, '
53
- + 'and a closing "## Verification" section.',
54
- parameters: {
55
- type: 'object',
56
- properties: {
57
- skill_id: {
58
- type: 'string',
59
- description:
60
- "Where it lives, as \"domain/name\". Both are lowercase letters, digits and hyphens. Use an existing domain (web, devops, python, testing, security, design, …) when the "
61
- + 'skill belongs to one, or a new domain of the user\'s own such as "team" or the '
62
- + 'project name. Example: team/release-checklist'
63
- },
64
- content: {
65
- type: 'string',
66
- description:
67
- "The complete SKILL.md, starting with the --- frontmatter block. Write the procedure, not an essay: the steps someone would actually take, in order, each with a "
68
- + 'checkable "**Done when:**" line, closing with "## Verification".'
69
- },
70
- overwrite: {
71
- type: 'boolean',
72
- description:
73
- "Replace an existing skill of the same id. Defaults to false. Only set this when the user has asked for that specific skill to be rewritten."
74
- }
75
- },
76
- required: ['skill_id', 'content']
21
+ const problems = [];
22
+ if (!/^---\r?\n[\s\S]*?\r?\n---/.test(content)) {
23
+ problems.push('missing the `---` frontmatter block at the very top');
77
24
  }
78
- },
79
-
80
- execute: async (args = {}) => {
81
- const parsed = parseSkillId(args.skill_id);
82
- if (parsed.error) return { success: false, error: parsed.error };
83
-
84
- const content = typeof args.content === 'string' ? args.content : '';
85
- if (!content.trim()) {
86
- return { success: false, error: 'content is required — write the whole SKILL.md' };
25
+ if (!/^description:\s*\S/m.test(content)) {
26
+ problems.push("frontmatter needs a `description:` — it is the ONLY thing the agent reads when deciding whether this skill applies, so write it as \"what this does. Use when …\"");
87
27
  }
88
- if (Buffer.byteLength(content, 'utf8') > MAX_SKILL_BYTES) {
89
- return {
90
- success: false,
91
- error: `the skill is larger than the ${MAX_SKILL_BYTES / 1024} KB limit. A skill this long `
92
- + 'will crowd out the task it is meant to help with — split it, or move the detail into '
93
- + 'the step that needs it.'
94
- };
28
+ if (!/^name:\s*\S/m.test(content)) {
29
+ problems.push('frontmatter needs a `name:`');
95
30
  }
96
-
97
- const problems = contractProblems(content);
98
- if (problems.length > 0) {
99
- return {
100
- success: false,
101
- error: 'the skill does not meet the contract:\n'
102
- + problems.map((problem) => ` - ${problem}`).join('\n')
103
- + '\n\nRewrite it with those fixed and call skill_create again.'
104
- };
31
+ if (!/\*\*Done when:\*\*/.test(content)) {
32
+ problems.push("no step ends with a `**Done when:**` criterion — without one this is a description of a task, not a procedure someone can follow to a known end");
33
+ }
34
+ if (!/##\s+Verification/i.test(content)) {
35
+ problems.push('no `## Verification` section — a skill has to say how to confirm it worked');
36
+ }
37
+ return problems;
38
+ }
39
+ export const createSkill = {
40
+ schema: {
41
+ name: 'skill_create',
42
+ description: "Write a reusable skill into the user's own skill library so it is available in every future session. Use when the user describes a procedure specific to them — their "
43
+ + 'deployment steps, their review checklist, their project conventions — that would '
44
+ + 'otherwise have to be explained again next time. Ask the user before writing one they '
45
+ + 'did not request. The body must follow the skill contract: frontmatter with name and a '
46
+ + '"Use when ..." description, numbered steps each ending with a "**Done when:**" line, '
47
+ + 'and a closing "## Verification" section.',
48
+ parameters: {
49
+ type: 'object',
50
+ properties: {
51
+ skill_id: {
52
+ type: 'string',
53
+ description: "Where it lives, as \"domain/name\". Both are lowercase letters, digits and hyphens. Use an existing domain (web, devops, python, testing, security, design, …) when the "
54
+ + 'skill belongs to one, or a new domain of the user\'s own such as "team" or the '
55
+ + 'project name. Example: team/release-checklist'
56
+ },
57
+ content: {
58
+ type: 'string',
59
+ description: "The complete SKILL.md, starting with the --- frontmatter block. Write the procedure, not an essay: the steps someone would actually take, in order, each with a "
60
+ + 'checkable "**Done when:**" line, closing with "## Verification".'
61
+ },
62
+ overwrite: {
63
+ type: 'boolean',
64
+ description: "Replace an existing skill of the same id. Defaults to false. Only set this when the user has asked for that specific skill to be rewritten."
65
+ }
66
+ },
67
+ required: ['skill_id', 'content']
68
+ }
69
+ },
70
+ execute: async (args = {}) => {
71
+ const parsed = parseSkillId(args.skill_id);
72
+ if ('error' in parsed && parsed.error)
73
+ return { success: false, error: parsed.error };
74
+ if (!parsed.domain || !parsed.name)
75
+ return { success: false, error: 'Invalid skill id' };
76
+ const content = typeof args.content === 'string' ? args.content : '';
77
+ if (!content.trim()) {
78
+ return { success: false, error: 'content is required — write the whole SKILL.md' };
79
+ }
80
+ if (Buffer.byteLength(content, 'utf8') > MAX_SKILL_BYTES) {
81
+ return {
82
+ success: false,
83
+ error: `the skill is larger than the ${MAX_SKILL_BYTES / 1024} KB limit. A skill this long `
84
+ + 'will crowd out the task it is meant to help with — split it, or move the detail into '
85
+ + 'the step that needs it.'
86
+ };
87
+ }
88
+ const problems = contractProblems(content);
89
+ if (problems.length > 0) {
90
+ return {
91
+ success: false,
92
+ error: 'the skill does not meet the contract:\n'
93
+ + problems.map((problem) => ` - ${problem}`).join('\n')
94
+ + '\n\nRewrite it with those fixed and call skill_create again.'
95
+ };
96
+ }
97
+ const written = writeUserSkill({
98
+ domain: parsed.domain,
99
+ name: parsed.name,
100
+ content,
101
+ overwrite: args.overwrite === true
102
+ });
103
+ if (!written.ok)
104
+ return { success: false, error: written.error ?? 'could not write skill' };
105
+ // The catalogue is cached; a skill written now must be visible now.
106
+ invalidateUserSkills();
107
+ return {
108
+ success: true,
109
+ result: `Wrote ${parsed.domain}/${parsed.name} to ${written.path}\n\n`
110
+ + `It is now in the user's library alongside the built-in skills, and it shadows a `
111
+ + `built-in of the same id. They can see it with /skill mine, read it with `
112
+ + `/skills ${parsed.domain}/${parsed.name}, and edit the file directly at `
113
+ + `${userSkillsRoot()}.`
114
+ };
105
115
  }
106
-
107
- const written = writeUserSkill({
108
- domain: parsed.domain,
109
- name: parsed.name,
110
- content,
111
- overwrite: args.overwrite === true
112
- });
113
- if (!written.ok) return { success: false, error: written.error };
114
-
115
- // The catalogue is cached; a skill written now must be visible now.
116
- invalidateUserSkills();
117
-
118
- return {
119
- success: true,
120
- result: `Wrote ${parsed.domain}/${parsed.name} to ${written.path}\n\n`
121
- + `It is now in the user's library alongside the built-in skills, and it shadows a `
122
- + `built-in of the same id. They can see it with /skill mine, read it with `
123
- + `/skills ${parsed.domain}/${parsed.name}, and edit the file directly at `
124
- + `${userSkillsRoot()}.`
125
- };
126
- }
127
116
  };
128
-
129
117
  export default createSkill;
@@ -0,0 +1,142 @@
1
+ // Let the agent write a skill for the user.
2
+ //
3
+ // The compiled library is one library for everybody. The other half of the same
4
+ // idea is that the agent can WRITE one: a user explains their release process
5
+ // once, and it becomes a procedure the agent follows every time afterwards
6
+ // instead of being re-explained every session. That is the difference between a
7
+ // tool that remembers and a tool that does not.
8
+ //
9
+ // The contract is the one every compiled skill already meets — frontmatter with
10
+ // a routing description, numbered steps each closing with a checkable
11
+ // criterion, and a verification section. It is enforced here rather than
12
+ // suggested, because a skill written to a weaker standard than the library is
13
+ // worse than none: it dilutes the index the agent chooses from.
14
+ //
15
+ // Path safety, size limits and sanitising all live in userSkills.js, and this
16
+ // tool cannot reach the filesystem except through it.
17
+
18
+ import {
19
+ parseSkillId, writeUserSkill, userSkillsRoot, MAX_SKILL_BYTES
20
+ } from '../userSkills.js';
21
+ import { invalidateUserSkills } from '../skillsManager.js';
22
+
23
+ export interface CreateSkillArgs {
24
+ skill_id?: string;
25
+ content?: string;
26
+ overwrite?: boolean;
27
+ }
28
+
29
+ export interface CreateSkillResult {
30
+ success: boolean;
31
+ result?: string;
32
+ error?: string;
33
+ }
34
+
35
+ /** Everything the contract requires, reported at once rather than one at a time. */
36
+ function contractProblems(content: string): string[] {
37
+ const problems: string[] = [];
38
+ if (!/^---\r?\n[\s\S]*?\r?\n---/.test(content)) {
39
+ problems.push('missing the `---` frontmatter block at the very top');
40
+ }
41
+ if (!/^description:\s*\S/m.test(content)) {
42
+ problems.push("frontmatter needs a `description:` — it is the ONLY thing the agent reads when deciding whether this skill applies, so write it as \"what this does. Use when …\"");
43
+ }
44
+ if (!/^name:\s*\S/m.test(content)) {
45
+ problems.push('frontmatter needs a `name:`');
46
+ }
47
+ if (!/\*\*Done when:\*\*/.test(content)) {
48
+ problems.push("no step ends with a `**Done when:**` criterion — without one this is a description of a task, not a procedure someone can follow to a known end");
49
+ }
50
+ if (!/##\s+Verification/i.test(content)) {
51
+ problems.push('no `## Verification` section — a skill has to say how to confirm it worked');
52
+ }
53
+ return problems;
54
+ }
55
+
56
+ export const createSkill = {
57
+ schema: {
58
+ name: 'skill_create',
59
+ description:
60
+ "Write a reusable skill into the user's own skill library so it is available in every future session. Use when the user describes a procedure specific to them — their "
61
+ + 'deployment steps, their review checklist, their project conventions — that would '
62
+ + 'otherwise have to be explained again next time. Ask the user before writing one they '
63
+ + 'did not request. The body must follow the skill contract: frontmatter with name and a '
64
+ + '"Use when ..." description, numbered steps each ending with a "**Done when:**" line, '
65
+ + 'and a closing "## Verification" section.',
66
+ parameters: {
67
+ type: 'object',
68
+ properties: {
69
+ skill_id: {
70
+ type: 'string',
71
+ description:
72
+ "Where it lives, as \"domain/name\". Both are lowercase letters, digits and hyphens. Use an existing domain (web, devops, python, testing, security, design, …) when the "
73
+ + 'skill belongs to one, or a new domain of the user\'s own such as "team" or the '
74
+ + 'project name. Example: team/release-checklist'
75
+ },
76
+ content: {
77
+ type: 'string',
78
+ description:
79
+ "The complete SKILL.md, starting with the --- frontmatter block. Write the procedure, not an essay: the steps someone would actually take, in order, each with a "
80
+ + 'checkable "**Done when:**" line, closing with "## Verification".'
81
+ },
82
+ overwrite: {
83
+ type: 'boolean',
84
+ description:
85
+ "Replace an existing skill of the same id. Defaults to false. Only set this when the user has asked for that specific skill to be rewritten."
86
+ }
87
+ },
88
+ required: ['skill_id', 'content']
89
+ }
90
+ },
91
+
92
+ execute: async (args: CreateSkillArgs = {}): Promise<CreateSkillResult> => {
93
+ const parsed = parseSkillId(args.skill_id);
94
+ if ('error' in parsed && parsed.error) return { success: false, error: parsed.error };
95
+ if (!parsed.domain || !parsed.name) return { success: false, error: 'Invalid skill id' };
96
+
97
+ const content = typeof args.content === 'string' ? args.content : '';
98
+ if (!content.trim()) {
99
+ return { success: false, error: 'content is required — write the whole SKILL.md' };
100
+ }
101
+ if (Buffer.byteLength(content, 'utf8') > MAX_SKILL_BYTES) {
102
+ return {
103
+ success: false,
104
+ error: `the skill is larger than the ${MAX_SKILL_BYTES / 1024} KB limit. A skill this long `
105
+ + 'will crowd out the task it is meant to help with — split it, or move the detail into '
106
+ + 'the step that needs it.'
107
+ };
108
+ }
109
+
110
+ const problems = contractProblems(content);
111
+ if (problems.length > 0) {
112
+ return {
113
+ success: false,
114
+ error: 'the skill does not meet the contract:\n'
115
+ + problems.map((problem) => ` - ${problem}`).join('\n')
116
+ + '\n\nRewrite it with those fixed and call skill_create again.'
117
+ };
118
+ }
119
+
120
+ const written = writeUserSkill({
121
+ domain: parsed.domain,
122
+ name: parsed.name,
123
+ content,
124
+ overwrite: args.overwrite === true
125
+ });
126
+ if (!written.ok) return { success: false, error: written.error ?? 'could not write skill' };
127
+
128
+ // The catalogue is cached; a skill written now must be visible now.
129
+ invalidateUserSkills();
130
+
131
+ return {
132
+ success: true,
133
+ result: `Wrote ${parsed.domain}/${parsed.name} to ${written.path}\n\n`
134
+ + `It is now in the user's library alongside the built-in skills, and it shadows a `
135
+ + `built-in of the same id. They can see it with /skill mine, read it with `
136
+ + `/skills ${parsed.domain}/${parsed.name}, and edit the file directly at `
137
+ + `${userSkillsRoot()}.`
138
+ };
139
+ }
140
+ };
141
+
142
+ export default createSkill;
@@ -1,105 +1,118 @@
1
- import fs from 'fs/promises';
2
- import os from 'os';
3
-
4
- // Phase 3 AGI Upgrade: Fast Levenshtein Distance for Fuzzy Matching
1
+ import fs from 'node:fs/promises';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { atomicWriteFileSync } from '../infra/atomicWriter.js';
5
5
  function getLevenshteinDistance(a, b) {
6
- const matrix = Array(a.length + 1).fill(null).map(() => Array(b.length + 1).fill(null));
7
-
8
- for (let i = 0; i <= a.length; i++) matrix[i][0] = i;
9
- for (let j = 0; j <= b.length; j++) matrix[0][j] = j;
10
-
11
- for (let i = 1; i <= a.length; i++) {
12
- for (let j = 1; j <= b.length; j++) {
13
- const indicator = a[i - 1] === b[j - 1] ? 0 : 1;
14
- matrix[i][j] = Math.min(
15
- matrix[i - 1][j] + 1, // deletion
16
- matrix[i][j - 1] + 1, // insertion
17
- matrix[i - 1][j - 1] + indicator // substitution
18
- );
6
+ const matrix = Array(a.length + 1)
7
+ .fill(null)
8
+ .map(() => Array(b.length + 1).fill(0));
9
+ for (let i = 0; i <= a.length; i++)
10
+ matrix[i][0] = i;
11
+ for (let j = 0; j <= b.length; j++)
12
+ matrix[0][j] = j;
13
+ for (let i = 1; i <= a.length; i++) {
14
+ for (let j = 1; j <= b.length; j++) {
15
+ const indicator = a[i - 1] === b[j - 1] ? 0 : 1;
16
+ matrix[i][j] = Math.min(matrix[i - 1][j] + 1, // deletion
17
+ matrix[i][j - 1] + 1, // insertion
18
+ matrix[i - 1][j - 1] + indicator // substitution
19
+ );
20
+ }
19
21
  }
20
- }
21
- return matrix[a.length][b.length];
22
+ return matrix[a.length][b.length];
22
23
  }
23
-
24
24
  function calculateConfidence(original, match) {
25
- const dist = getLevenshteinDistance(original, match);
26
- const maxLen = Math.max(original.length, match.length);
27
- if (maxLen === 0) return 100;
28
- return ((maxLen - dist) / maxLen) * 100;
25
+ const dist = getLevenshteinDistance(original, match);
26
+ const maxLen = Math.max(original.length, match.length);
27
+ if (maxLen === 0)
28
+ return 100;
29
+ return ((maxLen - dist) / maxLen) * 100;
29
30
  }
30
-
31
31
  export const fsEdit = {
32
- schema: {
33
- name: 'fs.edit',
34
- description: 'Surgically edit specific lines/blocks in a file. Employs 90% confidence Levenshtein fuzzy matching if exact match fails.',
35
- parameters: {
36
- type: 'object',
37
- properties: {
38
- path: { type: 'string' },
39
- edits: {
40
- type: 'array',
41
- items: {
32
+ schema: {
33
+ name: 'fs.edit',
34
+ description: 'Surgically edit specific lines/blocks in a file. Employs 90% confidence Levenshtein fuzzy matching if exact match fails.',
35
+ parameters: {
42
36
  type: 'object',
43
37
  properties: {
44
- searchContent: { type: 'string' },
45
- replaceContent: { type: 'string' }
38
+ path: { type: 'string' },
39
+ edits: {
40
+ type: 'array',
41
+ items: {
42
+ type: 'object',
43
+ properties: {
44
+ searchContent: { type: 'string' },
45
+ replaceContent: { type: 'string' }
46
+ },
47
+ required: ['searchContent', 'replaceContent']
48
+ }
49
+ }
46
50
  },
47
- required: ['searchContent', 'replaceContent']
48
- }
49
- }
50
- },
51
- required: ['path', 'edits']
52
- }
53
- },
54
- async execute(args) {
55
- try {
56
- const target = args.path.replace(/^~\//, os.homedir() + '/');
57
- let originalContent = await fs.readFile(target, 'utf8');
58
- let workingContent = originalContent; // Phase 3 AGI Upgrade: Atomic Rollback prep
59
-
60
- let replacements = 0;
61
- for (let i = 0; i < args.edits.length; i++) {
62
- const edit = args.edits[i];
63
-
64
- // Try exact match first
65
- if (workingContent.includes(edit.searchContent)) {
66
- workingContent = workingContent.replace(edit.searchContent, edit.replaceContent);
67
- replacements++;
68
- continue;
51
+ required: ['path', 'edits']
69
52
  }
70
-
71
- // Phase 3 AGI Upgrade: Fuzzy Match Fallback
72
- const lines = workingContent.split('\n');
73
- const oldLines = edit.searchContent.split('\n');
74
- let bestMatch = null;
75
- let highestConfidence = 0;
76
-
77
- for (let j = 0; j <= lines.length - oldLines.length; j++) {
78
- const chunk = lines.slice(j, j + oldLines.length).join('\n');
79
- const conf = calculateConfidence(edit.searchContent, chunk);
80
- if (conf > highestConfidence) {
81
- highestConfidence = conf;
82
- bestMatch = chunk;
83
- }
53
+ },
54
+ async execute(args) {
55
+ try {
56
+ if (!args || typeof args !== 'object') {
57
+ return { success: false, error: 'fs_edit requires an object with path and edits array.' };
58
+ }
59
+ if (typeof args.path !== 'string' || !args.path.trim()) {
60
+ return { success: false, error: 'fs_edit requires a non-empty string path.' };
61
+ }
62
+ if (!Array.isArray(args.edits) || args.edits.length === 0) {
63
+ return { success: false, error: 'fs_edit requires a non-empty edits array.' };
64
+ }
65
+ const targetPath = args.path.trim();
66
+ const target = targetPath.startsWith('~/') || targetPath.startsWith('~\\')
67
+ ? path.join(os.homedir(), targetPath.slice(2))
68
+ : path.resolve(targetPath);
69
+ const originalContent = await fs.readFile(target, 'utf8');
70
+ let workingContent = originalContent;
71
+ let replacements = 0;
72
+ for (let i = 0; i < args.edits.length; i++) {
73
+ const edit = args.edits[i];
74
+ if (!edit || typeof edit.searchContent !== 'string' || typeof edit.replaceContent !== 'string') {
75
+ return {
76
+ success: false,
77
+ error: `ATOMIC ROLLBACK: Edit index ${i} is missing valid searchContent or replaceContent strings. Rollback complete.`
78
+ };
79
+ }
80
+ // Try exact match first
81
+ if (workingContent.includes(edit.searchContent)) {
82
+ workingContent = workingContent.replace(edit.searchContent, edit.replaceContent);
83
+ replacements++;
84
+ continue;
85
+ }
86
+ // Fuzzy Match Fallback
87
+ const lines = workingContent.split('\n');
88
+ const oldLines = edit.searchContent.split('\n');
89
+ let bestMatch = null;
90
+ let highestConfidence = 0;
91
+ for (let j = 0; j <= lines.length - oldLines.length; j++) {
92
+ const chunk = lines.slice(j, j + oldLines.length).join('\n');
93
+ const conf = calculateConfidence(edit.searchContent, chunk);
94
+ if (conf > highestConfidence) {
95
+ highestConfidence = conf;
96
+ bestMatch = chunk;
97
+ }
98
+ }
99
+ if (highestConfidence >= 90 && bestMatch) {
100
+ workingContent = workingContent.replace(bestMatch, edit.replaceContent);
101
+ replacements++;
102
+ }
103
+ else {
104
+ return {
105
+ success: false,
106
+ error: `ATOMIC ROLLBACK: Edit index ${i} failed. Exact match not found, and fuzzy match confidence was too low (${highestConfidence.toFixed(2)}% < 90%). Previous edits in this batch were rolled back.`
107
+ };
108
+ }
109
+ }
110
+ // Commit the transaction atomically
111
+ atomicWriteFileSync(target, workingContent, { encoding: 'utf8' });
112
+ return { success: true, output: `Transaction Success: ${replacements} replacement(s) safely applied to ${args.path}` };
84
113
  }
85
-
86
- if (highestConfidence >= 90 && bestMatch) {
87
- workingContent = workingContent.replace(bestMatch, edit.replaceContent);
88
- replacements++;
89
- } else {
90
- // Atomic Rollback
91
- return {
92
- success: false,
93
- error: `ATOMIC ROLLBACK: Edit index ${i} failed. Exact match not found, and fuzzy match confidence was too low (${highestConfidence.toFixed(2)}% < 90%). Previous edits in this batch were rolled back.`
94
- };
114
+ catch (e) {
115
+ return { success: false, error: e instanceof Error ? e.message : String(e) };
95
116
  }
96
- }
97
-
98
- // Commit the transaction
99
- await fs.writeFile(target, workingContent, 'utf8');
100
- return { success: true, output: `Transaction Success: ${replacements} replacement(s) safely applied to ${args.path}` };
101
- } catch (e) {
102
- return { success: false, error: e.message };
103
117
  }
104
- }
105
118
  };