@aiagentwiki/cli 0.1.0 → 0.2.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.
Files changed (3) hide show
  1. package/README.md +29 -1
  2. package/dist/index.js +33 -5
  3. package/package.json +3 -4
package/README.md CHANGED
@@ -18,9 +18,37 @@ Requires Node.js `>=20`.
18
18
 
19
19
  ```bash
20
20
  agentwiki --help
21
+ agentwiki login --api-key aw_xxxxx
22
+ agentwiki whoami
21
23
  ```
22
24
 
23
- See the [main repository README](https://github.com/digitopvn/agentwiki#readme) for configuration (API URL, auth token) and full command reference.
25
+ ## Authentication
26
+
27
+ Credentials are resolved with this precedence (highest → lowest):
28
+
29
+ 1. **Environment variables** — `AGENTWIKI_API_KEY`, `AGENTWIKI_API_URL`
30
+ 2. **Credentials file** — `~/.agentwiki/credentials.json` (written by `agentwiki login`)
31
+ 3. **Defaults** — `apiUrl = https://api.agentwiki.cc`
32
+
33
+ ### Environment variables
34
+
35
+ | Variable | Purpose |
36
+ |---|---|
37
+ | `AGENTWIKI_API_KEY` | API key — bypasses `login`, ideal for CI/Docker/automation |
38
+ | `AGENTWIKI_API_URL` | Override API base URL (self-hosted, staging) |
39
+
40
+ Example (GitHub Actions):
41
+
42
+ ```yaml
43
+ - name: Publish site via AgentWiki CLI
44
+ env:
45
+ AGENTWIKI_API_KEY: ${{ secrets.AGENTWIKI_API_KEY }}
46
+ run: npx @aiagentwiki/cli sites deploy ./build --name my-site
47
+ ```
48
+
49
+ Use `agentwiki whoami` to verify which source (env/file/default) is in effect.
50
+
51
+ See the [main repository README](https://github.com/digitopvn/agentwiki#readme) for the full command reference.
24
52
 
25
53
  ## License
26
54
 
package/dist/index.js CHANGED
@@ -14,11 +14,30 @@ import { homedir } from "os";
14
14
  var CONFIG_DIR = join(homedir(), ".agentwiki");
15
15
  var CREDENTIALS_FILE = join(CONFIG_DIR, "credentials.json");
16
16
  var CONFIG_FILE = join(CONFIG_DIR, "config.json");
17
- function getCredentials() {
18
- if (!existsSync(CREDENTIALS_FILE)) {
19
- return { apiUrl: "https://api.agentwiki.cc" };
17
+ var DEFAULT_API_URL = "https://api.agentwiki.cc";
18
+ function readFileCredentials() {
19
+ if (!existsSync(CREDENTIALS_FILE)) return {};
20
+ try {
21
+ return JSON.parse(readFileSync(CREDENTIALS_FILE, "utf-8"));
22
+ } catch {
23
+ return {};
20
24
  }
21
- return { apiUrl: "https://api.agentwiki.cc", ...JSON.parse(readFileSync(CREDENTIALS_FILE, "utf-8")) };
25
+ }
26
+ function getCredentials() {
27
+ const file = readFileCredentials();
28
+ return {
29
+ ...file,
30
+ apiKey: process.env.AGENTWIKI_API_KEY ?? file.apiKey,
31
+ apiUrl: process.env.AGENTWIKI_API_URL ?? file.apiUrl ?? DEFAULT_API_URL
32
+ };
33
+ }
34
+ function getCredentialsWithSource() {
35
+ const file = readFileCredentials();
36
+ const source = {
37
+ apiKey: process.env.AGENTWIKI_API_KEY ? "env" : file.apiKey ? "file" : "none",
38
+ apiUrl: process.env.AGENTWIKI_API_URL ? "env" : file.apiUrl ? "file" : "default"
39
+ };
40
+ return { creds: getCredentials(), source };
22
41
  }
23
42
  function saveCredentials(creds) {
24
43
  if (!existsSync(CONFIG_DIR)) mkdirSync(CONFIG_DIR, { recursive: true });
@@ -128,11 +147,20 @@ program.command("login").description("Configure API key for authentication").opt
128
147
  }
129
148
  });
130
149
  program.command("whoami").description("Show current user info").action(async () => {
150
+ const { source, creds } = getCredentialsWithSource();
151
+ console.error(`# Auth source: apiKey=${source.apiKey} apiUrl=${source.apiUrl}`);
152
+ console.error(`# API URL: ${creds.apiUrl}`);
153
+ if (source.apiKey === "none") {
154
+ console.error("Not authenticated. Set AGENTWIKI_API_KEY env var or run: agentwiki login --api-key <key>");
155
+ process.exitCode = 1;
156
+ return;
157
+ }
131
158
  try {
132
159
  const me = await apiFetch("/auth/me");
133
160
  console.log(JSON.stringify(me, null, 2));
134
161
  } catch (err) {
135
- console.error("Not authenticated. Run: agentwiki login --api-key <key>");
162
+ console.error("API call failed:", err.message);
163
+ process.exitCode = 1;
136
164
  }
137
165
  });
138
166
  var doc = program.command("doc").description("Manage documents");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiagentwiki/cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "AgentWiki CLI — manage notes, docs, media, publish sites, and query your knowledge base from the terminal.",
5
5
  "keywords": [
6
6
  "agentwiki",
@@ -9,7 +9,7 @@
9
9
  "notes",
10
10
  "documentation"
11
11
  ],
12
- "homepage": "https://github.com/digitopvn/agentwiki#readme",
12
+ "homepage": "https://www.npmjs.com/package/@aiagentwiki/cli",
13
13
  "bugs": {
14
14
  "url": "https://github.com/digitopvn/agentwiki/issues"
15
15
  },
@@ -28,8 +28,7 @@
28
28
  "README.md"
29
29
  ],
30
30
  "publishConfig": {
31
- "access": "public",
32
- "provenance": true
31
+ "access": "public"
33
32
  },
34
33
  "scripts": {
35
34
  "build": "tsup",