@contextai-core/cli 0.1.1 → 0.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contextai-core/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Give your AI agents persistent memory. Install pre-built context packs for Cursor, Windsurf, Copilot & more.",
5
5
  "author": "ContextAI",
6
6
  "license": "ISC",
@@ -1,4 +1,4 @@
1
- import { Action } from "commander";
1
+
2
2
  import chalk from "chalk";
3
3
  import path from "path";
4
4
  import fs from "fs";
@@ -8,6 +8,14 @@ import chalk from 'chalk';
8
8
  */
9
9
  export async function smartWriteFile(filePath, content, reason) {
10
10
  const fullPath = path.resolve(process.cwd(), filePath);
11
+
12
+ // SAFETY: Restrict usage to .ai directory (and context folders)
13
+ // This prevents the tool from conflicting with the Agent's native coding capabilities.
14
+ const relPath = path.relative(process.cwd(), fullPath);
15
+ if (!relPath.startsWith('.ai') && !relPath.startsWith('.context')) {
16
+ throw new Error(`ACCESS DENIED: 'contextai write' is restricted to the .ai/ directory.\nUse your native 'write_file' tool for application code.`);
17
+ }
18
+
11
19
  const dir = path.dirname(fullPath);
12
20
 
13
21
  // 1. Write the file
@@ -16,19 +24,23 @@ export async function smartWriteFile(filePath, content, reason) {
16
24
  }
17
25
  fs.writeFileSync(fullPath, content, 'utf8');
18
26
 
19
- // 2. Update Changelog
20
- const aiDir = path.join(process.cwd(), '.ai', 'context');
21
- const changelogPath = path.join(aiDir, 'changelog.md');
27
+ // 2. System Audit Log (Immutable)
28
+ // Tracks "What happened" for safety/replay.
29
+ // Agent cannot modify this directly; it's a side-effect of the tool.
30
+ const aiDir = path.join(process.cwd(), '.ai');
31
+ const auditPath = path.join(aiDir, 'audit.log');
22
32
 
23
- if (fs.existsSync(changelogPath)) {
24
- const today = new Date().toISOString().split('T')[0];
25
- const entry = `| ${today} | Agent | ${reason} |`;
33
+ if (!fs.existsSync(aiDir)) {
34
+ try { fs.mkdirSync(aiDir); } catch (e) { }
35
+ }
26
36
 
27
- let changelog = fs.readFileSync(changelogPath, 'utf8');
28
- // append to table (simplistic approach: append before last empty line or at end)
29
- changelog += `\n${entry}`;
37
+ const timestamp = new Date().toISOString();
38
+ const logEntry = `[${timestamp}] ACTION:WRITE file="${filePath}" reason="${reason}"\n`;
30
39
 
31
- fs.writeFileSync(changelogPath, changelog, 'utf8');
40
+ try {
41
+ fs.appendFileSync(auditPath, logEntry, 'utf8');
42
+ } catch (e) {
43
+ // Silently fail logging rather than breaking the build
32
44
  }
33
45
 
34
46
  return { success: true, path: fullPath };