@a16njs/models 0.8.0 → 0.10.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/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +17 -4
- package/dist/plugin.d.ts.map +1 -1
- package/dist/warnings.d.ts +5 -1
- package/dist/warnings.d.ts.map +1 -1
- package/dist/warnings.js +4 -0
- package/dist/warnings.js.map +1 -1
- package/dist/workspace.d.ts +126 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +86 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { CustomizationType, type AgentCustomization, type GlobalPrompt, type SimpleAgentSkill, type AgentSkill, // Deprecated alias for SimpleAgentSkill
|
|
2
2
|
type AgentSkillIO, type FileRule, type AgentIgnore, type ManualPrompt, } from './types.js';
|
|
3
|
-
export { type A16nPlugin, type DiscoveryResult, type EmitResult, type EmitOptions, type WrittenFile, } from './plugin.js';
|
|
3
|
+
export { type A16nPlugin, type PluginPathPatterns, type DiscoveryResult, type EmitResult, type EmitOptions, type WrittenFile, } from './plugin.js';
|
|
4
4
|
export { WarningCode, type Warning } from './warnings.js';
|
|
5
5
|
export { isGlobalPrompt, isSimpleAgentSkill, isAgentSkill, // Deprecated alias for isSimpleAgentSkill
|
|
6
6
|
isAgentSkillIO, isFileRule, isAgentIgnore, isManualPrompt, getUniqueFilename, createId, } from './helpers.js';
|
|
7
7
|
export { type IRVersion, type ParsedIRVersion, CURRENT_IR_VERSION, parseIRVersion, areVersionsCompatible, getCurrentVersion, } from './version.js';
|
|
8
|
+
export { type Workspace, type WorkspaceEntry, resolveRoot, LocalWorkspace, toWorkspace } from './workspace.js';
|
|
8
9
|
export { type ParsedSkillFrontmatter, type ParsedSkill, parseSkillFrontmatter, readSkillFiles, writeAgentSkillIO, readAgentSkillIO, } from './agentskills-io.js';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EACjB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EAAE,wCAAwC;AACzD,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,WAAW,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAG1D,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,YAAY,EAAE,0CAA0C;AACxD,cAAc,EACd,UAAU,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,QAAQ,GACT,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAChB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EACjB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EAAE,wCAAwC;AACzD,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,WAAW,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAG1D,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,YAAY,EAAE,0CAA0C;AACxD,cAAc,EACd,UAAU,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,QAAQ,GACT,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG/G,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAChB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,8 @@ export { isGlobalPrompt, isSimpleAgentSkill, isAgentSkill, // Deprecated alias f
|
|
|
8
8
|
isAgentSkillIO, isFileRule, isAgentIgnore, isManualPrompt, getUniqueFilename, createId, } from './helpers.js';
|
|
9
9
|
// Version utilities
|
|
10
10
|
export { CURRENT_IR_VERSION, parseIRVersion, areVersionsCompatible, getCurrentVersion, } from './version.js';
|
|
11
|
+
// Workspace abstraction
|
|
12
|
+
export { resolveRoot, LocalWorkspace, toWorkspace } from './workspace.js';
|
|
11
13
|
// AgentSkills.io utilities
|
|
12
14
|
export { parseSkillFrontmatter, readSkillFiles, writeAgentSkillIO, readAgentSkillIO, } from './agentskills-io.js';
|
|
13
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAElE,QAAQ;AACR,OAAO,EACL,iBAAiB,GASlB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAElE,QAAQ;AACR,OAAO,EACL,iBAAiB,GASlB,MAAM,YAAY,CAAC;AAYpB,WAAW;AACX,OAAO,EAAE,WAAW,EAAgB,MAAM,eAAe,CAAC;AAE1D,UAAU;AACV,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,YAAY,EAAE,0CAA0C;AACxD,cAAc,EACd,UAAU,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,QAAQ,GACT,MAAM,cAAc,CAAC;AAEtB,oBAAoB;AACpB,OAAO,EAGL,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,wBAAwB;AACxB,OAAO,EAAuC,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE/G,2BAA2B;AAC3B,OAAO,EAGL,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,qBAAqB,CAAC"}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AgentCustomization, CustomizationType } from './types.js';
|
|
2
2
|
import type { Warning } from './warnings.js';
|
|
3
|
+
import type { Workspace } from './workspace.js';
|
|
3
4
|
/**
|
|
4
5
|
* Result of discovering customizations from a project.
|
|
5
6
|
*/
|
|
@@ -46,6 +47,16 @@ export interface EmitOptions {
|
|
|
46
47
|
/** If true, calculate what would be written without actually writing */
|
|
47
48
|
dryRun?: boolean;
|
|
48
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Path patterns for a plugin, used by transformations like path rewriting
|
|
52
|
+
* to identify and handle file references specific to this plugin's format.
|
|
53
|
+
*/
|
|
54
|
+
export interface PluginPathPatterns {
|
|
55
|
+
/** Directory prefixes used by this plugin (e.g., ['.cursor/rules/', '.cursor/skills/']) */
|
|
56
|
+
prefixes: string[];
|
|
57
|
+
/** File extensions used by this plugin (e.g., ['.mdc', '.md']) */
|
|
58
|
+
extensions: string[];
|
|
59
|
+
}
|
|
49
60
|
/**
|
|
50
61
|
* The plugin interface that all a16n plugins must implement.
|
|
51
62
|
* Plugins bridge between a16n's internal model and a specific tool's format.
|
|
@@ -57,19 +68,21 @@ export interface A16nPlugin {
|
|
|
57
68
|
name: string;
|
|
58
69
|
/** Which customization types this plugin supports */
|
|
59
70
|
supports: CustomizationType[];
|
|
71
|
+
/** Path patterns for this plugin's file format (used by transformations) */
|
|
72
|
+
pathPatterns?: PluginPathPatterns;
|
|
60
73
|
/**
|
|
61
74
|
* Discover all agent customizations in a directory tree.
|
|
62
|
-
* @param
|
|
75
|
+
* @param rootOrWorkspace - The root directory path or Workspace to search
|
|
63
76
|
* @returns All customizations found and any warnings
|
|
64
77
|
*/
|
|
65
|
-
discover(
|
|
78
|
+
discover(rootOrWorkspace: string | Workspace): Promise<DiscoveryResult>;
|
|
66
79
|
/**
|
|
67
80
|
* Emit customization models to disk in this plugin's format.
|
|
68
81
|
* @param models - The customizations to emit
|
|
69
|
-
* @param
|
|
82
|
+
* @param rootOrWorkspace - The root directory path or Workspace to write to
|
|
70
83
|
* @param options - Optional emit options (e.g., dryRun)
|
|
71
84
|
* @returns Info about what was written (or would be written) and any issues
|
|
72
85
|
*/
|
|
73
|
-
emit(models: AgentCustomization[],
|
|
86
|
+
emit(models: AgentCustomization[], rootOrWorkspace: string | Workspace, options?: EmitOptions): Promise<EmitResult>;
|
|
74
87
|
}
|
|
75
88
|
//# sourceMappingURL=plugin.d.ts.map
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,oCAAoC;IACpC,KAAK,EAAE,kBAAkB,EAAE,CAAC;IAC5B,gDAAgD;IAChD,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,IAAI,EAAE,iBAAiB,CAAC;IACxB,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC;IAClB,2EAA2E;IAC3E,SAAS,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,WAAW,CAAC,EAAE,kBAAkB,EAAE,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,+DAA+D;IAC/D,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,+CAA+C;IAC/C,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,yDAAyD;IACzD,WAAW,EAAE,kBAAkB,EAAE,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,wEAAwE;IACxE,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,2FAA2F;IAC3F,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,kEAAkE;IAClE,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,2DAA2D;IAC3D,EAAE,EAAE,MAAM,CAAC;IACX,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,4EAA4E;IAC5E,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAElC;;;;OAIG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAExE;;;;;;OAMG;IACH,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,EAAE,eAAe,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACrH"}
|
package/dist/warnings.d.ts
CHANGED
|
@@ -17,7 +17,11 @@ export declare enum WarningCode {
|
|
|
17
17
|
/** Sources have conflicting git status (some ignored, some tracked) */
|
|
18
18
|
GitStatusConflict = "git-status-conflict",
|
|
19
19
|
/** IR file version is incompatible with current reader version */
|
|
20
|
-
VersionMismatch = "version-mismatch"
|
|
20
|
+
VersionMismatch = "version-mismatch",
|
|
21
|
+
/** A path reference in content points to a source-format file not in the conversion set */
|
|
22
|
+
OrphanPathRef = "orphan-path-ref",
|
|
23
|
+
/** A post-conversion operation (e.g. gitignore cleanup) failed */
|
|
24
|
+
OperationFailed = "operation-failed"
|
|
21
25
|
}
|
|
22
26
|
/**
|
|
23
27
|
* A warning about something that happened during conversion.
|
package/dist/warnings.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"warnings.d.ts","sourceRoot":"","sources":["../src/warnings.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,WAAW;IACrB,kDAAkD;IAClD,MAAM,WAAW;IACjB,yCAAyC;IACzC,YAAY,iBAAiB;IAC7B,4CAA4C;IAC5C,OAAO,YAAY;IACnB,iCAAiC;IACjC,WAAW,gBAAgB;IAC3B,0CAA0C;IAC1C,WAAW,iBAAiB;IAC5B,6DAA6D;IAC7D,gBAAgB,sBAAsB;IACtC,uEAAuE;IACvE,iBAAiB,wBAAwB;IACzC,kEAAkE;IAClE,eAAe,qBAAqB;CACrC;AAED;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,0BAA0B;IAC1B,IAAI,EAAE,WAAW,CAAC;IAClB,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC"}
|
|
1
|
+
{"version":3,"file":"warnings.d.ts","sourceRoot":"","sources":["../src/warnings.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,WAAW;IACrB,kDAAkD;IAClD,MAAM,WAAW;IACjB,yCAAyC;IACzC,YAAY,iBAAiB;IAC7B,4CAA4C;IAC5C,OAAO,YAAY;IACnB,iCAAiC;IACjC,WAAW,gBAAgB;IAC3B,0CAA0C;IAC1C,WAAW,iBAAiB;IAC5B,6DAA6D;IAC7D,gBAAgB,sBAAsB;IACtC,uEAAuE;IACvE,iBAAiB,wBAAwB;IACzC,kEAAkE;IAClE,eAAe,qBAAqB;IACpC,2FAA2F;IAC3F,aAAa,oBAAoB;IACjC,kEAAkE;IAClE,eAAe,qBAAqB;CACrC;AAED;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,0BAA0B;IAC1B,IAAI,EAAE,WAAW,CAAC;IAClB,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC"}
|
package/dist/warnings.js
CHANGED
|
@@ -19,5 +19,9 @@ export var WarningCode;
|
|
|
19
19
|
WarningCode["GitStatusConflict"] = "git-status-conflict";
|
|
20
20
|
/** IR file version is incompatible with current reader version */
|
|
21
21
|
WarningCode["VersionMismatch"] = "version-mismatch";
|
|
22
|
+
/** A path reference in content points to a source-format file not in the conversion set */
|
|
23
|
+
WarningCode["OrphanPathRef"] = "orphan-path-ref";
|
|
24
|
+
/** A post-conversion operation (e.g. gitignore cleanup) failed */
|
|
25
|
+
WarningCode["OperationFailed"] = "operation-failed";
|
|
22
26
|
})(WarningCode || (WarningCode = {}));
|
|
23
27
|
//# sourceMappingURL=warnings.js.map
|
package/dist/warnings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"warnings.js","sourceRoot":"","sources":["../src/warnings.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"warnings.js","sourceRoot":"","sources":["../src/warnings.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,WAqBX;AArBD,WAAY,WAAW;IACrB,kDAAkD;IAClD,gCAAiB,CAAA;IACjB,yCAAyC;IACzC,4CAA6B,CAAA;IAC7B,4CAA4C;IAC5C,kCAAmB,CAAA;IACnB,iCAAiC;IACjC,0CAA2B,CAAA;IAC3B,0CAA0C;IAC1C,2CAA4B,CAAA;IAC5B,6DAA6D;IAC7D,qDAAsC,CAAA;IACtC,uEAAuE;IACvE,wDAAyC,CAAA;IACzC,kEAAkE;IAClE,mDAAoC,CAAA;IACpC,2FAA2F;IAC3F,gDAAiC,CAAA;IACjC,kEAAkE;IAClE,mDAAoC,CAAA;AACtC,CAAC,EArBW,WAAW,KAAX,WAAW,QAqBtB"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A directory entry returned by workspace readdir.
|
|
3
|
+
*/
|
|
4
|
+
export interface WorkspaceEntry {
|
|
5
|
+
/** The entry name (not full path) */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Whether this entry is a file */
|
|
8
|
+
isFile: boolean;
|
|
9
|
+
/** Whether this entry is a directory */
|
|
10
|
+
isDirectory: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Abstraction over file operations, enabling local filesystem,
|
|
14
|
+
* read-only (dry-run), and in-memory (testing) workspaces.
|
|
15
|
+
*
|
|
16
|
+
* All paths passed to workspace methods are relative to the workspace root.
|
|
17
|
+
* Implementations must handle path resolution internally.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Local filesystem workspace
|
|
22
|
+
* const ws = new LocalWorkspace('source', '/project');
|
|
23
|
+
* const content = await ws.read('.cursor/rules/my-rule.mdc');
|
|
24
|
+
*
|
|
25
|
+
* // In-memory workspace for testing
|
|
26
|
+
* const mem = new MemoryWorkspace('test');
|
|
27
|
+
* await mem.write('file.md', '# Hello');
|
|
28
|
+
* const exists = await mem.exists('file.md'); // true
|
|
29
|
+
*
|
|
30
|
+
* // Read-only wrapper for dry-run
|
|
31
|
+
* const readOnly = new ReadOnlyWorkspace(ws);
|
|
32
|
+
* await readOnly.write('file.md', 'content'); // throws!
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export interface Workspace {
|
|
36
|
+
/** Unique identifier for this workspace */
|
|
37
|
+
readonly id: string;
|
|
38
|
+
/** The root path of the workspace (for path resolution and display) */
|
|
39
|
+
readonly root: string;
|
|
40
|
+
/**
|
|
41
|
+
* Resolve a relative path within this workspace to an absolute path.
|
|
42
|
+
* @param relativePath - Path relative to workspace root
|
|
43
|
+
* @returns Absolute path
|
|
44
|
+
*/
|
|
45
|
+
resolve(relativePath: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Check if a path exists in this workspace.
|
|
48
|
+
* @param relativePath - Path relative to workspace root
|
|
49
|
+
* @returns true if the path exists
|
|
50
|
+
*/
|
|
51
|
+
exists(relativePath: string): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Read a file from this workspace.
|
|
54
|
+
* @param relativePath - Path relative to workspace root
|
|
55
|
+
* @returns File content as UTF-8 string
|
|
56
|
+
* @throws If the file does not exist
|
|
57
|
+
*/
|
|
58
|
+
read(relativePath: string): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Write a file to this workspace.
|
|
61
|
+
* Creates parent directories as needed.
|
|
62
|
+
* @param relativePath - Path relative to workspace root
|
|
63
|
+
* @param content - File content as UTF-8 string
|
|
64
|
+
* @throws If the workspace is read-only
|
|
65
|
+
*/
|
|
66
|
+
write(relativePath: string, content: string): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* List entries in a directory.
|
|
69
|
+
* @param relativePath - Path relative to workspace root
|
|
70
|
+
* @returns Array of directory entries
|
|
71
|
+
* @throws If the directory does not exist
|
|
72
|
+
*/
|
|
73
|
+
readdir(relativePath: string): Promise<WorkspaceEntry[]>;
|
|
74
|
+
/**
|
|
75
|
+
* Create a directory (and any missing parents).
|
|
76
|
+
* @param relativePath - Path relative to workspace root
|
|
77
|
+
*/
|
|
78
|
+
mkdir(relativePath: string): Promise<void>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Helper to extract the root path from a string or Workspace argument.
|
|
82
|
+
* Useful for plugins migrating to Workspace support.
|
|
83
|
+
*
|
|
84
|
+
* @param rootOrWorkspace - A string root path or Workspace instance
|
|
85
|
+
* @returns The root path string
|
|
86
|
+
*/
|
|
87
|
+
export declare function resolveRoot(rootOrWorkspace: string | Workspace): string;
|
|
88
|
+
/**
|
|
89
|
+
* Workspace backed by the local filesystem.
|
|
90
|
+
*
|
|
91
|
+
* All operations delegate to Node.js fs/promises.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const ws = new LocalWorkspace('source', '/project');
|
|
96
|
+
* const content = await ws.read('.cursor/rules/my-rule.mdc');
|
|
97
|
+
* await ws.write('.claude/rules/my-rule.md', content);
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare class LocalWorkspace implements Workspace {
|
|
101
|
+
readonly id: string;
|
|
102
|
+
readonly root: string;
|
|
103
|
+
/**
|
|
104
|
+
* Create a new LocalWorkspace.
|
|
105
|
+
* @param id - Unique identifier for this workspace
|
|
106
|
+
* @param root - Absolute path to the workspace root directory
|
|
107
|
+
*/
|
|
108
|
+
constructor(id: string, root: string);
|
|
109
|
+
resolve(relativePath: string): string;
|
|
110
|
+
exists(relativePath: string): Promise<boolean>;
|
|
111
|
+
read(relativePath: string): Promise<string>;
|
|
112
|
+
write(relativePath: string, content: string): Promise<void>;
|
|
113
|
+
readdir(relativePath: string): Promise<WorkspaceEntry[]>;
|
|
114
|
+
mkdir(relativePath: string): Promise<void>;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Convert a string root path or Workspace instance to a Workspace.
|
|
118
|
+
* If given a string, wraps it in a LocalWorkspace with the given id.
|
|
119
|
+
* If given a Workspace, returns it unchanged.
|
|
120
|
+
*
|
|
121
|
+
* @param rootOrWorkspace - A string root path or Workspace instance
|
|
122
|
+
* @param id - Workspace id to use when wrapping a string (default: 'default')
|
|
123
|
+
* @returns A Workspace instance
|
|
124
|
+
*/
|
|
125
|
+
export declare function toWorkspace(rootOrWorkspace: string | Workspace, id?: string): Workspace;
|
|
126
|
+
//# sourceMappingURL=workspace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAA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AM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI3C,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3D,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IASxD,KAAK,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGjD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,EAAE,EAAE,GAAE,MAAkB,GAAG,SAAS,CAKlG"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Helper to extract the root path from a string or Workspace argument.
|
|
5
|
+
* Useful for plugins migrating to Workspace support.
|
|
6
|
+
*
|
|
7
|
+
* @param rootOrWorkspace - A string root path or Workspace instance
|
|
8
|
+
* @returns The root path string
|
|
9
|
+
*/
|
|
10
|
+
export function resolveRoot(rootOrWorkspace) {
|
|
11
|
+
return typeof rootOrWorkspace === 'string' ? rootOrWorkspace : rootOrWorkspace.root;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Workspace backed by the local filesystem.
|
|
15
|
+
*
|
|
16
|
+
* All operations delegate to Node.js fs/promises.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const ws = new LocalWorkspace('source', '/project');
|
|
21
|
+
* const content = await ws.read('.cursor/rules/my-rule.mdc');
|
|
22
|
+
* await ws.write('.claude/rules/my-rule.md', content);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export class LocalWorkspace {
|
|
26
|
+
id;
|
|
27
|
+
root;
|
|
28
|
+
/**
|
|
29
|
+
* Create a new LocalWorkspace.
|
|
30
|
+
* @param id - Unique identifier for this workspace
|
|
31
|
+
* @param root - Absolute path to the workspace root directory
|
|
32
|
+
*/
|
|
33
|
+
constructor(id, root) {
|
|
34
|
+
this.id = id;
|
|
35
|
+
this.root = root;
|
|
36
|
+
}
|
|
37
|
+
resolve(relativePath) {
|
|
38
|
+
if (relativePath === '')
|
|
39
|
+
return this.root;
|
|
40
|
+
return path.join(this.root, relativePath);
|
|
41
|
+
}
|
|
42
|
+
async exists(relativePath) {
|
|
43
|
+
try {
|
|
44
|
+
await fs.access(this.resolve(relativePath));
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async read(relativePath) {
|
|
52
|
+
return fs.readFile(this.resolve(relativePath), 'utf-8');
|
|
53
|
+
}
|
|
54
|
+
async write(relativePath, content) {
|
|
55
|
+
const fullPath = this.resolve(relativePath);
|
|
56
|
+
await fs.mkdir(path.dirname(fullPath), { recursive: true });
|
|
57
|
+
await fs.writeFile(fullPath, content, 'utf-8');
|
|
58
|
+
}
|
|
59
|
+
async readdir(relativePath) {
|
|
60
|
+
const dirents = await fs.readdir(this.resolve(relativePath), { withFileTypes: true });
|
|
61
|
+
return dirents.map((d) => ({
|
|
62
|
+
name: d.name,
|
|
63
|
+
isFile: d.isFile(),
|
|
64
|
+
isDirectory: d.isDirectory(),
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
async mkdir(relativePath) {
|
|
68
|
+
await fs.mkdir(this.resolve(relativePath), { recursive: true });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Convert a string root path or Workspace instance to a Workspace.
|
|
73
|
+
* If given a string, wraps it in a LocalWorkspace with the given id.
|
|
74
|
+
* If given a Workspace, returns it unchanged.
|
|
75
|
+
*
|
|
76
|
+
* @param rootOrWorkspace - A string root path or Workspace instance
|
|
77
|
+
* @param id - Workspace id to use when wrapping a string (default: 'default')
|
|
78
|
+
* @returns A Workspace instance
|
|
79
|
+
*/
|
|
80
|
+
export function toWorkspace(rootOrWorkspace, id = 'default') {
|
|
81
|
+
if (typeof rootOrWorkspace === 'string') {
|
|
82
|
+
return new LocalWorkspace(id, rootOrWorkspace);
|
|
83
|
+
}
|
|
84
|
+
return rootOrWorkspace;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=workspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace.js","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AA0FlC;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,eAAmC;IAC7D,OAAO,OAAO,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC;AACtF,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,cAAc;IAOP;IACA;IAPlB;;;;OAIG;IACH,YACkB,EAAU,EACV,IAAY;QADZ,OAAE,GAAF,EAAE,CAAQ;QACV,SAAI,GAAJ,IAAI,CAAQ;IAC3B,CAAC;IAEJ,OAAO,CAAC,YAAoB;QAC1B,IAAI,YAAY,KAAK,EAAE;YAAE,OAAO,IAAI,CAAC,IAAI,CAAC;QAC1C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,YAAoB;QAC/B,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;YAC5C,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,YAAoB;QAC7B,OAAO,EAAE,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