ai-agent-test 0.9.4 → 0.9.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.
Files changed (4) hide show
  1. package/README.md +11 -3
  2. package/SYSTEM.md +3 -3
  3. package/bin/ai +101 -121
  4. package/package.json +2 -1
package/README.md CHANGED
@@ -76,7 +76,8 @@ Start CLI with selected model (default is the first model in the array):
76
76
 
77
77
  ```bash
78
78
  # option 1
79
- ai models 1 # to select the second model (Google Gemini)
79
+ ai models # List all available models
80
+ ai --model 1 # Select the second model (Google Gemini)
80
81
 
81
82
  # option 2
82
83
  export AI_MODEL_INDEX=1
@@ -116,8 +117,15 @@ When installed globally, run `ai` to start the interactive CLI:
116
117
  View and restore previous sessions:
117
118
 
118
119
  ```bash
119
- ai sessions ls # List last 20 sessions with 0-based indexing
120
- ai sessions 2 # Load and restart from session 2
120
+ ai sessions # List last 20 sessions with 0-based indexing
121
+ ai --session 2 # Load and restart from session 2
122
+ ```
123
+
124
+ You can also combine model and session options:
125
+
126
+ ```bash
127
+ ai --model 1 --session 2 # Use model 1 and load session 2
128
+ ai -m 1 -s 2 # Short form of the above command
121
129
  ```
122
130
 
123
131
  When loading a session, the conversation history is restored and logged to the current session file.
package/SYSTEM.md CHANGED
@@ -12,9 +12,9 @@ Critical workflow rules:
12
12
 
13
13
  Git best practices:
14
14
 
15
- - When user says "commit" - Perform both git add, git commit, and git push (no confirmation needed). Important note! If you made new changes, ask user's permission again even though user already said "commit".
16
- - Run git status before staging to verify what changes will be committed
17
- - When staging changes (with approval), always check that only intended files are staged
15
+ - When user says "commit" - Perform both git add, git commit, and git push (no confirmation needed).
16
+ - Important note! If you've just done new changes upon user request, ask user if they want you to commit/push even though user said "commit" before, not just commit yourself.
17
+ - Run git status before staging to verify what changes will be committed. Always check that only intended files are staged.
18
18
  - Avoid staging large batches (>10 files) or common problematic folders like /dist, /node_modules, \*.log, .DS_Store. Ask to user.
19
19
 
20
20
  Tools and skills:
package/bin/ai CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { argv } from "process"
4
3
  import { execSync } from "child_process"
5
4
  import { readFileSync } from "fs"
6
5
  import { homedir } from "os"
7
6
  import { join } from "path"
7
+ import { argv } from "process"
8
8
 
9
9
  import { loadConfig } from "../dist/config.js"
10
10
  import {
@@ -12,38 +12,112 @@ import {
12
12
  loadSession,
13
13
  getSessionFileByIndex,
14
14
  } from "../dist/utils/system.js"
15
+ import yargs from "yargs"
16
+ import { hideBin } from "yargs/helpers"
17
+
18
+ const packageJson = JSON.parse(
19
+ readFileSync(new URL("../package.json", import.meta.url), "utf-8"),
20
+ )
21
+
22
+ // Parse arguments using yargs
23
+ const args = yargs(hideBin(argv))
24
+ .option("model", {
25
+ alias: "m",
26
+ type: "number",
27
+ describe: "Start with model index from `ai models`",
28
+ })
29
+ .option("session", {
30
+ alias: "s",
31
+ type: "number",
32
+ describe: "Resume with session index from `ai sessions`",
33
+ })
34
+ .command(
35
+ "models",
36
+ "List all available models",
37
+ () => {},
38
+ () => {
39
+ try {
40
+ const modelsFile = join(homedir(), ".ai", "models.json")
41
+ const fileContent = readFileSync(modelsFile, "utf-8")
42
+ const models = JSON.parse(fileContent)
43
+
44
+ if (!Array.isArray(models) || models.length === 0) {
45
+ console.log("No models found in ~/.ai/models.json")
46
+ process.exit(1)
47
+ }
15
48
 
16
- // Handle models command
17
- if (argv[2] === "models") {
18
- const subCommand = argv[3]
19
-
20
- if (subCommand === "ls") {
21
- try {
22
- const modelsFile = join(homedir(), ".ai", "models.json")
23
- const fileContent = readFileSync(modelsFile, "utf-8")
24
- const models = JSON.parse(fileContent)
25
-
26
- if (!Array.isArray(models) || models.length === 0) {
27
- console.log("No models found in ~/.ai/models.json")
49
+ const displayPath = modelsFile.replace(homedir(), "~")
50
+ console.log(`Available models (${displayPath}):`)
51
+ models.forEach((model, index) => {
52
+ console.log(`${index}. ${model.modelName} (${model.modelApiType})`)
53
+ })
54
+ process.exit(0)
55
+ } catch (error) {
56
+ console.error(`Failed to load models: ${error.message}`)
28
57
  process.exit(1)
29
58
  }
30
-
31
- const displayPath = modelsFile.replace(homedir(), "~")
32
- console.log(`Available models (${displayPath}):`)
33
- models.forEach((model, index) => {
34
- console.log(`${index}. ${model.modelName} (${model.modelApiType})`)
35
- })
59
+ },
60
+ )
61
+ .command(
62
+ "sessions",
63
+ "List last 20 sessions",
64
+ () => {},
65
+ () => {
66
+ const sessions = listSessions(20)
67
+ if (sessions.length === 0) {
68
+ console.log("No sessions found.")
69
+ } else {
70
+ console.log(`Last ${sessions.length} sessions:`)
71
+ sessions.forEach((session, index) => {
72
+ let line = `${index}. ${session.timestamp}`
73
+ if (session.summary) {
74
+ line += ` - ${session.summary}`
75
+ }
76
+ console.log(line)
77
+ })
78
+ }
36
79
  process.exit(0)
37
- } catch (error) {
38
- console.error(`Failed to load models: ${error.message}`)
39
- process.exit(1)
40
- }
41
- } else if (subCommand) {
42
- process.env.AI_MODEL_INDEX = subCommand
43
- } else {
44
- console.log("Usage: ai models <index> or ai models ls")
80
+ },
81
+ )
82
+ .command(
83
+ "update",
84
+ "Update the ai-agent-test package to the latest version",
85
+ () => {},
86
+ () => {
87
+ execSync("npm install -g ai-agent-test", { stdio: "inherit" })
88
+ process.exit(0)
89
+ },
90
+ )
91
+ .help()
92
+ .version(packageJson.version)
93
+ .alias("version", "v")
94
+ .alias("help", "h")
95
+ .parse()
96
+
97
+ // Handle model index from --model option
98
+ if (args.model !== undefined) {
99
+ process.env.AI_MODEL_INDEX = args.model.toString()
100
+ }
101
+
102
+ // Handle session index from --session option
103
+ if (args.session !== undefined) {
104
+ const sessionIndex = args.session
105
+ const sessionFile = getSessionFileByIndex(sessionIndex)
106
+ if (!sessionFile) {
107
+ console.log(`Session ${sessionIndex} not found.`)
108
+ process.exit(1)
109
+ }
110
+
111
+ const messages = loadSession(sessionFile)
112
+ if (!messages) {
113
+ console.log(`Could not load session ${sessionIndex}.`)
45
114
  process.exit(1)
46
115
  }
116
+
117
+ process.env.AI_SESSION_INDEX = sessionIndex.toString()
118
+ process.env.AI_SESSION_FILE = sessionFile
119
+
120
+ console.log(`Loaded session ${sessionIndex} from ${sessionFile}`)
47
121
  }
48
122
 
49
123
  // Load config after setting model index
@@ -53,98 +127,4 @@ process.env.AI_MODEL_NAME = config.modelName
53
127
  process.env.AI_API_BASE_URL = config.apiBaseUrl
54
128
  process.env.AI_API_KEY = config.apiKey
55
129
 
56
- // Handle --version command
57
- if (argv[2] === "--version") {
58
- const packageJson = JSON.parse(
59
- readFileSync(new URL("../package.json", import.meta.url), "utf-8"),
60
- )
61
- console.log(packageJson.version)
62
- process.exit(0)
63
- }
64
-
65
- // Handle --help command
66
- if (argv[2] === "--help") {
67
- const packageJson = JSON.parse(
68
- readFileSync(new URL("../package.json", import.meta.url), "utf-8"),
69
- )
70
- console.log(`ai-agent-test v${packageJson.version}
71
-
72
- Usage: ai [options] [model-index]
73
-
74
- Commands:
75
- models ls List all available models
76
- models <idx> Run with model at index <idx> from config
77
- sessions ls List last 20 sessions
78
- sessions <idx> Load and restart from session <idx>
79
- update Update the ai-agent-test package to the latest version
80
- --version Show version number
81
- --help Show help message
82
-
83
- Arguments:
84
- model-index Index of the model to use (from ~/.ai/models.json)
85
-
86
- Examples:
87
- ai # Run with default model
88
- ai models ls # List all available models
89
- ai models 1 # Run with second model in config
90
- ai sessions ls # List last 20 sessions
91
- ai sessions 2 # Load and restart from session 2
92
- ai update # Update to latest version
93
- ai --version # Show version
94
- ai --help # Show help
95
- `)
96
- process.exit(0)
97
- }
98
-
99
- // Handle update command
100
- if (argv[2] === "update") {
101
- execSync("npm install -g ai-agent-test", { stdio: "inherit" })
102
- process.exit(0)
103
- }
104
-
105
- // Handle sessions command
106
- if (argv[2] === "sessions") {
107
- const subCommand = argv[3]
108
-
109
- if (subCommand === "ls") {
110
- const sessions = listSessions(20)
111
- if (sessions.length === 0) {
112
- console.log("No sessions found.")
113
- } else {
114
- console.log(`Last ${sessions.length} sessions:`)
115
- sessions.forEach((session, index) => {
116
- let line = `${index}. ${session.timestamp}`
117
- if (session.summary) {
118
- line += ` - ${session.summary}`
119
- }
120
- console.log(line)
121
- })
122
- }
123
- process.exit(0)
124
- } else {
125
- const sessionIndex = subCommand ? parseInt(subCommand, 10) : undefined
126
- if (sessionIndex !== undefined && !isNaN(sessionIndex)) {
127
- const sessionFile = getSessionFileByIndex(sessionIndex)
128
- if (!sessionFile) {
129
- console.log(`Session ${sessionIndex} not found.`)
130
- process.exit(1)
131
- }
132
-
133
- const messages = loadSession(sessionFile)
134
- if (!messages) {
135
- console.log(`Could not load session ${sessionIndex}.`)
136
- process.exit(1)
137
- }
138
-
139
- process.env.AI_SESSION_INDEX = sessionIndex.toString()
140
- process.env.AI_SESSION_FILE = sessionFile
141
-
142
- console.log(`Loaded session ${sessionIndex} from ${sessionFile}`)
143
- } else {
144
- console.log("Usage: ai sessions <index> or ai sessions ls")
145
- process.exit(1)
146
- }
147
- }
148
- }
149
-
150
130
  import("../dist/index.js")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-agent-test",
3
- "version": "0.9.4",
3
+ "version": "0.9.6",
4
4
  "main": "dist/index.js",
5
5
  "bin": {
6
6
  "ai": "./bin/ai"
@@ -55,6 +55,7 @@
55
55
  "chalk": "^5.6.2",
56
56
  "dotenv": "^17.4.1",
57
57
  "jsdom": "^29.0.1",
58
+ "yargs": "^18.0.0",
58
59
  "zod": "^4.3.6"
59
60
  }
60
61
  }