ai-dot 0.1.0-alpha.1

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.
@@ -0,0 +1,476 @@
1
+ /**
2
+ * A specialized AI assistant with isolated context, custom instructions,
3
+ * and optional tool/model restrictions.
4
+ *
5
+ * Claude Code: .claude/agents/*.md
6
+ * Cursor: .cursor/agents/*.md
7
+ * Codex: [agents.<name>] config sections
8
+ */
9
+ interface Agent {
10
+ /** Identifier used for delegation. */
11
+ name: string;
12
+ /** When/why the primary agent should delegate to this subagent. */
13
+ description: string;
14
+ /** Model override (e.g. "claude-sonnet-4-6"). */
15
+ model?: string;
16
+ /** When true, restrict to read-only file access. */
17
+ readonly?: boolean;
18
+ /** System prompt / behavioral guidance (markdown). */
19
+ instructions: string;
20
+ /** Allowed tool names. Undefined means all tools allowed. */
21
+ tools?: string[];
22
+ /** Agent mode (OpenCode). */
23
+ mode?: "primary" | "subagent" | "all";
24
+ /** Sampling temperature (OpenCode). */
25
+ temperature?: number;
26
+ /** Top-p sampling (OpenCode). */
27
+ topP?: number;
28
+ /** Max steps per invocation (OpenCode). */
29
+ steps?: number;
30
+ /** Display color in TUI (OpenCode). */
31
+ color?: string;
32
+ /** Hidden from agent picker (OpenCode). */
33
+ hidden?: boolean;
34
+ /** Disabled agent (OpenCode). */
35
+ disabled?: boolean;
36
+ }
37
+
38
+ /**
39
+ * The 4-tier scope hierarchy shared by Claude Code, Cursor, and Codex.
40
+ * Precedence: enterprise > project > user > local (highest to lowest).
41
+ */
42
+ declare const Scope: {
43
+ readonly Enterprise: "enterprise";
44
+ readonly Project: "project";
45
+ readonly User: "user";
46
+ readonly Local: "local";
47
+ };
48
+ type Scope = (typeof Scope)[keyof typeof Scope];
49
+ /** All scopes ordered from highest to lowest precedence. */
50
+ declare const SCOPE_PRECEDENCE: readonly Scope[];
51
+ /** Returns true if `a` has higher precedence (lower index) than `b`. */
52
+ declare function scopeOutranks(a: Scope, b: Scope): boolean;
53
+
54
+ /**
55
+ * A persistent, text-based instruction that shapes agent behavior.
56
+ *
57
+ * Abstracts what Claude Code calls "CLAUDE.md / rules",
58
+ * Cursor calls "rules", and Codex calls "AGENTS.md / instructions".
59
+ */
60
+ interface Directive {
61
+ /** Markdown content of the directive. */
62
+ content: string;
63
+ /** Scope at which this directive is defined. */
64
+ scope: Scope;
65
+ /** Optional glob patterns — activates only for matching file paths. */
66
+ appliesTo?: string[];
67
+ /** When true, always include in context (vs. intelligent selection). */
68
+ alwaysApply: boolean;
69
+ /** Optional human-readable description (used for intelligent selection). */
70
+ description?: string;
71
+ }
72
+
73
+ /** Lifecycle events that can trigger a hook. */
74
+ declare const HookEvent: {
75
+ readonly PreToolUse: "preToolUse";
76
+ readonly PostToolUse: "postToolUse";
77
+ readonly PreFileEdit: "preFileEdit";
78
+ readonly PostFileEdit: "postFileEdit";
79
+ readonly SessionStart: "sessionStart";
80
+ readonly SessionEnd: "sessionEnd";
81
+ readonly UserPromptSubmitted: "userPromptSubmitted";
82
+ readonly AgentStop: "agentStop";
83
+ readonly SubagentStop: "subagentStop";
84
+ readonly ErrorOccurred: "errorOccurred";
85
+ };
86
+ type HookEvent = (typeof HookEvent)[keyof typeof HookEvent];
87
+ /**
88
+ * An event handler that fires at specific points in the agent lifecycle.
89
+ * Supported by Claude Code and Cursor; not supported by Codex.
90
+ */
91
+ interface Hook {
92
+ /** Lifecycle event this hook responds to. */
93
+ event: HookEvent;
94
+ /** Filter condition (glob pattern or tool name) for when this hook fires. */
95
+ matcher?: string;
96
+ /** Shell command or prompt to execute. */
97
+ handler: string;
98
+ /** Scope at which this hook is defined. */
99
+ scope: Scope;
100
+ }
101
+
102
+ /**
103
+ * A file/directory exclusion rule — the agent should not access or index matching paths.
104
+ *
105
+ * Claude Code: Deny rules on Read()/Edit()
106
+ * Cursor: .cursorignore, .cursorindexingignore
107
+ * Codex: Protected paths + shell_environment_policy
108
+ */
109
+ interface IgnorePattern {
110
+ /** Gitignore-style glob pattern. */
111
+ pattern: string;
112
+ /** Scope at which this ignore rule is defined. */
113
+ scope: Exclude<Scope, "enterprise" | "local">;
114
+ }
115
+
116
+ /** The three possible access control decisions. */
117
+ declare const Decision: {
118
+ readonly Allow: "allow";
119
+ readonly Deny: "deny";
120
+ readonly Ask: "ask";
121
+ };
122
+ type Decision = (typeof Decision)[keyof typeof Decision];
123
+ /**
124
+ * An access control rule governing what tools and actions the agent can take.
125
+ *
126
+ * Claude Code: allow/deny/ask rules per tool (Bash(pattern), Read(pattern), etc.)
127
+ * Cursor: allow/deny per tool type (Shell(cmd), Read(glob), Write(glob))
128
+ * Codex: approval_policy + sandbox_mode + command rules
129
+ */
130
+ interface Permission {
131
+ /** Which tool this applies to (e.g. "Bash", "Read", "Write"). */
132
+ tool: string;
133
+ /** Glob/prefix pattern for matching arguments. */
134
+ pattern?: string;
135
+ /** Access control decision. */
136
+ decision: Decision;
137
+ /** Scope at which this permission is defined. */
138
+ scope: Scope;
139
+ }
140
+
141
+ /**
142
+ * A key-value configuration entry for tool behavior, model selection, and feature flags.
143
+ *
144
+ * Claude Code: .claude/settings.json
145
+ * Cursor: .cursor/cli.json
146
+ * Codex: .codex/config.toml
147
+ */
148
+ interface Setting {
149
+ /** Setting name. */
150
+ key: string;
151
+ /** Setting value (type varies by key). */
152
+ value: unknown;
153
+ /** Scope at which this setting is defined. */
154
+ scope: Scope;
155
+ }
156
+
157
+ /**
158
+ * A portable, reusable package of domain-specific knowledge and optional scripts.
159
+ *
160
+ * Structure: SKILL.md + optional scripts/, references/, assets/.
161
+ * Invocation: explicit (/skill-name) or automatic (agent decides).
162
+ * All three tools (Claude Code, Cursor, Codex) converge on this format.
163
+ */
164
+ interface Skill {
165
+ /** Identifier used for explicit invocation (e.g. /skill-name). */
166
+ name: string;
167
+ /** What this skill does and when to use it. */
168
+ description: string;
169
+ /** The SKILL.md body (markdown). */
170
+ content: string;
171
+ /** When true, only allow explicit /skill-name invocation. */
172
+ disableAutoInvocation: boolean;
173
+ }
174
+
175
+ /** MCP transport type. */
176
+ declare const Transport: {
177
+ readonly Stdio: "stdio";
178
+ readonly Http: "http";
179
+ readonly Sse: "sse";
180
+ };
181
+ type Transport = (typeof Transport)[keyof typeof Transport];
182
+ /**
183
+ * An external tool/data provider connected via Model Context Protocol (MCP).
184
+ * Universal across Claude Code, Cursor, and Codex.
185
+ */
186
+ interface ToolServer {
187
+ /** Identifier. */
188
+ name: string;
189
+ /** Connection type. */
190
+ transport: Transport;
191
+ /** Shell command (stdio) or endpoint URL (http/sse). */
192
+ command?: string;
193
+ url?: string;
194
+ /** Command arguments (stdio transport). */
195
+ args?: string[];
196
+ /** Environment variables passed to the server. */
197
+ env?: Record<string, string>;
198
+ /** If set, only these tools are exposed from the server. */
199
+ enabledTools?: string[];
200
+ /** If set, these tools are hidden from the server. */
201
+ disabledTools?: string[];
202
+ /** Scope at which this server is configured. */
203
+ scope: Scope;
204
+ }
205
+
206
+ /** Aggregated project configuration loaded from `.ai/`. */
207
+ interface ProjectConfig {
208
+ directives: Directive[];
209
+ skills: Skill[];
210
+ agents: Agent[];
211
+ toolServers: ToolServer[];
212
+ hooks: Hook[];
213
+ permissions: Permission[];
214
+ settings: Setting[];
215
+ ignorePatterns: IgnorePattern[];
216
+ }
217
+ /** A validation error with location context. */
218
+ interface ConfigError {
219
+ file: string;
220
+ line?: number;
221
+ message: string;
222
+ }
223
+ /** Result of config validation. */
224
+ interface ValidationResult {
225
+ valid: boolean;
226
+ errors: ConfigError[];
227
+ }
228
+ /** The scope at which config was loaded. */
229
+ type ConfigScope = "user" | "project";
230
+ /** Create an empty ProjectConfig. */
231
+ declare function emptyConfig(): ProjectConfig;
232
+ /**
233
+ * Merge two configs: base (user) + override (project).
234
+ * Project-level entities are appended after user-level ones.
235
+ * For settings with the same key, project overrides user.
236
+ */
237
+ declare function mergeConfigs(base: ProjectConfig, override: ProjectConfig): ProjectConfig;
238
+ /** Validate a ProjectConfig and return errors. */
239
+ declare function validateConfig(config: ProjectConfig): ValidationResult;
240
+
241
+ /** Validate config and warn about unsupported features per target. */
242
+ declare function runCheck(projectDir: string, scope?: ConfigScope): Promise<void>;
243
+
244
+ /** Source tool that originally created a config file. */
245
+ type SourceTool = "claude" | "cursor" | "codex" | "opencode";
246
+ /** Kind of config entity the file maps to. */
247
+ type DetectedKind = "directives" | "mcp" | "permissions" | "hooks" | "settings" | "agents" | "skills" | "ignore";
248
+ /** A detected raw config file in the project. */
249
+ interface DetectedFile {
250
+ path: string;
251
+ relativePath: string;
252
+ source: SourceTool;
253
+ kind: DetectedKind;
254
+ label: string;
255
+ }
256
+ /** Scan a project directory for existing raw config files from AI tools. */
257
+ declare function scanForConfigs(projectDir: string): Promise<DetectedFile[]>;
258
+
259
+ /** Options for the import command. */
260
+ interface ImportCommandOptions {
261
+ source?: SourceTool;
262
+ }
263
+ /** Import existing AI tool configs into .ai/ format. */
264
+ declare function runImportCommand(projectDir: string, options?: ImportCommandOptions): Promise<void>;
265
+
266
+ /** Target AI tool for config generation. */
267
+ declare const TargetTool: {
268
+ readonly Claude: "claude";
269
+ readonly Cursor: "cursor";
270
+ readonly Codex: "codex";
271
+ readonly OpenCode: "opencode";
272
+ readonly Copilot: "copilot";
273
+ readonly Antigravity: "antigravity";
274
+ };
275
+ type TargetTool = (typeof TargetTool)[keyof typeof TargetTool];
276
+ /** All supported target tools. */
277
+ declare const ALL_TARGETS: readonly TargetTool[];
278
+ /** A file written by an emitter. */
279
+ interface EmittedFile {
280
+ /** Relative path from the project root. */
281
+ path: string;
282
+ /** File content. */
283
+ content: string;
284
+ }
285
+ /** Result of an emit operation. */
286
+ interface EmitResult {
287
+ /** Files that were written (or would be written in dry-run). */
288
+ files: EmittedFile[];
289
+ /** Warnings about lossy mappings or unsupported features. */
290
+ warnings: string[];
291
+ }
292
+ /** Interface that all emitters implement. */
293
+ interface Emitter {
294
+ /** Emit config files for a specific target tool. */
295
+ emit(config: ProjectConfig, target: TargetTool): EmitResult;
296
+ }
297
+
298
+ /** Available template names. */
299
+ type TemplateName = "blank" | "minimal" | "web" | "python" | "monorepo";
300
+ /** Template metadata for display. */
301
+ interface TemplateInfo {
302
+ name: TemplateName;
303
+ label: string;
304
+ description: string;
305
+ factory: () => ProjectConfig;
306
+ }
307
+ /** All available templates. */
308
+ declare const TEMPLATES: readonly TemplateInfo[];
309
+ /** Get a template by name. Throws if not found. */
310
+ declare function getTemplate(name: TemplateName): ProjectConfig;
311
+ /** All valid template names. */
312
+ declare const TEMPLATE_NAMES: readonly TemplateName[];
313
+
314
+ /** Options for the init command. */
315
+ interface InitOptions {
316
+ template?: TemplateName;
317
+ targets?: TargetTool[];
318
+ skipImport?: boolean;
319
+ autoSync?: boolean;
320
+ }
321
+ /** Scaffold a new `.ai/` directory with guided setup or flags. */
322
+ declare function runInit(projectDir: string, options?: InitOptions): Promise<void>;
323
+
324
+ /** Show the status of generated files vs what's on disk. */
325
+ declare function runStatus(projectDir: string): Promise<void>;
326
+
327
+ interface SyncOptions {
328
+ targets: TargetTool[];
329
+ dryRun: boolean;
330
+ scope: ConfigScope;
331
+ force: boolean;
332
+ yes?: boolean;
333
+ }
334
+ /** Load config, run emitters, write files. */
335
+ declare function runSync(projectDir: string, options: SyncOptions): Promise<void>;
336
+
337
+ /** Result of loading a project config from `.ai/`. */
338
+ interface LoadResult {
339
+ config: ProjectConfig;
340
+ errors: ConfigError[];
341
+ }
342
+ /** Load a full ProjectConfig from an `.ai/` directory. */
343
+ declare function loadProjectConfig(aiDir: string, scope?: ConfigScope): Promise<LoadResult>;
344
+ /**
345
+ * Load merged config: user-level ~/.ai/ as base, project .ai/ overrides.
346
+ * Returns the combined config with correct scopes on each entity.
347
+ */
348
+ declare function loadMergedConfig(projectDir: string): Promise<LoadResult>;
349
+
350
+ /** Parsed result of a markdown file with YAML frontmatter. */
351
+ interface ParsedMarkdown {
352
+ /** Frontmatter key-value pairs. */
353
+ frontmatter: Record<string, unknown>;
354
+ /** Markdown body after frontmatter. */
355
+ body: string;
356
+ }
357
+ /**
358
+ * Parse a markdown string with optional YAML frontmatter.
359
+ *
360
+ * Frontmatter is delimited by `---` at the start of the file.
361
+ * Uses a simple parser to avoid pulling in a full YAML library for frontmatter
362
+ * (the main config.yaml uses the `yaml` package).
363
+ */
364
+ declare function parseMarkdownWithFrontmatter(raw: string): ParsedMarkdown;
365
+ /** Load and parse a markdown file with frontmatter from disk. */
366
+ declare function loadMarkdownFile(filePath: string): Promise<ParsedMarkdown>;
367
+
368
+ /**
369
+ * Scan `.ai/skills/` for skill directories.
370
+ * Each skill is a directory containing a SKILL.md file.
371
+ */
372
+ declare function loadSkills(skillsDir: string): Promise<Skill[]>;
373
+
374
+ /** Create a Directive with sensible defaults. */
375
+ declare function createDirective(overrides: Partial<Directive> & Pick<Directive, "content" | "scope">): Directive;
376
+ /** Create a Skill with sensible defaults. */
377
+ declare function createSkill(overrides: Partial<Skill> & Pick<Skill, "name" | "content">): Skill;
378
+ /** Create an Agent with sensible defaults. */
379
+ declare function createAgent(overrides: Partial<Agent> & Pick<Agent, "name" | "instructions">): Agent;
380
+ /** Create a ToolServer with sensible defaults. */
381
+ declare function createToolServer(overrides: Partial<ToolServer> & Pick<ToolServer, "name" | "transport" | "scope">): ToolServer;
382
+ /** Create a Hook with sensible defaults. */
383
+ declare function createHook(overrides: Partial<Hook> & Pick<Hook, "event" | "handler" | "scope">): Hook;
384
+ /** Create a Permission with sensible defaults. */
385
+ declare function createPermission(overrides: Partial<Permission> & Pick<Permission, "tool" | "decision" | "scope">): Permission;
386
+ /** Create a Setting. */
387
+ declare function createSetting(overrides: Partial<Setting> & Pick<Setting, "key" | "value" | "scope">): Setting;
388
+ /** Create an IgnorePattern. */
389
+ declare function createIgnorePattern(overrides: Partial<IgnorePattern> & Pick<IgnorePattern, "pattern" | "scope">): IgnorePattern;
390
+
391
+ declare function isDirective(v: unknown): v is Directive;
392
+ declare function isSkill(v: unknown): v is Skill;
393
+ declare function isAgent(v: unknown): v is Agent;
394
+ declare function isToolServer(v: unknown): v is ToolServer;
395
+ declare function isHook(v: unknown): v is Hook;
396
+ declare function isPermission(v: unknown): v is Permission;
397
+ declare function isSetting(v: unknown): v is Setting;
398
+ declare function isIgnorePattern(v: unknown): v is IgnorePattern;
399
+
400
+ /** Emits agent definition files. */
401
+ declare const agentsEmitter: Emitter;
402
+
403
+ /** Emits directive files — biggest format divergence across tools. */
404
+ declare const directivesEmitter: Emitter;
405
+
406
+ /** Emits hooks and ignore pattern configuration files. */
407
+ declare const hooksEmitter: Emitter;
408
+
409
+ /** Emits MCP server configuration files. */
410
+ declare const mcpEmitter: Emitter;
411
+
412
+ /** Emits permissions and settings configuration files. */
413
+ declare const permissionsEmitter: Emitter;
414
+
415
+ /** Emits skill files for all target tools. Near-identical format across all 3. */
416
+ declare const skillsEmitter: Emitter;
417
+
418
+ /** Parse Claude Code config files into a partial ProjectConfig. */
419
+ declare function parseClaude(projectDir: string, files: DetectedFile[]): Promise<Partial<ProjectConfig>>;
420
+
421
+ /** Parse Codex config files into a partial ProjectConfig. */
422
+ declare function parseCodex(_projectDir: string, files: DetectedFile[]): Promise<Partial<ProjectConfig>>;
423
+
424
+ /** Parse Cursor config files into a partial ProjectConfig. */
425
+ declare function parseCursor(_projectDir: string, files: DetectedFile[]): Promise<Partial<ProjectConfig>>;
426
+
427
+ /** Parse OpenCode config files into a partial ProjectConfig. */
428
+ declare function parseOpenCode(projectDir: string, files: DetectedFile[]): Promise<Partial<ProjectConfig>>;
429
+
430
+ /** Options for running an import. */
431
+ interface ImportOptions {
432
+ interactive: boolean;
433
+ sourceFilter?: SourceTool;
434
+ /** In interactive mode, this function selects which files to import. */
435
+ selectFiles?: (detected: DetectedFile[]) => Promise<DetectedFile[]>;
436
+ }
437
+ /** Result of an import operation. */
438
+ interface ImportResult {
439
+ detected: DetectedFile[];
440
+ imported: DetectedFile[];
441
+ config: ProjectConfig;
442
+ filesWritten: string[];
443
+ }
444
+ /** Run the import pipeline: scan → select → parse → merge → write. */
445
+ declare function runImport(projectDir: string, options: ImportOptions): Promise<ImportResult>;
446
+
447
+ /** Serialize a ProjectConfig back to an `.ai/` directory. Returns paths of written files. */
448
+ declare function writeProjectConfig(aiDir: string, config: ProjectConfig): Promise<string[]>;
449
+
450
+ /** Persisted state of last sync operation. */
451
+ interface SyncState {
452
+ /** Timestamp of last sync. */
453
+ lastSync: string;
454
+ /** Map of relative file path → content hash. */
455
+ files: Record<string, string>;
456
+ }
457
+ /** Compute a content hash for a string. */
458
+ declare function contentHash(content: string): string;
459
+ /** Load the sync state from .ai/.state.json. */
460
+ declare function loadState(projectDir: string): Promise<SyncState | null>;
461
+ /** Save the sync state to .ai/.state.json. */
462
+ declare function saveState(projectDir: string, files: EmittedFile[]): Promise<void>;
463
+ /** Status of a generated file compared to what's on disk. */
464
+ type FileStatus = "new" | "up-to-date" | "modified" | "conflict" | "orphaned";
465
+ /** Result of comparing a file. */
466
+ interface FileStatusEntry {
467
+ path: string;
468
+ status: FileStatus;
469
+ }
470
+ /**
471
+ * Compare generated files against on-disk state and last-known state.
472
+ * Returns status for each file plus any orphaned files from previous sync.
473
+ */
474
+ declare function diffFiles(projectDir: string, generated: EmittedFile[], state: SyncState | null): Promise<FileStatusEntry[]>;
475
+
476
+ export { ALL_TARGETS, type Agent, type ConfigError, type ConfigScope, Decision, type DetectedFile, type DetectedKind, type Directive, type EmitResult, type EmittedFile, type Emitter, type FileStatus, type FileStatusEntry, type Hook, HookEvent, type IgnorePattern, type ImportCommandOptions, type ImportOptions, type ImportResult, type InitOptions, type LoadResult, type ParsedMarkdown, type Permission, type ProjectConfig, SCOPE_PRECEDENCE, Scope, type Setting, type Skill, type SourceTool, type SyncOptions, type SyncState, TEMPLATES, TEMPLATE_NAMES, TargetTool, type TemplateInfo, type TemplateName, type ToolServer, Transport, type ValidationResult, agentsEmitter, contentHash, createAgent, createDirective, createHook, createIgnorePattern, createPermission, createSetting, createSkill, createToolServer, diffFiles, directivesEmitter, emptyConfig, getTemplate, hooksEmitter, isAgent, isDirective, isHook, isIgnorePattern, isPermission, isSetting, isSkill, isToolServer, loadMarkdownFile, loadMergedConfig, loadProjectConfig, loadSkills, loadState, mcpEmitter, mergeConfigs, parseClaude, parseCodex, parseCursor, parseMarkdownWithFrontmatter, parseOpenCode, permissionsEmitter, runCheck, runImport, runImportCommand, runInit, runStatus, runSync, saveState, scanForConfigs, scopeOutranks, skillsEmitter, validateConfig, writeProjectConfig };