Skip to content

Commit 955a3c0

Browse files
committed
cli: Add 'ws' command to manage workspaces
- Implement `manageWorkspaces` logic in `bin/cmd/cmds.ts` to list active workspaces and handle the activation process based on the `--activate` flag - Add the new `ws` subcommand in `bin/cmd/base.ts` to expose the workspace management functionality, including description and command-line options - Update `package.json` version to `0.0.120` and synchronize dependencies (`@agent-smith/core`, `@agent-smith/types`, `@types/node`) with the new feature requirements
1 parent dc1ec87 commit 955a3c0

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

packages/cli/bin/cmd/base.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Command, Option } from "commander";
22
import { conf, state } from "@agent-smith/core";
33
import { parseCommandArgs } from "../utils.js";
4-
import { processAgentCmd, processAgentsCmd, recreateDbCmd, resetDbCmd } from "./cmds.js";
4+
import { manageWorkspaces, processAgentCmd, processAgentsCmd, recreateDbCmd, resetDbCmd } from "./cmds.js";
55
import { displayOptions, inferenceOptions } from "../options.js";
66

77
function initBaseCommands(program: Command): Command {
@@ -62,6 +62,15 @@ function initBaseCommands(program: Command): Command {
6262
.action(async (...args: Array<any>) => {
6363
await recreateDbCmd()
6464
});
65+
const wsCmd = program.command("ws")
66+
.description("manage the workspaces")
67+
.action(async (...args: Array<any>) => {
68+
const ca = parseCommandArgs(args);
69+
await manageWorkspaces(ca.args, ca.options);
70+
});
71+
wsCmd.addOption(
72+
new Option("-a, --activate <name>", "activate a workspace")
73+
)
6574
return program
6675
}
6776

packages/cli/bin/cmd/cmds.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,32 @@ async function processAgentCmd(args: Array<string>, options: Record<string, any>
144144
//console.log(JSON.stringify(ts, null, " "));
145145
}
146146

147+
async function manageWorkspaces(args: Array<string>, options: Record<string, any>) {
148+
if (!options?.activate) {
149+
const { found, setting } = db.readSetting("workspace");
150+
const dws = found ? setting : null;
151+
const ws = db.readWorkspaces();
152+
ws.forEach(w => {
153+
const msg = dws == w.name ? colors.bold(w.name) + " " + colors.yellow("[active]") : colors.bold(w.name);
154+
console.log("- " + msg + " " + w.path);
155+
})
156+
} else {
157+
const { found, workspace } = db.readWorkspace(options.activate);
158+
if (!found) {
159+
runtimeDataError(`Workspace ${options.activate} not found`)
160+
return
161+
}
162+
db.upsertSetting("workspace", workspace.name);
163+
console.log(`Workspace ${colors.bold(options.activate)} activated`)
164+
}
165+
}
166+
147167
export {
148168
initUserCmds,
149169
processAgentCmd,
150170
processAgentsCmd,
151171
resetDbCmd,
152172
recreateDbCmd,
173+
manageWorkspaces,
153174
};
154175

packages/cli/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "@agent-smith/cli",
33
"description": "Agent Smith: terminal client for language model agents",
4-
"version": "0.0.119",
4+
"version": "0.0.120",
55
"scripts": {
66
"build": "rm -rf dist/* && tsc",
77
"cli": "node --loader ts-node/esm bin/index.ts",
88
"watch": "tsc --noCheck -p . -w"
99
},
1010
"dependencies": {
11-
"@agent-smith/core": "^0.0.3",
11+
"@agent-smith/core": "^0.0.8",
1212
"@inquirer/prompts": "^8.5.2",
1313
"@vue/reactivity": "^3.5.38",
1414
"ansi-colors": "^4.1.3",
@@ -20,13 +20,13 @@
2020
},
2121
"devDependencies": {
2222
"@agent-smith/agent": "^0.5.2",
23-
"@agent-smith/types": "^0.0.6",
23+
"@agent-smith/types": "^0.0.7",
2424
"@cfworker/json-schema": "^4.1.1",
2525
"@commander-js/extra-typings": "^15.0.0",
2626
"@rollup/plugin-node-resolve": "^16.0.3",
2727
"@rollup/plugin-typescript": "^12.3.0",
2828
"@types/marked-terminal": "^6.1.1",
29-
"@types/node": "^25.9.3",
29+
"@types/node": "^26.0.0",
3030
"ts-node": "^10.9.2",
3131
"tslib": "2.8.1",
3232
"typescript": "^6.0.3"

0 commit comments

Comments
 (0)